vxpocket.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Driver for Digigram VXpocket V2/440 soundcards
  3. *
  4. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  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. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <sound/core.h>
  23. #include "vxpocket.h"
  24. #include <pcmcia/ciscode.h>
  25. #include <pcmcia/cisreg.h>
  26. #include <sound/initval.h>
  27. #include <sound/tlv.h>
  28. /*
  29. */
  30. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  31. MODULE_DESCRIPTION("Digigram VXPocket");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("{{Digigram,VXPocket},{Digigram,VXPocket440}}");
  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 switches */
  37. static int ibl[SNDRV_CARDS];
  38. module_param_array(index, int, NULL, 0444);
  39. MODULE_PARM_DESC(index, "Index value for VXPocket soundcard.");
  40. module_param_array(id, charp, NULL, 0444);
  41. MODULE_PARM_DESC(id, "ID string for VXPocket soundcard.");
  42. module_param_array(enable, bool, NULL, 0444);
  43. MODULE_PARM_DESC(enable, "Enable VXPocket soundcard.");
  44. module_param_array(ibl, int, NULL, 0444);
  45. MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard.");
  46. /*
  47. */
  48. static unsigned int card_alloc;
  49. /*
  50. */
  51. static void vxpocket_release(struct pcmcia_device *link)
  52. {
  53. free_irq(link->irq, link->priv);
  54. pcmcia_disable_device(link);
  55. }
  56. /*
  57. * destructor, called from snd_card_free_when_closed()
  58. */
  59. static int snd_vxpocket_dev_free(struct snd_device *device)
  60. {
  61. struct vx_core *chip = device->device_data;
  62. snd_vx_free_firmware(chip);
  63. kfree(chip);
  64. return 0;
  65. }
  66. /*
  67. * Hardware information
  68. */
  69. /* VX-pocket V2
  70. *
  71. * 1 DSP, 1 sync UER
  72. * 1 programmable clock (NIY)
  73. * 1 stereo analog input (line/micro)
  74. * 1 stereo analog output
  75. * Only output levels can be modified
  76. */
  77. static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
  78. static struct snd_vx_hardware vxpocket_hw = {
  79. .name = "VXPocket",
  80. .type = VX_TYPE_VXPOCKET,
  81. /* hardware specs */
  82. .num_codecs = 1,
  83. .num_ins = 1,
  84. .num_outs = 1,
  85. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  86. .output_level_db_scale = db_scale_old_vol,
  87. };
  88. /* VX-pocket 440
  89. *
  90. * 1 DSP, 1 sync UER, 1 sync World Clock (NIY)
  91. * SMPTE (NIY)
  92. * 2 stereo analog input (line/micro)
  93. * 2 stereo analog output
  94. * Only output levels can be modified
  95. * UER, but only for the first two inputs and outputs.
  96. */
  97. static struct snd_vx_hardware vxp440_hw = {
  98. .name = "VXPocket440",
  99. .type = VX_TYPE_VXP440,
  100. /* hardware specs */
  101. .num_codecs = 2,
  102. .num_ins = 2,
  103. .num_outs = 2,
  104. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  105. .output_level_db_scale = db_scale_old_vol,
  106. };
  107. /*
  108. * create vxpocket instance
  109. */
  110. static int snd_vxpocket_new(struct snd_card *card, int ibl,
  111. struct pcmcia_device *link,
  112. struct snd_vxpocket **chip_ret)
  113. {
  114. struct vx_core *chip;
  115. struct snd_vxpocket *vxp;
  116. static struct snd_device_ops ops = {
  117. .dev_free = snd_vxpocket_dev_free,
  118. };
  119. int err;
  120. chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
  121. sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
  122. if (!chip)
  123. return -ENOMEM;
  124. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  125. if (err < 0) {
  126. kfree(chip);
  127. return err;
  128. }
  129. chip->ibl.size = ibl;
  130. vxp = (struct snd_vxpocket *)chip;
  131. vxp->p_dev = link;
  132. link->priv = chip;
  133. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  134. link->resource[0]->end = 16;
  135. link->config_flags |= CONF_ENABLE_IRQ;
  136. link->config_index = 1;
  137. link->config_regs = PRESENT_OPTION;
  138. *chip_ret = vxp;
  139. return 0;
  140. }
  141. /**
  142. * snd_vxpocket_assign_resources - initialize the hardware and card instance.
  143. * @chip: VX core instance
  144. * @port: i/o port for the card
  145. * @irq: irq number for the card
  146. *
  147. * this function assigns the specified port and irq, boot the card,
  148. * create pcm and control instances, and initialize the rest hardware.
  149. *
  150. * returns 0 if successful, or a negative error code.
  151. */
  152. static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq)
  153. {
  154. int err;
  155. struct snd_card *card = chip->card;
  156. struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  157. snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
  158. vxp->port = port;
  159. sprintf(card->shortname, "Digigram %s", card->driver);
  160. sprintf(card->longname, "%s at 0x%x, irq %i",
  161. card->shortname, port, irq);
  162. chip->irq = irq;
  163. if ((err = snd_vx_setup_firmware(chip)) < 0)
  164. return err;
  165. return 0;
  166. }
  167. /*
  168. * configuration callback
  169. */
  170. static int vxpocket_config(struct pcmcia_device *link)
  171. {
  172. struct vx_core *chip = link->priv;
  173. int ret;
  174. snd_printdd(KERN_DEBUG "vxpocket_config called\n");
  175. /* redefine hardware record according to the VERSION1 string */
  176. if (!strcmp(link->prod_id[1], "VX-POCKET")) {
  177. snd_printdd("VX-pocket is detected\n");
  178. } else {
  179. snd_printdd("VX-pocket 440 is detected\n");
  180. /* overwrite the hardware information */
  181. chip->hw = &vxp440_hw;
  182. chip->type = vxp440_hw.type;
  183. strcpy(chip->card->driver, vxp440_hw.name);
  184. }
  185. ret = pcmcia_request_io(link);
  186. if (ret)
  187. goto failed_preirq;
  188. ret = request_threaded_irq(link->irq, snd_vx_irq_handler,
  189. snd_vx_threaded_irq_handler,
  190. IRQF_SHARED, link->devname, link->priv);
  191. if (ret)
  192. goto failed_preirq;
  193. ret = pcmcia_enable_device(link);
  194. if (ret)
  195. goto failed;
  196. chip->dev = &link->dev;
  197. if (snd_vxpocket_assign_resources(chip, link->resource[0]->start,
  198. link->irq) < 0)
  199. goto failed;
  200. return 0;
  201. failed:
  202. free_irq(link->irq, link->priv);
  203. failed_preirq:
  204. pcmcia_disable_device(link);
  205. return -ENODEV;
  206. }
  207. #ifdef CONFIG_PM
  208. static int vxp_suspend(struct pcmcia_device *link)
  209. {
  210. struct vx_core *chip = link->priv;
  211. snd_printdd(KERN_DEBUG "SUSPEND\n");
  212. if (chip) {
  213. snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
  214. snd_vx_suspend(chip);
  215. }
  216. return 0;
  217. }
  218. static int vxp_resume(struct pcmcia_device *link)
  219. {
  220. struct vx_core *chip = link->priv;
  221. snd_printdd(KERN_DEBUG "RESUME\n");
  222. if (pcmcia_dev_present(link)) {
  223. //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  224. if (chip) {
  225. snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
  226. snd_vx_resume(chip);
  227. }
  228. }
  229. snd_printdd(KERN_DEBUG "resume done!\n");
  230. return 0;
  231. }
  232. #endif
  233. /*
  234. */
  235. static int vxpocket_probe(struct pcmcia_device *p_dev)
  236. {
  237. struct snd_card *card;
  238. struct snd_vxpocket *vxp;
  239. int i, err;
  240. /* find an empty slot from the card list */
  241. for (i = 0; i < SNDRV_CARDS; i++) {
  242. if (!(card_alloc & (1 << i)))
  243. break;
  244. }
  245. if (i >= SNDRV_CARDS) {
  246. snd_printk(KERN_ERR "vxpocket: too many cards found\n");
  247. return -EINVAL;
  248. }
  249. if (! enable[i])
  250. return -ENODEV; /* disabled explicitly */
  251. /* ok, create a card instance */
  252. err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE,
  253. 0, &card);
  254. if (err < 0) {
  255. snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
  256. return err;
  257. }
  258. err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp);
  259. if (err < 0) {
  260. snd_card_free(card);
  261. return err;
  262. }
  263. card->private_data = vxp;
  264. vxp->index = i;
  265. card_alloc |= 1 << i;
  266. vxp->p_dev = p_dev;
  267. return vxpocket_config(p_dev);
  268. }
  269. static void vxpocket_detach(struct pcmcia_device *link)
  270. {
  271. struct snd_vxpocket *vxp;
  272. struct vx_core *chip;
  273. if (! link)
  274. return;
  275. vxp = link->priv;
  276. chip = (struct vx_core *)vxp;
  277. card_alloc &= ~(1 << vxp->index);
  278. chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
  279. snd_card_disconnect(chip->card);
  280. vxpocket_release(link);
  281. snd_card_free_when_closed(chip->card);
  282. }
  283. /*
  284. * Module entry points
  285. */
  286. static const struct pcmcia_device_id vxp_ids[] = {
  287. PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
  288. PCMCIA_DEVICE_NULL
  289. };
  290. MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
  291. static struct pcmcia_driver vxp_cs_driver = {
  292. .owner = THIS_MODULE,
  293. .name = "snd-vxpocket",
  294. .probe = vxpocket_probe,
  295. .remove = vxpocket_detach,
  296. .id_table = vxp_ids,
  297. #ifdef CONFIG_PM
  298. .suspend = vxp_suspend,
  299. .resume = vxp_resume,
  300. #endif
  301. };
  302. module_pcmcia_driver(vxp_cs_driver);