echoaudio.h 17 KB

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