cs4236.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/pnp.h>
  25. #include <linux/moduleparam.h>
  26. #include <sound/core.h>
  27. #include <sound/cs4231.h>
  28. #include <sound/mpu401.h>
  29. #include <sound/opl3.h>
  30. #include <sound/initval.h>
  31. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  32. MODULE_LICENSE("GPL");
  33. #ifdef CS4232
  34. MODULE_DESCRIPTION("Cirrus Logic CS4232");
  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. #else
  42. MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
  43. MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
  44. "{Crystal Semiconductors,CS4236},"
  45. "{Crystal Semiconductors,CS4237},"
  46. "{Crystal Semiconductors,CS4238},"
  47. "{Crystal Semiconductors,CS4239},"
  48. "{Acer,AW37},"
  49. "{Acer,AW35/Pro},"
  50. "{Crystal,3D},"
  51. "{Crystal Computer,TidalWave128},"
  52. "{Dell,Optiplex GX1},"
  53. "{Dell,Workstation 400 sound},"
  54. "{EliteGroup,P5TX-LA sound},"
  55. "{Gallant,SC-70P},"
  56. "{Gateway,E1000 Onboard CS4236B},"
  57. "{Genius,Sound Maker 3DJ},"
  58. "{Hewlett Packard,HP6330 sound},"
  59. "{IBM,PC 300PL sound},"
  60. "{IBM,Aptiva 2137 E24},"
  61. "{IBM,IntelliStation M Pro},"
  62. "{Intel,Marlin Spike Mobo CS4235},"
  63. "{Intel PR440FX Onboard},"
  64. "{Guillemot,MaxiSound 16 PnP},"
  65. "{NewClear,3D},"
  66. "{TerraTec,AudioSystem EWS64L/XL},"
  67. "{Typhoon Soundsystem,CS4236B},"
  68. "{Turtle Beach,Malibu},"
  69. "{Unknown,Digital PC 5000 Onboard}}");
  70. #endif
  71. #ifdef CS4232
  72. #define IDENT "CS4232"
  73. #else
  74. #define IDENT "CS4236+"
  75. #endif
  76. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  77. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  78. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  79. #ifdef CONFIG_PNP
  80. static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  81. #endif
  82. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  83. static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  84. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
  85. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  86. static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  87. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  88. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
  89. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  90. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  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_array(port, long, NULL, 0444);
  102. MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
  103. module_param_array(cport, long, NULL, 0444);
  104. MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
  105. module_param_array(mpu_port, long, NULL, 0444);
  106. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
  107. module_param_array(fm_port, long, NULL, 0444);
  108. MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
  109. module_param_array(sb_port, long, NULL, 0444);
  110. MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
  111. module_param_array(irq, int, NULL, 0444);
  112. MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
  113. module_param_array(mpu_irq, int, NULL, 0444);
  114. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
  115. module_param_array(dma1, int, NULL, 0444);
  116. MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
  117. module_param_array(dma2, int, NULL, 0444);
  118. MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
  119. struct snd_card_cs4236 {
  120. struct resource *res_sb_port;
  121. #ifdef CONFIG_PNP
  122. struct pnp_dev *wss;
  123. struct pnp_dev *ctrl;
  124. struct pnp_dev *mpu;
  125. #endif
  126. };
  127. static snd_card_t *snd_cs4236_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  128. #ifdef CONFIG_PNP
  129. #define ISAPNP_CS4232(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
  130. { \
  131. ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
  132. .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
  133. ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
  134. ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401) } \
  135. }
  136. #define ISAPNP_CS4232_1(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
  137. { \
  138. ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
  139. .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
  140. ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
  141. ISAPNP_DEVICE_ID('P', 'N', 'P', _mpu401) } \
  142. }
  143. #define ISAPNP_CS4232_WOMPU(_va, _vb, _vc, _device, _wss, _ctrl) \
  144. { \
  145. ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
  146. .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
  147. ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl) } \
  148. }
  149. #ifdef CS4232
  150. static struct pnp_card_device_id snd_cs423x_pnpids[] = {
  151. /* Philips PCA70PS */
  152. { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  153. /* TerraTec Maestro 32/96 (CS4232) */
  154. { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  155. /* HP Omnibook 5500 onboard */
  156. { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
  157. /* Unnamed CS4236 card (Made in Taiwan) */
  158. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  159. /* Turtle Beach TBS-2000 (CS4232) */
  160. { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
  161. /* Turtle Beach Tropez Plus (CS4232) */
  162. { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  163. /* SIC CrystalWave 32 (CS4232) */
  164. { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  165. /* --- */
  166. { .id = "" } /* end */
  167. };
  168. #else /* CS4236 */
  169. static struct pnp_card_device_id snd_cs423x_pnpids[] = {
  170. /* Intel Marlin Spike Motherboard - CS4235 */
  171. { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  172. /* Intel Marlin Spike Motherboard (#2) - CS4235 */
  173. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  174. /* Unknown Intel mainboard - CS4235 */
  175. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
  176. /* Genius Sound Maker 3DJ - CS4237B */
  177. { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  178. /* Digital PC 5000 Onboard - CS4236B */
  179. { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
  180. /* some uknown CS4236B */
  181. { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  182. /* Intel PR440FX Onboard sound */
  183. { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  184. /* CS4235 on mainboard without MPU */
  185. { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
  186. /* Gateway E1000 Onboard CS4236B */
  187. { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  188. /* HP 6330 Onboard sound */
  189. { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  190. /* Crystal Computer TidalWave128 */
  191. { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  192. /* ACER AW37 - CS4235 */
  193. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  194. /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
  195. { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  196. /* Crystal 3D - CS4237B */
  197. { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  198. /* Typhoon Soundsystem PnP - CS4236B */
  199. { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  200. /* Crystal CX4235-XQ3 EP - CS4235 */
  201. { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  202. /* Crystal Semiconductors CS4237B */
  203. { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  204. /* NewClear 3D - CX4237B-XQ3 */
  205. { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  206. /* Dell Optiplex GX1 - CS4236B */
  207. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  208. /* Dell P410 motherboard - CS4236B */
  209. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  210. /* Dell Workstation 400 Onboard - CS4236B */
  211. { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  212. /* Turtle Beach Malibu - CS4237B */
  213. { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  214. /* CS4235 - onboard */
  215. { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  216. /* IBM Aptiva 2137 E24 Onboard - CS4237B */
  217. { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  218. /* IBM IntelliStation M Pro motherboard */
  219. { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  220. /* Guillemot MaxiSound 16 PnP - CS4236B */
  221. { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  222. /* Gallant SC-70P */
  223. { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  224. /* TerraTec AudioSystem EWS64XL - CS4236B */
  225. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
  226. /* TerraTec AudioSystem EWS64XL - CS4236B */
  227. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
  228. /* ACER AW37/Pro - CS4235 */
  229. { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  230. /* ACER AW35/Pro - CS4237B */
  231. { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  232. /* CS4235 without MPU401 */
  233. { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  234. /* Unknown SiS530 - CS4235 */
  235. { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  236. /* IBM IntelliStation M Pro 6898 11U - CS4236B */
  237. { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  238. /* IBM PC 300PL Onboard - CS4236B */
  239. { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
  240. /* Some noname CS4236 based card */
  241. { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  242. /* CS4236B */
  243. { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  244. /* CS4236B */
  245. { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  246. /* --- */
  247. { .id = "" } /* end */
  248. };
  249. #endif
  250. MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
  251. static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard,
  252. struct pnp_card_link *card,
  253. const struct pnp_card_device_id *id)
  254. {
  255. struct pnp_dev *pdev;
  256. struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
  257. int err;
  258. if (!cfg)
  259. return -ENOMEM;
  260. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  261. if (acard->wss == NULL) {
  262. kfree(cfg);
  263. return -EBUSY;
  264. }
  265. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  266. if (acard->ctrl == NULL) {
  267. kfree(cfg);
  268. return -EBUSY;
  269. }
  270. if (id->devs[2].id[0]) {
  271. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  272. if (acard->mpu == NULL) {
  273. kfree(cfg);
  274. return -EBUSY;
  275. }
  276. }
  277. /* WSS initialization */
  278. pdev = acard->wss;
  279. pnp_init_resource_table(cfg);
  280. if (port[dev] != SNDRV_AUTO_PORT)
  281. pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
  282. if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
  283. pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
  284. if (sb_port[dev] != SNDRV_AUTO_PORT)
  285. pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
  286. if (irq[dev] != SNDRV_AUTO_IRQ)
  287. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  288. if (dma1[dev] != SNDRV_AUTO_DMA)
  289. pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
  290. if (dma2[dev] != SNDRV_AUTO_DMA)
  291. pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
  292. err = pnp_manual_config_dev(pdev, cfg, 0);
  293. if (err < 0)
  294. snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
  295. err = pnp_activate_dev(pdev);
  296. if (err < 0) {
  297. kfree(cfg);
  298. printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
  299. return -EBUSY;
  300. }
  301. port[dev] = pnp_port_start(pdev, 0);
  302. if (fm_port[dev] > 0)
  303. fm_port[dev] = pnp_port_start(pdev, 1);
  304. sb_port[dev] = pnp_port_start(pdev, 2);
  305. irq[dev] = pnp_irq(pdev, 0);
  306. dma1[dev] = pnp_dma(pdev, 0);
  307. dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
  308. snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
  309. port[dev], fm_port[dev], sb_port[dev]);
  310. snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
  311. irq[dev], dma1[dev], dma2[dev]);
  312. /* CTRL initialization */
  313. if (acard->ctrl && cport[dev] > 0) {
  314. pdev = acard->ctrl;
  315. pnp_init_resource_table(cfg);
  316. if (cport[dev] != SNDRV_AUTO_PORT)
  317. pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
  318. err = pnp_manual_config_dev(pdev, cfg, 0);
  319. if (err < 0)
  320. snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
  321. err = pnp_activate_dev(pdev);
  322. if (err < 0) {
  323. kfree(cfg);
  324. printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
  325. return -EBUSY;
  326. }
  327. cport[dev] = pnp_port_start(pdev, 0);
  328. snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
  329. }
  330. /* MPU initialization */
  331. if (acard->mpu && mpu_port[dev] > 0) {
  332. pdev = acard->mpu;
  333. pnp_init_resource_table(cfg);
  334. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  335. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  336. if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
  337. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  338. err = pnp_manual_config_dev(pdev, cfg, 0);
  339. if (err < 0)
  340. snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
  341. err = pnp_activate_dev(pdev);
  342. if (err < 0) {
  343. printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
  344. mpu_port[dev] = SNDRV_AUTO_PORT;
  345. mpu_irq[dev] = SNDRV_AUTO_IRQ;
  346. } else {
  347. mpu_port[dev] = pnp_port_start(pdev, 0);
  348. if (mpu_irq[dev] >= 0 &&
  349. pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
  350. mpu_irq[dev] = pnp_irq(pdev, 0);
  351. } else {
  352. mpu_irq[dev] = -1; /* disable interrupt */
  353. }
  354. }
  355. snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  356. }
  357. kfree(cfg);
  358. return 0;
  359. }
  360. #endif /* CONFIG_PNP */
  361. static void snd_card_cs4236_free(snd_card_t *card)
  362. {
  363. struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data;
  364. if (acard) {
  365. if (acard->res_sb_port) {
  366. release_resource(acard->res_sb_port);
  367. kfree_nocheck(acard->res_sb_port);
  368. }
  369. }
  370. }
  371. static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard,
  372. const struct pnp_card_device_id *pid)
  373. {
  374. snd_card_t *card;
  375. struct snd_card_cs4236 *acard;
  376. snd_pcm_t *pcm = NULL;
  377. cs4231_t *chip;
  378. opl3_t *opl3;
  379. int err;
  380. #ifdef CONFIG_PNP
  381. if (!isapnp[dev]) {
  382. #endif
  383. if (port[dev] == SNDRV_AUTO_PORT) {
  384. snd_printk("specify port\n");
  385. return -EINVAL;
  386. }
  387. if (cport[dev] == SNDRV_AUTO_PORT) {
  388. snd_printk("specify cport\n");
  389. return -EINVAL;
  390. }
  391. #ifdef CONFIG_PNP
  392. }
  393. #endif
  394. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  395. sizeof(struct snd_card_cs4236));
  396. if (card == NULL)
  397. return -ENOMEM;
  398. acard = (struct snd_card_cs4236 *)card->private_data;
  399. card->private_free = snd_card_cs4236_free;
  400. #ifdef CONFIG_PNP
  401. if (isapnp[dev]) {
  402. if ((err = snd_card_cs4236_pnp(dev, acard, pcard, pid))<0) {
  403. printk(KERN_ERR "isapnp detection failed and probing for " IDENT " is not supported\n");
  404. snd_card_free(card);
  405. return -ENXIO;
  406. }
  407. snd_card_set_dev(card, &pcard->card->dev);
  408. }
  409. #endif
  410. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
  411. if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
  412. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  413. snd_card_free(card);
  414. return -ENOMEM;
  415. }
  416. #ifdef CS4232
  417. if ((err = snd_cs4231_create(card,
  418. port[dev],
  419. cport[dev],
  420. irq[dev],
  421. dma1[dev],
  422. dma2[dev],
  423. CS4231_HW_DETECT,
  424. 0,
  425. &chip)) < 0) {
  426. snd_card_free(card);
  427. return err;
  428. }
  429. if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
  430. snd_card_free(card);
  431. return err;
  432. }
  433. if ((err = snd_cs4231_mixer(chip)) < 0) {
  434. snd_card_free(card);
  435. return err;
  436. }
  437. #else /* CS4236 */
  438. if ((err = snd_cs4236_create(card,
  439. port[dev],
  440. cport[dev],
  441. irq[dev],
  442. dma1[dev],
  443. dma2[dev],
  444. CS4231_HW_DETECT,
  445. 0,
  446. &chip)) < 0) {
  447. snd_card_free(card);
  448. return err;
  449. }
  450. if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) {
  451. snd_card_free(card);
  452. return err;
  453. }
  454. if ((err = snd_cs4236_mixer(chip)) < 0) {
  455. snd_card_free(card);
  456. return err;
  457. }
  458. #endif
  459. strcpy(card->driver, pcm->name);
  460. strcpy(card->shortname, pcm->name);
  461. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
  462. pcm->name,
  463. chip->port,
  464. irq[dev],
  465. dma1[dev]);
  466. if (dma2[dev] >= 0)
  467. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  468. if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
  469. snd_card_free(card);
  470. return err;
  471. }
  472. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  473. if (snd_opl3_create(card,
  474. fm_port[dev], fm_port[dev] + 2,
  475. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  476. printk(KERN_ERR IDENT ": OPL3 not detected\n");
  477. } else {
  478. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  479. snd_card_free(card);
  480. return err;
  481. }
  482. }
  483. }
  484. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  485. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  486. mpu_irq[dev] = -1;
  487. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  488. mpu_port[dev], 0,
  489. mpu_irq[dev],
  490. mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
  491. printk(KERN_ERR IDENT ": MPU401 not detected\n");
  492. }
  493. if ((err = snd_card_register(card)) < 0) {
  494. snd_card_free(card);
  495. return err;
  496. }
  497. if (pcard)
  498. pnp_set_card_drvdata(pcard, card);
  499. else
  500. snd_cs4236_legacy[dev] = card;
  501. return 0;
  502. }
  503. #ifdef CONFIG_PNP
  504. static int __devinit snd_cs423x_pnp_detect(struct pnp_card_link *card,
  505. const struct pnp_card_device_id *id)
  506. {
  507. static int dev;
  508. int res;
  509. for ( ; dev < SNDRV_CARDS; dev++) {
  510. if (!enable[dev] || !isapnp[dev])
  511. continue;
  512. res = snd_card_cs423x_probe(dev, card, id);
  513. if (res < 0)
  514. return res;
  515. dev++;
  516. return 0;
  517. }
  518. return -ENODEV;
  519. }
  520. static void __devexit snd_cs423x_pnp_remove(struct pnp_card_link * pcard)
  521. {
  522. snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
  523. snd_card_disconnect(card);
  524. snd_card_free_in_thread(card);
  525. }
  526. static struct pnp_card_driver cs423x_pnpc_driver = {
  527. .flags = PNP_DRIVER_RES_DISABLE,
  528. .name = "cs423x",
  529. .id_table = snd_cs423x_pnpids,
  530. .probe = snd_cs423x_pnp_detect,
  531. .remove = __devexit_p(snd_cs423x_pnp_remove),
  532. };
  533. #endif /* CONFIG_PNP */
  534. static int __init alsa_card_cs423x_init(void)
  535. {
  536. int dev, cards = 0;
  537. for (dev = 0; dev < SNDRV_CARDS; dev++) {
  538. if (!enable[dev])
  539. continue;
  540. #ifdef CONFIG_PNP
  541. if (isapnp[dev])
  542. continue;
  543. #endif
  544. if (snd_card_cs423x_probe(dev, NULL, NULL) >= 0)
  545. cards++;
  546. }
  547. #ifdef CONFIG_PNP
  548. cards += pnp_register_card_driver(&cs423x_pnpc_driver);
  549. #endif
  550. if (!cards) {
  551. #ifdef CONFIG_PNP
  552. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  553. #endif
  554. #ifdef MODULE
  555. printk(KERN_ERR IDENT " soundcard not found or device busy\n");
  556. #endif
  557. return -ENODEV;
  558. }
  559. return 0;
  560. }
  561. static void __exit alsa_card_cs423x_exit(void)
  562. {
  563. int idx;
  564. #ifdef CONFIG_PNP
  565. /* PnP cards first */
  566. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  567. #endif
  568. for (idx = 0; idx < SNDRV_CARDS; idx++)
  569. snd_card_free(snd_cs4236_legacy[idx]);
  570. }
  571. module_init(alsa_card_cs423x_init)
  572. module_exit(alsa_card_cs423x_exit)