1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Framebuffer driver for TI OMAP boards
5 * Copyright (C) 2004 Nokia Corporation
6 * Author: Imre Deak <imre.deak@nokia.com>
9 * Alex McMains <aam@ridgerun.com> - Original driver
10 * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
11 * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
12 * Texas Instruments - H3 support
14 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <linux/uaccess.h>
18 #include <linux/module.h>
20 #include <linux/omap-dma.h>
22 #include <mach/hardware.h>
27 #define MODULE_NAME "omapfb"
29 static unsigned int def_accel
;
30 static unsigned long def_vram
[OMAPFB_PLANE_NUM
];
31 static unsigned int def_vram_cnt
;
32 static unsigned long def_vxres
;
33 static unsigned long def_vyres
;
34 static unsigned int def_rotate
;
35 static unsigned int def_mirror
;
37 static bool manual_update
= IS_BUILTIN(CONFIG_FB_OMAP_MANUAL_UPDATE
);
39 static struct platform_device
*fbdev_pdev
;
40 static struct lcd_panel
*fbdev_panel
;
41 static struct omapfb_device
*omapfb_dev
;
43 struct caps_table_struct
{
48 static const struct caps_table_struct ctrl_caps
[] = {
49 { OMAPFB_CAPS_MANUAL_UPDATE
, "manual update" },
50 { OMAPFB_CAPS_TEARSYNC
, "tearing synchronization" },
51 { OMAPFB_CAPS_PLANE_RELOCATE_MEM
, "relocate plane memory" },
52 { OMAPFB_CAPS_PLANE_SCALE
, "scale plane" },
53 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE
, "pixel double window" },
54 { OMAPFB_CAPS_WINDOW_SCALE
, "scale window" },
55 { OMAPFB_CAPS_WINDOW_OVERLAY
, "overlay window" },
56 { OMAPFB_CAPS_WINDOW_ROTATE
, "rotate window" },
57 { OMAPFB_CAPS_SET_BACKLIGHT
, "backlight setting" },
60 static const struct caps_table_struct color_caps
[] = {
61 { 1 << OMAPFB_COLOR_RGB565
, "RGB565", },
62 { 1 << OMAPFB_COLOR_YUV422
, "YUV422", },
63 { 1 << OMAPFB_COLOR_YUV420
, "YUV420", },
64 { 1 << OMAPFB_COLOR_CLUT_8BPP
, "CLUT8", },
65 { 1 << OMAPFB_COLOR_CLUT_4BPP
, "CLUT4", },
66 { 1 << OMAPFB_COLOR_CLUT_2BPP
, "CLUT2", },
67 { 1 << OMAPFB_COLOR_CLUT_1BPP
, "CLUT1", },
68 { 1 << OMAPFB_COLOR_RGB444
, "RGB444", },
69 { 1 << OMAPFB_COLOR_YUY422
, "YUY422", },
72 static void omapdss_release(struct device
*dev
)
76 /* dummy device for clocks */
77 static struct platform_device omapdss_device
= {
78 .name
= "omapdss_dss",
81 .release
= omapdss_release
,
86 * ---------------------------------------------------------------------------
88 * ---------------------------------------------------------------------------
90 extern struct lcd_ctrl hwa742_ctrl
;
92 static const struct lcd_ctrl
*ctrls
[] = {
95 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
100 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
101 extern struct lcd_ctrl_extif omap1_ext_if
;
104 static void omapfb_rqueue_lock(struct omapfb_device
*fbdev
)
106 mutex_lock(&fbdev
->rqueue_mutex
);
109 static void omapfb_rqueue_unlock(struct omapfb_device
*fbdev
)
111 mutex_unlock(&fbdev
->rqueue_mutex
);
115 * ---------------------------------------------------------------------------
116 * LCD controller and LCD DMA
117 * ---------------------------------------------------------------------------
120 * Allocate resources needed for LCD controller and LCD DMA operations. Video
121 * memory is allocated from system memory according to the virtual display
122 * size, except if a bigger memory size is specified explicitly as a kernel
125 static int ctrl_init(struct omapfb_device
*fbdev
)
130 /* kernel/module vram parameters override boot tags/board config */
132 for (i
= 0; i
< def_vram_cnt
; i
++)
133 fbdev
->mem_desc
.region
[i
].size
=
134 PAGE_ALIGN(def_vram
[i
]);
135 fbdev
->mem_desc
.region_cnt
= i
;
138 if (!fbdev
->mem_desc
.region_cnt
) {
139 struct lcd_panel
*panel
= fbdev
->panel
;
141 int bpp
= panel
->bpp
;
143 /* 12 bpp is packed in 16 bits */
146 def_size
= def_vxres
* def_vyres
* bpp
/ 8;
147 fbdev
->mem_desc
.region_cnt
= 1;
148 fbdev
->mem_desc
.region
[0].size
= PAGE_ALIGN(def_size
);
150 r
= fbdev
->ctrl
->init(fbdev
, 0, &fbdev
->mem_desc
);
152 dev_err(fbdev
->dev
, "controller initialization failed (%d)\n",
158 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
159 dev_dbg(fbdev
->dev
, "region%d phys %08x virt %p size=%lu\n",
161 fbdev
->mem_desc
.region
[i
].paddr
,
162 fbdev
->mem_desc
.region
[i
].vaddr
,
163 fbdev
->mem_desc
.region
[i
].size
);
169 static void ctrl_cleanup(struct omapfb_device
*fbdev
)
171 fbdev
->ctrl
->cleanup();
174 /* Must be called with fbdev->rqueue_mutex held. */
175 static int ctrl_change_mode(struct fb_info
*fbi
)
178 unsigned long offset
;
179 struct omapfb_plane_struct
*plane
= fbi
->par
;
180 struct omapfb_device
*fbdev
= plane
->fbdev
;
181 struct fb_var_screeninfo
*var
= &fbi
->var
;
183 offset
= var
->yoffset
* fbi
->fix
.line_length
+
184 var
->xoffset
* var
->bits_per_pixel
/ 8;
186 if (fbdev
->ctrl
->sync
)
188 r
= fbdev
->ctrl
->setup_plane(plane
->idx
, plane
->info
.channel_out
,
189 offset
, var
->xres_virtual
,
190 plane
->info
.pos_x
, plane
->info
.pos_y
,
191 var
->xres
, var
->yres
, plane
->color_mode
);
195 if (fbdev
->ctrl
->set_rotate
!= NULL
) {
196 r
= fbdev
->ctrl
->set_rotate(var
->rotate
);
201 if (fbdev
->ctrl
->set_scale
!= NULL
)
202 r
= fbdev
->ctrl
->set_scale(plane
->idx
,
203 var
->xres
, var
->yres
,
204 plane
->info
.out_width
,
205 plane
->info
.out_height
);
211 * ---------------------------------------------------------------------------
212 * fbdev framework callbacks and the ioctl interface
213 * ---------------------------------------------------------------------------
215 /* Called each time the omapfb device is opened */
216 static int omapfb_open(struct fb_info
*info
, int user
)
221 static void omapfb_sync(struct fb_info
*info
);
223 /* Called when the omapfb device is closed. We make sure that any pending
224 * gfx DMA operations are ended, before we return. */
225 static int omapfb_release(struct fb_info
*info
, int user
)
231 /* Store a single color palette entry into a pseudo palette or the hardware
232 * palette if one is available. For now we support only 16bpp and thus store
233 * the entry only to the pseudo palette.
235 static int _setcolreg(struct fb_info
*info
, u_int regno
, u_int red
, u_int green
,
236 u_int blue
, u_int transp
, int update_hw_pal
)
238 struct omapfb_plane_struct
*plane
= info
->par
;
239 struct omapfb_device
*fbdev
= plane
->fbdev
;
240 struct fb_var_screeninfo
*var
= &info
->var
;
243 switch (plane
->color_mode
) {
244 case OMAPFB_COLOR_YUV422
:
245 case OMAPFB_COLOR_YUV420
:
246 case OMAPFB_COLOR_YUY422
:
249 case OMAPFB_COLOR_CLUT_8BPP
:
250 case OMAPFB_COLOR_CLUT_4BPP
:
251 case OMAPFB_COLOR_CLUT_2BPP
:
252 case OMAPFB_COLOR_CLUT_1BPP
:
253 if (fbdev
->ctrl
->setcolreg
)
254 r
= fbdev
->ctrl
->setcolreg(regno
, red
, green
, blue
,
255 transp
, update_hw_pal
);
257 case OMAPFB_COLOR_RGB565
:
258 case OMAPFB_COLOR_RGB444
:
264 pal
= ((red
>> (16 - var
->red
.length
)) <<
266 ((green
>> (16 - var
->green
.length
)) <<
268 (blue
>> (16 - var
->blue
.length
));
269 ((u32
*)(info
->pseudo_palette
))[regno
] = pal
;
278 static int omapfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
279 u_int transp
, struct fb_info
*info
)
281 return _setcolreg(info
, regno
, red
, green
, blue
, transp
, 1);
284 static int omapfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
287 u16
*red
, *green
, *blue
, *transp
;
293 transp
= cmap
->transp
;
296 for (count
= 0; count
< cmap
->len
; count
++) {
299 r
= _setcolreg(info
, index
++, *red
++, *green
++, *blue
++, trans
,
300 count
== cmap
->len
- 1);
308 static int omapfb_update_full_screen(struct fb_info
*fbi
);
310 static int omapfb_blank(int blank
, struct fb_info
*fbi
)
312 struct omapfb_plane_struct
*plane
= fbi
->par
;
313 struct omapfb_device
*fbdev
= plane
->fbdev
;
317 omapfb_rqueue_lock(fbdev
);
319 case FB_BLANK_UNBLANK
:
320 if (fbdev
->state
== OMAPFB_SUSPENDED
) {
321 if (fbdev
->ctrl
->resume
)
322 fbdev
->ctrl
->resume();
323 if (fbdev
->panel
->enable
)
324 fbdev
->panel
->enable(fbdev
->panel
);
325 fbdev
->state
= OMAPFB_ACTIVE
;
326 if (fbdev
->ctrl
->get_update_mode() ==
327 OMAPFB_MANUAL_UPDATE
)
331 case FB_BLANK_POWERDOWN
:
332 if (fbdev
->state
== OMAPFB_ACTIVE
) {
333 if (fbdev
->panel
->disable
)
334 fbdev
->panel
->disable(fbdev
->panel
);
335 if (fbdev
->ctrl
->suspend
)
336 fbdev
->ctrl
->suspend();
337 fbdev
->state
= OMAPFB_SUSPENDED
;
343 omapfb_rqueue_unlock(fbdev
);
345 if (r
== 0 && do_update
)
346 r
= omapfb_update_full_screen(fbi
);
351 static void omapfb_sync(struct fb_info
*fbi
)
353 struct omapfb_plane_struct
*plane
= fbi
->par
;
354 struct omapfb_device
*fbdev
= plane
->fbdev
;
356 omapfb_rqueue_lock(fbdev
);
357 if (fbdev
->ctrl
->sync
)
359 omapfb_rqueue_unlock(fbdev
);
363 * Set fb_info.fix fields and also updates fbdev.
364 * When calling this fb_info.var must be set up already.
366 static void set_fb_fix(struct fb_info
*fbi
, int from_init
)
368 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
369 struct fb_var_screeninfo
*var
= &fbi
->var
;
370 struct omapfb_plane_struct
*plane
= fbi
->par
;
371 struct omapfb_mem_region
*rg
;
374 rg
= &plane
->fbdev
->mem_desc
.region
[plane
->idx
];
375 fbi
->screen_base
= rg
->vaddr
;
378 mutex_lock(&fbi
->mm_lock
);
379 fix
->smem_start
= rg
->paddr
;
380 fix
->smem_len
= rg
->size
;
381 mutex_unlock(&fbi
->mm_lock
);
383 fix
->smem_start
= rg
->paddr
;
384 fix
->smem_len
= rg
->size
;
387 fix
->type
= FB_TYPE_PACKED_PIXELS
;
388 bpp
= var
->bits_per_pixel
;
390 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
391 else switch (var
->bits_per_pixel
) {
394 fix
->visual
= FB_VISUAL_TRUECOLOR
;
395 /* 12bpp is stored in 16 bits */
402 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
405 fix
->accel
= FB_ACCEL_OMAP1610
;
406 fix
->line_length
= var
->xres_virtual
* bpp
/ 8;
409 static int set_color_mode(struct omapfb_plane_struct
*plane
,
410 struct fb_var_screeninfo
*var
)
412 switch (var
->nonstd
) {
415 case OMAPFB_COLOR_YUV422
:
416 var
->bits_per_pixel
= 16;
417 plane
->color_mode
= var
->nonstd
;
419 case OMAPFB_COLOR_YUV420
:
420 var
->bits_per_pixel
= 12;
421 plane
->color_mode
= var
->nonstd
;
423 case OMAPFB_COLOR_YUY422
:
424 var
->bits_per_pixel
= 16;
425 plane
->color_mode
= var
->nonstd
;
431 switch (var
->bits_per_pixel
) {
433 plane
->color_mode
= OMAPFB_COLOR_CLUT_1BPP
;
436 plane
->color_mode
= OMAPFB_COLOR_CLUT_2BPP
;
439 plane
->color_mode
= OMAPFB_COLOR_CLUT_4BPP
;
442 plane
->color_mode
= OMAPFB_COLOR_CLUT_8BPP
;
445 var
->bits_per_pixel
= 16;
448 if (plane
->fbdev
->panel
->bpp
== 12)
449 plane
->color_mode
= OMAPFB_COLOR_RGB444
;
451 plane
->color_mode
= OMAPFB_COLOR_RGB565
;
459 * Check the values in var against our capabilities and in case of out of
460 * bound values try to adjust them.
462 static int set_fb_var(struct fb_info
*fbi
,
463 struct fb_var_screeninfo
*var
)
466 unsigned long max_frame_size
;
467 unsigned long line_size
;
468 int xres_min
, xres_max
;
469 int yres_min
, yres_max
;
470 struct omapfb_plane_struct
*plane
= fbi
->par
;
471 struct omapfb_device
*fbdev
= plane
->fbdev
;
472 struct lcd_panel
*panel
= fbdev
->panel
;
474 if (set_color_mode(plane
, var
) < 0)
477 bpp
= var
->bits_per_pixel
;
478 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
)
481 switch (var
->rotate
) {
484 xres_min
= OMAPFB_PLANE_XRES_MIN
;
485 xres_max
= panel
->x_res
;
486 yres_min
= OMAPFB_PLANE_YRES_MIN
;
487 yres_max
= panel
->y_res
;
488 if (cpu_is_omap15xx()) {
489 var
->xres
= panel
->x_res
;
490 var
->yres
= panel
->y_res
;
495 xres_min
= OMAPFB_PLANE_YRES_MIN
;
496 xres_max
= panel
->y_res
;
497 yres_min
= OMAPFB_PLANE_XRES_MIN
;
498 yres_max
= panel
->x_res
;
499 if (cpu_is_omap15xx()) {
500 var
->xres
= panel
->y_res
;
501 var
->yres
= panel
->x_res
;
508 if (var
->xres
< xres_min
)
509 var
->xres
= xres_min
;
510 if (var
->yres
< yres_min
)
511 var
->yres
= yres_min
;
512 if (var
->xres
> xres_max
)
513 var
->xres
= xres_max
;
514 if (var
->yres
> yres_max
)
515 var
->yres
= yres_max
;
517 if (var
->xres_virtual
< var
->xres
)
518 var
->xres_virtual
= var
->xres
;
519 if (var
->yres_virtual
< var
->yres
)
520 var
->yres_virtual
= var
->yres
;
521 max_frame_size
= fbdev
->mem_desc
.region
[plane
->idx
].size
;
522 line_size
= var
->xres_virtual
* bpp
/ 8;
523 if (line_size
* var
->yres_virtual
> max_frame_size
) {
524 /* Try to keep yres_virtual first */
525 line_size
= max_frame_size
/ var
->yres_virtual
;
526 var
->xres_virtual
= line_size
* 8 / bpp
;
527 if (var
->xres_virtual
< var
->xres
) {
528 /* Still doesn't fit. Shrink yres_virtual too */
529 var
->xres_virtual
= var
->xres
;
530 line_size
= var
->xres
* bpp
/ 8;
531 var
->yres_virtual
= max_frame_size
/ line_size
;
533 /* Recheck this, as the virtual size changed. */
534 if (var
->xres_virtual
< var
->xres
)
535 var
->xres
= var
->xres_virtual
;
536 if (var
->yres_virtual
< var
->yres
)
537 var
->yres
= var
->yres_virtual
;
538 if (var
->xres
< xres_min
|| var
->yres
< yres_min
)
541 if (var
->xres
+ var
->xoffset
> var
->xres_virtual
)
542 var
->xoffset
= var
->xres_virtual
- var
->xres
;
543 if (var
->yres
+ var
->yoffset
> var
->yres_virtual
)
544 var
->yoffset
= var
->yres_virtual
- var
->yres
;
546 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
) {
547 var
->red
.offset
= 8; var
->red
.length
= 4;
548 var
->red
.msb_right
= 0;
549 var
->green
.offset
= 4; var
->green
.length
= 4;
550 var
->green
.msb_right
= 0;
551 var
->blue
.offset
= 0; var
->blue
.length
= 4;
552 var
->blue
.msb_right
= 0;
554 var
->red
.offset
= 11; var
->red
.length
= 5;
555 var
->red
.msb_right
= 0;
556 var
->green
.offset
= 5; var
->green
.length
= 6;
557 var
->green
.msb_right
= 0;
558 var
->blue
.offset
= 0; var
->blue
.length
= 5;
559 var
->blue
.msb_right
= 0;
566 /* pixclock in ps, the rest in pixclock */
567 var
->pixclock
= 10000000 / (panel
->pixel_clock
/ 100);
568 var
->left_margin
= panel
->hfp
;
569 var
->right_margin
= panel
->hbp
;
570 var
->upper_margin
= panel
->vfp
;
571 var
->lower_margin
= panel
->vbp
;
572 var
->hsync_len
= panel
->hsw
;
573 var
->vsync_len
= panel
->vsw
;
575 /* TODO: get these from panel->config */
576 var
->vmode
= FB_VMODE_NONINTERLACED
;
584 * Set new x,y offsets in the virtual display for the visible area and switch
587 static int omapfb_pan_display(struct fb_var_screeninfo
*var
,
590 struct omapfb_plane_struct
*plane
= fbi
->par
;
591 struct omapfb_device
*fbdev
= plane
->fbdev
;
594 omapfb_rqueue_lock(fbdev
);
595 if (var
->xoffset
!= fbi
->var
.xoffset
||
596 var
->yoffset
!= fbi
->var
.yoffset
) {
597 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
599 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
600 new_var
->xoffset
= var
->xoffset
;
601 new_var
->yoffset
= var
->yoffset
;
602 if (set_fb_var(fbi
, new_var
))
605 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
606 ctrl_change_mode(fbi
);
609 omapfb_rqueue_unlock(fbdev
);
614 /* Set mirror to vertical axis and switch to the new mode. */
615 static int omapfb_mirror(struct fb_info
*fbi
, int mirror
)
617 struct omapfb_plane_struct
*plane
= fbi
->par
;
618 struct omapfb_device
*fbdev
= plane
->fbdev
;
621 omapfb_rqueue_lock(fbdev
);
622 mirror
= mirror
? 1 : 0;
623 if (cpu_is_omap15xx())
625 else if (mirror
!= plane
->info
.mirror
) {
626 plane
->info
.mirror
= mirror
;
627 r
= ctrl_change_mode(fbi
);
629 omapfb_rqueue_unlock(fbdev
);
635 * Check values in var, try to adjust them in case of out of bound values if
636 * possible, or return error.
638 static int omapfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*fbi
)
640 struct omapfb_plane_struct
*plane
= fbi
->par
;
641 struct omapfb_device
*fbdev
= plane
->fbdev
;
644 omapfb_rqueue_lock(fbdev
);
645 if (fbdev
->ctrl
->sync
!= NULL
)
647 r
= set_fb_var(fbi
, var
);
648 omapfb_rqueue_unlock(fbdev
);
654 * Switch to a new mode. The parameters for it has been check already by
657 static int omapfb_set_par(struct fb_info
*fbi
)
659 struct omapfb_plane_struct
*plane
= fbi
->par
;
660 struct omapfb_device
*fbdev
= plane
->fbdev
;
663 omapfb_rqueue_lock(fbdev
);
665 r
= ctrl_change_mode(fbi
);
666 omapfb_rqueue_unlock(fbdev
);
671 int omapfb_update_window_async(struct fb_info
*fbi
,
672 struct omapfb_update_window
*win
,
673 void (*callback
)(void *),
677 struct omapfb_plane_struct
*plane
= fbi
->par
;
678 struct omapfb_device
*fbdev
= plane
->fbdev
;
679 struct fb_var_screeninfo
*var
= &fbi
->var
;
681 switch (var
->rotate
) {
684 xres
= fbdev
->panel
->x_res
;
685 yres
= fbdev
->panel
->y_res
;
689 xres
= fbdev
->panel
->y_res
;
690 yres
= fbdev
->panel
->x_res
;
696 if (win
->x
>= xres
|| win
->y
>= yres
||
697 win
->out_x
> xres
|| win
->out_y
> yres
)
700 if (!fbdev
->ctrl
->update_window
||
701 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
704 if (win
->x
+ win
->width
> xres
)
705 win
->width
= xres
- win
->x
;
706 if (win
->y
+ win
->height
> yres
)
707 win
->height
= yres
- win
->y
;
708 if (win
->out_x
+ win
->out_width
> xres
)
709 win
->out_width
= xres
- win
->out_x
;
710 if (win
->out_y
+ win
->out_height
> yres
)
711 win
->out_height
= yres
- win
->out_y
;
712 if (!win
->width
|| !win
->height
|| !win
->out_width
|| !win
->out_height
)
715 return fbdev
->ctrl
->update_window(fbi
, win
, callback
, callback_data
);
717 EXPORT_SYMBOL(omapfb_update_window_async
);
719 static int omapfb_update_win(struct fb_info
*fbi
,
720 struct omapfb_update_window
*win
)
722 struct omapfb_plane_struct
*plane
= fbi
->par
;
725 omapfb_rqueue_lock(plane
->fbdev
);
726 ret
= omapfb_update_window_async(fbi
, win
, NULL
, NULL
);
727 omapfb_rqueue_unlock(plane
->fbdev
);
732 static int omapfb_update_full_screen(struct fb_info
*fbi
)
734 struct omapfb_plane_struct
*plane
= fbi
->par
;
735 struct omapfb_device
*fbdev
= plane
->fbdev
;
736 struct omapfb_update_window win
;
739 if (!fbdev
->ctrl
->update_window
||
740 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
745 win
.width
= fbi
->var
.xres
;
746 win
.height
= fbi
->var
.yres
;
749 win
.out_width
= fbi
->var
.xres
;
750 win
.out_height
= fbi
->var
.yres
;
753 omapfb_rqueue_lock(fbdev
);
754 r
= fbdev
->ctrl
->update_window(fbi
, &win
, NULL
, NULL
);
755 omapfb_rqueue_unlock(fbdev
);
760 static int omapfb_setup_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
762 struct omapfb_plane_struct
*plane
= fbi
->par
;
763 struct omapfb_device
*fbdev
= plane
->fbdev
;
764 struct lcd_panel
*panel
= fbdev
->panel
;
765 struct omapfb_plane_info old_info
;
768 if (pi
->pos_x
+ pi
->out_width
> panel
->x_res
||
769 pi
->pos_y
+ pi
->out_height
> panel
->y_res
)
772 omapfb_rqueue_lock(fbdev
);
773 if (pi
->enabled
&& !fbdev
->mem_desc
.region
[plane
->idx
].size
) {
775 * This plane's memory was freed, can't enable it
776 * until it's reallocated.
781 old_info
= plane
->info
;
784 r
= ctrl_change_mode(fbi
);
786 plane
->info
= old_info
;
790 r
= fbdev
->ctrl
->enable_plane(plane
->idx
, pi
->enabled
);
792 plane
->info
= old_info
;
796 omapfb_rqueue_unlock(fbdev
);
800 static int omapfb_query_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
802 struct omapfb_plane_struct
*plane
= fbi
->par
;
808 static int omapfb_setup_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
810 struct omapfb_plane_struct
*plane
= fbi
->par
;
811 struct omapfb_device
*fbdev
= plane
->fbdev
;
812 struct omapfb_mem_region
*rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
816 if (fbdev
->ctrl
->setup_mem
== NULL
)
818 if (mi
->type
!= OMAPFB_MEMTYPE_SDRAM
)
821 size
= PAGE_ALIGN(mi
->size
);
822 omapfb_rqueue_lock(fbdev
);
823 if (plane
->info
.enabled
) {
827 if (rg
->size
!= size
|| rg
->type
!= mi
->type
) {
828 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
829 unsigned long old_size
= rg
->size
;
830 u8 old_type
= rg
->type
;
836 * size == 0 is a special case, for which we
837 * don't check / adjust the screen parameters.
838 * This isn't a problem since the plane can't
839 * be reenabled unless its size is > 0.
841 if (old_size
!= size
&& size
) {
843 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
844 r
= set_fb_var(fbi
, new_var
);
850 if (fbdev
->ctrl
->sync
)
852 r
= fbdev
->ctrl
->setup_mem(plane
->idx
, size
, mi
->type
, &paddr
);
854 /* Revert changes. */
861 if (old_size
!= size
) {
863 memcpy(&fbi
->var
, new_var
, sizeof(fbi
->var
));
867 * Set these explicitly to indicate that the
868 * plane memory is dealloce'd, the other
869 * screen parameters in var / fix are invalid.
871 mutex_lock(&fbi
->mm_lock
);
872 fbi
->fix
.smem_start
= 0;
873 fbi
->fix
.smem_len
= 0;
874 mutex_unlock(&fbi
->mm_lock
);
879 omapfb_rqueue_unlock(fbdev
);
884 static int omapfb_query_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
886 struct omapfb_plane_struct
*plane
= fbi
->par
;
887 struct omapfb_device
*fbdev
= plane
->fbdev
;
888 struct omapfb_mem_region
*rg
;
890 rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
891 memset(mi
, 0, sizeof(*mi
));
898 static int omapfb_set_color_key(struct omapfb_device
*fbdev
,
899 struct omapfb_color_key
*ck
)
903 if (!fbdev
->ctrl
->set_color_key
)
906 omapfb_rqueue_lock(fbdev
);
907 r
= fbdev
->ctrl
->set_color_key(ck
);
908 omapfb_rqueue_unlock(fbdev
);
913 static int omapfb_get_color_key(struct omapfb_device
*fbdev
,
914 struct omapfb_color_key
*ck
)
918 if (!fbdev
->ctrl
->get_color_key
)
921 omapfb_rqueue_lock(fbdev
);
922 r
= fbdev
->ctrl
->get_color_key(ck
);
923 omapfb_rqueue_unlock(fbdev
);
928 static struct blocking_notifier_head omapfb_client_list
[OMAPFB_PLANE_NUM
];
929 static int notifier_inited
;
931 static void omapfb_init_notifier(void)
935 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
936 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list
[i
]);
939 int omapfb_register_client(struct omapfb_notifier_block
*omapfb_nb
,
940 omapfb_notifier_callback_t callback
,
945 if ((unsigned)omapfb_nb
->plane_idx
>= OMAPFB_PLANE_NUM
)
948 if (!notifier_inited
) {
949 omapfb_init_notifier();
953 omapfb_nb
->nb
.notifier_call
= (int (*)(struct notifier_block
*,
954 unsigned long, void *))callback
;
955 omapfb_nb
->data
= callback_data
;
956 r
= blocking_notifier_chain_register(
957 &omapfb_client_list
[omapfb_nb
->plane_idx
],
961 if (omapfb_dev
!= NULL
&&
962 omapfb_dev
->ctrl
&& omapfb_dev
->ctrl
->bind_client
) {
963 omapfb_dev
->ctrl
->bind_client(omapfb_nb
);
968 EXPORT_SYMBOL(omapfb_register_client
);
970 int omapfb_unregister_client(struct omapfb_notifier_block
*omapfb_nb
)
972 return blocking_notifier_chain_unregister(
973 &omapfb_client_list
[omapfb_nb
->plane_idx
], &omapfb_nb
->nb
);
975 EXPORT_SYMBOL(omapfb_unregister_client
);
977 void omapfb_notify_clients(struct omapfb_device
*fbdev
, unsigned long event
)
981 if (!notifier_inited
)
982 /* no client registered yet */
985 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
986 blocking_notifier_call_chain(&omapfb_client_list
[i
], event
,
989 EXPORT_SYMBOL(omapfb_notify_clients
);
991 static int omapfb_set_update_mode(struct omapfb_device
*fbdev
,
992 enum omapfb_update_mode mode
)
996 omapfb_rqueue_lock(fbdev
);
997 r
= fbdev
->ctrl
->set_update_mode(mode
);
998 omapfb_rqueue_unlock(fbdev
);
1003 static enum omapfb_update_mode
omapfb_get_update_mode(struct omapfb_device
*fbdev
)
1007 omapfb_rqueue_lock(fbdev
);
1008 r
= fbdev
->ctrl
->get_update_mode();
1009 omapfb_rqueue_unlock(fbdev
);
1014 static void omapfb_get_caps(struct omapfb_device
*fbdev
, int plane
,
1015 struct omapfb_caps
*caps
)
1017 memset(caps
, 0, sizeof(*caps
));
1018 fbdev
->ctrl
->get_caps(plane
, caps
);
1019 if (fbdev
->panel
->get_caps
)
1020 caps
->ctrl
|= fbdev
->panel
->get_caps(fbdev
->panel
);
1023 /* For lcd testing */
1024 void omapfb_write_first_pixel(struct omapfb_device
*fbdev
, u16 pixval
)
1026 omapfb_rqueue_lock(fbdev
);
1027 *(u16
*)fbdev
->mem_desc
.region
[0].vaddr
= pixval
;
1028 if (fbdev
->ctrl
->get_update_mode() == OMAPFB_MANUAL_UPDATE
) {
1029 struct omapfb_update_window win
;
1031 memset(&win
, 0, sizeof(win
));
1036 fbdev
->ctrl
->update_window(fbdev
->fb_info
[0], &win
, NULL
, NULL
);
1038 omapfb_rqueue_unlock(fbdev
);
1040 EXPORT_SYMBOL(omapfb_write_first_pixel
);
1043 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1044 * here to be accessible by user mode code.
1046 static int omapfb_ioctl(struct fb_info
*fbi
, unsigned int cmd
,
1049 struct omapfb_plane_struct
*plane
= fbi
->par
;
1050 struct omapfb_device
*fbdev
= plane
->fbdev
;
1051 const struct fb_ops
*ops
= fbi
->fbops
;
1053 struct omapfb_update_window update_window
;
1054 struct omapfb_plane_info plane_info
;
1055 struct omapfb_mem_info mem_info
;
1056 struct omapfb_color_key color_key
;
1057 enum omapfb_update_mode update_mode
;
1058 struct omapfb_caps caps
;
1059 unsigned int mirror
;
1068 if (get_user(p
.mirror
, (int __user
*)arg
))
1071 omapfb_mirror(fbi
, p
.mirror
);
1073 case OMAPFB_SYNC_GFX
:
1078 case OMAPFB_SET_UPDATE_MODE
:
1079 if (get_user(p
.update_mode
, (int __user
*)arg
))
1082 r
= omapfb_set_update_mode(fbdev
, p
.update_mode
);
1084 case OMAPFB_GET_UPDATE_MODE
:
1085 p
.update_mode
= omapfb_get_update_mode(fbdev
);
1086 if (put_user(p
.update_mode
,
1087 (enum omapfb_update_mode __user
*)arg
))
1090 case OMAPFB_UPDATE_WINDOW_OLD
:
1091 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1092 sizeof(struct omapfb_update_window_old
)))
1095 struct omapfb_update_window
*u
= &p
.update_window
;
1098 u
->out_width
= u
->width
;
1099 u
->out_height
= u
->height
;
1100 memset(u
->reserved
, 0, sizeof(u
->reserved
));
1101 r
= omapfb_update_win(fbi
, u
);
1104 case OMAPFB_UPDATE_WINDOW
:
1105 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1106 sizeof(p
.update_window
)))
1109 r
= omapfb_update_win(fbi
, &p
.update_window
);
1111 case OMAPFB_SETUP_PLANE
:
1112 if (copy_from_user(&p
.plane_info
, (void __user
*)arg
,
1113 sizeof(p
.plane_info
)))
1116 r
= omapfb_setup_plane(fbi
, &p
.plane_info
);
1118 case OMAPFB_QUERY_PLANE
:
1119 if ((r
= omapfb_query_plane(fbi
, &p
.plane_info
)) < 0)
1121 if (copy_to_user((void __user
*)arg
, &p
.plane_info
,
1122 sizeof(p
.plane_info
)))
1125 case OMAPFB_SETUP_MEM
:
1126 if (copy_from_user(&p
.mem_info
, (void __user
*)arg
,
1127 sizeof(p
.mem_info
)))
1130 r
= omapfb_setup_mem(fbi
, &p
.mem_info
);
1132 case OMAPFB_QUERY_MEM
:
1133 if ((r
= omapfb_query_mem(fbi
, &p
.mem_info
)) < 0)
1135 if (copy_to_user((void __user
*)arg
, &p
.mem_info
,
1136 sizeof(p
.mem_info
)))
1139 case OMAPFB_SET_COLOR_KEY
:
1140 if (copy_from_user(&p
.color_key
, (void __user
*)arg
,
1141 sizeof(p
.color_key
)))
1144 r
= omapfb_set_color_key(fbdev
, &p
.color_key
);
1146 case OMAPFB_GET_COLOR_KEY
:
1147 if ((r
= omapfb_get_color_key(fbdev
, &p
.color_key
)) < 0)
1149 if (copy_to_user((void __user
*)arg
, &p
.color_key
,
1150 sizeof(p
.color_key
)))
1153 case OMAPFB_GET_CAPS
:
1154 omapfb_get_caps(fbdev
, plane
->idx
, &p
.caps
);
1155 if (copy_to_user((void __user
*)arg
, &p
.caps
, sizeof(p
.caps
)))
1158 case OMAPFB_LCD_TEST
:
1162 if (get_user(test_num
, (int __user
*)arg
)) {
1166 if (!fbdev
->panel
->run_test
) {
1170 r
= fbdev
->panel
->run_test(fbdev
->panel
, test_num
);
1173 case OMAPFB_CTRL_TEST
:
1177 if (get_user(test_num
, (int __user
*)arg
)) {
1181 if (!fbdev
->ctrl
->run_test
) {
1185 r
= fbdev
->ctrl
->run_test(test_num
);
1195 static int omapfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1197 struct omapfb_plane_struct
*plane
= info
->par
;
1198 struct omapfb_device
*fbdev
= plane
->fbdev
;
1201 omapfb_rqueue_lock(fbdev
);
1202 r
= fbdev
->ctrl
->mmap(info
, vma
);
1203 omapfb_rqueue_unlock(fbdev
);
1209 * Callback table for the frame buffer framework. Some of these pointers
1210 * will be changed according to the current setting of fb_info->accel_flags.
1212 static struct fb_ops omapfb_ops
= {
1213 .owner
= THIS_MODULE
,
1214 .fb_open
= omapfb_open
,
1215 .fb_release
= omapfb_release
,
1216 .fb_setcolreg
= omapfb_setcolreg
,
1217 .fb_setcmap
= omapfb_setcmap
,
1218 .fb_fillrect
= cfb_fillrect
,
1219 .fb_copyarea
= cfb_copyarea
,
1220 .fb_imageblit
= cfb_imageblit
,
1221 .fb_blank
= omapfb_blank
,
1222 .fb_ioctl
= omapfb_ioctl
,
1223 .fb_check_var
= omapfb_check_var
,
1224 .fb_set_par
= omapfb_set_par
,
1225 .fb_pan_display
= omapfb_pan_display
,
1229 * ---------------------------------------------------------------------------
1231 * ---------------------------------------------------------------------------
1233 /* omapfbX sysfs entries */
1234 static ssize_t
omapfb_show_caps_num(struct device
*dev
,
1235 struct device_attribute
*attr
, char *buf
)
1237 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1240 struct omapfb_caps caps
;
1244 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1245 omapfb_get_caps(fbdev
, plane
, &caps
);
1246 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1247 "plane#%d %#010x %#010x %#010x\n",
1248 plane
, caps
.ctrl
, caps
.plane_color
, caps
.wnd_color
);
1254 static ssize_t
omapfb_show_caps_text(struct device
*dev
,
1255 struct device_attribute
*attr
, char *buf
)
1257 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1259 struct omapfb_caps caps
;
1265 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1266 omapfb_get_caps(fbdev
, plane
, &caps
);
1267 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1268 "plane#%d:\n", plane
);
1269 for (i
= 0; i
< ARRAY_SIZE(ctrl_caps
) &&
1270 size
< PAGE_SIZE
; i
++) {
1271 if (ctrl_caps
[i
].flag
& caps
.ctrl
)
1272 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1273 " %s\n", ctrl_caps
[i
].name
);
1275 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1276 " plane colors:\n");
1277 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1278 size
< PAGE_SIZE
; i
++) {
1279 if (color_caps
[i
].flag
& caps
.plane_color
)
1280 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1281 " %s\n", color_caps
[i
].name
);
1283 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1284 " window colors:\n");
1285 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1286 size
< PAGE_SIZE
; i
++) {
1287 if (color_caps
[i
].flag
& caps
.wnd_color
)
1288 size
+= scnprintf(&buf
[size
], PAGE_SIZE
- size
,
1289 " %s\n", color_caps
[i
].name
);
1297 static DEVICE_ATTR(caps_num
, 0444, omapfb_show_caps_num
, NULL
);
1298 static DEVICE_ATTR(caps_text
, 0444, omapfb_show_caps_text
, NULL
);
1300 /* panel sysfs entries */
1301 static ssize_t
omapfb_show_panel_name(struct device
*dev
,
1302 struct device_attribute
*attr
, char *buf
)
1304 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1306 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->panel
->name
);
1309 static ssize_t
omapfb_show_bklight_level(struct device
*dev
,
1310 struct device_attribute
*attr
,
1313 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1316 if (fbdev
->panel
->get_bklight_level
) {
1317 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1318 fbdev
->panel
->get_bklight_level(fbdev
->panel
));
1324 static ssize_t
omapfb_store_bklight_level(struct device
*dev
,
1325 struct device_attribute
*attr
,
1326 const char *buf
, size_t size
)
1328 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1331 if (fbdev
->panel
->set_bklight_level
) {
1334 if (sscanf(buf
, "%10d", &level
) == 1) {
1335 r
= fbdev
->panel
->set_bklight_level(fbdev
->panel
,
1341 return r
? r
: size
;
1344 static ssize_t
omapfb_show_bklight_max(struct device
*dev
,
1345 struct device_attribute
*attr
, char *buf
)
1347 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1350 if (fbdev
->panel
->get_bklight_level
) {
1351 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1352 fbdev
->panel
->get_bklight_max(fbdev
->panel
));
1358 static struct device_attribute dev_attr_panel_name
=
1359 __ATTR(name
, 0444, omapfb_show_panel_name
, NULL
);
1360 static DEVICE_ATTR(backlight_level
, 0664,
1361 omapfb_show_bklight_level
, omapfb_store_bklight_level
);
1362 static DEVICE_ATTR(backlight_max
, 0444, omapfb_show_bklight_max
, NULL
);
1364 static struct attribute
*panel_attrs
[] = {
1365 &dev_attr_panel_name
.attr
,
1366 &dev_attr_backlight_level
.attr
,
1367 &dev_attr_backlight_max
.attr
,
1371 static const struct attribute_group panel_attr_grp
= {
1373 .attrs
= panel_attrs
,
1376 /* ctrl sysfs entries */
1377 static ssize_t
omapfb_show_ctrl_name(struct device
*dev
,
1378 struct device_attribute
*attr
, char *buf
)
1380 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1382 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->ctrl
->name
);
1385 static struct device_attribute dev_attr_ctrl_name
=
1386 __ATTR(name
, 0444, omapfb_show_ctrl_name
, NULL
);
1388 static struct attribute
*ctrl_attrs
[] = {
1389 &dev_attr_ctrl_name
.attr
,
1393 static const struct attribute_group ctrl_attr_grp
= {
1395 .attrs
= ctrl_attrs
,
1398 static int omapfb_register_sysfs(struct omapfb_device
*fbdev
)
1402 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_num
)))
1405 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_text
)))
1408 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &panel_attr_grp
)))
1411 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
)))
1416 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1418 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1420 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1422 dev_err(fbdev
->dev
, "unable to register sysfs interface\n");
1426 static void omapfb_unregister_sysfs(struct omapfb_device
*fbdev
)
1428 sysfs_remove_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
);
1429 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1430 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1431 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1435 * ---------------------------------------------------------------------------
1437 * ---------------------------------------------------------------------------
1439 /* Initialize system fb_info object and set the default video mode.
1440 * The frame buffer memory already allocated by lcddma_init
1442 static int fbinfo_init(struct omapfb_device
*fbdev
, struct fb_info
*info
)
1444 struct fb_var_screeninfo
*var
= &info
->var
;
1445 struct fb_fix_screeninfo
*fix
= &info
->fix
;
1448 info
->fbops
= &omapfb_ops
;
1449 info
->flags
= FBINFO_FLAG_DEFAULT
;
1451 strncpy(fix
->id
, MODULE_NAME
, sizeof(fix
->id
));
1453 info
->pseudo_palette
= fbdev
->pseudo_palette
;
1455 var
->accel_flags
= def_accel
? FB_ACCELF_TEXT
: 0;
1456 var
->xres
= def_vxres
;
1457 var
->yres
= def_vyres
;
1458 var
->xres_virtual
= def_vxres
;
1459 var
->yres_virtual
= def_vyres
;
1460 var
->rotate
= def_rotate
;
1461 var
->bits_per_pixel
= fbdev
->panel
->bpp
;
1463 set_fb_var(info
, var
);
1464 set_fb_fix(info
, 1);
1466 r
= fb_alloc_cmap(&info
->cmap
, 16, 0);
1468 dev_err(fbdev
->dev
, "unable to allocate color map memory\n");
1473 /* Release the fb_info object */
1474 static void fbinfo_cleanup(struct omapfb_device
*fbdev
, struct fb_info
*fbi
)
1476 fb_dealloc_cmap(&fbi
->cmap
);
1479 static void planes_cleanup(struct omapfb_device
*fbdev
)
1483 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1484 if (fbdev
->fb_info
[i
] == NULL
)
1486 fbinfo_cleanup(fbdev
, fbdev
->fb_info
[i
]);
1487 framebuffer_release(fbdev
->fb_info
[i
]);
1491 static int planes_init(struct omapfb_device
*fbdev
)
1493 struct fb_info
*fbi
;
1497 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1498 struct omapfb_plane_struct
*plane
;
1499 fbi
= framebuffer_alloc(sizeof(struct omapfb_plane_struct
),
1502 planes_cleanup(fbdev
);
1507 plane
->fbdev
= fbdev
;
1508 plane
->info
.mirror
= def_mirror
;
1509 fbdev
->fb_info
[i
] = fbi
;
1511 if ((r
= fbinfo_init(fbdev
, fbi
)) < 0) {
1512 framebuffer_release(fbi
);
1513 planes_cleanup(fbdev
);
1516 plane
->info
.out_width
= fbi
->var
.xres
;
1517 plane
->info
.out_height
= fbi
->var
.yres
;
1523 * Free driver resources. Can be called to rollback an aborted initialization
1526 static void omapfb_free_resources(struct omapfb_device
*fbdev
, int state
)
1532 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++)
1533 unregister_framebuffer(fbdev
->fb_info
[i
]);
1536 omapfb_unregister_sysfs(fbdev
);
1539 if (fbdev
->panel
->disable
)
1540 fbdev
->panel
->disable(fbdev
->panel
);
1543 omapfb_set_update_mode(fbdev
, OMAPFB_UPDATE_DISABLED
);
1546 planes_cleanup(fbdev
);
1549 ctrl_cleanup(fbdev
);
1552 if (fbdev
->panel
->cleanup
)
1553 fbdev
->panel
->cleanup(fbdev
->panel
);
1556 dev_set_drvdata(fbdev
->dev
, NULL
);
1559 /* nothing to free */
1566 static int omapfb_find_ctrl(struct omapfb_device
*fbdev
)
1568 struct omapfb_platform_data
*conf
;
1572 conf
= dev_get_platdata(fbdev
->dev
);
1576 strncpy(name
, conf
->lcd
.ctrl_name
, sizeof(name
) - 1);
1577 name
[sizeof(name
) - 1] = '\0';
1579 if (strcmp(name
, "internal") == 0) {
1580 fbdev
->ctrl
= fbdev
->int_ctrl
;
1584 for (i
= 0; i
< ARRAY_SIZE(ctrls
); i
++) {
1585 dev_dbg(fbdev
->dev
, "ctrl %s\n", ctrls
[i
]->name
);
1586 if (strcmp(ctrls
[i
]->name
, name
) == 0) {
1587 fbdev
->ctrl
= ctrls
[i
];
1592 if (fbdev
->ctrl
== NULL
) {
1593 dev_dbg(fbdev
->dev
, "ctrl %s not supported\n", name
);
1601 * Called by LDM binding to probe and attach a new device.
1602 * Initialization sequence:
1603 * 1. allocate system omapfb_device structure
1604 * 2. select controller type according to platform configuration
1606 * 3. init LCD controller and LCD DMA
1607 * 4. init system fb_info structure for all planes
1608 * 5. setup video mode for first plane and enable it
1609 * 6. enable LCD panel
1610 * 7. register sysfs attributes
1611 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1613 static int omapfb_do_probe(struct platform_device
*pdev
,
1614 struct lcd_panel
*panel
)
1616 struct omapfb_device
*fbdev
= NULL
;
1618 unsigned long phz
, hhz
, vhz
;
1625 if (pdev
->num_resources
!= 0) {
1626 dev_err(&pdev
->dev
, "probed for an unknown device\n");
1631 if (dev_get_platdata(&pdev
->dev
) == NULL
) {
1632 dev_err(&pdev
->dev
, "missing platform data\n");
1637 fbdev
= kzalloc(sizeof(*fbdev
), GFP_KERNEL
);
1638 if (fbdev
== NULL
) {
1640 "unable to allocate memory for device info\n");
1646 fbdev
->dev
= &pdev
->dev
;
1647 fbdev
->panel
= panel
;
1648 fbdev
->dssdev
= &omapdss_device
;
1649 platform_set_drvdata(pdev
, fbdev
);
1651 mutex_init(&fbdev
->rqueue_mutex
);
1653 fbdev
->int_ctrl
= &omap1_int_ctrl
;
1654 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1655 fbdev
->ext_if
= &omap1_ext_if
;
1657 if (omapfb_find_ctrl(fbdev
) < 0) {
1659 "LCD controller not found, board not supported\n");
1664 if (fbdev
->panel
->init
) {
1665 r
= fbdev
->panel
->init(fbdev
->panel
, fbdev
);
1670 pr_info("omapfb: configured for panel %s\n", fbdev
->panel
->name
);
1672 def_vxres
= def_vxres
? def_vxres
: fbdev
->panel
->x_res
;
1673 def_vyres
= def_vyres
? def_vyres
: fbdev
->panel
->y_res
;
1677 r
= ctrl_init(fbdev
);
1680 if (fbdev
->ctrl
->mmap
!= NULL
)
1681 omapfb_ops
.fb_mmap
= omapfb_mmap
;
1684 r
= planes_init(fbdev
);
1689 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1690 /* Set DMA priority for EMIFF access to highest */
1691 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF
, 15);
1694 r
= ctrl_change_mode(fbdev
->fb_info
[0]);
1696 dev_err(fbdev
->dev
, "mode setting failed\n");
1700 /* GFX plane is enabled by default */
1701 r
= fbdev
->ctrl
->enable_plane(OMAPFB_PLANE_GFX
, 1);
1705 omapfb_set_update_mode(fbdev
, manual_update
?
1706 OMAPFB_MANUAL_UPDATE
: OMAPFB_AUTO_UPDATE
);
1709 if (fbdev
->panel
->enable
) {
1710 r
= fbdev
->panel
->enable(fbdev
->panel
);
1716 r
= omapfb_register_sysfs(fbdev
);
1722 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1723 r
= register_framebuffer(fbdev
->fb_info
[i
]);
1726 "registering framebuffer %d failed\n", i
);
1729 vram
+= fbdev
->mem_desc
.region
[i
].size
;
1732 fbdev
->state
= OMAPFB_ACTIVE
;
1734 panel
= fbdev
->panel
;
1735 phz
= panel
->pixel_clock
* 1000;
1736 hhz
= phz
* 10 / (panel
->hfp
+ panel
->x_res
+ panel
->hbp
+ panel
->hsw
);
1737 vhz
= hhz
/ (panel
->vfp
+ panel
->y_res
+ panel
->vbp
+ panel
->vsw
);
1741 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1742 vram
, fbdev
->mem_desc
.region_cnt
);
1743 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1744 "vfreq %lu.%lu Hz\n",
1745 phz
/ 1000, hhz
/ 10000, hhz
% 10, vhz
/ 10, vhz
% 10);
1750 omapfb_free_resources(fbdev
, init_state
);
1755 static int omapfb_probe(struct platform_device
*pdev
)
1759 BUG_ON(fbdev_pdev
!= NULL
);
1761 r
= platform_device_register(&omapdss_device
);
1763 dev_err(&pdev
->dev
, "can't register omapdss device\n");
1767 /* Delay actual initialization until the LCD is registered */
1769 if (fbdev_panel
!= NULL
)
1770 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1774 void omapfb_register_panel(struct lcd_panel
*panel
)
1776 BUG_ON(fbdev_panel
!= NULL
);
1778 fbdev_panel
= panel
;
1779 if (fbdev_pdev
!= NULL
)
1780 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1782 EXPORT_SYMBOL_GPL(omapfb_register_panel
);
1784 /* Called when the device is being detached from the driver */
1785 static int omapfb_remove(struct platform_device
*pdev
)
1787 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1788 enum omapfb_state saved_state
= fbdev
->state
;
1790 /* FIXME: wait till completion of pending events */
1792 fbdev
->state
= OMAPFB_DISABLED
;
1793 omapfb_free_resources(fbdev
, saved_state
);
1795 platform_device_unregister(&omapdss_device
);
1796 fbdev
->dssdev
= NULL
;
1802 static int omapfb_suspend(struct platform_device
*pdev
, pm_message_t mesg
)
1804 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1807 omapfb_blank(FB_BLANK_POWERDOWN
, fbdev
->fb_info
[0]);
1812 static int omapfb_resume(struct platform_device
*pdev
)
1814 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1817 omapfb_blank(FB_BLANK_UNBLANK
, fbdev
->fb_info
[0]);
1821 static struct platform_driver omapfb_driver
= {
1822 .probe
= omapfb_probe
,
1823 .remove
= omapfb_remove
,
1824 .suspend
= omapfb_suspend
,
1825 .resume
= omapfb_resume
,
1827 .name
= MODULE_NAME
,
1833 /* Process kernel command line parameters */
1834 static int __init
omapfb_setup(char *options
)
1836 char *this_opt
= NULL
;
1839 pr_debug("omapfb: options %s\n", options
);
1841 if (!options
|| !*options
)
1844 while (!r
&& (this_opt
= strsep(&options
, ",")) != NULL
) {
1845 if (!strncmp(this_opt
, "accel", 5))
1847 else if (!strncmp(this_opt
, "vram:", 5)) {
1850 vram
= (simple_strtoul(this_opt
+ 5, &suffix
, 0));
1851 switch (suffix
[0]) {
1863 pr_debug("omapfb: invalid vram suffix %c\n",
1867 def_vram
[def_vram_cnt
++] = vram
;
1869 else if (!strncmp(this_opt
, "vxres:", 6))
1870 def_vxres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1871 else if (!strncmp(this_opt
, "vyres:", 6))
1872 def_vyres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1873 else if (!strncmp(this_opt
, "rotate:", 7))
1874 def_rotate
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1875 else if (!strncmp(this_opt
, "mirror:", 7))
1876 def_mirror
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1877 else if (!strncmp(this_opt
, "manual_update", 13))
1880 pr_debug("omapfb: invalid option\n");
1890 /* Register both the driver and the device */
1891 static int __init
omapfb_init(void)
1896 if (fb_get_options("omapfb", &option
))
1898 omapfb_setup(option
);
1900 /* Register the driver with LDM */
1901 if (platform_driver_register(&omapfb_driver
)) {
1902 pr_debug("failed to register omapfb driver\n");
1909 static void __exit
omapfb_cleanup(void)
1911 platform_driver_unregister(&omapfb_driver
);
1914 module_param_named(accel
, def_accel
, uint
, 0664);
1915 module_param_array_named(vram
, def_vram
, ulong
, &def_vram_cnt
, 0664);
1916 module_param_named(vxres
, def_vxres
, long, 0664);
1917 module_param_named(vyres
, def_vyres
, long, 0664);
1918 module_param_named(rotate
, def_rotate
, uint
, 0664);
1919 module_param_named(mirror
, def_mirror
, uint
, 0664);
1920 module_param_named(manual_update
, manual_update
, bool, 0664);
1922 module_init(omapfb_init
);
1923 module_exit(omapfb_cleanup
);
1925 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1926 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1927 MODULE_LICENSE("GPL");