blob: 9af6c1849c248d073d1f53812cf6a11bad8d0bcd [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 Hanf7f31e52012-01-27 14:47:22 +090085 * @has_blendcon: Set if has BLENDCON register.
Jingoo Hanb5480ed2011-08-22 12:16:04 +090086 * @has_clksel: Set if VIDCON0 register has CLKSEL bit.
Ben Dooks50a55032010-08-10 18:02:33 -070087 */
88struct s3c_fb_variant {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070089 unsigned int is_2443:1;
Ben Dooks50a55032010-08-10 18:02:33 -070090 unsigned short nr_windows;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -070091 unsigned short vidtcon;
92 unsigned short wincon;
93 unsigned short winmap;
94 unsigned short keycon;
95 unsigned short buf_start;
96 unsigned short buf_end;
97 unsigned short buf_size;
98 unsigned short osd;
99 unsigned short osd_stride;
Ben Dooks50a55032010-08-10 18:02:33 -0700100 unsigned short palette[S3C_FB_MAX_WIN];
Pawel Osciak067b2262010-08-10 18:02:38 -0700101
102 unsigned int has_prtcon:1;
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700103 unsigned int has_shadowcon:1;
Jingoo Hanf7f31e52012-01-27 14:47:22 +0900104 unsigned int has_blendcon:1;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900105 unsigned int has_clksel:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700106};
107
108/**
109 * struct s3c_fb_win_variant
110 * @has_osd_c: Set if has OSD C register.
111 * @has_osd_d: Set if has OSD D register.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700112 * @has_osd_alpha: Set if can change alpha transparency for a window.
Ben Dooks50a55032010-08-10 18:02:33 -0700113 * @palette_sz: Size of palette in entries.
114 * @palette_16bpp: Set if palette is 16bits wide.
Pawel Osciakf676ec22010-08-10 18:02:40 -0700115 * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
116 * register is located at the given offset from OSD_BASE.
Ben Dooks50a55032010-08-10 18:02:33 -0700117 * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
118 *
119 * valid_bpp bit x is set if (x+1)BPP is supported.
120 */
121struct s3c_fb_win_variant {
122 unsigned int has_osd_c:1;
123 unsigned int has_osd_d:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700124 unsigned int has_osd_alpha:1;
Ben Dooks50a55032010-08-10 18:02:33 -0700125 unsigned int palette_16bpp:1;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700126 unsigned short osd_size_off;
Ben Dooks50a55032010-08-10 18:02:33 -0700127 unsigned short palette_sz;
128 u32 valid_bpp;
129};
130
131/**
132 * struct s3c_fb_driverdata - per-device type driver data for init time.
133 * @variant: The variant information for this driver.
134 * @win: The window information for each window.
135 */
136struct s3c_fb_driverdata {
137 struct s3c_fb_variant variant;
138 struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
139};
140
Ben Dooksec549a02009-03-31 15:25:39 -0700141/**
Ben Dooksbc2da1b2010-08-10 18:02:34 -0700142 * struct s3c_fb_palette - palette information
143 * @r: Red bitfield.
144 * @g: Green bitfield.
145 * @b: Blue bitfield.
146 * @a: Alpha bitfield.
147 */
148struct s3c_fb_palette {
149 struct fb_bitfield r;
150 struct fb_bitfield g;
151 struct fb_bitfield b;
152 struct fb_bitfield a;
153};
154
155/**
Ben Dooksec549a02009-03-31 15:25:39 -0700156 * struct s3c_fb_win - per window private data for each framebuffer.
157 * @windata: The platform data supplied for the window configuration.
158 * @parent: The hardware that this window is part of.
159 * @fbinfo: Pointer pack to the framebuffer info for this window.
Ben Dooks50a55032010-08-10 18:02:33 -0700160 * @varint: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -0700161 * @palette_buffer: Buffer/cache to hold palette entries.
162 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
163 * @index: The window number of this window.
164 * @palette: The bitfields for changing r/g/b into a hardware palette entry.
165 */
166struct s3c_fb_win {
167 struct s3c_fb_pd_win *windata;
168 struct s3c_fb *parent;
169 struct fb_info *fbinfo;
170 struct s3c_fb_palette palette;
Ben Dooks50a55032010-08-10 18:02:33 -0700171 struct s3c_fb_win_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700172
173 u32 *palette_buffer;
174 u32 pseudo_palette[16];
175 unsigned int index;
176};
177
178/**
Pawel Osciakefdc8462010-08-10 18:02:38 -0700179 * struct s3c_fb_vsync - vsync information
180 * @wait: a queue for processes waiting for vsync
181 * @count: vsync interrupt count
182 */
183struct s3c_fb_vsync {
184 wait_queue_head_t wait;
185 unsigned int count;
186};
187
188/**
Ben Dooksec549a02009-03-31 15:25:39 -0700189 * struct s3c_fb - overall hardware state of the hardware
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000190 * @slock: The spinlock protection for this data sturcture.
Ben Dooksec549a02009-03-31 15:25:39 -0700191 * @dev: The device that we bound to, for printing, etc.
Ben Dooksec549a02009-03-31 15:25:39 -0700192 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900193 * @lcd_clk: The clk (sclk) feeding pixclk.
Ben Dooksec549a02009-03-31 15:25:39 -0700194 * @regs: The mapped hardware registers.
Ben Dooks50a55032010-08-10 18:02:33 -0700195 * @variant: Variant information for this hardware.
Ben Dooksec549a02009-03-31 15:25:39 -0700196 * @enabled: A bitmask of enabled hardware windows.
Mark Brownf4f51472011-12-27 14:16:10 +0000197 * @output_on: Flag if the physical output is enabled.
Ben Dooksec549a02009-03-31 15:25:39 -0700198 * @pdata: The platform configuration data passed with the device.
199 * @windows: The hardware windows that have been claimed.
Pawel Osciakefdc8462010-08-10 18:02:38 -0700200 * @irq_no: IRQ line number
201 * @irq_flags: irq flags
202 * @vsync_info: VSYNC-related information (count, queues...)
Ben Dooksec549a02009-03-31 15:25:39 -0700203 */
204struct s3c_fb {
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +0000205 spinlock_t slock;
Ben Dooksec549a02009-03-31 15:25:39 -0700206 struct device *dev;
Ben Dooksec549a02009-03-31 15:25:39 -0700207 struct clk *bus_clk;
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900208 struct clk *lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -0700209 void __iomem *regs;
Ben Dooks50a55032010-08-10 18:02:33 -0700210 struct s3c_fb_variant variant;
Ben Dooksec549a02009-03-31 15:25:39 -0700211
212 unsigned char enabled;
Mark Brownf4f51472011-12-27 14:16:10 +0000213 bool output_on;
Ben Dooksec549a02009-03-31 15:25:39 -0700214
215 struct s3c_fb_platdata *pdata;
216 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
Pawel Osciakefdc8462010-08-10 18:02:38 -0700217
218 int irq_no;
219 unsigned long irq_flags;
220 struct s3c_fb_vsync vsync_info;
Ben Dooksec549a02009-03-31 15:25:39 -0700221};
222
223/**
Ben Dooks50a55032010-08-10 18:02:33 -0700224 * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
225 * @win: The device window.
226 * @bpp: The bit depth.
Ben Dooksec549a02009-03-31 15:25:39 -0700227 */
Ben Dooks50a55032010-08-10 18:02:33 -0700228static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
Ben Dooksec549a02009-03-31 15:25:39 -0700229{
Ben Dooks50a55032010-08-10 18:02:33 -0700230 return win->variant.valid_bpp & VALID_BPP(bpp);
Ben Dooksec549a02009-03-31 15:25:39 -0700231}
232
233/**
234 * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
235 * @var: The screen information to verify.
236 * @info: The framebuffer device.
237 *
238 * Framebuffer layer call to verify the given information and allow us to
239 * update various information depending on the hardware capabilities.
240 */
241static int s3c_fb_check_var(struct fb_var_screeninfo *var,
242 struct fb_info *info)
243{
244 struct s3c_fb_win *win = info->par;
Ben Dooksec549a02009-03-31 15:25:39 -0700245 struct s3c_fb *sfb = win->parent;
246
247 dev_dbg(sfb->dev, "checking parameters\n");
248
Jingoo Han13e6af82011-06-09 04:26:38 +0000249 var->xres_virtual = max(var->xres_virtual, var->xres);
250 var->yres_virtual = max(var->yres_virtual, var->yres);
Ben Dooksec549a02009-03-31 15:25:39 -0700251
Ben Dooks50a55032010-08-10 18:02:33 -0700252 if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
Ben Dooksec549a02009-03-31 15:25:39 -0700253 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
254 win->index, var->bits_per_pixel);
255 return -EINVAL;
256 }
257
258 /* always ensure these are zero, for drop through cases below */
259 var->transp.offset = 0;
260 var->transp.length = 0;
261
262 switch (var->bits_per_pixel) {
263 case 1:
264 case 2:
265 case 4:
266 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700267 if (sfb->variant.palette[win->index] != 0) {
Ben Dooksec549a02009-03-31 15:25:39 -0700268 /* non palletised, A:1,R:2,G:3,B:2 mode */
269 var->red.offset = 4;
270 var->green.offset = 2;
271 var->blue.offset = 0;
272 var->red.length = 5;
273 var->green.length = 3;
274 var->blue.length = 2;
275 var->transp.offset = 7;
276 var->transp.length = 1;
277 } else {
278 var->red.offset = 0;
279 var->red.length = var->bits_per_pixel;
280 var->green = var->red;
281 var->blue = var->red;
282 }
283 break;
284
285 case 19:
286 /* 666 with one bit alpha/transparency */
287 var->transp.offset = 18;
288 var->transp.length = 1;
289 case 18:
290 var->bits_per_pixel = 32;
291
292 /* 666 format */
293 var->red.offset = 12;
294 var->green.offset = 6;
295 var->blue.offset = 0;
296 var->red.length = 6;
297 var->green.length = 6;
298 var->blue.length = 6;
299 break;
300
301 case 16:
302 /* 16 bpp, 565 format */
303 var->red.offset = 11;
304 var->green.offset = 5;
305 var->blue.offset = 0;
306 var->red.length = 5;
307 var->green.length = 6;
308 var->blue.length = 5;
309 break;
310
Jingoo Hanaf1ce6b2011-05-24 08:55:23 +0000311 case 32:
Ben Dooksec549a02009-03-31 15:25:39 -0700312 case 28:
313 case 25:
314 var->transp.length = var->bits_per_pixel - 24;
315 var->transp.offset = 24;
316 /* drop through */
317 case 24:
318 /* our 24bpp is unpacked, so 32bpp */
319 var->bits_per_pixel = 32;
Ben Dooksec549a02009-03-31 15:25:39 -0700320 var->red.offset = 16;
321 var->red.length = 8;
322 var->green.offset = 8;
323 var->green.length = 8;
324 var->blue.offset = 0;
325 var->blue.length = 8;
326 break;
327
328 default:
329 dev_err(sfb->dev, "invalid bpp\n");
330 }
331
332 dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
333 return 0;
334}
335
336/**
337 * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
338 * @sfb: The hardware state.
339 * @pixclock: The pixel clock wanted, in picoseconds.
340 *
341 * Given the specified pixel clock, work out the necessary divider to get
342 * close to the output frequency.
343 */
Mark Browneb29a5c2010-01-15 17:01:40 -0800344static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
Ben Dooksec549a02009-03-31 15:25:39 -0700345{
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900346 unsigned long clk;
Mark Browneb29a5c2010-01-15 17:01:40 -0800347 unsigned long long tmp;
Ben Dooksec549a02009-03-31 15:25:39 -0700348 unsigned int result;
349
Jingoo Hanb5480ed2011-08-22 12:16:04 +0900350 if (sfb->variant.has_clksel)
351 clk = clk_get_rate(sfb->bus_clk);
352 else
353 clk = clk_get_rate(sfb->lcd_clk);
354
Mark Browneb29a5c2010-01-15 17:01:40 -0800355 tmp = (unsigned long long)clk;
356 tmp *= pixclk;
357
358 do_div(tmp, 1000000000UL);
359 result = (unsigned int)tmp / 1000;
Ben Dooksec549a02009-03-31 15:25:39 -0700360
361 dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
362 pixclk, clk, result, clk / result);
363
364 return result;
365}
366
367/**
368 * s3c_fb_align_word() - align pixel count to word boundary
369 * @bpp: The number of bits per pixel
370 * @pix: The value to be aligned.
371 *
372 * Align the given pixel count so that it will start on an 32bit word
373 * boundary.
374 */
375static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
376{
377 int pix_per_word;
378
379 if (bpp > 16)
380 return pix;
381
382 pix_per_word = (8 * 32) / bpp;
383 return ALIGN(pix, pix_per_word);
384}
385
386/**
Pawel Osciakf676ec22010-08-10 18:02:40 -0700387 * vidosd_set_size() - set OSD size for a window
388 *
389 * @win: the window to set OSD size for
390 * @size: OSD size register value
391 */
392static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
393{
394 struct s3c_fb *sfb = win->parent;
395
396 /* OSD can be set up if osd_size_off != 0 for this window */
397 if (win->variant.osd_size_off)
398 writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
399 + win->variant.osd_size_off);
400}
401
402/**
403 * vidosd_set_alpha() - set alpha transparency for a window
404 *
405 * @win: the window to set OSD size for
406 * @alpha: alpha register value
407 */
408static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
409{
410 struct s3c_fb *sfb = win->parent;
411
412 if (win->variant.has_osd_alpha)
413 writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
414}
415
416/**
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700417 * shadow_protect_win() - disable updating values from shadow registers at vsync
418 *
419 * @win: window to protect registers for
420 * @protect: 1 to protect (disable updates)
421 */
422static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
423{
424 struct s3c_fb *sfb = win->parent;
425 u32 reg;
426
427 if (protect) {
428 if (sfb->variant.has_prtcon) {
429 writel(PRTCON_PROTECT, sfb->regs + PRTCON);
430 } else if (sfb->variant.has_shadowcon) {
431 reg = readl(sfb->regs + SHADOWCON);
432 writel(reg | SHADOWCON_WINx_PROTECT(win->index),
433 sfb->regs + SHADOWCON);
434 }
435 } else {
436 if (sfb->variant.has_prtcon) {
437 writel(0, sfb->regs + PRTCON);
438 } else if (sfb->variant.has_shadowcon) {
439 reg = readl(sfb->regs + SHADOWCON);
440 writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
441 sfb->regs + SHADOWCON);
442 }
443 }
444}
445
446/**
Mark Browna2b77dc2011-12-27 14:16:08 +0000447 * s3c_fb_enable() - Set the state of the main LCD output
448 * @sfb: The main framebuffer state.
449 * @enable: The state to set.
450 */
451static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
452{
453 u32 vidcon0 = readl(sfb->regs + VIDCON0);
454
Mark Brownf4f51472011-12-27 14:16:10 +0000455 if (enable && !sfb->output_on)
456 pm_runtime_get_sync(sfb->dev);
457
458 if (enable) {
Mark Browna2b77dc2011-12-27 14:16:08 +0000459 vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
Mark Brownf4f51472011-12-27 14:16:10 +0000460 } else {
Mark Browna2b77dc2011-12-27 14:16:08 +0000461 /* see the note in the framebuffer datasheet about
462 * why you cannot take both of these bits down at the
463 * same time. */
464
Mark Brownf4f51472011-12-27 14:16:10 +0000465 if (vidcon0 & VIDCON0_ENVID) {
466 vidcon0 |= VIDCON0_ENVID;
467 vidcon0 &= ~VIDCON0_ENVID_F;
468 }
Mark Browna2b77dc2011-12-27 14:16:08 +0000469 }
470
471 writel(vidcon0, sfb->regs + VIDCON0);
Mark Brownf4f51472011-12-27 14:16:10 +0000472
473 if (!enable && sfb->output_on)
474 pm_runtime_put_sync(sfb->dev);
475
476 sfb->output_on = enable;
Mark Browna2b77dc2011-12-27 14:16:08 +0000477}
478
479/**
Ben Dooksec549a02009-03-31 15:25:39 -0700480 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
481 * @info: The framebuffer to change.
482 *
483 * Framebuffer layer request to set a new mode for the specified framebuffer
484 */
485static int s3c_fb_set_par(struct fb_info *info)
486{
487 struct fb_var_screeninfo *var = &info->var;
488 struct s3c_fb_win *win = info->par;
489 struct s3c_fb *sfb = win->parent;
490 void __iomem *regs = sfb->regs;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700491 void __iomem *buf = regs;
Ben Dooksec549a02009-03-31 15:25:39 -0700492 int win_no = win->index;
Pawel Osciakf676ec22010-08-10 18:02:40 -0700493 u32 alpha = 0;
Ben Dooksec549a02009-03-31 15:25:39 -0700494 u32 data;
495 u32 pagewidth;
496 int clkdiv;
497
498 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
499
Mark Brown5751b232011-12-27 14:16:11 +0000500 pm_runtime_get_sync(sfb->dev);
501
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700502 shadow_protect_win(win, 1);
503
Ben Dooksec549a02009-03-31 15:25:39 -0700504 switch (var->bits_per_pixel) {
505 case 32:
506 case 24:
507 case 16:
508 case 12:
509 info->fix.visual = FB_VISUAL_TRUECOLOR;
510 break;
511 case 8:
Ben Dooks50a55032010-08-10 18:02:33 -0700512 if (win->variant.palette_sz >= 256)
Ben Dooksec549a02009-03-31 15:25:39 -0700513 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
514 else
515 info->fix.visual = FB_VISUAL_TRUECOLOR;
516 break;
517 case 1:
518 info->fix.visual = FB_VISUAL_MONO01;
519 break;
520 default:
521 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
522 break;
523 }
524
525 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
526
Pawel Osciak067b2262010-08-10 18:02:38 -0700527 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
528 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
529
Ben Dooksec549a02009-03-31 15:25:39 -0700530 /* disable the window whilst we update it */
531 writel(0, regs + WINCON(win_no));
532
InKi Daead044902010-08-10 18:02:31 -0700533 /* use platform specified window as the basis for the lcd timings */
Ben Dooksec549a02009-03-31 15:25:39 -0700534
InKi Daead044902010-08-10 18:02:31 -0700535 if (win_no == sfb->pdata->default_win) {
Mark Browneb29a5c2010-01-15 17:01:40 -0800536 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
Ben Dooksec549a02009-03-31 15:25:39 -0700537
538 data = sfb->pdata->vidcon0;
539 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
540
541 if (clkdiv > 1)
542 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
543 else
544 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
545
546 /* write the timing data to the panel */
547
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700548 if (sfb->variant.is_2443)
549 data |= (1 << 5);
550
Ben Dooksec549a02009-03-31 15:25:39 -0700551 writel(data, regs + VIDCON0);
552
Mark Browna2b77dc2011-12-27 14:16:08 +0000553 s3c_fb_enable(sfb, 1);
554
Ben Dooksec549a02009-03-31 15:25:39 -0700555 data = VIDTCON0_VBPD(var->upper_margin - 1) |
556 VIDTCON0_VFPD(var->lower_margin - 1) |
557 VIDTCON0_VSPW(var->vsync_len - 1);
558
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700559 writel(data, regs + sfb->variant.vidtcon);
Ben Dooksec549a02009-03-31 15:25:39 -0700560
561 data = VIDTCON1_HBPD(var->left_margin - 1) |
562 VIDTCON1_HFPD(var->right_margin - 1) |
563 VIDTCON1_HSPW(var->hsync_len - 1);
564
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700565 /* VIDTCON1 */
566 writel(data, regs + sfb->variant.vidtcon + 4);
Ben Dooksec549a02009-03-31 15:25:39 -0700567
568 data = VIDTCON2_LINEVAL(var->yres - 1) |
569 VIDTCON2_HOZVAL(var->xres - 1);
Jingoo Hanb73a21fc2011-04-01 07:17:27 +0000570 writel(data, regs + sfb->variant.vidtcon + 8);
Ben Dooksec549a02009-03-31 15:25:39 -0700571 }
572
573 /* write the buffer address */
574
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700575 /* start and end registers stride is 8 */
576 buf = regs + win_no * 8;
577
578 writel(info->fix.smem_start, buf + sfb->variant.buf_start);
Ben Dooksec549a02009-03-31 15:25:39 -0700579
580 data = info->fix.smem_start + info->fix.line_length * var->yres;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700581 writel(data, buf + sfb->variant.buf_end);
Ben Dooksec549a02009-03-31 15:25:39 -0700582
583 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
584 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
585 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700586 writel(data, regs + sfb->variant.buf_size + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700587
588 /* write 'OSD' registers to control position of framebuffer */
589
590 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700591 writel(data, regs + VIDOSD_A(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700592
593 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
594 var->xres - 1)) |
595 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
596
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700597 writel(data, regs + VIDOSD_B(win_no, sfb->variant));
Ben Dooksec549a02009-03-31 15:25:39 -0700598
599 data = var->xres * var->yres;
InKi Dae39000d62009-06-16 15:34:27 -0700600
Pawel Osciakf676ec22010-08-10 18:02:40 -0700601 alpha = VIDISD14C_ALPHA1_R(0xf) |
InKi Dae39000d62009-06-16 15:34:27 -0700602 VIDISD14C_ALPHA1_G(0xf) |
603 VIDISD14C_ALPHA1_B(0xf);
604
Pawel Osciakf676ec22010-08-10 18:02:40 -0700605 vidosd_set_alpha(win, alpha);
606 vidosd_set_size(win, data);
Ben Dooksec549a02009-03-31 15:25:39 -0700607
Jingoo Hanfab7c5b2011-06-09 04:26:45 +0000608 /* Enable DMA channel for this window */
609 if (sfb->variant.has_shadowcon) {
610 data = readl(sfb->regs + SHADOWCON);
611 data |= SHADOWCON_CHx_ENABLE(win_no);
612 writel(data, sfb->regs + SHADOWCON);
613 }
614
Ben Dooksec549a02009-03-31 15:25:39 -0700615 data = WINCONx_ENWIN;
Jingoo Han2d9ae7a2011-12-02 19:07:17 +0900616 sfb->enabled |= (1 << win->index);
Ben Dooksec549a02009-03-31 15:25:39 -0700617
618 /* note, since we have to round up the bits-per-pixel, we end up
619 * relying on the bitfield information for r/g/b/a to work out
620 * exactly which mode of operation is intended. */
621
622 switch (var->bits_per_pixel) {
623 case 1:
624 data |= WINCON0_BPPMODE_1BPP;
625 data |= WINCONx_BITSWP;
626 data |= WINCONx_BURSTLEN_4WORD;
627 break;
628 case 2:
629 data |= WINCON0_BPPMODE_2BPP;
630 data |= WINCONx_BITSWP;
631 data |= WINCONx_BURSTLEN_8WORD;
632 break;
633 case 4:
634 data |= WINCON0_BPPMODE_4BPP;
635 data |= WINCONx_BITSWP;
636 data |= WINCONx_BURSTLEN_8WORD;
637 break;
638 case 8:
639 if (var->transp.length != 0)
640 data |= WINCON1_BPPMODE_8BPP_1232;
641 else
642 data |= WINCON0_BPPMODE_8BPP_PALETTE;
643 data |= WINCONx_BURSTLEN_8WORD;
644 data |= WINCONx_BYTSWP;
645 break;
646 case 16:
647 if (var->transp.length != 0)
648 data |= WINCON1_BPPMODE_16BPP_A1555;
649 else
650 data |= WINCON0_BPPMODE_16BPP_565;
651 data |= WINCONx_HAWSWP;
652 data |= WINCONx_BURSTLEN_16WORD;
653 break;
654 case 24:
655 case 32:
656 if (var->red.length == 6) {
657 if (var->transp.length != 0)
658 data |= WINCON1_BPPMODE_19BPP_A1666;
659 else
660 data |= WINCON1_BPPMODE_18BPP_666;
InKi Dae39000d62009-06-16 15:34:27 -0700661 } else if (var->transp.length == 1)
662 data |= WINCON1_BPPMODE_25BPP_A1888
663 | WINCON1_BLD_PIX;
Jingoo Han4420dd22011-11-07 15:03:01 +0900664 else if ((var->transp.length == 4) ||
665 (var->transp.length == 8))
InKi Dae39000d62009-06-16 15:34:27 -0700666 data |= WINCON1_BPPMODE_28BPP_A4888
667 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
Ben Dooksec549a02009-03-31 15:25:39 -0700668 else
669 data |= WINCON0_BPPMODE_24BPP_888;
670
InKi Daedc8498c2010-08-10 18:02:32 -0700671 data |= WINCONx_WSWP;
Ben Dooksec549a02009-03-31 15:25:39 -0700672 data |= WINCONx_BURSTLEN_16WORD;
673 break;
674 }
675
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700676 /* Enable the colour keying for the window below this one */
InKi Dae39000d62009-06-16 15:34:27 -0700677 if (win_no > 0) {
678 u32 keycon0_data = 0, keycon1_data = 0;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700679 void __iomem *keycon = regs + sfb->variant.keycon;
InKi Dae39000d62009-06-16 15:34:27 -0700680
681 keycon0_data = ~(WxKEYCON0_KEYBL_EN |
682 WxKEYCON0_KEYEN_F |
683 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
684
685 keycon1_data = WxKEYCON1_COLVAL(0xffffff);
686
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700687 keycon += (win_no - 1) * 8;
688
689 writel(keycon0_data, keycon + WKEYCON0);
690 writel(keycon1_data, keycon + WKEYCON1);
InKi Dae39000d62009-06-16 15:34:27 -0700691 }
692
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700693 writel(data, regs + sfb->variant.wincon + (win_no * 4));
694 writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700695
Jingoo Hanf7f31e52012-01-27 14:47:22 +0900696 /* Set alpha value width */
697 if (sfb->variant.has_blendcon) {
698 data = readl(sfb->regs + BLENDCON);
699 data &= ~BLENDCON_NEW_MASK;
700 if (var->transp.length > 4)
701 data |= BLENDCON_NEW_8BIT_ALPHA_VALUE;
702 else
703 data |= BLENDCON_NEW_4BIT_ALPHA_VALUE;
704 writel(data, sfb->regs + BLENDCON);
705 }
706
Pawel Osciaka8bdabc2010-08-10 18:02:41 -0700707 shadow_protect_win(win, 0);
708
Mark Brown5751b232011-12-27 14:16:11 +0000709 pm_runtime_put_sync(sfb->dev);
710
Ben Dooksec549a02009-03-31 15:25:39 -0700711 return 0;
712}
713
714/**
715 * s3c_fb_update_palette() - set or schedule a palette update.
716 * @sfb: The hardware information.
717 * @win: The window being updated.
718 * @reg: The palette index being changed.
719 * @value: The computed palette value.
720 *
721 * Change the value of a palette register, either by directly writing to
722 * the palette (this requires the palette RAM to be disconnected from the
723 * hardware whilst this is in progress) or schedule the update for later.
724 *
725 * At the moment, since we have no VSYNC interrupt support, we simply set
726 * the palette entry directly.
727 */
728static void s3c_fb_update_palette(struct s3c_fb *sfb,
729 struct s3c_fb_win *win,
730 unsigned int reg,
731 u32 value)
732{
733 void __iomem *palreg;
734 u32 palcon;
735
Ben Dooks50a55032010-08-10 18:02:33 -0700736 palreg = sfb->regs + sfb->variant.palette[win->index];
Ben Dooksec549a02009-03-31 15:25:39 -0700737
738 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
739 __func__, win->index, reg, palreg, value);
740
741 win->palette_buffer[reg] = value;
742
743 palcon = readl(sfb->regs + WPALCON);
744 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
745
Ben Dooks50a55032010-08-10 18:02:33 -0700746 if (win->variant.palette_16bpp)
747 writew(value, palreg + (reg * 2));
Ben Dooksec549a02009-03-31 15:25:39 -0700748 else
Ben Dooks50a55032010-08-10 18:02:33 -0700749 writel(value, palreg + (reg * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700750
751 writel(palcon, sfb->regs + WPALCON);
752}
753
754static inline unsigned int chan_to_field(unsigned int chan,
755 struct fb_bitfield *bf)
756{
757 chan &= 0xffff;
758 chan >>= 16 - bf->length;
759 return chan << bf->offset;
760}
761
762/**
763 * s3c_fb_setcolreg() - framebuffer layer request to change palette.
764 * @regno: The palette index to change.
765 * @red: The red field for the palette data.
766 * @green: The green field for the palette data.
767 * @blue: The blue field for the palette data.
768 * @trans: The transparency (alpha) field for the palette data.
769 * @info: The framebuffer being changed.
770 */
771static int s3c_fb_setcolreg(unsigned regno,
772 unsigned red, unsigned green, unsigned blue,
773 unsigned transp, struct fb_info *info)
774{
775 struct s3c_fb_win *win = info->par;
776 struct s3c_fb *sfb = win->parent;
777 unsigned int val;
778
779 dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
780 __func__, win->index, regno, red, green, blue);
781
Mark Brown5751b232011-12-27 14:16:11 +0000782 pm_runtime_get_sync(sfb->dev);
783
Ben Dooksec549a02009-03-31 15:25:39 -0700784 switch (info->fix.visual) {
785 case FB_VISUAL_TRUECOLOR:
786 /* true-colour, use pseudo-palette */
787
788 if (regno < 16) {
789 u32 *pal = info->pseudo_palette;
790
791 val = chan_to_field(red, &info->var.red);
792 val |= chan_to_field(green, &info->var.green);
793 val |= chan_to_field(blue, &info->var.blue);
794
795 pal[regno] = val;
796 }
797 break;
798
799 case FB_VISUAL_PSEUDOCOLOR:
Ben Dooks50a55032010-08-10 18:02:33 -0700800 if (regno < win->variant.palette_sz) {
Ben Dooksec549a02009-03-31 15:25:39 -0700801 val = chan_to_field(red, &win->palette.r);
802 val |= chan_to_field(green, &win->palette.g);
803 val |= chan_to_field(blue, &win->palette.b);
804
805 s3c_fb_update_palette(sfb, win, regno, val);
806 }
807
808 break;
809
810 default:
Mark Brown5751b232011-12-27 14:16:11 +0000811 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700812 return 1; /* unknown type */
813 }
814
Mark Brown5751b232011-12-27 14:16:11 +0000815 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700816 return 0;
817}
818
819/**
Ben Dooksec549a02009-03-31 15:25:39 -0700820 * s3c_fb_blank() - blank or unblank the given window
821 * @blank_mode: The blank state from FB_BLANK_*
822 * @info: The framebuffer to blank.
823 *
824 * Framebuffer layer request to change the power state.
825 */
826static int s3c_fb_blank(int blank_mode, struct fb_info *info)
827{
828 struct s3c_fb_win *win = info->par;
829 struct s3c_fb *sfb = win->parent;
830 unsigned int index = win->index;
831 u32 wincon;
832
833 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
834
Mark Brown5751b232011-12-27 14:16:11 +0000835 pm_runtime_get_sync(sfb->dev);
836
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700837 wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
Ben Dooksec549a02009-03-31 15:25:39 -0700838
839 switch (blank_mode) {
840 case FB_BLANK_POWERDOWN:
841 wincon &= ~WINCONx_ENWIN;
842 sfb->enabled &= ~(1 << index);
843 /* fall through to FB_BLANK_NORMAL */
844
845 case FB_BLANK_NORMAL:
846 /* disable the DMA and display 0x0 (black) */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900847 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700848 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700849 sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900850 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700851 break;
852
853 case FB_BLANK_UNBLANK:
Jingoo Hanff8c9102011-12-08 18:08:00 +0900854 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700855 writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900856 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700857 wincon |= WINCONx_ENWIN;
858 sfb->enabled |= (1 << index);
859 break;
860
861 case FB_BLANK_VSYNC_SUSPEND:
862 case FB_BLANK_HSYNC_SUSPEND:
863 default:
Mark Brown5751b232011-12-27 14:16:11 +0000864 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -0700865 return 1;
866 }
867
Jingoo Hanff8c9102011-12-08 18:08:00 +0900868 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -0700869 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
Jingoo Hanff8c9102011-12-08 18:08:00 +0900870 shadow_protect_win(win, 0);
Ben Dooksec549a02009-03-31 15:25:39 -0700871
872 /* Check the enabled state to see if we need to be running the
873 * main LCD interface, as if there are no active windows then
874 * it is highly likely that we also do not need to output
875 * anything.
876 */
877
878 /* We could do something like the following code, but the current
879 * system of using framebuffer events means that we cannot make
880 * the distinction between just window 0 being inactive and all
881 * the windows being down.
882 *
883 * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
884 */
885
886 /* we're stuck with this until we can do something about overriding
887 * the power control using the blanking event for a single fb.
888 */
Jingoo Hanff8c9102011-12-08 18:08:00 +0900889 if (index == sfb->pdata->default_win) {
890 shadow_protect_win(win, 1);
Ben Dooksec549a02009-03-31 15:25:39 -0700891 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
Jingoo Hanff8c9102011-12-08 18:08:00 +0900892 shadow_protect_win(win, 0);
893 }
Ben Dooksec549a02009-03-31 15:25:39 -0700894
Mark Brown5751b232011-12-27 14:16:11 +0000895 pm_runtime_put_sync(sfb->dev);
896
Ben Dooksec549a02009-03-31 15:25:39 -0700897 return 0;
898}
899
Pawel Osciak067b2262010-08-10 18:02:38 -0700900/**
901 * s3c_fb_pan_display() - Pan the display.
902 *
903 * Note that the offsets can be written to the device at any time, as their
904 * values are latched at each vsync automatically. This also means that only
905 * the last call to this function will have any effect on next vsync, but
906 * there is no need to sleep waiting for it to prevent tearing.
907 *
908 * @var: The screen information to verify.
909 * @info: The framebuffer device.
910 */
911static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
912 struct fb_info *info)
913{
914 struct s3c_fb_win *win = info->par;
915 struct s3c_fb *sfb = win->parent;
916 void __iomem *buf = sfb->regs + win->index * 8;
917 unsigned int start_boff, end_boff;
918
Mark Brown5751b232011-12-27 14:16:11 +0000919 pm_runtime_get_sync(sfb->dev);
920
Pawel Osciak067b2262010-08-10 18:02:38 -0700921 /* Offset in bytes to the start of the displayed area */
922 start_boff = var->yoffset * info->fix.line_length;
923 /* X offset depends on the current bpp */
924 if (info->var.bits_per_pixel >= 8) {
925 start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
926 } else {
927 switch (info->var.bits_per_pixel) {
928 case 4:
929 start_boff += var->xoffset >> 1;
930 break;
931 case 2:
932 start_boff += var->xoffset >> 2;
933 break;
934 case 1:
935 start_boff += var->xoffset >> 3;
936 break;
937 default:
938 dev_err(sfb->dev, "invalid bpp\n");
Mark Brown5751b232011-12-27 14:16:11 +0000939 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700940 return -EINVAL;
941 }
942 }
943 /* Offset in bytes to the end of the displayed area */
Laurent Pinchartd8e7a742011-05-25 11:34:52 +0200944 end_boff = start_boff + info->var.yres * info->fix.line_length;
Pawel Osciak067b2262010-08-10 18:02:38 -0700945
946 /* Temporarily turn off per-vsync update from shadow registers until
947 * both start and end addresses are updated to prevent corruption */
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700948 shadow_protect_win(win, 1);
Pawel Osciak067b2262010-08-10 18:02:38 -0700949
950 writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
951 writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
952
Pawel Osciakf5ec5462010-08-10 18:02:40 -0700953 shadow_protect_win(win, 0);
Pawel Osciak067b2262010-08-10 18:02:38 -0700954
Mark Brown5751b232011-12-27 14:16:11 +0000955 pm_runtime_put_sync(sfb->dev);
Pawel Osciak067b2262010-08-10 18:02:38 -0700956 return 0;
957}
958
Pawel Osciakefdc8462010-08-10 18:02:38 -0700959/**
960 * s3c_fb_enable_irq() - enable framebuffer interrupts
961 * @sfb: main hardware state
962 */
963static void s3c_fb_enable_irq(struct s3c_fb *sfb)
964{
965 void __iomem *regs = sfb->regs;
966 u32 irq_ctrl_reg;
967
968 if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
969 /* IRQ disabled, enable it */
970 irq_ctrl_reg = readl(regs + VIDINTCON0);
971
972 irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
973 irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
974
975 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
976 irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
977 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
978 irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
979
980 writel(irq_ctrl_reg, regs + VIDINTCON0);
981 }
982}
983
984/**
985 * s3c_fb_disable_irq() - disable framebuffer interrupts
986 * @sfb: main hardware state
987 */
988static void s3c_fb_disable_irq(struct s3c_fb *sfb)
989{
990 void __iomem *regs = sfb->regs;
991 u32 irq_ctrl_reg;
992
993 if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
994 /* IRQ enabled, disable it */
995 irq_ctrl_reg = readl(regs + VIDINTCON0);
996
997 irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
998 irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
999
1000 writel(irq_ctrl_reg, regs + VIDINTCON0);
1001 }
1002}
1003
1004static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
1005{
1006 struct s3c_fb *sfb = dev_id;
1007 void __iomem *regs = sfb->regs;
1008 u32 irq_sts_reg;
1009
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001010 spin_lock(&sfb->slock);
1011
Pawel Osciakefdc8462010-08-10 18:02:38 -07001012 irq_sts_reg = readl(regs + VIDINTCON1);
1013
1014 if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
1015
1016 /* VSYNC interrupt, accept it */
1017 writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
1018
1019 sfb->vsync_info.count++;
1020 wake_up_interruptible(&sfb->vsync_info.wait);
1021 }
1022
1023 /* We only support waiting for VSYNC for now, so it's safe
1024 * to always disable irqs here.
1025 */
1026 s3c_fb_disable_irq(sfb);
1027
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001028 spin_unlock(&sfb->slock);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001029 return IRQ_HANDLED;
1030}
1031
1032/**
1033 * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
1034 * @sfb: main hardware state
1035 * @crtc: head index.
1036 */
1037static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
1038{
1039 unsigned long count;
1040 int ret;
1041
1042 if (crtc != 0)
1043 return -ENODEV;
1044
Mark Brown5751b232011-12-27 14:16:11 +00001045 pm_runtime_get_sync(sfb->dev);
1046
Pawel Osciakefdc8462010-08-10 18:02:38 -07001047 count = sfb->vsync_info.count;
1048 s3c_fb_enable_irq(sfb);
1049 ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
1050 count != sfb->vsync_info.count,
1051 msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
Mark Brown5751b232011-12-27 14:16:11 +00001052
1053 pm_runtime_put_sync(sfb->dev);
1054
Pawel Osciakefdc8462010-08-10 18:02:38 -07001055 if (ret == 0)
1056 return -ETIMEDOUT;
1057
1058 return 0;
1059}
1060
1061static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
1062 unsigned long arg)
1063{
1064 struct s3c_fb_win *win = info->par;
1065 struct s3c_fb *sfb = win->parent;
1066 int ret;
1067 u32 crtc;
1068
1069 switch (cmd) {
1070 case FBIO_WAITFORVSYNC:
1071 if (get_user(crtc, (u32 __user *)arg)) {
1072 ret = -EFAULT;
1073 break;
1074 }
1075
1076 ret = s3c_fb_wait_for_vsync(sfb, crtc);
1077 break;
1078 default:
1079 ret = -ENOTTY;
1080 }
1081
1082 return ret;
1083}
1084
Ben Dooksec549a02009-03-31 15:25:39 -07001085static struct fb_ops s3c_fb_ops = {
1086 .owner = THIS_MODULE,
1087 .fb_check_var = s3c_fb_check_var,
1088 .fb_set_par = s3c_fb_set_par,
1089 .fb_blank = s3c_fb_blank,
1090 .fb_setcolreg = s3c_fb_setcolreg,
1091 .fb_fillrect = cfb_fillrect,
1092 .fb_copyarea = cfb_copyarea,
1093 .fb_imageblit = cfb_imageblit,
Pawel Osciak067b2262010-08-10 18:02:38 -07001094 .fb_pan_display = s3c_fb_pan_display,
Pawel Osciakefdc8462010-08-10 18:02:38 -07001095 .fb_ioctl = s3c_fb_ioctl,
Ben Dooksec549a02009-03-31 15:25:39 -07001096};
1097
1098/**
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001099 * s3c_fb_missing_pixclock() - calculates pixel clock
1100 * @mode: The video mode to change.
1101 *
1102 * Calculate the pixel clock when none has been given through platform data.
1103 */
1104static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
1105{
1106 u64 pixclk = 1000000000000ULL;
1107 u32 div;
1108
1109 div = mode->left_margin + mode->hsync_len + mode->right_margin +
1110 mode->xres;
1111 div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
1112 mode->yres;
1113 div *= mode->refresh ? : 60;
1114
1115 do_div(pixclk, div);
1116
1117 mode->pixclock = pixclk;
1118}
1119
1120/**
Ben Dooksec549a02009-03-31 15:25:39 -07001121 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
1122 * @sfb: The base resources for the hardware.
1123 * @win: The window to initialise memory for.
1124 *
1125 * Allocate memory for the given framebuffer.
1126 */
1127static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
1128 struct s3c_fb_win *win)
1129{
1130 struct s3c_fb_pd_win *windata = win->windata;
1131 unsigned int real_size, virt_size, size;
1132 struct fb_info *fbi = win->fbinfo;
1133 dma_addr_t map_dma;
1134
1135 dev_dbg(sfb->dev, "allocating memory for display\n");
1136
1137 real_size = windata->win_mode.xres * windata->win_mode.yres;
1138 virt_size = windata->virtual_x * windata->virtual_y;
1139
1140 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
1141 real_size, windata->win_mode.xres, windata->win_mode.yres,
1142 virt_size, windata->virtual_x, windata->virtual_y);
1143
1144 size = (real_size > virt_size) ? real_size : virt_size;
1145 size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
1146 size /= 8;
1147
1148 fbi->fix.smem_len = size;
1149 size = PAGE_ALIGN(size);
1150
1151 dev_dbg(sfb->dev, "want %u bytes for window\n", size);
1152
1153 fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
1154 &map_dma, GFP_KERNEL);
1155 if (!fbi->screen_base)
1156 return -ENOMEM;
1157
1158 dev_dbg(sfb->dev, "mapped %x to %p\n",
1159 (unsigned int)map_dma, fbi->screen_base);
1160
1161 memset(fbi->screen_base, 0x0, size);
1162 fbi->fix.smem_start = map_dma;
1163
1164 return 0;
1165}
1166
1167/**
1168 * s3c_fb_free_memory() - free the display memory for the given window
1169 * @sfb: The base resources for the hardware.
1170 * @win: The window to free the display memory for.
1171 *
1172 * Free the display memory allocated by s3c_fb_alloc_memory().
1173 */
1174static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
1175{
1176 struct fb_info *fbi = win->fbinfo;
1177
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001178 if (fbi->screen_base)
1179 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
Ben Dooksec549a02009-03-31 15:25:39 -07001180 fbi->screen_base, fbi->fix.smem_start);
1181}
1182
1183/**
1184 * s3c_fb_release_win() - release resources for a framebuffer window.
1185 * @win: The window to cleanup the resources for.
1186 *
1187 * Release the resources that where claimed for the hardware window,
1188 * such as the framebuffer instance and any memory claimed for it.
1189 */
1190static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
1191{
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001192 u32 data;
1193
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001194 if (win->fbinfo) {
Pawel Osciak04ab9ef2010-08-10 18:02:43 -07001195 if (sfb->variant.has_shadowcon) {
1196 data = readl(sfb->regs + SHADOWCON);
1197 data &= ~SHADOWCON_CHx_ENABLE(win->index);
1198 data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
1199 writel(data, sfb->regs + SHADOWCON);
1200 }
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001201 unregister_framebuffer(win->fbinfo);
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001202 if (win->fbinfo->cmap.len)
1203 fb_dealloc_cmap(&win->fbinfo->cmap);
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001204 s3c_fb_free_memory(sfb, win);
1205 framebuffer_release(win->fbinfo);
1206 }
Ben Dooksec549a02009-03-31 15:25:39 -07001207}
1208
1209/**
1210 * s3c_fb_probe_win() - register an hardware window
1211 * @sfb: The base resources for the hardware
Ben Dooks50a55032010-08-10 18:02:33 -07001212 * @variant: The variant information for this window.
Ben Dooksec549a02009-03-31 15:25:39 -07001213 * @res: Pointer to where to place the resultant window.
1214 *
1215 * Allocate and do the basic initialisation for one of the hardware's graphics
1216 * windows.
1217 */
1218static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
Ben Dooks50a55032010-08-10 18:02:33 -07001219 struct s3c_fb_win_variant *variant,
Ben Dooksec549a02009-03-31 15:25:39 -07001220 struct s3c_fb_win **res)
1221{
1222 struct fb_var_screeninfo *var;
1223 struct fb_videomode *initmode;
1224 struct s3c_fb_pd_win *windata;
1225 struct s3c_fb_win *win;
1226 struct fb_info *fbinfo;
1227 int palette_size;
1228 int ret;
1229
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001230 dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
Ben Dooksec549a02009-03-31 15:25:39 -07001231
Pawel Osciakefdc8462010-08-10 18:02:38 -07001232 init_waitqueue_head(&sfb->vsync_info.wait);
1233
Ben Dooks50a55032010-08-10 18:02:33 -07001234 palette_size = variant->palette_sz * 4;
Ben Dooksec549a02009-03-31 15:25:39 -07001235
1236 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
1237 palette_size * sizeof(u32), sfb->dev);
1238 if (!fbinfo) {
1239 dev_err(sfb->dev, "failed to allocate framebuffer\n");
1240 return -ENOENT;
1241 }
1242
1243 windata = sfb->pdata->win[win_no];
1244 initmode = &windata->win_mode;
1245
1246 WARN_ON(windata->max_bpp == 0);
1247 WARN_ON(windata->win_mode.xres == 0);
1248 WARN_ON(windata->win_mode.yres == 0);
1249
1250 win = fbinfo->par;
Pawel Osciakcd7d7e02010-08-10 18:02:35 -07001251 *res = win;
Ben Dooksec549a02009-03-31 15:25:39 -07001252 var = &fbinfo->var;
Ben Dooks50a55032010-08-10 18:02:33 -07001253 win->variant = *variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001254 win->fbinfo = fbinfo;
1255 win->parent = sfb;
1256 win->windata = windata;
1257 win->index = win_no;
1258 win->palette_buffer = (u32 *)(win + 1);
1259
1260 ret = s3c_fb_alloc_memory(sfb, win);
1261 if (ret) {
1262 dev_err(sfb->dev, "failed to allocate display memory\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001263 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001264 }
1265
1266 /* setup the r/b/g positions for the window's palette */
Ben Dooksbc2da1b2010-08-10 18:02:34 -07001267 if (win->variant.palette_16bpp) {
1268 /* Set RGB 5:6:5 as default */
1269 win->palette.r.offset = 11;
1270 win->palette.r.length = 5;
1271 win->palette.g.offset = 5;
1272 win->palette.g.length = 6;
1273 win->palette.b.offset = 0;
1274 win->palette.b.length = 5;
1275
1276 } else {
1277 /* Set 8bpp or 8bpp and 1bit alpha */
1278 win->palette.r.offset = 16;
1279 win->palette.r.length = 8;
1280 win->palette.g.offset = 8;
1281 win->palette.g.length = 8;
1282 win->palette.b.offset = 0;
1283 win->palette.b.length = 8;
1284 }
Ben Dooksec549a02009-03-31 15:25:39 -07001285
1286 /* setup the initial video mode from the window */
1287 fb_videomode_to_var(&fbinfo->var, initmode);
1288
1289 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
1290 fbinfo->fix.accel = FB_ACCEL_NONE;
1291 fbinfo->var.activate = FB_ACTIVATE_NOW;
1292 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
1293 fbinfo->var.bits_per_pixel = windata->default_bpp;
1294 fbinfo->fbops = &s3c_fb_ops;
1295 fbinfo->flags = FBINFO_FLAG_DEFAULT;
1296 fbinfo->pseudo_palette = &win->pseudo_palette;
1297
1298 /* prepare to actually start the framebuffer */
1299
1300 ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
1301 if (ret < 0) {
1302 dev_err(sfb->dev, "check_var failed on initial video params\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001303 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001304 }
1305
1306 /* create initial colour map */
1307
Ben Dooks50a55032010-08-10 18:02:33 -07001308 ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
Ben Dooksec549a02009-03-31 15:25:39 -07001309 if (ret == 0)
1310 fb_set_cmap(&fbinfo->cmap, fbinfo);
1311 else
1312 dev_err(sfb->dev, "failed to allocate fb cmap\n");
1313
1314 s3c_fb_set_par(fbinfo);
1315
1316 dev_dbg(sfb->dev, "about to register framebuffer\n");
1317
1318 /* run the check_var and set_par on our configuration. */
1319
1320 ret = register_framebuffer(fbinfo);
1321 if (ret < 0) {
1322 dev_err(sfb->dev, "failed to register framebuffer\n");
Krzysztof Heltddc518d2009-06-16 15:34:33 -07001323 return ret;
Ben Dooksec549a02009-03-31 15:25:39 -07001324 }
1325
Ben Dooksec549a02009-03-31 15:25:39 -07001326 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
1327
1328 return 0;
Ben Dooksec549a02009-03-31 15:25:39 -07001329}
1330
1331/**
1332 * s3c_fb_clear_win() - clear hardware window registers.
1333 * @sfb: The base resources for the hardware.
1334 * @win: The window to process.
1335 *
1336 * Reset the specific window registers to a known state.
1337 */
1338static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
1339{
1340 void __iomem *regs = sfb->regs;
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001341 u32 reg;
Ben Dooksec549a02009-03-31 15:25:39 -07001342
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001343 writel(0, regs + sfb->variant.wincon + (win * 4));
1344 writel(0, regs + VIDOSD_A(win, sfb->variant));
1345 writel(0, regs + VIDOSD_B(win, sfb->variant));
1346 writel(0, regs + VIDOSD_C(win, sfb->variant));
Pawel Osciaka8bdabc2010-08-10 18:02:41 -07001347 reg = readl(regs + SHADOWCON);
1348 writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
Ben Dooksec549a02009-03-31 15:25:39 -07001349}
1350
1351static int __devinit s3c_fb_probe(struct platform_device *pdev)
1352{
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001353 const struct platform_device_id *platid;
Ben Dooks50a55032010-08-10 18:02:33 -07001354 struct s3c_fb_driverdata *fbdrv;
Ben Dooksec549a02009-03-31 15:25:39 -07001355 struct device *dev = &pdev->dev;
1356 struct s3c_fb_platdata *pd;
1357 struct s3c_fb *sfb;
1358 struct resource *res;
1359 int win;
1360 int ret = 0;
1361
Jingoo Hanb73a21fc2011-04-01 07:17:27 +00001362 platid = platform_get_device_id(pdev);
1363 fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
Ben Dooks50a55032010-08-10 18:02:33 -07001364
1365 if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
1366 dev_err(dev, "too many windows, cannot attach\n");
1367 return -EINVAL;
1368 }
1369
Ben Dooksec549a02009-03-31 15:25:39 -07001370 pd = pdev->dev.platform_data;
1371 if (!pd) {
1372 dev_err(dev, "no platform data specified\n");
1373 return -EINVAL;
1374 }
1375
Mark Brown857a8df2012-01-21 13:11:49 +00001376 sfb = devm_kzalloc(dev, sizeof(struct s3c_fb), GFP_KERNEL);
Ben Dooksec549a02009-03-31 15:25:39 -07001377 if (!sfb) {
1378 dev_err(dev, "no memory for framebuffers\n");
1379 return -ENOMEM;
1380 }
1381
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001382 dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
1383
Ben Dooksec549a02009-03-31 15:25:39 -07001384 sfb->dev = dev;
1385 sfb->pdata = pd;
Ben Dooks50a55032010-08-10 18:02:33 -07001386 sfb->variant = fbdrv->variant;
Ben Dooksec549a02009-03-31 15:25:39 -07001387
Jingoo Hanb07f3bbe2011-04-11 07:25:37 +00001388 spin_lock_init(&sfb->slock);
1389
Ben Dooksec549a02009-03-31 15:25:39 -07001390 sfb->bus_clk = clk_get(dev, "lcd");
1391 if (IS_ERR(sfb->bus_clk)) {
1392 dev_err(dev, "failed to get bus clock\n");
axel lin942b8d02011-02-11 08:51:10 +00001393 ret = PTR_ERR(sfb->bus_clk);
Ben Dooksec549a02009-03-31 15:25:39 -07001394 goto err_sfb;
1395 }
1396
1397 clk_enable(sfb->bus_clk);
1398
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001399 if (!sfb->variant.has_clksel) {
1400 sfb->lcd_clk = clk_get(dev, "sclk_fimd");
1401 if (IS_ERR(sfb->lcd_clk)) {
1402 dev_err(dev, "failed to get lcd clock\n");
1403 ret = PTR_ERR(sfb->lcd_clk);
1404 goto err_bus_clk;
1405 }
1406
1407 clk_enable(sfb->lcd_clk);
1408 }
1409
Jingoo Han49592122010-12-17 16:45:46 +09001410 pm_runtime_enable(sfb->dev);
1411
Ben Dooksec549a02009-03-31 15:25:39 -07001412 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1413 if (!res) {
1414 dev_err(dev, "failed to find registers\n");
1415 ret = -ENOENT;
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001416 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001417 }
1418
Mark Brown857a8df2012-01-21 13:11:49 +00001419 sfb->regs = devm_request_and_ioremap(dev, res);
Ben Dooksec549a02009-03-31 15:25:39 -07001420 if (!sfb->regs) {
1421 dev_err(dev, "failed to map registers\n");
1422 ret = -ENXIO;
Mark Brown857a8df2012-01-21 13:11:49 +00001423 goto err_lcd_clk;
Ben Dooksec549a02009-03-31 15:25:39 -07001424 }
1425
Pawel Osciakefdc8462010-08-10 18:02:38 -07001426 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1427 if (!res) {
1428 dev_err(dev, "failed to acquire irq resource\n");
1429 ret = -ENOENT;
Mark Brown857a8df2012-01-21 13:11:49 +00001430 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001431 }
1432 sfb->irq_no = res->start;
1433 ret = request_irq(sfb->irq_no, s3c_fb_irq,
1434 0, "s3c_fb", sfb);
1435 if (ret) {
1436 dev_err(dev, "irq request failed\n");
Mark Brown857a8df2012-01-21 13:11:49 +00001437 goto err_lcd_clk;
Pawel Osciakefdc8462010-08-10 18:02:38 -07001438 }
1439
Ben Dooksec549a02009-03-31 15:25:39 -07001440 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
1441
Jingoo Han49592122010-12-17 16:45:46 +09001442 platform_set_drvdata(pdev, sfb);
1443 pm_runtime_get_sync(sfb->dev);
1444
Ben Dooksec549a02009-03-31 15:25:39 -07001445 /* setup gpio and output polarity controls */
1446
1447 pd->setup_gpio();
1448
1449 writel(pd->vidcon1, sfb->regs + VIDCON1);
1450
1451 /* zero all windows before we do anything */
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 s3c_fb_clear_win(sfb, win);
1455
Ben Dooks94947032010-08-10 18:02:32 -07001456 /* initialise colour key controls */
Ben Dooks50a55032010-08-10 18:02:33 -07001457 for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001458 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1459
1460 regs += (win * 8);
1461 writel(0xffffff, regs + WKEYCON0);
1462 writel(0xffffff, regs + WKEYCON1);
Ben Dooks94947032010-08-10 18:02:32 -07001463 }
1464
Ben Dooksec549a02009-03-31 15:25:39 -07001465 /* we have the register setup, start allocating framebuffers */
1466
Ben Dooks50a55032010-08-10 18:02:33 -07001467 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
Ben Dooksec549a02009-03-31 15:25:39 -07001468 if (!pd->win[win])
1469 continue;
1470
Maurus Cuelenaere2bb567a2010-08-10 18:02:44 -07001471 if (!pd->win[win]->win_mode.pixclock)
1472 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1473
Ben Dooks50a55032010-08-10 18:02:33 -07001474 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1475 &sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001476 if (ret < 0) {
1477 dev_err(dev, "failed to create window %d\n", win);
1478 for (; win >= 0; win--)
1479 s3c_fb_release_win(sfb, sfb->windows[win]);
Mark Brown3500b0b2011-12-27 14:16:09 +00001480 goto err_pm_runtime;
Ben Dooksec549a02009-03-31 15:25:39 -07001481 }
1482 }
1483
1484 platform_set_drvdata(pdev, sfb);
Mark Brownfe05f8b2011-12-27 14:16:07 +00001485 pm_runtime_put_sync(sfb->dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001486
1487 return 0;
1488
Mark Brown3500b0b2011-12-27 14:16:09 +00001489err_pm_runtime:
1490 pm_runtime_put_sync(sfb->dev);
Pawel Osciakefdc8462010-08-10 18:02:38 -07001491 free_irq(sfb->irq_no, sfb);
1492
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001493err_lcd_clk:
Mark Brown3500b0b2011-12-27 14:16:09 +00001494 pm_runtime_disable(sfb->dev);
1495
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001496 if (!sfb->variant.has_clksel) {
1497 clk_disable(sfb->lcd_clk);
1498 clk_put(sfb->lcd_clk);
1499 }
1500
1501err_bus_clk:
Ben Dooksec549a02009-03-31 15:25:39 -07001502 clk_disable(sfb->bus_clk);
1503 clk_put(sfb->bus_clk);
1504
1505err_sfb:
Ben Dooksec549a02009-03-31 15:25:39 -07001506 return ret;
1507}
1508
1509/**
1510 * s3c_fb_remove() - Cleanup on module finalisation
1511 * @pdev: The platform device we are bound to.
1512 *
1513 * Shutdown and then release all the resources that the driver allocated
1514 * on initialisation.
1515 */
1516static int __devexit s3c_fb_remove(struct platform_device *pdev)
1517{
1518 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1519 int win;
1520
Mark Brownfe05f8b2011-12-27 14:16:07 +00001521 pm_runtime_get_sync(sfb->dev);
1522
Pawel Osciakc42b1102009-07-29 15:02:10 -07001523 for (win = 0; win < S3C_FB_MAX_WIN; win++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001524 if (sfb->windows[win])
1525 s3c_fb_release_win(sfb, sfb->windows[win]);
Ben Dooksec549a02009-03-31 15:25:39 -07001526
Pawel Osciakefdc8462010-08-10 18:02:38 -07001527 free_irq(sfb->irq_no, sfb);
1528
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001529 if (!sfb->variant.has_clksel) {
1530 clk_disable(sfb->lcd_clk);
1531 clk_put(sfb->lcd_clk);
1532 }
1533
Ben Dooksec549a02009-03-31 15:25:39 -07001534 clk_disable(sfb->bus_clk);
1535 clk_put(sfb->bus_clk);
1536
Jingoo Han49592122010-12-17 16:45:46 +09001537 pm_runtime_put_sync(sfb->dev);
1538 pm_runtime_disable(sfb->dev);
1539
Ben Dooksec549a02009-03-31 15:25:39 -07001540 return 0;
1541}
1542
Mark Brownf4f51472011-12-27 14:16:10 +00001543#ifdef CONFIG_PM_SLEEP
Jingoo Han49592122010-12-17 16:45:46 +09001544static int s3c_fb_suspend(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001545{
Jingoo Han49592122010-12-17 16:45:46 +09001546 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001547 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1548 struct s3c_fb_win *win;
1549 int win_no;
1550
Pawel Osciakc42b1102009-07-29 15:02:10 -07001551 for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
Ben Dooksec549a02009-03-31 15:25:39 -07001552 win = sfb->windows[win_no];
1553 if (!win)
1554 continue;
1555
1556 /* use the blank function to push into power-down */
1557 s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
1558 }
1559
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001560 if (!sfb->variant.has_clksel)
1561 clk_disable(sfb->lcd_clk);
1562
Ben Dooksec549a02009-03-31 15:25:39 -07001563 clk_disable(sfb->bus_clk);
1564 return 0;
1565}
1566
Jingoo Han49592122010-12-17 16:45:46 +09001567static int s3c_fb_resume(struct device *dev)
Ben Dooksec549a02009-03-31 15:25:39 -07001568{
Jingoo Han49592122010-12-17 16:45:46 +09001569 struct platform_device *pdev = to_platform_device(dev);
Ben Dooksec549a02009-03-31 15:25:39 -07001570 struct s3c_fb *sfb = platform_get_drvdata(pdev);
Marek Szyprowski17663e52009-05-28 14:34:35 -07001571 struct s3c_fb_platdata *pd = sfb->pdata;
Ben Dooksec549a02009-03-31 15:25:39 -07001572 struct s3c_fb_win *win;
1573 int win_no;
1574
1575 clk_enable(sfb->bus_clk);
1576
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001577 if (!sfb->variant.has_clksel)
1578 clk_enable(sfb->lcd_clk);
1579
Jingoo Han6aa96812011-05-24 08:55:31 +00001580 /* setup gpio and output polarity controls */
1581 pd->setup_gpio();
Marek Szyprowski17663e52009-05-28 14:34:35 -07001582 writel(pd->vidcon1, sfb->regs + VIDCON1);
1583
1584 /* zero all windows before we do anything */
Ben Dooks50a55032010-08-10 18:02:33 -07001585 for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
Marek Szyprowski17663e52009-05-28 14:34:35 -07001586 s3c_fb_clear_win(sfb, win_no);
1587
Ben Dooks50a55032010-08-10 18:02:33 -07001588 for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001589 void __iomem *regs = sfb->regs + sfb->variant.keycon;
Jingoo Hanff8c9102011-12-08 18:08:00 +09001590 win = sfb->windows[win_no];
1591 if (!win)
1592 continue;
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001593
Jingoo Hanff8c9102011-12-08 18:08:00 +09001594 shadow_protect_win(win, 1);
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001595 regs += (win_no * 8);
1596 writel(0xffffff, regs + WKEYCON0);
1597 writel(0xffffff, regs + WKEYCON1);
Jingoo Hanff8c9102011-12-08 18:08:00 +09001598 shadow_protect_win(win, 0);
Ben Dooks94947032010-08-10 18:02:32 -07001599 }
1600
Marek Szyprowski17663e52009-05-28 14:34:35 -07001601 /* restore framebuffers */
Ben Dooksec549a02009-03-31 15:25:39 -07001602 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1603 win = sfb->windows[win_no];
1604 if (!win)
1605 continue;
1606
1607 dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
1608 s3c_fb_set_par(win->fbinfo);
1609 }
1610
1611 return 0;
1612}
Ben Dooksec549a02009-03-31 15:25:39 -07001613#endif
1614
Mark Brownf4f51472011-12-27 14:16:10 +00001615#ifdef CONFIG_PM_RUNTIME
1616static int s3c_fb_runtime_suspend(struct device *dev)
1617{
1618 struct platform_device *pdev = to_platform_device(dev);
1619 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1620
1621 if (!sfb->variant.has_clksel)
1622 clk_disable(sfb->lcd_clk);
1623
1624 clk_disable(sfb->bus_clk);
1625
1626 return 0;
1627}
1628
1629static int s3c_fb_runtime_resume(struct device *dev)
1630{
1631 struct platform_device *pdev = to_platform_device(dev);
1632 struct s3c_fb *sfb = platform_get_drvdata(pdev);
1633 struct s3c_fb_platdata *pd = sfb->pdata;
1634
1635 clk_enable(sfb->bus_clk);
1636
1637 if (!sfb->variant.has_clksel)
1638 clk_enable(sfb->lcd_clk);
1639
1640 /* setup gpio and output polarity controls */
1641 pd->setup_gpio();
1642 writel(pd->vidcon1, sfb->regs + VIDCON1);
1643
1644 return 0;
1645}
1646#endif
Ben Dooks50a55032010-08-10 18:02:33 -07001647
1648#define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
1649#define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
1650
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001651static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
Ben Dooks50a55032010-08-10 18:02:33 -07001652 [0] = {
1653 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001654 .osd_size_off = 0x8,
Ben Dooks50a55032010-08-10 18:02:33 -07001655 .palette_sz = 256,
Jingoo Hancd74eba2011-04-22 07:09:40 +00001656 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1657 VALID_BPP(18) | VALID_BPP(24)),
Ben Dooks50a55032010-08-10 18:02:33 -07001658 },
1659 [1] = {
1660 .has_osd_c = 1,
1661 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001662 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001663 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001664 .palette_sz = 256,
1665 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1666 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001667 VALID_BPP(24) | VALID_BPP(25) |
1668 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001669 },
1670 [2] = {
1671 .has_osd_c = 1,
1672 .has_osd_d = 1,
Jingoo Hanc9d503e2011-04-22 07:09:31 +00001673 .osd_size_off = 0xc,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001674 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001675 .palette_sz = 16,
1676 .palette_16bpp = 1,
1677 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1678 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001679 VALID_BPP(24) | VALID_BPP(25) |
1680 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001681 },
1682 [3] = {
1683 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001684 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001685 .palette_sz = 16,
1686 .palette_16bpp = 1,
1687 .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
1688 VALID_BPP(18) | VALID_BPP(19) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001689 VALID_BPP(24) | VALID_BPP(25) |
1690 VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001691 },
1692 [4] = {
1693 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001694 .has_osd_alpha = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001695 .palette_sz = 4,
1696 .palette_16bpp = 1,
1697 .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
1698 VALID_BPP(16) | VALID_BPP(18) |
Jingoo Hancd74eba2011-04-22 07:09:40 +00001699 VALID_BPP(19) | VALID_BPP(24) |
1700 VALID_BPP(25) | VALID_BPP(28)),
Ben Dooks50a55032010-08-10 18:02:33 -07001701 },
1702};
1703
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001704static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
1705 [0] = {
1706 .has_osd_c = 1,
1707 .osd_size_off = 0x8,
1708 .palette_sz = 256,
1709 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1710 VALID_BPP(15) | VALID_BPP(16) |
1711 VALID_BPP(18) | VALID_BPP(19) |
1712 VALID_BPP(24) | VALID_BPP(25) |
1713 VALID_BPP(32)),
1714 },
1715 [1] = {
1716 .has_osd_c = 1,
1717 .has_osd_d = 1,
1718 .osd_size_off = 0xc,
1719 .has_osd_alpha = 1,
1720 .palette_sz = 256,
1721 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1722 VALID_BPP(15) | VALID_BPP(16) |
1723 VALID_BPP(18) | VALID_BPP(19) |
1724 VALID_BPP(24) | VALID_BPP(25) |
1725 VALID_BPP(32)),
1726 },
1727 [2] = {
1728 .has_osd_c = 1,
1729 .has_osd_d = 1,
1730 .osd_size_off = 0xc,
1731 .has_osd_alpha = 1,
1732 .palette_sz = 256,
1733 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1734 VALID_BPP(15) | VALID_BPP(16) |
1735 VALID_BPP(18) | VALID_BPP(19) |
1736 VALID_BPP(24) | VALID_BPP(25) |
1737 VALID_BPP(32)),
1738 },
1739 [3] = {
1740 .has_osd_c = 1,
1741 .has_osd_alpha = 1,
1742 .palette_sz = 256,
1743 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1744 VALID_BPP(15) | VALID_BPP(16) |
1745 VALID_BPP(18) | VALID_BPP(19) |
1746 VALID_BPP(24) | VALID_BPP(25) |
1747 VALID_BPP(32)),
1748 },
1749 [4] = {
1750 .has_osd_c = 1,
1751 .has_osd_alpha = 1,
1752 .palette_sz = 256,
1753 .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
1754 VALID_BPP(15) | VALID_BPP(16) |
1755 VALID_BPP(18) | VALID_BPP(19) |
1756 VALID_BPP(24) | VALID_BPP(25) |
1757 VALID_BPP(32)),
1758 },
1759};
1760
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001761static struct s3c_fb_driverdata s3c_fb_data_64xx = {
Ben Dooks50a55032010-08-10 18:02:33 -07001762 .variant = {
1763 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001764 .vidtcon = VIDTCON0,
1765 .wincon = WINCON(0),
1766 .winmap = WINxMAP(0),
1767 .keycon = WKEYCON,
1768 .osd = VIDOSD_BASE,
1769 .osd_stride = 16,
1770 .buf_start = VIDW_BUF_START(0),
1771 .buf_size = VIDW_BUF_SIZE(0),
1772 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001773
1774 .palette = {
1775 [0] = 0x400,
1776 [1] = 0x800,
1777 [2] = 0x300,
1778 [3] = 0x320,
1779 [4] = 0x340,
1780 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001781
1782 .has_prtcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001783 .has_clksel = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001784 },
1785 .win[0] = &s3c_fb_data_64xx_wins[0],
1786 .win[1] = &s3c_fb_data_64xx_wins[1],
1787 .win[2] = &s3c_fb_data_64xx_wins[2],
1788 .win[3] = &s3c_fb_data_64xx_wins[3],
1789 .win[4] = &s3c_fb_data_64xx_wins[4],
1790};
1791
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001792static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001793 .variant = {
1794 .nr_windows = 5,
1795 .vidtcon = VIDTCON0,
1796 .wincon = WINCON(0),
1797 .winmap = WINxMAP(0),
1798 .keycon = WKEYCON,
1799 .osd = VIDOSD_BASE,
1800 .osd_stride = 16,
1801 .buf_start = VIDW_BUF_START(0),
1802 .buf_size = VIDW_BUF_SIZE(0),
1803 .buf_end = VIDW_BUF_END(0),
1804
1805 .palette = {
1806 [0] = 0x2400,
1807 [1] = 0x2800,
1808 [2] = 0x2c00,
1809 [3] = 0x3000,
1810 [4] = 0x3400,
1811 },
Pawel Osciak067b2262010-08-10 18:02:38 -07001812
1813 .has_prtcon = 1,
Jingoo Hanf7f31e52012-01-27 14:47:22 +09001814 .has_blendcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001815 .has_clksel = 1,
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001816 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001817 .win[0] = &s3c_fb_data_s5p_wins[0],
1818 .win[1] = &s3c_fb_data_s5p_wins[1],
1819 .win[2] = &s3c_fb_data_s5p_wins[2],
1820 .win[3] = &s3c_fb_data_s5p_wins[3],
1821 .win[4] = &s3c_fb_data_s5p_wins[4],
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001822};
1823
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001824static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
Ben Dooks50a55032010-08-10 18:02:33 -07001825 .variant = {
1826 .nr_windows = 5,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001827 .vidtcon = VIDTCON0,
1828 .wincon = WINCON(0),
1829 .winmap = WINxMAP(0),
1830 .keycon = WKEYCON,
1831 .osd = VIDOSD_BASE,
1832 .osd_stride = 16,
1833 .buf_start = VIDW_BUF_START(0),
1834 .buf_size = VIDW_BUF_SIZE(0),
1835 .buf_end = VIDW_BUF_END(0),
Ben Dooks50a55032010-08-10 18:02:33 -07001836
1837 .palette = {
1838 [0] = 0x2400,
1839 [1] = 0x2800,
1840 [2] = 0x2c00,
1841 [3] = 0x3000,
1842 [4] = 0x3400,
1843 },
Pawel Osciakf5ec5462010-08-10 18:02:40 -07001844
1845 .has_shadowcon = 1,
Jingoo Hanf7f31e52012-01-27 14:47:22 +09001846 .has_blendcon = 1,
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001847 .has_clksel = 1,
1848 },
1849 .win[0] = &s3c_fb_data_s5p_wins[0],
1850 .win[1] = &s3c_fb_data_s5p_wins[1],
1851 .win[2] = &s3c_fb_data_s5p_wins[2],
1852 .win[3] = &s3c_fb_data_s5p_wins[3],
1853 .win[4] = &s3c_fb_data_s5p_wins[4],
1854};
1855
1856static struct s3c_fb_driverdata s3c_fb_data_exynos4 = {
1857 .variant = {
1858 .nr_windows = 5,
1859 .vidtcon = VIDTCON0,
1860 .wincon = WINCON(0),
1861 .winmap = WINxMAP(0),
1862 .keycon = WKEYCON,
1863 .osd = VIDOSD_BASE,
1864 .osd_stride = 16,
1865 .buf_start = VIDW_BUF_START(0),
1866 .buf_size = VIDW_BUF_SIZE(0),
1867 .buf_end = VIDW_BUF_END(0),
1868
1869 .palette = {
1870 [0] = 0x2400,
1871 [1] = 0x2800,
1872 [2] = 0x2c00,
1873 [3] = 0x3000,
1874 [4] = 0x3400,
1875 },
1876
1877 .has_shadowcon = 1,
Jingoo Hanf7f31e52012-01-27 14:47:22 +09001878 .has_blendcon = 1,
Ben Dooks50a55032010-08-10 18:02:33 -07001879 },
Jingoo Hanaf4a8352011-04-22 07:09:48 +00001880 .win[0] = &s3c_fb_data_s5p_wins[0],
1881 .win[1] = &s3c_fb_data_s5p_wins[1],
1882 .win[2] = &s3c_fb_data_s5p_wins[2],
1883 .win[3] = &s3c_fb_data_s5p_wins[3],
1884 .win[4] = &s3c_fb_data_s5p_wins[4],
Ben Dooks50a55032010-08-10 18:02:33 -07001885};
1886
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001887/* S3C2443/S3C2416 style hardware */
Marek Szyprowski8cfdcb22010-08-10 18:02:42 -07001888static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001889 .variant = {
1890 .nr_windows = 2,
1891 .is_2443 = 1,
1892
1893 .vidtcon = 0x08,
1894 .wincon = 0x14,
1895 .winmap = 0xd0,
1896 .keycon = 0xb0,
1897 .osd = 0x28,
1898 .osd_stride = 12,
1899 .buf_start = 0x64,
1900 .buf_size = 0x94,
1901 .buf_end = 0x7c,
1902
1903 .palette = {
1904 [0] = 0x400,
1905 [1] = 0x800,
1906 },
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001907 .has_clksel = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001908 },
1909 .win[0] = &(struct s3c_fb_win_variant) {
1910 .palette_sz = 256,
1911 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1912 },
1913 .win[1] = &(struct s3c_fb_win_variant) {
1914 .has_osd_c = 1,
Pawel Osciakf676ec22010-08-10 18:02:40 -07001915 .has_osd_alpha = 1,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001916 .palette_sz = 256,
1917 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1918 VALID_BPP(18) | VALID_BPP(19) |
1919 VALID_BPP(24) | VALID_BPP(25) |
1920 VALID_BPP(28)),
1921 },
1922};
1923
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001924static struct s3c_fb_driverdata s3c_fb_data_s5p64x0 = {
1925 .variant = {
1926 .nr_windows = 3,
1927 .vidtcon = VIDTCON0,
1928 .wincon = WINCON(0),
1929 .winmap = WINxMAP(0),
1930 .keycon = WKEYCON,
1931 .osd = VIDOSD_BASE,
1932 .osd_stride = 16,
1933 .buf_start = VIDW_BUF_START(0),
1934 .buf_size = VIDW_BUF_SIZE(0),
1935 .buf_end = VIDW_BUF_END(0),
1936
1937 .palette = {
1938 [0] = 0x2400,
1939 [1] = 0x2800,
1940 [2] = 0x2c00,
1941 },
Jingoo Hanf7f31e52012-01-27 14:47:22 +09001942
1943 .has_blendcon = 1,
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001944 },
1945 .win[0] = &s3c_fb_data_s5p_wins[0],
1946 .win[1] = &s3c_fb_data_s5p_wins[1],
1947 .win[2] = &s3c_fb_data_s5p_wins[2],
1948};
1949
Ben Dooks50a55032010-08-10 18:02:33 -07001950static struct platform_device_id s3c_fb_driver_ids[] = {
1951 {
1952 .name = "s3c-fb",
1953 .driver_data = (unsigned long)&s3c_fb_data_64xx,
1954 }, {
Pawel Osciak4e591ac2010-08-10 18:02:36 -07001955 .name = "s5pc100-fb",
1956 .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
1957 }, {
1958 .name = "s5pv210-fb",
1959 .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001960 }, {
Jingoo Hanb5480ed2011-08-22 12:16:04 +09001961 .name = "exynos4-fb",
1962 .driver_data = (unsigned long)&s3c_fb_data_exynos4,
1963 }, {
Ben Dooksc4bb6ff2010-08-10 18:02:34 -07001964 .name = "s3c2443-fb",
1965 .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
Ajay Kumar21b5a3a2011-09-09 14:00:51 -04001966 }, {
1967 .name = "s5p64x0-fb",
1968 .driver_data = (unsigned long)&s3c_fb_data_s5p64x0,
Ben Dooks50a55032010-08-10 18:02:33 -07001969 },
1970 {},
1971};
1972MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
1973
Mark Brownf4f51472011-12-27 14:16:10 +00001974static const struct dev_pm_ops s3cfb_pm_ops = {
1975 SET_SYSTEM_SLEEP_PM_OPS(s3c_fb_suspend, s3c_fb_resume)
1976 SET_RUNTIME_PM_OPS(s3c_fb_runtime_suspend, s3c_fb_runtime_resume,
1977 NULL)
1978};
Jingoo Han49592122010-12-17 16:45:46 +09001979
Ben Dooksec549a02009-03-31 15:25:39 -07001980static struct platform_driver s3c_fb_driver = {
1981 .probe = s3c_fb_probe,
Peter Korsgaard3163eaba2009-09-22 16:47:55 -07001982 .remove = __devexit_p(s3c_fb_remove),
Ben Dooks50a55032010-08-10 18:02:33 -07001983 .id_table = s3c_fb_driver_ids,
Ben Dooksec549a02009-03-31 15:25:39 -07001984 .driver = {
1985 .name = "s3c-fb",
1986 .owner = THIS_MODULE,
Mark Brownfe05f8b2011-12-27 14:16:07 +00001987 .pm = &s3cfb_pm_ops,
Ben Dooksec549a02009-03-31 15:25:39 -07001988 },
1989};
1990
Axel Lin4277f2c2011-11-26 10:25:54 +08001991module_platform_driver(s3c_fb_driver);
Ben Dooksec549a02009-03-31 15:25:39 -07001992
1993MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1994MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
1995MODULE_LICENSE("GPL");
1996MODULE_ALIAS("platform:s3c-fb");