amimouse.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Amiga mouse driver for Linux/m68k
  4. *
  5. * Copyright (c) 2000-2002 Vojtech Pavlik
  6. *
  7. * Based on the work of:
  8. * Michael Rausch James Banks
  9. * Matther Dillon David Giller
  10. * Nathan Laredo Linus Torvalds
  11. * Johan Myreen Jes Sorensen
  12. * Russell King
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/input.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/platform_device.h>
  19. #include <asm/irq.h>
  20. #include <asm/setup.h>
  21. #include <linux/uaccess.h>
  22. #include <asm/amigahw.h>
  23. #include <asm/amigaints.h>
  24. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  25. MODULE_DESCRIPTION("Amiga mouse driver");
  26. MODULE_LICENSE("GPL");
  27. static int amimouse_lastx, amimouse_lasty;
  28. static irqreturn_t amimouse_interrupt(int irq, void *data)
  29. {
  30. struct input_dev *dev = data;
  31. unsigned short joy0dat, potgor;
  32. int nx, ny, dx, dy;
  33. joy0dat = amiga_custom.joy0dat;
  34. nx = joy0dat & 0xff;
  35. ny = joy0dat >> 8;
  36. dx = nx - amimouse_lastx;
  37. dy = ny - amimouse_lasty;
  38. if (dx < -127) dx = (256 + nx) - amimouse_lastx;
  39. if (dx > 127) dx = (nx - 256) - amimouse_lastx;
  40. if (dy < -127) dy = (256 + ny) - amimouse_lasty;
  41. if (dy > 127) dy = (ny - 256) - amimouse_lasty;
  42. amimouse_lastx = nx;
  43. amimouse_lasty = ny;
  44. potgor = amiga_custom.potgor;
  45. input_report_rel(dev, REL_X, dx);
  46. input_report_rel(dev, REL_Y, dy);
  47. input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40);
  48. input_report_key(dev, BTN_MIDDLE, potgor & 0x0100);
  49. input_report_key(dev, BTN_RIGHT, potgor & 0x0400);
  50. input_sync(dev);
  51. return IRQ_HANDLED;
  52. }
  53. static int amimouse_open(struct input_dev *dev)
  54. {
  55. unsigned short joy0dat;
  56. int error;
  57. joy0dat = amiga_custom.joy0dat;
  58. amimouse_lastx = joy0dat & 0xff;
  59. amimouse_lasty = joy0dat >> 8;
  60. error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse",
  61. dev);
  62. if (error)
  63. dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
  64. return error;
  65. }
  66. static void amimouse_close(struct input_dev *dev)
  67. {
  68. free_irq(IRQ_AMIGA_VERTB, dev);
  69. }
  70. static int __init amimouse_probe(struct platform_device *pdev)
  71. {
  72. int err;
  73. struct input_dev *dev;
  74. dev = input_allocate_device();
  75. if (!dev)
  76. return -ENOMEM;
  77. dev->name = pdev->name;
  78. dev->phys = "amimouse/input0";
  79. dev->id.bustype = BUS_AMIGA;
  80. dev->id.vendor = 0x0001;
  81. dev->id.product = 0x0002;
  82. dev->id.version = 0x0100;
  83. dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  84. dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  85. dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  86. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  87. dev->open = amimouse_open;
  88. dev->close = amimouse_close;
  89. dev->dev.parent = &pdev->dev;
  90. err = input_register_device(dev);
  91. if (err) {
  92. input_free_device(dev);
  93. return err;
  94. }
  95. platform_set_drvdata(pdev, dev);
  96. return 0;
  97. }
  98. static int __exit amimouse_remove(struct platform_device *pdev)
  99. {
  100. struct input_dev *dev = platform_get_drvdata(pdev);
  101. input_unregister_device(dev);
  102. return 0;
  103. }
  104. static struct platform_driver amimouse_driver = {
  105. .remove = __exit_p(amimouse_remove),
  106. .driver = {
  107. .name = "amiga-mouse",
  108. },
  109. };
  110. module_platform_driver_probe(amimouse_driver, amimouse_probe);
  111. MODULE_ALIAS("platform:amiga-mouse");