| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips | 
 | 3 |  *  Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h> | 
 | 23 | #include <linux/err.h> | 
 | 24 | #include <linux/isa.h> | 
 | 25 | #include <linux/pnp.h> | 
 | 26 | #include <linux/module.h> | 
 | 27 | #include <sound/core.h> | 
 | 28 | #include <sound/wss.h> | 
 | 29 | #include <sound/mpu401.h> | 
 | 30 | #include <sound/opl3.h> | 
 | 31 | #include <sound/initval.h> | 
 | 32 |  | 
 | 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); | 
 | 34 | MODULE_LICENSE("GPL"); | 
 | 35 | MODULE_DESCRIPTION("Cirrus Logic CS4232-9"); | 
 | 36 | MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000}," | 
 | 37 | 		"{Turtle Beach,Tropez Plus}," | 
 | 38 | 		"{SIC CrystalWave 32}," | 
 | 39 | 		"{Hewlett Packard,Omnibook 5500}," | 
 | 40 | 		"{TerraTec,Maestro 32/96}," | 
 | 41 | 		"{Philips,PCA70PS}}," | 
 | 42 | 		"{{Crystal Semiconductors,CS4235}," | 
 | 43 | 		"{Crystal Semiconductors,CS4236}," | 
 | 44 | 		"{Crystal Semiconductors,CS4237}," | 
 | 45 | 		"{Crystal Semiconductors,CS4238}," | 
 | 46 | 		"{Crystal Semiconductors,CS4239}," | 
 | 47 | 		"{Acer,AW37}," | 
 | 48 | 		"{Acer,AW35/Pro}," | 
 | 49 | 		"{Crystal,3D}," | 
 | 50 | 		"{Crystal Computer,TidalWave128}," | 
 | 51 | 		"{Dell,Optiplex GX1}," | 
 | 52 | 		"{Dell,Workstation 400 sound}," | 
 | 53 | 		"{EliteGroup,P5TX-LA sound}," | 
 | 54 | 		"{Gallant,SC-70P}," | 
 | 55 | 		"{Gateway,E1000 Onboard CS4236B}," | 
 | 56 | 		"{Genius,Sound Maker 3DJ}," | 
 | 57 | 		"{Hewlett Packard,HP6330 sound}," | 
 | 58 | 		"{IBM,PC 300PL sound}," | 
 | 59 | 		"{IBM,Aptiva 2137 E24}," | 
 | 60 | 		"{IBM,IntelliStation M Pro}," | 
 | 61 | 		"{Intel,Marlin Spike Mobo CS4235}," | 
 | 62 | 		"{Intel PR440FX Onboard}," | 
 | 63 | 		"{Guillemot,MaxiSound 16 PnP}," | 
 | 64 | 		"{NewClear,3D}," | 
 | 65 | 		"{TerraTec,AudioSystem EWS64L/XL}," | 
 | 66 | 		"{Typhoon Soundsystem,CS4236B}," | 
 | 67 | 		"{Turtle Beach,Malibu}," | 
 | 68 | 		"{Unknown,Digital PC 5000 Onboard}}"); | 
 | 69 |  | 
 | 70 | MODULE_ALIAS("snd_cs4232"); | 
 | 71 |  | 
 | 72 | #define IDENT "CS4232+" | 
 | 73 | #define DEV_NAME "cs4232+" | 
 | 74 |  | 
 | 75 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
 | 76 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
 | 77 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ | 
 | 78 | #ifdef CONFIG_PNP | 
 | 79 | static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; | 
 | 80 | #endif | 
 | 81 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */ | 
 | 82 | static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */ | 
 | 83 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */ | 
 | 84 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */ | 
 | 85 | static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */ | 
 | 86 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */ | 
 | 87 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 9,11,12,15 */ | 
 | 88 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */ | 
 | 89 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */ | 
 | 90 |  | 
 | 91 | module_param_array(index, int, NULL, 0444); | 
 | 92 | MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard."); | 
 | 93 | module_param_array(id, charp, NULL, 0444); | 
 | 94 | MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard."); | 
 | 95 | module_param_array(enable, bool, NULL, 0444); | 
 | 96 | MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard."); | 
 | 97 | #ifdef CONFIG_PNP | 
 | 98 | module_param_array(isapnp, bool, NULL, 0444); | 
 | 99 | MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); | 
 | 100 | #endif | 
 | 101 | module_param_hw_array(port, long, ioport, NULL, 0444); | 
 | 102 | MODULE_PARM_DESC(port, "Port # for " IDENT " driver."); | 
 | 103 | module_param_hw_array(cport, long, ioport, NULL, 0444); | 
 | 104 | MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver."); | 
 | 105 | module_param_hw_array(mpu_port, long, ioport, NULL, 0444); | 
 | 106 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver."); | 
 | 107 | module_param_hw_array(fm_port, long, ioport, NULL, 0444); | 
 | 108 | MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver."); | 
 | 109 | module_param_hw_array(sb_port, long, ioport, NULL, 0444); | 
 | 110 | MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional)."); | 
 | 111 | module_param_hw_array(irq, int, irq, NULL, 0444); | 
 | 112 | MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver."); | 
 | 113 | module_param_hw_array(mpu_irq, int, irq, NULL, 0444); | 
 | 114 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver."); | 
 | 115 | module_param_hw_array(dma1, int, dma, NULL, 0444); | 
 | 116 | MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver."); | 
 | 117 | module_param_hw_array(dma2, int, dma, NULL, 0444); | 
 | 118 | MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver."); | 
 | 119 |  | 
 | 120 | #ifdef CONFIG_PNP | 
 | 121 | static int isa_registered; | 
 | 122 | static int pnpc_registered; | 
 | 123 | static int pnp_registered; | 
 | 124 | #endif /* CONFIG_PNP */ | 
 | 125 |  | 
 | 126 | struct snd_card_cs4236 { | 
 | 127 | 	struct snd_wss *chip; | 
 | 128 | 	struct resource *res_sb_port; | 
 | 129 | #ifdef CONFIG_PNP | 
 | 130 | 	struct pnp_dev *wss; | 
 | 131 | 	struct pnp_dev *ctrl; | 
 | 132 | 	struct pnp_dev *mpu; | 
 | 133 | #endif | 
 | 134 | }; | 
 | 135 |  | 
 | 136 | #ifdef CONFIG_PNP | 
 | 137 |  | 
 | 138 | /* | 
 | 139 |  * PNP BIOS | 
 | 140 |  */ | 
 | 141 | static const struct pnp_device_id snd_cs423x_pnpbiosids[] = { | 
 | 142 | 	{ .id = "CSC0100" }, | 
 | 143 | 	{ .id = "CSC0000" }, | 
 | 144 | 	/* Guillemot Turtlebeach something appears to be cs4232 compatible | 
 | 145 | 	 * (untested) */ | 
 | 146 | 	{ .id = "GIM0100" }, | 
 | 147 | 	{ .id = "" } | 
 | 148 | }; | 
 | 149 | MODULE_DEVICE_TABLE(pnp, snd_cs423x_pnpbiosids); | 
 | 150 |  | 
 | 151 | #define CS423X_ISAPNP_DRIVER	"cs4232_isapnp" | 
 | 152 | static const struct pnp_card_device_id snd_cs423x_pnpids[] = { | 
 | 153 | 	/* Philips PCA70PS */ | 
 | 154 | 	{ .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, | 
 | 155 | 	/* TerraTec Maestro 32/96 (CS4232) */ | 
 | 156 | 	{ .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 157 | 	/* HP Omnibook 5500 onboard */ | 
 | 158 | 	{ .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } }, | 
 | 159 | 	/* Unnamed CS4236 card (Made in Taiwan) */ | 
 | 160 | 	{ .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 161 | 	/* Turtle Beach TBS-2000 (CS4232) */ | 
 | 162 | 	{ .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } }, | 
 | 163 | 	/* Turtle Beach Tropez Plus (CS4232) */ | 
 | 164 | 	{ .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } }, | 
 | 165 | 	/* SIC CrystalWave 32 (CS4232) */ | 
 | 166 | 	{ .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 167 | 	/* Netfinity 3000 on-board soundcard */ | 
 | 168 | 	{ .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } }, | 
 | 169 | 	/* Intel Marlin Spike Motherboard - CS4235 */ | 
 | 170 | 	{ .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 171 | 	/* Intel Marlin Spike Motherboard (#2) - CS4235 */ | 
 | 172 | 	{ .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, | 
 | 173 | 	/* Unknown Intel mainboard - CS4235 */ | 
 | 174 | 	{ .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } }, | 
 | 175 | 	/* Genius Sound Maker 3DJ - CS4237B */ | 
 | 176 | 	{ .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 177 | 	/* Digital PC 5000 Onboard - CS4236B */ | 
 | 178 | 	{ .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } }, | 
 | 179 | 	/* some unknown CS4236B */ | 
 | 180 | 	{ .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 181 | 	/* Intel PR440FX Onboard sound */ | 
 | 182 | 	{ .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 183 | 	/* CS4235 on mainboard without MPU */ | 
 | 184 | 	{ .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } }, | 
 | 185 | 	/* Gateway E1000 Onboard CS4236B */ | 
 | 186 | 	{ .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 187 | 	/* HP 6330 Onboard sound */ | 
 | 188 | 	{ .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, | 
 | 189 | 	/* Crystal Computer TidalWave128 */ | 
 | 190 | 	{ .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 191 | 	/* ACER AW37 - CS4235 */ | 
 | 192 | 	{ .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 193 | 	/* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */ | 
 | 194 | 	{ .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 195 | 	/* Crystal 3D - CS4237B */ | 
 | 196 | 	{ .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 197 | 	/* Typhoon Soundsystem PnP - CS4236B */ | 
 | 198 | 	{ .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 199 | 	/* Crystal CX4235-XQ3 EP - CS4235 */ | 
 | 200 | 	{ .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, | 
 | 201 | 	/* Crystal Semiconductors CS4237B */ | 
 | 202 | 	{ .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 203 | 	/* NewClear 3D - CX4237B-XQ3 */ | 
 | 204 | 	{ .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 205 | 	/* Dell Optiplex GX1 - CS4236B */ | 
 | 206 | 	{ .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 207 | 	/* Dell P410 motherboard - CS4236B */ | 
 | 208 | 	{ .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } }, | 
 | 209 | 	/* Dell Workstation 400 Onboard - CS4236B */ | 
 | 210 | 	{ .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 211 | 	/* Turtle Beach Malibu - CS4237B */ | 
 | 212 | 	{ .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 213 | 	/* CS4235 - onboard */ | 
 | 214 | 	{ .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } }, | 
 | 215 | 	/* IBM Aptiva 2137 E24 Onboard - CS4237B */ | 
 | 216 | 	{ .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 217 | 	/* IBM IntelliStation M Pro motherboard */ | 
 | 218 | 	{ .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } }, | 
 | 219 | 	/* Guillemot MaxiSound 16 PnP - CS4236B */ | 
 | 220 | 	{ .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 221 | 	/* Gallant SC-70P */ | 
 | 222 | 	{ .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 223 | 	/* Techmakers MF-4236PW */ | 
 | 224 | 	{ .id = "CSCa736", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 225 | 	/* TerraTec AudioSystem EWS64XL - CS4236B */ | 
 | 226 | 	{ .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } }, | 
 | 227 | 	/* TerraTec AudioSystem EWS64XL - CS4236B */ | 
 | 228 | 	{ .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } }, | 
 | 229 | 	/* ACER AW37/Pro - CS4235 */ | 
 | 230 | 	{ .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 231 | 	/* ACER AW35/Pro - CS4237B */ | 
 | 232 | 	{ .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 233 | 	/* CS4235 without MPU401 */ | 
 | 234 | 	{ .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } }, | 
 | 235 | 	/* Unknown SiS530 - CS4235 */ | 
 | 236 | 	{ .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } }, | 
 | 237 | 	/* IBM IntelliStation M Pro 6898 11U - CS4236B */ | 
 | 238 | 	{ .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } }, | 
 | 239 | 	/* IBM PC 300PL Onboard - CS4236B */ | 
 | 240 | 	{ .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } }, | 
 | 241 | 	/* Some noname CS4236 based card */ | 
 | 242 | 	{ .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 243 | 	/* CS4236B */ | 
 | 244 | 	{ .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 245 | 	/* CS4236B */ | 
 | 246 | 	{ .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, | 
 | 247 | 	/* --- */ | 
 | 248 | 	{ .id = "" }	/* end */ | 
 | 249 | }; | 
 | 250 |  | 
 | 251 | MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids); | 
 | 252 |  | 
 | 253 | /* WSS initialization */ | 
 | 254 | static int snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev) | 
 | 255 | { | 
 | 256 | 	if (pnp_activate_dev(pdev) < 0) { | 
 | 257 | 		printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n"); | 
 | 258 | 		return -EBUSY; | 
 | 259 | 	} | 
 | 260 | 	port[dev] = pnp_port_start(pdev, 0); | 
 | 261 | 	if (fm_port[dev] > 0) | 
 | 262 | 		fm_port[dev] = pnp_port_start(pdev, 1); | 
 | 263 | 	sb_port[dev] = pnp_port_start(pdev, 2); | 
 | 264 | 	irq[dev] = pnp_irq(pdev, 0); | 
 | 265 | 	dma1[dev] = pnp_dma(pdev, 0); | 
 | 266 | 	dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1); | 
 | 267 | 	snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n", | 
 | 268 | 			port[dev], fm_port[dev], sb_port[dev]); | 
 | 269 | 	snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n", | 
 | 270 | 			irq[dev], dma1[dev], dma2[dev]); | 
 | 271 | 	return 0; | 
 | 272 | } | 
 | 273 |  | 
 | 274 | /* CTRL initialization */ | 
 | 275 | static int snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev) | 
 | 276 | { | 
 | 277 | 	if (pnp_activate_dev(pdev) < 0) { | 
 | 278 | 		printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n"); | 
 | 279 | 		return -EBUSY; | 
 | 280 | 	} | 
 | 281 | 	cport[dev] = pnp_port_start(pdev, 0); | 
 | 282 | 	snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]); | 
 | 283 | 	return 0; | 
 | 284 | } | 
 | 285 |  | 
 | 286 | /* MPU initialization */ | 
 | 287 | static int snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev) | 
 | 288 | { | 
 | 289 | 	if (pnp_activate_dev(pdev) < 0) { | 
 | 290 | 		printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n"); | 
 | 291 | 		mpu_port[dev] = SNDRV_AUTO_PORT; | 
 | 292 | 		mpu_irq[dev] = SNDRV_AUTO_IRQ; | 
 | 293 | 	} else { | 
 | 294 | 		mpu_port[dev] = pnp_port_start(pdev, 0); | 
 | 295 | 		if (mpu_irq[dev] >= 0 && | 
 | 296 | 		    pnp_irq_valid(pdev, 0) && | 
 | 297 | 		    pnp_irq(pdev, 0) != (resource_size_t)-1) { | 
 | 298 | 			mpu_irq[dev] = pnp_irq(pdev, 0); | 
 | 299 | 		} else { | 
 | 300 | 			mpu_irq[dev] = -1;	/* disable interrupt */ | 
 | 301 | 		} | 
 | 302 | 	} | 
 | 303 | 	snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]); | 
 | 304 | 	return 0; | 
 | 305 | } | 
 | 306 |  | 
 | 307 | static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard, | 
 | 308 | 			       struct pnp_dev *pdev, | 
 | 309 | 			       struct pnp_dev *cdev) | 
 | 310 | { | 
 | 311 | 	acard->wss = pdev; | 
 | 312 | 	if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0) | 
 | 313 | 		return -EBUSY; | 
 | 314 | 	if (cdev) | 
 | 315 | 		cport[dev] = pnp_port_start(cdev, 0); | 
 | 316 | 	else | 
 | 317 | 		cport[dev] = -1; | 
 | 318 | 	return 0; | 
 | 319 | } | 
 | 320 |  | 
 | 321 | static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard, | 
 | 322 | 				struct pnp_card_link *card, | 
 | 323 | 				const struct pnp_card_device_id *id) | 
 | 324 | { | 
 | 325 | 	acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL); | 
 | 326 | 	if (acard->wss == NULL) | 
 | 327 | 		return -EBUSY; | 
 | 328 | 	acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL); | 
 | 329 | 	if (acard->ctrl == NULL) | 
 | 330 | 		return -EBUSY; | 
 | 331 | 	if (id->devs[2].id[0]) { | 
 | 332 | 		acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); | 
 | 333 | 		if (acard->mpu == NULL) | 
 | 334 | 			return -EBUSY; | 
 | 335 | 	} | 
 | 336 |  | 
 | 337 | 	/* WSS initialization */ | 
 | 338 | 	if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0) | 
 | 339 | 		return -EBUSY; | 
 | 340 |  | 
 | 341 | 	/* CTRL initialization */ | 
 | 342 | 	if (acard->ctrl && cport[dev] > 0) { | 
 | 343 | 		if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0) | 
 | 344 | 			return -EBUSY; | 
 | 345 | 	} | 
 | 346 | 	/* MPU initialization */ | 
 | 347 | 	if (acard->mpu && mpu_port[dev] > 0) { | 
 | 348 | 		if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0) | 
 | 349 | 			return -EBUSY; | 
 | 350 | 	} | 
 | 351 | 	return 0; | 
 | 352 | } | 
 | 353 | #endif /* CONFIG_PNP */ | 
 | 354 |  | 
 | 355 | #ifdef CONFIG_PNP | 
 | 356 | #define is_isapnp_selected(dev)		isapnp[dev] | 
 | 357 | #else | 
 | 358 | #define is_isapnp_selected(dev)		0 | 
 | 359 | #endif | 
 | 360 |  | 
 | 361 | static void snd_card_cs4236_free(struct snd_card *card) | 
 | 362 | { | 
 | 363 | 	struct snd_card_cs4236 *acard = card->private_data; | 
 | 364 |  | 
 | 365 | 	release_and_free_resource(acard->res_sb_port); | 
 | 366 | } | 
 | 367 |  | 
 | 368 | static int snd_cs423x_card_new(struct device *pdev, int dev, | 
 | 369 | 			       struct snd_card **cardp) | 
 | 370 | { | 
 | 371 | 	struct snd_card *card; | 
 | 372 | 	int err; | 
 | 373 |  | 
 | 374 | 	err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, | 
 | 375 | 			   sizeof(struct snd_card_cs4236), &card); | 
 | 376 | 	if (err < 0) | 
 | 377 | 		return err; | 
 | 378 | 	card->private_free = snd_card_cs4236_free; | 
 | 379 | 	*cardp = card; | 
 | 380 | 	return 0; | 
 | 381 | } | 
 | 382 |  | 
 | 383 | static int snd_cs423x_probe(struct snd_card *card, int dev) | 
 | 384 | { | 
 | 385 | 	struct snd_card_cs4236 *acard; | 
 | 386 | 	struct snd_wss *chip; | 
 | 387 | 	struct snd_opl3 *opl3; | 
 | 388 | 	int err; | 
 | 389 |  | 
 | 390 | 	acard = card->private_data; | 
 | 391 | 	if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) | 
 | 392 | 		if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) { | 
 | 393 | 			printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]); | 
 | 394 | 			return -EBUSY; | 
 | 395 | 		} | 
 | 396 |  | 
 | 397 | 	err = snd_cs4236_create(card, port[dev], cport[dev], | 
 | 398 | 			     irq[dev], | 
 | 399 | 			     dma1[dev], dma2[dev], | 
 | 400 | 			     WSS_HW_DETECT3, 0, &chip); | 
 | 401 | 	if (err < 0) | 
 | 402 | 		return err; | 
 | 403 |  | 
 | 404 | 	acard->chip = chip; | 
 | 405 | 	if (chip->hardware & WSS_HW_CS4236B_MASK) { | 
 | 406 |  | 
 | 407 | 		err = snd_cs4236_pcm(chip, 0); | 
 | 408 | 		if (err < 0) | 
 | 409 | 			return err; | 
 | 410 |  | 
 | 411 | 		err = snd_cs4236_mixer(chip); | 
 | 412 | 		if (err < 0) | 
 | 413 | 			return err; | 
 | 414 | 	} else { | 
 | 415 | 		err = snd_wss_pcm(chip, 0); | 
 | 416 | 		if (err < 0) | 
 | 417 | 			return err; | 
 | 418 |  | 
 | 419 | 		err = snd_wss_mixer(chip); | 
 | 420 | 		if (err < 0) | 
 | 421 | 			return err; | 
 | 422 | 	} | 
 | 423 | 	strlcpy(card->driver, chip->pcm->name, sizeof(card->driver)); | 
 | 424 | 	strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); | 
 | 425 | 	if (dma2[dev] < 0) | 
 | 426 | 		snprintf(card->longname, sizeof(card->longname), | 
 | 427 | 			 "%s at 0x%lx, irq %i, dma %i", | 
 | 428 | 			 chip->pcm->name, chip->port, irq[dev], dma1[dev]); | 
 | 429 | 	else | 
 | 430 | 		snprintf(card->longname, sizeof(card->longname), | 
 | 431 | 			 "%s at 0x%lx, irq %i, dma %i&%d", | 
 | 432 | 			 chip->pcm->name, chip->port, irq[dev], dma1[dev], | 
 | 433 | 			 dma2[dev]); | 
 | 434 |  | 
 | 435 | 	err = snd_wss_timer(chip, 0); | 
 | 436 | 	if (err < 0) | 
 | 437 | 		return err; | 
 | 438 |  | 
 | 439 | 	if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { | 
 | 440 | 		if (snd_opl3_create(card, | 
 | 441 | 				    fm_port[dev], fm_port[dev] + 2, | 
 | 442 | 				    OPL3_HW_OPL3_CS, 0, &opl3) < 0) { | 
 | 443 | 			printk(KERN_WARNING IDENT ": OPL3 not detected\n"); | 
 | 444 | 		} else { | 
 | 445 | 			if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) | 
 | 446 | 				return err; | 
 | 447 | 		} | 
 | 448 | 	} | 
 | 449 |  | 
 | 450 | 	if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { | 
 | 451 | 		if (mpu_irq[dev] == SNDRV_AUTO_IRQ) | 
 | 452 | 			mpu_irq[dev] = -1; | 
 | 453 | 		if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, | 
 | 454 | 					mpu_port[dev], 0, | 
 | 455 | 					mpu_irq[dev], NULL) < 0) | 
 | 456 | 			printk(KERN_WARNING IDENT ": MPU401 not detected\n"); | 
 | 457 | 	} | 
 | 458 |  | 
 | 459 | 	return snd_card_register(card); | 
 | 460 | } | 
 | 461 |  | 
 | 462 | static int snd_cs423x_isa_match(struct device *pdev, | 
 | 463 | 				unsigned int dev) | 
 | 464 | { | 
 | 465 | 	if (!enable[dev] || is_isapnp_selected(dev)) | 
 | 466 | 		return 0; | 
 | 467 |  | 
 | 468 | 	if (port[dev] == SNDRV_AUTO_PORT) { | 
 | 469 | 		dev_err(pdev, "please specify port\n"); | 
 | 470 | 		return 0; | 
 | 471 | 	} | 
 | 472 | 	if (cport[dev] == SNDRV_AUTO_PORT) { | 
 | 473 | 		dev_err(pdev, "please specify cport\n"); | 
 | 474 | 		return 0; | 
 | 475 | 	} | 
 | 476 | 	if (irq[dev] == SNDRV_AUTO_IRQ) { | 
 | 477 | 		dev_err(pdev, "please specify irq\n"); | 
 | 478 | 		return 0; | 
 | 479 | 	} | 
 | 480 | 	if (dma1[dev] == SNDRV_AUTO_DMA) { | 
 | 481 | 		dev_err(pdev, "please specify dma1\n"); | 
 | 482 | 		return 0; | 
 | 483 | 	} | 
 | 484 | 	return 1; | 
 | 485 | } | 
 | 486 |  | 
 | 487 | static int snd_cs423x_isa_probe(struct device *pdev, | 
 | 488 | 				unsigned int dev) | 
 | 489 | { | 
 | 490 | 	struct snd_card *card; | 
 | 491 | 	int err; | 
 | 492 |  | 
 | 493 | 	err = snd_cs423x_card_new(pdev, dev, &card); | 
 | 494 | 	if (err < 0) | 
 | 495 | 		return err; | 
 | 496 | 	if ((err = snd_cs423x_probe(card, dev)) < 0) { | 
 | 497 | 		snd_card_free(card); | 
 | 498 | 		return err; | 
 | 499 | 	} | 
 | 500 |  | 
 | 501 | 	dev_set_drvdata(pdev, card); | 
 | 502 | 	return 0; | 
 | 503 | } | 
 | 504 |  | 
 | 505 | static int snd_cs423x_isa_remove(struct device *pdev, | 
 | 506 | 				 unsigned int dev) | 
 | 507 | { | 
 | 508 | 	snd_card_free(dev_get_drvdata(pdev)); | 
 | 509 | 	return 0; | 
 | 510 | } | 
 | 511 |  | 
 | 512 | #ifdef CONFIG_PM | 
 | 513 | static int snd_cs423x_suspend(struct snd_card *card) | 
 | 514 | { | 
 | 515 | 	struct snd_card_cs4236 *acard = card->private_data; | 
 | 516 | 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | 
 | 517 | 	acard->chip->suspend(acard->chip); | 
 | 518 | 	return 0; | 
 | 519 | } | 
 | 520 |  | 
 | 521 | static int snd_cs423x_resume(struct snd_card *card) | 
 | 522 | { | 
 | 523 | 	struct snd_card_cs4236 *acard = card->private_data; | 
 | 524 | 	acard->chip->resume(acard->chip); | 
 | 525 | 	snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 
 | 526 | 	return 0; | 
 | 527 | } | 
 | 528 |  | 
 | 529 | static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n, | 
 | 530 | 				  pm_message_t state) | 
 | 531 | { | 
 | 532 | 	return snd_cs423x_suspend(dev_get_drvdata(dev)); | 
 | 533 | } | 
 | 534 |  | 
 | 535 | static int snd_cs423x_isa_resume(struct device *dev, unsigned int n) | 
 | 536 | { | 
 | 537 | 	return snd_cs423x_resume(dev_get_drvdata(dev)); | 
 | 538 | } | 
 | 539 | #endif | 
 | 540 |  | 
 | 541 | static struct isa_driver cs423x_isa_driver = { | 
 | 542 | 	.match		= snd_cs423x_isa_match, | 
 | 543 | 	.probe		= snd_cs423x_isa_probe, | 
 | 544 | 	.remove		= snd_cs423x_isa_remove, | 
 | 545 | #ifdef CONFIG_PM | 
 | 546 | 	.suspend	= snd_cs423x_isa_suspend, | 
 | 547 | 	.resume		= snd_cs423x_isa_resume, | 
 | 548 | #endif | 
 | 549 | 	.driver		= { | 
 | 550 | 		.name	= DEV_NAME | 
 | 551 | 	}, | 
 | 552 | }; | 
 | 553 |  | 
 | 554 |  | 
 | 555 | #ifdef CONFIG_PNP | 
 | 556 | static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev, | 
 | 557 | 				     const struct pnp_device_id *id) | 
 | 558 | { | 
 | 559 | 	static int dev; | 
 | 560 | 	int err; | 
 | 561 | 	struct snd_card *card; | 
 | 562 | 	struct pnp_dev *cdev; | 
 | 563 | 	char cid[PNP_ID_LEN]; | 
 | 564 |  | 
 | 565 | 	if (pnp_device_is_isapnp(pdev)) | 
 | 566 | 		return -ENOENT;	/* we have another procedure - card */ | 
 | 567 | 	for (; dev < SNDRV_CARDS; dev++) { | 
 | 568 | 		if (enable[dev] && isapnp[dev]) | 
 | 569 | 			break; | 
 | 570 | 	} | 
 | 571 | 	if (dev >= SNDRV_CARDS) | 
 | 572 | 		return -ENODEV; | 
 | 573 |  | 
 | 574 | 	/* prepare second id */ | 
 | 575 | 	strcpy(cid, pdev->id[0].id); | 
 | 576 | 	cid[5] = '1'; | 
 | 577 | 	cdev = NULL; | 
 | 578 | 	list_for_each_entry(cdev, &(pdev->protocol->devices), protocol_list) { | 
 | 579 | 		if (!strcmp(cdev->id[0].id, cid)) | 
 | 580 | 			break; | 
 | 581 | 	} | 
 | 582 | 	err = snd_cs423x_card_new(&pdev->dev, dev, &card); | 
 | 583 | 	if (err < 0) | 
 | 584 | 		return err; | 
 | 585 | 	err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev); | 
 | 586 | 	if (err < 0) { | 
 | 587 | 		printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); | 
 | 588 | 		snd_card_free(card); | 
 | 589 | 		return err; | 
 | 590 | 	} | 
 | 591 | 	if ((err = snd_cs423x_probe(card, dev)) < 0) { | 
 | 592 | 		snd_card_free(card); | 
 | 593 | 		return err; | 
 | 594 | 	} | 
 | 595 | 	pnp_set_drvdata(pdev, card); | 
 | 596 | 	dev++; | 
 | 597 | 	return 0; | 
 | 598 | } | 
 | 599 |  | 
 | 600 | static void snd_cs423x_pnp_remove(struct pnp_dev *pdev) | 
 | 601 | { | 
 | 602 | 	snd_card_free(pnp_get_drvdata(pdev)); | 
 | 603 | } | 
 | 604 |  | 
 | 605 | #ifdef CONFIG_PM | 
 | 606 | static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) | 
 | 607 | { | 
 | 608 | 	return snd_cs423x_suspend(pnp_get_drvdata(pdev)); | 
 | 609 | } | 
 | 610 |  | 
 | 611 | static int snd_cs423x_pnp_resume(struct pnp_dev *pdev) | 
 | 612 | { | 
 | 613 | 	return snd_cs423x_resume(pnp_get_drvdata(pdev)); | 
 | 614 | } | 
 | 615 | #endif | 
 | 616 |  | 
 | 617 | static struct pnp_driver cs423x_pnp_driver = { | 
 | 618 | 	.name = "cs423x-pnpbios", | 
 | 619 | 	.id_table = snd_cs423x_pnpbiosids, | 
 | 620 | 	.probe = snd_cs423x_pnpbios_detect, | 
 | 621 | 	.remove = snd_cs423x_pnp_remove, | 
 | 622 | #ifdef CONFIG_PM | 
 | 623 | 	.suspend	= snd_cs423x_pnp_suspend, | 
 | 624 | 	.resume		= snd_cs423x_pnp_resume, | 
 | 625 | #endif | 
 | 626 | }; | 
 | 627 |  | 
 | 628 | static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard, | 
 | 629 | 				  const struct pnp_card_device_id *pid) | 
 | 630 | { | 
 | 631 | 	static int dev; | 
 | 632 | 	struct snd_card *card; | 
 | 633 | 	int res; | 
 | 634 |  | 
 | 635 | 	for ( ; dev < SNDRV_CARDS; dev++) { | 
 | 636 | 		if (enable[dev] && isapnp[dev]) | 
 | 637 | 			break; | 
 | 638 | 	} | 
 | 639 | 	if (dev >= SNDRV_CARDS) | 
 | 640 | 		return -ENODEV; | 
 | 641 |  | 
 | 642 | 	res = snd_cs423x_card_new(&pcard->card->dev, dev, &card); | 
 | 643 | 	if (res < 0) | 
 | 644 | 		return res; | 
 | 645 | 	if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) { | 
 | 646 | 		printk(KERN_ERR "isapnp detection failed and probing for " IDENT | 
 | 647 | 		       " is not supported\n"); | 
 | 648 | 		snd_card_free(card); | 
 | 649 | 		return res; | 
 | 650 | 	} | 
 | 651 | 	if ((res = snd_cs423x_probe(card, dev)) < 0) { | 
 | 652 | 		snd_card_free(card); | 
 | 653 | 		return res; | 
 | 654 | 	} | 
 | 655 | 	pnp_set_card_drvdata(pcard, card); | 
 | 656 | 	dev++; | 
 | 657 | 	return 0; | 
 | 658 | } | 
 | 659 |  | 
 | 660 | static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard) | 
 | 661 | { | 
 | 662 | 	snd_card_free(pnp_get_card_drvdata(pcard)); | 
 | 663 | 	pnp_set_card_drvdata(pcard, NULL); | 
 | 664 | } | 
 | 665 |  | 
 | 666 | #ifdef CONFIG_PM | 
 | 667 | static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) | 
 | 668 | { | 
 | 669 | 	return snd_cs423x_suspend(pnp_get_card_drvdata(pcard)); | 
 | 670 | } | 
 | 671 |  | 
 | 672 | static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard) | 
 | 673 | { | 
 | 674 | 	return snd_cs423x_resume(pnp_get_card_drvdata(pcard)); | 
 | 675 | } | 
 | 676 | #endif | 
 | 677 |  | 
 | 678 | static struct pnp_card_driver cs423x_pnpc_driver = { | 
 | 679 | 	.flags = PNP_DRIVER_RES_DISABLE, | 
 | 680 | 	.name = CS423X_ISAPNP_DRIVER, | 
 | 681 | 	.id_table = snd_cs423x_pnpids, | 
 | 682 | 	.probe = snd_cs423x_pnpc_detect, | 
 | 683 | 	.remove = snd_cs423x_pnpc_remove, | 
 | 684 | #ifdef CONFIG_PM | 
 | 685 | 	.suspend	= snd_cs423x_pnpc_suspend, | 
 | 686 | 	.resume		= snd_cs423x_pnpc_resume, | 
 | 687 | #endif | 
 | 688 | }; | 
 | 689 | #endif /* CONFIG_PNP */ | 
 | 690 |  | 
 | 691 | static int __init alsa_card_cs423x_init(void) | 
 | 692 | { | 
 | 693 | 	int err; | 
 | 694 |  | 
 | 695 | 	err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS); | 
 | 696 | #ifdef CONFIG_PNP | 
 | 697 | 	if (!err) | 
 | 698 | 		isa_registered = 1; | 
 | 699 | 	err = pnp_register_driver(&cs423x_pnp_driver); | 
 | 700 | 	if (!err) | 
 | 701 | 		pnp_registered = 1; | 
 | 702 | 	err = pnp_register_card_driver(&cs423x_pnpc_driver); | 
 | 703 | 	if (!err) | 
 | 704 | 		pnpc_registered = 1; | 
 | 705 | 	if (pnp_registered) | 
 | 706 | 		err = 0; | 
 | 707 | 	if (isa_registered) | 
 | 708 | 		err = 0; | 
 | 709 | #endif | 
 | 710 | 	return err; | 
 | 711 | } | 
 | 712 |  | 
 | 713 | static void __exit alsa_card_cs423x_exit(void) | 
 | 714 | { | 
 | 715 | #ifdef CONFIG_PNP | 
 | 716 | 	if (pnpc_registered) | 
 | 717 | 		pnp_unregister_card_driver(&cs423x_pnpc_driver); | 
 | 718 | 	if (pnp_registered) | 
 | 719 | 		pnp_unregister_driver(&cs423x_pnp_driver); | 
 | 720 | 	if (isa_registered) | 
 | 721 | #endif | 
 | 722 | 		isa_unregister_driver(&cs423x_isa_driver); | 
 | 723 | } | 
 | 724 |  | 
 | 725 | module_init(alsa_card_cs423x_init) | 
 | 726 | module_exit(alsa_card_cs423x_exit) |