cs4236.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. * Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/err.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/pnp.h>
  27. #include <linux/moduleparam.h>
  28. #include <sound/core.h>
  29. #include <sound/cs4231.h>
  30. #include <sound/mpu401.h>
  31. #include <sound/opl3.h>
  32. #include <sound/initval.h>
  33. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  34. MODULE_LICENSE("GPL");
  35. #ifdef CS4232
  36. MODULE_DESCRIPTION("Cirrus Logic CS4232");
  37. MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
  38. "{Turtle Beach,Tropez Plus},"
  39. "{SIC CrystalWave 32},"
  40. "{Hewlett Packard,Omnibook 5500},"
  41. "{TerraTec,Maestro 32/96},"
  42. "{Philips,PCA70PS}}");
  43. #else
  44. MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
  45. MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
  46. "{Crystal Semiconductors,CS4236},"
  47. "{Crystal Semiconductors,CS4237},"
  48. "{Crystal Semiconductors,CS4238},"
  49. "{Crystal Semiconductors,CS4239},"
  50. "{Acer,AW37},"
  51. "{Acer,AW35/Pro},"
  52. "{Crystal,3D},"
  53. "{Crystal Computer,TidalWave128},"
  54. "{Dell,Optiplex GX1},"
  55. "{Dell,Workstation 400 sound},"
  56. "{EliteGroup,P5TX-LA sound},"
  57. "{Gallant,SC-70P},"
  58. "{Gateway,E1000 Onboard CS4236B},"
  59. "{Genius,Sound Maker 3DJ},"
  60. "{Hewlett Packard,HP6330 sound},"
  61. "{IBM,PC 300PL sound},"
  62. "{IBM,Aptiva 2137 E24},"
  63. "{IBM,IntelliStation M Pro},"
  64. "{Intel,Marlin Spike Mobo CS4235},"
  65. "{Intel PR440FX Onboard},"
  66. "{Guillemot,MaxiSound 16 PnP},"
  67. "{NewClear,3D},"
  68. "{TerraTec,AudioSystem EWS64L/XL},"
  69. "{Typhoon Soundsystem,CS4236B},"
  70. "{Turtle Beach,Malibu},"
  71. "{Unknown,Digital PC 5000 Onboard}}");
  72. #endif
  73. #ifdef CS4232
  74. #define IDENT "CS4232"
  75. #else
  76. #define IDENT "CS4236+"
  77. #endif
  78. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  79. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  80. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  81. #ifdef CONFIG_PNP
  82. static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  83. #endif
  84. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  85. static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  86. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
  87. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  88. static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  89. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  90. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
  91. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  92. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  93. module_param_array(index, int, NULL, 0444);
  94. MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
  95. module_param_array(id, charp, NULL, 0444);
  96. MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
  97. module_param_array(enable, bool, NULL, 0444);
  98. MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
  99. #ifdef CONFIG_PNP
  100. module_param_array(isapnp, bool, NULL, 0444);
  101. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  102. #endif
  103. module_param_array(port, long, NULL, 0444);
  104. MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
  105. module_param_array(cport, long, NULL, 0444);
  106. MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
  107. module_param_array(mpu_port, long, NULL, 0444);
  108. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
  109. module_param_array(fm_port, long, NULL, 0444);
  110. MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
  111. module_param_array(sb_port, long, NULL, 0444);
  112. MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
  113. module_param_array(irq, int, NULL, 0444);
  114. MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
  115. module_param_array(mpu_irq, int, NULL, 0444);
  116. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
  117. module_param_array(dma1, int, NULL, 0444);
  118. MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
  119. module_param_array(dma2, int, NULL, 0444);
  120. MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
  121. static struct platform_device *platform_devices[SNDRV_CARDS];
  122. #ifdef CONFIG_PNP
  123. static int pnpc_registered;
  124. #ifdef CS4232
  125. static int pnp_registered;
  126. #endif
  127. #endif /* CONFIG_PNP */
  128. struct snd_card_cs4236 {
  129. struct snd_cs4231 *chip;
  130. struct resource *res_sb_port;
  131. #ifdef CONFIG_PNP
  132. struct pnp_dev *wss;
  133. struct pnp_dev *ctrl;
  134. struct pnp_dev *mpu;
  135. #endif
  136. };
  137. #ifdef CONFIG_PNP
  138. #ifdef CS4232
  139. /*
  140. * PNP BIOS
  141. */
  142. static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
  143. { .id = "CSC0100" },
  144. { .id = "CSC0000" },
  145. /* Guillemot Turtlebeach something appears to be cs4232 compatible
  146. * (untested) */
  147. { .id = "GIM0100" },
  148. { .id = "" }
  149. };
  150. MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
  151. #endif /* CS4232 */
  152. #ifdef CS4232
  153. #define CS423X_DRIVER "snd_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. /* --- */
  171. { .id = "" } /* end */
  172. };
  173. #else /* CS4236 */
  174. #define CS423X_DRIVER "snd_cs4236"
  175. #define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
  176. static struct pnp_card_device_id snd_cs423x_pnpids[] = {
  177. /* Intel Marlin Spike Motherboard - CS4235 */
  178. { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  179. /* Intel Marlin Spike Motherboard (#2) - CS4235 */
  180. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  181. /* Unknown Intel mainboard - CS4235 */
  182. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
  183. /* Genius Sound Maker 3DJ - CS4237B */
  184. { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  185. /* Digital PC 5000 Onboard - CS4236B */
  186. { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
  187. /* some uknown CS4236B */
  188. { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  189. /* Intel PR440FX Onboard sound */
  190. { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  191. /* CS4235 on mainboard without MPU */
  192. { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
  193. /* Gateway E1000 Onboard CS4236B */
  194. { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  195. /* HP 6330 Onboard sound */
  196. { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  197. /* Crystal Computer TidalWave128 */
  198. { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  199. /* ACER AW37 - CS4235 */
  200. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  201. /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
  202. { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  203. /* Crystal 3D - CS4237B */
  204. { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  205. /* Typhoon Soundsystem PnP - CS4236B */
  206. { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  207. /* Crystal CX4235-XQ3 EP - CS4235 */
  208. { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  209. /* Crystal Semiconductors CS4237B */
  210. { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  211. /* NewClear 3D - CX4237B-XQ3 */
  212. { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  213. /* Dell Optiplex GX1 - CS4236B */
  214. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  215. /* Dell P410 motherboard - CS4236B */
  216. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  217. /* Dell Workstation 400 Onboard - CS4236B */
  218. { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  219. /* Turtle Beach Malibu - CS4237B */
  220. { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  221. /* CS4235 - onboard */
  222. { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  223. /* IBM Aptiva 2137 E24 Onboard - CS4237B */
  224. { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  225. /* IBM IntelliStation M Pro motherboard */
  226. { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  227. /* Guillemot MaxiSound 16 PnP - CS4236B */
  228. { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  229. /* Gallant SC-70P */
  230. { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  231. /* TerraTec AudioSystem EWS64XL - CS4236B */
  232. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
  233. /* TerraTec AudioSystem EWS64XL - CS4236B */
  234. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
  235. /* ACER AW37/Pro - CS4235 */
  236. { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  237. /* ACER AW35/Pro - CS4237B */
  238. { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  239. /* CS4235 without MPU401 */
  240. { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  241. /* Unknown SiS530 - CS4235 */
  242. { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  243. /* IBM IntelliStation M Pro 6898 11U - CS4236B */
  244. { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  245. /* IBM PC 300PL Onboard - CS4236B */
  246. { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
  247. /* Some noname CS4236 based card */
  248. { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  249. /* CS4236B */
  250. { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  251. /* CS4236B */
  252. { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  253. /* --- */
  254. { .id = "" } /* end */
  255. };
  256. #endif
  257. MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
  258. /* WSS initialization */
  259. static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev,
  260. struct pnp_resource_table *cfg)
  261. {
  262. int err;
  263. pnp_init_resource_table(cfg);
  264. if (port[dev] != SNDRV_AUTO_PORT)
  265. pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
  266. if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
  267. pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
  268. if (sb_port[dev] != SNDRV_AUTO_PORT)
  269. pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
  270. if (irq[dev] != SNDRV_AUTO_IRQ)
  271. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  272. if (dma1[dev] != SNDRV_AUTO_DMA)
  273. pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
  274. if (dma2[dev] != SNDRV_AUTO_DMA)
  275. pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
  276. err = pnp_manual_config_dev(pdev, cfg, 0);
  277. if (err < 0)
  278. snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
  279. err = pnp_activate_dev(pdev);
  280. if (err < 0) {
  281. printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
  282. return -EBUSY;
  283. }
  284. port[dev] = pnp_port_start(pdev, 0);
  285. if (fm_port[dev] > 0)
  286. fm_port[dev] = pnp_port_start(pdev, 1);
  287. sb_port[dev] = pnp_port_start(pdev, 2);
  288. irq[dev] = pnp_irq(pdev, 0);
  289. dma1[dev] = pnp_dma(pdev, 0);
  290. dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
  291. snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
  292. port[dev], fm_port[dev], sb_port[dev]);
  293. snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
  294. irq[dev], dma1[dev], dma2[dev]);
  295. return 0;
  296. }
  297. /* CTRL initialization */
  298. static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev,
  299. struct pnp_resource_table *cfg)
  300. {
  301. int err;
  302. pnp_init_resource_table(cfg);
  303. if (cport[dev] != SNDRV_AUTO_PORT)
  304. pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
  305. err = pnp_manual_config_dev(pdev, cfg, 0);
  306. if (err < 0)
  307. snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
  308. err = pnp_activate_dev(pdev);
  309. if (err < 0) {
  310. printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
  311. return -EBUSY;
  312. }
  313. cport[dev] = pnp_port_start(pdev, 0);
  314. snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
  315. return 0;
  316. }
  317. /* MPU initialization */
  318. static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev,
  319. struct pnp_resource_table *cfg)
  320. {
  321. int err;
  322. pnp_init_resource_table(cfg);
  323. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  324. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  325. if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
  326. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  327. err = pnp_manual_config_dev(pdev, cfg, 0);
  328. if (err < 0)
  329. snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
  330. err = pnp_activate_dev(pdev);
  331. if (err < 0) {
  332. printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
  333. mpu_port[dev] = SNDRV_AUTO_PORT;
  334. mpu_irq[dev] = SNDRV_AUTO_IRQ;
  335. } else {
  336. mpu_port[dev] = pnp_port_start(pdev, 0);
  337. if (mpu_irq[dev] >= 0 &&
  338. pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
  339. mpu_irq[dev] = pnp_irq(pdev, 0);
  340. } else {
  341. mpu_irq[dev] = -1; /* disable interrupt */
  342. }
  343. }
  344. snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  345. return 0;
  346. }
  347. #ifdef CS4232
  348. static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
  349. struct pnp_dev *pdev)
  350. {
  351. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  352. if (!cfg)
  353. return -ENOMEM;
  354. if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) {
  355. kfree(cfg);
  356. return -EBUSY;
  357. }
  358. kfree(cfg);
  359. cport[dev] = -1;
  360. return 0;
  361. }
  362. #endif
  363. static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
  364. struct pnp_card_link *card,
  365. const struct pnp_card_device_id *id)
  366. {
  367. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  368. if (!cfg)
  369. return -ENOMEM;
  370. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  371. if (acard->wss == NULL)
  372. goto error;
  373. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  374. if (acard->ctrl == NULL)
  375. goto error;
  376. if (id->devs[2].id[0]) {
  377. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  378. if (acard->mpu == NULL)
  379. goto error;
  380. }
  381. /* WSS initialization */
  382. if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0)
  383. goto error;
  384. /* CTRL initialization */
  385. if (acard->ctrl && cport[dev] > 0) {
  386. if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0)
  387. goto error;
  388. }
  389. /* MPU initialization */
  390. if (acard->mpu && mpu_port[dev] > 0) {
  391. if (snd_cs423x_pnp_init_mpu(dev, acard->ctrl, cfg) < 0)
  392. goto error;
  393. }
  394. kfree(cfg);
  395. return 0;
  396. error:
  397. kfree(cfg);
  398. return -EBUSY;
  399. }
  400. #endif /* CONFIG_PNP */
  401. #ifdef CONFIG_PNP
  402. #define is_isapnp_selected(dev) isapnp[dev]
  403. #else
  404. #define is_isapnp_selected(dev) 0
  405. #endif
  406. static void snd_card_cs4236_free(struct snd_card *card)
  407. {
  408. struct snd_card_cs4236 *acard = card->private_data;
  409. release_and_free_resource(acard->res_sb_port);
  410. }
  411. static struct snd_card *snd_cs423x_card_new(int dev)
  412. {
  413. struct snd_card *card;
  414. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  415. sizeof(struct snd_card_cs4236));
  416. if (card == NULL)
  417. return NULL;
  418. card->private_free = snd_card_cs4236_free;
  419. return card;
  420. }
  421. static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
  422. {
  423. struct snd_card_cs4236 *acard;
  424. struct snd_pcm *pcm;
  425. struct snd_cs4231 *chip;
  426. struct snd_opl3 *opl3;
  427. int err;
  428. acard = card->private_data;
  429. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
  430. if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
  431. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  432. return -EBUSY;
  433. }
  434. #ifdef CS4232
  435. if ((err = snd_cs4231_create(card,
  436. port[dev],
  437. cport[dev],
  438. irq[dev],
  439. dma1[dev],
  440. dma2[dev],
  441. CS4231_HW_DETECT,
  442. 0,
  443. &chip)) < 0)
  444. return err;
  445. acard->chip = chip;
  446. if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
  447. return err;
  448. if ((err = snd_cs4231_mixer(chip)) < 0)
  449. return err;
  450. #else /* CS4236 */
  451. if ((err = snd_cs4236_create(card,
  452. port[dev],
  453. cport[dev],
  454. irq[dev],
  455. dma1[dev],
  456. dma2[dev],
  457. CS4231_HW_DETECT,
  458. 0,
  459. &chip)) < 0)
  460. return err;
  461. acard->chip = chip;
  462. if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
  463. return err;
  464. if ((err = snd_cs4236_mixer(chip)) < 0)
  465. return err;
  466. #endif
  467. strcpy(card->driver, pcm->name);
  468. strcpy(card->shortname, pcm->name);
  469. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
  470. pcm->name,
  471. chip->port,
  472. irq[dev],
  473. dma1[dev]);
  474. if (dma2[dev] >= 0)
  475. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  476. if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
  477. return err;
  478. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  479. if (snd_opl3_create(card,
  480. fm_port[dev], fm_port[dev] + 2,
  481. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  482. printk(KERN_WARNING IDENT ": OPL3 not detected\n");
  483. } else {
  484. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  485. return err;
  486. }
  487. }
  488. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  489. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  490. mpu_irq[dev] = -1;
  491. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  492. mpu_port[dev], 0,
  493. mpu_irq[dev],
  494. mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
  495. printk(KERN_WARNING IDENT ": MPU401 not detected\n");
  496. }
  497. return snd_card_register(card);
  498. }
  499. static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev)
  500. {
  501. int dev = pdev->id;
  502. struct snd_card *card;
  503. int err;
  504. if (port[dev] == SNDRV_AUTO_PORT) {
  505. snd_printk(KERN_ERR "specify port\n");
  506. return -EINVAL;
  507. }
  508. if (cport[dev] == SNDRV_AUTO_PORT) {
  509. snd_printk(KERN_ERR "specify cport\n");
  510. return -EINVAL;
  511. }
  512. card = snd_cs423x_card_new(dev);
  513. if (! card)
  514. return -ENOMEM;
  515. snd_card_set_dev(card, &pdev->dev);
  516. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  517. snd_card_free(card);
  518. return err;
  519. }
  520. platform_set_drvdata(pdev, card);
  521. return 0;
  522. }
  523. static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr)
  524. {
  525. snd_card_free(platform_get_drvdata(devptr));
  526. platform_set_drvdata(devptr, NULL);
  527. return 0;
  528. }
  529. #ifdef CONFIG_PM
  530. static int snd_cs423x_suspend(struct snd_card *card)
  531. {
  532. struct snd_card_cs4236 *acard = card->private_data;
  533. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  534. acard->chip->suspend(acard->chip);
  535. return 0;
  536. }
  537. static int snd_cs423x_resume(struct snd_card *card)
  538. {
  539. struct snd_card_cs4236 *acard = card->private_data;
  540. acard->chip->resume(acard->chip);
  541. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  542. return 0;
  543. }
  544. static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state)
  545. {
  546. return snd_cs423x_suspend(platform_get_drvdata(dev));
  547. }
  548. static int snd_cs423x_nonpnp_resume(struct platform_device *dev)
  549. {
  550. return snd_cs423x_resume(platform_get_drvdata(dev));
  551. }
  552. #endif
  553. static struct platform_driver cs423x_nonpnp_driver = {
  554. .probe = snd_cs423x_nonpnp_probe,
  555. .remove = __devexit_p(snd_cs423x_nonpnp_remove),
  556. #ifdef CONFIG_PM
  557. .suspend = snd_cs423x_nonpnp_suspend,
  558. .resume = snd_cs423x_nonpnp_resume,
  559. #endif
  560. .driver = {
  561. .name = CS423X_DRIVER
  562. },
  563. };
  564. #ifdef CONFIG_PNP
  565. #ifdef CS4232
  566. static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
  567. const struct pnp_device_id *id)
  568. {
  569. static int dev;
  570. int err;
  571. struct snd_card *card;
  572. if (pnp_device_is_isapnp(pdev))
  573. return -ENOENT; /* we have another procedure - card */
  574. for (; dev < SNDRV_CARDS; dev++) {
  575. if (enable[dev] && isapnp[dev])
  576. break;
  577. }
  578. if (dev >= SNDRV_CARDS)
  579. return -ENODEV;
  580. card = snd_cs423x_card_new(dev);
  581. if (! card)
  582. return -ENOMEM;
  583. if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
  584. printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
  585. snd_card_free(card);
  586. return err;
  587. }
  588. snd_card_set_dev(card, &pdev->dev);
  589. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  590. snd_card_free(card);
  591. return err;
  592. }
  593. pnp_set_drvdata(pdev, card);
  594. dev++;
  595. return 0;
  596. }
  597. static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
  598. {
  599. snd_card_free(pnp_get_drvdata(pdev));
  600. pnp_set_drvdata(pdev, NULL);
  601. }
  602. #ifdef CONFIG_PM
  603. static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  604. {
  605. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  606. }
  607. static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
  608. {
  609. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  610. }
  611. #endif
  612. static struct pnp_driver cs4232_pnp_driver = {
  613. .name = "cs4232-pnpbios",
  614. .id_table = snd_cs4232_pnpbiosids,
  615. .probe = snd_cs4232_pnpbios_detect,
  616. .remove = __devexit_p(snd_cs4232_pnp_remove),
  617. #ifdef CONFIG_PM
  618. .suspend = snd_cs4232_pnp_suspend,
  619. .resume = snd_cs4232_pnp_resume,
  620. #endif
  621. };
  622. #endif /* CS4232 */
  623. static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  624. const struct pnp_card_device_id *pid)
  625. {
  626. static int dev;
  627. struct snd_card *card;
  628. int res;
  629. for ( ; dev < SNDRV_CARDS; dev++) {
  630. if (enable[dev] && isapnp[dev])
  631. break;
  632. }
  633. if (dev >= SNDRV_CARDS)
  634. return -ENODEV;
  635. card = snd_cs423x_card_new(dev);
  636. if (! card)
  637. return -ENOMEM;
  638. if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
  639. printk(KERN_ERR "isapnp detection failed and probing for " IDENT
  640. " is not supported\n");
  641. snd_card_free(card);
  642. return res;
  643. }
  644. snd_card_set_dev(card, &pcard->card->dev);
  645. if ((res = snd_cs423x_probe(card, dev)) < 0) {
  646. snd_card_free(card);
  647. return res;
  648. }
  649. pnp_set_card_drvdata(pcard, card);
  650. dev++;
  651. return 0;
  652. }
  653. static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
  654. {
  655. snd_card_free(pnp_get_card_drvdata(pcard));
  656. pnp_set_card_drvdata(pcard, NULL);
  657. }
  658. #ifdef CONFIG_PM
  659. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  660. {
  661. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  662. }
  663. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  664. {
  665. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  666. }
  667. #endif
  668. static struct pnp_card_driver cs423x_pnpc_driver = {
  669. .flags = PNP_DRIVER_RES_DISABLE,
  670. .name = CS423X_ISAPNP_DRIVER,
  671. .id_table = snd_cs423x_pnpids,
  672. .probe = snd_cs423x_pnpc_detect,
  673. .remove = __devexit_p(snd_cs423x_pnpc_remove),
  674. #ifdef CONFIG_PM
  675. .suspend = snd_cs423x_pnpc_suspend,
  676. .resume = snd_cs423x_pnpc_resume,
  677. #endif
  678. };
  679. #endif /* CONFIG_PNP */
  680. static void __init_or_module snd_cs423x_unregister_all(void)
  681. {
  682. int i;
  683. #ifdef CONFIG_PNP
  684. if (pnpc_registered)
  685. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  686. #ifdef CS4232
  687. if (pnp_registered)
  688. pnp_unregister_driver(&cs4232_pnp_driver);
  689. #endif
  690. #endif /* CONFIG_PNP */
  691. for (i = 0; i < ARRAY_SIZE(platform_devices); ++i)
  692. platform_device_unregister(platform_devices[i]);
  693. platform_driver_unregister(&cs423x_nonpnp_driver);
  694. }
  695. static int __init alsa_card_cs423x_init(void)
  696. {
  697. int i, err, cards = 0;
  698. if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
  699. return err;
  700. for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
  701. struct platform_device *device;
  702. if (is_isapnp_selected(i))
  703. continue;
  704. device = platform_device_register_simple(CS423X_DRIVER,
  705. i, NULL, 0);
  706. if (IS_ERR(device)) {
  707. err = PTR_ERR(device);
  708. goto errout;
  709. }
  710. platform_devices[i] = device;
  711. cards++;
  712. }
  713. #ifdef CONFIG_PNP
  714. #ifdef CS4232
  715. i = pnp_register_driver(&cs4232_pnp_driver);
  716. if (i >= 0) {
  717. pnp_registered = 1;
  718. cards += i;
  719. }
  720. #endif
  721. i = pnp_register_card_driver(&cs423x_pnpc_driver);
  722. if (i >= 0) {
  723. pnpc_registered = 1;
  724. cards += i;
  725. }
  726. #endif /* CONFIG_PNP */
  727. if (!cards) {
  728. #ifdef MODULE
  729. printk(KERN_ERR IDENT " soundcard not found or device busy\n");
  730. #endif
  731. err = -ENODEV;
  732. goto errout;
  733. }
  734. return 0;
  735. errout:
  736. snd_cs423x_unregister_all();
  737. return err;
  738. }
  739. static void __exit alsa_card_cs423x_exit(void)
  740. {
  741. snd_cs423x_unregister_all();
  742. }
  743. module_init(alsa_card_cs423x_init)
  744. module_exit(alsa_card_cs423x_exit)