blob: d645c6d5fd9f8345f325fae9fcdcffae356c4f96 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Nicolas Pitre2f82af02009-09-14 03:25:28 -040069 * 2000/04/10: Nicolas Pitre <nico@fluxnic.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * - 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
Russell King59f0cb02008-10-27 11:24:09 +0000117 * memset.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 * - 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#include <linux/module.h>
164#include <linux/kernel.h>
165#include <linux/sched.h>
166#include <linux/errno.h>
167#include <linux/string.h>
168#include <linux/interrupt.h>
169#include <linux/slab.h>
Andrea Righi27ac7922008-07-23 21:28:13 -0700170#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#include <linux/fb.h>
172#include <linux/delay.h>
173#include <linux/init.h>
174#include <linux/ioport.h>
175#include <linux/cpufreq.h>
Russell Kingd052d1b2005-10-29 19:07:23 +0100176#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#include <linux/dma-mapping.h>
Matthias Kaehlcke7951ac92008-07-23 21:31:16 -0700178#include <linux/mutex.h>
Russell King99730222009-03-25 10:21:35 +0000179#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Russell King9e6720f2012-01-14 10:56:06 +0000181#include <video/sa1100fb.h>
182
Russell Kinga09e64f2008-08-05 16:14:15 +0100183#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +0100185#include <mach/assabet.h>
186#include <mach/shannon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 * Complain if VAR is out of range.
190 */
191#define DEBUG_VAR 1
192
193#undef ASSABET_PAL_VIDEO
194
195#include "sa1100fb.h"
196
197extern void (*sa1100fb_backlight_power)(int on);
198extern void (*sa1100fb_lcd_power)(int on);
199
Russell King58f5cbf2012-01-14 10:13:30 +0000200static const struct sa1100fb_rgb rgb_4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 .red = { .offset = 0, .length = 4, },
202 .green = { .offset = 0, .length = 4, },
203 .blue = { .offset = 0, .length = 4, },
204 .transp = { .offset = 0, .length = 0, },
205};
206
Russell King58f5cbf2012-01-14 10:13:30 +0000207static const struct sa1100fb_rgb rgb_8 = {
Michal Januszewski0a453482009-04-13 14:39:51 -0700208 .red = { .offset = 0, .length = 8, },
209 .green = { .offset = 0, .length = 8, },
210 .blue = { .offset = 0, .length = 8, },
211 .transp = { .offset = 0, .length = 0, },
212};
213
Russell King58f5cbf2012-01-14 10:13:30 +0000214static const struct sa1100fb_rgb def_rgb_16 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .red = { .offset = 11, .length = 5, },
216 .green = { .offset = 5, .length = 6, },
217 .blue = { .offset = 0, .length = 5, },
218 .transp = { .offset = 0, .length = 0, },
219};
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
224static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
225
226static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
227{
228 unsigned long flags;
229
230 local_irq_save(flags);
231 /*
232 * We need to handle two requests being made at the same time.
233 * There are two important cases:
234 * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
235 * We must perform the unblanking, which will do our REENABLE for us.
236 * 2. When we are blanking, but immediately unblank before we have
237 * blanked. We do the "REENABLE" thing here as well, just to be sure.
238 */
239 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
240 state = (u_int) -1;
241 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
242 state = C_REENABLE;
243
244 if (state != (u_int)-1) {
245 fbi->task_state = state;
246 schedule_work(&fbi->task);
247 }
248 local_irq_restore(flags);
249}
250
251static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
252{
253 chan &= 0xffff;
254 chan >>= 16 - bf->length;
255 return chan << bf->offset;
256}
257
258/*
259 * Convert bits-per-pixel to a hardware palette PBS value.
260 */
261static inline u_int palette_pbs(struct fb_var_screeninfo *var)
262{
263 int ret = 0;
264 switch (var->bits_per_pixel) {
265 case 4: ret = 0 << 12; break;
266 case 8: ret = 1 << 12; break;
267 case 16: ret = 2 << 12; break;
268 }
269 return ret;
270}
271
272static int
273sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
274 u_int trans, struct fb_info *info)
275{
276 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
277 u_int val, ret = 1;
278
279 if (regno < fbi->palette_size) {
280 val = ((red >> 4) & 0xf00);
281 val |= ((green >> 8) & 0x0f0);
282 val |= ((blue >> 12) & 0x00f);
283
284 if (regno == 0)
285 val |= palette_pbs(&fbi->fb.var);
286
287 fbi->palette_cpu[regno] = val;
288 ret = 0;
289 }
290 return ret;
291}
292
293static int
294sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
295 u_int trans, struct fb_info *info)
296{
297 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
298 unsigned int val;
299 int ret = 1;
300
301 /*
302 * If inverse mode was selected, invert all the colours
303 * rather than the register number. The register number
304 * is what you poke into the framebuffer to produce the
305 * colour you requested.
306 */
307 if (fbi->cmap_inverse) {
308 red = 0xffff - red;
309 green = 0xffff - green;
310 blue = 0xffff - blue;
311 }
312
313 /*
314 * If greyscale is true, then we convert the RGB value
315 * to greyscale no mater what visual we are using.
316 */
317 if (fbi->fb.var.grayscale)
318 red = green = blue = (19595 * red + 38470 * green +
319 7471 * blue) >> 16;
320
321 switch (fbi->fb.fix.visual) {
322 case FB_VISUAL_TRUECOLOR:
323 /*
324 * 12 or 16-bit True Colour. We encode the RGB value
325 * according to the RGB bitfield information.
326 */
327 if (regno < 16) {
328 u32 *pal = fbi->fb.pseudo_palette;
329
330 val = chan_to_field(red, &fbi->fb.var.red);
331 val |= chan_to_field(green, &fbi->fb.var.green);
332 val |= chan_to_field(blue, &fbi->fb.var.blue);
333
334 pal[regno] = val;
335 ret = 0;
336 }
337 break;
338
339 case FB_VISUAL_STATIC_PSEUDOCOLOR:
340 case FB_VISUAL_PSEUDOCOLOR:
341 ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
342 break;
343 }
344
345 return ret;
346}
347
Pavel Machek6edb7462005-10-14 15:59:01 -0700348#ifdef CONFIG_CPU_FREQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/*
350 * sa1100fb_display_dma_period()
351 * Calculate the minimum period (in picoseconds) between two DMA
352 * requests for the LCD controller. If we hit this, it means we're
353 * doing nothing but LCD DMA.
354 */
Russell Kingfc1df37e32005-08-07 14:20:26 +0100355static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 /*
358 * Period = pixclock * bits_per_byte * bytes_per_transfer
359 * / memory_bits_per_pixel;
360 */
361 return var->pixclock * 8 * 16 / var->bits_per_pixel;
362}
Pavel Machek6edb7462005-10-14 15:59:01 -0700363#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365/*
366 * sa1100fb_check_var():
367 * Round up in the following order: bits_per_pixel, xres,
368 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
369 * bitfields, horizontal timing, vertical timing.
370 */
371static int
372sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
373{
374 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
375 int rgbidx;
376
377 if (var->xres < MIN_XRES)
378 var->xres = MIN_XRES;
379 if (var->yres < MIN_YRES)
380 var->yres = MIN_YRES;
381 if (var->xres > fbi->max_xres)
382 var->xres = fbi->max_xres;
383 if (var->yres > fbi->max_yres)
384 var->yres = fbi->max_yres;
385 var->xres_virtual = max(var->xres_virtual, var->xres);
386 var->yres_virtual = max(var->yres_virtual, var->yres);
387
Russell King79889292012-01-14 10:22:56 +0000388 dev_dbg(fbi->dev, "var->bits_per_pixel=%d\n", var->bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 switch (var->bits_per_pixel) {
390 case 4:
Michal Januszewski0a453482009-04-13 14:39:51 -0700391 rgbidx = RGB_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
393 case 8:
394 rgbidx = RGB_8;
395 break;
396 case 16:
397 rgbidx = RGB_16;
398 break;
399 default:
400 return -EINVAL;
401 }
402
403 /*
404 * Copy the RGB parameters for this display
405 * from the machine specific parameters.
406 */
407 var->red = fbi->rgb[rgbidx]->red;
408 var->green = fbi->rgb[rgbidx]->green;
409 var->blue = fbi->rgb[rgbidx]->blue;
410 var->transp = fbi->rgb[rgbidx]->transp;
411
Russell King79889292012-01-14 10:22:56 +0000412 dev_dbg(fbi->dev, "RGBT length = %d:%d:%d:%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 var->red.length, var->green.length, var->blue.length,
414 var->transp.length);
415
Russell King79889292012-01-14 10:22:56 +0000416 dev_dbg(fbi->dev, "RGBT offset = %d:%d:%d:%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 var->red.offset, var->green.offset, var->blue.offset,
418 var->transp.offset);
419
420#ifdef CONFIG_CPU_FREQ
Russell King79889292012-01-14 10:22:56 +0000421 dev_dbg(fbi->dev, "dma period = %d ps, clock = %d kHz\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 sa1100fb_display_dma_period(var),
423 cpufreq_get(smp_processor_id()));
424#endif
425
426 return 0;
427}
428
429static inline void sa1100fb_set_truecolor(u_int is_true_color)
430{
431 if (machine_is_assabet()) {
432#if 1 // phase 4 or newer Assabet's
433 if (is_true_color)
434 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
435 else
436 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
437#else
438 // older Assabet's
439 if (is_true_color)
440 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
441 else
442 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
443#endif
444 }
445}
446
447/*
448 * sa1100fb_set_par():
449 * Set the user defined part of the display for the specified console
450 */
451static int sa1100fb_set_par(struct fb_info *info)
452{
453 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
454 struct fb_var_screeninfo *var = &info->var;
455 unsigned long palette_mem_size;
456
Russell King79889292012-01-14 10:22:56 +0000457 dev_dbg(fbi->dev, "set_par\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 if (var->bits_per_pixel == 16)
460 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
461 else if (!fbi->cmap_static)
462 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
463 else {
464 /*
465 * Some people have weird ideas about wanting static
466 * pseudocolor maps. I suspect their user space
467 * applications are broken.
468 */
469 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
470 }
471
472 fbi->fb.fix.line_length = var->xres_virtual *
473 var->bits_per_pixel / 8;
474 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
475
476 palette_mem_size = fbi->palette_size * sizeof(u16);
477
Russell King79889292012-01-14 10:22:56 +0000478 dev_dbg(fbi->dev, "palette_mem_size = 0x%08lx\n", palette_mem_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
481 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
482
483 /*
484 * Set (any) board control register to handle new color depth
485 */
486 sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
487 sa1100fb_activate_var(var, fbi);
488
489 return 0;
490}
491
492#if 0
493static int
494sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
495 struct fb_info *info)
496{
497 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
498
499 /*
500 * Make sure the user isn't doing something stupid.
501 */
502 if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
503 return -EINVAL;
504
505 return gen_set_cmap(cmap, kspc, con, info);
506}
507#endif
508
509/*
510 * Formal definition of the VESA spec:
511 * On
512 * This refers to the state of the display when it is in full operation
513 * Stand-By
514 * This defines an optional operating state of minimal power reduction with
515 * the shortest recovery time
516 * Suspend
517 * This refers to a level of power management in which substantial power
518 * reduction is achieved by the display. The display can have a longer
519 * recovery time from this state than from the Stand-by state
520 * Off
521 * This indicates that the display is consuming the lowest level of power
522 * and is non-operational. Recovery from this state may optionally require
523 * the user to manually power on the monitor
524 *
525 * Now, the fbdev driver adds an additional state, (blank), where they
526 * turn off the video (maybe by colormap tricks), but don't mess with the
527 * video itself: think of it semantically between on and Stand-By.
528 *
529 * So here's what we should do in our fbdev blank routine:
530 *
531 * VESA_NO_BLANKING (mode 0) Video on, front/back light on
532 * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
533 * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
534 * VESA_POWERDOWN (mode 3) Video off, front/back light off
535 *
536 * This will match the matrox implementation.
537 */
538/*
539 * sa1100fb_blank():
540 * Blank the display by setting all palette values to zero. Note, the
541 * 12 and 16 bpp modes don't really use the palette, so this will not
542 * blank the display in all modes.
543 */
544static int sa1100fb_blank(int blank, struct fb_info *info)
545{
546 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
547 int i;
548
Russell King79889292012-01-14 10:22:56 +0000549 dev_dbg(fbi->dev, "sa1100fb_blank: blank=%d\n", blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 switch (blank) {
552 case FB_BLANK_POWERDOWN:
553 case FB_BLANK_VSYNC_SUSPEND:
554 case FB_BLANK_HSYNC_SUSPEND:
555 case FB_BLANK_NORMAL:
556 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
557 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
558 for (i = 0; i < fbi->palette_size; i++)
559 sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
560 sa1100fb_schedule_work(fbi, C_DISABLE);
561 break;
562
563 case FB_BLANK_UNBLANK:
564 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
565 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
566 fb_set_cmap(&fbi->fb.cmap, info);
567 sa1100fb_schedule_work(fbi, C_ENABLE);
568 }
569 return 0;
570}
571
Christoph Hellwig216d5262006-01-14 13:21:25 -0800572static int sa1100fb_mmap(struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 struct vm_area_struct *vma)
574{
575 struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
576 unsigned long start, len, off = vma->vm_pgoff << PAGE_SHIFT;
577
578 if (off < info->fix.smem_len) {
579 vma->vm_pgoff += 1; /* skip over the palette */
580 return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
581 fbi->map_dma, fbi->map_size);
582 }
583
584 start = info->fix.mmio_start;
585 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
586
587 if ((vma->vm_end - vma->vm_start + off) > len)
588 return -EINVAL;
589
590 off += start & PAGE_MASK;
591 vma->vm_pgoff = off >> PAGE_SHIFT;
592 vma->vm_flags |= VM_IO;
593 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
594 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
595 vma->vm_end - vma->vm_start,
596 vma->vm_page_prot);
597}
598
599static struct fb_ops sa1100fb_ops = {
600 .owner = THIS_MODULE,
601 .fb_check_var = sa1100fb_check_var,
602 .fb_set_par = sa1100fb_set_par,
603// .fb_set_cmap = sa1100fb_set_cmap,
604 .fb_setcolreg = sa1100fb_setcolreg,
605 .fb_fillrect = cfb_fillrect,
606 .fb_copyarea = cfb_copyarea,
607 .fb_imageblit = cfb_imageblit,
608 .fb_blank = sa1100fb_blank,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .fb_mmap = sa1100fb_mmap,
610};
611
612/*
613 * Calculate the PCD value from the clock rate (in picoseconds).
614 * We take account of the PPCR clock setting.
615 */
616static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
617{
618 unsigned int pcd = cpuclock / 100;
619
620 pcd *= pixclock;
621 pcd /= 10000000;
622
623 return pcd + 1; /* make up for integer math truncations */
624}
625
626/*
627 * sa1100fb_activate_var():
628 * Configures LCD Controller based on entries in var parameter. Settings are
629 * only written to the controller if changes were made.
630 */
631static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
632{
633 struct sa1100fb_lcd_reg new_regs;
634 u_int half_screen_size, yres, pcd;
635 u_long flags;
636
Russell King79889292012-01-14 10:22:56 +0000637 dev_dbg(fbi->dev, "Configuring SA1100 LCD\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Russell King79889292012-01-14 10:22:56 +0000639 dev_dbg(fbi->dev, "var: xres=%d hslen=%d lm=%d rm=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 var->xres, var->hsync_len,
641 var->left_margin, var->right_margin);
Russell King79889292012-01-14 10:22:56 +0000642 dev_dbg(fbi->dev, "var: yres=%d vslen=%d um=%d bm=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 var->yres, var->vsync_len,
644 var->upper_margin, var->lower_margin);
645
646#if DEBUG_VAR
647 if (var->xres < 16 || var->xres > 1024)
Russell King79889292012-01-14 10:22:56 +0000648 dev_err(fbi->dev, "%s: invalid xres %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 fbi->fb.fix.id, var->xres);
650 if (var->hsync_len < 1 || var->hsync_len > 64)
Russell King79889292012-01-14 10:22:56 +0000651 dev_err(fbi->dev, "%s: invalid hsync_len %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 fbi->fb.fix.id, var->hsync_len);
653 if (var->left_margin < 1 || var->left_margin > 255)
Russell King79889292012-01-14 10:22:56 +0000654 dev_err(fbi->dev, "%s: invalid left_margin %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 fbi->fb.fix.id, var->left_margin);
656 if (var->right_margin < 1 || var->right_margin > 255)
Russell King79889292012-01-14 10:22:56 +0000657 dev_err(fbi->dev, "%s: invalid right_margin %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 fbi->fb.fix.id, var->right_margin);
659 if (var->yres < 1 || var->yres > 1024)
Russell King79889292012-01-14 10:22:56 +0000660 dev_err(fbi->dev, "%s: invalid yres %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 fbi->fb.fix.id, var->yres);
662 if (var->vsync_len < 1 || var->vsync_len > 64)
Russell King79889292012-01-14 10:22:56 +0000663 dev_err(fbi->dev, "%s: invalid vsync_len %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 fbi->fb.fix.id, var->vsync_len);
665 if (var->upper_margin < 0 || var->upper_margin > 255)
Russell King79889292012-01-14 10:22:56 +0000666 dev_err(fbi->dev, "%s: invalid upper_margin %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 fbi->fb.fix.id, var->upper_margin);
668 if (var->lower_margin < 0 || var->lower_margin > 255)
Russell King79889292012-01-14 10:22:56 +0000669 dev_err(fbi->dev, "%s: invalid lower_margin %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 fbi->fb.fix.id, var->lower_margin);
671#endif
672
673 new_regs.lccr0 = fbi->lccr0 |
674 LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
675 LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
676
677 new_regs.lccr1 =
678 LCCR1_DisWdth(var->xres) +
679 LCCR1_HorSnchWdth(var->hsync_len) +
680 LCCR1_BegLnDel(var->left_margin) +
681 LCCR1_EndLnDel(var->right_margin);
682
683 /*
684 * If we have a dual scan LCD, then we need to halve
685 * the YRES parameter.
686 */
687 yres = var->yres;
688 if (fbi->lccr0 & LCCR0_Dual)
689 yres /= 2;
690
691 new_regs.lccr2 =
692 LCCR2_DisHght(yres) +
693 LCCR2_VrtSnchWdth(var->vsync_len) +
694 LCCR2_BegFrmDel(var->upper_margin) +
695 LCCR2_EndFrmDel(var->lower_margin);
696
697 pcd = get_pcd(var->pixclock, cpufreq_get(0));
698 new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->lccr3 |
699 (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
700 (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
701
Russell King79889292012-01-14 10:22:56 +0000702 dev_dbg(fbi->dev, "nlccr0 = 0x%08lx\n", new_regs.lccr0);
703 dev_dbg(fbi->dev, "nlccr1 = 0x%08lx\n", new_regs.lccr1);
704 dev_dbg(fbi->dev, "nlccr2 = 0x%08lx\n", new_regs.lccr2);
705 dev_dbg(fbi->dev, "nlccr3 = 0x%08lx\n", new_regs.lccr3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 half_screen_size = var->bits_per_pixel;
708 half_screen_size = half_screen_size * var->xres * var->yres / 16;
709
710 /* Update shadow copy atomically */
711 local_irq_save(flags);
712 fbi->dbar1 = fbi->palette_dma;
713 fbi->dbar2 = fbi->screen_dma + half_screen_size;
714
715 fbi->reg_lccr0 = new_regs.lccr0;
716 fbi->reg_lccr1 = new_regs.lccr1;
717 fbi->reg_lccr2 = new_regs.lccr2;
718 fbi->reg_lccr3 = new_regs.lccr3;
719 local_irq_restore(flags);
720
721 /*
722 * Only update the registers if the controller is enabled
723 * and something has changed.
724 */
725 if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
726 (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
727 (DBAR1 != fbi->dbar1) || (DBAR2 != fbi->dbar2))
728 sa1100fb_schedule_work(fbi, C_REENABLE);
729
730 return 0;
731}
732
733/*
734 * NOTE! The following functions are purely helpers for set_ctrlr_state.
735 * Do not call them directly; set_ctrlr_state does the correct serialisation
736 * to ensure that things happen in the right way 100% of time time.
737 * -- rmk
738 */
739static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
740{
Russell King79889292012-01-14 10:22:56 +0000741 dev_dbg(fbi->dev, "backlight o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 if (sa1100fb_backlight_power)
744 sa1100fb_backlight_power(on);
745}
746
747static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
748{
Russell King79889292012-01-14 10:22:56 +0000749 dev_dbg(fbi->dev, "LCD power o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 if (sa1100fb_lcd_power)
752 sa1100fb_lcd_power(on);
753}
754
755static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
756{
757 u_int mask = 0;
758
759 /*
760 * Enable GPIO<9:2> for LCD use if:
761 * 1. Active display, or
762 * 2. Color Dual Passive display
763 *
764 * see table 11.8 on page 11-27 in the SA1100 manual
765 * -- Erik.
766 *
767 * SA1110 spec update nr. 25 says we can and should
768 * clear LDD15 to 12 for 4 or 8bpp modes with active
769 * panels.
770 */
771 if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
772 (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
773 mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
774
775 if (fbi->fb.var.bits_per_pixel > 8 ||
776 (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
777 mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
778
779 }
780
781 if (mask) {
782 GPDR |= mask;
783 GAFR |= mask;
784 }
785}
786
787static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
788{
Russell King79889292012-01-14 10:22:56 +0000789 dev_dbg(fbi->dev, "Enabling LCD controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 /*
792 * Make sure the mode bits are present in the first palette entry
793 */
794 fbi->palette_cpu[0] &= 0xcfff;
795 fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
796
797 /* Sequence from 11.7.10 */
798 LCCR3 = fbi->reg_lccr3;
799 LCCR2 = fbi->reg_lccr2;
800 LCCR1 = fbi->reg_lccr1;
801 LCCR0 = fbi->reg_lccr0 & ~LCCR0_LEN;
802 DBAR1 = fbi->dbar1;
803 DBAR2 = fbi->dbar2;
804 LCCR0 |= LCCR0_LEN;
805
806 if (machine_is_shannon()) {
807 GPDR |= SHANNON_GPIO_DISP_EN;
808 GPSR |= SHANNON_GPIO_DISP_EN;
809 }
810
Russell King79889292012-01-14 10:22:56 +0000811 dev_dbg(fbi->dev, "DBAR1 = 0x%08lx\n", DBAR1);
812 dev_dbg(fbi->dev, "DBAR2 = 0x%08lx\n", DBAR2);
813 dev_dbg(fbi->dev, "LCCR0 = 0x%08lx\n", LCCR0);
814 dev_dbg(fbi->dev, "LCCR1 = 0x%08lx\n", LCCR1);
815 dev_dbg(fbi->dev, "LCCR2 = 0x%08lx\n", LCCR2);
816 dev_dbg(fbi->dev, "LCCR3 = 0x%08lx\n", LCCR3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
819static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
820{
821 DECLARE_WAITQUEUE(wait, current);
822
Russell King79889292012-01-14 10:22:56 +0000823 dev_dbg(fbi->dev, "Disabling LCD controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 if (machine_is_shannon()) {
826 GPCR |= SHANNON_GPIO_DISP_EN;
827 }
828
829 set_current_state(TASK_UNINTERRUPTIBLE);
830 add_wait_queue(&fbi->ctrlr_wait, &wait);
831
832 LCSR = 0xffffffff; /* Clear LCD Status Register */
833 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
834 LCCR0 &= ~LCCR0_LEN; /* Disable LCD Controller */
835
836 schedule_timeout(20 * HZ / 1000);
837 remove_wait_queue(&fbi->ctrlr_wait, &wait);
838}
839
840/*
841 * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
842 */
David Howells7d12e782006-10-05 14:55:46 +0100843static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
845 struct sa1100fb_info *fbi = dev_id;
846 unsigned int lcsr = LCSR;
847
848 if (lcsr & LCSR_LDD) {
849 LCCR0 |= LCCR0_LDM;
850 wake_up(&fbi->ctrlr_wait);
851 }
852
853 LCSR = lcsr;
854 return IRQ_HANDLED;
855}
856
857/*
858 * This function must be called from task context only, since it will
859 * sleep when disabling the LCD controller, or if we get two contending
860 * processes trying to alter state.
861 */
862static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
863{
864 u_int old_state;
865
Matthias Kaehlcke7951ac92008-07-23 21:31:16 -0700866 mutex_lock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 old_state = fbi->state;
869
870 /*
871 * Hack around fbcon initialisation.
872 */
873 if (old_state == C_STARTUP && state == C_REENABLE)
874 state = C_ENABLE;
875
876 switch (state) {
877 case C_DISABLE_CLKCHANGE:
878 /*
879 * Disable controller for clock change. If the
880 * controller is already disabled, then do nothing.
881 */
882 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
883 fbi->state = state;
884 sa1100fb_disable_controller(fbi);
885 }
886 break;
887
888 case C_DISABLE_PM:
889 case C_DISABLE:
890 /*
891 * Disable controller
892 */
893 if (old_state != C_DISABLE) {
894 fbi->state = state;
895
896 __sa1100fb_backlight_power(fbi, 0);
897 if (old_state != C_DISABLE_CLKCHANGE)
898 sa1100fb_disable_controller(fbi);
899 __sa1100fb_lcd_power(fbi, 0);
900 }
901 break;
902
903 case C_ENABLE_CLKCHANGE:
904 /*
905 * Enable the controller after clock change. Only
906 * do this if we were disabled for the clock change.
907 */
908 if (old_state == C_DISABLE_CLKCHANGE) {
909 fbi->state = C_ENABLE;
910 sa1100fb_enable_controller(fbi);
911 }
912 break;
913
914 case C_REENABLE:
915 /*
916 * Re-enable the controller only if it was already
917 * enabled. This is so we reprogram the control
918 * registers.
919 */
920 if (old_state == C_ENABLE) {
921 sa1100fb_disable_controller(fbi);
922 sa1100fb_setup_gpio(fbi);
923 sa1100fb_enable_controller(fbi);
924 }
925 break;
926
927 case C_ENABLE_PM:
928 /*
929 * Re-enable the controller after PM. This is not
930 * perfect - think about the case where we were doing
931 * a clock change, and we suspended half-way through.
932 */
933 if (old_state != C_DISABLE_PM)
934 break;
935 /* fall through */
936
937 case C_ENABLE:
938 /*
939 * Power up the LCD screen, enable controller, and
940 * turn on the backlight.
941 */
942 if (old_state != C_ENABLE) {
943 fbi->state = C_ENABLE;
944 sa1100fb_setup_gpio(fbi);
945 __sa1100fb_lcd_power(fbi, 1);
946 sa1100fb_enable_controller(fbi);
947 __sa1100fb_backlight_power(fbi, 1);
948 }
949 break;
950 }
Matthias Kaehlcke7951ac92008-07-23 21:31:16 -0700951 mutex_unlock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
954/*
955 * Our LCD controller task (which is called when we blank or unblank)
956 * via keventd.
957 */
Pavel Machek23432172006-12-17 13:21:05 +0100958static void sa1100fb_task(struct work_struct *w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
Pavel Machek23432172006-12-17 13:21:05 +0100960 struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 u_int state = xchg(&fbi->task_state, -1);
962
963 set_ctrlr_state(fbi, state);
964}
965
966#ifdef CONFIG_CPU_FREQ
967/*
968 * Calculate the minimum DMA period over all displays that we own.
969 * This, together with the SDRAM bandwidth defines the slowest CPU
970 * frequency that can be selected.
971 */
972static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
973{
974#if 0
975 unsigned int min_period = (unsigned int)-1;
976 int i;
977
978 for (i = 0; i < MAX_NR_CONSOLES; i++) {
979 struct display *disp = &fb_display[i];
980 unsigned int period;
981
982 /*
983 * Do we own this display?
984 */
985 if (disp->fb_info != &fbi->fb)
986 continue;
987
988 /*
989 * Ok, calculate its DMA period
990 */
991 period = sa1100fb_display_dma_period(&disp->var);
992 if (period < min_period)
993 min_period = period;
994 }
995
996 return min_period;
997#else
998 /*
999 * FIXME: we need to verify _all_ consoles.
1000 */
1001 return sa1100fb_display_dma_period(&fbi->fb.var);
1002#endif
1003}
1004
1005/*
1006 * CPU clock speed change handler. We need to adjust the LCD timing
1007 * parameters when the CPU clock is adjusted by the power management
1008 * subsystem.
1009 */
1010static int
1011sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
1012 void *data)
1013{
1014 struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
1015 struct cpufreq_freqs *f = data;
1016 u_int pcd;
1017
1018 switch (val) {
1019 case CPUFREQ_PRECHANGE:
1020 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1021 break;
1022
1023 case CPUFREQ_POSTCHANGE:
1024 pcd = get_pcd(fbi->fb.var.pixclock, f->new);
1025 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
1026 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1027 break;
1028 }
1029 return 0;
1030}
1031
1032static int
1033sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
1034 void *data)
1035{
1036 struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
1037 struct cpufreq_policy *policy = data;
1038
1039 switch (val) {
1040 case CPUFREQ_ADJUST:
1041 case CPUFREQ_INCOMPATIBLE:
Russell King79889292012-01-14 10:22:56 +00001042 dev_dbg(fbi->dev, "min dma period: %d ps, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
1044 policy->max);
1045 /* todo: fill in min/max values */
1046 break;
1047 case CPUFREQ_NOTIFY:
1048 do {} while(0);
1049 /* todo: panic if min/max values aren't fulfilled
1050 * [can't really happen unless there's a bug in the
1051 * CPU policy verififcation process *
1052 */
1053 break;
1054 }
1055 return 0;
1056}
1057#endif
1058
1059#ifdef CONFIG_PM
1060/*
1061 * Power management hooks. Note that we won't be called from IRQ context,
1062 * unlike the blank functions above, so we may sleep.
1063 */
Russell King3ae5eae2005-11-09 22:32:44 +00001064static int sa1100fb_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
Russell King3ae5eae2005-11-09 22:32:44 +00001066 struct sa1100fb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Russell King9480e302005-10-28 09:52:56 -07001068 set_ctrlr_state(fbi, C_DISABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return 0;
1070}
1071
Russell King3ae5eae2005-11-09 22:32:44 +00001072static int sa1100fb_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
Russell King3ae5eae2005-11-09 22:32:44 +00001074 struct sa1100fb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Russell King9480e302005-10-28 09:52:56 -07001076 set_ctrlr_state(fbi, C_ENABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 return 0;
1078}
1079#else
1080#define sa1100fb_suspend NULL
1081#define sa1100fb_resume NULL
1082#endif
1083
1084/*
1085 * sa1100fb_map_video_memory():
1086 * Allocates the DRAM memory for the frame buffer. This buffer is
1087 * remapped into a non-cached, non-buffered, memory region to
1088 * allow palette and pixel writes to occur without flushing the
1089 * cache. Once this area is remapped, all virtual memory
1090 * access to the video memory should occur at the new region.
1091 */
Russell King66564d82012-01-14 10:00:38 +00001092static int __devinit sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
1094 /*
1095 * We reserve one page for the palette, plus the size
1096 * of the framebuffer.
1097 */
1098 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
1099 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1100 &fbi->map_dma, GFP_KERNEL);
1101
1102 if (fbi->map_cpu) {
1103 fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
1104 fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
1105 /*
1106 * FIXME: this is actually the wrong thing to place in
1107 * smem_start. But fbdev suffers from the problem that
1108 * it needs an API which doesn't exist (in this case,
1109 * dma_writecombine_mmap)
1110 */
1111 fbi->fb.fix.smem_start = fbi->screen_dma;
1112 }
1113
1114 return fbi->map_cpu ? 0 : -ENOMEM;
1115}
1116
1117/* Fake monspecs to fill in fbinfo structure */
Russell King66564d82012-01-14 10:00:38 +00001118static struct fb_monspecs monspecs __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 .hfmin = 30000,
1120 .hfmax = 70000,
1121 .vfmin = 50,
1122 .vfmax = 65,
1123};
1124
1125
Russell King66564d82012-01-14 10:00:38 +00001126static struct sa1100fb_info * __devinit sa1100fb_init_fbinfo(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Russell Kinge1b7a722012-01-14 11:50:04 +00001128 struct sa1100fb_mach_info *inf = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 struct sa1100fb_info *fbi;
Russell King531060f2012-01-14 10:49:44 +00001130 unsigned i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
1133 GFP_KERNEL);
1134 if (!fbi)
1135 return NULL;
1136
1137 memset(fbi, 0, sizeof(struct sa1100fb_info));
1138 fbi->dev = dev;
1139
1140 strcpy(fbi->fb.fix.id, SA1100_NAME);
1141
1142 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1143 fbi->fb.fix.type_aux = 0;
1144 fbi->fb.fix.xpanstep = 0;
1145 fbi->fb.fix.ypanstep = 0;
1146 fbi->fb.fix.ywrapstep = 0;
1147 fbi->fb.fix.accel = FB_ACCEL_NONE;
1148
1149 fbi->fb.var.nonstd = 0;
1150 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1151 fbi->fb.var.height = -1;
1152 fbi->fb.var.width = -1;
1153 fbi->fb.var.accel_flags = 0;
1154 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1155
1156 fbi->fb.fbops = &sa1100fb_ops;
1157 fbi->fb.flags = FBINFO_DEFAULT;
1158 fbi->fb.monspecs = monspecs;
1159 fbi->fb.pseudo_palette = (fbi + 1);
1160
Michal Januszewski0a453482009-04-13 14:39:51 -07001161 fbi->rgb[RGB_4] = &rgb_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 fbi->rgb[RGB_8] = &rgb_8;
1163 fbi->rgb[RGB_16] = &def_rgb_16;
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 /*
1166 * People just don't seem to get this. We don't support
1167 * anything but correct entries now, so panic if someone
1168 * does something stupid.
1169 */
1170 if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
1171 inf->pixclock == 0)
1172 panic("sa1100fb error: invalid LCCR3 fields set or zero "
1173 "pixclock.");
1174
1175 fbi->max_xres = inf->xres;
1176 fbi->fb.var.xres = inf->xres;
1177 fbi->fb.var.xres_virtual = inf->xres;
1178 fbi->max_yres = inf->yres;
1179 fbi->fb.var.yres = inf->yres;
1180 fbi->fb.var.yres_virtual = inf->yres;
1181 fbi->max_bpp = inf->bpp;
1182 fbi->fb.var.bits_per_pixel = inf->bpp;
1183 fbi->fb.var.pixclock = inf->pixclock;
1184 fbi->fb.var.hsync_len = inf->hsync_len;
1185 fbi->fb.var.left_margin = inf->left_margin;
1186 fbi->fb.var.right_margin = inf->right_margin;
1187 fbi->fb.var.vsync_len = inf->vsync_len;
1188 fbi->fb.var.upper_margin = inf->upper_margin;
1189 fbi->fb.var.lower_margin = inf->lower_margin;
1190 fbi->fb.var.sync = inf->sync;
1191 fbi->fb.var.grayscale = inf->cmap_greyscale;
1192 fbi->cmap_inverse = inf->cmap_inverse;
1193 fbi->cmap_static = inf->cmap_static;
1194 fbi->lccr0 = inf->lccr0;
1195 fbi->lccr3 = inf->lccr3;
1196 fbi->state = C_STARTUP;
1197 fbi->task_state = (u_char)-1;
1198 fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
1199 fbi->max_bpp / 8;
1200
Russell King531060f2012-01-14 10:49:44 +00001201 /* Copy the RGB bitfield overrides */
1202 for (i = 0; i < NR_RGB; i++)
1203 if (inf->rgb[i])
1204 fbi->rgb[i] = inf->rgb[i];
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 init_waitqueue_head(&fbi->ctrlr_wait);
Pavel Machek23432172006-12-17 13:21:05 +01001207 INIT_WORK(&fbi->task, sa1100fb_task);
Matthias Kaehlcke7951ac92008-07-23 21:31:16 -07001208 mutex_init(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 return fbi;
1211}
1212
Uwe Kleine-Königc2e13032010-02-04 20:56:51 +01001213static int __devinit sa1100fb_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
1215 struct sa1100fb_info *fbi;
Russell Kinge9368f82006-01-09 13:56:42 +00001216 int ret, irq;
1217
Russell Kinge1b7a722012-01-14 11:50:04 +00001218 if (!pdev->dev.platform_data) {
1219 dev_err(&pdev->dev, "no platform LCD data\n");
1220 return -EINVAL;
1221 }
1222
Russell Kinge9368f82006-01-09 13:56:42 +00001223 irq = platform_get_irq(pdev, 0);
David Vrabel48944732006-01-19 17:56:29 +00001224 if (irq < 0)
Russell Kinge9368f82006-01-09 13:56:42 +00001225 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
1228 return -EBUSY;
1229
Russell King3ae5eae2005-11-09 22:32:44 +00001230 fbi = sa1100fb_init_fbinfo(&pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 ret = -ENOMEM;
1232 if (!fbi)
1233 goto failed;
1234
1235 /* Initialize video memory */
1236 ret = sa1100fb_map_video_memory(fbi);
1237 if (ret)
1238 goto failed;
1239
Yong Zhangf8798cc2011-09-22 16:59:16 +08001240 ret = request_irq(irq, sa1100fb_handle_irq, 0, "LCD", fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (ret) {
Russell King79889292012-01-14 10:22:56 +00001242 dev_err(&pdev->dev, "request_irq failed: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 goto failed;
1244 }
1245
1246#ifdef ASSABET_PAL_VIDEO
1247 if (machine_is_assabet())
1248 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
1249#endif
1250
1251 /*
1252 * This makes sure that our colour bitfield
1253 * descriptors are correctly initialised.
1254 */
1255 sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
1256
Russell King3ae5eae2005-11-09 22:32:44 +00001257 platform_set_drvdata(pdev, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
1259 ret = register_framebuffer(&fbi->fb);
1260 if (ret < 0)
Russell Kinge9368f82006-01-09 13:56:42 +00001261 goto err_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263#ifdef CONFIG_CPU_FREQ
1264 fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
1265 fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
1266 cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
1267 cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
1268#endif
1269
1270 /* This driver cannot be unloaded at the moment */
1271 return 0;
1272
Russell Kinge9368f82006-01-09 13:56:42 +00001273 err_free_irq:
1274 free_irq(irq, fbi);
1275 failed:
Russell King3ae5eae2005-11-09 22:32:44 +00001276 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 kfree(fbi);
1278 release_mem_region(0xb0100000, 0x10000);
1279 return ret;
1280}
1281
Russell King3ae5eae2005-11-09 22:32:44 +00001282static struct platform_driver sa1100fb_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 .probe = sa1100fb_probe,
1284 .suspend = sa1100fb_suspend,
1285 .resume = sa1100fb_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001286 .driver = {
1287 .name = "sa11x0-fb",
Russell King4f7e34f2012-01-14 10:11:03 +00001288 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001289 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290};
1291
1292int __init sa1100fb_init(void)
1293{
1294 if (fb_get_options("sa1100fb", NULL))
1295 return -ENODEV;
1296
Russell King3ae5eae2005-11-09 22:32:44 +00001297 return platform_driver_register(&sa1100fb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
1300int __init sa1100fb_setup(char *options)
1301{
1302#if 0
1303 char *this_opt;
1304
1305 if (!options || !*options)
1306 return 0;
1307
1308 while ((this_opt = strsep(&options, ",")) != NULL) {
1309
1310 if (!strncmp(this_opt, "bpp:", 4))
1311 current_par.max_bpp =
1312 simple_strtoul(this_opt + 4, NULL, 0);
1313
1314 if (!strncmp(this_opt, "lccr0:", 6))
1315 lcd_shadow.lccr0 =
1316 simple_strtoul(this_opt + 6, NULL, 0);
1317 if (!strncmp(this_opt, "lccr1:", 6)) {
1318 lcd_shadow.lccr1 =
1319 simple_strtoul(this_opt + 6, NULL, 0);
1320 current_par.max_xres =
1321 (lcd_shadow.lccr1 & 0x3ff) + 16;
1322 }
1323 if (!strncmp(this_opt, "lccr2:", 6)) {
1324 lcd_shadow.lccr2 =
1325 simple_strtoul(this_opt + 6, NULL, 0);
1326 current_par.max_yres =
1327 (lcd_shadow.
1328 lccr0 & LCCR0_SDS) ? ((lcd_shadow.
1329 lccr2 & 0x3ff) +
1330 1) *
1331 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
1332 }
1333 if (!strncmp(this_opt, "lccr3:", 6))
1334 lcd_shadow.lccr3 =
1335 simple_strtoul(this_opt + 6, NULL, 0);
1336 }
1337#endif
1338 return 0;
1339}
1340
1341module_init(sa1100fb_init);
1342MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
1343MODULE_LICENSE("GPL");