/kern_oII/drivers/input/mouse/atarimouse.c

http://omnia2droid.googlecode.com/ · C · 158 lines · 89 code · 29 blank · 40 comment · 5 complexity · e92583598eab2a98613cb87e4a86a0e8 MD5 · raw file

  1. /*
  2. * Atari mouse driver for Linux/m68k
  3. *
  4. * Copyright (c) 2005 Michael Schmitz
  5. *
  6. * Based on:
  7. * Amiga mouse driver for Linux/m68k
  8. *
  9. * Copyright (c) 2000-2002 Vojtech Pavlik
  10. *
  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. /*
  36. * This program is free software; you can redistribute it and/or modify it
  37. * under the terms of the GNU General Public License version 2 as published by
  38. * the Free Software Foundation
  39. */
  40. #include <linux/module.h>
  41. #include <linux/init.h>
  42. #include <linux/input.h>
  43. #include <linux/interrupt.h>
  44. #include <asm/irq.h>
  45. #include <asm/setup.h>
  46. #include <asm/system.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/atarihw.h>
  49. #include <asm/atarikb.h>
  50. #include <asm/atariints.h>
  51. MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
  52. MODULE_DESCRIPTION("Atari mouse driver");
  53. MODULE_LICENSE("GPL");
  54. static int mouse_threshold[2] = {2, 2};
  55. module_param_array(mouse_threshold, int, NULL, 0);
  56. #ifdef FIXED_ATARI_JOYSTICK
  57. extern int atari_mouse_buttons;
  58. #endif
  59. static struct input_dev *atamouse_dev;
  60. static void atamouse_interrupt(char *buf)
  61. {
  62. int buttons, dx, dy;
  63. buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
  64. #ifdef FIXED_ATARI_JOYSTICK
  65. buttons |= atari_mouse_buttons & 2;
  66. atari_mouse_buttons = buttons;
  67. #endif
  68. /* only relative events get here */
  69. dx = buf[1];
  70. dy = -buf[2];
  71. input_report_rel(atamouse_dev, REL_X, dx);
  72. input_report_rel(atamouse_dev, REL_Y, dy);
  73. input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x1);
  74. input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2);
  75. input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x4);
  76. input_sync(atamouse_dev);
  77. return;
  78. }
  79. static int atamouse_open(struct input_dev *dev)
  80. {
  81. #ifdef FIXED_ATARI_JOYSTICK
  82. atari_mouse_buttons = 0;
  83. #endif
  84. ikbd_mouse_y0_top();
  85. ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
  86. ikbd_mouse_rel_pos();
  87. atari_input_mouse_interrupt_hook = atamouse_interrupt;
  88. return 0;
  89. }
  90. static void atamouse_close(struct input_dev *dev)
  91. {
  92. ikbd_mouse_disable();
  93. atari_mouse_interrupt_hook = NULL;
  94. }
  95. static int __init atamouse_init(void)
  96. {
  97. int error;
  98. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
  99. return -ENODEV;
  100. if (!atari_keyb_init())
  101. return -ENODEV;
  102. atamouse_dev = input_allocate_device();
  103. if (!atamouse_dev)
  104. return -ENOMEM;
  105. atamouse_dev->name = "Atari mouse";
  106. atamouse_dev->phys = "atamouse/input0";
  107. atamouse_dev->id.bustype = BUS_HOST;
  108. atamouse_dev->id.vendor = 0x0001;
  109. atamouse_dev->id.product = 0x0002;
  110. atamouse_dev->id.version = 0x0100;
  111. atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  112. atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  113. atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  114. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  115. atamouse_dev->open = atamouse_open;
  116. atamouse_dev->close = atamouse_close;
  117. error = input_register_device(atamouse_dev);
  118. if (error) {
  119. input_free_device(atamouse_dev);
  120. return error;
  121. }
  122. return 0;
  123. }
  124. static void __exit atamouse_exit(void)
  125. {
  126. input_unregister_device(atamouse_dev);
  127. }
  128. module_init(atamouse_init);
  129. module_exit(atamouse_exit);