blob: aaf0990162cc4a23ab33b1dd2ae6d00fa80f5dd0 [file] [log] [blame]
Imre Deak8b08cf22007-07-17 04:05:54 -07001/*
2 * Framebuffer driver for TI OMAP boards
3 *
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Imre Deak <imre.deak@nokia.com>
6 *
7 * Acknowledgements:
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
12 *
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.
17 *
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.
22 *
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.
26 */
27#include <linux/platform_device.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070028#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Imre Deak8b08cf22007-07-17 04:05:54 -070030#include <linux/uaccess.h>
Paul Gortmaker355b2002011-07-03 16:17:28 -040031#include <linux/module.h>
Imre Deak8b08cf22007-07-17 04:05:54 -070032
Tony Lindgrence491cf2009-10-20 09:40:47 -070033#include <plat/dma.h>
Imre Deak8b08cf22007-07-17 04:05:54 -070034
Tomi Valkeinen91773a02009-08-03 15:06:36 +030035#include "omapfb.h"
Russell King7c8ad982008-09-05 15:13:24 +010036#include "lcdc.h"
Russell King7c8ad982008-09-05 15:13:24 +010037
Imre Deak8b08cf22007-07-17 04:05:54 -070038#define MODULE_NAME "omapfb"
39
40static unsigned int def_accel;
41static unsigned long def_vram[OMAPFB_PLANE_NUM];
Russell King7c8ad982008-09-05 15:13:24 +010042static unsigned int def_vram_cnt;
Imre Deak8b08cf22007-07-17 04:05:54 -070043static unsigned long def_vxres;
44static unsigned long def_vyres;
45static unsigned int def_rotate;
46static unsigned int def_mirror;
47
48#ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
Rusty Russell90ab5ee2012-01-13 09:32:20 +103049static bool manual_update = 1;
Imre Deak8b08cf22007-07-17 04:05:54 -070050#else
Rusty Russell90ab5ee2012-01-13 09:32:20 +103051static bool manual_update;
Imre Deak8b08cf22007-07-17 04:05:54 -070052#endif
53
54static struct platform_device *fbdev_pdev;
55static struct lcd_panel *fbdev_panel;
56static struct omapfb_device *omapfb_dev;
57
58struct caps_table_struct {
59 unsigned long flag;
60 const char *name;
61};
62
63static struct caps_table_struct ctrl_caps[] = {
64 { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
65 { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
66 { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
67 { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
68 { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
69 { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
70 { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" },
Rodrigo Vivi2f21a622009-09-22 16:46:53 -070071 { OMAPFB_CAPS_WINDOW_ROTATE, "rotate window" },
Imre Deak8b08cf22007-07-17 04:05:54 -070072 { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" },
73};
74
75static struct caps_table_struct color_caps[] = {
76 { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
77 { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
78 { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
79 { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
80 { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
81 { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
82 { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
83 { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
84 { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
85};
86
Tomi Valkeinenb64a5a12010-01-07 11:56:14 +020087static void omapdss_release(struct device *dev)
88{
89}
90
Tomi Valkeinenf778a122009-12-16 13:18:07 +020091/* dummy device for clocks */
92static struct platform_device omapdss_device = {
Tomi Valkeinenc96c92d2011-04-21 19:11:16 +030093 .name = "omapdss_dss",
Tomi Valkeinenf778a122009-12-16 13:18:07 +020094 .id = -1,
Tomi Valkeinenb64a5a12010-01-07 11:56:14 +020095 .dev = {
96 .release = omapdss_release,
97 },
Tomi Valkeinenf778a122009-12-16 13:18:07 +020098};
99
Imre Deak8b08cf22007-07-17 04:05:54 -0700100/*
101 * ---------------------------------------------------------------------------
102 * LCD panel
103 * ---------------------------------------------------------------------------
104 */
Imre Deak8b08cf22007-07-17 04:05:54 -0700105extern struct lcd_ctrl hwa742_ctrl;
Imre Deak8b08cf22007-07-17 04:05:54 -0700106
Russell King7c8ad982008-09-05 15:13:24 +0100107static const struct lcd_ctrl *ctrls[] = {
Imre Deak8b08cf22007-07-17 04:05:54 -0700108 &omap1_int_ctrl,
Imre Deak8b08cf22007-07-17 04:05:54 -0700109
110#ifdef CONFIG_FB_OMAP_LCDC_HWA742
111 &hwa742_ctrl,
112#endif
Imre Deak8b08cf22007-07-17 04:05:54 -0700113};
114
115#ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
Imre Deak8b08cf22007-07-17 04:05:54 -0700116extern struct lcd_ctrl_extif omap1_ext_if;
Imre Deak8b08cf22007-07-17 04:05:54 -0700117#endif
118
119static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
120{
121 mutex_lock(&fbdev->rqueue_mutex);
122}
123
124static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
125{
126 mutex_unlock(&fbdev->rqueue_mutex);
127}
128
129/*
130 * ---------------------------------------------------------------------------
131 * LCD controller and LCD DMA
132 * ---------------------------------------------------------------------------
133 */
134/* Lookup table to map elem size to elem type. */
135static const int dma_elem_type[] = {
136 0,
137 OMAP_DMA_DATA_TYPE_S8,
138 OMAP_DMA_DATA_TYPE_S16,
139 0,
140 OMAP_DMA_DATA_TYPE_S32,
141};
142
143/*
144 * Allocate resources needed for LCD controller and LCD DMA operations. Video
145 * memory is allocated from system memory according to the virtual display
146 * size, except if a bigger memory size is specified explicitly as a kernel
147 * parameter.
148 */
149static int ctrl_init(struct omapfb_device *fbdev)
150{
151 int r;
152 int i;
153
154 /* kernel/module vram parameters override boot tags/board config */
155 if (def_vram_cnt) {
156 for (i = 0; i < def_vram_cnt; i++)
157 fbdev->mem_desc.region[i].size =
158 PAGE_ALIGN(def_vram[i]);
159 fbdev->mem_desc.region_cnt = i;
160 } else {
161 struct omapfb_platform_data *conf;
162
163 conf = fbdev->dev->platform_data;
164 fbdev->mem_desc = conf->mem_desc;
165 }
166
167 if (!fbdev->mem_desc.region_cnt) {
168 struct lcd_panel *panel = fbdev->panel;
169 int def_size;
170 int bpp = panel->bpp;
171
172 /* 12 bpp is packed in 16 bits */
173 if (bpp == 12)
174 bpp = 16;
175 def_size = def_vxres * def_vyres * bpp / 8;
176 fbdev->mem_desc.region_cnt = 1;
177 fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
178 }
179 r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
180 if (r < 0) {
181 dev_err(fbdev->dev, "controller initialization failed (%d)\n",
182 r);
183 return r;
184 }
185
186#ifdef DEBUG
187 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
188 dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
189 i,
190 fbdev->mem_desc.region[i].paddr,
191 fbdev->mem_desc.region[i].vaddr,
192 fbdev->mem_desc.region[i].size);
193 }
194#endif
195 return 0;
196}
197
198static void ctrl_cleanup(struct omapfb_device *fbdev)
199{
200 fbdev->ctrl->cleanup();
201}
202
203/* Must be called with fbdev->rqueue_mutex held. */
204static int ctrl_change_mode(struct fb_info *fbi)
205{
206 int r;
207 unsigned long offset;
208 struct omapfb_plane_struct *plane = fbi->par;
209 struct omapfb_device *fbdev = plane->fbdev;
210 struct fb_var_screeninfo *var = &fbi->var;
211
212 offset = var->yoffset * fbi->fix.line_length +
213 var->xoffset * var->bits_per_pixel / 8;
214
215 if (fbdev->ctrl->sync)
216 fbdev->ctrl->sync();
217 r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
218 offset, var->xres_virtual,
219 plane->info.pos_x, plane->info.pos_y,
220 var->xres, var->yres, plane->color_mode);
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700221 if (r < 0)
222 return r;
223
224 if (fbdev->ctrl->set_rotate != NULL) {
225 r = fbdev->ctrl->set_rotate(var->rotate);
226 if (r < 0)
227 return r;
228 }
229
Imre Deak8b08cf22007-07-17 04:05:54 -0700230 if (fbdev->ctrl->set_scale != NULL)
231 r = fbdev->ctrl->set_scale(plane->idx,
232 var->xres, var->yres,
233 plane->info.out_width,
234 plane->info.out_height);
235
236 return r;
237}
238
239/*
240 * ---------------------------------------------------------------------------
241 * fbdev framework callbacks and the ioctl interface
242 * ---------------------------------------------------------------------------
243 */
244/* Called each time the omapfb device is opened */
245static int omapfb_open(struct fb_info *info, int user)
246{
247 return 0;
248}
249
250static void omapfb_sync(struct fb_info *info);
251
252/* Called when the omapfb device is closed. We make sure that any pending
253 * gfx DMA operations are ended, before we return. */
254static int omapfb_release(struct fb_info *info, int user)
255{
256 omapfb_sync(info);
257 return 0;
258}
259
260/* Store a single color palette entry into a pseudo palette or the hardware
261 * palette if one is available. For now we support only 16bpp and thus store
262 * the entry only to the pseudo palette.
263 */
264static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
265 u_int blue, u_int transp, int update_hw_pal)
266{
267 struct omapfb_plane_struct *plane = info->par;
268 struct omapfb_device *fbdev = plane->fbdev;
269 struct fb_var_screeninfo *var = &info->var;
270 int r = 0;
271
272 switch (plane->color_mode) {
273 case OMAPFB_COLOR_YUV422:
274 case OMAPFB_COLOR_YUV420:
275 case OMAPFB_COLOR_YUY422:
276 r = -EINVAL;
277 break;
278 case OMAPFB_COLOR_CLUT_8BPP:
279 case OMAPFB_COLOR_CLUT_4BPP:
280 case OMAPFB_COLOR_CLUT_2BPP:
281 case OMAPFB_COLOR_CLUT_1BPP:
282 if (fbdev->ctrl->setcolreg)
283 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
284 transp, update_hw_pal);
285 /* Fallthrough */
286 case OMAPFB_COLOR_RGB565:
287 case OMAPFB_COLOR_RGB444:
288 if (r != 0)
289 break;
290
291 if (regno < 0) {
292 r = -EINVAL;
293 break;
294 }
295
296 if (regno < 16) {
297 u16 pal;
298 pal = ((red >> (16 - var->red.length)) <<
299 var->red.offset) |
300 ((green >> (16 - var->green.length)) <<
301 var->green.offset) |
302 (blue >> (16 - var->blue.length));
303 ((u32 *)(info->pseudo_palette))[regno] = pal;
304 }
305 break;
306 default:
307 BUG();
308 }
309 return r;
310}
311
312static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
313 u_int transp, struct fb_info *info)
314{
315 return _setcolreg(info, regno, red, green, blue, transp, 1);
316}
317
318static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
319{
320 int count, index, r;
321 u16 *red, *green, *blue, *transp;
322 u16 trans = 0xffff;
323
324 red = cmap->red;
325 green = cmap->green;
326 blue = cmap->blue;
327 transp = cmap->transp;
328 index = cmap->start;
329
330 for (count = 0; count < cmap->len; count++) {
331 if (transp)
332 trans = *transp++;
333 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
334 count == cmap->len - 1);
335 if (r != 0)
336 return r;
337 }
338
339 return 0;
340}
341
342static int omapfb_update_full_screen(struct fb_info *fbi);
343
344static int omapfb_blank(int blank, struct fb_info *fbi)
345{
346 struct omapfb_plane_struct *plane = fbi->par;
347 struct omapfb_device *fbdev = plane->fbdev;
348 int do_update = 0;
349 int r = 0;
350
351 omapfb_rqueue_lock(fbdev);
352 switch (blank) {
Felipe Contrerasc9585572009-03-31 15:25:42 -0700353 case FB_BLANK_UNBLANK:
Imre Deak8b08cf22007-07-17 04:05:54 -0700354 if (fbdev->state == OMAPFB_SUSPENDED) {
355 if (fbdev->ctrl->resume)
356 fbdev->ctrl->resume();
357 fbdev->panel->enable(fbdev->panel);
358 fbdev->state = OMAPFB_ACTIVE;
359 if (fbdev->ctrl->get_update_mode() ==
360 OMAPFB_MANUAL_UPDATE)
361 do_update = 1;
362 }
363 break;
Felipe Contrerasc9585572009-03-31 15:25:42 -0700364 case FB_BLANK_POWERDOWN:
Imre Deak8b08cf22007-07-17 04:05:54 -0700365 if (fbdev->state == OMAPFB_ACTIVE) {
366 fbdev->panel->disable(fbdev->panel);
367 if (fbdev->ctrl->suspend)
368 fbdev->ctrl->suspend();
369 fbdev->state = OMAPFB_SUSPENDED;
370 }
371 break;
372 default:
373 r = -EINVAL;
374 }
375 omapfb_rqueue_unlock(fbdev);
376
377 if (r == 0 && do_update)
378 r = omapfb_update_full_screen(fbi);
379
380 return r;
381}
382
383static void omapfb_sync(struct fb_info *fbi)
384{
385 struct omapfb_plane_struct *plane = fbi->par;
386 struct omapfb_device *fbdev = plane->fbdev;
387
388 omapfb_rqueue_lock(fbdev);
389 if (fbdev->ctrl->sync)
390 fbdev->ctrl->sync();
391 omapfb_rqueue_unlock(fbdev);
392}
393
394/*
395 * Set fb_info.fix fields and also updates fbdev.
396 * When calling this fb_info.var must be set up already.
397 */
Sergio Aguirre03bb2b42009-10-05 13:31:46 -0700398static void set_fb_fix(struct fb_info *fbi, int from_init)
Imre Deak8b08cf22007-07-17 04:05:54 -0700399{
400 struct fb_fix_screeninfo *fix = &fbi->fix;
401 struct fb_var_screeninfo *var = &fbi->var;
402 struct omapfb_plane_struct *plane = fbi->par;
403 struct omapfb_mem_region *rg;
404 int bpp;
405
406 rg = &plane->fbdev->mem_desc.region[plane->idx];
Russell King020f9702008-12-01 17:40:54 +0000407 fbi->screen_base = rg->vaddr;
Sergio Aguirre03bb2b42009-10-05 13:31:46 -0700408
409 if (!from_init) {
410 mutex_lock(&fbi->mm_lock);
411 fix->smem_start = rg->paddr;
412 fix->smem_len = rg->size;
413 mutex_unlock(&fbi->mm_lock);
414 } else {
415 fix->smem_start = rg->paddr;
416 fix->smem_len = rg->size;
417 }
Imre Deak8b08cf22007-07-17 04:05:54 -0700418
419 fix->type = FB_TYPE_PACKED_PIXELS;
420 bpp = var->bits_per_pixel;
421 if (var->nonstd)
422 fix->visual = FB_VISUAL_PSEUDOCOLOR;
423 else switch (var->bits_per_pixel) {
424 case 16:
425 case 12:
426 fix->visual = FB_VISUAL_TRUECOLOR;
427 /* 12bpp is stored in 16 bits */
428 bpp = 16;
429 break;
430 case 1:
431 case 2:
432 case 4:
433 case 8:
434 fix->visual = FB_VISUAL_PSEUDOCOLOR;
435 break;
436 }
437 fix->accel = FB_ACCEL_OMAP1610;
438 fix->line_length = var->xres_virtual * bpp / 8;
439}
440
441static int set_color_mode(struct omapfb_plane_struct *plane,
442 struct fb_var_screeninfo *var)
443{
444 switch (var->nonstd) {
445 case 0:
446 break;
447 case OMAPFB_COLOR_YUV422:
448 var->bits_per_pixel = 16;
449 plane->color_mode = var->nonstd;
450 return 0;
451 case OMAPFB_COLOR_YUV420:
452 var->bits_per_pixel = 12;
453 plane->color_mode = var->nonstd;
454 return 0;
455 case OMAPFB_COLOR_YUY422:
456 var->bits_per_pixel = 16;
457 plane->color_mode = var->nonstd;
458 return 0;
459 default:
460 return -EINVAL;
461 }
462
463 switch (var->bits_per_pixel) {
464 case 1:
465 plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
466 return 0;
467 case 2:
468 plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
469 return 0;
470 case 4:
471 plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
472 return 0;
473 case 8:
474 plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
475 return 0;
476 case 12:
477 var->bits_per_pixel = 16;
Imre Deak8b08cf22007-07-17 04:05:54 -0700478 case 16:
Janusz Krzysztofik3e9ff042010-01-14 21:25:43 +0100479 if (plane->fbdev->panel->bpp == 12)
480 plane->color_mode = OMAPFB_COLOR_RGB444;
481 else
482 plane->color_mode = OMAPFB_COLOR_RGB565;
Imre Deak8b08cf22007-07-17 04:05:54 -0700483 return 0;
484 default:
485 return -EINVAL;
486 }
487}
488
489/*
490 * Check the values in var against our capabilities and in case of out of
491 * bound values try to adjust them.
492 */
493static int set_fb_var(struct fb_info *fbi,
494 struct fb_var_screeninfo *var)
495{
496 int bpp;
497 unsigned long max_frame_size;
498 unsigned long line_size;
499 int xres_min, xres_max;
500 int yres_min, yres_max;
501 struct omapfb_plane_struct *plane = fbi->par;
502 struct omapfb_device *fbdev = plane->fbdev;
503 struct lcd_panel *panel = fbdev->panel;
504
505 if (set_color_mode(plane, var) < 0)
506 return -EINVAL;
507
508 bpp = var->bits_per_pixel;
509 if (plane->color_mode == OMAPFB_COLOR_RGB444)
510 bpp = 16;
511
512 switch (var->rotate) {
513 case 0:
514 case 180:
515 xres_min = OMAPFB_PLANE_XRES_MIN;
516 xres_max = panel->x_res;
517 yres_min = OMAPFB_PLANE_YRES_MIN;
518 yres_max = panel->y_res;
519 if (cpu_is_omap15xx()) {
520 var->xres = panel->x_res;
521 var->yres = panel->y_res;
522 }
523 break;
524 case 90:
525 case 270:
526 xres_min = OMAPFB_PLANE_YRES_MIN;
527 xres_max = panel->y_res;
528 yres_min = OMAPFB_PLANE_XRES_MIN;
529 yres_max = panel->x_res;
530 if (cpu_is_omap15xx()) {
531 var->xres = panel->y_res;
532 var->yres = panel->x_res;
533 }
534 break;
535 default:
536 return -EINVAL;
537 }
538
539 if (var->xres < xres_min)
540 var->xres = xres_min;
541 if (var->yres < yres_min)
542 var->yres = yres_min;
543 if (var->xres > xres_max)
544 var->xres = xres_max;
545 if (var->yres > yres_max)
546 var->yres = yres_max;
547
548 if (var->xres_virtual < var->xres)
549 var->xres_virtual = var->xres;
550 if (var->yres_virtual < var->yres)
551 var->yres_virtual = var->yres;
552 max_frame_size = fbdev->mem_desc.region[plane->idx].size;
553 line_size = var->xres_virtual * bpp / 8;
554 if (line_size * var->yres_virtual > max_frame_size) {
555 /* Try to keep yres_virtual first */
556 line_size = max_frame_size / var->yres_virtual;
557 var->xres_virtual = line_size * 8 / bpp;
558 if (var->xres_virtual < var->xres) {
559 /* Still doesn't fit. Shrink yres_virtual too */
560 var->xres_virtual = var->xres;
561 line_size = var->xres * bpp / 8;
562 var->yres_virtual = max_frame_size / line_size;
563 }
564 /* Recheck this, as the virtual size changed. */
565 if (var->xres_virtual < var->xres)
566 var->xres = var->xres_virtual;
567 if (var->yres_virtual < var->yres)
568 var->yres = var->yres_virtual;
569 if (var->xres < xres_min || var->yres < yres_min)
570 return -EINVAL;
571 }
572 if (var->xres + var->xoffset > var->xres_virtual)
573 var->xoffset = var->xres_virtual - var->xres;
574 if (var->yres + var->yoffset > var->yres_virtual)
575 var->yoffset = var->yres_virtual - var->yres;
Imre Deak8b08cf22007-07-17 04:05:54 -0700576
577 if (plane->color_mode == OMAPFB_COLOR_RGB444) {
578 var->red.offset = 8; var->red.length = 4;
579 var->red.msb_right = 0;
580 var->green.offset = 4; var->green.length = 4;
581 var->green.msb_right = 0;
582 var->blue.offset = 0; var->blue.length = 4;
583 var->blue.msb_right = 0;
584 } else {
585 var->red.offset = 11; var->red.length = 5;
586 var->red.msb_right = 0;
587 var->green.offset = 5; var->green.length = 6;
588 var->green.msb_right = 0;
589 var->blue.offset = 0; var->blue.length = 5;
590 var->blue.msb_right = 0;
591 }
592
593 var->height = -1;
594 var->width = -1;
595 var->grayscale = 0;
596
597 /* pixclock in ps, the rest in pixclock */
598 var->pixclock = 10000000 / (panel->pixel_clock / 100);
599 var->left_margin = panel->hfp;
600 var->right_margin = panel->hbp;
601 var->upper_margin = panel->vfp;
602 var->lower_margin = panel->vbp;
603 var->hsync_len = panel->hsw;
604 var->vsync_len = panel->vsw;
605
606 /* TODO: get these from panel->config */
607 var->vmode = FB_VMODE_NONINTERLACED;
608 var->sync = 0;
609
610 return 0;
611}
612
613
614/* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
615static void omapfb_rotate(struct fb_info *fbi, int rotate)
616{
617 struct omapfb_plane_struct *plane = fbi->par;
618 struct omapfb_device *fbdev = plane->fbdev;
619
620 omapfb_rqueue_lock(fbdev);
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700621 if (rotate != fbi->var.rotate) {
Imre Deak8b08cf22007-07-17 04:05:54 -0700622 struct fb_var_screeninfo *new_var = &fbdev->new_var;
623
624 memcpy(new_var, &fbi->var, sizeof(*new_var));
625 new_var->rotate = rotate;
626 if (set_fb_var(fbi, new_var) == 0 &&
627 memcmp(new_var, &fbi->var, sizeof(*new_var))) {
628 memcpy(&fbi->var, new_var, sizeof(*new_var));
629 ctrl_change_mode(fbi);
630 }
631 }
632 omapfb_rqueue_unlock(fbdev);
633}
634
635/*
636 * Set new x,y offsets in the virtual display for the visible area and switch
637 * to the new mode.
638 */
639static int omapfb_pan_display(struct fb_var_screeninfo *var,
640 struct fb_info *fbi)
641{
642 struct omapfb_plane_struct *plane = fbi->par;
643 struct omapfb_device *fbdev = plane->fbdev;
644 int r = 0;
645
646 omapfb_rqueue_lock(fbdev);
647 if (var->xoffset != fbi->var.xoffset ||
648 var->yoffset != fbi->var.yoffset) {
649 struct fb_var_screeninfo *new_var = &fbdev->new_var;
650
651 memcpy(new_var, &fbi->var, sizeof(*new_var));
652 new_var->xoffset = var->xoffset;
653 new_var->yoffset = var->yoffset;
654 if (set_fb_var(fbi, new_var))
655 r = -EINVAL;
656 else {
657 memcpy(&fbi->var, new_var, sizeof(*new_var));
658 ctrl_change_mode(fbi);
659 }
660 }
661 omapfb_rqueue_unlock(fbdev);
662
663 return r;
664}
665
666/* Set mirror to vertical axis and switch to the new mode. */
667static int omapfb_mirror(struct fb_info *fbi, int mirror)
668{
669 struct omapfb_plane_struct *plane = fbi->par;
670 struct omapfb_device *fbdev = plane->fbdev;
671 int r = 0;
672
673 omapfb_rqueue_lock(fbdev);
674 mirror = mirror ? 1 : 0;
675 if (cpu_is_omap15xx())
676 r = -EINVAL;
677 else if (mirror != plane->info.mirror) {
678 plane->info.mirror = mirror;
679 r = ctrl_change_mode(fbi);
680 }
681 omapfb_rqueue_unlock(fbdev);
682
683 return r;
684}
685
686/*
687 * Check values in var, try to adjust them in case of out of bound values if
688 * possible, or return error.
689 */
690static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
691{
692 struct omapfb_plane_struct *plane = fbi->par;
693 struct omapfb_device *fbdev = plane->fbdev;
694 int r;
695
696 omapfb_rqueue_lock(fbdev);
697 if (fbdev->ctrl->sync != NULL)
698 fbdev->ctrl->sync();
699 r = set_fb_var(fbi, var);
700 omapfb_rqueue_unlock(fbdev);
701
702 return r;
703}
704
705/*
706 * Switch to a new mode. The parameters for it has been check already by
707 * omapfb_check_var.
708 */
709static int omapfb_set_par(struct fb_info *fbi)
710{
711 struct omapfb_plane_struct *plane = fbi->par;
712 struct omapfb_device *fbdev = plane->fbdev;
713 int r = 0;
714
715 omapfb_rqueue_lock(fbdev);
Sergio Aguirre03bb2b42009-10-05 13:31:46 -0700716 set_fb_fix(fbi, 0);
Imre Deak8b08cf22007-07-17 04:05:54 -0700717 r = ctrl_change_mode(fbi);
718 omapfb_rqueue_unlock(fbdev);
719
720 return r;
721}
722
723int omapfb_update_window_async(struct fb_info *fbi,
724 struct omapfb_update_window *win,
725 void (*callback)(void *),
726 void *callback_data)
727{
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700728 int xres, yres;
Imre Deak8b08cf22007-07-17 04:05:54 -0700729 struct omapfb_plane_struct *plane = fbi->par;
730 struct omapfb_device *fbdev = plane->fbdev;
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700731 struct fb_var_screeninfo *var = &fbi->var;
Imre Deak8b08cf22007-07-17 04:05:54 -0700732
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700733 switch (var->rotate) {
734 case 0:
735 case 180:
736 xres = fbdev->panel->x_res;
737 yres = fbdev->panel->y_res;
738 break;
739 case 90:
740 case 270:
741 xres = fbdev->panel->y_res;
742 yres = fbdev->panel->x_res;
743 break;
744 default:
745 return -EINVAL;
746 }
747
748 if (win->x >= xres || win->y >= yres ||
749 win->out_x > xres || win->out_y > yres)
Imre Deak8b08cf22007-07-17 04:05:54 -0700750 return -EINVAL;
751
752 if (!fbdev->ctrl->update_window ||
753 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
754 return -ENODEV;
755
Rodrigo Vivi2f21a622009-09-22 16:46:53 -0700756 if (win->x + win->width > xres)
757 win->width = xres - win->x;
758 if (win->y + win->height > yres)
759 win->height = yres - win->y;
760 if (win->out_x + win->out_width > xres)
761 win->out_width = xres - win->out_x;
762 if (win->out_y + win->out_height > yres)
763 win->out_height = yres - win->out_y;
Imre Deak8b08cf22007-07-17 04:05:54 -0700764 if (!win->width || !win->height || !win->out_width || !win->out_height)
765 return 0;
766
767 return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
768}
769EXPORT_SYMBOL(omapfb_update_window_async);
770
771static int omapfb_update_win(struct fb_info *fbi,
772 struct omapfb_update_window *win)
773{
774 struct omapfb_plane_struct *plane = fbi->par;
775 int ret;
776
777 omapfb_rqueue_lock(plane->fbdev);
Russell Kingc0fc18c52008-09-05 15:10:27 +0100778 ret = omapfb_update_window_async(fbi, win, NULL, NULL);
Imre Deak8b08cf22007-07-17 04:05:54 -0700779 omapfb_rqueue_unlock(plane->fbdev);
780
781 return ret;
782}
783
784static int omapfb_update_full_screen(struct fb_info *fbi)
785{
786 struct omapfb_plane_struct *plane = fbi->par;
787 struct omapfb_device *fbdev = plane->fbdev;
788 struct omapfb_update_window win;
789 int r;
790
791 if (!fbdev->ctrl->update_window ||
792 fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
793 return -ENODEV;
794
795 win.x = 0;
796 win.y = 0;
797 win.width = fbi->var.xres;
798 win.height = fbi->var.yres;
799 win.out_x = 0;
800 win.out_y = 0;
801 win.out_width = fbi->var.xres;
802 win.out_height = fbi->var.yres;
803 win.format = 0;
804
805 omapfb_rqueue_lock(fbdev);
Russell Kingc0fc18c52008-09-05 15:10:27 +0100806 r = fbdev->ctrl->update_window(fbi, &win, NULL, NULL);
Imre Deak8b08cf22007-07-17 04:05:54 -0700807 omapfb_rqueue_unlock(fbdev);
808
809 return r;
810}
811
812static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
813{
814 struct omapfb_plane_struct *plane = fbi->par;
815 struct omapfb_device *fbdev = plane->fbdev;
816 struct lcd_panel *panel = fbdev->panel;
817 struct omapfb_plane_info old_info;
818 int r = 0;
819
820 if (pi->pos_x + pi->out_width > panel->x_res ||
821 pi->pos_y + pi->out_height > panel->y_res)
822 return -EINVAL;
823
824 omapfb_rqueue_lock(fbdev);
825 if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
826 /*
827 * This plane's memory was freed, can't enable it
828 * until it's reallocated.
829 */
830 r = -EINVAL;
831 goto out;
832 }
833 old_info = plane->info;
834 plane->info = *pi;
835 if (pi->enabled) {
836 r = ctrl_change_mode(fbi);
837 if (r < 0) {
838 plane->info = old_info;
839 goto out;
840 }
841 }
842 r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
843 if (r < 0) {
844 plane->info = old_info;
845 goto out;
846 }
847out:
848 omapfb_rqueue_unlock(fbdev);
849 return r;
850}
851
852static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
853{
854 struct omapfb_plane_struct *plane = fbi->par;
855
856 *pi = plane->info;
857 return 0;
858}
859
860static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
861{
862 struct omapfb_plane_struct *plane = fbi->par;
863 struct omapfb_device *fbdev = plane->fbdev;
864 struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
865 size_t size;
866 int r = 0;
867
868 if (fbdev->ctrl->setup_mem == NULL)
869 return -ENODEV;
Tomi Valkeinen1896e2f2011-09-20 10:07:24 +0300870 if (mi->type != OMAPFB_MEMTYPE_SDRAM)
Imre Deak8b08cf22007-07-17 04:05:54 -0700871 return -EINVAL;
872
873 size = PAGE_ALIGN(mi->size);
874 omapfb_rqueue_lock(fbdev);
875 if (plane->info.enabled) {
876 r = -EBUSY;
877 goto out;
878 }
879 if (rg->size != size || rg->type != mi->type) {
880 struct fb_var_screeninfo *new_var = &fbdev->new_var;
881 unsigned long old_size = rg->size;
882 u8 old_type = rg->type;
883 unsigned long paddr;
884
885 rg->size = size;
886 rg->type = mi->type;
887 /*
888 * size == 0 is a special case, for which we
889 * don't check / adjust the screen parameters.
890 * This isn't a problem since the plane can't
891 * be reenabled unless its size is > 0.
892 */
893 if (old_size != size && size) {
894 if (size) {
895 memcpy(new_var, &fbi->var, sizeof(*new_var));
896 r = set_fb_var(fbi, new_var);
897 if (r < 0)
898 goto out;
899 }
900 }
901
902 if (fbdev->ctrl->sync)
903 fbdev->ctrl->sync();
904 r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
905 if (r < 0) {
906 /* Revert changes. */
907 rg->size = old_size;
908 rg->type = old_type;
909 goto out;
910 }
911 rg->paddr = paddr;
912
913 if (old_size != size) {
914 if (size) {
915 memcpy(&fbi->var, new_var, sizeof(fbi->var));
Sergio Aguirre03bb2b42009-10-05 13:31:46 -0700916 set_fb_fix(fbi, 0);
Imre Deak8b08cf22007-07-17 04:05:54 -0700917 } else {
918 /*
919 * Set these explicitly to indicate that the
920 * plane memory is dealloce'd, the other
921 * screen parameters in var / fix are invalid.
922 */
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700923 mutex_lock(&fbi->mm_lock);
Imre Deak8b08cf22007-07-17 04:05:54 -0700924 fbi->fix.smem_start = 0;
925 fbi->fix.smem_len = 0;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700926 mutex_unlock(&fbi->mm_lock);
Imre Deak8b08cf22007-07-17 04:05:54 -0700927 }
928 }
929 }
930out:
931 omapfb_rqueue_unlock(fbdev);
932
933 return r;
934}
935
936static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
937{
938 struct omapfb_plane_struct *plane = fbi->par;
939 struct omapfb_device *fbdev = plane->fbdev;
940 struct omapfb_mem_region *rg;
941
942 rg = &fbdev->mem_desc.region[plane->idx];
943 memset(mi, 0, sizeof(*mi));
944 mi->size = rg->size;
945 mi->type = rg->type;
946
947 return 0;
948}
949
950static int omapfb_set_color_key(struct omapfb_device *fbdev,
951 struct omapfb_color_key *ck)
952{
953 int r;
954
955 if (!fbdev->ctrl->set_color_key)
956 return -ENODEV;
957
958 omapfb_rqueue_lock(fbdev);
959 r = fbdev->ctrl->set_color_key(ck);
960 omapfb_rqueue_unlock(fbdev);
961
962 return r;
963}
964
965static int omapfb_get_color_key(struct omapfb_device *fbdev,
966 struct omapfb_color_key *ck)
967{
968 int r;
969
970 if (!fbdev->ctrl->get_color_key)
971 return -ENODEV;
972
973 omapfb_rqueue_lock(fbdev);
974 r = fbdev->ctrl->get_color_key(ck);
975 omapfb_rqueue_unlock(fbdev);
976
977 return r;
978}
979
980static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
981static int notifier_inited;
982
983static void omapfb_init_notifier(void)
984{
985 int i;
986
987 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
988 BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
989}
990
991int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
992 omapfb_notifier_callback_t callback,
993 void *callback_data)
994{
995 int r;
996
997 if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
998 return -EINVAL;
999
1000 if (!notifier_inited) {
1001 omapfb_init_notifier();
1002 notifier_inited = 1;
1003 }
1004
1005 omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
1006 unsigned long, void *))callback;
1007 omapfb_nb->data = callback_data;
1008 r = blocking_notifier_chain_register(
1009 &omapfb_client_list[omapfb_nb->plane_idx],
1010 &omapfb_nb->nb);
1011 if (r)
1012 return r;
1013 if (omapfb_dev != NULL &&
1014 omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
1015 omapfb_dev->ctrl->bind_client(omapfb_nb);
1016 }
1017
1018 return 0;
1019}
1020EXPORT_SYMBOL(omapfb_register_client);
1021
1022int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
1023{
1024 return blocking_notifier_chain_unregister(
1025 &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
1026}
1027EXPORT_SYMBOL(omapfb_unregister_client);
1028
1029void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
1030{
1031 int i;
1032
1033 if (!notifier_inited)
1034 /* no client registered yet */
1035 return;
1036
1037 for (i = 0; i < OMAPFB_PLANE_NUM; i++)
1038 blocking_notifier_call_chain(&omapfb_client_list[i], event,
1039 fbdev->fb_info[i]);
1040}
1041EXPORT_SYMBOL(omapfb_notify_clients);
1042
1043static int omapfb_set_update_mode(struct omapfb_device *fbdev,
1044 enum omapfb_update_mode mode)
1045{
1046 int r;
1047
1048 omapfb_rqueue_lock(fbdev);
1049 r = fbdev->ctrl->set_update_mode(mode);
1050 omapfb_rqueue_unlock(fbdev);
1051
1052 return r;
1053}
1054
1055static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
1056{
1057 int r;
1058
1059 omapfb_rqueue_lock(fbdev);
1060 r = fbdev->ctrl->get_update_mode();
1061 omapfb_rqueue_unlock(fbdev);
1062
1063 return r;
1064}
1065
1066static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
1067 struct omapfb_caps *caps)
1068{
1069 memset(caps, 0, sizeof(*caps));
1070 fbdev->ctrl->get_caps(plane, caps);
1071 caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
1072}
1073
1074/* For lcd testing */
1075void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1076{
1077 omapfb_rqueue_lock(fbdev);
1078 *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
1079 if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
1080 struct omapfb_update_window win;
1081
1082 memset(&win, 0, sizeof(win));
1083 win.width = 2;
1084 win.height = 2;
1085 win.out_width = 2;
1086 win.out_height = 2;
Russell Kingc0fc18c52008-09-05 15:10:27 +01001087 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, NULL);
Imre Deak8b08cf22007-07-17 04:05:54 -07001088 }
1089 omapfb_rqueue_unlock(fbdev);
1090}
1091EXPORT_SYMBOL(omapfb_write_first_pixel);
1092
1093/*
1094 * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
1095 * here to be accessible by user mode code.
1096 */
1097static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
1098 unsigned long arg)
1099{
1100 struct omapfb_plane_struct *plane = fbi->par;
1101 struct omapfb_device *fbdev = plane->fbdev;
1102 struct fb_ops *ops = fbi->fbops;
1103 union {
1104 struct omapfb_update_window update_window;
1105 struct omapfb_plane_info plane_info;
1106 struct omapfb_mem_info mem_info;
1107 struct omapfb_color_key color_key;
1108 enum omapfb_update_mode update_mode;
1109 struct omapfb_caps caps;
1110 unsigned int mirror;
1111 int plane_out;
1112 int enable_plane;
1113 } p;
1114 int r = 0;
1115
1116 BUG_ON(!ops);
1117 switch (cmd) {
1118 case OMAPFB_MIRROR:
1119 if (get_user(p.mirror, (int __user *)arg))
1120 r = -EFAULT;
1121 else
1122 omapfb_mirror(fbi, p.mirror);
1123 break;
1124 case OMAPFB_SYNC_GFX:
1125 omapfb_sync(fbi);
1126 break;
1127 case OMAPFB_VSYNC:
1128 break;
1129 case OMAPFB_SET_UPDATE_MODE:
1130 if (get_user(p.update_mode, (int __user *)arg))
1131 r = -EFAULT;
1132 else
1133 r = omapfb_set_update_mode(fbdev, p.update_mode);
1134 break;
1135 case OMAPFB_GET_UPDATE_MODE:
1136 p.update_mode = omapfb_get_update_mode(fbdev);
1137 if (put_user(p.update_mode,
1138 (enum omapfb_update_mode __user *)arg))
1139 r = -EFAULT;
1140 break;
1141 case OMAPFB_UPDATE_WINDOW_OLD:
1142 if (copy_from_user(&p.update_window, (void __user *)arg,
1143 sizeof(struct omapfb_update_window_old)))
1144 r = -EFAULT;
1145 else {
1146 struct omapfb_update_window *u = &p.update_window;
1147 u->out_x = u->x;
1148 u->out_y = u->y;
1149 u->out_width = u->width;
1150 u->out_height = u->height;
1151 memset(u->reserved, 0, sizeof(u->reserved));
1152 r = omapfb_update_win(fbi, u);
1153 }
1154 break;
1155 case OMAPFB_UPDATE_WINDOW:
1156 if (copy_from_user(&p.update_window, (void __user *)arg,
1157 sizeof(p.update_window)))
1158 r = -EFAULT;
1159 else
1160 r = omapfb_update_win(fbi, &p.update_window);
1161 break;
1162 case OMAPFB_SETUP_PLANE:
1163 if (copy_from_user(&p.plane_info, (void __user *)arg,
1164 sizeof(p.plane_info)))
1165 r = -EFAULT;
1166 else
1167 r = omapfb_setup_plane(fbi, &p.plane_info);
1168 break;
1169 case OMAPFB_QUERY_PLANE:
1170 if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
1171 break;
1172 if (copy_to_user((void __user *)arg, &p.plane_info,
1173 sizeof(p.plane_info)))
1174 r = -EFAULT;
1175 break;
1176 case OMAPFB_SETUP_MEM:
1177 if (copy_from_user(&p.mem_info, (void __user *)arg,
1178 sizeof(p.mem_info)))
1179 r = -EFAULT;
1180 else
1181 r = omapfb_setup_mem(fbi, &p.mem_info);
1182 break;
1183 case OMAPFB_QUERY_MEM:
1184 if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
1185 break;
1186 if (copy_to_user((void __user *)arg, &p.mem_info,
1187 sizeof(p.mem_info)))
1188 r = -EFAULT;
1189 break;
1190 case OMAPFB_SET_COLOR_KEY:
1191 if (copy_from_user(&p.color_key, (void __user *)arg,
1192 sizeof(p.color_key)))
1193 r = -EFAULT;
1194 else
1195 r = omapfb_set_color_key(fbdev, &p.color_key);
1196 break;
1197 case OMAPFB_GET_COLOR_KEY:
1198 if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
1199 break;
1200 if (copy_to_user((void __user *)arg, &p.color_key,
1201 sizeof(p.color_key)))
1202 r = -EFAULT;
1203 break;
1204 case OMAPFB_GET_CAPS:
1205 omapfb_get_caps(fbdev, plane->idx, &p.caps);
1206 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
1207 r = -EFAULT;
1208 break;
1209 case OMAPFB_LCD_TEST:
1210 {
1211 int test_num;
1212
1213 if (get_user(test_num, (int __user *)arg)) {
1214 r = -EFAULT;
1215 break;
1216 }
1217 if (!fbdev->panel->run_test) {
1218 r = -EINVAL;
1219 break;
1220 }
1221 r = fbdev->panel->run_test(fbdev->panel, test_num);
1222 break;
1223 }
1224 case OMAPFB_CTRL_TEST:
1225 {
1226 int test_num;
1227
1228 if (get_user(test_num, (int __user *)arg)) {
1229 r = -EFAULT;
1230 break;
1231 }
1232 if (!fbdev->ctrl->run_test) {
1233 r = -EINVAL;
1234 break;
1235 }
1236 r = fbdev->ctrl->run_test(test_num);
1237 break;
1238 }
1239 default:
1240 r = -EINVAL;
1241 }
1242
1243 return r;
1244}
1245
1246static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1247{
1248 struct omapfb_plane_struct *plane = info->par;
1249 struct omapfb_device *fbdev = plane->fbdev;
1250 int r;
1251
1252 omapfb_rqueue_lock(fbdev);
1253 r = fbdev->ctrl->mmap(info, vma);
1254 omapfb_rqueue_unlock(fbdev);
1255
1256 return r;
1257}
1258
1259/*
1260 * Callback table for the frame buffer framework. Some of these pointers
1261 * will be changed according to the current setting of fb_info->accel_flags.
1262 */
1263static struct fb_ops omapfb_ops = {
1264 .owner = THIS_MODULE,
1265 .fb_open = omapfb_open,
1266 .fb_release = omapfb_release,
1267 .fb_setcolreg = omapfb_setcolreg,
1268 .fb_setcmap = omapfb_setcmap,
1269 .fb_fillrect = cfb_fillrect,
1270 .fb_copyarea = cfb_copyarea,
1271 .fb_imageblit = cfb_imageblit,
1272 .fb_blank = omapfb_blank,
1273 .fb_ioctl = omapfb_ioctl,
1274 .fb_check_var = omapfb_check_var,
1275 .fb_set_par = omapfb_set_par,
1276 .fb_rotate = omapfb_rotate,
1277 .fb_pan_display = omapfb_pan_display,
1278};
1279
1280/*
1281 * ---------------------------------------------------------------------------
1282 * Sysfs interface
1283 * ---------------------------------------------------------------------------
1284 */
1285/* omapfbX sysfs entries */
1286static ssize_t omapfb_show_caps_num(struct device *dev,
1287 struct device_attribute *attr, char *buf)
1288{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001289 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001290 int plane;
1291 size_t size;
1292 struct omapfb_caps caps;
1293
1294 plane = 0;
1295 size = 0;
1296 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1297 omapfb_get_caps(fbdev, plane, &caps);
1298 size += snprintf(&buf[size], PAGE_SIZE - size,
1299 "plane#%d %#010x %#010x %#010x\n",
1300 plane, caps.ctrl, caps.plane_color, caps.wnd_color);
1301 plane++;
1302 }
1303 return size;
1304}
1305
1306static ssize_t omapfb_show_caps_text(struct device *dev,
1307 struct device_attribute *attr, char *buf)
1308{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001309 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001310 int i;
1311 struct omapfb_caps caps;
1312 int plane;
1313 size_t size;
1314
1315 plane = 0;
1316 size = 0;
1317 while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
1318 omapfb_get_caps(fbdev, plane, &caps);
1319 size += snprintf(&buf[size], PAGE_SIZE - size,
1320 "plane#%d:\n", plane);
1321 for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
1322 size < PAGE_SIZE; i++) {
1323 if (ctrl_caps[i].flag & caps.ctrl)
1324 size += snprintf(&buf[size], PAGE_SIZE - size,
1325 " %s\n", ctrl_caps[i].name);
1326 }
1327 size += snprintf(&buf[size], PAGE_SIZE - size,
1328 " plane colors:\n");
1329 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1330 size < PAGE_SIZE; i++) {
1331 if (color_caps[i].flag & caps.plane_color)
1332 size += snprintf(&buf[size], PAGE_SIZE - size,
1333 " %s\n", color_caps[i].name);
1334 }
1335 size += snprintf(&buf[size], PAGE_SIZE - size,
1336 " window colors:\n");
1337 for (i = 0; i < ARRAY_SIZE(color_caps) &&
1338 size < PAGE_SIZE; i++) {
1339 if (color_caps[i].flag & caps.wnd_color)
1340 size += snprintf(&buf[size], PAGE_SIZE - size,
1341 " %s\n", color_caps[i].name);
1342 }
1343
1344 plane++;
1345 }
1346 return size;
1347}
1348
1349static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
1350static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
1351
1352/* panel sysfs entries */
1353static ssize_t omapfb_show_panel_name(struct device *dev,
1354 struct device_attribute *attr, char *buf)
1355{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001356 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001357
1358 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
1359}
1360
1361static ssize_t omapfb_show_bklight_level(struct device *dev,
1362 struct device_attribute *attr,
1363 char *buf)
1364{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001365 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001366 int r;
1367
1368 if (fbdev->panel->get_bklight_level) {
1369 r = snprintf(buf, PAGE_SIZE, "%d\n",
1370 fbdev->panel->get_bklight_level(fbdev->panel));
1371 } else
1372 r = -ENODEV;
1373 return r;
1374}
1375
1376static ssize_t omapfb_store_bklight_level(struct device *dev,
1377 struct device_attribute *attr,
1378 const char *buf, size_t size)
1379{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001380 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001381 int r;
1382
1383 if (fbdev->panel->set_bklight_level) {
1384 unsigned int level;
1385
1386 if (sscanf(buf, "%10d", &level) == 1) {
1387 r = fbdev->panel->set_bklight_level(fbdev->panel,
1388 level);
1389 } else
1390 r = -EINVAL;
1391 } else
1392 r = -ENODEV;
1393 return r ? r : size;
1394}
1395
1396static ssize_t omapfb_show_bklight_max(struct device *dev,
1397 struct device_attribute *attr, char *buf)
1398{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001399 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001400 int r;
1401
1402 if (fbdev->panel->get_bklight_level) {
1403 r = snprintf(buf, PAGE_SIZE, "%d\n",
1404 fbdev->panel->get_bklight_max(fbdev->panel));
1405 } else
1406 r = -ENODEV;
1407 return r;
1408}
1409
1410static struct device_attribute dev_attr_panel_name =
1411 __ATTR(name, 0444, omapfb_show_panel_name, NULL);
1412static DEVICE_ATTR(backlight_level, 0664,
1413 omapfb_show_bklight_level, omapfb_store_bklight_level);
1414static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
1415
1416static struct attribute *panel_attrs[] = {
1417 &dev_attr_panel_name.attr,
1418 &dev_attr_backlight_level.attr,
1419 &dev_attr_backlight_max.attr,
1420 NULL,
1421};
1422
1423static struct attribute_group panel_attr_grp = {
1424 .name = "panel",
1425 .attrs = panel_attrs,
1426};
1427
1428/* ctrl sysfs entries */
1429static ssize_t omapfb_show_ctrl_name(struct device *dev,
1430 struct device_attribute *attr, char *buf)
1431{
Greg Kroah-Hartman5e9a8bd2009-06-23 08:31:46 -07001432 struct omapfb_device *fbdev = dev_get_drvdata(dev);
Imre Deak8b08cf22007-07-17 04:05:54 -07001433
1434 return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
1435}
1436
1437static struct device_attribute dev_attr_ctrl_name =
1438 __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
1439
1440static struct attribute *ctrl_attrs[] = {
1441 &dev_attr_ctrl_name.attr,
1442 NULL,
1443};
1444
1445static struct attribute_group ctrl_attr_grp = {
1446 .name = "ctrl",
1447 .attrs = ctrl_attrs,
1448};
1449
1450static int omapfb_register_sysfs(struct omapfb_device *fbdev)
1451{
1452 int r;
1453
1454 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
1455 goto fail0;
1456
1457 if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
1458 goto fail1;
1459
1460 if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
1461 goto fail2;
1462
1463 if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
1464 goto fail3;
1465
1466 return 0;
1467fail3:
1468 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1469fail2:
1470 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1471fail1:
1472 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1473fail0:
1474 dev_err(fbdev->dev, "unable to register sysfs interface\n");
1475 return r;
1476}
1477
1478static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
1479{
1480 sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
1481 sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
1482 device_remove_file(fbdev->dev, &dev_attr_caps_num);
1483 device_remove_file(fbdev->dev, &dev_attr_caps_text);
1484}
1485
1486/*
1487 * ---------------------------------------------------------------------------
1488 * LDM callbacks
1489 * ---------------------------------------------------------------------------
1490 */
1491/* Initialize system fb_info object and set the default video mode.
1492 * The frame buffer memory already allocated by lcddma_init
1493 */
1494static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
1495{
1496 struct fb_var_screeninfo *var = &info->var;
1497 struct fb_fix_screeninfo *fix = &info->fix;
1498 int r = 0;
1499
1500 info->fbops = &omapfb_ops;
1501 info->flags = FBINFO_FLAG_DEFAULT;
1502
1503 strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
1504
1505 info->pseudo_palette = fbdev->pseudo_palette;
1506
1507 var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
1508 var->xres = def_vxres;
1509 var->yres = def_vyres;
1510 var->xres_virtual = def_vxres;
1511 var->yres_virtual = def_vyres;
1512 var->rotate = def_rotate;
1513 var->bits_per_pixel = fbdev->panel->bpp;
1514
1515 set_fb_var(info, var);
Sergio Aguirre03bb2b42009-10-05 13:31:46 -07001516 set_fb_fix(info, 1);
Imre Deak8b08cf22007-07-17 04:05:54 -07001517
1518 r = fb_alloc_cmap(&info->cmap, 16, 0);
1519 if (r != 0)
1520 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1521
1522 return r;
1523}
1524
1525/* Release the fb_info object */
1526static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
1527{
1528 fb_dealloc_cmap(&fbi->cmap);
1529}
1530
1531static void planes_cleanup(struct omapfb_device *fbdev)
1532{
1533 int i;
1534
1535 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1536 if (fbdev->fb_info[i] == NULL)
1537 break;
1538 fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
1539 framebuffer_release(fbdev->fb_info[i]);
1540 }
1541}
1542
1543static int planes_init(struct omapfb_device *fbdev)
1544{
1545 struct fb_info *fbi;
1546 int i;
1547 int r;
1548
1549 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1550 struct omapfb_plane_struct *plane;
1551 fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
1552 fbdev->dev);
1553 if (fbi == NULL) {
1554 dev_err(fbdev->dev,
1555 "unable to allocate memory for plane info\n");
1556 planes_cleanup(fbdev);
1557 return -ENOMEM;
1558 }
1559 plane = fbi->par;
1560 plane->idx = i;
1561 plane->fbdev = fbdev;
1562 plane->info.mirror = def_mirror;
1563 fbdev->fb_info[i] = fbi;
1564
1565 if ((r = fbinfo_init(fbdev, fbi)) < 0) {
1566 framebuffer_release(fbi);
1567 planes_cleanup(fbdev);
1568 return r;
1569 }
1570 plane->info.out_width = fbi->var.xres;
1571 plane->info.out_height = fbi->var.yres;
1572 }
1573 return 0;
1574}
1575
1576/*
1577 * Free driver resources. Can be called to rollback an aborted initialization
1578 * sequence.
1579 */
1580static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
1581{
1582 int i;
1583
1584 switch (state) {
1585 case OMAPFB_ACTIVE:
1586 for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
1587 unregister_framebuffer(fbdev->fb_info[i]);
1588 case 7:
1589 omapfb_unregister_sysfs(fbdev);
1590 case 6:
1591 fbdev->panel->disable(fbdev->panel);
1592 case 5:
1593 omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
1594 case 4:
1595 planes_cleanup(fbdev);
1596 case 3:
1597 ctrl_cleanup(fbdev);
1598 case 2:
1599 fbdev->panel->cleanup(fbdev->panel);
1600 case 1:
1601 dev_set_drvdata(fbdev->dev, NULL);
1602 kfree(fbdev);
1603 case 0:
1604 /* nothing to free */
1605 break;
1606 default:
1607 BUG();
1608 }
1609}
1610
1611static int omapfb_find_ctrl(struct omapfb_device *fbdev)
1612{
1613 struct omapfb_platform_data *conf;
1614 char name[17];
1615 int i;
1616
1617 conf = fbdev->dev->platform_data;
1618
1619 fbdev->ctrl = NULL;
1620
1621 strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
1622 name[sizeof(name) - 1] = '\0';
1623
1624 if (strcmp(name, "internal") == 0) {
1625 fbdev->ctrl = fbdev->int_ctrl;
1626 return 0;
1627 }
1628
1629 for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
1630 dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
1631 if (strcmp(ctrls[i]->name, name) == 0) {
1632 fbdev->ctrl = ctrls[i];
1633 break;
1634 }
1635 }
1636
1637 if (fbdev->ctrl == NULL) {
1638 dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
1639 return -1;
1640 }
1641
1642 return 0;
1643}
1644
1645static void check_required_callbacks(struct omapfb_device *fbdev)
1646{
1647#define _C(x) (fbdev->ctrl->x != NULL)
1648#define _P(x) (fbdev->panel->x != NULL)
1649 BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
1650 BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
1651 _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
1652 _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
1653 _P(get_caps)));
1654#undef _P
1655#undef _C
1656}
1657
1658/*
1659 * Called by LDM binding to probe and attach a new device.
1660 * Initialization sequence:
1661 * 1. allocate system omapfb_device structure
1662 * 2. select controller type according to platform configuration
1663 * init LCD panel
1664 * 3. init LCD controller and LCD DMA
1665 * 4. init system fb_info structure for all planes
1666 * 5. setup video mode for first plane and enable it
1667 * 6. enable LCD panel
1668 * 7. register sysfs attributes
1669 * OMAPFB_ACTIVE: register system fb_info structure for all planes
1670 */
1671static int omapfb_do_probe(struct platform_device *pdev,
1672 struct lcd_panel *panel)
1673{
1674 struct omapfb_device *fbdev = NULL;
1675 int init_state;
1676 unsigned long phz, hhz, vhz;
1677 unsigned long vram;
1678 int i;
1679 int r = 0;
1680
1681 init_state = 0;
1682
1683 if (pdev->num_resources != 0) {
1684 dev_err(&pdev->dev, "probed for an unknown device\n");
1685 r = -ENODEV;
1686 goto cleanup;
1687 }
1688
1689 if (pdev->dev.platform_data == NULL) {
1690 dev_err(&pdev->dev, "missing platform data\n");
1691 r = -ENOENT;
1692 goto cleanup;
1693 }
1694
1695 fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
1696 if (fbdev == NULL) {
1697 dev_err(&pdev->dev,
1698 "unable to allocate memory for device info\n");
1699 r = -ENOMEM;
1700 goto cleanup;
1701 }
1702 init_state++;
1703
1704 fbdev->dev = &pdev->dev;
1705 fbdev->panel = panel;
Tomi Valkeinenf778a122009-12-16 13:18:07 +02001706 fbdev->dssdev = &omapdss_device;
Imre Deak8b08cf22007-07-17 04:05:54 -07001707 platform_set_drvdata(pdev, fbdev);
1708
1709 mutex_init(&fbdev->rqueue_mutex);
1710
Imre Deak8b08cf22007-07-17 04:05:54 -07001711 fbdev->int_ctrl = &omap1_int_ctrl;
1712#ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
1713 fbdev->ext_if = &omap1_ext_if;
1714#endif
Imre Deak8b08cf22007-07-17 04:05:54 -07001715 if (omapfb_find_ctrl(fbdev) < 0) {
1716 dev_err(fbdev->dev,
1717 "LCD controller not found, board not supported\n");
1718 r = -ENODEV;
1719 goto cleanup;
1720 }
1721
1722 r = fbdev->panel->init(fbdev->panel, fbdev);
1723 if (r)
1724 goto cleanup;
1725
1726 pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
1727
arun c5910d352009-09-22 16:46:59 -07001728 def_vxres = def_vxres ? def_vxres : fbdev->panel->x_res;
1729 def_vyres = def_vyres ? def_vyres : fbdev->panel->y_res;
Imre Deak8b08cf22007-07-17 04:05:54 -07001730
1731 init_state++;
1732
1733 r = ctrl_init(fbdev);
1734 if (r)
1735 goto cleanup;
1736 if (fbdev->ctrl->mmap != NULL)
1737 omapfb_ops.fb_mmap = omapfb_mmap;
1738 init_state++;
1739
1740 check_required_callbacks(fbdev);
1741
1742 r = planes_init(fbdev);
1743 if (r)
1744 goto cleanup;
1745 init_state++;
1746
1747#ifdef CONFIG_FB_OMAP_DMA_TUNE
1748 /* Set DMA priority for EMIFF access to highest */
1749 if (cpu_class_is_omap1())
1750 omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
1751#endif
1752
1753 r = ctrl_change_mode(fbdev->fb_info[0]);
1754 if (r) {
1755 dev_err(fbdev->dev, "mode setting failed\n");
1756 goto cleanup;
1757 }
1758
1759 /* GFX plane is enabled by default */
1760 r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
1761 if (r)
1762 goto cleanup;
1763
1764 omapfb_set_update_mode(fbdev, manual_update ?
1765 OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
1766 init_state++;
1767
1768 r = fbdev->panel->enable(fbdev->panel);
1769 if (r)
1770 goto cleanup;
1771 init_state++;
1772
1773 r = omapfb_register_sysfs(fbdev);
1774 if (r)
1775 goto cleanup;
1776 init_state++;
1777
1778 vram = 0;
1779 for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
1780 r = register_framebuffer(fbdev->fb_info[i]);
1781 if (r != 0) {
1782 dev_err(fbdev->dev,
1783 "registering framebuffer %d failed\n", i);
1784 goto cleanup;
1785 }
1786 vram += fbdev->mem_desc.region[i].size;
1787 }
1788
1789 fbdev->state = OMAPFB_ACTIVE;
1790
1791 panel = fbdev->panel;
1792 phz = panel->pixel_clock * 1000;
1793 hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
1794 vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
1795
1796 omapfb_dev = fbdev;
1797
1798 pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
1799 vram, fbdev->mem_desc.region_cnt);
1800 pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
1801 "vfreq %lu.%lu Hz\n",
1802 phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
1803
1804 return 0;
1805
1806cleanup:
1807 omapfb_free_resources(fbdev, init_state);
1808
1809 return r;
1810}
1811
1812static int omapfb_probe(struct platform_device *pdev)
1813{
Tomi Valkeinenf778a122009-12-16 13:18:07 +02001814 int r;
1815
Imre Deak8b08cf22007-07-17 04:05:54 -07001816 BUG_ON(fbdev_pdev != NULL);
1817
Tomi Valkeinenf778a122009-12-16 13:18:07 +02001818 r = platform_device_register(&omapdss_device);
1819 if (r) {
1820 dev_err(&pdev->dev, "can't register omapdss device\n");
1821 return r;
1822 }
1823
Imre Deak8b08cf22007-07-17 04:05:54 -07001824 /* Delay actual initialization until the LCD is registered */
1825 fbdev_pdev = pdev;
1826 if (fbdev_panel != NULL)
1827 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1828 return 0;
1829}
1830
1831void omapfb_register_panel(struct lcd_panel *panel)
1832{
1833 BUG_ON(fbdev_panel != NULL);
1834
1835 fbdev_panel = panel;
1836 if (fbdev_pdev != NULL)
1837 omapfb_do_probe(fbdev_pdev, fbdev_panel);
1838}
1839
1840/* Called when the device is being detached from the driver */
1841static int omapfb_remove(struct platform_device *pdev)
1842{
1843 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1844 enum omapfb_state saved_state = fbdev->state;
1845
1846 /* FIXME: wait till completion of pending events */
1847
1848 fbdev->state = OMAPFB_DISABLED;
1849 omapfb_free_resources(fbdev, saved_state);
1850
Tomi Valkeinenf778a122009-12-16 13:18:07 +02001851 platform_device_unregister(&omapdss_device);
1852 fbdev->dssdev = NULL;
1853
Imre Deak8b08cf22007-07-17 04:05:54 -07001854 return 0;
1855}
1856
1857/* PM suspend */
1858static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
1859{
1860 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1861
Jouni Hoganderb6c2b662009-09-22 16:46:58 -07001862 if (fbdev != NULL)
1863 omapfb_blank(FB_BLANK_POWERDOWN, fbdev->fb_info[0]);
Imre Deak8b08cf22007-07-17 04:05:54 -07001864 return 0;
1865}
1866
1867/* PM resume */
1868static int omapfb_resume(struct platform_device *pdev)
1869{
1870 struct omapfb_device *fbdev = platform_get_drvdata(pdev);
1871
Jouni Hoganderb6c2b662009-09-22 16:46:58 -07001872 if (fbdev != NULL)
1873 omapfb_blank(FB_BLANK_UNBLANK, fbdev->fb_info[0]);
Imre Deak8b08cf22007-07-17 04:05:54 -07001874 return 0;
1875}
1876
1877static struct platform_driver omapfb_driver = {
1878 .probe = omapfb_probe,
1879 .remove = omapfb_remove,
1880 .suspend = omapfb_suspend,
1881 .resume = omapfb_resume,
1882 .driver = {
1883 .name = MODULE_NAME,
1884 .owner = THIS_MODULE,
1885 },
1886};
1887
1888#ifndef MODULE
1889
1890/* Process kernel command line parameters */
1891static int __init omapfb_setup(char *options)
1892{
1893 char *this_opt = NULL;
1894 int r = 0;
1895
1896 pr_debug("omapfb: options %s\n", options);
1897
1898 if (!options || !*options)
1899 return 0;
1900
1901 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
1902 if (!strncmp(this_opt, "accel", 5))
1903 def_accel = 1;
1904 else if (!strncmp(this_opt, "vram:", 5)) {
1905 char *suffix;
1906 unsigned long vram;
1907 vram = (simple_strtoul(this_opt + 5, &suffix, 0));
1908 switch (suffix[0]) {
1909 case '\0':
1910 break;
1911 case 'm':
1912 case 'M':
1913 vram *= 1024;
1914 /* Fall through */
1915 case 'k':
1916 case 'K':
1917 vram *= 1024;
1918 break;
1919 default:
1920 pr_debug("omapfb: invalid vram suffix %c\n",
1921 suffix[0]);
1922 r = -1;
1923 }
1924 def_vram[def_vram_cnt++] = vram;
1925 }
1926 else if (!strncmp(this_opt, "vxres:", 6))
1927 def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
1928 else if (!strncmp(this_opt, "vyres:", 6))
1929 def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
1930 else if (!strncmp(this_opt, "rotate:", 7))
1931 def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
1932 else if (!strncmp(this_opt, "mirror:", 7))
1933 def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
1934 else if (!strncmp(this_opt, "manual_update", 13))
1935 manual_update = 1;
1936 else {
1937 pr_debug("omapfb: invalid option\n");
1938 r = -1;
1939 }
1940 }
1941
1942 return r;
1943}
1944
1945#endif
1946
1947/* Register both the driver and the device */
1948static int __init omapfb_init(void)
1949{
1950#ifndef MODULE
1951 char *option;
1952
1953 if (fb_get_options("omapfb", &option))
1954 return -ENODEV;
1955 omapfb_setup(option);
1956#endif
1957 /* Register the driver with LDM */
1958 if (platform_driver_register(&omapfb_driver)) {
1959 pr_debug("failed to register omapfb driver\n");
1960 return -ENODEV;
1961 }
1962
1963 return 0;
1964}
1965
1966static void __exit omapfb_cleanup(void)
1967{
1968 platform_driver_unregister(&omapfb_driver);
1969}
1970
1971module_param_named(accel, def_accel, uint, 0664);
1972module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
1973module_param_named(vxres, def_vxres, long, 0664);
1974module_param_named(vyres, def_vyres, long, 0664);
1975module_param_named(rotate, def_rotate, uint, 0664);
1976module_param_named(mirror, def_mirror, uint, 0664);
1977module_param_named(manual_update, manual_update, bool, 0664);
1978
1979module_init(omapfb_init);
1980module_exit(omapfb_cleanup);
1981
1982MODULE_DESCRIPTION("TI OMAP framebuffer driver");
1983MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
1984MODULE_LICENSE("GPL");