au88x0_game.c 3.7 KB

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