patch-2.4.25 linux-2.4.25/drivers/video/maxinefb.c

Next file: linux-2.4.25/drivers/video/pmag-aa-fb.c
Previous file: linux-2.4.25/drivers/video/macfb.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.24/drivers/video/maxinefb.c linux-2.4.25/drivers/video/maxinefb.c
@@ -17,13 +17,17 @@
 
 /*
  * Changes:
- * 2001/01/27 removed debugging and testing code, fixed fb_ops
- *            initialization which had caused a crash before,
- *            general cleanup, first official release (KM)
+ * 2001-01-27  removed debugging and testing code, fixed fb_ops
+ *	       initialization which had caused a crash before,
+ *	       general cleanup, first official release (KM)
  *
+ * 2003-03-08  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
+ *	       Moved ims332 support in its own file. Code cleanup.
+ *
+ * 2003-09-08  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
+ *	       First attempt of mono and hw cursor support.
  */
 
-
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
@@ -33,363 +37,665 @@
 #include <linux/tty.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/fb.h>
-#include <video/fbcon.h>
-#include "maxinefb.h"
+#include <linux/console.h>
 
-/* bootinfo.h defines the machine type values, needed when checking */
-/* whether are really running on a maxine, KM                       */
+/*
+ * bootinfo.h is needed for checking whether we are really running
+ * on a maxine.
+ */
 #include <asm/bootinfo.h>
+#include <asm/addrspace.h>
 
+#include <video/fbcon.h>
 #include <video/fbcon-mfb.h>
 #include <video/fbcon-cfb2.h>
 #include <video/fbcon-cfb4.h>
 #include <video/fbcon-cfb8.h>
 
-#define arraysize(x)    (sizeof(x)/sizeof(*(x)))
+#include "ims332.h"
 
-static struct display disp;
-static struct fb_info fb_info;
+/* Version information */
+#define DRIVER_VERSION "0.02"
+#define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>"
+#define DRIVER_DESCRIPTION "Maxine Framebuffer Driver"
+#define DRIVER_DESCR "maxinefb"
 
-unsigned long fb_start, fb_size = 1024 * 768, fb_line_length = 1024;
-unsigned long fb_regs;
-unsigned char fb_bitmask;
-
-static struct fb_var_screeninfo maxinefb_defined = {
-	0, 0, 0, 0,		/* W,H, W, H (virtual) load xres,xres_virtual */
-	0, 0,			/* virtual -> visible no offset */
-	0,			/* depth -> load bits_per_pixel */
-	0,			/* greyscale ? */
-	{0, 0, 0},		/* R */
-	{0, 0, 0},		/* G */
-	{0, 0, 0},		/* B */
-	{0, 0, 0},		/* transparency */
-	0,			/* standard pixel format */
-	FB_ACTIVATE_NOW,
-	274, 195,		/* 14" monitor */
-	FB_ACCEL_NONE,
-	0L, 0L, 0L, 0L, 0L,
-	0L, 0L, 0,		/* No sync info */
-	FB_VMODE_NONINTERLACED,
-	{0, 0, 0, 0, 0, 0}
-};
+/* Prototypes */
+static int maxinefb_set_var(struct fb_var_screeninfo *var, int con,
+			    struct fb_info *info);
 
