2 * HP300 Topcat framebuffer support (derived from macfb of all things)
3 * Phil Blundell <philb@gnu.org> 1998
5 * Should this be moved to drivers/dio/video/ ? -- Peter Maydell
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>
15 #include <linux/tty.h>
16 #include <linux/malloc.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
20 #include <linux/dio.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
;
41 #define TC_FBEN 0x4090
42 #define TC_NBLANK 0x4080
47 #define SOURCE_X 0x40f2
48 #define SOURCE_Y 0x40f6
51 #define WHEIGHT 0x4106
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 */
63 {0,0,0}, /* transparency */
64 0, /* standard pixel format */
66 274,195, /* 14" monitor */
69 0L,0L,0, /* No sync info */
70 FB_VMODE_NONINTERLACED
,
78 static int currcon
= 0;
79 struct hpfb_par current_par
;
81 static void hpfb_encode_var(struct fb_var_screeninfo
*var
,
87 var
->xres_virtual
=1024;
88 var
->yres_virtual
=768;
91 var
->bits_per_pixel
= 1;
95 var
->transp
.msb_right
=0;
100 var
->vmode
=FB_VMODE_NONINTERLACED
;
109 for(i
=0;i
<arraysize(var
->reserved
);i
++)
113 static void hpfb_get_par(struct hpfb_par
*par
)
118 static int fb_update_var(int con
, struct fb_info
*info
)
123 static int do_fb_set_var(struct fb_var_screeninfo
*var
, int isactive
)
128 hpfb_encode_var(var
, &par
);
132 static int hpfb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
133 struct fb_info
*info
)
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
)
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);
158 writew(0xffff, fb_regs
+ 0x60ba);
162 static int hpfb_get_var(struct fb_var_screeninfo
*var
, int con
,
163 struct fb_info
*info
)
169 hpfb_encode_var(var
, &par
);
172 *var
=fb_display
[con
].var
;
176 static int hpfb_set_var(struct fb_var_screeninfo
*var
, int con
,
177 struct fb_info
*info
)
181 if ((err
=do_fb_set_var(var
, 1)))
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
;
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
)
210 hpfb_encode_fix(fix
, &par
);
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
)
234 static int hpfb_switch(int con
, struct fb_info
*info
)
236 do_fb_set_var(&fb_display
[con
].var
,1);
241 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
243 static void hpfb_blank(int blank
, struct fb_info
*info
)
248 static int hpfb_open(struct fb_info
*info
, int user
)
251 * Nothing, only a usage count for the moment
257 static void hpfb_set_disp(int con
)
259 struct fb_fix_screeninfo fix
;
260 struct display
*display
;
263 display
= &fb_display
[con
];
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
)
289 static struct fb_ops hpfb_ops
= {
301 #define TOPCAT_FBOMSB 0x5d
302 #define TOPCAT_FBOLSB 0x5f
304 int __init
hpfb_init_one(unsigned long base
)
308 fboff
= (readb(base
+ TOPCAT_FBOMSB
) << 8)
309 | readb(base
+ TOPCAT_FBOLSB
);
311 fb_start
= 0xf0000000 | (readb(base
+ fboff
) << 16);
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);
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
;
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
);
369 if (register_framebuffer(&fb_info
) < 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)
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
);
409 int sc
= dio_find(DIO_ID_FBUFFER
);
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
);
427 int __init
hpfb_setup(char *options
)