linux/drivers/video/omap2/omapfb/omapfb-ioctl.c
<<
>>
Prefs
   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#include <linux/export.h>
  31
  32#include <video/omapdss.h>
  33#include <plat/vrfb.h>
  34#include <plat/vram.h>
  35
  36#include "omapfb.h"
  37
  38static 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
  59        return &fbdev->regions[mem_idx];
  60}
  61
  62static 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;
  67        struct omap_overlay_info old_info;
  68        struct omapfb2_mem_region *old_rg, *new_rg;
  69        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
  81        old_rg = ofbi->region;
  82        new_rg = get_mem_region(ofbi, pi->mem_idx);
  83        if (!new_rg) {
  84                r = -EINVAL;
  85                goto out;
  86        }
  87
  88        /* 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
  98        if (pi->enabled && !new_rg->size) {
  99                /*
 100                 * This plane's memory was freed, can't enable it
 101                 * until it's reallocated.
 102                 */
 103                r = -EINVAL;
 104                goto put_mem;
 105        }
 106
 107        ovl->get_overlay_info(ovl, &old_info);
 108
 109        if (old_rg != new_rg) {
 110                ofbi->region = new_rg;
 111                set_fb_fix(fbi);
 112        }
 113
 114        if (!pi->enabled) {
 115                r = ovl->disable(ovl);
 116                if (r)
 117                        goto undo;
 118        }
 119
 120        if (pi->enabled) {
 121                r = omapfb_setup_overlay(fbi, ovl, pi->pos_x, pi->pos_y,
 122                        pi->out_width, pi->out_height);
 123                if (r)
 124                        goto undo;
 125        } else {
 126                struct omap_overlay_info info;
 127
 128                ovl->get_overlay_info(ovl, &info);
 129
 130                info.pos_x = pi->pos_x;
 131                info.pos_y = pi->pos_y;
 132                info.out_width = pi->out_width;
 133                info.out_height = pi->out_height;
 134
 135                r = ovl->set_overlay_info(ovl, &info);
 136                if (r)
 137                        goto undo;
 138        }
 139
 140        if (ovl->manager)
 141                ovl->manager->apply(ovl->manager);
 142
 143        if (pi->enabled) {
 144                r = ovl->enable(ovl);
 145                if (r)
 146                        goto undo;
 147        }
 148
 149        /* 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);
 158
 159        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);
 168 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);
 178 out:
 179        dev_err(fbdev->dev, "setup_plane failed\n");
 180
 181        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 {
 191                struct omap_overlay *ovl;
 192                struct omap_overlay_info ovli;
 193
 194                ovl = ofbi->overlays[0];
 195                ovl->get_overlay_info(ovl, &ovli);
 196
 197                pi->pos_x = ovli.pos_x;
 198                pi->pos_y = ovli.pos_y;
 199                pi->enabled = ovl->is_enabled(ovl);
 200                pi->channel_out = 0; /* xxx */
 201                pi->mirror = 0;
 202                pi->mem_idx = get_mem_idx(ofbi);
 203                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;
 215        int r = 0, i;
 216        size_t size;
 217
 218        if (mi->type != OMAPFB_MEMTYPE_SDRAM)
 219                return -EINVAL;
 220
 221        size = PAGE_ALIGN(mi->size);
 222
 223        rg = ofbi->region;
 224
 225        down_write_nested(&rg->lock, rg->id);
 226        atomic_inc(&rg->lock_count);
 227
 228        if (atomic_read(&rg->map_count)) {
 229                r = -EBUSY;
 230                goto out;
 231        }
 232
 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                        struct omap_overlay *ovl;
 242                        ovl = ofbi2->overlays[j];
 243                        if (ovl->is_enabled(ovl)) {
 244                                r = -EBUSY;
 245                                goto out;
 246                        }
 247                }
 248        }
 249
 250        if (rg->size != size || rg->type != mi->type) {
 251                r = omapfb_realloc_fbmem(fbi, size, mi->type);
 252                if (r) {
 253                        dev_err(fbdev->dev, "realloc fbmem failed\n");
 254                        goto out;
 255                }
 256        }
 257
 258 out:
 259        atomic_dec(&rg->lock_count);
 260        up_write(&rg->lock);
 261
 262        return r;
 263}
 264
 265static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
 266{
 267        struct omapfb_info *ofbi = FB2OFB(fbi);
 268        struct omapfb2_mem_region *rg;
 269
 270        rg = omapfb_get_mem_region(ofbi->region);
 271        memset(mi, 0, sizeof(*mi));
 272
 273        mi->size = rg->size;
 274        mi->type = rg->type;
 275
 276        omapfb_put_mem_region(rg);
 277
 278        return 0;
 279}
 280
 281static int omapfb_update_window_nolock(struct fb_info *fbi,
 282                u32 x, u32 y, u32 w, u32 h)
 283{
 284        struct omap_dss_device *display = fb2display(fbi);
 285        u16 dw, dh;
 286
 287        if (!display)
 288                return 0;
 289
 290        if (w == 0 || h == 0)
 291                return 0;
 292
 293        display->driver->get_resolution(display, &dw, &dh);
 294
 295        if (x + w > dw || y + h > dh)
 296                return -EINVAL;
 297
 298        return display->driver->update(display, x, y, w, h);
 299}
 300
 301/* This function is exported for SGX driver use */
 302int omapfb_update_window(struct fb_info *fbi,
 303                u32 x, u32 y, u32 w, u32 h)
 304{
 305        struct omapfb_info *ofbi = FB2OFB(fbi);
 306        struct omapfb2_device *fbdev = ofbi->fbdev;
 307        int r;
 308
 309        if (!lock_fb_info(fbi))
 310                return -ENODEV;
 311        omapfb_lock(fbdev);
 312
 313        r = omapfb_update_window_nolock(fbi, x, y, w, h);
 314
 315        omapfb_unlock(fbdev);
 316        unlock_fb_info(fbi);
 317
 318        return r;
 319}
 320EXPORT_SYMBOL(omapfb_update_window);
 321
 322int omapfb_set_update_mode(struct fb_info *fbi,
 323                                   enum omapfb_update_mode mode)
 324{
 325        struct omap_dss_device *display = fb2display(fbi);
 326        struct omapfb_info *ofbi = FB2OFB(fbi);
 327        struct omapfb2_device *fbdev = ofbi->fbdev;
 328        struct omapfb_display_data *d;
 329        int r;
 330
 331        if (!display)
 332                return -EINVAL;
 333
 334        if (mode != OMAPFB_AUTO_UPDATE && mode != OMAPFB_MANUAL_UPDATE)
 335                return -EINVAL;
 336
 337        omapfb_lock(fbdev);
 338
 339        d = get_display_data(fbdev, display);
 340
 341        if (d->update_mode == mode) {
 342                omapfb_unlock(fbdev);
 343                return 0;
 344        }
 345
 346        r = 0;
 347
 348        if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
 349                if (mode == OMAPFB_AUTO_UPDATE)
 350                        omapfb_start_auto_update(fbdev, display);
 351                else /* MANUAL_UPDATE */
 352                        omapfb_stop_auto_update(fbdev, display);
 353
 354                d->update_mode = mode;
 355        } else { /* AUTO_UPDATE */
 356                if (mode == OMAPFB_MANUAL_UPDATE)
 357                        r = -EINVAL;
 358        }
 359
 360        omapfb_unlock(fbdev);
 361
 362        return r;
 363}
 364
 365int omapfb_get_update_mode(struct fb_info *fbi,
 366                enum omapfb_update_mode *mode)
 367{
 368        struct omap_dss_device *display = fb2display(fbi);
 369        struct omapfb_info *ofbi = FB2OFB(fbi);
 370        struct omapfb2_device *fbdev = ofbi->fbdev;
 371        struct omapfb_display_data *d;
 372
 373        if (!display)
 374                return -EINVAL;
 375
 376        omapfb_lock(fbdev);
 377
 378        d = get_display_data(fbdev, display);
 379
 380        *mode = d->update_mode;
 381
 382        omapfb_unlock(fbdev);
 383
 384        return 0;
 385}
 386
 387/* XXX this color key handling is a hack... */
 388static struct omapfb_color_key omapfb_color_keys[2];
 389
 390static int _omapfb_set_color_key(struct omap_overlay_manager *mgr,
 391                struct omapfb_color_key *ck)
 392{
 393        struct omap_overlay_manager_info info;
 394        enum omap_dss_trans_key_type kt;
 395        int r;
 396
 397        mgr->get_manager_info(mgr, &info);
 398
 399        if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) {
 400                info.trans_enabled = false;
 401                omapfb_color_keys[mgr->id] = *ck;
 402
 403                r = mgr->set_manager_info(mgr, &info);
 404                if (r)
 405                        return r;
 406
 407                r = mgr->apply(mgr);
 408
 409                return r;
 410        }
 411
 412        switch (ck->key_type) {
 413        case OMAPFB_COLOR_KEY_GFX_DST:
 414                kt = OMAP_DSS_COLOR_KEY_GFX_DST;
 415                break;
 416        case OMAPFB_COLOR_KEY_VID_SRC:
 417                kt = OMAP_DSS_COLOR_KEY_VID_SRC;
 418                break;
 419        default:
 420                return -EINVAL;
 421        }
 422
 423        info.default_color = ck->background;
 424        info.trans_key = ck->trans_key;
 425        info.trans_key_type = kt;
 426        info.trans_enabled = true;
 427
 428        omapfb_color_keys[mgr->id] = *ck;
 429
 430        r = mgr->set_manager_info(mgr, &info);
 431        if (r)
 432                return r;
 433
 434        r = mgr->apply(mgr);
 435
 436        return r;
 437}
 438
 439static int omapfb_set_color_key(struct fb_info *fbi,
 440                struct omapfb_color_key *ck)
 441{
 442        struct omapfb_info *ofbi = FB2OFB(fbi);
 443        struct omapfb2_device *fbdev = ofbi->fbdev;
 444        int r;
 445        int i;
 446        struct omap_overlay_manager *mgr = NULL;
 447
 448        omapfb_lock(fbdev);
 449
 450        for (i = 0; i < ofbi->num_overlays; i++) {
 451                if (ofbi->overlays[i]->manager) {
 452                        mgr = ofbi->overlays[i]->manager;
 453                        break;
 454                }
 455        }
 456
 457        if (!mgr) {
 458                r = -EINVAL;
 459                goto err;
 460        }
 461
 462        r = _omapfb_set_color_key(mgr, ck);
 463err:
 464        omapfb_unlock(fbdev);
 465
 466        return r;
 467}
 468
 469static int omapfb_get_color_key(struct fb_info *fbi,
 470                struct omapfb_color_key *ck)
 471{
 472        struct omapfb_info *ofbi = FB2OFB(fbi);
 473        struct omapfb2_device *fbdev = ofbi->fbdev;
 474        struct omap_overlay_manager *mgr = NULL;
 475        int r = 0;
 476        int i;
 477
 478        omapfb_lock(fbdev);
 479
 480        for (i = 0; i < ofbi->num_overlays; i++) {
 481                if (ofbi->overlays[i]->manager) {
 482                        mgr = ofbi->overlays[i]->manager;
 483                        break;
 484                }
 485        }
 486
 487        if (!mgr) {
 488                r = -EINVAL;
 489                goto err;
 490        }
 491
 492        *ck = omapfb_color_keys[mgr->id];
 493err:
 494        omapfb_unlock(fbdev);
 495
 496        return r;
 497}
 498
 499static int omapfb_memory_read(struct fb_info *fbi,
 500                struct omapfb_memory_read *mr)
 501{
 502        struct omap_dss_device *display = fb2display(fbi);
 503        void *buf;
 504        int r;
 505
 506        if (!display || !display->driver->memory_read)
 507                return -ENOENT;
 508
 509        if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
 510                return -EFAULT;
 511
 512        if (mr->w * mr->h * 3 > mr->buffer_size)
 513                return -EINVAL;
 514
 515        buf = vmalloc(mr->buffer_size);
 516        if (!buf) {
 517                DBG("vmalloc failed\n");
 518                return -ENOMEM;
 519        }
 520
 521        r = display->driver->memory_read(display, buf, mr->buffer_size,
 522                        mr->x, mr->y, mr->w, mr->h);
 523
 524        if (r > 0) {
 525                if (copy_to_user(mr->buffer, buf, mr->buffer_size))
 526                        r = -EFAULT;
 527        }
 528
 529        vfree(buf);
 530
 531        return r;
 532}
 533
 534static int omapfb_get_ovl_colormode(struct omapfb2_device *fbdev,
 535                             struct omapfb_ovl_colormode *mode)
 536{
 537        int ovl_idx = mode->overlay_idx;
 538        int mode_idx = mode->mode_idx;
 539        struct omap_overlay *ovl;
 540        enum omap_color_mode supported_modes;
 541        struct fb_var_screeninfo var;
 542        int i;
 543
 544        if (ovl_idx >= fbdev->num_overlays)
 545                return -ENODEV;
 546        ovl = fbdev->overlays[ovl_idx];
 547        supported_modes = ovl->supported_modes;
 548
 549        mode_idx = mode->mode_idx;
 550
 551        for (i = 0; i < sizeof(supported_modes) * 8; i++) {
 552                if (!(supported_modes & (1 << i)))
 553                        continue;
 554                /*
 555                 * It's possible that the FB doesn't support a mode
 556                 * that is supported by the overlay, so call the
 557                 * following here.
 558                 */
 559                if (dss_mode_to_fb_mode(1 << i, &var) < 0)
 560                        continue;
 561
 562                mode_idx--;
 563                if (mode_idx < 0)
 564                        break;
 565        }
 566
 567        if (i == sizeof(supported_modes) * 8)
 568                return -ENOENT;
 569
 570        mode->bits_per_pixel = var.bits_per_pixel;
 571        mode->nonstd = var.nonstd;
 572        mode->red = var.red;
 573        mode->green = var.green;
 574        mode->blue = var.blue;
 575        mode->transp = var.transp;
 576
 577        return 0;
 578}
 579
 580static int omapfb_wait_for_go(struct fb_info *fbi)
 581{
 582        struct omapfb_info *ofbi = FB2OFB(fbi);
 583        int r = 0;
 584        int i;
 585
 586        for (i = 0; i < ofbi->num_overlays; ++i) {
 587                struct omap_overlay *ovl = ofbi->overlays[i];
 588                r = ovl->wait_for_go(ovl);
 589                if (r)
 590                        break;
 591        }
 592
 593        return r;
 594}
 595
 596int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
 597{
 598        struct omapfb_info *ofbi = FB2OFB(fbi);
 599        struct omapfb2_device *fbdev = ofbi->fbdev;
 600        struct omap_dss_device *display = fb2display(fbi);
 601
 602        union {
 603                struct omapfb_update_window_old uwnd_o;
 604                struct omapfb_update_window     uwnd;
 605                struct omapfb_plane_info        plane_info;
 606                struct omapfb_caps              caps;
 607                struct omapfb_mem_info          mem_info;
 608                struct omapfb_color_key         color_key;
 609                struct omapfb_ovl_colormode     ovl_colormode;
 610                enum omapfb_update_mode         update_mode;
 611                int test_num;
 612                struct omapfb_memory_read       memory_read;
 613                struct omapfb_vram_info         vram_info;
 614                struct omapfb_tearsync_info     tearsync_info;
 615                struct omapfb_display_info      display_info;
 616                u32                             crt;
 617        } p;
 618
 619        int r = 0;
 620
 621        switch (cmd) {
 622        case OMAPFB_SYNC_GFX:
 623                DBG("ioctl SYNC_GFX\n");
 624                if (!display || !display->driver->sync) {
 625                        /* DSS1 never returns an error here, so we neither */
 626                        /*r = -EINVAL;*/
 627                        break;
 628                }
 629
 630                r = display->driver->sync(display);
 631                break;
 632
 633        case OMAPFB_UPDATE_WINDOW_OLD:
 634                DBG("ioctl UPDATE_WINDOW_OLD\n");
 635                if (!display || !display->driver->update) {
 636                        r = -EINVAL;
 637                        break;
 638                }
 639
 640                if (copy_from_user(&p.uwnd_o,
 641                                        (void __user *)arg,
 642                                        sizeof(p.uwnd_o))) {
 643                        r = -EFAULT;
 644                        break;
 645                }
 646
 647                r = omapfb_update_window_nolock(fbi, p.uwnd_o.x, p.uwnd_o.y,
 648                                p.uwnd_o.width, p.uwnd_o.height);
 649                break;
 650
 651        case OMAPFB_UPDATE_WINDOW:
 652                DBG("ioctl UPDATE_WINDOW\n");
 653                if (!display || !display->driver->update) {
 654                        r = -EINVAL;
 655                        break;
 656                }
 657
 658                if (copy_from_user(&p.uwnd, (void __user *)arg,
 659                                        sizeof(p.uwnd))) {
 660                        r = -EFAULT;
 661                        break;
 662                }
 663
 664                r = omapfb_update_window_nolock(fbi, p.uwnd.x, p.uwnd.y,
 665                                p.uwnd.width, p.uwnd.height);
 666                break;
 667
 668        case OMAPFB_SETUP_PLANE:
 669                DBG("ioctl SETUP_PLANE\n");
 670                if (copy_from_user(&p.plane_info, (void __user *)arg,
 671                                        sizeof(p.plane_info)))
 672                        r = -EFAULT;
 673                else
 674                        r = omapfb_setup_plane(fbi, &p.plane_info);
 675                break;
 676
 677        case OMAPFB_QUERY_PLANE:
 678                DBG("ioctl QUERY_PLANE\n");
 679                r = omapfb_query_plane(fbi, &p.plane_info);
 680                if (r < 0)
 681                        break;
 682                if (copy_to_user((void __user *)arg, &p.plane_info,
 683                                        sizeof(p.plane_info)))
 684                        r = -EFAULT;
 685                break;
 686
 687        case OMAPFB_SETUP_MEM:
 688                DBG("ioctl SETUP_MEM\n");
 689                if (copy_from_user(&p.mem_info, (void __user *)arg,
 690                                        sizeof(p.mem_info)))
 691                        r = -EFAULT;
 692                else
 693                        r = omapfb_setup_mem(fbi, &p.mem_info);
 694                break;
 695
 696        case OMAPFB_QUERY_MEM:
 697                DBG("ioctl QUERY_MEM\n");
 698                r = omapfb_query_mem(fbi, &p.mem_info);
 699                if (r < 0)
 700                        break;
 701                if (copy_to_user((void __user *)arg, &p.mem_info,
 702                                        sizeof(p.mem_info)))
 703                        r = -EFAULT;
 704                break;
 705
 706        case OMAPFB_GET_CAPS:
 707                DBG("ioctl GET_CAPS\n");
 708                if (!display) {
 709                        r = -EINVAL;
 710                        break;
 711                }
 712
 713                memset(&p.caps, 0, sizeof(p.caps));
 714                if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
 715                        p.caps.ctrl |= OMAPFB_CAPS_MANUAL_UPDATE;
 716                if (display->caps & OMAP_DSS_DISPLAY_CAP_TEAR_ELIM)
 717                        p.caps.ctrl |= OMAPFB_CAPS_TEARSYNC;
 718
 719                if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
 720                        r = -EFAULT;
 721                break;
 722
 723        case OMAPFB_GET_OVERLAY_COLORMODE:
 724                DBG("ioctl GET_OVERLAY_COLORMODE\n");
 725                if (copy_from_user(&p.ovl_colormode, (void __user *)arg,
 726                                   sizeof(p.ovl_colormode))) {
 727                        r = -EFAULT;
 728                        break;
 729                }
 730                r = omapfb_get_ovl_colormode(fbdev, &p.ovl_colormode);
 731                if (r < 0)
 732                        break;
 733                if (copy_to_user((void __user *)arg, &p.ovl_colormode,
 734                                 sizeof(p.ovl_colormode)))
 735                        r = -EFAULT;
 736                break;
 737
 738        case OMAPFB_SET_UPDATE_MODE:
 739                DBG("ioctl SET_UPDATE_MODE\n");
 740                if (get_user(p.update_mode, (int __user *)arg))
 741                        r = -EFAULT;
 742                else
 743                        r = omapfb_set_update_mode(fbi, p.update_mode);
 744                break;
 745
 746        case OMAPFB_GET_UPDATE_MODE:
 747                DBG("ioctl GET_UPDATE_MODE\n");
 748                r = omapfb_get_update_mode(fbi, &p.update_mode);
 749                if (r)
 750                        break;
 751                if (put_user(p.update_mode,
 752                                        (enum omapfb_update_mode __user *)arg))
 753                        r = -EFAULT;
 754                break;
 755
 756        case OMAPFB_SET_COLOR_KEY:
 757                DBG("ioctl SET_COLOR_KEY\n");
 758                if (copy_from_user(&p.color_key, (void __user *)arg,
 759                                   sizeof(p.color_key)))
 760                        r = -EFAULT;
 761                else
 762                        r = omapfb_set_color_key(fbi, &p.color_key);
 763                break;
 764
 765        case OMAPFB_GET_COLOR_KEY:
 766                DBG("ioctl GET_COLOR_KEY\n");
 767                r = omapfb_get_color_key(fbi, &p.color_key);
 768                if (r)
 769                        break;
 770                if (copy_to_user((void __user *)arg, &p.color_key,
 771                                 sizeof(p.color_key)))
 772                        r = -EFAULT;
 773                break;
 774
 775        case FBIO_WAITFORVSYNC:
 776                if (get_user(p.crt, (__u32 __user *)arg)) {
 777                        r = -EFAULT;
 778                        break;
 779                }
 780                if (p.crt != 0) {
 781                        r = -ENODEV;
 782                        break;
 783                }
 784                /* FALLTHROUGH */
 785
 786        case OMAPFB_WAITFORVSYNC:
 787                DBG("ioctl WAITFORVSYNC\n");
 788                if (!display) {
 789                        r = -EINVAL;
 790                        break;
 791                }
 792
 793                r = display->manager->wait_for_vsync(display->manager);
 794                break;
 795
 796        case OMAPFB_WAITFORGO:
 797                DBG("ioctl WAITFORGO\n");
 798                if (!display) {
 799                        r = -EINVAL;
 800                        break;
 801                }
 802
 803                r = omapfb_wait_for_go(fbi);
 804                break;
 805
 806        /* LCD and CTRL tests do the same thing for backward
 807         * compatibility */
 808        case OMAPFB_LCD_TEST:
 809                DBG("ioctl LCD_TEST\n");
 810                if (get_user(p.test_num, (int __user *)arg)) {
 811                        r = -EFAULT;
 812                        break;
 813                }
 814                if (!display || !display->driver->run_test) {
 815                        r = -EINVAL;
 816                        break;
 817                }
 818
 819                r = display->driver->run_test(display, p.test_num);
 820
 821                break;
 822
 823        case OMAPFB_CTRL_TEST:
 824                DBG("ioctl CTRL_TEST\n");
 825                if (get_user(p.test_num, (int __user *)arg)) {
 826                        r = -EFAULT;
 827                        break;
 828                }
 829                if (!display || !display->driver->run_test) {
 830                        r = -EINVAL;
 831                        break;
 832                }
 833
 834                r = display->driver->run_test(display, p.test_num);
 835
 836                break;
 837
 838        case OMAPFB_MEMORY_READ:
 839                DBG("ioctl MEMORY_READ\n");
 840
 841                if (copy_from_user(&p.memory_read, (void __user *)arg,
 842                                        sizeof(p.memory_read))) {
 843                        r = -EFAULT;
 844                        break;
 845                }
 846
 847                r = omapfb_memory_read(fbi, &p.memory_read);
 848
 849                break;
 850
 851        case OMAPFB_GET_VRAM_INFO: {
 852                unsigned long vram, free, largest;
 853
 854                DBG("ioctl GET_VRAM_INFO\n");
 855
 856                omap_vram_get_info(&vram, &free, &largest);
 857                p.vram_info.total = vram;
 858                p.vram_info.free = free;
 859                p.vram_info.largest_free_block = largest;
 860
 861                if (copy_to_user((void __user *)arg, &p.vram_info,
 862                                        sizeof(p.vram_info)))
 863                        r = -EFAULT;
 864                break;
 865        }
 866
 867        case OMAPFB_SET_TEARSYNC: {
 868                DBG("ioctl SET_TEARSYNC\n");
 869
 870                if (copy_from_user(&p.tearsync_info, (void __user *)arg,
 871                                        sizeof(p.tearsync_info))) {
 872                        r = -EFAULT;
 873                        break;
 874                }
 875
 876                if (!display || !display->driver->enable_te) {
 877                        r = -ENODEV;
 878                        break;
 879                }
 880
 881                r = display->driver->enable_te(display,
 882                                !!p.tearsync_info.enabled);
 883
 884                break;
 885        }
 886
 887        case OMAPFB_GET_DISPLAY_INFO: {
 888                u16 xres, yres;
 889
 890                DBG("ioctl GET_DISPLAY_INFO\n");
 891
 892                if (display == NULL) {
 893                        r = -ENODEV;
 894                        break;
 895                }
 896
 897                display->driver->get_resolution(display, &xres, &yres);
 898
 899                p.display_info.xres = xres;
 900                p.display_info.yres = yres;
 901
 902                if (display->driver->get_dimensions) {
 903                        u32 w, h;
 904                        display->driver->get_dimensions(display, &w, &h);
 905                        p.display_info.width = w;
 906                        p.display_info.height = h;
 907                } else {
 908                        p.display_info.width = 0;
 909                        p.display_info.height = 0;
 910                }
 911
 912                if (copy_to_user((void __user *)arg, &p.display_info,
 913                                        sizeof(p.display_info)))
 914                        r = -EFAULT;
 915                break;
 916        }
 917
 918        default:
 919                dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd);
 920                r = -EINVAL;
 921        }
 922
 923        if (r < 0)
 924                DBG("ioctl failed: %d\n", r);
 925
 926        return r;
 927}
 928
 929
 930