2 * ALSA driver for RME Hammerfall DSP MADI audio interface(s)
4 * Copyright (c) 2003 Winfried Ritsch (IEM)
5 * code based on hdsp.c Paul Davis
8 * Modified 2006-06-01 for AES32 support by Remy Bruno
9 * <remy.bruno@trinnov.com>
11 * Modified 2009-04-13 for proper metering by Florian Faber
14 * Modified 2009-04-14 for native float support by Florian Faber
17 * Modified 2009-04-26 fixed bug in rms metering by Florian Faber
20 * Modified 2009-04-30 added hw serial number support by Florian Faber
22 * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth
24 * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #include <linux/init.h>
42 #include <linux/delay.h>
43 #include <linux/interrupt.h>
44 #include <linux/module.h>
45 #include <linux/slab.h>
46 #include <linux/pci.h>
47 #include <linux/math64.h>
50 #include <sound/core.h>
51 #include <sound/control.h>
52 #include <sound/pcm.h>
53 #include <sound/pcm_params.h>
54 #include <sound/info.h>
55 #include <sound/asoundef.h>
56 #include <sound/rawmidi.h>
57 #include <sound/hwdep.h>
58 #include <sound/initval.h>
60 #include <sound/hdspm.h>
62 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
63 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
64 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
66 module_param_array(index, int, NULL, 0444);
67 MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
69 module_param_array(id, charp, NULL, 0444);
70 MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
72 module_param_array(enable, bool, NULL, 0444);
73 MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
78 "Winfried Ritsch <ritsch_AT_iem.at>, "
79 "Paul Davis <paul@linuxaudiosystems.com>, "
80 "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, "
81 "Remy Bruno <remy.bruno@trinnov.com>, "
82 "Florian Faber <faberman@linuxproaudio.org>, "
83 "Adrian Knoth <adi@drcomp.erfurt.thur.de>"
85 MODULE_DESCRIPTION("RME HDSPM");
86 MODULE_LICENSE("GPL");
87 MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
89 /* --- Write registers. ---
90 These are defined as byte-offsets from the iobase value. */
92 #define HDSPM_WR_SETTINGS 0
93 #define HDSPM_outputBufferAddress 32
94 #define HDSPM_inputBufferAddress 36
95 #define HDSPM_controlRegister 64
96 #define HDSPM_interruptConfirmation 96
97 #define HDSPM_control2Reg 256 /* not in specs ???????? */
98 #define HDSPM_freqReg 256 /* for AES32 */
99 #define HDSPM_midiDataOut0 352 /* just believe in old code */
100 #define HDSPM_midiDataOut1 356
101 #define HDSPM_eeprom_wr 384 /* for AES32 */
103 /* DMA enable for 64 channels, only Bit 0 is relevant */
104 #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
105 #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
107 /* 16 page addresses for each of the 64 channels DMA buffer in and out
108 (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */
109 #define HDSPM_pageAddressBufferOut 8192
110 #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4)
112 #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */
114 #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */
116 /* --- Read registers. ---
117 These are defined as byte-offsets from the iobase value */
118 #define HDSPM_statusRegister 0
119 /*#define HDSPM_statusRegister2 96 */
120 /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at
121 * offset 192, for AES32 *and* MADI
122 * => need to check that offset 192 is working on MADI */
123 #define HDSPM_statusRegister2 192
124 #define HDSPM_timecodeRegister 128
127 #define HDSPM_RD_STATUS_0 0
128 #define HDSPM_RD_STATUS_1 64
129 #define HDSPM_RD_STATUS_2 128
130 #define HDSPM_RD_STATUS_3 192
132 #define HDSPM_RD_TCO 256
133 #define HDSPM_RD_PLL_FREQ 512
134 #define HDSPM_WR_TCO 128
136 #define HDSPM_TCO1_TCO_lock 0x00000001
137 #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002
138 #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004
139 #define HDSPM_TCO1_LTC_Input_valid 0x00000008
140 #define HDSPM_TCO1_WCK_Input_valid 0x00000010
141 #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020
142 #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040
144 #define HDSPM_TCO1_set_TC 0x00000100
145 #define HDSPM_TCO1_set_drop_frame_flag 0x00000200
146 #define HDSPM_TCO1_LTC_Format_LSB 0x00000400
147 #define HDSPM_TCO1_LTC_Format_MSB 0x00000800
149 #define HDSPM_TCO2_TC_run 0x00010000
150 #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000
151 #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000
152 #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000
153 #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000
154 #define HDSPM_TCO2_set_jam_sync 0x00200000
155 #define HDSPM_TCO2_set_flywheel 0x00400000
157 #define HDSPM_TCO2_set_01_4 0x01000000
158 #define HDSPM_TCO2_set_pull_down 0x02000000
159 #define HDSPM_TCO2_set_pull_up 0x04000000
160 #define HDSPM_TCO2_set_freq 0x08000000
161 #define HDSPM_TCO2_set_term_75R 0x10000000
162 #define HDSPM_TCO2_set_input_LSB 0x20000000
163 #define HDSPM_TCO2_set_input_MSB 0x40000000
164 #define HDSPM_TCO2_set_freq_from_app 0x80000000
167 #define HDSPM_midiDataOut0 352
168 #define HDSPM_midiDataOut1 356
169 #define HDSPM_midiDataOut2 368
171 #define HDSPM_midiDataIn0 360
172 #define HDSPM_midiDataIn1 364
173 #define HDSPM_midiDataIn2 372
174 #define HDSPM_midiDataIn3 376
176 /* status is data bytes in MIDI-FIFO (0-128) */
177 #define HDSPM_midiStatusOut0 384
178 #define HDSPM_midiStatusOut1 388
179 #define HDSPM_midiStatusOut2 400
181 #define HDSPM_midiStatusIn0 392
182 #define HDSPM_midiStatusIn1 396
183 #define HDSPM_midiStatusIn2 404
184 #define HDSPM_midiStatusIn3 408
187 /* the meters are regular i/o-mapped registers, but offset
188 considerably from the rest. the peak registers are reset
189 when read; the least-significant 4 bits are full-scale counters;
190 the actual peak value is in the most-significant 24 bits.
193 #define HDSPM_MADI_INPUT_PEAK 4096
194 #define HDSPM_MADI_PLAYBACK_PEAK 4352
195 #define HDSPM_MADI_OUTPUT_PEAK 4608
197 #define HDSPM_MADI_INPUT_RMS_L 6144
198 #define HDSPM_MADI_PLAYBACK_RMS_L 6400
199 #define HDSPM_MADI_OUTPUT_RMS_L 6656
201 #define HDSPM_MADI_INPUT_RMS_H 7168
202 #define HDSPM_MADI_PLAYBACK_RMS_H 7424
203 #define HDSPM_MADI_OUTPUT_RMS_H 7680
205 /* --- Control Register bits --------- */
206 #define HDSPM_Start (1<<0) /* start engine */
208 #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */
209 #define HDSPM_Latency1 (1<<2) /* where n is defined */
210 #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */
212 #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */
213 #define HDSPM_c0Master 0x1 /* Master clock bit in settings
214 register [RayDAT, AIO] */
216 #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */
218 #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
219 #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */
220 #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
221 #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */
223 #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */
224 #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
225 56channelMODE=0 */ /* MADI ONLY*/
226 #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */
228 #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
229 0=off, 1=on */ /* MADI ONLY */
230 #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */
232 #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax
235 #define HDSPM_InputSelect1 (1<<15) /* should be 0 */
237 #define HDSPM_SyncRef2 (1<<13)
238 #define HDSPM_SyncRef3 (1<<25)
240 #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */
241 #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
242 AES additional bits in
243 lower 5 Audiodatabits ??? */
244 #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */
245 #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */
247 #define HDSPM_Midi0InterruptEnable 0x0400000
248 #define HDSPM_Midi1InterruptEnable 0x0800000
249 #define HDSPM_Midi2InterruptEnable 0x0200000
250 #define HDSPM_Midi3InterruptEnable 0x4000000
252 #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
253 #define HDSPe_FLOAT_FORMAT 0x2000000
255 #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */
256 #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */
257 #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */
259 #define HDSPM_wclk_sel (1<<30)
261 /* additional control register bits for AIO*/
262 #define HDSPM_c0_Wck48 0x20 /* also RayDAT */
263 #define HDSPM_c0_Input0 0x1000
264 #define HDSPM_c0_Input1 0x2000
265 #define HDSPM_c0_Spdif_Opt 0x4000
266 #define HDSPM_c0_Pro 0x8000
267 #define HDSPM_c0_clr_tms 0x10000
268 #define HDSPM_c0_AEB1 0x20000
269 #define HDSPM_c0_AEB2 0x40000
270 #define HDSPM_c0_LineOut 0x80000
271 #define HDSPM_c0_AD_GAIN0 0x100000
272 #define HDSPM_c0_AD_GAIN1 0x200000
273 #define HDSPM_c0_DA_GAIN0 0x400000
274 #define HDSPM_c0_DA_GAIN1 0x800000
275 #define HDSPM_c0_PH_GAIN0 0x1000000
276 #define HDSPM_c0_PH_GAIN1 0x2000000
277 #define HDSPM_c0_Sym6db 0x4000000
280 /* --- bit helper defines */
281 #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
282 #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\
283 HDSPM_DoubleSpeed|HDSPM_QuadSpeed)
284 #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
285 #define HDSPM_InputOptical 0
286 #define HDSPM_InputCoaxial (HDSPM_InputSelect0)
287 #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\
288 HDSPM_SyncRef2|HDSPM_SyncRef3)
290 #define HDSPM_c0_SyncRef0 0x2
291 #define HDSPM_c0_SyncRef1 0x4
292 #define HDSPM_c0_SyncRef2 0x8
293 #define HDSPM_c0_SyncRef3 0x10
294 #define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\
295 HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3)
297 #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */
298 #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */
299 #define HDSPM_SYNC_FROM_TCO 2
300 #define HDSPM_SYNC_FROM_SYNC_IN 3
302 #define HDSPM_Frequency32KHz HDSPM_Frequency0
303 #define HDSPM_Frequency44_1KHz HDSPM_Frequency1
304 #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0)
305 #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0)
306 #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1)
307 #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\
309 #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0)
310 #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1)
311 #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\
315 /* Synccheck Status */
316 #define HDSPM_SYNC_CHECK_NO_LOCK 0
317 #define HDSPM_SYNC_CHECK_LOCK 1
318 #define HDSPM_SYNC_CHECK_SYNC 2
320 /* AutoSync References - used by "autosync_ref" control switch */
321 #define HDSPM_AUTOSYNC_FROM_WORD 0
322 #define HDSPM_AUTOSYNC_FROM_MADI 1
323 #define HDSPM_AUTOSYNC_FROM_TCO 2
324 #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3
325 #define HDSPM_AUTOSYNC_FROM_NONE 4
327 /* Possible sources of MADI input */
328 #define HDSPM_OPTICAL 0 /* optical */
329 #define HDSPM_COAXIAL 1 /* BNC */
331 #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
332 #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1))
334 #define hdspm_encode_in(x) (((x)&0x3)<<14)
335 #define hdspm_decode_in(x) (((x)>>14)&0x3)
337 /* --- control2 register bits --- */
338 #define HDSPM_TMS (1<<0)
339 #define HDSPM_TCK (1<<1)
340 #define HDSPM_TDI (1<<2)
341 #define HDSPM_JTAG (1<<3)
342 #define HDSPM_PWDN (1<<4)
343 #define HDSPM_PROGRAM (1<<5)
344 #define HDSPM_CONFIG_MODE_0 (1<<6)
345 #define HDSPM_CONFIG_MODE_1 (1<<7)
346 /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/
347 #define HDSPM_BIGENDIAN_MODE (1<<9)
348 #define HDSPM_RD_MULTIPLE (1<<10)
350 /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and
351 that do not conflict with specific bits for AES32 seem to be valid also
354 #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
355 #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */
356 #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1
360 #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
361 #define HDSPM_madiSync (1<<18) /* MADI is in sync */
363 #define HDSPM_tcoLockMadi 0x00000020 /* Optional TCO locked status for HDSPe MADI*/
364 #define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status for HDSPe MADI and AES32!*/
366 #define HDSPM_syncInLock 0x00010000 /* Sync In lock status for HDSPe MADI! */
367 #define HDSPM_syncInSync 0x00020000 /* Sync In sync status for HDSPe MADI! */
369 #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
370 /* since 64byte accurate, last 6 bits are not used */
374 #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
376 #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */
377 #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */
378 #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */
379 #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */
381 #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with
384 #define HDSPM_tco_detect 0x08000000
385 #define HDSPM_tcoLockAes 0x20000000 /* Optional TCO locked status for HDSPe AES */
387 #define HDSPM_s2_tco_detect 0x00000040
388 #define HDSPM_s2_AEBO_D 0x00000080
389 #define HDSPM_s2_AEBI_D 0x00000100
392 #define HDSPM_midi0IRQPending 0x40000000
393 #define HDSPM_midi1IRQPending 0x80000000
394 #define HDSPM_midi2IRQPending 0x20000000
395 #define HDSPM_midi2IRQPendingAES 0x00000020
396 #define HDSPM_midi3IRQPending 0x00200000
398 /* --- status bit helpers */
399 #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\
400 HDSPM_madiFreq2|HDSPM_madiFreq3)
401 #define HDSPM_madiFreq32 (HDSPM_madiFreq0)
402 #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1)
403 #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1)
404 #define HDSPM_madiFreq64 (HDSPM_madiFreq2)
405 #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2)
406 #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2)
407 #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2)
408 #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3)
409 #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0)
411 /* Status2 Register bits */ /* MADI ONLY */
413 #define HDSPM_version0 (1<<0) /* not really defined but I guess */
414 #define HDSPM_version1 (1<<1) /* in former cards it was ??? */
415 #define HDSPM_version2 (1<<2)
417 #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
418 #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
420 #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */
421 #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */
422 #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, 111=128 */
423 #define HDSPM_wc_freq3 0x800 /* 1000=176.4, 1001=192 */
425 #define HDSPM_SyncRef0 0x10000 /* Sync Reference */
426 #define HDSPM_SyncRef1 0x20000
428 #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */
429 #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
430 #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
432 #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
434 #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\
436 #define HDSPM_wcFreq32 (HDSPM_wc_freq0)
437 #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1)
438 #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1)
439 #define HDSPM_wcFreq64 (HDSPM_wc_freq2)
440 #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2)
441 #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2)
442 #define HDSPM_wcFreq128 (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2)
443 #define HDSPM_wcFreq176_4 (HDSPM_wc_freq3)
444 #define HDSPM_wcFreq192 (HDSPM_wc_freq0|HDSPM_wc_freq3)
446 #define HDSPM_status1_F_0 0x0400000
447 #define HDSPM_status1_F_1 0x0800000
448 #define HDSPM_status1_F_2 0x1000000
449 #define HDSPM_status1_F_3 0x2000000
450 #define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3)
453 #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
455 #define HDSPM_SelSyncRef_WORD 0
456 #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
457 #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1)
458 #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1)
459 #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
463 For AES32, bits for status, status2 and timecode are different
466 #define HDSPM_AES32_wcLock 0x0200000
467 #define HDSPM_AES32_wcSync 0x0100000
468 #define HDSPM_AES32_wcFreq_bit 22
469 /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function
471 #define HDSPM_AES32_syncref_bit 16
472 /* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */
474 #define HDSPM_AES32_AUTOSYNC_FROM_WORD 0
475 #define HDSPM_AES32_AUTOSYNC_FROM_AES1 1
476 #define HDSPM_AES32_AUTOSYNC_FROM_AES2 2
477 #define HDSPM_AES32_AUTOSYNC_FROM_AES3 3
478 #define HDSPM_AES32_AUTOSYNC_FROM_AES4 4
479 #define HDSPM_AES32_AUTOSYNC_FROM_AES5 5
480 #define HDSPM_AES32_AUTOSYNC_FROM_AES6 6
481 #define HDSPM_AES32_AUTOSYNC_FROM_AES7 7
482 #define HDSPM_AES32_AUTOSYNC_FROM_AES8 8
483 #define HDSPM_AES32_AUTOSYNC_FROM_TCO 9
484 #define HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN 10
485 #define HDSPM_AES32_AUTOSYNC_FROM_NONE 11
488 /* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */
489 #define HDSPM_LockAES 0x80
490 #define HDSPM_LockAES1 0x80
491 #define HDSPM_LockAES2 0x40
492 #define HDSPM_LockAES3 0x20
493 #define HDSPM_LockAES4 0x10
494 #define HDSPM_LockAES5 0x8
495 #define HDSPM_LockAES6 0x4
496 #define HDSPM_LockAES7 0x2
497 #define HDSPM_LockAES8 0x1
500 After windows driver sources, bits 4*i to 4*i+3 give the input frequency on
512 NB: Timecode register doesn't seem to work on AES32 card revision 230
516 #define UNITY_GAIN 32768 /* = 65536/2 */
517 #define MINUS_INFINITY_GAIN 0
519 /* Number of channels for different Speed Modes */
520 #define MADI_SS_CHANNELS 64
521 #define MADI_DS_CHANNELS 32
522 #define MADI_QS_CHANNELS 16
524 #define RAYDAT_SS_CHANNELS 36
525 #define RAYDAT_DS_CHANNELS 20
526 #define RAYDAT_QS_CHANNELS 12
528 #define AIO_IN_SS_CHANNELS 14
529 #define AIO_IN_DS_CHANNELS 10
530 #define AIO_IN_QS_CHANNELS 8
531 #define AIO_OUT_SS_CHANNELS 16
532 #define AIO_OUT_DS_CHANNELS 12
533 #define AIO_OUT_QS_CHANNELS 10
535 #define AES32_CHANNELS 16
537 /* the size of a substream (1 mono data stream) */
538 #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024)
539 #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES)
541 /* the size of the area we need to allocate for DMA transfers. the
542 size is the same regardless of the number of channels, and
543 also the latency to use.
544 for one direction !!!
546 #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
547 #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
549 #define HDSPM_RAYDAT_REV 211
550 #define HDSPM_AIO_REV 212
551 #define HDSPM_MADIFACE_REV 213
553 /* speed factor modes */
554 #define HDSPM_SPEED_SINGLE 0
555 #define HDSPM_SPEED_DOUBLE 1
556 #define HDSPM_SPEED_QUAD 2
558 /* names for speed modes */
559 static char *hdspm_speed_names[] = { "single", "double", "quad" };
561 static char *texts_autosync_aes_tco[] = { "Word Clock",
562 "AES1", "AES2", "AES3", "AES4",
563 "AES5", "AES6", "AES7", "AES8",
566 static char *texts_autosync_aes[] = { "Word Clock",
567 "AES1", "AES2", "AES3", "AES4",
568 "AES5", "AES6", "AES7", "AES8",
571 static char *texts_autosync_madi_tco[] = { "Word Clock",
572 "MADI", "TCO", "Sync In" };
573 static char *texts_autosync_madi[] = { "Word Clock",
576 static char *texts_autosync_raydat_tco[] = {
578 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
579 "AES", "SPDIF", "TCO", "Sync In"
581 static char *texts_autosync_raydat[] = {
583 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
584 "AES", "SPDIF", "Sync In"
586 static char *texts_autosync_aio_tco[] = {
588 "ADAT", "AES", "SPDIF", "TCO", "Sync In"
590 static char *texts_autosync_aio[] = { "Word Clock",
591 "ADAT", "AES", "SPDIF", "Sync In" };
593 static char *texts_freq[] = {
606 static char *texts_ports_madi[] = {
607 "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6",
608 "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12",
609 "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18",
610 "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24",
611 "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30",
612 "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36",
613 "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42",
614 "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48",
615 "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54",
616 "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60",
617 "MADI.61", "MADI.62", "MADI.63", "MADI.64",
621 static char *texts_ports_raydat_ss[] = {
622 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6",
623 "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
624 "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2",
625 "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8",
626 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6",
627 "ADAT4.7", "ADAT4.8",
632 static char *texts_ports_raydat_ds[] = {
633 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4",
634 "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
635 "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4",
636 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4",
641 static char *texts_ports_raydat_qs[] = {
642 "ADAT1.1", "ADAT1.2",
643 "ADAT2.1", "ADAT2.2",
644 "ADAT3.1", "ADAT3.2",
645 "ADAT4.1", "ADAT4.2",
651 static char *texts_ports_aio_in_ss[] = {
652 "Analogue.L", "Analogue.R",
654 "SPDIF.L", "SPDIF.R",
655 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
657 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
660 static char *texts_ports_aio_out_ss[] = {
661 "Analogue.L", "Analogue.R",
663 "SPDIF.L", "SPDIF.R",
664 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
666 "Phone.L", "Phone.R",
667 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
670 static char *texts_ports_aio_in_ds[] = {
671 "Analogue.L", "Analogue.R",
673 "SPDIF.L", "SPDIF.R",
674 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
675 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
678 static char *texts_ports_aio_out_ds[] = {
679 "Analogue.L", "Analogue.R",
681 "SPDIF.L", "SPDIF.R",
682 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
683 "Phone.L", "Phone.R",
684 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
687 static char *texts_ports_aio_in_qs[] = {
688 "Analogue.L", "Analogue.R",
690 "SPDIF.L", "SPDIF.R",
691 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
692 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
695 static char *texts_ports_aio_out_qs[] = {
696 "Analogue.L", "Analogue.R",
698 "SPDIF.L", "SPDIF.R",
699 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
700 "Phone.L", "Phone.R",
701 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
704 static char *texts_ports_aes32[] = {
705 "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7",
706 "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14",
710 /* These tables map the ALSA channels 1..N to the channels that we
711 need to use in order to find the relevant channel buffer. RME
712 refers to this kind of mapping as between "the ADAT channel and
713 the DMA channel." We index it using the logical audio channel,
714 and the value is the DMA channel (i.e. channel buffer number)
715 where the data for that channel can be read/written from/to.
718 static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = {
719 0, 1, 2, 3, 4, 5, 6, 7,
720 8, 9, 10, 11, 12, 13, 14, 15,
721 16, 17, 18, 19, 20, 21, 22, 23,
722 24, 25, 26, 27, 28, 29, 30, 31,
723 32, 33, 34, 35, 36, 37, 38, 39,
724 40, 41, 42, 43, 44, 45, 46, 47,
725 48, 49, 50, 51, 52, 53, 54, 55,
726 56, 57, 58, 59, 60, 61, 62, 63
729 static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = {
730 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */
731 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */
732 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */
733 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */
737 -1, -1, -1, -1, -1, -1, -1, -1,
738 -1, -1, -1, -1, -1, -1, -1, -1,
739 -1, -1, -1, -1, -1, -1, -1, -1,
742 static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = {
743 4, 5, 6, 7, /* ADAT 1 */
744 8, 9, 10, 11, /* ADAT 2 */
745 12, 13, 14, 15, /* ADAT 3 */
746 16, 17, 18, 19, /* ADAT 4 */
750 -1, -1, -1, -1, -1, -1, -1, -1,
751 -1, -1, -1, -1, -1, -1, -1, -1,
752 -1, -1, -1, -1, -1, -1, -1, -1,
753 -1, -1, -1, -1, -1, -1, -1, -1,
754 -1, -1, -1, -1, -1, -1, -1, -1,
757 static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = {
765 -1, -1, -1, -1, -1, -1, -1, -1,
766 -1, -1, -1, -1, -1, -1, -1, -1,
767 -1, -1, -1, -1, -1, -1, -1, -1,
768 -1, -1, -1, -1, -1, -1, -1, -1,
769 -1, -1, -1, -1, -1, -1, -1, -1,
770 -1, -1, -1, -1, -1, -1, -1, -1,
773 static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = {
776 10, 11, /* spdif in */
777 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */
778 2, 3, 4, 5, /* AEB */
779 -1, -1, -1, -1, -1, -1,
780 -1, -1, -1, -1, -1, -1, -1, -1,
781 -1, -1, -1, -1, -1, -1, -1, -1,
782 -1, -1, -1, -1, -1, -1, -1, -1,
783 -1, -1, -1, -1, -1, -1, -1, -1,
784 -1, -1, -1, -1, -1, -1, -1, -1,
787 static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = {
790 10, 11, /* spdif out */
791 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */
792 6, 7, /* phone out */
793 2, 3, 4, 5, /* AEB */
795 -1, -1, -1, -1, -1, -1, -1, -1,
796 -1, -1, -1, -1, -1, -1, -1, -1,
797 -1, -1, -1, -1, -1, -1, -1, -1,
798 -1, -1, -1, -1, -1, -1, -1, -1,
799 -1, -1, -1, -1, -1, -1, -1, -1,
802 static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = {
805 10, 11, /* spdif in */
806 12, 14, 16, 18, /* adat in */
807 2, 3, 4, 5, /* AEB */
809 -1, -1, -1, -1, -1, -1, -1, -1,
810 -1, -1, -1, -1, -1, -1, -1, -1,
811 -1, -1, -1, -1, -1, -1, -1, -1,
812 -1, -1, -1, -1, -1, -1, -1, -1,
813 -1, -1, -1, -1, -1, -1, -1, -1,
814 -1, -1, -1, -1, -1, -1, -1, -1
817 static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = {
820 10, 11, /* spdif out */
821 12, 14, 16, 18, /* adat out */
822 6, 7, /* phone out */
823 2, 3, 4, 5, /* AEB */
824 -1, -1, -1, -1, -1, -1, -1, -1,
825 -1, -1, -1, -1, -1, -1, -1, -1,
826 -1, -1, -1, -1, -1, -1, -1, -1,
827 -1, -1, -1, -1, -1, -1, -1, -1,
828 -1, -1, -1, -1, -1, -1, -1, -1,
829 -1, -1, -1, -1, -1, -1, -1, -1
832 static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = {
835 10, 11, /* spdif in */
836 12, 16, /* adat in */
837 2, 3, 4, 5, /* AEB */
839 -1, -1, -1, -1, -1, -1, -1, -1,
840 -1, -1, -1, -1, -1, -1, -1, -1,
841 -1, -1, -1, -1, -1, -1, -1, -1,
842 -1, -1, -1, -1, -1, -1, -1, -1,
843 -1, -1, -1, -1, -1, -1, -1, -1,
844 -1, -1, -1, -1, -1, -1, -1, -1
847 static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = {
850 10, 11, /* spdif out */
851 12, 16, /* adat out */
852 6, 7, /* phone out */
853 2, 3, 4, 5, /* AEB */
855 -1, -1, -1, -1, -1, -1, -1, -1,
856 -1, -1, -1, -1, -1, -1, -1, -1,
857 -1, -1, -1, -1, -1, -1, -1, -1,
858 -1, -1, -1, -1, -1, -1, -1, -1,
859 -1, -1, -1, -1, -1, -1, -1, -1,
860 -1, -1, -1, -1, -1, -1, -1, -1
863 static char channel_map_aes32[HDSPM_MAX_CHANNELS] = {
864 0, 1, 2, 3, 4, 5, 6, 7,
865 8, 9, 10, 11, 12, 13, 14, 15,
866 -1, -1, -1, -1, -1, -1, -1, -1,
867 -1, -1, -1, -1, -1, -1, -1, -1,
868 -1, -1, -1, -1, -1, -1, -1, -1,
869 -1, -1, -1, -1, -1, -1, -1, -1,
870 -1, -1, -1, -1, -1, -1, -1, -1,
871 -1, -1, -1, -1, -1, -1, -1, -1
877 struct snd_rawmidi *rmidi;
878 struct snd_rawmidi_substream *input;
879 struct snd_rawmidi_substream *output;
880 char istimer; /* timer in use */
881 struct timer_list timer;
898 int term; /* 0 = off, 1 = on */
903 /* only one playback and/or capture stream */
904 struct snd_pcm_substream *capture_substream;
905 struct snd_pcm_substream *playback_substream;
907 char *card_name; /* for procinfo */
908 unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/
912 int monitor_outs; /* set up monitoring outs init flag */
914 u32 control_register; /* cached value */
915 u32 control2_register; /* cached value */
916 u32 settings_register;
918 struct hdspm_midi midi[4];
919 struct tasklet_struct midi_tasklet;
922 unsigned char ss_in_channels;
923 unsigned char ds_in_channels;
924 unsigned char qs_in_channels;
925 unsigned char ss_out_channels;
926 unsigned char ds_out_channels;
927 unsigned char qs_out_channels;
929 unsigned char max_channels_in;
930 unsigned char max_channels_out;
932 signed char *channel_map_in;
933 signed char *channel_map_out;
935 signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs;
936 signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs;
938 char **port_names_in;
939 char **port_names_out;
941 char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs;
942 char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs;
944 unsigned char *playback_buffer; /* suitably aligned address */
945 unsigned char *capture_buffer; /* suitably aligned address */
947 pid_t capture_pid; /* process id which uses capture */
948 pid_t playback_pid; /* process id which uses capture */
949 int running; /* running status */
951 int last_external_sample_rate; /* samplerate mystic ... */
952 int last_internal_sample_rate;
953 int system_sample_rate;
955 int dev; /* Hardware vars... */
958 void __iomem *iobase;
960 int irq_count; /* for debug */
963 struct snd_card *card; /* one card */
964 struct snd_pcm *pcm; /* has one pcm */
965 struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */
966 struct pci_dev *pci; /* and an pci info */
969 /* fast alsa mixer */
970 struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS];
971 /* but input to much, so not used */
972 struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS];
973 /* full mixer accessible over mixer ioctl or hwdep-device */
974 struct hdspm_mixer *mixer;
976 struct hdspm_tco *tco; /* NULL if no TCO detected */
978 char **texts_autosync;
979 int texts_autosync_items;
981 cycles_t last_interrupt;
985 struct hdspm_peak_rms peak_rms;
989 static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = {
991 .vendor = PCI_VENDOR_ID_XILINX,
992 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
993 .subvendor = PCI_ANY_ID,
994 .subdevice = PCI_ANY_ID,
1001 MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
1004 static int snd_hdspm_create_alsa_devices(struct snd_card *card,
1005 struct hdspm *hdspm);
1006 static int snd_hdspm_create_pcm(struct snd_card *card,
1007 struct hdspm *hdspm);
1009 static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
1010 static inline int hdspm_get_pll_freq(struct hdspm *hdspm);
1011 static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
1012 static int hdspm_autosync_ref(struct hdspm *hdspm);
1013 static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out);
1014 static int snd_hdspm_set_defaults(struct hdspm *hdspm);
1015 static int hdspm_system_clock_mode(struct hdspm *hdspm);
1016 static void hdspm_set_sgbuf(struct hdspm *hdspm,
1017 struct snd_pcm_substream *substream,
1018 unsigned int reg, int channels);
1020 static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx);
1021 static int hdspm_wc_sync_check(struct hdspm *hdspm);
1022 static int hdspm_tco_sync_check(struct hdspm *hdspm);
1023 static int hdspm_sync_in_sync_check(struct hdspm *hdspm);
1025 static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index);
1026 static int hdspm_get_tco_sample_rate(struct hdspm *hdspm);
1027 static int hdspm_get_wc_sample_rate(struct hdspm *hdspm);
1031 static inline int HDSPM_bit2freq(int n)
1033 static const int bit2freq_tab[] = {
1034 0, 32000, 44100, 48000, 64000, 88200,
1035 96000, 128000, 176400, 192000 };
1038 return bit2freq_tab[n];
1041 static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm)
1043 return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type));
1047 /* Write/read to/from HDSPM with Adresses in Bytes
1048 not words but only 32Bit writes are allowed */
1050 static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
1053 writel(val, hdspm->iobase + reg);
1056 static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
1058 return readl(hdspm->iobase + reg);
1061 /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader
1062 mixer is write only on hardware so we have to cache him for read
1063 each fader is a u32, but uses only the first 16 bit */
1065 static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
1068 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
1071 return hdspm->mixer->ch[chan].in[in];
1074 static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
1077 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
1079 return hdspm->mixer->ch[chan].pb[pb];
1082 static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
1083 unsigned int in, unsigned short data)
1085 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
1089 HDSPM_MADI_mixerBase +
1090 ((in + 128 * chan) * sizeof(u32)),
1091 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
1095 static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
1096 unsigned int pb, unsigned short data)
1098 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
1102 HDSPM_MADI_mixerBase +
1103 ((64 + pb + 128 * chan) * sizeof(u32)),
1104 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
1109 /* enable DMA for specific channels, now available for DSP-MADI */
1110 static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
1112 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
1115 static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
1117 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
1120 /* check if same process is writing and reading */
1121 static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
1123 unsigned long flags;
1126 spin_lock_irqsave(&hdspm->lock, flags);
1127 if ((hdspm->playback_pid != hdspm->capture_pid) &&
1128 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
1131 spin_unlock_irqrestore(&hdspm->lock, flags);
1135 /* round arbitary sample rates to commonly known rates */
1136 static int hdspm_round_frequency(int rate)
1146 /* QS and DS rates normally can not be detected
1147 * automatically by the card. Only exception is MADI
1148 * in 96k frame mode.
1150 * So if we read SS values (32 .. 48k), check for
1151 * user-provided DS/QS bits in the control register
1152 * and multiply the base frequency accordingly.
1154 static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate)
1156 if (rate <= 48000) {
1157 if (hdspm->control_register & HDSPM_QuadSpeed)
1159 else if (hdspm->control_register &
1166 /* check for external sample rate, returns the sample rate in Hz*/
1167 static int hdspm_external_sample_rate(struct hdspm *hdspm)
1169 unsigned int status, status2, timecode;
1170 int syncref, rate = 0, rate_bits;
1172 switch (hdspm->io_type) {
1174 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1175 status = hdspm_read(hdspm, HDSPM_statusRegister);
1176 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
1178 syncref = hdspm_autosync_ref(hdspm);
1180 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
1181 /* Check WC sync and get sample rate */
1182 if (hdspm_wc_sync_check(hdspm))
1183 return HDSPM_bit2freq(hdspm_get_wc_sample_rate(hdspm));
1186 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
1187 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
1188 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
1189 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
1190 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
1191 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
1192 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
1193 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
1194 /* Check AES sync and get sample rate */
1195 if (hdspm_aes_sync_check(hdspm, syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))
1196 return HDSPM_bit2freq(hdspm_get_aes_sample_rate(hdspm,
1197 syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1));
1201 case HDSPM_AES32_AUTOSYNC_FROM_TCO:
1202 /* Check TCO sync and get sample rate */
1203 if (hdspm_tco_sync_check(hdspm))
1204 return HDSPM_bit2freq(hdspm_get_tco_sample_rate(hdspm));
1208 } /* end switch(syncref) */
1212 status = hdspm_read(hdspm, HDSPM_statusRegister);
1214 if (!(status & HDSPM_madiLock)) {
1215 rate = 0; /* no lock */
1217 switch (status & (HDSPM_status1_freqMask)) {
1218 case HDSPM_status1_F_0*1:
1219 rate = 32000; break;
1220 case HDSPM_status1_F_0*2:
1221 rate = 44100; break;
1222 case HDSPM_status1_F_0*3:
1223 rate = 48000; break;
1224 case HDSPM_status1_F_0*4:
1225 rate = 64000; break;
1226 case HDSPM_status1_F_0*5:
1227 rate = 88200; break;
1228 case HDSPM_status1_F_0*6:
1229 rate = 96000; break;
1230 case HDSPM_status1_F_0*7:
1231 rate = 128000; break;
1232 case HDSPM_status1_F_0*8:
1233 rate = 176400; break;
1234 case HDSPM_status1_F_0*9:
1235 rate = 192000; break;
1246 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1247 status = hdspm_read(hdspm, HDSPM_statusRegister);
1250 /* if wordclock has synced freq and wordclock is valid */
1251 if ((status2 & HDSPM_wcLock) != 0 &&
1252 (status2 & HDSPM_SelSyncRef0) == 0) {
1254 rate_bits = status2 & HDSPM_wcFreqMask;
1257 switch (rate_bits) {
1258 case HDSPM_wcFreq32:
1261 case HDSPM_wcFreq44_1:
1264 case HDSPM_wcFreq48:
1267 case HDSPM_wcFreq64:
1270 case HDSPM_wcFreq88_2:
1273 case HDSPM_wcFreq96:
1276 case HDSPM_wcFreq128:
1279 case HDSPM_wcFreq176_4:
1282 case HDSPM_wcFreq192:
1291 /* if rate detected and Syncref is Word than have it,
1292 * word has priority to MADI
1295 (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
1296 return hdspm_rate_multiplier(hdspm, rate);
1298 /* maybe a madi input (which is taken if sel sync is madi) */
1299 if (status & HDSPM_madiLock) {
1300 rate_bits = status & HDSPM_madiFreqMask;
1302 switch (rate_bits) {
1303 case HDSPM_madiFreq32:
1306 case HDSPM_madiFreq44_1:
1309 case HDSPM_madiFreq48:
1312 case HDSPM_madiFreq64:
1315 case HDSPM_madiFreq88_2:
1318 case HDSPM_madiFreq96:
1321 case HDSPM_madiFreq128:
1324 case HDSPM_madiFreq176_4:
1327 case HDSPM_madiFreq192:
1335 } /* endif HDSPM_madiLock */
1337 /* check sample rate from TCO or SYNC_IN */
1339 bool is_valid_input = 0;
1342 syncref = hdspm_autosync_ref(hdspm);
1343 if (HDSPM_AUTOSYNC_FROM_TCO == syncref) {
1345 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1346 hdspm_tco_sync_check(hdspm));
1347 } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) {
1349 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1350 hdspm_sync_in_sync_check(hdspm));
1353 if (is_valid_input && has_sync) {
1354 rate = hdspm_round_frequency(
1355 hdspm_get_pll_freq(hdspm));
1359 rate = hdspm_rate_multiplier(hdspm, rate);
1367 /* return latency in samples per period */
1368 static int hdspm_get_latency(struct hdspm *hdspm)
1372 n = hdspm_decode_latency(hdspm->control_register);
1374 /* Special case for new RME cards with 32 samples period size.
1375 * The three latency bits in the control register
1376 * (HDSP_LatencyMask) encode latency values of 64 samples as
1377 * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
1378 * denotes 8192 samples, but on new cards like RayDAT or AIO,
1379 * it corresponds to 32 samples.
1381 if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
1384 return 1 << (n + 6);
1387 /* Latency function */
1388 static inline void hdspm_compute_period_size(struct hdspm *hdspm)
1390 hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
1394 static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm)
1398 position = hdspm_read(hdspm, HDSPM_statusRegister);
1400 switch (hdspm->io_type) {
1403 position &= HDSPM_BufferPositionMask;
1404 position /= 4; /* Bytes per sample */
1407 position = (position & HDSPM_BufferID) ?
1408 (hdspm->period_bytes / 4) : 0;
1415 static inline void hdspm_start_audio(struct hdspm * s)
1417 s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
1418 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1421 static inline void hdspm_stop_audio(struct hdspm * s)
1423 s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
1424 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1427 /* should I silence all or only opened ones ? doit all for first even is 4MB*/
1428 static void hdspm_silence_playback(struct hdspm *hdspm)
1431 int n = hdspm->period_bytes;
1432 void *buf = hdspm->playback_buffer;
1437 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
1439 buf += HDSPM_CHANNEL_BUFFER_BYTES;
1443 static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
1447 spin_lock_irq(&s->lock);
1450 /* Special case for new RME cards like RayDAT/AIO which
1451 * support period sizes of 32 samples. Since latency is
1452 * encoded in the three bits of HDSP_LatencyMask, we can only
1453 * have values from 0 .. 7. While 0 still means 64 samples and
1454 * 6 represents 4096 samples on all cards, 7 represents 8192
1455 * on older cards and 32 samples on new cards.
1457 * In other words, period size in samples is calculated by
1458 * 2^(n+6) with n ranging from 0 .. 7.
1470 s->control_register &= ~HDSPM_LatencyMask;
1471 s->control_register |= hdspm_encode_latency(n);
1473 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1475 hdspm_compute_period_size(s);
1477 spin_unlock_irq(&s->lock);
1482 static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
1489 switch (hdspm->io_type) {
1492 freq_const = 110069313433624ULL;
1496 freq_const = 104857600000000ULL;
1499 freq_const = 131072000000000ULL;
1506 return div_u64(freq_const, period);
1510 static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
1516 else if (rate >= 56000)
1519 switch (hdspm->io_type) {
1521 n = 131072000000000ULL; /* 125 MHz */
1525 n = 110069313433624ULL; /* 105 MHz */
1529 n = 104857600000000ULL; /* 100 MHz */
1536 n = div_u64(n, rate);
1537 /* n should be less than 2^32 for being written to FREQ register */
1538 snd_BUG_ON(n >> 32);
1539 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
1542 /* dummy set rate lets see what happens */
1543 static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
1548 int current_speed, target_speed;
1550 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
1551 it (e.g. during module initialization).
1554 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
1557 if (called_internally) {
1559 /* request from ctl or card initialization
1560 just make a warning an remember setting
1561 for future master mode switching */
1563 snd_printk(KERN_WARNING "HDSPM: "
1564 "Warning: device is not running "
1565 "as a clock master.\n");
1569 /* hw_param request while in AutoSync mode */
1571 hdspm_external_sample_rate(hdspm);
1573 if (hdspm_autosync_ref(hdspm) ==
1574 HDSPM_AUTOSYNC_FROM_NONE) {
1576 snd_printk(KERN_WARNING "HDSPM: "
1577 "Detected no Externel Sync \n");
1580 } else if (rate != external_freq) {
1582 snd_printk(KERN_WARNING "HDSPM: "
1583 "Warning: No AutoSync source for "
1584 "requested rate\n");
1590 current_rate = hdspm->system_sample_rate;
1592 /* Changing between Singe, Double and Quad speed is not
1593 allowed if any substreams are open. This is because such a change
1594 causes a shift in the location of the DMA buffers and a reduction
1595 in the number of available buffers.
1597 Note that a similar but essentially insoluble problem exists for
1598 externally-driven rate changes. All we can do is to flag rate
1599 changes in the read/write routines.
1602 if (current_rate <= 48000)
1603 current_speed = HDSPM_SPEED_SINGLE;
1604 else if (current_rate <= 96000)
1605 current_speed = HDSPM_SPEED_DOUBLE;
1607 current_speed = HDSPM_SPEED_QUAD;
1610 target_speed = HDSPM_SPEED_SINGLE;
1611 else if (rate <= 96000)
1612 target_speed = HDSPM_SPEED_DOUBLE;
1614 target_speed = HDSPM_SPEED_QUAD;
1618 rate_bits = HDSPM_Frequency32KHz;
1621 rate_bits = HDSPM_Frequency44_1KHz;
1624 rate_bits = HDSPM_Frequency48KHz;
1627 rate_bits = HDSPM_Frequency64KHz;
1630 rate_bits = HDSPM_Frequency88_2KHz;
1633 rate_bits = HDSPM_Frequency96KHz;
1636 rate_bits = HDSPM_Frequency128KHz;
1639 rate_bits = HDSPM_Frequency176_4KHz;
1642 rate_bits = HDSPM_Frequency192KHz;
1648 if (current_speed != target_speed
1649 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
1652 "cannot change from %s speed to %s speed mode "
1653 "(capture PID = %d, playback PID = %d)\n",
1654 hdspm_speed_names[current_speed],
1655 hdspm_speed_names[target_speed],
1656 hdspm->capture_pid, hdspm->playback_pid);
1660 hdspm->control_register &= ~HDSPM_FrequencyMask;
1661 hdspm->control_register |= rate_bits;
1662 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1664 /* For AES32, need to set DDS value in FREQ register
1665 For MADI, also apparently */
1666 hdspm_set_dds_value(hdspm, rate);
1668 if (AES32 == hdspm->io_type && rate != current_rate)
1669 hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
1671 hdspm->system_sample_rate = rate;
1673 if (rate <= 48000) {
1674 hdspm->channel_map_in = hdspm->channel_map_in_ss;
1675 hdspm->channel_map_out = hdspm->channel_map_out_ss;
1676 hdspm->max_channels_in = hdspm->ss_in_channels;
1677 hdspm->max_channels_out = hdspm->ss_out_channels;
1678 hdspm->port_names_in = hdspm->port_names_in_ss;
1679 hdspm->port_names_out = hdspm->port_names_out_ss;
1680 } else if (rate <= 96000) {
1681 hdspm->channel_map_in = hdspm->channel_map_in_ds;
1682 hdspm->channel_map_out = hdspm->channel_map_out_ds;
1683 hdspm->max_channels_in = hdspm->ds_in_channels;
1684 hdspm->max_channels_out = hdspm->ds_out_channels;
1685 hdspm->port_names_in = hdspm->port_names_in_ds;
1686 hdspm->port_names_out = hdspm->port_names_out_ds;
1688 hdspm->channel_map_in = hdspm->channel_map_in_qs;
1689 hdspm->channel_map_out = hdspm->channel_map_out_qs;
1690 hdspm->max_channels_in = hdspm->qs_in_channels;
1691 hdspm->max_channels_out = hdspm->qs_out_channels;
1692 hdspm->port_names_in = hdspm->port_names_in_qs;
1693 hdspm->port_names_out = hdspm->port_names_out_qs;
1702 /* mainly for init to 0 on load */
1703 static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
1708 if (sgain > UNITY_GAIN)
1715 for (i = 0; i < HDSPM_MIXER_CHANNELS; i++)
1716 for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) {
1717 hdspm_write_in_gain(hdspm, i, j, gain);
1718 hdspm_write_pb_gain(hdspm, i, j, gain);
1722 /*----------------------------------------------------------------------------
1724 ----------------------------------------------------------------------------*/
1726 static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm,
1729 /* the hardware already does the relevant bit-mask with 0xff */
1730 return hdspm_read(hdspm, hdspm->midi[id].dataIn);
1733 static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1736 /* the hardware already does the relevant bit-mask with 0xff */
1737 return hdspm_write(hdspm, hdspm->midi[id].dataOut, val);
1740 static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
1742 return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF;
1745 static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
1747 int fifo_bytes_used;
1749 fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF;
1751 if (fifo_bytes_used < 128)
1752 return 128 - fifo_bytes_used;
1757 static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
1759 while (snd_hdspm_midi_input_available (hdspm, id))
1760 snd_hdspm_midi_read_byte (hdspm, id);
1763 static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)
1765 unsigned long flags;
1769 unsigned char buf[128];
1771 /* Output is not interrupt driven */
1773 spin_lock_irqsave (&hmidi->lock, flags);
1774 if (hmidi->output &&
1775 !snd_rawmidi_transmit_empty (hmidi->output)) {
1776 n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
1778 if (n_pending > 0) {
1779 if (n_pending > (int)sizeof (buf))
1780 n_pending = sizeof (buf);
1782 to_write = snd_rawmidi_transmit (hmidi->output, buf,
1785 for (i = 0; i < to_write; ++i)
1786 snd_hdspm_midi_write_byte (hmidi->hdspm,
1792 spin_unlock_irqrestore (&hmidi->lock, flags);
1796 static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)
1798 unsigned char buf[128]; /* this buffer is designed to match the MIDI
1801 unsigned long flags;
1805 spin_lock_irqsave (&hmidi->lock, flags);
1806 n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
1807 if (n_pending > 0) {
1809 if (n_pending > (int)sizeof (buf))
1810 n_pending = sizeof (buf);
1811 for (i = 0; i < n_pending; ++i)
1812 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm,
1815 snd_rawmidi_receive (hmidi->input, buf,
1818 /* flush the MIDI input FIFO */
1820 snd_hdspm_midi_read_byte (hmidi->hdspm,
1825 spin_unlock_irqrestore(&hmidi->lock, flags);
1827 spin_lock_irqsave(&hmidi->hdspm->lock, flags);
1828 hmidi->hdspm->control_register |= hmidi->ie;
1829 hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
1830 hmidi->hdspm->control_register);
1831 spin_unlock_irqrestore(&hmidi->hdspm->lock, flags);
1833 return snd_hdspm_midi_output_write (hmidi);
1837 snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1839 struct hdspm *hdspm;
1840 struct hdspm_midi *hmidi;
1841 unsigned long flags;
1843 hmidi = substream->rmidi->private_data;
1844 hdspm = hmidi->hdspm;
1846 spin_lock_irqsave (&hdspm->lock, flags);
1848 if (!(hdspm->control_register & hmidi->ie)) {
1849 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
1850 hdspm->control_register |= hmidi->ie;
1853 hdspm->control_register &= ~hmidi->ie;
1856 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1857 spin_unlock_irqrestore (&hdspm->lock, flags);
1860 static void snd_hdspm_midi_output_timer(unsigned long data)
1862 struct hdspm_midi *hmidi = (struct hdspm_midi *) data;
1863 unsigned long flags;
1865 snd_hdspm_midi_output_write(hmidi);
1866 spin_lock_irqsave (&hmidi->lock, flags);
1868 /* this does not bump hmidi->istimer, because the
1869 kernel automatically removed the timer when it
1870 expired, and we are now adding it back, thus
1871 leaving istimer wherever it was set before.
1874 if (hmidi->istimer) {
1875 hmidi->timer.expires = 1 + jiffies;
1876 add_timer(&hmidi->timer);
1879 spin_unlock_irqrestore (&hmidi->lock, flags);
1883 snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1885 struct hdspm_midi *hmidi;
1886 unsigned long flags;
1888 hmidi = substream->rmidi->private_data;
1889 spin_lock_irqsave (&hmidi->lock, flags);
1891 if (!hmidi->istimer) {
1892 init_timer(&hmidi->timer);
1893 hmidi->timer.function = snd_hdspm_midi_output_timer;
1894 hmidi->timer.data = (unsigned long) hmidi;
1895 hmidi->timer.expires = 1 + jiffies;
1896 add_timer(&hmidi->timer);
1900 if (hmidi->istimer && --hmidi->istimer <= 0)
1901 del_timer (&hmidi->timer);
1903 spin_unlock_irqrestore (&hmidi->lock, flags);
1905 snd_hdspm_midi_output_write(hmidi);
1908 static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)
1910 struct hdspm_midi *hmidi;
1912 hmidi = substream->rmidi->private_data;
1913 spin_lock_irq (&hmidi->lock);
1914 snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
1915 hmidi->input = substream;
1916 spin_unlock_irq (&hmidi->lock);
1921 static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)
1923 struct hdspm_midi *hmidi;
1925 hmidi = substream->rmidi->private_data;
1926 spin_lock_irq (&hmidi->lock);
1927 hmidi->output = substream;
1928 spin_unlock_irq (&hmidi->lock);
1933 static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)
1935 struct hdspm_midi *hmidi;
1937 snd_hdspm_midi_input_trigger (substream, 0);
1939 hmidi = substream->rmidi->private_data;
1940 spin_lock_irq (&hmidi->lock);
1941 hmidi->input = NULL;
1942 spin_unlock_irq (&hmidi->lock);
1947 static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)
1949 struct hdspm_midi *hmidi;
1951 snd_hdspm_midi_output_trigger (substream, 0);
1953 hmidi = substream->rmidi->private_data;
1954 spin_lock_irq (&hmidi->lock);
1955 hmidi->output = NULL;
1956 spin_unlock_irq (&hmidi->lock);
1961 static struct snd_rawmidi_ops snd_hdspm_midi_output =
1963 .open = snd_hdspm_midi_output_open,
1964 .close = snd_hdspm_midi_output_close,
1965 .trigger = snd_hdspm_midi_output_trigger,
1968 static struct snd_rawmidi_ops snd_hdspm_midi_input =
1970 .open = snd_hdspm_midi_input_open,
1971 .close = snd_hdspm_midi_input_close,
1972 .trigger = snd_hdspm_midi_input_trigger,
1975 static int snd_hdspm_create_midi(struct snd_card *card,
1976 struct hdspm *hdspm, int id)
1981 hdspm->midi[id].id = id;
1982 hdspm->midi[id].hdspm = hdspm;
1983 spin_lock_init (&hdspm->midi[id].lock);
1986 if (MADIface == hdspm->io_type) {
1987 /* MIDI-over-MADI on HDSPe MADIface */
1988 hdspm->midi[0].dataIn = HDSPM_midiDataIn2;
1989 hdspm->midi[0].statusIn = HDSPM_midiStatusIn2;
1990 hdspm->midi[0].dataOut = HDSPM_midiDataOut2;
1991 hdspm->midi[0].statusOut = HDSPM_midiStatusOut2;
1992 hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable;
1993 hdspm->midi[0].irq = HDSPM_midi2IRQPending;
1995 hdspm->midi[0].dataIn = HDSPM_midiDataIn0;
1996 hdspm->midi[0].statusIn = HDSPM_midiStatusIn0;
1997 hdspm->midi[0].dataOut = HDSPM_midiDataOut0;
1998 hdspm->midi[0].statusOut = HDSPM_midiStatusOut0;
1999 hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable;
2000 hdspm->midi[0].irq = HDSPM_midi0IRQPending;
2002 } else if (1 == id) {
2003 hdspm->midi[1].dataIn = HDSPM_midiDataIn1;
2004 hdspm->midi[1].statusIn = HDSPM_midiStatusIn1;
2005 hdspm->midi[1].dataOut = HDSPM_midiDataOut1;
2006 hdspm->midi[1].statusOut = HDSPM_midiStatusOut1;
2007 hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable;
2008 hdspm->midi[1].irq = HDSPM_midi1IRQPending;
2009 } else if ((2 == id) && (MADI == hdspm->io_type)) {
2010 /* MIDI-over-MADI on HDSPe MADI */
2011 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
2012 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
2013 hdspm->midi[2].dataOut = HDSPM_midiDataOut2;
2014 hdspm->midi[2].statusOut = HDSPM_midiStatusOut2;
2015 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
2016 hdspm->midi[2].irq = HDSPM_midi2IRQPending;
2017 } else if (2 == id) {
2018 /* TCO MTC, read only */
2019 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
2020 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
2021 hdspm->midi[2].dataOut = -1;
2022 hdspm->midi[2].statusOut = -1;
2023 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
2024 hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES;
2025 } else if (3 == id) {
2026 /* TCO MTC on HDSPe MADI */
2027 hdspm->midi[3].dataIn = HDSPM_midiDataIn3;
2028 hdspm->midi[3].statusIn = HDSPM_midiStatusIn3;
2029 hdspm->midi[3].dataOut = -1;
2030 hdspm->midi[3].statusOut = -1;
2031 hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable;
2032 hdspm->midi[3].irq = HDSPM_midi3IRQPending;
2035 if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) ||
2036 (MADIface == hdspm->io_type)))) {
2037 if ((id == 0) && (MADIface == hdspm->io_type)) {
2038 sprintf(buf, "%s MIDIoverMADI", card->shortname);
2039 } else if ((id == 2) && (MADI == hdspm->io_type)) {
2040 sprintf(buf, "%s MIDIoverMADI", card->shortname);
2042 sprintf(buf, "%s MIDI %d", card->shortname, id+1);
2044 err = snd_rawmidi_new(card, buf, id, 1, 1,
2045 &hdspm->midi[id].rmidi);
2049 sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d",
2051 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
2053 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2054 SNDRV_RAWMIDI_STREAM_OUTPUT,
2055 &snd_hdspm_midi_output);
2056 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2057 SNDRV_RAWMIDI_STREAM_INPUT,
2058 &snd_hdspm_midi_input);
2060 hdspm->midi[id].rmidi->info_flags |=
2061 SNDRV_RAWMIDI_INFO_OUTPUT |
2062 SNDRV_RAWMIDI_INFO_INPUT |
2063 SNDRV_RAWMIDI_INFO_DUPLEX;
2065 /* TCO MTC, read only */
2066 sprintf(buf, "%s MTC %d", card->shortname, id+1);
2067 err = snd_rawmidi_new(card, buf, id, 1, 1,
2068 &hdspm->midi[id].rmidi);
2072 sprintf(hdspm->midi[id].rmidi->name,
2073 "%s MTC %d", card->id, id+1);
2074 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
2076 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2077 SNDRV_RAWMIDI_STREAM_INPUT,
2078 &snd_hdspm_midi_input);
2080 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
2087 static void hdspm_midi_tasklet(unsigned long arg)
2089 struct hdspm *hdspm = (struct hdspm *)arg;
2092 while (i < hdspm->midiPorts) {
2093 if (hdspm->midi[i].pending)
2094 snd_hdspm_midi_input_read(&hdspm->midi[i]);
2101 /*-----------------------------------------------------------------------------
2103 ----------------------------------------------------------------------------*/
2105 /* get the system sample rate which is set */
2108 static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
2110 unsigned int period, rate;
2112 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
2113 rate = hdspm_calc_dds_value(hdspm, period);
2119 * Calculate the real sample rate from the
2120 * current DDS value.
2122 static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
2126 rate = hdspm_get_pll_freq(hdspm);
2128 if (rate > 207000) {
2129 /* Unreasonable high sample rate as seen on PCI MADI cards. */
2130 if (0 == hdspm_system_clock_mode(hdspm)) {
2131 /* master mode, return internal sample rate */
2132 rate = hdspm->system_sample_rate;
2134 /* slave mode, return external sample rate */
2135 rate = hdspm_external_sample_rate(hdspm);
2143 #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
2144 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2147 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2148 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2149 .info = snd_hdspm_info_system_sample_rate, \
2150 .put = snd_hdspm_put_system_sample_rate, \
2151 .get = snd_hdspm_get_system_sample_rate \
2154 static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_info *uinfo)
2157 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2159 uinfo->value.integer.min = 27000;
2160 uinfo->value.integer.max = 207000;
2161 uinfo->value.integer.step = 1;
2166 static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol,
2167 struct snd_ctl_elem_value *
2170 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2172 ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm);
2176 static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
2177 struct snd_ctl_elem_value *
2180 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2182 hdspm_set_dds_value(hdspm, ucontrol->value.enumerated.item[0]);
2188 * Returns the WordClock sample rate class for the given card.
2190 static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
2194 switch (hdspm->io_type) {
2197 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2198 return (status >> 16) & 0xF;
2201 status = hdspm_read(hdspm, HDSPM_statusRegister);
2202 return (status >> HDSPM_AES32_wcFreq_bit) & 0xF;
2213 * Returns the TCO sample rate class for the given card.
2215 static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
2220 switch (hdspm->io_type) {
2223 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2224 return (status >> 20) & 0xF;
2227 status = hdspm_read(hdspm, HDSPM_statusRegister);
2228 return (status >> 1) & 0xF;
2239 * Returns the SYNC_IN sample rate class for the given card.
2241 static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2246 switch (hdspm->io_type) {
2249 status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2250 return (status >> 12) & 0xF;
2261 * Returns the AES sample rate class for the given card.
2263 static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
2267 switch (hdspm->io_type) {
2269 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
2270 return (timecode >> (4*index)) & 0xF;
2279 * Returns the sample rate class for input source <idx> for
2280 * 'new style' cards like the AIO and RayDAT.
2282 static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2284 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2286 return (status >> (idx*4)) & 0xF;
2289 static void snd_hdspm_set_infotext(struct snd_ctl_elem_info *uinfo,
2290 char **texts, const int count)
2292 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2294 uinfo->value.enumerated.items = count;
2295 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2296 uinfo->value.enumerated.item =
2297 uinfo->value.enumerated.items - 1;
2298 strcpy(uinfo->value.enumerated.name,
2299 texts[uinfo->value.enumerated.item]);
2302 #define ENUMERATED_CTL_INFO(info, texts) \
2303 snd_hdspm_set_infotext(info, texts, ARRAY_SIZE(texts))
2307 #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
2308 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2310 .private_value = xindex, \
2311 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2312 .info = snd_hdspm_info_autosync_sample_rate, \
2313 .get = snd_hdspm_get_autosync_sample_rate \
2317 static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2318 struct snd_ctl_elem_info *uinfo)
2320 ENUMERATED_CTL_INFO(uinfo, texts_freq);
2325 static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2326 struct snd_ctl_elem_value *
2329 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2331 switch (hdspm->io_type) {
2333 switch (kcontrol->private_value) {
2335 ucontrol->value.enumerated.item[0] =
2336 hdspm_get_wc_sample_rate(hdspm);
2339 ucontrol->value.enumerated.item[0] =
2340 hdspm_get_tco_sample_rate(hdspm);
2343 ucontrol->value.enumerated.item[0] =
2344 hdspm_get_sync_in_sample_rate(hdspm);
2347 ucontrol->value.enumerated.item[0] =
2348 hdspm_get_s1_sample_rate(hdspm,
2349 kcontrol->private_value-1);
2354 switch (kcontrol->private_value) {
2356 ucontrol->value.enumerated.item[0] =
2357 hdspm_get_wc_sample_rate(hdspm);
2360 ucontrol->value.enumerated.item[0] =
2361 hdspm_get_tco_sample_rate(hdspm);
2363 case 5: /* SYNC_IN */
2364 ucontrol->value.enumerated.item[0] =
2365 hdspm_get_sync_in_sample_rate(hdspm);
2368 ucontrol->value.enumerated.item[0] =
2369 hdspm_get_s1_sample_rate(hdspm,
2370 kcontrol->private_value-1);
2376 switch (kcontrol->private_value) {
2378 ucontrol->value.enumerated.item[0] =
2379 hdspm_get_wc_sample_rate(hdspm);
2382 ucontrol->value.enumerated.item[0] =
2383 hdspm_get_tco_sample_rate(hdspm);
2385 case 10: /* SYNC_IN */
2386 ucontrol->value.enumerated.item[0] =
2387 hdspm_get_sync_in_sample_rate(hdspm);
2389 default: /* AES1 to AES8 */
2390 ucontrol->value.enumerated.item[0] =
2391 hdspm_get_s1_sample_rate(hdspm,
2392 kcontrol->private_value-1);
2400 int rate = hdspm_external_sample_rate(hdspm);
2401 int i, selected_rate = 0;
2402 for (i = 1; i < 10; i++)
2403 if (HDSPM_bit2freq(i) == rate) {
2407 ucontrol->value.enumerated.item[0] = selected_rate;
2419 #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
2420 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2423 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2424 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2425 .info = snd_hdspm_info_system_clock_mode, \
2426 .get = snd_hdspm_get_system_clock_mode, \
2427 .put = snd_hdspm_put_system_clock_mode, \
2432 * Returns the system clock mode for the given card.
2433 * @returns 0 - master, 1 - slave
2435 static int hdspm_system_clock_mode(struct hdspm *hdspm)
2437 switch (hdspm->io_type) {
2440 if (hdspm->settings_register & HDSPM_c0Master)
2445 if (hdspm->control_register & HDSPM_ClockModeMaster)
2454 * Sets the system clock mode.
2455 * @param mode 0 - master, 1 - slave
2457 static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
2459 hdspm_set_toggle_setting(hdspm,
2460 (hdspm_is_raydat_or_aio(hdspm)) ?
2461 HDSPM_c0Master : HDSPM_ClockModeMaster,
2466 static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
2467 struct snd_ctl_elem_info *uinfo)
2469 static char *texts[] = { "Master", "AutoSync" };
2470 ENUMERATED_CTL_INFO(uinfo, texts);
2474 static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol,
2475 struct snd_ctl_elem_value *ucontrol)
2477 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2479 ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm);
2483 static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_value *ucontrol)
2486 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2489 if (!snd_hdspm_use_is_exclusive(hdspm))
2492 val = ucontrol->value.enumerated.item[0];
2498 hdspm_set_system_clock_mode(hdspm, val);
2504 #define HDSPM_INTERNAL_CLOCK(xname, xindex) \
2505 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2508 .info = snd_hdspm_info_clock_source, \
2509 .get = snd_hdspm_get_clock_source, \
2510 .put = snd_hdspm_put_clock_source \
2514 static int hdspm_clock_source(struct hdspm * hdspm)
2516 switch (hdspm->system_sample_rate) {
2517 case 32000: return 0;
2518 case 44100: return 1;
2519 case 48000: return 2;
2520 case 64000: return 3;
2521 case 88200: return 4;
2522 case 96000: return 5;
2523 case 128000: return 6;
2524 case 176400: return 7;
2525 case 192000: return 8;
2531 static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
2536 rate = 32000; break;
2538 rate = 44100; break;
2540 rate = 48000; break;
2542 rate = 64000; break;
2544 rate = 88200; break;
2546 rate = 96000; break;
2548 rate = 128000; break;
2550 rate = 176400; break;
2552 rate = 192000; break;
2556 hdspm_set_rate(hdspm, rate, 1);
2560 static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
2561 struct snd_ctl_elem_info *uinfo)
2563 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2565 uinfo->value.enumerated.items = 9;
2567 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2568 uinfo->value.enumerated.item =
2569 uinfo->value.enumerated.items - 1;
2571 strcpy(uinfo->value.enumerated.name,
2572 texts_freq[uinfo->value.enumerated.item+1]);
2577 static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
2578 struct snd_ctl_elem_value *ucontrol)
2580 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2582 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
2586 static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
2587 struct snd_ctl_elem_value *ucontrol)
2589 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2593 if (!snd_hdspm_use_is_exclusive(hdspm))
2595 val = ucontrol->value.enumerated.item[0];
2600 spin_lock_irq(&hdspm->lock);
2601 if (val != hdspm_clock_source(hdspm))
2602 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
2605 spin_unlock_irq(&hdspm->lock);
2610 #define HDSPM_PREF_SYNC_REF(xname, xindex) \
2611 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2614 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2615 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2616 .info = snd_hdspm_info_pref_sync_ref, \
2617 .get = snd_hdspm_get_pref_sync_ref, \
2618 .put = snd_hdspm_put_pref_sync_ref \
2623 * Returns the current preferred sync reference setting.
2624 * The semantics of the return value are depending on the
2625 * card, please see the comments for clarification.
2627 static int hdspm_pref_sync_ref(struct hdspm * hdspm)
2629 switch (hdspm->io_type) {
2631 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2632 case 0: return 0; /* WC */
2633 case HDSPM_SyncRef0: return 1; /* AES 1 */
2634 case HDSPM_SyncRef1: return 2; /* AES 2 */
2635 case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */
2636 case HDSPM_SyncRef2: return 4; /* AES 4 */
2637 case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */
2638 case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */
2639 case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0:
2640 return 7; /* AES 7 */
2641 case HDSPM_SyncRef3: return 8; /* AES 8 */
2642 case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */
2649 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2650 case 0: return 0; /* WC */
2651 case HDSPM_SyncRef0: return 1; /* MADI */
2652 case HDSPM_SyncRef1: return 2; /* TCO */
2653 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2654 return 3; /* SYNC_IN */
2657 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2658 case 0: return 0; /* WC */
2659 case HDSPM_SyncRef0: return 1; /* MADI */
2660 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2661 return 2; /* SYNC_IN */
2668 switch ((hdspm->settings_register &
2669 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2670 case 0: return 0; /* WC */
2671 case 3: return 1; /* ADAT 1 */
2672 case 4: return 2; /* ADAT 2 */
2673 case 5: return 3; /* ADAT 3 */
2674 case 6: return 4; /* ADAT 4 */
2675 case 1: return 5; /* AES */
2676 case 2: return 6; /* SPDIF */
2677 case 9: return 7; /* TCO */
2678 case 10: return 8; /* SYNC_IN */
2681 switch ((hdspm->settings_register &
2682 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2683 case 0: return 0; /* WC */
2684 case 3: return 1; /* ADAT 1 */
2685 case 4: return 2; /* ADAT 2 */
2686 case 5: return 3; /* ADAT 3 */
2687 case 6: return 4; /* ADAT 4 */
2688 case 1: return 5; /* AES */
2689 case 2: return 6; /* SPDIF */
2690 case 10: return 7; /* SYNC_IN */
2698 switch ((hdspm->settings_register &
2699 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2700 case 0: return 0; /* WC */
2701 case 3: return 1; /* ADAT */
2702 case 1: return 2; /* AES */
2703 case 2: return 3; /* SPDIF */
2704 case 9: return 4; /* TCO */
2705 case 10: return 5; /* SYNC_IN */
2708 switch ((hdspm->settings_register &
2709 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2710 case 0: return 0; /* WC */
2711 case 3: return 1; /* ADAT */
2712 case 1: return 2; /* AES */
2713 case 2: return 3; /* SPDIF */
2714 case 10: return 4; /* SYNC_IN */
2726 * Set the preferred sync reference to <pref>. The semantics
2727 * of <pref> are depending on the card type, see the comments
2728 * for clarification.
2730 static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
2734 switch (hdspm->io_type) {
2736 hdspm->control_register &= ~HDSPM_SyncRefMask;
2741 hdspm->control_register |= HDSPM_SyncRef0;
2744 hdspm->control_register |= HDSPM_SyncRef1;
2747 hdspm->control_register |=
2748 HDSPM_SyncRef1+HDSPM_SyncRef0;
2751 hdspm->control_register |= HDSPM_SyncRef2;
2754 hdspm->control_register |=
2755 HDSPM_SyncRef2+HDSPM_SyncRef0;
2758 hdspm->control_register |=
2759 HDSPM_SyncRef2+HDSPM_SyncRef1;
2762 hdspm->control_register |=
2763 HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
2766 hdspm->control_register |= HDSPM_SyncRef3;
2769 hdspm->control_register |=
2770 HDSPM_SyncRef3+HDSPM_SyncRef0;
2780 hdspm->control_register &= ~HDSPM_SyncRefMask;
2786 hdspm->control_register |= HDSPM_SyncRef0;
2789 hdspm->control_register |= HDSPM_SyncRef1;
2791 case 3: /* SYNC_IN */
2792 hdspm->control_register |=
2793 HDSPM_SyncRef0+HDSPM_SyncRef1;
2803 hdspm->control_register |= HDSPM_SyncRef0;
2805 case 2: /* SYNC_IN */
2806 hdspm->control_register |=
2807 HDSPM_SyncRef0+HDSPM_SyncRef1;
2819 case 0: p = 0; break; /* WC */
2820 case 1: p = 3; break; /* ADAT 1 */
2821 case 2: p = 4; break; /* ADAT 2 */
2822 case 3: p = 5; break; /* ADAT 3 */
2823 case 4: p = 6; break; /* ADAT 4 */
2824 case 5: p = 1; break; /* AES */
2825 case 6: p = 2; break; /* SPDIF */
2826 case 7: p = 9; break; /* TCO */
2827 case 8: p = 10; break; /* SYNC_IN */
2832 case 0: p = 0; break; /* WC */
2833 case 1: p = 3; break; /* ADAT 1 */
2834 case 2: p = 4; break; /* ADAT 2 */
2835 case 3: p = 5; break; /* ADAT 3 */
2836 case 4: p = 6; break; /* ADAT 4 */
2837 case 5: p = 1; break; /* AES */
2838 case 6: p = 2; break; /* SPDIF */
2839 case 7: p = 10; break; /* SYNC_IN */
2848 case 0: p = 0; break; /* WC */
2849 case 1: p = 3; break; /* ADAT */
2850 case 2: p = 1; break; /* AES */
2851 case 3: p = 2; break; /* SPDIF */
2852 case 4: p = 9; break; /* TCO */
2853 case 5: p = 10; break; /* SYNC_IN */
2858 case 0: p = 0; break; /* WC */
2859 case 1: p = 3; break; /* ADAT */
2860 case 2: p = 1; break; /* AES */
2861 case 3: p = 2; break; /* SPDIF */
2862 case 4: p = 10; break; /* SYNC_IN */
2869 switch (hdspm->io_type) {
2872 hdspm->settings_register &= ~HDSPM_c0_SyncRefMask;
2873 hdspm->settings_register |= HDSPM_c0_SyncRef0 * p;
2874 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
2880 hdspm_write(hdspm, HDSPM_controlRegister,
2881 hdspm->control_register);
2888 static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol,
2889 struct snd_ctl_elem_info *uinfo)
2891 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2893 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2895 uinfo->value.enumerated.items = hdspm->texts_autosync_items;
2897 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2898 uinfo->value.enumerated.item =
2899 uinfo->value.enumerated.items - 1;
2901 strcpy(uinfo->value.enumerated.name,
2902 hdspm->texts_autosync[uinfo->value.enumerated.item]);
2907 static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol,
2908 struct snd_ctl_elem_value *ucontrol)
2910 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2911 int psf = hdspm_pref_sync_ref(hdspm);
2914 ucontrol->value.enumerated.item[0] = psf;
2921 static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,
2922 struct snd_ctl_elem_value *ucontrol)
2924 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2925 int val, change = 0;
2927 if (!snd_hdspm_use_is_exclusive(hdspm))
2930 val = ucontrol->value.enumerated.item[0];
2934 else if (val >= hdspm->texts_autosync_items)
2935 val = hdspm->texts_autosync_items-1;
2937 spin_lock_irq(&hdspm->lock);
2938 if (val != hdspm_pref_sync_ref(hdspm))
2939 change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0;
2941 spin_unlock_irq(&hdspm->lock);
2946 #define HDSPM_AUTOSYNC_REF(xname, xindex) \
2947 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2950 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2951 .info = snd_hdspm_info_autosync_ref, \
2952 .get = snd_hdspm_get_autosync_ref, \
2955 static int hdspm_autosync_ref(struct hdspm *hdspm)
2957 /* This looks at the autosync selected sync reference */
2958 if (AES32 == hdspm->io_type) {
2960 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
2961 unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF;
2962 if ((syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD) &&
2963 (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN)) {
2966 return HDSPM_AES32_AUTOSYNC_FROM_NONE;
2968 } else if (MADI == hdspm->io_type) {
2970 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2971 switch (status2 & HDSPM_SelSyncRefMask) {
2972 case HDSPM_SelSyncRef_WORD:
2973 return HDSPM_AUTOSYNC_FROM_WORD;
2974 case HDSPM_SelSyncRef_MADI:
2975 return HDSPM_AUTOSYNC_FROM_MADI;
2976 case HDSPM_SelSyncRef_TCO:
2977 return HDSPM_AUTOSYNC_FROM_TCO;
2978 case HDSPM_SelSyncRef_SyncIn:
2979 return HDSPM_AUTOSYNC_FROM_SYNC_IN;
2980 case HDSPM_SelSyncRef_NVALID:
2981 return HDSPM_AUTOSYNC_FROM_NONE;
2983 return HDSPM_AUTOSYNC_FROM_NONE;
2991 static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol,
2992 struct snd_ctl_elem_info *uinfo)
2994 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2996 if (AES32 == hdspm->io_type) {
2997 static char *texts[] = { "WordClock", "AES1", "AES2", "AES3",
2998 "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In", "None"};
3000 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3002 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
3003 if (uinfo->value.enumerated.item >=
3004 uinfo->value.enumerated.items)
3005 uinfo->value.enumerated.item =
3006 uinfo->value.enumerated.items - 1;
3007 strcpy(uinfo->value.enumerated.name,
3008 texts[uinfo->value.enumerated.item]);
3009 } else if (MADI == hdspm->io_type) {
3010 static char *texts[] = {"Word Clock", "MADI", "TCO",
3011 "Sync In", "None" };
3013 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3015 uinfo->value.enumerated.items = 5;
3016 if (uinfo->value.enumerated.item >=
3017 uinfo->value.enumerated.items)
3018 uinfo->value.enumerated.item =
3019 uinfo->value.enumerated.items - 1;
3020 strcpy(uinfo->value.enumerated.name,
3021 texts[uinfo->value.enumerated.item]);
3026 static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
3027 struct snd_ctl_elem_value *ucontrol)
3029 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3031 ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm);
3037 #define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \
3038 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3040 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3041 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3042 .info = snd_hdspm_info_tco_video_input_format, \
3043 .get = snd_hdspm_get_tco_video_input_format, \
3046 static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol,
3047 struct snd_ctl_elem_info *uinfo)
3049 static char *texts[] = {"No video", "NTSC", "PAL"};
3050 ENUMERATED_CTL_INFO(uinfo, texts);
3054 static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol,
3055 struct snd_ctl_elem_value *ucontrol)
3060 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3061 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3062 switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC |
3063 HDSPM_TCO1_Video_Input_Format_PAL)) {
3064 case HDSPM_TCO1_Video_Input_Format_NTSC:
3068 case HDSPM_TCO1_Video_Input_Format_PAL:
3077 ucontrol->value.enumerated.item[0] = ret;
3083 #define HDSPM_TCO_LTC_FRAMES(xname, xindex) \
3084 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3086 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3087 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3088 .info = snd_hdspm_info_tco_ltc_frames, \
3089 .get = snd_hdspm_get_tco_ltc_frames, \
3092 static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3093 struct snd_ctl_elem_info *uinfo)
3095 static char *texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps",
3097 ENUMERATED_CTL_INFO(uinfo, texts);
3101 static int hdspm_tco_ltc_frames(struct hdspm *hdspm)
3106 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3107 if (status & HDSPM_TCO1_LTC_Input_valid) {
3108 switch (status & (HDSPM_TCO1_LTC_Format_LSB |
3109 HDSPM_TCO1_LTC_Format_MSB)) {
3114 case HDSPM_TCO1_LTC_Format_LSB:
3118 case HDSPM_TCO1_LTC_Format_MSB:
3132 static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3133 struct snd_ctl_elem_value *ucontrol)
3135 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3137 ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm);
3141 #define HDSPM_TOGGLE_SETTING(xname, xindex) \
3142 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3144 .private_value = xindex, \
3145 .info = snd_hdspm_info_toggle_setting, \
3146 .get = snd_hdspm_get_toggle_setting, \
3147 .put = snd_hdspm_put_toggle_setting \
3150 static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask)
3154 if (hdspm_is_raydat_or_aio(hdspm))
3155 reg = hdspm->settings_register;
3157 reg = hdspm->control_register;
3159 return (reg & regmask) ? 1 : 0;
3162 static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out)
3167 if (hdspm_is_raydat_or_aio(hdspm)) {
3168 reg = &(hdspm->settings_register);
3169 target_reg = HDSPM_WR_SETTINGS;
3171 reg = &(hdspm->control_register);
3172 target_reg = HDSPM_controlRegister;
3180 hdspm_write(hdspm, target_reg, *reg);
3185 #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info
3187 static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol,
3188 struct snd_ctl_elem_value *ucontrol)
3190 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3191 u32 regmask = kcontrol->private_value;
3193 spin_lock_irq(&hdspm->lock);
3194 ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask);
3195 spin_unlock_irq(&hdspm->lock);
3199 static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol,
3200 struct snd_ctl_elem_value *ucontrol)
3202 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3203 u32 regmask = kcontrol->private_value;
3207 if (!snd_hdspm_use_is_exclusive(hdspm))
3209 val = ucontrol->value.integer.value[0] & 1;
3210 spin_lock_irq(&hdspm->lock);
3211 change = (int) val != hdspm_toggle_setting(hdspm, regmask);
3212 hdspm_set_toggle_setting(hdspm, regmask, val);
3213 spin_unlock_irq(&hdspm->lock);
3217 #define HDSPM_INPUT_SELECT(xname, xindex) \
3218 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3221 .info = snd_hdspm_info_input_select, \
3222 .get = snd_hdspm_get_input_select, \
3223 .put = snd_hdspm_put_input_select \
3226 static int hdspm_input_select(struct hdspm * hdspm)
3228 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
3231 static int hdspm_set_input_select(struct hdspm * hdspm, int out)
3234 hdspm->control_register |= HDSPM_InputSelect0;
3236 hdspm->control_register &= ~HDSPM_InputSelect0;
3237 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3242 static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
3243 struct snd_ctl_elem_info *uinfo)
3245 static char *texts[] = { "optical", "coaxial" };
3246 ENUMERATED_CTL_INFO(uinfo, texts);
3250 static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol,
3251 struct snd_ctl_elem_value *ucontrol)
3253 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3255 spin_lock_irq(&hdspm->lock);
3256 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
3257 spin_unlock_irq(&hdspm->lock);
3261 static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,
3262 struct snd_ctl_elem_value *ucontrol)
3264 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3268 if (!snd_hdspm_use_is_exclusive(hdspm))
3270 val = ucontrol->value.integer.value[0] & 1;
3271 spin_lock_irq(&hdspm->lock);
3272 change = (int) val != hdspm_input_select(hdspm);
3273 hdspm_set_input_select(hdspm, val);
3274 spin_unlock_irq(&hdspm->lock);
3279 #define HDSPM_DS_WIRE(xname, xindex) \
3280 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3283 .info = snd_hdspm_info_ds_wire, \
3284 .get = snd_hdspm_get_ds_wire, \
3285 .put = snd_hdspm_put_ds_wire \
3288 static int hdspm_ds_wire(struct hdspm * hdspm)
3290 return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
3293 static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
3296 hdspm->control_register |= HDSPM_DS_DoubleWire;
3298 hdspm->control_register &= ~HDSPM_DS_DoubleWire;
3299 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3304 static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
3305 struct snd_ctl_elem_info *uinfo)
3307 static char *texts[] = { "Single", "Double" };
3308 ENUMERATED_CTL_INFO(uinfo, texts);
3312 static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol,
3313 struct snd_ctl_elem_value *ucontrol)
3315 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3317 spin_lock_irq(&hdspm->lock);
3318 ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
3319 spin_unlock_irq(&hdspm->lock);
3323 static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,
3324 struct snd_ctl_elem_value *ucontrol)
3326 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3330 if (!snd_hdspm_use_is_exclusive(hdspm))
3332 val = ucontrol->value.integer.value[0] & 1;
3333 spin_lock_irq(&hdspm->lock);
3334 change = (int) val != hdspm_ds_wire(hdspm);
3335 hdspm_set_ds_wire(hdspm, val);
3336 spin_unlock_irq(&hdspm->lock);
3341 #define HDSPM_QS_WIRE(xname, xindex) \
3342 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3345 .info = snd_hdspm_info_qs_wire, \
3346 .get = snd_hdspm_get_qs_wire, \
3347 .put = snd_hdspm_put_qs_wire \
3350 static int hdspm_qs_wire(struct hdspm * hdspm)
3352 if (hdspm->control_register & HDSPM_QS_DoubleWire)
3354 if (hdspm->control_register & HDSPM_QS_QuadWire)
3359 static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
3361 hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
3366 hdspm->control_register |= HDSPM_QS_DoubleWire;
3369 hdspm->control_register |= HDSPM_QS_QuadWire;
3372 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3377 static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
3378 struct snd_ctl_elem_info *uinfo)
3380 static char *texts[] = { "Single", "Double", "Quad" };
3381 ENUMERATED_CTL_INFO(uinfo, texts);
3385 static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol,
3386 struct snd_ctl_elem_value *ucontrol)
3388 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3390 spin_lock_irq(&hdspm->lock);
3391 ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
3392 spin_unlock_irq(&hdspm->lock);
3396 static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
3397 struct snd_ctl_elem_value *ucontrol)
3399 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3403 if (!snd_hdspm_use_is_exclusive(hdspm))
3405 val = ucontrol->value.integer.value[0];
3410 spin_lock_irq(&hdspm->lock);
3411 change = val != hdspm_qs_wire(hdspm);
3412 hdspm_set_qs_wire(hdspm, val);
3413 spin_unlock_irq(&hdspm->lock);
3417 #define HDSPM_CONTROL_TRISTATE(xname, xindex) \
3418 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3420 .private_value = xindex, \
3421 .info = snd_hdspm_info_tristate, \
3422 .get = snd_hdspm_get_tristate, \
3423 .put = snd_hdspm_put_tristate \
3426 static int hdspm_tristate(struct hdspm *hdspm, u32 regmask)
3428 u32 reg = hdspm->settings_register & (regmask * 3);
3429 return reg / regmask;
3432 static int hdspm_set_tristate(struct hdspm *hdspm, int mode, u32 regmask)
3434 hdspm->settings_register &= ~(regmask * 3);
3435 hdspm->settings_register |= (regmask * mode);
3436 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
3441 static int snd_hdspm_info_tristate(struct snd_kcontrol *kcontrol,
3442 struct snd_ctl_elem_info *uinfo)
3444 u32 regmask = kcontrol->private_value;
3446 static char *texts_spdif[] = { "Optical", "Coaxial", "Internal" };
3447 static char *texts_levels[] = { "Hi Gain", "+4 dBu", "-10 dBV" };
3450 case HDSPM_c0_Input0:
3451 ENUMERATED_CTL_INFO(uinfo, texts_spdif);
3454 ENUMERATED_CTL_INFO(uinfo, texts_levels);
3460 static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol,
3461 struct snd_ctl_elem_value *ucontrol)
3463 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3464 u32 regmask = kcontrol->private_value;
3466 spin_lock_irq(&hdspm->lock);
3467 ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask);
3468 spin_unlock_irq(&hdspm->lock);
3472 static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol,
3473 struct snd_ctl_elem_value *ucontrol)
3475 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3476 u32 regmask = kcontrol->private_value;
3480 if (!snd_hdspm_use_is_exclusive(hdspm))
3482 val = ucontrol->value.integer.value[0];
3488 spin_lock_irq(&hdspm->lock);
3489 change = val != hdspm_tristate(hdspm, regmask);
3490 hdspm_set_tristate(hdspm, val, regmask);
3491 spin_unlock_irq(&hdspm->lock);
3495 #define HDSPM_MADI_SPEEDMODE(xname, xindex) \
3496 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3499 .info = snd_hdspm_info_madi_speedmode, \
3500 .get = snd_hdspm_get_madi_speedmode, \
3501 .put = snd_hdspm_put_madi_speedmode \
3504 static int hdspm_madi_speedmode(struct hdspm *hdspm)
3506 if (hdspm->control_register & HDSPM_QuadSpeed)
3508 if (hdspm->control_register & HDSPM_DoubleSpeed)
3513 static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode)
3515 hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed);
3520 hdspm->control_register |= HDSPM_DoubleSpeed;
3523 hdspm->control_register |= HDSPM_QuadSpeed;
3526 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3531 static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
3532 struct snd_ctl_elem_info *uinfo)
3534 static char *texts[] = { "Single", "Double", "Quad" };
3535 ENUMERATED_CTL_INFO(uinfo, texts);
3539 static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol,
3540 struct snd_ctl_elem_value *ucontrol)
3542 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3544 spin_lock_irq(&hdspm->lock);
3545 ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm);
3546 spin_unlock_irq(&hdspm->lock);
3550 static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol,
3551 struct snd_ctl_elem_value *ucontrol)
3553 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3557 if (!snd_hdspm_use_is_exclusive(hdspm))
3559 val = ucontrol->value.integer.value[0];
3564 spin_lock_irq(&hdspm->lock);
3565 change = val != hdspm_madi_speedmode(hdspm);
3566 hdspm_set_madi_speedmode(hdspm, val);
3567 spin_unlock_irq(&hdspm->lock);
3571 #define HDSPM_MIXER(xname, xindex) \
3572 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3576 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3577 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3578 .info = snd_hdspm_info_mixer, \
3579 .get = snd_hdspm_get_mixer, \
3580 .put = snd_hdspm_put_mixer \
3583 static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol,
3584 struct snd_ctl_elem_info *uinfo)
3586 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3588 uinfo->value.integer.min = 0;
3589 uinfo->value.integer.max = 65535;
3590 uinfo->value.integer.step = 1;
3594 static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,
3595 struct snd_ctl_elem_value *ucontrol)
3597 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3601 source = ucontrol->value.integer.value[0];
3604 else if (source >= 2 * HDSPM_MAX_CHANNELS)
3605 source = 2 * HDSPM_MAX_CHANNELS - 1;
3607 destination = ucontrol->value.integer.value[1];
3608 if (destination < 0)
3610 else if (destination >= HDSPM_MAX_CHANNELS)
3611 destination = HDSPM_MAX_CHANNELS - 1;
3613 spin_lock_irq(&hdspm->lock);
3614 if (source >= HDSPM_MAX_CHANNELS)
3615 ucontrol->value.integer.value[2] =
3616 hdspm_read_pb_gain(hdspm, destination,
3617 source - HDSPM_MAX_CHANNELS);
3619 ucontrol->value.integer.value[2] =
3620 hdspm_read_in_gain(hdspm, destination, source);
3622 spin_unlock_irq(&hdspm->lock);
3627 static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,
3628 struct snd_ctl_elem_value *ucontrol)
3630 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3636 if (!snd_hdspm_use_is_exclusive(hdspm))
3639 source = ucontrol->value.integer.value[0];
3640 destination = ucontrol->value.integer.value[1];
3642 if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
3644 if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
3647 gain = ucontrol->value.integer.value[2];
3649 spin_lock_irq(&hdspm->lock);
3651 if (source >= HDSPM_MAX_CHANNELS)
3652 change = gain != hdspm_read_pb_gain(hdspm, destination,
3654 HDSPM_MAX_CHANNELS);
3656 change = gain != hdspm_read_in_gain(hdspm, destination,
3660 if (source >= HDSPM_MAX_CHANNELS)
3661 hdspm_write_pb_gain(hdspm, destination,
3662 source - HDSPM_MAX_CHANNELS,
3665 hdspm_write_in_gain(hdspm, destination, source,
3668 spin_unlock_irq(&hdspm->lock);
3673 /* The simple mixer control(s) provide gain control for the
3674 basic 1:1 mappings of playback streams to output
3678 #define HDSPM_PLAYBACK_MIXER \
3679 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3680 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
3681 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3682 .info = snd_hdspm_info_playback_mixer, \
3683 .get = snd_hdspm_get_playback_mixer, \
3684 .put = snd_hdspm_put_playback_mixer \
3687 static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol,
3688 struct snd_ctl_elem_info *uinfo)
3690 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3692 uinfo->value.integer.min = 0;
3693 uinfo->value.integer.max = 64;
3694 uinfo->value.integer.step = 1;
3698 static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
3699 struct snd_ctl_elem_value *ucontrol)
3701 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3704 channel = ucontrol->id.index - 1;
3706 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3709 spin_lock_irq(&hdspm->lock);
3710 ucontrol->value.integer.value[0] =
3711 (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN;
3712 spin_unlock_irq(&hdspm->lock);
3717 static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
3718 struct snd_ctl_elem_value *ucontrol)
3720 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3725 if (!snd_hdspm_use_is_exclusive(hdspm))
3728 channel = ucontrol->id.index - 1;
3730 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3733 gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64;
3735 spin_lock_irq(&hdspm->lock);
3737 gain != hdspm_read_pb_gain(hdspm, channel,
3740 hdspm_write_pb_gain(hdspm, channel, channel,
3742 spin_unlock_irq(&hdspm->lock);
3746 #define HDSPM_SYNC_CHECK(xname, xindex) \
3747 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3749 .private_value = xindex, \
3750 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3751 .info = snd_hdspm_info_sync_check, \
3752 .get = snd_hdspm_get_sync_check \
3755 #define HDSPM_TCO_LOCK_CHECK(xname, xindex) \
3756 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3758 .private_value = xindex, \
3759 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3760 .info = snd_hdspm_tco_info_lock_check, \
3761 .get = snd_hdspm_get_sync_check \
3766 static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
3767 struct snd_ctl_elem_info *uinfo)
3769 static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" };
3770 ENUMERATED_CTL_INFO(uinfo, texts);
3774 static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol,
3775 struct snd_ctl_elem_info *uinfo)
3777 static char *texts[] = { "No Lock", "Lock" };
3778 ENUMERATED_CTL_INFO(uinfo, texts);
3782 static int hdspm_wc_sync_check(struct hdspm *hdspm)
3784 int status, status2;
3786 switch (hdspm->io_type) {
3788 status = hdspm_read(hdspm, HDSPM_statusRegister);
3789 if (status & HDSPM_AES32_wcLock) {
3790 if (status & HDSPM_AES32_wcSync)
3799 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3800 if (status2 & HDSPM_wcLock) {
3801 if (status2 & HDSPM_wcSync)
3811 status = hdspm_read(hdspm, HDSPM_statusRegister);
3813 if (status & 0x2000000)
3815 else if (status & 0x1000000)
3830 static int hdspm_madi_sync_check(struct hdspm *hdspm)
3832 int status = hdspm_read(hdspm, HDSPM_statusRegister);
3833 if (status & HDSPM_madiLock) {
3834 if (status & HDSPM_madiSync)
3843 static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx)
3845 int status, lock, sync;
3847 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3849 lock = (status & (0x1<<idx)) ? 1 : 0;
3850 sync = (status & (0x100<<idx)) ? 1 : 0;
3860 static int hdspm_sync_in_sync_check(struct hdspm *hdspm)
3862 int status, lock = 0, sync = 0;
3864 switch (hdspm->io_type) {
3867 status = hdspm_read(hdspm, HDSPM_RD_STATUS_3);
3868 lock = (status & 0x400) ? 1 : 0;
3869 sync = (status & 0x800) ? 1 : 0;
3873 status = hdspm_read(hdspm, HDSPM_statusRegister);
3874 lock = (status & HDSPM_syncInLock) ? 1 : 0;
3875 sync = (status & HDSPM_syncInSync) ? 1 : 0;
3879 status = hdspm_read(hdspm, HDSPM_statusRegister2);
3880 lock = (status & 0x100000) ? 1 : 0;
3881 sync = (status & 0x200000) ? 1 : 0;
3896 static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
3898 int status2, lock, sync;
3899 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3901 lock = (status2 & (0x0080 >> idx)) ? 1 : 0;
3902 sync = (status2 & (0x8000 >> idx)) ? 1 : 0;
3911 static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask)
3914 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3916 return (status & mask) ? 1 : 0;
3920 static int hdspm_tco_sync_check(struct hdspm *hdspm)
3925 switch (hdspm->io_type) {
3927 status = hdspm_read(hdspm, HDSPM_statusRegister);
3928 if (status & HDSPM_tcoLockMadi) {
3929 if (status & HDSPM_tcoSync)
3937 status = hdspm_read(hdspm, HDSPM_statusRegister);
3938 if (status & HDSPM_tcoLockAes) {
3939 if (status & HDSPM_tcoSync)
3950 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3952 if (status & 0x8000000)
3953 return 2; /* Sync */
3954 if (status & 0x4000000)
3955 return 1; /* Lock */
3956 return 0; /* No signal */
3968 static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
3969 struct snd_ctl_elem_value *ucontrol)
3971 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3974 switch (hdspm->io_type) {
3976 switch (kcontrol->private_value) {
3978 val = hdspm_wc_sync_check(hdspm); break;
3980 val = hdspm_tco_sync_check(hdspm); break;
3981 case 8: /* SYNC IN */
3982 val = hdspm_sync_in_sync_check(hdspm); break;
3984 val = hdspm_s1_sync_check(hdspm,
3985 kcontrol->private_value-1);
3990 switch (kcontrol->private_value) {
3992 val = hdspm_wc_sync_check(hdspm); break;
3994 val = hdspm_tco_sync_check(hdspm); break;
3995 case 5: /* SYNC IN */
3996 val = hdspm_sync_in_sync_check(hdspm); break;
3998 val = hdspm_s1_sync_check(hdspm,
3999 kcontrol->private_value-1);
4004 switch (kcontrol->private_value) {
4006 val = hdspm_wc_sync_check(hdspm); break;
4008 val = hdspm_madi_sync_check(hdspm); break;
4010 val = hdspm_tco_sync_check(hdspm); break;
4011 case 3: /* SYNC_IN */
4012 val = hdspm_sync_in_sync_check(hdspm); break;
4017 val = hdspm_madi_sync_check(hdspm); /* MADI */
4021 switch (kcontrol->private_value) {
4023 val = hdspm_wc_sync_check(hdspm); break;
4025 val = hdspm_tco_sync_check(hdspm); break;
4026 case 10 /* SYNC IN */:
4027 val = hdspm_sync_in_sync_check(hdspm); break;
4028 default: /* AES1 to AES8 */
4029 val = hdspm_aes_sync_check(hdspm,
4030 kcontrol->private_value-1);
4037 switch (kcontrol->private_value) {
4039 /* Check TCO for lock state of its current input */
4040 val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock);
4043 /* Check TCO for valid time code on LTC input. */
4044 val = hdspm_tco_input_check(hdspm,
4045 HDSPM_TCO1_LTC_Input_valid);
4055 ucontrol->value.enumerated.item[0] = val;
4064 static void hdspm_tco_write(struct hdspm *hdspm)
4066 unsigned int tc[4] = { 0, 0, 0, 0};
4068 switch (hdspm->tco->input) {
4070 tc[2] |= HDSPM_TCO2_set_input_MSB;
4073 tc[2] |= HDSPM_TCO2_set_input_LSB;
4079 switch (hdspm->tco->framerate) {
4081 tc[1] |= HDSPM_TCO1_LTC_Format_LSB;
4084 tc[1] |= HDSPM_TCO1_LTC_Format_MSB;
4087 tc[1] |= HDSPM_TCO1_LTC_Format_MSB +
4088 HDSPM_TCO1_set_drop_frame_flag;
4091 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4092 HDSPM_TCO1_LTC_Format_MSB;
4095 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4096 HDSPM_TCO1_LTC_Format_MSB +
4097 HDSPM_TCO1_set_drop_frame_flag;
4103 switch (hdspm->tco->wordclock) {
4105 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB;
4108 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB;
4114 switch (hdspm->tco->samplerate) {
4116 tc[2] |= HDSPM_TCO2_set_freq;
4119 tc[2] |= HDSPM_TCO2_set_freq_from_app;
4125 switch (hdspm->tco->pull) {
4127 tc[2] |= HDSPM_TCO2_set_pull_up;
4130 tc[2] |= HDSPM_TCO2_set_pull_down;
4133 tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4;
4136 tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4;
4142 if (1 == hdspm->tco->term) {
4143 tc[2] |= HDSPM_TCO2_set_term_75R;
4146 hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]);
4147 hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]);
4148 hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]);
4149 hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]);
4153 #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \
4154 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4157 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4158 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4159 .info = snd_hdspm_info_tco_sample_rate, \
4160 .get = snd_hdspm_get_tco_sample_rate, \
4161 .put = snd_hdspm_put_tco_sample_rate \
4164 static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
4165 struct snd_ctl_elem_info *uinfo)
4167 static char *texts[] = { "44.1 kHz", "48 kHz" };
4168 ENUMERATED_CTL_INFO(uinfo, texts);
4172 static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol,
4173 struct snd_ctl_elem_value *ucontrol)
4175 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4177 ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate;
4182 static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol,
4183 struct snd_ctl_elem_value *ucontrol)
4185 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4187 if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) {
4188 hdspm->tco->samplerate = ucontrol->value.enumerated.item[0];
4190 hdspm_tco_write(hdspm);
4199 #define HDSPM_TCO_PULL(xname, xindex) \
4200 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4203 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4204 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4205 .info = snd_hdspm_info_tco_pull, \
4206 .get = snd_hdspm_get_tco_pull, \
4207 .put = snd_hdspm_put_tco_pull \
4210 static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
4211 struct snd_ctl_elem_info *uinfo)
4213 static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" };
4214 ENUMERATED_CTL_INFO(uinfo, texts);
4218 static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol,
4219 struct snd_ctl_elem_value *ucontrol)
4221 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4223 ucontrol->value.enumerated.item[0] = hdspm->tco->pull;
4228 static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol,
4229 struct snd_ctl_elem_value *ucontrol)
4231 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4233 if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) {
4234 hdspm->tco->pull = ucontrol->value.enumerated.item[0];
4236 hdspm_tco_write(hdspm);
4244 #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \
4245 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4248 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4249 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4250 .info = snd_hdspm_info_tco_wck_conversion, \
4251 .get = snd_hdspm_get_tco_wck_conversion, \
4252 .put = snd_hdspm_put_tco_wck_conversion \
4255 static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4256 struct snd_ctl_elem_info *uinfo)
4258 static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
4259 ENUMERATED_CTL_INFO(uinfo, texts);
4263 static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4264 struct snd_ctl_elem_value *ucontrol)
4266 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4268 ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock;
4273 static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4274 struct snd_ctl_elem_value *ucontrol)
4276 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4278 if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) {
4279 hdspm->tco->wordclock = ucontrol->value.enumerated.item[0];
4281 hdspm_tco_write(hdspm);
4290 #define HDSPM_TCO_FRAME_RATE(xname, xindex) \
4291 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4294 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4295 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4296 .info = snd_hdspm_info_tco_frame_rate, \
4297 .get = snd_hdspm_get_tco_frame_rate, \
4298 .put = snd_hdspm_put_tco_frame_rate \
4301 static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
4302 struct snd_ctl_elem_info *uinfo)
4304 static char *texts[] = { "24 fps", "25 fps", "29.97fps",
4305 "29.97 dfps", "30 fps", "30 dfps" };
4306 ENUMERATED_CTL_INFO(uinfo, texts);
4310 static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol,
4311 struct snd_ctl_elem_value *ucontrol)
4313 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4315 ucontrol->value.enumerated.item[0] = hdspm->tco->framerate;
4320 static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol,
4321 struct snd_ctl_elem_value *ucontrol)
4323 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4325 if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) {
4326 hdspm->tco->framerate = ucontrol->value.enumerated.item[0];
4328 hdspm_tco_write(hdspm);
4337 #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \
4338 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4341 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4342 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4343 .info = snd_hdspm_info_tco_sync_source, \
4344 .get = snd_hdspm_get_tco_sync_source, \
4345 .put = snd_hdspm_put_tco_sync_source \
4348 static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
4349 struct snd_ctl_elem_info *uinfo)
4351 static char *texts[] = { "LTC", "Video", "WCK" };
4352 ENUMERATED_CTL_INFO(uinfo, texts);
4356 static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol,
4357 struct snd_ctl_elem_value *ucontrol)
4359 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4361 ucontrol->value.enumerated.item[0] = hdspm->tco->input;
4366 static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol,
4367 struct snd_ctl_elem_value *ucontrol)
4369 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4371 if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) {
4372 hdspm->tco->input = ucontrol->value.enumerated.item[0];
4374 hdspm_tco_write(hdspm);
4383 #define HDSPM_TCO_WORD_TERM(xname, xindex) \
4384 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4387 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4388 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4389 .info = snd_hdspm_info_tco_word_term, \
4390 .get = snd_hdspm_get_tco_word_term, \
4391 .put = snd_hdspm_put_tco_word_term \
4394 static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol,
4395 struct snd_ctl_elem_info *uinfo)
4397 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4399 uinfo->value.integer.min = 0;
4400 uinfo->value.integer.max = 1;
4406 static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol,
4407 struct snd_ctl_elem_value *ucontrol)
4409 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4411 ucontrol->value.enumerated.item[0] = hdspm->tco->term;
4417 static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol,
4418 struct snd_ctl_elem_value *ucontrol)
4420 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4422 if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) {
4423 hdspm->tco->term = ucontrol->value.enumerated.item[0];
4425 hdspm_tco_write(hdspm);
4436 static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
4437 HDSPM_MIXER("Mixer", 0),
4438 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4439 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4440 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4441 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4442 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4443 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4444 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4445 HDSPM_SYNC_CHECK("MADI SyncCheck", 1),
4446 HDSPM_SYNC_CHECK("TCO SyncCheck", 2),
4447 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
4448 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4449 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
4450 HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX),
4451 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4452 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
4453 HDSPM_INPUT_SELECT("Input Select", 0),
4454 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
4458 static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = {
4459 HDSPM_MIXER("Mixer", 0),
4460 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4461 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4462 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4463 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4464 HDSPM_SYNC_CHECK("MADI SyncCheck", 0),
4465 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
4466 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4467 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
4468 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
4471 static struct snd_kcontrol_new snd_hdspm_controls_aio[] = {
4472 HDSPM_MIXER("Mixer", 0),
4473 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4474 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4475 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4476 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4477 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4478 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4479 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4480 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4481 HDSPM_SYNC_CHECK("ADAT SyncCheck", 3),
4482 HDSPM_SYNC_CHECK("TCO SyncCheck", 4),
4483 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5),
4484 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4485 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4486 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4487 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3),
4488 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4),
4489 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5),
4490 HDSPM_CONTROL_TRISTATE("S/PDIF Input", HDSPM_c0_Input0),
4491 HDSPM_TOGGLE_SETTING("S/PDIF Out Optical", HDSPM_c0_Spdif_Opt),
4492 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4493 HDSPM_TOGGLE_SETTING("ADAT internal (AEB/TEB)", HDSPM_c0_AEB1),
4494 HDSPM_TOGGLE_SETTING("XLR Breakout Cable", HDSPM_c0_Sym6db),
4495 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48),
4496 HDSPM_CONTROL_TRISTATE("Input Level", HDSPM_c0_AD_GAIN0),
4497 HDSPM_CONTROL_TRISTATE("Output Level", HDSPM_c0_DA_GAIN0),
4498 HDSPM_CONTROL_TRISTATE("Phones Level", HDSPM_c0_PH_GAIN0)
4501 HDSPM_INPUT_SELECT("Input Select", 0),
4502 HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0),
4503 HDSPM_PROFESSIONAL("SPDIF Out Professional", 0);
4504 HDSPM_SPDIF_IN("SPDIF In", 0);
4505 HDSPM_BREAKOUT_CABLE("Breakout Cable", 0);
4506 HDSPM_INPUT_LEVEL("Input Level", 0);
4507 HDSPM_OUTPUT_LEVEL("Output Level", 0);
4508 HDSPM_PHONES("Phones", 0);
4512 static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = {
4513 HDSPM_MIXER("Mixer", 0),
4514 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4515 HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0),
4516 HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0),
4517 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4518 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4519 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4520 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4521 HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3),
4522 HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4),
4523 HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5),
4524 HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6),
4525 HDSPM_SYNC_CHECK("TCO SyncCheck", 7),
4526 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8),
4527 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4528 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4529 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4530 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3),
4531 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4),
4532 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5),
4533 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6),
4534 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7),
4535 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8),
4536 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4537 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48)
4540 static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = {
4541 HDSPM_MIXER("Mixer", 0),
4542 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4543 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4544 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4545 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4546 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4547 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4548 HDSPM_SYNC_CHECK("WC Sync Check", 0),
4549 HDSPM_SYNC_CHECK("AES1 Sync Check", 1),
4550 HDSPM_SYNC_CHECK("AES2 Sync Check", 2),
4551 HDSPM_SYNC_CHECK("AES3 Sync Check", 3),
4552 HDSPM_SYNC_CHECK("AES4 Sync Check", 4),
4553 HDSPM_SYNC_CHECK("AES5 Sync Check", 5),
4554 HDSPM_SYNC_CHECK("AES6 Sync Check", 6),
4555 HDSPM_SYNC_CHECK("AES7 Sync Check", 7),
4556 HDSPM_SYNC_CHECK("AES8 Sync Check", 8),
4557 HDSPM_SYNC_CHECK("TCO Sync Check", 9),
4558 HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10),
4559 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4560 HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1),
4561 HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2),
4562 HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3),
4563 HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4),
4564 HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5),
4565 HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6),
4566 HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7),
4567 HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8),
4568 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9),
4569 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10),
4570 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4571 HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis),
4572 HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby),
4573 HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional),
4574 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4575 HDSPM_DS_WIRE("Double Speed Wire Mode", 0),
4576 HDSPM_QS_WIRE("Quad Speed Wire Mode", 0),
4581 /* Control elements for the optional TCO module */
4582 static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
4583 HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0),
4584 HDSPM_TCO_PULL("TCO Pull", 0),
4585 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
4586 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
4587 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
4588 HDSPM_TCO_WORD_TERM("TCO Word Term", 0),
4589 HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11),
4590 HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12),
4591 HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0),
4592 HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0)
4596 static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
4599 static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
4603 for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) {
4604 if (hdspm->system_sample_rate > 48000) {
4605 hdspm->playback_mixer_ctls[i]->vd[0].access =
4606 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
4607 SNDRV_CTL_ELEM_ACCESS_READ |
4608 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
4610 hdspm->playback_mixer_ctls[i]->vd[0].access =
4611 SNDRV_CTL_ELEM_ACCESS_READWRITE |
4612 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
4614 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
4615 SNDRV_CTL_EVENT_MASK_INFO,
4616 &hdspm->playback_mixer_ctls[i]->id);
4623 static int snd_hdspm_create_controls(struct snd_card *card,
4624 struct hdspm *hdspm)
4626 unsigned int idx, limit;
4628 struct snd_kcontrol *kctl;
4629 struct snd_kcontrol_new *list = NULL;
4631 switch (hdspm->io_type) {
4633 list = snd_hdspm_controls_madi;
4634 limit = ARRAY_SIZE(snd_hdspm_controls_madi);
4637 list = snd_hdspm_controls_madiface;
4638 limit = ARRAY_SIZE(snd_hdspm_controls_madiface);
4641 list = snd_hdspm_controls_aio;
4642 limit = ARRAY_SIZE(snd_hdspm_controls_aio);
4645 list = snd_hdspm_controls_raydat;
4646 limit = ARRAY_SIZE(snd_hdspm_controls_raydat);
4649 list = snd_hdspm_controls_aes32;
4650 limit = ARRAY_SIZE(snd_hdspm_controls_aes32);
4655 for (idx = 0; idx < limit; idx++) {
4656 err = snd_ctl_add(card,
4657 snd_ctl_new1(&list[idx], hdspm));
4664 /* create simple 1:1 playback mixer controls */
4665 snd_hdspm_playback_mixer.name = "Chn";
4666 if (hdspm->system_sample_rate >= 128000) {
4667 limit = hdspm->qs_out_channels;
4668 } else if (hdspm->system_sample_rate >= 64000) {
4669 limit = hdspm->ds_out_channels;
4671 limit = hdspm->ss_out_channels;
4673 for (idx = 0; idx < limit; ++idx) {
4674 snd_hdspm_playback_mixer.index = idx + 1;
4675 kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm);
4676 err = snd_ctl_add(card, kctl);
4679 hdspm->playback_mixer_ctls[idx] = kctl;
4684 /* add tco control elements */
4685 list = snd_hdspm_controls_tco;
4686 limit = ARRAY_SIZE(snd_hdspm_controls_tco);
4687 for (idx = 0; idx < limit; idx++) {
4688 err = snd_ctl_add(card,
4689 snd_ctl_new1(&list[idx], hdspm));
4698 /*------------------------------------------------------------
4700 ------------------------------------------------------------*/
4703 snd_hdspm_proc_read_tco(struct snd_info_entry *entry,
4704 struct snd_info_buffer *buffer)
4706 struct hdspm *hdspm = entry->private_data;
4707 unsigned int status, control;
4708 int a, ltc, frames, seconds, minutes, hours;
4709 unsigned int period;
4713 snd_iprintf(buffer, "--- TCO ---\n");
4715 status = hdspm_read(hdspm, HDSPM_statusRegister);
4716 control = hdspm->control_register;
4719 if (status & HDSPM_tco_detect) {
4720 snd_iprintf(buffer, "TCO module detected.\n");
4721 a = hdspm_read(hdspm, HDSPM_RD_TCO+4);
4722 if (a & HDSPM_TCO1_LTC_Input_valid) {
4723 snd_iprintf(buffer, " LTC valid, ");
4724 switch (a & (HDSPM_TCO1_LTC_Format_LSB |
4725 HDSPM_TCO1_LTC_Format_MSB)) {
4727 snd_iprintf(buffer, "24 fps, ");
4729 case HDSPM_TCO1_LTC_Format_LSB:
4730 snd_iprintf(buffer, "25 fps, ");
4732 case HDSPM_TCO1_LTC_Format_MSB:
4733 snd_iprintf(buffer, "29.97 fps, ");
4736 snd_iprintf(buffer, "30 fps, ");
4739 if (a & HDSPM_TCO1_set_drop_frame_flag) {
4740 snd_iprintf(buffer, "drop frame\n");
4742 snd_iprintf(buffer, "full frame\n");
4745 snd_iprintf(buffer, " no LTC\n");
4747 if (a & HDSPM_TCO1_Video_Input_Format_NTSC) {
4748 snd_iprintf(buffer, " Video: NTSC\n");
4749 } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) {
4750 snd_iprintf(buffer, " Video: PAL\n");
4752 snd_iprintf(buffer, " No video\n");
4754 if (a & HDSPM_TCO1_TCO_lock) {
4755 snd_iprintf(buffer, " Sync: lock\n");
4757 snd_iprintf(buffer, " Sync: no lock\n");
4760 switch (hdspm->io_type) {
4763 freq_const = 110069313433624ULL;
4767 freq_const = 104857600000000ULL;
4770 break; /* no TCO possible */
4773 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
4774 snd_iprintf(buffer, " period: %u\n", period);
4777 /* rate = freq_const/period; */
4778 rate = div_u64(freq_const, period);
4780 if (control & HDSPM_QuadSpeed) {
4782 } else if (control & HDSPM_DoubleSpeed) {
4786 snd_iprintf(buffer, " Frequency: %u Hz\n",
4787 (unsigned int) rate);
4789 ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
4792 frames += (ltc & 0x3) * 10;
4794 seconds = ltc & 0xF;
4796 seconds += (ltc & 0x7) * 10;
4798 minutes = ltc & 0xF;
4800 minutes += (ltc & 0x7) * 10;
4804 hours += (ltc & 0x3) * 10;
4806 " LTC In: %02d:%02d:%02d:%02d\n",
4807 hours, minutes, seconds, frames);
4810 snd_iprintf(buffer, "No TCO module detected.\n");
4815 snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
4816 struct snd_info_buffer *buffer)
4818 struct hdspm *hdspm = entry->private_data;
4819 unsigned int status, status2, control, freq;
4821 char *pref_sync_ref;
4823 char *system_clock_mode;
4827 status = hdspm_read(hdspm, HDSPM_statusRegister);
4828 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
4829 control = hdspm->control_register;
4830 freq = hdspm_read(hdspm, HDSPM_timecodeRegister);
4832 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
4833 hdspm->card_name, hdspm->card->number + 1,
4834 hdspm->firmware_rev,
4835 (status2 & HDSPM_version0) |
4836 (status2 & HDSPM_version1) | (status2 &
4839 snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n",
4840 (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF,
4843 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
4844 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
4846 snd_iprintf(buffer, "--- System ---\n");
4849 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
4850 status & HDSPM_audioIRQPending,
4851 (status & HDSPM_midi0IRQPending) ? 1 : 0,
4852 (status & HDSPM_midi1IRQPending) ? 1 : 0,
4855 "HW pointer: id = %d, rawptr = %d (%d->%d) "
4856 "estimated= %ld (bytes)\n",
4857 ((status & HDSPM_BufferID) ? 1 : 0),
4858 (status & HDSPM_BufferPositionMask),
4859 (status & HDSPM_BufferPositionMask) %
4860 (2 * (int)hdspm->period_bytes),
4861 ((status & HDSPM_BufferPositionMask) - 64) %
4862 (2 * (int)hdspm->period_bytes),
4863 (long) hdspm_hw_pointer(hdspm) * 4);
4866 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
4867 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
4868 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
4869 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
4870 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
4872 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
4873 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
4874 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
4876 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
4878 hdspm->control_register, hdspm->control2_register,
4882 snd_iprintf(buffer, "--- Settings ---\n");
4884 x = hdspm_get_latency(hdspm);
4887 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
4888 x, (unsigned long) hdspm->period_bytes);
4890 snd_iprintf(buffer, "Line out: %s\n",
4891 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
4893 switch (hdspm->control_register & HDSPM_InputMask) {
4894 case HDSPM_InputOptical:
4897 case HDSPM_InputCoaxial:
4905 "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
4907 (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off",
4908 (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56",
4909 (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off");
4912 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
4913 system_clock_mode = "AutoSync";
4915 system_clock_mode = "Master";
4916 snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode);
4918 switch (hdspm_pref_sync_ref(hdspm)) {
4919 case HDSPM_SYNC_FROM_WORD:
4920 pref_sync_ref = "Word Clock";
4922 case HDSPM_SYNC_FROM_MADI:
4923 pref_sync_ref = "MADI Sync";
4925 case HDSPM_SYNC_FROM_TCO:
4926 pref_sync_ref = "TCO";
4928 case HDSPM_SYNC_FROM_SYNC_IN:
4929 pref_sync_ref = "Sync In";
4932 pref_sync_ref = "XXXX Clock";
4935 snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
4938 snd_iprintf(buffer, "System Clock Frequency: %d\n",
4939 hdspm->system_sample_rate);
4942 snd_iprintf(buffer, "--- Status:\n");
4944 x = status & HDSPM_madiSync;
4945 x2 = status2 & HDSPM_wcSync;
4947 snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
4948 (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
4950 (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
4953 switch (hdspm_autosync_ref(hdspm)) {
4954 case HDSPM_AUTOSYNC_FROM_SYNC_IN:
4955 autosync_ref = "Sync In";
4957 case HDSPM_AUTOSYNC_FROM_TCO:
4958 autosync_ref = "TCO";
4960 case HDSPM_AUTOSYNC_FROM_WORD:
4961 autosync_ref = "Word Clock";
4963 case HDSPM_AUTOSYNC_FROM_MADI:
4964 autosync_ref = "MADI Sync";
4966 case HDSPM_AUTOSYNC_FROM_NONE:
4967 autosync_ref = "Input not valid";
4970 autosync_ref = "---";
4974 "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
4975 autosync_ref, hdspm_external_sample_rate(hdspm),
4976 (status & HDSPM_madiFreqMask) >> 22,
4977 (status2 & HDSPM_wcFreqMask) >> 5);
4979 snd_iprintf(buffer, "Input: %s, Mode=%s\n",
4980 (status & HDSPM_AB_int) ? "Coax" : "Optical",
4981 (status & HDSPM_RX_64ch) ? "64 channels" :
4984 /* call readout function for TCO specific status */
4985 snd_hdspm_proc_read_tco(entry, buffer);
4987 snd_iprintf(buffer, "\n");
4991 snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
4992 struct snd_info_buffer *buffer)
4994 struct hdspm *hdspm = entry->private_data;
4995 unsigned int status;
4996 unsigned int status2;
4997 unsigned int timecode;
4998 unsigned int wcLock, wcSync;
5003 status = hdspm_read(hdspm, HDSPM_statusRegister);
5004 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
5005 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
5007 snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n",
5008 hdspm->card_name, hdspm->card->number + 1,
5009 hdspm->firmware_rev);
5011 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
5012 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
5014 snd_iprintf(buffer, "--- System ---\n");
5017 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
5018 status & HDSPM_audioIRQPending,
5019 (status & HDSPM_midi0IRQPending) ? 1 : 0,
5020 (status & HDSPM_midi1IRQPending) ? 1 : 0,
5023 "HW pointer: id = %d, rawptr = %d (%d->%d) "
5024 "estimated= %ld (bytes)\n",
5025 ((status & HDSPM_BufferID) ? 1 : 0),
5026 (status & HDSPM_BufferPositionMask),
5027 (status & HDSPM_BufferPositionMask) %
5028 (2 * (int)hdspm->period_bytes),
5029 ((status & HDSPM_BufferPositionMask) - 64) %
5030 (2 * (int)hdspm->period_bytes),
5031 (long) hdspm_hw_pointer(hdspm) * 4);
5034 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
5035 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
5036 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
5037 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
5038 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
5040 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
5041 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
5042 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
5044 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
5046 hdspm->control_register, hdspm->control2_register,
5049 snd_iprintf(buffer, "--- Settings ---\n");
5051 x = hdspm_get_latency(hdspm);
5054 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
5055 x, (unsigned long) hdspm->period_bytes);
5057 snd_iprintf(buffer, "Line out: %s\n",
5059 control_register & HDSPM_LineOut) ? "on " : "off");
5062 "ClearTrackMarker %s, Emphasis %s, Dolby %s\n",
5064 control_register & HDSPM_clr_tms) ? "on" : "off",
5066 control_register & HDSPM_Emphasis) ? "on" : "off",
5068 control_register & HDSPM_Dolby) ? "on" : "off");
5071 pref_syncref = hdspm_pref_sync_ref(hdspm);
5072 if (pref_syncref == 0)
5073 snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n");
5075 snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n",
5078 snd_iprintf(buffer, "System Clock Frequency: %d\n",
5079 hdspm->system_sample_rate);
5081 snd_iprintf(buffer, "Double speed: %s\n",
5082 hdspm->control_register & HDSPM_DS_DoubleWire?
5083 "Double wire" : "Single wire");
5084 snd_iprintf(buffer, "Quad speed: %s\n",
5085 hdspm->control_register & HDSPM_QS_DoubleWire?
5087 hdspm->control_register & HDSPM_QS_QuadWire?
5088 "Quad wire" : "Single wire");
5090 snd_iprintf(buffer, "--- Status:\n");
5092 wcLock = status & HDSPM_AES32_wcLock;
5093 wcSync = wcLock && (status & HDSPM_AES32_wcSync);
5095 snd_iprintf(buffer, "Word: %s Frequency: %d\n",
5096 (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock",
5097 HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF));
5099 for (x = 0; x < 8; x++) {
5100 snd_iprintf(buffer, "AES%d: %s Frequency: %d\n",
5102 (status2 & (HDSPM_LockAES >> x)) ?
5103 "Sync " : "No Lock",
5104 HDSPM_bit2freq((timecode >> (4*x)) & 0xF));
5107 switch (hdspm_autosync_ref(hdspm)) {
5108 case HDSPM_AES32_AUTOSYNC_FROM_NONE:
5109 autosync_ref = "None"; break;
5110 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
5111 autosync_ref = "Word Clock"; break;
5112 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
5113 autosync_ref = "AES1"; break;
5114 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
5115 autosync_ref = "AES2"; break;
5116 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
5117 autosync_ref = "AES3"; break;
5118 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
5119 autosync_ref = "AES4"; break;
5120 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
5121 autosync_ref = "AES5"; break;
5122 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
5123 autosync_ref = "AES6"; break;
5124 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
5125 autosync_ref = "AES7"; break;
5126 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
5127 autosync_ref = "AES8"; break;
5129 autosync_ref = "---"; break;
5131 snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref);
5133 snd_iprintf(buffer, "\n");
5137 snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
5138 struct snd_info_buffer *buffer)
5140 struct hdspm *hdspm = entry->private_data;
5141 unsigned int status1, status2, status3, control, i;
5142 unsigned int lock, sync;
5144 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
5145 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
5146 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
5148 control = hdspm->control_register;
5150 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
5151 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
5152 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
5155 snd_iprintf(buffer, "\n*** CLOCK MODE\n\n");
5157 snd_iprintf(buffer, "Clock mode : %s\n",
5158 (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave");
5159 snd_iprintf(buffer, "System frequency: %d Hz\n",
5160 hdspm_get_system_sample_rate(hdspm));
5162 snd_iprintf(buffer, "\n*** INPUT STATUS\n\n");
5167 for (i = 0; i < 8; i++) {
5168 snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n",
5170 (status1 & lock) ? 1 : 0,
5171 (status1 & sync) ? 1 : 0,
5172 texts_freq[(status2 >> (i * 4)) & 0xF]);
5178 snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n",
5179 (status1 & 0x1000000) ? 1 : 0,
5180 (status1 & 0x2000000) ? 1 : 0,
5181 texts_freq[(status1 >> 16) & 0xF]);
5183 snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n",
5184 (status1 & 0x4000000) ? 1 : 0,
5185 (status1 & 0x8000000) ? 1 : 0,
5186 texts_freq[(status1 >> 20) & 0xF]);
5188 snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n",
5189 (status3 & 0x400) ? 1 : 0,
5190 (status3 & 0x800) ? 1 : 0,
5191 texts_freq[(status2 >> 12) & 0xF]);
5195 #ifdef CONFIG_SND_DEBUG
5197 snd_hdspm_proc_read_debug(struct snd_info_entry *entry,
5198 struct snd_info_buffer *buffer)
5200 struct hdspm *hdspm = entry->private_data;
5204 for (i = 0; i < 256 /* 1024*64 */; i += j) {
5205 snd_iprintf(buffer, "0x%08X: ", i);
5206 for (j = 0; j < 16; j += 4)
5207 snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
5208 snd_iprintf(buffer, "\n");
5214 static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry,
5215 struct snd_info_buffer *buffer)
5217 struct hdspm *hdspm = entry->private_data;
5220 snd_iprintf(buffer, "# generated by hdspm\n");
5222 for (i = 0; i < hdspm->max_channels_in; i++) {
5223 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]);
5227 static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry,
5228 struct snd_info_buffer *buffer)
5230 struct hdspm *hdspm = entry->private_data;
5233 snd_iprintf(buffer, "# generated by hdspm\n");
5235 for (i = 0; i < hdspm->max_channels_out; i++) {
5236 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]);
5241 static void snd_hdspm_proc_init(struct hdspm *hdspm)
5243 struct snd_info_entry *entry;
5245 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) {
5246 switch (hdspm->io_type) {
5248 snd_info_set_text_ops(entry, hdspm,
5249 snd_hdspm_proc_read_aes32);
5252 snd_info_set_text_ops(entry, hdspm,
5253 snd_hdspm_proc_read_madi);
5256 /* snd_info_set_text_ops(entry, hdspm,
5257 snd_hdspm_proc_read_madiface); */
5260 snd_info_set_text_ops(entry, hdspm,
5261 snd_hdspm_proc_read_raydat);
5268 if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) {
5269 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in);
5272 if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) {
5273 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out);
5276 #ifdef CONFIG_SND_DEBUG
5277 /* debug file to read all hdspm registers */
5278 if (!snd_card_proc_new(hdspm->card, "debug", &entry))
5279 snd_info_set_text_ops(entry, hdspm,
5280 snd_hdspm_proc_read_debug);
5284 /*------------------------------------------------------------
5286 ------------------------------------------------------------*/
5288 static int snd_hdspm_set_defaults(struct hdspm * hdspm)
5290 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
5291 hold it (e.g. during module initialization).
5296 hdspm->settings_register = 0;
5298 switch (hdspm->io_type) {
5301 hdspm->control_register =
5302 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5307 hdspm->settings_register = 0x1 + 0x1000;
5308 /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0,
5310 hdspm->control_register =
5311 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5315 hdspm->control_register =
5316 HDSPM_ClockModeMaster | /* Master Clock Mode on */
5317 hdspm_encode_latency(7) | /* latency max=8192samples */
5318 HDSPM_SyncRef0 | /* AES1 is syncclock */
5319 HDSPM_LineOut | /* Analog output in */
5320 HDSPM_Professional; /* Professional mode */
5324 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5326 if (AES32 == hdspm->io_type) {
5327 /* No control2 register for AES32 */
5328 #ifdef SNDRV_BIG_ENDIAN
5329 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
5331 hdspm->control2_register = 0;
5334 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
5336 hdspm_compute_period_size(hdspm);
5338 /* silence everything */
5340 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
5342 if (hdspm_is_raydat_or_aio(hdspm))
5343 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
5345 /* set a default rate so that the channel map is set up. */
5346 hdspm_set_rate(hdspm, 48000, 1);
5352 /*------------------------------------------------------------
5354 ------------------------------------------------------------*/
5356 static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
5358 struct hdspm *hdspm = (struct hdspm *) dev_id;
5359 unsigned int status;
5360 int i, audio, midi, schedule = 0;
5363 status = hdspm_read(hdspm, HDSPM_statusRegister);
5365 audio = status & HDSPM_audioIRQPending;
5366 midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending |
5367 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
5369 /* now = get_cycles(); */
5371 * LAT_2..LAT_0 period counter (win) counter (mac)
5372 * 6 4096 ~256053425 ~514672358
5373 * 5 2048 ~128024983 ~257373821
5374 * 4 1024 ~64023706 ~128718089
5375 * 3 512 ~32005945 ~64385999
5376 * 2 256 ~16003039 ~32260176
5377 * 1 128 ~7998738 ~16194507
5378 * 0 64 ~3998231 ~8191558
5381 snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n",
5382 now-hdspm->last_interrupt, status & 0xFFC0);
5383 hdspm->last_interrupt = now;
5386 if (!audio && !midi)
5389 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
5394 if (hdspm->capture_substream)
5395 snd_pcm_period_elapsed(hdspm->capture_substream);
5397 if (hdspm->playback_substream)
5398 snd_pcm_period_elapsed(hdspm->playback_substream);
5403 while (i < hdspm->midiPorts) {
5404 if ((hdspm_read(hdspm,
5405 hdspm->midi[i].statusIn) & 0xff) &&
5406 (status & hdspm->midi[i].irq)) {
5407 /* we disable interrupts for this input until
5408 * processing is done
5410 hdspm->control_register &= ~hdspm->midi[i].ie;
5411 hdspm_write(hdspm, HDSPM_controlRegister,
5412 hdspm->control_register);
5413 hdspm->midi[i].pending = 1;
5421 tasklet_hi_schedule(&hdspm->midi_tasklet);
5427 /*------------------------------------------------------------
5429 ------------------------------------------------------------*/
5432 static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream
5435 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5436 return hdspm_hw_pointer(hdspm);
5440 static int snd_hdspm_reset(struct snd_pcm_substream *substream)
5442 struct snd_pcm_runtime *runtime = substream->runtime;
5443 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5444 struct snd_pcm_substream *other;
5446 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5447 other = hdspm->capture_substream;
5449 other = hdspm->playback_substream;
5452 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
5454 runtime->status->hw_ptr = 0;
5456 struct snd_pcm_substream *s;
5457 struct snd_pcm_runtime *oruntime = other->runtime;
5458 snd_pcm_group_for_each_entry(s, substream) {
5460 oruntime->status->hw_ptr =
5461 runtime->status->hw_ptr;
5469 static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5470 struct snd_pcm_hw_params *params)
5472 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5478 spin_lock_irq(&hdspm->lock);
5480 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5481 this_pid = hdspm->playback_pid;
5482 other_pid = hdspm->capture_pid;
5484 this_pid = hdspm->capture_pid;
5485 other_pid = hdspm->playback_pid;
5488 if (other_pid > 0 && this_pid != other_pid) {
5490 /* The other stream is open, and not by the same
5491 task as this one. Make sure that the parameters
5492 that matter are the same.
5495 if (params_rate(params) != hdspm->system_sample_rate) {
5496 spin_unlock_irq(&hdspm->lock);
5497 _snd_pcm_hw_param_setempty(params,
5498 SNDRV_PCM_HW_PARAM_RATE);
5502 if (params_period_size(params) != hdspm->period_bytes / 4) {
5503 spin_unlock_irq(&hdspm->lock);
5504 _snd_pcm_hw_param_setempty(params,
5505 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
5511 spin_unlock_irq(&hdspm->lock);
5513 /* how to make sure that the rate matches an externally-set one ? */
5515 spin_lock_irq(&hdspm->lock);
5516 err = hdspm_set_rate(hdspm, params_rate(params), 0);
5518 snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err);
5519 spin_unlock_irq(&hdspm->lock);
5520 _snd_pcm_hw_param_setempty(params,
5521 SNDRV_PCM_HW_PARAM_RATE);
5524 spin_unlock_irq(&hdspm->lock);
5526 err = hdspm_set_interrupt_interval(hdspm,
5527 params_period_size(params));
5529 snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err);
5530 _snd_pcm_hw_param_setempty(params,
5531 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
5535 /* Memory allocation, takashi's method, dont know if we should
5538 /* malloc all buffer even if not enabled to get sure */
5539 /* Update for MADI rev 204: we need to allocate for all channels,
5540 * otherwise it doesn't work at 96kHz */
5543 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
5545 snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err);
5549 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5551 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
5552 params_channels(params));
5554 for (i = 0; i < params_channels(params); ++i)
5555 snd_hdspm_enable_out(hdspm, i, 1);
5557 hdspm->playback_buffer =
5558 (unsigned char *) substream->runtime->dma_area;
5559 snd_printdd("Allocated sample buffer for playback at %p\n",
5560 hdspm->playback_buffer);
5562 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
5563 params_channels(params));
5565 for (i = 0; i < params_channels(params); ++i)
5566 snd_hdspm_enable_in(hdspm, i, 1);
5568 hdspm->capture_buffer =
5569 (unsigned char *) substream->runtime->dma_area;
5570 snd_printdd("Allocated sample buffer for capture at %p\n",
5571 hdspm->capture_buffer);
5575 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
5576 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5577 "playback" : "capture",
5578 snd_pcm_sgbuf_get_addr(substream, 0));
5581 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
5582 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5583 "playback" : "capture",
5584 params_rate(params), params_channels(params),
5585 params_buffer_size(params));
5589 /* For AES cards, the float format bit is the same as the
5590 * preferred sync reference. Since we don't want to break
5591 * sync settings, we have to skip the remaining part of this
5594 if (hdspm->io_type == AES32) {
5599 /* Switch to native float format if requested */
5600 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
5601 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
5602 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n");
5604 hdspm->control_register |= HDSPe_FLOAT_FORMAT;
5605 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
5606 if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
5607 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n");
5609 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
5611 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5616 static int snd_hdspm_hw_free(struct snd_pcm_substream *substream)
5619 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5621 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5623 /* params_channels(params) should be enough,
5624 but to get sure in case of error */
5625 for (i = 0; i < hdspm->max_channels_out; ++i)
5626 snd_hdspm_enable_out(hdspm, i, 0);
5628 hdspm->playback_buffer = NULL;
5630 for (i = 0; i < hdspm->max_channels_in; ++i)
5631 snd_hdspm_enable_in(hdspm, i, 0);
5633 hdspm->capture_buffer = NULL;
5637 snd_pcm_lib_free_pages(substream);
5643 static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
5644 struct snd_pcm_channel_info *info)
5646 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5648 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5649 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
5650 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel);
5654 if (hdspm->channel_map_out[info->channel] < 0) {
5655 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel);
5659 info->offset = hdspm->channel_map_out[info->channel] *
5660 HDSPM_CHANNEL_BUFFER_BYTES;
5662 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
5663 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel);
5667 if (hdspm->channel_map_in[info->channel] < 0) {
5668 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel);
5672 info->offset = hdspm->channel_map_in[info->channel] *
5673 HDSPM_CHANNEL_BUFFER_BYTES;
5682 static int snd_hdspm_ioctl(struct snd_pcm_substream *substream,
5683 unsigned int cmd, void *arg)
5686 case SNDRV_PCM_IOCTL1_RESET:
5687 return snd_hdspm_reset(substream);
5689 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
5691 struct snd_pcm_channel_info *info = arg;
5692 return snd_hdspm_channel_info(substream, info);
5698 return snd_pcm_lib_ioctl(substream, cmd, arg);
5701 static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)
5703 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5704 struct snd_pcm_substream *other;
5707 spin_lock(&hdspm->lock);
5708 running = hdspm->running;
5710 case SNDRV_PCM_TRIGGER_START:
5711 running |= 1 << substream->stream;
5713 case SNDRV_PCM_TRIGGER_STOP:
5714 running &= ~(1 << substream->stream);
5718 spin_unlock(&hdspm->lock);
5721 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5722 other = hdspm->capture_substream;
5724 other = hdspm->playback_substream;
5727 struct snd_pcm_substream *s;
5728 snd_pcm_group_for_each_entry(s, substream) {
5730 snd_pcm_trigger_done(s, substream);
5731 if (cmd == SNDRV_PCM_TRIGGER_START)
5732 running |= 1 << s->stream;
5734 running &= ~(1 << s->stream);
5738 if (cmd == SNDRV_PCM_TRIGGER_START) {
5739 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
5740 && substream->stream ==
5741 SNDRV_PCM_STREAM_CAPTURE)
5742 hdspm_silence_playback(hdspm);
5745 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5746 hdspm_silence_playback(hdspm);
5749 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
5750 hdspm_silence_playback(hdspm);
5753 snd_pcm_trigger_done(substream, substream);
5754 if (!hdspm->running && running)
5755 hdspm_start_audio(hdspm);
5756 else if (hdspm->running && !running)
5757 hdspm_stop_audio(hdspm);
5758 hdspm->running = running;
5759 spin_unlock(&hdspm->lock);
5764 static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
5769 static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
5770 .info = (SNDRV_PCM_INFO_MMAP |
5771 SNDRV_PCM_INFO_MMAP_VALID |
5772 SNDRV_PCM_INFO_NONINTERLEAVED |
5773 SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
5774 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5775 .rates = (SNDRV_PCM_RATE_32000 |
5776 SNDRV_PCM_RATE_44100 |
5777 SNDRV_PCM_RATE_48000 |
5778 SNDRV_PCM_RATE_64000 |
5779 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5780 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ),
5784 .channels_max = HDSPM_MAX_CHANNELS,
5786 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5787 .period_bytes_min = (32 * 4),
5788 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5794 static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
5795 .info = (SNDRV_PCM_INFO_MMAP |
5796 SNDRV_PCM_INFO_MMAP_VALID |
5797 SNDRV_PCM_INFO_NONINTERLEAVED |
5798 SNDRV_PCM_INFO_SYNC_START),
5799 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5800 .rates = (SNDRV_PCM_RATE_32000 |
5801 SNDRV_PCM_RATE_44100 |
5802 SNDRV_PCM_RATE_48000 |
5803 SNDRV_PCM_RATE_64000 |
5804 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5805 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000),
5809 .channels_max = HDSPM_MAX_CHANNELS,
5811 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5812 .period_bytes_min = (32 * 4),
5813 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5819 static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5820 struct snd_pcm_hw_rule *rule)
5822 struct hdspm *hdspm = rule->private;
5823 struct snd_interval *c =
5824 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5825 struct snd_interval *r =
5826 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5828 if (r->min > 96000 && r->max <= 192000) {
5829 struct snd_interval t = {
5830 .min = hdspm->qs_in_channels,
5831 .max = hdspm->qs_in_channels,
5834 return snd_interval_refine(c, &t);
5835 } else if (r->min > 48000 && r->max <= 96000) {
5836 struct snd_interval t = {
5837 .min = hdspm->ds_in_channels,
5838 .max = hdspm->ds_in_channels,
5841 return snd_interval_refine(c, &t);
5842 } else if (r->max < 64000) {
5843 struct snd_interval t = {
5844 .min = hdspm->ss_in_channels,
5845 .max = hdspm->ss_in_channels,
5848 return snd_interval_refine(c, &t);
5854 static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
5855 struct snd_pcm_hw_rule * rule)
5857 struct hdspm *hdspm = rule->private;
5858 struct snd_interval *c =
5859 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5860 struct snd_interval *r =
5861 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5863 if (r->min > 96000 && r->max <= 192000) {
5864 struct snd_interval t = {
5865 .min = hdspm->qs_out_channels,
5866 .max = hdspm->qs_out_channels,
5869 return snd_interval_refine(c, &t);
5870 } else if (r->min > 48000 && r->max <= 96000) {
5871 struct snd_interval t = {
5872 .min = hdspm->ds_out_channels,
5873 .max = hdspm->ds_out_channels,
5876 return snd_interval_refine(c, &t);
5877 } else if (r->max < 64000) {
5878 struct snd_interval t = {
5879 .min = hdspm->ss_out_channels,
5880 .max = hdspm->ss_out_channels,
5883 return snd_interval_refine(c, &t);
5889 static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
5890 struct snd_pcm_hw_rule * rule)
5892 struct hdspm *hdspm = rule->private;
5893 struct snd_interval *c =
5894 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5895 struct snd_interval *r =
5896 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5898 if (c->min >= hdspm->ss_in_channels) {
5899 struct snd_interval t = {
5904 return snd_interval_refine(r, &t);
5905 } else if (c->max <= hdspm->qs_in_channels) {
5906 struct snd_interval t = {
5911 return snd_interval_refine(r, &t);
5912 } else if (c->max <= hdspm->ds_in_channels) {
5913 struct snd_interval t = {
5918 return snd_interval_refine(r, &t);
5923 static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
5924 struct snd_pcm_hw_rule *rule)
5926 struct hdspm *hdspm = rule->private;
5927 struct snd_interval *c =
5928 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5929 struct snd_interval *r =
5930 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5932 if (c->min >= hdspm->ss_out_channels) {
5933 struct snd_interval t = {
5938 return snd_interval_refine(r, &t);
5939 } else if (c->max <= hdspm->qs_out_channels) {
5940 struct snd_interval t = {
5945 return snd_interval_refine(r, &t);
5946 } else if (c->max <= hdspm->ds_out_channels) {
5947 struct snd_interval t = {
5952 return snd_interval_refine(r, &t);
5958 static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params,
5959 struct snd_pcm_hw_rule *rule)
5961 unsigned int list[3];
5962 struct hdspm *hdspm = rule->private;
5963 struct snd_interval *c = hw_param_interval(params,
5964 SNDRV_PCM_HW_PARAM_CHANNELS);
5966 list[0] = hdspm->qs_in_channels;
5967 list[1] = hdspm->ds_in_channels;
5968 list[2] = hdspm->ss_in_channels;
5969 return snd_interval_list(c, 3, list, 0);
5972 static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params,
5973 struct snd_pcm_hw_rule *rule)
5975 unsigned int list[3];
5976 struct hdspm *hdspm = rule->private;
5977 struct snd_interval *c = hw_param_interval(params,
5978 SNDRV_PCM_HW_PARAM_CHANNELS);
5980 list[0] = hdspm->qs_out_channels;
5981 list[1] = hdspm->ds_out_channels;
5982 list[2] = hdspm->ss_out_channels;
5983 return snd_interval_list(c, 3, list, 0);
5987 static unsigned int hdspm_aes32_sample_rates[] = {
5988 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
5991 static struct snd_pcm_hw_constraint_list
5992 hdspm_hw_constraints_aes32_sample_rates = {
5993 .count = ARRAY_SIZE(hdspm_aes32_sample_rates),
5994 .list = hdspm_aes32_sample_rates,
5998 static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
6000 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6001 struct snd_pcm_runtime *runtime = substream->runtime;
6003 spin_lock_irq(&hdspm->lock);
6005 snd_pcm_set_sync(substream);
6008 runtime->hw = snd_hdspm_playback_subinfo;
6010 if (hdspm->capture_substream == NULL)
6011 hdspm_stop_audio(hdspm);
6013 hdspm->playback_pid = current->pid;
6014 hdspm->playback_substream = substream;
6016 spin_unlock_irq(&hdspm->lock);
6018 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6019 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6021 switch (hdspm->io_type) {
6024 snd_pcm_hw_constraint_minmax(runtime,
6025 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6027 /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
6028 snd_pcm_hw_constraint_minmax(runtime,
6029 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6034 snd_pcm_hw_constraint_minmax(runtime,
6035 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6040 if (AES32 == hdspm->io_type) {
6041 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6042 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6043 &hdspm_hw_constraints_aes32_sample_rates);
6045 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6046 snd_hdspm_hw_rule_rate_out_channels, hdspm,
6047 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6050 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6051 snd_hdspm_hw_rule_out_channels, hdspm,
6052 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6054 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6055 snd_hdspm_hw_rule_out_channels_rate, hdspm,
6056 SNDRV_PCM_HW_PARAM_RATE, -1);
6061 static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
6063 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6065 spin_lock_irq(&hdspm->lock);
6067 hdspm->playback_pid = -1;
6068 hdspm->playback_substream = NULL;
6070 spin_unlock_irq(&hdspm->lock);
6076 static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6078 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6079 struct snd_pcm_runtime *runtime = substream->runtime;
6081 spin_lock_irq(&hdspm->lock);
6082 snd_pcm_set_sync(substream);
6083 runtime->hw = snd_hdspm_capture_subinfo;
6085 if (hdspm->playback_substream == NULL)
6086 hdspm_stop_audio(hdspm);
6088 hdspm->capture_pid = current->pid;
6089 hdspm->capture_substream = substream;
6091 spin_unlock_irq(&hdspm->lock);
6093 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6094 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6096 switch (hdspm->io_type) {
6099 snd_pcm_hw_constraint_minmax(runtime,
6100 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6102 snd_pcm_hw_constraint_minmax(runtime,
6103 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6108 snd_pcm_hw_constraint_minmax(runtime,
6109 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6114 if (AES32 == hdspm->io_type) {
6115 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6116 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6117 &hdspm_hw_constraints_aes32_sample_rates);
6119 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6120 snd_hdspm_hw_rule_rate_in_channels, hdspm,
6121 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6124 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6125 snd_hdspm_hw_rule_in_channels, hdspm,
6126 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6128 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6129 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6130 SNDRV_PCM_HW_PARAM_RATE, -1);
6135 static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
6137 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6139 spin_lock_irq(&hdspm->lock);
6141 hdspm->capture_pid = -1;
6142 hdspm->capture_substream = NULL;
6144 spin_unlock_irq(&hdspm->lock);
6148 static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
6150 /* we have nothing to initialize but the call is required */
6154 static inline int copy_u32_le(void __user *dest, void __iomem *src)
6156 u32 val = readl(src);
6157 return copy_to_user(dest, &val, 4);
6160 static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6161 unsigned int cmd, unsigned long arg)
6163 void __user *argp = (void __user *)arg;
6164 struct hdspm *hdspm = hw->private_data;
6165 struct hdspm_mixer_ioctl mixer;
6166 struct hdspm_config info;
6167 struct hdspm_status status;
6168 struct hdspm_version hdspm_version;
6169 struct hdspm_peak_rms *levels;
6170 struct hdspm_ltc ltc;
6171 unsigned int statusregister;
6172 long unsigned int s;
6177 case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
6178 levels = &hdspm->peak_rms;
6179 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
6180 levels->input_peaks[i] =
6181 readl(hdspm->iobase +
6182 HDSPM_MADI_INPUT_PEAK + i*4);
6183 levels->playback_peaks[i] =
6184 readl(hdspm->iobase +
6185 HDSPM_MADI_PLAYBACK_PEAK + i*4);
6186 levels->output_peaks[i] =
6187 readl(hdspm->iobase +
6188 HDSPM_MADI_OUTPUT_PEAK + i*4);
6190 levels->input_rms[i] =
6191 ((uint64_t) readl(hdspm->iobase +
6192 HDSPM_MADI_INPUT_RMS_H + i*4) << 32) |
6193 (uint64_t) readl(hdspm->iobase +
6194 HDSPM_MADI_INPUT_RMS_L + i*4);
6195 levels->playback_rms[i] =
6196 ((uint64_t)readl(hdspm->iobase +
6197 HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) |
6198 (uint64_t)readl(hdspm->iobase +
6199 HDSPM_MADI_PLAYBACK_RMS_L + i*4);
6200 levels->output_rms[i] =
6201 ((uint64_t)readl(hdspm->iobase +
6202 HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) |
6203 (uint64_t)readl(hdspm->iobase +
6204 HDSPM_MADI_OUTPUT_RMS_L + i*4);
6207 if (hdspm->system_sample_rate > 96000) {
6209 } else if (hdspm->system_sample_rate > 48000) {
6214 levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
6216 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
6218 /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu
6219 [Levels]\n", sizeof(struct hdspm_peak_rms), s);
6225 case SNDRV_HDSPM_IOCTL_GET_LTC:
6226 ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
6227 i = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
6228 if (i & HDSPM_TCO1_LTC_Input_valid) {
6229 switch (i & (HDSPM_TCO1_LTC_Format_LSB |
6230 HDSPM_TCO1_LTC_Format_MSB)) {
6232 ltc.format = fps_24;
6234 case HDSPM_TCO1_LTC_Format_LSB:
6235 ltc.format = fps_25;
6237 case HDSPM_TCO1_LTC_Format_MSB:
6238 ltc.format = fps_2997;
6244 if (i & HDSPM_TCO1_set_drop_frame_flag) {
6245 ltc.frame = drop_frame;
6247 ltc.frame = full_frame;
6250 ltc.format = format_invalid;
6251 ltc.frame = frame_invalid;
6253 if (i & HDSPM_TCO1_Video_Input_Format_NTSC) {
6254 ltc.input_format = ntsc;
6255 } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) {
6256 ltc.input_format = pal;
6258 ltc.input_format = no_video;
6261 s = copy_to_user(argp, <c, sizeof(struct hdspm_ltc));
6264 snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
6270 case SNDRV_HDSPM_IOCTL_GET_CONFIG:
6272 memset(&info, 0, sizeof(info));
6273 spin_lock_irq(&hdspm->lock);
6274 info.pref_sync_ref = hdspm_pref_sync_ref(hdspm);
6275 info.wordclock_sync_check = hdspm_wc_sync_check(hdspm);
6277 info.system_sample_rate = hdspm->system_sample_rate;
6278 info.autosync_sample_rate =
6279 hdspm_external_sample_rate(hdspm);
6280 info.system_clock_mode = hdspm_system_clock_mode(hdspm);
6281 info.clock_source = hdspm_clock_source(hdspm);
6282 info.autosync_ref = hdspm_autosync_ref(hdspm);
6283 info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut);
6285 spin_unlock_irq(&hdspm->lock);
6286 if (copy_to_user(argp, &info, sizeof(info)))
6290 case SNDRV_HDSPM_IOCTL_GET_STATUS:
6291 memset(&status, 0, sizeof(status));
6293 status.card_type = hdspm->io_type;
6295 status.autosync_source = hdspm_autosync_ref(hdspm);
6297 status.card_clock = 110069313433624ULL;
6298 status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
6300 switch (hdspm->io_type) {
6303 status.card_specific.madi.sync_wc =
6304 hdspm_wc_sync_check(hdspm);
6305 status.card_specific.madi.sync_madi =
6306 hdspm_madi_sync_check(hdspm);
6307 status.card_specific.madi.sync_tco =
6308 hdspm_tco_sync_check(hdspm);
6309 status.card_specific.madi.sync_in =
6310 hdspm_sync_in_sync_check(hdspm);
6313 hdspm_read(hdspm, HDSPM_statusRegister);
6314 status.card_specific.madi.madi_input =
6315 (statusregister & HDSPM_AB_int) ? 1 : 0;
6316 status.card_specific.madi.channel_format =
6317 (statusregister & HDSPM_RX_64ch) ? 1 : 0;
6318 /* TODO: Mac driver sets it when f_s>48kHz */
6319 status.card_specific.madi.frame_format = 0;
6325 if (copy_to_user(argp, &status, sizeof(status)))
6331 case SNDRV_HDSPM_IOCTL_GET_VERSION:
6332 memset(&hdspm_version, 0, sizeof(hdspm_version));
6334 hdspm_version.card_type = hdspm->io_type;
6335 strncpy(hdspm_version.cardname, hdspm->card_name,
6336 sizeof(hdspm_version.cardname));
6337 hdspm_version.serial = hdspm->serial;
6338 hdspm_version.firmware_rev = hdspm->firmware_rev;
6339 hdspm_version.addons = 0;
6341 hdspm_version.addons |= HDSPM_ADDON_TCO;
6343 if (copy_to_user(argp, &hdspm_version,
6344 sizeof(hdspm_version)))
6348 case SNDRV_HDSPM_IOCTL_GET_MIXER:
6349 if (copy_from_user(&mixer, argp, sizeof(mixer)))
6351 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
6352 sizeof(struct hdspm_mixer)))
6362 static struct snd_pcm_ops snd_hdspm_playback_ops = {
6363 .open = snd_hdspm_playback_open,
6364 .close = snd_hdspm_playback_release,
6365 .ioctl = snd_hdspm_ioctl,
6366 .hw_params = snd_hdspm_hw_params,
6367 .hw_free = snd_hdspm_hw_free,
6368 .prepare = snd_hdspm_prepare,
6369 .trigger = snd_hdspm_trigger,
6370 .pointer = snd_hdspm_hw_pointer,
6371 .page = snd_pcm_sgbuf_ops_page,
6374 static struct snd_pcm_ops snd_hdspm_capture_ops = {
6375 .open = snd_hdspm_capture_open,
6376 .close = snd_hdspm_capture_release,
6377 .ioctl = snd_hdspm_ioctl,
6378 .hw_params = snd_hdspm_hw_params,
6379 .hw_free = snd_hdspm_hw_free,
6380 .prepare = snd_hdspm_prepare,
6381 .trigger = snd_hdspm_trigger,
6382 .pointer = snd_hdspm_hw_pointer,
6383 .page = snd_pcm_sgbuf_ops_page,
6386 static int snd_hdspm_create_hwdep(struct snd_card *card,
6387 struct hdspm *hdspm)
6389 struct snd_hwdep *hw;
6392 err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw);
6397 hw->private_data = hdspm;
6398 strcpy(hw->name, "HDSPM hwdep interface");
6400 hw->ops.open = snd_hdspm_hwdep_dummy_op;
6401 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
6402 hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl;
6403 hw->ops.release = snd_hdspm_hwdep_dummy_op;
6409 /*------------------------------------------------------------
6411 ------------------------------------------------------------*/
6412 static int snd_hdspm_preallocate_memory(struct hdspm *hdspm)
6415 struct snd_pcm *pcm;
6420 wanted = HDSPM_DMA_AREA_BYTES;
6423 snd_pcm_lib_preallocate_pages_for_all(pcm,
6424 SNDRV_DMA_TYPE_DEV_SG,
6425 snd_dma_pci_data(hdspm->pci),
6429 snd_printdd("Could not preallocate %zd Bytes\n", wanted);
6433 snd_printdd(" Preallocated %zd Bytes\n", wanted);
6439 static void hdspm_set_sgbuf(struct hdspm *hdspm,
6440 struct snd_pcm_substream *substream,
6441 unsigned int reg, int channels)
6445 /* continuous memory segment */
6446 for (i = 0; i < (channels * 16); i++)
6447 hdspm_write(hdspm, reg + 4 * i,
6448 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
6452 /* ------------- ALSA Devices ---------------------------- */
6453 static int snd_hdspm_create_pcm(struct snd_card *card,
6454 struct hdspm *hdspm)
6456 struct snd_pcm *pcm;
6459 err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm);
6464 pcm->private_data = hdspm;
6465 strcpy(pcm->name, hdspm->card_name);
6467 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6468 &snd_hdspm_playback_ops);
6469 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6470 &snd_hdspm_capture_ops);
6472 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6474 err = snd_hdspm_preallocate_memory(hdspm);
6481 static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
6485 for (i = 0; i < hdspm->midiPorts; i++)
6486 snd_hdspm_flush_midi_input(hdspm, i);
6489 static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6490 struct hdspm *hdspm)
6494 snd_printdd("Create card...\n");
6495 err = snd_hdspm_create_pcm(card, hdspm);
6500 while (i < hdspm->midiPorts) {
6501 err = snd_hdspm_create_midi(card, hdspm, i);
6508 err = snd_hdspm_create_controls(card, hdspm);
6512 err = snd_hdspm_create_hwdep(card, hdspm);
6516 snd_printdd("proc init...\n");
6517 snd_hdspm_proc_init(hdspm);
6519 hdspm->system_sample_rate = -1;
6520 hdspm->last_external_sample_rate = -1;
6521 hdspm->last_internal_sample_rate = -1;
6522 hdspm->playback_pid = -1;
6523 hdspm->capture_pid = -1;
6524 hdspm->capture_substream = NULL;
6525 hdspm->playback_substream = NULL;
6527 snd_printdd("Set defaults...\n");
6528 err = snd_hdspm_set_defaults(hdspm);
6532 snd_printdd("Update mixer controls...\n");
6533 hdspm_update_simple_mixer_controls(hdspm);
6535 snd_printdd("Initializeing complete ???\n");
6537 err = snd_card_register(card);
6539 snd_printk(KERN_ERR "HDSPM: error registering card\n");
6543 snd_printdd("... yes now\n");
6548 static int snd_hdspm_create(struct snd_card *card,
6549 struct hdspm *hdspm)
6552 struct pci_dev *pci = hdspm->pci;
6554 unsigned long io_extent;
6559 spin_lock_init(&hdspm->lock);
6561 pci_read_config_word(hdspm->pci,
6562 PCI_CLASS_REVISION, &hdspm->firmware_rev);
6564 strcpy(card->mixername, "Xilinx FPGA");
6565 strcpy(card->driver, "HDSPM");
6567 switch (hdspm->firmware_rev) {
6568 case HDSPM_RAYDAT_REV:
6569 hdspm->io_type = RayDAT;
6570 hdspm->card_name = "RME RayDAT";
6571 hdspm->midiPorts = 2;
6574 hdspm->io_type = AIO;
6575 hdspm->card_name = "RME AIO";
6576 hdspm->midiPorts = 1;
6578 case HDSPM_MADIFACE_REV:
6579 hdspm->io_type = MADIface;
6580 hdspm->card_name = "RME MADIface";
6581 hdspm->midiPorts = 1;
6584 if ((hdspm->firmware_rev == 0xf0) ||
6585 ((hdspm->firmware_rev >= 0xe6) &&
6586 (hdspm->firmware_rev <= 0xea))) {
6587 hdspm->io_type = AES32;
6588 hdspm->card_name = "RME AES32";
6589 hdspm->midiPorts = 2;
6590 } else if ((hdspm->firmware_rev == 0xd2) ||
6591 ((hdspm->firmware_rev >= 0xc8) &&
6592 (hdspm->firmware_rev <= 0xcf))) {
6593 hdspm->io_type = MADI;
6594 hdspm->card_name = "RME MADI";
6595 hdspm->midiPorts = 3;
6598 "HDSPM: unknown firmware revision %x\n",
6599 hdspm->firmware_rev);
6604 err = pci_enable_device(pci);
6608 pci_set_master(hdspm->pci);
6610 err = pci_request_regions(pci, "hdspm");
6614 hdspm->port = pci_resource_start(pci, 0);
6615 io_extent = pci_resource_len(pci, 0);
6617 snd_printdd("grabbed memory region 0x%lx-0x%lx\n",
6618 hdspm->port, hdspm->port + io_extent - 1);
6620 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
6621 if (!hdspm->iobase) {
6622 snd_printk(KERN_ERR "HDSPM: "
6623 "unable to remap region 0x%lx-0x%lx\n",
6624 hdspm->port, hdspm->port + io_extent - 1);
6627 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n",
6628 (unsigned long)hdspm->iobase, hdspm->port,
6629 hdspm->port + io_extent - 1);
6631 if (request_irq(pci->irq, snd_hdspm_interrupt,
6632 IRQF_SHARED, KBUILD_MODNAME, hdspm)) {
6633 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq);
6637 snd_printdd("use IRQ %d\n", pci->irq);
6639 hdspm->irq = pci->irq;
6641 snd_printdd("kmalloc Mixer memory of %zd Bytes\n",
6642 sizeof(struct hdspm_mixer));
6643 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
6644 if (!hdspm->mixer) {
6645 snd_printk(KERN_ERR "HDSPM: "
6646 "unable to kmalloc Mixer memory of %d Bytes\n",
6647 (int)sizeof(struct hdspm_mixer));
6651 hdspm->port_names_in = NULL;
6652 hdspm->port_names_out = NULL;
6654 switch (hdspm->io_type) {
6656 hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS;
6657 hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS;
6658 hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS;
6660 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6662 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6664 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6666 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6668 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6670 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6673 hdspm->max_channels_out = hdspm->max_channels_in =
6675 hdspm->port_names_in = hdspm->port_names_out =
6677 hdspm->channel_map_in = hdspm->channel_map_out =
6684 hdspm->ss_in_channels = hdspm->ss_out_channels =
6686 hdspm->ds_in_channels = hdspm->ds_out_channels =
6688 hdspm->qs_in_channels = hdspm->qs_out_channels =
6691 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6692 channel_map_unity_ss;
6693 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6694 channel_map_unity_ss;
6695 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6696 channel_map_unity_ss;
6698 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6700 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6702 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6707 hdspm->ss_in_channels = AIO_IN_SS_CHANNELS;
6708 hdspm->ds_in_channels = AIO_IN_DS_CHANNELS;
6709 hdspm->qs_in_channels = AIO_IN_QS_CHANNELS;
6710 hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS;
6711 hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS;
6712 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
6714 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
6715 snd_printk(KERN_INFO "HDSPM: AEB input board found\n");
6716 hdspm->ss_in_channels += 4;
6717 hdspm->ds_in_channels += 4;
6718 hdspm->qs_in_channels += 4;
6721 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) {
6722 snd_printk(KERN_INFO "HDSPM: AEB output board found\n");
6723 hdspm->ss_out_channels += 4;
6724 hdspm->ds_out_channels += 4;
6725 hdspm->qs_out_channels += 4;
6728 hdspm->channel_map_out_ss = channel_map_aio_out_ss;
6729 hdspm->channel_map_out_ds = channel_map_aio_out_ds;
6730 hdspm->channel_map_out_qs = channel_map_aio_out_qs;
6732 hdspm->channel_map_in_ss = channel_map_aio_in_ss;
6733 hdspm->channel_map_in_ds = channel_map_aio_in_ds;
6734 hdspm->channel_map_in_qs = channel_map_aio_in_qs;
6736 hdspm->port_names_in_ss = texts_ports_aio_in_ss;
6737 hdspm->port_names_out_ss = texts_ports_aio_out_ss;
6738 hdspm->port_names_in_ds = texts_ports_aio_in_ds;
6739 hdspm->port_names_out_ds = texts_ports_aio_out_ds;
6740 hdspm->port_names_in_qs = texts_ports_aio_in_qs;
6741 hdspm->port_names_out_qs = texts_ports_aio_out_qs;
6746 hdspm->ss_in_channels = hdspm->ss_out_channels =
6748 hdspm->ds_in_channels = hdspm->ds_out_channels =
6750 hdspm->qs_in_channels = hdspm->qs_out_channels =
6753 hdspm->max_channels_in = RAYDAT_SS_CHANNELS;
6754 hdspm->max_channels_out = RAYDAT_SS_CHANNELS;
6756 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6757 channel_map_raydat_ss;
6758 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6759 channel_map_raydat_ds;
6760 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6761 channel_map_raydat_qs;
6762 hdspm->channel_map_in = hdspm->channel_map_out =
6763 channel_map_raydat_ss;
6765 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6766 texts_ports_raydat_ss;
6767 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6768 texts_ports_raydat_ds;
6769 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6770 texts_ports_raydat_qs;
6778 switch (hdspm->io_type) {
6781 if (hdspm_read(hdspm, HDSPM_statusRegister2) &
6782 HDSPM_s2_tco_detect) {
6784 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6786 if (NULL != hdspm->tco) {
6787 hdspm_tco_write(hdspm);
6789 snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n");
6796 if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) {
6798 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6800 if (NULL != hdspm->tco) {
6801 hdspm_tco_write(hdspm);
6803 snd_printk(KERN_INFO "HDSPM: MADI/AES TCO module found\n");
6814 switch (hdspm->io_type) {
6817 hdspm->texts_autosync = texts_autosync_aes_tco;
6818 hdspm->texts_autosync_items =
6819 ARRAY_SIZE(texts_autosync_aes_tco);
6821 hdspm->texts_autosync = texts_autosync_aes;
6822 hdspm->texts_autosync_items =
6823 ARRAY_SIZE(texts_autosync_aes);
6829 hdspm->texts_autosync = texts_autosync_madi_tco;
6830 hdspm->texts_autosync_items = 4;
6832 hdspm->texts_autosync = texts_autosync_madi;
6833 hdspm->texts_autosync_items = 3;
6843 hdspm->texts_autosync = texts_autosync_raydat_tco;
6844 hdspm->texts_autosync_items = 9;
6846 hdspm->texts_autosync = texts_autosync_raydat;
6847 hdspm->texts_autosync_items = 8;
6853 hdspm->texts_autosync = texts_autosync_aio_tco;
6854 hdspm->texts_autosync_items = 6;
6856 hdspm->texts_autosync = texts_autosync_aio;
6857 hdspm->texts_autosync_items = 5;
6863 tasklet_init(&hdspm->midi_tasklet,
6864 hdspm_midi_tasklet, (unsigned long) hdspm);
6867 if (hdspm->io_type != MADIface) {
6868 hdspm->serial = (hdspm_read(hdspm,
6869 HDSPM_midiStatusIn0)>>8) & 0xFFFFFF;
6870 /* id contains either a user-provided value or the default
6871 * NULL. If it's the default, we're safe to
6872 * fill card->id with the serial number.
6874 * If the serial number is 0xFFFFFF, then we're dealing with
6875 * an old PCI revision that comes without a sane number. In
6876 * this case, we don't set card->id to avoid collisions
6877 * when running with multiple cards.
6879 if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) {
6880 sprintf(card->id, "HDSPMx%06x", hdspm->serial);
6881 snd_card_set_id(card, card->id);
6885 snd_printdd("create alsa devices.\n");
6886 err = snd_hdspm_create_alsa_devices(card, hdspm);
6890 snd_hdspm_initialize_midi_flush(hdspm);
6896 static int snd_hdspm_free(struct hdspm * hdspm)
6901 /* stop th audio, and cancel all interrupts */
6902 hdspm->control_register &=
6903 ~(HDSPM_Start | HDSPM_AudioInterruptEnable |
6904 HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable |
6905 HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable);
6906 hdspm_write(hdspm, HDSPM_controlRegister,
6907 hdspm->control_register);
6910 if (hdspm->irq >= 0)
6911 free_irq(hdspm->irq, (void *) hdspm);
6913 kfree(hdspm->mixer);
6916 iounmap(hdspm->iobase);
6919 pci_release_regions(hdspm->pci);
6921 pci_disable_device(hdspm->pci);
6926 static void snd_hdspm_card_free(struct snd_card *card)
6928 struct hdspm *hdspm = card->private_data;
6931 snd_hdspm_free(hdspm);
6935 static int snd_hdspm_probe(struct pci_dev *pci,
6936 const struct pci_device_id *pci_id)
6939 struct hdspm *hdspm;
6940 struct snd_card *card;
6943 if (dev >= SNDRV_CARDS)
6950 err = snd_card_create(index[dev], id[dev],
6951 THIS_MODULE, sizeof(struct hdspm), &card);
6955 hdspm = card->private_data;
6956 card->private_free = snd_hdspm_card_free;
6960 snd_card_set_dev(card, &pci->dev);
6962 err = snd_hdspm_create(card, hdspm);
6964 snd_card_free(card);
6968 if (hdspm->io_type != MADIface) {
6969 sprintf(card->shortname, "%s_%x",
6972 sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d",
6975 hdspm->port, hdspm->irq);
6977 sprintf(card->shortname, "%s", hdspm->card_name);
6978 sprintf(card->longname, "%s at 0x%lx, irq %d",
6979 hdspm->card_name, hdspm->port, hdspm->irq);
6982 err = snd_card_register(card);
6984 snd_card_free(card);
6988 pci_set_drvdata(pci, card);
6994 static void snd_hdspm_remove(struct pci_dev *pci)
6996 snd_card_free(pci_get_drvdata(pci));
6999 static struct pci_driver hdspm_driver = {
7000 .name = KBUILD_MODNAME,
7001 .id_table = snd_hdspm_ids,
7002 .probe = snd_hdspm_probe,
7003 .remove = snd_hdspm_remove,
7006 module_pci_driver(hdspm_driver);