Commit a38cbf4e authored by Jaroslav Kysela's avatar Jaroslav Kysela

ALSA CVS update - Jaroslav Kysela <perex@suse.cz>

Documentation,ALSA Core,PCMCIA Kconfig,PCMCIA
Sound Core PDAudioCF driver
Added Sound Core PDAudioCF driver
parent cb144397
......@@ -1179,6 +1179,16 @@ Module parameters
The power-management is supported.
Module snd-pdaudiocf
--------------------
Module for Sound Core PDAudioCF soundcard.
irq_mask - IRQ mask (PCMCIA type)
irq_list - List of available interrupts for this soundcard
Note: the driver is build only when CONFIG_ISA is set.
Configuring Non-ISAPNP Cards
============================
......
......@@ -108,5 +108,6 @@ obj-$(CONFIG_SND_VXP440) += snd-pcm.o snd-timer.o snd-page-alloc.o snd.o snd-hwd
obj-$(CONFIG_SND_VX222) += snd-pcm.o snd-timer.o snd-page-alloc.o snd.o snd-hwdep.o
obj-$(CONFIG_SND_BT87X) += snd-pcm.o snd-timer.o snd-page-alloc.o snd.o
obj-$(CONFIG_SND_MIXART) += snd-pcm.o snd-timer.o snd-page-alloc.o snd.o snd-hwdep.o
obj-$(CONFIG_SND_PDAUDIOCF) += snd-pcm.o snd-timer.o snd-page-alloc.o snd.o
obj-m := $(sort $(obj-m))
......@@ -15,4 +15,10 @@ config SND_VXP440
help
Say 'Y' or 'M' to include support for Digigram VXpocket 440 soundcard.
config SND_PDAUDIOCF
tristate "Sound Core PDAudioCF"
depends on SND && PCMCIA && ISA
help
Say 'Y' or 'M' to include support for Sound Core PDAudioCF soundcard.
endmenu
......@@ -3,6 +3,4 @@
# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
#
obj-$(CONFIG_SND) += vx/
obj-$(CONFIG_SND) += vx/ pdaudiocf/
#
# Makefile for ALSA
# Copyright (c) 2004 by Jaroslav Kysela <perex@suse.cz>
#
snd-pdaudiocf-objs := pdaudiocf.o pdaudiocf_core.o pdaudiocf_irq.o pdaudiocf_pcm.o
obj-$(CONFIG_SND_PDAUDIOCF) += snd-pdaudiocf.o
This diff is collapsed.
/*
* Driver for Sound Cors PDAudioCF soundcard
*
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PDAUDIOCF_H
#define __PDAUDIOCF_H
#include <sound/pcm.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
#include "ak4117.h"
/* 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)
typedef struct {
snd_card_t *card;
int index;
unsigned long port;
int irq;
spinlock_t reg_lock;
unsigned short regmap[8];
unsigned short suspend_reg_scr;
struct tasklet_struct tq;
spinlock_t ak4117_lock;
ak4117_t *ak4117;
unsigned int chip_status;
snd_pcm_t *pcm;
snd_pcm_substream_t *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 */
dev_link_t link;
dev_node_t node;
} pdacf_t;
static inline void pdacf_reg_write(pdacf_t *chip, unsigned char reg, unsigned short val)
{
outw(chip->regmap[reg>>1] = val, chip->port + reg);
}
static inline unsigned short pdacf_reg_read(pdacf_t *chip, unsigned char reg)
{
return inw(chip->port + reg);
}
unsigned char pdacf_ak4117_read(void *private_data, unsigned char reg);
void pdacf_ak4117_write(void *private_data, unsigned char reg, unsigned char val);
pdacf_t *snd_pdacf_create(snd_card_t *card);
int snd_pdacf_ak4117_create(pdacf_t *pdacf);
void snd_pdacf_powerdown(pdacf_t *chip);
#ifdef CONFIG_PM
void snd_pdacf_suspend(pdacf_t *chip);
void snd_pdacf_resume(pdacf_t *chip);
int snd_pdacf_set_power_state(snd_card_t *card, unsigned int power_state);
#endif
int snd_pdacf_pcm_new(pdacf_t *chip);
void pdacf_interrupt(int irq, void *dev, struct pt_regs *regs);
void pdacf_tasklet(unsigned long private_data);
void pdacf_reinit(pdacf_t *chip, int resume);
#endif /* __PDAUDIOCF_H */
/*
* Driver for Sound Core PDAudioCF soundcard
*
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sound/driver.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/info.h>
#include "pdaudiocf.h"
#define SNDRV_GET_ID
#include <sound/initval.h>
/*
*
*/
unsigned char pdacf_ak4117_read(void *private_data, unsigned char reg)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, private_data, return 0);
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;
}
void pdacf_ak4117_write(void *private_data, unsigned char reg, unsigned char val)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, private_data, return);
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(pdacf_t *chip)
{
printk("PDAUDIOCF DUMP (0x%lx):\n", chip->port);
printk("WPD : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_WDP));
printk("RDP : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_RDP));
printk("TCR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_TCR));
printk("SCR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_SCR));
printk("ISR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_ISR));
printk("IER : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_IER));
printk("AK_IFR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_AK_IFR));
}
#endif
static int pdacf_reset(pdacf_t *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(pdacf_t *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(snd_info_entry_t * entry,
snd_info_buffer_t * buffer)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, entry->private_data, return);
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(pdacf_t *chip)
{
snd_info_entry_t *entry;
if (! snd_card_proc_new(chip->card, "pdaudiocf", &entry))
snd_info_set_text_ops(entry, chip, 1024, pdacf_proc_read);
}
pdacf_t *snd_pdacf_create(snd_card_t *card)
{
pdacf_t *chip;
chip = snd_magic_kcalloc(pdacf_t, 0, GFP_KERNEL);
if (chip == NULL)
return NULL;
chip->card = card;
spin_lock_init(&chip->reg_lock);
spin_lock_init(&chip->ak4117_lock);
tasklet_init(&chip->tq, pdacf_tasklet, (unsigned long)chip);
card->private_data = chip;
pdacf_proc_init(chip);
return chip;
}
static void snd_pdacf_ak4117_change(ak4117_t *ak4117, unsigned char c0, unsigned char c1)
{
pdacf_t *chip = ak4117->change_callback_private;
unsigned long flags;
u16 val;
if (!(c0 & AK4117_UNLCK))
return;
spin_lock_irqsave(&chip->reg_lock, flags);
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);
spin_unlock_irqrestore(&chip->reg_lock, flags);
}
int snd_pdacf_ak4117_create(pdacf_t *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 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(pdacf_t *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
void snd_pdacf_suspend(pdacf_t *chip)
{
snd_card_t *card = chip->card;
u16 val;
if (card->power_state == SNDRV_CTL_POWER_D3hot)
return;
snd_pcm_suspend_all(chip->pcm);
/* 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);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
}
static inline int check_signal(pdacf_t *chip)
{
return (chip->ak4117->rcs0 & AK4117_UNLCK) == 0;
}
void snd_pdacf_resume(pdacf_t *chip)
{
snd_card_t *card = chip->card;
int timeout = 40;
if (card->power_state == SNDRV_CTL_POWER_D0)
return;
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(card, SNDRV_CTL_POWER_D0);
}
int snd_pdacf_set_power_state(snd_card_t *card, unsigned int power_state)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, card->power_state_private_data, return -ENXIO);
switch (power_state) {
case SNDRV_CTL_POWER_D0:
case SNDRV_CTL_POWER_D1:
case SNDRV_CTL_POWER_D2:
snd_pdacf_resume(chip);
break;
case SNDRV_CTL_POWER_D3hot:
case SNDRV_CTL_POWER_D3cold:
snd_pdacf_suspend(chip);
break;
default:
return -EINVAL;
}
return 0;
}
#endif
/*
* Driver for Sound Core PDAudioCF soundcard
*
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sound/driver.h>
#include <sound/core.h>
#include "pdaudiocf.h"
#define SNDRV_GET_ID
#include <sound/initval.h>
/*
*
*/
void pdacf_interrupt(int irq, void *dev, struct pt_regs *regs)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, dev, return);
unsigned short stat;
if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE|
PDAUDIOCF_STAT_IS_CONFIGURED|
PDAUDIOCF_STAT_IS_SUSPENDED)) != PDAUDIOCF_STAT_IS_CONFIGURED)
return;
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)
tasklet_hi_schedule(&chip->tq);
if (!(stat & PDAUDIOCF_IRQAKM))
stat |= PDAUDIOCF_IRQAKM; /* check rate */
}
if (regs != NULL)
snd_ak4117_check_rate_and_errors(chip->ak4117, 0);
}
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(pdacf_t *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);
}
}
}
}
void pdacf_tasklet(unsigned long private_data)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, (void *)private_data, return);
int size, off, cont, rdp, wdp;
if ((chip->chip_status & (PDAUDIOCF_STAT_IS_STALE|PDAUDIOCF_STAT_IS_CONFIGURED)) != PDAUDIOCF_STAT_IS_CONFIGURED)
return;
if (chip->pcm_substream == NULL || chip->pcm_substream->runtime == NULL || !snd_pcm_running(chip->pcm_substream))
return;
(unsigned int)rdp = inw(chip->port + PDAUDIOCF_REG_RDP);
(unsigned int)wdp = inw(chip->port + PDAUDIOCF_REG_WDP);
// printk("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
spin_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;
spin_unlock(&chip->reg_lock);
snd_pcm_period_elapsed(chip->pcm_substream);
spin_lock(&chip->reg_lock);
}
spin_unlock(&chip->reg_lock);
// printk("TASKLET: end\n");
}
/*
* Driver for Sound Core PDAudioCF soundcards
*
* PCM part
*
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sound/driver.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/asoundef.h>
#include "pdaudiocf.h"
#define chip_t pdacf_t
/*
* we use a vmalloc'ed (sg-)buffer
*/
/* get the physical page pointer on the given offset */
static struct page *snd_pcm_get_vmalloc_page(snd_pcm_substream_t *subs, unsigned long offset)
{
void *pageptr = subs->runtime->dma_area + offset;
return vmalloc_to_page(pageptr);
}
/*
* hw_params callback
* NOTE: this may be called not only once per pcm open!
*/
static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
{
snd_pcm_runtime_t *runtime = subs->runtime;
if (runtime->dma_area) {
if (runtime->dma_bytes >= size)
return 0; /* already enough large */
vfree_nocheck(runtime->dma_area);
}
runtime->dma_area = vmalloc_nocheck(size);
if (! runtime->dma_area)
return -ENOMEM;
runtime->dma_bytes = size;
return 0;
}
/*
* hw_free callback
* NOTE: this may be called not only once per pcm open!
*/
static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
{
snd_pcm_runtime_t *runtime = subs->runtime;
if (runtime->dma_area) {
vfree_nocheck(runtime->dma_area);
runtime->dma_area = NULL;
}
return 0;
}
/*
* clear the SRAM contents
*/
static int pdacf_pcm_clear_sram(pdacf_t *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(snd_pcm_substream_t *subs, int cmd)
{
pdacf_t *chip = snd_pcm_substream_chip(subs);
snd_pcm_runtime_t *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;
/* fall thru */
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;
}
spin_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:
spin_unlock(&chip->reg_lock);
snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_RATE);
return ret;
}
/*
* pdacf_pcm_hw_params - hw_params callback for playback and capture
*/
static int pdacf_pcm_hw_params(snd_pcm_substream_t *subs,
snd_pcm_hw_params_t *hw_params)
{
return snd_pcm_alloc_vmalloc_buffer(subs, params_buffer_bytes(hw_params));
}
/*
* pdacf_pcm_hw_free - hw_free callback for playback and capture
*/
static int pdacf_pcm_hw_free(snd_pcm_substream_t *subs)
{
return snd_pcm_free_vmalloc_buffer(subs);
}
/*
* pdacf_pcm_prepare - prepare callback for playback and capture
*/
static int pdacf_pcm_prepare(snd_pcm_substream_t *subs)
{
pdacf_t *chip = snd_pcm_substream_chip(subs);
snd_pcm_runtime_t *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;
/* fall trough */
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 snd_pcm_hardware_t 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),
.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(snd_pcm_substream_t *subs)
{
snd_pcm_runtime_t *runtime = subs->runtime;
pdacf_t *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(snd_pcm_substream_t *subs)
{
pdacf_t *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(snd_pcm_substream_t *subs)
{
pdacf_t *chip = snd_pcm_substream_chip(subs);
return chip->pcm_hwptr;
}
/*
* operators for PCM capture
*/
static snd_pcm_ops_t pdacf_pcm_capture_ops = {
.open = pdacf_pcm_capture_open,
.close = pdacf_pcm_capture_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = pdacf_pcm_hw_params,
.hw_free = pdacf_pcm_hw_free,
.prepare = pdacf_pcm_prepare,
.trigger = pdacf_pcm_trigger,
.pointer = pdacf_pcm_capture_pointer,
.page = snd_pcm_get_vmalloc_page,
};
/*
* free callback for pcm
*/
static void snd_pdacf_pcm_free(snd_pcm_t *pcm)
{
pdacf_t *chip = snd_magic_cast(pdacf_t, pcm->private_data, return);
chip->pcm = NULL;
}
/*
* snd_pdacf_pcm_new - create and initialize a pcm
*/
int snd_pdacf_pcm_new(pdacf_t *chip)
{
snd_pcm_t *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);
pcm->private_data = chip;
pcm->private_free = snd_pdacf_pcm_free;
pcm->info_flags = 0;
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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment