rpcmouse.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/sched.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/init.h>
  23. #include <linux/input.h>
  24. #include <asm/hardware.h>
  25. #include <asm/irq.h>
  26. #include <asm/io.h>
  27. #include <asm/hardware/iomd.h>
  28. MODULE_AUTHOR("Vojtech Pavlik, Russell King");
  29. MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
  30. MODULE_LICENSE("GPL");
  31. static short rpcmouse_lastx, rpcmouse_lasty;
  32. static struct input_dev *rpcmouse_dev;
  33. static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
  34. {
  35. struct input_dev *dev = dev_id;
  36. short x, y, dx, dy, b;
  37. x = (short) iomd_readl(IOMD_MOUSEX);
  38. y = (short) iomd_readl(IOMD_MOUSEY);
  39. b = (short) (__raw_readl(0xe0310000) ^ 0x70);
  40. dx = x - rpcmouse_lastx;
  41. dy = y - rpcmouse_lasty;
  42. rpcmouse_lastx = x;
  43. rpcmouse_lasty = y;
  44. input_regs(dev, regs);
  45. input_report_rel(dev, REL_X, dx);
  46. input_report_rel(dev, REL_Y, -dy);
  47. input_report_key(dev, BTN_LEFT, b & 0x40);
  48. input_report_key(dev, BTN_MIDDLE, b & 0x20);
  49. input_report_key(dev, BTN_RIGHT, b & 0x10);
  50. input_sync(dev);
  51. return IRQ_HANDLED;
  52. }
  53. static int __init rpcmouse_init(void)
  54. {
  55. if (!(rpcmouse_dev = input_allocate_device()))
  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, SA_SHIRQ, "rpcmouse", rpcmouse_dev)) {
  69. printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
  70. input_free_device(rpcmouse_dev);
  71. return -EBUSY;
  72. }
  73. input_register_device(rpcmouse_dev);
  74. return 0;
  75. }
  76. static void __exit rpcmouse_exit(void)
  77. {
  78. free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
  79. input_unregister_device(rpcmouse_dev);
  80. }
  81. module_init(rpcmouse_init);
  82. module_exit(rpcmouse_exit);