echoaudio.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 ECHO3G 0x0100
  133. /************************************************************************
  134. Array sizes and so forth
  135. ***********************************************************************/
  136. /*
  137. * Sizes
  138. */
  139. #define ECHO_MAXAUDIOINPUTS 32 /* Max audio input channels */
  140. #define ECHO_MAXAUDIOOUTPUTS 32 /* Max audio output channels */
  141. #define ECHO_MAXAUDIOPIPES 32 /* Max number of input and output
  142. * pipes */
  143. #define E3G_MAX_OUTPUTS 16
  144. #define ECHO_MAXMIDIJACKS 1 /* Max MIDI ports */
  145. #define ECHO_MIDI_QUEUE_SZ 512 /* Max MIDI input queue entries */
  146. #define ECHO_MTC_QUEUE_SZ 32 /* Max MIDI time code input queue
  147. * entries */
  148. /*
  149. * MIDI activity indicator timeout
  150. */
  151. #define MIDI_ACTIVITY_TIMEOUT_USEC 200000
  152. /****************************************************************************
  153. Clocks
  154. *****************************************************************************/
  155. /*
  156. * Clock numbers
  157. */
  158. #define ECHO_CLOCK_INTERNAL 0
  159. #define ECHO_CLOCK_WORD 1
  160. #define ECHO_CLOCK_SUPER 2
  161. #define ECHO_CLOCK_SPDIF 3
  162. #define ECHO_CLOCK_ADAT 4
  163. #define ECHO_CLOCK_ESYNC 5
  164. #define ECHO_CLOCK_ESYNC96 6
  165. #define ECHO_CLOCK_MTC 7
  166. #define ECHO_CLOCK_NUMBER 8
  167. #define ECHO_CLOCKS 0xffff
  168. /*
  169. * Clock bit numbers - used to report capabilities and whatever clocks
  170. * are being detected dynamically.
  171. */
  172. #define ECHO_CLOCK_BIT_INTERNAL (1 << ECHO_CLOCK_INTERNAL)
  173. #define ECHO_CLOCK_BIT_WORD (1 << ECHO_CLOCK_WORD)
  174. #define ECHO_CLOCK_BIT_SUPER (1 << ECHO_CLOCK_SUPER)
  175. #define ECHO_CLOCK_BIT_SPDIF (1 << ECHO_CLOCK_SPDIF)
  176. #define ECHO_CLOCK_BIT_ADAT (1 << ECHO_CLOCK_ADAT)
  177. #define ECHO_CLOCK_BIT_ESYNC (1 << ECHO_CLOCK_ESYNC)
  178. #define ECHO_CLOCK_BIT_ESYNC96 (1 << ECHO_CLOCK_ESYNC96)
  179. #define ECHO_CLOCK_BIT_MTC (1<<ECHO_CLOCK_MTC)
  180. /***************************************************************************
  181. Digital modes
  182. ****************************************************************************/
  183. /*
  184. * Digital modes for Mona, Layla24, and Gina24
  185. */
  186. #define DIGITAL_MODE_NONE 0xFF
  187. #define DIGITAL_MODE_SPDIF_RCA 0
  188. #define DIGITAL_MODE_SPDIF_OPTICAL 1
  189. #define DIGITAL_MODE_ADAT 2
  190. #define DIGITAL_MODE_SPDIF_CDROM 3
  191. #define DIGITAL_MODES 4
  192. /*
  193. * Digital mode capability masks
  194. */
  195. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA (1 << DIGITAL_MODE_SPDIF_RCA)
  196. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL (1 << DIGITAL_MODE_SPDIF_OPTICAL)
  197. #define ECHOCAPS_HAS_DIGITAL_MODE_ADAT (1 << DIGITAL_MODE_ADAT)
  198. #define ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM (1 << DIGITAL_MODE_SPDIF_CDROM)
  199. #define EXT_3GBOX_NC 0x01 /* 3G box not connected */
  200. #define EXT_3GBOX_NOT_SET 0x02 /* 3G box not detected yet */
  201. #define ECHOGAIN_MUTED (-128) /* Minimum possible gain */
  202. #define ECHOGAIN_MINOUT (-128) /* Min output gain (dB) */
  203. #define ECHOGAIN_MAXOUT (6) /* Max output gain (dB) */
  204. #define ECHOGAIN_MININP (-50) /* Min input gain (0.5 dB) */
  205. #define ECHOGAIN_MAXINP (50) /* Max input gain (0.5 dB) */
  206. #define PIPE_STATE_STOPPED 0 /* Pipe has been reset */
  207. #define PIPE_STATE_PAUSED 1 /* Pipe has been stopped */
  208. #define PIPE_STATE_STARTED 2 /* Pipe has been started */
  209. #define PIPE_STATE_PENDING 3 /* Pipe has pending start */
  210. /* Debug initialization */
  211. #ifdef CONFIG_SND_DEBUG
  212. #define DE_INIT(x) snd_printk x
  213. #else
  214. #define DE_INIT(x)
  215. #endif
  216. /* Debug hw_params callbacks */
  217. #ifdef CONFIG_SND_DEBUG
  218. #define DE_HWP(x) snd_printk x
  219. #else
  220. #define DE_HWP(x)
  221. #endif
  222. /* Debug normal activity (open, start, stop...) */
  223. #ifdef CONFIG_SND_DEBUG
  224. #define DE_ACT(x) snd_printk x
  225. #else
  226. #define DE_ACT(x)
  227. #endif
  228. /* Debug midi activity */
  229. #ifdef CONFIG_SND_DEBUG
  230. #define DE_MID(x) snd_printk x
  231. #else
  232. #define DE_MID(x)
  233. #endif
  234. struct audiopipe {
  235. volatile u32 *dma_counter; /* Commpage register that contains
  236. * the current dma position
  237. * (lower 32 bits only)
  238. */
  239. u32 last_counter; /* The last position, which is used
  240. * to compute...
  241. */
  242. u32 position; /* ...the number of bytes tranferred
  243. * by the DMA engine, modulo the
  244. * buffer size
  245. */
  246. short index; /* Index of the first channel or <0
  247. * if hw is not configured yet
  248. */
  249. short interleave;
  250. struct snd_dma_buffer sgpage; /* Room for the scatter-gather list */
  251. struct snd_pcm_hardware hw;
  252. struct snd_pcm_hw_constraint_list constr;
  253. short sglist_head;
  254. char state; /* pipe state */
  255. };
  256. struct audioformat {
  257. u8 interleave; /* How the data is arranged in memory:
  258. * mono = 1, stereo = 2, ...
  259. */
  260. u8 bits_per_sample; /* 8, 16, 24, 32 (24 bits left aligned) */
  261. char mono_to_stereo; /* Only used if interleave is 1 and
  262. * if this is an output pipe.
  263. */
  264. char data_are_bigendian; /* 1 = big endian, 0 = little endian */
  265. };
  266. struct echoaudio {
  267. spinlock_t lock;
  268. struct snd_pcm_substream *substream[DSP_MAXPIPES];
  269. int last_period[DSP_MAXPIPES];
  270. struct semaphore mode_mutex;
  271. u16 num_digital_modes, digital_mode_list[6];
  272. u16 num_clock_sources, clock_source_list[10];
  273. atomic_t opencount;
  274. struct snd_kcontrol *clock_src_ctl;
  275. struct snd_pcm *analog_pcm, *digital_pcm;
  276. struct snd_card *card;
  277. const char *card_name;
  278. struct pci_dev *pci;
  279. unsigned long dsp_registers_phys;
  280. struct resource *iores;
  281. struct snd_dma_buffer commpage_dma_buf;
  282. int irq;
  283. #ifdef ECHOCARD_HAS_MIDI
  284. struct snd_rawmidi *rmidi;
  285. struct snd_rawmidi_substream *midi_in, *midi_out;
  286. #endif
  287. struct timer_list timer;
  288. char tinuse; /* Timer in use */
  289. char midi_full; /* MIDI output buffer is full */
  290. char can_set_rate;
  291. char rate_set;
  292. /* This stuff is used mainly by the lowlevel code */
  293. struct comm_page *comm_page; /* Virtual address of the memory
  294. * seen by DSP
  295. */
  296. u32 pipe_alloc_mask; /* Bitmask of allocated pipes */
  297. u32 pipe_cyclic_mask; /* Bitmask of pipes with cyclic
  298. * buffers
  299. */
  300. u32 sample_rate; /* Card sample rate in Hz */
  301. u8 digital_mode; /* Current digital mode
  302. * (see DIGITAL_MODE_*)
  303. */
  304. u8 spdif_status; /* Gina20, Darla20, Darla24 - only */
  305. u8 clock_state; /* Gina20, Darla20, Darla24 - only */
  306. u8 input_clock; /* Currently selected sample clock
  307. * source
  308. */
  309. u8 output_clock; /* Layla20 only */
  310. char meters_enabled; /* VU-meters status */
  311. char asic_loaded; /* Set TRUE when ASIC loaded */
  312. char bad_board; /* Set TRUE if DSP won't load */
  313. char professional_spdif; /* 0 = consumer; 1 = professional */
  314. char non_audio_spdif; /* 3G - only */
  315. char digital_in_automute; /* Gina24, Layla24, Mona - only */
  316. char has_phantom_power;
  317. char hasnt_input_nominal_level; /* Gina3G */
  318. char phantom_power; /* Gina3G - only */
  319. char has_midi;
  320. char midi_input_enabled;
  321. #ifdef ECHOCARD_ECHO3G
  322. /* External module -dependent pipe and bus indexes */
  323. char px_digital_out, px_analog_in, px_digital_in, px_num;
  324. char bx_digital_out, bx_analog_in, bx_digital_in, bx_num;
  325. #endif
  326. char nominal_level[ECHO_MAXAUDIOPIPES]; /* True == -10dBV
  327. * False == +4dBu */
  328. s8 input_gain[ECHO_MAXAUDIOINPUTS]; /* Input level -50..+50
  329. * unit is 0.5dB */
  330. s8 output_gain[ECHO_MAXAUDIOOUTPUTS]; /* Output level -128..+6 dB
  331. * (-128=muted) */
  332. s8 monitor_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOINPUTS];
  333. /* -128..+6 dB */
  334. s8 vmixer_gain[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
  335. /* -128..+6 dB */
  336. u16 digital_modes; /* Bitmask of supported modes
  337. * (see ECHOCAPS_HAS_DIGITAL_MODE_*) */
  338. u16 input_clock_types; /* Suppoted input clock types */
  339. u16 output_clock_types; /* Suppoted output clock types -
  340. * Layla20 only */
  341. u16 device_id, subdevice_id;
  342. u16 *dsp_code; /* Current DSP code loaded,
  343. * NULL if nothing loaded */
  344. const struct firmware *dsp_code_to_load;/* DSP code to load */
  345. const struct firmware *asic_code; /* Current ASIC code */
  346. u32 comm_page_phys; /* Physical address of the
  347. * memory seen by DSP */
  348. volatile u32 __iomem *dsp_registers; /* DSP's register base */
  349. u32 active_mask; /* Chs. active mask or
  350. * punks out */
  351. #ifdef ECHOCARD_HAS_MIDI
  352. u16 mtc_state; /* State for MIDI input parsing state machine */
  353. u8 midi_buffer[MIDI_IN_BUFFER_SIZE];
  354. #endif
  355. };
  356. static int init_dsp_comm_page(struct echoaudio *chip);
  357. static int init_line_levels(struct echoaudio *chip);
  358. static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe);
  359. static int load_firmware(struct echoaudio *chip);
  360. static int wait_handshake(struct echoaudio *chip);
  361. static int send_vector(struct echoaudio *chip, u32 command);
  362. static int get_firmware(const struct firmware **fw_entry,
  363. const struct firmware *frm, struct echoaudio *chip);
  364. static void free_firmware(const struct firmware *fw_entry);
  365. #ifdef ECHOCARD_HAS_MIDI
  366. static int enable_midi_input(struct echoaudio *chip, char enable);
  367. static int midi_service_irq(struct echoaudio *chip);
  368. static int __devinit snd_echo_midi_create(struct snd_card *card,
  369. struct echoaudio *chip);
  370. #endif
  371. static inline void clear_handshake(struct echoaudio *chip)
  372. {
  373. chip->comm_page->handshake = 0;
  374. }
  375. static inline u32 get_dsp_register(struct echoaudio *chip, u32 index)
  376. {
  377. return readl(&chip->dsp_registers[index]);
  378. }
  379. static inline void set_dsp_register(struct echoaudio *chip, u32 index,
  380. u32 value)
  381. {
  382. writel(value, &chip->dsp_registers[index]);
  383. }
  384. /* Pipe and bus indexes. PX_* and BX_* are defined as chip->px_* and chip->bx_*
  385. for 3G cards because they depend on the external box. They are integer
  386. constants for all other cards.
  387. Never use those defines directly, use the following functions instead. */
  388. static inline int px_digital_out(const struct echoaudio *chip)
  389. {
  390. return PX_DIGITAL_OUT;
  391. }
  392. static inline int px_analog_in(const struct echoaudio *chip)
  393. {
  394. return PX_ANALOG_IN;
  395. }
  396. static inline int px_digital_in(const struct echoaudio *chip)
  397. {
  398. return PX_DIGITAL_IN;
  399. }
  400. static inline int px_num(const struct echoaudio *chip)
  401. {
  402. return PX_NUM;
  403. }
  404. static inline int bx_digital_out(const struct echoaudio *chip)
  405. {
  406. return BX_DIGITAL_OUT;
  407. }
  408. static inline int bx_analog_in(const struct echoaudio *chip)
  409. {
  410. return BX_ANALOG_IN;
  411. }
  412. static inline int bx_digital_in(const struct echoaudio *chip)
  413. {
  414. return BX_DIGITAL_IN;
  415. }
  416. static inline int bx_num(const struct echoaudio *chip)
  417. {
  418. return BX_NUM;
  419. }
  420. static inline int num_pipes_out(const struct echoaudio *chip)
  421. {
  422. return px_analog_in(chip);
  423. }
  424. static inline int num_pipes_in(const struct echoaudio *chip)
  425. {
  426. return px_num(chip) - px_analog_in(chip);
  427. }
  428. static inline int num_busses_out(const struct echoaudio *chip)
  429. {
  430. return bx_analog_in(chip);
  431. }
  432. static inline int num_busses_in(const struct echoaudio *chip)
  433. {
  434. return bx_num(chip) - bx_analog_in(chip);
  435. }
  436. static inline int num_analog_busses_out(const struct echoaudio *chip)
  437. {
  438. return bx_digital_out(chip);
  439. }
  440. static inline int num_analog_busses_in(const struct echoaudio *chip)
  441. {
  442. return bx_digital_in(chip) - bx_analog_in(chip);
  443. }
  444. static inline int num_digital_busses_out(const struct echoaudio *chip)
  445. {
  446. return num_busses_out(chip) - num_analog_busses_out(chip);
  447. }
  448. static inline int num_digital_busses_in(const struct echoaudio *chip)
  449. {
  450. return num_busses_in(chip) - num_analog_busses_in(chip);
  451. }
  452. /* The monitor array is a one-dimensional array; compute the offset
  453. * into the array */
  454. static inline int monitor_index(const struct echoaudio *chip, int out, int in)
  455. {
  456. return out * num_busses_in(chip) + in;
  457. }
  458. #ifndef pci_device
  459. #define pci_device(chip) (&chip->pci->dev)
  460. #endif
  461. #endif /* _ECHOAUDIO_H_ */