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