cs4236.c 25 KB

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