-struct maxinefb_par {
+/* Hardware cursor */
+struct maxine_cursor {
+	struct timer_list timer;
+	int enable;
+	int on;
+	int vbl_cnt;
+	int blink_rate;
+	u16 x, y, width, height;
 };
 
-static int currcon = 0;
-static struct maxinefb_par current_par;
+#define CURSOR_TIMER_FREQ	(HZ / 50)
+#define CURSOR_BLINK_RATE	(20)
+#define CURSOR_DRAW_DELAY	(2)
+
+static struct maxinefb_info {
+	struct fb_info info;
+	struct display disp;
+	struct display_switch dispsw;
+	struct ims332_regs *ims332;
+	unsigned long fb_start;
+	u32 fb_size;
+	struct maxine_cursor cursor;
+} *my_info;
+
+static struct maxinefb_par {
+} current_par;
+
+static int currcon = -1;
+
+static void maxine_set_cursor(struct maxinefb_info *ip, int on)
+{
+	struct maxine_cursor *c = &ip->cursor;
+
+	if (on)
+		ims332_position_cursor(ip->ims332, c->x, c->y);
+
+	ims332_enable_cursor(ip->ims332, on);
+}
+
+static void maxinefbcon_cursor(struct display *disp, int mode, int x, int y)
+{
+	struct maxinefb_info *ip = (struct maxinefb_info *)disp->fb_info;
+	struct maxine_cursor *c = &ip->cursor;
+
+	x *= fontwidth(disp);
+	y *= fontheight(disp);
+
+	if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable)
+		return;
+
+	c->enable = 0;
+	if (c->on)
+		maxine_set_cursor(ip, 0);
+	c->x = x - disp->var.xoffset;
+	c->y = y - disp->var.yoffset;
+
+	switch (mode) {
+		case CM_ERASE:
+			c->on = 0;
+			break;
+		case CM_DRAW:
+		case CM_MOVE:
+			if (c->on)
+				maxine_set_cursor(ip, c->on);
+			else
+				c->vbl_cnt = CURSOR_DRAW_DELAY;
+			c->enable = 1;
+			break;
+	}
+}
+
+static int maxinefbcon_set_font(struct display *disp, int width, int height)
+{
+	struct maxinefb_info *ip = (struct maxinefb_info *)disp->fb_info;
+	struct maxine_cursor *c = &ip->cursor;
+	u8 fgc = ~attr_bgcol_ec(disp, disp->conp);
 
+	if (width > 64 || height > 64 || width < 0 || height < 0)
+		return -EINVAL;
 
-/* Handle the funny Inmos RamDAC/video controller ... */
+	c->height = height;
+	c->width = width;
 
-void maxinefb_ims332_write_register(int regno, register unsigned int val)
-{
-	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
-	unsigned char *wptr;
+	ims332_set_font(ip->ims332, fgc, width, height);
 
-	wptr = regs + 0xa0000 + (regno << 4);
-	*((volatile unsigned int *) (regs)) = (val >> 8) & 0xff00;
-	*((volatile unsigned short *) (wptr)) = val;
+	return 1;
 }
 
-unsigned int maxinefb_ims332_read_register(int regno)
+static void maxine_cursor_timer_handler(unsigned long data)
 {
-	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
-	unsigned char *rptr;
-	register unsigned int j, k;
+	struct maxinefb_info *ip = (struct maxinefb_info *)data;
+	struct maxine_cursor *c = &ip->cursor;
+
+	if (!c->enable)
+		goto out;
 
-	rptr = regs + 0x80000 + (regno << 4);
-	j = *((volatile unsigned short *) rptr);
-	k = *((volatile unsigned short *) regs);
+	if (c->vbl_cnt && --c->vbl_cnt == 0) {
+		c->on ^= 1;
+		maxine_set_cursor(ip, c->on);
+		c->vbl_cnt = c->blink_rate;
+	}
 
-	return (j & 0xffff) | ((k & 0xff00) << 8);
+out:
+	c->timer.expires = jiffies + CURSOR_TIMER_FREQ;
+	add_timer(&c->timer);
 }
 
+static void __init maxine_cursor_init(struct maxinefb_info *ip)
+{
+	struct maxine_cursor *c = &ip->cursor;
+
+	c->enable = 1;
+	c->on = 1;
+	c->x = c->y = 0;
+	c->width = c->height = 0;
+	c->vbl_cnt = CURSOR_DRAW_DELAY;
+	c->blink_rate = CURSOR_BLINK_RATE;
+
+	init_timer(&c->timer);
+	c->timer.data = (unsigned long)ip;
+	c->timer.function = maxine_cursor_timer_handler;
+	mod_timer(&c->timer, jiffies + CURSOR_TIMER_FREQ);
+}
 
-static void maxinefb_encode_var(struct fb_var_screeninfo *var,
-				struct maxinefb_par *par)
+static void __exit maxine_cursor_exit(struct maxinefb_info *ip)
 {
-	int i = 0;
-	var->xres = 1024;
-	var->yres = 768;
-	var->xres_virtual = 1024;
-	var->yres_virtual = 768;
-	var->xoffset = 0;
-	var->yoffset = 0;
-	var->bits_per_pixel = 8;
-	var->grayscale = 0;
-	var->red.offset = 0;
-	var->red.length = 8;
-	var->red.msb_right = 0;
-	var->green.offset = 0;
-	var->green.length = 8;
-	var->green.msb_right = 0;
-	var->blue.offset = 0;
-	var->blue.length = 8;
-	var->blue.msb_right = 0;
-	var->transp.offset = 0;
-	var->transp.length = 0;
-	var->transp.msb_right = 0;
-	var->nonstd = 0;
-	var->activate = 1;
-	var->height = -1;
-	var->width = -1;
-	var->vmode = FB_VMODE_NONINTERLACED;
-	var->pixclock = 0;
-	var->sync = 0;
-	var->left_margin = 0;
-	var->right_margin = 0;
-	var->upper_margin = 0;
-	var->lower_margin = 0;
-	var->hsync_len = 0;
-	var->vsync_len = 0;
-	for (i = 0; i < arraysize(var->reserved); i++)
-		var->reserved[i] = 0;
+	struct maxine_cursor *c = &ip->cursor;
+
+	del_timer_sync(&c->timer);
 }
 
+#ifdef FBCON_HAS_MFB
+extern void fbcon_mfb_clear_margins(struct vc_data *conp, struct display *p,
+				    int bottom_only);
+
+static struct display_switch maxine_switch1 = {
+	.setup = fbcon_mfb_setup,
+	.bmove = fbcon_mfb_bmove,
+	.clear = fbcon_mfb_clear,
+	.putc = fbcon_mfb_putc,
+	.putcs = fbcon_mfb_putcs,
+	.revc = fbcon_mfb_revc,
+	.cursor = maxinefbcon_cursor,
+	.set_font = maxinefbcon_set_font,
+	.clear_margins = fbcon_mfb_clear_margins,
+	.fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
+};
+#endif
+#ifdef FBCON_HAS_CFB2
+static struct display_switch maxine_switch2 = {
+	.setup = fbcon_cfb2_setup,
+	.bmove = fbcon_cfb2_bmove,
+	.clear = fbcon_cfb2_clear,
+	.putc = fbcon_cfb2_putc,
+	.putcs = fbcon_cfb2_putcs,
+	.revc = fbcon_cfb2_revc,
+	.cursor = maxinefbcon_cursor,
+	.set_font = maxinefbcon_set_font,
+	.clear_margins = fbcon_cfb8_clear_margins, /* sigh.. */
+	.fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
+};
+#endif
+#ifdef FBCON_HAS_CFB4
+static struct display_switch maxine_switch4 = {
+	.setup = fbcon_cfb4_setup,
+	.bmove = fbcon_cfb4_bmove,
+	.clear = fbcon_cfb4_clear,
+	.putc = fbcon_cfb4_putc,
+	.putcs = fbcon_cfb4_putcs,
+	.revc = fbcon_cfb4_revc,
+	.cursor = maxinefbcon_cursor,
+	.set_font = maxinefbcon_set_font,
+	.clear_margins = fbcon_cfb8_clear_margins, /* sigh.. */
+	.fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
+};
+#endif
+static struct display_switch maxine_switch8 = {
+	.setup = fbcon_cfb8_setup,
+	.bmove = fbcon_cfb8_bmove,
+	.clear = fbcon_cfb8_clear,
+	.putc = fbcon_cfb8_putc,
+	.putcs = fbcon_cfb8_putcs,
+	.revc = fbcon_cfb8_revc,
+	.cursor = maxinefbcon_cursor,
+	.set_font = maxinefbcon_set_font,
+	.clear_margins = fbcon_cfb8_clear_margins,
+	.fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
+};
+
 static void maxinefb_get_par(struct maxinefb_par *par)
 {
 	*par = current_par;
 }
 
-static int maxinefb_fb_update_var(int con, struct fb_info *info)
+static int maxinefb_get_fix(struct fb_fix_screeninfo *fix, int con,
+			    struct fb_info *info)
 {
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+	struct fb_var_screeninfo *var = &disp->var;
+
+	memset(fix, 0, sizeof(struct fb_fix_screeninfo));
+	strcpy(fix->id, DRIVER_DESCR);
+	fix->smem_start = ip->fb_start;
+	fix->smem_len = ip->fb_size;
+	fix->type = FB_TYPE_PACKED_PIXELS;
+	fix->ypanstep = 1;
+	fix->ywrapstep = 1;
+	fix->visual = FB_VISUAL_PSEUDOCOLOR;
+	switch (var->bits_per_pixel) {
+#ifdef FBCON_HAS_MFB
+	case 1: fix->line_length = var->xres / 8; break;
+#endif
+#ifdef FBCON_HAS_CFB2
+	case 2: fix->line_length = var->xres / 4; break;
+#endif
+#ifdef FBCON_HAS_CFB4
+	case 4: fix->line_length = var->xres / 2; break;
+#endif
+	case 8:
+	default:
+		fix->line_length = var->xres;
+		var->bits_per_pixel = 8;
+		break;
+	}
+	fix->accel = FB_ACCEL_NONE;
+
 	return 0;
 }
 
-static int maxinefb_do_fb_set_var(struct fb_var_screeninfo *var,
-				  int isactive)
+static int maxinefb_set_dispsw(struct display *disp, struct maxinefb_info *ip)
 {
-	struct maxinefb_par par;
+	if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor)
+		disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE);
 
