cs4236.c 25 KB

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