2 * Framebuffer driver for TI OMAP boards
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Imre Deak <imre.deak@nokia.com>
8 * Alex McMains <aam@ridgerun.com> - Original driver
9 * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
10 * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
11 * Texas Instruments - H3 support
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <linux/platform_device.h>
29 #include <linux/uaccess.h>
37 #define MODULE_NAME "omapfb"
39 static unsigned int def_accel
;
40 static unsigned long def_vram
[OMAPFB_PLANE_NUM
];
41 static unsigned int def_vram_cnt
;
42 static unsigned long def_vxres
;
43 static unsigned long def_vyres
;
44 static unsigned int def_rotate
;
45 static unsigned int def_mirror
;
47 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
48 static int manual_update
= 1;
50 static int manual_update
;
53 static struct platform_device
*fbdev_pdev
;
54 static struct lcd_panel
*fbdev_panel
;
55 static struct omapfb_device
*omapfb_dev
;
57 struct caps_table_struct
{
62 static struct caps_table_struct ctrl_caps
[] = {
63 { OMAPFB_CAPS_MANUAL_UPDATE
, "manual update" },
64 { OMAPFB_CAPS_TEARSYNC
, "tearing synchronization" },
65 { OMAPFB_CAPS_PLANE_RELOCATE_MEM
, "relocate plane memory" },
66 { OMAPFB_CAPS_PLANE_SCALE
, "scale plane" },
67 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE
, "pixel double window" },
68 { OMAPFB_CAPS_WINDOW_SCALE
, "scale window" },
69 { OMAPFB_CAPS_WINDOW_OVERLAY
, "overlay window" },
70 { OMAPFB_CAPS_WINDOW_ROTATE
, "rotate window" },
71 { OMAPFB_CAPS_SET_BACKLIGHT
, "backlight setting" },
74 static struct caps_table_struct color_caps
[] = {
75 { 1 << OMAPFB_COLOR_RGB565
, "RGB565", },
76 { 1 << OMAPFB_COLOR_YUV422
, "YUV422", },
77 { 1 << OMAPFB_COLOR_YUV420
, "YUV420", },
78 { 1 << OMAPFB_COLOR_CLUT_8BPP
, "CLUT8", },
79 { 1 << OMAPFB_COLOR_CLUT_4BPP
, "CLUT4", },
80 { 1 << OMAPFB_COLOR_CLUT_2BPP
, "CLUT2", },
81 { 1 << OMAPFB_COLOR_CLUT_1BPP
, "CLUT1", },
82 { 1 << OMAPFB_COLOR_RGB444
, "RGB444", },
83 { 1 << OMAPFB_COLOR_YUY422
, "YUY422", },
86 static void omapdss_release(struct device
*dev
)
90 /* dummy device for clocks */
91 static struct platform_device omapdss_device
= {
95 .release
= omapdss_release
,
100 * ---------------------------------------------------------------------------
102 * ---------------------------------------------------------------------------
104 extern struct lcd_ctrl hwa742_ctrl
;
105 extern struct lcd_ctrl blizzard_ctrl
;
107 static const struct lcd_ctrl
*ctrls
[] = {
108 #ifdef CONFIG_ARCH_OMAP1
114 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
117 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
122 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
123 #ifdef CONFIG_ARCH_OMAP1
124 extern struct lcd_ctrl_extif omap1_ext_if
;
126 extern struct lcd_ctrl_extif omap2_ext_if
;
130 static void omapfb_rqueue_lock(struct omapfb_device
*fbdev
)
132 mutex_lock(&fbdev
->rqueue_mutex
);
135 static void omapfb_rqueue_unlock(struct omapfb_device
*fbdev
)
137 mutex_unlock(&fbdev
->rqueue_mutex
);
141 * ---------------------------------------------------------------------------
142 * LCD controller and LCD DMA
143 * ---------------------------------------------------------------------------
145 /* Lookup table to map elem size to elem type. */
146 static const int dma_elem_type
[] = {
148 OMAP_DMA_DATA_TYPE_S8
,
149 OMAP_DMA_DATA_TYPE_S16
,
151 OMAP_DMA_DATA_TYPE_S32
,
155 * Allocate resources needed for LCD controller and LCD DMA operations. Video
156 * memory is allocated from system memory according to the virtual display
157 * size, except if a bigger memory size is specified explicitly as a kernel
160 static int ctrl_init(struct omapfb_device
*fbdev
)
165 /* kernel/module vram parameters override boot tags/board config */
167 for (i
= 0; i
< def_vram_cnt
; i
++)
168 fbdev
->mem_desc
.region
[i
].size
=
169 PAGE_ALIGN(def_vram
[i
]);
170 fbdev
->mem_desc
.region_cnt
= i
;
172 struct omapfb_platform_data
*conf
;
174 conf
= fbdev
->dev
->platform_data
;
175 fbdev
->mem_desc
= conf
->mem_desc
;
178 if (!fbdev
->mem_desc
.region_cnt
) {
179 struct lcd_panel
*panel
= fbdev
->panel
;
181 int bpp
= panel
->bpp
;
183 /* 12 bpp is packed in 16 bits */
186 def_size
= def_vxres
* def_vyres
* bpp
/ 8;
187 fbdev
->mem_desc
.region_cnt
= 1;
188 fbdev
->mem_desc
.region
[0].size
= PAGE_ALIGN(def_size
);
190 r
= fbdev
->ctrl
->init(fbdev
, 0, &fbdev
->mem_desc
);
192 dev_err(fbdev
->dev
, "controller initialization failed (%d)\n",
198 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
199 dev_dbg(fbdev
->dev
, "region%d phys %08x virt %p size=%lu\n",
201 fbdev
->mem_desc
.region
[i
].paddr
,
202 fbdev
->mem_desc
.region
[i
].vaddr
,
203 fbdev
->mem_desc
.region
[i
].size
);
209 static void ctrl_cleanup(struct omapfb_device
*fbdev
)
211 fbdev
->ctrl
->cleanup();
214 /* Must be called with fbdev->rqueue_mutex held. */
215 static int ctrl_change_mode(struct fb_info
*fbi
)
218 unsigned long offset
;
219 struct omapfb_plane_struct
*plane
= fbi
->par
;
220 struct omapfb_device
*fbdev
= plane
->fbdev
;
221 struct fb_var_screeninfo
*var
= &fbi
->var
;
223 offset
= var
->yoffset
* fbi
->fix
.line_length
+
224 var
->xoffset
* var
->bits_per_pixel
/ 8;
226 if (fbdev
->ctrl
->sync
)
228 r
= fbdev
->ctrl
->setup_plane(plane
->idx
, plane
->info
.channel_out
,
229 offset
, var
->xres_virtual
,
230 plane
->info
.pos_x
, plane
->info
.pos_y
,
231 var
->xres
, var
->yres
, plane
->color_mode
);
235 if (fbdev
->ctrl
->set_rotate
!= NULL
) {
236 r
= fbdev
->ctrl
->set_rotate(var
->rotate
);
241 if (fbdev
->ctrl
->set_scale
!= NULL
)
242 r
= fbdev
->ctrl
->set_scale(plane
->idx
,
243 var
->xres
, var
->yres
,
244 plane
->info
.out_width
,
245 plane
->info
.out_height
);
251 * ---------------------------------------------------------------------------
252 * fbdev framework callbacks and the ioctl interface
253 * ---------------------------------------------------------------------------
255 /* Called each time the omapfb device is opened */
256 static int omapfb_open(struct fb_info
*info
, int user
)
261 static void omapfb_sync(struct fb_info
*info
);
263 /* Called when the omapfb device is closed. We make sure that any pending
264 * gfx DMA operations are ended, before we return. */
265 static int omapfb_release(struct fb_info
*info
, int user
)
271 /* Store a single color palette entry into a pseudo palette or the hardware
272 * palette if one is available. For now we support only 16bpp and thus store
273 * the entry only to the pseudo palette.
275 static int _setcolreg(struct fb_info
*info
, u_int regno
, u_int red
, u_int green
,
276 u_int blue
, u_int transp
, int update_hw_pal
)
278 struct omapfb_plane_struct
*plane
= info
->par
;
279 struct omapfb_device
*fbdev
= plane
->fbdev
;
280 struct fb_var_screeninfo
*var
= &info
->var
;
283 switch (plane
->color_mode
) {
284 case OMAPFB_COLOR_YUV422
:
285 case OMAPFB_COLOR_YUV420
:
286 case OMAPFB_COLOR_YUY422
:
289 case OMAPFB_COLOR_CLUT_8BPP
:
290 case OMAPFB_COLOR_CLUT_4BPP
:
291 case OMAPFB_COLOR_CLUT_2BPP
:
292 case OMAPFB_COLOR_CLUT_1BPP
:
293 if (fbdev
->ctrl
->setcolreg
)
294 r
= fbdev
->ctrl
->setcolreg(regno
, red
, green
, blue
,
295 transp
, update_hw_pal
);
297 case OMAPFB_COLOR_RGB565
:
298 case OMAPFB_COLOR_RGB444
:
309 pal
= ((red
>> (16 - var
->red
.length
)) <<
311 ((green
>> (16 - var
->green
.length
)) <<
313 (blue
>> (16 - var
->blue
.length
));
314 ((u32
*)(info
->pseudo_palette
))[regno
] = pal
;
323 static int omapfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
324 u_int transp
, struct fb_info
*info
)
326 return _setcolreg(info
, regno
, red
, green
, blue
, transp
, 1);
329 static int omapfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
332 u16
*red
, *green
, *blue
, *transp
;
338 transp
= cmap
->transp
;
341 for (count
= 0; count
< cmap
->len
; count
++) {
344 r
= _setcolreg(info
, index
++, *red
++, *green
++, *blue
++, trans
,
345 count
== cmap
->len
- 1);
353 static int omapfb_update_full_screen(struct fb_info
*fbi
);
355 static int omapfb_blank(int blank
, struct fb_info
*fbi
)
357 struct omapfb_plane_struct
*plane
= fbi
->par
;
358 struct omapfb_device
*fbdev
= plane
->fbdev
;
362 omapfb_rqueue_lock(fbdev
);
364 case FB_BLANK_UNBLANK
:
365 if (fbdev
->state
== OMAPFB_SUSPENDED
) {
366 if (fbdev
->ctrl
->resume
)
367 fbdev
->ctrl
->resume();
368 fbdev
->panel
->enable(fbdev
->panel
);
369 fbdev
->state
= OMAPFB_ACTIVE
;
370 if (fbdev
->ctrl
->get_update_mode() ==
371 OMAPFB_MANUAL_UPDATE
)
375 case FB_BLANK_POWERDOWN
:
376 if (fbdev
->state
== OMAPFB_ACTIVE
) {
377 fbdev
->panel
->disable(fbdev
->panel
);
378 if (fbdev
->ctrl
->suspend
)
379 fbdev
->ctrl
->suspend();
380 fbdev
->state
= OMAPFB_SUSPENDED
;
386 omapfb_rqueue_unlock(fbdev
);
388 if (r
== 0 && do_update
)
389 r
= omapfb_update_full_screen(fbi
);
394 static void omapfb_sync(struct fb_info
*fbi
)
396 struct omapfb_plane_struct
*plane
= fbi
->par
;
397 struct omapfb_device
*fbdev
= plane
->fbdev
;
399 omapfb_rqueue_lock(fbdev
);
400 if (fbdev
->ctrl
->sync
)
402 omapfb_rqueue_unlock(fbdev
);
406 * Set fb_info.fix fields and also updates fbdev.
407 * When calling this fb_info.var must be set up already.
409 static void set_fb_fix(struct fb_info
*fbi
, int from_init
)
411 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
412 struct fb_var_screeninfo
*var
= &fbi
->var
;
413 struct omapfb_plane_struct
*plane
= fbi
->par
;
414 struct omapfb_mem_region
*rg
;
417 rg
= &plane
->fbdev
->mem_desc
.region
[plane
->idx
];
418 fbi
->screen_base
= rg
->vaddr
;
421 mutex_lock(&fbi
->mm_lock
);
422 fix
->smem_start
= rg
->paddr
;
423 fix
->smem_len
= rg
->size
;
424 mutex_unlock(&fbi
->mm_lock
);
426 fix
->smem_start
= rg
->paddr
;
427 fix
->smem_len
= rg
->size
;
430 fix
->type
= FB_TYPE_PACKED_PIXELS
;
431 bpp
= var
->bits_per_pixel
;
433 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
434 else switch (var
->bits_per_pixel
) {
437 fix
->visual
= FB_VISUAL_TRUECOLOR
;
438 /* 12bpp is stored in 16 bits */
445 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
448 fix
->accel
= FB_ACCEL_OMAP1610
;
449 fix
->line_length
= var
->xres_virtual
* bpp
/ 8;
452 static int set_color_mode(struct omapfb_plane_struct
*plane
,
453 struct fb_var_screeninfo
*var
)
455 switch (var
->nonstd
) {
458 case OMAPFB_COLOR_YUV422
:
459 var
->bits_per_pixel
= 16;
460 plane
->color_mode
= var
->nonstd
;
462 case OMAPFB_COLOR_YUV420
:
463 var
->bits_per_pixel
= 12;
464 plane
->color_mode
= var
->nonstd
;
466 case OMAPFB_COLOR_YUY422
:
467 var
->bits_per_pixel
= 16;
468 plane
->color_mode
= var
->nonstd
;
474 switch (var
->bits_per_pixel
) {
476 plane
->color_mode
= OMAPFB_COLOR_CLUT_1BPP
;
479 plane
->color_mode
= OMAPFB_COLOR_CLUT_2BPP
;
482 plane
->color_mode
= OMAPFB_COLOR_CLUT_4BPP
;
485 plane
->color_mode
= OMAPFB_COLOR_CLUT_8BPP
;
488 var
->bits_per_pixel
= 16;
490 if (plane
->fbdev
->panel
->bpp
== 12)
491 plane
->color_mode
= OMAPFB_COLOR_RGB444
;
493 plane
->color_mode
= OMAPFB_COLOR_RGB565
;
501 * Check the values in var against our capabilities and in case of out of
502 * bound values try to adjust them.
504 static int set_fb_var(struct fb_info
*fbi
,
505 struct fb_var_screeninfo
*var
)
508 unsigned long max_frame_size
;
509 unsigned long line_size
;
510 int xres_min
, xres_max
;
511 int yres_min
, yres_max
;
512 struct omapfb_plane_struct
*plane
= fbi
->par
;
513 struct omapfb_device
*fbdev
= plane
->fbdev
;
514 struct lcd_panel
*panel
= fbdev
->panel
;
516 if (set_color_mode(plane
, var
) < 0)
519 bpp
= var
->bits_per_pixel
;
520 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
)
523 switch (var
->rotate
) {
526 xres_min
= OMAPFB_PLANE_XRES_MIN
;
527 xres_max
= panel
->x_res
;
528 yres_min
= OMAPFB_PLANE_YRES_MIN
;
529 yres_max
= panel
->y_res
;
530 if (cpu_is_omap15xx()) {
531 var
->xres
= panel
->x_res
;
532 var
->yres
= panel
->y_res
;
537 xres_min
= OMAPFB_PLANE_YRES_MIN
;
538 xres_max
= panel
->y_res
;
539 yres_min
= OMAPFB_PLANE_XRES_MIN
;
540 yres_max
= panel
->x_res
;
541 if (cpu_is_omap15xx()) {
542 var
->xres
= panel
->y_res
;
543 var
->yres
= panel
->x_res
;
550 if (var
->xres
< xres_min
)
551 var
->xres
= xres_min
;
552 if (var
->yres
< yres_min
)
553 var
->yres
= yres_min
;
554 if (var
->xres
> xres_max
)
555 var
->xres
= xres_max
;
556 if (var
->yres
> yres_max
)
557 var
->yres
= yres_max
;
559 if (var
->xres_virtual
< var
->xres
)
560 var
->xres_virtual
= var
->xres
;
561 if (var
->yres_virtual
< var
->yres
)
562 var
->yres_virtual
= var
->yres
;
563 max_frame_size
= fbdev
->mem_desc
.region
[plane
->idx
].size
;
564 line_size
= var
->xres_virtual
* bpp
/ 8;
565 if (line_size
* var
->yres_virtual
> max_frame_size
) {
566 /* Try to keep yres_virtual first */
567 line_size
= max_frame_size
/ var
->yres_virtual
;
568 var
->xres_virtual
= line_size
* 8 / bpp
;
569 if (var
->xres_virtual
< var
->xres
) {
570 /* Still doesn't fit. Shrink yres_virtual too */
571 var
->xres_virtual
= var
->xres
;
572 line_size
= var
->xres
* bpp
/ 8;
573 var
->yres_virtual
= max_frame_size
/ line_size
;
575 /* Recheck this, as the virtual size changed. */
576 if (var
->xres_virtual
< var
->xres
)
577 var
->xres
= var
->xres_virtual
;
578 if (var
->yres_virtual
< var
->yres
)
579 var
->yres
= var
->yres_virtual
;
580 if (var
->xres
< xres_min
|| var
->yres
< yres_min
)
583 if (var
->xres
+ var
->xoffset
> var
->xres_virtual
)
584 var
->xoffset
= var
->xres_virtual
- var
->xres
;
585 if (var
->yres
+ var
->yoffset
> var
->yres_virtual
)
586 var
->yoffset
= var
->yres_virtual
- var
->yres
;
588 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
) {
589 var
->red
.offset
= 8; var
->red
.length
= 4;
590 var
->red
.msb_right
= 0;
591 var
->green
.offset
= 4; var
->green
.length
= 4;
592 var
->green
.msb_right
= 0;
593 var
->blue
.offset
= 0; var
->blue
.length
= 4;
594 var
->blue
.msb_right
= 0;
596 var
->red
.offset
= 11; var
->red
.length
= 5;
597 var
->red
.msb_right
= 0;
598 var
->green
.offset
= 5; var
->green
.length
= 6;
599 var
->green
.msb_right
= 0;
600 var
->blue
.offset
= 0; var
->blue
.length
= 5;
601 var
->blue
.msb_right
= 0;
608 /* pixclock in ps, the rest in pixclock */
609 var
->pixclock
= 10000000 / (panel
->pixel_clock
/ 100);
610 var
->left_margin
= panel
->hfp
;
611 var
->right_margin
= panel
->hbp
;
612 var
->upper_margin
= panel
->vfp
;
613 var
->lower_margin
= panel
->vbp
;
614 var
->hsync_len
= panel
->hsw
;
615 var
->vsync_len
= panel
->vsw
;
617 /* TODO: get these from panel->config */
618 var
->vmode
= FB_VMODE_NONINTERLACED
;
625 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
626 static void omapfb_rotate(struct fb_info
*fbi
, int rotate
)
628 struct omapfb_plane_struct
*plane
= fbi
->par
;
629 struct omapfb_device
*fbdev
= plane
->fbdev
;
631 omapfb_rqueue_lock(fbdev
);
632 if (rotate
!= fbi
->var
.rotate
) {
633 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
635 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
636 new_var
->rotate
= rotate
;
637 if (set_fb_var(fbi
, new_var
) == 0 &&
638 memcmp(new_var
, &fbi
->var
, sizeof(*new_var
))) {
639 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
640 ctrl_change_mode(fbi
);
643 omapfb_rqueue_unlock(fbdev
);
647 * Set new x,y offsets in the virtual display for the visible area and switch
650 static int omapfb_pan_display(struct fb_var_screeninfo
*var
,
653 struct omapfb_plane_struct
*plane
= fbi
->par
;
654 struct omapfb_device
*fbdev
= plane
->fbdev
;
657 omapfb_rqueue_lock(fbdev
);
658 if (var
->xoffset
!= fbi
->var
.xoffset
||
659 var
->yoffset
!= fbi
->var
.yoffset
) {
660 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
662 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
663 new_var
->xoffset
= var
->xoffset
;
664 new_var
->yoffset
= var
->yoffset
;
665 if (set_fb_var(fbi
, new_var
))
668 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
669 ctrl_change_mode(fbi
);
672 omapfb_rqueue_unlock(fbdev
);
677 /* Set mirror to vertical axis and switch to the new mode. */
678 static int omapfb_mirror(struct fb_info
*fbi
, int mirror
)
680 struct omapfb_plane_struct
*plane
= fbi
->par
;
681 struct omapfb_device
*fbdev
= plane
->fbdev
;
684 omapfb_rqueue_lock(fbdev
);
685 mirror
= mirror
? 1 : 0;
686 if (cpu_is_omap15xx())
688 else if (mirror
!= plane
->info
.mirror
) {
689 plane
->info
.mirror
= mirror
;
690 r
= ctrl_change_mode(fbi
);
692 omapfb_rqueue_unlock(fbdev
);
698 * Check values in var, try to adjust them in case of out of bound values if
699 * possible, or return error.
701 static int omapfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*fbi
)
703 struct omapfb_plane_struct
*plane
= fbi
->par
;
704 struct omapfb_device
*fbdev
= plane
->fbdev
;
707 omapfb_rqueue_lock(fbdev
);
708 if (fbdev
->ctrl
->sync
!= NULL
)
710 r
= set_fb_var(fbi
, var
);
711 omapfb_rqueue_unlock(fbdev
);
717 * Switch to a new mode. The parameters for it has been check already by
720 static int omapfb_set_par(struct fb_info
*fbi
)
722 struct omapfb_plane_struct
*plane
= fbi
->par
;
723 struct omapfb_device
*fbdev
= plane
->fbdev
;
726 omapfb_rqueue_lock(fbdev
);
728 r
= ctrl_change_mode(fbi
);
729 omapfb_rqueue_unlock(fbdev
);
734 int omapfb_update_window_async(struct fb_info
*fbi
,
735 struct omapfb_update_window
*win
,
736 void (*callback
)(void *),
740 struct omapfb_plane_struct
*plane
= fbi
->par
;
741 struct omapfb_device
*fbdev
= plane
->fbdev
;
742 struct fb_var_screeninfo
*var
= &fbi
->var
;
744 switch (var
->rotate
) {
747 xres
= fbdev
->panel
->x_res
;
748 yres
= fbdev
->panel
->y_res
;
752 xres
= fbdev
->panel
->y_res
;
753 yres
= fbdev
->panel
->x_res
;
759 if (win
->x
>= xres
|| win
->y
>= yres
||
760 win
->out_x
> xres
|| win
->out_y
> yres
)
763 if (!fbdev
->ctrl
->update_window
||
764 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
767 if (win
->x
+ win
->width
> xres
)
768 win
->width
= xres
- win
->x
;
769 if (win
->y
+ win
->height
> yres
)
770 win
->height
= yres
- win
->y
;
771 if (win
->out_x
+ win
->out_width
> xres
)
772 win
->out_width
= xres
- win
->out_x
;
773 if (win
->out_y
+ win
->out_height
> yres
)
774 win
->out_height
= yres
- win
->out_y
;
775 if (!win
->width
|| !win
->height
|| !win
->out_width
|| !win
->out_height
)
778 return fbdev
->ctrl
->update_window(fbi
, win
, callback
, callback_data
);
780 EXPORT_SYMBOL(omapfb_update_window_async
);
782 static int omapfb_update_win(struct fb_info
*fbi
,
783 struct omapfb_update_window
*win
)
785 struct omapfb_plane_struct
*plane
= fbi
->par
;
788 omapfb_rqueue_lock(plane
->fbdev
);
789 ret
= omapfb_update_window_async(fbi
, win
, NULL
, NULL
);
790 omapfb_rqueue_unlock(plane
->fbdev
);
795 static int omapfb_update_full_screen(struct fb_info
*fbi
)
797 struct omapfb_plane_struct
*plane
= fbi
->par
;
798 struct omapfb_device
*fbdev
= plane
->fbdev
;
799 struct omapfb_update_window win
;
802 if (!fbdev
->ctrl
->update_window
||
803 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
808 win
.width
= fbi
->var
.xres
;
809 win
.height
= fbi
->var
.yres
;
812 win
.out_width
= fbi
->var
.xres
;
813 win
.out_height
= fbi
->var
.yres
;
816 omapfb_rqueue_lock(fbdev
);
817 r
= fbdev
->ctrl
->update_window(fbi
, &win
, NULL
, NULL
);
818 omapfb_rqueue_unlock(fbdev
);
823 static int omapfb_setup_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
825 struct omapfb_plane_struct
*plane
= fbi
->par
;
826 struct omapfb_device
*fbdev
= plane
->fbdev
;
827 struct lcd_panel
*panel
= fbdev
->panel
;
828 struct omapfb_plane_info old_info
;
831 if (pi
->pos_x
+ pi
->out_width
> panel
->x_res
||
832 pi
->pos_y
+ pi
->out_height
> panel
->y_res
)
835 omapfb_rqueue_lock(fbdev
);
836 if (pi
->enabled
&& !fbdev
->mem_desc
.region
[plane
->idx
].size
) {
838 * This plane's memory was freed, can't enable it
839 * until it's reallocated.
844 old_info
= plane
->info
;
847 r
= ctrl_change_mode(fbi
);
849 plane
->info
= old_info
;
853 r
= fbdev
->ctrl
->enable_plane(plane
->idx
, pi
->enabled
);
855 plane
->info
= old_info
;
859 omapfb_rqueue_unlock(fbdev
);
863 static int omapfb_query_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
865 struct omapfb_plane_struct
*plane
= fbi
->par
;
871 static int omapfb_setup_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
873 struct omapfb_plane_struct
*plane
= fbi
->par
;
874 struct omapfb_device
*fbdev
= plane
->fbdev
;
875 struct omapfb_mem_region
*rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
879 if (fbdev
->ctrl
->setup_mem
== NULL
)
881 if (mi
->type
> OMAPFB_MEMTYPE_MAX
)
884 size
= PAGE_ALIGN(mi
->size
);
885 omapfb_rqueue_lock(fbdev
);
886 if (plane
->info
.enabled
) {
890 if (rg
->size
!= size
|| rg
->type
!= mi
->type
) {
891 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
892 unsigned long old_size
= rg
->size
;
893 u8 old_type
= rg
->type
;
899 * size == 0 is a special case, for which we
900 * don't check / adjust the screen parameters.
901 * This isn't a problem since the plane can't
902 * be reenabled unless its size is > 0.
904 if (old_size
!= size
&& size
) {
906 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
907 r
= set_fb_var(fbi
, new_var
);
913 if (fbdev
->ctrl
->sync
)
915 r
= fbdev
->ctrl
->setup_mem(plane
->idx
, size
, mi
->type
, &paddr
);
917 /* Revert changes. */
924 if (old_size
!= size
) {
926 memcpy(&fbi
->var
, new_var
, sizeof(fbi
->var
));
930 * Set these explicitly to indicate that the
931 * plane memory is dealloce'd, the other
932 * screen parameters in var / fix are invalid.
934 mutex_lock(&fbi
->mm_lock
);
935 fbi
->fix
.smem_start
= 0;
936 fbi
->fix
.smem_len
= 0;
937 mutex_unlock(&fbi
->mm_lock
);
942 omapfb_rqueue_unlock(fbdev
);
947 static int omapfb_query_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
949 struct omapfb_plane_struct
*plane
= fbi
->par
;
950 struct omapfb_device
*fbdev
= plane
->fbdev
;
951 struct omapfb_mem_region
*rg
;
953 rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
954 memset(mi
, 0, sizeof(*mi
));
961 static int omapfb_set_color_key(struct omapfb_device
*fbdev
,
962 struct omapfb_color_key
*ck
)
966 if (!fbdev
->ctrl
->set_color_key
)
969 omapfb_rqueue_lock(fbdev
);
970 r
= fbdev
->ctrl
->set_color_key(ck
);
971 omapfb_rqueue_unlock(fbdev
);
976 static int omapfb_get_color_key(struct omapfb_device
*fbdev
,
977 struct omapfb_color_key
*ck
)
981 if (!fbdev
->ctrl
->get_color_key
)
984 omapfb_rqueue_lock(fbdev
);
985 r
= fbdev
->ctrl
->get_color_key(ck
);
986 omapfb_rqueue_unlock(fbdev
);
991 static struct blocking_notifier_head omapfb_client_list
[OMAPFB_PLANE_NUM
];
992 static int notifier_inited
;
994 static void omapfb_init_notifier(void)
998 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
999 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list
[i
]);
1002 int omapfb_register_client(struct omapfb_notifier_block
*omapfb_nb
,
1003 omapfb_notifier_callback_t callback
,
1004 void *callback_data
)
1008 if ((unsigned)omapfb_nb
->plane_idx
> OMAPFB_PLANE_NUM
)
1011 if (!notifier_inited
) {
1012 omapfb_init_notifier();
1013 notifier_inited
= 1;
1016 omapfb_nb
->nb
.notifier_call
= (int (*)(struct notifier_block
*,
1017 unsigned long, void *))callback
;
1018 omapfb_nb
->data
= callback_data
;
1019 r
= blocking_notifier_chain_register(
1020 &omapfb_client_list
[omapfb_nb
->plane_idx
],
1024 if (omapfb_dev
!= NULL
&&
1025 omapfb_dev
->ctrl
&& omapfb_dev
->ctrl
->bind_client
) {
1026 omapfb_dev
->ctrl
->bind_client(omapfb_nb
);
1031 EXPORT_SYMBOL(omapfb_register_client
);
1033 int omapfb_unregister_client(struct omapfb_notifier_block
*omapfb_nb
)
1035 return blocking_notifier_chain_unregister(
1036 &omapfb_client_list
[omapfb_nb
->plane_idx
], &omapfb_nb
->nb
);
1038 EXPORT_SYMBOL(omapfb_unregister_client
);
1040 void omapfb_notify_clients(struct omapfb_device
*fbdev
, unsigned long event
)
1044 if (!notifier_inited
)
1045 /* no client registered yet */
1048 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
1049 blocking_notifier_call_chain(&omapfb_client_list
[i
], event
,
1052 EXPORT_SYMBOL(omapfb_notify_clients
);
1054 static int omapfb_set_update_mode(struct omapfb_device
*fbdev
,
1055 enum omapfb_update_mode mode
)
1059 omapfb_rqueue_lock(fbdev
);
1060 r
= fbdev
->ctrl
->set_update_mode(mode
);
1061 omapfb_rqueue_unlock(fbdev
);
1066 static enum omapfb_update_mode
omapfb_get_update_mode(struct omapfb_device
*fbdev
)
1070 omapfb_rqueue_lock(fbdev
);
1071 r
= fbdev
->ctrl
->get_update_mode();
1072 omapfb_rqueue_unlock(fbdev
);
1077 static void omapfb_get_caps(struct omapfb_device
*fbdev
, int plane
,
1078 struct omapfb_caps
*caps
)
1080 memset(caps
, 0, sizeof(*caps
));
1081 fbdev
->ctrl
->get_caps(plane
, caps
);
1082 caps
->ctrl
|= fbdev
->panel
->get_caps(fbdev
->panel
);
1085 /* For lcd testing */
1086 void omapfb_write_first_pixel(struct omapfb_device
*fbdev
, u16 pixval
)
1088 omapfb_rqueue_lock(fbdev
);
1089 *(u16
*)fbdev
->mem_desc
.region
[0].vaddr
= pixval
;
1090 if (fbdev
->ctrl
->get_update_mode() == OMAPFB_MANUAL_UPDATE
) {
1091 struct omapfb_update_window win
;
1093 memset(&win
, 0, sizeof(win
));
1098 fbdev
->ctrl
->update_window(fbdev
->fb_info
[0], &win
, NULL
, NULL
);
1100 omapfb_rqueue_unlock(fbdev
);
1102 EXPORT_SYMBOL(omapfb_write_first_pixel
);
1105 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1106 * here to be accessible by user mode code.
1108 static int omapfb_ioctl(struct fb_info
*fbi
, unsigned int cmd
,
1111 struct omapfb_plane_struct
*plane
= fbi
->par
;
1112 struct omapfb_device
*fbdev
= plane
->fbdev
;
1113 struct fb_ops
*ops
= fbi
->fbops
;
1115 struct omapfb_update_window update_window
;
1116 struct omapfb_plane_info plane_info
;
1117 struct omapfb_mem_info mem_info
;
1118 struct omapfb_color_key color_key
;
1119 enum omapfb_update_mode update_mode
;
1120 struct omapfb_caps caps
;
1121 unsigned int mirror
;
1130 if (get_user(p
.mirror
, (int __user
*)arg
))
1133 omapfb_mirror(fbi
, p
.mirror
);
1135 case OMAPFB_SYNC_GFX
:
1140 case OMAPFB_SET_UPDATE_MODE
:
1141 if (get_user(p
.update_mode
, (int __user
*)arg
))
1144 r
= omapfb_set_update_mode(fbdev
, p
.update_mode
);
1146 case OMAPFB_GET_UPDATE_MODE
:
1147 p
.update_mode
= omapfb_get_update_mode(fbdev
);
1148 if (put_user(p
.update_mode
,
1149 (enum omapfb_update_mode __user
*)arg
))
1152 case OMAPFB_UPDATE_WINDOW_OLD
:
1153 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1154 sizeof(struct omapfb_update_window_old
)))
1157 struct omapfb_update_window
*u
= &p
.update_window
;
1160 u
->out_width
= u
->width
;
1161 u
->out_height
= u
->height
;
1162 memset(u
->reserved
, 0, sizeof(u
->reserved
));
1163 r
= omapfb_update_win(fbi
, u
);
1166 case OMAPFB_UPDATE_WINDOW
:
1167 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1168 sizeof(p
.update_window
)))
1171 r
= omapfb_update_win(fbi
, &p
.update_window
);
1173 case OMAPFB_SETUP_PLANE
:
1174 if (copy_from_user(&p
.plane_info
, (void __user
*)arg
,
1175 sizeof(p
.plane_info
)))
1178 r
= omapfb_setup_plane(fbi
, &p
.plane_info
);
1180 case OMAPFB_QUERY_PLANE
:
1181 if ((r
= omapfb_query_plane(fbi
, &p
.plane_info
)) < 0)
1183 if (copy_to_user((void __user
*)arg
, &p
.plane_info
,
1184 sizeof(p
.plane_info
)))
1187 case OMAPFB_SETUP_MEM
:
1188 if (copy_from_user(&p
.mem_info
, (void __user
*)arg
,
1189 sizeof(p
.mem_info
)))
1192 r
= omapfb_setup_mem(fbi
, &p
.mem_info
);
1194 case OMAPFB_QUERY_MEM
:
1195 if ((r
= omapfb_query_mem(fbi
, &p
.mem_info
)) < 0)
1197 if (copy_to_user((void __user
*)arg
, &p
.mem_info
,
1198 sizeof(p
.mem_info
)))
1201 case OMAPFB_SET_COLOR_KEY
:
1202 if (copy_from_user(&p
.color_key
, (void __user
*)arg
,
1203 sizeof(p
.color_key
)))
1206 r
= omapfb_set_color_key(fbdev
, &p
.color_key
);
1208 case OMAPFB_GET_COLOR_KEY
:
1209 if ((r
= omapfb_get_color_key(fbdev
, &p
.color_key
)) < 0)
1211 if (copy_to_user((void __user
*)arg
, &p
.color_key
,
1212 sizeof(p
.color_key
)))
1215 case OMAPFB_GET_CAPS
:
1216 omapfb_get_caps(fbdev
, plane
->idx
, &p
.caps
);
1217 if (copy_to_user((void __user
*)arg
, &p
.caps
, sizeof(p
.caps
)))
1220 case OMAPFB_LCD_TEST
:
1224 if (get_user(test_num
, (int __user
*)arg
)) {
1228 if (!fbdev
->panel
->run_test
) {
1232 r
= fbdev
->panel
->run_test(fbdev
->panel
, test_num
);
1235 case OMAPFB_CTRL_TEST
:
1239 if (get_user(test_num
, (int __user
*)arg
)) {
1243 if (!fbdev
->ctrl
->run_test
) {
1247 r
= fbdev
->ctrl
->run_test(test_num
);
1257 static int omapfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1259 struct omapfb_plane_struct
*plane
= info
->par
;
1260 struct omapfb_device
*fbdev
= plane
->fbdev
;
1263 omapfb_rqueue_lock(fbdev
);
1264 r
= fbdev
->ctrl
->mmap(info
, vma
);
1265 omapfb_rqueue_unlock(fbdev
);
1271 * Callback table for the frame buffer framework. Some of these pointers
1272 * will be changed according to the current setting of fb_info->accel_flags.
1274 static struct fb_ops omapfb_ops
= {
1275 .owner
= THIS_MODULE
,
1276 .fb_open
= omapfb_open
,
1277 .fb_release
= omapfb_release
,
1278 .fb_setcolreg
= omapfb_setcolreg
,
1279 .fb_setcmap
= omapfb_setcmap
,
1280 .fb_fillrect
= cfb_fillrect
,
1281 .fb_copyarea
= cfb_copyarea
,
1282 .fb_imageblit
= cfb_imageblit
,
1283 .fb_blank
= omapfb_blank
,
1284 .fb_ioctl
= omapfb_ioctl
,
1285 .fb_check_var
= omapfb_check_var
,
1286 .fb_set_par
= omapfb_set_par
,
1287 .fb_rotate
= omapfb_rotate
,
1288 .fb_pan_display
= omapfb_pan_display
,
1292 * ---------------------------------------------------------------------------
1294 * ---------------------------------------------------------------------------
1296 /* omapfbX sysfs entries */
1297 static ssize_t
omapfb_show_caps_num(struct device
*dev
,
1298 struct device_attribute
*attr
, char *buf
)
1300 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1303 struct omapfb_caps caps
;
1307 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1308 omapfb_get_caps(fbdev
, plane
, &caps
);
1309 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1310 "plane#%d %#010x %#010x %#010x\n",
1311 plane
, caps
.ctrl
, caps
.plane_color
, caps
.wnd_color
);
1317 static ssize_t
omapfb_show_caps_text(struct device
*dev
,
1318 struct device_attribute
*attr
, char *buf
)
1320 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1322 struct omapfb_caps caps
;
1328 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1329 omapfb_get_caps(fbdev
, plane
, &caps
);
1330 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1331 "plane#%d:\n", plane
);
1332 for (i
= 0; i
< ARRAY_SIZE(ctrl_caps
) &&
1333 size
< PAGE_SIZE
; i
++) {
1334 if (ctrl_caps
[i
].flag
& caps
.ctrl
)
1335 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1336 " %s\n", ctrl_caps
[i
].name
);
1338 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1339 " plane colors:\n");
1340 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1341 size
< PAGE_SIZE
; i
++) {
1342 if (color_caps
[i
].flag
& caps
.plane_color
)
1343 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1344 " %s\n", color_caps
[i
].name
);
1346 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1347 " window colors:\n");
1348 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1349 size
< PAGE_SIZE
; i
++) {
1350 if (color_caps
[i
].flag
& caps
.wnd_color
)
1351 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1352 " %s\n", color_caps
[i
].name
);
1360 static DEVICE_ATTR(caps_num
, 0444, omapfb_show_caps_num
, NULL
);
1361 static DEVICE_ATTR(caps_text
, 0444, omapfb_show_caps_text
, NULL
);
1363 /* panel sysfs entries */
1364 static ssize_t
omapfb_show_panel_name(struct device
*dev
,
1365 struct device_attribute
*attr
, char *buf
)
1367 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1369 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->panel
->name
);
1372 static ssize_t
omapfb_show_bklight_level(struct device
*dev
,
1373 struct device_attribute
*attr
,
1376 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1379 if (fbdev
->panel
->get_bklight_level
) {
1380 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1381 fbdev
->panel
->get_bklight_level(fbdev
->panel
));
1387 static ssize_t
omapfb_store_bklight_level(struct device
*dev
,
1388 struct device_attribute
*attr
,
1389 const char *buf
, size_t size
)
1391 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1394 if (fbdev
->panel
->set_bklight_level
) {
1397 if (sscanf(buf
, "%10d", &level
) == 1) {
1398 r
= fbdev
->panel
->set_bklight_level(fbdev
->panel
,
1404 return r
? r
: size
;
1407 static ssize_t
omapfb_show_bklight_max(struct device
*dev
,
1408 struct device_attribute
*attr
, char *buf
)
1410 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1413 if (fbdev
->panel
->get_bklight_level
) {
1414 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1415 fbdev
->panel
->get_bklight_max(fbdev
->panel
));
1421 static struct device_attribute dev_attr_panel_name
=
1422 __ATTR(name
, 0444, omapfb_show_panel_name
, NULL
);
1423 static DEVICE_ATTR(backlight_level
, 0664,
1424 omapfb_show_bklight_level
, omapfb_store_bklight_level
);
1425 static DEVICE_ATTR(backlight_max
, 0444, omapfb_show_bklight_max
, NULL
);
1427 static struct attribute
*panel_attrs
[] = {
1428 &dev_attr_panel_name
.attr
,
1429 &dev_attr_backlight_level
.attr
,
1430 &dev_attr_backlight_max
.attr
,
1434 static struct attribute_group panel_attr_grp
= {
1436 .attrs
= panel_attrs
,
1439 /* ctrl sysfs entries */
1440 static ssize_t
omapfb_show_ctrl_name(struct device
*dev
,
1441 struct device_attribute
*attr
, char *buf
)
1443 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1445 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->ctrl
->name
);
1448 static struct device_attribute dev_attr_ctrl_name
=
1449 __ATTR(name
, 0444, omapfb_show_ctrl_name
, NULL
);
1451 static struct attribute
*ctrl_attrs
[] = {
1452 &dev_attr_ctrl_name
.attr
,
1456 static struct attribute_group ctrl_attr_grp
= {
1458 .attrs
= ctrl_attrs
,
1461 static int omapfb_register_sysfs(struct omapfb_device
*fbdev
)
1465 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_num
)))
1468 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_text
)))
1471 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &panel_attr_grp
)))
1474 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
)))
1479 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1481 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1483 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1485 dev_err(fbdev
->dev
, "unable to register sysfs interface\n");
1489 static void omapfb_unregister_sysfs(struct omapfb_device
*fbdev
)
1491 sysfs_remove_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
);
1492 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1493 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1494 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1498 * ---------------------------------------------------------------------------
1500 * ---------------------------------------------------------------------------
1502 /* Initialize system fb_info object and set the default video mode.
1503 * The frame buffer memory already allocated by lcddma_init
1505 static int fbinfo_init(struct omapfb_device
*fbdev
, struct fb_info
*info
)
1507 struct fb_var_screeninfo
*var
= &info
->var
;
1508 struct fb_fix_screeninfo
*fix
= &info
->fix
;
1511 info
->fbops
= &omapfb_ops
;
1512 info
->flags
= FBINFO_FLAG_DEFAULT
;
1514 strncpy(fix
->id
, MODULE_NAME
, sizeof(fix
->id
));
1516 info
->pseudo_palette
= fbdev
->pseudo_palette
;
1518 var
->accel_flags
= def_accel
? FB_ACCELF_TEXT
: 0;
1519 var
->xres
= def_vxres
;
1520 var
->yres
= def_vyres
;
1521 var
->xres_virtual
= def_vxres
;
1522 var
->yres_virtual
= def_vyres
;
1523 var
->rotate
= def_rotate
;
1524 var
->bits_per_pixel
= fbdev
->panel
->bpp
;
1526 set_fb_var(info
, var
);
1527 set_fb_fix(info
, 1);
1529 r
= fb_alloc_cmap(&info
->cmap
, 16, 0);
1531 dev_err(fbdev
->dev
, "unable to allocate color map memory\n");
1536 /* Release the fb_info object */
1537 static void fbinfo_cleanup(struct omapfb_device
*fbdev
, struct fb_info
*fbi
)
1539 fb_dealloc_cmap(&fbi
->cmap
);
1542 static void planes_cleanup(struct omapfb_device
*fbdev
)
1546 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1547 if (fbdev
->fb_info
[i
] == NULL
)
1549 fbinfo_cleanup(fbdev
, fbdev
->fb_info
[i
]);
1550 framebuffer_release(fbdev
->fb_info
[i
]);
1554 static int planes_init(struct omapfb_device
*fbdev
)
1556 struct fb_info
*fbi
;
1560 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1561 struct omapfb_plane_struct
*plane
;
1562 fbi
= framebuffer_alloc(sizeof(struct omapfb_plane_struct
),
1566 "unable to allocate memory for plane info\n");
1567 planes_cleanup(fbdev
);
1572 plane
->fbdev
= fbdev
;
1573 plane
->info
.mirror
= def_mirror
;
1574 fbdev
->fb_info
[i
] = fbi
;
1576 if ((r
= fbinfo_init(fbdev
, fbi
)) < 0) {
1577 framebuffer_release(fbi
);
1578 planes_cleanup(fbdev
);
1581 plane
->info
.out_width
= fbi
->var
.xres
;
1582 plane
->info
.out_height
= fbi
->var
.yres
;
1588 * Free driver resources. Can be called to rollback an aborted initialization
1591 static void omapfb_free_resources(struct omapfb_device
*fbdev
, int state
)
1597 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++)
1598 unregister_framebuffer(fbdev
->fb_info
[i
]);
1600 omapfb_unregister_sysfs(fbdev
);
1602 fbdev
->panel
->disable(fbdev
->panel
);
1604 omapfb_set_update_mode(fbdev
, OMAPFB_UPDATE_DISABLED
);
1606 planes_cleanup(fbdev
);
1608 ctrl_cleanup(fbdev
);
1610 fbdev
->panel
->cleanup(fbdev
->panel
);
1612 dev_set_drvdata(fbdev
->dev
, NULL
);
1615 /* nothing to free */
1622 static int omapfb_find_ctrl(struct omapfb_device
*fbdev
)
1624 struct omapfb_platform_data
*conf
;
1628 conf
= fbdev
->dev
->platform_data
;
1632 strncpy(name
, conf
->lcd
.ctrl_name
, sizeof(name
) - 1);
1633 name
[sizeof(name
) - 1] = '\0';
1635 if (strcmp(name
, "internal") == 0) {
1636 fbdev
->ctrl
= fbdev
->int_ctrl
;
1640 for (i
= 0; i
< ARRAY_SIZE(ctrls
); i
++) {
1641 dev_dbg(fbdev
->dev
, "ctrl %s\n", ctrls
[i
]->name
);
1642 if (strcmp(ctrls
[i
]->name
, name
) == 0) {
1643 fbdev
->ctrl
= ctrls
[i
];
1648 if (fbdev
->ctrl
== NULL
) {
1649 dev_dbg(fbdev
->dev
, "ctrl %s not supported\n", name
);
1656 static void check_required_callbacks(struct omapfb_device
*fbdev
)
1658 #define _C(x) (fbdev->ctrl->x != NULL)
1659 #define _P(x) (fbdev->panel->x != NULL)
1660 BUG_ON(fbdev
->ctrl
== NULL
|| fbdev
->panel
== NULL
);
1661 BUG_ON(!(_C(init
) && _C(cleanup
) && _C(get_caps
) &&
1662 _C(set_update_mode
) && _C(setup_plane
) && _C(enable_plane
) &&
1663 _P(init
) && _P(cleanup
) && _P(enable
) && _P(disable
) &&
1670 * Called by LDM binding to probe and attach a new device.
1671 * Initialization sequence:
1672 * 1. allocate system omapfb_device structure
1673 * 2. select controller type according to platform configuration
1675 * 3. init LCD controller and LCD DMA
1676 * 4. init system fb_info structure for all planes
1677 * 5. setup video mode for first plane and enable it
1678 * 6. enable LCD panel
1679 * 7. register sysfs attributes
1680 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1682 static int omapfb_do_probe(struct platform_device
*pdev
,
1683 struct lcd_panel
*panel
)
1685 struct omapfb_device
*fbdev
= NULL
;
1687 unsigned long phz
, hhz
, vhz
;
1694 if (pdev
->num_resources
!= 0) {
1695 dev_err(&pdev
->dev
, "probed for an unknown device\n");
1700 if (pdev
->dev
.platform_data
== NULL
) {
1701 dev_err(&pdev
->dev
, "missing platform data\n");
1706 fbdev
= kzalloc(sizeof(struct omapfb_device
), GFP_KERNEL
);
1707 if (fbdev
== NULL
) {
1709 "unable to allocate memory for device info\n");
1715 fbdev
->dev
= &pdev
->dev
;
1716 fbdev
->panel
= panel
;
1717 fbdev
->dssdev
= &omapdss_device
;
1718 platform_set_drvdata(pdev
, fbdev
);
1720 mutex_init(&fbdev
->rqueue_mutex
);
1722 #ifdef CONFIG_ARCH_OMAP1
1723 fbdev
->int_ctrl
= &omap1_int_ctrl
;
1724 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1725 fbdev
->ext_if
= &omap1_ext_if
;
1728 fbdev
->int_ctrl
= &omap2_int_ctrl
;
1729 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1730 fbdev
->ext_if
= &omap2_ext_if
;
1733 if (omapfb_find_ctrl(fbdev
) < 0) {
1735 "LCD controller not found, board not supported\n");
1740 r
= fbdev
->panel
->init(fbdev
->panel
, fbdev
);
1744 pr_info("omapfb: configured for panel %s\n", fbdev
->panel
->name
);
1746 def_vxres
= def_vxres
? def_vxres
: fbdev
->panel
->x_res
;
1747 def_vyres
= def_vyres
? def_vyres
: fbdev
->panel
->y_res
;
1751 r
= ctrl_init(fbdev
);
1754 if (fbdev
->ctrl
->mmap
!= NULL
)
1755 omapfb_ops
.fb_mmap
= omapfb_mmap
;
1758 check_required_callbacks(fbdev
);
1760 r
= planes_init(fbdev
);
1765 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1766 /* Set DMA priority for EMIFF access to highest */
1767 if (cpu_class_is_omap1())
1768 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF
, 15);
1771 r
= ctrl_change_mode(fbdev
->fb_info
[0]);
1773 dev_err(fbdev
->dev
, "mode setting failed\n");
1777 /* GFX plane is enabled by default */
1778 r
= fbdev
->ctrl
->enable_plane(OMAPFB_PLANE_GFX
, 1);
1782 omapfb_set_update_mode(fbdev
, manual_update
?
1783 OMAPFB_MANUAL_UPDATE
: OMAPFB_AUTO_UPDATE
);
1786 r
= fbdev
->panel
->enable(fbdev
->panel
);
1791 r
= omapfb_register_sysfs(fbdev
);
1797 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1798 r
= register_framebuffer(fbdev
->fb_info
[i
]);
1801 "registering framebuffer %d failed\n", i
);
1804 vram
+= fbdev
->mem_desc
.region
[i
].size
;
1807 fbdev
->state
= OMAPFB_ACTIVE
;
1809 panel
= fbdev
->panel
;
1810 phz
= panel
->pixel_clock
* 1000;
1811 hhz
= phz
* 10 / (panel
->hfp
+ panel
->x_res
+ panel
->hbp
+ panel
->hsw
);
1812 vhz
= hhz
/ (panel
->vfp
+ panel
->y_res
+ panel
->vbp
+ panel
->vsw
);
1816 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1817 vram
, fbdev
->mem_desc
.region_cnt
);
1818 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1819 "vfreq %lu.%lu Hz\n",
1820 phz
/ 1000, hhz
/ 10000, hhz
% 10, vhz
/ 10, vhz
% 10);
1825 omapfb_free_resources(fbdev
, init_state
);
1830 static int omapfb_probe(struct platform_device
*pdev
)
1834 BUG_ON(fbdev_pdev
!= NULL
);
1836 r
= platform_device_register(&omapdss_device
);
1838 dev_err(&pdev
->dev
, "can't register omapdss device\n");
1842 /* Delay actual initialization until the LCD is registered */
1844 if (fbdev_panel
!= NULL
)
1845 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1849 void omapfb_register_panel(struct lcd_panel
*panel
)
1851 BUG_ON(fbdev_panel
!= NULL
);
1853 fbdev_panel
= panel
;
1854 if (fbdev_pdev
!= NULL
)
1855 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1858 /* Called when the device is being detached from the driver */
1859 static int omapfb_remove(struct platform_device
*pdev
)
1861 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1862 enum omapfb_state saved_state
= fbdev
->state
;
1864 /* FIXME: wait till completion of pending events */
1866 fbdev
->state
= OMAPFB_DISABLED
;
1867 omapfb_free_resources(fbdev
, saved_state
);
1869 platform_device_unregister(&omapdss_device
);
1870 fbdev
->dssdev
= NULL
;
1876 static int omapfb_suspend(struct platform_device
*pdev
, pm_message_t mesg
)
1878 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1881 omapfb_blank(FB_BLANK_POWERDOWN
, fbdev
->fb_info
[0]);
1886 static int omapfb_resume(struct platform_device
*pdev
)
1888 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1891 omapfb_blank(FB_BLANK_UNBLANK
, fbdev
->fb_info
[0]);
1895 static struct platform_driver omapfb_driver
= {
1896 .probe
= omapfb_probe
,
1897 .remove
= omapfb_remove
,
1898 .suspend
= omapfb_suspend
,
1899 .resume
= omapfb_resume
,
1901 .name
= MODULE_NAME
,
1902 .owner
= THIS_MODULE
,
1908 /* Process kernel command line parameters */
1909 static int __init
omapfb_setup(char *options
)
1911 char *this_opt
= NULL
;
1914 pr_debug("omapfb: options %s\n", options
);
1916 if (!options
|| !*options
)
1919 while (!r
&& (this_opt
= strsep(&options
, ",")) != NULL
) {
1920 if (!strncmp(this_opt
, "accel", 5))
1922 else if (!strncmp(this_opt
, "vram:", 5)) {
1925 vram
= (simple_strtoul(this_opt
+ 5, &suffix
, 0));
1926 switch (suffix
[0]) {
1938 pr_debug("omapfb: invalid vram suffix %c\n",
1942 def_vram
[def_vram_cnt
++] = vram
;
1944 else if (!strncmp(this_opt
, "vxres:", 6))
1945 def_vxres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1946 else if (!strncmp(this_opt
, "vyres:", 6))
1947 def_vyres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1948 else if (!strncmp(this_opt
, "rotate:", 7))
1949 def_rotate
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1950 else if (!strncmp(this_opt
, "mirror:", 7))
1951 def_mirror
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1952 else if (!strncmp(this_opt
, "manual_update", 13))
1955 pr_debug("omapfb: invalid option\n");
1965 /* Register both the driver and the device */
1966 static int __init
omapfb_init(void)
1971 if (fb_get_options("omapfb", &option
))
1973 omapfb_setup(option
);
1975 /* Register the driver with LDM */
1976 if (platform_driver_register(&omapfb_driver
)) {
1977 pr_debug("failed to register omapfb driver\n");
1984 static void __exit
omapfb_cleanup(void)
1986 platform_driver_unregister(&omapfb_driver
);
1989 module_param_named(accel
, def_accel
, uint
, 0664);
1990 module_param_array_named(vram
, def_vram
, ulong
, &def_vram_cnt
, 0664);
1991 module_param_named(vxres
, def_vxres
, long, 0664);
1992 module_param_named(vyres
, def_vyres
, long, 0664);
1993 module_param_named(rotate
, def_rotate
, uint
, 0664);
1994 module_param_named(mirror
, def_mirror
, uint
, 0664);
1995 module_param_named(manual_update
, manual_update
, bool, 0664);
1997 module_init(omapfb_init
);
1998 module_exit(omapfb_cleanup
);
2000 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
2001 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
2002 MODULE_LICENSE("GPL");