vx222.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/pci.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. #include <sound/core.h>
  26. #include <sound/initval.h>
  27. #include <sound/tlv.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 bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  37. static bool 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 const 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 const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
  64. static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
  65. static struct snd_vx_hardware vx222_old_hw = {
  66. .name = "VX222/Old",
  67. .type = VX_TYPE_BOARD,
  68. /* hw specs */
  69. .num_codecs = 1,
  70. .num_ins = 1,
  71. .num_outs = 1,
  72. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  73. .output_level_db_scale = db_scale_old_vol,
  74. };
  75. static struct snd_vx_hardware vx222_v2_hw = {
  76. .name = "VX222/v2",
  77. .type = VX_TYPE_V2,
  78. /* hw specs */
  79. .num_codecs = 1,
  80. .num_ins = 1,
  81. .num_outs = 1,
  82. .output_level_max = VX2_AKM_LEVEL_MAX,
  83. .output_level_db_scale = db_scale_akm,
  84. };
  85. static struct snd_vx_hardware vx222_mic_hw = {
  86. .name = "VX222/Mic",
  87. .type = VX_TYPE_MIC,
  88. /* hw specs */
  89. .num_codecs = 1,
  90. .num_ins = 1,
  91. .num_outs = 1,
  92. .output_level_max = VX2_AKM_LEVEL_MAX,
  93. .output_level_db_scale = db_scale_akm,
  94. };
  95. /*
  96. */
  97. static int snd_vx222_free(struct vx_core *chip)
  98. {
  99. struct snd_vx222 *vx = (struct snd_vx222 *)chip;
  100. if (chip->irq >= 0)
  101. free_irq(chip->irq, (void*)chip);
  102. if (vx->port[0])
  103. pci_release_regions(vx->pci);
  104. pci_disable_device(vx->pci);
  105. kfree(chip);
  106. return 0;
  107. }
  108. static int snd_vx222_dev_free(struct snd_device *device)
  109. {
  110. struct vx_core *chip = device->device_data;
  111. return snd_vx222_free(chip);
  112. }
  113. static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
  114. struct snd_vx_hardware *hw,
  115. struct snd_vx222 **rchip)
  116. {
  117. struct vx_core *chip;
  118. struct snd_vx222 *vx;
  119. int i, err;
  120. static struct snd_device_ops ops = {
  121. .dev_free = snd_vx222_dev_free,
  122. };
  123. struct snd_vx_ops *vx_ops;
  124. /* enable PCI device */
  125. if ((err = pci_enable_device(pci)) < 0)
  126. return err;
  127. pci_set_master(pci);
  128. vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
  129. chip = snd_vx_create(card, hw, vx_ops,
  130. sizeof(struct snd_vx222) - sizeof(struct vx_core));
  131. if (! chip) {
  132. pci_disable_device(pci);
  133. return -ENOMEM;
  134. }
  135. vx = (struct snd_vx222 *)chip;
  136. vx->pci = pci;
  137. if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
  138. snd_vx222_free(chip);
  139. return err;
  140. }
  141. for (i = 0; i < 2; i++)
  142. vx->port[i] = pci_resource_start(pci, i + 1);
  143. if (request_threaded_irq(pci->irq, snd_vx_irq_handler,
  144. snd_vx_threaded_irq_handler, IRQF_SHARED,
  145. KBUILD_MODNAME, chip)) {
  146. dev_err(card->dev, "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. *rchip = vx;
  156. return 0;
  157. }
  158. static int snd_vx222_probe(struct pci_dev *pci,
  159. const struct pci_device_id *pci_id)
  160. {
  161. static int dev;
  162. struct snd_card *card;
  163. struct snd_vx_hardware *hw;
  164. struct snd_vx222 *vx;
  165. int err;
  166. if (dev >= SNDRV_CARDS)
  167. return -ENODEV;
  168. if (!enable[dev]) {
  169. dev++;
  170. return -ENOENT;
  171. }
  172. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  173. 0, &card);
  174. if (err < 0)
  175. return err;
  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. dev_dbg(card->dev, "%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 snd_vx222_remove(struct pci_dev *pci)
  214. {
  215. snd_card_free(pci_get_drvdata(pci));
  216. }
  217. #ifdef CONFIG_PM_SLEEP
  218. static int snd_vx222_suspend(struct device *dev)
  219. {
  220. struct snd_card *card = dev_get_drvdata(dev);
  221. struct snd_vx222 *vx = card->private_data;
  222. return snd_vx_suspend(&vx->core);
  223. }
  224. static int snd_vx222_resume(struct device *dev)
  225. {
  226. struct snd_card *card = dev_get_drvdata(dev);
  227. struct snd_vx222 *vx = card->private_data;
  228. return snd_vx_resume(&vx->core);
  229. }
  230. static SIMPLE_DEV_PM_OPS(snd_vx222_pm, snd_vx222_suspend, snd_vx222_resume);
  231. #define SND_VX222_PM_OPS &snd_vx222_pm
  232. #else
  233. #define SND_VX222_PM_OPS NULL
  234. #endif
  235. static struct pci_driver vx222_driver = {
  236. .name = KBUILD_MODNAME,
  237. .id_table = snd_vx222_ids,
  238. .probe = snd_vx222_probe,
  239. .remove = snd_vx222_remove,
  240. .driver = {
  241. .pm = SND_VX222_PM_OPS,
  242. },
  243. };
  244. module_pci_driver(vx222_driver);