blob: df7bcce5b107d82dcbc46803cffcade9178cea67 [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>
Paul Gortmakera8a35932011-07-10 13:20:26 -040030#include <linux/export.h>
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030031
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030032#include <video/omapdss.h>
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030033#include <plat/vrfb.h>
34#include <plat/vram.h>
35
36#include "omapfb.h"
37
Ville Syrjälä078ff542010-03-17 20:36:51 +020038static u8 get_mem_idx(struct omapfb_info *ofbi)
39{
40 if (ofbi->id == ofbi->region->id)
41 return 0;
42
43 return OMAPFB_MEM_IDX_ENABLED | ofbi->region->id;
44}
45
46static struct omapfb2_mem_region *get_mem_region(struct omapfb_info *ofbi,
47 u8 mem_idx)
48{
49 struct omapfb2_device *fbdev = ofbi->fbdev;
50
51 if (mem_idx & OMAPFB_MEM_IDX_ENABLED)
52 mem_idx &= OMAPFB_MEM_IDX_MASK;
53 else
54 mem_idx = ofbi->id;
55
56 if (mem_idx >= fbdev->num_fbs)
57 return NULL;
58
Ville Syrjälä3d84b652010-03-17 21:42:06 +020059 return &fbdev->regions[mem_idx];
Ville Syrjälä078ff542010-03-17 20:36:51 +020060}
61
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030062static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
63{
64 struct omapfb_info *ofbi = FB2OFB(fbi);
65 struct omapfb2_device *fbdev = ofbi->fbdev;
66 struct omap_overlay *ovl;
Ville Syrjälä078ff542010-03-17 20:36:51 +020067 struct omap_overlay_info old_info;
68 struct omapfb2_mem_region *old_rg, *new_rg;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030069 int r = 0;
70
71 DBG("omapfb_setup_plane\n");
72
73 if (ofbi->num_overlays != 1) {
74 r = -EINVAL;
75 goto out;
76 }
77
78 /* XXX uses only the first overlay */
79 ovl = ofbi->overlays[0];
80
Ville Syrjälä3d84b652010-03-17 21:42:06 +020081 old_rg = ofbi->region;
Ville Syrjälä078ff542010-03-17 20:36:51 +020082 new_rg = get_mem_region(ofbi, pi->mem_idx);
83 if (!new_rg) {
84 r = -EINVAL;
Ville Syrjälä3d84b652010-03-17 21:42:06 +020085 goto out;
Ville Syrjälä078ff542010-03-17 20:36:51 +020086 }
87
Ville Syrjälä3d84b652010-03-17 21:42:06 +020088 /* Take the locks in a specific order to keep lockdep happy */
89 if (old_rg->id < new_rg->id) {
90 omapfb_get_mem_region(old_rg);
91 omapfb_get_mem_region(new_rg);
92 } else if (new_rg->id < old_rg->id) {
93 omapfb_get_mem_region(new_rg);
94 omapfb_get_mem_region(old_rg);
95 } else
96 omapfb_get_mem_region(old_rg);
97
Ville Syrjälä078ff542010-03-17 20:36:51 +020098 if (pi->enabled && !new_rg->size) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030099 /*
100 * This plane's memory was freed, can't enable it
101 * until it's reallocated.
102 */
103 r = -EINVAL;
Ville Syrjälä3d84b652010-03-17 21:42:06 +0200104 goto put_mem;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300105 }
106
Ville Syrjälä078ff542010-03-17 20:36:51 +0200107 ovl->get_overlay_info(ovl, &old_info);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300108
Ville Syrjälä078ff542010-03-17 20:36:51 +0200109 if (old_rg != new_rg) {
110 ofbi->region = new_rg;
111 set_fb_fix(fbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300112 }
113
Ville Syrjälä078ff542010-03-17 20:36:51 +0200114 if (pi->enabled) {
115 struct omap_overlay_info info;
116
117 r = omapfb_setup_overlay(fbi, ovl, pi->pos_x, pi->pos_y,
118 pi->out_width, pi->out_height);
119 if (r)
120 goto undo;
121
122 ovl->get_overlay_info(ovl, &info);
123
124 if (!info.enabled) {
125 info.enabled = pi->enabled;
126 r = ovl->set_overlay_info(ovl, &info);
127 if (r)
128 goto undo;
129 }
130 } else {
131 struct omap_overlay_info info;
132
133 ovl->get_overlay_info(ovl, &info);
134
135 info.enabled = pi->enabled;
136 info.pos_x = pi->pos_x;
137 info.pos_y = pi->pos_y;
138 info.out_width = pi->out_width;
139 info.out_height = pi->out_height;
140
141 r = ovl->set_overlay_info(ovl, &info);
142 if (r)
143 goto undo;
144 }
145
146 if (ovl->manager)
147 ovl->manager->apply(ovl->manager);
148
Ville Syrjälä3d84b652010-03-17 21:42:06 +0200149 /* Release the locks in a specific order to keep lockdep happy */
150 if (old_rg->id > new_rg->id) {
151 omapfb_put_mem_region(old_rg);
152 omapfb_put_mem_region(new_rg);
153 } else if (new_rg->id > old_rg->id) {
154 omapfb_put_mem_region(new_rg);
155 omapfb_put_mem_region(old_rg);
156 } else
157 omapfb_put_mem_region(old_rg);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200158
Ville Syrjälä078ff542010-03-17 20:36:51 +0200159 return 0;
160
161 undo:
162 if (old_rg != new_rg) {
163 ofbi->region = old_rg;
164 set_fb_fix(fbi);
165 }
166
167 ovl->set_overlay_info(ovl, &old_info);
Ville Syrjälä3d84b652010-03-17 21:42:06 +0200168 put_mem:
169 /* Release the locks in a specific order to keep lockdep happy */
170 if (old_rg->id > new_rg->id) {
171 omapfb_put_mem_region(old_rg);
172 omapfb_put_mem_region(new_rg);
173 } else if (new_rg->id > old_rg->id) {
174 omapfb_put_mem_region(new_rg);
175 omapfb_put_mem_region(old_rg);
176 } else
177 omapfb_put_mem_region(old_rg);
Ville Syrjälä078ff542010-03-17 20:36:51 +0200178 out:
179 dev_err(fbdev->dev, "setup_plane failed\n");
180
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300181 return r;
182}
183
184static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
185{
186 struct omapfb_info *ofbi = FB2OFB(fbi);
187
188 if (ofbi->num_overlays != 1) {
189 memset(pi, 0, sizeof(*pi));
190 } else {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300191 struct omap_overlay *ovl;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200192 struct omap_overlay_info *ovli;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300193
194 ovl = ofbi->overlays[0];
195 ovli = &ovl->info;
196
197 pi->pos_x = ovli->pos_x;
198 pi->pos_y = ovli->pos_y;
199 pi->enabled = ovli->enabled;
200 pi->channel_out = 0; /* xxx */
201 pi->mirror = 0;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200202 pi->mem_idx = get_mem_idx(ofbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300203 pi->out_width = ovli->out_width;
204 pi->out_height = ovli->out_height;
205 }
206
207 return 0;
208}
209
210static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
211{
212 struct omapfb_info *ofbi = FB2OFB(fbi);
213 struct omapfb2_device *fbdev = ofbi->fbdev;
214 struct omapfb2_mem_region *rg;
Ville Syrjälä430571d2010-03-17 20:43:23 +0200215 int r = 0, i;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300216 size_t size;
217
218 if (mi->type > OMAPFB_MEMTYPE_MAX)
219 return -EINVAL;
220
221 size = PAGE_ALIGN(mi->size);
222
Ville Syrjälä078ff542010-03-17 20:36:51 +0200223 rg = ofbi->region;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300224
Ville Syrjälä3d84b652010-03-17 21:42:06 +0200225 down_write_nested(&rg->lock, rg->id);
Ville Syrjälä1ceafc02010-03-17 21:28:50 +0200226 atomic_inc(&rg->lock_count);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200227
228 if (atomic_read(&rg->map_count)) {
229 r = -EBUSY;
230 goto out;
231 }
Ville Syrjälä078ff542010-03-17 20:36:51 +0200232
233 for (i = 0; i < fbdev->num_fbs; i++) {
234 struct omapfb_info *ofbi2 = FB2OFB(fbdev->fbs[i]);
235 int j;
236
237 if (ofbi2->region != rg)
238 continue;
239
240 for (j = 0; j < ofbi2->num_overlays; j++) {
241 if (ofbi2->overlays[j]->info.enabled) {
242 r = -EBUSY;
Ville Syrjälä430571d2010-03-17 20:43:23 +0200243 goto out;
Ville Syrjälä078ff542010-03-17 20:36:51 +0200244 }
245 }
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300246 }
247
248 if (rg->size != size || rg->type != mi->type) {
249 r = omapfb_realloc_fbmem(fbi, size, mi->type);
250 if (r) {
251 dev_err(fbdev->dev, "realloc fbmem failed\n");
Ville Syrjälä430571d2010-03-17 20:43:23 +0200252 goto out;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300253 }
254 }
255
Ville Syrjälä430571d2010-03-17 20:43:23 +0200256 out:
Ville Syrjälä1ceafc02010-03-17 21:28:50 +0200257 atomic_dec(&rg->lock_count);
Ville Syrjälä2f642a12010-03-17 20:58:03 +0200258 up_write(&rg->lock);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200259
260 return r;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300261}
262
263static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
264{
265 struct omapfb_info *ofbi = FB2OFB(fbi);
266 struct omapfb2_mem_region *rg;
267
Ville Syrjälä430571d2010-03-17 20:43:23 +0200268 rg = omapfb_get_mem_region(ofbi->region);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300269 memset(mi, 0, sizeof(*mi));
270
271 mi->size = rg->size;
272 mi->type = rg->type;
273
Ville Syrjälä430571d2010-03-17 20:43:23 +0200274 omapfb_put_mem_region(rg);
275
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300276 return 0;
277}
278
279static int omapfb_update_window_nolock(struct fb_info *fbi,
280 u32 x, u32 y, u32 w, u32 h)
281{
282 struct omap_dss_device *display = fb2display(fbi);
283 u16 dw, dh;
284
285 if (!display)
286 return 0;
287
288 if (w == 0 || h == 0)
289 return 0;
290
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200291 display->driver->get_resolution(display, &dw, &dh);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300292
293 if (x + w > dw || y + h > dh)
294 return -EINVAL;
295
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200296 return display->driver->update(display, x, y, w, h);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300297}
298
299/* This function is exported for SGX driver use */
300int omapfb_update_window(struct fb_info *fbi,
301 u32 x, u32 y, u32 w, u32 h)
302{
303 struct omapfb_info *ofbi = FB2OFB(fbi);
304 struct omapfb2_device *fbdev = ofbi->fbdev;
305 int r;
306
Jani Nikula27b67c92010-03-18 10:32:06 +0100307 if (!lock_fb_info(fbi))
308 return -ENODEV;
Jani Nikula238a4132010-03-18 10:32:05 +0100309 omapfb_lock(fbdev);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300310
311 r = omapfb_update_window_nolock(fbi, x, y, w, h);
312
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300313 omapfb_unlock(fbdev);
Jani Nikula238a4132010-03-18 10:32:05 +0100314 unlock_fb_info(fbi);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300315
316 return r;
317}
318EXPORT_SYMBOL(omapfb_update_window);
319
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300320int omapfb_set_update_mode(struct fb_info *fbi,
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300321 enum omapfb_update_mode mode)
322{
323 struct omap_dss_device *display = fb2display(fbi);
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300324 struct omapfb_info *ofbi = FB2OFB(fbi);
325 struct omapfb2_device *fbdev = ofbi->fbdev;
326 struct omapfb_display_data *d;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300327 int r;
328
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200329 if (!display)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300330 return -EINVAL;
331
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300332 if (mode != OMAPFB_AUTO_UPDATE && mode != OMAPFB_MANUAL_UPDATE)
333 return -EINVAL;
334
335 omapfb_lock(fbdev);
336
337 d = get_display_data(fbdev, display);
338
339 if (d->update_mode == mode) {
340 omapfb_unlock(fbdev);
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200341 return 0;
342 }
343
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300344 r = 0;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300345
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300346 if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
347 if (mode == OMAPFB_AUTO_UPDATE)
348 omapfb_start_auto_update(fbdev, display);
349 else /* MANUAL_UPDATE */
350 omapfb_stop_auto_update(fbdev, display);
351
352 d->update_mode = mode;
353 } else { /* AUTO_UPDATE */
354 if (mode == OMAPFB_MANUAL_UPDATE)
355 r = -EINVAL;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300356 }
357
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300358 omapfb_unlock(fbdev);
359
360 return r;
361}
362
363int omapfb_get_update_mode(struct fb_info *fbi,
364 enum omapfb_update_mode *mode)
365{
366 struct omap_dss_device *display = fb2display(fbi);
367 struct omapfb_info *ofbi = FB2OFB(fbi);
368 struct omapfb2_device *fbdev = ofbi->fbdev;
369 struct omapfb_display_data *d;
370
371 if (!display)
372 return -EINVAL;
373
374 omapfb_lock(fbdev);
375
376 d = get_display_data(fbdev, display);
377
378 *mode = d->update_mode;
379
380 omapfb_unlock(fbdev);
381
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300382 return 0;
383}
384
385/* XXX this color key handling is a hack... */
386static struct omapfb_color_key omapfb_color_keys[2];
387
388static int _omapfb_set_color_key(struct omap_overlay_manager *mgr,
389 struct omapfb_color_key *ck)
390{
391 struct omap_overlay_manager_info info;
392 enum omap_dss_trans_key_type kt;
393 int r;
394
395 mgr->get_manager_info(mgr, &info);
396
397 if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) {
398 info.trans_enabled = false;
399 omapfb_color_keys[mgr->id] = *ck;
400
401 r = mgr->set_manager_info(mgr, &info);
402 if (r)
403 return r;
404
405 r = mgr->apply(mgr);
406
407 return r;
408 }
409
410 switch (ck->key_type) {
411 case OMAPFB_COLOR_KEY_GFX_DST:
412 kt = OMAP_DSS_COLOR_KEY_GFX_DST;
413 break;
414 case OMAPFB_COLOR_KEY_VID_SRC:
415 kt = OMAP_DSS_COLOR_KEY_VID_SRC;
416 break;
417 default:
418 return -EINVAL;
419 }
420
421 info.default_color = ck->background;
422 info.trans_key = ck->trans_key;
423 info.trans_key_type = kt;
424 info.trans_enabled = true;
425
426 omapfb_color_keys[mgr->id] = *ck;
427
428 r = mgr->set_manager_info(mgr, &info);
429 if (r)
430 return r;
431
432 r = mgr->apply(mgr);
433
434 return r;
435}
436
437static int omapfb_set_color_key(struct fb_info *fbi,
438 struct omapfb_color_key *ck)
439{
440 struct omapfb_info *ofbi = FB2OFB(fbi);
441 struct omapfb2_device *fbdev = ofbi->fbdev;
442 int r;
443 int i;
444 struct omap_overlay_manager *mgr = NULL;
445
446 omapfb_lock(fbdev);
447
448 for (i = 0; i < ofbi->num_overlays; i++) {
449 if (ofbi->overlays[i]->manager) {
450 mgr = ofbi->overlays[i]->manager;
451 break;
452 }
453 }
454
455 if (!mgr) {
456 r = -EINVAL;
457 goto err;
458 }
459
460 r = _omapfb_set_color_key(mgr, ck);
461err:
462 omapfb_unlock(fbdev);
463
464 return r;
465}
466
467static int omapfb_get_color_key(struct fb_info *fbi,
468 struct omapfb_color_key *ck)
469{
470 struct omapfb_info *ofbi = FB2OFB(fbi);
471 struct omapfb2_device *fbdev = ofbi->fbdev;
472 struct omap_overlay_manager *mgr = NULL;
473 int r = 0;
474 int i;
475
476 omapfb_lock(fbdev);
477
478 for (i = 0; i < ofbi->num_overlays; i++) {
479 if (ofbi->overlays[i]->manager) {
480 mgr = ofbi->overlays[i]->manager;
481 break;
482 }
483 }
484
485 if (!mgr) {
486 r = -EINVAL;
487 goto err;
488 }
489
490 *ck = omapfb_color_keys[mgr->id];
491err:
492 omapfb_unlock(fbdev);
493
494 return r;
495}
496
497static int omapfb_memory_read(struct fb_info *fbi,
498 struct omapfb_memory_read *mr)
499{
500 struct omap_dss_device *display = fb2display(fbi);
501 void *buf;
502 int r;
503
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200504 if (!display || !display->driver->memory_read)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300505 return -ENOENT;
506
507 if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
508 return -EFAULT;
509
510 if (mr->w * mr->h * 3 > mr->buffer_size)
511 return -EINVAL;
512
513 buf = vmalloc(mr->buffer_size);
514 if (!buf) {
515 DBG("vmalloc failed\n");
516 return -ENOMEM;
517 }
518
Tomi Valkeinenc75d9462010-01-08 16:56:44 +0200519 r = display->driver->memory_read(display, buf, mr->buffer_size,
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300520 mr->x, mr->y, mr->w, mr->h);
521
522 if (r > 0) {
523 if (copy_to_user(mr->buffer, buf, mr->buffer_size))
524 r = -EFAULT;
525 }
526
527 vfree(buf);
528
529 return r;
530}
531
532static int omapfb_get_ovl_colormode(struct omapfb2_device *fbdev,
533 struct omapfb_ovl_colormode *mode)
534{
535 int ovl_idx = mode->overlay_idx;
536 int mode_idx = mode->mode_idx;
537 struct omap_overlay *ovl;
538 enum omap_color_mode supported_modes;
539 struct fb_var_screeninfo var;
540 int i;
541
542 if (ovl_idx >= fbdev->num_overlays)
543 return -ENODEV;
544 ovl = fbdev->overlays[ovl_idx];
545 supported_modes = ovl->supported_modes;
546
547 mode_idx = mode->mode_idx;
548
549 for (i = 0; i < sizeof(supported_modes) * 8; i++) {
550 if (!(supported_modes & (1 << i)))
551 continue;
552 /*
553 * It's possible that the FB doesn't support a mode
554 * that is supported by the overlay, so call the
555 * following here.
556 */
557 if (dss_mode_to_fb_mode(1 << i, &var) < 0)
558 continue;
559
560 mode_idx--;
561 if (mode_idx < 0)
562 break;
563 }
564
565 if (i == sizeof(supported_modes) * 8)
566 return -ENOENT;
567
568 mode->bits_per_pixel = var.bits_per_pixel;
569 mode->nonstd = var.nonstd;
570 mode->red = var.red;
571 mode->green = var.green;
572 mode->blue = var.blue;
573 mode->transp = var.transp;
574
575 return 0;
576}
577
578static int omapfb_wait_for_go(struct fb_info *fbi)
579{
580 struct omapfb_info *ofbi = FB2OFB(fbi);
581 int r = 0;
582 int i;
583
584 for (i = 0; i < ofbi->num_overlays; ++i) {
585 struct omap_overlay *ovl = ofbi->overlays[i];
586 r = ovl->wait_for_go(ovl);
587 if (r)
588 break;
589 }
590
591 return r;
592}
593
594int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
595{
596 struct omapfb_info *ofbi = FB2OFB(fbi);
597 struct omapfb2_device *fbdev = ofbi->fbdev;
598 struct omap_dss_device *display = fb2display(fbi);
599
600 union {
601 struct omapfb_update_window_old uwnd_o;
602 struct omapfb_update_window uwnd;
603 struct omapfb_plane_info plane_info;
604 struct omapfb_caps caps;
605 struct omapfb_mem_info mem_info;
606 struct omapfb_color_key color_key;
607 struct omapfb_ovl_colormode ovl_colormode;
608 enum omapfb_update_mode update_mode;
609 int test_num;
610 struct omapfb_memory_read memory_read;
611 struct omapfb_vram_info vram_info;
612 struct omapfb_tearsync_info tearsync_info;
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200613 struct omapfb_display_info display_info;
Grazvydas Ignotasece350d2010-07-02 22:54:56 +0200614 u32 crt;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300615 } p;
616
617 int r = 0;
618
619 switch (cmd) {
620 case OMAPFB_SYNC_GFX:
621 DBG("ioctl SYNC_GFX\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200622 if (!display || !display->driver->sync) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300623 /* DSS1 never returns an error here, so we neither */
624 /*r = -EINVAL;*/
625 break;
626 }
627
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200628 r = display->driver->sync(display);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300629 break;
630
631 case OMAPFB_UPDATE_WINDOW_OLD:
632 DBG("ioctl UPDATE_WINDOW_OLD\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200633 if (!display || !display->driver->update) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300634 r = -EINVAL;
635 break;
636 }
637
638 if (copy_from_user(&p.uwnd_o,
639 (void __user *)arg,
640 sizeof(p.uwnd_o))) {
641 r = -EFAULT;
642 break;
643 }
644
645 r = omapfb_update_window_nolock(fbi, p.uwnd_o.x, p.uwnd_o.y,
646 p.uwnd_o.width, p.uwnd_o.height);
647 break;
648
649 case OMAPFB_UPDATE_WINDOW:
650 DBG("ioctl UPDATE_WINDOW\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200651 if (!display || !display->driver->update) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300652 r = -EINVAL;
653 break;
654 }
655
656 if (copy_from_user(&p.uwnd, (void __user *)arg,
657 sizeof(p.uwnd))) {
658 r = -EFAULT;
659 break;
660 }
661
662 r = omapfb_update_window_nolock(fbi, p.uwnd.x, p.uwnd.y,
663 p.uwnd.width, p.uwnd.height);
664 break;
665
666 case OMAPFB_SETUP_PLANE:
667 DBG("ioctl SETUP_PLANE\n");
668 if (copy_from_user(&p.plane_info, (void __user *)arg,
669 sizeof(p.plane_info)))
670 r = -EFAULT;
671 else
672 r = omapfb_setup_plane(fbi, &p.plane_info);
673 break;
674
675 case OMAPFB_QUERY_PLANE:
676 DBG("ioctl QUERY_PLANE\n");
677 r = omapfb_query_plane(fbi, &p.plane_info);
678 if (r < 0)
679 break;
680 if (copy_to_user((void __user *)arg, &p.plane_info,
681 sizeof(p.plane_info)))
682 r = -EFAULT;
683 break;
684
685 case OMAPFB_SETUP_MEM:
686 DBG("ioctl SETUP_MEM\n");
687 if (copy_from_user(&p.mem_info, (void __user *)arg,
688 sizeof(p.mem_info)))
689 r = -EFAULT;
690 else
691 r = omapfb_setup_mem(fbi, &p.mem_info);
692 break;
693
694 case OMAPFB_QUERY_MEM:
695 DBG("ioctl QUERY_MEM\n");
696 r = omapfb_query_mem(fbi, &p.mem_info);
697 if (r < 0)
698 break;
699 if (copy_to_user((void __user *)arg, &p.mem_info,
700 sizeof(p.mem_info)))
701 r = -EFAULT;
702 break;
703
704 case OMAPFB_GET_CAPS:
705 DBG("ioctl GET_CAPS\n");
706 if (!display) {
707 r = -EINVAL;
708 break;
709 }
710
711 memset(&p.caps, 0, sizeof(p.caps));
712 if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
713 p.caps.ctrl |= OMAPFB_CAPS_MANUAL_UPDATE;
714 if (display->caps & OMAP_DSS_DISPLAY_CAP_TEAR_ELIM)
715 p.caps.ctrl |= OMAPFB_CAPS_TEARSYNC;
716
717 if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
718 r = -EFAULT;
719 break;
720
721 case OMAPFB_GET_OVERLAY_COLORMODE:
722 DBG("ioctl GET_OVERLAY_COLORMODE\n");
723 if (copy_from_user(&p.ovl_colormode, (void __user *)arg,
724 sizeof(p.ovl_colormode))) {
725 r = -EFAULT;
726 break;
727 }
728 r = omapfb_get_ovl_colormode(fbdev, &p.ovl_colormode);
729 if (r < 0)
730 break;
731 if (copy_to_user((void __user *)arg, &p.ovl_colormode,
732 sizeof(p.ovl_colormode)))
733 r = -EFAULT;
734 break;
735
736 case OMAPFB_SET_UPDATE_MODE:
737 DBG("ioctl SET_UPDATE_MODE\n");
738 if (get_user(p.update_mode, (int __user *)arg))
739 r = -EFAULT;
740 else
741 r = omapfb_set_update_mode(fbi, p.update_mode);
742 break;
743
744 case OMAPFB_GET_UPDATE_MODE:
745 DBG("ioctl GET_UPDATE_MODE\n");
746 r = omapfb_get_update_mode(fbi, &p.update_mode);
747 if (r)
748 break;
749 if (put_user(p.update_mode,
750 (enum omapfb_update_mode __user *)arg))
751 r = -EFAULT;
752 break;
753
754 case OMAPFB_SET_COLOR_KEY:
755 DBG("ioctl SET_COLOR_KEY\n");
756 if (copy_from_user(&p.color_key, (void __user *)arg,
757 sizeof(p.color_key)))
758 r = -EFAULT;
759 else
760 r = omapfb_set_color_key(fbi, &p.color_key);
761 break;
762
763 case OMAPFB_GET_COLOR_KEY:
764 DBG("ioctl GET_COLOR_KEY\n");
765 r = omapfb_get_color_key(fbi, &p.color_key);
766 if (r)
767 break;
768 if (copy_to_user((void __user *)arg, &p.color_key,
769 sizeof(p.color_key)))
770 r = -EFAULT;
771 break;
772
Grazvydas Ignotasece350d2010-07-02 22:54:56 +0200773 case FBIO_WAITFORVSYNC:
774 if (get_user(p.crt, (__u32 __user *)arg)) {
775 r = -EFAULT;
776 break;
777 }
778 if (p.crt != 0) {
779 r = -ENODEV;
780 break;
781 }
782 /* FALLTHROUGH */
783
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300784 case OMAPFB_WAITFORVSYNC:
785 DBG("ioctl WAITFORVSYNC\n");
786 if (!display) {
787 r = -EINVAL;
788 break;
789 }
790
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200791 r = display->manager->wait_for_vsync(display->manager);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300792 break;
793
794 case OMAPFB_WAITFORGO:
795 DBG("ioctl WAITFORGO\n");
796 if (!display) {
797 r = -EINVAL;
798 break;
799 }
800
801 r = omapfb_wait_for_go(fbi);
802 break;
803
804 /* LCD and CTRL tests do the same thing for backward
805 * compatibility */
806 case OMAPFB_LCD_TEST:
807 DBG("ioctl LCD_TEST\n");
808 if (get_user(p.test_num, (int __user *)arg)) {
809 r = -EFAULT;
810 break;
811 }
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200812 if (!display || !display->driver->run_test) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300813 r = -EINVAL;
814 break;
815 }
816
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200817 r = display->driver->run_test(display, p.test_num);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300818
819 break;
820
821 case OMAPFB_CTRL_TEST:
822 DBG("ioctl CTRL_TEST\n");
823 if (get_user(p.test_num, (int __user *)arg)) {
824 r = -EFAULT;
825 break;
826 }
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200827 if (!display || !display->driver->run_test) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300828 r = -EINVAL;
829 break;
830 }
831
Tomi Valkeinen1a75ef42010-01-08 16:21:28 +0200832 r = display->driver->run_test(display, p.test_num);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300833
834 break;
835
836 case OMAPFB_MEMORY_READ:
837 DBG("ioctl MEMORY_READ\n");
838
839 if (copy_from_user(&p.memory_read, (void __user *)arg,
840 sizeof(p.memory_read))) {
841 r = -EFAULT;
842 break;
843 }
844
845 r = omapfb_memory_read(fbi, &p.memory_read);
846
847 break;
848
849 case OMAPFB_GET_VRAM_INFO: {
850 unsigned long vram, free, largest;
851
852 DBG("ioctl GET_VRAM_INFO\n");
853
854 omap_vram_get_info(&vram, &free, &largest);
855 p.vram_info.total = vram;
856 p.vram_info.free = free;
857 p.vram_info.largest_free_block = largest;
858
859 if (copy_to_user((void __user *)arg, &p.vram_info,
860 sizeof(p.vram_info)))
861 r = -EFAULT;
862 break;
863 }
864
865 case OMAPFB_SET_TEARSYNC: {
866 DBG("ioctl SET_TEARSYNC\n");
867
868 if (copy_from_user(&p.tearsync_info, (void __user *)arg,
869 sizeof(p.tearsync_info))) {
870 r = -EFAULT;
871 break;
872 }
873
Jani Nikula93255882010-06-01 15:12:12 +0300874 if (!display || !display->driver->enable_te) {
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300875 r = -ENODEV;
876 break;
877 }
878
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200879 r = display->driver->enable_te(display,
880 !!p.tearsync_info.enabled);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300881
882 break;
883 }
884
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200885 case OMAPFB_GET_DISPLAY_INFO: {
886 u16 xres, yres;
887
888 DBG("ioctl GET_DISPLAY_INFO\n");
889
890 if (display == NULL) {
891 r = -ENODEV;
892 break;
893 }
894
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200895 display->driver->get_resolution(display, &xres, &yres);
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200896
897 p.display_info.xres = xres;
898 p.display_info.yres = yres;
Jani Nikula7a0987b2010-06-16 15:26:36 +0300899
900 if (display->driver->get_dimensions) {
901 u32 w, h;
902 display->driver->get_dimensions(display, &w, &h);
903 p.display_info.width = w;
904 p.display_info.height = h;
905 } else {
906 p.display_info.width = 0;
907 p.display_info.height = 0;
908 }
Tomi Valkeinen6dd2e422010-01-14 17:32:13 +0200909
910 if (copy_to_user((void __user *)arg, &p.display_info,
911 sizeof(p.display_info)))
912 r = -EFAULT;
913 break;
914 }
915
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300916 default:
917 dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd);
918 r = -EINVAL;
919 }
920
921 if (r < 0)
922 DBG("ioctl failed: %d\n", r);
923
924 return r;
925}
926
927