Back to home page

OSCL-LXR

 
 

    


0001 /****************************************************************************
0002 
0003    Copyright Echo Digital Audio Corporation (c) 1998 - 2004
0004    All rights reserved
0005    www.echoaudio.com
0006 
0007    This file is part of Echo Digital Audio's generic driver library.
0008 
0009    Echo Digital Audio's generic driver library is free software;
0010    you can redistribute it and/or modify it under the terms of
0011    the GNU General Public License as published by the Free Software
0012    Foundation.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program; if not, write to the Free Software
0021    Foundation, Inc., 59 Temple Place - Suite 330, Boston,
0022    MA  02111-1307, USA.
0023 
0024  ****************************************************************************
0025 
0026  Translation from C++ and adaptation for use in ALSA-Driver
0027  were made by Giuliano Pochini <pochini@shiny.it>
0028 
0029  ****************************************************************************
0030 
0031 
0032    Here's a block diagram of how most of the cards work:
0033 
0034                   +-----------+
0035            record |           |<-------------------- Inputs
0036           <-------|           |        |
0037      PCI          | Transport |        |
0038      bus          |  engine   |       \|/
0039           ------->|           |    +-------+
0040             play  |           |--->|monitor|-------> Outputs
0041                   +-----------+    | mixer |
0042                                    +-------+
0043 
0044    The lines going to and from the PCI bus represent "pipes".  A pipe performs
0045    audio transport - moving audio data to and from buffers on the host via
0046    bus mastering.
0047 
0048    The inputs and outputs on the right represent input and output "busses."
0049    A bus is a physical, real connection to the outside world.  An example
0050    of a bus would be the 1/4" analog connectors on the back of Layla or
0051    an RCA S/PDIF connector.
0052 
0053    For most cards, there is a one-to-one correspondence between outputs
0054    and busses; that is, each individual pipe is hard-wired to a single bus.
0055 
0056    Cards that work this way are Darla20, Gina20, Layla20, Darla24, Gina24,
0057    Layla24, Mona, and Indigo.
0058 
0059 
0060    Mia has a feature called "virtual outputs."
0061 
0062 
0063                   +-----------+
0064            record |           |<----------------------------- Inputs
0065           <-------|           |                  |
0066      PCI          | Transport |                  |
0067      bus          |  engine   |                 \|/
0068           ------->|           |   +------+   +-------+
0069             play  |           |-->|vmixer|-->|monitor|-------> Outputs
0070                   +-----------+   +------+   | mixer |
0071                                              +-------+
0072 
0073 
0074    Obviously, the difference here is the box labeled "vmixer."  Vmixer is
0075    short for "virtual output mixer."  For Mia, pipes are *not* hard-wired
0076    to a single bus; the vmixer lets you mix any pipe to any bus in any
0077    combination.
0078 
0079    Note, however, that the left-hand side of the diagram is unchanged.
0080    Transport works exactly the same way - the difference is in the mixer stage.
0081 
0082 
0083    Pipes and busses are numbered starting at zero.
0084 
0085 
0086 
0087    Pipe index
0088    ==========
0089 
0090    A number of calls in CEchoGals refer to a "pipe index".  A pipe index is
0091    a unique number for a pipe that unambiguously refers to a playback or record
0092    pipe.  Pipe indices are numbered starting with analog outputs, followed by
0093    digital outputs, then analog inputs, then digital inputs.
0094 
0095    Take Gina24 as an example:
0096 
0097    Pipe index
0098 
0099    0-7            Analog outputs (0 .. FirstDigitalBusOut-1)
0100    8-15           Digital outputs (FirstDigitalBusOut .. NumBussesOut-1)
0101    16-17          Analog inputs
0102    18-25          Digital inputs
0103 
0104 
0105    You get the pipe index by calling CEchoGals::OpenAudio; the other transport
0106    functions take the pipe index as a parameter.  If you need a pipe index for
0107    some other reason, use the handy Makepipe_index method.
0108 
0109 
0110    Some calls take a CChannelMask parameter; CChannelMask is a handy way to
0111    group pipe indices.
0112 
0113 
0114 
0115    Digital mode switch
0116    ===================
0117 
0118    Some cards (right now, Gina24, Layla24, and Mona) have a Digital Mode Switch
0119    or DMS.  Cards with a DMS can be set to one of three mutually exclusive
0120    digital modes: S/PDIF RCA, S/PDIF optical, or ADAT optical.
0121 
0122    This may create some confusion since ADAT optical is 8 channels wide and
0123    S/PDIF is only two channels wide.  Gina24, Layla24, and Mona handle this
0124    by acting as if they always have 8 digital outs and ins.  If you are in
0125    either S/PDIF mode, the last 6 channels don't do anything - data sent
0126    out these channels is thrown away and you will always record zeros.
0127 
0128    Note that with Gina24, Layla24, and Mona, sample rates above 50 kHz are
0129    only available if you have the card configured for S/PDIF optical or S/PDIF
0130    RCA.
0131 
0132 
0133 
0134    Double speed mode
0135    =================
0136 
0137    Some of the cards support 88.2 kHz and 96 kHz sampling (Darla24, Gina24,
0138    Layla24, Mona, Mia, and Indigo).  For these cards, the driver sometimes has
0139    to worry about "double speed mode"; double speed mode applies whenever the
0140    sampling rate is above 50 kHz.
0141 
0142    For instance, Mona and Layla24 support word clock sync.  However, they
0143    actually support two different word clock modes - single speed (below
0144    50 kHz) and double speed (above 50 kHz).  The hardware detects if a single
0145    or double speed word clock signal is present; the generic code uses that
0146    information to determine which mode to use.
0147 
0148    The generic code takes care of all this for you.
0149 */
0150 
0151 
0152 #ifndef _ECHOAUDIO_H_
0153 #define _ECHOAUDIO_H_
0154 
0155 
0156 #include "echoaudio_dsp.h"
0157 
0158 
0159 
0160 /***********************************************************************
0161 
0162     PCI configuration space
0163 
0164 ***********************************************************************/
0165 
0166 /*
0167  * PCI vendor ID and device IDs for the hardware
0168  */
0169 #define VENDOR_ID       0x1057
0170 #define DEVICE_ID_56301     0x1801
0171 #define DEVICE_ID_56361     0x3410
0172 #define SUBVENDOR_ID        0xECC0
0173 
0174 
0175 /*
0176  * Valid Echo PCI subsystem card IDs
0177  */
0178 #define DARLA20         0x0010
0179 #define GINA20          0x0020
0180 #define LAYLA20         0x0030
0181 #define DARLA24         0x0040
0182 #define GINA24          0x0050
0183 #define LAYLA24         0x0060
0184 #define MONA            0x0070
0185 #define MIA         0x0080
0186 #define INDIGO          0x0090
0187 #define INDIGO_IO       0x00a0
0188 #define INDIGO_DJ       0x00b0
0189 #define DC8         0x00c0
0190 #define INDIGO_IOX      0x00d0
0191 #define INDIGO_DJX      0x00e0
0192 #define ECHO3G          0x0100
0193 
0194 
0195 /************************************************************************
0196 
0197     Array sizes and so forth
0198 
0199 ***********************************************************************/
0200 
0201 /*
0202  * Sizes
0203  */
0204 #define ECHO_MAXAUDIOINPUTS 32  /* Max audio input channels */
0205 #define ECHO_MAXAUDIOOUTPUTS    32  /* Max audio output channels */
0206 #define ECHO_MAXAUDIOPIPES  32  /* Max number of input and output
0207                      * pipes */
0208 #define E3G_MAX_OUTPUTS     16
0209 #define ECHO_MAXMIDIJACKS   1   /* Max MIDI ports */
0210 #define ECHO_MIDI_QUEUE_SZ  512 /* Max MIDI input queue entries */
0211 #define ECHO_MTC_QUEUE_SZ   32  /* Max MIDI time code input queue
0212                      * entries */
0213 
0214 /*
0215  * MIDI activity indicator timeout
0216  */
0217 #define MIDI_ACTIVITY_TIMEOUT_USEC  200000
0218 
0219 
0220 /****************************************************************************
0221  
0222    Clocks
0223 
0224 *****************************************************************************/
0225 
0226 /*
0227  * Clock numbers
0228  */
0229 #define ECHO_CLOCK_INTERNAL     0
0230 #define ECHO_CLOCK_WORD         1
0231 #define ECHO_CLOCK_SUPER        2
0232 #define ECHO_CLOCK_SPDIF        3
0233 #define ECHO_CLOCK_ADAT         4
0234 #define ECHO_CLOCK_ESYNC        5
0235 #define ECHO_CLOCK_ESYNC96      6
0236 #define ECHO_CLOCK_MTC          7
0237 #define ECHO_CLOCK_NUMBER       8
0238 #define ECHO_CLOCKS         0xffff
0239 
0240 /*
0241  * Clock bit numbers - used to report capabilities and whatever clocks
0242  * are being detected dynamically.
0243  */
0244 #define ECHO_CLOCK_BIT_INTERNAL     (1 << ECHO_CLOCK_INTERNAL)
0245 #define ECHO_CLOCK_BIT_WORD     (1 << ECHO_CLOCK_WORD)
0246 #define ECHO_CLOCK_BIT_SUPER        (1 << ECHO_CLOCK_SUPER)
0247 #define ECHO_CLOCK_BIT_SPDIF        (1 << ECHO_CLOCK_SPDIF)
0248 #define ECHO_CLOCK_BIT_ADAT     (1 << ECHO_CLOCK_ADAT)
0249 #define ECHO_CLOCK_BIT_ESYNC        (1 << ECHO_CLOCK_ESYNC)
0250 #define ECHO_CLOCK_BIT_ESYNC96      (1 << ECHO_CLOCK_ESYNC96)
0251 #define ECHO_CLOCK_BIT_MTC      (1<<ECHO_CLOCK_MTC)
0252 
0253 
0254 /***************************************************************************
0255 
0256    Digital modes
0257 
0258 ****************************************************************************/
0259 
0260 /*
0261  * Digital modes for Mona, Layla24, and Gina24
0262  */
0263 #define DIGITAL_MODE_NONE           0xFF
0264 #define DIGITAL_MODE_SPDIF_RCA          0
0265 #define DIGITAL_MODE_SPDIF_OPTICAL      1
0266 #define DIGITAL_MODE_ADAT           2
0267 #define DIGITAL_MODE_SPDIF_CDROM        3
0268 #define DIGITAL_MODES               4
0269 
0270 /*
0271  * Digital mode capability masks
0272  */
0273 #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA (1 << DIGITAL_MODE_SPDIF_RCA)
0274 #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL (1 << DIGITAL_MODE_SPDIF_OPTICAL)
0275 #define ECHOCAPS_HAS_DIGITAL_MODE_ADAT      (1 << DIGITAL_MODE_ADAT)
0276 #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM   (1 << DIGITAL_MODE_SPDIF_CDROM)
0277 
0278 
0279 #define EXT_3GBOX_NC            0x01    /* 3G box not connected */
0280 #define EXT_3GBOX_NOT_SET       0x02    /* 3G box not detected yet */
0281 
0282 
0283 #define ECHOGAIN_MUTED      (-128)  /* Minimum possible gain */
0284 #define ECHOGAIN_MINOUT     (-128)  /* Min output gain (dB) */
0285 #define ECHOGAIN_MAXOUT     (6) /* Max output gain (dB) */
0286 #define ECHOGAIN_MININP     (-50)   /* Min input gain (0.5 dB) */
0287 #define ECHOGAIN_MAXINP     (50)    /* Max input gain (0.5 dB) */
0288 
0289 #define PIPE_STATE_STOPPED  0   /* Pipe has been reset */
0290 #define PIPE_STATE_PAUSED   1   /* Pipe has been stopped */
0291 #define PIPE_STATE_STARTED  2   /* Pipe has been started */
0292 #define PIPE_STATE_PENDING  3   /* Pipe has pending start */
0293 
0294 
0295 
0296 struct audiopipe {
0297     volatile __le32 *dma_counter;   /* Commpage register that contains
0298                      * the current dma position
0299                      * (lower 32 bits only)
0300                      */
0301     u32 last_period;                /* Counter position last time a
0302                      * period elapsed
0303                      */
0304     u32 last_counter;       /* Used exclusively by pcm_pointer
0305                      * under PCM core locks.
0306                      * The last position, which is used
0307                      * to compute...
0308                      */
0309     u32 position;           /* ...the number of bytes tranferred
0310                      * by the DMA engine, modulo the
0311                      * buffer size
0312                      */
0313     short index;            /* Index of the first channel or <0
0314                      * if hw is not configured yet
0315                      */
0316     short interleave;
0317     struct snd_dma_buffer sgpage;   /* Room for the scatter-gather list */
0318     struct snd_pcm_hardware hw;
0319     struct snd_pcm_hw_constraint_list constr;
0320     short sglist_head;
0321     char state;         /* pipe state */
0322 };
0323 
0324 
0325 struct audioformat {
0326     u8 interleave;          /* How the data is arranged in memory:
0327                      * mono = 1, stereo = 2, ...
0328                      */
0329     u8 bits_per_sample;     /* 8, 16, 24, 32 (24 bits left aligned) */
0330     char mono_to_stereo;        /* Only used if interleave is 1 and
0331                      * if this is an output pipe.
0332                      */
0333     char data_are_bigendian;    /* 1 = big endian, 0 = little endian */
0334 };
0335 
0336 
0337 struct echoaudio {
0338     spinlock_t lock;
0339     struct snd_pcm_substream *substream[DSP_MAXPIPES];
0340     struct mutex mode_mutex;
0341     u16 num_digital_modes, digital_mode_list[6];
0342     u16 num_clock_sources, clock_source_list[10];
0343     unsigned int opencount;  /* protected by mode_mutex */
0344     struct snd_kcontrol *clock_src_ctl;
0345     struct snd_pcm *analog_pcm, *digital_pcm;
0346     struct snd_card *card;
0347     const char *card_name;
0348     struct pci_dev *pci;
0349     unsigned long dsp_registers_phys;
0350     struct resource *iores;
0351     struct snd_dma_buffer *commpage_dma_buf;
0352     int irq;
0353 #ifdef ECHOCARD_HAS_MIDI
0354     struct snd_rawmidi *rmidi;
0355     struct snd_rawmidi_substream *midi_in, *midi_out;
0356 #endif
0357     struct timer_list timer;
0358     char tinuse;                /* Timer in use */
0359     char midi_full;             /* MIDI output buffer is full */
0360     char can_set_rate;                      /* protected by mode_mutex */
0361     char rate_set;                          /* protected by mode_mutex */
0362 
0363     /* This stuff is used mainly by the lowlevel code */
0364     struct comm_page *comm_page;    /* Virtual address of the memory
0365                      * seen by DSP
0366                      */
0367     u32 pipe_alloc_mask;        /* Bitmask of allocated pipes */
0368     u32 pipe_cyclic_mask;       /* Bitmask of pipes with cyclic
0369                      * buffers
0370                      */
0371     u32 sample_rate;        /* Card sample rate in Hz */
0372     u8 digital_mode;        /* Current digital mode
0373                      * (see DIGITAL_MODE_*)
0374                      */
0375     u8 spdif_status;        /* Gina20, Darla20, Darla24 - only */
0376     u8 clock_state;         /* Gina20, Darla20, Darla24 - only */
0377     u8 input_clock;         /* Currently selected sample clock
0378                      * source
0379                      */
0380     u8 output_clock;        /* Layla20 only */
0381     char meters_enabled;        /* VU-meters status */
0382     char asic_loaded;       /* Set true when ASIC loaded */
0383     char bad_board;         /* Set true if DSP won't load */
0384     char professional_spdif;    /* 0 = consumer; 1 = professional */
0385     char non_audio_spdif;       /* 3G - only */
0386     char digital_in_automute;   /* Gina24, Layla24, Mona - only */
0387     char has_phantom_power;
0388     char hasnt_input_nominal_level; /* Gina3G */
0389     char phantom_power;     /* Gina3G - only */
0390     char has_midi;
0391     char midi_input_enabled;
0392 
0393 #ifdef ECHOCARD_ECHO3G
0394     /* External module -dependent pipe and bus indexes */
0395     char px_digital_out, px_analog_in, px_digital_in, px_num;
0396     char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;
0397 #endif
0398 
0399     char nominal_level[ECHO_MAXAUDIOPIPES]; /* True == -10dBV
0400                          * False == +4dBu */
0401     s8 input_gain[ECHO_MAXAUDIOINPUTS]; /* Input level -50..+50
0402                          * unit is 0.5dB */
0403     s8 output_gain[ECHO_MAXAUDIOOUTPUTS];   /* Output level -128..+6 dB
0404                          * (-128=muted) */
0405     s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];
0406         /* -128..+6 dB */
0407     s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
0408         /* -128..+6 dB */
0409 
0410     u16 digital_modes;      /* Bitmask of supported modes
0411                      * (see ECHOCAPS_HAS_DIGITAL_MODE_*) */
0412     u16 input_clock_types;      /* Suppoted input clock types */
0413     u16 output_clock_types;     /* Suppoted output clock types -
0414                      * Layla20 only */
0415     u16 device_id, subdevice_id;
0416     u16 *dsp_code;          /* Current DSP code loaded,
0417                      * NULL if nothing loaded */
0418     short dsp_code_to_load;     /* DSP code to load */
0419     short asic_code;        /* Current ASIC code */
0420     u32 comm_page_phys;         /* Physical address of the
0421                          * memory seen by DSP */
0422     u32 __iomem *dsp_registers;     /* DSP's register base */
0423     u32 active_mask;            /* Chs. active mask or
0424                          * punks out */
0425 #ifdef CONFIG_PM_SLEEP
0426     const struct firmware *fw_cache[8]; /* Cached firmwares */
0427 #endif
0428 
0429 #ifdef ECHOCARD_HAS_MIDI
0430     u16 mtc_state;              /* State for MIDI input parsing state machine */
0431     u8 midi_buffer[MIDI_IN_BUFFER_SIZE];
0432 #endif
0433 };
0434 
0435 
0436 static int init_dsp_comm_page(struct echoaudio *chip);
0437 static int init_line_levels(struct echoaudio *chip);
0438 static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);
0439 static int load_firmware(struct echoaudio *chip);
0440 static int wait_handshake(struct echoaudio *chip);
0441 static int send_vector(struct echoaudio *chip, u32 command);
0442 static int get_firmware(const struct firmware **fw_entry,
0443             struct echoaudio *chip, const short fw_index);
0444 static void free_firmware(const struct firmware *fw_entry,
0445               struct echoaudio *chip);
0446 
0447 #ifdef ECHOCARD_HAS_MIDI
0448 static int enable_midi_input(struct echoaudio *chip, char enable);
0449 static void snd_echo_midi_output_trigger(
0450             struct snd_rawmidi_substream *substream, int up);
0451 static int midi_service_irq(struct echoaudio *chip);
0452 static int snd_echo_midi_create(struct snd_card *card,
0453                 struct echoaudio *chip);
0454 #endif
0455 
0456 
0457 static inline void clear_handshake(struct echoaudio *chip)
0458 {
0459     chip->comm_page->handshake = 0;
0460 }
0461 
0462 static inline u32 get_dsp_register(struct echoaudio *chip, u32 index)
0463 {
0464     return readl(&chip->dsp_registers[index]);
0465 }
0466 
0467 static inline void set_dsp_register(struct echoaudio *chip, u32 index,
0468                     u32 value)
0469 {
0470     writel(value, &chip->dsp_registers[index]);
0471 }
0472 
0473 
0474 /* Pipe and bus indexes. PX_* and BX_* are defined as chip->px_* and chip->bx_*
0475 for 3G cards because they depend on the external box. They are integer
0476 constants for all other cards.
0477 Never use those defines directly, use the following functions instead. */
0478 
0479 static inline int px_digital_out(const struct echoaudio *chip)
0480 {
0481     return PX_DIGITAL_OUT;
0482 }
0483 
0484 static inline int px_analog_in(const struct echoaudio *chip)
0485 {
0486     return PX_ANALOG_IN;
0487 }
0488 
0489 static inline int px_digital_in(const struct echoaudio *chip)
0490 {
0491     return PX_DIGITAL_IN;
0492 }
0493 
0494 static inline int px_num(const struct echoaudio *chip)
0495 {
0496     return PX_NUM;
0497 }
0498 
0499 static inline int bx_digital_out(const struct echoaudio *chip)
0500 {
0501     return BX_DIGITAL_OUT;
0502 }
0503 
0504 static inline int bx_analog_in(const struct echoaudio *chip)
0505 {
0506     return BX_ANALOG_IN;
0507 }
0508 
0509 static inline int bx_digital_in(const struct echoaudio *chip)
0510 {
0511     return BX_DIGITAL_IN;
0512 }
0513 
0514 static inline int bx_num(const struct echoaudio *chip)
0515 {
0516     return BX_NUM;
0517 }
0518 
0519 static inline int num_pipes_out(const struct echoaudio *chip)
0520 {
0521     return px_analog_in(chip);
0522 }
0523 
0524 static inline int num_pipes_in(const struct echoaudio *chip)
0525 {
0526     return px_num(chip) - px_analog_in(chip);
0527 }
0528 
0529 static inline int num_busses_out(const struct echoaudio *chip)
0530 {
0531     return bx_analog_in(chip);
0532 }
0533 
0534 static inline int num_busses_in(const struct echoaudio *chip)
0535 {
0536     return bx_num(chip) - bx_analog_in(chip);
0537 }
0538 
0539 static inline int num_analog_busses_out(const struct echoaudio *chip)
0540 {
0541     return bx_digital_out(chip);
0542 }
0543 
0544 static inline int num_analog_busses_in(const struct echoaudio *chip)
0545 {
0546     return bx_digital_in(chip) - bx_analog_in(chip);
0547 }
0548 
0549 static inline int num_digital_busses_out(const struct echoaudio *chip)
0550 {
0551     return num_busses_out(chip) - num_analog_busses_out(chip);
0552 }
0553 
0554 static inline int num_digital_busses_in(const struct echoaudio *chip)
0555 {
0556     return num_busses_in(chip) - num_analog_busses_in(chip);
0557 }
0558 
0559 /* The monitor array is a one-dimensional array; compute the offset
0560  * into the array */
0561 static inline int monitor_index(const struct echoaudio *chip, int out, int in)
0562 {
0563     return out * num_busses_in(chip) + in;
0564 }
0565 
0566 #endif /* _ECHOAUDIO_H_ */