tcx.c 12 KB

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