Import 2.3.18pre1
[davej-history.git] / drivers / video / hpfb.c
blob27a383ece24bd59906c03e932eb1f9f31e19a5cb
1 /*
2 * HP300 Topcat framebuffer support (derived from macfb of all things)
3 * Phil Blundell <philb@gnu.org> 1998
4 *
5 * Should this be moved to drivers/dio/video/ ? -- Peter Maydell
6 * No! -- Jes
7 */
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/errno.h>
13 #include <linux/string.h>
14 #include <linux/mm.h>
15 #include <linux/tty.h>
16 #include <linux/malloc.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/fb.h>
20 #include <linux/dio.h>
21 #include <asm/io.h>
22 #include <asm/blinken.h>
23 #include <asm/hwtest.h>
25 #include <video/fbcon-mfb.h>
26 #include <video/fbcon-cfb2.h>
27 #include <video/fbcon-cfb4.h>
28 #include <video/fbcon-cfb8.h>
30 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
32 static struct display disp;
33 static struct fb_info fb_info;
35 unsigned long fb_start, fb_size = 1024*768, fb_line_length = 1024;
36 unsigned long fb_regs;
37 unsigned char fb_bitmask;
39 #define TC_WEN 0x4088
40 #define TC_REN 0x408c
41 #define TC_FBEN 0x4090
42 #define TC_NBLANK 0x4080
44 /* blitter regs */
45 #define BUSY 0x4044
46 #define WMRR 0x40ef
47 #define SOURCE_X 0x40f2
48 #define SOURCE_Y 0x40f6
49 #define DEST_X 0x40fa
50 #define DEST_Y 0x40fe
51 #define WHEIGHT 0x4106
52 #define WWIDTH 0x4102
53 #define WMOVE 0x409c
55 static struct fb_var_screeninfo hpfb_defined = {
56 0,0,0,0, /* W,H, W, H (virtual) load xres,xres_virtual*/
57 0,0, /* virtual -> visible no offset */
58 0, /* depth -> load bits_per_pixel */
59 0, /* greyscale ? */
60 {0,2,0}, /* R */
61 {0,2,0}, /* G */
62 {0,2,0}, /* B */
63 {0,0,0}, /* transparency */
64 0, /* standard pixel format */
65 FB_ACTIVATE_NOW,
66 274,195, /* 14" monitor */
67 FB_ACCEL_NONE,
68 0L,0L,0L,0L,0L,
69 0L,0L,0, /* No sync info */
70 FB_VMODE_NONINTERLACED,
71 {0,0,0,0,0,0}
74 struct hpfb_par
78 static int currcon = 0;
79 struct hpfb_par current_par;
81 static void hpfb_encode_var(struct fb_var_screeninfo *var,
82 struct hpfb_par *par)
84 int i=0;
85 var->xres=1024;
86 var->yres=768;
87 var->xres_virtual=1024;
88 var->yres_virtual=768;
89 var->xoffset=0;
90 var->yoffset=0;
91 var->bits_per_pixel = 1;
92 var->grayscale=0;
93 var->transp.offset=0;
94 var->transp.length=0;
95 var->transp.msb_right=0;
96 var->nonstd=0;
97 var->activate=0;
98 var->height= -1;
99 var->width= -1;
100 var->vmode=FB_VMODE_NONINTERLACED;
101 var->pixclock=0;
102 var->sync=0;
103 var->left_margin=0;
104 var->right_margin=0;
105 var->upper_margin=0;
106 var->lower_margin=0;
107 var->hsync_len=0;
108 var->vsync_len=0;
109 for(i=0;i<arraysize(var->reserved);i++)
110 var->reserved[i]=0;
113 static void hpfb_get_par(struct hpfb_par *par)
115 *par=current_par;
118 static int fb_update_var(int con, struct fb_info *info)
120 return 0;
123 static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
125 struct hpfb_par par;
127 hpfb_get_par(&par);
128 hpfb_encode_var(var, &par);
129 return 0;
132 static int hpfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
133 struct fb_info *info)
135 return 0;
139 * Set the palette. This may not work on all boards but only experimentation will tell.
140 * XXX Doesn't work at all.
143 static int hpfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
144 struct fb_info *info)
146 unsigned int i;
147 for (i = 0; i < cmap->len; i++)
149 while (readw(fb_regs + 0x6002) & 0x4) udelay(1);
150 writew(0, fb_regs + 0x60f0);
151 writew(cmap->start + i, fb_regs + 0x60b8);
152 writew(cmap->red[i], fb_regs + 0x60b2);
153 writew(cmap->green[i], fb_regs + 0x60b4);
154 writew(cmap->blue[i], fb_regs + 0x60b6);
155 writew(0xff, fb_regs + 0x60f0);
156 udelay(100);
158 writew(0xffff, fb_regs + 0x60ba);
159 return 0;
162 static int hpfb_get_var(struct fb_var_screeninfo *var, int con,
163 struct fb_info *info)
165 struct hpfb_par par;
166 if(con==-1)
168 hpfb_get_par(&par);
169 hpfb_encode_var(var, &par);
171 else
172 *var=fb_display[con].var;
173 return 0;
176 static int hpfb_set_var(struct fb_var_screeninfo *var, int con,
177 struct fb_info *info)
179 int err;
181 if ((err=do_fb_set_var(var, 1)))
182 return err;
183 return 0;
186 static void hpfb_encode_fix(struct fb_fix_screeninfo *fix,
187 struct hpfb_par *par)
189 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
190 strcpy(fix->id, "HP300 Topcat");
193 * X works, but screen wraps ...
195 fix->smem_start=fb_start;
196 fix->smem_len=fb_size;
197 fix->type = FB_TYPE_PACKED_PIXELS;
198 fix->visual = FB_VISUAL_PSEUDOCOLOR;
199 fix->xpanstep=0;
200 fix->ypanstep=0;
201 fix->ywrapstep=0;
202 fix->line_length=fb_line_length;
205 static int hpfb_get_fix(struct fb_fix_screeninfo *fix, int con,
206 struct fb_info *info)
208 struct hpfb_par par;
209 hpfb_get_par(&par);
210 hpfb_encode_fix(fix, &par);
211 return 0;
214 static void topcat_blit(int x0, int y0, int x1, int y1, int w, int h)
216 while (readb(fb_regs + BUSY) & fb_bitmask);
217 writeb(0x3, fb_regs + WMRR);
218 writew(x0, fb_regs + SOURCE_X);
219 writew(y0, fb_regs + SOURCE_Y);
220 writew(x1, fb_regs + DEST_X);
221 writew(y1, fb_regs + DEST_Y);
222 writew(h, fb_regs + WHEIGHT);
223 writew(w, fb_regs + WWIDTH);
224 writeb(fb_bitmask, fb_regs + WMOVE);
227 static int hpfb_ioctl(struct inode *inode, struct file *file,
228 unsigned int cmd, unsigned long arg, int con,
229 struct fb_info *info)
231 return -EINVAL;
234 static int hpfb_switch(int con, struct fb_info *info)
236 do_fb_set_var(&fb_display[con].var,1);
237 currcon=con;
238 return 0;
241 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
243 static void hpfb_blank(int blank, struct fb_info *info)
245 /* Not supported */
248 static int hpfb_open(struct fb_info *info, int user)
251 * Nothing, only a usage count for the moment
253 MOD_INC_USE_COUNT;
254 return(0);
257 static void hpfb_set_disp(int con)
259 struct fb_fix_screeninfo fix;
260 struct display *display;
262 if (con >= 0)
263 display = &fb_display[con];
264 else
265 display = &disp; /* used during initialization */
267 hpfb_get_fix(&fix, con, 0);
269 display->screen_base = fix.smem_start;
270 display->visual = fix.visual;
271 display->type = fix.type;
272 display->type_aux = fix.type_aux;
273 display->ypanstep = fix.ypanstep;
274 display->ywrapstep = fix.ywrapstep;
275 display->line_length = fix.line_length;
276 display->next_line = fix.line_length;
277 display->can_soft_blank = 0;
278 display->inverse = 0;
280 display->dispsw = &fbcon_cfb8;
283 static int hpfb_release(struct fb_info *info, int user)
285 MOD_DEC_USE_COUNT;
286 return(0);
289 static struct fb_ops hpfb_ops = {
290 hpfb_open,
291 hpfb_release,
292 hpfb_get_fix,
293 hpfb_get_var,
294 hpfb_set_var,
295 hpfb_get_cmap,
296 hpfb_set_cmap,
297 NULL,
298 hpfb_ioctl
301 #define TOPCAT_FBOMSB 0x5d
302 #define TOPCAT_FBOLSB 0x5f
304 int __init hpfb_init_one(unsigned long base)
306 unsigned long fboff;
308 fboff = (readb(base + TOPCAT_FBOMSB) << 8)
309 | readb(base + TOPCAT_FBOLSB);
311 fb_start = 0xf0000000 | (readb(base + fboff) << 16);
312 fb_regs = base;
314 #if 0
315 /* This is the magic incantation NetBSD uses to make Catseye boards work. */
316 writeb(0, base+0x4800);
317 writeb(0, base+0x4510);
318 writeb(0, base+0x4512);
319 writeb(0, base+0x4514);
320 writeb(0, base+0x4516);
321 writeb(0x90, base+0x4206);
322 #endif
325 * Fill in the available video resolution
328 hpfb_defined.xres = 1024;
329 hpfb_defined.yres = 768;
330 hpfb_defined.xres_virtual = 1024;
331 hpfb_defined.yres_virtual = 768;
332 hpfb_defined.bits_per_pixel = 8;
335 * Give the hardware a bit of a prod and work out how many bits per
336 * pixel are supported.
339 writeb(0xff, base + TC_WEN);
340 writeb(0xff, base + TC_FBEN);
341 writeb(0xff, fb_start);
342 fb_bitmask = readb(fb_start);
345 * Enable reading/writing of all the planes.
347 writeb(fb_bitmask, base + TC_WEN);
348 writeb(fb_bitmask, base + TC_REN);
349 writeb(fb_bitmask, base + TC_FBEN);
350 writeb(0x1, base + TC_NBLANK);
353 * Let there be consoles..
355 strcpy(fb_info.modename, "Topcat");
356 fb_info.changevar = NULL;
357 fb_info.node = -1;
358 fb_info.fbops = &hpfb_ops;
359 fb_info.disp = &disp;
360 fb_info.switch_con = &hpfb_switch;
361 fb_info.updatevar = &fb_update_var;
362 fb_info.blank = &hpfb_blank;
363 fb_info.flags = FBINFO_FLAG_DEFAULT;
364 do_fb_set_var(&hpfb_defined, 1);
366 hpfb_get_var(&disp.var, -1, &fb_info);
367 hpfb_set_disp(-1);
369 if (register_framebuffer(&fb_info) < 0)
370 return 1;
372 return 0;
376 * Check that the secondary ID indicates that we have some hope of working with this
377 * framebuffer. The catseye boards are pretty much like topcats and we can muddle through.
380 #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
381 || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
384 * Initialise the framebuffer
387 int __init hpfb_init(void)
389 unsigned int sid;
391 /* Topcats can be on the internal IO bus or real DIO devices.
392 * The internal variant sits at 0xf0560000; it has primary
393 * and secondary ID registers just like the DIO version.
394 * So we merge the two detection routines.
396 * Perhaps this #define should be in a global header file:
397 * I believe it's common to all internal fbs, not just topcat.
399 #define INTFBADDR 0xf0560000
401 if (hwreg_present((void *)INTFBADDR) && (DIO_ID(INTFBADDR) == DIO_ID_FBUFFER)
402 && topcat_sid_ok(sid = DIO_SECID(INTFBADDR)))
404 printk("Internal Topcat found (secondary id %02x)\n", sid);
405 hpfb_init_one(INTFBADDR);
407 else
409 int sc = dio_find(DIO_ID_FBUFFER);
410 if (sc)
412 unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
413 unsigned int sid = DIO_SECID(addr);
415 if (topcat_sid_ok(sid))
417 printk("Topcat found at DIO select code %02x "
418 "(secondary id %02x)\n", sc, sid);
419 hpfb_init_one(addr);
424 return 0;
427 int __init hpfb_setup(char *options)
429 return 0;