Merge remote-tracking branch 'pm/linux-next'
[linux-2.6/next.git] / drivers / video / pmag-aa-fb.c
blob838424817de2307e0af1c92358ebaf412d5b7c92
1 /*
2 * linux/drivers/video/pmag-aa-fb.c
3 * Copyright 2002 Karsten Merker <merker@debian.org>
5 * PMAG-AA TurboChannel framebuffer card support ... derived from
6 * pmag-ba-fb.c, which is Copyright (C) 1999, 2000, 2001 by
7 * Michael Engel <engel@unix-ag.org>, Karsten Merker <merker@debian.org>
8 * and Harald Koerfgen <hkoerfg@web.de>, which itself is derived from
9 * "HP300 Topcat framebuffer support (derived from macfb of all things)
10 * Phil Blundell <philb@gnu.org> 1998"
12 * This file is subject to the terms and conditions of the GNU General
13 * Public License. See the file COPYING in the main directory of this
14 * archive for more details.
16 * 2002-09-28 Karsten Merker <merker@linuxtag.org>
17 * Version 0.01: First try to get a PMAG-AA running.
19 * 2003-02-24 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
20 * Version 0.02: Major code cleanup.
22 * 2003-09-21 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
23 * Hardware cursor support.
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/string.h>
29 #include <linux/timer.h>
30 #include <linux/mm.h>
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/fb.h>
34 #include <linux/console.h>
36 #include <asm/bootinfo.h>
37 #include <asm/dec/machtype.h>
38 #include <asm/dec/tc.h>
40 #include <video/fbcon.h>
41 #include <video/fbcon-cfb8.h>
43 #include "bt455.h"
44 #include "bt431.h"
46 /* Version information */
47 #define DRIVER_VERSION "0.02"
48 #define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>"
49 #define DRIVER_DESCRIPTION "PMAG-AA Framebuffer Driver"
51 /* Prototypes */
52 static int aafb_set_var(struct fb_var_screeninfo *var, int con,
53 struct fb_info *info);
56 * Bt455 RAM DAC register base offset (rel. to TC slot base address).
58 #define PMAG_AA_BT455_OFFSET 0x100000
61 * Bt431 cursor generator offset (rel. to TC slot base address).
63 #define PMAG_AA_BT431_OFFSET 0x180000
66 * Begin of PMAG-AA framebuffer memory relative to TC slot address,
67 * resolution is 1280x1024x1 (8 bits deep, but only LSB is used).
69 #define PMAG_AA_ONBOARD_FBMEM_OFFSET 0x200000
71 struct aafb_cursor {
72 struct timer_list timer;
73 int enable;
74 int on;
75 int vbl_cnt;
76 int blink_rate;
77 u16 x, y, width, height;
80 #define CURSOR_TIMER_FREQ (HZ / 50)
81 #define CURSOR_BLINK_RATE (20)
82 #define CURSOR_DRAW_DELAY (2)
84 struct aafb_info {
85 struct fb_info info;
86 struct display disp;
87 struct aafb_cursor cursor;
88 struct bt455_regs *bt455;
89 struct bt431_regs *bt431;
90 unsigned long fb_start;
91 unsigned long fb_size;
92 unsigned long fb_line_length;
96 * Max 3 TURBOchannel slots -> max 3 PMAG-AA.
98 static struct aafb_info my_fb_info[3];
100 static struct aafb_par {
101 } current_par;
103 static int currcon = -1;
105 static void aafb_set_cursor(struct aafb_info *info, int on)
107 struct aafb_cursor *c = &info->cursor;
109 if (on) {
110 bt431_position_cursor(info->bt431, c->x, c->y);
111 bt431_enable_cursor(info->bt431);
112 } else
113 bt431_erase_cursor(info->bt431);
116 static void aafbcon_cursor(struct display *disp, int mode, int x, int y)
118 struct aafb_info *info = (struct aafb_info *)disp->fb_info;
119 struct aafb_cursor *c = &info->cursor;
121 x *= fontwidth(disp);
122 y *= fontheight(disp);
124 if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable)
125 return;
127 c->enable = 0;
128 if (c->on)
129 aafb_set_cursor(info, 0);
130 c->x = x - disp->var.xoffset;
131 c->y = y - disp->var.yoffset;
133 switch (mode) {
134 case CM_ERASE:
135 c->on = 0;
136 break;
137 case CM_DRAW:
138 case CM_MOVE:
139 if (c->on)
140 aafb_set_cursor(info, c->on);
141 else
142 c->vbl_cnt = CURSOR_DRAW_DELAY;
143 c->enable = 1;
144 break;
148 static int aafbcon_set_font(struct display *disp, int width, int height)
150 struct aafb_info *info = (struct aafb_info *)disp->fb_info;
151 struct aafb_cursor *c = &info->cursor;
152 u8 fgc = ~attr_bgcol_ec(disp, disp->conp, &info->info);
154 if (width > 64 || height > 64 || width < 0 || height < 0)
155 return -EINVAL;
157 c->height = height;
158 c->width = width;
160 bt431_set_font(info->bt431, fgc, width, height);
162 return 1;
165 static void aafb_cursor_timer_handler(unsigned long data)
167 struct aafb_info *info = (struct aafb_info *)data;
168 struct aafb_cursor *c = &info->cursor;
170 if (!c->enable)
171 goto out;
173 if (c->vbl_cnt && --c->vbl_cnt == 0) {
174 c->on ^= 1;
175 aafb_set_cursor(info, c->on);
176 c->vbl_cnt = c->blink_rate;
179 out:
180 c->timer.expires = jiffies + CURSOR_TIMER_FREQ;
181 add_timer(&c->timer);
184 static void __init aafb_cursor_init(struct aafb_info *info)
186 struct aafb_cursor *c = &info->cursor;
188 c->enable = 1;
189 c->on = 1;
190 c->x = c->y = 0;
191 c->width = c->height = 0;
192 c->vbl_cnt = CURSOR_DRAW_DELAY;
193 c->blink_rate = CURSOR_BLINK_RATE;
195 init_timer(&c->timer);
196 c->timer.data = (unsigned long)info;
197 c->timer.function = aafb_cursor_timer_handler;
198 mod_timer(&c->timer, jiffies + CURSOR_TIMER_FREQ);
201 static void __exit aafb_cursor_exit(struct aafb_info *info)
203 struct aafb_cursor *c = &info->cursor;
205 del_timer_sync(&c->timer);
208 static struct display_switch aafb_switch8 = {
209 .setup = fbcon_cfb8_setup,
210 .bmove = fbcon_cfb8_bmove,
211 .clear = fbcon_cfb8_clear,
212 .putc = fbcon_cfb8_putc,
213 .putcs = fbcon_cfb8_putcs,
214 .revc = fbcon_cfb8_revc,
215 .cursor = aafbcon_cursor,
216 .set_font = aafbcon_set_font,
217 .clear_margins = fbcon_cfb8_clear_margins,
218 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
221 static void aafb_get_par(struct aafb_par *par)
223 *par = current_par;
226 static int aafb_get_fix(struct fb_fix_screeninfo *fix, int con,
227 struct fb_info *info)
229 struct aafb_info *ip = (struct aafb_info *)info;
231 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
232 strcpy(fix->id, "PMAG-AA");
233 fix->smem_start = ip->fb_start;
234 fix->smem_len = ip->fb_size;
235 fix->type = FB_TYPE_PACKED_PIXELS;
236 fix->ypanstep = 1;
237 fix->ywrapstep = 1;
238 fix->visual = FB_VISUAL_MONO10;
239 fix->line_length = 1280;
240 fix->accel = FB_ACCEL_NONE;
242 return 0;
245 static void aafb_set_disp(struct display *disp, int con,
246 struct aafb_info *info)
248 struct fb_fix_screeninfo fix;
250 disp->fb_info = &info->info;
251 aafb_set_var(&disp->var, con, &info->info);
252 if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor)
253 disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE);
254 disp->dispsw = &aafb_switch8;
255 disp->dispsw_data = 0;
257 aafb_get_fix(&fix, con, &info->info);
258 disp->screen_base = (u8 *) fix.smem_start;
259 disp->visual = fix.visual;
260 disp->type = fix.type;
261 disp->type_aux = fix.type_aux;
262 disp->ypanstep = fix.ypanstep;
263 disp->ywrapstep = fix.ywrapstep;
264 disp->line_length = fix.line_length;
265 disp->next_line = 2048;
266 disp->can_soft_blank = 1;
267 disp->inverse = 0;
268 disp->scrollmode = SCROLL_YREDRAW;
270 aafbcon_set_font(disp, fontwidth(disp), fontheight(disp));
273 static int aafb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
274 struct fb_info *info)
276 static u16 color[2] = {0x0000, 0x000f};
277 static struct fb_cmap aafb_cmap = {0, 2, color, color, color, NULL};
279 fb_copy_cmap(&aafb_cmap, cmap, kspc ? 0 : 2);
280 return 0;
283 static int aafb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
284 struct fb_info *info)
286 u16 color[2] = {0x0000, 0x000f};
288 if (cmap->start == 0
289 && cmap->len == 2
290 && memcmp(cmap->red, color, sizeof(color)) == 0
291 && memcmp(cmap->green, color, sizeof(color)) == 0
292 && memcmp(cmap->blue, color, sizeof(color)) == 0
293 && cmap->transp == NULL)
294 return 0;
295 else
296 return -EINVAL;
299 static int aafb_ioctl(struct fb_info *info, u32 cmd, unsigned long arg)
301 /* TODO: Not yet implemented */
302 return -ENOIOCTLCMD;
305 static int aafb_switch(int con, struct fb_info *info)
307 struct aafb_info *ip = (struct aafb_info *)info;
308 struct display *old = (currcon < 0) ? &ip->disp : (fb_display + currcon);
309 struct display *new = (con < 0) ? &ip->disp : (fb_display + con);
311 if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor)
312 old->conp->vc_sw->con_cursor(old->conp, CM_ERASE);
314 /* Set the current console. */
315 currcon = con;
316 aafb_set_disp(new, con, ip);
318 return 0;
321 static void aafb_encode_var(struct fb_var_screeninfo *var,
322 struct aafb_par *par)
324 var->xres = 1280;
325 var->yres = 1024;
326 var->xres_virtual = 2048;
327 var->yres_virtual = 1024;
328 var->xoffset = 0;
329 var->yoffset = 0;
330 var->bits_per_pixel = 8;
331 var->grayscale = 1;
332 var->red.offset = 0;
333 var->red.length = 0;
334 var->red.msb_right = 0;
335 var->green.offset = 0;
336 var->green.length = 1;
337 var->green.msb_right = 0;
338 var->blue.offset = 0;
339 var->blue.length = 0;
340 var->blue.msb_right = 0;
341 var->transp.offset = 0;
342 var->transp.length = 0;
343 var->transp.msb_right = 0;
344 var->nonstd = 0;
345 var->activate &= ~FB_ACTIVATE_MASK & FB_ACTIVATE_NOW;
346 var->accel_flags = 0;
347 var->sync = FB_SYNC_ON_GREEN;
348 var->vmode &= ~FB_VMODE_MASK & FB_VMODE_NONINTERLACED;
351 static int aafb_get_var(struct fb_var_screeninfo *var, int con,
352 struct fb_info *info)
354 if (con < 0) {
355 struct aafb_par par;
357 memset(var, 0, sizeof(struct fb_var_screeninfo));
358 aafb_get_par(&par);
359 aafb_encode_var(var, &par);
360 } else
361 *var = info->var;
363 return 0;
366 static int aafb_set_var(struct fb_var_screeninfo *var, int con,
367 struct fb_info *info)
369 struct aafb_par par;
371 aafb_get_par(&par);
372 aafb_encode_var(var, &par);
373 info->var = *var;
375 return 0;
378 static int aafb_update_var(int con, struct fb_info *info)
380 struct aafb_info *ip = (struct aafb_info *)info;
381 struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
383 if (con == currcon)
384 aafbcon_cursor(disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
386 return 0;
389 /* 0 unblanks, any other blanks. */
391 static void aafb_blank(int blank, struct fb_info *info)
393 struct aafb_info *ip = (struct aafb_info *)info;
394 u8 val = blank ? 0x00 : 0x0f;
396 bt455_write_cmap_entry(ip->bt455, 1, val, val, val);
397 aafbcon_cursor(&ip->disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
400 static struct fb_ops aafb_ops = {
401 .owner = THIS_MODULE,
402 .fb_get_fix = aafb_get_fix,
403 .fb_get_var = aafb_get_var,
404 .fb_set_var = aafb_set_var,
405 .fb_get_cmap = aafb_get_cmap,
406 .fb_set_cmap = aafb_set_cmap,
407 .fb_ioctl = aafb_ioctl
410 static int __init init_one(int slot)
412 unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot));
413 struct aafb_info *ip = &my_fb_info[slot];
415 memset(ip, 0, sizeof(struct aafb_info));
418 * Framebuffer display memory base address and friends.
420 ip->bt455 = (struct bt455_regs *) (base_addr + PMAG_AA_BT455_OFFSET);
421 ip->bt431 = (struct bt431_regs *) (base_addr + PMAG_AA_BT431_OFFSET);
422 ip->fb_start = base_addr + PMAG_AA_ONBOARD_FBMEM_OFFSET;
423 ip->fb_size = 2048 * 1024; /* fb_fix_screeninfo.smem_length
424 seems to be physical */
425 ip->fb_line_length = 2048;
428 * Let there be consoles..
430 strcpy(ip->info.modename, "PMAG-AA");
431 ip->info.node = -1;
432 ip->info.flags = FBINFO_FLAG_DEFAULT;
433 ip->info.fbops = &aafb_ops;
434 ip->info.disp = &ip->disp;
435 ip->info.changevar = NULL;
436 ip->info.switch_con = &aafb_switch;
437 ip->info.updatevar = &aafb_update_var;
438 ip->info.blank = &aafb_blank;
440 aafb_set_disp(&ip->disp, currcon, ip);
443 * Configure the RAM DACs.
445 bt455_erase_cursor(ip->bt455);
447 /* Init colormap. */
448 bt455_write_cmap_entry(ip->bt455, 0, 0x00, 0x00, 0x00);
449 bt455_write_cmap_entry(ip->bt455, 1, 0x0f, 0x0f, 0x0f);
451 /* Init hardware cursor. */
452 bt431_init_cursor(ip->bt431);
453 aafb_cursor_init(ip);
455 /* Clear the screen. */
456 memset ((void *)ip->fb_start, 0, ip->fb_size);
458 if (register_framebuffer(&ip->info) < 0)
459 return -EINVAL;
461 printk(KERN_INFO "fb%d: %s frame buffer in TC slot %d\n",
462 GET_FB_IDX(ip->info.node), ip->info.modename, slot);
464 return 0;
467 static int __exit exit_one(int slot)
469 struct aafb_info *ip = &my_fb_info[slot];
471 if (unregister_framebuffer(&ip->info) < 0)
472 return -EINVAL;
474 return 0;
478 * Initialise the framebuffer.
480 int __init pmagaafb_init(void)
482 int sid;
483 int found = 0;
485 while ((sid = search_tc_card("PMAG-AA")) >= 0) {
486 found = 1;
487 claim_tc_card(sid);
488 init_one(sid);
491 return found ? 0 : -ENXIO;
494 static void __exit pmagaafb_exit(void)
496 int sid;
498 while ((sid = search_tc_card("PMAG-AA")) >= 0) {
499 exit_one(sid);
500 release_tc_card(sid);
504 MODULE_AUTHOR(DRIVER_AUTHOR);
505 MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
506 MODULE_LICENSE("GPL");
507 #ifdef MODULE
508 module_init(pmagaafb_init);
509 module_exit(pmagaafb_exit);
510 #endif