Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * Driver for Digigram VXpocket V2/440 soundcards | |
4 | * | |
5 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> | |
1ac71e5a | 6 | |
1da177e4 LT |
7 | */ |
8 | ||
1da177e4 | 9 | |
1da177e4 | 10 | #include <linux/init.h> |
65a77217 | 11 | #include <linux/module.h> |
5a0e3ad6 | 12 | #include <linux/slab.h> |
1da177e4 | 13 | #include <sound/core.h> |
1da177e4 | 14 | #include "vxpocket.h" |
6d00a312 TI |
15 | #include <pcmcia/ciscode.h> |
16 | #include <pcmcia/cisreg.h> | |
1da177e4 | 17 | #include <sound/initval.h> |
1186ed8c | 18 | #include <sound/tlv.h> |
1da177e4 LT |
19 | |
20 | /* | |
21 | */ | |
22 | ||
1da177e4 | 23 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); |
6d00a312 | 24 | MODULE_DESCRIPTION("Digigram VXPocket"); |
1da177e4 | 25 | MODULE_LICENSE("GPL"); |
6d00a312 | 26 | MODULE_SUPPORTED_DEVICE("{{Digigram,VXPocket},{Digigram,VXPocket440}}"); |
1da177e4 LT |
27 | |
28 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | |
29 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | |
a67ff6a5 | 30 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ |
1da177e4 LT |
31 | static int ibl[SNDRV_CARDS]; |
32 | ||
33 | module_param_array(index, int, NULL, 0444); | |
6d00a312 | 34 | MODULE_PARM_DESC(index, "Index value for VXPocket soundcard."); |
1da177e4 | 35 | module_param_array(id, charp, NULL, 0444); |
6d00a312 | 36 | MODULE_PARM_DESC(id, "ID string for VXPocket soundcard."); |
1da177e4 | 37 | module_param_array(enable, bool, NULL, 0444); |
6d00a312 | 38 | MODULE_PARM_DESC(enable, "Enable VXPocket soundcard."); |
1da177e4 | 39 | module_param_array(ibl, int, NULL, 0444); |
6d00a312 | 40 | MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard."); |
1da177e4 LT |
41 | |
42 | ||
43 | /* | |
44 | */ | |
45 | ||
6d00a312 | 46 | static unsigned int card_alloc; |
1da177e4 | 47 | |
1da177e4 | 48 | |
6d00a312 TI |
49 | /* |
50 | */ | |
fba395ee | 51 | static void vxpocket_release(struct pcmcia_device *link) |
6d00a312 | 52 | { |
db0a5214 | 53 | free_irq(link->irq, link->priv); |
fba395ee | 54 | pcmcia_disable_device(link); |
6d00a312 | 55 | } |
1da177e4 | 56 | |
6d00a312 | 57 | /* |
2b29b13c | 58 | * destructor, called from snd_card_free_when_closed() |
6d00a312 | 59 | */ |
af26367f | 60 | static int snd_vxpocket_dev_free(struct snd_device *device) |
6d00a312 | 61 | { |
af26367f | 62 | struct vx_core *chip = device->device_data; |
1da177e4 | 63 | |
6d00a312 TI |
64 | snd_vx_free_firmware(chip); |
65 | kfree(chip); | |
66 | return 0; | |
67 | } | |
1da177e4 | 68 | |
1da177e4 | 69 | |
6d00a312 TI |
70 | /* |
71 | * Hardware information | |
72 | */ | |
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 | ||
0cb29ea0 | 83 | static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0); |
1186ed8c | 84 | |
f8ae2d29 | 85 | static const struct snd_vx_hardware vxpocket_hw = { |
6d00a312 TI |
86 | .name = "VXPocket", |
87 | .type = VX_TYPE_VXPOCKET, | |
1da177e4 LT |
88 | |
89 | /* hardware specs */ | |
6d00a312 TI |
90 | .num_codecs = 1, |
91 | .num_ins = 1, | |
92 | .num_outs = 1, | |
1da177e4 | 93 | .output_level_max = VX_ANALOG_OUT_LEVEL_MAX, |
1186ed8c | 94 | .output_level_db_scale = db_scale_old_vol, |
1da177e4 LT |
95 | }; |
96 | ||
6d00a312 TI |
97 | /* VX-pocket 440 |
98 | * | |
99 | * 1 DSP, 1 sync UER, 1 sync World Clock (NIY) | |
100 | * SMPTE (NIY) | |
101 | * 2 stereo analog input (line/micro) | |
102 | * 2 stereo analog output | |
103 | * Only output levels can be modified | |
104 | * UER, but only for the first two inputs and outputs. | |
105 | */ | |
1da177e4 | 106 | |
f8ae2d29 | 107 | static const struct snd_vx_hardware vxp440_hw = { |
6d00a312 TI |
108 | .name = "VXPocket440", |
109 | .type = VX_TYPE_VXP440, | |
110 | ||
111 | /* hardware specs */ | |
112 | .num_codecs = 2, | |
113 | .num_ins = 2, | |
114 | .num_outs = 2, | |
115 | .output_level_max = VX_ANALOG_OUT_LEVEL_MAX, | |
1186ed8c | 116 | .output_level_db_scale = db_scale_old_vol, |
6d00a312 TI |
117 | }; |
118 | ||
119 | ||
120 | /* | |
121 | * create vxpocket instance | |
122 | */ | |
2fa51107 TI |
123 | static int snd_vxpocket_new(struct snd_card *card, int ibl, |
124 | struct pcmcia_device *link, | |
125 | struct snd_vxpocket **chip_ret) | |
6d00a312 | 126 | { |
af26367f | 127 | struct vx_core *chip; |
6d00a312 | 128 | struct snd_vxpocket *vxp; |
0326564d | 129 | static const struct snd_device_ops ops = { |
6d00a312 TI |
130 | .dev_free = snd_vxpocket_dev_free, |
131 | }; | |
2fa51107 | 132 | int err; |
6d00a312 TI |
133 | |
134 | chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops, | |
af26367f | 135 | sizeof(struct snd_vxpocket) - sizeof(struct vx_core)); |
2fa51107 TI |
136 | if (!chip) |
137 | return -ENOMEM; | |
6d00a312 | 138 | |
2fa51107 TI |
139 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
140 | if (err < 0) { | |
6d00a312 | 141 | kfree(chip); |
2fa51107 | 142 | return err; |
6d00a312 TI |
143 | } |
144 | chip->ibl.size = ibl; | |
145 | ||
2e0de6ea | 146 | vxp = to_vxpocket(chip); |
6d00a312 | 147 | |
fba395ee | 148 | vxp->p_dev = link; |
6d00a312 TI |
149 | link->priv = chip; |
150 | ||
90abdc3b DB |
151 | link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; |
152 | link->resource[0]->end = 16; | |
6d00a312 | 153 | |
1ac71e5a | 154 | link->config_flags |= CONF_ENABLE_IRQ; |
7feabb64 DB |
155 | link->config_index = 1; |
156 | link->config_regs = PRESENT_OPTION; | |
6d00a312 | 157 | |
2fa51107 TI |
158 | *chip_ret = vxp; |
159 | return 0; | |
6d00a312 TI |
160 | } |
161 | ||
162 | ||
163 | /** | |
164 | * snd_vxpocket_assign_resources - initialize the hardware and card instance. | |
2a9e8df0 | 165 | * @chip: VX core instance |
6d00a312 TI |
166 | * @port: i/o port for the card |
167 | * @irq: irq number for the card | |
168 | * | |
169 | * this function assigns the specified port and irq, boot the card, | |
170 | * create pcm and control instances, and initialize the rest hardware. | |
171 | * | |
172 | * returns 0 if successful, or a negative error code. | |
173 | */ | |
af26367f | 174 | static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq) |
6d00a312 TI |
175 | { |
176 | int err; | |
af26367f | 177 | struct snd_card *card = chip->card; |
2e0de6ea | 178 | struct snd_vxpocket *vxp = to_vxpocket(chip); |
6d00a312 TI |
179 | |
180 | snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq); | |
181 | vxp->port = port; | |
182 | ||
183 | sprintf(card->shortname, "Digigram %s", card->driver); | |
184 | sprintf(card->longname, "%s at 0x%x, irq %i", | |
185 | card->shortname, port, irq); | |
186 | ||
187 | chip->irq = irq; | |
0ca4cefa | 188 | card->sync_irq = chip->irq; |
6d00a312 TI |
189 | |
190 | if ((err = snd_vx_setup_firmware(chip)) < 0) | |
191 | return err; | |
192 | ||
193 | return 0; | |
194 | } | |
195 | ||
196 | ||
197 | /* | |
198 | * configuration callback | |
199 | */ | |
200 | ||
15b99ac1 | 201 | static int vxpocket_config(struct pcmcia_device *link) |
6d00a312 | 202 | { |
af26367f | 203 | struct vx_core *chip = link->priv; |
7c5af6ff | 204 | int ret; |
6d00a312 TI |
205 | |
206 | snd_printdd(KERN_DEBUG "vxpocket_config called\n"); | |
6d00a312 TI |
207 | |
208 | /* redefine hardware record according to the VERSION1 string */ | |
af2b3b50 | 209 | if (!strcmp(link->prod_id[1], "VX-POCKET")) { |
6d00a312 TI |
210 | snd_printdd("VX-pocket is detected\n"); |
211 | } else { | |
212 | snd_printdd("VX-pocket 440 is detected\n"); | |
213 | /* overwrite the hardware information */ | |
214 | chip->hw = &vxp440_hw; | |
215 | chip->type = vxp440_hw.type; | |
216 | strcpy(chip->card->driver, vxp440_hw.name); | |
217 | } | |
218 | ||
90abdc3b | 219 | ret = pcmcia_request_io(link); |
7c5af6ff | 220 | if (ret) |
db0a5214 | 221 | goto failed_preirq; |
7c5af6ff | 222 | |
db0a5214 TI |
223 | ret = request_threaded_irq(link->irq, snd_vx_irq_handler, |
224 | snd_vx_threaded_irq_handler, | |
225 | IRQF_SHARED, link->devname, link->priv); | |
7c5af6ff | 226 | if (ret) |
db0a5214 | 227 | goto failed_preirq; |
7c5af6ff | 228 | |
1ac71e5a | 229 | ret = pcmcia_enable_device(link); |
7c5af6ff DB |
230 | if (ret) |
231 | goto failed; | |
6d00a312 | 232 | |
dd2e5a15 | 233 | chip->dev = &link->dev; |
6d00a312 | 234 | |
9a017a91 DB |
235 | if (snd_vxpocket_assign_resources(chip, link->resource[0]->start, |
236 | link->irq) < 0) | |
6d00a312 TI |
237 | goto failed; |
238 | ||
79ca4f3f | 239 | return 0; |
6d00a312 | 240 | |
db0a5214 TI |
241 | failed: |
242 | free_irq(link->irq, link->priv); | |
243 | failed_preirq: | |
fba395ee | 244 | pcmcia_disable_device(link); |
15b99ac1 | 245 | return -ENODEV; |
6d00a312 TI |
246 | } |
247 | ||
efe3cd10 | 248 | #ifdef CONFIG_PM |
6d00a312 | 249 | |
fba395ee | 250 | static int vxp_suspend(struct pcmcia_device *link) |
6d00a312 | 251 | { |
af26367f | 252 | struct vx_core *chip = link->priv; |
6d00a312 | 253 | |
efe3cd10 | 254 | snd_printdd(KERN_DEBUG "SUSPEND\n"); |
efe3cd10 DB |
255 | if (chip) { |
256 | snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n"); | |
68cb2b55 | 257 | snd_vx_suspend(chip); |
efe3cd10 | 258 | } |
efe3cd10 DB |
259 | |
260 | return 0; | |
261 | } | |
262 | ||
fba395ee | 263 | static int vxp_resume(struct pcmcia_device *link) |
efe3cd10 | 264 | { |
efe3cd10 DB |
265 | struct vx_core *chip = link->priv; |
266 | ||
267 | snd_printdd(KERN_DEBUG "RESUME\n"); | |
9940ec36 | 268 | if (pcmcia_dev_present(link)) { |
efe3cd10 | 269 | //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; |
0ed1cad1 | 270 | if (chip) { |
efe3cd10 DB |
271 | snd_printdd(KERN_DEBUG "calling snd_vx_resume\n"); |
272 | snd_vx_resume(chip); | |
6d00a312 | 273 | } |
6d00a312 | 274 | } |
efe3cd10 DB |
275 | snd_printdd(KERN_DEBUG "resume done!\n"); |
276 | ||
6d00a312 TI |
277 | return 0; |
278 | } | |
1da177e4 | 279 | |
efe3cd10 DB |
280 | #endif |
281 | ||
1da177e4 LT |
282 | |
283 | /* | |
284 | */ | |
15b99ac1 | 285 | static int vxpocket_probe(struct pcmcia_device *p_dev) |
1da177e4 | 286 | { |
af26367f | 287 | struct snd_card *card; |
6d00a312 | 288 | struct snd_vxpocket *vxp; |
bd7dd77c | 289 | int i, err; |
6d00a312 TI |
290 | |
291 | /* find an empty slot from the card list */ | |
292 | for (i = 0; i < SNDRV_CARDS; i++) { | |
27fe0f4b | 293 | if (!(card_alloc & (1 << i))) |
6d00a312 TI |
294 | break; |
295 | } | |
296 | if (i >= SNDRV_CARDS) { | |
297 | snd_printk(KERN_ERR "vxpocket: too many cards found\n"); | |
efe3cd10 | 298 | return -EINVAL; |
6d00a312 TI |
299 | } |
300 | if (! enable[i]) | |
efe3cd10 | 301 | return -ENODEV; /* disabled explicitly */ |
6d00a312 TI |
302 | |
303 | /* ok, create a card instance */ | |
5815f555 TI |
304 | err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE, |
305 | 0, &card); | |
bd7dd77c | 306 | if (err < 0) { |
6d00a312 | 307 | snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n"); |
bd7dd77c | 308 | return err; |
6d00a312 TI |
309 | } |
310 | ||
2fa51107 TI |
311 | err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp); |
312 | if (err < 0) { | |
6d00a312 | 313 | snd_card_free(card); |
2fa51107 | 314 | return err; |
6d00a312 | 315 | } |
0ed1cad1 | 316 | card->private_data = vxp; |
6d00a312 | 317 | |
adf111e6 | 318 | vxp->index = i; |
6d00a312 TI |
319 | card_alloc |= 1 << i; |
320 | ||
fd238232 | 321 | vxp->p_dev = p_dev; |
efe3cd10 | 322 | |
15b99ac1 | 323 | return vxpocket_config(p_dev); |
1da177e4 LT |
324 | } |
325 | ||
fba395ee | 326 | static void vxpocket_detach(struct pcmcia_device *link) |
1da177e4 | 327 | { |
6d00a312 | 328 | struct snd_vxpocket *vxp; |
af26367f | 329 | struct vx_core *chip; |
6d00a312 TI |
330 | |
331 | if (! link) | |
332 | return; | |
333 | ||
334 | vxp = link->priv; | |
af26367f | 335 | chip = (struct vx_core *)vxp; |
6d00a312 TI |
336 | card_alloc &= ~(1 << vxp->index); |
337 | ||
6d00a312 TI |
338 | chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */ |
339 | snd_card_disconnect(chip->card); | |
340 | vxpocket_release(link); | |
2b29b13c | 341 | snd_card_free_when_closed(chip->card); |
1da177e4 LT |
342 | } |
343 | ||
344 | /* | |
345 | * Module entry points | |
346 | */ | |
347 | ||
4ef7e714 | 348 | static const struct pcmcia_device_id vxp_ids[] = { |
e9a07afd DB |
349 | PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100), |
350 | PCMCIA_DEVICE_NULL | |
351 | }; | |
352 | MODULE_DEVICE_TABLE(pcmcia, vxp_ids); | |
353 | ||
1da177e4 LT |
354 | static struct pcmcia_driver vxp_cs_driver = { |
355 | .owner = THIS_MODULE, | |
2e9b981a | 356 | .name = "snd-vxpocket", |
15b99ac1 | 357 | .probe = vxpocket_probe, |
efe3cd10 | 358 | .remove = vxpocket_detach, |
e9a07afd | 359 | .id_table = vxp_ids, |
efe3cd10 DB |
360 | #ifdef CONFIG_PM |
361 | .suspend = vxp_suspend, | |
362 | .resume = vxp_resume, | |
363 | #endif | |
1da177e4 | 364 | }; |
b85c4a18 | 365 | module_pcmcia_driver(vxp_cs_driver); |