-	maxinefb_get_par(&par);
-	maxinefb_encode_var(var, &par);
+	switch (disp->var.bits_per_pixel) {
+#ifdef FBCON_HAS_MFB
+	case 1: ip->dispsw = maxine_switch1; break;
+#endif
+#ifdef FBCON_HAS_CFB2
+	case 2: ip->dispsw = maxine_switch2; break;
+#endif
+#ifdef FBCON_HAS_CFB4
+	case 4: ip->dispsw = maxine_switch4; break;
+#endif
+	case 8:
+	default:
+		ip->dispsw = maxine_switch8;
+		disp->var.bits_per_pixel = 8;
+		break;
+	}
+
+	ims332_set_color_depth(ip->ims332, disp->var.bits_per_pixel);
+	disp->dispsw = &ip->dispsw;
+	disp->dispsw_data = 0;
 	return 0;
 }
 
+static void maxinefb_set_disp(struct display *disp, int con,
+			      struct maxinefb_info *ip)
+{
+	struct fb_fix_screeninfo fix;
 
-/* Get the palette */
+	disp->fb_info = &ip->info;
+	maxinefb_set_var(&disp->var, con, &ip->info);
+	maxinefb_set_dispsw(disp, ip);
+
+	maxinefb_get_fix(&fix, con, &ip->info);
+	disp->screen_base = (u8 *)fix.smem_start;
+	disp->visual = fix.visual;
+	disp->type = fix.type;
+	disp->type_aux = fix.type_aux;
+	disp->ypanstep = fix.ypanstep;
+	disp->ywrapstep = fix.ywrapstep;
+	disp->line_length = fix.line_length;
+	disp->next_line = fix.line_length;
+	disp->can_soft_blank = 1;
+	disp->inverse = 0;
+	disp->scrollmode = SCROLL_YREDRAW;
+
+	maxinefbcon_set_font(disp, fontwidth(disp), fontheight(disp));
+}
+
+static int getcolreg(u32 reg, u32 *red, u32 *green, u32 *blue, u32 *transp,
+		     struct fb_info *info)
+{
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+
+	u8 r;
+	u8 g;
+	u8 b;
 
-static int maxinefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
-			     struct fb_info *info)
+	if (reg > 255)
+		return 1;
+
+	/*
+	 * Cmap fields are 16 bits wide, but the hardware colormap
+	 * has only 8 bits.
+	 */
+	ims332_read_cmap(ip->ims332, reg, &r, &g, &b);
+	*red = r << 8;
+	*green = g << 8;
+	*blue = b << 8;
+	*transp = 0;
+
+	return 0;
+}
+
+static int setcolreg(u32 reg, u32 red, u32 green, u32 blue, u32 transp,
+		     struct fb_info *info)
 {
-	unsigned int i;
-	unsigned long hw_colorvalue = 0;	/* raw color value from the register */
-	unsigned int length;
-
-	if (((cmap->start) + (cmap->len)) >= 256) {
-		length = 256 - (cmap->start);
-	} else {
-		length = cmap->len;
-	}
-	for (i = 0; i < length; i++) {
-		hw_colorvalue =
-		    maxinefb_ims332_read_register(IMS332_REG_COLOR_PALETTE
-						  + cmap->start + i);
-		(cmap->red[i]) = ((hw_colorvalue & 0x0000ff));
-		(cmap->green[i]) = ((hw_colorvalue & 0x00ff00) >> 8);
-		(cmap->blue[i]) = ((hw_colorvalue & 0xff0000) >> 16);
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+
+	if (reg > 255)
+		return 1;
+
+	/*
+	 * Cmap fields are 16 bits wide, but the hardware colormap
+	 * has only 8 bits.
+	 */
+	red = (red >> 8) & 0xff;
+	green = (green >> 8) & 0xff;
+	blue = (blue >> 8) & 0xff;
+
+	ims332_write_cmap(ip->ims332, reg, red, green, blue);
 
-	}
 	return 0;
 }
 
