File Index
Files and directories
Sign in
FILE

vxpocket.c

File preview with syntax highlighting.

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