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/slab.h>
36 #include <linux/vmalloc.h>
37 #include <linux/delay.h>
38 #include <linux/interrupt.h>
39 #include <asm/uaccess.h>
41 #include <linux/init.h>
43 #if defined(CONFIG_M68VZ328)
44 #include <asm/MC68VZ328.h>
45 #elif defined(CONFIG_M68EZ328)
46 #include <asm/MC68EZ328.h>
47 #elif defined(CONFIG_M68328)
48 #include <asm/MC68328.h>
50 #error wrong architecture for the MC68x328 frame buffer device
53 #if defined(CONFIG_FB_68328_INVERT)
54 #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO01
56 #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO10
59 static u_long videomemory;
60 static u_long videomemorysize;
62 static struct fb_info fb_info;
63 static u32 mc68x328fb_pseudo_palette[17];
65 static struct fb_var_screeninfo mc68x328fb_default __initdata = {
69 .activate = FB_ACTIVATE_TEST,
79 .vmode = FB_VMODE_NONINTERLACED,
82 static struct fb_fix_screeninfo mc68x328fb_fix __initdata = {
84 .type = FB_TYPE_PACKED_PIXELS,
88 .accel = FB_ACCEL_NONE,
92 * Interface used by the world
94 int mc68x328fb_init(void);
95 int mc68x328fb_setup(char *);
97 static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
98 struct fb_info *info);
99 static int mc68x328fb_set_par(struct fb_info *info);
100 static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
101 u_int transp, struct fb_info *info);
102 static int mc68x328fb_pan_display(struct fb_var_screeninfo *var,
103 struct fb_info *info);
104 static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma);
106 static struct fb_ops mc68x328fb_ops = {
107 .fb_check_var = mc68x328fb_check_var,
108 .fb_set_par = mc68x328fb_set_par,
109 .fb_setcolreg = mc68x328fb_setcolreg,
110 .fb_pan_display = mc68x328fb_pan_display,
111 .fb_fillrect = cfb_fillrect,
112 .fb_copyarea = cfb_copyarea,
113 .fb_imageblit = cfb_imageblit,
114 .fb_mmap = mc68x328fb_mmap,
121 static u_long get_line_length(int xres_virtual, int bpp)
125 length = xres_virtual * bpp;
126 length = (length + 31) & ~31;
132 * Setting the video mode has been split into two parts.
133 * First part, xxxfb_check_var, must not write anything
134 * to hardware, it should only verify and adjust var.
135 * This means it doesn't alter par but it does use hardware
136 * data from it to check this var.
139 static int mc68x328fb_check_var(struct fb_var_screeninfo *var,
140 struct fb_info *info)
145 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
146 * as FB_VMODE_SMOOTH_XPAN is only used internally
149 if (var->vmode & FB_VMODE_CONUPDATE) {
150 var->vmode |= FB_VMODE_YWRAP;
151 var->xoffset = info->var.xoffset;
152 var->yoffset = info->var.yoffset;
156 * Some very basic checks
162 if (var->xres > var->xres_virtual)
163 var->xres_virtual = var->xres;
164 if (var->yres > var->yres_virtual)
165 var->yres_virtual = var->yres;
166 if (var->bits_per_pixel <= 1)
167 var->bits_per_pixel = 1;
168 else if (var->bits_per_pixel <= 8)
169 var->bits_per_pixel = 8;
170 else if (var->bits_per_pixel <= 16)
171 var->bits_per_pixel = 16;
172 else if (var->bits_per_pixel <= 24)
173 var->bits_per_pixel = 24;
174 else if (var->bits_per_pixel <= 32)
175 var->bits_per_pixel = 32;
179 if (var->xres_virtual < var->xoffset + var->xres)
180 var->xres_virtual = var->xoffset + var->xres;
181 if (var->yres_virtual < var->yoffset + var->yres)
182 var->yres_virtual = var->yoffset + var->yres;
188 get_line_length(var->xres_virtual, var->bits_per_pixel);
189 if (line_length * var->yres_virtual > videomemorysize)
193 * Now that we checked it we alter var. The reason being is that the video
194 * mode passed in might not work but slight changes to it might make it
195 * work. This way we let the user know what is acceptable.
197 switch (var->bits_per_pixel) {
201 var->green.offset = 0;
202 var->green.length = 1;
203 var->blue.offset = 0;
204 var->blue.length = 1;
205 var->transp.offset = 0;
206 var->transp.length = 0;
211 var->green.offset = 0;
212 var->green.length = 8;
213 var->blue.offset = 0;
214 var->blue.length = 8;
215 var->transp.offset = 0;
216 var->transp.length = 0;
218 case 16: /* RGBA 5551 */
219 if (var->transp.length) {
222 var->green.offset = 5;
223 var->green.length = 5;
224 var->blue.offset = 10;
225 var->blue.length = 5;
226 var->transp.offset = 15;
227 var->transp.length = 1;
228 } else { /* RGB 565 */
231 var->green.offset = 5;
232 var->green.length = 6;
233 var->blue.offset = 11;
234 var->blue.length = 5;
235 var->transp.offset = 0;
236 var->transp.length = 0;
239 case 24: /* RGB 888 */
242 var->green.offset = 8;
243 var->green.length = 8;
244 var->blue.offset = 16;
245 var->blue.length = 8;
246 var->transp.offset = 0;
247 var->transp.length = 0;
249 case 32: /* RGBA 8888 */
252 var->green.offset = 8;
253 var->green.length = 8;
254 var->blue.offset = 16;
255 var->blue.length = 8;
256 var->transp.offset = 24;
257 var->transp.length = 8;
260 var->red.msb_right = 0;
261 var->green.msb_right = 0;
262 var->blue.msb_right = 0;
263 var->transp.msb_right = 0;
268 /* This routine actually sets the video mode. It's in here where we
269 * the hardware state info->par and fix which can be affected by the
270 * change in par. For this driver it doesn't do much.
272 static int mc68x328fb_set_par(struct fb_info *info)
274 info->fix.line_length = get_line_length(info->var.xres_virtual,
275 info->var.bits_per_pixel);
280 * Set a single color register. The values supplied are already
281 * rounded down to the hardware's capabilities (according to the
282 * entries in the var structure). Return != 0 for invalid regno.
285 static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
286 u_int transp, struct fb_info *info)
288 if (regno >= 256) /* no. of hw registers */
291 * Program hardware... do anything you want with transp
294 /* grayscale works only partially under directcolor */
295 if (info->var.grayscale) {
296 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
298 (red * 77 + green * 151 + blue * 28) >> 8;
302 * var->{color}.offset contains start of bitfield
303 * var->{color}.length contains length of bitfield
304 * {hardwarespecific} contains width of RAMDAC
305 * cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
306 * RAMDAC[X] is programmed to (red, green, blue)
309 * uses offset = 0 && length = RAMDAC register width.
310 * var->{color}.offset is 0
311 * var->{color}.length contains widht of DAC
313 * RAMDAC[X] is programmed to (red, green, blue)
315 * does not use DAC. Usually 3 are present.
316 * var->{color}.offset contains start of bitfield
317 * var->{color}.length contains length of bitfield
318 * cmap is programmed to (red << red.offset) | (green << green.offset) |
319 * (blue << blue.offset) | (transp << transp.offset)
320 * RAMDAC does not exist
322 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
323 switch (info->fix.visual) {
324 case FB_VISUAL_TRUECOLOR:
325 case FB_VISUAL_PSEUDOCOLOR:
326 red = CNVT_TOHW(red, info->var.red.length);
327 green = CNVT_TOHW(green, info->var.green.length);
328 blue = CNVT_TOHW(blue, info->var.blue.length);
329 transp = CNVT_TOHW(transp, info->var.transp.length);
331 case FB_VISUAL_DIRECTCOLOR:
332 red = CNVT_TOHW(red, 8); /* expect 8 bit DAC */
333 green = CNVT_TOHW(green, 8);
334 blue = CNVT_TOHW(blue, 8);
335 /* hey, there is bug in transp handling... */
336 transp = CNVT_TOHW(transp, 8);
340 /* Truecolor has hardware independent palette */
341 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
347 v = (red << info->var.red.offset) |
348 (green << info->var.green.offset) |
349 (blue << info->var.blue.offset) |
350 (transp << info->var.transp.offset);
351 switch (info->var.bits_per_pixel) {
355 ((u32 *) (info->pseudo_palette))[regno] = v;
359 ((u32 *) (info->pseudo_palette))[regno] = v;
368 * Pan or Wrap the Display
370 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
373 static int mc68x328fb_pan_display(struct fb_var_screeninfo *var,
374 struct fb_info *info)
376 if (var->vmode & FB_VMODE_YWRAP) {
378 || var->yoffset >= info->var.yres_virtual
382 if (var->xoffset + var->xres > info->var.xres_virtual ||
383 var->yoffset + var->yres > info->var.yres_virtual)
386 info->var.xoffset = var->xoffset;
387 info->var.yoffset = var->yoffset;
388 if (var->vmode & FB_VMODE_YWRAP)
389 info->var.vmode |= FB_VMODE_YWRAP;
391 info->var.vmode &= ~FB_VMODE_YWRAP;
396 * Most drivers don't need their own mmap function
399 static int mc68x328fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
402 /* this is uClinux (no MMU) specific code */
404 vma->vm_flags |= VM_RESERVED;
405 vma->vm_start = videomemory;
413 int __init mc68x328fb_setup(char *options)
419 if (!options || !*options)
422 while ((this_opt = strsep(&options, ",")) != NULL) {
425 if (!strncmp(this_opt, "disable", 7))
426 mc68x328fb_enable = 0;
436 int __init mc68x328fb_init(void)
441 if (fb_get_options("68328fb", &option))
443 mc68x328fb_setup(option);
446 * initialize the default mode from the LCD controller registers
448 mc68x328fb_default.xres = LXMAX;
449 mc68x328fb_default.yres = LYMAX+1;
450 mc68x328fb_default.xres_virtual = mc68x328fb_default.xres;
451 mc68x328fb_default.yres_virtual = mc68x328fb_default.yres;
452 mc68x328fb_default.bits_per_pixel = 1 + (LPICF & 0x01);
454 videomemorysize = (mc68x328fb_default.xres_virtual+7) / 8 *
455 mc68x328fb_default.yres_virtual * mc68x328fb_default.bits_per_pixel;
457 fb_info.screen_base = (void *)videomemory;
458 fb_info.fbops = &mc68x328fb_ops;
459 fb_info.var = mc68x328fb_default;
460 fb_info.fix = mc68x328fb_fix;
461 fb_info.fix.smem_start = videomemory;
462 fb_info.fix.smem_len = videomemorysize;
463 fb_info.fix.line_length =
464 get_line_length(mc68x328fb_default.xres_virtual, mc68x328fb_default.bits_per_pixel);
465 fb_info.fix.visual = (mc68x328fb_default.bits_per_pixel) == 1 ?
466 MC68X328FB_MONO_VISUAL : FB_VISUAL_PSEUDOCOLOR;
467 if (fb_info.var.bits_per_pixel == 1) {
468 fb_info.var.red.length = fb_info.var.green.length = fb_info.var.blue.length = 1;
469 fb_info.var.red.offset = fb_info.var.green.offset = fb_info.var.blue.offset = 0;
471 fb_info.pseudo_palette = &mc68x328fb_pseudo_palette;
472 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
474 fb_alloc_cmap(&fb_info.cmap, 256, 0);
476 if (register_framebuffer(&fb_info) < 0) {
481 "fb%d: %s frame buffer device\n", fb_info.node, fb_info.fix.id);
483 "fb%d: %dx%dx%d at 0x%08lx\n", fb_info.node,
484 mc68x328fb_default.xres_virtual, 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);
499 module_exit(mc68x328fb_cleanup);
501 MODULE_LICENSE("GPL");