+#define CMAP_LEN(disp) ((disp->visual == FB_VISUAL_PSEUDOCOLOR) \
+			? (1 << disp->var.bits_per_pixel) : 16)
 
-/* Set the palette */
+static void do_install_cmap(int con, struct maxinefb_info *ip)
+{
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+	int len = CMAP_LEN(disp);
 
-static int maxinefb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
+	if (con != currcon)
+		return;
+	if (fb_display[con].cmap.len)
+		fb_set_cmap(&fb_display[con].cmap, 1, setcolreg, &ip->info);
+	else
+		fb_set_cmap(fb_default_cmap(len), 1, setcolreg, &ip->info);
+}
+
+static void do_save_cmap(int con, struct maxinefb_info *ip)
+{
+	if (con != currcon)
+		return;
+	fb_get_cmap(&fb_display[con].cmap, 1, getcolreg, &ip->info);
+}
+
+static int maxinefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
 			     struct fb_info *info)
 {
-	unsigned int i;
-	unsigned long hw_colorvalue;	/* value to be written into the palette reg. */
-	unsigned short cmap_red;
-	unsigned short cmap_green;
-	unsigned short cmap_blue;
-	unsigned int length;
-
-	hw_colorvalue = 0;
-	if (((cmap->start) + (cmap->len)) >= 256) {
-		length = 256 - (cmap->start);
-	} else {
-		length = cmap->len;
-	}
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+	int len = CMAP_LEN(disp);
+
+	if (con == currcon) /* current console? */
+		return fb_get_cmap(cmap, kspc, getcolreg, info);
+
+	if (disp->cmap.len) /* non default colormap? */
+		fb_copy_cmap(&disp->cmap, cmap, kspc ? 0 : 2);
+	else
+		fb_copy_cmap(fb_default_cmap(len), cmap, kspc ? 0 : 2);
 
-	for (i = 0; i < length; i++) {
-		cmap_red = ((cmap->red[i]) >> 8);	/* The cmap fields are 16 bits    */
-		cmap_green = ((cmap->green[i]) >> 8);	/* wide, but the harware colormap */
-		cmap_blue = ((cmap->blue[i]) >> 8);	/* registers are only 8 bits wide */
-
-		hw_colorvalue =
-		    (cmap_blue << 16) + (cmap_green << 8) + (cmap_red);
-		maxinefb_ims332_write_register(IMS332_REG_COLOR_PALETTE +
-					       cmap->start + i,
-					       hw_colorvalue);
-	}
 	return 0;
 }
 
