aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/omap2/omapfb
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/video/omap2/omapfb
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/video/omap2/omapfb')
-rw-r--r--drivers/video/omap2/omapfb/Kconfig28
-rw-r--r--drivers/video/omap2/omapfb/Makefile2
-rw-r--r--drivers/video/omap2/omapfb/omapfb-ioctl.c785
-rw-r--r--drivers/video/omap2/omapfb/omapfb-main.c2287
-rw-r--r--drivers/video/omap2/omapfb/omapfb-sysfs.c507
-rw-r--r--drivers/video/omap2/omapfb/omapfb.h155
6 files changed, 3764 insertions, 0 deletions
diff --git a/drivers/video/omap2/omapfb/Kconfig b/drivers/video/omap2/omapfb/Kconfig
new file mode 100644
index 000000000000..43496d6c377f
--- /dev/null
+++ b/drivers/video/omap2/omapfb/Kconfig
@@ -0,0 +1,28 @@
1menuconfig FB_OMAP2
2 tristate "OMAP2/3 frame buffer support (EXPERIMENTAL)"
3 depends on FB && OMAP2_DSS
4
5 select OMAP2_VRAM
6 select OMAP2_VRFB
7 select FB_CFB_FILLRECT
8 select FB_CFB_COPYAREA
9 select FB_CFB_IMAGEBLIT
10 help
11 Frame buffer driver for OMAP2/3 based boards.
12
13config FB_OMAP2_DEBUG_SUPPORT
14 bool "Debug support for OMAP2/3 FB"
15 default y
16 depends on FB_OMAP2
17 help
18 Support for debug output. You have to enable the actual printing
19 with 'debug' module parameter.
20
21config FB_OMAP2_NUM_FBS
22 int "Number of framebuffers"
23 range 1 10
24 default 3
25 depends on FB_OMAP2
26 help
27 Select the number of framebuffers created. OMAP2/3 has 3 overlays
28 so normally this would be 3.
diff --git a/drivers/video/omap2/omapfb/Makefile b/drivers/video/omap2/omapfb/Makefile
new file mode 100644
index 000000000000..51c2e00d9bf8
--- /dev/null
+++ b/drivers/video/omap2/omapfb/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_FB_OMAP2) += omapfb.o
2omapfb-y := omapfb-main.o omapfb-sysfs.o omapfb-ioctl.o
diff --git a/drivers/video/omap2/omapfb/omapfb-ioctl.c b/drivers/video/omap2/omapfb/omapfb-ioctl.c
new file mode 100644
index 000000000000..1ffa760b8545
--- /dev/null
+++ b/drivers/video/omap2/omapfb/omapfb-ioctl.c
@@ -0,0 +1,785 @@
1/*
2 * linux/drivers/video/omap2/omapfb-ioctl.c
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <linux/fb.h>
24#include <linux/device.h>
25#include <linux/uaccess.h>
26#include <linux/platform_device.h>
27#include <linux/mm.h>
28#include <linux/omapfb.h>
29#include <linux/vmalloc.h>
30
31#include <plat/display.h>
32#include <plat/vrfb.h>
33#include <plat/vram.h>
34
35#include "omapfb.h"
36
37static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
38{
39 struct omapfb_info *ofbi = FB2OFB(fbi);
40 struct omapfb2_device *fbdev = ofbi->fbdev;
41 struct omap_overlay *ovl;
42 struct omap_overlay_info info;
43 int r = 0;
44
45 DBG("omapfb_setup_plane\n");
46
47 if (ofbi->num_overlays != 1) {
48 r = -EINVAL;
49 goto out;
50 }
51
52 /* XXX uses only the first overlay */
53 ovl = ofbi->overlays[0];
54
55 if (pi->enabled && !ofbi->region.size) {
56 /*
57 * This plane's memory was freed, can't enable it
58 * until it's reallocated.
59 */
60 r = -EINVAL;
61 goto out;
62 }
63
64 ovl->get_overlay_info(ovl, &info);
65
66 info.pos_x = pi->pos_x;
67 info.pos_y = pi->pos_y;
68 info.out_width = pi->out_width;
69 info.out_height = pi->out_height;
70 info.enabled = pi->enabled;
71
72 r = ovl->set_overlay_info(ovl, &info);
73 if (r)
74 goto out;
75
76 if (ovl->manager) {
77 r = ovl->manager->apply(ovl->manager);
78 if (r)
79 goto out;
80 }
81
82out:
83 if (r)
84 dev_err(fbdev->dev, "setup_plane failed\n");
85 return r;
86}
87
88static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
89{
90 struct omapfb_info *ofbi = FB2OFB(fbi);
91
92 if (ofbi->num_overlays != 1) {
93 memset(pi, 0, sizeof(*pi));
94 } else {
95 struct omap_overlay_info *ovli;
96 struct omap_overlay *ovl;
97
98 ovl = ofbi->overlays[0];
99 ovli = &ovl->info;
100
101 pi->pos_x = ovli->pos_x;
102 pi->pos_y = ovli->pos_y;
103 pi->enabled = ovli->enabled;
104 pi->channel_out = 0; /* xxx */
105 pi->mirror = 0;
106 pi->out_width = ovli->out_width;
107 pi->out_height = ovli->out_height;
108 }
109
110 return 0;
111}
112
113static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
114{
115 struct omapfb_info *ofbi = FB2OFB(fbi);
116 struct omapfb2_device *fbdev = ofbi->fbdev;
117 struct omapfb2_mem_region *rg;
118 int r, i;
119 size_t size;
120
121 if (mi->type > OMAPFB_MEMTYPE_MAX)
122 return -EINVAL;
123
124 size = PAGE_ALIGN(mi->size);
125
126 rg = &ofbi->region;
127
128 for (i = 0; i < ofbi->num_overlays; i++) {
129 if (ofbi->overlays[i]->info.enabled)
130 return -EBUSY;
131 }
132
133 if (rg->size != size || rg->type != mi->type) {
134 r = omapfb_realloc_fbmem(fbi, size, mi->type);
135 if (r) {
136 dev_err(fbdev->dev, "realloc fbmem failed\n");
137 return r;
138 }
139 }
140
141 return 0;
142}
143
144static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
145{
146 struct omapfb_info *ofbi = FB2OFB(fbi);
147 struct omapfb2_mem_region *rg;
148
149 rg = &ofbi->region;
150 memset(mi, 0, sizeof(*mi));
151
152 mi->size = rg->size;
153 mi->type = rg->type;
154
155 return 0;
156}
157
158static int omapfb_update_window_nolock(struct fb_info *fbi,
159 u32 x, u32 y, u32 w, u32 h)
160{
161 struct omap_dss_device *display = fb2display(fbi);
162 u16 dw, dh;
163
164 if (!display)
165 return 0;
166
167 if (w == 0 || h == 0)
168 return 0;
169
170 display->driver->get_resolution(display, &dw, &dh);
171
172 if (x + w > dw || y + h > dh)
173 return -EINVAL;
174
175 return display->driver->update(display, x, y, w, h);
176}
177
178/* This function is exported for SGX driver use */
179int omapfb_update_window(struct fb_info *fbi,
180 u32 x, u32 y, u32 w, u32 h)
181{
182 struct omapfb_info *ofbi = FB2OFB(fbi);
183 struct omapfb2_device *fbdev = ofbi->fbdev;
184 int r;
185
186 omapfb_lock(fbdev);
187 lock_fb_info(fbi);
188
189 r = omapfb_update_window_nolock(fbi, x, y, w, h);
190
191 unlock_fb_info(fbi);
192 omapfb_unlock(fbdev);
193
194 return r;
195}
196EXPORT_SYMBOL(omapfb_update_window);
197
198static int omapfb_set_update_mode(struct fb_info *fbi,
199 enum omapfb_update_mode mode)
200{
201 struct omap_dss_device *display = fb2display(fbi);
202 enum omap_dss_update_mode um;
203 int r;
204
205 if (!display || !display->driver->set_update_mode)
206 return -EINVAL;
207
208 switch (mode) {
209 case OMAPFB_UPDATE_DISABLED:
210 um = OMAP_DSS_UPDATE_DISABLED;
211 break;
212
213 case OMAPFB_AUTO_UPDATE:
214 um = OMAP_DSS_UPDATE_AUTO;
215 break;
216
217 case OMAPFB_MANUAL_UPDATE:
218 um = OMAP_DSS_UPDATE_MANUAL;
219 break;
220
221 default:
222 return -EINVAL;
223 }
224
225 r = display->driver->set_update_mode(display, um);
226
227 return r;
228}
229
230static int omapfb_get_update_mode(struct fb_info *fbi,
231 enum omapfb_update_mode *mode)
232{
233 struct omap_dss_device *display = fb2display(fbi);
234 enum omap_dss_update_mode m;
235
236 if (!display)
237 return -EINVAL;
238
239 if (!display->driver->get_update_mode) {
240 *mode = OMAPFB_AUTO_UPDATE;
241 return 0;
242 }
243
244 m = display->driver->get_update_mode(display);
245
246 switch (m) {
247 case OMAP_DSS_UPDATE_DISABLED:
248 *mode = OMAPFB_UPDATE_DISABLED;
249 break;
250 case OMAP_DSS_UPDATE_AUTO:
251 *mode = OMAPFB_AUTO_UPDATE;
252 break;
253 case OMAP_DSS_UPDATE_MANUAL:
254 *mode = OMAPFB_MANUAL_UPDATE;
255 break;
256 default:
257 BUG();
258 }
259
260 return 0;
261}
262
263/* XXX this color key handling is a hack... */
264static struct omapfb_color_key omapfb_color_keys[2];
265
266static int _omapfb_set_color_key(struct omap_overlay_manager *mgr,
267 struct omapfb_color_key *ck)
268{
269 struct omap_overlay_manager_info info;
270 enum omap_dss_trans_key_type kt;
271 int r;
272
273 mgr->get_manager_info(mgr, &info);
274
275 if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) {
276 info.trans_enabled = false;
277 omapfb_color_keys[mgr->id] = *ck;
278
279 r = mgr->set_manager_info(mgr, &info);
280 if (r)
281 return r;
282
283 r = mgr->apply(mgr);
284
285 return r;
286 }
287
288 switch (ck->key_type) {
289 case OMAPFB_COLOR_KEY_GFX_DST:
290 kt = OMAP_DSS_COLOR_KEY_GFX_DST;
291 break;
292 case OMAPFB_COLOR_KEY_VID_SRC:
293 kt = OMAP_DSS_COLOR_KEY_VID_SRC;
294 break;
295 default:
296 return -EINVAL;
297 }
298
299 info.default_color = ck->background;
300 info.trans_key = ck->trans_key;
301 info.trans_key_type = kt;
302 info.trans_enabled = true;
303
304 omapfb_color_keys[mgr->id] = *ck;
305
306 r = mgr->set_manager_info(mgr, &info);
307 if (r)
308 return r;
309
310 r = mgr->apply(mgr);
311
312 return r;
313}
314
315static int omapfb_set_color_key(struct fb_info *fbi,
316 struct omapfb_color_key *ck)
317{
318 struct omapfb_info *ofbi = FB2OFB(fbi);
319 struct omapfb2_device *fbdev = ofbi->fbdev;
320 int r;
321 int i;
322 struct omap_overlay_manager *mgr = NULL;
323
324 omapfb_lock(fbdev);
325
326 for (i = 0; i < ofbi->num_overlays; i++) {
327 if (ofbi->overlays[i]->manager) {
328 mgr = ofbi->overlays[i]->manager;
329 break;
330 }
331 }
332
333 if (!mgr) {
334 r = -EINVAL;
335 goto err;
336 }
337
338 r = _omapfb_set_color_key(mgr, ck);
339err:
340 omapfb_unlock(fbdev);
341
342 return r;
343}
344
345static int omapfb_get_color_key(struct fb_info *fbi,
346 struct omapfb_color_key *ck)
347{
348 struct omapfb_info *ofbi = FB2OFB(fbi);
349 struct omapfb2_device *fbdev = ofbi->fbdev;
350 struct omap_overlay_manager *mgr = NULL;
351 int r = 0;
352 int i;
353
354 omapfb_lock(fbdev);
355
356 for (i = 0; i < ofbi->num_overlays; i++) {
357 if (ofbi->overlays[i]->manager) {
358 mgr = ofbi->overlays[i]->manager;
359 break;
360 }
361 }
362
363 if (!mgr) {
364 r = -EINVAL;
365 goto err;
366 }
367
368 *ck = omapfb_color_keys[mgr->id];
369err:
370 omapfb_unlock(fbdev);
371
372 return r;
373}
374
375static int omapfb_memory_read(struct fb_info *fbi,
376 struct omapfb_memory_read *mr)
377{
378 struct omap_dss_device *display = fb2display(fbi);
379 void *buf;
380 int r;
381
382 if (!display || !display->driver->memory_read)
383 return -ENOENT;
384
385 if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
386 return -EFAULT;
387
388 if (mr->w * mr->h * 3 > mr->buffer_size)
389 return -EINVAL;
390
391 buf = vmalloc(mr->buffer_size);
392 if (!buf) {
393 DBG("vmalloc failed\n");
394 return -ENOMEM;
395 }
396
397 r = display->driver->memory_read(display, buf, mr->buffer_size,
398 mr->x, mr->y, mr->w, mr->h);
399
400 if (r > 0) {
401 if (copy_to_user(mr->buffer, buf, mr->buffer_size))
402 r = -EFAULT;
403 }
404
405 vfree(buf);
406
407 return r;
408}
409
410static int omapfb_get_ovl_colormode(struct omapfb2_device *fbdev,
411 struct omapfb_ovl_colormode *mode)
412{
413 int ovl_idx = mode->overlay_idx;
414 int mode_idx = mode->mode_idx;
415 struct omap_overlay *ovl;
416 enum omap_color_mode supported_modes;
417 struct fb_var_screeninfo var;
418 int i;
419
420 if (ovl_idx >= fbdev->num_overlays)
421 return -ENODEV;
422 ovl = fbdev->overlays[ovl_idx];
423 supported_modes = ovl->supported_modes;
424
425 mode_idx = mode->mode_idx;
426
427 for (i = 0; i < sizeof(supported_modes) * 8; i++) {
428 if (!(supported_modes & (1 << i)))
429 continue;
430 /*
431 * It's possible that the FB doesn't support a mode
432 * that is supported by the overlay, so call the
433 * following here.
434 */
435 if (dss_mode_to_fb_mode(1 << i, &var) < 0)
436 continue;
437
438 mode_idx--;
439 if (mode_idx < 0)
440 break;
441 }
442
443 if (i == sizeof(supported_modes) * 8)
444 return -ENOENT;
445
446 mode->bits_per_pixel = var.bits_per_pixel;
447 mode->nonstd = var.nonstd;
448 mode->red = var.red;
449 mode->green = var.green;
450 mode->blue = var.blue;
451 mode->transp = var.transp;
452
453 return 0;
454}
455
456static int omapfb_wait_for_go(struct fb_info *fbi)
457{
458 struct omapfb_info *ofbi = FB2OFB(fbi);
459 int r = 0;
460 int i;
461
462 for (i = 0; i < ofbi->num_overlays; ++i) {
463 struct omap_overlay *ovl = ofbi->overlays[i];
464 r = ovl->wait_for_go(ovl);
465 if (r)
466 break;
467 }
468
469 return r;
470}
471
472int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
473{
474 struct omapfb_info *ofbi = FB2OFB(fbi);
475 struct omapfb2_device *fbdev = ofbi->fbdev;
476 struct omap_dss_device *display = fb2display(fbi);
477
478 union {
479 struct omapfb_update_window_old uwnd_o;
480 struct omapfb_update_window uwnd;
481 struct omapfb_plane_info plane_info;
482 struct omapfb_caps caps;
483 struct omapfb_mem_info mem_info;
484 struct omapfb_color_key color_key;
485 struct omapfb_ovl_colormode ovl_colormode;
486 enum omapfb_update_mode update_mode;
487 int test_num;
488 struct omapfb_memory_read memory_read;
489 struct omapfb_vram_info vram_info;
490 struct omapfb_tearsync_info tearsync_info;
491 struct omapfb_display_info display_info;
492 } p;
493
494 int r = 0;
495
496 switch (cmd) {
497 case OMAPFB_SYNC_GFX:
498 DBG("ioctl SYNC_GFX\n");
499 if (!display || !display->driver->sync) {
500 /* DSS1 never returns an error here, so we neither */
501 /*r = -EINVAL;*/
502 break;
503 }
504
505 r = display->driver->sync(display);
506 break;
507
508 case OMAPFB_UPDATE_WINDOW_OLD:
509 DBG("ioctl UPDATE_WINDOW_OLD\n");
510 if (!display || !display->driver->update) {
511 r = -EINVAL;
512 break;
513 }
514
515 if (copy_from_user(&p.uwnd_o,
516 (void __user *)arg,
517 sizeof(p.uwnd_o))) {
518 r = -EFAULT;
519 break;
520 }
521
522 r = omapfb_update_window_nolock(fbi, p.uwnd_o.x, p.uwnd_o.y,
523 p.uwnd_o.width, p.uwnd_o.height);
524 break;
525
526 case OMAPFB_UPDATE_WINDOW:
527 DBG("ioctl UPDATE_WINDOW\n");
528 if (!display || !display->driver->update) {
529 r = -EINVAL;
530 break;
531 }
532
533 if (copy_from_user(&p.uwnd, (void __user *)arg,
534 sizeof(p.uwnd))) {
535 r = -EFAULT;
536 break;
537 }
538
539 r = omapfb_update_window_nolock(fbi, p.uwnd.x, p.uwnd.y,
540 p.uwnd.width, p.uwnd.height);
541 break;
542
543 case OMAPFB_SETUP_PLANE:
544 DBG("ioctl SETUP_PLANE\n");
545 if (copy_from_user(&p.plane_info, (void __user *)arg,
546 sizeof(p.plane_info)))
547 r = -EFAULT;
548 else
549 r = omapfb_setup_plane(fbi, &p.plane_info);
550 break;
551
552 case OMAPFB_QUERY_PLANE:
553 DBG("ioctl QUERY_PLANE\n");
554 r = omapfb_query_plane(fbi, &p.plane_info);
555 if (r < 0)
556 break;
557 if (copy_to_user((void __user *)arg, &p.plane_info,
558 sizeof(p.plane_info)))
559 r = -EFAULT;
560 break;
561
562 case OMAPFB_SETUP_MEM:
563 DBG("ioctl SETUP_MEM\n");
564 if (copy_from_user(&p.mem_info, (void __user *)arg,
565 sizeof(p.mem_info)))
566 r = -EFAULT;
567 else
568 r = omapfb_setup_mem(fbi, &p.mem_info);
569 break;
570
571 case OMAPFB_QUERY_MEM:
572 DBG("ioctl QUERY_MEM\n");
573 r = omapfb_query_mem(fbi, &p.mem_info);
574 if (r < 0)
575 break;
576 if (copy_to_user((void __user *)arg, &p.mem_info,
577 sizeof(p.mem_info)))
578 r = -EFAULT;
579 break;
580
581 case OMAPFB_GET_CAPS:
582 DBG("ioctl GET_CAPS\n");
583 if (!display) {
584 r = -EINVAL;
585 break;
586 }
587
588 memset(&p.caps, 0, sizeof(p.caps));
589 if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
590 p.caps.ctrl |= OMAPFB_CAPS_MANUAL_UPDATE;
591 if (display->caps & OMAP_DSS_DISPLAY_CAP_TEAR_ELIM)
592 p.caps.ctrl |= OMAPFB_CAPS_TEARSYNC;
593
594 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
595 r = -EFAULT;
596 break;
597
598 case OMAPFB_GET_OVERLAY_COLORMODE:
599 DBG("ioctl GET_OVERLAY_COLORMODE\n");
600 if (copy_from_user(&p.ovl_colormode, (void __user *)arg,
601 sizeof(p.ovl_colormode))) {
602 r = -EFAULT;
603 break;
604 }
605 r = omapfb_get_ovl_colormode(fbdev, &p.ovl_colormode);
606 if (r < 0)
607 break;
608 if (copy_to_user((void __user *)arg, &p.ovl_colormode,
609 sizeof(p.ovl_colormode)))
610 r = -EFAULT;
611 break;
612
613 case OMAPFB_SET_UPDATE_MODE:
614 DBG("ioctl SET_UPDATE_MODE\n");
615 if (get_user(p.update_mode, (int __user *)arg))
616 r = -EFAULT;
617 else
618 r = omapfb_set_update_mode(fbi, p.update_mode);
619 break;
620
621 case OMAPFB_GET_UPDATE_MODE:
622 DBG("ioctl GET_UPDATE_MODE\n");
623 r = omapfb_get_update_mode(fbi, &p.update_mode);
624 if (r)
625 break;
626 if (put_user(p.update_mode,
627 (enum omapfb_update_mode __user *)arg))
628 r = -EFAULT;
629 break;
630
631 case OMAPFB_SET_COLOR_KEY:
632 DBG("ioctl SET_COLOR_KEY\n");
633 if (copy_from_user(&p.color_key, (void __user *)arg,
634 sizeof(p.color_key)))
635 r = -EFAULT;
636 else
637 r = omapfb_set_color_key(fbi, &p.color_key);
638 break;
639
640 case OMAPFB_GET_COLOR_KEY:
641 DBG("ioctl GET_COLOR_KEY\n");
642 r = omapfb_get_color_key(fbi, &p.color_key);
643 if (r)
644 break;
645 if (copy_to_user((void __user *)arg, &p.color_key,
646 sizeof(p.color_key)))
647 r = -EFAULT;
648 break;
649
650 case OMAPFB_WAITFORVSYNC:
651 DBG("ioctl WAITFORVSYNC\n");
652 if (!display) {
653 r = -EINVAL;
654 break;
655 }
656
657 r = display->manager->wait_for_vsync(display->manager);
658 break;
659
660 case OMAPFB_WAITFORGO:
661 DBG("ioctl WAITFORGO\n");
662 if (!display) {
663 r = -EINVAL;
664 break;
665 }
666
667 r = omapfb_wait_for_go(fbi);
668 break;
669
670 /* LCD and CTRL tests do the same thing for backward
671 * compatibility */
672 case OMAPFB_LCD_TEST:
673 DBG("ioctl LCD_TEST\n");
674 if (get_user(p.test_num, (int __user *)arg)) {
675 r = -EFAULT;
676 break;
677 }
678 if (!display || !display->driver->run_test) {
679 r = -EINVAL;
680 break;
681 }
682
683 r = display->driver->run_test(display, p.test_num);
684
685 break;
686
687 case OMAPFB_CTRL_TEST:
688 DBG("ioctl CTRL_TEST\n");
689 if (get_user(p.test_num, (int __user *)arg)) {
690 r = -EFAULT;
691 break;
692 }
693 if (!display || !display->driver->run_test) {
694 r = -EINVAL;
695 break;
696 }
697
698 r = display->driver->run_test(display, p.test_num);
699
700 break;
701
702 case OMAPFB_MEMORY_READ:
703 DBG("ioctl MEMORY_READ\n");
704
705 if (copy_from_user(&p.memory_read, (void __user *)arg,
706 sizeof(p.memory_read))) {
707 r = -EFAULT;
708 break;
709 }
710
711 r = omapfb_memory_read(fbi, &p.memory_read);
712
713 break;
714
715 case OMAPFB_GET_VRAM_INFO: {
716 unsigned long vram, free, largest;
717
718 DBG("ioctl GET_VRAM_INFO\n");
719
720 omap_vram_get_info(&vram, &free, &largest);
721 p.vram_info.total = vram;
722 p.vram_info.free = free;
723 p.vram_info.largest_free_block = largest;
724
725 if (copy_to_user((void __user *)arg, &p.vram_info,
726 sizeof(p.vram_info)))
727 r = -EFAULT;
728 break;
729 }
730
731 case OMAPFB_SET_TEARSYNC: {
732 DBG("ioctl SET_TEARSYNC\n");
733
734 if (copy_from_user(&p.tearsync_info, (void __user *)arg,
735 sizeof(p.tearsync_info))) {
736 r = -EFAULT;
737 break;
738 }
739
740 if (!display->driver->enable_te) {
741 r = -ENODEV;
742 break;
743 }
744
745 r = display->driver->enable_te(display,
746 !!p.tearsync_info.enabled);
747
748 break;
749 }
750
751 case OMAPFB_GET_DISPLAY_INFO: {
752 u16 xres, yres;
753
754 DBG("ioctl GET_DISPLAY_INFO\n");
755
756 if (display == NULL) {
757 r = -ENODEV;
758 break;
759 }
760
761 display->driver->get_resolution(display, &xres, &yres);
762
763 p.display_info.xres = xres;
764 p.display_info.yres = yres;
765 p.display_info.width = 0;
766 p.display_info.height = 0;
767
768 if (copy_to_user((void __user *)arg, &p.display_info,
769 sizeof(p.display_info)))
770 r = -EFAULT;
771 break;
772 }
773
774 default:
775 dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd);
776 r = -EINVAL;
777 }
778
779 if (r < 0)
780 DBG("ioctl failed: %d\n", r);
781
782 return r;
783}
784
785
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
new file mode 100644
index 000000000000..4b4506da96da
--- /dev/null
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -0,0 +1,2287 @@
1/*
2 * linux/drivers/video/omap2/omapfb-main.c
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <linux/module.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/fb.h>
27#include <linux/dma-mapping.h>
28#include <linux/vmalloc.h>
29#include <linux/device.h>
30#include <linux/platform_device.h>
31#include <linux/omapfb.h>
32
33#include <plat/display.h>
34#include <plat/vram.h>
35#include <plat/vrfb.h>
36
37#include "omapfb.h"
38
39#define MODULE_NAME "omapfb"
40
41#define OMAPFB_PLANE_XRES_MIN 8
42#define OMAPFB_PLANE_YRES_MIN 8
43
44static char *def_mode;
45static char *def_vram;
46static int def_vrfb;
47static int def_rotate;
48static int def_mirror;
49
50#ifdef DEBUG
51unsigned int omapfb_debug;
52module_param_named(debug, omapfb_debug, bool, 0644);
53static unsigned int omapfb_test_pattern;
54module_param_named(test, omapfb_test_pattern, bool, 0644);
55#endif
56
57static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi);
58static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev,
59 struct omap_dss_device *dssdev);
60
61#ifdef DEBUG
62static void draw_pixel(struct fb_info *fbi, int x, int y, unsigned color)
63{
64 struct fb_var_screeninfo *var = &fbi->var;
65 struct fb_fix_screeninfo *fix = &fbi->fix;
66 void __iomem *addr = fbi->screen_base;
67 const unsigned bytespp = var->bits_per_pixel >> 3;
68 const unsigned line_len = fix->line_length / bytespp;
69
70 int r = (color >> 16) & 0xff;
71 int g = (color >> 8) & 0xff;
72 int b = (color >> 0) & 0xff;
73
74 if (var->bits_per_pixel == 16) {
75 u16 __iomem *p = (u16 __iomem *)addr;
76 p += y * line_len + x;
77
78 r = r * 32 / 256;
79 g = g * 64 / 256;
80 b = b * 32 / 256;
81
82 __raw_writew((r << 11) | (g << 5) | (b << 0), p);
83 } else if (var->bits_per_pixel == 24) {
84 u8 __iomem *p = (u8 __iomem *)addr;
85 p += (y * line_len + x) * 3;
86
87 __raw_writeb(b, p + 0);
88 __raw_writeb(g, p + 1);
89 __raw_writeb(r, p + 2);
90 } else if (var->bits_per_pixel == 32) {
91 u32 __iomem *p = (u32 __iomem *)addr;
92 p += y * line_len + x;
93 __raw_writel(color, p);
94 }
95}
96
97static void fill_fb(struct fb_info *fbi)
98{
99 struct fb_var_screeninfo *var = &fbi->var;
100 const short w = var->xres_virtual;
101 const short h = var->yres_virtual;
102 void __iomem *addr = fbi->screen_base;
103 int y, x;
104
105 if (!addr)
106 return;
107
108 DBG("fill_fb %dx%d, line_len %d bytes\n", w, h, fbi->fix.line_length);
109
110 for (y = 0; y < h; y++) {
111 for (x = 0; x < w; x++) {
112 if (x < 20 && y < 20)
113 draw_pixel(fbi, x, y, 0xffffff);
114 else if (x < 20 && (y > 20 && y < h - 20))
115 draw_pixel(fbi, x, y, 0xff);
116 else if (y < 20 && (x > 20 && x < w - 20))
117 draw_pixel(fbi, x, y, 0xff00);
118 else if (x > w - 20 && (y > 20 && y < h - 20))
119 draw_pixel(fbi, x, y, 0xff0000);
120 else if (y > h - 20 && (x > 20 && x < w - 20))
121 draw_pixel(fbi, x, y, 0xffff00);
122 else if (x == 20 || x == w - 20 ||
123 y == 20 || y == h - 20)
124 draw_pixel(fbi, x, y, 0xffffff);
125 else if (x == y || w - x == h - y)
126 draw_pixel(fbi, x, y, 0xff00ff);
127 else if (w - x == y || x == h - y)
128 draw_pixel(fbi, x, y, 0x00ffff);
129 else if (x > 20 && y > 20 && x < w - 20 && y < h - 20) {
130 int t = x * 3 / w;
131 unsigned r = 0, g = 0, b = 0;
132 unsigned c;
133 if (var->bits_per_pixel == 16) {
134 if (t == 0)
135 b = (y % 32) * 256 / 32;
136 else if (t == 1)
137 g = (y % 64) * 256 / 64;
138 else if (t == 2)
139 r = (y % 32) * 256 / 32;
140 } else {
141 if (t == 0)
142 b = (y % 256);
143 else if (t == 1)
144 g = (y % 256);
145 else if (t == 2)
146 r = (y % 256);
147 }
148 c = (r << 16) | (g << 8) | (b << 0);
149 draw_pixel(fbi, x, y, c);
150 } else {
151 draw_pixel(fbi, x, y, 0);
152 }
153 }
154 }
155}
156#endif
157
158static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot)
159{
160 const struct vrfb *vrfb = &ofbi->region.vrfb;
161 unsigned offset;
162
163 switch (rot) {
164 case FB_ROTATE_UR:
165 offset = 0;
166 break;
167 case FB_ROTATE_CW:
168 offset = vrfb->yoffset;
169 break;
170 case FB_ROTATE_UD:
171 offset = vrfb->yoffset * OMAP_VRFB_LINE_LEN + vrfb->xoffset;
172 break;
173 case FB_ROTATE_CCW:
174 offset = vrfb->xoffset * OMAP_VRFB_LINE_LEN;
175 break;
176 default:
177 BUG();
178 }
179
180 offset *= vrfb->bytespp;
181
182 return offset;
183}
184
185static u32 omapfb_get_region_rot_paddr(const struct omapfb_info *ofbi, int rot)
186{
187 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
188 return ofbi->region.vrfb.paddr[rot]
189 + omapfb_get_vrfb_offset(ofbi, rot);
190 } else {
191 return ofbi->region.paddr;
192 }
193}
194
195static u32 omapfb_get_region_paddr(const struct omapfb_info *ofbi)
196{
197 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
198 return ofbi->region.vrfb.paddr[0];
199 else
200 return ofbi->region.paddr;
201}
202
203static void __iomem *omapfb_get_region_vaddr(const struct omapfb_info *ofbi)
204{
205 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
206 return ofbi->region.vrfb.vaddr[0];
207 else
208 return ofbi->region.vaddr;
209}
210
211static struct omapfb_colormode omapfb_colormodes[] = {
212 {
213 .dssmode = OMAP_DSS_COLOR_UYVY,
214 .bits_per_pixel = 16,
215 .nonstd = OMAPFB_COLOR_YUV422,
216 }, {
217 .dssmode = OMAP_DSS_COLOR_YUV2,
218 .bits_per_pixel = 16,
219 .nonstd = OMAPFB_COLOR_YUY422,
220 }, {
221 .dssmode = OMAP_DSS_COLOR_ARGB16,
222 .bits_per_pixel = 16,
223 .red = { .length = 4, .offset = 8, .msb_right = 0 },
224 .green = { .length = 4, .offset = 4, .msb_right = 0 },
225 .blue = { .length = 4, .offset = 0, .msb_right = 0 },
226 .transp = { .length = 4, .offset = 12, .msb_right = 0 },
227 }, {
228 .dssmode = OMAP_DSS_COLOR_RGB16,
229 .bits_per_pixel = 16,
230 .red = { .length = 5, .offset = 11, .msb_right = 0 },
231 .green = { .length = 6, .offset = 5, .msb_right = 0 },
232 .blue = { .length = 5, .offset = 0, .msb_right = 0 },
233 .transp = { .length = 0, .offset = 0, .msb_right = 0 },
234 }, {
235 .dssmode = OMAP_DSS_COLOR_RGB24P,
236 .bits_per_pixel = 24,
237 .red = { .length = 8, .offset = 16, .msb_right = 0 },
238 .green = { .length = 8, .offset = 8, .msb_right = 0 },
239 .blue = { .length = 8, .offset = 0, .msb_right = 0 },
240 .transp = { .length = 0, .offset = 0, .msb_right = 0 },
241 }, {
242 .dssmode = OMAP_DSS_COLOR_RGB24U,
243 .bits_per_pixel = 32,
244 .red = { .length = 8, .offset = 16, .msb_right = 0 },
245 .green = { .length = 8, .offset = 8, .msb_right = 0 },
246 .blue = { .length = 8, .offset = 0, .msb_right = 0 },
247 .transp = { .length = 0, .offset = 0, .msb_right = 0 },
248 }, {
249 .dssmode = OMAP_DSS_COLOR_ARGB32,
250 .bits_per_pixel = 32,
251 .red = { .length = 8, .offset = 16, .msb_right = 0 },
252 .green = { .length = 8, .offset = 8, .msb_right = 0 },
253 .blue = { .length = 8, .offset = 0, .msb_right = 0 },
254 .transp = { .length = 8, .offset = 24, .msb_right = 0 },
255 }, {
256 .dssmode = OMAP_DSS_COLOR_RGBA32,
257 .bits_per_pixel = 32,
258 .red = { .length = 8, .offset = 24, .msb_right = 0 },
259 .green = { .length = 8, .offset = 16, .msb_right = 0 },
260 .blue = { .length = 8, .offset = 8, .msb_right = 0 },
261 .transp = { .length = 8, .offset = 0, .msb_right = 0 },
262 }, {
263 .dssmode = OMAP_DSS_COLOR_RGBX32,
264 .bits_per_pixel = 32,
265 .red = { .length = 8, .offset = 24, .msb_right = 0 },
266 .green = { .length = 8, .offset = 16, .msb_right = 0 },
267 .blue = { .length = 8, .offset = 8, .msb_right = 0 },
268 .transp = { .length = 0, .offset = 0, .msb_right = 0 },
269 },
270};
271
272static bool cmp_var_to_colormode(struct fb_var_screeninfo *var,
273 struct omapfb_colormode *color)
274{
275 bool cmp_component(struct fb_bitfield *f1, struct fb_bitfield *f2)
276 {
277 return f1->length == f2->length &&
278 f1->offset == f2->offset &&
279 f1->msb_right == f2->msb_right;
280 }
281
282 if (var->bits_per_pixel == 0 ||
283 var->red.length == 0 ||
284 var->blue.length == 0 ||
285 var->green.length == 0)
286 return 0;
287
288 return var->bits_per_pixel == color->bits_per_pixel &&
289 cmp_component(&var->red, &color->red) &&
290 cmp_component(&var->green, &color->green) &&
291 cmp_component(&var->blue, &color->blue) &&
292 cmp_component(&var->transp, &color->transp);
293}
294
295static void assign_colormode_to_var(struct fb_var_screeninfo *var,
296 struct omapfb_colormode *color)
297{
298 var->bits_per_pixel = color->bits_per_pixel;
299 var->nonstd = color->nonstd;
300 var->red = color->red;
301 var->green = color->green;
302 var->blue = color->blue;
303 var->transp = color->transp;
304}
305
306static int fb_mode_to_dss_mode(struct fb_var_screeninfo *var,
307 enum omap_color_mode *mode)
308{
309 enum omap_color_mode dssmode;
310 int i;
311
312 /* first match with nonstd field */
313 if (var->nonstd) {
314 for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
315 struct omapfb_colormode *m = &omapfb_colormodes[i];
316 if (var->nonstd == m->nonstd) {
317 assign_colormode_to_var(var, m);
318 *mode = m->dssmode;
319 return 0;
320 }
321 }
322
323 return -EINVAL;
324 }
325
326 /* then try exact match of bpp and colors */
327 for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
328 struct omapfb_colormode *m = &omapfb_colormodes[i];
329 if (cmp_var_to_colormode(var, m)) {
330 assign_colormode_to_var(var, m);
331 *mode = m->dssmode;
332 return 0;
333 }
334 }
335
336 /* match with bpp if user has not filled color fields
337 * properly */
338 switch (var->bits_per_pixel) {
339 case 1:
340 dssmode = OMAP_DSS_COLOR_CLUT1;
341 break;
342 case 2:
343 dssmode = OMAP_DSS_COLOR_CLUT2;
344 break;
345 case 4:
346 dssmode = OMAP_DSS_COLOR_CLUT4;
347 break;
348 case 8:
349 dssmode = OMAP_DSS_COLOR_CLUT8;
350 break;
351 case 12:
352 dssmode = OMAP_DSS_COLOR_RGB12U;
353 break;
354 case 16:
355 dssmode = OMAP_DSS_COLOR_RGB16;
356 break;
357 case 24:
358 dssmode = OMAP_DSS_COLOR_RGB24P;
359 break;
360 case 32:
361 dssmode = OMAP_DSS_COLOR_RGB24U;
362 break;
363 default:
364 return -EINVAL;
365 }
366
367 for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
368 struct omapfb_colormode *m = &omapfb_colormodes[i];
369 if (dssmode == m->dssmode) {
370 assign_colormode_to_var(var, m);
371 *mode = m->dssmode;
372 return 0;
373 }
374 }
375
376 return -EINVAL;
377}
378
379static int check_fb_res_bounds(struct fb_var_screeninfo *var)
380{
381 int xres_min = OMAPFB_PLANE_XRES_MIN;
382 int xres_max = 2048;
383 int yres_min = OMAPFB_PLANE_YRES_MIN;
384 int yres_max = 2048;
385
386 /* XXX: some applications seem to set virtual res to 0. */
387 if (var->xres_virtual == 0)
388 var->xres_virtual = var->xres;
389
390 if (var->yres_virtual == 0)
391 var->yres_virtual = var->yres;
392
393 if (var->xres_virtual < xres_min || var->yres_virtual < yres_min)
394 return -EINVAL;
395
396 if (var->xres < xres_min)
397 var->xres = xres_min;
398 if (var->yres < yres_min)
399 var->yres = yres_min;
400 if (var->xres > xres_max)
401 var->xres = xres_max;
402 if (var->yres > yres_max)
403 var->yres = yres_max;
404
405 if (var->xres > var->xres_virtual)
406 var->xres = var->xres_virtual;
407 if (var->yres > var->yres_virtual)
408 var->yres = var->yres_virtual;
409
410 return 0;
411}
412
413static void shrink_height(unsigned long max_frame_size,
414 struct fb_var_screeninfo *var)
415{
416 DBG("can't fit FB into memory, reducing y\n");
417 var->yres_virtual = max_frame_size /
418 (var->xres_virtual * var->bits_per_pixel >> 3);
419
420 if (var->yres_virtual < OMAPFB_PLANE_YRES_MIN)
421 var->yres_virtual = OMAPFB_PLANE_YRES_MIN;
422
423 if (var->yres > var->yres_virtual)
424 var->yres = var->yres_virtual;
425}
426
427static void shrink_width(unsigned long max_frame_size,
428 struct fb_var_screeninfo *var)
429{
430 DBG("can't fit FB into memory, reducing x\n");
431 var->xres_virtual = max_frame_size / var->yres_virtual /
432 (var->bits_per_pixel >> 3);
433
434 if (var->xres_virtual < OMAPFB_PLANE_XRES_MIN)
435 var->xres_virtual = OMAPFB_PLANE_XRES_MIN;
436
437 if (var->xres > var->xres_virtual)
438 var->xres = var->xres_virtual;
439}
440
441static int check_vrfb_fb_size(unsigned long region_size,
442 const struct fb_var_screeninfo *var)
443{
444 unsigned long min_phys_size = omap_vrfb_min_phys_size(var->xres_virtual,
445 var->yres_virtual, var->bits_per_pixel >> 3);
446
447 return min_phys_size > region_size ? -EINVAL : 0;
448}
449
450static int check_fb_size(const struct omapfb_info *ofbi,
451 struct fb_var_screeninfo *var)
452{
453 unsigned long max_frame_size = ofbi->region.size;
454 int bytespp = var->bits_per_pixel >> 3;
455 unsigned long line_size = var->xres_virtual * bytespp;
456
457 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
458 /* One needs to check for both VRFB and OMAPFB limitations. */
459 if (check_vrfb_fb_size(max_frame_size, var))
460 shrink_height(omap_vrfb_max_height(
461 max_frame_size, var->xres_virtual, bytespp) *
462 line_size, var);
463
464 if (check_vrfb_fb_size(max_frame_size, var)) {
465 DBG("cannot fit FB to memory\n");
466 return -EINVAL;
467 }
468
469 return 0;
470 }
471
472 DBG("max frame size %lu, line size %lu\n", max_frame_size, line_size);
473
474 if (line_size * var->yres_virtual > max_frame_size)
475 shrink_height(max_frame_size, var);
476
477 if (line_size * var->yres_virtual > max_frame_size) {
478 shrink_width(max_frame_size, var);
479 line_size = var->xres_virtual * bytespp;
480 }
481
482 if (line_size * var->yres_virtual > max_frame_size) {
483 DBG("cannot fit FB to memory\n");
484 return -EINVAL;
485 }
486
487 return 0;
488}
489
490/*
491 * Consider if VRFB assisted rotation is in use and if the virtual space for
492 * the zero degree view needs to be mapped. The need for mapping also acts as
493 * the trigger for setting up the hardware on the context in question. This
494 * ensures that one does not attempt to access the virtual view before the
495 * hardware is serving the address translations.
496 */
497static int setup_vrfb_rotation(struct fb_info *fbi)
498{
499 struct omapfb_info *ofbi = FB2OFB(fbi);
500 struct omapfb2_mem_region *rg = &ofbi->region;
501 struct vrfb *vrfb = &rg->vrfb;
502 struct fb_var_screeninfo *var = &fbi->var;
503 struct fb_fix_screeninfo *fix = &fbi->fix;
504 unsigned bytespp;
505 bool yuv_mode;
506 enum omap_color_mode mode;
507 int r;
508 bool reconf;
509
510 if (!rg->size || ofbi->rotation_type != OMAP_DSS_ROT_VRFB)
511 return 0;
512
513 DBG("setup_vrfb_rotation\n");
514
515 r = fb_mode_to_dss_mode(var, &mode);
516 if (r)
517 return r;
518
519 bytespp = var->bits_per_pixel >> 3;
520
521 yuv_mode = mode == OMAP_DSS_COLOR_YUV2 || mode == OMAP_DSS_COLOR_UYVY;
522
523 /* We need to reconfigure VRFB if the resolution changes, if yuv mode
524 * is enabled/disabled, or if bytes per pixel changes */
525
526 /* XXX we shouldn't allow this when framebuffer is mmapped */
527
528 reconf = false;
529
530 if (yuv_mode != vrfb->yuv_mode)
531 reconf = true;
532 else if (bytespp != vrfb->bytespp)
533 reconf = true;
534 else if (vrfb->xres != var->xres_virtual ||
535 vrfb->yres != var->yres_virtual)
536 reconf = true;
537
538 if (vrfb->vaddr[0] && reconf) {
539 fbi->screen_base = NULL;
540 fix->smem_start = 0;
541 fix->smem_len = 0;
542 iounmap(vrfb->vaddr[0]);
543 vrfb->vaddr[0] = NULL;
544 DBG("setup_vrfb_rotation: reset fb\n");
545 }
546
547 if (vrfb->vaddr[0])
548 return 0;
549
550 omap_vrfb_setup(&rg->vrfb, rg->paddr,
551 var->xres_virtual,
552 var->yres_virtual,
553 bytespp, yuv_mode);
554
555 /* Now one can ioremap the 0 angle view */
556 r = omap_vrfb_map_angle(vrfb, var->yres_virtual, 0);
557 if (r)
558 return r;
559
560 /* used by open/write in fbmem.c */
561 fbi->screen_base = ofbi->region.vrfb.vaddr[0];
562
563 fix->smem_start = ofbi->region.vrfb.paddr[0];
564
565 switch (var->nonstd) {
566 case OMAPFB_COLOR_YUV422:
567 case OMAPFB_COLOR_YUY422:
568 fix->line_length =
569 (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2;
570 break;
571 default:
572 fix->line_length =
573 (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3;
574 break;
575 }
576
577 fix->smem_len = var->yres_virtual * fix->line_length;
578
579 return 0;
580}
581
582int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
583 struct fb_var_screeninfo *var)
584{
585 int i;
586
587 for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
588 struct omapfb_colormode *mode = &omapfb_colormodes[i];
589 if (dssmode == mode->dssmode) {
590 assign_colormode_to_var(var, mode);
591 return 0;
592 }
593 }
594 return -ENOENT;
595}
596
597void set_fb_fix(struct fb_info *fbi)
598{
599 struct fb_fix_screeninfo *fix = &fbi->fix;
600 struct fb_var_screeninfo *var = &fbi->var;
601 struct omapfb_info *ofbi = FB2OFB(fbi);
602 struct omapfb2_mem_region *rg = &ofbi->region;
603
604 DBG("set_fb_fix\n");
605
606 /* used by open/write in fbmem.c */
607 fbi->screen_base = (char __iomem *)omapfb_get_region_vaddr(ofbi);
608
609 /* used by mmap in fbmem.c */
610 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
611 switch (var->nonstd) {
612 case OMAPFB_COLOR_YUV422:
613 case OMAPFB_COLOR_YUY422:
614 fix->line_length =
615 (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2;
616 break;
617 default:
618 fix->line_length =
619 (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3;
620 break;
621 }
622
623 fix->smem_len = var->yres_virtual * fix->line_length;
624 } else {
625 fix->line_length =
626 (var->xres_virtual * var->bits_per_pixel) >> 3;
627 fix->smem_len = rg->size;
628 }
629
630 fix->smem_start = omapfb_get_region_paddr(ofbi);
631
632 fix->type = FB_TYPE_PACKED_PIXELS;
633
634 if (var->nonstd)
635 fix->visual = FB_VISUAL_PSEUDOCOLOR;
636 else {
637 switch (var->bits_per_pixel) {
638 case 32:
639 case 24:
640 case 16:
641 case 12:
642 fix->visual = FB_VISUAL_TRUECOLOR;
643 /* 12bpp is stored in 16 bits */
644 break;
645 case 1:
646 case 2:
647 case 4:
648 case 8:
649 fix->visual = FB_VISUAL_PSEUDOCOLOR;
650 break;
651 }
652 }
653
654 fix->accel = FB_ACCEL_NONE;
655
656 fix->xpanstep = 1;
657 fix->ypanstep = 1;
658}
659
660/* check new var and possibly modify it to be ok */
661int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var)
662{
663 struct omapfb_info *ofbi = FB2OFB(fbi);
664 struct omap_dss_device *display = fb2display(fbi);
665 enum omap_color_mode mode = 0;
666 int i;
667 int r;
668
669 DBG("check_fb_var %d\n", ofbi->id);
670
671 if (ofbi->region.size == 0)
672 return 0;
673
674 r = fb_mode_to_dss_mode(var, &mode);
675 if (r) {
676 DBG("cannot convert var to omap dss mode\n");
677 return r;
678 }
679
680 for (i = 0; i < ofbi->num_overlays; ++i) {
681 if ((ofbi->overlays[i]->supported_modes & mode) == 0) {
682 DBG("invalid mode\n");
683 return -EINVAL;
684 }
685 }
686
687 if (var->rotate < 0 || var->rotate > 3)
688 return -EINVAL;
689
690 if (check_fb_res_bounds(var))
691 return -EINVAL;
692
693 if (check_fb_size(ofbi, var))
694 return -EINVAL;
695
696 if (var->xres + var->xoffset > var->xres_virtual)
697 var->xoffset = var->xres_virtual - var->xres;
698 if (var->yres + var->yoffset > var->yres_virtual)
699 var->yoffset = var->yres_virtual - var->yres;
700
701 DBG("xres = %d, yres = %d, vxres = %d, vyres = %d\n",
702 var->xres, var->yres,
703 var->xres_virtual, var->yres_virtual);
704
705 var->height = -1;
706 var->width = -1;
707 var->grayscale = 0;
708
709 if (display && display->driver->get_timings) {
710 struct omap_video_timings timings;
711 display->driver->get_timings(display, &timings);
712
713 /* pixclock in ps, the rest in pixclock */
714 var->pixclock = timings.pixel_clock != 0 ?
715 KHZ2PICOS(timings.pixel_clock) :
716 0;
717 var->left_margin = timings.hfp;
718 var->right_margin = timings.hbp;
719 var->upper_margin = timings.vfp;
720 var->lower_margin = timings.vbp;
721 var->hsync_len = timings.hsw;
722 var->vsync_len = timings.vsw;
723 } else {
724 var->pixclock = 0;
725 var->left_margin = 0;
726 var->right_margin = 0;
727 var->upper_margin = 0;
728 var->lower_margin = 0;
729 var->hsync_len = 0;
730 var->vsync_len = 0;
731 }
732
733 /* TODO: get these from panel->config */
734 var->vmode = FB_VMODE_NONINTERLACED;
735 var->sync = 0;
736
737 return 0;
738}
739
740/*
741 * ---------------------------------------------------------------------------
742 * fbdev framework callbacks
743 * ---------------------------------------------------------------------------
744 */
745static int omapfb_open(struct fb_info *fbi, int user)
746{
747 return 0;
748}
749
750static int omapfb_release(struct fb_info *fbi, int user)
751{
752#if 0
753 struct omapfb_info *ofbi = FB2OFB(fbi);
754 struct omapfb2_device *fbdev = ofbi->fbdev;
755 struct omap_dss_device *display = fb2display(fbi);
756
757 DBG("Closing fb with plane index %d\n", ofbi->id);
758
759 omapfb_lock(fbdev);
760
761 if (display && display->get_update_mode && display->update) {
762 /* XXX this update should be removed, I think. But it's
763 * good for debugging */
764 if (display->get_update_mode(display) ==
765 OMAP_DSS_UPDATE_MANUAL) {
766 u16 w, h;
767
768 if (display->sync)
769 display->sync(display);
770
771 display->get_resolution(display, &w, &h);
772 display->update(display, 0, 0, w, h);
773 }
774 }
775
776 if (display && display->sync)
777 display->sync(display);
778
779 omapfb_unlock(fbdev);
780#endif
781 return 0;
782}
783
784static unsigned calc_rotation_offset_dma(const struct fb_var_screeninfo *var,
785 const struct fb_fix_screeninfo *fix, int rotation)
786{
787 unsigned offset;
788
789 offset = var->yoffset * fix->line_length +
790 var->xoffset * (var->bits_per_pixel >> 3);
791
792 return offset;
793}
794
795static unsigned calc_rotation_offset_vrfb(const struct fb_var_screeninfo *var,
796 const struct fb_fix_screeninfo *fix, int rotation)
797{
798 unsigned offset;
799
800 if (rotation == FB_ROTATE_UD)
801 offset = (var->yres_virtual - var->yres) *
802 fix->line_length;
803 else if (rotation == FB_ROTATE_CW)
804 offset = (var->yres_virtual - var->yres) *
805 (var->bits_per_pixel >> 3);
806 else
807 offset = 0;
808
809 if (rotation == FB_ROTATE_UR)
810 offset += var->yoffset * fix->line_length +
811 var->xoffset * (var->bits_per_pixel >> 3);
812 else if (rotation == FB_ROTATE_UD)
813 offset -= var->yoffset * fix->line_length +
814 var->xoffset * (var->bits_per_pixel >> 3);
815 else if (rotation == FB_ROTATE_CW)
816 offset -= var->xoffset * fix->line_length +
817 var->yoffset * (var->bits_per_pixel >> 3);
818 else if (rotation == FB_ROTATE_CCW)
819 offset += var->xoffset * fix->line_length +
820 var->yoffset * (var->bits_per_pixel >> 3);
821
822 return offset;
823}
824
825
826/* setup overlay according to the fb */
827static int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
828 u16 posx, u16 posy, u16 outw, u16 outh)
829{
830 int r = 0;
831 struct omapfb_info *ofbi = FB2OFB(fbi);
832 struct fb_var_screeninfo *var = &fbi->var;
833 struct fb_fix_screeninfo *fix = &fbi->fix;
834 enum omap_color_mode mode = 0;
835 int offset;
836 u32 data_start_p;
837 void __iomem *data_start_v;
838 struct omap_overlay_info info;
839 int xres, yres;
840 int screen_width;
841 int mirror;
842 int rotation = var->rotate;
843 int i;
844
845 for (i = 0; i < ofbi->num_overlays; i++) {
846 if (ovl != ofbi->overlays[i])
847 continue;
848
849 rotation = (rotation + ofbi->rotation[i]) % 4;
850 break;
851 }
852
853 DBG("setup_overlay %d, posx %d, posy %d, outw %d, outh %d\n", ofbi->id,
854 posx, posy, outw, outh);
855
856 if (rotation == FB_ROTATE_CW || rotation == FB_ROTATE_CCW) {
857 xres = var->yres;
858 yres = var->xres;
859 } else {
860 xres = var->xres;
861 yres = var->yres;
862 }
863
864
865 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
866 data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation);
867 data_start_v = NULL;
868 } else {
869 data_start_p = omapfb_get_region_paddr(ofbi);
870 data_start_v = omapfb_get_region_vaddr(ofbi);
871 }
872
873 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
874 offset = calc_rotation_offset_vrfb(var, fix, rotation);
875 else
876 offset = calc_rotation_offset_dma(var, fix, rotation);
877
878 data_start_p += offset;
879 data_start_v += offset;
880
881 if (offset)
882 DBG("offset %d, %d = %d\n",
883 var->xoffset, var->yoffset, offset);
884
885 DBG("paddr %x, vaddr %p\n", data_start_p, data_start_v);
886
887 r = fb_mode_to_dss_mode(var, &mode);
888 if (r) {
889 DBG("fb_mode_to_dss_mode failed");
890 goto err;
891 }
892
893 switch (var->nonstd) {
894 case OMAPFB_COLOR_YUV422:
895 case OMAPFB_COLOR_YUY422:
896 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
897 screen_width = fix->line_length
898 / (var->bits_per_pixel >> 2);
899 break;
900 }
901 default:
902 screen_width = fix->line_length / (var->bits_per_pixel >> 3);
903 break;
904 }
905
906 ovl->get_overlay_info(ovl, &info);
907
908 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
909 mirror = 0;
910 else
911 mirror = ofbi->mirror;
912
913 info.paddr = data_start_p;
914 info.vaddr = data_start_v;
915 info.screen_width = screen_width;
916 info.width = xres;
917 info.height = yres;
918 info.color_mode = mode;
919 info.rotation_type = ofbi->rotation_type;
920 info.rotation = rotation;
921 info.mirror = mirror;
922
923 info.pos_x = posx;
924 info.pos_y = posy;
925 info.out_width = outw;
926 info.out_height = outh;
927
928 r = ovl->set_overlay_info(ovl, &info);
929 if (r) {
930 DBG("ovl->setup_overlay_info failed\n");
931 goto err;
932 }
933
934 return 0;
935
936err:
937 DBG("setup_overlay failed\n");
938 return r;
939}
940
941/* apply var to the overlay */
942int omapfb_apply_changes(struct fb_info *fbi, int init)
943{
944 int r = 0;
945 struct omapfb_info *ofbi = FB2OFB(fbi);
946 struct fb_var_screeninfo *var = &fbi->var;
947 struct omap_overlay *ovl;
948 u16 posx, posy;
949 u16 outw, outh;
950 int i;
951
952#ifdef DEBUG
953 if (omapfb_test_pattern)
954 fill_fb(fbi);
955#endif
956
957 for (i = 0; i < ofbi->num_overlays; i++) {
958 ovl = ofbi->overlays[i];
959
960 DBG("apply_changes, fb %d, ovl %d\n", ofbi->id, ovl->id);
961
962 if (ofbi->region.size == 0) {
963 /* the fb is not available. disable the overlay */
964 omapfb_overlay_enable(ovl, 0);
965 if (!init && ovl->manager)
966 ovl->manager->apply(ovl->manager);
967 continue;
968 }
969
970 if (init || (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
971 int rotation = (var->rotate + ofbi->rotation[i]) % 4;
972 if (rotation == FB_ROTATE_CW ||
973 rotation == FB_ROTATE_CCW) {
974 outw = var->yres;
975 outh = var->xres;
976 } else {
977 outw = var->xres;
978 outh = var->yres;
979 }
980 } else {
981 outw = ovl->info.out_width;
982 outh = ovl->info.out_height;
983 }
984
985 if (init) {
986 posx = 0;
987 posy = 0;
988 } else {
989 posx = ovl->info.pos_x;
990 posy = ovl->info.pos_y;
991 }
992
993 r = omapfb_setup_overlay(fbi, ovl, posx, posy, outw, outh);
994 if (r)
995 goto err;
996
997 if (!init && ovl->manager)
998 ovl->manager->apply(ovl->manager);
999 }
1000 return 0;
1001err:
1002 DBG("apply_changes failed\n");
1003 return r;
1004}
1005
1006/* checks var and eventually tweaks it to something supported,
1007 * DO NOT MODIFY PAR */
1008static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
1009{
1010 int r;
1011
1012 DBG("check_var(%d)\n", FB2OFB(fbi)->id);
1013
1014 r = check_fb_var(fbi, var);
1015
1016 return r;
1017}
1018
1019/* set the video mode according to info->var */
1020static int omapfb_set_par(struct fb_info *fbi)
1021{
1022 int r;
1023
1024 DBG("set_par(%d)\n", FB2OFB(fbi)->id);
1025
1026 set_fb_fix(fbi);
1027
1028 r = setup_vrfb_rotation(fbi);
1029 if (r)
1030 return r;
1031
1032 r = omapfb_apply_changes(fbi, 0);
1033
1034 return r;
1035}
1036
1037static int omapfb_pan_display(struct fb_var_screeninfo *var,
1038 struct fb_info *fbi)
1039{
1040 struct fb_var_screeninfo new_var;
1041 int r;
1042
1043 DBG("pan_display(%d)\n", FB2OFB(fbi)->id);
1044
1045 if (var->xoffset == fbi->var.xoffset &&
1046 var->yoffset == fbi->var.yoffset)
1047 return 0;
1048
1049 new_var = fbi->var;
1050 new_var.xoffset = var->xoffset;
1051 new_var.yoffset = var->yoffset;
1052
1053 fbi->var = new_var;
1054
1055 r = omapfb_apply_changes(fbi, 0);
1056
1057 return r;
1058}
1059
1060static void mmap_user_open(struct vm_area_struct *vma)
1061{
1062 struct omapfb_info *ofbi = (struct omapfb_info *)vma->vm_private_data;
1063
1064 atomic_inc(&ofbi->map_count);
1065}
1066
1067static void mmap_user_close(struct vm_area_struct *vma)
1068{
1069 struct omapfb_info *ofbi = (struct omapfb_info *)vma->vm_private_data;
1070
1071 atomic_dec(&ofbi->map_count);
1072}
1073
1074static struct vm_operations_struct mmap_user_ops = {
1075 .open = mmap_user_open,
1076 .close = mmap_user_close,
1077};
1078
1079static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
1080{
1081 struct omapfb_info *ofbi = FB2OFB(fbi);
1082 struct fb_fix_screeninfo *fix = &fbi->fix;
1083 unsigned long off;
1084 unsigned long start;
1085 u32 len;
1086
1087 if (vma->vm_end - vma->vm_start == 0)
1088 return 0;
1089 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1090 return -EINVAL;
1091 off = vma->vm_pgoff << PAGE_SHIFT;
1092
1093 start = omapfb_get_region_paddr(ofbi);
1094 len = fix->smem_len;
1095 if (off >= len)
1096 return -EINVAL;
1097 if ((vma->vm_end - vma->vm_start + off) > len)
1098 return -EINVAL;
1099
1100 off += start;
1101
1102 DBG("user mmap region start %lx, len %d, off %lx\n", start, len, off);
1103
1104 vma->vm_pgoff = off >> PAGE_SHIFT;
1105 vma->vm_flags |= VM_IO | VM_RESERVED;
1106 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1107 vma->vm_ops = &mmap_user_ops;
1108 vma->vm_private_data = ofbi;
1109 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1110 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1111 return -EAGAIN;
1112 /* vm_ops.open won't be called for mmap itself. */
1113 atomic_inc(&ofbi->map_count);
1114 return 0;
1115}
1116
1117/* Store a single color palette entry into a pseudo palette or the hardware
1118 * palette if one is available. For now we support only 16bpp and thus store
1119 * the entry only to the pseudo palette.
1120 */
1121static int _setcolreg(struct fb_info *fbi, u_int regno, u_int red, u_int green,
1122 u_int blue, u_int transp, int update_hw_pal)
1123{
1124 /*struct omapfb_info *ofbi = FB2OFB(fbi);*/
1125 /*struct omapfb2_device *fbdev = ofbi->fbdev;*/
1126 struct fb_var_screeninfo *var = &fbi->var;
1127 int r = 0;
1128
1129 enum omapfb_color_format mode = OMAPFB_COLOR_RGB24U; /* XXX */
1130
1131 /*switch (plane->color_mode) {*/
1132 switch (mode) {
1133 case OMAPFB_COLOR_YUV422:
1134 case OMAPFB_COLOR_YUV420:
1135 case OMAPFB_COLOR_YUY422:
1136 r = -EINVAL;
1137 break;
1138 case OMAPFB_COLOR_CLUT_8BPP:
1139 case OMAPFB_COLOR_CLUT_4BPP:
1140 case OMAPFB_COLOR_CLUT_2BPP:
1141 case OMAPFB_COLOR_CLUT_1BPP:
1142 /*
1143 if (fbdev->ctrl->setcolreg)
1144 r = fbdev->ctrl->setcolreg(regno, red, green, blue,
1145 transp, update_hw_pal);
1146 */
1147 /* Fallthrough */
1148 r = -EINVAL;
1149 break;
1150 case OMAPFB_COLOR_RGB565:
1151 case OMAPFB_COLOR_RGB444:
1152 case OMAPFB_COLOR_RGB24P:
1153 case OMAPFB_COLOR_RGB24U:
1154 if (r != 0)
1155 break;
1156
1157 if (regno < 0) {
1158 r = -EINVAL;
1159 break;
1160 }
1161
1162 if (regno < 16) {
1163 u16 pal;
1164 pal = ((red >> (16 - var->red.length)) <<
1165 var->red.offset) |
1166 ((green >> (16 - var->green.length)) <<
1167 var->green.offset) |
1168 (blue >> (16 - var->blue.length));
1169 ((u32 *)(fbi->pseudo_palette))[regno] = pal;
1170 }
1171 break;
1172 default:
1173 BUG();
1174 }
1175 return r;
1176}
1177
1178static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
1179 u_int transp, struct fb_info *info)
1180{
1181 DBG("setcolreg\n");
1182
1183 return _setcolreg(info, regno, red, green, blue, transp, 1);
1184}
1185
1186static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1187{
1188 int count, index, r;
1189 u16 *red, *green, *blue, *transp;
1190 u16 trans = 0xffff;
1191
1192 DBG("setcmap\n");
1193
1194 red = cmap->red;
1195 green = cmap->green;
1196 blue = cmap->blue;
1197 transp = cmap->transp;
1198 index = cmap->start;
1199
1200 for (count = 0; count < cmap->len; count++) {
1201 if (transp)
1202 trans = *transp++;
1203 r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
1204 count == cmap->len - 1);
1205 if (r != 0)
1206 return r;
1207 }
1208
1209 return 0;
1210}
1211
1212static int omapfb_blank(int blank, struct fb_info *fbi)
1213{
1214 struct omapfb_info *ofbi = FB2OFB(fbi);
1215 struct omapfb2_device *fbdev = ofbi->fbdev;
1216 struct omap_dss_device *display = fb2display(fbi);
1217 int do_update = 0;
1218 int r = 0;
1219
1220 omapfb_lock(fbdev);
1221
1222 switch (blank) {
1223 case FB_BLANK_UNBLANK:
1224 if (display->state != OMAP_DSS_DISPLAY_SUSPENDED)
1225 goto exit;
1226
1227 if (display->driver->resume)
1228 r = display->driver->resume(display);
1229
1230 if (r == 0 && display->driver->get_update_mode &&
1231 display->driver->get_update_mode(display) ==
1232 OMAP_DSS_UPDATE_MANUAL)
1233 do_update = 1;
1234
1235 break;
1236
1237 case FB_BLANK_NORMAL:
1238 /* FB_BLANK_NORMAL could be implemented.
1239 * Needs DSS additions. */
1240 case FB_BLANK_VSYNC_SUSPEND:
1241 case FB_BLANK_HSYNC_SUSPEND:
1242 case FB_BLANK_POWERDOWN:
1243 if (display->state != OMAP_DSS_DISPLAY_ACTIVE)
1244 goto exit;
1245
1246 if (display->driver->suspend)
1247 r = display->driver->suspend(display);
1248
1249 break;
1250
1251 default:
1252 r = -EINVAL;
1253 }
1254
1255exit:
1256 omapfb_unlock(fbdev);
1257
1258 if (r == 0 && do_update && display->driver->update) {
1259 u16 w, h;
1260 display->driver->get_resolution(display, &w, &h);
1261
1262 r = display->driver->update(display, 0, 0, w, h);
1263 }
1264
1265 return r;
1266}
1267
1268#if 0
1269/* XXX fb_read and fb_write are needed for VRFB */
1270ssize_t omapfb_write(struct fb_info *info, const char __user *buf,
1271 size_t count, loff_t *ppos)
1272{
1273 DBG("omapfb_write %d, %lu\n", count, (unsigned long)*ppos);
1274 /* XXX needed for VRFB */
1275 return count;
1276}
1277#endif
1278
1279static struct fb_ops omapfb_ops = {
1280 .owner = THIS_MODULE,
1281 .fb_open = omapfb_open,
1282 .fb_release = omapfb_release,
1283 .fb_fillrect = cfb_fillrect,
1284 .fb_copyarea = cfb_copyarea,
1285 .fb_imageblit = cfb_imageblit,
1286 .fb_blank = omapfb_blank,
1287 .fb_ioctl = omapfb_ioctl,
1288 .fb_check_var = omapfb_check_var,
1289 .fb_set_par = omapfb_set_par,
1290 .fb_pan_display = omapfb_pan_display,
1291 .fb_mmap = omapfb_mmap,
1292 .fb_setcolreg = omapfb_setcolreg,
1293 .fb_setcmap = omapfb_setcmap,
1294 /*.fb_write = omapfb_write,*/
1295};
1296
1297static void omapfb_free_fbmem(struct fb_info *fbi)
1298{
1299 struct omapfb_info *ofbi = FB2OFB(fbi);
1300 struct omapfb2_device *fbdev = ofbi->fbdev;
1301 struct omapfb2_mem_region *rg;
1302
1303 rg = &ofbi->region;
1304
1305 if (rg->paddr)
1306 if (omap_vram_free(rg->paddr, rg->size))
1307 dev_err(fbdev->dev, "VRAM FREE failed\n");
1308
1309 if (rg->vaddr)
1310 iounmap(rg->vaddr);
1311
1312 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
1313 /* unmap the 0 angle rotation */
1314 if (rg->vrfb.vaddr[0]) {
1315 iounmap(rg->vrfb.vaddr[0]);
1316 omap_vrfb_release_ctx(&rg->vrfb);
1317 rg->vrfb.vaddr[0] = NULL;
1318 }
1319 }
1320
1321 rg->vaddr = NULL;
1322 rg->paddr = 0;
1323 rg->alloc = 0;
1324 rg->size = 0;
1325}
1326
1327static void clear_fb_info(struct fb_info *fbi)
1328{
1329 memset(&fbi->var, 0, sizeof(fbi->var));
1330 memset(&fbi->fix, 0, sizeof(fbi->fix));
1331 strlcpy(fbi->fix.id, MODULE_NAME, sizeof(fbi->fix.id));
1332}
1333
1334static int omapfb_free_all_fbmem(struct omapfb2_device *fbdev)
1335{
1336 int i;
1337
1338 DBG("free all fbmem\n");
1339
1340 for (i = 0; i < fbdev->num_fbs; i++) {
1341 struct fb_info *fbi = fbdev->fbs[i];
1342 omapfb_free_fbmem(fbi);
1343 clear_fb_info(fbi);
1344 }
1345
1346 return 0;
1347}
1348
1349static int omapfb_alloc_fbmem(struct fb_info *fbi, unsigned long size,
1350 unsigned long paddr)
1351{
1352 struct omapfb_info *ofbi = FB2OFB(fbi);
1353 struct omapfb2_device *fbdev = ofbi->fbdev;
1354 struct omapfb2_mem_region *rg;
1355 void __iomem *vaddr;
1356 int r;
1357
1358 rg = &ofbi->region;
1359 memset(rg, 0, sizeof(*rg));
1360
1361 size = PAGE_ALIGN(size);
1362
1363 if (!paddr) {
1364 DBG("allocating %lu bytes for fb %d\n", size, ofbi->id);
1365 r = omap_vram_alloc(OMAP_VRAM_MEMTYPE_SDRAM, size, &paddr);
1366 } else {
1367 DBG("reserving %lu bytes at %lx for fb %d\n", size, paddr,
1368 ofbi->id);
1369 r = omap_vram_reserve(paddr, size);
1370 }
1371
1372 if (r) {
1373 dev_err(fbdev->dev, "failed to allocate framebuffer\n");
1374 return -ENOMEM;
1375 }
1376
1377 if (ofbi->rotation_type != OMAP_DSS_ROT_VRFB) {
1378 vaddr = ioremap_wc(paddr, size);
1379
1380 if (!vaddr) {
1381 dev_err(fbdev->dev, "failed to ioremap framebuffer\n");
1382 omap_vram_free(paddr, size);
1383 return -ENOMEM;
1384 }
1385
1386 DBG("allocated VRAM paddr %lx, vaddr %p\n", paddr, vaddr);
1387 } else {
1388 r = omap_vrfb_request_ctx(&rg->vrfb);
1389 if (r) {
1390 dev_err(fbdev->dev, "vrfb create ctx failed\n");
1391 return r;
1392 }
1393
1394 vaddr = NULL;
1395 }
1396
1397 rg->paddr = paddr;
1398 rg->vaddr = vaddr;
1399 rg->size = size;
1400 rg->alloc = 1;
1401
1402 return 0;
1403}
1404
1405/* allocate fbmem using display resolution as reference */
1406static int omapfb_alloc_fbmem_display(struct fb_info *fbi, unsigned long size,
1407 unsigned long paddr)
1408{
1409 struct omapfb_info *ofbi = FB2OFB(fbi);
1410 struct omapfb2_device *fbdev = ofbi->fbdev;
1411 struct omap_dss_device *display;
1412 int bytespp;
1413
1414 display = fb2display(fbi);
1415
1416 if (!display)
1417 return 0;
1418
1419 switch (omapfb_get_recommended_bpp(fbdev, display)) {
1420 case 16:
1421 bytespp = 2;
1422 break;
1423 case 24:
1424 bytespp = 4;
1425 break;
1426 default:
1427 bytespp = 4;
1428 break;
1429 }
1430
1431 if (!size) {
1432 u16 w, h;
1433
1434 display->driver->get_resolution(display, &w, &h);
1435
1436 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
1437 size = max(omap_vrfb_min_phys_size(w, h, bytespp),
1438 omap_vrfb_min_phys_size(h, w, bytespp));
1439
1440 DBG("adjusting fb mem size for VRFB, %u -> %lu\n",
1441 w * h * bytespp, size);
1442 } else {
1443 size = w * h * bytespp;
1444 }
1445 }
1446
1447 if (!size)
1448 return 0;
1449
1450 return omapfb_alloc_fbmem(fbi, size, paddr);
1451}
1452
1453static enum omap_color_mode fb_format_to_dss_mode(enum omapfb_color_format fmt)
1454{
1455 enum omap_color_mode mode;
1456
1457 switch (fmt) {
1458 case OMAPFB_COLOR_RGB565:
1459 mode = OMAP_DSS_COLOR_RGB16;
1460 break;
1461 case OMAPFB_COLOR_YUV422:
1462 mode = OMAP_DSS_COLOR_YUV2;
1463 break;
1464 case OMAPFB_COLOR_CLUT_8BPP:
1465 mode = OMAP_DSS_COLOR_CLUT8;
1466 break;
1467 case OMAPFB_COLOR_CLUT_4BPP:
1468 mode = OMAP_DSS_COLOR_CLUT4;
1469 break;
1470 case OMAPFB_COLOR_CLUT_2BPP:
1471 mode = OMAP_DSS_COLOR_CLUT2;
1472 break;
1473 case OMAPFB_COLOR_CLUT_1BPP:
1474 mode = OMAP_DSS_COLOR_CLUT1;
1475 break;
1476 case OMAPFB_COLOR_RGB444:
1477 mode = OMAP_DSS_COLOR_RGB12U;
1478 break;
1479 case OMAPFB_COLOR_YUY422:
1480 mode = OMAP_DSS_COLOR_UYVY;
1481 break;
1482 case OMAPFB_COLOR_ARGB16:
1483 mode = OMAP_DSS_COLOR_ARGB16;
1484 break;
1485 case OMAPFB_COLOR_RGB24U:
1486 mode = OMAP_DSS_COLOR_RGB24U;
1487 break;
1488 case OMAPFB_COLOR_RGB24P:
1489 mode = OMAP_DSS_COLOR_RGB24P;
1490 break;
1491 case OMAPFB_COLOR_ARGB32:
1492 mode = OMAP_DSS_COLOR_ARGB32;
1493 break;
1494 case OMAPFB_COLOR_RGBA32:
1495 mode = OMAP_DSS_COLOR_RGBA32;
1496 break;
1497 case OMAPFB_COLOR_RGBX32:
1498 mode = OMAP_DSS_COLOR_RGBX32;
1499 break;
1500 default:
1501 mode = -EINVAL;
1502 }
1503
1504 return mode;
1505}
1506
1507static int omapfb_parse_vram_param(const char *param, int max_entries,
1508 unsigned long *sizes, unsigned long *paddrs)
1509{
1510 int fbnum;
1511 unsigned long size;
1512 unsigned long paddr = 0;
1513 char *p, *start;
1514
1515 start = (char *)param;
1516
1517 while (1) {
1518 p = start;
1519
1520 fbnum = simple_strtoul(p, &p, 10);
1521
1522 if (p == param)
1523 return -EINVAL;
1524
1525 if (*p != ':')
1526 return -EINVAL;
1527
1528 if (fbnum >= max_entries)
1529 return -EINVAL;
1530
1531 size = memparse(p + 1, &p);
1532
1533 if (!size)
1534 return -EINVAL;
1535
1536 paddr = 0;
1537
1538 if (*p == '@') {
1539 paddr = simple_strtoul(p + 1, &p, 16);
1540
1541 if (!paddr)
1542 return -EINVAL;
1543
1544 }
1545
1546 paddrs[fbnum] = paddr;
1547 sizes[fbnum] = size;
1548
1549 if (*p == 0)
1550 break;
1551
1552 if (*p != ',')
1553 return -EINVAL;
1554
1555 ++p;
1556
1557 start = p;
1558 }
1559
1560 return 0;
1561}
1562
1563static int omapfb_allocate_all_fbs(struct omapfb2_device *fbdev)
1564{
1565 int i, r;
1566 unsigned long vram_sizes[10];
1567 unsigned long vram_paddrs[10];
1568
1569 memset(&vram_sizes, 0, sizeof(vram_sizes));
1570 memset(&vram_paddrs, 0, sizeof(vram_paddrs));
1571
1572 if (def_vram && omapfb_parse_vram_param(def_vram, 10,
1573 vram_sizes, vram_paddrs)) {
1574 dev_err(fbdev->dev, "failed to parse vram parameter\n");
1575
1576 memset(&vram_sizes, 0, sizeof(vram_sizes));
1577 memset(&vram_paddrs, 0, sizeof(vram_paddrs));
1578 }
1579
1580 if (fbdev->dev->platform_data) {
1581 struct omapfb_platform_data *opd;
1582 opd = fbdev->dev->platform_data;
1583 for (i = 0; i < opd->mem_desc.region_cnt; ++i) {
1584 if (!vram_sizes[i]) {
1585 unsigned long size;
1586 unsigned long paddr;
1587
1588 size = opd->mem_desc.region[i].size;
1589 paddr = opd->mem_desc.region[i].paddr;
1590
1591 vram_sizes[i] = size;
1592 vram_paddrs[i] = paddr;
1593 }
1594 }
1595 }
1596
1597 for (i = 0; i < fbdev->num_fbs; i++) {
1598 /* allocate memory automatically only for fb0, or if
1599 * excplicitly defined with vram or plat data option */
1600 if (i == 0 || vram_sizes[i] != 0) {
1601 r = omapfb_alloc_fbmem_display(fbdev->fbs[i],
1602 vram_sizes[i], vram_paddrs[i]);
1603
1604 if (r)
1605 return r;
1606 }
1607 }
1608
1609 for (i = 0; i < fbdev->num_fbs; i++) {
1610 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
1611 struct omapfb2_mem_region *rg;
1612 rg = &ofbi->region;
1613
1614 DBG("region%d phys %08x virt %p size=%lu\n",
1615 i,
1616 rg->paddr,
1617 rg->vaddr,
1618 rg->size);
1619 }
1620
1621 return 0;
1622}
1623
1624int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type)
1625{
1626 struct omapfb_info *ofbi = FB2OFB(fbi);
1627 struct omapfb2_device *fbdev = ofbi->fbdev;
1628 struct omap_dss_device *display = fb2display(fbi);
1629 struct omapfb2_mem_region *rg = &ofbi->region;
1630 unsigned long old_size = rg->size;
1631 unsigned long old_paddr = rg->paddr;
1632 int old_type = rg->type;
1633 int r;
1634
1635 if (type > OMAPFB_MEMTYPE_MAX)
1636 return -EINVAL;
1637
1638 size = PAGE_ALIGN(size);
1639
1640 if (old_size == size && old_type == type)
1641 return 0;
1642
1643 if (display && display->driver->sync)
1644 display->driver->sync(display);
1645
1646 omapfb_free_fbmem(fbi);
1647
1648 if (size == 0) {
1649 clear_fb_info(fbi);
1650 return 0;
1651 }
1652
1653 r = omapfb_alloc_fbmem(fbi, size, 0);
1654
1655 if (r) {
1656 if (old_size)
1657 omapfb_alloc_fbmem(fbi, old_size, old_paddr);
1658
1659 if (rg->size == 0)
1660 clear_fb_info(fbi);
1661
1662 return r;
1663 }
1664
1665 if (old_size == size)
1666 return 0;
1667
1668 if (old_size == 0) {
1669 DBG("initializing fb %d\n", ofbi->id);
1670 r = omapfb_fb_init(fbdev, fbi);
1671 if (r) {
1672 DBG("omapfb_fb_init failed\n");
1673 goto err;
1674 }
1675 r = omapfb_apply_changes(fbi, 1);
1676 if (r) {
1677 DBG("omapfb_apply_changes failed\n");
1678 goto err;
1679 }
1680 } else {
1681 struct fb_var_screeninfo new_var;
1682 memcpy(&new_var, &fbi->var, sizeof(new_var));
1683 r = check_fb_var(fbi, &new_var);
1684 if (r)
1685 goto err;
1686 memcpy(&fbi->var, &new_var, sizeof(fbi->var));
1687 set_fb_fix(fbi);
1688 r = setup_vrfb_rotation(fbi);
1689 if (r)
1690 goto err;
1691 }
1692
1693 return 0;
1694err:
1695 omapfb_free_fbmem(fbi);
1696 clear_fb_info(fbi);
1697 return r;
1698}
1699
1700/* initialize fb_info, var, fix to something sane based on the display */
1701static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi)
1702{
1703 struct fb_var_screeninfo *var = &fbi->var;
1704 struct omap_dss_device *display = fb2display(fbi);
1705 struct omapfb_info *ofbi = FB2OFB(fbi);
1706 int r = 0;
1707
1708 fbi->fbops = &omapfb_ops;
1709 fbi->flags = FBINFO_FLAG_DEFAULT;
1710 fbi->pseudo_palette = fbdev->pseudo_palette;
1711
1712 if (ofbi->region.size == 0) {
1713 clear_fb_info(fbi);
1714 return 0;
1715 }
1716
1717 var->nonstd = 0;
1718 var->bits_per_pixel = 0;
1719
1720 var->rotate = def_rotate;
1721
1722 /*
1723 * Check if there is a default color format set in the board file,
1724 * and use this format instead the default deducted from the
1725 * display bpp.
1726 */
1727 if (fbdev->dev->platform_data) {
1728 struct omapfb_platform_data *opd;
1729 int id = ofbi->id;
1730
1731 opd = fbdev->dev->platform_data;
1732 if (opd->mem_desc.region[id].format_used) {
1733 enum omap_color_mode mode;
1734 enum omapfb_color_format format;
1735
1736 format = opd->mem_desc.region[id].format;
1737 mode = fb_format_to_dss_mode(format);
1738 if (mode < 0) {
1739 r = mode;
1740 goto err;
1741 }
1742 r = dss_mode_to_fb_mode(mode, var);
1743 if (r < 0)
1744 goto err;
1745 }
1746 }
1747
1748 if (display) {
1749 u16 w, h;
1750 int rotation = (var->rotate + ofbi->rotation[0]) % 4;
1751
1752 display->driver->get_resolution(display, &w, &h);
1753
1754 if (rotation == FB_ROTATE_CW ||
1755 rotation == FB_ROTATE_CCW) {
1756 var->xres = h;
1757 var->yres = w;
1758 } else {
1759 var->xres = w;
1760 var->yres = h;
1761 }
1762
1763 var->xres_virtual = var->xres;
1764 var->yres_virtual = var->yres;
1765
1766 if (!var->bits_per_pixel) {
1767 switch (omapfb_get_recommended_bpp(fbdev, display)) {
1768 case 16:
1769 var->bits_per_pixel = 16;
1770 break;
1771 case 24:
1772 var->bits_per_pixel = 32;
1773 break;
1774 default:
1775 dev_err(fbdev->dev, "illegal display "
1776 "bpp\n");
1777 return -EINVAL;
1778 }
1779 }
1780 } else {
1781 /* if there's no display, let's just guess some basic values */
1782 var->xres = 320;
1783 var->yres = 240;
1784 var->xres_virtual = var->xres;
1785 var->yres_virtual = var->yres;
1786 if (!var->bits_per_pixel)
1787 var->bits_per_pixel = 16;
1788 }
1789
1790 r = check_fb_var(fbi, var);
1791 if (r)
1792 goto err;
1793
1794 set_fb_fix(fbi);
1795 r = setup_vrfb_rotation(fbi);
1796 if (r)
1797 goto err;
1798
1799 r = fb_alloc_cmap(&fbi->cmap, 256, 0);
1800 if (r)
1801 dev_err(fbdev->dev, "unable to allocate color map memory\n");
1802
1803err:
1804 return r;
1805}
1806
1807static void fbinfo_cleanup(struct omapfb2_device *fbdev, struct fb_info *fbi)
1808{
1809 fb_dealloc_cmap(&fbi->cmap);
1810}
1811
1812
1813static void omapfb_free_resources(struct omapfb2_device *fbdev)
1814{
1815 int i;
1816
1817 DBG("free_resources\n");
1818
1819 if (fbdev == NULL)
1820 return;
1821
1822 for (i = 0; i < fbdev->num_fbs; i++)
1823 unregister_framebuffer(fbdev->fbs[i]);
1824
1825 /* free the reserved fbmem */
1826 omapfb_free_all_fbmem(fbdev);
1827
1828 for (i = 0; i < fbdev->num_fbs; i++) {
1829 fbinfo_cleanup(fbdev, fbdev->fbs[i]);
1830 framebuffer_release(fbdev->fbs[i]);
1831 }
1832
1833 for (i = 0; i < fbdev->num_displays; i++) {
1834 if (fbdev->displays[i]->state != OMAP_DSS_DISPLAY_DISABLED)
1835 fbdev->displays[i]->driver->disable(fbdev->displays[i]);
1836
1837 omap_dss_put_device(fbdev->displays[i]);
1838 }
1839
1840 dev_set_drvdata(fbdev->dev, NULL);
1841 kfree(fbdev);
1842}
1843
1844static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
1845{
1846 int r, i;
1847
1848 fbdev->num_fbs = 0;
1849
1850 DBG("create %d framebuffers\n", CONFIG_FB_OMAP2_NUM_FBS);
1851
1852 /* allocate fb_infos */
1853 for (i = 0; i < CONFIG_FB_OMAP2_NUM_FBS; i++) {
1854 struct fb_info *fbi;
1855 struct omapfb_info *ofbi;
1856
1857 fbi = framebuffer_alloc(sizeof(struct omapfb_info),
1858 fbdev->dev);
1859
1860 if (fbi == NULL) {
1861 dev_err(fbdev->dev,
1862 "unable to allocate memory for plane info\n");
1863 return -ENOMEM;
1864 }
1865
1866 clear_fb_info(fbi);
1867
1868 fbdev->fbs[i] = fbi;
1869
1870 ofbi = FB2OFB(fbi);
1871 ofbi->fbdev = fbdev;
1872 ofbi->id = i;
1873
1874 /* assign these early, so that fb alloc can use them */
1875 ofbi->rotation_type = def_vrfb ? OMAP_DSS_ROT_VRFB :
1876 OMAP_DSS_ROT_DMA;
1877 ofbi->mirror = def_mirror;
1878
1879 fbdev->num_fbs++;
1880 }
1881
1882 DBG("fb_infos allocated\n");
1883
1884 /* assign overlays for the fbs */
1885 for (i = 0; i < min(fbdev->num_fbs, fbdev->num_overlays); i++) {
1886 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
1887
1888 ofbi->overlays[0] = fbdev->overlays[i];
1889 ofbi->num_overlays = 1;
1890 }
1891
1892 /* allocate fb memories */
1893 r = omapfb_allocate_all_fbs(fbdev);
1894 if (r) {
1895 dev_err(fbdev->dev, "failed to allocate fbmem\n");
1896 return r;
1897 }
1898
1899 DBG("fbmems allocated\n");
1900
1901 /* setup fb_infos */
1902 for (i = 0; i < fbdev->num_fbs; i++) {
1903 r = omapfb_fb_init(fbdev, fbdev->fbs[i]);
1904 if (r) {
1905 dev_err(fbdev->dev, "failed to setup fb_info\n");
1906 return r;
1907 }
1908 }
1909
1910 DBG("fb_infos initialized\n");
1911
1912 for (i = 0; i < fbdev->num_fbs; i++) {
1913 r = register_framebuffer(fbdev->fbs[i]);
1914 if (r != 0) {
1915 dev_err(fbdev->dev,
1916 "registering framebuffer %d failed\n", i);
1917 return r;
1918 }
1919 }
1920
1921 DBG("framebuffers registered\n");
1922
1923 for (i = 0; i < fbdev->num_fbs; i++) {
1924 r = omapfb_apply_changes(fbdev->fbs[i], 1);
1925 if (r) {
1926 dev_err(fbdev->dev, "failed to change mode\n");
1927 return r;
1928 }
1929 }
1930
1931 DBG("create sysfs for fbs\n");
1932 r = omapfb_create_sysfs(fbdev);
1933 if (r) {
1934 dev_err(fbdev->dev, "failed to create sysfs entries\n");
1935 return r;
1936 }
1937
1938 /* Enable fb0 */
1939 if (fbdev->num_fbs > 0) {
1940 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[0]);
1941
1942 if (ofbi->num_overlays > 0) {
1943 struct omap_overlay *ovl = ofbi->overlays[0];
1944
1945 r = omapfb_overlay_enable(ovl, 1);
1946
1947 if (r) {
1948 dev_err(fbdev->dev,
1949 "failed to enable overlay\n");
1950 return r;
1951 }
1952 }
1953 }
1954
1955 DBG("create_framebuffers done\n");
1956
1957 return 0;
1958}
1959
1960static int omapfb_mode_to_timings(const char *mode_str,
1961 struct omap_video_timings *timings, u8 *bpp)
1962{
1963 struct fb_info fbi;
1964 struct fb_var_screeninfo var;
1965 struct fb_ops fbops;
1966 int r;
1967
1968#ifdef CONFIG_OMAP2_DSS_VENC
1969 if (strcmp(mode_str, "pal") == 0) {
1970 *timings = omap_dss_pal_timings;
1971 *bpp = 0;
1972 return 0;
1973 } else if (strcmp(mode_str, "ntsc") == 0) {
1974 *timings = omap_dss_ntsc_timings;
1975 *bpp = 0;
1976 return 0;
1977 }
1978#endif
1979
1980 /* this is quite a hack, but I wanted to use the modedb and for
1981 * that we need fb_info and var, so we create dummy ones */
1982
1983 memset(&fbi, 0, sizeof(fbi));
1984 memset(&var, 0, sizeof(var));
1985 memset(&fbops, 0, sizeof(fbops));
1986 fbi.fbops = &fbops;
1987
1988 r = fb_find_mode(&var, &fbi, mode_str, NULL, 0, NULL, 24);
1989
1990 if (r != 0) {
1991 timings->pixel_clock = PICOS2KHZ(var.pixclock);
1992 timings->hfp = var.left_margin;
1993 timings->hbp = var.right_margin;
1994 timings->vfp = var.upper_margin;
1995 timings->vbp = var.lower_margin;
1996 timings->hsw = var.hsync_len;
1997 timings->vsw = var.vsync_len;
1998 timings->x_res = var.xres;
1999 timings->y_res = var.yres;
2000
2001 switch (var.bits_per_pixel) {
2002 case 16:
2003 *bpp = 16;
2004 break;
2005 case 24:
2006 case 32:
2007 default:
2008 *bpp = 24;
2009 break;
2010 }
2011
2012 return 0;
2013 } else {
2014 return -EINVAL;
2015 }
2016}
2017
2018static int omapfb_set_def_mode(struct omapfb2_device *fbdev,
2019 struct omap_dss_device *display, char *mode_str)
2020{
2021 int r;
2022 u8 bpp;
2023 struct omap_video_timings timings;
2024
2025 r = omapfb_mode_to_timings(mode_str, &timings, &bpp);
2026 if (r)
2027 return r;
2028
2029 fbdev->bpp_overrides[fbdev->num_bpp_overrides].dssdev = display;
2030 fbdev->bpp_overrides[fbdev->num_bpp_overrides].bpp = bpp;
2031 ++fbdev->num_bpp_overrides;
2032
2033 if (!display->driver->check_timings || !display->driver->set_timings)
2034 return -EINVAL;
2035
2036 r = display->driver->check_timings(display, &timings);
2037 if (r)
2038 return r;
2039
2040 display->driver->set_timings(display, &timings);
2041
2042 return 0;
2043}
2044
2045static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev,
2046 struct omap_dss_device *dssdev)
2047{
2048 int i;
2049
2050 BUG_ON(dssdev->driver->get_recommended_bpp == NULL);
2051
2052 for (i = 0; i < fbdev->num_bpp_overrides; ++i) {
2053 if (dssdev == fbdev->bpp_overrides[i].dssdev)
2054 return fbdev->bpp_overrides[i].bpp;
2055 }
2056
2057 return dssdev->driver->get_recommended_bpp(dssdev);
2058}
2059
2060static int omapfb_parse_def_modes(struct omapfb2_device *fbdev)
2061{
2062 char *str, *options, *this_opt;
2063 int r = 0;
2064
2065 str = kmalloc(strlen(def_mode) + 1, GFP_KERNEL);
2066 strcpy(str, def_mode);
2067 options = str;
2068
2069 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
2070 char *p, *display_str, *mode_str;
2071 struct omap_dss_device *display;
2072 int i;
2073
2074 p = strchr(this_opt, ':');
2075 if (!p) {
2076 r = -EINVAL;
2077 break;
2078 }
2079
2080 *p = 0;
2081 display_str = this_opt;
2082 mode_str = p + 1;
2083
2084 display = NULL;
2085 for (i = 0; i < fbdev->num_displays; ++i) {
2086 if (strcmp(fbdev->displays[i]->name,
2087 display_str) == 0) {
2088 display = fbdev->displays[i];
2089 break;
2090 }
2091 }
2092
2093 if (!display) {
2094 r = -EINVAL;
2095 break;
2096 }
2097
2098 r = omapfb_set_def_mode(fbdev, display, mode_str);
2099 if (r)
2100 break;
2101 }
2102
2103 kfree(str);
2104
2105 return r;
2106}
2107
2108static int omapfb_probe(struct platform_device *pdev)
2109{
2110 struct omapfb2_device *fbdev = NULL;
2111 int r = 0;
2112 int i;
2113 struct omap_overlay *ovl;
2114 struct omap_dss_device *def_display;
2115 struct omap_dss_device *dssdev;
2116
2117 DBG("omapfb_probe\n");
2118
2119 if (pdev->num_resources != 0) {
2120 dev_err(&pdev->dev, "probed for an unknown device\n");
2121 r = -ENODEV;
2122 goto err0;
2123 }
2124
2125 fbdev = kzalloc(sizeof(struct omapfb2_device), GFP_KERNEL);
2126 if (fbdev == NULL) {
2127 r = -ENOMEM;
2128 goto err0;
2129 }
2130
2131 mutex_init(&fbdev->mtx);
2132
2133 fbdev->dev = &pdev->dev;
2134 platform_set_drvdata(pdev, fbdev);
2135
2136 r = 0;
2137 fbdev->num_displays = 0;
2138 dssdev = NULL;
2139 for_each_dss_dev(dssdev) {
2140 omap_dss_get_device(dssdev);
2141
2142 if (!dssdev->driver) {
2143 dev_err(&pdev->dev, "no driver for display\n");
2144 r = -ENODEV;
2145 }
2146
2147 fbdev->displays[fbdev->num_displays++] = dssdev;
2148 }
2149
2150 if (r)
2151 goto cleanup;
2152
2153 if (fbdev->num_displays == 0) {
2154 dev_err(&pdev->dev, "no displays\n");
2155 r = -EINVAL;
2156 goto cleanup;
2157 }
2158
2159 fbdev->num_overlays = omap_dss_get_num_overlays();
2160 for (i = 0; i < fbdev->num_overlays; i++)
2161 fbdev->overlays[i] = omap_dss_get_overlay(i);
2162
2163 fbdev->num_managers = omap_dss_get_num_overlay_managers();
2164 for (i = 0; i < fbdev->num_managers; i++)
2165 fbdev->managers[i] = omap_dss_get_overlay_manager(i);
2166
2167 if (def_mode && strlen(def_mode) > 0) {
2168 if (omapfb_parse_def_modes(fbdev))
2169 dev_warn(&pdev->dev, "cannot parse default modes\n");
2170 }
2171
2172 r = omapfb_create_framebuffers(fbdev);
2173 if (r)
2174 goto cleanup;
2175
2176 for (i = 0; i < fbdev->num_managers; i++) {
2177 struct omap_overlay_manager *mgr;
2178 mgr = fbdev->managers[i];
2179 r = mgr->apply(mgr);
2180 if (r)
2181 dev_warn(fbdev->dev, "failed to apply dispc config\n");
2182 }
2183
2184 DBG("mgr->apply'ed\n");
2185
2186 /* gfx overlay should be the default one. find a display
2187 * connected to that, and use it as default display */
2188 ovl = omap_dss_get_overlay(0);
2189 if (ovl->manager && ovl->manager->device) {
2190 def_display = ovl->manager->device;
2191 } else {
2192 dev_warn(&pdev->dev, "cannot find default display\n");
2193 def_display = NULL;
2194 }
2195
2196 if (def_display) {
2197 struct omap_dss_driver *dssdrv = def_display->driver;
2198
2199 r = def_display->driver->enable(def_display);
2200 if (r) {
2201 dev_warn(fbdev->dev, "Failed to enable display '%s'\n",
2202 def_display->name);
2203 goto cleanup;
2204 }
2205
2206 if (def_display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
2207 u16 w, h;
2208 if (dssdrv->enable_te)
2209 dssdrv->enable_te(def_display, 1);
2210 if (dssdrv->set_update_mode)
2211 dssdrv->set_update_mode(def_display,
2212 OMAP_DSS_UPDATE_MANUAL);
2213
2214 dssdrv->get_resolution(def_display, &w, &h);
2215 def_display->driver->update(def_display, 0, 0, w, h);
2216 } else {
2217 if (dssdrv->set_update_mode)
2218 dssdrv->set_update_mode(def_display,
2219 OMAP_DSS_UPDATE_AUTO);
2220 }
2221 }
2222
2223 return 0;
2224
2225cleanup:
2226 omapfb_free_resources(fbdev);
2227err0:
2228 dev_err(&pdev->dev, "failed to setup omapfb\n");
2229 return r;
2230}
2231
2232static int omapfb_remove(struct platform_device *pdev)
2233{
2234 struct omapfb2_device *fbdev = platform_get_drvdata(pdev);
2235
2236 /* FIXME: wait till completion of pending events */
2237
2238 omapfb_remove_sysfs(fbdev);
2239
2240 omapfb_free_resources(fbdev);
2241
2242 return 0;
2243}
2244
2245static struct platform_driver omapfb_driver = {
2246 .probe = omapfb_probe,
2247 .remove = omapfb_remove,
2248 .driver = {
2249 .name = "omapfb",
2250 .owner = THIS_MODULE,
2251 },
2252};
2253
2254static int __init omapfb_init(void)
2255{
2256 DBG("omapfb_init\n");
2257
2258 if (platform_driver_register(&omapfb_driver)) {
2259 printk(KERN_ERR "failed to register omapfb driver\n");
2260 return -ENODEV;
2261 }
2262
2263 return 0;
2264}
2265
2266static void __exit omapfb_exit(void)
2267{
2268 DBG("omapfb_exit\n");
2269 platform_driver_unregister(&omapfb_driver);
2270}
2271
2272module_param_named(mode, def_mode, charp, 0);
2273module_param_named(vram, def_vram, charp, 0);
2274module_param_named(rotate, def_rotate, int, 0);
2275module_param_named(vrfb, def_vrfb, bool, 0);
2276module_param_named(mirror, def_mirror, bool, 0);
2277
2278/* late_initcall to let panel/ctrl drivers loaded first.
2279 * I guess better option would be a more dynamic approach,
2280 * so that omapfb reacts to new panels when they are loaded */
2281late_initcall(omapfb_init);
2282/*module_init(omapfb_init);*/
2283module_exit(omapfb_exit);
2284
2285MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
2286MODULE_DESCRIPTION("OMAP2/3 Framebuffer");
2287MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/omap2/omapfb/omapfb-sysfs.c b/drivers/video/omap2/omapfb/omapfb-sysfs.c
new file mode 100644
index 000000000000..62bb88f5c192
--- /dev/null
+++ b/drivers/video/omap2/omapfb/omapfb-sysfs.c
@@ -0,0 +1,507 @@
1/*
2 * linux/drivers/video/omap2/omapfb-sysfs.c
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <linux/fb.h>
24#include <linux/sysfs.h>
25#include <linux/device.h>
26#include <linux/uaccess.h>
27#include <linux/platform_device.h>
28#include <linux/kernel.h>
29#include <linux/mm.h>
30#include <linux/omapfb.h>
31
32#include <plat/display.h>
33#include <plat/vrfb.h>
34
35#include "omapfb.h"
36
37static ssize_t show_rotate_type(struct device *dev,
38 struct device_attribute *attr, char *buf)
39{
40 struct fb_info *fbi = dev_get_drvdata(dev);
41 struct omapfb_info *ofbi = FB2OFB(fbi);
42
43 return snprintf(buf, PAGE_SIZE, "%d\n", ofbi->rotation_type);
44}
45
46static ssize_t store_rotate_type(struct device *dev,
47 struct device_attribute *attr,
48 const char *buf, size_t count)
49{
50 struct fb_info *fbi = dev_get_drvdata(dev);
51 struct omapfb_info *ofbi = FB2OFB(fbi);
52 enum omap_dss_rotation_type rot_type;
53 int r;
54
55 rot_type = simple_strtoul(buf, NULL, 0);
56
57 if (rot_type != OMAP_DSS_ROT_DMA && rot_type != OMAP_DSS_ROT_VRFB)
58 return -EINVAL;
59
60 lock_fb_info(fbi);
61
62 r = 0;
63 if (rot_type == ofbi->rotation_type)
64 goto out;
65
66 if (ofbi->region.size) {
67 r = -EBUSY;
68 goto out;
69 }
70
71 ofbi->rotation_type = rot_type;
72
73 /*
74 * Since the VRAM for this FB is not allocated at the moment we don't
75 * need to do any further parameter checking at this point.
76 */
77out:
78 unlock_fb_info(fbi);
79
80 return r ? r : count;
81}
82
83
84static ssize_t show_mirror(struct device *dev,
85 struct device_attribute *attr, char *buf)
86{
87 struct fb_info *fbi = dev_get_drvdata(dev);
88 struct omapfb_info *ofbi = FB2OFB(fbi);
89
90 return snprintf(buf, PAGE_SIZE, "%d\n", ofbi->mirror);
91}
92
93static ssize_t store_mirror(struct device *dev,
94 struct device_attribute *attr,
95 const char *buf, size_t count)
96{
97 struct fb_info *fbi = dev_get_drvdata(dev);
98 struct omapfb_info *ofbi = FB2OFB(fbi);
99 bool mirror;
100 int r;
101 struct fb_var_screeninfo new_var;
102
103 mirror = simple_strtoul(buf, NULL, 0);
104
105 if (mirror != 0 && mirror != 1)
106 return -EINVAL;
107
108 lock_fb_info(fbi);
109
110 ofbi->mirror = mirror;
111
112 memcpy(&new_var, &fbi->var, sizeof(new_var));
113 r = check_fb_var(fbi, &new_var);
114 if (r)
115 goto out;
116 memcpy(&fbi->var, &new_var, sizeof(fbi->var));
117
118 set_fb_fix(fbi);
119
120 r = omapfb_apply_changes(fbi, 0);
121 if (r)
122 goto out;
123
124 r = count;
125out:
126 unlock_fb_info(fbi);
127
128 return r;
129}
130
131static ssize_t show_overlays(struct device *dev,
132 struct device_attribute *attr, char *buf)
133{
134 struct fb_info *fbi = dev_get_drvdata(dev);
135 struct omapfb_info *ofbi = FB2OFB(fbi);
136 struct omapfb2_device *fbdev = ofbi->fbdev;
137 ssize_t l = 0;
138 int t;
139
140 omapfb_lock(fbdev);
141 lock_fb_info(fbi);
142
143 for (t = 0; t < ofbi->num_overlays; t++) {
144 struct omap_overlay *ovl = ofbi->overlays[t];
145 int ovlnum;
146
147 for (ovlnum = 0; ovlnum < fbdev->num_overlays; ++ovlnum)
148 if (ovl == fbdev->overlays[ovlnum])
149 break;
150
151 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
152 t == 0 ? "" : ",", ovlnum);
153 }
154
155 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
156
157 unlock_fb_info(fbi);
158 omapfb_unlock(fbdev);
159
160 return l;
161}
162
163static struct omapfb_info *get_overlay_fb(struct omapfb2_device *fbdev,
164 struct omap_overlay *ovl)
165{
166 int i, t;
167
168 for (i = 0; i < fbdev->num_fbs; i++) {
169 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
170
171 for (t = 0; t < ofbi->num_overlays; t++) {
172 if (ofbi->overlays[t] == ovl)
173 return ofbi;
174 }
175 }
176
177 return NULL;
178}
179
180static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
181 const char *buf, size_t count)
182{
183 struct fb_info *fbi = dev_get_drvdata(dev);
184 struct omapfb_info *ofbi = FB2OFB(fbi);
185 struct omapfb2_device *fbdev = ofbi->fbdev;
186 struct omap_overlay *ovls[OMAPFB_MAX_OVL_PER_FB];
187 struct omap_overlay *ovl;
188 int num_ovls, r, i;
189 int len;
190 bool added = false;
191
192 num_ovls = 0;
193
194 len = strlen(buf);
195 if (buf[len - 1] == '\n')
196 len = len - 1;
197
198 omapfb_lock(fbdev);
199 lock_fb_info(fbi);
200
201 if (len > 0) {
202 char *p = (char *)buf;
203 int ovlnum;
204
205 while (p < buf + len) {
206 int found;
207 if (num_ovls == OMAPFB_MAX_OVL_PER_FB) {
208 r = -EINVAL;
209 goto out;
210 }
211
212 ovlnum = simple_strtoul(p, &p, 0);
213 if (ovlnum > fbdev->num_overlays) {
214 r = -EINVAL;
215 goto out;
216 }
217
218 found = 0;
219 for (i = 0; i < num_ovls; ++i) {
220 if (ovls[i] == fbdev->overlays[ovlnum]) {
221 found = 1;
222 break;
223 }
224 }
225
226 if (!found)
227 ovls[num_ovls++] = fbdev->overlays[ovlnum];
228
229 p++;
230 }
231 }
232
233 for (i = 0; i < num_ovls; ++i) {
234 struct omapfb_info *ofbi2 = get_overlay_fb(fbdev, ovls[i]);
235 if (ofbi2 && ofbi2 != ofbi) {
236 dev_err(fbdev->dev, "overlay already in use\n");
237 r = -EINVAL;
238 goto out;
239 }
240 }
241
242 /* detach unused overlays */
243 for (i = 0; i < ofbi->num_overlays; ++i) {
244 int t, found;
245
246 ovl = ofbi->overlays[i];
247
248 found = 0;
249
250 for (t = 0; t < num_ovls; ++t) {
251 if (ovl == ovls[t]) {
252 found = 1;
253 break;
254 }
255 }
256
257 if (found)
258 continue;
259
260 DBG("detaching %d\n", ofbi->overlays[i]->id);
261
262 omapfb_overlay_enable(ovl, 0);
263
264 if (ovl->manager)
265 ovl->manager->apply(ovl->manager);
266
267 for (t = i + 1; t < ofbi->num_overlays; t++) {
268 ofbi->rotation[t-1] = ofbi->rotation[t];
269 ofbi->overlays[t-1] = ofbi->overlays[t];
270 }
271
272 ofbi->num_overlays--;
273 i--;
274 }
275
276 for (i = 0; i < num_ovls; ++i) {
277 int t, found;
278
279 ovl = ovls[i];
280
281 found = 0;
282
283 for (t = 0; t < ofbi->num_overlays; ++t) {
284 if (ovl == ofbi->overlays[t]) {
285 found = 1;
286 break;
287 }
288 }
289
290 if (found)
291 continue;
292 ofbi->rotation[ofbi->num_overlays] = 0;
293 ofbi->overlays[ofbi->num_overlays++] = ovl;
294
295 added = true;
296 }
297
298 if (added) {
299 r = omapfb_apply_changes(fbi, 0);
300 if (r)
301 goto out;
302 }
303
304 r = count;
305out:
306 unlock_fb_info(fbi);
307 omapfb_unlock(fbdev);
308
309 return r;
310}
311
312static ssize_t show_overlays_rotate(struct device *dev,
313 struct device_attribute *attr, char *buf)
314{
315 struct fb_info *fbi = dev_get_drvdata(dev);
316 struct omapfb_info *ofbi = FB2OFB(fbi);
317 ssize_t l = 0;
318 int t;
319
320 lock_fb_info(fbi);
321
322 for (t = 0; t < ofbi->num_overlays; t++) {
323 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
324 t == 0 ? "" : ",", ofbi->rotation[t]);
325 }
326
327 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
328
329 unlock_fb_info(fbi);
330
331 return l;
332}
333
334static ssize_t store_overlays_rotate(struct device *dev,
335 struct device_attribute *attr, const char *buf, size_t count)
336{
337 struct fb_info *fbi = dev_get_drvdata(dev);
338 struct omapfb_info *ofbi = FB2OFB(fbi);
339 int num_ovls = 0, r, i;
340 int len;
341 bool changed = false;
342 u8 rotation[OMAPFB_MAX_OVL_PER_FB];
343
344 len = strlen(buf);
345 if (buf[len - 1] == '\n')
346 len = len - 1;
347
348 lock_fb_info(fbi);
349
350 if (len > 0) {
351 char *p = (char *)buf;
352
353 while (p < buf + len) {
354 int rot;
355
356 if (num_ovls == ofbi->num_overlays) {
357 r = -EINVAL;
358 goto out;
359 }
360
361 rot = simple_strtoul(p, &p, 0);
362 if (rot < 0 || rot > 3) {
363 r = -EINVAL;
364 goto out;
365 }
366
367 if (ofbi->rotation[num_ovls] != rot)
368 changed = true;
369
370 rotation[num_ovls++] = rot;
371
372 p++;
373 }
374 }
375
376 if (num_ovls != ofbi->num_overlays) {
377 r = -EINVAL;
378 goto out;
379 }
380
381 if (changed) {
382 for (i = 0; i < num_ovls; ++i)
383 ofbi->rotation[i] = rotation[i];
384
385 r = omapfb_apply_changes(fbi, 0);
386 if (r)
387 goto out;
388
389 /* FIXME error handling? */
390 }
391
392 r = count;
393out:
394 unlock_fb_info(fbi);
395
396 return r;
397}
398
399static ssize_t show_size(struct device *dev,
400 struct device_attribute *attr, char *buf)
401{
402 struct fb_info *fbi = dev_get_drvdata(dev);
403 struct omapfb_info *ofbi = FB2OFB(fbi);
404
405 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region.size);
406}
407
408static ssize_t store_size(struct device *dev, struct device_attribute *attr,
409 const char *buf, size_t count)
410{
411 struct fb_info *fbi = dev_get_drvdata(dev);
412 struct omapfb_info *ofbi = FB2OFB(fbi);
413 unsigned long size;
414 int r;
415 int i;
416
417 size = PAGE_ALIGN(simple_strtoul(buf, NULL, 0));
418
419 lock_fb_info(fbi);
420
421 for (i = 0; i < ofbi->num_overlays; i++) {
422 if (ofbi->overlays[i]->info.enabled) {
423 r = -EBUSY;
424 goto out;
425 }
426 }
427
428 if (size != ofbi->region.size) {
429 r = omapfb_realloc_fbmem(fbi, size, ofbi->region.type);
430 if (r) {
431 dev_err(dev, "realloc fbmem failed\n");
432 goto out;
433 }
434 }
435
436 r = count;
437out:
438 unlock_fb_info(fbi);
439
440 return r;
441}
442
443static ssize_t show_phys(struct device *dev,
444 struct device_attribute *attr, char *buf)
445{
446 struct fb_info *fbi = dev_get_drvdata(dev);
447 struct omapfb_info *ofbi = FB2OFB(fbi);
448
449 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region.paddr);
450}
451
452static ssize_t show_virt(struct device *dev,
453 struct device_attribute *attr, char *buf)
454{
455 struct fb_info *fbi = dev_get_drvdata(dev);
456 struct omapfb_info *ofbi = FB2OFB(fbi);
457
458 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region.vaddr);
459}
460
461static struct device_attribute omapfb_attrs[] = {
462 __ATTR(rotate_type, S_IRUGO | S_IWUSR, show_rotate_type,
463 store_rotate_type),
464 __ATTR(mirror, S_IRUGO | S_IWUSR, show_mirror, store_mirror),
465 __ATTR(size, S_IRUGO | S_IWUSR, show_size, store_size),
466 __ATTR(overlays, S_IRUGO | S_IWUSR, show_overlays, store_overlays),
467 __ATTR(overlays_rotate, S_IRUGO | S_IWUSR, show_overlays_rotate,
468 store_overlays_rotate),
469 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
470 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
471};
472
473int omapfb_create_sysfs(struct omapfb2_device *fbdev)
474{
475 int i;
476 int r;
477
478 DBG("create sysfs for fbs\n");
479 for (i = 0; i < fbdev->num_fbs; i++) {
480 int t;
481 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
482 r = device_create_file(fbdev->fbs[i]->dev,
483 &omapfb_attrs[t]);
484
485 if (r) {
486 dev_err(fbdev->dev, "failed to create sysfs "
487 "file\n");
488 return r;
489 }
490 }
491 }
492
493 return 0;
494}
495
496void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
497{
498 int i, t;
499
500 DBG("remove sysfs for fbs\n");
501 for (i = 0; i < fbdev->num_fbs; i++) {
502 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
503 device_remove_file(fbdev->fbs[i]->dev,
504 &omapfb_attrs[t]);
505 }
506}
507
diff --git a/drivers/video/omap2/omapfb/omapfb.h b/drivers/video/omap2/omapfb/omapfb.h
new file mode 100644
index 000000000000..cd54fdbfd8bb
--- /dev/null
+++ b/drivers/video/omap2/omapfb/omapfb.h
@@ -0,0 +1,155 @@
1/*
2 * linux/drivers/video/omap2/omapfb.h
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
24#define __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
25
26#ifdef CONFIG_FB_OMAP2_DEBUG_SUPPORT
27#define DEBUG
28#endif
29
30#include <plat/display.h>
31
32#ifdef DEBUG
33extern unsigned int omapfb_debug;
34#define DBG(format, ...) \
35 if (omapfb_debug) \
36 printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__)
37#else
38#define DBG(format, ...)
39#endif
40
41#define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
42
43/* max number of overlays to which a framebuffer data can be direct */
44#define OMAPFB_MAX_OVL_PER_FB 3
45
46struct omapfb2_mem_region {
47 u32 paddr;
48 void __iomem *vaddr;
49 struct vrfb vrfb;
50 unsigned long size;
51 u8 type; /* OMAPFB_PLANE_MEM_* */
52 bool alloc; /* allocated by the driver */
53 bool map; /* kernel mapped by the driver */
54};
55
56/* appended to fb_info */
57struct omapfb_info {
58 int id;
59 struct omapfb2_mem_region region;
60 atomic_t map_count;
61 int num_overlays;
62 struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
63 struct omapfb2_device *fbdev;
64 enum omap_dss_rotation_type rotation_type;
65 u8 rotation[OMAPFB_MAX_OVL_PER_FB];
66 bool mirror;
67};
68
69struct omapfb2_device {
70 struct device *dev;
71 struct mutex mtx;
72
73 u32 pseudo_palette[17];
74
75 int state;
76
77 unsigned num_fbs;
78 struct fb_info *fbs[10];
79
80 unsigned num_displays;
81 struct omap_dss_device *displays[10];
82 unsigned num_overlays;
83 struct omap_overlay *overlays[10];
84 unsigned num_managers;
85 struct omap_overlay_manager *managers[10];
86
87 unsigned num_bpp_overrides;
88 struct {
89 struct omap_dss_device *dssdev;
90 u8 bpp;
91 } bpp_overrides[10];
92};
93
94struct omapfb_colormode {
95 enum omap_color_mode dssmode;
96 u32 bits_per_pixel;
97 u32 nonstd;
98 struct fb_bitfield red;
99 struct fb_bitfield green;
100 struct fb_bitfield blue;
101 struct fb_bitfield transp;
102};
103
104void set_fb_fix(struct fb_info *fbi);
105int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
106int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
107int omapfb_apply_changes(struct fb_info *fbi, int init);
108
109int omapfb_create_sysfs(struct omapfb2_device *fbdev);
110void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
111
112int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
113
114int omapfb_update_window(struct fb_info *fbi,
115 u32 x, u32 y, u32 w, u32 h);
116
117int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
118 struct fb_var_screeninfo *var);
119
120/* find the display connected to this fb, if any */
121static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
122{
123 struct omapfb_info *ofbi = FB2OFB(fbi);
124 int i;
125
126 /* XXX: returns the display connected to first attached overlay */
127 for (i = 0; i < ofbi->num_overlays; i++) {
128 if (ofbi->overlays[i]->manager)
129 return ofbi->overlays[i]->manager->device;
130 }
131
132 return NULL;
133}
134
135static inline void omapfb_lock(struct omapfb2_device *fbdev)
136{
137 mutex_lock(&fbdev->mtx);
138}
139
140static inline void omapfb_unlock(struct omapfb2_device *fbdev)
141{
142 mutex_unlock(&fbdev->mtx);
143}
144
145static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
146 int enable)
147{
148 struct omap_overlay_info info;
149
150 ovl->get_overlay_info(ovl, &info);
151 info.enabled = enable;
152 return ovl->set_overlay_info(ovl, &info);
153}
154
155#endif