blob: b6c3fc2db6328a2f187e7a35f1ac8448a3abeebd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* p9100.c: P9100 frame buffer driver
2 *
David S. Miller50312ce2006-06-29 14:35:52 -07003 * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 1999 Derrick J Brashear (shadow@dementia.org)
5 *
6 * Driver layout based loosely on tgafb.c, see that file for credits.
7 */
8
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/errno.h>
12#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/delay.h>
14#include <linux/init.h>
15#include <linux/fb.h>
16#include <linux/mm.h>
Robert Reif6cd5a862008-05-08 21:37:30 -070017#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/fbio.h>
21
22#include "sbuslib.h"
23
24/*
25 * Local functions.
26 */
27
28static int p9100_setcolreg(unsigned, unsigned, unsigned, unsigned,
29 unsigned, struct fb_info *);
30static int p9100_blank(int, struct fb_info *);
31
Christoph Hellwig216d5262006-01-14 13:21:25 -080032static int p9100_mmap(struct fb_info *, struct vm_area_struct *);
Christoph Hellwig67a66802006-01-14 13:21:25 -080033static int p9100_ioctl(struct fb_info *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*
36 * Frame buffer operations
37 */
38
39static struct fb_ops p9100_ops = {
40 .owner = THIS_MODULE,
41 .fb_setcolreg = p9100_setcolreg,
42 .fb_blank = p9100_blank,
43 .fb_fillrect = cfb_fillrect,
44 .fb_copyarea = cfb_copyarea,
45 .fb_imageblit = cfb_imageblit,
46 .fb_mmap = p9100_mmap,
47 .fb_ioctl = p9100_ioctl,
Christoph Hellwig9ffb83b2005-11-12 12:11:12 -080048#ifdef CONFIG_COMPAT
49 .fb_compat_ioctl = sbusfb_compat_ioctl,
50#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
53/* P9100 control registers */
54#define P9100_SYSCTL_OFF 0x0UL
55#define P9100_VIDEOCTL_OFF 0x100UL
56#define P9100_VRAMCTL_OFF 0x180UL
57#define P9100_RAMDAC_OFF 0x200UL
58#define P9100_VIDEOCOPROC_OFF 0x400UL
59
60/* P9100 command registers */
61#define P9100_CMD_OFF 0x0UL
62
63/* P9100 framebuffer memory */
64#define P9100_FB_OFF 0x0UL
65
66/* 3 bits: 2=8bpp 3=16bpp 5=32bpp 7=24bpp */
67#define SYS_CONFIG_PIXELSIZE_SHIFT 26
68
69#define SCREENPAINT_TIMECTL1_ENABLE_VIDEO 0x20 /* 0 = off, 1 = on */
70
71struct p9100_regs {
72 /* Registers for the system control */
David S. Miller50312ce2006-06-29 14:35:52 -070073 u32 sys_base;
74 u32 sys_config;
75 u32 sys_intr;
76 u32 sys_int_ena;
77 u32 sys_alt_rd;
78 u32 sys_alt_wr;
79 u32 sys_xxx[58];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 /* Registers for the video control */
David S. Miller50312ce2006-06-29 14:35:52 -070082 u32 vid_base;
83 u32 vid_hcnt;
84 u32 vid_htotal;
85 u32 vid_hsync_rise;
86 u32 vid_hblank_rise;
87 u32 vid_hblank_fall;
88 u32 vid_hcnt_preload;
89 u32 vid_vcnt;
90 u32 vid_vlen;
91 u32 vid_vsync_rise;
92 u32 vid_vblank_rise;
93 u32 vid_vblank_fall;
94 u32 vid_vcnt_preload;
95 u32 vid_screenpaint_addr;
96 u32 vid_screenpaint_timectl1;
97 u32 vid_screenpaint_qsfcnt;
98 u32 vid_screenpaint_timectl2;
99 u32 vid_xxx[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 /* Registers for the video control */
David S. Miller50312ce2006-06-29 14:35:52 -0700102 u32 vram_base;
103 u32 vram_memcfg;
104 u32 vram_refresh_pd;
105 u32 vram_refresh_cnt;
106 u32 vram_raslo_max;
107 u32 vram_raslo_cur;
108 u32 pwrup_cfg;
109 u32 vram_xxx[25];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 /* Registers for IBM RGB528 Palette */
David S. Miller50312ce2006-06-29 14:35:52 -0700112 u32 ramdac_cmap_wridx;
113 u32 ramdac_palette_data;
114 u32 ramdac_pixel_mask;
115 u32 ramdac_palette_rdaddr;
116 u32 ramdac_idx_lo;
117 u32 ramdac_idx_hi;
118 u32 ramdac_idx_data;
119 u32 ramdac_idx_ctl;
120 u32 ramdac_xxx[1784];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
123struct p9100_cmd_parameng {
David S. Miller50312ce2006-06-29 14:35:52 -0700124 u32 parameng_status;
125 u32 parameng_bltcmd;
126 u32 parameng_quadcmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct p9100_par {
130 spinlock_t lock;
131 struct p9100_regs __iomem *regs;
132
133 u32 flags;
134#define P9100_FLAG_BLANKED 0x00000001
135
David S. Miller50312ce2006-06-29 14:35:52 -0700136 unsigned long which_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137};
138
139/**
140 * p9100_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 */
148static int p9100_setcolreg(unsigned regno,
149 unsigned red, unsigned green, unsigned blue,
150 unsigned transp, struct fb_info *info)
151{
152 struct p9100_par *par = (struct p9100_par *) info->par;
153 struct p9100_regs __iomem *regs = par->regs;
154 unsigned long flags;
155
156 if (regno >= 256)
157 return 1;
158
159 red >>= 8;
160 green >>= 8;
161 blue >>= 8;
162
163 spin_lock_irqsave(&par->lock, flags);
164
165 sbus_writel((regno << 16), &regs->ramdac_cmap_wridx);
166 sbus_writel((red << 16), &regs->ramdac_palette_data);
167 sbus_writel((green << 16), &regs->ramdac_palette_data);
168 sbus_writel((blue << 16), &regs->ramdac_palette_data);
169
170 spin_unlock_irqrestore(&par->lock, flags);
171
172 return 0;
173}
174
175/**
176 * p9100_blank - Optional function. Blanks the display.
177 * @blank_mode: the blank mode we want.
178 * @info: frame buffer structure that represents a single frame buffer
179 */
180static int
181p9100_blank(int blank, struct fb_info *info)
182{
183 struct p9100_par *par = (struct p9100_par *) info->par;
184 struct p9100_regs __iomem *regs = par->regs;
185 unsigned long flags;
186 u32 val;
187
188 spin_lock_irqsave(&par->lock, flags);
189
190 switch (blank) {
191 case FB_BLANK_UNBLANK: /* Unblanking */
192 val = sbus_readl(&regs->vid_screenpaint_timectl1);
193 val |= SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
194 sbus_writel(val, &regs->vid_screenpaint_timectl1);
195 par->flags &= ~P9100_FLAG_BLANKED;
196 break;
197
198 case FB_BLANK_NORMAL: /* Normal blanking */
199 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
200 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
201 case FB_BLANK_POWERDOWN: /* Poweroff */
202 val = sbus_readl(&regs->vid_screenpaint_timectl1);
203 val &= ~SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
204 sbus_writel(val, &regs->vid_screenpaint_timectl1);
205 par->flags |= P9100_FLAG_BLANKED;
206 break;
207 }
208
209 spin_unlock_irqrestore(&par->lock, flags);
210
211 return 0;
212}
213
214static struct sbus_mmap_map p9100_mmap_map[] = {
215 { CG3_MMAP_OFFSET, 0, SBUS_MMAP_FBSIZE(1) },
216 { 0, 0, 0 }
217};
218
Christoph Hellwig216d5262006-01-14 13:21:25 -0800219static int p9100_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 struct p9100_par *par = (struct p9100_par *)info->par;
222
223 return sbusfb_mmap_helper(p9100_mmap_map,
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000224 info->fix.smem_start, info->fix.smem_len,
David S. Miller50312ce2006-06-29 14:35:52 -0700225 par->which_io, vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Christoph Hellwig67a66802006-01-14 13:21:25 -0800228static int p9100_ioctl(struct fb_info *info, unsigned int cmd,
229 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* Make it look like a cg3. */
232 return sbusfb_ioctl_helper(cmd, arg, info,
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000233 FBTYPE_SUN3COLOR, 8, info->fix.smem_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236/*
237 * Initialisation
238 */
239
David S. Miller50312ce2006-06-29 14:35:52 -0700240static void p9100_init_fix(struct fb_info *info, int linebytes, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
David S. Miller50312ce2006-06-29 14:35:52 -0700242 strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 info->fix.type = FB_TYPE_PACKED_PIXELS;
245 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
246
247 info->fix.line_length = linebytes;
248
249 info->fix.accel = FB_ACCEL_SUN_CGTHREE;
250}
251
Grant Likely2dc11582010-08-06 09:25:50 -0600252static int __devinit p9100_probe(struct platform_device *op, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Anatolij Gustschind4b8b2c2010-06-03 02:20:44 +0200254 struct device_node *dp = op->dev.of_node;
David S. Millerc7f439b2007-07-27 22:31:46 -0700255 struct fb_info *info;
256 struct p9100_par *par;
David S. Miller50312ce2006-06-29 14:35:52 -0700257 int linebytes, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
David S. Millerc7f439b2007-07-27 22:31:46 -0700259 info = framebuffer_alloc(sizeof(struct p9100_par), &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
David S. Millerc7f439b2007-07-27 22:31:46 -0700261 err = -ENOMEM;
262 if (!info)
263 goto out_err;
264 par = info->par;
265
266 spin_lock_init(&par->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 /* This is the framebuffer and the only resource apps can mmap. */
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000269 info->fix.smem_start = op->resource[2].start;
David S. Millerc7f439b2007-07-27 22:31:46 -0700270 par->which_io = op->resource[2].flags & IORESOURCE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Robert Reif6cd5a862008-05-08 21:37:30 -0700272 sbusfb_fill_var(&info->var, dp, 8);
David S. Millerc7f439b2007-07-27 22:31:46 -0700273 info->var.red.length = 8;
274 info->var.green.length = 8;
275 info->var.blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
David S. Millerc7f439b2007-07-27 22:31:46 -0700277 linebytes = of_getintprop_default(dp, "linebytes", info->var.xres);
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000278 info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
David S. Millerc7f439b2007-07-27 22:31:46 -0700280 par->regs = of_ioremap(&op->resource[0], 0,
281 sizeof(struct p9100_regs), "p9100 regs");
282 if (!par->regs)
283 goto out_release_fb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
David S. Millerc7f439b2007-07-27 22:31:46 -0700285 info->flags = FBINFO_DEFAULT;
286 info->fbops = &p9100_ops;
287 info->screen_base = of_ioremap(&op->resource[2], 0,
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000288 info->fix.smem_len, "p9100 ram");
David S. Millerc7f439b2007-07-27 22:31:46 -0700289 if (!info->screen_base)
290 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Robert Reif59f71372008-05-03 21:12:00 -0700292 p9100_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
David S. Millerc7f439b2007-07-27 22:31:46 -0700294 if (fb_alloc_cmap(&info->cmap, 256, 0))
295 goto out_unmap_screen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
David S. Millerc7f439b2007-07-27 22:31:46 -0700297 p9100_init_fix(info, linebytes, dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
David S. Millerc7f439b2007-07-27 22:31:46 -0700299 err = register_framebuffer(info);
300 if (err < 0)
301 goto out_dealloc_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
David S. Millerc7f439b2007-07-27 22:31:46 -0700303 fb_set_cmap(&info->cmap, info);
304
305 dev_set_drvdata(&op->dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Robert Reif194f1a682008-04-27 15:18:57 -0700307 printk(KERN_INFO "%s: p9100 at %lx:%lx\n",
David S. Miller50312ce2006-06-29 14:35:52 -0700308 dp->full_name,
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000309 par->which_io, info->fix.smem_start);
David S. Miller50312ce2006-06-29 14:35:52 -0700310
311 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
David S. Millerc7f439b2007-07-27 22:31:46 -0700313out_dealloc_cmap:
314 fb_dealloc_cmap(&info->cmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
David S. Millerc7f439b2007-07-27 22:31:46 -0700316out_unmap_screen:
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000317 of_iounmap(&op->resource[2], info->screen_base, info->fix.smem_len);
David S. Millerc7f439b2007-07-27 22:31:46 -0700318
319out_unmap_regs:
320 of_iounmap(&op->resource[0], par->regs, sizeof(struct p9100_regs));
321
322out_release_fb:
323 framebuffer_release(info);
324
325out_err:
326 return err;
David S. Miller50312ce2006-06-29 14:35:52 -0700327}
328
Grant Likely2dc11582010-08-06 09:25:50 -0600329static int __devexit p9100_remove(struct platform_device *op)
David S. Miller50312ce2006-06-29 14:35:52 -0700330{
David S. Millerc7f439b2007-07-27 22:31:46 -0700331 struct fb_info *info = dev_get_drvdata(&op->dev);
332 struct p9100_par *par = info->par;
David S. Miller50312ce2006-06-29 14:35:52 -0700333
David S. Millerc7f439b2007-07-27 22:31:46 -0700334 unregister_framebuffer(info);
335 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700336
David S. Millerc7f439b2007-07-27 22:31:46 -0700337 of_iounmap(&op->resource[0], par->regs, sizeof(struct p9100_regs));
Krzysztof Helt0d76cb22009-05-04 10:42:57 +0000338 of_iounmap(&op->resource[2], info->screen_base, info->fix.smem_len);
David S. Miller50312ce2006-06-29 14:35:52 -0700339
David S. Millerc7f439b2007-07-27 22:31:46 -0700340 framebuffer_release(info);
David S. Miller50312ce2006-06-29 14:35:52 -0700341
David S. Millere3a411a32006-12-28 21:01:32 -0800342 dev_set_drvdata(&op->dev, NULL);
David S. Miller50312ce2006-06-29 14:35:52 -0700343
344 return 0;
345}
346
David S. Millerfd098312008-08-31 01:23:17 -0700347static const struct of_device_id p9100_match[] = {
David S. Miller50312ce2006-06-29 14:35:52 -0700348 {
349 .name = "p9100",
350 },
351 {},
352};
353MODULE_DEVICE_TABLE(of, p9100_match);
354
355static struct of_platform_driver p9100_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700356 .driver = {
357 .name = "p9100",
358 .owner = THIS_MODULE,
359 .of_match_table = p9100_match,
360 },
David S. Miller50312ce2006-06-29 14:35:52 -0700361 .probe = p9100_probe,
362 .remove = __devexit_p(p9100_remove),
363};
364
365static int __init p9100_init(void)
366{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (fb_get_options("p9100fb", NULL))
368 return -ENODEV;
369
Grant Likely1ab1d632010-06-24 15:14:37 -0600370 return of_register_platform_driver(&p9100_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
David S. Miller50312ce2006-06-29 14:35:52 -0700373static void __exit p9100_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Grant Likely1ab1d632010-06-24 15:14:37 -0600375 of_unregister_platform_driver(&p9100_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378module_init(p9100_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379module_exit(p9100_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381MODULE_DESCRIPTION("framebuffer driver for P9100 chipsets");
David S. Miller50312ce2006-06-29 14:35:52 -0700382MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
383MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384MODULE_LICENSE("GPL");