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>
32 #include <mach/omapfb.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", },
87 * ---------------------------------------------------------------------------
89 * ---------------------------------------------------------------------------
91 extern struct lcd_ctrl hwa742_ctrl
;
92 extern struct lcd_ctrl blizzard_ctrl
;
94 static const struct lcd_ctrl
*ctrls
[] = {
95 #ifdef CONFIG_ARCH_OMAP1
101 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
104 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
109 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
110 #ifdef CONFIG_ARCH_OMAP1
111 extern struct lcd_ctrl_extif omap1_ext_if
;
113 extern struct lcd_ctrl_extif omap2_ext_if
;
117 static void omapfb_rqueue_lock(struct omapfb_device
*fbdev
)
119 mutex_lock(&fbdev
->rqueue_mutex
);
122 static void omapfb_rqueue_unlock(struct omapfb_device
*fbdev
)
124 mutex_unlock(&fbdev
->rqueue_mutex
);
128 * ---------------------------------------------------------------------------
129 * LCD controller and LCD DMA
130 * ---------------------------------------------------------------------------
132 /* Lookup table to map elem size to elem type. */
133 static const int dma_elem_type
[] = {
135 OMAP_DMA_DATA_TYPE_S8
,
136 OMAP_DMA_DATA_TYPE_S16
,
138 OMAP_DMA_DATA_TYPE_S32
,
142 * Allocate resources needed for LCD controller and LCD DMA operations. Video
143 * memory is allocated from system memory according to the virtual display
144 * size, except if a bigger memory size is specified explicitly as a kernel
147 static int ctrl_init(struct omapfb_device
*fbdev
)
152 /* kernel/module vram parameters override boot tags/board config */
154 for (i
= 0; i
< def_vram_cnt
; i
++)
155 fbdev
->mem_desc
.region
[i
].size
=
156 PAGE_ALIGN(def_vram
[i
]);
157 fbdev
->mem_desc
.region_cnt
= i
;
159 struct omapfb_platform_data
*conf
;
161 conf
= fbdev
->dev
->platform_data
;
162 fbdev
->mem_desc
= conf
->mem_desc
;
165 if (!fbdev
->mem_desc
.region_cnt
) {
166 struct lcd_panel
*panel
= fbdev
->panel
;
168 int bpp
= panel
->bpp
;
170 /* 12 bpp is packed in 16 bits */
173 def_size
= def_vxres
* def_vyres
* bpp
/ 8;
174 fbdev
->mem_desc
.region_cnt
= 1;
175 fbdev
->mem_desc
.region
[0].size
= PAGE_ALIGN(def_size
);
177 r
= fbdev
->ctrl
->init(fbdev
, 0, &fbdev
->mem_desc
);
179 dev_err(fbdev
->dev
, "controller initialization failed (%d)\n",
185 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
186 dev_dbg(fbdev
->dev
, "region%d phys %08x virt %p size=%lu\n",
188 fbdev
->mem_desc
.region
[i
].paddr
,
189 fbdev
->mem_desc
.region
[i
].vaddr
,
190 fbdev
->mem_desc
.region
[i
].size
);
196 static void ctrl_cleanup(struct omapfb_device
*fbdev
)
198 fbdev
->ctrl
->cleanup();
201 /* Must be called with fbdev->rqueue_mutex held. */
202 static int ctrl_change_mode(struct fb_info
*fbi
)
205 unsigned long offset
;
206 struct omapfb_plane_struct
*plane
= fbi
->par
;
207 struct omapfb_device
*fbdev
= plane
->fbdev
;
208 struct fb_var_screeninfo
*var
= &fbi
->var
;
210 offset
= var
->yoffset
* fbi
->fix
.line_length
+
211 var
->xoffset
* var
->bits_per_pixel
/ 8;
213 if (fbdev
->ctrl
->sync
)
215 r
= fbdev
->ctrl
->setup_plane(plane
->idx
, plane
->info
.channel_out
,
216 offset
, var
->xres_virtual
,
217 plane
->info
.pos_x
, plane
->info
.pos_y
,
218 var
->xres
, var
->yres
, plane
->color_mode
);
222 if (fbdev
->ctrl
->set_rotate
!= NULL
) {
223 r
= fbdev
->ctrl
->set_rotate(var
->rotate
);
228 if (fbdev
->ctrl
->set_scale
!= NULL
)
229 r
= fbdev
->ctrl
->set_scale(plane
->idx
,
230 var
->xres
, var
->yres
,
231 plane
->info
.out_width
,
232 plane
->info
.out_height
);
238 * ---------------------------------------------------------------------------
239 * fbdev framework callbacks and the ioctl interface
240 * ---------------------------------------------------------------------------
242 /* Called each time the omapfb device is opened */
243 static int omapfb_open(struct fb_info
*info
, int user
)
248 static void omapfb_sync(struct fb_info
*info
);
250 /* Called when the omapfb device is closed. We make sure that any pending
251 * gfx DMA operations are ended, before we return. */
252 static int omapfb_release(struct fb_info
*info
, int user
)
258 /* Store a single color palette entry into a pseudo palette or the hardware
259 * palette if one is available. For now we support only 16bpp and thus store
260 * the entry only to the pseudo palette.
262 static int _setcolreg(struct fb_info
*info
, u_int regno
, u_int red
, u_int green
,
263 u_int blue
, u_int transp
, int update_hw_pal
)
265 struct omapfb_plane_struct
*plane
= info
->par
;
266 struct omapfb_device
*fbdev
= plane
->fbdev
;
267 struct fb_var_screeninfo
*var
= &info
->var
;
270 switch (plane
->color_mode
) {
271 case OMAPFB_COLOR_YUV422
:
272 case OMAPFB_COLOR_YUV420
:
273 case OMAPFB_COLOR_YUY422
:
276 case OMAPFB_COLOR_CLUT_8BPP
:
277 case OMAPFB_COLOR_CLUT_4BPP
:
278 case OMAPFB_COLOR_CLUT_2BPP
:
279 case OMAPFB_COLOR_CLUT_1BPP
:
280 if (fbdev
->ctrl
->setcolreg
)
281 r
= fbdev
->ctrl
->setcolreg(regno
, red
, green
, blue
,
282 transp
, update_hw_pal
);
284 case OMAPFB_COLOR_RGB565
:
285 case OMAPFB_COLOR_RGB444
:
296 pal
= ((red
>> (16 - var
->red
.length
)) <<
298 ((green
>> (16 - var
->green
.length
)) <<
300 (blue
>> (16 - var
->blue
.length
));
301 ((u32
*)(info
->pseudo_palette
))[regno
] = pal
;
310 static int omapfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
311 u_int transp
, struct fb_info
*info
)
313 return _setcolreg(info
, regno
, red
, green
, blue
, transp
, 1);
316 static int omapfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
319 u16
*red
, *green
, *blue
, *transp
;
325 transp
= cmap
->transp
;
328 for (count
= 0; count
< cmap
->len
; count
++) {
331 r
= _setcolreg(info
, index
++, *red
++, *green
++, *blue
++, trans
,
332 count
== cmap
->len
- 1);
340 static int omapfb_update_full_screen(struct fb_info
*fbi
);
342 static int omapfb_blank(int blank
, struct fb_info
*fbi
)
344 struct omapfb_plane_struct
*plane
= fbi
->par
;
345 struct omapfb_device
*fbdev
= plane
->fbdev
;
349 omapfb_rqueue_lock(fbdev
);
351 case FB_BLANK_UNBLANK
:
352 if (fbdev
->state
== OMAPFB_SUSPENDED
) {
353 if (fbdev
->ctrl
->resume
)
354 fbdev
->ctrl
->resume();
355 fbdev
->panel
->enable(fbdev
->panel
);
356 fbdev
->state
= OMAPFB_ACTIVE
;
357 if (fbdev
->ctrl
->get_update_mode() ==
358 OMAPFB_MANUAL_UPDATE
)
362 case FB_BLANK_POWERDOWN
:
363 if (fbdev
->state
== OMAPFB_ACTIVE
) {
364 fbdev
->panel
->disable(fbdev
->panel
);
365 if (fbdev
->ctrl
->suspend
)
366 fbdev
->ctrl
->suspend();
367 fbdev
->state
= OMAPFB_SUSPENDED
;
373 omapfb_rqueue_unlock(fbdev
);
375 if (r
== 0 && do_update
)
376 r
= omapfb_update_full_screen(fbi
);
381 static void omapfb_sync(struct fb_info
*fbi
)
383 struct omapfb_plane_struct
*plane
= fbi
->par
;
384 struct omapfb_device
*fbdev
= plane
->fbdev
;
386 omapfb_rqueue_lock(fbdev
);
387 if (fbdev
->ctrl
->sync
)
389 omapfb_rqueue_unlock(fbdev
);
393 * Set fb_info.fix fields and also updates fbdev.
394 * When calling this fb_info.var must be set up already.
396 static void set_fb_fix(struct fb_info
*fbi
)
398 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
399 struct fb_var_screeninfo
*var
= &fbi
->var
;
400 struct omapfb_plane_struct
*plane
= fbi
->par
;
401 struct omapfb_mem_region
*rg
;
404 rg
= &plane
->fbdev
->mem_desc
.region
[plane
->idx
];
405 fbi
->screen_base
= rg
->vaddr
;
406 mutex_lock(&fbi
->mm_lock
);
407 fix
->smem_start
= rg
->paddr
;
408 fix
->smem_len
= rg
->size
;
409 mutex_unlock(&fbi
->mm_lock
);
411 fix
->type
= FB_TYPE_PACKED_PIXELS
;
412 bpp
= var
->bits_per_pixel
;
414 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
415 else switch (var
->bits_per_pixel
) {
418 fix
->visual
= FB_VISUAL_TRUECOLOR
;
419 /* 12bpp is stored in 16 bits */
426 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
429 fix
->accel
= FB_ACCEL_OMAP1610
;
430 fix
->line_length
= var
->xres_virtual
* bpp
/ 8;
433 static int set_color_mode(struct omapfb_plane_struct
*plane
,
434 struct fb_var_screeninfo
*var
)
436 switch (var
->nonstd
) {
439 case OMAPFB_COLOR_YUV422
:
440 var
->bits_per_pixel
= 16;
441 plane
->color_mode
= var
->nonstd
;
443 case OMAPFB_COLOR_YUV420
:
444 var
->bits_per_pixel
= 12;
445 plane
->color_mode
= var
->nonstd
;
447 case OMAPFB_COLOR_YUY422
:
448 var
->bits_per_pixel
= 16;
449 plane
->color_mode
= var
->nonstd
;
455 switch (var
->bits_per_pixel
) {
457 plane
->color_mode
= OMAPFB_COLOR_CLUT_1BPP
;
460 plane
->color_mode
= OMAPFB_COLOR_CLUT_2BPP
;
463 plane
->color_mode
= OMAPFB_COLOR_CLUT_4BPP
;
466 plane
->color_mode
= OMAPFB_COLOR_CLUT_8BPP
;
469 var
->bits_per_pixel
= 16;
470 plane
->color_mode
= OMAPFB_COLOR_RGB444
;
473 plane
->color_mode
= OMAPFB_COLOR_RGB565
;
481 * Check the values in var against our capabilities and in case of out of
482 * bound values try to adjust them.
484 static int set_fb_var(struct fb_info
*fbi
,
485 struct fb_var_screeninfo
*var
)
488 unsigned long max_frame_size
;
489 unsigned long line_size
;
490 int xres_min
, xres_max
;
491 int yres_min
, yres_max
;
492 struct omapfb_plane_struct
*plane
= fbi
->par
;
493 struct omapfb_device
*fbdev
= plane
->fbdev
;
494 struct lcd_panel
*panel
= fbdev
->panel
;
496 if (set_color_mode(plane
, var
) < 0)
499 bpp
= var
->bits_per_pixel
;
500 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
)
503 switch (var
->rotate
) {
506 xres_min
= OMAPFB_PLANE_XRES_MIN
;
507 xres_max
= panel
->x_res
;
508 yres_min
= OMAPFB_PLANE_YRES_MIN
;
509 yres_max
= panel
->y_res
;
510 if (cpu_is_omap15xx()) {
511 var
->xres
= panel
->x_res
;
512 var
->yres
= panel
->y_res
;
517 xres_min
= OMAPFB_PLANE_YRES_MIN
;
518 xres_max
= panel
->y_res
;
519 yres_min
= OMAPFB_PLANE_XRES_MIN
;
520 yres_max
= panel
->x_res
;
521 if (cpu_is_omap15xx()) {
522 var
->xres
= panel
->y_res
;
523 var
->yres
= panel
->x_res
;
530 if (var
->xres
< xres_min
)
531 var
->xres
= xres_min
;
532 if (var
->yres
< yres_min
)
533 var
->yres
= yres_min
;
534 if (var
->xres
> xres_max
)
535 var
->xres
= xres_max
;
536 if (var
->yres
> yres_max
)
537 var
->yres
= yres_max
;
539 if (var
->xres_virtual
< var
->xres
)
540 var
->xres_virtual
= var
->xres
;
541 if (var
->yres_virtual
< var
->yres
)
542 var
->yres_virtual
= var
->yres
;
543 max_frame_size
= fbdev
->mem_desc
.region
[plane
->idx
].size
;
544 line_size
= var
->xres_virtual
* bpp
/ 8;
545 if (line_size
* var
->yres_virtual
> max_frame_size
) {
546 /* Try to keep yres_virtual first */
547 line_size
= max_frame_size
/ var
->yres_virtual
;
548 var
->xres_virtual
= line_size
* 8 / bpp
;
549 if (var
->xres_virtual
< var
->xres
) {
550 /* Still doesn't fit. Shrink yres_virtual too */
551 var
->xres_virtual
= var
->xres
;
552 line_size
= var
->xres
* bpp
/ 8;
553 var
->yres_virtual
= max_frame_size
/ line_size
;
555 /* Recheck this, as the virtual size changed. */
556 if (var
->xres_virtual
< var
->xres
)
557 var
->xres
= var
->xres_virtual
;
558 if (var
->yres_virtual
< var
->yres
)
559 var
->yres
= var
->yres_virtual
;
560 if (var
->xres
< xres_min
|| var
->yres
< yres_min
)
563 if (var
->xres
+ var
->xoffset
> var
->xres_virtual
)
564 var
->xoffset
= var
->xres_virtual
- var
->xres
;
565 if (var
->yres
+ var
->yoffset
> var
->yres_virtual
)
566 var
->yoffset
= var
->yres_virtual
- var
->yres
;
568 if (plane
->color_mode
== OMAPFB_COLOR_RGB444
) {
569 var
->red
.offset
= 8; var
->red
.length
= 4;
570 var
->red
.msb_right
= 0;
571 var
->green
.offset
= 4; var
->green
.length
= 4;
572 var
->green
.msb_right
= 0;
573 var
->blue
.offset
= 0; var
->blue
.length
= 4;
574 var
->blue
.msb_right
= 0;
576 var
->red
.offset
= 11; var
->red
.length
= 5;
577 var
->red
.msb_right
= 0;
578 var
->green
.offset
= 5; var
->green
.length
= 6;
579 var
->green
.msb_right
= 0;
580 var
->blue
.offset
= 0; var
->blue
.length
= 5;
581 var
->blue
.msb_right
= 0;
588 /* pixclock in ps, the rest in pixclock */
589 var
->pixclock
= 10000000 / (panel
->pixel_clock
/ 100);
590 var
->left_margin
= panel
->hfp
;
591 var
->right_margin
= panel
->hbp
;
592 var
->upper_margin
= panel
->vfp
;
593 var
->lower_margin
= panel
->vbp
;
594 var
->hsync_len
= panel
->hsw
;
595 var
->vsync_len
= panel
->vsw
;
597 /* TODO: get these from panel->config */
598 var
->vmode
= FB_VMODE_NONINTERLACED
;
605 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
606 static void omapfb_rotate(struct fb_info
*fbi
, int rotate
)
608 struct omapfb_plane_struct
*plane
= fbi
->par
;
609 struct omapfb_device
*fbdev
= plane
->fbdev
;
611 omapfb_rqueue_lock(fbdev
);
612 if (rotate
!= fbi
->var
.rotate
) {
613 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
615 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
616 new_var
->rotate
= rotate
;
617 if (set_fb_var(fbi
, new_var
) == 0 &&
618 memcmp(new_var
, &fbi
->var
, sizeof(*new_var
))) {
619 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
620 ctrl_change_mode(fbi
);
623 omapfb_rqueue_unlock(fbdev
);
627 * Set new x,y offsets in the virtual display for the visible area and switch
630 static int omapfb_pan_display(struct fb_var_screeninfo
*var
,
633 struct omapfb_plane_struct
*plane
= fbi
->par
;
634 struct omapfb_device
*fbdev
= plane
->fbdev
;
637 omapfb_rqueue_lock(fbdev
);
638 if (var
->xoffset
!= fbi
->var
.xoffset
||
639 var
->yoffset
!= fbi
->var
.yoffset
) {
640 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
642 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
643 new_var
->xoffset
= var
->xoffset
;
644 new_var
->yoffset
= var
->yoffset
;
645 if (set_fb_var(fbi
, new_var
))
648 memcpy(&fbi
->var
, new_var
, sizeof(*new_var
));
649 ctrl_change_mode(fbi
);
652 omapfb_rqueue_unlock(fbdev
);
657 /* Set mirror to vertical axis and switch to the new mode. */
658 static int omapfb_mirror(struct fb_info
*fbi
, int mirror
)
660 struct omapfb_plane_struct
*plane
= fbi
->par
;
661 struct omapfb_device
*fbdev
= plane
->fbdev
;
664 omapfb_rqueue_lock(fbdev
);
665 mirror
= mirror
? 1 : 0;
666 if (cpu_is_omap15xx())
668 else if (mirror
!= plane
->info
.mirror
) {
669 plane
->info
.mirror
= mirror
;
670 r
= ctrl_change_mode(fbi
);
672 omapfb_rqueue_unlock(fbdev
);
678 * Check values in var, try to adjust them in case of out of bound values if
679 * possible, or return error.
681 static int omapfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*fbi
)
683 struct omapfb_plane_struct
*plane
= fbi
->par
;
684 struct omapfb_device
*fbdev
= plane
->fbdev
;
687 omapfb_rqueue_lock(fbdev
);
688 if (fbdev
->ctrl
->sync
!= NULL
)
690 r
= set_fb_var(fbi
, var
);
691 omapfb_rqueue_unlock(fbdev
);
697 * Switch to a new mode. The parameters for it has been check already by
700 static int omapfb_set_par(struct fb_info
*fbi
)
702 struct omapfb_plane_struct
*plane
= fbi
->par
;
703 struct omapfb_device
*fbdev
= plane
->fbdev
;
706 omapfb_rqueue_lock(fbdev
);
708 r
= ctrl_change_mode(fbi
);
709 omapfb_rqueue_unlock(fbdev
);
714 int omapfb_update_window_async(struct fb_info
*fbi
,
715 struct omapfb_update_window
*win
,
716 void (*callback
)(void *),
720 struct omapfb_plane_struct
*plane
= fbi
->par
;
721 struct omapfb_device
*fbdev
= plane
->fbdev
;
722 struct fb_var_screeninfo
*var
= &fbi
->var
;
724 switch (var
->rotate
) {
727 xres
= fbdev
->panel
->x_res
;
728 yres
= fbdev
->panel
->y_res
;
732 xres
= fbdev
->panel
->y_res
;
733 yres
= fbdev
->panel
->x_res
;
739 if (win
->x
>= xres
|| win
->y
>= yres
||
740 win
->out_x
> xres
|| win
->out_y
> yres
)
743 if (!fbdev
->ctrl
->update_window
||
744 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
747 if (win
->x
+ win
->width
> xres
)
748 win
->width
= xres
- win
->x
;
749 if (win
->y
+ win
->height
> yres
)
750 win
->height
= yres
- win
->y
;
751 if (win
->out_x
+ win
->out_width
> xres
)
752 win
->out_width
= xres
- win
->out_x
;
753 if (win
->out_y
+ win
->out_height
> yres
)
754 win
->out_height
= yres
- win
->out_y
;
755 if (!win
->width
|| !win
->height
|| !win
->out_width
|| !win
->out_height
)
758 return fbdev
->ctrl
->update_window(fbi
, win
, callback
, callback_data
);
760 EXPORT_SYMBOL(omapfb_update_window_async
);
762 static int omapfb_update_win(struct fb_info
*fbi
,
763 struct omapfb_update_window
*win
)
765 struct omapfb_plane_struct
*plane
= fbi
->par
;
768 omapfb_rqueue_lock(plane
->fbdev
);
769 ret
= omapfb_update_window_async(fbi
, win
, NULL
, NULL
);
770 omapfb_rqueue_unlock(plane
->fbdev
);
775 static int omapfb_update_full_screen(struct fb_info
*fbi
)
777 struct omapfb_plane_struct
*plane
= fbi
->par
;
778 struct omapfb_device
*fbdev
= plane
->fbdev
;
779 struct omapfb_update_window win
;
782 if (!fbdev
->ctrl
->update_window
||
783 fbdev
->ctrl
->get_update_mode() != OMAPFB_MANUAL_UPDATE
)
788 win
.width
= fbi
->var
.xres
;
789 win
.height
= fbi
->var
.yres
;
792 win
.out_width
= fbi
->var
.xres
;
793 win
.out_height
= fbi
->var
.yres
;
796 omapfb_rqueue_lock(fbdev
);
797 r
= fbdev
->ctrl
->update_window(fbi
, &win
, NULL
, NULL
);
798 omapfb_rqueue_unlock(fbdev
);
803 static int omapfb_setup_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
805 struct omapfb_plane_struct
*plane
= fbi
->par
;
806 struct omapfb_device
*fbdev
= plane
->fbdev
;
807 struct lcd_panel
*panel
= fbdev
->panel
;
808 struct omapfb_plane_info old_info
;
811 if (pi
->pos_x
+ pi
->out_width
> panel
->x_res
||
812 pi
->pos_y
+ pi
->out_height
> panel
->y_res
)
815 omapfb_rqueue_lock(fbdev
);
816 if (pi
->enabled
&& !fbdev
->mem_desc
.region
[plane
->idx
].size
) {
818 * This plane's memory was freed, can't enable it
819 * until it's reallocated.
824 old_info
= plane
->info
;
827 r
= ctrl_change_mode(fbi
);
829 plane
->info
= old_info
;
833 r
= fbdev
->ctrl
->enable_plane(plane
->idx
, pi
->enabled
);
835 plane
->info
= old_info
;
839 omapfb_rqueue_unlock(fbdev
);
843 static int omapfb_query_plane(struct fb_info
*fbi
, struct omapfb_plane_info
*pi
)
845 struct omapfb_plane_struct
*plane
= fbi
->par
;
851 static int omapfb_setup_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
853 struct omapfb_plane_struct
*plane
= fbi
->par
;
854 struct omapfb_device
*fbdev
= plane
->fbdev
;
855 struct omapfb_mem_region
*rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
859 if (fbdev
->ctrl
->setup_mem
== NULL
)
861 if (mi
->type
> OMAPFB_MEMTYPE_MAX
)
864 size
= PAGE_ALIGN(mi
->size
);
865 omapfb_rqueue_lock(fbdev
);
866 if (plane
->info
.enabled
) {
870 if (rg
->size
!= size
|| rg
->type
!= mi
->type
) {
871 struct fb_var_screeninfo
*new_var
= &fbdev
->new_var
;
872 unsigned long old_size
= rg
->size
;
873 u8 old_type
= rg
->type
;
879 * size == 0 is a special case, for which we
880 * don't check / adjust the screen parameters.
881 * This isn't a problem since the plane can't
882 * be reenabled unless its size is > 0.
884 if (old_size
!= size
&& size
) {
886 memcpy(new_var
, &fbi
->var
, sizeof(*new_var
));
887 r
= set_fb_var(fbi
, new_var
);
893 if (fbdev
->ctrl
->sync
)
895 r
= fbdev
->ctrl
->setup_mem(plane
->idx
, size
, mi
->type
, &paddr
);
897 /* Revert changes. */
904 if (old_size
!= size
) {
906 memcpy(&fbi
->var
, new_var
, sizeof(fbi
->var
));
910 * Set these explicitly to indicate that the
911 * plane memory is dealloce'd, the other
912 * screen parameters in var / fix are invalid.
914 mutex_lock(&fbi
->mm_lock
);
915 fbi
->fix
.smem_start
= 0;
916 fbi
->fix
.smem_len
= 0;
917 mutex_unlock(&fbi
->mm_lock
);
922 omapfb_rqueue_unlock(fbdev
);
927 static int omapfb_query_mem(struct fb_info
*fbi
, struct omapfb_mem_info
*mi
)
929 struct omapfb_plane_struct
*plane
= fbi
->par
;
930 struct omapfb_device
*fbdev
= plane
->fbdev
;
931 struct omapfb_mem_region
*rg
;
933 rg
= &fbdev
->mem_desc
.region
[plane
->idx
];
934 memset(mi
, 0, sizeof(*mi
));
941 static int omapfb_set_color_key(struct omapfb_device
*fbdev
,
942 struct omapfb_color_key
*ck
)
946 if (!fbdev
->ctrl
->set_color_key
)
949 omapfb_rqueue_lock(fbdev
);
950 r
= fbdev
->ctrl
->set_color_key(ck
);
951 omapfb_rqueue_unlock(fbdev
);
956 static int omapfb_get_color_key(struct omapfb_device
*fbdev
,
957 struct omapfb_color_key
*ck
)
961 if (!fbdev
->ctrl
->get_color_key
)
964 omapfb_rqueue_lock(fbdev
);
965 r
= fbdev
->ctrl
->get_color_key(ck
);
966 omapfb_rqueue_unlock(fbdev
);
971 static struct blocking_notifier_head omapfb_client_list
[OMAPFB_PLANE_NUM
];
972 static int notifier_inited
;
974 static void omapfb_init_notifier(void)
978 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
979 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list
[i
]);
982 int omapfb_register_client(struct omapfb_notifier_block
*omapfb_nb
,
983 omapfb_notifier_callback_t callback
,
988 if ((unsigned)omapfb_nb
->plane_idx
> OMAPFB_PLANE_NUM
)
991 if (!notifier_inited
) {
992 omapfb_init_notifier();
996 omapfb_nb
->nb
.notifier_call
= (int (*)(struct notifier_block
*,
997 unsigned long, void *))callback
;
998 omapfb_nb
->data
= callback_data
;
999 r
= blocking_notifier_chain_register(
1000 &omapfb_client_list
[omapfb_nb
->plane_idx
],
1004 if (omapfb_dev
!= NULL
&&
1005 omapfb_dev
->ctrl
&& omapfb_dev
->ctrl
->bind_client
) {
1006 omapfb_dev
->ctrl
->bind_client(omapfb_nb
);
1011 EXPORT_SYMBOL(omapfb_register_client
);
1013 int omapfb_unregister_client(struct omapfb_notifier_block
*omapfb_nb
)
1015 return blocking_notifier_chain_unregister(
1016 &omapfb_client_list
[omapfb_nb
->plane_idx
], &omapfb_nb
->nb
);
1018 EXPORT_SYMBOL(omapfb_unregister_client
);
1020 void omapfb_notify_clients(struct omapfb_device
*fbdev
, unsigned long event
)
1024 if (!notifier_inited
)
1025 /* no client registered yet */
1028 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++)
1029 blocking_notifier_call_chain(&omapfb_client_list
[i
], event
,
1032 EXPORT_SYMBOL(omapfb_notify_clients
);
1034 static int omapfb_set_update_mode(struct omapfb_device
*fbdev
,
1035 enum omapfb_update_mode mode
)
1039 omapfb_rqueue_lock(fbdev
);
1040 r
= fbdev
->ctrl
->set_update_mode(mode
);
1041 omapfb_rqueue_unlock(fbdev
);
1046 static enum omapfb_update_mode
omapfb_get_update_mode(struct omapfb_device
*fbdev
)
1050 omapfb_rqueue_lock(fbdev
);
1051 r
= fbdev
->ctrl
->get_update_mode();
1052 omapfb_rqueue_unlock(fbdev
);
1057 static void omapfb_get_caps(struct omapfb_device
*fbdev
, int plane
,
1058 struct omapfb_caps
*caps
)
1060 memset(caps
, 0, sizeof(*caps
));
1061 fbdev
->ctrl
->get_caps(plane
, caps
);
1062 caps
->ctrl
|= fbdev
->panel
->get_caps(fbdev
->panel
);
1065 /* For lcd testing */
1066 void omapfb_write_first_pixel(struct omapfb_device
*fbdev
, u16 pixval
)
1068 omapfb_rqueue_lock(fbdev
);
1069 *(u16
*)fbdev
->mem_desc
.region
[0].vaddr
= pixval
;
1070 if (fbdev
->ctrl
->get_update_mode() == OMAPFB_MANUAL_UPDATE
) {
1071 struct omapfb_update_window win
;
1073 memset(&win
, 0, sizeof(win
));
1078 fbdev
->ctrl
->update_window(fbdev
->fb_info
[0], &win
, NULL
, NULL
);
1080 omapfb_rqueue_unlock(fbdev
);
1082 EXPORT_SYMBOL(omapfb_write_first_pixel
);
1085 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1086 * here to be accessible by user mode code.
1088 static int omapfb_ioctl(struct fb_info
*fbi
, unsigned int cmd
,
1091 struct omapfb_plane_struct
*plane
= fbi
->par
;
1092 struct omapfb_device
*fbdev
= plane
->fbdev
;
1093 struct fb_ops
*ops
= fbi
->fbops
;
1095 struct omapfb_update_window update_window
;
1096 struct omapfb_plane_info plane_info
;
1097 struct omapfb_mem_info mem_info
;
1098 struct omapfb_color_key color_key
;
1099 enum omapfb_update_mode update_mode
;
1100 struct omapfb_caps caps
;
1101 unsigned int mirror
;
1110 if (get_user(p
.mirror
, (int __user
*)arg
))
1113 omapfb_mirror(fbi
, p
.mirror
);
1115 case OMAPFB_SYNC_GFX
:
1120 case OMAPFB_SET_UPDATE_MODE
:
1121 if (get_user(p
.update_mode
, (int __user
*)arg
))
1124 r
= omapfb_set_update_mode(fbdev
, p
.update_mode
);
1126 case OMAPFB_GET_UPDATE_MODE
:
1127 p
.update_mode
= omapfb_get_update_mode(fbdev
);
1128 if (put_user(p
.update_mode
,
1129 (enum omapfb_update_mode __user
*)arg
))
1132 case OMAPFB_UPDATE_WINDOW_OLD
:
1133 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1134 sizeof(struct omapfb_update_window_old
)))
1137 struct omapfb_update_window
*u
= &p
.update_window
;
1140 u
->out_width
= u
->width
;
1141 u
->out_height
= u
->height
;
1142 memset(u
->reserved
, 0, sizeof(u
->reserved
));
1143 r
= omapfb_update_win(fbi
, u
);
1146 case OMAPFB_UPDATE_WINDOW
:
1147 if (copy_from_user(&p
.update_window
, (void __user
*)arg
,
1148 sizeof(p
.update_window
)))
1151 r
= omapfb_update_win(fbi
, &p
.update_window
);
1153 case OMAPFB_SETUP_PLANE
:
1154 if (copy_from_user(&p
.plane_info
, (void __user
*)arg
,
1155 sizeof(p
.plane_info
)))
1158 r
= omapfb_setup_plane(fbi
, &p
.plane_info
);
1160 case OMAPFB_QUERY_PLANE
:
1161 if ((r
= omapfb_query_plane(fbi
, &p
.plane_info
)) < 0)
1163 if (copy_to_user((void __user
*)arg
, &p
.plane_info
,
1164 sizeof(p
.plane_info
)))
1167 case OMAPFB_SETUP_MEM
:
1168 if (copy_from_user(&p
.mem_info
, (void __user
*)arg
,
1169 sizeof(p
.mem_info
)))
1172 r
= omapfb_setup_mem(fbi
, &p
.mem_info
);
1174 case OMAPFB_QUERY_MEM
:
1175 if ((r
= omapfb_query_mem(fbi
, &p
.mem_info
)) < 0)
1177 if (copy_to_user((void __user
*)arg
, &p
.mem_info
,
1178 sizeof(p
.mem_info
)))
1181 case OMAPFB_SET_COLOR_KEY
:
1182 if (copy_from_user(&p
.color_key
, (void __user
*)arg
,
1183 sizeof(p
.color_key
)))
1186 r
= omapfb_set_color_key(fbdev
, &p
.color_key
);
1188 case OMAPFB_GET_COLOR_KEY
:
1189 if ((r
= omapfb_get_color_key(fbdev
, &p
.color_key
)) < 0)
1191 if (copy_to_user((void __user
*)arg
, &p
.color_key
,
1192 sizeof(p
.color_key
)))
1195 case OMAPFB_GET_CAPS
:
1196 omapfb_get_caps(fbdev
, plane
->idx
, &p
.caps
);
1197 if (copy_to_user((void __user
*)arg
, &p
.caps
, sizeof(p
.caps
)))
1200 case OMAPFB_LCD_TEST
:
1204 if (get_user(test_num
, (int __user
*)arg
)) {
1208 if (!fbdev
->panel
->run_test
) {
1212 r
= fbdev
->panel
->run_test(fbdev
->panel
, test_num
);
1215 case OMAPFB_CTRL_TEST
:
1219 if (get_user(test_num
, (int __user
*)arg
)) {
1223 if (!fbdev
->ctrl
->run_test
) {
1227 r
= fbdev
->ctrl
->run_test(test_num
);
1237 static int omapfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1239 struct omapfb_plane_struct
*plane
= info
->par
;
1240 struct omapfb_device
*fbdev
= plane
->fbdev
;
1243 omapfb_rqueue_lock(fbdev
);
1244 r
= fbdev
->ctrl
->mmap(info
, vma
);
1245 omapfb_rqueue_unlock(fbdev
);
1251 * Callback table for the frame buffer framework. Some of these pointers
1252 * will be changed according to the current setting of fb_info->accel_flags.
1254 static struct fb_ops omapfb_ops
= {
1255 .owner
= THIS_MODULE
,
1256 .fb_open
= omapfb_open
,
1257 .fb_release
= omapfb_release
,
1258 .fb_setcolreg
= omapfb_setcolreg
,
1259 .fb_setcmap
= omapfb_setcmap
,
1260 .fb_fillrect
= cfb_fillrect
,
1261 .fb_copyarea
= cfb_copyarea
,
1262 .fb_imageblit
= cfb_imageblit
,
1263 .fb_blank
= omapfb_blank
,
1264 .fb_ioctl
= omapfb_ioctl
,
1265 .fb_check_var
= omapfb_check_var
,
1266 .fb_set_par
= omapfb_set_par
,
1267 .fb_rotate
= omapfb_rotate
,
1268 .fb_pan_display
= omapfb_pan_display
,
1272 * ---------------------------------------------------------------------------
1274 * ---------------------------------------------------------------------------
1276 /* omapfbX sysfs entries */
1277 static ssize_t
omapfb_show_caps_num(struct device
*dev
,
1278 struct device_attribute
*attr
, char *buf
)
1280 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1283 struct omapfb_caps caps
;
1287 while (size
< PAGE_SIZE
&& plane
< OMAPFB_PLANE_NUM
) {
1288 omapfb_get_caps(fbdev
, plane
, &caps
);
1289 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1290 "plane#%d %#010x %#010x %#010x\n",
1291 plane
, caps
.ctrl
, caps
.plane_color
, caps
.wnd_color
);
1297 static ssize_t
omapfb_show_caps_text(struct device
*dev
,
1298 struct device_attribute
*attr
, char *buf
)
1300 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1302 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:\n", plane
);
1312 for (i
= 0; i
< ARRAY_SIZE(ctrl_caps
) &&
1313 size
< PAGE_SIZE
; i
++) {
1314 if (ctrl_caps
[i
].flag
& caps
.ctrl
)
1315 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1316 " %s\n", ctrl_caps
[i
].name
);
1318 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1319 " plane colors:\n");
1320 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1321 size
< PAGE_SIZE
; i
++) {
1322 if (color_caps
[i
].flag
& caps
.plane_color
)
1323 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1324 " %s\n", color_caps
[i
].name
);
1326 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1327 " window colors:\n");
1328 for (i
= 0; i
< ARRAY_SIZE(color_caps
) &&
1329 size
< PAGE_SIZE
; i
++) {
1330 if (color_caps
[i
].flag
& caps
.wnd_color
)
1331 size
+= snprintf(&buf
[size
], PAGE_SIZE
- size
,
1332 " %s\n", color_caps
[i
].name
);
1340 static DEVICE_ATTR(caps_num
, 0444, omapfb_show_caps_num
, NULL
);
1341 static DEVICE_ATTR(caps_text
, 0444, omapfb_show_caps_text
, NULL
);
1343 /* panel sysfs entries */
1344 static ssize_t
omapfb_show_panel_name(struct device
*dev
,
1345 struct device_attribute
*attr
, char *buf
)
1347 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1349 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->panel
->name
);
1352 static ssize_t
omapfb_show_bklight_level(struct device
*dev
,
1353 struct device_attribute
*attr
,
1356 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1359 if (fbdev
->panel
->get_bklight_level
) {
1360 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1361 fbdev
->panel
->get_bklight_level(fbdev
->panel
));
1367 static ssize_t
omapfb_store_bklight_level(struct device
*dev
,
1368 struct device_attribute
*attr
,
1369 const char *buf
, size_t size
)
1371 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1374 if (fbdev
->panel
->set_bklight_level
) {
1377 if (sscanf(buf
, "%10d", &level
) == 1) {
1378 r
= fbdev
->panel
->set_bklight_level(fbdev
->panel
,
1384 return r
? r
: size
;
1387 static ssize_t
omapfb_show_bklight_max(struct device
*dev
,
1388 struct device_attribute
*attr
, char *buf
)
1390 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1393 if (fbdev
->panel
->get_bklight_level
) {
1394 r
= snprintf(buf
, PAGE_SIZE
, "%d\n",
1395 fbdev
->panel
->get_bklight_max(fbdev
->panel
));
1401 static struct device_attribute dev_attr_panel_name
=
1402 __ATTR(name
, 0444, omapfb_show_panel_name
, NULL
);
1403 static DEVICE_ATTR(backlight_level
, 0664,
1404 omapfb_show_bklight_level
, omapfb_store_bklight_level
);
1405 static DEVICE_ATTR(backlight_max
, 0444, omapfb_show_bklight_max
, NULL
);
1407 static struct attribute
*panel_attrs
[] = {
1408 &dev_attr_panel_name
.attr
,
1409 &dev_attr_backlight_level
.attr
,
1410 &dev_attr_backlight_max
.attr
,
1414 static struct attribute_group panel_attr_grp
= {
1416 .attrs
= panel_attrs
,
1419 /* ctrl sysfs entries */
1420 static ssize_t
omapfb_show_ctrl_name(struct device
*dev
,
1421 struct device_attribute
*attr
, char *buf
)
1423 struct omapfb_device
*fbdev
= dev_get_drvdata(dev
);
1425 return snprintf(buf
, PAGE_SIZE
, "%s\n", fbdev
->ctrl
->name
);
1428 static struct device_attribute dev_attr_ctrl_name
=
1429 __ATTR(name
, 0444, omapfb_show_ctrl_name
, NULL
);
1431 static struct attribute
*ctrl_attrs
[] = {
1432 &dev_attr_ctrl_name
.attr
,
1436 static struct attribute_group ctrl_attr_grp
= {
1438 .attrs
= ctrl_attrs
,
1441 static int omapfb_register_sysfs(struct omapfb_device
*fbdev
)
1445 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_num
)))
1448 if ((r
= device_create_file(fbdev
->dev
, &dev_attr_caps_text
)))
1451 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &panel_attr_grp
)))
1454 if ((r
= sysfs_create_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
)))
1459 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1461 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1463 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1465 dev_err(fbdev
->dev
, "unable to register sysfs interface\n");
1469 static void omapfb_unregister_sysfs(struct omapfb_device
*fbdev
)
1471 sysfs_remove_group(&fbdev
->dev
->kobj
, &ctrl_attr_grp
);
1472 sysfs_remove_group(&fbdev
->dev
->kobj
, &panel_attr_grp
);
1473 device_remove_file(fbdev
->dev
, &dev_attr_caps_num
);
1474 device_remove_file(fbdev
->dev
, &dev_attr_caps_text
);
1478 * ---------------------------------------------------------------------------
1480 * ---------------------------------------------------------------------------
1482 /* Initialize system fb_info object and set the default video mode.
1483 * The frame buffer memory already allocated by lcddma_init
1485 static int fbinfo_init(struct omapfb_device
*fbdev
, struct fb_info
*info
)
1487 struct fb_var_screeninfo
*var
= &info
->var
;
1488 struct fb_fix_screeninfo
*fix
= &info
->fix
;
1491 info
->fbops
= &omapfb_ops
;
1492 info
->flags
= FBINFO_FLAG_DEFAULT
;
1494 strncpy(fix
->id
, MODULE_NAME
, sizeof(fix
->id
));
1496 info
->pseudo_palette
= fbdev
->pseudo_palette
;
1498 var
->accel_flags
= def_accel
? FB_ACCELF_TEXT
: 0;
1499 var
->xres
= def_vxres
;
1500 var
->yres
= def_vyres
;
1501 var
->xres_virtual
= def_vxres
;
1502 var
->yres_virtual
= def_vyres
;
1503 var
->rotate
= def_rotate
;
1504 var
->bits_per_pixel
= fbdev
->panel
->bpp
;
1506 set_fb_var(info
, var
);
1509 r
= fb_alloc_cmap(&info
->cmap
, 16, 0);
1511 dev_err(fbdev
->dev
, "unable to allocate color map memory\n");
1516 /* Release the fb_info object */
1517 static void fbinfo_cleanup(struct omapfb_device
*fbdev
, struct fb_info
*fbi
)
1519 fb_dealloc_cmap(&fbi
->cmap
);
1522 static void planes_cleanup(struct omapfb_device
*fbdev
)
1526 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1527 if (fbdev
->fb_info
[i
] == NULL
)
1529 fbinfo_cleanup(fbdev
, fbdev
->fb_info
[i
]);
1530 framebuffer_release(fbdev
->fb_info
[i
]);
1534 static int planes_init(struct omapfb_device
*fbdev
)
1536 struct fb_info
*fbi
;
1540 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1541 struct omapfb_plane_struct
*plane
;
1542 fbi
= framebuffer_alloc(sizeof(struct omapfb_plane_struct
),
1546 "unable to allocate memory for plane info\n");
1547 planes_cleanup(fbdev
);
1552 plane
->fbdev
= fbdev
;
1553 plane
->info
.mirror
= def_mirror
;
1554 fbdev
->fb_info
[i
] = fbi
;
1556 if ((r
= fbinfo_init(fbdev
, fbi
)) < 0) {
1557 framebuffer_release(fbi
);
1558 planes_cleanup(fbdev
);
1561 plane
->info
.out_width
= fbi
->var
.xres
;
1562 plane
->info
.out_height
= fbi
->var
.yres
;
1568 * Free driver resources. Can be called to rollback an aborted initialization
1571 static void omapfb_free_resources(struct omapfb_device
*fbdev
, int state
)
1577 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++)
1578 unregister_framebuffer(fbdev
->fb_info
[i
]);
1580 omapfb_unregister_sysfs(fbdev
);
1582 fbdev
->panel
->disable(fbdev
->panel
);
1584 omapfb_set_update_mode(fbdev
, OMAPFB_UPDATE_DISABLED
);
1586 planes_cleanup(fbdev
);
1588 ctrl_cleanup(fbdev
);
1590 fbdev
->panel
->cleanup(fbdev
->panel
);
1592 dev_set_drvdata(fbdev
->dev
, NULL
);
1595 /* nothing to free */
1602 static int omapfb_find_ctrl(struct omapfb_device
*fbdev
)
1604 struct omapfb_platform_data
*conf
;
1608 conf
= fbdev
->dev
->platform_data
;
1612 strncpy(name
, conf
->lcd
.ctrl_name
, sizeof(name
) - 1);
1613 name
[sizeof(name
) - 1] = '\0';
1615 if (strcmp(name
, "internal") == 0) {
1616 fbdev
->ctrl
= fbdev
->int_ctrl
;
1620 for (i
= 0; i
< ARRAY_SIZE(ctrls
); i
++) {
1621 dev_dbg(fbdev
->dev
, "ctrl %s\n", ctrls
[i
]->name
);
1622 if (strcmp(ctrls
[i
]->name
, name
) == 0) {
1623 fbdev
->ctrl
= ctrls
[i
];
1628 if (fbdev
->ctrl
== NULL
) {
1629 dev_dbg(fbdev
->dev
, "ctrl %s not supported\n", name
);
1636 static void check_required_callbacks(struct omapfb_device
*fbdev
)
1638 #define _C(x) (fbdev->ctrl->x != NULL)
1639 #define _P(x) (fbdev->panel->x != NULL)
1640 BUG_ON(fbdev
->ctrl
== NULL
|| fbdev
->panel
== NULL
);
1641 BUG_ON(!(_C(init
) && _C(cleanup
) && _C(get_caps
) &&
1642 _C(set_update_mode
) && _C(setup_plane
) && _C(enable_plane
) &&
1643 _P(init
) && _P(cleanup
) && _P(enable
) && _P(disable
) &&
1650 * Called by LDM binding to probe and attach a new device.
1651 * Initialization sequence:
1652 * 1. allocate system omapfb_device structure
1653 * 2. select controller type according to platform configuration
1655 * 3. init LCD controller and LCD DMA
1656 * 4. init system fb_info structure for all planes
1657 * 5. setup video mode for first plane and enable it
1658 * 6. enable LCD panel
1659 * 7. register sysfs attributes
1660 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1662 static int omapfb_do_probe(struct platform_device
*pdev
,
1663 struct lcd_panel
*panel
)
1665 struct omapfb_device
*fbdev
= NULL
;
1667 unsigned long phz
, hhz
, vhz
;
1674 if (pdev
->num_resources
!= 0) {
1675 dev_err(&pdev
->dev
, "probed for an unknown device\n");
1680 if (pdev
->dev
.platform_data
== NULL
) {
1681 dev_err(&pdev
->dev
, "missing platform data\n");
1686 fbdev
= kzalloc(sizeof(struct omapfb_device
), GFP_KERNEL
);
1687 if (fbdev
== NULL
) {
1689 "unable to allocate memory for device info\n");
1695 fbdev
->dev
= &pdev
->dev
;
1696 fbdev
->panel
= panel
;
1697 platform_set_drvdata(pdev
, fbdev
);
1699 mutex_init(&fbdev
->rqueue_mutex
);
1701 #ifdef CONFIG_ARCH_OMAP1
1702 fbdev
->int_ctrl
= &omap1_int_ctrl
;
1703 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1704 fbdev
->ext_if
= &omap1_ext_if
;
1707 fbdev
->int_ctrl
= &omap2_int_ctrl
;
1708 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1709 fbdev
->ext_if
= &omap2_ext_if
;
1712 if (omapfb_find_ctrl(fbdev
) < 0) {
1714 "LCD controller not found, board not supported\n");
1719 r
= fbdev
->panel
->init(fbdev
->panel
, fbdev
);
1723 pr_info("omapfb: configured for panel %s\n", fbdev
->panel
->name
);
1725 def_vxres
= def_vxres
? def_vxres
: fbdev
->panel
->x_res
;
1726 def_vyres
= def_vyres
? def_vyres
: fbdev
->panel
->y_res
;
1730 r
= ctrl_init(fbdev
);
1733 if (fbdev
->ctrl
->mmap
!= NULL
)
1734 omapfb_ops
.fb_mmap
= omapfb_mmap
;
1737 check_required_callbacks(fbdev
);
1739 r
= planes_init(fbdev
);
1744 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1745 /* Set DMA priority for EMIFF access to highest */
1746 if (cpu_class_is_omap1())
1747 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF
, 15);
1750 r
= ctrl_change_mode(fbdev
->fb_info
[0]);
1752 dev_err(fbdev
->dev
, "mode setting failed\n");
1756 /* GFX plane is enabled by default */
1757 r
= fbdev
->ctrl
->enable_plane(OMAPFB_PLANE_GFX
, 1);
1761 omapfb_set_update_mode(fbdev
, manual_update
?
1762 OMAPFB_MANUAL_UPDATE
: OMAPFB_AUTO_UPDATE
);
1765 r
= fbdev
->panel
->enable(fbdev
->panel
);
1770 r
= omapfb_register_sysfs(fbdev
);
1776 for (i
= 0; i
< fbdev
->mem_desc
.region_cnt
; i
++) {
1777 r
= register_framebuffer(fbdev
->fb_info
[i
]);
1780 "registering framebuffer %d failed\n", i
);
1783 vram
+= fbdev
->mem_desc
.region
[i
].size
;
1786 fbdev
->state
= OMAPFB_ACTIVE
;
1788 panel
= fbdev
->panel
;
1789 phz
= panel
->pixel_clock
* 1000;
1790 hhz
= phz
* 10 / (panel
->hfp
+ panel
->x_res
+ panel
->hbp
+ panel
->hsw
);
1791 vhz
= hhz
/ (panel
->vfp
+ panel
->y_res
+ panel
->vbp
+ panel
->vsw
);
1795 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1796 vram
, fbdev
->mem_desc
.region_cnt
);
1797 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1798 "vfreq %lu.%lu Hz\n",
1799 phz
/ 1000, hhz
/ 10000, hhz
% 10, vhz
/ 10, vhz
% 10);
1804 omapfb_free_resources(fbdev
, init_state
);
1809 static int omapfb_probe(struct platform_device
*pdev
)
1811 BUG_ON(fbdev_pdev
!= NULL
);
1813 /* Delay actual initialization until the LCD is registered */
1815 if (fbdev_panel
!= NULL
)
1816 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1820 void omapfb_register_panel(struct lcd_panel
*panel
)
1822 BUG_ON(fbdev_panel
!= NULL
);
1824 fbdev_panel
= panel
;
1825 if (fbdev_pdev
!= NULL
)
1826 omapfb_do_probe(fbdev_pdev
, fbdev_panel
);
1829 /* Called when the device is being detached from the driver */
1830 static int omapfb_remove(struct platform_device
*pdev
)
1832 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1833 enum omapfb_state saved_state
= fbdev
->state
;
1835 /* FIXME: wait till completion of pending events */
1837 fbdev
->state
= OMAPFB_DISABLED
;
1838 omapfb_free_resources(fbdev
, saved_state
);
1844 static int omapfb_suspend(struct platform_device
*pdev
, pm_message_t mesg
)
1846 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1849 omapfb_blank(FB_BLANK_POWERDOWN
, fbdev
->fb_info
[0]);
1854 static int omapfb_resume(struct platform_device
*pdev
)
1856 struct omapfb_device
*fbdev
= platform_get_drvdata(pdev
);
1859 omapfb_blank(FB_BLANK_UNBLANK
, fbdev
->fb_info
[0]);
1863 static struct platform_driver omapfb_driver
= {
1864 .probe
= omapfb_probe
,
1865 .remove
= omapfb_remove
,
1866 .suspend
= omapfb_suspend
,
1867 .resume
= omapfb_resume
,
1869 .name
= MODULE_NAME
,
1870 .owner
= THIS_MODULE
,
1876 /* Process kernel command line parameters */
1877 static int __init
omapfb_setup(char *options
)
1879 char *this_opt
= NULL
;
1882 pr_debug("omapfb: options %s\n", options
);
1884 if (!options
|| !*options
)
1887 while (!r
&& (this_opt
= strsep(&options
, ",")) != NULL
) {
1888 if (!strncmp(this_opt
, "accel", 5))
1890 else if (!strncmp(this_opt
, "vram:", 5)) {
1893 vram
= (simple_strtoul(this_opt
+ 5, &suffix
, 0));
1894 switch (suffix
[0]) {
1906 pr_debug("omapfb: invalid vram suffix %c\n",
1910 def_vram
[def_vram_cnt
++] = vram
;
1912 else if (!strncmp(this_opt
, "vxres:", 6))
1913 def_vxres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1914 else if (!strncmp(this_opt
, "vyres:", 6))
1915 def_vyres
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1916 else if (!strncmp(this_opt
, "rotate:", 7))
1917 def_rotate
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1918 else if (!strncmp(this_opt
, "mirror:", 7))
1919 def_mirror
= (simple_strtoul(this_opt
+ 7, NULL
, 0));
1920 else if (!strncmp(this_opt
, "manual_update", 13))
1923 pr_debug("omapfb: invalid option\n");
1933 /* Register both the driver and the device */
1934 static int __init
omapfb_init(void)
1939 if (fb_get_options("omapfb", &option
))
1941 omapfb_setup(option
);
1943 /* Register the driver with LDM */
1944 if (platform_driver_register(&omapfb_driver
)) {
1945 pr_debug("failed to register omapfb driver\n");
1952 static void __exit
omapfb_cleanup(void)
1954 platform_driver_unregister(&omapfb_driver
);
1957 module_param_named(accel
, def_accel
, uint
, 0664);
1958 module_param_array_named(vram
, def_vram
, ulong
, &def_vram_cnt
, 0664);
1959 module_param_named(vxres
, def_vxres
, long, 0664);
1960 module_param_named(vyres
, def_vyres
, long, 0664);
1961 module_param_named(rotate
, def_rotate
, uint
, 0664);
1962 module_param_named(mirror
, def_mirror
, uint
, 0664);
1963 module_param_named(manual_update
, manual_update
, bool, 0664);
1965 module_init(omapfb_init
);
1966 module_exit(omapfb_cleanup
);
1968 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1969 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1970 MODULE_LICENSE("GPL");