diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/video/sun3fb.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/video/sun3fb.c')
-rw-r--r-- | drivers/video/sun3fb.c | 704 |
1 files changed, 704 insertions, 0 deletions
diff --git a/drivers/video/sun3fb.c b/drivers/video/sun3fb.c new file mode 100644 index 000000000000..9b36b9df535f --- /dev/null +++ b/drivers/video/sun3fb.c | |||
@@ -0,0 +1,704 @@ | |||
1 | /* | ||
2 | * linux/drivers/video/sun3fb.c -- Frame buffer driver for Sun3 | ||
3 | * | ||
4 | * (C) 1998 Thomas Bogendoerfer | ||
5 | * | ||
6 | * This driver is bases on sbusfb.c, which is | ||
7 | * | ||
8 | * Copyright (C) 1998 Jakub Jelinek | ||
9 | * | ||
10 | * This driver is partly based on the Open Firmware console driver | ||
11 | * | ||
12 | * Copyright (C) 1997 Geert Uytterhoeven | ||
13 | * | ||
14 | * and SPARC console subsystem | ||
15 | * | ||
16 | * Copyright (C) 1995 Peter Zaitcev (zaitcev@yahoo.com) | ||
17 | * Copyright (C) 1995-1997 David S. Miller (davem@caip.rutgers.edu) | ||
18 | * Copyright (C) 1995-1996 Miguel de Icaza (miguel@nuclecu.unam.mx) | ||
19 | * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk) | ||
20 | * Copyright (C) 1996-1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | ||
21 | * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) | ||
22 | * | ||
23 | * This file is subject to the terms and conditions of the GNU General Public | ||
24 | * License. See the file COPYING in the main directory of this archive for | ||
25 | * more details. | ||
26 | */ | ||
27 | |||
28 | #include <linux/config.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/errno.h> | ||
32 | #include <linux/string.h> | ||
33 | #include <linux/mm.h> | ||
34 | #include <linux/tty.h> | ||
35 | #include <linux/slab.h> | ||
36 | #include <linux/vmalloc.h> | ||
37 | #include <linux/delay.h> | ||
38 | #include <linux/interrupt.h> | ||
39 | #include <linux/fb.h> | ||
40 | #include <linux/selection.h> | ||
41 | #include <linux/init.h> | ||
42 | #include <linux/console.h> | ||
43 | #include <linux/kd.h> | ||
44 | #include <linux/vt_kern.h> | ||
45 | |||
46 | #include <asm/uaccess.h> | ||
47 | #include <asm/pgtable.h> /* io_remap_page_range() */ | ||
48 | |||
49 | #ifdef CONFIG_SUN3 | ||
50 | #include <asm/oplib.h> | ||
51 | #include <asm/machines.h> | ||
52 | #include <asm/idprom.h> | ||
53 | |||
54 | #define CGFOUR_OBMEM_ADDR 0x1f300000 | ||
55 | #define BWTWO_OBMEM_ADDR 0x1f000000 | ||
56 | #define BWTWO_OBMEM50_ADDR 0x00100000 | ||
57 | |||
58 | #endif | ||
59 | #ifdef CONFIG_SUN3X | ||
60 | #include <asm/sun3x.h> | ||
61 | #endif | ||
62 | #include <video/sbusfb.h> | ||
63 | |||
64 | #define DEFAULT_CURSOR_BLINK_RATE (2*HZ/5) | ||
65 | |||
66 | #define CURSOR_SHAPE 1 | ||
67 | #define CURSOR_BLINK 2 | ||
68 | |||
69 | #define mymemset(x,y) memset(x,0,y) | ||
70 | |||
71 | /* | ||
72 | * Interface used by the world | ||
73 | */ | ||
74 | |||
75 | int sun3fb_init(void); | ||
76 | void sun3fb_setup(char *options); | ||
77 | |||
78 | static char fontname[40] __initdata = { 0 }; | ||
79 | static int curblink __initdata = 1; | ||
80 | |||
81 | static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con, | ||
82 | struct fb_info *info); | ||
83 | static int sun3fb_get_var(struct fb_var_screeninfo *var, int con, | ||
84 | struct fb_info *info); | ||
85 | static int sun3fb_set_var(struct fb_var_screeninfo *var, int con, | ||
86 | struct fb_info *info); | ||
87 | static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con, | ||
88 | struct fb_info *info); | ||
89 | static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con, | ||
90 | struct fb_info *info); | ||
91 | static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, | ||
92 | u_int transp, struct fb_info *info); | ||
93 | static int sun3fb_blank(int blank, struct fb_info *info); | ||
94 | static void sun3fb_cursor(struct display *p, int mode, int x, int y); | ||
95 | static void sun3fb_clear_margin(struct display *p, int s); | ||
96 | |||
97 | /* | ||
98 | * Interface to the low level console driver | ||
99 | */ | ||
100 | |||
101 | static int sun3fbcon_switch(int con, struct fb_info *info); | ||
102 | static int sun3fbcon_updatevar(int con, struct fb_info *info); | ||
103 | |||
104 | /* | ||
105 | * Internal routines | ||
106 | */ | ||
107 | |||
108 | static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue, | ||
109 | u_int *transp, struct fb_info *info); | ||
110 | |||
111 | static struct fb_ops sun3fb_ops = { | ||
112 | .owner = THIS_MODULE, | ||
113 | .fb_get_fix = sun3fb_get_fix, | ||
114 | .fb_get_var = sun3fb_get_var, | ||
115 | .fb_set_var = sun3fb_set_var, | ||
116 | .fb_get_cmap = sun3fb_get_cmap, | ||
117 | .fb_set_cmap = sun3fb_set_cmap, | ||
118 | .fb_setcolreg = sun3fb_setcolreg, | ||
119 | .fb_blank = sun3fb_blank, | ||
120 | }; | ||
121 | |||
122 | static void sun3fb_clear_margin(struct display *p, int s) | ||
123 | { | ||
124 | struct fb_info_sbusfb *fb = sbusfbinfod(p); | ||
125 | |||
126 | return; | ||
127 | |||
128 | if (fb->switch_from_graph) | ||
129 | (*fb->switch_from_graph)(fb); | ||
130 | if (fb->fill) { | ||
131 | unsigned short rects [16]; | ||
132 | |||
133 | rects [0] = 0; | ||
134 | rects [1] = 0; | ||
135 | rects [2] = fb->var.xres_virtual; | ||
136 | rects [3] = fb->y_margin; | ||
137 | rects [4] = 0; | ||
138 | rects [5] = fb->y_margin; | ||
139 | rects [6] = fb->x_margin; | ||
140 | rects [7] = fb->var.yres_virtual; | ||
141 | rects [8] = fb->var.xres_virtual - fb->x_margin; | ||
142 | rects [9] = fb->y_margin; | ||
143 | rects [10] = fb->var.xres_virtual; | ||
144 | rects [11] = fb->var.yres_virtual; | ||
145 | rects [12] = fb->x_margin; | ||
146 | rects [13] = fb->var.yres_virtual - fb->y_margin; | ||
147 | rects [14] = fb->var.xres_virtual - fb->x_margin; | ||
148 | rects [15] = fb->var.yres_virtual; | ||
149 | (*fb->fill)(fb, p, s, 4, rects); | ||
150 | } else { | ||
151 | unsigned char *fb_base = fb->info.screen_base, *q; | ||
152 | int skip_bytes = fb->y_margin * fb->var.xres_virtual; | ||
153 | int scr_size = fb->var.xres_virtual * fb->var.yres_virtual; | ||
154 | int h, he, incr, size; | ||
155 | |||
156 | he = fb->var.yres; | ||
157 | if (fb->var.bits_per_pixel == 1) { | ||
158 | fb_base -= (skip_bytes + fb->x_margin) / 8; | ||
159 | skip_bytes /= 8; | ||
160 | scr_size /= 8; | ||
161 | mymemset (fb_base, skip_bytes - fb->x_margin / 8); | ||
162 | mymemset (fb_base + scr_size - skip_bytes + fb->x_margin / 8, skip_bytes - fb->x_margin / 8); | ||
163 | incr = fb->var.xres_virtual / 8; | ||
164 | size = fb->x_margin / 8 * 2; | ||
165 | for (q = fb_base + skip_bytes - fb->x_margin / 8, h = 0; | ||
166 | h <= he; q += incr, h++) | ||
167 | mymemset (q, size); | ||
168 | } else { | ||
169 | fb_base -= (skip_bytes + fb->x_margin); | ||
170 | memset (fb_base, attr_bgcol(p,s), skip_bytes - fb->x_margin); | ||
171 | memset (fb_base + scr_size - skip_bytes + fb->x_margin, attr_bgcol(p,s), skip_bytes - fb->x_margin); | ||
172 | incr = fb->var.xres_virtual; | ||
173 | size = fb->x_margin * 2; | ||
174 | for (q = fb_base + skip_bytes - fb->x_margin, h = 0; | ||
175 | h <= he; q += incr, h++) | ||
176 | memset (q, attr_bgcol(p,s), size); | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | static void sun3fb_disp_setup(struct display *p) | ||
182 | { | ||
183 | struct fb_info_sbusfb *fb = sbusfbinfod(p); | ||
184 | |||
185 | if (fb->setup) | ||
186 | fb->setup(p); | ||
187 | sun3fb_clear_margin(p, 0); | ||
188 | } | ||
189 | |||
190 | /* | ||
191 | * Get the Fixed Part of the Display | ||
192 | */ | ||
193 | |||
194 | static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con, | ||
195 | struct fb_info *info) | ||
196 | { | ||
197 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
198 | |||
199 | memcpy(fix, &fb->fix, sizeof(struct fb_fix_screeninfo)); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | /* | ||
204 | * Get the User Defined Part of the Display | ||
205 | */ | ||
206 | |||
207 | static int sun3fb_get_var(struct fb_var_screeninfo *var, int con, | ||
208 | struct fb_info *info) | ||
209 | { | ||
210 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
211 | |||
212 | memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo)); | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | /* | ||
217 | * Set the User Defined Part of the Display | ||
218 | */ | ||
219 | |||
220 | static int sun3fb_set_var(struct fb_var_screeninfo *var, int con, | ||
221 | struct fb_info *info) | ||
222 | { | ||
223 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
224 | |||
225 | if (var->xres > fb->var.xres || var->yres > fb->var.yres || | ||
226 | var->xres_virtual > fb->var.xres_virtual || | ||
227 | var->yres_virtual > fb->var.yres_virtual || | ||
228 | var->bits_per_pixel != fb->var.bits_per_pixel || | ||
229 | var->nonstd || | ||
230 | (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED) | ||
231 | return -EINVAL; | ||
232 | memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo)); | ||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | /* | ||
237 | * Hardware cursor | ||
238 | */ | ||
239 | |||
240 | static unsigned char hw_cursor_cmap[2] = { 0, 0xff }; | ||
241 | |||
242 | static void | ||
243 | sun3fb_cursor_timer_handler(unsigned long dev_addr) | ||
244 | { | ||
245 | struct fb_info_sbusfb *fb = (struct fb_info_sbusfb *)dev_addr; | ||
246 | |||
247 | if (!fb->setcursor) return; | ||
248 | |||
249 | if (fb->cursor.mode & CURSOR_BLINK) { | ||
250 | fb->cursor.enable ^= 1; | ||
251 | fb->setcursor(fb); | ||
252 | } | ||
253 | |||
254 | fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate; | ||
255 | add_timer(&fb->cursor.timer); | ||
256 | } | ||
257 | |||
258 | static void sun3fb_cursor(struct display *p, int mode, int x, int y) | ||
259 | { | ||
260 | struct fb_info_sbusfb *fb = sbusfbinfod(p); | ||
261 | |||
262 | switch (mode) { | ||
263 | case CM_ERASE: | ||
264 | fb->cursor.mode &= ~CURSOR_BLINK; | ||
265 | fb->cursor.enable = 0; | ||
266 | (*fb->setcursor)(fb); | ||
267 | break; | ||
268 | |||
269 | case CM_MOVE: | ||
270 | case CM_DRAW: | ||
271 | if (fb->cursor.mode & CURSOR_SHAPE) { | ||
272 | fb->cursor.size.fbx = fontwidth(p); | ||
273 | fb->cursor.size.fby = fontheight(p); | ||
274 | fb->cursor.chot.fbx = 0; | ||
275 | fb->cursor.chot.fby = 0; | ||
276 | fb->cursor.enable = 1; | ||
277 | memset (fb->cursor.bits, 0, sizeof (fb->cursor.bits)); | ||
278 | fb->cursor.bits[0][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p))); | ||
279 | fb->cursor.bits[1][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p))); | ||
280 | fb->cursor.bits[0][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p))); | ||
281 | fb->cursor.bits[1][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p))); | ||
282 | (*fb->setcursormap) (fb, hw_cursor_cmap, hw_cursor_cmap, hw_cursor_cmap); | ||
283 | (*fb->setcurshape) (fb); | ||
284 | } | ||
285 | fb->cursor.mode = CURSOR_BLINK; | ||
286 | if (fontwidthlog(p)) | ||
287 | fb->cursor.cpos.fbx = (x << fontwidthlog(p)) + fb->x_margin; | ||
288 | else | ||
289 | fb->cursor.cpos.fbx = (x * fontwidth(p)) + fb->x_margin; | ||
290 | if (fontheightlog(p)) | ||
291 | fb->cursor.cpos.fby = (y << fontheightlog(p)) + fb->y_margin; | ||
292 | else | ||
293 | fb->cursor.cpos.fby = (y * fontheight(p)) + fb->y_margin; | ||
294 | (*fb->setcursor)(fb); | ||
295 | break; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * Get the Colormap | ||
301 | */ | ||
302 | |||
303 | static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con, | ||
304 | struct fb_info *info) | ||
305 | { | ||
306 | if (con == info->currcon) /* current console? */ | ||
307 | return fb_get_cmap(cmap, kspc, sun3fb_getcolreg, info); | ||
308 | else if (fb_display[con].cmap.len) /* non default colormap? */ | ||
309 | fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2); | ||
310 | else | ||
311 | fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), cmap, kspc ? 0 : 2); | ||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | /* | ||
316 | * Set the Colormap | ||
317 | */ | ||
318 | |||
319 | static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con, | ||
320 | struct fb_info *info) | ||
321 | { | ||
322 | int err; | ||
323 | |||
324 | if (!fb_display[con].cmap.len) { /* no colormap allocated? */ | ||
325 | if ((err = fb_alloc_cmap(&fb_display[con].cmap, 1<<fb_display[con].var.bits_per_pixel, 0))) | ||
326 | return err; | ||
327 | } | ||
328 | if (con == info->currcon) { /* current console? */ | ||
329 | err = fb_set_cmap(cmap, kspc, info); | ||
330 | if (!err) { | ||
331 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
332 | |||
333 | if (fb->loadcmap) | ||
334 | (*fb->loadcmap)(fb, &fb_display[con], cmap->start, cmap->len); | ||
335 | } | ||
336 | return err; | ||
337 | } else | ||
338 | fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1); | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | /* | ||
343 | * Setup: parse used options | ||
344 | */ | ||
345 | |||
346 | void __init sun3fb_setup(char *options) | ||
347 | { | ||
348 | char *p; | ||
349 | |||
350 | for (p = options;;) { | ||
351 | if (!strncmp(p, "font=", 5)) { | ||
352 | int i; | ||
353 | |||
354 | for (i = 0; i < sizeof(fontname) - 1; i++) | ||
355 | if (p[i+5] == ' ' || !p[i+5]) | ||
356 | break; | ||
357 | memcpy(fontname, p+5, i); | ||
358 | fontname[i] = 0; | ||
359 | } else if (!strncmp(p, "noblink", 7)) | ||
360 | curblink = 0; | ||
361 | while (*p && *p != ' ' && *p != ',') p++; | ||
362 | if (*p != ',') break; | ||
363 | p++; | ||
364 | } | ||
365 | |||
366 | return; | ||
367 | } | ||
368 | |||
369 | static int sun3fbcon_switch(int con, struct fb_info *info) | ||
370 | { | ||
371 | int x_margin, y_margin; | ||
372 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
373 | int lastconsole; | ||
374 | |||
375 | /* Do we have to save the colormap? */ | ||
376 | if (fb_display[info->currcon].cmap.len) | ||
377 | fb_get_cmap(&fb_display[info->currcon].cmap, 1, sun3fb_getcolreg, info); | ||
378 | |||
379 | if (info->display_fg) { | ||
380 | lastconsole = info->display_fg->vc_num; | ||
381 | if (lastconsole != con && | ||
382 | (fontwidth(&fb_display[lastconsole]) != fontwidth(&fb_display[con]) || | ||
383 | fontheight(&fb_display[lastconsole]) != fontheight(&fb_display[con]))) | ||
384 | fb->cursor.mode |= CURSOR_SHAPE; | ||
385 | } | ||
386 | x_margin = (fb_display[con].var.xres_virtual - fb_display[con].var.xres) / 2; | ||
387 | y_margin = (fb_display[con].var.yres_virtual - fb_display[con].var.yres) / 2; | ||
388 | if (fb->margins) | ||
389 | fb->margins(fb, &fb_display[con], x_margin, y_margin); | ||
390 | if (fb->graphmode || fb->x_margin != x_margin || fb->y_margin != y_margin) { | ||
391 | fb->x_margin = x_margin; fb->y_margin = y_margin; | ||
392 | sun3fb_clear_margin(&fb_display[con], 0); | ||
393 | } | ||
394 | info->currcon = con; | ||
395 | /* Install new colormap */ | ||
396 | do_install_cmap(con, info); | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * Update the `var' structure (called by fbcon.c) | ||
402 | */ | ||
403 | |||
404 | static int sun3fbcon_updatevar(int con, struct fb_info *info) | ||
405 | { | ||
406 | /* Nothing */ | ||
407 | return 0; | ||
408 | } | ||
409 | |||
410 | /* | ||
411 | * Blank the display. | ||
412 | */ | ||
413 | |||
414 | static int sun3fb_blank(int blank, struct fb_info *info) | ||
415 | { | ||
416 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
417 | |||
418 | if (blank && fb->blank) | ||
419 | return fb->blank(fb); | ||
420 | else if (!blank && fb->unblank) | ||
421 | return fb->unblank(fb); | ||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * Read a single color register and split it into | ||
427 | * colors/transparent. Return != 0 for invalid regno. | ||
428 | */ | ||
429 | |||
430 | static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue, | ||
431 | u_int *transp, struct fb_info *info) | ||
432 | { | ||
433 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
434 | |||
435 | if (!fb->color_map || regno > 255) | ||
436 | return 1; | ||
437 | *red = (fb->color_map CM(regno, 0)<<8) | fb->color_map CM(regno, 0); | ||
438 | *green = (fb->color_map CM(regno, 1)<<8) | fb->color_map CM(regno, 1); | ||
439 | *blue = (fb->color_map CM(regno, 2)<<8) | fb->color_map CM(regno, 2); | ||
440 | *transp = 0; | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | |||
445 | /* | ||
446 | * Set a single color register. The values supplied are already | ||
447 | * rounded down to the hardware's capabilities (according to the | ||
448 | * entries in the var structure). Return != 0 for invalid regno. | ||
449 | */ | ||
450 | |||
451 | static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, | ||
452 | u_int transp, struct fb_info *info) | ||
453 | { | ||
454 | struct fb_info_sbusfb *fb = sbusfbinfo(info); | ||
455 | |||
456 | if (!fb->color_map || regno > 255) | ||
457 | return 1; | ||
458 | red >>= 8; | ||
459 | green >>= 8; | ||
460 | blue >>= 8; | ||
461 | fb->color_map CM(regno, 0) = red; | ||
462 | fb->color_map CM(regno, 1) = green; | ||
463 | fb->color_map CM(regno, 2) = blue; | ||
464 | return 0; | ||
465 | } | ||
466 | |||
467 | static int sun3fb_set_font(struct display *p, int width, int height) | ||
468 | { | ||
469 | int w = p->var.xres_virtual, h = p->var.yres_virtual; | ||
470 | int depth = p->var.bits_per_pixel; | ||
471 | struct fb_info_sbusfb *fb = sbusfbinfod(p); | ||
472 | int x_margin, y_margin; | ||
473 | |||
474 | if (depth > 8) depth = 8; | ||
475 | x_margin = (w % width) / 2; | ||
476 | y_margin = (h % height) / 2; | ||
477 | |||
478 | p->var.xres = w - 2*x_margin; | ||
479 | p->var.yres = h - 2*y_margin; | ||
480 | |||
481 | fb->cursor.mode |= CURSOR_SHAPE; | ||
482 | |||
483 | if (fb->margins) | ||
484 | fb->margins(fb, p, x_margin, y_margin); | ||
485 | if (fb->x_margin != x_margin || fb->y_margin != y_margin) { | ||
486 | fb->x_margin = x_margin; fb->y_margin = y_margin; | ||
487 | sun3fb_clear_margin(p, 0); | ||
488 | } | ||
489 | |||
490 | return 1; | ||
491 | } | ||
492 | |||
493 | void sun3fb_palette(int enter) | ||
494 | { | ||
495 | int i; | ||
496 | struct display *p; | ||
497 | |||
498 | for (i = 0; i < MAX_NR_CONSOLES; i++) { | ||
499 | p = &fb_display[i]; | ||
500 | if (p->dispsw && p->dispsw->setup == sun3fb_disp_setup && | ||
501 | p->fb_info->display_fg && | ||
502 | p->fb_info->display_fg->vc_num == i) { | ||
503 | struct fb_info_sbusfb *fb = sbusfbinfod(p); | ||
504 | |||
505 | if (fb->restore_palette) { | ||
506 | if (enter) | ||
507 | fb->restore_palette(fb); | ||
508 | else if (vc_cons[i].d->vc_mode != KD_GRAPHICS) | ||
509 | vc_cons[i].d->vc_sw->con_set_palette(vc_cons[i].d, color_table); | ||
510 | } | ||
511 | } | ||
512 | } | ||
513 | } | ||
514 | |||
515 | /* | ||
516 | * Initialisation | ||
517 | */ | ||
518 | static int __init sun3fb_init_fb(int fbtype, unsigned long addr) | ||
519 | { | ||
520 | static struct sbus_dev sdb; | ||
521 | struct fb_fix_screeninfo *fix; | ||
522 | struct fb_var_screeninfo *var; | ||
523 | struct display *disp; | ||
524 | struct fb_info_sbusfb *fb; | ||
525 | struct fbtype *type; | ||
526 | int linebytes, w, h, depth; | ||
527 | char *p = NULL; | ||
528 | |||
529 | fb = kmalloc(sizeof(struct fb_info_sbusfb), GFP_ATOMIC); | ||
530 | if (!fb) | ||
531 | return -ENOMEM; | ||
532 | |||
533 | memset(fb, 0, sizeof(struct fb_info_sbusfb)); | ||
534 | fix = &fb->fix; | ||
535 | var = &fb->var; | ||
536 | disp = &fb->disp; | ||
537 | type = &fb->type; | ||
538 | |||
539 | sdb.reg_addrs[0].phys_addr = addr; | ||
540 | fb->sbdp = &sdb; | ||
541 | |||
542 | type->fb_type = fbtype; | ||
543 | |||
544 | type->fb_height = h = 900; | ||
545 | type->fb_width = w = 1152; | ||
546 | sizechange: | ||
547 | type->fb_depth = depth = (fbtype == FBTYPE_SUN2BW) ? 1 : 8; | ||
548 | linebytes = w * depth / 8; | ||
549 | type->fb_size = PAGE_ALIGN((linebytes) * h); | ||
550 | /* | ||
551 | fb->x_margin = (w & 7) / 2; | ||
552 | fb->y_margin = (h & 15) / 2; | ||
553 | */ | ||
554 | fb->x_margin = fb->y_margin = 0; | ||
555 | |||
556 | var->xres_virtual = w; | ||
557 | var->yres_virtual = h; | ||
558 | var->xres = w - 2*fb->x_margin; | ||
559 | var->yres = h - 2*fb->y_margin; | ||
560 | |||
561 | var->bits_per_pixel = depth; | ||
562 | var->height = var->width = -1; | ||
563 | var->pixclock = 10000; | ||
564 | var->vmode = FB_VMODE_NONINTERLACED; | ||
565 | var->red.length = var->green.length = var->blue.length = 8; | ||
566 | |||
567 | fix->line_length = linebytes; | ||
568 | fix->smem_len = type->fb_size; | ||
569 | fix->type = FB_TYPE_PACKED_PIXELS; | ||
570 | fix->visual = FB_VISUAL_PSEUDOCOLOR; | ||
571 | |||
572 | fb->info.fbops = &sun3fb_ops; | ||
573 | fb->info.disp = disp; | ||
574 | fb->info.currcon = -1; | ||
575 | strcpy(fb->info.fontname, fontname); | ||
576 | fb->info.changevar = NULL; | ||
577 | fb->info.switch_con = &sun3fbcon_switch; | ||
578 | fb->info.updatevar = &sun3fbcon_updatevar; | ||
579 | fb->info.flags = FBINFO_FLAG_DEFAULT; | ||
580 | |||
581 | fb->cursor.hwsize.fbx = 32; | ||
582 | fb->cursor.hwsize.fby = 32; | ||
583 | |||
584 | if (depth > 1 && !fb->color_map) { | ||
585 | if((fb->color_map = kmalloc(256 * 3, GFP_ATOMIC))==NULL) | ||
586 | return -ENOMEM; | ||
587 | } | ||
588 | |||
589 | switch(fbtype) { | ||
590 | #ifdef CONFIG_FB_CGSIX | ||
591 | case FBTYPE_SUNFAST_COLOR: | ||
592 | p = cgsixfb_init(fb); break; | ||
593 | #endif | ||
594 | #ifdef CONFIG_FB_BWTWO | ||
595 | case FBTYPE_SUN2BW: | ||
596 | p = bwtwofb_init(fb); break; | ||
597 | #endif | ||
598 | #ifdef CONFIG_FB_CGTHREE | ||
599 | case FBTYPE_SUN4COLOR: | ||
600 | case FBTYPE_SUN3COLOR: | ||
601 | type->fb_size = 0x100000; | ||
602 | p = cgthreefb_init(fb); break; | ||
603 | #endif | ||
604 | } | ||
605 | fix->smem_start = (unsigned long)fb->info.screen_base; // FIXME | ||
606 | |||
607 | if (!p) { | ||
608 | kfree(fb); | ||
609 | return -ENODEV; | ||
610 | } | ||
611 | |||
612 | if (p == SBUSFBINIT_SIZECHANGE) | ||
613 | goto sizechange; | ||
614 | |||
615 | disp->dispsw = &fb->dispsw; | ||
616 | if (fb->setcursor) { | ||
617 | fb->dispsw.cursor = sun3fb_cursor; | ||
618 | if (curblink) { | ||
619 | fb->cursor.blink_rate = DEFAULT_CURSOR_BLINK_RATE; | ||
620 | init_timer(&fb->cursor.timer); | ||
621 | fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate; | ||
622 | fb->cursor.timer.data = (unsigned long)fb; | ||
623 | fb->cursor.timer.function = sun3fb_cursor_timer_handler; | ||
624 | add_timer(&fb->cursor.timer); | ||
625 | } | ||
626 | } | ||
627 | fb->cursor.mode = CURSOR_SHAPE; | ||
628 | fb->dispsw.set_font = sun3fb_set_font; | ||
629 | fb->setup = fb->dispsw.setup; | ||
630 | fb->dispsw.setup = sun3fb_disp_setup; | ||
631 | fb->dispsw.clear_margins = NULL; | ||
632 | |||
633 | disp->var = *var; | ||
634 | disp->visual = fix->visual; | ||
635 | disp->type = fix->type; | ||
636 | disp->type_aux = fix->type_aux; | ||
637 | disp->line_length = fix->line_length; | ||
638 | |||
639 | if (fb->blank) | ||
640 | disp->can_soft_blank = 1; | ||
641 | |||
642 | sun3fb_set_var(var, -1, &fb->info); | ||
643 | |||
644 | if (register_framebuffer(&fb->info) < 0) { | ||
645 | kfree(fb); | ||
646 | return -EINVAL; | ||
647 | } | ||
648 | printk("fb%d: %s\n", fb->info.node, p); | ||
649 | |||
650 | return 0; | ||
651 | } | ||
652 | |||
653 | |||
654 | int __init sun3fb_init(void) | ||
655 | { | ||
656 | extern int con_is_present(void); | ||
657 | unsigned long addr; | ||
658 | char p4id; | ||
659 | |||
660 | if (!con_is_present()) return -ENODEV; | ||
661 | #ifdef CONFIG_SUN3 | ||
662 | switch(*(romvec->pv_fbtype)) | ||
663 | { | ||
664 | case FBTYPE_SUN2BW: | ||
665 | addr = 0xfe20000; | ||
666 | return sun3fb_init_fb(FBTYPE_SUN2BW, addr); | ||
667 | case FBTYPE_SUN3COLOR: | ||
668 | case FBTYPE_SUN4COLOR: | ||
669 | if(idprom->id_machtype != (SM_SUN3|SM_3_60)) { | ||
670 | printk("sun3fb: cgthree/four only supported on 3/60\n"); | ||
671 | return -ENODEV; | ||
672 | } | ||
673 | |||
674 | addr = CGFOUR_OBMEM_ADDR; | ||
675 | return sun3fb_init_fb(*(romvec->pv_fbtype), addr); | ||
676 | default: | ||
677 | printk("sun3fb: unsupported framebuffer\n"); | ||
678 | return -ENODEV; | ||
679 | } | ||
680 | #else | ||
681 | addr = SUN3X_VIDEO_BASE; | ||
682 | p4id = *(char *)SUN3X_VIDEO_P4ID; | ||
683 | |||
684 | p4id = (p4id == 0x45) ? p4id : (p4id & 0xf0); | ||
685 | switch (p4id) { | ||
686 | case 0x00: | ||
687 | return sun3fb_init_fb(FBTYPE_SUN2BW, addr); | ||
688 | #if 0 /* not yet */ | ||
689 | case 0x40: | ||
690 | return sun3fb_init_fb(FBTYPE_SUN4COLOR, addr); | ||
691 | break; | ||
692 | case 0x45: | ||
693 | return sun3fb_init_fb(FBTYPE_SUN8COLOR, addr); | ||
694 | break; | ||
695 | #endif | ||
696 | case 0x60: | ||
697 | return sun3fb_init_fb(FBTYPE_SUNFAST_COLOR, addr); | ||
698 | } | ||
699 | #endif | ||
700 | |||
701 | return -ENODEV; | ||
702 | } | ||
703 | |||
704 | MODULE_LICENSE("GPL"); | ||