atarimouse.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Atari mouse driver for Linux/m68k
  4. *
  5. * Copyright (c) 2005 Michael Schmitz
  6. *
  7. * Based on:
  8. * Amiga mouse driver for Linux/m68k
  9. *
  10. * Copyright (c) 2000-2002 Vojtech Pavlik
  11. */
  12. /*
  13. * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
  14. * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
  15. * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
  16. * This driver only deals with handing key events off to the input layer.
  17. *
  18. * Largely based on the old:
  19. *
  20. * Atari Mouse Driver for Linux
  21. * by Robert de Vries (robert@and.nl) 19Jul93
  22. *
  23. * 16 Nov 1994 Andreas Schwab
  24. * Compatibility with busmouse
  25. * Support for three button mouse (shamelessly stolen from MiNT)
  26. * third button wired to one of the joystick directions on joystick 1
  27. *
  28. * 1996/02/11 Andreas Schwab
  29. * Module support
  30. * Allow multiple open's
  31. *
  32. * Converted to use new generic busmouse code. 5 Apr 1998
  33. * Russell King <rmk@arm.uk.linux.org>
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/input.h>
  38. #include <linux/interrupt.h>
  39. #include <asm/irq.h>
  40. #include <asm/setup.h>
  41. #include <linux/uaccess.h>
  42. #include <asm/atarihw.h>
  43. #include <asm/atarikb.h>
  44. #include <asm/atariints.h>
  45. MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
  46. MODULE_DESCRIPTION("Atari mouse driver");
  47. MODULE_LICENSE("GPL");
  48. static int mouse_threshold[2] = {2, 2};
  49. module_param_array(mouse_threshold, int, NULL, 0);
  50. #ifdef FIXED_ATARI_JOYSTICK
  51. extern int atari_mouse_buttons;
  52. #endif
  53. static struct input_dev *atamouse_dev;
  54. static void atamouse_interrupt(char *buf)
  55. {
  56. int buttons, dx, dy;
  57. buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
  58. #ifdef FIXED_ATARI_JOYSTICK
  59. buttons |= atari_mouse_buttons & 2;
  60. atari_mouse_buttons = buttons;
  61. #endif
  62. /* only relative events get here */
  63. dx = buf[1];
  64. dy = buf[2];
  65. input_report_rel(atamouse_dev, REL_X, dx);
  66. input_report_rel(atamouse_dev, REL_Y, dy);
  67. input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x4);
  68. input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2);
  69. input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x1);
  70. input_sync(atamouse_dev);
  71. return;
  72. }
  73. static int atamouse_open(struct input_dev *dev)
  74. {
  75. #ifdef FIXED_ATARI_JOYSTICK
  76. atari_mouse_buttons = 0;
  77. #endif
  78. ikbd_mouse_y0_top();
  79. ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
  80. ikbd_mouse_rel_pos();
  81. atari_input_mouse_interrupt_hook = atamouse_interrupt;
  82. return 0;
  83. }
  84. static void atamouse_close(struct input_dev *dev)
  85. {
  86. ikbd_mouse_disable();
  87. atari_input_mouse_interrupt_hook = NULL;
  88. }
  89. static int __init atamouse_init(void)
  90. {
  91. int error;
  92. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
  93. return -ENODEV;
  94. error = atari_keyb_init();
  95. if (error)
  96. return error;
  97. atamouse_dev = input_allocate_device();
  98. if (!atamouse_dev)
  99. return -ENOMEM;
  100. atamouse_dev->name = "Atari mouse";
  101. atamouse_dev->phys = "atamouse/input0";
  102. atamouse_dev->id.bustype = BUS_HOST;
  103. atamouse_dev->id.vendor = 0x0001;
  104. atamouse_dev->id.product = 0x0002;
  105. atamouse_dev->id.version = 0x0100;
  106. atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  107. atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  108. atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  109. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  110. atamouse_dev->open = atamouse_open;
  111. atamouse_dev->close = atamouse_close;
  112. error = input_register_device(atamouse_dev);
  113. if (error) {
  114. input_free_device(atamouse_dev);
  115. return error;
  116. }
  117. return 0;
  118. }
  119. static void __exit atamouse_exit(void)
  120. {
  121. input_unregister_device(atamouse_dev);
  122. }
  123. module_init(atamouse_init);
  124. module_exit(atamouse_exit);