2005-04-17 06:20:36 +08:00
|
|
|
/* Hewlett-Packard Harmony audio driver
|
|
|
|
*
|
|
|
|
* This is a driver for the Harmony audio chipset found
|
|
|
|
* on the LASI ASIC of various early HP PA-RISC workstations.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004, Kyle McMartin <kyle@{debian.org,parisc-linux.org}>
|
|
|
|
*
|
|
|
|
* Based on the previous Harmony incarnations by,
|
|
|
|
* Copyright 2000 (c) Linuxcare Canada, Alex deVries
|
|
|
|
* Copyright 2000-2003 (c) Helge Deller
|
|
|
|
* Copyright 2001 (c) Matthieu Delahaye
|
|
|
|
* Copyright 2001 (c) Jean-Christophe Vaugeois
|
|
|
|
* Copyright 2003 (c) Laurent Canet
|
|
|
|
* Copyright 2004 (c) Stuart Brady
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License, version 2, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* - graveyard and silence buffers last for lifetime of
|
|
|
|
* the driver. playback and capture buffers are allocated
|
|
|
|
* per _open()/_close().
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2015-01-28 23:49:33 +08:00
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/rawmidi.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/info.h>
|
|
|
|
|
|
|
|
#include <asm/hardware.h>
|
|
|
|
#include <asm/parisc-device.h>
|
|
|
|
|
|
|
|
#include "harmony.h"
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
|
|
|
|
static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
|
|
|
|
module_param(index, int, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "Index value for Harmony driver.");
|
|
|
|
module_param(id, charp, 0444);
|
|
|
|
MODULE_PARM_DESC(id, "ID string for Harmony driver.");
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct parisc_device_id snd_harmony_devtable[] = {
|
|
|
|
/* bushmaster / flounder */
|
|
|
|
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A },
|
|
|
|
/* 712 / 715 */
|
|
|
|
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B },
|
|
|
|
/* pace */
|
|
|
|
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E },
|
|
|
|
/* outfield / coral II */
|
|
|
|
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(parisc, snd_harmony_devtable);
|
|
|
|
|
|
|
|
#define NAME "harmony"
|
|
|
|
#define PFX NAME ": "
|
|
|
|
|
2017-06-07 20:17:04 +08:00
|
|
|
static const unsigned int snd_harmony_rates[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
5512, 6615, 8000, 9600,
|
|
|
|
11025, 16000, 18900, 22050,
|
|
|
|
27428, 32000, 33075, 37800,
|
|
|
|
44100, 48000
|
|
|
|
};
|
|
|
|
|
2017-06-07 20:17:04 +08:00
|
|
|
static const unsigned int rate_bits[14] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
HARMONY_SR_5KHZ, HARMONY_SR_6KHZ, HARMONY_SR_8KHZ,
|
|
|
|
HARMONY_SR_9KHZ, HARMONY_SR_11KHZ, HARMONY_SR_16KHZ,
|
|
|
|
HARMONY_SR_18KHZ, HARMONY_SR_22KHZ, HARMONY_SR_27KHZ,
|
|
|
|
HARMONY_SR_32KHZ, HARMONY_SR_33KHZ, HARMONY_SR_37KHZ,
|
|
|
|
HARMONY_SR_44KHZ, HARMONY_SR_48KHZ
|
|
|
|
};
|
|
|
|
|
2017-06-07 20:17:04 +08:00
|
|
|
static const struct snd_pcm_hw_constraint_list hw_constraint_rates = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.count = ARRAY_SIZE(snd_harmony_rates),
|
|
|
|
.list = snd_harmony_rates,
|
|
|
|
.mask = 0,
|
|
|
|
};
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static inline unsigned long
|
|
|
|
harmony_read(struct snd_harmony *h, unsigned r)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return __raw_readl(h->iobase + r);
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static inline void
|
|
|
|
harmony_write(struct snd_harmony *h, unsigned r, unsigned long v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
__raw_writel(v, h->iobase + r);
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static inline void
|
|
|
|
harmony_wait_for_control(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
while (harmony_read(h, HARMONY_CNTL) & HARMONY_CNTL_C) ;
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static inline void
|
|
|
|
harmony_reset(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
harmony_write(h, HARMONY_RESET, 1);
|
|
|
|
mdelay(50);
|
|
|
|
harmony_write(h, HARMONY_RESET, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
harmony_disable_interrupts(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 dstatus;
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
dstatus = harmony_read(h, HARMONY_DSTATUS);
|
|
|
|
dstatus &= ~HARMONY_DSTATUS_IE;
|
|
|
|
harmony_write(h, HARMONY_DSTATUS, dstatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
harmony_enable_interrupts(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 dstatus;
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
dstatus = harmony_read(h, HARMONY_DSTATUS);
|
|
|
|
dstatus |= HARMONY_DSTATUS_IE;
|
|
|
|
harmony_write(h, HARMONY_DSTATUS, dstatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
harmony_mute(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&h->mixer_lock, flags);
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
harmony_write(h, HARMONY_GAINCTL, HARMONY_GAIN_SILENCE);
|
|
|
|
spin_unlock_irqrestore(&h->mixer_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
harmony_unmute(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&h->mixer_lock, flags);
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
harmony_write(h, HARMONY_GAINCTL, h->st.gain);
|
|
|
|
spin_unlock_irqrestore(&h->mixer_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
harmony_set_control(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 ctrl;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&h->lock, flags);
|
|
|
|
|
|
|
|
ctrl = (HARMONY_CNTL_C |
|
|
|
|
(h->st.format << 6) |
|
|
|
|
(h->st.stereo << 5) |
|
|
|
|
(h->st.rate));
|
|
|
|
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
harmony_write(h, HARMONY_CNTL, ctrl);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&h->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t
|
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 21:55:46 +08:00
|
|
|
snd_harmony_interrupt(int irq, void *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 dstatus;
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock(&h->lock);
|
|
|
|
harmony_disable_interrupts(h);
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
dstatus = harmony_read(h, HARMONY_DSTATUS);
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
|
|
|
|
if (dstatus & HARMONY_DSTATUS_PN) {
|
2005-10-22 10:42:38 +08:00
|
|
|
if (h->psubs && h->st.playing) {
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&h->lock);
|
|
|
|
h->pbuf.buf += h->pbuf.count; /* PAGE_SIZE */
|
|
|
|
h->pbuf.buf %= h->pbuf.size; /* MAX_BUFS*PAGE_SIZE */
|
|
|
|
|
|
|
|
harmony_write(h, HARMONY_PNXTADD,
|
|
|
|
h->pbuf.addr + h->pbuf.buf);
|
|
|
|
h->stats.play_intr++;
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
snd_pcm_period_elapsed(h->psubs);
|
|
|
|
} else {
|
|
|
|
spin_lock(&h->lock);
|
|
|
|
harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
|
|
|
|
h->stats.silence_intr++;
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstatus & HARMONY_DSTATUS_RN) {
|
2005-10-22 10:42:38 +08:00
|
|
|
if (h->csubs && h->st.capturing) {
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&h->lock);
|
|
|
|
h->cbuf.buf += h->cbuf.count;
|
|
|
|
h->cbuf.buf %= h->cbuf.size;
|
|
|
|
|
|
|
|
harmony_write(h, HARMONY_RNXTADD,
|
|
|
|
h->cbuf.addr + h->cbuf.buf);
|
|
|
|
h->stats.rec_intr++;
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
snd_pcm_period_elapsed(h->csubs);
|
|
|
|
} else {
|
|
|
|
spin_lock(&h->lock);
|
|
|
|
harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
|
|
|
|
h->stats.graveyard_intr++;
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock(&h->lock);
|
|
|
|
harmony_enable_interrupts(h);
|
|
|
|
spin_unlock(&h->lock);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
snd_harmony_rate_bits(int rate)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(snd_harmony_rates); i++)
|
|
|
|
if (snd_harmony_rates[i] == rate)
|
|
|
|
return rate_bits[i];
|
|
|
|
|
|
|
|
return HARMONY_SR_44KHZ;
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static struct snd_pcm_hardware snd_harmony_playback =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_JOINT_DUPLEX | SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER),
|
|
|
|
.formats = (SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_MU_LAW |
|
|
|
|
SNDRV_PCM_FMTBIT_A_LAW),
|
|
|
|
.rates = (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000 |
|
|
|
|
SNDRV_PCM_RATE_KNOT),
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = MAX_BUF_SIZE,
|
|
|
|
.period_bytes_min = BUF_SIZE,
|
|
|
|
.period_bytes_max = BUF_SIZE,
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = MAX_BUFS,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static struct snd_pcm_hardware snd_harmony_capture =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_JOINT_DUPLEX | SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER),
|
|
|
|
.formats = (SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_MU_LAW |
|
|
|
|
SNDRV_PCM_FMTBIT_A_LAW),
|
|
|
|
.rates = (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000 |
|
|
|
|
SNDRV_PCM_RATE_KNOT),
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = MAX_BUF_SIZE,
|
|
|
|
.period_bytes_min = BUF_SIZE,
|
|
|
|
.period_bytes_max = BUF_SIZE,
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = MAX_BUFS,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_playback_trigger(struct snd_pcm_substream *ss, int cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (h->st.capturing)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
h->st.playing = 1;
|
|
|
|
harmony_write(h, HARMONY_PNXTADD, h->pbuf.addr);
|
|
|
|
harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
|
|
|
|
harmony_unmute(h);
|
|
|
|
harmony_enable_interrupts(h);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
h->st.playing = 0;
|
|
|
|
harmony_mute(h);
|
2005-10-22 10:42:38 +08:00
|
|
|
harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
harmony_disable_interrupts(h);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
default:
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_capture_trigger(struct snd_pcm_substream *ss, int cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (h->st.playing)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
h->st.capturing = 1;
|
|
|
|
harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
|
|
|
|
harmony_write(h, HARMONY_RNXTADD, h->cbuf.addr);
|
|
|
|
harmony_unmute(h);
|
|
|
|
harmony_enable_interrupts(h);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
h->st.capturing = 0;
|
2005-10-22 10:42:38 +08:00
|
|
|
harmony_mute(h);
|
|
|
|
harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
|
|
|
|
harmony_disable_interrupts(h);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
default:
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock(&h->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_set_data_format(struct snd_harmony *h, int fmt, int force)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int o = h->st.format;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
switch(fmt) {
|
|
|
|
case SNDRV_PCM_FORMAT_S16_BE:
|
|
|
|
n = HARMONY_DF_16BIT_LINEAR;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_A_LAW:
|
|
|
|
n = HARMONY_DF_8BIT_ALAW;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_MU_LAW:
|
|
|
|
n = HARMONY_DF_8BIT_ULAW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
n = HARMONY_DF_16BIT_LINEAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (force || o != n) {
|
|
|
|
snd_pcm_format_set_silence(fmt, h->sdma.area, SILENCE_BUFSZ /
|
|
|
|
(snd_pcm_format_physical_width(fmt)
|
|
|
|
/ 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_playback_prepare(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (h->st.capturing)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
h->pbuf.size = snd_pcm_lib_buffer_bytes(ss);
|
|
|
|
h->pbuf.count = snd_pcm_lib_period_bytes(ss);
|
2005-10-22 10:42:38 +08:00
|
|
|
if (h->pbuf.buf >= h->pbuf.size)
|
|
|
|
h->pbuf.buf = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
h->st.playing = 0;
|
|
|
|
|
|
|
|
h->st.rate = snd_harmony_rate_bits(rt->rate);
|
|
|
|
h->st.format = snd_harmony_set_data_format(h, rt->format, 0);
|
|
|
|
|
|
|
|
if (rt->channels == 2)
|
|
|
|
h->st.stereo = HARMONY_SS_STEREO;
|
|
|
|
else
|
|
|
|
h->st.stereo = HARMONY_SS_MONO;
|
|
|
|
|
|
|
|
harmony_set_control(h);
|
|
|
|
|
|
|
|
h->pbuf.addr = rt->dma_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_capture_prepare(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (h->st.playing)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
h->cbuf.size = snd_pcm_lib_buffer_bytes(ss);
|
|
|
|
h->cbuf.count = snd_pcm_lib_period_bytes(ss);
|
2005-10-22 10:42:38 +08:00
|
|
|
if (h->cbuf.buf >= h->cbuf.size)
|
|
|
|
h->cbuf.buf = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
h->st.capturing = 0;
|
|
|
|
|
|
|
|
h->st.rate = snd_harmony_rate_bits(rt->rate);
|
|
|
|
h->st.format = snd_harmony_set_data_format(h, rt->format, 0);
|
|
|
|
|
|
|
|
if (rt->channels == 2)
|
|
|
|
h->st.stereo = HARMONY_SS_STEREO;
|
|
|
|
else
|
|
|
|
h->st.stereo = HARMONY_SS_MONO;
|
|
|
|
|
|
|
|
harmony_set_control(h);
|
|
|
|
|
|
|
|
h->cbuf.addr = rt->dma_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_playback_pointer(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long pcuradd;
|
|
|
|
unsigned long played;
|
|
|
|
|
|
|
|
if (!(h->st.playing) || (h->psubs == NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((h->pbuf.addr == 0) || (h->pbuf.size == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pcuradd = harmony_read(h, HARMONY_PCURADD);
|
|
|
|
played = pcuradd - h->pbuf.addr;
|
|
|
|
|
|
|
|
#ifdef HARMONY_DEBUG
|
|
|
|
printk(KERN_DEBUG PFX "playback_pointer is 0x%lx-0x%lx = %d bytes\n",
|
|
|
|
pcuradd, h->pbuf.addr, played);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pcuradd > h->pbuf.addr + h->pbuf.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_to_frames(rt, played);
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_capture_pointer(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long rcuradd;
|
|
|
|
unsigned long caught;
|
|
|
|
|
|
|
|
if (!(h->st.capturing) || (h->csubs == NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((h->cbuf.addr == 0) || (h->cbuf.size == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rcuradd = harmony_read(h, HARMONY_RCURADD);
|
|
|
|
caught = rcuradd - h->cbuf.addr;
|
|
|
|
|
|
|
|
#ifdef HARMONY_DEBUG
|
|
|
|
printk(KERN_DEBUG PFX "capture_pointer is 0x%lx-0x%lx = %d bytes\n",
|
|
|
|
rcuradd, h->cbuf.addr, caught);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (rcuradd > h->cbuf.addr + h->cbuf.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_to_frames(rt, caught);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_playback_open(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
h->psubs = ss;
|
|
|
|
rt->hw = snd_harmony_playback;
|
|
|
|
snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
&hw_constraint_rates);
|
|
|
|
|
|
|
|
err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_capture_open(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
|
|
|
struct snd_pcm_runtime *rt = ss->runtime;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
h->csubs = ss;
|
|
|
|
rt->hw = snd_harmony_capture;
|
|
|
|
snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
&hw_constraint_rates);
|
|
|
|
|
|
|
|
err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_playback_close(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
h->psubs = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_capture_close(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
h->csubs = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_hw_params(struct snd_pcm_substream *ss,
|
|
|
|
struct snd_pcm_hw_params *hw)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_pcm_substream_chip(ss);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = snd_pcm_lib_malloc_pages(ss, params_buffer_bytes(hw));
|
|
|
|
if (err > 0 && h->dma.type == SNDRV_DMA_TYPE_CONTINUOUS)
|
|
|
|
ss->runtime->dma_addr = __pa(ss->runtime->dma_area);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_hw_free(struct snd_pcm_substream *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return snd_pcm_lib_free_pages(ss);
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static struct snd_pcm_ops snd_harmony_playback_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = snd_harmony_playback_open,
|
|
|
|
.close = snd_harmony_playback_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_harmony_hw_params,
|
|
|
|
.hw_free = snd_harmony_hw_free,
|
|
|
|
.prepare = snd_harmony_playback_prepare,
|
|
|
|
.trigger = snd_harmony_playback_trigger,
|
|
|
|
.pointer = snd_harmony_playback_pointer,
|
|
|
|
};
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static struct snd_pcm_ops snd_harmony_capture_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = snd_harmony_capture_open,
|
|
|
|
.close = snd_harmony_capture_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_harmony_hw_params,
|
|
|
|
.hw_free = snd_harmony_hw_free,
|
|
|
|
.prepare = snd_harmony_capture_prepare,
|
|
|
|
.trigger = snd_harmony_capture_trigger,
|
|
|
|
.pointer = snd_harmony_capture_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_pcm_init(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_pcm *pcm;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
ALSA: sound/parisc: Move dereference after NULL test
If the NULL test on h is needed in snd_harmony_mixer_init, then the
dereference should be after the NULL test.
Actually, there is a sequence of calls: snd_harmony_create, then
snd_harmony_pcm_init, and then snd_harmony_mixer_init. snd_harmony_create
initializes h, but may indeed leave it as NULL. There was no NULL test at
the beginning of snd_harmony_pcm_init, so I have added one. The NULL test
in snd_harmony_mixer_init is then not necessary, but in case the ordering
of the calls changes, I have left it, and moved the dereference after it.
A simplified version of the semantic match that detects this problem is as
follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-10-17 14:33:47 +08:00
|
|
|
if (snd_BUG_ON(!h))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
harmony_disable_interrupts(h);
|
|
|
|
|
|
|
|
err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
&snd_harmony_playback_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
|
|
|
|
&snd_harmony_capture_ops);
|
|
|
|
|
|
|
|
pcm->private_data = h;
|
|
|
|
pcm->info_flags = 0;
|
|
|
|
strcpy(pcm->name, "harmony");
|
|
|
|
h->pcm = pcm;
|
|
|
|
|
|
|
|
h->psubs = NULL;
|
|
|
|
h->csubs = NULL;
|
|
|
|
|
|
|
|
/* initialize graveyard buffer */
|
|
|
|
h->dma.type = SNDRV_DMA_TYPE_DEV;
|
|
|
|
h->dma.dev = &h->dev->dev;
|
|
|
|
err = snd_dma_alloc_pages(h->dma.type,
|
|
|
|
h->dma.dev,
|
|
|
|
BUF_SIZE*GRAVEYARD_BUFS,
|
|
|
|
&h->gdma);
|
|
|
|
if (err < 0) {
|
|
|
|
printk(KERN_ERR PFX "cannot allocate graveyard buffer!\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize silence buffers */
|
|
|
|
err = snd_dma_alloc_pages(h->dma.type,
|
|
|
|
h->dma.dev,
|
|
|
|
BUF_SIZE*SILENCE_BUFS,
|
|
|
|
&h->sdma);
|
|
|
|
if (err < 0) {
|
|
|
|
printk(KERN_ERR PFX "cannot allocate silence buffer!\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pre-allocate space for DMA */
|
|
|
|
err = snd_pcm_lib_preallocate_pages_for_all(pcm, h->dma.type,
|
|
|
|
h->dma.dev,
|
|
|
|
MAX_BUF_SIZE,
|
|
|
|
MAX_BUF_SIZE);
|
|
|
|
if (err < 0) {
|
|
|
|
printk(KERN_ERR PFX "buffer allocation error: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->st.format = snd_harmony_set_data_format(h,
|
|
|
|
SNDRV_PCM_FORMAT_S16_BE, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_set_new_gain(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
harmony_wait_for_control(h);
|
|
|
|
harmony_write(h, HARMONY_GAINCTL, h->st.gain);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_mixercontrol_info(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int mask = (kc->private_value >> 16) & 0xff;
|
|
|
|
int left_shift = (kc->private_value) & 0xff;
|
|
|
|
int right_shift = (kc->private_value >> 8) & 0xff;
|
|
|
|
|
|
|
|
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN :
|
|
|
|
SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = left_shift == right_shift ? 1 : 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_volume_get(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_kcontrol_chip(kc);
|
2005-04-17 06:20:36 +08:00
|
|
|
int shift_left = (kc->private_value) & 0xff;
|
|
|
|
int shift_right = (kc->private_value >> 8) & 0xff;
|
|
|
|
int mask = (kc->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kc->private_value >> 24) & 0xff;
|
|
|
|
int left, right;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock_irq(&h->mixer_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
left = (h->st.gain >> shift_left) & mask;
|
|
|
|
right = (h->st.gain >> shift_right) & mask;
|
|
|
|
if (invert) {
|
|
|
|
left = mask - left;
|
|
|
|
right = mask - right;
|
|
|
|
}
|
2005-10-22 10:42:38 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ucontrol->value.integer.value[0] = left;
|
2005-10-22 10:42:38 +08:00
|
|
|
if (shift_left != shift_right)
|
|
|
|
ucontrol->value.integer.value[1] = right;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock_irq(&h->mixer_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_volume_put(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_kcontrol_chip(kc);
|
2005-04-17 06:20:36 +08:00
|
|
|
int shift_left = (kc->private_value) & 0xff;
|
|
|
|
int shift_right = (kc->private_value >> 8) & 0xff;
|
|
|
|
int mask = (kc->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kc->private_value >> 24) & 0xff;
|
|
|
|
int left, right;
|
|
|
|
int old_gain = h->st.gain;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock_irq(&h->mixer_lock);
|
2005-10-22 10:42:38 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
left = ucontrol->value.integer.value[0] & mask;
|
2005-10-22 10:42:38 +08:00
|
|
|
if (invert)
|
2005-04-17 06:20:36 +08:00
|
|
|
left = mask - left;
|
2005-10-22 10:42:38 +08:00
|
|
|
h->st.gain &= ~( (mask << shift_left ) );
|
|
|
|
h->st.gain |= (left << shift_left);
|
|
|
|
|
|
|
|
if (shift_left != shift_right) {
|
|
|
|
right = ucontrol->value.integer.value[1] & mask;
|
|
|
|
if (invert)
|
|
|
|
right = mask - right;
|
|
|
|
h->st.gain &= ~( (mask << shift_right) );
|
|
|
|
h->st.gain |= (right << shift_right);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-10-22 10:42:38 +08:00
|
|
|
|
|
|
|
snd_harmony_set_new_gain(h);
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock_irq(&h->mixer_lock);
|
2005-10-22 10:42:38 +08:00
|
|
|
|
|
|
|
return h->st.gain != old_gain;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_captureroute_info(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-10-22 10:42:38 +08:00
|
|
|
{
|
2014-10-21 00:15:26 +08:00
|
|
|
static const char * const texts[2] = { "Line", "Mic" };
|
|
|
|
|
|
|
|
return snd_ctl_enum_info(uinfo, 1, 2, texts);
|
2005-10-22 10:42:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_captureroute_get(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-10-22 10:42:38 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_kcontrol_chip(kc);
|
2005-10-22 10:42:38 +08:00
|
|
|
int value;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock_irq(&h->mixer_lock);
|
2005-10-22 10:42:38 +08:00
|
|
|
|
|
|
|
value = (h->st.gain >> HARMONY_GAIN_IS_SHIFT) & 1;
|
|
|
|
ucontrol->value.enumerated.item[0] = value;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock_irq(&h->mixer_lock);
|
2005-10-22 10:42:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_captureroute_put(struct snd_kcontrol *kc,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-10-22 10:42:38 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = snd_kcontrol_chip(kc);
|
2005-10-22 10:42:38 +08:00
|
|
|
int value;
|
|
|
|
int old_gain = h->st.gain;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_lock_irq(&h->mixer_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-22 10:42:38 +08:00
|
|
|
value = ucontrol->value.enumerated.item[0] & 1;
|
|
|
|
h->st.gain &= ~HARMONY_GAIN_IS_MASK;
|
|
|
|
h->st.gain |= value << HARMONY_GAIN_IS_SHIFT;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_harmony_set_new_gain(h);
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
spin_unlock_irq(&h->mixer_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-22 10:42:38 +08:00
|
|
|
return h->st.gain != old_gain;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
#define HARMONY_CONTROLS ARRAY_SIZE(snd_harmony_controls)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
|
|
|
|
.info = snd_harmony_mixercontrol_info, \
|
|
|
|
.get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
|
|
|
|
.private_value = ((left_shift) | ((right_shift) << 8) | \
|
|
|
|
((mask) << 16) | ((invert) << 24)) }
|
|
|
|
|
2005-11-17 22:12:11 +08:00
|
|
|
static struct snd_kcontrol_new snd_harmony_controls[] = {
|
2005-10-22 10:42:38 +08:00
|
|
|
HARMONY_VOLUME("Master Playback Volume", HARMONY_GAIN_LO_SHIFT,
|
2005-04-17 06:20:36 +08:00
|
|
|
HARMONY_GAIN_RO_SHIFT, HARMONY_GAIN_OUT, 1),
|
|
|
|
HARMONY_VOLUME("Capture Volume", HARMONY_GAIN_LI_SHIFT,
|
|
|
|
HARMONY_GAIN_RI_SHIFT, HARMONY_GAIN_IN, 0),
|
2005-10-22 10:42:38 +08:00
|
|
|
HARMONY_VOLUME("Monitor Volume", HARMONY_GAIN_MA_SHIFT,
|
|
|
|
HARMONY_GAIN_MA_SHIFT, HARMONY_GAIN_MA, 1),
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Input Route",
|
|
|
|
.info = snd_harmony_captureroute_info,
|
|
|
|
.get = snd_harmony_captureroute_get,
|
|
|
|
.put = snd_harmony_captureroute_put
|
|
|
|
},
|
|
|
|
HARMONY_VOLUME("Internal Speaker Switch", HARMONY_GAIN_SE_SHIFT,
|
|
|
|
HARMONY_GAIN_SE_SHIFT, 1, 0),
|
|
|
|
HARMONY_VOLUME("Line-Out Switch", HARMONY_GAIN_LE_SHIFT,
|
|
|
|
HARMONY_GAIN_LE_SHIFT, 1, 0),
|
|
|
|
HARMONY_VOLUME("Headphones Switch", HARMONY_GAIN_HE_SHIFT,
|
|
|
|
HARMONY_GAIN_HE_SHIFT, 1, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2012-12-07 01:35:16 +08:00
|
|
|
static void
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_mixer_reset(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
harmony_mute(h);
|
|
|
|
harmony_reset(h);
|
|
|
|
h->st.gain = HARMONY_GAIN_DEFAULT;
|
|
|
|
harmony_unmute(h);
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:16 +08:00
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_mixer_init(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
ALSA: sound/parisc: Move dereference after NULL test
If the NULL test on h is needed in snd_harmony_mixer_init, then the
dereference should be after the NULL test.
Actually, there is a sequence of calls: snd_harmony_create, then
snd_harmony_pcm_init, and then snd_harmony_mixer_init. snd_harmony_create
initializes h, but may indeed leave it as NULL. There was no NULL test at
the beginning of snd_harmony_pcm_init, so I have added one. The NULL test
in snd_harmony_mixer_init is then not necessary, but in case the ordering
of the calls changes, I have left it, and moved the dereference after it.
A simplified version of the semantic match that detects this problem is as
follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-10-17 14:33:47 +08:00
|
|
|
struct snd_card *card;
|
2005-04-17 06:20:36 +08:00
|
|
|
int idx, err;
|
|
|
|
|
2008-08-08 23:12:47 +08:00
|
|
|
if (snd_BUG_ON(!h))
|
2008-09-02 01:45:58 +08:00
|
|
|
return -EINVAL;
|
ALSA: sound/parisc: Move dereference after NULL test
If the NULL test on h is needed in snd_harmony_mixer_init, then the
dereference should be after the NULL test.
Actually, there is a sequence of calls: snd_harmony_create, then
snd_harmony_pcm_init, and then snd_harmony_mixer_init. snd_harmony_create
initializes h, but may indeed leave it as NULL. There was no NULL test at
the beginning of snd_harmony_pcm_init, so I have added one. The NULL test
in snd_harmony_mixer_init is then not necessary, but in case the ordering
of the calls changes, I have left it, and moved the dereference after it.
A simplified version of the semantic match that detects this problem is as
follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-10-17 14:33:47 +08:00
|
|
|
card = h->card;
|
2005-04-17 06:20:36 +08:00
|
|
|
strcpy(card->mixername, "Harmony Gain control interface");
|
|
|
|
|
|
|
|
for (idx = 0; idx < HARMONY_CONTROLS; idx++) {
|
|
|
|
err = snd_ctl_add(card,
|
|
|
|
snd_ctl_new1(&snd_harmony_controls[idx], h));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_harmony_mixer_reset(h);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_free(struct snd_harmony *h)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (h->gdma.addr)
|
|
|
|
snd_dma_free_pages(&h->gdma);
|
|
|
|
if (h->sdma.addr)
|
|
|
|
snd_dma_free_pages(&h->sdma);
|
|
|
|
|
|
|
|
if (h->irq >= 0)
|
|
|
|
free_irq(h->irq, h);
|
|
|
|
|
2015-01-04 05:55:54 +08:00
|
|
|
iounmap(h->iobase);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(h);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_dev_free(struct snd_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h = dev->device_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
return snd_harmony_free(h);
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:16 +08:00
|
|
|
static int
|
2005-11-17 22:12:11 +08:00
|
|
|
snd_harmony_create(struct snd_card *card,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct parisc_device *padev,
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony **rchip)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_harmony *h;
|
|
|
|
static struct snd_device_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_free = snd_harmony_dev_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
*rchip = NULL;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
h = kzalloc(sizeof(*h), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (h == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2005-10-22 10:36:40 +08:00
|
|
|
h->hpa = padev->hpa.start;
|
2005-04-17 06:20:36 +08:00
|
|
|
h->card = card;
|
|
|
|
h->dev = padev;
|
2005-11-17 17:34:40 +08:00
|
|
|
h->irq = -1;
|
2005-10-22 10:36:40 +08:00
|
|
|
h->iobase = ioremap_nocache(padev->hpa.start, HARMONY_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (h->iobase == NULL) {
|
|
|
|
printk(KERN_ERR PFX "unable to remap hpa 0x%lx\n",
|
2009-05-15 22:00:38 +08:00
|
|
|
(unsigned long)padev->hpa.start);
|
2005-04-17 06:20:36 +08:00
|
|
|
err = -EBUSY;
|
|
|
|
goto free_and_ret;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
err = request_irq(padev->irq, snd_harmony_interrupt, 0,
|
2005-04-17 06:20:36 +08:00
|
|
|
"harmony", h);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR PFX "could not obtain interrupt %d",
|
2005-11-17 17:34:40 +08:00
|
|
|
padev->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto free_and_ret;
|
|
|
|
}
|
2005-11-17 17:34:40 +08:00
|
|
|
h->irq = padev->irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_init(&h->mixer_lock);
|
|
|
|
spin_lock_init(&h->lock);
|
|
|
|
|
|
|
|
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
|
|
|
|
h, &ops)) < 0) {
|
|
|
|
goto free_and_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rchip = h;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_and_ret:
|
|
|
|
snd_harmony_free(h);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:16 +08:00
|
|
|
static int
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_harmony_probe(struct parisc_device *padev)
|
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 22:12:11 +08:00
|
|
|
struct snd_card *card;
|
|
|
|
struct snd_harmony *h;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-01-29 21:35:40 +08:00
|
|
|
err = snd_card_new(&padev->dev, index, id, THIS_MODULE, 0, &card);
|
2008-12-28 23:45:02 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = snd_harmony_create(card, padev, &h);
|
2005-11-17 17:34:40 +08:00
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto free_and_ret;
|
|
|
|
|
|
|
|
err = snd_harmony_pcm_init(h);
|
2005-11-17 17:34:40 +08:00
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto free_and_ret;
|
|
|
|
|
|
|
|
err = snd_harmony_mixer_init(h);
|
2005-11-17 17:34:40 +08:00
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto free_and_ret;
|
|
|
|
|
|
|
|
strcpy(card->driver, "harmony");
|
|
|
|
strcpy(card->shortname, "Harmony");
|
|
|
|
sprintf(card->longname, "%s at 0x%lx, irq %i",
|
|
|
|
card->shortname, h->hpa, h->irq);
|
|
|
|
|
|
|
|
err = snd_card_register(card);
|
2005-11-17 17:34:40 +08:00
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto free_and_ret;
|
|
|
|
|
2005-11-17 17:34:40 +08:00
|
|
|
parisc_set_drvdata(padev, card);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_and_ret:
|
|
|
|
snd_card_free(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:16 +08:00
|
|
|
static int
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_harmony_remove(struct parisc_device *padev)
|
|
|
|
{
|
2005-11-17 17:34:40 +08:00
|
|
|
snd_card_free(parisc_get_drvdata(padev));
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct parisc_driver snd_harmony_driver = {
|
|
|
|
.name = "harmony",
|
|
|
|
.id_table = snd_harmony_devtable,
|
|
|
|
.probe = snd_harmony_probe,
|
2012-12-07 01:35:16 +08:00
|
|
|
.remove = snd_harmony_remove,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
alsa_harmony_init(void)
|
|
|
|
{
|
2005-11-17 17:34:40 +08:00
|
|
|
return register_parisc_driver(&snd_harmony_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
alsa_harmony_fini(void)
|
|
|
|
{
|
2005-11-17 22:12:11 +08:00
|
|
|
unregister_parisc_driver(&snd_harmony_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
|
|
|
|
MODULE_DESCRIPTION("Harmony sound driver");
|
|
|
|
|
|
|
|
module_init(alsa_harmony_init);
|
|
|
|
module_exit(alsa_harmony_fini);
|