p9100.c 8.8 KB

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