cs4236.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
  4. * Copyright (c) by Jaroslav Kysela <[email protected]>
  5. */
  6. #include <linux/init.h>
  7. #include <linux/err.h>
  8. #include <linux/isa.h>
  9. #include <linux/pnp.h>
  10. #include <linux/module.h>
  11. #include <sound/core.h>
  12. #include <sound/wss.h>
  13. #include <sound/mpu401.h>
  14. #include <sound/opl3.h>
  15. #include <sound/initval.h>
  16. MODULE_AUTHOR("Jaroslav Kysela <[email protected]>");
  17. MODULE_LICENSE("GPL");
  18. MODULE_DESCRIPTION("Cirrus Logic CS4232-9");
  19. MODULE_ALIAS("snd_cs4232");
  20. #define IDENT "CS4232+"
  21. #define DEV_NAME "cs4232+"
  22. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  23. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  24. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  25. #ifdef CONFIG_PNP
  26. static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  27. #endif
  28. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  29. static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  30. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
  31. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  32. static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  33. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  34. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
  35. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  36. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  37. module_param_array(index, int, NULL, 0444);
  38. MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
  39. module_param_array(id, charp, NULL, 0444);
  40. MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
  41. module_param_array(enable, bool, NULL, 0444);
  42. MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
  43. #ifdef CONFIG_PNP
  44. module_param_array(isapnp, bool, NULL, 0444);
  45. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  46. #endif
  47. module_param_hw_array(port, long, ioport, NULL, 0444);
  48. MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
  49. module_param_hw_array(cport, long, ioport, NULL, 0444);
  50. MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
  51. module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
  52. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
  53. module_param_hw_array(fm_port, long, ioport, NULL, 0444);
  54. MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
  55. module_param_hw_array(sb_port, long, ioport, NULL, 0444);
  56. MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
  57. module_param_hw_array(irq, int, irq, NULL, 0444);
  58. MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
  59. module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
  60. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
  61. module_param_hw_array(dma1, int, dma, NULL, 0444);
  62. MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
  63. module_param_hw_array(dma2, int, dma, NULL, 0444);
  64. MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
  65. #ifdef CONFIG_PNP
  66. static int isa_registered;
  67. static int pnpc_registered;
  68. static int pnp_registered;
  69. #endif /* CONFIG_PNP */
  70. struct snd_card_cs4236 {
  71. struct snd_wss *chip;
  72. #ifdef CONFIG_PNP
  73. struct pnp_dev *wss;
  74. struct pnp_dev *ctrl;
  75. struct pnp_dev *mpu;
  76. #endif
  77. };
  78. #ifdef CONFIG_PNP
  79. /*
  80. * PNP BIOS
  81. */
  82. static const struct pnp_device_id snd_cs423x_pnpbiosids[] = {
  83. { .id = "CSC0100" },
  84. { .id = "CSC0000" },
  85. /* Guillemot Turtlebeach something appears to be cs4232 compatible
  86. * (untested) */
  87. { .id = "GIM0100" },
  88. { .id = "" }
  89. };
  90. MODULE_DEVICE_TABLE(pnp, snd_cs423x_pnpbiosids);
  91. #define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
  92. static const struct pnp_card_device_id snd_cs423x_pnpids[] = {
  93. /* Philips PCA70PS */
  94. { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  95. /* TerraTec Maestro 32/96 (CS4232) */
  96. { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  97. /* HP Omnibook 5500 onboard */
  98. { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
  99. /* Unnamed CS4236 card (Made in Taiwan) */
  100. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  101. /* Turtle Beach TBS-2000 (CS4232) */
  102. { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
  103. /* Turtle Beach Tropez Plus (CS4232) */
  104. { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
  105. /* SIC CrystalWave 32 (CS4232) */
  106. { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  107. /* Netfinity 3000 on-board soundcard */
  108. { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
  109. /* Intel Marlin Spike Motherboard - CS4235 */
  110. { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  111. /* Intel Marlin Spike Motherboard (#2) - CS4235 */
  112. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  113. /* Unknown Intel mainboard - CS4235 */
  114. { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
  115. /* Genius Sound Maker 3DJ - CS4237B */
  116. { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  117. /* Digital PC 5000 Onboard - CS4236B */
  118. { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
  119. /* some unknown CS4236B */
  120. { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  121. /* Intel PR440FX Onboard sound */
  122. { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  123. /* CS4235 on mainboard without MPU */
  124. { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
  125. /* Gateway E1000 Onboard CS4236B */
  126. { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  127. /* HP 6330 Onboard sound */
  128. { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  129. /* Crystal Computer TidalWave128 */
  130. { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  131. /* ACER AW37 - CS4235 */
  132. { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  133. /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
  134. { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  135. /* Crystal 3D - CS4237B */
  136. { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  137. /* Typhoon Soundsystem PnP - CS4236B */
  138. { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  139. /* Crystal CX4235-XQ3 EP - CS4235 */
  140. { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  141. /* Crystal Semiconductors CS4237B */
  142. { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  143. /* NewClear 3D - CX4237B-XQ3 */
  144. { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  145. /* Dell Optiplex GX1 - CS4236B */
  146. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  147. /* Dell P410 motherboard - CS4236B */
  148. { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  149. /* Dell Workstation 400 Onboard - CS4236B */
  150. { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  151. /* Turtle Beach Malibu - CS4237B */
  152. { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  153. /* CS4235 - onboard */
  154. { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
  155. /* IBM Aptiva 2137 E24 Onboard - CS4237B */
  156. { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  157. /* IBM IntelliStation M Pro motherboard */
  158. { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  159. /* Guillemot MaxiSound 16 PnP - CS4236B */
  160. { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  161. /* Gallant SC-70P */
  162. { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  163. /* Techmakers MF-4236PW */
  164. { .id = "CSCa736", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  165. /* TerraTec AudioSystem EWS64XL - CS4236B */
  166. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
  167. /* TerraTec AudioSystem EWS64XL - CS4236B */
  168. { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
  169. /* ACER AW37/Pro - CS4235 */
  170. { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  171. /* ACER AW35/Pro - CS4237B */
  172. { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  173. /* CS4235 without MPU401 */
  174. { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  175. /* Unknown SiS530 - CS4235 */
  176. { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
  177. /* IBM IntelliStation M Pro 6898 11U - CS4236B */
  178. { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
  179. /* IBM PC 300PL Onboard - CS4236B */
  180. { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
  181. /* Some noname CS4236 based card */
  182. { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  183. /* CS4236B */
  184. { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  185. /* CS4236B */
  186. { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
  187. /* --- */
  188. { .id = "" } /* end */
  189. };
  190. MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
  191. /* WSS initialization */
  192. static int snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev)
  193. {
  194. if (pnp_activate_dev(pdev) < 0) {
  195. printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
  196. return -EBUSY;
  197. }
  198. port[dev] = pnp_port_start(pdev, 0);
  199. if (fm_port[dev] > 0)
  200. fm_port[dev] = pnp_port_start(pdev, 1);
  201. sb_port[dev] = pnp_port_start(pdev, 2);
  202. irq[dev] = pnp_irq(pdev, 0);
  203. dma1[dev] = pnp_dma(pdev, 0);
  204. dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
  205. snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
  206. port[dev], fm_port[dev], sb_port[dev]);
  207. snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
  208. irq[dev], dma1[dev], dma2[dev]);
  209. return 0;
  210. }
  211. /* CTRL initialization */
  212. static int snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
  213. {
  214. if (pnp_activate_dev(pdev) < 0) {
  215. printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
  216. return -EBUSY;
  217. }
  218. cport[dev] = pnp_port_start(pdev, 0);
  219. snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
  220. return 0;
  221. }
  222. /* MPU initialization */
  223. static int snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
  224. {
  225. if (pnp_activate_dev(pdev) < 0) {
  226. printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
  227. mpu_port[dev] = SNDRV_AUTO_PORT;
  228. mpu_irq[dev] = SNDRV_AUTO_IRQ;
  229. } else {
  230. mpu_port[dev] = pnp_port_start(pdev, 0);
  231. if (mpu_irq[dev] >= 0 &&
  232. pnp_irq_valid(pdev, 0) &&
  233. pnp_irq(pdev, 0) != (resource_size_t)-1) {
  234. mpu_irq[dev] = pnp_irq(pdev, 0);
  235. } else {
  236. mpu_irq[dev] = -1; /* disable interrupt */
  237. }
  238. }
  239. snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  240. return 0;
  241. }
  242. static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
  243. struct pnp_dev *pdev,
  244. struct pnp_dev *cdev)
  245. {
  246. acard->wss = pdev;
  247. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  248. return -EBUSY;
  249. if (cdev)
  250. cport[dev] = pnp_port_start(cdev, 0);
  251. else
  252. cport[dev] = -1;
  253. return 0;
  254. }
  255. static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
  256. struct pnp_card_link *card,
  257. const struct pnp_card_device_id *id)
  258. {
  259. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  260. if (acard->wss == NULL)
  261. return -EBUSY;
  262. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  263. if (acard->ctrl == NULL)
  264. return -EBUSY;
  265. if (id->devs[2].id[0]) {
  266. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  267. if (acard->mpu == NULL)
  268. return -EBUSY;
  269. }
  270. /* WSS initialization */
  271. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  272. return -EBUSY;
  273. /* CTRL initialization */
  274. if (acard->ctrl && cport[dev] > 0) {
  275. if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
  276. return -EBUSY;
  277. }
  278. /* MPU initialization */
  279. if (acard->mpu && mpu_port[dev] > 0) {
  280. if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
  281. return -EBUSY;
  282. }
  283. return 0;
  284. }
  285. #endif /* CONFIG_PNP */
  286. #ifdef CONFIG_PNP
  287. #define is_isapnp_selected(dev) isapnp[dev]
  288. #else
  289. #define is_isapnp_selected(dev) 0
  290. #endif
  291. static int snd_cs423x_card_new(struct device *pdev, int dev,
  292. struct snd_card **cardp)
  293. {
  294. struct snd_card *card;
  295. int err;
  296. err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
  297. sizeof(struct snd_card_cs4236), &card);
  298. if (err < 0)
  299. return err;
  300. *cardp = card;
  301. return 0;
  302. }
  303. static int snd_cs423x_probe(struct snd_card *card, int dev)
  304. {
  305. struct snd_card_cs4236 *acard;
  306. struct snd_wss *chip;
  307. struct snd_opl3 *opl3;
  308. int err;
  309. acard = card->private_data;
  310. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) {
  311. if (!devm_request_region(card->dev, sb_port[dev], 16,
  312. IDENT " SB")) {
  313. printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
  314. return -EBUSY;
  315. }
  316. }
  317. err = snd_cs4236_create(card, port[dev], cport[dev],
  318. irq[dev],
  319. dma1[dev], dma2[dev],
  320. WSS_HW_DETECT3, 0, &chip);
  321. if (err < 0)
  322. return err;
  323. acard->chip = chip;
  324. if (chip->hardware & WSS_HW_CS4236B_MASK) {
  325. err = snd_cs4236_pcm(chip, 0);
  326. if (err < 0)
  327. return err;
  328. err = snd_cs4236_mixer(chip);
  329. if (err < 0)
  330. return err;
  331. } else {
  332. err = snd_wss_pcm(chip, 0);
  333. if (err < 0)
  334. return err;
  335. err = snd_wss_mixer(chip);
  336. if (err < 0)
  337. return err;
  338. }
  339. strscpy(card->driver, chip->pcm->name, sizeof(card->driver));
  340. strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
  341. if (dma2[dev] < 0)
  342. snprintf(card->longname, sizeof(card->longname),
  343. "%s at 0x%lx, irq %i, dma %i",
  344. chip->pcm->name, chip->port, irq[dev], dma1[dev]);
  345. else
  346. snprintf(card->longname, sizeof(card->longname),
  347. "%s at 0x%lx, irq %i, dma %i&%d",
  348. chip->pcm->name, chip->port, irq[dev], dma1[dev],
  349. dma2[dev]);
  350. err = snd_wss_timer(chip, 0);
  351. if (err < 0)
  352. return err;
  353. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  354. if (snd_opl3_create(card,
  355. fm_port[dev], fm_port[dev] + 2,
  356. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  357. printk(KERN_WARNING IDENT ": OPL3 not detected\n");
  358. } else {
  359. err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  360. if (err < 0)
  361. return err;
  362. }
  363. }
  364. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  365. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  366. mpu_irq[dev] = -1;
  367. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  368. mpu_port[dev], 0,
  369. mpu_irq[dev], NULL) < 0)
  370. printk(KERN_WARNING IDENT ": MPU401 not detected\n");
  371. }
  372. return snd_card_register(card);
  373. }
  374. static int snd_cs423x_isa_match(struct device *pdev,
  375. unsigned int dev)
  376. {
  377. if (!enable[dev] || is_isapnp_selected(dev))
  378. return 0;
  379. if (port[dev] == SNDRV_AUTO_PORT) {
  380. dev_err(pdev, "please specify port\n");
  381. return 0;
  382. }
  383. if (cport[dev] == SNDRV_AUTO_PORT) {
  384. dev_err(pdev, "please specify cport\n");
  385. return 0;
  386. }
  387. if (irq[dev] == SNDRV_AUTO_IRQ) {
  388. dev_err(pdev, "please specify irq\n");
  389. return 0;
  390. }
  391. if (dma1[dev] == SNDRV_AUTO_DMA) {
  392. dev_err(pdev, "please specify dma1\n");
  393. return 0;
  394. }
  395. return 1;
  396. }
  397. static int snd_cs423x_isa_probe(struct device *pdev,
  398. unsigned int dev)
  399. {
  400. struct snd_card *card;
  401. int err;
  402. err = snd_cs423x_card_new(pdev, dev, &card);
  403. if (err < 0)
  404. return err;
  405. err = snd_cs423x_probe(card, dev);
  406. if (err < 0)
  407. return err;
  408. dev_set_drvdata(pdev, card);
  409. return 0;
  410. }
  411. #ifdef CONFIG_PM
  412. static int snd_cs423x_suspend(struct snd_card *card)
  413. {
  414. struct snd_card_cs4236 *acard = card->private_data;
  415. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  416. acard->chip->suspend(acard->chip);
  417. return 0;
  418. }
  419. static int snd_cs423x_resume(struct snd_card *card)
  420. {
  421. struct snd_card_cs4236 *acard = card->private_data;
  422. acard->chip->resume(acard->chip);
  423. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  424. return 0;
  425. }
  426. static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
  427. pm_message_t state)
  428. {
  429. return snd_cs423x_suspend(dev_get_drvdata(dev));
  430. }
  431. static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
  432. {
  433. return snd_cs423x_resume(dev_get_drvdata(dev));
  434. }
  435. #endif
  436. static struct isa_driver cs423x_isa_driver = {
  437. .match = snd_cs423x_isa_match,
  438. .probe = snd_cs423x_isa_probe,
  439. #ifdef CONFIG_PM
  440. .suspend = snd_cs423x_isa_suspend,
  441. .resume = snd_cs423x_isa_resume,
  442. #endif
  443. .driver = {
  444. .name = DEV_NAME
  445. },
  446. };
  447. #ifdef CONFIG_PNP
  448. static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
  449. const struct pnp_device_id *id)
  450. {
  451. static int dev;
  452. int err;
  453. struct snd_card *card;
  454. struct pnp_dev *cdev, *iter;
  455. char cid[PNP_ID_LEN];
  456. if (pnp_device_is_isapnp(pdev))
  457. return -ENOENT; /* we have another procedure - card */
  458. for (; dev < SNDRV_CARDS; dev++) {
  459. if (enable[dev] && isapnp[dev])
  460. break;
  461. }
  462. if (dev >= SNDRV_CARDS)
  463. return -ENODEV;
  464. /* prepare second id */
  465. strcpy(cid, pdev->id[0].id);
  466. cid[5] = '1';
  467. cdev = NULL;
  468. list_for_each_entry(iter, &(pdev->protocol->devices), protocol_list) {
  469. if (!strcmp(iter->id[0].id, cid)) {
  470. cdev = iter;
  471. break;
  472. }
  473. }
  474. err = snd_cs423x_card_new(&pdev->dev, dev, &card);
  475. if (err < 0)
  476. return err;
  477. err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
  478. if (err < 0) {
  479. printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
  480. return err;
  481. }
  482. err = snd_cs423x_probe(card, dev);
  483. if (err < 0)
  484. return err;
  485. pnp_set_drvdata(pdev, card);
  486. dev++;
  487. return 0;
  488. }
  489. #ifdef CONFIG_PM
  490. static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  491. {
  492. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  493. }
  494. static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
  495. {
  496. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  497. }
  498. #endif
  499. static struct pnp_driver cs423x_pnp_driver = {
  500. .name = "cs423x-pnpbios",
  501. .id_table = snd_cs423x_pnpbiosids,
  502. .probe = snd_cs423x_pnpbios_detect,
  503. #ifdef CONFIG_PM
  504. .suspend = snd_cs423x_pnp_suspend,
  505. .resume = snd_cs423x_pnp_resume,
  506. #endif
  507. };
  508. static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  509. const struct pnp_card_device_id *pid)
  510. {
  511. static int dev;
  512. struct snd_card *card;
  513. int res;
  514. for ( ; dev < SNDRV_CARDS; dev++) {
  515. if (enable[dev] && isapnp[dev])
  516. break;
  517. }
  518. if (dev >= SNDRV_CARDS)
  519. return -ENODEV;
  520. res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
  521. if (res < 0)
  522. return res;
  523. res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid);
  524. if (res < 0) {
  525. printk(KERN_ERR "isapnp detection failed and probing for " IDENT
  526. " is not supported\n");
  527. return res;
  528. }
  529. res = snd_cs423x_probe(card, dev);
  530. if (res < 0)
  531. return res;
  532. pnp_set_card_drvdata(pcard, card);
  533. dev++;
  534. return 0;
  535. }
  536. #ifdef CONFIG_PM
  537. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  538. {
  539. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  540. }
  541. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  542. {
  543. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  544. }
  545. #endif
  546. static struct pnp_card_driver cs423x_pnpc_driver = {
  547. .flags = PNP_DRIVER_RES_DISABLE,
  548. .name = CS423X_ISAPNP_DRIVER,
  549. .id_table = snd_cs423x_pnpids,
  550. .probe = snd_cs423x_pnpc_detect,
  551. #ifdef CONFIG_PM
  552. .suspend = snd_cs423x_pnpc_suspend,
  553. .resume = snd_cs423x_pnpc_resume,
  554. #endif
  555. };
  556. #endif /* CONFIG_PNP */
  557. static int __init alsa_card_cs423x_init(void)
  558. {
  559. int err;
  560. err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
  561. #ifdef CONFIG_PNP
  562. if (!err)
  563. isa_registered = 1;
  564. err = pnp_register_driver(&cs423x_pnp_driver);
  565. if (!err)
  566. pnp_registered = 1;
  567. err = pnp_register_card_driver(&cs423x_pnpc_driver);
  568. if (!err)
  569. pnpc_registered = 1;
  570. if (pnp_registered)
  571. err = 0;
  572. if (isa_registered)
  573. err = 0;
  574. #endif
  575. return err;
  576. }
  577. static void __exit alsa_card_cs423x_exit(void)
  578. {
  579. #ifdef CONFIG_PNP
  580. if (pnpc_registered)
  581. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  582. if (pnp_registered)
  583. pnp_unregister_driver(&cs423x_pnp_driver);
  584. if (isa_registered)
  585. #endif
  586. isa_unregister_driver(&cs423x_isa_driver);
  587. }
  588. module_init(alsa_card_cs423x_init)
  589. module_exit(alsa_card_cs423x_exit)