vx222.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 <sound/tlv.h>
  29. #include "vx222.h"
  30. #define CARD_NAME "VX222"
  31. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  32. MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
  33. MODULE_LICENSE("GPL");
  34. MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}");
  35. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  36. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  37. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  38. static int mic[SNDRV_CARDS]; /* microphone */
  39. static int ibl[SNDRV_CARDS]; /* microphone */
  40. module_param_array(index, int, NULL, 0444);
  41. MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
  42. module_param_array(id, charp, NULL, 0444);
  43. MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
  44. module_param_array(enable, bool, NULL, 0444);
  45. MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
  46. module_param_array(mic, bool, NULL, 0444);
  47. MODULE_PARM_DESC(mic, "Enable Microphone.");
  48. module_param_array(ibl, int, NULL, 0444);
  49. MODULE_PARM_DESC(ibl, "Capture IBL size.");
  50. /*
  51. */
  52. enum {
  53. VX_PCI_VX222_OLD,
  54. VX_PCI_VX222_NEW
  55. };
  56. static struct pci_device_id snd_vx222_ids[] = {
  57. { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */
  58. { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */
  59. { 0, }
  60. };
  61. MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
  62. /*
  63. */
  64. static DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
  65. static DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
  66. static struct snd_vx_hardware vx222_old_hw = {
  67. .name = "VX222/Old",
  68. .type = VX_TYPE_BOARD,
  69. /* hw specs */
  70. .num_codecs = 1,
  71. .num_ins = 1,
  72. .num_outs = 1,
  73. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  74. .output_level_db_scale = db_scale_old_vol,
  75. };
  76. static struct snd_vx_hardware vx222_v2_hw = {
  77. .name = "VX222/v2",
  78. .type = VX_TYPE_V2,
  79. /* hw specs */
  80. .num_codecs = 1,
  81. .num_ins = 1,
  82. .num_outs = 1,
  83. .output_level_max = VX2_AKM_LEVEL_MAX,
  84. .output_level_db_scale = db_scale_akm,
  85. };
  86. static struct snd_vx_hardware vx222_mic_hw = {
  87. .name = "VX222/Mic",
  88. .type = VX_TYPE_MIC,
  89. /* hw specs */
  90. .num_codecs = 1,
  91. .num_ins = 1,
  92. .num_outs = 1,
  93. .output_level_max = VX2_AKM_LEVEL_MAX,
  94. .output_level_db_scale = db_scale_akm,
  95. };
  96. /*
  97. */
  98. static int snd_vx222_free(struct vx_core *chip)
  99. {
  100. struct snd_vx222 *vx = (struct snd_vx222 *)chip;
  101. if (chip->irq >= 0)
  102. free_irq(chip->irq, (void*)chip);
  103. if (vx->port[0])
  104. pci_release_regions(vx->pci);
  105. pci_disable_device(vx->pci);
  106. kfree(chip);
  107. return 0;
  108. }
  109. static int snd_vx222_dev_free(struct snd_device *device)
  110. {
  111. struct vx_core *chip = device->device_data;
  112. return snd_vx222_free(chip);
  113. }
  114. static int __devinit snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
  115. struct snd_vx_hardware *hw,
  116. struct snd_vx222 **rchip)
  117. {
  118. struct vx_core *chip;
  119. struct snd_vx222 *vx;
  120. int i, err;
  121. static struct snd_device_ops ops = {
  122. .dev_free = snd_vx222_dev_free,
  123. };
  124. struct snd_vx_ops *vx_ops;
  125. /* enable PCI device */
  126. if ((err = pci_enable_device(pci)) < 0)
  127. return err;
  128. pci_set_master(pci);
  129. vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
  130. chip = snd_vx_create(card, hw, vx_ops,
  131. sizeof(struct snd_vx222) - sizeof(struct vx_core));
  132. if (! chip) {
  133. pci_disable_device(pci);
  134. return -ENOMEM;
  135. }
  136. vx = (struct snd_vx222 *)chip;
  137. vx->pci = pci;
  138. if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
  139. snd_vx222_free(chip);
  140. return err;
  141. }
  142. for (i = 0; i < 2; i++)
  143. vx->port[i] = pci_resource_start(pci, i + 1);
  144. if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_DISABLED|IRQF_SHARED,
  145. CARD_NAME, (void *) chip)) {
  146. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  147. snd_vx222_free(chip);
  148. return -EBUSY;
  149. }
  150. chip->irq = pci->irq;
  151. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  152. snd_vx222_free(chip);
  153. return err;
  154. }
  155. snd_card_set_dev(card, &pci->dev);
  156. *rchip = vx;
  157. return 0;
  158. }
  159. static int __devinit snd_vx222_probe(struct pci_dev *pci,
  160. const struct pci_device_id *pci_id)
  161. {
  162. static int dev;
  163. struct snd_card *card;
  164. struct snd_vx_hardware *hw;
  165. struct snd_vx222 *vx;
  166. int err;
  167. if (dev >= SNDRV_CARDS)
  168. return -ENODEV;
  169. if (!enable[dev]) {
  170. dev++;
  171. return -ENOENT;
  172. }
  173. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  174. if (card == NULL)
  175. return -ENOMEM;
  176. switch ((int)pci_id->driver_data) {
  177. case VX_PCI_VX222_OLD:
  178. hw = &vx222_old_hw;
  179. break;
  180. case VX_PCI_VX222_NEW:
  181. default:
  182. if (mic[dev])
  183. hw = &vx222_mic_hw;
  184. else
  185. hw = &vx222_v2_hw;
  186. break;
  187. }
  188. if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) {
  189. snd_card_free(card);
  190. return err;
  191. }
  192. card->private_data = vx;
  193. vx->core.ibl.size = ibl[dev];
  194. sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
  195. card->shortname, vx->port[0], vx->port[1], vx->core.irq);
  196. snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n",
  197. card->shortname, vx->port[0], vx->port[1], vx->core.irq);
  198. #ifdef SND_VX_FW_LOADER
  199. vx->core.dev = &pci->dev;
  200. #endif
  201. if ((err = snd_vx_setup_firmware(&vx->core)) < 0) {
  202. snd_card_free(card);
  203. return err;
  204. }
  205. if ((err = snd_card_register(card)) < 0) {
  206. snd_card_free(card);
  207. return err;
  208. }
  209. pci_set_drvdata(pci, card);
  210. dev++;
  211. return 0;
  212. }
  213. static void __devexit snd_vx222_remove(struct pci_dev *pci)
  214. {
  215. snd_card_free(pci_get_drvdata(pci));
  216. pci_set_drvdata(pci, NULL);
  217. }
  218. #ifdef CONFIG_PM
  219. static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state)
  220. {
  221. struct snd_card *card = pci_get_drvdata(pci);
  222. struct snd_vx222 *vx = card->private_data;
  223. int err;
  224. err = snd_vx_suspend(&vx->core, state);
  225. pci_disable_device(pci);
  226. pci_save_state(pci);
  227. pci_set_power_state(pci, pci_choose_state(pci, state));
  228. return err;
  229. }
  230. static int snd_vx222_resume(struct pci_dev *pci)
  231. {
  232. struct snd_card *card = pci_get_drvdata(pci);
  233. struct snd_vx222 *vx = card->private_data;
  234. pci_set_power_state(pci, PCI_D0);
  235. pci_restore_state(pci);
  236. if (pci_enable_device(pci) < 0) {
  237. printk(KERN_ERR "vx222: pci_enable_device failed, "
  238. "disabling device\n");
  239. snd_card_disconnect(card);
  240. return -EIO;
  241. }
  242. pci_set_master(pci);
  243. return snd_vx_resume(&vx->core);
  244. }
  245. #endif
  246. static struct pci_driver driver = {
  247. .name = "Digigram VX222",
  248. .id_table = snd_vx222_ids,
  249. .probe = snd_vx222_probe,
  250. .remove = __devexit_p(snd_vx222_remove),
  251. #ifdef CONFIG_PM
  252. .suspend = snd_vx222_suspend,
  253. .resume = snd_vx222_resume,
  254. #endif
  255. };
  256. static int __init alsa_card_vx222_init(void)
  257. {
  258. return pci_register_driver(&driver);
  259. }
  260. static void __exit alsa_card_vx222_exit(void)
  261. {
  262. pci_unregister_driver(&driver);
  263. }
  264. module_init(alsa_card_vx222_init)
  265. module_exit(alsa_card_vx222_exit)