rpcmouse.c 2.7 KB

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