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 */
8
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>
24
25 #include <video/fbcon.h>
26 #include <video/fbcon-mfb.h>
27 #include <video/fbcon-cfb2.h>
28 #include <video/fbcon-cfb4.h>
29 #include <video/fbcon-cfb8.h>
30
31 static struct display disp;
32 static struct fb_info fb_info;
33
34 unsigned long fb_start, fb_size = 1024*768, fb_line_length = 1024;
35 unsigned long fb_regs;
36 unsigned char fb_bitmask;
37
38 #define TC_WEN 0x4088
39 #define TC_REN 0x408c
40 #define TC_FBEN 0x4090
41 #define TC_NBLANK 0x4080
42
43 /* blitter regs */
44 #define BUSY 0x4044
45 #define WMRR 0x40ef
46 #define SOURCE_X 0x40f2
47 #define SOURCE_Y 0x40f6
48 #define DEST_X 0x40fa
49 #define DEST_Y 0x40fe
50 #define WHEIGHT 0x4106
51 #define WWIDTH 0x4102
52 #define WMOVE 0x409c
53
54 static struct fb_var_screeninfo hpfb_defined = {
55 0,0,0,0, /* W,H, W, H (virtual) load xres,xres_virtual*/
56 0,0, /* virtual -> visible no offset */
57 0, /* depth -> load bits_per_pixel */
58 0, /* greyscale ? */
59 {0,2,0}, /* R */
60 {0,2,0}, /* G */
61 {0,2,0}, /* B */
62 {0,0,0}, /* transparency */
63 0, /* standard pixel format */
64 FB_ACTIVATE_NOW,
65 274,195, /* 14" monitor */
66 FB_ACCEL_NONE,
67 0L,0L,0L,0L,0L,
68 0L,0L,0, /* No sync info */
69 FB_VMODE_NONINTERLACED,
70 {0,0,0,0,0,0}
71 };
72
73 struct hpfb_par
74 {
75 };
76
77 static int currcon = 0;
78 struct hpfb_par current_par;
79
80 static void hpfb_encode_var(struct fb_var_screeninfo *var,
81 struct hpfb_par *par)
82 {
83 int i=0;
84 var->xres=1024;
85 var->yres=768;
86 var->xres_virtual=1024;
87 var->yres_virtual=768;
88 var->xoffset=0;
89 var->yoffset=0;
90 var->bits_per_pixel = 1;
91 var->grayscale=0;
92 var->transp.offset=0;
93 var->transp.length=0;
94 var->transp.msb_right=0;
95 var->nonstd=0;
96 var->activate=0;
97 var->height= -1;
98 var->width= -1;
99 var->vmode=FB_VMODE_NONINTERLACED;
100 var->pixclock=0;
101 var->sync=0;
102 var->left_margin=0;
103 var->right_margin=0;
104 var->upper_margin=0;
105 var->lower_margin=0;
106 var->hsync_len=0;
107 var->vsync_len=0;
108 for(i=0;i<ARRAY_SIZE(var->reserved);i++)
109 var->reserved[i]=0;
110 }
111
112 static void hpfb_get_par(struct hpfb_par *par)
113 {
114 *par=current_par;
115 }
116
117 static int fb_update_var(int con, struct fb_info *info)
118 {
119 return 0;
120 }
121
122 static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
123 {
124 struct hpfb_par par;
125
126 hpfb_get_par(&par);
127 hpfb_encode_var(var, &par);
128 return 0;
129 }
130
131 static int hpfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
132 struct fb_info *info)
133 {
134 return 0;
135 }
136
137 /*
138 * Set the palette. This may not work on all boards but only experimentation will tell.
139 * XXX Doesn't work at all.
140 */
141
142 static int hpfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
143 struct fb_info *info)
144 {
145 unsigned int i;
146 for (i = 0; i < cmap->len; i++)
147 {
148 while (readw(fb_regs + 0x6002) & 0x4) udelay(1);
149 writew(0, fb_regs + 0x60f0);
150 writew(cmap->start + i, fb_regs + 0x60b8);
151 writew(cmap->red[i], fb_regs + 0x60b2);
152 writew(cmap->green[i], fb_regs + 0x60b4);
153 writew(cmap->blue[i], fb_regs + 0x60b6);
154 writew(0xff, fb_regs + 0x60f0);
155 udelay(100);
156 }
157 writew(0xffff, fb_regs + 0x60ba);
158 return 0;
159 }
160
161 static int hpfb_get_var(struct fb_var_screeninfo *var, int con,
162 struct fb_info *info)
163 {
164 struct hpfb_par par;
165 if(con==-1)
166 {
167 hpfb_get_par(&par);
168 hpfb_encode_var(var, &par);
169 }
170 else
171 *var=fb_display[con].var;
172 return 0;
173 }
174
175 static int hpfb_set_var(struct fb_var_screeninfo *var, int con,
176 struct fb_info *info)
177 {
178 int err;
179
180 if ((err=do_fb_set_var(var, 1)))
181 return err;
182 return 0;
183 }
184
185 static void hpfb_encode_fix(struct fb_fix_screeninfo *fix,
186 struct hpfb_par *par)
187 {
188 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
189 strcpy(fix->id, "HP300 Topcat");
190
191 /*
192 * X works, but screen wraps ...
193 */
194 fix->smem_start=fb_start;
195 fix->smem_len=fb_size;
196 fix->type = FB_TYPE_PACKED_PIXELS;
197 fix->visual = FB_VISUAL_PSEUDOCOLOR;
198 fix->xpanstep=0;
199 fix->ypanstep=0;
200 fix->ywrapstep=0;
201 fix->line_length=fb_line_length;
202 }
203
204 static int hpfb_get_fix(struct fb_fix_screeninfo *fix, int con,
205 struct fb_info *info)
206 {
207 struct hpfb_par par;
208 hpfb_get_par(&par);
209 hpfb_encode_fix(fix, &par);
210 return 0;
211 }
212
213 static void topcat_blit(int x0, int y0, int x1, int y1, int w, int h)
214 {
215 while (readb(fb_regs + BUSY) & fb_bitmask);
216 writeb(0x3, fb_regs + WMRR);
217 writew(x0, fb_regs + SOURCE_X);
218 writew(y0, fb_regs + SOURCE_Y);
219 writew(x1, fb_regs + DEST_X);
220 writew(y1, fb_regs + DEST_Y);
221 writew(h, fb_regs + WHEIGHT);
222 writew(w, fb_regs + WWIDTH);
223 writeb(fb_bitmask, fb_regs + WMOVE);
224 }
225
226 static int hpfb_switch(int con, struct fb_info *info)
227 {
228 do_fb_set_var(&fb_display[con].var,1);
229 currcon=con;
230 return 0;
231 }
232
233 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
234
235 static void hpfb_blank(int blank, struct fb_info *info)
236 {
237 /* Not supported */
238 }
239
240 static void hpfb_set_disp(int con)
241 {
242 struct fb_fix_screeninfo fix;
243 struct display *display;
244
245 if (con >= 0)
246 display = &fb_display[con];
247 else
248 display = &disp; /* used during initialization */
249
250 hpfb_get_fix(&fix, con, 0);
251
252 display->screen_base = fix.smem_start;
253 display->visual = fix.visual;
254 display->type = fix.type;
255 display->type_aux = fix.type_aux;
256 display->ypanstep = fix.ypanstep;
257 display->ywrapstep = fix.ywrapstep;
258 display->line_length = fix.line_length;
259 display->next_line = fix.line_length;
260 display->can_soft_blank = 0;
261 display->inverse = 0;
262
263 display->dispsw = &fbcon_cfb8;
264 }
265
266 static struct fb_ops hpfb_ops = {
267 owner: THIS_MODULE,
268 fb_get_fix: hpfb_get_fix,
269 fb_get_var: hpfb_get_var,
270 fb_set_var: hpfb_set_var,
271 fb_get_cmap: hpfb_get_cmap,
272 fb_set_cmap: hpfb_set_cmap,
273 };
274
275 #define TOPCAT_FBOMSB 0x5d
276 #define TOPCAT_FBOLSB 0x5f
277
278 int __init hpfb_init_one(unsigned long base)
279 {
280 unsigned long fboff;
281
282 fboff = (readb(base + TOPCAT_FBOMSB) << 8)
283 | readb(base + TOPCAT_FBOLSB);
284
285 fb_start = 0xf0000000 | (readb(base + fboff) << 16);
286 fb_regs = base;
287
288 #if 0
289 /* This is the magic incantation NetBSD uses to make Catseye boards work. */
290 writeb(0, base+0x4800);
291 writeb(0, base+0x4510);
292 writeb(0, base+0x4512);
293 writeb(0, base+0x4514);
294 writeb(0, base+0x4516);
295 writeb(0x90, base+0x4206);
296 #endif
297
298 /*
299 * Fill in the available video resolution
300 */
301
302 hpfb_defined.xres = 1024;
303 hpfb_defined.yres = 768;
304 hpfb_defined.xres_virtual = 1024;
305 hpfb_defined.yres_virtual = 768;
306 hpfb_defined.bits_per_pixel = 8;
307
308 /*
309 * Give the hardware a bit of a prod and work out how many bits per
310 * pixel are supported.
311 */
312
313 writeb(0xff, base + TC_WEN);
314 writeb(0xff, base + TC_FBEN);
315 writeb(0xff, fb_start);
316 fb_bitmask = readb(fb_start);
317
318 /*
319 * Enable reading/writing of all the planes.
320 */
321 writeb(fb_bitmask, base + TC_WEN);
322 writeb(fb_bitmask, base + TC_REN);
323 writeb(fb_bitmask, base + TC_FBEN);
324 writeb(0x1, base + TC_NBLANK);
325
326 /*
327 * Let there be consoles..
328 */
329 strcpy(fb_info.modename, "Topcat");
330 fb_info.changevar = NULL;
331 fb_info.node = -1;
332 fb_info.fbops = &hpfb_ops;
333 fb_info.disp = &disp;
334 fb_info.switch_con = &hpfb_switch;
335 fb_info.updatevar = &fb_update_var;
336 fb_info.blank = &hpfb_blank;
337 fb_info.flags = FBINFO_FLAG_DEFAULT;
338 do_fb_set_var(&hpfb_defined, 1);
339
340 hpfb_get_var(&disp.var, -1, &fb_info);
341 hpfb_set_disp(-1);
342
343 if (register_framebuffer(&fb_info) < 0)
344 return 1;
345
346 return 0;
347 }
348
349 /*
350 * Check that the secondary ID indicates that we have some hope of working with this
351 * framebuffer. The catseye boards are pretty much like topcats and we can muddle through.
352 */
353
354 #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
355 || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
356
357 /*
358 * Initialise the framebuffer
359 */
360
361 int __init hpfb_init(void)
362 {
363 unsigned int sid;
364
365 /* Topcats can be on the internal IO bus or real DIO devices.
366 * The internal variant sits at 0xf0560000; it has primary
367 * and secondary ID registers just like the DIO version.
368 * So we merge the two detection routines.
369 *
370 * Perhaps this #define should be in a global header file:
371 * I believe it's common to all internal fbs, not just topcat.
372 */
373 #define INTFBADDR 0xf0560000
374
375 if (hwreg_present((void *)INTFBADDR) && (DIO_ID(INTFBADDR) == DIO_ID_FBUFFER)
376 && topcat_sid_ok(sid = DIO_SECID(INTFBADDR)))
377 {
378 printk("Internal Topcat found (secondary id %02x)\n", sid);
379 hpfb_init_one(INTFBADDR);
380 }
381 else
382 {
383 int sc = dio_find(DIO_ID_FBUFFER);
384 if (sc)
385 {
386 unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
387 unsigned int sid = DIO_SECID(addr);
388
389 if (topcat_sid_ok(sid))
390 {
391 printk("Topcat found at DIO select code %02x "
392 "(secondary id %02x)\n", sc, sid);
393 hpfb_init_one(addr);
394 }
395 }
396 }
397
398 return 0;
399 }
400
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.