blob: 7c5158dda0bf8f91ec9827a6fb9b5d1a3b9a172d [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 Hanb73a21fc2011-04-01 07:17:27 +000051 __raw_writel(v, r); } while (0)
Ben Dooksec549a02009-03-31 15:25:39 -070052#endif /* FB_S3C_DEBUG_REGWRITE */
53
Pawel Osciakefdc8462010-08-10 18:02:38 -070054/* irq_flags bits */
55#define S3C_FB_VSYNC_IRQ_EN 0
56
57#define VSYNC_TIMEOUT_MSEC 50
58
Ben Dooksec549a02009-03-31 15:25:39 -070059struct s3c_fb;
60
Ben Dooks50a55032010-08-10 18:02:33 -070061#define VALID_BPP(x) (1 << ((x) - 1))
62
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070063#define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
64#define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
65#define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
66#define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
67#define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
68
Ben Dooks50a55032010-08-10 18:02:33 -070069/**
70 * struct s3c_fb_variant - fb variant information
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070071 * @is_2443: Set if S3C2443/S3C2416 style hardware.
Ben Dooks50a55032010-08-10 18:02:33 -070072 * @nr_windows: The number of windows.
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070073 * @vidtcon: The base for the VIDTCONx registers
74 * @wincon: The base for the WINxCON registers.
75 * @winmap: The base for the WINxMAP registers.
76 * @keycon: The abse for the WxKEYCON registers.
77 * @buf_start: Offset of buffer start registers.
78 * @buf_size: Offset of buffer size registers.
79 * @buf_end: Offset of buffer end registers.
80 * @osd: The base for the OSD registers.
Ben Dooks50a55032010-08-10 18:02:33 -070081 * @palette: Address of palette memory, or 0 if none.
Pawel Osciak067b2262010-08-10 18:02:38 -070082 * @has_prtcon: Set if has PRTCON register.
Pawel Osciakf5ec5462010-08-10 18:02:40 -070083 * @has_shadowcon: Set if has SHADOWCON register.
Jingoo Hanb5480ed2011-08-22 12:16:04 +090084 * @has_clksel: Set if VIDCON0 register has CLKSEL bit.
Ben Dooks50a55032010-08-10 18:02:33 -070085 */
86struct s3c_fb_variant {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070087 unsigned int is_2443:1;
Ben Dooks50a55032010-08-10 18:02:33 -070088 unsigned short nr_windows;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070089 unsigned short vidtcon;
90 unsigned short wincon;
91 unsigned short winmap;
92 unsigned short keycon;
93 unsigned short buf_start;
94 unsigned short buf_end;
95 unsigned short buf_size;
96 unsigned short osd;
97 unsigned short osd_stride;
Ben Dooks50a55032010-08-10 18:02:33 -070098 unsigned short palette[S3C_FB_MAX_WIN];
Pawel Osciak067b2262010-08-10 18:02:38 -070099
100 unsigned int has_prtcon:1;
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700101 unsigned int has_shadowcon:1;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900102 unsigned int has_clksel:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700103};
104
105/**
106 * struct s3c_fb_win_variant
107 * @has_osd_c: Set if has OSD C register.
108 * @has_osd_d: Set if has OSD D register.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700109 * @has_osd_alpha: Set if can change alpha transparency for a window.
Ben Dooks50a55032010-08-10 18:02:33 -0700110 * @palette_sz: Size of palette in entries.
111 * @palette_16bpp: Set if palette is 16bits wide.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700112 * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
113 * register is located at the given offset from OSD_BASE.
Ben Dooks50a55032010-08-10 18:02:33 -0700114 * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
115 *
116 * valid_bpp bit x is set if (x+1)BPP is supported.
117 */
118struct s3c_fb_win_variant {
119 unsigned int has_osd_c:1;
120 unsigned int has_osd_d:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700121 unsigned int has_osd_alpha:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700122 unsigned int palette_16bpp:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700123 unsigned short osd_size_off;
Ben Dooks50a55032010-08-10 18:02:33 -0700124 unsigned short palette_sz;
125 u32 valid_bpp;
126};
127
128/**
129 * struct s3c_fb_driverdata - per-device type driver data for init time.
130 * @variant: The variant information for this driver.
131 * @win: The window information for each window.
132 */
133struct s3c_fb_driverdata {
134 struct s3c_fb_variant variant;
135 struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
136};
137
Ben Dooksec549a02009-03-31 15:25:39 -0700138/**
Ben Dooksbc2da1b2010-08-10 18:02:34 -0700139 * struct s3c_fb_palette - palette information
140 * @r: Red bitfield.
141 * @g: Green bitfield.
142 * @b: Blue bitfield.
143 * @a: Alpha bitfield.
144 */
145struct s3c_fb_palette {
146 struct fb_bitfield r;
147 struct fb_bitfield g;
148 struct fb_bitfield b;
149 struct fb_bitfield a;
150};
151
152/**
Ben Dooksec549a02009-03-31 15:25:39 -0700153 * struct s3c_fb_win - per window private data for each framebuffer.
154 * @windata: The platform data supplied for the window configuration.
155 * @parent: The hardware that this window is part of.
156 * @fbinfo: Pointer pack to the framebuffer info for this window.
Ben Dooks50a55032010-08-10 18:02:33 -0700157 * @varint: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -0700158 * @palette_buffer: Buffer/cache to hold palette entries.
159 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
160 * @index: The window number of this window.
161 * @palette: The bitfields for changing r/g/b into a hardware palette entry.
162 */
163struct s3c_fb_win {
164 struct s3c_fb_pd_win *windata;
165 struct s3c_fb *parent;
166 struct fb_info *fbinfo;
167 struct s3c_fb_palette palette;
Ben Dooks50a55032010-08-10 18:02:33 -0700168 struct s3c_fb_win_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700169
170 u32 *palette_buffer;
171 u32 pseudo_palette[16];
172 unsigned int index;
173};
174
175/**
Pawel Osciakefdc8462010-08-10 18:02:38 -0700176 * struct s3c_fb_vsync - vsync information
177 * @wait: a queue for processes waiting for vsync
178 * @count: vsync interrupt count
179 */
180struct s3c_fb_vsync {
181 wait_queue_head_t wait;
182 unsigned int count;
183};
184
185/**
Ben Dooksec549a02009-03-31 15:25:39 -0700186 * struct s3c_fb - overall hardware state of the hardware
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000187 * @slock: The spinlock protection for this data sturcture.
Ben Dooksec549a02009-03-31 15:25:39 -0700188 * @dev: The device that we bound to, for printing, etc.
Ben Dooksec549a02009-03-31 15:25:39 -0700189 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900190 * @lcd_clk: The clk (sclk) feeding pixclk.
Ben Dooksec549a02009-03-31 15:25:39 -0700191 * @regs: The mapped hardware registers.
Ben Dooks50a55032010-08-10 18:02:33 -0700192 * @variant: Variant information for this hardware.
Ben Dooksec549a02009-03-31 15:25:39 -0700193 * @enabled: A bitmask of enabled hardware windows.
Mark Brownf4f51472011-12-27 14:16:10 +0000194 * @output_on: Flag if the physical output is enabled.
Ben Dooksec549a02009-03-31 15:25:39 -0700195 * @pdata: The platform configuration data passed with the device.
196 * @windows: The hardware windows that have been claimed.
Pawel Osciakefdc8462010-08-10 18:02:38 -0700197 * @irq_no: IRQ line number
198 * @irq_flags: irq flags
199 * @vsync_info: VSYNC-related information (count, queues...)
Ben Dooksec549a02009-03-31 15:25:39 -0700200 */
201struct s3c_fb {
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000202 spinlock_t slock;
Ben Dooksec549a02009-03-31 15:25:39 -0700203 struct device *dev;
Ben Dooksec549a02009-03-31 15:25:39 -0700204 struct clk *bus_clk;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900205 struct clk *lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -0700206 void __iomem *regs;
Ben Dooks50a55032010-08-10 18:02:33 -0700207 struct s3c_fb_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700208
209 unsigned char enabled;
Mark Brownf4f51472011-12-27 14:16:10 +0000210 bool output_on;
Ben Dooksec549a02009-03-31 15:25:39 -0700211
212 struct s3c_fb_platdata *pdata;
213 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
Pawel Osciakefdc8462010-08-10 18:02:38 -0700214
215 int irq_no;
216 unsigned long irq_flags;
217 struct s3c_fb_vsync vsync_info;
Ben Dooksec549a02009-03-31 15:25:39 -0700218};
219
220/**
Ben Dooks50a55032010-08-10 18:02:33 -0700221 * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
222 * @win: The device window.
223 * @bpp: The bit depth.
Ben Dooksec549a02009-03-31 15:25:39 -0700224 */
Ben Dooks50a55032010-08-10 18:02:33 -0700225static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
Ben Dooksec549a02009-03-31 15:25:39 -0700226{
Ben Dooks50a55032010-08-10 18:02:33 -0700227 return win->variant.valid_bpp & VALID_BPP(bpp);
Ben Dooksec549a02009-03-31 15:25:39 -0700228}
229
230/**
231 * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
232 * @var: The screen information to verify.
233 * @info: The framebuffer device.
234 *
235 * Framebuffer layer call to verify the given information and allow us to
236 * update various information depending on the hardware capabilities.
237 */
238static int s3c_fb_check_var(struct fb_var_screeninfo *var,
239 struct fb_info *info)
240{
241 struct s3c_fb_win *win = info->par;
Ben Dooksec549a02009-03-31 15:25:39 -0700242 struct s3c_fb *sfb = win->parent;
243
244 dev_dbg(sfb->dev, "checking parameters\n");
245
Jingoo Han13e6af82011-06-09 04:26:38 +0000246 var->xres_virtual = max(var->xres_virtual, var->xres);
247 var->yres_virtual = max(var->yres_virtual, var->yres);
Ben Dooksec549a02009-03-31 15:25:39 -0700248
Ben Dooks50a55032010-08-10 18:02:33 -0700249 if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
Ben Dooksec549a02009-03-31 15:25:39 -0700250 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
251 win->index, var->bits_per_pixel);
252 return -EINVAL;
253 }
254
255 /* always ensure these are zero, for drop through cases below */
256 var->transp.offset = 0;
257 var->transp.length = 0;
258
259 switch (var->bits_per_pixel) {
260 case 1:
261 case 2:
262 case 4:
263 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700264 if (sfb->variant.palette[win->index] != 0) {
Ben Dooksec549a02009-03-31 15:25:39 -0700265 /* non palletised, A:1,R:2,G:3,B:2 mode */
266 var->red.offset = 4;
267 var->green.offset = 2;
268 var->blue.offset = 0;
269 var->red.length = 5;
270 var->green.length = 3;
271 var->blue.length = 2;
272 var->transp.offset = 7;
273 var->transp.length = 1;
274 } else {
275 var->red.offset = 0;
276 var->red.length = var->bits_per_pixel;
277 var->green = var->red;
278 var->blue = var->red;
279 }
280 break;
281
282 case 19:
283 /* 666 with one bit alpha/transparency */
284 var->transp.offset = 18;
285 var->transp.length = 1;
286 case 18:
287 var->bits_per_pixel = 32;
288
289 /* 666 format */
290 var->red.offset = 12;
291 var->green.offset = 6;
292 var->blue.offset = 0;
293 var->red.length = 6;
294 var->green.length = 6;
295 var->blue.length = 6;
296 break;
297
298 case 16:
299 /* 16 bpp, 565 format */
300 var->red.offset = 11;
301 var->green.offset = 5;
302 var->blue.offset = 0;
303 var->red.length = 5;
304 var->green.length = 6;
305 var->blue.length = 5;
306 break;
307
Jingoo Hanaf1ce6b2011-05-24 08:55:23 +0000308 case 32:
Ben Dooksec549a02009-03-31 15:25:39 -0700309 case 28:
310 case 25:
311 var->transp.length = var->bits_per_pixel - 24;
312 var->transp.offset = 24;
313 /* drop through */
314 case 24:
315 /* our 24bpp is unpacked, so 32bpp */
316 var->bits_per_pixel = 32;
Ben Dooksec549a02009-03-31 15:25:39 -0700317 var->red.offset = 16;
318 var->red.length = 8;
319 var->green.offset = 8;
320 var->green.length = 8;
321 var->blue.offset = 0;
322 var->blue.length = 8;
323 break;
324
325 default:
326 dev_err(sfb->dev, "invalid bpp\n");
327 }
328
329 dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
330 return 0;
331}
332
333/**
334 * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
335 * @sfb: The hardware state.
336 * @pixclock: The pixel clock wanted, in picoseconds.
337 *
338 * Given the specified pixel clock, work out the necessary divider to get
339 * close to the output frequency.
340 */
Mark Browneb29a5c2010-01-15 17:01:40 -0800341static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
Ben Dooksec549a02009-03-31 15:25:39 -0700342{
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900343 unsigned long clk;
Mark Browneb29a5c2010-01-15 17:01:40 -0800344 unsigned long long tmp;
Ben Dooksec549a02009-03-31 15:25:39 -0700345 unsigned int result;
346
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900347 if (sfb->variant.has_clksel)
348 clk = clk_get_rate(sfb->bus_clk);
349 else
350 clk = clk_get_rate(sfb->lcd_clk);
351
Mark Browneb29a5c2010-01-15 17:01:40 -0800352 tmp = (unsigned long long)clk;
353 tmp *= pixclk;
354
355 do_div(tmp, 1000000000UL);
356 result = (unsigned int)tmp / 1000;
Ben Dooksec549a02009-03-31 15:25:39 -0700357
358 dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
359 pixclk, clk, result, clk / result);
360
361 return result;
362}
363
364/**
365 * s3c_fb_align_word() - align pixel count to word boundary
366 * @bpp: The number of bits per pixel
367 * @pix: The value to be aligned.
368 *
369 * Align the given pixel count so that it will start on an 32bit word
370 * boundary.
371 */
372static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
373{
374 int pix_per_word;
375
376 if (bpp > 16)
377 return pix;
378
379 pix_per_word = (8 * 32) / bpp;
380 return ALIGN(pix, pix_per_word);
381}
382
383/**
Pawel Osciakf676ec22010-08-10 18:02:40 -0700384 * vidosd_set_size() - set OSD size for a window
385 *
386 * @win: the window to set OSD size for
387 * @size: OSD size register value
388 */
389static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
390{
391 struct s3c_fb *sfb = win->parent;
392
393 /* OSD can be set up if osd_size_off != 0 for this window */
394 if (win->variant.osd_size_off)
395 writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
396 + win->variant.osd_size_off);
397}
398
399/**
400 * vidosd_set_alpha() - set alpha transparency for a window
401 *
402 * @win: the window to set OSD size for
403 * @alpha: alpha register value
404 */
405static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
406{
407 struct s3c_fb *sfb = win->parent;
408
409 if (win->variant.has_osd_alpha)
410 writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
411}
412
413/**
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700414 * shadow_protect_win() - disable updating values from shadow registers at vsync
415 *
416 * @win: window to protect registers for
417 * @protect: 1 to protect (disable updates)
418 */
419static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
420{
421 struct s3c_fb *sfb = win->parent;
422 u32 reg;
423
424 if (protect) {
425 if (sfb->variant.has_prtcon) {
426 writel(PRTCON_PROTECT, sfb->regs + PRTCON);
427 } else if (sfb->variant.has_shadowcon) {
428 reg = readl(sfb->regs + SHADOWCON);
429 writel(reg | SHADOWCON_WINx_PROTECT(win->index),
430 sfb->regs + SHADOWCON);
431 }
432 } else {
433 if (sfb->variant.has_prtcon) {
434 writel(0, sfb->regs + PRTCON);
435 } else if (sfb->variant.has_shadowcon) {
436 reg = readl(sfb->regs + SHADOWCON);
437 writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
438 sfb->regs + SHADOWCON);
439 }
440 }
441}
442
443/**
Mark Browna2b77dc2011-12-27 14:16:08 +0000444 * s3c_fb_enable() - Set the state of the main LCD output
445 * @sfb: The main framebuffer state.
446 * @enable: The state to set.
447 */
448static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
449{
450 u32 vidcon0 = readl(sfb->regs + VIDCON0);
451
Mark Brownf4f51472011-12-27 14:16:10 +0000452 if (enable && !sfb->output_on)
453 pm_runtime_get_sync(sfb->dev);
454
455 if (enable) {
Mark Browna2b77dc2011-12-27 14:16:08 +0000456 vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
Mark Brownf4f51472011-12-27 14:16:10 +0000457 } else {
Mark Browna2b77dc2011-12-27 14:16:08 +0000458 /* see the note in the framebuffer datasheet about
459 * why you cannot take both of these bits down at the
460 * same time. */
461
Mark Brownf4f51472011-12-27 14:16:10 +0000462 if (vidcon0 & VIDCON0_ENVID) {
463 vidcon0 |= VIDCON0_ENVID;
464 vidcon0 &= ~VIDCON0_ENVID_F;
465 }
Mark Browna2b77dc2011-12-27 14:16:08 +0000466 }
467
468 writel(vidcon0, sfb->regs + VIDCON0);
Mark Brownf4f51472011-12-27 14:16:10 +0000469
470 if (!enable && sfb->output_on)
471 pm_runtime_put_sync(sfb->dev);
472
473 sfb->output_on = enable;
Mark Browna2b77dc2011-12-27 14:16:08 +0000474}
475
476/**
Ben Dooksec549a02009-03-31 15:25:39 -0700477 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
478 * @info: The framebuffer to change.
479 *
480 * Framebuffer layer request to set a new mode for the specified framebuffer
481 */
482static int s3c_fb_set_par(struct fb_info *info)
483{
484 struct fb_var_screeninfo *var = &info->var;
485 struct s3c_fb_win *win = info->par;
486 struct s3c_fb *sfb = win->parent;
487 void __iomem *regs = sfb->regs;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700488 void __iomem *buf = regs;
Ben Dooksec549a02009-03-31 15:25:39 -0700489 int win_no = win->index;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700490 u32 alpha = 0;
Ben Dooksec549a02009-03-31 15:25:39 -0700491 u32 data;
492 u32 pagewidth;
493 int clkdiv;
494
495 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
496
Mark Brown5751b232011-12-27 14:16:11 +0000497 pm_runtime_get_sync(sfb->dev);
498
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700499 shadow_protect_win(win, 1);
500
Ben Dooksec549a02009-03-31 15:25:39 -0700501 switch (var->bits_per_pixel) {
502 case 32:
503 case 24:
504 case 16:
505 case 12:
506 info->fix.visual = FB_VISUAL_TRUECOLOR;
507 break;
508 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700509 if (win->variant.palette_sz >= 256)
Ben Dooksec549a02009-03-31 15:25:39 -0700510 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
511 else
512 info->fix.visual = FB_VISUAL_TRUECOLOR;
513 break;
514 case 1:
515 info->fix.visual = FB_VISUAL_MONO01;
516 break;
517 default:
518 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
519 break;
520 }
521
522 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
523
Pawel Osciak067b2262010-08-10 18:02:38 -0700524 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
525 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
526
Ben Dooksec549a02009-03-31 15:25:39 -0700527 /* disable the window whilst we update it */
528 writel(0, regs + WINCON(win_no));
529
InKi Daead044902010-08-10 18:02:31 -0700530 /* use platform specified window as the basis for the lcd timings */
Ben Dooksec549a02009-03-31 15:25:39 -0700531
InKi Daead044902010-08-10 18:02:31 -0700532 if (win_no == sfb->pdata->default_win) {
Mark Browneb29a5c2010-01-15 17:01:40 -0800533 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
Ben Dooksec549a02009-03-31 15:25:39 -0700534
535 data = sfb->pdata->vidcon0;
536 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
537
538 if (clkdiv > 1)
539 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
540 else
541 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
542
543 /* write the timing data to the panel */
544
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700545 if (sfb->variant.is_2443)
546 data |= (1 << 5);
547
Ben Dooksec549a02009-03-31 15:25:39 -0700548 writel(data, regs + VIDCON0);
549
Mark Browna2b77dc2011-12-27 14:16:08 +0000550 s3c_fb_enable(sfb, 1);
551
Ben Dooksec549a02009-03-31 15:25:39 -0700552 data = VIDTCON0_VBPD(var->upper_margin - 1) |
553 VIDTCON0_VFPD(var->lower_margin - 1) |
554 VIDTCON0_VSPW(var->vsync_len - 1);
555
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700556 writel(data, regs + sfb->variant.vidtcon);
Ben Dooksec549a02009-03-31 15:25:39 -0700557
558 data = VIDTCON1_HBPD(var->left_margin - 1) |
559 VIDTCON1_HFPD(var->right_margin - 1) |
560 VIDTCON1_HSPW(var->hsync_len - 1);
561
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700562 /* VIDTCON1 */
563 writel(data, regs + sfb->variant.vidtcon + 4);
Ben Dooksec549a02009-03-31 15:25:39 -0700564
565 data = VIDTCON2_LINEVAL(var->yres - 1) |
566 VIDTCON2_HOZVAL(var->xres - 1);
Jingoo Hanb73a21fc2011-04-01 07:17:27 +0000567 writel(data, regs + sfb->variant.vidtcon + 8);
Ben Dooksec549a02009-03-31 15:25:39 -0700568 }
569
570 /* write the buffer address */
571
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700572 /* start and end registers stride is 8 */
573 buf = regs + win_no * 8;
574
575 writel(info->fix.smem_start, buf + sfb->variant.buf_start);
Ben Dooksec549a02009-03-31 15:25:39 -0700576
577 data = info->fix.smem_start + info->fix.line_length * var->yres;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700578 writel(data, buf + sfb->variant.buf_end);
Ben Dooksec549a02009-03-31 15:25:39 -0700579
580 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
581 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
582 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700583 writel(data, regs + sfb->variant.buf_size + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700584
585 /* write 'OSD' registers to control position of framebuffer */
586
587 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700588 writel(data, regs + VIDOSD_A(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700589
590 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
591 var->xres - 1)) |
592 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
593
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700594 writel(data, regs + VIDOSD_B(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700595
596 data = var->xres * var->yres;
InKi Dae39000d62009-06-16 15:34:27 -0700597
Pawel Osciakf676ec22010-08-10 18:02:40 -0700598 alpha = VIDISD14C_ALPHA1_R(0xf) |
InKi Dae39000d62009-06-16 15:34:27 -0700599 VIDISD14C_ALPHA1_G(0xf) |
600 VIDISD14C_ALPHA1_B(0xf);
601
Pawel Osciakf676ec22010-08-10 18:02:40 -0700602 vidosd_set_alpha(win, alpha);
603 vidosd_set_size(win, data);
Ben Dooksec549a02009-03-31 15:25:39 -0700604
Jingoo Hanfab7c5b2011-06-09 04:26:45 +0000605 /* Enable DMA channel for this window */
606 if (sfb->variant.has_shadowcon) {
607 data = readl(sfb->regs + SHADOWCON);
608 data |= SHADOWCON_CHx_ENABLE(win_no);
609 writel(data, sfb->regs + SHADOWCON);
610 }
611
Ben Dooksec549a02009-03-31 15:25:39 -0700612 data = WINCONx_ENWIN;
Jingoo Han2d9ae7a2011-12-02 19:07:17 +0900613 sfb->enabled |= (1 << win->index);
Ben Dooksec549a02009-03-31 15:25:39 -0700614
615 /* note, since we have to round up the bits-per-pixel, we end up
616 * relying on the bitfield information for r/g/b/a to work out
617 * exactly which mode of operation is intended. */
618
619 switch (var->bits_per_pixel) {
620 case 1:
621 data |= WINCON0_BPPMODE_1BPP;
622 data |= WINCONx_BITSWP;
623 data |= WINCONx_BURSTLEN_4WORD;
624 break;
625 case 2:
626 data |= WINCON0_BPPMODE_2BPP;
627 data |= WINCONx_BITSWP;
628 data |= WINCONx_BURSTLEN_8WORD;
629 break;
630 case 4:
631 data |= WINCON0_BPPMODE_4BPP;
632 data |= WINCONx_BITSWP;
633 data |= WINCONx_BURSTLEN_8WORD;
634 break;
635 case 8:
636 if (var->transp.length != 0)
637 data |= WINCON1_BPPMODE_8BPP_1232;
638 else
639 data |= WINCON0_BPPMODE_8BPP_PALETTE;
640 data |= WINCONx_BURSTLEN_8WORD;
641 data |= WINCONx_BYTSWP;
642 break;
643 case 16:
644 if (var->transp.length != 0)
645 data |= WINCON1_BPPMODE_16BPP_A1555;
646 else
647 data |= WINCON0_BPPMODE_16BPP_565;
648 data |= WINCONx_HAWSWP;
649 data |= WINCONx_BURSTLEN_16WORD;
650 break;
651 case 24:
652 case 32:
653 if (var->red.length == 6) {
654 if (var->transp.length != 0)
655 data |= WINCON1_BPPMODE_19BPP_A1666;
656 else
657 data |= WINCON1_BPPMODE_18BPP_666;
InKi Dae39000d62009-06-16 15:34:27 -0700658 } else if (var->transp.length == 1)
659 data |= WINCON1_BPPMODE_25BPP_A1888
660 | WINCON1_BLD_PIX;
Jingoo Han4420dd22011-11-07 15:03:01 +0900661 else if ((var->transp.length == 4) ||
662 (var->transp.length == 8))
InKi Dae39000d62009-06-16 15:34:27 -0700663 data |= WINCON1_BPPMODE_28BPP_A4888
664 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
Ben Dooksec549a02009-03-31 15:25:39 -0700665 else
666 data |= WINCON0_BPPMODE_24BPP_888;
667
InKi Daedc8498c2010-08-10 18:02:32 -0700668 data |= WINCONx_WSWP;
Ben Dooksec549a02009-03-31 15:25:39 -0700669 data |= WINCONx_BURSTLEN_16WORD;
670 break;
671 }
672
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700673 /* Enable the colour keying for the window below this one */
InKi Dae39000d62009-06-16 15:34:27 -0700674 if (win_no > 0) {
675 u32 keycon0_data = 0, keycon1_data = 0;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700676 void __iomem *keycon = regs + sfb->variant.keycon;
InKi Dae39000d62009-06-16 15:34:27 -0700677
678 keycon0_data = ~(WxKEYCON0_KEYBL_EN |
679 WxKEYCON0_KEYEN_F |
680 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
681
682 keycon1_data = WxKEYCON1_COLVAL(0xffffff);
683
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700684 keycon += (win_no - 1) * 8;
685
686 writel(keycon0_data, keycon + WKEYCON0);
687 writel(keycon1_data, keycon + WKEYCON1);
InKi Dae39000d62009-06-16 15:34:27 -0700688 }
689
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700690 writel(data, regs + sfb->variant.wincon + (win_no * 4));
691 writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700692
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700693 shadow_protect_win(win, 0);
694
Mark Brown5751b232011-12-27 14:16:11 +0000695 pm_runtime_put_sync(sfb->dev);
696
Ben Dooksec549a02009-03-31 15:25:39 -0700697 return 0;
698}
699
700/**
701 * s3c_fb_update_palette() - set or schedule a palette update.
702 * @sfb: The hardware information.
703 * @win: The window being updated.
704 * @reg: The palette index being changed.
705 * @value: The computed palette value.
706 *
707 * Change the value of a palette register, either by directly writing to
708 * the palette (this requires the palette RAM to be disconnected from the
709 * hardware whilst this is in progress) or schedule the update for later.
710 *
711 * At the moment, since we have no VSYNC interrupt support, we simply set
712 * the palette entry directly.
713 */
714static void s3c_fb_update_palette(struct s3c_fb *sfb,
715 struct s3c_fb_win *win,
716 unsigned int reg,
717 u32 value)
718{
719 void __iomem *palreg;
720 u32 palcon;
721
Ben Dooks50a55032010-08-10 18:02:33 -0700722 palreg = sfb->regs + sfb->variant.palette[win->index];
Ben Dooksec549a02009-03-31 15:25:39 -0700723
724 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
725 __func__, win->index, reg, palreg, value);
726
727 win->palette_buffer[reg] = value;
728
729 palcon = readl(sfb->regs + WPALCON);
730 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
731
Ben Dooks50a55032010-08-10 18:02:33 -0700732 if (win->variant.palette_16bpp)
733 writew(value, palreg + (reg * 2));
Ben Dooksec549a02009-03-31 15:25:39 -0700734 else
Ben Dooks50a55032010-08-10 18:02:33 -0700735 writel(value, palreg + (reg * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700736
737 writel(palcon, sfb->regs + WPALCON);
738}
739
740static inline unsigned int chan_to_field(unsigned int chan,
741 struct fb_bitfield *bf)
742{
743 chan &= 0xffff;
744 chan >>= 16 - bf->length;
745 return chan << bf->offset;
746}
747
748/**
749 * s3c_fb_setcolreg() - framebuffer layer request to change palette.
750 * @regno: The palette index to change.
751 * @red: The red field for the palette data.
752 * @green: The green field for the palette data.
753 * @blue: The blue field for the palette data.
754 * @trans: The transparency (alpha) field for the palette data.
755 * @info: The framebuffer being changed.
756 */
757static int s3c_fb_setcolreg(unsigned regno,
758 unsigned red, unsigned green, unsigned blue,
759 unsigned transp, struct fb_info *info)
760{
761 struct s3c_fb_win *win = info->par;
762 struct s3c_fb *sfb = win->parent;
763 unsigned int val;
764
765 dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
766 __func__, win->index, regno, red, green, blue);
767
Mark Brown5751b232011-12-27 14:16:11 +0000768 pm_runtime_get_sync(sfb->dev);
769
Ben Dooksec549a02009-03-31 15:25:39 -0700770 switch (info->fix.visual) {
771 case FB_VISUAL_TRUECOLOR:
772 /* true-colour, use pseudo-palette */
773
774 if (regno < 16) {
775 u32 *pal = info->pseudo_palette;
776
777 val = chan_to_field(red, &info->var.red);
778 val |= chan_to_field(green, &info->var.green);
779 val |= chan_to_field(blue, &info->var.blue);
780
781 pal[regno] = val;
782 }
783 break;
784
785 case FB_VISUAL_PSEUDOCOLOR:
Ben Dooks50a55032010-08-10 18:02:33 -0700786 if (regno < win->variant.palette_sz) {
Ben Dooksec549a02009-03-31 15:25:39 -0700787 val = chan_to_field(red, &win->palette.r);
788 val |= chan_to_field(green, &win->palette.g);
789 val |= chan_to_field(blue, &win->palette.b);
790
791 s3c_fb_update_palette(sfb, win, regno, val);
792 }
793
794 break;
795
796 default:
Mark Brown5751b232011-12-27 14:16:11 +0000797 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700798 return 1; /* unknown type */
799 }
800
Mark Brown5751b232011-12-27 14:16:11 +0000801 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700802 return 0;
803}
804
805/**
Ben Dooksec549a02009-03-31 15:25:39 -0700806 * s3c_fb_blank() - blank or unblank the given window
807 * @blank_mode: The blank state from FB_BLANK_*
808 * @info: The framebuffer to blank.
809 *
810 * Framebuffer layer request to change the power state.
811 */
812static int s3c_fb_blank(int blank_mode, struct fb_info *info)
813{
814 struct s3c_fb_win *win = info->par;
815 struct s3c_fb *sfb = win->parent;
816 unsigned int index = win->index;
817 u32 wincon;
818
819 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
820
Mark Brown5751b232011-12-27 14:16:11 +0000821 pm_runtime_get_sync(sfb->dev);
822
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700823 wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700824
825 switch (blank_mode) {
826 case FB_BLANK_POWERDOWN:
827 wincon &= ~WINCONx_ENWIN;
828 sfb->enabled &= ~(1 << index);
829 /* fall through to FB_BLANK_NORMAL */
830
831 case FB_BLANK_NORMAL:
832 /* disable the DMA and display 0x0 (black) */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900833 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700834 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700835 sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900836 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700837 break;
838
839 case FB_BLANK_UNBLANK:
Jingoo Hanff8c9102011-12-08 18:08:00 +0900840 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700841 writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900842 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700843 wincon |= WINCONx_ENWIN;
844 sfb->enabled |= (1 << index);
845 break;
846
847 case FB_BLANK_VSYNC_SUSPEND:
848 case FB_BLANK_HSYNC_SUSPEND:
849 default:
Mark Brown5751b232011-12-27 14:16:11 +0000850 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700851 return 1;
852 }
853
Jingoo Hanff8c9102011-12-08 18:08:00 +0900854 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700855 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900856 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700857
858 /* Check the enabled state to see if we need to be running the
859 * main LCD interface, as if there are no active windows then
860 * it is highly likely that we also do not need to output
861 * anything.
862 */
863
864 /* We could do something like the following code, but the current
865 * system of using framebuffer events means that we cannot make
866 * the distinction between just window 0 being inactive and all
867 * the windows being down.
868 *
869 * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
870 */
871
872 /* we're stuck with this until we can do something about overriding
873 * the power control using the blanking event for a single fb.
874 */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900875 if (index == sfb->pdata->default_win) {
876 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700877 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
Jingoo Hanff8c9102011-12-08 18:08:00 +0900878 shadow_protect_win(win, 0);
879 }
Ben Dooksec549a02009-03-31 15:25:39 -0700880
Mark Brown5751b232011-12-27 14:16:11 +0000881 pm_runtime_put_sync(sfb->dev);
882
Ben Dooksec549a02009-03-31 15:25:39 -0700883 return 0;
884}
885
Pawel Osciak067b2262010-08-10 18:02:38 -0700886/**
887 * s3c_fb_pan_display() - Pan the display.
888 *
889 * Note that the offsets can be written to the device at any time, as their
890 * values are latched at each vsync automatically. This also means that only
891 * the last call to this function will have any effect on next vsync, but
892 * there is no need to sleep waiting for it to prevent tearing.
893 *
894 * @var: The screen information to verify.
895 * @info: The framebuffer device.
896 */
897static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
898 struct fb_info *info)
899{
900 struct s3c_fb_win *win = info->par;
901 struct s3c_fb *sfb = win->parent;
902 void __iomem *buf = sfb->regs + win->index * 8;
903 unsigned int start_boff, end_boff;
904
Mark Brown5751b232011-12-27 14:16:11 +0000905 pm_runtime_get_sync(sfb->dev);
906
Pawel Osciak067b2262010-08-10 18:02:38 -0700907 /* Offset in bytes to the start of the displayed area */
908 start_boff = var->yoffset * info->fix.line_length;
909 /* X offset depends on the current bpp */
910 if (info->var.bits_per_pixel >= 8) {
911 start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
912 } else {
913 switch (info->var.bits_per_pixel) {
914 case 4:
915 start_boff += var->xoffset >> 1;
916 break;
917 case 2:
918 start_boff += var->xoffset >> 2;
919 break;
920 case 1:
921 start_boff += var->xoffset >> 3;
922 break;
923 default:
924 dev_err(sfb->dev, "invalid bpp\n");
Mark Brown5751b232011-12-27 14:16:11 +0000925 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700926 return -EINVAL;
927 }
928 }
929 /* Offset in bytes to the end of the displayed area */
Laurent Pinchartd8e7a742011-05-25 11:34:52 +0200930 end_boff = start_boff + info->var.yres * info->fix.line_length;
Pawel Osciak067b2262010-08-10 18:02:38 -0700931
932 /* Temporarily turn off per-vsync update from shadow registers until
933 * both start and end addresses are updated to prevent corruption */
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700934 shadow_protect_win(win, 1);
Pawel Osciak067b2262010-08-10 18:02:38 -0700935
936 writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
937 writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
938
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700939 shadow_protect_win(win, 0);
Pawel Osciak067b2262010-08-10 18:02:38 -0700940
Mark Brown5751b232011-12-27 14:16:11 +0000941 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700942 return 0;
943}
944
Pawel Osciakefdc8462010-08-10 18:02:38 -0700945/**
946 * s3c_fb_enable_irq() - enable framebuffer interrupts
947 * @sfb: main hardware state
948 */
949static void s3c_fb_enable_irq(struct s3c_fb *sfb)
950{
951 void __iomem *regs = sfb->regs;
952 u32 irq_ctrl_reg;
953
954 if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
955 /* IRQ disabled, enable it */
956 irq_ctrl_reg = readl(regs + VIDINTCON0);
957
958 irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
959 irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
960
961 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
962 irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
963 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
964 irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
965
966 writel(irq_ctrl_reg, regs + VIDINTCON0);
967 }
968}
969
970/**
971 * s3c_fb_disable_irq() - disable framebuffer interrupts
972 * @sfb: main hardware state
973 */
974static void s3c_fb_disable_irq(struct s3c_fb *sfb)
975{
976 void __iomem *regs = sfb->regs;
977 u32 irq_ctrl_reg;
978
979 if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
980 /* IRQ enabled, disable it */
981 irq_ctrl_reg = readl(regs + VIDINTCON0);
982
983 irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
984 irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
985
986 writel(irq_ctrl_reg, regs + VIDINTCON0);
987 }
988}
989
990static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
991{
992 struct s3c_fb *sfb = dev_id;
993 void __iomem *regs = sfb->regs;
994 u32 irq_sts_reg;
995
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000996 spin_lock(&sfb->slock);
997
Pawel Osciakefdc8462010-08-10 18:02:38 -0700998 irq_sts_reg = readl(regs + VIDINTCON1);
999
1000 if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
1001
1002 /* VSYNC interrupt, accept it */
1003 writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
1004
1005 sfb->vsync_info.count++;
1006 wake_up_interruptible(&sfb->vsync_info.wait);
1007 }
1008
1009 /* We only support waiting for VSYNC for now, so it's safe
1010 * to always disable irqs here.
1011 */
1012 s3c_fb_disable_irq(sfb);
1013
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001014 spin_unlock(&sfb->slock);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001015 return IRQ_HANDLED;
1016}
1017
1018/**
1019 * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
1020 * @sfb: main hardware state
1021 * @crtc: head index.
1022 */
1023static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
1024{
1025 unsigned long count;
1026 int ret;
1027
1028 if (crtc != 0)
1029 return -ENODEV;
1030
Mark Brown5751b232011-12-27 14:16:11 +00001031 pm_runtime_get_sync(sfb->dev);
1032
Pawel Osciakefdc8462010-08-10 18:02:38 -07001033 count = sfb->vsync_info.count;
1034 s3c_fb_enable_irq(sfb);
1035 ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
1036 count != sfb->vsync_info.count,
1037 msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
Mark Brown5751b232011-12-27 14:16:11 +00001038
1039 pm_runtime_put_sync(sfb->dev);
1040
Pawel Osciakefdc8462010-08-10 18:02:38 -07001041 if (ret == 0)
1042 return -ETIMEDOUT;
1043
1044 return 0;
1045}
1046
1047static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
1048 unsigned long arg)
1049{
1050 struct s3c_fb_win *win = info->par;
1051 struct s3c_fb *sfb = win->parent;
1052 int ret;
1053 u32 crtc;
1054
1055 switch (cmd) {
1056 case FBIO_WAITFORVSYNC:
1057 if (get_user(crtc, (u32 __user *)arg)) {
1058 ret = -EFAULT;
1059 break;
1060 }
1061
1062 ret = s3c_fb_wait_for_vsync(sfb, crtc);
1063 break;
1064 default:
1065 ret = -ENOTTY;
1066 }
1067
1068 return ret;
1069}
1070
Ben Dooksec549a02009-03-31 15:25:39 -07001071static struct fb_ops s3c_fb_ops = {
1072 .owner = THIS_MODULE,
1073 .fb_check_var = s3c_fb_check_var,
1074 .fb_set_par = s3c_fb_set_par,
1075 .fb_blank = s3c_fb_blank,
1076 .fb_setcolreg = s3c_fb_setcolreg,
1077 .fb_fillrect = cfb_fillrect,
1078 .fb_copyarea = cfb_copyarea,
1079 .fb_imageblit = cfb_imageblit,
Pawel Osciak067b2262010-08-10 18:02:38 -07001080 .fb_pan_display = s3c_fb_pan_display,
Pawel Osciakefdc8462010-08-10 18:02:38 -07001081 .fb_ioctl = s3c_fb_ioctl,
Ben Dooksec549a02009-03-31 15:25:39 -07001082};
1083
1084/**
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001085 * s3c_fb_missing_pixclock() - calculates pixel clock
1086 * @mode: The video mode to change.
1087 *
1088 * Calculate the pixel clock when none has been given through platform data.
1089 */
1090static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
1091{
1092 u64 pixclk = 1000000000000ULL;
1093 u32 div;
1094
1095 div = mode->left_margin + mode->hsync_len + mode->right_margin +
1096 mode->xres;
1097 div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
1098 mode->yres;
1099 div *= mode->refresh ? : 60;
1100
1101 do_div(pixclk, div);
1102
1103 mode->pixclock = pixclk;
1104}
1105
1106/**
Ben Dooksec549a02009-03-31 15:25:39 -07001107 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
1108 * @sfb: The base resources for the hardware.
1109 * @win: The window to initialise memory for.
1110 *
1111 * Allocate memory for the given framebuffer.
1112 */
1113static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
1114 struct s3c_fb_win *win)
1115{
1116 struct s3c_fb_pd_win *windata = win->windata;
1117 unsigned int real_size, virt_size, size;
1118 struct fb_info *fbi = win->fbinfo;
1119 dma_addr_t map_dma;
1120
1121 dev_dbg(sfb->dev, "allocating memory for display\n");
1122
1123 real_size = windata->win_mode.xres * windata->win_mode.yres;
1124 virt_size = windata->virtual_x * windata->virtual_y;
1125
1126 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
1127 real_size, windata->win_mode.xres, windata->win_mode.yres,
1128 virt_size, windata->virtual_x, windata->virtual_y);
1129
1130 size = (real_size > virt_size) ? real_size : virt_size;
1131 size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
1132 size /= 8;
1133
1134 fbi->fix.smem_len = size;
1135 size = PAGE_ALIGN(size);
1136
1137 dev_dbg(sfb->dev, "want %u bytes for window\n", size);
1138
1139 fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
1140 &map_dma, GFP_KERNEL);
1141 if (!fbi->screen_base)
1142 return -ENOMEM;
1143
1144 dev_dbg(sfb->dev, "mapped %x to %p\n",
1145 (unsigned int)map_dma, fbi->screen_base);
1146
1147 memset(fbi->screen_base, 0x0, size);
1148 fbi->fix.smem_start = map_dma;
1149
1150 return 0;
1151}
1152
1153/**
1154 * s3c_fb_free_memory() - free the display memory for the given window
1155 * @sfb: The base resources for the hardware.
1156 * @win: The window to free the display memory for.
1157 *
1158 * Free the display memory allocated by s3c_fb_alloc_memory().
1159 */
1160static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
1161{
1162 struct fb_info *fbi = win->fbinfo;
1163
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001164 if (fbi->screen_base)
1165 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
Ben Dooksec549a02009-03-31 15:25:39 -07001166 fbi->screen_base, fbi->fix.smem_start);
1167}
1168
1169/**
1170 * s3c_fb_release_win() - release resources for a framebuffer window.
1171 * @win: The window to cleanup the resources for.
1172 *
1173 * Release the resources that where claimed for the hardware window,
1174 * such as the framebuffer instance and any memory claimed for it.
1175 */
1176static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
1177{
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001178 u32 data;
1179
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001180 if (win->fbinfo) {
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001181 if (sfb->variant.has_shadowcon) {
1182 data = readl(sfb->regs + SHADOWCON);
1183 data &= ~SHADOWCON_CHx_ENABLE(win->index);
1184 data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
1185 writel(data, sfb->regs + SHADOWCON);
1186 }
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001187 unregister_framebuffer(win->fbinfo);
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001188 if (win->fbinfo->cmap.len)
1189 fb_dealloc_cmap(&win->fbinfo->cmap);
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001190 s3c_fb_free_memory(sfb, win);
1191 framebuffer_release(win->fbinfo);
1192 }
Ben Dooksec549a02009-03-31 15:25:39 -07001193}
1194
1195/**
1196 * s3c_fb_probe_win() - register an hardware window
1197 * @sfb: The base resources for the hardware
Ben Dooks50a55032010-08-10 18:02:33 -07001198 * @variant: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -07001199 * @res: Pointer to where to place the resultant window.
1200 *
1201 * Allocate and do the basic initialisation for one of the hardware's graphics
1202 * windows.
1203 */
1204static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
Ben Dooks50a55032010-08-10 18:02:33 -07001205 struct s3c_fb_win_variant *variant,
Ben Dooksec549a02009-03-31 15:25:39 -07001206 struct s3c_fb_win **res)
1207{
1208 struct fb_var_screeninfo *var;
1209 struct fb_videomode *initmode;
1210 struct s3c_fb_pd_win *windata;
1211 struct s3c_fb_win *win;
1212 struct fb_info *fbinfo;
1213 int palette_size;
1214 int ret;
1215
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001216 dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
Ben Dooksec549a02009-03-31 15:25:39 -07001217
Pawel Osciakefdc8462010-08-10 18:02:38 -07001218 init_waitqueue_head(&sfb->vsync_info.wait);
1219
Ben Dooks50a55032010-08-10 18:02:33 -07001220 palette_size = variant->palette_sz * 4;
Ben Dooksec549a02009-03-31 15:25:39 -07001221
1222 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
1223 palette_size * sizeof(u32), sfb->dev);
1224 if (!fbinfo) {
1225 dev_err(sfb->dev, "failed to allocate framebuffer\n");
1226 return -ENOENT;
1227 }
1228
1229 windata = sfb->pdata->win[win_no];
1230 initmode = &windata->win_mode;
1231
1232 WARN_ON(windata->max_bpp == 0);
1233 WARN_ON(windata->win_mode.xres == 0);
1234 WARN_ON(windata->win_mode.yres == 0);
1235
1236 win = fbinfo->par;
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001237 *res = win;
Ben Dooksec549a02009-03-31 15:25:39 -07001238 var = &fbinfo->var;
Ben Dooks50a55032010-08-10 18:02:33 -07001239 win->variant = *variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001240 win->fbinfo = fbinfo;
1241 win->parent = sfb;
1242 win->windata = windata;
1243 win->index = win_no;
1244 win->palette_buffer = (u32 *)(win + 1);
1245
1246 ret = s3c_fb_alloc_memory(sfb, win);
1247 if (ret) {
1248 dev_err(sfb->dev, "failed to allocate display memory\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001249 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001250 }
1251
1252 /* setup the r/b/g positions for the window's palette */
Ben Dooksbc2da1b2010-08-10 18:02:34 -07001253 if (win->variant.palette_16bpp) {
1254 /* Set RGB 5:6:5 as default */
1255 win->palette.r.offset = 11;
1256 win->palette.r.length = 5;
1257 win->palette.g.offset = 5;
1258 win->palette.g.length = 6;
1259 win->palette.b.offset = 0;
1260 win->palette.b.length = 5;
1261
1262 } else {
1263 /* Set 8bpp or 8bpp and 1bit alpha */
1264 win->palette.r.offset = 16;
1265 win->palette.r.length = 8;
1266 win->palette.g.offset = 8;
1267 win->palette.g.length = 8;
1268 win->palette.b.offset = 0;
1269 win->palette.b.length = 8;
1270 }
Ben Dooksec549a02009-03-31 15:25:39 -07001271
1272 /* setup the initial video mode from the window */
1273 fb_videomode_to_var(&fbinfo->var, initmode);
1274
1275 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
1276 fbinfo->fix.accel = FB_ACCEL_NONE;
1277 fbinfo->var.activate = FB_ACTIVATE_NOW;
1278 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
1279 fbinfo->var.bits_per_pixel = windata->default_bpp;
1280 fbinfo->fbops = &s3c_fb_ops;
1281 fbinfo->flags = FBINFO_FLAG_DEFAULT;
1282 fbinfo->pseudo_palette = &win->pseudo_palette;
1283
1284 /* prepare to actually start the framebuffer */
1285
1286 ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
1287 if (ret < 0) {
1288 dev_err(sfb->dev, "check_var failed on initial video params\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001289 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001290 }
1291
1292 /* create initial colour map */
1293
Ben Dooks50a55032010-08-10 18:02:33 -07001294 ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
Ben Dooksec549a02009-03-31 15:25:39 -07001295 if (ret == 0)
1296 fb_set_cmap(&fbinfo->cmap, fbinfo);
1297 else
1298 dev_err(sfb->dev, "failed to allocate fb cmap\n");
1299
1300 s3c_fb_set_par(fbinfo);
1301
1302 dev_dbg(sfb->dev, "about to register framebuffer\n");
1303
1304 /* run the check_var and set_par on our configuration. */
1305
1306 ret = register_framebuffer(fbinfo);
1307 if (ret < 0) {
1308 dev_err(sfb->dev, "failed to register framebuffer\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001309 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001310 }
1311
Ben Dooksec549a02009-03-31 15:25:39 -07001312 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
1313
1314 return 0;
Ben Dooksec549a02009-03-31 15:25:39 -07001315}
1316
1317/**
1318 * s3c_fb_clear_win() - clear hardware window registers.
1319 * @sfb: The base resources for the hardware.
1320 * @win: The window to process.
1321 *
1322 * Reset the specific window registers to a known state.
1323 */
1324static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
1325{
1326 void __iomem *regs = sfb->regs;
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001327 u32 reg;
Ben Dooksec549a02009-03-31 15:25:39 -07001328
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001329 writel(0, regs + sfb->variant.wincon + (win * 4));
1330 writel(0, regs + VIDOSD_A(win, sfb->variant));
1331 writel(0, regs + VIDOSD_B(win, sfb->variant));
1332 writel(0, regs + VIDOSD_C(win, sfb->variant));
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001333 reg = readl(regs + SHADOWCON);
1334 writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
Ben Dooksec549a02009-03-31 15:25:39 -07001335}
1336
1337static int __devinit s3c_fb_probe(struct platform_device *pdev)
1338{
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001339 const struct platform_device_id *platid;
Ben Dooks50a55032010-08-10 18:02:33 -07001340 struct s3c_fb_driverdata *fbdrv;
Ben Dooksec549a02009-03-31 15:25:39 -07001341 struct device *dev = &pdev->dev;
1342 struct s3c_fb_platdata *pd;
1343 struct s3c_fb *sfb;
1344 struct resource *res;
1345 int win;
1346 int ret = 0;
1347
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001348 platid = platform_get_device_id(pdev);
1349 fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
Ben Dooks50a55032010-08-10 18:02:33 -07001350
1351 if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
1352 dev_err(dev, "too many windows, cannot attach\n");
1353 return -EINVAL;
1354 }
1355
Ben Dooksec549a02009-03-31 15:25:39 -07001356 pd = pdev->dev.platform_data;
1357 if (!pd) {
1358 dev_err(dev, "no platform data specified\n");
1359 return -EINVAL;
1360 }
1361
Mark Brown857a8df2012-01-21 13:11:49 +00001362 sfb = devm_kzalloc(dev, sizeof(struct s3c_fb), GFP_KERNEL);
Ben Dooksec549a02009-03-31 15:25:39 -07001363 if (!sfb) {
1364 dev_err(dev, "no memory for framebuffers\n");
1365 return -ENOMEM;
1366 }
1367
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001368 dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
1369
Ben Dooksec549a02009-03-31 15:25:39 -07001370 sfb->dev = dev;
1371 sfb->pdata = pd;
Ben Dooks50a55032010-08-10 18:02:33 -07001372 sfb->variant = fbdrv->variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001373
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001374 spin_lock_init(&sfb->slock);
1375
Ben Dooksec549a02009-03-31 15:25:39 -07001376 sfb->bus_clk = clk_get(dev, "lcd");
1377 if (IS_ERR(sfb->bus_clk)) {
1378 dev_err(dev, "failed to get bus clock\n");
axel lin942b8d02011-02-11 08:51:10 +00001379 ret = PTR_ERR(sfb->bus_clk);
Ben Dooksec549a02009-03-31 15:25:39 -07001380 goto err_sfb;
1381 }
1382
1383 clk_enable(sfb->bus_clk);
1384
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001385 if (!sfb->variant.has_clksel) {
1386 sfb->lcd_clk = clk_get(dev, "sclk_fimd");
1387 if (IS_ERR(sfb->lcd_clk)) {
1388 dev_err(dev, "failed to get lcd clock\n");
1389 ret = PTR_ERR(sfb->lcd_clk);
1390 goto err_bus_clk;
1391 }
1392
1393 clk_enable(sfb->lcd_clk);
1394 }
1395
Jingoo Han49592122010-12-17 16:45:46 +09001396 pm_runtime_enable(sfb->dev);
1397
Ben Dooksec549a02009-03-31 15:25:39 -07001398 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1399 if (!res) {
1400 dev_err(dev, "failed to find registers\n");
1401 ret = -ENOENT;
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001402 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001403 }
1404
Mark Brown857a8df2012-01-21 13:11:49 +00001405 sfb->regs = devm_request_and_ioremap(dev, res);
Ben Dooksec549a02009-03-31 15:25:39 -07001406 if (!sfb->regs) {
1407 dev_err(dev, "failed to map registers\n");
1408 ret = -ENXIO;
Mark Brown857a8df2012-01-21 13:11:49 +00001409 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001410 }
1411
Pawel Osciakefdc8462010-08-10 18:02:38 -07001412 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1413 if (!res) {
1414 dev_err(dev, "failed to acquire irq resource\n");
1415 ret = -ENOENT;
Mark Brown857a8df2012-01-21 13:11:49 +00001416 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001417 }
1418 sfb->irq_no = res->start;
1419 ret = request_irq(sfb->irq_no, s3c_fb_irq,
1420 0, "s3c_fb", sfb);
1421 if (ret) {
1422 dev_err(dev, "irq request failed\n");
Mark Brown857a8df2012-01-21 13:11:49 +00001423 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001424 }
1425
Ben Dooksec549a02009-03-31 15:25:39 -07001426 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
1427
Jingoo Han49592122010-12-17 16:45:46 +09001428 platform_set_drvdata(pdev, sfb);
1429 pm_runtime_get_sync(sfb->dev);
1430
Ben Dooksec549a02009-03-31 15:25:39 -07001431 /* setup gpio and output polarity controls */
1432
1433 pd->setup_gpio();
1434
1435 writel(pd->vidcon1, sfb->regs + VIDCON1);
1436
1437 /* zero all windows before we do anything */
1438
Ben Dooks50a55032010-08-10 18:02:33 -07001439 for (win = 0; win < fbdrv->variant.nr_windows; win++)
Ben Dooksec549a02009-03-31 15:25:39 -07001440 s3c_fb_clear_win(sfb, win);
1441
Ben Dooks94947032010-08-10 18:02:32 -07001442 /* initialise colour key controls */
Ben Dooks50a55032010-08-10 18:02:33 -07001443 for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001444 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1445
1446 regs += (win * 8);
1447 writel(0xffffff, regs + WKEYCON0);
1448 writel(0xffffff, regs + WKEYCON1);
Ben Dooks94947032010-08-10 18:02:32 -07001449 }
1450
Ben Dooksec549a02009-03-31 15:25:39 -07001451 /* we have the register setup, start allocating framebuffers */
1452
Ben Dooks50a55032010-08-10 18:02:33 -07001453 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
Ben Dooksec549a02009-03-31 15:25:39 -07001454 if (!pd->win[win])
1455 continue;
1456
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001457 if (!pd->win[win]->win_mode.pixclock)
1458 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1459
Ben Dooks50a55032010-08-10 18:02:33 -07001460 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1461 &sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001462 if (ret < 0) {
1463 dev_err(dev, "failed to create window %d\n", win);
1464 for (; win >= 0; win--)
1465 s3c_fb_release_win(sfb, sfb->windows[win]);
Mark Brown3500b0b2011-12-27 14:16:09 +00001466 goto err_pm_runtime;
Ben Dooksec549a02009-03-31 15:25:39 -07001467 }
1468 }
1469
1470 platform_set_drvdata(pdev, sfb);
Mark Brownfe05f8b2011-12-27 14:16:07 +00001471 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001472
1473 return 0;
1474
Mark Brown3500b0b2011-12-27 14:16:09 +00001475err_pm_runtime:
1476 pm_runtime_put_sync(sfb->dev);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001477 free_irq(sfb->irq_no, sfb);
1478
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001479err_lcd_clk:
Mark Brown3500b0b2011-12-27 14:16:09 +00001480 pm_runtime_disable(sfb->dev);
1481
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001482 if (!sfb->variant.has_clksel) {
1483 clk_disable(sfb->lcd_clk);
1484 clk_put(sfb->lcd_clk);
1485 }
1486
1487err_bus_clk:
Ben Dooksec549a02009-03-31 15:25:39 -07001488 clk_disable(sfb->bus_clk);
1489 clk_put(sfb->bus_clk);
1490
1491err_sfb:
Ben Dooksec549a02009-03-31 15:25:39 -07001492 return ret;
1493}
1494
1495/**
1496 * s3c_fb_remove() - Cleanup on module finalisation
1497 * @pdev: The platform device we are bound to.
1498 *
1499 * Shutdown and then release all the resources that the driver allocated
1500 * on initialisation.
1501 */
1502static int __devexit s3c_fb_remove(struct platform_device *pdev)
1503{
1504 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1505 int win;
1506
Mark Brownfe05f8b2011-12-27 14:16:07 +00001507 pm_runtime_get_sync(sfb->dev);
1508
Pawel Osciakc42b1102009-07-29 15:02:10 -07001509 for (win = 0; win < S3C_FB_MAX_WIN; win++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001510 if (sfb->windows[win])
1511 s3c_fb_release_win(sfb, sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001512
Pawel Osciakefdc8462010-08-10 18:02:38 -07001513 free_irq(sfb->irq_no, sfb);
1514
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001515 if (!sfb->variant.has_clksel) {
1516 clk_disable(sfb->lcd_clk);
1517 clk_put(sfb->lcd_clk);
1518 }
1519
Ben Dooksec549a02009-03-31 15:25:39 -07001520 clk_disable(sfb->bus_clk);
1521 clk_put(sfb->bus_clk);
1522
Jingoo Han49592122010-12-17 16:45:46 +09001523 pm_runtime_put_sync(sfb->dev);
1524 pm_runtime_disable(sfb->dev);
1525
Ben Dooksec549a02009-03-31 15:25:39 -07001526 return 0;
1527}
1528
Mark Brownf4f51472011-12-27 14:16:10 +00001529#ifdef CONFIG_PM_SLEEP
Jingoo Han49592122010-12-17 16:45:46 +09001530static int s3c_fb_suspend(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001531{
Jingoo Han49592122010-12-17 16:45:46 +09001532 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001533 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1534 struct s3c_fb_win *win;
1535 int win_no;
1536
Pawel Osciakc42b1102009-07-29 15:02:10 -07001537 for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
Ben Dooksec549a02009-03-31 15:25:39 -07001538 win = sfb->windows[win_no];
1539 if (!win)
1540 continue;
1541
1542 /* use the blank function to push into power-down */
1543 s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
1544 }
1545
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001546 if (!sfb->variant.has_clksel)
1547 clk_disable(sfb->lcd_clk);
1548
Ben Dooksec549a02009-03-31 15:25:39 -07001549 clk_disable(sfb->bus_clk);
1550 return 0;
1551}
1552
Jingoo Han49592122010-12-17 16:45:46 +09001553static int s3c_fb_resume(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001554{
Jingoo Han49592122010-12-17 16:45:46 +09001555 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001556 struct s3c_fb *sfb = platform_get_drvdata(pdev);
Marek Szyprowski17663e52009-05-28 14:34:35 -07001557 struct s3c_fb_platdata *pd = sfb->pdata;
Ben Dooksec549a02009-03-31 15:25:39 -07001558 struct s3c_fb_win *win;
1559 int win_no;
1560
1561 clk_enable(sfb->bus_clk);
1562
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001563 if (!sfb->variant.has_clksel)
1564 clk_enable(sfb->lcd_clk);
1565
Jingoo Han6aa96812011-05-24 08:55:31 +00001566 /* setup gpio and output polarity controls */
1567 pd->setup_gpio();
Marek Szyprowski17663e52009-05-28 14:34:35 -07001568 writel(pd->vidcon1, sfb->regs + VIDCON1);
1569
1570 /* zero all windows before we do anything */
Ben Dooks50a55032010-08-10 18:02:33 -07001571 for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001572 s3c_fb_clear_win(sfb, win_no);
1573
Ben Dooks50a55032010-08-10 18:02:33 -07001574 for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001575 void __iomem *regs = sfb->regs + sfb->variant.keycon;
Jingoo Hanff8c9102011-12-08 18:08:00 +09001576 win = sfb->windows[win_no];
1577 if (!win)
1578 continue;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001579
Jingoo Hanff8c9102011-12-08 18:08:00 +09001580 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001581 regs += (win_no * 8);
1582 writel(0xffffff, regs + WKEYCON0);
1583 writel(0xffffff, regs + WKEYCON1);
Jingoo Hanff8c9102011-12-08 18:08:00 +09001584 shadow_protect_win(win, 0);
Ben Dooks94947032010-08-10 18:02:32 -07001585 }
1586
Marek Szyprowski17663e52009-05-28 14:34:35 -07001587 /* restore framebuffers */
Ben Dooksec549a02009-03-31 15:25:39 -07001588 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1589 win = sfb->windows[win_no];
1590 if (!win)
1591 continue;
1592
1593 dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
1594 s3c_fb_set_par(win->fbinfo);
1595 }
1596
1597 return 0;
1598}
Ben Dooksec549a02009-03-31 15:25:39 -07001599#endif
1600
Mark Brownf4f51472011-12-27 14:16:10 +00001601#ifdef CONFIG_PM_RUNTIME
1602static int s3c_fb_runtime_suspend(struct device *dev)
1603{
1604 struct platform_device *pdev = to_platform_device(dev);
1605 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1606
1607 if (!sfb->variant.has_clksel)
1608 clk_disable(sfb->lcd_clk);
1609
1610 clk_disable(sfb->bus_clk);
1611
1612 return 0;
1613}
1614
1615static int s3c_fb_runtime_resume(struct device *dev)
1616{
1617 struct platform_device *pdev = to_platform_device(dev);
1618 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1619 struct s3c_fb_platdata *pd = sfb->pdata;
1620
1621 clk_enable(sfb->bus_clk);
1622
1623 if (!sfb->variant.has_clksel)
1624 clk_enable(sfb->lcd_clk);
1625
1626 /* setup gpio and output polarity controls */
1627 pd->setup_gpio();
1628 writel(pd->vidcon1, sfb->regs + VIDCON1);
1629
1630 return 0;
1631}
1632#endif
Ben Dooks50a55032010-08-10 18:02:33 -07001633
1634#define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
1635#define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
1636
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001637static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
Ben Dooks50a55032010-08-10 18:02:33 -07001638 [0] = {
1639 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001640 .osd_size_off = 0x8,
Ben Dooks50a55032010-08-10 18:02:33 -07001641 .palette_sz = 256,
Jingoo Hancd74eba2011-04-22 07:09:40 +00001642 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1643 VALID_BPP(18) | VALID_BPP(24)),
Ben Dooks50a55032010-08-10 18:02:33 -07001644 },
1645 [1] = {
1646 .has_osd_c = 1,
1647 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001648 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001649 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001650 .palette_sz = 256,
1651 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1652 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001653 VALID_BPP(24) | VALID_BPP(25) |
1654 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001655 },
1656 [2] = {
1657 .has_osd_c = 1,
1658 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001659 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001660 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001661 .palette_sz = 16,
1662 .palette_16bpp = 1,
1663 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1664 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001665 VALID_BPP(24) | VALID_BPP(25) |
1666 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001667 },
1668 [3] = {
1669 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001670 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001671 .palette_sz = 16,
1672 .palette_16bpp = 1,
1673 .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
1674 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001675 VALID_BPP(24) | VALID_BPP(25) |
1676 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001677 },
1678 [4] = {
1679 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001680 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001681 .palette_sz = 4,
1682 .palette_16bpp = 1,
1683 .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
1684 VALID_BPP(16) | VALID_BPP(18) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001685 VALID_BPP(19) | VALID_BPP(24) |
1686 VALID_BPP(25) | VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001687 },
1688};
1689
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001690static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
1691 [0] = {
1692 .has_osd_c = 1,
1693 .osd_size_off = 0x8,
1694 .palette_sz = 256,
1695 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1696 VALID_BPP(15) | VALID_BPP(16) |
1697 VALID_BPP(18) | VALID_BPP(19) |
1698 VALID_BPP(24) | VALID_BPP(25) |
1699 VALID_BPP(32)),
1700 },
1701 [1] = {
1702 .has_osd_c = 1,
1703 .has_osd_d = 1,
1704 .osd_size_off = 0xc,
1705 .has_osd_alpha = 1,
1706 .palette_sz = 256,
1707 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1708 VALID_BPP(15) | VALID_BPP(16) |
1709 VALID_BPP(18) | VALID_BPP(19) |
1710 VALID_BPP(24) | VALID_BPP(25) |
1711 VALID_BPP(32)),
1712 },
1713 [2] = {
1714 .has_osd_c = 1,
1715 .has_osd_d = 1,
1716 .osd_size_off = 0xc,
1717 .has_osd_alpha = 1,
1718 .palette_sz = 256,
1719 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1720 VALID_BPP(15) | VALID_BPP(16) |
1721 VALID_BPP(18) | VALID_BPP(19) |
1722 VALID_BPP(24) | VALID_BPP(25) |
1723 VALID_BPP(32)),
1724 },
1725 [3] = {
1726 .has_osd_c = 1,
1727 .has_osd_alpha = 1,
1728 .palette_sz = 256,
1729 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1730 VALID_BPP(15) | VALID_BPP(16) |
1731 VALID_BPP(18) | VALID_BPP(19) |
1732 VALID_BPP(24) | VALID_BPP(25) |
1733 VALID_BPP(32)),
1734 },
1735 [4] = {
1736 .has_osd_c = 1,
1737 .has_osd_alpha = 1,
1738 .palette_sz = 256,
1739 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1740 VALID_BPP(15) | VALID_BPP(16) |
1741 VALID_BPP(18) | VALID_BPP(19) |
1742 VALID_BPP(24) | VALID_BPP(25) |
1743 VALID_BPP(32)),
1744 },
1745};
1746
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001747static struct s3c_fb_driverdata s3c_fb_data_64xx = {
Ben Dooks50a55032010-08-10 18:02:33 -07001748 .variant = {
1749 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001750 .vidtcon = VIDTCON0,
1751 .wincon = WINCON(0),
1752 .winmap = WINxMAP(0),
1753 .keycon = WKEYCON,
1754 .osd = VIDOSD_BASE,
1755 .osd_stride = 16,
1756 .buf_start = VIDW_BUF_START(0),
1757 .buf_size = VIDW_BUF_SIZE(0),
1758 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001759
1760 .palette = {
1761 [0] = 0x400,
1762 [1] = 0x800,
1763 [2] = 0x300,
1764 [3] = 0x320,
1765 [4] = 0x340,
1766 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001767
1768 .has_prtcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001769 .has_clksel = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001770 },
1771 .win[0] = &s3c_fb_data_64xx_wins[0],
1772 .win[1] = &s3c_fb_data_64xx_wins[1],
1773 .win[2] = &s3c_fb_data_64xx_wins[2],
1774 .win[3] = &s3c_fb_data_64xx_wins[3],
1775 .win[4] = &s3c_fb_data_64xx_wins[4],
1776};
1777
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001778static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001779 .variant = {
1780 .nr_windows = 5,
1781 .vidtcon = VIDTCON0,
1782 .wincon = WINCON(0),
1783 .winmap = WINxMAP(0),
1784 .keycon = WKEYCON,
1785 .osd = VIDOSD_BASE,
1786 .osd_stride = 16,
1787 .buf_start = VIDW_BUF_START(0),
1788 .buf_size = VIDW_BUF_SIZE(0),
1789 .buf_end = VIDW_BUF_END(0),
1790
1791 .palette = {
1792 [0] = 0x2400,
1793 [1] = 0x2800,
1794 [2] = 0x2c00,
1795 [3] = 0x3000,
1796 [4] = 0x3400,
1797 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001798
1799 .has_prtcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001800 .has_clksel = 1,
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001801 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001802 .win[0] = &s3c_fb_data_s5p_wins[0],
1803 .win[1] = &s3c_fb_data_s5p_wins[1],
1804 .win[2] = &s3c_fb_data_s5p_wins[2],
1805 .win[3] = &s3c_fb_data_s5p_wins[3],
1806 .win[4] = &s3c_fb_data_s5p_wins[4],
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001807};
1808
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001809static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
Ben Dooks50a55032010-08-10 18:02:33 -07001810 .variant = {
1811 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001812 .vidtcon = VIDTCON0,
1813 .wincon = WINCON(0),
1814 .winmap = WINxMAP(0),
1815 .keycon = WKEYCON,
1816 .osd = VIDOSD_BASE,
1817 .osd_stride = 16,
1818 .buf_start = VIDW_BUF_START(0),
1819 .buf_size = VIDW_BUF_SIZE(0),
1820 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001821
1822 .palette = {
1823 [0] = 0x2400,
1824 [1] = 0x2800,
1825 [2] = 0x2c00,
1826 [3] = 0x3000,
1827 [4] = 0x3400,
1828 },
Pawel Osciakf5ec5462010-08-10 18:02:40 -07001829
1830 .has_shadowcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001831 .has_clksel = 1,
1832 },
1833 .win[0] = &s3c_fb_data_s5p_wins[0],
1834 .win[1] = &s3c_fb_data_s5p_wins[1],
1835 .win[2] = &s3c_fb_data_s5p_wins[2],
1836 .win[3] = &s3c_fb_data_s5p_wins[3],
1837 .win[4] = &s3c_fb_data_s5p_wins[4],
1838};
1839
1840static struct s3c_fb_driverdata s3c_fb_data_exynos4 = {
1841 .variant = {
1842 .nr_windows = 5,
1843 .vidtcon = VIDTCON0,
1844 .wincon = WINCON(0),
1845 .winmap = WINxMAP(0),
1846 .keycon = WKEYCON,
1847 .osd = VIDOSD_BASE,
1848 .osd_stride = 16,
1849 .buf_start = VIDW_BUF_START(0),
1850 .buf_size = VIDW_BUF_SIZE(0),
1851 .buf_end = VIDW_BUF_END(0),
1852
1853 .palette = {
1854 [0] = 0x2400,
1855 [1] = 0x2800,
1856 [2] = 0x2c00,
1857 [3] = 0x3000,
1858 [4] = 0x3400,
1859 },
1860
1861 .has_shadowcon = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001862 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001863 .win[0] = &s3c_fb_data_s5p_wins[0],
1864 .win[1] = &s3c_fb_data_s5p_wins[1],
1865 .win[2] = &s3c_fb_data_s5p_wins[2],
1866 .win[3] = &s3c_fb_data_s5p_wins[3],
1867 .win[4] = &s3c_fb_data_s5p_wins[4],
Ben Dooks50a55032010-08-10 18:02:33 -07001868};
1869
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001870/* S3C2443/S3C2416 style hardware */
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001871static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001872 .variant = {
1873 .nr_windows = 2,
1874 .is_2443 = 1,
1875
1876 .vidtcon = 0x08,
1877 .wincon = 0x14,
1878 .winmap = 0xd0,
1879 .keycon = 0xb0,
1880 .osd = 0x28,
1881 .osd_stride = 12,
1882 .buf_start = 0x64,
1883 .buf_size = 0x94,
1884 .buf_end = 0x7c,
1885
1886 .palette = {
1887 [0] = 0x400,
1888 [1] = 0x800,
1889 },
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001890 .has_clksel = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001891 },
1892 .win[0] = &(struct s3c_fb_win_variant) {
1893 .palette_sz = 256,
1894 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1895 },
1896 .win[1] = &(struct s3c_fb_win_variant) {
1897 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001898 .has_osd_alpha = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001899 .palette_sz = 256,
1900 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1901 VALID_BPP(18) | VALID_BPP(19) |
1902 VALID_BPP(24) | VALID_BPP(25) |
1903 VALID_BPP(28)),
1904 },
1905};
1906
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001907static struct s3c_fb_driverdata s3c_fb_data_s5p64x0 = {
1908 .variant = {
1909 .nr_windows = 3,
1910 .vidtcon = VIDTCON0,
1911 .wincon = WINCON(0),
1912 .winmap = WINxMAP(0),
1913 .keycon = WKEYCON,
1914 .osd = VIDOSD_BASE,
1915 .osd_stride = 16,
1916 .buf_start = VIDW_BUF_START(0),
1917 .buf_size = VIDW_BUF_SIZE(0),
1918 .buf_end = VIDW_BUF_END(0),
1919
1920 .palette = {
1921 [0] = 0x2400,
1922 [1] = 0x2800,
1923 [2] = 0x2c00,
1924 },
1925 },
1926 .win[0] = &s3c_fb_data_s5p_wins[0],
1927 .win[1] = &s3c_fb_data_s5p_wins[1],
1928 .win[2] = &s3c_fb_data_s5p_wins[2],
1929};
1930
Ben Dooks50a55032010-08-10 18:02:33 -07001931static struct platform_device_id s3c_fb_driver_ids[] = {
1932 {
1933 .name = "s3c-fb",
1934 .driver_data = (unsigned long)&s3c_fb_data_64xx,
1935 }, {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001936 .name = "s5pc100-fb",
1937 .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
1938 }, {
1939 .name = "s5pv210-fb",
1940 .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001941 }, {
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001942 .name = "exynos4-fb",
1943 .driver_data = (unsigned long)&s3c_fb_data_exynos4,
1944 }, {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001945 .name = "s3c2443-fb",
1946 .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001947 }, {
1948 .name = "s5p64x0-fb",
1949 .driver_data = (unsigned long)&s3c_fb_data_s5p64x0,
Ben Dooks50a55032010-08-10 18:02:33 -07001950 },
1951 {},
1952};
1953MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
1954
Mark Brownf4f51472011-12-27 14:16:10 +00001955static const struct dev_pm_ops s3cfb_pm_ops = {
1956 SET_SYSTEM_SLEEP_PM_OPS(s3c_fb_suspend, s3c_fb_resume)
1957 SET_RUNTIME_PM_OPS(s3c_fb_runtime_suspend, s3c_fb_runtime_resume,
1958 NULL)
1959};
Jingoo Han49592122010-12-17 16:45:46 +09001960
Ben Dooksec549a02009-03-31 15:25:39 -07001961static struct platform_driver s3c_fb_driver = {
1962 .probe = s3c_fb_probe,
Peter Korsgaard3163eaba2009-09-22 16:47:55 -07001963 .remove = __devexit_p(s3c_fb_remove),
Ben Dooks50a55032010-08-10 18:02:33 -07001964 .id_table = s3c_fb_driver_ids,
Ben Dooksec549a02009-03-31 15:25:39 -07001965 .driver = {
1966 .name = "s3c-fb",
1967 .owner = THIS_MODULE,
Mark Brownfe05f8b2011-12-27 14:16:07 +00001968 .pm = &s3cfb_pm_ops,
Ben Dooksec549a02009-03-31 15:25:39 -07001969 },
1970};
1971
Axel Lin4277f2c2011-11-26 10:25:54 +08001972module_platform_driver(s3c_fb_driver);
Ben Dooksec549a02009-03-31 15:25:39 -07001973
1974MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1975MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
1976MODULE_LICENSE("GPL");
1977MODULE_ALIAS("platform:s3c-fb");