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