blob: 69bcbfca47f6237abd3fd05579de4f94ff507996 [file] [log] [blame]
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +03001/*
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
Ville Syrjälä078ff542010-03-17 20:36:51 +020037static u8 get_mem_idx(struct omapfb_info *ofbi)
38{
39 if (ofbi->id == ofbi->region->id)
40 return 0;
41
42 return OMAPFB_MEM_IDX_ENABLED | ofbi->region->id;
43}
44
45static struct omapfb2_mem_region *get_mem_region(struct omapfb_info *ofbi,
46 u8 mem_idx)
47{
48 struct omapfb2_device *fbdev = ofbi->fbdev;
49
50 if (mem_idx & OMAPFB_MEM_IDX_ENABLED)
51 mem_idx &= OMAPFB_MEM_IDX_MASK;
52 else
53 mem_idx = ofbi->id;
54
55 if (mem_idx >= fbdev->num_fbs)
56 return NULL;
57
Ville Syrjälä430571d2010-03-17 20:43:23 +020058 return omapfb_get_mem_region(&fbdev->regions[mem_idx]);
Ville Syrjälä078ff542010-03-17 20:36:51 +020059}
60
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030061static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
62{
63 struct omapfb_info *ofbi = FB2OFB(fbi);
64 struct omapfb2_device *fbdev = ofbi->fbdev;
65 struct omap_overlay *ovl;
Ville Syrjälä078ff542010-03-17 20:36:51 +020066 struct omap_overlay_info old_info;
67 struct omapfb2_mem_region *old_rg, *new_rg;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030068 int r = 0;
69
70 DBG("omapfb_setup_plane\n");
71
72 if (ofbi->num_overlays != 1) {
73 r = -EINVAL;
74 goto out;
75 }
76
77 /* XXX uses only the first overlay */
78 ovl = ofbi->overlays[0];
79
Ville Syrjälä430571d2010-03-17 20:43:23 +020080 old_rg = omapfb_get_mem_region(ofbi->region);
Ville Syrjälä078ff542010-03-17 20:36:51 +020081 new_rg = get_mem_region(ofbi, pi->mem_idx);
82 if (!new_rg) {
83 r = -EINVAL;
Ville Syrjälä430571d2010-03-17 20:43:23 +020084 goto put_old;
Ville Syrjälä078ff542010-03-17 20:36:51 +020085 }
86
87 if (pi->enabled && !new_rg->size) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030088 /*
89 * This plane's memory was freed, can't enable it
90 * until it's reallocated.
91 */
92 r = -EINVAL;
Ville Syrjälä430571d2010-03-17 20:43:23 +020093 goto put_new;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030094 }
95
Ville Syrjälä078ff542010-03-17 20:36:51 +020096 ovl->get_overlay_info(ovl, &old_info);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030097
Ville Syrjälä078ff542010-03-17 20:36:51 +020098 if (old_rg != new_rg) {
99 ofbi->region = new_rg;
100 set_fb_fix(fbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300101 }
102
Ville Syrjälä078ff542010-03-17 20:36:51 +0200103 if (pi->enabled) {
104 struct omap_overlay_info info;
105
106 r = omapfb_setup_overlay(fbi, ovl, pi->pos_x, pi->pos_y,
107 pi->out_width, pi->out_height);
108 if (r)
109 goto undo;
110
111 ovl->get_overlay_info(ovl, &info);
112
113 if (!info.enabled) {
114 info.enabled = pi->enabled;
115 r = ovl->set_overlay_info(ovl, &info);
116 if (r)
117 goto undo;
118 }
119 } else {
120 struct omap_overlay_info info;
121
122 ovl->get_overlay_info(ovl, &info);
123
124 info.enabled = pi->enabled;
125 info.pos_x = pi->pos_x;
126 info.pos_y = pi->pos_y;
127 info.out_width = pi->out_width;
128 info.out_height = pi->out_height;
129
130 r = ovl->set_overlay_info(ovl, &info);
131 if (r)
132 goto undo;
133 }
134
135 if (ovl->manager)
136 ovl->manager->apply(ovl->manager);
137
Ville Syrjälä430571d2010-03-17 20:43:23 +0200138 omapfb_put_mem_region(new_rg);
139 omapfb_put_mem_region(old_rg);
140
Ville Syrjälä078ff542010-03-17 20:36:51 +0200141 return 0;
142
143 undo:
144 if (old_rg != new_rg) {
145 ofbi->region = old_rg;
146 set_fb_fix(fbi);
147 }
148
149 ovl->set_overlay_info(ovl, &old_info);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200150 put_new:
151 omapfb_put_mem_region(new_rg);
152 put_old:
153 omapfb_put_mem_region(old_rg);
Ville Syrjälä078ff542010-03-17 20:36:51 +0200154 out:
155 dev_err(fbdev->dev, "setup_plane failed\n");
156
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300157 return r;
158}
159
160static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
161{
162 struct omapfb_info *ofbi = FB2OFB(fbi);
163
164 if (ofbi->num_overlays != 1) {
165 memset(pi, 0, sizeof(*pi));
166 } else {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300167 struct omap_overlay *ovl;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200168 struct omap_overlay_info *ovli;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300169
170 ovl = ofbi->overlays[0];
171 ovli = &ovl->info;
172
173 pi->pos_x = ovli->pos_x;
174 pi->pos_y = ovli->pos_y;
175 pi->enabled = ovli->enabled;
176 pi->channel_out = 0; /* xxx */
177 pi->mirror = 0;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200178 pi->mem_idx = get_mem_idx(ofbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300179 pi->out_width = ovli->out_width;
180 pi->out_height = ovli->out_height;
181 }
182
183 return 0;
184}
185
186static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
187{
188 struct omapfb_info *ofbi = FB2OFB(fbi);
189 struct omapfb2_device *fbdev = ofbi->fbdev;
190 struct omapfb2_mem_region *rg;
Ville Syrjälä430571d2010-03-17 20:43:23 +0200191 int r = 0, i;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300192 size_t size;
193
194 if (mi->type > OMAPFB_MEMTYPE_MAX)
195 return -EINVAL;
196
197 size = PAGE_ALIGN(mi->size);
198
Ville Syrjälä078ff542010-03-17 20:36:51 +0200199 rg = ofbi->region;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300200
Ville Syrjälä430571d2010-03-17 20:43:23 +0200201 /* FIXME probably should be a rwsem ... */
202 mutex_lock(&rg->mtx);
203 while (rg->ref) {
204 mutex_unlock(&rg->mtx);
205 schedule();
206 mutex_lock(&rg->mtx);
207 }
208
209 if (atomic_read(&rg->map_count)) {
210 r = -EBUSY;
211 goto out;
212 }
Ville Syrjälä078ff542010-03-17 20:36:51 +0200213
214 for (i = 0; i < fbdev->num_fbs; i++) {
215 struct omapfb_info *ofbi2 = FB2OFB(fbdev->fbs[i]);
216 int j;
217
218 if (ofbi2->region != rg)
219 continue;
220
221 for (j = 0; j < ofbi2->num_overlays; j++) {
222 if (ofbi2->overlays[j]->info.enabled) {
223 r = -EBUSY;
Ville Syrjälä430571d2010-03-17 20:43:23 +0200224 goto out;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200225 }
226 }
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300227 }
228
229 if (rg->size != size || rg->type != mi->type) {
230 r = omapfb_realloc_fbmem(fbi, size, mi->type);
231 if (r) {
232 dev_err(fbdev->dev, "realloc fbmem failed\n");
Ville Syrjälä430571d2010-03-17 20:43:23 +0200233 goto out;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300234 }
235 }
236
Ville Syrjälä430571d2010-03-17 20:43:23 +0200237 out:
238 mutex_unlock(&rg->mtx);
239
240 return r;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300241}
242
243static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
244{
245 struct omapfb_info *ofbi = FB2OFB(fbi);
246 struct omapfb2_mem_region *rg;
247
Ville Syrjälä430571d2010-03-17 20:43:23 +0200248 rg = omapfb_get_mem_region(ofbi->region);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300249 memset(mi, 0, sizeof(*mi));
250
251 mi->size = rg->size;
252 mi->type = rg->type;
253
Ville Syrjälä430571d2010-03-17 20:43:23 +0200254 omapfb_put_mem_region(rg);
255
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300256 return 0;
257}
258
259static int omapfb_update_window_nolock(struct fb_info *fbi,
260 u32 x, u32 y, u32 w, u32 h)
261{
262 struct omap_dss_device *display = fb2display(fbi);
263 u16 dw, dh;
264
265 if (!display)
266 return 0;
267
268 if (w == 0 || h == 0)
269 return 0;
270
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200271 display->driver->get_resolution(display, &dw, &dh);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300272
273 if (x + w > dw || y + h > dh)
274 return -EINVAL;
275
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200276 return display->driver->update(display, x, y, w, h);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300277}
278
279/* This function is exported for SGX driver use */
280int omapfb_update_window(struct fb_info *fbi,
281 u32 x, u32 y, u32 w, u32 h)
282{
283 struct omapfb_info *ofbi = FB2OFB(fbi);
284 struct omapfb2_device *fbdev = ofbi->fbdev;
285 int r;
286
Jani Nikula27b67c92010-03-18 10:32:06 +0100287 if (!lock_fb_info(fbi))
288 return -ENODEV;
Jani Nikula238a4132010-03-18 10:32:05 +0100289 omapfb_lock(fbdev);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300290
291 r = omapfb_update_window_nolock(fbi, x, y, w, h);
292
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300293 omapfb_unlock(fbdev);
Jani Nikula238a4132010-03-18 10:32:05 +0100294 unlock_fb_info(fbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300295
296 return r;
297}
298EXPORT_SYMBOL(omapfb_update_window);
299
300static int omapfb_set_update_mode(struct fb_info *fbi,
301 enum omapfb_update_mode mode)
302{
303 struct omap_dss_device *display = fb2display(fbi);
304 enum omap_dss_update_mode um;
305 int r;
306
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200307 if (!display || !display->driver->set_update_mode)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300308 return -EINVAL;
309
310 switch (mode) {
311 case OMAPFB_UPDATE_DISABLED:
312 um = OMAP_DSS_UPDATE_DISABLED;
313 break;
314
315 case OMAPFB_AUTO_UPDATE:
316 um = OMAP_DSS_UPDATE_AUTO;
317 break;
318
319 case OMAPFB_MANUAL_UPDATE:
320 um = OMAP_DSS_UPDATE_MANUAL;
321 break;
322
323 default:
324 return -EINVAL;
325 }
326
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200327 r = display->driver->set_update_mode(display, um);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300328
329 return r;
330}
331
332static int omapfb_get_update_mode(struct fb_info *fbi,
333 enum omapfb_update_mode *mode)
334{
335 struct omap_dss_device *display = fb2display(fbi);
336 enum omap_dss_update_mode m;
337
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200338 if (!display)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300339 return -EINVAL;
340
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200341 if (!display->driver->get_update_mode) {
342 *mode = OMAPFB_AUTO_UPDATE;
343 return 0;
344 }
345
346 m = display->driver->get_update_mode(display);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300347
348 switch (m) {
349 case OMAP_DSS_UPDATE_DISABLED:
350 *mode = OMAPFB_UPDATE_DISABLED;
351 break;
352 case OMAP_DSS_UPDATE_AUTO:
353 *mode = OMAPFB_AUTO_UPDATE;
354 break;
355 case OMAP_DSS_UPDATE_MANUAL:
356 *mode = OMAPFB_MANUAL_UPDATE;
357 break;
358 default:
359 BUG();
360 }
361
362 return 0;
363}
364
365/* XXX this color key handling is a hack... */
366static struct omapfb_color_key omapfb_color_keys[2];
367
368static int _omapfb_set_color_key(struct omap_overlay_manager *mgr,
369 struct omapfb_color_key *ck)
370{
371 struct omap_overlay_manager_info info;
372 enum omap_dss_trans_key_type kt;
373 int r;
374
375 mgr->get_manager_info(mgr, &info);
376
377 if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) {
378 info.trans_enabled = false;
379 omapfb_color_keys[mgr->id] = *ck;
380
381 r = mgr->set_manager_info(mgr, &info);
382 if (r)
383 return r;
384
385 r = mgr->apply(mgr);
386
387 return r;
388 }
389
390 switch (ck->key_type) {
391 case OMAPFB_COLOR_KEY_GFX_DST:
392 kt = OMAP_DSS_COLOR_KEY_GFX_DST;
393 break;
394 case OMAPFB_COLOR_KEY_VID_SRC:
395 kt = OMAP_DSS_COLOR_KEY_VID_SRC;
396 break;
397 default:
398 return -EINVAL;
399 }
400
401 info.default_color = ck->background;
402 info.trans_key = ck->trans_key;
403 info.trans_key_type = kt;
404 info.trans_enabled = true;
405
406 omapfb_color_keys[mgr->id] = *ck;
407
408 r = mgr->set_manager_info(mgr, &info);
409 if (r)
410 return r;
411
412 r = mgr->apply(mgr);
413
414 return r;
415}
416
417static int omapfb_set_color_key(struct fb_info *fbi,
418 struct omapfb_color_key *ck)
419{
420 struct omapfb_info *ofbi = FB2OFB(fbi);
421 struct omapfb2_device *fbdev = ofbi->fbdev;
422 int r;
423 int i;
424 struct omap_overlay_manager *mgr = NULL;
425
426 omapfb_lock(fbdev);
427
428 for (i = 0; i < ofbi->num_overlays; i++) {
429 if (ofbi->overlays[i]->manager) {
430 mgr = ofbi->overlays[i]->manager;
431 break;
432 }
433 }
434
435 if (!mgr) {
436 r = -EINVAL;
437 goto err;
438 }
439
440 r = _omapfb_set_color_key(mgr, ck);
441err:
442 omapfb_unlock(fbdev);
443
444 return r;
445}
446
447static int omapfb_get_color_key(struct fb_info *fbi,
448 struct omapfb_color_key *ck)
449{
450 struct omapfb_info *ofbi = FB2OFB(fbi);
451 struct omapfb2_device *fbdev = ofbi->fbdev;
452 struct omap_overlay_manager *mgr = NULL;
453 int r = 0;
454 int i;
455
456 omapfb_lock(fbdev);
457
458 for (i = 0; i < ofbi->num_overlays; i++) {
459 if (ofbi->overlays[i]->manager) {
460 mgr = ofbi->overlays[i]->manager;
461 break;
462 }
463 }
464
465 if (!mgr) {
466 r = -EINVAL;
467 goto err;
468 }
469
470 *ck = omapfb_color_keys[mgr->id];
471err:
472 omapfb_unlock(fbdev);
473
474 return r;
475}
476
477static int omapfb_memory_read(struct fb_info *fbi,
478 struct omapfb_memory_read *mr)
479{
480 struct omap_dss_device *display = fb2display(fbi);
481 void *buf;
482 int r;
483
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200484 if (!display || !display->driver->memory_read)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300485 return -ENOENT;
486
487 if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
488 return -EFAULT;
489
490 if (mr->w * mr->h * 3 > mr->buffer_size)
491 return -EINVAL;
492
493 buf = vmalloc(mr->buffer_size);
494 if (!buf) {
495 DBG("vmalloc failed\n");
496 return -ENOMEM;
497 }
498
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200499 r = display->driver->memory_read(display, buf, mr->buffer_size,
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300500 mr->x, mr->y, mr->w, mr->h);
501
502 if (r > 0) {
503 if (copy_to_user(mr->buffer, buf, mr->buffer_size))
504 r = -EFAULT;
505 }
506
507 vfree(buf);
508
509 return r;
510}
511
512static int omapfb_get_ovl_colormode(struct omapfb2_device *fbdev,
513 struct omapfb_ovl_colormode *mode)
514{
515 int ovl_idx = mode->overlay_idx;
516 int mode_idx = mode->mode_idx;
517 struct omap_overlay *ovl;
518 enum omap_color_mode supported_modes;
519 struct fb_var_screeninfo var;
520 int i;
521
522 if (ovl_idx >= fbdev->num_overlays)
523 return -ENODEV;
524 ovl = fbdev->overlays[ovl_idx];
525 supported_modes = ovl->supported_modes;
526
527 mode_idx = mode->mode_idx;
528
529 for (i = 0; i < sizeof(supported_modes) * 8; i++) {
530 if (!(supported_modes & (1 << i)))
531 continue;
532 /*
533 * It's possible that the FB doesn't support a mode
534 * that is supported by the overlay, so call the
535 * following here.
536 */
537 if (dss_mode_to_fb_mode(1 << i, &var) < 0)
538 continue;
539
540 mode_idx--;
541 if (mode_idx < 0)
542 break;
543 }
544
545 if (i == sizeof(supported_modes) * 8)
546 return -ENOENT;
547
548 mode->bits_per_pixel = var.bits_per_pixel;
549 mode->nonstd = var.nonstd;
550 mode->red = var.red;
551 mode->green = var.green;
552 mode->blue = var.blue;
553 mode->transp = var.transp;
554
555 return 0;
556}
557
558static int omapfb_wait_for_go(struct fb_info *fbi)
559{
560 struct omapfb_info *ofbi = FB2OFB(fbi);
561 int r = 0;
562 int i;
563
564 for (i = 0; i < ofbi->num_overlays; ++i) {
565 struct omap_overlay *ovl = ofbi->overlays[i];
566 r = ovl->wait_for_go(ovl);
567 if (r)
568 break;
569 }
570
571 return r;
572}
573
574int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
575{
576 struct omapfb_info *ofbi = FB2OFB(fbi);
577 struct omapfb2_device *fbdev = ofbi->fbdev;
578 struct omap_dss_device *display = fb2display(fbi);
579
580 union {
581 struct omapfb_update_window_old uwnd_o;
582 struct omapfb_update_window uwnd;
583 struct omapfb_plane_info plane_info;
584 struct omapfb_caps caps;
585 struct omapfb_mem_info mem_info;
586 struct omapfb_color_key color_key;
587 struct omapfb_ovl_colormode ovl_colormode;
588 enum omapfb_update_mode update_mode;
589 int test_num;
590 struct omapfb_memory_read memory_read;
591 struct omapfb_vram_info vram_info;
592 struct omapfb_tearsync_info tearsync_info;
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200593 struct omapfb_display_info display_info;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300594 } p;
595
596 int r = 0;
597
598 switch (cmd) {
599 case OMAPFB_SYNC_GFX:
600 DBG("ioctl SYNC_GFX\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200601 if (!display || !display->driver->sync) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300602 /* DSS1 never returns an error here, so we neither */
603 /*r = -EINVAL;*/
604 break;
605 }
606
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200607 r = display->driver->sync(display);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300608 break;
609
610 case OMAPFB_UPDATE_WINDOW_OLD:
611 DBG("ioctl UPDATE_WINDOW_OLD\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200612 if (!display || !display->driver->update) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300613 r = -EINVAL;
614 break;
615 }
616
617 if (copy_from_user(&p.uwnd_o,
618 (void __user *)arg,
619 sizeof(p.uwnd_o))) {
620 r = -EFAULT;
621 break;
622 }
623
624 r = omapfb_update_window_nolock(fbi, p.uwnd_o.x, p.uwnd_o.y,
625 p.uwnd_o.width, p.uwnd_o.height);
626 break;
627
628 case OMAPFB_UPDATE_WINDOW:
629 DBG("ioctl UPDATE_WINDOW\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200630 if (!display || !display->driver->update) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300631 r = -EINVAL;
632 break;
633 }
634
635 if (copy_from_user(&p.uwnd, (void __user *)arg,
636 sizeof(p.uwnd))) {
637 r = -EFAULT;
638 break;
639 }
640
641 r = omapfb_update_window_nolock(fbi, p.uwnd.x, p.uwnd.y,
642 p.uwnd.width, p.uwnd.height);
643 break;
644
645 case OMAPFB_SETUP_PLANE:
646 DBG("ioctl SETUP_PLANE\n");
647 if (copy_from_user(&p.plane_info, (void __user *)arg,
648 sizeof(p.plane_info)))
649 r = -EFAULT;
650 else
651 r = omapfb_setup_plane(fbi, &p.plane_info);
652 break;
653
654 case OMAPFB_QUERY_PLANE:
655 DBG("ioctl QUERY_PLANE\n");
656 r = omapfb_query_plane(fbi, &p.plane_info);
657 if (r < 0)
658 break;
659 if (copy_to_user((void __user *)arg, &p.plane_info,
660 sizeof(p.plane_info)))
661 r = -EFAULT;
662 break;
663
664 case OMAPFB_SETUP_MEM:
665 DBG("ioctl SETUP_MEM\n");
666 if (copy_from_user(&p.mem_info, (void __user *)arg,
667 sizeof(p.mem_info)))
668 r = -EFAULT;
669 else
670 r = omapfb_setup_mem(fbi, &p.mem_info);
671 break;
672
673 case OMAPFB_QUERY_MEM:
674 DBG("ioctl QUERY_MEM\n");
675 r = omapfb_query_mem(fbi, &p.mem_info);
676 if (r < 0)
677 break;
678 if (copy_to_user((void __user *)arg, &p.mem_info,
679 sizeof(p.mem_info)))
680 r = -EFAULT;
681 break;
682
683 case OMAPFB_GET_CAPS:
684 DBG("ioctl GET_CAPS\n");
685 if (!display) {
686 r = -EINVAL;
687 break;
688 }
689
690 memset(&p.caps, 0, sizeof(p.caps));
691 if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
692 p.caps.ctrl |= OMAPFB_CAPS_MANUAL_UPDATE;
693 if (display->caps & OMAP_DSS_DISPLAY_CAP_TEAR_ELIM)
694 p.caps.ctrl |= OMAPFB_CAPS_TEARSYNC;
695
696 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
697 r = -EFAULT;
698 break;
699
700 case OMAPFB_GET_OVERLAY_COLORMODE:
701 DBG("ioctl GET_OVERLAY_COLORMODE\n");
702 if (copy_from_user(&p.ovl_colormode, (void __user *)arg,
703 sizeof(p.ovl_colormode))) {
704 r = -EFAULT;
705 break;
706 }
707 r = omapfb_get_ovl_colormode(fbdev, &p.ovl_colormode);
708 if (r < 0)
709 break;
710 if (copy_to_user((void __user *)arg, &p.ovl_colormode,
711 sizeof(p.ovl_colormode)))
712 r = -EFAULT;
713 break;
714
715 case OMAPFB_SET_UPDATE_MODE:
716 DBG("ioctl SET_UPDATE_MODE\n");
717 if (get_user(p.update_mode, (int __user *)arg))
718 r = -EFAULT;
719 else
720 r = omapfb_set_update_mode(fbi, p.update_mode);
721 break;
722
723 case OMAPFB_GET_UPDATE_MODE:
724 DBG("ioctl GET_UPDATE_MODE\n");
725 r = omapfb_get_update_mode(fbi, &p.update_mode);
726 if (r)
727 break;
728 if (put_user(p.update_mode,
729 (enum omapfb_update_mode __user *)arg))
730 r = -EFAULT;
731 break;
732
733 case OMAPFB_SET_COLOR_KEY:
734 DBG("ioctl SET_COLOR_KEY\n");
735 if (copy_from_user(&p.color_key, (void __user *)arg,
736 sizeof(p.color_key)))
737 r = -EFAULT;
738 else
739 r = omapfb_set_color_key(fbi, &p.color_key);
740 break;
741
742 case OMAPFB_GET_COLOR_KEY:
743 DBG("ioctl GET_COLOR_KEY\n");
744 r = omapfb_get_color_key(fbi, &p.color_key);
745 if (r)
746 break;
747 if (copy_to_user((void __user *)arg, &p.color_key,
748 sizeof(p.color_key)))
749 r = -EFAULT;
750 break;
751
752 case OMAPFB_WAITFORVSYNC:
753 DBG("ioctl WAITFORVSYNC\n");
754 if (!display) {
755 r = -EINVAL;
756 break;
757 }
758
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200759 r = display->manager->wait_for_vsync(display->manager);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300760 break;
761
762 case OMAPFB_WAITFORGO:
763 DBG("ioctl WAITFORGO\n");
764 if (!display) {
765 r = -EINVAL;
766 break;
767 }
768
769 r = omapfb_wait_for_go(fbi);
770 break;
771
772 /* LCD and CTRL tests do the same thing for backward
773 * compatibility */
774 case OMAPFB_LCD_TEST:
775 DBG("ioctl LCD_TEST\n");
776 if (get_user(p.test_num, (int __user *)arg)) {
777 r = -EFAULT;
778 break;
779 }
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200780 if (!display || !display->driver->run_test) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300781 r = -EINVAL;
782 break;
783 }
784
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200785 r = display->driver->run_test(display, p.test_num);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300786
787 break;
788
789 case OMAPFB_CTRL_TEST:
790 DBG("ioctl CTRL_TEST\n");
791 if (get_user(p.test_num, (int __user *)arg)) {
792 r = -EFAULT;
793 break;
794 }
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200795 if (!display || !display->driver->run_test) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300796 r = -EINVAL;
797 break;
798 }
799
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200800 r = display->driver->run_test(display, p.test_num);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300801
802 break;
803
804 case OMAPFB_MEMORY_READ:
805 DBG("ioctl MEMORY_READ\n");
806
807 if (copy_from_user(&p.memory_read, (void __user *)arg,
808 sizeof(p.memory_read))) {
809 r = -EFAULT;
810 break;
811 }
812
813 r = omapfb_memory_read(fbi, &p.memory_read);
814
815 break;
816
817 case OMAPFB_GET_VRAM_INFO: {
818 unsigned long vram, free, largest;
819
820 DBG("ioctl GET_VRAM_INFO\n");
821
822 omap_vram_get_info(&vram, &free, &largest);
823 p.vram_info.total = vram;
824 p.vram_info.free = free;
825 p.vram_info.largest_free_block = largest;
826
827 if (copy_to_user((void __user *)arg, &p.vram_info,
828 sizeof(p.vram_info)))
829 r = -EFAULT;
830 break;
831 }
832
833 case OMAPFB_SET_TEARSYNC: {
834 DBG("ioctl SET_TEARSYNC\n");
835
836 if (copy_from_user(&p.tearsync_info, (void __user *)arg,
837 sizeof(p.tearsync_info))) {
838 r = -EFAULT;
839 break;
840 }
841
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200842 if (!display->driver->enable_te) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300843 r = -ENODEV;
844 break;
845 }
846
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200847 r = display->driver->enable_te(display,
848 !!p.tearsync_info.enabled);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300849
850 break;
851 }
852
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200853 case OMAPFB_GET_DISPLAY_INFO: {
854 u16 xres, yres;
855
856 DBG("ioctl GET_DISPLAY_INFO\n");
857
858 if (display == NULL) {
859 r = -ENODEV;
860 break;
861 }
862
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200863 display->driver->get_resolution(display, &xres, &yres);
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200864
865 p.display_info.xres = xres;
866 p.display_info.yres = yres;
867 p.display_info.width = 0;
868 p.display_info.height = 0;
869
870 if (copy_to_user((void __user *)arg, &p.display_info,
871 sizeof(p.display_info)))
872 r = -EFAULT;
873 break;
874 }
875
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300876 default:
877 dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd);
878 r = -EINVAL;
879 }
880
881 if (r < 0)
882 DBG("ioctl failed: %d\n", r);
883
884 return r;
885}
886
887