v2.4.9.9 -> v2.4.9.10
[opensuse:kernel.git] / drivers / video / pmagb-b-fb.c
1 /*
2  *      linux/drivers/video/pmagb-b-fb.c
3  *
4  *      PMAGB-B TurboChannel framebuffer card support ... derived from:
5  *      "HP300 Topcat framebuffer support (derived from macfb of all things)
6  *      Phil Blundell <philb@gnu.org> 1998", the original code can be
7  *      found in the file hpfb.c in the same directory.
8  *
9  *      DECstation related code Copyright (C) 1999, 2000, 2001 by
10  *      Michael Engel <engel@unix-ag.org>,
11  *      Karsten Merker <merker@linuxtag.org> and 
12  *      Harald Koerfgen.
13  *      This file is subject to the terms and conditions of the GNU General
14  *      Public License.  See the file COPYING in the main directory of this
15  *      archive for more details.
16  *
17  */
18
19 /*
20  *      We currently only support the PMAGB-B in high resolution mode
21  *      as I know of no way to detect low resolution mode set via jumper.
22  *      KM, 2001/01/07
23  */
24
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/errno.h>
29 #include <linux/string.h>
30 #include <linux/timer.h>
31 #include <linux/mm.h>
32 #include <linux/tty.h>
33 #include <linux/slab.h>
34 #include <linux/delay.h>
35 #include <linux/init.h>
36 #include <linux/fb.h>
37 #include <asm/bootinfo.h>
38 #include <asm/dec/machtype.h>
39 #include <asm/dec/tc.h>
40 #include "pmagb-b-fb.h"
41
42 #include <video/fbcon.h>
43 #include <video/fbcon-mfb.h>
44 #include <video/fbcon-cfb2.h>
45 #include <video/fbcon-cfb4.h>
46 #include <video/fbcon-cfb8.h>
47
48 #define arraysize(x)    (sizeof(x)/sizeof(*(x)))
49
50 struct pmagb_b_ramdac_regs {
51         unsigned char addr_low;
52         unsigned char pad0[3];
53         unsigned char addr_hi;
54         unsigned char pad1[3];
55         unsigned char data;
56         unsigned char pad2[3];
57         unsigned char cmap;
58 };
59
60 struct pmagb_b_my_fb_info {
61         struct fb_info info;
62         struct pmagb_b_ramdac_regs *bt459_regs;
63         unsigned long pmagbb_fb_start;
64         unsigned long pmagbb_fb_size;
65         unsigned long pmagbb_fb_line_length;
66 };
67
68 static struct display disp;
69 /*
70  * Max 3 TURBOchannel slots -> max 3 PMAGB-B :)
71  */
72 static struct pmagb_b_my_fb_info pmagbb_fb_info[3];
73
74 static struct fb_var_screeninfo pmagbbfb_defined = {
75         0, 0, 0, 0,             /* W,H, W, H (virtual) load xres,xres_virtual */
76         0, 0,                   /* virtual -> visible no offset */
77         0,                      /* depth -> load bits_per_pixel */
78         0,                      /* greyscale ? */
79         {0, 0, 0},              /* R */
80         {0, 0, 0},              /* G */
81         {0, 0, 0},              /* B */
82         {0, 0, 0},              /* transparency */
83         0,                      /* standard pixel format */
84         FB_ACTIVATE_NOW,
85         274, 195,               /* 14" monitor */
86         FB_ACCEL_NONE,
87         0L, 0L, 0L, 0L, 0L,
88         0L, 0L, 0,              /* No sync info */
89         FB_VMODE_NONINTERLACED,
90         {0, 0, 0, 0, 0, 0}
91 };
92
93 struct pmagbbfb_par {
94 };
95
96 static int currcon = 0;
97 struct pmagbbfb_par current_par;
98
99 static void pmagbbfb_encode_var(struct fb_var_screeninfo *var,
100                                 struct pmagbbfb_par *par)
101 {
102         int i = 0;
103         var->xres = 1280;
104         var->yres = 1024;
105         var->xres_virtual = 1280;
106         var->yres_virtual = 1024;
107         var->xoffset = 0;
108         var->yoffset = 0;
109         var->bits_per_pixel = 8;
110         var->grayscale = 0;
111         var->transp.offset = 0;
112         var->transp.length = 0;
113         var->transp.msb_right = 0;
114         var->nonstd = 0;
115         var->activate = 1;
116         var->height = -1;
117         var->width = -1;
118         var->vmode = FB_VMODE_NONINTERLACED;
119         var->pixclock = 0;
120         var->sync = 0;
121         var->left_margin = 0;
122         var->right_margin = 0;
123         var->upper_margin = 0;
124         var->lower_margin = 0;
125         var->hsync_len = 0;
126         var->vsync_len = 0;
127         for (i = 0; i < arraysize(var->reserved); i++)
128                 var->reserved[i] = 0;
129 }
130
131 static void pmagbbfb_get_par(struct pmagbbfb_par *par)
132 {
133         *par = current_par;
134 }
135
136 static int pmagbb_fb_update_var(int con, struct fb_info *info)
137 {
138         return 0;
139 }
140
141 static int pmagbb_do_fb_set_var(struct fb_var_screeninfo *var,
142                                 int isactive)
143 {
144         struct pmagbbfb_par par;
145
146         pmagbbfb_get_par(&par);
147         pmagbbfb_encode_var(var, &par);
148         return 0;
149 }
150
151 /*
152  * Turn hardware cursor off
153  */
154 void pmagbbfb_erase_cursor(struct pmagb_b_my_fb_info *info)
155 {
156         info->bt459_regs->addr_low = 0;
157         info->bt459_regs->addr_hi = 3;
158         info->bt459_regs->data = 0;
159 }
160
161 /*
162  * Write to a Bt459 color map register
163  */
164 void pmagb_b_bt459_write_colormap(struct pmagb_b_my_fb_info *info,
165                                   int reg, __u8 red, __u8 green, __u8 blue)
166 {
167         info->bt459_regs->addr_low = (__u8) reg;
168         info->bt459_regs->addr_hi = 0;
169         info->bt459_regs->cmap = red;
170         info->bt459_regs->cmap = green;
171         info->bt459_regs->cmap = blue;
172 }
173
174 /*
175  * Get the palette
176  */
177
178 static int pmagbbfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
179                              struct fb_info *info)
180 {
181         unsigned int i;
182         unsigned int length;
183
184         if (((cmap->start) + (cmap->len)) >= 256) {
185                 length = 256 - (cmap->start);
186         } else {
187                 length = cmap->len;
188         }
189         for (i = 0; i < length; i++) {
190                 /*
191                  * TODO
192                  */
193         }
194         return 0;
195 }
196
197 /*
198  * Set the palette. 
199  */
200 static int pmagbbfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
201                              struct fb_info *info)
202 {
203         unsigned int i;
204         __u8 cmap_red, cmap_green, cmap_blue;
205         unsigned int length;
206
207         if (((cmap->start) + (cmap->len)) >= 256)
208                 length = 256 - (cmap->start);
209         else
210                 length = cmap->len;
211
212         for (i = 0; i < length; i++) {
213                 cmap_red = ((cmap->red[i]) >> 8);       /* The cmap fields are 16 bits    */
214                 cmap_green = ((cmap->green[i]) >> 8);   /* wide, but the harware colormap */
215                 cmap_blue = ((cmap->blue[i]) >> 8);     /* registers are only 8 bits wide */
216
217                 pmagb_b_bt459_write_colormap((struct pmagb_b_my_fb_info *)
218                                              info, cmap->start + i,
219                                              cmap_red, cmap_green,
220                                              cmap_blue);
221         }
222         return 0;
223 }
224
225 static int pmagbbfb_get_var(struct fb_var_screeninfo *var, int con,
226                             struct fb_info *info)
227 {
228         struct pmagbbfb_par par;
229         if (con == -1) {
230                 pmagbbfb_get_par(&par);
231                 pmagbbfb_encode_var(var, &par);
232         } else
233                 *var = fb_display[con].var;
234         return 0;
235 }
236
237
238 static int pmagbbfb_set_var(struct fb_var_screeninfo *var, int con,
239                             struct fb_info *info)
240 {
241         int err;
242
243         if ((err = pmagbb_do_fb_set_var(var, 1)))
244                 return err;
245         return 0;
246 }
247
248 static void pmagbbfb_encode_fix(struct fb_fix_screeninfo *fix,
249                                 struct pmagbbfb_par *par,
250                                 struct pmagb_b_my_fb_info *info)
251 {
252         memset(fix, 0, sizeof(struct fb_fix_screeninfo));
253         strcpy(fix->id, "PMAGB-BA");
254
255         fix->smem_start = info->pmagbb_fb_start;
256         fix->smem_len = info->pmagbb_fb_size;
257         fix->type = FB_TYPE_PACKED_PIXELS;
258         fix->visual = FB_VISUAL_PSEUDOCOLOR;
259         fix->xpanstep = 0;
260         fix->ypanstep = 0;
261         fix->ywrapstep = 0;
262         fix->line_length = info->pmagbb_fb_line_length;
263 }
264
265 static int pmagbbfb_get_fix(struct fb_fix_screeninfo *fix, int con,
266                             struct fb_info *info)
267 {
268         struct pmagbbfb_par par;
269
270         pmagbbfb_get_par(&par);
271         pmagbbfb_encode_fix(fix, &par, (struct pmagb_b_my_fb_info *) info);
272
273         return 0;
274 }
275
276
277 static int pmagbbfb_ioctl(struct inode *inode, struct file *file,
278                           unsigned int cmd, unsigned long arg, int con,
279                           struct fb_info *info)
280 {
281         return -EINVAL;
282 }
283
284 static int pmagbbfb_switch(int con, struct fb_info *info)
285 {
286         pmagbb_do_fb_set_var(&fb_display[con].var, 1);
287         currcon = con;
288
289         return 0;
290 }
291
292 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
293
294 static void pmagbbfb_blank(int blank, struct fb_info *info)
295 {
296         /* Not supported */
297 }
298
299 static int pmagbbfb_open(struct fb_info *info, int user)
300 {
301         /*
302          * Nothing, only a usage count for the moment
303          */
304         MOD_INC_USE_COUNT;
305         return (0);
306 }
307
308 static void pmagbbfb_set_disp(int con, struct pmagb_b_my_fb_info *info)
309 {
310         struct fb_fix_screeninfo fix;
311         struct display *display;
312
313         if (con >= 0)
314                 display = &fb_display[con];
315         else
316                 display = &disp;        /* used during initialization */
317
318         pmagbbfb_get_fix(&fix, con, (struct fb_info *) info);
319
320         display->screen_base = (char *) fix.smem_start;
321         display->visual = fix.visual;
322         display->type = fix.type;
323         display->type_aux = fix.type_aux;
324         display->ypanstep = fix.ypanstep;
325         display->ywrapstep = fix.ywrapstep;
326         display->line_length = fix.line_length;
327         display->next_line = fix.line_length;
328         display->can_soft_blank = 0;
329         display->inverse = 0;
330
331         display->dispsw = &fbcon_cfb8;
332 }
333
334 static int pmagbbfb_release(struct fb_info *info, int user)
335 {
336         MOD_DEC_USE_COUNT;
337         return (0);
338 }
339
340 static struct fb_ops pmagbbfb_ops = {
341         owner:THIS_MODULE,
342         fb_open:pmagbbfb_open,
343         fb_release:pmagbbfb_release,
344         fb_get_fix:pmagbbfb_get_fix,
345         fb_get_var:pmagbbfb_get_var,
346         fb_set_var:pmagbbfb_set_var,
347         fb_get_cmap:pmagbbfb_get_cmap,
348         fb_set_cmap:pmagbbfb_set_cmap,
349         fb_ioctl:pmagbbfb_ioctl,
350         fb_mmap:0,
351         fb_rasterimg:0
352 };
353
354 int __init pmagbbfb_init_one(int slot)
355 {
356         unsigned long base_addr = get_tc_base_addr(slot);
357         struct pmagb_b_my_fb_info *ip =
358             (struct pmagb_b_my_fb_info *) &pmagbb_fb_info[slot];
359
360         printk("PMAGB-BA framebuffer in slot %d\n", slot);
361
362         /*
363          * Framebuffer display memory base address and friends
364          */
365         ip->bt459_regs =
366             (struct pmagb_b_ramdac_regs *) (base_addr +
367                                             PMAGB_B_BT459_OFFSET);
368         ip->pmagbb_fb_start = base_addr + PMAGB_B_ONBOARD_FBMEM_OFFSET;
369         ip->pmagbb_fb_size = 1280 * 1024;
370         ip->pmagbb_fb_line_length = 1280;
371
372         /*
373          * Configure the Bt459 RAM DAC
374          */
375         pmagbbfb_erase_cursor(ip);
376
377         /*
378          *      Fill in the available video resolution
379          */
380
381         pmagbbfb_defined.xres = 1280;
382         pmagbbfb_defined.yres = 1024;
383         pmagbbfb_defined.xres_virtual = 1280;
384         pmagbbfb_defined.yres_virtual = 1024;
385         pmagbbfb_defined.bits_per_pixel = 8;
386
387         /*
388          *      Let there be consoles..
389          */
390         strcpy(ip->info.modename, "PMAGB-BA");
391         ip->info.changevar = NULL;
392         ip->info.node = -1;
393         ip->info.fbops = &pmagbbfb_ops;
394         ip->info.disp = &disp;
395         ip->info.switch_con = &pmagbbfb_switch;
396         ip->info.updatevar = &pmagbb_fb_update_var;
397         ip->info.blank = &pmagbbfb_blank;
398         ip->info.flags = FBINFO_FLAG_DEFAULT;
399
400         pmagbb_do_fb_set_var(&pmagbbfb_defined, 1);
401         pmagbbfb_get_var(&disp.var, -1, (struct fb_info *) ip);
402         pmagbbfb_set_disp(-1, ip);
403
404         if (register_framebuffer((struct fb_info *) ip) < 0)
405                 return 1;
406
407         return 0;
408 }
409
410 /* 
411  * Initialise the framebuffer
412  */
413
414 int __init pmagbbfb_init(void)
415 {
416         int sid;
417         int found = 0;
418
419         if (TURBOCHANNEL) {
420                 while ((sid = search_tc_card("PMAGB-BA")) >= 0) {
421                         found = 1;
422                         claim_tc_card(sid);
423                         pmagbbfb_init_one(sid);
424                 }
425                 return found ? 0 : -ENODEV;
426         } else {
427                 return -ENODEV;
428         }
429 }
430
431 int __init pmagbbfb_setup(char *options)
432 {
433         return 0;
434 }
435
436 MODULE_LICENSE("GPL");