rpcmouse.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <linux/io.h>
  24. #include <mach/hardware.h>
  25. #include <asm/irq.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(IOMEM(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_MASK(EV_KEY) | BIT_MASK(EV_REL);
  64. rpcmouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  65. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  66. rpcmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  67. rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
  68. rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
  69. if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
  70. printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
  71. err = -EBUSY;
  72. goto err_free_dev;
  73. }
  74. err = input_register_device(rpcmouse_dev);
  75. if (err)
  76. goto err_free_irq;
  77. return 0;
  78. err_free_irq:
  79. free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
  80. err_free_dev:
  81. input_free_device(rpcmouse_dev);
  82. return err;
  83. }
  84. static void __exit rpcmouse_exit(void)
  85. {
  86. free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
  87. input_unregister_device(rpcmouse_dev);
  88. }
  89. module_init(rpcmouse_init);
  90. module_exit(rpcmouse_exit);