azt2320.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. card-azt2320.c - driver for Aztech Systems AZT2320 based soundcards.
  3. Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. /*
  17. This driver should provide support for most Aztech AZT2320 based cards.
  18. Several AZT2316 chips are also supported/tested, but autoprobe doesn't
  19. work: all module option have to be set.
  20. No docs available for us at Aztech headquarters !!! Unbelievable ...
  21. No other help obtained.
  22. Thanks to Rainer Wiesner <rainer.wiesner@01019freenet.de> for the WSS
  23. activation method (full-duplex audio!).
  24. */
  25. #include <sound/driver.h>
  26. #include <asm/io.h>
  27. #include <linux/delay.h>
  28. #include <linux/init.h>
  29. #include <linux/time.h>
  30. #include <linux/wait.h>
  31. #include <linux/pnp.h>
  32. #include <linux/moduleparam.h>
  33. #include <sound/core.h>
  34. #include <sound/initval.h>
  35. #include <sound/cs4231.h>
  36. #include <sound/mpu401.h>
  37. #include <sound/opl3.h>
  38. #define PFX "azt2320: "
  39. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  40. MODULE_DESCRIPTION("Aztech Systems AZT2320");
  41. MODULE_LICENSE("GPL");
  42. MODULE_SUPPORTED_DEVICE("{{Aztech Systems,PRO16V},"
  43. "{Aztech Systems,AZT2320},"
  44. "{Aztech Systems,AZT3300},"
  45. "{Aztech Systems,AZT2320},"
  46. "{Aztech Systems,AZT3000}}");
  47. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  48. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  49. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  50. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  51. static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  52. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  53. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  54. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  55. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  56. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  57. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  58. module_param_array(index, int, NULL, 0444);
  59. MODULE_PARM_DESC(index, "Index value for azt2320 based soundcard.");
  60. module_param_array(id, charp, NULL, 0444);
  61. MODULE_PARM_DESC(id, "ID string for azt2320 based soundcard.");
  62. module_param_array(enable, bool, NULL, 0444);
  63. MODULE_PARM_DESC(enable, "Enable azt2320 based soundcard.");
  64. module_param_array(port, long, NULL, 0444);
  65. MODULE_PARM_DESC(port, "Port # for azt2320 driver.");
  66. module_param_array(wss_port, long, NULL, 0444);
  67. MODULE_PARM_DESC(wss_port, "WSS Port # for azt2320 driver.");
  68. module_param_array(mpu_port, long, NULL, 0444);
  69. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for azt2320 driver.");
  70. module_param_array(fm_port, long, NULL, 0444);
  71. MODULE_PARM_DESC(fm_port, "FM port # for azt2320 driver.");
  72. module_param_array(irq, int, NULL, 0444);
  73. MODULE_PARM_DESC(irq, "IRQ # for azt2320 driver.");
  74. module_param_array(mpu_irq, int, NULL, 0444);
  75. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for azt2320 driver.");
  76. module_param_array(dma1, int, NULL, 0444);
  77. MODULE_PARM_DESC(dma1, "1st DMA # for azt2320 driver.");
  78. module_param_array(dma2, int, NULL, 0444);
  79. MODULE_PARM_DESC(dma2, "2nd DMA # for azt2320 driver.");
  80. struct snd_card_azt2320 {
  81. int dev_no;
  82. struct pnp_dev *dev;
  83. struct pnp_dev *devmpu;
  84. struct snd_cs4231 *chip;
  85. };
  86. static struct pnp_card_device_id snd_azt2320_pnpids[] = {
  87. /* PRO16V */
  88. { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
  89. /* Aztech Sound Galaxy 16 */
  90. { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
  91. /* Packard Bell Sound III 336 AM/SP */
  92. { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  93. /* AT3300 */
  94. { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
  95. /* --- */
  96. { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  97. /* --- */
  98. { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  99. { .id = "" } /* end */
  100. };
  101. MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
  102. #define DRIVER_NAME "snd-card-azt2320"
  103. static int __devinit snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
  104. struct pnp_card_link *card,
  105. const struct pnp_card_device_id *id)
  106. {
  107. struct pnp_dev *pdev;
  108. struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
  109. int err;
  110. if (!cfg)
  111. return -ENOMEM;
  112. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  113. if (acard->dev == NULL) {
  114. kfree(cfg);
  115. return -ENODEV;
  116. }
  117. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
  118. pdev = acard->dev;
  119. pnp_init_resource_table(cfg);
  120. /* override resources */
  121. if (port[dev] != SNDRV_AUTO_PORT)
  122. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  123. if (fm_port[dev] != SNDRV_AUTO_PORT)
  124. pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
  125. if (wss_port[dev] != SNDRV_AUTO_PORT)
  126. pnp_resource_change(&cfg->port_resource[2], wss_port[dev], 4);
  127. if (dma1[dev] != SNDRV_AUTO_DMA)
  128. pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
  129. if (dma2[dev] != SNDRV_AUTO_DMA)
  130. pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
  131. if (irq[dev] != SNDRV_AUTO_IRQ)
  132. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  133. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  134. snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
  135. err = pnp_activate_dev(pdev);
  136. if (err < 0) {
  137. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  138. kfree(cfg);
  139. return err;
  140. }
  141. port[dev] = pnp_port_start(pdev, 0);
  142. fm_port[dev] = pnp_port_start(pdev, 1);
  143. wss_port[dev] = pnp_port_start(pdev, 2);
  144. dma1[dev] = pnp_dma(pdev, 0);
  145. dma2[dev] = pnp_dma(pdev, 1);
  146. irq[dev] = pnp_irq(pdev, 0);
  147. pdev = acard->devmpu;
  148. if (pdev != NULL) {
  149. pnp_init_resource_table(cfg);
  150. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  151. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  152. if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
  153. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  154. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  155. snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
  156. err = pnp_activate_dev(pdev);
  157. if (err < 0)
  158. goto __mpu_error;
  159. mpu_port[dev] = pnp_port_start(pdev, 0);
  160. mpu_irq[dev] = pnp_irq(pdev, 0);
  161. } else {
  162. __mpu_error:
  163. if (pdev) {
  164. pnp_release_card_device(pdev);
  165. snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
  166. }
  167. acard->devmpu = NULL;
  168. mpu_port[dev] = -1;
  169. }
  170. kfree (cfg);
  171. return 0;
  172. }
  173. /* same of snd_sbdsp_command by Jaroslav Kysela */
  174. static int __devinit snd_card_azt2320_command(unsigned long port, unsigned char val)
  175. {
  176. int i;
  177. unsigned long limit;
  178. limit = jiffies + HZ / 10;
  179. for (i = 50000; i && time_after(limit, jiffies); i--)
  180. if (!(inb(port + 0x0c) & 0x80)) {
  181. outb(val, port + 0x0c);
  182. return 0;
  183. }
  184. return -EBUSY;
  185. }
  186. static int __devinit snd_card_azt2320_enable_wss(unsigned long port)
  187. {
  188. int error;
  189. if ((error = snd_card_azt2320_command(port, 0x09)))
  190. return error;
  191. if ((error = snd_card_azt2320_command(port, 0x00)))
  192. return error;
  193. mdelay(5);
  194. return 0;
  195. }
  196. static int __devinit snd_card_azt2320_probe(int dev,
  197. struct pnp_card_link *pcard,
  198. const struct pnp_card_device_id *pid)
  199. {
  200. int error;
  201. struct snd_card *card;
  202. struct snd_card_azt2320 *acard;
  203. struct snd_cs4231 *chip;
  204. struct snd_opl3 *opl3;
  205. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  206. sizeof(struct snd_card_azt2320))) == NULL)
  207. return -ENOMEM;
  208. acard = (struct snd_card_azt2320 *)card->private_data;
  209. if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
  210. snd_card_free(card);
  211. return error;
  212. }
  213. snd_card_set_dev(card, &pcard->card->dev);
  214. if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
  215. snd_card_free(card);
  216. return error;
  217. }
  218. if ((error = snd_cs4231_create(card, wss_port[dev], -1,
  219. irq[dev],
  220. dma1[dev],
  221. dma2[dev],
  222. CS4231_HW_DETECT, 0, &chip)) < 0) {
  223. snd_card_free(card);
  224. return error;
  225. }
  226. strcpy(card->driver, "AZT2320");
  227. strcpy(card->shortname, "Aztech AZT2320");
  228. sprintf(card->longname, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
  229. card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
  230. if ((error = snd_cs4231_pcm(chip, 0, NULL)) < 0) {
  231. snd_card_free(card);
  232. return error;
  233. }
  234. if ((error = snd_cs4231_mixer(chip)) < 0) {
  235. snd_card_free(card);
  236. return error;
  237. }
  238. if ((error = snd_cs4231_timer(chip, 0, NULL)) < 0) {
  239. snd_card_free(card);
  240. return error;
  241. }
  242. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  243. if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
  244. mpu_port[dev], 0,
  245. mpu_irq[dev], SA_INTERRUPT,
  246. NULL) < 0)
  247. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  248. }
  249. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  250. if (snd_opl3_create(card,
  251. fm_port[dev], fm_port[dev] + 2,
  252. OPL3_HW_AUTO, 0, &opl3) < 0) {
  253. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  254. fm_port[dev], fm_port[dev] + 2);
  255. } else {
  256. if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
  257. snd_card_free(card);
  258. return error;
  259. }
  260. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  261. snd_card_free(card);
  262. return error;
  263. }
  264. }
  265. }
  266. if ((error = snd_card_register(card)) < 0) {
  267. snd_card_free(card);
  268. return error;
  269. }
  270. pnp_set_card_drvdata(pcard, card);
  271. return 0;
  272. }
  273. static int __devinit snd_azt2320_pnp_detect(struct pnp_card_link *card,
  274. const struct pnp_card_device_id *id)
  275. {
  276. static int dev;
  277. int res;
  278. for ( ; dev < SNDRV_CARDS; dev++) {
  279. if (!enable[dev])
  280. continue;
  281. res = snd_card_azt2320_probe(dev, card, id);
  282. if (res < 0)
  283. return res;
  284. dev++;
  285. return 0;
  286. }
  287. return -ENODEV;
  288. }
  289. static void __devexit snd_azt2320_pnp_remove(struct pnp_card_link * pcard)
  290. {
  291. snd_card_free(pnp_get_card_drvdata(pcard));
  292. pnp_set_card_drvdata(pcard, NULL);
  293. }
  294. #ifdef CONFIG_PM
  295. static int snd_azt2320_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  296. {
  297. struct snd_card *card = pnp_get_card_drvdata(pcard);
  298. struct snd_card_azt2320 *acard = card->private_data;
  299. struct snd_cs4231 *chip = acard->chip;
  300. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  301. chip->suspend(chip);
  302. return 0;
  303. }
  304. static int snd_azt2320_pnp_resume(struct pnp_card_link *pcard)
  305. {
  306. struct snd_card *card = pnp_get_card_drvdata(pcard);
  307. struct snd_card_azt2320 *acard = card->private_data;
  308. struct snd_cs4231 *chip = acard->chip;
  309. chip->resume(chip);
  310. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  311. return 0;
  312. }
  313. #endif
  314. static struct pnp_card_driver azt2320_pnpc_driver = {
  315. .flags = PNP_DRIVER_RES_DISABLE,
  316. .name = "azt2320",
  317. .id_table = snd_azt2320_pnpids,
  318. .probe = snd_azt2320_pnp_detect,
  319. .remove = __devexit_p(snd_azt2320_pnp_remove),
  320. #ifdef CONFIG_PM
  321. .suspend = snd_azt2320_pnp_suspend,
  322. .resume = snd_azt2320_pnp_resume,
  323. #endif
  324. };
  325. static int __init alsa_card_azt2320_init(void)
  326. {
  327. int cards;
  328. cards = pnp_register_card_driver(&azt2320_pnpc_driver);
  329. if (cards <= 0) {
  330. pnp_unregister_card_driver(&azt2320_pnpc_driver);
  331. #ifdef MODULE
  332. snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
  333. #endif
  334. return -ENODEV;
  335. }
  336. return 0;
  337. }
  338. static void __exit alsa_card_azt2320_exit(void)
  339. {
  340. pnp_unregister_card_driver(&azt2320_pnpc_driver);
  341. }
  342. module_init(alsa_card_azt2320_init)
  343. module_exit(alsa_card_azt2320_exit)