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/slab.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
hpfb_encode_var(struct fb_var_screeninfo * var,struct hpfb_par * par)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
hpfb_get_par(struct hpfb_par * par)112 static void hpfb_get_par(struct hpfb_par *par)
113 {
114 *par=current_par;
115 }
116
fb_update_var(int con,struct fb_info * info)117 static int fb_update_var(int con, struct fb_info *info)
118 {
119 return 0;
120 }
121
do_fb_set_var(struct fb_var_screeninfo * var,int isactive)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
hpfb_get_cmap(struct fb_cmap * cmap,int kspc,int con,struct fb_info * info)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
hpfb_set_cmap(struct fb_cmap * cmap,int kspc,int con,struct fb_info * info)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 (in_be16(fb_regs + 0x6002) & 0x4) udelay(1);
149 out_be16(fb_regs + 0x60f0, 0);
150 out_be16(fb_regs + 0x60b8, cmap->start + i);
151 out_be16(fb_regs + 0x60b2, cmap->red[i]);
152 out_be16(fb_regs + 0x60b4, cmap->green[i]);
153 out_be16(fb_regs + 0x60b6, cmap->blue[i]);
154 out_be16(fb_regs + 0x60f0, 0xff);
155 udelay(100);
156 }
157 out_be16(fb_regs + 0x60ba, 0xffff);
158 return 0;
159 }
160
hpfb_get_var(struct fb_var_screeninfo * var,int con,struct fb_info * info)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
hpfb_set_var(struct fb_var_screeninfo * var,int con,struct fb_info * info)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
hpfb_encode_fix(struct fb_fix_screeninfo * fix,struct hpfb_par * par)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
hpfb_get_fix(struct fb_fix_screeninfo * fix,int con,struct fb_info * info)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
topcat_blit(int x0,int y0,int x1,int y1,int w,int h)213 static void topcat_blit(int x0, int y0, int x1, int y1, int w, int h)
214 {
215 while (in_8(fb_regs + BUSY) & fb_bitmask);
216 out_8(fb_regs + WMRR, 0x3);
217 out_be16(fb_regs + SOURCE_X, x0);
218 out_be16(fb_regs + SOURCE_Y, y0);
219 out_be16(fb_regs + DEST_X, x1);
220 out_be16(fb_regs + DEST_Y, y1);
221 out_be16(fb_regs + WHEIGHT, h);
222 out_be16(fb_regs + WWIDTH, w);
223 out_8(fb_regs + WMOVE, fb_bitmask);
224 }
225
hpfb_switch(int con,struct fb_info * info)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
hpfb_blank(int blank,struct fb_info * info)235 static void hpfb_blank(int blank, struct fb_info *info)
236 {
237 /* Not supported */
238 }
239
hpfb_set_disp(int con)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 = (char *)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 #ifdef FBCON_HAS_CFB8
264 display->dispsw = &fbcon_cfb8;
265 #else
266 display->dispsw = &fbcon_dummy;
267 #endif
268 }
269
270 static struct fb_ops hpfb_ops = {
271 owner: THIS_MODULE,
272 fb_get_fix: hpfb_get_fix,
273 fb_get_var: hpfb_get_var,
274 fb_set_var: hpfb_set_var,
275 fb_get_cmap: hpfb_get_cmap,
276 fb_set_cmap: hpfb_set_cmap,
277 };
278
279 #define TOPCAT_FBOMSB 0x5d
280 #define TOPCAT_FBOLSB 0x5f
281
hpfb_init_one(unsigned long base)282 int __init hpfb_init_one(unsigned long base)
283 {
284 unsigned long fboff;
285
286 fboff = (in_8(base + TOPCAT_FBOMSB) << 8) | in_8(base + TOPCAT_FBOLSB);
287
288 fb_start = 0xf0000000 | (in_8(base + fboff) << 16);
289 fb_regs = base;
290
291 #if 0
292 /* This is the magic incantation NetBSD uses to make Catseye boards work. */
293 out_8(base+0x4800, 0);
294 out_8(base+0x4510, 0);
295 out_8(base+0x4512, 0);
296 out_8(base+0x4514, 0);
297 out_8(base+0x4516, 0);
298 out_8(base+0x4206, 0x90);
299 #endif
300
301 /*
302 * Fill in the available video resolution
303 */
304
305 hpfb_defined.xres = 1024;
306 hpfb_defined.yres = 768;
307 hpfb_defined.xres_virtual = 1024;
308 hpfb_defined.yres_virtual = 768;
309 hpfb_defined.bits_per_pixel = 8;
310
311 /*
312 * Give the hardware a bit of a prod and work out how many bits per
313 * pixel are supported.
314 */
315
316 out_8(base + TC_WEN, 0xff);
317 out_8(base + TC_FBEN, 0xff);
318 out_8(fb_start, 0xff);
319 fb_bitmask = in_8(fb_start);
320
321 /*
322 * Enable reading/writing of all the planes.
323 */
324 out_8(base + TC_WEN, fb_bitmask);
325 out_8(base + TC_REN, fb_bitmask);
326 out_8(base + TC_FBEN, fb_bitmask);
327 out_8(base + TC_NBLANK, 0x1);
328
329 /*
330 * Let there be consoles..
331 */
332 strcpy(fb_info.modename, "Topcat");
333 fb_info.changevar = NULL;
334 fb_info.node = -1;
335 fb_info.fbops = &hpfb_ops;
336 fb_info.disp = &disp;
337 fb_info.switch_con = &hpfb_switch;
338 fb_info.updatevar = &fb_update_var;
339 fb_info.blank = &hpfb_blank;
340 fb_info.flags = FBINFO_FLAG_DEFAULT;
341 do_fb_set_var(&hpfb_defined, 1);
342
343 hpfb_get_var(&disp.var, -1, &fb_info);
344 hpfb_set_disp(-1);
345
346 if (register_framebuffer(&fb_info) < 0)
347 return 1;
348
349 return 0;
350 }
351
352 /*
353 * Check that the secondary ID indicates that we have some hope of working with this
354 * framebuffer. The catseye boards are pretty much like topcats and we can muddle through.
355 */
356
357 #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
358 || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
359
360 /*
361 * Initialise the framebuffer
362 */
363
hpfb_init(void)364 int __init hpfb_init(void)
365 {
366 unsigned int sid;
367
368 /* Topcats can be on the internal IO bus or real DIO devices.
369 * The internal variant sits at 0xf0560000; it has primary
370 * and secondary ID registers just like the DIO version.
371 * So we merge the two detection routines.
372 *
373 * Perhaps this #define should be in a global header file:
374 * I believe it's common to all internal fbs, not just topcat.
375 */
376 #define INTFBADDR 0xf0560000
377
378 if (hwreg_present((void *)INTFBADDR) && (DIO_ID(INTFBADDR) == DIO_ID_FBUFFER)
379 && topcat_sid_ok(sid = DIO_SECID(INTFBADDR)))
380 {
381 printk("Internal Topcat found (secondary id %02x)\n", sid);
382 hpfb_init_one(INTFBADDR);
383 }
384 else
385 {
386 int sc = dio_find(DIO_ID_FBUFFER);
387 if (sc)
388 {
389 unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
390 unsigned int sid = DIO_SECID(addr);
391
392 if (topcat_sid_ok(sid))
393 {
394 printk("Topcat found at DIO select code %02x "
395 "(secondary id %02x)\n", sc, sid);
396 hpfb_init_one(addr);
397 }
398 }
399 }
400
401 return 0;
402 }
403
404 MODULE_LICENSE("GPL");
405