cs4236.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. static int pnpc_registered;
  123. #ifdef CS4232
  124. static int pnp_registered;
  125. #endif
  126. struct snd_card_cs4236 {
  127. struct snd_cs4231 *chip;
  128. struct resource *res_sb_port;
  129. #ifdef CONFIG_PNP
  130. struct pnp_dev *wss;
  131. struct pnp_dev *ctrl;
  132. struct pnp_dev *mpu;
  133. #endif
  134. };
  135. #ifdef CONFIG_PNP
  136. #ifdef CS4232
  137. /*
  138. * PNP BIOS
  139. */
  140. static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
  141. { .id = "CSC0100" },
  142. { .id = "CSC0000" },
  143. /* Guillemot Turtlebeach something appears to be cs4232 compatible
  144. * (untested) */
  145. { .id = "GIM0100" },
  146. { .id = "" }
  147. };
  148. MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
  149. #endif /* CS4232 */
  150. #ifdef CS4232
  151. #define CS423X_DRIVER "snd_cs4232"
  152. #define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
  153. static struct pnp_card_device_id snd_cs423x_pnpids[] = {
  154. /* Philips PCA70PS */
  155. { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  156. /* TerraTec Maestro 32/96 (CS4232) */
  157. { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  158. /* HP Omnibook 5500 onboard */
  159. { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
  160. /* Unnamed CS4236 card (Made in Taiwan) */
  161. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  162. /* Turtle Beach TBS-2000 (CS4232) */
  163. { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
  164. /* Turtle Beach Tropez Plus (CS4232) */
  165. { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  166. /* SIC CrystalWave 32 (CS4232) */
  167. { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  168. /* --- */
  169. { .id = "" } /* end */
  170. };
  171. #else /* CS4236 */
  172. #define CS423X_DRIVER "snd_cs4236"
  173. #define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
  174. static struct pnp_card_device_id snd_cs423x_pnpids[] = {
  175. /* Intel Marlin Spike Motherboard - CS4235 */
  176. { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  177. /* Intel Marlin Spike Motherboard (#2) - CS4235 */
  178. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  179. /* Unknown Intel mainboard - CS4235 */
  180. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
  181. /* Genius Sound Maker 3DJ - CS4237B */
  182. { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  183. /* Digital PC 5000 Onboard - CS4236B */
  184. { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
  185. /* some uknown CS4236B */
  186. { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  187. /* Intel PR440FX Onboard sound */
  188. { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  189. /* CS4235 on mainboard without MPU */
  190. { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
  191. /* Gateway E1000 Onboard CS4236B */
  192. { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  193. /* HP 6330 Onboard sound */
  194. { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  195. /* Crystal Computer TidalWave128 */
  196. { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  197. /* ACER AW37 - CS4235 */
  198. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  199. /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
  200. { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  201. /* Crystal 3D - CS4237B */
  202. { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  203. /* Typhoon Soundsystem PnP - CS4236B */
  204. { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  205. /* Crystal CX4235-XQ3 EP - CS4235 */
  206. { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  207. /* Crystal Semiconductors CS4237B */
  208. { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  209. /* NewClear 3D - CX4237B-XQ3 */
  210. { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  211. /* Dell Optiplex GX1 - CS4236B */
  212. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  213. /* Dell P410 motherboard - CS4236B */
  214. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  215. /* Dell Workstation 400 Onboard - CS4236B */
  216. { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  217. /* Turtle Beach Malibu - CS4237B */
  218. { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  219. /* CS4235 - onboard */
  220. { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  221. /* IBM Aptiva 2137 E24 Onboard - CS4237B */
  222. { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  223. /* IBM IntelliStation M Pro motherboard */
  224. { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  225. /* Guillemot MaxiSound 16 PnP - CS4236B */
  226. { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  227. /* Gallant SC-70P */
  228. { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  229. /* TerraTec AudioSystem EWS64XL - CS4236B */
  230. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
  231. /* TerraTec AudioSystem EWS64XL - CS4236B */
  232. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
  233. /* ACER AW37/Pro - CS4235 */
  234. { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  235. /* ACER AW35/Pro - CS4237B */
  236. { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  237. /* CS4235 without MPU401 */
  238. { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  239. /* Unknown SiS530 - CS4235 */
  240. { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  241. /* IBM IntelliStation M Pro 6898 11U - CS4236B */
  242. { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  243. /* IBM PC 300PL Onboard - CS4236B */
  244. { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
  245. /* Some noname CS4236 based card */
  246. { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  247. /* CS4236B */
  248. { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  249. /* CS4236B */
  250. { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  251. /* --- */
  252. { .id = "" } /* end */
  253. };
  254. #endif
  255. MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
  256. /* WSS initialization */
  257. static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev,
  258. struct pnp_resource_table *cfg)
  259. {
  260. int err;
  261. pnp_init_resource_table(cfg);
  262. if (port[dev] != SNDRV_AUTO_PORT)
  263. pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
  264. if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
  265. pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
  266. if (sb_port[dev] != SNDRV_AUTO_PORT)
  267. pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
  268. if (irq[dev] != SNDRV_AUTO_IRQ)
  269. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  270. if (dma1[dev] != SNDRV_AUTO_DMA)
  271. pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
  272. if (dma2[dev] != SNDRV_AUTO_DMA)
  273. pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
  274. err = pnp_manual_config_dev(pdev, cfg, 0);
  275. if (err < 0)
  276. snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
  277. err = pnp_activate_dev(pdev);
  278. if (err < 0) {
  279. printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
  280. return -EBUSY;
  281. }
  282. port[dev] = pnp_port_start(pdev, 0);
  283. if (fm_port[dev] > 0)
  284. fm_port[dev] = pnp_port_start(pdev, 1);
  285. sb_port[dev] = pnp_port_start(pdev, 2);
  286. irq[dev] = pnp_irq(pdev, 0);
  287. dma1[dev] = pnp_dma(pdev, 0);
  288. dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
  289. snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
  290. port[dev], fm_port[dev], sb_port[dev]);
  291. snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
  292. irq[dev], dma1[dev], dma2[dev]);
  293. return 0;
  294. }
  295. /* CTRL initialization */
  296. static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev,
  297. struct pnp_resource_table *cfg)
  298. {
  299. int err;
  300. pnp_init_resource_table(cfg);
  301. if (cport[dev] != SNDRV_AUTO_PORT)
  302. pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
  303. err = pnp_manual_config_dev(pdev, cfg, 0);
  304. if (err < 0)
  305. snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
  306. err = pnp_activate_dev(pdev);
  307. if (err < 0) {
  308. printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
  309. return -EBUSY;
  310. }
  311. cport[dev] = pnp_port_start(pdev, 0);
  312. snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
  313. return 0;
  314. }
  315. /* MPU initialization */
  316. static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev,
  317. struct pnp_resource_table *cfg)
  318. {
  319. int err;
  320. pnp_init_resource_table(cfg);
  321. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  322. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  323. if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
  324. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  325. err = pnp_manual_config_dev(pdev, cfg, 0);
  326. if (err < 0)
  327. snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
  328. err = pnp_activate_dev(pdev);
  329. if (err < 0) {
  330. printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
  331. mpu_port[dev] = SNDRV_AUTO_PORT;
  332. mpu_irq[dev] = SNDRV_AUTO_IRQ;
  333. } else {
  334. mpu_port[dev] = pnp_port_start(pdev, 0);
  335. if (mpu_irq[dev] >= 0 &&
  336. pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
  337. mpu_irq[dev] = pnp_irq(pdev, 0);
  338. } else {
  339. mpu_irq[dev] = -1; /* disable interrupt */
  340. }
  341. }
  342. snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  343. return 0;
  344. }
  345. #ifdef CS4232
  346. static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
  347. struct pnp_dev *pdev)
  348. {
  349. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  350. if (!cfg)
  351. return -ENOMEM;
  352. if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) {
  353. kfree(cfg);
  354. return -EBUSY;
  355. }
  356. kfree(cfg);
  357. cport[dev] = -1;
  358. return 0;
  359. }
  360. #endif
  361. static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
  362. struct pnp_card_link *card,
  363. const struct pnp_card_device_id *id)
  364. {
  365. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  366. if (!cfg)
  367. return -ENOMEM;
  368. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  369. if (acard->wss == NULL)
  370. goto error;
  371. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  372. if (acard->ctrl == NULL)
  373. goto error;
  374. if (id->devs[2].id[0]) {
  375. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  376. if (acard->mpu == NULL)
  377. goto error;
  378. }
  379. /* WSS initialization */
  380. if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0)
  381. goto error;
  382. /* CTRL initialization */
  383. if (acard->ctrl && cport[dev] > 0) {
  384. if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0)
  385. goto error;
  386. }
  387. /* MPU initialization */
  388. if (acard->mpu && mpu_port[dev] > 0) {
  389. if (snd_cs423x_pnp_init_mpu(dev, acard->ctrl, cfg) < 0)
  390. goto error;
  391. }
  392. kfree(cfg);
  393. return 0;
  394. error:
  395. kfree(cfg);
  396. return -EBUSY;
  397. }
  398. #endif /* CONFIG_PNP */
  399. #ifdef CONFIG_PNP
  400. #define is_isapnp_selected(dev) isapnp[dev]
  401. #else
  402. #define is_isapnp_selected(dev) 0
  403. #endif
  404. static void snd_card_cs4236_free(struct snd_card *card)
  405. {
  406. struct snd_card_cs4236 *acard = card->private_data;
  407. release_and_free_resource(acard->res_sb_port);
  408. }
  409. static struct snd_card *snd_cs423x_card_new(int dev)
  410. {
  411. struct snd_card *card;
  412. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  413. sizeof(struct snd_card_cs4236));
  414. if (card == NULL)
  415. return NULL;
  416. card->private_free = snd_card_cs4236_free;
  417. return card;
  418. }
  419. static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
  420. {
  421. struct snd_card_cs4236 *acard;
  422. struct snd_pcm *pcm;
  423. struct snd_cs4231 *chip;
  424. struct snd_opl3 *opl3;
  425. int err;
  426. acard = card->private_data;
  427. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
  428. if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
  429. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  430. return -EBUSY;
  431. }
  432. #ifdef CS4232
  433. if ((err = snd_cs4231_create(card,
  434. port[dev],
  435. cport[dev],
  436. irq[dev],
  437. dma1[dev],
  438. dma2[dev],
  439. CS4231_HW_DETECT,
  440. 0,
  441. &chip)) < 0)
  442. return err;
  443. acard->chip = chip;
  444. if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
  445. return err;
  446. if ((err = snd_cs4231_mixer(chip)) < 0)
  447. return err;
  448. #else /* CS4236 */
  449. if ((err = snd_cs4236_create(card,
  450. port[dev],
  451. cport[dev],
  452. irq[dev],
  453. dma1[dev],
  454. dma2[dev],
  455. CS4231_HW_DETECT,
  456. 0,
  457. &chip)) < 0)
  458. return err;
  459. acard->chip = chip;
  460. if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
  461. return err;
  462. if ((err = snd_cs4236_mixer(chip)) < 0)
  463. return err;
  464. #endif
  465. strcpy(card->driver, pcm->name);
  466. strcpy(card->shortname, pcm->name);
  467. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
  468. pcm->name,
  469. chip->port,
  470. irq[dev],
  471. dma1[dev]);
  472. if (dma2[dev] >= 0)
  473. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  474. if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
  475. return err;
  476. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  477. if (snd_opl3_create(card,
  478. fm_port[dev], fm_port[dev] + 2,
  479. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  480. printk(KERN_WARNING IDENT ": OPL3 not detected\n");
  481. } else {
  482. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  483. return err;
  484. }
  485. }
  486. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  487. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  488. mpu_irq[dev] = -1;
  489. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  490. mpu_port[dev], 0,
  491. mpu_irq[dev],
  492. mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
  493. printk(KERN_WARNING IDENT ": MPU401 not detected\n");
  494. }
  495. return snd_card_register(card);
  496. }
  497. static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev)
  498. {
  499. int dev = pdev->id;
  500. struct snd_card *card;
  501. int err;
  502. if (port[dev] == SNDRV_AUTO_PORT) {
  503. snd_printk(KERN_ERR "specify port\n");
  504. return -EINVAL;
  505. }
  506. if (cport[dev] == SNDRV_AUTO_PORT) {
  507. snd_printk(KERN_ERR "specify cport\n");
  508. return -EINVAL;
  509. }
  510. card = snd_cs423x_card_new(dev);
  511. if (! card)
  512. return -ENOMEM;
  513. snd_card_set_dev(card, &pdev->dev);
  514. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  515. snd_card_free(card);
  516. return err;
  517. }
  518. platform_set_drvdata(pdev, card);
  519. return 0;
  520. }
  521. static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr)
  522. {
  523. snd_card_free(platform_get_drvdata(devptr));
  524. platform_set_drvdata(devptr, NULL);
  525. return 0;
  526. }
  527. #ifdef CONFIG_PM
  528. static int snd_cs423x_suspend(struct snd_card *card)
  529. {
  530. struct snd_card_cs4236 *acard = card->private_data;
  531. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  532. acard->chip->suspend(acard->chip);
  533. return 0;
  534. }
  535. static int snd_cs423x_resume(struct snd_card *card)
  536. {
  537. struct snd_card_cs4236 *acard = card->private_data;
  538. acard->chip->resume(acard->chip);
  539. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  540. return 0;
  541. }
  542. static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state)
  543. {
  544. return snd_cs423x_suspend(platform_get_drvdata(dev));
  545. }
  546. static int snd_cs423x_nonpnp_resume(struct platform_device *dev)
  547. {
  548. return snd_cs423x_resume(platform_get_drvdata(dev));
  549. }
  550. #endif
  551. static struct platform_driver cs423x_nonpnp_driver = {
  552. .probe = snd_cs423x_nonpnp_probe,
  553. .remove = __devexit_p(snd_cs423x_nonpnp_remove),
  554. #ifdef CONFIG_PM
  555. .suspend = snd_cs423x_nonpnp_suspend,
  556. .resume = snd_cs423x_nonpnp_resume,
  557. #endif
  558. .driver = {
  559. .name = CS423X_DRIVER
  560. },
  561. };
  562. #ifdef CONFIG_PNP
  563. #ifdef CS4232
  564. static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
  565. const struct pnp_device_id *id)
  566. {
  567. static int dev;
  568. int err;
  569. struct snd_card *card;
  570. if (pnp_device_is_isapnp(pdev))
  571. return -ENOENT; /* we have another procedure - card */
  572. for (; dev < SNDRV_CARDS; dev++) {
  573. if (enable[dev] && isapnp[dev])
  574. break;
  575. }
  576. if (dev >= SNDRV_CARDS)
  577. return -ENODEV;
  578. card = snd_cs423x_card_new(dev);
  579. if (! card)
  580. return -ENOMEM;
  581. if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
  582. printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
  583. snd_card_free(card);
  584. return err;
  585. }
  586. snd_card_set_dev(card, &pdev->dev);
  587. if ((err = snd_cs423x_probe(card, dev)) < 0) {
  588. snd_card_free(card);
  589. return err;
  590. }
  591. pnp_set_drvdata(pdev, card);
  592. dev++;
  593. return 0;
  594. }
  595. static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
  596. {
  597. snd_card_free(pnp_get_drvdata(pdev));
  598. pnp_set_drvdata(pdev, NULL);
  599. }
  600. #ifdef CONFIG_PM
  601. static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  602. {
  603. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  604. }
  605. static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
  606. {
  607. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  608. }
  609. #endif
  610. static struct pnp_driver cs4232_pnp_driver = {
  611. .name = "cs4232-pnpbios",
  612. .id_table = snd_cs4232_pnpbiosids,
  613. .probe = snd_cs4232_pnpbios_detect,
  614. .remove = __devexit_p(snd_cs4232_pnp_remove),
  615. #ifdef CONFIG_PM
  616. .suspend = snd_cs4232_pnp_suspend,
  617. .resume = snd_cs4232_pnp_resume,
  618. #endif
  619. };
  620. #endif /* CS4232 */
  621. static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  622. const struct pnp_card_device_id *pid)
  623. {
  624. static int dev;
  625. struct snd_card *card;
  626. int res;
  627. for ( ; dev < SNDRV_CARDS; dev++) {
  628. if (enable[dev] && isapnp[dev])
  629. break;
  630. }
  631. if (dev >= SNDRV_CARDS)
  632. return -ENODEV;
  633. card = snd_cs423x_card_new(dev);
  634. if (! card)
  635. return -ENOMEM;
  636. if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
  637. printk(KERN_ERR "isapnp detection failed and probing for " IDENT
  638. " is not supported\n");
  639. snd_card_free(card);
  640. return res;
  641. }
  642. snd_card_set_dev(card, &pcard->card->dev);
  643. if ((res = snd_cs423x_probe(card, dev)) < 0) {
  644. snd_card_free(card);
  645. return res;
  646. }
  647. pnp_set_card_drvdata(pcard, card);
  648. dev++;
  649. return 0;
  650. }
  651. static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
  652. {
  653. snd_card_free(pnp_get_card_drvdata(pcard));
  654. pnp_set_card_drvdata(pcard, NULL);
  655. }
  656. #ifdef CONFIG_PM
  657. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  658. {
  659. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  660. }
  661. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  662. {
  663. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  664. }
  665. #endif
  666. static struct pnp_card_driver cs423x_pnpc_driver = {
  667. .flags = PNP_DRIVER_RES_DISABLE,
  668. .name = CS423X_ISAPNP_DRIVER,
  669. .id_table = snd_cs423x_pnpids,
  670. .probe = snd_cs423x_pnpc_detect,
  671. .remove = __devexit_p(snd_cs423x_pnpc_remove),
  672. #ifdef CONFIG_PM
  673. .suspend = snd_cs423x_pnpc_suspend,
  674. .resume = snd_cs423x_pnpc_resume,
  675. #endif
  676. };
  677. #endif /* CONFIG_PNP */
  678. static void __init_or_module snd_cs423x_unregister_all(void)
  679. {
  680. int i;
  681. if (pnpc_registered)
  682. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  683. #ifdef CS4232
  684. if (pnp_registered)
  685. pnp_unregister_driver(&cs4232_pnp_driver);
  686. #endif
  687. for (i = 0; i < ARRAY_SIZE(platform_devices); ++i)
  688. platform_device_unregister(platform_devices[i]);
  689. platform_driver_unregister(&cs423x_nonpnp_driver);
  690. }
  691. static int __init alsa_card_cs423x_init(void)
  692. {
  693. int i, err, cards = 0;
  694. if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
  695. return err;
  696. for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
  697. struct platform_device *device;
  698. if (is_isapnp_selected(i))
  699. continue;
  700. device = platform_device_register_simple(CS423X_DRIVER,
  701. i, NULL, 0);
  702. if (IS_ERR(device)) {
  703. err = PTR_ERR(device);
  704. goto errout;
  705. }
  706. platform_devices[i] = device;
  707. cards++;
  708. }
  709. #ifdef CS4232
  710. i = pnp_register_driver(&cs4232_pnp_driver);
  711. if (i >= 0) {
  712. pnp_registered = 1;
  713. cards += i;
  714. }
  715. #endif
  716. i = pnp_register_card_driver(&cs423x_pnpc_driver);
  717. if (i >= 0) {
  718. pnpc_registered = 1;
  719. cards += i;
  720. }
  721. if (!cards) {
  722. #ifdef MODULE
  723. printk(KERN_ERR IDENT " soundcard not found or device busy\n");
  724. #endif
  725. err = -ENODEV;
  726. goto errout;
  727. }
  728. return 0;
  729. errout:
  730. snd_cs423x_unregister_all();
  731. return err;
  732. }
  733. static void __exit alsa_card_cs423x_exit(void)
  734. {
  735. snd_cs423x_unregister_all();
  736. }
  737. module_init(alsa_card_cs423x_init)
  738. module_exit(alsa_card_cs423x_exit)