18c2ecf20Sopenharmony_ci/****************************************************************************
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci   Copyright Echo Digital Audio Corporation (c) 1998 - 2004
48c2ecf20Sopenharmony_ci   All rights reserved
58c2ecf20Sopenharmony_ci   www.echoaudio.com
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci   This file is part of Echo Digital Audio's generic driver library.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci   Echo Digital Audio's generic driver library is free software;
108c2ecf20Sopenharmony_ci   you can redistribute it and/or modify it under the terms of
118c2ecf20Sopenharmony_ci   the GNU General Public License as published by the Free Software
128c2ecf20Sopenharmony_ci   Foundation.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci   This program is distributed in the hope that it will be useful,
158c2ecf20Sopenharmony_ci   but WITHOUT ANY WARRANTY; without even the implied warranty of
168c2ecf20Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178c2ecf20Sopenharmony_ci   GNU General Public License for more details.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci   You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci   along with this program; if not, write to the Free Software
218c2ecf20Sopenharmony_ci   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
228c2ecf20Sopenharmony_ci   MA  02111-1307, USA.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci ****************************************************************************
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci Translation from C++ and adaptation for use in ALSA-Driver
278c2ecf20Sopenharmony_ci were made by Giuliano Pochini <pochini@shiny.it>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci ****************************************************************************
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci   Here's a block diagram of how most of the cards work:
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci                  +-----------+
358c2ecf20Sopenharmony_ci           record |           |<-------------------- Inputs
368c2ecf20Sopenharmony_ci          <-------|           |        |
378c2ecf20Sopenharmony_ci     PCI          | Transport |        |
388c2ecf20Sopenharmony_ci     bus          |  engine   |       \|/
398c2ecf20Sopenharmony_ci          ------->|           |    +-------+
408c2ecf20Sopenharmony_ci            play  |           |--->|monitor|-------> Outputs
418c2ecf20Sopenharmony_ci                  +-----------+    | mixer |
428c2ecf20Sopenharmony_ci                                   +-------+
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci   The lines going to and from the PCI bus represent "pipes".  A pipe performs
458c2ecf20Sopenharmony_ci   audio transport - moving audio data to and from buffers on the host via
468c2ecf20Sopenharmony_ci   bus mastering.
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci   The inputs and outputs on the right represent input and output "busses."
498c2ecf20Sopenharmony_ci   A bus is a physical, real connection to the outside world.  An example
508c2ecf20Sopenharmony_ci   of a bus would be the 1/4" analog connectors on the back of Layla or
518c2ecf20Sopenharmony_ci   an RCA S/PDIF connector.
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci   For most cards, there is a one-to-one correspondence between outputs
548c2ecf20Sopenharmony_ci   and busses; that is, each individual pipe is hard-wired to a single bus.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci   Cards that work this way are Darla20, Gina20, Layla20, Darla24, Gina24,
578c2ecf20Sopenharmony_ci   Layla24, Mona, and Indigo.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci   Mia has a feature called "virtual outputs."
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci                  +-----------+
648c2ecf20Sopenharmony_ci           record |           |<----------------------------- Inputs
658c2ecf20Sopenharmony_ci          <-------|           |                  |
668c2ecf20Sopenharmony_ci     PCI          | Transport |                  |
678c2ecf20Sopenharmony_ci     bus          |  engine   |                 \|/
688c2ecf20Sopenharmony_ci          ------->|           |   +------+   +-------+
698c2ecf20Sopenharmony_ci            play  |           |-->|vmixer|-->|monitor|-------> Outputs
708c2ecf20Sopenharmony_ci                  +-----------+   +------+   | mixer |
718c2ecf20Sopenharmony_ci                                             +-------+
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci   Obviously, the difference here is the box labeled "vmixer."  Vmixer is
758c2ecf20Sopenharmony_ci   short for "virtual output mixer."  For Mia, pipes are *not* hard-wired
768c2ecf20Sopenharmony_ci   to a single bus; the vmixer lets you mix any pipe to any bus in any
778c2ecf20Sopenharmony_ci   combination.
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci   Note, however, that the left-hand side of the diagram is unchanged.
808c2ecf20Sopenharmony_ci   Transport works exactly the same way - the difference is in the mixer stage.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci   Pipes and busses are numbered starting at zero.
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci   Pipe index
888c2ecf20Sopenharmony_ci   ==========
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci   A number of calls in CEchoGals refer to a "pipe index".  A pipe index is
918c2ecf20Sopenharmony_ci   a unique number for a pipe that unambiguously refers to a playback or record
928c2ecf20Sopenharmony_ci   pipe.  Pipe indices are numbered starting with analog outputs, followed by
938c2ecf20Sopenharmony_ci   digital outputs, then analog inputs, then digital inputs.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci   Take Gina24 as an example:
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci   Pipe index
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci   0-7            Analog outputs (0 .. FirstDigitalBusOut-1)
1008c2ecf20Sopenharmony_ci   8-15           Digital outputs (FirstDigitalBusOut .. NumBussesOut-1)
1018c2ecf20Sopenharmony_ci   16-17          Analog inputs
1028c2ecf20Sopenharmony_ci   18-25          Digital inputs
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci   You get the pipe index by calling CEchoGals::OpenAudio; the other transport
1068c2ecf20Sopenharmony_ci   functions take the pipe index as a parameter.  If you need a pipe index for
1078c2ecf20Sopenharmony_ci   some other reason, use the handy Makepipe_index method.
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci   Some calls take a CChannelMask parameter; CChannelMask is a handy way to
1118c2ecf20Sopenharmony_ci   group pipe indices.
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci   Digital mode switch
1168c2ecf20Sopenharmony_ci   ===================
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci   Some cards (right now, Gina24, Layla24, and Mona) have a Digital Mode Switch
1198c2ecf20Sopenharmony_ci   or DMS.  Cards with a DMS can be set to one of three mutually exclusive
1208c2ecf20Sopenharmony_ci   digital modes: S/PDIF RCA, S/PDIF optical, or ADAT optical.
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci   This may create some confusion since ADAT optical is 8 channels wide and
1238c2ecf20Sopenharmony_ci   S/PDIF is only two channels wide.  Gina24, Layla24, and Mona handle this
1248c2ecf20Sopenharmony_ci   by acting as if they always have 8 digital outs and ins.  If you are in
1258c2ecf20Sopenharmony_ci   either S/PDIF mode, the last 6 channels don't do anything - data sent
1268c2ecf20Sopenharmony_ci   out these channels is thrown away and you will always record zeros.
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci   Note that with Gina24, Layla24, and Mona, sample rates above 50 kHz are
1298c2ecf20Sopenharmony_ci   only available if you have the card configured for S/PDIF optical or S/PDIF
1308c2ecf20Sopenharmony_ci   RCA.
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci   Double speed mode
1358c2ecf20Sopenharmony_ci   =================
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci   Some of the cards support 88.2 kHz and 96 kHz sampling (Darla24, Gina24,
1388c2ecf20Sopenharmony_ci   Layla24, Mona, Mia, and Indigo).  For these cards, the driver sometimes has
1398c2ecf20Sopenharmony_ci   to worry about "double speed mode"; double speed mode applies whenever the
1408c2ecf20Sopenharmony_ci   sampling rate is above 50 kHz.
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci   For instance, Mona and Layla24 support word clock sync.  However, they
1438c2ecf20Sopenharmony_ci   actually support two different word clock modes - single speed (below
1448c2ecf20Sopenharmony_ci   50 kHz) and double speed (above 50 kHz).  The hardware detects if a single
1458c2ecf20Sopenharmony_ci   or double speed word clock signal is present; the generic code uses that
1468c2ecf20Sopenharmony_ci   information to determine which mode to use.
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci   The generic code takes care of all this for you.
1498c2ecf20Sopenharmony_ci*/
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#ifndef _ECHOAUDIO_H_
1538c2ecf20Sopenharmony_ci#define _ECHOAUDIO_H_
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#include "echoaudio_dsp.h"
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/***********************************************************************
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	PCI configuration space
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci***********************************************************************/
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/*
1678c2ecf20Sopenharmony_ci * PCI vendor ID and device IDs for the hardware
1688c2ecf20Sopenharmony_ci */
1698c2ecf20Sopenharmony_ci#define VENDOR_ID		0x1057
1708c2ecf20Sopenharmony_ci#define DEVICE_ID_56301		0x1801
1718c2ecf20Sopenharmony_ci#define DEVICE_ID_56361		0x3410
1728c2ecf20Sopenharmony_ci#define SUBVENDOR_ID		0xECC0
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/*
1768c2ecf20Sopenharmony_ci * Valid Echo PCI subsystem card IDs
1778c2ecf20Sopenharmony_ci */
1788c2ecf20Sopenharmony_ci#define DARLA20			0x0010
1798c2ecf20Sopenharmony_ci#define GINA20			0x0020
1808c2ecf20Sopenharmony_ci#define LAYLA20			0x0030
1818c2ecf20Sopenharmony_ci#define DARLA24			0x0040
1828c2ecf20Sopenharmony_ci#define GINA24			0x0050
1838c2ecf20Sopenharmony_ci#define LAYLA24			0x0060
1848c2ecf20Sopenharmony_ci#define MONA			0x0070
1858c2ecf20Sopenharmony_ci#define MIA			0x0080
1868c2ecf20Sopenharmony_ci#define INDIGO			0x0090
1878c2ecf20Sopenharmony_ci#define INDIGO_IO		0x00a0
1888c2ecf20Sopenharmony_ci#define INDIGO_DJ		0x00b0
1898c2ecf20Sopenharmony_ci#define DC8			0x00c0
1908c2ecf20Sopenharmony_ci#define INDIGO_IOX		0x00d0
1918c2ecf20Sopenharmony_ci#define INDIGO_DJX		0x00e0
1928c2ecf20Sopenharmony_ci#define ECHO3G			0x0100
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/************************************************************************
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	Array sizes and so forth
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci***********************************************************************/
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/*
2028c2ecf20Sopenharmony_ci * Sizes
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_ci#define ECHO_MAXAUDIOINPUTS	32	/* Max audio input channels */
2058c2ecf20Sopenharmony_ci#define ECHO_MAXAUDIOOUTPUTS	32	/* Max audio output channels */
2068c2ecf20Sopenharmony_ci#define ECHO_MAXAUDIOPIPES	32	/* Max number of input and output
2078c2ecf20Sopenharmony_ci					 * pipes */
2088c2ecf20Sopenharmony_ci#define E3G_MAX_OUTPUTS		16
2098c2ecf20Sopenharmony_ci#define ECHO_MAXMIDIJACKS	1	/* Max MIDI ports */
2108c2ecf20Sopenharmony_ci#define ECHO_MIDI_QUEUE_SZ 	512	/* Max MIDI input queue entries */
2118c2ecf20Sopenharmony_ci#define ECHO_MTC_QUEUE_SZ	32	/* Max MIDI time code input queue
2128c2ecf20Sopenharmony_ci					 * entries */
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/*
2158c2ecf20Sopenharmony_ci * MIDI activity indicator timeout
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci#define MIDI_ACTIVITY_TIMEOUT_USEC	200000
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci/****************************************************************************
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci   Clocks
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci*****************************************************************************/
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/*
2278c2ecf20Sopenharmony_ci * Clock numbers
2288c2ecf20Sopenharmony_ci */
2298c2ecf20Sopenharmony_ci#define ECHO_CLOCK_INTERNAL		0
2308c2ecf20Sopenharmony_ci#define ECHO_CLOCK_WORD			1
2318c2ecf20Sopenharmony_ci#define ECHO_CLOCK_SUPER		2
2328c2ecf20Sopenharmony_ci#define ECHO_CLOCK_SPDIF		3
2338c2ecf20Sopenharmony_ci#define ECHO_CLOCK_ADAT			4
2348c2ecf20Sopenharmony_ci#define ECHO_CLOCK_ESYNC		5
2358c2ecf20Sopenharmony_ci#define ECHO_CLOCK_ESYNC96		6
2368c2ecf20Sopenharmony_ci#define ECHO_CLOCK_MTC			7
2378c2ecf20Sopenharmony_ci#define ECHO_CLOCK_NUMBER		8
2388c2ecf20Sopenharmony_ci#define ECHO_CLOCKS			0xffff
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/*
2418c2ecf20Sopenharmony_ci * Clock bit numbers - used to report capabilities and whatever clocks
2428c2ecf20Sopenharmony_ci * are being detected dynamically.
2438c2ecf20Sopenharmony_ci */
2448c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_INTERNAL		(1 << ECHO_CLOCK_INTERNAL)
2458c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_WORD		(1 << ECHO_CLOCK_WORD)
2468c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_SUPER		(1 << ECHO_CLOCK_SUPER)
2478c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_SPDIF		(1 << ECHO_CLOCK_SPDIF)
2488c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_ADAT		(1 << ECHO_CLOCK_ADAT)
2498c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_ESYNC		(1 << ECHO_CLOCK_ESYNC)
2508c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_ESYNC96		(1 << ECHO_CLOCK_ESYNC96)
2518c2ecf20Sopenharmony_ci#define ECHO_CLOCK_BIT_MTC		(1<<ECHO_CLOCK_MTC)
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/***************************************************************************
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci   Digital modes
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci****************************************************************************/
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci/*
2618c2ecf20Sopenharmony_ci * Digital modes for Mona, Layla24, and Gina24
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_ci#define DIGITAL_MODE_NONE			0xFF
2648c2ecf20Sopenharmony_ci#define DIGITAL_MODE_SPDIF_RCA			0
2658c2ecf20Sopenharmony_ci#define DIGITAL_MODE_SPDIF_OPTICAL		1
2668c2ecf20Sopenharmony_ci#define DIGITAL_MODE_ADAT			2
2678c2ecf20Sopenharmony_ci#define DIGITAL_MODE_SPDIF_CDROM		3
2688c2ecf20Sopenharmony_ci#define DIGITAL_MODES				4
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci/*
2718c2ecf20Sopenharmony_ci * Digital mode capability masks
2728c2ecf20Sopenharmony_ci */
2738c2ecf20Sopenharmony_ci#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA	(1 << DIGITAL_MODE_SPDIF_RCA)
2748c2ecf20Sopenharmony_ci#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL	(1 << DIGITAL_MODE_SPDIF_OPTICAL)
2758c2ecf20Sopenharmony_ci#define ECHOCAPS_HAS_DIGITAL_MODE_ADAT		(1 << DIGITAL_MODE_ADAT)
2768c2ecf20Sopenharmony_ci#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM	(1 << DIGITAL_MODE_SPDIF_CDROM)
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#define EXT_3GBOX_NC			0x01	/* 3G box not connected */
2808c2ecf20Sopenharmony_ci#define EXT_3GBOX_NOT_SET		0x02	/* 3G box not detected yet */
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci#define ECHOGAIN_MUTED		(-128)	/* Minimum possible gain */
2848c2ecf20Sopenharmony_ci#define ECHOGAIN_MINOUT		(-128)	/* Min output gain (dB) */
2858c2ecf20Sopenharmony_ci#define ECHOGAIN_MAXOUT		(6)	/* Max output gain (dB) */
2868c2ecf20Sopenharmony_ci#define ECHOGAIN_MININP		(-50)	/* Min input gain (0.5 dB) */
2878c2ecf20Sopenharmony_ci#define ECHOGAIN_MAXINP		(50)	/* Max input gain (0.5 dB) */
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci#define PIPE_STATE_STOPPED	0	/* Pipe has been reset */
2908c2ecf20Sopenharmony_ci#define PIPE_STATE_PAUSED	1	/* Pipe has been stopped */
2918c2ecf20Sopenharmony_ci#define PIPE_STATE_STARTED	2	/* Pipe has been started */
2928c2ecf20Sopenharmony_ci#define PIPE_STATE_PENDING	3	/* Pipe has pending start */
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistruct audiopipe {
2978c2ecf20Sopenharmony_ci	volatile __le32 *dma_counter;	/* Commpage register that contains
2988c2ecf20Sopenharmony_ci					 * the current dma position
2998c2ecf20Sopenharmony_ci					 * (lower 32 bits only)
3008c2ecf20Sopenharmony_ci					 */
3018c2ecf20Sopenharmony_ci	u32 last_period;                /* Counter position last time a
3028c2ecf20Sopenharmony_ci					 * period elapsed
3038c2ecf20Sopenharmony_ci					 */
3048c2ecf20Sopenharmony_ci	u32 last_counter;		/* Used exclusively by pcm_pointer
3058c2ecf20Sopenharmony_ci					 * under PCM core locks.
3068c2ecf20Sopenharmony_ci					 * The last position, which is used
3078c2ecf20Sopenharmony_ci					 * to compute...
3088c2ecf20Sopenharmony_ci					 */
3098c2ecf20Sopenharmony_ci	u32 position;			/* ...the number of bytes tranferred
3108c2ecf20Sopenharmony_ci					 * by the DMA engine, modulo the
3118c2ecf20Sopenharmony_ci					 * buffer size
3128c2ecf20Sopenharmony_ci					 */
3138c2ecf20Sopenharmony_ci	short index;			/* Index of the first channel or <0
3148c2ecf20Sopenharmony_ci					 * if hw is not configured yet
3158c2ecf20Sopenharmony_ci					 */
3168c2ecf20Sopenharmony_ci	short interleave;
3178c2ecf20Sopenharmony_ci	struct snd_dma_buffer sgpage;	/* Room for the scatter-gather list */
3188c2ecf20Sopenharmony_ci	struct snd_pcm_hardware hw;
3198c2ecf20Sopenharmony_ci	struct snd_pcm_hw_constraint_list constr;
3208c2ecf20Sopenharmony_ci	short sglist_head;
3218c2ecf20Sopenharmony_ci	char state;			/* pipe state */
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistruct audioformat {
3268c2ecf20Sopenharmony_ci	u8 interleave;			/* How the data is arranged in memory:
3278c2ecf20Sopenharmony_ci					 * mono = 1, stereo = 2, ...
3288c2ecf20Sopenharmony_ci					 */
3298c2ecf20Sopenharmony_ci	u8 bits_per_sample;		/* 8, 16, 24, 32 (24 bits left aligned) */
3308c2ecf20Sopenharmony_ci	char mono_to_stereo;		/* Only used if interleave is 1 and
3318c2ecf20Sopenharmony_ci					 * if this is an output pipe.
3328c2ecf20Sopenharmony_ci					 */
3338c2ecf20Sopenharmony_ci	char data_are_bigendian;	/* 1 = big endian, 0 = little endian */
3348c2ecf20Sopenharmony_ci};
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistruct echoaudio {
3388c2ecf20Sopenharmony_ci	spinlock_t lock;
3398c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream[DSP_MAXPIPES];
3408c2ecf20Sopenharmony_ci	struct mutex mode_mutex;
3418c2ecf20Sopenharmony_ci	u16 num_digital_modes, digital_mode_list[6];
3428c2ecf20Sopenharmony_ci	u16 num_clock_sources, clock_source_list[10];
3438c2ecf20Sopenharmony_ci	unsigned int opencount;  /* protected by mode_mutex */
3448c2ecf20Sopenharmony_ci	struct snd_kcontrol *clock_src_ctl;
3458c2ecf20Sopenharmony_ci	struct snd_pcm *analog_pcm, *digital_pcm;
3468c2ecf20Sopenharmony_ci	struct snd_card *card;
3478c2ecf20Sopenharmony_ci	const char *card_name;
3488c2ecf20Sopenharmony_ci	struct pci_dev *pci;
3498c2ecf20Sopenharmony_ci	unsigned long dsp_registers_phys;
3508c2ecf20Sopenharmony_ci	struct resource *iores;
3518c2ecf20Sopenharmony_ci	struct snd_dma_buffer commpage_dma_buf;
3528c2ecf20Sopenharmony_ci	int irq;
3538c2ecf20Sopenharmony_ci#ifdef ECHOCARD_HAS_MIDI
3548c2ecf20Sopenharmony_ci	struct snd_rawmidi *rmidi;
3558c2ecf20Sopenharmony_ci	struct snd_rawmidi_substream *midi_in, *midi_out;
3568c2ecf20Sopenharmony_ci#endif
3578c2ecf20Sopenharmony_ci	struct timer_list timer;
3588c2ecf20Sopenharmony_ci	char tinuse;				/* Timer in use */
3598c2ecf20Sopenharmony_ci	char midi_full;				/* MIDI output buffer is full */
3608c2ecf20Sopenharmony_ci	char can_set_rate;                      /* protected by mode_mutex */
3618c2ecf20Sopenharmony_ci	char rate_set;                          /* protected by mode_mutex */
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	/* This stuff is used mainly by the lowlevel code */
3648c2ecf20Sopenharmony_ci	struct comm_page *comm_page;	/* Virtual address of the memory
3658c2ecf20Sopenharmony_ci					 * seen by DSP
3668c2ecf20Sopenharmony_ci					 */
3678c2ecf20Sopenharmony_ci	u32 pipe_alloc_mask;		/* Bitmask of allocated pipes */
3688c2ecf20Sopenharmony_ci	u32 pipe_cyclic_mask;		/* Bitmask of pipes with cyclic
3698c2ecf20Sopenharmony_ci					 * buffers
3708c2ecf20Sopenharmony_ci					 */
3718c2ecf20Sopenharmony_ci	u32 sample_rate;		/* Card sample rate in Hz */
3728c2ecf20Sopenharmony_ci	u8 digital_mode;		/* Current digital mode
3738c2ecf20Sopenharmony_ci					 * (see DIGITAL_MODE_*)
3748c2ecf20Sopenharmony_ci					 */
3758c2ecf20Sopenharmony_ci	u8 spdif_status;		/* Gina20, Darla20, Darla24 - only */
3768c2ecf20Sopenharmony_ci	u8 clock_state;			/* Gina20, Darla20, Darla24 - only */
3778c2ecf20Sopenharmony_ci	u8 input_clock;			/* Currently selected sample clock
3788c2ecf20Sopenharmony_ci					 * source
3798c2ecf20Sopenharmony_ci					 */
3808c2ecf20Sopenharmony_ci	u8 output_clock;		/* Layla20 only */
3818c2ecf20Sopenharmony_ci	char meters_enabled;		/* VU-meters status */
3828c2ecf20Sopenharmony_ci	char asic_loaded;		/* Set true when ASIC loaded */
3838c2ecf20Sopenharmony_ci	char bad_board;			/* Set true if DSP won't load */
3848c2ecf20Sopenharmony_ci	char professional_spdif;	/* 0 = consumer; 1 = professional */
3858c2ecf20Sopenharmony_ci	char non_audio_spdif;		/* 3G - only */
3868c2ecf20Sopenharmony_ci	char digital_in_automute;	/* Gina24, Layla24, Mona - only */
3878c2ecf20Sopenharmony_ci	char has_phantom_power;
3888c2ecf20Sopenharmony_ci	char hasnt_input_nominal_level;	/* Gina3G */
3898c2ecf20Sopenharmony_ci	char phantom_power;		/* Gina3G - only */
3908c2ecf20Sopenharmony_ci	char has_midi;
3918c2ecf20Sopenharmony_ci	char midi_input_enabled;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci#ifdef ECHOCARD_ECHO3G
3948c2ecf20Sopenharmony_ci	/* External module -dependent pipe and bus indexes */
3958c2ecf20Sopenharmony_ci	char px_digital_out, px_analog_in, px_digital_in, px_num;
3968c2ecf20Sopenharmony_ci	char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;
3978c2ecf20Sopenharmony_ci#endif
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	char nominal_level[ECHO_MAXAUDIOPIPES];	/* True == -10dBV
4008c2ecf20Sopenharmony_ci						 * False == +4dBu */
4018c2ecf20Sopenharmony_ci	s8 input_gain[ECHO_MAXAUDIOINPUTS];	/* Input level -50..+50
4028c2ecf20Sopenharmony_ci						 * unit is 0.5dB */
4038c2ecf20Sopenharmony_ci	s8 output_gain[ECHO_MAXAUDIOOUTPUTS];	/* Output level -128..+6 dB
4048c2ecf20Sopenharmony_ci						 * (-128=muted) */
4058c2ecf20Sopenharmony_ci	s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];
4068c2ecf20Sopenharmony_ci		/* -128..+6 dB */
4078c2ecf20Sopenharmony_ci	s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
4088c2ecf20Sopenharmony_ci		/* -128..+6 dB */
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	u16 digital_modes;		/* Bitmask of supported modes
4118c2ecf20Sopenharmony_ci					 * (see ECHOCAPS_HAS_DIGITAL_MODE_*) */
4128c2ecf20Sopenharmony_ci	u16 input_clock_types;		/* Suppoted input clock types */
4138c2ecf20Sopenharmony_ci	u16 output_clock_types;		/* Suppoted output clock types -
4148c2ecf20Sopenharmony_ci					 * Layla20 only */
4158c2ecf20Sopenharmony_ci	u16 device_id, subdevice_id;
4168c2ecf20Sopenharmony_ci	u16 *dsp_code;			/* Current DSP code loaded,
4178c2ecf20Sopenharmony_ci					 * NULL if nothing loaded */
4188c2ecf20Sopenharmony_ci	short dsp_code_to_load;		/* DSP code to load */
4198c2ecf20Sopenharmony_ci	short asic_code;		/* Current ASIC code */
4208c2ecf20Sopenharmony_ci	u32 comm_page_phys;			/* Physical address of the
4218c2ecf20Sopenharmony_ci						 * memory seen by DSP */
4228c2ecf20Sopenharmony_ci	u32 __iomem *dsp_registers;		/* DSP's register base */
4238c2ecf20Sopenharmony_ci	u32 active_mask;			/* Chs. active mask or
4248c2ecf20Sopenharmony_ci						 * punks out */
4258c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
4268c2ecf20Sopenharmony_ci	const struct firmware *fw_cache[8];	/* Cached firmwares */
4278c2ecf20Sopenharmony_ci#endif
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci#ifdef ECHOCARD_HAS_MIDI
4308c2ecf20Sopenharmony_ci	u16 mtc_state;				/* State for MIDI input parsing state machine */
4318c2ecf20Sopenharmony_ci	u8 midi_buffer[MIDI_IN_BUFFER_SIZE];
4328c2ecf20Sopenharmony_ci#endif
4338c2ecf20Sopenharmony_ci};
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cistatic int init_dsp_comm_page(struct echoaudio *chip);
4378c2ecf20Sopenharmony_cistatic int init_line_levels(struct echoaudio *chip);
4388c2ecf20Sopenharmony_cistatic int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);
4398c2ecf20Sopenharmony_cistatic int load_firmware(struct echoaudio *chip);
4408c2ecf20Sopenharmony_cistatic int wait_handshake(struct echoaudio *chip);
4418c2ecf20Sopenharmony_cistatic int send_vector(struct echoaudio *chip, u32 command);
4428c2ecf20Sopenharmony_cistatic int get_firmware(const struct firmware **fw_entry,
4438c2ecf20Sopenharmony_ci			struct echoaudio *chip, const short fw_index);
4448c2ecf20Sopenharmony_cistatic void free_firmware(const struct firmware *fw_entry,
4458c2ecf20Sopenharmony_ci			  struct echoaudio *chip);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci#ifdef ECHOCARD_HAS_MIDI
4488c2ecf20Sopenharmony_cistatic int enable_midi_input(struct echoaudio *chip, char enable);
4498c2ecf20Sopenharmony_cistatic void snd_echo_midi_output_trigger(
4508c2ecf20Sopenharmony_ci			struct snd_rawmidi_substream *substream, int up);
4518c2ecf20Sopenharmony_cistatic int midi_service_irq(struct echoaudio *chip);
4528c2ecf20Sopenharmony_cistatic int snd_echo_midi_create(struct snd_card *card,
4538c2ecf20Sopenharmony_ci				struct echoaudio *chip);
4548c2ecf20Sopenharmony_ci#endif
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistatic inline void clear_handshake(struct echoaudio *chip)
4588c2ecf20Sopenharmony_ci{
4598c2ecf20Sopenharmony_ci	chip->comm_page->handshake = 0;
4608c2ecf20Sopenharmony_ci}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_cistatic inline u32 get_dsp_register(struct echoaudio *chip, u32 index)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	return readl(&chip->dsp_registers[index]);
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic inline void set_dsp_register(struct echoaudio *chip, u32 index,
4688c2ecf20Sopenharmony_ci				    u32 value)
4698c2ecf20Sopenharmony_ci{
4708c2ecf20Sopenharmony_ci	writel(value, &chip->dsp_registers[index]);
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci/* Pipe and bus indexes. PX_* and BX_* are defined as chip->px_* and chip->bx_*
4758c2ecf20Sopenharmony_cifor 3G cards because they depend on the external box. They are integer
4768c2ecf20Sopenharmony_ciconstants for all other cards.
4778c2ecf20Sopenharmony_ciNever use those defines directly, use the following functions instead. */
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cistatic inline int px_digital_out(const struct echoaudio *chip)
4808c2ecf20Sopenharmony_ci{
4818c2ecf20Sopenharmony_ci	return PX_DIGITAL_OUT;
4828c2ecf20Sopenharmony_ci}
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_cistatic inline int px_analog_in(const struct echoaudio *chip)
4858c2ecf20Sopenharmony_ci{
4868c2ecf20Sopenharmony_ci	return PX_ANALOG_IN;
4878c2ecf20Sopenharmony_ci}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_cistatic inline int px_digital_in(const struct echoaudio *chip)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	return PX_DIGITAL_IN;
4928c2ecf20Sopenharmony_ci}
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_cistatic inline int px_num(const struct echoaudio *chip)
4958c2ecf20Sopenharmony_ci{
4968c2ecf20Sopenharmony_ci	return PX_NUM;
4978c2ecf20Sopenharmony_ci}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistatic inline int bx_digital_out(const struct echoaudio *chip)
5008c2ecf20Sopenharmony_ci{
5018c2ecf20Sopenharmony_ci	return BX_DIGITAL_OUT;
5028c2ecf20Sopenharmony_ci}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cistatic inline int bx_analog_in(const struct echoaudio *chip)
5058c2ecf20Sopenharmony_ci{
5068c2ecf20Sopenharmony_ci	return BX_ANALOG_IN;
5078c2ecf20Sopenharmony_ci}
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_cistatic inline int bx_digital_in(const struct echoaudio *chip)
5108c2ecf20Sopenharmony_ci{
5118c2ecf20Sopenharmony_ci	return BX_DIGITAL_IN;
5128c2ecf20Sopenharmony_ci}
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cistatic inline int bx_num(const struct echoaudio *chip)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	return BX_NUM;
5178c2ecf20Sopenharmony_ci}
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_cistatic inline int num_pipes_out(const struct echoaudio *chip)
5208c2ecf20Sopenharmony_ci{
5218c2ecf20Sopenharmony_ci	return px_analog_in(chip);
5228c2ecf20Sopenharmony_ci}
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistatic inline int num_pipes_in(const struct echoaudio *chip)
5258c2ecf20Sopenharmony_ci{
5268c2ecf20Sopenharmony_ci	return px_num(chip) - px_analog_in(chip);
5278c2ecf20Sopenharmony_ci}
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_cistatic inline int num_busses_out(const struct echoaudio *chip)
5308c2ecf20Sopenharmony_ci{
5318c2ecf20Sopenharmony_ci	return bx_analog_in(chip);
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cistatic inline int num_busses_in(const struct echoaudio *chip)
5358c2ecf20Sopenharmony_ci{
5368c2ecf20Sopenharmony_ci	return bx_num(chip) - bx_analog_in(chip);
5378c2ecf20Sopenharmony_ci}
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cistatic inline int num_analog_busses_out(const struct echoaudio *chip)
5408c2ecf20Sopenharmony_ci{
5418c2ecf20Sopenharmony_ci	return bx_digital_out(chip);
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic inline int num_analog_busses_in(const struct echoaudio *chip)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	return bx_digital_in(chip) - bx_analog_in(chip);
5478c2ecf20Sopenharmony_ci}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic inline int num_digital_busses_out(const struct echoaudio *chip)
5508c2ecf20Sopenharmony_ci{
5518c2ecf20Sopenharmony_ci	return num_busses_out(chip) - num_analog_busses_out(chip);
5528c2ecf20Sopenharmony_ci}
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_cistatic inline int num_digital_busses_in(const struct echoaudio *chip)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	return num_busses_in(chip) - num_analog_busses_in(chip);
5578c2ecf20Sopenharmony_ci}
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci/* The monitor array is a one-dimensional array; compute the offset
5608c2ecf20Sopenharmony_ci * into the array */
5618c2ecf20Sopenharmony_cistatic inline int monitor_index(const struct echoaudio *chip, int out, int in)
5628c2ecf20Sopenharmony_ci{
5638c2ecf20Sopenharmony_ci	return out * num_busses_in(chip) + in;
5648c2ecf20Sopenharmony_ci}
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci#endif /* _ECHOAUDIO_H_ */
567