brintos

brintos / linux-shallow public Read only

0
0
Text · 7.0 KiB · d2d5f64 Raw
330 lines · c
1// SPDX-License-Identifier: GPL-2.0-or-later2/*3 * Driver for Digigram VXpocket V2/440 soundcards4 *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 information55 */56 57/* VX-pocket V258 *59 * 1 DSP, 1 sync UER60 * 1 programmable clock (NIY)61 * 1 stereo analog input (line/micro)62 * 1 stereo analog output63 * Only output levels can be modified64 */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 44081 *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 output86 * Only output levels can be modified87 * 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 instance105 */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 instance140 * @port: i/o port for the card141 * @irq: irq number for the card142 *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 callback175 */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		strcpy(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_PM221 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#endif245 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	return vxpocket_config(p_dev);288}289 290static void vxpocket_detach(struct pcmcia_device *link)291{292	struct snd_vxpocket *vxp;293	struct vx_core *chip;294 295	if (! link)296		return;297 298	vxp = link->priv;299	chip = (struct vx_core *)vxp;300	card_alloc &= ~(1 << vxp->index);301 302	chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */303	snd_card_disconnect(chip->card);304	vxpocket_release(link);305	snd_card_free_when_closed(chip->card);306}307 308/*309 * Module entry points310 */311 312static const struct pcmcia_device_id vxp_ids[] = {313	PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100),314	PCMCIA_DEVICE_NULL315};316MODULE_DEVICE_TABLE(pcmcia, vxp_ids);317 318static struct pcmcia_driver vxp_cs_driver = {319	.owner		= THIS_MODULE,320	.name		= "snd-vxpocket",321	.probe		= vxpocket_probe,322	.remove		= vxpocket_detach,323	.id_table	= vxp_ids,324#ifdef CONFIG_PM325	.suspend	= vxp_suspend,326	.resume		= vxp_resume,327#endif328};329module_pcmcia_driver(vxp_cs_driver);330