2 * Framebuffer driver for TI OMAP boards
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Imre Deak <imre.deak@nokia.com>
8 * Alex McMains <aam@ridgerun.com> - Original driver
9 * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
10 * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
11 * Texas Instruments - H3 support
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <linux/platform_device.h>
29 #include <linux/uaccess.h>
37 #define MODULE_NAME "omapfb"
39 static unsigned int def_accel;
40 static unsigned long def_vram[OMAPFB_PLANE_NUM];
41 static unsigned int def_vram_cnt;
42 static unsigned long def_vxres;
43 static unsigned long def_vyres;
44 static unsigned int def_rotate;
45 static unsigned int def_mirror;
47 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
48 static int manual_update = 1;
50 static int manual_update;
53 static struct platform_device *fbdev_pdev;
54 static struct lcd_panel *fbdev_panel;
55 static struct omapfb_device *omapfb_dev;
57 struct caps_table_struct {
62 static struct caps_table_struct ctrl_caps[] = {
63 { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
64 { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
65 { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
66 { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
67 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
68 { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
69 { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" },
70 { OMAPFB_CAPS_WINDOW_ROTATE, "rotate window" },
71 { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" },
74 static struct caps_table_struct color_caps[] = {
75 { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
76 { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
77 { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
78 { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
79 { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
80 { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
81 { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
82 { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
83 { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
86 /* dummy device for clocks */
87 static struct platform_device omapdss_device = {
93 * ---------------------------------------------------------------------------
95 * ---------------------------------------------------------------------------
97 extern struct lcd_ctrl hwa742_ctrl;
98 extern struct lcd_ctrl blizzard_ctrl;
100 static const struct lcd_ctrl *ctrls[] = {
101 #ifdef CONFIG_ARCH_OMAP1
107 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
110 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
115 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
116 #ifdef CONFIG_ARCH_OMAP1
117 extern struct lcd_ctrl_extif omap1_ext_if;
119 extern struct lcd_ctrl_extif omap2_ext_if;
123 static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
125 mutex_lock(&fbdev->rqueue_mutex);
128 static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
130 mutex_unlock(&fbdev->rqueue_mutex);
134 * ---------------------------------------------------------------------------
135 * LCD controller and LCD DMA
136 * ---------------------------------------------------------------------------
138 /* Lookup table to map elem size to elem type. */
139 static const int dma_elem_type[] = {
141 OMAP_DMA_DATA_TYPE_S8,
142 OMAP_DMA_DATA_TYPE_S16,
144 OMAP_DMA_DATA_TYPE_S32,
148 * Allocate resources needed for LCD controller and LCD DMA operations. Video
149 * memory is allocated from system memory according to the virtual display
150 * size, except if a bigger memory size is specified explicitly as a kernel
153 static int ctrl_init(struct omapfb_device *fbdev)
158 /* kernel/module vram parameters override boot tags/board config */
160 for (i = 0; i < def_vram_cnt; i++)
161 fbdev->mem_desc.region[i].size =
162 PAGE_ALIGN(def_vram[i]);
163 fbdev->mem_desc.region_cnt = i;
165 struct omapfb_platform_data *conf;
167 conf = fbdev->dev->platform_data;
168 fbdev->mem_desc = conf->mem_desc;
171 if (!fbdev->mem_desc.region_cnt) {
172 struct lcd_panel *panel = fbdev->panel;
174 int bpp = panel->bpp;
176 /* 12 bpp is packed in 16 bits */
179 def_size = def_vxres * def_vyres * bpp / 8;
180 fbdev->mem_desc.region_cnt = 1;
181 fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
183 r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
185 dev_err(fbdev->dev, "controller initialization failed (%d)\n",
191 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
192 dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
194 fbdev->mem_desc.region[i].paddr,
195 fbdev->mem_desc.region[i].vaddr,
196 fbdev->mem_desc.region[i].size);
202 static void ctrl_cleanup(struct omapfb_device *fbdev)
204 fbdev->ctrl->cleanup();
207 /* Must be called with fbdev->rqueue_mutex held. */
208 static int ctrl_change_mode(struct fb_info *fbi)
211 unsigned long offset;
212 struct omapfb_plane_struct *plane = fbi->par;
213 struct omapfb_device *fbdev = plane->fbdev;
214 struct fb_var_screeninfo *var = &fbi->var;
216 offset = var->yoffset * fbi->fix.line_length +
217 var->xoffset * var->bits_per_pixel / 8;
219 if (fbdev->ctrl->sync)
221 r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
222 offset, var->xres_virtual,
223 plane->info.pos_x, plane->info.pos_y,
224 var->xres, var->yres, plane->color_mode);
228 if (fbdev->ctrl->set_rotate != NULL) {
229 r = fbdev->ctrl->set_rotate(var->rotate);
234 if (fbdev->ctrl->set_scale != NULL)
235 r = fbdev->ctrl->set_scale(plane->idx,
236 var->xres, var->yres,
237 plane->info.out_width,
238 plane->info.out_height);
244 * ---------------------------------------------------------------------------
245 * fbdev framework callbacks and the ioctl interface
246 * ---------------------------------------------------------------------------
248 /* Called each time the omapfb device is opened */
249 static int omapfb_open(struct fb_info *info, int user)
254 static void omapfb_sync(struct fb_info *info);
256 /* Called when the omapfb device is closed. We make sure that any pending
257 * gfx DMA operations are ended, before we return. */
258 static int omapfb_release(struct fb_info *info, int user)
264 /* Store a single color palette entry into a pseudo palette or the hardware
265 * palette if one is available. For now we support only 16bpp and thus store
266 * the entry only to the pseudo palette.
268 static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
269 u_int blue, u_int transp, int update_hw_pal)
271 struct omapfb_plane_struct *plane = info->par;
272 struct omapfb_device *fbdev = plane->fbdev;
273 struct fb_var_screeninfo *var = &info->var;
276 switch (plane->color_mode) {
277 case OMAPFB_COLOR_YUV422:
278 case OMAPFB_COLOR_YUV420:
279 case OMAPFB_COLOR_YUY422:
282 case OMAPFB_COLOR_CLUT_8BPP:
283 case OMAPFB_COLOR_CLUT_4BPP:
284 case OMAPFB_COLOR_CLUT_2BPP:
285 case OMAPFB_COLOR_CLUT_1BPP:
286 if (fbdev->ctrl->setcolreg)
287 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
288 transp, update_hw_pal);
290 case OMAPFB_COLOR_RGB565:
291 case OMAPFB_COLOR_RGB444:
302 pal = ((red >> (16 - var->red.length)) <<
304 ((green >> (16 - var->green.length)) <<
306 (blue >> (16 - var->blue.length));
307 ((u32 *)(info->pseudo_palette))[regno] = pal;
316 static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
317 u_int transp, struct fb_info *info)
319 return _setcolreg(info, regno, red, green, blue, transp, 1);
322 static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
325 u16 *red, *green, *blue, *transp;
331 transp = cmap->transp;
334 for (count = 0; count < cmap->len; count++) {
337 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
338 count == cmap->len - 1);
346 static int omapfb_update_full_screen(struct fb_info *fbi);
348 static int omapfb_blank(int blank, struct fb_info *fbi)
350 struct omapfb_plane_struct *plane = fbi->par;
351 struct omapfb_device *fbdev = plane->fbdev;
355 omapfb_rqueue_lock(fbdev);
357 case FB_BLANK_UNBLANK:
358 if (fbdev->state == OMAPFB_SUSPENDED) {
359 if (fbdev->ctrl->resume)
360 fbdev->ctrl->resume();
361 fbdev->panel->enable(fbdev->panel);
362 fbdev->state = OMAPFB_ACTIVE;
363 if (fbdev->ctrl->get_update_mode() ==
364 OMAPFB_MANUAL_UPDATE)
368 case FB_BLANK_POWERDOWN:
369 if (fbdev->state == OMAPFB_ACTIVE) {
370 fbdev->panel->disable(fbdev->panel);
371 if (fbdev->ctrl->suspend)
372 fbdev->ctrl->suspend();
373 fbdev->state = OMAPFB_SUSPENDED;
379 omapfb_rqueue_unlock(fbdev);
381 if (r == 0 && do_update)
382 r = omapfb_update_full_screen(fbi);
387 static void omapfb_sync(struct fb_info *fbi)
389 struct omapfb_plane_struct *plane = fbi->par;
390 struct omapfb_device *fbdev = plane->fbdev;
392 omapfb_rqueue_lock(fbdev);
393 if (fbdev->ctrl->sync)
395 omapfb_rqueue_unlock(fbdev);
399 * Set fb_info.fix fields and also updates fbdev.
400 * When calling this fb_info.var must be set up already.
402 static void set_fb_fix(struct fb_info *fbi, int from_init)
404 struct fb_fix_screeninfo *fix = &fbi->fix;
405 struct fb_var_screeninfo *var = &fbi->var;
406 struct omapfb_plane_struct *plane = fbi->par;
407 struct omapfb_mem_region *rg;
410 rg = &plane->fbdev->mem_desc.region[plane->idx];
411 fbi->screen_base = rg->vaddr;
414 mutex_lock(&fbi->mm_lock);
415 fix->smem_start = rg->paddr;
416 fix->smem_len = rg->size;
417 mutex_unlock(&fbi->mm_lock);
419 fix->smem_start = rg->paddr;
420 fix->smem_len = rg->size;
423 fix->type = FB_TYPE_PACKED_PIXELS;
424 bpp = var->bits_per_pixel;
426 fix->visual = FB_VISUAL_PSEUDOCOLOR;
427 else switch (var->bits_per_pixel) {
430 fix->visual = FB_VISUAL_TRUECOLOR;
431 /* 12bpp is stored in 16 bits */
438 fix->visual = FB_VISUAL_PSEUDOCOLOR;
441 fix->accel = FB_ACCEL_OMAP1610;
442 fix->line_length = var->xres_virtual * bpp / 8;
445 static int set_color_mode(struct omapfb_plane_struct *plane,
446 struct fb_var_screeninfo *var)
448 switch (var->nonstd) {
451 case OMAPFB_COLOR_YUV422:
452 var->bits_per_pixel = 16;
453 plane->color_mode = var->nonstd;
455 case OMAPFB_COLOR_YUV420:
456 var->bits_per_pixel = 12;
457 plane->color_mode = var->nonstd;
459 case OMAPFB_COLOR_YUY422:
460 var->bits_per_pixel = 16;
461 plane->color_mode = var->nonstd;
467 switch (var->bits_per_pixel) {
469 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
472 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
475 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
478 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
481 var->bits_per_pixel = 16;
482 plane->color_mode = OMAPFB_COLOR_RGB444;
485 plane->color_mode = OMAPFB_COLOR_RGB565;
493 * Check the values in var against our capabilities and in case of out of
494 * bound values try to adjust them.
496 static int set_fb_var(struct fb_info *fbi,
497 struct fb_var_screeninfo *var)
500 unsigned long max_frame_size;
501 unsigned long line_size;
502 int xres_min, xres_max;
503 int yres_min, yres_max;
504 struct omapfb_plane_struct *plane = fbi->par;
505 struct omapfb_device *fbdev = plane->fbdev;
506 struct lcd_panel *panel = fbdev->panel;
508 if (set_color_mode(plane, var) < 0)
511 bpp = var->bits_per_pixel;
512 if (plane->color_mode == OMAPFB_COLOR_RGB444)
515 switch (var->rotate) {
518 xres_min = OMAPFB_PLANE_XRES_MIN;
519 xres_max = panel->x_res;
520 yres_min = OMAPFB_PLANE_YRES_MIN;
521 yres_max = panel->y_res;
522 if (cpu_is_omap15xx()) {
523 var->xres = panel->x_res;
524 var->yres = panel->y_res;
529 xres_min = OMAPFB_PLANE_YRES_MIN;
530 xres_max = panel->y_res;
531 yres_min = OMAPFB_PLANE_XRES_MIN;
532 yres_max = panel->x_res;
533 if (cpu_is_omap15xx()) {
534 var->xres = panel->y_res;
535 var->yres = panel->x_res;
542 if (var->xres < xres_min)
543 var->xres = xres_min;
544 if (var->yres < yres_min)
545 var->yres = yres_min;
546 if (var->xres > xres_max)
547 var->xres = xres_max;
548 if (var->yres > yres_max)
549 var->yres = yres_max;
551 if (var->xres_virtual < var->xres)
552 var->xres_virtual = var->xres;
553 if (var->yres_virtual < var->yres)
554 var->yres_virtual = var->yres;
555 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
556 line_size = var->xres_virtual * bpp / 8;
557 if (line_size * var->yres_virtual > max_frame_size) {
558 /* Try to keep yres_virtual first */
559 line_size = max_frame_size / var->yres_virtual;
560 var->xres_virtual = line_size * 8 / bpp;
561 if (var->xres_virtual < var->xres) {
562 /* Still doesn't fit. Shrink yres_virtual too */
563 var->xres_virtual = var->xres;
564 line_size = var->xres * bpp / 8;
565 var->yres_virtual = max_frame_size / line_size;
567 /* Recheck this, as the virtual size changed. */
568 if (var->xres_virtual < var->xres)
569 var->xres = var->xres_virtual;
570 if (var->yres_virtual < var->yres)
571 var->yres = var->yres_virtual;
572 if (var->xres < xres_min || var->yres < yres_min)
575 if (var->xres + var->xoffset > var->xres_virtual)
576 var->xoffset = var->xres_virtual - var->xres;
577 if (var->yres + var->yoffset > var->yres_virtual)
578 var->yoffset = var->yres_virtual - var->yres;
580 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
581 var->red.offset = 8; var->red.length = 4;
582 var->red.msb_right = 0;
583 var->green.offset = 4; var->green.length = 4;
584 var->green.msb_right = 0;
585 var->blue.offset = 0; var->blue.length = 4;
586 var->blue.msb_right = 0;
588 var->red.offset = 11; var->red.length = 5;
589 var->red.msb_right = 0;
590 var->green.offset = 5; var->green.length = 6;
591 var->green.msb_right = 0;
592 var->blue.offset = 0; var->blue.length = 5;
593 var->blue.msb_right = 0;
600 /* pixclock in ps, the rest in pixclock */
601 var->pixclock = 10000000 / (panel->pixel_clock / 100);
602 var->left_margin = panel->hfp;
603 var->right_margin = panel->hbp;
604 var->upper_margin = panel->vfp;
605 var->lower_margin = panel->vbp;
606 var->hsync_len = panel->hsw;
607 var->vsync_len = panel->vsw;
609 /* TODO: get these from panel->config */
610 var->vmode = FB_VMODE_NONINTERLACED;
617 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
618 static void omapfb_rotate(struct fb_info *fbi, int rotate)
620 struct omapfb_plane_struct *plane = fbi->par;
621 struct omapfb_device *fbdev = plane->fbdev;
623 omapfb_rqueue_lock(fbdev);
624 if (rotate != fbi->var.rotate) {
625 struct fb_var_screeninfo *new_var = &fbdev->new_var;
627 memcpy(new_var, &fbi->var, sizeof(*new_var));
628 new_var->rotate = rotate;
629 if (set_fb_var(fbi, new_var) == 0 &&
630 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
631 memcpy(&fbi->var, new_var, sizeof(*new_var));
632 ctrl_change_mode(fbi);
635 omapfb_rqueue_unlock(fbdev);
639 * Set new x,y offsets in the virtual display for the visible area and switch
642 static int omapfb_pan_display(struct fb_var_screeninfo *var,
645 struct omapfb_plane_struct *plane = fbi->par;
646 struct omapfb_device *fbdev = plane->fbdev;
649 omapfb_rqueue_lock(fbdev);
650 if (var->xoffset != fbi->var.xoffset ||
651 var->yoffset != fbi->var.yoffset) {
652 struct fb_var_screeninfo *new_var = &fbdev->new_var;
654 memcpy(new_var, &fbi->var, sizeof(*new_var));
655 new_var->xoffset = var->xoffset;
656 new_var->yoffset = var->yoffset;
657 if (set_fb_var(fbi, new_var))
660 memcpy(&fbi->var, new_var, sizeof(*new_var));
661 ctrl_change_mode(fbi);
664 omapfb_rqueue_unlock(fbdev);
669 /* Set mirror to vertical axis and switch to the new mode. */
670 static int omapfb_mirror(struct fb_info *fbi, int mirror)
672 struct omapfb_plane_struct *plane = fbi->par;
673 struct omapfb_device *fbdev = plane->fbdev;
676 omapfb_rqueue_lock(fbdev);
677 mirror = mirror ? 1 : 0;
678 if (cpu_is_omap15xx())
680 else if (mirror != plane->info.mirror) {
681 plane->info.mirror = mirror;
682 r = ctrl_change_mode(fbi);
684 omapfb_rqueue_unlock(fbdev);
690 * Check values in var, try to adjust them in case of out of bound values if
691 * possible, or return error.
693 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
695 struct omapfb_plane_struct *plane = fbi->par;
696 struct omapfb_device *fbdev = plane->fbdev;
699 omapfb_rqueue_lock(fbdev);
700 if (fbdev->ctrl->sync != NULL)
702 r = set_fb_var(fbi, var);
703 omapfb_rqueue_unlock(fbdev);
709 * Switch to a new mode. The parameters for it has been check already by
712 static int omapfb_set_par(struct fb_info *fbi)
714 struct omapfb_plane_struct *plane = fbi->par;
715 struct omapfb_device *fbdev = plane->fbdev;
718 omapfb_rqueue_lock(fbdev);
720 r = ctrl_change_mode(fbi);
721 omapfb_rqueue_unlock(fbdev);
726 int omapfb_update_window_async(struct fb_info *fbi,
727 struct omapfb_update_window *win,
728 void (*callback)(void *),
732 struct omapfb_plane_struct *plane = fbi->par;
733 struct omapfb_device *fbdev = plane->fbdev;
734 struct fb_var_screeninfo *var = &fbi->var;
736 switch (var->rotate) {
739 xres = fbdev->panel->x_res;
740 yres = fbdev->panel->y_res;
744 xres = fbdev->panel->y_res;
745 yres = fbdev->panel->x_res;
751 if (win->x >= xres || win->y >= yres ||
752 win->out_x > xres || win->out_y > yres)
755 if (!fbdev->ctrl->update_window ||
756 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
759 if (win->x + win->width > xres)
760 win->width = xres - win->x;
761 if (win->y + win->height > yres)
762 win->height = yres - win->y;
763 if (win->out_x + win->out_width > xres)
764 win->out_width = xres - win->out_x;
765 if (win->out_y + win->out_height > yres)
766 win->out_height = yres - win->out_y;
767 if (!win->width || !win->height || !win->out_width || !win->out_height)
770 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
772 EXPORT_SYMBOL(omapfb_update_window_async);
774 static int omapfb_update_win(struct fb_info *fbi,
775 struct omapfb_update_window *win)
777 struct omapfb_plane_struct *plane = fbi->par;
780 omapfb_rqueue_lock(plane->fbdev);
781 ret = omapfb_update_window_async(fbi, win, NULL, NULL);
782 omapfb_rqueue_unlock(plane->fbdev);
787 static int omapfb_update_full_screen(struct fb_info *fbi)
789 struct omapfb_plane_struct *plane = fbi->par;
790 struct omapfb_device *fbdev = plane->fbdev;
791 struct omapfb_update_window win;
794 if (!fbdev->ctrl->update_window ||
795 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
800 win.width = fbi->var.xres;
801 win.height = fbi->var.yres;
804 win.out_width = fbi->var.xres;
805 win.out_height = fbi->var.yres;
808 omapfb_rqueue_lock(fbdev);
809 r = fbdev->ctrl->update_window(fbi, &win, NULL, NULL);
810 omapfb_rqueue_unlock(fbdev);
815 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
817 struct omapfb_plane_struct *plane = fbi->par;
818 struct omapfb_device *fbdev = plane->fbdev;
819 struct lcd_panel *panel = fbdev->panel;
820 struct omapfb_plane_info old_info;
823 if (pi->pos_x + pi->out_width > panel->x_res ||
824 pi->pos_y + pi->out_height > panel->y_res)
827 omapfb_rqueue_lock(fbdev);
828 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
830 * This plane's memory was freed, can't enable it
831 * until it's reallocated.
836 old_info = plane->info;
839 r = ctrl_change_mode(fbi);
841 plane->info = old_info;
845 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
847 plane->info = old_info;
851 omapfb_rqueue_unlock(fbdev);
855 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
857 struct omapfb_plane_struct *plane = fbi->par;
863 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
865 struct omapfb_plane_struct *plane = fbi->par;
866 struct omapfb_device *fbdev = plane->fbdev;
867 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
871 if (fbdev->ctrl->setup_mem == NULL)
873 if (mi->type > OMAPFB_MEMTYPE_MAX)
876 size = PAGE_ALIGN(mi->size);
877 omapfb_rqueue_lock(fbdev);
878 if (plane->info.enabled) {
882 if (rg->size != size || rg->type != mi->type) {
883 struct fb_var_screeninfo *new_var = &fbdev->new_var;
884 unsigned long old_size = rg->size;
885 u8 old_type = rg->type;
891 * size == 0 is a special case, for which we
892 * don't check / adjust the screen parameters.
893 * This isn't a problem since the plane can't
894 * be reenabled unless its size is > 0.
896 if (old_size != size && size) {
898 memcpy(new_var, &fbi->var, sizeof(*new_var));
899 r = set_fb_var(fbi, new_var);
905 if (fbdev->ctrl->sync)
907 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
909 /* Revert changes. */
916 if (old_size != size) {
918 memcpy(&fbi->var, new_var, sizeof(fbi->var));
922 * Set these explicitly to indicate that the
923 * plane memory is dealloce'd, the other
924 * screen parameters in var / fix are invalid.
926 mutex_lock(&fbi->mm_lock);
927 fbi->fix.smem_start = 0;
928 fbi->fix.smem_len = 0;
929 mutex_unlock(&fbi->mm_lock);
934 omapfb_rqueue_unlock(fbdev);
939 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
941 struct omapfb_plane_struct *plane = fbi->par;
942 struct omapfb_device *fbdev = plane->fbdev;
943 struct omapfb_mem_region *rg;
945 rg = &fbdev->mem_desc.region[plane->idx];
946 memset(mi, 0, sizeof(*mi));
953 static int omapfb_set_color_key(struct omapfb_device *fbdev,
954 struct omapfb_color_key *ck)
958 if (!fbdev->ctrl->set_color_key)
961 omapfb_rqueue_lock(fbdev);
962 r = fbdev->ctrl->set_color_key(ck);
963 omapfb_rqueue_unlock(fbdev);
968 static int omapfb_get_color_key(struct omapfb_device *fbdev,
969 struct omapfb_color_key *ck)
973 if (!fbdev->ctrl->get_color_key)
976 omapfb_rqueue_lock(fbdev);
977 r = fbdev->ctrl->get_color_key(ck);
978 omapfb_rqueue_unlock(fbdev);
983 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
984 static int notifier_inited;
986 static void omapfb_init_notifier(void)
990 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
991 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
994 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
995 omapfb_notifier_callback_t callback,
1000 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
1003 if (!notifier_inited) {
1004 omapfb_init_notifier();
1005 notifier_inited = 1;
1008 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
1009 unsigned long, void *))callback;
1010 omapfb_nb->data = callback_data;
1011 r = blocking_notifier_chain_register(
1012 &omapfb_client_list[omapfb_nb->plane_idx],
1016 if (omapfb_dev != NULL &&
1017 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
1018 omapfb_dev->ctrl->bind_client(omapfb_nb);
1023 EXPORT_SYMBOL(omapfb_register_client);
1025 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
1027 return blocking_notifier_chain_unregister(
1028 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
1030 EXPORT_SYMBOL(omapfb_unregister_client);
1032 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
1036 if (!notifier_inited)
1037 /* no client registered yet */
1040 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1041 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1044 EXPORT_SYMBOL(omapfb_notify_clients);
1046 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1047 enum omapfb_update_mode mode)
1051 omapfb_rqueue_lock(fbdev);
1052 r = fbdev->ctrl->set_update_mode(mode);
1053 omapfb_rqueue_unlock(fbdev);
1058 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1062 omapfb_rqueue_lock(fbdev);
1063 r = fbdev->ctrl->get_update_mode();
1064 omapfb_rqueue_unlock(fbdev);
1069 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1070 struct omapfb_caps *caps)
1072 memset(caps, 0, sizeof(*caps));
1073 fbdev->ctrl->get_caps(plane, caps);
1074 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1077 /* For lcd testing */
1078 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1080 omapfb_rqueue_lock(fbdev);
1081 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1082 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1083 struct omapfb_update_window win;
1085 memset(&win, 0, sizeof(win));
1090 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, NULL);
1092 omapfb_rqueue_unlock(fbdev);
1094 EXPORT_SYMBOL(omapfb_write_first_pixel);
1097 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1098 * here to be accessible by user mode code.
1100 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1103 struct omapfb_plane_struct *plane = fbi->par;
1104 struct omapfb_device *fbdev = plane->fbdev;
1105 struct fb_ops *ops = fbi->fbops;
1107 struct omapfb_update_window update_window;
1108 struct omapfb_plane_info plane_info;
1109 struct omapfb_mem_info mem_info;
1110 struct omapfb_color_key color_key;
1111 enum omapfb_update_mode update_mode;
1112 struct omapfb_caps caps;
1113 unsigned int mirror;
1122 if (get_user(p.mirror, (int __user *)arg))
1125 omapfb_mirror(fbi, p.mirror);
1127 case OMAPFB_SYNC_GFX:
1132 case OMAPFB_SET_UPDATE_MODE:
1133 if (get_user(p.update_mode, (int __user *)arg))
1136 r = omapfb_set_update_mode(fbdev, p.update_mode);
1138 case OMAPFB_GET_UPDATE_MODE:
1139 p.update_mode = omapfb_get_update_mode(fbdev);
1140 if (put_user(p.update_mode,
1141 (enum omapfb_update_mode __user *)arg))
1144 case OMAPFB_UPDATE_WINDOW_OLD:
1145 if (copy_from_user(&p.update_window, (void __user *)arg,
1146 sizeof(struct omapfb_update_window_old)))
1149 struct omapfb_update_window *u = &p.update_window;
1152 u->out_width = u->width;
1153 u->out_height = u->height;
1154 memset(u->reserved, 0, sizeof(u->reserved));
1155 r = omapfb_update_win(fbi, u);
1158 case OMAPFB_UPDATE_WINDOW:
1159 if (copy_from_user(&p.update_window, (void __user *)arg,
1160 sizeof(p.update_window)))
1163 r = omapfb_update_win(fbi, &p.update_window);
1165 case OMAPFB_SETUP_PLANE:
1166 if (copy_from_user(&p.plane_info, (void __user *)arg,
1167 sizeof(p.plane_info)))
1170 r = omapfb_setup_plane(fbi, &p.plane_info);
1172 case OMAPFB_QUERY_PLANE:
1173 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1175 if (copy_to_user((void __user *)arg, &p.plane_info,
1176 sizeof(p.plane_info)))
1179 case OMAPFB_SETUP_MEM:
1180 if (copy_from_user(&p.mem_info, (void __user *)arg,
1181 sizeof(p.mem_info)))
1184 r = omapfb_setup_mem(fbi, &p.mem_info);
1186 case OMAPFB_QUERY_MEM:
1187 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1189 if (copy_to_user((void __user *)arg, &p.mem_info,
1190 sizeof(p.mem_info)))
1193 case OMAPFB_SET_COLOR_KEY:
1194 if (copy_from_user(&p.color_key, (void __user *)arg,
1195 sizeof(p.color_key)))
1198 r = omapfb_set_color_key(fbdev, &p.color_key);
1200 case OMAPFB_GET_COLOR_KEY:
1201 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1203 if (copy_to_user((void __user *)arg, &p.color_key,
1204 sizeof(p.color_key)))
1207 case OMAPFB_GET_CAPS:
1208 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1209 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1212 case OMAPFB_LCD_TEST:
1216 if (get_user(test_num, (int __user *)arg)) {
1220 if (!fbdev->panel->run_test) {
1224 r = fbdev->panel->run_test(fbdev->panel, test_num);
1227 case OMAPFB_CTRL_TEST:
1231 if (get_user(test_num, (int __user *)arg)) {
1235 if (!fbdev->ctrl->run_test) {
1239 r = fbdev->ctrl->run_test(test_num);
1249 static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1251 struct omapfb_plane_struct *plane = info->par;
1252 struct omapfb_device *fbdev = plane->fbdev;
1255 omapfb_rqueue_lock(fbdev);
1256 r = fbdev->ctrl->mmap(info, vma);
1257 omapfb_rqueue_unlock(fbdev);
1263 * Callback table for the frame buffer framework. Some of these pointers
1264 * will be changed according to the current setting of fb_info->accel_flags.
1266 static struct fb_ops omapfb_ops = {
1267 .owner = THIS_MODULE,
1268 .fb_open = omapfb_open,
1269 .fb_release = omapfb_release,
1270 .fb_setcolreg = omapfb_setcolreg,
1271 .fb_setcmap = omapfb_setcmap,
1272 .fb_fillrect = cfb_fillrect,
1273 .fb_copyarea = cfb_copyarea,
1274 .fb_imageblit = cfb_imageblit,
1275 .fb_blank = omapfb_blank,
1276 .fb_ioctl = omapfb_ioctl,
1277 .fb_check_var = omapfb_check_var,
1278 .fb_set_par = omapfb_set_par,
1279 .fb_rotate = omapfb_rotate,
1280 .fb_pan_display = omapfb_pan_display,
1284 * ---------------------------------------------------------------------------
1286 * ---------------------------------------------------------------------------
1288 /* omapfbX sysfs entries */
1289 static ssize_t omapfb_show_caps_num(struct device *dev,
1290 struct device_attribute *attr, char *buf)
1292 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1295 struct omapfb_caps caps;
1299 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1300 omapfb_get_caps(fbdev, plane, &caps);
1301 size += snprintf(&buf[size], PAGE_SIZE - size,
1302 "plane#%d %#010x %#010x %#010x\n",
1303 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1309 static ssize_t omapfb_show_caps_text(struct device *dev,
1310 struct device_attribute *attr, char *buf)
1312 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1314 struct omapfb_caps caps;
1320 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1321 omapfb_get_caps(fbdev, plane, &caps);
1322 size += snprintf(&buf[size], PAGE_SIZE - size,
1323 "plane#%d:\n", plane);
1324 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1325 size < PAGE_SIZE; i++) {
1326 if (ctrl_caps[i].flag & caps.ctrl)
1327 size += snprintf(&buf[size], PAGE_SIZE - size,
1328 " %s\n", ctrl_caps[i].name);
1330 size += snprintf(&buf[size], PAGE_SIZE - size,
1331 " plane colors:\n");
1332 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1333 size < PAGE_SIZE; i++) {
1334 if (color_caps[i].flag & caps.plane_color)
1335 size += snprintf(&buf[size], PAGE_SIZE - size,
1336 " %s\n", color_caps[i].name);
1338 size += snprintf(&buf[size], PAGE_SIZE - size,
1339 " window colors:\n");
1340 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1341 size < PAGE_SIZE; i++) {
1342 if (color_caps[i].flag & caps.wnd_color)
1343 size += snprintf(&buf[size], PAGE_SIZE - size,
1344 " %s\n", color_caps[i].name);
1352 static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1353 static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1355 /* panel sysfs entries */
1356 static ssize_t omapfb_show_panel_name(struct device *dev,
1357 struct device_attribute *attr, char *buf)
1359 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1361 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1364 static ssize_t omapfb_show_bklight_level(struct device *dev,
1365 struct device_attribute *attr,
1368 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1371 if (fbdev->panel->get_bklight_level) {
1372 r = snprintf(buf, PAGE_SIZE, "%d\n",
1373 fbdev->panel->get_bklight_level(fbdev->panel));
1379 static ssize_t omapfb_store_bklight_level(struct device *dev,
1380 struct device_attribute *attr,
1381 const char *buf, size_t size)
1383 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1386 if (fbdev->panel->set_bklight_level) {
1389 if (sscanf(buf, "%10d", &level) == 1) {
1390 r = fbdev->panel->set_bklight_level(fbdev->panel,
1396 return r ? r : size;
1399 static ssize_t omapfb_show_bklight_max(struct device *dev,
1400 struct device_attribute *attr, char *buf)
1402 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1405 if (fbdev->panel->get_bklight_level) {
1406 r = snprintf(buf, PAGE_SIZE, "%d\n",
1407 fbdev->panel->get_bklight_max(fbdev->panel));
1413 static struct device_attribute dev_attr_panel_name =
1414 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1415 static DEVICE_ATTR(backlight_level, 0664,
1416 omapfb_show_bklight_level, omapfb_store_bklight_level);
1417 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1419 static struct attribute *panel_attrs[] = {
1420 &dev_attr_panel_name.attr,
1421 &dev_attr_backlight_level.attr,
1422 &dev_attr_backlight_max.attr,
1426 static struct attribute_group panel_attr_grp = {
1428 .attrs = panel_attrs,
1431 /* ctrl sysfs entries */
1432 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1433 struct device_attribute *attr, char *buf)
1435 struct omapfb_device *fbdev = dev_get_drvdata(dev);
1437 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1440 static struct device_attribute dev_attr_ctrl_name =
1441 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1443 static struct attribute *ctrl_attrs[] = {
1444 &dev_attr_ctrl_name.attr,
1448 static struct attribute_group ctrl_attr_grp = {
1450 .attrs = ctrl_attrs,
1453 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1457 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1460 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1463 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1466 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1471 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1473 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1475 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1477 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1481 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1483 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1484 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1485 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1486 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1490 * ---------------------------------------------------------------------------
1492 * ---------------------------------------------------------------------------
1494 /* Initialize system fb_info object and set the default video mode.
1495 * The frame buffer memory already allocated by lcddma_init
1497 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1499 struct fb_var_screeninfo *var = &info->var;
1500 struct fb_fix_screeninfo *fix = &info->fix;
1503 info->fbops = &omapfb_ops;
1504 info->flags = FBINFO_FLAG_DEFAULT;
1506 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1508 info->pseudo_palette = fbdev->pseudo_palette;
1510 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1511 var->xres = def_vxres;
1512 var->yres = def_vyres;
1513 var->xres_virtual = def_vxres;
1514 var->yres_virtual = def_vyres;
1515 var->rotate = def_rotate;
1516 var->bits_per_pixel = fbdev->panel->bpp;
1518 set_fb_var(info, var);
1519 set_fb_fix(info, 1);
1521 r = fb_alloc_cmap(&info->cmap, 16, 0);
1523 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1528 /* Release the fb_info object */
1529 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1531 fb_dealloc_cmap(&fbi->cmap);
1534 static void planes_cleanup(struct omapfb_device *fbdev)
1538 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1539 if (fbdev->fb_info[i] == NULL)
1541 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1542 framebuffer_release(fbdev->fb_info[i]);
1546 static int planes_init(struct omapfb_device *fbdev)
1548 struct fb_info *fbi;
1552 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1553 struct omapfb_plane_struct *plane;
1554 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1558 "unable to allocate memory for plane info\n");
1559 planes_cleanup(fbdev);
1564 plane->fbdev = fbdev;
1565 plane->info.mirror = def_mirror;
1566 fbdev->fb_info[i] = fbi;
1568 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1569 framebuffer_release(fbi);
1570 planes_cleanup(fbdev);
1573 plane->info.out_width = fbi->var.xres;
1574 plane->info.out_height = fbi->var.yres;
1580 * Free driver resources. Can be called to rollback an aborted initialization
1583 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1589 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1590 unregister_framebuffer(fbdev->fb_info[i]);
1592 omapfb_unregister_sysfs(fbdev);
1594 fbdev->panel->disable(fbdev->panel);
1596 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1598 planes_cleanup(fbdev);
1600 ctrl_cleanup(fbdev);
1602 fbdev->panel->cleanup(fbdev->panel);
1604 dev_set_drvdata(fbdev->dev, NULL);
1607 /* nothing to free */
1614 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1616 struct omapfb_platform_data *conf;
1620 conf = fbdev->dev->platform_data;
1624 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1625 name[sizeof(name) - 1] = '\0';
1627 if (strcmp(name, "internal") == 0) {
1628 fbdev->ctrl = fbdev->int_ctrl;
1632 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1633 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1634 if (strcmp(ctrls[i]->name, name) == 0) {
1635 fbdev->ctrl = ctrls[i];
1640 if (fbdev->ctrl == NULL) {
1641 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1648 static void check_required_callbacks(struct omapfb_device *fbdev)
1650 #define _C(x) (fbdev->ctrl->x != NULL)
1651 #define _P(x) (fbdev->panel->x != NULL)
1652 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1653 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1654 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1655 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1662 * Called by LDM binding to probe and attach a new device.
1663 * Initialization sequence:
1664 * 1. allocate system omapfb_device structure
1665 * 2. select controller type according to platform configuration
1667 * 3. init LCD controller and LCD DMA
1668 * 4. init system fb_info structure for all planes
1669 * 5. setup video mode for first plane and enable it
1670 * 6. enable LCD panel
1671 * 7. register sysfs attributes
1672 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1674 static int omapfb_do_probe(struct platform_device *pdev,
1675 struct lcd_panel *panel)
1677 struct omapfb_device *fbdev = NULL;
1679 unsigned long phz, hhz, vhz;
1686 if (pdev->num_resources != 0) {
1687 dev_err(&pdev->dev, "probed for an unknown device\n");
1692 if (pdev->dev.platform_data == NULL) {
1693 dev_err(&pdev->dev, "missing platform data\n");
1698 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1699 if (fbdev == NULL) {
1701 "unable to allocate memory for device info\n");
1707 fbdev->dev = &pdev->dev;
1708 fbdev->panel = panel;
1709 fbdev->dssdev = &omapdss_device;
1710 platform_set_drvdata(pdev, fbdev);
1712 mutex_init(&fbdev->rqueue_mutex);
1714 #ifdef CONFIG_ARCH_OMAP1
1715 fbdev->int_ctrl = &omap1_int_ctrl;
1716 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1717 fbdev->ext_if = &omap1_ext_if;
1720 fbdev->int_ctrl = &omap2_int_ctrl;
1721 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1722 fbdev->ext_if = &omap2_ext_if;
1725 if (omapfb_find_ctrl(fbdev) < 0) {
1727 "LCD controller not found, board not supported\n");
1732 r = fbdev->panel->init(fbdev->panel, fbdev);
1736 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1738 def_vxres = def_vxres ? def_vxres : fbdev->panel->x_res;
1739 def_vyres = def_vyres ? def_vyres : fbdev->panel->y_res;
1743 r = ctrl_init(fbdev);
1746 if (fbdev->ctrl->mmap != NULL)
1747 omapfb_ops.fb_mmap = omapfb_mmap;
1750 check_required_callbacks(fbdev);
1752 r = planes_init(fbdev);
1757 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1758 /* Set DMA priority for EMIFF access to highest */
1759 if (cpu_class_is_omap1())
1760 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1763 r = ctrl_change_mode(fbdev->fb_info[0]);
1765 dev_err(fbdev->dev, "mode setting failed\n");
1769 /* GFX plane is enabled by default */
1770 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1774 omapfb_set_update_mode(fbdev, manual_update ?
1775 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1778 r = fbdev->panel->enable(fbdev->panel);
1783 r = omapfb_register_sysfs(fbdev);
1789 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1790 r = register_framebuffer(fbdev->fb_info[i]);
1793 "registering framebuffer %d failed\n", i);
1796 vram += fbdev->mem_desc.region[i].size;
1799 fbdev->state = OMAPFB_ACTIVE;
1801 panel = fbdev->panel;
1802 phz = panel->pixel_clock * 1000;
1803 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1804 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1808 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1809 vram, fbdev->mem_desc.region_cnt);
1810 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1811 "vfreq %lu.%lu Hz\n",
1812 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1817 omapfb_free_resources(fbdev, init_state);
1822 static int omapfb_probe(struct platform_device *pdev)
1826 BUG_ON(fbdev_pdev != NULL);
1828 r = platform_device_register(&omapdss_device);
1830 dev_err(&pdev->dev, "can't register omapdss device\n");
1834 /* Delay actual initialization until the LCD is registered */
1836 if (fbdev_panel != NULL)
1837 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1841 void omapfb_register_panel(struct lcd_panel *panel)
1843 BUG_ON(fbdev_panel != NULL);
1845 fbdev_panel = panel;
1846 if (fbdev_pdev != NULL)
1847 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1850 /* Called when the device is being detached from the driver */
1851 static int omapfb_remove(struct platform_device *pdev)
1853 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1854 enum omapfb_state saved_state = fbdev->state;
1856 /* FIXME: wait till completion of pending events */
1858 fbdev->state = OMAPFB_DISABLED;
1859 omapfb_free_resources(fbdev, saved_state);
1861 platform_device_unregister(&omapdss_device);
1862 fbdev->dssdev = NULL;
1868 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1870 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1873 omapfb_blank(FB_BLANK_POWERDOWN, fbdev->fb_info[0]);
1878 static int omapfb_resume(struct platform_device *pdev)
1880 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1883 omapfb_blank(FB_BLANK_UNBLANK, fbdev->fb_info[0]);
1887 static struct platform_driver omapfb_driver = {
1888 .probe = omapfb_probe,
1889 .remove = omapfb_remove,
1890 .suspend = omapfb_suspend,
1891 .resume = omapfb_resume,
1893 .name = MODULE_NAME,
1894 .owner = THIS_MODULE,
1900 /* Process kernel command line parameters */
1901 static int __init omapfb_setup(char *options)
1903 char *this_opt = NULL;
1906 pr_debug("omapfb: options %s\n", options);
1908 if (!options || !*options)
1911 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1912 if (!strncmp(this_opt, "accel", 5))
1914 else if (!strncmp(this_opt, "vram:", 5)) {
1917 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1918 switch (suffix[0]) {
1930 pr_debug("omapfb: invalid vram suffix %c\n",
1934 def_vram[def_vram_cnt++] = vram;
1936 else if (!strncmp(this_opt, "vxres:", 6))
1937 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1938 else if (!strncmp(this_opt, "vyres:", 6))
1939 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1940 else if (!strncmp(this_opt, "rotate:", 7))
1941 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1942 else if (!strncmp(this_opt, "mirror:", 7))
1943 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1944 else if (!strncmp(this_opt, "manual_update", 13))
1947 pr_debug("omapfb: invalid option\n");
1957 /* Register both the driver and the device */
1958 static int __init omapfb_init(void)
1963 if (fb_get_options("omapfb", &option))
1965 omapfb_setup(option);
1967 /* Register the driver with LDM */
1968 if (platform_driver_register(&omapfb_driver)) {
1969 pr_debug("failed to register omapfb driver\n");
1976 static void __exit omapfb_cleanup(void)
1978 platform_driver_unregister(&omapfb_driver);
1981 module_param_named(accel, def_accel, uint, 0664);
1982 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1983 module_param_named(vxres, def_vxres, long, 0664);
1984 module_param_named(vyres, def_vyres, long, 0664);
1985 module_param_named(rotate, def_rotate, uint, 0664);
1986 module_param_named(mirror, def_mirror, uint, 0664);
1987 module_param_named(manual_update, manual_update, bool, 0664);
1989 module_init(omapfb_init);
1990 module_exit(omapfb_cleanup);
1992 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1993 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1994 MODULE_LICENSE("GPL");