2 * File: drivers/video/omap/omapfb_main.c
4 * Framebuffer driver for TI OMAP boards
6 * Copyright (C) 2004 Nokia Corporation
7 * Author: Imre Deak <imre.deak@nokia.com>
10 * Alex McMains <aam@ridgerun.com> - Original driver
11 * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
12 * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
13 * Texas Instruments - H3 support
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <linux/platform_device.h>
31 #include <asm/uaccess.h>
32 #include <asm/mach-types.h>
33 #include <asm/arch/dma.h>
34 #include <asm/arch/omapfb.h>
36 #define MODULE_NAME "omapfb"
38 static unsigned int def_accel;
39 static unsigned long def_vram[OMAPFB_PLANE_NUM];
40 static int def_vram_cnt;
41 static unsigned long def_vxres;
42 static unsigned long def_vyres;
43 static unsigned int def_rotate;
44 static unsigned int def_mirror;
46 #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
47 static int manual_update = 1;
49 static int manual_update;
52 static struct platform_device *fbdev_pdev;
53 static struct lcd_panel *fbdev_panel;
54 static struct omapfb_device *omapfb_dev;
56 struct caps_table_struct {
61 static struct caps_table_struct ctrl_caps[] = {
62 { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
63 { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
64 { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
65 { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
66 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
67 { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
68 { OMAPFB_CAPS_WINDOW_OVERLAY,"overlay window" },
69 { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" },
72 static struct caps_table_struct color_caps[] = {
73 { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
74 { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
75 { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
76 { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
77 { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
78 { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
79 { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
80 { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
81 { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
85 * ---------------------------------------------------------------------------
87 * ---------------------------------------------------------------------------
89 extern struct lcd_ctrl omap1_int_ctrl;
90 extern struct lcd_ctrl omap2_int_ctrl;
91 extern struct lcd_ctrl hwa742_ctrl;
92 extern struct lcd_ctrl blizzard_ctrl;
94 static struct lcd_ctrl *ctrls[] = {
95 #ifdef CONFIG_ARCH_OMAP1
101 #ifdef CONFIG_FB_OMAP_LCDC_HWA742
104 #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
109 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
110 #ifdef CONFIG_ARCH_OMAP1
111 extern struct lcd_ctrl_extif omap1_ext_if;
113 extern struct lcd_ctrl_extif omap2_ext_if;
117 static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
119 mutex_lock(&fbdev->rqueue_mutex);
122 static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
124 mutex_unlock(&fbdev->rqueue_mutex);
128 * ---------------------------------------------------------------------------
129 * LCD controller and LCD DMA
130 * ---------------------------------------------------------------------------
132 /* Lookup table to map elem size to elem type. */
133 static const int dma_elem_type[] = {
135 OMAP_DMA_DATA_TYPE_S8,
136 OMAP_DMA_DATA_TYPE_S16,
138 OMAP_DMA_DATA_TYPE_S32,
141 /* Allocate resources needed for LCD controller and LCD DMA operations. Video
142 * memory is allocated from system memory according to the virtual display
143 * size, except if a bigger memory size is specified explicitly as a kernel
146 static int ctrl_init(struct omapfb_device *fbdev)
151 /* kernel/module vram parameters override boot tags/board config */
153 for (i = 0; i < def_vram_cnt; i++)
154 fbdev->mem_desc.region[i].size =
155 PAGE_ALIGN(def_vram[i]);
156 fbdev->mem_desc.region_cnt = i;
158 struct omapfb_platform_data *conf;
160 conf = fbdev->dev->platform_data;
161 fbdev->mem_desc = conf->mem_desc;
164 if (!fbdev->mem_desc.region_cnt) {
165 struct lcd_panel *panel = fbdev->panel;
167 int bpp = panel->bpp;
169 /* 12 bpp is packed in 16 bits */
172 def_size = def_vxres * def_vyres * bpp / 8;
173 fbdev->mem_desc.region_cnt = 1;
174 fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
176 r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
178 dev_err(fbdev->dev, "controller initialization failed (%d)\n", r);
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);
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;
466 /* Check the values in var against our capabilities and in case of out of
467 * bound values try to adjust them.
469 static int set_fb_var(struct fb_info *fbi,
470 struct fb_var_screeninfo *var)
473 unsigned long max_frame_size;
474 unsigned long line_size;
475 int xres_min, xres_max;
476 int yres_min, yres_max;
477 struct omapfb_plane_struct *plane = fbi->par;
478 struct omapfb_device *fbdev = plane->fbdev;
479 struct lcd_panel *panel = fbdev->panel;
481 if (set_color_mode(plane, var) < 0)
484 bpp = var->bits_per_pixel;
485 if (plane->color_mode == OMAPFB_COLOR_RGB444)
488 switch (var->rotate) {
491 xres_min = OMAPFB_PLANE_XRES_MIN;
492 xres_max = panel->x_res;
493 yres_min = OMAPFB_PLANE_YRES_MIN;
494 yres_max = panel->y_res;
495 if (cpu_is_omap15xx()) {
496 var->xres = panel->x_res;
497 var->yres = panel->y_res;
502 xres_min = OMAPFB_PLANE_YRES_MIN;
503 xres_max = panel->y_res;
504 yres_min = OMAPFB_PLANE_XRES_MIN;
505 yres_max = panel->x_res;
506 if (cpu_is_omap15xx()) {
507 var->xres = panel->y_res;
508 var->yres = panel->x_res;
515 if (var->xres < xres_min)
516 var->xres = xres_min;
517 if (var->yres < yres_min)
518 var->yres = yres_min;
519 if (var->xres > xres_max)
520 var->xres = xres_max;
521 if (var->yres > yres_max)
522 var->yres = yres_max;
524 if (var->xres_virtual < var->xres)
525 var->xres_virtual = var->xres;
526 if (var->yres_virtual < var->yres)
527 var->yres_virtual = var->yres;
528 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
529 line_size = var->xres_virtual * bpp / 8;
530 if (line_size * var->yres_virtual > max_frame_size) {
531 /* Try to keep yres_virtual first */
532 line_size = max_frame_size / var->yres_virtual;
533 var->xres_virtual = line_size * 8 / bpp;
534 if (var->xres_virtual < var->xres) {
535 /* Still doesn't fit. Shrink yres_virtual too */
536 var->xres_virtual = var->xres;
537 line_size = var->xres * bpp / 8;
538 var->yres_virtual = max_frame_size / line_size;
540 /* Recheck this, as the virtual size changed. */
541 if (var->xres_virtual < var->xres)
542 var->xres = var->xres_virtual;
543 if (var->yres_virtual < var->yres)
544 var->yres = var->yres_virtual;
545 if (var->xres < xres_min || var->yres < yres_min)
548 if (var->xres + var->xoffset > var->xres_virtual)
549 var->xoffset = var->xres_virtual - var->xres;
550 if (var->yres + var->yoffset > var->yres_virtual)
551 var->yoffset = var->yres_virtual - var->yres;
552 line_size = var->xres * bpp / 8;
554 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
555 var->red.offset = 8; var->red.length = 4;
556 var->red.msb_right = 0;
557 var->green.offset = 4; var->green.length = 4;
558 var->green.msb_right = 0;
559 var->blue.offset = 0; var->blue.length = 4;
560 var->blue.msb_right = 0;
562 var->red.offset = 11; var->red.length = 5;
563 var->red.msb_right = 0;
564 var->green.offset= 5; var->green.length = 6;
565 var->green.msb_right = 0;
566 var->blue.offset = 0; var->blue.length = 5;
567 var->blue.msb_right = 0;
574 /* pixclock in ps, the rest in pixclock */
575 var->pixclock = 10000000 / (panel->pixel_clock / 100);
576 var->left_margin = panel->hfp;
577 var->right_margin = panel->hbp;
578 var->upper_margin = panel->vfp;
579 var->lower_margin = panel->vbp;
580 var->hsync_len = panel->hsw;
581 var->vsync_len = panel->vsw;
583 /* TODO: get these from panel->config */
584 var->vmode = FB_VMODE_NONINTERLACED;
591 /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
592 static void omapfb_rotate(struct fb_info *fbi, int rotate)
594 struct omapfb_plane_struct *plane = fbi->par;
595 struct omapfb_device *fbdev = plane->fbdev;
597 omapfb_rqueue_lock(fbdev);
598 if (cpu_is_omap15xx() && rotate != fbi->var.rotate) {
599 struct fb_var_screeninfo *new_var = &fbdev->new_var;
601 memcpy(new_var, &fbi->var, sizeof(*new_var));
602 new_var->rotate = rotate;
603 if (set_fb_var(fbi, new_var) == 0 &&
604 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
605 memcpy(&fbi->var, new_var, sizeof(*new_var));
606 ctrl_change_mode(fbi);
609 omapfb_rqueue_unlock(fbdev);
612 /* Set new x,y offsets in the virtual display for the visible area and switch
615 static int omapfb_pan_display(struct fb_var_screeninfo *var,
618 struct omapfb_plane_struct *plane = fbi->par;
619 struct omapfb_device *fbdev = plane->fbdev;
622 omapfb_rqueue_lock(fbdev);
623 if (var->xoffset != fbi->var.xoffset ||
624 var->yoffset != fbi->var.yoffset) {
625 struct fb_var_screeninfo *new_var = &fbdev->new_var;
627 memcpy(new_var, &fbi->var, sizeof(*new_var));
628 new_var->xoffset = var->xoffset;
629 new_var->yoffset = var->yoffset;
630 if (set_fb_var(fbi, new_var))
633 memcpy(&fbi->var, new_var, sizeof(*new_var));
634 ctrl_change_mode(fbi);
637 omapfb_rqueue_unlock(fbdev);
642 /* Set mirror to vertical axis and switch to the new mode. */
643 static int omapfb_mirror(struct fb_info *fbi, int mirror)
645 struct omapfb_plane_struct *plane = fbi->par;
646 struct omapfb_device *fbdev = plane->fbdev;
649 omapfb_rqueue_lock(fbdev);
650 mirror = mirror ? 1 : 0;
651 if (cpu_is_omap15xx())
653 else if (mirror != plane->info.mirror) {
654 plane->info.mirror = mirror;
655 r = ctrl_change_mode(fbi);
657 omapfb_rqueue_unlock(fbdev);
662 /* Check values in var, try to adjust them in case of out of bound values if
663 * possible, or return error.
665 static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
667 struct omapfb_plane_struct *plane = fbi->par;
668 struct omapfb_device *fbdev = plane->fbdev;
671 omapfb_rqueue_lock(fbdev);
672 if (fbdev->ctrl->sync != NULL)
674 r = set_fb_var(fbi, var);
675 omapfb_rqueue_unlock(fbdev);
680 /* Switch to a new mode. The parameters for it has been check already by
683 static int omapfb_set_par(struct fb_info *fbi)
685 struct omapfb_plane_struct *plane = fbi->par;
686 struct omapfb_device *fbdev = plane->fbdev;
689 omapfb_rqueue_lock(fbdev);
691 r = ctrl_change_mode(fbi);
692 omapfb_rqueue_unlock(fbdev);
697 int omapfb_update_window_async(struct fb_info *fbi,
698 struct omapfb_update_window *win,
699 void (*callback)(void *),
702 struct omapfb_plane_struct *plane = fbi->par;
703 struct omapfb_device *fbdev = plane->fbdev;
704 struct fb_var_screeninfo *var;
707 if (win->x >= var->xres || win->y >= var->yres ||
708 win->out_x > var->xres || win->out_y >= var->yres)
711 if (!fbdev->ctrl->update_window ||
712 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
715 if (win->x + win->width >= var->xres)
716 win->width = var->xres - win->x;
717 if (win->y + win->height >= var->yres)
718 win->height = var->yres - win->y;
719 /* The out sizes should be cropped to the LCD size */
720 if (win->out_x + win->out_width > fbdev->panel->x_res)
721 win->out_width = fbdev->panel->x_res - win->out_x;
722 if (win->out_y + win->out_height > fbdev->panel->y_res)
723 win->out_height = fbdev->panel->y_res - win->out_y;
724 if (!win->width || !win->height || !win->out_width || !win->out_height)
727 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
729 EXPORT_SYMBOL(omapfb_update_window_async);
731 static int omapfb_update_win(struct fb_info *fbi,
732 struct omapfb_update_window *win)
734 struct omapfb_plane_struct *plane = fbi->par;
737 omapfb_rqueue_lock(plane->fbdev);
738 ret = omapfb_update_window_async(fbi, win, NULL, 0);
739 omapfb_rqueue_unlock(plane->fbdev);
744 static int omapfb_update_full_screen(struct fb_info *fbi)
746 struct omapfb_plane_struct *plane = fbi->par;
747 struct omapfb_device *fbdev = plane->fbdev;
748 struct omapfb_update_window win;
751 if (!fbdev->ctrl->update_window ||
752 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
757 win.width = fbi->var.xres;
758 win.height = fbi->var.yres;
761 omapfb_rqueue_lock(fbdev);
762 r = fbdev->ctrl->update_window(fbi, &win, NULL, 0);
763 omapfb_rqueue_unlock(fbdev);
768 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
770 struct omapfb_plane_struct *plane = fbi->par;
771 struct omapfb_device *fbdev = plane->fbdev;
772 struct lcd_panel *panel = fbdev->panel;
773 struct omapfb_plane_info old_info;
776 if (pi->pos_x + pi->out_width > panel->x_res ||
777 pi->pos_y + pi->out_height > panel->y_res)
780 omapfb_rqueue_lock(fbdev);
781 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
782 /* This plane's memory was freed, can't enable it
783 * until it's reallocated.
788 old_info = plane->info;
791 r = ctrl_change_mode(fbi);
793 plane->info = old_info;
797 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
799 plane->info = old_info;
803 omapfb_rqueue_unlock(fbdev);
807 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
809 struct omapfb_plane_struct *plane = fbi->par;
815 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
817 struct omapfb_plane_struct *plane = fbi->par;
818 struct omapfb_device *fbdev = plane->fbdev;
819 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
823 if (fbdev->ctrl->setup_mem == NULL)
825 if (mi->type > OMAPFB_MEMTYPE_MAX)
828 size = PAGE_ALIGN(mi->size);
829 omapfb_rqueue_lock(fbdev);
830 if (plane->info.enabled) {
834 if (rg->size != size || rg->type != mi->type) {
835 struct fb_var_screeninfo *new_var = &fbdev->new_var;
836 unsigned long old_size = rg->size;
837 u8 old_type = rg->type;
842 /* size == 0 is a special case, for which we
843 * don't check / adjust the screen parameters.
844 * This isn't a problem since the plane can't
845 * be reenabled unless its size is > 0.
847 if (old_size != size && size) {
849 memcpy(new_var, &fbi->var, sizeof(*new_var));
850 r = set_fb_var(fbi, new_var);
856 if (fbdev->ctrl->sync)
858 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
860 /* Revert changes. */
867 if (old_size != size) {
869 memcpy(&fbi->var, new_var, sizeof(fbi->var));
872 /* Set these explicitly to indicate that the
873 * plane memory is dealloce'd, the other
874 * screen parameters in var / fix are invalid.
876 fbi->fix.smem_start = 0;
877 fbi->fix.smem_len = 0;
882 omapfb_rqueue_unlock(fbdev);
887 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
889 struct omapfb_plane_struct *plane = fbi->par;
890 struct omapfb_device *fbdev = plane->fbdev;
891 struct omapfb_mem_region *rg;
893 rg = &fbdev->mem_desc.region[plane->idx];
894 memset(mi, 0, sizeof(*mi));
901 static int omapfb_set_color_key(struct omapfb_device *fbdev,
902 struct omapfb_color_key *ck)
906 if (!fbdev->ctrl->set_color_key)
909 omapfb_rqueue_lock(fbdev);
910 r = fbdev->ctrl->set_color_key(ck);
911 omapfb_rqueue_unlock(fbdev);
916 static int omapfb_get_color_key(struct omapfb_device *fbdev,
917 struct omapfb_color_key *ck)
921 if (!fbdev->ctrl->get_color_key)
924 omapfb_rqueue_lock(fbdev);
925 r = fbdev->ctrl->get_color_key(ck);
926 omapfb_rqueue_unlock(fbdev);
931 static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
932 static int notifier_inited;
934 static void omapfb_init_notifier(void)
938 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
939 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
942 int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
943 omapfb_notifier_callback_t callback,
948 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
951 if (!notifier_inited) {
952 omapfb_init_notifier();
956 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
957 unsigned long, void *))callback;
958 omapfb_nb->data = callback_data;
959 r = blocking_notifier_chain_register(
960 &omapfb_client_list[omapfb_nb->plane_idx],
964 if (omapfb_dev != NULL &&
965 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
966 omapfb_dev->ctrl->bind_client(omapfb_nb);
971 EXPORT_SYMBOL(omapfb_register_client);
973 int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
975 return blocking_notifier_chain_unregister(
976 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
978 EXPORT_SYMBOL(omapfb_unregister_client);
980 void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
984 if (!notifier_inited)
985 /* no client registered yet */
988 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
989 blocking_notifier_call_chain(&omapfb_client_list[i], event,
992 EXPORT_SYMBOL(omapfb_notify_clients);
994 static int omapfb_set_update_mode(struct omapfb_device *fbdev,
995 enum omapfb_update_mode mode)
999 omapfb_rqueue_lock(fbdev);
1000 r = fbdev->ctrl->set_update_mode(mode);
1001 omapfb_rqueue_unlock(fbdev);
1006 static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1010 omapfb_rqueue_lock(fbdev);
1011 r = fbdev->ctrl->get_update_mode();
1012 omapfb_rqueue_unlock(fbdev);
1017 static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1018 struct omapfb_caps *caps)
1020 memset(caps, 0, sizeof(*caps));
1021 fbdev->ctrl->get_caps(plane, caps);
1022 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1025 /* For lcd testing */
1026 void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1028 omapfb_rqueue_lock(fbdev);
1029 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1030 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1031 struct omapfb_update_window win;
1033 memset(&win, 0, sizeof(win));
1038 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0);
1040 omapfb_rqueue_unlock(fbdev);
1042 EXPORT_SYMBOL(omapfb_write_first_pixel);
1044 /* Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1045 * here to be accessible by user mode code.
1047 static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1050 struct omapfb_plane_struct *plane = fbi->par;
1051 struct omapfb_device *fbdev = plane->fbdev;
1052 struct fb_ops *ops = fbi->fbops;
1054 struct omapfb_update_window update_window;
1055 struct omapfb_plane_info plane_info;
1056 struct omapfb_mem_info mem_info;
1057 struct omapfb_color_key color_key;
1058 enum omapfb_update_mode update_mode;
1059 struct omapfb_caps caps;
1060 unsigned int mirror;
1070 if (get_user(p.mirror, (int __user *)arg))
1073 omapfb_mirror(fbi, p.mirror);
1075 case OMAPFB_SYNC_GFX:
1080 case OMAPFB_SET_UPDATE_MODE:
1081 if (get_user(p.update_mode, (int __user *)arg))
1084 r = omapfb_set_update_mode(fbdev, p.update_mode);
1086 case OMAPFB_GET_UPDATE_MODE:
1087 p.update_mode = omapfb_get_update_mode(fbdev);
1088 if (put_user(p.update_mode,
1089 (enum omapfb_update_mode __user *)arg))
1092 case OMAPFB_UPDATE_WINDOW_OLD:
1093 if (copy_from_user(&p.update_window, (void __user *)arg,
1094 sizeof(struct omapfb_update_window_old)))
1097 struct omapfb_update_window *u = &p.update_window;
1100 u->out_width = u->width;
1101 u->out_height = u->height;
1102 memset(u->reserved, 0, sizeof(u->reserved));
1103 r = omapfb_update_win(fbi, u);
1106 case OMAPFB_UPDATE_WINDOW:
1107 if (copy_from_user(&p.update_window, (void __user *)arg,
1108 sizeof(p.update_window)))
1111 r = omapfb_update_win(fbi, &p.update_window);
1113 case OMAPFB_SETUP_PLANE:
1114 if (copy_from_user(&p.plane_info, (void __user *)arg,
1115 sizeof(p.plane_info)))
1118 r = omapfb_setup_plane(fbi, &p.plane_info);
1120 case OMAPFB_QUERY_PLANE:
1121 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1123 if (copy_to_user((void __user *)arg, &p.plane_info,
1124 sizeof(p.plane_info)))
1127 case OMAPFB_SETUP_MEM:
1128 if (copy_from_user(&p.mem_info, (void __user *)arg,
1129 sizeof(p.mem_info)))
1132 r = omapfb_setup_mem(fbi, &p.mem_info);
1134 case OMAPFB_QUERY_MEM:
1135 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1137 if (copy_to_user((void __user *)arg, &p.mem_info,
1138 sizeof(p.mem_info)))
1141 case OMAPFB_SET_COLOR_KEY:
1142 if (copy_from_user(&p.color_key, (void __user *)arg,
1143 sizeof(p.color_key)))
1146 r = omapfb_set_color_key(fbdev, &p.color_key);
1148 case OMAPFB_GET_COLOR_KEY:
1149 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1151 if (copy_to_user((void __user *)arg, &p.color_key,
1152 sizeof(p.color_key)))
1155 case OMAPFB_GET_CAPS:
1156 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1157 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1160 case OMAPFB_LCD_TEST:
1164 if (get_user(test_num, (int __user *)arg)) {
1168 if (!fbdev->panel->run_test) {
1172 r = fbdev->panel->run_test(fbdev->panel, test_num);
1175 case OMAPFB_CTRL_TEST:
1179 if (get_user(test_num, (int __user *)arg)) {
1183 if (!fbdev->ctrl->run_test) {
1187 r = fbdev->ctrl->run_test(test_num);
1197 static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1199 struct omapfb_plane_struct *plane = info->par;
1200 struct omapfb_device *fbdev = plane->fbdev;
1203 omapfb_rqueue_lock(fbdev);
1204 r = fbdev->ctrl->mmap(info, vma);
1205 omapfb_rqueue_unlock(fbdev);
1210 /* Callback table for the frame buffer framework. Some of these pointers
1211 * will be changed according to the current setting of fb_info->accel_flags.
1213 static struct fb_ops omapfb_ops = {
1214 .owner = THIS_MODULE,
1215 .fb_open = omapfb_open,
1216 .fb_release = omapfb_release,
1217 .fb_setcolreg = omapfb_setcolreg,
1218 .fb_setcmap = omapfb_setcmap,
1219 .fb_fillrect = cfb_fillrect,
1220 .fb_copyarea = cfb_copyarea,
1221 .fb_imageblit = cfb_imageblit,
1222 .fb_blank = omapfb_blank,
1223 .fb_ioctl = omapfb_ioctl,
1224 .fb_check_var = omapfb_check_var,
1225 .fb_set_par = omapfb_set_par,
1226 .fb_rotate = omapfb_rotate,
1227 .fb_pan_display = omapfb_pan_display,
1231 * ---------------------------------------------------------------------------
1233 * ---------------------------------------------------------------------------
1235 /* omapfbX sysfs entries */
1236 static ssize_t omapfb_show_caps_num(struct device *dev,
1237 struct device_attribute *attr, char *buf)
1239 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1242 struct omapfb_caps caps;
1246 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1247 omapfb_get_caps(fbdev, plane, &caps);
1248 size += snprintf(&buf[size], PAGE_SIZE - size,
1249 "plane#%d %#010x %#010x %#010x\n",
1250 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1256 static ssize_t omapfb_show_caps_text(struct device *dev,
1257 struct device_attribute *attr, char *buf)
1259 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1261 struct omapfb_caps caps;
1267 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1268 omapfb_get_caps(fbdev, plane, &caps);
1269 size += snprintf(&buf[size], PAGE_SIZE - size,
1270 "plane#%d:\n", plane);
1271 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1272 size < PAGE_SIZE; i++) {
1273 if (ctrl_caps[i].flag & caps.ctrl)
1274 size += snprintf(&buf[size], PAGE_SIZE - size,
1275 " %s\n", ctrl_caps[i].name);
1277 size += snprintf(&buf[size], PAGE_SIZE - size,
1278 " plane colors:\n");
1279 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1280 size < PAGE_SIZE; i++) {
1281 if (color_caps[i].flag & caps.plane_color)
1282 size += snprintf(&buf[size], PAGE_SIZE - size,
1283 " %s\n", color_caps[i].name);
1285 size += snprintf(&buf[size], PAGE_SIZE - size,
1286 " window colors:\n");
1287 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1288 size < PAGE_SIZE; i++) {
1289 if (color_caps[i].flag & caps.wnd_color)
1290 size += snprintf(&buf[size], PAGE_SIZE - size,
1291 " %s\n", color_caps[i].name);
1299 static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1300 static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1302 /* panel sysfs entries */
1303 static ssize_t omapfb_show_panel_name(struct device *dev,
1304 struct device_attribute *attr, char *buf)
1306 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1308 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1311 static ssize_t omapfb_show_bklight_level(struct device *dev,
1312 struct device_attribute *attr,
1315 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1318 if (fbdev->panel->get_bklight_level) {
1319 r = snprintf(buf, PAGE_SIZE, "%d\n",
1320 fbdev->panel->get_bklight_level(fbdev->panel));
1326 static ssize_t omapfb_store_bklight_level(struct device *dev,
1327 struct device_attribute *attr,
1328 const char *buf, size_t size)
1330 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1333 if (fbdev->panel->set_bklight_level) {
1336 if (sscanf(buf, "%10d", &level) == 1) {
1337 r = fbdev->panel->set_bklight_level(fbdev->panel, level);
1342 return r ? r : size;
1345 static ssize_t omapfb_show_bklight_max(struct device *dev,
1346 struct device_attribute *attr, char *buf)
1348 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1351 if (fbdev->panel->get_bklight_level) {
1352 r = snprintf(buf, PAGE_SIZE, "%d\n",
1353 fbdev->panel->get_bklight_max(fbdev->panel));
1359 static struct device_attribute dev_attr_panel_name =
1360 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1361 static DEVICE_ATTR(backlight_level, 0664,
1362 omapfb_show_bklight_level, omapfb_store_bklight_level);
1363 static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1365 static struct attribute *panel_attrs[] = {
1366 &dev_attr_panel_name.attr,
1367 &dev_attr_backlight_level.attr,
1368 &dev_attr_backlight_max.attr,
1372 static struct attribute_group panel_attr_grp = {
1374 .attrs = panel_attrs,
1377 /* ctrl sysfs entries */
1378 static ssize_t omapfb_show_ctrl_name(struct device *dev,
1379 struct device_attribute *attr, char *buf)
1381 struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
1383 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1386 static struct device_attribute dev_attr_ctrl_name =
1387 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1389 static struct attribute *ctrl_attrs[] = {
1390 &dev_attr_ctrl_name.attr,
1394 static struct attribute_group ctrl_attr_grp = {
1396 .attrs = ctrl_attrs,
1399 static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1403 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1406 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1409 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1412 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1417 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1419 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1421 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1423 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1427 static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1429 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1430 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1431 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1432 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1436 * ---------------------------------------------------------------------------
1438 * ---------------------------------------------------------------------------
1440 /* Initialize system fb_info object and set the default video mode.
1441 * The frame buffer memory already allocated by lcddma_init
1443 static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1445 struct fb_var_screeninfo *var = &info->var;
1446 struct fb_fix_screeninfo *fix = &info->fix;
1449 info->fbops = &omapfb_ops;
1450 info->flags = FBINFO_FLAG_DEFAULT;
1452 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1454 info->pseudo_palette = fbdev->pseudo_palette;
1456 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1457 var->xres = def_vxres;
1458 var->yres = def_vyres;
1459 var->xres_virtual = def_vxres;
1460 var->yres_virtual = def_vyres;
1461 var->rotate = def_rotate;
1462 var->bits_per_pixel = fbdev->panel->bpp;
1464 set_fb_var(info, var);
1467 r = fb_alloc_cmap(&info->cmap, 16, 0);
1469 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1474 /* Release the fb_info object */
1475 static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1477 fb_dealloc_cmap(&fbi->cmap);
1480 static void planes_cleanup(struct omapfb_device *fbdev)
1484 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1485 if (fbdev->fb_info[i] == NULL)
1487 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1488 framebuffer_release(fbdev->fb_info[i]);
1492 static int planes_init(struct omapfb_device *fbdev)
1494 struct fb_info *fbi;
1498 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1499 struct omapfb_plane_struct *plane;
1500 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1504 "unable to allocate memory for plane info\n");
1505 planes_cleanup(fbdev);
1510 plane->fbdev = fbdev;
1511 plane->info.mirror = def_mirror;
1512 fbdev->fb_info[i] = fbi;
1514 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1515 framebuffer_release(fbi);
1516 planes_cleanup(fbdev);
1519 plane->info.out_width = fbi->var.xres;
1520 plane->info.out_height = fbi->var.yres;
1525 /* Free driver resources. Can be called to rollback an aborted initialization
1528 static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1534 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1535 unregister_framebuffer(fbdev->fb_info[i]);
1537 omapfb_unregister_sysfs(fbdev);
1539 fbdev->panel->disable(fbdev->panel);
1541 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1543 planes_cleanup(fbdev);
1545 ctrl_cleanup(fbdev);
1547 fbdev->panel->cleanup(fbdev->panel);
1549 dev_set_drvdata(fbdev->dev, NULL);
1552 /* nothing to free */
1559 static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1561 struct omapfb_platform_data *conf;
1565 conf = fbdev->dev->platform_data;
1569 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1570 name[sizeof(name) - 1] = '\0';
1572 if (strcmp(name, "internal") == 0) {
1573 fbdev->ctrl = fbdev->int_ctrl;
1577 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1578 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1579 if (strcmp(ctrls[i]->name, name) == 0) {
1580 fbdev->ctrl = ctrls[i];
1585 if (fbdev->ctrl == NULL) {
1586 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1593 static void check_required_callbacks(struct omapfb_device *fbdev)
1595 #define _C(x) (fbdev->ctrl->x != NULL)
1596 #define _P(x) (fbdev->panel->x != NULL)
1597 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1598 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1599 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1600 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1606 /* Called by LDM binding to probe and attach a new device.
1607 * Initialization sequence:
1608 * 1. allocate system omapfb_device structure
1609 * 2. select controller type according to platform configuration
1611 * 3. init LCD controller and LCD DMA
1612 * 4. init system fb_info structure for all planes
1613 * 5. setup video mode for first plane and enable it
1614 * 6. enable LCD panel
1615 * 7. register sysfs attributes
1616 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1618 static int omapfb_do_probe(struct platform_device *pdev, struct lcd_panel *panel)
1620 struct omapfb_device *fbdev = NULL;
1622 unsigned long phz, hhz, vhz;
1629 if (pdev->num_resources != 0) {
1630 dev_err(&pdev->dev, "probed for an unknown device\n");
1635 if (pdev->dev.platform_data == NULL) {
1636 dev_err(&pdev->dev, "missing platform data\n");
1641 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1642 if (fbdev == NULL) {
1644 "unable to allocate memory for device info\n");
1650 fbdev->dev = &pdev->dev;
1651 fbdev->panel = panel;
1652 platform_set_drvdata(pdev, fbdev);
1654 mutex_init(&fbdev->rqueue_mutex);
1656 #ifdef CONFIG_ARCH_OMAP1
1657 fbdev->int_ctrl = &omap1_int_ctrl;
1658 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1659 fbdev->ext_if = &omap1_ext_if;
1662 fbdev->int_ctrl = &omap2_int_ctrl;
1663 #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1664 fbdev->ext_if = &omap2_ext_if;
1667 if (omapfb_find_ctrl(fbdev) < 0) {
1669 "LCD controller not found, board not supported\n");
1674 r = fbdev->panel->init(fbdev->panel, fbdev);
1678 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1680 def_vxres = def_vxres ? : fbdev->panel->x_res;
1681 def_vyres = def_vyres ? : fbdev->panel->y_res;
1685 r = ctrl_init(fbdev);
1688 if (fbdev->ctrl->mmap != NULL)
1689 omapfb_ops.fb_mmap = omapfb_mmap;
1692 check_required_callbacks(fbdev);
1694 r = planes_init(fbdev);
1699 #ifdef CONFIG_FB_OMAP_DMA_TUNE
1700 /* Set DMA priority for EMIFF access to highest */
1701 if (cpu_class_is_omap1())
1702 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1705 r = ctrl_change_mode(fbdev->fb_info[0]);
1707 dev_err(fbdev->dev, "mode setting failed\n");
1711 /* GFX plane is enabled by default */
1712 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1716 omapfb_set_update_mode(fbdev, manual_update ?
1717 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1720 r = fbdev->panel->enable(fbdev->panel);
1725 r = omapfb_register_sysfs(fbdev);
1731 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1732 r = register_framebuffer(fbdev->fb_info[i]);
1735 "registering framebuffer %d failed\n", i);
1738 vram += fbdev->mem_desc.region[i].size;
1741 fbdev->state = OMAPFB_ACTIVE;
1743 panel = fbdev->panel;
1744 phz = panel->pixel_clock * 1000;
1745 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1746 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1750 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1751 vram, fbdev->mem_desc.region_cnt);
1752 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1753 "vfreq %lu.%lu Hz\n",
1754 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1759 omapfb_free_resources(fbdev, init_state);
1764 static int omapfb_probe(struct platform_device *pdev)
1766 BUG_ON(fbdev_pdev != NULL);
1768 /* Delay actual initialization until the LCD is registered */
1770 if (fbdev_panel != NULL)
1771 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1775 void omapfb_register_panel(struct lcd_panel *panel)
1777 BUG_ON(fbdev_panel != NULL);
1779 fbdev_panel = panel;
1780 if (fbdev_pdev != NULL)
1781 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1784 /* Called when the device is being detached from the driver */
1785 static int omapfb_remove(struct platform_device *pdev)
1787 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1788 enum omapfb_state saved_state = fbdev->state;
1790 /* FIXME: wait till completion of pending events */
1792 fbdev->state = OMAPFB_DISABLED;
1793 omapfb_free_resources(fbdev, saved_state);
1799 static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1801 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1803 omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
1809 static int omapfb_resume(struct platform_device *pdev)
1811 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1813 omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
1817 static struct platform_driver omapfb_driver = {
1818 .probe = omapfb_probe,
1819 .remove = omapfb_remove,
1820 .suspend = omapfb_suspend,
1821 .resume = omapfb_resume,
1823 .name = MODULE_NAME,
1824 .owner = THIS_MODULE,
1830 /* Process kernel command line parameters */
1831 static int __init omapfb_setup(char *options)
1833 char *this_opt = NULL;
1836 pr_debug("omapfb: options %s\n", options);
1838 if (!options || !*options)
1841 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1842 if (!strncmp(this_opt, "accel", 5))
1844 else if (!strncmp(this_opt, "vram:", 5)) {
1847 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1848 switch (suffix[0]) {
1860 pr_debug("omapfb: invalid vram suffix %c\n",
1864 def_vram[def_vram_cnt++] = vram;
1866 else if (!strncmp(this_opt, "vxres:", 6))
1867 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1868 else if (!strncmp(this_opt, "vyres:", 6))
1869 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1870 else if (!strncmp(this_opt, "rotate:", 7))
1871 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1872 else if (!strncmp(this_opt, "mirror:", 7))
1873 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1874 else if (!strncmp(this_opt, "manual_update", 13))
1877 pr_debug("omapfb: invalid option\n");
1887 /* Register both the driver and the device */
1888 static int __init omapfb_init(void)
1893 if (fb_get_options("omapfb", &option))
1895 omapfb_setup(option);
1897 /* Register the driver with LDM */
1898 if (platform_driver_register(&omapfb_driver)) {
1899 pr_debug("failed to register omapfb driver\n");
1906 static void __exit omapfb_cleanup(void)
1908 platform_driver_unregister(&omapfb_driver);
1911 module_param_named(accel, def_accel, uint, 0664);
1912 module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1913 module_param_named(vxres, def_vxres, long, 0664);
1914 module_param_named(vyres, def_vyres, long, 0664);
1915 module_param_named(rotate, def_rotate, uint, 0664);
1916 module_param_named(mirror, def_mirror, uint, 0664);
1917 module_param_named(manual_update, manual_update, bool, 0664);
1919 module_init(omapfb_init);
1920 module_exit(omapfb_cleanup);
1922 MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1923 MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1924 MODULE_LICENSE("GPL");