amimouse.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <linux/platform_device.h>
  23. #include <asm/irq.h>
  24. #include <asm/setup.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 irqreturn_t amimouse_interrupt(int irq, void *data)
  33. {
  34. struct input_dev *dev = data;
  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_report_rel(dev, REL_X, dx);
  50. input_report_rel(dev, REL_Y, dy);
  51. input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40);
  52. input_report_key(dev, BTN_MIDDLE, potgor & 0x0100);
  53. input_report_key(dev, BTN_RIGHT, potgor & 0x0400);
  54. input_sync(dev);
  55. return IRQ_HANDLED;
  56. }
  57. static int amimouse_open(struct input_dev *dev)
  58. {
  59. unsigned short joy0dat;
  60. int error;
  61. joy0dat = amiga_custom.joy0dat;
  62. amimouse_lastx = joy0dat & 0xff;
  63. amimouse_lasty = joy0dat >> 8;
  64. error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse",
  65. dev);
  66. if (error)
  67. dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
  68. return error;
  69. }
  70. static void amimouse_close(struct input_dev *dev)
  71. {
  72. free_irq(IRQ_AMIGA_VERTB, dev);
  73. }
  74. static int __init amimouse_probe(struct platform_device *pdev)
  75. {
  76. int err;
  77. struct input_dev *dev;
  78. dev = input_allocate_device();
  79. if (!dev)
  80. return -ENOMEM;
  81. dev->name = pdev->name;
  82. dev->phys = "amimouse/input0";
  83. dev->id.bustype = BUS_AMIGA;
  84. dev->id.vendor = 0x0001;
  85. dev->id.product = 0x0002;
  86. dev->id.version = 0x0100;
  87. dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  88. dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  89. dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  90. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  91. dev->open = amimouse_open;
  92. dev->close = amimouse_close;
  93. dev->dev.parent = &pdev->dev;
  94. err = input_register_device(dev);
  95. if (err) {
  96. input_free_device(dev);
  97. return err;
  98. }
  99. platform_set_drvdata(pdev, dev);
  100. return 0;
  101. }
  102. static int __exit amimouse_remove(struct platform_device *pdev)
  103. {
  104. struct input_dev *dev = platform_get_drvdata(pdev);
  105. input_unregister_device(dev);
  106. return 0;
  107. }
  108. static struct platform_driver amimouse_driver = {
  109. .remove = __exit_p(amimouse_remove),
  110. .driver = {
  111. .name = "amiga-mouse",
  112. },
  113. };
  114. module_platform_driver_probe(amimouse_driver, amimouse_probe);
  115. MODULE_ALIAS("platform:amiga-mouse");