diff options
Diffstat (limited to 'drivers/video/pxafb.c')
-rw-r--r-- | drivers/video/pxafb.c | 981 |
1 files changed, 652 insertions, 329 deletions
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c index cc59c52e1103..48ff701d3a72 100644 --- a/drivers/video/pxafb.c +++ b/drivers/video/pxafb.c | |||
@@ -20,6 +20,16 @@ | |||
20 | * | 20 | * |
21 | * linux-arm-kernel@lists.arm.linux.org.uk | 21 | * linux-arm-kernel@lists.arm.linux.org.uk |
22 | * | 22 | * |
23 | * Add support for overlay1 and overlay2 based on pxafb_overlay.c: | ||
24 | * | ||
25 | * Copyright (C) 2004, Intel Corporation | ||
26 | * | ||
27 | * 2003/08/27: <yu.tang@intel.com> | ||
28 | * 2004/03/10: <stanley.cai@intel.com> | ||
29 | * 2004/10/28: <yan.yin@intel.com> | ||
30 | * | ||
31 | * Copyright (C) 2006-2008 Marvell International Ltd. | ||
32 | * All Rights Reserved | ||
23 | */ | 33 | */ |
24 | 34 | ||
25 | #include <linux/module.h> | 35 | #include <linux/module.h> |
@@ -50,7 +60,6 @@ | |||
50 | #include <asm/irq.h> | 60 | #include <asm/irq.h> |
51 | #include <asm/div64.h> | 61 | #include <asm/div64.h> |
52 | #include <mach/pxa-regs.h> | 62 | #include <mach/pxa-regs.h> |
53 | #include <mach/pxa2xx-gpio.h> | ||
54 | #include <mach/bitfield.h> | 63 | #include <mach/bitfield.h> |
55 | #include <mach/pxafb.h> | 64 | #include <mach/pxafb.h> |
56 | 65 | ||
@@ -67,14 +76,16 @@ | |||
67 | LCCR0_SFM | LCCR0_LDM | LCCR0_ENB) | 76 | LCCR0_SFM | LCCR0_LDM | LCCR0_ENB) |
68 | 77 | ||
69 | #define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\ | 78 | #define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\ |
70 | LCCR3_PCD | LCCR3_BPP) | 79 | LCCR3_PCD | LCCR3_BPP(0xf)) |
71 | |||
72 | static void (*pxafb_backlight_power)(int); | ||
73 | static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *); | ||
74 | 80 | ||
75 | static int pxafb_activate_var(struct fb_var_screeninfo *var, | 81 | static int pxafb_activate_var(struct fb_var_screeninfo *var, |
76 | struct pxafb_info *); | 82 | struct pxafb_info *); |
77 | static void set_ctrlr_state(struct pxafb_info *fbi, u_int state); | 83 | static void set_ctrlr_state(struct pxafb_info *fbi, u_int state); |
84 | static void setup_base_frame(struct pxafb_info *fbi, int branch); | ||
85 | static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, | ||
86 | unsigned long offset, size_t size); | ||
87 | |||
88 | static unsigned long video_mem_size = 0; | ||
78 | 89 | ||
79 | static inline unsigned long | 90 | static inline unsigned long |
80 | lcd_readl(struct pxafb_info *fbi, unsigned int off) | 91 | lcd_readl(struct pxafb_info *fbi, unsigned int off) |
@@ -156,6 +167,12 @@ pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue, | |||
156 | val |= ((blue >> 8) & 0x000000fc); | 167 | val |= ((blue >> 8) & 0x000000fc); |
157 | ((u32 *)(fbi->palette_cpu))[regno] = val; | 168 | ((u32 *)(fbi->palette_cpu))[regno] = val; |
158 | break; | 169 | break; |
170 | case LCCR4_PAL_FOR_3: | ||
171 | val = ((red << 8) & 0x00ff0000); | ||
172 | val |= ((green >> 0) & 0x0000ff00); | ||
173 | val |= ((blue >> 8) & 0x000000ff); | ||
174 | ((u32 *)(fbi->palette_cpu))[regno] = val; | ||
175 | break; | ||
159 | } | 176 | } |
160 | 177 | ||
161 | return 0; | 178 | return 0; |
@@ -216,37 +233,110 @@ pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, | |||
216 | return ret; | 233 | return ret; |
217 | } | 234 | } |
218 | 235 | ||
219 | /* | 236 | /* calculate pixel depth, transparency bit included, >=16bpp formats _only_ */ |
220 | * pxafb_bpp_to_lccr3(): | 237 | static inline int var_to_depth(struct fb_var_screeninfo *var) |
221 | * Convert a bits per pixel value to the correct bit pattern for LCCR3 | ||
222 | */ | ||
223 | static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var) | ||
224 | { | 238 | { |
225 | int ret = 0; | 239 | return var->red.length + var->green.length + |
240 | var->blue.length + var->transp.length; | ||
241 | } | ||
242 | |||
243 | /* calculate 4-bit BPP value for LCCR3 and OVLxC1 */ | ||
244 | static int pxafb_var_to_bpp(struct fb_var_screeninfo *var) | ||
245 | { | ||
246 | int bpp = -EINVAL; | ||
247 | |||
226 | switch (var->bits_per_pixel) { | 248 | switch (var->bits_per_pixel) { |
227 | case 1: ret = LCCR3_1BPP; break; | 249 | case 1: bpp = 0; break; |
228 | case 2: ret = LCCR3_2BPP; break; | 250 | case 2: bpp = 1; break; |
229 | case 4: ret = LCCR3_4BPP; break; | 251 | case 4: bpp = 2; break; |
230 | case 8: ret = LCCR3_8BPP; break; | 252 | case 8: bpp = 3; break; |
231 | case 16: ret = LCCR3_16BPP; break; | 253 | case 16: bpp = 4; break; |
232 | case 24: | 254 | case 24: |
233 | switch (var->red.length + var->green.length + | 255 | switch (var_to_depth(var)) { |
234 | var->blue.length + var->transp.length) { | 256 | case 18: bpp = 6; break; /* 18-bits/pixel packed */ |
235 | case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break; | 257 | case 19: bpp = 8; break; /* 19-bits/pixel packed */ |
236 | case 19: ret = LCCR3_19BPP_P; break; | 258 | case 24: bpp = 9; break; |
237 | } | 259 | } |
238 | break; | 260 | break; |
239 | case 32: | 261 | case 32: |
240 | switch (var->red.length + var->green.length + | 262 | switch (var_to_depth(var)) { |
241 | var->blue.length + var->transp.length) { | 263 | case 18: bpp = 5; break; /* 18-bits/pixel unpacked */ |
242 | case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break; | 264 | case 19: bpp = 7; break; /* 19-bits/pixel unpacked */ |
243 | case 19: ret = LCCR3_19BPP; break; | 265 | case 25: bpp = 10; break; |
244 | case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break; | ||
245 | case 25: ret = LCCR3_25BPP; break; | ||
246 | } | 266 | } |
247 | break; | 267 | break; |
248 | } | 268 | } |
249 | return ret; | 269 | return bpp; |
270 | } | ||
271 | |||
272 | /* | ||
273 | * pxafb_var_to_lccr3(): | ||
274 | * Convert a bits per pixel value to the correct bit pattern for LCCR3 | ||
275 | * | ||
276 | * NOTE: for PXA27x with overlays support, the LCCR3_PDFOR_x bits have an | ||
277 | * implication of the acutal use of transparency bit, which we handle it | ||
278 | * here separatedly. See PXA27x Developer's Manual, Section <<7.4.6 Pixel | ||
279 | * Formats>> for the valid combination of PDFOR, PAL_FOR for various BPP. | ||
280 | * | ||
281 | * Transparency for palette pixel formats is not supported at the moment. | ||
282 | */ | ||
283 | static uint32_t pxafb_var_to_lccr3(struct fb_var_screeninfo *var) | ||
284 | { | ||
285 | int bpp = pxafb_var_to_bpp(var); | ||
286 | uint32_t lccr3; | ||
287 | |||
288 | if (bpp < 0) | ||
289 | return 0; | ||
290 | |||
291 | lccr3 = LCCR3_BPP(bpp); | ||
292 | |||
293 | switch (var_to_depth(var)) { | ||
294 | case 16: lccr3 |= var->transp.length ? LCCR3_PDFOR_3 : 0; break; | ||
295 | case 18: lccr3 |= LCCR3_PDFOR_3; break; | ||
296 | case 24: lccr3 |= var->transp.length ? LCCR3_PDFOR_2 : LCCR3_PDFOR_3; | ||
297 | break; | ||
298 | case 19: | ||
299 | case 25: lccr3 |= LCCR3_PDFOR_0; break; | ||
300 | } | ||
301 | return lccr3; | ||
302 | } | ||
303 | |||
304 | #define SET_PIXFMT(v, r, g, b, t) \ | ||
305 | ({ \ | ||
306 | (v)->transp.offset = (t) ? (r) + (g) + (b) : 0; \ | ||
307 | (v)->transp.length = (t) ? (t) : 0; \ | ||
308 | (v)->blue.length = (b); (v)->blue.offset = 0; \ | ||
309 | (v)->green.length = (g); (v)->green.offset = (b); \ | ||
310 | (v)->red.length = (r); (v)->red.offset = (b) + (g); \ | ||
311 | }) | ||
312 | |||
313 | /* set the RGBT bitfields of fb_var_screeninf according to | ||
314 | * var->bits_per_pixel and given depth | ||
315 | */ | ||
316 | static void pxafb_set_pixfmt(struct fb_var_screeninfo *var, int depth) | ||
317 | { | ||
318 | if (depth == 0) | ||
319 | depth = var->bits_per_pixel; | ||
320 | |||
321 | if (var->bits_per_pixel < 16) { | ||
322 | /* indexed pixel formats */ | ||
323 | var->red.offset = 0; var->red.length = 8; | ||
324 | var->green.offset = 0; var->green.length = 8; | ||
325 | var->blue.offset = 0; var->blue.length = 8; | ||
326 | var->transp.offset = 0; var->transp.length = 8; | ||
327 | } | ||
328 | |||
329 | switch (depth) { | ||
330 | case 16: var->transp.length ? | ||
331 | SET_PIXFMT(var, 5, 5, 5, 1) : /* RGBT555 */ | ||
332 | SET_PIXFMT(var, 5, 6, 5, 0); break; /* RGB565 */ | ||
333 | case 18: SET_PIXFMT(var, 6, 6, 6, 0); break; /* RGB666 */ | ||
334 | case 19: SET_PIXFMT(var, 6, 6, 6, 1); break; /* RGBT666 */ | ||
335 | case 24: var->transp.length ? | ||
336 | SET_PIXFMT(var, 8, 8, 7, 1) : /* RGBT887 */ | ||
337 | SET_PIXFMT(var, 8, 8, 8, 0); break; /* RGB888 */ | ||
338 | case 25: SET_PIXFMT(var, 8, 8, 8, 1); break; /* RGBT888 */ | ||
339 | } | ||
250 | } | 340 | } |
251 | 341 | ||
252 | #ifdef CONFIG_CPU_FREQ | 342 | #ifdef CONFIG_CPU_FREQ |
@@ -308,8 +398,49 @@ static void pxafb_setmode(struct fb_var_screeninfo *var, | |||
308 | var->lower_margin = mode->lower_margin; | 398 | var->lower_margin = mode->lower_margin; |
309 | var->sync = mode->sync; | 399 | var->sync = mode->sync; |
310 | var->grayscale = mode->cmap_greyscale; | 400 | var->grayscale = mode->cmap_greyscale; |
311 | var->xres_virtual = var->xres; | 401 | |
312 | var->yres_virtual = var->yres; | 402 | /* set the initial RGBA bitfields */ |
403 | pxafb_set_pixfmt(var, mode->depth); | ||
404 | } | ||
405 | |||
406 | static int pxafb_adjust_timing(struct pxafb_info *fbi, | ||
407 | struct fb_var_screeninfo *var) | ||
408 | { | ||
409 | int line_length; | ||
410 | |||
411 | var->xres = max_t(int, var->xres, MIN_XRES); | ||
412 | var->yres = max_t(int, var->yres, MIN_YRES); | ||
413 | |||
414 | if (!(fbi->lccr0 & LCCR0_LCDT)) { | ||
415 | clamp_val(var->hsync_len, 1, 64); | ||
416 | clamp_val(var->vsync_len, 1, 64); | ||
417 | clamp_val(var->left_margin, 1, 255); | ||
418 | clamp_val(var->right_margin, 1, 255); | ||
419 | clamp_val(var->upper_margin, 1, 255); | ||
420 | clamp_val(var->lower_margin, 1, 255); | ||
421 | } | ||
422 | |||
423 | /* make sure each line is aligned on word boundary */ | ||
424 | line_length = var->xres * var->bits_per_pixel / 8; | ||
425 | line_length = ALIGN(line_length, 4); | ||
426 | var->xres = line_length * 8 / var->bits_per_pixel; | ||
427 | |||
428 | /* we don't support xpan, force xres_virtual to be equal to xres */ | ||
429 | var->xres_virtual = var->xres; | ||
430 | |||
431 | if (var->accel_flags & FB_ACCELF_TEXT) | ||
432 | var->yres_virtual = fbi->fb.fix.smem_len / line_length; | ||
433 | else | ||
434 | var->yres_virtual = max(var->yres_virtual, var->yres); | ||
435 | |||
436 | /* check for limits */ | ||
437 | if (var->xres > MAX_XRES || var->yres > MAX_YRES) | ||
438 | return -EINVAL; | ||
439 | |||
440 | if (var->yres > var->yres_virtual) | ||
441 | return -EINVAL; | ||
442 | |||
443 | return 0; | ||
313 | } | 444 | } |
314 | 445 | ||
315 | /* | 446 | /* |
@@ -325,11 +456,7 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | |||
325 | { | 456 | { |
326 | struct pxafb_info *fbi = (struct pxafb_info *)info; | 457 | struct pxafb_info *fbi = (struct pxafb_info *)info; |
327 | struct pxafb_mach_info *inf = fbi->dev->platform_data; | 458 | struct pxafb_mach_info *inf = fbi->dev->platform_data; |
328 | 459 | int err; | |
329 | if (var->xres < MIN_XRES) | ||
330 | var->xres = MIN_XRES; | ||
331 | if (var->yres < MIN_YRES) | ||
332 | var->yres = MIN_YRES; | ||
333 | 460 | ||
334 | if (inf->fixed_modes) { | 461 | if (inf->fixed_modes) { |
335 | struct pxafb_mode_info *mode; | 462 | struct pxafb_mode_info *mode; |
@@ -338,74 +465,18 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | |||
338 | if (!mode) | 465 | if (!mode) |
339 | return -EINVAL; | 466 | return -EINVAL; |
340 | pxafb_setmode(var, mode); | 467 | pxafb_setmode(var, mode); |
341 | } else { | ||
342 | if (var->xres > inf->modes->xres) | ||
343 | return -EINVAL; | ||
344 | if (var->yres > inf->modes->yres) | ||
345 | return -EINVAL; | ||
346 | if (var->bits_per_pixel > inf->modes->bpp) | ||
347 | return -EINVAL; | ||
348 | } | 468 | } |
349 | 469 | ||
350 | var->xres_virtual = | 470 | /* do a test conversion to BPP fields to check the color formats */ |
351 | max(var->xres_virtual, var->xres); | 471 | err = pxafb_var_to_bpp(var); |
352 | var->yres_virtual = | 472 | if (err < 0) |
353 | max(var->yres_virtual, var->yres); | 473 | return err; |
354 | 474 | ||
355 | /* | 475 | pxafb_set_pixfmt(var, var_to_depth(var)); |
356 | * Setup the RGB parameters for this display. | ||
357 | * | ||
358 | * The pixel packing format is described on page 7-11 of the | ||
359 | * PXA2XX Developer's Manual. | ||
360 | */ | ||
361 | if (var->bits_per_pixel == 16) { | ||
362 | var->red.offset = 11; var->red.length = 5; | ||
363 | var->green.offset = 5; var->green.length = 6; | ||
364 | var->blue.offset = 0; var->blue.length = 5; | ||
365 | var->transp.offset = var->transp.length = 0; | ||
366 | } else if (var->bits_per_pixel > 16) { | ||
367 | struct pxafb_mode_info *mode; | ||
368 | 476 | ||
369 | mode = pxafb_getmode(inf, var); | 477 | err = pxafb_adjust_timing(fbi, var); |
370 | if (!mode) | 478 | if (err) |
371 | return -EINVAL; | 479 | return err; |
372 | |||
373 | switch (mode->depth) { | ||
374 | case 18: /* RGB666 */ | ||
375 | var->transp.offset = var->transp.length = 0; | ||
376 | var->red.offset = 12; var->red.length = 6; | ||
377 | var->green.offset = 6; var->green.length = 6; | ||
378 | var->blue.offset = 0; var->blue.length = 6; | ||
379 | break; | ||
380 | case 19: /* RGBT666 */ | ||
381 | var->transp.offset = 18; var->transp.length = 1; | ||
382 | var->red.offset = 12; var->red.length = 6; | ||
383 | var->green.offset = 6; var->green.length = 6; | ||
384 | var->blue.offset = 0; var->blue.length = 6; | ||
385 | break; | ||
386 | case 24: /* RGB888 */ | ||
387 | var->transp.offset = var->transp.length = 0; | ||
388 | var->red.offset = 16; var->red.length = 8; | ||
389 | var->green.offset = 8; var->green.length = 8; | ||
390 | var->blue.offset = 0; var->blue.length = 8; | ||
391 | break; | ||
392 | case 25: /* RGBT888 */ | ||
393 | var->transp.offset = 24; var->transp.length = 1; | ||
394 | var->red.offset = 16; var->red.length = 8; | ||
395 | var->green.offset = 8; var->green.length = 8; | ||
396 | var->blue.offset = 0; var->blue.length = 8; | ||
397 | break; | ||
398 | default: | ||
399 | return -EINVAL; | ||
400 | } | ||
401 | } else { | ||
402 | var->red.offset = var->green.offset = 0; | ||
403 | var->blue.offset = var->transp.offset = 0; | ||
404 | var->red.length = 8; | ||
405 | var->green.length = 8; | ||
406 | var->blue.length = 8; | ||
407 | var->transp.length = 0; | ||
408 | } | ||
409 | 480 | ||
410 | #ifdef CONFIG_CPU_FREQ | 481 | #ifdef CONFIG_CPU_FREQ |
411 | pr_debug("pxafb: dma period = %d ps\n", | 482 | pr_debug("pxafb: dma period = %d ps\n", |
@@ -415,11 +486,6 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) | |||
415 | return 0; | 486 | return 0; |
416 | } | 487 | } |
417 | 488 | ||
418 | static inline void pxafb_set_truecolor(u_int is_true_color) | ||
419 | { | ||
420 | /* do your machine-specific setup if needed */ | ||
421 | } | ||
422 | |||
423 | /* | 489 | /* |
424 | * pxafb_set_par(): | 490 | * pxafb_set_par(): |
425 | * Set the user defined part of the display for the specified console | 491 | * Set the user defined part of the display for the specified console |
@@ -452,11 +518,6 @@ static int pxafb_set_par(struct fb_info *info) | |||
452 | 518 | ||
453 | fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0]; | 519 | fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0]; |
454 | 520 | ||
455 | /* | ||
456 | * Set (any) board control register to handle new color depth | ||
457 | */ | ||
458 | pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR); | ||
459 | |||
460 | if (fbi->fb.var.bits_per_pixel >= 16) | 521 | if (fbi->fb.var.bits_per_pixel >= 16) |
461 | fb_dealloc_cmap(&fbi->fb.cmap); | 522 | fb_dealloc_cmap(&fbi->fb.cmap); |
462 | else | 523 | else |
@@ -467,6 +528,24 @@ static int pxafb_set_par(struct fb_info *info) | |||
467 | return 0; | 528 | return 0; |
468 | } | 529 | } |
469 | 530 | ||
531 | static int pxafb_pan_display(struct fb_var_screeninfo *var, | ||
532 | struct fb_info *info) | ||
533 | { | ||
534 | struct pxafb_info *fbi = (struct pxafb_info *)info; | ||
535 | int dma = DMA_MAX + DMA_BASE; | ||
536 | |||
537 | if (fbi->state != C_ENABLE) | ||
538 | return 0; | ||
539 | |||
540 | setup_base_frame(fbi, 1); | ||
541 | |||
542 | if (fbi->lccr0 & LCCR0_SDS) | ||
543 | lcd_writel(fbi, FBR1, fbi->fdadr[dma + 1] | 0x1); | ||
544 | |||
545 | lcd_writel(fbi, FBR0, fbi->fdadr[dma] | 0x1); | ||
546 | return 0; | ||
547 | } | ||
548 | |||
470 | /* | 549 | /* |
471 | * pxafb_blank(): | 550 | * pxafb_blank(): |
472 | * Blank the display by setting all palette values to zero. Note, the | 551 | * Blank the display by setting all palette values to zero. Note, the |
@@ -502,32 +581,342 @@ static int pxafb_blank(int blank, struct fb_info *info) | |||
502 | return 0; | 581 | return 0; |
503 | } | 582 | } |
504 | 583 | ||
505 | static int pxafb_mmap(struct fb_info *info, | ||
506 | struct vm_area_struct *vma) | ||
507 | { | ||
508 | struct pxafb_info *fbi = (struct pxafb_info *)info; | ||
509 | unsigned long off = vma->vm_pgoff << PAGE_SHIFT; | ||
510 | |||
511 | if (off < info->fix.smem_len) { | ||
512 | vma->vm_pgoff += fbi->video_offset / PAGE_SIZE; | ||
513 | return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu, | ||
514 | fbi->map_dma, fbi->map_size); | ||
515 | } | ||
516 | return -EINVAL; | ||
517 | } | ||
518 | |||
519 | static struct fb_ops pxafb_ops = { | 584 | static struct fb_ops pxafb_ops = { |
520 | .owner = THIS_MODULE, | 585 | .owner = THIS_MODULE, |
521 | .fb_check_var = pxafb_check_var, | 586 | .fb_check_var = pxafb_check_var, |
522 | .fb_set_par = pxafb_set_par, | 587 | .fb_set_par = pxafb_set_par, |
588 | .fb_pan_display = pxafb_pan_display, | ||
523 | .fb_setcolreg = pxafb_setcolreg, | 589 | .fb_setcolreg = pxafb_setcolreg, |
524 | .fb_fillrect = cfb_fillrect, | 590 | .fb_fillrect = cfb_fillrect, |
525 | .fb_copyarea = cfb_copyarea, | 591 | .fb_copyarea = cfb_copyarea, |
526 | .fb_imageblit = cfb_imageblit, | 592 | .fb_imageblit = cfb_imageblit, |
527 | .fb_blank = pxafb_blank, | 593 | .fb_blank = pxafb_blank, |
528 | .fb_mmap = pxafb_mmap, | ||
529 | }; | 594 | }; |
530 | 595 | ||
596 | #ifdef CONFIG_FB_PXA_OVERLAY | ||
597 | static void overlay1fb_setup(struct pxafb_layer *ofb) | ||
598 | { | ||
599 | int size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual; | ||
600 | unsigned long start = ofb->video_mem_phys; | ||
601 | setup_frame_dma(ofb->fbi, DMA_OV1, PAL_NONE, start, size); | ||
602 | } | ||
603 | |||
604 | /* Depending on the enable status of overlay1/2, the DMA should be | ||
605 | * updated from FDADRx (when disabled) or FBRx (when enabled). | ||
606 | */ | ||
607 | static void overlay1fb_enable(struct pxafb_layer *ofb) | ||
608 | { | ||
609 | int enabled = lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN; | ||
610 | uint32_t fdadr1 = ofb->fbi->fdadr[DMA_OV1] | (enabled ? 0x1 : 0); | ||
611 | |||
612 | lcd_writel(ofb->fbi, enabled ? FBR1 : FDADR1, fdadr1); | ||
613 | lcd_writel(ofb->fbi, OVL1C2, ofb->control[1]); | ||
614 | lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] | OVLxC1_OEN); | ||
615 | } | ||
616 | |||
617 | static void overlay1fb_disable(struct pxafb_layer *ofb) | ||
618 | { | ||
619 | uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); | ||
620 | |||
621 | lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN); | ||
622 | |||
623 | lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1)); | ||
624 | lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1)); | ||
625 | lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3); | ||
626 | |||
627 | if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) | ||
628 | pr_warning("%s: timeout disabling overlay1\n", __func__); | ||
629 | |||
630 | lcd_writel(ofb->fbi, LCCR5, lccr5); | ||
631 | } | ||
632 | |||
633 | static void overlay2fb_setup(struct pxafb_layer *ofb) | ||
634 | { | ||
635 | int size, div = 1, pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd); | ||
636 | unsigned long start[3] = { ofb->video_mem_phys, 0, 0 }; | ||
637 | |||
638 | if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED) { | ||
639 | size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual; | ||
640 | setup_frame_dma(ofb->fbi, DMA_OV2_Y, -1, start[0], size); | ||
641 | } else { | ||
642 | size = ofb->fb.var.xres_virtual * ofb->fb.var.yres_virtual; | ||
643 | switch (pfor) { | ||
644 | case OVERLAY_FORMAT_YUV444_PLANAR: div = 1; break; | ||
645 | case OVERLAY_FORMAT_YUV422_PLANAR: div = 2; break; | ||
646 | case OVERLAY_FORMAT_YUV420_PLANAR: div = 4; break; | ||
647 | } | ||
648 | start[1] = start[0] + size; | ||
649 | start[2] = start[1] + size / div; | ||
650 | setup_frame_dma(ofb->fbi, DMA_OV2_Y, -1, start[0], size); | ||
651 | setup_frame_dma(ofb->fbi, DMA_OV2_Cb, -1, start[1], size / div); | ||
652 | setup_frame_dma(ofb->fbi, DMA_OV2_Cr, -1, start[2], size / div); | ||
653 | } | ||
654 | } | ||
655 | |||
656 | static void overlay2fb_enable(struct pxafb_layer *ofb) | ||
657 | { | ||
658 | int pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd); | ||
659 | int enabled = lcd_readl(ofb->fbi, OVL2C1) & OVLxC1_OEN; | ||
660 | uint32_t fdadr2 = ofb->fbi->fdadr[DMA_OV2_Y] | (enabled ? 0x1 : 0); | ||
661 | uint32_t fdadr3 = ofb->fbi->fdadr[DMA_OV2_Cb] | (enabled ? 0x1 : 0); | ||
662 | uint32_t fdadr4 = ofb->fbi->fdadr[DMA_OV2_Cr] | (enabled ? 0x1 : 0); | ||
663 | |||
664 | if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED) | ||
665 | lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2); | ||
666 | else { | ||
667 | lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2); | ||
668 | lcd_writel(ofb->fbi, enabled ? FBR3 : FDADR3, fdadr3); | ||
669 | lcd_writel(ofb->fbi, enabled ? FBR4 : FDADR4, fdadr4); | ||
670 | } | ||
671 | lcd_writel(ofb->fbi, OVL2C2, ofb->control[1]); | ||
672 | lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] | OVLxC1_OEN); | ||
673 | } | ||
674 | |||
675 | static void overlay2fb_disable(struct pxafb_layer *ofb) | ||
676 | { | ||
677 | uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); | ||
678 | |||
679 | lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN); | ||
680 | |||
681 | lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2)); | ||
682 | lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2)); | ||
683 | lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] | 0x3); | ||
684 | lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3); | ||
685 | lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3); | ||
686 | |||
687 | if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) | ||
688 | pr_warning("%s: timeout disabling overlay2\n", __func__); | ||
689 | } | ||
690 | |||
691 | static struct pxafb_layer_ops ofb_ops[] = { | ||
692 | [0] = { | ||
693 | .enable = overlay1fb_enable, | ||
694 | .disable = overlay1fb_disable, | ||
695 | .setup = overlay1fb_setup, | ||
696 | }, | ||
697 | [1] = { | ||
698 | .enable = overlay2fb_enable, | ||
699 | .disable = overlay2fb_disable, | ||
700 | .setup = overlay2fb_setup, | ||
701 | }, | ||
702 | }; | ||
703 | |||
704 | static int overlayfb_open(struct fb_info *info, int user) | ||
705 | { | ||
706 | struct pxafb_layer *ofb = (struct pxafb_layer *)info; | ||
707 | |||
708 | /* no support for framebuffer console on overlay */ | ||
709 | if (user == 0) | ||
710 | return -ENODEV; | ||
711 | |||
712 | /* allow only one user at a time */ | ||
713 | if (atomic_inc_and_test(&ofb->usage)) | ||
714 | return -EBUSY; | ||
715 | |||
716 | /* unblank the base framebuffer */ | ||
717 | fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK); | ||
718 | return 0; | ||
719 | } | ||
720 | |||
721 | static int overlayfb_release(struct fb_info *info, int user) | ||
722 | { | ||
723 | struct pxafb_layer *ofb = (struct pxafb_layer*) info; | ||
724 | |||
725 | atomic_dec(&ofb->usage); | ||
726 | ofb->ops->disable(ofb); | ||
727 | |||
728 | free_pages_exact(ofb->video_mem, ofb->video_mem_size); | ||
729 | ofb->video_mem = NULL; | ||
730 | ofb->video_mem_size = 0; | ||
731 | return 0; | ||
732 | } | ||
733 | |||
734 | static int overlayfb_check_var(struct fb_var_screeninfo *var, | ||
735 | struct fb_info *info) | ||
736 | { | ||
737 | struct pxafb_layer *ofb = (struct pxafb_layer *)info; | ||
738 | struct fb_var_screeninfo *base_var = &ofb->fbi->fb.var; | ||
739 | int xpos, ypos, pfor, bpp; | ||
740 | |||
741 | xpos = NONSTD_TO_XPOS(var->nonstd); | ||
742 | ypos = NONSTD_TO_XPOS(var->nonstd); | ||
743 | pfor = NONSTD_TO_PFOR(var->nonstd); | ||
744 | |||
745 | bpp = pxafb_var_to_bpp(var); | ||
746 | if (bpp < 0) | ||
747 | return -EINVAL; | ||
748 | |||
749 | /* no support for YUV format on overlay1 */ | ||
750 | if (ofb->id == OVERLAY1 && pfor != 0) | ||
751 | return -EINVAL; | ||
752 | |||
753 | /* for YUV packed formats, bpp = 'minimum bpp of YUV components' */ | ||
754 | switch (pfor) { | ||
755 | case OVERLAY_FORMAT_RGB: | ||
756 | bpp = pxafb_var_to_bpp(var); | ||
757 | if (bpp < 0) | ||
758 | return -EINVAL; | ||
759 | |||
760 | pxafb_set_pixfmt(var, var_to_depth(var)); | ||
761 | break; | ||
762 | case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break; | ||
763 | case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 8; break; | ||
764 | case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 4; break; | ||
765 | case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 2; break; | ||
766 | default: | ||
767 | return -EINVAL; | ||
768 | } | ||
769 | |||
770 | /* each line must start at a 32-bit word boundary */ | ||
771 | if ((xpos * bpp) % 32) | ||
772 | return -EINVAL; | ||
773 | |||
774 | /* xres must align on 32-bit word boundary */ | ||
775 | var->xres = roundup(var->xres * bpp, 32) / bpp; | ||
776 | |||
777 | if ((xpos + var->xres > base_var->xres) || | ||
778 | (ypos + var->yres > base_var->yres)) | ||
779 | return -EINVAL; | ||
780 | |||
781 | var->xres_virtual = var->xres; | ||
782 | var->yres_virtual = max(var->yres, var->yres_virtual); | ||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | static int overlayfb_map_video_memory(struct pxafb_layer *ofb) | ||
787 | { | ||
788 | struct fb_var_screeninfo *var = &ofb->fb.var; | ||
789 | int pfor = NONSTD_TO_PFOR(var->nonstd); | ||
790 | int size, bpp = 0; | ||
791 | |||
792 | switch (pfor) { | ||
793 | case OVERLAY_FORMAT_RGB: bpp = var->bits_per_pixel; break; | ||
794 | case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break; | ||
795 | case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 24; break; | ||
796 | case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 16; break; | ||
797 | case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 12; break; | ||
798 | } | ||
799 | |||
800 | ofb->fb.fix.line_length = var->xres_virtual * bpp / 8; | ||
801 | |||
802 | size = PAGE_ALIGN(ofb->fb.fix.line_length * var->yres_virtual); | ||
803 | |||
804 | /* don't re-allocate if the original video memory is enough */ | ||
805 | if (ofb->video_mem) { | ||
806 | if (ofb->video_mem_size >= size) | ||
807 | return 0; | ||
808 | |||
809 | free_pages_exact(ofb->video_mem, ofb->video_mem_size); | ||
810 | } | ||
811 | |||
812 | ofb->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); | ||
813 | if (ofb->video_mem == NULL) | ||
814 | return -ENOMEM; | ||
815 | |||
816 | ofb->video_mem_phys = virt_to_phys(ofb->video_mem); | ||
817 | ofb->video_mem_size = size; | ||
818 | |||
819 | ofb->fb.fix.smem_start = ofb->video_mem_phys; | ||
820 | ofb->fb.fix.smem_len = ofb->fb.fix.line_length * var->yres_virtual; | ||
821 | ofb->fb.screen_base = ofb->video_mem; | ||
822 | return 0; | ||
823 | } | ||
824 | |||
825 | static int overlayfb_set_par(struct fb_info *info) | ||
826 | { | ||
827 | struct pxafb_layer *ofb = (struct pxafb_layer *)info; | ||
828 | struct fb_var_screeninfo *var = &info->var; | ||
829 | int xpos, ypos, pfor, bpp, ret; | ||
830 | |||
831 | ret = overlayfb_map_video_memory(ofb); | ||
832 | if (ret) | ||
833 | return ret; | ||
834 | |||
835 | bpp = pxafb_var_to_bpp(var); | ||
836 | xpos = NONSTD_TO_XPOS(var->nonstd); | ||
837 | ypos = NONSTD_TO_XPOS(var->nonstd); | ||
838 | pfor = NONSTD_TO_PFOR(var->nonstd); | ||
839 | |||
840 | ofb->control[0] = OVLxC1_PPL(var->xres) | OVLxC1_LPO(var->yres) | | ||
841 | OVLxC1_BPP(bpp); | ||
842 | ofb->control[1] = OVLxC2_XPOS(xpos) | OVLxC2_YPOS(ypos); | ||
843 | |||
844 | if (ofb->id == OVERLAY2) | ||
845 | ofb->control[1] |= OVL2C2_PFOR(pfor); | ||
846 | |||
847 | ofb->ops->setup(ofb); | ||
848 | ofb->ops->enable(ofb); | ||
849 | return 0; | ||
850 | } | ||
851 | |||
852 | static struct fb_ops overlay_fb_ops = { | ||
853 | .owner = THIS_MODULE, | ||
854 | .fb_open = overlayfb_open, | ||
855 | .fb_release = overlayfb_release, | ||
856 | .fb_check_var = overlayfb_check_var, | ||
857 | .fb_set_par = overlayfb_set_par, | ||
858 | }; | ||
859 | |||
860 | static void __devinit init_pxafb_overlay(struct pxafb_info *fbi, | ||
861 | struct pxafb_layer *ofb, int id) | ||
862 | { | ||
863 | sprintf(ofb->fb.fix.id, "overlay%d", id + 1); | ||
864 | |||
865 | ofb->fb.fix.type = FB_TYPE_PACKED_PIXELS; | ||
866 | ofb->fb.fix.xpanstep = 0; | ||
867 | ofb->fb.fix.ypanstep = 1; | ||
868 | |||
869 | ofb->fb.var.activate = FB_ACTIVATE_NOW; | ||
870 | ofb->fb.var.height = -1; | ||
871 | ofb->fb.var.width = -1; | ||
872 | ofb->fb.var.vmode = FB_VMODE_NONINTERLACED; | ||
873 | |||
874 | ofb->fb.fbops = &overlay_fb_ops; | ||
875 | ofb->fb.flags = FBINFO_FLAG_DEFAULT; | ||
876 | ofb->fb.node = -1; | ||
877 | ofb->fb.pseudo_palette = NULL; | ||
878 | |||
879 | ofb->id = id; | ||
880 | ofb->ops = &ofb_ops[id]; | ||
881 | atomic_set(&ofb->usage, 0); | ||
882 | ofb->fbi = fbi; | ||
883 | init_completion(&ofb->branch_done); | ||
884 | } | ||
885 | |||
886 | static int __devinit pxafb_overlay_init(struct pxafb_info *fbi) | ||
887 | { | ||
888 | int i, ret; | ||
889 | |||
890 | for (i = 0; i < 2; i++) { | ||
891 | init_pxafb_overlay(fbi, &fbi->overlay[i], i); | ||
892 | ret = register_framebuffer(&fbi->overlay[i].fb); | ||
893 | if (ret) { | ||
894 | dev_err(fbi->dev, "failed to register overlay %d\n", i); | ||
895 | return ret; | ||
896 | } | ||
897 | } | ||
898 | |||
899 | /* mask all IU/BS/EOF/SOF interrupts */ | ||
900 | lcd_writel(fbi, LCCR5, ~0); | ||
901 | |||
902 | /* place overlay(s) on top of base */ | ||
903 | fbi->lccr0 |= LCCR0_OUC; | ||
904 | pr_info("PXA Overlay driver loaded successfully!\n"); | ||
905 | return 0; | ||
906 | } | ||
907 | |||
908 | static void __devexit pxafb_overlay_exit(struct pxafb_info *fbi) | ||
909 | { | ||
910 | int i; | ||
911 | |||
912 | for (i = 0; i < 2; i++) | ||
913 | unregister_framebuffer(&fbi->overlay[i].fb); | ||
914 | } | ||
915 | #else | ||
916 | static inline void pxafb_overlay_init(struct pxafb_info *fbi) {} | ||
917 | static inline void pxafb_overlay_exit(struct pxafb_info *fbi) {} | ||
918 | #endif /* CONFIG_FB_PXA_OVERLAY */ | ||
919 | |||
531 | /* | 920 | /* |
532 | * Calculate the PCD value from the clock rate (in picoseconds). | 921 | * Calculate the PCD value from the clock rate (in picoseconds). |
533 | * We take account of the PPCR clock setting. | 922 | * We take account of the PPCR clock setting. |
@@ -607,22 +996,22 @@ unsigned long pxafb_get_hsync_time(struct device *dev) | |||
607 | EXPORT_SYMBOL(pxafb_get_hsync_time); | 996 | EXPORT_SYMBOL(pxafb_get_hsync_time); |
608 | 997 | ||
609 | static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, | 998 | static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, |
610 | unsigned int offset, size_t size) | 999 | unsigned long start, size_t size) |
611 | { | 1000 | { |
612 | struct pxafb_dma_descriptor *dma_desc, *pal_desc; | 1001 | struct pxafb_dma_descriptor *dma_desc, *pal_desc; |
613 | unsigned int dma_desc_off, pal_desc_off; | 1002 | unsigned int dma_desc_off, pal_desc_off; |
614 | 1003 | ||
615 | if (dma < 0 || dma >= DMA_MAX) | 1004 | if (dma < 0 || dma >= DMA_MAX * 2) |
616 | return -EINVAL; | 1005 | return -EINVAL; |
617 | 1006 | ||
618 | dma_desc = &fbi->dma_buff->dma_desc[dma]; | 1007 | dma_desc = &fbi->dma_buff->dma_desc[dma]; |
619 | dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]); | 1008 | dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]); |
620 | 1009 | ||
621 | dma_desc->fsadr = fbi->screen_dma + offset; | 1010 | dma_desc->fsadr = start; |
622 | dma_desc->fidr = 0; | 1011 | dma_desc->fidr = 0; |
623 | dma_desc->ldcmd = size; | 1012 | dma_desc->ldcmd = size; |
624 | 1013 | ||
625 | if (pal < 0 || pal >= PAL_MAX) { | 1014 | if (pal < 0 || pal >= PAL_MAX * 2) { |
626 | dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off; | 1015 | dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off; |
627 | fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off; | 1016 | fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off; |
628 | } else { | 1017 | } else { |
@@ -648,6 +1037,27 @@ static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, | |||
648 | return 0; | 1037 | return 0; |
649 | } | 1038 | } |
650 | 1039 | ||
1040 | static void setup_base_frame(struct pxafb_info *fbi, int branch) | ||
1041 | { | ||
1042 | struct fb_var_screeninfo *var = &fbi->fb.var; | ||
1043 | struct fb_fix_screeninfo *fix = &fbi->fb.fix; | ||
1044 | int nbytes, dma, pal, bpp = var->bits_per_pixel; | ||
1045 | unsigned long offset; | ||
1046 | |||
1047 | dma = DMA_BASE + (branch ? DMA_MAX : 0); | ||
1048 | pal = (bpp >= 16) ? PAL_NONE : PAL_BASE + (branch ? PAL_MAX : 0); | ||
1049 | |||
1050 | nbytes = fix->line_length * var->yres; | ||
1051 | offset = fix->line_length * var->yoffset + fbi->video_mem_phys; | ||
1052 | |||
1053 | if (fbi->lccr0 & LCCR0_SDS) { | ||
1054 | nbytes = nbytes / 2; | ||
1055 | setup_frame_dma(fbi, dma + 1, PAL_NONE, offset + nbytes, nbytes); | ||
1056 | } | ||
1057 | |||
1058 | setup_frame_dma(fbi, dma, pal, offset, nbytes); | ||
1059 | } | ||
1060 | |||
651 | #ifdef CONFIG_FB_PXA_SMARTPANEL | 1061 | #ifdef CONFIG_FB_PXA_SMARTPANEL |
652 | static int setup_smart_dma(struct pxafb_info *fbi) | 1062 | static int setup_smart_dma(struct pxafb_info *fbi) |
653 | { | 1063 | { |
@@ -701,6 +1111,7 @@ int pxafb_smart_flush(struct fb_info *info) | |||
701 | lcd_writel(fbi, LCCR1, fbi->reg_lccr1); | 1111 | lcd_writel(fbi, LCCR1, fbi->reg_lccr1); |
702 | lcd_writel(fbi, LCCR2, fbi->reg_lccr2); | 1112 | lcd_writel(fbi, LCCR2, fbi->reg_lccr2); |
703 | lcd_writel(fbi, LCCR3, fbi->reg_lccr3); | 1113 | lcd_writel(fbi, LCCR3, fbi->reg_lccr3); |
1114 | lcd_writel(fbi, LCCR4, fbi->reg_lccr4); | ||
704 | lcd_writel(fbi, FDADR0, fbi->fdadr[0]); | 1115 | lcd_writel(fbi, FDADR0, fbi->fdadr[0]); |
705 | lcd_writel(fbi, FDADR6, fbi->fdadr[6]); | 1116 | lcd_writel(fbi, FDADR6, fbi->fdadr[6]); |
706 | 1117 | ||
@@ -727,12 +1138,19 @@ int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds) | |||
727 | int i; | 1138 | int i; |
728 | struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb); | 1139 | struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb); |
729 | 1140 | ||
730 | /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */ | 1141 | for (i = 0; i < n_cmds; i++, cmds++) { |
731 | for (i = 0; i < n_cmds; i++) { | 1142 | /* if it is a software delay, flush and delay */ |
1143 | if ((*cmds & 0xff00) == SMART_CMD_DELAY) { | ||
1144 | pxafb_smart_flush(info); | ||
1145 | mdelay(*cmds & 0xff); | ||
1146 | continue; | ||
1147 | } | ||
1148 | |||
1149 | /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */ | ||
732 | if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8) | 1150 | if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8) |
733 | pxafb_smart_flush(info); | 1151 | pxafb_smart_flush(info); |
734 | 1152 | ||
735 | fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds++; | 1153 | fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds; |
736 | } | 1154 | } |
737 | 1155 | ||
738 | return 0; | 1156 | return 0; |
@@ -764,7 +1182,9 @@ static void setup_smart_timing(struct pxafb_info *fbi, | |||
764 | LCCR1_HorSnchWdth(__smart_timing(t3, lclk)); | 1182 | LCCR1_HorSnchWdth(__smart_timing(t3, lclk)); |
765 | 1183 | ||
766 | fbi->reg_lccr2 = LCCR2_DisHght(var->yres); | 1184 | fbi->reg_lccr2 = LCCR2_DisHght(var->yres); |
767 | fbi->reg_lccr3 = LCCR3_PixClkDiv(__smart_timing(t4, lclk)); | 1185 | fbi->reg_lccr3 = fbi->lccr3 | LCCR3_PixClkDiv(__smart_timing(t4, lclk)); |
1186 | fbi->reg_lccr3 |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? LCCR3_HSP : 0; | ||
1187 | fbi->reg_lccr3 |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? LCCR3_VSP : 0; | ||
768 | 1188 | ||
769 | /* FIXME: make this configurable */ | 1189 | /* FIXME: make this configurable */ |
770 | fbi->reg_cmdcr = 1; | 1190 | fbi->reg_cmdcr = 1; |
@@ -789,11 +1209,15 @@ static int pxafb_smart_thread(void *arg) | |||
789 | if (try_to_freeze()) | 1209 | if (try_to_freeze()) |
790 | continue; | 1210 | continue; |
791 | 1211 | ||
1212 | mutex_lock(&fbi->ctrlr_lock); | ||
1213 | |||
792 | if (fbi->state == C_ENABLE) { | 1214 | if (fbi->state == C_ENABLE) { |
793 | inf->smart_update(&fbi->fb); | 1215 | inf->smart_update(&fbi->fb); |
794 | complete(&fbi->refresh_done); | 1216 | complete(&fbi->refresh_done); |
795 | } | 1217 | } |
796 | 1218 | ||
1219 | mutex_unlock(&fbi->ctrlr_lock); | ||
1220 | |||
797 | set_current_state(TASK_INTERRUPTIBLE); | 1221 | set_current_state(TASK_INTERRUPTIBLE); |
798 | schedule_timeout(30 * HZ / 1000); | 1222 | schedule_timeout(30 * HZ / 1000); |
799 | } | 1223 | } |
@@ -804,16 +1228,22 @@ static int pxafb_smart_thread(void *arg) | |||
804 | 1228 | ||
805 | static int pxafb_smart_init(struct pxafb_info *fbi) | 1229 | static int pxafb_smart_init(struct pxafb_info *fbi) |
806 | { | 1230 | { |
807 | if (!(fbi->lccr0 | LCCR0_LCDT)) | 1231 | if (!(fbi->lccr0 & LCCR0_LCDT)) |
808 | return 0; | 1232 | return 0; |
809 | 1233 | ||
1234 | fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff; | ||
1235 | fbi->n_smart_cmds = 0; | ||
1236 | |||
1237 | init_completion(&fbi->command_done); | ||
1238 | init_completion(&fbi->refresh_done); | ||
1239 | |||
810 | fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi, | 1240 | fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi, |
811 | "lcd_refresh"); | 1241 | "lcd_refresh"); |
812 | if (IS_ERR(fbi->smart_thread)) { | 1242 | if (IS_ERR(fbi->smart_thread)) { |
813 | printk(KERN_ERR "%s: unable to create kernel thread\n", | 1243 | pr_err("%s: unable to create kernel thread\n", __func__); |
814 | __func__); | ||
815 | return PTR_ERR(fbi->smart_thread); | 1244 | return PTR_ERR(fbi->smart_thread); |
816 | } | 1245 | } |
1246 | |||
817 | return 0; | 1247 | return 0; |
818 | } | 1248 | } |
819 | #else | 1249 | #else |
@@ -826,7 +1256,9 @@ int pxafb_smart_flush(struct fb_info *info) | |||
826 | { | 1256 | { |
827 | return 0; | 1257 | return 0; |
828 | } | 1258 | } |
829 | #endif /* CONFIG_FB_SMART_PANEL */ | 1259 | |
1260 | static inline int pxafb_smart_init(struct pxafb_info *fbi) { return 0; } | ||
1261 | #endif /* CONFIG_FB_PXA_SMARTPANEL */ | ||
830 | 1262 | ||
831 | static void setup_parallel_timing(struct pxafb_info *fbi, | 1263 | static void setup_parallel_timing(struct pxafb_info *fbi, |
832 | struct fb_var_screeninfo *var) | 1264 | struct fb_var_screeninfo *var) |
@@ -874,51 +1306,7 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, | |||
874 | struct pxafb_info *fbi) | 1306 | struct pxafb_info *fbi) |
875 | { | 1307 | { |
876 | u_long flags; | 1308 | u_long flags; |
877 | size_t nbytes; | ||
878 | |||
879 | #if DEBUG_VAR | ||
880 | if (!(fbi->lccr0 & LCCR0_LCDT)) { | ||
881 | if (var->xres < 16 || var->xres > 1024) | ||
882 | printk(KERN_ERR "%s: invalid xres %d\n", | ||
883 | fbi->fb.fix.id, var->xres); | ||
884 | switch (var->bits_per_pixel) { | ||
885 | case 1: | ||
886 | case 2: | ||
887 | case 4: | ||
888 | case 8: | ||
889 | case 16: | ||
890 | case 24: | ||
891 | case 32: | ||
892 | break; | ||
893 | default: | ||
894 | printk(KERN_ERR "%s: invalid bit depth %d\n", | ||
895 | fbi->fb.fix.id, var->bits_per_pixel); | ||
896 | break; | ||
897 | } | ||
898 | 1309 | ||
899 | if (var->hsync_len < 1 || var->hsync_len > 64) | ||
900 | printk(KERN_ERR "%s: invalid hsync_len %d\n", | ||
901 | fbi->fb.fix.id, var->hsync_len); | ||
902 | if (var->left_margin < 1 || var->left_margin > 255) | ||
903 | printk(KERN_ERR "%s: invalid left_margin %d\n", | ||
904 | fbi->fb.fix.id, var->left_margin); | ||
905 | if (var->right_margin < 1 || var->right_margin > 255) | ||
906 | printk(KERN_ERR "%s: invalid right_margin %d\n", | ||
907 | fbi->fb.fix.id, var->right_margin); | ||
908 | if (var->yres < 1 || var->yres > 1024) | ||
909 | printk(KERN_ERR "%s: invalid yres %d\n", | ||
910 | fbi->fb.fix.id, var->yres); | ||
911 | if (var->vsync_len < 1 || var->vsync_len > 64) | ||
912 | printk(KERN_ERR "%s: invalid vsync_len %d\n", | ||
913 | fbi->fb.fix.id, var->vsync_len); | ||
914 | if (var->upper_margin < 0 || var->upper_margin > 255) | ||
915 | printk(KERN_ERR "%s: invalid upper_margin %d\n", | ||
916 | fbi->fb.fix.id, var->upper_margin); | ||
917 | if (var->lower_margin < 0 || var->lower_margin > 255) | ||
918 | printk(KERN_ERR "%s: invalid lower_margin %d\n", | ||
919 | fbi->fb.fix.id, var->lower_margin); | ||
920 | } | ||
921 | #endif | ||
922 | /* Update shadow copy atomically */ | 1310 | /* Update shadow copy atomically */ |
923 | local_irq_save(flags); | 1311 | local_irq_save(flags); |
924 | 1312 | ||
@@ -929,23 +1317,13 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, | |||
929 | #endif | 1317 | #endif |
930 | setup_parallel_timing(fbi, var); | 1318 | setup_parallel_timing(fbi, var); |
931 | 1319 | ||
1320 | setup_base_frame(fbi, 0); | ||
1321 | |||
932 | fbi->reg_lccr0 = fbi->lccr0 | | 1322 | fbi->reg_lccr0 = fbi->lccr0 | |
933 | (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | | 1323 | (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | |
934 | LCCR0_QDM | LCCR0_BM | LCCR0_OUM); | 1324 | LCCR0_QDM | LCCR0_BM | LCCR0_OUM); |
935 | 1325 | ||
936 | fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var); | 1326 | fbi->reg_lccr3 |= pxafb_var_to_lccr3(var); |
937 | |||
938 | nbytes = var->yres * fbi->fb.fix.line_length; | ||
939 | |||
940 | if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) { | ||
941 | nbytes = nbytes / 2; | ||
942 | setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, nbytes, nbytes); | ||
943 | } | ||
944 | |||
945 | if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT)) | ||
946 | setup_frame_dma(fbi, DMA_BASE, PAL_NONE, 0, nbytes); | ||
947 | else | ||
948 | setup_frame_dma(fbi, DMA_BASE, PAL_BASE, 0, nbytes); | ||
949 | 1327 | ||
950 | fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK; | 1328 | fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK; |
951 | fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK); | 1329 | fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK); |
@@ -959,6 +1337,7 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, | |||
959 | (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) || | 1337 | (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) || |
960 | (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) || | 1338 | (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) || |
961 | (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) || | 1339 | (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) || |
1340 | (lcd_readl(fbi, LCCR4) != fbi->reg_lccr4) || | ||
962 | (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) || | 1341 | (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) || |
963 | (lcd_readl(fbi, FDADR1) != fbi->fdadr[1])) | 1342 | (lcd_readl(fbi, FDADR1) != fbi->fdadr[1])) |
964 | pxafb_schedule_work(fbi, C_REENABLE); | 1343 | pxafb_schedule_work(fbi, C_REENABLE); |
@@ -976,67 +1355,16 @@ static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on) | |||
976 | { | 1355 | { |
977 | pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff"); | 1356 | pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff"); |
978 | 1357 | ||
979 | if (pxafb_backlight_power) | 1358 | if (fbi->backlight_power) |
980 | pxafb_backlight_power(on); | 1359 | fbi->backlight_power(on); |
981 | } | 1360 | } |
982 | 1361 | ||
983 | static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on) | 1362 | static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on) |
984 | { | 1363 | { |
985 | pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff"); | 1364 | pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff"); |
986 | 1365 | ||
987 | if (pxafb_lcd_power) | 1366 | if (fbi->lcd_power) |
988 | pxafb_lcd_power(on, &fbi->fb.var); | 1367 | fbi->lcd_power(on, &fbi->fb.var); |
989 | } | ||
990 | |||
991 | static void pxafb_setup_gpio(struct pxafb_info *fbi) | ||
992 | { | ||
993 | int gpio, ldd_bits; | ||
994 | unsigned int lccr0 = fbi->lccr0; | ||
995 | |||
996 | /* | ||
997 | * setup is based on type of panel supported | ||
998 | */ | ||
999 | |||
1000 | /* 4 bit interface */ | ||
1001 | if ((lccr0 & LCCR0_CMS) == LCCR0_Mono && | ||
1002 | (lccr0 & LCCR0_SDS) == LCCR0_Sngl && | ||
1003 | (lccr0 & LCCR0_DPD) == LCCR0_4PixMono) | ||
1004 | ldd_bits = 4; | ||
1005 | |||
1006 | /* 8 bit interface */ | ||
1007 | else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono && | ||
1008 | ((lccr0 & LCCR0_SDS) == LCCR0_Dual || | ||
1009 | (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) || | ||
1010 | ((lccr0 & LCCR0_CMS) == LCCR0_Color && | ||
1011 | (lccr0 & LCCR0_PAS) == LCCR0_Pas && | ||
1012 | (lccr0 & LCCR0_SDS) == LCCR0_Sngl)) | ||
1013 | ldd_bits = 8; | ||
1014 | |||
1015 | /* 16 bit interface */ | ||
1016 | else if ((lccr0 & LCCR0_CMS) == LCCR0_Color && | ||
1017 | ((lccr0 & LCCR0_SDS) == LCCR0_Dual || | ||
1018 | (lccr0 & LCCR0_PAS) == LCCR0_Act)) | ||
1019 | ldd_bits = 16; | ||
1020 | |||
1021 | else { | ||
1022 | printk(KERN_ERR "pxafb_setup_gpio: unable to determine " | ||
1023 | "bits per pixel\n"); | ||
1024 | return; | ||
1025 | } | ||
1026 | |||
1027 | for (gpio = 58; ldd_bits; gpio++, ldd_bits--) | ||
1028 | pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT); | ||
1029 | /* 18 bit interface */ | ||
1030 | if (fbi->fb.var.bits_per_pixel > 16) { | ||
1031 | pxa_gpio_mode(86 | GPIO_ALT_FN_2_OUT); | ||
1032 | pxa_gpio_mode(87 | GPIO_ALT_FN_2_OUT); | ||
1033 | } | ||
1034 | pxa_gpio_mode(GPIO74_LCD_FCLK_MD); | ||
1035 | pxa_gpio_mode(GPIO75_LCD_LCLK_MD); | ||
1036 | pxa_gpio_mode(GPIO76_LCD_PCLK_MD); | ||
1037 | |||
1038 | if ((lccr0 & LCCR0_PAS) == 0) | ||
1039 | pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD); | ||
1040 | } | 1368 | } |
1041 | 1369 | ||
1042 | static void pxafb_enable_controller(struct pxafb_info *fbi) | 1370 | static void pxafb_enable_controller(struct pxafb_info *fbi) |
@@ -1056,6 +1384,7 @@ static void pxafb_enable_controller(struct pxafb_info *fbi) | |||
1056 | return; | 1384 | return; |
1057 | 1385 | ||
1058 | /* Sequence from 11.7.10 */ | 1386 | /* Sequence from 11.7.10 */ |
1387 | lcd_writel(fbi, LCCR4, fbi->reg_lccr4); | ||
1059 | lcd_writel(fbi, LCCR3, fbi->reg_lccr3); | 1388 | lcd_writel(fbi, LCCR3, fbi->reg_lccr3); |
1060 | lcd_writel(fbi, LCCR2, fbi->reg_lccr2); | 1389 | lcd_writel(fbi, LCCR2, fbi->reg_lccr2); |
1061 | lcd_writel(fbi, LCCR1, fbi->reg_lccr1); | 1390 | lcd_writel(fbi, LCCR1, fbi->reg_lccr1); |
@@ -1097,8 +1426,9 @@ static void pxafb_disable_controller(struct pxafb_info *fbi) | |||
1097 | static irqreturn_t pxafb_handle_irq(int irq, void *dev_id) | 1426 | static irqreturn_t pxafb_handle_irq(int irq, void *dev_id) |
1098 | { | 1427 | { |
1099 | struct pxafb_info *fbi = dev_id; | 1428 | struct pxafb_info *fbi = dev_id; |
1100 | unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR); | 1429 | unsigned int lccr0, lcsr, lcsr1; |
1101 | 1430 | ||
1431 | lcsr = lcd_readl(fbi, LCSR); | ||
1102 | if (lcsr & LCSR_LDD) { | 1432 | if (lcsr & LCSR_LDD) { |
1103 | lccr0 = lcd_readl(fbi, LCCR0); | 1433 | lccr0 = lcd_readl(fbi, LCCR0); |
1104 | lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM); | 1434 | lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM); |
@@ -1109,8 +1439,18 @@ static irqreturn_t pxafb_handle_irq(int irq, void *dev_id) | |||
1109 | if (lcsr & LCSR_CMD_INT) | 1439 | if (lcsr & LCSR_CMD_INT) |
1110 | complete(&fbi->command_done); | 1440 | complete(&fbi->command_done); |
1111 | #endif | 1441 | #endif |
1112 | |||
1113 | lcd_writel(fbi, LCSR, lcsr); | 1442 | lcd_writel(fbi, LCSR, lcsr); |
1443 | |||
1444 | #ifdef CONFIG_FB_PXA_OVERLAY | ||
1445 | lcsr1 = lcd_readl(fbi, LCSR1); | ||
1446 | if (lcsr1 & LCSR1_BS(1)) | ||
1447 | complete(&fbi->overlay[0].branch_done); | ||
1448 | |||
1449 | if (lcsr1 & LCSR1_BS(2)) | ||
1450 | complete(&fbi->overlay[1].branch_done); | ||
1451 | |||
1452 | lcd_writel(fbi, LCSR1, lcsr1); | ||
1453 | #endif | ||
1114 | return IRQ_HANDLED; | 1454 | return IRQ_HANDLED; |
1115 | } | 1455 | } |
1116 | 1456 | ||
@@ -1181,7 +1521,6 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state) | |||
1181 | if (old_state == C_ENABLE) { | 1521 | if (old_state == C_ENABLE) { |
1182 | __pxafb_lcd_power(fbi, 0); | 1522 | __pxafb_lcd_power(fbi, 0); |
1183 | pxafb_disable_controller(fbi); | 1523 | pxafb_disable_controller(fbi); |
1184 | pxafb_setup_gpio(fbi); | ||
1185 | pxafb_enable_controller(fbi); | 1524 | pxafb_enable_controller(fbi); |
1186 | __pxafb_lcd_power(fbi, 1); | 1525 | __pxafb_lcd_power(fbi, 1); |
1187 | } | 1526 | } |
@@ -1204,7 +1543,6 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state) | |||
1204 | */ | 1543 | */ |
1205 | if (old_state != C_ENABLE) { | 1544 | if (old_state != C_ENABLE) { |
1206 | fbi->state = C_ENABLE; | 1545 | fbi->state = C_ENABLE; |
1207 | pxafb_setup_gpio(fbi); | ||
1208 | pxafb_enable_controller(fbi); | 1546 | pxafb_enable_controller(fbi); |
1209 | __pxafb_lcd_power(fbi, 1); | 1547 | __pxafb_lcd_power(fbi, 1); |
1210 | __pxafb_backlight_power(fbi, 1); | 1548 | __pxafb_backlight_power(fbi, 1); |
@@ -1303,77 +1641,34 @@ static int pxafb_resume(struct platform_device *dev) | |||
1303 | #define pxafb_resume NULL | 1641 | #define pxafb_resume NULL |
1304 | #endif | 1642 | #endif |
1305 | 1643 | ||
1306 | /* | 1644 | static int __devinit pxafb_init_video_memory(struct pxafb_info *fbi) |
1307 | * pxafb_map_video_memory(): | ||
1308 | * Allocates the DRAM memory for the frame buffer. This buffer is | ||
1309 | * remapped into a non-cached, non-buffered, memory region to | ||
1310 | * allow palette and pixel writes to occur without flushing the | ||
1311 | * cache. Once this area is remapped, all virtual memory | ||
1312 | * access to the video memory should occur at the new region. | ||
1313 | */ | ||
1314 | static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi) | ||
1315 | { | 1645 | { |
1316 | /* | 1646 | int size = PAGE_ALIGN(fbi->video_mem_size); |
1317 | * We reserve one page for the palette, plus the size | ||
1318 | * of the framebuffer. | ||
1319 | */ | ||
1320 | fbi->video_offset = PAGE_ALIGN(sizeof(struct pxafb_dma_buff)); | ||
1321 | fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + fbi->video_offset); | ||
1322 | fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size, | ||
1323 | &fbi->map_dma, GFP_KERNEL); | ||
1324 | |||
1325 | if (fbi->map_cpu) { | ||
1326 | /* prevent initial garbage on screen */ | ||
1327 | memset(fbi->map_cpu, 0, fbi->map_size); | ||
1328 | fbi->fb.screen_base = fbi->map_cpu + fbi->video_offset; | ||
1329 | fbi->screen_dma = fbi->map_dma + fbi->video_offset; | ||
1330 | |||
1331 | /* | ||
1332 | * FIXME: this is actually the wrong thing to place in | ||
1333 | * smem_start. But fbdev suffers from the problem that | ||
1334 | * it needs an API which doesn't exist (in this case, | ||
1335 | * dma_writecombine_mmap) | ||
1336 | */ | ||
1337 | fbi->fb.fix.smem_start = fbi->screen_dma; | ||
1338 | fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16; | ||
1339 | |||
1340 | fbi->dma_buff = (void *) fbi->map_cpu; | ||
1341 | fbi->dma_buff_phys = fbi->map_dma; | ||
1342 | fbi->palette_cpu = (u16 *) fbi->dma_buff->palette; | ||
1343 | 1647 | ||
1344 | pr_debug("pxafb: palette_mem_size = 0x%08x\n", fbi->palette_size*sizeof(u16)); | 1648 | fbi->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); |
1649 | if (fbi->video_mem == NULL) | ||
1650 | return -ENOMEM; | ||
1345 | 1651 | ||
1346 | #ifdef CONFIG_FB_PXA_SMARTPANEL | 1652 | fbi->video_mem_phys = virt_to_phys(fbi->video_mem); |
1347 | fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff; | 1653 | fbi->video_mem_size = size; |
1348 | fbi->n_smart_cmds = 0; | ||
1349 | #endif | ||
1350 | } | ||
1351 | |||
1352 | return fbi->map_cpu ? 0 : -ENOMEM; | ||
1353 | } | ||
1354 | 1654 | ||
1355 | static void pxafb_decode_mode_info(struct pxafb_info *fbi, | 1655 | fbi->fb.fix.smem_start = fbi->video_mem_phys; |
1356 | struct pxafb_mode_info *modes, | 1656 | fbi->fb.fix.smem_len = fbi->video_mem_size; |
1357 | unsigned int num_modes) | 1657 | fbi->fb.screen_base = fbi->video_mem; |
1358 | { | ||
1359 | unsigned int i, smemlen; | ||
1360 | |||
1361 | pxafb_setmode(&fbi->fb.var, &modes[0]); | ||
1362 | 1658 | ||
1363 | for (i = 0; i < num_modes; i++) { | 1659 | return fbi->video_mem ? 0 : -ENOMEM; |
1364 | smemlen = modes[i].xres * modes[i].yres * modes[i].bpp / 8; | ||
1365 | if (smemlen > fbi->fb.fix.smem_len) | ||
1366 | fbi->fb.fix.smem_len = smemlen; | ||
1367 | } | ||
1368 | } | 1660 | } |
1369 | 1661 | ||
1370 | static void pxafb_decode_mach_info(struct pxafb_info *fbi, | 1662 | static void pxafb_decode_mach_info(struct pxafb_info *fbi, |
1371 | struct pxafb_mach_info *inf) | 1663 | struct pxafb_mach_info *inf) |
1372 | { | 1664 | { |
1373 | unsigned int lcd_conn = inf->lcd_conn; | 1665 | unsigned int lcd_conn = inf->lcd_conn; |
1666 | struct pxafb_mode_info *m; | ||
1667 | int i; | ||
1374 | 1668 | ||
1375 | fbi->cmap_inverse = inf->cmap_inverse; | 1669 | fbi->cmap_inverse = inf->cmap_inverse; |
1376 | fbi->cmap_static = inf->cmap_static; | 1670 | fbi->cmap_static = inf->cmap_static; |
1671 | fbi->lccr4 = inf->lccr4; | ||
1377 | 1672 | ||
1378 | switch (lcd_conn & LCD_TYPE_MASK) { | 1673 | switch (lcd_conn & LCD_TYPE_MASK) { |
1379 | case LCD_TYPE_MONO_STN: | 1674 | case LCD_TYPE_MONO_STN: |
@@ -1398,7 +1693,6 @@ static void pxafb_decode_mach_info(struct pxafb_info *fbi, | |||
1398 | /* fall back to backward compatibility way */ | 1693 | /* fall back to backward compatibility way */ |
1399 | fbi->lccr0 = inf->lccr0; | 1694 | fbi->lccr0 = inf->lccr0; |
1400 | fbi->lccr3 = inf->lccr3; | 1695 | fbi->lccr3 = inf->lccr3; |
1401 | fbi->lccr4 = inf->lccr4; | ||
1402 | goto decode_mode; | 1696 | goto decode_mode; |
1403 | } | 1697 | } |
1404 | 1698 | ||
@@ -1412,7 +1706,22 @@ static void pxafb_decode_mach_info(struct pxafb_info *fbi, | |||
1412 | fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0; | 1706 | fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0; |
1413 | 1707 | ||
1414 | decode_mode: | 1708 | decode_mode: |
1415 | pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes); | 1709 | pxafb_setmode(&fbi->fb.var, &inf->modes[0]); |
1710 | |||
1711 | /* decide video memory size as follows: | ||
1712 | * 1. default to mode of maximum resolution | ||
1713 | * 2. allow platform to override | ||
1714 | * 3. allow module parameter to override | ||
1715 | */ | ||
1716 | for (i = 0, m = &inf->modes[0]; i < inf->num_modes; i++, m++) | ||
1717 | fbi->video_mem_size = max_t(size_t, fbi->video_mem_size, | ||
1718 | m->xres * m->yres * m->bpp / 8); | ||
1719 | |||
1720 | if (inf->video_mem_size > fbi->video_mem_size) | ||
1721 | fbi->video_mem_size = inf->video_mem_size; | ||
1722 | |||
1723 | if (video_mem_size > fbi->video_mem_size) | ||
1724 | fbi->video_mem_size = video_mem_size; | ||
1416 | } | 1725 | } |
1417 | 1726 | ||
1418 | static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) | 1727 | static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) |
@@ -1429,7 +1738,7 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) | |||
1429 | memset(fbi, 0, sizeof(struct pxafb_info)); | 1738 | memset(fbi, 0, sizeof(struct pxafb_info)); |
1430 | fbi->dev = dev; | 1739 | fbi->dev = dev; |
1431 | 1740 | ||
1432 | fbi->clk = clk_get(dev, "LCDCLK"); | 1741 | fbi->clk = clk_get(dev, NULL); |
1433 | if (IS_ERR(fbi->clk)) { | 1742 | if (IS_ERR(fbi->clk)) { |
1434 | kfree(fbi); | 1743 | kfree(fbi); |
1435 | return NULL; | 1744 | return NULL; |
@@ -1440,7 +1749,7 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) | |||
1440 | fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS; | 1749 | fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS; |
1441 | fbi->fb.fix.type_aux = 0; | 1750 | fbi->fb.fix.type_aux = 0; |
1442 | fbi->fb.fix.xpanstep = 0; | 1751 | fbi->fb.fix.xpanstep = 0; |
1443 | fbi->fb.fix.ypanstep = 0; | 1752 | fbi->fb.fix.ypanstep = 1; |
1444 | fbi->fb.fix.ywrapstep = 0; | 1753 | fbi->fb.fix.ywrapstep = 0; |
1445 | fbi->fb.fix.accel = FB_ACCEL_NONE; | 1754 | fbi->fb.fix.accel = FB_ACCEL_NONE; |
1446 | 1755 | ||
@@ -1448,7 +1757,7 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) | |||
1448 | fbi->fb.var.activate = FB_ACTIVATE_NOW; | 1757 | fbi->fb.var.activate = FB_ACTIVATE_NOW; |
1449 | fbi->fb.var.height = -1; | 1758 | fbi->fb.var.height = -1; |
1450 | fbi->fb.var.width = -1; | 1759 | fbi->fb.var.width = -1; |
1451 | fbi->fb.var.accel_flags = 0; | 1760 | fbi->fb.var.accel_flags = FB_ACCELF_TEXT; |
1452 | fbi->fb.var.vmode = FB_VMODE_NONINTERLACED; | 1761 | fbi->fb.var.vmode = FB_VMODE_NONINTERLACED; |
1453 | 1762 | ||
1454 | fbi->fb.fbops = &pxafb_ops; | 1763 | fbi->fb.fbops = &pxafb_ops; |
@@ -1468,10 +1777,6 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) | |||
1468 | INIT_WORK(&fbi->task, pxafb_task); | 1777 | INIT_WORK(&fbi->task, pxafb_task); |
1469 | mutex_init(&fbi->ctrlr_lock); | 1778 | mutex_init(&fbi->ctrlr_lock); |
1470 | init_completion(&fbi->disable_done); | 1779 | init_completion(&fbi->disable_done); |
1471 | #ifdef CONFIG_FB_PXA_SMARTPANEL | ||
1472 | init_completion(&fbi->command_done); | ||
1473 | init_completion(&fbi->refresh_done); | ||
1474 | #endif | ||
1475 | 1780 | ||
1476 | return fbi; | 1781 | return fbi; |
1477 | } | 1782 | } |
@@ -1544,7 +1849,9 @@ static int __devinit parse_opt(struct device *dev, char *this_opt) | |||
1544 | 1849 | ||
1545 | s[0] = '\0'; | 1850 | s[0] = '\0'; |
1546 | 1851 | ||
1547 | if (!strncmp(this_opt, "mode:", 5)) { | 1852 | if (!strncmp(this_opt, "vmem:", 5)) { |
1853 | video_mem_size = memparse(this_opt + 5, NULL); | ||
1854 | } else if (!strncmp(this_opt, "mode:", 5)) { | ||
1548 | return parse_opt_mode(dev, this_opt); | 1855 | return parse_opt_mode(dev, this_opt); |
1549 | } else if (!strncmp(this_opt, "pixclock:", 9)) { | 1856 | } else if (!strncmp(this_opt, "pixclock:", 9)) { |
1550 | mode->pixclock = simple_strtoul(this_opt+9, NULL, 0); | 1857 | mode->pixclock = simple_strtoul(this_opt+9, NULL, 0); |
@@ -1748,8 +2055,7 @@ static int __devinit pxafb_probe(struct platform_device *dev) | |||
1748 | ret = -EINVAL; | 2055 | ret = -EINVAL; |
1749 | goto failed; | 2056 | goto failed; |
1750 | } | 2057 | } |
1751 | pxafb_backlight_power = inf->pxafb_backlight_power; | 2058 | |
1752 | pxafb_lcd_power = inf->pxafb_lcd_power; | ||
1753 | fbi = pxafb_init_fbinfo(&dev->dev); | 2059 | fbi = pxafb_init_fbinfo(&dev->dev); |
1754 | if (!fbi) { | 2060 | if (!fbi) { |
1755 | /* only reason for pxafb_init_fbinfo to fail is kmalloc */ | 2061 | /* only reason for pxafb_init_fbinfo to fail is kmalloc */ |
@@ -1758,6 +2064,9 @@ static int __devinit pxafb_probe(struct platform_device *dev) | |||
1758 | goto failed; | 2064 | goto failed; |
1759 | } | 2065 | } |
1760 | 2066 | ||
2067 | fbi->backlight_power = inf->pxafb_backlight_power; | ||
2068 | fbi->lcd_power = inf->pxafb_lcd_power; | ||
2069 | |||
1761 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); | 2070 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); |
1762 | if (r == NULL) { | 2071 | if (r == NULL) { |
1763 | dev_err(&dev->dev, "no I/O memory resource defined\n"); | 2072 | dev_err(&dev->dev, "no I/O memory resource defined\n"); |
@@ -1779,12 +2088,20 @@ static int __devinit pxafb_probe(struct platform_device *dev) | |||
1779 | goto failed_free_res; | 2088 | goto failed_free_res; |
1780 | } | 2089 | } |
1781 | 2090 | ||
1782 | /* Initialize video memory */ | 2091 | fbi->dma_buff_size = PAGE_ALIGN(sizeof(struct pxafb_dma_buff)); |
1783 | ret = pxafb_map_video_memory(fbi); | 2092 | fbi->dma_buff = dma_alloc_coherent(fbi->dev, fbi->dma_buff_size, |
2093 | &fbi->dma_buff_phys, GFP_KERNEL); | ||
2094 | if (fbi->dma_buff == NULL) { | ||
2095 | dev_err(&dev->dev, "failed to allocate memory for DMA\n"); | ||
2096 | ret = -ENOMEM; | ||
2097 | goto failed_free_io; | ||
2098 | } | ||
2099 | |||
2100 | ret = pxafb_init_video_memory(fbi); | ||
1784 | if (ret) { | 2101 | if (ret) { |
1785 | dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret); | 2102 | dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret); |
1786 | ret = -ENOMEM; | 2103 | ret = -ENOMEM; |
1787 | goto failed_free_io; | 2104 | goto failed_free_dma; |
1788 | } | 2105 | } |
1789 | 2106 | ||
1790 | irq = platform_get_irq(dev, 0); | 2107 | irq = platform_get_irq(dev, 0); |
@@ -1801,13 +2118,12 @@ static int __devinit pxafb_probe(struct platform_device *dev) | |||
1801 | goto failed_free_mem; | 2118 | goto failed_free_mem; |
1802 | } | 2119 | } |
1803 | 2120 | ||
1804 | #ifdef CONFIG_FB_PXA_SMARTPANEL | ||
1805 | ret = pxafb_smart_init(fbi); | 2121 | ret = pxafb_smart_init(fbi); |
1806 | if (ret) { | 2122 | if (ret) { |
1807 | dev_err(&dev->dev, "failed to initialize smartpanel\n"); | 2123 | dev_err(&dev->dev, "failed to initialize smartpanel\n"); |
1808 | goto failed_free_irq; | 2124 | goto failed_free_irq; |
1809 | } | 2125 | } |
1810 | #endif | 2126 | |
1811 | /* | 2127 | /* |
1812 | * This makes sure that our colour bitfield | 2128 | * This makes sure that our colour bitfield |
1813 | * descriptors are correctly initialised. | 2129 | * descriptors are correctly initialised. |
@@ -1833,6 +2149,8 @@ static int __devinit pxafb_probe(struct platform_device *dev) | |||
1833 | goto failed_free_cmap; | 2149 | goto failed_free_cmap; |
1834 | } | 2150 | } |
1835 | 2151 | ||
2152 | pxafb_overlay_init(fbi); | ||
2153 | |||
1836 | #ifdef CONFIG_CPU_FREQ | 2154 | #ifdef CONFIG_CPU_FREQ |
1837 | fbi->freq_transition.notifier_call = pxafb_freq_transition; | 2155 | fbi->freq_transition.notifier_call = pxafb_freq_transition; |
1838 | fbi->freq_policy.notifier_call = pxafb_freq_policy; | 2156 | fbi->freq_policy.notifier_call = pxafb_freq_policy; |
@@ -1855,8 +2173,10 @@ failed_free_cmap: | |||
1855 | failed_free_irq: | 2173 | failed_free_irq: |
1856 | free_irq(irq, fbi); | 2174 | free_irq(irq, fbi); |
1857 | failed_free_mem: | 2175 | failed_free_mem: |
1858 | dma_free_writecombine(&dev->dev, fbi->map_size, | 2176 | free_pages_exact(fbi->video_mem, fbi->video_mem_size); |
1859 | fbi->map_cpu, fbi->map_dma); | 2177 | failed_free_dma: |
2178 | dma_free_coherent(&dev->dev, fbi->dma_buff_size, | ||
2179 | fbi->dma_buff, fbi->dma_buff_phys); | ||
1860 | failed_free_io: | 2180 | failed_free_io: |
1861 | iounmap(fbi->mmio_base); | 2181 | iounmap(fbi->mmio_base); |
1862 | failed_free_res: | 2182 | failed_free_res: |
@@ -1881,6 +2201,7 @@ static int __devexit pxafb_remove(struct platform_device *dev) | |||
1881 | 2201 | ||
1882 | info = &fbi->fb; | 2202 | info = &fbi->fb; |
1883 | 2203 | ||
2204 | pxafb_overlay_exit(fbi); | ||
1884 | unregister_framebuffer(info); | 2205 | unregister_framebuffer(info); |
1885 | 2206 | ||
1886 | pxafb_disable_controller(fbi); | 2207 | pxafb_disable_controller(fbi); |
@@ -1891,8 +2212,10 @@ static int __devexit pxafb_remove(struct platform_device *dev) | |||
1891 | irq = platform_get_irq(dev, 0); | 2212 | irq = platform_get_irq(dev, 0); |
1892 | free_irq(irq, fbi); | 2213 | free_irq(irq, fbi); |
1893 | 2214 | ||
1894 | dma_free_writecombine(&dev->dev, fbi->map_size, | 2215 | free_pages_exact(fbi->video_mem, fbi->video_mem_size); |
1895 | fbi->map_cpu, fbi->map_dma); | 2216 | |
2217 | dma_free_writecombine(&dev->dev, fbi->dma_buff_size, | ||
2218 | fbi->dma_buff, fbi->dma_buff_phys); | ||
1896 | 2219 | ||
1897 | iounmap(fbi->mmio_base); | 2220 | iounmap(fbi->mmio_base); |
1898 | 2221 | ||