cs4236.c 22 KB

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