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>
28 #include <linux/uaccess.h>
30 #include <asm/mach-types.h>
31 #include <asm/arch/dma.h>
32 #include <asm/arch/omapfb.h>
34 #define MODULE_NAME "omapfb"
36 static unsigned int def_accel;
37 static unsigned long def_vram[OMAPFB_PLANE_NUM];
38 static int def_vram_cnt;
39 static unsigned long def_vxres;
40 static unsigned long def_vyres;
41 static unsigned int def_rotate;
42 static unsigned int def_mirror;
44 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
45 static int manual_update = 1;
47 static int manual_update;
50 static struct platform_device *fbdev_pdev;
51 static struct lcd_panel *fbdev_panel;
52 static struct omapfb_device *omapfb_dev;
54 struct caps_table_struct {
59 static struct caps_table_struct ctrl_caps[] = {
60 { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
61 { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
62 { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
63 { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
64 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
65 { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
66 { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" },
67 { OMAPFB_CAPS_WINDOW_ROTATE, "rotate window" },
68 { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" },
71 static struct caps_table_struct color_caps[] = {
72 { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
73 { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
74 { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
75 { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
76 { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
77 { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
78 { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
79 { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
80 { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
84 * ---------------------------------------------------------------------------
86 * ---------------------------------------------------------------------------
88 extern struct lcd_ctrl omap1_int_ctrl;
89 extern struct lcd_ctrl omap2_int_ctrl;
90 extern struct lcd_ctrl hwa742_ctrl;
91 extern struct lcd_ctrl blizzard_ctrl;
93 static struct lcd_ctrl *ctrls[] = {
94 #ifdef CONFIG_ARCH_OMAP1
100 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
103 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
108 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
109 #ifdef CONFIG_ARCH_OMAP1
110 extern struct lcd_ctrl_extif omap1_ext_if;
112 extern struct lcd_ctrl_extif omap2_ext_if;
116 static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
118 mutex_lock(&fbdev->rqueue_mutex);
121 static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
123 mutex_unlock(&fbdev->rqueue_mutex);
127 * ---------------------------------------------------------------------------
128 * LCD controller and LCD DMA
129 * ---------------------------------------------------------------------------
131 /* Lookup table to map elem size to elem type. */
132 static const int dma_elem_type[] = {
134 OMAP_DMA_DATA_TYPE_S8,
135 OMAP_DMA_DATA_TYPE_S16,
137 OMAP_DMA_DATA_TYPE_S32,
141 * Allocate resources needed for LCD controller and LCD DMA operations. Video
142 * memory is allocated from system memory according to the virtual display
143 * size, except if a bigger memory size is specified explicitly as a kernel
146 static int ctrl_init(struct omapfb_device *fbdev)
151 /* kernel/module vram parameters override boot tags/board config */
153 for (i = 0; i < def_vram_cnt; i++)
154 fbdev->mem_desc.region[i].size =
155 PAGE_ALIGN(def_vram[i]);
156 fbdev->mem_desc.region_cnt = i;
158 struct omapfb_platform_data *conf;
160 conf = fbdev->dev->platform_data;
161 fbdev->mem_desc = conf->mem_desc;
164 if (!fbdev->mem_desc.region_cnt) {
165 struct lcd_panel *panel = fbdev->panel;
167 int bpp = panel->bpp;
169 /* 12 bpp is packed in 16 bits */
172 def_size = def_vxres * def_vyres * bpp / 8;
173 fbdev->mem_desc.region_cnt = 1;
174 fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
176 r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
178 dev_err(fbdev->dev, "controller initialization failed (%d)\n",
184 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
185 dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
187 fbdev->mem_desc.region[i].paddr,
188 fbdev->mem_desc.region[i].vaddr,
189 fbdev->mem_desc.region[i].size);
195 static void ctrl_cleanup(struct omapfb_device *fbdev)
197 fbdev->ctrl->cleanup();
200 /* Must be called with fbdev->rqueue_mutex held. */
201 static int ctrl_change_mode(struct fb_info *fbi)
204 unsigned long offset;
205 struct omapfb_plane_struct *plane = fbi->par;
206 struct omapfb_device *fbdev = plane->fbdev;
207 struct fb_var_screeninfo *var = &fbi->var;
209 offset = var->yoffset * fbi->fix.line_length +
210 var->xoffset * var->bits_per_pixel / 8;
212 if (fbdev->ctrl->sync)
214 r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
215 offset, var->xres_virtual,
216 plane->info.pos_x, plane->info.pos_y,
217 var->xres, var->yres, plane->color_mode);
221 if (fbdev->ctrl->set_rotate != NULL)
222 if((r = fbdev->ctrl->set_rotate(var->rotate)) < 0)
225 if (fbdev->ctrl->set_scale != NULL)
226 r = fbdev->ctrl->set_scale(plane->idx,
227 var->xres, var->yres,
228 plane->info.out_width,
229 plane->info.out_height);
235 * ---------------------------------------------------------------------------
236 * fbdev framework callbacks and the ioctl interface
237 * ---------------------------------------------------------------------------
239 /* Called each time the omapfb device is opened */
240 static int omapfb_open(struct fb_info *info, int user)
245 static void omapfb_sync(struct fb_info *info);
247 /* Called when the omapfb device is closed. We make sure that any pending
248 * gfx DMA operations are ended, before we return. */
249 static int omapfb_release(struct fb_info *info, int user)
255 /* Store a single color palette entry into a pseudo palette or the hardware
256 * palette if one is available. For now we support only 16bpp and thus store
257 * the entry only to the pseudo palette.
259 static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
260 u_int blue, u_int transp, int update_hw_pal)
262 struct omapfb_plane_struct *plane = info->par;
263 struct omapfb_device *fbdev = plane->fbdev;
264 struct fb_var_screeninfo *var = &info->var;
267 switch (plane->color_mode) {
268 case OMAPFB_COLOR_YUV422:
269 case OMAPFB_COLOR_YUV420:
270 case OMAPFB_COLOR_YUY422:
273 case OMAPFB_COLOR_CLUT_8BPP:
274 case OMAPFB_COLOR_CLUT_4BPP:
275 case OMAPFB_COLOR_CLUT_2BPP:
276 case OMAPFB_COLOR_CLUT_1BPP:
277 if (fbdev->ctrl->setcolreg)
278 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
279 transp, update_hw_pal);
281 case OMAPFB_COLOR_RGB565:
282 case OMAPFB_COLOR_RGB444:
293 pal = ((red >> (16 - var->red.length)) <<
295 ((green >> (16 - var->green.length)) <<
297 (blue >> (16 - var->blue.length));
298 ((u32 *)(info->pseudo_palette))[regno] = pal;
307 static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
308 u_int transp, struct fb_info *info)
310 return _setcolreg(info, regno, red, green, blue, transp, 1);
313 static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
316 u16 *red, *green, *blue, *transp;
322 transp = cmap->transp;
325 for (count = 0; count < cmap->len; count++) {
328 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
329 count == cmap->len - 1);
337 static int omapfb_update_full_screen(struct fb_info *fbi);
339 static int omapfb_blank(int blank, struct fb_info *fbi)
341 struct omapfb_plane_struct *plane = fbi->par;
342 struct omapfb_device *fbdev = plane->fbdev;
346 omapfb_rqueue_lock(fbdev);
348 case VESA_NO_BLANKING:
349 if (fbdev->state == OMAPFB_SUSPENDED) {
350 if (fbdev->ctrl->resume)
351 fbdev->ctrl->resume();
352 fbdev->panel->enable(fbdev->panel);
353 fbdev->state = OMAPFB_ACTIVE;
354 if (fbdev->ctrl->get_update_mode() ==
355 OMAPFB_MANUAL_UPDATE)
360 if (fbdev->state == OMAPFB_ACTIVE) {
361 fbdev->panel->disable(fbdev->panel);
362 if (fbdev->ctrl->suspend)
363 fbdev->ctrl->suspend();
364 fbdev->state = OMAPFB_SUSPENDED;
370 omapfb_rqueue_unlock(fbdev);
372 if (r == 0 && do_update)
373 r = omapfb_update_full_screen(fbi);
378 static void omapfb_sync(struct fb_info *fbi)
380 struct omapfb_plane_struct *plane = fbi->par;
381 struct omapfb_device *fbdev = plane->fbdev;
383 omapfb_rqueue_lock(fbdev);
384 if (fbdev->ctrl->sync)
386 omapfb_rqueue_unlock(fbdev);
390 * Set fb_info.fix fields and also updates fbdev.
391 * When calling this fb_info.var must be set up already.
393 static void set_fb_fix(struct fb_info *fbi)
395 struct fb_fix_screeninfo *fix = &fbi->fix;
396 struct fb_var_screeninfo *var = &fbi->var;
397 struct omapfb_plane_struct *plane = fbi->par;
398 struct omapfb_mem_region *rg;
401 rg = &plane->fbdev->mem_desc.region[plane->idx];
402 fbi->screen_base = (char __iomem *)rg->vaddr;
403 fix->smem_start = rg->paddr;
404 fix->smem_len = rg->size;
406 fix->type = FB_TYPE_PACKED_PIXELS;
407 bpp = var->bits_per_pixel;
409 fix->visual = FB_VISUAL_PSEUDOCOLOR;
410 else switch (var->bits_per_pixel) {
413 fix->visual = FB_VISUAL_TRUECOLOR;
414 /* 12bpp is stored in 16 bits */
421 fix->visual = FB_VISUAL_PSEUDOCOLOR;
424 fix->accel = FB_ACCEL_OMAP1610;
425 fix->line_length = var->xres_virtual * bpp / 8;
428 static int set_color_mode(struct omapfb_plane_struct *plane,
429 struct fb_var_screeninfo *var)
431 switch (var->nonstd) {
434 case OMAPFB_COLOR_YUV422:
435 var->bits_per_pixel = 16;
436 plane->color_mode = var->nonstd;
438 case OMAPFB_COLOR_YUV420:
439 var->bits_per_pixel = 12;
440 plane->color_mode = var->nonstd;
442 case OMAPFB_COLOR_YUY422:
443 var->bits_per_pixel = 16;
444 plane->color_mode = var->nonstd;
450 switch (var->bits_per_pixel) {
452 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
455 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
458 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
461 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
464 var->bits_per_pixel = 16;
465 plane->color_mode = OMAPFB_COLOR_RGB444;
468 plane->color_mode = OMAPFB_COLOR_RGB565;
476 * Check the values in var against our capabilities and in case of out of
477 * bound values try to adjust them.
479 static int set_fb_var(struct fb_info *fbi,
480 struct fb_var_screeninfo *var)
483 unsigned long max_frame_size;
484 unsigned long line_size;
485 int xres_min, xres_max;
486 int yres_min, yres_max;
487 struct omapfb_plane_struct *plane = fbi->par;
488 struct omapfb_device *fbdev = plane->fbdev;
489 struct lcd_panel *panel = fbdev->panel;
491 if (set_color_mode(plane, var) < 0)
494 bpp = var->bits_per_pixel;
495 if (plane->color_mode == OMAPFB_COLOR_RGB444)
498 switch (var->rotate) {
501 xres_min = OMAPFB_PLANE_XRES_MIN;
502 xres_max = panel->x_res;
503 yres_min = OMAPFB_PLANE_YRES_MIN;
504 yres_max = panel->y_res;
505 if (cpu_is_omap15xx()) {
506 var->xres = panel->x_res;
507 var->yres = panel->y_res;
512 xres_min = OMAPFB_PLANE_YRES_MIN;
513 xres_max = panel->y_res;
514 yres_min = OMAPFB_PLANE_XRES_MIN;
515 yres_max = panel->x_res;
516 if (cpu_is_omap15xx()) {
517 var->xres = panel->y_res;
518 var->yres = panel->x_res;
525 if (var->xres < xres_min)
526 var->xres = xres_min;
527 if (var->yres < yres_min)
528 var->yres = yres_min;
529 if (var->xres > xres_max)
530 var->xres = xres_max;
531 if (var->yres > yres_max)
532 var->yres = yres_max;
534 if (var->xres_virtual < var->xres)
535 var->xres_virtual = var->xres;
536 if (var->yres_virtual < var->yres)
537 var->yres_virtual = var->yres;
538 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
539 line_size = var->xres_virtual * bpp / 8;
540 if (line_size * var->yres_virtual > max_frame_size) {
541 /* Try to keep yres_virtual first */
542 line_size = max_frame_size / var->yres_virtual;
543 var->xres_virtual = line_size * 8 / bpp;
544 if (var->xres_virtual < var->xres) {
545 /* Still doesn't fit. Shrink yres_virtual too */
546 var->xres_virtual = var->xres;
547 line_size = var->xres * bpp / 8;
548 var->yres_virtual = max_frame_size / line_size;
550 /* Recheck this, as the virtual size changed. */
551 if (var->xres_virtual < var->xres)
552 var->xres = var->xres_virtual;
553 if (var->yres_virtual < var->yres)
554 var->yres = var->yres_virtual;
555 if (var->xres < xres_min || var->yres < yres_min)
558 if (var->xres + var->xoffset > var->xres_virtual)
559 var->xoffset = var->xres_virtual - var->xres;
560 if (var->yres + var->yoffset > var->yres_virtual)
561 var->yoffset = var->yres_virtual - var->yres;
562 line_size = var->xres * bpp / 8;
564 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
565 var->red.offset = 8; var->red.length = 4;
566 var->red.msb_right = 0;
567 var->green.offset = 4; var->green.length = 4;
568 var->green.msb_right = 0;
569 var->blue.offset = 0; var->blue.length = 4;
570 var->blue.msb_right = 0;
572 var->red.offset = 11; var->red.length = 5;
573 var->red.msb_right = 0;
574 var->green.offset = 5; var->green.length = 6;
575 var->green.msb_right = 0;
576 var->blue.offset = 0; var->blue.length = 5;
577 var->blue.msb_right = 0;
584 /* pixclock in ps, the rest in pixclock */
585 var->pixclock = 10000000 / (panel->pixel_clock / 100);
586 var->left_margin = panel->hfp;
587 var->right_margin = panel->hbp;
588 var->upper_margin = panel->vfp;
589 var->lower_margin = panel->vbp;
590 var->hsync_len = panel->hsw;
591 var->vsync_len = panel->vsw;
593 /* TODO: get these from panel->config */
594 var->vmode = FB_VMODE_NONINTERLACED;
601 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
602 static void omapfb_rotate(struct fb_info *fbi, int rotate)
604 struct omapfb_plane_struct *plane = fbi->par;
605 struct omapfb_device *fbdev = plane->fbdev;
607 omapfb_rqueue_lock(fbdev);
608 if (rotate != fbi->var.rotate) {
609 struct fb_var_screeninfo *new_var = &fbdev->new_var;
611 memcpy(new_var, &fbi->var, sizeof(*new_var));
612 new_var->rotate = rotate;
613 if (set_fb_var(fbi, new_var) == 0 &&
614 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
615 memcpy(&fbi->var, new_var, sizeof(*new_var));
616 ctrl_change_mode(fbi);
619 omapfb_rqueue_unlock(fbdev);
623 * Set new x,y offsets in the virtual display for the visible area and switch
626 static int omapfb_pan_display(struct fb_var_screeninfo *var,
629 struct omapfb_plane_struct *plane = fbi->par;
630 struct omapfb_device *fbdev = plane->fbdev;
633 omapfb_rqueue_lock(fbdev);
634 if (var->xoffset != fbi->var.xoffset ||
635 var->yoffset != fbi->var.yoffset) {
636 struct fb_var_screeninfo *new_var = &fbdev->new_var;
638 memcpy(new_var, &fbi->var, sizeof(*new_var));
639 new_var->xoffset = var->xoffset;
640 new_var->yoffset = var->yoffset;
641 if (set_fb_var(fbi, new_var))
644 memcpy(&fbi->var, new_var, sizeof(*new_var));
645 ctrl_change_mode(fbi);
648 omapfb_rqueue_unlock(fbdev);
653 /* Set mirror to vertical axis and switch to the new mode. */
654 static int omapfb_mirror(struct fb_info *fbi, int mirror)
656 struct omapfb_plane_struct *plane = fbi->par;
657 struct omapfb_device *fbdev = plane->fbdev;
660 omapfb_rqueue_lock(fbdev);
661 mirror = mirror ? 1 : 0;
662 if (cpu_is_omap15xx())
664 else if (mirror != plane->info.mirror) {
665 plane->info.mirror = mirror;
666 r = ctrl_change_mode(fbi);
668 omapfb_rqueue_unlock(fbdev);
674 * Check values in var, try to adjust them in case of out of bound values if
675 * possible, or return error.
677 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
679 struct omapfb_plane_struct *plane = fbi->par;
680 struct omapfb_device *fbdev = plane->fbdev;
683 omapfb_rqueue_lock(fbdev);
684 if (fbdev->ctrl->sync != NULL)
686 r = set_fb_var(fbi, var);
687 omapfb_rqueue_unlock(fbdev);
693 * Switch to a new mode. The parameters for it has been check already by
696 static int omapfb_set_par(struct fb_info *fbi)
698 struct omapfb_plane_struct *plane = fbi->par;
699 struct omapfb_device *fbdev = plane->fbdev;
702 omapfb_rqueue_lock(fbdev);
704 r = ctrl_change_mode(fbi);
705 omapfb_rqueue_unlock(fbdev);
710 int omapfb_update_window_async(struct fb_info *fbi,
711 struct omapfb_update_window *win,
712 void (*callback)(void *),
716 struct omapfb_plane_struct *plane = fbi->par;
717 struct omapfb_device *fbdev = plane->fbdev;
718 struct fb_var_screeninfo *var = &fbi->var;
720 switch (var->rotate) {
723 xres = fbdev->panel->x_res;
724 yres = fbdev->panel->y_res;
728 xres = fbdev->panel->y_res;
729 yres = fbdev->panel->x_res;
735 if (win->x >= xres || win->y >= yres ||
736 win->out_x > xres || win->out_y > yres)
739 if (!fbdev->ctrl->update_window ||
740 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
743 if (win->x + win->width > xres)
744 win->width = xres - win->x;
745 if (win->y + win->height > yres)
746 win->height = yres - win->y;
747 if (win->out_x + win->out_width > xres)
748 win->out_width = xres - win->out_x;
749 if (win->out_y + win->out_height > yres)
750 win->out_height = yres - win->out_y;
751 if (!win->width || !win->height || !win->out_width || !win->out_height)
754 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
756 EXPORT_SYMBOL(omapfb_update_window_async);
758 static int omapfb_update_win(struct fb_info *fbi,
759 struct omapfb_update_window *win)
761 struct omapfb_plane_struct *plane = fbi->par;
764 omapfb_rqueue_lock(plane->fbdev);
765 ret = omapfb_update_window_async(fbi, win, NULL, 0);
766 omapfb_rqueue_unlock(plane->fbdev);
771 static int omapfb_update_full_screen(struct fb_info *fbi)
773 struct omapfb_plane_struct *plane = fbi->par;
774 struct omapfb_device *fbdev = plane->fbdev;
775 struct omapfb_update_window win;
778 if (!fbdev->ctrl->update_window ||
779 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
784 win.width = fbi->var.xres;
785 win.height = fbi->var.yres;
788 win.out_width = fbi->var.xres;
789 win.out_height = fbi->var.yres;
792 omapfb_rqueue_lock(fbdev);
793 r = fbdev->ctrl->update_window(fbi, &win, NULL, 0);
794 omapfb_rqueue_unlock(fbdev);
799 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
801 struct omapfb_plane_struct *plane = fbi->par;
802 struct omapfb_device *fbdev = plane->fbdev;
803 struct lcd_panel *panel = fbdev->panel;
804 struct omapfb_plane_info old_info;
807 if (pi->pos_x + pi->out_width > panel->x_res ||
808 pi->pos_y + pi->out_height > panel->y_res)
811 omapfb_rqueue_lock(fbdev);
812 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
814 * This plane's memory was freed, can't enable it
815 * until it's reallocated.
820 old_info = plane->info;
823 r = ctrl_change_mode(fbi);
825 plane->info = old_info;
829 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
831 plane->info = old_info;
835 omapfb_rqueue_unlock(fbdev);
839 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
841 struct omapfb_plane_struct *plane = fbi->par;
847 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
849 struct omapfb_plane_struct *plane = fbi->par;
850 struct omapfb_device *fbdev = plane->fbdev;
851 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
855 if (fbdev->ctrl->setup_mem == NULL)
857 if (mi->type > OMAPFB_MEMTYPE_MAX)
860 size = PAGE_ALIGN(mi->size);
861 omapfb_rqueue_lock(fbdev);
862 if (plane->info.enabled) {
866 if (rg->size != size || rg->type != mi->type) {
867 struct fb_var_screeninfo *new_var = &fbdev->new_var;
868 unsigned long old_size = rg->size;
869 u8 old_type = rg->type;
875 * size == 0 is a special case, for which we
876 * don't check / adjust the screen parameters.
877 * This isn't a problem since the plane can't
878 * be reenabled unless its size is > 0.
880 if (old_size != size && size) {
882 memcpy(new_var, &fbi->var, sizeof(*new_var));
883 r = set_fb_var(fbi, new_var);
889 if (fbdev->ctrl->sync)
891 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
893 /* Revert changes. */
900 if (old_size != size) {
902 memcpy(&fbi->var, new_var, sizeof(fbi->var));
906 * Set these explicitly to indicate that the
907 * plane memory is dealloce'd, the other
908 * screen parameters in var / fix are invalid.
910 fbi->fix.smem_start = 0;
911 fbi->fix.smem_len = 0;
916 omapfb_rqueue_unlock(fbdev);
921 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
923 struct omapfb_plane_struct *plane = fbi->par;
924 struct omapfb_device *fbdev = plane->fbdev;
925 struct omapfb_mem_region *rg;
927 rg = &fbdev->mem_desc.region[plane->idx];
928 memset(mi, 0, sizeof(*mi));
935 static int omapfb_set_color_key(struct omapfb_device *fbdev,
936 struct omapfb_color_key *ck)
940 if (!fbdev->ctrl->set_color_key)
943 omapfb_rqueue_lock(fbdev);
944 r = fbdev->ctrl->set_color_key(ck);
945 omapfb_rqueue_unlock(fbdev);
950 static int omapfb_get_color_key(struct omapfb_device *fbdev,
951 struct omapfb_color_key *ck)
955 if (!fbdev->ctrl->get_color_key)
958 omapfb_rqueue_lock(fbdev);
959 r = fbdev->ctrl->get_color_key(ck);
960 omapfb_rqueue_unlock(fbdev);
965 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
966 static int notifier_inited;
968 static void omapfb_init_notifier(void)
972 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
973 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
976 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
977 omapfb_notifier_callback_t callback,
982 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
985 if (!notifier_inited) {
986 omapfb_init_notifier();
990 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
991 unsigned long, void *))callback;
992 omapfb_nb->data = callback_data;
993 r = blocking_notifier_chain_register(
994 &omapfb_client_list[omapfb_nb->plane_idx],
998 if (omapfb_dev != NULL &&
999 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
1000 omapfb_dev->ctrl->bind_client(omapfb_nb);
1005 EXPORT_SYMBOL(omapfb_register_client);
1007 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
1009 return blocking_notifier_chain_unregister(
1010 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
1012 EXPORT_SYMBOL(omapfb_unregister_client);
1014 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
1018 if (!notifier_inited)
1019 /* no client registered yet */
1022 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1023 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1026 EXPORT_SYMBOL(omapfb_notify_clients);
1028 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1029 enum omapfb_update_mode mode)
1033 omapfb_rqueue_lock(fbdev);
1034 r = fbdev->ctrl->set_update_mode(mode);
1035 omapfb_rqueue_unlock(fbdev);
1040 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1044 omapfb_rqueue_lock(fbdev);
1045 r = fbdev->ctrl->get_update_mode();
1046 omapfb_rqueue_unlock(fbdev);
1051 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1052 struct omapfb_caps *caps)
1054 memset(caps, 0, sizeof(*caps));
1055 fbdev->ctrl->get_caps(plane, caps);
1056 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1059 /* For lcd testing */
1060 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1062 omapfb_rqueue_lock(fbdev);
1063 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1064 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1065 struct omapfb_update_window win;
1067 memset(&win, 0, sizeof(win));
1072 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0);
1074 omapfb_rqueue_unlock(fbdev);
1076 EXPORT_SYMBOL(omapfb_write_first_pixel);
1079 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1080 * here to be accessible by user mode code.
1082 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1085 struct omapfb_plane_struct *plane = fbi->par;
1086 struct omapfb_device *fbdev = plane->fbdev;
1087 struct fb_ops *ops = fbi->fbops;
1089 struct omapfb_update_window update_window;
1090 struct omapfb_plane_info plane_info;
1091 struct omapfb_mem_info mem_info;
1092 struct omapfb_color_key color_key;
1093 enum omapfb_update_mode update_mode;
1094 struct omapfb_caps caps;
1095 unsigned int mirror;
1104 if (get_user(p.mirror, (int __user *)arg))
1107 omapfb_mirror(fbi, p.mirror);
1109 case OMAPFB_SYNC_GFX:
1114 case OMAPFB_SET_UPDATE_MODE:
1115 if (get_user(p.update_mode, (int __user *)arg))
1118 r = omapfb_set_update_mode(fbdev, p.update_mode);
1120 case OMAPFB_GET_UPDATE_MODE:
1121 p.update_mode = omapfb_get_update_mode(fbdev);
1122 if (put_user(p.update_mode,
1123 (enum omapfb_update_mode __user *)arg))
1126 case OMAPFB_UPDATE_WINDOW_OLD:
1127 if (copy_from_user(&p.update_window, (void __user *)arg,
1128 sizeof(struct omapfb_update_window_old)))
1131 struct omapfb_update_window *u = &p.update_window;
1134 u->out_width = u->width;
1135 u->out_height = u->height;
1136 memset(u->reserved, 0, sizeof(u->reserved));
1137 r = omapfb_update_win(fbi, u);
1140 case OMAPFB_UPDATE_WINDOW:
1141 if (copy_from_user(&p.update_window, (void __user *)arg,
1142 sizeof(p.update_window)))
1145 r = omapfb_update_win(fbi, &p.update_window);
1147 case OMAPFB_SETUP_PLANE:
1148 if (copy_from_user(&p.plane_info, (void __user *)arg,
1149 sizeof(p.plane_info)))
1152 r = omapfb_setup_plane(fbi, &p.plane_info);
1154 case OMAPFB_QUERY_PLANE:
1155 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1157 if (copy_to_user((void __user *)arg, &p.plane_info,
1158 sizeof(p.plane_info)))
1161 case OMAPFB_SETUP_MEM:
1162 if (copy_from_user(&p.mem_info, (void __user *)arg,
1163 sizeof(p.mem_info)))
1166 r = omapfb_setup_mem(fbi, &p.mem_info);
1168 case OMAPFB_QUERY_MEM:
1169 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1171 if (copy_to_user((void __user *)arg, &p.mem_info,
1172 sizeof(p.mem_info)))
1175 case OMAPFB_SET_COLOR_KEY:
1176 if (copy_from_user(&p.color_key, (void __user *)arg,
1177 sizeof(p.color_key)))
1180 r = omapfb_set_color_key(fbdev, &p.color_key);
1182 case OMAPFB_GET_COLOR_KEY:
1183 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1185 if (copy_to_user((void __user *)arg, &p.color_key,
1186 sizeof(p.color_key)))
1189 case OMAPFB_GET_CAPS:
1190 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1191 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1194 case OMAPFB_LCD_TEST:
1198 if (get_user(test_num, (int __user *)arg)) {
1202 if (!fbdev->panel->run_test) {
1206 r = fbdev->panel->run_test(fbdev->panel, test_num);
1209 case OMAPFB_CTRL_TEST:
1213 if (get_user(test_num, (int __user *)arg)) {
1217 if (!fbdev->ctrl->run_test) {
1221 r = fbdev->ctrl->run_test(test_num);
1231 static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1233 struct omapfb_plane_struct *plane = info->par;
1234 struct omapfb_device *fbdev = plane->fbdev;
1237 omapfb_rqueue_lock(fbdev);
1238 r = fbdev->ctrl->mmap(info, vma);
1239 omapfb_rqueue_unlock(fbdev);
1245 * Callback table for the frame buffer framework. Some of these pointers
1246 * will be changed according to the current setting of fb_info->accel_flags.
1248 static struct fb_ops omapfb_ops = {
1249 .owner = THIS_MODULE,
1250 .fb_open = omapfb_open,
1251 .fb_release = omapfb_release,
1252 .fb_setcolreg = omapfb_setcolreg,
1253 .fb_setcmap = omapfb_setcmap,
1254 .fb_fillrect = cfb_fillrect,
1255 .fb_copyarea = cfb_copyarea,
1256 .fb_imageblit = cfb_imageblit,
1257 .fb_blank = omapfb_blank,
1258 .fb_ioctl = omapfb_ioctl,
1259 .fb_check_var = omapfb_check_var,
1260 .fb_set_par = omapfb_set_par,
1261 .fb_rotate = omapfb_rotate,
1262 .fb_pan_display = omapfb_pan_display,
1266 * ---------------------------------------------------------------------------
1268 * ---------------------------------------------------------------------------
1270 /* omapfbX sysfs entries */
1271 static ssize_t omapfb_show_caps_num(struct device *dev,
1272 struct device_attribute *attr, char *buf)
1274 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1277 struct omapfb_caps caps;
1281 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1282 omapfb_get_caps(fbdev, plane, &caps);
1283 size += snprintf(&buf[size], PAGE_SIZE - size,
1284 "plane#%d %#010x %#010x %#010x\n",
1285 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1291 static ssize_t omapfb_show_caps_text(struct device *dev,
1292 struct device_attribute *attr, char *buf)
1294 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1296 struct omapfb_caps caps;
1302 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1303 omapfb_get_caps(fbdev, plane, &caps);
1304 size += snprintf(&buf[size], PAGE_SIZE - size,
1305 "plane#%d:\n", plane);
1306 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1307 size < PAGE_SIZE; i++) {
1308 if (ctrl_caps[i].flag & caps.ctrl)
1309 size += snprintf(&buf[size], PAGE_SIZE - size,
1310 " %s\n", ctrl_caps[i].name);
1312 size += snprintf(&buf[size], PAGE_SIZE - size,
1313 " plane colors:\n");
1314 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1315 size < PAGE_SIZE; i++) {
1316 if (color_caps[i].flag & caps.plane_color)
1317 size += snprintf(&buf[size], PAGE_SIZE - size,
1318 " %s\n", color_caps[i].name);
1320 size += snprintf(&buf[size], PAGE_SIZE - size,
1321 " window colors:\n");
1322 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1323 size < PAGE_SIZE; i++) {
1324 if (color_caps[i].flag & caps.wnd_color)
1325 size += snprintf(&buf[size], PAGE_SIZE - size,
1326 " %s\n", color_caps[i].name);
1334 static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1335 static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1337 /* panel sysfs entries */
1338 static ssize_t omapfb_show_panel_name(struct device *dev,
1339 struct device_attribute *attr, char *buf)
1341 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1343 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1346 static ssize_t omapfb_show_bklight_level(struct device *dev,
1347 struct device_attribute *attr,
1350 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1353 if (fbdev->panel->get_bklight_level) {
1354 r = snprintf(buf, PAGE_SIZE, "%d\n",
1355 fbdev->panel->get_bklight_level(fbdev->panel));
1361 static ssize_t omapfb_store_bklight_level(struct device *dev,
1362 struct device_attribute *attr,
1363 const char *buf, size_t size)
1365 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1368 if (fbdev->panel->set_bklight_level) {
1371 if (sscanf(buf, "%10d", &level) == 1) {
1372 r = fbdev->panel->set_bklight_level(fbdev->panel,
1378 return r ? r : size;
1381 static ssize_t omapfb_show_bklight_max(struct device *dev,
1382 struct device_attribute *attr, char *buf)
1384 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1387 if (fbdev->panel->get_bklight_level) {
1388 r = snprintf(buf, PAGE_SIZE, "%d\n",
1389 fbdev->panel->get_bklight_max(fbdev->panel));
1395 static struct device_attribute dev_attr_panel_name =
1396 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1397 static DEVICE_ATTR(backlight_level, 0664,
1398 omapfb_show_bklight_level, omapfb_store_bklight_level);
1399 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1401 static struct attribute *panel_attrs[] = {
1402 &dev_attr_panel_name.attr,
1403 &dev_attr_backlight_level.attr,
1404 &dev_attr_backlight_max.attr,
1408 static struct attribute_group panel_attr_grp = {
1410 .attrs = panel_attrs,
1413 /* ctrl sysfs entries */
1414 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1415 struct device_attribute *attr, char *buf)
1417 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1419 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1422 static struct device_attribute dev_attr_ctrl_name =
1423 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1425 static struct attribute *ctrl_attrs[] = {
1426 &dev_attr_ctrl_name.attr,
1430 static struct attribute_group ctrl_attr_grp = {
1432 .attrs = ctrl_attrs,
1435 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1439 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1442 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1445 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1448 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1453 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1455 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1457 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1459 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1463 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1465 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1466 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1467 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1468 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1472 * ---------------------------------------------------------------------------
1474 * ---------------------------------------------------------------------------
1476 /* Initialize system fb_info object and set the default video mode.
1477 * The frame buffer memory already allocated by lcddma_init
1479 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1481 struct fb_var_screeninfo *var = &info->var;
1482 struct fb_fix_screeninfo *fix = &info->fix;
1485 info->fbops = &omapfb_ops;
1486 info->flags = FBINFO_FLAG_DEFAULT;
1488 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1490 info->pseudo_palette = fbdev->pseudo_palette;
1492 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1493 var->xres = def_vxres;
1494 var->yres = def_vyres;
1495 var->xres_virtual = def_vxres;
1496 var->yres_virtual = def_vyres;
1497 var->rotate = def_rotate;
1498 var->bits_per_pixel = fbdev->panel->bpp;
1500 set_fb_var(info, var);
1503 r = fb_alloc_cmap(&info->cmap, 16, 0);
1505 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1510 /* Release the fb_info object */
1511 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1513 fb_dealloc_cmap(&fbi->cmap);
1516 static void planes_cleanup(struct omapfb_device *fbdev)
1520 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1521 if (fbdev->fb_info[i] == NULL)
1523 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1524 framebuffer_release(fbdev->fb_info[i]);
1528 static int planes_init(struct omapfb_device *fbdev)
1530 struct fb_info *fbi;
1534 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1535 struct omapfb_plane_struct *plane;
1536 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1540 "unable to allocate memory for plane info\n");
1541 planes_cleanup(fbdev);
1546 plane->fbdev = fbdev;
1547 plane->info.mirror = def_mirror;
1548 fbdev->fb_info[i] = fbi;
1550 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1551 framebuffer_release(fbi);
1552 planes_cleanup(fbdev);
1555 plane->info.out_width = fbi->var.xres;
1556 plane->info.out_height = fbi->var.yres;
1562 * Free driver resources. Can be called to rollback an aborted initialization
1565 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1571 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1572 unregister_framebuffer(fbdev->fb_info[i]);
1574 omapfb_unregister_sysfs(fbdev);
1576 fbdev->panel->disable(fbdev->panel);
1578 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1580 planes_cleanup(fbdev);
1582 ctrl_cleanup(fbdev);
1584 fbdev->panel->cleanup(fbdev->panel);
1586 dev_set_drvdata(fbdev->dev, NULL);
1589 /* nothing to free */
1596 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1598 struct omapfb_platform_data *conf;
1602 conf = fbdev->dev->platform_data;
1606 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1607 name[sizeof(name) - 1] = '\0';
1609 if (strcmp(name, "internal") == 0) {
1610 fbdev->ctrl = fbdev->int_ctrl;
1614 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1615 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1616 if (strcmp(ctrls[i]->name, name) == 0) {
1617 fbdev->ctrl = ctrls[i];
1622 if (fbdev->ctrl == NULL) {
1623 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1630 static void check_required_callbacks(struct omapfb_device *fbdev)
1632 #define _C(x) (fbdev->ctrl->x != NULL)
1633 #define _P(x) (fbdev->panel->x != NULL)
1634 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1635 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1636 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1637 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1644 * Called by LDM binding to probe and attach a new device.
1645 * Initialization sequence:
1646 * 1. allocate system omapfb_device structure
1647 * 2. select controller type according to platform configuration
1649 * 3. init LCD controller and LCD DMA
1650 * 4. init system fb_info structure for all planes
1651 * 5. setup video mode for first plane and enable it
1652 * 6. enable LCD panel
1653 * 7. register sysfs attributes
1654 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1656 static int omapfb_do_probe(struct platform_device *pdev,
1657 struct lcd_panel *panel)
1659 struct omapfb_device *fbdev = NULL;
1661 unsigned long phz, hhz, vhz;
1668 if (pdev->num_resources != 0) {
1669 dev_err(&pdev->dev, "probed for an unknown device\n");
1674 if (pdev->dev.platform_data == NULL) {
1675 dev_err(&pdev->dev, "missing platform data\n");
1680 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1681 if (fbdev == NULL) {
1683 "unable to allocate memory for device info\n");
1689 fbdev->dev = &pdev->dev;
1690 fbdev->panel = panel;
1691 platform_set_drvdata(pdev, fbdev);
1693 mutex_init(&fbdev->rqueue_mutex);
1695 #ifdef CONFIG_ARCH_OMAP1
1696 fbdev->int_ctrl = &omap1_int_ctrl;
1697 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1698 fbdev->ext_if = &omap1_ext_if;
1701 fbdev->int_ctrl = &omap2_int_ctrl;
1702 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1703 fbdev->ext_if = &omap2_ext_if;
1706 if (omapfb_find_ctrl(fbdev) < 0) {
1708 "LCD controller not found, board not supported\n");
1713 r = fbdev->panel->init(fbdev->panel, fbdev);
1717 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1719 def_vxres = def_vxres ? : fbdev->panel->x_res;
1720 def_vyres = def_vyres ? : fbdev->panel->y_res;
1724 r = ctrl_init(fbdev);
1727 if (fbdev->ctrl->mmap != NULL)
1728 omapfb_ops.fb_mmap = omapfb_mmap;
1731 check_required_callbacks(fbdev);
1733 r = planes_init(fbdev);
1738 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1739 /* Set DMA priority for EMIFF access to highest */
1740 if (cpu_class_is_omap1())
1741 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1744 r = ctrl_change_mode(fbdev->fb_info[0]);
1746 dev_err(fbdev->dev, "mode setting failed\n");
1750 /* GFX plane is enabled by default */
1751 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1755 omapfb_set_update_mode(fbdev, manual_update ?
1756 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1759 r = fbdev->panel->enable(fbdev->panel);
1764 r = omapfb_register_sysfs(fbdev);
1770 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1771 r = register_framebuffer(fbdev->fb_info[i]);
1774 "registering framebuffer %d failed\n", i);
1777 vram += fbdev->mem_desc.region[i].size;
1780 fbdev->state = OMAPFB_ACTIVE;
1782 panel = fbdev->panel;
1783 phz = panel->pixel_clock * 1000;
1784 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1785 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1789 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1790 vram, fbdev->mem_desc.region_cnt);
1791 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1792 "vfreq %lu.%lu Hz\n",
1793 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1798 omapfb_free_resources(fbdev, init_state);
1803 static int omapfb_probe(struct platform_device *pdev)
1805 BUG_ON(fbdev_pdev != NULL);
1807 /* Delay actual initialization until the LCD is registered */
1809 if (fbdev_panel != NULL)
1810 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1814 void omapfb_register_panel(struct lcd_panel *panel)
1816 BUG_ON(fbdev_panel != NULL);
1818 fbdev_panel = panel;
1819 if (fbdev_pdev != NULL)
1820 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1823 /* Called when the device is being detached from the driver */
1824 static int omapfb_remove(struct platform_device *pdev)
1826 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1827 enum omapfb_state saved_state = fbdev->state;
1829 /* FIXME: wait till completion of pending events */
1831 fbdev->state = OMAPFB_DISABLED;
1832 omapfb_free_resources(fbdev, saved_state);
1838 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1840 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1842 omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
1848 static int omapfb_resume(struct platform_device *pdev)
1850 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1852 omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
1856 static struct platform_driver omapfb_driver = {
1857 .probe = omapfb_probe,
1858 .remove = omapfb_remove,
1859 .suspend = omapfb_suspend,
1860 .resume = omapfb_resume,
1862 .name = MODULE_NAME,
1863 .owner = THIS_MODULE,
1869 /* Process kernel command line parameters */
1870 static int __init omapfb_setup(char *options)
1872 char *this_opt = NULL;
1875 pr_debug("omapfb: options %s\n", options);
1877 if (!options || !*options)
1880 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1881 if (!strncmp(this_opt, "accel", 5))
1883 else if (!strncmp(this_opt, "vram:", 5)) {
1886 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1887 switch (suffix[0]) {
1899 pr_debug("omapfb: invalid vram suffix %c\n",
1903 def_vram[def_vram_cnt++] = vram;
1905 else if (!strncmp(this_opt, "vxres:", 6))
1906 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1907 else if (!strncmp(this_opt, "vyres:", 6))
1908 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1909 else if (!strncmp(this_opt, "rotate:", 7))
1910 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1911 else if (!strncmp(this_opt, "mirror:", 7))
1912 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1913 else if (!strncmp(this_opt, "manual_update", 13))
1916 pr_debug("omapfb: invalid option\n");
1926 /* Register both the driver and the device */
1927 static int __init omapfb_init(void)
1932 if (fb_get_options("omapfb", &option))
1934 omapfb_setup(option);
1936 /* Register the driver with LDM */
1937 if (platform_driver_register(&omapfb_driver)) {
1938 pr_debug("failed to register omapfb driver\n");
1945 static void __exit omapfb_cleanup(void)
1947 platform_driver_unregister(&omapfb_driver);
1950 module_param_named(accel, def_accel, uint, 0664);
1951 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1952 module_param_named(vxres, def_vxres, long, 0664);
1953 module_param_named(vyres, def_vyres, long, 0664);
1954 module_param_named(rotate, def_rotate, uint, 0664);
1955 module_param_named(mirror, def_mirror, uint, 0664);
1956 module_param_named(manual_update, manual_update, bool, 0664);
1958 module_init(omapfb_init);
1959 module_exit(omapfb_cleanup);
1961 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1962 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1963 MODULE_LICENSE("GPL");