bw2.c 9.3 KB

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