-static int maxinefb_get_var(struct fb_var_screeninfo *var, int con,
-			    struct fb_info *info)
+static int maxinefb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
+			     struct fb_info *info)
 {
-	struct maxinefb_par par;
-	if (con == -1) {
-		maxinefb_get_par(&par);
-		maxinefb_encode_var(var, &par);
-	} else
-		*var = fb_display[con].var;
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+	int len = CMAP_LEN(disp);
+	int err;
+
+	/* No colormap allocated? */
+	if ((err = fb_alloc_cmap(&disp->cmap, len, 0)))
+		return err;
+
+	if (con == currcon) /* current console? */
+		return fb_set_cmap(cmap, kspc, setcolreg, info);
+
+	fb_copy_cmap(cmap, &disp->cmap, kspc ? 0 : 1);
+
 	return 0;
 }
 
+static int maxinefb_ioctl(struct inode *inode, struct file *file, u32 cmd,
+			  unsigned long arg, int con, struct fb_info *info)
+{
+	/* TODO: Not yet implemented */
+	return -ENOIOCTLCMD;
+}
 
-static int maxinefb_set_var(struct fb_var_screeninfo *var, int con,
-			    struct fb_info *info)
+static int maxinefb_switch(int con, struct fb_info *info)
 {
-	int err;
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *old = (currcon < 0) ? &ip->disp : (fb_display + currcon);
+	struct display *new = (con < 0) ? &ip->disp : (fb_display + con);
+
+	do_save_cmap(currcon, ip);
+	if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor)
+		old->conp->vc_sw->con_cursor(old->conp, CM_ERASE);
+
+	/* Set the current console. */
+	currcon = con;
+	maxinefb_set_disp(new, con, ip);
 
