tcx.c 12 KB

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