diff options
author | Takashi Iwai <tiwai@suse.de> | 2009-05-26 07:55:42 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-05-26 07:55:42 -0400 |
commit | db1005ec6ff8f250bccbc87387a955078891bfe4 (patch) | |
tree | 43388819d1477db084eaa7901b74461494b61fa6 /sound/pci | |
parent | a693a26fe0807c3c406d6b5295d222b646677288 (diff) |
ALSA: riptide - Fix joystick resource handling
The current code doesn't handle the multiple gameports properly,
and uses unnecessary global static variables to store the data.
This patch changes the probe / remove routines to use the driver
data assigned to the dedicated pci device, and adds the support of
multiple devices.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/riptide/riptide.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c index 460be038f9c7..235a71e5ac8d 100644 --- a/sound/pci/riptide/riptide.c +++ b/sound/pci/riptide/riptide.c | |||
@@ -2014,14 +2014,12 @@ static int __devinit snd_riptide_mixer(struct snd_riptide *chip) | |||
2014 | } | 2014 | } |
2015 | 2015 | ||
2016 | #ifdef SUPPORT_JOYSTICK | 2016 | #ifdef SUPPORT_JOYSTICK |
2017 | static int have_joystick; | ||
2018 | static struct pci_dev *riptide_gameport_pci; | ||
2019 | static struct gameport *riptide_gameport; | ||
2020 | 2017 | ||
2021 | static int __devinit | 2018 | static int __devinit |
2022 | snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id) | 2019 | snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id) |
2023 | { | 2020 | { |
2024 | static int dev; | 2021 | static int dev; |
2022 | struct gameport *gameport; | ||
2025 | 2023 | ||
2026 | if (dev >= SNDRV_CARDS) | 2024 | if (dev >= SNDRV_CARDS) |
2027 | return -ENODEV; | 2025 | return -ENODEV; |
@@ -2030,36 +2028,33 @@ snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id) | |||
2030 | return -ENOENT; | 2028 | return -ENOENT; |
2031 | } | 2029 | } |
2032 | 2030 | ||
2033 | if (joystick_port[dev]) { | 2031 | if (!joystick_port[dev++]) |
2034 | riptide_gameport = gameport_allocate_port(); | 2032 | return 0; |
2035 | if (riptide_gameport) { | 2033 | |
2036 | if (!request_region | 2034 | gameport = gameport_allocate_port(); |
2037 | (joystick_port[dev], 8, "Riptide gameport")) { | 2035 | if (!gameport) |
2038 | snd_printk(KERN_WARNING | 2036 | return -ENOMEM; |
2039 | "Riptide: cannot grab gameport 0x%x\n", | 2037 | if (!request_region(joystick_port[dev], 8, "Riptide gameport")) { |
2040 | joystick_port[dev]); | 2038 | snd_printk(KERN_WARNING |
2041 | gameport_free_port(riptide_gameport); | 2039 | "Riptide: cannot grab gameport 0x%x\n", |
2042 | riptide_gameport = NULL; | 2040 | joystick_port[dev]); |
2043 | } else { | 2041 | gameport_free_port(gameport); |
2044 | riptide_gameport_pci = pci; | 2042 | return -EBUSY; |
2045 | riptide_gameport->io = joystick_port[dev]; | ||
2046 | gameport_register_port(riptide_gameport); | ||
2047 | } | ||
2048 | } | ||
2049 | } | 2043 | } |
2050 | dev++; | 2044 | |
2045 | gameport->io = joystick_port[dev]; | ||
2046 | gameport_register_port(gameport); | ||
2047 | pci_set_drvdata(pci, gameport); | ||
2051 | return 0; | 2048 | return 0; |
2052 | } | 2049 | } |
2053 | 2050 | ||
2054 | static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci) | 2051 | static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci) |
2055 | { | 2052 | { |
2056 | if (riptide_gameport) { | 2053 | struct gameport *gameport = pci_get_drvdata(pci); |
2057 | if (riptide_gameport_pci == pci) { | 2054 | if (gameport) { |
2058 | release_region(riptide_gameport->io, 8); | 2055 | release_region(gameport->io, 8); |
2059 | riptide_gameport_pci = NULL; | 2056 | gameport_unregister_port(gameport); |
2060 | gameport_unregister_port(riptide_gameport); | 2057 | pci_set_drvdata(pci, NULL); |
2061 | riptide_gameport = NULL; | ||
2062 | } | ||
2063 | } | 2058 | } |
2064 | } | 2059 | } |
2065 | #endif | 2060 | #endif |
@@ -2198,14 +2193,11 @@ static struct pci_driver joystick_driver = { | |||
2198 | static int __init alsa_card_riptide_init(void) | 2193 | static int __init alsa_card_riptide_init(void) |
2199 | { | 2194 | { |
2200 | int err; | 2195 | int err; |
2201 | if ((err = pci_register_driver(&driver)) < 0) | 2196 | err = pci_register_driver(&driver); |
2197 | if (err < 0) | ||
2202 | return err; | 2198 | return err; |
2203 | #if defined(SUPPORT_JOYSTICK) | 2199 | #if defined(SUPPORT_JOYSTICK) |
2204 | if (pci_register_driver(&joystick_driver) < 0) { | 2200 | pci_register_driver(&joystick_driver); |
2205 | have_joystick = 0; | ||
2206 | snd_printk(KERN_INFO "no joystick found\n"); | ||
2207 | } else | ||
2208 | have_joystick = 1; | ||
2209 | #endif | 2201 | #endif |
2210 | return 0; | 2202 | return 0; |
2211 | } | 2203 | } |
@@ -2214,8 +2206,7 @@ static void __exit alsa_card_riptide_exit(void) | |||
2214 | { | 2206 | { |
2215 | pci_unregister_driver(&driver); | 2207 | pci_unregister_driver(&driver); |
2216 | #if defined(SUPPORT_JOYSTICK) | 2208 | #if defined(SUPPORT_JOYSTICK) |
2217 | if (have_joystick) | 2209 | pci_unregister_driver(&joystick_driver); |
2218 | pci_unregister_driver(&joystick_driver); | ||
2219 | #endif | 2210 | #endif |
2220 | } | 2211 | } |
2221 | 2212 | ||