]>
Commit | Line | Data |
---|---|---|
ec549a0f BD |
1 | /* linux/drivers/video/s3c-fb.c |
2 | * | |
3 | * Copyright 2008 Openmoko Inc. | |
50a5503a | 4 | * Copyright 2008-2010 Simtec Electronics |
ec549a0f BD |
5 | * 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 | |
c4bb6ffa | 12 | * published by the Free Software FoundatIon. |
ec549a0f BD |
13 | */ |
14 | ||
15 | #include <linux/kernel.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/platform_device.h> | |
18 | #include <linux/dma-mapping.h> | |
5a0e3ad6 | 19 | #include <linux/slab.h> |
ec549a0f | 20 | #include <linux/init.h> |
ec549a0f BD |
21 | #include <linux/clk.h> |
22 | #include <linux/fb.h> | |
23 | #include <linux/io.h> | |
24 | ||
25 | #include <mach/map.h> | |
c4bb6ffa | 26 | #include <plat/regs-fb-v4.h> |
ec549a0f BD |
27 | #include <plat/fb.h> |
28 | ||
29 | /* This driver will export a number of framebuffer interfaces depending | |
30 | * on the configuration passed in via the platform data. Each fb instance | |
31 | * maps to a hardware window. Currently there is no support for runtime | |
32 | * setting of the alpha-blending functions that each window has, so only | |
33 | * window 0 is actually useful. | |
34 | * | |
35 | * Window 0 is treated specially, it is used for the basis of the LCD | |
36 | * output timings and as the control for the output power-down state. | |
37 | */ | |
38 | ||
50a5503a BD |
39 | /* note, the previous use of <mach/regs-fb.h> to get platform specific data |
40 | * has been replaced by using the platform device name to pick the correct | |
41 | * configuration data for the system. | |
ec549a0f BD |
42 | */ |
43 | ||
44 | #ifdef CONFIG_FB_S3C_DEBUG_REGWRITE | |
45 | #undef writel | |
46 | #define writel(v, r) do { \ | |
47 | printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \ | |
48 | __raw_writel(v, r); } while(0) | |
49 | #endif /* FB_S3C_DEBUG_REGWRITE */ | |
50 | ||
51 | struct s3c_fb; | |
52 | ||
50a5503a BD |
53 | #define VALID_BPP(x) (1 << ((x) - 1)) |
54 | ||
c4bb6ffa BD |
55 | #define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride)) |
56 | #define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00) | |
57 | #define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04) | |
58 | #define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08) | |
59 | #define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C) | |
60 | ||
50a5503a BD |
61 | /** |
62 | * struct s3c_fb_variant - fb variant information | |
c4bb6ffa | 63 | * @is_2443: Set if S3C2443/S3C2416 style hardware. |
50a5503a | 64 | * @nr_windows: The number of windows. |
c4bb6ffa BD |
65 | * @vidtcon: The base for the VIDTCONx registers |
66 | * @wincon: The base for the WINxCON registers. | |
67 | * @winmap: The base for the WINxMAP registers. | |
68 | * @keycon: The abse for the WxKEYCON registers. | |
69 | * @buf_start: Offset of buffer start registers. | |
70 | * @buf_size: Offset of buffer size registers. | |
71 | * @buf_end: Offset of buffer end registers. | |
72 | * @osd: The base for the OSD registers. | |
50a5503a BD |
73 | * @palette: Address of palette memory, or 0 if none. |
74 | */ | |
75 | struct s3c_fb_variant { | |
c4bb6ffa | 76 | unsigned int is_2443:1; |
50a5503a | 77 | unsigned short nr_windows; |
c4bb6ffa BD |
78 | unsigned short vidtcon; |
79 | unsigned short wincon; | |
80 | unsigned short winmap; | |
81 | unsigned short keycon; | |
82 | unsigned short buf_start; | |
83 | unsigned short buf_end; | |
84 | unsigned short buf_size; | |
85 | unsigned short osd; | |
86 | unsigned short osd_stride; | |
50a5503a BD |
87 | unsigned short palette[S3C_FB_MAX_WIN]; |
88 | }; | |
89 | ||
90 | /** | |
91 | * struct s3c_fb_win_variant | |
92 | * @has_osd_c: Set if has OSD C register. | |
93 | * @has_osd_d: Set if has OSD D register. | |
94 | * @palette_sz: Size of palette in entries. | |
95 | * @palette_16bpp: Set if palette is 16bits wide. | |
96 | * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel. | |
97 | * | |
98 | * valid_bpp bit x is set if (x+1)BPP is supported. | |
99 | */ | |
100 | struct s3c_fb_win_variant { | |
101 | unsigned int has_osd_c:1; | |
102 | unsigned int has_osd_d:1; | |
103 | unsigned int palette_16bpp:1; | |
104 | unsigned short palette_sz; | |
105 | u32 valid_bpp; | |
106 | }; | |
107 | ||
108 | /** | |
109 | * struct s3c_fb_driverdata - per-device type driver data for init time. | |
110 | * @variant: The variant information for this driver. | |
111 | * @win: The window information for each window. | |
112 | */ | |
113 | struct s3c_fb_driverdata { | |
114 | struct s3c_fb_variant variant; | |
115 | struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN]; | |
116 | }; | |
117 | ||
bc2da1b6 BD |
118 | /** |
119 | * struct s3c_fb_palette - palette information | |
120 | * @r: Red bitfield. | |
121 | * @g: Green bitfield. | |
122 | * @b: Blue bitfield. | |
123 | * @a: Alpha bitfield. | |
124 | */ | |
125 | struct s3c_fb_palette { | |
126 | struct fb_bitfield r; | |
127 | struct fb_bitfield g; | |
128 | struct fb_bitfield b; | |
129 | struct fb_bitfield a; | |
130 | }; | |
131 | ||
ec549a0f BD |
132 | /** |
133 | * struct s3c_fb_win - per window private data for each framebuffer. | |
134 | * @windata: The platform data supplied for the window configuration. | |
135 | * @parent: The hardware that this window is part of. | |
136 | * @fbinfo: Pointer pack to the framebuffer info for this window. | |
50a5503a | 137 | * @varint: The variant information for this window. |
ec549a0f BD |
138 | * @palette_buffer: Buffer/cache to hold palette entries. |
139 | * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/ | |
140 | * @index: The window number of this window. | |
141 | * @palette: The bitfields for changing r/g/b into a hardware palette entry. | |
142 | */ | |
143 | struct s3c_fb_win { | |
144 | struct s3c_fb_pd_win *windata; | |
145 | struct s3c_fb *parent; | |
146 | struct fb_info *fbinfo; | |
147 | struct s3c_fb_palette palette; | |
50a5503a | 148 | struct s3c_fb_win_variant variant; |
ec549a0f BD |
149 | |
150 | u32 *palette_buffer; | |
151 | u32 pseudo_palette[16]; | |
152 | unsigned int index; | |
153 | }; | |
154 | ||
155 | /** | |
156 | * struct s3c_fb - overall hardware state of the hardware | |
157 | * @dev: The device that we bound to, for printing, etc. | |
158 | * @regs_res: The resource we claimed for the IO registers. | |
159 | * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk. | |
160 | * @regs: The mapped hardware registers. | |
50a5503a | 161 | * @variant: Variant information for this hardware. |
ec549a0f BD |
162 | * @enabled: A bitmask of enabled hardware windows. |
163 | * @pdata: The platform configuration data passed with the device. | |
164 | * @windows: The hardware windows that have been claimed. | |
165 | */ | |
166 | struct s3c_fb { | |
167 | struct device *dev; | |
168 | struct resource *regs_res; | |
169 | struct clk *bus_clk; | |
170 | void __iomem *regs; | |
50a5503a | 171 | struct s3c_fb_variant variant; |
ec549a0f BD |
172 | |
173 | unsigned char enabled; | |
174 | ||
175 | struct s3c_fb_platdata *pdata; | |
176 | struct s3c_fb_win *windows[S3C_FB_MAX_WIN]; | |
177 | }; | |
178 | ||
179 | /** | |
50a5503a BD |
180 | * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode. |
181 | * @win: The device window. | |
182 | * @bpp: The bit depth. | |
ec549a0f | 183 | */ |
50a5503a | 184 | static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp) |
ec549a0f | 185 | { |
50a5503a | 186 | return win->variant.valid_bpp & VALID_BPP(bpp); |
ec549a0f BD |
187 | } |
188 | ||
189 | /** | |
190 | * s3c_fb_check_var() - framebuffer layer request to verify a given mode. | |
191 | * @var: The screen information to verify. | |
192 | * @info: The framebuffer device. | |
193 | * | |
194 | * Framebuffer layer call to verify the given information and allow us to | |
195 | * update various information depending on the hardware capabilities. | |
196 | */ | |
197 | static int s3c_fb_check_var(struct fb_var_screeninfo *var, | |
198 | struct fb_info *info) | |
199 | { | |
200 | struct s3c_fb_win *win = info->par; | |
201 | struct s3c_fb_pd_win *windata = win->windata; | |
202 | struct s3c_fb *sfb = win->parent; | |
203 | ||
204 | dev_dbg(sfb->dev, "checking parameters\n"); | |
205 | ||
206 | var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres); | |
207 | var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres); | |
208 | ||
50a5503a | 209 | if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) { |
ec549a0f BD |
210 | dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n", |
211 | win->index, var->bits_per_pixel); | |
212 | return -EINVAL; | |
213 | } | |
214 | ||
215 | /* always ensure these are zero, for drop through cases below */ | |
216 | var->transp.offset = 0; | |
217 | var->transp.length = 0; | |
218 | ||
219 | switch (var->bits_per_pixel) { | |
220 | case 1: | |
221 | case 2: | |
222 | case 4: | |
223 | case 8: | |
50a5503a | 224 | if (sfb->variant.palette[win->index] != 0) { |
ec549a0f BD |
225 | /* non palletised, A:1,R:2,G:3,B:2 mode */ |
226 | var->red.offset = 4; | |
227 | var->green.offset = 2; | |
228 | var->blue.offset = 0; | |
229 | var->red.length = 5; | |
230 | var->green.length = 3; | |
231 | var->blue.length = 2; | |
232 | var->transp.offset = 7; | |
233 | var->transp.length = 1; | |
234 | } else { | |
235 | var->red.offset = 0; | |
236 | var->red.length = var->bits_per_pixel; | |
237 | var->green = var->red; | |
238 | var->blue = var->red; | |
239 | } | |
240 | break; | |
241 | ||
242 | case 19: | |
243 | /* 666 with one bit alpha/transparency */ | |
244 | var->transp.offset = 18; | |
245 | var->transp.length = 1; | |
246 | case 18: | |
247 | var->bits_per_pixel = 32; | |
248 | ||
249 | /* 666 format */ | |
250 | var->red.offset = 12; | |
251 | var->green.offset = 6; | |
252 | var->blue.offset = 0; | |
253 | var->red.length = 6; | |
254 | var->green.length = 6; | |
255 | var->blue.length = 6; | |
256 | break; | |
257 | ||
258 | case 16: | |
259 | /* 16 bpp, 565 format */ | |
260 | var->red.offset = 11; | |
261 | var->green.offset = 5; | |
262 | var->blue.offset = 0; | |
263 | var->red.length = 5; | |
264 | var->green.length = 6; | |
265 | var->blue.length = 5; | |
266 | break; | |
267 | ||
268 | case 28: | |
269 | case 25: | |
270 | var->transp.length = var->bits_per_pixel - 24; | |
271 | var->transp.offset = 24; | |
272 | /* drop through */ | |
273 | case 24: | |
274 | /* our 24bpp is unpacked, so 32bpp */ | |
275 | var->bits_per_pixel = 32; | |
276 | case 32: | |
277 | var->red.offset = 16; | |
278 | var->red.length = 8; | |
279 | var->green.offset = 8; | |
280 | var->green.length = 8; | |
281 | var->blue.offset = 0; | |
282 | var->blue.length = 8; | |
283 | break; | |
284 | ||
285 | default: | |
286 | dev_err(sfb->dev, "invalid bpp\n"); | |
287 | } | |
288 | ||
289 | dev_dbg(sfb->dev, "%s: verified parameters\n", __func__); | |
290 | return 0; | |
291 | } | |
292 | ||
293 | /** | |
294 | * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock. | |
295 | * @sfb: The hardware state. | |
296 | * @pixclock: The pixel clock wanted, in picoseconds. | |
297 | * | |
298 | * Given the specified pixel clock, work out the necessary divider to get | |
299 | * close to the output frequency. | |
300 | */ | |
eb29a5cc | 301 | static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk) |
ec549a0f BD |
302 | { |
303 | unsigned long clk = clk_get_rate(sfb->bus_clk); | |
eb29a5cc | 304 | unsigned long long tmp; |
ec549a0f BD |
305 | unsigned int result; |
306 | ||
eb29a5cc MB |
307 | tmp = (unsigned long long)clk; |
308 | tmp *= pixclk; | |
309 | ||
310 | do_div(tmp, 1000000000UL); | |
311 | result = (unsigned int)tmp / 1000; | |
ec549a0f BD |
312 | |
313 | dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n", | |
314 | pixclk, clk, result, clk / result); | |
315 | ||
316 | return result; | |
317 | } | |
318 | ||
319 | /** | |
320 | * s3c_fb_align_word() - align pixel count to word boundary | |
321 | * @bpp: The number of bits per pixel | |
322 | * @pix: The value to be aligned. | |
323 | * | |
324 | * Align the given pixel count so that it will start on an 32bit word | |
325 | * boundary. | |
326 | */ | |
327 | static int s3c_fb_align_word(unsigned int bpp, unsigned int pix) | |
328 | { | |
329 | int pix_per_word; | |
330 | ||
331 | if (bpp > 16) | |
332 | return pix; | |
333 | ||
334 | pix_per_word = (8 * 32) / bpp; | |
335 | return ALIGN(pix, pix_per_word); | |
336 | } | |
337 | ||
338 | /** | |
339 | * s3c_fb_set_par() - framebuffer request to set new framebuffer state. | |
340 | * @info: The framebuffer to change. | |
341 | * | |
342 | * Framebuffer layer request to set a new mode for the specified framebuffer | |
343 | */ | |
344 | static int s3c_fb_set_par(struct fb_info *info) | |
345 | { | |
346 | struct fb_var_screeninfo *var = &info->var; | |
347 | struct s3c_fb_win *win = info->par; | |
348 | struct s3c_fb *sfb = win->parent; | |
349 | void __iomem *regs = sfb->regs; | |
c4bb6ffa | 350 | void __iomem *buf = regs; |
ec549a0f | 351 | int win_no = win->index; |
600ce1a0 | 352 | u32 osdc_data = 0; |
ec549a0f BD |
353 | u32 data; |
354 | u32 pagewidth; | |
355 | int clkdiv; | |
356 | ||
357 | dev_dbg(sfb->dev, "setting framebuffer parameters\n"); | |
358 | ||
359 | switch (var->bits_per_pixel) { | |
360 | case 32: | |
361 | case 24: | |
362 | case 16: | |
363 | case 12: | |
364 | info->fix.visual = FB_VISUAL_TRUECOLOR; | |
365 | break; | |
366 | case 8: | |
50a5503a | 367 | if (win->variant.palette_sz >= 256) |
ec549a0f BD |
368 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
369 | else | |
370 | info->fix.visual = FB_VISUAL_TRUECOLOR; | |
371 | break; | |
372 | case 1: | |
373 | info->fix.visual = FB_VISUAL_MONO01; | |
374 | break; | |
375 | default: | |
376 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; | |
377 | break; | |
378 | } | |
379 | ||
380 | info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8; | |
381 | ||
382 | /* disable the window whilst we update it */ | |
383 | writel(0, regs + WINCON(win_no)); | |
384 | ||
ad04490a | 385 | /* use platform specified window as the basis for the lcd timings */ |
ec549a0f | 386 | |
ad04490a | 387 | if (win_no == sfb->pdata->default_win) { |
eb29a5cc | 388 | clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock); |
ec549a0f BD |
389 | |
390 | data = sfb->pdata->vidcon0; | |
391 | data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR); | |
392 | ||
393 | if (clkdiv > 1) | |
394 | data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR; | |
395 | else | |
396 | data &= ~VIDCON0_CLKDIR; /* 1:1 clock */ | |
397 | ||
398 | /* write the timing data to the panel */ | |
399 | ||
c4bb6ffa BD |
400 | if (sfb->variant.is_2443) |
401 | data |= (1 << 5); | |
402 | ||
ec549a0f BD |
403 | data |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
404 | writel(data, regs + VIDCON0); | |
405 | ||
406 | data = VIDTCON0_VBPD(var->upper_margin - 1) | | |
407 | VIDTCON0_VFPD(var->lower_margin - 1) | | |
408 | VIDTCON0_VSPW(var->vsync_len - 1); | |
409 | ||
c4bb6ffa | 410 | writel(data, regs + sfb->variant.vidtcon); |
ec549a0f BD |
411 | |
412 | data = VIDTCON1_HBPD(var->left_margin - 1) | | |
413 | VIDTCON1_HFPD(var->right_margin - 1) | | |
414 | VIDTCON1_HSPW(var->hsync_len - 1); | |
415 | ||
c4bb6ffa BD |
416 | /* VIDTCON1 */ |
417 | writel(data, regs + sfb->variant.vidtcon + 4); | |
ec549a0f BD |
418 | |
419 | data = VIDTCON2_LINEVAL(var->yres - 1) | | |
420 | VIDTCON2_HOZVAL(var->xres - 1); | |
c4bb6ffa | 421 | writel(data, regs +sfb->variant.vidtcon + 8 ); |
ec549a0f BD |
422 | } |
423 | ||
424 | /* write the buffer address */ | |
425 | ||
c4bb6ffa BD |
426 | /* start and end registers stride is 8 */ |
427 | buf = regs + win_no * 8; | |
428 | ||
429 | writel(info->fix.smem_start, buf + sfb->variant.buf_start); | |
ec549a0f BD |
430 | |
431 | data = info->fix.smem_start + info->fix.line_length * var->yres; | |
c4bb6ffa | 432 | writel(data, buf + sfb->variant.buf_end); |
ec549a0f BD |
433 | |
434 | pagewidth = (var->xres * var->bits_per_pixel) >> 3; | |
435 | data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) | | |
436 | VIDW_BUF_SIZE_PAGEWIDTH(pagewidth); | |
c4bb6ffa | 437 | writel(data, regs + sfb->variant.buf_size + (win_no * 4)); |
ec549a0f BD |
438 | |
439 | /* write 'OSD' registers to control position of framebuffer */ | |
440 | ||
441 | data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0); | |
c4bb6ffa | 442 | writel(data, regs + VIDOSD_A(win_no, sfb->variant)); |
ec549a0f BD |
443 | |
444 | data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel, | |
445 | var->xres - 1)) | | |
446 | VIDOSDxB_BOTRIGHT_Y(var->yres - 1); | |
447 | ||
c4bb6ffa | 448 | writel(data, regs + VIDOSD_B(win_no, sfb->variant)); |
ec549a0f BD |
449 | |
450 | data = var->xres * var->yres; | |
39000d65 | 451 | |
39000d65 ID |
452 | osdc_data = VIDISD14C_ALPHA1_R(0xf) | |
453 | VIDISD14C_ALPHA1_G(0xf) | | |
454 | VIDISD14C_ALPHA1_B(0xf); | |
455 | ||
50a5503a | 456 | if (win->variant.has_osd_d) { |
c4bb6ffa BD |
457 | writel(data, regs + VIDOSD_D(win_no, sfb->variant)); |
458 | writel(osdc_data, regs + VIDOSD_C(win_no, sfb->variant)); | |
ec549a0f | 459 | } else |
c4bb6ffa | 460 | writel(data, regs + VIDOSD_C(win_no, sfb->variant)); |
ec549a0f BD |
461 | |
462 | data = WINCONx_ENWIN; | |
463 | ||
464 | /* note, since we have to round up the bits-per-pixel, we end up | |
465 | * relying on the bitfield information for r/g/b/a to work out | |
466 | * exactly which mode of operation is intended. */ | |
467 | ||
468 | switch (var->bits_per_pixel) { | |
469 | case 1: | |
470 | data |= WINCON0_BPPMODE_1BPP; | |
471 | data |= WINCONx_BITSWP; | |
472 | data |= WINCONx_BURSTLEN_4WORD; | |
473 | break; | |
474 | case 2: | |
475 | data |= WINCON0_BPPMODE_2BPP; | |
476 | data |= WINCONx_BITSWP; | |
477 | data |= WINCONx_BURSTLEN_8WORD; | |
478 | break; | |
479 | case 4: | |
480 | data |= WINCON0_BPPMODE_4BPP; | |
481 | data |= WINCONx_BITSWP; | |
482 | data |= WINCONx_BURSTLEN_8WORD; | |
483 | break; | |
484 | case 8: | |
485 | if (var->transp.length != 0) | |
486 | data |= WINCON1_BPPMODE_8BPP_1232; | |
487 | else | |
488 | data |= WINCON0_BPPMODE_8BPP_PALETTE; | |
489 | data |= WINCONx_BURSTLEN_8WORD; | |
490 | data |= WINCONx_BYTSWP; | |
491 | break; | |
492 | case 16: | |
493 | if (var->transp.length != 0) | |
494 | data |= WINCON1_BPPMODE_16BPP_A1555; | |
495 | else | |
496 | data |= WINCON0_BPPMODE_16BPP_565; | |
497 | data |= WINCONx_HAWSWP; | |
498 | data |= WINCONx_BURSTLEN_16WORD; | |
499 | break; | |
500 | case 24: | |
501 | case 32: | |
502 | if (var->red.length == 6) { | |
503 | if (var->transp.length != 0) | |
504 | data |= WINCON1_BPPMODE_19BPP_A1666; | |
505 | else | |
506 | data |= WINCON1_BPPMODE_18BPP_666; | |
39000d65 ID |
507 | } else if (var->transp.length == 1) |
508 | data |= WINCON1_BPPMODE_25BPP_A1888 | |
509 | | WINCON1_BLD_PIX; | |
510 | else if (var->transp.length == 4) | |
511 | data |= WINCON1_BPPMODE_28BPP_A4888 | |
512 | | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL; | |
ec549a0f BD |
513 | else |
514 | data |= WINCON0_BPPMODE_24BPP_888; | |
515 | ||
dc8498c0 | 516 | data |= WINCONx_WSWP; |
ec549a0f BD |
517 | data |= WINCONx_BURSTLEN_16WORD; |
518 | break; | |
519 | } | |
520 | ||
c4bb6ffa | 521 | /* Enable the colour keying for the window below this one */ |
39000d65 ID |
522 | if (win_no > 0) { |
523 | u32 keycon0_data = 0, keycon1_data = 0; | |
c4bb6ffa | 524 | void __iomem *keycon = regs + sfb->variant.keycon; |
39000d65 ID |
525 | |
526 | keycon0_data = ~(WxKEYCON0_KEYBL_EN | | |
527 | WxKEYCON0_KEYEN_F | | |
528 | WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); | |
529 | ||
530 | keycon1_data = WxKEYCON1_COLVAL(0xffffff); | |
531 | ||
c4bb6ffa BD |
532 | keycon += (win_no - 1) * 8; |
533 | ||
534 | writel(keycon0_data, keycon + WKEYCON0); | |
535 | writel(keycon1_data, keycon + WKEYCON1); | |
39000d65 ID |
536 | } |
537 | ||
c4bb6ffa BD |
538 | writel(data, regs + sfb->variant.wincon + (win_no * 4)); |
539 | writel(0x0, regs + sfb->variant.winmap + (win_no * 4)); | |
ec549a0f BD |
540 | |
541 | return 0; | |
542 | } | |
543 | ||
544 | /** | |
545 | * s3c_fb_update_palette() - set or schedule a palette update. | |
546 | * @sfb: The hardware information. | |
547 | * @win: The window being updated. | |
548 | * @reg: The palette index being changed. | |
549 | * @value: The computed palette value. | |
550 | * | |
551 | * Change the value of a palette register, either by directly writing to | |
552 | * the palette (this requires the palette RAM to be disconnected from the | |
553 | * hardware whilst this is in progress) or schedule the update for later. | |
554 | * | |
555 | * At the moment, since we have no VSYNC interrupt support, we simply set | |
556 | * the palette entry directly. | |
557 | */ | |
558 | static void s3c_fb_update_palette(struct s3c_fb *sfb, | |
559 | struct s3c_fb_win *win, | |
560 | unsigned int reg, | |
561 | u32 value) | |
562 | { | |
563 | void __iomem *palreg; | |
564 | u32 palcon; | |
565 | ||
50a5503a | 566 | palreg = sfb->regs + sfb->variant.palette[win->index]; |
ec549a0f BD |
567 | |
568 | dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n", | |
569 | __func__, win->index, reg, palreg, value); | |
570 | ||
571 | win->palette_buffer[reg] = value; | |
572 | ||
573 | palcon = readl(sfb->regs + WPALCON); | |
574 | writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON); | |
575 | ||
50a5503a BD |
576 | if (win->variant.palette_16bpp) |
577 | writew(value, palreg + (reg * 2)); | |
ec549a0f | 578 | else |
50a5503a | 579 | writel(value, palreg + (reg * 4)); |
ec549a0f BD |
580 | |
581 | writel(palcon, sfb->regs + WPALCON); | |
582 | } | |
583 | ||
584 | static inline unsigned int chan_to_field(unsigned int chan, | |
585 | struct fb_bitfield *bf) | |
586 | { | |
587 | chan &= 0xffff; | |
588 | chan >>= 16 - bf->length; | |
589 | return chan << bf->offset; | |
590 | } | |
591 | ||
592 | /** | |
593 | * s3c_fb_setcolreg() - framebuffer layer request to change palette. | |
594 | * @regno: The palette index to change. | |
595 | * @red: The red field for the palette data. | |
596 | * @green: The green field for the palette data. | |
597 | * @blue: The blue field for the palette data. | |
598 | * @trans: The transparency (alpha) field for the palette data. | |
599 | * @info: The framebuffer being changed. | |
600 | */ | |
601 | static int s3c_fb_setcolreg(unsigned regno, | |
602 | unsigned red, unsigned green, unsigned blue, | |
603 | unsigned transp, struct fb_info *info) | |
604 | { | |
605 | struct s3c_fb_win *win = info->par; | |
606 | struct s3c_fb *sfb = win->parent; | |
607 | unsigned int val; | |
608 | ||
609 | dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n", | |
610 | __func__, win->index, regno, red, green, blue); | |
611 | ||
612 | switch (info->fix.visual) { | |
613 | case FB_VISUAL_TRUECOLOR: | |
614 | /* true-colour, use pseudo-palette */ | |
615 | ||
616 | if (regno < 16) { | |
617 | u32 *pal = info->pseudo_palette; | |
618 | ||
619 | val = chan_to_field(red, &info->var.red); | |
620 | val |= chan_to_field(green, &info->var.green); | |
621 | val |= chan_to_field(blue, &info->var.blue); | |
622 | ||
623 | pal[regno] = val; | |
624 | } | |
625 | break; | |
626 | ||
627 | case FB_VISUAL_PSEUDOCOLOR: | |
50a5503a | 628 | if (regno < win->variant.palette_sz) { |
ec549a0f BD |
629 | val = chan_to_field(red, &win->palette.r); |
630 | val |= chan_to_field(green, &win->palette.g); | |
631 | val |= chan_to_field(blue, &win->palette.b); | |
632 | ||
633 | s3c_fb_update_palette(sfb, win, regno, val); | |
634 | } | |
635 | ||
636 | break; | |
637 | ||
638 | default: | |
639 | return 1; /* unknown type */ | |
640 | } | |
641 | ||
642 | return 0; | |
643 | } | |
644 | ||
645 | /** | |
646 | * s3c_fb_enable() - Set the state of the main LCD output | |
647 | * @sfb: The main framebuffer state. | |
648 | * @enable: The state to set. | |
649 | */ | |
650 | static void s3c_fb_enable(struct s3c_fb *sfb, int enable) | |
651 | { | |
652 | u32 vidcon0 = readl(sfb->regs + VIDCON0); | |
653 | ||
654 | if (enable) | |
655 | vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F; | |
656 | else { | |
657 | /* see the note in the framebuffer datasheet about | |
658 | * why you cannot take both of these bits down at the | |
659 | * same time. */ | |
660 | ||
661 | if (!(vidcon0 & VIDCON0_ENVID)) | |
662 | return; | |
663 | ||
664 | vidcon0 |= VIDCON0_ENVID; | |
665 | vidcon0 &= ~VIDCON0_ENVID_F; | |
666 | } | |
667 | ||
668 | writel(vidcon0, sfb->regs + VIDCON0); | |
669 | } | |
670 | ||
671 | /** | |
672 | * s3c_fb_blank() - blank or unblank the given window | |
673 | * @blank_mode: The blank state from FB_BLANK_* | |
674 | * @info: The framebuffer to blank. | |
675 | * | |
676 | * Framebuffer layer request to change the power state. | |
677 | */ | |
678 | static int s3c_fb_blank(int blank_mode, struct fb_info *info) | |
679 | { | |
680 | struct s3c_fb_win *win = info->par; | |
681 | struct s3c_fb *sfb = win->parent; | |
682 | unsigned int index = win->index; | |
683 | u32 wincon; | |
684 | ||
685 | dev_dbg(sfb->dev, "blank mode %d\n", blank_mode); | |
686 | ||
c4bb6ffa | 687 | wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4)); |
ec549a0f BD |
688 | |
689 | switch (blank_mode) { | |
690 | case FB_BLANK_POWERDOWN: | |
691 | wincon &= ~WINCONx_ENWIN; | |
692 | sfb->enabled &= ~(1 << index); | |
693 | /* fall through to FB_BLANK_NORMAL */ | |
694 | ||
695 | case FB_BLANK_NORMAL: | |
696 | /* disable the DMA and display 0x0 (black) */ | |
697 | writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0), | |
c4bb6ffa | 698 | sfb->regs + sfb->variant.winmap + (index * 4)); |
ec549a0f BD |
699 | break; |
700 | ||
701 | case FB_BLANK_UNBLANK: | |
c4bb6ffa | 702 | writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4)); |
ec549a0f BD |
703 | wincon |= WINCONx_ENWIN; |
704 | sfb->enabled |= (1 << index); | |
705 | break; | |
706 | ||
707 | case FB_BLANK_VSYNC_SUSPEND: | |
708 | case FB_BLANK_HSYNC_SUSPEND: | |
709 | default: | |
710 | return 1; | |
711 | } | |
712 | ||
c4bb6ffa | 713 | writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4)); |
ec549a0f BD |
714 | |
715 | /* Check the enabled state to see if we need to be running the | |
716 | * main LCD interface, as if there are no active windows then | |
717 | * it is highly likely that we also do not need to output | |
718 | * anything. | |
719 | */ | |
720 | ||
721 | /* We could do something like the following code, but the current | |
722 | * system of using framebuffer events means that we cannot make | |
723 | * the distinction between just window 0 being inactive and all | |
724 | * the windows being down. | |
725 | * | |
726 | * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0); | |
727 | */ | |
728 | ||
729 | /* we're stuck with this until we can do something about overriding | |
730 | * the power control using the blanking event for a single fb. | |
731 | */ | |
ad04490a | 732 | if (index == sfb->pdata->default_win) |
ec549a0f BD |
733 | s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0); |
734 | ||
735 | return 0; | |
736 | } | |
737 | ||
738 | static struct fb_ops s3c_fb_ops = { | |
739 | .owner = THIS_MODULE, | |
740 | .fb_check_var = s3c_fb_check_var, | |
741 | .fb_set_par = s3c_fb_set_par, | |
742 | .fb_blank = s3c_fb_blank, | |
743 | .fb_setcolreg = s3c_fb_setcolreg, | |
744 | .fb_fillrect = cfb_fillrect, | |
745 | .fb_copyarea = cfb_copyarea, | |
746 | .fb_imageblit = cfb_imageblit, | |
747 | }; | |
748 | ||
749 | /** | |
750 | * s3c_fb_alloc_memory() - allocate display memory for framebuffer window | |
751 | * @sfb: The base resources for the hardware. | |
752 | * @win: The window to initialise memory for. | |
753 | * | |
754 | * Allocate memory for the given framebuffer. | |
755 | */ | |
756 | static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb, | |
757 | struct s3c_fb_win *win) | |
758 | { | |
759 | struct s3c_fb_pd_win *windata = win->windata; | |
760 | unsigned int real_size, virt_size, size; | |
761 | struct fb_info *fbi = win->fbinfo; | |
762 | dma_addr_t map_dma; | |
763 | ||
764 | dev_dbg(sfb->dev, "allocating memory for display\n"); | |
765 | ||
766 | real_size = windata->win_mode.xres * windata->win_mode.yres; | |
767 | virt_size = windata->virtual_x * windata->virtual_y; | |
768 | ||
769 | dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n", | |
770 | real_size, windata->win_mode.xres, windata->win_mode.yres, | |
771 | virt_size, windata->virtual_x, windata->virtual_y); | |
772 | ||
773 | size = (real_size > virt_size) ? real_size : virt_size; | |
774 | size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp; | |
775 | size /= 8; | |
776 | ||
777 | fbi->fix.smem_len = size; | |
778 | size = PAGE_ALIGN(size); | |
779 | ||
780 | dev_dbg(sfb->dev, "want %u bytes for window\n", size); | |
781 | ||
782 | fbi->screen_base = dma_alloc_writecombine(sfb->dev, size, | |
783 | &map_dma, GFP_KERNEL); | |
784 | if (!fbi->screen_base) | |
785 | return -ENOMEM; | |
786 | ||
787 | dev_dbg(sfb->dev, "mapped %x to %p\n", | |
788 | (unsigned int)map_dma, fbi->screen_base); | |
789 | ||
790 | memset(fbi->screen_base, 0x0, size); | |
791 | fbi->fix.smem_start = map_dma; | |
792 | ||
793 | return 0; | |
794 | } | |
795 | ||
796 | /** | |
797 | * s3c_fb_free_memory() - free the display memory for the given window | |
798 | * @sfb: The base resources for the hardware. | |
799 | * @win: The window to free the display memory for. | |
800 | * | |
801 | * Free the display memory allocated by s3c_fb_alloc_memory(). | |
802 | */ | |
803 | static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win) | |
804 | { | |
805 | struct fb_info *fbi = win->fbinfo; | |
806 | ||
cd7d7e02 PO |
807 | if (fbi->screen_base) |
808 | dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len), | |
ec549a0f BD |
809 | fbi->screen_base, fbi->fix.smem_start); |
810 | } | |
811 | ||
812 | /** | |
813 | * s3c_fb_release_win() - release resources for a framebuffer window. | |
814 | * @win: The window to cleanup the resources for. | |
815 | * | |
816 | * Release the resources that where claimed for the hardware window, | |
817 | * such as the framebuffer instance and any memory claimed for it. | |
818 | */ | |
819 | static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win) | |
820 | { | |
ddc518d9 KH |
821 | if (win->fbinfo) { |
822 | unregister_framebuffer(win->fbinfo); | |
cd7d7e02 PO |
823 | if (win->fbinfo->cmap.len) |
824 | fb_dealloc_cmap(&win->fbinfo->cmap); | |
ddc518d9 KH |
825 | s3c_fb_free_memory(sfb, win); |
826 | framebuffer_release(win->fbinfo); | |
827 | } | |
ec549a0f BD |
828 | } |
829 | ||
830 | /** | |
831 | * s3c_fb_probe_win() - register an hardware window | |
832 | * @sfb: The base resources for the hardware | |
50a5503a | 833 | * @variant: The variant information for this window. |
ec549a0f BD |
834 | * @res: Pointer to where to place the resultant window. |
835 | * | |
836 | * Allocate and do the basic initialisation for one of the hardware's graphics | |
837 | * windows. | |
838 | */ | |
839 | static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no, | |
50a5503a | 840 | struct s3c_fb_win_variant *variant, |
ec549a0f BD |
841 | struct s3c_fb_win **res) |
842 | { | |
843 | struct fb_var_screeninfo *var; | |
844 | struct fb_videomode *initmode; | |
845 | struct s3c_fb_pd_win *windata; | |
846 | struct s3c_fb_win *win; | |
847 | struct fb_info *fbinfo; | |
848 | int palette_size; | |
849 | int ret; | |
850 | ||
c4bb6ffa | 851 | dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant); |
ec549a0f | 852 | |
50a5503a | 853 | palette_size = variant->palette_sz * 4; |
ec549a0f BD |
854 | |
855 | fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) + | |
856 | palette_size * sizeof(u32), sfb->dev); | |
857 | if (!fbinfo) { | |
858 | dev_err(sfb->dev, "failed to allocate framebuffer\n"); | |
859 | return -ENOENT; | |
860 | } | |
861 | ||
862 | windata = sfb->pdata->win[win_no]; | |
863 | initmode = &windata->win_mode; | |
864 | ||
865 | WARN_ON(windata->max_bpp == 0); | |
866 | WARN_ON(windata->win_mode.xres == 0); | |
867 | WARN_ON(windata->win_mode.yres == 0); | |
868 | ||
869 | win = fbinfo->par; | |
cd7d7e02 | 870 | *res = win; |
ec549a0f | 871 | var = &fbinfo->var; |
50a5503a | 872 | win->variant = *variant; |
ec549a0f BD |
873 | win->fbinfo = fbinfo; |
874 | win->parent = sfb; | |
875 | win->windata = windata; | |
876 | win->index = win_no; | |
877 | win->palette_buffer = (u32 *)(win + 1); | |
878 | ||
879 | ret = s3c_fb_alloc_memory(sfb, win); | |
880 | if (ret) { | |
881 | dev_err(sfb->dev, "failed to allocate display memory\n"); | |
ddc518d9 | 882 | return ret; |
ec549a0f BD |
883 | } |
884 | ||
885 | /* setup the r/b/g positions for the window's palette */ | |
bc2da1b6 BD |
886 | if (win->variant.palette_16bpp) { |
887 | /* Set RGB 5:6:5 as default */ | |
888 | win->palette.r.offset = 11; | |
889 | win->palette.r.length = 5; | |
890 | win->palette.g.offset = 5; | |
891 | win->palette.g.length = 6; | |
892 | win->palette.b.offset = 0; | |
893 | win->palette.b.length = 5; | |
894 | ||
895 | } else { | |
896 | /* Set 8bpp or 8bpp and 1bit alpha */ | |
897 | win->palette.r.offset = 16; | |
898 | win->palette.r.length = 8; | |
899 | win->palette.g.offset = 8; | |
900 | win->palette.g.length = 8; | |
901 | win->palette.b.offset = 0; | |
902 | win->palette.b.length = 8; | |
903 | } | |
ec549a0f BD |
904 | |
905 | /* setup the initial video mode from the window */ | |
906 | fb_videomode_to_var(&fbinfo->var, initmode); | |
907 | ||
908 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; | |
909 | fbinfo->fix.accel = FB_ACCEL_NONE; | |
910 | fbinfo->var.activate = FB_ACTIVATE_NOW; | |
911 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; | |
912 | fbinfo->var.bits_per_pixel = windata->default_bpp; | |
913 | fbinfo->fbops = &s3c_fb_ops; | |
914 | fbinfo->flags = FBINFO_FLAG_DEFAULT; | |
915 | fbinfo->pseudo_palette = &win->pseudo_palette; | |
916 | ||
917 | /* prepare to actually start the framebuffer */ | |
918 | ||
919 | ret = s3c_fb_check_var(&fbinfo->var, fbinfo); | |
920 | if (ret < 0) { | |
921 | dev_err(sfb->dev, "check_var failed on initial video params\n"); | |
ddc518d9 | 922 | return ret; |
ec549a0f BD |
923 | } |
924 | ||
925 | /* create initial colour map */ | |
926 | ||
50a5503a | 927 | ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1); |
ec549a0f BD |
928 | if (ret == 0) |
929 | fb_set_cmap(&fbinfo->cmap, fbinfo); | |
930 | else | |
931 | dev_err(sfb->dev, "failed to allocate fb cmap\n"); | |
932 | ||
933 | s3c_fb_set_par(fbinfo); | |
934 | ||
935 | dev_dbg(sfb->dev, "about to register framebuffer\n"); | |
936 | ||
937 | /* run the check_var and set_par on our configuration. */ | |
938 | ||
939 | ret = register_framebuffer(fbinfo); | |
940 | if (ret < 0) { | |
941 | dev_err(sfb->dev, "failed to register framebuffer\n"); | |
ddc518d9 | 942 | return ret; |
ec549a0f BD |
943 | } |
944 | ||
ec549a0f BD |
945 | dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id); |
946 | ||
947 | return 0; | |
ec549a0f BD |
948 | } |
949 | ||
950 | /** | |
951 | * s3c_fb_clear_win() - clear hardware window registers. | |
952 | * @sfb: The base resources for the hardware. | |
953 | * @win: The window to process. | |
954 | * | |
955 | * Reset the specific window registers to a known state. | |
956 | */ | |
957 | static void s3c_fb_clear_win(struct s3c_fb *sfb, int win) | |
958 | { | |
959 | void __iomem *regs = sfb->regs; | |
960 | ||
c4bb6ffa BD |
961 | writel(0, regs + sfb->variant.wincon + (win * 4)); |
962 | writel(0, regs + VIDOSD_A(win, sfb->variant)); | |
963 | writel(0, regs + VIDOSD_B(win, sfb->variant)); | |
964 | writel(0, regs + VIDOSD_C(win, sfb->variant)); | |
ec549a0f BD |
965 | } |
966 | ||
967 | static int __devinit s3c_fb_probe(struct platform_device *pdev) | |
968 | { | |
50a5503a | 969 | struct s3c_fb_driverdata *fbdrv; |
ec549a0f BD |
970 | struct device *dev = &pdev->dev; |
971 | struct s3c_fb_platdata *pd; | |
972 | struct s3c_fb *sfb; | |
973 | struct resource *res; | |
974 | int win; | |
975 | int ret = 0; | |
976 | ||
50a5503a BD |
977 | fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data; |
978 | ||
979 | if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) { | |
980 | dev_err(dev, "too many windows, cannot attach\n"); | |
981 | return -EINVAL; | |
982 | } | |
983 | ||
ec549a0f BD |
984 | pd = pdev->dev.platform_data; |
985 | if (!pd) { | |
986 | dev_err(dev, "no platform data specified\n"); | |
987 | return -EINVAL; | |
988 | } | |
989 | ||
990 | sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL); | |
991 | if (!sfb) { | |
992 | dev_err(dev, "no memory for framebuffers\n"); | |
993 | return -ENOMEM; | |
994 | } | |
995 | ||
c4bb6ffa BD |
996 | dev_dbg(dev, "allocate new framebuffer %p\n", sfb); |
997 | ||
ec549a0f BD |
998 | sfb->dev = dev; |
999 | sfb->pdata = pd; | |
50a5503a | 1000 | sfb->variant = fbdrv->variant; |
ec549a0f BD |
1001 | |
1002 | sfb->bus_clk = clk_get(dev, "lcd"); | |
1003 | if (IS_ERR(sfb->bus_clk)) { | |
1004 | dev_err(dev, "failed to get bus clock\n"); | |
1005 | goto err_sfb; | |
1006 | } | |
1007 | ||
1008 | clk_enable(sfb->bus_clk); | |
1009 | ||
1010 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
1011 | if (!res) { | |
1012 | dev_err(dev, "failed to find registers\n"); | |
1013 | ret = -ENOENT; | |
1014 | goto err_clk; | |
1015 | } | |
1016 | ||
1017 | sfb->regs_res = request_mem_region(res->start, resource_size(res), | |
1018 | dev_name(dev)); | |
1019 | if (!sfb->regs_res) { | |
1020 | dev_err(dev, "failed to claim register region\n"); | |
1021 | ret = -ENOENT; | |
1022 | goto err_clk; | |
1023 | } | |
1024 | ||
1025 | sfb->regs = ioremap(res->start, resource_size(res)); | |
1026 | if (!sfb->regs) { | |
1027 | dev_err(dev, "failed to map registers\n"); | |
1028 | ret = -ENXIO; | |
1029 | goto err_req_region; | |
1030 | } | |
1031 | ||
1032 | dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs); | |
1033 | ||
1034 | /* setup gpio and output polarity controls */ | |
1035 | ||
1036 | pd->setup_gpio(); | |
1037 | ||
1038 | writel(pd->vidcon1, sfb->regs + VIDCON1); | |
1039 | ||
1040 | /* zero all windows before we do anything */ | |
1041 | ||
50a5503a | 1042 | for (win = 0; win < fbdrv->variant.nr_windows; win++) |
ec549a0f BD |
1043 | s3c_fb_clear_win(sfb, win); |
1044 | ||
94947037 | 1045 | /* initialise colour key controls */ |
50a5503a | 1046 | for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) { |
c4bb6ffa BD |
1047 | void __iomem *regs = sfb->regs + sfb->variant.keycon; |
1048 | ||
1049 | regs += (win * 8); | |
1050 | writel(0xffffff, regs + WKEYCON0); | |
1051 | writel(0xffffff, regs + WKEYCON1); | |
94947037 BD |
1052 | } |
1053 | ||
ec549a0f BD |
1054 | /* we have the register setup, start allocating framebuffers */ |
1055 | ||
50a5503a | 1056 | for (win = 0; win < fbdrv->variant.nr_windows; win++) { |
ec549a0f BD |
1057 | if (!pd->win[win]) |
1058 | continue; | |
1059 | ||
50a5503a BD |
1060 | ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win], |
1061 | &sfb->windows[win]); | |
ec549a0f BD |
1062 | if (ret < 0) { |
1063 | dev_err(dev, "failed to create window %d\n", win); | |
1064 | for (; win >= 0; win--) | |
1065 | s3c_fb_release_win(sfb, sfb->windows[win]); | |
1066 | goto err_ioremap; | |
1067 | } | |
1068 | } | |
1069 | ||
1070 | platform_set_drvdata(pdev, sfb); | |
1071 | ||
1072 | return 0; | |
1073 | ||
1074 | err_ioremap: | |
1075 | iounmap(sfb->regs); | |
1076 | ||
1077 | err_req_region: | |
1078 | release_resource(sfb->regs_res); | |
1079 | kfree(sfb->regs_res); | |
1080 | ||
1081 | err_clk: | |
1082 | clk_disable(sfb->bus_clk); | |
1083 | clk_put(sfb->bus_clk); | |
1084 | ||
1085 | err_sfb: | |
1086 | kfree(sfb); | |
1087 | return ret; | |
1088 | } | |
1089 | ||
1090 | /** | |
1091 | * s3c_fb_remove() - Cleanup on module finalisation | |
1092 | * @pdev: The platform device we are bound to. | |
1093 | * | |
1094 | * Shutdown and then release all the resources that the driver allocated | |
1095 | * on initialisation. | |
1096 | */ | |
1097 | static int __devexit s3c_fb_remove(struct platform_device *pdev) | |
1098 | { | |
1099 | struct s3c_fb *sfb = platform_get_drvdata(pdev); | |
1100 | int win; | |
1101 | ||
c42b110c | 1102 | for (win = 0; win < S3C_FB_MAX_WIN; win++) |
17663e59 MS |
1103 | if (sfb->windows[win]) |
1104 | s3c_fb_release_win(sfb, sfb->windows[win]); | |
ec549a0f BD |
1105 | |
1106 | iounmap(sfb->regs); | |
1107 | ||
1108 | clk_disable(sfb->bus_clk); | |
1109 | clk_put(sfb->bus_clk); | |
1110 | ||
1111 | release_resource(sfb->regs_res); | |
1112 | kfree(sfb->regs_res); | |
1113 | ||
1114 | kfree(sfb); | |
1115 | ||
1116 | return 0; | |
1117 | } | |
1118 | ||
1119 | #ifdef CONFIG_PM | |
1120 | static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state) | |
1121 | { | |
1122 | struct s3c_fb *sfb = platform_get_drvdata(pdev); | |
1123 | struct s3c_fb_win *win; | |
1124 | int win_no; | |
1125 | ||
c42b110c | 1126 | for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) { |
ec549a0f BD |
1127 | win = sfb->windows[win_no]; |
1128 | if (!win) | |
1129 | continue; | |
1130 | ||
1131 | /* use the blank function to push into power-down */ | |
1132 | s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo); | |
1133 | } | |
1134 | ||
1135 | clk_disable(sfb->bus_clk); | |
1136 | return 0; | |
1137 | } | |
1138 | ||
1139 | static int s3c_fb_resume(struct platform_device *pdev) | |
1140 | { | |
1141 | struct s3c_fb *sfb = platform_get_drvdata(pdev); | |
17663e59 | 1142 | struct s3c_fb_platdata *pd = sfb->pdata; |
ec549a0f BD |
1143 | struct s3c_fb_win *win; |
1144 | int win_no; | |
1145 | ||
1146 | clk_enable(sfb->bus_clk); | |
1147 | ||
17663e59 MS |
1148 | /* setup registers */ |
1149 | writel(pd->vidcon1, sfb->regs + VIDCON1); | |
1150 | ||
1151 | /* zero all windows before we do anything */ | |
50a5503a | 1152 | for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++) |
17663e59 MS |
1153 | s3c_fb_clear_win(sfb, win_no); |
1154 | ||
50a5503a | 1155 | for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) { |
c4bb6ffa BD |
1156 | void __iomem *regs = sfb->regs + sfb->variant.keycon; |
1157 | ||
1158 | regs += (win_no * 8); | |
1159 | writel(0xffffff, regs + WKEYCON0); | |
1160 | writel(0xffffff, regs + WKEYCON1); | |
94947037 BD |
1161 | } |
1162 | ||
17663e59 | 1163 | /* restore framebuffers */ |
ec549a0f BD |
1164 | for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { |
1165 | win = sfb->windows[win_no]; | |
1166 | if (!win) | |
1167 | continue; | |
1168 | ||
1169 | dev_dbg(&pdev->dev, "resuming window %d\n", win_no); | |
1170 | s3c_fb_set_par(win->fbinfo); | |
1171 | } | |
1172 | ||
1173 | return 0; | |
1174 | } | |
1175 | #else | |
1176 | #define s3c_fb_suspend NULL | |
1177 | #define s3c_fb_resume NULL | |
1178 | #endif | |
1179 | ||
50a5503a BD |
1180 | |
1181 | #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4)) | |
1182 | #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8)) | |
1183 | ||
1184 | static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] __devinitdata = { | |
1185 | [0] = { | |
1186 | .has_osd_c = 1, | |
1187 | .palette_sz = 256, | |
1188 | .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24), | |
1189 | }, | |
1190 | [1] = { | |
1191 | .has_osd_c = 1, | |
1192 | .has_osd_d = 1, | |
1193 | .palette_sz = 256, | |
1194 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | | |
1195 | VALID_BPP(18) | VALID_BPP(19) | | |
1196 | VALID_BPP(24) | VALID_BPP(25)), | |
1197 | }, | |
1198 | [2] = { | |
1199 | .has_osd_c = 1, | |
1200 | .has_osd_d = 1, | |
1201 | .palette_sz = 16, | |
1202 | .palette_16bpp = 1, | |
1203 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | | |
1204 | VALID_BPP(18) | VALID_BPP(19) | | |
1205 | VALID_BPP(24) | VALID_BPP(25)), | |
1206 | }, | |
1207 | [3] = { | |
1208 | .has_osd_c = 1, | |
1209 | .has_osd_d = 1, | |
1210 | .palette_sz = 16, | |
1211 | .palette_16bpp = 1, | |
1212 | .valid_bpp = (VALID_BPP124 | VALID_BPP(16) | | |
1213 | VALID_BPP(18) | VALID_BPP(19) | | |
1214 | VALID_BPP(24) | VALID_BPP(25)), | |
1215 | }, | |
1216 | [4] = { | |
1217 | .has_osd_c = 1, | |
1218 | .palette_sz = 4, | |
1219 | .palette_16bpp = 1, | |
1220 | .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) | | |
1221 | VALID_BPP(16) | VALID_BPP(18) | | |
1222 | VALID_BPP(24) | VALID_BPP(25)), | |
1223 | }, | |
1224 | }; | |
1225 | ||
1226 | static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = { | |
1227 | .variant = { | |
1228 | .nr_windows = 5, | |
c4bb6ffa BD |
1229 | .vidtcon = VIDTCON0, |
1230 | .wincon = WINCON(0), | |
1231 | .winmap = WINxMAP(0), | |
1232 | .keycon = WKEYCON, | |
1233 | .osd = VIDOSD_BASE, | |
1234 | .osd_stride = 16, | |
1235 | .buf_start = VIDW_BUF_START(0), | |
1236 | .buf_size = VIDW_BUF_SIZE(0), | |
1237 | .buf_end = VIDW_BUF_END(0), | |
50a5503a BD |
1238 | |
1239 | .palette = { | |
1240 | [0] = 0x400, | |
1241 | [1] = 0x800, | |
1242 | [2] = 0x300, | |
1243 | [3] = 0x320, | |
1244 | [4] = 0x340, | |
1245 | }, | |
1246 | }, | |
1247 | .win[0] = &s3c_fb_data_64xx_wins[0], | |
1248 | .win[1] = &s3c_fb_data_64xx_wins[1], | |
1249 | .win[2] = &s3c_fb_data_64xx_wins[2], | |
1250 | .win[3] = &s3c_fb_data_64xx_wins[3], | |
1251 | .win[4] = &s3c_fb_data_64xx_wins[4], | |
1252 | }; | |
1253 | ||
1254 | static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = { | |
1255 | .variant = { | |
1256 | .nr_windows = 5, | |
c4bb6ffa BD |
1257 | .vidtcon = VIDTCON0, |
1258 | .wincon = WINCON(0), | |
1259 | .winmap = WINxMAP(0), | |
1260 | .keycon = WKEYCON, | |
1261 | .osd = VIDOSD_BASE, | |
1262 | .osd_stride = 16, | |
1263 | .buf_start = VIDW_BUF_START(0), | |
1264 | .buf_size = VIDW_BUF_SIZE(0), | |
1265 | .buf_end = VIDW_BUF_END(0), | |
50a5503a BD |
1266 | |
1267 | .palette = { | |
1268 | [0] = 0x2400, | |
1269 | [1] = 0x2800, | |
1270 | [2] = 0x2c00, | |
1271 | [3] = 0x3000, | |
1272 | [4] = 0x3400, | |
1273 | }, | |
1274 | }, | |
1275 | .win[0] = &s3c_fb_data_64xx_wins[0], | |
1276 | .win[1] = &s3c_fb_data_64xx_wins[1], | |
1277 | .win[2] = &s3c_fb_data_64xx_wins[2], | |
1278 | .win[3] = &s3c_fb_data_64xx_wins[3], | |
1279 | .win[4] = &s3c_fb_data_64xx_wins[4], | |
1280 | }; | |
1281 | ||
c4bb6ffa BD |
1282 | /* S3C2443/S3C2416 style hardware */ |
1283 | static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = { | |
1284 | .variant = { | |
1285 | .nr_windows = 2, | |
1286 | .is_2443 = 1, | |
1287 | ||
1288 | .vidtcon = 0x08, | |
1289 | .wincon = 0x14, | |
1290 | .winmap = 0xd0, | |
1291 | .keycon = 0xb0, | |
1292 | .osd = 0x28, | |
1293 | .osd_stride = 12, | |
1294 | .buf_start = 0x64, | |
1295 | .buf_size = 0x94, | |
1296 | .buf_end = 0x7c, | |
1297 | ||
1298 | .palette = { | |
1299 | [0] = 0x400, | |
1300 | [1] = 0x800, | |
1301 | }, | |
1302 | }, | |
1303 | .win[0] = &(struct s3c_fb_win_variant) { | |
1304 | .palette_sz = 256, | |
1305 | .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24), | |
1306 | }, | |
1307 | .win[1] = &(struct s3c_fb_win_variant) { | |
1308 | .has_osd_c = 1, | |
1309 | .palette_sz = 256, | |
1310 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | | |
1311 | VALID_BPP(18) | VALID_BPP(19) | | |
1312 | VALID_BPP(24) | VALID_BPP(25) | | |
1313 | VALID_BPP(28)), | |
1314 | }, | |
1315 | }; | |
1316 | ||
50a5503a BD |
1317 | static struct platform_device_id s3c_fb_driver_ids[] = { |
1318 | { | |
1319 | .name = "s3c-fb", | |
1320 | .driver_data = (unsigned long)&s3c_fb_data_64xx, | |
1321 | }, { | |
1322 | .name = "s5p-fb", | |
1323 | .driver_data = (unsigned long)&s3c_fb_data_s5p, | |
c4bb6ffa BD |
1324 | }, { |
1325 | .name = "s3c2443-fb", | |
1326 | .driver_data = (unsigned long)&s3c_fb_data_s3c2443, | |
50a5503a BD |
1327 | }, |
1328 | {}, | |
1329 | }; | |
1330 | MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids); | |
1331 | ||
ec549a0f BD |
1332 | static struct platform_driver s3c_fb_driver = { |
1333 | .probe = s3c_fb_probe, | |
3163eaba | 1334 | .remove = __devexit_p(s3c_fb_remove), |
ec549a0f BD |
1335 | .suspend = s3c_fb_suspend, |
1336 | .resume = s3c_fb_resume, | |
50a5503a | 1337 | .id_table = s3c_fb_driver_ids, |
ec549a0f BD |
1338 | .driver = { |
1339 | .name = "s3c-fb", | |
1340 | .owner = THIS_MODULE, | |
1341 | }, | |
1342 | }; | |
1343 | ||
1344 | static int __init s3c_fb_init(void) | |
1345 | { | |
1346 | return platform_driver_register(&s3c_fb_driver); | |
1347 | } | |
1348 | ||
1349 | static void __exit s3c_fb_cleanup(void) | |
1350 | { | |
1351 | platform_driver_unregister(&s3c_fb_driver); | |
1352 | } | |
1353 | ||
1354 | module_init(s3c_fb_init); | |
1355 | module_exit(s3c_fb_cleanup); | |
1356 | ||
1357 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | |
1358 | MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver"); | |
1359 | MODULE_LICENSE("GPL"); | |
1360 | MODULE_ALIAS("platform:s3c-fb"); |