File: /usr/src/linux/drivers/video/maxinefb.c

1     /*
2      *      linux/drivers/video/maxinefb.c
3      *
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.
8      *
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.
15      *
16      */
17     
18     /*
19      * Changes:
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)
23      *
24      */
25     
26     
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>
32     #include <linux/mm.h>
33     #include <linux/tty.h>
34     #include <linux/slab.h>
35     #include <linux/delay.h>
36     #include <linux/init.h>
37     #include <linux/fb.h>
38     #include <video/fbcon.h>
39     #include "maxinefb.h"
40     
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>
44     
45     #include <video/fbcon-mfb.h>
46     #include <video/fbcon-cfb2.h>
47     #include <video/fbcon-cfb4.h>
48     #include <video/fbcon-cfb8.h>
49     
50     #define arraysize(x)    (sizeof(x)/sizeof(*(x)))
51     
52     static struct display disp;
53     static struct fb_info fb_info;
54     
55     unsigned long fb_start, fb_size = 1024 * 768, fb_line_length = 1024;
56     unsigned long fb_regs;
57     unsigned char fb_bitmask;
58     
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 */
63     	0,			/* greyscale ? */
64     	{0, 0, 0},		/* R */
65     	{0, 0, 0},		/* G */
66     	{0, 0, 0},		/* B */
67     	{0, 0, 0},		/* transparency */
68     	0,			/* standard pixel format */
69     	FB_ACTIVATE_NOW,
70     	274, 195,		/* 14" monitor */
71     	FB_ACCEL_NONE,
72     	0L, 0L, 0L, 0L, 0L,
73     	0L, 0L, 0,		/* No sync info */
74     	FB_VMODE_NONINTERLACED,
75     	{0, 0, 0, 0, 0, 0}
76     };
77     
78     struct maxinefb_par {
79     };
80     
81     static int currcon = 0;
82     struct maxinefb_par current_par;
83     
84     /* Reference to machine type set in arch/mips/dec/prom/identify.c, KM */
85     extern unsigned long mips_machtype;
86     
87     
88     /* Handle the funny Inmos RamDAC/video controller ... */
89     
90     void maxinefb_ims332_write_register(int regno, register unsigned int val)
91     {
92     	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
93     	unsigned char *wptr;
94     
95     	wptr = regs + 0xa0000 + (regno << 4);
96     	*((volatile unsigned int *) (regs)) = (val >> 8) & 0xff00;
97     	*((volatile unsigned short *) (wptr)) = val;
98     }
99     
100     unsigned int maxinefb_ims332_read_register(int regno)
101     {
102     	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
103     	unsigned char *rptr;
104     	register unsigned int j, k;
105     
106     	rptr = regs + 0x80000 + (regno << 4);
107     	j = *((volatile unsigned short *) rptr);
108     	k = *((volatile unsigned short *) regs);
109     
110     	return (j & 0xffff) | ((k & 0xff00) << 8);
111     }
112     
113     
114     static void maxinefb_encode_var(struct fb_var_screeninfo *var,
115     				struct maxinefb_par *par)
116     {
117     	int i = 0;
118     	var->xres = 1024;
119     	var->yres = 768;
120     	var->xres_virtual = 1024;
121     	var->yres_virtual = 768;
122     	var->xoffset = 0;
123     	var->yoffset = 0;
124     	var->bits_per_pixel = 8;
125     	var->grayscale = 0;
126     	var->transp.offset = 0;
127     	var->transp.length = 0;
128     	var->transp.msb_right = 0;
129     	var->nonstd = 0;
130     	var->activate = 1;
131     	var->height = -1;
132     	var->width = -1;
133     	var->vmode = FB_VMODE_NONINTERLACED;
134     	var->pixclock = 0;
135     	var->sync = 0;
136     	var->left_margin = 0;
137     	var->right_margin = 0;
138     	var->upper_margin = 0;
139     	var->lower_margin = 0;
140     	var->hsync_len = 0;
141     	var->vsync_len = 0;
142     	for (i = 0; i < arraysize(var->reserved); i++)
143     		var->reserved[i] = 0;
144     }
145     
146     static void maxinefb_get_par(struct maxinefb_par *par)
147     {
148     	*par = current_par;
149     }
150     
151     static int maxinefb_fb_update_var(int con, struct fb_info *info)
152     {
153     	return 0;
154     }
155     
156     static int maxinefb_do_fb_set_var(struct fb_var_screeninfo *var,
157     				  int isactive)
158     {
159     	struct maxinefb_par par;
160     
161     	maxinefb_get_par(&par);
162     	maxinefb_encode_var(var, &par);
163     	return 0;
164     }
165     
166     
167     /* Get the palette */
168     
169     static int maxinefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
170     			     struct fb_info *info)
171     {
172     	unsigned int i;
173     	unsigned long hw_colorvalue = 0;	/* raw color value from the register */
174     	unsigned int length;
175     
176     	if (((cmap->start) + (cmap->len)) >= 256) {
177     		length = 256 - (cmap->start);
178     	} else {
179     		length = cmap->len;
180     	}
181     	for (i = 0; i < length; i++) {
182     		hw_colorvalue =
183     		    maxinefb_ims332_read_register(IMS332_REG_COLOR_PALETTE
184     						  + cmap->start + i);
185     		(cmap->red[i]) = ((hw_colorvalue & 0x0000ff));
186     		(cmap->green[i]) = ((hw_colorvalue & 0x00ff00) >> 8);
187     		(cmap->blue[i]) = ((hw_colorvalue & 0xff0000) >> 16);
188     
189     	}
190     	return 0;
191     }
192     
193     
194     /* Set the palette */
195     
196     static int maxinefb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
197     			     struct fb_info *info)
198     {
199     	unsigned int i;
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;
204     	unsigned int length;
205     
206     	hw_colorvalue = 0;
207     	if (((cmap->start) + (cmap->len)) >= 256) {
208     		length = 256 - (cmap->start);
209     	} else {
210     		length = cmap->len;
211     	}
212     
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 */
217     
218     		hw_colorvalue =
219     		    (cmap_blue << 16) + (cmap_green << 8) + (cmap_red);
220     		maxinefb_ims332_write_register(IMS332_REG_COLOR_PALETTE +
221     					       cmap->start + i,
222     					       hw_colorvalue);
223     	}
224     	return 0;
225     }
226     
227     static int maxinefb_get_var(struct fb_var_screeninfo *var, int con,
228     			    struct fb_info *info)
229     {
230     	struct maxinefb_par par;
231     	if (con == -1) {
232     		maxinefb_get_par(&par);
233     		maxinefb_encode_var(var, &par);
234     	} else
235     		*var = fb_display[con].var;
236     	return 0;
237     }
238     
239     
240     static int maxinefb_set_var(struct fb_var_screeninfo *var, int con,
241     			    struct fb_info *info)
242     {
243     	int err;
244     
245     	if ((err = maxinefb_do_fb_set_var(var, 1)))
246     		return err;
247     	return 0;
248     }
249     static void maxinefb_encode_fix(struct fb_fix_screeninfo *fix,
250     				struct maxinefb_par *par)
251     {
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 */
255     
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;
260     	fix->xpanstep = 0;
261     	fix->ypanstep = 0;
262     	fix->ywrapstep = 0;
263     	fix->line_length = fb_line_length;
264     }
265     
266     static int maxinefb_get_fix(struct fb_fix_screeninfo *fix, int con,
267     			    struct fb_info *info)
268     {
269     	struct maxinefb_par par;
270     	maxinefb_get_par(&par);
271     	maxinefb_encode_fix(fix, &par);
272     	return 0;
273     }
274     
275     static int maxinefb_switch(int con, struct fb_info *info)
276     {
277     	maxinefb_do_fb_set_var(&fb_display[con].var, 1);
278     	currcon = con;
279     	return 0;
280     }
281     
282     static void maxinefb_set_disp(int con)
283     {
284     	struct fb_fix_screeninfo fix;
285     	struct display *display;
286     
287     	if (con >= 0)
288     		display = &fb_display[con];
289     	else
290     		display = &disp;	/* used during initialization */
291     
292     	maxinefb_get_fix(&fix, con, 0);
293     
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     
305     	display->dispsw = &fbcon_cfb8;
306     }
307     
308     static struct fb_ops maxinefb_ops = {
309     	owner:		THIS_MODULE,
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,
315     };
316     
317     int __init maxinefb_init(void)
318     {
319     	volatile unsigned char *fboff;
320     	int i;
321     
322     	/* Validate we're on the proper machine type */
323     	if (mips_machtype != MACH_DS5000_XX) {
324     		return -EINVAL;
325     	}
326     
327     	printk(KERN_INFO "Maxinefb: Personal DECstation detected\n");
328     	printk(KERN_INFO "Maxinefb: initializing onboard framebuffer\n");
329     
330     	/* Framebuffer display memory base address */
331     	fb_start = DS5000_xx_ONBOARD_FBMEM_START;
332     
333     	/* Clear screen */
334     	for (fboff = fb_start; fboff < fb_start + 0x1ffff; fboff++)
335     		*fboff = 0x0;
336     
337     	/* erase hardware cursor */
338     	for (i = 0; i < 512; i++) {
339     		maxinefb_ims332_write_register(IMS332_REG_CURSOR_RAM + i,
340     					       0);
341     		/*
342     		   if (i&0x8 == 0)
343     		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0x0f);
344     		   else
345     		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0xf0);
346     		 */
347     	}
348     
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;
355     
356     	/* Let there be consoles... */
357     
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;
361     	fb_info.node = -1;
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);
369     
370     	maxinefb_get_var(&disp.var, -1, &fb_info);
371     	maxinefb_set_disp(-1);
372     
373     	if (register_framebuffer(&fb_info) < 0)
374     		return 1;
375     
376     	return 0;
377     }
378     
379     static void __exit maxinefb_exit(void)
380     {
381     	unregister_framebuffer(&fb_info);
382     }
383     
384     #ifdef MODULE
385     MODULE_LICENSE("GPL");
386     module_init(maxinefb_init);
387     #endif
388     module_exit(maxinefb_exit);
389     
390