linux/drivers/staging/unisys/visorinput/visorinput.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2011 - 2015 UNISYS CORPORATION
   3 * All rights reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms and conditions of the GNU General Public License,
   7 * version 2, as published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but
  10 * WITHOUT ANY WARRANTY; without even the implied warranty of
  11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  12 * NON INFRINGEMENT.  See the GNU General Public License for more
  13 * details.
  14 */
  15
  16/*
  17 * This driver lives in a generic guest Linux partition, and registers to
  18 * receive keyboard and mouse channels from the visorbus driver.  It reads
  19 * inputs from such channels, and delivers it to the Linux OS in the
  20 * standard way the Linux expects for input drivers.
  21 */
  22
  23#include <linux/fb.h>
  24#include <linux/input.h>
  25#include <linux/kernel.h>
  26#include <linux/module.h>
  27#include <linux/uuid.h>
  28
  29#include "visorbus.h"
  30#include "ultrainputreport.h"
  31
  32/* Keyboard channel {c73416d0-b0b8-44af-b304-9d2ae99f1b3d} */
  33#define VISOR_KEYBOARD_CHANNEL_GUID \
  34        GUID_INIT(0xc73416d0, 0xb0b8, 0x44af, \
  35                  0xb3, 0x4, 0x9d, 0x2a, 0xe9, 0x9f, 0x1b, 0x3d)
  36#define VISOR_KEYBOARD_CHANNEL_GUID_STR "c73416d0-b0b8-44af-b304-9d2ae99f1b3d"
  37
  38/* Mouse channel {addf07d4-94a9-46e2-81c3-61abcdbdbd87} */
  39#define VISOR_MOUSE_CHANNEL_GUID \
  40        GUID_INIT(0xaddf07d4, 0x94a9, 0x46e2, \
  41                  0x81, 0xc3, 0x61, 0xab, 0xcd, 0xbd, 0xbd, 0x87)
  42#define VISOR_MOUSE_CHANNEL_GUID_STR "addf07d4-94a9-46e2-81c3-61abcdbdbd87"
  43
  44#define PIXELS_ACROSS_DEFAULT 800
  45#define PIXELS_DOWN_DEFAULT   600
  46#define KEYCODE_TABLE_BYTES   256
  47
  48enum visorinput_device_type {
  49        visorinput_keyboard,
  50        visorinput_mouse,
  51};
  52
  53/*
  54 * This is the private data that we store for each device.
  55 * A pointer to this struct is maintained via
  56 * dev_get_drvdata() / dev_set_drvdata() for each struct device.
  57 */
  58struct visorinput_devdata {
  59        struct visor_device *dev;
  60        /* lock for dev */
  61        struct mutex lock_visor_dev;
  62        struct input_dev *visorinput_dev;
  63        bool paused;
  64        bool interrupts_enabled;
  65        /* size of following array */
  66        unsigned int keycode_table_bytes;
  67        /* for keyboard devices: visorkbd_keycode[] + visorkbd_ext_keycode[] */
  68        unsigned char keycode_table[0];
  69};
  70
  71static const guid_t visor_keyboard_channel_guid = VISOR_KEYBOARD_CHANNEL_GUID;
  72static const guid_t visor_mouse_channel_guid = VISOR_MOUSE_CHANNEL_GUID;
  73
  74/*
  75 * Borrowed from drivers/input/keyboard/atakbd.c
  76 * This maps 1-byte scancodes to keycodes.
  77 */
  78static const unsigned char visorkbd_keycode[KEYCODE_TABLE_BYTES] = {
  79        /* American layout */
  80        [0] = KEY_GRAVE,
  81        [1] = KEY_ESC,
  82        [2] = KEY_1,
  83        [3] = KEY_2,
  84        [4] = KEY_3,
  85        [5] = KEY_4,
  86        [6] = KEY_5,
  87        [7] = KEY_6,
  88        [8] = KEY_7,
  89        [9] = KEY_8,
  90        [10] = KEY_9,
  91        [11] = KEY_0,
  92        [12] = KEY_MINUS,
  93        [13] = KEY_EQUAL,
  94        [14] = KEY_BACKSPACE,
  95        [15] = KEY_TAB,
  96        [16] = KEY_Q,
  97        [17] = KEY_W,
  98        [18] = KEY_E,
  99        [19] = KEY_R,
 100        [20] = KEY_T,
 101        [21] = KEY_Y,
 102        [22] = KEY_U,
 103        [23] = KEY_I,
 104        [24] = KEY_O,
 105        [25] = KEY_P,
 106        [26] = KEY_LEFTBRACE,
 107        [27] = KEY_RIGHTBRACE,
 108        [28] = KEY_ENTER,
 109        [29] = KEY_LEFTCTRL,
 110        [30] = KEY_A,
 111        [31] = KEY_S,
 112        [32] = KEY_D,
 113        [33] = KEY_F,
 114        [34] = KEY_G,
 115        [35] = KEY_H,
 116        [36] = KEY_J,
 117        [37] = KEY_K,
 118        [38] = KEY_L,
 119        [39] = KEY_SEMICOLON,
 120        [40] = KEY_APOSTROPHE,
 121        [41] = KEY_GRAVE,
 122        [42] = KEY_LEFTSHIFT,
 123        [43] = KEY_BACKSLASH,
 124        [44] = KEY_Z,
 125        [45] = KEY_X,
 126        [46] = KEY_C,
 127        [47] = KEY_V,
 128        [48] = KEY_B,
 129        [49] = KEY_N,
 130        [50] = KEY_M,
 131        [51] = KEY_COMMA,
 132        [52] = KEY_DOT,
 133        [53] = KEY_SLASH,
 134        [54] = KEY_RIGHTSHIFT,
 135        [55] = KEY_KPASTERISK,
 136        [56] = KEY_LEFTALT,
 137        [57] = KEY_SPACE,
 138        [58] = KEY_CAPSLOCK,
 139        [59] = KEY_F1,
 140        [60] = KEY_F2,
 141        [61] = KEY_F3,
 142        [62] = KEY_F4,
 143        [63] = KEY_F5,
 144        [64] = KEY_F6,
 145        [65] = KEY_F7,
 146        [66] = KEY_F8,
 147        [67] = KEY_F9,
 148        [68] = KEY_F10,
 149        [69] = KEY_NUMLOCK,
 150        [70] = KEY_SCROLLLOCK,
 151        [71] = KEY_KP7,
 152        [72] = KEY_KP8,
 153        [73] = KEY_KP9,
 154        [74] = KEY_KPMINUS,
 155        [75] = KEY_KP4,
 156        [76] = KEY_KP5,
 157        [77] = KEY_KP6,
 158        [78] = KEY_KPPLUS,
 159        [79] = KEY_KP1,
 160        [80] = KEY_KP2,
 161        [81] = KEY_KP3,
 162        [82] = KEY_KP0,
 163        [83] = KEY_KPDOT,
 164        /* enables UK backslash+pipe key and FR lessthan+greaterthan key */
 165        [86] = KEY_102ND,
 166        [87] = KEY_F11,
 167        [88] = KEY_F12,
 168        [90] = KEY_KPLEFTPAREN,
 169        [91] = KEY_KPRIGHTPAREN,
 170        [92] = KEY_KPASTERISK,
 171        [93] = KEY_KPASTERISK,
 172        [94] = KEY_KPPLUS,
 173        [95] = KEY_HELP,
 174        [96] = KEY_KPENTER,
 175        [97] = KEY_RIGHTCTRL,
 176        [98] = KEY_KPSLASH,
 177        [99] = KEY_KPLEFTPAREN,
 178        [100] = KEY_KPRIGHTPAREN,
 179        [101] = KEY_KPSLASH,
 180        [102] = KEY_HOME,
 181        [103] = KEY_UP,
 182        [104] = KEY_PAGEUP,
 183        [105] = KEY_LEFT,
 184        [106] = KEY_RIGHT,
 185        [107] = KEY_END,
 186        [108] = KEY_DOWN,
 187        [109] = KEY_PAGEDOWN,
 188        [110] = KEY_INSERT,
 189        [111] = KEY_DELETE,
 190        [112] = KEY_MACRO,
 191        [113] = KEY_MUTE
 192};
 193
 194/*
 195 * This maps the <xx> in extended scancodes of the form "0xE0 <xx>" into
 196 * keycodes.
 197 */
 198static const unsigned char visorkbd_ext_keycode[KEYCODE_TABLE_BYTES] = {
 199        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x00 */
 200        0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x10 */
 201        0, 0, 0, 0, KEY_KPENTER, KEY_RIGHTCTRL, 0, 0,               /* 0x18 */
 202        0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x20 */
 203        KEY_RIGHTALT, 0, 0, 0, 0, 0, 0, 0,                          /* 0x28 */
 204        0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x30 */
 205        KEY_RIGHTALT /* AltGr */, 0, 0, 0, 0, 0, 0, 0,              /* 0x38 */
 206        0, 0, 0, 0, 0, 0, 0, KEY_HOME,                              /* 0x40 */
 207        KEY_UP, KEY_PAGEUP, 0, KEY_LEFT, 0, KEY_RIGHT, 0, KEY_END,  /* 0x48 */
 208        KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, 0, 0, 0, 0, /* 0x50 */
 209        0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x58 */
 210        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x60 */
 211        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x70 */
 212};
 213
 214static int visorinput_open(struct input_dev *visorinput_dev)
 215{
 216        struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
 217
 218        if (!devdata) {
 219                dev_err(&visorinput_dev->dev,
 220                        "%s input_get_drvdata(%p) returned NULL\n",
 221                        __func__, visorinput_dev);
 222                return -EINVAL;
 223        }
 224        dev_dbg(&visorinput_dev->dev, "%s opened\n", __func__);
 225
 226        /*
 227         * If we're not paused, really enable interrupts.
 228         * Regardless of whether we are paused, set a flag indicating
 229         * interrupts should be enabled so when we resume, interrupts
 230         * will really be enabled.
 231         */
 232        mutex_lock(&devdata->lock_visor_dev);
 233        devdata->interrupts_enabled = true;
 234        if (devdata->paused)
 235                goto out_unlock;
 236        visorbus_enable_channel_interrupts(devdata->dev);
 237
 238out_unlock:
 239        mutex_unlock(&devdata->lock_visor_dev);
 240        return 0;
 241}
 242
 243static void visorinput_close(struct input_dev *visorinput_dev)
 244{
 245        struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
 246
 247        if (!devdata) {
 248                dev_err(&visorinput_dev->dev,
 249                        "%s input_get_drvdata(%p) returned NULL\n",
 250                        __func__, visorinput_dev);
 251                return;
 252        }
 253        dev_dbg(&visorinput_dev->dev, "%s closed\n", __func__);
 254
 255        /*
 256         * If we're not paused, really disable interrupts.
 257         * Regardless of whether we are paused, set a flag indicating
 258         * interrupts should be disabled so when we resume we will
 259         * not re-enable them.
 260         */
 261        mutex_lock(&devdata->lock_visor_dev);
 262        devdata->interrupts_enabled = false;
 263        if (devdata->paused)
 264                goto out_unlock;
 265        visorbus_disable_channel_interrupts(devdata->dev);
 266
 267out_unlock:
 268        mutex_unlock(&devdata->lock_visor_dev);
 269}
 270
 271/*
 272 * setup_client_keyboard() initializes and returns a Linux input node that
 273 * we can use to deliver keyboard inputs to Linux.  We of course do this when
 274 * we see keyboard inputs coming in on a keyboard channel.
 275 */
 276static struct input_dev *setup_client_keyboard(void *devdata,
 277                                               unsigned char *keycode_table)
 278
 279{
 280        int i;
 281        struct input_dev *visorinput_dev = input_allocate_device();
 282
 283        if (!visorinput_dev)
 284                return NULL;
 285
 286        visorinput_dev->name = "visor Keyboard";
 287        visorinput_dev->phys = "visorkbd:input0";
 288        visorinput_dev->id.bustype = BUS_VIRTUAL;
 289        visorinput_dev->id.vendor = 0x0001;
 290        visorinput_dev->id.product = 0x0001;
 291        visorinput_dev->id.version = 0x0100;
 292
 293        visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) |
 294                                   BIT_MASK(EV_REP) |
 295                                   BIT_MASK(EV_LED);
 296        visorinput_dev->ledbit[0] = BIT_MASK(LED_CAPSL) |
 297                                    BIT_MASK(LED_SCROLLL) |
 298                                    BIT_MASK(LED_NUML);
 299        visorinput_dev->keycode = keycode_table;
 300        /* sizeof(unsigned char) */
 301        visorinput_dev->keycodesize = 1;
 302        visorinput_dev->keycodemax = KEYCODE_TABLE_BYTES;
 303
 304        for (i = 1; i < visorinput_dev->keycodemax; i++)
 305                set_bit(keycode_table[i], visorinput_dev->keybit);
 306        for (i = 1; i < visorinput_dev->keycodemax; i++)
 307                set_bit(keycode_table[i + KEYCODE_TABLE_BYTES],
 308                        visorinput_dev->keybit);
 309
 310        visorinput_dev->open = visorinput_open;
 311        visorinput_dev->close = visorinput_close;
 312        /* pre input_register! */
 313        input_set_drvdata(visorinput_dev, devdata);
 314
 315        return visorinput_dev;
 316}
 317
 318static struct input_dev *setup_client_mouse(void *devdata)
 319{
 320        int xres, yres;
 321        struct fb_info *fb0;
 322        struct input_dev *visorinput_dev = input_allocate_device();
 323
 324        if (!visorinput_dev)
 325                return NULL;
 326
 327        visorinput_dev->name = "visor Mouse";
 328        visorinput_dev->phys = "visormou:input0";
 329        visorinput_dev->id.bustype = BUS_VIRTUAL;
 330        visorinput_dev->id.vendor = 0x0001;
 331        visorinput_dev->id.product = 0x0002;
 332        visorinput_dev->id.version = 0x0100;
 333
 334        visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
 335        set_bit(BTN_LEFT, visorinput_dev->keybit);
 336        set_bit(BTN_RIGHT, visorinput_dev->keybit);
 337        set_bit(BTN_MIDDLE, visorinput_dev->keybit);
 338
 339        if (registered_fb[0]) {
 340                fb0 = registered_fb[0];
 341                xres = fb0->var.xres_virtual;
 342                yres = fb0->var.yres_virtual;
 343        } else {
 344                xres = PIXELS_ACROSS_DEFAULT;
 345                yres = PIXELS_DOWN_DEFAULT;
 346        }
 347        input_set_abs_params(visorinput_dev, ABS_X, 0, xres, 0, 0);
 348        input_set_abs_params(visorinput_dev, ABS_Y, 0, yres, 0, 0);
 349
 350        visorinput_dev->open = visorinput_open;
 351        visorinput_dev->close = visorinput_close;
 352        /* pre input_register! */
 353        input_set_drvdata(visorinput_dev, devdata);
 354        input_set_capability(visorinput_dev, EV_REL, REL_WHEEL);
 355
 356        return visorinput_dev;
 357}
 358
 359static struct visorinput_devdata *devdata_create(
 360                                        struct visor_device *dev,
 361                                        enum visorinput_device_type devtype)
 362{
 363        struct visorinput_devdata *devdata = NULL;
 364        unsigned int extra_bytes = 0;
 365
 366        if (devtype == visorinput_keyboard)
 367                /* allocate room for devdata->keycode_table, filled in below */
 368                extra_bytes = KEYCODE_TABLE_BYTES * 2;
 369        devdata = kzalloc(sizeof(*devdata) + extra_bytes, GFP_KERNEL);
 370        if (!devdata)
 371                return NULL;
 372        mutex_init(&devdata->lock_visor_dev);
 373        mutex_lock(&devdata->lock_visor_dev);
 374        devdata->dev = dev;
 375
 376        /*
 377         * visorinput_open() can be called as soon as input_register_device()
 378         * happens, and that will enable channel interrupts.  Setting paused
 379         * prevents us from getting into visorinput_channel_interrupt() prior
 380         * to the device structure being totally initialized.
 381         */
 382        devdata->paused = true;
 383
 384        /*
 385         * This is an input device in a client guest partition,
 386         * so we need to create whatever input nodes are necessary to
 387         * deliver our inputs to the guest OS.
 388         */
 389        switch (devtype) {
 390        case visorinput_keyboard:
 391                devdata->keycode_table_bytes = extra_bytes;
 392                memcpy(devdata->keycode_table, visorkbd_keycode,
 393                       KEYCODE_TABLE_BYTES);
 394                memcpy(devdata->keycode_table + KEYCODE_TABLE_BYTES,
 395                       visorkbd_ext_keycode, KEYCODE_TABLE_BYTES);
 396                devdata->visorinput_dev = setup_client_keyboard
 397                        (devdata, devdata->keycode_table);
 398                if (!devdata->visorinput_dev)
 399                        goto cleanups_register;
 400                break;
 401        case visorinput_mouse:
 402                devdata->visorinput_dev = setup_client_mouse(devdata);
 403                if (!devdata->visorinput_dev)
 404                        goto cleanups_register;
 405                break;
 406        default:
 407                /* No other input devices supported */
 408                break;
 409        }
 410
 411        dev_set_drvdata(&dev->device, devdata);
 412        mutex_unlock(&devdata->lock_visor_dev);
 413
 414        /*
 415         * Device struct is completely set up now, with the exception of
 416         * visorinput_dev being registered.
 417         * We need to unlock before we register the device, because this
 418         * can cause an on-stack call of visorinput_open(), which would
 419         * deadlock if we had the lock.
 420         */
 421        if (input_register_device(devdata->visorinput_dev)) {
 422                input_free_device(devdata->visorinput_dev);
 423                goto err_kfree_devdata;
 424        }
 425
 426        mutex_lock(&devdata->lock_visor_dev);
 427        /*
 428         * Establish calls to visorinput_channel_interrupt() if that is
 429         * the desired state that we've kept track of in interrupts_enabled
 430         * while the device was being created.
 431         */
 432        devdata->paused = false;
 433        if (devdata->interrupts_enabled)
 434                visorbus_enable_channel_interrupts(dev);
 435        mutex_unlock(&devdata->lock_visor_dev);
 436
 437        return devdata;
 438
 439cleanups_register:
 440        mutex_unlock(&devdata->lock_visor_dev);
 441err_kfree_devdata:
 442        kfree(devdata);
 443        return NULL;
 444}
 445
 446static int visorinput_probe(struct visor_device *dev)
 447{
 448        const guid_t *guid;
 449        enum visorinput_device_type devtype;
 450
 451        guid = visorchannel_get_guid(dev->visorchannel);
 452        if (guid_equal(guid, &visor_mouse_channel_guid))
 453                devtype = visorinput_mouse;
 454        else if (guid_equal(guid, &visor_keyboard_channel_guid))
 455                devtype = visorinput_keyboard;
 456        else
 457                return -ENODEV;
 458        visorbus_disable_channel_interrupts(dev);
 459        if (!devdata_create(dev, devtype))
 460                return -ENOMEM;
 461        return 0;
 462}
 463
 464static void unregister_client_input(struct input_dev *visorinput_dev)
 465{
 466        if (visorinput_dev)
 467                input_unregister_device(visorinput_dev);
 468}
 469
 470static void visorinput_remove(struct visor_device *dev)
 471{
 472        struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
 473
 474        if (!devdata)
 475                return;
 476
 477        mutex_lock(&devdata->lock_visor_dev);
 478        visorbus_disable_channel_interrupts(dev);
 479
 480        /*
 481         * due to above, at this time no thread of execution will be
 482         * in visorinput_channel_interrupt()
 483         */
 484
 485        dev_set_drvdata(&dev->device, NULL);
 486        mutex_unlock(&devdata->lock_visor_dev);
 487
 488        unregister_client_input(devdata->visorinput_dev);
 489        kfree(devdata);
 490}
 491
 492/*
 493 * Make it so the current locking state of the locking key indicated by
 494 * <keycode> is as indicated by <desired_state> (1=locked, 0=unlocked).
 495 */
 496static void handle_locking_key(struct input_dev *visorinput_dev, int keycode,
 497                               int desired_state)
 498{
 499        int led;
 500
 501        switch (keycode) {
 502        case KEY_CAPSLOCK:
 503                led = LED_CAPSL;
 504                break;
 505        case KEY_SCROLLLOCK:
 506                led = LED_SCROLLL;
 507                break;
 508        case KEY_NUMLOCK:
 509                led = LED_NUML;
 510                break;
 511        default:
 512                led = -1;
 513                return;
 514        }
 515        if (test_bit(led, visorinput_dev->led) != desired_state) {
 516                input_report_key(visorinput_dev, keycode, 1);
 517                input_sync(visorinput_dev);
 518                input_report_key(visorinput_dev, keycode, 0);
 519                input_sync(visorinput_dev);
 520                __change_bit(led, visorinput_dev->led);
 521        }
 522}
 523
 524/*
 525 * <scancode> is either a 1-byte scancode, or an extended 16-bit scancode
 526 * with 0xE0 in the low byte and the extended scancode value in the next
 527 * higher byte.
 528 */
 529static int scancode_to_keycode(int scancode)
 530{
 531        if (scancode > 0xff)
 532                return visorkbd_ext_keycode[(scancode >> 8) & 0xff];
 533
 534        return visorkbd_keycode[scancode];
 535}
 536
 537static int calc_button(int x)
 538{
 539        switch (x) {
 540        case 1:
 541                return BTN_LEFT;
 542        case 2:
 543                return BTN_MIDDLE;
 544        case 3:
 545                return BTN_RIGHT;
 546        default:
 547                return -EINVAL;
 548        }
 549}
 550
 551/*
 552 * This is used only when this driver is active as an input driver in the
 553 * client guest partition.  It is called periodically so we can obtain inputs
 554 * from the channel, and deliver them to the guest OS.
 555 */
 556static void visorinput_channel_interrupt(struct visor_device *dev)
 557{
 558        struct visor_inputreport r;
 559        int scancode, keycode;
 560        struct input_dev *visorinput_dev;
 561        int xmotion, ymotion, button;
 562        int i;
 563        struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
 564
 565        if (!devdata)
 566                return;
 567
 568        visorinput_dev = devdata->visorinput_dev;
 569
 570        while (!visorchannel_signalremove(dev->visorchannel, 0, &r)) {
 571                scancode = r.activity.arg1;
 572                keycode = scancode_to_keycode(scancode);
 573                switch (r.activity.action) {
 574                case INPUTACTION_KEY_DOWN:
 575                        input_report_key(visorinput_dev, keycode, 1);
 576                        input_sync(visorinput_dev);
 577                        break;
 578                case INPUTACTION_KEY_UP:
 579                        input_report_key(visorinput_dev, keycode, 0);
 580                        input_sync(visorinput_dev);
 581                        break;
 582                case INPUTACTION_KEY_DOWN_UP:
 583                        input_report_key(visorinput_dev, keycode, 1);
 584                        input_sync(visorinput_dev);
 585                        input_report_key(visorinput_dev, keycode, 0);
 586                        input_sync(visorinput_dev);
 587                        break;
 588                case INPUTACTION_SET_LOCKING_KEY_STATE:
 589                        handle_locking_key(visorinput_dev, keycode,
 590                                           r.activity.arg2);
 591                        break;
 592                case INPUTACTION_XY_MOTION:
 593                        xmotion = r.activity.arg1;
 594                        ymotion = r.activity.arg2;
 595                        input_report_abs(visorinput_dev, ABS_X, xmotion);
 596                        input_report_abs(visorinput_dev, ABS_Y, ymotion);
 597                        input_sync(visorinput_dev);
 598                        break;
 599                case INPUTACTION_MOUSE_BUTTON_DOWN:
 600                        button = calc_button(r.activity.arg1);
 601                        if (button < 0)
 602                                break;
 603                        input_report_key(visorinput_dev, button, 1);
 604                        input_sync(visorinput_dev);
 605                        break;
 606                case INPUTACTION_MOUSE_BUTTON_UP:
 607                        button = calc_button(r.activity.arg1);
 608                        if (button < 0)
 609                                break;
 610                        input_report_key(visorinput_dev, button, 0);
 611                        input_sync(visorinput_dev);
 612                        break;
 613                case INPUTACTION_MOUSE_BUTTON_CLICK:
 614                        button = calc_button(r.activity.arg1);
 615                        if (button < 0)
 616                                break;
 617                        input_report_key(visorinput_dev, button, 1);
 618                        input_sync(visorinput_dev);
 619                        input_report_key(visorinput_dev, button, 0);
 620                        input_sync(visorinput_dev);
 621                        break;
 622                case INPUTACTION_MOUSE_BUTTON_DCLICK:
 623                        button = calc_button(r.activity.arg1);
 624                        if (button < 0)
 625                                break;
 626                        for (i = 0; i < 2; i++) {
 627                                input_report_key(visorinput_dev, button, 1);
 628                                input_sync(visorinput_dev);
 629                                input_report_key(visorinput_dev, button, 0);
 630                                input_sync(visorinput_dev);
 631                        }
 632                        break;
 633                case INPUTACTION_WHEEL_ROTATE_AWAY:
 634                        input_report_rel(visorinput_dev, REL_WHEEL, 1);
 635                        input_sync(visorinput_dev);
 636                        break;
 637                case INPUTACTION_WHEEL_ROTATE_TOWARD:
 638                        input_report_rel(visorinput_dev, REL_WHEEL, -1);
 639                        input_sync(visorinput_dev);
 640                        break;
 641                default:
 642                        /* Unsupported input action */
 643                        break;
 644                }
 645        }
 646}
 647
 648static int visorinput_pause(struct visor_device *dev,
 649                            visorbus_state_complete_func complete_func)
 650{
 651        int rc;
 652        struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
 653
 654        if (!devdata) {
 655                rc = -ENODEV;
 656                goto out;
 657        }
 658
 659        mutex_lock(&devdata->lock_visor_dev);
 660        if (devdata->paused) {
 661                rc = -EBUSY;
 662                goto out_locked;
 663        }
 664        if (devdata->interrupts_enabled)
 665                visorbus_disable_channel_interrupts(dev);
 666
 667        /*
 668         * due to above, at this time no thread of execution will be
 669         * in visorinput_channel_interrupt()
 670         */
 671        devdata->paused = true;
 672        complete_func(dev, 0);
 673        rc = 0;
 674out_locked:
 675        mutex_unlock(&devdata->lock_visor_dev);
 676out:
 677        return rc;
 678}
 679
 680static int visorinput_resume(struct visor_device *dev,
 681                             visorbus_state_complete_func complete_func)
 682{
 683        int rc;
 684        struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
 685
 686        if (!devdata) {
 687                rc = -ENODEV;
 688                goto out;
 689        }
 690        mutex_lock(&devdata->lock_visor_dev);
 691        if (!devdata->paused) {
 692                rc = -EBUSY;
 693                goto out_locked;
 694        }
 695        devdata->paused = false;
 696        complete_func(dev, 0);
 697
 698        /*
 699         * Re-establish calls to visorinput_channel_interrupt() if that is
 700         * the desired state that we've kept track of in interrupts_enabled
 701         * while the device was paused.
 702         */
 703        if (devdata->interrupts_enabled)
 704                visorbus_enable_channel_interrupts(dev);
 705
 706        rc = 0;
 707out_locked:
 708        mutex_unlock(&devdata->lock_visor_dev);
 709out:
 710        return rc;
 711}
 712
 713/* GUIDS for all channel types supported by this driver. */
 714static struct visor_channeltype_descriptor visorinput_channel_types[] = {
 715        { VISOR_KEYBOARD_CHANNEL_GUID, "keyboard",
 716          sizeof(struct channel_header), 0 },
 717        { VISOR_MOUSE_CHANNEL_GUID, "mouse", sizeof(struct channel_header), 0 },
 718        {}
 719};
 720
 721static struct visor_driver visorinput_driver = {
 722        .name = "visorinput",
 723        .owner = THIS_MODULE,
 724        .channel_types = visorinput_channel_types,
 725        .probe = visorinput_probe,
 726        .remove = visorinput_remove,
 727        .channel_interrupt = visorinput_channel_interrupt,
 728        .pause = visorinput_pause,
 729        .resume = visorinput_resume,
 730};
 731
 732module_driver(visorinput_driver, visorbus_register_visor_driver,
 733              visorbus_unregister_visor_driver);
 734
 735MODULE_DEVICE_TABLE(visorbus, visorinput_channel_types);
 736
 737MODULE_AUTHOR("Unisys");
 738MODULE_LICENSE("GPL");
 739MODULE_DESCRIPTION("s-Par human input driver for virtual keyboard/mouse");
 740
 741MODULE_ALIAS("visorbus:" VISOR_MOUSE_CHANNEL_GUID_STR);
 742MODULE_ALIAS("visorbus:" VISOR_KEYBOARD_CHANNEL_GUID_STR);
 743