2 * linux/drivers/video/omap2/omapfb-ioctl.c
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
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.
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
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/>.
24 #include <linux/device.h>
25 #include <linux/uaccess.h>
26 #include <linux/platform_device.h>
28 #include <linux/omapfb.h>
29 #include <linux/vmalloc.h>
31 #include <mach/display.h>
32 #include <mach/vrfb.h>
36 static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
38 struct omapfb_info *ofbi = FB2OFB(fbi);
39 struct omapfb2_device *fbdev = ofbi->fbdev;
40 struct omap_display *display = fb2display(fbi);
41 struct omap_overlay *ovl;
42 struct omap_overlay_info info;
45 DBG("omapfb_setup_plane\n");
49 if (ofbi->num_overlays != 1) {
54 /* XXX uses only the first overlay */
55 ovl = ofbi->overlays[0];
57 if (pi->enabled && !ofbi->region.size) {
59 * This plane's memory was freed, can't enable it
60 * until it's reallocated.
66 ovl->get_overlay_info(ovl, &info);
68 info.pos_x = pi->pos_x;
69 info.pos_y = pi->pos_y;
70 info.out_width = pi->out_width;
71 info.out_height = pi->out_height;
72 info.enabled = pi->enabled;
74 r = ovl->set_overlay_info(ovl, &info);
79 r = ovl->manager->apply(ovl->manager);
88 display->sync(display);
90 display->get_resolution(display, &w, &h);
93 display->update(display, 0, 0, w, h);
99 dev_err(fbdev->dev, "setup_plane failed\n");
103 static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
105 struct omapfb_info *ofbi = FB2OFB(fbi);
106 struct omapfb2_device *fbdev = ofbi->fbdev;
110 if (ofbi->num_overlays != 1) {
111 memset(pi, 0, sizeof(*pi));
113 struct omap_overlay_info *ovli;
114 struct omap_overlay *ovl;
116 ovl = ofbi->overlays[0];
119 pi->pos_x = ovli->pos_x;
120 pi->pos_y = ovli->pos_y;
121 pi->enabled = ovli->enabled;
122 pi->channel_out = 0; /* xxx */
124 pi->out_width = ovli->out_width;
125 pi->out_height = ovli->out_height;
128 omapfb_unlock(fbdev);
133 static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
135 struct omapfb_info *ofbi = FB2OFB(fbi);
136 struct omapfb2_device *fbdev = ofbi->fbdev;
137 struct omapfb2_mem_region *rg;
141 if (mi->type > OMAPFB_MEMTYPE_MAX)
144 size = PAGE_ALIGN(mi->size);
150 for (i = 0; i < ofbi->num_overlays; i++) {
151 if (ofbi->overlays[i]->info.enabled) {
157 if (rg->size != size || rg->type != mi->type) {
158 r = omapfb_realloc_fbmem(fbi, size, mi->type);
160 dev_err(fbdev->dev, "realloc fbmem failed\n");
167 omapfb_unlock(fbdev);
172 static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
174 struct omapfb_info *ofbi = FB2OFB(fbi);
175 struct omapfb2_device *fbdev = ofbi->fbdev;
176 struct omapfb2_mem_region *rg;
179 memset(mi, 0, sizeof(*mi));
184 omapfb_unlock(fbdev);
189 static int omapfb_update_window(struct fb_info *fbi,
190 u32 x, u32 y, u32 w, u32 h)
192 struct omapfb_info *ofbi = FB2OFB(fbi);
193 struct omapfb2_device *fbdev = ofbi->fbdev;
194 struct omap_display *display = fb2display(fbi);
200 if (w == 0 || h == 0)
203 display->get_resolution(display, &dw, &dh);
205 if (x + w > dw || y + h > dh)
209 display->update(display, x, y, w, h);
210 omapfb_unlock(fbdev);
215 static int omapfb_set_update_mode(struct fb_info *fbi,
216 enum omapfb_update_mode mode)
218 struct omapfb_info *ofbi = FB2OFB(fbi);
219 struct omapfb2_device *fbdev = ofbi->fbdev;
220 struct omap_display *display = fb2display(fbi);
221 enum omap_dss_update_mode um;
224 if (!display || !display->set_update_mode)
228 case OMAPFB_UPDATE_DISABLED:
229 um = OMAP_DSS_UPDATE_DISABLED;
232 case OMAPFB_AUTO_UPDATE:
233 um = OMAP_DSS_UPDATE_AUTO;
236 case OMAPFB_MANUAL_UPDATE:
237 um = OMAP_DSS_UPDATE_MANUAL;
245 r = display->set_update_mode(display, um);
246 omapfb_unlock(fbdev);
251 static int omapfb_get_update_mode(struct fb_info *fbi,
252 enum omapfb_update_mode *mode)
254 struct omapfb_info *ofbi = FB2OFB(fbi);
255 struct omapfb2_device *fbdev = ofbi->fbdev;
256 struct omap_display *display = fb2display(fbi);
257 enum omap_dss_update_mode m;
259 if (!display || !display->get_update_mode)
263 m = display->get_update_mode(display);
264 omapfb_unlock(fbdev);
267 case OMAP_DSS_UPDATE_DISABLED:
268 *mode = OMAPFB_UPDATE_DISABLED;
270 case OMAP_DSS_UPDATE_AUTO:
271 *mode = OMAPFB_AUTO_UPDATE;
273 case OMAP_DSS_UPDATE_MANUAL:
274 *mode = OMAPFB_MANUAL_UPDATE;
283 /* XXX this color key handling is a hack... */
284 static struct omapfb_color_key omapfb_color_keys[2];
286 static int _omapfb_set_color_key(struct omap_overlay_manager *mgr,
287 struct omapfb_color_key *ck)
289 enum omap_dss_color_key_type kt;
291 if (!mgr->set_default_color ||
292 !mgr->set_trans_key_type_and_value ||
293 !mgr->enable_trans_key)
296 if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) {
297 mgr->enable_trans_key(mgr, 0);
298 omapfb_color_keys[mgr->id] = *ck;
302 switch(ck->key_type) {
303 case OMAPFB_COLOR_KEY_GFX_DST:
304 kt = OMAP_DSS_COLOR_KEY_GFX_DST;
306 case OMAPFB_COLOR_KEY_VID_SRC:
307 kt = OMAP_DSS_COLOR_KEY_VID_SRC;
313 mgr->set_default_color(mgr, ck->background);
314 mgr->set_trans_key_type_and_value(mgr, kt, ck->trans_key);
315 mgr->enable_trans_key(mgr, 1);
317 omapfb_color_keys[mgr->id] = *ck;
322 static int omapfb_set_color_key(struct fb_info *fbi,
323 struct omapfb_color_key *ck)
325 struct omapfb_info *ofbi = FB2OFB(fbi);
326 struct omapfb2_device *fbdev = ofbi->fbdev;
329 struct omap_overlay_manager *mgr = NULL;
333 for (i = 0; i < ofbi->num_overlays; i++) {
334 if (ofbi->overlays[i]->manager) {
335 mgr = ofbi->overlays[i]->manager;
345 if (!mgr->set_default_color ||
346 !mgr->set_trans_key_type_and_value ||
347 !mgr->enable_trans_key) {
352 r = _omapfb_set_color_key(mgr, ck);
354 omapfb_unlock(fbdev);
359 static int omapfb_get_color_key(struct fb_info *fbi,
360 struct omapfb_color_key *ck)
362 struct omapfb_info *ofbi = FB2OFB(fbi);
363 struct omapfb2_device *fbdev = ofbi->fbdev;
364 struct omap_overlay_manager *mgr = NULL;
370 for (i = 0; i < ofbi->num_overlays; i++) {
371 if (ofbi->overlays[i]->manager) {
372 mgr = ofbi->overlays[i]->manager;
382 if (!mgr->set_default_color ||
383 !mgr->set_trans_key_type_and_value ||
384 !mgr->enable_trans_key) {
389 *ck = omapfb_color_keys[mgr->id];
391 omapfb_unlock(fbdev);
396 static int omapfb_memory_read(struct fb_info *fbi,
397 struct omapfb_memory_read *mr)
399 struct omap_display *display = fb2display(fbi);
400 struct omapfb_info *ofbi = FB2OFB(fbi);
401 struct omapfb2_device *fbdev = ofbi->fbdev;
405 if (!display || !display->memory_read)
408 if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
411 if (mr->w * mr->h * 3 > mr->buffer_size)
414 buf = vmalloc(mr->buffer_size);
416 DBG("vmalloc failed\n");
422 r = display->memory_read(display, buf, mr->buffer_size,
423 mr->x, mr->y, mr->w, mr->h);
426 if (copy_to_user(mr->buffer, buf, mr->buffer_size))
432 omapfb_unlock(fbdev);
437 int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
439 struct omapfb_info *ofbi = FB2OFB(fbi);
440 struct omapfb2_device *fbdev = ofbi->fbdev;
441 struct omap_display *display = fb2display(fbi);
444 struct omapfb_update_window_old uwnd_o;
445 struct omapfb_update_window uwnd;
446 struct omapfb_plane_info plane_info;
447 struct omapfb_caps caps;
448 struct omapfb_mem_info mem_info;
449 struct omapfb_color_key color_key;
450 enum omapfb_update_mode update_mode;
452 struct omapfb_memory_read memory_read;
459 case OMAPFB_SYNC_GFX:
460 DBG("ioctl SYNC_GFX\n");
461 if (!display || !display->sync) {
462 /* DSS1 never returns an error here, so we neither */
468 r = display->sync(display);
469 omapfb_unlock(fbdev);
472 case OMAPFB_UPDATE_WINDOW_OLD:
473 DBG("ioctl UPDATE_WINDOW_OLD\n");
474 if (!display || !display->update) {
479 if (copy_from_user(&p.uwnd_o,
486 r = omapfb_update_window(fbi, p.uwnd_o.x, p.uwnd_o.y,
487 p.uwnd_o.width, p.uwnd_o.height);
490 case OMAPFB_UPDATE_WINDOW:
491 DBG("ioctl UPDATE_WINDOW\n");
492 if (!display || !display->update) {
497 if (copy_from_user(&p.uwnd, (void __user *)arg,
503 r = omapfb_update_window(fbi, p.uwnd.x, p.uwnd.y,
504 p.uwnd.width, p.uwnd.height);
507 case OMAPFB_SETUP_PLANE:
508 DBG("ioctl SETUP_PLANE\n");
509 if (copy_from_user(&p.plane_info, (void __user *)arg,
510 sizeof(p.plane_info)))
513 r = omapfb_setup_plane(fbi, &p.plane_info);
516 case OMAPFB_QUERY_PLANE:
517 DBG("ioctl QUERY_PLANE\n");
518 r = omapfb_query_plane(fbi, &p.plane_info);
521 if (copy_to_user((void __user *)arg, &p.plane_info,
522 sizeof(p.plane_info)))
526 case OMAPFB_SETUP_MEM:
527 DBG("ioctl SETUP_MEM\n");
528 if (copy_from_user(&p.mem_info, (void __user *)arg,
532 r = omapfb_setup_mem(fbi, &p.mem_info);
535 case OMAPFB_QUERY_MEM:
536 DBG("ioctl QUERY_MEM\n");
537 r = omapfb_query_mem(fbi, &p.mem_info);
540 if (copy_to_user((void __user *)arg, &p.mem_info,
545 case OMAPFB_GET_CAPS:
546 DBG("ioctl GET_CAPS\n");
552 p.caps.ctrl = display->caps;
554 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
558 case OMAPFB_SET_UPDATE_MODE:
559 DBG("ioctl SET_UPDATE_MODE\n");
560 if (get_user(p.update_mode, (int __user *)arg))
563 r = omapfb_set_update_mode(fbi, p.update_mode);
566 case OMAPFB_GET_UPDATE_MODE:
567 DBG("ioctl GET_UPDATE_MODE\n");
568 r = omapfb_get_update_mode(fbi, &p.update_mode);
571 if (put_user(p.update_mode,
572 (enum omapfb_update_mode __user *)arg))
576 case OMAPFB_SET_COLOR_KEY:
577 DBG("ioctl SET_COLOR_KEY\n");
578 if (copy_from_user(&p.color_key, (void __user *)arg,
579 sizeof(p.color_key)))
582 r = omapfb_set_color_key(fbi, &p.color_key);
585 case OMAPFB_GET_COLOR_KEY:
586 DBG("ioctl GET_COLOR_KEY\n");
587 if ((r = omapfb_get_color_key(fbi, &p.color_key)) < 0)
589 if (copy_to_user((void __user *)arg, &p.color_key,
590 sizeof(p.color_key)))
594 case FBIO_WAITFORVSYNC:
595 if (get_user(p.crt, (u_int32_t __user *)arg)) {
605 case OMAPFB_WAITFORVSYNC:
606 DBG("ioctl WAITFORVSYNC\n");
612 r = display->wait_vsync(display);
615 /* LCD and CTRL tests do the same thing for backward
617 case OMAPFB_LCD_TEST:
618 DBG("ioctl LCD_TEST\n");
619 if (get_user(p.test_num, (int __user *)arg)) {
623 if (!display || !display->run_test) {
628 r = display->run_test(display, p.test_num);
632 case OMAPFB_CTRL_TEST:
633 DBG("ioctl CTRL_TEST\n");
634 if (get_user(p.test_num, (int __user *)arg)) {
638 if (!display || !display->run_test) {
643 r = display->run_test(display, p.test_num);
647 case OMAPFB_MEMORY_READ:
648 DBG("ioctl MEMORY_READ\n");
650 if (copy_from_user(&p.memory_read, (void __user *)arg,
651 sizeof(p.memory_read))) {
656 r = omapfb_memory_read(fbi, &p.memory_read);
661 dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd);
666 DBG("ioctl failed: %d\n", r);