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