ad1816a.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. card-ad1816a.c - driver for ADI SoundPort AD1816A based soundcards.
  3. Copyright (C) 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. #include <linux/init.h>
  17. #include <linux/time.h>
  18. #include <linux/wait.h>
  19. #include <linux/pnp.h>
  20. #include <linux/module.h>
  21. #include <sound/core.h>
  22. #include <sound/initval.h>
  23. #include <sound/ad1816a.h>
  24. #include <sound/mpu401.h>
  25. #include <sound/opl3.h>
  26. #define PFX "ad1816a: "
  27. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  28. MODULE_DESCRIPTION("AD1816A, AD1815");
  29. MODULE_LICENSE("GPL");
  30. MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
  31. "{Analog Devices,AD1815},"
  32. "{Analog Devices,AD1816A},"
  33. "{TerraTec,Base 64},"
  34. "{TerraTec,AudioSystem EWS64S},"
  35. "{Aztech/Newcom SC-16 3D},"
  36. "{Shark Predator ISA}}");
  37. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
  38. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  39. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  40. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  41. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  42. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  43. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  44. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  45. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  46. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  47. static int clockfreq[SNDRV_CARDS];
  48. module_param_array(index, int, NULL, 0444);
  49. MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
  50. module_param_array(id, charp, NULL, 0444);
  51. MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
  52. module_param_array(enable, bool, NULL, 0444);
  53. MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
  54. module_param_array(clockfreq, int, NULL, 0444);
  55. MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0).");
  56. struct snd_card_ad1816a {
  57. struct pnp_dev *dev;
  58. struct pnp_dev *devmpu;
  59. };
  60. static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
  61. /* Analog Devices AD1815 */
  62. { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
  63. /* Analog Device AD1816? */
  64. { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  65. /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
  66. { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  67. /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
  68. { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
  69. /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
  70. { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  71. /* Highscreen Sound-Boostar 16 3D */
  72. { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  73. /* Shark Predator ISA - added by Ken Arromdee */
  74. { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  75. /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
  76. { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  77. /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
  78. { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } },
  79. /* Analog Devices AD1816A - Terratec Base 64 */
  80. { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  81. /* end */
  82. { .id = "" }
  83. };
  84. MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
  85. #define DRIVER_NAME "snd-card-ad1816a"
  86. static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *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 -EBUSY;
  95. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
  96. if (acard->devmpu == NULL) {
  97. mpu_port[dev] = -1;
  98. snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
  99. }
  100. pdev = acard->dev;
  101. err = pnp_activate_dev(pdev);
  102. if (err < 0) {
  103. printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
  104. return -EBUSY;
  105. }
  106. port[dev] = pnp_port_start(pdev, 2);
  107. fm_port[dev] = pnp_port_start(pdev, 1);
  108. dma1[dev] = pnp_dma(pdev, 0);
  109. dma2[dev] = pnp_dma(pdev, 1);
  110. irq[dev] = pnp_irq(pdev, 0);
  111. if (acard->devmpu == NULL)
  112. return 0;
  113. pdev = acard->devmpu;
  114. err = pnp_activate_dev(pdev);
  115. if (err < 0) {
  116. printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
  117. mpu_port[dev] = -1;
  118. acard->devmpu = NULL;
  119. } else {
  120. mpu_port[dev] = pnp_port_start(pdev, 0);
  121. mpu_irq[dev] = pnp_irq(pdev, 0);
  122. }
  123. return 0;
  124. }
  125. static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
  126. const struct pnp_card_device_id *pid)
  127. {
  128. int error;
  129. struct snd_card *card;
  130. struct snd_card_ad1816a *acard;
  131. struct snd_ad1816a *chip;
  132. struct snd_opl3 *opl3;
  133. struct snd_timer *timer;
  134. error = snd_card_create(index[dev], id[dev], THIS_MODULE,
  135. sizeof(struct snd_card_ad1816a), &card);
  136. if (error < 0)
  137. return error;
  138. acard = card->private_data;
  139. if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
  140. snd_card_free(card);
  141. return error;
  142. }
  143. snd_card_set_dev(card, &pcard->card->dev);
  144. if ((error = snd_ad1816a_create(card, port[dev],
  145. irq[dev],
  146. dma1[dev],
  147. dma2[dev],
  148. &chip)) < 0) {
  149. snd_card_free(card);
  150. return error;
  151. }
  152. if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
  153. chip->clock_freq = clockfreq[dev];
  154. strcpy(card->driver, "AD1816A");
  155. strcpy(card->shortname, "ADI SoundPort AD1816A");
  156. sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
  157. card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
  158. if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
  159. snd_card_free(card);
  160. return error;
  161. }
  162. if ((error = snd_ad1816a_mixer(chip)) < 0) {
  163. snd_card_free(card);
  164. return error;
  165. }
  166. error = snd_ad1816a_timer(chip, 0, &timer);
  167. if (error < 0) {
  168. snd_card_free(card);
  169. return error;
  170. }
  171. if (mpu_port[dev] > 0) {
  172. if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  173. mpu_port[dev], 0, mpu_irq[dev],
  174. NULL) < 0)
  175. printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
  176. }
  177. if (fm_port[dev] > 0) {
  178. if (snd_opl3_create(card,
  179. fm_port[dev], fm_port[dev] + 2,
  180. OPL3_HW_AUTO, 0, &opl3) < 0) {
  181. printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
  182. } else {
  183. error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  184. if (error < 0) {
  185. snd_card_free(card);
  186. return error;
  187. }
  188. }
  189. }
  190. if ((error = snd_card_register(card)) < 0) {
  191. snd_card_free(card);
  192. return error;
  193. }
  194. pnp_set_card_drvdata(pcard, card);
  195. return 0;
  196. }
  197. static unsigned int __devinitdata ad1816a_devices;
  198. static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
  199. const struct pnp_card_device_id *id)
  200. {
  201. static int dev;
  202. int res;
  203. for ( ; dev < SNDRV_CARDS; dev++) {
  204. if (!enable[dev])
  205. continue;
  206. res = snd_card_ad1816a_probe(dev, card, id);
  207. if (res < 0)
  208. return res;
  209. dev++;
  210. ad1816a_devices++;
  211. return 0;
  212. }
  213. return -ENODEV;
  214. }
  215. static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
  216. {
  217. snd_card_free(pnp_get_card_drvdata(pcard));
  218. pnp_set_card_drvdata(pcard, NULL);
  219. }
  220. static struct pnp_card_driver ad1816a_pnpc_driver = {
  221. .flags = PNP_DRIVER_RES_DISABLE,
  222. .name = "ad1816a",
  223. .id_table = snd_ad1816a_pnpids,
  224. .probe = snd_ad1816a_pnp_detect,
  225. .remove = __devexit_p(snd_ad1816a_pnp_remove),
  226. /* FIXME: suspend/resume */
  227. };
  228. static int __init alsa_card_ad1816a_init(void)
  229. {
  230. int err;
  231. err = pnp_register_card_driver(&ad1816a_pnpc_driver);
  232. if (err)
  233. return err;
  234. if (!ad1816a_devices) {
  235. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  236. #ifdef MODULE
  237. printk(KERN_ERR "no AD1816A based soundcards found.\n");
  238. #endif /* MODULE */
  239. return -ENODEV;
  240. }
  241. return 0;
  242. }
  243. static void __exit alsa_card_ad1816a_exit(void)
  244. {
  245. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  246. }
  247. module_init(alsa_card_ad1816a_init)
  248. module_exit(alsa_card_ad1816a_exit)