tcx.c 12 KB

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