vxpocket.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * Driver for Digigram VXpocket V2/440 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/moduleparam.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 int 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. pcmcia_disable_device(link);
  54. }
  55. /*
  56. * destructor, called from snd_card_free_when_closed()
  57. */
  58. static int snd_vxpocket_dev_free(struct snd_device *device)
  59. {
  60. struct vx_core *chip = device->device_data;
  61. snd_vx_free_firmware(chip);
  62. kfree(chip);
  63. return 0;
  64. }
  65. /*
  66. * Hardware information
  67. */
  68. /* VX-pocket V2
  69. *
  70. * 1 DSP, 1 sync UER
  71. * 1 programmable clock (NIY)
  72. * 1 stereo analog input (line/micro)
  73. * 1 stereo analog output
  74. * Only output levels can be modified
  75. */
  76. static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
  77. static struct snd_vx_hardware vxpocket_hw = {
  78. .name = "VXPocket",
  79. .type = VX_TYPE_VXPOCKET,
  80. /* hardware specs */
  81. .num_codecs = 1,
  82. .num_ins = 1,
  83. .num_outs = 1,
  84. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  85. .output_level_db_scale = db_scale_old_vol,
  86. };
  87. /* VX-pocket 440
  88. *
  89. * 1 DSP, 1 sync UER, 1 sync World Clock (NIY)
  90. * SMPTE (NIY)
  91. * 2 stereo analog input (line/micro)
  92. * 2 stereo analog output
  93. * Only output levels can be modified
  94. * UER, but only for the first two inputs and outputs.
  95. */
  96. static struct snd_vx_hardware vxp440_hw = {
  97. .name = "VXPocket440",
  98. .type = VX_TYPE_VXP440,
  99. /* hardware specs */
  100. .num_codecs = 2,
  101. .num_ins = 2,
  102. .num_outs = 2,
  103. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  104. .output_level_db_scale = db_scale_old_vol,
  105. };
  106. /*
  107. * create vxpocket instance
  108. */
  109. static int snd_vxpocket_new(struct snd_card *card, int ibl,
  110. struct pcmcia_device *link,
  111. struct snd_vxpocket **chip_ret)
  112. {
  113. struct vx_core *chip;
  114. struct snd_vxpocket *vxp;
  115. static struct snd_device_ops ops = {
  116. .dev_free = snd_vxpocket_dev_free,
  117. };
  118. int err;
  119. chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
  120. sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
  121. if (!chip)
  122. return -ENOMEM;
  123. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  124. if (err < 0) {
  125. kfree(chip);
  126. return err;
  127. }
  128. chip->ibl.size = ibl;
  129. vxp = (struct snd_vxpocket *)chip;
  130. vxp->p_dev = link;
  131. link->priv = chip;
  132. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  133. link->io.NumPorts1 = 16;
  134. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  135. link->irq.Handler = &snd_vx_irq_handler;
  136. link->conf.Attributes = CONF_ENABLE_IRQ;
  137. link->conf.IntType = INT_MEMORY_AND_IO;
  138. link->conf.ConfigIndex = 1;
  139. link->conf.Present = PRESENT_OPTION;
  140. *chip_ret = vxp;
  141. return 0;
  142. }
  143. /**
  144. * snd_vxpocket_assign_resources - initialize the hardware and card instance.
  145. * @port: i/o port for the card
  146. * @irq: irq number for the card
  147. *
  148. * this function assigns the specified port and irq, boot the card,
  149. * create pcm and control instances, and initialize the rest hardware.
  150. *
  151. * returns 0 if successful, or a negative error code.
  152. */
  153. static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq)
  154. {
  155. int err;
  156. struct snd_card *card = chip->card;
  157. struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  158. snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
  159. vxp->port = port;
  160. sprintf(card->shortname, "Digigram %s", card->driver);
  161. sprintf(card->longname, "%s at 0x%x, irq %i",
  162. card->shortname, port, irq);
  163. chip->irq = irq;
  164. if ((err = snd_vx_setup_firmware(chip)) < 0)
  165. return err;
  166. return 0;
  167. }
  168. /*
  169. * configuration callback
  170. */
  171. static int vxpocket_config(struct pcmcia_device *link)
  172. {
  173. struct vx_core *chip = link->priv;
  174. struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  175. int ret;
  176. snd_printdd(KERN_DEBUG "vxpocket_config called\n");
  177. /* redefine hardware record according to the VERSION1 string */
  178. if (!strcmp(link->prod_id[1], "VX-POCKET")) {
  179. snd_printdd("VX-pocket is detected\n");
  180. } else {
  181. snd_printdd("VX-pocket 440 is detected\n");
  182. /* overwrite the hardware information */
  183. chip->hw = &vxp440_hw;
  184. chip->type = vxp440_hw.type;
  185. strcpy(chip->card->driver, vxp440_hw.name);
  186. }
  187. ret = pcmcia_request_io(link, &link->io);
  188. if (ret)
  189. goto failed;
  190. ret = pcmcia_request_irq(link, &link->irq);
  191. if (ret)
  192. goto failed;
  193. ret = pcmcia_request_configuration(link, &link->conf);
  194. if (ret)
  195. goto failed;
  196. chip->dev = &link->dev;
  197. snd_card_set_dev(chip->card, chip->dev);
  198. if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
  199. goto failed;
  200. link->dev_node = &vxp->node;
  201. return 0;
  202. failed:
  203. pcmcia_disable_device(link);
  204. return -ENODEV;
  205. }
  206. #ifdef CONFIG_PM
  207. static int vxp_suspend(struct pcmcia_device *link)
  208. {
  209. struct vx_core *chip = link->priv;
  210. snd_printdd(KERN_DEBUG "SUSPEND\n");
  211. if (chip) {
  212. snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
  213. snd_vx_suspend(chip, PMSG_SUSPEND);
  214. }
  215. return 0;
  216. }
  217. static int vxp_resume(struct pcmcia_device *link)
  218. {
  219. struct vx_core *chip = link->priv;
  220. snd_printdd(KERN_DEBUG "RESUME\n");
  221. if (pcmcia_dev_present(link)) {
  222. //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  223. if (chip) {
  224. snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
  225. snd_vx_resume(chip);
  226. }
  227. }
  228. snd_printdd(KERN_DEBUG "resume done!\n");
  229. return 0;
  230. }
  231. #endif
  232. /*
  233. */
  234. static int vxpocket_probe(struct pcmcia_device *p_dev)
  235. {
  236. struct snd_card *card;
  237. struct snd_vxpocket *vxp;
  238. int i, err;
  239. /* find an empty slot from the card list */
  240. for (i = 0; i < SNDRV_CARDS; i++) {
  241. if (!(card_alloc & (1 << i)))
  242. break;
  243. }
  244. if (i >= SNDRV_CARDS) {
  245. snd_printk(KERN_ERR "vxpocket: too many cards found\n");
  246. return -EINVAL;
  247. }
  248. if (! enable[i])
  249. return -ENODEV; /* disabled explicitly */
  250. /* ok, create a card instance */
  251. err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card);
  252. if (err < 0) {
  253. snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
  254. return err;
  255. }
  256. err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp);
  257. if (err < 0) {
  258. snd_card_free(card);
  259. return err;
  260. }
  261. card->private_data = vxp;
  262. vxp->index = i;
  263. card_alloc |= 1 << i;
  264. vxp->p_dev = p_dev;
  265. return vxpocket_config(p_dev);
  266. }
  267. static void vxpocket_detach(struct pcmcia_device *link)
  268. {
  269. struct snd_vxpocket *vxp;
  270. struct vx_core *chip;
  271. if (! link)
  272. return;
  273. vxp = link->priv;
  274. chip = (struct vx_core *)vxp;
  275. card_alloc &= ~(1 << vxp->index);
  276. chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
  277. snd_card_disconnect(chip->card);
  278. vxpocket_release(link);
  279. snd_card_free_when_closed(chip->card);
  280. }
  281. /*
  282. * Module entry points
  283. */
  284. static struct pcmcia_device_id vxp_ids[] = {
  285. PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
  286. PCMCIA_DEVICE_NULL
  287. };
  288. MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
  289. static struct pcmcia_driver vxp_cs_driver = {
  290. .owner = THIS_MODULE,
  291. .drv = {
  292. .name = "snd-vxpocket",
  293. },
  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. static int __init init_vxpocket(void)
  303. {
  304. return pcmcia_register_driver(&vxp_cs_driver);
  305. }
  306. static void __exit exit_vxpocket(void)
  307. {
  308. pcmcia_unregister_driver(&vxp_cs_driver);
  309. }
  310. module_init(init_vxpocket);
  311. module_exit(exit_vxpocket);