blob: 9e903454ffc138b053c4ad32f7b12dd3636e8f94 [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>
13#include <linux/slab.h>
14#include <linux/delay.h>
15#include <linux/init.h>
16#include <linux/fb.h>
17#include <linux/mm.h>
Robert Reif6cd5a862008-05-08 21:37:30 -070018#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/fbio.h>
22
23#include "sbuslib.h"
24
25/*
26 * Local functions.
27 */
28
29static int p9100_setcolreg(unsigned, unsigned, unsigned, unsigned,
30 unsigned, struct fb_info *);
31static int p9100_blank(int, struct fb_info *);
32
Christoph Hellwig216d5262006-01-14 13:21:25 -080033static int p9100_mmap(struct fb_info *, struct vm_area_struct *);
Christoph Hellwig67a66802006-01-14 13:21:25 -080034static int p9100_ioctl(struct fb_info *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/*
37 * Frame buffer operations
38 */
39
40static struct fb_ops p9100_ops = {
41 .owner = THIS_MODULE,
42 .fb_setcolreg = p9100_setcolreg,
43 .fb_blank = p9100_blank,
44 .fb_fillrect = cfb_fillrect,
45 .fb_copyarea = cfb_copyarea,
46 .fb_imageblit = cfb_imageblit,
47 .fb_mmap = p9100_mmap,
48 .fb_ioctl = p9100_ioctl,
Christoph Hellwig9ffb83b2005-11-12 12:11:12 -080049#ifdef CONFIG_COMPAT
50 .fb_compat_ioctl = sbusfb_compat_ioctl,
51#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54/* P9100 control registers */
55#define P9100_SYSCTL_OFF 0x0UL
56#define P9100_VIDEOCTL_OFF 0x100UL
57#define P9100_VRAMCTL_OFF 0x180UL
58#define P9100_RAMDAC_OFF 0x200UL
59#define P9100_VIDEOCOPROC_OFF 0x400UL
60
61/* P9100 command registers */
62#define P9100_CMD_OFF 0x0UL
63
64/* P9100 framebuffer memory */
65#define P9100_FB_OFF 0x0UL
66
67/* 3 bits: 2=8bpp 3=16bpp 5=32bpp 7=24bpp */
68#define SYS_CONFIG_PIXELSIZE_SHIFT 26
69
70#define SCREENPAINT_TIMECTL1_ENABLE_VIDEO 0x20 /* 0 = off, 1 = on */
71
72struct p9100_regs {
73 /* Registers for the system control */
David S. Miller50312ce2006-06-29 14:35:52 -070074 u32 sys_base;
75 u32 sys_config;
76 u32 sys_intr;
77 u32 sys_int_ena;
78 u32 sys_alt_rd;
79 u32 sys_alt_wr;
80 u32 sys_xxx[58];
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 /* Registers for the video control */
David S. Miller50312ce2006-06-29 14:35:52 -070083 u32 vid_base;
84 u32 vid_hcnt;
85 u32 vid_htotal;
86 u32 vid_hsync_rise;
87 u32 vid_hblank_rise;
88 u32 vid_hblank_fall;
89 u32 vid_hcnt_preload;
90 u32 vid_vcnt;
91 u32 vid_vlen;
92 u32 vid_vsync_rise;
93 u32 vid_vblank_rise;
94 u32 vid_vblank_fall;
95 u32 vid_vcnt_preload;
96 u32 vid_screenpaint_addr;
97 u32 vid_screenpaint_timectl1;
98 u32 vid_screenpaint_qsfcnt;
99 u32 vid_screenpaint_timectl2;
100 u32 vid_xxx[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 /* Registers for the video control */
David S. Miller50312ce2006-06-29 14:35:52 -0700103 u32 vram_base;
104 u32 vram_memcfg;
105 u32 vram_refresh_pd;
106 u32 vram_refresh_cnt;
107 u32 vram_raslo_max;
108 u32 vram_raslo_cur;
109 u32 pwrup_cfg;
110 u32 vram_xxx[25];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 /* Registers for IBM RGB528 Palette */
David S. Miller50312ce2006-06-29 14:35:52 -0700113 u32 ramdac_cmap_wridx;
114 u32 ramdac_palette_data;
115 u32 ramdac_pixel_mask;
116 u32 ramdac_palette_rdaddr;
117 u32 ramdac_idx_lo;
118 u32 ramdac_idx_hi;
119 u32 ramdac_idx_data;
120 u32 ramdac_idx_ctl;
121 u32 ramdac_xxx[1784];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
124struct p9100_cmd_parameng {
David S. Miller50312ce2006-06-29 14:35:52 -0700125 u32 parameng_status;
126 u32 parameng_bltcmd;
127 u32 parameng_quadcmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct p9100_par {
131 spinlock_t lock;
132 struct p9100_regs __iomem *regs;
133
134 u32 flags;
135#define P9100_FLAG_BLANKED 0x00000001
136
137 unsigned long physbase;
David S. Miller50312ce2006-06-29 14:35:52 -0700138 unsigned long which_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 unsigned long fbsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
142/**
143 * p9100_setcolreg - Optional function. Sets a color register.
144 * @regno: boolean, 0 copy local, 1 get_user() function
145 * @red: frame buffer colormap structure
146 * @green: The green value which can be up to 16 bits wide
147 * @blue: The blue value which can be up to 16 bits wide.
148 * @transp: If supported the alpha value which can be up to 16 bits wide.
149 * @info: frame buffer info structure
150 */
151static int p9100_setcolreg(unsigned regno,
152 unsigned red, unsigned green, unsigned blue,
153 unsigned transp, struct fb_info *info)
154{
155 struct p9100_par *par = (struct p9100_par *) info->par;
156 struct p9100_regs __iomem *regs = par->regs;
157 unsigned long flags;
158
159 if (regno >= 256)
160 return 1;
161
162 red >>= 8;
163 green >>= 8;
164 blue >>= 8;
165
166 spin_lock_irqsave(&par->lock, flags);
167
168 sbus_writel((regno << 16), &regs->ramdac_cmap_wridx);
169 sbus_writel((red << 16), &regs->ramdac_palette_data);
170 sbus_writel((green << 16), &regs->ramdac_palette_data);
171 sbus_writel((blue << 16), &regs->ramdac_palette_data);
172
173 spin_unlock_irqrestore(&par->lock, flags);
174
175 return 0;
176}
177
178/**
179 * p9100_blank - Optional function. Blanks the display.
180 * @blank_mode: the blank mode we want.
181 * @info: frame buffer structure that represents a single frame buffer
182 */
183static int
184p9100_blank(int blank, struct fb_info *info)
185{
186 struct p9100_par *par = (struct p9100_par *) info->par;
187 struct p9100_regs __iomem *regs = par->regs;
188 unsigned long flags;
189 u32 val;
190
191 spin_lock_irqsave(&par->lock, flags);
192
193 switch (blank) {
194 case FB_BLANK_UNBLANK: /* Unblanking */
195 val = sbus_readl(&regs->vid_screenpaint_timectl1);
196 val |= SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
197 sbus_writel(val, &regs->vid_screenpaint_timectl1);
198 par->flags &= ~P9100_FLAG_BLANKED;
199 break;
200
201 case FB_BLANK_NORMAL: /* Normal blanking */
202 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
203 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
204 case FB_BLANK_POWERDOWN: /* Poweroff */
205 val = sbus_readl(&regs->vid_screenpaint_timectl1);
206 val &= ~SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
207 sbus_writel(val, &regs->vid_screenpaint_timectl1);
208 par->flags |= P9100_FLAG_BLANKED;
209 break;
210 }
211
212 spin_unlock_irqrestore(&par->lock, flags);
213
214 return 0;
215}
216
217static struct sbus_mmap_map p9100_mmap_map[] = {
218 { CG3_MMAP_OFFSET, 0, SBUS_MMAP_FBSIZE(1) },
219 { 0, 0, 0 }
220};
221
Christoph Hellwig216d5262006-01-14 13:21:25 -0800222static int p9100_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 struct p9100_par *par = (struct p9100_par *)info->par;
225
226 return sbusfb_mmap_helper(p9100_mmap_map,
227 par->physbase, par->fbsize,
David S. Miller50312ce2006-06-29 14:35:52 -0700228 par->which_io, vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Christoph Hellwig67a66802006-01-14 13:21:25 -0800231static int p9100_ioctl(struct fb_info *info, unsigned int cmd,
232 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 struct p9100_par *par = (struct p9100_par *) info->par;
235
236 /* Make it look like a cg3. */
237 return sbusfb_ioctl_helper(cmd, arg, info,
238 FBTYPE_SUN3COLOR, 8, par->fbsize);
239}
240
241/*
242 * Initialisation
243 */
244
David S. Miller50312ce2006-06-29 14:35:52 -0700245static void p9100_init_fix(struct fb_info *info, int linebytes, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
David S. Miller50312ce2006-06-29 14:35:52 -0700247 strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 info->fix.type = FB_TYPE_PACKED_PIXELS;
250 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
251
252 info->fix.line_length = linebytes;
253
254 info->fix.accel = FB_ACCEL_SUN_CGTHREE;
255}
256
David S. Millerc7f439b2007-07-27 22:31:46 -0700257static int __devinit p9100_probe(struct of_device *op, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
David S. Miller50312ce2006-06-29 14:35:52 -0700259 struct device_node *dp = op->node;
David S. Millerc7f439b2007-07-27 22:31:46 -0700260 struct fb_info *info;
261 struct p9100_par *par;
David S. Miller50312ce2006-06-29 14:35:52 -0700262 int linebytes, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
David S. Millerc7f439b2007-07-27 22:31:46 -0700264 info = framebuffer_alloc(sizeof(struct p9100_par), &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
David S. Millerc7f439b2007-07-27 22:31:46 -0700266 err = -ENOMEM;
267 if (!info)
268 goto out_err;
269 par = info->par;
270
271 spin_lock_init(&par->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 /* This is the framebuffer and the only resource apps can mmap. */
David S. Millerc7f439b2007-07-27 22:31:46 -0700274 par->physbase = op->resource[2].start;
275 par->which_io = op->resource[2].flags & IORESOURCE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Robert Reif6cd5a862008-05-08 21:37:30 -0700277 sbusfb_fill_var(&info->var, dp, 8);
David S. Millerc7f439b2007-07-27 22:31:46 -0700278 info->var.red.length = 8;
279 info->var.green.length = 8;
280 info->var.blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
David S. Millerc7f439b2007-07-27 22:31:46 -0700282 linebytes = of_getintprop_default(dp, "linebytes", info->var.xres);
283 par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
David S. Millerc7f439b2007-07-27 22:31:46 -0700285 par->regs = of_ioremap(&op->resource[0], 0,
286 sizeof(struct p9100_regs), "p9100 regs");
287 if (!par->regs)
288 goto out_release_fb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
David S. Millerc7f439b2007-07-27 22:31:46 -0700290 info->flags = FBINFO_DEFAULT;
291 info->fbops = &p9100_ops;
292 info->screen_base = of_ioremap(&op->resource[2], 0,
293 par->fbsize, "p9100 ram");
294 if (!info->screen_base)
295 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Robert Reif59f71372008-05-03 21:12:00 -0700297 p9100_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
David S. Millerc7f439b2007-07-27 22:31:46 -0700299 if (fb_alloc_cmap(&info->cmap, 256, 0))
300 goto out_unmap_screen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
David S. Millerc7f439b2007-07-27 22:31:46 -0700302 p9100_init_fix(info, linebytes, dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
David S. Millerc7f439b2007-07-27 22:31:46 -0700304 err = register_framebuffer(info);
305 if (err < 0)
306 goto out_dealloc_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
David S. Millerc7f439b2007-07-27 22:31:46 -0700308 fb_set_cmap(&info->cmap, info);
309
310 dev_set_drvdata(&op->dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Robert Reif194f1a682008-04-27 15:18:57 -0700312 printk(KERN_INFO "%s: p9100 at %lx:%lx\n",
David S. Miller50312ce2006-06-29 14:35:52 -0700313 dp->full_name,
David S. Millerc7f439b2007-07-27 22:31:46 -0700314 par->which_io, par->physbase);
David S. Miller50312ce2006-06-29 14:35:52 -0700315
316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
David S. Millerc7f439b2007-07-27 22:31:46 -0700318out_dealloc_cmap:
319 fb_dealloc_cmap(&info->cmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
David S. Millerc7f439b2007-07-27 22:31:46 -0700321out_unmap_screen:
322 of_iounmap(&op->resource[2], info->screen_base, par->fbsize);
323
324out_unmap_regs:
325 of_iounmap(&op->resource[0], par->regs, sizeof(struct p9100_regs));
326
327out_release_fb:
328 framebuffer_release(info);
329
330out_err:
331 return err;
David S. Miller50312ce2006-06-29 14:35:52 -0700332}
333
David S. Millere3a411a32006-12-28 21:01:32 -0800334static int __devexit p9100_remove(struct of_device *op)
David S. Miller50312ce2006-06-29 14:35:52 -0700335{
David S. Millerc7f439b2007-07-27 22:31:46 -0700336 struct fb_info *info = dev_get_drvdata(&op->dev);
337 struct p9100_par *par = info->par;
David S. Miller50312ce2006-06-29 14:35:52 -0700338
David S. Millerc7f439b2007-07-27 22:31:46 -0700339 unregister_framebuffer(info);
340 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700341
David S. Millerc7f439b2007-07-27 22:31:46 -0700342 of_iounmap(&op->resource[0], par->regs, sizeof(struct p9100_regs));
343 of_iounmap(&op->resource[2], info->screen_base, par->fbsize);
David S. Miller50312ce2006-06-29 14:35:52 -0700344
David S. Millerc7f439b2007-07-27 22:31:46 -0700345 framebuffer_release(info);
David S. Miller50312ce2006-06-29 14:35:52 -0700346
David S. Millere3a411a32006-12-28 21:01:32 -0800347 dev_set_drvdata(&op->dev, NULL);
David S. Miller50312ce2006-06-29 14:35:52 -0700348
349 return 0;
350}
351
352static struct of_device_id p9100_match[] = {
353 {
354 .name = "p9100",
355 },
356 {},
357};
358MODULE_DEVICE_TABLE(of, p9100_match);
359
360static struct of_platform_driver p9100_driver = {
361 .name = "p9100",
362 .match_table = p9100_match,
363 .probe = p9100_probe,
364 .remove = __devexit_p(p9100_remove),
365};
366
367static int __init p9100_init(void)
368{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (fb_get_options("p9100fb", NULL))
370 return -ENODEV;
371
David S. Miller50312ce2006-06-29 14:35:52 -0700372 return of_register_driver(&p9100_driver, &of_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
David S. Miller50312ce2006-06-29 14:35:52 -0700375static void __exit p9100_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
David S. Miller50312ce2006-06-29 14:35:52 -0700377 of_unregister_driver(&p9100_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380module_init(p9100_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381module_exit(p9100_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383MODULE_DESCRIPTION("framebuffer driver for P9100 chipsets");
David S. Miller50312ce2006-06-29 14:35:52 -0700384MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
385MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386MODULE_LICENSE("GPL");