tcx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. struct all_info {
  295. struct fb_info info;
  296. struct tcx_par par;
  297. };
  298. static void tcx_unmap_regs(struct of_device *op, struct all_info *all)
  299. {
  300. if (all->par.tec)
  301. of_iounmap(&op->resource[7],
  302. all->par.tec, sizeof(struct tcx_tec));
  303. if (all->par.thc)
  304. of_iounmap(&op->resource[9],
  305. all->par.thc, sizeof(struct tcx_thc));
  306. if (all->par.bt)
  307. of_iounmap(&op->resource[8],
  308. all->par.bt, sizeof(struct bt_regs));
  309. if (all->par.cplane)
  310. of_iounmap(&op->resource[4],
  311. all->par.cplane, all->par.fbsize * sizeof(u32));
  312. if (all->info.screen_base)
  313. of_iounmap(&op->resource[0],
  314. all->info.screen_base, all->par.fbsize);
  315. }
  316. static int __devinit tcx_init_one(struct of_device *op)
  317. {
  318. struct device_node *dp = op->node;
  319. struct all_info *all;
  320. int linebytes, i, err;
  321. all = kzalloc(sizeof(*all), GFP_KERNEL);
  322. if (!all)
  323. return -ENOMEM;
  324. spin_lock_init(&all->par.lock);
  325. all->par.lowdepth =
  326. (of_find_property(dp, "tcx-8-bit", NULL) != NULL);
  327. sbusfb_fill_var(&all->info.var, dp->node, 8);
  328. all->info.var.red.length = 8;
  329. all->info.var.green.length = 8;
  330. all->info.var.blue.length = 8;
  331. linebytes = of_getintprop_default(dp, "linebytes",
  332. all->info.var.xres);
  333. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  334. all->par.tec = of_ioremap(&op->resource[7], 0,
  335. sizeof(struct tcx_tec), "tcx tec");
  336. all->par.thc = of_ioremap(&op->resource[9], 0,
  337. sizeof(struct tcx_thc), "tcx thc");
  338. all->par.bt = of_ioremap(&op->resource[8], 0,
  339. sizeof(struct bt_regs), "tcx dac");
  340. all->info.screen_base = of_ioremap(&op->resource[0], 0,
  341. all->par.fbsize, "tcx ram");
  342. if (!all->par.tec || !all->par.thc ||
  343. !all->par.bt || !all->info.screen_base) {
  344. tcx_unmap_regs(op, all);
  345. kfree(all);
  346. return -ENOMEM;
  347. }
  348. memcpy(&all->par.mmap_map, &__tcx_mmap_map, sizeof(all->par.mmap_map));
  349. if (!all->par.lowdepth) {
  350. all->par.cplane = of_ioremap(&op->resource[4], 0,
  351. all->par.fbsize * sizeof(u32),
  352. "tcx cplane");
  353. if (!all->par.cplane) {
  354. tcx_unmap_regs(op, all);
  355. kfree(all);
  356. return -ENOMEM;
  357. }
  358. } else {
  359. all->par.mmap_map[1].size = SBUS_MMAP_EMPTY;
  360. all->par.mmap_map[4].size = SBUS_MMAP_EMPTY;
  361. all->par.mmap_map[5].size = SBUS_MMAP_EMPTY;
  362. all->par.mmap_map[6].size = SBUS_MMAP_EMPTY;
  363. }
  364. all->par.physbase = 0;
  365. all->par.which_io = op->resource[0].flags & IORESOURCE_BITS;
  366. for (i = 0; i < TCX_MMAP_ENTRIES; i++) {
  367. int j;
  368. switch (i) {
  369. case 10:
  370. j = 12;
  371. break;
  372. case 11: case 12:
  373. j = i - 1;
  374. break;
  375. default:
  376. j = i;
  377. break;
  378. };
  379. all->par.mmap_map[i].poff = op->resource[j].start;
  380. }
  381. all->info.flags = FBINFO_DEFAULT;
  382. all->info.fbops = &tcx_ops;
  383. all->info.par = &all->par;
  384. /* Initialize brooktree DAC. */
  385. sbus_writel(0x04 << 24, &all->par.bt->addr); /* color planes */
  386. sbus_writel(0xff << 24, &all->par.bt->control);
  387. sbus_writel(0x05 << 24, &all->par.bt->addr);
  388. sbus_writel(0x00 << 24, &all->par.bt->control);
  389. sbus_writel(0x06 << 24, &all->par.bt->addr); /* overlay plane */
  390. sbus_writel(0x73 << 24, &all->par.bt->control);
  391. sbus_writel(0x07 << 24, &all->par.bt->addr);
  392. sbus_writel(0x00 << 24, &all->par.bt->control);
  393. tcx_reset(&all->info);
  394. tcx_blank(FB_BLANK_UNBLANK, &all->info);
  395. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  396. tcx_unmap_regs(op, all);
  397. kfree(all);
  398. return -ENOMEM;
  399. }
  400. fb_set_cmap(&all->info.cmap, &all->info);
  401. tcx_init_fix(&all->info, linebytes);
  402. err = register_framebuffer(&all->info);
  403. if (err < 0) {
  404. fb_dealloc_cmap(&all->info.cmap);
  405. tcx_unmap_regs(op, all);
  406. kfree(all);
  407. return err;
  408. }
  409. dev_set_drvdata(&op->dev, all);
  410. printk("%s: TCX at %lx:%lx, %s\n",
  411. dp->full_name,
  412. all->par.which_io,
  413. op->resource[0].start,
  414. all->par.lowdepth ? "8-bit only" : "24-bit depth");
  415. return 0;
  416. }
  417. static int __devinit tcx_probe(struct of_device *dev, const struct of_device_id *match)
  418. {
  419. struct of_device *op = to_of_device(&dev->dev);
  420. return tcx_init_one(op);
  421. }
  422. static int __devexit tcx_remove(struct of_device *op)
  423. {
  424. struct all_info *all = dev_get_drvdata(&op->dev);
  425. unregister_framebuffer(&all->info);
  426. fb_dealloc_cmap(&all->info.cmap);
  427. tcx_unmap_regs(op, all);
  428. kfree(all);
  429. dev_set_drvdata(&op->dev, NULL);
  430. return 0;
  431. }
  432. static struct of_device_id tcx_match[] = {
  433. {
  434. .name = "SUNW,tcx",
  435. },
  436. {},
  437. };
  438. MODULE_DEVICE_TABLE(of, tcx_match);
  439. static struct of_platform_driver tcx_driver = {
  440. .name = "tcx",
  441. .match_table = tcx_match,
  442. .probe = tcx_probe,
  443. .remove = __devexit_p(tcx_remove),
  444. };
  445. int __init tcx_init(void)
  446. {
  447. if (fb_get_options("tcxfb", NULL))
  448. return -ENODEV;
  449. return of_register_driver(&tcx_driver, &of_bus_type);
  450. }
  451. void __exit tcx_exit(void)
  452. {
  453. of_unregister_driver(&tcx_driver);
  454. }
  455. module_init(tcx_init);
  456. module_exit(tcx_exit);
  457. MODULE_DESCRIPTION("framebuffer driver for TCX chipsets");
  458. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  459. MODULE_VERSION("2.0");
  460. MODULE_LICENSE("GPL");