Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/time.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <sound/core.h> |
| 35 | #include "au88x0.h" |
| 36 | #include <linux/gameport.h> |
| 37 | |
| 38 | #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) |
| 39 | |
| 40 | #define VORTEX_GAME_DWAIT 20 /* 20 ms */ |
| 41 | |
| 42 | static unsigned char vortex_game_read(struct gameport *gameport) |
| 43 | { |
| 44 | vortex_t *vortex = gameport_get_port_data(gameport); |
| 45 | return hwread(vortex->mmio, VORTEX_GAME_LEGACY); |
| 46 | } |
| 47 | |
| 48 | static void vortex_game_trigger(struct gameport *gameport) |
| 49 | { |
| 50 | vortex_t *vortex = gameport_get_port_data(gameport); |
| 51 | hwwrite(vortex->mmio, VORTEX_GAME_LEGACY, 0xff); |
| 52 | } |
| 53 | |
| 54 | static int |
| 55 | vortex_game_cooked_read(struct gameport *gameport, int *axes, int *buttons) |
| 56 | { |
| 57 | vortex_t *vortex = gameport_get_port_data(gameport); |
| 58 | int i; |
| 59 | |
| 60 | *buttons = (~hwread(vortex->mmio, VORTEX_GAME_LEGACY) >> 4) & 0xf; |
| 61 | |
| 62 | for (i = 0; i < 4; i++) { |
| 63 | axes[i] = |
| 64 | hwread(vortex->mmio, VORTEX_GAME_AXIS + (i * AXIS_SIZE)); |
| 65 | if (axes[i] == AXIS_RANGE) |
| 66 | axes[i] = -1; |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static int vortex_game_open(struct gameport *gameport, int mode) |
| 72 | { |
| 73 | vortex_t *vortex = gameport_get_port_data(gameport); |
| 74 | |
| 75 | switch (mode) { |
| 76 | case GAMEPORT_MODE_COOKED: |
| 77 | hwwrite(vortex->mmio, VORTEX_CTRL2, |
| 78 | hwread(vortex->mmio, |
| 79 | VORTEX_CTRL2) | CTRL2_GAME_ADCMODE); |
| 80 | msleep(VORTEX_GAME_DWAIT); |
| 81 | return 0; |
| 82 | case GAMEPORT_MODE_RAW: |
| 83 | hwwrite(vortex->mmio, VORTEX_CTRL2, |
| 84 | hwread(vortex->mmio, |
| 85 | VORTEX_CTRL2) & ~CTRL2_GAME_ADCMODE); |
| 86 | return 0; |
| 87 | default: |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int __devinit vortex_gameport_register(vortex_t * vortex) |
| 95 | { |
| 96 | struct gameport *gp; |
| 97 | |
| 98 | vortex->gameport = gp = gameport_allocate_port(); |
| 99 | if (!gp) { |
| 100 | printk(KERN_ERR "vortex: cannot allocate memory for gameport\n"); |
| 101 | return -ENOMEM; |
| 102 | }; |
| 103 | |
| 104 | gameport_set_name(gp, "AU88x0 Gameport"); |
| 105 | gameport_set_phys(gp, "pci%s/gameport0", pci_name(vortex->pci_dev)); |
| 106 | gameport_set_dev_parent(gp, &vortex->pci_dev->dev); |
| 107 | |
| 108 | gp->read = vortex_game_read; |
| 109 | gp->trigger = vortex_game_trigger; |
| 110 | gp->cooked_read = vortex_game_cooked_read; |
| 111 | gp->open = vortex_game_open; |
| 112 | |
| 113 | gameport_set_port_data(gp, vortex); |
| 114 | gp->fuzz = 64; |
| 115 | |
| 116 | gameport_register_port(gp); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static void vortex_gameport_unregister(vortex_t * vortex) |
| 122 | { |
| 123 | if (vortex->gameport) { |
| 124 | gameport_unregister_port(vortex->gameport); |
| 125 | vortex->gameport = NULL; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | #else |
| 130 | static inline int vortex_gameport_register(vortex_t * vortex) { return -ENOSYS; } |
| 131 | static inline void vortex_gameport_unregister(vortex_t * vortex) { } |
| 132 | #endif |