cs4236.c 22 KB

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