cs4236.c 24 KB

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