echoaudio.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /****************************************************************************
  2. Copyright Echo Digital Audio Corporation (c) 1998 - 2004
  3. All rights reserved
  4. www.echoaudio.com
  5. This file is part of Echo Digital Audio's generic driver library.
  6. Echo Digital Audio's generic driver library is free software;
  7. you can redistribute it and/or modify it under the terms of
  8. the GNU General Public License as published by the Free Software
  9. Foundation.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. MA 02111-1307, USA.
  18. ****************************************************************************
  19. Translation from C++ and adaptation for use in ALSA-Driver
  20. were made by Giuliano Pochini <pochini@shiny.it>
  21. ****************************************************************************
  22. Here's a block diagram of how most of the cards work:
  23. +-----------+
  24. record | |<-------------------- Inputs
  25. <-------| | |
  26. PCI | Transport | |
  27. bus | engine | \|/
  28. ------->| | +-------+
  29. play | |--->|monitor|-------> Outputs
  30. +-----------+ | mixer |
  31. +-------+
  32. The lines going to and from the PCI bus represent "pipes". A pipe performs
  33. audio transport - moving audio data to and from buffers on the host via
  34. bus mastering.
  35. The inputs and outputs on the right represent input and output "busses."
  36. A bus is a physical, real connection to the outside world. An example
  37. of a bus would be the 1/4" analog connectors on the back of Layla or
  38. an RCA S/PDIF connector.
  39. For most cards, there is a one-to-one correspondence between outputs
  40. and busses; that is, each individual pipe is hard-wired to a single bus.
  41. Cards that work this way are Darla20, Gina20, Layla20, Darla24, Gina24,
  42. Layla24, Mona, and Indigo.
  43. Mia has a feature called "virtual outputs."
  44. +-----------+
  45. record | |<----------------------------- Inputs
  46. <-------| | |
  47. PCI | Transport | |
  48. bus | engine | \|/
  49. ------->| | +------+ +-------+
  50. play | |-->|vmixer|-->|monitor|-------> Outputs
  51. +-----------+ +------+ | mixer |
  52. +-------+
  53. Obviously, the difference here is the box labeled "vmixer." Vmixer is
  54. short for "virtual output mixer." For Mia, pipes are *not* hard-wired
  55. to a single bus; the vmixer lets you mix any pipe to any bus in any
  56. combination.
  57. Note, however, that the left-hand side of the diagram is unchanged.
  58. Transport works exactly the same way - the difference is in the mixer stage.
  59. Pipes and busses are numbered starting at zero.
  60. Pipe index
  61. ==========
  62. A number of calls in CEchoGals refer to a "pipe index". A pipe index is
  63. a unique number for a pipe that unambiguously refers to a playback or record
  64. pipe. Pipe indices are numbered starting with analog outputs, followed by
  65. digital outputs, then analog inputs, then digital inputs.
  66. Take Gina24 as an example:
  67. Pipe index
  68. 0-7 Analog outputs (0 .. FirstDigitalBusOut-1)
  69. 8-15 Digital outputs (FirstDigitalBusOut .. NumBussesOut-1)
  70. 16-17 Analog inputs
  71. 18-25 Digital inputs
  72. You get the pipe index by calling CEchoGals::OpenAudio; the other transport
  73. functions take the pipe index as a parameter. If you need a pipe index for
  74. some other reason, use the handy Makepipe_index method.
  75. Some calls take a CChannelMask parameter; CChannelMask is a handy way to
  76. group pipe indices.
  77. Digital mode switch
  78. ===================
  79. Some cards (right now, Gina24, Layla24, and Mona) have a Digital Mode Switch
  80. or DMS. Cards with a DMS can be set to one of three mutually exclusive
  81. digital modes: S/PDIF RCA, S/PDIF optical, or ADAT optical.
  82. This may create some confusion since ADAT optical is 8 channels wide and
  83. S/PDIF is only two channels wide. Gina24, Layla24, and Mona handle this
  84. by acting as if they always have 8 digital outs and ins. If you are in
  85. either S/PDIF mode, the last 6 channels don't do anything - data sent
  86. out these channels is thrown away and you will always record zeros.
  87. Note that with Gina24, Layla24, and Mona, sample rates above 50 kHz are
  88. only available if you have the card configured for S/PDIF optical or S/PDIF
  89. RCA.
  90. Double speed mode
  91. =================
  92. Some of the cards support 88.2 kHz and 96 kHz sampling (Darla24, Gina24,
  93. Layla24, Mona, Mia, and Indigo). For these cards, the driver sometimes has
  94. to worry about "double speed mode"; double speed mode applies whenever the
  95. sampling rate is above 50 kHz.
  96. For instance, Mona and Layla24 support word clock sync. However, they
  97. actually support two different word clock modes - single speed (below
  98. 50 kHz) and double speed (above 50 kHz). The hardware detects if a single
  99. or double speed word clock signal is present; the generic code uses that
  100. information to determine which mode to use.
  101. The generic code takes care of all this for you.
  102. */
  103. #ifndef _ECHOAUDIO_H_
  104. #define _ECHOAUDIO_H_
  105. #define TRUE 1
  106. #define FALSE 0
  107. #include "echoaudio_dsp.h"
  108. /***********************************************************************
  109. PCI configuration space
  110. ***********************************************************************/
  111. /*
  112. * PCI vendor ID and device IDs for the hardware
  113. */
  114. #define VENDOR_ID 0x1057
  115. #define DEVICE_ID_56301 0x1801
  116. #define DEVICE_ID_56361 0x3410
  117. #define SUBVENDOR_ID 0xECC0
  118. /*
  119. * Valid Echo PCI subsystem card IDs
  120. */
  121. #define DARLA20 0x0010
  122. #define GINA20 0x0020
  123. #define LAYLA20 0x0030
  124. #define DARLA24 0x0040
  125. #define GINA24 0x0050
  126. #define LAYLA24 0x0060
  127. #define MONA 0x0070
  128. #define MIA 0x0080
  129. #define INDIGO 0x0090
  130. #define INDIGO_IO 0x00a0
  131. #define INDIGO_DJ 0x00b0
  132. #define DC8 0x00c0
  133. #define INDIGO_IOX 0x00d0
  134. #define INDIGO_DJX 0x00e0
  135. #define ECHO3G 0x0100
  136. /************************************************************************
  137. Array sizes and so forth
  138. ***********************************************************************/
  139. /*
  140. * Sizes
  141. */
  142. #define ECHO_MAXAUDIOINPUTS 32 /* Max audio input channels */
  143. #define ECHO_MAXAUDIOOUTPUTS 32 /* Max audio output channels */
  144. #define ECHO_MAXAUDIOPIPES 32 /* Max number of input and output
  145. * pipes */
  146. #define E3G_MAX_OUTPUTS 16
  147. #define ECHO_MAXMIDIJACKS 1 /* Max MIDI ports */
  148. #define ECHO_MIDI_QUEUE_SZ 512 /* Max MIDI input queue entries */
  149. #define ECHO_MTC_QUEUE_SZ 32 /* Max MIDI time code input queue
  150. * entries */
  151. /*
  152. * MIDI activity indicator timeout
  153. */
  154. #define MIDI_ACTIVITY_TIMEOUT_USEC 200000
  155. /****************************************************************************
  156. Clocks
  157. *****************************************************************************/
  158. /*
  159. * Clock numbers
  160. */
  161. #define ECHO_CLOCK_INTERNAL 0
  162. #define ECHO_CLOCK_WORD 1
  163. #define ECHO_CLOCK_SUPER 2
  164. #define ECHO_CLOCK_SPDIF 3
  165. #define ECHO_CLOCK_ADAT 4
  166. #define ECHO_CLOCK_ESYNC 5
  167. #define ECHO_CLOCK_ESYNC96 6
  168. #define ECHO_CLOCK_MTC 7
  169. #define ECHO_CLOCK_NUMBER 8
  170. #define ECHO_CLOCKS 0xffff
  171. /*
  172. * Clock bit numbers - used to report capabilities and whatever clocks
  173. * are being detected dynamically.
  174. */
  175. #define ECHO_CLOCK_BIT_INTERNAL (1 << ECHO_CLOCK_INTERNAL)
  176. #define ECHO_CLOCK_BIT_WORD (1 << ECHO_CLOCK_WORD)
  177. #define ECHO_CLOCK_BIT_SUPER (1 << ECHO_CLOCK_SUPER)
  178. #define ECHO_CLOCK_BIT_SPDIF (1 << ECHO_CLOCK_SPDIF)
  179. #define ECHO_CLOCK_BIT_ADAT (1 << ECHO_CLOCK_ADAT)
  180. #define ECHO_CLOCK_BIT_ESYNC (1 << ECHO_CLOCK_ESYNC)
  181. #define ECHO_CLOCK_BIT_ESYNC96 (1 << ECHO_CLOCK_ESYNC96)
  182. #define ECHO_CLOCK_BIT_MTC (1<<ECHO_CLOCK_MTC)
  183. /***************************************************************************
  184. Digital modes
  185. ****************************************************************************/
  186. /*
  187. * Digital modes for Mona, Layla24, and Gina24
  188. */
  189. #define DIGITAL_MODE_NONE 0xFF
  190. #define DIGITAL_MODE_SPDIF_RCA 0
  191. #define DIGITAL_MODE_SPDIF_OPTICAL 1
  192. #define DIGITAL_MODE_ADAT 2
  193. #define DIGITAL_MODE_SPDIF_CDROM 3
  194. #define DIGITAL_MODES 4
  195. /*
  196. * Digital mode capability masks
  197. */
  198. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA (1 << DIGITAL_MODE_SPDIF_RCA)
  199. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL (1 << DIGITAL_MODE_SPDIF_OPTICAL)
  200. #define ECHOCAPS_HAS_DIGITAL_MODE_ADAT (1 << DIGITAL_MODE_ADAT)
  201. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM (1 << DIGITAL_MODE_SPDIF_CDROM)
  202. #define EXT_3GBOX_NC 0x01 /* 3G box not connected */
  203. #define EXT_3GBOX_NOT_SET 0x02 /* 3G box not detected yet */
  204. #define ECHOGAIN_MUTED (-128) /* Minimum possible gain */
  205. #define ECHOGAIN_MINOUT (-128) /* Min output gain (dB) */
  206. #define ECHOGAIN_MAXOUT (6) /* Max output gain (dB) */
  207. #define ECHOGAIN_MININP (-50) /* Min input gain (0.5 dB) */
  208. #define ECHOGAIN_MAXINP (50) /* Max input gain (0.5 dB) */
  209. #define PIPE_STATE_STOPPED 0 /* Pipe has been reset */
  210. #define PIPE_STATE_PAUSED 1 /* Pipe has been stopped */
  211. #define PIPE_STATE_STARTED 2 /* Pipe has been started */
  212. #define PIPE_STATE_PENDING 3 /* Pipe has pending start */
  213. struct audiopipe {
  214. volatile u32 *dma_counter; /* Commpage register that contains
  215. * the current dma position
  216. * (lower 32 bits only)
  217. */
  218. u32 last_counter; /* The last position, which is used
  219. * to compute...
  220. */
  221. u32 position; /* ...the number of bytes tranferred
  222. * by the DMA engine, modulo the
  223. * buffer size
  224. */
  225. short index; /* Index of the first channel or <0
  226. * if hw is not configured yet
  227. */
  228. short interleave;
  229. struct snd_dma_buffer sgpage; /* Room for the scatter-gather list */
  230. struct snd_pcm_hardware hw;
  231. struct snd_pcm_hw_constraint_list constr;
  232. short sglist_head;
  233. char state; /* pipe state */
  234. };
  235. struct audioformat {
  236. u8 interleave; /* How the data is arranged in memory:
  237. * mono = 1, stereo = 2, ...
  238. */
  239. u8 bits_per_sample; /* 8, 16, 24, 32 (24 bits left aligned) */
  240. char mono_to_stereo; /* Only used if interleave is 1 and
  241. * if this is an output pipe.
  242. */
  243. char data_are_bigendian; /* 1 = big endian, 0 = little endian */
  244. };
  245. struct echoaudio {
  246. spinlock_t lock;
  247. struct snd_pcm_substream *substream[DSP_MAXPIPES];
  248. int last_period[DSP_MAXPIPES];
  249. struct mutex mode_mutex;
  250. u16 num_digital_modes, digital_mode_list[6];
  251. u16 num_clock_sources, clock_source_list[10];
  252. atomic_t opencount;
  253. struct snd_kcontrol *clock_src_ctl;
  254. struct snd_pcm *analog_pcm, *digital_pcm;
  255. struct snd_card *card;
  256. const char *card_name;
  257. struct pci_dev *pci;
  258. unsigned long dsp_registers_phys;
  259. struct resource *iores;
  260. struct snd_dma_buffer commpage_dma_buf;
  261. int irq;
  262. #ifdef ECHOCARD_HAS_MIDI
  263. struct snd_rawmidi *rmidi;
  264. struct snd_rawmidi_substream *midi_in, *midi_out;
  265. #endif
  266. struct timer_list timer;
  267. char tinuse; /* Timer in use */
  268. char midi_full; /* MIDI output buffer is full */
  269. char can_set_rate;
  270. char rate_set;
  271. /* This stuff is used mainly by the lowlevel code */
  272. struct comm_page *comm_page; /* Virtual address of the memory
  273. * seen by DSP
  274. */
  275. u32 pipe_alloc_mask; /* Bitmask of allocated pipes */
  276. u32 pipe_cyclic_mask; /* Bitmask of pipes with cyclic
  277. * buffers
  278. */
  279. u32 sample_rate; /* Card sample rate in Hz */
  280. u8 digital_mode; /* Current digital mode
  281. * (see DIGITAL_MODE_*)
  282. */
  283. u8 spdif_status; /* Gina20, Darla20, Darla24 - only */
  284. u8 clock_state; /* Gina20, Darla20, Darla24 - only */
  285. u8 input_clock; /* Currently selected sample clock
  286. * source
  287. */
  288. u8 output_clock; /* Layla20 only */
  289. char meters_enabled; /* VU-meters status */
  290. char asic_loaded; /* Set TRUE when ASIC loaded */
  291. char bad_board; /* Set TRUE if DSP won't load */
  292. char professional_spdif; /* 0 = consumer; 1 = professional */
  293. char non_audio_spdif; /* 3G - only */
  294. char digital_in_automute; /* Gina24, Layla24, Mona - only */
  295. char has_phantom_power;
  296. char hasnt_input_nominal_level; /* Gina3G */
  297. char phantom_power; /* Gina3G - only */
  298. char has_midi;
  299. char midi_input_enabled;
  300. #ifdef ECHOCARD_ECHO3G
  301. /* External module -dependent pipe and bus indexes */
  302. char px_digital_out, px_analog_in, px_digital_in, px_num;
  303. char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;
  304. #endif
  305. char nominal_level[ECHO_MAXAUDIOPIPES]; /* True == -10dBV
  306. * False == +4dBu */
  307. s8 input_gain[ECHO_MAXAUDIOINPUTS]; /* Input level -50..+50
  308. * unit is 0.5dB */
  309. s8 output_gain[ECHO_MAXAUDIOOUTPUTS]; /* Output level -128..+6 dB
  310. * (-128=muted) */
  311. s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];
  312. /* -128..+6 dB */
  313. s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
  314. /* -128..+6 dB */
  315. u16 digital_modes; /* Bitmask of supported modes
  316. * (see ECHOCAPS_HAS_DIGITAL_MODE_*) */
  317. u16 input_clock_types; /* Suppoted input clock types */
  318. u16 output_clock_types; /* Suppoted output clock types -
  319. * Layla20 only */
  320. u16 device_id, subdevice_id;
  321. u16 *dsp_code; /* Current DSP code loaded,
  322. * NULL if nothing loaded */
  323. short dsp_code_to_load; /* DSP code to load */
  324. short asic_code; /* Current ASIC code */
  325. u32 comm_page_phys; /* Physical address of the
  326. * memory seen by DSP */
  327. volatile u32 __iomem *dsp_registers; /* DSP's register base */
  328. u32 active_mask; /* Chs. active mask or
  329. * punks out */
  330. #ifdef CONFIG_PM_SLEEP
  331. const struct firmware *fw_cache[8]; /* Cached firmwares */
  332. #endif
  333. #ifdef ECHOCARD_HAS_MIDI
  334. u16 mtc_state; /* State for MIDI input parsing state machine */
  335. u8 midi_buffer[MIDI_IN_BUFFER_SIZE];
  336. #endif
  337. };
  338. static int init_dsp_comm_page(struct echoaudio *chip);
  339. static int init_line_levels(struct echoaudio *chip);
  340. static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);
  341. static int load_firmware(struct echoaudio *chip);
  342. static int wait_handshake(struct echoaudio *chip);
  343. static int send_vector(struct echoaudio *chip, u32 command);
  344. static int get_firmware(const struct firmware **fw_entry,
  345. struct echoaudio *chip, const short fw_index);
  346. static void free_firmware(const struct firmware *fw_entry,
  347. struct echoaudio *chip);
  348. #ifdef ECHOCARD_HAS_MIDI
  349. static int enable_midi_input(struct echoaudio *chip, char enable);
  350. static void snd_echo_midi_output_trigger(
  351. struct snd_rawmidi_substream *substream, int up);
  352. static int midi_service_irq(struct echoaudio *chip);
  353. static int snd_echo_midi_create(struct snd_card *card,
  354. struct echoaudio *chip);
  355. #endif
  356. static inline void clear_handshake(struct echoaudio *chip)
  357. {
  358. chip->comm_page->handshake = 0;
  359. }
  360. static inline u32 get_dsp_register(struct echoaudio *chip, u32 index)
  361. {
  362. return readl(&chip->dsp_registers[index]);
  363. }
  364. static inline void set_dsp_register(struct echoaudio *chip, u32 index,
  365. u32 value)
  366. {
  367. writel(value, &chip->dsp_registers[index]);
  368. }
  369. /* Pipe and bus indexes. PX_* and BX_* are defined as chip->px_* and chip->bx_*
  370. for 3G cards because they depend on the external box. They are integer
  371. constants for all other cards.
  372. Never use those defines directly, use the following functions instead. */
  373. static inline int px_digital_out(const struct echoaudio *chip)
  374. {
  375. return PX_DIGITAL_OUT;
  376. }
  377. static inline int px_analog_in(const struct echoaudio *chip)
  378. {
  379. return PX_ANALOG_IN;
  380. }
  381. static inline int px_digital_in(const struct echoaudio *chip)
  382. {
  383. return PX_DIGITAL_IN;
  384. }
  385. static inline int px_num(const struct echoaudio *chip)
  386. {
  387. return PX_NUM;
  388. }
  389. static inline int bx_digital_out(const struct echoaudio *chip)
  390. {
  391. return BX_DIGITAL_OUT;
  392. }
  393. static inline int bx_analog_in(const struct echoaudio *chip)
  394. {
  395. return BX_ANALOG_IN;
  396. }
  397. static inline int bx_digital_in(const struct echoaudio *chip)
  398. {
  399. return BX_DIGITAL_IN;
  400. }
  401. static inline int bx_num(const struct echoaudio *chip)
  402. {
  403. return BX_NUM;
  404. }
  405. static inline int num_pipes_out(const struct echoaudio *chip)
  406. {
  407. return px_analog_in(chip);
  408. }
  409. static inline int num_pipes_in(const struct echoaudio *chip)
  410. {
  411. return px_num(chip) - px_analog_in(chip);
  412. }
  413. static inline int num_busses_out(const struct echoaudio *chip)
  414. {
  415. return bx_analog_in(chip);
  416. }
  417. static inline int num_busses_in(const struct echoaudio *chip)
  418. {
  419. return bx_num(chip) - bx_analog_in(chip);
  420. }
  421. static inline int num_analog_busses_out(const struct echoaudio *chip)
  422. {
  423. return bx_digital_out(chip);
  424. }
  425. static inline int num_analog_busses_in(const struct echoaudio *chip)
  426. {
  427. return bx_digital_in(chip) - bx_analog_in(chip);
  428. }
  429. static inline int num_digital_busses_out(const struct echoaudio *chip)
  430. {
  431. return num_busses_out(chip) - num_analog_busses_out(chip);
  432. }
  433. static inline int num_digital_busses_in(const struct echoaudio *chip)
  434. {
  435. return num_busses_in(chip) - num_analog_busses_in(chip);
  436. }
  437. /* The monitor array is a one-dimensional array; compute the offset
  438. * into the array */
  439. static inline int monitor_index(const struct echoaudio *chip, int out, int in)
  440. {
  441. return out * num_busses_in(chip) + in;
  442. }
  443. #ifndef pci_device
  444. #define pci_device(chip) (&chip->pci->dev)
  445. #endif
  446. #endif /* _ECHOAUDIO_H_ */