tcx.c 12 KB

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