cs4236.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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 struct snd_card *snd_cs423x_card_new(int dev)
  364. {
  365. struct snd_card *card;
  366. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  367. sizeof(struct snd_card_cs4236));
  368. if (card == NULL)
  369. return NULL;
  370. card->private_free = snd_card_cs4236_free;
  371. return card;
  372. }
  373. static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
  374. {
  375. struct snd_card_cs4236 *acard;
  376. struct snd_pcm *pcm;
  377. struct snd_wss *chip;
  378. struct snd_opl3 *opl3;
  379. int err;
  380. acard = card->private_data;
  381. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
  382. if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
  383. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  384. return -EBUSY;
  385. }
  386. #ifdef CS4232
  387. err = snd_wss_create(card, port[dev], cport[dev],
  388. irq[dev],
  389. dma1[dev], dma2[dev],
  390. WSS_HW_DETECT, 0, &chip);
  391. if (err < 0)
  392. return err;
  393. acard->chip = chip;
  394. err = snd_wss_pcm(chip, 0, &pcm);
  395. if (err < 0)
  396. return err;
  397. err = snd_wss_mixer(chip);
  398. if (err < 0)
  399. return err;
  400. #else /* CS4236 */
  401. err = snd_cs4236_create(card,
  402. port[dev], cport[dev],
  403. irq[dev], dma1[dev], dma2[dev],
  404. WSS_HW_DETECT, 0, &chip);
  405. if (err < 0)
  406. return err;
  407. acard->chip = chip;
  408. err = snd_cs4236_pcm(chip, 0, &pcm);
  409. if (err < 0)
  410. return err;
  411. err = snd_cs4236_mixer(chip);
  412. if (err < 0)
  413. return err;
  414. #endif
  415. strcpy(card->driver, pcm->name);
  416. strcpy(card->shortname, pcm->name);
  417. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
  418. pcm->name,
  419. chip->port,
  420. irq[dev],
  421. dma1[dev]);
  422. if (dma2[dev] >= 0)
  423. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  424. err = snd_wss_timer(chip, 0, NULL);
  425. if (err < 0)
  426. return err;
  427. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  428. if (snd_opl3_create(card,
  429. fm_port[dev], fm_port[dev] + 2,
  430. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  431. printk(KERN_WARNING IDENT ": OPL3 not detected\n");
  432. } else {
  433. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  434. return err;
  435. }
  436. }
  437. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  438. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  439. mpu_irq[dev] = -1;
  440. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  441. mpu_port[dev], 0,
  442. mpu_irq[dev],
  443. mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
  444. printk(KERN_WARNING IDENT ": MPU401 not detected\n");
  445. }
  446. return snd_card_register(card);
  447. }
  448. static int __devinit snd_cs423x_isa_match(struct device *pdev,
  449. unsigned int dev)
  450. {
  451. if (!enable[dev] || is_isapnp_selected(dev))
  452. return 0;
  453. if (port[dev] == SNDRV_AUTO_PORT) {
  454. snd_printk(KERN_ERR "%s: please specify port\n", pdev->bus_id);
  455. return 0;
  456. }
  457. if (cport[dev] == SNDRV_AUTO_PORT) {
  458. snd_printk(KERN_ERR "%s: please specify cport\n", pdev->bus_id);
  459. return 0;
  460. }
  461. if (irq[dev] == SNDRV_AUTO_IRQ) {
  462. snd_printk(KERN_ERR "%s: please specify irq\n", pdev->bus_id);
  463. return 0;
  464. }
  465. if (dma1[dev] == SNDRV_AUTO_DMA) {
  466. snd_printk(KERN_ERR "%s: please specify dma1\n", pdev->bus_id);
  467. return 0;
  468. }
  469. return 1;
  470. }
  471. static int __devinit snd_cs423x_isa_probe(struct device *pdev,
  472. unsigned int dev)
  473. {
  474. struct snd_card *card;
  475. int err;
  476. card = snd_cs423x_card_new(dev);
  477. if (! card)
  478. return -ENOMEM;
  479. snd_card_set_dev(card, pdev);
  480. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  481. snd_card_free(card);
  482. return err;
  483. }
  484. dev_set_drvdata(pdev, card);
  485. return 0;
  486. }
  487. static int __devexit snd_cs423x_isa_remove(struct device *pdev,
  488. unsigned int dev)
  489. {
  490. snd_card_free(dev_get_drvdata(pdev));
  491. dev_set_drvdata(pdev, NULL);
  492. return 0;
  493. }
  494. #ifdef CONFIG_PM
  495. static int snd_cs423x_suspend(struct snd_card *card)
  496. {
  497. struct snd_card_cs4236 *acard = card->private_data;
  498. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  499. acard->chip->suspend(acard->chip);
  500. return 0;
  501. }
  502. static int snd_cs423x_resume(struct snd_card *card)
  503. {
  504. struct snd_card_cs4236 *acard = card->private_data;
  505. acard->chip->resume(acard->chip);
  506. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  507. return 0;
  508. }
  509. static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
  510. pm_message_t state)
  511. {
  512. return snd_cs423x_suspend(dev_get_drvdata(dev));
  513. }
  514. static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
  515. {
  516. return snd_cs423x_resume(dev_get_drvdata(dev));
  517. }
  518. #endif
  519. static struct isa_driver cs423x_isa_driver = {
  520. .match = snd_cs423x_isa_match,
  521. .probe = snd_cs423x_isa_probe,
  522. .remove = __devexit_p(snd_cs423x_isa_remove),
  523. #ifdef CONFIG_PM
  524. .suspend = snd_cs423x_isa_suspend,
  525. .resume = snd_cs423x_isa_resume,
  526. #endif
  527. .driver = {
  528. .name = DEV_NAME
  529. },
  530. };
  531. #ifdef CONFIG_PNP
  532. #ifdef CS4232
  533. static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
  534. const struct pnp_device_id *id)
  535. {
  536. static int dev;
  537. int err;
  538. struct snd_card *card;
  539. if (pnp_device_is_isapnp(pdev))
  540. return -ENOENT; /* we have another procedure - card */
  541. for (; dev < SNDRV_CARDS; dev++) {
  542. if (enable[dev] && isapnp[dev])
  543. break;
  544. }
  545. if (dev >= SNDRV_CARDS)
  546. return -ENODEV;
  547. card = snd_cs423x_card_new(dev);
  548. if (! card)
  549. return -ENOMEM;
  550. if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
  551. printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
  552. snd_card_free(card);
  553. return err;
  554. }
  555. snd_card_set_dev(card, &pdev->dev);
  556. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  557. snd_card_free(card);
  558. return err;
  559. }
  560. pnp_set_drvdata(pdev, card);
  561. dev++;
  562. return 0;
  563. }
  564. static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
  565. {
  566. snd_card_free(pnp_get_drvdata(pdev));
  567. pnp_set_drvdata(pdev, NULL);
  568. }
  569. #ifdef CONFIG_PM
  570. static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  571. {
  572. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  573. }
  574. static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
  575. {
  576. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  577. }
  578. #endif
  579. static struct pnp_driver cs4232_pnp_driver = {
  580. .name = "cs4232-pnpbios",
  581. .id_table = snd_cs4232_pnpbiosids,
  582. .probe = snd_cs4232_pnpbios_detect,
  583. .remove = __devexit_p(snd_cs4232_pnp_remove),
  584. #ifdef CONFIG_PM
  585. .suspend = snd_cs4232_pnp_suspend,
  586. .resume = snd_cs4232_pnp_resume,
  587. #endif
  588. };
  589. #endif /* CS4232 */
  590. static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  591. const struct pnp_card_device_id *pid)
  592. {
  593. static int dev;
  594. struct snd_card *card;
  595. int res;
  596. for ( ; dev < SNDRV_CARDS; dev++) {
  597. if (enable[dev] && isapnp[dev])
  598. break;
  599. }
  600. if (dev >= SNDRV_CARDS)
  601. return -ENODEV;
  602. card = snd_cs423x_card_new(dev);
  603. if (! card)
  604. return -ENOMEM;
  605. if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
  606. printk(KERN_ERR "isapnp detection failed and probing for " IDENT
  607. " is not supported\n");
  608. snd_card_free(card);
  609. return res;
  610. }
  611. snd_card_set_dev(card, &pcard->card->dev);
  612. if ((res = snd_cs423x_probe(card, dev)) < 0) {
  613. snd_card_free(card);
  614. return res;
  615. }
  616. pnp_set_card_drvdata(pcard, card);
  617. dev++;
  618. return 0;
  619. }
  620. static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
  621. {
  622. snd_card_free(pnp_get_card_drvdata(pcard));
  623. pnp_set_card_drvdata(pcard, NULL);
  624. }
  625. #ifdef CONFIG_PM
  626. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  627. {
  628. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  629. }
  630. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  631. {
  632. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  633. }
  634. #endif
  635. static struct pnp_card_driver cs423x_pnpc_driver = {
  636. .flags = PNP_DRIVER_RES_DISABLE,
  637. .name = CS423X_ISAPNP_DRIVER,
  638. .id_table = snd_cs423x_pnpids,
  639. .probe = snd_cs423x_pnpc_detect,
  640. .remove = __devexit_p(snd_cs423x_pnpc_remove),
  641. #ifdef CONFIG_PM
  642. .suspend = snd_cs423x_pnpc_suspend,
  643. .resume = snd_cs423x_pnpc_resume,
  644. #endif
  645. };
  646. #endif /* CONFIG_PNP */
  647. static int __init alsa_card_cs423x_init(void)
  648. {
  649. int err;
  650. err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
  651. #ifdef CONFIG_PNP
  652. if (!err)
  653. isa_registered = 1;
  654. #ifdef CS4232
  655. err = pnp_register_driver(&cs4232_pnp_driver);
  656. if (!err)
  657. pnp_registered = 1;
  658. #endif
  659. err = pnp_register_card_driver(&cs423x_pnpc_driver);
  660. if (!err)
  661. pnpc_registered = 1;
  662. #ifdef CS4232
  663. if (pnp_registered)
  664. err = 0;
  665. #endif
  666. if (isa_registered)
  667. err = 0;
  668. #endif
  669. return err;
  670. }
  671. static void __exit alsa_card_cs423x_exit(void)
  672. {
  673. #ifdef CONFIG_PNP
  674. if (pnpc_registered)
  675. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  676. #ifdef CS4232
  677. if (pnp_registered)
  678. pnp_unregister_driver(&cs4232_pnp_driver);
  679. #endif
  680. if (isa_registered)
  681. #endif
  682. isa_unregister_driver(&cs423x_isa_driver);
  683. }
  684. module_init(alsa_card_cs423x_init)
  685. module_exit(alsa_card_cs423x_exit)