azt2320.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 <linux/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/init.h>
  28. #include <linux/time.h>
  29. #include <linux/wait.h>
  30. #include <linux/pnp.h>
  31. #include <linux/module.h>
  32. #include <sound/core.h>
  33. #include <sound/initval.h>
  34. #include <sound/wss.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/opl3.h>
  37. #define PFX "azt2320: "
  38. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  39. MODULE_DESCRIPTION("Aztech Systems AZT2320");
  40. MODULE_LICENSE("GPL");
  41. MODULE_SUPPORTED_DEVICE("{{Aztech Systems,PRO16V},"
  42. "{Aztech Systems,AZT2320},"
  43. "{Aztech Systems,AZT3300},"
  44. "{Aztech Systems,AZT2320},"
  45. "{Aztech Systems,AZT3000}}");
  46. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  47. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  48. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  49. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  50. static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  51. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  52. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  53. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  54. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  55. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  56. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  57. module_param_array(index, int, NULL, 0444);
  58. MODULE_PARM_DESC(index, "Index value for azt2320 based soundcard.");
  59. module_param_array(id, charp, NULL, 0444);
  60. MODULE_PARM_DESC(id, "ID string for azt2320 based soundcard.");
  61. module_param_array(enable, bool, NULL, 0444);
  62. MODULE_PARM_DESC(enable, "Enable azt2320 based soundcard.");
  63. struct snd_card_azt2320 {
  64. int dev_no;
  65. struct pnp_dev *dev;
  66. struct pnp_dev *devmpu;
  67. struct snd_wss *chip;
  68. };
  69. static struct pnp_card_device_id snd_azt2320_pnpids[] = {
  70. /* PRO16V */
  71. { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
  72. /* Aztech Sound Galaxy 16 */
  73. { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
  74. /* Packard Bell Sound III 336 AM/SP */
  75. { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  76. /* AT3300 */
  77. { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
  78. /* --- */
  79. { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  80. /* --- */
  81. { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
  82. { .id = "" } /* end */
  83. };
  84. MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
  85. #define DRIVER_NAME "snd-card-azt2320"
  86. static int snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
  87. struct pnp_card_link *card,
  88. const struct pnp_card_device_id *id)
  89. {
  90. struct pnp_dev *pdev;
  91. int err;
  92. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  93. if (acard->dev == NULL)
  94. return -ENODEV;
  95. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
  96. pdev = acard->dev;
  97. err = pnp_activate_dev(pdev);
  98. if (err < 0) {
  99. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  100. return err;
  101. }
  102. port[dev] = pnp_port_start(pdev, 0);
  103. fm_port[dev] = pnp_port_start(pdev, 1);
  104. wss_port[dev] = pnp_port_start(pdev, 2);
  105. dma1[dev] = pnp_dma(pdev, 0);
  106. dma2[dev] = pnp_dma(pdev, 1);
  107. irq[dev] = pnp_irq(pdev, 0);
  108. pdev = acard->devmpu;
  109. if (pdev != NULL) {
  110. err = pnp_activate_dev(pdev);
  111. if (err < 0)
  112. goto __mpu_error;
  113. mpu_port[dev] = pnp_port_start(pdev, 0);
  114. mpu_irq[dev] = pnp_irq(pdev, 0);
  115. } else {
  116. __mpu_error:
  117. if (pdev) {
  118. pnp_release_card_device(pdev);
  119. snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
  120. }
  121. acard->devmpu = NULL;
  122. mpu_port[dev] = -1;
  123. }
  124. return 0;
  125. }
  126. /* same of snd_sbdsp_command by Jaroslav Kysela */
  127. static int snd_card_azt2320_command(unsigned long port, unsigned char val)
  128. {
  129. int i;
  130. unsigned long limit;
  131. limit = jiffies + HZ / 10;
  132. for (i = 50000; i && time_after(limit, jiffies); i--)
  133. if (!(inb(port + 0x0c) & 0x80)) {
  134. outb(val, port + 0x0c);
  135. return 0;
  136. }
  137. return -EBUSY;
  138. }
  139. static int snd_card_azt2320_enable_wss(unsigned long port)
  140. {
  141. int error;
  142. if ((error = snd_card_azt2320_command(port, 0x09)))
  143. return error;
  144. if ((error = snd_card_azt2320_command(port, 0x00)))
  145. return error;
  146. mdelay(5);
  147. return 0;
  148. }
  149. static int snd_card_azt2320_probe(int dev,
  150. struct pnp_card_link *pcard,
  151. const struct pnp_card_device_id *pid)
  152. {
  153. int error;
  154. struct snd_card *card;
  155. struct snd_card_azt2320 *acard;
  156. struct snd_wss *chip;
  157. struct snd_opl3 *opl3;
  158. error = snd_card_new(&pcard->card->dev,
  159. index[dev], id[dev], THIS_MODULE,
  160. sizeof(struct snd_card_azt2320), &card);
  161. if (error < 0)
  162. return error;
  163. acard = card->private_data;
  164. if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
  165. snd_card_free(card);
  166. return error;
  167. }
  168. if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
  169. snd_card_free(card);
  170. return error;
  171. }
  172. error = snd_wss_create(card, wss_port[dev], -1,
  173. irq[dev],
  174. dma1[dev], dma2[dev],
  175. WSS_HW_DETECT, 0, &chip);
  176. if (error < 0) {
  177. snd_card_free(card);
  178. return error;
  179. }
  180. strcpy(card->driver, "AZT2320");
  181. strcpy(card->shortname, "Aztech AZT2320");
  182. sprintf(card->longname, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
  183. card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
  184. error = snd_wss_pcm(chip, 0);
  185. if (error < 0) {
  186. snd_card_free(card);
  187. return error;
  188. }
  189. error = snd_wss_mixer(chip);
  190. if (error < 0) {
  191. snd_card_free(card);
  192. return error;
  193. }
  194. error = snd_wss_timer(chip, 0);
  195. if (error < 0) {
  196. snd_card_free(card);
  197. return error;
  198. }
  199. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  200. if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
  201. mpu_port[dev], 0,
  202. mpu_irq[dev], NULL) < 0)
  203. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  204. }
  205. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  206. if (snd_opl3_create(card,
  207. fm_port[dev], fm_port[dev] + 2,
  208. OPL3_HW_AUTO, 0, &opl3) < 0) {
  209. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  210. fm_port[dev], fm_port[dev] + 2);
  211. } else {
  212. if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
  213. snd_card_free(card);
  214. return error;
  215. }
  216. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  217. snd_card_free(card);
  218. return error;
  219. }
  220. }
  221. }
  222. if ((error = snd_card_register(card)) < 0) {
  223. snd_card_free(card);
  224. return error;
  225. }
  226. pnp_set_card_drvdata(pcard, card);
  227. return 0;
  228. }
  229. static unsigned int azt2320_devices;
  230. static int snd_azt2320_pnp_detect(struct pnp_card_link *card,
  231. const struct pnp_card_device_id *id)
  232. {
  233. static int dev;
  234. int res;
  235. for ( ; dev < SNDRV_CARDS; dev++) {
  236. if (!enable[dev])
  237. continue;
  238. res = snd_card_azt2320_probe(dev, card, id);
  239. if (res < 0)
  240. return res;
  241. dev++;
  242. azt2320_devices++;
  243. return 0;
  244. }
  245. return -ENODEV;
  246. }
  247. static void snd_azt2320_pnp_remove(struct pnp_card_link *pcard)
  248. {
  249. snd_card_free(pnp_get_card_drvdata(pcard));
  250. pnp_set_card_drvdata(pcard, NULL);
  251. }
  252. #ifdef CONFIG_PM
  253. static int snd_azt2320_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  254. {
  255. struct snd_card *card = pnp_get_card_drvdata(pcard);
  256. struct snd_card_azt2320 *acard = card->private_data;
  257. struct snd_wss *chip = acard->chip;
  258. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  259. chip->suspend(chip);
  260. return 0;
  261. }
  262. static int snd_azt2320_pnp_resume(struct pnp_card_link *pcard)
  263. {
  264. struct snd_card *card = pnp_get_card_drvdata(pcard);
  265. struct snd_card_azt2320 *acard = card->private_data;
  266. struct snd_wss *chip = acard->chip;
  267. chip->resume(chip);
  268. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  269. return 0;
  270. }
  271. #endif
  272. static struct pnp_card_driver azt2320_pnpc_driver = {
  273. .flags = PNP_DRIVER_RES_DISABLE,
  274. .name = "azt2320",
  275. .id_table = snd_azt2320_pnpids,
  276. .probe = snd_azt2320_pnp_detect,
  277. .remove = snd_azt2320_pnp_remove,
  278. #ifdef CONFIG_PM
  279. .suspend = snd_azt2320_pnp_suspend,
  280. .resume = snd_azt2320_pnp_resume,
  281. #endif
  282. };
  283. static int __init alsa_card_azt2320_init(void)
  284. {
  285. int err;
  286. err = pnp_register_card_driver(&azt2320_pnpc_driver);
  287. if (err)
  288. return err;
  289. if (!azt2320_devices) {
  290. pnp_unregister_card_driver(&azt2320_pnpc_driver);
  291. #ifdef MODULE
  292. snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
  293. #endif
  294. return -ENODEV;
  295. }
  296. return 0;
  297. }
  298. static void __exit alsa_card_azt2320_exit(void)
  299. {
  300. pnp_unregister_card_driver(&azt2320_pnpc_driver);
  301. }
  302. module_init(alsa_card_azt2320_init)
  303. module_exit(alsa_card_azt2320_exit)