ad1816a.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/moduleparam.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 int 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 EWS64S */
  76. { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  77. /* Analog Devices AD1816A - Terratec Base 64 */
  78. { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  79. /* end */
  80. { .id = "" }
  81. };
  82. MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
  83. #define DRIVER_NAME "snd-card-ad1816a"
  84. static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
  85. struct pnp_card_link *card,
  86. const struct pnp_card_device_id *id)
  87. {
  88. struct pnp_dev *pdev;
  89. int err;
  90. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  91. if (acard->dev == NULL)
  92. return -EBUSY;
  93. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
  94. if (acard->devmpu == NULL) {
  95. mpu_port[dev] = -1;
  96. snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
  97. }
  98. pdev = acard->dev;
  99. err = pnp_activate_dev(pdev);
  100. if (err < 0) {
  101. printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
  102. return -EBUSY;
  103. }
  104. port[dev] = pnp_port_start(pdev, 2);
  105. fm_port[dev] = pnp_port_start(pdev, 1);
  106. dma1[dev] = pnp_dma(pdev, 0);
  107. dma2[dev] = pnp_dma(pdev, 1);
  108. irq[dev] = pnp_irq(pdev, 0);
  109. if (acard->devmpu == NULL)
  110. return 0;
  111. pdev = acard->devmpu;
  112. err = pnp_activate_dev(pdev);
  113. if (err < 0) {
  114. printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
  115. mpu_port[dev] = -1;
  116. acard->devmpu = NULL;
  117. } else {
  118. mpu_port[dev] = pnp_port_start(pdev, 0);
  119. mpu_irq[dev] = pnp_irq(pdev, 0);
  120. }
  121. return 0;
  122. }
  123. static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
  124. const struct pnp_card_device_id *pid)
  125. {
  126. int error;
  127. struct snd_card *card;
  128. struct snd_card_ad1816a *acard;
  129. struct snd_ad1816a *chip;
  130. struct snd_opl3 *opl3;
  131. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  132. sizeof(struct snd_card_ad1816a))) == NULL)
  133. return -ENOMEM;
  134. acard = (struct snd_card_ad1816a *)card->private_data;
  135. if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
  136. snd_card_free(card);
  137. return error;
  138. }
  139. snd_card_set_dev(card, &pcard->card->dev);
  140. if ((error = snd_ad1816a_create(card, port[dev],
  141. irq[dev],
  142. dma1[dev],
  143. dma2[dev],
  144. &chip)) < 0) {
  145. snd_card_free(card);
  146. return error;
  147. }
  148. if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
  149. chip->clock_freq = clockfreq[dev];
  150. strcpy(card->driver, "AD1816A");
  151. strcpy(card->shortname, "ADI SoundPort AD1816A");
  152. sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
  153. card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
  154. if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
  155. snd_card_free(card);
  156. return error;
  157. }
  158. if ((error = snd_ad1816a_mixer(chip)) < 0) {
  159. snd_card_free(card);
  160. return error;
  161. }
  162. if (mpu_port[dev] > 0) {
  163. if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  164. mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
  165. NULL) < 0)
  166. printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
  167. }
  168. if (fm_port[dev] > 0) {
  169. if (snd_opl3_create(card,
  170. fm_port[dev], fm_port[dev] + 2,
  171. OPL3_HW_AUTO, 0, &opl3) < 0) {
  172. printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
  173. } else {
  174. if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
  175. snd_card_free(card);
  176. return error;
  177. }
  178. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  179. snd_card_free(card);
  180. return error;
  181. }
  182. }
  183. }
  184. if ((error = snd_card_register(card)) < 0) {
  185. snd_card_free(card);
  186. return error;
  187. }
  188. pnp_set_card_drvdata(pcard, card);
  189. return 0;
  190. }
  191. static unsigned int __devinitdata ad1816a_devices;
  192. static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
  193. const struct pnp_card_device_id *id)
  194. {
  195. static int dev;
  196. int res;
  197. for ( ; dev < SNDRV_CARDS; dev++) {
  198. if (!enable[dev])
  199. continue;
  200. res = snd_card_ad1816a_probe(dev, card, id);
  201. if (res < 0)
  202. return res;
  203. dev++;
  204. ad1816a_devices++;
  205. return 0;
  206. }
  207. return -ENODEV;
  208. }
  209. static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
  210. {
  211. snd_card_free(pnp_get_card_drvdata(pcard));
  212. pnp_set_card_drvdata(pcard, NULL);
  213. }
  214. static struct pnp_card_driver ad1816a_pnpc_driver = {
  215. .flags = PNP_DRIVER_RES_DISABLE,
  216. .name = "ad1816a",
  217. .id_table = snd_ad1816a_pnpids,
  218. .probe = snd_ad1816a_pnp_detect,
  219. .remove = __devexit_p(snd_ad1816a_pnp_remove),
  220. /* FIXME: suspend/resume */
  221. };
  222. static int __init alsa_card_ad1816a_init(void)
  223. {
  224. int err;
  225. err = pnp_register_card_driver(&ad1816a_pnpc_driver);
  226. if (err)
  227. return err;
  228. if (!ad1816a_devices) {
  229. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  230. #ifdef MODULE
  231. printk(KERN_ERR "no AD1816A based soundcards found.\n");
  232. #endif /* MODULE */
  233. return -ENODEV;
  234. }
  235. return 0;
  236. }
  237. static void __exit alsa_card_ad1816a_exit(void)
  238. {
  239. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  240. }
  241. module_init(alsa_card_ad1816a_init)
  242. module_exit(alsa_card_ad1816a_exit)