cs4236.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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 <perex@perex.cz>
  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 <perex@perex.cz>");
  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. dev_err(&pdev->dev, 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. dev_dbg(&pdev->dev,
  206. "isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
  207. port[dev], fm_port[dev], sb_port[dev]);
  208. dev_dbg(&pdev->dev,
  209. "isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
  210. irq[dev], dma1[dev], dma2[dev]);
  211. return 0;
  212. }
  213. /* CTRL initialization */
  214. static int snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
  215. {
  216. if (pnp_activate_dev(pdev) < 0) {
  217. dev_err(&pdev->dev, IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
  218. return -EBUSY;
  219. }
  220. cport[dev] = pnp_port_start(pdev, 0);
  221. dev_dbg(&pdev->dev, "isapnp CTRL: control port=0x%lx\n", cport[dev]);
  222. return 0;
  223. }
  224. /* MPU initialization */
  225. static int snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
  226. {
  227. if (pnp_activate_dev(pdev) < 0) {
  228. dev_err(&pdev->dev, IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
  229. mpu_port[dev] = SNDRV_AUTO_PORT;
  230. mpu_irq[dev] = SNDRV_AUTO_IRQ;
  231. } else {
  232. mpu_port[dev] = pnp_port_start(pdev, 0);
  233. if (mpu_irq[dev] >= 0 &&
  234. pnp_irq_valid(pdev, 0) &&
  235. pnp_irq(pdev, 0) != (resource_size_t)-1) {
  236. mpu_irq[dev] = pnp_irq(pdev, 0);
  237. } else {
  238. mpu_irq[dev] = -1; /* disable interrupt */
  239. }
  240. }
  241. dev_dbg(&pdev->dev, "isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
  242. return 0;
  243. }
  244. static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
  245. struct pnp_dev *pdev,
  246. struct pnp_dev *cdev)
  247. {
  248. acard->wss = pdev;
  249. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  250. return -EBUSY;
  251. if (cdev)
  252. cport[dev] = pnp_port_start(cdev, 0);
  253. else
  254. cport[dev] = -1;
  255. return 0;
  256. }
  257. static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
  258. struct pnp_card_link *card,
  259. const struct pnp_card_device_id *id)
  260. {
  261. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  262. if (acard->wss == NULL)
  263. return -EBUSY;
  264. acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
  265. if (acard->ctrl == NULL)
  266. return -EBUSY;
  267. if (id->devs[2].id[0]) {
  268. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  269. if (acard->mpu == NULL)
  270. return -EBUSY;
  271. }
  272. /* WSS initialization */
  273. if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
  274. return -EBUSY;
  275. /* CTRL initialization */
  276. if (acard->ctrl && cport[dev] > 0) {
  277. if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
  278. return -EBUSY;
  279. }
  280. /* MPU initialization */
  281. if (acard->mpu && mpu_port[dev] > 0) {
  282. if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
  283. return -EBUSY;
  284. }
  285. return 0;
  286. }
  287. #endif /* CONFIG_PNP */
  288. #ifdef CONFIG_PNP
  289. #define is_isapnp_selected(dev) isapnp[dev]
  290. #else
  291. #define is_isapnp_selected(dev) 0
  292. #endif
  293. static int snd_cs423x_card_new(struct device *pdev, int dev,
  294. struct snd_card **cardp)
  295. {
  296. struct snd_card *card;
  297. int err;
  298. err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
  299. sizeof(struct snd_card_cs4236), &card);
  300. if (err < 0)
  301. return err;
  302. *cardp = card;
  303. return 0;
  304. }
  305. static int snd_cs423x_probe(struct snd_card *card, int dev)
  306. {
  307. struct snd_card_cs4236 *acard;
  308. struct snd_wss *chip;
  309. struct snd_opl3 *opl3;
  310. int err;
  311. acard = card->private_data;
  312. if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) {
  313. if (!devm_request_region(card->dev, sb_port[dev], 16,
  314. IDENT " SB")) {
  315. dev_err(card->dev, IDENT ": unable to register SB port at 0x%lx\n",
  316. sb_port[dev]);
  317. return -EBUSY;
  318. }
  319. }
  320. err = snd_cs4236_create(card, port[dev], cport[dev],
  321. irq[dev],
  322. dma1[dev], dma2[dev],
  323. WSS_HW_DETECT3, 0, &chip);
  324. if (err < 0)
  325. return err;
  326. acard->chip = chip;
  327. if (chip->hardware & WSS_HW_CS4236B_MASK) {
  328. err = snd_cs4236_pcm(chip, 0);
  329. if (err < 0)
  330. return err;
  331. err = snd_cs4236_mixer(chip);
  332. if (err < 0)
  333. return err;
  334. } else {
  335. err = snd_wss_pcm(chip, 0);
  336. if (err < 0)
  337. return err;
  338. err = snd_wss_mixer(chip);
  339. if (err < 0)
  340. return err;
  341. }
  342. strscpy(card->driver, chip->pcm->name, sizeof(card->driver));
  343. strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
  344. if (dma2[dev] < 0)
  345. scnprintf(card->longname, sizeof(card->longname),
  346. "%s at 0x%lx, irq %i, dma %i",
  347. chip->pcm->name, chip->port, irq[dev], dma1[dev]);
  348. else
  349. scnprintf(card->longname, sizeof(card->longname),
  350. "%s at 0x%lx, irq %i, dma %i&%d",
  351. chip->pcm->name, chip->port, irq[dev], dma1[dev],
  352. dma2[dev]);
  353. err = snd_wss_timer(chip, 0);
  354. if (err < 0)
  355. return err;
  356. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  357. if (snd_opl3_create(card,
  358. fm_port[dev], fm_port[dev] + 2,
  359. OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
  360. dev_warn(card->dev, IDENT ": OPL3 not detected\n");
  361. } else {
  362. err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  363. if (err < 0)
  364. return err;
  365. }
  366. }
  367. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  368. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  369. mpu_irq[dev] = -1;
  370. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  371. mpu_port[dev], 0,
  372. mpu_irq[dev], NULL) < 0)
  373. dev_warn(card->dev, IDENT ": MPU401 not detected\n");
  374. }
  375. return snd_card_register(card);
  376. }
  377. static int snd_cs423x_isa_match(struct device *pdev,
  378. unsigned int dev)
  379. {
  380. if (!enable[dev] || is_isapnp_selected(dev))
  381. return 0;
  382. if (port[dev] == SNDRV_AUTO_PORT) {
  383. dev_err(pdev, "please specify port\n");
  384. return 0;
  385. }
  386. if (cport[dev] == SNDRV_AUTO_PORT) {
  387. dev_err(pdev, "please specify cport\n");
  388. return 0;
  389. }
  390. if (irq[dev] == SNDRV_AUTO_IRQ) {
  391. dev_err(pdev, "please specify irq\n");
  392. return 0;
  393. }
  394. if (dma1[dev] == SNDRV_AUTO_DMA) {
  395. dev_err(pdev, "please specify dma1\n");
  396. return 0;
  397. }
  398. return 1;
  399. }
  400. static int snd_cs423x_isa_probe(struct device *pdev,
  401. unsigned int dev)
  402. {
  403. struct snd_card *card;
  404. int err;
  405. err = snd_cs423x_card_new(pdev, dev, &card);
  406. if (err < 0)
  407. return err;
  408. err = snd_cs423x_probe(card, dev);
  409. if (err < 0)
  410. return err;
  411. dev_set_drvdata(pdev, card);
  412. return 0;
  413. }
  414. #ifdef CONFIG_PM
  415. static int snd_cs423x_suspend(struct snd_card *card)
  416. {
  417. struct snd_card_cs4236 *acard = card->private_data;
  418. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  419. acard->chip->suspend(acard->chip);
  420. return 0;
  421. }
  422. static int snd_cs423x_resume(struct snd_card *card)
  423. {
  424. struct snd_card_cs4236 *acard = card->private_data;
  425. acard->chip->resume(acard->chip);
  426. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  427. return 0;
  428. }
  429. static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
  430. pm_message_t state)
  431. {
  432. return snd_cs423x_suspend(dev_get_drvdata(dev));
  433. }
  434. static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
  435. {
  436. return snd_cs423x_resume(dev_get_drvdata(dev));
  437. }
  438. #endif
  439. static struct isa_driver cs423x_isa_driver = {
  440. .match = snd_cs423x_isa_match,
  441. .probe = snd_cs423x_isa_probe,
  442. #ifdef CONFIG_PM
  443. .suspend = snd_cs423x_isa_suspend,
  444. .resume = snd_cs423x_isa_resume,
  445. #endif
  446. .driver = {
  447. .name = DEV_NAME
  448. },
  449. };
  450. #ifdef CONFIG_PNP
  451. static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
  452. const struct pnp_device_id *id)
  453. {
  454. static int dev;
  455. int err;
  456. struct snd_card *card;
  457. struct pnp_dev *cdev, *iter;
  458. char cid[PNP_ID_LEN];
  459. if (pnp_device_is_isapnp(pdev))
  460. return -ENOENT; /* we have another procedure - card */
  461. for (; dev < SNDRV_CARDS; dev++) {
  462. if (enable[dev] && isapnp[dev])
  463. break;
  464. }
  465. if (dev >= SNDRV_CARDS)
  466. return -ENODEV;
  467. /* prepare second id */
  468. strcpy(cid, pdev->id[0].id);
  469. cid[5] = '1';
  470. cdev = NULL;
  471. list_for_each_entry(iter, &(pdev->protocol->devices), protocol_list) {
  472. if (!strcmp(iter->id[0].id, cid)) {
  473. cdev = iter;
  474. break;
  475. }
  476. }
  477. err = snd_cs423x_card_new(&pdev->dev, dev, &card);
  478. if (err < 0)
  479. return err;
  480. err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
  481. if (err < 0) {
  482. dev_err(card->dev, "PnP BIOS detection failed for " IDENT "\n");
  483. return err;
  484. }
  485. err = snd_cs423x_probe(card, dev);
  486. if (err < 0)
  487. return err;
  488. pnp_set_drvdata(pdev, card);
  489. dev++;
  490. return 0;
  491. }
  492. #ifdef CONFIG_PM
  493. static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  494. {
  495. return snd_cs423x_suspend(pnp_get_drvdata(pdev));
  496. }
  497. static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
  498. {
  499. return snd_cs423x_resume(pnp_get_drvdata(pdev));
  500. }
  501. #endif
  502. static struct pnp_driver cs423x_pnp_driver = {
  503. .name = "cs423x-pnpbios",
  504. .id_table = snd_cs423x_pnpbiosids,
  505. .probe = snd_cs423x_pnpbios_detect,
  506. #ifdef CONFIG_PM
  507. .suspend = snd_cs423x_pnp_suspend,
  508. .resume = snd_cs423x_pnp_resume,
  509. #endif
  510. };
  511. static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
  512. const struct pnp_card_device_id *pid)
  513. {
  514. static int dev;
  515. struct snd_card *card;
  516. int res;
  517. for ( ; dev < SNDRV_CARDS; dev++) {
  518. if (enable[dev] && isapnp[dev])
  519. break;
  520. }
  521. if (dev >= SNDRV_CARDS)
  522. return -ENODEV;
  523. res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
  524. if (res < 0)
  525. return res;
  526. res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid);
  527. if (res < 0) {
  528. dev_err(card->dev, "isapnp detection failed and probing for " IDENT
  529. " is not supported\n");
  530. return res;
  531. }
  532. res = snd_cs423x_probe(card, dev);
  533. if (res < 0)
  534. return res;
  535. pnp_set_card_drvdata(pcard, card);
  536. dev++;
  537. return 0;
  538. }
  539. #ifdef CONFIG_PM
  540. static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
  541. {
  542. return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
  543. }
  544. static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
  545. {
  546. return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
  547. }
  548. #endif
  549. static struct pnp_card_driver cs423x_pnpc_driver = {
  550. .flags = PNP_DRIVER_RES_DISABLE,
  551. .name = CS423X_ISAPNP_DRIVER,
  552. .id_table = snd_cs423x_pnpids,
  553. .probe = snd_cs423x_pnpc_detect,
  554. #ifdef CONFIG_PM
  555. .suspend = snd_cs423x_pnpc_suspend,
  556. .resume = snd_cs423x_pnpc_resume,
  557. #endif
  558. };
  559. #endif /* CONFIG_PNP */
  560. static int __init alsa_card_cs423x_init(void)
  561. {
  562. int err;
  563. err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
  564. #ifdef CONFIG_PNP
  565. if (!err)
  566. isa_registered = 1;
  567. err = pnp_register_driver(&cs423x_pnp_driver);
  568. if (!err)
  569. pnp_registered = 1;
  570. err = pnp_register_card_driver(&cs423x_pnpc_driver);
  571. if (!err)
  572. pnpc_registered = 1;
  573. if (pnp_registered)
  574. err = 0;
  575. if (isa_registered)
  576. err = 0;
  577. #endif
  578. return err;
  579. }
  580. static void __exit alsa_card_cs423x_exit(void)
  581. {
  582. #ifdef CONFIG_PNP
  583. if (pnpc_registered)
  584. pnp_unregister_card_driver(&cs423x_pnpc_driver);
  585. if (pnp_registered)
  586. pnp_unregister_driver(&cs423x_pnp_driver);
  587. if (isa_registered)
  588. #endif
  589. isa_unregister_driver(&cs423x_isa_driver);
  590. }
  591. module_init(alsa_card_cs423x_init)
  592. module_exit(alsa_card_cs423x_exit)