ad1816a.c 8.5 KB

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