es968.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 <sound/driver.h>
  18. #include <linux/init.h>
  19. #include <linux/time.h>
  20. #include <linux/pnp.h>
  21. #include <linux/moduleparam.h>
  22. #include <sound/core.h>
  23. #include <sound/initval.h>
  24. #include <sound/sb.h>
  25. #define PFX "es968: "
  26. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  27. MODULE_DESCRIPTION("ESS AudioDrive ES968");
  28. MODULE_LICENSE("GPL");
  29. MODULE_SUPPORTED_DEVICE("{{ESS,AudioDrive ES968}}");
  30. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  31. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  32. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  33. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  34. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
  35. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  36. module_param_array(index, int, NULL, 0444);
  37. MODULE_PARM_DESC(index, "Index value for es968 based soundcard.");
  38. module_param_array(id, charp, NULL, 0444);
  39. MODULE_PARM_DESC(id, "ID string for es968 based soundcard.");
  40. module_param_array(enable, bool, NULL, 0444);
  41. MODULE_PARM_DESC(enable, "Enable es968 based soundcard.");
  42. module_param_array(port, long, NULL, 0444);
  43. MODULE_PARM_DESC(port, "Port # for es968 driver.");
  44. module_param_array(irq, int, NULL, 0444);
  45. MODULE_PARM_DESC(irq, "IRQ # for es968 driver.");
  46. module_param_array(dma8, int, NULL, 0444);
  47. MODULE_PARM_DESC(dma8, "8-bit DMA # for es968 driver.");
  48. struct snd_card_es968 {
  49. struct pnp_dev *dev;
  50. struct snd_sb *chip;
  51. };
  52. static struct pnp_card_device_id snd_es968_pnpids[] = {
  53. { .id = "ESS0968", .devs = { { "@@@0968" }, } },
  54. { .id = "", } /* end */
  55. };
  56. MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
  57. #define DRIVER_NAME "snd-card-es968"
  58. static irqreturn_t snd_card_es968_interrupt(int irq, void *dev_id)
  59. {
  60. struct snd_sb *chip = dev_id;
  61. if (chip->open & SB_OPEN_PCM) {
  62. return snd_sb8dsp_interrupt(chip);
  63. } else {
  64. return snd_sb8dsp_midi_interrupt(chip);
  65. }
  66. }
  67. static int __devinit snd_card_es968_pnp(int dev, struct snd_card_es968 *acard,
  68. struct pnp_card_link *card,
  69. const struct pnp_card_device_id *id)
  70. {
  71. struct pnp_dev *pdev;
  72. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  73. int err;
  74. if (!cfg)
  75. return -ENOMEM;
  76. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  77. if (acard->dev == NULL) {
  78. kfree(cfg);
  79. return -ENODEV;
  80. }
  81. pdev = acard->dev;
  82. pnp_init_resource_table(cfg);
  83. /* override resources */
  84. if (port[dev] != SNDRV_AUTO_PORT)
  85. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  86. if (dma8[dev] != SNDRV_AUTO_DMA)
  87. pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
  88. if (irq[dev] != SNDRV_AUTO_IRQ)
  89. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  90. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  91. snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
  92. err = pnp_activate_dev(pdev);
  93. if (err < 0) {
  94. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  95. kfree(cfg);
  96. return err;
  97. }
  98. port[dev] = pnp_port_start(pdev, 0);
  99. dma8[dev] = pnp_dma(pdev, 1);
  100. irq[dev] = pnp_irq(pdev, 0);
  101. kfree(cfg);
  102. return 0;
  103. }
  104. static int __devinit snd_card_es968_probe(int dev,
  105. struct pnp_card_link *pcard,
  106. const struct pnp_card_device_id *pid)
  107. {
  108. int error;
  109. struct snd_sb *chip;
  110. struct snd_card *card;
  111. struct snd_card_es968 *acard;
  112. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  113. sizeof(struct snd_card_es968))) == NULL)
  114. return -ENOMEM;
  115. acard = card->private_data;
  116. if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
  117. snd_card_free(card);
  118. return error;
  119. }
  120. snd_card_set_dev(card, &pcard->card->dev);
  121. if ((error = snd_sbdsp_create(card, port[dev],
  122. irq[dev],
  123. snd_card_es968_interrupt,
  124. dma8[dev],
  125. -1,
  126. SB_HW_AUTO, &chip)) < 0) {
  127. snd_card_free(card);
  128. return error;
  129. }
  130. acard->chip = chip;
  131. if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
  132. snd_card_free(card);
  133. return error;
  134. }
  135. if ((error = snd_sbmixer_new(chip)) < 0) {
  136. snd_card_free(card);
  137. return error;
  138. }
  139. if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
  140. snd_card_free(card);
  141. return error;
  142. }
  143. strcpy(card->driver, "ES968");
  144. strcpy(card->shortname, "ESS ES968");
  145. sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
  146. card->shortname, chip->name, chip->port, irq[dev], dma8[dev]);
  147. if ((error = snd_card_register(card)) < 0) {
  148. snd_card_free(card);
  149. return error;
  150. }
  151. pnp_set_card_drvdata(pcard, card);
  152. return 0;
  153. }
  154. static unsigned int __devinitdata es968_devices;
  155. static int __devinit snd_es968_pnp_detect(struct pnp_card_link *card,
  156. const struct pnp_card_device_id *id)
  157. {
  158. static int dev;
  159. int res;
  160. for ( ; dev < SNDRV_CARDS; dev++) {
  161. if (!enable[dev])
  162. continue;
  163. res = snd_card_es968_probe(dev, card, id);
  164. if (res < 0)
  165. return res;
  166. dev++;
  167. es968_devices++;
  168. return 0;
  169. }
  170. return -ENODEV;
  171. }
  172. static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
  173. {
  174. snd_card_free(pnp_get_card_drvdata(pcard));
  175. pnp_set_card_drvdata(pcard, NULL);
  176. }
  177. #ifdef CONFIG_PM
  178. static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  179. {
  180. struct snd_card *card = pnp_get_card_drvdata(pcard);
  181. struct snd_card_es968 *acard = card->private_data;
  182. struct snd_sb *chip = acard->chip;
  183. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  184. snd_pcm_suspend_all(chip->pcm);
  185. snd_sbmixer_suspend(chip);
  186. return 0;
  187. }
  188. static int snd_es968_pnp_resume(struct pnp_card_link *pcard)
  189. {
  190. struct snd_card *card = pnp_get_card_drvdata(pcard);
  191. struct snd_card_es968 *acard = card->private_data;
  192. struct snd_sb *chip = acard->chip;
  193. snd_sbdsp_reset(chip);
  194. snd_sbmixer_resume(chip);
  195. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  196. return 0;
  197. }
  198. #endif
  199. static struct pnp_card_driver es968_pnpc_driver = {
  200. .flags = PNP_DRIVER_RES_DISABLE,
  201. .name = "es968",
  202. .id_table = snd_es968_pnpids,
  203. .probe = snd_es968_pnp_detect,
  204. .remove = __devexit_p(snd_es968_pnp_remove),
  205. #ifdef CONFIG_PM
  206. .suspend = snd_es968_pnp_suspend,
  207. .resume = snd_es968_pnp_resume,
  208. #endif
  209. };
  210. static int __init alsa_card_es968_init(void)
  211. {
  212. int err = pnp_register_card_driver(&es968_pnpc_driver);
  213. if (err)
  214. return err;
  215. if (!es968_devices) {
  216. pnp_unregister_card_driver(&es968_pnpc_driver);
  217. #ifdef MODULE
  218. snd_printk(KERN_ERR "no ES968 based soundcards found\n");
  219. #endif
  220. return -ENODEV;
  221. }
  222. return 0;
  223. }
  224. static void __exit alsa_card_es968_exit(void)
  225. {
  226. pnp_unregister_card_driver(&es968_pnpc_driver);
  227. }
  228. module_init(alsa_card_es968_init)
  229. module_exit(alsa_card_es968_exit)