[SPARC]: Fix RTC compat ioctl kernel log spam.
[linux-2.6-block.git] / drivers / video / p9100.c
CommitLineData
1da177e4
LT
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
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>
18
19#include <asm/io.h>
20#include <asm/sbus.h>
21#include <asm/oplib.h>
22#include <asm/fbio.h>
23
24#include "sbuslib.h"
25
26/*
27 * Local functions.
28 */
29
30static int p9100_setcolreg(unsigned, unsigned, unsigned, unsigned,
31 unsigned, struct fb_info *);
32static int p9100_blank(int, struct fb_info *);
33
34static int p9100_mmap(struct fb_info *, struct file *, struct vm_area_struct *);
35static int p9100_ioctl(struct inode *, struct file *, unsigned int,
36 unsigned long, struct fb_info *);
37
38/*
39 * Frame buffer operations
40 */
41
42static struct fb_ops p9100_ops = {
43 .owner = THIS_MODULE,
44 .fb_setcolreg = p9100_setcolreg,
45 .fb_blank = p9100_blank,
46 .fb_fillrect = cfb_fillrect,
47 .fb_copyarea = cfb_copyarea,
48 .fb_imageblit = cfb_imageblit,
49 .fb_mmap = p9100_mmap,
50 .fb_ioctl = p9100_ioctl,
1da177e4
LT
51};
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 */
73 volatile u32 sys_base;
74 volatile u32 sys_config;
75 volatile u32 sys_intr;
76 volatile u32 sys_int_ena;
77 volatile u32 sys_alt_rd;
78 volatile u32 sys_alt_wr;
79 volatile u32 sys_xxx[58];
80
81 /* Registers for the video control */
82 volatile u32 vid_base;
83 volatile u32 vid_hcnt;
84 volatile u32 vid_htotal;
85 volatile u32 vid_hsync_rise;
86 volatile u32 vid_hblank_rise;
87 volatile u32 vid_hblank_fall;
88 volatile u32 vid_hcnt_preload;
89 volatile u32 vid_vcnt;
90 volatile u32 vid_vlen;
91 volatile u32 vid_vsync_rise;
92 volatile u32 vid_vblank_rise;
93 volatile u32 vid_vblank_fall;
94 volatile u32 vid_vcnt_preload;
95 volatile u32 vid_screenpaint_addr;
96 volatile u32 vid_screenpaint_timectl1;
97 volatile u32 vid_screenpaint_qsfcnt;
98 volatile u32 vid_screenpaint_timectl2;
99 volatile u32 vid_xxx[15];
100
101 /* Registers for the video control */
102 volatile u32 vram_base;
103 volatile u32 vram_memcfg;
104 volatile u32 vram_refresh_pd;
105 volatile u32 vram_refresh_cnt;
106 volatile u32 vram_raslo_max;
107 volatile u32 vram_raslo_cur;
108 volatile u32 pwrup_cfg;
109 volatile u32 vram_xxx[25];
110
111 /* Registers for IBM RGB528 Palette */
112 volatile u32 ramdac_cmap_wridx;
113 volatile u32 ramdac_palette_data;
114 volatile u32 ramdac_pixel_mask;
115 volatile u32 ramdac_palette_rdaddr;
116 volatile u32 ramdac_idx_lo;
117 volatile u32 ramdac_idx_hi;
118 volatile u32 ramdac_idx_data;
119 volatile u32 ramdac_idx_ctl;
120 volatile u32 ramdac_xxx[1784];
121};
122
123struct p9100_cmd_parameng {
124 volatile u32 parameng_status;
125 volatile u32 parameng_bltcmd;
126 volatile u32 parameng_quadcmd;
127};
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
136 unsigned long physbase;
137 unsigned long fbsize;
138
139 struct sbus_dev *sdev;
140 struct list_head list;
141};
142
143/**
144 * p9100_setcolreg - Optional function. Sets a color register.
145 * @regno: boolean, 0 copy local, 1 get_user() function
146 * @red: frame buffer colormap structure
147 * @green: The green value which can be up to 16 bits wide
148 * @blue: The blue value which can be up to 16 bits wide.
149 * @transp: If supported the alpha value which can be up to 16 bits wide.
150 * @info: frame buffer info structure
151 */
152static int p9100_setcolreg(unsigned regno,
153 unsigned red, unsigned green, unsigned blue,
154 unsigned transp, struct fb_info *info)
155{
156 struct p9100_par *par = (struct p9100_par *) info->par;
157 struct p9100_regs __iomem *regs = par->regs;
158 unsigned long flags;
159
160 if (regno >= 256)
161 return 1;
162
163 red >>= 8;
164 green >>= 8;
165 blue >>= 8;
166
167 spin_lock_irqsave(&par->lock, flags);
168
169 sbus_writel((regno << 16), &regs->ramdac_cmap_wridx);
170 sbus_writel((red << 16), &regs->ramdac_palette_data);
171 sbus_writel((green << 16), &regs->ramdac_palette_data);
172 sbus_writel((blue << 16), &regs->ramdac_palette_data);
173
174 spin_unlock_irqrestore(&par->lock, flags);
175
176 return 0;
177}
178
179/**
180 * p9100_blank - Optional function. Blanks the display.
181 * @blank_mode: the blank mode we want.
182 * @info: frame buffer structure that represents a single frame buffer
183 */
184static int
185p9100_blank(int blank, struct fb_info *info)
186{
187 struct p9100_par *par = (struct p9100_par *) info->par;
188 struct p9100_regs __iomem *regs = par->regs;
189 unsigned long flags;
190 u32 val;
191
192 spin_lock_irqsave(&par->lock, flags);
193
194 switch (blank) {
195 case FB_BLANK_UNBLANK: /* Unblanking */
196 val = sbus_readl(&regs->vid_screenpaint_timectl1);
197 val |= SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
198 sbus_writel(val, &regs->vid_screenpaint_timectl1);
199 par->flags &= ~P9100_FLAG_BLANKED;
200 break;
201
202 case FB_BLANK_NORMAL: /* Normal blanking */
203 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
204 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
205 case FB_BLANK_POWERDOWN: /* Poweroff */
206 val = sbus_readl(&regs->vid_screenpaint_timectl1);
207 val &= ~SCREENPAINT_TIMECTL1_ENABLE_VIDEO;
208 sbus_writel(val, &regs->vid_screenpaint_timectl1);
209 par->flags |= P9100_FLAG_BLANKED;
210 break;
211 }
212
213 spin_unlock_irqrestore(&par->lock, flags);
214
215 return 0;
216}
217
218static struct sbus_mmap_map p9100_mmap_map[] = {
219 { CG3_MMAP_OFFSET, 0, SBUS_MMAP_FBSIZE(1) },
220 { 0, 0, 0 }
221};
222
223static int p9100_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
224{
225 struct p9100_par *par = (struct p9100_par *)info->par;
226
227 return sbusfb_mmap_helper(p9100_mmap_map,
228 par->physbase, par->fbsize,
229 par->sdev->reg_addrs[0].which_io,
230 vma);
231}
232
233static int p9100_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
234 unsigned long arg, struct fb_info *info)
235{
236 struct p9100_par *par = (struct p9100_par *) info->par;
237
238 /* Make it look like a cg3. */
239 return sbusfb_ioctl_helper(cmd, arg, info,
240 FBTYPE_SUN3COLOR, 8, par->fbsize);
241}
242
243/*
244 * Initialisation
245 */
246
247static void
248p9100_init_fix(struct fb_info *info, int linebytes)
249{
250 struct p9100_par *par = (struct p9100_par *)info->par;
251
252 strlcpy(info->fix.id, par->sdev->prom_name, sizeof(info->fix.id));
253
254 info->fix.type = FB_TYPE_PACKED_PIXELS;
255 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
256
257 info->fix.line_length = linebytes;
258
259 info->fix.accel = FB_ACCEL_SUN_CGTHREE;
260}
261
262struct all_info {
263 struct fb_info info;
264 struct p9100_par par;
265 struct list_head list;
266};
267static LIST_HEAD(p9100_list);
268
269static void p9100_init_one(struct sbus_dev *sdev)
270{
271 struct all_info *all;
272 int linebytes;
273
274 all = kmalloc(sizeof(*all), GFP_KERNEL);
275 if (!all) {
276 printk(KERN_ERR "p9100: Cannot allocate memory.\n");
277 return;
278 }
279 memset(all, 0, sizeof(*all));
280
281 INIT_LIST_HEAD(&all->list);
282
283 spin_lock_init(&all->par.lock);
284 all->par.sdev = sdev;
285
286 /* This is the framebuffer and the only resource apps can mmap. */
287 all->par.physbase = sdev->reg_addrs[2].phys_addr;
288
289 sbusfb_fill_var(&all->info.var, sdev->prom_node, 8);
d85c3553
TC
290 all->info.var.red.length = 8;
291 all->info.var.green.length = 8;
292 all->info.var.blue.length = 8;
1da177e4
LT
293
294 linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
295 all->info.var.xres);
296 all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
297
298 all->par.regs = sbus_ioremap(&sdev->resource[0], 0,
299 sizeof(struct p9100_regs), "p9100 regs");
300
301 all->info.flags = FBINFO_DEFAULT;
302 all->info.fbops = &p9100_ops;
303#ifdef CONFIG_SPARC32
304 all->info.screen_base = (char __iomem *)
305 prom_getintdefault(sdev->prom_node, "address", 0);
306#endif
307 if (!all->info.screen_base)
308 all->info.screen_base = sbus_ioremap(&sdev->resource[2], 0,
309 all->par.fbsize, "p9100 ram");
310 all->info.par = &all->par;
311
312 p9100_blank(0, &all->info);
313
314 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
315 printk(KERN_ERR "p9100: Could not allocate color map.\n");
316 kfree(all);
317 return;
318 }
319
320 p9100_init_fix(&all->info, linebytes);
321
322 if (register_framebuffer(&all->info) < 0) {
323 printk(KERN_ERR "p9100: Could not register framebuffer.\n");
324 fb_dealloc_cmap(&all->info.cmap);
325 kfree(all);
326 return;
327 }
d85c3553 328 fb_set_cmap(&all->info.cmap, &all->info);
1da177e4
LT
329
330 list_add(&all->list, &p9100_list);
331
332 printk("p9100: %s at %lx:%lx\n",
333 sdev->prom_name,
334 (long) sdev->reg_addrs[0].which_io,
335 (long) sdev->reg_addrs[0].phys_addr);
336}
337
338int __init p9100_init(void)
339{
340 struct sbus_bus *sbus;
341 struct sbus_dev *sdev;
342
343 if (fb_get_options("p9100fb", NULL))
344 return -ENODEV;
345
346 for_all_sbusdev(sdev, sbus) {
347 if (!strcmp(sdev->prom_name, "p9100"))
348 p9100_init_one(sdev);
349 }
350
351 return 0;
352}
353
354void __exit p9100_exit(void)
355{
356 struct list_head *pos, *tmp;
357
358 list_for_each_safe(pos, tmp, &p9100_list) {
359 struct all_info *all = list_entry(pos, typeof(*all), list);
360
361 unregister_framebuffer(&all->info);
362 fb_dealloc_cmap(&all->info.cmap);
363 kfree(all);
364 }
365}
366
367int __init
368p9100_setup(char *arg)
369{
370 /* No cmdline options yet... */
371 return 0;
372}
373
374module_init(p9100_init);
375
376#ifdef MODULE
377module_exit(p9100_exit);
378#endif
379
380MODULE_DESCRIPTION("framebuffer driver for P9100 chipsets");
381MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
382MODULE_LICENSE("GPL");