cs4236.c 22 KB

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