2 * linux/drivers/video/68328fb.c -- Low level implementation of the
3 * mc68x328 LCD frame buffer device
5 * Copyright (C) 2003 Georges Menie
7 * This driver assumes an already configured controller (e.g. from config.c)
8 * Keep the code clean of board specific initialization.
10 * This code has not been tested with colors, colormap management functions
11 * are minimal (no colormap data written to the 68328 registers...)
13 * initial version of this driver:
14 * Copyright (C) 1998,1999 Kenneth Albanowski <kjahds@kjahds.com>,
15 * The Silver Hammer Group, Ltd.
17 * this version is based on :
19 * linux/drivers/video/vfb.c -- Virtual frame buffer device
21 * Copyright (C) 2002 James Simmons
23 * Copyright (C) 1997 Geert Uytterhoeven
25 * This file is subject to the terms and conditions of the GNU General Public
26 * License. See the file COPYING in the main directory of this archive for
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/string.h>
35 #include <linux/vmalloc.h>
36 #include <linux/delay.h>
37 #include <linux/interrupt.h>
38 #include <asm/uaccess.h>
40 #include <linux/init.h>
42 #if defined(CONFIG_M68VZ328)
43 #include <asm/MC68VZ328.h>
44 #elif defined(CONFIG_M68EZ328)
45 #include <asm/MC68EZ328.h>
46 #elif defined(CONFIG_M68328)
47 #include <asm/MC68328.h>
49 #error wrong architecture for the MC68x328 frame buffer device
52 #if defined(CONFIG_FB_68328_INVERT)
53 #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO01
55 #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO10
58 static u_long videomemory
;
59 static u_long videomemorysize
;
61 static struct fb_info fb_info
;
62 static u32 mc68x328fb_pseudo_palette
[16];
64 static struct fb_var_screeninfo mc68x328fb_default __initdata
= {
68 .activate
= FB_ACTIVATE_TEST
,
78 .vmode
= FB_VMODE_NONINTERLACED
,
81 static struct fb_fix_screeninfo mc68x328fb_fix __initdata
= {
83 .type
= FB_TYPE_PACKED_PIXELS
,
87 .accel
= FB_ACCEL_NONE
,
91 * Interface used by the world
93 int mc68x328fb_init(void);
94 int mc68x328fb_setup(char *);
96 static int mc68x328fb_check_var(struct fb_var_screeninfo
*var
,
97 struct fb_info
*info
);
98 static int mc68x328fb_set_par(struct fb_info
*info
);
99 static int mc68x328fb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
100 u_int transp
, struct fb_info
*info
);
101 static int mc68x328fb_pan_display(struct fb_var_screeninfo
*var
,
102 struct fb_info
*info
);
103 static int mc68x328fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
);
105 static struct fb_ops mc68x328fb_ops
= {
106 .fb_check_var
= mc68x328fb_check_var
,
107 .fb_set_par
= mc68x328fb_set_par
,
108 .fb_setcolreg
= mc68x328fb_setcolreg
,
109 .fb_pan_display
= mc68x328fb_pan_display
,
110 .fb_fillrect
= cfb_fillrect
,
111 .fb_copyarea
= cfb_copyarea
,
112 .fb_imageblit
= cfb_imageblit
,
113 .fb_mmap
= mc68x328fb_mmap
,
120 static u_long
get_line_length(int xres_virtual
, int bpp
)
124 length
= xres_virtual
* bpp
;
125 length
= (length
+ 31) & ~31;
131 * Setting the video mode has been split into two parts.
132 * First part, xxxfb_check_var, must not write anything
133 * to hardware, it should only verify and adjust var.
134 * This means it doesn't alter par but it does use hardware
135 * data from it to check this var.
138 static int mc68x328fb_check_var(struct fb_var_screeninfo
*var
,
139 struct fb_info
*info
)
144 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
145 * as FB_VMODE_SMOOTH_XPAN is only used internally
148 if (var
->vmode
& FB_VMODE_CONUPDATE
) {
149 var
->vmode
|= FB_VMODE_YWRAP
;
150 var
->xoffset
= info
->var
.xoffset
;
151 var
->yoffset
= info
->var
.yoffset
;
155 * Some very basic checks
161 if (var
->xres
> var
->xres_virtual
)
162 var
->xres_virtual
= var
->xres
;
163 if (var
->yres
> var
->yres_virtual
)
164 var
->yres_virtual
= var
->yres
;
165 if (var
->bits_per_pixel
<= 1)
166 var
->bits_per_pixel
= 1;
167 else if (var
->bits_per_pixel
<= 8)
168 var
->bits_per_pixel
= 8;
169 else if (var
->bits_per_pixel
<= 16)
170 var
->bits_per_pixel
= 16;
171 else if (var
->bits_per_pixel
<= 24)
172 var
->bits_per_pixel
= 24;
173 else if (var
->bits_per_pixel
<= 32)
174 var
->bits_per_pixel
= 32;
178 if (var
->xres_virtual
< var
->xoffset
+ var
->xres
)
179 var
->xres_virtual
= var
->xoffset
+ var
->xres
;
180 if (var
->yres_virtual
< var
->yoffset
+ var
->yres
)
181 var
->yres_virtual
= var
->yoffset
+ var
->yres
;
187 get_line_length(var
->xres_virtual
, var
->bits_per_pixel
);
188 if (line_length
* var
->yres_virtual
> videomemorysize
)
192 * Now that we checked it we alter var. The reason being is that the video
193 * mode passed in might not work but slight changes to it might make it
194 * work. This way we let the user know what is acceptable.
196 switch (var
->bits_per_pixel
) {
200 var
->green
.offset
= 0;
201 var
->green
.length
= 1;
202 var
->blue
.offset
= 0;
203 var
->blue
.length
= 1;
204 var
->transp
.offset
= 0;
205 var
->transp
.length
= 0;
210 var
->green
.offset
= 0;
211 var
->green
.length
= 8;
212 var
->blue
.offset
= 0;
213 var
->blue
.length
= 8;
214 var
->transp
.offset
= 0;
215 var
->transp
.length
= 0;
217 case 16: /* RGBA 5551 */
218 if (var
->transp
.length
) {
221 var
->green
.offset
= 5;
222 var
->green
.length
= 5;
223 var
->blue
.offset
= 10;
224 var
->blue
.length
= 5;
225 var
->transp
.offset
= 15;
226 var
->transp
.length
= 1;
227 } else { /* RGB 565 */
230 var
->green
.offset
= 5;
231 var
->green
.length
= 6;
232 var
->blue
.offset
= 11;
233 var
->blue
.length
= 5;
234 var
->transp
.offset
= 0;
235 var
->transp
.length
= 0;
238 case 24: /* RGB 888 */
241 var
->green
.offset
= 8;
242 var
->green
.length
= 8;
243 var
->blue
.offset
= 16;
244 var
->blue
.length
= 8;
245 var
->transp
.offset
= 0;
246 var
->transp
.length
= 0;
248 case 32: /* RGBA 8888 */
251 var
->green
.offset
= 8;
252 var
->green
.length
= 8;
253 var
->blue
.offset
= 16;
254 var
->blue
.length
= 8;
255 var
->transp
.offset
= 24;
256 var
->transp
.length
= 8;
259 var
->red
.msb_right
= 0;
260 var
->green
.msb_right
= 0;
261 var
->blue
.msb_right
= 0;
262 var
->transp
.msb_right
= 0;
267 /* This routine actually sets the video mode. It's in here where we
268 * the hardware state info->par and fix which can be affected by the
269 * change in par. For this driver it doesn't do much.
271 static int mc68x328fb_set_par(struct fb_info
*info
)
273 info
->fix
.line_length
= get_line_length(info
->var
.xres_virtual
,
274 info
->var
.bits_per_pixel
);
279 * Set a single color register. The values supplied are already
280 * rounded down to the hardware's capabilities (according to the
281 * entries in the var structure). Return != 0 for invalid regno.
284 static int mc68x328fb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
285 u_int transp
, struct fb_info
*info
)
287 if (regno
>= 256) /* no. of hw registers */
290 * Program hardware... do anything you want with transp
293 /* grayscale works only partially under directcolor */
294 if (info
->var
.grayscale
) {
295 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
297 (red
* 77 + green
* 151 + blue
* 28) >> 8;
301 * var->{color}.offset contains start of bitfield
302 * var->{color}.length contains length of bitfield
303 * {hardwarespecific} contains width of RAMDAC
304 * cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
305 * RAMDAC[X] is programmed to (red, green, blue)
308 * uses offset = 0 && length = RAMDAC register width.
309 * var->{color}.offset is 0
310 * var->{color}.length contains width of DAC
312 * RAMDAC[X] is programmed to (red, green, blue)
314 * does not use DAC. Usually 3 are present.
315 * var->{color}.offset contains start of bitfield
316 * var->{color}.length contains length of bitfield
317 * cmap is programmed to (red << red.offset) | (green << green.offset) |
318 * (blue << blue.offset) | (transp << transp.offset)
319 * RAMDAC does not exist
321 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
322 switch (info
->fix
.visual
) {
323 case FB_VISUAL_TRUECOLOR
:
324 case FB_VISUAL_PSEUDOCOLOR
:
325 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
326 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
327 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
328 transp
= CNVT_TOHW(transp
, info
->var
.transp
.length
);
330 case FB_VISUAL_DIRECTCOLOR
:
331 red
= CNVT_TOHW(red
, 8); /* expect 8 bit DAC */
332 green
= CNVT_TOHW(green
, 8);
333 blue
= CNVT_TOHW(blue
, 8);
334 /* hey, there is bug in transp handling... */
335 transp
= CNVT_TOHW(transp
, 8);
339 /* Truecolor has hardware independent palette */
340 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
346 v
= (red
<< info
->var
.red
.offset
) |
347 (green
<< info
->var
.green
.offset
) |
348 (blue
<< info
->var
.blue
.offset
) |
349 (transp
<< info
->var
.transp
.offset
);
350 switch (info
->var
.bits_per_pixel
) {
354 ((u32
*) (info
->pseudo_palette
))[regno
] = v
;
358 ((u32
*) (info
->pseudo_palette
))[regno
] = v
;
367 * Pan or Wrap the Display
369 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
372 static int mc68x328fb_pan_display(struct fb_var_screeninfo
*var
,
373 struct fb_info
*info
)
375 if (var
->vmode
& FB_VMODE_YWRAP
) {
377 || var
->yoffset
>= info
->var
.yres_virtual
381 if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
||
382 var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
385 info
->var
.xoffset
= var
->xoffset
;
386 info
->var
.yoffset
= var
->yoffset
;
387 if (var
->vmode
& FB_VMODE_YWRAP
)
388 info
->var
.vmode
|= FB_VMODE_YWRAP
;
390 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
395 * Most drivers don't need their own mmap function
398 static int mc68x328fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
401 /* this is uClinux (no MMU) specific code */
403 vma
->vm_flags
|= VM_DONTEXPAND
| VM_DONTDUMP
;
404 vma
->vm_start
= videomemory
;
412 int __init
mc68x328fb_setup(char *options
)
418 if (!options
|| !*options
)
421 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
424 if (!strncmp(this_opt
, "disable", 7))
425 mc68x328fb_enable
= 0;
435 int __init
mc68x328fb_init(void)
440 if (fb_get_options("68328fb", &option
))
442 mc68x328fb_setup(option
);
445 * initialize the default mode from the LCD controller registers
447 mc68x328fb_default
.xres
= LXMAX
;
448 mc68x328fb_default
.yres
= LYMAX
+1;
449 mc68x328fb_default
.xres_virtual
= mc68x328fb_default
.xres
;
450 mc68x328fb_default
.yres_virtual
= mc68x328fb_default
.yres
;
451 mc68x328fb_default
.bits_per_pixel
= 1 + (LPICF
& 0x01);
453 videomemorysize
= (mc68x328fb_default
.xres_virtual
+7) / 8 *
454 mc68x328fb_default
.yres_virtual
* mc68x328fb_default
.bits_per_pixel
;
456 fb_info
.screen_base
= (void *)videomemory
;
457 fb_info
.fbops
= &mc68x328fb_ops
;
458 fb_info
.var
= mc68x328fb_default
;
459 fb_info
.fix
= mc68x328fb_fix
;
460 fb_info
.fix
.smem_start
= videomemory
;
461 fb_info
.fix
.smem_len
= videomemorysize
;
462 fb_info
.fix
.line_length
=
463 get_line_length(mc68x328fb_default
.xres_virtual
, mc68x328fb_default
.bits_per_pixel
);
464 fb_info
.fix
.visual
= (mc68x328fb_default
.bits_per_pixel
) == 1 ?
465 MC68X328FB_MONO_VISUAL
: FB_VISUAL_PSEUDOCOLOR
;
466 if (fb_info
.var
.bits_per_pixel
== 1) {
467 fb_info
.var
.red
.length
= fb_info
.var
.green
.length
= fb_info
.var
.blue
.length
= 1;
468 fb_info
.var
.red
.offset
= fb_info
.var
.green
.offset
= fb_info
.var
.blue
.offset
= 0;
470 fb_info
.pseudo_palette
= &mc68x328fb_pseudo_palette
;
471 fb_info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
473 if (fb_alloc_cmap(&fb_info
.cmap
, 256, 0))
476 if (register_framebuffer(&fb_info
) < 0) {
477 fb_dealloc_cmap(&fb_info
.cmap
);
481 fb_info(&fb_info
, "%s frame buffer device\n", fb_info
.fix
.id
);
482 fb_info(&fb_info
, "%dx%dx%d at 0x%08lx\n",
483 mc68x328fb_default
.xres_virtual
,
484 mc68x328fb_default
.yres_virtual
,
485 1 << mc68x328fb_default
.bits_per_pixel
, videomemory
);
490 module_init(mc68x328fb_init
);
494 static void __exit
mc68x328fb_cleanup(void)
496 unregister_framebuffer(&fb_info
);
497 fb_dealloc_cmap(&fb_info
.cmap
);
500 module_exit(mc68x328fb_cleanup
);
502 MODULE_LICENSE("GPL");