tcx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /* tcx.c: TCX 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) 1996 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 tcx_setcolreg(unsigned, unsigned, unsigned, unsigned,
  26. unsigned, struct fb_info *);
  27. static int tcx_blank(int, struct fb_info *);
  28. static int tcx_mmap(struct fb_info *, struct vm_area_struct *);
  29. static int tcx_ioctl(struct fb_info *, unsigned int, unsigned long);
  30. static int tcx_pan_display(struct fb_var_screeninfo *, struct fb_info *);
  31. /*
  32. * Frame buffer operations
  33. */
  34. static struct fb_ops tcx_ops = {
  35. .owner = THIS_MODULE,
  36. .fb_setcolreg = tcx_setcolreg,
  37. .fb_blank = tcx_blank,
  38. .fb_pan_display = tcx_pan_display,
  39. .fb_fillrect = cfb_fillrect,
  40. .fb_copyarea = cfb_copyarea,
  41. .fb_imageblit = cfb_imageblit,
  42. .fb_mmap = tcx_mmap,
  43. .fb_ioctl = tcx_ioctl,
  44. #ifdef CONFIG_COMPAT
  45. .fb_compat_ioctl = sbusfb_compat_ioctl,
  46. #endif
  47. };
  48. /* THC definitions */
  49. #define TCX_THC_MISC_REV_SHIFT 16
  50. #define TCX_THC_MISC_REV_MASK 15
  51. #define TCX_THC_MISC_VSYNC_DIS (1 << 25)
  52. #define TCX_THC_MISC_HSYNC_DIS (1 << 24)
  53. #define TCX_THC_MISC_RESET (1 << 12)
  54. #define TCX_THC_MISC_VIDEO (1 << 10)
  55. #define TCX_THC_MISC_SYNC (1 << 9)
  56. #define TCX_THC_MISC_VSYNC (1 << 8)
  57. #define TCX_THC_MISC_SYNC_ENAB (1 << 7)
  58. #define TCX_THC_MISC_CURS_RES (1 << 6)
  59. #define TCX_THC_MISC_INT_ENAB (1 << 5)
  60. #define TCX_THC_MISC_INT (1 << 4)
  61. #define TCX_THC_MISC_INIT 0x9f
  62. #define TCX_THC_REV_REV_SHIFT 20
  63. #define TCX_THC_REV_REV_MASK 15
  64. #define TCX_THC_REV_MINREV_SHIFT 28
  65. #define TCX_THC_REV_MINREV_MASK 15
  66. /* The contents are unknown */
  67. struct tcx_tec {
  68. u32 tec_matrix;
  69. u32 tec_clip;
  70. u32 tec_vdc;
  71. };
  72. struct tcx_thc {
  73. u32 thc_rev;
  74. u32 thc_pad0[511];
  75. u32 thc_hs; /* hsync timing */
  76. u32 thc_hsdvs;
  77. u32 thc_hd;
  78. u32 thc_vs; /* vsync timing */
  79. u32 thc_vd;
  80. u32 thc_refresh;
  81. u32 thc_misc;
  82. u32 thc_pad1[56];
  83. u32 thc_cursxy; /* cursor x,y position (16 bits each) */
  84. u32 thc_cursmask[32]; /* cursor mask bits */
  85. u32 thc_cursbits[32]; /* what to show where mask enabled */
  86. };
  87. struct bt_regs {
  88. u32 addr;
  89. u32 color_map;
  90. u32 control;
  91. u32 cursor;
  92. };
  93. #define TCX_MMAP_ENTRIES 14
  94. struct tcx_par {
  95. spinlock_t lock;
  96. struct bt_regs __iomem *bt;
  97. struct tcx_thc __iomem *thc;
  98. struct tcx_tec __iomem *tec;
  99. u32 __iomem *cplane;
  100. u32 flags;
  101. #define TCX_FLAG_BLANKED 0x00000001
  102. unsigned long which_io;
  103. struct sbus_mmap_map mmap_map[TCX_MMAP_ENTRIES];
  104. int lowdepth;
  105. };
  106. /* Reset control plane so that WID is 8-bit plane. */
  107. static void __tcx_set_control_plane(struct fb_info *info)
  108. {
  109. struct tcx_par *par = info->par;
  110. u32 __iomem *p, *pend;
  111. if (par->lowdepth)
  112. return;
  113. p = par->cplane;
  114. if (p == NULL)
  115. return;
  116. for (pend = p + info->fix.smem_len; p < pend; p++) {
  117. u32 tmp = sbus_readl(p);
  118. tmp &= 0xffffff;
  119. sbus_writel(tmp, p);
  120. }
  121. }
  122. static void tcx_reset(struct fb_info *info)
  123. {
  124. struct tcx_par *par = (struct tcx_par *) info->par;
  125. unsigned long flags;
  126. spin_lock_irqsave(&par->lock, flags);
  127. __tcx_set_control_plane(info);
  128. spin_unlock_irqrestore(&par->lock, flags);
  129. }
  130. static int tcx_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  131. {
  132. tcx_reset(info);
  133. return 0;
  134. }
  135. /**
  136. * tcx_setcolreg - Optional function. Sets a color register.
  137. * @regno: boolean, 0 copy local, 1 get_user() function
  138. * @red: frame buffer colormap structure
  139. * @green: The green value which can be up to 16 bits wide
  140. * @blue: The blue value which can be up to 16 bits wide.
  141. * @transp: If supported the alpha value which can be up to 16 bits wide.
  142. * @info: frame buffer info structure
  143. */
  144. static int tcx_setcolreg(unsigned regno,
  145. unsigned red, unsigned green, unsigned blue,
  146. unsigned transp, struct fb_info *info)
  147. {
  148. struct tcx_par *par = (struct tcx_par *) info->par;
  149. struct bt_regs __iomem *bt = par->bt;
  150. unsigned long flags;
  151. if (regno >= 256)
  152. return 1;
  153. red >>= 8;
  154. green >>= 8;
  155. blue >>= 8;
  156. spin_lock_irqsave(&par->lock, flags);
  157. sbus_writel(regno << 24, &bt->addr);
  158. sbus_writel(red << 24, &bt->color_map);
  159. sbus_writel(green << 24, &bt->color_map);
  160. sbus_writel(blue << 24, &bt->color_map);
  161. spin_unlock_irqrestore(&par->lock, flags);
  162. return 0;
  163. }
  164. /**
  165. * tcx_blank - Optional function. Blanks the display.
  166. * @blank_mode: the blank mode we want.
  167. * @info: frame buffer structure that represents a single frame buffer
  168. */
  169. static int
  170. tcx_blank(int blank, struct fb_info *info)
  171. {
  172. struct tcx_par *par = (struct tcx_par *) info->par;
  173. struct tcx_thc __iomem *thc = par->thc;
  174. unsigned long flags;
  175. u32 val;
  176. spin_lock_irqsave(&par->lock, flags);
  177. val = sbus_readl(&thc->thc_misc);
  178. switch (blank) {
  179. case FB_BLANK_UNBLANK: /* Unblanking */
  180. val &= ~(TCX_THC_MISC_VSYNC_DIS |
  181. TCX_THC_MISC_HSYNC_DIS);
  182. val |= TCX_THC_MISC_VIDEO;
  183. par->flags &= ~TCX_FLAG_BLANKED;
  184. break;
  185. case FB_BLANK_NORMAL: /* Normal blanking */
  186. val &= ~TCX_THC_MISC_VIDEO;
  187. par->flags |= TCX_FLAG_BLANKED;
  188. break;
  189. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  190. val |= TCX_THC_MISC_VSYNC_DIS;
  191. break;
  192. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  193. val |= TCX_THC_MISC_HSYNC_DIS;
  194. break;
  195. case FB_BLANK_POWERDOWN: /* Poweroff */
  196. break;
  197. };
  198. sbus_writel(val, &thc->thc_misc);
  199. spin_unlock_irqrestore(&par->lock, flags);
  200. return 0;
  201. }
  202. static struct sbus_mmap_map __tcx_mmap_map[TCX_MMAP_ENTRIES] = {
  203. {
  204. .voff = TCX_RAM8BIT,
  205. .size = SBUS_MMAP_FBSIZE(1)
  206. },
  207. {
  208. .voff = TCX_RAM24BIT,
  209. .size = SBUS_MMAP_FBSIZE(4)
  210. },
  211. {
  212. .voff = TCX_UNK3,
  213. .size = SBUS_MMAP_FBSIZE(8)
  214. },
  215. {
  216. .voff = TCX_UNK4,
  217. .size = SBUS_MMAP_FBSIZE(8)
  218. },
  219. {
  220. .voff = TCX_CONTROLPLANE,
  221. .size = SBUS_MMAP_FBSIZE(4)
  222. },
  223. {
  224. .voff = TCX_UNK6,
  225. .size = SBUS_MMAP_FBSIZE(8)
  226. },
  227. {
  228. .voff = TCX_UNK7,
  229. .size = SBUS_MMAP_FBSIZE(8)
  230. },
  231. {
  232. .voff = TCX_TEC,
  233. .size = PAGE_SIZE
  234. },
  235. {
  236. .voff = TCX_BTREGS,
  237. .size = PAGE_SIZE
  238. },
  239. {
  240. .voff = TCX_THC,
  241. .size = PAGE_SIZE
  242. },
  243. {
  244. .voff = TCX_DHC,
  245. .size = PAGE_SIZE
  246. },
  247. {
  248. .voff = TCX_ALT,
  249. .size = PAGE_SIZE
  250. },
  251. {
  252. .voff = TCX_UNK2,
  253. .size = 0x20000
  254. },
  255. { .size = 0 }
  256. };
  257. static int tcx_mmap(struct fb_info *info, struct vm_area_struct *vma)
  258. {
  259. struct tcx_par *par = (struct tcx_par *)info->par;
  260. return sbusfb_mmap_helper(par->mmap_map,
  261. info->fix.smem_start, info->fix.smem_len,
  262. par->which_io, vma);
  263. }
  264. static int tcx_ioctl(struct fb_info *info, unsigned int cmd,
  265. unsigned long arg)
  266. {
  267. struct tcx_par *par = (struct tcx_par *) info->par;
  268. return sbusfb_ioctl_helper(cmd, arg, info,
  269. FBTYPE_TCXCOLOR,
  270. (par->lowdepth ? 8 : 24),
  271. info->fix.smem_len);
  272. }
  273. /*
  274. * Initialisation
  275. */
  276. static void
  277. tcx_init_fix(struct fb_info *info, int linebytes)
  278. {
  279. struct tcx_par *par = (struct tcx_par *)info->par;
  280. const char *tcx_name;
  281. if (par->lowdepth)
  282. tcx_name = "TCX8";
  283. else
  284. tcx_name = "TCX24";
  285. strlcpy(info->fix.id, tcx_name, sizeof(info->fix.id));
  286. info->fix.type = FB_TYPE_PACKED_PIXELS;
  287. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  288. info->fix.line_length = linebytes;
  289. info->fix.accel = FB_ACCEL_SUN_TCX;
  290. }
  291. static void tcx_unmap_regs(struct platform_device *op, struct fb_info *info,
  292. struct tcx_par *par)
  293. {
  294. if (par->tec)
  295. of_iounmap(&op->resource[7],
  296. par->tec, sizeof(struct tcx_tec));
  297. if (par->thc)
  298. of_iounmap(&op->resource[9],
  299. par->thc, sizeof(struct tcx_thc));
  300. if (par->bt)
  301. of_iounmap(&op->resource[8],
  302. par->bt, sizeof(struct bt_regs));
  303. if (par->cplane)
  304. of_iounmap(&op->resource[4],
  305. par->cplane, info->fix.smem_len * sizeof(u32));
  306. if (info->screen_base)
  307. of_iounmap(&op->resource[0],
  308. info->screen_base, info->fix.smem_len);
  309. }
  310. static int __devinit tcx_probe(struct platform_device *op)
  311. {
  312. struct device_node *dp = op->dev.of_node;
  313. struct fb_info *info;
  314. struct tcx_par *par;
  315. int linebytes, i, err;
  316. info = framebuffer_alloc(sizeof(struct tcx_par), &op->dev);
  317. err = -ENOMEM;
  318. if (!info)
  319. goto out_err;
  320. par = info->par;
  321. spin_lock_init(&par->lock);
  322. par->lowdepth =
  323. (of_find_property(dp, "tcx-8-bit", NULL) != NULL);
  324. sbusfb_fill_var(&info->var, dp, 8);
  325. info->var.red.length = 8;
  326. info->var.green.length = 8;
  327. info->var.blue.length = 8;
  328. linebytes = of_getintprop_default(dp, "linebytes",
  329. info->var.xres);
  330. info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
  331. par->tec = of_ioremap(&op->resource[7], 0,
  332. sizeof(struct tcx_tec), "tcx tec");
  333. par->thc = of_ioremap(&op->resource[9], 0,
  334. sizeof(struct tcx_thc), "tcx thc");
  335. par->bt = of_ioremap(&op->resource[8], 0,
  336. sizeof(struct bt_regs), "tcx dac");
  337. info->screen_base = of_ioremap(&op->resource[0], 0,
  338. info->fix.smem_len, "tcx ram");
  339. if (!par->tec || !par->thc ||
  340. !par->bt || !info->screen_base)
  341. goto out_unmap_regs;
  342. memcpy(&par->mmap_map, &__tcx_mmap_map, sizeof(par->mmap_map));
  343. if (!par->lowdepth) {
  344. par->cplane = of_ioremap(&op->resource[4], 0,
  345. info->fix.smem_len * sizeof(u32),
  346. "tcx cplane");
  347. if (!par->cplane)
  348. goto out_unmap_regs;
  349. } else {
  350. par->mmap_map[1].size = SBUS_MMAP_EMPTY;
  351. par->mmap_map[4].size = SBUS_MMAP_EMPTY;
  352. par->mmap_map[5].size = SBUS_MMAP_EMPTY;
  353. par->mmap_map[6].size = SBUS_MMAP_EMPTY;
  354. }
  355. info->fix.smem_start = op->resource[0].start;
  356. par->which_io = op->resource[0].flags & IORESOURCE_BITS;
  357. for (i = 0; i < TCX_MMAP_ENTRIES; i++) {
  358. int j;
  359. switch (i) {
  360. case 10:
  361. j = 12;
  362. break;
  363. case 11: case 12:
  364. j = i - 1;
  365. break;
  366. default:
  367. j = i;
  368. break;
  369. };
  370. par->mmap_map[i].poff = op->resource[j].start;
  371. }
  372. info->flags = FBINFO_DEFAULT;
  373. info->fbops = &tcx_ops;
  374. /* Initialize brooktree DAC. */
  375. sbus_writel(0x04 << 24, &par->bt->addr); /* color planes */
  376. sbus_writel(0xff << 24, &par->bt->control);
  377. sbus_writel(0x05 << 24, &par->bt->addr);
  378. sbus_writel(0x00 << 24, &par->bt->control);
  379. sbus_writel(0x06 << 24, &par->bt->addr); /* overlay plane */
  380. sbus_writel(0x73 << 24, &par->bt->control);
  381. sbus_writel(0x07 << 24, &par->bt->addr);
  382. sbus_writel(0x00 << 24, &par->bt->control);
  383. tcx_reset(info);
  384. tcx_blank(FB_BLANK_UNBLANK, info);
  385. if (fb_alloc_cmap(&info->cmap, 256, 0))
  386. goto out_unmap_regs;
  387. fb_set_cmap(&info->cmap, info);
  388. tcx_init_fix(info, linebytes);
  389. err = register_framebuffer(info);
  390. if (err < 0)
  391. goto out_dealloc_cmap;
  392. dev_set_drvdata(&op->dev, info);
  393. printk(KERN_INFO "%s: TCX at %lx:%lx, %s\n",
  394. dp->full_name,
  395. par->which_io,
  396. info->fix.smem_start,
  397. par->lowdepth ? "8-bit only" : "24-bit depth");
  398. return 0;
  399. out_dealloc_cmap:
  400. fb_dealloc_cmap(&info->cmap);
  401. out_unmap_regs:
  402. tcx_unmap_regs(op, info, par);
  403. framebuffer_release(info);
  404. out_err:
  405. return err;
  406. }
  407. static int __devexit tcx_remove(struct platform_device *op)
  408. {
  409. struct fb_info *info = dev_get_drvdata(&op->dev);
  410. struct tcx_par *par = info->par;
  411. unregister_framebuffer(info);
  412. fb_dealloc_cmap(&info->cmap);
  413. tcx_unmap_regs(op, info, par);
  414. framebuffer_release(info);
  415. dev_set_drvdata(&op->dev, NULL);
  416. return 0;
  417. }
  418. static const struct of_device_id tcx_match[] = {
  419. {
  420. .name = "SUNW,tcx",
  421. },
  422. {},
  423. };
  424. MODULE_DEVICE_TABLE(of, tcx_match);
  425. static struct platform_driver tcx_driver = {
  426. .driver = {
  427. .name = "tcx",
  428. .owner = THIS_MODULE,
  429. .of_match_table = tcx_match,
  430. },
  431. .probe = tcx_probe,
  432. .remove = __devexit_p(tcx_remove),
  433. };
  434. static int __init tcx_init(void)
  435. {
  436. if (fb_get_options("tcxfb", NULL))
  437. return -ENODEV;
  438. return platform_driver_register(&tcx_driver);
  439. }
  440. static void __exit tcx_exit(void)
  441. {
  442. platform_driver_unregister(&tcx_driver);
  443. }
  444. module_init(tcx_init);
  445. module_exit(tcx_exit);
  446. MODULE_DESCRIPTION("framebuffer driver for TCX chipsets");
  447. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  448. MODULE_VERSION("2.0");
  449. MODULE_LICENSE("GPL");