Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips |
| 3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sound/driver.h> |
| 23 | #include <linux/init.h> |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 24 | #include <linux/err.h> |
| 25 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/slab.h> |
| 27 | #include <linux/pnp.h> |
| 28 | #include <linux/moduleparam.h> |
| 29 | #include <sound/core.h> |
| 30 | #include <sound/cs4231.h> |
| 31 | #include <sound/mpu401.h> |
| 32 | #include <sound/opl3.h> |
| 33 | #include <sound/initval.h> |
| 34 | |
| 35 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 36 | MODULE_LICENSE("GPL"); |
| 37 | #ifdef CS4232 |
| 38 | MODULE_DESCRIPTION("Cirrus Logic CS4232"); |
| 39 | MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000}," |
| 40 | "{Turtle Beach,Tropez Plus}," |
| 41 | "{SIC CrystalWave 32}," |
| 42 | "{Hewlett Packard,Omnibook 5500}," |
| 43 | "{TerraTec,Maestro 32/96}," |
| 44 | "{Philips,PCA70PS}}"); |
| 45 | #else |
| 46 | MODULE_DESCRIPTION("Cirrus Logic CS4235-9"); |
| 47 | MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235}," |
| 48 | "{Crystal Semiconductors,CS4236}," |
| 49 | "{Crystal Semiconductors,CS4237}," |
| 50 | "{Crystal Semiconductors,CS4238}," |
| 51 | "{Crystal Semiconductors,CS4239}," |
| 52 | "{Acer,AW37}," |
| 53 | "{Acer,AW35/Pro}," |
| 54 | "{Crystal,3D}," |
| 55 | "{Crystal Computer,TidalWave128}," |
| 56 | "{Dell,Optiplex GX1}," |
| 57 | "{Dell,Workstation 400 sound}," |
| 58 | "{EliteGroup,P5TX-LA sound}," |
| 59 | "{Gallant,SC-70P}," |
| 60 | "{Gateway,E1000 Onboard CS4236B}," |
| 61 | "{Genius,Sound Maker 3DJ}," |
| 62 | "{Hewlett Packard,HP6330 sound}," |
| 63 | "{IBM,PC 300PL sound}," |
| 64 | "{IBM,Aptiva 2137 E24}," |
| 65 | "{IBM,IntelliStation M Pro}," |
| 66 | "{Intel,Marlin Spike Mobo CS4235}," |
| 67 | "{Intel PR440FX Onboard}," |
| 68 | "{Guillemot,MaxiSound 16 PnP}," |
| 69 | "{NewClear,3D}," |
| 70 | "{TerraTec,AudioSystem EWS64L/XL}," |
| 71 | "{Typhoon Soundsystem,CS4236B}," |
| 72 | "{Turtle Beach,Malibu}," |
| 73 | "{Unknown,Digital PC 5000 Onboard}}"); |
| 74 | #endif |
| 75 | |
| 76 | #ifdef CS4232 |
| 77 | #define IDENT "CS4232" |
Jaroslav Kysela | ec80859 | 2006-01-22 09:28:15 +0100 | [diff] [blame] | 78 | #define CS423X_DRIVER "snd_cs4232" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #else |
| 80 | #define IDENT "CS4236+" |
Jaroslav Kysela | ec80859 | 2006-01-22 09:28:15 +0100 | [diff] [blame] | 81 | #define CS423X_DRIVER "snd_cs4236" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #endif |
| 83 | |
| 84 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 85 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 86 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
| 87 | #ifdef CONFIG_PNP |
| 88 | static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
| 89 | #endif |
| 90 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 91 | static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 92 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */ |
| 93 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 94 | static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 95 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */ |
| 96 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */ |
| 97 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ |
| 98 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ |
| 99 | |
| 100 | module_param_array(index, int, NULL, 0444); |
| 101 | MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard."); |
| 102 | module_param_array(id, charp, NULL, 0444); |
| 103 | MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard."); |
| 104 | module_param_array(enable, bool, NULL, 0444); |
| 105 | MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard."); |
| 106 | #ifdef CONFIG_PNP |
| 107 | module_param_array(isapnp, bool, NULL, 0444); |
| 108 | MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); |
| 109 | #endif |
| 110 | module_param_array(port, long, NULL, 0444); |
| 111 | MODULE_PARM_DESC(port, "Port # for " IDENT " driver."); |
| 112 | module_param_array(cport, long, NULL, 0444); |
| 113 | MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver."); |
| 114 | module_param_array(mpu_port, long, NULL, 0444); |
| 115 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver."); |
| 116 | module_param_array(fm_port, long, NULL, 0444); |
| 117 | MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver."); |
| 118 | module_param_array(sb_port, long, NULL, 0444); |
| 119 | MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional)."); |
| 120 | module_param_array(irq, int, NULL, 0444); |
| 121 | MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver."); |
| 122 | module_param_array(mpu_irq, int, NULL, 0444); |
| 123 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver."); |
| 124 | module_param_array(dma1, int, NULL, 0444); |
| 125 | MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver."); |
| 126 | module_param_array(dma2, int, NULL, 0444); |
| 127 | MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver."); |
| 128 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 129 | static struct platform_device *platform_devices[SNDRV_CARDS]; |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 130 | #ifdef CONFIG_PNP |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 131 | static int pnpc_registered; |
| 132 | #ifdef CS4232 |
| 133 | static int pnp_registered; |
| 134 | #endif |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 135 | #endif /* CONFIG_PNP */ |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | struct snd_card_cs4236 { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 138 | struct snd_cs4231 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | struct resource *res_sb_port; |
| 140 | #ifdef CONFIG_PNP |
| 141 | struct pnp_dev *wss; |
| 142 | struct pnp_dev *ctrl; |
| 143 | struct pnp_dev *mpu; |
| 144 | #endif |
| 145 | }; |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #ifdef CONFIG_PNP |
| 148 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 149 | #ifdef CS4232 |
| 150 | /* |
| 151 | * PNP BIOS |
| 152 | */ |
| 153 | static const struct pnp_device_id snd_cs4232_pnpbiosids[] = { |
| 154 | { .id = "CSC0100" }, |
| 155 | { .id = "CSC0000" }, |
| 156 | /* Guillemot Turtlebeach something appears to be cs4232 compatible |
| 157 | * (untested) */ |
| 158 | { .id = "GIM0100" }, |
| 159 | { .id = "" } |
| 160 | }; |
| 161 | MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids); |
| 162 | #endif /* CS4232 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | #ifdef CS4232 |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 165 | #define CS423X_ISAPNP_DRIVER "cs4232_isapnp" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | static struct pnp_card_device_id snd_cs423x_pnpids[] = { |
| 167 | /* Philips PCA70PS */ |
| 168 | { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, |
| 169 | /* TerraTec Maestro 32/96 (CS4232) */ |
| 170 | { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 171 | /* HP Omnibook 5500 onboard */ |
| 172 | { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } }, |
| 173 | /* Unnamed CS4236 card (Made in Taiwan) */ |
| 174 | { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 175 | /* Turtle Beach TBS-2000 (CS4232) */ |
| 176 | { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } }, |
| 177 | /* Turtle Beach Tropez Plus (CS4232) */ |
| 178 | { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, |
| 179 | /* SIC CrystalWave 32 (CS4232) */ |
| 180 | { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
Lukasz Stemach | 50f794c | 2006-01-23 15:22:13 +0100 | [diff] [blame] | 181 | /* Netfinity 3000 on-board soundcard */ |
| 182 | { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | /* --- */ |
| 184 | { .id = "" } /* end */ |
| 185 | }; |
| 186 | #else /* CS4236 */ |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 187 | #define CS423X_ISAPNP_DRIVER "cs4236_isapnp" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | static struct pnp_card_device_id snd_cs423x_pnpids[] = { |
| 189 | /* Intel Marlin Spike Motherboard - CS4235 */ |
| 190 | { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 191 | /* Intel Marlin Spike Motherboard (#2) - CS4235 */ |
| 192 | { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, |
| 193 | /* Unknown Intel mainboard - CS4235 */ |
| 194 | { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } }, |
| 195 | /* Genius Sound Maker 3DJ - CS4237B */ |
| 196 | { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 197 | /* Digital PC 5000 Onboard - CS4236B */ |
| 198 | { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } }, |
| 199 | /* some uknown CS4236B */ |
| 200 | { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 201 | /* Intel PR440FX Onboard sound */ |
| 202 | { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 203 | /* CS4235 on mainboard without MPU */ |
| 204 | { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } }, |
| 205 | /* Gateway E1000 Onboard CS4236B */ |
| 206 | { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 207 | /* HP 6330 Onboard sound */ |
| 208 | { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, |
| 209 | /* Crystal Computer TidalWave128 */ |
| 210 | { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 211 | /* ACER AW37 - CS4235 */ |
| 212 | { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 213 | /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */ |
| 214 | { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 215 | /* Crystal 3D - CS4237B */ |
| 216 | { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 217 | /* Typhoon Soundsystem PnP - CS4236B */ |
| 218 | { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 219 | /* Crystal CX4235-XQ3 EP - CS4235 */ |
| 220 | { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, |
| 221 | /* Crystal Semiconductors CS4237B */ |
| 222 | { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 223 | /* NewClear 3D - CX4237B-XQ3 */ |
| 224 | { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 225 | /* Dell Optiplex GX1 - CS4236B */ |
| 226 | { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 227 | /* Dell P410 motherboard - CS4236B */ |
| 228 | { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } }, |
| 229 | /* Dell Workstation 400 Onboard - CS4236B */ |
| 230 | { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 231 | /* Turtle Beach Malibu - CS4237B */ |
| 232 | { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 233 | /* CS4235 - onboard */ |
| 234 | { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, |
| 235 | /* IBM Aptiva 2137 E24 Onboard - CS4237B */ |
| 236 | { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 237 | /* IBM IntelliStation M Pro motherboard */ |
| 238 | { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } }, |
| 239 | /* Guillemot MaxiSound 16 PnP - CS4236B */ |
| 240 | { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 241 | /* Gallant SC-70P */ |
| 242 | { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 243 | /* TerraTec AudioSystem EWS64XL - CS4236B */ |
| 244 | { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } }, |
| 245 | /* TerraTec AudioSystem EWS64XL - CS4236B */ |
| 246 | { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } }, |
| 247 | /* ACER AW37/Pro - CS4235 */ |
| 248 | { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 249 | /* ACER AW35/Pro - CS4237B */ |
| 250 | { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 251 | /* CS4235 without MPU401 */ |
| 252 | { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } }, |
| 253 | /* Unknown SiS530 - CS4235 */ |
| 254 | { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } }, |
| 255 | /* IBM IntelliStation M Pro 6898 11U - CS4236B */ |
| 256 | { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } }, |
| 257 | /* IBM PC 300PL Onboard - CS4236B */ |
| 258 | { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } }, |
| 259 | /* Some noname CS4236 based card */ |
| 260 | { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 261 | /* CS4236B */ |
| 262 | { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 263 | /* CS4236B */ |
| 264 | { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, |
| 265 | /* --- */ |
| 266 | { .id = "" } /* end */ |
| 267 | }; |
| 268 | #endif |
| 269 | |
| 270 | MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids); |
| 271 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 272 | /* WSS initialization */ |
| 273 | static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev, |
| 274 | struct pnp_resource_table *cfg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | int err; |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | pnp_init_resource_table(cfg); |
| 279 | if (port[dev] != SNDRV_AUTO_PORT) |
| 280 | pnp_resource_change(&cfg->port_resource[0], port[dev], 4); |
| 281 | if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0) |
| 282 | pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4); |
| 283 | if (sb_port[dev] != SNDRV_AUTO_PORT) |
| 284 | pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16); |
| 285 | if (irq[dev] != SNDRV_AUTO_IRQ) |
| 286 | pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); |
| 287 | if (dma1[dev] != SNDRV_AUTO_DMA) |
| 288 | pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1); |
| 289 | if (dma2[dev] != SNDRV_AUTO_DMA) |
| 290 | pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1); |
| 291 | err = pnp_manual_config_dev(pdev, cfg, 0); |
| 292 | if (err < 0) |
| 293 | snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n"); |
| 294 | err = pnp_activate_dev(pdev); |
| 295 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n"); |
| 297 | return -EBUSY; |
| 298 | } |
| 299 | port[dev] = pnp_port_start(pdev, 0); |
| 300 | if (fm_port[dev] > 0) |
| 301 | fm_port[dev] = pnp_port_start(pdev, 1); |
| 302 | sb_port[dev] = pnp_port_start(pdev, 2); |
| 303 | irq[dev] = pnp_irq(pdev, 0); |
| 304 | dma1[dev] = pnp_dma(pdev, 0); |
| 305 | dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1); |
| 306 | snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n", |
| 307 | port[dev], fm_port[dev], sb_port[dev]); |
| 308 | snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n", |
| 309 | irq[dev], dma1[dev], dma2[dev]); |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | /* CTRL initialization */ |
| 314 | static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev, |
| 315 | struct pnp_resource_table *cfg) |
| 316 | { |
| 317 | int err; |
| 318 | |
| 319 | pnp_init_resource_table(cfg); |
| 320 | if (cport[dev] != SNDRV_AUTO_PORT) |
| 321 | pnp_resource_change(&cfg->port_resource[0], cport[dev], 8); |
| 322 | err = pnp_manual_config_dev(pdev, cfg, 0); |
| 323 | if (err < 0) |
| 324 | snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n"); |
| 325 | err = pnp_activate_dev(pdev); |
| 326 | if (err < 0) { |
| 327 | printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n"); |
| 328 | return -EBUSY; |
| 329 | } |
| 330 | cport[dev] = pnp_port_start(pdev, 0); |
| 331 | snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]); |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | /* MPU initialization */ |
| 336 | static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev, |
| 337 | struct pnp_resource_table *cfg) |
| 338 | { |
| 339 | int err; |
| 340 | |
| 341 | pnp_init_resource_table(cfg); |
| 342 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 343 | pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2); |
| 344 | if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0) |
| 345 | pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1); |
| 346 | err = pnp_manual_config_dev(pdev, cfg, 0); |
| 347 | if (err < 0) |
| 348 | snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n"); |
| 349 | err = pnp_activate_dev(pdev); |
| 350 | if (err < 0) { |
| 351 | printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n"); |
| 352 | mpu_port[dev] = SNDRV_AUTO_PORT; |
| 353 | mpu_irq[dev] = SNDRV_AUTO_IRQ; |
| 354 | } else { |
| 355 | mpu_port[dev] = pnp_port_start(pdev, 0); |
| 356 | if (mpu_irq[dev] >= 0 && |
| 357 | pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) { |
| 358 | mpu_irq[dev] = pnp_irq(pdev, 0); |
| 359 | } else { |
| 360 | mpu_irq[dev] = -1; /* disable interrupt */ |
| 361 | } |
| 362 | } |
| 363 | snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]); |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | #ifdef CS4232 |
| 368 | static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard, |
| 369 | struct pnp_dev *pdev) |
| 370 | { |
| 371 | struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); |
| 372 | |
| 373 | if (!cfg) |
| 374 | return -ENOMEM; |
| 375 | if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) { |
| 376 | kfree(cfg); |
| 377 | return -EBUSY; |
| 378 | } |
| 379 | kfree(cfg); |
| 380 | cport[dev] = -1; |
| 381 | return 0; |
| 382 | } |
| 383 | #endif |
| 384 | |
| 385 | static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard, |
| 386 | struct pnp_card_link *card, |
| 387 | const struct pnp_card_device_id *id) |
| 388 | { |
| 389 | struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); |
| 390 | |
| 391 | if (!cfg) |
| 392 | return -ENOMEM; |
| 393 | |
| 394 | acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL); |
| 395 | if (acard->wss == NULL) |
| 396 | goto error; |
| 397 | acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL); |
| 398 | if (acard->ctrl == NULL) |
| 399 | goto error; |
| 400 | if (id->devs[2].id[0]) { |
| 401 | acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); |
| 402 | if (acard->mpu == NULL) |
| 403 | goto error; |
| 404 | } |
| 405 | |
| 406 | /* WSS initialization */ |
| 407 | if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) |
| 408 | goto error; |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* CTRL initialization */ |
| 411 | if (acard->ctrl && cport[dev] > 0) { |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 412 | if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0) |
| 413 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | /* MPU initialization */ |
| 416 | if (acard->mpu && mpu_port[dev] > 0) { |
Rene Herman | 6f595cf | 2006-02-24 13:03:51 -0800 | [diff] [blame] | 417 | if (snd_cs423x_pnp_init_mpu(dev, acard->mpu, cfg) < 0) |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 418 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | kfree(cfg); |
| 421 | return 0; |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 422 | |
| 423 | error: |
| 424 | kfree(cfg); |
| 425 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | #endif /* CONFIG_PNP */ |
| 428 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 429 | #ifdef CONFIG_PNP |
| 430 | #define is_isapnp_selected(dev) isapnp[dev] |
| 431 | #else |
| 432 | #define is_isapnp_selected(dev) 0 |
| 433 | #endif |
| 434 | |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 435 | static void snd_card_cs4236_free(struct snd_card *card) |
| 436 | { |
| 437 | struct snd_card_cs4236 *acard = card->private_data; |
| 438 | |
| 439 | release_and_free_resource(acard->res_sb_port); |
| 440 | } |
| 441 | |
| 442 | static struct snd_card *snd_cs423x_card_new(int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 444 | struct snd_card *card; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 445 | |
| 446 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 447 | sizeof(struct snd_card_cs4236)); |
| 448 | if (card == NULL) |
| 449 | return NULL; |
| 450 | card->private_free = snd_card_cs4236_free; |
| 451 | return card; |
| 452 | } |
| 453 | |
| 454 | static int __devinit snd_cs423x_probe(struct snd_card *card, int dev) |
| 455 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | struct snd_card_cs4236 *acard; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 457 | struct snd_pcm *pcm; |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 458 | struct snd_cs4231 *chip; |
| 459 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | int err; |
| 461 | |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 462 | acard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) |
| 464 | if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) { |
| 465 | printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]); |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 466 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | #ifdef CS4232 |
| 470 | if ((err = snd_cs4231_create(card, |
| 471 | port[dev], |
| 472 | cport[dev], |
| 473 | irq[dev], |
| 474 | dma1[dev], |
| 475 | dma2[dev], |
| 476 | CS4231_HW_DETECT, |
| 477 | 0, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 478 | &chip)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 479 | return err; |
| 480 | acard->chip = chip; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 481 | |
| 482 | if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 483 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 484 | |
| 485 | if ((err = snd_cs4231_mixer(chip)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 486 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | #else /* CS4236 */ |
| 489 | if ((err = snd_cs4236_create(card, |
| 490 | port[dev], |
| 491 | cport[dev], |
| 492 | irq[dev], |
| 493 | dma1[dev], |
| 494 | dma2[dev], |
| 495 | CS4231_HW_DETECT, |
| 496 | 0, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 497 | &chip)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 498 | return err; |
| 499 | acard->chip = chip; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 500 | |
| 501 | if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 502 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 503 | |
| 504 | if ((err = snd_cs4236_mixer(chip)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 505 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | #endif |
| 507 | strcpy(card->driver, pcm->name); |
| 508 | strcpy(card->shortname, pcm->name); |
| 509 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", |
| 510 | pcm->name, |
| 511 | chip->port, |
| 512 | irq[dev], |
| 513 | dma1[dev]); |
| 514 | if (dma2[dev] >= 0) |
| 515 | sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]); |
| 516 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 517 | if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 518 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 521 | if (snd_opl3_create(card, |
| 522 | fm_port[dev], fm_port[dev] + 2, |
| 523 | OPL3_HW_OPL3_CS, 0, &opl3) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 524 | printk(KERN_WARNING IDENT ": OPL3 not detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } else { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 526 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 527 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 532 | if (mpu_irq[dev] == SNDRV_AUTO_IRQ) |
| 533 | mpu_irq[dev] = -1; |
| 534 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, |
| 535 | mpu_port[dev], 0, |
| 536 | mpu_irq[dev], |
| 537 | mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0) |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 538 | printk(KERN_WARNING IDENT ": MPU401 not detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 540 | |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 541 | return snd_card_register(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 544 | static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev) |
| 545 | { |
| 546 | int dev = pdev->id; |
| 547 | struct snd_card *card; |
| 548 | int err; |
| 549 | |
| 550 | if (port[dev] == SNDRV_AUTO_PORT) { |
| 551 | snd_printk(KERN_ERR "specify port\n"); |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | if (cport[dev] == SNDRV_AUTO_PORT) { |
| 555 | snd_printk(KERN_ERR "specify cport\n"); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | card = snd_cs423x_card_new(dev); |
| 560 | if (! card) |
| 561 | return -ENOMEM; |
| 562 | snd_card_set_dev(card, &pdev->dev); |
| 563 | if ((err = snd_cs423x_probe(card, dev)) < 0) { |
| 564 | snd_card_free(card); |
| 565 | return err; |
| 566 | } |
| 567 | |
| 568 | platform_set_drvdata(pdev, card); |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr) |
| 573 | { |
| 574 | snd_card_free(platform_get_drvdata(devptr)); |
| 575 | platform_set_drvdata(devptr, NULL); |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | #ifdef CONFIG_PM |
| 580 | static int snd_cs423x_suspend(struct snd_card *card) |
| 581 | { |
| 582 | struct snd_card_cs4236 *acard = card->private_data; |
| 583 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 584 | acard->chip->suspend(acard->chip); |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int snd_cs423x_resume(struct snd_card *card) |
| 589 | { |
| 590 | struct snd_card_cs4236 *acard = card->private_data; |
| 591 | acard->chip->resume(acard->chip); |
| 592 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state) |
| 597 | { |
| 598 | return snd_cs423x_suspend(platform_get_drvdata(dev)); |
| 599 | } |
| 600 | |
| 601 | static int snd_cs423x_nonpnp_resume(struct platform_device *dev) |
| 602 | { |
| 603 | return snd_cs423x_resume(platform_get_drvdata(dev)); |
| 604 | } |
| 605 | #endif |
| 606 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 607 | static struct platform_driver cs423x_nonpnp_driver = { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 608 | .probe = snd_cs423x_nonpnp_probe, |
| 609 | .remove = __devexit_p(snd_cs423x_nonpnp_remove), |
| 610 | #ifdef CONFIG_PM |
| 611 | .suspend = snd_cs423x_nonpnp_suspend, |
| 612 | .resume = snd_cs423x_nonpnp_resume, |
| 613 | #endif |
| 614 | .driver = { |
| 615 | .name = CS423X_DRIVER |
| 616 | }, |
| 617 | }; |
| 618 | |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | #ifdef CONFIG_PNP |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 621 | #ifdef CS4232 |
| 622 | static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev, |
| 623 | const struct pnp_device_id *id) |
| 624 | { |
| 625 | static int dev; |
| 626 | int err; |
| 627 | struct snd_card *card; |
| 628 | |
| 629 | if (pnp_device_is_isapnp(pdev)) |
| 630 | return -ENOENT; /* we have another procedure - card */ |
| 631 | for (; dev < SNDRV_CARDS; dev++) { |
| 632 | if (enable[dev] && isapnp[dev]) |
| 633 | break; |
| 634 | } |
| 635 | if (dev >= SNDRV_CARDS) |
| 636 | return -ENODEV; |
| 637 | |
| 638 | card = snd_cs423x_card_new(dev); |
| 639 | if (! card) |
| 640 | return -ENOMEM; |
| 641 | if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) { |
| 642 | printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); |
| 643 | snd_card_free(card); |
| 644 | return err; |
| 645 | } |
| 646 | snd_card_set_dev(card, &pdev->dev); |
| 647 | if ((err = snd_cs423x_probe(card, dev)) < 0) { |
| 648 | snd_card_free(card); |
| 649 | return err; |
| 650 | } |
| 651 | pnp_set_drvdata(pdev, card); |
| 652 | dev++; |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev) |
| 657 | { |
| 658 | snd_card_free(pnp_get_drvdata(pdev)); |
| 659 | pnp_set_drvdata(pdev, NULL); |
| 660 | } |
| 661 | |
| 662 | #ifdef CONFIG_PM |
| 663 | static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) |
| 664 | { |
| 665 | return snd_cs423x_suspend(pnp_get_drvdata(pdev)); |
| 666 | } |
| 667 | |
| 668 | static int snd_cs4232_pnp_resume(struct pnp_dev *pdev) |
| 669 | { |
| 670 | return snd_cs423x_resume(pnp_get_drvdata(pdev)); |
| 671 | } |
| 672 | #endif |
| 673 | |
| 674 | static struct pnp_driver cs4232_pnp_driver = { |
| 675 | .name = "cs4232-pnpbios", |
| 676 | .id_table = snd_cs4232_pnpbiosids, |
| 677 | .probe = snd_cs4232_pnpbios_detect, |
| 678 | .remove = __devexit_p(snd_cs4232_pnp_remove), |
| 679 | #ifdef CONFIG_PM |
| 680 | .suspend = snd_cs4232_pnp_suspend, |
| 681 | .resume = snd_cs4232_pnp_resume, |
| 682 | #endif |
| 683 | }; |
| 684 | #endif /* CS4232 */ |
| 685 | |
| 686 | static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard, |
| 687 | const struct pnp_card_device_id *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
| 689 | static int dev; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 690 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | int res; |
| 692 | |
| 693 | for ( ; dev < SNDRV_CARDS; dev++) { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 694 | if (enable[dev] && isapnp[dev]) |
| 695 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 697 | if (dev >= SNDRV_CARDS) |
| 698 | return -ENODEV; |
| 699 | |
| 700 | card = snd_cs423x_card_new(dev); |
| 701 | if (! card) |
| 702 | return -ENOMEM; |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 703 | if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) { |
| 704 | printk(KERN_ERR "isapnp detection failed and probing for " IDENT |
| 705 | " is not supported\n"); |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 706 | snd_card_free(card); |
| 707 | return res; |
| 708 | } |
| 709 | snd_card_set_dev(card, &pcard->card->dev); |
| 710 | if ((res = snd_cs423x_probe(card, dev)) < 0) { |
| 711 | snd_card_free(card); |
| 712 | return res; |
| 713 | } |
| 714 | pnp_set_card_drvdata(pcard, card); |
| 715 | dev++; |
| 716 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 719 | static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 721 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 722 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 725 | #ifdef CONFIG_PM |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 726 | static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 727 | { |
| 728 | return snd_cs423x_suspend(pnp_get_card_drvdata(pcard)); |
| 729 | } |
| 730 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 731 | static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 732 | { |
| 733 | return snd_cs423x_resume(pnp_get_card_drvdata(pcard)); |
| 734 | } |
| 735 | #endif |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | static struct pnp_card_driver cs423x_pnpc_driver = { |
| 738 | .flags = PNP_DRIVER_RES_DISABLE, |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 739 | .name = CS423X_ISAPNP_DRIVER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | .id_table = snd_cs423x_pnpids, |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 741 | .probe = snd_cs423x_pnpc_detect, |
| 742 | .remove = __devexit_p(snd_cs423x_pnpc_remove), |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 743 | #ifdef CONFIG_PM |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 744 | .suspend = snd_cs423x_pnpc_suspend, |
| 745 | .resume = snd_cs423x_pnpc_resume, |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 746 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | }; |
| 748 | #endif /* CONFIG_PNP */ |
| 749 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 750 | static void __init_or_module snd_cs423x_unregister_all(void) |
| 751 | { |
| 752 | int i; |
| 753 | |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 754 | #ifdef CONFIG_PNP |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 755 | if (pnpc_registered) |
| 756 | pnp_unregister_card_driver(&cs423x_pnpc_driver); |
| 757 | #ifdef CS4232 |
| 758 | if (pnp_registered) |
| 759 | pnp_unregister_driver(&cs4232_pnp_driver); |
| 760 | #endif |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 761 | #endif /* CONFIG_PNP */ |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 762 | for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) |
| 763 | platform_device_unregister(platform_devices[i]); |
| 764 | platform_driver_unregister(&cs423x_nonpnp_driver); |
| 765 | } |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | static int __init alsa_card_cs423x_init(void) |
| 768 | { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 769 | int i, err, cards = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 771 | if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0) |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 772 | return err; |
| 773 | |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame^] | 774 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 775 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame^] | 776 | if (! enable[i] || is_isapnp_selected(i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | continue; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 778 | device = platform_device_register_simple(CS423X_DRIVER, |
| 779 | i, NULL, 0); |
| 780 | if (IS_ERR(device)) { |
| 781 | err = PTR_ERR(device); |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 782 | goto errout; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 783 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 784 | platform_devices[i] = device; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 785 | cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 787 | #ifdef CONFIG_PNP |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 788 | #ifdef CS4232 |
| 789 | i = pnp_register_driver(&cs4232_pnp_driver); |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 790 | if (i >= 0) { |
| 791 | pnp_registered = 1; |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 792 | cards += i; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 793 | } |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 794 | #endif |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 795 | i = pnp_register_card_driver(&cs423x_pnpc_driver); |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 796 | if (i >= 0) { |
| 797 | pnpc_registered = 1; |
Takashi Iwai | 6bba41a | 2005-11-17 17:00:53 +0100 | [diff] [blame] | 798 | cards += i; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 799 | } |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 800 | #endif /* CONFIG_PNP */ |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | if (!cards) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | #ifdef MODULE |
| 804 | printk(KERN_ERR IDENT " soundcard not found or device busy\n"); |
| 805 | #endif |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 806 | err = -ENODEV; |
| 807 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | return 0; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 810 | |
| 811 | errout: |
| 812 | snd_cs423x_unregister_all(); |
| 813 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void __exit alsa_card_cs423x_exit(void) |
| 817 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 818 | snd_cs423x_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | module_init(alsa_card_cs423x_init) |
| 822 | module_exit(alsa_card_cs423x_exit) |