From ace9429bb58fd418f0c81d4c2835699bddf6bde6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:27:49 +0200 Subject: Adding upstream version 6.6.15. Signed-off-by: Daniel Baumann --- sound/pcmcia/Kconfig | 35 ++ sound/pcmcia/Makefile | 7 + sound/pcmcia/pdaudiocf/Makefile | 9 + sound/pcmcia/pdaudiocf/pdaudiocf.c | 292 ++++++++++++++++ sound/pcmcia/pdaudiocf/pdaudiocf.h | 128 +++++++ sound/pcmcia/pdaudiocf/pdaudiocf_core.c | 279 +++++++++++++++ sound/pcmcia/pdaudiocf/pdaudiocf_irq.c | 313 +++++++++++++++++ sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c | 274 +++++++++++++++ sound/pcmcia/vx/Makefile | 9 + sound/pcmcia/vx/vxp_mixer.c | 140 ++++++++ sound/pcmcia/vx/vxp_ops.c | 601 ++++++++++++++++++++++++++++++++ sound/pcmcia/vx/vxpocket.c | 340 ++++++++++++++++++ sound/pcmcia/vx/vxpocket.h | 79 +++++ 13 files changed, 2506 insertions(+) create mode 100644 sound/pcmcia/Kconfig create mode 100644 sound/pcmcia/Makefile create mode 100644 sound/pcmcia/pdaudiocf/Makefile create mode 100644 sound/pcmcia/pdaudiocf/pdaudiocf.c create mode 100644 sound/pcmcia/pdaudiocf/pdaudiocf.h create mode 100644 sound/pcmcia/pdaudiocf/pdaudiocf_core.c create mode 100644 sound/pcmcia/pdaudiocf/pdaudiocf_irq.c create mode 100644 sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c create mode 100644 sound/pcmcia/vx/Makefile create mode 100644 sound/pcmcia/vx/vxp_mixer.c create mode 100644 sound/pcmcia/vx/vxp_ops.c create mode 100644 sound/pcmcia/vx/vxpocket.c create mode 100644 sound/pcmcia/vx/vxpocket.h (limited to 'sound/pcmcia') diff --git a/sound/pcmcia/Kconfig b/sound/pcmcia/Kconfig new file mode 100644 index 0000000000..2e3dfc1ff5 --- /dev/null +++ b/sound/pcmcia/Kconfig @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0-only +# ALSA PCMCIA drivers + +menuconfig SND_PCMCIA + bool "PCMCIA sound devices" + depends on PCMCIA + depends on HAS_IOPORT + default y + help + Support for sound devices connected via the PCMCIA bus. + +if SND_PCMCIA && PCMCIA + +config SND_VXPOCKET + tristate "Digigram VXpocket" + select SND_VX_LIB + help + Say Y here to include support for Digigram VXpocket and + VXpocket 440 soundcards. + + To compile this driver as a module, choose M here: the module + will be called snd-vxpocket. + +config SND_PDAUDIOCF + tristate "Sound Core PDAudioCF" + select SND_PCM + help + Say Y here to include support for Sound Core PDAudioCF + soundcards. + + To compile this driver as a module, choose M here: the module + will be called snd-pdaudiocf. + +endif # SND_PCMCIA + diff --git a/sound/pcmcia/Makefile b/sound/pcmcia/Makefile new file mode 100644 index 0000000000..874f09a8e4 --- /dev/null +++ b/sound/pcmcia/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for ALSA +# Copyright (c) 2001 by Jaroslav Kysela +# + +obj-$(CONFIG_SND) += vx/ pdaudiocf/ diff --git a/sound/pcmcia/pdaudiocf/Makefile b/sound/pcmcia/pdaudiocf/Makefile new file mode 100644 index 0000000000..ea0d67576d --- /dev/null +++ b/sound/pcmcia/pdaudiocf/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for ALSA +# Copyright (c) 2004 by Jaroslav Kysela +# + +snd-pdaudiocf-objs := pdaudiocf.o pdaudiocf_core.o pdaudiocf_irq.o pdaudiocf_pcm.o + +obj-$(CONFIG_SND_PDAUDIOCF) += snd-pdaudiocf.o diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c new file mode 100644 index 0000000000..8363ec08df --- /dev/null +++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c @@ -0,0 +1,292 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Sound Core PDAudioCF soundcard + * + * Copyright (c) 2003 by Jaroslav Kysela + */ + +#include +#include +#include +#include +#include +#include "pdaudiocf.h" +#include +#include + +/* + */ + +#define CARD_NAME "PDAudio-CF" + +MODULE_AUTHOR("Jaroslav Kysela "); +MODULE_DESCRIPTION("Sound Core " CARD_NAME); +MODULE_LICENSE("GPL"); + +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ +static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ + +module_param_array(index, int, NULL, 0444); +MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); +module_param_array(id, charp, NULL, 0444); +MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); +module_param_array(enable, bool, NULL, 0444); +MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); + +/* + */ + +static struct snd_card *card_list[SNDRV_CARDS]; + +/* + * prototypes + */ +static int pdacf_config(struct pcmcia_device *link); +static void snd_pdacf_detach(struct pcmcia_device *p_dev); + +static void pdacf_release(struct pcmcia_device *link) +{ + free_irq(link->irq, link->priv); + pcmcia_disable_device(link); +} + +/* + * destructor + */ +static int snd_pdacf_free(struct snd_pdacf *pdacf) +{ + struct pcmcia_device *link = pdacf->p_dev; + + pdacf_release(link); + + card_list[pdacf->index] = NULL; + pdacf->card = NULL; + + kfree(pdacf); + return 0; +} + +static int snd_pdacf_dev_free(struct snd_device *device) +{ + struct snd_pdacf *chip = device->device_data; + return snd_pdacf_free(chip); +} + +/* + * snd_pdacf_attach - attach callback for cs + */ +static int snd_pdacf_probe(struct pcmcia_device *link) +{ + int i, err; + struct snd_pdacf *pdacf; + struct snd_card *card; + static const struct snd_device_ops ops = { + .dev_free = snd_pdacf_dev_free, + }; + + snd_printdd(KERN_DEBUG "pdacf_attach called\n"); + /* find an empty slot from the card list */ + for (i = 0; i < SNDRV_CARDS; i++) { + if (! card_list[i]) + break; + } + if (i >= SNDRV_CARDS) { + snd_printk(KERN_ERR "pdacf: too many cards found\n"); + return -EINVAL; + } + if (! enable[i]) + return -ENODEV; /* disabled explicitly */ + + /* ok, create a card instance */ + err = snd_card_new(&link->dev, index[i], id[i], THIS_MODULE, + 0, &card); + if (err < 0) { + snd_printk(KERN_ERR "pdacf: cannot create a card instance\n"); + return err; + } + + pdacf = snd_pdacf_create(card); + if (!pdacf) { + snd_card_free(card); + return -ENOMEM; + } + + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops); + if (err < 0) { + kfree(pdacf); + snd_card_free(card); + return err; + } + + pdacf->index = i; + card_list[i] = card; + + pdacf->p_dev = link; + link->priv = pdacf; + + link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; + link->resource[0]->end = 16; + + link->config_flags = CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ; + link->config_index = 1; + link->config_regs = PRESENT_OPTION; + + return pdacf_config(link); +} + + +/** + * snd_pdacf_assign_resources - initialize the hardware and card instance. + * @pdacf: context + * @port: i/o port for the card + * @irq: irq number for the card + * + * this function assigns the specified port and irq, boot the card, + * create pcm and control instances, and initialize the rest hardware. + * + * returns 0 if successful, or a negative error code. + */ +static int snd_pdacf_assign_resources(struct snd_pdacf *pdacf, int port, int irq) +{ + int err; + struct snd_card *card = pdacf->card; + + snd_printdd(KERN_DEBUG "pdacf assign resources: port = 0x%x, irq = %d\n", port, irq); + pdacf->port = port; + pdacf->irq = irq; + pdacf->chip_status |= PDAUDIOCF_STAT_IS_CONFIGURED; + + err = snd_pdacf_ak4117_create(pdacf); + if (err < 0) + return err; + + strcpy(card->driver, "PDAudio-CF"); + sprintf(card->shortname, "Core Sound %s", card->driver); + sprintf(card->longname, "%s at 0x%x, irq %i", + card->shortname, port, irq); + + err = snd_pdacf_pcm_new(pdacf); + if (err < 0) + return err; + + err = snd_card_register(card); + if (err < 0) + return err; + + return 0; +} + + +/* + * snd_pdacf_detach - detach callback for cs + */ +static void snd_pdacf_detach(struct pcmcia_device *link) +{ + struct snd_pdacf *chip = link->priv; + + snd_printdd(KERN_DEBUG "pdacf_detach called\n"); + + if (chip->chip_status & PDAUDIOCF_STAT_IS_CONFIGURED) + snd_pdacf_powerdown(chip); + chip->chip_status |= PDAUDIOCF_STAT_IS_STALE; /* to be sure */ + snd_card_disconnect(chip->card); + snd_card_free_when_closed(chip->card); +} + +/* + * configuration callback + */ + +static int pdacf_config(struct pcmcia_device *link) +{ + struct snd_pdacf *pdacf = link->priv; + int ret; + + snd_printdd(KERN_DEBUG "pdacf_config called\n"); + link->config_index = 0x5; + link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ; + + ret = pcmcia_request_io(link); + if (ret) + goto failed_preirq; + + ret = request_threaded_irq(link->irq, pdacf_interrupt, + pdacf_threaded_irq, + IRQF_SHARED, link->devname, link->priv); + if (ret) + goto failed_preirq; + + ret = pcmcia_enable_device(link); + if (ret) + goto failed; + + if (snd_pdacf_assign_resources(pdacf, link->resource[0]->start, + link->irq) < 0) + goto failed; + + pdacf->card->sync_irq = link->irq; + return 0; + + failed: + free_irq(link->irq, link->priv); +failed_preirq: + pcmcia_disable_device(link); + return -ENODEV; +} + +#ifdef CONFIG_PM + +static int pdacf_suspend(struct pcmcia_device *link) +{ + struct snd_pdacf *chip = link->priv; + + snd_printdd(KERN_DEBUG "SUSPEND\n"); + if (chip) { + snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n"); + snd_pdacf_suspend(chip); + } + + return 0; +} + +static int pdacf_resume(struct pcmcia_device *link) +{ + struct snd_pdacf *chip = link->priv; + + snd_printdd(KERN_DEBUG "RESUME\n"); + if (pcmcia_dev_present(link)) { + if (chip) { + snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n"); + snd_pdacf_resume(chip); + } + } + snd_printdd(KERN_DEBUG "resume done!\n"); + + return 0; +} + +#endif + +/* + * Module entry points + */ +static const struct pcmcia_device_id snd_pdacf_ids[] = { + /* this is too general PCMCIA_DEVICE_MANF_CARD(0x015d, 0x4c45), */ + PCMCIA_DEVICE_PROD_ID12("Core Sound","PDAudio-CF",0x396d19d2,0x71717b49), + PCMCIA_DEVICE_NULL +}; +MODULE_DEVICE_TABLE(pcmcia, snd_pdacf_ids); + +static struct pcmcia_driver pdacf_cs_driver = { + .owner = THIS_MODULE, + .name = "snd-pdaudiocf", + .probe = snd_pdacf_probe, + .remove = snd_pdacf_detach, + .id_table = snd_pdacf_ids, +#ifdef CONFIG_PM + .suspend = pdacf_suspend, + .resume = pdacf_resume, +#endif +}; +module_pcmcia_driver(pdacf_cs_driver); diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.h b/sound/pcmcia/pdaudiocf/pdaudiocf.h new file mode 100644 index 0000000000..12a29a2cb8 --- /dev/null +++ b/sound/pcmcia/pdaudiocf/pdaudiocf.h @@ -0,0 +1,128 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Driver for Sound Cors PDAudioCF soundcard + * + * Copyright (c) 2003 by Jaroslav Kysela + */ + +#ifndef __PDAUDIOCF_H +#define __PDAUDIOCF_H + +#include +#include +#include +#include +#include + +#include + +/* PDAUDIOCF registers */ +#define PDAUDIOCF_REG_MD 0x00 /* music data, R/O */ +#define PDAUDIOCF_REG_WDP 0x02 /* write data pointer / 2, R/O */ +#define PDAUDIOCF_REG_RDP 0x04 /* read data pointer / 2, R/O */ +#define PDAUDIOCF_REG_TCR 0x06 /* test control register W/O */ +#define PDAUDIOCF_REG_SCR 0x08 /* status and control, R/W (see bit description) */ +#define PDAUDIOCF_REG_ISR 0x0a /* interrupt status, R/O */ +#define PDAUDIOCF_REG_IER 0x0c /* interrupt enable, R/W */ +#define PDAUDIOCF_REG_AK_IFR 0x0e /* AK interface register, R/W */ + +/* PDAUDIOCF_REG_TCR */ +#define PDAUDIOCF_ELIMAKMBIT (1<<0) /* simulate AKM music data */ +#define PDAUDIOCF_TESTDATASEL (1<<1) /* test data selection, 0 = 0x55, 1 = pseudo-random */ + +/* PDAUDIOCF_REG_SCR */ +#define PDAUDIOCF_AK_SBP (1<<0) /* serial port busy flag */ +#define PDAUDIOCF_RST (1<<2) /* FPGA, AKM + SRAM buffer reset */ +#define PDAUDIOCF_PDN (1<<3) /* power down bit */ +#define PDAUDIOCF_CLKDIV0 (1<<4) /* choose 24.576Mhz clock divided by 1,2,3 or 4 */ +#define PDAUDIOCF_CLKDIV1 (1<<5) +#define PDAUDIOCF_RECORD (1<<6) /* start capturing to SRAM */ +#define PDAUDIOCF_AK_SDD (1<<7) /* music data detected */ +#define PDAUDIOCF_RED_LED_OFF (1<<8) /* red LED off override */ +#define PDAUDIOCF_BLUE_LED_OFF (1<<9) /* blue LED off override */ +#define PDAUDIOCF_DATAFMT0 (1<<10) /* data format bits: 00 = 16-bit, 01 = 18-bit */ +#define PDAUDIOCF_DATAFMT1 (1<<11) /* 10 = 20-bit, 11 = 24-bit, all right justified */ +#define PDAUDIOCF_FPGAREV(x) ((x>>12)&0x0f) /* FPGA revision */ + +/* PDAUDIOCF_REG_ISR */ +#define PDAUDIOCF_IRQLVL (1<<0) /* Buffer level IRQ */ +#define PDAUDIOCF_IRQOVR (1<<1) /* Overrun IRQ */ +#define PDAUDIOCF_IRQAKM (1<<2) /* AKM IRQ */ + +/* PDAUDIOCF_REG_IER */ +#define PDAUDIOCF_IRQLVLEN0 (1<<0) /* fill threshold levels; 00 = none, 01 = 1/8th of buffer */ +#define PDAUDIOCF_IRQLVLEN1 (1<<1) /* 10 = 1/4th of buffer, 11 = 1/2th of buffer */ +#define PDAUDIOCF_IRQOVREN (1<<2) /* enable overrun IRQ */ +#define PDAUDIOCF_IRQAKMEN (1<<3) /* enable AKM IRQ */ +#define PDAUDIOCF_BLUEDUTY0 (1<<8) /* blue LED duty cycle; 00 = 100%, 01 = 50% */ +#define PDAUDIOCF_BLUEDUTY1 (1<<9) /* 02 = 25%, 11 = 12% */ +#define PDAUDIOCF_REDDUTY0 (1<<10) /* red LED duty cycle; 00 = 100%, 01 = 50% */ +#define PDAUDIOCF_REDDUTY1 (1<<11) /* 02 = 25%, 11 = 12% */ +#define PDAUDIOCF_BLUESDD (1<<12) /* blue LED against SDD bit */ +#define PDAUDIOCF_BLUEMODULATE (1<<13) /* save power when 100% duty cycle selected */ +#define PDAUDIOCF_REDMODULATE (1<<14) /* save power when 100% duty cycle selected */ +#define PDAUDIOCF_HALFRATE (1<<15) /* slow both LED blinks by half (also spdif detect rate) */ + +/* chip status */ +#define PDAUDIOCF_STAT_IS_STALE (1<<0) +#define PDAUDIOCF_STAT_IS_CONFIGURED (1<<1) +#define PDAUDIOCF_STAT_IS_SUSPENDED (1<<2) + +struct snd_pdacf { + struct snd_card *card; + int index; + + unsigned long port; + int irq; + + struct mutex reg_lock; + unsigned short regmap[8]; + unsigned short suspend_reg_scr; + + spinlock_t ak4117_lock; + struct ak4117 *ak4117; + + unsigned int chip_status; + + struct snd_pcm *pcm; + struct snd_pcm_substream *pcm_substream; + unsigned int pcm_running: 1; + unsigned int pcm_channels; + unsigned int pcm_swab; + unsigned int pcm_little; + unsigned int pcm_frame; + unsigned int pcm_sample; + unsigned int pcm_xor; + unsigned int pcm_size; + unsigned int pcm_period; + unsigned int pcm_tdone; + unsigned int pcm_hwptr; + void *pcm_area; + + /* pcmcia stuff */ + struct pcmcia_device *p_dev; +}; + +static inline void pdacf_reg_write(struct snd_pdacf *chip, unsigned char reg, unsigned short val) +{ + outw(chip->regmap[reg>>1] = val, chip->port + reg); +} + +static inline unsigned short pdacf_reg_read(struct snd_pdacf *chip, unsigned char reg) +{ + return inw(chip->port + reg); +} + +struct snd_pdacf *snd_pdacf_create(struct snd_card *card); +int snd_pdacf_ak4117_create(struct snd_pdacf *pdacf); +void snd_pdacf_powerdown(struct snd_pdacf *chip); +#ifdef CONFIG_PM +int snd_pdacf_suspend(struct snd_pdacf *chip); +int snd_pdacf_resume(struct snd_pdacf *chip); +#endif +int snd_pdacf_pcm_new(struct snd_pdacf *chip); +irqreturn_t pdacf_interrupt(int irq, void *dev); +irqreturn_t pdacf_threaded_irq(int irq, void *dev); +void pdacf_reinit(struct snd_pdacf *chip, int resume); + +#endif /* __PDAUDIOCF_H */ diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_core.c b/sound/pcmcia/pdaudiocf/pdaudiocf_core.c new file mode 100644 index 0000000000..5537c0882a --- /dev/null +++ b/sound/pcmcia/pdaudiocf/pdaudiocf_core.c @@ -0,0 +1,279 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Sound Core PDAudioCF soundcard + * + * Copyright (c) 2003 by Jaroslav Kysela + */ + +#include +#include +#include +#include +#include "pdaudiocf.h" +#include + +/* + * + */ +static unsigned char pdacf_ak4117_read(void *private_data, unsigned char reg) +{ + struct snd_pdacf *chip = private_data; + unsigned long timeout; + unsigned long flags; + unsigned char res; + + spin_lock_irqsave(&chip->ak4117_lock, flags); + timeout = 1000; + while (pdacf_reg_read(chip, PDAUDIOCF_REG_SCR) & PDAUDIOCF_AK_SBP) { + udelay(5); + if (--timeout == 0) { + spin_unlock_irqrestore(&chip->ak4117_lock, flags); + snd_printk(KERN_ERR "AK4117 ready timeout (read)\n"); + return 0; + } + } + pdacf_reg_write(chip, PDAUDIOCF_REG_AK_IFR, (u16)reg << 8); + timeout = 1000; + while (pdacf_reg_read(chip, PDAUDIOCF_REG_SCR) & PDAUDIOCF_AK_SBP) { + udelay(5); + if (--timeout == 0) { + spin_unlock_irqrestore(&chip->ak4117_lock, flags); + snd_printk(KERN_ERR "AK4117 read timeout (read2)\n"); + return 0; + } + } + res = (unsigned char)pdacf_reg_read(chip, PDAUDIOCF_REG_AK_IFR); + spin_unlock_irqrestore(&chip->ak4117_lock, flags); + return res; +} + +static void pdacf_ak4117_write(void *private_data, unsigned char reg, unsigned char val) +{ + struct snd_pdacf *chip = private_data; + unsigned long timeout; + unsigned long flags; + + spin_lock_irqsave(&chip->ak4117_lock, flags); + timeout = 1000; + while (inw(chip->port + PDAUDIOCF_REG_SCR) & PDAUDIOCF_AK_SBP) { + udelay(5); + if (--timeout == 0) { + spin_unlock_irqrestore(&chip->ak4117_lock, flags); + snd_printk(KERN_ERR "AK4117 ready timeout (write)\n"); + return; + } + } + outw((u16)reg << 8 | val | (1<<13), chip->port + PDAUDIOCF_REG_AK_IFR); + spin_unlock_irqrestore(&chip->ak4117_lock, flags); +} + +#if 0 +void pdacf_dump(struct snd_pdacf *chip) +{ + printk(KERN_DEBUG "PDAUDIOCF DUMP (0x%lx):\n", chip->port); + printk(KERN_DEBUG "WPD : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_WDP)); + printk(KERN_DEBUG "RDP : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_RDP)); + printk(KERN_DEBUG "TCR : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_TCR)); + printk(KERN_DEBUG "SCR : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_SCR)); + printk(KERN_DEBUG "ISR : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_ISR)); + printk(KERN_DEBUG "IER : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_IER)); + printk(KERN_DEBUG "AK_IFR : 0x%x\n", + inw(chip->port + PDAUDIOCF_REG_AK_IFR)); +} +#endif + +static int pdacf_reset(struct snd_pdacf *chip, int powerdown) +{ + u16 val; + + val = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + val |= PDAUDIOCF_PDN; + val &= ~PDAUDIOCF_RECORD; /* for sure */ + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + udelay(5); + val |= PDAUDIOCF_RST; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + udelay(200); + val &= ~PDAUDIOCF_RST; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + udelay(5); + if (!powerdown) { + val &= ~PDAUDIOCF_PDN; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + udelay(200); + } + return 0; +} + +void pdacf_reinit(struct snd_pdacf *chip, int resume) +{ + pdacf_reset(chip, 0); + if (resume) + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, chip->suspend_reg_scr); + snd_ak4117_reinit(chip->ak4117); + pdacf_reg_write(chip, PDAUDIOCF_REG_TCR, chip->regmap[PDAUDIOCF_REG_TCR>>1]); + pdacf_reg_write(chip, PDAUDIOCF_REG_IER, chip->regmap[PDAUDIOCF_REG_IER>>1]); +} + +static void pdacf_proc_read(struct snd_info_entry * entry, + struct snd_info_buffer *buffer) +{ + struct snd_pdacf *chip = entry->private_data; + u16 tmp; + + snd_iprintf(buffer, "PDAudioCF\n\n"); + tmp = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + snd_iprintf(buffer, "FPGA revision : 0x%x\n", PDAUDIOCF_FPGAREV(tmp)); + +} + +static void pdacf_proc_init(struct snd_pdacf *chip) +{ + snd_card_ro_proc_new(chip->card, "pdaudiocf", chip, pdacf_proc_read); +} + +struct snd_pdacf *snd_pdacf_create(struct snd_card *card) +{ + struct snd_pdacf *chip; + + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (chip == NULL) + return NULL; + chip->card = card; + mutex_init(&chip->reg_lock); + spin_lock_init(&chip->ak4117_lock); + card->private_data = chip; + + pdacf_proc_init(chip); + return chip; +} + +static void snd_pdacf_ak4117_change(struct ak4117 *ak4117, unsigned char c0, unsigned char c1) +{ + struct snd_pdacf *chip = ak4117->change_callback_private; + u16 val; + + if (!(c0 & AK4117_UNLCK)) + return; + mutex_lock(&chip->reg_lock); + val = chip->regmap[PDAUDIOCF_REG_SCR>>1]; + if (ak4117->rcs0 & AK4117_UNLCK) + val |= PDAUDIOCF_BLUE_LED_OFF; + else + val &= ~PDAUDIOCF_BLUE_LED_OFF; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + mutex_unlock(&chip->reg_lock); +} + +int snd_pdacf_ak4117_create(struct snd_pdacf *chip) +{ + int err; + u16 val; + /* design note: if we unmask PLL unlock, parity, valid, audio or auto bit interrupts */ + /* from AK4117 then INT1 pin from AK4117 will be high all time, because PCMCIA interrupts are */ + /* egde based and FPGA does logical OR for all interrupt sources, we cannot use these */ + /* high-rate sources */ + static const unsigned char pgm[5] = { + AK4117_XTL_24_576M | AK4117_EXCT, /* AK4117_REG_PWRDN */ + AK4117_CM_PLL_XTAL | AK4117_PKCS_128fs | AK4117_XCKS_128fs, /* AK4117_REQ_CLOCK */ + AK4117_EFH_1024LRCLK | AK4117_DIF_24R | AK4117_IPS, /* AK4117_REG_IO */ + 0xff, /* AK4117_REG_INT0_MASK */ + AK4117_MAUTO | AK4117_MAUD | AK4117_MULK | AK4117_MPAR | AK4117_MV, /* AK4117_REG_INT1_MASK */ + }; + + err = pdacf_reset(chip, 0); + if (err < 0) + return err; + err = snd_ak4117_create(chip->card, pdacf_ak4117_read, pdacf_ak4117_write, pgm, chip, &chip->ak4117); + if (err < 0) + return err; + + val = pdacf_reg_read(chip, PDAUDIOCF_REG_TCR); +#if 1 /* normal operation */ + val &= ~(PDAUDIOCF_ELIMAKMBIT|PDAUDIOCF_TESTDATASEL); +#else /* debug */ + val |= PDAUDIOCF_ELIMAKMBIT; + val &= ~PDAUDIOCF_TESTDATASEL; +#endif + pdacf_reg_write(chip, PDAUDIOCF_REG_TCR, val); + + /* setup the FPGA to match AK4117 setup */ + val = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + val &= ~(PDAUDIOCF_CLKDIV0 | PDAUDIOCF_CLKDIV1); /* use 24.576Mhz clock */ + val &= ~(PDAUDIOCF_RED_LED_OFF|PDAUDIOCF_BLUE_LED_OFF); + val |= PDAUDIOCF_DATAFMT0 | PDAUDIOCF_DATAFMT1; /* 24-bit data */ + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + + /* setup LEDs and IRQ */ + val = pdacf_reg_read(chip, PDAUDIOCF_REG_IER); + val &= ~(PDAUDIOCF_IRQLVLEN0 | PDAUDIOCF_IRQLVLEN1); + val &= ~(PDAUDIOCF_BLUEDUTY0 | PDAUDIOCF_REDDUTY0 | PDAUDIOCF_REDDUTY1); + val |= PDAUDIOCF_BLUEDUTY1 | PDAUDIOCF_HALFRATE; + val |= PDAUDIOCF_IRQOVREN | PDAUDIOCF_IRQAKMEN; + pdacf_reg_write(chip, PDAUDIOCF_REG_IER, val); + + chip->ak4117->change_callback_private = chip; + chip->ak4117->change_callback = snd_pdacf_ak4117_change; + + /* update LED status */ + snd_pdacf_ak4117_change(chip->ak4117, AK4117_UNLCK, 0); + + return 0; +} + +void snd_pdacf_powerdown(struct snd_pdacf *chip) +{ + u16 val; + + val = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + chip->suspend_reg_scr = val; + val |= PDAUDIOCF_RED_LED_OFF | PDAUDIOCF_BLUE_LED_OFF; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); + /* disable interrupts, but use direct write to preserve old register value in chip->regmap */ + val = inw(chip->port + PDAUDIOCF_REG_IER); + val &= ~(PDAUDIOCF_IRQOVREN|PDAUDIOCF_IRQAKMEN|PDAUDIOCF_IRQLVLEN0|PDAUDIOCF_IRQLVLEN1); + outw(val, chip->port + PDAUDIOCF_REG_IER); + pdacf_reset(chip, 1); +} + +#ifdef CONFIG_PM + +int snd_pdacf_suspend(struct snd_pdacf *chip) +{ + u16 val; + + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); + /* disable interrupts, but use direct write to preserve old register value in chip->regmap */ + val = inw(chip->port + PDAUDIOCF_REG_IER); + val &= ~(PDAUDIOCF_IRQOVREN|PDAUDIOCF_IRQAKMEN|PDAUDIOCF_IRQLVLEN0|PDAUDIOCF_IRQLVLEN1); + outw(val, chip->port + PDAUDIOCF_REG_IER); + chip->chip_status |= PDAUDIOCF_STAT_IS_SUSPENDED; /* ignore interrupts from now */ + snd_pdacf_powerdown(chip); + return 0; +} + +static inline int check_signal(struct snd_pdacf *chip) +{ + return (chip->ak4117->rcs0 & AK4117_UNLCK) == 0; +} + +int snd_pdacf_resume(struct snd_pdacf *chip) +{ + int timeout = 40; + + pdacf_reinit(chip, 1); + /* wait for AK4117's PLL */ + while (timeout-- > 0 && + (snd_ak4117_external_rate(chip->ak4117) <= 0 || !check_signal(chip))) + mdelay(1); + chip->chip_status &= ~PDAUDIOCF_STAT_IS_SUSPENDED; + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); + return 0; +} +#endif diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c b/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c new file mode 100644 index 0000000000..f134b4a462 --- /dev/null +++ b/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c @@ -0,0 +1,313 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Sound Core PDAudioCF soundcard + * + * Copyright (c) 2003 by Jaroslav Kysela + */ + +#include +#include "pdaudiocf.h" +#include +#include + +/* + * + */ +irqreturn_t pdacf_interrupt(int irq, void *dev) +{ + struct snd_pdacf *chip = dev; + unsigned short stat; + bool wake_thread = false; + + if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE| + PDAUDIOCF_STAT_IS_CONFIGURED| + PDAUDIOCF_STAT_IS_SUSPENDED)) != PDAUDIOCF_STAT_IS_CONFIGURED) + return IRQ_HANDLED; /* IRQ_NONE here? */ + + stat = inw(chip->port + PDAUDIOCF_REG_ISR); + if (stat & (PDAUDIOCF_IRQLVL|PDAUDIOCF_IRQOVR)) { + if (stat & PDAUDIOCF_IRQOVR) /* should never happen */ + snd_printk(KERN_ERR "PDAUDIOCF SRAM buffer overrun detected!\n"); + if (chip->pcm_substream) + wake_thread = true; + if (!(stat & PDAUDIOCF_IRQAKM)) + stat |= PDAUDIOCF_IRQAKM; /* check rate */ + } + if (get_irq_regs() != NULL) + snd_ak4117_check_rate_and_errors(chip->ak4117, 0); + return wake_thread ? IRQ_WAKE_THREAD : IRQ_HANDLED; +} + +static inline void pdacf_transfer_mono16(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + while (size-- > 0) { + *dst++ = inw(rdp_port) ^ xor; + inw(rdp_port); + } +} + +static inline void pdacf_transfer_mono32(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + inw(rdp_port); + *dst++ = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor; + } +} + +static inline void pdacf_transfer_stereo16(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + while (size-- > 0) { + *dst++ = inw(rdp_port) ^ xor; + *dst++ = inw(rdp_port) ^ xor; + } +} + +static inline void pdacf_transfer_stereo32(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2, val3; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + val3 = inw(rdp_port); + *dst++ = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor; + *dst++ = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor; + } +} + +static inline void pdacf_transfer_mono16sw(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + while (size-- > 0) { + *dst++ = swab16(inw(rdp_port) ^ xor); + inw(rdp_port); + } +} + +static inline void pdacf_transfer_mono32sw(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + inw(rdp_port); + *dst++ = swab32((((val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor); + } +} + +static inline void pdacf_transfer_stereo16sw(u16 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + while (size-- > 0) { + *dst++ = swab16(inw(rdp_port) ^ xor); + *dst++ = swab16(inw(rdp_port) ^ xor); + } +} + +static inline void pdacf_transfer_stereo32sw(u32 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2, val3; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + val3 = inw(rdp_port); + *dst++ = swab32((((val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor); + *dst++ = swab32((((u32)val3 << 16) | (val2 & 0xff00)) ^ xor); + } +} + +static inline void pdacf_transfer_mono24le(u8 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2; + register u32 xval1; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + inw(rdp_port); + xval1 = (((val2 & 0xff) << 8) | (val1 << 16)) ^ xor; + *dst++ = (u8)(xval1 >> 8); + *dst++ = (u8)(xval1 >> 16); + *dst++ = (u8)(xval1 >> 24); + } +} + +static inline void pdacf_transfer_mono24be(u8 *dst, u16 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2; + register u32 xval1; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + inw(rdp_port); + xval1 = (((val2 & 0xff) << 8) | (val1 << 16)) ^ xor; + *dst++ = (u8)(xval1 >> 24); + *dst++ = (u8)(xval1 >> 16); + *dst++ = (u8)(xval1 >> 8); + } +} + +static inline void pdacf_transfer_stereo24le(u8 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2, val3; + register u32 xval1, xval2; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + val3 = inw(rdp_port); + xval1 = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor; + xval2 = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor; + *dst++ = (u8)(xval1 >> 8); + *dst++ = (u8)(xval1 >> 16); + *dst++ = (u8)(xval1 >> 24); + *dst++ = (u8)(xval2 >> 8); + *dst++ = (u8)(xval2 >> 16); + *dst++ = (u8)(xval2 >> 24); + } +} + +static inline void pdacf_transfer_stereo24be(u8 *dst, u32 xor, unsigned int size, unsigned long rdp_port) +{ + register u16 val1, val2, val3; + register u32 xval1, xval2; + + while (size-- > 0) { + val1 = inw(rdp_port); + val2 = inw(rdp_port); + val3 = inw(rdp_port); + xval1 = ((((u32)val2 & 0xff) << 24) | ((u32)val1 << 8)) ^ xor; + xval2 = (((u32)val3 << 16) | (val2 & 0xff00)) ^ xor; + *dst++ = (u8)(xval1 >> 24); + *dst++ = (u8)(xval1 >> 16); + *dst++ = (u8)(xval1 >> 8); + *dst++ = (u8)(xval2 >> 24); + *dst++ = (u8)(xval2 >> 16); + *dst++ = (u8)(xval2 >> 8); + } +} + +static void pdacf_transfer(struct snd_pdacf *chip, unsigned int size, unsigned int off) +{ + unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD; + unsigned int xor = chip->pcm_xor; + + if (chip->pcm_sample == 3) { + if (chip->pcm_little) { + if (chip->pcm_channels == 1) { + pdacf_transfer_mono24le((char *)chip->pcm_area + (off * 3), xor, size, rdp_port); + } else { + pdacf_transfer_stereo24le((char *)chip->pcm_area + (off * 6), xor, size, rdp_port); + } + } else { + if (chip->pcm_channels == 1) { + pdacf_transfer_mono24be((char *)chip->pcm_area + (off * 3), xor, size, rdp_port); + } else { + pdacf_transfer_stereo24be((char *)chip->pcm_area + (off * 6), xor, size, rdp_port); + } + } + return; + } + if (chip->pcm_swab == 0) { + if (chip->pcm_channels == 1) { + if (chip->pcm_frame == 2) { + pdacf_transfer_mono16((u16 *)chip->pcm_area + off, xor, size, rdp_port); + } else { + pdacf_transfer_mono32((u32 *)chip->pcm_area + off, xor, size, rdp_port); + } + } else { + if (chip->pcm_frame == 2) { + pdacf_transfer_stereo16((u16 *)chip->pcm_area + (off * 2), xor, size, rdp_port); + } else { + pdacf_transfer_stereo32((u32 *)chip->pcm_area + (off * 2), xor, size, rdp_port); + } + } + } else { + if (chip->pcm_channels == 1) { + if (chip->pcm_frame == 2) { + pdacf_transfer_mono16sw((u16 *)chip->pcm_area + off, xor, size, rdp_port); + } else { + pdacf_transfer_mono32sw((u32 *)chip->pcm_area + off, xor, size, rdp_port); + } + } else { + if (chip->pcm_frame == 2) { + pdacf_transfer_stereo16sw((u16 *)chip->pcm_area + (off * 2), xor, size, rdp_port); + } else { + pdacf_transfer_stereo32sw((u32 *)chip->pcm_area + (off * 2), xor, size, rdp_port); + } + } + } +} + +irqreturn_t pdacf_threaded_irq(int irq, void *dev) +{ + struct snd_pdacf *chip = dev; + int size, off, cont, rdp, wdp; + + if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE|PDAUDIOCF_STAT_IS_CONFIGURED)) != PDAUDIOCF_STAT_IS_CONFIGURED) + return IRQ_HANDLED; + + if (chip->pcm_substream == NULL || chip->pcm_substream->runtime == NULL || !snd_pcm_running(chip->pcm_substream)) + return IRQ_HANDLED; + + rdp = inw(chip->port + PDAUDIOCF_REG_RDP); + wdp = inw(chip->port + PDAUDIOCF_REG_WDP); + /* printk(KERN_DEBUG "TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); */ + size = wdp - rdp; + if (size < 0) + size += 0x10000; + if (size == 0) + size = 0x10000; + size /= chip->pcm_frame; + if (size > 64) + size -= 32; + +#if 0 + chip->pcm_hwptr += size; + chip->pcm_hwptr %= chip->pcm_size; + chip->pcm_tdone += size; + if (chip->pcm_frame == 2) { + unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD; + while (size-- > 0) { + inw(rdp_port); + inw(rdp_port); + } + } else { + unsigned long rdp_port = chip->port + PDAUDIOCF_REG_MD; + while (size-- > 0) { + inw(rdp_port); + inw(rdp_port); + inw(rdp_port); + } + } +#else + off = chip->pcm_hwptr + chip->pcm_tdone; + off %= chip->pcm_size; + chip->pcm_tdone += size; + while (size > 0) { + cont = chip->pcm_size - off; + if (cont > size) + cont = size; + pdacf_transfer(chip, cont, off); + off += cont; + off %= chip->pcm_size; + size -= cont; + } +#endif + mutex_lock(&chip->reg_lock); + while (chip->pcm_tdone >= chip->pcm_period) { + chip->pcm_hwptr += chip->pcm_period; + chip->pcm_hwptr %= chip->pcm_size; + chip->pcm_tdone -= chip->pcm_period; + mutex_unlock(&chip->reg_lock); + snd_pcm_period_elapsed(chip->pcm_substream); + mutex_lock(&chip->reg_lock); + } + mutex_unlock(&chip->reg_lock); + return IRQ_HANDLED; +} diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c new file mode 100644 index 0000000000..aaa82ec365 --- /dev/null +++ b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c @@ -0,0 +1,274 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Sound Core PDAudioCF soundcards + * + * PCM part + * + * Copyright (c) 2003 by Jaroslav Kysela + */ + +#include +#include +#include +#include "pdaudiocf.h" + + +/* + * clear the SRAM contents + */ +static int pdacf_pcm_clear_sram(struct snd_pdacf *chip) +{ + int max_loop = 64 * 1024; + + while (inw(chip->port + PDAUDIOCF_REG_RDP) != inw(chip->port + PDAUDIOCF_REG_WDP)) { + if (max_loop-- < 0) + return -EIO; + inw(chip->port + PDAUDIOCF_REG_MD); + } + return 0; +} + +/* + * pdacf_pcm_trigger - trigger callback for capture + */ +static int pdacf_pcm_trigger(struct snd_pcm_substream *subs, int cmd) +{ + struct snd_pdacf *chip = snd_pcm_substream_chip(subs); + struct snd_pcm_runtime *runtime = subs->runtime; + int inc, ret = 0, rate; + unsigned short mask, val, tmp; + + if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE) + return -EBUSY; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + chip->pcm_hwptr = 0; + chip->pcm_tdone = 0; + fallthrough; + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_RESUME: + mask = 0; + val = PDAUDIOCF_RECORD; + inc = 1; + rate = snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_STAT|AK4117_CHECK_NO_RATE); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_SUSPEND: + mask = PDAUDIOCF_RECORD; + val = 0; + inc = -1; + rate = 0; + break; + default: + return -EINVAL; + } + mutex_lock(&chip->reg_lock); + chip->pcm_running += inc; + tmp = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + if (chip->pcm_running) { + if ((chip->ak4117->rcs0 & AK4117_UNLCK) || runtime->rate != rate) { + chip->pcm_running -= inc; + ret = -EIO; + goto __end; + } + } + tmp &= ~mask; + tmp |= val; + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, tmp); + __end: + mutex_unlock(&chip->reg_lock); + snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_RATE); + return ret; +} + +/* + * pdacf_pcm_prepare - prepare callback for playback and capture + */ +static int pdacf_pcm_prepare(struct snd_pcm_substream *subs) +{ + struct snd_pdacf *chip = snd_pcm_substream_chip(subs); + struct snd_pcm_runtime *runtime = subs->runtime; + u16 val, nval, aval; + + if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE) + return -EBUSY; + + chip->pcm_channels = runtime->channels; + + chip->pcm_little = snd_pcm_format_little_endian(runtime->format) > 0; +#ifdef SNDRV_LITTLE_ENDIAN + chip->pcm_swab = snd_pcm_format_big_endian(runtime->format) > 0; +#else + chip->pcm_swab = chip->pcm_little; +#endif + + if (snd_pcm_format_unsigned(runtime->format)) + chip->pcm_xor = 0x80008000; + + if (pdacf_pcm_clear_sram(chip) < 0) + return -EIO; + + val = nval = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); + nval &= ~(PDAUDIOCF_DATAFMT0|PDAUDIOCF_DATAFMT1); + switch (runtime->format) { + case SNDRV_PCM_FORMAT_S16_LE: + case SNDRV_PCM_FORMAT_S16_BE: + break; + default: /* 24-bit */ + nval |= PDAUDIOCF_DATAFMT0 | PDAUDIOCF_DATAFMT1; + break; + } + aval = 0; + chip->pcm_sample = 4; + switch (runtime->format) { + case SNDRV_PCM_FORMAT_S16_LE: + case SNDRV_PCM_FORMAT_S16_BE: + aval = AK4117_DIF_16R; + chip->pcm_frame = 2; + chip->pcm_sample = 2; + break; + case SNDRV_PCM_FORMAT_S24_3LE: + case SNDRV_PCM_FORMAT_S24_3BE: + chip->pcm_sample = 3; + fallthrough; + default: /* 24-bit */ + aval = AK4117_DIF_24R; + chip->pcm_frame = 3; + chip->pcm_xor &= 0xffff0000; + break; + } + + if (val != nval) { + snd_ak4117_reg_write(chip->ak4117, AK4117_REG_IO, AK4117_DIF2|AK4117_DIF1|AK4117_DIF0, aval); + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, nval); + } + + val = pdacf_reg_read(chip, PDAUDIOCF_REG_IER); + val &= ~(PDAUDIOCF_IRQLVLEN1); + val |= PDAUDIOCF_IRQLVLEN0; + pdacf_reg_write(chip, PDAUDIOCF_REG_IER, val); + + chip->pcm_size = runtime->buffer_size; + chip->pcm_period = runtime->period_size; + chip->pcm_area = runtime->dma_area; + + return 0; +} + + +/* + * capture hw information + */ + +static const struct snd_pcm_hardware pdacf_pcm_capture_hw = { + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_BATCH), + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | + SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, + .rates = SNDRV_PCM_RATE_32000 | + SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | + SNDRV_PCM_RATE_88200 | + SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_176400 | + SNDRV_PCM_RATE_192000, + .rate_min = 32000, + .rate_max = 192000, + .channels_min = 1, + .channels_max = 2, + .buffer_bytes_max = (512*1024), + .period_bytes_min = 8*1024, + .period_bytes_max = (64*1024), + .periods_min = 2, + .periods_max = 128, + .fifo_size = 0, +}; + + +/* + * pdacf_pcm_capture_open - open callback for capture + */ +static int pdacf_pcm_capture_open(struct snd_pcm_substream *subs) +{ + struct snd_pcm_runtime *runtime = subs->runtime; + struct snd_pdacf *chip = snd_pcm_substream_chip(subs); + + if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE) + return -EBUSY; + + runtime->hw = pdacf_pcm_capture_hw; + runtime->private_data = chip; + chip->pcm_substream = subs; + + return 0; +} + +/* + * pdacf_pcm_capture_close - close callback for capture + */ +static int pdacf_pcm_capture_close(struct snd_pcm_substream *subs) +{ + struct snd_pdacf *chip = snd_pcm_substream_chip(subs); + + if (!chip) + return -EINVAL; + pdacf_reinit(chip, 0); + chip->pcm_substream = NULL; + return 0; +} + + +/* + * pdacf_pcm_capture_pointer - pointer callback for capture + */ +static snd_pcm_uframes_t pdacf_pcm_capture_pointer(struct snd_pcm_substream *subs) +{ + struct snd_pdacf *chip = snd_pcm_substream_chip(subs); + return chip->pcm_hwptr; +} + +/* + * operators for PCM capture + */ +static const struct snd_pcm_ops pdacf_pcm_capture_ops = { + .open = pdacf_pcm_capture_open, + .close = pdacf_pcm_capture_close, + .prepare = pdacf_pcm_prepare, + .trigger = pdacf_pcm_trigger, + .pointer = pdacf_pcm_capture_pointer, +}; + + +/* + * snd_pdacf_pcm_new - create and initialize a pcm + */ +int snd_pdacf_pcm_new(struct snd_pdacf *chip) +{ + struct snd_pcm *pcm; + int err; + + err = snd_pcm_new(chip->card, "PDAudioCF", 0, 0, 1, &pcm); + if (err < 0) + return err; + + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pdacf_pcm_capture_ops); + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, + 0, 0); + + pcm->private_data = chip; + pcm->info_flags = 0; + pcm->nonatomic = true; + strcpy(pcm->name, chip->card->shortname); + chip->pcm = pcm; + + err = snd_ak4117_build(chip->ak4117, pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); + if (err < 0) + return err; + + return 0; +} diff --git a/sound/pcmcia/vx/Makefile b/sound/pcmcia/vx/Makefile new file mode 100644 index 0000000000..b25006e4d2 --- /dev/null +++ b/sound/pcmcia/vx/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for ALSA +# Copyright (c) 2001 by Jaroslav Kysela +# + +snd-vxpocket-objs := vxpocket.o vxp_ops.o vxp_mixer.o + +obj-$(CONFIG_SND_VXPOCKET) += snd-vxpocket.o diff --git a/sound/pcmcia/vx/vxp_mixer.c b/sound/pcmcia/vx/vxp_mixer.c new file mode 100644 index 0000000000..bc21144758 --- /dev/null +++ b/sound/pcmcia/vx/vxp_mixer.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Digigram VXpocket soundcards + * + * VX-pocket mixer + * + * Copyright (c) 2002 by Takashi Iwai + */ + +#include +#include +#include +#include "vxpocket.h" + +#define MIC_LEVEL_MIN 0 +#define MIC_LEVEL_MAX 8 + +/* + * mic level control (for VXPocket) + */ +static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = MIC_LEVEL_MAX; + return 0; +} + +static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct vx_core *_chip = snd_kcontrol_chip(kcontrol); + struct snd_vxpocket *chip = to_vxpocket(_chip); + ucontrol->value.integer.value[0] = chip->mic_level; + return 0; +} + +static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct vx_core *_chip = snd_kcontrol_chip(kcontrol); + struct snd_vxpocket *chip = to_vxpocket(_chip); + unsigned int val = ucontrol->value.integer.value[0]; + + if (val > MIC_LEVEL_MAX) + return -EINVAL; + mutex_lock(&_chip->mixer_mutex); + if (chip->mic_level != ucontrol->value.integer.value[0]) { + vx_set_mic_level(_chip, ucontrol->value.integer.value[0]); + chip->mic_level = ucontrol->value.integer.value[0]; + mutex_unlock(&_chip->mixer_mutex); + return 1; + } + mutex_unlock(&_chip->mixer_mutex); + return 0; +} + +static const DECLARE_TLV_DB_SCALE(db_scale_mic, -21, 3, 0); + +static const struct snd_kcontrol_new vx_control_mic_level = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_TLV_READ), + .name = "Mic Capture Volume", + .info = vx_mic_level_info, + .get = vx_mic_level_get, + .put = vx_mic_level_put, + .tlv = { .p = db_scale_mic }, +}; + +/* + * mic boost level control (for VXP440) + */ +#define vx_mic_boost_info snd_ctl_boolean_mono_info + +static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct vx_core *_chip = snd_kcontrol_chip(kcontrol); + struct snd_vxpocket *chip = to_vxpocket(_chip); + ucontrol->value.integer.value[0] = chip->mic_level; + return 0; +} + +static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct vx_core *_chip = snd_kcontrol_chip(kcontrol); + struct snd_vxpocket *chip = to_vxpocket(_chip); + int val = !!ucontrol->value.integer.value[0]; + mutex_lock(&_chip->mixer_mutex); + if (chip->mic_level != val) { + vx_set_mic_boost(_chip, val); + chip->mic_level = val; + mutex_unlock(&_chip->mixer_mutex); + return 1; + } + mutex_unlock(&_chip->mixer_mutex); + return 0; +} + +static const struct snd_kcontrol_new vx_control_mic_boost = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Mic Boost", + .info = vx_mic_boost_info, + .get = vx_mic_boost_get, + .put = vx_mic_boost_put, +}; + + +int vxp_add_mic_controls(struct vx_core *_chip) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + int err; + + /* mute input levels */ + chip->mic_level = 0; + switch (_chip->type) { + case VX_TYPE_VXPOCKET: + vx_set_mic_level(_chip, 0); + break; + case VX_TYPE_VXP440: + vx_set_mic_boost(_chip, 0); + break; + } + + /* mic level */ + switch (_chip->type) { + case VX_TYPE_VXPOCKET: + err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip)); + if (err < 0) + return err; + break; + case VX_TYPE_VXP440: + err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_boost, chip)); + if (err < 0) + return err; + break; + } + + return 0; +} + diff --git a/sound/pcmcia/vx/vxp_ops.c b/sound/pcmcia/vx/vxp_ops.c new file mode 100644 index 0000000000..4176abd737 --- /dev/null +++ b/sound/pcmcia/vx/vxp_ops.c @@ -0,0 +1,601 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Digigram VXpocket soundcards + * + * lowlevel routines for VXpocket soundcards + * + * Copyright (c) 2002 by Takashi Iwai + */ + +#include +#include +#include +#include +#include +#include "vxpocket.h" + + +static const int vxp_reg_offset[VX_REG_MAX] = { + [VX_ICR] = 0x00, // ICR + [VX_CVR] = 0x01, // CVR + [VX_ISR] = 0x02, // ISR + [VX_IVR] = 0x03, // IVR + [VX_RXH] = 0x05, // RXH + [VX_RXM] = 0x06, // RXM + [VX_RXL] = 0x07, // RXL + [VX_DMA] = 0x04, // DMA + [VX_CDSP] = 0x08, // CDSP + [VX_LOFREQ] = 0x09, // LFREQ + [VX_HIFREQ] = 0x0a, // HFREQ + [VX_DATA] = 0x0b, // DATA + [VX_MICRO] = 0x0c, // MICRO + [VX_DIALOG] = 0x0d, // DIALOG + [VX_CSUER] = 0x0e, // CSUER + [VX_RUER] = 0x0f, // RUER +}; + + +static inline unsigned long vxp_reg_addr(struct vx_core *_chip, int reg) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + return chip->port + vxp_reg_offset[reg]; +} + +/* + * snd_vx_inb - read a byte from the register + * @offset: register offset + */ +static unsigned char vxp_inb(struct vx_core *chip, int offset) +{ + return inb(vxp_reg_addr(chip, offset)); +} + +/* + * snd_vx_outb - write a byte on the register + * @offset: the register offset + * @val: the value to write + */ +static void vxp_outb(struct vx_core *chip, int offset, unsigned char val) +{ + outb(val, vxp_reg_addr(chip, offset)); +} + +/* + * redefine macros to call directly + */ +#undef vx_inb +#define vx_inb(chip,reg) vxp_inb((struct vx_core *)(chip), VX_##reg) +#undef vx_outb +#define vx_outb(chip,reg,val) vxp_outb((struct vx_core *)(chip), VX_##reg,val) + + +/* + * vx_check_magic - check the magic word on xilinx + * + * returns zero if a magic word is detected, or a negative error code. + */ +static int vx_check_magic(struct vx_core *chip) +{ + unsigned long end_time = jiffies + HZ / 5; + int c; + do { + c = vx_inb(chip, CDSP); + if (c == CDSP_MAGIC) + return 0; + msleep(10); + } while (time_after_eq(end_time, jiffies)); + snd_printk(KERN_ERR "cannot find xilinx magic word (%x)\n", c); + return -EIO; +} + + +/* + * vx_reset_dsp - reset the DSP + */ + +#define XX_DSP_RESET_WAIT_TIME 2 /* ms */ + +static void vxp_reset_dsp(struct vx_core *_chip) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* set the reset dsp bit to 1 */ + vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_DSP_RESET_MASK); + vx_inb(chip, CDSP); + mdelay(XX_DSP_RESET_WAIT_TIME); + /* reset the bit */ + chip->regCDSP &= ~VXP_CDSP_DSP_RESET_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + vx_inb(chip, CDSP); + mdelay(XX_DSP_RESET_WAIT_TIME); +} + +/* + * reset codec bit + */ +static void vxp_reset_codec(struct vx_core *_chip) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* Set the reset CODEC bit to 1. */ + vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_CODEC_RESET_MASK); + vx_inb(chip, CDSP); + msleep(10); + /* Set the reset CODEC bit to 0. */ + chip->regCDSP &= ~VXP_CDSP_CODEC_RESET_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + vx_inb(chip, CDSP); + msleep(1); +} + +/* + * vx_load_xilinx_binary - load the xilinx binary image + * the binary image is the binary array converted from the bitstream file. + */ +static int vxp_load_xilinx_binary(struct vx_core *_chip, const struct firmware *fw) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + unsigned int i; + int c; + int regCSUER, regRUER; + const unsigned char *image; + unsigned char data; + + /* Switch to programmation mode */ + chip->regDIALOG |= VXP_DLG_XILINX_REPROG_MASK; + vx_outb(chip, DIALOG, chip->regDIALOG); + + /* Save register CSUER and RUER */ + regCSUER = vx_inb(chip, CSUER); + regRUER = vx_inb(chip, RUER); + + /* reset HF0 and HF1 */ + vx_outb(chip, ICR, 0); + + /* Wait for answer HF2 equal to 1 */ + snd_printdd(KERN_DEBUG "check ISR_HF2\n"); + if (vx_check_isr(_chip, ISR_HF2, ISR_HF2, 20) < 0) + goto _error; + + /* set HF1 for loading xilinx binary */ + vx_outb(chip, ICR, ICR_HF1); + image = fw->data; + for (i = 0; i < fw->size; i++, image++) { + data = *image; + if (vx_wait_isr_bit(_chip, ISR_TX_EMPTY) < 0) + goto _error; + vx_outb(chip, TXL, data); + /* wait for reading */ + if (vx_wait_for_rx_full(_chip) < 0) + goto _error; + c = vx_inb(chip, RXL); + if (c != (int)data) + snd_printk(KERN_ERR "vxpocket: load xilinx mismatch at %d: 0x%x != 0x%x\n", i, c, (int)data); + } + + /* reset HF1 */ + vx_outb(chip, ICR, 0); + + /* wait for HF3 */ + if (vx_check_isr(_chip, ISR_HF3, ISR_HF3, 20) < 0) + goto _error; + + /* read the number of bytes received */ + if (vx_wait_for_rx_full(_chip) < 0) + goto _error; + + c = (int)vx_inb(chip, RXH) << 16; + c |= (int)vx_inb(chip, RXM) << 8; + c |= vx_inb(chip, RXL); + + snd_printdd(KERN_DEBUG "xilinx: dsp size received 0x%x, orig 0x%zx\n", c, fw->size); + + vx_outb(chip, ICR, ICR_HF0); + + /* TEMPO 250ms : wait until Xilinx is downloaded */ + msleep(300); + + /* test magical word */ + if (vx_check_magic(_chip) < 0) + goto _error; + + /* Restore register 0x0E and 0x0F (thus replacing COR and FCSR) */ + vx_outb(chip, CSUER, regCSUER); + vx_outb(chip, RUER, regRUER); + + /* Reset the Xilinx's signal enabling IO access */ + chip->regDIALOG |= VXP_DLG_XILINX_REPROG_MASK; + vx_outb(chip, DIALOG, chip->regDIALOG); + vx_inb(chip, DIALOG); + msleep(10); + chip->regDIALOG &= ~VXP_DLG_XILINX_REPROG_MASK; + vx_outb(chip, DIALOG, chip->regDIALOG); + vx_inb(chip, DIALOG); + + /* Reset of the Codec */ + vxp_reset_codec(_chip); + vx_reset_dsp(_chip); + + return 0; + + _error: + vx_outb(chip, CSUER, regCSUER); + vx_outb(chip, RUER, regRUER); + chip->regDIALOG &= ~VXP_DLG_XILINX_REPROG_MASK; + vx_outb(chip, DIALOG, chip->regDIALOG); + return -EIO; +} + + +/* + * vxp_load_dsp - load_dsp callback + */ +static int vxp_load_dsp(struct vx_core *vx, int index, const struct firmware *fw) +{ + int err; + + switch (index) { + case 0: + /* xilinx boot */ + err = vx_check_magic(vx); + if (err < 0) + return err; + err = snd_vx_load_boot_image(vx, fw); + if (err < 0) + return err; + return 0; + case 1: + /* xilinx image */ + return vxp_load_xilinx_binary(vx, fw); + case 2: + /* DSP boot */ + return snd_vx_dsp_boot(vx, fw); + case 3: + /* DSP image */ + return snd_vx_dsp_load(vx, fw); + default: + snd_BUG(); + return -EINVAL; + } +} + + +/* + * vx_test_and_ack - test and acknowledge interrupt + * + * called from irq hander, too + * + * spinlock held! + */ +static int vxp_test_and_ack(struct vx_core *_chip) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* not booted yet? */ + if (! (_chip->chip_status & VX_STAT_XILINX_LOADED)) + return -ENXIO; + + if (! (vx_inb(chip, DIALOG) & VXP_DLG_MEMIRQ_MASK)) + return -EIO; + + /* ok, interrupts generated, now ack it */ + /* set ACQUIT bit up and down */ + vx_outb(chip, DIALOG, chip->regDIALOG | VXP_DLG_ACK_MEMIRQ_MASK); + /* useless read just to spend some time and maintain + * the ACQUIT signal up for a while ( a bus cycle ) + */ + vx_inb(chip, DIALOG); + vx_outb(chip, DIALOG, chip->regDIALOG & ~VXP_DLG_ACK_MEMIRQ_MASK); + + return 0; +} + + +/* + * vx_validate_irq - enable/disable IRQ + */ +static void vxp_validate_irq(struct vx_core *_chip, int enable) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* Set the interrupt enable bit to 1 in CDSP register */ + if (enable) + chip->regCDSP |= VXP_CDSP_VALID_IRQ_MASK; + else + chip->regCDSP &= ~VXP_CDSP_VALID_IRQ_MASK; + vx_outb(chip, CDSP, chip->regCDSP); +} + +/* + * vx_setup_pseudo_dma - set up the pseudo dma read/write mode. + * @do_write: 0 = read, 1 = set up for DMA write + */ +static void vx_setup_pseudo_dma(struct vx_core *_chip, int do_write) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* Interrupt mode and HREQ pin enabled for host transmit / receive data transfers */ + vx_outb(chip, ICR, do_write ? ICR_TREQ : ICR_RREQ); + /* Reset the pseudo-dma register */ + vx_inb(chip, ISR); + vx_outb(chip, ISR, 0); + + /* Select DMA in read/write transfer mode and in 16-bit accesses */ + chip->regDIALOG |= VXP_DLG_DMA16_SEL_MASK; + chip->regDIALOG |= do_write ? VXP_DLG_DMAWRITE_SEL_MASK : VXP_DLG_DMAREAD_SEL_MASK; + vx_outb(chip, DIALOG, chip->regDIALOG); + +} + +/* + * vx_release_pseudo_dma - disable the pseudo-DMA mode + */ +static void vx_release_pseudo_dma(struct vx_core *_chip) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + /* Disable DMA and 16-bit accesses */ + chip->regDIALOG &= ~(VXP_DLG_DMAWRITE_SEL_MASK| + VXP_DLG_DMAREAD_SEL_MASK| + VXP_DLG_DMA16_SEL_MASK); + vx_outb(chip, DIALOG, chip->regDIALOG); + /* HREQ pin disabled. */ + vx_outb(chip, ICR, 0); +} + +/* + * vx_pseudo_dma_write - write bulk data on pseudo-DMA mode + * @count: data length to transfer in bytes + * + * data size must be aligned to 6 bytes to ensure the 24bit alignment on DSP. + * NB: call with a certain lock! + */ +static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, + struct vx_pipe *pipe, int count) +{ + long port = vxp_reg_addr(chip, VX_DMA); + int offset = pipe->hw_ptr; + unsigned short *addr = (unsigned short *)(runtime->dma_area + offset); + + vx_setup_pseudo_dma(chip, 1); + if (offset + count >= pipe->buffer_bytes) { + int length = pipe->buffer_bytes - offset; + count -= length; + length >>= 1; /* in 16bit words */ + /* Transfer using pseudo-dma. */ + for (; length > 0; length--) { + outw(*addr, port); + addr++; + } + addr = (unsigned short *)runtime->dma_area; + pipe->hw_ptr = 0; + } + pipe->hw_ptr += count; + count >>= 1; /* in 16bit words */ + /* Transfer using pseudo-dma. */ + for (; count > 0; count--) { + outw(*addr, port); + addr++; + } + vx_release_pseudo_dma(chip); +} + + +/* + * vx_pseudo_dma_read - read bulk data on pseudo DMA mode + * @offset: buffer offset in bytes + * @count: data length to transfer in bytes + * + * the read length must be aligned to 6 bytes, as well as write. + * NB: call with a certain lock! + */ +static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, + struct vx_pipe *pipe, int count) +{ + struct snd_vxpocket *pchip = to_vxpocket(chip); + long port = vxp_reg_addr(chip, VX_DMA); + int offset = pipe->hw_ptr; + unsigned short *addr = (unsigned short *)(runtime->dma_area + offset); + + if (snd_BUG_ON(count % 2)) + return; + vx_setup_pseudo_dma(chip, 0); + if (offset + count >= pipe->buffer_bytes) { + int length = pipe->buffer_bytes - offset; + count -= length; + length >>= 1; /* in 16bit words */ + /* Transfer using pseudo-dma. */ + for (; length > 0; length--) + *addr++ = inw(port); + addr = (unsigned short *)runtime->dma_area; + pipe->hw_ptr = 0; + } + pipe->hw_ptr += count; + count >>= 1; /* in 16bit words */ + /* Transfer using pseudo-dma. */ + for (; count > 1; count--) + *addr++ = inw(port); + /* Disable DMA */ + pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK; + vx_outb(chip, DIALOG, pchip->regDIALOG); + /* Read the last word (16 bits) */ + *addr = inw(port); + /* Disable 16-bit accesses */ + pchip->regDIALOG &= ~VXP_DLG_DMA16_SEL_MASK; + vx_outb(chip, DIALOG, pchip->regDIALOG); + /* HREQ pin disabled. */ + vx_outb(chip, ICR, 0); +} + + +/* + * write a codec data (24bit) + */ +static void vxp_write_codec_reg(struct vx_core *chip, int codec, unsigned int data) +{ + int i; + + /* Activate access to the corresponding codec register */ + if (! codec) + vx_inb(chip, LOFREQ); + else + vx_inb(chip, CODEC2); + + /* We have to send 24 bits (3 x 8 bits). Start with most signif. Bit */ + for (i = 0; i < 24; i++, data <<= 1) + vx_outb(chip, DATA, ((data & 0x800000) ? VX_DATA_CODEC_MASK : 0)); + + /* Terminate access to codec registers */ + vx_inb(chip, HIFREQ); +} + + +/* + * vx_set_mic_boost - set mic boost level (on vxp440 only) + * @boost: 0 = 20dB, 1 = +38dB + */ +void vx_set_mic_boost(struct vx_core *chip, int boost) +{ + struct snd_vxpocket *pchip = to_vxpocket(chip); + + if (chip->chip_status & VX_STAT_IS_STALE) + return; + + mutex_lock(&chip->lock); + if (pchip->regCDSP & P24_CDSP_MICS_SEL_MASK) { + if (boost) { + /* boost: 38 dB */ + pchip->regCDSP &= ~P24_CDSP_MIC20_SEL_MASK; + pchip->regCDSP |= P24_CDSP_MIC38_SEL_MASK; + } else { + /* minimum value: 20 dB */ + pchip->regCDSP |= P24_CDSP_MIC20_SEL_MASK; + pchip->regCDSP &= ~P24_CDSP_MIC38_SEL_MASK; + } + vx_outb(chip, CDSP, pchip->regCDSP); + } + mutex_unlock(&chip->lock); +} + +/* + * remap the linear value (0-8) to the actual value (0-15) + */ +static int vx_compute_mic_level(int level) +{ + switch (level) { + case 5: level = 6 ; break; + case 6: level = 8 ; break; + case 7: level = 11; break; + case 8: level = 15; break; + default: break ; + } + return level; +} + +/* + * vx_set_mic_level - set mic level (on vxpocket only) + * @level: the mic level = 0 - 8 (max) + */ +void vx_set_mic_level(struct vx_core *chip, int level) +{ + struct snd_vxpocket *pchip = to_vxpocket(chip); + + if (chip->chip_status & VX_STAT_IS_STALE) + return; + + mutex_lock(&chip->lock); + if (pchip->regCDSP & VXP_CDSP_MIC_SEL_MASK) { + level = vx_compute_mic_level(level); + vx_outb(chip, MICRO, level); + } + mutex_unlock(&chip->lock); +} + + +/* + * change the input audio source + */ +static void vxp_change_audio_source(struct vx_core *_chip, int src) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + switch (src) { + case VX_AUDIO_SRC_DIGITAL: + chip->regCDSP |= VXP_CDSP_DATAIN_SEL_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + break; + case VX_AUDIO_SRC_LINE: + chip->regCDSP &= ~VXP_CDSP_DATAIN_SEL_MASK; + if (_chip->type == VX_TYPE_VXP440) + chip->regCDSP &= ~P24_CDSP_MICS_SEL_MASK; + else + chip->regCDSP &= ~VXP_CDSP_MIC_SEL_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + break; + case VX_AUDIO_SRC_MIC: + chip->regCDSP &= ~VXP_CDSP_DATAIN_SEL_MASK; + /* reset mic levels */ + if (_chip->type == VX_TYPE_VXP440) { + chip->regCDSP &= ~P24_CDSP_MICS_SEL_MASK; + if (chip->mic_level) + chip->regCDSP |= P24_CDSP_MIC38_SEL_MASK; + else + chip->regCDSP |= P24_CDSP_MIC20_SEL_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + } else { + chip->regCDSP |= VXP_CDSP_MIC_SEL_MASK; + vx_outb(chip, CDSP, chip->regCDSP); + vx_outb(chip, MICRO, vx_compute_mic_level(chip->mic_level)); + } + break; + } +} + +/* + * change the clock source + * source = INTERNAL_QUARTZ or UER_SYNC + */ +static void vxp_set_clock_source(struct vx_core *_chip, int source) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + if (source == INTERNAL_QUARTZ) + chip->regCDSP &= ~VXP_CDSP_CLOCKIN_SEL_MASK; + else + chip->regCDSP |= VXP_CDSP_CLOCKIN_SEL_MASK; + vx_outb(chip, CDSP, chip->regCDSP); +} + + +/* + * reset the board + */ +static void vxp_reset_board(struct vx_core *_chip, int cold_reset) +{ + struct snd_vxpocket *chip = to_vxpocket(_chip); + + chip->regCDSP = 0; + chip->regDIALOG = 0; +} + + +/* + * callbacks + */ +/* exported */ +const struct snd_vx_ops snd_vxpocket_ops = { + .in8 = vxp_inb, + .out8 = vxp_outb, + .test_and_ack = vxp_test_and_ack, + .validate_irq = vxp_validate_irq, + .write_codec = vxp_write_codec_reg, + .reset_codec = vxp_reset_codec, + .change_audio_source = vxp_change_audio_source, + .set_clock_source = vxp_set_clock_source, + .load_dsp = vxp_load_dsp, + .add_controls = vxp_add_mic_controls, + .reset_dsp = vxp_reset_dsp, + .reset_board = vxp_reset_board, + .dma_write = vxp_dma_write, + .dma_read = vxp_dma_read, +}; diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c new file mode 100644 index 0000000000..7a0f0e73ce --- /dev/null +++ b/sound/pcmcia/vx/vxpocket.c @@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Digigram VXpocket V2/440 soundcards + * + * Copyright (c) 2002 by Takashi Iwai + + */ + + +#include +#include +#include +#include +#include "vxpocket.h" +#include +#include +#include +#include + +MODULE_AUTHOR("Takashi Iwai "); +MODULE_DESCRIPTION("Digigram VXPocket"); +MODULE_LICENSE("GPL"); + +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ +static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ +static int ibl[SNDRV_CARDS]; + +module_param_array(index, int, NULL, 0444); +MODULE_PARM_DESC(index, "Index value for VXPocket soundcard."); +module_param_array(id, charp, NULL, 0444); +MODULE_PARM_DESC(id, "ID string for VXPocket soundcard."); +module_param_array(enable, bool, NULL, 0444); +MODULE_PARM_DESC(enable, "Enable VXPocket soundcard."); +module_param_array(ibl, int, NULL, 0444); +MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard."); + + +/* + */ + +static unsigned int card_alloc; + + +/* + */ +static void vxpocket_release(struct pcmcia_device *link) +{ + free_irq(link->irq, link->priv); + pcmcia_disable_device(link); +} + +/* + * Hardware information + */ + +/* VX-pocket V2 + * + * 1 DSP, 1 sync UER + * 1 programmable clock (NIY) + * 1 stereo analog input (line/micro) + * 1 stereo analog output + * Only output levels can be modified + */ + +static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0); + +static const struct snd_vx_hardware vxpocket_hw = { + .name = "VXPocket", + .type = VX_TYPE_VXPOCKET, + + /* hardware specs */ + .num_codecs = 1, + .num_ins = 1, + .num_outs = 1, + .output_level_max = VX_ANALOG_OUT_LEVEL_MAX, + .output_level_db_scale = db_scale_old_vol, +}; + +/* VX-pocket 440 + * + * 1 DSP, 1 sync UER, 1 sync World Clock (NIY) + * SMPTE (NIY) + * 2 stereo analog input (line/micro) + * 2 stereo analog output + * Only output levels can be modified + * UER, but only for the first two inputs and outputs. + */ + +static const struct snd_vx_hardware vxp440_hw = { + .name = "VXPocket440", + .type = VX_TYPE_VXP440, + + /* hardware specs */ + .num_codecs = 2, + .num_ins = 2, + .num_outs = 2, + .output_level_max = VX_ANALOG_OUT_LEVEL_MAX, + .output_level_db_scale = db_scale_old_vol, +}; + + +/* + * create vxpocket instance + */ +static int snd_vxpocket_new(struct snd_card *card, int ibl, + struct pcmcia_device *link, + struct snd_vxpocket **chip_ret) +{ + struct vx_core *chip; + struct snd_vxpocket *vxp; + + chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops, + sizeof(struct snd_vxpocket) - sizeof(struct vx_core)); + if (!chip) + return -ENOMEM; + + chip->ibl.size = ibl; + + vxp = to_vxpocket(chip); + + vxp->p_dev = link; + link->priv = chip; + + link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; + link->resource[0]->end = 16; + + link->config_flags |= CONF_ENABLE_IRQ; + link->config_index = 1; + link->config_regs = PRESENT_OPTION; + + *chip_ret = vxp; + return 0; +} + + +/** + * snd_vxpocket_assign_resources - initialize the hardware and card instance. + * @chip: VX core instance + * @port: i/o port for the card + * @irq: irq number for the card + * + * this function assigns the specified port and irq, boot the card, + * create pcm and control instances, and initialize the rest hardware. + * + * returns 0 if successful, or a negative error code. + */ +static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq) +{ + int err; + struct snd_card *card = chip->card; + struct snd_vxpocket *vxp = to_vxpocket(chip); + + snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq); + vxp->port = port; + + sprintf(card->shortname, "Digigram %s", card->driver); + sprintf(card->longname, "%s at 0x%x, irq %i", + card->shortname, port, irq); + + chip->irq = irq; + card->sync_irq = chip->irq; + + err = snd_vx_setup_firmware(chip); + if (err < 0) + return err; + + return 0; +} + + +/* + * configuration callback + */ + +static int vxpocket_config(struct pcmcia_device *link) +{ + struct vx_core *chip = link->priv; + int ret; + + snd_printdd(KERN_DEBUG "vxpocket_config called\n"); + + /* redefine hardware record according to the VERSION1 string */ + if (!strcmp(link->prod_id[1], "VX-POCKET")) { + snd_printdd("VX-pocket is detected\n"); + } else { + snd_printdd("VX-pocket 440 is detected\n"); + /* overwrite the hardware information */ + chip->hw = &vxp440_hw; + chip->type = vxp440_hw.type; + strcpy(chip->card->driver, vxp440_hw.name); + } + + ret = pcmcia_request_io(link); + if (ret) + goto failed_preirq; + + ret = request_threaded_irq(link->irq, snd_vx_irq_handler, + snd_vx_threaded_irq_handler, + IRQF_SHARED, link->devname, link->priv); + if (ret) + goto failed_preirq; + + ret = pcmcia_enable_device(link); + if (ret) + goto failed; + + chip->dev = &link->dev; + + if (snd_vxpocket_assign_resources(chip, link->resource[0]->start, + link->irq) < 0) + goto failed; + + return 0; + + failed: + free_irq(link->irq, link->priv); +failed_preirq: + pcmcia_disable_device(link); + return -ENODEV; +} + +#ifdef CONFIG_PM + +static int vxp_suspend(struct pcmcia_device *link) +{ + struct vx_core *chip = link->priv; + + snd_printdd(KERN_DEBUG "SUSPEND\n"); + if (chip) { + snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n"); + snd_vx_suspend(chip); + } + + return 0; +} + +static int vxp_resume(struct pcmcia_device *link) +{ + struct vx_core *chip = link->priv; + + snd_printdd(KERN_DEBUG "RESUME\n"); + if (pcmcia_dev_present(link)) { + //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; + if (chip) { + snd_printdd(KERN_DEBUG "calling snd_vx_resume\n"); + snd_vx_resume(chip); + } + } + snd_printdd(KERN_DEBUG "resume done!\n"); + + return 0; +} + +#endif + + +/* + */ +static int vxpocket_probe(struct pcmcia_device *p_dev) +{ + struct snd_card *card; + struct snd_vxpocket *vxp; + int i, err; + + /* find an empty slot from the card list */ + for (i = 0; i < SNDRV_CARDS; i++) { + if (!(card_alloc & (1 << i))) + break; + } + if (i >= SNDRV_CARDS) { + snd_printk(KERN_ERR "vxpocket: too many cards found\n"); + return -EINVAL; + } + if (! enable[i]) + return -ENODEV; /* disabled explicitly */ + + /* ok, create a card instance */ + err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE, + 0, &card); + if (err < 0) { + snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n"); + return err; + } + + err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp); + if (err < 0) { + snd_card_free(card); + return err; + } + card->private_data = vxp; + + vxp->index = i; + card_alloc |= 1 << i; + + vxp->p_dev = p_dev; + + return vxpocket_config(p_dev); +} + +static void vxpocket_detach(struct pcmcia_device *link) +{ + struct snd_vxpocket *vxp; + struct vx_core *chip; + + if (! link) + return; + + vxp = link->priv; + chip = (struct vx_core *)vxp; + card_alloc &= ~(1 << vxp->index); + + chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */ + snd_card_disconnect(chip->card); + vxpocket_release(link); + snd_card_free_when_closed(chip->card); +} + +/* + * Module entry points + */ + +static const struct pcmcia_device_id vxp_ids[] = { + PCMCIA_DEVICE_MANF_CARD(0x01f1, 0x0100), + PCMCIA_DEVICE_NULL +}; +MODULE_DEVICE_TABLE(pcmcia, vxp_ids); + +static struct pcmcia_driver vxp_cs_driver = { + .owner = THIS_MODULE, + .name = "snd-vxpocket", + .probe = vxpocket_probe, + .remove = vxpocket_detach, + .id_table = vxp_ids, +#ifdef CONFIG_PM + .suspend = vxp_suspend, + .resume = vxp_resume, +#endif +}; +module_pcmcia_driver(vxp_cs_driver); diff --git a/sound/pcmcia/vx/vxpocket.h b/sound/pcmcia/vx/vxpocket.h new file mode 100644 index 0000000000..bce616cc3a --- /dev/null +++ b/sound/pcmcia/vx/vxpocket.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Driver for Digigram VXpocket soundcards + * + * Copyright (c) 2002 by Takashi Iwai + */ + +#ifndef __VXPOCKET_H +#define __VXPOCKET_H + +#include + +#include +#include + +struct snd_vxpocket { + + struct vx_core core; + + unsigned long port; + + int mic_level; /* analog mic level (or boost) */ + + unsigned int regCDSP; /* current CDSP register */ + unsigned int regDIALOG; /* current DIALOG register */ + + int index; /* card index */ + + /* pcmcia stuff */ + struct pcmcia_device *p_dev; +}; + +#define to_vxpocket(x) container_of(x, struct snd_vxpocket, core) + +extern const struct snd_vx_ops snd_vxpocket_ops; + +void vx_set_mic_boost(struct vx_core *chip, int boost); +void vx_set_mic_level(struct vx_core *chip, int level); + +int vxp_add_mic_controls(struct vx_core *chip); + +/* Constants used to access the CDSP register (0x08). */ +#define CDSP_MAGIC 0xA7 /* magic value (for read) */ +/* for write */ +#define VXP_CDSP_CLOCKIN_SEL_MASK 0x80 /* 0 (internal), 1 (AES/EBU) */ +#define VXP_CDSP_DATAIN_SEL_MASK 0x40 /* 0 (analog), 1 (UER) */ +#define VXP_CDSP_SMPTE_SEL_MASK 0x20 +#define VXP_CDSP_RESERVED_MASK 0x10 +#define VXP_CDSP_MIC_SEL_MASK 0x08 +#define VXP_CDSP_VALID_IRQ_MASK 0x04 +#define VXP_CDSP_CODEC_RESET_MASK 0x02 +#define VXP_CDSP_DSP_RESET_MASK 0x01 +/* VXPOCKET 240/440 */ +#define P24_CDSP_MICS_SEL_MASK 0x18 +#define P24_CDSP_MIC20_SEL_MASK 0x10 +#define P24_CDSP_MIC38_SEL_MASK 0x08 + +/* Constants used to access the MEMIRQ register (0x0C). */ +#define P44_MEMIRQ_MASTER_SLAVE_SEL_MASK 0x08 +#define P44_MEMIRQ_SYNCED_ALONE_SEL_MASK 0x04 +#define P44_MEMIRQ_WCLK_OUT_IN_SEL_MASK 0x02 /* Not used */ +#define P44_MEMIRQ_WCLK_UER_SEL_MASK 0x01 /* Not used */ + +/* Micro levels (0x0C) */ + +/* Constants used to access the DIALOG register (0x0D). */ +#define VXP_DLG_XILINX_REPROG_MASK 0x80 /* W */ +#define VXP_DLG_DATA_XICOR_MASK 0x80 /* R */ +#define VXP_DLG_RESERVED4_0_MASK 0x40 +#define VXP_DLG_RESERVED2_0_MASK 0x20 +#define VXP_DLG_RESERVED1_0_MASK 0x10 +#define VXP_DLG_DMAWRITE_SEL_MASK 0x08 /* W */ +#define VXP_DLG_DMAREAD_SEL_MASK 0x04 /* W */ +#define VXP_DLG_MEMIRQ_MASK 0x02 /* R */ +#define VXP_DLG_DMA16_SEL_MASK 0x02 /* W */ +#define VXP_DLG_ACK_MEMIRQ_MASK 0x01 /* R/W */ + + +#endif /* __VXPOCKET_H */ -- cgit v1.2.3