Commit 317e4550 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

[PATCH] ALSA Harmony sound driver for PA-RISC

ALSA Harmony rewrite
Signed-Off-By: default avatarKyle McMartin <kyle@parisc-linux.org>
Signed-off-by: default avatarStuart Brady <sdbrady@ntlworld.com>
Signed-off-by: default avatarMatthew Wilcox <willy@parisc-linux.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dadfb803
...@@ -920,6 +920,13 @@ M: khc@pm.waw.pl ...@@ -920,6 +920,13 @@ M: khc@pm.waw.pl
W: http://www.kernel.org/pub/linux/utils/net/hdlc/ W: http://www.kernel.org/pub/linux/utils/net/hdlc/
S: Maintained S: Maintained
HARMONY SOUND DRIVER
P: Kyle McMartin
M: kyle@parisc-linux.org
W: http://www.parisc-linux.org/~kyle/harmony/
L: parisc-linux@lists.parisc-linux.org
S: Maintained
HAYES ESP SERIAL DRIVER HAYES ESP SERIAL DRIVER
P: Andrew J. Robinson P: Andrew J. Robinson
M: arobinso@nyx.net M: arobinso@nyx.net
......
# ALSA PA-RISC drivers # ALSA PA-RISC drivers
menu "ALSA GSC devices" menu "GSC devices"
depends on SND!=n && GSC depends on SND!=n && GSC
config SND_HARMONY config SND_HARMONY
......
/* /* Hewlett-Packard Harmony audio driver
* Harmony chipset driver
* *
* This is a sound driver for ASP's and Lasi's Harmony sound chip * This is a driver for the Harmony audio chipset found
* and is unlikely to be used for anything other than on a HP PA-RISC. * on the LASI ASIC of various early HP PA-RISC workstations.
* *
* Harmony is found in HP 712s, 715/new and many other GSC based machines. * Copyright (C) 2004, Kyle McMartin <kyle@{debian.org,parisc-linux.org}>
* On older 715 machines you'll find the technically identical chip
* called 'Vivace'. Both Harmony and Vivace are supported by this driver.
* *
* this ALSA driver is based on OSS driver by: * Based on the previous Harmony incarnations by,
* Copyright 2000 (c) Linuxcare Canada, Alex deVries <alex@linuxcare.com> * Copyright 2000 (c) Linuxcare Canada, Alex deVries
* Copyright 2000-2002 (c) Helge Deller <deller@gmx.de> * Copyright 2000-2003 (c) Helge Deller
* Copyright 2001 (c) Matthieu Delahaye <delahaym@esiee.fr> * Copyright 2001 (c) Matthieu Delahaye
* Copyright 2001 (c) Jean-Christophe Vaugeois
* Copyright 2003 (c) Laurent Canet
* Copyright 2004 (c) Stuart Brady
* *
* TODO: * This program is free software; you can redistribute it and/or modify
* - use generic DMA interface and ioremap()/iounmap() * it under the terms of the GNU General Public License, version 2, as
* - capture is still untested (and probaby non-working) * published by the Free Software Foundation.
* - spin locks
* - implement non-consistent DMA pages
* - implement gain meter
* - module parameters
* - correct cleaning sequence
* - better error checking
* - try to have a better quality.
*
*/
/*
* Harmony chipset 'modus operandi'.
* - This chipset is found in some HP 32bit workstations, like 712, or B132 class.
* most of controls are done through registers. Register are found at a fixed offset
* from the hard physical adress, given in struct dev by register_parisc_driver.
*
* Playback and recording use 4kb pages (dma or not, depending on the machine).
* *
* Most of PCM playback & capture is done through interrupt. When harmony needs * This program is distributed in the hope that it will be useful,
* a new buffer to put recorded data or read played PCM, it sends an interrupt. * but WITHOUT ANY WARRANTY; without even the implied warranty of
* Bits 2 and 10 of DSTATUS register are '1' when harmony needs respectively * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* a new page for recording and playing. * GNU General Public License for more details.
* Interrupt are disabled/enabled by writing to bit 32 of DSTATUS.
* Adresses of next page to be played is put in PNXTADD register, next page
* to be recorded is put in RNXTADD. There is 2 read-only registers, PCURADD and
* RCURADD that provides adress of current page.
* *
* Harmony has no way to control full duplex or half duplex mode. It means * You should have received a copy of the GNU General Public License
* that we always need to provide adresses of playback and capture data, even * along with this program; if not, write to the Free Software
* when this is not needed. That's why we statically alloc one graveyard * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* buffer (to put recorded data in play-only mode) and a silence buffer.
* *
* Bitrate, number of channels and data format are controlled with * Notes:
* the CNTL register. * - graveyard and silence buffers last for lifetime of
* the driver. playback and capture buffers are allocated
* per _open()/_close().
* *
* Mixer work is done through one register (GAINCTL). Only input gain, * TODO:
* output attenuation and general attenuation control is provided. There is
* also controls for enabling/disabling internal speaker and line
* input.
* *
* Buffers used by this driver are all DMA consistent.
*/ */
#include <linux/delay.h>
#include <sound/driver.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/moduleparam.h> #include <linux/delay.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/dma-mapping.h>
#include <sound/driver.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/control.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/control.h>
#include <sound/rawmidi.h> #include <sound/rawmidi.h>
#include <sound/initval.h> #include <sound/initval.h>
#include <sound/info.h> #include <sound/info.h>
#include <asm/hardware.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/hardware.h>
#include <asm/parisc-device.h> #include <asm/parisc-device.h>
MODULE_AUTHOR("Laurent Canet <canetl@esiee.fr>"); #include "harmony.h"
MODULE_DESCRIPTION("ALSA Harmony sound driver");
MODULE_LICENSE("GPL"); static struct parisc_device_id snd_harmony_devtable[] = {
MODULE_SUPPORTED_DEVICE("{{ALSA,Harmony soundcard}}"); /* bushmaster / flounder */
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A },
#undef DEBUG /* 712 / 715 */
#ifdef DEBUG { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B },
# define DPRINTK printk /* pace */
#else { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E },
# define DPRINTK(x,...) /* outfield / coral II */
#endif { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F },
{ 0, }
#define PFX "harmony: " };
#define MAX_PCM_DEVICES 1
#define MAX_PCM_SUBSTREAMS 4
#define MAX_MIDI_DEVICES 0
#define HARMONY_BUF_SIZE 4096
#define MAX_BUFS 10
#define MAX_BUFFER_SIZE (MAX_BUFS * HARMONY_BUF_SIZE)
/* number of silence & graveyard buffers */
#define GRAVEYARD_BUFS 3
#define SILENCE_BUFS 3
#define HARMONY_CNTL_C 0x80000000
#define HARMONY_DSTATUS_PN 0x00000200
#define HARMONY_DSTATUS_RN 0x00000002
#define HARMONY_DSTATUS_IE 0x80000000
#define HARMONY_DF_16BIT_LINEAR 0x00000000
#define HARMONY_DF_8BIT_ULAW 0x00000001
#define HARMONY_DF_8BIT_ALAW 0x00000002
#define HARMONY_SS_MONO 0x00000000
#define HARMONY_SS_STEREO 0x00000001
/*
* Channels Mask in mixer register
* try some "reasonable" default gain values
*/
#define HARMONY_GAIN_TOTAL_SILENCE 0x00F00FFF
/* the following should be enough (mixer is
* very sensible on harmony)
*/
#define HARMONY_GAIN_DEFAULT 0x0F2FF082
/* useless since only one card is supported ATM */
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for Harmony device.");
module_param_array(id, charp, NULL, 0444);
MODULE_PARM_DESC(id, "ID string for Harmony device.");
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "Enable Harmony device.");
/* Register offset (from base hpa) */
#define REG_ID 0x00
#define REG_RESET 0x04
#define REG_CNTL 0x08
#define REG_GAINCTL 0x0C
#define REG_PNXTADD 0x10
#define REG_PCURADD 0x14
#define REG_RNXTADD 0x18
#define REG_RCURADD 0x1C
#define REG_DSTATUS 0x20
#define REG_OV 0x24
#define REG_PIO 0x28
#define REG_DIAG 0x3C
/*
* main harmony structure
*/
typedef struct snd_card_harmony {
/* spinlocks (To be done) */
spinlock_t mixer_lock;
spinlock_t control_lock;
/* parameters */
int irq;
unsigned long hpa;
int id;
int rev;
u32 current_gain;
int data_format; /* HARMONY_DF_xx_BIT_xxx */
int sample_rate; /* HARMONY_SR_xx_KHZ */
int stereo_select; /* HARMONY_SS_MONO or HARMONY_SS_STEREO */
int format_initialized;
unsigned long ply_buffer;
int ply_buf;
int ply_count;
int ply_size;
int ply_stopped;
int ply_total;
unsigned long cap_buffer;
int cap_buf;
int cap_count;
int cap_size;
int cap_stopped;
int cap_total;
struct parisc_device *pa_dev;
struct snd_dma_device dma_dev;
/* the graveyard buffer is used as recording buffer when playback,
* because harmony always want a buffer to put recorded data */
struct snd_dma_buffer graveyard_dma;
int graveyard_count;
/* same thing for silence buffer */
struct snd_dma_buffer silence_dma;
int silence_count;
/* alsa stuff */
snd_card_t *card;
snd_pcm_t *pcm;
snd_pcm_substream_t *playback_substream;
snd_pcm_substream_t *capture_substream;
snd_info_entry_t *proc_entry;
} snd_card_harmony_t;
static snd_card_t *snd_harmony_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
/* wait to be out of control mode */
static inline void snd_harmony_wait_cntl(snd_card_harmony_t *harmony)
{
int timeout = 5000;
while ( (gsc_readl(harmony->hpa+REG_CNTL) & HARMONY_CNTL_C) && --timeout) MODULE_DEVICE_TABLE(parisc, snd_harmony_devtable);
{
/* Wait */ ;
}
if (timeout == 0) DPRINTK(KERN_DEBUG PFX "Error: wait cntl timeouted\n");
}
#define NAME "harmony"
#define PFX NAME ": "
/* static unsigned int snd_harmony_rates[] = {
* sample rate routines 5512, 6615, 8000, 9600,
*/
static unsigned int snd_card_harmony_rates[] = {
5125, 6615, 8000, 9600,
11025, 16000, 18900, 22050, 11025, 16000, 18900, 22050,
27428, 32000, 33075, 37800, 27428, 32000, 33075, 37800,
44100, 48000 44100, 48000
}; };
static snd_pcm_hw_constraint_list_t hw_constraint_rates = {
.count = ARRAY_SIZE(snd_card_harmony_rates),
.list = snd_card_harmony_rates,
.mask = 0,
};
#define HARMONY_SR_8KHZ 0x08
#define HARMONY_SR_16KHZ 0x09
#define HARMONY_SR_27KHZ 0x0A
#define HARMONY_SR_32KHZ 0x0B
#define HARMONY_SR_48KHZ 0x0E
#define HARMONY_SR_9KHZ 0x0F
#define HARMONY_SR_5KHZ 0x10
#define HARMONY_SR_11KHZ 0x11
#define HARMONY_SR_18KHZ 0x12
#define HARMONY_SR_22KHZ 0x13
#define HARMONY_SR_37KHZ 0x14
#define HARMONY_SR_44KHZ 0x15
#define HARMONY_SR_33KHZ 0x16
#define HARMONY_SR_6KHZ 0x17
/* bits corresponding to the entries of snd_card_harmony_rates */
static unsigned int rate_bits[14] = { static unsigned int rate_bits[14] = {
HARMONY_SR_5KHZ, HARMONY_SR_6KHZ, HARMONY_SR_8KHZ, HARMONY_SR_5KHZ, HARMONY_SR_6KHZ, HARMONY_SR_8KHZ,
HARMONY_SR_9KHZ, HARMONY_SR_11KHZ, HARMONY_SR_16KHZ, HARMONY_SR_9KHZ, HARMONY_SR_11KHZ, HARMONY_SR_16KHZ,
...@@ -267,642 +91,624 @@ static unsigned int rate_bits[14] = { ...@@ -267,642 +91,624 @@ static unsigned int rate_bits[14] = {
HARMONY_SR_44KHZ, HARMONY_SR_48KHZ HARMONY_SR_44KHZ, HARMONY_SR_48KHZ
}; };
/* snd_card_harmony_rate_bits static snd_pcm_hw_constraint_list_t hw_constraint_rates = {
* @rate: index of current data rate in list .count = ARRAY_SIZE(snd_harmony_rates),
* returns: harmony hex code for registers .list = snd_harmony_rates,
*/ .mask = 0,
static unsigned int snd_card_harmony_rate_bits(int rate) };
{
unsigned int idx;
for (idx = 0; idx < ARRAY_SIZE(snd_card_harmony_rates); idx++) inline unsigned long
if (snd_card_harmony_rates[idx] == rate) harmony_read(harmony_t *h, unsigned r)
return rate_bits[idx]; {
return HARMONY_SR_44KHZ; /* fallback */ return __raw_readl(h->iobase + r);
} }
/* inline void
* update controls (data format, sample rate, number of channels) harmony_write(harmony_t *h, unsigned r, unsigned long v)
* according to value supplied in data structure
*/
void snd_harmony_update_control(snd_card_harmony_t *harmony)
{ {
u32 default_cntl; __raw_writel(v, h->iobase + r);
}
/* Set CNTL */
default_cntl = (HARMONY_CNTL_C | /* The C bit */
(harmony->data_format << 6) | /* Set the data format */
(harmony->stereo_select << 5) | /* Stereo select */
(harmony->sample_rate)); /* Set sample rate */
/* initialize CNTL */ static void
snd_harmony_wait_cntl(harmony); harmony_wait_for_control(harmony_t *h)
{
while (harmony_read(h, HARMONY_CNTL) & HARMONY_CNTL_C) ;
}
gsc_writel(default_cntl, harmony->hpa+REG_CNTL); inline void
harmony_reset(harmony_t *h)
{
harmony_write(h, HARMONY_RESET, 1);
mdelay(50);
harmony_write(h, HARMONY_RESET, 0);
}
static void
harmony_disable_interrupts(harmony_t *h)
{
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
* interruption controls routines harmony_enable_interrupts(harmony_t *h)
*/ {
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 snd_harmony_disable_interrupts(snd_card_harmony_t *chip) static void
harmony_mute(harmony_t *h)
{ {
snd_harmony_wait_cntl(chip); unsigned long flags;
gsc_writel(0, chip->hpa+REG_DSTATUS);
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 snd_harmony_enable_interrupts(snd_card_harmony_t *chip) static void
harmony_unmute(harmony_t *h)
{ {
snd_harmony_wait_cntl(chip); unsigned long flags;
gsc_writel(HARMONY_DSTATUS_IE, chip->hpa+REG_DSTATUS);
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
* interruption routine: harmony_set_control(harmony_t *h)
* The interrupt routine must provide adresse of next physical pages
* used by harmony
*/
static int snd_card_harmony_interrupt(int irq, void *dev, struct pt_regs *regs)
{ {
snd_card_harmony_t *harmony = (snd_card_harmony_t *)dev; u32 ctrl;
u32 dstatus = 0; unsigned long flags;
unsigned long hpa = harmony->hpa;
/* Turn off interrupts */ spin_lock_irqsave(&h->lock, flags);
snd_harmony_disable_interrupts(harmony);
/* wait for control to free */ ctrl = (HARMONY_CNTL_C |
snd_harmony_wait_cntl(harmony); (h->st.format << 6) |
(h->st.stereo << 5) |
(h->st.rate));
/* Read dstatus and pcuradd (the current address) */ harmony_wait_for_control(h);
dstatus = gsc_readl(hpa+REG_DSTATUS); harmony_write(h, HARMONY_CNTL, ctrl);
/* Check if this is a request to get the next play buffer */ spin_unlock_irqrestore(&h->lock, flags);
if (dstatus & HARMONY_DSTATUS_PN) { }
if (harmony->playback_substream) {
harmony->ply_buf += harmony->ply_count; static irqreturn_t
harmony->ply_buf %= harmony->ply_size; snd_harmony_interrupt(int irq, void *dev, struct pt_regs *regs)
{
u32 dstatus;
harmony_t *h = dev;
gsc_writel(harmony->ply_buffer + harmony->ply_buf, spin_lock(&h->lock);
hpa+REG_PNXTADD); harmony_disable_interrupts(h);
harmony_wait_for_control(h);
dstatus = harmony_read(h, HARMONY_DSTATUS);
spin_unlock(&h->lock);
snd_pcm_period_elapsed(harmony->playback_substream); if (dstatus & HARMONY_DSTATUS_PN) {
harmony->ply_total++; if (h->psubs) {
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 { } else {
gsc_writel(harmony->silence_dma.addr + spin_lock(&h->lock);
(HARMONY_BUF_SIZE*harmony->silence_count), harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
hpa+REG_PNXTADD); h->stats.silence_intr++;
harmony->silence_count++; spin_unlock(&h->lock);
harmony->silence_count %= SILENCE_BUFS;
} }
} }
/* Check if we're being asked to fill in a recording buffer */
if (dstatus & HARMONY_DSTATUS_RN) { if (dstatus & HARMONY_DSTATUS_RN) {
if (harmony->capture_substream) { if (h->csubs) {
harmony->cap_buf += harmony->cap_count; spin_lock(&h->lock);
harmony->cap_buf %= harmony->cap_size; h->cbuf.buf += h->cbuf.count;
h->cbuf.buf %= h->cbuf.size;
gsc_writel(harmony->cap_buffer + harmony->cap_buf,
hpa+REG_RNXTADD); harmony_write(h, HARMONY_RNXTADD,
h->cbuf.addr + h->cbuf.buf);
snd_pcm_period_elapsed(harmony->capture_substream); h->stats.rec_intr++;
harmony->cap_total++; spin_unlock(&h->lock);
snd_pcm_period_elapsed(h->csubs);
} else { } else {
/* graveyard buffer */ spin_lock(&h->lock);
gsc_writel(harmony->graveyard_dma.addr + harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
(HARMONY_BUF_SIZE*harmony->graveyard_count), h->stats.graveyard_intr++;
hpa+REG_RNXTADD); spin_unlock(&h->lock);
harmony->graveyard_count++;
harmony->graveyard_count %= GRAVEYARD_BUFS;
} }
} }
snd_harmony_enable_interrupts(harmony);
spin_lock(&h->lock);
harmony_enable_interrupts(h);
spin_unlock(&h->lock);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
/* static unsigned int
* proc entry snd_harmony_rate_bits(int rate)
* this proc file will give some debugging info
*/
static void snd_harmony_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
{ {
snd_card_harmony_t *harmony = (snd_card_harmony_t *)entry->private_data; unsigned int i;
snd_iprintf(buffer, "LASI Harmony driver\nLaurent Canet <canetl@esiee.fr>\n\n");
snd_iprintf(buffer, "IRQ %d, hpa %lx, id %d rev %d\n",
harmony->irq, harmony->hpa,
harmony->id, harmony->rev);
snd_iprintf(buffer, "Current gain %lx\n", (unsigned long) harmony->current_gain);
snd_iprintf(buffer, "\tsample rate=%d\n", harmony->sample_rate);
snd_iprintf(buffer, "\tstereo select=%d\n", harmony->stereo_select);
snd_iprintf(buffer, "\tbitperchan=%d\n\n", harmony->data_format);
snd_iprintf(buffer, "Play status:\n");
snd_iprintf(buffer, "\tstopped %d\n", harmony->ply_stopped);
snd_iprintf(buffer, "\tbuffer %lx, count %d\n", harmony->ply_buffer, harmony->ply_count);
snd_iprintf(buffer, "\tbuf %d size %d\n\n", harmony->ply_buf, harmony->ply_size);
snd_iprintf(buffer, "Capture status:\n");
snd_iprintf(buffer, "\tstopped %d\n", harmony->cap_stopped);
snd_iprintf(buffer, "\tbuffer %lx, count %d\n", harmony->cap_buffer, harmony->cap_count);
snd_iprintf(buffer, "\tbuf %d, size %d\n\n", harmony->cap_buf, harmony->cap_size);
snd_iprintf(buffer, "Funny stats: total played=%d, recorded=%d\n\n", harmony->ply_total, harmony->cap_total);
snd_iprintf(buffer, "Register:\n");
snd_iprintf(buffer, "\tgainctl: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_GAINCTL));
snd_iprintf(buffer, "\tcntl: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_CNTL));
snd_iprintf(buffer, "\tid: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_ID));
snd_iprintf(buffer, "\tpcuradd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_PCURADD));
snd_iprintf(buffer, "\trcuradd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_RCURADD));
snd_iprintf(buffer, "\tpnxtadd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_PNXTADD));
snd_iprintf(buffer, "\trnxtadd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_RNXTADD));
snd_iprintf(buffer, "\tdstatus: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_DSTATUS));
snd_iprintf(buffer, "\tov: %lx\n\n", (unsigned long) gsc_readl(harmony->hpa+REG_OV));
} for (i = 0; i < ARRAY_SIZE(snd_harmony_rates); i++)
if (snd_harmony_rates[i] == rate)
static void __devinit snd_harmony_proc_init(snd_card_harmony_t *harmony) return rate_bits[i];
{
snd_info_entry_t *entry;
if (! snd_card_proc_new(harmony->card, "harmony", &entry)) return HARMONY_SR_44KHZ;
snd_info_set_text_ops(entry, harmony, 2048, snd_harmony_proc_read);
} }
/* static snd_pcm_hardware_t snd_harmony_playback =
* PCM Stuff
*/
static int snd_card_harmony_playback_ioctl(snd_pcm_substream_t * substream,
unsigned int cmd,
void *arg)
{ {
return snd_pcm_lib_ioctl(substream, cmd, arg); .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 snd_card_harmony_capture_ioctl(snd_pcm_substream_t * substream, static snd_pcm_hardware_t snd_harmony_capture =
unsigned int cmd,
void *arg)
{ {
return snd_pcm_lib_ioctl(substream, cmd, arg); .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 snd_card_harmony_playback_trigger(snd_pcm_substream_t * substream, static int
int cmd) snd_harmony_playback_trigger(snd_pcm_substream_t *ss, int cmd)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
unsigned long flags;
switch (cmd) { if (h->st.capturing)
case SNDRV_PCM_TRIGGER_STOP:
if (harmony->ply_stopped)
return -EBUSY; return -EBUSY;
harmony->ply_stopped = 1;
snd_harmony_disable_interrupts(harmony); spin_lock_irqsave(&h->lock, flags);
break; switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
if (!harmony->ply_stopped) h->st.playing = 1;
return -EBUSY; harmony_write(h, HARMONY_PNXTADD, h->pbuf.addr);
harmony->ply_stopped = 0; harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
/* write the location of the first buffer to play */ harmony_unmute(h);
gsc_writel(harmony->ply_buffer, harmony->hpa+REG_PNXTADD); harmony_enable_interrupts(h);
snd_harmony_enable_interrupts(harmony); break;
case SNDRV_PCM_TRIGGER_STOP:
h->st.playing = 0;
harmony_mute(h);
harmony_disable_interrupts(h);
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
DPRINTK(KERN_INFO PFX "received unimplemented trigger: %d\n", cmd);
default: default:
spin_unlock_irqrestore(&h->lock, flags);
snd_BUG();
return -EINVAL; return -EINVAL;
} }
spin_unlock_irqrestore(&h->lock, flags);
return 0; return 0;
} }
static int snd_card_harmony_capture_trigger(snd_pcm_substream_t * substream, static int
int cmd) snd_harmony_capture_trigger(snd_pcm_substream_t *ss, int cmd)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
unsigned long flags;
switch (cmd) { if (h->st.playing)
case SNDRV_PCM_TRIGGER_STOP:
if (harmony->cap_stopped)
return -EBUSY; return -EBUSY;
harmony->cap_stopped = 1;
snd_harmony_disable_interrupts(harmony); spin_lock_irqsave(&h->lock, flags);
break; switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
if (!harmony->cap_stopped) h->st.capturing = 1;
return -EBUSY; harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
harmony->cap_stopped = 0; harmony_write(h, HARMONY_RNXTADD, h->cbuf.addr);
snd_harmony_enable_interrupts(harmony); harmony_unmute(h);
harmony_enable_interrupts(h);
break;
case SNDRV_PCM_TRIGGER_STOP:
h->st.capturing = 0;
harmony_mute(h);
harmony_disable_interrupts(h);
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
DPRINTK(KERN_INFO PFX "Received unimplemented trigger: %d\n", cmd);
default: default:
spin_unlock_irqrestore(&h->lock, flags);
snd_BUG();
return -EINVAL; return -EINVAL;
} }
spin_unlock_irqrestore(&h->lock, flags);
return 0; return 0;
} }
/* set data format */ static int
static int snd_harmony_set_data_format(snd_card_harmony_t *harmony, int pcm_format) snd_harmony_set_data_format(harmony_t *h, int fmt)
{ {
int old_format = harmony->data_format; int o = h->st.format;
int new_format = old_format; int n;
switch (pcm_format) {
switch(fmt) {
case SNDRV_PCM_FORMAT_S16_BE: case SNDRV_PCM_FORMAT_S16_BE:
new_format = HARMONY_DF_16BIT_LINEAR; n = HARMONY_DF_16BIT_LINEAR;
break; break;
case SNDRV_PCM_FORMAT_A_LAW: case SNDRV_PCM_FORMAT_A_LAW:
new_format = HARMONY_DF_8BIT_ALAW; n = HARMONY_DF_8BIT_ALAW;
break; break;
case SNDRV_PCM_FORMAT_MU_LAW: case SNDRV_PCM_FORMAT_MU_LAW:
new_format = HARMONY_DF_8BIT_ULAW; n = HARMONY_DF_8BIT_ULAW;
break;
default:
n = HARMONY_DF_16BIT_LINEAR;
break; break;
} }
/* re-initialize silence buffer if needed */
if (old_format != new_format)
snd_pcm_format_set_silence(pcm_format, harmony->silence_dma.area,
(HARMONY_BUF_SIZE * SILENCE_BUFS * 8) / snd_pcm_format_width(pcm_format));
return new_format; if (o != n) {
snd_pcm_format_set_silence(fmt, h->sdma.area,
SILENCE_BUFSZ /
snd_pcm_format_width(fmt));
}
return n;
} }
static int snd_card_harmony_playback_prepare(snd_pcm_substream_t * substream) static int
snd_harmony_playback_prepare(snd_pcm_substream_t *ss)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *rt = ss->runtime;
harmony->ply_size = snd_pcm_lib_buffer_bytes(substream); if (h->st.capturing)
harmony->ply_count = snd_pcm_lib_period_bytes(substream); return -EBUSY;
harmony->ply_buf = 0;
harmony->ply_stopped = 1;
/* initialize given sample rate */ h->pbuf.size = snd_pcm_lib_buffer_bytes(ss);
harmony->sample_rate = snd_card_harmony_rate_bits(runtime->rate); h->pbuf.count = snd_pcm_lib_period_bytes(ss);
h->pbuf.buf = 0;
h->st.playing = 0;
/* data format */ h->st.rate = snd_harmony_rate_bits(rt->rate);
harmony->data_format = snd_harmony_set_data_format(harmony, runtime->format); h->st.format = snd_harmony_set_data_format(h, rt->format);
/* number of channels */ if (rt->channels == 2)
if (runtime->channels == 2) h->st.stereo = HARMONY_SS_STEREO;
harmony->stereo_select = HARMONY_SS_STEREO;
else else
harmony->stereo_select = HARMONY_SS_MONO; h->st.stereo = HARMONY_SS_MONO;
harmony_set_control(h);
DPRINTK(KERN_INFO PFX "Playback_prepare, sr=%d(%x), df=%x, ss=%x hpa=%lx\n", runtime->rate, h->pbuf.addr = rt->dma_addr;
harmony->sample_rate, harmony->data_format, harmony->stereo_select, harmony->hpa);
snd_harmony_update_control(harmony);
harmony->format_initialized = 1;
harmony->ply_buffer = runtime->dma_addr;
return 0; return 0;
} }
static int snd_card_harmony_capture_prepare(snd_pcm_substream_t * substream) static int
snd_harmony_capture_prepare(snd_pcm_substream_t *ss)
{ {
snd_pcm_runtime_t *runtime = substream->runtime; harmony_t *h = snd_pcm_substream_chip(ss);
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *rt = ss->runtime;
harmony->cap_size = snd_pcm_lib_buffer_bytes(substream); if (h->st.playing)
harmony->cap_count = snd_pcm_lib_period_bytes(substream); return -EBUSY;
harmony->cap_count = 0;
harmony->cap_stopped = 1;
/* initialize given sample rate */ h->cbuf.size = snd_pcm_lib_buffer_bytes(ss);
harmony->sample_rate = snd_card_harmony_rate_bits(runtime->rate); h->cbuf.count = snd_pcm_lib_period_bytes(ss);
h->cbuf.buf = 0;
h->st.capturing = 0;
/* data format */ h->st.rate = snd_harmony_rate_bits(rt->rate);
harmony->data_format = snd_harmony_set_data_format(harmony, runtime->format); h->st.format = snd_harmony_set_data_format(h, rt->format);
/* number of channels */ if (rt->channels == 2)
if (runtime->channels == 1) h->st.stereo = HARMONY_SS_STEREO;
harmony->stereo_select = HARMONY_SS_MONO; else
else if (runtime->channels == 2) h->st.stereo = HARMONY_SS_MONO;
harmony->stereo_select = HARMONY_SS_STEREO;
snd_harmony_update_control(harmony); harmony_set_control(h);
harmony->format_initialized = 1;
harmony->cap_buffer = runtime->dma_addr; h->cbuf.addr = rt->dma_addr;
return 0; return 0;
} }
static snd_pcm_uframes_t snd_card_harmony_capture_pointer(snd_pcm_substream_t * substream) static snd_pcm_uframes_t
snd_harmony_playback_pointer(snd_pcm_substream_t *ss)
{ {
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *rt = ss->runtime;
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
unsigned long rcuradd; unsigned long pcuradd;
int recorded; unsigned long played;
if (harmony->cap_stopped) return 0; if (!(h->st.playing) || (h->psubs == NULL))
if (harmony->capture_substream == NULL) return 0; return 0;
rcuradd = gsc_readl(harmony->hpa+REG_RCURADD); if ((h->pbuf.addr == 0) || (h->pbuf.size == 0))
recorded = (rcuradd - harmony->cap_buffer); return 0;
recorded %= harmony->cap_size;
return bytes_to_frames(runtime, recorded); 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
static snd_pcm_uframes_t snd_card_harmony_playback_pointer(snd_pcm_substream_t * substream) if (pcuradd > h->pbuf.addr + h->pbuf.size) {
{ return 0;
snd_pcm_runtime_t *runtime = substream->runtime; }
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
int played;
long int pcuradd = gsc_readl(harmony->hpa+REG_PCURADD);
if ((harmony->ply_stopped) || (harmony->playback_substream == NULL)) return 0; return bytes_to_frames(rt, played);
if ((harmony->ply_buffer == 0) || (harmony->ply_size == 0)) return 0; }
played = (pcuradd - harmony->ply_buffer); static snd_pcm_uframes_t
snd_harmony_capture_pointer(snd_pcm_substream_t *ss)
{
snd_pcm_runtime_t *rt = ss->runtime;
harmony_t *h = snd_pcm_substream_chip(ss);
unsigned long rcuradd;
unsigned long caught;
printk(KERN_DEBUG PFX "Pointer is %lx-%lx = %d\n", pcuradd, harmony->ply_buffer, played); if (!(h->st.capturing) || (h->csubs == NULL))
return 0;
if (pcuradd > harmony->ply_buffer + harmony->ply_size) return 0; if ((h->cbuf.addr == 0) || (h->cbuf.size == 0))
return 0;
return bytes_to_frames(runtime, played); rcuradd = harmony_read(h, HARMONY_RCURADD);
} caught = rcuradd - h->cbuf.addr;
static snd_pcm_hardware_t snd_card_harmony_playback = #ifdef HARMONY_DEBUG
{ printk(KERN_DEBUG PFX "capture_pointer is 0x%lx-0x%lx = %d bytes\n",
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | rcuradd, h->cbuf.addr, caught);
SNDRV_PCM_INFO_JOINT_DUPLEX | #endif
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_BLOCK_TRANSFER),
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_BE |
SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_MU_LAW),
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
.rate_min = 5500,
.rate_max = 48000,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = MAX_BUFFER_SIZE,
.period_bytes_min = HARMONY_BUF_SIZE,
.period_bytes_max = HARMONY_BUF_SIZE,
.periods_min = 1,
.periods_max = MAX_BUFS,
.fifo_size = 0,
};
static snd_pcm_hardware_t snd_card_harmony_capture = if (rcuradd > h->cbuf.addr + h->cbuf.size) {
{ return 0;
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | }
SNDRV_PCM_INFO_JOINT_DUPLEX |
SNDRV_PCM_INFO_MMAP_VALID | return bytes_to_frames(rt, caught);
SNDRV_PCM_INFO_BLOCK_TRANSFER), }
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_BE |
SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_MU_LAW),
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
.rate_min = 5500,
.rate_max = 48000,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = MAX_BUFFER_SIZE,
.period_bytes_min = HARMONY_BUF_SIZE,
.period_bytes_max = HARMONY_BUF_SIZE,
.periods_min = 1,
.periods_max = MAX_BUFS,
.fifo_size = 0,
};
static int snd_card_harmony_playback_open(snd_pcm_substream_t * substream) static int
snd_harmony_playback_open(snd_pcm_substream_t *ss)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *rt = ss->runtime;
int err; int err;
harmony->playback_substream = substream; h->psubs = ss;
runtime->hw = snd_card_harmony_playback; rt->hw = snd_harmony_playback;
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates); snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
&hw_constraint_rates);
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
if (err < 0)
return err; return err;
return 0; return 0;
} }
static int snd_card_harmony_capture_open(snd_pcm_substream_t * substream) static int
snd_harmony_capture_open(snd_pcm_substream_t *ss)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *rt = ss->runtime;
int err; int err;
harmony->capture_substream = substream; h->csubs = ss;
runtime->hw = snd_card_harmony_capture; rt->hw = snd_harmony_capture;
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates); snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) &hw_constraint_rates);
err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
if (err < 0)
return err; return err;
return 0;
return 0;
} }
static int snd_card_harmony_playback_close(snd_pcm_substream_t * substream) static int
snd_harmony_playback_close(snd_pcm_substream_t *ss)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
h->psubs = NULL;
harmony->playback_substream = NULL;
harmony->ply_size = 0;
harmony->ply_buf = 0;
harmony->ply_buffer = 0;
harmony->ply_count = 0;
harmony->ply_stopped = 1;
harmony->format_initialized = 0;
return 0; return 0;
} }
static int snd_card_harmony_capture_close(snd_pcm_substream_t * substream) static int
snd_harmony_capture_close(snd_pcm_substream_t *ss)
{ {
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
h->csubs = NULL;
harmony->capture_substream = NULL;
harmony->cap_size = 0;
harmony->cap_buf = 0;
harmony->cap_buffer = 0;
harmony->cap_count = 0;
harmony->cap_stopped = 1;
harmony->format_initialized = 0;
return 0; return 0;
} }
static int snd_card_harmony_hw_params(snd_pcm_substream_t *substream, static int
snd_pcm_hw_params_t * hw_params) snd_harmony_hw_params(snd_pcm_substream_t *ss,
snd_pcm_hw_params_t *hw)
{ {
int err; int err;
snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream); harmony_t *h = snd_pcm_substream_chip(ss);
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);
err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
if (err > 0 && harmony->dma_dev.type == SNDRV_DMA_TYPE_CONTINUOUS)
substream->runtime->dma_addr = __pa(substream->runtime->dma_area);
DPRINTK(KERN_INFO PFX "HW Params returned %d, dma_addr %lx\n", err,
(unsigned long)substream->runtime->dma_addr);
return err; return err;
} }
static int snd_card_harmony_hw_free(snd_pcm_substream_t *substream) static int
snd_harmony_hw_free(snd_pcm_substream_t *ss)
{ {
snd_pcm_lib_free_pages(substream); return snd_pcm_lib_free_pages(ss);
return 0;
} }
static snd_pcm_ops_t snd_card_harmony_playback_ops = { static snd_pcm_ops_t snd_harmony_playback_ops = {
.open = snd_card_harmony_playback_open, .open = snd_harmony_playback_open,
.close = snd_card_harmony_playback_close, .close = snd_harmony_playback_close,
.ioctl = snd_card_harmony_playback_ioctl, .ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_card_harmony_hw_params, .hw_params = snd_harmony_hw_params,
.hw_free = snd_card_harmony_hw_free, .hw_free = snd_harmony_hw_free,
.prepare = snd_card_harmony_playback_prepare, .prepare = snd_harmony_playback_prepare,
.trigger = snd_card_harmony_playback_trigger, .trigger = snd_harmony_playback_trigger,
.pointer = snd_card_harmony_playback_pointer, .pointer = snd_harmony_playback_pointer,
}; };
static snd_pcm_ops_t snd_card_harmony_capture_ops = { static snd_pcm_ops_t snd_harmony_capture_ops = {
.open = snd_card_harmony_capture_open, .open = snd_harmony_capture_open,
.close = snd_card_harmony_capture_close, .close = snd_harmony_capture_close,
.ioctl = snd_card_harmony_capture_ioctl, .ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_card_harmony_hw_params, .hw_params = snd_harmony_hw_params,
.hw_free = snd_card_harmony_hw_free, .hw_free = snd_harmony_hw_free,
.prepare = snd_card_harmony_capture_prepare, .prepare = snd_harmony_capture_prepare,
.trigger = snd_card_harmony_capture_trigger, .trigger = snd_harmony_capture_trigger,
.pointer = snd_card_harmony_capture_pointer, .pointer = snd_harmony_capture_pointer,
}; };
static int snd_card_harmony_pcm_init(snd_card_harmony_t *harmony) static int
snd_harmony_pcm_init(harmony_t *h)
{ {
snd_pcm_t *pcm; snd_pcm_t *pcm;
int err; int err;
/* Request that IRQ */ harmony_disable_interrupts(h);
if (request_irq(harmony->irq, snd_card_harmony_interrupt, 0 ,"harmony", harmony)) {
printk(KERN_ERR PFX "Error requesting irq %d.\n", harmony->irq);
return -EFAULT;
}
snd_harmony_disable_interrupts(harmony);
if ((err = snd_pcm_new(harmony->card, "Harmony", 0, 1, 1, &pcm)) < 0) err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm);
if (err < 0)
return err; return err;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_harmony_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_harmony_capture_ops); &snd_harmony_playback_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
&snd_harmony_capture_ops);
pcm->private_data = harmony; pcm->private_data = h;
pcm->info_flags = 0; pcm->info_flags = 0;
strcpy(pcm->name, "Harmony"); strcpy(pcm->name, "harmony");
harmony->pcm = pcm; h->pcm = pcm;
h->psubs = NULL;
h->csubs = NULL;
/* initialize graveyard buffer */ /* initialize graveyard buffer */
harmony->dma_dev.type = SNDRV_DMA_TYPE_DEV; h->dma.type = SNDRV_DMA_TYPE_DEV;
harmony->dma_dev.dev = &harmony->pa_dev->dev; h->dma.dev = &h->dev->dev;
err = snd_dma_alloc_pages(harmony->dma_dev.type, err = snd_dma_alloc_pages(h->dma.type,
harmony->dma_dev.dev, h->dma.dev,
HARMONY_BUF_SIZE*GRAVEYARD_BUFS, BUF_SIZE*GRAVEYARD_BUFS,
&harmony->graveyard_dma); &h->gdma);
if (err == -ENOMEM) {
/* use continuous buffers */
harmony->dma_dev.type = SNDRV_DMA_TYPE_CONTINUOUS;
harmony->dma_dev.dev = snd_dma_continuous_data(GFP_KERNEL);
err = snd_dma_alloc_pages(harmony->dma_dev.type,
harmony->dma_dev.dev,
HARMONY_BUF_SIZE*GRAVEYARD_BUFS,
&harmony->graveyard_dma);
}
if (err < 0) { if (err < 0) {
printk(KERN_ERR PFX "can't allocate graveyard buffer\n"); printk(KERN_ERR PFX "cannot allocate graveyard buffer!\n");
return err; return err;
} }
harmony->graveyard_count = 0;
/* initialize silence buffers */ /* initialize silence buffers */
err = snd_dma_alloc_pages(harmony->dma_dev.type, err = snd_dma_alloc_pages(h->dma.type,
harmony->dma_dev.dev, h->dma.dev,
HARMONY_BUF_SIZE*SILENCE_BUFS, BUF_SIZE*SILENCE_BUFS,
&harmony->silence_dma); &h->sdma);
if (err < 0) { if (err < 0) {
printk(KERN_ERR PFX "can't allocate silence buffer\n"); printk(KERN_ERR PFX "cannot allocate silence buffer!\n");
return err; return err;
} }
harmony->silence_count = 0;
if (harmony->dma_dev.type == SNDRV_DMA_TYPE_CONTINUOUS) { /* pre-allocate space for DMA */
harmony->graveyard_dma.addr = __pa(harmony->graveyard_dma.area); err = snd_pcm_lib_preallocate_pages_for_all(pcm, h->dma.type,
harmony->silence_dma.addr = __pa(harmony->silence_dma.area); h->dma.dev,
} MAX_BUF_SIZE,
MAX_BUF_SIZE);
harmony->ply_stopped = harmony->cap_stopped = 1;
harmony->playback_substream = NULL;
harmony->capture_substream = NULL;
harmony->graveyard_count = 0;
err = snd_pcm_lib_preallocate_pages_for_all(pcm, harmony->dma_dev.type,
harmony->dma_dev.dev,
MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
if (err < 0) { if (err < 0) {
printk(KERN_ERR PFX "buffer allocation error %d\n", err); printk(KERN_ERR PFX "buffer allocation error: %d\n", err);
// return err; return err;
} }
return 0; return 0;
} }
/* static void
* mixer routines snd_harmony_set_new_gain(harmony_t *h)
*/
static void snd_harmony_set_new_gain(snd_card_harmony_t *harmony)
{ {
DPRINTK(KERN_INFO PFX "Setting new gain %x at %lx\n", harmony->current_gain, harmony->hpa+REG_GAINCTL); harmony_wait_for_control(h);
/* Wait until we're out of control mode */ harmony_write(h, HARMONY_GAINCTL, h->st.gain);
snd_harmony_wait_cntl(harmony);
gsc_writel(harmony->current_gain, harmony->hpa+REG_GAINCTL);
} }
#define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \ static int
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ snd_harmony_mixercontrol_info(snd_kcontrol_t *kc,
.info = snd_harmony_mixercontrol_info, \ snd_ctl_elem_info_t *uinfo)
.get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
.private_value = ((left_shift) | ((right_shift) << 8) | ((mask) << 16) | ((invert) << 24)) }
static int snd_harmony_mixercontrol_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
{ {
int mask = (kcontrol->private_value >> 16) & 0xff; int mask = (kc->private_value >> 16) & 0xff;
int left_shift = (kcontrol->private_value) & 0xff; int left_shift = (kc->private_value) & 0xff;
int right_shift = (kcontrol->private_value >> 8) & 0xff; int right_shift = (kc->private_value >> 8) & 0xff;
uinfo->type = (mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER); uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN :
uinfo->count = (left_shift == right_shift) ? 1 : 2; SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = left_shift == right_shift ? 1 : 2;
uinfo->value.integer.min = 0; uinfo->value.integer.min = 0;
uinfo->value.integer.max = mask; uinfo->value.integer.max = mask;
return 0; return 0;
} }
static int snd_harmony_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) static int
snd_harmony_volume_get(snd_kcontrol_t *kc,
snd_ctl_elem_value_t *ucontrol)
{ {
snd_card_harmony_t *harmony = snd_kcontrol_chip(kcontrol); harmony_t *h = snd_kcontrol_chip(kc);
int shift_left = (kcontrol->private_value) & 0xff; int shift_left = (kc->private_value) & 0xff;
int shift_right = (kcontrol->private_value >> 8) & 0xff; int shift_right = (kc->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff; int mask = (kc->private_value >> 16) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff; int invert = (kc->private_value >> 24) & 0xff;
unsigned long flags;
int left, right; int left, right;
unsigned long flags;
spin_lock_irqsave(&harmony->mixer_lock, flags); spin_lock_irqsave(&h->mixer_lock, flags);
left = (harmony->current_gain >> shift_left) & mask;
right = (harmony->current_gain >> shift_right) & mask; left = (h->st.gain >> shift_left) & mask;
right = (h->st.gain >> shift_right) & mask;
if (invert) { if (invert) {
left = mask - left; left = mask - left;
...@@ -910,21 +716,24 @@ static int snd_harmony_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ ...@@ -910,21 +716,24 @@ static int snd_harmony_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
} }
ucontrol->value.integer.value[0] = left; ucontrol->value.integer.value[0] = left;
ucontrol->value.integer.value[1] = right; ucontrol->value.integer.value[1] = right;
spin_unlock_irqrestore(&harmony->mixer_lock, flags);
spin_unlock_irqrestore(&h->mixer_lock, flags);
return 0; return 0;
} }
static int snd_harmony_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) static int
snd_harmony_volume_put(snd_kcontrol_t *kc,
snd_ctl_elem_value_t *ucontrol)
{ {
snd_card_harmony_t *harmony = snd_kcontrol_chip(kcontrol); harmony_t *h = snd_kcontrol_chip(kc);
int shift_left = (kcontrol->private_value) & 0xff; int shift_left = (kc->private_value) & 0xff;
int shift_right = (kcontrol->private_value >> 8) & 0xff; int shift_right = (kc->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff; int mask = (kc->private_value >> 16) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff; int invert = (kc->private_value >> 24) & 0xff;
unsigned long flags;
int left, right; int left, right;
int old_gain = harmony->current_gain; int old_gain = h->st.gain;
unsigned long flags;
left = ucontrol->value.integer.value[0] & mask; left = ucontrol->value.integer.value[0] & mask;
right = ucontrol->value.integer.value[1] & mask; right = ucontrol->value.integer.value[1] & mask;
...@@ -933,213 +742,249 @@ static int snd_harmony_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ ...@@ -933,213 +742,249 @@ static int snd_harmony_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
right = mask - right; right = mask - right;
} }
spin_lock_irqsave(&harmony->mixer_lock, flags); spin_lock_irqsave(&h->mixer_lock, flags);
harmony->current_gain = harmony->current_gain & ~( (mask << shift_right) | (mask << shift_left));
harmony->current_gain = harmony->current_gain | ((left << shift_left) | (right << shift_right) ); h->st.gain &= ~( (mask << shift_right) | (mask << shift_left) );
snd_harmony_set_new_gain(harmony); h->st.gain |= ( (left << shift_left) | (right << shift_right) );
spin_unlock_irqrestore(&harmony->mixer_lock, flags); snd_harmony_set_new_gain(h);
return (old_gain - harmony->current_gain); spin_unlock_irqrestore(&h->mixer_lock, flags);
return (old_gain - h->st.gain);
} }
#define HARMONY_CONTROLS (sizeof(snd_harmony_controls)/sizeof(snd_kcontrol_new_t)) #define HARMONY_CONTROLS (sizeof(snd_harmony_controls)/ \
sizeof(snd_kcontrol_new_t))
#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)) }
static snd_kcontrol_new_t snd_harmony_controls[] = { static snd_kcontrol_new_t snd_harmony_controls[] = {
HARMONY_VOLUME("PCM Capture Volume", 12, 16, 0x0f, 0), HARMONY_VOLUME("Playback Volume", HARMONY_GAIN_LO_SHIFT,
HARMONY_VOLUME("Master Volume", 20, 20, 0x0f, 1), HARMONY_GAIN_RO_SHIFT, HARMONY_GAIN_OUT, 1),
HARMONY_VOLUME("PCM Playback Volume", 6, 0, 0x3f, 1), HARMONY_VOLUME("Capture Volume", HARMONY_GAIN_LI_SHIFT,
HARMONY_GAIN_RI_SHIFT, HARMONY_GAIN_IN, 0),
}; };
static void __init snd_harmony_reset_codec(snd_card_harmony_t *harmony) static void __init
snd_harmony_mixer_reset(harmony_t *h)
{ {
snd_harmony_wait_cntl(harmony); harmony_mute(h);
gsc_writel(1, harmony->hpa+REG_RESET); harmony_reset(h);
mdelay(50); /* wait 50 ms */ h->st.gain = HARMONY_GAIN_DEFAULT;
gsc_writel(0, harmony->hpa+REG_RESET); harmony_unmute(h);
} }
/* static int __init
* Mute all the output and reset Harmony. snd_harmony_mixer_init(harmony_t *h)
*/
static void __init snd_harmony_mixer_reset(snd_card_harmony_t *harmony)
{ {
harmony->current_gain = HARMONY_GAIN_TOTAL_SILENCE; snd_card_t *card = h->card;
snd_harmony_set_new_gain(harmony);
snd_harmony_reset_codec(harmony);
harmony->current_gain = HARMONY_GAIN_DEFAULT;
snd_harmony_set_new_gain(harmony);
}
static int __init snd_card_harmony_mixer_init(snd_card_harmony_t *harmony)
{
snd_card_t *card = harmony->card;
int idx, err; int idx, err;
snd_assert(harmony != NULL, return -EINVAL); snd_assert(h != NULL, return -EINVAL);
strcpy(card->mixername, "Harmony Gain control interface"); strcpy(card->mixername, "Harmony Gain control interface");
for (idx = 0; idx < HARMONY_CONTROLS; idx++) { for (idx = 0; idx < HARMONY_CONTROLS; idx++) {
if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_harmony_controls[idx], harmony))) < 0) err = snd_ctl_add(card,
snd_ctl_new1(&snd_harmony_controls[idx], h));
if (err < 0)
return err; return err;
} }
snd_harmony_mixer_reset(harmony); snd_harmony_mixer_reset(h);
return 0; return 0;
} }
static int snd_card_harmony_create(snd_card_t *card, struct parisc_device *pa_dev, snd_card_harmony_t *harmony) static int
snd_harmony_free(harmony_t *h)
{ {
u32 cntl; if (h->gdma.addr)
snd_dma_free_pages(&h->gdma);
if (h->sdma.addr)
snd_dma_free_pages(&h->sdma);
harmony->card = card; if (h->irq >= 0)
free_irq(h->irq, h);
harmony->pa_dev = pa_dev; if (h->iobase)
iounmap(h->iobase);
/* Set the HPA of harmony */ parisc_set_drvdata(h->dev, NULL);
harmony->hpa = pa_dev->hpa;
harmony->irq = pa_dev->irq; kfree(h);
if (!harmony->irq) { return 0;
printk(KERN_ERR PFX "no irq found\n"); }
return -ENODEV;
static int
snd_harmony_dev_free(snd_device_t *dev)
{
harmony_t *h = dev->device_data;
return snd_harmony_free(h);
}
static int __devinit
snd_harmony_create(snd_card_t *card,
struct parisc_device *padev,
harmony_t **rchip)
{
int err;
harmony_t *h;
static snd_device_ops_t ops = {
.dev_free = snd_harmony_dev_free,
};
*rchip = NULL;
h = kmalloc(sizeof(*h), GFP_KERNEL);
if (h == NULL)
return -ENOMEM;
memset(&h->st, 0, sizeof(h->st));
memset(&h->stats, 0, sizeof(h->stats));
memset(&h->pbuf, 0, sizeof(h->pbuf));
memset(&h->cbuf, 0, sizeof(h->cbuf));
h->hpa = padev->hpa;
h->card = card;
h->dev = padev;
h->irq = padev->irq;
h->iobase = ioremap_nocache(padev->hpa, HARMONY_SIZE);
if (h->iobase == NULL) {
printk(KERN_ERR PFX "unable to remap hpa 0x%lx\n",
padev->hpa);
err = -EBUSY;
goto free_and_ret;
} }
/* Grab the ID and revision from the device */ err = request_irq(h->irq, snd_harmony_interrupt, 0,
harmony->id = (gsc_readl(harmony->hpa+REG_ID)&0x00ff0000) >> 16; "harmony", h);
if ((harmony->id | 1) != 0x15) { if (err) {
printk(KERN_WARNING PFX "wrong harmony id 0x%02x\n", harmony->id); printk(KERN_ERR PFX "could not obtain interrupt %d",
return -EBUSY; h->irq);
goto free_and_ret;
} }
cntl = gsc_readl(harmony->hpa+REG_CNTL);
harmony->rev = (cntl>>20) & 0xff;
printk(KERN_INFO "Lasi Harmony Audio driver h/w id %i, rev. %i at 0x%lx, IRQ %i\n", harmony->id, harmony->rev, pa_dev->hpa, harmony->irq); spin_lock_init(&h->mixer_lock);
spin_lock_init(&h->lock);
/* Make sure the control bit isn't set, although I don't think it if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
ever is. */ h, &ops)) < 0) {
if (cntl & HARMONY_CNTL_C) { goto free_and_ret;
printk(KERN_WARNING PFX "CNTL busy\n");
harmony->hpa = 0;
return -EBUSY;
} }
*rchip = h;
return 0; return 0;
free_and_ret:
snd_harmony_free(h);
return err;
} }
static int __init snd_card_harmony_probe(struct parisc_device *pa_dev) static int __devinit
snd_harmony_probe(struct parisc_device *padev)
{ {
int err;
static int dev; static int dev;
snd_card_harmony_t *chip;
snd_card_t *card; snd_card_t *card;
int err; harmony_t *h;
static int index = SNDRV_DEFAULT_IDX1;
static char *id = SNDRV_DEFAULT_STR1;
if (dev >= SNDRV_CARDS) h = parisc_get_drvdata(padev);
if (h != NULL) {
return -ENODEV; return -ENODEV;
if (!enable[dev]) {
dev++;
return -ENOENT;
} }
snd_harmony_cards[dev] = snd_card_new(index[dev], id[dev], THIS_MODULE, card = snd_card_new(index, id, THIS_MODULE, 0);
sizeof(snd_card_harmony_t));
card = snd_harmony_cards[dev];
if (card == NULL) if (card == NULL)
return -ENOMEM; return -ENOMEM;
chip = (struct snd_card_harmony *)card->private_data;
spin_lock_init(&chip->control_lock);
spin_lock_init(&chip->mixer_lock);
if ((err = snd_card_harmony_create(card, pa_dev, chip)) < 0) { err = snd_harmony_create(card, padev, &h);
printk(KERN_ERR PFX "Creation failed\n"); if (err < 0) {
snd_card_free(card); goto free_and_ret;
return err;
}
if ((err = snd_card_harmony_pcm_init(chip)) < 0) {
printk(KERN_ERR PFX "PCM Init failed\n");
snd_card_free(card);
return err;
} }
if ((err = snd_card_harmony_mixer_init(chip)) < 0) {
printk(KERN_ERR PFX "Mixer init failed\n"); err = snd_harmony_pcm_init(h);
snd_card_free(card); if (err < 0) {
return err; goto free_and_ret;
} }
snd_harmony_proc_init(chip); err = snd_harmony_mixer_init(h);
if (err < 0) {
goto free_and_ret;
}
strcpy(card->driver, "Harmony"); strcpy(card->driver, "harmony");
strcpy(card->shortname, "ALSA driver for LASI Harmony"); strcpy(card->shortname, "Harmony");
sprintf(card->longname, "%s at h/w, id %i, rev. %i hpa 0x%lx, IRQ %i\n",card->shortname, chip->id, chip->rev, pa_dev->hpa, chip->irq); sprintf(card->longname, "%s at 0x%lx, irq %i",
card->shortname, h->hpa, h->irq);
if ((err = snd_card_register(card)) < 0) { err = snd_card_register(card);
snd_card_free(card); if (err < 0) {
return err; goto free_and_ret;
} }
printk(KERN_DEBUG PFX "Successfully registered harmony pcm backend & mixer %d\n", dev);
dev++; dev++;
return 0; parisc_set_drvdata(padev, h);
}
static struct parisc_device_id snd_card_harmony_devicetbl[] = { return 0;
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A }, /* Bushmaster/Flounder */
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B }, /* 712/715 Audio */
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E }, /* Pace Audio */
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F }, /* Outfield / Coral II */
{ 0, }
};
MODULE_DEVICE_TABLE(parisc, snd_card_harmony_devicetbl); free_and_ret:
snd_card_free(card);
return err;
}
/* static int __devexit
* bloc device parisc. c'est une structure qui definit un device snd_harmony_remove(struct parisc_device *padev)
* que l'on trouve sur parisc. {
* On y trouve les differents numeros HVERSION correspondant au device harmony_t *h = parisc_get_drvdata(padev);
* en question (ce qui permet a l'inventory de l'identifier) et la fonction snd_card_free(h->card);
* d'initialisation du chose return 0;
*/ }
static struct parisc_driver snd_card_harmony_driver = { static struct parisc_driver snd_harmony_driver = {
.name = "Lasi ALSA Harmony", .name = "harmony",
.id_table = snd_card_harmony_devicetbl, .id_table = snd_harmony_devtable,
.probe = snd_card_harmony_probe, .probe = snd_harmony_probe,
.remove = snd_harmony_remove,
}; };
static int __init alsa_card_harmony_init(void) static int __init
alsa_harmony_init(void)
{ {
int err; int err;
if ((err = register_parisc_driver(&snd_card_harmony_driver)) < 0) { err = register_parisc_driver(&snd_harmony_driver);
printk(KERN_ERR "Harmony soundcard not found or device busy\n"); if (err < 0) {
printk(KERN_ERR PFX "device not found\n");
return err; return err;
} }
return 0; return 0;
} }
static void __exit alsa_card_harmony_exit(void) static void __exit
alsa_harmony_fini(void)
{ {
int idx; int err;
snd_card_harmony_t *harmony;
err = unregister_parisc_driver(&snd_harmony_driver);
for (idx = 0; idx < SNDRV_CARDS; idx++) if (err < 0) {
{ printk(KERN_ERR PFX "failed to unregister\n");
if (snd_harmony_cards[idx] != NULL)
{
DPRINTK(KERN_INFO PFX "Freeing card %d\n", idx);
harmony = snd_harmony_cards[idx]->private_data;
free_irq(harmony->irq, harmony);
printk(KERN_INFO PFX "Card unloaded %d, irq=%d\n", idx, harmony->irq);
snd_card_free(snd_harmony_cards[idx]);
}
} }
if (unregister_parisc_driver(&snd_card_harmony_driver) < 0)
printk(KERN_ERR PFX "Failed to unregister Harmony driver\n"); return;
} }
module_init(alsa_card_harmony_init) MODULE_LICENSE("GPL");
module_exit(alsa_card_harmony_exit) MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
MODULE_DESCRIPTION("Harmony sound driver");
module_init(alsa_harmony_init);
module_exit(alsa_harmony_fini);
/* Hewlett-Packard Harmony audio driver
* Copyright (C) 2004, Kyle McMartin <kyle@parisc-linux.org>
*/
#ifndef __HARMONY_H__
#define __HARMONY_H__
struct harmony_buffer {
unsigned long addr;
int buf;
int count;
int size;
int coherent;
};
typedef struct snd_card_harmony {
int irq;
unsigned long hpa; /* hard physical address */
void __iomem *iobase; /* remapped io address */
struct parisc_device *dev;
struct {
u32 gain;
u32 rate;
u32 format;
u32 stereo;
int playing;
int capturing;
} st;
struct snd_dma_device dma; /* playback/capture */
struct harmony_buffer pbuf;
struct harmony_buffer cbuf;
struct snd_dma_buffer gdma; /* graveyard */
struct snd_dma_buffer sdma; /* silence */
struct {
unsigned long play_intr;
unsigned long rec_intr;
unsigned long graveyard_intr;
unsigned long silence_intr;
} stats;
snd_pcm_t *pcm;
snd_card_t *card;
snd_pcm_substream_t *psubs;
snd_pcm_substream_t *csubs;
snd_info_entry_t *proc;
spinlock_t lock;
spinlock_t mixer_lock;
} harmony_t;
#define MAX_PCM_DEVICES 1
#define MAX_PCM_SUBSTREAMS 4
#define MAX_MIDI_DEVICES 0
#define HARMONY_SIZE 64
#define BUF_SIZE PAGE_SIZE
#define MAX_BUFS 10
#define MAX_BUF_SIZE (MAX_BUFS * BUF_SIZE)
#define PLAYBACK_BUFS MAX_BUFS
#define RECORD_BUFS MAX_BUFS
#define GRAVEYARD_BUFS 1
#define GRAVEYARD_BUFSZ (GRAVEYARD_BUFS*BUF_SIZE)
#define SILENCE_BUFS 1
#define SILENCE_BUFSZ (SILENCE_BUFS*BUF_SIZE)
#define HARMONY_ID 0x000
#define HARMONY_RESET 0x004
#define HARMONY_CNTL 0x008
#define HARMONY_GAINCTL 0x00c
#define HARMONY_PNXTADD 0x010
#define HARMONY_PCURADD 0x014
#define HARMONY_RNXTADD 0x018
#define HARMONY_RCURADD 0x01c
#define HARMONY_DSTATUS 0x020
#define HARMONY_OV 0x024
#define HARMONY_PIO 0x028
#define HARMONY_DIAG 0x03c
#define HARMONY_CNTL_C 0x80000000
#define HARMONY_CNTL_ST 0x00000020
#define HARMONY_CNTL_44100 0x00000015 /* HARMONY_SR_44KHZ */
#define HARMONY_CNTL_8000 0x00000008 /* HARMONY_SR_8KHZ */
#define HARMONY_DSTATUS_ID 0x00000000 /* interrupts off */
#define HARMONY_DSTATUS_PN 0x00000200 /* playback fill */
#define HARMONY_DSTATUS_RN 0x00000002 /* record fill */
#define HARMONY_DSTATUS_IE 0x80000000 /* interrupts on */
#define HARMONY_DF_16BIT_LINEAR 0x00000000
#define HARMONY_DF_8BIT_ULAW 0x00000001
#define HARMONY_DF_8BIT_ALAW 0x00000002
#define HARMONY_SS_MONO 0x00000000
#define HARMONY_SS_STEREO 0x00000001
#define HARMONY_GAIN_SILENCE 0x00F00FFF
#define HARMONY_GAIN_DEFAULT 0x0FF00000
#define HARMONY_GAIN_HE_SHIFT 27
#define HARMONY_GAIN_HE_MASK (1 << HARMONY_GAIN_HE_SHIFT)
#define HARMONY_GAIN_LE_SHIFT 26
#define HARMONY_GAIN_LE_MASK (1 << HARMONY_GAIN_LE_SHIFT)
#define HARMONY_GAIN_SE_SHIFT 25
#define HARMONY_GAIN_SE_MASK (1 << HARMONY_GAIN_SE_SHIFT)
#define HARMONY_GAIN_IS_SHIFT 24
#define HARMONY_GAIN_IS_MASK (1 << HARMONY_GAIN_IS_SHIFT)
#define HARMONY_GAIN_MA 0x0f
#define HARMONY_GAIN_MA_SHIFT 20
#define HARMONY_GAIN_MA_MASK (HARMONY_GAIN_MA << HARMONY_GAIN_MA_SHIFT)
#define HARMONY_GAIN_IN 0x0f
#define HARMONY_GAIN_LI_SHIFT 16
#define HARMONY_GAIN_LI_MASK (HARMONY_GAIN_IN << HARMONY_GAIN_LI_SHIFT)
#define HARMONY_GAIN_RI_SHIFT 12
#define HARMONY_GAIN_RI_MASK (HARMONY_GAIN_IN << HARMONY_GAIN_RI_SHIFT)
#define HARMONY_GAIN_OUT 0x3f
#define HARMONY_GAIN_LO_SHIFT 6
#define HARMONY_GAIN_LO_MASK (HARMONY_GAIN_OUT << HARMONY_GAIN_LO_SHIFT)
#define HARMONY_GAIN_RO_SHIFT 0
#define HARMONY_GAIN_RO_MASK (HARMONY_GAIN_OUT << HARMONY_GAIN_RO_SHIFT)
#define HARMONY_MAX_OUT (HARMONY_GAIN_RO_MASK >> HARMONY_GAIN_RO_SHIFT)
#define HARMONY_MAX_IN (HARMONY_GAIN_RI_MASK >> HARMONY_GAIN_RI_SHIFT)
#define HARMONY_MAX_MON (HARMONY_GAIN_MA_MASK >> HARMONY_GAIN_MA_SHIFT)
#define HARMONY_SR_8KHZ 0x08
#define HARMONY_SR_16KHZ 0x09
#define HARMONY_SR_27KHZ 0x0A
#define HARMONY_SR_32KHZ 0x0B
#define HARMONY_SR_48KHZ 0x0E
#define HARMONY_SR_9KHZ 0x0F
#define HARMONY_SR_5KHZ 0x10
#define HARMONY_SR_11KHZ 0x11
#define HARMONY_SR_18KHZ 0x12
#define HARMONY_SR_22KHZ 0x13
#define HARMONY_SR_37KHZ 0x14
#define HARMONY_SR_44KHZ 0x15
#define HARMONY_SR_33KHZ 0x16
#define HARMONY_SR_6KHZ 0x17
#endif /* __HARMONY_H__ */
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