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
9 * S3C2410 LCD Controller Frame Buffer Driver
10 * based on skeletonfb.c, sa1100fb.c and others
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>
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
24 * - Replaced 0 and 1 by on or off when reading the
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>
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>
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
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>
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>
74 #include <linux/module.h>
75 #include <linux/kernel.h>
76 #include <linux/errno.h>
77 #include <linux/string.h>
79 #include <linux/slab.h>
80 #include <linux/delay.h>
82 #include <linux/init.h>
83 #include <linux/dma-mapping.h>
84 #include <linux/interrupt.h>
85 #include <linux/workqueue.h>
86 #include <linux/wait.h>
87 #include <linux/platform_device.h>
88 #include <linux/clk.h>
91 #include <asm/uaccess.h>
92 #include <asm/div64.h>
94 #include <asm/mach/map.h>
95 #include <asm/arch/regs-lcd.h>
96 #include <asm/arch/regs-gpio.h>
97 #include <asm/arch/fb.h>
100 #include <linux/pm.h>
103 #include "s3c2410fb.h"
105 static struct s3c2410fb_mach_info *mach_info;
107 /* Debugging stuff */
108 #ifdef CONFIG_FB_S3C2410_DEBUG
109 static int debug = 1;
111 static int debug = 0;
114 #define dprintk(msg...) if (debug) { printk(KERN_DEBUG "s3c2410fb: " msg); }
116 /* useful functions */
118 /* s3c2410fb_set_lcdaddr
120 * initialise lcd controller address pointers
122 static void s3c2410fb_set_lcdaddr(struct fb_info *info)
124 unsigned long saddr1, saddr2, saddr3;
125 int line_length = info->var.xres * info->var.bits_per_pixel;
126 struct s3c2410fb_info *fbi = info->par;
127 void __iomem *regs = fbi->io;
129 saddr1 = info->fix.smem_start >> 1;
130 saddr2 = info->fix.smem_start;
131 saddr2 += (line_length * info->var.yres) / 8;
134 saddr3 = S3C2410_OFFSIZE(0) |
135 S3C2410_PAGEWIDTH((line_length / 16) & 0x3ff);
137 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
138 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
139 dprintk("LCDSADDR3 = 0x%08lx\n", saddr3);
141 writel(saddr1, regs + S3C2410_LCDSADDR1);
142 writel(saddr2, regs + S3C2410_LCDSADDR2);
143 writel(saddr3, regs + S3C2410_LCDSADDR3);
146 /* s3c2410fb_calc_pixclk()
148 * calculate divisor for clk->pixclk
150 static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
151 unsigned long pixclk)
153 unsigned long clk = clk_get_rate(fbi->clk);
154 unsigned long long div;
156 /* pixclk is in picoseoncds, our clock is in Hz
158 * Hz -> picoseconds is / 10^-12
161 div = (unsigned long long)clk * pixclk;
162 do_div(div, 1000000UL);
163 do_div(div, 1000000UL);
165 dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div);
170 * s3c2410fb_check_var():
171 * Get the video params out of 'var'. If a value doesn't fit, round it up,
172 * if it's too big, return -EINVAL.
175 static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
176 struct fb_info *info)
178 struct s3c2410fb_info *fbi = info->par;
179 struct s3c2410fb_mach_info *mach_info = fbi->mach_info;
180 struct s3c2410fb_display *display = NULL;
183 dprintk("check_var(var=%p, info=%p)\n", var, info);
185 /* validate x/y resolution */
187 for (i = 0; i < mach_info->num_displays; i++)
188 if (var->yres == mach_info->displays[i].yres &&
189 var->xres == mach_info->displays[i].xres &&
190 var->bits_per_pixel == mach_info->displays[i].bpp) {
191 display = mach_info->displays + i;
192 fbi->current_display = i;
197 dprintk("wrong resolution or depth %dx%d at %d bpp\n",
198 var->xres, var->yres, var->bits_per_pixel);
202 /* it is always the size as the display */
203 var->xres_virtual = display->xres;
204 var->yres_virtual = display->yres;
206 /* copy lcd settings */
207 var->left_margin = display->left_margin;
208 var->right_margin = display->right_margin;
210 var->transp.offset = 0;
211 var->transp.length = 0;
212 /* set r/g/b positions */
213 switch (var->bits_per_pixel) {
218 var->red.length = var->bits_per_pixel;
219 var->green = var->red;
220 var->blue = var->red;
223 if (display->type != S3C2410_LCDCON1_TFT) {
227 var->green.length = 3;
228 var->green.offset = 2;
229 var->blue.length = 2;
230 var->blue.offset = 0;
234 var->green = var->red;
235 var->blue = var->red;
242 var->green.length = 4;
243 var->green.offset = 4;
244 var->blue.length = 4;
245 var->blue.offset = 0;
250 if (display->lcdcon5 & S3C2410_LCDCON5_FRM565) {
251 /* 16 bpp, 565 format */
252 var->red.offset = 11;
253 var->green.offset = 5;
254 var->blue.offset = 0;
256 var->green.length = 6;
257 var->blue.length = 5;
259 /* 16 bpp, 5551 format */
260 var->red.offset = 11;
261 var->green.offset = 6;
262 var->blue.offset = 1;
264 var->green.length = 5;
265 var->blue.length = 5;
269 /* 24 bpp 888 and 8 dummy */
271 var->red.offset = 16;
272 var->green.length = 8;
273 var->green.offset = 8;
274 var->blue.length = 8;
275 var->blue.offset = 0;
281 /* s3c2410fb_calculate_stn_lcd_regs
283 * calculate register values from var settings
285 static void s3c2410fb_calculate_stn_lcd_regs(const struct fb_info *info,
286 struct s3c2410fb_hw *regs)
288 const struct s3c2410fb_info *fbi = info->par;
289 const struct fb_var_screeninfo *var = &info->var;
290 int type = regs->lcdcon1 & ~S3C2410_LCDCON1_TFT;
291 int hs = var->xres >> 2;
292 unsigned wdly = (var->left_margin >> 4) - 1;
293 unsigned wlh = (var->hsync_len >> 4) - 1;
295 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres);
296 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres);
297 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel);
299 if (type != S3C2410_LCDCON1_STN4)
302 regs->lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK;
304 switch (var->bits_per_pixel) {
306 regs->lcdcon1 |= S3C2410_LCDCON1_STN1BPP;
309 regs->lcdcon1 |= S3C2410_LCDCON1_STN2GREY;
312 regs->lcdcon1 |= S3C2410_LCDCON1_STN4GREY;
315 regs->lcdcon1 |= S3C2410_LCDCON1_STN8BPP;
319 regs->lcdcon1 |= S3C2410_LCDCON1_STN12BPP;
324 /* invalid pixel depth */
325 dev_err(fbi->dev, "invalid bpp %d\n",
326 var->bits_per_pixel);
328 /* update X/Y info */
329 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
330 var->left_margin, var->right_margin, var->hsync_len);
332 regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1);
340 regs->lcdcon3 = S3C2410_LCDCON3_WDLY(wdly) |
341 S3C2410_LCDCON3_LINEBLANK(var->right_margin / 8) |
342 S3C2410_LCDCON3_HOZVAL(hs - 1);
344 regs->lcdcon4 = S3C2410_LCDCON4_WLH(wlh);
347 /* s3c2410fb_calculate_tft_lcd_regs
349 * calculate register values from var settings
351 static void s3c2410fb_calculate_tft_lcd_regs(const struct fb_info *info,
352 struct s3c2410fb_hw *regs)
354 const struct s3c2410fb_info *fbi = info->par;
355 const struct fb_var_screeninfo *var = &info->var;
357 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres);
358 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres);
359 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel);
361 regs->lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK;
363 switch (var->bits_per_pixel) {
365 regs->lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
368 regs->lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
371 regs->lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
374 regs->lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
375 regs->lcdcon5 |= S3C2410_LCDCON5_BSWP |
376 S3C2410_LCDCON5_FRM565;
377 regs->lcdcon5 &= ~S3C2410_LCDCON5_HWSWP;
380 regs->lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
381 regs->lcdcon5 &= ~S3C2410_LCDCON5_BSWP;
382 regs->lcdcon5 |= S3C2410_LCDCON5_HWSWP;
385 regs->lcdcon1 |= S3C2410_LCDCON1_TFT24BPP;
386 regs->lcdcon5 &= ~(S3C2410_LCDCON5_BSWP |
387 S3C2410_LCDCON5_HWSWP |
388 S3C2410_LCDCON5_BPP24BL);
391 /* invalid pixel depth */
392 dev_err(fbi->dev, "invalid bpp %d\n",
393 var->bits_per_pixel);
395 /* update X/Y info */
396 dprintk("setting vert: up=%d, low=%d, sync=%d\n",
397 var->upper_margin, var->lower_margin, var->vsync_len);
399 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
400 var->left_margin, var->right_margin, var->hsync_len);
402 regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1) |
403 S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
404 S3C2410_LCDCON2_VFPD(var->lower_margin - 1) |
405 S3C2410_LCDCON2_VSPW(var->vsync_len - 1);
407 regs->lcdcon3 = S3C2410_LCDCON3_HBPD(var->right_margin - 1) |
408 S3C2410_LCDCON3_HFPD(var->left_margin - 1) |
409 S3C2410_LCDCON3_HOZVAL(var->xres - 1);
411 regs->lcdcon4 = S3C2410_LCDCON4_HSPW(var->hsync_len - 1);
414 /* s3c2410fb_activate_var
416 * activate (set) the controller from the given framebuffer
419 static void s3c2410fb_activate_var(struct fb_info *info)
421 struct s3c2410fb_info *fbi = info->par;
422 void __iomem *regs = fbi->io;
423 struct fb_var_screeninfo *var = &info->var;
424 struct s3c2410fb_mach_info *mach_info = fbi->mach_info;
425 struct s3c2410fb_display *display = mach_info->displays +
426 fbi->current_display;
428 /* set display type */
429 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_TFT;
430 fbi->regs.lcdcon1 |= display->type;
432 if (var->pixclock > 0) {
433 int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock);
435 if (display->type == S3C2410_LCDCON1_TFT) {
436 clkdiv = (clkdiv / 2) - 1;
440 clkdiv = (clkdiv / 2);
445 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff);
446 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
449 if (display->type == S3C2410_LCDCON1_TFT)
450 s3c2410fb_calculate_tft_lcd_regs(info, &fbi->regs);
452 s3c2410fb_calculate_stn_lcd_regs(info, &fbi->regs);
454 /* write new registers */
456 dprintk("new register set:\n");
457 dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1);
458 dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2);
459 dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3);
460 dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4);
461 dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5);
463 writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID,
464 regs + S3C2410_LCDCON1);
465 writel(fbi->regs.lcdcon2, regs + S3C2410_LCDCON2);
466 writel(fbi->regs.lcdcon3, regs + S3C2410_LCDCON3);
467 writel(fbi->regs.lcdcon4, regs + S3C2410_LCDCON4);
468 writel(fbi->regs.lcdcon5, regs + S3C2410_LCDCON5);
470 /* set lcd address pointers */
471 s3c2410fb_set_lcdaddr(info);
473 writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1);
477 * s3c2410fb_set_par - Alters the hardware state.
478 * @info: frame buffer structure that represents a single frame buffer
481 static int s3c2410fb_set_par(struct fb_info *info)
483 struct fb_var_screeninfo *var = &info->var;
485 switch (var->bits_per_pixel) {
489 info->fix.visual = FB_VISUAL_TRUECOLOR;
492 info->fix.visual = FB_VISUAL_MONO01;
495 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
499 info->fix.line_length = (var->width * var->bits_per_pixel) / 8;
501 /* activate this new configuration */
503 s3c2410fb_activate_var(info);
507 static void schedule_palette_update(struct s3c2410fb_info *fbi,
508 unsigned int regno, unsigned int val)
512 void __iomem *regs = fbi->io;
514 local_irq_save(flags);
516 fbi->palette_buffer[regno] = val;
518 if (!fbi->palette_ready) {
519 fbi->palette_ready = 1;
522 irqen = readl(regs + S3C2410_LCDINTMSK);
523 irqen &= ~S3C2410_LCDINT_FRSYNC;
524 writel(irqen, regs + S3C2410_LCDINTMSK);
527 local_irq_restore(flags);
531 static inline unsigned int chan_to_field(unsigned int chan,
532 struct fb_bitfield *bf)
535 chan >>= 16 - bf->length;
536 return chan << bf->offset;
539 static int s3c2410fb_setcolreg(unsigned regno,
540 unsigned red, unsigned green, unsigned blue,
541 unsigned transp, struct fb_info *info)
543 struct s3c2410fb_info *fbi = info->par;
544 void __iomem *regs = fbi->io;
547 /* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n",
548 regno, red, green, blue); */
550 switch (info->fix.visual) {
551 case FB_VISUAL_TRUECOLOR:
552 /* true-colour, use pseudo-palette */
555 u32 *pal = info->pseudo_palette;
557 val = chan_to_field(red, &info->var.red);
558 val |= chan_to_field(green, &info->var.green);
559 val |= chan_to_field(blue, &info->var.blue);
565 case FB_VISUAL_PSEUDOCOLOR:
567 /* currently assume RGB 5-6-5 mode */
569 val = ((red >> 0) & 0xf800);
570 val |= ((green >> 5) & 0x07e0);
571 val |= ((blue >> 11) & 0x001f);
573 writel(val, regs + S3C2410_TFTPAL(regno));
574 schedule_palette_update(fbi, regno, val);
580 return 1; /* unknown type */
588 * @blank_mode: the blank mode we want.
589 * @info: frame buffer structure that represents a single frame buffer
591 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
592 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
593 * video mode which doesn't support it. Implements VESA suspend
594 * and powerdown modes on hardware that supports disabling hsync/vsync:
595 * blank_mode == 2: suspend vsync
596 * blank_mode == 3: suspend hsync
597 * blank_mode == 4: powerdown
599 * Returns negative errno on error, or zero on success.
602 static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
604 struct s3c2410fb_info *fbi = info->par;
605 void __iomem *regs = fbi->io;
607 dprintk("blank(mode=%d, info=%p)\n", blank_mode, info);
609 if (mach_info == NULL)
612 if (blank_mode == FB_BLANK_UNBLANK)
613 writel(0x0, regs + S3C2410_TPAL);
615 dprintk("setting TPAL to output 0x000000\n");
616 writel(S3C2410_TPAL_EN, regs + S3C2410_TPAL);
622 static int s3c2410fb_debug_show(struct device *dev,
623 struct device_attribute *attr, char *buf)
625 return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off");
627 static int s3c2410fb_debug_store(struct device *dev,
628 struct device_attribute *attr,
629 const char *buf, size_t len)
631 if (mach_info == NULL)
637 if (strnicmp(buf, "on", 2) == 0 ||
638 strnicmp(buf, "1", 1) == 0) {
640 printk(KERN_DEBUG "s3c2410fb: Debug On");
641 } else if (strnicmp(buf, "off", 3) == 0 ||
642 strnicmp(buf, "0", 1) == 0) {
644 printk(KERN_DEBUG "s3c2410fb: Debug Off");
652 static DEVICE_ATTR(debug, 0666, s3c2410fb_debug_show, s3c2410fb_debug_store);
654 static struct fb_ops s3c2410fb_ops = {
655 .owner = THIS_MODULE,
656 .fb_check_var = s3c2410fb_check_var,
657 .fb_set_par = s3c2410fb_set_par,
658 .fb_blank = s3c2410fb_blank,
659 .fb_setcolreg = s3c2410fb_setcolreg,
660 .fb_fillrect = cfb_fillrect,
661 .fb_copyarea = cfb_copyarea,
662 .fb_imageblit = cfb_imageblit,
666 * s3c2410fb_map_video_memory():
667 * Allocates the DRAM memory for the frame buffer. This buffer is
668 * remapped into a non-cached, non-buffered, memory region to
669 * allow palette and pixel writes to occur without flushing the
670 * cache. Once this area is remapped, all virtual memory
671 * access to the video memory should occur at the new region.
673 static int __init s3c2410fb_map_video_memory(struct fb_info *info)
675 struct s3c2410fb_info *fbi = info->par;
677 dprintk("map_video_memory(fbi=%p)\n", fbi);
679 fbi->map_size = PAGE_ALIGN(info->fix.smem_len + PAGE_SIZE);
680 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
681 &fbi->map_dma, GFP_KERNEL);
683 fbi->map_size = info->fix.smem_len;
686 /* prevent initial garbage on screen */
687 dprintk("map_video_memory: clear %p:%08x\n",
688 fbi->map_cpu, fbi->map_size);
689 memset(fbi->map_cpu, 0xf0, fbi->map_size);
691 fbi->screen_dma = fbi->map_dma;
692 info->screen_base = fbi->map_cpu;
693 info->fix.smem_start = fbi->screen_dma;
695 dprintk("map_video_memory: dma=%08x cpu=%p size=%08x\n",
696 fbi->map_dma, fbi->map_cpu, info->fix.smem_len);
699 return fbi->map_cpu ? 0 : -ENOMEM;
702 static inline void s3c2410fb_unmap_video_memory(struct s3c2410fb_info *fbi)
704 dma_free_writecombine(fbi->dev, fbi->map_size, fbi->map_cpu,
708 static inline void modify_gpio(void __iomem *reg,
709 unsigned long set, unsigned long mask)
713 tmp = readl(reg) & ~mask;
714 writel(tmp | set, reg);
718 * s3c2410fb_init_registers - Initialise all LCD-related registers
720 static int s3c2410fb_init_registers(struct fb_info *info)
722 struct s3c2410fb_info *fbi = info->par;
724 void __iomem *regs = fbi->io;
726 /* Initialise LCD with values from haret */
728 local_irq_save(flags);
730 /* modify the gpio(s) with interrupts set (bjd) */
732 modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask);
733 modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask);
734 modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask);
735 modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask);
737 local_irq_restore(flags);
739 writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1);
740 writel(fbi->regs.lcdcon2, regs + S3C2410_LCDCON2);
741 writel(fbi->regs.lcdcon3, regs + S3C2410_LCDCON3);
742 writel(fbi->regs.lcdcon4, regs + S3C2410_LCDCON4);
743 writel(fbi->regs.lcdcon5, regs + S3C2410_LCDCON5);
745 s3c2410fb_set_lcdaddr(info);
747 dprintk("LPCSEL = 0x%08lx\n", mach_info->lpcsel);
748 writel(mach_info->lpcsel, regs + S3C2410_LPCSEL);
750 dprintk("replacing TPAL %08x\n", readl(regs + S3C2410_TPAL));
752 /* ensure temporary palette disabled */
753 writel(0x00, regs + S3C2410_TPAL);
755 /* Enable video by setting the ENVID bit to 1 */
756 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID;
757 writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1);
761 static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
764 void __iomem *regs = fbi->io;
766 fbi->palette_ready = 0;
768 for (i = 0; i < 256; i++) {
769 unsigned long ent = fbi->palette_buffer[i];
770 if (ent == PALETTE_BUFF_CLEAR)
773 writel(ent, regs + S3C2410_TFTPAL(i));
775 /* it seems the only way to know exactly
776 * if the palette wrote ok, is to check
777 * to see if the value verifies ok
780 if (readw(regs + S3C2410_TFTPAL(i)) == ent)
781 fbi->palette_buffer[i] = PALETTE_BUFF_CLEAR;
783 fbi->palette_ready = 1; /* retry */
787 static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
789 struct s3c2410fb_info *fbi = dev_id;
790 void __iomem *regs = fbi->io;
791 unsigned long lcdirq = readl(regs + S3C2410_LCDINTPND);
793 if (lcdirq & S3C2410_LCDINT_FRSYNC) {
794 if (fbi->palette_ready)
795 s3c2410fb_write_palette(fbi);
797 writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDINTPND);
798 writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDSRCPND);
804 static char driver_name[] = "s3c2410fb";
806 static int __init s3c2410fb_probe(struct platform_device *pdev)
808 struct s3c2410fb_info *info;
809 struct s3c2410fb_display *display;
810 struct fb_info *fbinfo;
811 struct resource *res;
818 mach_info = pdev->dev.platform_data;
819 if (mach_info == NULL) {
821 "no platform data for lcd, cannot attach\n");
825 display = mach_info->displays + mach_info->default_display;
827 irq = platform_get_irq(pdev, 0);
829 dev_err(&pdev->dev, "no irq for device\n");
833 fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), &pdev->dev);
838 info->dev = &pdev->dev;
840 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
842 dev_err(&pdev->dev, "failed to get memory registers\n");
847 size = (res->end - res->start) + 1;
848 info->mem = request_mem_region(res->start, size, pdev->name);
849 if (info->mem == NULL) {
850 dev_err(&pdev->dev, "failed to get memory region\n");
855 info->io = ioremap(res->start, size);
856 if (info->io == NULL) {
857 dev_err(&pdev->dev, "ioremap() of registers failed\n");
862 platform_set_drvdata(pdev, fbinfo);
864 dprintk("devinit\n");
866 strcpy(fbinfo->fix.id, driver_name);
868 info->regs.lcdcon1 = display->lcdcon1;
869 info->regs.lcdcon5 = display->lcdcon5;
871 /* Stop the video and unset ENVID if set */
872 info->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID;
873 lcdcon1 = readl(info->io + S3C2410_LCDCON1);
874 writel(lcdcon1 & ~S3C2410_LCDCON1_ENVID, info->io + S3C2410_LCDCON1);
876 info->mach_info = pdev->dev.platform_data;
877 info->current_display = mach_info->default_display;
879 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
880 fbinfo->fix.type_aux = 0;
881 fbinfo->fix.xpanstep = 0;
882 fbinfo->fix.ypanstep = 0;
883 fbinfo->fix.ywrapstep = 0;
884 fbinfo->fix.accel = FB_ACCEL_NONE;
886 fbinfo->var.nonstd = 0;
887 fbinfo->var.activate = FB_ACTIVATE_NOW;
888 fbinfo->var.height = display->height;
889 fbinfo->var.width = display->width;
890 fbinfo->var.accel_flags = 0;
891 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
893 fbinfo->fbops = &s3c2410fb_ops;
894 fbinfo->flags = FBINFO_FLAG_DEFAULT;
895 fbinfo->pseudo_palette = &info->pseudo_pal;
897 fbinfo->var.xres = display->xres;
898 fbinfo->var.xres_virtual = display->xres;
899 fbinfo->var.yres = display->yres;
900 fbinfo->var.yres_virtual = display->yres;
901 fbinfo->var.bits_per_pixel = display->bpp;
902 fbinfo->var.left_margin = display->left_margin;
903 fbinfo->var.right_margin = display->right_margin;
905 fbinfo->var.upper_margin = display->upper_margin;
906 fbinfo->var.lower_margin = display->lower_margin;
907 fbinfo->var.vsync_len = display->vsync_len;
908 fbinfo->var.hsync_len = display->hsync_len;
910 fbinfo->var.red.offset = 11;
911 fbinfo->var.green.offset = 5;
912 fbinfo->var.blue.offset = 0;
913 fbinfo->var.transp.offset = 0;
914 fbinfo->var.red.length = 5;
915 fbinfo->var.green.length = 6;
916 fbinfo->var.blue.length = 5;
917 fbinfo->var.transp.length = 0;
919 /* find maximum required memory size for display */
920 for (i = 0; i < mach_info->num_displays; i++) {
921 unsigned long smem_len = mach_info->displays[i].xres;
923 smem_len *= mach_info->displays[i].yres;
924 smem_len *= mach_info->displays[i].bpp;
926 if (fbinfo->fix.smem_len < smem_len)
927 fbinfo->fix.smem_len = smem_len;
930 for (i = 0; i < 256; i++)
931 info->palette_buffer[i] = PALETTE_BUFF_CLEAR;
933 ret = request_irq(irq, s3c2410fb_irq, IRQF_DISABLED, pdev->name, info);
935 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
940 info->clk = clk_get(NULL, "lcd");
941 if (!info->clk || IS_ERR(info->clk)) {
942 printk(KERN_ERR "failed to get lcd clock source\n");
947 clk_enable(info->clk);
948 dprintk("got and enabled clock\n");
952 /* Initialize video memory */
953 ret = s3c2410fb_map_video_memory(fbinfo);
955 printk(KERN_ERR "Failed to allocate video RAM: %d\n", ret);
960 dprintk("got video memory\n");
962 s3c2410fb_init_registers(fbinfo);
964 s3c2410fb_check_var(&fbinfo->var, fbinfo);
966 ret = register_framebuffer(fbinfo);
968 printk(KERN_ERR "Failed to register framebuffer device: %d\n",
970 goto free_video_memory;
973 /* create device files */
974 device_create_file(&pdev->dev, &dev_attr_debug);
976 printk(KERN_INFO "fb%d: %s frame buffer device\n",
977 fbinfo->node, fbinfo->fix.id);
982 s3c2410fb_unmap_video_memory(info);
984 clk_disable(info->clk);
991 release_resource(info->mem);
994 framebuffer_release(fbinfo);
998 /* s3c2410fb_stop_lcd
1000 * shutdown the lcd controller
1002 static void s3c2410fb_stop_lcd(struct s3c2410fb_info *fbi)
1004 unsigned long flags;
1006 local_irq_save(flags);
1008 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID;
1009 writel(fbi->regs.lcdcon1, fbi->io + S3C2410_LCDCON1);
1011 local_irq_restore(flags);
1017 static int s3c2410fb_remove(struct platform_device *pdev)
1019 struct fb_info *fbinfo = platform_get_drvdata(pdev);
1020 struct s3c2410fb_info *info = fbinfo->par;
1023 s3c2410fb_stop_lcd(info);
1026 s3c2410fb_unmap_video_memory(info);
1029 clk_disable(info->clk);
1034 irq = platform_get_irq(pdev, 0);
1035 free_irq(irq, info);
1037 release_resource(info->mem);
1040 unregister_framebuffer(fbinfo);
1047 /* suspend and resume support for the lcd controller */
1048 static int s3c2410fb_suspend(struct platform_device *dev, pm_message_t state)
1050 struct fb_info *fbinfo = platform_get_drvdata(dev);
1051 struct s3c2410fb_info *info = fbinfo->par;
1053 s3c2410fb_stop_lcd(info);
1055 /* sleep before disabling the clock, we need to ensure
1056 * the LCD DMA engine is not going to get back on the bus
1057 * before the clock goes off again (bjd) */
1060 clk_disable(info->clk);
1065 static int s3c2410fb_resume(struct platform_device *dev)
1067 struct fb_info *fbinfo = platform_get_drvdata(dev);
1068 struct s3c2410fb_info *info = fbinfo->par;
1070 clk_enable(info->clk);
1073 s3c2410fb_init_registers(info);
1079 #define s3c2410fb_suspend NULL
1080 #define s3c2410fb_resume NULL
1083 static struct platform_driver s3c2410fb_driver = {
1084 .probe = s3c2410fb_probe,
1085 .remove = s3c2410fb_remove,
1086 .suspend = s3c2410fb_suspend,
1087 .resume = s3c2410fb_resume,
1089 .name = "s3c2410-lcd",
1090 .owner = THIS_MODULE,
1094 int __devinit s3c2410fb_init(void)
1096 return platform_driver_register(&s3c2410fb_driver);
1099 static void __exit s3c2410fb_cleanup(void)
1101 platform_driver_unregister(&s3c2410fb_driver);
1104 module_init(s3c2410fb_init);
1105 module_exit(s3c2410fb_cleanup);
1107 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, "
1108 "Ben Dooks <ben-linux@fluff.org>");
1109 MODULE_DESCRIPTION("Framebuffer driver for the s3c2410");
1110 MODULE_LICENSE("GPL");