au88x0_game.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Manuel Jander.
  3. *
  4. * Based on the work of:
  5. * Vojtech Pavlik
  6. * Raymond Ingles
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Should you need to contact me, the author, you can do so either by
  23. * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
  24. * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
  25. *
  26. * Based 90% on Vojtech Pavlik pcigame driver.
  27. * Merged and modified by Manuel Jander, for the OpenVortex
  28. * driver. (email: mjander@embedded.cl).
  29. */
  30. #include <linux/time.h>
  31. #include <linux/delay.h>
  32. #include <linux/init.h>
  33. #include <sound/core.h>
  34. #include "au88x0.h"
  35. #include <linux/gameport.h>
  36. #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  37. #define VORTEX_GAME_DWAIT 20 /* 20 ms */
  38. static unsigned char vortex_game_read(struct gameport *gameport)
  39. {
  40. vortex_t *vortex = gameport_get_port_data(gameport);
  41. return hwread(vortex->mmio, VORTEX_GAME_LEGACY);
  42. }
  43. static void vortex_game_trigger(struct gameport *gameport)
  44. {
  45. vortex_t *vortex = gameport_get_port_data(gameport);
  46. hwwrite(vortex->mmio, VORTEX_GAME_LEGACY, 0xff);
  47. }
  48. static int
  49. vortex_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  50. {
  51. vortex_t *vortex = gameport_get_port_data(gameport);
  52. int i;
  53. *buttons = (~hwread(vortex->mmio, VORTEX_GAME_LEGACY) >> 4) & 0xf;
  54. for (i = 0; i < 4; i++) {
  55. axes[i] =
  56. hwread(vortex->mmio, VORTEX_GAME_AXIS + (i * AXIS_SIZE));
  57. if (axes[i] == AXIS_RANGE)
  58. axes[i] = -1;
  59. }
  60. return 0;
  61. }
  62. static int vortex_game_open(struct gameport *gameport, int mode)
  63. {
  64. vortex_t *vortex = gameport_get_port_data(gameport);
  65. switch (mode) {
  66. case GAMEPORT_MODE_COOKED:
  67. hwwrite(vortex->mmio, VORTEX_CTRL2,
  68. hwread(vortex->mmio,
  69. VORTEX_CTRL2) | CTRL2_GAME_ADCMODE);
  70. msleep(VORTEX_GAME_DWAIT);
  71. return 0;
  72. case GAMEPORT_MODE_RAW:
  73. hwwrite(vortex->mmio, VORTEX_CTRL2,
  74. hwread(vortex->mmio,
  75. VORTEX_CTRL2) & ~CTRL2_GAME_ADCMODE);
  76. return 0;
  77. default:
  78. return -1;
  79. }
  80. return 0;
  81. }
  82. static int __devinit vortex_gameport_register(vortex_t * vortex)
  83. {
  84. struct gameport *gp;
  85. vortex->gameport = gp = gameport_allocate_port();
  86. if (!gp) {
  87. printk(KERN_ERR "vortex: cannot allocate memory for gameport\n");
  88. return -ENOMEM;
  89. };
  90. gameport_set_name(gp, "AU88x0 Gameport");
  91. gameport_set_phys(gp, "pci%s/gameport0", pci_name(vortex->pci_dev));
  92. gameport_set_dev_parent(gp, &vortex->pci_dev->dev);
  93. gp->read = vortex_game_read;
  94. gp->trigger = vortex_game_trigger;
  95. gp->cooked_read = vortex_game_cooked_read;
  96. gp->open = vortex_game_open;
  97. gameport_set_port_data(gp, vortex);
  98. gp->fuzz = 64;
  99. gameport_register_port(gp);
  100. return 0;
  101. }
  102. static void vortex_gameport_unregister(vortex_t * vortex)
  103. {
  104. if (vortex->gameport) {
  105. gameport_unregister_port(vortex->gameport);
  106. vortex->gameport = NULL;
  107. }
  108. }
  109. #else
  110. static inline int vortex_gameport_register(vortex_t * vortex) { return -ENOSYS; }
  111. static inline void vortex_gameport_unregister(vortex_t * vortex) { }
  112. #endif