bw2.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 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[] = {
  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[] = {
  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[] = {
  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[] = {
  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[] = {
  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 bw2_do_default_mode(struct bw2_par *par, struct fb_info *info,
  192. int *linebytes)
  193. {
  194. u8 status, mon;
  195. u8 *p;
  196. status = sbus_readb(&par->regs->status);
  197. mon = status & BWTWO_SR_RES_MASK;
  198. switch (status & BWTWO_SR_ID_MASK) {
  199. case BWTWO_SR_ID_MONO_ECL:
  200. if (mon == BWTWO_SR_1600_1280) {
  201. p = bw2regs_1600;
  202. info->var.xres = info->var.xres_virtual = 1600;
  203. info->var.yres = info->var.yres_virtual = 1280;
  204. *linebytes = 1600 / 8;
  205. } else
  206. p = bw2regs_ecl;
  207. break;
  208. case BWTWO_SR_ID_MONO:
  209. p = bw2regs_analog;
  210. break;
  211. case BWTWO_SR_ID_MSYNC:
  212. if (mon == BWTWO_SR_1152_900_76_A ||
  213. mon == BWTWO_SR_1152_900_76_B)
  214. p = bw2regs_76hz;
  215. else
  216. p = bw2regs_66hz;
  217. break;
  218. case BWTWO_SR_ID_NOCONN:
  219. return 0;
  220. default:
  221. printk(KERN_ERR "bw2: can't handle SR %02x\n",
  222. status);
  223. return -EINVAL;
  224. }
  225. for ( ; *p; p += 2) {
  226. u8 __iomem *regp = &((u8 __iomem *)par->regs)[p[0]];
  227. sbus_writeb(p[1], regp);
  228. }
  229. return 0;
  230. }
  231. static int bw2_probe(struct platform_device *op)
  232. {
  233. struct device_node *dp = op->dev.of_node;
  234. struct fb_info *info;
  235. struct bw2_par *par;
  236. int linebytes, err;
  237. info = framebuffer_alloc(sizeof(struct bw2_par), &op->dev);
  238. err = -ENOMEM;
  239. if (!info)
  240. goto out_err;
  241. par = info->par;
  242. spin_lock_init(&par->lock);
  243. info->fix.smem_start = op->resource[0].start;
  244. par->which_io = op->resource[0].flags & IORESOURCE_BITS;
  245. sbusfb_fill_var(&info->var, dp, 1);
  246. linebytes = of_getintprop_default(dp, "linebytes",
  247. info->var.xres);
  248. info->var.red.length = info->var.green.length =
  249. info->var.blue.length = info->var.bits_per_pixel;
  250. info->var.red.offset = info->var.green.offset =
  251. info->var.blue.offset = 0;
  252. par->regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET,
  253. sizeof(struct bw2_regs), "bw2 regs");
  254. if (!par->regs)
  255. goto out_release_fb;
  256. if (!of_find_property(dp, "width", NULL)) {
  257. err = bw2_do_default_mode(par, info, &linebytes);
  258. if (err)
  259. goto out_unmap_regs;
  260. }
  261. info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
  262. info->flags = FBINFO_DEFAULT;
  263. info->fbops = &bw2_ops;
  264. info->screen_base = of_ioremap(&op->resource[0], 0,
  265. info->fix.smem_len, "bw2 ram");
  266. if (!info->screen_base) {
  267. err = -ENOMEM;
  268. goto out_unmap_regs;
  269. }
  270. bw2_blank(FB_BLANK_UNBLANK, info);
  271. bw2_init_fix(info, linebytes);
  272. err = register_framebuffer(info);
  273. if (err < 0)
  274. goto out_unmap_screen;
  275. dev_set_drvdata(&op->dev, info);
  276. printk(KERN_INFO "%s: bwtwo at %lx:%lx\n",
  277. dp->full_name, par->which_io, info->fix.smem_start);
  278. return 0;
  279. out_unmap_screen:
  280. of_iounmap(&op->resource[0], info->screen_base, info->fix.smem_len);
  281. out_unmap_regs:
  282. of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs));
  283. out_release_fb:
  284. framebuffer_release(info);
  285. out_err:
  286. return err;
  287. }
  288. static int bw2_remove(struct platform_device *op)
  289. {
  290. struct fb_info *info = dev_get_drvdata(&op->dev);
  291. struct bw2_par *par = info->par;
  292. unregister_framebuffer(info);
  293. of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs));
  294. of_iounmap(&op->resource[0], info->screen_base, info->fix.smem_len);
  295. framebuffer_release(info);
  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. .of_match_table = bw2_match,
  309. },
  310. .probe = bw2_probe,
  311. .remove = bw2_remove,
  312. };
  313. static int __init bw2_init(void)
  314. {
  315. if (fb_get_options("bw2fb", NULL))
  316. return -ENODEV;
  317. return platform_driver_register(&bw2_driver);
  318. }
  319. static void __exit bw2_exit(void)
  320. {
  321. platform_driver_unregister(&bw2_driver);
  322. }
  323. module_init(bw2_init);
  324. module_exit(bw2_exit);
  325. MODULE_DESCRIPTION("framebuffer driver for BWTWO chipsets");
  326. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  327. MODULE_VERSION("2.0");
  328. MODULE_LICENSE("GPL");