1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Digigram VXpocket V2/440 soundcards
5 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <sound/core.h>
15 #include <pcmcia/ciscode.h>
16 #include <pcmcia/cisreg.h>
17 #include <sound/initval.h>
18 #include <sound/tlv.h>
20 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
21 MODULE_DESCRIPTION("Digigram VXPocket");
22 MODULE_LICENSE("GPL");
24 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
25 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
26 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */
27 static int ibl[SNDRV_CARDS];
29 module_param_array(index, int, NULL, 0444);
30 MODULE_PARM_DESC(index, "Index value for VXPocket soundcard.");
31 module_param_array(id, charp, NULL, 0444);
32 MODULE_PARM_DESC(id, "ID string for VXPocket soundcard.");
33 module_param_array(enable, bool, NULL, 0444);
34 MODULE_PARM_DESC(enable, "Enable VXPocket soundcard.");
35 module_param_array(ibl, int, NULL, 0444);
36 MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard.");
42 static unsigned int card_alloc;
47 static void vxpocket_release(struct pcmcia_device *link)
49 free_irq(link->irq, link->priv);
50 pcmcia_disable_device(link);
54 * Hardware information
60 * 1 programmable clock (NIY)
61 * 1 stereo analog input (line/micro)
62 * 1 stereo analog output
63 * Only output levels can be modified
66 static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
68 static const struct snd_vx_hardware vxpocket_hw = {
70 .type = VX_TYPE_VXPOCKET,
76 .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
77 .output_level_db_scale = db_scale_old_vol,
82 * 1 DSP, 1 sync UER, 1 sync World Clock (NIY)
84 * 2 stereo analog input (line/micro)
85 * 2 stereo analog output
86 * Only output levels can be modified
87 * UER, but only for the first two inputs and outputs.
90 static const struct snd_vx_hardware vxp440_hw = {
91 .name = "VXPocket440",
92 .type = VX_TYPE_VXP440,
98 .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
99 .output_level_db_scale = db_scale_old_vol,
104 * create vxpocket instance
106 static int snd_vxpocket_new(struct snd_card *card, int ibl,
107 struct pcmcia_device *link,
108 struct snd_vxpocket **chip_ret)
110 struct vx_core *chip;
111 struct snd_vxpocket *vxp;
113 chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
114 sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
118 chip->ibl.size = ibl;
120 vxp = to_vxpocket(chip);
125 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
126 link->resource[0]->end = 16;
128 link->config_flags |= CONF_ENABLE_IRQ;
129 link->config_index = 1;
130 link->config_regs = PRESENT_OPTION;
138 * snd_vxpocket_assign_resources - initialize the hardware and card instance.
139 * @chip: VX core instance
140 * @port: i/o port for the card
141 * @irq: irq number for the card
143 * this function assigns the specified port and irq, boot the card,
144 * create pcm and control instances, and initialize the rest hardware.
146 * returns 0 if successful, or a negative error code.
148 static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq)
151 struct snd_card *card = chip->card;
152 struct snd_vxpocket *vxp = to_vxpocket(chip);
154 snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
157 sprintf(card->shortname, "Digigram %s", card->driver);
158 sprintf(card->longname, "%s at 0x%x, irq %i",
159 card->shortname, port, irq);
162 card->sync_irq = chip->irq;
164 err = snd_vx_setup_firmware(chip);
173 * configuration callback
176 static int vxpocket_config(struct pcmcia_device *link)
178 struct vx_core *chip = link->priv;
181 snd_printdd(KERN_DEBUG "vxpocket_config called\n");
183 /* redefine hardware record according to the VERSION1 string */
184 if (!strcmp(link->prod_id[1], "VX-POCKET")) {
185 snd_printdd("VX-pocket is detected\n");
187 snd_printdd("VX-pocket 440 is detected\n");
188 /* overwrite the hardware information */
189 chip->hw = &vxp440_hw;
190 chip->type = vxp440_hw.type;
191 strcpy(chip->card->driver, vxp440_hw.name);
194 ret = pcmcia_request_io(link);
198 ret = request_threaded_irq(link->irq, snd_vx_irq_handler,
199 snd_vx_threaded_irq_handler,
200 IRQF_SHARED, link->devname, link->priv);
204 ret = pcmcia_enable_device(link);
208 chip->dev = &link->dev;
210 if (snd_vxpocket_assign_resources(chip, link->resource[0]->start,
217 free_irq(link->irq, link->priv);
219 pcmcia_disable_device(link);
225 static int vxp_suspend(struct pcmcia_device *link)
227 struct vx_core *chip = link->priv;
229 snd_printdd(KERN_DEBUG "SUSPEND\n");
231 snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
232 snd_vx_suspend(chip);
238 static int vxp_resume(struct pcmcia_device *link)
240 struct vx_core *chip = link->priv;
242 snd_printdd(KERN_DEBUG "RESUME\n");
243 if (pcmcia_dev_present(link)) {
244 //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
246 snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
250 snd_printdd(KERN_DEBUG "resume done!\n");
260 static int vxpocket_probe(struct pcmcia_device *p_dev)
262 struct snd_card *card;
263 struct snd_vxpocket *vxp;
266 /* find an empty slot from the card list */
267 for (i = 0; i < SNDRV_CARDS; i++) {
268 if (!(card_alloc & (1 << i)))
271 if (i >= SNDRV_CARDS) {
272 snd_printk(KERN_ERR "vxpocket: too many cards found\n");
276 return -ENODEV; /* disabled explicitly */
278 /* ok, create a card instance */
279 err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE,
282 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
286 err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp);
291 card->private_data = vxp;
294 card_alloc |= 1 << i;
298 return vxpocket_config(p_dev);
301 static void vxpocket_detach(struct pcmcia_device *link)
303 struct snd_vxpocket *vxp;
304 struct vx_core *chip;
310 chip = (struct vx_core *)vxp;
311 card_alloc &= ~(1 << vxp->index);
313 chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
314 snd_card_disconnect(chip->card);
315 vxpocket_release(link);
316 snd_card_free_when_closed(chip->card);
320 * Module entry points
323 static const struct pcmcia_device_id vxp_ids[] = {
324 PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),
327 MODULE_DEVICE_TABLE(pcmcia, vxp_ids);
329 static struct pcmcia_driver vxp_cs_driver = {
330 .owner = THIS_MODULE,
331 .name = "snd-vxpocket",
332 .probe = vxpocket_probe,
333 .remove = vxpocket_detach,
336 .suspend = vxp_suspend,
337 .resume = vxp_resume,
340 module_pcmcia_driver(vxp_cs_driver);