p9100.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /* p9100.c: P9100 frame buffer driver
  2. *
  3. * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
  4. * Copyright 1999 Derrick J Brashear (shadow@dementia.org)
  5. *
  6. * Driver layout based loosely on tgafb.c, see that file for credits.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/string.h>
  12. #include <linux/slab.h>
  13. #include <linux/delay.h>
  14. #include <linux/init.h>
  15. #include <linux/fb.h>
  16. #include <linux/mm.h>
  17. #include <asm/io.h>
  18. #include <asm/prom.h>
  19. #include <asm/of_device.h>
  20. #include <asm/fbio.h>
  21. #include "sbuslib.h"
  22. /*
  23. * Local functions.
  24. */
  25. static int p9100_setcolreg(unsigned, unsigned, unsigned, unsigned,
  26. unsigned, struct fb_info *);
  27. static int p9100_blank(int, struct fb_info *);
  28. static int p9100_mmap(struct fb_info *, struct vm_area_struct *);
  29. static int p9100_ioctl(struct fb_info *, unsigned int, unsigned long);
  30. /*
  31. * Frame buffer operations
  32. */
  33. static struct fb_ops p9100_ops = {
  34. .owner = THIS_MODULE,
  35. .fb_setcolreg = p9100_setcolreg,
  36. .fb_blank = p9100_blank,
  37. .fb_fillrect = cfb_fillrect,
  38. .fb_copyarea = cfb_copyarea,
  39. .fb_imageblit = cfb_imageblit,
  40. .fb_mmap = p9100_mmap,
  41. .fb_ioctl = p9100_ioctl,
  42. #ifdef CONFIG_COMPAT
  43. .fb_compat_ioctl = sbusfb_compat_ioctl,
  44. #endif
  45. };
  46. /* P9100 control registers */
  47. #define P9100_SYSCTL_OFF 0x0UL
  48. #define P9100_VIDEOCTL_OFF 0x100UL
  49. #define P9100_VRAMCTL_OFF 0x180UL
  50. #define P9100_RAMDAC_OFF 0x200UL
  51. #define P9100_VIDEOCOPROC_OFF 0x400UL
  52. /* P9100 command registers */
  53. #define P9100_CMD_OFF 0x0UL
  54. /* P9100 framebuffer memory */
  55. #define P9100_FB_OFF 0x0UL
  56. /* 3 bits: 2=8bpp 3=16bpp 5=32bpp 7=24bpp */
  57. #define SYS_CONFIG_PIXELSIZE_SHIFT 26
  58. #define SCREENPAINT_TIMECTL1_ENABLE_VIDEO 0x20 /* 0 = off, 1 = on */
  59. struct p9100_regs {
  60. /* Registers for the system control */
  61. u32 sys_base;
  62. u32 sys_config;
  63. u32 sys_intr;
  64. u32 sys_int_ena;
  65. u32 sys_alt_rd;
  66. u32 sys_alt_wr;
  67. u32 sys_xxx[58];
  68. /* Registers for the video control */
  69. u32 vid_base;
  70. u32 vid_hcnt;
  71. u32 vid_htotal;
  72. u32 vid_hsync_rise;
  73. u32 vid_hblank_rise;
  74. u32 vid_hblank_fall;
  75. u32 vid_hcnt_preload;
  76. u32 vid_vcnt;
  77. u32 vid_vlen;
  78. u32 vid_vsync_rise;
  79. u32 vid_vblank_rise;
  80. u32 vid_vblank_fall;
  81. u32 vid_vcnt_preload;
  82. u32 vid_screenpaint_addr;
  83. u32 vid_screenpaint_timectl1;
  84. u32 vid_screenpaint_qsfcnt;
  85. u32 vid_screenpaint_timectl2;
  86. u32 vid_xxx[15];
  87. /* Registers for the video control */
  88. u32 vram_base;
  89. u32 vram_memcfg;
  90. u32 vram_refresh_pd;
  91. u32 vram_refresh_cnt;
  92. u32 vram_raslo_max;
  93. u32 vram_raslo_cur;
  94. u32 pwrup_cfg;
  95. u32 vram_xxx[25];
  96. /* Registers for IBM RGB528 Palette */
  97. u32 ramdac_cmap_wridx;
  98. u32 ramdac_palette_data;
  99. u32 ramdac_pixel_mask;
  100. u32 ramdac_palette_rdaddr;
  101. u32 ramdac_idx_lo;
  102. u32 ramdac_idx_hi;
  103. u32 ramdac_idx_data;
  104. u32 ramdac_idx_ctl;
  105. u32 ramdac_xxx[1784];
  106. };
  107. struct p9100_cmd_parameng {
  108. u32 parameng_status;
  109. u32 parameng_bltcmd;
  110. u32 parameng_quadcmd;
  111. };
  112. struct p9100_par {
  113. spinlock_t lock;
  114. struct p9100_regs __iomem *regs;
  115. u32 flags;
  116. #define P9100_FLAG_BLANKED 0x00000001
  117. unsigned long physbase;
  118. unsigned long which_io;
  119. unsigned long fbsize;
  120. };
  121. /**
  122. * p9100_setcolreg - Optional function. Sets a color register.
  123. * @regno: boolean, 0 copy local, 1 get_user() function
  124. * @red: frame buffer colormap structure
  125. * @green: The green value which can be up to 16 bits wide
  126. * @blue: The blue value which can be up to 16 bits wide.
  127. * @transp: If supported the alpha value which can be up to 16 bits wide.
  128. * @info: frame buffer info structure
  129. */
  130. static int p9100_setcolreg(unsigned regno,
  131. unsigned red, unsigned green, unsigned blue,
  132. unsigned transp, struct fb_info *info)
  133. {
  134. struct p9100_par *par = (struct p9100_par *) info->par;
  135. struct p9100_regs __iomem *regs = par->regs;
  136. unsigned long flags;
  137. if (regno >= 256)
  138. return 1;
  139. red >>= 8;
  140. green >>= 8;
  141. blue >>= 8;
  142. spin_lock_irqsave(&par->lock, flags);
  143. sbus_writel((regno << 16), &regs->ramdac_cmap_wridx);
  144. sbus_writel((red << 16), &regs->ramdac_palette_data);
  145. sbus_writel((green << 16), &regs->ramdac_palette_data);
  146. sbus_writel((blue << 16), &regs->ramdac_palette_data);
  147. spin_unlock_irqrestore(&par->lock, flags);
  148. return 0;
  149. }
  150. /**
  151. * p9100_blank - Optional function. Blanks the display.
  152. * @blank_mode: the blank mode we want.
  153. * @info: frame buffer structure that represents a single frame buffer
  154. */
  155. static int
  156. p9100_blank(int blank, struct fb_info *info)
  157. {
  158. struct p9100_par *par = (struct p9100_par *) info->par;
  159. struct p9100_regs __iomem *regs = par->regs;
  160. unsigned long flags;
  161. u32 val;
  162. spin_lock_irqsave(&par->lock, flags);
  163. switch (blank) {
  164. case FB_BLANK_UNBLANK: /* Unblanking */
  165. val = sbus_readl(&regs->vid_screenpaint_timectl1);
  166. val |= SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
  167. sbus_writel(val, &regs->vid_screenpaint_timectl1);
  168. par->flags &= ~P9100_FLAG_BLANKED;
  169. break;
  170. case FB_BLANK_NORMAL: /* Normal blanking */
  171. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  172. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  173. case FB_BLANK_POWERDOWN: /* Poweroff */
  174. val = sbus_readl(&regs->vid_screenpaint_timectl1);
  175. val &= ~SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
  176. sbus_writel(val, &regs->vid_screenpaint_timectl1);
  177. par->flags |= P9100_FLAG_BLANKED;
  178. break;
  179. }
  180. spin_unlock_irqrestore(&par->lock, flags);
  181. return 0;
  182. }
  183. static struct sbus_mmap_map p9100_mmap_map[] = {
  184. { CG3_MMAP_OFFSET, 0, SBUS_MMAP_FBSIZE(1) },
  185. { 0, 0, 0 }
  186. };
  187. static int p9100_mmap(struct fb_info *info, struct vm_area_struct *vma)
  188. {
  189. struct p9100_par *par = (struct p9100_par *)info->par;
  190. return sbusfb_mmap_helper(p9100_mmap_map,
  191. par->physbase, par->fbsize,
  192. par->which_io, vma);
  193. }
  194. static int p9100_ioctl(struct fb_info *info, unsigned int cmd,
  195. unsigned long arg)
  196. {
  197. struct p9100_par *par = (struct p9100_par *) info->par;
  198. /* Make it look like a cg3. */
  199. return sbusfb_ioctl_helper(cmd, arg, info,
  200. FBTYPE_SUN3COLOR, 8, par->fbsize);
  201. }
  202. /*
  203. * Initialisation
  204. */
  205. static void p9100_init_fix(struct fb_info *info, int linebytes, struct device_node *dp)
  206. {
  207. strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
  208. info->fix.type = FB_TYPE_PACKED_PIXELS;
  209. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  210. info->fix.line_length = linebytes;
  211. info->fix.accel = FB_ACCEL_SUN_CGTHREE;
  212. }
  213. struct all_info {
  214. struct fb_info info;
  215. struct p9100_par par;
  216. };
  217. static int __devinit p9100_init_one(struct of_device *op)
  218. {
  219. struct device_node *dp = op->node;
  220. struct all_info *all;
  221. int linebytes, err;
  222. all = kzalloc(sizeof(*all), GFP_KERNEL);
  223. if (!all)
  224. return -ENOMEM;
  225. spin_lock_init(&all->par.lock);
  226. /* This is the framebuffer and the only resource apps can mmap. */
  227. all->par.physbase = op->resource[2].start;
  228. all->par.which_io = op->resource[2].flags & IORESOURCE_BITS;
  229. sbusfb_fill_var(&all->info.var, dp->node, 8);
  230. all->info.var.red.length = 8;
  231. all->info.var.green.length = 8;
  232. all->info.var.blue.length = 8;
  233. linebytes = of_getintprop_default(dp, "linebytes",
  234. all->info.var.xres);
  235. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  236. all->par.regs = of_ioremap(&op->resource[0], 0,
  237. sizeof(struct p9100_regs), "p9100 regs");
  238. if (!all->par.regs) {
  239. kfree(all);
  240. return -ENOMEM;
  241. }
  242. all->info.flags = FBINFO_DEFAULT;
  243. all->info.fbops = &p9100_ops;
  244. all->info.screen_base = of_ioremap(&op->resource[2], 0,
  245. all->par.fbsize, "p9100 ram");
  246. if (!all->info.screen_base) {
  247. of_iounmap(&op->resource[0],
  248. all->par.regs, sizeof(struct p9100_regs));
  249. kfree(all);
  250. return -ENOMEM;
  251. }
  252. all->info.par = &all->par;
  253. p9100_blank(0, &all->info);
  254. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  255. of_iounmap(&op->resource[0],
  256. all->par.regs, sizeof(struct p9100_regs));
  257. of_iounmap(&op->resource[2],
  258. all->info.screen_base, all->par.fbsize);
  259. kfree(all);
  260. return -ENOMEM;
  261. }
  262. p9100_init_fix(&all->info, linebytes, dp);
  263. err = register_framebuffer(&all->info);
  264. if (err < 0) {
  265. fb_dealloc_cmap(&all->info.cmap);
  266. of_iounmap(&op->resource[0],
  267. all->par.regs, sizeof(struct p9100_regs));
  268. of_iounmap(&op->resource[2],
  269. all->info.screen_base, all->par.fbsize);
  270. kfree(all);
  271. return err;
  272. }
  273. fb_set_cmap(&all->info.cmap, &all->info);
  274. dev_set_drvdata(&op->dev, all);
  275. printk("%s: p9100 at %lx:%lx\n",
  276. dp->full_name,
  277. all->par.which_io, all->par.physbase);
  278. return 0;
  279. }
  280. static int __devinit p9100_probe(struct of_device *dev, const struct of_device_id *match)
  281. {
  282. struct of_device *op = to_of_device(&dev->dev);
  283. return p9100_init_one(op);
  284. }
  285. static int __devexit p9100_remove(struct of_device *op)
  286. {
  287. struct all_info *all = dev_get_drvdata(&op->dev);
  288. unregister_framebuffer(&all->info);
  289. fb_dealloc_cmap(&all->info.cmap);
  290. of_iounmap(&op->resource[0], all->par.regs, sizeof(struct p9100_regs));
  291. of_iounmap(&op->resource[2], all->info.screen_base, all->par.fbsize);
  292. kfree(all);
  293. dev_set_drvdata(&op->dev, NULL);
  294. return 0;
  295. }
  296. static struct of_device_id p9100_match[] = {
  297. {
  298. .name = "p9100",
  299. },
  300. {},
  301. };
  302. MODULE_DEVICE_TABLE(of, p9100_match);
  303. static struct of_platform_driver p9100_driver = {
  304. .name = "p9100",
  305. .match_table = p9100_match,
  306. .probe = p9100_probe,
  307. .remove = __devexit_p(p9100_remove),
  308. };
  309. static int __init p9100_init(void)
  310. {
  311. if (fb_get_options("p9100fb", NULL))
  312. return -ENODEV;
  313. return of_register_driver(&p9100_driver, &of_bus_type);
  314. }
  315. static void __exit p9100_exit(void)
  316. {
  317. of_unregister_driver(&p9100_driver);
  318. }
  319. module_init(p9100_init);
  320. module_exit(p9100_exit);
  321. MODULE_DESCRIPTION("framebuffer driver for P9100 chipsets");
  322. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  323. MODULE_VERSION("2.0");
  324. MODULE_LICENSE("GPL");