amimouse.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 char *amimouse_name = "Amiga mouse";
  34. static char *amimouse_phys = "amimouse/input0";
  35. static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
  36. {
  37. unsigned short joy0dat, potgor;
  38. int nx, ny, dx, dy;
  39. joy0dat = custom.joy0dat;
  40. nx = joy0dat & 0xff;
  41. ny = joy0dat >> 8;
  42. dx = nx - amimouse_lastx;
  43. dy = ny - amimouse_lasty;
  44. if (dx < -127) dx = (256 + nx) - amimouse_lastx;
  45. if (dx > 127) dx = (nx - 256) - amimouse_lastx;
  46. if (dy < -127) dy = (256 + ny) - amimouse_lasty;
  47. if (dy > 127) dy = (ny - 256) - amimouse_lasty;
  48. amimouse_lastx = nx;
  49. amimouse_lasty = ny;
  50. potgor = custom.potgor;
  51. input_regs(&amimouse_dev, fp);
  52. input_report_rel(&amimouse_dev, REL_X, dx);
  53. input_report_rel(&amimouse_dev, REL_Y, dy);
  54. input_report_key(&amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
  55. input_report_key(&amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
  56. input_report_key(&amimouse_dev, BTN_RIGHT, potgor & 0x0400);
  57. input_sync(&amimouse_dev);
  58. return IRQ_HANDLED;
  59. }
  60. static int amimouse_open(struct input_dev *dev)
  61. {
  62. unsigned short joy0dat;
  63. joy0dat = custom.joy0dat;
  64. amimouse_lastx = joy0dat & 0xff;
  65. amimouse_lasty = joy0dat >> 8;
  66. if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
  67. printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
  68. return -EBUSY;
  69. }
  70. return 0;
  71. }
  72. static void amimouse_close(struct input_dev *dev)
  73. {
  74. free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
  75. }
  76. static int __init amimouse_init(void)
  77. {
  78. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
  79. return -ENODEV;
  80. amimouse_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  81. amimouse_dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
  82. amimouse_dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  83. amimouse_dev.open = amimouse_open;
  84. amimouse_dev.close = amimouse_close;
  85. amimouse_dev.name = amimouse_name;
  86. amimouse_dev.phys = amimouse_phys;
  87. amimouse_dev.id.bustype = BUS_AMIGA;
  88. amimouse_dev.id.vendor = 0x0001;
  89. amimouse_dev.id.product = 0x0002;
  90. amimouse_dev.id.version = 0x0100;
  91. input_register_device(&amimouse_dev);
  92. printk(KERN_INFO "input: %s at joy0dat\n", amimouse_name);
  93. return 0;
  94. }
  95. static void __exit amimouse_exit(void)
  96. {
  97. input_unregister_device(&amimouse_dev);
  98. }
  99. module_init(amimouse_init);
  100. module_exit(amimouse_exit);