p9100.c 9.0 KB

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