p9100.c 9.5 KB

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