2019-05-27 09:55:05 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Driver for Sound Core PDAudioCF soundcard
|
|
|
|
*
|
2007-10-15 11:50:19 +04:00
|
|
|
* Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include "pdaudiocf.h"
|
|
|
|
#include <sound/initval.h>
|
2006-10-08 18:01:14 +04:00
|
|
|
#include <asm/irq_regs.h>
|
2005-04-17 02: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 17:55:46 +04:00
|
|
|
irqreturn_t pdacf_interrupt(int irq, void *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:07:38 +03:00
|
|
|
struct snd_pdacf *chip = dev;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned short stat;
|
2014-09-10 16:58:59 +04:00
|
|
|
bool wake_thread = false;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
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)
|
2014-09-10 16:58:59 +04:00
|
|
|
wake_thread = true;
|
2005-04-17 02:20:36 +04:00
|
|
|
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 17:55:46 +04:00
|
|
|
if (get_irq_regs() != NULL)
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_ak4117_check_rate_and_errors(chip->ak4117, 0);
|
2014-09-10 16:58:59 +04:00
|
|
|
return wake_thread ? IRQ_WAKE_THREAD : IRQ_HANDLED;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 17:07:38 +03:00
|
|
|
static void pdacf_transfer(struct snd_pdacf *chip, unsigned int size, unsigned int off)
|
2005-04-17 02: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 16:58:59 +04:00
|
|
|
irqreturn_t pdacf_threaded_irq(int irq, void *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-09-10 16:58:59 +04:00
|
|
|
struct snd_pdacf *chip = dev;
|
2005-04-17 02: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)
|
2014-09-10 16:58:59 +04:00
|
|
|
return IRQ_HANDLED;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (chip->pcm_substream == NULL || chip->pcm_substream->runtime == NULL || !snd_pcm_running(chip->pcm_substream))
|
2014-09-10 16:58:59 +04:00
|
|
|
return IRQ_HANDLED;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
rdp = inw(chip->port + PDAUDIOCF_REG_RDP);
|
|
|
|
wdp = inw(chip->port + PDAUDIOCF_REG_WDP);
|
2009-02-05 18:11:58 +03:00
|
|
|
/* printk(KERN_DEBUG "TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); */
|
2005-04-17 02:20:36 +04:00
|
|
|
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
|
2014-09-10 16:58:59 +04:00
|
|
|
mutex_lock(&chip->reg_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
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;
|
2014-09-10 16:58:59 +04:00
|
|
|
mutex_unlock(&chip->reg_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_pcm_period_elapsed(chip->pcm_substream);
|
2014-09-10 16:58:59 +04:00
|
|
|
mutex_lock(&chip->reg_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2014-09-10 16:58:59 +04:00
|
|
|
mutex_unlock(&chip->reg_lock);
|
|
|
|
return IRQ_HANDLED;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|