2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2007-10-15 07:50:19 +00:00
|
|
|
* Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
2005-04-16 22:20:36 +00:00
|
|
|
* Uros Bizjak <uros@kss-loka.si>
|
|
|
|
*
|
|
|
|
* Lowlevel routines for control of Sound Blaster cards
|
|
|
|
*
|
|
|
|
* 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 <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ioport.h>
|
2011-07-15 16:38:28 +00:00
|
|
|
#include <linux/module.h>
|
2015-01-28 15:49:33 +00:00
|
|
|
#include <linux/io.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/sb.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
|
|
|
|
#include <asm/dma.h>
|
|
|
|
|
2007-10-15 07:50:19 +00:00
|
|
|
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_DESCRIPTION("ALSA lowlevel driver for Sound Blaster cards");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
#define BUSY_LOOPS 100000
|
|
|
|
|
|
|
|
#undef IO_DEBUG
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
int snd_sbdsp_command(struct snd_sb *chip, unsigned char val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
#ifdef IO_DEBUG
|
2005-10-20 16:26:44 +00:00
|
|
|
snd_printk(KERN_DEBUG "command 0x%x\n", val);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
for (i = BUSY_LOOPS; i; i--)
|
|
|
|
if ((inb(SBP(chip, STATUS)) & 0x80) == 0) {
|
|
|
|
outb(val, SBP(chip, COMMAND));
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-03 23:32:18 +00:00
|
|
|
snd_printd("%s [0x%lx]: timeout (0x%x)\n", __func__, chip->port, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
int snd_sbdsp_get_byte(struct snd_sb *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
int i;
|
|
|
|
for (i = BUSY_LOOPS; i; i--) {
|
|
|
|
if (inb(SBP(chip, DATA_AVAIL)) & 0x80) {
|
|
|
|
val = inb(SBP(chip, READ));
|
|
|
|
#ifdef IO_DEBUG
|
2005-10-20 16:26:44 +00:00
|
|
|
snd_printk(KERN_DEBUG "get_byte 0x%x\n", val);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
2008-03-03 23:32:18 +00:00
|
|
|
snd_printd("%s [0x%lx]: timeout\n", __func__, chip->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
int snd_sbdsp_reset(struct snd_sb *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
outb(1, SBP(chip, RESET));
|
|
|
|
udelay(10);
|
|
|
|
outb(0, SBP(chip, RESET));
|
|
|
|
udelay(30);
|
|
|
|
for (i = BUSY_LOOPS; i; i--)
|
|
|
|
if (inb(SBP(chip, DATA_AVAIL)) & 0x80) {
|
|
|
|
if (inb(SBP(chip, READ)) == 0xaa)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2008-03-03 23:32:18 +00:00
|
|
|
snd_printdd("%s [0x%lx] failed...\n", __func__, chip->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
static int snd_sbdsp_version(struct snd_sb * chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int result = -ENODEV;
|
|
|
|
|
|
|
|
snd_sbdsp_command(chip, SB_DSP_GET_VERSION);
|
|
|
|
result = (short) snd_sbdsp_get_byte(chip) << 8;
|
|
|
|
result |= (short) snd_sbdsp_get_byte(chip);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
static int snd_sbdsp_probe(struct snd_sb * chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int version;
|
|
|
|
int major, minor;
|
|
|
|
char *str;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialization sequence
|
|
|
|
*/
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chip->reg_lock, flags);
|
|
|
|
if (snd_sbdsp_reset(chip) < 0) {
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
version = snd_sbdsp_version(chip);
|
|
|
|
if (version < 0) {
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
|
|
major = version >> 8;
|
|
|
|
minor = version & 0xff;
|
|
|
|
snd_printdd("SB [0x%lx]: DSP chip found, version = %i.%i\n",
|
|
|
|
chip->port, major, minor);
|
2007-05-24 16:46:54 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (chip->hardware) {
|
|
|
|
case SB_HW_AUTO:
|
|
|
|
switch (major) {
|
|
|
|
case 1:
|
|
|
|
chip->hardware = SB_HW_10;
|
|
|
|
str = "1.0";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (minor) {
|
|
|
|
chip->hardware = SB_HW_201;
|
|
|
|
str = "2.01+";
|
|
|
|
} else {
|
|
|
|
chip->hardware = SB_HW_20;
|
|
|
|
str = "2.0";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
chip->hardware = SB_HW_PRO;
|
|
|
|
str = "Pro";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
chip->hardware = SB_HW_16;
|
|
|
|
str = "16";
|
|
|
|
break;
|
|
|
|
default:
|
2005-10-20 16:26:44 +00:00
|
|
|
snd_printk(KERN_INFO "SB [0x%lx]: unknown DSP chip version %i.%i\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
chip->port, major, minor);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SB_HW_ALS100:
|
|
|
|
str = "16 (ALS-100)";
|
|
|
|
break;
|
|
|
|
case SB_HW_ALS4000:
|
|
|
|
str = "16 (ALS-4000)";
|
|
|
|
break;
|
|
|
|
case SB_HW_DT019X:
|
|
|
|
str = "(DT019X/ALS007)";
|
|
|
|
break;
|
2007-05-24 16:46:54 +00:00
|
|
|
case SB_HW_CS5530:
|
|
|
|
str = "16 (CS5530)";
|
|
|
|
break;
|
2009-12-20 18:01:50 +00:00
|
|
|
case SB_HW_JAZZ16:
|
|
|
|
str = "Pro (Jazz16)";
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
sprintf(chip->name, "Sound Blaster %s", str);
|
|
|
|
chip->version = (major << 8) | minor;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
static int snd_sbdsp_free(struct snd_sb *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-11-21 18:32:02 +00:00
|
|
|
release_and_free_resource(chip->res_port);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (chip->irq >= 0)
|
|
|
|
free_irq(chip->irq, (void *) chip);
|
|
|
|
#ifdef CONFIG_ISA
|
|
|
|
if (chip->dma8 >= 0) {
|
|
|
|
disable_dma(chip->dma8);
|
|
|
|
free_dma(chip->dma8);
|
|
|
|
}
|
|
|
|
if (chip->dma16 >= 0 && chip->dma16 != chip->dma8) {
|
|
|
|
disable_dma(chip->dma16);
|
|
|
|
free_dma(chip->dma16);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
kfree(chip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
static int snd_sbdsp_dev_free(struct snd_device *device)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 13:34:36 +00:00
|
|
|
struct snd_sb *chip = device->device_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
return snd_sbdsp_free(chip);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:34:36 +00:00
|
|
|
int snd_sbdsp_create(struct snd_card *card,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long port,
|
|
|
|
int irq,
|
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 13:55:46 +00:00
|
|
|
irq_handler_t irq_handler,
|
2005-04-16 22:20:36 +00:00
|
|
|
int dma8,
|
|
|
|
int dma16,
|
|
|
|
unsigned short hardware,
|
2005-11-17 13:34:36 +00:00
|
|
|
struct snd_sb **r_chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 13:34:36 +00:00
|
|
|
struct snd_sb *chip;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
2005-11-17 13:34:36 +00:00
|
|
|
static struct snd_device_ops ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.dev_free = snd_sbdsp_dev_free,
|
|
|
|
};
|
|
|
|
|
2008-08-08 15:11:45 +00:00
|
|
|
if (snd_BUG_ON(!r_chip))
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
*r_chip = NULL;
|
2005-09-09 12:21:17 +00:00
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (chip == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
spin_lock_init(&chip->reg_lock);
|
|
|
|
spin_lock_init(&chip->open_lock);
|
|
|
|
spin_lock_init(&chip->midi_input_lock);
|
|
|
|
spin_lock_init(&chip->mixer_lock);
|
|
|
|
chip->irq = -1;
|
|
|
|
chip->dma8 = -1;
|
|
|
|
chip->dma16 = -1;
|
|
|
|
chip->port = port;
|
|
|
|
|
2007-08-29 10:54:25 +00:00
|
|
|
if (request_irq(irq, irq_handler,
|
|
|
|
(hardware == SB_HW_ALS4000 ||
|
|
|
|
hardware == SB_HW_CS5530) ?
|
2011-09-22 08:59:20 +00:00
|
|
|
IRQF_SHARED : 0,
|
2005-04-16 22:20:36 +00:00
|
|
|
"SoundBlaster", (void *) chip)) {
|
|
|
|
snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq);
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
chip->irq = irq;
|
|
|
|
|
|
|
|
if (hardware == SB_HW_ALS4000)
|
|
|
|
goto __skip_allocation;
|
|
|
|
|
|
|
|
if ((chip->res_port = request_region(port, 16, "SoundBlaster")) == NULL) {
|
|
|
|
snd_printk(KERN_ERR "sb: can't grab port 0x%lx\n", port);
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_ISA
|
|
|
|
if (dma8 >= 0 && request_dma(dma8, "SoundBlaster - 8bit")) {
|
|
|
|
snd_printk(KERN_ERR "sb: can't grab DMA8 %d\n", dma8);
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
chip->dma8 = dma8;
|
|
|
|
if (dma16 >= 0) {
|
|
|
|
if (hardware != SB_HW_ALS100 && (dma16 < 5 || dma16 > 7)) {
|
|
|
|
/* no duplex */
|
|
|
|
dma16 = -1;
|
|
|
|
} else if (request_dma(dma16, "SoundBlaster - 16bit")) {
|
|
|
|
snd_printk(KERN_ERR "sb: can't grab DMA16 %d\n", dma16);
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chip->dma16 = dma16;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__skip_allocation:
|
|
|
|
chip->card = card;
|
|
|
|
chip->hardware = hardware;
|
|
|
|
if ((err = snd_sbdsp_probe(chip)) < 0) {
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
|
|
|
|
snd_sbdsp_free(chip);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
*r_chip = chip;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_sbdsp_command);
|
|
|
|
EXPORT_SYMBOL(snd_sbdsp_get_byte);
|
|
|
|
EXPORT_SYMBOL(snd_sbdsp_reset);
|
|
|
|
EXPORT_SYMBOL(snd_sbdsp_create);
|
|
|
|
/* sb_mixer.c */
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_write);
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_read);
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_new);
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_add_ctl);
|
2005-11-17 15:16:10 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_suspend);
|
|
|
|
EXPORT_SYMBOL(snd_sbmixer_resume);
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* INIT part
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int __init alsa_sb_common_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit alsa_sb_common_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(alsa_sb_common_init)
|
|
|
|
module_exit(alsa_sb_common_exit)
|