]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/video/68328fb.c -- Low level implementation of the | |
3 | * mc68x328 LCD frame buffer device | |
4 | * | |
5 | * Copyright (C) 2003 Georges Menie | |
6 | * | |
7 | * This driver assumes an already configured controller (e.g. from config.c) | |
8 | * Keep the code clean of board specific initialization. | |
9 | * | |
10 | * This code has not been tested with colors, colormap management functions | |
11 | * are minimal (no colormap data written to the 68328 registers...) | |
12 | * | |
13 | * initial version of this driver: | |
14 | * Copyright (C) 1998,1999 Kenneth Albanowski <[email protected]>, | |
15 | * The Silver Hammer Group, Ltd. | |
16 | * | |
17 | * this version is based on : | |
18 | * | |
19 | * linux/drivers/video/vfb.c -- Virtual frame buffer device | |
20 | * | |
21 | * Copyright (C) 2002 James Simmons | |
22 | * | |
23 | * Copyright (C) 1997 Geert Uytterhoeven | |
24 | * | |
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 | |
27 | * more details. | |
28 | */ | |
29 | ||
30 | #include <linux/module.h> | |
31 | #include <linux/kernel.h> | |
32 | #include <linux/errno.h> | |
33 | #include <linux/string.h> | |
34 | #include <linux/mm.h> | |
35 | #include <linux/tty.h> | |
36 | #include <linux/slab.h> | |
37 | #include <linux/vmalloc.h> | |
38 | #include <linux/delay.h> | |
39 | #include <linux/interrupt.h> | |
40 | #include <asm/uaccess.h> | |
41 | #include <linux/fb.h> | |
42 | #include <linux/init.h> | |
43 | ||
44 | #if defined(CONFIG_M68VZ328) | |
45 | #include <asm/MC68VZ328.h> | |
46 | #elif defined(CONFIG_M68EZ328) | |
47 | #include <asm/MC68EZ328.h> | |
48 | #elif defined(CONFIG_M68328) | |
49 | #include <asm/MC68328.h> | |
50 | #else | |
51 | #error wrong architecture for the MC68x328 frame buffer device | |
52 | #endif | |
53 | ||
54 | #if defined(CONFIG_FB_68328_INVERT) | |
55 | #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO01 | |
56 | #else | |
57 | #define MC68X328FB_MONO_VISUAL FB_VISUAL_MONO10 | |
58 | #endif | |
59 | ||
60 | static u_long videomemory; | |
61 | static u_long videomemorysize; | |
62 | ||
63 | static struct fb_info fb_info; | |
64 | static u32 mc68x328fb_pseudo_palette[17]; | |
65 | ||
66 | static struct fb_var_screeninfo mc68x328fb_default __initdata = { | |
67 | .red = { 0, 8, 0 }, | |
68 | .green = { 0, 8, 0 }, | |
69 | .blue = { 0, 8, 0 }, | |
70 | .activate = FB_ACTIVATE_TEST, | |
71 | .height = -1, | |
72 | .width = -1, | |
73 | .pixclock = 20000, | |
74 | .left_margin = 64, | |
75 | .right_margin = 64, | |
76 | .upper_margin = 32, | |
77 | .lower_margin = 32, | |
78 | .hsync_len = 64, | |
79 | .vsync_len = 2, | |
80 | .vmode = FB_VMODE_NONINTERLACED, | |
81 | }; | |
82 | ||
83 | static struct fb_fix_screeninfo mc68x328fb_fix __initdata = { | |
84 | .id = "68328fb", | |
85 | .type = FB_TYPE_PACKED_PIXELS, | |
86 | .xpanstep = 1, | |
87 | .ypanstep = 1, | |
88 | .ywrapstep = 1, | |
89 | .accel = FB_ACCEL_NONE, | |
90 | }; | |
91 | ||
92 | /* | |
93 | * Interface used by the world | |
94 | */ | |
95 | int mc68x328fb_init(void); | |
96 | int mc68x328fb_setup(char *); | |
97 | ||
98 | static int mc68x328fb_check_var(struct fb_var_screeninfo *var, | |
99 | struct fb_info *info); | |
100 | static int mc68x328fb_set_par(struct fb_info *info); | |
101 | static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, | |
102 | u_int transp, struct fb_info *info); | |
103 | static int mc68x328fb_pan_display(struct fb_var_screeninfo *var, | |
104 | struct fb_info *info); | |
105 | static int mc68x328fb_mmap(struct fb_info *info, struct file *file, | |
106 | struct vm_area_struct *vma); | |
107 | ||
108 | static struct fb_ops mc68x328fb_ops = { | |
109 | .fb_check_var = mc68x328fb_check_var, | |
110 | .fb_set_par = mc68x328fb_set_par, | |
111 | .fb_setcolreg = mc68x328fb_setcolreg, | |
112 | .fb_pan_display = mc68x328fb_pan_display, | |
113 | .fb_fillrect = cfb_fillrect, | |
114 | .fb_copyarea = cfb_copyarea, | |
115 | .fb_imageblit = cfb_imageblit, | |
1da177e4 LT |
116 | .fb_mmap = mc68x328fb_mmap, |
117 | }; | |
118 | ||
119 | /* | |
120 | * Internal routines | |
121 | */ | |
122 | ||
123 | static u_long get_line_length(int xres_virtual, int bpp) | |
124 | { | |
125 | u_long length; | |
126 | ||
127 | length = xres_virtual * bpp; | |
128 | length = (length + 31) & ~31; | |
129 | length >>= 3; | |
130 | return (length); | |
131 | } | |
132 | ||
133 | /* | |
134 | * Setting the video mode has been split into two parts. | |
135 | * First part, xxxfb_check_var, must not write anything | |
136 | * to hardware, it should only verify and adjust var. | |
137 | * This means it doesn't alter par but it does use hardware | |
138 | * data from it to check this var. | |
139 | */ | |
140 | ||
141 | static int mc68x328fb_check_var(struct fb_var_screeninfo *var, | |
142 | struct fb_info *info) | |
143 | { | |
144 | u_long line_length; | |
145 | ||
146 | /* | |
147 | * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal! | |
148 | * as FB_VMODE_SMOOTH_XPAN is only used internally | |
149 | */ | |
150 | ||
151 | if (var->vmode & FB_VMODE_CONUPDATE) { | |
152 | var->vmode |= FB_VMODE_YWRAP; | |
153 | var->xoffset = info->var.xoffset; | |
154 | var->yoffset = info->var.yoffset; | |
155 | } | |
156 | ||
157 | /* | |
158 | * Some very basic checks | |
159 | */ | |
160 | if (!var->xres) | |
161 | var->xres = 1; | |
162 | if (!var->yres) | |
163 | var->yres = 1; | |
164 | if (var->xres > var->xres_virtual) | |
165 | var->xres_virtual = var->xres; | |
166 | if (var->yres > var->yres_virtual) | |
167 | var->yres_virtual = var->yres; | |
168 | if (var->bits_per_pixel <= 1) | |
169 | var->bits_per_pixel = 1; | |
170 | else if (var->bits_per_pixel <= 8) | |
171 | var->bits_per_pixel = 8; | |
172 | else if (var->bits_per_pixel <= 16) | |
173 | var->bits_per_pixel = 16; | |
174 | else if (var->bits_per_pixel <= 24) | |
175 | var->bits_per_pixel = 24; | |
176 | else if (var->bits_per_pixel <= 32) | |
177 | var->bits_per_pixel = 32; | |
178 | else | |
179 | return -EINVAL; | |
180 | ||
181 | if (var->xres_virtual < var->xoffset + var->xres) | |
182 | var->xres_virtual = var->xoffset + var->xres; | |
183 | if (var->yres_virtual < var->yoffset + var->yres) | |
184 | var->yres_virtual = var->yoffset + var->yres; | |
185 | ||
186 | /* | |
187 | * Memory limit | |
188 | */ | |
189 | line_length = | |
190 | get_line_length(var->xres_virtual, var->bits_per_pixel); | |
191 | if (line_length * var->yres_virtual > videomemorysize) | |
192 | return -ENOMEM; | |
193 | ||
194 | /* | |
195 | * Now that we checked it we alter var. The reason being is that the video | |
196 | * mode passed in might not work but slight changes to it might make it | |
197 | * work. This way we let the user know what is acceptable. | |
198 | */ | |
199 | switch (var->bits_per_pixel) { | |
200 | case 1: | |
201 | var->red.offset = 0; | |
202 | var->red.length = 1; | |
203 | var->green.offset = 0; | |
204 | var->green.length = 1; | |
205 | var->blue.offset = 0; | |
206 | var->blue.length = 1; | |
207 | var->transp.offset = 0; | |
208 | var->transp.length = 0; | |
209 | break; | |
210 | case 8: | |
211 | var->red.offset = 0; | |
212 | var->red.length = 8; | |
213 | var->green.offset = 0; | |
214 | var->green.length = 8; | |
215 | var->blue.offset = 0; | |
216 | var->blue.length = 8; | |
217 | var->transp.offset = 0; | |
218 | var->transp.length = 0; | |
219 | break; | |
220 | case 16: /* RGBA 5551 */ | |
221 | if (var->transp.length) { | |
222 | var->red.offset = 0; | |
223 | var->red.length = 5; | |
224 | var->green.offset = 5; | |
225 | var->green.length = 5; | |
226 | var->blue.offset = 10; | |
227 | var->blue.length = 5; | |
228 | var->transp.offset = 15; | |
229 | var->transp.length = 1; | |
230 | } else { /* RGB 565 */ | |
231 | var->red.offset = 0; | |
232 | var->red.length = 5; | |
233 | var->green.offset = 5; | |
234 | var->green.length = 6; | |
235 | var->blue.offset = 11; | |
236 | var->blue.length = 5; | |
237 | var->transp.offset = 0; | |
238 | var->transp.length = 0; | |
239 | } | |
240 | break; | |
241 | case 24: /* RGB 888 */ | |
242 | var->red.offset = 0; | |
243 | var->red.length = 8; | |
244 | var->green.offset = 8; | |
245 | var->green.length = 8; | |
246 | var->blue.offset = 16; | |
247 | var->blue.length = 8; | |
248 | var->transp.offset = 0; | |
249 | var->transp.length = 0; | |
250 | break; | |
251 | case 32: /* RGBA 8888 */ | |
252 | var->red.offset = 0; | |
253 | var->red.length = 8; | |
254 | var->green.offset = 8; | |
255 | var->green.length = 8; | |
256 | var->blue.offset = 16; | |
257 | var->blue.length = 8; | |
258 | var->transp.offset = 24; | |
259 | var->transp.length = 8; | |
260 | break; | |
261 | } | |
262 | var->red.msb_right = 0; | |
263 | var->green.msb_right = 0; | |
264 | var->blue.msb_right = 0; | |
265 | var->transp.msb_right = 0; | |
266 | ||
267 | return 0; | |
268 | } | |
269 | ||
270 | /* This routine actually sets the video mode. It's in here where we | |
271 | * the hardware state info->par and fix which can be affected by the | |
272 | * change in par. For this driver it doesn't do much. | |
273 | */ | |
274 | static int mc68x328fb_set_par(struct fb_info *info) | |
275 | { | |
276 | info->fix.line_length = get_line_length(info->var.xres_virtual, | |
277 | info->var.bits_per_pixel); | |
278 | return 0; | |
279 | } | |
280 | ||
281 | /* | |
282 | * Set a single color register. The values supplied are already | |
283 | * rounded down to the hardware's capabilities (according to the | |
284 | * entries in the var structure). Return != 0 for invalid regno. | |
285 | */ | |
286 | ||
287 | static int mc68x328fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, | |
288 | u_int transp, struct fb_info *info) | |
289 | { | |
290 | if (regno >= 256) /* no. of hw registers */ | |
291 | return 1; | |
292 | /* | |
293 | * Program hardware... do anything you want with transp | |
294 | */ | |
295 | ||
296 | /* grayscale works only partially under directcolor */ | |
297 | if (info->var.grayscale) { | |
298 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | |
299 | red = green = blue = | |
300 | (red * 77 + green * 151 + blue * 28) >> 8; | |
301 | } | |
302 | ||
303 | /* Directcolor: | |
304 | * var->{color}.offset contains start of bitfield | |
305 | * var->{color}.length contains length of bitfield | |
306 | * {hardwarespecific} contains width of RAMDAC | |
307 | * cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset) | |
308 | * RAMDAC[X] is programmed to (red, green, blue) | |
309 | * | |
310 | * Pseudocolor: | |
311 | * uses offset = 0 && length = RAMDAC register width. | |
312 | * var->{color}.offset is 0 | |
313 | * var->{color}.length contains widht of DAC | |
314 | * cmap is not used | |
315 | * RAMDAC[X] is programmed to (red, green, blue) | |
316 | * Truecolor: | |
317 | * does not use DAC. Usually 3 are present. | |
318 | * var->{color}.offset contains start of bitfield | |
319 | * var->{color}.length contains length of bitfield | |
320 | * cmap is programmed to (red << red.offset) | (green << green.offset) | | |
321 | * (blue << blue.offset) | (transp << transp.offset) | |
322 | * RAMDAC does not exist | |
323 | */ | |
324 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) | |
325 | switch (info->fix.visual) { | |
326 | case FB_VISUAL_TRUECOLOR: | |
327 | case FB_VISUAL_PSEUDOCOLOR: | |
328 | red = CNVT_TOHW(red, info->var.red.length); | |
329 | green = CNVT_TOHW(green, info->var.green.length); | |
330 | blue = CNVT_TOHW(blue, info->var.blue.length); | |
331 | transp = CNVT_TOHW(transp, info->var.transp.length); | |
332 | break; | |
333 | case FB_VISUAL_DIRECTCOLOR: | |
334 | red = CNVT_TOHW(red, 8); /* expect 8 bit DAC */ | |
335 | green = CNVT_TOHW(green, 8); | |
336 | blue = CNVT_TOHW(blue, 8); | |
337 | /* hey, there is bug in transp handling... */ | |
338 | transp = CNVT_TOHW(transp, 8); | |
339 | break; | |
340 | } | |
341 | #undef CNVT_TOHW | |
342 | /* Truecolor has hardware independent palette */ | |
343 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { | |
344 | u32 v; | |
345 | ||
346 | if (regno >= 16) | |
347 | return 1; | |
348 | ||
349 | v = (red << info->var.red.offset) | | |
350 | (green << info->var.green.offset) | | |
351 | (blue << info->var.blue.offset) | | |
352 | (transp << info->var.transp.offset); | |
353 | switch (info->var.bits_per_pixel) { | |
354 | case 8: | |
355 | break; | |
356 | case 16: | |
357 | ((u32 *) (info->pseudo_palette))[regno] = v; | |
358 | break; | |
359 | case 24: | |
360 | case 32: | |
361 | ((u32 *) (info->pseudo_palette))[regno] = v; | |
362 | break; | |
363 | } | |
364 | return 0; | |
365 | } | |
366 | return 0; | |
367 | } | |
368 | ||
369 | /* | |
370 | * Pan or Wrap the Display | |
371 | * | |
372 | * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag | |
373 | */ | |
374 | ||
375 | static int mc68x328fb_pan_display(struct fb_var_screeninfo *var, | |
376 | struct fb_info *info) | |
377 | { | |
378 | if (var->vmode & FB_VMODE_YWRAP) { | |
379 | if (var->yoffset < 0 | |
380 | || var->yoffset >= info->var.yres_virtual | |
381 | || var->xoffset) | |
382 | return -EINVAL; | |
383 | } else { | |
384 | if (var->xoffset + var->xres > info->var.xres_virtual || | |
385 | var->yoffset + var->yres > info->var.yres_virtual) | |
386 | return -EINVAL; | |
387 | } | |
388 | info->var.xoffset = var->xoffset; | |
389 | info->var.yoffset = var->yoffset; | |
390 | if (var->vmode & FB_VMODE_YWRAP) | |
391 | info->var.vmode |= FB_VMODE_YWRAP; | |
392 | else | |
393 | info->var.vmode &= ~FB_VMODE_YWRAP; | |
394 | return 0; | |
395 | } | |
396 | ||
397 | /* | |
398 | * Most drivers don't need their own mmap function | |
399 | */ | |
400 | ||
401 | static int mc68x328fb_mmap(struct fb_info *info, struct file *file, | |
402 | struct vm_area_struct *vma) | |
403 | { | |
404 | #ifndef MMU | |
405 | /* this is uClinux (no MMU) specific code */ | |
406 | ||
407 | vma->vm_flags |= VM_RESERVED; | |
408 | vma->vm_start = videomemory; | |
409 | ||
410 | return 0; | |
411 | #else | |
412 | return -EINVAL; | |
413 | #endif | |
414 | } | |
415 | ||
416 | int __init mc68x328fb_setup(char *options) | |
417 | { | |
418 | #if 0 | |
419 | char *this_opt; | |
420 | #endif | |
421 | ||
422 | if (!options || !*options) | |
423 | return 1; | |
424 | #if 0 | |
425 | while ((this_opt = strsep(&options, ",")) != NULL) { | |
426 | if (!*this_opt) | |
427 | continue; | |
428 | if (!strncmp(this_opt, "disable", 7)) | |
429 | mc68x328fb_enable = 0; | |
430 | } | |
431 | #endif | |
432 | return 1; | |
433 | } | |
434 | ||
435 | /* | |
436 | * Initialisation | |
437 | */ | |
438 | ||
439 | int __init mc68x328fb_init(void) | |
440 | { | |
441 | #ifndef MODULE | |
442 | char *option = NULL; | |
443 | ||
444 | if (fb_get_options("68328fb", &option)) | |
445 | return -ENODEV; | |
446 | mc68x328fb_setup(option); | |
447 | #endif | |
448 | /* | |
449 | * initialize the default mode from the LCD controller registers | |
450 | */ | |
451 | mc68x328fb_default.xres = LXMAX; | |
452 | mc68x328fb_default.yres = LYMAX+1; | |
453 | mc68x328fb_default.xres_virtual = mc68x328fb_default.xres; | |
454 | mc68x328fb_default.yres_virtual = mc68x328fb_default.yres; | |
455 | mc68x328fb_default.bits_per_pixel = 1 + (LPICF & 0x01); | |
456 | videomemory = LSSA; | |
457 | videomemorysize = (mc68x328fb_default.xres_virtual+7) / 8 * | |
458 | mc68x328fb_default.yres_virtual * mc68x328fb_default.bits_per_pixel; | |
459 | ||
460 | fb_info.screen_base = (void *)videomemory; | |
461 | fb_info.fbops = &mc68x328fb_ops; | |
462 | fb_info.var = mc68x328fb_default; | |
463 | fb_info.fix = mc68x328fb_fix; | |
464 | fb_info.fix.smem_start = videomemory; | |
465 | fb_info.fix.smem_len = videomemorysize; | |
466 | fb_info.fix.line_length = | |
467 | get_line_length(mc68x328fb_default.xres_virtual, mc68x328fb_default.bits_per_pixel); | |
468 | fb_info.fix.visual = (mc68x328fb_default.bits_per_pixel) == 1 ? | |
469 | MC68X328FB_MONO_VISUAL : FB_VISUAL_PSEUDOCOLOR; | |
470 | if (fb_info.var.bits_per_pixel == 1) { | |
471 | fb_info.var.red.length = fb_info.var.green.length = fb_info.var.blue.length = 1; | |
472 | fb_info.var.red.offset = fb_info.var.green.offset = fb_info.var.blue.offset = 0; | |
473 | } | |
474 | fb_info.pseudo_palette = &mc68x328fb_pseudo_palette; | |
475 | fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; | |
476 | ||
477 | fb_alloc_cmap(&fb_info.cmap, 256, 0); | |
478 | ||
479 | if (register_framebuffer(&fb_info) < 0) { | |
480 | return -EINVAL; | |
481 | } | |
482 | ||
483 | printk(KERN_INFO | |
484 | "fb%d: %s frame buffer device\n", fb_info.node, fb_info.fix.id); | |
485 | printk(KERN_INFO | |
486 | "fb%d: %dx%dx%d at 0x%08lx\n", fb_info.node, | |
487 | mc68x328fb_default.xres_virtual, mc68x328fb_default.yres_virtual, | |
488 | 1 << mc68x328fb_default.bits_per_pixel, videomemory); | |
489 | ||
490 | return 0; | |
491 | } | |
492 | ||
493 | module_init(mc68x328fb_init); | |
494 | ||
495 | #ifdef MODULE | |
496 | ||
497 | static void __exit mc68x328fb_cleanup(void) | |
498 | { | |
499 | unregister_framebuffer(&fb_info); | |
500 | } | |
501 | ||
502 | module_exit(mc68x328fb_cleanup); | |
503 | ||
504 | MODULE_LICENSE("GPL"); | |
505 | #endif /* MODULE */ |