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/slab.h>
30 #include <linux/uaccess.h>
38 #define MODULE_NAME "omapfb"
40 static unsigned int def_accel
;
41 static unsigned long def_vram
[OMAPFB_PLANE_NUM
];
42 static unsigned int def_vram_cnt
;
43 static unsigned long def_vxres
;
44 static unsigned long def_vyres
;
45 static unsigned int def_rotate
;
46 static unsigned int def_mirror
;
48 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
49 static int manual_update
= 1;
51 static int manual_update
;
54 static struct platform_device
*fbdev_pdev
;
55 static struct lcd_panel
*fbdev_panel
;
56 static struct omapfb_device
*omapfb_dev
;
58 struct caps_table_struct
{
63 static struct caps_table_struct ctrl_caps
[] = {
64 { OMAPFB_CAPS_MANUAL_UPDATE
, "manual update" },
65 { OMAPFB_CAPS_TEARSYNC
, "tearing synchronization" },
66 { OMAPFB_CAPS_PLANE_RELOCATE_MEM
, "relocate plane memory" },
67 { OMAPFB_CAPS_PLANE_SCALE
, "scale plane" },
68 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE
, "pixel double window" },
69 { OMAPFB_CAPS_WINDOW_SCALE
, "scale window" },
70 { OMAPFB_CAPS_WINDOW_OVERLAY
, "overlay window" },
71 { OMAPFB_CAPS_WINDOW_ROTATE
, "rotate window" },
72 { OMAPFB_CAPS_SET_BACKLIGHT
, "backlight setting" },
75 static struct caps_table_struct color_caps
[] = {
76 { 1 << OMAPFB_COLOR_RGB565
, "RGB565", },
77 { 1 << OMAPFB_COLOR_YUV422
, "YUV422", },
78 { 1 << OMAPFB_COLOR_YUV420
, "YUV420", },
79 { 1 << OMAPFB_COLOR_CLUT_8BPP
, "CLUT8", },
80 { 1 << OMAPFB_COLOR_CLUT_4BPP
, "CLUT4", },
81 { 1 << OMAPFB_COLOR_CLUT_2BPP
, "CLUT2", },
82 { 1 << OMAPFB_COLOR_CLUT_1BPP
, "CLUT1", },
83 { 1 << OMAPFB_COLOR_RGB444
, "RGB444", },
84 { 1 << OMAPFB_COLOR_YUY422
, "YUY422", },
87 static void omapdss_release(struct device
*dev
)
91 /* dummy device for clocks */
92 static struct platform_device omapdss_device
= {
96 .release
= omapdss_release
,
101 * ---------------------------------------------------------------------------
103 * ---------------------------------------------------------------------------
105 extern struct lcd_ctrl hwa742_ctrl
;
106 extern struct lcd_ctrl blizzard_ctrl
;
108 static const struct lcd_ctrl
*ctrls
[] = {
109 #ifdef CONFIG_ARCH_OMAP1
115 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
118 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
123 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
124 #ifdef CONFIG_ARCH_OMAP1
125 extern struct lcd_ctrl_extif omap1_ext_if
;
127 extern struct lcd_ctrl_extif omap2_ext_if
;
131 static void omapfb_rqueue_lock(struct omapfb_device
*fbdev
)
133 mutex_lock(&fbdev
->rqueue_mutex
);
136 static void omapfb_rqueue_unlock(struct omapfb_device
*fbdev
)
138 mutex_unlock(&fbdev
->rqueue_mutex
);
142 * ---------------------------------------------------------------------------
143 * LCD controller and LCD DMA
144 * ---------------------------------------------------------------------------
146 /* Lookup table to map elem size to elem type. */
147 static const int dma_elem_type
[] = {
149 OMAP_DMA_DATA_TYPE_S8
,
150 OMAP_DMA_DATA_TYPE_S16
,
152 OMAP_DMA_DATA_TYPE_S32
,
156 * Allocate resources needed for LCD controller and LCD DMA operations. Video
157 * memory is allocated from system memory according to the virtual display
158 * size, except if a bigger memory size is specified explicitly as a kernel
161 static int ctrl_init(struct omapfb_device
*fbdev
)
166 /* kernel/module vram parameters override boot tags/board config */
168 for (i
= 0; i
< def_vram_cnt
; i
++)
169 fbdev
->mem_desc
.region
[i
].size
=
170 PAGE_ALIGN(def_vram
[i
]);
171 fbdev
->mem_desc
.region_cnt
= i
;
173 struct omapfb_platform_data
*conf
;
175 conf
= fbdev
->dev
->platform_data
;
176 fbdev
->mem_desc
= conf
->mem_desc
;
179 if (!fbdev
->mem_desc
.region_cnt
) {
180 struct lcd_panel
*panel
= fbdev
->panel
;
182 int bpp
= panel
->bpp
;
184 /* 12 bpp is packed in 16 bits */
187 def_size
= def_vxres
* def_vyres
* bpp
/ 8;
188 fbdev
->mem_desc
.region_cnt
= 1;
189 fbdev
->mem_desc
.region
[0].size
= PAGE_ALIGN(def_size
);
191 r
= fbdev
->ctrl
->init(fbdev
, 0, &fbdev
->mem_desc
);
193 dev_err(fbdev
->dev
, "controller initialization failed (%d)\n",
199 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
200 dev_dbg(fbdev
->dev
, "region%d phys %08x virt %p size=%lu\n",
202 fbdev
->mem_desc
.region
[i
].paddr
,
203 fbdev
->mem_desc
.region
[i
].vaddr
,
204 fbdev
->mem_desc
.region
[i
].size
);
210 static void ctrl_cleanup(struct omapfb_device
*fbdev
)
212 fbdev
->ctrl
->cleanup();
215 /* Must be called with fbdev->rqueue_mutex held. */
216 static int ctrl_change_mode(struct fb_info
*fbi
)
219 unsigned long offset
;
220 struct omapfb_plane_struct
*plane
= fbi
->par
;
221 struct omapfb_device
*fbdev
= plane
->fbdev
;
222 struct fb_var_screeninfo
*var
= &fbi
->var
;
224 offset
= var
->yoffset
* fbi
->fix
.line_length
+
225 var
->xoffset
* var
->bits_per_pixel
/ 8;
227 if (fbdev
->ctrl
->sync
)
229 r
= fbdev
->ctrl
->setup_plane(plane
->idx
, plane
->info
.channel_out
,
230 offset
, var
->xres_virtual
,
231 plane
->info
.pos_x
, plane
->info
.pos_y
,
232 var
->xres
, var
->yres
, plane
->color_mode
);
236 if (fbdev
->ctrl
->set_rotate
!= NULL
) {
237 r
= fbdev
->ctrl
->set_rotate(var
->rotate
);
242 if (fbdev
->ctrl
->set_scale
!= NULL
)
243 r
= fbdev
->ctrl
->set_scale(plane
->idx
,
244 var
->xres
, var
->yres
,
245 plane
->info
.out_width
,
246 plane
->info
.out_height
);
252 * ---------------------------------------------------------------------------
253 * fbdev framework callbacks and the ioctl interface
254 * ---------------------------------------------------------------------------
256 /* Called each time the omapfb device is opened */
257 static int omapfb_open(struct fb_info
*info
, int user
)
262 static void omapfb_sync(struct fb_info
*info
);
264 /* Called when the omapfb device is closed. We make sure that any pending
265 * gfx DMA operations are ended, before we return. */
266 static int omapfb_release(struct fb_info
*info
, int user
)
272 /* Store a single color palette entry into a pseudo palette or the hardware
273 * palette if one is available. For now we support only 16bpp and thus store
274 * the entry only to the pseudo palette.
276 static int _setcolreg(struct fb_info
*info
, u_int regno
, u_int red
, u_int green
,
277 u_int blue
, u_int transp
, int update_hw_pal
)
279 struct omapfb_plane_struct
*plane
= info
->par
;
280 struct omapfb_device
*fbdev
= plane
->fbdev
;
281 struct fb_var_screeninfo
*var
= &info
->var
;
284 switch (plane
->color_mode
) {
285 case OMAPFB_COLOR_YUV422
:
286 case OMAPFB_COLOR_YUV420
:
287 case OMAPFB_COLOR_YUY422
:
290 case OMAPFB_COLOR_CLUT_8BPP
:
291 case OMAPFB_COLOR_CLUT_4BPP
:
292 case OMAPFB_COLOR_CLUT_2BPP
:
293 case OMAPFB_COLOR_CLUT_1BPP
:
294 if (fbdev
->ctrl
->setcolreg
)
295 r
= fbdev
->ctrl
->setcolreg(regno
, red
, green
, blue
,
296 transp
, update_hw_pal
);
298 case OMAPFB_COLOR_RGB565
:
299 case OMAPFB_COLOR_RGB444
:
310 pal
= ((red
>> (16 - var
->red
.length
)) <<
312 ((green
>> (16 - var
->green
.length
)) <<
314 (blue
>> (16 - var
->blue
.length
));
315 ((u32
*)(info
->pseudo_palette
))[regno
] = pal
;
324 static int omapfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
325 u_int transp
, struct fb_info
*info
)
327 return _setcolreg(info
, regno
, red
, green
, blue
, transp
, 1);
330 static int omapfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
333 u16
*red
, *green
, *blue
, *transp
;
339 transp
= cmap
->transp
;
342 for (count
= 0; count
< cmap
->len
; count
++) {
345 r
= _setcolreg(info
, index
++, *red
++, *green
++, *blue
++, trans
,
346 count
== cmap
->len
- 1);
354 static int omapfb_update_full_screen(struct fb_info
*fbi
);
356 static int omapfb_blank(int blank
, struct fb_info
*fbi
)
358 struct omapfb_plane_struct
*plane
= fbi
->par
;
359 struct omapfb_device
*fbdev
= plane
->fbdev
;
363 omapfb_rqueue_lock(fbdev
);
365 case FB_BLANK_UNBLANK
:
366 if (fbdev
->state
== OMAPFB_SUSPENDED
) {
367 if (fbdev
->ctrl
->resume
)
368 fbdev
->ctrl
->resume();
369 fbdev
->panel
->enable(fbdev
->panel
);
370 fbdev
->state
= OMAPFB_ACTIVE
;
371 if (fbdev
->ctrl
->get_update_mode() ==
372 OMAPFB_MANUAL_UPDATE
)
376 case FB_BLANK_POWERDOWN
:
377 if (fbdev
->state
== OMAPFB_ACTIVE
) {
378 fbdev
->panel
->disable(fbdev
->panel
);
379 if (fbdev
->ctrl
->suspend
)
380 fbdev
->ctrl
->suspend();
381 fbdev
->state
= OMAPFB_SUSPENDED
;
387 omapfb_rqueue_unlock(fbdev
);
389 if (r
== 0 && do_update
)
390 r
= omapfb_update_full_screen(fbi
);
395 static void omapfb_sync(struct fb_info
*fbi
)
397 struct omapfb_plane_struct
*plane
= fbi
->par
;
398 struct omapfb_device
*fbdev
= plane
->fbdev
;
400 omapfb_rqueue_lock(fbdev
);
401 if (fbdev
->ctrl
->sync
)
403 omapfb_rqueue_unlock(fbdev
);
407 * Set fb_info.fix fields and also updates fbdev.
408 * When calling this fb_info.var must be set up already.
410 static void set_fb_fix(struct fb_info
*fbi
, int from_init
)
412 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
413 struct fb_var_screeninfo
*var
= &fbi
->var
;
414 struct omapfb_plane_struct
*plane
= fbi
->par
;
415 struct omapfb_mem_region
*rg
;
418 rg
= &plane
->fbdev
->mem_desc
.region
[plane
->idx
];
419 fbi
->screen_base
= rg
->vaddr
;
422 mutex_lock(&fbi
->mm_lock
);
423 fix
->smem_start
= rg
->paddr
;
424 fix
->smem_len
= rg
->size
;
425 mutex_unlock(&fbi
->mm_lock
);
427 fix
->smem_start
= rg
->paddr
;
428 fix
->smem_len
= rg
->size
;
431 fix
->type
= FB_TYPE_PACKED_PIXELS
;
432 bpp
= var
->bits_per_pixel
;
434 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
435 else switch (var
->bits_per_pixel
) {
438 fix
->visual
= FB_VISUAL_TRUECOLOR
;
439 /* 12bpp is stored in 16 bits */
446 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
449 fix
->accel
= FB_ACCEL_OMAP1610
;
450 fix
->line_length
= var
->xres_virtual
* bpp
/ 8;
453 static int set_color_mode(struct omapfb_plane_struct
*plane
,
454 struct fb_var_screeninfo
*var
)
456 switch (var
->nonstd
) {
459 case OMAPFB_COLOR_YUV422
:
460 var
->bits_per_pixel
= 16;
461 plane
->color_mode
= var
->nonstd
;
463 case OMAPFB_COLOR_YUV420
:
464 var
->bits_per_pixel
= 12;
465 plane
->color_mode
= var
->nonstd
;
467 case OMAPFB_COLOR_YUY422
:
468 var
->bits_per_pixel
= 16;
469 plane
->color_mode
= var
->nonstd
;
475 switch (var
->bits_per_pixel
) {
477 plane
->color_mode
= OMAPFB_COLOR_CLUT_1BPP
;
480 plane
->color_mode
= OMAPFB_COLOR_CLUT_2BPP
;
483 plane
->color_mode
= OMAPFB_COLOR_CLUT_4BPP
;
486 plane
->color_mode
= OMAPFB_COLOR_CLUT_8BPP
;
489 var
->bits_per_pixel
= 16;
491 if (plane
->fbdev
->panel
->bpp
== 12)
492 plane
->color_mode
= OMAPFB_COLOR_RGB444
;
494 plane
->color_mode
= OMAPFB_COLOR_RGB565
;
502 * Check the values in var against our capabilities and in case of out of
503 * bound values try to adjust them.
505 static int set_fb_var(struct fb_info
*fbi
,
506 struct fb_var_screeninfo
*var
)
509 unsigned long max_frame_size
;
510 unsigned long line_size
;
511 int xres_min
, xres_max
;
512 int yres_min
, yres_max
;
513 struct omapfb_plane_struct
*plane
= fbi
->par
;
514 struct omapfb_device
*fbdev
= plane
->fbdev
;
515 struct lcd_panel
*panel
= fbdev
->panel
;
517 if (set_color_mode(plane
, var
) < 0)
520 bpp
= var
->bits_per_pixel
;
521 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
)
524 switch (var
->rotate
) {
527 xres_min
= OMAPFB_PLANE_XRES_MIN
;
528 xres_max
= panel
->x_res
;
529 yres_min
= OMAPFB_PLANE_YRES_MIN
;
530 yres_max
= panel
->y_res
;
531 if (cpu_is_omap15xx()) {
532 var
->xres
= panel
->x_res
;
533 var
->yres
= panel
->y_res
;
538 xres_min
= OMAPFB_PLANE_YRES_MIN
;
539 xres_max
= panel
->y_res
;
540 yres_min
= OMAPFB_PLANE_XRES_MIN
;
541 yres_max
= panel
->x_res
;
542 if (cpu_is_omap15xx()) {
543 var
->xres
= panel
->y_res
;
544 var
->yres
= panel
->x_res
;
551 if (var
->xres
< xres_min
)
552 var
->xres
= xres_min
;
553 if (var
->yres
< yres_min
)
554 var
->yres
= yres_min
;
555 if (var
->xres
> xres_max
)
556 var
->xres
= xres_max
;
557 if (var
->yres
> yres_max
)
558 var
->yres
= yres_max
;
560 if (var
->xres_virtual
< var
->xres
)
561 var
->xres_virtual
= var
->xres
;
562 if (var
->yres_virtual
< var
->yres
)
563 var
->yres_virtual
= var
->yres
;
564 max_frame_size
= fbdev
->mem_desc
.region
[plane
->idx
].size
;
565 line_size
= var
->xres_virtual
* bpp
/ 8;
566 if (line_size
* var
->yres_virtual
> max_frame_size
) {
567 /* Try to keep yres_virtual first */
568 line_size
= max_frame_size
/ var
->yres_virtual
;
569 var
->xres_virtual
= line_size
* 8 / bpp
;
570 if (var
->xres_virtual
< var
->xres
) {
571 /* Still doesn't fit. Shrink yres_virtual too */
572 var
->xres_virtual
= var
->xres
;
573 line_size
= var
->xres
* bpp
/ 8;
574 var
->yres_virtual
= max_frame_size
/ line_size
;
576 /* Recheck this, as the virtual size changed. */
577 if (var
->xres_virtual
< var
->xres
)
578 var
->xres
= var
->xres_virtual
;
579 if (var
->yres_virtual
< var
->yres
)
580 var
->yres
= var
->yres_virtual
;
581 if (var
->xres
< xres_min
|| var
->yres
< yres_min
)
584 if (var
->xres
+ var
->xoffset
> var
->xres_virtual
)
585 var
->xoffset
= var
->xres_virtual
- var
->xres
;
586 if (var
->yres
+ var
->yoffset
> var
->yres_virtual
)
587 var
->yoffset
= var
->yres_virtual
- var
->yres
;
589 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
) {
590 var
->red
.offset
= 8; var
->red
.length
= 4;
591 var
->red
.msb_right
= 0;
592 var
->green
.offset
= 4; var
->green
.length
= 4;
593 var
->green
.msb_right
= 0;
594 var
->blue
.offset
= 0; var
->blue
.length
= 4;
595 var
->blue
.msb_right
= 0;
597 var
->red
.offset
= 11; var
->red
.length
= 5;
598 var
->red
.msb_right
= 0;
599 var
->green
.offset
= 5; var
->green
.length
= 6;
600 var
->green
.msb_right
= 0;
601 var
->blue
.offset
= 0; var
->blue
.length
= 5;
602 var
->blue
.msb_right
= 0;
609 /* pixclock in ps, the rest in pixclock */
610 var
->pixclock
= 10000000 / (panel
->pixel_clock
/ 100);
611 var
->left_margin
= panel
->hfp
;
612 var
->right_margin
= panel
->hbp
;
613 var
->upper_margin
= panel
->vfp
;
614 var
->lower_margin
= panel
->vbp
;
615 var
->hsync_len
= panel
->hsw
;
616 var
->vsync_len
= panel
->vsw
;
618 /* TODO: get these from panel->config */
619 var
->vmode
= FB_VMODE_NONINTERLACED
;
626 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
627 static void omapfb_rotate(struct fb_info
*fbi
, int rotate
)
629 struct omapfb_plane_struct
*plane
= fbi
->par
;
630 struct omapfb_device
*fbdev
= plane
->fbdev
;
632 omapfb_rqueue_lock(fbdev
);
633 if (rotate
!= fbi
->var
.rotate
) {
634 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
636 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
637 new_var
->rotate
= rotate
;
638 if (set_fb_var(fbi
, new_var
) == 0 &&
639 memcmp(new_var
, &fbi
->var
, sizeof(*new_var
))) {
640 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
641 ctrl_change_mode(fbi
);
644 omapfb_rqueue_unlock(fbdev
);
648 * Set new x,y offsets in the virtual display for the visible area and switch
651 static int omapfb_pan_display(struct fb_var_screeninfo
*var
,
654 struct omapfb_plane_struct
*plane
= fbi
->par
;
655 struct omapfb_device
*fbdev
= plane
->fbdev
;
658 omapfb_rqueue_lock(fbdev
);
659 if (var
->xoffset
!= fbi
->var
.xoffset
||
660 var
->yoffset
!= fbi
->var
.yoffset
) {
661 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
663 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
664 new_var
->xoffset
= var
->xoffset
;
665 new_var
->yoffset
= var
->yoffset
;
666 if (set_fb_var(fbi
, new_var
))
669 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
670 ctrl_change_mode(fbi
);
673 omapfb_rqueue_unlock(fbdev
);
678 /* Set mirror to vertical axis and switch to the new mode. */
679 static int omapfb_mirror(struct fb_info
*fbi
, int mirror
)
681 struct omapfb_plane_struct
*plane
= fbi
->par
;
682 struct omapfb_device
*fbdev
= plane
->fbdev
;
685 omapfb_rqueue_lock(fbdev
);
686 mirror
= mirror
? 1 : 0;
687 if (cpu_is_omap15xx())
689 else if (mirror
!= plane
->info
.mirror
) {
690 plane
->info
.mirror
= mirror
;
691 r
= ctrl_change_mode(fbi
);
693 omapfb_rqueue_unlock(fbdev
);
699 * Check values in var, try to adjust them in case of out of bound values if
700 * possible, or return error.
702 static int omapfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*fbi
)
704 struct omapfb_plane_struct
*plane
= fbi
->par
;
705 struct omapfb_device
*fbdev
= plane
->fbdev
;
708 omapfb_rqueue_lock(fbdev
);
709 if (fbdev
->ctrl
->sync
!= NULL
)
711 r
= set_fb_var(fbi
, var
);
712 omapfb_rqueue_unlock(fbdev
);
718 * Switch to a new mode. The parameters for it has been check already by
721 static int omapfb_set_par(struct fb_info
*fbi
)
723 struct omapfb_plane_struct
*plane
= fbi
->par
;
724 struct omapfb_device
*fbdev
= plane
->fbdev
;
727 omapfb_rqueue_lock(fbdev
);
729 r
= ctrl_change_mode(fbi
);
730 omapfb_rqueue_unlock(fbdev
);
735 int omapfb_update_window_async(struct fb_info
*fbi
,
736 struct omapfb_update_window
*win
,
737 void (*callback
)(void *),
741 struct omapfb_plane_struct
*plane
= fbi
->par
;
742 struct omapfb_device
*fbdev
= plane
->fbdev
;
743 struct fb_var_screeninfo
*var
= &fbi
->var
;
745 switch (var
->rotate
) {
748 xres
= fbdev
->panel
->x_res
;
749 yres
= fbdev
->panel
->y_res
;
753 xres
= fbdev
->panel
->y_res
;
754 yres
= fbdev
->panel
->x_res
;
760 if (win
->x
>= xres
|| win
->y
>= yres
||
761 win
->out_x
> xres
|| win
->out_y
> yres
)
764 if (!fbdev
->ctrl
->update_window
||
765 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
768 if (win
->x
+ win
->width
> xres
)
769 win
->width
= xres
- win
->x
;
770 if (win
->y
+ win
->height
> yres
)
771 win
->height
= yres
- win
->y
;
772 if (win
->out_x
+ win
->out_width
> xres
)
773 win
->out_width
= xres
- win
->out_x
;
774 if (win
->out_y
+ win
->out_height
> yres
)
775 win
->out_height
= yres
- win
->out_y
;
776 if (!win
->width
|| !win
->height
|| !win
->out_width
|| !win
->out_height
)
779 return fbdev
->ctrl
->update_window(fbi
, win
, callback
, callback_data
);
781 EXPORT_SYMBOL(omapfb_update_window_async
);
783 static int omapfb_update_win(struct fb_info
*fbi
,
784 struct omapfb_update_window
*win
)
786 struct omapfb_plane_struct
*plane
= fbi
->par
;
789 omapfb_rqueue_lock(plane
->fbdev
);
790 ret
= omapfb_update_window_async(fbi
, win
, NULL
, NULL
);
791 omapfb_rqueue_unlock(plane
->fbdev
);
796 static int omapfb_update_full_screen(struct fb_info
*fbi
)
798 struct omapfb_plane_struct
*plane
= fbi
->par
;
799 struct omapfb_device
*fbdev
= plane
->fbdev
;
800 struct omapfb_update_window win
;
803 if (!fbdev
->ctrl
->update_window
||
804 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
809 win
.width
= fbi
->var
.xres
;
810 win
.height
= fbi
->var
.yres
;
813 win
.out_width
= fbi
->var
.xres
;
814 win
.out_height
= fbi
->var
.yres
;
817 omapfb_rqueue_lock(fbdev
);
818 r
= fbdev
->ctrl
->update_window(fbi
, &win
, NULL
, NULL
);
819 omapfb_rqueue_unlock(fbdev
);
824 static int omapfb_setup_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
826 struct omapfb_plane_struct
*plane
= fbi
->par
;
827 struct omapfb_device
*fbdev
= plane
->fbdev
;
828 struct lcd_panel
*panel
= fbdev
->panel
;
829 struct omapfb_plane_info old_info
;
832 if (pi
->pos_x
+ pi
->out_width
> panel
->x_res
||
833 pi
->pos_y
+ pi
->out_height
> panel
->y_res
)
836 omapfb_rqueue_lock(fbdev
);
837 if (pi
->enabled
&& !fbdev
->mem_desc
.region
[plane
->idx
].size
) {
839 * This plane's memory was freed, can't enable it
840 * until it's reallocated.
845 old_info
= plane
->info
;
848 r
= ctrl_change_mode(fbi
);
850 plane
->info
= old_info
;
854 r
= fbdev
->ctrl
->enable_plane(plane
->idx
, pi
->enabled
);
856 plane
->info
= old_info
;
860 omapfb_rqueue_unlock(fbdev
);
864 static int omapfb_query_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
866 struct omapfb_plane_struct
*plane
= fbi
->par
;
872 static int omapfb_setup_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
874 struct omapfb_plane_struct
*plane
= fbi
->par
;
875 struct omapfb_device
*fbdev
= plane
->fbdev
;
876 struct omapfb_mem_region
*rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
880 if (fbdev
->ctrl
->setup_mem
== NULL
)
882 if (mi
->type
> OMAPFB_MEMTYPE_MAX
)
885 size
= PAGE_ALIGN(mi
->size
);
886 omapfb_rqueue_lock(fbdev
);
887 if (plane
->info
.enabled
) {
891 if (rg
->size
!= size
|| rg
->type
!= mi
->type
) {
892 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
893 unsigned long old_size
= rg
->size
;
894 u8 old_type
= rg
->type
;
900 * size == 0 is a special case, for which we
901 * don't check / adjust the screen parameters.
902 * This isn't a problem since the plane can't
903 * be reenabled unless its size is > 0.
905 if (old_size
!= size
&& size
) {
907 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
908 r
= set_fb_var(fbi
, new_var
);
914 if (fbdev
->ctrl
->sync
)
916 r
= fbdev
->ctrl
->setup_mem(plane
->idx
, size
, mi
->type
, &paddr
);
918 /* Revert changes. */
925 if (old_size
!= size
) {
927 memcpy(&fbi
->var
, new_var
, sizeof(fbi
->var
));
931 * Set these explicitly to indicate that the
932 * plane memory is dealloce'd, the other
933 * screen parameters in var / fix are invalid.
935 mutex_lock(&fbi
->mm_lock
);
936 fbi
->fix
.smem_start
= 0;
937 fbi
->fix
.smem_len
= 0;
938 mutex_unlock(&fbi
->mm_lock
);
943 omapfb_rqueue_unlock(fbdev
);
948 static int omapfb_query_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
950 struct omapfb_plane_struct
*plane
= fbi
->par
;
951 struct omapfb_device
*fbdev
= plane
->fbdev
;
952 struct omapfb_mem_region
*rg
;
954 rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
955 memset(mi
, 0, sizeof(*mi
));
962 static int omapfb_set_color_key(struct omapfb_device
*fbdev
,
963 struct omapfb_color_key
*ck
)
967 if (!fbdev
->ctrl
->set_color_key
)
970 omapfb_rqueue_lock(fbdev
);
971 r
= fbdev
->ctrl
->set_color_key(ck
);
972 omapfb_rqueue_unlock(fbdev
);
977 static int omapfb_get_color_key(struct omapfb_device
*fbdev
,
978 struct omapfb_color_key
*ck
)
982 if (!fbdev
->ctrl
->get_color_key
)
985 omapfb_rqueue_lock(fbdev
);
986 r
= fbdev
->ctrl
->get_color_key(ck
);
987 omapfb_rqueue_unlock(fbdev
);
992 static struct blocking_notifier_head omapfb_client_list
[OMAPFB_PLANE_NUM
];
993 static int notifier_inited
;
995 static void omapfb_init_notifier(void)
999 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
1000 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list
[i
]);
1003 int omapfb_register_client(struct omapfb_notifier_block
*omapfb_nb
,
1004 omapfb_notifier_callback_t callback
,
1005 void *callback_data
)
1009 if ((unsigned)omapfb_nb
->plane_idx
> OMAPFB_PLANE_NUM
)
1012 if (!notifier_inited
) {
1013 omapfb_init_notifier();
1014 notifier_inited
= 1;
1017 omapfb_nb
->nb
.notifier_call
= (int (*)(struct notifier_block
*,
1018 unsigned long, void *))callback
;
1019 omapfb_nb
->data
= callback_data
;
1020 r
= blocking_notifier_chain_register(
1021 &omapfb_client_list
[omapfb_nb
->plane_idx
],
1025 if (omapfb_dev
!= NULL
&&
1026 omapfb_dev
->ctrl
&& omapfb_dev
->ctrl
->bind_client
) {
1027 omapfb_dev
->ctrl
->bind_client(omapfb_nb
);
1032 EXPORT_SYMBOL(omapfb_register_client
);
1034 int omapfb_unregister_client(struct omapfb_notifier_block
*omapfb_nb
)
1036 return blocking_notifier_chain_unregister(
1037 &omapfb_client_list
[omapfb_nb
->plane_idx
], &omapfb_nb
->nb
);
1039 EXPORT_SYMBOL(omapfb_unregister_client
);
1041 void omapfb_notify_clients(struct omapfb_device
*fbdev
, unsigned long event
)
1045 if (!notifier_inited
)
1046 /* no client registered yet */
1049 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
1050 blocking_notifier_call_chain(&omapfb_client_list
[i
], event
,
1053 EXPORT_SYMBOL(omapfb_notify_clients
);
1055 static int omapfb_set_update_mode(struct omapfb_device
*fbdev
,
1056 enum omapfb_update_mode mode
)
1060 omapfb_rqueue_lock(fbdev
);
1061 r
= fbdev
->ctrl
->set_update_mode(mode
);
1062 omapfb_rqueue_unlock(fbdev
);
1067 static enum omapfb_update_mode
omapfb_get_update_mode(struct omapfb_device
*fbdev
)
1071 omapfb_rqueue_lock(fbdev
);
1072 r
= fbdev
->ctrl
->get_update_mode();
1073 omapfb_rqueue_unlock(fbdev
);
1078 static void omapfb_get_caps(struct omapfb_device
*fbdev
, int plane
,
1079 struct omapfb_caps
*caps
)
1081 memset(caps
, 0, sizeof(*caps
));
1082 fbdev
->ctrl
->get_caps(plane
, caps
);
1083 caps
->ctrl
|= fbdev
->panel
->get_caps(fbdev
->panel
);
1086 /* For lcd testing */
1087 void omapfb_write_first_pixel(struct omapfb_device
*fbdev
, u16 pixval
)
1089 omapfb_rqueue_lock(fbdev
);
1090 *(u16
*)fbdev
->mem_desc
.region
[0].vaddr
= pixval
;
1091 if (fbdev
->ctrl
->get_update_mode() == OMAPFB_MANUAL_UPDATE
) {
1092 struct omapfb_update_window win
;
1094 memset(&win
, 0, sizeof(win
));
1099 fbdev
->ctrl
->update_window(fbdev
->fb_info
[0], &win
, NULL
, NULL
);
1101 omapfb_rqueue_unlock(fbdev
);
1103 EXPORT_SYMBOL(omapfb_write_first_pixel
);
1106 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1107 * here to be accessible by user mode code.
1109 static int omapfb_ioctl(struct fb_info
*fbi
, unsigned int cmd
,
1112 struct omapfb_plane_struct
*plane
= fbi
->par
;
1113 struct omapfb_device
*fbdev
= plane
->fbdev
;
1114 struct fb_ops
*ops
= fbi
->fbops
;
1116 struct omapfb_update_window update_window
;
1117 struct omapfb_plane_info plane_info
;
1118 struct omapfb_mem_info mem_info
;
1119 struct omapfb_color_key color_key
;
1120 enum omapfb_update_mode update_mode
;
1121 struct omapfb_caps caps
;
1122 unsigned int mirror
;
1131 if (get_user(p
.mirror
, (int __user
*)arg
))
1134 omapfb_mirror(fbi
, p
.mirror
);
1136 case OMAPFB_SYNC_GFX
:
1141 case OMAPFB_SET_UPDATE_MODE
:
1142 if (get_user(p
.update_mode
, (int __user
*)arg
))
1145 r
= omapfb_set_update_mode(fbdev
, p
.update_mode
);
1147 case OMAPFB_GET_UPDATE_MODE
:
1148 p
.update_mode
= omapfb_get_update_mode(fbdev
);
1149 if (put_user(p
.update_mode
,
1150 (enum omapfb_update_mode __user
*)arg
))
1153 case OMAPFB_UPDATE_WINDOW_OLD
:
1154 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1155 sizeof(struct omapfb_update_window_old
)))
1158 struct omapfb_update_window
*u
= &p
.update_window
;
1161 u
->out_width
= u
->width
;
1162 u
->out_height
= u
->height
;
1163 memset(u
->reserved
, 0, sizeof(u
->reserved
));
1164 r
= omapfb_update_win(fbi
, u
);
1167 case OMAPFB_UPDATE_WINDOW
:
1168 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1169 sizeof(p
.update_window
)))
1172 r
= omapfb_update_win(fbi
, &p
.update_window
);
1174 case OMAPFB_SETUP_PLANE
:
1175 if (copy_from_user(&p
.plane_info
, (void __user
*)arg
,
1176 sizeof(p
.plane_info
)))
1179 r
= omapfb_setup_plane(fbi
, &p
.plane_info
);
1181 case OMAPFB_QUERY_PLANE
:
1182 if ((r
= omapfb_query_plane(fbi
, &p
.plane_info
)) < 0)
1184 if (copy_to_user((void __user
*)arg
, &p
.plane_info
,
1185 sizeof(p
.plane_info
)))
1188 case OMAPFB_SETUP_MEM
:
1189 if (copy_from_user(&p
.mem_info
, (void __user
*)arg
,
1190 sizeof(p
.mem_info
)))
1193 r
= omapfb_setup_mem(fbi
, &p
.mem_info
);
1195 case OMAPFB_QUERY_MEM
:
1196 if ((r
= omapfb_query_mem(fbi
, &p
.mem_info
)) < 0)
1198 if (copy_to_user((void __user
*)arg
, &p
.mem_info
,
1199 sizeof(p
.mem_info
)))
1202 case OMAPFB_SET_COLOR_KEY
:
1203 if (copy_from_user(&p
.color_key
, (void __user
*)arg
,
1204 sizeof(p
.color_key
)))
1207 r
= omapfb_set_color_key(fbdev
, &p
.color_key
);
1209 case OMAPFB_GET_COLOR_KEY
:
1210 if ((r
= omapfb_get_color_key(fbdev
, &p
.color_key
)) < 0)
1212 if (copy_to_user((void __user
*)arg
, &p
.color_key
,
1213 sizeof(p
.color_key
)))
1216 case OMAPFB_GET_CAPS
:
1217 omapfb_get_caps(fbdev
, plane
->idx
, &p
.caps
);
1218 if (copy_to_user((void __user
*)arg
, &p
.caps
, sizeof(p
.caps
)))
1221 case OMAPFB_LCD_TEST
:
1225 if (get_user(test_num
, (int __user
*)arg
)) {
1229 if (!fbdev
->panel
->run_test
) {
1233 r
= fbdev
->panel
->run_test(fbdev
->panel
, test_num
);
1236 case OMAPFB_CTRL_TEST
:
1240 if (get_user(test_num
, (int __user
*)arg
)) {
1244 if (!fbdev
->ctrl
->run_test
) {
1248 r
= fbdev
->ctrl
->run_test(test_num
);
1258 static int omapfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1260 struct omapfb_plane_struct
*plane
= info
->par
;
1261 struct omapfb_device
*fbdev
= plane
->fbdev
;
1264 omapfb_rqueue_lock(fbdev
);
1265 r
= fbdev
->ctrl
->mmap(info
, vma
);
1266 omapfb_rqueue_unlock(fbdev
);
1272 * Callback table for the frame buffer framework. Some of these pointers
1273 * will be changed according to the current setting of fb_info->accel_flags.
1275 static struct fb_ops omapfb_ops
= {
1276 .owner
= THIS_MODULE
,
1277 .fb_open
= omapfb_open
,
1278 .fb_release
= omapfb_release
,
1279 .fb_setcolreg
= omapfb_setcolreg
,
1280 .fb_setcmap
= omapfb_setcmap
,
1281 .fb_fillrect
= cfb_fillrect
,
1282 .fb_copyarea
= cfb_copyarea
,
1283 .fb_imageblit
= cfb_imageblit
,
1284 .fb_blank
= omapfb_blank
,
1285 .fb_ioctl
= omapfb_ioctl
,
1286 .fb_check_var
= omapfb_check_var
,
1287 .fb_set_par
= omapfb_set_par
,
1288 .fb_rotate
= omapfb_rotate
,
1289 .fb_pan_display
= omapfb_pan_display
,
1293 * ---------------------------------------------------------------------------
1295 * ---------------------------------------------------------------------------
1297 /* omapfbX sysfs entries */
1298 static ssize_t
omapfb_show_caps_num(struct device
*dev
,
1299 struct device_attribute
*attr
, char *buf
)
1301 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1304 struct omapfb_caps caps
;
1308 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1309 omapfb_get_caps(fbdev
, plane
, &caps
);
1310 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1311 "plane#%d %#010x %#010x %#010x\n",
1312 plane
, caps
.ctrl
, caps
.plane_color
, caps
.wnd_color
);
1318 static ssize_t
omapfb_show_caps_text(struct device
*dev
,
1319 struct device_attribute
*attr
, char *buf
)
1321 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1323 struct omapfb_caps caps
;
1329 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1330 omapfb_get_caps(fbdev
, plane
, &caps
);
1331 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1332 "plane#%d:\n", plane
);
1333 for (i
= 0; i
< ARRAY_SIZE(ctrl_caps
) &&
1334 size
< PAGE_SIZE
; i
++) {
1335 if (ctrl_caps
[i
].flag
& caps
.ctrl
)
1336 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1337 " %s\n", ctrl_caps
[i
].name
);
1339 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1340 " plane colors:\n");
1341 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1342 size
< PAGE_SIZE
; i
++) {
1343 if (color_caps
[i
].flag
& caps
.plane_color
)
1344 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1345 " %s\n", color_caps
[i
].name
);
1347 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1348 " window colors:\n");
1349 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1350 size
< PAGE_SIZE
; i
++) {
1351 if (color_caps
[i
].flag
& caps
.wnd_color
)
1352 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1353 " %s\n", color_caps
[i
].name
);
1361 static DEVICE_ATTR(caps_num
, 0444, omapfb_show_caps_num
, NULL
);
1362 static DEVICE_ATTR(caps_text
, 0444, omapfb_show_caps_text
, NULL
);
1364 /* panel sysfs entries */
1365 static ssize_t
omapfb_show_panel_name(struct device
*dev
,
1366 struct device_attribute
*attr
, char *buf
)
1368 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1370 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->panel
->name
);
1373 static ssize_t
omapfb_show_bklight_level(struct device
*dev
,
1374 struct device_attribute
*attr
,
1377 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1380 if (fbdev
->panel
->get_bklight_level
) {
1381 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1382 fbdev
->panel
->get_bklight_level(fbdev
->panel
));
1388 static ssize_t
omapfb_store_bklight_level(struct device
*dev
,
1389 struct device_attribute
*attr
,
1390 const char *buf
, size_t size
)
1392 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1395 if (fbdev
->panel
->set_bklight_level
) {
1398 if (sscanf(buf
, "%10d", &level
) == 1) {
1399 r
= fbdev
->panel
->set_bklight_level(fbdev
->panel
,
1405 return r
? r
: size
;
1408 static ssize_t
omapfb_show_bklight_max(struct device
*dev
,
1409 struct device_attribute
*attr
, char *buf
)
1411 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1414 if (fbdev
->panel
->get_bklight_level
) {
1415 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1416 fbdev
->panel
->get_bklight_max(fbdev
->panel
));
1422 static struct device_attribute dev_attr_panel_name
=
1423 __ATTR(name
, 0444, omapfb_show_panel_name
, NULL
);
1424 static DEVICE_ATTR(backlight_level
, 0664,
1425 omapfb_show_bklight_level
, omapfb_store_bklight_level
);
1426 static DEVICE_ATTR(backlight_max
, 0444, omapfb_show_bklight_max
, NULL
);
1428 static struct attribute
*panel_attrs
[] = {
1429 &dev_attr_panel_name
.attr
,
1430 &dev_attr_backlight_level
.attr
,
1431 &dev_attr_backlight_max
.attr
,
1435 static struct attribute_group panel_attr_grp
= {
1437 .attrs
= panel_attrs
,
1440 /* ctrl sysfs entries */
1441 static ssize_t
omapfb_show_ctrl_name(struct device
*dev
,
1442 struct device_attribute
*attr
, char *buf
)
1444 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1446 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->ctrl
->name
);
1449 static struct device_attribute dev_attr_ctrl_name
=
1450 __ATTR(name
, 0444, omapfb_show_ctrl_name
, NULL
);
1452 static struct attribute
*ctrl_attrs
[] = {
1453 &dev_attr_ctrl_name
.attr
,
1457 static struct attribute_group ctrl_attr_grp
= {
1459 .attrs
= ctrl_attrs
,
1462 static int omapfb_register_sysfs(struct omapfb_device
*fbdev
)
1466 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_num
)))
1469 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_text
)))
1472 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &panel_attr_grp
)))
1475 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
)))
1480 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1482 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1484 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1486 dev_err(fbdev
->dev
, "unable to register sysfs interface\n");
1490 static void omapfb_unregister_sysfs(struct omapfb_device
*fbdev
)
1492 sysfs_remove_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
);
1493 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1494 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1495 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1499 * ---------------------------------------------------------------------------
1501 * ---------------------------------------------------------------------------
1503 /* Initialize system fb_info object and set the default video mode.
1504 * The frame buffer memory already allocated by lcddma_init
1506 static int fbinfo_init(struct omapfb_device
*fbdev
, struct fb_info
*info
)
1508 struct fb_var_screeninfo
*var
= &info
->var
;
1509 struct fb_fix_screeninfo
*fix
= &info
->fix
;
1512 info
->fbops
= &omapfb_ops
;
1513 info
->flags
= FBINFO_FLAG_DEFAULT
;
1515 strncpy(fix
->id
, MODULE_NAME
, sizeof(fix
->id
));
1517 info
->pseudo_palette
= fbdev
->pseudo_palette
;
1519 var
->accel_flags
= def_accel
? FB_ACCELF_TEXT
: 0;
1520 var
->xres
= def_vxres
;
1521 var
->yres
= def_vyres
;
1522 var
->xres_virtual
= def_vxres
;
1523 var
->yres_virtual
= def_vyres
;
1524 var
->rotate
= def_rotate
;
1525 var
->bits_per_pixel
= fbdev
->panel
->bpp
;
1527 set_fb_var(info
, var
);
1528 set_fb_fix(info
, 1);
1530 r
= fb_alloc_cmap(&info
->cmap
, 16, 0);
1532 dev_err(fbdev
->dev
, "unable to allocate color map memory\n");
1537 /* Release the fb_info object */
1538 static void fbinfo_cleanup(struct omapfb_device
*fbdev
, struct fb_info
*fbi
)
1540 fb_dealloc_cmap(&fbi
->cmap
);
1543 static void planes_cleanup(struct omapfb_device
*fbdev
)
1547 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1548 if (fbdev
->fb_info
[i
] == NULL
)
1550 fbinfo_cleanup(fbdev
, fbdev
->fb_info
[i
]);
1551 framebuffer_release(fbdev
->fb_info
[i
]);
1555 static int planes_init(struct omapfb_device
*fbdev
)
1557 struct fb_info
*fbi
;
1561 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1562 struct omapfb_plane_struct
*plane
;
1563 fbi
= framebuffer_alloc(sizeof(struct omapfb_plane_struct
),
1567 "unable to allocate memory for plane info\n");
1568 planes_cleanup(fbdev
);
1573 plane
->fbdev
= fbdev
;
1574 plane
->info
.mirror
= def_mirror
;
1575 fbdev
->fb_info
[i
] = fbi
;
1577 if ((r
= fbinfo_init(fbdev
, fbi
)) < 0) {
1578 framebuffer_release(fbi
);
1579 planes_cleanup(fbdev
);
1582 plane
->info
.out_width
= fbi
->var
.xres
;
1583 plane
->info
.out_height
= fbi
->var
.yres
;
1589 * Free driver resources. Can be called to rollback an aborted initialization
1592 static void omapfb_free_resources(struct omapfb_device
*fbdev
, int state
)
1598 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++)
1599 unregister_framebuffer(fbdev
->fb_info
[i
]);
1601 omapfb_unregister_sysfs(fbdev
);
1603 fbdev
->panel
->disable(fbdev
->panel
);
1605 omapfb_set_update_mode(fbdev
, OMAPFB_UPDATE_DISABLED
);
1607 planes_cleanup(fbdev
);
1609 ctrl_cleanup(fbdev
);
1611 fbdev
->panel
->cleanup(fbdev
->panel
);
1613 dev_set_drvdata(fbdev
->dev
, NULL
);
1616 /* nothing to free */
1623 static int omapfb_find_ctrl(struct omapfb_device
*fbdev
)
1625 struct omapfb_platform_data
*conf
;
1629 conf
= fbdev
->dev
->platform_data
;
1633 strncpy(name
, conf
->lcd
.ctrl_name
, sizeof(name
) - 1);
1634 name
[sizeof(name
) - 1] = '\0';
1636 if (strcmp(name
, "internal") == 0) {
1637 fbdev
->ctrl
= fbdev
->int_ctrl
;
1641 for (i
= 0; i
< ARRAY_SIZE(ctrls
); i
++) {
1642 dev_dbg(fbdev
->dev
, "ctrl %s\n", ctrls
[i
]->name
);
1643 if (strcmp(ctrls
[i
]->name
, name
) == 0) {
1644 fbdev
->ctrl
= ctrls
[i
];
1649 if (fbdev
->ctrl
== NULL
) {
1650 dev_dbg(fbdev
->dev
, "ctrl %s not supported\n", name
);
1657 static void check_required_callbacks(struct omapfb_device
*fbdev
)
1659 #define _C(x) (fbdev->ctrl->x != NULL)
1660 #define _P(x) (fbdev->panel->x != NULL)
1661 BUG_ON(fbdev
->ctrl
== NULL
|| fbdev
->panel
== NULL
);
1662 BUG_ON(!(_C(init
) && _C(cleanup
) && _C(get_caps
) &&
1663 _C(set_update_mode
) && _C(setup_plane
) && _C(enable_plane
) &&
1664 _P(init
) && _P(cleanup
) && _P(enable
) && _P(disable
) &&
1671 * Called by LDM binding to probe and attach a new device.
1672 * Initialization sequence:
1673 * 1. allocate system omapfb_device structure
1674 * 2. select controller type according to platform configuration
1676 * 3. init LCD controller and LCD DMA
1677 * 4. init system fb_info structure for all planes
1678 * 5. setup video mode for first plane and enable it
1679 * 6. enable LCD panel
1680 * 7. register sysfs attributes
1681 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1683 static int omapfb_do_probe(struct platform_device
*pdev
,
1684 struct lcd_panel
*panel
)
1686 struct omapfb_device
*fbdev
= NULL
;
1688 unsigned long phz
, hhz
, vhz
;
1695 if (pdev
->num_resources
!= 0) {
1696 dev_err(&pdev
->dev
, "probed for an unknown device\n");
1701 if (pdev
->dev
.platform_data
== NULL
) {
1702 dev_err(&pdev
->dev
, "missing platform data\n");
1707 fbdev
= kzalloc(sizeof(struct omapfb_device
), GFP_KERNEL
);
1708 if (fbdev
== NULL
) {
1710 "unable to allocate memory for device info\n");
1716 fbdev
->dev
= &pdev
->dev
;
1717 fbdev
->panel
= panel
;
1718 fbdev
->dssdev
= &omapdss_device
;
1719 platform_set_drvdata(pdev
, fbdev
);
1721 mutex_init(&fbdev
->rqueue_mutex
);
1723 #ifdef CONFIG_ARCH_OMAP1
1724 fbdev
->int_ctrl
= &omap1_int_ctrl
;
1725 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1726 fbdev
->ext_if
= &omap1_ext_if
;
1729 fbdev
->int_ctrl
= &omap2_int_ctrl
;
1730 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1731 fbdev
->ext_if
= &omap2_ext_if
;
1734 if (omapfb_find_ctrl(fbdev
) < 0) {
1736 "LCD controller not found, board not supported\n");
1741 r
= fbdev
->panel
->init(fbdev
->panel
, fbdev
);
1745 pr_info("omapfb: configured for panel %s\n", fbdev
->panel
->name
);
1747 def_vxres
= def_vxres
? def_vxres
: fbdev
->panel
->x_res
;
1748 def_vyres
= def_vyres
? def_vyres
: fbdev
->panel
->y_res
;
1752 r
= ctrl_init(fbdev
);
1755 if (fbdev
->ctrl
->mmap
!= NULL
)
1756 omapfb_ops
.fb_mmap
= omapfb_mmap
;
1759 check_required_callbacks(fbdev
);
1761 r
= planes_init(fbdev
);
1766 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1767 /* Set DMA priority for EMIFF access to highest */
1768 if (cpu_class_is_omap1())
1769 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF
, 15);
1772 r
= ctrl_change_mode(fbdev
->fb_info
[0]);
1774 dev_err(fbdev
->dev
, "mode setting failed\n");
1778 /* GFX plane is enabled by default */
1779 r
= fbdev
->ctrl
->enable_plane(OMAPFB_PLANE_GFX
, 1);
1783 omapfb_set_update_mode(fbdev
, manual_update
?
1784 OMAPFB_MANUAL_UPDATE
: OMAPFB_AUTO_UPDATE
);
1787 r
= fbdev
->panel
->enable(fbdev
->panel
);
1792 r
= omapfb_register_sysfs(fbdev
);
1798 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1799 r
= register_framebuffer(fbdev
->fb_info
[i
]);
1802 "registering framebuffer %d failed\n", i
);
1805 vram
+= fbdev
->mem_desc
.region
[i
].size
;
1808 fbdev
->state
= OMAPFB_ACTIVE
;
1810 panel
= fbdev
->panel
;
1811 phz
= panel
->pixel_clock
* 1000;
1812 hhz
= phz
* 10 / (panel
->hfp
+ panel
->x_res
+ panel
->hbp
+ panel
->hsw
);
1813 vhz
= hhz
/ (panel
->vfp
+ panel
->y_res
+ panel
->vbp
+ panel
->vsw
);
1817 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1818 vram
, fbdev
->mem_desc
.region_cnt
);
1819 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1820 "vfreq %lu.%lu Hz\n",
1821 phz
/ 1000, hhz
/ 10000, hhz
% 10, vhz
/ 10, vhz
% 10);
1826 omapfb_free_resources(fbdev
, init_state
);
1831 static int omapfb_probe(struct platform_device
*pdev
)
1835 BUG_ON(fbdev_pdev
!= NULL
);
1837 r
= platform_device_register(&omapdss_device
);
1839 dev_err(&pdev
->dev
, "can't register omapdss device\n");
1843 /* Delay actual initialization until the LCD is registered */
1845 if (fbdev_panel
!= NULL
)
1846 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1850 void omapfb_register_panel(struct lcd_panel
*panel
)
1852 BUG_ON(fbdev_panel
!= NULL
);
1854 fbdev_panel
= panel
;
1855 if (fbdev_pdev
!= NULL
)
1856 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1859 /* Called when the device is being detached from the driver */
1860 static int omapfb_remove(struct platform_device
*pdev
)
1862 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1863 enum omapfb_state saved_state
= fbdev
->state
;
1865 /* FIXME: wait till completion of pending events */
1867 fbdev
->state
= OMAPFB_DISABLED
;
1868 omapfb_free_resources(fbdev
, saved_state
);
1870 platform_device_unregister(&omapdss_device
);
1871 fbdev
->dssdev
= NULL
;
1877 static int omapfb_suspend(struct platform_device
*pdev
, pm_message_t mesg
)
1879 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1882 omapfb_blank(FB_BLANK_POWERDOWN
, fbdev
->fb_info
[0]);
1887 static int omapfb_resume(struct platform_device
*pdev
)
1889 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1892 omapfb_blank(FB_BLANK_UNBLANK
, fbdev
->fb_info
[0]);
1896 static struct platform_driver omapfb_driver
= {
1897 .probe
= omapfb_probe
,
1898 .remove
= omapfb_remove
,
1899 .suspend
= omapfb_suspend
,
1900 .resume
= omapfb_resume
,
1902 .name
= MODULE_NAME
,
1903 .owner
= THIS_MODULE
,
1909 /* Process kernel command line parameters */
1910 static int __init
omapfb_setup(char *options
)
1912 char *this_opt
= NULL
;
1915 pr_debug("omapfb: options %s\n", options
);
1917 if (!options
|| !*options
)
1920 while (!r
&& (this_opt
= strsep(&options
, ",")) != NULL
) {
1921 if (!strncmp(this_opt
, "accel", 5))
1923 else if (!strncmp(this_opt
, "vram:", 5)) {
1926 vram
= (simple_strtoul(this_opt
+ 5, &suffix
, 0));
1927 switch (suffix
[0]) {
1939 pr_debug("omapfb: invalid vram suffix %c\n",
1943 def_vram
[def_vram_cnt
++] = vram
;
1945 else if (!strncmp(this_opt
, "vxres:", 6))
1946 def_vxres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1947 else if (!strncmp(this_opt
, "vyres:", 6))
1948 def_vyres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1949 else if (!strncmp(this_opt
, "rotate:", 7))
1950 def_rotate
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1951 else if (!strncmp(this_opt
, "mirror:", 7))
1952 def_mirror
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1953 else if (!strncmp(this_opt
, "manual_update", 13))
1956 pr_debug("omapfb: invalid option\n");
1966 /* Register both the driver and the device */
1967 static int __init
omapfb_init(void)
1972 if (fb_get_options("omapfb", &option
))
1974 omapfb_setup(option
);
1976 /* Register the driver with LDM */
1977 if (platform_driver_register(&omapfb_driver
)) {
1978 pr_debug("failed to register omapfb driver\n");
1985 static void __exit
omapfb_cleanup(void)
1987 platform_driver_unregister(&omapfb_driver
);
1990 module_param_named(accel
, def_accel
, uint
, 0664);
1991 module_param_array_named(vram
, def_vram
, ulong
, &def_vram_cnt
, 0664);
1992 module_param_named(vxres
, def_vxres
, long, 0664);
1993 module_param_named(vyres
, def_vyres
, long, 0664);
1994 module_param_named(rotate
, def_rotate
, uint
, 0664);
1995 module_param_named(mirror
, def_mirror
, uint
, 0664);
1996 module_param_named(manual_update
, manual_update
, bool, 0664);
1998 module_init(omapfb_init
);
1999 module_exit(omapfb_cleanup
);
2001 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
2002 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
2003 MODULE_LICENSE("GPL");