Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/video/pmag-aa-fb.c | |
3 | * Copyright 2002 Karsten Merker <merker@debian.org> | |
4 | * | |
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" | |
11 | * | |
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. | |
15 | * | |
16 | * 2002-09-28 Karsten Merker <merker@linuxtag.org> | |
17 | * Version 0.01: First try to get a PMAG-AA running. | |
18 | * | |
19 | * 2003-02-24 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de> | |
20 | * Version 0.02: Major code cleanup. | |
21 | * | |
22 | * 2003-09-21 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de> | |
23 | * Hardware cursor support. | |
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 <linux/console.h> | |
38 | ||
39 | #include <asm/bootinfo.h> | |
40 | #include <asm/dec/machtype.h> | |
41 | #include <asm/dec/tc.h> | |
42 | ||
43 | #include <video/fbcon.h> | |
44 | #include <video/fbcon-cfb8.h> | |
45 | ||
46 | #include "bt455.h" | |
47 | #include "bt431.h" | |
48 | ||
49 | /* Version information */ | |
50 | #define DRIVER_VERSION "0.02" | |
51 | #define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>" | |
52 | #define DRIVER_DESCRIPTION "PMAG-AA Framebuffer Driver" | |
53 | ||
54 | /* Prototypes */ | |
55 | static int aafb_set_var(struct fb_var_screeninfo *var, int con, | |
56 | struct fb_info *info); | |
57 | ||
58 | /* | |
59 | * Bt455 RAM DAC register base offset (rel. to TC slot base address). | |
60 | */ | |
61 | #define PMAG_AA_BT455_OFFSET 0x100000 | |
62 | ||
63 | /* | |
64 | * Bt431 cursor generator offset (rel. to TC slot base address). | |
65 | */ | |
66 | #define PMAG_AA_BT431_OFFSET 0x180000 | |
67 | ||
68 | /* | |
69 | * Begin of PMAG-AA framebuffer memory relative to TC slot address, | |
70 | * resolution is 1280x1024x1 (8 bits deep, but only LSB is used). | |
71 | */ | |
72 | #define PMAG_AA_ONBOARD_FBMEM_OFFSET 0x200000 | |
73 | ||
74 | struct aafb_cursor { | |
75 | struct timer_list timer; | |
76 | int enable; | |
77 | int on; | |
78 | int vbl_cnt; | |
79 | int blink_rate; | |
80 | u16 x, y, width, height; | |
81 | }; | |
82 | ||
83 | #define CURSOR_TIMER_FREQ (HZ / 50) | |
84 | #define CURSOR_BLINK_RATE (20) | |
85 | #define CURSOR_DRAW_DELAY (2) | |
86 | ||
87 | struct aafb_info { | |
88 | struct fb_info info; | |
89 | struct display disp; | |
90 | struct aafb_cursor cursor; | |
91 | struct bt455_regs *bt455; | |
92 | struct bt431_regs *bt431; | |
93 | unsigned long fb_start; | |
94 | unsigned long fb_size; | |
95 | unsigned long fb_line_length; | |
96 | }; | |
97 | ||
98 | /* | |
99 | * Max 3 TURBOchannel slots -> max 3 PMAG-AA. | |
100 | */ | |
101 | static struct aafb_info my_fb_info[3]; | |
102 | ||
103 | static struct aafb_par { | |
104 | } current_par; | |
105 | ||
106 | static int currcon = -1; | |
107 | ||
108 | static void aafb_set_cursor(struct aafb_info *info, int on) | |
109 | { | |
110 | struct aafb_cursor *c = &info->cursor; | |
111 | ||
112 | if (on) { | |
113 | bt431_position_cursor(info->bt431, c->x, c->y); | |
114 | bt431_enable_cursor(info->bt431); | |
115 | } else | |
116 | bt431_erase_cursor(info->bt431); | |
117 | } | |
118 | ||
119 | static void aafbcon_cursor(struct display *disp, int mode, int x, int y) | |
120 | { | |
121 | struct aafb_info *info = (struct aafb_info *)disp->fb_info; | |
122 | struct aafb_cursor *c = &info->cursor; | |
123 | ||
124 | x *= fontwidth(disp); | |
125 | y *= fontheight(disp); | |
126 | ||
127 | if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable) | |
128 | return; | |
129 | ||
130 | c->enable = 0; | |
131 | if (c->on) | |
132 | aafb_set_cursor(info, 0); | |
133 | c->x = x - disp->var.xoffset; | |
134 | c->y = y - disp->var.yoffset; | |
135 | ||
136 | switch (mode) { | |
137 | case CM_ERASE: | |
138 | c->on = 0; | |
139 | break; | |
140 | case CM_DRAW: | |
141 | case CM_MOVE: | |
142 | if (c->on) | |
143 | aafb_set_cursor(info, c->on); | |
144 | else | |
145 | c->vbl_cnt = CURSOR_DRAW_DELAY; | |
146 | c->enable = 1; | |
147 | break; | |
148 | } | |
149 | } | |
150 | ||
151 | static int aafbcon_set_font(struct display *disp, int width, int height) | |
152 | { | |
153 | struct aafb_info *info = (struct aafb_info *)disp->fb_info; | |
154 | struct aafb_cursor *c = &info->cursor; | |
155 | u8 fgc = ~attr_bgcol_ec(disp, disp->conp); | |
156 | ||
157 | if (width > 64 || height > 64 || width < 0 || height < 0) | |
158 | return -EINVAL; | |
159 | ||
160 | c->height = height; | |
161 | c->width = width; | |
162 | ||
163 | bt431_set_font(info->bt431, fgc, width, height); | |
164 | ||
165 | return 1; | |
166 | } | |
167 | ||
168 | static void aafb_cursor_timer_handler(unsigned long data) | |
169 | { | |
170 | struct aafb_info *info = (struct aafb_info *)data; | |
171 | struct aafb_cursor *c = &info->cursor; | |
172 | ||
173 | if (!c->enable) | |
174 | goto out; | |
175 | ||
176 | if (c->vbl_cnt && --c->vbl_cnt == 0) { | |
177 | c->on ^= 1; | |
178 | aafb_set_cursor(info, c->on); | |
179 | c->vbl_cnt = c->blink_rate; | |
180 | } | |
181 | ||
182 | out: | |
183 | c->timer.expires = jiffies + CURSOR_TIMER_FREQ; | |
184 | add_timer(&c->timer); | |
185 | } | |
186 | ||
187 | static void __init aafb_cursor_init(struct aafb_info *info) | |
188 | { | |
189 | struct aafb_cursor *c = &info->cursor; | |
190 | ||
191 | c->enable = 1; | |
192 | c->on = 1; | |
193 | c->x = c->y = 0; | |
194 | c->width = c->height = 0; | |
195 | c->vbl_cnt = CURSOR_DRAW_DELAY; | |
196 | c->blink_rate = CURSOR_BLINK_RATE; | |
197 | ||
198 | init_timer(&c->timer); | |
199 | c->timer.data = (unsigned long)info; | |
200 | c->timer.function = aafb_cursor_timer_handler; | |
201 | mod_timer(&c->timer, jiffies + CURSOR_TIMER_FREQ); | |
202 | } | |
203 | ||
204 | static void __exit aafb_cursor_exit(struct aafb_info *info) | |
205 | { | |
206 | struct aafb_cursor *c = &info->cursor; | |
207 | ||
208 | del_timer_sync(&c->timer); | |
209 | } | |
210 | ||
211 | static struct display_switch aafb_switch8 = { | |
212 | .setup = fbcon_cfb8_setup, | |
213 | .bmove = fbcon_cfb8_bmove, | |
214 | .clear = fbcon_cfb8_clear, | |
215 | .putc = fbcon_cfb8_putc, | |
216 | .putcs = fbcon_cfb8_putcs, | |
217 | .revc = fbcon_cfb8_revc, | |
218 | .cursor = aafbcon_cursor, | |
219 | .set_font = aafbcon_set_font, | |
220 | .clear_margins = fbcon_cfb8_clear_margins, | |
221 | .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16) | |
222 | }; | |
223 | ||
224 | static void aafb_get_par(struct aafb_par *par) | |
225 | { | |
226 | *par = current_par; | |
227 | } | |
228 | ||
229 | static int aafb_get_fix(struct fb_fix_screeninfo *fix, int con, | |
230 | struct fb_info *info) | |
231 | { | |
232 | struct aafb_info *ip = (struct aafb_info *)info; | |
233 | ||
234 | memset(fix, 0, sizeof(struct fb_fix_screeninfo)); | |
235 | strcpy(fix->id, "PMAG-AA"); | |
236 | fix->smem_start = ip->fb_start; | |
237 | fix->smem_len = ip->fb_size; | |
238 | fix->type = FB_TYPE_PACKED_PIXELS; | |
239 | fix->ypanstep = 1; | |
240 | fix->ywrapstep = 1; | |
241 | fix->visual = FB_VISUAL_MONO10; | |
242 | fix->line_length = 1280; | |
243 | fix->accel = FB_ACCEL_NONE; | |
244 | ||
245 | return 0; | |
246 | } | |
247 | ||
248 | static void aafb_set_disp(struct display *disp, int con, | |
249 | struct aafb_info *info) | |
250 | { | |
251 | struct fb_fix_screeninfo fix; | |
252 | ||
253 | disp->fb_info = &info->info; | |
254 | aafb_set_var(&disp->var, con, &info->info); | |
255 | if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor) | |
256 | disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE); | |
257 | disp->dispsw = &aafb_switch8; | |
258 | disp->dispsw_data = 0; | |
259 | ||
260 | aafb_get_fix(&fix, con, &info->info); | |
261 | disp->screen_base = (u8 *) fix.smem_start; | |
262 | disp->visual = fix.visual; | |
263 | disp->type = fix.type; | |
264 | disp->type_aux = fix.type_aux; | |
265 | disp->ypanstep = fix.ypanstep; | |
266 | disp->ywrapstep = fix.ywrapstep; | |
267 | disp->line_length = fix.line_length; | |
268 | disp->next_line = 2048; | |
269 | disp->can_soft_blank = 1; | |
270 | disp->inverse = 0; | |
271 | disp->scrollmode = SCROLL_YREDRAW; | |
272 | ||
273 | aafbcon_set_font(disp, fontwidth(disp), fontheight(disp)); | |
274 | } | |
275 | ||
276 | static int aafb_get_cmap(struct fb_cmap *cmap, int kspc, int con, | |
277 | struct fb_info *info) | |
278 | { | |
279 | static u16 color[2] = {0x0000, 0x000f}; | |
280 | static struct fb_cmap aafb_cmap = {0, 2, color, color, color, NULL}; | |
281 | ||
282 | fb_copy_cmap(&aafb_cmap, cmap, kspc ? 0 : 2); | |
283 | return 0; | |
284 | } | |
285 | ||
286 | static int aafb_set_cmap(struct fb_cmap *cmap, int kspc, int con, | |
287 | struct fb_info *info) | |
288 | { | |
289 | u16 color[2] = {0x0000, 0x000f}; | |
290 | ||
291 | if (cmap->start == 0 | |
292 | && cmap->len == 2 | |
293 | && memcmp(cmap->red, color, sizeof(color)) == 0 | |
294 | && memcmp(cmap->green, color, sizeof(color)) == 0 | |
295 | && memcmp(cmap->blue, color, sizeof(color)) == 0 | |
296 | && cmap->transp == NULL) | |
297 | return 0; | |
298 | else | |
299 | return -EINVAL; | |
300 | } | |
301 | ||
302 | static int aafb_ioctl(struct inode *inode, struct file *file, u32 cmd, | |
303 | unsigned long arg, int con, struct fb_info *info) | |
304 | { | |
305 | /* TODO: Not yet implemented */ | |
306 | return -ENOIOCTLCMD; | |
307 | } | |
308 | ||
309 | static int aafb_switch(int con, struct fb_info *info) | |
310 | { | |
311 | struct aafb_info *ip = (struct aafb_info *)info; | |
312 | struct display *old = (currcon < 0) ? &ip->disp : (fb_display + currcon); | |
313 | struct display *new = (con < 0) ? &ip->disp : (fb_display + con); | |
314 | ||
315 | if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor) | |
316 | old->conp->vc_sw->con_cursor(old->conp, CM_ERASE); | |
317 | ||
318 | /* Set the current console. */ | |
319 | currcon = con; | |
320 | aafb_set_disp(new, con, ip); | |
321 | ||
322 | return 0; | |
323 | } | |
324 | ||
325 | static void aafb_encode_var(struct fb_var_screeninfo *var, | |
326 | struct aafb_par *par) | |
327 | { | |
328 | var->xres = 1280; | |
329 | var->yres = 1024; | |
330 | var->xres_virtual = 2048; | |
331 | var->yres_virtual = 1024; | |
332 | var->xoffset = 0; | |
333 | var->yoffset = 0; | |
334 | var->bits_per_pixel = 8; | |
335 | var->grayscale = 1; | |
336 | var->red.offset = 0; | |
337 | var->red.length = 0; | |
338 | var->red.msb_right = 0; | |
339 | var->green.offset = 0; | |
340 | var->green.length = 1; | |
341 | var->green.msb_right = 0; | |
342 | var->blue.offset = 0; | |
343 | var->blue.length = 0; | |
344 | var->blue.msb_right = 0; | |
345 | var->transp.offset = 0; | |
346 | var->transp.length = 0; | |
347 | var->transp.msb_right = 0; | |
348 | var->nonstd = 0; | |
349 | var->activate &= ~FB_ACTIVATE_MASK & FB_ACTIVATE_NOW; | |
350 | var->accel_flags = 0; | |
351 | var->sync = FB_SYNC_ON_GREEN; | |
352 | var->vmode &= ~FB_VMODE_MASK & FB_VMODE_NONINTERLACED; | |
353 | } | |
354 | ||
355 | static int aafb_get_var(struct fb_var_screeninfo *var, int con, | |
356 | struct fb_info *info) | |
357 | { | |
358 | if (con < 0) { | |
359 | struct aafb_par par; | |
360 | ||
361 | memset(var, 0, sizeof(struct fb_var_screeninfo)); | |
362 | aafb_get_par(&par); | |
363 | aafb_encode_var(var, &par); | |
364 | } else | |
365 | *var = info->var; | |
366 | ||
367 | return 0; | |
368 | } | |
369 | ||
370 | static int aafb_set_var(struct fb_var_screeninfo *var, int con, | |
371 | struct fb_info *info) | |
372 | { | |
373 | struct aafb_par par; | |
374 | ||
375 | aafb_get_par(&par); | |
376 | aafb_encode_var(var, &par); | |
377 | info->var = *var; | |
378 | ||
379 | return 0; | |
380 | } | |
381 | ||
382 | static int aafb_update_var(int con, struct fb_info *info) | |
383 | { | |
384 | struct aafb_info *ip = (struct aafb_info *)info; | |
385 | struct display *disp = (con < 0) ? &ip->disp : (fb_display + con); | |
386 | ||
387 | if (con == currcon) | |
388 | aafbcon_cursor(disp, CM_ERASE, ip->cursor.x, ip->cursor.y); | |
389 | ||
390 | return 0; | |
391 | } | |
392 | ||
393 | /* 0 unblanks, any other blanks. */ | |
394 | ||
395 | static void aafb_blank(int blank, struct fb_info *info) | |
396 | { | |
397 | struct aafb_info *ip = (struct aafb_info *)info; | |
398 | u8 val = blank ? 0x00 : 0x0f; | |
399 | ||
400 | bt455_write_cmap_entry(ip->bt455, 1, val, val, val); | |
401 | aafbcon_cursor(&ip->disp, CM_ERASE, ip->cursor.x, ip->cursor.y); | |
402 | } | |
403 | ||
404 | static struct fb_ops aafb_ops = { | |
405 | .owner = THIS_MODULE, | |
406 | .fb_get_fix = aafb_get_fix, | |
407 | .fb_get_var = aafb_get_var, | |
408 | .fb_set_var = aafb_set_var, | |
409 | .fb_get_cmap = aafb_get_cmap, | |
410 | .fb_set_cmap = aafb_set_cmap, | |
411 | .fb_ioctl = aafb_ioctl | |
412 | }; | |
413 | ||
414 | static int __init init_one(int slot) | |
415 | { | |
61838ffe | 416 | unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot)); |
1da177e4 LT |
417 | struct aafb_info *ip = &my_fb_info[slot]; |
418 | ||
419 | memset(ip, 0, sizeof(struct aafb_info)); | |
420 | ||
421 | /* | |
422 | * Framebuffer display memory base address and friends. | |
423 | */ | |
424 | ip->bt455 = (struct bt455_regs *) (base_addr + PMAG_AA_BT455_OFFSET); | |
425 | ip->bt431 = (struct bt431_regs *) (base_addr + PMAG_AA_BT431_OFFSET); | |
426 | ip->fb_start = base_addr + PMAG_AA_ONBOARD_FBMEM_OFFSET; | |
427 | ip->fb_size = 2048 * 1024; /* fb_fix_screeninfo.smem_length | |
428 | seems to be physical */ | |
429 | ip->fb_line_length = 2048; | |
430 | ||
431 | /* | |
432 | * Let there be consoles.. | |
433 | */ | |
434 | strcpy(ip->info.modename, "PMAG-AA"); | |
435 | ip->info.node = -1; | |
436 | ip->info.flags = FBINFO_FLAG_DEFAULT; | |
437 | ip->info.fbops = &aafb_ops; | |
438 | ip->info.disp = &ip->disp; | |
439 | ip->info.changevar = NULL; | |
440 | ip->info.switch_con = &aafb_switch; | |
441 | ip->info.updatevar = &aafb_update_var; | |
442 | ip->info.blank = &aafb_blank; | |
443 | ||
444 | aafb_set_disp(&ip->disp, currcon, ip); | |
445 | ||
446 | /* | |
447 | * Configure the RAM DACs. | |
448 | */ | |
449 | bt455_erase_cursor(ip->bt455); | |
450 | ||
451 | /* Init colormap. */ | |
452 | bt455_write_cmap_entry(ip->bt455, 0, 0x00, 0x00, 0x00); | |
453 | bt455_write_cmap_entry(ip->bt455, 1, 0x0f, 0x0f, 0x0f); | |
454 | ||
455 | /* Init hardware cursor. */ | |
456 | bt431_init_cursor(ip->bt431); | |
457 | aafb_cursor_init(ip); | |
458 | ||
459 | /* Clear the screen. */ | |
460 | memset ((void *)ip->fb_start, 0, ip->fb_size); | |
461 | ||
462 | if (register_framebuffer(&ip->info) < 0) | |
463 | return -EINVAL; | |
464 | ||
465 | printk(KERN_INFO "fb%d: %s frame buffer in TC slot %d\n", | |
466 | GET_FB_IDX(ip->info.node), ip->info.modename, slot); | |
467 | ||
468 | return 0; | |
469 | } | |
470 | ||
471 | static int __exit exit_one(int slot) | |
472 | { | |
473 | struct aafb_info *ip = &my_fb_info[slot]; | |
474 | ||
475 | if (unregister_framebuffer(&ip->info) < 0) | |
476 | return -EINVAL; | |
477 | ||
478 | return 0; | |
479 | } | |
480 | ||
481 | /* | |
482 | * Initialise the framebuffer. | |
483 | */ | |
484 | int __init pmagaafb_init(void) | |
485 | { | |
486 | int sid; | |
487 | int found = 0; | |
488 | ||
489 | while ((sid = search_tc_card("PMAG-AA")) >= 0) { | |
490 | found = 1; | |
491 | claim_tc_card(sid); | |
492 | init_one(sid); | |
493 | } | |
494 | ||
495 | return found ? 0 : -ENXIO; | |
496 | } | |
497 | ||
498 | static void __exit pmagaafb_exit(void) | |
499 | { | |
500 | int sid; | |
501 | ||
502 | while ((sid = search_tc_card("PMAG-AA")) >= 0) { | |
503 | exit_one(sid); | |
504 | release_tc_card(sid); | |
505 | } | |
506 | } | |
507 | ||
508 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
509 | MODULE_DESCRIPTION(DRIVER_DESCRIPTION); | |
510 | MODULE_LICENSE("GPL"); | |
511 | #ifdef MODULE | |
512 | module_init(pmagaafb_init); | |
513 | module_exit(pmagaafb_exit); | |
514 | #endif |