vxpocket.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for Digigram VXpocket V2/440 soundcards
  4. *
  5. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <sound/core.h>
  11. #include "vxpocket.h"
  12. #include <pcmcia/ciscode.h>
  13. #include <pcmcia/cisreg.h>
  14. #include <sound/initval.h>
  15. #include <sound/tlv.h>
  16. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  17. MODULE_DESCRIPTION("Digigram VXPocket");
  18. MODULE_LICENSE("GPL");
  19. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  20. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  21. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */
  22. static int ibl[SNDRV_CARDS];
  23. module_param_array(index, int, NULL, 0444);
  24. MODULE_PARM_DESC(index, "Index value for VXPocket soundcard.");
  25. module_param_array(id, charp, NULL, 0444);
  26. MODULE_PARM_DESC(id, "ID string for VXPocket soundcard.");
  27. module_param_array(enable, bool, NULL, 0444);
  28. MODULE_PARM_DESC(enable, "Enable VXPocket soundcard.");
  29. module_param_array(ibl, int, NULL, 0444);
  30. MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard.");
  31. /*
  32. */
  33. static unsigned int card_alloc;
  34. /*
  35. */
  36. static void vxpocket_release(struct pcmcia_device *link)
  37. {
  38. free_irq(link->irq, link->priv);
  39. pcmcia_disable_device(link);
  40. }
  41. /*
  42. * Hardware information
  43. */
  44. /* VX-pocket V2
  45. *
  46. * 1 DSP, 1 sync UER
  47. * 1 programmable clock (NIY)
  48. * 1 stereo analog input (line/micro)
  49. * 1 stereo analog output
  50. * Only output levels can be modified
  51. */
  52. static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
  53. static const struct snd_vx_hardware vxpocket_hw = {
  54. .name = "VXPocket",
  55. .type = VX_TYPE_VXPOCKET,
  56. /* hardware specs */
  57. .num_codecs = 1,
  58. .num_ins = 1,
  59. .num_outs = 1,
  60. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  61. .output_level_db_scale = db_scale_old_vol,
  62. };
  63. /* VX-pocket 440
  64. *
  65. * 1 DSP, 1 sync UER, 1 sync World Clock (NIY)
  66. * SMPTE (NIY)
  67. * 2 stereo analog input (line/micro)
  68. * 2 stereo analog output
  69. * Only output levels can be modified
  70. * UER, but only for the first two inputs and outputs.
  71. */
  72. static const struct snd_vx_hardware vxp440_hw = {
  73. .name = "VXPocket440",
  74. .type = VX_TYPE_VXP440,
  75. /* hardware specs */
  76. .num_codecs = 2,
  77. .num_ins = 2,
  78. .num_outs = 2,
  79. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  80. .output_level_db_scale = db_scale_old_vol,
  81. };
  82. /*
  83. * create vxpocket instance
  84. */
  85. static int snd_vxpocket_new(struct snd_card *card, int ibl,
  86. struct pcmcia_device *link,
  87. struct snd_vxpocket **chip_ret)
  88. {
  89. struct vx_core *chip;
  90. struct snd_vxpocket *vxp;
  91. chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
  92. sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
  93. if (!chip)
  94. return -ENOMEM;
  95. chip->ibl.size = ibl;
  96. vxp = to_vxpocket(chip);
  97. vxp->p_dev = link;
  98. link->priv = chip;
  99. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  100. link->resource[0]->end = 16;
  101. link->config_flags |= CONF_ENABLE_IRQ;
  102. link->config_index = 1;
  103. link->config_regs = PRESENT_OPTION;
  104. *chip_ret = vxp;
  105. return 0;
  106. }
  107. /**
  108. * snd_vxpocket_assign_resources - initialize the hardware and card instance.
  109. * @chip: VX core instance
  110. * @port: i/o port for the card
  111. * @irq: irq number for the card
  112. *
  113. * this function assigns the specified port and irq, boot the card,
  114. * create pcm and control instances, and initialize the rest hardware.
  115. *
  116. * returns 0 if successful, or a negative error code.
  117. */
  118. static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq)
  119. {
  120. int err;
  121. struct snd_card *card = chip->card;
  122. struct snd_vxpocket *vxp = to_vxpocket(chip);
  123. dev_dbg(chip->card->dev,
  124. "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
  125. vxp->port = port;
  126. sprintf(card->shortname, "Digigram %s", card->driver);
  127. sprintf(card->longname, "%s at 0x%x, irq %i",
  128. card->shortname, port, irq);
  129. chip->irq = irq;
  130. card->sync_irq = chip->irq;
  131. err = snd_vx_setup_firmware(chip);
  132. if (err < 0)
  133. return err;
  134. return 0;
  135. }
  136. /*
  137. * configuration callback
  138. */
  139. static int vxpocket_config(struct pcmcia_device *link)
  140. {
  141. struct vx_core *chip = link->priv;
  142. int ret;
  143. /* redefine hardware record according to the VERSION1 string */
  144. if (!strcmp(link->prod_id[1], "VX-POCKET")) {
  145. dev_dbg(chip->card->dev, "VX-pocket is detected\n");
  146. } else {
  147. dev_dbg(chip->card->dev, "VX-pocket 440 is detected\n");
  148. /* overwrite the hardware information */
  149. chip->hw = &vxp440_hw;
  150. chip->type = vxp440_hw.type;
  151. strcpy(chip->card->driver, vxp440_hw.name);
  152. }
  153. ret = pcmcia_request_io(link);
  154. if (ret)
  155. goto failed_preirq;
  156. ret = request_threaded_irq(link->irq, snd_vx_irq_handler,
  157. snd_vx_threaded_irq_handler,
  158. IRQF_SHARED, link->devname, link->priv);
  159. if (ret)
  160. goto failed_preirq;
  161. ret = pcmcia_enable_device(link);
  162. if (ret)
  163. goto failed;
  164. if (snd_vxpocket_assign_resources(chip, link->resource[0]->start,
  165. link->irq) < 0)
  166. goto failed;
  167. return 0;
  168. failed:
  169. free_irq(link->irq, link->priv);
  170. failed_preirq:
  171. pcmcia_disable_device(link);
  172. return -ENODEV;
  173. }
  174. #ifdef CONFIG_PM
  175. static int vxp_suspend(struct pcmcia_device *link)
  176. {
  177. struct vx_core *chip = link->priv;
  178. if (chip)
  179. snd_vx_suspend(chip);
  180. return 0;
  181. }
  182. static int vxp_resume(struct pcmcia_device *link)
  183. {
  184. struct vx_core *chip = link->priv;
  185. if (pcmcia_dev_present(link)) {
  186. if (chip)
  187. snd_vx_resume(chip);
  188. }
  189. return 0;
  190. }
  191. #endif
  192. /*
  193. */
  194. static int vxpocket_probe(struct pcmcia_device *p_dev)
  195. {
  196. struct snd_card *card;
  197. struct snd_vxpocket *vxp;
  198. int i, err;
  199. /* find an empty slot from the card list */
  200. for (i = 0; i < SNDRV_CARDS; i++) {
  201. if (!(card_alloc & (1 << i)))
  202. break;
  203. }
  204. if (i >= SNDRV_CARDS) {
  205. dev_err(&p_dev->dev, "vxpocket: too many cards found\n");
  206. return -EINVAL;
  207. }
  208. if (! enable[i])
  209. return -ENODEV; /* disabled explicitly */
  210. /* ok, create a card instance */
  211. err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE,
  212. 0, &card);
  213. if (err < 0) {
  214. dev_err(&p_dev->dev, "vxpocket: cannot create a card instance\n");
  215. return err;
  216. }
  217. err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp);
  218. if (err < 0) {
  219. snd_card_free(card);
  220. return err;
  221. }
  222. card->private_data = vxp;
  223. vxp->index = i;
  224. card_alloc |= 1 << i;
  225. vxp->p_dev = p_dev;
  226. return vxpocket_config(p_dev);
  227. }
  228. static void vxpocket_detach(struct pcmcia_device *link)
  229. {
  230. struct snd_vxpocket *vxp;
  231. struct vx_core *chip;
  232. if (! link)
  233. return;
  234. vxp = link->priv;
  235. chip = (struct vx_core *)vxp;
  236. card_alloc &= ~(1 << vxp->index);
  237. chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
  238. snd_card_disconnect(chip->card);
  239. vxpocket_release(link);
  240. snd_card_free_when_closed(chip->card);
  241. }
  242. /*
  243. * Module entry points
  244. */
  245. static const struct pcmcia_device_id vxp_ids[] = {
  246. PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
  247. PCMCIA_DEVICE_NULL
  248. };
  249. MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
  250. static struct pcmcia_driver vxp_cs_driver = {
  251. .owner = THIS_MODULE,
  252. .name = "snd-vxpocket",
  253. .probe = vxpocket_probe,
  254. .remove = vxpocket_detach,
  255. .id_table = vxp_ids,
  256. #ifdef CONFIG_PM
  257. .suspend = vxp_suspend,
  258. .resume = vxp_resume,
  259. #endif
  260. };
  261. module_pcmcia_driver(vxp_cs_driver);