2 * linux/drivers/video/sbusfb.c -- SBUS or UPA based frame buffer device
4 * Copyright (C) 1998 Jakub Jelinek
6 * This driver is partly based on the Open Firmware console driver
8 * Copyright (C) 1997 Geert Uytterhoeven
10 * and SPARC console subsystem
12 * Copyright (C) 1995 Peter Zaitcev (zaitcev@yahoo.com)
13 * Copyright (C) 1995-1997 David S. Miller (davem@caip.rutgers.edu)
14 * Copyright (C) 1995-1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
15 * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
16 * Copyright (C) 1996-1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
17 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
19 * This file is subject to the terms and conditions of the GNU General Public
20 * License. See the file COPYING in the main directory of this archive for
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/string.h>
30 #include <linux/tty.h>
31 #include <linux/slab.h>
32 #include <linux/vmalloc.h>
33 #include <linux/delay.h>
34 #include <linux/interrupt.h>
36 #include <linux/selection.h>
37 #include <linux/init.h>
38 #include <linux/console.h>
40 #include <linux/vt_kern.h>
42 #include <asm/uaccess.h>
43 #include <asm/pgtable.h> /* io_remap_page_range() */
45 #include <video/sbusfb.h>
47 #define DEFAULT_CURSOR_BLINK_RATE (2*HZ/5)
49 #define CURSOR_SHAPE 1
50 #define CURSOR_BLINK 2
53 * Interface used by the world
56 int sbusfb_init(void);
57 int sbusfb_setup(char*);
60 static int defx_margin = -1, defy_margin = -1;
61 static char fontname[40] __initdata = { 0 };
62 static int curblink __initdata = 1;
66 int x_margin, y_margin;
68 { 8, 1280, 1024, 64, 80 },
69 { 8, 1152, 1024, 64, 80 },
70 { 8, 1152, 900, 64, 18 },
71 { 8, 1024, 768, 0, 0 },
72 { 8, 800, 600, 16, 12 },
73 { 8, 640, 480, 0, 0 },
74 { 1, 1152, 900, 8, 18 },
78 static int sbusfb_open(struct fb_info *info, int user);
79 static int sbusfb_release(struct fb_info *info, int user);
80 static int sbusfb_mmap(struct fb_info *info, struct file *file,
81 struct vm_area_struct *vma);
82 static int sbusfb_get_fix(struct fb_fix_screeninfo *fix, int con,
83 struct fb_info *info);
84 static int sbusfb_get_var(struct fb_var_screeninfo *var, int con,
85 struct fb_info *info);
86 static int sbusfb_set_var(struct fb_var_screeninfo *var, int con,
87 struct fb_info *info);
88 static int sbusfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
89 struct fb_info *info);
90 static int sbusfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
91 struct fb_info *info);
92 static int sbusfb_ioctl(struct inode *inode, struct file *file, u_int cmd,
93 u_long arg, int con, struct fb_info *info);
94 static void sbusfb_cursor(struct display *p, int mode, int x, int y);
95 static void sbusfb_clear_margin(struct display *p, int s);
99 * Interface to the low level console driver
102 static int sbusfbcon_switch(int con, struct fb_info *info);
103 static int sbusfbcon_updatevar(int con, struct fb_info *info);
104 static void sbusfbcon_blank(int blank, struct fb_info *info);
111 static int sbusfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
112 u_int *transp, struct fb_info *info);
113 static int sbusfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
114 u_int transp, struct fb_info *info);
115 static void do_install_cmap(int con, struct fb_info *info);
117 static struct fb_ops sbusfb_ops = {
119 fb_open: sbusfb_open,
120 fb_release: sbusfb_release,
121 fb_get_fix: sbusfb_get_fix,
122 fb_get_var: sbusfb_get_var,
123 fb_set_var: sbusfb_set_var,
124 fb_get_cmap: sbusfb_get_cmap,
125 fb_set_cmap: sbusfb_set_cmap,
126 fb_ioctl: sbusfb_ioctl,
127 fb_mmap: sbusfb_mmap,
131 * Open/Release the frame buffer device
134 static int sbusfb_open(struct fb_info *info, int user)
136 struct fb_info_sbusfb *fb = sbusfbinfo(info);
149 static int sbusfb_release(struct fb_info *info, int user)
151 struct fb_info_sbusfb *fb = sbusfbinfo(info);
156 if (fb->vtconsole != -1) {
157 vt_cons[fb->vtconsole]->vc_mode = KD_TEXT;
160 sbusfb_clear_margin(&fb_display[fb->vtconsole], 0);
171 static unsigned long sbusfb_mmapsize(struct fb_info_sbusfb *fb, long size)
173 if (size == SBUS_MMAP_EMPTY) return 0;
174 if (size >= 0) return size;
175 return fb->type.fb_size * (-size);
178 static int sbusfb_mmap(struct fb_info *info, struct file *file,
179 struct vm_area_struct *vma)
181 struct fb_info_sbusfb *fb = sbusfbinfo(info);
182 unsigned int size, page, r, map_size;
183 unsigned long map_offset = 0;
187 size = vma->vm_end - vma->vm_start;
188 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
191 off = vma->vm_pgoff << PAGE_SHIFT;
193 /* To stop the swapper from even considering these pages */
194 vma->vm_flags |= (VM_SHM| VM_LOCKED);
197 /* Each page, see which map applies */
198 for (page = 0; page < size; ){
200 for (i = 0; fb->mmap_map[i].size; i++)
201 if (fb->mmap_map[i].voff == off+page) {
202 map_size = sbusfb_mmapsize(fb,fb->mmap_map[i].size);
204 #define POFF_MASK (PAGE_MASK|0x1UL)
206 #define POFF_MASK (PAGE_MASK)
208 map_offset = (fb->physbase + fb->mmap_map[i].poff) & POFF_MASK;
215 if (page + map_size > size)
216 map_size = size - page;
217 r = io_remap_page_range (vma->vm_start+page, map_offset, map_size, vma->vm_page_prot, fb->iospace);
223 vma->vm_flags |= VM_IO;
227 if (info->display_fg)
228 lastconsole = info->display_fg->vc_num;
230 if (fb->consolecnt && fb_display[lastconsole].fb_info == info) {
231 fb->vtconsole = lastconsole;
233 vt_cons [lastconsole]->vc_mode = KD_GRAPHICS;
234 vc_cons[lastconsole].d->vc_sw->con_cursor(vc_cons[lastconsole].d,CM_ERASE);
235 } else if (fb->unblank && !fb->blanked)
241 static void sbusfb_clear_margin(struct display *p, int s)
243 struct fb_info_sbusfb *fb = sbusfbinfod(p);
245 if (fb->switch_from_graph)
246 (*fb->switch_from_graph)(fb);
248 unsigned short rects [16];
252 rects [2] = fb->var.xres_virtual;
253 rects [3] = fb->y_margin;
255 rects [5] = fb->y_margin;
256 rects [6] = fb->x_margin;
257 rects [7] = fb->var.yres_virtual;
258 rects [8] = fb->var.xres_virtual - fb->x_margin;
259 rects [9] = fb->y_margin;
260 rects [10] = fb->var.xres_virtual;
261 rects [11] = fb->var.yres_virtual;
262 rects [12] = fb->x_margin;
263 rects [13] = fb->var.yres_virtual - fb->y_margin;
264 rects [14] = fb->var.xres_virtual - fb->x_margin;
265 rects [15] = fb->var.yres_virtual;
266 (*fb->fill)(fb, p, s, 4, rects);
268 unsigned char *fb_base = p->screen_base, *q;
269 int skip_bytes = fb->y_margin * fb->var.xres_virtual;
270 int scr_size = fb->var.xres_virtual * fb->var.yres_virtual;
271 int h, he, incr, size;
274 if (fb->var.bits_per_pixel == 1) {
275 fb_base -= (skip_bytes + fb->x_margin) / 8;
278 fb_memset255 (fb_base, skip_bytes - fb->x_margin / 8);
279 fb_memset255 (fb_base + scr_size - skip_bytes + fb->x_margin / 8, skip_bytes - fb->x_margin / 8);
280 incr = fb->var.xres_virtual / 8;
281 size = fb->x_margin / 8 * 2;
282 for (q = fb_base + skip_bytes - fb->x_margin / 8, h = 0;
283 h <= he; q += incr, h++)
284 fb_memset255 (q, size);
286 fb_base -= (skip_bytes + fb->x_margin);
287 memset (fb_base, attr_bgcol(p,s), skip_bytes - fb->x_margin);
288 memset (fb_base + scr_size - skip_bytes + fb->x_margin, attr_bgcol(p,s), skip_bytes - fb->x_margin);
289 incr = fb->var.xres_virtual;
290 size = fb->x_margin * 2;
291 for (q = fb_base + skip_bytes - fb->x_margin, h = 0;
292 h <= he; q += incr, h++)
293 memset (q, attr_bgcol(p,s), size);
298 static void sbusfb_disp_setup(struct display *p)
300 struct fb_info_sbusfb *fb = sbusfbinfod(p);
304 sbusfb_clear_margin(p, 0);
308 * Get the Fixed Part of the Display
311 static int sbusfb_get_fix(struct fb_fix_screeninfo *fix, int con,
312 struct fb_info *info)
314 struct fb_info_sbusfb *fb = sbusfbinfo(info);
316 memcpy(fix, &fb->fix, sizeof(struct fb_fix_screeninfo));
321 * Get the User Defined Part of the Display
324 static int sbusfb_get_var(struct fb_var_screeninfo *var, int con,
325 struct fb_info *info)
327 struct fb_info_sbusfb *fb = sbusfbinfo(info);
329 memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo));
334 * Set the User Defined Part of the Display
337 static int sbusfb_set_var(struct fb_var_screeninfo *var, int con,
338 struct fb_info *info)
340 struct display *display;
341 int activate = var->activate;
344 display = &fb_display[con];
346 display = info->disp;
348 /* simple check for equality until fully implemented -E */
349 if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
350 if (display->var.xres != var->xres ||
351 display->var.yres != var->yres ||
352 display->var.xres_virtual != var->xres_virtual ||
353 display->var.yres_virtual != var->yres_virtual ||
354 display->var.bits_per_pixel != var->bits_per_pixel ||
355 display->var.accel_flags != var->accel_flags) {
367 static int sbus_hw_scursor (struct fbcursor *cursor, struct fb_info_sbusfb *fb)
372 char red[2], green[2], blue[2];
374 if (copy_from_user (&f, cursor, sizeof(struct fbcursor)))
377 if (op & FB_CUR_SETSHAPE){
378 if ((u32) f.size.fbx > fb->cursor.hwsize.fbx)
380 if ((u32) f.size.fby > fb->cursor.hwsize.fby)
383 bytes = f.size.fby << 3;
385 bytes = f.size.fby << 2;
387 if (op & FB_CUR_SETCMAP){
388 if (f.cmap.index || f.cmap.count != 2)
390 if (copy_from_user (red, f.cmap.red, 2) ||
391 copy_from_user (green, f.cmap.green, 2) ||
392 copy_from_user (blue, f.cmap.blue, 2))
395 if (op & FB_CUR_SETCMAP)
396 (*fb->setcursormap) (fb, red, green, blue);
397 if (op & FB_CUR_SETSHAPE){
400 fb->cursor.size = f.size;
401 memset ((void *)&fb->cursor.bits, 0, sizeof (fb->cursor.bits));
402 if (copy_from_user (fb->cursor.bits [0], f.mask, bytes) ||
403 copy_from_user (fb->cursor.bits [1], f.image, bytes))
405 if (f.size.fbx <= 32) {
406 u = 0xffffffff << (32 - f.size.fbx);
407 for (i = fb->cursor.size.fby - 1; i >= 0; i--) {
408 fb->cursor.bits [0][i] &= u;
409 fb->cursor.bits [1][i] &= fb->cursor.bits [0][i];
412 u = 0xffffffff << (64 - f.size.fbx);
413 for (i = fb->cursor.size.fby - 1; i >= 0; i--) {
414 fb->cursor.bits [0][2*i+1] &= u;
415 fb->cursor.bits [1][2*i] &= fb->cursor.bits [0][2*i];
416 fb->cursor.bits [1][2*i+1] &= fb->cursor.bits [0][2*i+1];
419 (*fb->setcurshape) (fb);
421 if (op & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)){
422 if (op & FB_CUR_SETCUR)
423 fb->cursor.enable = f.enable;
424 if (op & FB_CUR_SETPOS)
425 fb->cursor.cpos = f.pos;
426 if (op & FB_CUR_SETHOT)
427 fb->cursor.chot = f.hot;
428 (*fb->setcursor) (fb);
433 static unsigned char hw_cursor_cmap[2] = { 0, 0xff };
436 sbusfb_cursor_timer_handler(unsigned long dev_addr)
438 struct fb_info_sbusfb *fb = (struct fb_info_sbusfb *)dev_addr;
440 if (!fb->setcursor) return;
442 if (fb->cursor.mode & CURSOR_BLINK) {
443 fb->cursor.enable ^= 1;
447 fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
448 add_timer(&fb->cursor.timer);
451 static void sbusfb_cursor(struct display *p, int mode, int x, int y)
453 struct fb_info_sbusfb *fb = sbusfbinfod(p);
457 fb->cursor.mode &= ~CURSOR_BLINK;
458 fb->cursor.enable = 0;
459 (*fb->setcursor)(fb);
464 if (fb->cursor.mode & CURSOR_SHAPE) {
465 fb->cursor.size.fbx = fontwidth(p);
466 fb->cursor.size.fby = fontheight(p);
467 fb->cursor.chot.fbx = 0;
468 fb->cursor.chot.fby = 0;
469 fb->cursor.enable = 1;
470 memset (fb->cursor.bits, 0, sizeof (fb->cursor.bits));
471 fb->cursor.bits[0][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
472 fb->cursor.bits[1][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
473 fb->cursor.bits[0][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
474 fb->cursor.bits[1][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
475 (*fb->setcursormap) (fb, hw_cursor_cmap, hw_cursor_cmap, hw_cursor_cmap);
476 (*fb->setcurshape) (fb);
478 fb->cursor.mode = CURSOR_BLINK;
480 fb->cursor.cpos.fbx = (x << fontwidthlog(p)) + fb->x_margin;
482 fb->cursor.cpos.fbx = (x * fontwidth(p)) + fb->x_margin;
483 if (fontheightlog(p))
484 fb->cursor.cpos.fby = (y << fontheightlog(p)) + fb->y_margin;
486 fb->cursor.cpos.fby = (y * fontheight(p)) + fb->y_margin;
487 (*fb->setcursor)(fb);
496 static int sbusfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
497 struct fb_info *info)
499 if (!info->display_fg || con == info->display_fg->vc_num) /* current console? */
500 return fb_get_cmap(cmap, kspc, sbusfb_getcolreg, info);
501 else if (fb_display[con].cmap.len) /* non default colormap? */
502 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
504 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), cmap, kspc ? 0 : 2);
512 static int sbusfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
513 struct fb_info *info)
516 struct display *disp;
519 disp = &fb_display[con];
522 if (!disp->cmap.len) { /* no colormap allocated? */
523 if ((err = fb_alloc_cmap(&disp->cmap, 1<<disp->var.bits_per_pixel, 0)))
526 if (con == currcon) { /* current console? */
527 err = fb_set_cmap(cmap, kspc, sbusfb_setcolreg, info);
529 struct fb_info_sbusfb *fb = sbusfbinfo(info);
532 (*fb->loadcmap)(fb, &fb_display[con], cmap->start, cmap->len);
536 fb_copy_cmap(cmap, &disp->cmap, kspc ? 0 : 1);
540 static int sbusfb_ioctl(struct inode *inode, struct file *file, u_int cmd,
541 u_long arg, int con, struct fb_info *info)
543 struct fb_info_sbusfb *fb = sbusfbinfo(info);
548 case FBIOGTYPE: /* return frame buffer type */
549 if (copy_to_user((struct fbtype *)arg, &fb->type, sizeof(struct fbtype)))
553 struct fbgattr *fba = (struct fbgattr *) arg;
555 i = verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct fbgattr));
557 if (__put_user(fb->emulations[0], &fba->real_type) ||
558 __put_user(0, &fba->owner) ||
559 __copy_to_user(&fba->fbtype, &fb->type,
560 sizeof(struct fbtype)) ||
561 __put_user(0, &fba->sattr.flags) ||
562 __put_user(fb->type.fb_type, &fba->sattr.emu_type) ||
563 __put_user(-1, &fba->sattr.dev_specific[0]))
565 for (i = 0; i < 4; i++) {
566 if (put_user(fb->emulations[i], &fba->emu_types[i]))
572 i = verify_area (VERIFY_READ, (void *) arg, sizeof (struct fbsattr));
576 if (fb->consolecnt) {
577 lastconsole = info->display_fg->vc_num;
578 if (vt_cons[lastconsole]->vc_mode == KD_TEXT)
581 if (get_user(i, (int *)arg))
584 if (!fb->blanked || !fb->unblank)
586 if (fb->consolecnt || (fb->open && fb->mmaped))
590 if (fb->blanked || !fb->blank)
597 if (put_user(fb->blanked, (int *) arg))
600 case FBIOGETCMAP_SPARC: {
602 int end, count, index;
607 i = verify_area (VERIFY_READ, (void *) arg, sizeof (struct fbcmap));
609 cmap = (struct fbcmap *) arg;
610 if (__get_user(count, &cmap->count) ||
611 __get_user(index, &cmap->index))
613 if ((index < 0) || (index > 255))
615 if (index + count > 256)
617 if (__get_user(rp, &cmap->red) ||
618 __get_user(gp, &cmap->green) ||
619 __get_user(bp, &cmap->blue))
621 if (verify_area (VERIFY_WRITE, rp, count))
623 if (verify_area (VERIFY_WRITE, gp, count))
625 if (verify_area (VERIFY_WRITE, bp, count))
628 for (i = index; i < end; i++){
629 if (__put_user(fb->color_map CM(i,0), rp) ||
630 __put_user(fb->color_map CM(i,1), gp) ||
631 __put_user(fb->color_map CM(i,2), bp))
635 (*fb->loadcmap)(fb, NULL, index, count);
638 case FBIOPUTCMAP_SPARC: { /* load color map entries */
640 int end, count, index;
643 if (!fb->loadcmap || !fb->color_map)
645 i = verify_area (VERIFY_READ, (void *) arg, sizeof (struct fbcmap));
647 cmap = (struct fbcmap *) arg;
648 if (__get_user(count, &cmap->count) ||
649 __get_user(index, &cmap->index))
651 if ((index < 0) || (index > 255))
653 if (index + count > 256)
655 if (__get_user(rp, &cmap->red) ||
656 __get_user(gp, &cmap->green) ||
657 __get_user(bp, &cmap->blue))
659 if (verify_area (VERIFY_READ, rp, count))
661 if (verify_area (VERIFY_READ, gp, count))
663 if (verify_area (VERIFY_READ, bp, count))
667 for (i = index; i < end; i++){
668 if (__get_user(fb->color_map CM(i,0), rp))
670 if (__get_user(fb->color_map CM(i,1), gp))
672 if (__get_user(fb->color_map CM(i,2), bp))
676 (*fb->loadcmap)(fb, NULL, index, count);
680 struct fbcurpos *p = (struct fbcurpos *) arg;
681 if (!fb->setcursor) return -EINVAL;
682 if(verify_area (VERIFY_WRITE, p, sizeof (struct fbcurpos)))
684 if (__put_user(fb->cursor.hwsize.fbx, &p->fbx) ||
685 __put_user(fb->cursor.hwsize.fby, &p->fby))
690 if (!fb->setcursor) return -EINVAL;
691 if (fb->consolecnt) {
692 lastconsole = info->display_fg->vc_num;
693 if (vt_cons[lastconsole]->vc_mode == KD_TEXT)
694 return -EINVAL; /* Don't let graphics programs hide our nice text cursor */
695 fb->cursor.mode = CURSOR_SHAPE; /* Forget state of our text cursor */
697 return sbus_hw_scursor ((struct fbcursor *) arg, fb);
700 if (!fb->setcursor) return -EINVAL;
701 /* Don't let graphics programs move our nice text cursor */
702 if (fb->consolecnt) {
703 lastconsole = info->display_fg->vc_num;
704 if (vt_cons[lastconsole]->vc_mode == KD_TEXT)
705 return -EINVAL; /* Don't let graphics programs move our nice text cursor */
707 if (copy_from_user(&fb->cursor.cpos, (void *)arg, sizeof(struct fbcurpos)))
709 (*fb->setcursor) (fb);
713 return fb->ioctl(fb, cmd, arg);
720 * Setup: parse used options
723 int __init sbusfb_setup(char *options)
727 for (p = options;;) {
728 if (!strncmp(p, "nomargins", 9)) {
729 defx_margin = 0; defy_margin = 0;
730 } else if (!strncmp(p, "margins=", 8)) {
734 i = simple_strtoul(p+8,&q,10);
735 if (i >= 0 && *q == 'x') {
736 j = simple_strtoul(q+1,&q,10);
737 if (j >= 0 && (*q == ' ' || !*q)) {
738 defx_margin = i; defy_margin = j;
741 } else if (!strncmp(p, "font=", 5)) {
744 for (i = 0; i < sizeof(fontname) - 1; i++)
745 if (p[i+5] == ' ' || !p[i+5])
747 memcpy(fontname, p+5, i);
749 } else if (!strncmp(p, "noblink", 7))
751 while (*p && *p != ' ' && *p != ',') p++;
752 if (*p != ',') break;
758 static int sbusfbcon_switch(int con, struct fb_info *info)
760 int x_margin, y_margin;
761 struct fb_info_sbusfb *fb = sbusfbinfo(info);
764 /* Do we have to save the colormap? */
765 if (fb_display[currcon].cmap.len)
766 fb_get_cmap(&fb_display[currcon].cmap, 1, sbusfb_getcolreg, info);
768 if (info->display_fg) {
769 lastconsole = info->display_fg->vc_num;
770 if (lastconsole != con &&
771 (fontwidth(&fb_display[lastconsole]) != fontwidth(&fb_display[con]) ||
772 fontheight(&fb_display[lastconsole]) != fontheight(&fb_display[con])))
773 fb->cursor.mode |= CURSOR_SHAPE;
775 x_margin = (fb_display[con].var.xres_virtual - fb_display[con].var.xres) / 2;
776 y_margin = (fb_display[con].var.yres_virtual - fb_display[con].var.yres) / 2;
778 fb->margins(fb, &fb_display[con], x_margin, y_margin);
779 if (fb->graphmode || fb->x_margin != x_margin || fb->y_margin != y_margin) {
780 fb->x_margin = x_margin; fb->y_margin = y_margin;
781 sbusfb_clear_margin(&fb_display[con], 0);
784 /* Install new colormap */
785 do_install_cmap(con, info);
790 * Update the `var' structure (called by fbcon.c)
793 static int sbusfbcon_updatevar(int con, struct fb_info *info)
803 static void sbusfbcon_blank(int blank, struct fb_info *info)
805 struct fb_info_sbusfb *fb = sbusfbinfo(info);
807 if (blank && fb->blank)
808 return fb->blank(fb);
809 else if (!blank && fb->unblank)
810 return fb->unblank(fb);
814 * Read a single color register and split it into
815 * colors/transparent. Return != 0 for invalid regno.
818 static int sbusfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
819 u_int *transp, struct fb_info *info)
821 struct fb_info_sbusfb *fb = sbusfbinfo(info);
823 if (!fb->color_map || regno > 255)
825 *red = (fb->color_map CM(regno, 0)<<8) | fb->color_map CM(regno, 0);
826 *green = (fb->color_map CM(regno, 1)<<8) | fb->color_map CM(regno, 1);
827 *blue = (fb->color_map CM(regno, 2)<<8) | fb->color_map CM(regno, 2);
834 * Set a single color register. The values supplied are already
835 * rounded down to the hardware's capabilities (according to the
836 * entries in the var structure). Return != 0 for invalid regno.
839 static int sbusfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
840 u_int transp, struct fb_info *info)
842 struct fb_info_sbusfb *fb = sbusfbinfo(info);
844 if (!fb->color_map || regno > 255)
849 fb->color_map CM(regno, 0) = red;
850 fb->color_map CM(regno, 1) = green;
851 fb->color_map CM(regno, 2) = blue;
856 static void do_install_cmap(int con, struct fb_info *info)
858 struct fb_info_sbusfb *fb = sbusfbinfo(info);
862 if (fb_display[con].cmap.len)
863 fb_set_cmap(&fb_display[con].cmap, 1, sbusfb_setcolreg, info);
865 fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
866 1, sbusfb_setcolreg, info);
868 (*fb->loadcmap)(fb, &fb_display[con], 0, 256);
871 static int sbusfb_set_font(struct display *p, int width, int height)
874 int w = p->var.xres_virtual, h = p->var.yres_virtual;
875 int depth = p->var.bits_per_pixel;
876 struct fb_info_sbusfb *fb = sbusfbinfod(p);
877 int x_margin, y_margin;
879 if (depth > 8) depth = 8;
882 if (defx_margin < 0 || defy_margin < 0) {
883 for (margin = 0; def_margins[margin].depth; margin++)
884 if (w == def_margins[margin].xres &&
885 h == def_margins[margin].yres &&
886 depth == def_margins[margin].depth) {
887 x_margin = def_margins[margin].x_margin;
888 y_margin = def_margins[margin].y_margin;
892 x_margin = defx_margin;
893 y_margin = defy_margin;
895 x_margin += ((w - 2*x_margin) % width) / 2;
896 y_margin += ((h - 2*y_margin) % height) / 2;
898 p->var.xres = w - 2*x_margin;
899 p->var.yres = h - 2*y_margin;
901 fb->cursor.mode |= CURSOR_SHAPE;
904 fb->margins(fb, p, x_margin, y_margin);
905 if (fb->x_margin != x_margin || fb->y_margin != y_margin) {
906 fb->x_margin = x_margin; fb->y_margin = y_margin;
907 sbusfb_clear_margin(p, 0);
913 void sbusfb_palette(int enter)
918 for (i = 0; i < MAX_NR_CONSOLES; i++) {
920 if (p->dispsw && p->dispsw->setup == sbusfb_disp_setup &&
921 p->fb_info->display_fg &&
922 p->fb_info->display_fg->vc_num == i) {
923 struct fb_info_sbusfb *fb = sbusfbinfod(p);
925 if (fb->restore_palette) {
927 fb->restore_palette(fb);
928 else if (vt_cons[i]->vc_mode != KD_GRAPHICS)
929 vc_cons[i].d->vc_sw->con_set_palette(vc_cons[i].d, color_table);
939 extern void (*prom_palette)(int);
941 static void __init sbusfb_init_fb(int node, int parent, int fbtype,
942 struct sbus_dev *sbdp)
944 struct fb_fix_screeninfo *fix;
945 struct fb_var_screeninfo *var;
946 struct display *disp;
947 struct fb_info_sbusfb *fb;
949 int linebytes, w, h, depth;
953 fb = kmalloc(sizeof(struct fb_info_sbusfb), GFP_ATOMIC);
955 prom_printf("Could not allocate sbusfb structure\n");
960 prom_palette = sbusfb_palette;
962 memset(fb, 0, sizeof(struct fb_info_sbusfb));
968 spin_lock_init(&fb->lock);
969 fb->prom_node = node;
970 fb->prom_parent = parent;
973 fb->iospace = sbdp->reg_addrs[0].which_io;
975 type->fb_type = fbtype;
976 memset(&fb->emulations, 0xff, sizeof(fb->emulations));
977 fb->emulations[0] = fbtype;
980 disp->screen_base = (unsigned char *)prom_getintdefault(node, "address", 0);
983 type->fb_height = h = prom_getintdefault(node, "height", 900);
984 type->fb_width = w = prom_getintdefault(node, "width", 1152);
986 type->fb_depth = depth = (fbtype == FBTYPE_SUN2BW) ? 1 : 8;
987 linebytes = prom_getintdefault(node, "linebytes", w * depth / 8);
988 type->fb_size = PAGE_ALIGN((linebytes) * h);
990 if (defx_margin < 0 || defy_margin < 0) {
991 for (margin = 0; def_margins[margin].depth; margin++)
992 if (w == def_margins[margin].xres &&
993 h == def_margins[margin].yres &&
994 depth == def_margins[margin].depth) {
995 fb->x_margin = def_margins[margin].x_margin;
996 fb->y_margin = def_margins[margin].y_margin;
1000 fb->x_margin = defx_margin;
1001 fb->y_margin = defy_margin;
1003 fb->x_margin += ((w - 2*fb->x_margin) & 7) / 2;
1004 fb->y_margin += ((h - 2*fb->y_margin) & 15) / 2;
1006 var->xres_virtual = w;
1007 var->yres_virtual = h;
1008 var->xres = w - 2*fb->x_margin;
1009 var->yres = h - 2*fb->y_margin;
1011 var->bits_per_pixel = depth;
1012 var->height = var->width = -1;
1013 var->pixclock = 10000;
1014 var->vmode = FB_VMODE_NONINTERLACED;
1015 var->red.length = var->green.length = var->blue.length = 8;
1017 fix->line_length = linebytes;
1018 fix->smem_len = type->fb_size;
1019 fix->type = FB_TYPE_PACKED_PIXELS;
1020 fix->visual = FB_VISUAL_PSEUDOCOLOR;
1023 fb->info.fbops = &sbusfb_ops;
1024 fb->info.disp = disp;
1025 strcpy(fb->info.fontname, fontname);
1026 fb->info.changevar = NULL;
1027 fb->info.switch_con = &sbusfbcon_switch;
1028 fb->info.updatevar = &sbusfbcon_updatevar;
1029 fb->info.blank = &sbusfbcon_blank;
1030 fb->info.flags = FBINFO_FLAG_DEFAULT;
1032 fb->cursor.hwsize.fbx = 32;
1033 fb->cursor.hwsize.fby = 32;
1035 if (depth > 1 && !fb->color_map)
1036 fb->color_map = kmalloc(256 * 3, GFP_ATOMIC);
1039 #ifdef CONFIG_FB_CREATOR
1040 case FBTYPE_CREATOR:
1041 p = creatorfb_init(fb); break;
1043 #ifdef CONFIG_FB_CGSIX
1044 case FBTYPE_SUNFAST_COLOR:
1045 p = cgsixfb_init(fb); break;
1047 #ifdef CONFIG_FB_CGTHREE
1048 case FBTYPE_SUN3COLOR:
1049 p = cgthreefb_init(fb); break;
1051 #ifdef CONFIG_FB_TCX
1052 case FBTYPE_TCXCOLOR:
1053 p = tcxfb_init(fb); break;
1055 #ifdef CONFIG_FB_LEO
1057 p = leofb_init(fb); break;
1059 #ifdef CONFIG_FB_BWTWO
1061 p = bwtwofb_init(fb); break;
1063 #ifdef CONFIG_FB_CGFOURTEEN
1064 case FBTYPE_MDICOLOR:
1065 p = cgfourteenfb_init(fb); break;
1067 #ifdef CONFIG_FB_P9100
1068 case FBTYPE_P9100COLOR:
1069 /* Temporary crock. For now we are a cg3 */
1070 p = p9100fb_init(fb); type->fb_type = FBTYPE_SUN3COLOR; break;
1076 kfree(fb->color_map);
1081 if (p == SBUSFBINIT_SIZECHANGE)
1084 disp->dispsw = &fb->dispsw;
1085 if (fb->setcursor) {
1086 fb->dispsw.cursor = sbusfb_cursor;
1088 fb->cursor.blink_rate = DEFAULT_CURSOR_BLINK_RATE;
1089 init_timer(&fb->cursor.timer);
1090 fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
1091 fb->cursor.timer.data = (unsigned long)fb;
1092 fb->cursor.timer.function = sbusfb_cursor_timer_handler;
1093 add_timer(&fb->cursor.timer);
1096 fb->cursor.mode = CURSOR_SHAPE;
1097 fb->dispsw.set_font = sbusfb_set_font;
1098 fb->setup = fb->dispsw.setup;
1099 fb->dispsw.setup = sbusfb_disp_setup;
1100 fb->dispsw.clear_margins = NULL;
1103 disp->visual = fix->visual;
1104 disp->type = fix->type;
1105 disp->type_aux = fix->type_aux;
1106 disp->line_length = fix->line_length;
1109 disp->can_soft_blank = 1;
1111 sbusfb_set_var(var, -1, &fb->info);
1113 if (register_framebuffer(&fb->info) < 0) {
1115 kfree(fb->color_map);
1119 printk(KERN_INFO "fb%d: %s\n", GET_FB_IDX(fb->info.node), p);
1122 static inline int known_card(char *name)
1125 for (p = name; *p && *p != ','; p++);
1126 if (*p == ',') name = p + 1;
1127 if (!strcmp(name, "cgsix") || !strcmp(name, "cgthree+"))
1128 return FBTYPE_SUNFAST_COLOR;
1129 if (!strcmp(name, "cgthree") || !strcmp(name, "cgRDI"))
1130 return FBTYPE_SUN3COLOR;
1131 if (!strcmp(name, "cgfourteen"))
1132 return FBTYPE_MDICOLOR;
1133 if (!strcmp(name, "leo"))
1134 return FBTYPE_SUNLEO;
1135 if (!strcmp(name, "bwtwo"))
1136 return FBTYPE_SUN2BW;
1137 if (!strcmp(name, "tcx"))
1138 return FBTYPE_TCXCOLOR;
1139 if (!strcmp(name, "p9100"))
1140 return FBTYPE_P9100COLOR;
1141 return FBTYPE_NOTYPE;
1144 #ifdef CONFIG_FB_CREATOR
1145 static void creator_fb_scan_siblings(int root)
1149 child = prom_getchild(root);
1150 for (node = prom_searchsiblings(child, "SUNW,ffb"); node;
1151 node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb"))
1152 sbusfb_init_fb(node, root, FBTYPE_CREATOR, NULL);
1153 for (node = prom_searchsiblings(child, "SUNW,afb"); node;
1154 node = prom_searchsiblings(prom_getsibling(node), "SUNW,afb"))
1155 sbusfb_init_fb(node, root, FBTYPE_CREATOR, NULL);
1158 static void creator_fb_scan(void)
1162 creator_fb_scan_siblings(prom_root_node);
1164 root = prom_getchild(prom_root_node);
1165 for (root = prom_searchsiblings(root, "upa"); root;
1166 root = prom_searchsiblings(prom_getsibling(root), "upa"))
1167 creator_fb_scan_siblings(root);
1171 int __init sbusfb_init(void)
1174 struct sbus_dev *sbdp;
1175 struct sbus_bus *sbus;
1177 extern int con_is_present(void);
1179 if (!con_is_present()) return -ENXIO;
1181 #ifdef CONFIG_FB_CREATOR
1185 sbusfb_init_fb(0, 0, FBTYPE_SUN2BW, NULL);
1187 #if defined(CONFIG_FB_CGFOURTEEN) && !defined(__sparc_v9__)
1190 root = prom_getchild(prom_root_node);
1191 root = prom_searchsiblings(root, "obio");
1193 (node = prom_searchsiblings(prom_getchild(root), "cgfourteen"))) {
1194 sbusfb_init_fb(node, root, FBTYPE_MDICOLOR, NULL);
1198 if (sbus_root == NULL)
1200 for_all_sbusdev(sbdp, sbus) {
1201 type = known_card(sbdp->prom_name);
1202 if (type == FBTYPE_NOTYPE)
1204 if (prom_getproperty(sbdp->prom_node, "emulation",
1205 prom_name, sizeof(prom_name)) > 0) {
1206 type = known_card(prom_name);
1207 if (type == FBTYPE_NOTYPE)
1208 type = known_card(sbdp->prom_name);
1210 sbusfb_init_fb(sbdp->prom_node, sbdp->bus->prom_node, type, sbdp);
1215 MODULE_LICENSE("GPL");