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 <asm/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_SET_BACKLIGHT, "backlight setting" },
70 static struct caps_table_struct color_caps[] = {
71 { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
72 { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
73 { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
74 { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
75 { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
76 { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
77 { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
78 { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
79 { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
83 * ---------------------------------------------------------------------------
85 * ---------------------------------------------------------------------------
87 extern struct lcd_ctrl omap1_int_ctrl;
88 extern struct lcd_ctrl omap2_int_ctrl;
89 extern struct lcd_ctrl hwa742_ctrl;
90 extern struct lcd_ctrl blizzard_ctrl;
92 static struct lcd_ctrl *ctrls[] = {
93 #ifdef CONFIG_ARCH_OMAP1
99 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
102 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
107 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
108 #ifdef CONFIG_ARCH_OMAP1
109 extern struct lcd_ctrl_extif omap1_ext_if;
111 extern struct lcd_ctrl_extif omap2_ext_if;
115 static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
117 mutex_lock(&fbdev->rqueue_mutex);
120 static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
122 mutex_unlock(&fbdev->rqueue_mutex);
126 * ---------------------------------------------------------------------------
127 * LCD controller and LCD DMA
128 * ---------------------------------------------------------------------------
130 /* Lookup table to map elem size to elem type. */
131 static const int dma_elem_type[] = {
133 OMAP_DMA_DATA_TYPE_S8,
134 OMAP_DMA_DATA_TYPE_S16,
136 OMAP_DMA_DATA_TYPE_S32,
140 * Allocate resources needed for LCD controller and LCD DMA operations. Video
141 * memory is allocated from system memory according to the virtual display
142 * size, except if a bigger memory size is specified explicitly as a kernel
145 static int ctrl_init(struct omapfb_device *fbdev)
150 /* kernel/module vram parameters override boot tags/board config */
152 for (i = 0; i < def_vram_cnt; i++)
153 fbdev->mem_desc.region[i].size =
154 PAGE_ALIGN(def_vram[i]);
155 fbdev->mem_desc.region_cnt = i;
157 struct omapfb_platform_data *conf;
159 conf = fbdev->dev->platform_data;
160 fbdev->mem_desc = conf->mem_desc;
163 if (!fbdev->mem_desc.region_cnt) {
164 struct lcd_panel *panel = fbdev->panel;
166 int bpp = panel->bpp;
168 /* 12 bpp is packed in 16 bits */
171 def_size = def_vxres * def_vyres * bpp / 8;
172 fbdev->mem_desc.region_cnt = 1;
173 fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
175 r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
177 dev_err(fbdev->dev, "controller initialization failed (%d)\n", r);
182 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
183 dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
185 fbdev->mem_desc.region[i].paddr,
186 fbdev->mem_desc.region[i].vaddr,
187 fbdev->mem_desc.region[i].size);
193 static void ctrl_cleanup(struct omapfb_device *fbdev)
195 fbdev->ctrl->cleanup();
198 /* Must be called with fbdev->rqueue_mutex held. */
199 static int ctrl_change_mode(struct fb_info *fbi)
202 unsigned long offset;
203 struct omapfb_plane_struct *plane = fbi->par;
204 struct omapfb_device *fbdev = plane->fbdev;
205 struct fb_var_screeninfo *var = &fbi->var;
207 offset = var->yoffset * fbi->fix.line_length +
208 var->xoffset * var->bits_per_pixel / 8;
210 if (fbdev->ctrl->sync)
212 r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
213 offset, var->xres_virtual,
214 plane->info.pos_x, plane->info.pos_y,
215 var->xres, var->yres, plane->color_mode);
216 if (fbdev->ctrl->set_scale != NULL)
217 r = fbdev->ctrl->set_scale(plane->idx,
218 var->xres, var->yres,
219 plane->info.out_width,
220 plane->info.out_height);
226 * ---------------------------------------------------------------------------
227 * fbdev framework callbacks and the ioctl interface
228 * ---------------------------------------------------------------------------
230 /* Called each time the omapfb device is opened */
231 static int omapfb_open(struct fb_info *info, int user)
236 static void omapfb_sync(struct fb_info *info);
238 /* Called when the omapfb device is closed. We make sure that any pending
239 * gfx DMA operations are ended, before we return. */
240 static int omapfb_release(struct fb_info *info, int user)
246 /* Store a single color palette entry into a pseudo palette or the hardware
247 * palette if one is available. For now we support only 16bpp and thus store
248 * the entry only to the pseudo palette.
250 static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
251 u_int blue, u_int transp, int update_hw_pal)
253 struct omapfb_plane_struct *plane = info->par;
254 struct omapfb_device *fbdev = plane->fbdev;
255 struct fb_var_screeninfo *var = &info->var;
258 switch (plane->color_mode) {
259 case OMAPFB_COLOR_YUV422:
260 case OMAPFB_COLOR_YUV420:
261 case OMAPFB_COLOR_YUY422:
264 case OMAPFB_COLOR_CLUT_8BPP:
265 case OMAPFB_COLOR_CLUT_4BPP:
266 case OMAPFB_COLOR_CLUT_2BPP:
267 case OMAPFB_COLOR_CLUT_1BPP:
268 if (fbdev->ctrl->setcolreg)
269 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
270 transp, update_hw_pal);
272 case OMAPFB_COLOR_RGB565:
273 case OMAPFB_COLOR_RGB444:
284 pal = ((red >> (16 - var->red.length)) <<
286 ((green >> (16 - var->green.length)) <<
288 (blue >> (16 - var->blue.length));
289 ((u32 *)(info->pseudo_palette))[regno] = pal;
298 static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
299 u_int transp, struct fb_info *info)
301 return _setcolreg(info, regno, red, green, blue, transp, 1);
304 static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
307 u16 *red, *green, *blue, *transp;
313 transp = cmap->transp;
316 for (count = 0; count < cmap->len; count++) {
319 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
320 count == cmap->len - 1);
328 static int omapfb_update_full_screen(struct fb_info *fbi);
330 static int omapfb_blank(int blank, struct fb_info *fbi)
332 struct omapfb_plane_struct *plane = fbi->par;
333 struct omapfb_device *fbdev = plane->fbdev;
337 omapfb_rqueue_lock(fbdev);
339 case VESA_NO_BLANKING:
340 if (fbdev->state == OMAPFB_SUSPENDED) {
341 if (fbdev->ctrl->resume)
342 fbdev->ctrl->resume();
343 fbdev->panel->enable(fbdev->panel);
344 fbdev->state = OMAPFB_ACTIVE;
345 if (fbdev->ctrl->get_update_mode() ==
346 OMAPFB_MANUAL_UPDATE)
351 if (fbdev->state == OMAPFB_ACTIVE) {
352 fbdev->panel->disable(fbdev->panel);
353 if (fbdev->ctrl->suspend)
354 fbdev->ctrl->suspend();
355 fbdev->state = OMAPFB_SUSPENDED;
361 omapfb_rqueue_unlock(fbdev);
363 if (r == 0 && do_update)
364 r = omapfb_update_full_screen(fbi);
369 static void omapfb_sync(struct fb_info *fbi)
371 struct omapfb_plane_struct *plane = fbi->par;
372 struct omapfb_device *fbdev = plane->fbdev;
374 omapfb_rqueue_lock(fbdev);
375 if (fbdev->ctrl->sync)
377 omapfb_rqueue_unlock(fbdev);
381 * Set fb_info.fix fields and also updates fbdev.
382 * When calling this fb_info.var must be set up already.
384 static void set_fb_fix(struct fb_info *fbi)
386 struct fb_fix_screeninfo *fix = &fbi->fix;
387 struct fb_var_screeninfo *var = &fbi->var;
388 struct omapfb_plane_struct *plane = fbi->par;
389 struct omapfb_mem_region *rg;
392 rg = &plane->fbdev->mem_desc.region[plane->idx];
393 fbi->screen_base = (char __iomem *)rg->vaddr;
394 fix->smem_start = rg->paddr;
395 fix->smem_len = rg->size;
397 fix->type = FB_TYPE_PACKED_PIXELS;
398 bpp = var->bits_per_pixel;
400 fix->visual = FB_VISUAL_PSEUDOCOLOR;
401 else switch (var->bits_per_pixel) {
404 fix->visual = FB_VISUAL_TRUECOLOR;
405 /* 12bpp is stored in 16 bits */
412 fix->visual = FB_VISUAL_PSEUDOCOLOR;
415 fix->accel = FB_ACCEL_OMAP1610;
416 fix->line_length = var->xres_virtual * bpp / 8;
419 static int set_color_mode(struct omapfb_plane_struct *plane,
420 struct fb_var_screeninfo *var)
422 switch (var->nonstd) {
425 case OMAPFB_COLOR_YUV422:
426 var->bits_per_pixel = 16;
427 plane->color_mode = var->nonstd;
429 case OMAPFB_COLOR_YUV420:
430 var->bits_per_pixel = 12;
431 plane->color_mode = var->nonstd;
433 case OMAPFB_COLOR_YUY422:
434 var->bits_per_pixel = 16;
435 plane->color_mode = var->nonstd;
441 switch (var->bits_per_pixel) {
443 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
446 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
449 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
452 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
455 var->bits_per_pixel = 16;
456 plane->color_mode = OMAPFB_COLOR_RGB444;
459 plane->color_mode = OMAPFB_COLOR_RGB565;
467 * Check the values in var against our capabilities and in case of out of
468 * bound values try to adjust them.
470 static int set_fb_var(struct fb_info *fbi,
471 struct fb_var_screeninfo *var)
474 unsigned long max_frame_size;
475 unsigned long line_size;
476 int xres_min, xres_max;
477 int yres_min, yres_max;
478 struct omapfb_plane_struct *plane = fbi->par;
479 struct omapfb_device *fbdev = plane->fbdev;
480 struct lcd_panel *panel = fbdev->panel;
482 if (set_color_mode(plane, var) < 0)
485 bpp = var->bits_per_pixel;
486 if (plane->color_mode == OMAPFB_COLOR_RGB444)
489 switch (var->rotate) {
492 xres_min = OMAPFB_PLANE_XRES_MIN;
493 xres_max = panel->x_res;
494 yres_min = OMAPFB_PLANE_YRES_MIN;
495 yres_max = panel->y_res;
496 if (cpu_is_omap15xx()) {
497 var->xres = panel->x_res;
498 var->yres = panel->y_res;
503 xres_min = OMAPFB_PLANE_YRES_MIN;
504 xres_max = panel->y_res;
505 yres_min = OMAPFB_PLANE_XRES_MIN;
506 yres_max = panel->x_res;
507 if (cpu_is_omap15xx()) {
508 var->xres = panel->y_res;
509 var->yres = panel->x_res;
516 if (var->xres < xres_min)
517 var->xres = xres_min;
518 if (var->yres < yres_min)
519 var->yres = yres_min;
520 if (var->xres > xres_max)
521 var->xres = xres_max;
522 if (var->yres > yres_max)
523 var->yres = yres_max;
525 if (var->xres_virtual < var->xres)
526 var->xres_virtual = var->xres;
527 if (var->yres_virtual < var->yres)
528 var->yres_virtual = var->yres;
529 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
530 line_size = var->xres_virtual * bpp / 8;
531 if (line_size * var->yres_virtual > max_frame_size) {
532 /* Try to keep yres_virtual first */
533 line_size = max_frame_size / var->yres_virtual;
534 var->xres_virtual = line_size * 8 / bpp;
535 if (var->xres_virtual < var->xres) {
536 /* Still doesn't fit. Shrink yres_virtual too */
537 var->xres_virtual = var->xres;
538 line_size = var->xres * bpp / 8;
539 var->yres_virtual = max_frame_size / line_size;
541 /* Recheck this, as the virtual size changed. */
542 if (var->xres_virtual < var->xres)
543 var->xres = var->xres_virtual;
544 if (var->yres_virtual < var->yres)
545 var->yres = var->yres_virtual;
546 if (var->xres < xres_min || var->yres < yres_min)
549 if (var->xres + var->xoffset > var->xres_virtual)
550 var->xoffset = var->xres_virtual - var->xres;
551 if (var->yres + var->yoffset > var->yres_virtual)
552 var->yoffset = var->yres_virtual - var->yres;
553 line_size = var->xres * bpp / 8;
555 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
556 var->red.offset = 8; var->red.length = 4;
557 var->red.msb_right = 0;
558 var->green.offset = 4; var->green.length = 4;
559 var->green.msb_right = 0;
560 var->blue.offset = 0; var->blue.length = 4;
561 var->blue.msb_right = 0;
563 var->red.offset = 11; var->red.length = 5;
564 var->red.msb_right = 0;
565 var->green.offset= 5; var->green.length = 6;
566 var->green.msb_right = 0;
567 var->blue.offset = 0; var->blue.length = 5;
568 var->blue.msb_right = 0;
575 /* pixclock in ps, the rest in pixclock */
576 var->pixclock = 10000000 / (panel->pixel_clock / 100);
577 var->left_margin = panel->hfp;
578 var->right_margin = panel->hbp;
579 var->upper_margin = panel->vfp;
580 var->lower_margin = panel->vbp;
581 var->hsync_len = panel->hsw;
582 var->vsync_len = panel->vsw;
584 /* TODO: get these from panel->config */
585 var->vmode = FB_VMODE_NONINTERLACED;
592 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
593 static void omapfb_rotate(struct fb_info *fbi, int rotate)
595 struct omapfb_plane_struct *plane = fbi->par;
596 struct omapfb_device *fbdev = plane->fbdev;
598 omapfb_rqueue_lock(fbdev);
599 if (cpu_is_omap15xx() && rotate != fbi->var.rotate) {
600 struct fb_var_screeninfo *new_var = &fbdev->new_var;
602 memcpy(new_var, &fbi->var, sizeof(*new_var));
603 new_var->rotate = rotate;
604 if (set_fb_var(fbi, new_var) == 0 &&
605 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
606 memcpy(&fbi->var, new_var, sizeof(*new_var));
607 ctrl_change_mode(fbi);
610 omapfb_rqueue_unlock(fbdev);
614 * Set new x,y offsets in the virtual display for the visible area and switch
617 static int omapfb_pan_display(struct fb_var_screeninfo *var,
620 struct omapfb_plane_struct *plane = fbi->par;
621 struct omapfb_device *fbdev = plane->fbdev;
624 omapfb_rqueue_lock(fbdev);
625 if (var->xoffset != fbi->var.xoffset ||
626 var->yoffset != fbi->var.yoffset) {
627 struct fb_var_screeninfo *new_var = &fbdev->new_var;
629 memcpy(new_var, &fbi->var, sizeof(*new_var));
630 new_var->xoffset = var->xoffset;
631 new_var->yoffset = var->yoffset;
632 if (set_fb_var(fbi, new_var))
635 memcpy(&fbi->var, new_var, sizeof(*new_var));
636 ctrl_change_mode(fbi);
639 omapfb_rqueue_unlock(fbdev);
644 /* Set mirror to vertical axis and switch to the new mode. */
645 static int omapfb_mirror(struct fb_info *fbi, int mirror)
647 struct omapfb_plane_struct *plane = fbi->par;
648 struct omapfb_device *fbdev = plane->fbdev;
651 omapfb_rqueue_lock(fbdev);
652 mirror = mirror ? 1 : 0;
653 if (cpu_is_omap15xx())
655 else if (mirror != plane->info.mirror) {
656 plane->info.mirror = mirror;
657 r = ctrl_change_mode(fbi);
659 omapfb_rqueue_unlock(fbdev);
665 * Check values in var, try to adjust them in case of out of bound values if
666 * possible, or return error.
668 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
670 struct omapfb_plane_struct *plane = fbi->par;
671 struct omapfb_device *fbdev = plane->fbdev;
674 omapfb_rqueue_lock(fbdev);
675 if (fbdev->ctrl->sync != NULL)
677 r = set_fb_var(fbi, var);
678 omapfb_rqueue_unlock(fbdev);
684 * Switch to a new mode. The parameters for it has been check already by
687 static int omapfb_set_par(struct fb_info *fbi)
689 struct omapfb_plane_struct *plane = fbi->par;
690 struct omapfb_device *fbdev = plane->fbdev;
693 omapfb_rqueue_lock(fbdev);
695 r = ctrl_change_mode(fbi);
696 omapfb_rqueue_unlock(fbdev);
701 int omapfb_update_window_async(struct fb_info *fbi,
702 struct omapfb_update_window *win,
703 void (*callback)(void *),
706 struct omapfb_plane_struct *plane = fbi->par;
707 struct omapfb_device *fbdev = plane->fbdev;
708 struct fb_var_screeninfo *var;
711 if (win->x >= var->xres || win->y >= var->yres ||
712 win->out_x > var->xres || win->out_y >= var->yres)
715 if (!fbdev->ctrl->update_window ||
716 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
719 if (win->x + win->width >= var->xres)
720 win->width = var->xres - win->x;
721 if (win->y + win->height >= var->yres)
722 win->height = var->yres - win->y;
723 /* The out sizes should be cropped to the LCD size */
724 if (win->out_x + win->out_width > fbdev->panel->x_res)
725 win->out_width = fbdev->panel->x_res - win->out_x;
726 if (win->out_y + win->out_height > fbdev->panel->y_res)
727 win->out_height = fbdev->panel->y_res - win->out_y;
728 if (!win->width || !win->height || !win->out_width || !win->out_height)
731 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
733 EXPORT_SYMBOL(omapfb_update_window_async);
735 static int omapfb_update_win(struct fb_info *fbi,
736 struct omapfb_update_window *win)
738 struct omapfb_plane_struct *plane = fbi->par;
741 omapfb_rqueue_lock(plane->fbdev);
742 ret = omapfb_update_window_async(fbi, win, NULL, 0);
743 omapfb_rqueue_unlock(plane->fbdev);
748 static int omapfb_update_full_screen(struct fb_info *fbi)
750 struct omapfb_plane_struct *plane = fbi->par;
751 struct omapfb_device *fbdev = plane->fbdev;
752 struct omapfb_update_window win;
755 if (!fbdev->ctrl->update_window ||
756 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
761 win.width = fbi->var.xres;
762 win.height = fbi->var.yres;
765 win.out_width = fbi->var.xres;
766 win.out_height = fbi->var.yres;
769 omapfb_rqueue_lock(fbdev);
770 r = fbdev->ctrl->update_window(fbi, &win, NULL, 0);
771 omapfb_rqueue_unlock(fbdev);
776 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
778 struct omapfb_plane_struct *plane = fbi->par;
779 struct omapfb_device *fbdev = plane->fbdev;
780 struct lcd_panel *panel = fbdev->panel;
781 struct omapfb_plane_info old_info;
784 if (pi->pos_x + pi->out_width > panel->x_res ||
785 pi->pos_y + pi->out_height > panel->y_res)
788 omapfb_rqueue_lock(fbdev);
789 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
791 * This plane's memory was freed, can't enable it
792 * until it's reallocated.
797 old_info = plane->info;
800 r = ctrl_change_mode(fbi);
802 plane->info = old_info;
806 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
808 plane->info = old_info;
812 omapfb_rqueue_unlock(fbdev);
816 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
818 struct omapfb_plane_struct *plane = fbi->par;
824 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
826 struct omapfb_plane_struct *plane = fbi->par;
827 struct omapfb_device *fbdev = plane->fbdev;
828 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
832 if (fbdev->ctrl->setup_mem == NULL)
834 if (mi->type > OMAPFB_MEMTYPE_MAX)
837 size = PAGE_ALIGN(mi->size);
838 omapfb_rqueue_lock(fbdev);
839 if (plane->info.enabled) {
843 if (rg->size != size || rg->type != mi->type) {
844 struct fb_var_screeninfo *new_var = &fbdev->new_var;
845 unsigned long old_size = rg->size;
846 u8 old_type = rg->type;
852 * size == 0 is a special case, for which we
853 * don't check / adjust the screen parameters.
854 * This isn't a problem since the plane can't
855 * be reenabled unless its size is > 0.
857 if (old_size != size && size) {
859 memcpy(new_var, &fbi->var, sizeof(*new_var));
860 r = set_fb_var(fbi, new_var);
866 if (fbdev->ctrl->sync)
868 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
870 /* Revert changes. */
877 if (old_size != size) {
879 memcpy(&fbi->var, new_var, sizeof(fbi->var));
883 * Set these explicitly to indicate that the
884 * plane memory is dealloce'd, the other
885 * screen parameters in var / fix are invalid.
887 fbi->fix.smem_start = 0;
888 fbi->fix.smem_len = 0;
893 omapfb_rqueue_unlock(fbdev);
898 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
900 struct omapfb_plane_struct *plane = fbi->par;
901 struct omapfb_device *fbdev = plane->fbdev;
902 struct omapfb_mem_region *rg;
904 rg = &fbdev->mem_desc.region[plane->idx];
905 memset(mi, 0, sizeof(*mi));
912 static int omapfb_set_color_key(struct omapfb_device *fbdev,
913 struct omapfb_color_key *ck)
917 if (!fbdev->ctrl->set_color_key)
920 omapfb_rqueue_lock(fbdev);
921 r = fbdev->ctrl->set_color_key(ck);
922 omapfb_rqueue_unlock(fbdev);
927 static int omapfb_get_color_key(struct omapfb_device *fbdev,
928 struct omapfb_color_key *ck)
932 if (!fbdev->ctrl->get_color_key)
935 omapfb_rqueue_lock(fbdev);
936 r = fbdev->ctrl->get_color_key(ck);
937 omapfb_rqueue_unlock(fbdev);
942 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
943 static int notifier_inited;
945 static void omapfb_init_notifier(void)
949 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
950 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
953 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
954 omapfb_notifier_callback_t callback,
959 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
962 if (!notifier_inited) {
963 omapfb_init_notifier();
967 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
968 unsigned long, void *))callback;
969 omapfb_nb->data = callback_data;
970 r = blocking_notifier_chain_register(
971 &omapfb_client_list[omapfb_nb->plane_idx],
975 if (omapfb_dev != NULL &&
976 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
977 omapfb_dev->ctrl->bind_client(omapfb_nb);
982 EXPORT_SYMBOL(omapfb_register_client);
984 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
986 return blocking_notifier_chain_unregister(
987 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
989 EXPORT_SYMBOL(omapfb_unregister_client);
991 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
995 if (!notifier_inited)
996 /* no client registered yet */
999 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1000 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1003 EXPORT_SYMBOL(omapfb_notify_clients);
1005 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1006 enum omapfb_update_mode mode)
1010 omapfb_rqueue_lock(fbdev);
1011 r = fbdev->ctrl->set_update_mode(mode);
1012 omapfb_rqueue_unlock(fbdev);
1017 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1021 omapfb_rqueue_lock(fbdev);
1022 r = fbdev->ctrl->get_update_mode();
1023 omapfb_rqueue_unlock(fbdev);
1028 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1029 struct omapfb_caps *caps)
1031 memset(caps, 0, sizeof(*caps));
1032 fbdev->ctrl->get_caps(plane, caps);
1033 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1036 /* For lcd testing */
1037 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1039 omapfb_rqueue_lock(fbdev);
1040 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1041 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1042 struct omapfb_update_window win;
1044 memset(&win, 0, sizeof(win));
1049 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0);
1051 omapfb_rqueue_unlock(fbdev);
1053 EXPORT_SYMBOL(omapfb_write_first_pixel);
1056 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1057 * here to be accessible by user mode code.
1059 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1062 struct omapfb_plane_struct *plane = fbi->par;
1063 struct omapfb_device *fbdev = plane->fbdev;
1064 struct fb_ops *ops = fbi->fbops;
1066 struct omapfb_update_window update_window;
1067 struct omapfb_plane_info plane_info;
1068 struct omapfb_mem_info mem_info;
1069 struct omapfb_color_key color_key;
1070 enum omapfb_update_mode update_mode;
1071 struct omapfb_caps caps;
1072 unsigned int mirror;
1082 if (get_user(p.mirror, (int __user *)arg))
1085 omapfb_mirror(fbi, p.mirror);
1087 case OMAPFB_SYNC_GFX:
1092 case OMAPFB_SET_UPDATE_MODE:
1093 if (get_user(p.update_mode, (int __user *)arg))
1096 r = omapfb_set_update_mode(fbdev, p.update_mode);
1098 case OMAPFB_GET_UPDATE_MODE:
1099 p.update_mode = omapfb_get_update_mode(fbdev);
1100 if (put_user(p.update_mode,
1101 (enum omapfb_update_mode __user *)arg))
1104 case OMAPFB_UPDATE_WINDOW_OLD:
1105 if (copy_from_user(&p.update_window, (void __user *)arg,
1106 sizeof(struct omapfb_update_window_old)))
1109 struct omapfb_update_window *u = &p.update_window;
1112 u->out_width = u->width;
1113 u->out_height = u->height;
1114 memset(u->reserved, 0, sizeof(u->reserved));
1115 r = omapfb_update_win(fbi, u);
1118 case OMAPFB_UPDATE_WINDOW:
1119 if (copy_from_user(&p.update_window, (void __user *)arg,
1120 sizeof(p.update_window)))
1123 r = omapfb_update_win(fbi, &p.update_window);
1125 case OMAPFB_SETUP_PLANE:
1126 if (copy_from_user(&p.plane_info, (void __user *)arg,
1127 sizeof(p.plane_info)))
1130 r = omapfb_setup_plane(fbi, &p.plane_info);
1132 case OMAPFB_QUERY_PLANE:
1133 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1135 if (copy_to_user((void __user *)arg, &p.plane_info,
1136 sizeof(p.plane_info)))
1139 case OMAPFB_SETUP_MEM:
1140 if (copy_from_user(&p.mem_info, (void __user *)arg,
1141 sizeof(p.mem_info)))
1144 r = omapfb_setup_mem(fbi, &p.mem_info);
1146 case OMAPFB_QUERY_MEM:
1147 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1149 if (copy_to_user((void __user *)arg, &p.mem_info,
1150 sizeof(p.mem_info)))
1153 case OMAPFB_SET_COLOR_KEY:
1154 if (copy_from_user(&p.color_key, (void __user *)arg,
1155 sizeof(p.color_key)))
1158 r = omapfb_set_color_key(fbdev, &p.color_key);
1160 case OMAPFB_GET_COLOR_KEY:
1161 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1163 if (copy_to_user((void __user *)arg, &p.color_key,
1164 sizeof(p.color_key)))
1167 case OMAPFB_GET_CAPS:
1168 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1169 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1172 case OMAPFB_LCD_TEST:
1176 if (get_user(test_num, (int __user *)arg)) {
1180 if (!fbdev->panel->run_test) {
1184 r = fbdev->panel->run_test(fbdev->panel, test_num);
1187 case OMAPFB_CTRL_TEST:
1191 if (get_user(test_num, (int __user *)arg)) {
1195 if (!fbdev->ctrl->run_test) {
1199 r = fbdev->ctrl->run_test(test_num);
1209 static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1211 struct omapfb_plane_struct *plane = info->par;
1212 struct omapfb_device *fbdev = plane->fbdev;
1215 omapfb_rqueue_lock(fbdev);
1216 r = fbdev->ctrl->mmap(info, vma);
1217 omapfb_rqueue_unlock(fbdev);
1223 * Callback table for the frame buffer framework. Some of these pointers
1224 * will be changed according to the current setting of fb_info->accel_flags.
1226 static struct fb_ops omapfb_ops = {
1227 .owner = THIS_MODULE,
1228 .fb_open = omapfb_open,
1229 .fb_release = omapfb_release,
1230 .fb_setcolreg = omapfb_setcolreg,
1231 .fb_setcmap = omapfb_setcmap,
1232 .fb_fillrect = cfb_fillrect,
1233 .fb_copyarea = cfb_copyarea,
1234 .fb_imageblit = cfb_imageblit,
1235 .fb_blank = omapfb_blank,
1236 .fb_ioctl = omapfb_ioctl,
1237 .fb_check_var = omapfb_check_var,
1238 .fb_set_par = omapfb_set_par,
1239 .fb_rotate = omapfb_rotate,
1240 .fb_pan_display = omapfb_pan_display,
1244 * ---------------------------------------------------------------------------
1246 * ---------------------------------------------------------------------------
1248 /* omapfbX sysfs entries */
1249 static ssize_t omapfb_show_caps_num(struct device *dev,
1250 struct device_attribute *attr, char *buf)
1252 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1255 struct omapfb_caps caps;
1259 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1260 omapfb_get_caps(fbdev, plane, &caps);
1261 size += snprintf(&buf[size], PAGE_SIZE - size,
1262 "plane#%d %#010x %#010x %#010x\n",
1263 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1269 static ssize_t omapfb_show_caps_text(struct device *dev,
1270 struct device_attribute *attr, char *buf)
1272 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1274 struct omapfb_caps caps;
1280 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1281 omapfb_get_caps(fbdev, plane, &caps);
1282 size += snprintf(&buf[size], PAGE_SIZE - size,
1283 "plane#%d:\n", plane);
1284 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1285 size < PAGE_SIZE; i++) {
1286 if (ctrl_caps[i].flag & caps.ctrl)
1287 size += snprintf(&buf[size], PAGE_SIZE - size,
1288 " %s\n", ctrl_caps[i].name);
1290 size += snprintf(&buf[size], PAGE_SIZE - size,
1291 " plane colors:\n");
1292 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1293 size < PAGE_SIZE; i++) {
1294 if (color_caps[i].flag & caps.plane_color)
1295 size += snprintf(&buf[size], PAGE_SIZE - size,
1296 " %s\n", color_caps[i].name);
1298 size += snprintf(&buf[size], PAGE_SIZE - size,
1299 " window colors:\n");
1300 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1301 size < PAGE_SIZE; i++) {
1302 if (color_caps[i].flag & caps.wnd_color)
1303 size += snprintf(&buf[size], PAGE_SIZE - size,
1304 " %s\n", color_caps[i].name);
1312 static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1313 static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1315 /* panel sysfs entries */
1316 static ssize_t omapfb_show_panel_name(struct device *dev,
1317 struct device_attribute *attr, char *buf)
1319 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1321 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1324 static ssize_t omapfb_show_bklight_level(struct device *dev,
1325 struct device_attribute *attr,
1328 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1331 if (fbdev->panel->get_bklight_level) {
1332 r = snprintf(buf, PAGE_SIZE, "%d\n",
1333 fbdev->panel->get_bklight_level(fbdev->panel));
1339 static ssize_t omapfb_store_bklight_level(struct device *dev,
1340 struct device_attribute *attr,
1341 const char *buf, size_t size)
1343 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1346 if (fbdev->panel->set_bklight_level) {
1349 if (sscanf(buf, "%10d", &level) == 1) {
1350 r = fbdev->panel->set_bklight_level(fbdev->panel, level);
1355 return r ? r : size;
1358 static ssize_t omapfb_show_bklight_max(struct device *dev,
1359 struct device_attribute *attr, char *buf)
1361 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1364 if (fbdev->panel->get_bklight_level) {
1365 r = snprintf(buf, PAGE_SIZE, "%d\n",
1366 fbdev->panel->get_bklight_max(fbdev->panel));
1372 static struct device_attribute dev_attr_panel_name =
1373 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1374 static DEVICE_ATTR(backlight_level, 0664,
1375 omapfb_show_bklight_level, omapfb_store_bklight_level);
1376 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1378 static struct attribute *panel_attrs[] = {
1379 &dev_attr_panel_name.attr,
1380 &dev_attr_backlight_level.attr,
1381 &dev_attr_backlight_max.attr,
1385 static struct attribute_group panel_attr_grp = {
1387 .attrs = panel_attrs,
1390 /* ctrl sysfs entries */
1391 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1392 struct device_attribute *attr, char *buf)
1394 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1396 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1399 static struct device_attribute dev_attr_ctrl_name =
1400 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1402 static struct attribute *ctrl_attrs[] = {
1403 &dev_attr_ctrl_name.attr,
1407 static struct attribute_group ctrl_attr_grp = {
1409 .attrs = ctrl_attrs,
1412 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1416 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1419 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1422 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1425 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1430 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1432 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1434 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1436 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1440 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1442 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1443 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1444 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1445 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1449 * ---------------------------------------------------------------------------
1451 * ---------------------------------------------------------------------------
1453 /* Initialize system fb_info object and set the default video mode.
1454 * The frame buffer memory already allocated by lcddma_init
1456 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1458 struct fb_var_screeninfo *var = &info->var;
1459 struct fb_fix_screeninfo *fix = &info->fix;
1462 info->fbops = &omapfb_ops;
1463 info->flags = FBINFO_FLAG_DEFAULT;
1465 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1467 info->pseudo_palette = fbdev->pseudo_palette;
1469 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1470 var->xres = def_vxres;
1471 var->yres = def_vyres;
1472 var->xres_virtual = def_vxres;
1473 var->yres_virtual = def_vyres;
1474 var->rotate = def_rotate;
1475 var->bits_per_pixel = fbdev->panel->bpp;
1477 set_fb_var(info, var);
1480 r = fb_alloc_cmap(&info->cmap, 16, 0);
1482 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1487 /* Release the fb_info object */
1488 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1490 fb_dealloc_cmap(&fbi->cmap);
1493 static void planes_cleanup(struct omapfb_device *fbdev)
1497 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1498 if (fbdev->fb_info[i] == NULL)
1500 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1501 framebuffer_release(fbdev->fb_info[i]);
1505 static int planes_init(struct omapfb_device *fbdev)
1507 struct fb_info *fbi;
1511 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1512 struct omapfb_plane_struct *plane;
1513 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1517 "unable to allocate memory for plane info\n");
1518 planes_cleanup(fbdev);
1523 plane->fbdev = fbdev;
1524 plane->info.mirror = def_mirror;
1525 fbdev->fb_info[i] = fbi;
1527 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1528 framebuffer_release(fbi);
1529 planes_cleanup(fbdev);
1532 plane->info.out_width = fbi->var.xres;
1533 plane->info.out_height = fbi->var.yres;
1539 * Free driver resources. Can be called to rollback an aborted initialization
1542 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1548 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1549 unregister_framebuffer(fbdev->fb_info[i]);
1551 omapfb_unregister_sysfs(fbdev);
1553 fbdev->panel->disable(fbdev->panel);
1555 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1557 planes_cleanup(fbdev);
1559 ctrl_cleanup(fbdev);
1561 fbdev->panel->cleanup(fbdev->panel);
1563 dev_set_drvdata(fbdev->dev, NULL);
1566 /* nothing to free */
1573 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1575 struct omapfb_platform_data *conf;
1579 conf = fbdev->dev->platform_data;
1583 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1584 name[sizeof(name) - 1] = '\0';
1586 if (strcmp(name, "internal") == 0) {
1587 fbdev->ctrl = fbdev->int_ctrl;
1591 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1592 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1593 if (strcmp(ctrls[i]->name, name) == 0) {
1594 fbdev->ctrl = ctrls[i];
1599 if (fbdev->ctrl == NULL) {
1600 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1607 static void check_required_callbacks(struct omapfb_device *fbdev)
1609 #define _C(x) (fbdev->ctrl->x != NULL)
1610 #define _P(x) (fbdev->panel->x != NULL)
1611 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1612 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1613 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1614 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1621 * Called by LDM binding to probe and attach a new device.
1622 * Initialization sequence:
1623 * 1. allocate system omapfb_device structure
1624 * 2. select controller type according to platform configuration
1626 * 3. init LCD controller and LCD DMA
1627 * 4. init system fb_info structure for all planes
1628 * 5. setup video mode for first plane and enable it
1629 * 6. enable LCD panel
1630 * 7. register sysfs attributes
1631 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1633 static int omapfb_do_probe(struct platform_device *pdev, struct lcd_panel *panel)
1635 struct omapfb_device *fbdev = NULL;
1637 unsigned long phz, hhz, vhz;
1644 if (pdev->num_resources != 0) {
1645 dev_err(&pdev->dev, "probed for an unknown device\n");
1650 if (pdev->dev.platform_data == NULL) {
1651 dev_err(&pdev->dev, "missing platform data\n");
1656 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1657 if (fbdev == NULL) {
1659 "unable to allocate memory for device info\n");
1665 fbdev->dev = &pdev->dev;
1666 fbdev->panel = panel;
1667 platform_set_drvdata(pdev, fbdev);
1669 mutex_init(&fbdev->rqueue_mutex);
1671 #ifdef CONFIG_ARCH_OMAP1
1672 fbdev->int_ctrl = &omap1_int_ctrl;
1673 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1674 fbdev->ext_if = &omap1_ext_if;
1677 fbdev->int_ctrl = &omap2_int_ctrl;
1678 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1679 fbdev->ext_if = &omap2_ext_if;
1682 if (omapfb_find_ctrl(fbdev) < 0) {
1684 "LCD controller not found, board not supported\n");
1689 r = fbdev->panel->init(fbdev->panel, fbdev);
1693 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1695 def_vxres = def_vxres ? : fbdev->panel->x_res;
1696 def_vyres = def_vyres ? : fbdev->panel->y_res;
1700 r = ctrl_init(fbdev);
1703 if (fbdev->ctrl->mmap != NULL)
1704 omapfb_ops.fb_mmap = omapfb_mmap;
1707 check_required_callbacks(fbdev);
1709 r = planes_init(fbdev);
1714 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1715 /* Set DMA priority for EMIFF access to highest */
1716 if (cpu_class_is_omap1())
1717 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1720 r = ctrl_change_mode(fbdev->fb_info[0]);
1722 dev_err(fbdev->dev, "mode setting failed\n");
1726 /* GFX plane is enabled by default */
1727 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1731 omapfb_set_update_mode(fbdev, manual_update ?
1732 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1735 r = fbdev->panel->enable(fbdev->panel);
1740 r = omapfb_register_sysfs(fbdev);
1746 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1747 r = register_framebuffer(fbdev->fb_info[i]);
1750 "registering framebuffer %d failed\n", i);
1753 vram += fbdev->mem_desc.region[i].size;
1756 fbdev->state = OMAPFB_ACTIVE;
1758 panel = fbdev->panel;
1759 phz = panel->pixel_clock * 1000;
1760 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1761 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1765 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1766 vram, fbdev->mem_desc.region_cnt);
1767 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1768 "vfreq %lu.%lu Hz\n",
1769 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1774 omapfb_free_resources(fbdev, init_state);
1779 static int omapfb_probe(struct platform_device *pdev)
1781 BUG_ON(fbdev_pdev != NULL);
1783 /* Delay actual initialization until the LCD is registered */
1785 if (fbdev_panel != NULL)
1786 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1790 void omapfb_register_panel(struct lcd_panel *panel)
1792 BUG_ON(fbdev_panel != NULL);
1794 fbdev_panel = panel;
1795 if (fbdev_pdev != NULL)
1796 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1799 /* Called when the device is being detached from the driver */
1800 static int omapfb_remove(struct platform_device *pdev)
1802 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1803 enum omapfb_state saved_state = fbdev->state;
1805 /* FIXME: wait till completion of pending events */
1807 fbdev->state = OMAPFB_DISABLED;
1808 omapfb_free_resources(fbdev, saved_state);
1814 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1816 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1818 omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
1824 static int omapfb_resume(struct platform_device *pdev)
1826 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1828 omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
1832 static struct platform_driver omapfb_driver = {
1833 .probe = omapfb_probe,
1834 .remove = omapfb_remove,
1835 .suspend = omapfb_suspend,
1836 .resume = omapfb_resume,
1838 .name = MODULE_NAME,
1839 .owner = THIS_MODULE,
1845 /* Process kernel command line parameters */
1846 static int __init omapfb_setup(char *options)
1848 char *this_opt = NULL;
1851 pr_debug("omapfb: options %s\n", options);
1853 if (!options || !*options)
1856 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1857 if (!strncmp(this_opt, "accel", 5))
1859 else if (!strncmp(this_opt, "vram:", 5)) {
1862 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1863 switch (suffix[0]) {
1875 pr_debug("omapfb: invalid vram suffix %c\n",
1879 def_vram[def_vram_cnt++] = vram;
1881 else if (!strncmp(this_opt, "vxres:", 6))
1882 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1883 else if (!strncmp(this_opt, "vyres:", 6))
1884 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1885 else if (!strncmp(this_opt, "rotate:", 7))
1886 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1887 else if (!strncmp(this_opt, "mirror:", 7))
1888 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1889 else if (!strncmp(this_opt, "manual_update", 13))
1892 pr_debug("omapfb: invalid option\n");
1902 /* Register both the driver and the device */
1903 static int __init omapfb_init(void)
1908 if (fb_get_options("omapfb", &option))
1910 omapfb_setup(option);
1912 /* Register the driver with LDM */
1913 if (platform_driver_register(&omapfb_driver)) {
1914 pr_debug("failed to register omapfb driver\n");
1921 static void __exit omapfb_cleanup(void)
1923 platform_driver_unregister(&omapfb_driver);
1926 module_param_named(accel, def_accel, uint, 0664);
1927 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1928 module_param_named(vxres, def_vxres, long, 0664);
1929 module_param_named(vyres, def_vyres, long, 0664);
1930 module_param_named(rotate, def_rotate, uint, 0664);
1931 module_param_named(mirror, def_mirror, uint, 0664);
1932 module_param_named(manual_update, manual_update, bool, 0664);
1934 module_init(omapfb_init);
1935 module_exit(omapfb_cleanup);
1937 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1938 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1939 MODULE_LICENSE("GPL");