-	if ((err = maxinefb_do_fb_set_var(var, 1)))
-		return err;
 	return 0;
 }
-static void maxinefb_encode_fix(struct fb_fix_screeninfo *fix,
-				struct maxinefb_par *par)
+
+static int maxinefb_encode_var(struct fb_var_screeninfo *var,
+			       struct maxinefb_par *par)
 {
-	memset(fix, 0, sizeof(struct fb_fix_screeninfo));
-	strcpy(fix->id, "maxinefb");
-	/* fix->id is a char[16], so a maximum of 15 characters, KM */
+	var->xres = 1024;
+	var->yres = 768;
+	var->xres_virtual = 1024;
+	var->yres_virtual = 1024;
+	var->xoffset = 0;
+	var->yoffset = 0;
+	var->grayscale = 0;
+	switch (var->bits_per_pixel) {
+#ifdef FBCON_HAS_MFB
+	case 1:
+		var->red.offset = 0;
+		var->red.length = 1;
+		var->red.msb_right = 0;
+		var->green.offset = 0;
+		var->green.length = 1;
+		var->green.msb_right = 0;
+		var->blue.offset = 0;
+		var->blue.length = 1;
+		var->blue.msb_right = 0;
+		var->transp.offset = 0;
+		var->transp.length = 0;
+		var->transp.msb_right = 0;
+		break;
+#endif
+#ifdef FBCON_HAS_CFB2
+	case 2:
+		var->red.offset = 0;
+		var->red.length = 2;
+		var->red.msb_right = 0;
+		var->green.offset = 0;
+		var->green.length = 2;
+		var->green.msb_right = 0;
+		var->blue.offset = 0;
+		var->blue.length = 2;
+		var->blue.msb_right = 0;
+		var->transp.offset = 0;
+		var->transp.length = 0;
+		var->transp.msb_right = 0;
+		break;
+#endif
+#ifdef FBCON_HAS_CFB4
+	case 4:
+		var->red.offset = 0;
+		var->red.length = 4;
+		var->red.msb_right = 0;
+		var->green.offset = 0;
+		var->green.length = 4;
+		var->green.msb_right = 0;
+		var->blue.offset = 0;
+		var->blue.length = 4;
+		var->blue.msb_right = 0;
+		var->transp.offset = 0;
+		var->transp.length = 0;
+		var->transp.msb_right = 0;
+		break;
+#endif
+	case 8:
+	default:
+		var->red.offset = 0;
+		var->red.length = 8;
+		var->red.msb_right = 0;
+		var->green.offset = 0;
+		var->green.length = 8;
+		var->green.msb_right = 0;
+		var->blue.offset = 0;
+		var->blue.length = 8;
+		var->blue.msb_right = 0;
+		var->transp.offset = 0;
+		var->transp.length = 0;
+		var->transp.msb_right = 0;
+		var->bits_per_pixel = 8;
+		break;
+	}
+	var->nonstd = 0;
+	var->activate &= ~FB_ACTIVATE_MASK & FB_ACTIVATE_NOW;
+	var->accel_flags = 0;
+	var->sync = FB_SYNC_ON_GREEN;
+	var->vmode &= ~FB_VMODE_MASK & FB_VMODE_NONINTERLACED;
 
-	fix->smem_start = fb_start;	/* display memory base address, KM */
-	fix->smem_len = fb_size;
-	fix->type = FB_TYPE_PACKED_PIXELS;
-	fix->visual = FB_VISUAL_PSEUDOCOLOR;
-	fix->xpanstep = 0;
-	fix->ypanstep = 0;
-	fix->ywrapstep = 0;
-	fix->line_length = fb_line_length;
+	return 0;
 }
 
