rpcmouse.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Acorn RiscPC mouse driver for Linux/ARM
  3. *
  4. * Copyright (c) 2000-2002 Vojtech Pavlik
  5. * Copyright (C) 1996-2002 Russell King
  6. *
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This handles the Acorn RiscPCs mouse. We basically have a couple of
  14. * hardware registers that track the sensor count for the X-Y movement and
  15. * another register holding the button state. On every VSYNC interrupt we read
  16. * the complete state and then work out if something has changed.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/init.h>
  22. #include <linux/input.h>
  23. #include <asm/hardware.h>
  24. #include <asm/irq.h>
  25. #include <asm/io.h>
  26. #include <asm/hardware/iomd.h>
  27. MODULE_AUTHOR("Vojtech Pavlik, Russell King");
  28. MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
  29. MODULE_LICENSE("GPL");
  30. static short rpcmouse_lastx, rpcmouse_lasty;
  31. static struct input_dev *rpcmouse_dev;
  32. static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
  33. {
  34. struct input_dev *dev = dev_id;
  35. short x, y, dx, dy, b;
  36. x = (short) iomd_readl(IOMD_MOUSEX);
  37. y = (short) iomd_readl(IOMD_MOUSEY);
  38. b = (short) (__raw_readl(0xe0310000) ^ 0x70);
  39. dx = x - rpcmouse_lastx;
  40. dy = y - rpcmouse_lasty;
  41. rpcmouse_lastx = x;
  42. rpcmouse_lasty = y;
  43. input_report_rel(dev, REL_X, dx);
  44. input_report_rel(dev, REL_Y, -dy);
  45. input_report_key(dev, BTN_LEFT, b & 0x40);
  46. input_report_key(dev, BTN_MIDDLE, b & 0x20);
  47. input_report_key(dev, BTN_RIGHT, b & 0x10);
  48. input_sync(dev);
  49. return IRQ_HANDLED;
  50. }
  51. static int __init rpcmouse_init(void)
  52. {
  53. int err;
  54. rpcmouse_dev = input_allocate_device();
  55. if (!rpcmouse_dev)
  56. return -ENOMEM;
  57. rpcmouse_dev->name = "Acorn RiscPC Mouse";
  58. rpcmouse_dev->phys = "rpcmouse/input0";
  59. rpcmouse_dev->id.bustype = BUS_HOST;
  60. rpcmouse_dev->id.vendor = 0x0005;
  61. rpcmouse_dev->id.product = 0x0001;
  62. rpcmouse_dev->id.version = 0x0100;
  63. rpcmouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  64. rpcmouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  65. rpcmouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  66. rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
  67. rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
  68. if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
  69. printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
  70. err = -EBUSY;
  71. goto err_free_dev;
  72. }
  73. err = input_register_device(rpcmouse_dev);
  74. if (err)
  75. goto err_free_irq;
  76. return 0;
  77. err_free_irq:
  78. free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
  79. err_free_dev:
  80. input_free_device(rpcmouse_dev);
  81. return err;
  82. }
  83. static void __exit rpcmouse_exit(void)
  84. {
  85. free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
  86. input_unregister_device(rpcmouse_dev);
  87. }
  88. module_init(rpcmouse_init);
  89. module_exit(rpcmouse_exit);