cs4236.c 22 KB

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