cs4236.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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_array(port, long, NULL, 0444);
  96. MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
  97. module_param_array(cport, long, NULL, 0444);
  98. MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
  99. module_param_array(mpu_port, long, NULL, 0444);
  100. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
  101. module_param_array(fm_port, long, NULL, 0444);
  102. MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
  103. module_param_array(sb_port, long, NULL, 0444);
  104. MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
  105. module_param_array(irq, int, NULL, 0444);
  106. MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
  107. module_param_array(mpu_irq, int, NULL, 0444);
  108. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
  109. module_param_array(dma1, int, NULL, 0444);
  110. MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
  111. module_param_array(dma2, int, 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 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) && pnp_irq(pdev, 0) >= 0) {
  282. mpu_irq[dev] = pnp_irq(pdev, 0);
  283. } else {
  284. mpu_irq[dev] = -1; /* disable interrupt */
  285. }
  286. }
  287. snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  288. return 0;
  289. }
  290. static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
  291. struct pnp_dev *pdev,
  292. struct pnp_dev *cdev)
  293. {
  294. acard->wss = pdev;
  295. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  296. return -EBUSY;
  297. if (cdev)
  298. cport[dev] = pnp_port_start(cdev, 0);
  299. else
  300. cport[dev] = -1;
  301. return 0;
  302. }
  303. static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
  304. struct pnp_card_link *card,
  305. const struct pnp_card_device_id *id)
  306. {
  307. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  308. if (acard->wss == NULL)
  309. return -EBUSY;
  310. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  311. if (acard->ctrl == NULL)
  312. return -EBUSY;
  313. if (id->devs[2].id[0]) {
  314. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  315. if (acard->mpu == NULL)
  316. return -EBUSY;
  317. }
  318. /* WSS initialization */
  319. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  320. return -EBUSY;
  321. /* CTRL initialization */
  322. if (acard->ctrl && cport[dev] > 0) {
  323. if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
  324. return -EBUSY;
  325. }
  326. /* MPU initialization */
  327. if (acard->mpu && mpu_port[dev] > 0) {
  328. if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
  329. return -EBUSY;
  330. }
  331. return 0;
  332. }
  333. #endif /* CONFIG_PNP */
  334. #ifdef CONFIG_PNP
  335. #define is_isapnp_selected(dev) isapnp[dev]
  336. #else
  337. #define is_isapnp_selected(dev) 0
  338. #endif
  339. static void snd_card_cs4236_free(struct snd_card *card)
  340. {
  341. struct snd_card_cs4236 *acard = card->private_data;
  342. release_and_free_resource(acard->res_sb_port);
  343. }
  344. static int snd_cs423x_card_new(struct device *pdev, int dev,
  345. struct snd_card **cardp)
  346. {
  347. struct snd_card *card;
  348. int err;
  349. err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
  350. sizeof(struct snd_card_cs4236), &card);
  351. if (err < 0)
  352. return err;
  353. card->private_free = snd_card_cs4236_free;
  354. *cardp = card;
  355. return 0;
  356. }
  357. static int snd_cs423x_probe(struct snd_card *card, int dev)
  358. {
  359. struct snd_card_cs4236 *acard;
  360. struct snd_wss *chip;
  361. struct snd_opl3 *opl3;
  362. int err;
  363. acard = card->private_data;
  364. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
  365. if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
  366. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  367. return -EBUSY;
  368. }
  369. err = snd_cs4236_create(card, port[dev], cport[dev],
  370. irq[dev],
  371. dma1[dev], dma2[dev],
  372. WSS_HW_DETECT3, 0, &chip);
  373. if (err < 0)
  374. return err;
  375. acard->chip = chip;
  376. if (chip->hardware & WSS_HW_CS4236B_MASK) {
  377. err = snd_cs4236_pcm(chip, 0);
  378. if (err < 0)
  379. return err;
  380. err = snd_cs4236_mixer(chip);
  381. if (err < 0)
  382. return err;
  383. } else {
  384. err = snd_wss_pcm(chip, 0);
  385. if (err < 0)
  386. return err;
  387. err = snd_wss_mixer(chip);
  388. if (err < 0)
  389. return err;
  390. }
  391. strcpy(card->driver, chip->pcm->name);
  392. strcpy(card->shortname, chip->pcm->name);
  393. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
  394. chip->pcm->name,
  395. chip->port,
  396. irq[dev],
  397. dma1[dev]);
  398. if (dma2[dev] >= 0)
  399. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  400. err = snd_wss_timer(chip, 0);
  401. if (err < 0)
  402. return err;
  403. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  404. if (snd_opl3_create(card,
  405. fm_port[dev], fm_port[dev] + 2,
  406. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  407. printk(KERN_WARNING IDENT ": OPL3 not detected\n");
  408. } else {
  409. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  410. return err;
  411. }
  412. }
  413. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  414. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  415. mpu_irq[dev] = -1;
  416. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  417. mpu_port[dev], 0,
  418. mpu_irq[dev], NULL) < 0)
  419. printk(KERN_WARNING IDENT ": MPU401 not detected\n");
  420. }
  421. return snd_card_register(card);
  422. }
  423. static int snd_cs423x_isa_match(struct device *pdev,
  424. unsigned int dev)
  425. {
  426. if (!enable[dev] || is_isapnp_selected(dev))
  427. return 0;
  428. if (port[dev] == SNDRV_AUTO_PORT) {
  429. dev_err(pdev, "please specify port\n");
  430. return 0;
  431. }
  432. if (cport[dev] == SNDRV_AUTO_PORT) {
  433. dev_err(pdev, "please specify cport\n");
  434. return 0;
  435. }
  436. if (irq[dev] == SNDRV_AUTO_IRQ) {
  437. dev_err(pdev, "please specify irq\n");
  438. return 0;
  439. }
  440. if (dma1[dev] == SNDRV_AUTO_DMA) {
  441. dev_err(pdev, "please specify dma1\n");
  442. return 0;
  443. }
  444. return 1;
  445. }
  446. static int snd_cs423x_isa_probe(struct device *pdev,
  447. unsigned int dev)
  448. {
  449. struct snd_card *card;
  450. int err;
  451. err = snd_cs423x_card_new(pdev, dev, &card);
  452. if (err < 0)
  453. return err;
  454. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  455. snd_card_free(card);
  456. return err;
  457. }
  458. dev_set_drvdata(pdev, card);
  459. return 0;
  460. }
  461. static int snd_cs423x_isa_remove(struct device *pdev,
  462. unsigned int dev)
  463. {
  464. snd_card_free(dev_get_drvdata(pdev));
  465. return 0;
  466. }
  467. #ifdef CONFIG_PM
  468. static int snd_cs423x_suspend(struct snd_card *card)
  469. {
  470. struct snd_card_cs4236 *acard = card->private_data;
  471. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  472. acard->chip->suspend(acard->chip);
  473. return 0;
  474. }
  475. static int snd_cs423x_resume(struct snd_card *card)
  476. {
  477. struct snd_card_cs4236 *acard = card->private_data;
  478. acard->chip->resume(acard->chip);
  479. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  480. return 0;
  481. }
  482. static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
  483. pm_message_t state)
  484. {
  485. return snd_cs423x_suspend(dev_get_drvdata(dev));
  486. }
  487. static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
  488. {
  489. return snd_cs423x_resume(dev_get_drvdata(dev));
  490. }
  491. #endif
  492. static struct isa_driver cs423x_isa_driver = {
  493. .match = snd_cs423x_isa_match,
  494. .probe = snd_cs423x_isa_probe,
  495. .remove = snd_cs423x_isa_remove,
  496. #ifdef CONFIG_PM
  497. .suspend = snd_cs423x_isa_suspend,
  498. .resume = snd_cs423x_isa_resume,
  499. #endif
  500. .driver = {
  501. .name = DEV_NAME
  502. },
  503. };
  504. #ifdef CONFIG_PNP
  505. static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
  506. const struct pnp_device_id *id)
  507. {
  508. static int dev;
  509. int err;
  510. struct snd_card *card;
  511. struct pnp_dev *cdev;
  512. char cid[PNP_ID_LEN];
  513. if (pnp_device_is_isapnp(pdev))
  514. return -ENOENT; /* we have another procedure - card */
  515. for (; dev < SNDRV_CARDS; dev++) {
  516. if (enable[dev] && isapnp[dev])
  517. break;
  518. }
  519. if (dev >= SNDRV_CARDS)
  520. return -ENODEV;
  521. /* prepare second id */
  522. strcpy(cid, pdev->id[0].id);
  523. cid[5] = '1';
  524. cdev = NULL;
  525. list_for_each_entry(cdev, &(pdev->protocol->devices), protocol_list) {
  526. if (!strcmp(cdev->id[0].id, cid))
  527. break;
  528. }
  529. err = snd_cs423x_card_new(&pdev->dev, dev, &card);
  530. if (err < 0)
  531. return err;
  532. err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
  533. if (err < 0) {
  534. printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
  535. snd_card_free(card);
  536. return err;
  537. }
  538. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  539. snd_card_free(card);
  540. return err;
  541. }
  542. pnp_set_drvdata(pdev, card);
  543. dev++;
  544. return 0;
  545. }
  546. static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
  547. {
  548. snd_card_free(pnp_get_drvdata(pdev));
  549. }
  550. #ifdef CONFIG_PM
  551. static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  552. {
  553. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  554. }
  555. static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
  556. {
  557. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  558. }
  559. #endif
  560. static struct pnp_driver cs423x_pnp_driver = {
  561. .name = "cs423x-pnpbios",
  562. .id_table = snd_cs423x_pnpbiosids,
  563. .probe = snd_cs423x_pnpbios_detect,
  564. .remove = snd_cs423x_pnp_remove,
  565. #ifdef CONFIG_PM
  566. .suspend = snd_cs423x_pnp_suspend,
  567. .resume = snd_cs423x_pnp_resume,
  568. #endif
  569. };
  570. static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  571. const struct pnp_card_device_id *pid)
  572. {
  573. static int dev;
  574. struct snd_card *card;
  575. int res;
  576. for ( ; dev < SNDRV_CARDS; dev++) {
  577. if (enable[dev] && isapnp[dev])
  578. break;
  579. }
  580. if (dev >= SNDRV_CARDS)
  581. return -ENODEV;
  582. res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
  583. if (res < 0)
  584. return res;
  585. if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
  586. printk(KERN_ERR "isapnp detection failed and probing for " IDENT
  587. " is not supported\n");
  588. snd_card_free(card);
  589. return res;
  590. }
  591. if ((res = snd_cs423x_probe(card, dev)) < 0) {
  592. snd_card_free(card);
  593. return res;
  594. }
  595. pnp_set_card_drvdata(pcard, card);
  596. dev++;
  597. return 0;
  598. }
  599. static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
  600. {
  601. snd_card_free(pnp_get_card_drvdata(pcard));
  602. pnp_set_card_drvdata(pcard, NULL);
  603. }
  604. #ifdef CONFIG_PM
  605. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  606. {
  607. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  608. }
  609. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  610. {
  611. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  612. }
  613. #endif
  614. static struct pnp_card_driver cs423x_pnpc_driver = {
  615. .flags = PNP_DRIVER_RES_DISABLE,
  616. .name = CS423X_ISAPNP_DRIVER,
  617. .id_table = snd_cs423x_pnpids,
  618. .probe = snd_cs423x_pnpc_detect,
  619. .remove = snd_cs423x_pnpc_remove,
  620. #ifdef CONFIG_PM
  621. .suspend = snd_cs423x_pnpc_suspend,
  622. .resume = snd_cs423x_pnpc_resume,
  623. #endif
  624. };
  625. #endif /* CONFIG_PNP */
  626. static int __init alsa_card_cs423x_init(void)
  627. {
  628. int err;
  629. err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
  630. #ifdef CONFIG_PNP
  631. if (!err)
  632. isa_registered = 1;
  633. err = pnp_register_driver(&cs423x_pnp_driver);
  634. if (!err)
  635. pnp_registered = 1;
  636. err = pnp_register_card_driver(&cs423x_pnpc_driver);
  637. if (!err)
  638. pnpc_registered = 1;
  639. if (pnp_registered)
  640. err = 0;
  641. if (isa_registered)
  642. err = 0;
  643. #endif
  644. return err;
  645. }
  646. static void __exit alsa_card_cs423x_exit(void)
  647. {
  648. #ifdef CONFIG_PNP
  649. if (pnpc_registered)
  650. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  651. if (pnp_registered)
  652. pnp_unregister_driver(&cs423x_pnp_driver);
  653. if (isa_registered)
  654. #endif
  655. isa_unregister_driver(&cs423x_isa_driver);
  656. }
  657. module_init(alsa_card_cs423x_init)
  658. module_exit(alsa_card_cs423x_exit)