blob: 389189a9e7759513f7a4a22b4bfa76688b33e0d8 [file] [log] [blame]
Ben Dooksec549a02009-03-31 15:25:39 -07001/* linux/drivers/video/s3c-fb.c
2 *
3 * Copyright 2008 Openmoko Inc.
Ben Dooks50a55032010-08-10 18:02:33 -07004 * Copyright 2008-2010 Simtec Electronics
Ben Dooksec549a02009-03-31 15:25:39 -07005 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
7 *
8 * Samsung SoC Framebuffer driver
9 *
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
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070012 * published by the Free Software FoundatIon.
Ben Dooksec549a02009-03-31 15:25:39 -070013*/
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Ben Dooksec549a02009-03-31 15:25:39 -070020#include <linux/init.h>
Ben Dooksec549a02009-03-31 15:25:39 -070021#include <linux/clk.h>
22#include <linux/fb.h>
23#include <linux/io.h>
Pawel Osciakefdc8462010-08-10 18:02:38 -070024#include <linux/uaccess.h>
25#include <linux/interrupt.h>
Jingoo Han49592122010-12-17 16:45:46 +090026#include <linux/pm_runtime.h>
Ben Dooksec549a02009-03-31 15:25:39 -070027
28#include <mach/map.h>
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070029#include <plat/regs-fb-v4.h>
Ben Dooksec549a02009-03-31 15:25:39 -070030#include <plat/fb.h>
31
32/* This driver will export a number of framebuffer interfaces depending
33 * on the configuration passed in via the platform data. Each fb instance
34 * maps to a hardware window. Currently there is no support for runtime
35 * setting of the alpha-blending functions that each window has, so only
36 * window 0 is actually useful.
37 *
38 * Window 0 is treated specially, it is used for the basis of the LCD
39 * output timings and as the control for the output power-down state.
40*/
41
Ben Dooks50a55032010-08-10 18:02:33 -070042/* note, the previous use of <mach/regs-fb.h> to get platform specific data
43 * has been replaced by using the platform device name to pick the correct
44 * configuration data for the system.
Ben Dooksec549a02009-03-31 15:25:39 -070045*/
46
47#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
48#undef writel
49#define writel(v, r) do { \
50 printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \
Jingoo Han05e52b42012-01-26 19:38:45 +090051 __raw_writel(v, r); \
52} while (0)
Ben Dooksec549a02009-03-31 15:25:39 -070053#endif /* FB_S3C_DEBUG_REGWRITE */
54
Pawel Osciakefdc8462010-08-10 18:02:38 -070055/* irq_flags bits */
56#define S3C_FB_VSYNC_IRQ_EN 0
57
58#define VSYNC_TIMEOUT_MSEC 50
59
Ben Dooksec549a02009-03-31 15:25:39 -070060struct s3c_fb;
61
Ben Dooks50a55032010-08-10 18:02:33 -070062#define VALID_BPP(x) (1 << ((x) - 1))
63
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070064#define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
65#define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
66#define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
67#define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
68#define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
69
Ben Dooks50a55032010-08-10 18:02:33 -070070/**
71 * struct s3c_fb_variant - fb variant information
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070072 * @is_2443: Set if S3C2443/S3C2416 style hardware.
Ben Dooks50a55032010-08-10 18:02:33 -070073 * @nr_windows: The number of windows.
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070074 * @vidtcon: The base for the VIDTCONx registers
75 * @wincon: The base for the WINxCON registers.
76 * @winmap: The base for the WINxMAP registers.
77 * @keycon: The abse for the WxKEYCON registers.
78 * @buf_start: Offset of buffer start registers.
79 * @buf_size: Offset of buffer size registers.
80 * @buf_end: Offset of buffer end registers.
81 * @osd: The base for the OSD registers.
Ben Dooks50a55032010-08-10 18:02:33 -070082 * @palette: Address of palette memory, or 0 if none.
Pawel Osciak067b2262010-08-10 18:02:38 -070083 * @has_prtcon: Set if has PRTCON register.
Pawel Osciakf5ec5462010-08-10 18:02:40 -070084 * @has_shadowcon: Set if has SHADOWCON register.
Jingoo Hanb5480ed2011-08-22 12:16:04 +090085 * @has_clksel: Set if VIDCON0 register has CLKSEL bit.
Ben Dooks50a55032010-08-10 18:02:33 -070086 */
87struct s3c_fb_variant {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070088 unsigned int is_2443:1;
Ben Dooks50a55032010-08-10 18:02:33 -070089 unsigned short nr_windows;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070090 unsigned short vidtcon;
91 unsigned short wincon;
92 unsigned short winmap;
93 unsigned short keycon;
94 unsigned short buf_start;
95 unsigned short buf_end;
96 unsigned short buf_size;
97 unsigned short osd;
98 unsigned short osd_stride;
Ben Dooks50a55032010-08-10 18:02:33 -070099 unsigned short palette[S3C_FB_MAX_WIN];
Pawel Osciak067b2262010-08-10 18:02:38 -0700100
101 unsigned int has_prtcon:1;
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700102 unsigned int has_shadowcon:1;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900103 unsigned int has_clksel:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700104};
105
106/**
107 * struct s3c_fb_win_variant
108 * @has_osd_c: Set if has OSD C register.
109 * @has_osd_d: Set if has OSD D register.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700110 * @has_osd_alpha: Set if can change alpha transparency for a window.
Ben Dooks50a55032010-08-10 18:02:33 -0700111 * @palette_sz: Size of palette in entries.
112 * @palette_16bpp: Set if palette is 16bits wide.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700113 * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
114 * register is located at the given offset from OSD_BASE.
Ben Dooks50a55032010-08-10 18:02:33 -0700115 * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
116 *
117 * valid_bpp bit x is set if (x+1)BPP is supported.
118 */
119struct s3c_fb_win_variant {
120 unsigned int has_osd_c:1;
121 unsigned int has_osd_d:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700122 unsigned int has_osd_alpha:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700123 unsigned int palette_16bpp:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700124 unsigned short osd_size_off;
Ben Dooks50a55032010-08-10 18:02:33 -0700125 unsigned short palette_sz;
126 u32 valid_bpp;
127};
128
129/**
130 * struct s3c_fb_driverdata - per-device type driver data for init time.
131 * @variant: The variant information for this driver.
132 * @win: The window information for each window.
133 */
134struct s3c_fb_driverdata {
135 struct s3c_fb_variant variant;
136 struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
137};
138
Ben Dooksec549a02009-03-31 15:25:39 -0700139/**
Ben Dooksbc2da1b2010-08-10 18:02:34 -0700140 * struct s3c_fb_palette - palette information
141 * @r: Red bitfield.
142 * @g: Green bitfield.
143 * @b: Blue bitfield.
144 * @a: Alpha bitfield.
145 */
146struct s3c_fb_palette {
147 struct fb_bitfield r;
148 struct fb_bitfield g;
149 struct fb_bitfield b;
150 struct fb_bitfield a;
151};
152
153/**
Ben Dooksec549a02009-03-31 15:25:39 -0700154 * struct s3c_fb_win - per window private data for each framebuffer.
155 * @windata: The platform data supplied for the window configuration.
156 * @parent: The hardware that this window is part of.
157 * @fbinfo: Pointer pack to the framebuffer info for this window.
Ben Dooks50a55032010-08-10 18:02:33 -0700158 * @varint: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -0700159 * @palette_buffer: Buffer/cache to hold palette entries.
160 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
161 * @index: The window number of this window.
162 * @palette: The bitfields for changing r/g/b into a hardware palette entry.
163 */
164struct s3c_fb_win {
165 struct s3c_fb_pd_win *windata;
166 struct s3c_fb *parent;
167 struct fb_info *fbinfo;
168 struct s3c_fb_palette palette;
Ben Dooks50a55032010-08-10 18:02:33 -0700169 struct s3c_fb_win_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700170
171 u32 *palette_buffer;
172 u32 pseudo_palette[16];
173 unsigned int index;
174};
175
176/**
Pawel Osciakefdc8462010-08-10 18:02:38 -0700177 * struct s3c_fb_vsync - vsync information
178 * @wait: a queue for processes waiting for vsync
179 * @count: vsync interrupt count
180 */
181struct s3c_fb_vsync {
182 wait_queue_head_t wait;
183 unsigned int count;
184};
185
186/**
Ben Dooksec549a02009-03-31 15:25:39 -0700187 * struct s3c_fb - overall hardware state of the hardware
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000188 * @slock: The spinlock protection for this data sturcture.
Ben Dooksec549a02009-03-31 15:25:39 -0700189 * @dev: The device that we bound to, for printing, etc.
Ben Dooksec549a02009-03-31 15:25:39 -0700190 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900191 * @lcd_clk: The clk (sclk) feeding pixclk.
Ben Dooksec549a02009-03-31 15:25:39 -0700192 * @regs: The mapped hardware registers.
Ben Dooks50a55032010-08-10 18:02:33 -0700193 * @variant: Variant information for this hardware.
Ben Dooksec549a02009-03-31 15:25:39 -0700194 * @enabled: A bitmask of enabled hardware windows.
Mark Brownf4f51472011-12-27 14:16:10 +0000195 * @output_on: Flag if the physical output is enabled.
Ben Dooksec549a02009-03-31 15:25:39 -0700196 * @pdata: The platform configuration data passed with the device.
197 * @windows: The hardware windows that have been claimed.
Pawel Osciakefdc8462010-08-10 18:02:38 -0700198 * @irq_no: IRQ line number
199 * @irq_flags: irq flags
200 * @vsync_info: VSYNC-related information (count, queues...)
Ben Dooksec549a02009-03-31 15:25:39 -0700201 */
202struct s3c_fb {
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000203 spinlock_t slock;
Ben Dooksec549a02009-03-31 15:25:39 -0700204 struct device *dev;
Ben Dooksec549a02009-03-31 15:25:39 -0700205 struct clk *bus_clk;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900206 struct clk *lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -0700207 void __iomem *regs;
Ben Dooks50a55032010-08-10 18:02:33 -0700208 struct s3c_fb_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700209
210 unsigned char enabled;
Mark Brownf4f51472011-12-27 14:16:10 +0000211 bool output_on;
Ben Dooksec549a02009-03-31 15:25:39 -0700212
213 struct s3c_fb_platdata *pdata;
214 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
Pawel Osciakefdc8462010-08-10 18:02:38 -0700215
216 int irq_no;
217 unsigned long irq_flags;
218 struct s3c_fb_vsync vsync_info;
Ben Dooksec549a02009-03-31 15:25:39 -0700219};
220
221/**
Ben Dooks50a55032010-08-10 18:02:33 -0700222 * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
223 * @win: The device window.
224 * @bpp: The bit depth.
Ben Dooksec549a02009-03-31 15:25:39 -0700225 */
Ben Dooks50a55032010-08-10 18:02:33 -0700226static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
Ben Dooksec549a02009-03-31 15:25:39 -0700227{
Ben Dooks50a55032010-08-10 18:02:33 -0700228 return win->variant.valid_bpp & VALID_BPP(bpp);
Ben Dooksec549a02009-03-31 15:25:39 -0700229}
230
231/**
232 * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
233 * @var: The screen information to verify.
234 * @info: The framebuffer device.
235 *
236 * Framebuffer layer call to verify the given information and allow us to
237 * update various information depending on the hardware capabilities.
238 */
239static int s3c_fb_check_var(struct fb_var_screeninfo *var,
240 struct fb_info *info)
241{
242 struct s3c_fb_win *win = info->par;
Ben Dooksec549a02009-03-31 15:25:39 -0700243 struct s3c_fb *sfb = win->parent;
244
245 dev_dbg(sfb->dev, "checking parameters\n");
246
Jingoo Han13e6af82011-06-09 04:26:38 +0000247 var->xres_virtual = max(var->xres_virtual, var->xres);
248 var->yres_virtual = max(var->yres_virtual, var->yres);
Ben Dooksec549a02009-03-31 15:25:39 -0700249
Ben Dooks50a55032010-08-10 18:02:33 -0700250 if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
Ben Dooksec549a02009-03-31 15:25:39 -0700251 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
252 win->index, var->bits_per_pixel);
253 return -EINVAL;
254 }
255
256 /* always ensure these are zero, for drop through cases below */
257 var->transp.offset = 0;
258 var->transp.length = 0;
259
260 switch (var->bits_per_pixel) {
261 case 1:
262 case 2:
263 case 4:
264 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700265 if (sfb->variant.palette[win->index] != 0) {
Ben Dooksec549a02009-03-31 15:25:39 -0700266 /* non palletised, A:1,R:2,G:3,B:2 mode */
267 var->red.offset = 4;
268 var->green.offset = 2;
269 var->blue.offset = 0;
270 var->red.length = 5;
271 var->green.length = 3;
272 var->blue.length = 2;
273 var->transp.offset = 7;
274 var->transp.length = 1;
275 } else {
276 var->red.offset = 0;
277 var->red.length = var->bits_per_pixel;
278 var->green = var->red;
279 var->blue = var->red;
280 }
281 break;
282
283 case 19:
284 /* 666 with one bit alpha/transparency */
285 var->transp.offset = 18;
286 var->transp.length = 1;
287 case 18:
288 var->bits_per_pixel = 32;
289
290 /* 666 format */
291 var->red.offset = 12;
292 var->green.offset = 6;
293 var->blue.offset = 0;
294 var->red.length = 6;
295 var->green.length = 6;
296 var->blue.length = 6;
297 break;
298
299 case 16:
300 /* 16 bpp, 565 format */
301 var->red.offset = 11;
302 var->green.offset = 5;
303 var->blue.offset = 0;
304 var->red.length = 5;
305 var->green.length = 6;
306 var->blue.length = 5;
307 break;
308
Jingoo Hanaf1ce6b2011-05-24 08:55:23 +0000309 case 32:
Ben Dooksec549a02009-03-31 15:25:39 -0700310 case 28:
311 case 25:
312 var->transp.length = var->bits_per_pixel - 24;
313 var->transp.offset = 24;
314 /* drop through */
315 case 24:
316 /* our 24bpp is unpacked, so 32bpp */
317 var->bits_per_pixel = 32;
Ben Dooksec549a02009-03-31 15:25:39 -0700318 var->red.offset = 16;
319 var->red.length = 8;
320 var->green.offset = 8;
321 var->green.length = 8;
322 var->blue.offset = 0;
323 var->blue.length = 8;
324 break;
325
326 default:
327 dev_err(sfb->dev, "invalid bpp\n");
328 }
329
330 dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
331 return 0;
332}
333
334/**
335 * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
336 * @sfb: The hardware state.
337 * @pixclock: The pixel clock wanted, in picoseconds.
338 *
339 * Given the specified pixel clock, work out the necessary divider to get
340 * close to the output frequency.
341 */
Mark Browneb29a5c2010-01-15 17:01:40 -0800342static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
Ben Dooksec549a02009-03-31 15:25:39 -0700343{
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900344 unsigned long clk;
Mark Browneb29a5c2010-01-15 17:01:40 -0800345 unsigned long long tmp;
Ben Dooksec549a02009-03-31 15:25:39 -0700346 unsigned int result;
347
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900348 if (sfb->variant.has_clksel)
349 clk = clk_get_rate(sfb->bus_clk);
350 else
351 clk = clk_get_rate(sfb->lcd_clk);
352
Mark Browneb29a5c2010-01-15 17:01:40 -0800353 tmp = (unsigned long long)clk;
354 tmp *= pixclk;
355
356 do_div(tmp, 1000000000UL);
357 result = (unsigned int)tmp / 1000;
Ben Dooksec549a02009-03-31 15:25:39 -0700358
359 dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
360 pixclk, clk, result, clk / result);
361
362 return result;
363}
364
365/**
366 * s3c_fb_align_word() - align pixel count to word boundary
367 * @bpp: The number of bits per pixel
368 * @pix: The value to be aligned.
369 *
370 * Align the given pixel count so that it will start on an 32bit word
371 * boundary.
372 */
373static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
374{
375 int pix_per_word;
376
377 if (bpp > 16)
378 return pix;
379
380 pix_per_word = (8 * 32) / bpp;
381 return ALIGN(pix, pix_per_word);
382}
383
384/**
Pawel Osciakf676ec22010-08-10 18:02:40 -0700385 * vidosd_set_size() - set OSD size for a window
386 *
387 * @win: the window to set OSD size for
388 * @size: OSD size register value
389 */
390static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
391{
392 struct s3c_fb *sfb = win->parent;
393
394 /* OSD can be set up if osd_size_off != 0 for this window */
395 if (win->variant.osd_size_off)
396 writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
397 + win->variant.osd_size_off);
398}
399
400/**
401 * vidosd_set_alpha() - set alpha transparency for a window
402 *
403 * @win: the window to set OSD size for
404 * @alpha: alpha register value
405 */
406static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
407{
408 struct s3c_fb *sfb = win->parent;
409
410 if (win->variant.has_osd_alpha)
411 writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
412}
413
414/**
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700415 * shadow_protect_win() - disable updating values from shadow registers at vsync
416 *
417 * @win: window to protect registers for
418 * @protect: 1 to protect (disable updates)
419 */
420static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
421{
422 struct s3c_fb *sfb = win->parent;
423 u32 reg;
424
425 if (protect) {
426 if (sfb->variant.has_prtcon) {
427 writel(PRTCON_PROTECT, sfb->regs + PRTCON);
428 } else if (sfb->variant.has_shadowcon) {
429 reg = readl(sfb->regs + SHADOWCON);
430 writel(reg | SHADOWCON_WINx_PROTECT(win->index),
431 sfb->regs + SHADOWCON);
432 }
433 } else {
434 if (sfb->variant.has_prtcon) {
435 writel(0, sfb->regs + PRTCON);
436 } else if (sfb->variant.has_shadowcon) {
437 reg = readl(sfb->regs + SHADOWCON);
438 writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
439 sfb->regs + SHADOWCON);
440 }
441 }
442}
443
444/**
Mark Browna2b77dc2011-12-27 14:16:08 +0000445 * s3c_fb_enable() - Set the state of the main LCD output
446 * @sfb: The main framebuffer state.
447 * @enable: The state to set.
448 */
449static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
450{
451 u32 vidcon0 = readl(sfb->regs + VIDCON0);
452
Mark Brownf4f51472011-12-27 14:16:10 +0000453 if (enable && !sfb->output_on)
454 pm_runtime_get_sync(sfb->dev);
455
456 if (enable) {
Mark Browna2b77dc2011-12-27 14:16:08 +0000457 vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
Mark Brownf4f51472011-12-27 14:16:10 +0000458 } else {
Mark Browna2b77dc2011-12-27 14:16:08 +0000459 /* see the note in the framebuffer datasheet about
460 * why you cannot take both of these bits down at the
461 * same time. */
462
Mark Brownf4f51472011-12-27 14:16:10 +0000463 if (vidcon0 & VIDCON0_ENVID) {
464 vidcon0 |= VIDCON0_ENVID;
465 vidcon0 &= ~VIDCON0_ENVID_F;
466 }
Mark Browna2b77dc2011-12-27 14:16:08 +0000467 }
468
469 writel(vidcon0, sfb->regs + VIDCON0);
Mark Brownf4f51472011-12-27 14:16:10 +0000470
471 if (!enable && sfb->output_on)
472 pm_runtime_put_sync(sfb->dev);
473
474 sfb->output_on = enable;
Mark Browna2b77dc2011-12-27 14:16:08 +0000475}
476
477/**
Ben Dooksec549a02009-03-31 15:25:39 -0700478 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
479 * @info: The framebuffer to change.
480 *
481 * Framebuffer layer request to set a new mode for the specified framebuffer
482 */
483static int s3c_fb_set_par(struct fb_info *info)
484{
485 struct fb_var_screeninfo *var = &info->var;
486 struct s3c_fb_win *win = info->par;
487 struct s3c_fb *sfb = win->parent;
488 void __iomem *regs = sfb->regs;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700489 void __iomem *buf = regs;
Ben Dooksec549a02009-03-31 15:25:39 -0700490 int win_no = win->index;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700491 u32 alpha = 0;
Ben Dooksec549a02009-03-31 15:25:39 -0700492 u32 data;
493 u32 pagewidth;
494 int clkdiv;
495
496 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
497
Mark Brown5751b232011-12-27 14:16:11 +0000498 pm_runtime_get_sync(sfb->dev);
499
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700500 shadow_protect_win(win, 1);
501
Ben Dooksec549a02009-03-31 15:25:39 -0700502 switch (var->bits_per_pixel) {
503 case 32:
504 case 24:
505 case 16:
506 case 12:
507 info->fix.visual = FB_VISUAL_TRUECOLOR;
508 break;
509 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700510 if (win->variant.palette_sz >= 256)
Ben Dooksec549a02009-03-31 15:25:39 -0700511 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
512 else
513 info->fix.visual = FB_VISUAL_TRUECOLOR;
514 break;
515 case 1:
516 info->fix.visual = FB_VISUAL_MONO01;
517 break;
518 default:
519 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
520 break;
521 }
522
523 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
524
Pawel Osciak067b2262010-08-10 18:02:38 -0700525 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
526 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
527
Ben Dooksec549a02009-03-31 15:25:39 -0700528 /* disable the window whilst we update it */
529 writel(0, regs + WINCON(win_no));
530
InKi Daead044902010-08-10 18:02:31 -0700531 /* use platform specified window as the basis for the lcd timings */
Ben Dooksec549a02009-03-31 15:25:39 -0700532
InKi Daead044902010-08-10 18:02:31 -0700533 if (win_no == sfb->pdata->default_win) {
Mark Browneb29a5c2010-01-15 17:01:40 -0800534 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
Ben Dooksec549a02009-03-31 15:25:39 -0700535
536 data = sfb->pdata->vidcon0;
537 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
538
539 if (clkdiv > 1)
540 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
541 else
542 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
543
544 /* write the timing data to the panel */
545
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700546 if (sfb->variant.is_2443)
547 data |= (1 << 5);
548
Ben Dooksec549a02009-03-31 15:25:39 -0700549 writel(data, regs + VIDCON0);
550
Mark Browna2b77dc2011-12-27 14:16:08 +0000551 s3c_fb_enable(sfb, 1);
552
Ben Dooksec549a02009-03-31 15:25:39 -0700553 data = VIDTCON0_VBPD(var->upper_margin - 1) |
554 VIDTCON0_VFPD(var->lower_margin - 1) |
555 VIDTCON0_VSPW(var->vsync_len - 1);
556
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700557 writel(data, regs + sfb->variant.vidtcon);
Ben Dooksec549a02009-03-31 15:25:39 -0700558
559 data = VIDTCON1_HBPD(var->left_margin - 1) |
560 VIDTCON1_HFPD(var->right_margin - 1) |
561 VIDTCON1_HSPW(var->hsync_len - 1);
562
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700563 /* VIDTCON1 */
564 writel(data, regs + sfb->variant.vidtcon + 4);
Ben Dooksec549a02009-03-31 15:25:39 -0700565
566 data = VIDTCON2_LINEVAL(var->yres - 1) |
567 VIDTCON2_HOZVAL(var->xres - 1);
Jingoo Hanb73a21fc2011-04-01 07:17:27 +0000568 writel(data, regs + sfb->variant.vidtcon + 8);
Ben Dooksec549a02009-03-31 15:25:39 -0700569 }
570
571 /* write the buffer address */
572
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700573 /* start and end registers stride is 8 */
574 buf = regs + win_no * 8;
575
576 writel(info->fix.smem_start, buf + sfb->variant.buf_start);
Ben Dooksec549a02009-03-31 15:25:39 -0700577
578 data = info->fix.smem_start + info->fix.line_length * var->yres;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700579 writel(data, buf + sfb->variant.buf_end);
Ben Dooksec549a02009-03-31 15:25:39 -0700580
581 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
582 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
583 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700584 writel(data, regs + sfb->variant.buf_size + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700585
586 /* write 'OSD' registers to control position of framebuffer */
587
588 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700589 writel(data, regs + VIDOSD_A(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700590
591 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
592 var->xres - 1)) |
593 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
594
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700595 writel(data, regs + VIDOSD_B(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700596
597 data = var->xres * var->yres;
InKi Dae39000d62009-06-16 15:34:27 -0700598
Pawel Osciakf676ec22010-08-10 18:02:40 -0700599 alpha = VIDISD14C_ALPHA1_R(0xf) |
InKi Dae39000d62009-06-16 15:34:27 -0700600 VIDISD14C_ALPHA1_G(0xf) |
601 VIDISD14C_ALPHA1_B(0xf);
602
Pawel Osciakf676ec22010-08-10 18:02:40 -0700603 vidosd_set_alpha(win, alpha);
604 vidosd_set_size(win, data);
Ben Dooksec549a02009-03-31 15:25:39 -0700605
Jingoo Hanfab7c5b2011-06-09 04:26:45 +0000606 /* Enable DMA channel for this window */
607 if (sfb->variant.has_shadowcon) {
608 data = readl(sfb->regs + SHADOWCON);
609 data |= SHADOWCON_CHx_ENABLE(win_no);
610 writel(data, sfb->regs + SHADOWCON);
611 }
612
Ben Dooksec549a02009-03-31 15:25:39 -0700613 data = WINCONx_ENWIN;
Jingoo Han2d9ae7a2011-12-02 19:07:17 +0900614 sfb->enabled |= (1 << win->index);
Ben Dooksec549a02009-03-31 15:25:39 -0700615
616 /* note, since we have to round up the bits-per-pixel, we end up
617 * relying on the bitfield information for r/g/b/a to work out
618 * exactly which mode of operation is intended. */
619
620 switch (var->bits_per_pixel) {
621 case 1:
622 data |= WINCON0_BPPMODE_1BPP;
623 data |= WINCONx_BITSWP;
624 data |= WINCONx_BURSTLEN_4WORD;
625 break;
626 case 2:
627 data |= WINCON0_BPPMODE_2BPP;
628 data |= WINCONx_BITSWP;
629 data |= WINCONx_BURSTLEN_8WORD;
630 break;
631 case 4:
632 data |= WINCON0_BPPMODE_4BPP;
633 data |= WINCONx_BITSWP;
634 data |= WINCONx_BURSTLEN_8WORD;
635 break;
636 case 8:
637 if (var->transp.length != 0)
638 data |= WINCON1_BPPMODE_8BPP_1232;
639 else
640 data |= WINCON0_BPPMODE_8BPP_PALETTE;
641 data |= WINCONx_BURSTLEN_8WORD;
642 data |= WINCONx_BYTSWP;
643 break;
644 case 16:
645 if (var->transp.length != 0)
646 data |= WINCON1_BPPMODE_16BPP_A1555;
647 else
648 data |= WINCON0_BPPMODE_16BPP_565;
649 data |= WINCONx_HAWSWP;
650 data |= WINCONx_BURSTLEN_16WORD;
651 break;
652 case 24:
653 case 32:
654 if (var->red.length == 6) {
655 if (var->transp.length != 0)
656 data |= WINCON1_BPPMODE_19BPP_A1666;
657 else
658 data |= WINCON1_BPPMODE_18BPP_666;
InKi Dae39000d62009-06-16 15:34:27 -0700659 } else if (var->transp.length == 1)
660 data |= WINCON1_BPPMODE_25BPP_A1888
661 | WINCON1_BLD_PIX;
Jingoo Han4420dd22011-11-07 15:03:01 +0900662 else if ((var->transp.length == 4) ||
663 (var->transp.length == 8))
InKi Dae39000d62009-06-16 15:34:27 -0700664 data |= WINCON1_BPPMODE_28BPP_A4888
665 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
Ben Dooksec549a02009-03-31 15:25:39 -0700666 else
667 data |= WINCON0_BPPMODE_24BPP_888;
668
InKi Daedc8498c2010-08-10 18:02:32 -0700669 data |= WINCONx_WSWP;
Ben Dooksec549a02009-03-31 15:25:39 -0700670 data |= WINCONx_BURSTLEN_16WORD;
671 break;
672 }
673
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700674 /* Enable the colour keying for the window below this one */
InKi Dae39000d62009-06-16 15:34:27 -0700675 if (win_no > 0) {
676 u32 keycon0_data = 0, keycon1_data = 0;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700677 void __iomem *keycon = regs + sfb->variant.keycon;
InKi Dae39000d62009-06-16 15:34:27 -0700678
679 keycon0_data = ~(WxKEYCON0_KEYBL_EN |
680 WxKEYCON0_KEYEN_F |
681 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
682
683 keycon1_data = WxKEYCON1_COLVAL(0xffffff);
684
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700685 keycon += (win_no - 1) * 8;
686
687 writel(keycon0_data, keycon + WKEYCON0);
688 writel(keycon1_data, keycon + WKEYCON1);
InKi Dae39000d62009-06-16 15:34:27 -0700689 }
690
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700691 writel(data, regs + sfb->variant.wincon + (win_no * 4));
692 writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700693
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700694 shadow_protect_win(win, 0);
695
Mark Brown5751b232011-12-27 14:16:11 +0000696 pm_runtime_put_sync(sfb->dev);
697
Ben Dooksec549a02009-03-31 15:25:39 -0700698 return 0;
699}
700
701/**
702 * s3c_fb_update_palette() - set or schedule a palette update.
703 * @sfb: The hardware information.
704 * @win: The window being updated.
705 * @reg: The palette index being changed.
706 * @value: The computed palette value.
707 *
708 * Change the value of a palette register, either by directly writing to
709 * the palette (this requires the palette RAM to be disconnected from the
710 * hardware whilst this is in progress) or schedule the update for later.
711 *
712 * At the moment, since we have no VSYNC interrupt support, we simply set
713 * the palette entry directly.
714 */
715static void s3c_fb_update_palette(struct s3c_fb *sfb,
716 struct s3c_fb_win *win,
717 unsigned int reg,
718 u32 value)
719{
720 void __iomem *palreg;
721 u32 palcon;
722
Ben Dooks50a55032010-08-10 18:02:33 -0700723 palreg = sfb->regs + sfb->variant.palette[win->index];
Ben Dooksec549a02009-03-31 15:25:39 -0700724
725 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
726 __func__, win->index, reg, palreg, value);
727
728 win->palette_buffer[reg] = value;
729
730 palcon = readl(sfb->regs + WPALCON);
731 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
732
Ben Dooks50a55032010-08-10 18:02:33 -0700733 if (win->variant.palette_16bpp)
734 writew(value, palreg + (reg * 2));
Ben Dooksec549a02009-03-31 15:25:39 -0700735 else
Ben Dooks50a55032010-08-10 18:02:33 -0700736 writel(value, palreg + (reg * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700737
738 writel(palcon, sfb->regs + WPALCON);
739}
740
741static inline unsigned int chan_to_field(unsigned int chan,
742 struct fb_bitfield *bf)
743{
744 chan &= 0xffff;
745 chan >>= 16 - bf->length;
746 return chan << bf->offset;
747}
748
749/**
750 * s3c_fb_setcolreg() - framebuffer layer request to change palette.
751 * @regno: The palette index to change.
752 * @red: The red field for the palette data.
753 * @green: The green field for the palette data.
754 * @blue: The blue field for the palette data.
755 * @trans: The transparency (alpha) field for the palette data.
756 * @info: The framebuffer being changed.
757 */
758static int s3c_fb_setcolreg(unsigned regno,
759 unsigned red, unsigned green, unsigned blue,
760 unsigned transp, struct fb_info *info)
761{
762 struct s3c_fb_win *win = info->par;
763 struct s3c_fb *sfb = win->parent;
764 unsigned int val;
765
766 dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
767 __func__, win->index, regno, red, green, blue);
768
Mark Brown5751b232011-12-27 14:16:11 +0000769 pm_runtime_get_sync(sfb->dev);
770
Ben Dooksec549a02009-03-31 15:25:39 -0700771 switch (info->fix.visual) {
772 case FB_VISUAL_TRUECOLOR:
773 /* true-colour, use pseudo-palette */
774
775 if (regno < 16) {
776 u32 *pal = info->pseudo_palette;
777
778 val = chan_to_field(red, &info->var.red);
779 val |= chan_to_field(green, &info->var.green);
780 val |= chan_to_field(blue, &info->var.blue);
781
782 pal[regno] = val;
783 }
784 break;
785
786 case FB_VISUAL_PSEUDOCOLOR:
Ben Dooks50a55032010-08-10 18:02:33 -0700787 if (regno < win->variant.palette_sz) {
Ben Dooksec549a02009-03-31 15:25:39 -0700788 val = chan_to_field(red, &win->palette.r);
789 val |= chan_to_field(green, &win->palette.g);
790 val |= chan_to_field(blue, &win->palette.b);
791
792 s3c_fb_update_palette(sfb, win, regno, val);
793 }
794
795 break;
796
797 default:
Mark Brown5751b232011-12-27 14:16:11 +0000798 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700799 return 1; /* unknown type */
800 }
801
Mark Brown5751b232011-12-27 14:16:11 +0000802 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700803 return 0;
804}
805
806/**
Ben Dooksec549a02009-03-31 15:25:39 -0700807 * s3c_fb_blank() - blank or unblank the given window
808 * @blank_mode: The blank state from FB_BLANK_*
809 * @info: The framebuffer to blank.
810 *
811 * Framebuffer layer request to change the power state.
812 */
813static int s3c_fb_blank(int blank_mode, struct fb_info *info)
814{
815 struct s3c_fb_win *win = info->par;
816 struct s3c_fb *sfb = win->parent;
817 unsigned int index = win->index;
818 u32 wincon;
819
820 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
821
Mark Brown5751b232011-12-27 14:16:11 +0000822 pm_runtime_get_sync(sfb->dev);
823
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700824 wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700825
826 switch (blank_mode) {
827 case FB_BLANK_POWERDOWN:
828 wincon &= ~WINCONx_ENWIN;
829 sfb->enabled &= ~(1 << index);
830 /* fall through to FB_BLANK_NORMAL */
831
832 case FB_BLANK_NORMAL:
833 /* disable the DMA and display 0x0 (black) */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900834 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700835 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700836 sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900837 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700838 break;
839
840 case FB_BLANK_UNBLANK:
Jingoo Hanff8c9102011-12-08 18:08:00 +0900841 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700842 writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900843 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700844 wincon |= WINCONx_ENWIN;
845 sfb->enabled |= (1 << index);
846 break;
847
848 case FB_BLANK_VSYNC_SUSPEND:
849 case FB_BLANK_HSYNC_SUSPEND:
850 default:
Mark Brown5751b232011-12-27 14:16:11 +0000851 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700852 return 1;
853 }
854
Jingoo Hanff8c9102011-12-08 18:08:00 +0900855 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700856 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900857 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700858
859 /* Check the enabled state to see if we need to be running the
860 * main LCD interface, as if there are no active windows then
861 * it is highly likely that we also do not need to output
862 * anything.
863 */
864
865 /* We could do something like the following code, but the current
866 * system of using framebuffer events means that we cannot make
867 * the distinction between just window 0 being inactive and all
868 * the windows being down.
869 *
870 * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
871 */
872
873 /* we're stuck with this until we can do something about overriding
874 * the power control using the blanking event for a single fb.
875 */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900876 if (index == sfb->pdata->default_win) {
877 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700878 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
Jingoo Hanff8c9102011-12-08 18:08:00 +0900879 shadow_protect_win(win, 0);
880 }
Ben Dooksec549a02009-03-31 15:25:39 -0700881
Mark Brown5751b232011-12-27 14:16:11 +0000882 pm_runtime_put_sync(sfb->dev);
883
Ben Dooksec549a02009-03-31 15:25:39 -0700884 return 0;
885}
886
Pawel Osciak067b2262010-08-10 18:02:38 -0700887/**
888 * s3c_fb_pan_display() - Pan the display.
889 *
890 * Note that the offsets can be written to the device at any time, as their
891 * values are latched at each vsync automatically. This also means that only
892 * the last call to this function will have any effect on next vsync, but
893 * there is no need to sleep waiting for it to prevent tearing.
894 *
895 * @var: The screen information to verify.
896 * @info: The framebuffer device.
897 */
898static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
899 struct fb_info *info)
900{
901 struct s3c_fb_win *win = info->par;
902 struct s3c_fb *sfb = win->parent;
903 void __iomem *buf = sfb->regs + win->index * 8;
904 unsigned int start_boff, end_boff;
905
Mark Brown5751b232011-12-27 14:16:11 +0000906 pm_runtime_get_sync(sfb->dev);
907
Pawel Osciak067b2262010-08-10 18:02:38 -0700908 /* Offset in bytes to the start of the displayed area */
909 start_boff = var->yoffset * info->fix.line_length;
910 /* X offset depends on the current bpp */
911 if (info->var.bits_per_pixel >= 8) {
912 start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
913 } else {
914 switch (info->var.bits_per_pixel) {
915 case 4:
916 start_boff += var->xoffset >> 1;
917 break;
918 case 2:
919 start_boff += var->xoffset >> 2;
920 break;
921 case 1:
922 start_boff += var->xoffset >> 3;
923 break;
924 default:
925 dev_err(sfb->dev, "invalid bpp\n");
Mark Brown5751b232011-12-27 14:16:11 +0000926 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700927 return -EINVAL;
928 }
929 }
930 /* Offset in bytes to the end of the displayed area */
Laurent Pinchartd8e7a742011-05-25 11:34:52 +0200931 end_boff = start_boff + info->var.yres * info->fix.line_length;
Pawel Osciak067b2262010-08-10 18:02:38 -0700932
933 /* Temporarily turn off per-vsync update from shadow registers until
934 * both start and end addresses are updated to prevent corruption */
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700935 shadow_protect_win(win, 1);
Pawel Osciak067b2262010-08-10 18:02:38 -0700936
937 writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
938 writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
939
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700940 shadow_protect_win(win, 0);
Pawel Osciak067b2262010-08-10 18:02:38 -0700941
Mark Brown5751b232011-12-27 14:16:11 +0000942 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700943 return 0;
944}
945
Pawel Osciakefdc8462010-08-10 18:02:38 -0700946/**
947 * s3c_fb_enable_irq() - enable framebuffer interrupts
948 * @sfb: main hardware state
949 */
950static void s3c_fb_enable_irq(struct s3c_fb *sfb)
951{
952 void __iomem *regs = sfb->regs;
953 u32 irq_ctrl_reg;
954
955 if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
956 /* IRQ disabled, enable it */
957 irq_ctrl_reg = readl(regs + VIDINTCON0);
958
959 irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
960 irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
961
962 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
963 irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
964 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
965 irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
966
967 writel(irq_ctrl_reg, regs + VIDINTCON0);
968 }
969}
970
971/**
972 * s3c_fb_disable_irq() - disable framebuffer interrupts
973 * @sfb: main hardware state
974 */
975static void s3c_fb_disable_irq(struct s3c_fb *sfb)
976{
977 void __iomem *regs = sfb->regs;
978 u32 irq_ctrl_reg;
979
980 if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
981 /* IRQ enabled, disable it */
982 irq_ctrl_reg = readl(regs + VIDINTCON0);
983
984 irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
985 irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
986
987 writel(irq_ctrl_reg, regs + VIDINTCON0);
988 }
989}
990
991static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
992{
993 struct s3c_fb *sfb = dev_id;
994 void __iomem *regs = sfb->regs;
995 u32 irq_sts_reg;
996
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000997 spin_lock(&sfb->slock);
998
Pawel Osciakefdc8462010-08-10 18:02:38 -0700999 irq_sts_reg = readl(regs + VIDINTCON1);
1000
1001 if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
1002
1003 /* VSYNC interrupt, accept it */
1004 writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
1005
1006 sfb->vsync_info.count++;
1007 wake_up_interruptible(&sfb->vsync_info.wait);
1008 }
1009
1010 /* We only support waiting for VSYNC for now, so it's safe
1011 * to always disable irqs here.
1012 */
1013 s3c_fb_disable_irq(sfb);
1014
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001015 spin_unlock(&sfb->slock);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001016 return IRQ_HANDLED;
1017}
1018
1019/**
1020 * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
1021 * @sfb: main hardware state
1022 * @crtc: head index.
1023 */
1024static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
1025{
1026 unsigned long count;
1027 int ret;
1028
1029 if (crtc != 0)
1030 return -ENODEV;
1031
Mark Brown5751b232011-12-27 14:16:11 +00001032 pm_runtime_get_sync(sfb->dev);
1033
Pawel Osciakefdc8462010-08-10 18:02:38 -07001034 count = sfb->vsync_info.count;
1035 s3c_fb_enable_irq(sfb);
1036 ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
1037 count != sfb->vsync_info.count,
1038 msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
Mark Brown5751b232011-12-27 14:16:11 +00001039
1040 pm_runtime_put_sync(sfb->dev);
1041
Pawel Osciakefdc8462010-08-10 18:02:38 -07001042 if (ret == 0)
1043 return -ETIMEDOUT;
1044
1045 return 0;
1046}
1047
1048static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
1049 unsigned long arg)
1050{
1051 struct s3c_fb_win *win = info->par;
1052 struct s3c_fb *sfb = win->parent;
1053 int ret;
1054 u32 crtc;
1055
1056 switch (cmd) {
1057 case FBIO_WAITFORVSYNC:
1058 if (get_user(crtc, (u32 __user *)arg)) {
1059 ret = -EFAULT;
1060 break;
1061 }
1062
1063 ret = s3c_fb_wait_for_vsync(sfb, crtc);
1064 break;
1065 default:
1066 ret = -ENOTTY;
1067 }
1068
1069 return ret;
1070}
1071
Ben Dooksec549a02009-03-31 15:25:39 -07001072static struct fb_ops s3c_fb_ops = {
1073 .owner = THIS_MODULE,
1074 .fb_check_var = s3c_fb_check_var,
1075 .fb_set_par = s3c_fb_set_par,
1076 .fb_blank = s3c_fb_blank,
1077 .fb_setcolreg = s3c_fb_setcolreg,
1078 .fb_fillrect = cfb_fillrect,
1079 .fb_copyarea = cfb_copyarea,
1080 .fb_imageblit = cfb_imageblit,
Pawel Osciak067b2262010-08-10 18:02:38 -07001081 .fb_pan_display = s3c_fb_pan_display,
Pawel Osciakefdc8462010-08-10 18:02:38 -07001082 .fb_ioctl = s3c_fb_ioctl,
Ben Dooksec549a02009-03-31 15:25:39 -07001083};
1084
1085/**
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001086 * s3c_fb_missing_pixclock() - calculates pixel clock
1087 * @mode: The video mode to change.
1088 *
1089 * Calculate the pixel clock when none has been given through platform data.
1090 */
1091static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
1092{
1093 u64 pixclk = 1000000000000ULL;
1094 u32 div;
1095
1096 div = mode->left_margin + mode->hsync_len + mode->right_margin +
1097 mode->xres;
1098 div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
1099 mode->yres;
1100 div *= mode->refresh ? : 60;
1101
1102 do_div(pixclk, div);
1103
1104 mode->pixclock = pixclk;
1105}
1106
1107/**
Ben Dooksec549a02009-03-31 15:25:39 -07001108 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
1109 * @sfb: The base resources for the hardware.
1110 * @win: The window to initialise memory for.
1111 *
1112 * Allocate memory for the given framebuffer.
1113 */
1114static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
1115 struct s3c_fb_win *win)
1116{
1117 struct s3c_fb_pd_win *windata = win->windata;
1118 unsigned int real_size, virt_size, size;
1119 struct fb_info *fbi = win->fbinfo;
1120 dma_addr_t map_dma;
1121
1122 dev_dbg(sfb->dev, "allocating memory for display\n");
1123
1124 real_size = windata->win_mode.xres * windata->win_mode.yres;
1125 virt_size = windata->virtual_x * windata->virtual_y;
1126
1127 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
1128 real_size, windata->win_mode.xres, windata->win_mode.yres,
1129 virt_size, windata->virtual_x, windata->virtual_y);
1130
1131 size = (real_size > virt_size) ? real_size : virt_size;
1132 size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
1133 size /= 8;
1134
1135 fbi->fix.smem_len = size;
1136 size = PAGE_ALIGN(size);
1137
1138 dev_dbg(sfb->dev, "want %u bytes for window\n", size);
1139
1140 fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
1141 &map_dma, GFP_KERNEL);
1142 if (!fbi->screen_base)
1143 return -ENOMEM;
1144
1145 dev_dbg(sfb->dev, "mapped %x to %p\n",
1146 (unsigned int)map_dma, fbi->screen_base);
1147
1148 memset(fbi->screen_base, 0x0, size);
1149 fbi->fix.smem_start = map_dma;
1150
1151 return 0;
1152}
1153
1154/**
1155 * s3c_fb_free_memory() - free the display memory for the given window
1156 * @sfb: The base resources for the hardware.
1157 * @win: The window to free the display memory for.
1158 *
1159 * Free the display memory allocated by s3c_fb_alloc_memory().
1160 */
1161static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
1162{
1163 struct fb_info *fbi = win->fbinfo;
1164
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001165 if (fbi->screen_base)
1166 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
Ben Dooksec549a02009-03-31 15:25:39 -07001167 fbi->screen_base, fbi->fix.smem_start);
1168}
1169
1170/**
1171 * s3c_fb_release_win() - release resources for a framebuffer window.
1172 * @win: The window to cleanup the resources for.
1173 *
1174 * Release the resources that where claimed for the hardware window,
1175 * such as the framebuffer instance and any memory claimed for it.
1176 */
1177static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
1178{
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001179 u32 data;
1180
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001181 if (win->fbinfo) {
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001182 if (sfb->variant.has_shadowcon) {
1183 data = readl(sfb->regs + SHADOWCON);
1184 data &= ~SHADOWCON_CHx_ENABLE(win->index);
1185 data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
1186 writel(data, sfb->regs + SHADOWCON);
1187 }
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001188 unregister_framebuffer(win->fbinfo);
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001189 if (win->fbinfo->cmap.len)
1190 fb_dealloc_cmap(&win->fbinfo->cmap);
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001191 s3c_fb_free_memory(sfb, win);
1192 framebuffer_release(win->fbinfo);
1193 }
Ben Dooksec549a02009-03-31 15:25:39 -07001194}
1195
1196/**
1197 * s3c_fb_probe_win() - register an hardware window
1198 * @sfb: The base resources for the hardware
Ben Dooks50a55032010-08-10 18:02:33 -07001199 * @variant: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -07001200 * @res: Pointer to where to place the resultant window.
1201 *
1202 * Allocate and do the basic initialisation for one of the hardware's graphics
1203 * windows.
1204 */
1205static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
Ben Dooks50a55032010-08-10 18:02:33 -07001206 struct s3c_fb_win_variant *variant,
Ben Dooksec549a02009-03-31 15:25:39 -07001207 struct s3c_fb_win **res)
1208{
1209 struct fb_var_screeninfo *var;
1210 struct fb_videomode *initmode;
1211 struct s3c_fb_pd_win *windata;
1212 struct s3c_fb_win *win;
1213 struct fb_info *fbinfo;
1214 int palette_size;
1215 int ret;
1216
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001217 dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
Ben Dooksec549a02009-03-31 15:25:39 -07001218
Pawel Osciakefdc8462010-08-10 18:02:38 -07001219 init_waitqueue_head(&sfb->vsync_info.wait);
1220
Ben Dooks50a55032010-08-10 18:02:33 -07001221 palette_size = variant->palette_sz * 4;
Ben Dooksec549a02009-03-31 15:25:39 -07001222
1223 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
1224 palette_size * sizeof(u32), sfb->dev);
1225 if (!fbinfo) {
1226 dev_err(sfb->dev, "failed to allocate framebuffer\n");
1227 return -ENOENT;
1228 }
1229
1230 windata = sfb->pdata->win[win_no];
1231 initmode = &windata->win_mode;
1232
1233 WARN_ON(windata->max_bpp == 0);
1234 WARN_ON(windata->win_mode.xres == 0);
1235 WARN_ON(windata->win_mode.yres == 0);
1236
1237 win = fbinfo->par;
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001238 *res = win;
Ben Dooksec549a02009-03-31 15:25:39 -07001239 var = &fbinfo->var;
Ben Dooks50a55032010-08-10 18:02:33 -07001240 win->variant = *variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001241 win->fbinfo = fbinfo;
1242 win->parent = sfb;
1243 win->windata = windata;
1244 win->index = win_no;
1245 win->palette_buffer = (u32 *)(win + 1);
1246
1247 ret = s3c_fb_alloc_memory(sfb, win);
1248 if (ret) {
1249 dev_err(sfb->dev, "failed to allocate display memory\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001250 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001251 }
1252
1253 /* setup the r/b/g positions for the window's palette */
Ben Dooksbc2da1b2010-08-10 18:02:34 -07001254 if (win->variant.palette_16bpp) {
1255 /* Set RGB 5:6:5 as default */
1256 win->palette.r.offset = 11;
1257 win->palette.r.length = 5;
1258 win->palette.g.offset = 5;
1259 win->palette.g.length = 6;
1260 win->palette.b.offset = 0;
1261 win->palette.b.length = 5;
1262
1263 } else {
1264 /* Set 8bpp or 8bpp and 1bit alpha */
1265 win->palette.r.offset = 16;
1266 win->palette.r.length = 8;
1267 win->palette.g.offset = 8;
1268 win->palette.g.length = 8;
1269 win->palette.b.offset = 0;
1270 win->palette.b.length = 8;
1271 }
Ben Dooksec549a02009-03-31 15:25:39 -07001272
1273 /* setup the initial video mode from the window */
1274 fb_videomode_to_var(&fbinfo->var, initmode);
1275
1276 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
1277 fbinfo->fix.accel = FB_ACCEL_NONE;
1278 fbinfo->var.activate = FB_ACTIVATE_NOW;
1279 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
1280 fbinfo->var.bits_per_pixel = windata->default_bpp;
1281 fbinfo->fbops = &s3c_fb_ops;
1282 fbinfo->flags = FBINFO_FLAG_DEFAULT;
1283 fbinfo->pseudo_palette = &win->pseudo_palette;
1284
1285 /* prepare to actually start the framebuffer */
1286
1287 ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
1288 if (ret < 0) {
1289 dev_err(sfb->dev, "check_var failed on initial video params\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001290 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001291 }
1292
1293 /* create initial colour map */
1294
Ben Dooks50a55032010-08-10 18:02:33 -07001295 ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
Ben Dooksec549a02009-03-31 15:25:39 -07001296 if (ret == 0)
1297 fb_set_cmap(&fbinfo->cmap, fbinfo);
1298 else
1299 dev_err(sfb->dev, "failed to allocate fb cmap\n");
1300
1301 s3c_fb_set_par(fbinfo);
1302
1303 dev_dbg(sfb->dev, "about to register framebuffer\n");
1304
1305 /* run the check_var and set_par on our configuration. */
1306
1307 ret = register_framebuffer(fbinfo);
1308 if (ret < 0) {
1309 dev_err(sfb->dev, "failed to register framebuffer\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001310 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001311 }
1312
Ben Dooksec549a02009-03-31 15:25:39 -07001313 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
1314
1315 return 0;
Ben Dooksec549a02009-03-31 15:25:39 -07001316}
1317
1318/**
1319 * s3c_fb_clear_win() - clear hardware window registers.
1320 * @sfb: The base resources for the hardware.
1321 * @win: The window to process.
1322 *
1323 * Reset the specific window registers to a known state.
1324 */
1325static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
1326{
1327 void __iomem *regs = sfb->regs;
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001328 u32 reg;
Ben Dooksec549a02009-03-31 15:25:39 -07001329
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001330 writel(0, regs + sfb->variant.wincon + (win * 4));
1331 writel(0, regs + VIDOSD_A(win, sfb->variant));
1332 writel(0, regs + VIDOSD_B(win, sfb->variant));
1333 writel(0, regs + VIDOSD_C(win, sfb->variant));
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001334 reg = readl(regs + SHADOWCON);
1335 writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
Ben Dooksec549a02009-03-31 15:25:39 -07001336}
1337
1338static int __devinit s3c_fb_probe(struct platform_device *pdev)
1339{
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001340 const struct platform_device_id *platid;
Ben Dooks50a55032010-08-10 18:02:33 -07001341 struct s3c_fb_driverdata *fbdrv;
Ben Dooksec549a02009-03-31 15:25:39 -07001342 struct device *dev = &pdev->dev;
1343 struct s3c_fb_platdata *pd;
1344 struct s3c_fb *sfb;
1345 struct resource *res;
1346 int win;
1347 int ret = 0;
1348
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001349 platid = platform_get_device_id(pdev);
1350 fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
Ben Dooks50a55032010-08-10 18:02:33 -07001351
1352 if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
1353 dev_err(dev, "too many windows, cannot attach\n");
1354 return -EINVAL;
1355 }
1356
Ben Dooksec549a02009-03-31 15:25:39 -07001357 pd = pdev->dev.platform_data;
1358 if (!pd) {
1359 dev_err(dev, "no platform data specified\n");
1360 return -EINVAL;
1361 }
1362
Mark Brown857a8df2012-01-21 13:11:49 +00001363 sfb = devm_kzalloc(dev, sizeof(struct s3c_fb), GFP_KERNEL);
Ben Dooksec549a02009-03-31 15:25:39 -07001364 if (!sfb) {
1365 dev_err(dev, "no memory for framebuffers\n");
1366 return -ENOMEM;
1367 }
1368
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001369 dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
1370
Ben Dooksec549a02009-03-31 15:25:39 -07001371 sfb->dev = dev;
1372 sfb->pdata = pd;
Ben Dooks50a55032010-08-10 18:02:33 -07001373 sfb->variant = fbdrv->variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001374
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001375 spin_lock_init(&sfb->slock);
1376
Ben Dooksec549a02009-03-31 15:25:39 -07001377 sfb->bus_clk = clk_get(dev, "lcd");
1378 if (IS_ERR(sfb->bus_clk)) {
1379 dev_err(dev, "failed to get bus clock\n");
axel lin942b8d02011-02-11 08:51:10 +00001380 ret = PTR_ERR(sfb->bus_clk);
Ben Dooksec549a02009-03-31 15:25:39 -07001381 goto err_sfb;
1382 }
1383
1384 clk_enable(sfb->bus_clk);
1385
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001386 if (!sfb->variant.has_clksel) {
1387 sfb->lcd_clk = clk_get(dev, "sclk_fimd");
1388 if (IS_ERR(sfb->lcd_clk)) {
1389 dev_err(dev, "failed to get lcd clock\n");
1390 ret = PTR_ERR(sfb->lcd_clk);
1391 goto err_bus_clk;
1392 }
1393
1394 clk_enable(sfb->lcd_clk);
1395 }
1396
Jingoo Han49592122010-12-17 16:45:46 +09001397 pm_runtime_enable(sfb->dev);
1398
Ben Dooksec549a02009-03-31 15:25:39 -07001399 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1400 if (!res) {
1401 dev_err(dev, "failed to find registers\n");
1402 ret = -ENOENT;
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001403 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001404 }
1405
Mark Brown857a8df2012-01-21 13:11:49 +00001406 sfb->regs = devm_request_and_ioremap(dev, res);
Ben Dooksec549a02009-03-31 15:25:39 -07001407 if (!sfb->regs) {
1408 dev_err(dev, "failed to map registers\n");
1409 ret = -ENXIO;
Mark Brown857a8df2012-01-21 13:11:49 +00001410 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001411 }
1412
Pawel Osciakefdc8462010-08-10 18:02:38 -07001413 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1414 if (!res) {
1415 dev_err(dev, "failed to acquire irq resource\n");
1416 ret = -ENOENT;
Mark Brown857a8df2012-01-21 13:11:49 +00001417 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001418 }
1419 sfb->irq_no = res->start;
1420 ret = request_irq(sfb->irq_no, s3c_fb_irq,
1421 0, "s3c_fb", sfb);
1422 if (ret) {
1423 dev_err(dev, "irq request failed\n");
Mark Brown857a8df2012-01-21 13:11:49 +00001424 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001425 }
1426
Ben Dooksec549a02009-03-31 15:25:39 -07001427 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
1428
Jingoo Han49592122010-12-17 16:45:46 +09001429 platform_set_drvdata(pdev, sfb);
1430 pm_runtime_get_sync(sfb->dev);
1431
Ben Dooksec549a02009-03-31 15:25:39 -07001432 /* setup gpio and output polarity controls */
1433
1434 pd->setup_gpio();
1435
1436 writel(pd->vidcon1, sfb->regs + VIDCON1);
1437
1438 /* zero all windows before we do anything */
1439
Ben Dooks50a55032010-08-10 18:02:33 -07001440 for (win = 0; win < fbdrv->variant.nr_windows; win++)
Ben Dooksec549a02009-03-31 15:25:39 -07001441 s3c_fb_clear_win(sfb, win);
1442
Ben Dooks94947032010-08-10 18:02:32 -07001443 /* initialise colour key controls */
Ben Dooks50a55032010-08-10 18:02:33 -07001444 for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001445 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1446
1447 regs += (win * 8);
1448 writel(0xffffff, regs + WKEYCON0);
1449 writel(0xffffff, regs + WKEYCON1);
Ben Dooks94947032010-08-10 18:02:32 -07001450 }
1451
Ben Dooksec549a02009-03-31 15:25:39 -07001452 /* we have the register setup, start allocating framebuffers */
1453
Ben Dooks50a55032010-08-10 18:02:33 -07001454 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
Ben Dooksec549a02009-03-31 15:25:39 -07001455 if (!pd->win[win])
1456 continue;
1457
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001458 if (!pd->win[win]->win_mode.pixclock)
1459 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1460
Ben Dooks50a55032010-08-10 18:02:33 -07001461 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1462 &sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001463 if (ret < 0) {
1464 dev_err(dev, "failed to create window %d\n", win);
1465 for (; win >= 0; win--)
1466 s3c_fb_release_win(sfb, sfb->windows[win]);
Mark Brown3500b0b2011-12-27 14:16:09 +00001467 goto err_pm_runtime;
Ben Dooksec549a02009-03-31 15:25:39 -07001468 }
1469 }
1470
1471 platform_set_drvdata(pdev, sfb);
Mark Brownfe05f8b2011-12-27 14:16:07 +00001472 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001473
1474 return 0;
1475
Mark Brown3500b0b2011-12-27 14:16:09 +00001476err_pm_runtime:
1477 pm_runtime_put_sync(sfb->dev);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001478 free_irq(sfb->irq_no, sfb);
1479
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001480err_lcd_clk:
Mark Brown3500b0b2011-12-27 14:16:09 +00001481 pm_runtime_disable(sfb->dev);
1482
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001483 if (!sfb->variant.has_clksel) {
1484 clk_disable(sfb->lcd_clk);
1485 clk_put(sfb->lcd_clk);
1486 }
1487
1488err_bus_clk:
Ben Dooksec549a02009-03-31 15:25:39 -07001489 clk_disable(sfb->bus_clk);
1490 clk_put(sfb->bus_clk);
1491
1492err_sfb:
Ben Dooksec549a02009-03-31 15:25:39 -07001493 return ret;
1494}
1495
1496/**
1497 * s3c_fb_remove() - Cleanup on module finalisation
1498 * @pdev: The platform device we are bound to.
1499 *
1500 * Shutdown and then release all the resources that the driver allocated
1501 * on initialisation.
1502 */
1503static int __devexit s3c_fb_remove(struct platform_device *pdev)
1504{
1505 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1506 int win;
1507
Mark Brownfe05f8b2011-12-27 14:16:07 +00001508 pm_runtime_get_sync(sfb->dev);
1509
Pawel Osciakc42b1102009-07-29 15:02:10 -07001510 for (win = 0; win < S3C_FB_MAX_WIN; win++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001511 if (sfb->windows[win])
1512 s3c_fb_release_win(sfb, sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001513
Pawel Osciakefdc8462010-08-10 18:02:38 -07001514 free_irq(sfb->irq_no, sfb);
1515
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001516 if (!sfb->variant.has_clksel) {
1517 clk_disable(sfb->lcd_clk);
1518 clk_put(sfb->lcd_clk);
1519 }
1520
Ben Dooksec549a02009-03-31 15:25:39 -07001521 clk_disable(sfb->bus_clk);
1522 clk_put(sfb->bus_clk);
1523
Jingoo Han49592122010-12-17 16:45:46 +09001524 pm_runtime_put_sync(sfb->dev);
1525 pm_runtime_disable(sfb->dev);
1526
Ben Dooksec549a02009-03-31 15:25:39 -07001527 return 0;
1528}
1529
Mark Brownf4f51472011-12-27 14:16:10 +00001530#ifdef CONFIG_PM_SLEEP
Jingoo Han49592122010-12-17 16:45:46 +09001531static int s3c_fb_suspend(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001532{
Jingoo Han49592122010-12-17 16:45:46 +09001533 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001534 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1535 struct s3c_fb_win *win;
1536 int win_no;
1537
Pawel Osciakc42b1102009-07-29 15:02:10 -07001538 for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
Ben Dooksec549a02009-03-31 15:25:39 -07001539 win = sfb->windows[win_no];
1540 if (!win)
1541 continue;
1542
1543 /* use the blank function to push into power-down */
1544 s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
1545 }
1546
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001547 if (!sfb->variant.has_clksel)
1548 clk_disable(sfb->lcd_clk);
1549
Ben Dooksec549a02009-03-31 15:25:39 -07001550 clk_disable(sfb->bus_clk);
1551 return 0;
1552}
1553
Jingoo Han49592122010-12-17 16:45:46 +09001554static int s3c_fb_resume(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001555{
Jingoo Han49592122010-12-17 16:45:46 +09001556 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001557 struct s3c_fb *sfb = platform_get_drvdata(pdev);
Marek Szyprowski17663e52009-05-28 14:34:35 -07001558 struct s3c_fb_platdata *pd = sfb->pdata;
Ben Dooksec549a02009-03-31 15:25:39 -07001559 struct s3c_fb_win *win;
1560 int win_no;
1561
1562 clk_enable(sfb->bus_clk);
1563
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001564 if (!sfb->variant.has_clksel)
1565 clk_enable(sfb->lcd_clk);
1566
Jingoo Han6aa96812011-05-24 08:55:31 +00001567 /* setup gpio and output polarity controls */
1568 pd->setup_gpio();
Marek Szyprowski17663e52009-05-28 14:34:35 -07001569 writel(pd->vidcon1, sfb->regs + VIDCON1);
1570
1571 /* zero all windows before we do anything */
Ben Dooks50a55032010-08-10 18:02:33 -07001572 for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001573 s3c_fb_clear_win(sfb, win_no);
1574
Ben Dooks50a55032010-08-10 18:02:33 -07001575 for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001576 void __iomem *regs = sfb->regs + sfb->variant.keycon;
Jingoo Hanff8c9102011-12-08 18:08:00 +09001577 win = sfb->windows[win_no];
1578 if (!win)
1579 continue;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001580
Jingoo Hanff8c9102011-12-08 18:08:00 +09001581 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001582 regs += (win_no * 8);
1583 writel(0xffffff, regs + WKEYCON0);
1584 writel(0xffffff, regs + WKEYCON1);
Jingoo Hanff8c9102011-12-08 18:08:00 +09001585 shadow_protect_win(win, 0);
Ben Dooks94947032010-08-10 18:02:32 -07001586 }
1587
Marek Szyprowski17663e52009-05-28 14:34:35 -07001588 /* restore framebuffers */
Ben Dooksec549a02009-03-31 15:25:39 -07001589 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1590 win = sfb->windows[win_no];
1591 if (!win)
1592 continue;
1593
1594 dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
1595 s3c_fb_set_par(win->fbinfo);
1596 }
1597
1598 return 0;
1599}
Ben Dooksec549a02009-03-31 15:25:39 -07001600#endif
1601
Mark Brownf4f51472011-12-27 14:16:10 +00001602#ifdef CONFIG_PM_RUNTIME
1603static int s3c_fb_runtime_suspend(struct device *dev)
1604{
1605 struct platform_device *pdev = to_platform_device(dev);
1606 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1607
1608 if (!sfb->variant.has_clksel)
1609 clk_disable(sfb->lcd_clk);
1610
1611 clk_disable(sfb->bus_clk);
1612
1613 return 0;
1614}
1615
1616static int s3c_fb_runtime_resume(struct device *dev)
1617{
1618 struct platform_device *pdev = to_platform_device(dev);
1619 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1620 struct s3c_fb_platdata *pd = sfb->pdata;
1621
1622 clk_enable(sfb->bus_clk);
1623
1624 if (!sfb->variant.has_clksel)
1625 clk_enable(sfb->lcd_clk);
1626
1627 /* setup gpio and output polarity controls */
1628 pd->setup_gpio();
1629 writel(pd->vidcon1, sfb->regs + VIDCON1);
1630
1631 return 0;
1632}
1633#endif
Ben Dooks50a55032010-08-10 18:02:33 -07001634
1635#define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
1636#define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
1637
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001638static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
Ben Dooks50a55032010-08-10 18:02:33 -07001639 [0] = {
1640 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001641 .osd_size_off = 0x8,
Ben Dooks50a55032010-08-10 18:02:33 -07001642 .palette_sz = 256,
Jingoo Hancd74eba2011-04-22 07:09:40 +00001643 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1644 VALID_BPP(18) | VALID_BPP(24)),
Ben Dooks50a55032010-08-10 18:02:33 -07001645 },
1646 [1] = {
1647 .has_osd_c = 1,
1648 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001649 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001650 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001651 .palette_sz = 256,
1652 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1653 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001654 VALID_BPP(24) | VALID_BPP(25) |
1655 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001656 },
1657 [2] = {
1658 .has_osd_c = 1,
1659 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001660 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001661 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001662 .palette_sz = 16,
1663 .palette_16bpp = 1,
1664 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1665 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001666 VALID_BPP(24) | VALID_BPP(25) |
1667 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001668 },
1669 [3] = {
1670 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001671 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001672 .palette_sz = 16,
1673 .palette_16bpp = 1,
1674 .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
1675 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001676 VALID_BPP(24) | VALID_BPP(25) |
1677 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001678 },
1679 [4] = {
1680 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001681 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001682 .palette_sz = 4,
1683 .palette_16bpp = 1,
1684 .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
1685 VALID_BPP(16) | VALID_BPP(18) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001686 VALID_BPP(19) | VALID_BPP(24) |
1687 VALID_BPP(25) | VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001688 },
1689};
1690
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001691static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
1692 [0] = {
1693 .has_osd_c = 1,
1694 .osd_size_off = 0x8,
1695 .palette_sz = 256,
1696 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1697 VALID_BPP(15) | VALID_BPP(16) |
1698 VALID_BPP(18) | VALID_BPP(19) |
1699 VALID_BPP(24) | VALID_BPP(25) |
1700 VALID_BPP(32)),
1701 },
1702 [1] = {
1703 .has_osd_c = 1,
1704 .has_osd_d = 1,
1705 .osd_size_off = 0xc,
1706 .has_osd_alpha = 1,
1707 .palette_sz = 256,
1708 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1709 VALID_BPP(15) | VALID_BPP(16) |
1710 VALID_BPP(18) | VALID_BPP(19) |
1711 VALID_BPP(24) | VALID_BPP(25) |
1712 VALID_BPP(32)),
1713 },
1714 [2] = {
1715 .has_osd_c = 1,
1716 .has_osd_d = 1,
1717 .osd_size_off = 0xc,
1718 .has_osd_alpha = 1,
1719 .palette_sz = 256,
1720 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1721 VALID_BPP(15) | VALID_BPP(16) |
1722 VALID_BPP(18) | VALID_BPP(19) |
1723 VALID_BPP(24) | VALID_BPP(25) |
1724 VALID_BPP(32)),
1725 },
1726 [3] = {
1727 .has_osd_c = 1,
1728 .has_osd_alpha = 1,
1729 .palette_sz = 256,
1730 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1731 VALID_BPP(15) | VALID_BPP(16) |
1732 VALID_BPP(18) | VALID_BPP(19) |
1733 VALID_BPP(24) | VALID_BPP(25) |
1734 VALID_BPP(32)),
1735 },
1736 [4] = {
1737 .has_osd_c = 1,
1738 .has_osd_alpha = 1,
1739 .palette_sz = 256,
1740 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1741 VALID_BPP(15) | VALID_BPP(16) |
1742 VALID_BPP(18) | VALID_BPP(19) |
1743 VALID_BPP(24) | VALID_BPP(25) |
1744 VALID_BPP(32)),
1745 },
1746};
1747
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001748static struct s3c_fb_driverdata s3c_fb_data_64xx = {
Ben Dooks50a55032010-08-10 18:02:33 -07001749 .variant = {
1750 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001751 .vidtcon = VIDTCON0,
1752 .wincon = WINCON(0),
1753 .winmap = WINxMAP(0),
1754 .keycon = WKEYCON,
1755 .osd = VIDOSD_BASE,
1756 .osd_stride = 16,
1757 .buf_start = VIDW_BUF_START(0),
1758 .buf_size = VIDW_BUF_SIZE(0),
1759 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001760
1761 .palette = {
1762 [0] = 0x400,
1763 [1] = 0x800,
1764 [2] = 0x300,
1765 [3] = 0x320,
1766 [4] = 0x340,
1767 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001768
1769 .has_prtcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001770 .has_clksel = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001771 },
1772 .win[0] = &s3c_fb_data_64xx_wins[0],
1773 .win[1] = &s3c_fb_data_64xx_wins[1],
1774 .win[2] = &s3c_fb_data_64xx_wins[2],
1775 .win[3] = &s3c_fb_data_64xx_wins[3],
1776 .win[4] = &s3c_fb_data_64xx_wins[4],
1777};
1778
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001779static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001780 .variant = {
1781 .nr_windows = 5,
1782 .vidtcon = VIDTCON0,
1783 .wincon = WINCON(0),
1784 .winmap = WINxMAP(0),
1785 .keycon = WKEYCON,
1786 .osd = VIDOSD_BASE,
1787 .osd_stride = 16,
1788 .buf_start = VIDW_BUF_START(0),
1789 .buf_size = VIDW_BUF_SIZE(0),
1790 .buf_end = VIDW_BUF_END(0),
1791
1792 .palette = {
1793 [0] = 0x2400,
1794 [1] = 0x2800,
1795 [2] = 0x2c00,
1796 [3] = 0x3000,
1797 [4] = 0x3400,
1798 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001799
1800 .has_prtcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001801 .has_clksel = 1,
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001802 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001803 .win[0] = &s3c_fb_data_s5p_wins[0],
1804 .win[1] = &s3c_fb_data_s5p_wins[1],
1805 .win[2] = &s3c_fb_data_s5p_wins[2],
1806 .win[3] = &s3c_fb_data_s5p_wins[3],
1807 .win[4] = &s3c_fb_data_s5p_wins[4],
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001808};
1809
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001810static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
Ben Dooks50a55032010-08-10 18:02:33 -07001811 .variant = {
1812 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001813 .vidtcon = VIDTCON0,
1814 .wincon = WINCON(0),
1815 .winmap = WINxMAP(0),
1816 .keycon = WKEYCON,
1817 .osd = VIDOSD_BASE,
1818 .osd_stride = 16,
1819 .buf_start = VIDW_BUF_START(0),
1820 .buf_size = VIDW_BUF_SIZE(0),
1821 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001822
1823 .palette = {
1824 [0] = 0x2400,
1825 [1] = 0x2800,
1826 [2] = 0x2c00,
1827 [3] = 0x3000,
1828 [4] = 0x3400,
1829 },
Pawel Osciakf5ec5462010-08-10 18:02:40 -07001830
1831 .has_shadowcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001832 .has_clksel = 1,
1833 },
1834 .win[0] = &s3c_fb_data_s5p_wins[0],
1835 .win[1] = &s3c_fb_data_s5p_wins[1],
1836 .win[2] = &s3c_fb_data_s5p_wins[2],
1837 .win[3] = &s3c_fb_data_s5p_wins[3],
1838 .win[4] = &s3c_fb_data_s5p_wins[4],
1839};
1840
1841static struct s3c_fb_driverdata s3c_fb_data_exynos4 = {
1842 .variant = {
1843 .nr_windows = 5,
1844 .vidtcon = VIDTCON0,
1845 .wincon = WINCON(0),
1846 .winmap = WINxMAP(0),
1847 .keycon = WKEYCON,
1848 .osd = VIDOSD_BASE,
1849 .osd_stride = 16,
1850 .buf_start = VIDW_BUF_START(0),
1851 .buf_size = VIDW_BUF_SIZE(0),
1852 .buf_end = VIDW_BUF_END(0),
1853
1854 .palette = {
1855 [0] = 0x2400,
1856 [1] = 0x2800,
1857 [2] = 0x2c00,
1858 [3] = 0x3000,
1859 [4] = 0x3400,
1860 },
1861
1862 .has_shadowcon = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001863 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001864 .win[0] = &s3c_fb_data_s5p_wins[0],
1865 .win[1] = &s3c_fb_data_s5p_wins[1],
1866 .win[2] = &s3c_fb_data_s5p_wins[2],
1867 .win[3] = &s3c_fb_data_s5p_wins[3],
1868 .win[4] = &s3c_fb_data_s5p_wins[4],
Ben Dooks50a55032010-08-10 18:02:33 -07001869};
1870
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001871/* S3C2443/S3C2416 style hardware */
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001872static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001873 .variant = {
1874 .nr_windows = 2,
1875 .is_2443 = 1,
1876
1877 .vidtcon = 0x08,
1878 .wincon = 0x14,
1879 .winmap = 0xd0,
1880 .keycon = 0xb0,
1881 .osd = 0x28,
1882 .osd_stride = 12,
1883 .buf_start = 0x64,
1884 .buf_size = 0x94,
1885 .buf_end = 0x7c,
1886
1887 .palette = {
1888 [0] = 0x400,
1889 [1] = 0x800,
1890 },
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001891 .has_clksel = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001892 },
1893 .win[0] = &(struct s3c_fb_win_variant) {
1894 .palette_sz = 256,
1895 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1896 },
1897 .win[1] = &(struct s3c_fb_win_variant) {
1898 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001899 .has_osd_alpha = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001900 .palette_sz = 256,
1901 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1902 VALID_BPP(18) | VALID_BPP(19) |
1903 VALID_BPP(24) | VALID_BPP(25) |
1904 VALID_BPP(28)),
1905 },
1906};
1907
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001908static struct s3c_fb_driverdata s3c_fb_data_s5p64x0 = {
1909 .variant = {
1910 .nr_windows = 3,
1911 .vidtcon = VIDTCON0,
1912 .wincon = WINCON(0),
1913 .winmap = WINxMAP(0),
1914 .keycon = WKEYCON,
1915 .osd = VIDOSD_BASE,
1916 .osd_stride = 16,
1917 .buf_start = VIDW_BUF_START(0),
1918 .buf_size = VIDW_BUF_SIZE(0),
1919 .buf_end = VIDW_BUF_END(0),
1920
1921 .palette = {
1922 [0] = 0x2400,
1923 [1] = 0x2800,
1924 [2] = 0x2c00,
1925 },
1926 },
1927 .win[0] = &s3c_fb_data_s5p_wins[0],
1928 .win[1] = &s3c_fb_data_s5p_wins[1],
1929 .win[2] = &s3c_fb_data_s5p_wins[2],
1930};
1931
Ben Dooks50a55032010-08-10 18:02:33 -07001932static struct platform_device_id s3c_fb_driver_ids[] = {
1933 {
1934 .name = "s3c-fb",
1935 .driver_data = (unsigned long)&s3c_fb_data_64xx,
1936 }, {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001937 .name = "s5pc100-fb",
1938 .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
1939 }, {
1940 .name = "s5pv210-fb",
1941 .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001942 }, {
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001943 .name = "exynos4-fb",
1944 .driver_data = (unsigned long)&s3c_fb_data_exynos4,
1945 }, {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001946 .name = "s3c2443-fb",
1947 .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001948 }, {
1949 .name = "s5p64x0-fb",
1950 .driver_data = (unsigned long)&s3c_fb_data_s5p64x0,
Ben Dooks50a55032010-08-10 18:02:33 -07001951 },
1952 {},
1953};
1954MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
1955
Mark Brownf4f51472011-12-27 14:16:10 +00001956static const struct dev_pm_ops s3cfb_pm_ops = {
1957 SET_SYSTEM_SLEEP_PM_OPS(s3c_fb_suspend, s3c_fb_resume)
1958 SET_RUNTIME_PM_OPS(s3c_fb_runtime_suspend, s3c_fb_runtime_resume,
1959 NULL)
1960};
Jingoo Han49592122010-12-17 16:45:46 +09001961
Ben Dooksec549a02009-03-31 15:25:39 -07001962static struct platform_driver s3c_fb_driver = {
1963 .probe = s3c_fb_probe,
Peter Korsgaard3163eaba2009-09-22 16:47:55 -07001964 .remove = __devexit_p(s3c_fb_remove),
Ben Dooks50a55032010-08-10 18:02:33 -07001965 .id_table = s3c_fb_driver_ids,
Ben Dooksec549a02009-03-31 15:25:39 -07001966 .driver = {
1967 .name = "s3c-fb",
1968 .owner = THIS_MODULE,
Mark Brownfe05f8b2011-12-27 14:16:07 +00001969 .pm = &s3cfb_pm_ops,
Ben Dooksec549a02009-03-31 15:25:39 -07001970 },
1971};
1972
Axel Lin4277f2c2011-11-26 10:25:54 +08001973module_platform_driver(s3c_fb_driver);
Ben Dooksec549a02009-03-31 15:25:39 -07001974
1975MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1976MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
1977MODULE_LICENSE("GPL");
1978MODULE_ALIAS("platform:s3c-fb");