-static int maxinefb_get_fix(struct fb_fix_screeninfo *fix, int con,
+static int maxinefb_get_var(struct fb_var_screeninfo *var, int con,
 			    struct fb_info *info)
 {
 	struct maxinefb_par par;
-	maxinefb_get_par(&par);
-	maxinefb_encode_fix(fix, &par);
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+
+	if (con < 0) {
+		maxinefb_get_par(&par);
+		memset(var, 0, sizeof(struct fb_var_screeninfo));
+		return maxinefb_encode_var(var, &par);
+	} else
+		*var = disp->var;
+
 	return 0;
 }
 
-static int maxinefb_switch(int con, struct fb_info *info)
+static int maxinefb_set_var(struct fb_var_screeninfo *var, int con,
+			    struct fb_info *info)
 {
-	maxinefb_do_fb_set_var(&fb_display[con].var, 1);
-	currcon = con;
-	return 0;
+	struct maxinefb_par par;
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
+	int ret;
+
+	maxinefb_get_par(&par);
+	ret = maxinefb_encode_var(var, &par);
+	if (ret)
+		goto out;
+	disp->var = *var;
+
+	/* Set default colormap. */
+	ret = fb_alloc_cmap(&disp->cmap, 0, 0);
+	if (ret)
+		goto out;
+	do_install_cmap(con, ip);
+
+out:
+	return ret;
 }
 
-static void maxinefb_set_disp(int con)
+static int maxinefb_fb_update_var(int con, struct fb_info *info)
 {
-	struct fb_fix_screeninfo fix;
-	struct display *display;
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
+	struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
 
-	if (con >= 0)
-		display = &fb_display[con];
-	else
-		display = &disp;	/* used during initialization */
+	if (con == currcon)
+		maxinefbcon_cursor(disp, CM_ERASE, ip->cursor.x,
+				   ip->cursor.y);
+
+	return 0;
+}
+
+/* 0 unblanks, anything else blanks. */
 
-	maxinefb_get_fix(&fix, con, 0);
+static void maxinefb_blank(int blank, struct fb_info *info)
+{
+	struct maxinefb_info *ip = (struct maxinefb_info *)info;
 
-	display->screen_base = (char *)fix.smem_start;
-	display->visual = fix.visual;
-	display->type = fix.type;
-	display->type_aux = fix.type_aux;
-	display->ypanstep = fix.ypanstep;
-	display->ywrapstep = fix.ywrapstep;
-	display->line_length = fix.line_length;
-	display->next_line = fix.line_length;
-	display->can_soft_blank = 0;
-	display->inverse = 0;
-	display->scrollmode = SCROLL_YREDRAW;
-	display->dispsw = &fbcon_cfb8;
+	ims332_blank_screen(ip->ims332, !!blank);
 }
 
 static struct fb_ops maxinefb_ops = {
-	owner:		THIS_MODULE,
-	fb_get_fix:	maxinefb_get_fix,
-	fb_get_var:	maxinefb_get_var,
-	fb_set_var:	maxinefb_set_var,
-	fb_get_cmap:	maxinefb_get_cmap,
-	fb_set_cmap:	maxinefb_set_cmap,
+	.owner = THIS_MODULE,
+	.fb_get_fix = maxinefb_get_fix,
+	.fb_get_var = maxinefb_get_var,
+	.fb_set_var = maxinefb_set_var,
+	.fb_get_cmap = maxinefb_get_cmap,
+	.fb_set_cmap = maxinefb_set_cmap,
+	.fb_ioctl = maxinefb_ioctl
 };
 
 int __init maxinefb_init(void)
 {
-	unsigned long fboff;
-	int i;
-
-	/* Validate we're on the proper machine type */
-	if (mips_machtype != MACH_DS5000_XX) {
-		return -EINVAL;
+	/* Validate we're on the proper machine type. */
+	if (mips_machtype != MACH_DS5000_XX)
+		return -ENXIO;
+
+	my_info = (struct maxinefb_info *)kmalloc(sizeof(struct maxinefb_info), GFP_ATOMIC);
+	if (!my_info) {
+		printk(KERN_ERR DRIVER_DESCR ": can't alloc maxinefb_info\n");
+		return -ENOMEM;
 	}
+	memset(my_info, 0, sizeof(struct maxinefb_info));
 
-	printk(KERN_INFO "Maxinefb: Personal DECstation detected\n");
-	printk(KERN_INFO "Maxinefb: initializing onboard framebuffer\n");
+	/*
+	 * Let there be consoles..
+	 */
+	strcpy(my_info->info.modename, DRIVER_DESCRIPTION);
+	my_info->info.node = -1;
+	my_info->info.flags = FBINFO_FLAG_DEFAULT;
+	my_info->info.fbops = &maxinefb_ops;
+	my_info->info.disp = &my_info->disp;
+	my_info->info.changevar = NULL;
+	my_info->info.switch_con = &maxinefb_switch;
+	my_info->info.updatevar = &maxinefb_fb_update_var;
+	my_info->info.blank = &maxinefb_blank;
+
+	/* Initialize IMS G332 video controller. */
+	my_info->ims332 = (struct ims332_regs *)KSEG1ADDR(0x1c140000);
+	ims332_bootstrap(my_info->ims332);
+
+	/* Framebuffer memory, default resolution is 1024x768x8. */
+	my_info->fb_start = KSEG1ADDR(0x0a000000);
+	my_info->fb_size = 1024 * 1024;
+	memset((void *) my_info->fb_start, 0, my_info->fb_size);
 
-	/* Framebuffer display memory base address */
-	fb_start = DS5000_xx_ONBOARD_FBMEM_START;
+	maxine_cursor_init(my_info);
+	maxinefb_set_disp(&my_info->disp, currcon, my_info);
 
-	/* Clear screen */
-	for (fboff = fb_start; fboff < fb_start + 0x1ffff; fboff++)
-		*(volatile unsigned char *)fboff = 0x0;
-
-	/* erase hardware cursor */
-	for (i = 0; i < 512; i++) {
-		maxinefb_ims332_write_register(IMS332_REG_CURSOR_RAM + i,
-					       0);
-		/*
-		   if (i&0x8 == 0)
-		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0x0f);
-		   else
-		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0xf0);
-		 */
-	}
-
-	/* Fill in the available video resolution */
-	maxinefb_defined.xres = 1024;
-	maxinefb_defined.yres = 768;
-	maxinefb_defined.xres_virtual = 1024;
-	maxinefb_defined.yres_virtual = 768;
-	maxinefb_defined.bits_per_pixel = 8;
-
-	/* Let there be consoles... */
-
-	strcpy(fb_info.modename, "Maxine onboard graphics 1024x768x8");
-	/* fb_info.modename: maximum of 39 characters + trailing nullbyte, KM */
-	fb_info.changevar = NULL;
-	fb_info.node = -1;
-	fb_info.fbops = &maxinefb_ops;
-	fb_info.disp = &disp;
-	fb_info.switch_con = &maxinefb_switch;
-	fb_info.updatevar = &maxinefb_fb_update_var;
-	fb_info.blank = NULL;
-	fb_info.flags = FBINFO_FLAG_DEFAULT;
-	maxinefb_do_fb_set_var(&maxinefb_defined, 1);
-
-	maxinefb_get_var(&disp.var, -1, &fb_info);
-	maxinefb_set_disp(-1);
+	if (register_framebuffer(&my_info->info) < 0)
+		return -EINVAL;
 
-	if (register_framebuffer(&fb_info) < 0)
-		return 1;
+	printk(KERN_INFO "fb%d: %s\n", GET_FB_IDX(my_info->info.node),
+	       my_info->info.modename);
 
 	return 0;
 }
 
 static void __exit maxinefb_exit(void)
 {
-	unregister_framebuffer(&fb_info);
+	unregister_framebuffer(&my_info->info);
+	maxine_cursor_exit(my_info);
+	kfree(my_info);
 }
 
-#ifdef MODULE
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
 MODULE_LICENSE("GPL");
+#ifdef MODULE
 module_init(maxinefb_init);
-#endif
 module_exit(maxinefb_exit);
-
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)