MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / video / sa1100fb.c
blobb2c7aa10449a2f33bc53ca8aea1ec5f871fc0f4e
1 /*
2 * linux/drivers/video/sa1100fb.c
4 * Copyright (C) 1999 Eric A. Thomas
5 * Based on acornfb.c Copyright (C) Russell King.
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
11 * StrongARM 1100 LCD Controller Frame Buffer Driver
13 * Please direct your questions and comments on this driver to the following
14 * email address:
16 * linux-arm-kernel@lists.arm.linux.org.uk
18 * Clean patches should be sent to the ARM Linux Patch System. Please see the
19 * following web page for more information:
21 * http://www.arm.linux.org.uk/developer/patches/info.shtml
23 * Thank you.
25 * Known problems:
26 * - With the Neponset plugged into an Assabet, LCD powerdown
27 * doesn't work (LCD stays powered up). Therefore we shouldn't
28 * blank the screen.
29 * - We don't limit the CPU clock rate nor the mode selection
30 * according to the available SDRAM bandwidth.
32 * Other notes:
33 * - Linear grayscale palettes and the kernel.
34 * Such code does not belong in the kernel. The kernel frame buffer
35 * drivers do not expect a linear colourmap, but a colourmap based on
36 * the VT100 standard mapping.
38 * If your _userspace_ requires a linear colourmap, then the setup of
39 * such a colourmap belongs _in userspace_, not in the kernel. Code
40 * to set the colourmap correctly from user space has been sent to
41 * David Neuer. It's around 8 lines of C code, plus another 4 to
42 * detect if we are using grayscale.
44 * - The following must never be specified in a panel definition:
45 * LCCR0_LtlEnd, LCCR3_PixClkDiv, LCCR3_VrtSnchL, LCCR3_HorSnchL
47 * - The following should be specified:
48 * either LCCR0_Color or LCCR0_Mono
49 * either LCCR0_Sngl or LCCR0_Dual
50 * either LCCR0_Act or LCCR0_Pas
51 * either LCCR3_OutEnH or LCCD3_OutEnL
52 * either LCCR3_PixRsEdg or LCCR3_PixFlEdg
53 * either LCCR3_ACBsDiv or LCCR3_ACBsCntOff
55 * Code Status:
56 * 1999/04/01:
57 * - Driver appears to be working for Brutus 320x200x8bpp mode. Other
58 * resolutions are working, but only the 8bpp mode is supported.
59 * Changes need to be made to the palette encode and decode routines
60 * to support 4 and 16 bpp modes.
61 * Driver is not designed to be a module. The FrameBuffer is statically
62 * allocated since dynamic allocation of a 300k buffer cannot be
63 * guaranteed.
65 * 1999/06/17:
66 * - FrameBuffer memory is now allocated at run-time when the
67 * driver is initialized.
69 * 2000/04/10: Nicolas Pitre <nico@cam.org>
70 * - Big cleanup for dynamic selection of machine type at run time.
72 * 2000/07/19: Jamey Hicks <jamey@crl.dec.com>
73 * - Support for Bitsy aka Compaq iPAQ H3600 added.
75 * 2000/08/07: Tak-Shing Chan <tchan.rd@idthk.com>
76 * Jeff Sutherland <jsutherland@accelent.com>
77 * - Resolved an issue caused by a change made to the Assabet's PLD
78 * earlier this year which broke the framebuffer driver for newer
79 * Phase 4 Assabets. Some other parameters were changed to optimize
80 * for the Sharp display.
82 * 2000/08/09: Kunihiko IMAI <imai@vasara.co.jp>
83 * - XP860 support added
85 * 2000/08/19: Mark Huang <mhuang@livetoy.com>
86 * - Allows standard options to be passed on the kernel command line
87 * for most common passive displays.
89 * 2000/08/29:
90 * - s/save_flags_cli/local_irq_save/
91 * - remove unneeded extra save_flags_cli in sa1100fb_enable_lcd_controller
93 * 2000/10/10: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
94 * - Updated LART stuff. Fixed some minor bugs.
96 * 2000/10/30: Murphy Chen <murphy@mail.dialogue.com.tw>
97 * - Pangolin support added
99 * 2000/10/31: Roman Jordan <jor@hoeft-wessel.de>
100 * - Huw Webpanel support added
102 * 2000/11/23: Eric Peng <ericpeng@coventive.com>
103 * - Freebird add
105 * 2001/02/07: Jamey Hicks <jamey.hicks@compaq.com>
106 * Cliff Brake <cbrake@accelent.com>
107 * - Added PM callback
109 * 2001/05/26: <rmk@arm.linux.org.uk>
110 * - Fix 16bpp so that (a) we use the right colours rather than some
111 * totally random colour depending on what was in page 0, and (b)
112 * we don't de-reference a NULL pointer.
113 * - remove duplicated implementation of consistent_alloc()
114 * - convert dma address types to dma_addr_t
115 * - remove unused 'montype' stuff
116 * - remove redundant zero inits of init_var after the initial
117 * memzero.
118 * - remove allow_modeset (acornfb idea does not belong here)
120 * 2001/05/28: <rmk@arm.linux.org.uk>
121 * - massive cleanup - move machine dependent data into structures
122 * - I've left various #warnings in - if you see one, and know
123 * the hardware concerned, please get in contact with me.
125 * 2001/05/31: <rmk@arm.linux.org.uk>
126 * - Fix LCCR1 HSW value, fix all machine type specifications to
127 * keep values in line. (Please check your machine type specs)
129 * 2001/06/10: <rmk@arm.linux.org.uk>
130 * - Fiddle with the LCD controller from task context only; mainly
131 * so that we can run with interrupts on, and sleep.
132 * - Convert #warnings into #errors. No pain, no gain. ;)
134 * 2001/06/14: <rmk@arm.linux.org.uk>
135 * - Make the palette BPS value for 12bpp come out correctly.
136 * - Take notice of "greyscale" on any colour depth.
137 * - Make truecolor visuals use the RGB channel encoding information.
139 * 2001/07/02: <rmk@arm.linux.org.uk>
140 * - Fix colourmap problems.
142 * 2001/07/13: <abraham@2d3d.co.za>
143 * - Added support for the ICP LCD-Kit01 on LART. This LCD is
144 * manufactured by Prime View, model no V16C6448AB
146 * 2001/07/23: <rmk@arm.linux.org.uk>
147 * - Hand merge version from handhelds.org CVS tree. See patch
148 * notes for 595/1 for more information.
149 * - Drop 12bpp (it's 16bpp with different colour register mappings).
150 * - This hardware can not do direct colour. Therefore we don't
151 * support it.
153 * 2001/07/27: <rmk@arm.linux.org.uk>
154 * - Halve YRES on dual scan LCDs.
156 * 2001/08/22: <rmk@arm.linux.org.uk>
157 * - Add b/w iPAQ pixclock value.
159 * 2001/10/12: <rmk@arm.linux.org.uk>
160 * - Add patch 681/1 and clean up stork definitions.
163 #include <linux/config.h>
164 #include <linux/module.h>
165 #include <linux/kernel.h>
166 #include <linux/sched.h>
167 #include <linux/errno.h>
168 #include <linux/string.h>
169 #include <linux/interrupt.h>
170 #include <linux/slab.h>
171 #include <linux/fb.h>
172 #include <linux/delay.h>
173 #include <linux/init.h>
174 #include <linux/ioport.h>
175 #include <linux/cpufreq.h>
176 #include <linux/device.h>
177 #include <linux/dma-mapping.h>
179 #include <asm/hardware.h>
180 #include <asm/io.h>
181 #include <asm/irq.h>
182 #include <asm/mach-types.h>
183 #include <asm/uaccess.h>
184 #include <asm/arch/assabet.h>
185 #include <asm/arch/shannon.h>
188 * debugging?
190 #define DEBUG 0
192 * Complain if VAR is out of range.
194 #define DEBUG_VAR 1
196 #undef ASSABET_PAL_VIDEO
198 #include "sa1100fb.h"
200 extern void (*sa1100fb_backlight_power)(int on);
201 extern void (*sa1100fb_lcd_power)(int on);
204 * IMHO this looks wrong. In 8BPP, length should be 8.
206 static struct sa1100fb_rgb rgb_8 = {
207 .red = { .offset = 0, .length = 4, },
208 .green = { .offset = 0, .length = 4, },
209 .blue = { .offset = 0, .length = 4, },
210 .transp = { .offset = 0, .length = 0, },
213 static struct sa1100fb_rgb def_rgb_16 = {
214 .red = { .offset = 11, .length = 5, },
215 .green = { .offset = 5, .length = 6, },
216 .blue = { .offset = 0, .length = 5, },
217 .transp = { .offset = 0, .length = 0, },
220 #ifdef CONFIG_SA1100_ASSABET
221 #ifndef ASSABET_PAL_VIDEO
223 * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
224 * takes an RGB666 signal, but we provide it with an RGB565 signal
225 * instead (def_rgb_16).
227 static struct sa1100fb_mach_info lq039q2ds54_info __initdata = {
228 .pixclock = 171521, .bpp = 16,
229 .xres = 320, .yres = 240,
231 .hsync_len = 5, .vsync_len = 1,
232 .left_margin = 61, .upper_margin = 3,
233 .right_margin = 9, .lower_margin = 0,
235 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
237 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
238 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
240 #else
241 static struct sa1100fb_mach_info pal_info __initdata = {
242 .pixclock = 67797, .bpp = 16,
243 .xres = 640, .yres = 512,
245 .hsync_len = 64, .vsync_len = 6,
246 .left_margin = 125, .upper_margin = 70,
247 .right_margin = 115, .lower_margin = 36,
249 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
250 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
252 #endif
253 #endif
255 #ifdef CONFIG_SA1100_H3800
256 static struct sa1100fb_mach_info h3800_info __initdata = {
257 .pixclock = 174757, .bpp = 16,
258 .xres = 320, .yres = 240,
260 .hsync_len = 3, .vsync_len = 3,
261 .left_margin = 12, .upper_margin = 10,
262 .right_margin = 17, .lower_margin = 1,
264 .cmap_static = 1,
266 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
267 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
269 #endif
271 #ifdef CONFIG_SA1100_H3600
272 static struct sa1100fb_mach_info h3600_info __initdata = {
273 .pixclock = 174757, .bpp = 16,
274 .xres = 320, .yres = 240,
276 .hsync_len = 3, .vsync_len = 3,
277 .left_margin = 12, .upper_margin = 10,
278 .right_margin = 17, .lower_margin = 1,
280 .cmap_static = 1,
282 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
283 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
286 static struct sa1100fb_rgb h3600_rgb_16 = {
287 .red = { .offset = 12, .length = 4, },
288 .green = { .offset = 7, .length = 4, },
289 .blue = { .offset = 1, .length = 4, },
290 .transp = { .offset = 0, .length = 0, },
292 #endif
294 #ifdef CONFIG_SA1100_H3100
295 static struct sa1100fb_mach_info h3100_info __initdata = {
296 .pixclock = 406977, .bpp = 4,
297 .xres = 320, .yres = 240,
299 .hsync_len = 26, .vsync_len = 41,
300 .left_margin = 4, .upper_margin = 0,
301 .right_margin = 4, .lower_margin = 0,
303 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
304 .cmap_greyscale = 1,
305 .cmap_inverse = 1,
307 .lccr0 = LCCR0_Mono | LCCR0_4PixMono | LCCR0_Sngl | LCCR0_Pas,
308 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
310 #endif
312 #ifdef CONFIG_SA1100_BRUTUS
313 static struct sa1100fb_mach_info brutus_info __initdata = {
314 .pixclock = 0, .bpp = 8,
315 .xres = 320, .yres = 240,
317 .hsync_len = 3, .vsync_len = 1,
318 .left_margin = 41, .upper_margin = 0,
319 .right_margin = 101, .lower_margin = 0,
321 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
323 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Pas,
324 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2) |
325 LCCR3_PixClkDiv(44),
327 #endif
329 #ifdef CONFIG_SA1100_COLLIE
330 static struct sa1100fb_mach_info collie_info __initdata = {
331 .pixclock = 171521, .bpp = 16,
332 .xres = 320, .yres = 240,
334 .hsync_len = 5, .vsync_len = 1,
335 .left_margin = 11, .upper_margin = 2,
336 .right_margin = 30, .lower_margin = 0,
338 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
340 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
341 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
343 #endif
345 #ifdef CONFIG_SA1100_FREEBIRD
346 #warning Please check this carefully
347 static struct sa1100fb_mach_info freebird_info __initdata = {
348 .pixclock = 171521, .bpp = 16,
349 .xres = 240, .yres = 320,
351 .hsync_len = 3, .vsync_len = 2,
352 .left_margin = 2, .upper_margin = 0,
353 .right_margin = 2, .lower_margin = 0,
355 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
357 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Pas,
358 .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(2),
361 static struct sa1100fb_rgb freebird_rgb_16 = {
362 .red = { .offset = 8, .length = 4, },
363 .green = { .offset = 4, .length = 4, },
364 .blue = { .offset = 0, .length = 4, },
365 .transp = { .offset = 12, .length = 4, },
367 #endif
369 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
370 static struct sa1100fb_mach_info graphicsclient_info __initdata = {
371 .pixclock = 53500, .bpp = 8,
372 .xres = 640, .yres = 480,
374 .hsync_len = 9, .vsync_len = 9,
375 .left_margin = 54, .upper_margin = 24,
376 .right_margin = 54, .lower_margin = 32,
378 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
379 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
381 #endif
383 #ifdef CONFIG_SA1100_HUW_WEBPANEL
384 static struct sa1100fb_mach_info huw_webpanel_info __initdata = {
385 .pixclock = 0, .bpp = 8,
386 .xres = 640, .yres = 480,
388 .hsync_len = 3, .vsync_len = 1,
389 .left_margin = 41, .upper_margin = 0,
390 .right_margin = 101, .lower_margin = 0,
392 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
394 .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
395 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2) | 8,
396 #error FIXME
398 * FIXME: please get rid of the '| 8' in preference to an
399 * LCCR3_PixClkDiv() version. --rmk
402 #endif
404 #ifdef LART_GREY_LCD
405 static struct sa1100fb_mach_info lart_grey_info __initdata = {
406 .pixclock = 150000, .bpp = 4,
407 .xres = 320, .yres = 240,
409 .hsync_len = 1, .vsync_len = 1,
410 .left_margin = 4, .upper_margin = 0,
411 .right_margin = 2, .lower_margin = 0,
413 .cmap_greyscale = 1,
414 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
416 .lccr0 = LCCR0_Mono | LCCR0_Sngl | LCCR0_Pas | LCCR0_4PixMono,
417 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
419 #endif
420 #ifdef LART_COLOR_LCD
421 static struct sa1100fb_mach_info lart_color_info __initdata = {
422 .pixclock = 150000, .bpp = 16,
423 .xres = 320, .yres = 240,
425 .hsync_len = 2, .vsync_len = 3,
426 .left_margin = 69, .upper_margin = 14,
427 .right_margin = 8, .lower_margin = 4,
429 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
430 .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
432 #endif
433 #ifdef LART_VIDEO_OUT
434 static struct sa1100fb_mach_info lart_video_info __initdata = {
435 .pixclock = 39721, .bpp = 16,
436 .xres = 640, .yres = 480,
438 .hsync_len = 95, .vsync_len = 2,
439 .left_margin = 40, .upper_margin = 32,
440 .right_margin = 24, .lower_margin = 11,
442 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
444 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
445 .lccr3 = LCCR3_OutEnL | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
447 #endif
449 #ifdef LART_KIT01_LCD
450 static struct sa1100fb_mach_info lart_kit01_info __initdata = {
451 .pixclock = 63291, .bpp = 16,
452 .xres = 640, .yres = 480,
454 .hsync_len = 64, .vsync_len = 3,
455 .left_margin = 122, .upper_margin = 45,
456 .right_margin = 10, .lower_margin = 10,
458 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
459 .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg
461 #endif
463 #ifdef CONFIG_SA1100_SHANNON
464 static struct sa1100fb_mach_info shannon_info __initdata = {
465 .pixclock = 152500, .bpp = 8,
466 .xres = 640, .yres = 480,
468 .hsync_len = 4, .vsync_len = 3,
469 .left_margin = 2, .upper_margin = 0,
470 .right_margin = 1, .lower_margin = 0,
472 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
474 .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
475 .lccr3 = LCCR3_ACBsDiv(512),
477 #endif
479 #ifdef CONFIG_SA1100_OMNIMETER
480 static struct sa1100fb_mach_info omnimeter_info __initdata = {
481 .pixclock = 0, .bpp = 4,
482 .xres = 480, .yres = 320,
484 .hsync_len = 1, .vsync_len = 1,
485 .left_margin = 10, .upper_margin = 0,
486 .right_margin = 10, .lower_margin = 0,
488 .cmap_greyscale = 1,
489 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
491 .lccr0 = LCCR0_Mono | LCCR0_Sngl | LCCR0_Pas | LCCR0_8PixMono,
492 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(255) |
493 LCCR3_PixClkDiv(44),
494 #error FIXME: fix pixclock, ACBsDiv
496 * FIXME: I think ACBsDiv is wrong above - should it be 512 (disabled)?
497 * - rmk
500 #endif
502 #ifdef CONFIG_SA1100_PANGOLIN
503 static struct sa1100fb_mach_info pangolin_info __initdata = {
504 .pixclock = 341521, .bpp = 16,
505 .xres = 800, .yres = 600,
507 .hsync_len = 64, .vsync_len = 7,
508 .left_margin = 160, .upper_margin = 7,
509 .right_margin = 24, .lower_margin = 1,
511 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
513 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
514 .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsCntOff,
516 #endif
518 #ifdef CONFIG_SA1100_STORK
519 #if STORK_TFT /* ie the NEC TFT */
521 * pixclock is ps per clock. say 72Hz, 800x600 clocks => (1/72)/(800*600)
522 * = 28935 and a bit
523 * NB likely to be increased to ease bus timings wrt pcmcia interface
525 static struct sa1100fb_mach_info stork_tft_info __initdata = {
526 .pixclock = 28935, .bpp = 16,
527 .xres = 640, .yres = 480,
529 .hsync_len = 64, .vsync_len = 2,
530 .left_margin = 48, .upper_margin = 12,
531 .right_margin = 48, .lower_margin = 31,
533 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
534 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsCntOff,
537 static struct sa1100fb_rgb stork_tft_rgb_16 = {
538 .red = { .offset = 11, .length = 5, },
539 .green = { .offset = 5, .length = 6, },
540 .blue = { .offset = 0, .length = 5, },
541 .transp = { .offset = 0, .length = 0, },
544 #else /* Kyocera DSTN */
546 static struct sa1100fb_mach_info stork_dstn_info __initdata = {
547 .pixclock = 0, .bpp = 16,
548 .xres = 640, .yres = 480,
550 .hsync_len = 2, .vsync_len = 2,
551 .left_margin = 2, .upper_margin = 0,
552 .right_margin = 2, .lower_margin = 0,
554 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT ,
556 .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
557 #error Fixme
558 .lccr3 = 0xff00 |
559 0x18 /* ought to be 0x14 but DMA isn't up to that as yet */
562 static struct sa1100fb_rgb stork_dstn_rgb_16 = {
563 .red = { .offset = 8, .length = 4, },
564 .green = { .offset = 4, .length = 4, },
565 .blue = { .offset = 0, .length = 4, },
566 .transp = { .offset = 0, .length = 0, },
568 #endif
569 #endif
571 #ifdef CONFIG_SA1100_PT_SYSTEM3
573 * 648 x 480 x 8bpp x 75Hz Dual Panel Color STN Display
575 * pixclock = 1/( 640*3/8*240 ), [pixclock]=1e-12s=ps
576 * 3 due to r,g,b lines
577 * 8 due to 8 bit data bus
578 * 640 due to 640 pixels per line
579 * 240 = 480/2 due to dual panel display
580 * =>4.32Mhz => 231481E-12s
582 static struct sa1100fb_mach_info system3_info __initdata = {
583 .pixclock = 231481, .bpp = 8,
584 .xres = 640, .yres = 480,
586 .hsync_len = 2, .vsync_len = 2,
587 .left_margin = 2, .upper_margin = 0,
588 .right_margin = 2, .lower_margin = 0,
590 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
592 .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
593 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
595 #endif
597 #ifdef CONFIG_SA1100_XP860
598 static struct sa1100fb_mach_info xp860_info __initdata = {
599 .pixclock = 0, .bpp = 8,
600 .xres = 1024, .yres = 768,
602 .hsync_len = 3, .vsync_len = 3,
603 .left_margin = 3, .upper_margin = 2,
604 .right_margin = 2, .lower_margin = 1,
606 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
607 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_PixClkDiv(6),
609 #endif
613 static struct sa1100fb_mach_info * __init
614 sa1100fb_get_machine_info(struct sa1100fb_info *fbi)
616 struct sa1100fb_mach_info *inf = NULL;
619 * R G B T
620 * default {11,5}, { 5,6}, { 0,5}, { 0,0}
621 * h3600 {12,4}, { 7,4}, { 1,4}, { 0,0}
622 * freebird { 8,4}, { 4,4}, { 0,4}, {12,4}
624 #ifdef CONFIG_SA1100_ASSABET
625 if (machine_is_assabet()) {
626 #ifndef ASSABET_PAL_VIDEO
627 inf = &lq039q2ds54_info;
628 #else
629 inf = &pal_info;
630 #endif
632 #endif
633 #ifdef CONFIG_SA1100_H3100
634 if (machine_is_h3100()) {
635 inf = &h3100_info;
637 #endif
638 #ifdef CONFIG_SA1100_H3600
639 if (machine_is_h3600()) {
640 inf = &h3600_info;
641 fbi->rgb[RGB_16] = &h3600_rgb_16;
643 #endif
644 #ifdef CONFIG_SA1100_H3800
645 if (machine_is_h3800()) {
646 inf = &h3800_info;
648 #endif
649 #ifdef CONFIG_SA1100_BRUTUS
650 if (machine_is_brutus()) {
651 inf = &brutus_info;
653 #endif
654 #ifdef CONFIG_SA1100_COLLIE
655 if (machine_is_collie()) {
656 inf = &collie_info;
658 #endif
659 #ifdef CONFIG_SA1100_FREEBIRD
660 if (machine_is_freebird()) {
661 inf = &freebird_info;
662 fbi->rgb[RGB_16] = &freebird_rgb16;
664 #endif
665 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
666 if (machine_is_graphicsclient()) {
667 inf = &graphicsclient_info;
669 #endif
670 #ifdef CONFIG_SA1100_HUW_WEBPANEL
671 if (machine_is_huw_webpanel()) {
672 inf = &huw_webpanel_info;
674 #endif
675 #ifdef CONFIG_SA1100_LART
676 if (machine_is_lart()) {
677 #ifdef LART_GREY_LCD
678 inf = &lart_grey_info;
679 #endif
680 #ifdef LART_COLOR_LCD
681 inf = &lart_color_info;
682 #endif
683 #ifdef LART_VIDEO_OUT
684 inf = &lart_video_info;
685 #endif
686 #ifdef LART_KIT01_LCD
687 inf = &lart_kit01_info;
688 #endif
690 #endif
691 #ifdef CONFIG_SA1100_OMNIMETER
692 if (machine_is_omnimeter()) {
693 inf = &omnimeter_info;
695 #endif
696 #ifdef CONFIG_SA1100_PANGOLIN
697 if (machine_is_pangolin()) {
698 inf = &pangolin_info;
700 #endif
701 #ifdef CONFIG_SA1100_PT_SYSTEM3
702 if (machine_is_pt_system3()) {
703 inf = &system3_info;
705 #endif
706 #ifdef CONFIG_SA1100_SHANNON
707 if (machine_is_shannon()) {
708 inf = &shannon_info;
710 #endif
711 #ifdef CONFIG_SA1100_STORK
712 if (machine_is_stork()) {
713 #if STORK_TFT
714 inf = &stork_tft_info;
715 fbi->rgb[RGB_16] = &stork_tft_rgb_16;
716 #else
717 inf = &stork_dstn_info;
718 fbi->rgb[RGB_16] = &stork_dstn_rgb_16;
719 #endif
721 #endif
722 #ifdef CONFIG_SA1100_XP860
723 if (machine_is_xp860()) {
724 inf = &xp860_info;
726 #endif
727 return inf;
730 static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
731 static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
733 static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
735 unsigned long flags;
737 local_irq_save(flags);
739 * We need to handle two requests being made at the same time.
740 * There are two important cases:
741 * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
742 * We must perform the unblanking, which will do our REENABLE for us.
743 * 2. When we are blanking, but immediately unblank before we have
744 * blanked. We do the "REENABLE" thing here as well, just to be sure.
746 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
747 state = (u_int) -1;
748 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
749 state = C_REENABLE;
751 if (state != (u_int)-1) {
752 fbi->task_state = state;
753 schedule_work(&fbi->task);
755 local_irq_restore(flags);
758 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
760 chan &= 0xffff;
761 chan >>= 16 - bf->length;
762 return chan << bf->offset;
766 * Convert bits-per-pixel to a hardware palette PBS value.
768 static inline u_int palette_pbs(struct fb_var_screeninfo *var)
770 int ret = 0;
771 switch (var->bits_per_pixel) {
772 case 4: ret = 0 << 12; break;
773 case 8: ret = 1 << 12; break;
774 case 16: ret = 2 << 12; break;
776 return ret;
779 static int
780 sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
781 u_int trans, struct fb_info *info)
783 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
784 u_int val, ret = 1;
786 if (regno < fbi->palette_size) {
787 val = ((red >> 4) & 0xf00);
788 val |= ((green >> 8) & 0x0f0);
789 val |= ((blue >> 12) & 0x00f);
791 if (regno == 0)
792 val |= palette_pbs(&fbi->fb.var);
794 fbi->palette_cpu[regno] = val;
795 ret = 0;
797 return ret;
800 static int
801 sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
802 u_int trans, struct fb_info *info)
804 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
805 unsigned int val;
806 int ret = 1;
809 * If inverse mode was selected, invert all the colours
810 * rather than the register number. The register number
811 * is what you poke into the framebuffer to produce the
812 * colour you requested.
814 if (fbi->cmap_inverse) {
815 red = 0xffff - red;
816 green = 0xffff - green;
817 blue = 0xffff - blue;
821 * If greyscale is true, then we convert the RGB value
822 * to greyscale no mater what visual we are using.
824 if (fbi->fb.var.grayscale)
825 red = green = blue = (19595 * red + 38470 * green +
826 7471 * blue) >> 16;
828 switch (fbi->fb.fix.visual) {
829 case FB_VISUAL_TRUECOLOR:
831 * 12 or 16-bit True Colour. We encode the RGB value
832 * according to the RGB bitfield information.
834 if (regno < 16) {
835 u32 *pal = fbi->fb.pseudo_palette;
837 val = chan_to_field(red, &fbi->fb.var.red);
838 val |= chan_to_field(green, &fbi->fb.var.green);
839 val |= chan_to_field(blue, &fbi->fb.var.blue);
841 pal[regno] = val;
842 ret = 0;
844 break;
846 case FB_VISUAL_STATIC_PSEUDOCOLOR:
847 case FB_VISUAL_PSEUDOCOLOR:
848 ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
849 break;
852 return ret;
856 * sa1100fb_display_dma_period()
857 * Calculate the minimum period (in picoseconds) between two DMA
858 * requests for the LCD controller. If we hit this, it means we're
859 * doing nothing but LCD DMA.
861 static unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
864 * Period = pixclock * bits_per_byte * bytes_per_transfer
865 * / memory_bits_per_pixel;
867 return var->pixclock * 8 * 16 / var->bits_per_pixel;
871 * sa1100fb_check_var():
872 * Round up in the following order: bits_per_pixel, xres,
873 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
874 * bitfields, horizontal timing, vertical timing.
876 static int
877 sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
879 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
880 int rgbidx;
882 if (var->xres < MIN_XRES)
883 var->xres = MIN_XRES;
884 if (var->yres < MIN_YRES)
885 var->yres = MIN_YRES;
886 if (var->xres > fbi->max_xres)
887 var->xres = fbi->max_xres;
888 if (var->yres > fbi->max_yres)
889 var->yres = fbi->max_yres;
890 var->xres_virtual = max(var->xres_virtual, var->xres);
891 var->yres_virtual = max(var->yres_virtual, var->yres);
893 DPRINTK("var->bits_per_pixel=%d\n", var->bits_per_pixel);
894 switch (var->bits_per_pixel) {
895 case 4:
896 rgbidx = RGB_8;
897 break;
898 case 8:
899 rgbidx = RGB_8;
900 break;
901 case 16:
902 rgbidx = RGB_16;
903 break;
904 default:
905 return -EINVAL;
909 * Copy the RGB parameters for this display
910 * from the machine specific parameters.
912 var->red = fbi->rgb[rgbidx]->red;
913 var->green = fbi->rgb[rgbidx]->green;
914 var->blue = fbi->rgb[rgbidx]->blue;
915 var->transp = fbi->rgb[rgbidx]->transp;
917 DPRINTK("RGBT length = %d:%d:%d:%d\n",
918 var->red.length, var->green.length, var->blue.length,
919 var->transp.length);
921 DPRINTK("RGBT offset = %d:%d:%d:%d\n",
922 var->red.offset, var->green.offset, var->blue.offset,
923 var->transp.offset);
925 #ifdef CONFIG_CPU_FREQ
926 printk(KERN_DEBUG "dma period = %d ps, clock = %d kHz\n",
927 sa1100fb_display_dma_period(var),
928 cpufreq_get(smp_processor_id()));
929 #endif
931 return 0;
934 static inline void sa1100fb_set_truecolor(u_int is_true_color)
936 if (machine_is_assabet()) {
937 #if 1 // phase 4 or newer Assabet's
938 if (is_true_color)
939 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
940 else
941 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
942 #else
943 // older Assabet's
944 if (is_true_color)
945 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
946 else
947 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
948 #endif
953 * sa1100fb_set_par():
954 * Set the user defined part of the display for the specified console
956 static int sa1100fb_set_par(struct fb_info *info)
958 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
959 struct fb_var_screeninfo *var = &info->var;
960 unsigned long palette_mem_size;
962 DPRINTK("set_par\n");
964 if (var->bits_per_pixel == 16)
965 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
966 else if (!fbi->cmap_static)
967 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
968 else {
970 * Some people have weird ideas about wanting static
971 * pseudocolor maps. I suspect their user space
972 * applications are broken.
974 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
977 fbi->fb.fix.line_length = var->xres_virtual *
978 var->bits_per_pixel / 8;
979 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
981 palette_mem_size = fbi->palette_size * sizeof(u16);
983 DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
985 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
986 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
989 * Set (any) board control register to handle new color depth
991 sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
993 #ifdef CONFIG_SA1100_OMNIMETER
994 #error Do we have to do this here? We already do it at init time.
995 if (machine_is_omnimeter())
996 SetLCDContrast(DefaultLCDContrast);
997 #endif
999 sa1100fb_activate_var(var, fbi);
1001 return 0;
1004 #if 0
1005 static int
1006 sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
1007 struct fb_info *info)
1009 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
1012 * Make sure the user isn't doing something stupid.
1014 if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
1015 return -EINVAL;
1017 return gen_set_cmap(cmap, kspc, con, info);
1019 #endif
1022 * Formal definition of the VESA spec:
1023 * On
1024 * This refers to the state of the display when it is in full operation
1025 * Stand-By
1026 * This defines an optional operating state of minimal power reduction with
1027 * the shortest recovery time
1028 * Suspend
1029 * This refers to a level of power management in which substantial power
1030 * reduction is achieved by the display. The display can have a longer
1031 * recovery time from this state than from the Stand-by state
1032 * Off
1033 * This indicates that the display is consuming the lowest level of power
1034 * and is non-operational. Recovery from this state may optionally require
1035 * the user to manually power on the monitor
1037 * Now, the fbdev driver adds an additional state, (blank), where they
1038 * turn off the video (maybe by colormap tricks), but don't mess with the
1039 * video itself: think of it semantically between on and Stand-By.
1041 * So here's what we should do in our fbdev blank routine:
1043 * VESA_NO_BLANKING (mode 0) Video on, front/back light on
1044 * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
1045 * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
1046 * VESA_POWERDOWN (mode 3) Video off, front/back light off
1048 * This will match the matrox implementation.
1051 * sa1100fb_blank():
1052 * Blank the display by setting all palette values to zero. Note, the
1053 * 12 and 16 bpp modes don't really use the palette, so this will not
1054 * blank the display in all modes.
1056 static int sa1100fb_blank(int blank, struct fb_info *info)
1058 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
1059 int i;
1061 DPRINTK("sa1100fb_blank: blank=%d\n", blank);
1063 switch (blank) {
1064 case VESA_POWERDOWN:
1065 case VESA_VSYNC_SUSPEND:
1066 case VESA_HSYNC_SUSPEND:
1067 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
1068 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
1069 for (i = 0; i < fbi->palette_size; i++)
1070 sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
1071 sa1100fb_schedule_work(fbi, C_DISABLE);
1072 break;
1074 case VESA_NO_BLANKING:
1075 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
1076 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
1077 fb_set_cmap(&fbi->fb.cmap, info);
1078 sa1100fb_schedule_work(fbi, C_ENABLE);
1080 return 0;
1083 static struct fb_ops sa1100fb_ops = {
1084 .owner = THIS_MODULE,
1085 .fb_check_var = sa1100fb_check_var,
1086 .fb_set_par = sa1100fb_set_par,
1087 // .fb_set_cmap = sa1100fb_set_cmap,
1088 .fb_setcolreg = sa1100fb_setcolreg,
1089 .fb_fillrect = cfb_fillrect,
1090 .fb_copyarea = cfb_copyarea,
1091 .fb_imageblit = cfb_imageblit,
1092 .fb_blank = sa1100fb_blank,
1093 .fb_cursor = soft_cursor,
1097 * Calculate the PCD value from the clock rate (in picoseconds).
1098 * We take account of the PPCR clock setting.
1100 static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
1102 unsigned int pcd = cpuclock / 100;
1104 pcd *= pixclock;
1105 pcd /= 10000000;
1107 return pcd + 1; /* make up for integer math truncations */
1111 * sa1100fb_activate_var():
1112 * Configures LCD Controller based on entries in var parameter. Settings are
1113 * only written to the controller if changes were made.
1115 static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
1117 struct sa1100fb_lcd_reg new_regs;
1118 u_int half_screen_size, yres, pcd;
1119 u_long flags;
1121 DPRINTK("Configuring SA1100 LCD\n");
1123 DPRINTK("var: xres=%d hslen=%d lm=%d rm=%d\n",
1124 var->xres, var->hsync_len,
1125 var->left_margin, var->right_margin);
1126 DPRINTK("var: yres=%d vslen=%d um=%d bm=%d\n",
1127 var->yres, var->vsync_len,
1128 var->upper_margin, var->lower_margin);
1130 #if DEBUG_VAR
1131 if (var->xres < 16 || var->xres > 1024)
1132 printk(KERN_ERR "%s: invalid xres %d\n",
1133 fbi->fb.fix.id, var->xres);
1134 if (var->hsync_len < 1 || var->hsync_len > 64)
1135 printk(KERN_ERR "%s: invalid hsync_len %d\n",
1136 fbi->fb.fix.id, var->hsync_len);
1137 if (var->left_margin < 1 || var->left_margin > 255)
1138 printk(KERN_ERR "%s: invalid left_margin %d\n",
1139 fbi->fb.fix.id, var->left_margin);
1140 if (var->right_margin < 1 || var->right_margin > 255)
1141 printk(KERN_ERR "%s: invalid right_margin %d\n",
1142 fbi->fb.fix.id, var->right_margin);
1143 if (var->yres < 1 || var->yres > 1024)
1144 printk(KERN_ERR "%s: invalid yres %d\n",
1145 fbi->fb.fix.id, var->yres);
1146 if (var->vsync_len < 1 || var->vsync_len > 64)
1147 printk(KERN_ERR "%s: invalid vsync_len %d\n",
1148 fbi->fb.fix.id, var->vsync_len);
1149 if (var->upper_margin < 0 || var->upper_margin > 255)
1150 printk(KERN_ERR "%s: invalid upper_margin %d\n",
1151 fbi->fb.fix.id, var->upper_margin);
1152 if (var->lower_margin < 0 || var->lower_margin > 255)
1153 printk(KERN_ERR "%s: invalid lower_margin %d\n",
1154 fbi->fb.fix.id, var->lower_margin);
1155 #endif
1157 new_regs.lccr0 = fbi->lccr0 |
1158 LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
1159 LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
1161 new_regs.lccr1 =
1162 LCCR1_DisWdth(var->xres) +
1163 LCCR1_HorSnchWdth(var->hsync_len) +
1164 LCCR1_BegLnDel(var->left_margin) +
1165 LCCR1_EndLnDel(var->right_margin);
1168 * If we have a dual scan LCD, then we need to halve
1169 * the YRES parameter.
1171 yres = var->yres;
1172 if (fbi->lccr0 & LCCR0_Dual)
1173 yres /= 2;
1175 new_regs.lccr2 =
1176 LCCR2_DisHght(yres) +
1177 LCCR2_VrtSnchWdth(var->vsync_len) +
1178 LCCR2_BegFrmDel(var->upper_margin) +
1179 LCCR2_EndFrmDel(var->lower_margin);
1181 pcd = get_pcd(var->pixclock, cpufreq_get(0));
1182 new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->lccr3 |
1183 (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
1184 (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
1186 DPRINTK("nlccr0 = 0x%08lx\n", new_regs.lccr0);
1187 DPRINTK("nlccr1 = 0x%08lx\n", new_regs.lccr1);
1188 DPRINTK("nlccr2 = 0x%08lx\n", new_regs.lccr2);
1189 DPRINTK("nlccr3 = 0x%08lx\n", new_regs.lccr3);
1191 half_screen_size = var->bits_per_pixel;
1192 half_screen_size = half_screen_size * var->xres * var->yres / 16;
1194 /* Update shadow copy atomically */
1195 local_irq_save(flags);
1196 fbi->dbar1 = fbi->palette_dma;
1197 fbi->dbar2 = fbi->screen_dma + half_screen_size;
1199 fbi->reg_lccr0 = new_regs.lccr0;
1200 fbi->reg_lccr1 = new_regs.lccr1;
1201 fbi->reg_lccr2 = new_regs.lccr2;
1202 fbi->reg_lccr3 = new_regs.lccr3;
1203 local_irq_restore(flags);
1206 * Only update the registers if the controller is enabled
1207 * and something has changed.
1209 if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
1210 (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
1211 (DBAR1 != fbi->dbar1) || (DBAR2 != fbi->dbar2))
1212 sa1100fb_schedule_work(fbi, C_REENABLE);
1214 return 0;
1218 * NOTE! The following functions are purely helpers for set_ctrlr_state.
1219 * Do not call them directly; set_ctrlr_state does the correct serialisation
1220 * to ensure that things happen in the right way 100% of time time.
1221 * -- rmk
1223 static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
1225 DPRINTK("backlight o%s\n", on ? "n" : "ff");
1227 if (sa1100fb_backlight_power)
1228 sa1100fb_backlight_power(on);
1231 static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
1233 DPRINTK("LCD power o%s\n", on ? "n" : "ff");
1235 if (sa1100fb_lcd_power)
1236 sa1100fb_lcd_power(on);
1239 static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
1241 u_int mask = 0;
1244 * Enable GPIO<9:2> for LCD use if:
1245 * 1. Active display, or
1246 * 2. Color Dual Passive display
1248 * see table 11.8 on page 11-27 in the SA1100 manual
1249 * -- Erik.
1251 * SA1110 spec update nr. 25 says we can and should
1252 * clear LDD15 to 12 for 4 or 8bpp modes with active
1253 * panels.
1255 if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
1256 (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
1257 mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
1259 if (fbi->fb.var.bits_per_pixel > 8 ||
1260 (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
1261 mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
1265 if (mask) {
1266 GPDR |= mask;
1267 GAFR |= mask;
1271 static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
1273 DPRINTK("Enabling LCD controller\n");
1276 * Make sure the mode bits are present in the first palette entry
1278 fbi->palette_cpu[0] &= 0xcfff;
1279 fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
1281 /* Sequence from 11.7.10 */
1282 LCCR3 = fbi->reg_lccr3;
1283 LCCR2 = fbi->reg_lccr2;
1284 LCCR1 = fbi->reg_lccr1;
1285 LCCR0 = fbi->reg_lccr0 & ~LCCR0_LEN;
1286 DBAR1 = fbi->dbar1;
1287 DBAR2 = fbi->dbar2;
1288 LCCR0 |= LCCR0_LEN;
1290 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
1291 #error Where is GPIO24 set as an output? Can we fit this in somewhere else?
1292 if (machine_is_graphicsclient()) {
1293 // From ADS doc again...same as disable
1294 msleep(20);
1295 GPSR |= GPIO_GPIO24;
1297 #endif
1299 if (machine_is_shannon()) {
1300 GPDR |= SHANNON_GPIO_DISP_EN;
1301 GPSR |= SHANNON_GPIO_DISP_EN;
1304 DPRINTK("DBAR1 = 0x%08x\n", DBAR1);
1305 DPRINTK("DBAR2 = 0x%08x\n", DBAR2);
1306 DPRINTK("LCCR0 = 0x%08x\n", LCCR0);
1307 DPRINTK("LCCR1 = 0x%08x\n", LCCR1);
1308 DPRINTK("LCCR2 = 0x%08x\n", LCCR2);
1309 DPRINTK("LCCR3 = 0x%08x\n", LCCR3);
1312 static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
1314 DECLARE_WAITQUEUE(wait, current);
1316 DPRINTK("Disabling LCD controller\n");
1318 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
1319 #error Where is GPIO24 set as an output? Can we fit this in somewhere else?
1320 if (machine_is_graphicsclient()) {
1322 * From ADS internal document:
1323 * GPIO24 should be LOW at least 10msec prior to disabling
1324 * the LCD interface.
1326 * We'll wait 20msec.
1328 GPCR |= GPIO_GPIO24;
1329 msleep(20);
1331 #endif
1332 #ifdef CONFIG_SA1100_HUW_WEBPANEL
1333 #error Move me into __sa1100fb_lcd_power and/or __sa1100fb_backlight_power
1334 if (machine_is_huw_webpanel()) {
1335 // don't forget to set the control lines to zero (?)
1336 DPRINTK("ShutDown HuW LCD controller\n");
1337 BCR_clear(BCR_TFT_ENA + BCR_CCFL_POW + BCR_PWM_BACKLIGHT);
1339 #endif
1341 if (machine_is_shannon()) {
1342 GPCR |= SHANNON_GPIO_DISP_EN;
1345 add_wait_queue(&fbi->ctrlr_wait, &wait);
1346 set_current_state(TASK_UNINTERRUPTIBLE);
1348 LCSR = 0xffffffff; /* Clear LCD Status Register */
1349 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
1350 LCCR0 &= ~LCCR0_LEN; /* Disable LCD Controller */
1352 schedule_timeout(20 * HZ / 1000);
1353 remove_wait_queue(&fbi->ctrlr_wait, &wait);
1357 * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
1359 static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
1361 struct sa1100fb_info *fbi = dev_id;
1362 unsigned int lcsr = LCSR;
1364 if (lcsr & LCSR_LDD) {
1365 LCCR0 |= LCCR0_LDM;
1366 wake_up(&fbi->ctrlr_wait);
1369 LCSR = lcsr;
1370 return IRQ_HANDLED;
1374 * This function must be called from task context only, since it will
1375 * sleep when disabling the LCD controller, or if we get two contending
1376 * processes trying to alter state.
1378 static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1380 u_int old_state;
1382 down(&fbi->ctrlr_sem);
1384 old_state = fbi->state;
1387 * Hack around fbcon initialisation.
1389 if (old_state == C_STARTUP && state == C_REENABLE)
1390 state = C_ENABLE;
1392 switch (state) {
1393 case C_DISABLE_CLKCHANGE:
1395 * Disable controller for clock change. If the
1396 * controller is already disabled, then do nothing.
1398 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
1399 fbi->state = state;
1400 sa1100fb_disable_controller(fbi);
1402 break;
1404 case C_DISABLE_PM:
1405 case C_DISABLE:
1407 * Disable controller
1409 if (old_state != C_DISABLE) {
1410 fbi->state = state;
1412 __sa1100fb_backlight_power(fbi, 0);
1413 if (old_state != C_DISABLE_CLKCHANGE)
1414 sa1100fb_disable_controller(fbi);
1415 __sa1100fb_lcd_power(fbi, 0);
1417 break;
1419 case C_ENABLE_CLKCHANGE:
1421 * Enable the controller after clock change. Only
1422 * do this if we were disabled for the clock change.
1424 if (old_state == C_DISABLE_CLKCHANGE) {
1425 fbi->state = C_ENABLE;
1426 sa1100fb_enable_controller(fbi);
1428 break;
1430 case C_REENABLE:
1432 * Re-enable the controller only if it was already
1433 * enabled. This is so we reprogram the control
1434 * registers.
1436 if (old_state == C_ENABLE) {
1437 sa1100fb_disable_controller(fbi);
1438 sa1100fb_setup_gpio(fbi);
1439 sa1100fb_enable_controller(fbi);
1441 break;
1443 case C_ENABLE_PM:
1445 * Re-enable the controller after PM. This is not
1446 * perfect - think about the case where we were doing
1447 * a clock change, and we suspended half-way through.
1449 if (old_state != C_DISABLE_PM)
1450 break;
1451 /* fall through */
1453 case C_ENABLE:
1455 * Power up the LCD screen, enable controller, and
1456 * turn on the backlight.
1458 if (old_state != C_ENABLE) {
1459 fbi->state = C_ENABLE;
1460 sa1100fb_setup_gpio(fbi);
1461 __sa1100fb_lcd_power(fbi, 1);
1462 sa1100fb_enable_controller(fbi);
1463 __sa1100fb_backlight_power(fbi, 1);
1465 break;
1467 up(&fbi->ctrlr_sem);
1471 * Our LCD controller task (which is called when we blank or unblank)
1472 * via keventd.
1474 static void sa1100fb_task(void *dummy)
1476 struct sa1100fb_info *fbi = dummy;
1477 u_int state = xchg(&fbi->task_state, -1);
1479 set_ctrlr_state(fbi, state);
1482 #ifdef CONFIG_CPU_FREQ
1484 * Calculate the minimum DMA period over all displays that we own.
1485 * This, together with the SDRAM bandwidth defines the slowest CPU
1486 * frequency that can be selected.
1488 static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
1490 #if 0
1491 unsigned int min_period = (unsigned int)-1;
1492 int i;
1494 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1495 struct display *disp = &fb_display[i];
1496 unsigned int period;
1499 * Do we own this display?
1501 if (disp->fb_info != &fbi->fb)
1502 continue;
1505 * Ok, calculate its DMA period
1507 period = sa1100fb_display_dma_period(&disp->var);
1508 if (period < min_period)
1509 min_period = period;
1512 return min_period;
1513 #else
1515 * FIXME: we need to verify _all_ consoles.
1517 return sa1100fb_display_dma_period(&fbi->fb.var);
1518 #endif
1522 * CPU clock speed change handler. We need to adjust the LCD timing
1523 * parameters when the CPU clock is adjusted by the power management
1524 * subsystem.
1526 static int
1527 sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
1528 void *data)
1530 struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
1531 struct cpufreq_freqs *f = data;
1532 u_int pcd;
1534 switch (val) {
1535 case CPUFREQ_PRECHANGE:
1536 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1537 break;
1539 case CPUFREQ_POSTCHANGE:
1540 pcd = get_pcd(fbi->fb.var.pixclock, f->new);
1541 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
1542 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1543 break;
1545 return 0;
1548 static int
1549 sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
1550 void *data)
1552 struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
1553 struct cpufreq_policy *policy = data;
1555 switch (val) {
1556 case CPUFREQ_ADJUST:
1557 case CPUFREQ_INCOMPATIBLE:
1558 printk(KERN_DEBUG "min dma period: %d ps, "
1559 "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
1560 policy->max);
1561 /* todo: fill in min/max values */
1562 break;
1563 case CPUFREQ_NOTIFY:
1564 do {} while(0);
1565 /* todo: panic if min/max values aren't fulfilled
1566 * [can't really happen unless there's a bug in the
1567 * CPU policy verififcation process *
1569 break;
1571 return 0;
1573 #endif
1575 #ifdef CONFIG_PM
1577 * Power management hooks. Note that we won't be called from IRQ context,
1578 * unlike the blank functions above, so we may sleep.
1580 static int sa1100fb_suspend(struct device *dev, u32 state, u32 level)
1582 struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1584 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
1585 set_ctrlr_state(fbi, C_DISABLE_PM);
1586 return 0;
1589 static int sa1100fb_resume(struct device *dev, u32 level)
1591 struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1593 if (level == RESUME_ENABLE)
1594 set_ctrlr_state(fbi, C_ENABLE_PM);
1595 return 0;
1597 #else
1598 #define sa1100fb_suspend NULL
1599 #define sa1100fb_resume NULL
1600 #endif
1603 * sa1100fb_map_video_memory():
1604 * Allocates the DRAM memory for the frame buffer. This buffer is
1605 * remapped into a non-cached, non-buffered, memory region to
1606 * allow palette and pixel writes to occur without flushing the
1607 * cache. Once this area is remapped, all virtual memory
1608 * access to the video memory should occur at the new region.
1610 static int __init sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
1613 * We reserve one page for the palette, plus the size
1614 * of the framebuffer.
1616 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
1617 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1618 &fbi->map_dma, GFP_KERNEL);
1620 if (fbi->map_cpu) {
1621 fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
1622 fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
1624 * FIXME: this is actually the wrong thing to place in
1625 * smem_start. But fbdev suffers from the problem that
1626 * it needs an API which doesn't exist (in this case,
1627 * dma_writecombine_mmap)
1629 fbi->fb.fix.smem_start = fbi->screen_dma;
1632 return fbi->map_cpu ? 0 : -ENOMEM;
1635 /* Fake monspecs to fill in fbinfo structure */
1636 static struct fb_monspecs monspecs __initdata = {
1637 .hfmin = 30000,
1638 .hfmax = 70000,
1639 .vfmin = 50,
1640 .vfmax = 65,
1644 static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
1646 struct sa1100fb_mach_info *inf;
1647 struct sa1100fb_info *fbi;
1649 fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
1650 GFP_KERNEL);
1651 if (!fbi)
1652 return NULL;
1654 memset(fbi, 0, sizeof(struct sa1100fb_info));
1655 fbi->dev = dev;
1657 strcpy(fbi->fb.fix.id, SA1100_NAME);
1659 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1660 fbi->fb.fix.type_aux = 0;
1661 fbi->fb.fix.xpanstep = 0;
1662 fbi->fb.fix.ypanstep = 0;
1663 fbi->fb.fix.ywrapstep = 0;
1664 fbi->fb.fix.accel = FB_ACCEL_NONE;
1666 fbi->fb.var.nonstd = 0;
1667 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1668 fbi->fb.var.height = -1;
1669 fbi->fb.var.width = -1;
1670 fbi->fb.var.accel_flags = 0;
1671 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1673 fbi->fb.fbops = &sa1100fb_ops;
1674 fbi->fb.flags = FBINFO_DEFAULT;
1675 fbi->fb.monspecs = monspecs;
1676 fbi->fb.currcon = -1;
1677 fbi->fb.pseudo_palette = (fbi + 1);
1679 fbi->rgb[RGB_8] = &rgb_8;
1680 fbi->rgb[RGB_16] = &def_rgb_16;
1682 inf = sa1100fb_get_machine_info(fbi);
1685 * People just don't seem to get this. We don't support
1686 * anything but correct entries now, so panic if someone
1687 * does something stupid.
1689 if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
1690 inf->pixclock == 0)
1691 panic("sa1100fb error: invalid LCCR3 fields set or zero "
1692 "pixclock.");
1694 fbi->max_xres = inf->xres;
1695 fbi->fb.var.xres = inf->xres;
1696 fbi->fb.var.xres_virtual = inf->xres;
1697 fbi->max_yres = inf->yres;
1698 fbi->fb.var.yres = inf->yres;
1699 fbi->fb.var.yres_virtual = inf->yres;
1700 fbi->max_bpp = inf->bpp;
1701 fbi->fb.var.bits_per_pixel = inf->bpp;
1702 fbi->fb.var.pixclock = inf->pixclock;
1703 fbi->fb.var.hsync_len = inf->hsync_len;
1704 fbi->fb.var.left_margin = inf->left_margin;
1705 fbi->fb.var.right_margin = inf->right_margin;
1706 fbi->fb.var.vsync_len = inf->vsync_len;
1707 fbi->fb.var.upper_margin = inf->upper_margin;
1708 fbi->fb.var.lower_margin = inf->lower_margin;
1709 fbi->fb.var.sync = inf->sync;
1710 fbi->fb.var.grayscale = inf->cmap_greyscale;
1711 fbi->cmap_inverse = inf->cmap_inverse;
1712 fbi->cmap_static = inf->cmap_static;
1713 fbi->lccr0 = inf->lccr0;
1714 fbi->lccr3 = inf->lccr3;
1715 fbi->state = C_STARTUP;
1716 fbi->task_state = (u_char)-1;
1717 fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
1718 fbi->max_bpp / 8;
1720 init_waitqueue_head(&fbi->ctrlr_wait);
1721 INIT_WORK(&fbi->task, sa1100fb_task, fbi);
1722 init_MUTEX(&fbi->ctrlr_sem);
1724 return fbi;
1727 static int __init sa1100fb_probe(struct device *dev)
1729 struct sa1100fb_info *fbi;
1730 int ret;
1732 if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
1733 return -EBUSY;
1735 fbi = sa1100fb_init_fbinfo(dev);
1736 ret = -ENOMEM;
1737 if (!fbi)
1738 goto failed;
1740 /* Initialize video memory */
1741 ret = sa1100fb_map_video_memory(fbi);
1742 if (ret)
1743 goto failed;
1745 ret = request_irq(IRQ_LCD, sa1100fb_handle_irq, SA_INTERRUPT,
1746 "LCD", fbi);
1747 if (ret) {
1748 printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
1749 goto failed;
1752 #ifdef ASSABET_PAL_VIDEO
1753 if (machine_is_assabet())
1754 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
1755 #endif
1757 #ifdef CONFIG_SA1100_FREEBIRD
1758 #error Please move this into __sa1100fb_lcd_power
1759 if (machine_is_freebird()) {
1760 BCR_set(BCR_FREEBIRD_LCD_DISP);
1761 mdelay(20);
1762 BCR_set(BCR_FREEBIRD_LCD_PWR);
1763 mdelay(20);
1765 #endif
1768 * This makes sure that our colour bitfield
1769 * descriptors are correctly initialised.
1771 sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
1773 dev_set_drvdata(dev, fbi);
1775 ret = register_framebuffer(&fbi->fb);
1776 if (ret < 0)
1777 goto failed;
1779 #ifdef CONFIG_CPU_FREQ
1780 fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
1781 fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
1782 cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
1783 cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
1784 #endif
1786 /* This driver cannot be unloaded at the moment */
1787 return 0;
1789 failed:
1790 dev_set_drvdata(dev, NULL);
1791 if (fbi)
1792 kfree(fbi);
1793 release_mem_region(0xb0100000, 0x10000);
1794 return ret;
1797 static struct device_driver sa1100fb_driver = {
1798 .name = "sa11x0-fb",
1799 .bus = &platform_bus_type,
1800 .probe = sa1100fb_probe,
1801 .suspend = sa1100fb_suspend,
1802 .resume = sa1100fb_resume,
1805 int __init sa1100fb_init(void)
1807 if (fb_get_options("sa1100fb", NULL))
1808 return -ENODEV;
1810 return driver_register(&sa1100fb_driver);
1813 int __init sa1100fb_setup(char *options)
1815 #if 0
1816 char *this_opt;
1818 if (!options || !*options)
1819 return 0;
1821 while ((this_opt = strsep(&options, ",")) != NULL) {
1823 if (!strncmp(this_opt, "bpp:", 4))
1824 current_par.max_bpp =
1825 simple_strtoul(this_opt + 4, NULL, 0);
1827 if (!strncmp(this_opt, "lccr0:", 6))
1828 lcd_shadow.lccr0 =
1829 simple_strtoul(this_opt + 6, NULL, 0);
1830 if (!strncmp(this_opt, "lccr1:", 6)) {
1831 lcd_shadow.lccr1 =
1832 simple_strtoul(this_opt + 6, NULL, 0);
1833 current_par.max_xres =
1834 (lcd_shadow.lccr1 & 0x3ff) + 16;
1836 if (!strncmp(this_opt, "lccr2:", 6)) {
1837 lcd_shadow.lccr2 =
1838 simple_strtoul(this_opt + 6, NULL, 0);
1839 current_par.max_yres =
1840 (lcd_shadow.
1841 lccr0 & LCCR0_SDS) ? ((lcd_shadow.
1842 lccr2 & 0x3ff) +
1843 1) *
1844 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
1846 if (!strncmp(this_opt, "lccr3:", 6))
1847 lcd_shadow.lccr3 =
1848 simple_strtoul(this_opt + 6, NULL, 0);
1850 #endif
1851 return 0;
1854 module_init(sa1100fb_init);
1855 MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
1856 MODULE_LICENSE("GPL");