amimouse.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Amiga mouse driver for Linux/m68k
  3. *
  4. * Copyright (c) 2000-2002 Vojtech Pavlik
  5. *
  6. * Based on the work of:
  7. * Michael Rausch James Banks
  8. * Matther Dillon David Giller
  9. * Nathan Laredo Linus Torvalds
  10. * Johan Myreen Jes Sorensen
  11. * Russell King
  12. */
  13. /*
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License version 2 as published by
  16. * the Free Software Foundation
  17. */
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/input.h>
  21. #include <linux/interrupt.h>
  22. #include <asm/irq.h>
  23. #include <asm/setup.h>
  24. #include <asm/system.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/amigahw.h>
  27. #include <asm/amigaints.h>
  28. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  29. MODULE_DESCRIPTION("Amiga mouse driver");
  30. MODULE_LICENSE("GPL");
  31. static int amimouse_lastx, amimouse_lasty;
  32. static struct input_dev *amimouse_dev;
  33. static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
  34. {
  35. unsigned short joy0dat, potgor;
  36. int nx, ny, dx, dy;
  37. joy0dat = amiga_custom.joy0dat;
  38. nx = joy0dat & 0xff;
  39. ny = joy0dat >> 8;
  40. dx = nx - amimouse_lastx;
  41. dy = ny - amimouse_lasty;
  42. if (dx < -127) dx = (256 + nx) - amimouse_lastx;
  43. if (dx > 127) dx = (nx - 256) - amimouse_lastx;
  44. if (dy < -127) dy = (256 + ny) - amimouse_lasty;
  45. if (dy > 127) dy = (ny - 256) - amimouse_lasty;
  46. amimouse_lastx = nx;
  47. amimouse_lasty = ny;
  48. potgor = amiga_custom.potgor;
  49. input_regs(amimouse_dev, fp);
  50. input_report_rel(amimouse_dev, REL_X, dx);
  51. input_report_rel(amimouse_dev, REL_Y, dy);
  52. input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
  53. input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
  54. input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400);
  55. input_sync(amimouse_dev);
  56. return IRQ_HANDLED;
  57. }
  58. static int amimouse_open(struct input_dev *dev)
  59. {
  60. unsigned short joy0dat;
  61. joy0dat = amiga_custom.joy0dat;
  62. amimouse_lastx = joy0dat & 0xff;
  63. amimouse_lasty = joy0dat >> 8;
  64. if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
  65. printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
  66. return -EBUSY;
  67. }
  68. return 0;
  69. }
  70. static void amimouse_close(struct input_dev *dev)
  71. {
  72. free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
  73. }
  74. static int __init amimouse_init(void)
  75. {
  76. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
  77. return -ENODEV;
  78. if (!(amimouse_dev = input_allocate_device()))
  79. return -ENOMEM;
  80. amimouse_dev->name = "Amiga mouse";
  81. amimouse_dev->phys = "amimouse/input0";
  82. amimouse_dev->id.bustype = BUS_AMIGA;
  83. amimouse_dev->id.vendor = 0x0001;
  84. amimouse_dev->id.product = 0x0002;
  85. amimouse_dev->id.version = 0x0100;
  86. amimouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  87. amimouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  88. amimouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  89. amimouse_dev->open = amimouse_open;
  90. amimouse_dev->close = amimouse_close;
  91. input_register_device(amimouse_dev);
  92. return 0;
  93. }
  94. static void __exit amimouse_exit(void)
  95. {
  96. input_unregister_device(amimouse_dev);
  97. }
  98. module_init(amimouse_init);
  99. module_exit(amimouse_exit);