tcx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /* tcx.c: TCX frame buffer driver
  2. *
  3. * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  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/sbus.h>
  21. #include <asm/oplib.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. volatile u32 tec_matrix;
  71. volatile u32 tec_clip;
  72. volatile u32 tec_vdc;
  73. };
  74. struct tcx_thc {
  75. volatile u32 thc_rev;
  76. u32 thc_pad0[511];
  77. volatile u32 thc_hs; /* hsync timing */
  78. volatile u32 thc_hsdvs;
  79. volatile u32 thc_hd;
  80. volatile u32 thc_vs; /* vsync timing */
  81. volatile u32 thc_vd;
  82. volatile u32 thc_refresh;
  83. volatile u32 thc_misc;
  84. u32 thc_pad1[56];
  85. volatile u32 thc_cursxy; /* cursor x,y position (16 bits each) */
  86. volatile u32 thc_cursmask[32]; /* cursor mask bits */
  87. volatile u32 thc_cursbits[32]; /* what to show where mask enabled */
  88. };
  89. struct bt_regs {
  90. volatile u32 addr;
  91. volatile u32 color_map;
  92. volatile u32 control;
  93. volatile 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. volatile u32 __iomem *cplane;
  102. u32 flags;
  103. #define TCX_FLAG_BLANKED 0x00000001
  104. unsigned long physbase;
  105. unsigned long fbsize;
  106. struct sbus_mmap_map mmap_map[TCX_MMAP_ENTRIES];
  107. int lowdepth;
  108. struct sbus_dev *sdev;
  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. volatile 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->sdev->reg_addrs[0].which_io,
  266. vma);
  267. }
  268. static int tcx_ioctl(struct fb_info *info, unsigned int cmd,
  269. unsigned long arg)
  270. {
  271. struct tcx_par *par = (struct tcx_par *) info->par;
  272. return sbusfb_ioctl_helper(cmd, arg, info,
  273. FBTYPE_TCXCOLOR,
  274. (par->lowdepth ? 8 : 24),
  275. par->fbsize);
  276. }
  277. /*
  278. * Initialisation
  279. */
  280. static void
  281. tcx_init_fix(struct fb_info *info, int linebytes)
  282. {
  283. struct tcx_par *par = (struct tcx_par *)info->par;
  284. const char *tcx_name;
  285. if (par->lowdepth)
  286. tcx_name = "TCX8";
  287. else
  288. tcx_name = "TCX24";
  289. strlcpy(info->fix.id, tcx_name, sizeof(info->fix.id));
  290. info->fix.type = FB_TYPE_PACKED_PIXELS;
  291. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  292. info->fix.line_length = linebytes;
  293. info->fix.accel = FB_ACCEL_SUN_TCX;
  294. }
  295. struct all_info {
  296. struct fb_info info;
  297. struct tcx_par par;
  298. struct list_head list;
  299. };
  300. static LIST_HEAD(tcx_list);
  301. static void tcx_init_one(struct sbus_dev *sdev)
  302. {
  303. struct all_info *all;
  304. int linebytes, i;
  305. all = kmalloc(sizeof(*all), GFP_KERNEL);
  306. if (!all) {
  307. printk(KERN_ERR "tcx: Cannot allocate memory.\n");
  308. return;
  309. }
  310. memset(all, 0, sizeof(*all));
  311. INIT_LIST_HEAD(&all->list);
  312. spin_lock_init(&all->par.lock);
  313. all->par.sdev = sdev;
  314. all->par.lowdepth = prom_getbool(sdev->prom_node, "tcx-8-bit");
  315. sbusfb_fill_var(&all->info.var, sdev->prom_node, 8);
  316. all->info.var.red.length = 8;
  317. all->info.var.green.length = 8;
  318. all->info.var.blue.length = 8;
  319. linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
  320. all->info.var.xres);
  321. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  322. all->par.tec = sbus_ioremap(&sdev->resource[7], 0,
  323. sizeof(struct tcx_tec), "tcx tec");
  324. all->par.thc = sbus_ioremap(&sdev->resource[9], 0,
  325. sizeof(struct tcx_thc), "tcx thc");
  326. all->par.bt = sbus_ioremap(&sdev->resource[8], 0,
  327. sizeof(struct bt_regs), "tcx dac");
  328. memcpy(&all->par.mmap_map, &__tcx_mmap_map, sizeof(all->par.mmap_map));
  329. if (!all->par.lowdepth) {
  330. all->par.cplane = sbus_ioremap(&sdev->resource[4], 0,
  331. all->par.fbsize * sizeof(u32), "tcx cplane");
  332. } else {
  333. all->par.mmap_map[1].size = SBUS_MMAP_EMPTY;
  334. all->par.mmap_map[4].size = SBUS_MMAP_EMPTY;
  335. all->par.mmap_map[5].size = SBUS_MMAP_EMPTY;
  336. all->par.mmap_map[6].size = SBUS_MMAP_EMPTY;
  337. }
  338. all->par.physbase = 0;
  339. for (i = 0; i < TCX_MMAP_ENTRIES; i++) {
  340. int j;
  341. switch (i) {
  342. case 10:
  343. j = 12;
  344. break;
  345. case 11: case 12:
  346. j = i - 1;
  347. break;
  348. default:
  349. j = i;
  350. break;
  351. };
  352. all->par.mmap_map[i].poff = sdev->reg_addrs[j].phys_addr;
  353. }
  354. all->info.flags = FBINFO_DEFAULT;
  355. all->info.fbops = &tcx_ops;
  356. #ifdef CONFIG_SPARC32
  357. all->info.screen_base = (char __iomem *)
  358. prom_getintdefault(sdev->prom_node, "address", 0);
  359. #endif
  360. if (!all->info.screen_base)
  361. all->info.screen_base = sbus_ioremap(&sdev->resource[0], 0,
  362. all->par.fbsize, "tcx ram");
  363. all->info.par = &all->par;
  364. /* Initialize brooktree DAC. */
  365. sbus_writel(0x04 << 24, &all->par.bt->addr); /* color planes */
  366. sbus_writel(0xff << 24, &all->par.bt->control);
  367. sbus_writel(0x05 << 24, &all->par.bt->addr);
  368. sbus_writel(0x00 << 24, &all->par.bt->control);
  369. sbus_writel(0x06 << 24, &all->par.bt->addr); /* overlay plane */
  370. sbus_writel(0x73 << 24, &all->par.bt->control);
  371. sbus_writel(0x07 << 24, &all->par.bt->addr);
  372. sbus_writel(0x00 << 24, &all->par.bt->control);
  373. tcx_reset(&all->info);
  374. tcx_blank(FB_BLANK_UNBLANK, &all->info);
  375. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  376. printk(KERN_ERR "tcx: Could not allocate color map.\n");
  377. kfree(all);
  378. return;
  379. }
  380. fb_set_cmap(&all->info.cmap, &all->info);
  381. tcx_init_fix(&all->info, linebytes);
  382. if (register_framebuffer(&all->info) < 0) {
  383. printk(KERN_ERR "tcx: Could not register framebuffer.\n");
  384. fb_dealloc_cmap(&all->info.cmap);
  385. kfree(all);
  386. return;
  387. }
  388. list_add(&all->list, &tcx_list);
  389. printk("tcx: %s at %lx:%lx, %s\n",
  390. sdev->prom_name,
  391. (long) sdev->reg_addrs[0].which_io,
  392. (long) sdev->reg_addrs[0].phys_addr,
  393. all->par.lowdepth ? "8-bit only" : "24-bit depth");
  394. }
  395. int __init tcx_init(void)
  396. {
  397. struct sbus_bus *sbus;
  398. struct sbus_dev *sdev;
  399. if (fb_get_options("tcxfb", NULL))
  400. return -ENODEV;
  401. for_all_sbusdev(sdev, sbus) {
  402. if (!strcmp(sdev->prom_name, "SUNW,tcx"))
  403. tcx_init_one(sdev);
  404. }
  405. return 0;
  406. }
  407. void __exit tcx_exit(void)
  408. {
  409. struct list_head *pos, *tmp;
  410. list_for_each_safe(pos, tmp, &tcx_list) {
  411. struct all_info *all = list_entry(pos, typeof(*all), list);
  412. unregister_framebuffer(&all->info);
  413. fb_dealloc_cmap(&all->info.cmap);
  414. kfree(all);
  415. }
  416. }
  417. int __init
  418. tcx_setup(char *arg)
  419. {
  420. /* No cmdline options yet... */
  421. return 0;
  422. }
  423. module_init(tcx_init);
  424. #ifdef MODULE
  425. module_exit(tcx_exit);
  426. #endif
  427. MODULE_DESCRIPTION("framebuffer driver for TCX chipsets");
  428. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  429. MODULE_LICENSE("GPL");