patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / video / sa1100fb.c
1 /*
2  *  linux/drivers/video/sa1100fb.c
3  *
4  *  Copyright (C) 1999 Eric A. Thomas
5  *   Based on acornfb.c Copyright (C) Russell King.
6  *
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.
10  *
11  *              StrongARM 1100 LCD Controller Frame Buffer Driver
12  *
13  * Please direct your questions and comments on this driver to the following
14  * email address:
15  *
16  *      linux-arm-kernel@lists.arm.linux.org.uk
17  *
18  * Clean patches should be sent to the ARM Linux Patch System.  Please see the
19  * following web page for more information:
20  *
21  *      http://www.arm.linux.org.uk/developer/patches/info.shtml
22  *
23  * Thank you.
24  *
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.
31  *
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.
37  *
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.
43  *
44  *      - The following must never be specified in a panel definition:
45  *           LCCR0_LtlEnd, LCCR3_PixClkDiv, LCCR3_VrtSnchL, LCCR3_HorSnchL
46  *
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
54  *
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. 
64  *
65  * 1999/06/17:
66  *      - FrameBuffer memory is now allocated at run-time when the
67  *        driver is initialized.    
68  *
69  * 2000/04/10: Nicolas Pitre <nico@cam.org>
70  *      - Big cleanup for dynamic selection of machine type at run time.
71  *
72  * 2000/07/19: Jamey Hicks <jamey@crl.dec.com>
73  *      - Support for Bitsy aka Compaq iPAQ H3600 added.
74  *
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.
81  *
82  * 2000/08/09: Kunihiko IMAI <imai@vasara.co.jp>
83  *      - XP860 support added
84  *
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.
88  *
89  * 2000/08/29:
90  *      - s/save_flags_cli/local_irq_save/
91  *      - remove unneeded extra save_flags_cli in sa1100fb_enable_lcd_controller
92  *
93  * 2000/10/10: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
94  *      - Updated LART stuff. Fixed some minor bugs.
95  *
96  * 2000/10/30: Murphy Chen <murphy@mail.dialogue.com.tw>
97  *      - Pangolin support added
98  *
99  * 2000/10/31: Roman Jordan <jor@hoeft-wessel.de>
100  *      - Huw Webpanel support added
101  *
102  * 2000/11/23: Eric Peng <ericpeng@coventive.com>
103  *      - Freebird add
104  *
105  * 2001/02/07: Jamey Hicks <jamey.hicks@compaq.com> 
106  *             Cliff Brake <cbrake@accelent.com>
107  *      - Added PM callback
108  *
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)
119  *
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.
124  *
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)
128  *
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. ;)
133  *
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.
138  *
139  * 2001/07/02: <rmk@arm.linux.org.uk>
140  *      - Fix colourmap problems.
141  *
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
145  *
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.
152  *
153  * 2001/07/27: <rmk@arm.linux.org.uk>
154  *      - Halve YRES on dual scan LCDs.
155  *
156  * 2001/08/22: <rmk@arm.linux.org.uk>
157  *      - Add b/w iPAQ pixclock value.
158  *
159  * 2001/10/12: <rmk@arm.linux.org.uk>
160  *      - Add patch 681/1 and clean up stork definitions.
161  */
162
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>
178
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>
186
187 /*
188  * debugging?
189  */
190 #define DEBUG 0
191 /*
192  * Complain if VAR is out of range.
193  */
194 #define DEBUG_VAR 1
195
196 #undef ASSABET_PAL_VIDEO
197
198 #include "sa1100fb.h"
199
200 extern void (*sa1100fb_backlight_power)(int on);
201 extern void (*sa1100fb_lcd_power)(int on);
202
203 /*
204  * IMHO this looks wrong.  In 8BPP, length should be 8.
205  */
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, },
211 };
212
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, },
218 };
219
220 #ifdef CONFIG_SA1100_ASSABET
221 #ifndef ASSABET_PAL_VIDEO
222 /*
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).
226  */
227 static struct sa1100fb_mach_info lq039q2ds54_info __initdata = {
228         .pixclock       = 171521,       .bpp            = 16,
229         .xres           = 320,          .yres           = 240,
230
231         .hsync_len      = 5,            .vsync_len      = 1,
232         .left_margin    = 61,           .upper_margin   = 3,
233         .right_margin   = 9,            .lower_margin   = 0,
234
235         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
236
237         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
238         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
239 };
240 #else
241 static struct sa1100fb_mach_info pal_info __initdata = {
242         .pixclock       = 67797,        .bpp            = 16,
243         .xres           = 640,          .yres           = 512,
244
245         .hsync_len      = 64,           .vsync_len      = 6,
246         .left_margin    = 125,          .upper_margin   = 70,
247         .right_margin   = 115,          .lower_margin   = 36,
248
249         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
250         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
251 };
252 #endif
253 #endif
254
255 #ifdef CONFIG_SA1100_H3800
256 static struct sa1100fb_mach_info h3800_info __initdata = {
257         .pixclock       = 174757,       .bpp            = 16,
258         .xres           = 320,          .yres           = 240,
259
260         .hsync_len      = 3,            .vsync_len      = 3,
261         .left_margin    = 12,           .upper_margin   = 10,
262         .right_margin   = 17,           .lower_margin   = 1,
263
264         .cmap_static    = 1,
265
266         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
267         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
268 };
269 #endif
270
271 #ifdef CONFIG_SA1100_H3600
272 static struct sa1100fb_mach_info h3600_info __initdata = {
273         .pixclock       = 174757,       .bpp            = 16,
274         .xres           = 320,          .yres           = 240,
275
276         .hsync_len      = 3,            .vsync_len      = 3,
277         .left_margin    = 12,           .upper_margin   = 10,
278         .right_margin   = 17,           .lower_margin   = 1,
279
280         .cmap_static    = 1,
281
282         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
283         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
284 };
285
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, },
291 };
292 #endif
293
294 #ifdef CONFIG_SA1100_H3100
295 static struct sa1100fb_mach_info h3100_info __initdata = {
296         .pixclock       = 406977,       .bpp            = 4,
297         .xres           = 320,          .yres           = 240,
298
299         .hsync_len      = 26,           .vsync_len      = 41,
300         .left_margin    = 4,            .upper_margin   = 0,
301         .right_margin   = 4,            .lower_margin   = 0,
302
303         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
304         .cmap_greyscale = 1,
305         .cmap_inverse   = 1,
306
307         .lccr0          = LCCR0_Mono | LCCR0_4PixMono | LCCR0_Sngl | LCCR0_Pas,
308         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
309 };
310 #endif
311
312 #ifdef CONFIG_SA1100_BRUTUS
313 static struct sa1100fb_mach_info brutus_info __initdata = {
314         .pixclock       = 0,            .bpp            = 8,
315         .xres           = 320,          .yres           = 240,
316
317         .hsync_len      = 3,            .vsync_len      = 1,
318         .left_margin    = 41,           .upper_margin   = 0,
319         .right_margin   = 101,          .lower_margin   = 0,
320
321         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
322
323         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Pas,
324         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2) |
325                           LCCR3_PixClkDiv(44),
326 };
327 #endif
328
329 #ifdef CONFIG_SA1100_COLLIE
330 static struct sa1100fb_mach_info collie_info __initdata = {
331         pixclock:       171521,         bpp:            16,
332         xres:           320,            yres:           240,
333
334         hsync_len:      5,              vsync_len:      1,
335         left_margin:    11,             upper_margin:   2,
336         right_margin:   30,             lower_margin:   0,
337
338         sync:           FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
339
340         lccr0:          LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
341         lccr3:          LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
342 };
343 #endif
344
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,
350
351         .hsync_len      = 3,            .vsync_len      = 2,
352         .left_margin    = 2,            .upper_margin   = 0,
353         .right_margin   = 2,            .lower_margin   = 0,
354
355         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
356
357         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Pas,
358         .lccr3          = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(2),
359 };
360
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, },
366 };
367 #endif
368
369 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
370 static struct sa1100fb_mach_info graphicsclient_info __initdata = {
371         .pixclock       = 53500,        .bpp            = 8,
372         .xres           = 640,          .yres           = 480,
373
374         .hsync_len      = 9,            .vsync_len      = 9,
375         .left_margin    = 54,           .upper_margin   = 24,
376         .right_margin   = 54,           .lower_margin   = 32,
377
378         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
379         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
380 };
381 #endif
382
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,
387
388         .hsync_len      = 3,            .vsync_len      = 1,
389         .left_margin    = 41,           .upper_margin   = 0,
390         .right_margin   = 101,          .lower_margin   = 0,
391
392         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
393
394         .lccr0          = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
395         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2) | 8,
396 #error FIXME
397         /*
398          * FIXME: please get rid of the '| 8' in preference to an
399          * LCCR3_PixClkDiv() version. --rmk
400          */
401 };
402 #endif
403
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,
408
409         .hsync_len      = 1,            .vsync_len      = 1,
410         .left_margin    = 4,            .upper_margin   = 0,
411         .right_margin   = 2,            .lower_margin   = 0,
412
413         .cmap_greyscale = 1,
414         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
415
416         .lccr0          = LCCR0_Mono | LCCR0_Sngl | LCCR0_Pas | LCCR0_4PixMono,
417         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
418 };
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,
424
425         .hsync_len      = 2,            .vsync_len      = 3,
426         .left_margin    = 69,           .upper_margin   = 14,
427         .right_margin   = 8,            .lower_margin   = 4,
428
429         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
430         .lccr3          = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
431 };
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,
437
438         .hsync_len      = 95,           .vsync_len      = 2,
439         .left_margin    = 40,           .upper_margin   = 32,
440         .right_margin   = 24,           .lower_margin   = 11,
441
442         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
443
444         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
445         .lccr3          = LCCR3_OutEnL | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
446 };
447 #endif
448
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,
453
454         .hsync_len      = 64,           .vsync_len      = 3,
455         .left_margin    = 122,          .upper_margin   = 45,
456         .right_margin   = 10,           .lower_margin   = 10,
457
458         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
459         .lccr3          = LCCR3_OutEnH | LCCR3_PixFlEdg
460 };
461 #endif
462
463 #ifdef CONFIG_SA1100_SHANNON
464 static struct sa1100fb_mach_info shannon_info __initdata = {
465         .pixclock       = 152500,       .bpp            = 8,
466         .xres           = 640,          .yres           = 480,
467
468         .hsync_len      = 4,            .vsync_len      = 3,
469         .left_margin    = 2,            .upper_margin   = 0,
470         .right_margin   = 1,            .lower_margin   = 0,
471
472         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 
473
474         .lccr0          = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
475         .lccr3          = LCCR3_ACBsDiv(512),
476 };
477 #endif
478
479 #ifdef CONFIG_SA1100_OMNIMETER
480 static struct sa1100fb_mach_info omnimeter_info __initdata = {
481         .pixclock       = 0,            .bpp            = 4,
482         .xres           = 480,          .yres           = 320,
483
484         .hsync_len      = 1,            .vsync_len      = 1,
485         .left_margin    = 10,           .upper_margin   = 0,
486         .right_margin   = 10,           .lower_margin   = 0,
487
488         .cmap_greyscale = 1,
489         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
490
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
495         /*
496          * FIXME: I think ACBsDiv is wrong above - should it be 512 (disabled)?
497          *   - rmk
498          */
499 };
500 #endif
501
502 #ifdef CONFIG_SA1100_PANGOLIN
503 static struct sa1100fb_mach_info pangolin_info __initdata = {
504         .pixclock       = 341521,       .bpp            = 16,
505         .xres           = 800,          .yres           = 600,
506
507         .hsync_len      = 64,           .vsync_len      = 7,
508         .left_margin    = 160,          .upper_margin   = 7,
509         .right_margin   = 24,           .lower_margin   = 1,
510
511         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
512
513         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
514         .lccr3          = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsCntOff,
515 };
516 #endif
517
518 #ifdef CONFIG_SA1100_STORK
519 #if STORK_TFT                   /* ie the NEC TFT */
520 /*
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
524  */
525 static struct sa1100fb_mach_info stork_tft_info __initdata = {
526         .pixclock       = 28935,        .bpp            = 16,
527         .xres           = 640,          .yres           = 480,
528
529         .hsync_len      = 64,           .vsync_len      = 2,
530         .left_margin    = 48,           .upper_margin   = 12,
531         .right_margin   = 48,           .lower_margin   = 31,
532
533         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
534         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsCntOff,
535 };
536
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, },
542 };
543
544 #else   /* Kyocera DSTN */
545
546 static struct sa1100fb_mach_info stork_dstn_info __initdata = {
547         .pixclock       = 0,            .bpp            = 16,
548         .xres           = 640,          .yres           = 480,
549
550         .hsync_len      = 2,            .vsync_len      = 2,
551         .left_margin    = 2,            .upper_margin   = 0,
552         .right_margin   = 2,            .lower_margin   = 0,
553
554         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT ,
555
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 */
560 };
561
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, },
567 };
568 #endif
569 #endif
570
571 #ifdef CONFIG_SA1100_PT_SYSTEM3
572 /*
573  * 648 x 480 x 8bpp x 75Hz Dual Panel Color STN Display
574  *
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
581  */
582 static struct sa1100fb_mach_info system3_info __initdata = {
583         .pixclock       = 231481,       .bpp            = 8,
584         .xres           = 640,          .yres           = 480,
585
586         .hsync_len      = 2,            .vsync_len      = 2,
587         .left_margin    = 2,            .upper_margin   = 0,
588         .right_margin   = 2,            .lower_margin   = 0,
589
590         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
591
592         .lccr0          = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
593         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
594 };
595 #endif
596
597 #ifdef CONFIG_SA1100_XP860
598 static struct sa1100fb_mach_info xp860_info __initdata = {
599         .pixclock       = 0,            .bpp            = 8,
600         .xres           = 1024,         .yres           = 768,
601
602         .hsync_len      = 3,            .vsync_len      = 3,
603         .left_margin    = 3,            .upper_margin   = 2,
604         .right_margin   = 2,            .lower_margin   = 1,
605
606         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
607         .lccr3          = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_PixClkDiv(6),
608 };
609 #endif
610
611
612
613 static struct sa1100fb_mach_info * __init
614 sa1100fb_get_machine_info(struct sa1100fb_info *fbi)
615 {
616         struct sa1100fb_mach_info *inf = NULL;
617
618         /*
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}
623          */
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
631         }
632 #endif
633 #ifdef CONFIG_SA1100_H3100
634         if (machine_is_h3100()) {
635                 inf = &h3100_info;
636         }
637 #endif
638 #ifdef CONFIG_SA1100_H3600
639         if (machine_is_h3600()) {
640                 inf = &h3600_info;
641                 fbi->rgb[RGB_16] = &h3600_rgb_16;
642         }
643 #endif
644 #ifdef CONFIG_SA1100_H3800
645         if (machine_is_h3800()) {
646                 inf = &h3800_info;
647         }
648 #endif
649 #ifdef CONFIG_SA1100_BRUTUS
650         if (machine_is_brutus()) {
651                 inf = &brutus_info;
652         }
653 #endif
654 #ifdef CONFIG_SA1100_COLLIE
655         if (machine_is_collie()) {
656                 inf = &collie_info;
657         }
658 #endif
659 #ifdef CONFIG_SA1100_FREEBIRD
660         if (machine_is_freebird()) {
661                 inf = &freebird_info;
662                 fbi->rgb[RGB_16] = &freebird_rgb16;
663         }
664 #endif
665 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
666         if (machine_is_graphicsclient()) {
667                 inf = &graphicsclient_info;
668         }
669 #endif
670 #ifdef CONFIG_SA1100_HUW_WEBPANEL
671         if (machine_is_huw_webpanel()) {
672                 inf = &huw_webpanel_info;
673         }
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
689         }
690 #endif
691 #ifdef CONFIG_SA1100_OMNIMETER
692         if (machine_is_omnimeter()) {
693                 inf = &omnimeter_info;
694         }
695 #endif
696 #ifdef CONFIG_SA1100_PANGOLIN
697         if (machine_is_pangolin()) {
698                 inf = &pangolin_info;
699         }
700 #endif
701 #ifdef CONFIG_SA1100_PT_SYSTEM3
702         if (machine_is_pt_system3()) {
703                 inf = &system3_info;
704         }
705 #endif
706 #ifdef CONFIG_SA1100_SHANNON
707         if (machine_is_shannon()) {
708                 inf = &shannon_info;
709         }
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
720         }
721 #endif
722 #ifdef CONFIG_SA1100_XP860
723         if (machine_is_xp860()) {
724                 inf = &xp860_info;
725         }
726 #endif
727         return inf;
728 }
729
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);
732
733 static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
734 {
735         unsigned long flags;
736
737         local_irq_save(flags);
738         /*
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.
745          */
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;
750
751         if (state != (u_int)-1) {
752                 fbi->task_state = state;
753                 schedule_work(&fbi->task);
754         }
755         local_irq_restore(flags);
756 }
757
758 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
759 {
760         chan &= 0xffff;
761         chan >>= 16 - bf->length;
762         return chan << bf->offset;
763 }
764
765 /*
766  * Convert bits-per-pixel to a hardware palette PBS value.
767  */
768 static inline u_int palette_pbs(struct fb_var_screeninfo *var)
769 {
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;
775         }
776         return ret;
777 }
778
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)
782 {
783         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
784         u_int val, ret = 1;
785
786         if (regno < fbi->palette_size) {
787                 val = ((red >> 4) & 0xf00);
788                 val |= ((green >> 8) & 0x0f0);
789                 val |= ((blue >> 12) & 0x00f);
790
791                 if (regno == 0)
792                         val |= palette_pbs(&fbi->fb.var);
793
794                 fbi->palette_cpu[regno] = val;
795                 ret = 0;
796         }
797         return ret;
798 }
799
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)
803 {
804         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
805         unsigned int val;
806         int ret = 1;
807
808         /*
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.
813          */
814         if (fbi->cmap_inverse) {
815                 red   = 0xffff - red;
816                 green = 0xffff - green;
817                 blue  = 0xffff - blue;
818         }
819
820         /*
821          * If greyscale is true, then we convert the RGB value
822          * to greyscale no mater what visual we are using.
823          */
824         if (fbi->fb.var.grayscale)
825                 red = green = blue = (19595 * red + 38470 * green +
826                                         7471 * blue) >> 16;
827
828         switch (fbi->fb.fix.visual) {
829         case FB_VISUAL_TRUECOLOR:
830                 /*
831                  * 12 or 16-bit True Colour.  We encode the RGB value
832                  * according to the RGB bitfield information.
833                  */
834                 if (regno < 16) {
835                         u32 *pal = fbi->fb.pseudo_palette;
836
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);
840
841                         pal[regno] = val;
842                         ret = 0;
843                 }
844                 break;
845
846         case FB_VISUAL_STATIC_PSEUDOCOLOR:
847         case FB_VISUAL_PSEUDOCOLOR:
848                 ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
849                 break;
850         }
851
852         return ret;
853 }
854
855 /*
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.
860  */
861 static unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
862 {
863         /*
864          * Period = pixclock * bits_per_byte * bytes_per_transfer
865          *              / memory_bits_per_pixel;
866          */
867         return var->pixclock * 8 * 16 / var->bits_per_pixel;
868 }
869
870 /*
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.
875  */
876 static int
877 sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
878 {
879         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
880         int rgbidx;
881
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);
892
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;
906         }
907
908         /*
909          * Copy the RGB parameters for this display
910          * from the machine specific parameters.
911          */
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;
916
917         DPRINTK("RGBT length = %d:%d:%d:%d\n",
918                 var->red.length, var->green.length, var->blue.length,
919                 var->transp.length);
920
921         DPRINTK("RGBT offset = %d:%d:%d:%d\n",
922                 var->red.offset, var->green.offset, var->blue.offset,
923                 var->transp.offset);
924
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
930
931         return 0;
932 }
933
934 static inline void sa1100fb_set_truecolor(u_int is_true_color)
935 {
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
949         }
950 }
951
952 /*
953  * sa1100fb_set_par():
954  *      Set the user defined part of the display for the specified console
955  */
956 static int sa1100fb_set_par(struct fb_info *info)
957 {
958         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
959         struct fb_var_screeninfo *var = &info->var;
960         unsigned long palette_mem_size;
961
962         DPRINTK("set_par\n");
963
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 {
969                 /*
970                  * Some people have weird ideas about wanting static
971                  * pseudocolor maps.  I suspect their user space
972                  * applications are broken.
973                  */
974                 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
975         }
976
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;
980
981         palette_mem_size = fbi->palette_size * sizeof(u16);
982
983         DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
984
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;
987
988         /*
989          * Set (any) board control register to handle new color depth
990          */
991         sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
992
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
998
999         sa1100fb_activate_var(var, fbi);
1000
1001         return 0;
1002 }
1003
1004 #if 0
1005 static int
1006 sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
1007                   struct fb_info *info)
1008 {
1009         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
1010
1011         /*
1012          * Make sure the user isn't doing something stupid.
1013          */
1014         if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
1015                 return -EINVAL;
1016
1017         return gen_set_cmap(cmap, kspc, con, info);
1018 }
1019 #endif
1020
1021 /*
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
1036  *
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.
1040  *
1041  *  So here's what we should do in our fbdev blank routine:
1042  *
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
1047  *
1048  *  This will match the matrox implementation.
1049  */
1050 /*
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.  
1055  */
1056 static int sa1100fb_blank(int blank, struct fb_info *info)
1057 {
1058         struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
1059         int i;
1060
1061         DPRINTK("sa1100fb_blank: blank=%d\n", blank);
1062
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;
1073
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, 1, info);
1078                 sa1100fb_schedule_work(fbi, C_ENABLE);
1079         }
1080         return 0;
1081 }
1082
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,
1094 };
1095
1096 /*
1097  * Calculate the PCD value from the clock rate (in picoseconds).
1098  * We take account of the PPCR clock setting.
1099  */
1100 static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
1101 {
1102         unsigned int pcd = cpuclock / 100;
1103
1104         pcd *= pixclock;
1105         pcd /= 10000000;
1106
1107         return pcd + 1; /* make up for integer math truncations */
1108 }
1109
1110 /*
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.  
1114  */
1115 static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
1116 {
1117         struct sa1100fb_lcd_reg new_regs;
1118         u_int half_screen_size, yres, pcd;
1119         u_long flags;
1120
1121         DPRINTK("Configuring SA1100 LCD\n");
1122
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);
1129
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
1156
1157         new_regs.lccr0 = fbi->lccr0 |
1158                 LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
1159                 LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
1160
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);
1166
1167         /*
1168          * If we have a dual scan LCD, then we need to halve
1169          * the YRES parameter.
1170          */
1171         yres = var->yres;
1172         if (fbi->lccr0 & LCCR0_Dual)
1173                 yres /= 2;
1174
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);
1180
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);
1185
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);
1190
1191         half_screen_size = var->bits_per_pixel;
1192         half_screen_size = half_screen_size * var->xres * var->yres / 16;
1193
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;
1198
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);
1204
1205         /*
1206          * Only update the registers if the controller is enabled
1207          * and something has changed.
1208          */
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);
1213
1214         return 0;
1215 }
1216
1217 /*
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
1222  */
1223 static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
1224 {
1225         DPRINTK("backlight o%s\n", on ? "n" : "ff");
1226
1227         if (sa1100fb_backlight_power)
1228                 sa1100fb_backlight_power(on);
1229 }
1230
1231 static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
1232 {
1233         DPRINTK("LCD power o%s\n", on ? "n" : "ff");
1234
1235         if (sa1100fb_lcd_power)
1236                 sa1100fb_lcd_power(on);
1237 }
1238
1239 static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
1240 {
1241         u_int mask = 0;
1242
1243         /*
1244          * Enable GPIO<9:2> for LCD use if:
1245          *  1. Active display, or
1246          *  2. Color Dual Passive display
1247          *
1248          * see table 11.8 on page 11-27 in the SA1100 manual
1249          *   -- Erik.
1250          *
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.  
1254          */
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;
1258
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;
1262
1263         }
1264
1265         if (mask) {
1266                 GPDR |= mask;
1267                 GAFR |= mask;
1268         }
1269 }
1270
1271 static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
1272 {
1273         DPRINTK("Enabling LCD controller\n");
1274
1275         /*
1276          * Make sure the mode bits are present in the first palette entry
1277          */
1278         fbi->palette_cpu[0] &= 0xcfff;
1279         fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
1280
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;
1289
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                 set_current_state(TASK_UNINTERRUPTIBLE);
1295                 schedule_timeout(20 * HZ / 1000);
1296                 GPSR |= GPIO_GPIO24;
1297         }
1298 #endif
1299
1300         if (machine_is_shannon()) {
1301                 GPDR |= SHANNON_GPIO_DISP_EN;
1302                 GPSR |= SHANNON_GPIO_DISP_EN;
1303         }       
1304
1305         DPRINTK("DBAR1 = 0x%08x\n", DBAR1);
1306         DPRINTK("DBAR2 = 0x%08x\n", DBAR2);
1307         DPRINTK("LCCR0 = 0x%08x\n", LCCR0);
1308         DPRINTK("LCCR1 = 0x%08x\n", LCCR1);
1309         DPRINTK("LCCR2 = 0x%08x\n", LCCR2);
1310         DPRINTK("LCCR3 = 0x%08x\n", LCCR3);
1311 }
1312
1313 static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
1314 {
1315         DECLARE_WAITQUEUE(wait, current);
1316
1317         DPRINTK("Disabling LCD controller\n");
1318
1319 #ifdef CONFIG_SA1100_GRAPHICSCLIENT
1320 #error Where is GPIO24 set as an output?  Can we fit this in somewhere else?
1321         if (machine_is_graphicsclient()) {
1322                 /*
1323                  * From ADS internal document:
1324                  *  GPIO24 should be LOW at least 10msec prior to disabling
1325                  *  the LCD interface.
1326                  *
1327                  * We'll wait 20msec.
1328                  */
1329                 GPCR |= GPIO_GPIO24;
1330                 set_current_state(TASK_UNINTERRUPTIBLE);
1331                 schedule_timeout(20 * HZ / 1000);
1332         }
1333 #endif
1334 #ifdef CONFIG_SA1100_HUW_WEBPANEL
1335 #error Move me into __sa1100fb_lcd_power and/or __sa1100fb_backlight_power
1336         if (machine_is_huw_webpanel()) {
1337                 // don't forget to set the control lines to zero (?)
1338                 DPRINTK("ShutDown HuW LCD controller\n");
1339                 BCR_clear(BCR_TFT_ENA + BCR_CCFL_POW + BCR_PWM_BACKLIGHT);
1340         }
1341 #endif
1342
1343         if (machine_is_shannon()) {
1344                 GPCR |= SHANNON_GPIO_DISP_EN;
1345         }       
1346
1347         add_wait_queue(&fbi->ctrlr_wait, &wait);
1348         set_current_state(TASK_UNINTERRUPTIBLE);
1349
1350         LCSR = 0xffffffff;      /* Clear LCD Status Register */
1351         LCCR0 &= ~LCCR0_LDM;    /* Enable LCD Disable Done Interrupt */
1352         LCCR0 &= ~LCCR0_LEN;    /* Disable LCD Controller */
1353
1354         schedule_timeout(20 * HZ / 1000);
1355         remove_wait_queue(&fbi->ctrlr_wait, &wait);
1356 }
1357
1358 /*
1359  *  sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
1360  */
1361 static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
1362 {
1363         struct sa1100fb_info *fbi = dev_id;
1364         unsigned int lcsr = LCSR;
1365
1366         if (lcsr & LCSR_LDD) {
1367                 LCCR0 |= LCCR0_LDM;
1368                 wake_up(&fbi->ctrlr_wait);
1369         }
1370
1371         LCSR = lcsr;
1372         return IRQ_HANDLED;
1373 }
1374
1375 /*
1376  * This function must be called from task context only, since it will
1377  * sleep when disabling the LCD controller, or if we get two contending
1378  * processes trying to alter state.
1379  */
1380 static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1381 {
1382         u_int old_state;
1383
1384         down(&fbi->ctrlr_sem);
1385
1386         old_state = fbi->state;
1387
1388         /*
1389          * Hack around fbcon initialisation.
1390          */
1391         if (old_state == C_STARTUP && state == C_REENABLE)
1392                 state = C_ENABLE;
1393
1394         switch (state) {
1395         case C_DISABLE_CLKCHANGE:
1396                 /*
1397                  * Disable controller for clock change.  If the
1398                  * controller is already disabled, then do nothing.
1399                  */
1400                 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
1401                         fbi->state = state;
1402                         sa1100fb_disable_controller(fbi);
1403                 }
1404                 break;
1405
1406         case C_DISABLE_PM:
1407         case C_DISABLE:
1408                 /*
1409                  * Disable controller
1410                  */
1411                 if (old_state != C_DISABLE) {
1412                         fbi->state = state;
1413
1414                         __sa1100fb_backlight_power(fbi, 0);
1415                         if (old_state != C_DISABLE_CLKCHANGE)
1416                                 sa1100fb_disable_controller(fbi);
1417                         __sa1100fb_lcd_power(fbi, 0);
1418                 }
1419                 break;
1420
1421         case C_ENABLE_CLKCHANGE:
1422                 /*
1423                  * Enable the controller after clock change.  Only
1424                  * do this if we were disabled for the clock change.
1425                  */
1426                 if (old_state == C_DISABLE_CLKCHANGE) {
1427                         fbi->state = C_ENABLE;
1428                         sa1100fb_enable_controller(fbi);
1429                 }
1430                 break;
1431
1432         case C_REENABLE:
1433                 /*
1434                  * Re-enable the controller only if it was already
1435                  * enabled.  This is so we reprogram the control
1436                  * registers.
1437                  */
1438                 if (old_state == C_ENABLE) {
1439                         sa1100fb_disable_controller(fbi);
1440                         sa1100fb_setup_gpio(fbi);
1441                         sa1100fb_enable_controller(fbi);
1442                 }
1443                 break;
1444
1445         case C_ENABLE_PM:
1446                 /*
1447                  * Re-enable the controller after PM.  This is not
1448                  * perfect - think about the case where we were doing
1449                  * a clock change, and we suspended half-way through.
1450                  */
1451                 if (old_state != C_DISABLE_PM)
1452                         break;
1453                 /* fall through */
1454
1455         case C_ENABLE:
1456                 /*
1457                  * Power up the LCD screen, enable controller, and
1458                  * turn on the backlight.
1459                  */
1460                 if (old_state != C_ENABLE) {
1461                         fbi->state = C_ENABLE;
1462                         sa1100fb_setup_gpio(fbi);
1463                         __sa1100fb_lcd_power(fbi, 1);
1464                         sa1100fb_enable_controller(fbi);
1465                         __sa1100fb_backlight_power(fbi, 1);
1466                 }
1467                 break;
1468         }
1469         up(&fbi->ctrlr_sem);
1470 }
1471
1472 /*
1473  * Our LCD controller task (which is called when we blank or unblank)
1474  * via keventd.
1475  */
1476 static void sa1100fb_task(void *dummy)
1477 {
1478         struct sa1100fb_info *fbi = dummy;
1479         u_int state = xchg(&fbi->task_state, -1);
1480
1481         set_ctrlr_state(fbi, state);
1482 }
1483
1484 #ifdef CONFIG_CPU_FREQ
1485 /*
1486  * Calculate the minimum DMA period over all displays that we own.
1487  * This, together with the SDRAM bandwidth defines the slowest CPU
1488  * frequency that can be selected.
1489  */
1490 static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
1491 {
1492 #if 0
1493         unsigned int min_period = (unsigned int)-1;
1494         int i;
1495
1496         for (i = 0; i < MAX_NR_CONSOLES; i++) {
1497                 struct display *disp = &fb_display[i];
1498                 unsigned int period;
1499
1500                 /*
1501                  * Do we own this display?
1502                  */
1503                 if (disp->fb_info != &fbi->fb)
1504                         continue;
1505
1506                 /*
1507                  * Ok, calculate its DMA period
1508                  */
1509                 period = sa1100fb_display_dma_period(&disp->var);
1510                 if (period < min_period)
1511                         min_period = period;
1512         }
1513
1514         return min_period;
1515 #else
1516         /*
1517          * FIXME: we need to verify _all_ consoles.
1518          */
1519         return sa1100fb_display_dma_period(&fbi->fb.var);
1520 #endif
1521 }
1522
1523 /*
1524  * CPU clock speed change handler.  We need to adjust the LCD timing
1525  * parameters when the CPU clock is adjusted by the power management
1526  * subsystem.
1527  */
1528 static int
1529 sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
1530                          void *data)
1531 {
1532         struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
1533         struct cpufreq_freqs *f = data;
1534         u_int pcd;
1535
1536         switch (val) {
1537         case CPUFREQ_PRECHANGE:
1538                 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1539                 break;
1540
1541         case CPUFREQ_POSTCHANGE:
1542                 pcd = get_pcd(fbi->fb.var.pixclock, f->new);
1543                 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
1544                 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1545                 break;
1546         }
1547         return 0;
1548 }
1549
1550 static int
1551 sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
1552                      void *data)
1553 {
1554         struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
1555         struct cpufreq_policy *policy = data;
1556
1557         switch (val) {
1558         case CPUFREQ_ADJUST:
1559         case CPUFREQ_INCOMPATIBLE:
1560                 printk(KERN_DEBUG "min dma period: %d ps, "
1561                         "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
1562                         policy->max);
1563                 /* todo: fill in min/max values */
1564                 break;
1565         case CPUFREQ_NOTIFY:
1566                 do {} while(0);
1567                 /* todo: panic if min/max values aren't fulfilled 
1568                  * [can't really happen unless there's a bug in the
1569                  * CPU policy verififcation process *
1570                  */
1571                 break;
1572         }
1573         return 0;
1574 }
1575 #endif
1576
1577 #ifdef CONFIG_PM
1578 /*
1579  * Power management hooks.  Note that we won't be called from IRQ context,
1580  * unlike the blank functions above, so we may sleep.
1581  */
1582 static int sa1100fb_suspend(struct device *dev, u32 state, u32 level)
1583 {
1584         struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1585
1586         if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
1587                 set_ctrlr_state(fbi, C_DISABLE_PM);
1588         return 0;
1589 }
1590
1591 static int sa1100fb_resume(struct device *dev, u32 level)
1592 {
1593         struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1594
1595         if (level == RESUME_ENABLE)
1596                 set_ctrlr_state(fbi, C_ENABLE_PM);
1597         return 0;
1598 }
1599 #else
1600 #define sa1100fb_suspend        NULL
1601 #define sa1100fb_resume         NULL
1602 #endif
1603
1604 /*
1605  * sa1100fb_map_video_memory():
1606  *      Allocates the DRAM memory for the frame buffer.  This buffer is  
1607  *      remapped into a non-cached, non-buffered, memory region to  
1608  *      allow palette and pixel writes to occur without flushing the 
1609  *      cache.  Once this area is remapped, all virtual memory
1610  *      access to the video memory should occur at the new region.
1611  */
1612 static int __init sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
1613 {
1614         /*
1615          * We reserve one page for the palette, plus the size
1616          * of the framebuffer.
1617          */
1618         fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
1619         fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1620                                               &fbi->map_dma, GFP_KERNEL);
1621
1622         if (fbi->map_cpu) {
1623                 fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
1624                 fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
1625                 /*
1626                  * FIXME: this is actually the wrong thing to place in
1627                  * smem_start.  But fbdev suffers from the problem that
1628                  * it needs an API which doesn't exist (in this case,
1629                  * dma_writecombine_mmap)
1630                  */
1631                 fbi->fb.fix.smem_start = fbi->screen_dma;
1632         }
1633
1634         return fbi->map_cpu ? 0 : -ENOMEM;
1635 }
1636
1637 /* Fake monspecs to fill in fbinfo structure */
1638 static struct fb_monspecs monspecs __initdata = {
1639         .hfmin  = 30000,
1640         .hfmax  = 70000,
1641         .vfmin  = 50,
1642         .vfmax  = 65,
1643 };
1644
1645
1646 static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
1647 {
1648         struct sa1100fb_mach_info *inf;
1649         struct sa1100fb_info *fbi;
1650
1651         fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
1652                       GFP_KERNEL);
1653         if (!fbi)
1654                 return NULL;
1655
1656         memset(fbi, 0, sizeof(struct sa1100fb_info));
1657         fbi->dev = dev;
1658
1659         strcpy(fbi->fb.fix.id, SA1100_NAME);
1660
1661         fbi->fb.fix.type        = FB_TYPE_PACKED_PIXELS;
1662         fbi->fb.fix.type_aux    = 0;
1663         fbi->fb.fix.xpanstep    = 0;
1664         fbi->fb.fix.ypanstep    = 0;
1665         fbi->fb.fix.ywrapstep   = 0;
1666         fbi->fb.fix.accel       = FB_ACCEL_NONE;
1667
1668         fbi->fb.var.nonstd      = 0;
1669         fbi->fb.var.activate    = FB_ACTIVATE_NOW;
1670         fbi->fb.var.height      = -1;
1671         fbi->fb.var.width       = -1;
1672         fbi->fb.var.accel_flags = 0;
1673         fbi->fb.var.vmode       = FB_VMODE_NONINTERLACED;
1674
1675         fbi->fb.fbops           = &sa1100fb_ops;
1676         fbi->fb.flags           = FBINFO_FLAG_DEFAULT;
1677         fbi->fb.monspecs        = monspecs;
1678         fbi->fb.currcon         = -1;
1679         fbi->fb.pseudo_palette  = (fbi + 1);
1680
1681         fbi->rgb[RGB_8]         = &rgb_8;
1682         fbi->rgb[RGB_16]        = &def_rgb_16;
1683
1684         inf = sa1100fb_get_machine_info(fbi);
1685
1686         /*
1687          * People just don't seem to get this.  We don't support
1688          * anything but correct entries now, so panic if someone
1689          * does something stupid.
1690          */
1691         if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
1692             inf->pixclock == 0)
1693                 panic("sa1100fb error: invalid LCCR3 fields set or zero "
1694                         "pixclock.");
1695
1696         fbi->max_xres                   = inf->xres;
1697         fbi->fb.var.xres                = inf->xres;
1698         fbi->fb.var.xres_virtual        = inf->xres;
1699         fbi->max_yres                   = inf->yres;
1700         fbi->fb.var.yres                = inf->yres;
1701         fbi->fb.var.yres_virtual        = inf->yres;
1702         fbi->max_bpp                    = inf->bpp;
1703         fbi->fb.var.bits_per_pixel      = inf->bpp;
1704         fbi->fb.var.pixclock            = inf->pixclock;
1705         fbi->fb.var.hsync_len           = inf->hsync_len;
1706         fbi->fb.var.left_margin         = inf->left_margin;
1707         fbi->fb.var.right_margin        = inf->right_margin;
1708         fbi->fb.var.vsync_len           = inf->vsync_len;
1709         fbi->fb.var.upper_margin        = inf->upper_margin;
1710         fbi->fb.var.lower_margin        = inf->lower_margin;
1711         fbi->fb.var.sync                = inf->sync;
1712         fbi->fb.var.grayscale           = inf->cmap_greyscale;
1713         fbi->cmap_inverse               = inf->cmap_inverse;
1714         fbi->cmap_static                = inf->cmap_static;
1715         fbi->lccr0                      = inf->lccr0;
1716         fbi->lccr3                      = inf->lccr3;
1717         fbi->state                      = C_STARTUP;
1718         fbi->task_state                 = (u_char)-1;
1719         fbi->fb.fix.smem_len            = fbi->max_xres * fbi->max_yres *
1720                                           fbi->max_bpp / 8;
1721
1722         init_waitqueue_head(&fbi->ctrlr_wait);
1723         INIT_WORK(&fbi->task, sa1100fb_task, fbi);
1724         init_MUTEX(&fbi->ctrlr_sem);
1725
1726         return fbi;
1727 }
1728
1729 static int __init sa1100fb_probe(struct device *dev)
1730 {
1731         struct sa1100fb_info *fbi;
1732         int ret;
1733
1734         if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
1735                 return -EBUSY;
1736
1737         fbi = sa1100fb_init_fbinfo(dev);
1738         ret = -ENOMEM;
1739         if (!fbi)
1740                 goto failed;
1741
1742         /* Initialize video memory */
1743         ret = sa1100fb_map_video_memory(fbi);
1744         if (ret)
1745                 goto failed;
1746
1747         ret = request_irq(IRQ_LCD, sa1100fb_handle_irq, SA_INTERRUPT,
1748                           "LCD", fbi);
1749         if (ret) {
1750                 printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
1751                 goto failed;
1752         }
1753
1754 #ifdef ASSABET_PAL_VIDEO
1755         if (machine_is_assabet())
1756                 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
1757 #endif
1758
1759 #ifdef CONFIG_SA1100_FREEBIRD
1760 #error Please move this into __sa1100fb_lcd_power
1761         if (machine_is_freebird()) {
1762                 BCR_set(BCR_FREEBIRD_LCD_DISP);
1763                 mdelay(20);
1764                 BCR_set(BCR_FREEBIRD_LCD_PWR);
1765                 mdelay(20);
1766         }
1767 #endif
1768
1769         /*
1770          * This makes sure that our colour bitfield
1771          * descriptors are correctly initialised.
1772          */
1773         sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
1774
1775         dev_set_drvdata(dev, fbi);
1776
1777         ret = register_framebuffer(&fbi->fb);
1778         if (ret < 0)
1779                 goto failed;
1780
1781 #ifdef CONFIG_CPU_FREQ
1782         fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
1783         fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
1784         cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
1785         cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
1786 #endif
1787
1788         /* This driver cannot be unloaded at the moment */
1789         return 0;
1790
1791 failed:
1792         dev_set_drvdata(dev, NULL);
1793         if (fbi)
1794                 kfree(fbi);
1795         release_mem_region(0xb0100000, 0x10000);
1796         return ret;
1797 }
1798
1799 static struct device_driver sa1100fb_driver = {
1800         .name           = "sa11x0-fb",
1801         .bus            = &platform_bus_type,
1802         .probe          = sa1100fb_probe,
1803         .suspend        = sa1100fb_suspend,
1804         .resume         = sa1100fb_resume,
1805 };
1806
1807 int __init sa1100fb_init(void)
1808 {
1809         return driver_register(&sa1100fb_driver);
1810 }
1811
1812 int __init sa1100fb_setup(char *options)
1813 {
1814 #if 0
1815         char *this_opt;
1816
1817         if (!options || !*options)
1818                 return 0;
1819
1820         while ((this_opt = strsep(&options, ",")) != NULL) {
1821
1822                 if (!strncmp(this_opt, "bpp:", 4))
1823                         current_par.max_bpp =
1824                             simple_strtoul(this_opt + 4, NULL, 0);
1825
1826                 if (!strncmp(this_opt, "lccr0:", 6))
1827                         lcd_shadow.lccr0 =
1828                             simple_strtoul(this_opt + 6, NULL, 0);
1829                 if (!strncmp(this_opt, "lccr1:", 6)) {
1830                         lcd_shadow.lccr1 =
1831                             simple_strtoul(this_opt + 6, NULL, 0);
1832                         current_par.max_xres =
1833                             (lcd_shadow.lccr1 & 0x3ff) + 16;
1834                 }
1835                 if (!strncmp(this_opt, "lccr2:", 6)) {
1836                         lcd_shadow.lccr2 =
1837                             simple_strtoul(this_opt + 6, NULL, 0);
1838                         current_par.max_yres =
1839                             (lcd_shadow.
1840                              lccr0 & LCCR0_SDS) ? ((lcd_shadow.
1841                                                     lccr2 & 0x3ff) +
1842                                                    1) *
1843                             2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
1844                 }
1845                 if (!strncmp(this_opt, "lccr3:", 6))
1846                         lcd_shadow.lccr3 =
1847                             simple_strtoul(this_opt + 6, NULL, 0);
1848         }
1849 #endif
1850         return 0;
1851 }
1852
1853 MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
1854 MODULE_LICENSE("GPL");