ad1816a.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
  57. /* Analog Devices AD1815 */
  58. { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
  59. /* Analog Device AD1816? */
  60. { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  61. /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
  62. { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  63. /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
  64. { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
  65. /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
  66. { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  67. /* Highscreen Sound-Boostar 16 3D */
  68. { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  69. /* Shark Predator ISA - added by Ken Arromdee */
  70. { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  71. /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
  72. { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  73. /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
  74. { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } },
  75. /* Analog Devices AD1816A - Terratec Base 64 */
  76. { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
  77. /* end */
  78. { .id = "" }
  79. };
  80. MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
  81. #define DRIVER_NAME "snd-card-ad1816a"
  82. static int snd_card_ad1816a_pnp(int dev, struct pnp_card_link *card,
  83. const struct pnp_card_device_id *id)
  84. {
  85. struct pnp_dev *pdev;
  86. int err;
  87. pdev = pnp_request_card_device(card, id->devs[0].id, NULL);
  88. if (pdev == NULL)
  89. return -EBUSY;
  90. err = pnp_activate_dev(pdev);
  91. if (err < 0) {
  92. printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
  93. return -EBUSY;
  94. }
  95. port[dev] = pnp_port_start(pdev, 2);
  96. fm_port[dev] = pnp_port_start(pdev, 1);
  97. dma1[dev] = pnp_dma(pdev, 0);
  98. dma2[dev] = pnp_dma(pdev, 1);
  99. irq[dev] = pnp_irq(pdev, 0);
  100. pdev = pnp_request_card_device(card, id->devs[1].id, NULL);
  101. if (pdev == NULL) {
  102. mpu_port[dev] = -1;
  103. snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
  104. return 0;
  105. }
  106. err = pnp_activate_dev(pdev);
  107. if (err < 0) {
  108. printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
  109. mpu_port[dev] = -1;
  110. } else {
  111. mpu_port[dev] = pnp_port_start(pdev, 0);
  112. mpu_irq[dev] = pnp_irq(pdev, 0);
  113. }
  114. return 0;
  115. }
  116. static int snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
  117. const struct pnp_card_device_id *pid)
  118. {
  119. int error;
  120. struct snd_card *card;
  121. struct snd_ad1816a *chip;
  122. struct snd_opl3 *opl3;
  123. error = snd_card_new(&pcard->card->dev,
  124. index[dev], id[dev], THIS_MODULE,
  125. sizeof(struct snd_ad1816a), &card);
  126. if (error < 0)
  127. return error;
  128. chip = card->private_data;
  129. if ((error = snd_card_ad1816a_pnp(dev, pcard, pid))) {
  130. snd_card_free(card);
  131. return error;
  132. }
  133. if ((error = snd_ad1816a_create(card, port[dev],
  134. irq[dev],
  135. dma1[dev],
  136. dma2[dev],
  137. chip)) < 0) {
  138. snd_card_free(card);
  139. return error;
  140. }
  141. if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
  142. chip->clock_freq = clockfreq[dev];
  143. strcpy(card->driver, "AD1816A");
  144. strcpy(card->shortname, "ADI SoundPort AD1816A");
  145. sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
  146. card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
  147. if ((error = snd_ad1816a_pcm(chip, 0)) < 0) {
  148. snd_card_free(card);
  149. return error;
  150. }
  151. if ((error = snd_ad1816a_mixer(chip)) < 0) {
  152. snd_card_free(card);
  153. return error;
  154. }
  155. error = snd_ad1816a_timer(chip, 0);
  156. if (error < 0) {
  157. snd_card_free(card);
  158. return error;
  159. }
  160. if (mpu_port[dev] > 0) {
  161. if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  162. mpu_port[dev], 0, mpu_irq[dev],
  163. NULL) < 0)
  164. printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
  165. }
  166. if (fm_port[dev] > 0) {
  167. if (snd_opl3_create(card,
  168. fm_port[dev], fm_port[dev] + 2,
  169. OPL3_HW_AUTO, 0, &opl3) < 0) {
  170. printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
  171. } else {
  172. error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  173. if (error < 0) {
  174. snd_card_free(card);
  175. return error;
  176. }
  177. }
  178. }
  179. if ((error = snd_card_register(card)) < 0) {
  180. snd_card_free(card);
  181. return error;
  182. }
  183. pnp_set_card_drvdata(pcard, card);
  184. return 0;
  185. }
  186. static unsigned int ad1816a_devices;
  187. static int snd_ad1816a_pnp_detect(struct pnp_card_link *card,
  188. const struct pnp_card_device_id *id)
  189. {
  190. static int dev;
  191. int res;
  192. for ( ; dev < SNDRV_CARDS; dev++) {
  193. if (!enable[dev])
  194. continue;
  195. res = snd_card_ad1816a_probe(dev, card, id);
  196. if (res < 0)
  197. return res;
  198. dev++;
  199. ad1816a_devices++;
  200. return 0;
  201. }
  202. return -ENODEV;
  203. }
  204. static void snd_ad1816a_pnp_remove(struct pnp_card_link *pcard)
  205. {
  206. snd_card_free(pnp_get_card_drvdata(pcard));
  207. pnp_set_card_drvdata(pcard, NULL);
  208. }
  209. #ifdef CONFIG_PM
  210. static int snd_ad1816a_pnp_suspend(struct pnp_card_link *pcard,
  211. pm_message_t state)
  212. {
  213. struct snd_card *card = pnp_get_card_drvdata(pcard);
  214. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  215. snd_ad1816a_suspend(card->private_data);
  216. return 0;
  217. }
  218. static int snd_ad1816a_pnp_resume(struct pnp_card_link *pcard)
  219. {
  220. struct snd_card *card = pnp_get_card_drvdata(pcard);
  221. snd_ad1816a_resume(card->private_data);
  222. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  223. return 0;
  224. }
  225. #endif
  226. static struct pnp_card_driver ad1816a_pnpc_driver = {
  227. .flags = PNP_DRIVER_RES_DISABLE,
  228. .name = "ad1816a",
  229. .id_table = snd_ad1816a_pnpids,
  230. .probe = snd_ad1816a_pnp_detect,
  231. .remove = snd_ad1816a_pnp_remove,
  232. #ifdef CONFIG_PM
  233. .suspend = snd_ad1816a_pnp_suspend,
  234. .resume = snd_ad1816a_pnp_resume,
  235. #endif
  236. };
  237. static int __init alsa_card_ad1816a_init(void)
  238. {
  239. int err;
  240. err = pnp_register_card_driver(&ad1816a_pnpc_driver);
  241. if (err)
  242. return err;
  243. if (!ad1816a_devices) {
  244. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  245. #ifdef MODULE
  246. printk(KERN_ERR "no AD1816A based soundcards found.\n");
  247. #endif /* MODULE */
  248. return -ENODEV;
  249. }
  250. return 0;
  251. }
  252. static void __exit alsa_card_ad1816a_exit(void)
  253. {
  254. pnp_unregister_card_driver(&ad1816a_pnpc_driver);
  255. }
  256. module_init(alsa_card_ad1816a_init)
  257. module_exit(alsa_card_ad1816a_exit)