Import 2.3.18pre1
[davej-history.git] / drivers / video / cgfourteenfb.c
blob0e1f095c641151f80460bf257d0dc032f0dab302
1 /* $Id: cgfourteenfb.c,v 1.5 1999/08/10 15:56:02 davem Exp $
2 * cgfourteenfb.c: CGfourteen frame buffer driver
4 * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 */
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/mm.h>
14 #include <linux/tty.h>
15 #include <linux/malloc.h>
16 #include <linux/vmalloc.h>
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
19 #include <linux/fb.h>
20 #include <linux/init.h>
21 #include <linux/selection.h>
23 #include <video/sbusfb.h>
24 #include <asm/io.h>
25 #include <asm/pgtable.h>
26 #include <asm/uaccess.h>
28 #include <video/fbcon-cfb8.h>
30 #define CG14_MCR_INTENABLE_SHIFT 7
31 #define CG14_MCR_INTENABLE_MASK 0x80
32 #define CG14_MCR_VIDENABLE_SHIFT 6
33 #define CG14_MCR_VIDENABLE_MASK 0x40
34 #define CG14_MCR_PIXMODE_SHIFT 4
35 #define CG14_MCR_PIXMODE_MASK 0x30
36 #define CG14_MCR_TMR_SHIFT 2
37 #define CG14_MCR_TMR_MASK 0x0c
38 #define CG14_MCR_TMENABLE_SHIFT 1
39 #define CG14_MCR_TMENABLE_MASK 0x02
40 #define CG14_MCR_RESET_SHIFT 0
41 #define CG14_MCR_RESET_MASK 0x01
42 #define CG14_REV_REVISION_SHIFT 4
43 #define CG14_REV_REVISION_MASK 0xf0
44 #define CG14_REV_IMPL_SHIFT 0
45 #define CG14_REV_IMPL_MASK 0x0f
46 #define CG14_VBR_FRAMEBASE_SHIFT 12
47 #define CG14_VBR_FRAMEBASE_MASK 0x00fff000
48 #define CG14_VMCR1_SETUP_SHIFT 0
49 #define CG14_VMCR1_SETUP_MASK 0x000001ff
50 #define CG14_VMCR1_VCONFIG_SHIFT 9
51 #define CG14_VMCR1_VCONFIG_MASK 0x00000e00
52 #define CG14_VMCR2_REFRESH_SHIFT 0
53 #define CG14_VMCR2_REFRESH_MASK 0x00000001
54 #define CG14_VMCR2_TESTROWCNT_SHIFT 1
55 #define CG14_VMCR2_TESTROWCNT_MASK 0x00000002
56 #define CG14_VMCR2_FBCONFIG_SHIFT 2
57 #define CG14_VMCR2_FBCONFIG_MASK 0x0000000c
58 #define CG14_VCR_REFRESHREQ_SHIFT 0
59 #define CG14_VCR_REFRESHREQ_MASK 0x000003ff
60 #define CG14_VCR1_REFRESHENA_SHIFT 10
61 #define CG14_VCR1_REFRESHENA_MASK 0x00000400
62 #define CG14_VCA_CAD_SHIFT 0
63 #define CG14_VCA_CAD_MASK 0x000003ff
64 #define CG14_VCA_VERS_SHIFT 10
65 #define CG14_VCA_VERS_MASK 0x00000c00
66 #define CG14_VCA_RAMSPEED_SHIFT 12
67 #define CG14_VCA_RAMSPEED_MASK 0x00001000
68 #define CG14_VCA_8MB_SHIFT 13
69 #define CG14_VCA_8MB_MASK 0x00002000
71 #define CG14_MCR_PIXMODE_8 0
72 #define CG14_MCR_PIXMODE_16 2
73 #define CG14_MCR_PIXMODE_32 3
75 struct cg14_regs{
76 volatile u8 mcr; /* Master Control Reg */
77 volatile u8 ppr; /* Packed Pixel Reg */
78 volatile u8 tms[2]; /* Test Mode Status Regs */
79 volatile u8 msr; /* Master Status Reg */
80 volatile u8 fsr; /* Fault Status Reg */
81 volatile u8 rev; /* Revision & Impl */
82 volatile u8 ccr; /* Clock Control Reg */
83 volatile u32 tmr; /* Test Mode Read Back */
84 volatile u8 mod; /* Monitor Operation Data Reg */
85 volatile u8 acr; /* Aux Control */
86 u8 xxx0[6];
87 volatile u16 hct; /* Hor Counter */
88 volatile u16 vct; /* Vert Counter */
89 volatile u16 hbs; /* Hor Blank Start */
90 volatile u16 hbc; /* Hor Blank Clear */
91 volatile u16 hss; /* Hor Sync Start */
92 volatile u16 hsc; /* Hor Sync Clear */
93 volatile u16 csc; /* Composite Sync Clear */
94 volatile u16 vbs; /* Vert Blank Start */
95 volatile u16 vbc; /* Vert Blank Clear */
96 volatile u16 vss; /* Vert Sync Start */
97 volatile u16 vsc; /* Vert Sync Clear */
98 volatile u16 xcs;
99 volatile u16 xcc;
100 volatile u16 fsa; /* Fault Status Address */
101 volatile u16 adr; /* Address Registers */
102 u8 xxx1[0xce];
103 volatile u8 pcg[0x100]; /* Pixel Clock Generator */
104 volatile u32 vbr; /* Frame Base Row */
105 volatile u32 vmcr; /* VBC Master Control */
106 volatile u32 vcr; /* VBC refresh */
107 volatile u32 vca; /* VBC Config */
110 #define CG14_CCR_ENABLE 0x04
111 #define CG14_CCR_SELECT 0x02 /* HW/Full screen */
113 struct cg14_cursor {
114 volatile u32 cpl0[32]; /* Enable plane 0 */
115 volatile u32 cpl1[32]; /* Color selection plane */
116 volatile u8 ccr; /* Cursor Control Reg */
117 u8 xxx0[3];
118 volatile u16 cursx; /* Cursor x,y position */
119 volatile u16 cursy; /* Cursor x,y position */
120 volatile u32 color0;
121 volatile u32 color1;
122 u32 xxx1[0x1bc];
123 volatile u32 cpl0i[32]; /* Enable plane 0 autoinc */
124 volatile u32 cpl1i[32]; /* Color selection autoinc */
127 struct cg14_dac {
128 volatile u8 addr; /* Address Register */
129 u8 xxx0[255];
130 volatile u8 glut; /* Gamma table */
131 u8 xxx1[255];
132 volatile u8 select; /* Register Select */
133 u8 xxx2[255];
134 volatile u8 mode; /* Mode Register */
137 struct cg14_xlut{
138 volatile u8 x_xlut [256];
139 volatile u8 x_xlutd [256];
140 u8 xxx0[0x600];
141 volatile u8 x_xlut_inc [256];
142 volatile u8 x_xlutd_inc [256];
145 /* Color look up table (clut) */
146 /* Each one of these arrays hold the color lookup table (for 256
147 * colors) for each MDI page (I assume then there should be 4 MDI
148 * pages, I still wonder what they are. I have seen NeXTStep split
149 * the screen in four parts, while operating in 24 bits mode. Each
150 * integer holds 4 values: alpha value (transparency channel, thanks
151 * go to John Stone (johns@umr.edu) from OpenBSD), red, green and blue
153 * I currently use the clut instead of the Xlut
155 struct cg14_clut {
156 unsigned int c_clut [256];
157 unsigned int c_clutd [256]; /* i wonder what the 'd' is for */
158 unsigned int c_clut_inc [256];
159 unsigned int c_clutd_inc [256];
162 static struct sbus_mmap_map cg14_mmap_map[] __initdata = {
163 { CG14_REGS, 0x80000000, 0x1000 },
164 { CG14_XLUT, 0x80003000, 0x1000 },
165 { CG14_CLUT1, 0x80004000, 0x1000 },
166 { CG14_CLUT2, 0x80005000, 0x1000 },
167 { CG14_CLUT3, 0x80006000, 0x1000 },
168 { CG3_MMAP_OFFSET -
169 0x7000, 0x80000000, 0x7000 },
170 { CG3_MMAP_OFFSET, 0x00000000, SBUS_MMAP_FBSIZE(1) },
171 { MDI_CURSOR_MAP, 0x80001000, 0x1000 },
172 { MDI_CHUNKY_BGR_MAP, 0x01000000, 0x400000 },
173 { MDI_PLANAR_X16_MAP, 0x02000000, 0x200000 },
174 { MDI_PLANAR_C16_MAP, 0x02800000, 0x200000 },
175 { MDI_PLANAR_X32_MAP, 0x03000000, 0x100000 },
176 { MDI_PLANAR_B32_MAP, 0x03400000, 0x100000 },
177 { MDI_PLANAR_G32_MAP, 0x03800000, 0x100000 },
178 { MDI_PLANAR_R32_MAP, 0x03c00000, 0x100000 },
179 { 0, 0, 0 }
182 static void cg14_loadcmap (struct fb_info_sbusfb *fb, struct display *p, int index, int count)
184 struct cg14_clut *clut = fb->s.cg14.clut;
186 for (; count--; index++)
187 clut->c_clut[index] =
188 (fb->color_map CM(index,2) << 16) |
189 (fb->color_map CM(index,1) << 8) |
190 (fb->color_map CM(index,0));
193 static void cg14_margins (struct fb_info_sbusfb *fb, struct display *p, int x_margin, int y_margin)
195 p->screen_base += (y_margin - fb->y_margin) * p->line_length + (x_margin - fb->x_margin);
198 static void cg14_setcursormap (struct fb_info_sbusfb *fb, u8 *red, u8 *green, u8 *blue)
200 struct cg14_cursor *cur = fb->s.cg14.cursor;
202 cur->color0 = ((red[0]) | (green[0] << 8) | (blue[0] << 16));
203 cur->color1 = ((red[1]) | (green[1] << 8) | (blue[1] << 16));
206 /* Set cursor shape */
207 static void cg14_setcurshape (struct fb_info_sbusfb *fb)
209 struct cg14_cursor *cur = fb->s.cg14.cursor;
210 int i;
212 for (i = 0; i < 32; i++){
213 cur->cpl0 [i] = fb->cursor.bits[0][i];
214 cur->cpl1 [i] = fb->cursor.bits[1][i];
218 /* Load cursor information */
219 static void cg14_setcursor (struct fb_info_sbusfb *fb)
221 struct cg_cursor *c = &fb->cursor;
222 struct cg14_cursor *cur = fb->s.cg14.cursor;
224 if (c->enable)
225 cur->ccr |= CG14_CCR_ENABLE;
226 cur->cursx = ((c->cpos.fbx - c->chot.fbx) & 0xfff);
227 cur->cursy = ((c->cpos.fby - c->chot.fby) & 0xfff);
230 static void cg14_switch_from_graph (struct fb_info_sbusfb *fb)
232 /* Set the 8-bpp mode */
233 if (fb->open && fb->mmaped){
234 volatile char *mcr = &fb->s.cg14.regs->mcr;
236 fb->s.cg14.mode = 8;
237 *mcr = (*mcr & ~(CG14_MCR_PIXMODE_MASK));
241 static void cg14_reset (struct fb_info_sbusfb *fb)
243 volatile char *mcr = &fb->s.cg14.regs->mcr;
245 *mcr = (*mcr & ~(CG14_MCR_PIXMODE_MASK));
248 static int cg14_ioctl (struct fb_info_sbusfb *fb, unsigned int cmd, unsigned long arg)
250 volatile char *mcr = &fb->s.cg14.regs->mcr;
251 struct mdi_cfginfo *mdii;
252 int mode;
254 switch (cmd) {
255 case MDI_RESET:
256 *mcr = (*mcr & ~CG14_MCR_PIXMODE_MASK);
257 break;
258 case MDI_GET_CFGINFO:
259 mdii = (struct mdi_cfginfo *)arg;
260 put_user_ret(FBTYPE_MDICOLOR, &mdii->mdi_type, -EFAULT);
261 __put_user_ret(fb->type.fb_height, &mdii->mdi_height, -EFAULT);
262 __put_user_ret(fb->type.fb_width, &mdii->mdi_width, -EFAULT);
263 __put_user_ret(fb->s.cg14.mode, &mdii->mdi_mode, -EFAULT);
264 __put_user_ret(72, &mdii->mdi_pixfreq, -EFAULT); /* FIXME */
265 __put_user_ret(fb->s.cg14.ramsize, &mdii->mdi_size, -EFAULT);
266 break;
267 case MDI_SET_PIXELMODE:
268 get_user_ret(mode, (int *)arg, -EFAULT);
269 switch (mode){
270 case MDI_32_PIX:
271 *mcr = (*mcr & ~CG14_MCR_PIXMODE_MASK) |
272 (CG14_MCR_PIXMODE_32 << CG14_MCR_PIXMODE_SHIFT);
273 break;
274 case MDI_16_PIX:
275 *mcr = (*mcr & ~CG14_MCR_PIXMODE_MASK) | 0x20;
276 break;
277 case MDI_8_PIX:
278 *mcr = (*mcr & ~CG14_MCR_PIXMODE_MASK);
279 break;
280 default:
281 return -ENOSYS;
283 fb->s.cg14.mode = mode;
284 break;
285 default:
286 return -EINVAL;
288 return 0;
291 static unsigned long __init get_phys(unsigned long addr)
293 return __get_phys(addr);
296 static int __init get_iospace(unsigned long addr)
298 return __get_iospace(addr);
301 static char idstring[60] __initdata = { 0 };
303 char __init *cgfourteenfb_init(struct fb_info_sbusfb *fb)
305 struct fb_fix_screeninfo *fix = &fb->fix;
306 struct display *disp = &fb->disp;
307 struct fbtype *type = &fb->type;
308 unsigned long rphys, phys;
309 u32 bases[6];
310 int is_8mb, i;
312 #ifndef FBCON_HAS_CFB8
313 return NULL;
314 #endif
315 prom_getproperty (fb->prom_node, "address", (char *) &bases[0], 8);
316 if (!bases[0]) {
317 printk("cg14 not mmaped\n");
318 return NULL;
320 if (get_iospace(bases[0]) != get_iospace(bases[1])) {
321 printk("Ugh. cg14 iospaces don't match\n");
322 return NULL;
324 fb->physbase = phys = get_phys(bases[1]);
325 rphys = get_phys(bases[0]);
326 fb->iospace = get_iospace(bases[0]);
327 fb->s.cg14.regs = (struct cg14_regs *)(unsigned long)bases[0];
328 fb->s.cg14.clut = (void *)((unsigned long)bases[0]+CG14_CLUT1);
329 fb->s.cg14.cursor = (void *)((unsigned long)bases[0]+CG14_CURSORREGS);
330 disp->screen_base = (char *)bases[1];
332 /* CG14_VCA_8MB_MASK is not correctly set on the 501-2482
333 * VSIMM, so we read the memory size from the PROM
335 prom_getproperty(fb->prom_node, "reg", (char *) &bases[0], 24);
336 is_8mb = bases[5] == 0x800000;
338 fb->mmap_map = kmalloc(sizeof(cg14_mmap_map), GFP_KERNEL);
339 if (!fb->mmap_map)
340 return NULL;
342 for (i = 0; ; i++) {
343 fb->mmap_map[i].voff = cg14_mmap_map[i].voff;
344 fb->mmap_map[i].poff = (cg14_mmap_map[i].poff & 0x80000000) ?
345 (cg14_mmap_map[i].poff & 0x7fffffff) + rphys - phys :
346 cg14_mmap_map[i].poff;
347 fb->mmap_map[i].size = cg14_mmap_map[i].size;
348 if (is_8mb && fb->mmap_map[i].size >= 0x100000 &&
349 fb->mmap_map[i].size <= 0x400000)
350 fb->mmap_map[i].size <<= 1;
351 if (!cg14_mmap_map[i].size)
352 break;
355 strcpy(fb->info.modename, "CGfourteen");
356 strcpy(fix->id, "CGfourteen");
357 fix->line_length = fb->var.xres_virtual;
358 fix->accel = FB_ACCEL_SUN_CG14;
360 disp->scrollmode = SCROLL_YREDRAW;
361 disp->screen_base += fix->line_length * fb->y_margin + fb->x_margin;
362 fb->dispsw = fbcon_cfb8;
364 type->fb_depth = 24;
365 fb->emulations[1] = FBTYPE_SUN3COLOR;
367 fb->margins = cg14_margins;
368 fb->loadcmap = cg14_loadcmap;
369 fb->setcursor = cg14_setcursor;
370 fb->setcursormap = cg14_setcursormap;
371 fb->setcurshape = cg14_setcurshape;
372 fb->reset = cg14_reset;
373 fb->switch_from_graph = cg14_switch_from_graph;
374 fb->ioctl = cg14_ioctl;
376 fb->s.cg14.mode = 8;
377 fb->s.cg14.ramsize = (is_8mb) ? 0x800000 : 0x400000;
379 cg14_reset(fb);
381 sprintf(idstring, "cgfourteen at %x.%08lx, %dMB, rev=%d, impl=%d", fb->iospace, phys,
382 is_8mb ? 8 : 4, fb->s.cg14.regs->rev >> 4, fb->s.cg14.regs->rev & 0xf);
384 return idstring;