1 /* linux/drivers/video/s3c2410fb.c
2 * Copyright (c) 2004,2005 Arnaud Patard
3 * Copyright (c) 2004-2008 Ben Dooks
5 * S3C2410 LCD Framebuffer Driver
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
11 * Driver based on skeletonfb.c, sa1100fb.c and others.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/err.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
22 #include <linux/slab.h>
23 #include <linux/delay.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/cpufreq.h>
33 #include <asm/div64.h>
35 #include <asm/mach/map.h>
36 #include <mach/regs-lcd.h>
37 #include <mach/regs-gpio.h>
44 #include "s3c2410fb.h"
47 static int debug = IS_BUILTIN(CONFIG_FB_S3C2410_DEBUG);
49 #define dprintk(msg...) \
55 /* useful functions */
57 static int is_s3c2412(struct s3c2410fb_info *fbi)
59 return (fbi->drv_type == DRV_S3C2412);
62 /* s3c2410fb_set_lcdaddr
64 * initialise lcd controller address pointers
66 static void s3c2410fb_set_lcdaddr(struct fb_info *info)
68 unsigned long saddr1, saddr2, saddr3;
69 struct s3c2410fb_info *fbi = info->par;
70 void __iomem *regs = fbi->io;
72 saddr1 = info->fix.smem_start >> 1;
73 saddr2 = info->fix.smem_start;
74 saddr2 += info->fix.line_length * info->var.yres;
77 saddr3 = S3C2410_OFFSIZE(0) |
78 S3C2410_PAGEWIDTH((info->fix.line_length / 2) & 0x3ff);
80 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
81 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
82 dprintk("LCDSADDR3 = 0x%08lx\n", saddr3);
84 writel(saddr1, regs + S3C2410_LCDSADDR1);
85 writel(saddr2, regs + S3C2410_LCDSADDR2);
86 writel(saddr3, regs + S3C2410_LCDSADDR3);
89 /* s3c2410fb_calc_pixclk()
91 * calculate divisor for clk->pixclk
93 static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
96 unsigned long clk = fbi->clk_rate;
97 unsigned long long div;
99 /* pixclk is in picoseconds, our clock is in Hz
101 * Hz -> picoseconds is / 10^-12
104 div = (unsigned long long)clk * pixclk;
105 div >>= 12; /* div / 2^12 */
106 do_div(div, 625 * 625UL * 625); /* div / 5^12 */
108 dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div);
113 * s3c2410fb_check_var():
114 * Get the video params out of 'var'. If a value doesn't fit, round it up,
115 * if it's too big, return -EINVAL.
118 static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
119 struct fb_info *info)
121 struct s3c2410fb_info *fbi = info->par;
122 struct s3c2410fb_mach_info *mach_info = dev_get_platdata(fbi->dev);
123 struct s3c2410fb_display *display = NULL;
124 struct s3c2410fb_display *default_display = mach_info->displays +
125 mach_info->default_display;
126 int type = default_display->type;
129 dprintk("check_var(var=%p, info=%p)\n", var, info);
131 /* validate x/y resolution */
132 /* choose default mode if possible */
133 if (var->yres == default_display->yres &&
134 var->xres == default_display->xres &&
135 var->bits_per_pixel == default_display->bpp)
136 display = default_display;
138 for (i = 0; i < mach_info->num_displays; i++)
139 if (type == mach_info->displays[i].type &&
140 var->yres == mach_info->displays[i].yres &&
141 var->xres == mach_info->displays[i].xres &&
142 var->bits_per_pixel == mach_info->displays[i].bpp) {
143 display = mach_info->displays + i;
148 dprintk("wrong resolution or depth %dx%d at %d bpp\n",
149 var->xres, var->yres, var->bits_per_pixel);
153 /* it is always the size as the display */
154 var->xres_virtual = display->xres;
155 var->yres_virtual = display->yres;
156 var->height = display->height;
157 var->width = display->width;
159 /* copy lcd settings */
160 var->pixclock = display->pixclock;
161 var->left_margin = display->left_margin;
162 var->right_margin = display->right_margin;
163 var->upper_margin = display->upper_margin;
164 var->lower_margin = display->lower_margin;
165 var->vsync_len = display->vsync_len;
166 var->hsync_len = display->hsync_len;
168 fbi->regs.lcdcon5 = display->lcdcon5;
169 /* set display type */
170 fbi->regs.lcdcon1 = display->type;
172 var->transp.offset = 0;
173 var->transp.length = 0;
174 /* set r/g/b positions */
175 switch (var->bits_per_pixel) {
180 var->red.length = var->bits_per_pixel;
181 var->green = var->red;
182 var->blue = var->red;
185 if (display->type != S3C2410_LCDCON1_TFT) {
189 var->green.length = 3;
190 var->green.offset = 2;
191 var->blue.length = 2;
192 var->blue.offset = 0;
196 var->green = var->red;
197 var->blue = var->red;
204 var->green.length = 4;
205 var->green.offset = 4;
206 var->blue.length = 4;
207 var->blue.offset = 0;
212 if (display->lcdcon5 & S3C2410_LCDCON5_FRM565) {
213 /* 16 bpp, 565 format */
214 var->red.offset = 11;
215 var->green.offset = 5;
216 var->blue.offset = 0;
218 var->green.length = 6;
219 var->blue.length = 5;
221 /* 16 bpp, 5551 format */
222 var->red.offset = 11;
223 var->green.offset = 6;
224 var->blue.offset = 1;
226 var->green.length = 5;
227 var->blue.length = 5;
231 /* 24 bpp 888 and 8 dummy */
233 var->red.offset = 16;
234 var->green.length = 8;
235 var->green.offset = 8;
236 var->blue.length = 8;
237 var->blue.offset = 0;
243 /* s3c2410fb_calculate_stn_lcd_regs
245 * calculate register values from var settings
247 static void s3c2410fb_calculate_stn_lcd_regs(const struct fb_info *info,
248 struct s3c2410fb_hw *regs)
250 const struct s3c2410fb_info *fbi = info->par;
251 const struct fb_var_screeninfo *var = &info->var;
252 int type = regs->lcdcon1 & ~S3C2410_LCDCON1_TFT;
253 int hs = var->xres >> 2;
254 unsigned wdly = (var->left_margin >> 4) - 1;
255 unsigned wlh = (var->hsync_len >> 4) - 1;
257 if (type != S3C2410_LCDCON1_STN4)
260 switch (var->bits_per_pixel) {
262 regs->lcdcon1 |= S3C2410_LCDCON1_STN1BPP;
265 regs->lcdcon1 |= S3C2410_LCDCON1_STN2GREY;
268 regs->lcdcon1 |= S3C2410_LCDCON1_STN4GREY;
271 regs->lcdcon1 |= S3C2410_LCDCON1_STN8BPP;
275 regs->lcdcon1 |= S3C2410_LCDCON1_STN12BPP;
280 /* invalid pixel depth */
281 dev_err(fbi->dev, "invalid bpp %d\n",
282 var->bits_per_pixel);
284 /* update X/Y info */
285 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
286 var->left_margin, var->right_margin, var->hsync_len);
288 regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1);
296 regs->lcdcon3 = S3C2410_LCDCON3_WDLY(wdly) |
297 S3C2410_LCDCON3_LINEBLANK(var->right_margin / 8) |
298 S3C2410_LCDCON3_HOZVAL(hs - 1);
300 regs->lcdcon4 = S3C2410_LCDCON4_WLH(wlh);
303 /* s3c2410fb_calculate_tft_lcd_regs
305 * calculate register values from var settings
307 static void s3c2410fb_calculate_tft_lcd_regs(const struct fb_info *info,
308 struct s3c2410fb_hw *regs)
310 const struct s3c2410fb_info *fbi = info->par;
311 const struct fb_var_screeninfo *var = &info->var;
313 switch (var->bits_per_pixel) {
315 regs->lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
318 regs->lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
321 regs->lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
324 regs->lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
325 regs->lcdcon5 |= S3C2410_LCDCON5_BSWP |
326 S3C2410_LCDCON5_FRM565;
327 regs->lcdcon5 &= ~S3C2410_LCDCON5_HWSWP;
330 regs->lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
331 regs->lcdcon5 &= ~S3C2410_LCDCON5_BSWP;
332 regs->lcdcon5 |= S3C2410_LCDCON5_HWSWP;
335 regs->lcdcon1 |= S3C2410_LCDCON1_TFT24BPP;
336 regs->lcdcon5 &= ~(S3C2410_LCDCON5_BSWP |
337 S3C2410_LCDCON5_HWSWP |
338 S3C2410_LCDCON5_BPP24BL);
341 /* invalid pixel depth */
342 dev_err(fbi->dev, "invalid bpp %d\n",
343 var->bits_per_pixel);
345 /* update X/Y info */
346 dprintk("setting vert: up=%d, low=%d, sync=%d\n",
347 var->upper_margin, var->lower_margin, var->vsync_len);
349 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
350 var->left_margin, var->right_margin, var->hsync_len);
352 regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1) |
353 S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
354 S3C2410_LCDCON2_VFPD(var->lower_margin - 1) |
355 S3C2410_LCDCON2_VSPW(var->vsync_len - 1);
357 regs->lcdcon3 = S3C2410_LCDCON3_HBPD(var->right_margin - 1) |
358 S3C2410_LCDCON3_HFPD(var->left_margin - 1) |
359 S3C2410_LCDCON3_HOZVAL(var->xres - 1);
361 regs->lcdcon4 = S3C2410_LCDCON4_HSPW(var->hsync_len - 1);
364 /* s3c2410fb_activate_var
366 * activate (set) the controller from the given framebuffer
369 static void s3c2410fb_activate_var(struct fb_info *info)
371 struct s3c2410fb_info *fbi = info->par;
372 void __iomem *regs = fbi->io;
373 int type = fbi->regs.lcdcon1 & S3C2410_LCDCON1_TFT;
374 struct fb_var_screeninfo *var = &info->var;
377 clkdiv = DIV_ROUND_UP(s3c2410fb_calc_pixclk(fbi, var->pixclock), 2);
379 dprintk("%s: var->xres = %d\n", __func__, var->xres);
380 dprintk("%s: var->yres = %d\n", __func__, var->yres);
381 dprintk("%s: var->bpp = %d\n", __func__, var->bits_per_pixel);
383 if (type == S3C2410_LCDCON1_TFT) {
384 s3c2410fb_calculate_tft_lcd_regs(info, &fbi->regs);
389 s3c2410fb_calculate_stn_lcd_regs(info, &fbi->regs);
394 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
396 /* write new registers */
398 dprintk("new register set:\n");
399 dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1);
400 dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2);
401 dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3);
402 dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4);
403 dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5);
405 writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID,
406 regs + S3C2410_LCDCON1);
407 writel(fbi->regs.lcdcon2, regs + S3C2410_LCDCON2);
408 writel(fbi->regs.lcdcon3, regs + S3C2410_LCDCON3);
409 writel(fbi->regs.lcdcon4, regs + S3C2410_LCDCON4);
410 writel(fbi->regs.lcdcon5, regs + S3C2410_LCDCON5);
412 /* set lcd address pointers */
413 s3c2410fb_set_lcdaddr(info);
415 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID,
416 writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1);
420 * s3c2410fb_set_par - Alters the hardware state.
421 * @info: frame buffer structure that represents a single frame buffer
424 static int s3c2410fb_set_par(struct fb_info *info)
426 struct fb_var_screeninfo *var = &info->var;
428 switch (var->bits_per_pixel) {
432 info->fix.visual = FB_VISUAL_TRUECOLOR;
435 info->fix.visual = FB_VISUAL_MONO01;
438 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
442 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
444 /* activate this new configuration */
446 s3c2410fb_activate_var(info);
450 static void schedule_palette_update(struct s3c2410fb_info *fbi,
451 unsigned int regno, unsigned int val)
455 void __iomem *irq_base = fbi->irq_base;
457 local_irq_save(flags);
459 fbi->palette_buffer[regno] = val;
461 if (!fbi->palette_ready) {
462 fbi->palette_ready = 1;
465 irqen = readl(irq_base + S3C24XX_LCDINTMSK);
466 irqen &= ~S3C2410_LCDINT_FRSYNC;
467 writel(irqen, irq_base + S3C24XX_LCDINTMSK);
470 local_irq_restore(flags);
474 static inline unsigned int chan_to_field(unsigned int chan,
475 struct fb_bitfield *bf)
478 chan >>= 16 - bf->length;
479 return chan << bf->offset;
482 static int s3c2410fb_setcolreg(unsigned regno,
483 unsigned red, unsigned green, unsigned blue,
484 unsigned transp, struct fb_info *info)
486 struct s3c2410fb_info *fbi = info->par;
487 void __iomem *regs = fbi->io;
490 /* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n",
491 regno, red, green, blue); */
493 switch (info->fix.visual) {
494 case FB_VISUAL_TRUECOLOR:
495 /* true-colour, use pseudo-palette */
498 u32 *pal = info->pseudo_palette;
500 val = chan_to_field(red, &info->var.red);
501 val |= chan_to_field(green, &info->var.green);
502 val |= chan_to_field(blue, &info->var.blue);
508 case FB_VISUAL_PSEUDOCOLOR:
510 /* currently assume RGB 5-6-5 mode */
512 val = (red >> 0) & 0xf800;
513 val |= (green >> 5) & 0x07e0;
514 val |= (blue >> 11) & 0x001f;
516 writel(val, regs + S3C2410_TFTPAL(regno));
517 schedule_palette_update(fbi, regno, val);
523 return 1; /* unknown type */
529 /* s3c2410fb_lcd_enable
531 * shutdown the lcd controller
533 static void s3c2410fb_lcd_enable(struct s3c2410fb_info *fbi, int enable)
537 local_irq_save(flags);
540 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID;
542 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID;
544 writel(fbi->regs.lcdcon1, fbi->io + S3C2410_LCDCON1);
546 local_irq_restore(flags);
552 * @blank_mode: the blank mode we want.
553 * @info: frame buffer structure that represents a single frame buffer
555 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
556 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
557 * video mode which doesn't support it. Implements VESA suspend
558 * and powerdown modes on hardware that supports disabling hsync/vsync:
560 * Returns negative errno on error, or zero on success.
563 static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
565 struct s3c2410fb_info *fbi = info->par;
566 void __iomem *tpal_reg = fbi->io;
568 dprintk("blank(mode=%d, info=%p)\n", blank_mode, info);
570 tpal_reg += is_s3c2412(fbi) ? S3C2412_TPAL : S3C2410_TPAL;
572 if (blank_mode == FB_BLANK_POWERDOWN)
573 s3c2410fb_lcd_enable(fbi, 0);
575 s3c2410fb_lcd_enable(fbi, 1);
577 if (blank_mode == FB_BLANK_UNBLANK)
578 writel(0x0, tpal_reg);
580 dprintk("setting TPAL to output 0x000000\n");
581 writel(S3C2410_TPAL_EN, tpal_reg);
587 static int s3c2410fb_debug_show(struct device *dev,
588 struct device_attribute *attr, char *buf)
590 return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off");
593 static int s3c2410fb_debug_store(struct device *dev,
594 struct device_attribute *attr,
595 const char *buf, size_t len)
600 if (strncasecmp(buf, "on", 2) == 0 ||
601 strncasecmp(buf, "1", 1) == 0) {
603 dev_dbg(dev, "s3c2410fb: Debug On");
604 } else if (strncasecmp(buf, "off", 3) == 0 ||
605 strncasecmp(buf, "0", 1) == 0) {
607 dev_dbg(dev, "s3c2410fb: Debug Off");
615 static DEVICE_ATTR(debug, 0664, s3c2410fb_debug_show, s3c2410fb_debug_store);
617 static const struct fb_ops s3c2410fb_ops = {
618 .owner = THIS_MODULE,
619 .fb_check_var = s3c2410fb_check_var,
620 .fb_set_par = s3c2410fb_set_par,
621 .fb_blank = s3c2410fb_blank,
622 .fb_setcolreg = s3c2410fb_setcolreg,
623 .fb_fillrect = cfb_fillrect,
624 .fb_copyarea = cfb_copyarea,
625 .fb_imageblit = cfb_imageblit,
629 * s3c2410fb_map_video_memory():
630 * Allocates the DRAM memory for the frame buffer. This buffer is
631 * remapped into a non-cached, non-buffered, memory region to
632 * allow palette and pixel writes to occur without flushing the
633 * cache. Once this area is remapped, all virtual memory
634 * access to the video memory should occur at the new region.
636 static int s3c2410fb_map_video_memory(struct fb_info *info)
638 struct s3c2410fb_info *fbi = info->par;
640 unsigned map_size = PAGE_ALIGN(info->fix.smem_len);
642 dprintk("map_video_memory(fbi=%p) map_size %u\n", fbi, map_size);
644 info->screen_base = dma_alloc_wc(fbi->dev, map_size, &map_dma,
647 if (info->screen_base) {
648 /* prevent initial garbage on screen */
649 dprintk("map_video_memory: clear %p:%08x\n",
650 info->screen_base, map_size);
651 memset(info->screen_base, 0x00, map_size);
653 info->fix.smem_start = map_dma;
655 dprintk("map_video_memory: dma=%08lx cpu=%p size=%08x\n",
656 info->fix.smem_start, info->screen_base, map_size);
659 return info->screen_base ? 0 : -ENOMEM;
662 static inline void s3c2410fb_unmap_video_memory(struct fb_info *info)
664 struct s3c2410fb_info *fbi = info->par;
666 dma_free_wc(fbi->dev, PAGE_ALIGN(info->fix.smem_len),
667 info->screen_base, info->fix.smem_start);
670 static inline void modify_gpio(void __iomem *reg,
671 unsigned long set, unsigned long mask)
675 tmp = readl(reg) & ~mask;
676 writel(tmp | set, reg);
680 * s3c2410fb_init_registers - Initialise all LCD-related registers
682 static int s3c2410fb_init_registers(struct fb_info *info)
684 struct s3c2410fb_info *fbi = info->par;
685 struct s3c2410fb_mach_info *mach_info = dev_get_platdata(fbi->dev);
687 void __iomem *regs = fbi->io;
689 void __iomem *lpcsel;
691 if (is_s3c2412(fbi)) {
692 tpal = regs + S3C2412_TPAL;
693 lpcsel = regs + S3C2412_TCONSEL;
695 tpal = regs + S3C2410_TPAL;
696 lpcsel = regs + S3C2410_LPCSEL;
699 /* Initialise LCD with values from haret */
701 local_irq_save(flags);
703 /* modify the gpio(s) with interrupts set (bjd) */
705 modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask);
706 modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask);
707 modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask);
708 modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask);
710 local_irq_restore(flags);
712 dprintk("LPCSEL = 0x%08lx\n", mach_info->lpcsel);
713 writel(mach_info->lpcsel, lpcsel);
715 dprintk("replacing TPAL %08x\n", readl(tpal));
717 /* ensure temporary palette disabled */
723 static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
726 void __iomem *regs = fbi->io;
728 fbi->palette_ready = 0;
730 for (i = 0; i < 256; i++) {
731 unsigned long ent = fbi->palette_buffer[i];
732 if (ent == PALETTE_BUFF_CLEAR)
735 writel(ent, regs + S3C2410_TFTPAL(i));
737 /* it seems the only way to know exactly
738 * if the palette wrote ok, is to check
739 * to see if the value verifies ok
742 if (readw(regs + S3C2410_TFTPAL(i)) == ent)
743 fbi->palette_buffer[i] = PALETTE_BUFF_CLEAR;
745 fbi->palette_ready = 1; /* retry */
749 static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
751 struct s3c2410fb_info *fbi = dev_id;
752 void __iomem *irq_base = fbi->irq_base;
753 unsigned long lcdirq = readl(irq_base + S3C24XX_LCDINTPND);
755 if (lcdirq & S3C2410_LCDINT_FRSYNC) {
756 if (fbi->palette_ready)
757 s3c2410fb_write_palette(fbi);
759 writel(S3C2410_LCDINT_FRSYNC, irq_base + S3C24XX_LCDINTPND);
760 writel(S3C2410_LCDINT_FRSYNC, irq_base + S3C24XX_LCDSRCPND);
766 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
768 static int s3c2410fb_cpufreq_transition(struct notifier_block *nb,
769 unsigned long val, void *data)
771 struct s3c2410fb_info *info;
772 struct fb_info *fbinfo;
775 info = container_of(nb, struct s3c2410fb_info, freq_transition);
776 fbinfo = dev_get_drvdata(info->dev);
778 /* work out change, <0 for speed-up */
779 delta_f = info->clk_rate - clk_get_rate(info->clk);
781 if ((val == CPUFREQ_POSTCHANGE && delta_f > 0) ||
782 (val == CPUFREQ_PRECHANGE && delta_f < 0)) {
783 info->clk_rate = clk_get_rate(info->clk);
784 s3c2410fb_activate_var(fbinfo);
790 static inline int s3c2410fb_cpufreq_register(struct s3c2410fb_info *info)
792 info->freq_transition.notifier_call = s3c2410fb_cpufreq_transition;
794 return cpufreq_register_notifier(&info->freq_transition,
795 CPUFREQ_TRANSITION_NOTIFIER);
798 static inline void s3c2410fb_cpufreq_deregister(struct s3c2410fb_info *info)
800 cpufreq_unregister_notifier(&info->freq_transition,
801 CPUFREQ_TRANSITION_NOTIFIER);
805 static inline int s3c2410fb_cpufreq_register(struct s3c2410fb_info *info)
810 static inline void s3c2410fb_cpufreq_deregister(struct s3c2410fb_info *info)
816 static const char driver_name[] = "s3c2410fb";
818 static int s3c24xxfb_probe(struct platform_device *pdev,
819 enum s3c_drv_type drv_type)
821 struct s3c2410fb_info *info;
822 struct s3c2410fb_display *display;
823 struct fb_info *fbinfo;
824 struct s3c2410fb_mach_info *mach_info;
825 struct resource *res;
832 mach_info = dev_get_platdata(&pdev->dev);
833 if (mach_info == NULL) {
835 "no platform data for lcd, cannot attach\n");
839 if (mach_info->default_display >= mach_info->num_displays) {
840 dev_err(&pdev->dev, "default is %d but only %d displays\n",
841 mach_info->default_display, mach_info->num_displays);
845 display = mach_info->displays + mach_info->default_display;
847 irq = platform_get_irq(pdev, 0);
849 dev_err(&pdev->dev, "no irq for device\n");
853 fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), &pdev->dev);
857 platform_set_drvdata(pdev, fbinfo);
860 info->dev = &pdev->dev;
861 info->drv_type = drv_type;
863 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
865 dev_err(&pdev->dev, "failed to get memory registers\n");
870 size = resource_size(res);
871 info->mem = request_mem_region(res->start, size, pdev->name);
872 if (info->mem == NULL) {
873 dev_err(&pdev->dev, "failed to get memory region\n");
878 info->io = ioremap(res->start, size);
879 if (info->io == NULL) {
880 dev_err(&pdev->dev, "ioremap() of registers failed\n");
885 if (drv_type == DRV_S3C2412)
886 info->irq_base = info->io + S3C2412_LCDINTBASE;
888 info->irq_base = info->io + S3C2410_LCDINTBASE;
890 dprintk("devinit\n");
892 strcpy(fbinfo->fix.id, driver_name);
895 lcdcon1 = readl(info->io + S3C2410_LCDCON1);
896 writel(lcdcon1 & ~S3C2410_LCDCON1_ENVID, info->io + S3C2410_LCDCON1);
898 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
899 fbinfo->fix.type_aux = 0;
900 fbinfo->fix.xpanstep = 0;
901 fbinfo->fix.ypanstep = 0;
902 fbinfo->fix.ywrapstep = 0;
903 fbinfo->fix.accel = FB_ACCEL_NONE;
905 fbinfo->var.nonstd = 0;
906 fbinfo->var.activate = FB_ACTIVATE_NOW;
907 fbinfo->var.accel_flags = 0;
908 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
910 fbinfo->fbops = &s3c2410fb_ops;
911 fbinfo->flags = FBINFO_FLAG_DEFAULT;
912 fbinfo->pseudo_palette = &info->pseudo_pal;
914 for (i = 0; i < 256; i++)
915 info->palette_buffer[i] = PALETTE_BUFF_CLEAR;
917 ret = request_irq(irq, s3c2410fb_irq, 0, pdev->name, info);
919 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
924 info->clk = clk_get(NULL, "lcd");
925 if (IS_ERR(info->clk)) {
926 dev_err(&pdev->dev, "failed to get lcd clock source\n");
927 ret = PTR_ERR(info->clk);
931 clk_prepare_enable(info->clk);
932 dprintk("got and enabled clock\n");
934 usleep_range(1000, 1100);
936 info->clk_rate = clk_get_rate(info->clk);
938 /* find maximum required memory size for display */
939 for (i = 0; i < mach_info->num_displays; i++) {
940 unsigned long smem_len = mach_info->displays[i].xres;
942 smem_len *= mach_info->displays[i].yres;
943 smem_len *= mach_info->displays[i].bpp;
945 if (fbinfo->fix.smem_len < smem_len)
946 fbinfo->fix.smem_len = smem_len;
949 /* Initialize video memory */
950 ret = s3c2410fb_map_video_memory(fbinfo);
952 dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
957 dprintk("got video memory\n");
959 fbinfo->var.xres = display->xres;
960 fbinfo->var.yres = display->yres;
961 fbinfo->var.bits_per_pixel = display->bpp;
963 s3c2410fb_init_registers(fbinfo);
965 s3c2410fb_check_var(&fbinfo->var, fbinfo);
967 ret = s3c2410fb_cpufreq_register(info);
969 dev_err(&pdev->dev, "Failed to register cpufreq\n");
970 goto free_video_memory;
973 ret = register_framebuffer(fbinfo);
975 dev_err(&pdev->dev, "Failed to register framebuffer device: %d\n",
980 /* create device files */
981 ret = device_create_file(&pdev->dev, &dev_attr_debug);
983 dev_err(&pdev->dev, "failed to add debug attribute\n");
985 dev_info(&pdev->dev, "fb%d: %s frame buffer device\n",
986 fbinfo->node, fbinfo->fix.id);
991 s3c2410fb_cpufreq_deregister(info);
993 s3c2410fb_unmap_video_memory(fbinfo);
995 clk_disable_unprepare(info->clk);
1002 release_mem_region(res->start, size);
1004 framebuffer_release(fbinfo);
1008 static int s3c2410fb_probe(struct platform_device *pdev)
1010 return s3c24xxfb_probe(pdev, DRV_S3C2410);
1013 static int s3c2412fb_probe(struct platform_device *pdev)
1015 return s3c24xxfb_probe(pdev, DRV_S3C2412);
1022 static int s3c2410fb_remove(struct platform_device *pdev)
1024 struct fb_info *fbinfo = platform_get_drvdata(pdev);
1025 struct s3c2410fb_info *info = fbinfo->par;
1028 unregister_framebuffer(fbinfo);
1029 s3c2410fb_cpufreq_deregister(info);
1031 s3c2410fb_lcd_enable(info, 0);
1032 usleep_range(1000, 1100);
1034 s3c2410fb_unmap_video_memory(fbinfo);
1037 clk_disable_unprepare(info->clk);
1042 irq = platform_get_irq(pdev, 0);
1043 free_irq(irq, info);
1047 release_mem_region(info->mem->start, resource_size(info->mem));
1049 framebuffer_release(fbinfo);
1056 /* suspend and resume support for the lcd controller */
1057 static int s3c2410fb_suspend(struct platform_device *dev, pm_message_t state)
1059 struct fb_info *fbinfo = platform_get_drvdata(dev);
1060 struct s3c2410fb_info *info = fbinfo->par;
1062 s3c2410fb_lcd_enable(info, 0);
1064 /* sleep before disabling the clock, we need to ensure
1065 * the LCD DMA engine is not going to get back on the bus
1066 * before the clock goes off again (bjd) */
1068 usleep_range(1000, 1100);
1069 clk_disable_unprepare(info->clk);
1074 static int s3c2410fb_resume(struct platform_device *dev)
1076 struct fb_info *fbinfo = platform_get_drvdata(dev);
1077 struct s3c2410fb_info *info = fbinfo->par;
1079 clk_prepare_enable(info->clk);
1080 usleep_range(1000, 1100);
1082 s3c2410fb_init_registers(fbinfo);
1084 /* re-activate our display after resume */
1085 s3c2410fb_activate_var(fbinfo);
1086 s3c2410fb_blank(FB_BLANK_UNBLANK, fbinfo);
1092 #define s3c2410fb_suspend NULL
1093 #define s3c2410fb_resume NULL
1096 static struct platform_driver s3c2410fb_driver = {
1097 .probe = s3c2410fb_probe,
1098 .remove = s3c2410fb_remove,
1099 .suspend = s3c2410fb_suspend,
1100 .resume = s3c2410fb_resume,
1102 .name = "s3c2410-lcd",
1106 static struct platform_driver s3c2412fb_driver = {
1107 .probe = s3c2412fb_probe,
1108 .remove = s3c2410fb_remove,
1109 .suspend = s3c2410fb_suspend,
1110 .resume = s3c2410fb_resume,
1112 .name = "s3c2412-lcd",
1116 int __init s3c2410fb_init(void)
1118 int ret = platform_driver_register(&s3c2410fb_driver);
1121 ret = platform_driver_register(&s3c2412fb_driver);
1126 static void __exit s3c2410fb_cleanup(void)
1128 platform_driver_unregister(&s3c2410fb_driver);
1129 platform_driver_unregister(&s3c2412fb_driver);
1132 module_init(s3c2410fb_init);
1133 module_exit(s3c2410fb_cleanup);
1135 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
1136 MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
1137 MODULE_DESCRIPTION("Framebuffer driver for the s3c2410");
1138 MODULE_LICENSE("GPL");
1139 MODULE_ALIAS("platform:s3c2410-lcd");
1140 MODULE_ALIAS("platform:s3c2412-lcd");