es968.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. card-es968.c - driver for ESS AudioDrive ES968 based soundcards.
  3. Copyright (C) 1999 by Massimo Piccioni <dafastidio@libero.it>
  4. Thanks to Pierfrancesco 'qM2' Passerini.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <linux/init.h>
  18. #include <linux/time.h>
  19. #include <linux/pnp.h>
  20. #include <linux/moduleparam.h>
  21. #include <sound/core.h>
  22. #include <sound/initval.h>
  23. #include <sound/sb.h>
  24. #define PFX "es968: "
  25. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  26. MODULE_DESCRIPTION("ESS AudioDrive ES968");
  27. MODULE_LICENSE("GPL");
  28. MODULE_SUPPORTED_DEVICE("{{ESS,AudioDrive ES968}}");
  29. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  30. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  31. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  32. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  33. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  34. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  35. module_param_array(index, int, NULL, 0444);
  36. MODULE_PARM_DESC(index, "Index value for es968 based soundcard.");
  37. module_param_array(id, charp, NULL, 0444);
  38. MODULE_PARM_DESC(id, "ID string for es968 based soundcard.");
  39. module_param_array(enable, bool, NULL, 0444);
  40. MODULE_PARM_DESC(enable, "Enable es968 based soundcard.");
  41. struct snd_card_es968 {
  42. struct pnp_dev *dev;
  43. struct snd_sb *chip;
  44. };
  45. static struct pnp_card_device_id snd_es968_pnpids[] = {
  46. { .id = "ESS0968", .devs = { { "@@@0968" }, } },
  47. { .id = "", } /* end */
  48. };
  49. MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
  50. #define DRIVER_NAME "snd-card-es968"
  51. static irqreturn_t snd_card_es968_interrupt(int irq, void *dev_id)
  52. {
  53. struct snd_sb *chip = dev_id;
  54. if (chip->open & SB_OPEN_PCM) {
  55. return snd_sb8dsp_interrupt(chip);
  56. } else {
  57. return snd_sb8dsp_midi_interrupt(chip);
  58. }
  59. }
  60. static int __devinit snd_card_es968_pnp(int dev, struct snd_card_es968 *acard,
  61. struct pnp_card_link *card,
  62. const struct pnp_card_device_id *id)
  63. {
  64. struct pnp_dev *pdev;
  65. int err;
  66. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  67. if (acard->dev == NULL)
  68. return -ENODEV;
  69. pdev = acard->dev;
  70. err = pnp_activate_dev(pdev);
  71. if (err < 0) {
  72. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  73. return err;
  74. }
  75. port[dev] = pnp_port_start(pdev, 0);
  76. dma8[dev] = pnp_dma(pdev, 1);
  77. irq[dev] = pnp_irq(pdev, 0);
  78. return 0;
  79. }
  80. static int __devinit snd_card_es968_probe(int dev,
  81. struct pnp_card_link *pcard,
  82. const struct pnp_card_device_id *pid)
  83. {
  84. int error;
  85. struct snd_sb *chip;
  86. struct snd_card *card;
  87. struct snd_card_es968 *acard;
  88. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  89. sizeof(struct snd_card_es968))) == NULL)
  90. return -ENOMEM;
  91. acard = card->private_data;
  92. if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
  93. snd_card_free(card);
  94. return error;
  95. }
  96. snd_card_set_dev(card, &pcard->card->dev);
  97. if ((error = snd_sbdsp_create(card, port[dev],
  98. irq[dev],
  99. snd_card_es968_interrupt,
  100. dma8[dev],
  101. -1,
  102. SB_HW_AUTO, &chip)) < 0) {
  103. snd_card_free(card);
  104. return error;
  105. }
  106. acard->chip = chip;
  107. if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
  108. snd_card_free(card);
  109. return error;
  110. }
  111. if ((error = snd_sbmixer_new(chip)) < 0) {
  112. snd_card_free(card);
  113. return error;
  114. }
  115. if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
  116. snd_card_free(card);
  117. return error;
  118. }
  119. strcpy(card->driver, "ES968");
  120. strcpy(card->shortname, "ESS ES968");
  121. sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
  122. card->shortname, chip->name, chip->port, irq[dev], dma8[dev]);
  123. if ((error = snd_card_register(card)) < 0) {
  124. snd_card_free(card);
  125. return error;
  126. }
  127. pnp_set_card_drvdata(pcard, card);
  128. return 0;
  129. }
  130. static unsigned int __devinitdata es968_devices;
  131. static int __devinit snd_es968_pnp_detect(struct pnp_card_link *card,
  132. const struct pnp_card_device_id *id)
  133. {
  134. static int dev;
  135. int res;
  136. for ( ; dev < SNDRV_CARDS; dev++) {
  137. if (!enable[dev])
  138. continue;
  139. res = snd_card_es968_probe(dev, card, id);
  140. if (res < 0)
  141. return res;
  142. dev++;
  143. es968_devices++;
  144. return 0;
  145. }
  146. return -ENODEV;
  147. }
  148. static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
  149. {
  150. snd_card_free(pnp_get_card_drvdata(pcard));
  151. pnp_set_card_drvdata(pcard, NULL);
  152. }
  153. #ifdef CONFIG_PM
  154. static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  155. {
  156. struct snd_card *card = pnp_get_card_drvdata(pcard);
  157. struct snd_card_es968 *acard = card->private_data;
  158. struct snd_sb *chip = acard->chip;
  159. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  160. snd_pcm_suspend_all(chip->pcm);
  161. snd_sbmixer_suspend(chip);
  162. return 0;
  163. }
  164. static int snd_es968_pnp_resume(struct pnp_card_link *pcard)
  165. {
  166. struct snd_card *card = pnp_get_card_drvdata(pcard);
  167. struct snd_card_es968 *acard = card->private_data;
  168. struct snd_sb *chip = acard->chip;
  169. snd_sbdsp_reset(chip);
  170. snd_sbmixer_resume(chip);
  171. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  172. return 0;
  173. }
  174. #endif
  175. static struct pnp_card_driver es968_pnpc_driver = {
  176. .flags = PNP_DRIVER_RES_DISABLE,
  177. .name = "es968",
  178. .id_table = snd_es968_pnpids,
  179. .probe = snd_es968_pnp_detect,
  180. .remove = __devexit_p(snd_es968_pnp_remove),
  181. #ifdef CONFIG_PM
  182. .suspend = snd_es968_pnp_suspend,
  183. .resume = snd_es968_pnp_resume,
  184. #endif
  185. };
  186. static int __init alsa_card_es968_init(void)
  187. {
  188. int err = pnp_register_card_driver(&es968_pnpc_driver);
  189. if (err)
  190. return err;
  191. if (!es968_devices) {
  192. pnp_unregister_card_driver(&es968_pnpc_driver);
  193. #ifdef MODULE
  194. snd_printk(KERN_ERR "no ES968 based soundcards found\n");
  195. #endif
  196. return -ENODEV;
  197. }
  198. return 0;
  199. }
  200. static void __exit alsa_card_es968_exit(void)
  201. {
  202. pnp_unregister_card_driver(&es968_pnpc_driver);
  203. }
  204. module_init(alsa_card_es968_init)
  205. module_exit(alsa_card_es968_exit)