2 * Framebuffer driver for TI OMAP boards
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Imre Deak <imre.deak@nokia.com>
8 * Alex McMains <aam@ridgerun.com> - Original driver
9 * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
10 * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
11 * Texas Instruments - H3 support
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <linux/platform_device.h>
28 #include <linux/uaccess.h>
30 #include <asm/mach-types.h>
31 #include <asm/arch/dma.h>
32 #include <asm/arch/omapfb.h>
34 #define MODULE_NAME "omapfb"
36 static unsigned int def_accel;
37 static unsigned long def_vram[OMAPFB_PLANE_NUM];
38 static int def_vram_cnt;
39 static unsigned long def_vxres;
40 static unsigned long def_vyres;
41 static unsigned int def_rotate;
42 static unsigned int def_mirror;
44 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
45 static int manual_update = 1;
47 static int manual_update;
50 static struct platform_device *fbdev_pdev;
51 static struct lcd_panel *fbdev_panel;
52 static struct omapfb_device *omapfb_dev;
54 struct caps_table_struct {
59 static struct caps_table_struct ctrl_caps[] = {
60 { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
61 { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
62 { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
63 { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
64 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
65 { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
66 { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" },
67 { OMAPFB_CAPS_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",
183 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
184 dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
186 fbdev->mem_desc.region[i].paddr,
187 fbdev->mem_desc.region[i].vaddr,
188 fbdev->mem_desc.region[i].size);
194 static void ctrl_cleanup(struct omapfb_device *fbdev)
196 fbdev->ctrl->cleanup();
199 /* Must be called with fbdev->rqueue_mutex held. */
200 static int ctrl_change_mode(struct fb_info *fbi)
203 unsigned long offset;
204 struct omapfb_plane_struct *plane = fbi->par;
205 struct omapfb_device *fbdev = plane->fbdev;
206 struct fb_var_screeninfo *var = &fbi->var;
208 offset = var->yoffset * fbi->fix.line_length +
209 var->xoffset * var->bits_per_pixel / 8;
211 if (fbdev->ctrl->sync)
213 r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
214 offset, var->xres_virtual,
215 plane->info.pos_x, plane->info.pos_y,
216 var->xres, var->yres, plane->color_mode);
217 if (fbdev->ctrl->set_scale != NULL)
218 r = fbdev->ctrl->set_scale(plane->idx,
219 var->xres, var->yres,
220 plane->info.out_width,
221 plane->info.out_height);
227 * ---------------------------------------------------------------------------
228 * fbdev framework callbacks and the ioctl interface
229 * ---------------------------------------------------------------------------
231 /* Called each time the omapfb device is opened */
232 static int omapfb_open(struct fb_info *info, int user)
237 static void omapfb_sync(struct fb_info *info);
239 /* Called when the omapfb device is closed. We make sure that any pending
240 * gfx DMA operations are ended, before we return. */
241 static int omapfb_release(struct fb_info *info, int user)
247 /* Store a single color palette entry into a pseudo palette or the hardware
248 * palette if one is available. For now we support only 16bpp and thus store
249 * the entry only to the pseudo palette.
251 static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
252 u_int blue, u_int transp, int update_hw_pal)
254 struct omapfb_plane_struct *plane = info->par;
255 struct omapfb_device *fbdev = plane->fbdev;
256 struct fb_var_screeninfo *var = &info->var;
259 switch (plane->color_mode) {
260 case OMAPFB_COLOR_YUV422:
261 case OMAPFB_COLOR_YUV420:
262 case OMAPFB_COLOR_YUY422:
265 case OMAPFB_COLOR_CLUT_8BPP:
266 case OMAPFB_COLOR_CLUT_4BPP:
267 case OMAPFB_COLOR_CLUT_2BPP:
268 case OMAPFB_COLOR_CLUT_1BPP:
269 if (fbdev->ctrl->setcolreg)
270 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
271 transp, update_hw_pal);
273 case OMAPFB_COLOR_RGB565:
274 case OMAPFB_COLOR_RGB444:
285 pal = ((red >> (16 - var->red.length)) <<
287 ((green >> (16 - var->green.length)) <<
289 (blue >> (16 - var->blue.length));
290 ((u32 *)(info->pseudo_palette))[regno] = pal;
299 static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
300 u_int transp, struct fb_info *info)
302 return _setcolreg(info, regno, red, green, blue, transp, 1);
305 static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
308 u16 *red, *green, *blue, *transp;
314 transp = cmap->transp;
317 for (count = 0; count < cmap->len; count++) {
320 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
321 count == cmap->len - 1);
329 static int omapfb_update_full_screen(struct fb_info *fbi);
331 static int omapfb_blank(int blank, struct fb_info *fbi)
333 struct omapfb_plane_struct *plane = fbi->par;
334 struct omapfb_device *fbdev = plane->fbdev;
338 omapfb_rqueue_lock(fbdev);
340 case VESA_NO_BLANKING:
341 if (fbdev->state == OMAPFB_SUSPENDED) {
342 if (fbdev->ctrl->resume)
343 fbdev->ctrl->resume();
344 fbdev->panel->enable(fbdev->panel);
345 fbdev->state = OMAPFB_ACTIVE;
346 if (fbdev->ctrl->get_update_mode() ==
347 OMAPFB_MANUAL_UPDATE)
352 if (fbdev->state == OMAPFB_ACTIVE) {
353 fbdev->panel->disable(fbdev->panel);
354 if (fbdev->ctrl->suspend)
355 fbdev->ctrl->suspend();
356 fbdev->state = OMAPFB_SUSPENDED;
362 omapfb_rqueue_unlock(fbdev);
364 if (r == 0 && do_update)
365 r = omapfb_update_full_screen(fbi);
370 static void omapfb_sync(struct fb_info *fbi)
372 struct omapfb_plane_struct *plane = fbi->par;
373 struct omapfb_device *fbdev = plane->fbdev;
375 omapfb_rqueue_lock(fbdev);
376 if (fbdev->ctrl->sync)
378 omapfb_rqueue_unlock(fbdev);
382 * Set fb_info.fix fields and also updates fbdev.
383 * When calling this fb_info.var must be set up already.
385 static void set_fb_fix(struct fb_info *fbi)
387 struct fb_fix_screeninfo *fix = &fbi->fix;
388 struct fb_var_screeninfo *var = &fbi->var;
389 struct omapfb_plane_struct *plane = fbi->par;
390 struct omapfb_mem_region *rg;
393 rg = &plane->fbdev->mem_desc.region[plane->idx];
394 fbi->screen_base = (char __iomem *)rg->vaddr;
395 fix->smem_start = rg->paddr;
396 fix->smem_len = rg->size;
398 fix->type = FB_TYPE_PACKED_PIXELS;
399 bpp = var->bits_per_pixel;
401 fix->visual = FB_VISUAL_PSEUDOCOLOR;
402 else switch (var->bits_per_pixel) {
405 fix->visual = FB_VISUAL_TRUECOLOR;
406 /* 12bpp is stored in 16 bits */
413 fix->visual = FB_VISUAL_PSEUDOCOLOR;
416 fix->accel = FB_ACCEL_OMAP1610;
417 fix->line_length = var->xres_virtual * bpp / 8;
420 static int set_color_mode(struct omapfb_plane_struct *plane,
421 struct fb_var_screeninfo *var)
423 switch (var->nonstd) {
426 case OMAPFB_COLOR_YUV422:
427 var->bits_per_pixel = 16;
428 plane->color_mode = var->nonstd;
430 case OMAPFB_COLOR_YUV420:
431 var->bits_per_pixel = 12;
432 plane->color_mode = var->nonstd;
434 case OMAPFB_COLOR_YUY422:
435 var->bits_per_pixel = 16;
436 plane->color_mode = var->nonstd;
442 switch (var->bits_per_pixel) {
444 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
447 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
450 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
453 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
456 var->bits_per_pixel = 16;
457 plane->color_mode = OMAPFB_COLOR_RGB444;
460 plane->color_mode = OMAPFB_COLOR_RGB565;
468 * Check the values in var against our capabilities and in case of out of
469 * bound values try to adjust them.
471 static int set_fb_var(struct fb_info *fbi,
472 struct fb_var_screeninfo *var)
475 unsigned long max_frame_size;
476 unsigned long line_size;
477 int xres_min, xres_max;
478 int yres_min, yres_max;
479 struct omapfb_plane_struct *plane = fbi->par;
480 struct omapfb_device *fbdev = plane->fbdev;
481 struct lcd_panel *panel = fbdev->panel;
483 if (set_color_mode(plane, var) < 0)
486 bpp = var->bits_per_pixel;
487 if (plane->color_mode == OMAPFB_COLOR_RGB444)
490 switch (var->rotate) {
493 xres_min = OMAPFB_PLANE_XRES_MIN;
494 xres_max = panel->x_res;
495 yres_min = OMAPFB_PLANE_YRES_MIN;
496 yres_max = panel->y_res;
497 if (cpu_is_omap15xx()) {
498 var->xres = panel->x_res;
499 var->yres = panel->y_res;
504 xres_min = OMAPFB_PLANE_YRES_MIN;
505 xres_max = panel->y_res;
506 yres_min = OMAPFB_PLANE_XRES_MIN;
507 yres_max = panel->x_res;
508 if (cpu_is_omap15xx()) {
509 var->xres = panel->y_res;
510 var->yres = panel->x_res;
517 if (var->xres < xres_min)
518 var->xres = xres_min;
519 if (var->yres < yres_min)
520 var->yres = yres_min;
521 if (var->xres > xres_max)
522 var->xres = xres_max;
523 if (var->yres > yres_max)
524 var->yres = yres_max;
526 if (var->xres_virtual < var->xres)
527 var->xres_virtual = var->xres;
528 if (var->yres_virtual < var->yres)
529 var->yres_virtual = var->yres;
530 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
531 line_size = var->xres_virtual * bpp / 8;
532 if (line_size * var->yres_virtual > max_frame_size) {
533 /* Try to keep yres_virtual first */
534 line_size = max_frame_size / var->yres_virtual;
535 var->xres_virtual = line_size * 8 / bpp;
536 if (var->xres_virtual < var->xres) {
537 /* Still doesn't fit. Shrink yres_virtual too */
538 var->xres_virtual = var->xres;
539 line_size = var->xres * bpp / 8;
540 var->yres_virtual = max_frame_size / line_size;
542 /* Recheck this, as the virtual size changed. */
543 if (var->xres_virtual < var->xres)
544 var->xres = var->xres_virtual;
545 if (var->yres_virtual < var->yres)
546 var->yres = var->yres_virtual;
547 if (var->xres < xres_min || var->yres < yres_min)
550 if (var->xres + var->xoffset > var->xres_virtual)
551 var->xoffset = var->xres_virtual - var->xres;
552 if (var->yres + var->yoffset > var->yres_virtual)
553 var->yoffset = var->yres_virtual - var->yres;
554 line_size = var->xres * bpp / 8;
556 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
557 var->red.offset = 8; var->red.length = 4;
558 var->red.msb_right = 0;
559 var->green.offset = 4; var->green.length = 4;
560 var->green.msb_right = 0;
561 var->blue.offset = 0; var->blue.length = 4;
562 var->blue.msb_right = 0;
564 var->red.offset = 11; var->red.length = 5;
565 var->red.msb_right = 0;
566 var->green.offset = 5; var->green.length = 6;
567 var->green.msb_right = 0;
568 var->blue.offset = 0; var->blue.length = 5;
569 var->blue.msb_right = 0;
576 /* pixclock in ps, the rest in pixclock */
577 var->pixclock = 10000000 / (panel->pixel_clock / 100);
578 var->left_margin = panel->hfp;
579 var->right_margin = panel->hbp;
580 var->upper_margin = panel->vfp;
581 var->lower_margin = panel->vbp;
582 var->hsync_len = panel->hsw;
583 var->vsync_len = panel->vsw;
585 /* TODO: get these from panel->config */
586 var->vmode = FB_VMODE_NONINTERLACED;
593 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
594 static void omapfb_rotate(struct fb_info *fbi, int rotate)
596 struct omapfb_plane_struct *plane = fbi->par;
597 struct omapfb_device *fbdev = plane->fbdev;
599 omapfb_rqueue_lock(fbdev);
600 if (cpu_is_omap15xx() && rotate != fbi->var.rotate) {
601 struct fb_var_screeninfo *new_var = &fbdev->new_var;
603 memcpy(new_var, &fbi->var, sizeof(*new_var));
604 new_var->rotate = rotate;
605 if (set_fb_var(fbi, new_var) == 0 &&
606 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
607 memcpy(&fbi->var, new_var, sizeof(*new_var));
608 ctrl_change_mode(fbi);
611 omapfb_rqueue_unlock(fbdev);
615 * Set new x,y offsets in the virtual display for the visible area and switch
618 static int omapfb_pan_display(struct fb_var_screeninfo *var,
621 struct omapfb_plane_struct *plane = fbi->par;
622 struct omapfb_device *fbdev = plane->fbdev;
625 omapfb_rqueue_lock(fbdev);
626 if (var->xoffset != fbi->var.xoffset ||
627 var->yoffset != fbi->var.yoffset) {
628 struct fb_var_screeninfo *new_var = &fbdev->new_var;
630 memcpy(new_var, &fbi->var, sizeof(*new_var));
631 new_var->xoffset = var->xoffset;
632 new_var->yoffset = var->yoffset;
633 if (set_fb_var(fbi, new_var))
636 memcpy(&fbi->var, new_var, sizeof(*new_var));
637 ctrl_change_mode(fbi);
640 omapfb_rqueue_unlock(fbdev);
645 /* Set mirror to vertical axis and switch to the new mode. */
646 static int omapfb_mirror(struct fb_info *fbi, int mirror)
648 struct omapfb_plane_struct *plane = fbi->par;
649 struct omapfb_device *fbdev = plane->fbdev;
652 omapfb_rqueue_lock(fbdev);
653 mirror = mirror ? 1 : 0;
654 if (cpu_is_omap15xx())
656 else if (mirror != plane->info.mirror) {
657 plane->info.mirror = mirror;
658 r = ctrl_change_mode(fbi);
660 omapfb_rqueue_unlock(fbdev);
666 * Check values in var, try to adjust them in case of out of bound values if
667 * possible, or return error.
669 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
671 struct omapfb_plane_struct *plane = fbi->par;
672 struct omapfb_device *fbdev = plane->fbdev;
675 omapfb_rqueue_lock(fbdev);
676 if (fbdev->ctrl->sync != NULL)
678 r = set_fb_var(fbi, var);
679 omapfb_rqueue_unlock(fbdev);
685 * Switch to a new mode. The parameters for it has been check already by
688 static int omapfb_set_par(struct fb_info *fbi)
690 struct omapfb_plane_struct *plane = fbi->par;
691 struct omapfb_device *fbdev = plane->fbdev;
694 omapfb_rqueue_lock(fbdev);
696 r = ctrl_change_mode(fbi);
697 omapfb_rqueue_unlock(fbdev);
702 int omapfb_update_window_async(struct fb_info *fbi,
703 struct omapfb_update_window *win,
704 void (*callback)(void *),
707 struct omapfb_plane_struct *plane = fbi->par;
708 struct omapfb_device *fbdev = plane->fbdev;
709 struct fb_var_screeninfo *var;
712 if (win->x >= var->xres || win->y >= var->yres ||
713 win->out_x > var->xres || win->out_y >= var->yres)
716 if (!fbdev->ctrl->update_window ||
717 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
720 if (win->x + win->width >= var->xres)
721 win->width = var->xres - win->x;
722 if (win->y + win->height >= var->yres)
723 win->height = var->yres - win->y;
724 /* The out sizes should be cropped to the LCD size */
725 if (win->out_x + win->out_width > fbdev->panel->x_res)
726 win->out_width = fbdev->panel->x_res - win->out_x;
727 if (win->out_y + win->out_height > fbdev->panel->y_res)
728 win->out_height = fbdev->panel->y_res - win->out_y;
729 if (!win->width || !win->height || !win->out_width || !win->out_height)
732 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
734 EXPORT_SYMBOL(omapfb_update_window_async);
736 static int omapfb_update_win(struct fb_info *fbi,
737 struct omapfb_update_window *win)
739 struct omapfb_plane_struct *plane = fbi->par;
742 omapfb_rqueue_lock(plane->fbdev);
743 ret = omapfb_update_window_async(fbi, win, NULL, 0);
744 omapfb_rqueue_unlock(plane->fbdev);
749 static int omapfb_update_full_screen(struct fb_info *fbi)
751 struct omapfb_plane_struct *plane = fbi->par;
752 struct omapfb_device *fbdev = plane->fbdev;
753 struct omapfb_update_window win;
756 if (!fbdev->ctrl->update_window ||
757 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
762 win.width = fbi->var.xres;
763 win.height = fbi->var.yres;
766 win.out_width = fbi->var.xres;
767 win.out_height = fbi->var.yres;
770 omapfb_rqueue_lock(fbdev);
771 r = fbdev->ctrl->update_window(fbi, &win, NULL, 0);
772 omapfb_rqueue_unlock(fbdev);
777 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
779 struct omapfb_plane_struct *plane = fbi->par;
780 struct omapfb_device *fbdev = plane->fbdev;
781 struct lcd_panel *panel = fbdev->panel;
782 struct omapfb_plane_info old_info;
785 if (pi->pos_x + pi->out_width > panel->x_res ||
786 pi->pos_y + pi->out_height > panel->y_res)
789 omapfb_rqueue_lock(fbdev);
790 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
792 * This plane's memory was freed, can't enable it
793 * until it's reallocated.
798 old_info = plane->info;
801 r = ctrl_change_mode(fbi);
803 plane->info = old_info;
807 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
809 plane->info = old_info;
813 omapfb_rqueue_unlock(fbdev);
817 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
819 struct omapfb_plane_struct *plane = fbi->par;
825 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
827 struct omapfb_plane_struct *plane = fbi->par;
828 struct omapfb_device *fbdev = plane->fbdev;
829 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
833 if (fbdev->ctrl->setup_mem == NULL)
835 if (mi->type > OMAPFB_MEMTYPE_MAX)
838 size = PAGE_ALIGN(mi->size);
839 omapfb_rqueue_lock(fbdev);
840 if (plane->info.enabled) {
844 if (rg->size != size || rg->type != mi->type) {
845 struct fb_var_screeninfo *new_var = &fbdev->new_var;
846 unsigned long old_size = rg->size;
847 u8 old_type = rg->type;
853 * size == 0 is a special case, for which we
854 * don't check / adjust the screen parameters.
855 * This isn't a problem since the plane can't
856 * be reenabled unless its size is > 0.
858 if (old_size != size && size) {
860 memcpy(new_var, &fbi->var, sizeof(*new_var));
861 r = set_fb_var(fbi, new_var);
867 if (fbdev->ctrl->sync)
869 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
871 /* Revert changes. */
878 if (old_size != size) {
880 memcpy(&fbi->var, new_var, sizeof(fbi->var));
884 * Set these explicitly to indicate that the
885 * plane memory is dealloce'd, the other
886 * screen parameters in var / fix are invalid.
888 fbi->fix.smem_start = 0;
889 fbi->fix.smem_len = 0;
894 omapfb_rqueue_unlock(fbdev);
899 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
901 struct omapfb_plane_struct *plane = fbi->par;
902 struct omapfb_device *fbdev = plane->fbdev;
903 struct omapfb_mem_region *rg;
905 rg = &fbdev->mem_desc.region[plane->idx];
906 memset(mi, 0, sizeof(*mi));
913 static int omapfb_set_color_key(struct omapfb_device *fbdev,
914 struct omapfb_color_key *ck)
918 if (!fbdev->ctrl->set_color_key)
921 omapfb_rqueue_lock(fbdev);
922 r = fbdev->ctrl->set_color_key(ck);
923 omapfb_rqueue_unlock(fbdev);
928 static int omapfb_get_color_key(struct omapfb_device *fbdev,
929 struct omapfb_color_key *ck)
933 if (!fbdev->ctrl->get_color_key)
936 omapfb_rqueue_lock(fbdev);
937 r = fbdev->ctrl->get_color_key(ck);
938 omapfb_rqueue_unlock(fbdev);
943 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
944 static int notifier_inited;
946 static void omapfb_init_notifier(void)
950 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
951 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
954 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
955 omapfb_notifier_callback_t callback,
960 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
963 if (!notifier_inited) {
964 omapfb_init_notifier();
968 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
969 unsigned long, void *))callback;
970 omapfb_nb->data = callback_data;
971 r = blocking_notifier_chain_register(
972 &omapfb_client_list[omapfb_nb->plane_idx],
976 if (omapfb_dev != NULL &&
977 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
978 omapfb_dev->ctrl->bind_client(omapfb_nb);
983 EXPORT_SYMBOL(omapfb_register_client);
985 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
987 return blocking_notifier_chain_unregister(
988 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
990 EXPORT_SYMBOL(omapfb_unregister_client);
992 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
996 if (!notifier_inited)
997 /* no client registered yet */
1000 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1001 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1004 EXPORT_SYMBOL(omapfb_notify_clients);
1006 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1007 enum omapfb_update_mode mode)
1011 omapfb_rqueue_lock(fbdev);
1012 r = fbdev->ctrl->set_update_mode(mode);
1013 omapfb_rqueue_unlock(fbdev);
1018 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1022 omapfb_rqueue_lock(fbdev);
1023 r = fbdev->ctrl->get_update_mode();
1024 omapfb_rqueue_unlock(fbdev);
1029 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1030 struct omapfb_caps *caps)
1032 memset(caps, 0, sizeof(*caps));
1033 fbdev->ctrl->get_caps(plane, caps);
1034 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1037 /* For lcd testing */
1038 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1040 omapfb_rqueue_lock(fbdev);
1041 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1042 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1043 struct omapfb_update_window win;
1045 memset(&win, 0, sizeof(win));
1050 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0);
1052 omapfb_rqueue_unlock(fbdev);
1054 EXPORT_SYMBOL(omapfb_write_first_pixel);
1057 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1058 * here to be accessible by user mode code.
1060 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1063 struct omapfb_plane_struct *plane = fbi->par;
1064 struct omapfb_device *fbdev = plane->fbdev;
1065 struct fb_ops *ops = fbi->fbops;
1067 struct omapfb_update_window update_window;
1068 struct omapfb_plane_info plane_info;
1069 struct omapfb_mem_info mem_info;
1070 struct omapfb_color_key color_key;
1071 enum omapfb_update_mode update_mode;
1072 struct omapfb_caps caps;
1073 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,
1356 return r ? r : size;
1359 static ssize_t omapfb_show_bklight_max(struct device *dev,
1360 struct device_attribute *attr, char *buf)
1362 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1365 if (fbdev->panel->get_bklight_level) {
1366 r = snprintf(buf, PAGE_SIZE, "%d\n",
1367 fbdev->panel->get_bklight_max(fbdev->panel));
1373 static struct device_attribute dev_attr_panel_name =
1374 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1375 static DEVICE_ATTR(backlight_level, 0664,
1376 omapfb_show_bklight_level, omapfb_store_bklight_level);
1377 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1379 static struct attribute *panel_attrs[] = {
1380 &dev_attr_panel_name.attr,
1381 &dev_attr_backlight_level.attr,
1382 &dev_attr_backlight_max.attr,
1386 static struct attribute_group panel_attr_grp = {
1388 .attrs = panel_attrs,
1391 /* ctrl sysfs entries */
1392 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1393 struct device_attribute *attr, char *buf)
1395 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1397 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1400 static struct device_attribute dev_attr_ctrl_name =
1401 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1403 static struct attribute *ctrl_attrs[] = {
1404 &dev_attr_ctrl_name.attr,
1408 static struct attribute_group ctrl_attr_grp = {
1410 .attrs = ctrl_attrs,
1413 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1417 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1420 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1423 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1426 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1431 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1433 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1435 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1437 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1441 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1443 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1444 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1445 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1446 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1450 * ---------------------------------------------------------------------------
1452 * ---------------------------------------------------------------------------
1454 /* Initialize system fb_info object and set the default video mode.
1455 * The frame buffer memory already allocated by lcddma_init
1457 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1459 struct fb_var_screeninfo *var = &info->var;
1460 struct fb_fix_screeninfo *fix = &info->fix;
1463 info->fbops = &omapfb_ops;
1464 info->flags = FBINFO_FLAG_DEFAULT;
1466 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1468 info->pseudo_palette = fbdev->pseudo_palette;
1470 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1471 var->xres = def_vxres;
1472 var->yres = def_vyres;
1473 var->xres_virtual = def_vxres;
1474 var->yres_virtual = def_vyres;
1475 var->rotate = def_rotate;
1476 var->bits_per_pixel = fbdev->panel->bpp;
1478 set_fb_var(info, var);
1481 r = fb_alloc_cmap(&info->cmap, 16, 0);
1483 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1488 /* Release the fb_info object */
1489 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1491 fb_dealloc_cmap(&fbi->cmap);
1494 static void planes_cleanup(struct omapfb_device *fbdev)
1498 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1499 if (fbdev->fb_info[i] == NULL)
1501 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1502 framebuffer_release(fbdev->fb_info[i]);
1506 static int planes_init(struct omapfb_device *fbdev)
1508 struct fb_info *fbi;
1512 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1513 struct omapfb_plane_struct *plane;
1514 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1518 "unable to allocate memory for plane info\n");
1519 planes_cleanup(fbdev);
1524 plane->fbdev = fbdev;
1525 plane->info.mirror = def_mirror;
1526 fbdev->fb_info[i] = fbi;
1528 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1529 framebuffer_release(fbi);
1530 planes_cleanup(fbdev);
1533 plane->info.out_width = fbi->var.xres;
1534 plane->info.out_height = fbi->var.yres;
1540 * Free driver resources. Can be called to rollback an aborted initialization
1543 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1549 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1550 unregister_framebuffer(fbdev->fb_info[i]);
1552 omapfb_unregister_sysfs(fbdev);
1554 fbdev->panel->disable(fbdev->panel);
1556 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1558 planes_cleanup(fbdev);
1560 ctrl_cleanup(fbdev);
1562 fbdev->panel->cleanup(fbdev->panel);
1564 dev_set_drvdata(fbdev->dev, NULL);
1567 /* nothing to free */
1574 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1576 struct omapfb_platform_data *conf;
1580 conf = fbdev->dev->platform_data;
1584 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1585 name[sizeof(name) - 1] = '\0';
1587 if (strcmp(name, "internal") == 0) {
1588 fbdev->ctrl = fbdev->int_ctrl;
1592 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1593 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1594 if (strcmp(ctrls[i]->name, name) == 0) {
1595 fbdev->ctrl = ctrls[i];
1600 if (fbdev->ctrl == NULL) {
1601 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1608 static void check_required_callbacks(struct omapfb_device *fbdev)
1610 #define _C(x) (fbdev->ctrl->x != NULL)
1611 #define _P(x) (fbdev->panel->x != NULL)
1612 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1613 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1614 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1615 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1622 * Called by LDM binding to probe and attach a new device.
1623 * Initialization sequence:
1624 * 1. allocate system omapfb_device structure
1625 * 2. select controller type according to platform configuration
1627 * 3. init LCD controller and LCD DMA
1628 * 4. init system fb_info structure for all planes
1629 * 5. setup video mode for first plane and enable it
1630 * 6. enable LCD panel
1631 * 7. register sysfs attributes
1632 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1634 static int omapfb_do_probe(struct platform_device *pdev,
1635 struct lcd_panel *panel)
1637 struct omapfb_device *fbdev = NULL;
1639 unsigned long phz, hhz, vhz;
1646 if (pdev->num_resources != 0) {
1647 dev_err(&pdev->dev, "probed for an unknown device\n");
1652 if (pdev->dev.platform_data == NULL) {
1653 dev_err(&pdev->dev, "missing platform data\n");
1658 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1659 if (fbdev == NULL) {
1661 "unable to allocate memory for device info\n");
1667 fbdev->dev = &pdev->dev;
1668 fbdev->panel = panel;
1669 platform_set_drvdata(pdev, fbdev);
1671 mutex_init(&fbdev->rqueue_mutex);
1673 #ifdef CONFIG_ARCH_OMAP1
1674 fbdev->int_ctrl = &omap1_int_ctrl;
1675 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1676 fbdev->ext_if = &omap1_ext_if;
1679 fbdev->int_ctrl = &omap2_int_ctrl;
1680 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1681 fbdev->ext_if = &omap2_ext_if;
1684 if (omapfb_find_ctrl(fbdev) < 0) {
1686 "LCD controller not found, board not supported\n");
1691 r = fbdev->panel->init(fbdev->panel, fbdev);
1695 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1697 def_vxres = def_vxres ? : fbdev->panel->x_res;
1698 def_vyres = def_vyres ? : fbdev->panel->y_res;
1702 r = ctrl_init(fbdev);
1705 if (fbdev->ctrl->mmap != NULL)
1706 omapfb_ops.fb_mmap = omapfb_mmap;
1709 check_required_callbacks(fbdev);
1711 r = planes_init(fbdev);
1716 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1717 /* Set DMA priority for EMIFF access to highest */
1718 if (cpu_class_is_omap1())
1719 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1722 r = ctrl_change_mode(fbdev->fb_info[0]);
1724 dev_err(fbdev->dev, "mode setting failed\n");
1728 /* GFX plane is enabled by default */
1729 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1733 omapfb_set_update_mode(fbdev, manual_update ?
1734 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1737 r = fbdev->panel->enable(fbdev->panel);
1742 r = omapfb_register_sysfs(fbdev);
1748 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1749 r = register_framebuffer(fbdev->fb_info[i]);
1752 "registering framebuffer %d failed\n", i);
1755 vram += fbdev->mem_desc.region[i].size;
1758 fbdev->state = OMAPFB_ACTIVE;
1760 panel = fbdev->panel;
1761 phz = panel->pixel_clock * 1000;
1762 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1763 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1767 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1768 vram, fbdev->mem_desc.region_cnt);
1769 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1770 "vfreq %lu.%lu Hz\n",
1771 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1776 omapfb_free_resources(fbdev, init_state);
1781 static int omapfb_probe(struct platform_device *pdev)
1783 BUG_ON(fbdev_pdev != NULL);
1785 /* Delay actual initialization until the LCD is registered */
1787 if (fbdev_panel != NULL)
1788 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1792 void omapfb_register_panel(struct lcd_panel *panel)
1794 BUG_ON(fbdev_panel != NULL);
1796 fbdev_panel = panel;
1797 if (fbdev_pdev != NULL)
1798 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1801 /* Called when the device is being detached from the driver */
1802 static int omapfb_remove(struct platform_device *pdev)
1804 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1805 enum omapfb_state saved_state = fbdev->state;
1807 /* FIXME: wait till completion of pending events */
1809 fbdev->state = OMAPFB_DISABLED;
1810 omapfb_free_resources(fbdev, saved_state);
1816 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1818 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1820 omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
1826 static int omapfb_resume(struct platform_device *pdev)
1828 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1830 omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
1834 static struct platform_driver omapfb_driver = {
1835 .probe = omapfb_probe,
1836 .remove = omapfb_remove,
1837 .suspend = omapfb_suspend,
1838 .resume = omapfb_resume,
1840 .name = MODULE_NAME,
1841 .owner = THIS_MODULE,
1847 /* Process kernel command line parameters */
1848 static int __init omapfb_setup(char *options)
1850 char *this_opt = NULL;
1853 pr_debug("omapfb: options %s\n", options);
1855 if (!options || !*options)
1858 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1859 if (!strncmp(this_opt, "accel", 5))
1861 else if (!strncmp(this_opt, "vram:", 5)) {
1864 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1865 switch (suffix[0]) {
1877 pr_debug("omapfb: invalid vram suffix %c\n",
1881 def_vram[def_vram_cnt++] = vram;
1883 else if (!strncmp(this_opt, "vxres:", 6))
1884 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1885 else if (!strncmp(this_opt, "vyres:", 6))
1886 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1887 else if (!strncmp(this_opt, "rotate:", 7))
1888 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1889 else if (!strncmp(this_opt, "mirror:", 7))
1890 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1891 else if (!strncmp(this_opt, "manual_update", 13))
1894 pr_debug("omapfb: invalid option\n");
1904 /* Register both the driver and the device */
1905 static int __init omapfb_init(void)
1910 if (fb_get_options("omapfb", &option))
1912 omapfb_setup(option);
1914 /* Register the driver with LDM */
1915 if (platform_driver_register(&omapfb_driver)) {
1916 pr_debug("failed to register omapfb driver\n");
1923 static void __exit omapfb_cleanup(void)
1925 platform_driver_unregister(&omapfb_driver);
1928 module_param_named(accel, def_accel, uint, 0664);
1929 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1930 module_param_named(vxres, def_vxres, long, 0664);
1931 module_param_named(vyres, def_vyres, long, 0664);
1932 module_param_named(rotate, def_rotate, uint, 0664);
1933 module_param_named(mirror, def_mirror, uint, 0664);
1934 module_param_named(manual_update, manual_update, bool, 0664);
1936 module_init(omapfb_init);
1937 module_exit(omapfb_cleanup);
1939 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1940 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1941 MODULE_LICENSE("GPL");