bw2.c 9.2 KB

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