565 lines · c
1/****************************************************************************2 3 Copyright Echo Digital Audio Corporation (c) 1998 - 20044 All rights reserved5 www.echoaudio.com6 7 This file is part of Echo Digital Audio's generic driver library.8 9 Echo Digital Audio's generic driver library is free software;10 you can redistribute it and/or modify it under the terms of11 the GNU General Public License as published by the Free Software12 Foundation.13 14 This program is distributed in the hope that it will be useful,15 but WITHOUT ANY WARRANTY; without even the implied warranty of16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 GNU General Public License for more details.18 19 You should have received a copy of the GNU General Public License20 along with this program; if not, write to the Free Software21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,22 MA 02111-1307, USA.23 24 ****************************************************************************25 26 Translation from C++ and adaptation for use in ALSA-Driver27 were made by Giuliano Pochini <pochini@shiny.it>28 29 ****************************************************************************30 31 32 Here's a block diagram of how most of the cards work:33 34 +-----------+35 record | |<-------------------- Inputs36 <-------| | |37 PCI | Transport | |38 bus | engine | \|/39 ------->| | +-------+40 play | |--->|monitor|-------> Outputs41 +-----------+ | mixer |42 +-------+43 44 The lines going to and from the PCI bus represent "pipes". A pipe performs45 audio transport - moving audio data to and from buffers on the host via46 bus mastering.47 48 The inputs and outputs on the right represent input and output "busses."49 A bus is a physical, real connection to the outside world. An example50 of a bus would be the 1/4" analog connectors on the back of Layla or51 an RCA S/PDIF connector.52 53 For most cards, there is a one-to-one correspondence between outputs54 and busses; that is, each individual pipe is hard-wired to a single bus.55 56 Cards that work this way are Darla20, Gina20, Layla20, Darla24, Gina24,57 Layla24, Mona, and Indigo.58 59 60 Mia has a feature called "virtual outputs."61 62 63 +-----------+64 record | |<----------------------------- Inputs65 <-------| | |66 PCI | Transport | |67 bus | engine | \|/68 ------->| | +------+ +-------+69 play | |-->|vmixer|-->|monitor|-------> Outputs70 +-----------+ +------+ | mixer |71 +-------+72 73 74 Obviously, the difference here is the box labeled "vmixer." Vmixer is75 short for "virtual output mixer." For Mia, pipes are *not* hard-wired76 to a single bus; the vmixer lets you mix any pipe to any bus in any77 combination.78 79 Note, however, that the left-hand side of the diagram is unchanged.80 Transport works exactly the same way - the difference is in the mixer stage.81 82 83 Pipes and busses are numbered starting at zero.84 85 86 87 Pipe index88 ==========89 90 A number of calls in CEchoGals refer to a "pipe index". A pipe index is91 a unique number for a pipe that unambiguously refers to a playback or record92 pipe. Pipe indices are numbered starting with analog outputs, followed by93 digital outputs, then analog inputs, then digital inputs.94 95 Take Gina24 as an example:96 97 Pipe index98 99 0-7 Analog outputs (0 .. FirstDigitalBusOut-1)100 8-15 Digital outputs (FirstDigitalBusOut .. NumBussesOut-1)101 16-17 Analog inputs102 18-25 Digital inputs103 104 105 You get the pipe index by calling CEchoGals::OpenAudio; the other transport106 functions take the pipe index as a parameter. If you need a pipe index for107 some other reason, use the handy Makepipe_index method.108 109 110 Some calls take a CChannelMask parameter; CChannelMask is a handy way to111 group pipe indices.112 113 114 115 Digital mode switch116 ===================117 118 Some cards (right now, Gina24, Layla24, and Mona) have a Digital Mode Switch119 or DMS. Cards with a DMS can be set to one of three mutually exclusive120 digital modes: S/PDIF RCA, S/PDIF optical, or ADAT optical.121 122 This may create some confusion since ADAT optical is 8 channels wide and123 S/PDIF is only two channels wide. Gina24, Layla24, and Mona handle this124 by acting as if they always have 8 digital outs and ins. If you are in125 either S/PDIF mode, the last 6 channels don't do anything - data sent126 out these channels is thrown away and you will always record zeros.127 128 Note that with Gina24, Layla24, and Mona, sample rates above 50 kHz are129 only available if you have the card configured for S/PDIF optical or S/PDIF130 RCA.131 132 133 134 Double speed mode135 =================136 137 Some of the cards support 88.2 kHz and 96 kHz sampling (Darla24, Gina24,138 Layla24, Mona, Mia, and Indigo). For these cards, the driver sometimes has139 to worry about "double speed mode"; double speed mode applies whenever the140 sampling rate is above 50 kHz.141 142 For instance, Mona and Layla24 support word clock sync. However, they143 actually support two different word clock modes - single speed (below144 50 kHz) and double speed (above 50 kHz). The hardware detects if a single145 or double speed word clock signal is present; the generic code uses that146 information to determine which mode to use.147 148 The generic code takes care of all this for you.149*/150 151 152#ifndef _ECHOAUDIO_H_153#define _ECHOAUDIO_H_154 155 156#include "echoaudio_dsp.h"157 158 159 160/***********************************************************************161 162 PCI configuration space163 164***********************************************************************/165 166/*167 * PCI vendor ID and device IDs for the hardware168 */169#define VENDOR_ID 0x1057170#define DEVICE_ID_56301 0x1801171#define DEVICE_ID_56361 0x3410172#define SUBVENDOR_ID 0xECC0173 174 175/*176 * Valid Echo PCI subsystem card IDs177 */178#define DARLA20 0x0010179#define GINA20 0x0020180#define LAYLA20 0x0030181#define DARLA24 0x0040182#define GINA24 0x0050183#define LAYLA24 0x0060184#define MONA 0x0070185#define MIA 0x0080186#define INDIGO 0x0090187#define INDIGO_IO 0x00a0188#define INDIGO_DJ 0x00b0189#define DC8 0x00c0190#define INDIGO_IOX 0x00d0191#define INDIGO_DJX 0x00e0192#define ECHO3G 0x0100193 194 195/************************************************************************196 197 Array sizes and so forth198 199***********************************************************************/200 201/*202 * Sizes203 */204#define ECHO_MAXAUDIOINPUTS 32 /* Max audio input channels */205#define ECHO_MAXAUDIOOUTPUTS 32 /* Max audio output channels */206#define ECHO_MAXAUDIOPIPES 32 /* Max number of input and output207 * pipes */208#define E3G_MAX_OUTPUTS 16209#define ECHO_MAXMIDIJACKS 1 /* Max MIDI ports */210#define ECHO_MIDI_QUEUE_SZ 512 /* Max MIDI input queue entries */211#define ECHO_MTC_QUEUE_SZ 32 /* Max MIDI time code input queue212 * entries */213 214/*215 * MIDI activity indicator timeout216 */217#define MIDI_ACTIVITY_TIMEOUT_USEC 200000218 219 220/****************************************************************************221 222 Clocks223 224*****************************************************************************/225 226/*227 * Clock numbers228 */229#define ECHO_CLOCK_INTERNAL 0230#define ECHO_CLOCK_WORD 1231#define ECHO_CLOCK_SUPER 2232#define ECHO_CLOCK_SPDIF 3233#define ECHO_CLOCK_ADAT 4234#define ECHO_CLOCK_ESYNC 5235#define ECHO_CLOCK_ESYNC96 6236#define ECHO_CLOCK_MTC 7237#define ECHO_CLOCK_NUMBER 8238#define ECHO_CLOCKS 0xffff239 240/*241 * Clock bit numbers - used to report capabilities and whatever clocks242 * are being detected dynamically.243 */244#define ECHO_CLOCK_BIT_INTERNAL (1 << ECHO_CLOCK_INTERNAL)245#define ECHO_CLOCK_BIT_WORD (1 << ECHO_CLOCK_WORD)246#define ECHO_CLOCK_BIT_SUPER (1 << ECHO_CLOCK_SUPER)247#define ECHO_CLOCK_BIT_SPDIF (1 << ECHO_CLOCK_SPDIF)248#define ECHO_CLOCK_BIT_ADAT (1 << ECHO_CLOCK_ADAT)249#define ECHO_CLOCK_BIT_ESYNC (1 << ECHO_CLOCK_ESYNC)250#define ECHO_CLOCK_BIT_ESYNC96 (1 << ECHO_CLOCK_ESYNC96)251#define ECHO_CLOCK_BIT_MTC (1<<ECHO_CLOCK_MTC)252 253 254/***************************************************************************255 256 Digital modes257 258****************************************************************************/259 260/*261 * Digital modes for Mona, Layla24, and Gina24262 */263#define DIGITAL_MODE_NONE 0xFF264#define DIGITAL_MODE_SPDIF_RCA 0265#define DIGITAL_MODE_SPDIF_OPTICAL 1266#define DIGITAL_MODE_ADAT 2267#define DIGITAL_MODE_SPDIF_CDROM 3268#define DIGITAL_MODES 4269 270/*271 * Digital mode capability masks272 */273#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA (1 << DIGITAL_MODE_SPDIF_RCA)274#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL (1 << DIGITAL_MODE_SPDIF_OPTICAL)275#define ECHOCAPS_HAS_DIGITAL_MODE_ADAT (1 << DIGITAL_MODE_ADAT)276#define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM (1 << DIGITAL_MODE_SPDIF_CDROM)277 278 279#define EXT_3GBOX_NC 0x01 /* 3G box not connected */280#define EXT_3GBOX_NOT_SET 0x02 /* 3G box not detected yet */281 282 283#define ECHOGAIN_MUTED (-128) /* Minimum possible gain */284#define ECHOGAIN_MINOUT (-128) /* Min output gain (dB) */285#define ECHOGAIN_MAXOUT (6) /* Max output gain (dB) */286#define ECHOGAIN_MININP (-50) /* Min input gain (0.5 dB) */287#define ECHOGAIN_MAXINP (50) /* Max input gain (0.5 dB) */288 289#define PIPE_STATE_STOPPED 0 /* Pipe has been reset */290#define PIPE_STATE_PAUSED 1 /* Pipe has been stopped */291#define PIPE_STATE_STARTED 2 /* Pipe has been started */292#define PIPE_STATE_PENDING 3 /* Pipe has pending start */293 294 295 296struct audiopipe {297 volatile __le32 *dma_counter; /* Commpage register that contains298 * the current dma position299 * (lower 32 bits only)300 */301 u32 last_period; /* Counter position last time a302 * period elapsed303 */304 u32 last_counter; /* Used exclusively by pcm_pointer305 * under PCM core locks.306 * The last position, which is used307 * to compute...308 */309 u32 position; /* ...the number of bytes tranferred310 * by the DMA engine, modulo the311 * buffer size312 */313 short index; /* Index of the first channel or <0314 * if hw is not configured yet315 */316 short interleave;317 struct snd_dma_buffer sgpage; /* Room for the scatter-gather list */318 struct snd_pcm_hardware hw;319 struct snd_pcm_hw_constraint_list constr;320 short sglist_head;321 char state; /* pipe state */322};323 324 325struct audioformat {326 u8 interleave; /* How the data is arranged in memory:327 * mono = 1, stereo = 2, ...328 */329 u8 bits_per_sample; /* 8, 16, 24, 32 (24 bits left aligned) */330 char mono_to_stereo; /* Only used if interleave is 1 and331 * if this is an output pipe.332 */333 char data_are_bigendian; /* 1 = big endian, 0 = little endian */334};335 336 337struct echoaudio {338 spinlock_t lock;339 struct snd_pcm_substream *substream[DSP_MAXPIPES];340 struct mutex mode_mutex;341 u16 num_digital_modes, digital_mode_list[6];342 u16 num_clock_sources, clock_source_list[10];343 unsigned int opencount; /* protected by mode_mutex */344 struct snd_kcontrol *clock_src_ctl;345 struct snd_pcm *analog_pcm, *digital_pcm;346 struct snd_card *card;347 const char *card_name;348 struct pci_dev *pci;349 unsigned long dsp_registers_phys;350 struct resource *iores;351 struct snd_dma_buffer *commpage_dma_buf;352 int irq;353#ifdef ECHOCARD_HAS_MIDI354 struct snd_rawmidi *rmidi;355 struct snd_rawmidi_substream *midi_in, *midi_out;356#endif357 struct timer_list timer;358 char tinuse; /* Timer in use */359 char midi_full; /* MIDI output buffer is full */360 char can_set_rate; /* protected by mode_mutex */361 char rate_set; /* protected by mode_mutex */362 363 /* This stuff is used mainly by the lowlevel code */364 struct comm_page *comm_page; /* Virtual address of the memory365 * seen by DSP366 */367 u32 pipe_alloc_mask; /* Bitmask of allocated pipes */368 u32 pipe_cyclic_mask; /* Bitmask of pipes with cyclic369 * buffers370 */371 u32 sample_rate; /* Card sample rate in Hz */372 u8 digital_mode; /* Current digital mode373 * (see DIGITAL_MODE_*)374 */375 u8 spdif_status; /* Gina20, Darla20, Darla24 - only */376 u8 clock_state; /* Gina20, Darla20, Darla24 - only */377 u8 input_clock; /* Currently selected sample clock378 * source379 */380 u8 output_clock; /* Layla20 only */381 char meters_enabled; /* VU-meters status */382 char asic_loaded; /* Set true when ASIC loaded */383 char bad_board; /* Set true if DSP won't load */384 char professional_spdif; /* 0 = consumer; 1 = professional */385 char non_audio_spdif; /* 3G - only */386 char digital_in_automute; /* Gina24, Layla24, Mona - only */387 char has_phantom_power;388 char hasnt_input_nominal_level; /* Gina3G */389 char phantom_power; /* Gina3G - only */390 char has_midi;391 char midi_input_enabled;392 393#ifdef ECHOCARD_ECHO3G394 /* External module -dependent pipe and bus indexes */395 char px_digital_out, px_analog_in, px_digital_in, px_num;396 char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;397#endif398 399 char nominal_level[ECHO_MAXAUDIOPIPES]; /* True == -10dBV400 * False == +4dBu */401 s8 input_gain[ECHO_MAXAUDIOINPUTS]; /* Input level -50..+50402 * unit is 0.5dB */403 s8 output_gain[ECHO_MAXAUDIOOUTPUTS]; /* Output level -128..+6 dB404 * (-128=muted) */405 s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];406 /* -128..+6 dB */407 s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];408 /* -128..+6 dB */409 410 u16 digital_modes; /* Bitmask of supported modes411 * (see ECHOCAPS_HAS_DIGITAL_MODE_*) */412 u16 input_clock_types; /* Suppoted input clock types */413 u16 output_clock_types; /* Suppoted output clock types -414 * Layla20 only */415 u16 device_id, subdevice_id;416 u16 *dsp_code; /* Current DSP code loaded,417 * NULL if nothing loaded */418 short dsp_code_to_load; /* DSP code to load */419 short asic_code; /* Current ASIC code */420 u32 comm_page_phys; /* Physical address of the421 * memory seen by DSP */422 u32 __iomem *dsp_registers; /* DSP's register base */423 u32 active_mask; /* Chs. active mask or424 * punks out */425 const struct firmware *fw_cache[8]; /* Cached firmwares */426 427#ifdef ECHOCARD_HAS_MIDI428 u16 mtc_state; /* State for MIDI input parsing state machine */429 u8 midi_buffer[MIDI_IN_BUFFER_SIZE];430#endif431};432 433 434static int init_dsp_comm_page(struct echoaudio *chip);435static int init_line_levels(struct echoaudio *chip);436static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);437static int load_firmware(struct echoaudio *chip);438static int wait_handshake(struct echoaudio *chip);439static int send_vector(struct echoaudio *chip, u32 command);440static int get_firmware(const struct firmware **fw_entry,441 struct echoaudio *chip, const short fw_index);442static void free_firmware(const struct firmware *fw_entry,443 struct echoaudio *chip);444 445#ifdef ECHOCARD_HAS_MIDI446static int enable_midi_input(struct echoaudio *chip, char enable);447static void snd_echo_midi_output_trigger(448 struct snd_rawmidi_substream *substream, int up);449static int midi_service_irq(struct echoaudio *chip);450static int snd_echo_midi_create(struct snd_card *card,451 struct echoaudio *chip);452#endif453 454 455static inline void clear_handshake(struct echoaudio *chip)456{457 chip->comm_page->handshake = 0;458}459 460static inline u32 get_dsp_register(struct echoaudio *chip, u32 index)461{462 return readl(&chip->dsp_registers[index]);463}464 465static inline void set_dsp_register(struct echoaudio *chip, u32 index,466 u32 value)467{468 writel(value, &chip->dsp_registers[index]);469}470 471 472/* Pipe and bus indexes. PX_* and BX_* are defined as chip->px_* and chip->bx_*473for 3G cards because they depend on the external box. They are integer474constants for all other cards.475Never use those defines directly, use the following functions instead. */476 477static inline int px_digital_out(const struct echoaudio *chip)478{479 return PX_DIGITAL_OUT;480}481 482static inline int px_analog_in(const struct echoaudio *chip)483{484 return PX_ANALOG_IN;485}486 487static inline int px_digital_in(const struct echoaudio *chip)488{489 return PX_DIGITAL_IN;490}491 492static inline int px_num(const struct echoaudio *chip)493{494 return PX_NUM;495}496 497static inline int bx_digital_out(const struct echoaudio *chip)498{499 return BX_DIGITAL_OUT;500}501 502static inline int bx_analog_in(const struct echoaudio *chip)503{504 return BX_ANALOG_IN;505}506 507static inline int bx_digital_in(const struct echoaudio *chip)508{509 return BX_DIGITAL_IN;510}511 512static inline int bx_num(const struct echoaudio *chip)513{514 return BX_NUM;515}516 517static inline int num_pipes_out(const struct echoaudio *chip)518{519 return px_analog_in(chip);520}521 522static inline int num_pipes_in(const struct echoaudio *chip)523{524 return px_num(chip) - px_analog_in(chip);525}526 527static inline int num_busses_out(const struct echoaudio *chip)528{529 return bx_analog_in(chip);530}531 532static inline int num_busses_in(const struct echoaudio *chip)533{534 return bx_num(chip) - bx_analog_in(chip);535}536 537static inline int num_analog_busses_out(const struct echoaudio *chip)538{539 return bx_digital_out(chip);540}541 542static inline int num_analog_busses_in(const struct echoaudio *chip)543{544 return bx_digital_in(chip) - bx_analog_in(chip);545}546 547static inline int num_digital_busses_out(const struct echoaudio *chip)548{549 return num_busses_out(chip) - num_analog_busses_out(chip);550}551 552static inline int num_digital_busses_in(const struct echoaudio *chip)553{554 return num_busses_in(chip) - num_analog_busses_in(chip);555}556 557/* The monitor array is a one-dimensional array; compute the offset558 * into the array */559static inline int monitor_index(const struct echoaudio *chip, int out, int in)560{561 return out * num_busses_in(chip) + in;562}563 564#endif /* _ECHOAUDIO_H_ */565