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 if((r = fbdev->ctrl->set_rotate(var->rotate)) < 0)
226 if ((fbdev->ctrl->set_scale != NULL) && (plane->idx > 0))
227 r = fbdev->ctrl->set_scale(plane->idx,
228 var->xres, var->yres,
229 plane->info.out_width,
230 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 VESA_NO_BLANKING:
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)
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 fix->smem_start = rg->paddr;
407 fix->smem_len = rg->size;
409 fix->type = FB_TYPE_PACKED_PIXELS;
410 bpp = var->bits_per_pixel;
412 fix->visual = FB_VISUAL_PSEUDOCOLOR;
413 else switch (var->bits_per_pixel) {
416 fix->visual = FB_VISUAL_TRUECOLOR;
417 /* 12bpp is stored in 16 bits */
424 fix->visual = FB_VISUAL_PSEUDOCOLOR;
427 fix->accel = FB_ACCEL_OMAP1610;
428 fix->line_length = var->xres_virtual * bpp / 8;
431 static int set_color_mode(struct omapfb_plane_struct *plane,
432 struct fb_var_screeninfo *var)
434 switch (var->nonstd) {
437 case OMAPFB_COLOR_YUV422:
438 var->bits_per_pixel = 16;
439 plane->color_mode = var->nonstd;
441 case OMAPFB_COLOR_YUV420:
442 var->bits_per_pixel = 12;
443 plane->color_mode = var->nonstd;
445 case OMAPFB_COLOR_YUY422:
446 var->bits_per_pixel = 16;
447 plane->color_mode = var->nonstd;
453 switch (var->bits_per_pixel) {
455 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
458 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
461 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
464 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
467 var->bits_per_pixel = 16;
468 plane->color_mode = OMAPFB_COLOR_RGB444;
471 plane->color_mode = OMAPFB_COLOR_RGB565;
479 * Check the values in var against our capabilities and in case of out of
480 * bound values try to adjust them.
482 static int set_fb_var(struct fb_info *fbi,
483 struct fb_var_screeninfo *var)
486 unsigned long max_frame_size;
487 unsigned long line_size;
488 int xres_min, xres_max;
489 int yres_min, yres_max;
490 struct omapfb_plane_struct *plane = fbi->par;
491 struct omapfb_device *fbdev = plane->fbdev;
492 struct lcd_panel *panel = fbdev->panel;
494 if (set_color_mode(plane, var) < 0)
497 bpp = var->bits_per_pixel;
498 if (plane->color_mode == OMAPFB_COLOR_RGB444)
501 switch (var->rotate) {
504 xres_min = OMAPFB_PLANE_XRES_MIN;
505 xres_max = panel->x_res;
506 yres_min = OMAPFB_PLANE_YRES_MIN;
507 yres_max = panel->y_res;
508 if (cpu_is_omap15xx()) {
509 var->xres = panel->x_res;
510 var->yres = panel->y_res;
515 xres_min = OMAPFB_PLANE_YRES_MIN;
516 xres_max = panel->y_res;
517 yres_min = OMAPFB_PLANE_XRES_MIN;
518 yres_max = panel->x_res;
519 if (cpu_is_omap15xx()) {
520 var->xres = panel->y_res;
521 var->yres = panel->x_res;
528 if (var->xres < xres_min)
529 var->xres = xres_min;
530 if (var->yres < yres_min)
531 var->yres = yres_min;
532 if (var->xres > xres_max)
533 var->xres = xres_max;
534 if (var->yres > yres_max)
535 var->yres = yres_max;
537 if (var->xres_virtual < var->xres)
538 var->xres_virtual = var->xres;
539 if (var->yres_virtual < var->yres)
540 var->yres_virtual = var->yres;
541 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
542 line_size = var->xres_virtual * bpp / 8;
543 if (line_size * var->yres_virtual > max_frame_size) {
544 /* Try to keep yres_virtual first */
545 line_size = max_frame_size / var->yres_virtual;
546 var->xres_virtual = line_size * 8 / bpp;
547 if (var->xres_virtual < var->xres) {
548 /* Still doesn't fit. Shrink yres_virtual too */
549 var->xres_virtual = var->xres;
550 line_size = var->xres * bpp / 8;
551 var->yres_virtual = max_frame_size / line_size;
553 /* Recheck this, as the virtual size changed. */
554 if (var->xres_virtual < var->xres)
555 var->xres = var->xres_virtual;
556 if (var->yres_virtual < var->yres)
557 var->yres = var->yres_virtual;
558 if (var->xres < xres_min || var->yres < yres_min)
561 if (var->xres + var->xoffset > var->xres_virtual)
562 var->xoffset = var->xres_virtual - var->xres;
563 if (var->yres + var->yoffset > var->yres_virtual)
564 var->yoffset = var->yres_virtual - var->yres;
566 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
567 var->red.offset = 8; var->red.length = 4;
568 var->red.msb_right = 0;
569 var->green.offset = 4; var->green.length = 4;
570 var->green.msb_right = 0;
571 var->blue.offset = 0; var->blue.length = 4;
572 var->blue.msb_right = 0;
574 var->red.offset = 11; var->red.length = 5;
575 var->red.msb_right = 0;
576 var->green.offset = 5; var->green.length = 6;
577 var->green.msb_right = 0;
578 var->blue.offset = 0; var->blue.length = 5;
579 var->blue.msb_right = 0;
586 /* pixclock in ps, the rest in pixclock */
587 var->pixclock = 10000000 / (panel->pixel_clock / 100);
588 var->left_margin = panel->hfp;
589 var->right_margin = panel->hbp;
590 var->upper_margin = panel->vfp;
591 var->lower_margin = panel->vbp;
592 var->hsync_len = panel->hsw;
593 var->vsync_len = panel->vsw;
595 /* TODO: get these from panel->config */
596 var->vmode = FB_VMODE_NONINTERLACED;
603 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
604 static void omapfb_rotate(struct fb_info *fbi, int rotate)
606 struct omapfb_plane_struct *plane = fbi->par;
607 struct omapfb_device *fbdev = plane->fbdev;
609 omapfb_rqueue_lock(fbdev);
610 if (rotate != fbi->var.rotate) {
611 struct fb_var_screeninfo *new_var = &fbdev->new_var;
613 memcpy(new_var, &fbi->var, sizeof(*new_var));
614 new_var->rotate = rotate;
615 if (set_fb_var(fbi, new_var) == 0 &&
616 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
617 memcpy(&fbi->var, new_var, sizeof(*new_var));
618 ctrl_change_mode(fbi);
621 omapfb_rqueue_unlock(fbdev);
625 * Set new x,y offsets in the virtual display for the visible area and switch
628 static int omapfb_pan_display(struct fb_var_screeninfo *var,
631 struct omapfb_plane_struct *plane = fbi->par;
632 struct omapfb_device *fbdev = plane->fbdev;
635 omapfb_rqueue_lock(fbdev);
636 if (var->xoffset != fbi->var.xoffset ||
637 var->yoffset != fbi->var.yoffset) {
638 struct fb_var_screeninfo *new_var = &fbdev->new_var;
640 memcpy(new_var, &fbi->var, sizeof(*new_var));
641 new_var->xoffset = var->xoffset;
642 new_var->yoffset = var->yoffset;
643 if (set_fb_var(fbi, new_var))
646 memcpy(&fbi->var, new_var, sizeof(*new_var));
647 ctrl_change_mode(fbi);
650 omapfb_rqueue_unlock(fbdev);
655 /* Set mirror to vertical axis and switch to the new mode. */
656 static int omapfb_mirror(struct fb_info *fbi, int mirror)
658 struct omapfb_plane_struct *plane = fbi->par;
659 struct omapfb_device *fbdev = plane->fbdev;
662 omapfb_rqueue_lock(fbdev);
663 mirror = mirror ? 1 : 0;
664 if (cpu_is_omap15xx())
666 else if (mirror != plane->info.mirror) {
667 plane->info.mirror = mirror;
668 r = ctrl_change_mode(fbi);
670 omapfb_rqueue_unlock(fbdev);
676 * Check values in var, try to adjust them in case of out of bound values if
677 * possible, or return error.
679 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
681 struct omapfb_plane_struct *plane = fbi->par;
682 struct omapfb_device *fbdev = plane->fbdev;
685 omapfb_rqueue_lock(fbdev);
686 if (fbdev->ctrl->sync != NULL)
688 r = set_fb_var(fbi, var);
689 omapfb_rqueue_unlock(fbdev);
695 * Switch to a new mode. The parameters for it has been check already by
698 static int omapfb_set_par(struct fb_info *fbi)
700 struct omapfb_plane_struct *plane = fbi->par;
701 struct omapfb_device *fbdev = plane->fbdev;
704 omapfb_rqueue_lock(fbdev);
706 r = ctrl_change_mode(fbi);
707 omapfb_rqueue_unlock(fbdev);
712 int omapfb_update_window_async(struct fb_info *fbi,
713 struct omapfb_update_window *win,
714 void (*callback)(void *),
718 struct omapfb_plane_struct *plane = fbi->par;
719 struct omapfb_device *fbdev = plane->fbdev;
720 struct fb_var_screeninfo *var = &fbi->var;
722 switch (var->rotate) {
725 xres = fbdev->panel->x_res;
726 yres = fbdev->panel->y_res;
730 xres = fbdev->panel->y_res;
731 yres = fbdev->panel->x_res;
737 if (win->x >= xres || win->y >= yres ||
738 win->out_x > xres || win->out_y > yres)
741 if (!fbdev->ctrl->update_window ||
742 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
745 if (win->x + win->width > xres)
746 win->width = xres - win->x;
747 if (win->y + win->height > yres)
748 win->height = yres - win->y;
749 if (win->out_x + win->out_width > xres)
750 win->out_width = xres - win->out_x;
751 if (win->out_y + win->out_height > yres)
752 win->out_height = yres - win->out_y;
753 if (!win->width || !win->height || !win->out_width || !win->out_height)
756 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
758 EXPORT_SYMBOL(omapfb_update_window_async);
760 static int omapfb_update_win(struct fb_info *fbi,
761 struct omapfb_update_window *win)
763 struct omapfb_plane_struct *plane = fbi->par;
766 omapfb_rqueue_lock(plane->fbdev);
767 ret = omapfb_update_window_async(fbi, win, NULL, NULL);
768 omapfb_rqueue_unlock(plane->fbdev);
773 static int omapfb_update_full_screen(struct fb_info *fbi)
775 struct omapfb_plane_struct *plane = fbi->par;
776 struct omapfb_device *fbdev = plane->fbdev;
777 struct omapfb_update_window win;
780 if (!fbdev->ctrl->update_window ||
781 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
786 win.width = fbi->var.xres;
787 win.height = fbi->var.yres;
790 win.out_width = fbi->var.xres;
791 win.out_height = fbi->var.yres;
794 omapfb_rqueue_lock(fbdev);
795 r = fbdev->ctrl->update_window(fbi, &win, NULL, NULL);
796 omapfb_rqueue_unlock(fbdev);
801 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
803 struct omapfb_plane_struct *plane = fbi->par;
804 struct omapfb_device *fbdev = plane->fbdev;
805 struct lcd_panel *panel = fbdev->panel;
806 struct omapfb_plane_info old_info;
809 if (pi->pos_x + pi->out_width > panel->x_res ||
810 pi->pos_y + pi->out_height > panel->y_res)
813 omapfb_rqueue_lock(fbdev);
814 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
816 * This plane's memory was freed, can't enable it
817 * until it's reallocated.
822 old_info = plane->info;
825 r = ctrl_change_mode(fbi);
827 plane->info = old_info;
831 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
833 plane->info = old_info;
837 omapfb_rqueue_unlock(fbdev);
841 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
843 struct omapfb_plane_struct *plane = fbi->par;
849 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
851 struct omapfb_plane_struct *plane = fbi->par;
852 struct omapfb_device *fbdev = plane->fbdev;
853 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
857 if (fbdev->ctrl->setup_mem == NULL)
859 if (mi->type > OMAPFB_MEMTYPE_MAX)
862 size = PAGE_ALIGN(mi->size);
863 omapfb_rqueue_lock(fbdev);
864 if (plane->info.enabled) {
868 if (rg->size != size || rg->type != mi->type) {
869 struct fb_var_screeninfo *new_var = &fbdev->new_var;
870 unsigned long old_size = rg->size;
871 u8 old_type = rg->type;
877 * size == 0 is a special case, for which we
878 * don't check / adjust the screen parameters.
879 * This isn't a problem since the plane can't
880 * be reenabled unless its size is > 0.
882 if (old_size != size && size) {
884 memcpy(new_var, &fbi->var, sizeof(*new_var));
885 r = set_fb_var(fbi, new_var);
891 if (fbdev->ctrl->sync)
893 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
895 /* Revert changes. */
902 if (old_size != size) {
904 memcpy(&fbi->var, new_var, sizeof(fbi->var));
908 * Set these explicitly to indicate that the
909 * plane memory is dealloce'd, the other
910 * screen parameters in var / fix are invalid.
912 fbi->fix.smem_start = 0;
913 fbi->fix.smem_len = 0;
918 omapfb_rqueue_unlock(fbdev);
923 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
925 struct omapfb_plane_struct *plane = fbi->par;
926 struct omapfb_device *fbdev = plane->fbdev;
927 struct omapfb_mem_region *rg;
929 rg = &fbdev->mem_desc.region[plane->idx];
930 memset(mi, 0, sizeof(*mi));
937 static int omapfb_set_color_key(struct omapfb_device *fbdev,
938 struct omapfb_color_key *ck)
942 if (!fbdev->ctrl->set_color_key)
945 omapfb_rqueue_lock(fbdev);
946 r = fbdev->ctrl->set_color_key(ck);
947 omapfb_rqueue_unlock(fbdev);
952 static int omapfb_get_color_key(struct omapfb_device *fbdev,
953 struct omapfb_color_key *ck)
957 if (!fbdev->ctrl->get_color_key)
960 omapfb_rqueue_lock(fbdev);
961 r = fbdev->ctrl->get_color_key(ck);
962 omapfb_rqueue_unlock(fbdev);
967 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
968 static int notifier_inited;
970 static void omapfb_init_notifier(void)
974 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
975 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
978 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
979 omapfb_notifier_callback_t callback,
984 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
987 if (!notifier_inited) {
988 omapfb_init_notifier();
992 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
993 unsigned long, void *))callback;
994 omapfb_nb->data = callback_data;
995 r = blocking_notifier_chain_register(
996 &omapfb_client_list[omapfb_nb->plane_idx],
1000 if (omapfb_dev != NULL &&
1001 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
1002 omapfb_dev->ctrl->bind_client(omapfb_nb);
1007 EXPORT_SYMBOL(omapfb_register_client);
1009 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
1011 return blocking_notifier_chain_unregister(
1012 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
1014 EXPORT_SYMBOL(omapfb_unregister_client);
1016 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
1020 if (!notifier_inited)
1021 /* no client registered yet */
1024 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1025 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1028 EXPORT_SYMBOL(omapfb_notify_clients);
1030 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1031 enum omapfb_update_mode mode)
1035 omapfb_rqueue_lock(fbdev);
1036 r = fbdev->ctrl->set_update_mode(mode);
1037 omapfb_rqueue_unlock(fbdev);
1042 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1046 omapfb_rqueue_lock(fbdev);
1047 r = fbdev->ctrl->get_update_mode();
1048 omapfb_rqueue_unlock(fbdev);
1053 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1054 struct omapfb_caps *caps)
1056 memset(caps, 0, sizeof(*caps));
1057 fbdev->ctrl->get_caps(plane, caps);
1058 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1061 /* For lcd testing */
1062 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1064 omapfb_rqueue_lock(fbdev);
1065 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1066 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1067 struct omapfb_update_window win;
1069 memset(&win, 0, sizeof(win));
1074 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, NULL);
1076 omapfb_rqueue_unlock(fbdev);
1078 EXPORT_SYMBOL(omapfb_write_first_pixel);
1081 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1082 * here to be accessible by user mode code.
1084 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1087 struct omapfb_plane_struct *plane = fbi->par;
1088 struct omapfb_device *fbdev = plane->fbdev;
1089 struct fb_ops *ops = fbi->fbops;
1091 struct omapfb_update_window update_window;
1092 struct omapfb_plane_info plane_info;
1093 struct omapfb_mem_info mem_info;
1094 struct omapfb_color_key color_key;
1095 enum omapfb_update_mode update_mode;
1096 struct omapfb_caps caps;
1097 unsigned int mirror;
1106 if (get_user(p.mirror, (int __user *)arg))
1109 omapfb_mirror(fbi, p.mirror);
1111 case OMAPFB_SYNC_GFX:
1116 case OMAPFB_SET_UPDATE_MODE:
1117 if (get_user(p.update_mode, (int __user *)arg))
1120 r = omapfb_set_update_mode(fbdev, p.update_mode);
1122 case OMAPFB_GET_UPDATE_MODE:
1123 p.update_mode = omapfb_get_update_mode(fbdev);
1124 if (put_user(p.update_mode,
1125 (enum omapfb_update_mode __user *)arg))
1128 case OMAPFB_UPDATE_WINDOW_OLD:
1129 if (copy_from_user(&p.update_window, (void __user *)arg,
1130 sizeof(struct omapfb_update_window_old)))
1133 struct omapfb_update_window *u = &p.update_window;
1136 u->out_width = u->width;
1137 u->out_height = u->height;
1138 memset(u->reserved, 0, sizeof(u->reserved));
1139 r = omapfb_update_win(fbi, u);
1142 case OMAPFB_UPDATE_WINDOW:
1143 if (copy_from_user(&p.update_window, (void __user *)arg,
1144 sizeof(p.update_window)))
1147 r = omapfb_update_win(fbi, &p.update_window);
1149 case OMAPFB_SETUP_PLANE:
1150 if (copy_from_user(&p.plane_info, (void __user *)arg,
1151 sizeof(p.plane_info)))
1154 r = omapfb_setup_plane(fbi, &p.plane_info);
1156 case OMAPFB_QUERY_PLANE:
1157 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1159 if (copy_to_user((void __user *)arg, &p.plane_info,
1160 sizeof(p.plane_info)))
1163 case OMAPFB_SETUP_MEM:
1164 if (copy_from_user(&p.mem_info, (void __user *)arg,
1165 sizeof(p.mem_info)))
1168 r = omapfb_setup_mem(fbi, &p.mem_info);
1170 case OMAPFB_QUERY_MEM:
1171 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1173 if (copy_to_user((void __user *)arg, &p.mem_info,
1174 sizeof(p.mem_info)))
1177 case OMAPFB_SET_COLOR_KEY:
1178 if (copy_from_user(&p.color_key, (void __user *)arg,
1179 sizeof(p.color_key)))
1182 r = omapfb_set_color_key(fbdev, &p.color_key);
1184 case OMAPFB_GET_COLOR_KEY:
1185 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1187 if (copy_to_user((void __user *)arg, &p.color_key,
1188 sizeof(p.color_key)))
1191 case OMAPFB_GET_CAPS:
1192 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1193 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1196 case OMAPFB_LCD_TEST:
1200 if (get_user(test_num, (int __user *)arg)) {
1204 if (!fbdev->panel->run_test) {
1208 r = fbdev->panel->run_test(fbdev->panel, test_num);
1211 case OMAPFB_CTRL_TEST:
1215 if (get_user(test_num, (int __user *)arg)) {
1219 if (!fbdev->ctrl->run_test) {
1223 r = fbdev->ctrl->run_test(test_num);
1233 static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1235 struct omapfb_plane_struct *plane = info->par;
1236 struct omapfb_device *fbdev = plane->fbdev;
1239 omapfb_rqueue_lock(fbdev);
1240 r = fbdev->ctrl->mmap(info, vma);
1241 omapfb_rqueue_unlock(fbdev);
1247 * Callback table for the frame buffer framework. Some of these pointers
1248 * will be changed according to the current setting of fb_info->accel_flags.
1250 static struct fb_ops omapfb_ops = {
1251 .owner = THIS_MODULE,
1252 .fb_open = omapfb_open,
1253 .fb_release = omapfb_release,
1254 .fb_setcolreg = omapfb_setcolreg,
1255 .fb_setcmap = omapfb_setcmap,
1256 .fb_fillrect = cfb_fillrect,
1257 .fb_copyarea = cfb_copyarea,
1258 .fb_imageblit = cfb_imageblit,
1259 .fb_blank = omapfb_blank,
1260 .fb_ioctl = omapfb_ioctl,
1261 .fb_check_var = omapfb_check_var,
1262 .fb_set_par = omapfb_set_par,
1263 .fb_rotate = omapfb_rotate,
1264 .fb_pan_display = omapfb_pan_display,
1268 * ---------------------------------------------------------------------------
1270 * ---------------------------------------------------------------------------
1272 /* omapfbX sysfs entries */
1273 static ssize_t omapfb_show_caps_num(struct device *dev,
1274 struct device_attribute *attr, char *buf)
1276 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1279 struct omapfb_caps caps;
1283 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1284 omapfb_get_caps(fbdev, plane, &caps);
1285 size += snprintf(&buf[size], PAGE_SIZE - size,
1286 "plane#%d %#010x %#010x %#010x\n",
1287 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1293 static ssize_t omapfb_show_caps_text(struct device *dev,
1294 struct device_attribute *attr, char *buf)
1296 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1298 struct omapfb_caps caps;
1304 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1305 omapfb_get_caps(fbdev, plane, &caps);
1306 size += snprintf(&buf[size], PAGE_SIZE - size,
1307 "plane#%d:\n", plane);
1308 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1309 size < PAGE_SIZE; i++) {
1310 if (ctrl_caps[i].flag & caps.ctrl)
1311 size += snprintf(&buf[size], PAGE_SIZE - size,
1312 " %s\n", ctrl_caps[i].name);
1314 size += snprintf(&buf[size], PAGE_SIZE - size,
1315 " plane colors:\n");
1316 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1317 size < PAGE_SIZE; i++) {
1318 if (color_caps[i].flag & caps.plane_color)
1319 size += snprintf(&buf[size], PAGE_SIZE - size,
1320 " %s\n", color_caps[i].name);
1322 size += snprintf(&buf[size], PAGE_SIZE - size,
1323 " window colors:\n");
1324 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1325 size < PAGE_SIZE; i++) {
1326 if (color_caps[i].flag & caps.wnd_color)
1327 size += snprintf(&buf[size], PAGE_SIZE - size,
1328 " %s\n", color_caps[i].name);
1336 static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1337 static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1339 /* panel sysfs entries */
1340 static ssize_t omapfb_show_panel_name(struct device *dev,
1341 struct device_attribute *attr, char *buf)
1343 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1345 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1348 static ssize_t omapfb_show_bklight_level(struct device *dev,
1349 struct device_attribute *attr,
1352 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1355 if (fbdev->panel->get_bklight_level) {
1356 r = snprintf(buf, PAGE_SIZE, "%d\n",
1357 fbdev->panel->get_bklight_level(fbdev->panel));
1363 static ssize_t omapfb_store_bklight_level(struct device *dev,
1364 struct device_attribute *attr,
1365 const char *buf, size_t size)
1367 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1370 if (fbdev->panel->set_bklight_level) {
1373 if (sscanf(buf, "%10d", &level) == 1) {
1374 r = fbdev->panel->set_bklight_level(fbdev->panel,
1380 return r ? r : size;
1383 static ssize_t omapfb_show_bklight_max(struct device *dev,
1384 struct device_attribute *attr, char *buf)
1386 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1389 if (fbdev->panel->get_bklight_level) {
1390 r = snprintf(buf, PAGE_SIZE, "%d\n",
1391 fbdev->panel->get_bklight_max(fbdev->panel));
1397 static struct device_attribute dev_attr_panel_name =
1398 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1399 static DEVICE_ATTR(backlight_level, 0664,
1400 omapfb_show_bklight_level, omapfb_store_bklight_level);
1401 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1403 static struct attribute *panel_attrs[] = {
1404 &dev_attr_panel_name.attr,
1405 &dev_attr_backlight_level.attr,
1406 &dev_attr_backlight_max.attr,
1410 static struct attribute_group panel_attr_grp = {
1412 .attrs = panel_attrs,
1415 /* ctrl sysfs entries */
1416 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1417 struct device_attribute *attr, char *buf)
1419 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1421 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1424 static struct device_attribute dev_attr_ctrl_name =
1425 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1427 static struct attribute *ctrl_attrs[] = {
1428 &dev_attr_ctrl_name.attr,
1432 static struct attribute_group ctrl_attr_grp = {
1434 .attrs = ctrl_attrs,
1437 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1441 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1444 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1447 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1450 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1455 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1457 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1459 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1461 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1465 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1467 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1468 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1469 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1470 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1474 * ---------------------------------------------------------------------------
1476 * ---------------------------------------------------------------------------
1478 /* Initialize system fb_info object and set the default video mode.
1479 * The frame buffer memory already allocated by lcddma_init
1481 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1483 struct fb_var_screeninfo *var = &info->var;
1484 struct fb_fix_screeninfo *fix = &info->fix;
1487 info->fbops = &omapfb_ops;
1488 info->flags = FBINFO_FLAG_DEFAULT;
1490 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1492 info->pseudo_palette = fbdev->pseudo_palette;
1494 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1495 var->xres = def_vxres;
1496 var->yres = def_vyres;
1497 var->xres_virtual = def_vxres;
1498 var->yres_virtual = def_vyres;
1499 var->rotate = def_rotate;
1500 var->bits_per_pixel = fbdev->panel->bpp;
1502 set_fb_var(info, var);
1505 r = fb_alloc_cmap(&info->cmap, 16, 0);
1507 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1512 /* Release the fb_info object */
1513 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1515 fb_dealloc_cmap(&fbi->cmap);
1518 static void planes_cleanup(struct omapfb_device *fbdev)
1522 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1523 if (fbdev->fb_info[i] == NULL)
1525 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1526 framebuffer_release(fbdev->fb_info[i]);
1530 static int planes_init(struct omapfb_device *fbdev)
1532 struct fb_info *fbi;
1536 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1537 struct omapfb_plane_struct *plane;
1538 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1542 "unable to allocate memory for plane info\n");
1543 planes_cleanup(fbdev);
1548 plane->fbdev = fbdev;
1549 plane->info.mirror = def_mirror;
1550 fbdev->fb_info[i] = fbi;
1552 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1553 framebuffer_release(fbi);
1554 planes_cleanup(fbdev);
1557 plane->info.out_width = fbi->var.xres;
1558 plane->info.out_height = fbi->var.yres;
1564 * Free driver resources. Can be called to rollback an aborted initialization
1567 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1573 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1574 unregister_framebuffer(fbdev->fb_info[i]);
1576 omapfb_unregister_sysfs(fbdev);
1578 fbdev->panel->disable(fbdev->panel);
1580 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1582 planes_cleanup(fbdev);
1584 ctrl_cleanup(fbdev);
1586 fbdev->panel->cleanup(fbdev->panel);
1588 dev_set_drvdata(fbdev->dev, NULL);
1591 /* nothing to free */
1598 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1600 struct omapfb_platform_data *conf;
1604 conf = fbdev->dev->platform_data;
1608 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1609 name[sizeof(name) - 1] = '\0';
1611 if (strcmp(name, "internal") == 0) {
1612 fbdev->ctrl = fbdev->int_ctrl;
1616 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1617 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1618 if (strcmp(ctrls[i]->name, name) == 0) {
1619 fbdev->ctrl = ctrls[i];
1624 if (fbdev->ctrl == NULL) {
1625 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1632 static void check_required_callbacks(struct omapfb_device *fbdev)
1634 #define _C(x) (fbdev->ctrl->x != NULL)
1635 #define _P(x) (fbdev->panel->x != NULL)
1636 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1637 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1638 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1639 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1646 * Called by LDM binding to probe and attach a new device.
1647 * Initialization sequence:
1648 * 1. allocate system omapfb_device structure
1649 * 2. select controller type according to platform configuration
1651 * 3. init LCD controller and LCD DMA
1652 * 4. init system fb_info structure for all planes
1653 * 5. setup video mode for first plane and enable it
1654 * 6. enable LCD panel
1655 * 7. register sysfs attributes
1656 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1658 static int omapfb_do_probe(struct platform_device *pdev,
1659 struct lcd_panel *panel)
1661 struct omapfb_device *fbdev = NULL;
1663 unsigned long phz, hhz, vhz;
1670 if (pdev->num_resources != 0) {
1671 dev_err(&pdev->dev, "probed for an unknown device\n");
1676 if (pdev->dev.platform_data == NULL) {
1677 dev_err(&pdev->dev, "missing platform data\n");
1682 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1683 if (fbdev == NULL) {
1685 "unable to allocate memory for device info\n");
1691 fbdev->dev = &pdev->dev;
1692 fbdev->panel = panel;
1693 platform_set_drvdata(pdev, fbdev);
1695 mutex_init(&fbdev->rqueue_mutex);
1697 #ifdef CONFIG_ARCH_OMAP1
1698 fbdev->int_ctrl = &omap1_int_ctrl;
1699 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1700 fbdev->ext_if = &omap1_ext_if;
1703 fbdev->int_ctrl = &omap2_int_ctrl;
1704 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1705 fbdev->ext_if = &omap2_ext_if;
1708 if (omapfb_find_ctrl(fbdev) < 0) {
1710 "LCD controller not found, board not supported\n");
1715 r = fbdev->panel->init(fbdev->panel, fbdev);
1719 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1721 def_vxres = def_vxres ? def_vxres : fbdev->panel->x_res;
1722 def_vyres = def_vyres ? def_vyres : fbdev->panel->y_res;
1726 r = ctrl_init(fbdev);
1729 if (fbdev->ctrl->mmap != NULL)
1730 omapfb_ops.fb_mmap = omapfb_mmap;
1733 check_required_callbacks(fbdev);
1735 r = planes_init(fbdev);
1740 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1741 /* Set DMA priority for EMIFF access to highest */
1742 if (cpu_class_is_omap1())
1743 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1746 r = ctrl_change_mode(fbdev->fb_info[0]);
1748 dev_err(fbdev->dev, "mode setting failed\n");
1752 /* GFX plane is enabled by default */
1753 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1757 omapfb_set_update_mode(fbdev, manual_update ?
1758 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1761 r = fbdev->panel->enable(fbdev->panel);
1766 r = omapfb_register_sysfs(fbdev);
1772 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1773 r = register_framebuffer(fbdev->fb_info[i]);
1776 "registering framebuffer %d failed\n", i);
1779 vram += fbdev->mem_desc.region[i].size;
1782 fbdev->state = OMAPFB_ACTIVE;
1784 panel = fbdev->panel;
1785 phz = panel->pixel_clock * 1000;
1786 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1787 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1791 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1792 vram, fbdev->mem_desc.region_cnt);
1793 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1794 "vfreq %lu.%lu Hz\n",
1795 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1800 omapfb_free_resources(fbdev, init_state);
1805 static int omapfb_probe(struct platform_device *pdev)
1807 BUG_ON(fbdev_pdev != NULL);
1809 /* Delay actual initialization until the LCD is registered */
1811 if (fbdev_panel != NULL)
1812 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1816 void omapfb_register_panel(struct lcd_panel *panel)
1818 BUG_ON(fbdev_panel != NULL);
1820 fbdev_panel = panel;
1821 if (fbdev_pdev != NULL)
1822 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1825 /* Called when the device is being detached from the driver */
1826 static int omapfb_remove(struct platform_device *pdev)
1828 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1829 enum omapfb_state saved_state = fbdev->state;
1831 /* FIXME: wait till completion of pending events */
1833 fbdev->state = OMAPFB_DISABLED;
1834 omapfb_free_resources(fbdev, saved_state);
1840 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1842 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1845 omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
1850 static int omapfb_resume(struct platform_device *pdev)
1852 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1855 omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
1859 static struct platform_driver omapfb_driver = {
1860 .probe = omapfb_probe,
1861 .remove = omapfb_remove,
1862 .suspend = omapfb_suspend,
1863 .resume = omapfb_resume,
1865 .name = MODULE_NAME,
1866 .owner = THIS_MODULE,
1872 /* Process kernel command line parameters */
1873 static int __init omapfb_setup(char *options)
1875 char *this_opt = NULL;
1878 pr_debug("omapfb: options %s\n", options);
1880 if (!options || !*options)
1883 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1884 if (!strncmp(this_opt, "accel", 5))
1886 else if (!strncmp(this_opt, "vram:", 5)) {
1889 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1890 switch (suffix[0]) {
1902 pr_debug("omapfb: invalid vram suffix %c\n",
1906 def_vram[def_vram_cnt++] = vram;
1908 else if (!strncmp(this_opt, "vxres:", 6))
1909 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1910 else if (!strncmp(this_opt, "vyres:", 6))
1911 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1912 else if (!strncmp(this_opt, "rotate:", 7))
1913 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1914 else if (!strncmp(this_opt, "mirror:", 7))
1915 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1916 else if (!strncmp(this_opt, "manual_update", 13))
1919 pr_debug("omapfb: invalid option\n");
1929 /* Register both the driver and the device */
1930 static int __init omapfb_init(void)
1935 if (fb_get_options("omapfb", &option))
1937 omapfb_setup(option);
1939 /* Register the driver with LDM */
1940 if (platform_driver_register(&omapfb_driver)) {
1941 pr_debug("failed to register omapfb driver\n");
1948 static void __exit omapfb_cleanup(void)
1950 platform_driver_unregister(&omapfb_driver);
1953 module_param_named(accel, def_accel, uint, 0664);
1954 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1955 module_param_named(vxres, def_vxres, long, 0664);
1956 module_param_named(vyres, def_vyres, long, 0664);
1957 module_param_named(rotate, def_rotate, uint, 0664);
1958 module_param_named(mirror, def_mirror, uint, 0664);
1959 module_param_named(manual_update, manual_update, bool, 0664);
1961 module_init(omapfb_init);
1962 module_exit(omapfb_cleanup);
1964 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1965 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1966 MODULE_LICENSE("GPL");