vx222.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Driver for Digigram VX222 V2/Mic PCI soundcards
  3. *
  4. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/pci.h>
  24. #include <linux/slab.h>
  25. #include <linux/moduleparam.h>
  26. #include <sound/core.h>
  27. #include <sound/initval.h>
  28. #include "vx222.h"
  29. #define CARD_NAME "VX222"
  30. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  31. MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}");
  34. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  35. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  36. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  37. static int mic[SNDRV_CARDS]; /* microphone */
  38. static int ibl[SNDRV_CARDS]; /* microphone */
  39. module_param_array(index, int, NULL, 0444);
  40. MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
  41. module_param_array(id, charp, NULL, 0444);
  42. MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
  43. module_param_array(enable, bool, NULL, 0444);
  44. MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
  45. module_param_array(mic, bool, NULL, 0444);
  46. MODULE_PARM_DESC(mic, "Enable Microphone.");
  47. module_param_array(ibl, int, NULL, 0444);
  48. MODULE_PARM_DESC(ibl, "Capture IBL size.");
  49. /*
  50. */
  51. enum {
  52. VX_PCI_VX222_OLD,
  53. VX_PCI_VX222_NEW
  54. };
  55. static struct pci_device_id snd_vx222_ids[] = {
  56. { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */
  57. { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */
  58. { 0, }
  59. };
  60. MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
  61. /*
  62. */
  63. static struct snd_vx_hardware vx222_old_hw = {
  64. .name = "VX222/Old",
  65. .type = VX_TYPE_BOARD,
  66. /* hw specs */
  67. .num_codecs = 1,
  68. .num_ins = 1,
  69. .num_outs = 1,
  70. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  71. };
  72. static struct snd_vx_hardware vx222_v2_hw = {
  73. .name = "VX222/v2",
  74. .type = VX_TYPE_V2,
  75. /* hw specs */
  76. .num_codecs = 1,
  77. .num_ins = 1,
  78. .num_outs = 1,
  79. .output_level_max = VX2_AKM_LEVEL_MAX,
  80. };
  81. static struct snd_vx_hardware vx222_mic_hw = {
  82. .name = "VX222/Mic",
  83. .type = VX_TYPE_MIC,
  84. /* hw specs */
  85. .num_codecs = 1,
  86. .num_ins = 1,
  87. .num_outs = 1,
  88. .output_level_max = VX2_AKM_LEVEL_MAX,
  89. };
  90. /*
  91. */
  92. static int snd_vx222_free(struct vx_core *chip)
  93. {
  94. struct snd_vx222 *vx = (struct snd_vx222 *)chip;
  95. if (chip->irq >= 0)
  96. free_irq(chip->irq, (void*)chip);
  97. if (vx->port[0])
  98. pci_release_regions(vx->pci);
  99. pci_disable_device(vx->pci);
  100. kfree(chip);
  101. return 0;
  102. }
  103. static int snd_vx222_dev_free(struct snd_device *device)
  104. {
  105. struct vx_core *chip = device->device_data;
  106. return snd_vx222_free(chip);
  107. }
  108. static int __devinit snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
  109. struct snd_vx_hardware *hw,
  110. struct snd_vx222 **rchip)
  111. {
  112. struct vx_core *chip;
  113. struct snd_vx222 *vx;
  114. int i, err;
  115. static struct snd_device_ops ops = {
  116. .dev_free = snd_vx222_dev_free,
  117. };
  118. struct snd_vx_ops *vx_ops;
  119. /* enable PCI device */
  120. if ((err = pci_enable_device(pci)) < 0)
  121. return err;
  122. pci_set_master(pci);
  123. vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
  124. chip = snd_vx_create(card, hw, vx_ops,
  125. sizeof(struct snd_vx222) - sizeof(struct vx_core));
  126. if (! chip) {
  127. pci_disable_device(pci);
  128. return -ENOMEM;
  129. }
  130. vx = (struct snd_vx222 *)chip;
  131. vx->pci = pci;
  132. if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
  133. snd_vx222_free(chip);
  134. return err;
  135. }
  136. for (i = 0; i < 2; i++)
  137. vx->port[i] = pci_resource_start(pci, i + 1);
  138. if (request_irq(pci->irq, snd_vx_irq_handler, SA_INTERRUPT|SA_SHIRQ,
  139. CARD_NAME, (void *) chip)) {
  140. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  141. snd_vx222_free(chip);
  142. return -EBUSY;
  143. }
  144. chip->irq = pci->irq;
  145. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  146. snd_vx222_free(chip);
  147. return err;
  148. }
  149. snd_card_set_dev(card, &pci->dev);
  150. *rchip = vx;
  151. return 0;
  152. }
  153. static int __devinit snd_vx222_probe(struct pci_dev *pci,
  154. const struct pci_device_id *pci_id)
  155. {
  156. static int dev;
  157. struct snd_card *card;
  158. struct snd_vx_hardware *hw;
  159. struct snd_vx222 *vx;
  160. int err;
  161. if (dev >= SNDRV_CARDS)
  162. return -ENODEV;
  163. if (!enable[dev]) {
  164. dev++;
  165. return -ENOENT;
  166. }
  167. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  168. if (card == NULL)
  169. return -ENOMEM;
  170. switch ((int)pci_id->driver_data) {
  171. case VX_PCI_VX222_OLD:
  172. hw = &vx222_old_hw;
  173. break;
  174. case VX_PCI_VX222_NEW:
  175. default:
  176. if (mic[dev])
  177. hw = &vx222_mic_hw;
  178. else
  179. hw = &vx222_v2_hw;
  180. break;
  181. }
  182. if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) {
  183. snd_card_free(card);
  184. return err;
  185. }
  186. card->private_data = vx;
  187. vx->core.ibl.size = ibl[dev];
  188. sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
  189. card->shortname, vx->port[0], vx->port[1], vx->core.irq);
  190. snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n",
  191. card->shortname, vx->port[0], vx->port[1], vx->core.irq);
  192. #ifdef SND_VX_FW_LOADER
  193. vx->core.dev = &pci->dev;
  194. #endif
  195. if ((err = snd_vx_setup_firmware(&vx->core)) < 0) {
  196. snd_card_free(card);
  197. return err;
  198. }
  199. if ((err = snd_card_register(card)) < 0) {
  200. snd_card_free(card);
  201. return err;
  202. }
  203. pci_set_drvdata(pci, card);
  204. dev++;
  205. return 0;
  206. }
  207. static void __devexit snd_vx222_remove(struct pci_dev *pci)
  208. {
  209. snd_card_free(pci_get_drvdata(pci));
  210. pci_set_drvdata(pci, NULL);
  211. }
  212. #ifdef CONFIG_PM
  213. static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state)
  214. {
  215. struct snd_card *card = pci_get_drvdata(pci);
  216. struct snd_vx222 *vx = card->private_data;
  217. int err;
  218. err = snd_vx_suspend(&vx->core, state);
  219. pci_set_power_state(pci, PCI_D3hot);
  220. pci_disable_device(pci);
  221. pci_save_state(pci);
  222. return err;
  223. }
  224. static int snd_vx222_resume(struct pci_dev *pci)
  225. {
  226. struct snd_card *card = pci_get_drvdata(pci);
  227. struct snd_vx222 *vx = card->private_data;
  228. pci_restore_state(pci);
  229. pci_enable_device(pci);
  230. pci_set_power_state(pci, PCI_D0);
  231. pci_set_master(pci);
  232. return snd_vx_resume(&vx->core);
  233. }
  234. #endif
  235. static struct pci_driver driver = {
  236. .name = "Digigram VX222",
  237. .id_table = snd_vx222_ids,
  238. .probe = snd_vx222_probe,
  239. .remove = __devexit_p(snd_vx222_remove),
  240. #ifdef CONFIG_PM
  241. .suspend = snd_vx222_suspend,
  242. .resume = snd_vx222_resume,
  243. #endif
  244. };
  245. static int __init alsa_card_vx222_init(void)
  246. {
  247. return pci_register_driver(&driver);
  248. }
  249. static void __exit alsa_card_vx222_exit(void)
  250. {
  251. pci_unregister_driver(&driver);
  252. }
  253. module_init(alsa_card_vx222_init)
  254. module_exit(alsa_card_vx222_exit)