2 * linux/drivers/video/maxinefb.c
4 * DECstation 5000/xx onboard framebuffer support ... derived from:
5 * "HP300 Topcat framebuffer support (derived from macfb of all things)
6 * Phil Blundell <philb@gnu.org> 1998", the original code can be
7 * found in the file hpfb.c in the same directory.
9 * DECstation related code Copyright (C) 1999,2000,2001 by
10 * Michael Engel <engel@unix-ag.org> and
11 * Karsten Merker <merker@linuxtag.org>.
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.
20 * 2001/01/27 removed debugging and testing code, fixed fb_ops
21 * initialization which had caused a crash before,
22 * general cleanup, first official release (KM)
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/errno.h>
31 #include <linux/string.h>
33 #include <linux/tty.h>
34 #include <linux/slab.h>
35 #include <linux/delay.h>
36 #include <linux/init.h>
38 #include <video/fbcon.h>
41 /* bootinfo.h defines the machine type values, needed when checking */
42 /* whether are really running on a maxine, KM */
43 #include <asm/bootinfo.h>
45 #include <video/fbcon-mfb.h>
46 #include <video/fbcon-cfb2.h>
47 #include <video/fbcon-cfb4.h>
48 #include <video/fbcon-cfb8.h>
50 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
52 static struct display disp;
53 static struct fb_info fb_info;
55 unsigned long fb_start, fb_size = 1024 * 768, fb_line_length = 1024;
56 unsigned long fb_regs;
57 unsigned char fb_bitmask;
59 static struct fb_var_screeninfo maxinefb_defined = {
60 0, 0, 0, 0, /* W,H, W, H (virtual) load xres,xres_virtual */
61 0, 0, /* virtual -> visible no offset */
62 0, /* depth -> load bits_per_pixel */
67 {0, 0, 0}, /* transparency */
68 0, /* standard pixel format */
70 274, 195, /* 14" monitor */
73 0L, 0L, 0, /* No sync info */
74 FB_VMODE_NONINTERLACED,
81 static int currcon = 0;
82 static struct maxinefb_par current_par;
84 /* Reference to machine type set in arch/mips/dec/prom/identify.c, KM */
85 extern unsigned long mips_machtype;
88 /* Handle the funny Inmos RamDAC/video controller ... */
90 void maxinefb_ims332_write_register(int regno, register unsigned int val)
92 register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
95 wptr = regs + 0xa0000 + (regno << 4);
96 *((volatile unsigned int *) (regs)) = (val >> 8) & 0xff00;
97 *((volatile unsigned short *) (wptr)) = val;
100 unsigned int maxinefb_ims332_read_register(int regno)
102 register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
104 register unsigned int j, k;
106 rptr = regs + 0x80000 + (regno << 4);
107 j = *((volatile unsigned short *) rptr);
108 k = *((volatile unsigned short *) regs);
110 return (j & 0xffff) | ((k & 0xff00) << 8);
114 static void maxinefb_encode_var(struct fb_var_screeninfo *var,
115 struct maxinefb_par *par)
120 var->xres_virtual = 1024;
121 var->yres_virtual = 768;
124 var->bits_per_pixel = 8;
126 var->transp.offset = 0;
127 var->transp.length = 0;
128 var->transp.msb_right = 0;
133 var->vmode = FB_VMODE_NONINTERLACED;
136 var->left_margin = 0;
137 var->right_margin = 0;
138 var->upper_margin = 0;
139 var->lower_margin = 0;
142 for (i = 0; i < arraysize(var->reserved); i++)
143 var->reserved[i] = 0;
146 static void maxinefb_get_par(struct maxinefb_par *par)
151 static int maxinefb_fb_update_var(int con, struct fb_info *info)
156 static int maxinefb_do_fb_set_var(struct fb_var_screeninfo *var,
159 struct maxinefb_par par;
161 maxinefb_get_par(&par);
162 maxinefb_encode_var(var, &par);
167 /* Get the palette */
169 static int maxinefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
170 struct fb_info *info)
173 unsigned long hw_colorvalue = 0; /* raw color value from the register */
176 if (((cmap->start) + (cmap->len)) >= 256) {
177 length = 256 - (cmap->start);
181 for (i = 0; i < length; i++) {
183 maxinefb_ims332_read_register(IMS332_REG_COLOR_PALETTE
185 (cmap->red[i]) = ((hw_colorvalue & 0x0000ff));
186 (cmap->green[i]) = ((hw_colorvalue & 0x00ff00) >> 8);
187 (cmap->blue[i]) = ((hw_colorvalue & 0xff0000) >> 16);
194 /* Set the palette */
196 static int maxinefb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
197 struct fb_info *info)
200 unsigned long hw_colorvalue; /* value to be written into the palette reg. */
201 unsigned short cmap_red;
202 unsigned short cmap_green;
203 unsigned short cmap_blue;
207 if (((cmap->start) + (cmap->len)) >= 256) {
208 length = 256 - (cmap->start);
213 for (i = 0; i < length; i++) {
214 cmap_red = ((cmap->red[i]) >> 8); /* The cmap fields are 16 bits */
215 cmap_green = ((cmap->green[i]) >> 8); /* wide, but the harware colormap */
216 cmap_blue = ((cmap->blue[i]) >> 8); /* registers are only 8 bits wide */
219 (cmap_blue << 16) + (cmap_green << 8) + (cmap_red);
220 maxinefb_ims332_write_register(IMS332_REG_COLOR_PALETTE +
227 static int maxinefb_get_var(struct fb_var_screeninfo *var, int con,
228 struct fb_info *info)
230 struct maxinefb_par par;
232 maxinefb_get_par(&par);
233 maxinefb_encode_var(var, &par);
235 *var = fb_display[con].var;
240 static int maxinefb_set_var(struct fb_var_screeninfo *var, int con,
241 struct fb_info *info)
245 if ((err = maxinefb_do_fb_set_var(var, 1)))
249 static void maxinefb_encode_fix(struct fb_fix_screeninfo *fix,
250 struct maxinefb_par *par)
252 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
253 strcpy(fix->id, "maxinefb");
254 /* fix->id is a char[16], so a maximum of 15 characters, KM */
256 fix->smem_start = (char *) fb_start; /* display memory base address, KM */
257 fix->smem_len = fb_size;
258 fix->type = FB_TYPE_PACKED_PIXELS;
259 fix->visual = FB_VISUAL_PSEUDOCOLOR;
263 fix->line_length = fb_line_length;
266 static int maxinefb_get_fix(struct fb_fix_screeninfo *fix, int con,
267 struct fb_info *info)
269 struct maxinefb_par par;
270 maxinefb_get_par(&par);
271 maxinefb_encode_fix(fix, &par);
275 static int maxinefb_switch(int con, struct fb_info *info)
277 maxinefb_do_fb_set_var(&fb_display[con].var, 1);
282 static void maxinefb_set_disp(int con)
284 struct fb_fix_screeninfo fix;
285 struct display *display;
288 display = &fb_display[con];
290 display = &disp; /* used during initialization */
292 maxinefb_get_fix(&fix, con, 0);
294 display->screen_base = fix.smem_start;
295 display->visual = fix.visual;
296 display->type = fix.type;
297 display->type_aux = fix.type_aux;
298 display->ypanstep = fix.ypanstep;
299 display->ywrapstep = fix.ywrapstep;
300 display->line_length = fix.line_length;
301 display->next_line = fix.line_length;
302 display->can_soft_blank = 0;
303 display->inverse = 0;
304 display->scrollmode = SCROLL_YREDRAW;
305 display->dispsw = &fbcon_cfb8;
308 static struct fb_ops maxinefb_ops = {
310 fb_get_fix: maxinefb_get_fix,
311 fb_get_var: maxinefb_get_var,
312 fb_set_var: maxinefb_set_var,
313 fb_get_cmap: maxinefb_get_cmap,
314 fb_set_cmap: maxinefb_set_cmap,
317 int __init maxinefb_init(void)
319 volatile unsigned char *fboff;
322 /* Validate we're on the proper machine type */
323 if (mips_machtype != MACH_DS5000_XX) {
327 printk(KERN_INFO "Maxinefb: Personal DECstation detected\n");
328 printk(KERN_INFO "Maxinefb: initializing onboard framebuffer\n");
330 /* Framebuffer display memory base address */
331 fb_start = DS5000_xx_ONBOARD_FBMEM_START;
334 for (fboff = fb_start; fboff < fb_start + 0x1ffff; fboff++)
337 /* erase hardware cursor */
338 for (i = 0; i < 512; i++) {
339 maxinefb_ims332_write_register(IMS332_REG_CURSOR_RAM + i,
343 maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0x0f);
345 maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0xf0);
349 /* Fill in the available video resolution */
350 maxinefb_defined.xres = 1024;
351 maxinefb_defined.yres = 768;
352 maxinefb_defined.xres_virtual = 1024;
353 maxinefb_defined.yres_virtual = 768;
354 maxinefb_defined.bits_per_pixel = 8;
356 /* Let there be consoles... */
358 strcpy(fb_info.modename, "Maxine onboard graphics 1024x768x8");
359 /* fb_info.modename: maximum of 39 characters + trailing nullbyte, KM */
360 fb_info.changevar = NULL;
362 fb_info.fbops = &maxinefb_ops;
363 fb_info.disp = &disp;
364 fb_info.switch_con = &maxinefb_switch;
365 fb_info.updatevar = &maxinefb_fb_update_var;
366 fb_info.blank = NULL;
367 fb_info.flags = FBINFO_FLAG_DEFAULT;
368 maxinefb_do_fb_set_var(&maxinefb_defined, 1);
370 maxinefb_get_var(&disp.var, -1, &fb_info);
371 maxinefb_set_disp(-1);
373 if (register_framebuffer(&fb_info) < 0)
379 static void __exit maxinefb_exit(void)
381 unregister_framebuffer(&fb_info);
385 MODULE_LICENSE("GPL");
386 module_init(maxinefb_init);
388 module_exit(maxinefb_exit);