1 /* linux/drivers/video/s3c-fb.c
3 * Copyright 2008 Openmoko Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * Samsung SoC Framebuffer driver
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/init.h>
20 #include <linux/gfp.h>
21 #include <linux/clk.h>
26 #include <mach/regs-fb.h>
29 /* This driver will export a number of framebuffer interfaces depending
30 * on the configuration passed in via the platform data. Each fb instance
31 * maps to a hardware window. Currently there is no support for runtime
32 * setting of the alpha-blending functions that each window has, so only
33 * window 0 is actually useful.
35 * Window 0 is treated specially, it is used for the basis of the LCD
36 * output timings and as the control for the output power-down state.
39 /* note, some of the functions that get called are derived from including
40 * <mach/regs-fb.h> as they are specific to the architecture that the code
44 #ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
46 #define writel(v, r) do { \
47 printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \
48 __raw_writel(v, r); } while(0)
49 #endif /* FB_S3C_DEBUG_REGWRITE */
54 * struct s3c_fb_win - per window private data for each framebuffer.
55 * @windata: The platform data supplied for the window configuration.
56 * @parent: The hardware that this window is part of.
57 * @fbinfo: Pointer pack to the framebuffer info for this window.
58 * @palette_buffer: Buffer/cache to hold palette entries.
59 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
60 * @index: The window number of this window.
61 * @palette: The bitfields for changing r/g/b into a hardware palette entry.
64 struct s3c_fb_pd_win *windata;
65 struct s3c_fb *parent;
66 struct fb_info *fbinfo;
67 struct s3c_fb_palette palette;
70 u32 pseudo_palette[16];
75 * struct s3c_fb - overall hardware state of the hardware
76 * @dev: The device that we bound to, for printing, etc.
77 * @regs_res: The resource we claimed for the IO registers.
78 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
79 * @regs: The mapped hardware registers.
80 * @enabled: A bitmask of enabled hardware windows.
81 * @pdata: The platform configuration data passed with the device.
82 * @windows: The hardware windows that have been claimed.
86 struct resource *regs_res;
90 unsigned char enabled;
92 struct s3c_fb_platdata *pdata;
93 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
97 * s3c_fb_win_has_palette() - determine if a mode has a palette
98 * @win: The window number being queried.
99 * @bpp: The number of bits per pixel to test.
101 * Work out if the given window supports palletised data at the specified bpp.
103 static int s3c_fb_win_has_palette(unsigned int win, unsigned int bpp)
105 return s3c_fb_win_pal_size(win) <= (1 << bpp);
109 * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
110 * @var: The screen information to verify.
111 * @info: The framebuffer device.
113 * Framebuffer layer call to verify the given information and allow us to
114 * update various information depending on the hardware capabilities.
116 static int s3c_fb_check_var(struct fb_var_screeninfo *var,
117 struct fb_info *info)
119 struct s3c_fb_win *win = info->par;
120 struct s3c_fb_pd_win *windata = win->windata;
121 struct s3c_fb *sfb = win->parent;
123 dev_dbg(sfb->dev, "checking parameters\n");
125 var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres);
126 var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres);
128 if (!s3c_fb_validate_win_bpp(win->index, var->bits_per_pixel)) {
129 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
130 win->index, var->bits_per_pixel);
134 /* always ensure these are zero, for drop through cases below */
135 var->transp.offset = 0;
136 var->transp.length = 0;
138 switch (var->bits_per_pixel) {
143 if (!s3c_fb_win_has_palette(win->index, var->bits_per_pixel)) {
144 /* non palletised, A:1,R:2,G:3,B:2 mode */
146 var->green.offset = 2;
147 var->blue.offset = 0;
149 var->green.length = 3;
150 var->blue.length = 2;
151 var->transp.offset = 7;
152 var->transp.length = 1;
155 var->red.length = var->bits_per_pixel;
156 var->green = var->red;
157 var->blue = var->red;
162 /* 666 with one bit alpha/transparency */
163 var->transp.offset = 18;
164 var->transp.length = 1;
166 var->bits_per_pixel = 32;
169 var->red.offset = 12;
170 var->green.offset = 6;
171 var->blue.offset = 0;
173 var->green.length = 6;
174 var->blue.length = 6;
178 /* 16 bpp, 565 format */
179 var->red.offset = 11;
180 var->green.offset = 5;
181 var->blue.offset = 0;
183 var->green.length = 6;
184 var->blue.length = 5;
189 var->transp.length = var->bits_per_pixel - 24;
190 var->transp.offset = 24;
193 /* our 24bpp is unpacked, so 32bpp */
194 var->bits_per_pixel = 32;
196 var->red.offset = 16;
198 var->green.offset = 8;
199 var->green.length = 8;
200 var->blue.offset = 0;
201 var->blue.length = 8;
205 dev_err(sfb->dev, "invalid bpp\n");
208 dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
213 * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
214 * @sfb: The hardware state.
215 * @pixclock: The pixel clock wanted, in picoseconds.
217 * Given the specified pixel clock, work out the necessary divider to get
218 * close to the output frequency.
220 static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
222 unsigned long clk = clk_get_rate(sfb->bus_clk);
223 unsigned long long tmp;
226 tmp = (unsigned long long)clk;
229 do_div(tmp, 1000000000UL);
230 result = (unsigned int)tmp / 1000;
232 dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
233 pixclk, clk, result, clk / result);
239 * s3c_fb_align_word() - align pixel count to word boundary
240 * @bpp: The number of bits per pixel
241 * @pix: The value to be aligned.
243 * Align the given pixel count so that it will start on an 32bit word
246 static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
253 pix_per_word = (8 * 32) / bpp;
254 return ALIGN(pix, pix_per_word);
258 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
259 * @info: The framebuffer to change.
261 * Framebuffer layer request to set a new mode for the specified framebuffer
263 static int s3c_fb_set_par(struct fb_info *info)
265 struct fb_var_screeninfo *var = &info->var;
266 struct s3c_fb_win *win = info->par;
267 struct s3c_fb *sfb = win->parent;
268 void __iomem *regs = sfb->regs;
269 int win_no = win->index;
274 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
276 switch (var->bits_per_pixel) {
281 info->fix.visual = FB_VISUAL_TRUECOLOR;
284 if (s3c_fb_win_has_palette(win_no, 8))
285 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
287 info->fix.visual = FB_VISUAL_TRUECOLOR;
290 info->fix.visual = FB_VISUAL_MONO01;
293 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
297 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
299 /* disable the window whilst we update it */
300 writel(0, regs + WINCON(win_no));
302 /* use window 0 as the basis for the lcd output timings */
305 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
307 data = sfb->pdata->vidcon0;
308 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
311 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
313 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
315 /* write the timing data to the panel */
317 data |= VIDCON0_ENVID | VIDCON0_ENVID_F;
318 writel(data, regs + VIDCON0);
320 data = VIDTCON0_VBPD(var->upper_margin - 1) |
321 VIDTCON0_VFPD(var->lower_margin - 1) |
322 VIDTCON0_VSPW(var->vsync_len - 1);
324 writel(data, regs + VIDTCON0);
326 data = VIDTCON1_HBPD(var->left_margin - 1) |
327 VIDTCON1_HFPD(var->right_margin - 1) |
328 VIDTCON1_HSPW(var->hsync_len - 1);
330 writel(data, regs + VIDTCON1);
332 data = VIDTCON2_LINEVAL(var->yres - 1) |
333 VIDTCON2_HOZVAL(var->xres - 1);
334 writel(data, regs + VIDTCON2);
337 /* write the buffer address */
339 writel(info->fix.smem_start, regs + VIDW_BUF_START(win_no));
341 data = info->fix.smem_start + info->fix.line_length * var->yres;
342 writel(data, regs + VIDW_BUF_END(win_no));
344 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
345 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
346 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
347 writel(data, regs + VIDW_BUF_SIZE(win_no));
349 /* write 'OSD' registers to control position of framebuffer */
351 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
352 writel(data, regs + VIDOSD_A(win_no));
354 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
356 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
358 writel(data, regs + VIDOSD_B(win_no));
360 data = var->xres * var->yres;
361 if (s3c_fb_has_osd_d(win_no)) {
362 writel(data, regs + VIDOSD_D(win_no));
363 writel(0, regs + VIDOSD_C(win_no));
365 writel(data, regs + VIDOSD_C(win_no));
367 data = WINCONx_ENWIN;
369 /* note, since we have to round up the bits-per-pixel, we end up
370 * relying on the bitfield information for r/g/b/a to work out
371 * exactly which mode of operation is intended. */
373 switch (var->bits_per_pixel) {
375 data |= WINCON0_BPPMODE_1BPP;
376 data |= WINCONx_BITSWP;
377 data |= WINCONx_BURSTLEN_4WORD;
380 data |= WINCON0_BPPMODE_2BPP;
381 data |= WINCONx_BITSWP;
382 data |= WINCONx_BURSTLEN_8WORD;
385 data |= WINCON0_BPPMODE_4BPP;
386 data |= WINCONx_BITSWP;
387 data |= WINCONx_BURSTLEN_8WORD;
390 if (var->transp.length != 0)
391 data |= WINCON1_BPPMODE_8BPP_1232;
393 data |= WINCON0_BPPMODE_8BPP_PALETTE;
394 data |= WINCONx_BURSTLEN_8WORD;
395 data |= WINCONx_BYTSWP;
398 if (var->transp.length != 0)
399 data |= WINCON1_BPPMODE_16BPP_A1555;
401 data |= WINCON0_BPPMODE_16BPP_565;
402 data |= WINCONx_HAWSWP;
403 data |= WINCONx_BURSTLEN_16WORD;
407 if (var->red.length == 6) {
408 if (var->transp.length != 0)
409 data |= WINCON1_BPPMODE_19BPP_A1666;
411 data |= WINCON1_BPPMODE_18BPP_666;
412 } else if (var->transp.length != 0)
413 data |= WINCON1_BPPMODE_25BPP_A1888;
415 data |= WINCON0_BPPMODE_24BPP_888;
417 data |= WINCONx_BURSTLEN_16WORD;
421 writel(data, regs + WINCON(win_no));
422 writel(0x0, regs + WINxMAP(win_no));
428 * s3c_fb_update_palette() - set or schedule a palette update.
429 * @sfb: The hardware information.
430 * @win: The window being updated.
431 * @reg: The palette index being changed.
432 * @value: The computed palette value.
434 * Change the value of a palette register, either by directly writing to
435 * the palette (this requires the palette RAM to be disconnected from the
436 * hardware whilst this is in progress) or schedule the update for later.
438 * At the moment, since we have no VSYNC interrupt support, we simply set
439 * the palette entry directly.
441 static void s3c_fb_update_palette(struct s3c_fb *sfb,
442 struct s3c_fb_win *win,
446 void __iomem *palreg;
449 palreg = sfb->regs + s3c_fb_pal_reg(win->index, reg);
451 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
452 __func__, win->index, reg, palreg, value);
454 win->palette_buffer[reg] = value;
456 palcon = readl(sfb->regs + WPALCON);
457 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
459 if (s3c_fb_pal_is16(win->index))
460 writew(value, palreg);
462 writel(value, palreg);
464 writel(palcon, sfb->regs + WPALCON);
467 static inline unsigned int chan_to_field(unsigned int chan,
468 struct fb_bitfield *bf)
471 chan >>= 16 - bf->length;
472 return chan << bf->offset;
476 * s3c_fb_setcolreg() - framebuffer layer request to change palette.
477 * @regno: The palette index to change.
478 * @red: The red field for the palette data.
479 * @green: The green field for the palette data.
480 * @blue: The blue field for the palette data.
481 * @trans: The transparency (alpha) field for the palette data.
482 * @info: The framebuffer being changed.
484 static int s3c_fb_setcolreg(unsigned regno,
485 unsigned red, unsigned green, unsigned blue,
486 unsigned transp, struct fb_info *info)
488 struct s3c_fb_win *win = info->par;
489 struct s3c_fb *sfb = win->parent;
492 dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
493 __func__, win->index, regno, red, green, blue);
495 switch (info->fix.visual) {
496 case FB_VISUAL_TRUECOLOR:
497 /* true-colour, use pseudo-palette */
500 u32 *pal = info->pseudo_palette;
502 val = chan_to_field(red, &info->var.red);
503 val |= chan_to_field(green, &info->var.green);
504 val |= chan_to_field(blue, &info->var.blue);
510 case FB_VISUAL_PSEUDOCOLOR:
511 if (regno < s3c_fb_win_pal_size(win->index)) {
512 val = chan_to_field(red, &win->palette.r);
513 val |= chan_to_field(green, &win->palette.g);
514 val |= chan_to_field(blue, &win->palette.b);
516 s3c_fb_update_palette(sfb, win, regno, val);
522 return 1; /* unknown type */
529 * s3c_fb_enable() - Set the state of the main LCD output
530 * @sfb: The main framebuffer state.
531 * @enable: The state to set.
533 static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
535 u32 vidcon0 = readl(sfb->regs + VIDCON0);
538 vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
540 /* see the note in the framebuffer datasheet about
541 * why you cannot take both of these bits down at the
544 if (!(vidcon0 & VIDCON0_ENVID))
547 vidcon0 |= VIDCON0_ENVID;
548 vidcon0 &= ~VIDCON0_ENVID_F;
551 writel(vidcon0, sfb->regs + VIDCON0);
555 * s3c_fb_blank() - blank or unblank the given window
556 * @blank_mode: The blank state from FB_BLANK_*
557 * @info: The framebuffer to blank.
559 * Framebuffer layer request to change the power state.
561 static int s3c_fb_blank(int blank_mode, struct fb_info *info)
563 struct s3c_fb_win *win = info->par;
564 struct s3c_fb *sfb = win->parent;
565 unsigned int index = win->index;
568 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
570 wincon = readl(sfb->regs + WINCON(index));
572 switch (blank_mode) {
573 case FB_BLANK_POWERDOWN:
574 wincon &= ~WINCONx_ENWIN;
575 sfb->enabled &= ~(1 << index);
576 /* fall through to FB_BLANK_NORMAL */
578 case FB_BLANK_NORMAL:
579 /* disable the DMA and display 0x0 (black) */
580 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
581 sfb->regs + WINxMAP(index));
584 case FB_BLANK_UNBLANK:
585 writel(0x0, sfb->regs + WINxMAP(index));
586 wincon |= WINCONx_ENWIN;
587 sfb->enabled |= (1 << index);
590 case FB_BLANK_VSYNC_SUSPEND:
591 case FB_BLANK_HSYNC_SUSPEND:
596 writel(wincon, sfb->regs + WINCON(index));
598 /* Check the enabled state to see if we need to be running the
599 * main LCD interface, as if there are no active windows then
600 * it is highly likely that we also do not need to output
604 /* We could do something like the following code, but the current
605 * system of using framebuffer events means that we cannot make
606 * the distinction between just window 0 being inactive and all
607 * the windows being down.
609 * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
612 /* we're stuck with this until we can do something about overriding
613 * the power control using the blanking event for a single fb.
616 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
621 static struct fb_ops s3c_fb_ops = {
622 .owner = THIS_MODULE,
623 .fb_check_var = s3c_fb_check_var,
624 .fb_set_par = s3c_fb_set_par,
625 .fb_blank = s3c_fb_blank,
626 .fb_setcolreg = s3c_fb_setcolreg,
627 .fb_fillrect = cfb_fillrect,
628 .fb_copyarea = cfb_copyarea,
629 .fb_imageblit = cfb_imageblit,
633 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
634 * @sfb: The base resources for the hardware.
635 * @win: The window to initialise memory for.
637 * Allocate memory for the given framebuffer.
639 static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
640 struct s3c_fb_win *win)
642 struct s3c_fb_pd_win *windata = win->windata;
643 unsigned int real_size, virt_size, size;
644 struct fb_info *fbi = win->fbinfo;
647 dev_dbg(sfb->dev, "allocating memory for display\n");
649 real_size = windata->win_mode.xres * windata->win_mode.yres;
650 virt_size = windata->virtual_x * windata->virtual_y;
652 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
653 real_size, windata->win_mode.xres, windata->win_mode.yres,
654 virt_size, windata->virtual_x, windata->virtual_y);
656 size = (real_size > virt_size) ? real_size : virt_size;
657 size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
660 fbi->fix.smem_len = size;
661 size = PAGE_ALIGN(size);
663 dev_dbg(sfb->dev, "want %u bytes for window\n", size);
665 fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
666 &map_dma, GFP_KERNEL);
667 if (!fbi->screen_base)
670 dev_dbg(sfb->dev, "mapped %x to %p\n",
671 (unsigned int)map_dma, fbi->screen_base);
673 memset(fbi->screen_base, 0x0, size);
674 fbi->fix.smem_start = map_dma;
680 * s3c_fb_free_memory() - free the display memory for the given window
681 * @sfb: The base resources for the hardware.
682 * @win: The window to free the display memory for.
684 * Free the display memory allocated by s3c_fb_alloc_memory().
686 static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
688 struct fb_info *fbi = win->fbinfo;
690 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
691 fbi->screen_base, fbi->fix.smem_start);
695 * s3c_fb_release_win() - release resources for a framebuffer window.
696 * @win: The window to cleanup the resources for.
698 * Release the resources that where claimed for the hardware window,
699 * such as the framebuffer instance and any memory claimed for it.
701 static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
703 fb_dealloc_cmap(&win->fbinfo->cmap);
704 unregister_framebuffer(win->fbinfo);
705 s3c_fb_free_memory(sfb, win);
709 * s3c_fb_probe_win() - register an hardware window
710 * @sfb: The base resources for the hardware
711 * @res: Pointer to where to place the resultant window.
713 * Allocate and do the basic initialisation for one of the hardware's graphics
716 static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
717 struct s3c_fb_win **res)
719 struct fb_var_screeninfo *var;
720 struct fb_videomode *initmode;
721 struct s3c_fb_pd_win *windata;
722 struct s3c_fb_win *win;
723 struct fb_info *fbinfo;
727 dev_dbg(sfb->dev, "probing window %d\n", win_no);
729 palette_size = s3c_fb_win_pal_size(win_no);
731 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
732 palette_size * sizeof(u32), sfb->dev);
734 dev_err(sfb->dev, "failed to allocate framebuffer\n");
738 windata = sfb->pdata->win[win_no];
739 initmode = &windata->win_mode;
741 WARN_ON(windata->max_bpp == 0);
742 WARN_ON(windata->win_mode.xres == 0);
743 WARN_ON(windata->win_mode.yres == 0);
747 win->fbinfo = fbinfo;
749 win->windata = windata;
751 win->palette_buffer = (u32 *)(win + 1);
753 ret = s3c_fb_alloc_memory(sfb, win);
755 dev_err(sfb->dev, "failed to allocate display memory\n");
756 goto err_framebuffer;
759 /* setup the r/b/g positions for the window's palette */
760 s3c_fb_init_palette(win_no, &win->palette);
762 /* setup the initial video mode from the window */
763 fb_videomode_to_var(&fbinfo->var, initmode);
765 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
766 fbinfo->fix.accel = FB_ACCEL_NONE;
767 fbinfo->var.activate = FB_ACTIVATE_NOW;
768 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
769 fbinfo->var.bits_per_pixel = windata->default_bpp;
770 fbinfo->fbops = &s3c_fb_ops;
771 fbinfo->flags = FBINFO_FLAG_DEFAULT;
772 fbinfo->pseudo_palette = &win->pseudo_palette;
774 /* prepare to actually start the framebuffer */
776 ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
778 dev_err(sfb->dev, "check_var failed on initial video params\n");
782 /* create initial colour map */
784 ret = fb_alloc_cmap(&fbinfo->cmap, s3c_fb_win_pal_size(win_no), 1);
786 fb_set_cmap(&fbinfo->cmap, fbinfo);
788 dev_err(sfb->dev, "failed to allocate fb cmap\n");
790 s3c_fb_set_par(fbinfo);
792 dev_dbg(sfb->dev, "about to register framebuffer\n");
794 /* run the check_var and set_par on our configuration. */
796 ret = register_framebuffer(fbinfo);
798 dev_err(sfb->dev, "failed to register framebuffer\n");
803 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
808 s3c_fb_free_memory(sfb, win);
811 unregister_framebuffer(fbinfo);
816 * s3c_fb_clear_win() - clear hardware window registers.
817 * @sfb: The base resources for the hardware.
818 * @win: The window to process.
820 * Reset the specific window registers to a known state.
822 static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
824 void __iomem *regs = sfb->regs;
826 writel(0, regs + WINCON(win));
827 writel(0xffffff, regs + WxKEYCONy(win, 0));
828 writel(0xffffff, regs + WxKEYCONy(win, 1));
830 writel(0, regs + VIDOSD_A(win));
831 writel(0, regs + VIDOSD_B(win));
832 writel(0, regs + VIDOSD_C(win));
835 static int __devinit s3c_fb_probe(struct platform_device *pdev)
837 struct device *dev = &pdev->dev;
838 struct s3c_fb_platdata *pd;
840 struct resource *res;
844 pd = pdev->dev.platform_data;
846 dev_err(dev, "no platform data specified\n");
850 sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL);
852 dev_err(dev, "no memory for framebuffers\n");
859 sfb->bus_clk = clk_get(dev, "lcd");
860 if (IS_ERR(sfb->bus_clk)) {
861 dev_err(dev, "failed to get bus clock\n");
865 clk_enable(sfb->bus_clk);
867 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
869 dev_err(dev, "failed to find registers\n");
874 sfb->regs_res = request_mem_region(res->start, resource_size(res),
876 if (!sfb->regs_res) {
877 dev_err(dev, "failed to claim register region\n");
882 sfb->regs = ioremap(res->start, resource_size(res));
884 dev_err(dev, "failed to map registers\n");
889 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
891 /* setup gpio and output polarity controls */
895 writel(pd->vidcon1, sfb->regs + VIDCON1);
897 /* zero all windows before we do anything */
899 for (win = 0; win < S3C_FB_MAX_WIN; win++)
900 s3c_fb_clear_win(sfb, win);
902 /* we have the register setup, start allocating framebuffers */
904 for (win = 0; win < S3C_FB_MAX_WIN; win++) {
908 ret = s3c_fb_probe_win(sfb, win, &sfb->windows[win]);
910 dev_err(dev, "failed to create window %d\n", win);
911 for (; win >= 0; win--)
912 s3c_fb_release_win(sfb, sfb->windows[win]);
917 platform_set_drvdata(pdev, sfb);
925 release_resource(sfb->regs_res);
926 kfree(sfb->regs_res);
929 clk_disable(sfb->bus_clk);
930 clk_put(sfb->bus_clk);
938 * s3c_fb_remove() - Cleanup on module finalisation
939 * @pdev: The platform device we are bound to.
941 * Shutdown and then release all the resources that the driver allocated
944 static int __devexit s3c_fb_remove(struct platform_device *pdev)
946 struct s3c_fb *sfb = platform_get_drvdata(pdev);
949 for (win = 0; win <= S3C_FB_MAX_WIN; win++)
950 if (sfb->windows[win])
951 s3c_fb_release_win(sfb, sfb->windows[win]);
955 clk_disable(sfb->bus_clk);
956 clk_put(sfb->bus_clk);
958 release_resource(sfb->regs_res);
959 kfree(sfb->regs_res);
967 static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state)
969 struct s3c_fb *sfb = platform_get_drvdata(pdev);
970 struct s3c_fb_win *win;
973 for (win_no = S3C_FB_MAX_WIN; win_no >= 0; win_no--) {
974 win = sfb->windows[win_no];
978 /* use the blank function to push into power-down */
979 s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
982 clk_disable(sfb->bus_clk);
986 static int s3c_fb_resume(struct platform_device *pdev)
988 struct s3c_fb *sfb = platform_get_drvdata(pdev);
989 struct s3c_fb_platdata *pd = sfb->pdata;
990 struct s3c_fb_win *win;
993 clk_enable(sfb->bus_clk);
995 /* setup registers */
996 writel(pd->vidcon1, sfb->regs + VIDCON1);
998 /* zero all windows before we do anything */
999 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++)
1000 s3c_fb_clear_win(sfb, win_no);
1002 /* restore framebuffers */
1003 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1004 win = sfb->windows[win_no];
1008 dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
1009 s3c_fb_set_par(win->fbinfo);
1015 #define s3c_fb_suspend NULL
1016 #define s3c_fb_resume NULL
1019 static struct platform_driver s3c_fb_driver = {
1020 .probe = s3c_fb_probe,
1021 .remove = s3c_fb_remove,
1022 .suspend = s3c_fb_suspend,
1023 .resume = s3c_fb_resume,
1026 .owner = THIS_MODULE,
1030 static int __init s3c_fb_init(void)
1032 return platform_driver_register(&s3c_fb_driver);
1035 static void __exit s3c_fb_cleanup(void)
1037 platform_driver_unregister(&s3c_fb_driver);
1040 module_init(s3c_fb_init);
1041 module_exit(s3c_fb_cleanup);
1043 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1044 MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
1045 MODULE_LICENSE("GPL");
1046 MODULE_ALIAS("platform:s3c-fb");