bw2.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /* bw2.c: BWTWO frame buffer driver
  2. *
  3. * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
  5. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
  7. *
  8. * Driver layout based loosely on tgafb.c, see that file for credits.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/fb.h>
  18. #include <linux/mm.h>
  19. #include <asm/io.h>
  20. #include <asm/oplib.h>
  21. #include <asm/prom.h>
  22. #include <asm/of_device.h>
  23. #include <asm/fbio.h>
  24. #include "sbuslib.h"
  25. /*
  26. * Local functions.
  27. */
  28. static int bw2_blank(int, struct fb_info *);
  29. static int bw2_mmap(struct fb_info *, struct vm_area_struct *);
  30. static int bw2_ioctl(struct fb_info *, unsigned int, unsigned long);
  31. /*
  32. * Frame buffer operations
  33. */
  34. static struct fb_ops bw2_ops = {
  35. .owner = THIS_MODULE,
  36. .fb_blank = bw2_blank,
  37. .fb_fillrect = cfb_fillrect,
  38. .fb_copyarea = cfb_copyarea,
  39. .fb_imageblit = cfb_imageblit,
  40. .fb_mmap = bw2_mmap,
  41. .fb_ioctl = bw2_ioctl,
  42. #ifdef CONFIG_COMPAT
  43. .fb_compat_ioctl = sbusfb_compat_ioctl,
  44. #endif
  45. };
  46. /* OBio addresses for the bwtwo registers */
  47. #define BWTWO_REGISTER_OFFSET 0x400000
  48. struct bt_regs {
  49. u32 addr;
  50. u32 color_map;
  51. u32 control;
  52. u32 cursor;
  53. };
  54. struct bw2_regs {
  55. struct bt_regs cmap;
  56. u8 control;
  57. u8 status;
  58. u8 cursor_start;
  59. u8 cursor_end;
  60. u8 h_blank_start;
  61. u8 h_blank_end;
  62. u8 h_sync_start;
  63. u8 h_sync_end;
  64. u8 comp_sync_end;
  65. u8 v_blank_start_high;
  66. u8 v_blank_start_low;
  67. u8 v_blank_end;
  68. u8 v_sync_start;
  69. u8 v_sync_end;
  70. u8 xfer_holdoff_start;
  71. u8 xfer_holdoff_end;
  72. };
  73. /* Status Register Constants */
  74. #define BWTWO_SR_RES_MASK 0x70
  75. #define BWTWO_SR_1600_1280 0x50
  76. #define BWTWO_SR_1152_900_76_A 0x40
  77. #define BWTWO_SR_1152_900_76_B 0x60
  78. #define BWTWO_SR_ID_MASK 0x0f
  79. #define BWTWO_SR_ID_MONO 0x02
  80. #define BWTWO_SR_ID_MONO_ECL 0x03
  81. #define BWTWO_SR_ID_MSYNC 0x04
  82. #define BWTWO_SR_ID_NOCONN 0x0a
  83. /* Control Register Constants */
  84. #define BWTWO_CTL_ENABLE_INTS 0x80
  85. #define BWTWO_CTL_ENABLE_VIDEO 0x40
  86. #define BWTWO_CTL_ENABLE_TIMING 0x20
  87. #define BWTWO_CTL_ENABLE_CURCMP 0x10
  88. #define BWTWO_CTL_XTAL_MASK 0x0C
  89. #define BWTWO_CTL_DIVISOR_MASK 0x03
  90. /* Status Register Constants */
  91. #define BWTWO_STAT_PENDING_INT 0x80
  92. #define BWTWO_STAT_MSENSE_MASK 0x70
  93. #define BWTWO_STAT_ID_MASK 0x0f
  94. struct bw2_par {
  95. spinlock_t lock;
  96. struct bw2_regs __iomem *regs;
  97. u32 flags;
  98. #define BW2_FLAG_BLANKED 0x00000001
  99. unsigned long physbase;
  100. unsigned long which_io;
  101. unsigned long fbsize;
  102. };
  103. /**
  104. * bw2_blank - Optional function. Blanks the display.
  105. * @blank_mode: the blank mode we want.
  106. * @info: frame buffer structure that represents a single frame buffer
  107. */
  108. static int
  109. bw2_blank(int blank, struct fb_info *info)
  110. {
  111. struct bw2_par *par = (struct bw2_par *) info->par;
  112. struct bw2_regs __iomem *regs = par->regs;
  113. unsigned long flags;
  114. u8 val;
  115. spin_lock_irqsave(&par->lock, flags);
  116. switch (blank) {
  117. case FB_BLANK_UNBLANK: /* Unblanking */
  118. val = sbus_readb(&regs->control);
  119. val |= BWTWO_CTL_ENABLE_VIDEO;
  120. sbus_writeb(val, &regs->control);
  121. par->flags &= ~BW2_FLAG_BLANKED;
  122. break;
  123. case FB_BLANK_NORMAL: /* Normal blanking */
  124. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  125. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  126. case FB_BLANK_POWERDOWN: /* Poweroff */
  127. val = sbus_readb(&regs->control);
  128. val &= ~BWTWO_CTL_ENABLE_VIDEO;
  129. sbus_writeb(val, &regs->control);
  130. par->flags |= BW2_FLAG_BLANKED;
  131. break;
  132. }
  133. spin_unlock_irqrestore(&par->lock, flags);
  134. return 0;
  135. }
  136. static struct sbus_mmap_map bw2_mmap_map[] = {
  137. {
  138. .size = SBUS_MMAP_FBSIZE(1)
  139. },
  140. { .size = 0 }
  141. };
  142. static int bw2_mmap(struct fb_info *info, struct vm_area_struct *vma)
  143. {
  144. struct bw2_par *par = (struct bw2_par *)info->par;
  145. return sbusfb_mmap_helper(bw2_mmap_map,
  146. par->physbase, par->fbsize,
  147. par->which_io,
  148. vma);
  149. }
  150. static int bw2_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  151. {
  152. struct bw2_par *par = (struct bw2_par *) info->par;
  153. return sbusfb_ioctl_helper(cmd, arg, info,
  154. FBTYPE_SUN2BW, 1, par->fbsize);
  155. }
  156. /*
  157. * Initialisation
  158. */
  159. static void __devinit bw2_init_fix(struct fb_info *info, int linebytes)
  160. {
  161. strlcpy(info->fix.id, "bwtwo", sizeof(info->fix.id));
  162. info->fix.type = FB_TYPE_PACKED_PIXELS;
  163. info->fix.visual = FB_VISUAL_MONO01;
  164. info->fix.line_length = linebytes;
  165. info->fix.accel = FB_ACCEL_SUN_BWTWO;
  166. }
  167. static u8 bw2regs_1600[] __devinitdata = {
  168. 0x14, 0x8b, 0x15, 0x28, 0x16, 0x03, 0x17, 0x13,
  169. 0x18, 0x7b, 0x19, 0x05, 0x1a, 0x34, 0x1b, 0x2e,
  170. 0x1c, 0x00, 0x1d, 0x0a, 0x1e, 0xff, 0x1f, 0x01,
  171. 0x10, 0x21, 0
  172. };
  173. static u8 bw2regs_ecl[] __devinitdata = {
  174. 0x14, 0x65, 0x15, 0x1e, 0x16, 0x04, 0x17, 0x0c,
  175. 0x18, 0x5e, 0x19, 0x03, 0x1a, 0xa7, 0x1b, 0x23,
  176. 0x1c, 0x00, 0x1d, 0x08, 0x1e, 0xff, 0x1f, 0x01,
  177. 0x10, 0x20, 0
  178. };
  179. static u8 bw2regs_analog[] __devinitdata = {
  180. 0x14, 0xbb, 0x15, 0x2b, 0x16, 0x03, 0x17, 0x13,
  181. 0x18, 0xb0, 0x19, 0x03, 0x1a, 0xa6, 0x1b, 0x22,
  182. 0x1c, 0x01, 0x1d, 0x05, 0x1e, 0xff, 0x1f, 0x01,
  183. 0x10, 0x20, 0
  184. };
  185. static u8 bw2regs_76hz[] __devinitdata = {
  186. 0x14, 0xb7, 0x15, 0x27, 0x16, 0x03, 0x17, 0x0f,
  187. 0x18, 0xae, 0x19, 0x03, 0x1a, 0xae, 0x1b, 0x2a,
  188. 0x1c, 0x01, 0x1d, 0x09, 0x1e, 0xff, 0x1f, 0x01,
  189. 0x10, 0x24, 0
  190. };
  191. static u8 bw2regs_66hz[] __devinitdata = {
  192. 0x14, 0xbb, 0x15, 0x2b, 0x16, 0x04, 0x17, 0x14,
  193. 0x18, 0xae, 0x19, 0x03, 0x1a, 0xa8, 0x1b, 0x24,
  194. 0x1c, 0x01, 0x1d, 0x05, 0x1e, 0xff, 0x1f, 0x01,
  195. 0x10, 0x20, 0
  196. };
  197. static void __devinit bw2_do_default_mode(struct bw2_par *par,
  198. struct fb_info *info,
  199. int *linebytes)
  200. {
  201. u8 status, mon;
  202. u8 *p;
  203. status = sbus_readb(&par->regs->status);
  204. mon = status & BWTWO_SR_RES_MASK;
  205. switch (status & BWTWO_SR_ID_MASK) {
  206. case BWTWO_SR_ID_MONO_ECL:
  207. if (mon == BWTWO_SR_1600_1280) {
  208. p = bw2regs_1600;
  209. info->var.xres = info->var.xres_virtual = 1600;
  210. info->var.yres = info->var.yres_virtual = 1280;
  211. *linebytes = 1600 / 8;
  212. } else
  213. p = bw2regs_ecl;
  214. break;
  215. case BWTWO_SR_ID_MONO:
  216. p = bw2regs_analog;
  217. break;
  218. case BWTWO_SR_ID_MSYNC:
  219. if (mon == BWTWO_SR_1152_900_76_A ||
  220. mon == BWTWO_SR_1152_900_76_B)
  221. p = bw2regs_76hz;
  222. else
  223. p = bw2regs_66hz;
  224. break;
  225. case BWTWO_SR_ID_NOCONN:
  226. return;
  227. default:
  228. prom_printf("bw2: can't handle SR %02x\n",
  229. status);
  230. prom_halt();
  231. }
  232. for ( ; *p; p += 2) {
  233. u8 __iomem *regp = &((u8 __iomem *)par->regs)[p[0]];
  234. sbus_writeb(p[1], regp);
  235. }
  236. }
  237. struct all_info {
  238. struct fb_info info;
  239. struct bw2_par par;
  240. };
  241. static int __devinit bw2_init_one(struct of_device *op)
  242. {
  243. struct device_node *dp = op->node;
  244. struct all_info *all;
  245. int linebytes, err;
  246. all = kzalloc(sizeof(*all), GFP_KERNEL);
  247. if (!all)
  248. return -ENOMEM;
  249. spin_lock_init(&all->par.lock);
  250. all->par.physbase = op->resource[0].start;
  251. all->par.which_io = op->resource[0].flags & IORESOURCE_BITS;
  252. sbusfb_fill_var(&all->info.var, dp->node, 1);
  253. linebytes = of_getintprop_default(dp, "linebytes",
  254. all->info.var.xres);
  255. all->info.var.red.length = all->info.var.green.length =
  256. all->info.var.blue.length = all->info.var.bits_per_pixel;
  257. all->info.var.red.offset = all->info.var.green.offset =
  258. all->info.var.blue.offset = 0;
  259. all->par.regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET,
  260. sizeof(struct bw2_regs), "bw2 regs");
  261. if (!of_find_property(dp, "width", NULL))
  262. bw2_do_default_mode(&all->par, &all->info, &linebytes);
  263. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  264. all->info.flags = FBINFO_DEFAULT;
  265. all->info.fbops = &bw2_ops;
  266. all->info.screen_base =
  267. of_ioremap(&op->resource[0], 0, all->par.fbsize, "bw2 ram");
  268. all->info.par = &all->par;
  269. bw2_blank(0, &all->info);
  270. bw2_init_fix(&all->info, linebytes);
  271. err= register_framebuffer(&all->info);
  272. if (err < 0) {
  273. of_iounmap(&op->resource[0],
  274. all->par.regs, sizeof(struct bw2_regs));
  275. of_iounmap(&op->resource[0],
  276. all->info.screen_base, all->par.fbsize);
  277. kfree(all);
  278. return err;
  279. }
  280. dev_set_drvdata(&op->dev, all);
  281. printk("%s: bwtwo at %lx:%lx\n",
  282. dp->full_name,
  283. all->par.which_io, all->par.physbase);
  284. return 0;
  285. }
  286. static int __devinit bw2_probe(struct of_device *dev, const struct of_device_id *match)
  287. {
  288. struct of_device *op = to_of_device(&dev->dev);
  289. return bw2_init_one(op);
  290. }
  291. static int __devexit bw2_remove(struct of_device *op)
  292. {
  293. struct all_info *all = dev_get_drvdata(&op->dev);
  294. unregister_framebuffer(&all->info);
  295. of_iounmap(&op->resource[0], all->par.regs, sizeof(struct bw2_regs));
  296. of_iounmap(&op->resource[0], all->info.screen_base, all->par.fbsize);
  297. kfree(all);
  298. dev_set_drvdata(&op->dev, NULL);
  299. return 0;
  300. }
  301. static struct of_device_id bw2_match[] = {
  302. {
  303. .name = "bwtwo",
  304. },
  305. {},
  306. };
  307. MODULE_DEVICE_TABLE(of, bw2_match);
  308. static struct of_platform_driver bw2_driver = {
  309. .name = "bw2",
  310. .match_table = bw2_match,
  311. .probe = bw2_probe,
  312. .remove = __devexit_p(bw2_remove),
  313. };
  314. static int __init bw2_init(void)
  315. {
  316. if (fb_get_options("bw2fb", NULL))
  317. return -ENODEV;
  318. return of_register_driver(&bw2_driver, &of_bus_type);
  319. }
  320. static void __exit bw2_exit(void)
  321. {
  322. return of_unregister_driver(&bw2_driver);
  323. }
  324. module_init(bw2_init);
  325. module_exit(bw2_exit);
  326. MODULE_DESCRIPTION("framebuffer driver for BWTWO chipsets");
  327. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  328. MODULE_VERSION("2.0");
  329. MODULE_LICENSE("GPL");