[PATCH] Kprobes: preempt_disable/enable() simplification
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / s3c2410fb.c
blob3cef90456a4b3fb341c10defa60043aad77404b8
1 /*
2 * linux/drivers/video/s3c2410fb.c
3 * Copyright (c) Arnaud Patard, Ben Dooks
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
9 * S3C2410 LCD Controller Frame Buffer Driver
10 * based on skeletonfb.c, sa1100fb.c and others
12 * ChangeLog
13 * 2005-04-07: Arnaud Patard <arnaud.patard@rtp-net.org>
14 * - u32 state -> pm_message_t state
15 * - S3C2410_{VA,SZ}_LCD -> S3C24XX
17 * 2005-03-15: Arnaud Patard <arnaud.patard@rtp-net.org>
18 * - Removed the ioctl
19 * - use readl/writel instead of __raw_writel/__raw_readl
21 * 2004-12-04: Arnaud Patard <arnaud.patard@rtp-net.org>
22 * - Added the possibility to set on or off the
23 * debugging mesaages
24 * - Replaced 0 and 1 by on or off when reading the
25 * /sys files
27 * 2005-03-23: Ben Dooks <ben-linux@fluff.org>
28 * - added non 16bpp modes
29 * - updated platform information for range of x/y/bpp
30 * - add code to ensure palette is written correctly
31 * - add pixel clock divisor control
33 * 2004-11-11: Arnaud Patard <arnaud.patard@rtp-net.org>
34 * - Removed the use of currcon as it no more exist
35 * - Added LCD power sysfs interface
37 * 2004-11-03: Ben Dooks <ben-linux@fluff.org>
38 * - minor cleanups
39 * - add suspend/resume support
40 * - s3c2410fb_setcolreg() not valid in >8bpp modes
41 * - removed last CONFIG_FB_S3C2410_FIXED
42 * - ensure lcd controller stopped before cleanup
43 * - added sysfs interface for backlight power
44 * - added mask for gpio configuration
45 * - ensured IRQs disabled during GPIO configuration
46 * - disable TPAL before enabling video
48 * 2004-09-20: Arnaud Patard <arnaud.patard@rtp-net.org>
49 * - Suppress command line options
51 * 2004-09-15: Arnaud Patard <arnaud.patard@rtp-net.org>
52 * - code cleanup
54 * 2004-09-07: Arnaud Patard <arnaud.patard@rtp-net.org>
55 * - Renamed from h1940fb.c to s3c2410fb.c
56 * - Add support for different devices
57 * - Backlight support
59 * 2004-09-05: Herbert Pötzl <herbert@13thfloor.at>
60 * - added clock (de-)allocation code
61 * - added fixem fbmem option
63 * 2004-07-27: Arnaud Patard <arnaud.patard@rtp-net.org>
64 * - code cleanup
65 * - added a forgotten return in h1940fb_init
67 * 2004-07-19: Herbert Pötzl <herbert@13thfloor.at>
68 * - code cleanup and extended debugging
70 * 2004-07-15: Arnaud Patard <arnaud.patard@rtp-net.org>
71 * - First version
74 #include <linux/module.h>
75 #include <linux/kernel.h>
76 #include <linux/errno.h>
77 #include <linux/string.h>
78 #include <linux/mm.h>
79 #include <linux/tty.h>
80 #include <linux/slab.h>
81 #include <linux/delay.h>
82 #include <linux/fb.h>
83 #include <linux/init.h>
84 #include <linux/dma-mapping.h>
85 #include <linux/string.h>
86 #include <linux/interrupt.h>
87 #include <linux/workqueue.h>
88 #include <linux/wait.h>
89 #include <linux/platform_device.h>
91 #include <asm/io.h>
92 #include <asm/uaccess.h>
93 #include <asm/div64.h>
95 #include <asm/mach/map.h>
96 #include <asm/arch/regs-lcd.h>
97 #include <asm/arch/regs-gpio.h>
98 #include <asm/arch/fb.h>
99 #include <asm/hardware/clock.h>
101 #ifdef CONFIG_PM
102 #include <linux/pm.h>
103 #endif
105 #include "s3c2410fb.h"
108 static struct s3c2410fb_mach_info *mach_info;
110 /* Debugging stuff */
111 #ifdef CONFIG_FB_S3C2410_DEBUG
112 static int debug = 1;
113 #else
114 static int debug = 0;
115 #endif
117 #define dprintk(msg...) if (debug) { printk(KERN_DEBUG "s3c2410fb: " msg); }
119 /* useful functions */
121 /* s3c2410fb_set_lcdaddr
123 * initialise lcd controller address pointers
126 static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi)
128 struct fb_var_screeninfo *var = &fbi->fb->var;
129 unsigned long saddr1, saddr2, saddr3;
131 saddr1 = fbi->fb->fix.smem_start >> 1;
132 saddr2 = fbi->fb->fix.smem_start;
133 saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8;
134 saddr2>>= 1;
136 saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH(var->xres);
138 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
139 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
140 dprintk("LCDSADDR3 = 0x%08lx\n", saddr3);
142 writel(saddr1, S3C2410_LCDSADDR1);
143 writel(saddr2, S3C2410_LCDSADDR2);
144 writel(saddr3, S3C2410_LCDSADDR3);
147 /* s3c2410fb_calc_pixclk()
149 * calculate divisor for clk->pixclk
152 static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
153 unsigned long pixclk)
155 unsigned long clk = clk_get_rate(fbi->clk);
156 unsigned long long div;
158 /* pixclk is in picoseoncds, our clock is in Hz
160 * Hz -> picoseconds is / 10^-12
163 div = (unsigned long long)clk * pixclk;
164 do_div(div,1000000UL);
165 do_div(div,1000000UL);
167 dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div);
168 return div;
172 * s3c2410fb_check_var():
173 * Get the video params out of 'var'. If a value doesn't fit, round it up,
174 * if it's too big, return -EINVAL.
177 static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
178 struct fb_info *info)
180 struct s3c2410fb_info *fbi = info->par;
182 dprintk("check_var(var=%p, info=%p)\n", var, info);
184 /* validate x/y resolution */
186 if (var->yres > fbi->mach_info->yres.max)
187 var->yres = fbi->mach_info->yres.max;
188 else if (var->yres < fbi->mach_info->yres.min)
189 var->yres = fbi->mach_info->yres.min;
191 if (var->xres > fbi->mach_info->xres.max)
192 var->yres = fbi->mach_info->xres.max;
193 else if (var->xres < fbi->mach_info->xres.min)
194 var->xres = fbi->mach_info->xres.min;
196 /* validate bpp */
198 if (var->bits_per_pixel > fbi->mach_info->bpp.max)
199 var->bits_per_pixel = fbi->mach_info->bpp.max;
200 else if (var->bits_per_pixel < fbi->mach_info->bpp.min)
201 var->bits_per_pixel = fbi->mach_info->bpp.min;
203 /* set r/g/b positions */
205 if (var->bits_per_pixel == 16) {
206 var->red.offset = 11;
207 var->green.offset = 5;
208 var->blue.offset = 0;
209 var->red.length = 5;
210 var->green.length = 6;
211 var->blue.length = 5;
212 var->transp.length = 0;
213 } else {
214 var->red.length = var->bits_per_pixel;
215 var->red.offset = 0;
216 var->green.length = var->bits_per_pixel;
217 var->green.offset = 0;
218 var->blue.length = var->bits_per_pixel;
219 var->blue.offset = 0;
220 var->transp.length = 0;
223 return 0;
226 /* s3c2410fb_activate_var
228 * activate (set) the controller from the given framebuffer
229 * information
232 static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
233 struct fb_var_screeninfo *var)
235 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK;
237 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres);
238 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres);
239 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel);
241 switch (var->bits_per_pixel) {
242 case 1:
243 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
244 break;
245 case 2:
246 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
247 break;
248 case 4:
249 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
250 break;
251 case 8:
252 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
253 break;
254 case 16:
255 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
256 break;
259 /* check to see if we need to update sync/borders */
261 if (!fbi->mach_info->fixed_syncs) {
262 dprintk("setting vert: up=%d, low=%d, sync=%d\n",
263 var->upper_margin, var->lower_margin,
264 var->vsync_len);
266 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
267 var->left_margin, var->right_margin,
268 var->hsync_len);
270 fbi->regs.lcdcon2 =
271 S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
272 S3C2410_LCDCON2_VFPD(var->lower_margin - 1) |
273 S3C2410_LCDCON2_VSPW(var->vsync_len - 1);
275 fbi->regs.lcdcon3 =
276 S3C2410_LCDCON3_HBPD(var->right_margin - 1) |
277 S3C2410_LCDCON3_HFPD(var->left_margin - 1);
279 fbi->regs.lcdcon4 &= ~S3C2410_LCDCON4_HSPW(0xff);
280 fbi->regs.lcdcon4 |= S3C2410_LCDCON4_HSPW(var->hsync_len - 1);
283 /* update X/Y info */
285 fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff);
286 fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1);
288 fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff);
289 fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(var->xres - 1);
291 if (var->pixclock > 0) {
292 int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock);
294 clkdiv = (clkdiv / 2) -1;
295 if (clkdiv < 0)
296 clkdiv = 0;
298 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff);
299 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
302 /* write new registers */
304 dprintk("new register set:\n");
305 dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1);
306 dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2);
307 dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3);
308 dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4);
309 dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5);
311 writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1);
312 writel(fbi->regs.lcdcon2, S3C2410_LCDCON2);
313 writel(fbi->regs.lcdcon3, S3C2410_LCDCON3);
314 writel(fbi->regs.lcdcon4, S3C2410_LCDCON4);
315 writel(fbi->regs.lcdcon5, S3C2410_LCDCON5);
317 /* set lcd address pointers */
318 s3c2410fb_set_lcdaddr(fbi);
320 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
325 * s3c2410fb_set_par - Optional function. Alters the hardware state.
326 * @info: frame buffer structure that represents a single frame buffer
329 static int s3c2410fb_set_par(struct fb_info *info)
331 struct s3c2410fb_info *fbi = info->par;
332 struct fb_var_screeninfo *var = &info->var;
334 if (var->bits_per_pixel == 16)
335 fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR;
336 else
337 fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR;
339 fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8;
341 /* activate this new configuration */
343 s3c2410fb_activate_var(fbi, var);
344 return 0;
347 static void schedule_palette_update(struct s3c2410fb_info *fbi,
348 unsigned int regno, unsigned int val)
350 unsigned long flags;
351 unsigned long irqen;
353 local_irq_save(flags);
355 fbi->palette_buffer[regno] = val;
357 if (!fbi->palette_ready) {
358 fbi->palette_ready = 1;
360 /* enable IRQ */
361 irqen = readl(S3C2410_LCDINTMSK);
362 irqen &= ~S3C2410_LCDINT_FRSYNC;
363 writel(irqen, S3C2410_LCDINTMSK);
366 local_irq_restore(flags);
369 /* from pxafb.c */
370 static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
372 chan &= 0xffff;
373 chan >>= 16 - bf->length;
374 return chan << bf->offset;
377 static int s3c2410fb_setcolreg(unsigned regno,
378 unsigned red, unsigned green, unsigned blue,
379 unsigned transp, struct fb_info *info)
381 struct s3c2410fb_info *fbi = info->par;
382 unsigned int val;
384 /* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n", regno, red, green, blue); */
386 switch (fbi->fb->fix.visual) {
387 case FB_VISUAL_TRUECOLOR:
388 /* true-colour, use pseuo-palette */
390 if (regno < 16) {
391 u32 *pal = fbi->fb->pseudo_palette;
393 val = chan_to_field(red, &fbi->fb->var.red);
394 val |= chan_to_field(green, &fbi->fb->var.green);
395 val |= chan_to_field(blue, &fbi->fb->var.blue);
397 pal[regno] = val;
399 break;
401 case FB_VISUAL_PSEUDOCOLOR:
402 if (regno < 256) {
403 /* currently assume RGB 5-6-5 mode */
405 val = ((red >> 0) & 0xf800);
406 val |= ((green >> 5) & 0x07e0);
407 val |= ((blue >> 11) & 0x001f);
409 writel(val, S3C2410_TFTPAL(regno));
410 schedule_palette_update(fbi, regno, val);
413 break;
415 default:
416 return 1; /* unknown type */
419 return 0;
424 * s3c2410fb_blank
425 * @blank_mode: the blank mode we want.
426 * @info: frame buffer structure that represents a single frame buffer
428 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
429 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
430 * video mode which doesn't support it. Implements VESA suspend
431 * and powerdown modes on hardware that supports disabling hsync/vsync:
432 * blank_mode == 2: suspend vsync
433 * blank_mode == 3: suspend hsync
434 * blank_mode == 4: powerdown
436 * Returns negative errno on error, or zero on success.
439 static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
441 dprintk("blank(mode=%d, info=%p)\n", blank_mode, info);
443 if (mach_info == NULL)
444 return -EINVAL;
446 if (blank_mode == FB_BLANK_UNBLANK)
447 writel(0x0, S3C2410_TPAL);
448 else {
449 dprintk("setting TPAL to output 0x000000\n");
450 writel(S3C2410_TPAL_EN, S3C2410_TPAL);
453 return 0;
456 static int s3c2410fb_debug_show(struct device *dev, struct device_attribute *attr, char *buf)
458 return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off");
460 static int s3c2410fb_debug_store(struct device *dev, struct device_attribute *attr,
461 const char *buf, size_t len)
463 if (mach_info == NULL)
464 return -EINVAL;
466 if (len < 1)
467 return -EINVAL;
469 if (strnicmp(buf, "on", 2) == 0 ||
470 strnicmp(buf, "1", 1) == 0) {
471 debug = 1;
472 printk(KERN_DEBUG "s3c2410fb: Debug On");
473 } else if (strnicmp(buf, "off", 3) == 0 ||
474 strnicmp(buf, "0", 1) == 0) {
475 debug = 0;
476 printk(KERN_DEBUG "s3c2410fb: Debug Off");
477 } else {
478 return -EINVAL;
481 return len;
485 static DEVICE_ATTR(debug, 0666,
486 s3c2410fb_debug_show,
487 s3c2410fb_debug_store);
489 static struct fb_ops s3c2410fb_ops = {
490 .owner = THIS_MODULE,
491 .fb_check_var = s3c2410fb_check_var,
492 .fb_set_par = s3c2410fb_set_par,
493 .fb_blank = s3c2410fb_blank,
494 .fb_setcolreg = s3c2410fb_setcolreg,
495 .fb_fillrect = cfb_fillrect,
496 .fb_copyarea = cfb_copyarea,
497 .fb_imageblit = cfb_imageblit,
498 .fb_cursor = soft_cursor,
503 * s3c2410fb_map_video_memory():
504 * Allocates the DRAM memory for the frame buffer. This buffer is
505 * remapped into a non-cached, non-buffered, memory region to
506 * allow palette and pixel writes to occur without flushing the
507 * cache. Once this area is remapped, all virtual memory
508 * access to the video memory should occur at the new region.
510 static int __init s3c2410fb_map_video_memory(struct s3c2410fb_info *fbi)
512 dprintk("map_video_memory(fbi=%p)\n", fbi);
514 fbi->map_size = PAGE_ALIGN(fbi->fb->fix.smem_len + PAGE_SIZE);
515 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
516 &fbi->map_dma, GFP_KERNEL);
518 fbi->map_size = fbi->fb->fix.smem_len;
520 if (fbi->map_cpu) {
521 /* prevent initial garbage on screen */
522 dprintk("map_video_memory: clear %p:%08x\n",
523 fbi->map_cpu, fbi->map_size);
524 memset(fbi->map_cpu, 0xf0, fbi->map_size);
526 fbi->screen_dma = fbi->map_dma;
527 fbi->fb->screen_base = fbi->map_cpu;
528 fbi->fb->fix.smem_start = fbi->screen_dma;
530 dprintk("map_video_memory: dma=%08x cpu=%p size=%08x\n",
531 fbi->map_dma, fbi->map_cpu, fbi->fb->fix.smem_len);
534 return fbi->map_cpu ? 0 : -ENOMEM;
537 static inline void s3c2410fb_unmap_video_memory(struct s3c2410fb_info *fbi)
539 dma_free_writecombine(fbi->dev,fbi->map_size,fbi->map_cpu, fbi->map_dma);
542 static inline void modify_gpio(void __iomem *reg,
543 unsigned long set, unsigned long mask)
545 unsigned long tmp;
547 tmp = readl(reg) & ~mask;
548 writel(tmp | set, reg);
553 * s3c2410fb_init_registers - Initialise all LCD-related registers
556 int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
558 unsigned long flags;
560 /* Initialise LCD with values from haret */
562 local_irq_save(flags);
564 /* modify the gpio(s) with interrupts set (bjd) */
566 modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask);
567 modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask);
568 modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask);
569 modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask);
571 local_irq_restore(flags);
573 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
574 writel(fbi->regs.lcdcon2, S3C2410_LCDCON2);
575 writel(fbi->regs.lcdcon3, S3C2410_LCDCON3);
576 writel(fbi->regs.lcdcon4, S3C2410_LCDCON4);
577 writel(fbi->regs.lcdcon5, S3C2410_LCDCON5);
579 s3c2410fb_set_lcdaddr(fbi);
581 dprintk("LPCSEL = 0x%08lx\n", mach_info->lpcsel);
582 writel(mach_info->lpcsel, S3C2410_LPCSEL);
584 dprintk("replacing TPAL %08x\n", readl(S3C2410_TPAL));
586 /* ensure temporary palette disabled */
587 writel(0x00, S3C2410_TPAL);
589 /* Enable video by setting the ENVID bit to 1 */
590 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID;
591 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
592 return 0;
595 static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
597 unsigned int i;
598 unsigned long ent;
600 fbi->palette_ready = 0;
602 for (i = 0; i < 256; i++) {
603 if ((ent = fbi->palette_buffer[i]) == PALETTE_BUFF_CLEAR)
604 continue;
606 writel(ent, S3C2410_TFTPAL(i));
608 /* it seems the only way to know exactly
609 * if the palette wrote ok, is to check
610 * to see if the value verifies ok
613 if (readw(S3C2410_TFTPAL(i)) == ent)
614 fbi->palette_buffer[i] = PALETTE_BUFF_CLEAR;
615 else
616 fbi->palette_ready = 1; /* retry */
620 static irqreturn_t s3c2410fb_irq(int irq, void *dev_id, struct pt_regs *r)
622 struct s3c2410fb_info *fbi = dev_id;
623 unsigned long lcdirq = readl(S3C2410_LCDINTPND);
625 if (lcdirq & S3C2410_LCDINT_FRSYNC) {
626 if (fbi->palette_ready)
627 s3c2410fb_write_palette(fbi);
629 writel(S3C2410_LCDINT_FRSYNC, S3C2410_LCDINTPND);
630 writel(S3C2410_LCDINT_FRSYNC, S3C2410_LCDSRCPND);
633 return IRQ_HANDLED;
636 static char driver_name[]="s3c2410fb";
638 int __init s3c2410fb_probe(struct device *dev)
640 struct s3c2410fb_info *info;
641 struct fb_info *fbinfo;
642 struct platform_device *pdev = to_platform_device(dev);
643 struct s3c2410fb_hw *mregs;
644 int ret;
645 int irq;
646 int i;
648 mach_info = dev->platform_data;
649 if (mach_info == NULL) {
650 dev_err(dev,"no platform data for lcd, cannot attach\n");
651 return -EINVAL;
654 mregs = &mach_info->regs;
656 irq = platform_get_irq(pdev, 0);
657 if (irq < 0) {
658 dev_err(dev, "no irq for device\n");
659 return -ENOENT;
662 fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), dev);
663 if (!fbinfo) {
664 return -ENOMEM;
668 info = fbinfo->par;
669 info->fb = fbinfo;
670 dev_set_drvdata(dev, fbinfo);
672 s3c2410fb_init_registers(info);
674 dprintk("devinit\n");
676 strcpy(fbinfo->fix.id, driver_name);
678 memcpy(&info->regs, &mach_info->regs, sizeof(info->regs));
680 info->mach_info = dev->platform_data;
682 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
683 fbinfo->fix.type_aux = 0;
684 fbinfo->fix.xpanstep = 0;
685 fbinfo->fix.ypanstep = 0;
686 fbinfo->fix.ywrapstep = 0;
687 fbinfo->fix.accel = FB_ACCEL_NONE;
689 fbinfo->var.nonstd = 0;
690 fbinfo->var.activate = FB_ACTIVATE_NOW;
691 fbinfo->var.height = mach_info->height;
692 fbinfo->var.width = mach_info->width;
693 fbinfo->var.accel_flags = 0;
694 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
696 fbinfo->fbops = &s3c2410fb_ops;
697 fbinfo->flags = FBINFO_FLAG_DEFAULT;
698 fbinfo->pseudo_palette = &info->pseudo_pal;
700 fbinfo->var.xres = mach_info->xres.defval;
701 fbinfo->var.xres_virtual = mach_info->xres.defval;
702 fbinfo->var.yres = mach_info->yres.defval;
703 fbinfo->var.yres_virtual = mach_info->yres.defval;
704 fbinfo->var.bits_per_pixel = mach_info->bpp.defval;
706 fbinfo->var.upper_margin = S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) +1;
707 fbinfo->var.lower_margin = S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) +1;
708 fbinfo->var.vsync_len = S3C2410_LCDCON2_GET_VSPW(mregs->lcdcon2) + 1;
710 fbinfo->var.left_margin = S3C2410_LCDCON3_GET_HFPD(mregs->lcdcon3) + 1;
711 fbinfo->var.right_margin = S3C2410_LCDCON3_GET_HBPD(mregs->lcdcon3) + 1;
712 fbinfo->var.hsync_len = S3C2410_LCDCON4_GET_HSPW(mregs->lcdcon4) + 1;
714 fbinfo->var.red.offset = 11;
715 fbinfo->var.green.offset = 5;
716 fbinfo->var.blue.offset = 0;
717 fbinfo->var.transp.offset = 0;
718 fbinfo->var.red.length = 5;
719 fbinfo->var.green.length = 6;
720 fbinfo->var.blue.length = 5;
721 fbinfo->var.transp.length = 0;
722 fbinfo->fix.smem_len = mach_info->xres.max *
723 mach_info->yres.max *
724 mach_info->bpp.max / 8;
726 for (i = 0; i < 256; i++)
727 info->palette_buffer[i] = PALETTE_BUFF_CLEAR;
729 if (!request_mem_region((unsigned long)S3C24XX_VA_LCD, SZ_1M, "s3c2410-lcd")) {
730 ret = -EBUSY;
731 goto dealloc_fb;
735 dprintk("got LCD region\n");
737 ret = request_irq(irq, s3c2410fb_irq, SA_INTERRUPT, pdev->name, info);
738 if (ret) {
739 dev_err(dev, "cannot get irq %d - err %d\n", irq, ret);
740 ret = -EBUSY;
741 goto release_mem;
744 info->clk = clk_get(NULL, "lcd");
745 if (!info->clk || IS_ERR(info->clk)) {
746 printk(KERN_ERR "failed to get lcd clock source\n");
747 ret = -ENOENT;
748 goto release_irq;
751 clk_use(info->clk);
752 clk_enable(info->clk);
753 dprintk("got and enabled clock\n");
755 msleep(1);
757 /* Initialize video memory */
758 ret = s3c2410fb_map_video_memory(info);
759 if (ret) {
760 printk( KERN_ERR "Failed to allocate video RAM: %d\n", ret);
761 ret = -ENOMEM;
762 goto release_clock;
764 dprintk("got video memory\n");
766 ret = s3c2410fb_init_registers(info);
768 ret = s3c2410fb_check_var(&fbinfo->var, fbinfo);
770 ret = register_framebuffer(fbinfo);
771 if (ret < 0) {
772 printk(KERN_ERR "Failed to register framebuffer device: %d\n", ret);
773 goto free_video_memory;
776 /* create device files */
777 device_create_file(dev, &dev_attr_debug);
779 printk(KERN_INFO "fb%d: %s frame buffer device\n",
780 fbinfo->node, fbinfo->fix.id);
782 return 0;
784 free_video_memory:
785 s3c2410fb_unmap_video_memory(info);
786 release_clock:
787 clk_disable(info->clk);
788 clk_unuse(info->clk);
789 clk_put(info->clk);
790 release_irq:
791 free_irq(irq,info);
792 release_mem:
793 release_mem_region((unsigned long)S3C24XX_VA_LCD, S3C24XX_SZ_LCD);
794 dealloc_fb:
795 framebuffer_release(fbinfo);
796 return ret;
799 /* s3c2410fb_stop_lcd
801 * shutdown the lcd controller
804 static void s3c2410fb_stop_lcd(void)
806 unsigned long flags;
807 unsigned long tmp;
809 local_irq_save(flags);
811 tmp = readl(S3C2410_LCDCON1);
812 writel(tmp & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1);
814 local_irq_restore(flags);
818 * Cleanup
820 static int s3c2410fb_remove(struct device *dev)
822 struct platform_device *pdev = to_platform_device(dev);
823 struct fb_info *fbinfo = dev_get_drvdata(dev);
824 struct s3c2410fb_info *info = fbinfo->par;
825 int irq;
827 s3c2410fb_stop_lcd();
828 msleep(1);
830 s3c2410fb_unmap_video_memory(info);
832 if (info->clk) {
833 clk_disable(info->clk);
834 clk_unuse(info->clk);
835 clk_put(info->clk);
836 info->clk = NULL;
839 irq = platform_get_irq(pdev, 0);
840 free_irq(irq,info);
841 release_mem_region((unsigned long)S3C24XX_VA_LCD, S3C24XX_SZ_LCD);
842 unregister_framebuffer(fbinfo);
844 return 0;
847 #ifdef CONFIG_PM
849 /* suspend and resume support for the lcd controller */
851 static int s3c2410fb_suspend(struct device *dev, pm_message_t state)
853 struct fb_info *fbinfo = dev_get_drvdata(dev);
854 struct s3c2410fb_info *info = fbinfo->par;
856 s3c2410fb_stop_lcd();
858 /* sleep before disabling the clock, we need to ensure
859 * the LCD DMA engine is not going to get back on the bus
860 * before the clock goes off again (bjd) */
862 msleep(1);
863 clk_disable(info->clk);
865 return 0;
868 static int s3c2410fb_resume(struct device *dev)
870 struct fb_info *fbinfo = dev_get_drvdata(dev);
871 struct s3c2410fb_info *info = fbinfo->par;
873 clk_enable(info->clk);
874 msleep(1);
876 s3c2410fb_init_registers(info);
878 return 0;
881 #else
882 #define s3c2410fb_suspend NULL
883 #define s3c2410fb_resume NULL
884 #endif
886 static struct device_driver s3c2410fb_driver = {
887 .name = "s3c2410-lcd",
888 .bus = &platform_bus_type,
889 .probe = s3c2410fb_probe,
890 .suspend = s3c2410fb_suspend,
891 .resume = s3c2410fb_resume,
892 .remove = s3c2410fb_remove
895 int __devinit s3c2410fb_init(void)
897 return driver_register(&s3c2410fb_driver);
900 static void __exit s3c2410fb_cleanup(void)
902 driver_unregister(&s3c2410fb_driver);
906 module_init(s3c2410fb_init);
907 module_exit(s3c2410fb_cleanup);
909 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, Ben Dooks <ben-linux@fluff.org>");
910 MODULE_DESCRIPTION("Framebuffer driver for the s3c2410");
911 MODULE_LICENSE("GPL");