vxpocket.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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 <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/moduleparam.h>
  23. #include <sound/core.h>
  24. #include "vxpocket.h"
  25. #include <pcmcia/ciscode.h>
  26. #include <pcmcia/cisreg.h>
  27. #include <sound/initval.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(dev_link_t *link)
  52. {
  53. if (link->state & DEV_CONFIG) {
  54. /* release cs resources */
  55. pcmcia_release_configuration(link->handle);
  56. pcmcia_release_io(link->handle, &link->io);
  57. pcmcia_release_irq(link->handle, &link->irq);
  58. link->state &= ~DEV_CONFIG;
  59. }
  60. }
  61. /*
  62. * destructor, called from snd_card_free_in_thread()
  63. */
  64. static int snd_vxpocket_dev_free(struct snd_device *device)
  65. {
  66. struct vx_core *chip = device->device_data;
  67. snd_vx_free_firmware(chip);
  68. kfree(chip);
  69. return 0;
  70. }
  71. /*
  72. * Hardware information
  73. */
  74. /* VX-pocket V2
  75. *
  76. * 1 DSP, 1 sync UER
  77. * 1 programmable clock (NIY)
  78. * 1 stereo analog input (line/micro)
  79. * 1 stereo analog output
  80. * Only output levels can be modified
  81. */
  82. static struct snd_vx_hardware vxpocket_hw = {
  83. .name = "VXPocket",
  84. .type = VX_TYPE_VXPOCKET,
  85. /* hardware specs */
  86. .num_codecs = 1,
  87. .num_ins = 1,
  88. .num_outs = 1,
  89. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  90. };
  91. /* VX-pocket 440
  92. *
  93. * 1 DSP, 1 sync UER, 1 sync World Clock (NIY)
  94. * SMPTE (NIY)
  95. * 2 stereo analog input (line/micro)
  96. * 2 stereo analog output
  97. * Only output levels can be modified
  98. * UER, but only for the first two inputs and outputs.
  99. */
  100. static struct snd_vx_hardware vxp440_hw = {
  101. .name = "VXPocket440",
  102. .type = VX_TYPE_VXP440,
  103. /* hardware specs */
  104. .num_codecs = 2,
  105. .num_ins = 2,
  106. .num_outs = 2,
  107. .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
  108. };
  109. /*
  110. * create vxpocket instance
  111. */
  112. static struct snd_vxpocket *snd_vxpocket_new(struct snd_card *card, int ibl)
  113. {
  114. dev_link_t *link; /* Info for cardmgr */
  115. struct vx_core *chip;
  116. struct snd_vxpocket *vxp;
  117. static struct snd_device_ops ops = {
  118. .dev_free = snd_vxpocket_dev_free,
  119. };
  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 NULL;
  124. if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops) < 0) {
  125. kfree(chip);
  126. return NULL;
  127. }
  128. chip->ibl.size = ibl;
  129. vxp = (struct snd_vxpocket *)chip;
  130. link = &vxp->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 | IRQ_HANDLE_PRESENT;
  135. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  136. link->irq.Handler = &snd_vx_irq_handler;
  137. link->irq.Instance = chip;
  138. link->conf.Attributes = CONF_ENABLE_IRQ;
  139. link->conf.Vcc = 50;
  140. link->conf.IntType = INT_MEMORY_AND_IO;
  141. link->conf.ConfigIndex = 1;
  142. link->conf.Present = PRESENT_OPTION;
  143. return vxp;
  144. }
  145. /**
  146. * snd_vxpocket_assign_resources - initialize the hardware and card instance.
  147. * @port: i/o port for the card
  148. * @irq: irq number for the card
  149. *
  150. * this function assigns the specified port and irq, boot the card,
  151. * create pcm and control instances, and initialize the rest hardware.
  152. *
  153. * returns 0 if successful, or a negative error code.
  154. */
  155. static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq)
  156. {
  157. int err;
  158. struct snd_card *card = chip->card;
  159. struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  160. snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
  161. vxp->port = port;
  162. sprintf(card->shortname, "Digigram %s", card->driver);
  163. sprintf(card->longname, "%s at 0x%x, irq %i",
  164. card->shortname, port, irq);
  165. chip->irq = irq;
  166. if ((err = snd_vx_setup_firmware(chip)) < 0)
  167. return err;
  168. return 0;
  169. }
  170. /*
  171. * configuration callback
  172. */
  173. #define CS_CHECK(fn, ret) \
  174. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  175. static void vxpocket_config(dev_link_t *link)
  176. {
  177. client_handle_t handle = link->handle;
  178. struct vx_core *chip = link->priv;
  179. struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  180. tuple_t tuple;
  181. cisparse_t *parse;
  182. u_short buf[32];
  183. int last_fn, last_ret;
  184. snd_printdd(KERN_DEBUG "vxpocket_config called\n");
  185. parse = kmalloc(sizeof(*parse), GFP_KERNEL);
  186. if (! parse) {
  187. snd_printk(KERN_ERR "vx: cannot allocate\n");
  188. return;
  189. }
  190. tuple.Attributes = 0;
  191. tuple.TupleData = (cisdata_t *)buf;
  192. tuple.TupleDataMax = sizeof(buf);
  193. tuple.TupleOffset = 0;
  194. tuple.DesiredTuple = CISTPL_CONFIG;
  195. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
  196. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
  197. CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, parse));
  198. link->conf.ConfigBase = parse->config.base;
  199. link->conf.Present = parse->config.rmask[0];
  200. /* redefine hardware record according to the VERSION1 string */
  201. tuple.DesiredTuple = CISTPL_VERS_1;
  202. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
  203. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
  204. CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, parse));
  205. if (! strcmp(parse->version_1.str + parse->version_1.ofs[1], "VX-POCKET")) {
  206. snd_printdd("VX-pocket is detected\n");
  207. } else {
  208. snd_printdd("VX-pocket 440 is detected\n");
  209. /* overwrite the hardware information */
  210. chip->hw = &vxp440_hw;
  211. chip->type = vxp440_hw.type;
  212. strcpy(chip->card->driver, vxp440_hw.name);
  213. }
  214. /* Configure card */
  215. link->state |= DEV_CONFIG;
  216. CS_CHECK(RequestIO, pcmcia_request_io(handle, &link->io));
  217. CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
  218. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
  219. chip->dev = &handle_to_dev(link->handle);
  220. snd_card_set_dev(chip->card, chip->dev);
  221. if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
  222. goto failed;
  223. link->dev = &vxp->node;
  224. link->state &= ~DEV_CONFIG_PENDING;
  225. kfree(parse);
  226. return;
  227. cs_failed:
  228. cs_error(link->handle, last_fn, last_ret);
  229. failed:
  230. pcmcia_release_configuration(link->handle);
  231. pcmcia_release_io(link->handle, &link->io);
  232. pcmcia_release_irq(link->handle, &link->irq);
  233. link->state &= ~DEV_CONFIG;
  234. kfree(parse);
  235. }
  236. #ifdef CONFIG_PM
  237. static int vxp_suspend(struct pcmcia_device *dev)
  238. {
  239. dev_link_t *link = dev_to_instance(dev);
  240. struct vx_core *chip = link->priv;
  241. snd_printdd(KERN_DEBUG "SUSPEND\n");
  242. link->state |= DEV_SUSPEND;
  243. if (chip) {
  244. snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
  245. snd_vx_suspend(chip, PMSG_SUSPEND);
  246. }
  247. snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n");
  248. if (link->state & DEV_CONFIG)
  249. pcmcia_release_configuration(link->handle);
  250. return 0;
  251. }
  252. static int vxp_resume(struct pcmcia_device *dev)
  253. {
  254. dev_link_t *link = dev_to_instance(dev);
  255. struct vx_core *chip = link->priv;
  256. snd_printdd(KERN_DEBUG "RESUME\n");
  257. link->state &= ~DEV_SUSPEND;
  258. snd_printdd(KERN_DEBUG "CARD_RESET\n");
  259. if (DEV_OK(link)) {
  260. //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
  261. snd_printdd(KERN_DEBUG "requestconfig...\n");
  262. pcmcia_request_configuration(link->handle, &link->conf);
  263. if (chip) {
  264. snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
  265. snd_vx_resume(chip);
  266. }
  267. }
  268. snd_printdd(KERN_DEBUG "resume done!\n");
  269. return 0;
  270. }
  271. #endif
  272. /*
  273. */
  274. static int vxpocket_attach(struct pcmcia_device *p_dev)
  275. {
  276. struct snd_card *card;
  277. struct snd_vxpocket *vxp;
  278. int i;
  279. /* find an empty slot from the card list */
  280. for (i = 0; i < SNDRV_CARDS; i++) {
  281. if (! card_alloc & (1 << i))
  282. break;
  283. }
  284. if (i >= SNDRV_CARDS) {
  285. snd_printk(KERN_ERR "vxpocket: too many cards found\n");
  286. return -EINVAL;
  287. }
  288. if (! enable[i])
  289. return -ENODEV; /* disabled explicitly */
  290. /* ok, create a card instance */
  291. card = snd_card_new(index[i], id[i], THIS_MODULE, 0);
  292. if (card == NULL) {
  293. snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
  294. return -ENOMEM;
  295. }
  296. vxp = snd_vxpocket_new(card, ibl[i]);
  297. if (! vxp) {
  298. snd_card_free(card);
  299. return -ENODEV;
  300. }
  301. card->private_data = vxp;
  302. vxp->index = i;
  303. card_alloc |= 1 << i;
  304. /* Chain drivers */
  305. vxp->link.next = NULL;
  306. vxp->link.handle = p_dev;
  307. vxp->link.state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  308. p_dev->instance = &vxp->link;
  309. vxpocket_config(&vxp->link);
  310. return 0;
  311. }
  312. static void vxpocket_detach(struct pcmcia_device *p_dev)
  313. {
  314. dev_link_t *link = dev_to_instance(p_dev);
  315. struct snd_vxpocket *vxp;
  316. struct vx_core *chip;
  317. if (! link)
  318. return;
  319. vxp = link->priv;
  320. chip = (struct vx_core *)vxp;
  321. card_alloc &= ~(1 << vxp->index);
  322. chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
  323. snd_card_disconnect(chip->card);
  324. vxpocket_release(link);
  325. snd_card_free_in_thread(chip->card);
  326. }
  327. /*
  328. * Module entry points
  329. */
  330. static struct pcmcia_device_id vxp_ids[] = {
  331. PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
  332. PCMCIA_DEVICE_NULL
  333. };
  334. MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
  335. static struct pcmcia_driver vxp_cs_driver = {
  336. .owner = THIS_MODULE,
  337. .drv = {
  338. .name = "snd-vxpocket",
  339. },
  340. .probe = vxpocket_attach,
  341. .remove = vxpocket_detach,
  342. .id_table = vxp_ids,
  343. #ifdef CONFIG_PM
  344. .suspend = vxp_suspend,
  345. .resume = vxp_resume,
  346. #endif
  347. };
  348. static int __init init_vxpocket(void)
  349. {
  350. return pcmcia_register_driver(&vxp_cs_driver);
  351. }
  352. static void __exit exit_vxpocket(void)
  353. {
  354. pcmcia_unregister_driver(&vxp_cs_driver);
  355. }
  356. module_init(init_vxpocket);
  357. module_exit(exit_vxpocket);