2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* Driver for Sound Core PDAudioCF soundcard
|
|
|
|
*
|
2007-10-15 03:50:19 -04:00
|
|
|
* Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* 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/core.h>
|
|
|
|
#include "pdaudiocf.h"
|
|
|
|
#include <sound/initval.h>
|
2006-10-08 10:01:14 -04:00
|
|
|
#include <asm/irq_regs.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 09:55:46 -04:00
|
|
|
irqreturn_t pdacf_interrupt(int irq, void *dev)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2005-11-17 09:07:38 -05:00
|
|
|
struct snd_pdacf *chip = dev;
|
2005-04-16 18:20:36 -04:00
|
|
|
unsigned short stat;
|
|
|
|
|
|
|
|
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)
|
|
|
|
tasklet_hi_schedule(&chip->tq);
|
|
|
|
if (!(stat & PDAUDIOCF_IRQAKM))
|
|
|
|
stat |= PDAUDIOCF_IRQAKM; /* check rate */
|
|
|
|
}
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 09:55:46 -04:00
|
|
|
if (get_irq_regs() != NULL)
|
2005-04-16 18:20:36 -04:00
|
|
|
snd_ak4117_check_rate_and_errors(chip->ak4117, 0);
|
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-17 09:07:38 -05:00
|
|
|
static void pdacf_transfer(struct snd_pdacf *chip, unsigned int size, unsigned int off)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2005-11-17 09:07:38 -05:00
|
|
|
struct snd_pdacf *chip = (struct snd_pdacf *) private_data;
|
2005-04-16 18:20:36 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
rdp = inw(chip->port + PDAUDIOCF_REG_RDP);
|
|
|
|
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");
|
|
|
|
}
|