blob: 26f10fdbfcd62acd4eb24d0e76523e479e372a36 [file] [log] [blame]
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001/*
Takashi Iwai763f3562005-06-03 11:25:34 +02002 * ALSA driver for RME Hammerfall DSP MADI audio interface(s)
3 *
4 * Copyright (c) 2003 Winfried Ritsch (IEM)
5 * code based on hdsp.c Paul Davis
6 * Marcus Andersson
7 * Thomas Charbonnel
Remy Bruno3cee5a62006-10-16 12:46:32 +02008 * Modified 2006-06-01 for AES32 support by Remy Bruno
9 * <remy.bruno@trinnov.com>
Takashi Iwai763f3562005-06-03 11:25:34 +020010 *
Adrian Knoth0dca1792011-01-26 19:32:14 +010011 * Modified 2009-04-13 for proper metering by Florian Faber
12 * <faber@faberman.de>
13 *
14 * Modified 2009-04-14 for native float support by Florian Faber
15 * <faber@faberman.de>
16 *
17 * Modified 2009-04-26 fixed bug in rms metering by Florian Faber
18 * <faber@faberman.de>
19 *
20 * Modified 2009-04-30 added hw serial number support by Florian Faber
21 *
22 * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth
23 *
24 * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth
25 *
Takashi Iwai763f3562005-06-03 11:25:34 +020026 * 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.
30 *
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.
35 *
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
39 *
40 */
Takashi Iwai763f3562005-06-03 11:25:34 +020041#include <linux/init.h>
42#include <linux/delay.h>
43#include <linux/interrupt.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040044#include <linux/module.h>
Takashi Iwai763f3562005-06-03 11:25:34 +020045#include <linux/slab.h>
46#include <linux/pci.h>
Takashi Iwai3f7440a2009-06-05 17:40:04 +020047#include <linux/math64.h>
Takashi Iwai763f3562005-06-03 11:25:34 +020048#include <asm/io.h>
49
50#include <sound/core.h>
51#include <sound/control.h>
52#include <sound/pcm.h>
Adrian Knoth0dca1792011-01-26 19:32:14 +010053#include <sound/pcm_params.h>
Takashi Iwai763f3562005-06-03 11:25:34 +020054#include <sound/info.h>
55#include <sound/asoundef.h>
56#include <sound/rawmidi.h>
57#include <sound/hwdep.h>
58#include <sound/initval.h>
59
60#include <sound/hdspm.h>
61
62static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
63static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103064static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
Takashi Iwai763f3562005-06-03 11:25:34 +020065
Takashi Iwai763f3562005-06-03 11:25:34 +020066module_param_array(index, int, NULL, 0444);
67MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
68
69module_param_array(id, charp, NULL, 0444);
70MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
71
72module_param_array(enable, bool, NULL, 0444);
73MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
74
Takashi Iwai763f3562005-06-03 11:25:34 +020075
76MODULE_AUTHOR
Adrian Knoth0dca1792011-01-26 19:32:14 +010077(
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>"
84);
Takashi Iwai763f3562005-06-03 11:25:34 +020085MODULE_DESCRIPTION("RME HDSPM");
86MODULE_LICENSE("GPL");
87MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
88
Adrian Knoth0dca1792011-01-26 19:32:14 +010089/* --- Write registers. ---
Takashi Iwai763f3562005-06-03 11:25:34 +020090 These are defined as byte-offsets from the iobase value. */
91
Adrian Knoth0dca1792011-01-26 19:32:14 +010092#define HDSPM_WR_SETTINGS 0
93#define HDSPM_outputBufferAddress 32
94#define HDSPM_inputBufferAddress 36
Takashi Iwai763f3562005-06-03 11:25:34 +020095#define HDSPM_controlRegister 64
96#define HDSPM_interruptConfirmation 96
97#define HDSPM_control2Reg 256 /* not in specs ???????? */
Remy Brunoffb2c3c2007-03-07 19:08:46 +010098#define HDSPM_freqReg 256 /* for AES32 */
Adrian Knoth0dca1792011-01-26 19:32:14 +010099#define HDSPM_midiDataOut0 352 /* just believe in old code */
100#define HDSPM_midiDataOut1 356
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100101#define HDSPM_eeprom_wr 384 /* for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200102
103/* DMA enable for 64 channels, only Bit 0 is relevant */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100104#define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
Takashi Iwai763f3562005-06-03 11:25:34 +0200105#define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
106
Adrian Knoth0dca1792011-01-26 19:32:14 +0100107/* 16 page addresses for each of the 64 channels DMA buffer in and out
Takashi Iwai763f3562005-06-03 11:25:34 +0200108 (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)
111
112#define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */
113
114#define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */
115
116/* --- Read registers. ---
117 These are defined as byte-offsets from the iobase value */
118#define HDSPM_statusRegister 0
Remy Bruno3cee5a62006-10-16 12:46:32 +0200119/*#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
Takashi Iwai763f3562005-06-03 11:25:34 +0200125
Adrian Knoth0dca1792011-01-26 19:32:14 +0100126/* AIO, RayDAT */
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
131
132#define HDSPM_RD_TCO 256
133#define HDSPM_RD_PLL_FREQ 512
134#define HDSPM_WR_TCO 128
135
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
143
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
148
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
156
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
165
166
167#define HDSPM_midiDataOut0 352
168#define HDSPM_midiDataOut1 356
169#define HDSPM_midiDataOut2 368
170
Takashi Iwai763f3562005-06-03 11:25:34 +0200171#define HDSPM_midiDataIn0 360
172#define HDSPM_midiDataIn1 364
Adrian Knoth0dca1792011-01-26 19:32:14 +0100173#define HDSPM_midiDataIn2 372
174#define HDSPM_midiDataIn3 376
Takashi Iwai763f3562005-06-03 11:25:34 +0200175
176/* status is data bytes in MIDI-FIFO (0-128) */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100177#define HDSPM_midiStatusOut0 384
178#define HDSPM_midiStatusOut1 388
179#define HDSPM_midiStatusOut2 400
180
181#define HDSPM_midiStatusIn0 392
182#define HDSPM_midiStatusIn1 396
183#define HDSPM_midiStatusIn2 404
184#define HDSPM_midiStatusIn3 408
Takashi Iwai763f3562005-06-03 11:25:34 +0200185
186
187/* the meters are regular i/o-mapped registers, but offset
188 considerably from the rest. the peak registers are reset
Adrian Knoth0dca1792011-01-26 19:32:14 +0100189 when read; the least-significant 4 bits are full-scale counters;
Takashi Iwai763f3562005-06-03 11:25:34 +0200190 the actual peak value is in the most-significant 24 bits.
191*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100192
193#define HDSPM_MADI_INPUT_PEAK 4096
194#define HDSPM_MADI_PLAYBACK_PEAK 4352
195#define HDSPM_MADI_OUTPUT_PEAK 4608
196
197#define HDSPM_MADI_INPUT_RMS_L 6144
198#define HDSPM_MADI_PLAYBACK_RMS_L 6400
199#define HDSPM_MADI_OUTPUT_RMS_L 6656
200
201#define HDSPM_MADI_INPUT_RMS_H 7168
202#define HDSPM_MADI_PLAYBACK_RMS_H 7424
203#define HDSPM_MADI_OUTPUT_RMS_H 7680
Takashi Iwai763f3562005-06-03 11:25:34 +0200204
205/* --- Control Register bits --------- */
206#define HDSPM_Start (1<<0) /* start engine */
207
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} */
211
Adrian Knoth0dca1792011-01-26 19:32:14 +0100212#define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */
213#define HDSPM_c0Master 0x1 /* Master clock bit in settings
214 register [RayDAT, AIO] */
Takashi Iwai763f3562005-06-03 11:25:34 +0200215
216#define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */
217
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 */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200221#define HDSPM_QuadSpeed (1<<31) /* quad speed bit */
Takashi Iwai763f3562005-06-03 11:25:34 +0200222
Remy Bruno3cee5a62006-10-16 12:46:32 +0200223#define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200224#define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200225 56channelMODE=0 */ /* MADI ONLY*/
226#define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200227
Adrian Knoth0dca1792011-01-26 19:32:14 +0100228#define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200229 0=off, 1=on */ /* MADI ONLY */
230#define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200231
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200232#define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax
233 * -- MADI ONLY
234 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200235#define HDSPM_InputSelect1 (1<<15) /* should be 0 */
236
Remy Bruno3cee5a62006-10-16 12:46:32 +0200237#define HDSPM_SyncRef2 (1<<13)
238#define HDSPM_SyncRef3 (1<<25)
Takashi Iwai763f3562005-06-03 11:25:34 +0200239
Remy Bruno3cee5a62006-10-16 12:46:32 +0200240#define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100241#define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
Takashi Iwai763f3562005-06-03 11:25:34 +0200242 AES additional bits in
243 lower 5 Audiodatabits ??? */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200244#define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */
245#define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200246
Adrian Knoth0dca1792011-01-26 19:32:14 +0100247#define HDSPM_Midi0InterruptEnable 0x0400000
248#define HDSPM_Midi1InterruptEnable 0x0800000
249#define HDSPM_Midi2InterruptEnable 0x0200000
250#define HDSPM_Midi3InterruptEnable 0x4000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200251
252#define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100253#define HDSPe_FLOAT_FORMAT 0x2000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200254
Remy Bruno3cee5a62006-10-16 12:46:32 +0200255#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 */
258
259#define HDSPM_wclk_sel (1<<30)
Takashi Iwai763f3562005-06-03 11:25:34 +0200260
Adrian Knoth384f7782013-07-05 11:27:53 +0200261/* 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
278
279
Takashi Iwai763f3562005-06-03 11:25:34 +0200280/* --- bit helper defines */
281#define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200282#define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\
283 HDSPM_DoubleSpeed|HDSPM_QuadSpeed)
Takashi Iwai763f3562005-06-03 11:25:34 +0200284#define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
285#define HDSPM_InputOptical 0
286#define HDSPM_InputCoaxial (HDSPM_InputSelect0)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200287#define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\
288 HDSPM_SyncRef2|HDSPM_SyncRef3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200289
Adrian Knoth0dca1792011-01-26 19:32:14 +0100290#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)
296
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
Takashi Iwai763f3562005-06-03 11:25:34 +0200301
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)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200307#define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\
308 HDSPM_Frequency0)
Remy Bruno3cee5a62006-10-16 12:46:32 +0200309#define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0)
310#define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200311#define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\
312 HDSPM_Frequency0)
Takashi Iwai763f3562005-06-03 11:25:34 +0200313
Takashi Iwai763f3562005-06-03 11:25:34 +0200314
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
319
320/* AutoSync References - used by "autosync_ref" control switch */
321#define HDSPM_AUTOSYNC_FROM_WORD 0
322#define HDSPM_AUTOSYNC_FROM_MADI 1
Adrian Knoth0dca1792011-01-26 19:32:14 +0100323#define HDSPM_AUTOSYNC_FROM_TCO 2
324#define HDSPM_AUTOSYNC_FROM_SYNC_IN 3
325#define HDSPM_AUTOSYNC_FROM_NONE 4
Takashi Iwai763f3562005-06-03 11:25:34 +0200326
327/* Possible sources of MADI input */
328#define HDSPM_OPTICAL 0 /* optical */
329#define HDSPM_COAXIAL 1 /* BNC */
330
331#define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100332#define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1))
Takashi Iwai763f3562005-06-03 11:25:34 +0200333
334#define hdspm_encode_in(x) (((x)&0x3)<<14)
335#define hdspm_decode_in(x) (((x)>>14)&0x3)
336
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)
349
Remy Bruno3cee5a62006-10-16 12:46:32 +0200350/* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200351 that do not conflict with specific bits for AES32 seem to be valid also
352 for the AES32
353 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200354#define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200355#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
357 * (like inp0)
358 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100359
Takashi Iwai763f3562005-06-03 11:25:34 +0200360#define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100361#define HDSPM_madiSync (1<<18) /* MADI is in sync */
362
Adrian Knothb0bf5502013-07-05 11:28:05 +0200363#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!*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100365
Adrian Knothb0bf5502013-07-05 11:28:05 +0200366#define HDSPM_syncInLock 0x00010000 /* Sync In lock status for HDSPe MADI! */
367#define HDSPM_syncInSync 0x00020000 /* Sync In sync status for HDSPe MADI! */
Takashi Iwai763f3562005-06-03 11:25:34 +0200368
369#define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100370 /* since 64byte accurate, last 6 bits are not used */
Takashi Iwai763f3562005-06-03 11:25:34 +0200371
Adrian Knoth0dca1792011-01-26 19:32:14 +0100372
373
Takashi Iwai763f3562005-06-03 11:25:34 +0200374#define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
375
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 */
380
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200381#define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with
382 * Interrupt
383 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100384#define HDSPM_tco_detect 0x08000000
Adrian Knothb0bf5502013-07-05 11:28:05 +0200385#define HDSPM_tcoLockAes 0x20000000 /* Optional TCO locked status for HDSPe AES */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100386
387#define HDSPM_s2_tco_detect 0x00000040
388#define HDSPM_s2_AEBO_D 0x00000080
389#define HDSPM_s2_AEBI_D 0x00000100
390
391
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
Takashi Iwai763f3562005-06-03 11:25:34 +0200397
398/* --- status bit helpers */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200399#define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\
400 HDSPM_madiFreq2|HDSPM_madiFreq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200401#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)
410
Remy Bruno3cee5a62006-10-16 12:46:32 +0200411/* Status2 Register bits */ /* MADI ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200412
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300413#define HDSPM_version0 (1<<0) /* not really defined but I guess */
Takashi Iwai763f3562005-06-03 11:25:34 +0200414#define HDSPM_version1 (1<<1) /* in former cards it was ??? */
415#define HDSPM_version2 (1<<2)
416
417#define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
418#define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
419
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, */
Adrian Knotha8cd7142013-05-31 12:57:09 +0200422#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 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200424
Adrian Knoth0dca1792011-01-26 19:32:14 +0100425#define HDSPM_SyncRef0 0x10000 /* Sync Reference */
426#define HDSPM_SyncRef1 0x20000
427
428#define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */
Takashi Iwai763f3562005-06-03 11:25:34 +0200429#define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
430#define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
431
432#define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
433
Adrian Knotha8cd7142013-05-31 12:57:09 +0200434#define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\
435 HDSPM_wc_freq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200436#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)
Adrian Knotha8cd7142013-05-31 12:57:09 +0200442#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)
Takashi Iwai763f3562005-06-03 11:25:34 +0200445
Adrian Knoth0dca1792011-01-26 19:32:14 +0100446#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)
451
Takashi Iwai763f3562005-06-03 11:25:34 +0200452
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200453#define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
454 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200455#define HDSPM_SelSyncRef_WORD 0
456#define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100457#define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1)
458#define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200459#define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
460 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200461
Remy Bruno3cee5a62006-10-16 12:46:32 +0200462/*
463 For AES32, bits for status, status2 and timecode are different
464*/
465/* status */
466#define HDSPM_AES32_wcLock 0x0200000
Andre Schramm56bde0f2013-01-09 14:40:18 +0100467#define HDSPM_AES32_wcSync 0x0100000
Remy Bruno3cee5a62006-10-16 12:46:32 +0200468#define HDSPM_AES32_wcFreq_bit 22
Adrian Knoth0dca1792011-01-26 19:32:14 +0100469/* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function
Remy Bruno3cee5a62006-10-16 12:46:32 +0200470 HDSPM_bit2freq */
471#define HDSPM_AES32_syncref_bit 16
472/* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */
473
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
Adrian Knothb0bf5502013-07-05 11:28:05 +0200483#define HDSPM_AES32_AUTOSYNC_FROM_TCO 9
484#define HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN 10
485#define HDSPM_AES32_AUTOSYNC_FROM_NONE 11
Remy Bruno3cee5a62006-10-16 12:46:32 +0200486
487/* status2 */
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
498/*
499 Timecode
500 After windows driver sources, bits 4*i to 4*i+3 give the input frequency on
501 AES i+1
502 bits 3210
503 0001 32kHz
504 0010 44.1kHz
505 0011 48kHz
506 0100 64kHz
507 0101 88.2kHz
508 0110 96kHz
509 0111 128kHz
510 1000 176.4kHz
511 1001 192kHz
512 NB: Timecode register doesn't seem to work on AES32 card revision 230
513*/
514
Takashi Iwai763f3562005-06-03 11:25:34 +0200515/* Mixer Values */
516#define UNITY_GAIN 32768 /* = 65536/2 */
517#define MINUS_INFINITY_GAIN 0
518
Takashi Iwai763f3562005-06-03 11:25:34 +0200519/* 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
523
Adrian Knoth0dca1792011-01-26 19:32:14 +0100524#define RAYDAT_SS_CHANNELS 36
525#define RAYDAT_DS_CHANNELS 20
526#define RAYDAT_QS_CHANNELS 12
527
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
534
Adrian Knothd2d10a22011-02-28 15:14:47 +0100535#define AES32_CHANNELS 16
536
Takashi Iwai763f3562005-06-03 11:25:34 +0200537/* 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)
540
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
Adrian Knoth0dca1792011-01-26 19:32:14 +0100543 also the latency to use.
Takashi Iwai763f3562005-06-03 11:25:34 +0200544 for one direction !!!
545*/
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100546#define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
Takashi Iwai763f3562005-06-03 11:25:34 +0200547#define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
548
Adrian Knoth0dca1792011-01-26 19:32:14 +0100549#define HDSPM_RAYDAT_REV 211
550#define HDSPM_AIO_REV 212
551#define HDSPM_MADIFACE_REV 213
Remy Bruno3cee5a62006-10-16 12:46:32 +0200552
Remy Bruno65345992007-08-31 12:21:08 +0200553/* speed factor modes */
554#define HDSPM_SPEED_SINGLE 0
555#define HDSPM_SPEED_DOUBLE 1
556#define HDSPM_SPEED_QUAD 2
Adrian Knoth0dca1792011-01-26 19:32:14 +0100557
Remy Bruno65345992007-08-31 12:21:08 +0200558/* names for speed modes */
559static char *hdspm_speed_names[] = { "single", "double", "quad" };
560
Adrian Knoth0dca1792011-01-26 19:32:14 +0100561static char *texts_autosync_aes_tco[] = { "Word Clock",
562 "AES1", "AES2", "AES3", "AES4",
563 "AES5", "AES6", "AES7", "AES8",
Adrian Knothdb2d1a92013-07-05 11:28:08 +0200564 "TCO", "Sync In"
565};
Adrian Knoth0dca1792011-01-26 19:32:14 +0100566static char *texts_autosync_aes[] = { "Word Clock",
567 "AES1", "AES2", "AES3", "AES4",
Adrian Knothdb2d1a92013-07-05 11:28:08 +0200568 "AES5", "AES6", "AES7", "AES8",
569 "Sync In"
570};
Adrian Knoth0dca1792011-01-26 19:32:14 +0100571static char *texts_autosync_madi_tco[] = { "Word Clock",
572 "MADI", "TCO", "Sync In" };
573static char *texts_autosync_madi[] = { "Word Clock",
574 "MADI", "Sync In" };
575
576static char *texts_autosync_raydat_tco[] = {
577 "Word Clock",
578 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
579 "AES", "SPDIF", "TCO", "Sync In"
580};
581static char *texts_autosync_raydat[] = {
582 "Word Clock",
583 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
584 "AES", "SPDIF", "Sync In"
585};
586static char *texts_autosync_aio_tco[] = {
587 "Word Clock",
588 "ADAT", "AES", "SPDIF", "TCO", "Sync In"
589};
590static char *texts_autosync_aio[] = { "Word Clock",
591 "ADAT", "AES", "SPDIF", "Sync In" };
592
593static char *texts_freq[] = {
594 "No Lock",
595 "32 kHz",
596 "44.1 kHz",
597 "48 kHz",
598 "64 kHz",
599 "88.2 kHz",
600 "96 kHz",
601 "128 kHz",
602 "176.4 kHz",
603 "192 kHz"
604};
605
Adrian Knoth0dca1792011-01-26 19:32:14 +0100606static 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",
618};
619
620
621static 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",
628 "AES.L", "AES.R",
629 "SPDIF.L", "SPDIF.R"
630};
631
632static 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",
637 "AES.L", "AES.R",
638 "SPDIF.L", "SPDIF.R"
639};
640
641static 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",
646 "AES.L", "AES.R",
647 "SPDIF.L", "SPDIF.R"
648};
649
650
651static char *texts_ports_aio_in_ss[] = {
652 "Analogue.L", "Analogue.R",
653 "AES.L", "AES.R",
654 "SPDIF.L", "SPDIF.R",
655 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200656 "ADAT.7", "ADAT.8",
657 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100658};
659
660static char *texts_ports_aio_out_ss[] = {
661 "Analogue.L", "Analogue.R",
662 "AES.L", "AES.R",
663 "SPDIF.L", "SPDIF.R",
664 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
665 "ADAT.7", "ADAT.8",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200666 "Phone.L", "Phone.R",
667 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100668};
669
670static char *texts_ports_aio_in_ds[] = {
671 "Analogue.L", "Analogue.R",
672 "AES.L", "AES.R",
673 "SPDIF.L", "SPDIF.R",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200674 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
675 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100676};
677
678static char *texts_ports_aio_out_ds[] = {
679 "Analogue.L", "Analogue.R",
680 "AES.L", "AES.R",
681 "SPDIF.L", "SPDIF.R",
682 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200683 "Phone.L", "Phone.R",
684 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100685};
686
687static char *texts_ports_aio_in_qs[] = {
688 "Analogue.L", "Analogue.R",
689 "AES.L", "AES.R",
690 "SPDIF.L", "SPDIF.R",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200691 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
692 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100693};
694
695static char *texts_ports_aio_out_qs[] = {
696 "Analogue.L", "Analogue.R",
697 "AES.L", "AES.R",
698 "SPDIF.L", "SPDIF.R",
699 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200700 "Phone.L", "Phone.R",
701 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100702};
703
Adrian Knoth432d2502011-02-23 11:43:08 +0100704static 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",
707 "AES.15", "AES.16"
708};
709
Adrian Knoth55a57602011-01-27 11:23:15 +0100710/* 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.
716*/
717
718static 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
727};
728
Adrian Knoth55a57602011-01-27 11:23:15 +0100729static 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 */
734 0, 1, /* AES */
735 2, 3, /* SPDIF */
736 -1, -1, -1, -1,
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,
740};
741
742static 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 */
747 0, 1, /* AES */
748 2, 3, /* SPDIF */
749 -1, -1, -1, -1,
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,
755};
756
757static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = {
758 4, 5, /* ADAT 1 */
759 6, 7, /* ADAT 2 */
760 8, 9, /* ADAT 3 */
761 10, 11, /* ADAT 4 */
762 0, 1, /* AES */
763 2, 3, /* SPDIF */
764 -1, -1, -1, -1,
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,
771};
772
773static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = {
774 0, 1, /* line in */
775 8, 9, /* aes in, */
776 10, 11, /* spdif in */
777 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200778 2, 3, 4, 5, /* AEB */
779 -1, -1, -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100780 -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,
785};
786
787static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = {
788 0, 1, /* line out */
789 8, 9, /* aes out */
790 10, 11, /* spdif out */
791 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */
792 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200793 2, 3, 4, 5, /* AEB */
794 -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100795 -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,
800};
801
802static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = {
803 0, 1, /* line in */
804 8, 9, /* aes in */
805 10, 11, /* spdif in */
806 12, 14, 16, 18, /* adat in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200807 2, 3, 4, 5, /* AEB */
808 -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100809 -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
815};
816
817static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = {
818 0, 1, /* line out */
819 8, 9, /* aes out */
820 10, 11, /* spdif out */
821 12, 14, 16, 18, /* adat out */
822 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200823 2, 3, 4, 5, /* AEB */
Adrian Knoth55a57602011-01-27 11:23:15 +0100824 -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
830};
831
832static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = {
833 0, 1, /* line in */
834 8, 9, /* aes in */
835 10, 11, /* spdif in */
836 12, 16, /* adat in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200837 2, 3, 4, 5, /* AEB */
838 -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100839 -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
845};
846
847static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = {
848 0, 1, /* line out */
849 8, 9, /* aes out */
850 10, 11, /* spdif out */
851 12, 16, /* adat out */
852 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200853 2, 3, 4, 5, /* AEB */
854 -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100855 -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
861};
862
Adrian Knoth432d2502011-02-23 11:43:08 +0100863static 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
872};
873
Takashi Iwai98274f02005-11-17 14:52:34 +0100874struct hdspm_midi {
875 struct hdspm *hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +0200876 int id;
Takashi Iwai98274f02005-11-17 14:52:34 +0100877 struct snd_rawmidi *rmidi;
878 struct snd_rawmidi_substream *input;
879 struct snd_rawmidi_substream *output;
Takashi Iwai763f3562005-06-03 11:25:34 +0200880 char istimer; /* timer in use */
881 struct timer_list timer;
882 spinlock_t lock;
883 int pending;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100884 int dataIn;
885 int statusIn;
886 int dataOut;
887 int statusOut;
888 int ie;
889 int irq;
890};
891
892struct hdspm_tco {
893 int input;
894 int framerate;
895 int wordclock;
896 int samplerate;
897 int pull;
898 int term; /* 0 = off, 1 = on */
Takashi Iwai763f3562005-06-03 11:25:34 +0200899};
900
Takashi Iwai98274f02005-11-17 14:52:34 +0100901struct hdspm {
Takashi Iwai763f3562005-06-03 11:25:34 +0200902 spinlock_t lock;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200903 /* only one playback and/or capture stream */
904 struct snd_pcm_substream *capture_substream;
905 struct snd_pcm_substream *playback_substream;
Takashi Iwai763f3562005-06-03 11:25:34 +0200906
907 char *card_name; /* for procinfo */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200908 unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/
909
Adrian Knoth0dca1792011-01-26 19:32:14 +0100910 uint8_t io_type;
Takashi Iwai763f3562005-06-03 11:25:34 +0200911
Takashi Iwai763f3562005-06-03 11:25:34 +0200912 int monitor_outs; /* set up monitoring outs init flag */
913
914 u32 control_register; /* cached value */
915 u32 control2_register; /* cached value */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100916 u32 settings_register;
Takashi Iwai763f3562005-06-03 11:25:34 +0200917
Adrian Knoth0dca1792011-01-26 19:32:14 +0100918 struct hdspm_midi midi[4];
Takashi Iwai763f3562005-06-03 11:25:34 +0200919 struct tasklet_struct midi_tasklet;
920
921 size_t period_bytes;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100922 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;
928
929 unsigned char max_channels_in;
930 unsigned char max_channels_out;
931
Takashi Iwai286bed02011-06-30 12:45:36 +0200932 signed char *channel_map_in;
933 signed char *channel_map_out;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100934
Takashi Iwai286bed02011-06-30 12:45:36 +0200935 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;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100937
938 char **port_names_in;
939 char **port_names_out;
940
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;
Takashi Iwai763f3562005-06-03 11:25:34 +0200943
944 unsigned char *playback_buffer; /* suitably aligned address */
945 unsigned char *capture_buffer; /* suitably aligned address */
946
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 */
950
951 int last_external_sample_rate; /* samplerate mystic ... */
952 int last_internal_sample_rate;
953 int system_sample_rate;
954
Takashi Iwai763f3562005-06-03 11:25:34 +0200955 int dev; /* Hardware vars... */
956 int irq;
957 unsigned long port;
958 void __iomem *iobase;
959
960 int irq_count; /* for debug */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100961 int midiPorts;
Takashi Iwai763f3562005-06-03 11:25:34 +0200962
Takashi Iwai98274f02005-11-17 14:52:34 +0100963 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 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200966 struct pci_dev *pci; /* and an pci info */
967
968 /* Mixer vars */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200969 /* 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];
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300973 /* full mixer accessible over mixer ioctl or hwdep-device */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200974 struct hdspm_mixer *mixer;
Takashi Iwai763f3562005-06-03 11:25:34 +0200975
Adrian Knoth0dca1792011-01-26 19:32:14 +0100976 struct hdspm_tco *tco; /* NULL if no TCO detected */
Takashi Iwai763f3562005-06-03 11:25:34 +0200977
Adrian Knoth0dca1792011-01-26 19:32:14 +0100978 char **texts_autosync;
979 int texts_autosync_items;
Takashi Iwai763f3562005-06-03 11:25:34 +0200980
Adrian Knoth0dca1792011-01-26 19:32:14 +0100981 cycles_t last_interrupt;
Jaroslav Kysela730a5862011-01-27 13:03:15 +0100982
Adrian Knoth7d53a632012-01-04 14:31:16 +0100983 unsigned int serial;
984
Jaroslav Kysela730a5862011-01-27 13:03:15 +0100985 struct hdspm_peak_rms peak_rms;
Takashi Iwai763f3562005-06-03 11:25:34 +0200986};
987
Takashi Iwai763f3562005-06-03 11:25:34 +0200988
Alexey Dobriyancebe41d2010-02-06 00:21:03 +0200989static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = {
Takashi Iwai763f3562005-06-03 11:25:34 +0200990 {
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,
995 .class = 0,
996 .class_mask = 0,
997 .driver_data = 0},
998 {0,}
999};
1000
1001MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
1002
1003/* prototypes */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001004static int snd_hdspm_create_alsa_devices(struct snd_card *card,
1005 struct hdspm *hdspm);
1006static int snd_hdspm_create_pcm(struct snd_card *card,
1007 struct hdspm *hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001008
Adrian Knoth0dca1792011-01-26 19:32:14 +01001009static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
Adrian Knoth3f7bf912013-03-10 00:37:21 +01001010static inline int hdspm_get_pll_freq(struct hdspm *hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001011static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
1012static int hdspm_autosync_ref(struct hdspm *hdspm);
Adrian Knoth34be7eb2013-07-05 11:27:56 +02001013static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001014static int snd_hdspm_set_defaults(struct hdspm *hdspm);
Adrian Knoth21a164d2012-10-19 17:42:23 +02001015static int hdspm_system_clock_mode(struct hdspm *hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001016static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +02001017 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +02001018 unsigned int reg, int channels);
1019
Adrian Knoth5b266352013-07-05 11:28:10 +02001020static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx);
1021static int hdspm_wc_sync_check(struct hdspm *hdspm);
1022static int hdspm_tco_sync_check(struct hdspm *hdspm);
1023static int hdspm_sync_in_sync_check(struct hdspm *hdspm);
1024
1025static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index);
1026static int hdspm_get_tco_sample_rate(struct hdspm *hdspm);
1027static int hdspm_get_wc_sample_rate(struct hdspm *hdspm);
1028
1029
1030
Remy Bruno3cee5a62006-10-16 12:46:32 +02001031static inline int HDSPM_bit2freq(int n)
1032{
Denys Vlasenko62cef822008-04-14 13:04:18 +02001033 static const int bit2freq_tab[] = {
1034 0, 32000, 44100, 48000, 64000, 88200,
Remy Bruno3cee5a62006-10-16 12:46:32 +02001035 96000, 128000, 176400, 192000 };
1036 if (n < 1 || n > 9)
1037 return 0;
1038 return bit2freq_tab[n];
1039}
1040
Adrian Knothb2ed6322013-07-05 11:27:54 +02001041static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm)
1042{
1043 return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type));
1044}
1045
1046
Adrian Knoth0dca1792011-01-26 19:32:14 +01001047/* Write/read to/from HDSPM with Adresses in Bytes
Takashi Iwai763f3562005-06-03 11:25:34 +02001048 not words but only 32Bit writes are allowed */
1049
Takashi Iwai98274f02005-11-17 14:52:34 +01001050static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
Takashi Iwai763f3562005-06-03 11:25:34 +02001051 unsigned int val)
1052{
1053 writel(val, hdspm->iobase + reg);
1054}
1055
Takashi Iwai98274f02005-11-17 14:52:34 +01001056static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
Takashi Iwai763f3562005-06-03 11:25:34 +02001057{
1058 return readl(hdspm->iobase + reg);
1059}
1060
Adrian Knoth0dca1792011-01-26 19:32:14 +01001061/* 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
Takashi Iwai763f3562005-06-03 11:25:34 +02001063 each fader is a u32, but uses only the first 16 bit */
1064
Takashi Iwai98274f02005-11-17 14:52:34 +01001065static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001066 unsigned int in)
1067{
Adrian Bunk5bab24822006-03-13 14:15:04 +01001068 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001069 return 0;
1070
1071 return hdspm->mixer->ch[chan].in[in];
1072}
1073
Takashi Iwai98274f02005-11-17 14:52:34 +01001074static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001075 unsigned int pb)
1076{
Adrian Bunk5bab24822006-03-13 14:15:04 +01001077 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001078 return 0;
1079 return hdspm->mixer->ch[chan].pb[pb];
1080}
1081
Denys Vlasenko62cef822008-04-14 13:04:18 +02001082static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001083 unsigned int in, unsigned short data)
1084{
1085 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
1086 return -1;
1087
1088 hdspm_write(hdspm,
1089 HDSPM_MADI_mixerBase +
1090 ((in + 128 * chan) * sizeof(u32)),
1091 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
1092 return 0;
1093}
1094
Denys Vlasenko62cef822008-04-14 13:04:18 +02001095static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001096 unsigned int pb, unsigned short data)
1097{
1098 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
1099 return -1;
1100
1101 hdspm_write(hdspm,
1102 HDSPM_MADI_mixerBase +
1103 ((64 + pb + 128 * chan) * sizeof(u32)),
1104 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
1105 return 0;
1106}
1107
1108
1109/* enable DMA for specific channels, now available for DSP-MADI */
Takashi Iwai98274f02005-11-17 14:52:34 +01001110static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001111{
1112 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
1113}
1114
Takashi Iwai98274f02005-11-17 14:52:34 +01001115static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001116{
1117 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
1118}
1119
1120/* check if same process is writing and reading */
Denys Vlasenko62cef822008-04-14 13:04:18 +02001121static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001122{
1123 unsigned long flags;
1124 int ret = 1;
1125
1126 spin_lock_irqsave(&hdspm->lock, flags);
1127 if ((hdspm->playback_pid != hdspm->capture_pid) &&
1128 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
1129 ret = 0;
1130 }
1131 spin_unlock_irqrestore(&hdspm->lock, flags);
1132 return ret;
1133}
1134
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001135/* round arbitary sample rates to commonly known rates */
1136static int hdspm_round_frequency(int rate)
1137{
1138 if (rate < 38050)
1139 return 32000;
1140 if (rate < 46008)
1141 return 44100;
1142 else
1143 return 48000;
1144}
1145
Adrian Knotha8a729f2013-05-31 12:57:10 +02001146/* QS and DS rates normally can not be detected
1147 * automatically by the card. Only exception is MADI
1148 * in 96k frame mode.
1149 *
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.
1153 */
1154static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate)
1155{
1156 if (rate <= 48000) {
1157 if (hdspm->control_register & HDSPM_QuadSpeed)
1158 return rate * 4;
1159 else if (hdspm->control_register &
1160 HDSPM_DoubleSpeed)
1161 return rate * 2;
1162 };
1163 return rate;
1164}
1165
Adrian Knoth5b266352013-07-05 11:28:10 +02001166/* check for external sample rate, returns the sample rate in Hz*/
Denys Vlasenko62cef822008-04-14 13:04:18 +02001167static int hdspm_external_sample_rate(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001168{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001169 unsigned int status, status2, timecode;
1170 int syncref, rate = 0, rate_bits;
Takashi Iwai763f3562005-06-03 11:25:34 +02001171
Adrian Knoth0dca1792011-01-26 19:32:14 +01001172 switch (hdspm->io_type) {
1173 case AES32:
1174 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1175 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01001176 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001177
1178 syncref = hdspm_autosync_ref(hdspm);
Adrian Knothdbae4a02013-07-05 11:28:14 +02001179 switch (syncref) {
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));
1184 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001185
Adrian Knothdbae4a02013-07-05 11:28:14 +02001186 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));
1198 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001199
Adrian Knothdbae4a02013-07-05 11:28:14 +02001200
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));
1205 break;
1206 default:
1207 return 0;
1208 } /* end switch(syncref) */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001209 break;
1210
1211 case MADIface:
1212 status = hdspm_read(hdspm, HDSPM_statusRegister);
1213
1214 if (!(status & HDSPM_madiLock)) {
1215 rate = 0; /* no lock */
1216 } else {
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;
1236 default:
1237 rate = 0; break;
1238 }
1239 }
1240
1241 break;
1242
1243 case MADI:
1244 case AIO:
1245 case RayDAT:
1246 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1247 status = hdspm_read(hdspm, HDSPM_statusRegister);
1248 rate = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02001249
Remy Bruno3cee5a62006-10-16 12:46:32 +02001250 /* if wordclock has synced freq and wordclock is valid */
1251 if ((status2 & HDSPM_wcLock) != 0 &&
Adrian Knothfedf1532011-06-12 17:26:18 +02001252 (status2 & HDSPM_SelSyncRef0) == 0) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02001253
1254 rate_bits = status2 & HDSPM_wcFreqMask;
1255
Adrian Knoth0dca1792011-01-26 19:32:14 +01001256
Remy Bruno3cee5a62006-10-16 12:46:32 +02001257 switch (rate_bits) {
1258 case HDSPM_wcFreq32:
1259 rate = 32000;
1260 break;
1261 case HDSPM_wcFreq44_1:
1262 rate = 44100;
1263 break;
1264 case HDSPM_wcFreq48:
1265 rate = 48000;
1266 break;
1267 case HDSPM_wcFreq64:
1268 rate = 64000;
1269 break;
1270 case HDSPM_wcFreq88_2:
1271 rate = 88200;
1272 break;
1273 case HDSPM_wcFreq96:
1274 rate = 96000;
1275 break;
Adrian Knotha8cd7142013-05-31 12:57:09 +02001276 case HDSPM_wcFreq128:
1277 rate = 128000;
1278 break;
1279 case HDSPM_wcFreq176_4:
1280 rate = 176400;
1281 break;
1282 case HDSPM_wcFreq192:
1283 rate = 192000;
1284 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001285 default:
1286 rate = 0;
1287 break;
1288 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001289 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001290
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001291 /* if rate detected and Syncref is Word than have it,
1292 * word has priority to MADI
1293 */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001294 if (rate != 0 &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01001295 (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
Adrian Knoth7b559392013-05-31 12:57:11 +02001296 return hdspm_rate_multiplier(hdspm, rate);
Remy Bruno3cee5a62006-10-16 12:46:32 +02001297
Adrian Knoth0dca1792011-01-26 19:32:14 +01001298 /* maybe a madi input (which is taken if sel sync is madi) */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001299 if (status & HDSPM_madiLock) {
1300 rate_bits = status & HDSPM_madiFreqMask;
1301
1302 switch (rate_bits) {
1303 case HDSPM_madiFreq32:
1304 rate = 32000;
1305 break;
1306 case HDSPM_madiFreq44_1:
1307 rate = 44100;
1308 break;
1309 case HDSPM_madiFreq48:
1310 rate = 48000;
1311 break;
1312 case HDSPM_madiFreq64:
1313 rate = 64000;
1314 break;
1315 case HDSPM_madiFreq88_2:
1316 rate = 88200;
1317 break;
1318 case HDSPM_madiFreq96:
1319 rate = 96000;
1320 break;
1321 case HDSPM_madiFreq128:
1322 rate = 128000;
1323 break;
1324 case HDSPM_madiFreq176_4:
1325 rate = 176400;
1326 break;
1327 case HDSPM_madiFreq192:
1328 rate = 192000;
1329 break;
1330 default:
1331 rate = 0;
1332 break;
1333 }
Adrian Knothd12c51d2011-07-29 03:11:03 +02001334
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001335 } /* endif HDSPM_madiLock */
1336
1337 /* check sample rate from TCO or SYNC_IN */
1338 {
1339 bool is_valid_input = 0;
1340 bool has_sync = 0;
1341
1342 syncref = hdspm_autosync_ref(hdspm);
1343 if (HDSPM_AUTOSYNC_FROM_TCO == syncref) {
1344 is_valid_input = 1;
1345 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1346 hdspm_tco_sync_check(hdspm));
1347 } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) {
1348 is_valid_input = 1;
1349 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1350 hdspm_sync_in_sync_check(hdspm));
Adrian Knothd12c51d2011-07-29 03:11:03 +02001351 }
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001352
1353 if (is_valid_input && has_sync) {
1354 rate = hdspm_round_frequency(
1355 hdspm_get_pll_freq(hdspm));
1356 }
1357 }
1358
Adrian Knotha8a729f2013-05-31 12:57:10 +02001359 rate = hdspm_rate_multiplier(hdspm, rate);
1360
Adrian Knoth0dca1792011-01-26 19:32:14 +01001361 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001362 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01001363
1364 return rate;
Takashi Iwai763f3562005-06-03 11:25:34 +02001365}
1366
Adrian Knoth7cb155f2011-08-15 00:22:53 +02001367/* return latency in samples per period */
1368static int hdspm_get_latency(struct hdspm *hdspm)
1369{
1370 int n;
1371
1372 n = hdspm_decode_latency(hdspm->control_register);
1373
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.
1380 */
1381 if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
1382 n = -1;
1383
1384 return 1 << (n + 6);
1385}
1386
Takashi Iwai763f3562005-06-03 11:25:34 +02001387/* Latency function */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001388static inline void hdspm_compute_period_size(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001389{
Adrian Knoth7cb155f2011-08-15 00:22:53 +02001390 hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001391}
1392
Adrian Knoth0dca1792011-01-26 19:32:14 +01001393
1394static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001395{
1396 int position;
1397
1398 position = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth483cee72011-02-23 11:43:09 +01001399
1400 switch (hdspm->io_type) {
1401 case RayDAT:
1402 case AIO:
1403 position &= HDSPM_BufferPositionMask;
1404 position /= 4; /* Bytes per sample */
1405 break;
1406 default:
1407 position = (position & HDSPM_BufferID) ?
1408 (hdspm->period_bytes / 4) : 0;
1409 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001410
1411 return position;
1412}
1413
1414
Takashi Iwai98274f02005-11-17 14:52:34 +01001415static inline void hdspm_start_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001416{
1417 s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
1418 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1419}
1420
Takashi Iwai98274f02005-11-17 14:52:34 +01001421static inline void hdspm_stop_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001422{
1423 s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
1424 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1425}
1426
1427/* should I silence all or only opened ones ? doit all for first even is 4MB*/
Denys Vlasenko62cef822008-04-14 13:04:18 +02001428static void hdspm_silence_playback(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001429{
1430 int i;
1431 int n = hdspm->period_bytes;
1432 void *buf = hdspm->playback_buffer;
1433
Remy Bruno3cee5a62006-10-16 12:46:32 +02001434 if (buf == NULL)
1435 return;
Takashi Iwai763f3562005-06-03 11:25:34 +02001436
1437 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
1438 memset(buf, 0, n);
1439 buf += HDSPM_CHANNEL_BUFFER_BYTES;
1440 }
1441}
1442
Adrian Knoth0dca1792011-01-26 19:32:14 +01001443static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
Takashi Iwai763f3562005-06-03 11:25:34 +02001444{
1445 int n;
1446
1447 spin_lock_irq(&s->lock);
1448
Adrian Knoth2e610272011-08-15 00:22:54 +02001449 if (32 == frames) {
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.
1456 *
1457 * In other words, period size in samples is calculated by
1458 * 2^(n+6) with n ranging from 0 .. 7.
1459 */
1460 n = 7;
1461 } else {
1462 frames >>= 7;
1463 n = 0;
1464 while (frames) {
1465 n++;
1466 frames >>= 1;
1467 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001468 }
Adrian Knoth2e610272011-08-15 00:22:54 +02001469
Takashi Iwai763f3562005-06-03 11:25:34 +02001470 s->control_register &= ~HDSPM_LatencyMask;
1471 s->control_register |= hdspm_encode_latency(n);
1472
1473 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1474
1475 hdspm_compute_period_size(s);
1476
1477 spin_unlock_irq(&s->lock);
1478
1479 return 0;
1480}
1481
Adrian Knoth0dca1792011-01-26 19:32:14 +01001482static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
1483{
1484 u64 freq_const;
1485
1486 if (period == 0)
1487 return 0;
1488
1489 switch (hdspm->io_type) {
1490 case MADI:
1491 case AES32:
1492 freq_const = 110069313433624ULL;
1493 break;
1494 case RayDAT:
1495 case AIO:
1496 freq_const = 104857600000000ULL;
1497 break;
1498 case MADIface:
1499 freq_const = 131072000000000ULL;
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001500 break;
1501 default:
1502 snd_BUG();
1503 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001504 }
1505
1506 return div_u64(freq_const, period);
1507}
1508
1509
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001510static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
1511{
1512 u64 n;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001513
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001514 if (rate >= 112000)
1515 rate /= 4;
1516 else if (rate >= 56000)
1517 rate /= 2;
1518
Adrian Knoth0dca1792011-01-26 19:32:14 +01001519 switch (hdspm->io_type) {
1520 case MADIface:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001521 n = 131072000000000ULL; /* 125 MHz */
1522 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001523 case MADI:
1524 case AES32:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001525 n = 110069313433624ULL; /* 105 MHz */
1526 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001527 case RayDAT:
1528 case AIO:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001529 n = 104857600000000ULL; /* 100 MHz */
1530 break;
1531 default:
1532 snd_BUG();
1533 return;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001534 }
1535
Takashi Iwai3f7440a2009-06-05 17:40:04 +02001536 n = div_u64(n, rate);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001537 /* n should be less than 2^32 for being written to FREQ register */
Takashi Iwaida3cec32008-08-08 17:12:14 +02001538 snd_BUG_ON(n >> 32);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001539 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
1540}
Takashi Iwai763f3562005-06-03 11:25:34 +02001541
1542/* dummy set rate lets see what happens */
Takashi Iwai98274f02005-11-17 14:52:34 +01001543static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
Takashi Iwai763f3562005-06-03 11:25:34 +02001544{
Takashi Iwai763f3562005-06-03 11:25:34 +02001545 int current_rate;
1546 int rate_bits;
1547 int not_set = 0;
Remy Bruno65345992007-08-31 12:21:08 +02001548 int current_speed, target_speed;
Takashi Iwai763f3562005-06-03 11:25:34 +02001549
1550 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
1551 it (e.g. during module initialization).
1552 */
1553
1554 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
1555
Adrian Knoth0dca1792011-01-26 19:32:14 +01001556 /* SLAVE --- */
Takashi Iwai763f3562005-06-03 11:25:34 +02001557 if (called_internally) {
1558
Adrian Knoth0dca1792011-01-26 19:32:14 +01001559 /* request from ctl or card initialization
1560 just make a warning an remember setting
1561 for future master mode switching */
1562
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001563 snd_printk(KERN_WARNING "HDSPM: "
1564 "Warning: device is not running "
1565 "as a clock master.\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001566 not_set = 1;
1567 } else {
1568
1569 /* hw_param request while in AutoSync mode */
1570 int external_freq =
1571 hdspm_external_sample_rate(hdspm);
1572
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001573 if (hdspm_autosync_ref(hdspm) ==
1574 HDSPM_AUTOSYNC_FROM_NONE) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001575
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001576 snd_printk(KERN_WARNING "HDSPM: "
1577 "Detected no Externel Sync \n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001578 not_set = 1;
1579
1580 } else if (rate != external_freq) {
1581
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001582 snd_printk(KERN_WARNING "HDSPM: "
1583 "Warning: No AutoSync source for "
1584 "requested rate\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001585 not_set = 1;
1586 }
1587 }
1588 }
1589
1590 current_rate = hdspm->system_sample_rate;
1591
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.
1596
1597 Note that a similar but essentially insoluble problem exists for
1598 externally-driven rate changes. All we can do is to flag rate
Adrian Knoth0dca1792011-01-26 19:32:14 +01001599 changes in the read/write routines.
Takashi Iwai763f3562005-06-03 11:25:34 +02001600 */
1601
Remy Bruno65345992007-08-31 12:21:08 +02001602 if (current_rate <= 48000)
1603 current_speed = HDSPM_SPEED_SINGLE;
1604 else if (current_rate <= 96000)
1605 current_speed = HDSPM_SPEED_DOUBLE;
1606 else
1607 current_speed = HDSPM_SPEED_QUAD;
1608
1609 if (rate <= 48000)
1610 target_speed = HDSPM_SPEED_SINGLE;
1611 else if (rate <= 96000)
1612 target_speed = HDSPM_SPEED_DOUBLE;
1613 else
1614 target_speed = HDSPM_SPEED_QUAD;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001615
Takashi Iwai763f3562005-06-03 11:25:34 +02001616 switch (rate) {
1617 case 32000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001618 rate_bits = HDSPM_Frequency32KHz;
1619 break;
1620 case 44100:
Takashi Iwai763f3562005-06-03 11:25:34 +02001621 rate_bits = HDSPM_Frequency44_1KHz;
1622 break;
1623 case 48000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001624 rate_bits = HDSPM_Frequency48KHz;
1625 break;
1626 case 64000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001627 rate_bits = HDSPM_Frequency64KHz;
1628 break;
1629 case 88200:
Takashi Iwai763f3562005-06-03 11:25:34 +02001630 rate_bits = HDSPM_Frequency88_2KHz;
1631 break;
1632 case 96000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001633 rate_bits = HDSPM_Frequency96KHz;
1634 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001635 case 128000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001636 rate_bits = HDSPM_Frequency128KHz;
1637 break;
1638 case 176400:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001639 rate_bits = HDSPM_Frequency176_4KHz;
1640 break;
1641 case 192000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001642 rate_bits = HDSPM_Frequency192KHz;
1643 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001644 default:
1645 return -EINVAL;
1646 }
1647
Remy Bruno65345992007-08-31 12:21:08 +02001648 if (current_speed != target_speed
Takashi Iwai763f3562005-06-03 11:25:34 +02001649 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
1650 snd_printk
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001651 (KERN_ERR "HDSPM: "
Remy Bruno65345992007-08-31 12:21:08 +02001652 "cannot change from %s speed to %s speed mode "
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001653 "(capture PID = %d, playback PID = %d)\n",
Remy Bruno65345992007-08-31 12:21:08 +02001654 hdspm_speed_names[current_speed],
1655 hdspm_speed_names[target_speed],
Takashi Iwai763f3562005-06-03 11:25:34 +02001656 hdspm->capture_pid, hdspm->playback_pid);
1657 return -EBUSY;
1658 }
1659
1660 hdspm->control_register &= ~HDSPM_FrequencyMask;
1661 hdspm->control_register |= rate_bits;
1662 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1663
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001664 /* For AES32, need to set DDS value in FREQ register
1665 For MADI, also apparently */
1666 hdspm_set_dds_value(hdspm, rate);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001667
1668 if (AES32 == hdspm->io_type && rate != current_rate)
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001669 hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
Takashi Iwai763f3562005-06-03 11:25:34 +02001670
1671 hdspm->system_sample_rate = rate;
1672
Adrian Knoth0dca1792011-01-26 19:32:14 +01001673 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;
1687 } else {
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;
1694 }
1695
Takashi Iwai763f3562005-06-03 11:25:34 +02001696 if (not_set != 0)
1697 return -1;
1698
1699 return 0;
1700}
1701
1702/* mainly for init to 0 on load */
Takashi Iwai98274f02005-11-17 14:52:34 +01001703static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
Takashi Iwai763f3562005-06-03 11:25:34 +02001704{
1705 int i, j;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001706 unsigned int gain;
1707
1708 if (sgain > UNITY_GAIN)
1709 gain = UNITY_GAIN;
1710 else if (sgain < 0)
1711 gain = 0;
1712 else
1713 gain = sgain;
Takashi Iwai763f3562005-06-03 11:25:34 +02001714
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);
1719 }
1720}
1721
1722/*----------------------------------------------------------------------------
1723 MIDI
1724 ----------------------------------------------------------------------------*/
1725
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001726static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm,
1727 int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001728{
1729 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001730 return hdspm_read(hdspm, hdspm->midi[id].dataIn);
Takashi Iwai763f3562005-06-03 11:25:34 +02001731}
1732
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001733static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1734 int val)
Takashi Iwai763f3562005-06-03 11:25:34 +02001735{
1736 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001737 return hdspm_write(hdspm, hdspm->midi[id].dataOut, val);
Takashi Iwai763f3562005-06-03 11:25:34 +02001738}
1739
Takashi Iwai98274f02005-11-17 14:52:34 +01001740static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001741{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001742 return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001743}
1744
Takashi Iwai98274f02005-11-17 14:52:34 +01001745static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001746{
1747 int fifo_bytes_used;
1748
Adrian Knoth0dca1792011-01-26 19:32:14 +01001749 fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001750
1751 if (fifo_bytes_used < 128)
1752 return 128 - fifo_bytes_used;
1753 else
1754 return 0;
1755}
1756
Denys Vlasenko62cef822008-04-14 13:04:18 +02001757static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001758{
1759 while (snd_hdspm_midi_input_available (hdspm, id))
1760 snd_hdspm_midi_read_byte (hdspm, id);
1761}
1762
Takashi Iwai98274f02005-11-17 14:52:34 +01001763static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001764{
1765 unsigned long flags;
1766 int n_pending;
1767 int to_write;
1768 int i;
1769 unsigned char buf[128];
1770
1771 /* Output is not interrupt driven */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001772
Takashi Iwai763f3562005-06-03 11:25:34 +02001773 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001774 if (hmidi->output &&
1775 !snd_rawmidi_transmit_empty (hmidi->output)) {
1776 n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
1777 hmidi->id);
1778 if (n_pending > 0) {
1779 if (n_pending > (int)sizeof (buf))
1780 n_pending = sizeof (buf);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001781
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001782 to_write = snd_rawmidi_transmit (hmidi->output, buf,
1783 n_pending);
1784 if (to_write > 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001785 for (i = 0; i < to_write; ++i)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001786 snd_hdspm_midi_write_byte (hmidi->hdspm,
1787 hmidi->id,
1788 buf[i]);
Takashi Iwai763f3562005-06-03 11:25:34 +02001789 }
1790 }
1791 }
1792 spin_unlock_irqrestore (&hmidi->lock, flags);
1793 return 0;
1794}
1795
Takashi Iwai98274f02005-11-17 14:52:34 +01001796static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001797{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001798 unsigned char buf[128]; /* this buffer is designed to match the MIDI
1799 * input FIFO size
1800 */
Takashi Iwai763f3562005-06-03 11:25:34 +02001801 unsigned long flags;
1802 int n_pending;
1803 int i;
1804
1805 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001806 n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
1807 if (n_pending > 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001808 if (hmidi->input) {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001809 if (n_pending > (int)sizeof (buf))
Takashi Iwai763f3562005-06-03 11:25:34 +02001810 n_pending = sizeof (buf);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001811 for (i = 0; i < n_pending; ++i)
1812 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm,
1813 hmidi->id);
1814 if (n_pending)
1815 snd_rawmidi_receive (hmidi->input, buf,
1816 n_pending);
Takashi Iwai763f3562005-06-03 11:25:34 +02001817 } else {
1818 /* flush the MIDI input FIFO */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001819 while (n_pending--)
1820 snd_hdspm_midi_read_byte (hmidi->hdspm,
1821 hmidi->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02001822 }
1823 }
1824 hmidi->pending = 0;
Adrian Knothc0da0012011-06-12 17:26:17 +02001825 spin_unlock_irqrestore(&hmidi->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001826
Adrian Knothc0da0012011-06-12 17:26:17 +02001827 spin_lock_irqsave(&hmidi->hdspm->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001828 hmidi->hdspm->control_register |= hmidi->ie;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001829 hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
1830 hmidi->hdspm->control_register);
Adrian Knothc0da0012011-06-12 17:26:17 +02001831 spin_unlock_irqrestore(&hmidi->hdspm->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001832
Takashi Iwai763f3562005-06-03 11:25:34 +02001833 return snd_hdspm_midi_output_write (hmidi);
1834}
1835
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001836static void
1837snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001838{
Takashi Iwai98274f02005-11-17 14:52:34 +01001839 struct hdspm *hdspm;
1840 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001841 unsigned long flags;
Takashi Iwai763f3562005-06-03 11:25:34 +02001842
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001843 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001844 hdspm = hmidi->hdspm;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001845
Takashi Iwai763f3562005-06-03 11:25:34 +02001846 spin_lock_irqsave (&hdspm->lock, flags);
1847 if (up) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001848 if (!(hdspm->control_register & hmidi->ie)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001849 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001850 hdspm->control_register |= hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001851 }
1852 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001853 hdspm->control_register &= ~hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001854 }
1855
1856 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1857 spin_unlock_irqrestore (&hdspm->lock, flags);
1858}
1859
1860static void snd_hdspm_midi_output_timer(unsigned long data)
1861{
Takashi Iwai98274f02005-11-17 14:52:34 +01001862 struct hdspm_midi *hmidi = (struct hdspm_midi *) data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001863 unsigned long flags;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001864
Takashi Iwai763f3562005-06-03 11:25:34 +02001865 snd_hdspm_midi_output_write(hmidi);
1866 spin_lock_irqsave (&hmidi->lock, flags);
1867
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
Adrian Knoth0dca1792011-01-26 19:32:14 +01001871 leaving istimer wherever it was set before.
Takashi Iwai763f3562005-06-03 11:25:34 +02001872 */
1873
1874 if (hmidi->istimer) {
1875 hmidi->timer.expires = 1 + jiffies;
1876 add_timer(&hmidi->timer);
1877 }
1878
1879 spin_unlock_irqrestore (&hmidi->lock, flags);
1880}
1881
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001882static void
1883snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001884{
Takashi Iwai98274f02005-11-17 14:52:34 +01001885 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001886 unsigned long flags;
1887
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001888 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001889 spin_lock_irqsave (&hmidi->lock, flags);
1890 if (up) {
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);
1897 hmidi->istimer++;
1898 }
1899 } else {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001900 if (hmidi->istimer && --hmidi->istimer <= 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02001901 del_timer (&hmidi->timer);
Takashi Iwai763f3562005-06-03 11:25:34 +02001902 }
1903 spin_unlock_irqrestore (&hmidi->lock, flags);
1904 if (up)
1905 snd_hdspm_midi_output_write(hmidi);
1906}
1907
Takashi Iwai98274f02005-11-17 14:52:34 +01001908static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001909{
Takashi Iwai98274f02005-11-17 14:52:34 +01001910 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001911
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001912 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001913 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);
1917
1918 return 0;
1919}
1920
Takashi Iwai98274f02005-11-17 14:52:34 +01001921static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001922{
Takashi Iwai98274f02005-11-17 14:52:34 +01001923 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001924
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001925 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001926 spin_lock_irq (&hmidi->lock);
1927 hmidi->output = substream;
1928 spin_unlock_irq (&hmidi->lock);
1929
1930 return 0;
1931}
1932
Takashi Iwai98274f02005-11-17 14:52:34 +01001933static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001934{
Takashi Iwai98274f02005-11-17 14:52:34 +01001935 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001936
1937 snd_hdspm_midi_input_trigger (substream, 0);
1938
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001939 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001940 spin_lock_irq (&hmidi->lock);
1941 hmidi->input = NULL;
1942 spin_unlock_irq (&hmidi->lock);
1943
1944 return 0;
1945}
1946
Takashi Iwai98274f02005-11-17 14:52:34 +01001947static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001948{
Takashi Iwai98274f02005-11-17 14:52:34 +01001949 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001950
1951 snd_hdspm_midi_output_trigger (substream, 0);
1952
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001953 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001954 spin_lock_irq (&hmidi->lock);
1955 hmidi->output = NULL;
1956 spin_unlock_irq (&hmidi->lock);
1957
1958 return 0;
1959}
1960
Takashi Iwai98274f02005-11-17 14:52:34 +01001961static struct snd_rawmidi_ops snd_hdspm_midi_output =
Takashi Iwai763f3562005-06-03 11:25:34 +02001962{
1963 .open = snd_hdspm_midi_output_open,
1964 .close = snd_hdspm_midi_output_close,
1965 .trigger = snd_hdspm_midi_output_trigger,
1966};
1967
Takashi Iwai98274f02005-11-17 14:52:34 +01001968static struct snd_rawmidi_ops snd_hdspm_midi_input =
Takashi Iwai763f3562005-06-03 11:25:34 +02001969{
1970 .open = snd_hdspm_midi_input_open,
1971 .close = snd_hdspm_midi_input_close,
1972 .trigger = snd_hdspm_midi_input_trigger,
1973};
1974
Bill Pembertone23e7a12012-12-06 12:35:10 -05001975static int snd_hdspm_create_midi(struct snd_card *card,
1976 struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001977{
1978 int err;
1979 char buf[32];
1980
1981 hdspm->midi[id].id = id;
Takashi Iwai763f3562005-06-03 11:25:34 +02001982 hdspm->midi[id].hdspm = hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +02001983 spin_lock_init (&hdspm->midi[id].lock);
1984
Adrian Knoth0dca1792011-01-26 19:32:14 +01001985 if (0 == id) {
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;
1994 } else {
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;
2001 }
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;
2033 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002034
Adrian Knoth0dca1792011-01-26 19:32:14 +01002035 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);
2041 } else {
2042 sprintf(buf, "%s MIDI %d", card->shortname, id+1);
2043 }
2044 err = snd_rawmidi_new(card, buf, id, 1, 1,
2045 &hdspm->midi[id].rmidi);
2046 if (err < 0)
2047 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02002048
Adrian Knoth0dca1792011-01-26 19:32:14 +01002049 sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d",
2050 card->id, id+1);
2051 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
Takashi Iwai763f3562005-06-03 11:25:34 +02002052
Adrian Knoth0dca1792011-01-26 19:32:14 +01002053 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);
2059
2060 hdspm->midi[id].rmidi->info_flags |=
2061 SNDRV_RAWMIDI_INFO_OUTPUT |
2062 SNDRV_RAWMIDI_INFO_INPUT |
2063 SNDRV_RAWMIDI_INFO_DUPLEX;
2064 } else {
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);
2069 if (err < 0)
2070 return err;
2071
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];
2075
2076 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2077 SNDRV_RAWMIDI_STREAM_INPUT,
2078 &snd_hdspm_midi_input);
2079
2080 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
2081 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002082
2083 return 0;
2084}
2085
2086
2087static void hdspm_midi_tasklet(unsigned long arg)
2088{
Takashi Iwai98274f02005-11-17 14:52:34 +01002089 struct hdspm *hdspm = (struct hdspm *)arg;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002090 int i = 0;
2091
2092 while (i < hdspm->midiPorts) {
2093 if (hdspm->midi[i].pending)
2094 snd_hdspm_midi_input_read(&hdspm->midi[i]);
2095
2096 i++;
2097 }
2098}
Takashi Iwai763f3562005-06-03 11:25:34 +02002099
2100
2101/*-----------------------------------------------------------------------------
2102 Status Interface
2103 ----------------------------------------------------------------------------*/
2104
2105/* get the system sample rate which is set */
2106
Adrian Knoth0dca1792011-01-26 19:32:14 +01002107
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002108static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
2109{
2110 unsigned int period, rate;
2111
2112 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
2113 rate = hdspm_calc_dds_value(hdspm, period);
2114
2115 return rate;
2116}
2117
Adrian Knoth0dca1792011-01-26 19:32:14 +01002118/**
2119 * Calculate the real sample rate from the
2120 * current DDS value.
2121 **/
2122static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
2123{
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002124 unsigned int rate;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002125
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002126 rate = hdspm_get_pll_freq(hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002127
Adrian Knotha97bda72012-05-30 14:23:18 +02002128 if (rate > 207000) {
Adrian Knoth21a164d2012-10-19 17:42:23 +02002129 /* 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;
2133 } else {
2134 /* slave mode, return external sample rate */
2135 rate = hdspm_external_sample_rate(hdspm);
2136 }
Adrian Knotha97bda72012-05-30 14:23:18 +02002137 }
2138
Adrian Knoth0dca1792011-01-26 19:32:14 +01002139 return rate;
2140}
2141
2142
Takashi Iwai763f3562005-06-03 11:25:34 +02002143#define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02002144{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2145 .name = xname, \
2146 .index = xindex, \
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 \
Takashi Iwai763f3562005-06-03 11:25:34 +02002152}
2153
Takashi Iwai98274f02005-11-17 14:52:34 +01002154static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002156{
2157 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2158 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002159 uinfo->value.integer.min = 27000;
2160 uinfo->value.integer.max = 207000;
2161 uinfo->value.integer.step = 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002162 return 0;
2163}
2164
Adrian Knoth0dca1792011-01-26 19:32:14 +01002165
Takashi Iwai98274f02005-11-17 14:52:34 +01002166static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol,
2167 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02002168 ucontrol)
2169{
Takashi Iwai98274f02005-11-17 14:52:34 +01002170 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002171
Adrian Knoth0dca1792011-01-26 19:32:14 +01002172 ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002173 return 0;
2174}
2175
Adrian Knoth41285a92012-10-19 17:42:22 +02002176static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
2177 struct snd_ctl_elem_value *
2178 ucontrol)
2179{
2180 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2181
2182 hdspm_set_dds_value(hdspm, ucontrol->value.enumerated.item[0]);
2183 return 0;
2184}
2185
Adrian Knoth0dca1792011-01-26 19:32:14 +01002186
2187/**
2188 * Returns the WordClock sample rate class for the given card.
2189 **/
2190static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
2191{
2192 int status;
2193
2194 switch (hdspm->io_type) {
2195 case RayDAT:
2196 case AIO:
2197 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2198 return (status >> 16) & 0xF;
2199 break;
Adrian Knotha57fea82013-07-05 11:28:11 +02002200 case AES32:
2201 status = hdspm_read(hdspm, HDSPM_statusRegister);
2202 return (status >> HDSPM_AES32_wcFreq_bit) & 0xF;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002203 default:
2204 break;
2205 }
2206
2207
2208 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002209}
2210
Adrian Knoth0dca1792011-01-26 19:32:14 +01002211
2212/**
2213 * Returns the TCO sample rate class for the given card.
2214 **/
2215static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
2216{
2217 int status;
2218
2219 if (hdspm->tco) {
2220 switch (hdspm->io_type) {
2221 case RayDAT:
2222 case AIO:
2223 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2224 return (status >> 20) & 0xF;
2225 break;
Adrian Knoth051c44f2013-07-05 11:28:12 +02002226 case AES32:
2227 status = hdspm_read(hdspm, HDSPM_statusRegister);
2228 return (status >> 1) & 0xF;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002229 default:
2230 break;
2231 }
2232 }
2233
2234 return 0;
2235}
2236
2237
2238/**
2239 * Returns the SYNC_IN sample rate class for the given card.
2240 **/
2241static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2242{
2243 int status;
2244
2245 if (hdspm->tco) {
2246 switch (hdspm->io_type) {
2247 case RayDAT:
2248 case AIO:
2249 status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2250 return (status >> 12) & 0xF;
2251 break;
2252 default:
2253 break;
2254 }
2255 }
2256
2257 return 0;
2258}
2259
Adrian Knothd3c36ed2013-07-05 11:28:09 +02002260/**
2261 * Returns the AES sample rate class for the given card.
2262 **/
2263static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
2264{
2265 int timecode;
2266
2267 switch (hdspm->io_type) {
2268 case AES32:
2269 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
2270 return (timecode >> (4*index)) & 0xF;
2271 break;
2272 default:
2273 break;
2274 }
2275 return 0;
2276}
Adrian Knoth0dca1792011-01-26 19:32:14 +01002277
2278/**
2279 * Returns the sample rate class for input source <idx> for
2280 * 'new style' cards like the AIO and RayDAT.
2281 **/
2282static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2283{
2284 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2285
2286 return (status >> (idx*4)) & 0xF;
2287}
2288
Adrian Knoth8cea5712013-07-05 11:27:59 +02002289static void snd_hdspm_set_infotext(struct snd_ctl_elem_info *uinfo,
2290 char **texts, const int count)
2291{
2292 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2293 uinfo->count = 1;
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]);
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01002300}
2301
Adrian Knoth8cea5712013-07-05 11:27:59 +02002302#define ENUMERATED_CTL_INFO(info, texts) \
2303 snd_hdspm_set_infotext(info, texts, ARRAY_SIZE(texts))
2304
Adrian Knoth0dca1792011-01-26 19:32:14 +01002305
Adrian Knoth23361422013-07-05 11:28:17 +02002306/* Helper function to query the external sample rate and return the
2307 * corresponding enum to be returned to userspace.
2308 */
2309static int hdspm_external_rate_to_enum(struct hdspm *hdspm)
2310{
2311 int rate = hdspm_external_sample_rate(hdspm);
2312 int i, selected_rate = 0;
2313 for (i = 1; i < 10; i++)
2314 if (HDSPM_bit2freq(i) == rate) {
2315 selected_rate = i;
2316 break;
2317 }
2318 return selected_rate;
2319}
2320
Adrian Knoth0dca1792011-01-26 19:32:14 +01002321
2322#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
2323{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2324 .name = xname, \
2325 .private_value = xindex, \
2326 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2327 .info = snd_hdspm_info_autosync_sample_rate, \
2328 .get = snd_hdspm_get_autosync_sample_rate \
2329}
2330
2331
Takashi Iwai98274f02005-11-17 14:52:34 +01002332static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2333 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002334{
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01002335 ENUMERATED_CTL_INFO(uinfo, texts_freq);
Takashi Iwai763f3562005-06-03 11:25:34 +02002336 return 0;
2337}
2338
Adrian Knoth0dca1792011-01-26 19:32:14 +01002339
Takashi Iwai98274f02005-11-17 14:52:34 +01002340static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2341 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02002342 ucontrol)
2343{
Takashi Iwai98274f02005-11-17 14:52:34 +01002344 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002345
Adrian Knoth0dca1792011-01-26 19:32:14 +01002346 switch (hdspm->io_type) {
2347 case RayDAT:
2348 switch (kcontrol->private_value) {
2349 case 0:
2350 ucontrol->value.enumerated.item[0] =
2351 hdspm_get_wc_sample_rate(hdspm);
2352 break;
2353 case 7:
2354 ucontrol->value.enumerated.item[0] =
2355 hdspm_get_tco_sample_rate(hdspm);
2356 break;
2357 case 8:
2358 ucontrol->value.enumerated.item[0] =
2359 hdspm_get_sync_in_sample_rate(hdspm);
2360 break;
2361 default:
2362 ucontrol->value.enumerated.item[0] =
2363 hdspm_get_s1_sample_rate(hdspm,
2364 kcontrol->private_value-1);
2365 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002366 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002367
Adrian Knoth0dca1792011-01-26 19:32:14 +01002368 case AIO:
2369 switch (kcontrol->private_value) {
2370 case 0: /* WC */
2371 ucontrol->value.enumerated.item[0] =
2372 hdspm_get_wc_sample_rate(hdspm);
2373 break;
2374 case 4: /* TCO */
2375 ucontrol->value.enumerated.item[0] =
2376 hdspm_get_tco_sample_rate(hdspm);
2377 break;
2378 case 5: /* SYNC_IN */
2379 ucontrol->value.enumerated.item[0] =
2380 hdspm_get_sync_in_sample_rate(hdspm);
2381 break;
2382 default:
2383 ucontrol->value.enumerated.item[0] =
2384 hdspm_get_s1_sample_rate(hdspm,
Adrian Knoth1cb7dbf2013-07-05 11:28:03 +02002385 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002386 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002387 break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002388
2389 case AES32:
2390
2391 switch (kcontrol->private_value) {
2392 case 0: /* WC */
2393 ucontrol->value.enumerated.item[0] =
2394 hdspm_get_wc_sample_rate(hdspm);
2395 break;
2396 case 9: /* TCO */
2397 ucontrol->value.enumerated.item[0] =
2398 hdspm_get_tco_sample_rate(hdspm);
2399 break;
2400 case 10: /* SYNC_IN */
2401 ucontrol->value.enumerated.item[0] =
2402 hdspm_get_sync_in_sample_rate(hdspm);
2403 break;
2404 default: /* AES1 to AES8 */
2405 ucontrol->value.enumerated.item[0] =
2406 hdspm_get_s1_sample_rate(hdspm,
2407 kcontrol->private_value-1);
2408 break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002409 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002410 break;
Adrian Knothb8812c52012-10-19 17:42:26 +02002411
2412 case MADI:
2413 case MADIface:
Adrian Knoth23361422013-07-05 11:28:17 +02002414 ucontrol->value.enumerated.item[0] =
2415 hdspm_external_rate_to_enum(hdspm);
Adrian Knothb8812c52012-10-19 17:42:26 +02002416 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002417 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002418 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002419 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002420
Takashi Iwai763f3562005-06-03 11:25:34 +02002421 return 0;
2422}
2423
Adrian Knoth0dca1792011-01-26 19:32:14 +01002424
Takashi Iwai763f3562005-06-03 11:25:34 +02002425#define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002426{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2427 .name = xname, \
2428 .index = xindex, \
2429 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2430 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2431 .info = snd_hdspm_info_system_clock_mode, \
2432 .get = snd_hdspm_get_system_clock_mode, \
2433 .put = snd_hdspm_put_system_clock_mode, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002434}
2435
2436
Adrian Knoth0dca1792011-01-26 19:32:14 +01002437/**
2438 * Returns the system clock mode for the given card.
2439 * @returns 0 - master, 1 - slave
2440 **/
2441static int hdspm_system_clock_mode(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002442{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002443 switch (hdspm->io_type) {
2444 case AIO:
2445 case RayDAT:
2446 if (hdspm->settings_register & HDSPM_c0Master)
2447 return 0;
2448 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002449
Adrian Knoth0dca1792011-01-26 19:32:14 +01002450 default:
2451 if (hdspm->control_register & HDSPM_ClockModeMaster)
2452 return 0;
2453 }
2454
Takashi Iwai763f3562005-06-03 11:25:34 +02002455 return 1;
2456}
2457
Adrian Knoth0dca1792011-01-26 19:32:14 +01002458
2459/**
2460 * Sets the system clock mode.
2461 * @param mode 0 - master, 1 - slave
2462 **/
2463static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
2464{
Adrian Knoth34be7eb2013-07-05 11:27:56 +02002465 hdspm_set_toggle_setting(hdspm,
2466 (hdspm_is_raydat_or_aio(hdspm)) ?
2467 HDSPM_c0Master : HDSPM_ClockModeMaster,
2468 (0 == mode));
Adrian Knoth0dca1792011-01-26 19:32:14 +01002469}
2470
2471
Takashi Iwai98274f02005-11-17 14:52:34 +01002472static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
2473 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002474{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002475 static char *texts[] = { "Master", "AutoSync" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01002476 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02002477 return 0;
2478}
2479
Takashi Iwai98274f02005-11-17 14:52:34 +01002480static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol,
2481 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002482{
Takashi Iwai98274f02005-11-17 14:52:34 +01002483 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002484
Adrian Knoth0dca1792011-01-26 19:32:14 +01002485 ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002486 return 0;
2487}
2488
Adrian Knoth0dca1792011-01-26 19:32:14 +01002489static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol,
2490 struct snd_ctl_elem_value *ucontrol)
2491{
2492 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2493 int val;
2494
2495 if (!snd_hdspm_use_is_exclusive(hdspm))
2496 return -EBUSY;
2497
2498 val = ucontrol->value.enumerated.item[0];
2499 if (val < 0)
2500 val = 0;
2501 else if (val > 1)
2502 val = 1;
2503
2504 hdspm_set_system_clock_mode(hdspm, val);
2505
2506 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002507}
2508
Adrian Knoth0dca1792011-01-26 19:32:14 +01002509
2510#define HDSPM_INTERNAL_CLOCK(xname, xindex) \
2511{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2512 .name = xname, \
2513 .index = xindex, \
2514 .info = snd_hdspm_info_clock_source, \
2515 .get = snd_hdspm_get_clock_source, \
2516 .put = snd_hdspm_put_clock_source \
2517}
2518
2519
Takashi Iwai98274f02005-11-17 14:52:34 +01002520static int hdspm_clock_source(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002521{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002522 switch (hdspm->system_sample_rate) {
2523 case 32000: return 0;
2524 case 44100: return 1;
2525 case 48000: return 2;
2526 case 64000: return 3;
2527 case 88200: return 4;
2528 case 96000: return 5;
2529 case 128000: return 6;
2530 case 176400: return 7;
2531 case 192000: return 8;
Takashi Iwai763f3562005-06-03 11:25:34 +02002532 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002533
2534 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002535}
2536
Takashi Iwai98274f02005-11-17 14:52:34 +01002537static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
Takashi Iwai763f3562005-06-03 11:25:34 +02002538{
2539 int rate;
2540 switch (mode) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002541 case 0:
2542 rate = 32000; break;
2543 case 1:
2544 rate = 44100; break;
2545 case 2:
2546 rate = 48000; break;
2547 case 3:
2548 rate = 64000; break;
2549 case 4:
2550 rate = 88200; break;
2551 case 5:
2552 rate = 96000; break;
2553 case 6:
2554 rate = 128000; break;
2555 case 7:
2556 rate = 176400; break;
2557 case 8:
2558 rate = 192000; break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002559 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002560 rate = 48000;
Takashi Iwai763f3562005-06-03 11:25:34 +02002561 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002562 hdspm_set_rate(hdspm, rate, 1);
2563 return 0;
2564}
2565
Takashi Iwai98274f02005-11-17 14:52:34 +01002566static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002568{
Takashi Iwai763f3562005-06-03 11:25:34 +02002569 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2570 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002571 uinfo->value.enumerated.items = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002572
2573 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2574 uinfo->value.enumerated.item =
2575 uinfo->value.enumerated.items - 1;
2576
2577 strcpy(uinfo->value.enumerated.name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01002578 texts_freq[uinfo->value.enumerated.item+1]);
Takashi Iwai763f3562005-06-03 11:25:34 +02002579
2580 return 0;
2581}
2582
Takashi Iwai98274f02005-11-17 14:52:34 +01002583static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
2584 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002585{
Takashi Iwai98274f02005-11-17 14:52:34 +01002586 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002587
2588 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
2589 return 0;
2590}
2591
Takashi Iwai98274f02005-11-17 14:52:34 +01002592static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
2593 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002594{
Takashi Iwai98274f02005-11-17 14:52:34 +01002595 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002596 int change;
2597 int val;
2598
2599 if (!snd_hdspm_use_is_exclusive(hdspm))
2600 return -EBUSY;
2601 val = ucontrol->value.enumerated.item[0];
2602 if (val < 0)
2603 val = 0;
Remy Bruno65345992007-08-31 12:21:08 +02002604 if (val > 9)
2605 val = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002606 spin_lock_irq(&hdspm->lock);
2607 if (val != hdspm_clock_source(hdspm))
2608 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
2609 else
2610 change = 0;
2611 spin_unlock_irq(&hdspm->lock);
2612 return change;
2613}
2614
Adrian Knoth0dca1792011-01-26 19:32:14 +01002615
Takashi Iwai763f3562005-06-03 11:25:34 +02002616#define HDSPM_PREF_SYNC_REF(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02002617{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002618 .name = xname, \
2619 .index = xindex, \
2620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2621 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2622 .info = snd_hdspm_info_pref_sync_ref, \
2623 .get = snd_hdspm_get_pref_sync_ref, \
2624 .put = snd_hdspm_put_pref_sync_ref \
Takashi Iwai763f3562005-06-03 11:25:34 +02002625}
2626
Adrian Knoth0dca1792011-01-26 19:32:14 +01002627
2628/**
2629 * Returns the current preferred sync reference setting.
2630 * The semantics of the return value are depending on the
2631 * card, please see the comments for clarification.
2632 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002633static int hdspm_pref_sync_ref(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002634{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002635 switch (hdspm->io_type) {
2636 case AES32:
Remy Bruno3cee5a62006-10-16 12:46:32 +02002637 switch (hdspm->control_register & HDSPM_SyncRefMask) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002638 case 0: return 0; /* WC */
2639 case HDSPM_SyncRef0: return 1; /* AES 1 */
2640 case HDSPM_SyncRef1: return 2; /* AES 2 */
2641 case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */
2642 case HDSPM_SyncRef2: return 4; /* AES 4 */
2643 case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */
2644 case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */
2645 case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0:
2646 return 7; /* AES 7 */
2647 case HDSPM_SyncRef3: return 8; /* AES 8 */
2648 case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002649 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002650 break;
2651
2652 case MADI:
2653 case MADIface:
2654 if (hdspm->tco) {
2655 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2656 case 0: return 0; /* WC */
2657 case HDSPM_SyncRef0: return 1; /* MADI */
2658 case HDSPM_SyncRef1: return 2; /* TCO */
2659 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2660 return 3; /* SYNC_IN */
2661 }
2662 } else {
2663 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2664 case 0: return 0; /* WC */
2665 case HDSPM_SyncRef0: return 1; /* MADI */
2666 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2667 return 2; /* SYNC_IN */
2668 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02002669 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002670 break;
2671
2672 case RayDAT:
2673 if (hdspm->tco) {
2674 switch ((hdspm->settings_register &
2675 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2676 case 0: return 0; /* WC */
2677 case 3: return 1; /* ADAT 1 */
2678 case 4: return 2; /* ADAT 2 */
2679 case 5: return 3; /* ADAT 3 */
2680 case 6: return 4; /* ADAT 4 */
2681 case 1: return 5; /* AES */
2682 case 2: return 6; /* SPDIF */
2683 case 9: return 7; /* TCO */
2684 case 10: return 8; /* SYNC_IN */
2685 }
2686 } else {
2687 switch ((hdspm->settings_register &
2688 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2689 case 0: return 0; /* WC */
2690 case 3: return 1; /* ADAT 1 */
2691 case 4: return 2; /* ADAT 2 */
2692 case 5: return 3; /* ADAT 3 */
2693 case 6: return 4; /* ADAT 4 */
2694 case 1: return 5; /* AES */
2695 case 2: return 6; /* SPDIF */
2696 case 10: return 7; /* SYNC_IN */
2697 }
2698 }
2699
2700 break;
2701
2702 case AIO:
2703 if (hdspm->tco) {
2704 switch ((hdspm->settings_register &
2705 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2706 case 0: return 0; /* WC */
2707 case 3: return 1; /* ADAT */
2708 case 1: return 2; /* AES */
2709 case 2: return 3; /* SPDIF */
2710 case 9: return 4; /* TCO */
2711 case 10: return 5; /* SYNC_IN */
2712 }
2713 } else {
2714 switch ((hdspm->settings_register &
2715 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2716 case 0: return 0; /* WC */
2717 case 3: return 1; /* ADAT */
2718 case 1: return 2; /* AES */
2719 case 2: return 3; /* SPDIF */
2720 case 10: return 4; /* SYNC_IN */
2721 }
2722 }
2723
2724 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002725 }
2726
Adrian Knoth0dca1792011-01-26 19:32:14 +01002727 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002728}
2729
Adrian Knoth0dca1792011-01-26 19:32:14 +01002730
2731/**
2732 * Set the preferred sync reference to <pref>. The semantics
2733 * of <pref> are depending on the card type, see the comments
2734 * for clarification.
2735 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002736static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
Takashi Iwai763f3562005-06-03 11:25:34 +02002737{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002738 int p = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002739
Adrian Knoth0dca1792011-01-26 19:32:14 +01002740 switch (hdspm->io_type) {
2741 case AES32:
2742 hdspm->control_register &= ~HDSPM_SyncRefMask;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002743 switch (pref) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002744 case 0: /* WC */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002745 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002746 case 1: /* AES 1 */
2747 hdspm->control_register |= HDSPM_SyncRef0;
2748 break;
2749 case 2: /* AES 2 */
2750 hdspm->control_register |= HDSPM_SyncRef1;
2751 break;
2752 case 3: /* AES 3 */
2753 hdspm->control_register |=
2754 HDSPM_SyncRef1+HDSPM_SyncRef0;
2755 break;
2756 case 4: /* AES 4 */
2757 hdspm->control_register |= HDSPM_SyncRef2;
2758 break;
2759 case 5: /* AES 5 */
2760 hdspm->control_register |=
2761 HDSPM_SyncRef2+HDSPM_SyncRef0;
2762 break;
2763 case 6: /* AES 6 */
2764 hdspm->control_register |=
2765 HDSPM_SyncRef2+HDSPM_SyncRef1;
2766 break;
2767 case 7: /* AES 7 */
2768 hdspm->control_register |=
2769 HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
2770 break;
2771 case 8: /* AES 8 */
2772 hdspm->control_register |= HDSPM_SyncRef3;
2773 break;
2774 case 9: /* TCO */
2775 hdspm->control_register |=
2776 HDSPM_SyncRef3+HDSPM_SyncRef0;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002777 break;
2778 default:
2779 return -1;
2780 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002781
2782 break;
2783
2784 case MADI:
2785 case MADIface:
2786 hdspm->control_register &= ~HDSPM_SyncRefMask;
2787 if (hdspm->tco) {
2788 switch (pref) {
2789 case 0: /* WC */
2790 break;
2791 case 1: /* MADI */
2792 hdspm->control_register |= HDSPM_SyncRef0;
2793 break;
2794 case 2: /* TCO */
2795 hdspm->control_register |= HDSPM_SyncRef1;
2796 break;
2797 case 3: /* SYNC_IN */
2798 hdspm->control_register |=
2799 HDSPM_SyncRef0+HDSPM_SyncRef1;
2800 break;
2801 default:
2802 return -1;
2803 }
2804 } else {
2805 switch (pref) {
2806 case 0: /* WC */
2807 break;
2808 case 1: /* MADI */
2809 hdspm->control_register |= HDSPM_SyncRef0;
2810 break;
2811 case 2: /* SYNC_IN */
2812 hdspm->control_register |=
2813 HDSPM_SyncRef0+HDSPM_SyncRef1;
2814 break;
2815 default:
2816 return -1;
2817 }
2818 }
2819
2820 break;
2821
2822 case RayDAT:
2823 if (hdspm->tco) {
2824 switch (pref) {
2825 case 0: p = 0; break; /* WC */
2826 case 1: p = 3; break; /* ADAT 1 */
2827 case 2: p = 4; break; /* ADAT 2 */
2828 case 3: p = 5; break; /* ADAT 3 */
2829 case 4: p = 6; break; /* ADAT 4 */
2830 case 5: p = 1; break; /* AES */
2831 case 6: p = 2; break; /* SPDIF */
2832 case 7: p = 9; break; /* TCO */
2833 case 8: p = 10; break; /* SYNC_IN */
2834 default: return -1;
2835 }
2836 } else {
2837 switch (pref) {
2838 case 0: p = 0; break; /* WC */
2839 case 1: p = 3; break; /* ADAT 1 */
2840 case 2: p = 4; break; /* ADAT 2 */
2841 case 3: p = 5; break; /* ADAT 3 */
2842 case 4: p = 6; break; /* ADAT 4 */
2843 case 5: p = 1; break; /* AES */
2844 case 6: p = 2; break; /* SPDIF */
2845 case 7: p = 10; break; /* SYNC_IN */
2846 default: return -1;
2847 }
2848 }
2849 break;
2850
2851 case AIO:
2852 if (hdspm->tco) {
2853 switch (pref) {
2854 case 0: p = 0; break; /* WC */
2855 case 1: p = 3; break; /* ADAT */
2856 case 2: p = 1; break; /* AES */
2857 case 3: p = 2; break; /* SPDIF */
2858 case 4: p = 9; break; /* TCO */
2859 case 5: p = 10; break; /* SYNC_IN */
2860 default: return -1;
2861 }
2862 } else {
2863 switch (pref) {
2864 case 0: p = 0; break; /* WC */
2865 case 1: p = 3; break; /* ADAT */
2866 case 2: p = 1; break; /* AES */
2867 case 3: p = 2; break; /* SPDIF */
2868 case 4: p = 10; break; /* SYNC_IN */
2869 default: return -1;
2870 }
2871 }
2872 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002873 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002874
2875 switch (hdspm->io_type) {
2876 case RayDAT:
2877 case AIO:
2878 hdspm->settings_register &= ~HDSPM_c0_SyncRefMask;
2879 hdspm->settings_register |= HDSPM_c0_SyncRef0 * p;
2880 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
2881 break;
2882
2883 case MADI:
2884 case MADIface:
2885 case AES32:
2886 hdspm_write(hdspm, HDSPM_controlRegister,
2887 hdspm->control_register);
2888 }
2889
Takashi Iwai763f3562005-06-03 11:25:34 +02002890 return 0;
2891}
2892
Adrian Knoth0dca1792011-01-26 19:32:14 +01002893
Takashi Iwai98274f02005-11-17 14:52:34 +01002894static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol,
2895 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002896{
Remy Bruno3cee5a62006-10-16 12:46:32 +02002897 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002898
Adrian Knoth0dca1792011-01-26 19:32:14 +01002899 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2900 uinfo->count = 1;
2901 uinfo->value.enumerated.items = hdspm->texts_autosync_items;
Takashi Iwai763f3562005-06-03 11:25:34 +02002902
Adrian Knoth0dca1792011-01-26 19:32:14 +01002903 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2904 uinfo->value.enumerated.item =
2905 uinfo->value.enumerated.items - 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002906
Adrian Knoth0dca1792011-01-26 19:32:14 +01002907 strcpy(uinfo->value.enumerated.name,
2908 hdspm->texts_autosync[uinfo->value.enumerated.item]);
Remy Bruno3cee5a62006-10-16 12:46:32 +02002909
Takashi Iwai763f3562005-06-03 11:25:34 +02002910 return 0;
2911}
2912
Takashi Iwai98274f02005-11-17 14:52:34 +01002913static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol,
2914 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002915{
Takashi Iwai98274f02005-11-17 14:52:34 +01002916 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002917 int psf = hdspm_pref_sync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002918
Adrian Knoth0dca1792011-01-26 19:32:14 +01002919 if (psf >= 0) {
2920 ucontrol->value.enumerated.item[0] = psf;
2921 return 0;
2922 }
2923
2924 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002925}
2926
Takashi Iwai98274f02005-11-17 14:52:34 +01002927static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,
2928 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002929{
Takashi Iwai98274f02005-11-17 14:52:34 +01002930 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002931 int val, change = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002932
2933 if (!snd_hdspm_use_is_exclusive(hdspm))
2934 return -EBUSY;
2935
Adrian Knoth0dca1792011-01-26 19:32:14 +01002936 val = ucontrol->value.enumerated.item[0];
2937
2938 if (val < 0)
2939 val = 0;
2940 else if (val >= hdspm->texts_autosync_items)
2941 val = hdspm->texts_autosync_items-1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002942
2943 spin_lock_irq(&hdspm->lock);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002944 if (val != hdspm_pref_sync_ref(hdspm))
2945 change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0;
2946
Takashi Iwai763f3562005-06-03 11:25:34 +02002947 spin_unlock_irq(&hdspm->lock);
2948 return change;
2949}
2950
Adrian Knoth0dca1792011-01-26 19:32:14 +01002951
Takashi Iwai763f3562005-06-03 11:25:34 +02002952#define HDSPM_AUTOSYNC_REF(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02002953{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2954 .name = xname, \
2955 .index = xindex, \
2956 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2957 .info = snd_hdspm_info_autosync_ref, \
2958 .get = snd_hdspm_get_autosync_ref, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002959}
2960
Adrian Knoth0dca1792011-01-26 19:32:14 +01002961static int hdspm_autosync_ref(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002962{
Adrian Knoth2d60fc72013-07-05 11:28:15 +02002963 /* This looks at the autosync selected sync reference */
Adrian Knoth0dca1792011-01-26 19:32:14 +01002964 if (AES32 == hdspm->io_type) {
Takashi Iwai763f3562005-06-03 11:25:34 +02002965
Adrian Knoth2d60fc72013-07-05 11:28:15 +02002966 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
2967 unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF;
2968 if ((syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD) &&
2969 (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN)) {
2970 return syncref;
2971 }
2972 return HDSPM_AES32_AUTOSYNC_FROM_NONE;
2973
2974 } else if (MADI == hdspm->io_type) {
2975
2976 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02002977 switch (status2 & HDSPM_SelSyncRefMask) {
2978 case HDSPM_SelSyncRef_WORD:
2979 return HDSPM_AUTOSYNC_FROM_WORD;
2980 case HDSPM_SelSyncRef_MADI:
2981 return HDSPM_AUTOSYNC_FROM_MADI;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002982 case HDSPM_SelSyncRef_TCO:
2983 return HDSPM_AUTOSYNC_FROM_TCO;
2984 case HDSPM_SelSyncRef_SyncIn:
2985 return HDSPM_AUTOSYNC_FROM_SYNC_IN;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002986 case HDSPM_SelSyncRef_NVALID:
2987 return HDSPM_AUTOSYNC_FROM_NONE;
2988 default:
Adrian Knothe71b95a2013-07-05 11:28:06 +02002989 return HDSPM_AUTOSYNC_FROM_NONE;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002990 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002991
Takashi Iwai763f3562005-06-03 11:25:34 +02002992 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002993 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002994}
2995
Adrian Knoth0dca1792011-01-26 19:32:14 +01002996
Takashi Iwai98274f02005-11-17 14:52:34 +01002997static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol,
2998 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002999{
Remy Bruno3cee5a62006-10-16 12:46:32 +02003000 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003001
Adrian Knoth0dca1792011-01-26 19:32:14 +01003002 if (AES32 == hdspm->io_type) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02003003 static char *texts[] = { "WordClock", "AES1", "AES2", "AES3",
Adrian Knothdb2d1a92013-07-05 11:28:08 +02003004 "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In", "None"};
Remy Bruno3cee5a62006-10-16 12:46:32 +02003005
3006 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3007 uinfo->count = 1;
Adrian Knothdb2d1a92013-07-05 11:28:08 +02003008 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003009 if (uinfo->value.enumerated.item >=
3010 uinfo->value.enumerated.items)
Remy Bruno3cee5a62006-10-16 12:46:32 +02003011 uinfo->value.enumerated.item =
3012 uinfo->value.enumerated.items - 1;
3013 strcpy(uinfo->value.enumerated.name,
3014 texts[uinfo->value.enumerated.item]);
Adrian Knoth0dca1792011-01-26 19:32:14 +01003015 } else if (MADI == hdspm->io_type) {
3016 static char *texts[] = {"Word Clock", "MADI", "TCO",
3017 "Sync In", "None" };
Remy Bruno3cee5a62006-10-16 12:46:32 +02003018
3019 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3020 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003021 uinfo->value.enumerated.items = 5;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003022 if (uinfo->value.enumerated.item >=
Adrian Knoth0dca1792011-01-26 19:32:14 +01003023 uinfo->value.enumerated.items)
Remy Bruno3cee5a62006-10-16 12:46:32 +02003024 uinfo->value.enumerated.item =
3025 uinfo->value.enumerated.items - 1;
3026 strcpy(uinfo->value.enumerated.name,
3027 texts[uinfo->value.enumerated.item]);
3028 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003029 return 0;
3030}
3031
Takashi Iwai98274f02005-11-17 14:52:34 +01003032static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
3033 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003034{
Takashi Iwai98274f02005-11-17 14:52:34 +01003035 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003036
Remy Bruno65345992007-08-31 12:21:08 +02003037 ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02003038 return 0;
3039}
3040
Adrian Knothf99c7882013-03-10 00:37:26 +01003041
3042
3043#define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \
3044{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3045 .name = xname, \
3046 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3047 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3048 .info = snd_hdspm_info_tco_video_input_format, \
3049 .get = snd_hdspm_get_tco_video_input_format, \
3050}
3051
3052static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol,
3053 struct snd_ctl_elem_info *uinfo)
3054{
3055 static char *texts[] = {"No video", "NTSC", "PAL"};
3056 ENUMERATED_CTL_INFO(uinfo, texts);
3057 return 0;
3058}
3059
3060static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol,
3061 struct snd_ctl_elem_value *ucontrol)
3062{
3063 u32 status;
3064 int ret = 0;
3065
3066 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3067 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3068 switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC |
3069 HDSPM_TCO1_Video_Input_Format_PAL)) {
3070 case HDSPM_TCO1_Video_Input_Format_NTSC:
3071 /* ntsc */
3072 ret = 1;
3073 break;
3074 case HDSPM_TCO1_Video_Input_Format_PAL:
3075 /* pal */
3076 ret = 2;
3077 break;
3078 default:
3079 /* no video */
3080 ret = 0;
3081 break;
3082 }
3083 ucontrol->value.enumerated.item[0] = ret;
3084 return 0;
3085}
3086
3087
3088
3089#define HDSPM_TCO_LTC_FRAMES(xname, xindex) \
3090{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3091 .name = xname, \
3092 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3093 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3094 .info = snd_hdspm_info_tco_ltc_frames, \
3095 .get = snd_hdspm_get_tco_ltc_frames, \
3096}
3097
3098static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3099 struct snd_ctl_elem_info *uinfo)
3100{
3101 static char *texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps",
3102 "30 fps"};
3103 ENUMERATED_CTL_INFO(uinfo, texts);
3104 return 0;
3105}
3106
3107static int hdspm_tco_ltc_frames(struct hdspm *hdspm)
3108{
3109 u32 status;
3110 int ret = 0;
3111
3112 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3113 if (status & HDSPM_TCO1_LTC_Input_valid) {
3114 switch (status & (HDSPM_TCO1_LTC_Format_LSB |
3115 HDSPM_TCO1_LTC_Format_MSB)) {
3116 case 0:
3117 /* 24 fps */
3118 ret = 1;
3119 break;
3120 case HDSPM_TCO1_LTC_Format_LSB:
3121 /* 25 fps */
3122 ret = 2;
3123 break;
3124 case HDSPM_TCO1_LTC_Format_MSB:
3125 /* 25 fps */
3126 ret = 3;
3127 break;
3128 default:
3129 /* 30 fps */
3130 ret = 4;
3131 break;
3132 }
3133 }
3134
3135 return ret;
3136}
3137
3138static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3139 struct snd_ctl_elem_value *ucontrol)
3140{
3141 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3142
3143 ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm);
3144 return 0;
3145}
3146
Adrian Knothbf0ff872012-12-03 14:55:49 +01003147#define HDSPM_TOGGLE_SETTING(xname, xindex) \
3148{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3149 .name = xname, \
3150 .private_value = xindex, \
3151 .info = snd_hdspm_info_toggle_setting, \
3152 .get = snd_hdspm_get_toggle_setting, \
3153 .put = snd_hdspm_put_toggle_setting \
3154}
3155
3156static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask)
3157{
Adrian Knothce13f3f2013-07-05 11:27:55 +02003158 u32 reg;
3159
3160 if (hdspm_is_raydat_or_aio(hdspm))
3161 reg = hdspm->settings_register;
3162 else
3163 reg = hdspm->control_register;
3164
3165 return (reg & regmask) ? 1 : 0;
Adrian Knothbf0ff872012-12-03 14:55:49 +01003166}
3167
3168static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out)
3169{
Adrian Knothce13f3f2013-07-05 11:27:55 +02003170 u32 *reg;
3171 u32 target_reg;
3172
3173 if (hdspm_is_raydat_or_aio(hdspm)) {
3174 reg = &(hdspm->settings_register);
3175 target_reg = HDSPM_WR_SETTINGS;
3176 } else {
3177 reg = &(hdspm->control_register);
3178 target_reg = HDSPM_controlRegister;
3179 }
3180
Adrian Knothbf0ff872012-12-03 14:55:49 +01003181 if (out)
Adrian Knothce13f3f2013-07-05 11:27:55 +02003182 *reg |= regmask;
Adrian Knothbf0ff872012-12-03 14:55:49 +01003183 else
Adrian Knothce13f3f2013-07-05 11:27:55 +02003184 *reg &= ~regmask;
3185
3186 hdspm_write(hdspm, target_reg, *reg);
Adrian Knothbf0ff872012-12-03 14:55:49 +01003187
3188 return 0;
3189}
3190
3191#define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info
3192
3193static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol,
3194 struct snd_ctl_elem_value *ucontrol)
3195{
3196 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3197 u32 regmask = kcontrol->private_value;
3198
3199 spin_lock_irq(&hdspm->lock);
3200 ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask);
3201 spin_unlock_irq(&hdspm->lock);
3202 return 0;
3203}
3204
3205static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol,
3206 struct snd_ctl_elem_value *ucontrol)
3207{
3208 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3209 u32 regmask = kcontrol->private_value;
3210 int change;
3211 unsigned int val;
3212
3213 if (!snd_hdspm_use_is_exclusive(hdspm))
3214 return -EBUSY;
3215 val = ucontrol->value.integer.value[0] & 1;
3216 spin_lock_irq(&hdspm->lock);
3217 change = (int) val != hdspm_toggle_setting(hdspm, regmask);
3218 hdspm_set_toggle_setting(hdspm, regmask, val);
3219 spin_unlock_irq(&hdspm->lock);
3220 return change;
3221}
3222
Takashi Iwai763f3562005-06-03 11:25:34 +02003223#define HDSPM_INPUT_SELECT(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003224{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3225 .name = xname, \
3226 .index = xindex, \
3227 .info = snd_hdspm_info_input_select, \
3228 .get = snd_hdspm_get_input_select, \
3229 .put = snd_hdspm_put_input_select \
Takashi Iwai763f3562005-06-03 11:25:34 +02003230}
3231
Takashi Iwai98274f02005-11-17 14:52:34 +01003232static int hdspm_input_select(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003233{
3234 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
3235}
3236
Takashi Iwai98274f02005-11-17 14:52:34 +01003237static int hdspm_set_input_select(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02003238{
3239 if (out)
3240 hdspm->control_register |= HDSPM_InputSelect0;
3241 else
3242 hdspm->control_register &= ~HDSPM_InputSelect0;
3243 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3244
3245 return 0;
3246}
3247
Takashi Iwai98274f02005-11-17 14:52:34 +01003248static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
3249 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003250{
3251 static char *texts[] = { "optical", "coaxial" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003252 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02003253 return 0;
3254}
3255
Takashi Iwai98274f02005-11-17 14:52:34 +01003256static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol,
3257 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003258{
Takashi Iwai98274f02005-11-17 14:52:34 +01003259 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003260
3261 spin_lock_irq(&hdspm->lock);
3262 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
3263 spin_unlock_irq(&hdspm->lock);
3264 return 0;
3265}
3266
Takashi Iwai98274f02005-11-17 14:52:34 +01003267static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,
3268 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003269{
Takashi Iwai98274f02005-11-17 14:52:34 +01003270 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003271 int change;
3272 unsigned int val;
3273
3274 if (!snd_hdspm_use_is_exclusive(hdspm))
3275 return -EBUSY;
3276 val = ucontrol->value.integer.value[0] & 1;
3277 spin_lock_irq(&hdspm->lock);
3278 change = (int) val != hdspm_input_select(hdspm);
3279 hdspm_set_input_select(hdspm, val);
3280 spin_unlock_irq(&hdspm->lock);
3281 return change;
3282}
3283
Adrian Knoth0dca1792011-01-26 19:32:14 +01003284
Remy Bruno3cee5a62006-10-16 12:46:32 +02003285#define HDSPM_DS_WIRE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003286{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3287 .name = xname, \
3288 .index = xindex, \
3289 .info = snd_hdspm_info_ds_wire, \
3290 .get = snd_hdspm_get_ds_wire, \
3291 .put = snd_hdspm_put_ds_wire \
Remy Bruno3cee5a62006-10-16 12:46:32 +02003292}
3293
3294static int hdspm_ds_wire(struct hdspm * hdspm)
3295{
3296 return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
3297}
3298
3299static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
3300{
3301 if (ds)
3302 hdspm->control_register |= HDSPM_DS_DoubleWire;
3303 else
3304 hdspm->control_register &= ~HDSPM_DS_DoubleWire;
3305 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3306
3307 return 0;
3308}
3309
3310static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
3311 struct snd_ctl_elem_info *uinfo)
3312{
3313 static char *texts[] = { "Single", "Double" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003314 ENUMERATED_CTL_INFO(uinfo, texts);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003315 return 0;
3316}
3317
3318static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol,
3319 struct snd_ctl_elem_value *ucontrol)
3320{
3321 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3322
3323 spin_lock_irq(&hdspm->lock);
3324 ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
3325 spin_unlock_irq(&hdspm->lock);
3326 return 0;
3327}
3328
3329static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,
3330 struct snd_ctl_elem_value *ucontrol)
3331{
3332 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3333 int change;
3334 unsigned int val;
3335
3336 if (!snd_hdspm_use_is_exclusive(hdspm))
3337 return -EBUSY;
3338 val = ucontrol->value.integer.value[0] & 1;
3339 spin_lock_irq(&hdspm->lock);
3340 change = (int) val != hdspm_ds_wire(hdspm);
3341 hdspm_set_ds_wire(hdspm, val);
3342 spin_unlock_irq(&hdspm->lock);
3343 return change;
3344}
3345
Adrian Knoth0dca1792011-01-26 19:32:14 +01003346
Remy Bruno3cee5a62006-10-16 12:46:32 +02003347#define HDSPM_QS_WIRE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003348{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3349 .name = xname, \
3350 .index = xindex, \
3351 .info = snd_hdspm_info_qs_wire, \
3352 .get = snd_hdspm_get_qs_wire, \
3353 .put = snd_hdspm_put_qs_wire \
Remy Bruno3cee5a62006-10-16 12:46:32 +02003354}
3355
3356static int hdspm_qs_wire(struct hdspm * hdspm)
3357{
3358 if (hdspm->control_register & HDSPM_QS_DoubleWire)
3359 return 1;
3360 if (hdspm->control_register & HDSPM_QS_QuadWire)
3361 return 2;
3362 return 0;
3363}
3364
3365static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
3366{
3367 hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
3368 switch (mode) {
3369 case 0:
3370 break;
3371 case 1:
3372 hdspm->control_register |= HDSPM_QS_DoubleWire;
3373 break;
3374 case 2:
3375 hdspm->control_register |= HDSPM_QS_QuadWire;
3376 break;
3377 }
3378 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3379
3380 return 0;
3381}
3382
3383static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
3384 struct snd_ctl_elem_info *uinfo)
3385{
3386 static char *texts[] = { "Single", "Double", "Quad" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003387 ENUMERATED_CTL_INFO(uinfo, texts);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003388 return 0;
3389}
3390
3391static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol,
3392 struct snd_ctl_elem_value *ucontrol)
3393{
3394 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3395
3396 spin_lock_irq(&hdspm->lock);
3397 ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
3398 spin_unlock_irq(&hdspm->lock);
3399 return 0;
3400}
3401
3402static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
3403 struct snd_ctl_elem_value *ucontrol)
3404{
3405 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3406 int change;
3407 int val;
3408
3409 if (!snd_hdspm_use_is_exclusive(hdspm))
3410 return -EBUSY;
3411 val = ucontrol->value.integer.value[0];
3412 if (val < 0)
3413 val = 0;
3414 if (val > 2)
3415 val = 2;
3416 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003417 change = val != hdspm_qs_wire(hdspm);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003418 hdspm_set_qs_wire(hdspm, val);
3419 spin_unlock_irq(&hdspm->lock);
3420 return change;
3421}
3422
Adrian Knothacf14762013-07-05 11:28:00 +02003423#define HDSPM_CONTROL_TRISTATE(xname, xindex) \
3424{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3425 .name = xname, \
3426 .private_value = xindex, \
3427 .info = snd_hdspm_info_tristate, \
3428 .get = snd_hdspm_get_tristate, \
3429 .put = snd_hdspm_put_tristate \
3430}
3431
3432static int hdspm_tristate(struct hdspm *hdspm, u32 regmask)
3433{
3434 u32 reg = hdspm->settings_register & (regmask * 3);
3435 return reg / regmask;
3436}
3437
3438static int hdspm_set_tristate(struct hdspm *hdspm, int mode, u32 regmask)
3439{
3440 hdspm->settings_register &= ~(regmask * 3);
3441 hdspm->settings_register |= (regmask * mode);
3442 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
3443
3444 return 0;
3445}
3446
3447static int snd_hdspm_info_tristate(struct snd_kcontrol *kcontrol,
3448 struct snd_ctl_elem_info *uinfo)
3449{
3450 u32 regmask = kcontrol->private_value;
3451
3452 static char *texts_spdif[] = { "Optical", "Coaxial", "Internal" };
3453 static char *texts_levels[] = { "Hi Gain", "+4 dBu", "-10 dBV" };
3454
3455 switch (regmask) {
3456 case HDSPM_c0_Input0:
3457 ENUMERATED_CTL_INFO(uinfo, texts_spdif);
3458 break;
3459 default:
3460 ENUMERATED_CTL_INFO(uinfo, texts_levels);
3461 break;
3462 }
3463 return 0;
3464}
3465
3466static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol,
3467 struct snd_ctl_elem_value *ucontrol)
3468{
3469 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3470 u32 regmask = kcontrol->private_value;
3471
3472 spin_lock_irq(&hdspm->lock);
3473 ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask);
3474 spin_unlock_irq(&hdspm->lock);
3475 return 0;
3476}
3477
3478static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol,
3479 struct snd_ctl_elem_value *ucontrol)
3480{
3481 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3482 u32 regmask = kcontrol->private_value;
3483 int change;
3484 int val;
3485
3486 if (!snd_hdspm_use_is_exclusive(hdspm))
3487 return -EBUSY;
3488 val = ucontrol->value.integer.value[0];
3489 if (val < 0)
3490 val = 0;
3491 if (val > 2)
3492 val = 2;
3493
3494 spin_lock_irq(&hdspm->lock);
3495 change = val != hdspm_tristate(hdspm, regmask);
3496 hdspm_set_tristate(hdspm, val, regmask);
3497 spin_unlock_irq(&hdspm->lock);
3498 return change;
3499}
3500
Adrian Knoth700d1ef2011-07-29 03:11:02 +02003501#define HDSPM_MADI_SPEEDMODE(xname, xindex) \
3502{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3503 .name = xname, \
3504 .index = xindex, \
3505 .info = snd_hdspm_info_madi_speedmode, \
3506 .get = snd_hdspm_get_madi_speedmode, \
3507 .put = snd_hdspm_put_madi_speedmode \
3508}
3509
3510static int hdspm_madi_speedmode(struct hdspm *hdspm)
3511{
3512 if (hdspm->control_register & HDSPM_QuadSpeed)
3513 return 2;
3514 if (hdspm->control_register & HDSPM_DoubleSpeed)
3515 return 1;
3516 return 0;
3517}
3518
3519static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode)
3520{
3521 hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed);
3522 switch (mode) {
3523 case 0:
3524 break;
3525 case 1:
3526 hdspm->control_register |= HDSPM_DoubleSpeed;
3527 break;
3528 case 2:
3529 hdspm->control_register |= HDSPM_QuadSpeed;
3530 break;
3531 }
3532 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3533
3534 return 0;
3535}
3536
3537static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
3538 struct snd_ctl_elem_info *uinfo)
3539{
3540 static char *texts[] = { "Single", "Double", "Quad" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003541 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth700d1ef2011-07-29 03:11:02 +02003542 return 0;
3543}
3544
3545static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol,
3546 struct snd_ctl_elem_value *ucontrol)
3547{
3548 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3549
3550 spin_lock_irq(&hdspm->lock);
3551 ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm);
3552 spin_unlock_irq(&hdspm->lock);
3553 return 0;
3554}
3555
3556static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol,
3557 struct snd_ctl_elem_value *ucontrol)
3558{
3559 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3560 int change;
3561 int val;
3562
3563 if (!snd_hdspm_use_is_exclusive(hdspm))
3564 return -EBUSY;
3565 val = ucontrol->value.integer.value[0];
3566 if (val < 0)
3567 val = 0;
3568 if (val > 2)
3569 val = 2;
3570 spin_lock_irq(&hdspm->lock);
3571 change = val != hdspm_madi_speedmode(hdspm);
3572 hdspm_set_madi_speedmode(hdspm, val);
3573 spin_unlock_irq(&hdspm->lock);
3574 return change;
3575}
Takashi Iwai763f3562005-06-03 11:25:34 +02003576
3577#define HDSPM_MIXER(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003578{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3579 .name = xname, \
3580 .index = xindex, \
3581 .device = 0, \
3582 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3583 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3584 .info = snd_hdspm_info_mixer, \
3585 .get = snd_hdspm_get_mixer, \
3586 .put = snd_hdspm_put_mixer \
Takashi Iwai763f3562005-06-03 11:25:34 +02003587}
3588
Takashi Iwai98274f02005-11-17 14:52:34 +01003589static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol,
3590 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003591{
3592 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3593 uinfo->count = 3;
3594 uinfo->value.integer.min = 0;
3595 uinfo->value.integer.max = 65535;
3596 uinfo->value.integer.step = 1;
3597 return 0;
3598}
3599
Takashi Iwai98274f02005-11-17 14:52:34 +01003600static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,
3601 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003602{
Takashi Iwai98274f02005-11-17 14:52:34 +01003603 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003604 int source;
3605 int destination;
3606
3607 source = ucontrol->value.integer.value[0];
3608 if (source < 0)
3609 source = 0;
3610 else if (source >= 2 * HDSPM_MAX_CHANNELS)
3611 source = 2 * HDSPM_MAX_CHANNELS - 1;
3612
3613 destination = ucontrol->value.integer.value[1];
3614 if (destination < 0)
3615 destination = 0;
3616 else if (destination >= HDSPM_MAX_CHANNELS)
3617 destination = HDSPM_MAX_CHANNELS - 1;
3618
3619 spin_lock_irq(&hdspm->lock);
3620 if (source >= HDSPM_MAX_CHANNELS)
3621 ucontrol->value.integer.value[2] =
3622 hdspm_read_pb_gain(hdspm, destination,
3623 source - HDSPM_MAX_CHANNELS);
3624 else
3625 ucontrol->value.integer.value[2] =
3626 hdspm_read_in_gain(hdspm, destination, source);
3627
3628 spin_unlock_irq(&hdspm->lock);
3629
3630 return 0;
3631}
3632
Takashi Iwai98274f02005-11-17 14:52:34 +01003633static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,
3634 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003635{
Takashi Iwai98274f02005-11-17 14:52:34 +01003636 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003637 int change;
3638 int source;
3639 int destination;
3640 int gain;
3641
3642 if (!snd_hdspm_use_is_exclusive(hdspm))
3643 return -EBUSY;
3644
3645 source = ucontrol->value.integer.value[0];
3646 destination = ucontrol->value.integer.value[1];
3647
3648 if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
3649 return -1;
3650 if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
3651 return -1;
3652
3653 gain = ucontrol->value.integer.value[2];
3654
3655 spin_lock_irq(&hdspm->lock);
3656
3657 if (source >= HDSPM_MAX_CHANNELS)
3658 change = gain != hdspm_read_pb_gain(hdspm, destination,
3659 source -
3660 HDSPM_MAX_CHANNELS);
3661 else
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003662 change = gain != hdspm_read_in_gain(hdspm, destination,
3663 source);
Takashi Iwai763f3562005-06-03 11:25:34 +02003664
3665 if (change) {
3666 if (source >= HDSPM_MAX_CHANNELS)
3667 hdspm_write_pb_gain(hdspm, destination,
3668 source - HDSPM_MAX_CHANNELS,
3669 gain);
3670 else
3671 hdspm_write_in_gain(hdspm, destination, source,
3672 gain);
3673 }
3674 spin_unlock_irq(&hdspm->lock);
3675
3676 return change;
3677}
3678
3679/* The simple mixer control(s) provide gain control for the
3680 basic 1:1 mappings of playback streams to output
Adrian Knoth0dca1792011-01-26 19:32:14 +01003681 streams.
Takashi Iwai763f3562005-06-03 11:25:34 +02003682*/
3683
3684#define HDSPM_PLAYBACK_MIXER \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003685{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3686 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
3687 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3688 .info = snd_hdspm_info_playback_mixer, \
3689 .get = snd_hdspm_get_playback_mixer, \
3690 .put = snd_hdspm_put_playback_mixer \
Takashi Iwai763f3562005-06-03 11:25:34 +02003691}
3692
Takashi Iwai98274f02005-11-17 14:52:34 +01003693static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol,
3694 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003695{
3696 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3697 uinfo->count = 1;
3698 uinfo->value.integer.min = 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003699 uinfo->value.integer.max = 64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003700 uinfo->value.integer.step = 1;
3701 return 0;
3702}
3703
Takashi Iwai98274f02005-11-17 14:52:34 +01003704static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
3705 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003706{
Takashi Iwai98274f02005-11-17 14:52:34 +01003707 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003708 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003709
3710 channel = ucontrol->id.index - 1;
3711
Takashi Iwaida3cec32008-08-08 17:12:14 +02003712 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3713 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003714
Takashi Iwai763f3562005-06-03 11:25:34 +02003715 spin_lock_irq(&hdspm->lock);
3716 ucontrol->value.integer.value[0] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003717 (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN;
Takashi Iwai763f3562005-06-03 11:25:34 +02003718 spin_unlock_irq(&hdspm->lock);
3719
Takashi Iwai763f3562005-06-03 11:25:34 +02003720 return 0;
3721}
3722
Takashi Iwai98274f02005-11-17 14:52:34 +01003723static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
3724 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003725{
Takashi Iwai98274f02005-11-17 14:52:34 +01003726 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003727 int change;
3728 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003729 int gain;
3730
3731 if (!snd_hdspm_use_is_exclusive(hdspm))
3732 return -EBUSY;
3733
3734 channel = ucontrol->id.index - 1;
3735
Takashi Iwaida3cec32008-08-08 17:12:14 +02003736 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3737 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003738
Adrian Knoth0dca1792011-01-26 19:32:14 +01003739 gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003740
3741 spin_lock_irq(&hdspm->lock);
3742 change =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003743 gain != hdspm_read_pb_gain(hdspm, channel,
3744 channel);
Takashi Iwai763f3562005-06-03 11:25:34 +02003745 if (change)
Adrian Knoth0dca1792011-01-26 19:32:14 +01003746 hdspm_write_pb_gain(hdspm, channel, channel,
Takashi Iwai763f3562005-06-03 11:25:34 +02003747 gain);
3748 spin_unlock_irq(&hdspm->lock);
3749 return change;
3750}
3751
Adrian Knoth0dca1792011-01-26 19:32:14 +01003752#define HDSPM_SYNC_CHECK(xname, xindex) \
3753{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3754 .name = xname, \
3755 .private_value = xindex, \
3756 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3757 .info = snd_hdspm_info_sync_check, \
3758 .get = snd_hdspm_get_sync_check \
Takashi Iwai763f3562005-06-03 11:25:34 +02003759}
3760
Adrian Knoth34542212013-03-10 00:37:25 +01003761#define HDSPM_TCO_LOCK_CHECK(xname, xindex) \
3762{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3763 .name = xname, \
3764 .private_value = xindex, \
3765 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3766 .info = snd_hdspm_tco_info_lock_check, \
3767 .get = snd_hdspm_get_sync_check \
3768}
3769
3770
Adrian Knoth0dca1792011-01-26 19:32:14 +01003771
Takashi Iwai98274f02005-11-17 14:52:34 +01003772static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
3773 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003774{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003775 static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003776 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02003777 return 0;
3778}
3779
Adrian Knoth34542212013-03-10 00:37:25 +01003780static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol,
3781 struct snd_ctl_elem_info *uinfo)
3782{
3783 static char *texts[] = { "No Lock", "Lock" };
3784 ENUMERATED_CTL_INFO(uinfo, texts);
3785 return 0;
3786}
3787
Adrian Knoth0dca1792011-01-26 19:32:14 +01003788static int hdspm_wc_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003789{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003790 int status, status2;
3791
3792 switch (hdspm->io_type) {
3793 case AES32:
3794 status = hdspm_read(hdspm, HDSPM_statusRegister);
Andre Schramm56bde0f2013-01-09 14:40:18 +01003795 if (status & HDSPM_AES32_wcLock) {
3796 if (status & HDSPM_AES32_wcSync)
3797 return 2;
3798 else
3799 return 1;
3800 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02003801 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003802 break;
3803
3804 case MADI:
3805 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003806 if (status2 & HDSPM_wcLock) {
3807 if (status2 & HDSPM_wcSync)
3808 return 2;
3809 else
3810 return 1;
3811 }
3812 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003813 break;
3814
3815 case RayDAT:
3816 case AIO:
3817 status = hdspm_read(hdspm, HDSPM_statusRegister);
3818
3819 if (status & 0x2000000)
3820 return 2;
3821 else if (status & 0x1000000)
3822 return 1;
3823 return 0;
3824
3825 break;
3826
3827 case MADIface:
3828 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02003829 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003830
Takashi Iwai763f3562005-06-03 11:25:34 +02003831
Adrian Knoth0dca1792011-01-26 19:32:14 +01003832 return 3;
Takashi Iwai763f3562005-06-03 11:25:34 +02003833}
3834
3835
Adrian Knoth0dca1792011-01-26 19:32:14 +01003836static int hdspm_madi_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003837{
3838 int status = hdspm_read(hdspm, HDSPM_statusRegister);
3839 if (status & HDSPM_madiLock) {
3840 if (status & HDSPM_madiSync)
3841 return 2;
3842 else
3843 return 1;
3844 }
3845 return 0;
3846}
3847
Adrian Knoth0dca1792011-01-26 19:32:14 +01003848
3849static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx)
3850{
3851 int status, lock, sync;
3852
3853 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3854
3855 lock = (status & (0x1<<idx)) ? 1 : 0;
3856 sync = (status & (0x100<<idx)) ? 1 : 0;
3857
3858 if (lock && sync)
3859 return 2;
3860 else if (lock)
3861 return 1;
3862 return 0;
3863}
3864
3865
3866static int hdspm_sync_in_sync_check(struct hdspm *hdspm)
3867{
3868 int status, lock = 0, sync = 0;
3869
3870 switch (hdspm->io_type) {
3871 case RayDAT:
3872 case AIO:
3873 status = hdspm_read(hdspm, HDSPM_RD_STATUS_3);
3874 lock = (status & 0x400) ? 1 : 0;
3875 sync = (status & 0x800) ? 1 : 0;
3876 break;
3877
3878 case MADI:
Adrian Knoth2e0452f2012-10-19 17:42:27 +02003879 status = hdspm_read(hdspm, HDSPM_statusRegister);
3880 lock = (status & HDSPM_syncInLock) ? 1 : 0;
3881 sync = (status & HDSPM_syncInSync) ? 1 : 0;
3882 break;
3883
Adrian Knoth0dca1792011-01-26 19:32:14 +01003884 case AES32:
3885 status = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth9a215f42012-10-19 17:42:28 +02003886 lock = (status & 0x100000) ? 1 : 0;
3887 sync = (status & 0x200000) ? 1 : 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003888 break;
3889
3890 case MADIface:
3891 break;
3892 }
3893
3894 if (lock && sync)
3895 return 2;
3896 else if (lock)
3897 return 1;
3898
3899 return 0;
3900}
3901
3902static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
3903{
3904 int status2, lock, sync;
3905 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3906
3907 lock = (status2 & (0x0080 >> idx)) ? 1 : 0;
3908 sync = (status2 & (0x8000 >> idx)) ? 1 : 0;
3909
3910 if (sync)
3911 return 2;
3912 else if (lock)
3913 return 1;
3914 return 0;
3915}
3916
Adrian Knoth34542212013-03-10 00:37:25 +01003917static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask)
3918{
3919 u32 status;
3920 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3921
3922 return (status & mask) ? 1 : 0;
3923}
3924
Adrian Knoth0dca1792011-01-26 19:32:14 +01003925
3926static int hdspm_tco_sync_check(struct hdspm *hdspm)
3927{
3928 int status;
3929
3930 if (hdspm->tco) {
3931 switch (hdspm->io_type) {
3932 case MADI:
Adrian Knothb0bf5502013-07-05 11:28:05 +02003933 status = hdspm_read(hdspm, HDSPM_statusRegister);
3934 if (status & HDSPM_tcoLockMadi) {
3935 if (status & HDSPM_tcoSync)
3936 return 2;
3937 else
3938 return 1;
3939 }
3940 return 0;
3941 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003942 case AES32:
3943 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knothb0bf5502013-07-05 11:28:05 +02003944 if (status & HDSPM_tcoLockAes) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01003945 if (status & HDSPM_tcoSync)
3946 return 2;
3947 else
3948 return 1;
3949 }
3950 return 0;
3951
3952 break;
3953
3954 case RayDAT:
3955 case AIO:
3956 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3957
3958 if (status & 0x8000000)
3959 return 2; /* Sync */
3960 if (status & 0x4000000)
3961 return 1; /* Lock */
3962 return 0; /* No signal */
3963 break;
3964
3965 default:
3966 break;
3967 }
3968 }
3969
3970 return 3; /* N/A */
3971}
3972
3973
3974static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
3975 struct snd_ctl_elem_value *ucontrol)
3976{
3977 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3978 int val = -1;
3979
3980 switch (hdspm->io_type) {
3981 case RayDAT:
3982 switch (kcontrol->private_value) {
3983 case 0: /* WC */
3984 val = hdspm_wc_sync_check(hdspm); break;
3985 case 7: /* TCO */
3986 val = hdspm_tco_sync_check(hdspm); break;
3987 case 8: /* SYNC IN */
3988 val = hdspm_sync_in_sync_check(hdspm); break;
3989 default:
Adrian Knothd1a3c982012-11-07 18:00:09 +01003990 val = hdspm_s1_sync_check(hdspm,
3991 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01003992 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02003993 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003994
3995 case AIO:
3996 switch (kcontrol->private_value) {
3997 case 0: /* WC */
3998 val = hdspm_wc_sync_check(hdspm); break;
3999 case 4: /* TCO */
4000 val = hdspm_tco_sync_check(hdspm); break;
4001 case 5: /* SYNC IN */
4002 val = hdspm_sync_in_sync_check(hdspm); break;
4003 default:
Adrian Knoth1cb7dbf2013-07-05 11:28:03 +02004004 val = hdspm_s1_sync_check(hdspm,
4005 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004006 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004007 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004008
4009 case MADI:
4010 switch (kcontrol->private_value) {
4011 case 0: /* WC */
4012 val = hdspm_wc_sync_check(hdspm); break;
4013 case 1: /* MADI */
4014 val = hdspm_madi_sync_check(hdspm); break;
4015 case 2: /* TCO */
4016 val = hdspm_tco_sync_check(hdspm); break;
4017 case 3: /* SYNC_IN */
4018 val = hdspm_sync_in_sync_check(hdspm); break;
4019 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004020 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004021
4022 case MADIface:
4023 val = hdspm_madi_sync_check(hdspm); /* MADI */
4024 break;
4025
4026 case AES32:
4027 switch (kcontrol->private_value) {
4028 case 0: /* WC */
4029 val = hdspm_wc_sync_check(hdspm); break;
4030 case 9: /* TCO */
4031 val = hdspm_tco_sync_check(hdspm); break;
4032 case 10 /* SYNC IN */:
4033 val = hdspm_sync_in_sync_check(hdspm); break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01004034 default: /* AES1 to AES8 */
Adrian Knoth0dca1792011-01-26 19:32:14 +01004035 val = hdspm_aes_sync_check(hdspm,
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01004036 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004037 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004038 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004039
4040 }
4041
Adrian Knoth34542212013-03-10 00:37:25 +01004042 if (hdspm->tco) {
4043 switch (kcontrol->private_value) {
4044 case 11:
4045 /* Check TCO for lock state of its current input */
4046 val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock);
4047 break;
4048 case 12:
4049 /* Check TCO for valid time code on LTC input. */
4050 val = hdspm_tco_input_check(hdspm,
4051 HDSPM_TCO1_LTC_Input_valid);
4052 break;
4053 default:
4054 break;
4055 }
4056 }
4057
Adrian Knoth0dca1792011-01-26 19:32:14 +01004058 if (-1 == val)
4059 val = 3;
4060
4061 ucontrol->value.enumerated.item[0] = val;
4062 return 0;
4063}
4064
4065
4066
4067/**
4068 * TCO controls
4069 **/
4070static void hdspm_tco_write(struct hdspm *hdspm)
4071{
4072 unsigned int tc[4] = { 0, 0, 0, 0};
4073
4074 switch (hdspm->tco->input) {
4075 case 0:
4076 tc[2] |= HDSPM_TCO2_set_input_MSB;
4077 break;
4078 case 1:
4079 tc[2] |= HDSPM_TCO2_set_input_LSB;
4080 break;
4081 default:
4082 break;
4083 }
4084
4085 switch (hdspm->tco->framerate) {
4086 case 1:
4087 tc[1] |= HDSPM_TCO1_LTC_Format_LSB;
4088 break;
4089 case 2:
4090 tc[1] |= HDSPM_TCO1_LTC_Format_MSB;
4091 break;
4092 case 3:
4093 tc[1] |= HDSPM_TCO1_LTC_Format_MSB +
4094 HDSPM_TCO1_set_drop_frame_flag;
4095 break;
4096 case 4:
4097 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4098 HDSPM_TCO1_LTC_Format_MSB;
4099 break;
4100 case 5:
4101 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4102 HDSPM_TCO1_LTC_Format_MSB +
4103 HDSPM_TCO1_set_drop_frame_flag;
4104 break;
4105 default:
4106 break;
4107 }
4108
4109 switch (hdspm->tco->wordclock) {
4110 case 1:
4111 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB;
4112 break;
4113 case 2:
4114 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB;
4115 break;
4116 default:
4117 break;
4118 }
4119
4120 switch (hdspm->tco->samplerate) {
4121 case 1:
4122 tc[2] |= HDSPM_TCO2_set_freq;
4123 break;
4124 case 2:
4125 tc[2] |= HDSPM_TCO2_set_freq_from_app;
4126 break;
4127 default:
4128 break;
4129 }
4130
4131 switch (hdspm->tco->pull) {
4132 case 1:
4133 tc[2] |= HDSPM_TCO2_set_pull_up;
4134 break;
4135 case 2:
4136 tc[2] |= HDSPM_TCO2_set_pull_down;
4137 break;
4138 case 3:
4139 tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4;
4140 break;
4141 case 4:
4142 tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4;
4143 break;
4144 default:
4145 break;
4146 }
4147
4148 if (1 == hdspm->tco->term) {
4149 tc[2] |= HDSPM_TCO2_set_term_75R;
4150 }
4151
4152 hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]);
4153 hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]);
4154 hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]);
4155 hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]);
4156}
4157
4158
4159#define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \
4160{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4161 .name = xname, \
4162 .index = xindex, \
4163 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4164 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4165 .info = snd_hdspm_info_tco_sample_rate, \
4166 .get = snd_hdspm_get_tco_sample_rate, \
4167 .put = snd_hdspm_put_tco_sample_rate \
4168}
4169
4170static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
4171 struct snd_ctl_elem_info *uinfo)
4172{
4173 static char *texts[] = { "44.1 kHz", "48 kHz" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004174 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004175 return 0;
4176}
4177
4178static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol,
4179 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02004180{
Takashi Iwai98274f02005-11-17 14:52:34 +01004181 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02004182
Adrian Knoth0dca1792011-01-26 19:32:14 +01004183 ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate;
4184
Takashi Iwai763f3562005-06-03 11:25:34 +02004185 return 0;
4186}
4187
Adrian Knoth0dca1792011-01-26 19:32:14 +01004188static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol,
4189 struct snd_ctl_elem_value *ucontrol)
Remy Bruno3cee5a62006-10-16 12:46:32 +02004190{
Adrian Knoth0dca1792011-01-26 19:32:14 +01004191 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4192
4193 if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) {
4194 hdspm->tco->samplerate = ucontrol->value.enumerated.item[0];
4195
4196 hdspm_tco_write(hdspm);
4197
4198 return 1;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004199 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01004200
Remy Bruno3cee5a62006-10-16 12:46:32 +02004201 return 0;
4202}
4203
Adrian Knoth0dca1792011-01-26 19:32:14 +01004204
4205#define HDSPM_TCO_PULL(xname, xindex) \
4206{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4207 .name = xname, \
4208 .index = xindex, \
4209 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4210 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4211 .info = snd_hdspm_info_tco_pull, \
4212 .get = snd_hdspm_get_tco_pull, \
4213 .put = snd_hdspm_put_tco_pull \
4214}
4215
4216static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
4217 struct snd_ctl_elem_info *uinfo)
4218{
4219 static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004220 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004221 return 0;
4222}
4223
4224static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol,
4225 struct snd_ctl_elem_value *ucontrol)
4226{
4227 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4228
4229 ucontrol->value.enumerated.item[0] = hdspm->tco->pull;
4230
4231 return 0;
4232}
4233
4234static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol,
4235 struct snd_ctl_elem_value *ucontrol)
4236{
4237 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4238
4239 if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) {
4240 hdspm->tco->pull = ucontrol->value.enumerated.item[0];
4241
4242 hdspm_tco_write(hdspm);
4243
4244 return 1;
4245 }
4246
4247 return 0;
4248}
4249
4250#define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \
4251{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4252 .name = xname, \
4253 .index = xindex, \
4254 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4255 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4256 .info = snd_hdspm_info_tco_wck_conversion, \
4257 .get = snd_hdspm_get_tco_wck_conversion, \
4258 .put = snd_hdspm_put_tco_wck_conversion \
4259}
4260
4261static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4262 struct snd_ctl_elem_info *uinfo)
4263{
4264 static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004265 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004266 return 0;
4267}
4268
4269static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4270 struct snd_ctl_elem_value *ucontrol)
4271{
4272 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4273
4274 ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock;
4275
4276 return 0;
4277}
4278
4279static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4280 struct snd_ctl_elem_value *ucontrol)
4281{
4282 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4283
4284 if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) {
4285 hdspm->tco->wordclock = ucontrol->value.enumerated.item[0];
4286
4287 hdspm_tco_write(hdspm);
4288
4289 return 1;
4290 }
4291
4292 return 0;
4293}
4294
4295
4296#define HDSPM_TCO_FRAME_RATE(xname, xindex) \
4297{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4298 .name = xname, \
4299 .index = xindex, \
4300 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4301 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4302 .info = snd_hdspm_info_tco_frame_rate, \
4303 .get = snd_hdspm_get_tco_frame_rate, \
4304 .put = snd_hdspm_put_tco_frame_rate \
4305}
4306
4307static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
4308 struct snd_ctl_elem_info *uinfo)
4309{
4310 static char *texts[] = { "24 fps", "25 fps", "29.97fps",
4311 "29.97 dfps", "30 fps", "30 dfps" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004312 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004313 return 0;
4314}
4315
4316static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol,
Remy Bruno3cee5a62006-10-16 12:46:32 +02004317 struct snd_ctl_elem_value *ucontrol)
4318{
Remy Bruno3cee5a62006-10-16 12:46:32 +02004319 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4320
Adrian Knoth0dca1792011-01-26 19:32:14 +01004321 ucontrol->value.enumerated.item[0] = hdspm->tco->framerate;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004322
Remy Bruno3cee5a62006-10-16 12:46:32 +02004323 return 0;
4324}
Takashi Iwai763f3562005-06-03 11:25:34 +02004325
Adrian Knoth0dca1792011-01-26 19:32:14 +01004326static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol,
4327 struct snd_ctl_elem_value *ucontrol)
4328{
4329 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4330
4331 if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) {
4332 hdspm->tco->framerate = ucontrol->value.enumerated.item[0];
4333
4334 hdspm_tco_write(hdspm);
4335
4336 return 1;
4337 }
4338
4339 return 0;
4340}
4341
4342
4343#define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \
4344{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4345 .name = xname, \
4346 .index = xindex, \
4347 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4348 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4349 .info = snd_hdspm_info_tco_sync_source, \
4350 .get = snd_hdspm_get_tco_sync_source, \
4351 .put = snd_hdspm_put_tco_sync_source \
4352}
4353
4354static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
4355 struct snd_ctl_elem_info *uinfo)
4356{
4357 static char *texts[] = { "LTC", "Video", "WCK" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004358 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004359 return 0;
4360}
4361
4362static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol,
4363 struct snd_ctl_elem_value *ucontrol)
4364{
4365 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4366
4367 ucontrol->value.enumerated.item[0] = hdspm->tco->input;
4368
4369 return 0;
4370}
4371
4372static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol,
4373 struct snd_ctl_elem_value *ucontrol)
4374{
4375 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4376
4377 if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) {
4378 hdspm->tco->input = ucontrol->value.enumerated.item[0];
4379
4380 hdspm_tco_write(hdspm);
4381
4382 return 1;
4383 }
4384
4385 return 0;
4386}
4387
4388
4389#define HDSPM_TCO_WORD_TERM(xname, xindex) \
4390{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4391 .name = xname, \
4392 .index = xindex, \
4393 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4394 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4395 .info = snd_hdspm_info_tco_word_term, \
4396 .get = snd_hdspm_get_tco_word_term, \
4397 .put = snd_hdspm_put_tco_word_term \
4398}
4399
4400static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol,
4401 struct snd_ctl_elem_info *uinfo)
4402{
4403 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4404 uinfo->count = 1;
4405 uinfo->value.integer.min = 0;
4406 uinfo->value.integer.max = 1;
4407
4408 return 0;
4409}
4410
4411
4412static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol,
4413 struct snd_ctl_elem_value *ucontrol)
4414{
4415 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4416
4417 ucontrol->value.enumerated.item[0] = hdspm->tco->term;
4418
4419 return 0;
4420}
4421
4422
4423static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol,
4424 struct snd_ctl_elem_value *ucontrol)
4425{
4426 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4427
4428 if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) {
4429 hdspm->tco->term = ucontrol->value.enumerated.item[0];
4430
4431 hdspm_tco_write(hdspm);
4432
4433 return 1;
4434 }
4435
4436 return 0;
4437}
4438
4439
4440
Takashi Iwai763f3562005-06-03 11:25:34 +02004441
Remy Bruno3cee5a62006-10-16 12:46:32 +02004442static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
Takashi Iwai763f3562005-06-03 11:25:34 +02004443 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004444 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Takashi Iwai763f3562005-06-03 11:25:34 +02004445 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4446 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4447 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4448 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Adrian Knothb8812c52012-10-19 17:42:26 +02004449 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004450 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4451 HDSPM_SYNC_CHECK("MADI SyncCheck", 1),
Adrian Knoth930f4ff2012-10-19 17:42:29 +02004452 HDSPM_SYNC_CHECK("TCO SyncCheck", 2),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004453 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
Adrian Knothc9e16682012-12-03 14:55:50 +01004454 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4455 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
Adrian Knoth696be0f2013-03-10 00:37:23 +01004456 HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX),
Adrian Knothc9e16682012-12-03 14:55:50 +01004457 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4458 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
Adrian Knoth700d1ef2011-07-29 03:11:02 +02004459 HDSPM_INPUT_SELECT("Input Select", 0),
4460 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004461};
4462
4463
4464static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = {
4465 HDSPM_MIXER("Mixer", 0),
4466 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4467 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4468 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4469 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4470 HDSPM_SYNC_CHECK("MADI SyncCheck", 0),
Adrian Knothc9e16682012-12-03 14:55:50 +01004471 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
4472 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4473 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
Adrian Knoth700d1ef2011-07-29 03:11:02 +02004474 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004475};
4476
Adrian Knoth0dca1792011-01-26 19:32:14 +01004477static struct snd_kcontrol_new snd_hdspm_controls_aio[] = {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004478 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004479 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004480 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4481 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004482 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004483 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004484 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4485 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4486 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4487 HDSPM_SYNC_CHECK("ADAT SyncCheck", 3),
4488 HDSPM_SYNC_CHECK("TCO SyncCheck", 4),
4489 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5),
4490 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4491 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4492 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4493 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3),
4494 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4),
Adrian Knothfb0f1212013-07-05 11:27:58 +02004495 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5),
Adrian Knoth42f4c122013-07-05 11:28:01 +02004496 HDSPM_CONTROL_TRISTATE("S/PDIF Input", HDSPM_c0_Input0),
Adrian Knothfb0f1212013-07-05 11:27:58 +02004497 HDSPM_TOGGLE_SETTING("S/PDIF Out Optical", HDSPM_c0_Spdif_Opt),
4498 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4499 HDSPM_TOGGLE_SETTING("ADAT internal (AEB/TEB)", HDSPM_c0_AEB1),
4500 HDSPM_TOGGLE_SETTING("XLR Breakout Cable", HDSPM_c0_Sym6db),
Adrian Knoth42f4c122013-07-05 11:28:01 +02004501 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48),
4502 HDSPM_CONTROL_TRISTATE("Input Level", HDSPM_c0_AD_GAIN0),
4503 HDSPM_CONTROL_TRISTATE("Output Level", HDSPM_c0_DA_GAIN0),
4504 HDSPM_CONTROL_TRISTATE("Phones Level", HDSPM_c0_PH_GAIN0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004505
4506 /*
4507 HDSPM_INPUT_SELECT("Input Select", 0),
4508 HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0),
4509 HDSPM_PROFESSIONAL("SPDIF Out Professional", 0);
4510 HDSPM_SPDIF_IN("SPDIF In", 0);
4511 HDSPM_BREAKOUT_CABLE("Breakout Cable", 0);
4512 HDSPM_INPUT_LEVEL("Input Level", 0);
4513 HDSPM_OUTPUT_LEVEL("Output Level", 0);
4514 HDSPM_PHONES("Phones", 0);
4515 */
4516};
4517
4518static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = {
4519 HDSPM_MIXER("Mixer", 0),
4520 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4521 HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0),
4522 HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0),
4523 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4524 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4525 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4526 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4527 HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3),
4528 HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4),
4529 HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5),
4530 HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6),
4531 HDSPM_SYNC_CHECK("TCO SyncCheck", 7),
4532 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8),
4533 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4534 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4535 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4536 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3),
4537 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4),
4538 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5),
4539 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6),
4540 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7),
Adrian Knoth11a5cd32013-07-05 11:27:57 +02004541 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8),
4542 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4543 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004544};
4545
4546static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = {
4547 HDSPM_MIXER("Mixer", 0),
4548 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4549 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4550 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4551 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4552 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4553 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4554 HDSPM_SYNC_CHECK("WC Sync Check", 0),
4555 HDSPM_SYNC_CHECK("AES1 Sync Check", 1),
4556 HDSPM_SYNC_CHECK("AES2 Sync Check", 2),
4557 HDSPM_SYNC_CHECK("AES3 Sync Check", 3),
4558 HDSPM_SYNC_CHECK("AES4 Sync Check", 4),
4559 HDSPM_SYNC_CHECK("AES5 Sync Check", 5),
4560 HDSPM_SYNC_CHECK("AES6 Sync Check", 6),
4561 HDSPM_SYNC_CHECK("AES7 Sync Check", 7),
4562 HDSPM_SYNC_CHECK("AES8 Sync Check", 8),
4563 HDSPM_SYNC_CHECK("TCO Sync Check", 9),
4564 HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10),
4565 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4566 HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1),
4567 HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2),
4568 HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3),
4569 HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4),
4570 HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5),
4571 HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6),
4572 HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7),
4573 HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8),
4574 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9),
4575 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10),
Adrian Knothc9e16682012-12-03 14:55:50 +01004576 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4577 HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis),
4578 HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby),
4579 HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional),
4580 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004581 HDSPM_DS_WIRE("Double Speed Wire Mode", 0),
4582 HDSPM_QS_WIRE("Quad Speed Wire Mode", 0),
4583};
4584
Adrian Knoth0dca1792011-01-26 19:32:14 +01004585
4586
4587/* Control elements for the optional TCO module */
4588static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
4589 HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0),
4590 HDSPM_TCO_PULL("TCO Pull", 0),
4591 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
4592 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
4593 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
Adrian Knotha8176502013-03-10 00:37:27 +01004594 HDSPM_TCO_WORD_TERM("TCO Word Term", 0),
4595 HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11),
4596 HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12),
4597 HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0),
4598 HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004599};
4600
4601
Takashi Iwai98274f02005-11-17 14:52:34 +01004602static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
Takashi Iwai763f3562005-06-03 11:25:34 +02004603
4604
Takashi Iwai98274f02005-11-17 14:52:34 +01004605static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004606{
4607 int i;
4608
Adrian Knoth0dca1792011-01-26 19:32:14 +01004609 for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) {
Takashi Iwai763f3562005-06-03 11:25:34 +02004610 if (hdspm->system_sample_rate > 48000) {
4611 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004612 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
4613 SNDRV_CTL_ELEM_ACCESS_READ |
4614 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004615 } else {
4616 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004617 SNDRV_CTL_ELEM_ACCESS_READWRITE |
4618 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004619 }
4620 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
Adrian Knoth0dca1792011-01-26 19:32:14 +01004621 SNDRV_CTL_EVENT_MASK_INFO,
4622 &hdspm->playback_mixer_ctls[i]->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02004623 }
4624
4625 return 0;
4626}
4627
4628
Adrian Knoth0dca1792011-01-26 19:32:14 +01004629static int snd_hdspm_create_controls(struct snd_card *card,
4630 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004631{
4632 unsigned int idx, limit;
4633 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01004634 struct snd_kcontrol *kctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004635 struct snd_kcontrol_new *list = NULL;
Takashi Iwai763f3562005-06-03 11:25:34 +02004636
Adrian Knoth0dca1792011-01-26 19:32:14 +01004637 switch (hdspm->io_type) {
4638 case MADI:
4639 list = snd_hdspm_controls_madi;
4640 limit = ARRAY_SIZE(snd_hdspm_controls_madi);
4641 break;
4642 case MADIface:
4643 list = snd_hdspm_controls_madiface;
4644 limit = ARRAY_SIZE(snd_hdspm_controls_madiface);
4645 break;
4646 case AIO:
4647 list = snd_hdspm_controls_aio;
4648 limit = ARRAY_SIZE(snd_hdspm_controls_aio);
4649 break;
4650 case RayDAT:
4651 list = snd_hdspm_controls_raydat;
4652 limit = ARRAY_SIZE(snd_hdspm_controls_raydat);
4653 break;
4654 case AES32:
4655 list = snd_hdspm_controls_aes32;
4656 limit = ARRAY_SIZE(snd_hdspm_controls_aes32);
4657 break;
4658 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004659
Adrian Knoth0dca1792011-01-26 19:32:14 +01004660 if (NULL != list) {
4661 for (idx = 0; idx < limit; idx++) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004662 err = snd_ctl_add(card,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004663 snd_ctl_new1(&list[idx], hdspm));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004664 if (err < 0)
4665 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004666 }
4667 }
4668
Takashi Iwai763f3562005-06-03 11:25:34 +02004669
Adrian Knoth0dca1792011-01-26 19:32:14 +01004670 /* create simple 1:1 playback mixer controls */
Takashi Iwai763f3562005-06-03 11:25:34 +02004671 snd_hdspm_playback_mixer.name = "Chn";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004672 if (hdspm->system_sample_rate >= 128000) {
4673 limit = hdspm->qs_out_channels;
4674 } else if (hdspm->system_sample_rate >= 64000) {
4675 limit = hdspm->ds_out_channels;
4676 } else {
4677 limit = hdspm->ss_out_channels;
4678 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004679 for (idx = 0; idx < limit; ++idx) {
4680 snd_hdspm_playback_mixer.index = idx + 1;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004681 kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm);
4682 err = snd_ctl_add(card, kctl);
4683 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004684 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004685 hdspm->playback_mixer_ctls[idx] = kctl;
4686 }
4687
Adrian Knoth0dca1792011-01-26 19:32:14 +01004688
4689 if (hdspm->tco) {
4690 /* add tco control elements */
4691 list = snd_hdspm_controls_tco;
4692 limit = ARRAY_SIZE(snd_hdspm_controls_tco);
4693 for (idx = 0; idx < limit; idx++) {
4694 err = snd_ctl_add(card,
4695 snd_ctl_new1(&list[idx], hdspm));
4696 if (err < 0)
4697 return err;
4698 }
4699 }
4700
Takashi Iwai763f3562005-06-03 11:25:34 +02004701 return 0;
4702}
4703
4704/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01004705 /proc interface
Takashi Iwai763f3562005-06-03 11:25:34 +02004706 ------------------------------------------------------------*/
4707
4708static void
Adrian Knoth57601072013-07-05 11:28:04 +02004709snd_hdspm_proc_read_tco(struct snd_info_entry *entry,
4710 struct snd_info_buffer *buffer)
Takashi Iwai763f3562005-06-03 11:25:34 +02004711{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004712 struct hdspm *hdspm = entry->private_data;
Adrian Knoth57601072013-07-05 11:28:04 +02004713 unsigned int status, control;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004714 int a, ltc, frames, seconds, minutes, hours;
4715 unsigned int period;
4716 u64 freq_const = 0;
4717 u32 rate;
4718
Adrian Knoth57601072013-07-05 11:28:04 +02004719 snd_iprintf(buffer, "--- TCO ---\n");
4720
Takashi Iwai763f3562005-06-03 11:25:34 +02004721 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004722 control = hdspm->control_register;
Takashi Iwai763f3562005-06-03 11:25:34 +02004723
Adrian Knoth0dca1792011-01-26 19:32:14 +01004724
Adrian Knoth0dca1792011-01-26 19:32:14 +01004725 if (status & HDSPM_tco_detect) {
4726 snd_iprintf(buffer, "TCO module detected.\n");
4727 a = hdspm_read(hdspm, HDSPM_RD_TCO+4);
4728 if (a & HDSPM_TCO1_LTC_Input_valid) {
4729 snd_iprintf(buffer, " LTC valid, ");
4730 switch (a & (HDSPM_TCO1_LTC_Format_LSB |
4731 HDSPM_TCO1_LTC_Format_MSB)) {
4732 case 0:
4733 snd_iprintf(buffer, "24 fps, ");
4734 break;
4735 case HDSPM_TCO1_LTC_Format_LSB:
4736 snd_iprintf(buffer, "25 fps, ");
4737 break;
4738 case HDSPM_TCO1_LTC_Format_MSB:
4739 snd_iprintf(buffer, "29.97 fps, ");
4740 break;
4741 default:
4742 snd_iprintf(buffer, "30 fps, ");
4743 break;
4744 }
4745 if (a & HDSPM_TCO1_set_drop_frame_flag) {
4746 snd_iprintf(buffer, "drop frame\n");
4747 } else {
4748 snd_iprintf(buffer, "full frame\n");
4749 }
4750 } else {
4751 snd_iprintf(buffer, " no LTC\n");
4752 }
4753 if (a & HDSPM_TCO1_Video_Input_Format_NTSC) {
4754 snd_iprintf(buffer, " Video: NTSC\n");
4755 } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) {
4756 snd_iprintf(buffer, " Video: PAL\n");
4757 } else {
4758 snd_iprintf(buffer, " No video\n");
4759 }
4760 if (a & HDSPM_TCO1_TCO_lock) {
4761 snd_iprintf(buffer, " Sync: lock\n");
4762 } else {
4763 snd_iprintf(buffer, " Sync: no lock\n");
4764 }
4765
4766 switch (hdspm->io_type) {
4767 case MADI:
4768 case AES32:
4769 freq_const = 110069313433624ULL;
4770 break;
4771 case RayDAT:
4772 case AIO:
4773 freq_const = 104857600000000ULL;
4774 break;
4775 case MADIface:
4776 break; /* no TCO possible */
4777 }
4778
4779 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
4780 snd_iprintf(buffer, " period: %u\n", period);
4781
4782
4783 /* rate = freq_const/period; */
4784 rate = div_u64(freq_const, period);
4785
4786 if (control & HDSPM_QuadSpeed) {
4787 rate *= 4;
4788 } else if (control & HDSPM_DoubleSpeed) {
4789 rate *= 2;
4790 }
4791
4792 snd_iprintf(buffer, " Frequency: %u Hz\n",
4793 (unsigned int) rate);
4794
4795 ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
4796 frames = ltc & 0xF;
4797 ltc >>= 4;
4798 frames += (ltc & 0x3) * 10;
4799 ltc >>= 4;
4800 seconds = ltc & 0xF;
4801 ltc >>= 4;
4802 seconds += (ltc & 0x7) * 10;
4803 ltc >>= 4;
4804 minutes = ltc & 0xF;
4805 ltc >>= 4;
4806 minutes += (ltc & 0x7) * 10;
4807 ltc >>= 4;
4808 hours = ltc & 0xF;
4809 ltc >>= 4;
4810 hours += (ltc & 0x3) * 10;
4811 snd_iprintf(buffer,
4812 " LTC In: %02d:%02d:%02d:%02d\n",
4813 hours, minutes, seconds, frames);
4814
4815 } else {
4816 snd_iprintf(buffer, "No TCO module detected.\n");
4817 }
Adrian Knoth57601072013-07-05 11:28:04 +02004818}
4819
4820static void
4821snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
4822 struct snd_info_buffer *buffer)
4823{
4824 struct hdspm *hdspm = entry->private_data;
4825 unsigned int status, status2, control, freq;
4826
4827 char *pref_sync_ref;
4828 char *autosync_ref;
4829 char *system_clock_mode;
4830 char *insel;
4831 int x, x2;
4832
4833 status = hdspm_read(hdspm, HDSPM_statusRegister);
4834 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
4835 control = hdspm->control_register;
4836 freq = hdspm_read(hdspm, HDSPM_timecodeRegister);
4837
4838 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
4839 hdspm->card_name, hdspm->card->number + 1,
4840 hdspm->firmware_rev,
4841 (status2 & HDSPM_version0) |
4842 (status2 & HDSPM_version1) | (status2 &
4843 HDSPM_version2));
4844
4845 snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n",
4846 (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF,
4847 hdspm->serial);
4848
4849 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
4850 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
4851
4852 snd_iprintf(buffer, "--- System ---\n");
4853
4854 snd_iprintf(buffer,
4855 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
4856 status & HDSPM_audioIRQPending,
4857 (status & HDSPM_midi0IRQPending) ? 1 : 0,
4858 (status & HDSPM_midi1IRQPending) ? 1 : 0,
4859 hdspm->irq_count);
4860 snd_iprintf(buffer,
4861 "HW pointer: id = %d, rawptr = %d (%d->%d) "
4862 "estimated= %ld (bytes)\n",
4863 ((status & HDSPM_BufferID) ? 1 : 0),
4864 (status & HDSPM_BufferPositionMask),
4865 (status & HDSPM_BufferPositionMask) %
4866 (2 * (int)hdspm->period_bytes),
4867 ((status & HDSPM_BufferPositionMask) - 64) %
4868 (2 * (int)hdspm->period_bytes),
4869 (long) hdspm_hw_pointer(hdspm) * 4);
4870
4871 snd_iprintf(buffer,
4872 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
4873 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
4874 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
4875 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
4876 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
4877 snd_iprintf(buffer,
4878 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
4879 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
4880 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
4881 snd_iprintf(buffer,
4882 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
4883 "status2=0x%x\n",
4884 hdspm->control_register, hdspm->control2_register,
4885 status, status2);
4886
Takashi Iwai763f3562005-06-03 11:25:34 +02004887
4888 snd_iprintf(buffer, "--- Settings ---\n");
4889
Adrian Knoth7cb155f2011-08-15 00:22:53 +02004890 x = hdspm_get_latency(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02004891
4892 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004893 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
4894 x, (unsigned long) hdspm->period_bytes);
Takashi Iwai763f3562005-06-03 11:25:34 +02004895
Adrian Knoth0dca1792011-01-26 19:32:14 +01004896 snd_iprintf(buffer, "Line out: %s\n",
4897 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004898
4899 switch (hdspm->control_register & HDSPM_InputMask) {
4900 case HDSPM_InputOptical:
4901 insel = "Optical";
4902 break;
4903 case HDSPM_InputCoaxial:
4904 insel = "Coaxial";
4905 break;
4906 default:
Masanari Iidaec8f53f2012-11-02 00:28:50 +09004907 insel = "Unknown";
Takashi Iwai763f3562005-06-03 11:25:34 +02004908 }
4909
Takashi Iwai763f3562005-06-03 11:25:34 +02004910 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004911 "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
4912 "Auto Input %s\n",
4913 (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off",
4914 (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56",
4915 (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004916
Adrian Knoth0dca1792011-01-26 19:32:14 +01004917
Remy Bruno3cee5a62006-10-16 12:46:32 +02004918 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
Adrian Knoth0dca1792011-01-26 19:32:14 +01004919 system_clock_mode = "AutoSync";
Remy Bruno3cee5a62006-10-16 12:46:32 +02004920 else
Takashi Iwai763f3562005-06-03 11:25:34 +02004921 system_clock_mode = "Master";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004922 snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode);
Takashi Iwai763f3562005-06-03 11:25:34 +02004923
4924 switch (hdspm_pref_sync_ref(hdspm)) {
4925 case HDSPM_SYNC_FROM_WORD:
4926 pref_sync_ref = "Word Clock";
4927 break;
4928 case HDSPM_SYNC_FROM_MADI:
4929 pref_sync_ref = "MADI Sync";
4930 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004931 case HDSPM_SYNC_FROM_TCO:
4932 pref_sync_ref = "TCO";
4933 break;
4934 case HDSPM_SYNC_FROM_SYNC_IN:
4935 pref_sync_ref = "Sync In";
4936 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02004937 default:
4938 pref_sync_ref = "XXXX Clock";
4939 break;
4940 }
4941 snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004942 pref_sync_ref);
Takashi Iwai763f3562005-06-03 11:25:34 +02004943
4944 snd_iprintf(buffer, "System Clock Frequency: %d\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004945 hdspm->system_sample_rate);
Takashi Iwai763f3562005-06-03 11:25:34 +02004946
4947
4948 snd_iprintf(buffer, "--- Status:\n");
4949
4950 x = status & HDSPM_madiSync;
4951 x2 = status2 & HDSPM_wcSync;
4952
4953 snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004954 (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
4955 "NoLock",
4956 (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
4957 "NoLock");
Takashi Iwai763f3562005-06-03 11:25:34 +02004958
4959 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01004960 case HDSPM_AUTOSYNC_FROM_SYNC_IN:
4961 autosync_ref = "Sync In";
4962 break;
4963 case HDSPM_AUTOSYNC_FROM_TCO:
4964 autosync_ref = "TCO";
4965 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02004966 case HDSPM_AUTOSYNC_FROM_WORD:
4967 autosync_ref = "Word Clock";
4968 break;
4969 case HDSPM_AUTOSYNC_FROM_MADI:
4970 autosync_ref = "MADI Sync";
4971 break;
4972 case HDSPM_AUTOSYNC_FROM_NONE:
4973 autosync_ref = "Input not valid";
4974 break;
4975 default:
4976 autosync_ref = "---";
4977 break;
4978 }
4979 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004980 "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
4981 autosync_ref, hdspm_external_sample_rate(hdspm),
4982 (status & HDSPM_madiFreqMask) >> 22,
4983 (status2 & HDSPM_wcFreqMask) >> 5);
Takashi Iwai763f3562005-06-03 11:25:34 +02004984
4985 snd_iprintf(buffer, "Input: %s, Mode=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004986 (status & HDSPM_AB_int) ? "Coax" : "Optical",
4987 (status & HDSPM_RX_64ch) ? "64 channels" :
4988 "56 channels");
Takashi Iwai763f3562005-06-03 11:25:34 +02004989
Adrian Knoth57601072013-07-05 11:28:04 +02004990 /* call readout function for TCO specific status */
4991 snd_hdspm_proc_read_tco(entry, buffer);
4992
Takashi Iwai763f3562005-06-03 11:25:34 +02004993 snd_iprintf(buffer, "\n");
4994}
4995
Remy Bruno3cee5a62006-10-16 12:46:32 +02004996static void
4997snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
4998 struct snd_info_buffer *buffer)
4999{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005000 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005001 unsigned int status;
5002 unsigned int status2;
5003 unsigned int timecode;
Andre Schramm56bde0f2013-01-09 14:40:18 +01005004 unsigned int wcLock, wcSync;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005005 int pref_syncref;
5006 char *autosync_ref;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005007 int x;
5008
5009 status = hdspm_read(hdspm, HDSPM_statusRegister);
5010 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
5011 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
5012
5013 snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n",
5014 hdspm->card_name, hdspm->card->number + 1,
5015 hdspm->firmware_rev);
5016
5017 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
5018 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
5019
5020 snd_iprintf(buffer, "--- System ---\n");
5021
5022 snd_iprintf(buffer,
5023 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
5024 status & HDSPM_audioIRQPending,
5025 (status & HDSPM_midi0IRQPending) ? 1 : 0,
5026 (status & HDSPM_midi1IRQPending) ? 1 : 0,
5027 hdspm->irq_count);
5028 snd_iprintf(buffer,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005029 "HW pointer: id = %d, rawptr = %d (%d->%d) "
5030 "estimated= %ld (bytes)\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005031 ((status & HDSPM_BufferID) ? 1 : 0),
5032 (status & HDSPM_BufferPositionMask),
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005033 (status & HDSPM_BufferPositionMask) %
5034 (2 * (int)hdspm->period_bytes),
5035 ((status & HDSPM_BufferPositionMask) - 64) %
5036 (2 * (int)hdspm->period_bytes),
Remy Bruno3cee5a62006-10-16 12:46:32 +02005037 (long) hdspm_hw_pointer(hdspm) * 4);
5038
5039 snd_iprintf(buffer,
5040 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
5041 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
5042 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
5043 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
5044 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
5045 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005046 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
5047 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
5048 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
5049 snd_iprintf(buffer,
5050 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
5051 "status2=0x%x\n",
5052 hdspm->control_register, hdspm->control2_register,
5053 status, status2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02005054
5055 snd_iprintf(buffer, "--- Settings ---\n");
5056
Adrian Knoth7cb155f2011-08-15 00:22:53 +02005057 x = hdspm_get_latency(hdspm);
Remy Bruno3cee5a62006-10-16 12:46:32 +02005058
5059 snd_iprintf(buffer,
5060 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
5061 x, (unsigned long) hdspm->period_bytes);
5062
Adrian Knoth0dca1792011-01-26 19:32:14 +01005063 snd_iprintf(buffer, "Line out: %s\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005064 (hdspm->
Adrian Knoth0dca1792011-01-26 19:32:14 +01005065 control_register & HDSPM_LineOut) ? "on " : "off");
Remy Bruno3cee5a62006-10-16 12:46:32 +02005066
5067 snd_iprintf(buffer,
5068 "ClearTrackMarker %s, Emphasis %s, Dolby %s\n",
5069 (hdspm->
5070 control_register & HDSPM_clr_tms) ? "on" : "off",
5071 (hdspm->
5072 control_register & HDSPM_Emphasis) ? "on" : "off",
5073 (hdspm->
5074 control_register & HDSPM_Dolby) ? "on" : "off");
5075
Remy Bruno3cee5a62006-10-16 12:46:32 +02005076
5077 pref_syncref = hdspm_pref_sync_ref(hdspm);
5078 if (pref_syncref == 0)
5079 snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n");
5080 else
5081 snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n",
5082 pref_syncref);
5083
5084 snd_iprintf(buffer, "System Clock Frequency: %d\n",
5085 hdspm->system_sample_rate);
5086
5087 snd_iprintf(buffer, "Double speed: %s\n",
5088 hdspm->control_register & HDSPM_DS_DoubleWire?
5089 "Double wire" : "Single wire");
5090 snd_iprintf(buffer, "Quad speed: %s\n",
5091 hdspm->control_register & HDSPM_QS_DoubleWire?
5092 "Double wire" :
5093 hdspm->control_register & HDSPM_QS_QuadWire?
5094 "Quad wire" : "Single wire");
5095
5096 snd_iprintf(buffer, "--- Status:\n");
5097
Andre Schramm56bde0f2013-01-09 14:40:18 +01005098 wcLock = status & HDSPM_AES32_wcLock;
5099 wcSync = wcLock && (status & HDSPM_AES32_wcSync);
5100
Remy Bruno3cee5a62006-10-16 12:46:32 +02005101 snd_iprintf(buffer, "Word: %s Frequency: %d\n",
Andre Schramm56bde0f2013-01-09 14:40:18 +01005102 (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005103 HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02005104
5105 for (x = 0; x < 8; x++) {
5106 snd_iprintf(buffer, "AES%d: %s Frequency: %d\n",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005107 x+1,
5108 (status2 & (HDSPM_LockAES >> x)) ?
Adrian Knoth0dca1792011-01-26 19:32:14 +01005109 "Sync " : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005110 HDSPM_bit2freq((timecode >> (4*x)) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02005111 }
5112
5113 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005114 case HDSPM_AES32_AUTOSYNC_FROM_NONE:
5115 autosync_ref = "None"; break;
5116 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
5117 autosync_ref = "Word Clock"; break;
5118 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
5119 autosync_ref = "AES1"; break;
5120 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
5121 autosync_ref = "AES2"; break;
5122 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
5123 autosync_ref = "AES3"; break;
5124 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
5125 autosync_ref = "AES4"; break;
5126 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
5127 autosync_ref = "AES5"; break;
5128 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
5129 autosync_ref = "AES6"; break;
5130 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
5131 autosync_ref = "AES7"; break;
5132 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
5133 autosync_ref = "AES8"; break;
Adrian Knoth194062d2013-07-05 11:28:16 +02005134 case HDSPM_AES32_AUTOSYNC_FROM_TCO:
5135 autosync_ref = "TCO"; break;
5136 case HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN:
5137 autosync_ref = "Sync In"; break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005138 default:
5139 autosync_ref = "---"; break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005140 }
5141 snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref);
5142
Adrian Knoth194062d2013-07-05 11:28:16 +02005143 /* call readout function for TCO specific status */
5144 snd_hdspm_proc_read_tco(entry, buffer);
5145
Remy Bruno3cee5a62006-10-16 12:46:32 +02005146 snd_iprintf(buffer, "\n");
5147}
5148
Adrian Knoth0dca1792011-01-26 19:32:14 +01005149static void
5150snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
5151 struct snd_info_buffer *buffer)
5152{
5153 struct hdspm *hdspm = entry->private_data;
5154 unsigned int status1, status2, status3, control, i;
5155 unsigned int lock, sync;
5156
5157 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
5158 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
5159 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
5160
5161 control = hdspm->control_register;
5162
5163 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
5164 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
5165 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
5166
5167
5168 snd_iprintf(buffer, "\n*** CLOCK MODE\n\n");
5169
5170 snd_iprintf(buffer, "Clock mode : %s\n",
5171 (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave");
5172 snd_iprintf(buffer, "System frequency: %d Hz\n",
5173 hdspm_get_system_sample_rate(hdspm));
5174
5175 snd_iprintf(buffer, "\n*** INPUT STATUS\n\n");
5176
5177 lock = 0x1;
5178 sync = 0x100;
5179
5180 for (i = 0; i < 8; i++) {
5181 snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n",
5182 i,
5183 (status1 & lock) ? 1 : 0,
5184 (status1 & sync) ? 1 : 0,
5185 texts_freq[(status2 >> (i * 4)) & 0xF]);
5186
5187 lock = lock<<1;
5188 sync = sync<<1;
5189 }
5190
5191 snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n",
5192 (status1 & 0x1000000) ? 1 : 0,
5193 (status1 & 0x2000000) ? 1 : 0,
5194 texts_freq[(status1 >> 16) & 0xF]);
5195
5196 snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n",
5197 (status1 & 0x4000000) ? 1 : 0,
5198 (status1 & 0x8000000) ? 1 : 0,
5199 texts_freq[(status1 >> 20) & 0xF]);
5200
5201 snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n",
5202 (status3 & 0x400) ? 1 : 0,
5203 (status3 & 0x800) ? 1 : 0,
5204 texts_freq[(status2 >> 12) & 0xF]);
5205
5206}
5207
Remy Bruno3cee5a62006-10-16 12:46:32 +02005208#ifdef CONFIG_SND_DEBUG
5209static void
Adrian Knoth0dca1792011-01-26 19:32:14 +01005210snd_hdspm_proc_read_debug(struct snd_info_entry *entry,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005211 struct snd_info_buffer *buffer)
5212{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005213 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005214
5215 int j,i;
5216
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005217 for (i = 0; i < 256 /* 1024*64 */; i += j) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02005218 snd_iprintf(buffer, "0x%08X: ", i);
5219 for (j = 0; j < 16; j += 4)
5220 snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
5221 snd_iprintf(buffer, "\n");
5222 }
5223}
5224#endif
5225
5226
Adrian Knoth0dca1792011-01-26 19:32:14 +01005227static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry,
5228 struct snd_info_buffer *buffer)
5229{
5230 struct hdspm *hdspm = entry->private_data;
5231 int i;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005232
Adrian Knoth0dca1792011-01-26 19:32:14 +01005233 snd_iprintf(buffer, "# generated by hdspm\n");
5234
5235 for (i = 0; i < hdspm->max_channels_in; i++) {
5236 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]);
5237 }
5238}
5239
5240static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry,
5241 struct snd_info_buffer *buffer)
5242{
5243 struct hdspm *hdspm = entry->private_data;
5244 int i;
5245
5246 snd_iprintf(buffer, "# generated by hdspm\n");
5247
5248 for (i = 0; i < hdspm->max_channels_out; i++) {
5249 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]);
5250 }
5251}
5252
5253
Bill Pembertone23e7a12012-12-06 12:35:10 -05005254static void snd_hdspm_proc_init(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005255{
Takashi Iwai98274f02005-11-17 14:52:34 +01005256 struct snd_info_entry *entry;
Takashi Iwai763f3562005-06-03 11:25:34 +02005257
Adrian Knoth0dca1792011-01-26 19:32:14 +01005258 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) {
5259 switch (hdspm->io_type) {
5260 case AES32:
5261 snd_info_set_text_ops(entry, hdspm,
5262 snd_hdspm_proc_read_aes32);
5263 break;
5264 case MADI:
5265 snd_info_set_text_ops(entry, hdspm,
5266 snd_hdspm_proc_read_madi);
5267 break;
5268 case MADIface:
5269 /* snd_info_set_text_ops(entry, hdspm,
5270 snd_hdspm_proc_read_madiface); */
5271 break;
5272 case RayDAT:
5273 snd_info_set_text_ops(entry, hdspm,
5274 snd_hdspm_proc_read_raydat);
5275 break;
5276 case AIO:
5277 break;
5278 }
5279 }
5280
5281 if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) {
5282 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in);
5283 }
5284
5285 if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) {
5286 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out);
5287 }
5288
Remy Bruno3cee5a62006-10-16 12:46:32 +02005289#ifdef CONFIG_SND_DEBUG
5290 /* debug file to read all hdspm registers */
5291 if (!snd_card_proc_new(hdspm->card, "debug", &entry))
5292 snd_info_set_text_ops(entry, hdspm,
5293 snd_hdspm_proc_read_debug);
5294#endif
Takashi Iwai763f3562005-06-03 11:25:34 +02005295}
5296
5297/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005298 hdspm intitialize
Takashi Iwai763f3562005-06-03 11:25:34 +02005299 ------------------------------------------------------------*/
5300
Takashi Iwai98274f02005-11-17 14:52:34 +01005301static int snd_hdspm_set_defaults(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005302{
Takashi Iwai763f3562005-06-03 11:25:34 +02005303 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
Joe Perches561de312007-12-18 13:13:47 +01005304 hold it (e.g. during module initialization).
Adrian Knoth0dca1792011-01-26 19:32:14 +01005305 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005306
5307 /* set defaults: */
5308
Adrian Knoth0dca1792011-01-26 19:32:14 +01005309 hdspm->settings_register = 0;
5310
5311 switch (hdspm->io_type) {
5312 case MADI:
5313 case MADIface:
5314 hdspm->control_register =
5315 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5316 break;
5317
5318 case RayDAT:
5319 case AIO:
5320 hdspm->settings_register = 0x1 + 0x1000;
5321 /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0,
5322 * line_out */
5323 hdspm->control_register =
5324 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5325 break;
5326
5327 case AES32:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005328 hdspm->control_register =
Adrian Knothe71b95a2013-07-05 11:28:06 +02005329 HDSPM_ClockModeMaster | /* Master Clock Mode on */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005330 hdspm_encode_latency(7) | /* latency max=8192samples */
Remy Bruno3cee5a62006-10-16 12:46:32 +02005331 HDSPM_SyncRef0 | /* AES1 is syncclock */
5332 HDSPM_LineOut | /* Analog output in */
5333 HDSPM_Professional; /* Professional mode */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005334 break;
5335 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005336
5337 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5338
Adrian Knoth0dca1792011-01-26 19:32:14 +01005339 if (AES32 == hdspm->io_type) {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005340 /* No control2 register for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005341#ifdef SNDRV_BIG_ENDIAN
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005342 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
Takashi Iwai763f3562005-06-03 11:25:34 +02005343#else
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005344 hdspm->control2_register = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02005345#endif
5346
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005347 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
5348 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005349 hdspm_compute_period_size(hdspm);
5350
5351 /* silence everything */
5352
5353 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
5354
Adrian Knothb2ed6322013-07-05 11:27:54 +02005355 if (hdspm_is_raydat_or_aio(hdspm))
Adrian Knoth0dca1792011-01-26 19:32:14 +01005356 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
Takashi Iwai763f3562005-06-03 11:25:34 +02005357
5358 /* set a default rate so that the channel map is set up. */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005359 hdspm_set_rate(hdspm, 48000, 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02005360
5361 return 0;
5362}
5363
5364
5365/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005366 interrupt
Takashi Iwai763f3562005-06-03 11:25:34 +02005367 ------------------------------------------------------------*/
5368
David Howells7d12e782006-10-05 14:55:46 +01005369static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
Takashi Iwai763f3562005-06-03 11:25:34 +02005370{
Takashi Iwai98274f02005-11-17 14:52:34 +01005371 struct hdspm *hdspm = (struct hdspm *) dev_id;
Takashi Iwai763f3562005-06-03 11:25:34 +02005372 unsigned int status;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005373 int i, audio, midi, schedule = 0;
5374 /* cycles_t now; */
Takashi Iwai763f3562005-06-03 11:25:34 +02005375
5376 status = hdspm_read(hdspm, HDSPM_statusRegister);
5377
5378 audio = status & HDSPM_audioIRQPending;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005379 midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending |
5380 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
Takashi Iwai763f3562005-06-03 11:25:34 +02005381
Adrian Knoth0dca1792011-01-26 19:32:14 +01005382 /* now = get_cycles(); */
5383 /**
5384 * LAT_2..LAT_0 period counter (win) counter (mac)
5385 * 6 4096 ~256053425 ~514672358
5386 * 5 2048 ~128024983 ~257373821
5387 * 4 1024 ~64023706 ~128718089
5388 * 3 512 ~32005945 ~64385999
5389 * 2 256 ~16003039 ~32260176
5390 * 1 128 ~7998738 ~16194507
5391 * 0 64 ~3998231 ~8191558
5392 **/
5393 /*
5394 snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n",
5395 now-hdspm->last_interrupt, status & 0xFFC0);
5396 hdspm->last_interrupt = now;
5397 */
5398
5399 if (!audio && !midi)
Takashi Iwai763f3562005-06-03 11:25:34 +02005400 return IRQ_NONE;
5401
5402 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
5403 hdspm->irq_count++;
5404
Takashi Iwai763f3562005-06-03 11:25:34 +02005405
5406 if (audio) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005407 if (hdspm->capture_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005408 snd_pcm_period_elapsed(hdspm->capture_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005409
5410 if (hdspm->playback_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005411 snd_pcm_period_elapsed(hdspm->playback_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005412 }
5413
Adrian Knoth0dca1792011-01-26 19:32:14 +01005414 if (midi) {
5415 i = 0;
5416 while (i < hdspm->midiPorts) {
5417 if ((hdspm_read(hdspm,
5418 hdspm->midi[i].statusIn) & 0xff) &&
5419 (status & hdspm->midi[i].irq)) {
5420 /* we disable interrupts for this input until
5421 * processing is done
5422 */
5423 hdspm->control_register &= ~hdspm->midi[i].ie;
5424 hdspm_write(hdspm, HDSPM_controlRegister,
5425 hdspm->control_register);
5426 hdspm->midi[i].pending = 1;
5427 schedule = 1;
5428 }
5429
5430 i++;
5431 }
5432
5433 if (schedule)
5434 tasklet_hi_schedule(&hdspm->midi_tasklet);
Takashi Iwai763f3562005-06-03 11:25:34 +02005435 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005436
Takashi Iwai763f3562005-06-03 11:25:34 +02005437 return IRQ_HANDLED;
5438}
5439
5440/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005441 pcm interface
Takashi Iwai763f3562005-06-03 11:25:34 +02005442 ------------------------------------------------------------*/
5443
5444
Adrian Knoth0dca1792011-01-26 19:32:14 +01005445static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream
5446 *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005447{
Takashi Iwai98274f02005-11-17 14:52:34 +01005448 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005449 return hdspm_hw_pointer(hdspm);
5450}
5451
Takashi Iwai763f3562005-06-03 11:25:34 +02005452
Takashi Iwai98274f02005-11-17 14:52:34 +01005453static int snd_hdspm_reset(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005454{
Takashi Iwai98274f02005-11-17 14:52:34 +01005455 struct snd_pcm_runtime *runtime = substream->runtime;
5456 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5457 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005458
5459 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5460 other = hdspm->capture_substream;
5461 else
5462 other = hdspm->playback_substream;
5463
5464 if (hdspm->running)
5465 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
5466 else
5467 runtime->status->hw_ptr = 0;
5468 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005469 struct snd_pcm_substream *s;
5470 struct snd_pcm_runtime *oruntime = other->runtime;
Takashi Iwaief991b92007-02-22 12:52:53 +01005471 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005472 if (s == other) {
5473 oruntime->status->hw_ptr =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005474 runtime->status->hw_ptr;
Takashi Iwai763f3562005-06-03 11:25:34 +02005475 break;
5476 }
5477 }
5478 }
5479 return 0;
5480}
5481
Takashi Iwai98274f02005-11-17 14:52:34 +01005482static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5483 struct snd_pcm_hw_params *params)
Takashi Iwai763f3562005-06-03 11:25:34 +02005484{
Takashi Iwai98274f02005-11-17 14:52:34 +01005485 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005486 int err;
5487 int i;
5488 pid_t this_pid;
5489 pid_t other_pid;
Takashi Iwai763f3562005-06-03 11:25:34 +02005490
5491 spin_lock_irq(&hdspm->lock);
5492
5493 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5494 this_pid = hdspm->playback_pid;
5495 other_pid = hdspm->capture_pid;
5496 } else {
5497 this_pid = hdspm->capture_pid;
5498 other_pid = hdspm->playback_pid;
5499 }
5500
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005501 if (other_pid > 0 && this_pid != other_pid) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005502
5503 /* The other stream is open, and not by the same
5504 task as this one. Make sure that the parameters
5505 that matter are the same.
Adrian Knoth0dca1792011-01-26 19:32:14 +01005506 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005507
5508 if (params_rate(params) != hdspm->system_sample_rate) {
5509 spin_unlock_irq(&hdspm->lock);
5510 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005511 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005512 return -EBUSY;
5513 }
5514
5515 if (params_period_size(params) != hdspm->period_bytes / 4) {
5516 spin_unlock_irq(&hdspm->lock);
5517 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005518 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005519 return -EBUSY;
5520 }
5521
5522 }
5523 /* We're fine. */
5524 spin_unlock_irq(&hdspm->lock);
5525
5526 /* how to make sure that the rate matches an externally-set one ? */
5527
5528 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005529 err = hdspm_set_rate(hdspm, params_rate(params), 0);
5530 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005531 snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005532 spin_unlock_irq(&hdspm->lock);
5533 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005534 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005535 return err;
5536 }
5537 spin_unlock_irq(&hdspm->lock);
5538
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005539 err = hdspm_set_interrupt_interval(hdspm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005540 params_period_size(params));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005541 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005542 snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005543 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005544 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005545 return err;
5546 }
5547
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005548 /* Memory allocation, takashi's method, dont know if we should
5549 * spinlock
5550 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005551 /* malloc all buffer even if not enabled to get sure */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005552 /* Update for MADI rev 204: we need to allocate for all channels,
5553 * otherwise it doesn't work at 96kHz */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005554
Takashi Iwai763f3562005-06-03 11:25:34 +02005555 err =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005556 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
5557 if (err < 0) {
5558 snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005559 return err;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005560 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005561
Takashi Iwai763f3562005-06-03 11:25:34 +02005562 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5563
Takashi Iwai77a23f22008-08-21 13:00:13 +02005564 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
Takashi Iwai763f3562005-06-03 11:25:34 +02005565 params_channels(params));
5566
5567 for (i = 0; i < params_channels(params); ++i)
5568 snd_hdspm_enable_out(hdspm, i, 1);
5569
5570 hdspm->playback_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005571 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005572 snd_printdd("Allocated sample buffer for playback at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005573 hdspm->playback_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005574 } else {
Takashi Iwai77a23f22008-08-21 13:00:13 +02005575 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
Takashi Iwai763f3562005-06-03 11:25:34 +02005576 params_channels(params));
5577
5578 for (i = 0; i < params_channels(params); ++i)
5579 snd_hdspm_enable_in(hdspm, i, 1);
5580
5581 hdspm->capture_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005582 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005583 snd_printdd("Allocated sample buffer for capture at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005584 hdspm->capture_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005585 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005586
Remy Bruno3cee5a62006-10-16 12:46:32 +02005587 /*
5588 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
5589 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5590 "playback" : "capture",
Takashi Iwai77a23f22008-08-21 13:00:13 +02005591 snd_pcm_sgbuf_get_addr(substream, 0));
Adrian Knoth0dca1792011-01-26 19:32:14 +01005592 */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005593 /*
Adrian Knoth0dca1792011-01-26 19:32:14 +01005594 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
5595 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5596 "playback" : "capture",
5597 params_rate(params), params_channels(params),
5598 params_buffer_size(params));
5599 */
5600
5601
Adrian Knoth3ac9b0a2013-07-05 11:28:13 +02005602 /* For AES cards, the float format bit is the same as the
5603 * preferred sync reference. Since we don't want to break
5604 * sync settings, we have to skip the remaining part of this
5605 * function.
5606 */
5607 if (hdspm->io_type == AES32) {
5608 return 0;
5609 }
5610
5611
Adrian Knoth0dca1792011-01-26 19:32:14 +01005612 /* Switch to native float format if requested */
5613 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
5614 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
5615 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n");
5616
5617 hdspm->control_register |= HDSPe_FLOAT_FORMAT;
5618 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
5619 if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
5620 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n");
5621
5622 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
5623 }
5624 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5625
Takashi Iwai763f3562005-06-03 11:25:34 +02005626 return 0;
5627}
5628
Takashi Iwai98274f02005-11-17 14:52:34 +01005629static int snd_hdspm_hw_free(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005630{
5631 int i;
Takashi Iwai98274f02005-11-17 14:52:34 +01005632 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005633
5634 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5635
Adrian Knoth0dca1792011-01-26 19:32:14 +01005636 /* params_channels(params) should be enough,
Takashi Iwai763f3562005-06-03 11:25:34 +02005637 but to get sure in case of error */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005638 for (i = 0; i < hdspm->max_channels_out; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005639 snd_hdspm_enable_out(hdspm, i, 0);
5640
5641 hdspm->playback_buffer = NULL;
5642 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005643 for (i = 0; i < hdspm->max_channels_in; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005644 snd_hdspm_enable_in(hdspm, i, 0);
5645
5646 hdspm->capture_buffer = NULL;
5647
5648 }
5649
5650 snd_pcm_lib_free_pages(substream);
5651
5652 return 0;
5653}
5654
Adrian Knoth0dca1792011-01-26 19:32:14 +01005655
Takashi Iwai98274f02005-11-17 14:52:34 +01005656static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005657 struct snd_pcm_channel_info *info)
Takashi Iwai763f3562005-06-03 11:25:34 +02005658{
Takashi Iwai98274f02005-11-17 14:52:34 +01005659 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005660
Adrian Knoth0dca1792011-01-26 19:32:14 +01005661 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5662 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
5663 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel);
5664 return -EINVAL;
5665 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005666
Adrian Knoth0dca1792011-01-26 19:32:14 +01005667 if (hdspm->channel_map_out[info->channel] < 0) {
5668 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel);
5669 return -EINVAL;
5670 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005671
Adrian Knoth0dca1792011-01-26 19:32:14 +01005672 info->offset = hdspm->channel_map_out[info->channel] *
5673 HDSPM_CHANNEL_BUFFER_BYTES;
5674 } else {
5675 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
5676 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel);
5677 return -EINVAL;
5678 }
5679
5680 if (hdspm->channel_map_in[info->channel] < 0) {
5681 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel);
5682 return -EINVAL;
5683 }
5684
5685 info->offset = hdspm->channel_map_in[info->channel] *
5686 HDSPM_CHANNEL_BUFFER_BYTES;
5687 }
5688
Takashi Iwai763f3562005-06-03 11:25:34 +02005689 info->first = 0;
5690 info->step = 32;
5691 return 0;
5692}
5693
Adrian Knoth0dca1792011-01-26 19:32:14 +01005694
Takashi Iwai98274f02005-11-17 14:52:34 +01005695static int snd_hdspm_ioctl(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005696 unsigned int cmd, void *arg)
Takashi Iwai763f3562005-06-03 11:25:34 +02005697{
5698 switch (cmd) {
5699 case SNDRV_PCM_IOCTL1_RESET:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005700 return snd_hdspm_reset(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005701
5702 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
Adrian Knoth0dca1792011-01-26 19:32:14 +01005703 {
5704 struct snd_pcm_channel_info *info = arg;
5705 return snd_hdspm_channel_info(substream, info);
5706 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005707 default:
5708 break;
5709 }
5710
5711 return snd_pcm_lib_ioctl(substream, cmd, arg);
5712}
5713
Takashi Iwai98274f02005-11-17 14:52:34 +01005714static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)
Takashi Iwai763f3562005-06-03 11:25:34 +02005715{
Takashi Iwai98274f02005-11-17 14:52:34 +01005716 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5717 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005718 int running;
5719
5720 spin_lock(&hdspm->lock);
5721 running = hdspm->running;
5722 switch (cmd) {
5723 case SNDRV_PCM_TRIGGER_START:
5724 running |= 1 << substream->stream;
5725 break;
5726 case SNDRV_PCM_TRIGGER_STOP:
5727 running &= ~(1 << substream->stream);
5728 break;
5729 default:
5730 snd_BUG();
5731 spin_unlock(&hdspm->lock);
5732 return -EINVAL;
5733 }
5734 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5735 other = hdspm->capture_substream;
5736 else
5737 other = hdspm->playback_substream;
5738
5739 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005740 struct snd_pcm_substream *s;
Takashi Iwaief991b92007-02-22 12:52:53 +01005741 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005742 if (s == other) {
5743 snd_pcm_trigger_done(s, substream);
5744 if (cmd == SNDRV_PCM_TRIGGER_START)
5745 running |= 1 << s->stream;
5746 else
5747 running &= ~(1 << s->stream);
5748 goto _ok;
5749 }
5750 }
5751 if (cmd == SNDRV_PCM_TRIGGER_START) {
5752 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
Adrian Knoth0dca1792011-01-26 19:32:14 +01005753 && substream->stream ==
5754 SNDRV_PCM_STREAM_CAPTURE)
Takashi Iwai763f3562005-06-03 11:25:34 +02005755 hdspm_silence_playback(hdspm);
5756 } else {
5757 if (running &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01005758 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Takashi Iwai763f3562005-06-03 11:25:34 +02005759 hdspm_silence_playback(hdspm);
5760 }
5761 } else {
5762 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
5763 hdspm_silence_playback(hdspm);
5764 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005765_ok:
Takashi Iwai763f3562005-06-03 11:25:34 +02005766 snd_pcm_trigger_done(substream, substream);
5767 if (!hdspm->running && running)
5768 hdspm_start_audio(hdspm);
5769 else if (hdspm->running && !running)
5770 hdspm_stop_audio(hdspm);
5771 hdspm->running = running;
5772 spin_unlock(&hdspm->lock);
5773
5774 return 0;
5775}
5776
Takashi Iwai98274f02005-11-17 14:52:34 +01005777static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005778{
5779 return 0;
5780}
5781
Takashi Iwai98274f02005-11-17 14:52:34 +01005782static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005783 .info = (SNDRV_PCM_INFO_MMAP |
5784 SNDRV_PCM_INFO_MMAP_VALID |
5785 SNDRV_PCM_INFO_NONINTERLEAVED |
5786 SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
5787 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5788 .rates = (SNDRV_PCM_RATE_32000 |
5789 SNDRV_PCM_RATE_44100 |
5790 SNDRV_PCM_RATE_48000 |
5791 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005792 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5793 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ),
Takashi Iwai763f3562005-06-03 11:25:34 +02005794 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005795 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005796 .channels_min = 1,
5797 .channels_max = HDSPM_MAX_CHANNELS,
5798 .buffer_bytes_max =
5799 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
Adrian Knoth1b6fa102011-08-15 00:22:51 +02005800 .period_bytes_min = (32 * 4),
Takashi Iwai52e6fb42011-08-15 10:40:59 +02005801 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005802 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005803 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005804 .fifo_size = 0
5805};
5806
Takashi Iwai98274f02005-11-17 14:52:34 +01005807static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005808 .info = (SNDRV_PCM_INFO_MMAP |
5809 SNDRV_PCM_INFO_MMAP_VALID |
5810 SNDRV_PCM_INFO_NONINTERLEAVED |
5811 SNDRV_PCM_INFO_SYNC_START),
5812 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5813 .rates = (SNDRV_PCM_RATE_32000 |
5814 SNDRV_PCM_RATE_44100 |
5815 SNDRV_PCM_RATE_48000 |
5816 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005817 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5818 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000),
Takashi Iwai763f3562005-06-03 11:25:34 +02005819 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005820 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005821 .channels_min = 1,
5822 .channels_max = HDSPM_MAX_CHANNELS,
5823 .buffer_bytes_max =
5824 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
Adrian Knoth1b6fa102011-08-15 00:22:51 +02005825 .period_bytes_min = (32 * 4),
Takashi Iwai52e6fb42011-08-15 10:40:59 +02005826 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005827 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005828 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005829 .fifo_size = 0
5830};
5831
Adrian Knoth0dca1792011-01-26 19:32:14 +01005832static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5833 struct snd_pcm_hw_rule *rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005834{
Takashi Iwai98274f02005-11-17 14:52:34 +01005835 struct hdspm *hdspm = rule->private;
5836 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005837 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005838 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005839 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5840
Adrian Knoth0dca1792011-01-26 19:32:14 +01005841 if (r->min > 96000 && r->max <= 192000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005842 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005843 .min = hdspm->qs_in_channels,
5844 .max = hdspm->qs_in_channels,
5845 .integer = 1,
5846 };
5847 return snd_interval_refine(c, &t);
5848 } else if (r->min > 48000 && r->max <= 96000) {
5849 struct snd_interval t = {
5850 .min = hdspm->ds_in_channels,
5851 .max = hdspm->ds_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005852 .integer = 1,
5853 };
5854 return snd_interval_refine(c, &t);
5855 } else if (r->max < 64000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005856 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005857 .min = hdspm->ss_in_channels,
5858 .max = hdspm->ss_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005859 .integer = 1,
5860 };
5861 return snd_interval_refine(c, &t);
5862 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005863
Takashi Iwai763f3562005-06-03 11:25:34 +02005864 return 0;
5865}
5866
Adrian Knoth0dca1792011-01-26 19:32:14 +01005867static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
Takashi Iwai98274f02005-11-17 14:52:34 +01005868 struct snd_pcm_hw_rule * rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005869{
Takashi Iwai98274f02005-11-17 14:52:34 +01005870 struct hdspm *hdspm = rule->private;
5871 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005872 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005873 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005874 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5875
Adrian Knoth0dca1792011-01-26 19:32:14 +01005876 if (r->min > 96000 && r->max <= 192000) {
5877 struct snd_interval t = {
5878 .min = hdspm->qs_out_channels,
5879 .max = hdspm->qs_out_channels,
5880 .integer = 1,
5881 };
5882 return snd_interval_refine(c, &t);
5883 } else if (r->min > 48000 && r->max <= 96000) {
5884 struct snd_interval t = {
5885 .min = hdspm->ds_out_channels,
5886 .max = hdspm->ds_out_channels,
5887 .integer = 1,
5888 };
5889 return snd_interval_refine(c, &t);
5890 } else if (r->max < 64000) {
5891 struct snd_interval t = {
5892 .min = hdspm->ss_out_channels,
5893 .max = hdspm->ss_out_channels,
5894 .integer = 1,
5895 };
5896 return snd_interval_refine(c, &t);
5897 } else {
5898 }
5899 return 0;
5900}
5901
5902static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
5903 struct snd_pcm_hw_rule * rule)
5904{
5905 struct hdspm *hdspm = rule->private;
5906 struct snd_interval *c =
5907 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5908 struct snd_interval *r =
5909 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5910
5911 if (c->min >= hdspm->ss_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005912 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005913 .min = 32000,
5914 .max = 48000,
5915 .integer = 1,
5916 };
5917 return snd_interval_refine(r, &t);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005918 } else if (c->max <= hdspm->qs_in_channels) {
5919 struct snd_interval t = {
5920 .min = 128000,
5921 .max = 192000,
5922 .integer = 1,
5923 };
5924 return snd_interval_refine(r, &t);
5925 } else if (c->max <= hdspm->ds_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005926 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005927 .min = 64000,
5928 .max = 96000,
5929 .integer = 1,
5930 };
Takashi Iwai763f3562005-06-03 11:25:34 +02005931 return snd_interval_refine(r, &t);
5932 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005933
5934 return 0;
5935}
5936static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
5937 struct snd_pcm_hw_rule *rule)
5938{
5939 struct hdspm *hdspm = rule->private;
5940 struct snd_interval *c =
5941 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5942 struct snd_interval *r =
5943 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5944
5945 if (c->min >= hdspm->ss_out_channels) {
5946 struct snd_interval t = {
5947 .min = 32000,
5948 .max = 48000,
5949 .integer = 1,
5950 };
5951 return snd_interval_refine(r, &t);
5952 } else if (c->max <= hdspm->qs_out_channels) {
5953 struct snd_interval t = {
5954 .min = 128000,
5955 .max = 192000,
5956 .integer = 1,
5957 };
5958 return snd_interval_refine(r, &t);
5959 } else if (c->max <= hdspm->ds_out_channels) {
5960 struct snd_interval t = {
5961 .min = 64000,
5962 .max = 96000,
5963 .integer = 1,
5964 };
5965 return snd_interval_refine(r, &t);
5966 }
5967
Takashi Iwai763f3562005-06-03 11:25:34 +02005968 return 0;
5969}
5970
Adrian Knoth0dca1792011-01-26 19:32:14 +01005971static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params,
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005972 struct snd_pcm_hw_rule *rule)
5973{
5974 unsigned int list[3];
5975 struct hdspm *hdspm = rule->private;
5976 struct snd_interval *c = hw_param_interval(params,
5977 SNDRV_PCM_HW_PARAM_CHANNELS);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005978
5979 list[0] = hdspm->qs_in_channels;
5980 list[1] = hdspm->ds_in_channels;
5981 list[2] = hdspm->ss_in_channels;
5982 return snd_interval_list(c, 3, list, 0);
5983}
5984
5985static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params,
5986 struct snd_pcm_hw_rule *rule)
5987{
5988 unsigned int list[3];
5989 struct hdspm *hdspm = rule->private;
5990 struct snd_interval *c = hw_param_interval(params,
5991 SNDRV_PCM_HW_PARAM_CHANNELS);
5992
5993 list[0] = hdspm->qs_out_channels;
5994 list[1] = hdspm->ds_out_channels;
5995 list[2] = hdspm->ss_out_channels;
5996 return snd_interval_list(c, 3, list, 0);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005997}
5998
5999
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006000static unsigned int hdspm_aes32_sample_rates[] = {
6001 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
6002};
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006003
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006004static struct snd_pcm_hw_constraint_list
6005hdspm_hw_constraints_aes32_sample_rates = {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006006 .count = ARRAY_SIZE(hdspm_aes32_sample_rates),
6007 .list = hdspm_aes32_sample_rates,
6008 .mask = 0
6009};
6010
Takashi Iwai98274f02005-11-17 14:52:34 +01006011static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006012{
Takashi Iwai98274f02005-11-17 14:52:34 +01006013 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6014 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02006015
Takashi Iwai763f3562005-06-03 11:25:34 +02006016 spin_lock_irq(&hdspm->lock);
6017
6018 snd_pcm_set_sync(substream);
6019
Adrian Knoth0dca1792011-01-26 19:32:14 +01006020
Takashi Iwai763f3562005-06-03 11:25:34 +02006021 runtime->hw = snd_hdspm_playback_subinfo;
6022
6023 if (hdspm->capture_substream == NULL)
6024 hdspm_stop_audio(hdspm);
6025
6026 hdspm->playback_pid = current->pid;
6027 hdspm->playback_substream = substream;
6028
6029 spin_unlock_irq(&hdspm->lock);
6030
6031 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
Takashi Iwaid8776812011-08-15 10:45:42 +02006032 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02006033
Adrian Knoth0dca1792011-01-26 19:32:14 +01006034 switch (hdspm->io_type) {
6035 case AIO:
6036 case RayDAT:
Takashi Iwaid8776812011-08-15 10:45:42 +02006037 snd_pcm_hw_constraint_minmax(runtime,
6038 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6039 32, 4096);
6040 /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
6041 snd_pcm_hw_constraint_minmax(runtime,
6042 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6043 16384, 16384);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006044 break;
6045
6046 default:
Takashi Iwaid8776812011-08-15 10:45:42 +02006047 snd_pcm_hw_constraint_minmax(runtime,
6048 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6049 64, 8192);
6050 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006051 }
6052
6053 if (AES32 == hdspm->io_type) {
Takashi Iwai3fa9e3d2011-08-15 10:42:23 +02006054 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006055 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6056 &hdspm_hw_constraints_aes32_sample_rates);
6057 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006058 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006059 snd_hdspm_hw_rule_rate_out_channels, hdspm,
6060 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006061 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006062
6063 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6064 snd_hdspm_hw_rule_out_channels, hdspm,
6065 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6066
6067 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6068 snd_hdspm_hw_rule_out_channels_rate, hdspm,
6069 SNDRV_PCM_HW_PARAM_RATE, -1);
6070
Takashi Iwai763f3562005-06-03 11:25:34 +02006071 return 0;
6072}
6073
Takashi Iwai98274f02005-11-17 14:52:34 +01006074static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006075{
Takashi Iwai98274f02005-11-17 14:52:34 +01006076 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02006077
6078 spin_lock_irq(&hdspm->lock);
6079
6080 hdspm->playback_pid = -1;
6081 hdspm->playback_substream = NULL;
6082
6083 spin_unlock_irq(&hdspm->lock);
6084
6085 return 0;
6086}
6087
6088
Takashi Iwai98274f02005-11-17 14:52:34 +01006089static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006090{
Takashi Iwai98274f02005-11-17 14:52:34 +01006091 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6092 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02006093
6094 spin_lock_irq(&hdspm->lock);
6095 snd_pcm_set_sync(substream);
6096 runtime->hw = snd_hdspm_capture_subinfo;
6097
6098 if (hdspm->playback_substream == NULL)
6099 hdspm_stop_audio(hdspm);
6100
6101 hdspm->capture_pid = current->pid;
6102 hdspm->capture_substream = substream;
6103
6104 spin_unlock_irq(&hdspm->lock);
6105
6106 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
Takashi Iwaid8776812011-08-15 10:45:42 +02006107 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6108
Adrian Knoth0dca1792011-01-26 19:32:14 +01006109 switch (hdspm->io_type) {
6110 case AIO:
6111 case RayDAT:
Takashi Iwaid8776812011-08-15 10:45:42 +02006112 snd_pcm_hw_constraint_minmax(runtime,
6113 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6114 32, 4096);
6115 snd_pcm_hw_constraint_minmax(runtime,
6116 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6117 16384, 16384);
6118 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006119
6120 default:
Takashi Iwaid8776812011-08-15 10:45:42 +02006121 snd_pcm_hw_constraint_minmax(runtime,
6122 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6123 64, 8192);
6124 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006125 }
6126
6127 if (AES32 == hdspm->io_type) {
Takashi Iwai3fa9e3d2011-08-15 10:42:23 +02006128 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006129 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6130 &hdspm_hw_constraints_aes32_sample_rates);
6131 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006132 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006133 snd_hdspm_hw_rule_rate_in_channels, hdspm,
6134 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006135 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006136
6137 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6138 snd_hdspm_hw_rule_in_channels, hdspm,
6139 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6140
6141 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6142 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6143 SNDRV_PCM_HW_PARAM_RATE, -1);
6144
Takashi Iwai763f3562005-06-03 11:25:34 +02006145 return 0;
6146}
6147
Takashi Iwai98274f02005-11-17 14:52:34 +01006148static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006149{
Takashi Iwai98274f02005-11-17 14:52:34 +01006150 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02006151
6152 spin_lock_irq(&hdspm->lock);
6153
6154 hdspm->capture_pid = -1;
6155 hdspm->capture_substream = NULL;
6156
6157 spin_unlock_irq(&hdspm->lock);
6158 return 0;
6159}
6160
Adrian Knoth0dca1792011-01-26 19:32:14 +01006161static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
Takashi Iwai763f3562005-06-03 11:25:34 +02006162{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006163 /* we have nothing to initialize but the call is required */
6164 return 0;
6165}
6166
6167static inline int copy_u32_le(void __user *dest, void __iomem *src)
6168{
6169 u32 val = readl(src);
6170 return copy_to_user(dest, &val, 4);
6171}
6172
6173static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006174 unsigned int cmd, unsigned long arg)
Adrian Knoth0dca1792011-01-26 19:32:14 +01006175{
6176 void __user *argp = (void __user *)arg;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006177 struct hdspm *hdspm = hw->private_data;
Takashi Iwai98274f02005-11-17 14:52:34 +01006178 struct hdspm_mixer_ioctl mixer;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006179 struct hdspm_config info;
6180 struct hdspm_status status;
Takashi Iwai98274f02005-11-17 14:52:34 +01006181 struct hdspm_version hdspm_version;
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006182 struct hdspm_peak_rms *levels;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006183 struct hdspm_ltc ltc;
6184 unsigned int statusregister;
6185 long unsigned int s;
6186 int i = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02006187
6188 switch (cmd) {
6189
Takashi Iwai763f3562005-06-03 11:25:34 +02006190 case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006191 levels = &hdspm->peak_rms;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006192 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006193 levels->input_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006194 readl(hdspm->iobase +
6195 HDSPM_MADI_INPUT_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006196 levels->playback_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006197 readl(hdspm->iobase +
6198 HDSPM_MADI_PLAYBACK_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006199 levels->output_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006200 readl(hdspm->iobase +
6201 HDSPM_MADI_OUTPUT_PEAK + i*4);
6202
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006203 levels->input_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006204 ((uint64_t) readl(hdspm->iobase +
6205 HDSPM_MADI_INPUT_RMS_H + i*4) << 32) |
6206 (uint64_t) readl(hdspm->iobase +
6207 HDSPM_MADI_INPUT_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006208 levels->playback_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006209 ((uint64_t)readl(hdspm->iobase +
6210 HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) |
6211 (uint64_t)readl(hdspm->iobase +
6212 HDSPM_MADI_PLAYBACK_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006213 levels->output_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006214 ((uint64_t)readl(hdspm->iobase +
6215 HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) |
6216 (uint64_t)readl(hdspm->iobase +
6217 HDSPM_MADI_OUTPUT_RMS_L + i*4);
6218 }
6219
6220 if (hdspm->system_sample_rate > 96000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006221 levels->speed = qs;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006222 } else if (hdspm->system_sample_rate > 48000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006223 levels->speed = ds;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006224 } else {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006225 levels->speed = ss;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006226 }
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006227 levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006228
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006229 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
Adrian Knoth0dca1792011-01-26 19:32:14 +01006230 if (0 != s) {
6231 /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu
6232 [Levels]\n", sizeof(struct hdspm_peak_rms), s);
6233 */
Takashi Iwai763f3562005-06-03 11:25:34 +02006234 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006235 }
6236 break;
6237
6238 case SNDRV_HDSPM_IOCTL_GET_LTC:
6239 ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
6240 i = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
6241 if (i & HDSPM_TCO1_LTC_Input_valid) {
6242 switch (i & (HDSPM_TCO1_LTC_Format_LSB |
6243 HDSPM_TCO1_LTC_Format_MSB)) {
6244 case 0:
6245 ltc.format = fps_24;
6246 break;
6247 case HDSPM_TCO1_LTC_Format_LSB:
6248 ltc.format = fps_25;
6249 break;
6250 case HDSPM_TCO1_LTC_Format_MSB:
6251 ltc.format = fps_2997;
6252 break;
6253 default:
6254 ltc.format = 30;
6255 break;
6256 }
6257 if (i & HDSPM_TCO1_set_drop_frame_flag) {
6258 ltc.frame = drop_frame;
6259 } else {
6260 ltc.frame = full_frame;
6261 }
6262 } else {
6263 ltc.format = format_invalid;
6264 ltc.frame = frame_invalid;
6265 }
6266 if (i & HDSPM_TCO1_Video_Input_Format_NTSC) {
6267 ltc.input_format = ntsc;
6268 } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) {
6269 ltc.input_format = pal;
6270 } else {
6271 ltc.input_format = no_video;
6272 }
6273
6274 s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc));
6275 if (0 != s) {
6276 /*
6277 snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
Takashi Iwai763f3562005-06-03 11:25:34 +02006278 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006279 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006280
6281 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02006282
Adrian Knoth0dca1792011-01-26 19:32:14 +01006283 case SNDRV_HDSPM_IOCTL_GET_CONFIG:
Takashi Iwai763f3562005-06-03 11:25:34 +02006284
Adrian Knoth4ab69a22011-02-23 11:43:14 +01006285 memset(&info, 0, sizeof(info));
Takashi Iwai763f3562005-06-03 11:25:34 +02006286 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006287 info.pref_sync_ref = hdspm_pref_sync_ref(hdspm);
6288 info.wordclock_sync_check = hdspm_wc_sync_check(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006289
6290 info.system_sample_rate = hdspm->system_sample_rate;
6291 info.autosync_sample_rate =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006292 hdspm_external_sample_rate(hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006293 info.system_clock_mode = hdspm_system_clock_mode(hdspm);
6294 info.clock_source = hdspm_clock_source(hdspm);
6295 info.autosync_ref = hdspm_autosync_ref(hdspm);
Adrian Knothc9e16682012-12-03 14:55:50 +01006296 info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut);
Takashi Iwai763f3562005-06-03 11:25:34 +02006297 info.passthru = 0;
6298 spin_unlock_irq(&hdspm->lock);
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006299 if (copy_to_user(argp, &info, sizeof(info)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006300 return -EFAULT;
6301 break;
6302
Adrian Knoth0dca1792011-01-26 19:32:14 +01006303 case SNDRV_HDSPM_IOCTL_GET_STATUS:
Dan Carpenter643d6bb2011-09-23 09:24:21 +03006304 memset(&status, 0, sizeof(status));
6305
Adrian Knoth0dca1792011-01-26 19:32:14 +01006306 status.card_type = hdspm->io_type;
6307
6308 status.autosync_source = hdspm_autosync_ref(hdspm);
6309
6310 status.card_clock = 110069313433624ULL;
6311 status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
6312
6313 switch (hdspm->io_type) {
6314 case MADI:
6315 case MADIface:
6316 status.card_specific.madi.sync_wc =
6317 hdspm_wc_sync_check(hdspm);
6318 status.card_specific.madi.sync_madi =
6319 hdspm_madi_sync_check(hdspm);
6320 status.card_specific.madi.sync_tco =
6321 hdspm_tco_sync_check(hdspm);
6322 status.card_specific.madi.sync_in =
6323 hdspm_sync_in_sync_check(hdspm);
6324
6325 statusregister =
6326 hdspm_read(hdspm, HDSPM_statusRegister);
6327 status.card_specific.madi.madi_input =
6328 (statusregister & HDSPM_AB_int) ? 1 : 0;
6329 status.card_specific.madi.channel_format =
Adrian Knoth9e6ff522011-10-27 21:57:52 +02006330 (statusregister & HDSPM_RX_64ch) ? 1 : 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006331 /* TODO: Mac driver sets it when f_s>48kHz */
6332 status.card_specific.madi.frame_format = 0;
6333
6334 default:
6335 break;
6336 }
6337
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006338 if (copy_to_user(argp, &status, sizeof(status)))
Adrian Knoth0dca1792011-01-26 19:32:14 +01006339 return -EFAULT;
6340
6341
6342 break;
6343
Takashi Iwai763f3562005-06-03 11:25:34 +02006344 case SNDRV_HDSPM_IOCTL_GET_VERSION:
Dan Carpenter643d6bb2011-09-23 09:24:21 +03006345 memset(&hdspm_version, 0, sizeof(hdspm_version));
6346
Adrian Knoth0dca1792011-01-26 19:32:14 +01006347 hdspm_version.card_type = hdspm->io_type;
6348 strncpy(hdspm_version.cardname, hdspm->card_name,
6349 sizeof(hdspm_version.cardname));
Adrian Knoth7d53a632012-01-04 14:31:16 +01006350 hdspm_version.serial = hdspm->serial;
Takashi Iwai763f3562005-06-03 11:25:34 +02006351 hdspm_version.firmware_rev = hdspm->firmware_rev;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006352 hdspm_version.addons = 0;
6353 if (hdspm->tco)
6354 hdspm_version.addons |= HDSPM_ADDON_TCO;
6355
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006356 if (copy_to_user(argp, &hdspm_version,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006357 sizeof(hdspm_version)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006358 return -EFAULT;
6359 break;
6360
6361 case SNDRV_HDSPM_IOCTL_GET_MIXER:
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006362 if (copy_from_user(&mixer, argp, sizeof(mixer)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006363 return -EFAULT;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006364 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006365 sizeof(struct hdspm_mixer)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006366 return -EFAULT;
6367 break;
6368
6369 default:
6370 return -EINVAL;
6371 }
6372 return 0;
6373}
6374
Takashi Iwai98274f02005-11-17 14:52:34 +01006375static struct snd_pcm_ops snd_hdspm_playback_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006376 .open = snd_hdspm_playback_open,
6377 .close = snd_hdspm_playback_release,
6378 .ioctl = snd_hdspm_ioctl,
6379 .hw_params = snd_hdspm_hw_params,
6380 .hw_free = snd_hdspm_hw_free,
6381 .prepare = snd_hdspm_prepare,
6382 .trigger = snd_hdspm_trigger,
6383 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006384 .page = snd_pcm_sgbuf_ops_page,
6385};
6386
Takashi Iwai98274f02005-11-17 14:52:34 +01006387static struct snd_pcm_ops snd_hdspm_capture_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006388 .open = snd_hdspm_capture_open,
6389 .close = snd_hdspm_capture_release,
6390 .ioctl = snd_hdspm_ioctl,
6391 .hw_params = snd_hdspm_hw_params,
6392 .hw_free = snd_hdspm_hw_free,
6393 .prepare = snd_hdspm_prepare,
6394 .trigger = snd_hdspm_trigger,
6395 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006396 .page = snd_pcm_sgbuf_ops_page,
6397};
6398
Bill Pembertone23e7a12012-12-06 12:35:10 -05006399static int snd_hdspm_create_hwdep(struct snd_card *card,
6400 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006401{
Takashi Iwai98274f02005-11-17 14:52:34 +01006402 struct snd_hwdep *hw;
Takashi Iwai763f3562005-06-03 11:25:34 +02006403 int err;
6404
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006405 err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw);
6406 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006407 return err;
6408
6409 hdspm->hwdep = hw;
6410 hw->private_data = hdspm;
6411 strcpy(hw->name, "HDSPM hwdep interface");
6412
Adrian Knoth0dca1792011-01-26 19:32:14 +01006413 hw->ops.open = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006414 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
Adrian Knoth8de5d6f2012-03-08 15:38:04 +01006415 hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006416 hw->ops.release = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006417
6418 return 0;
6419}
6420
6421
6422/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01006423 memory interface
Takashi Iwai763f3562005-06-03 11:25:34 +02006424 ------------------------------------------------------------*/
Bill Pembertone23e7a12012-12-06 12:35:10 -05006425static int snd_hdspm_preallocate_memory(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006426{
6427 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01006428 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006429 size_t wanted;
6430
6431 pcm = hdspm->pcm;
6432
Remy Bruno3cee5a62006-10-16 12:46:32 +02006433 wanted = HDSPM_DMA_AREA_BYTES;
Takashi Iwai763f3562005-06-03 11:25:34 +02006434
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006435 err =
Takashi Iwai763f3562005-06-03 11:25:34 +02006436 snd_pcm_lib_preallocate_pages_for_all(pcm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006437 SNDRV_DMA_TYPE_DEV_SG,
Takashi Iwai763f3562005-06-03 11:25:34 +02006438 snd_dma_pci_data(hdspm->pci),
6439 wanted,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006440 wanted);
6441 if (err < 0) {
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006442 snd_printdd("Could not preallocate %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006443
6444 return err;
6445 } else
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006446 snd_printdd(" Preallocated %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006447
6448 return 0;
6449}
6450
Adrian Knoth0dca1792011-01-26 19:32:14 +01006451
6452static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +02006453 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +02006454 unsigned int reg, int channels)
6455{
6456 int i;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006457
6458 /* continuous memory segment */
Takashi Iwai763f3562005-06-03 11:25:34 +02006459 for (i = 0; i < (channels * 16); i++)
6460 hdspm_write(hdspm, reg + 4 * i,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006461 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
Takashi Iwai763f3562005-06-03 11:25:34 +02006462}
6463
Adrian Knoth0dca1792011-01-26 19:32:14 +01006464
Takashi Iwai763f3562005-06-03 11:25:34 +02006465/* ------------- ALSA Devices ---------------------------- */
Bill Pembertone23e7a12012-12-06 12:35:10 -05006466static int snd_hdspm_create_pcm(struct snd_card *card,
6467 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006468{
Takashi Iwai98274f02005-11-17 14:52:34 +01006469 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006470 int err;
6471
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006472 err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm);
6473 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006474 return err;
6475
6476 hdspm->pcm = pcm;
6477 pcm->private_data = hdspm;
6478 strcpy(pcm->name, hdspm->card_name);
6479
6480 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6481 &snd_hdspm_playback_ops);
6482 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6483 &snd_hdspm_capture_ops);
6484
6485 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6486
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006487 err = snd_hdspm_preallocate_memory(hdspm);
6488 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006489 return err;
6490
6491 return 0;
6492}
6493
Takashi Iwai98274f02005-11-17 14:52:34 +01006494static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006495{
Adrian Knoth7c7102b2011-02-28 15:14:50 +01006496 int i;
6497
6498 for (i = 0; i < hdspm->midiPorts; i++)
6499 snd_hdspm_flush_midi_input(hdspm, i);
Takashi Iwai763f3562005-06-03 11:25:34 +02006500}
6501
Bill Pembertone23e7a12012-12-06 12:35:10 -05006502static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6503 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006504{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006505 int err, i;
Takashi Iwai763f3562005-06-03 11:25:34 +02006506
6507 snd_printdd("Create card...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006508 err = snd_hdspm_create_pcm(card, hdspm);
6509 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006510 return err;
6511
Adrian Knoth0dca1792011-01-26 19:32:14 +01006512 i = 0;
6513 while (i < hdspm->midiPorts) {
6514 err = snd_hdspm_create_midi(card, hdspm, i);
6515 if (err < 0) {
6516 return err;
6517 }
6518 i++;
6519 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006520
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006521 err = snd_hdspm_create_controls(card, hdspm);
6522 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006523 return err;
6524
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006525 err = snd_hdspm_create_hwdep(card, hdspm);
6526 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006527 return err;
6528
6529 snd_printdd("proc init...\n");
6530 snd_hdspm_proc_init(hdspm);
6531
6532 hdspm->system_sample_rate = -1;
6533 hdspm->last_external_sample_rate = -1;
6534 hdspm->last_internal_sample_rate = -1;
6535 hdspm->playback_pid = -1;
6536 hdspm->capture_pid = -1;
6537 hdspm->capture_substream = NULL;
6538 hdspm->playback_substream = NULL;
6539
6540 snd_printdd("Set defaults...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006541 err = snd_hdspm_set_defaults(hdspm);
6542 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006543 return err;
6544
6545 snd_printdd("Update mixer controls...\n");
6546 hdspm_update_simple_mixer_controls(hdspm);
6547
6548 snd_printdd("Initializeing complete ???\n");
6549
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006550 err = snd_card_register(card);
6551 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006552 snd_printk(KERN_ERR "HDSPM: error registering card\n");
6553 return err;
6554 }
6555
6556 snd_printdd("... yes now\n");
6557
6558 return 0;
6559}
6560
Bill Pembertone23e7a12012-12-06 12:35:10 -05006561static int snd_hdspm_create(struct snd_card *card,
6562 struct hdspm *hdspm)
6563{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006564
Takashi Iwai763f3562005-06-03 11:25:34 +02006565 struct pci_dev *pci = hdspm->pci;
6566 int err;
Takashi Iwai763f3562005-06-03 11:25:34 +02006567 unsigned long io_extent;
6568
6569 hdspm->irq = -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02006570 hdspm->card = card;
6571
6572 spin_lock_init(&hdspm->lock);
6573
Takashi Iwai763f3562005-06-03 11:25:34 +02006574 pci_read_config_word(hdspm->pci,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006575 PCI_CLASS_REVISION, &hdspm->firmware_rev);
Remy Bruno3cee5a62006-10-16 12:46:32 +02006576
Takashi Iwai763f3562005-06-03 11:25:34 +02006577 strcpy(card->mixername, "Xilinx FPGA");
Adrian Knoth0dca1792011-01-26 19:32:14 +01006578 strcpy(card->driver, "HDSPM");
6579
6580 switch (hdspm->firmware_rev) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01006581 case HDSPM_RAYDAT_REV:
6582 hdspm->io_type = RayDAT;
6583 hdspm->card_name = "RME RayDAT";
6584 hdspm->midiPorts = 2;
6585 break;
6586 case HDSPM_AIO_REV:
6587 hdspm->io_type = AIO;
6588 hdspm->card_name = "RME AIO";
6589 hdspm->midiPorts = 1;
6590 break;
6591 case HDSPM_MADIFACE_REV:
6592 hdspm->io_type = MADIface;
6593 hdspm->card_name = "RME MADIface";
6594 hdspm->midiPorts = 1;
6595 break;
Adrian Knoth5027f342011-02-28 15:14:49 +01006596 default:
Adrian Knothc09403d2011-10-27 21:57:54 +02006597 if ((hdspm->firmware_rev == 0xf0) ||
6598 ((hdspm->firmware_rev >= 0xe6) &&
6599 (hdspm->firmware_rev <= 0xea))) {
6600 hdspm->io_type = AES32;
6601 hdspm->card_name = "RME AES32";
6602 hdspm->midiPorts = 2;
Adrian Knoth05c7cc92011-11-21 16:15:36 +01006603 } else if ((hdspm->firmware_rev == 0xd2) ||
Adrian Knothc09403d2011-10-27 21:57:54 +02006604 ((hdspm->firmware_rev >= 0xc8) &&
6605 (hdspm->firmware_rev <= 0xcf))) {
6606 hdspm->io_type = MADI;
6607 hdspm->card_name = "RME MADI";
6608 hdspm->midiPorts = 3;
6609 } else {
6610 snd_printk(KERN_ERR
6611 "HDSPM: unknown firmware revision %x\n",
Adrian Knoth5027f342011-02-28 15:14:49 +01006612 hdspm->firmware_rev);
Adrian Knothc09403d2011-10-27 21:57:54 +02006613 return -ENODEV;
6614 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02006615 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006616
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006617 err = pci_enable_device(pci);
6618 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006619 return err;
6620
6621 pci_set_master(hdspm->pci);
6622
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006623 err = pci_request_regions(pci, "hdspm");
6624 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006625 return err;
6626
6627 hdspm->port = pci_resource_start(pci, 0);
6628 io_extent = pci_resource_len(pci, 0);
6629
6630 snd_printdd("grabbed memory region 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006631 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006632
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006633 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
6634 if (!hdspm->iobase) {
6635 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006636 "unable to remap region 0x%lx-0x%lx\n",
6637 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006638 return -EBUSY;
6639 }
6640 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006641 (unsigned long)hdspm->iobase, hdspm->port,
6642 hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006643
6644 if (request_irq(pci->irq, snd_hdspm_interrupt,
Takashi Iwai934c2b62011-06-10 16:36:37 +02006645 IRQF_SHARED, KBUILD_MODNAME, hdspm)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006646 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq);
6647 return -EBUSY;
6648 }
6649
6650 snd_printdd("use IRQ %d\n", pci->irq);
6651
6652 hdspm->irq = pci->irq;
Takashi Iwai763f3562005-06-03 11:25:34 +02006653
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006654 snd_printdd("kmalloc Mixer memory of %zd Bytes\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006655 sizeof(struct hdspm_mixer));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006656 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
6657 if (!hdspm->mixer) {
6658 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006659 "unable to kmalloc Mixer memory of %d Bytes\n",
6660 (int)sizeof(struct hdspm_mixer));
Julia Lawallb17cbdd2012-08-19 09:02:54 +02006661 return -ENOMEM;
Takashi Iwai763f3562005-06-03 11:25:34 +02006662 }
6663
Adrian Knoth0dca1792011-01-26 19:32:14 +01006664 hdspm->port_names_in = NULL;
6665 hdspm->port_names_out = NULL;
6666
6667 switch (hdspm->io_type) {
6668 case AES32:
Adrian Knothd2d10a22011-02-28 15:14:47 +01006669 hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS;
6670 hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS;
6671 hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS;
Adrian Knoth432d2502011-02-23 11:43:08 +01006672
6673 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6674 channel_map_aes32;
6675 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6676 channel_map_aes32;
6677 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6678 channel_map_aes32;
6679 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6680 texts_ports_aes32;
6681 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6682 texts_ports_aes32;
6683 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6684 texts_ports_aes32;
6685
Adrian Knothd2d10a22011-02-28 15:14:47 +01006686 hdspm->max_channels_out = hdspm->max_channels_in =
6687 AES32_CHANNELS;
Adrian Knoth432d2502011-02-23 11:43:08 +01006688 hdspm->port_names_in = hdspm->port_names_out =
6689 texts_ports_aes32;
6690 hdspm->channel_map_in = hdspm->channel_map_out =
6691 channel_map_aes32;
6692
Adrian Knoth0dca1792011-01-26 19:32:14 +01006693 break;
6694
6695 case MADI:
6696 case MADIface:
6697 hdspm->ss_in_channels = hdspm->ss_out_channels =
6698 MADI_SS_CHANNELS;
6699 hdspm->ds_in_channels = hdspm->ds_out_channels =
6700 MADI_DS_CHANNELS;
6701 hdspm->qs_in_channels = hdspm->qs_out_channels =
6702 MADI_QS_CHANNELS;
6703
6704 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6705 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006706 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006707 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006708 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006709 channel_map_unity_ss;
6710
6711 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6712 texts_ports_madi;
6713 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6714 texts_ports_madi;
6715 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6716 texts_ports_madi;
6717 break;
6718
6719 case AIO:
Adrian Knoth0dca1792011-01-26 19:32:14 +01006720 hdspm->ss_in_channels = AIO_IN_SS_CHANNELS;
6721 hdspm->ds_in_channels = AIO_IN_DS_CHANNELS;
6722 hdspm->qs_in_channels = AIO_IN_QS_CHANNELS;
6723 hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS;
6724 hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS;
6725 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
6726
Adrian Knoth3de9db22013-07-05 11:28:02 +02006727 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
6728 snd_printk(KERN_INFO "HDSPM: AEB input board found\n");
6729 hdspm->ss_in_channels += 4;
6730 hdspm->ds_in_channels += 4;
6731 hdspm->qs_in_channels += 4;
6732 }
6733
6734 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) {
6735 snd_printk(KERN_INFO "HDSPM: AEB output board found\n");
6736 hdspm->ss_out_channels += 4;
6737 hdspm->ds_out_channels += 4;
6738 hdspm->qs_out_channels += 4;
6739 }
6740
Adrian Knoth0dca1792011-01-26 19:32:14 +01006741 hdspm->channel_map_out_ss = channel_map_aio_out_ss;
6742 hdspm->channel_map_out_ds = channel_map_aio_out_ds;
6743 hdspm->channel_map_out_qs = channel_map_aio_out_qs;
6744
6745 hdspm->channel_map_in_ss = channel_map_aio_in_ss;
6746 hdspm->channel_map_in_ds = channel_map_aio_in_ds;
6747 hdspm->channel_map_in_qs = channel_map_aio_in_qs;
6748
6749 hdspm->port_names_in_ss = texts_ports_aio_in_ss;
6750 hdspm->port_names_out_ss = texts_ports_aio_out_ss;
6751 hdspm->port_names_in_ds = texts_ports_aio_in_ds;
6752 hdspm->port_names_out_ds = texts_ports_aio_out_ds;
6753 hdspm->port_names_in_qs = texts_ports_aio_in_qs;
6754 hdspm->port_names_out_qs = texts_ports_aio_out_qs;
6755
6756 break;
6757
6758 case RayDAT:
6759 hdspm->ss_in_channels = hdspm->ss_out_channels =
6760 RAYDAT_SS_CHANNELS;
6761 hdspm->ds_in_channels = hdspm->ds_out_channels =
6762 RAYDAT_DS_CHANNELS;
6763 hdspm->qs_in_channels = hdspm->qs_out_channels =
6764 RAYDAT_QS_CHANNELS;
6765
6766 hdspm->max_channels_in = RAYDAT_SS_CHANNELS;
6767 hdspm->max_channels_out = RAYDAT_SS_CHANNELS;
6768
6769 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6770 channel_map_raydat_ss;
6771 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6772 channel_map_raydat_ds;
6773 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6774 channel_map_raydat_qs;
6775 hdspm->channel_map_in = hdspm->channel_map_out =
6776 channel_map_raydat_ss;
6777
6778 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6779 texts_ports_raydat_ss;
6780 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6781 texts_ports_raydat_ds;
6782 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6783 texts_ports_raydat_qs;
6784
6785
6786 break;
6787
6788 }
6789
6790 /* TCO detection */
6791 switch (hdspm->io_type) {
6792 case AIO:
6793 case RayDAT:
6794 if (hdspm_read(hdspm, HDSPM_statusRegister2) &
6795 HDSPM_s2_tco_detect) {
6796 hdspm->midiPorts++;
6797 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6798 GFP_KERNEL);
6799 if (NULL != hdspm->tco) {
6800 hdspm_tco_write(hdspm);
6801 }
6802 snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n");
6803 } else {
6804 hdspm->tco = NULL;
6805 }
6806 break;
6807
6808 case MADI:
6809 if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) {
6810 hdspm->midiPorts++;
6811 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6812 GFP_KERNEL);
6813 if (NULL != hdspm->tco) {
6814 hdspm_tco_write(hdspm);
6815 }
Adrian Knothe71b95a2013-07-05 11:28:06 +02006816 snd_printk(KERN_INFO "HDSPM: MADI/AES TCO module found\n");
Adrian Knoth0dca1792011-01-26 19:32:14 +01006817 } else {
6818 hdspm->tco = NULL;
6819 }
6820 break;
6821
6822 default:
6823 hdspm->tco = NULL;
6824 }
6825
6826 /* texts */
6827 switch (hdspm->io_type) {
6828 case AES32:
6829 if (hdspm->tco) {
6830 hdspm->texts_autosync = texts_autosync_aes_tco;
Adrian Knothe71b95a2013-07-05 11:28:06 +02006831 hdspm->texts_autosync_items =
6832 ARRAY_SIZE(texts_autosync_aes_tco);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006833 } else {
6834 hdspm->texts_autosync = texts_autosync_aes;
Adrian Knothe71b95a2013-07-05 11:28:06 +02006835 hdspm->texts_autosync_items =
6836 ARRAY_SIZE(texts_autosync_aes);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006837 }
6838 break;
6839
6840 case MADI:
6841 if (hdspm->tco) {
6842 hdspm->texts_autosync = texts_autosync_madi_tco;
6843 hdspm->texts_autosync_items = 4;
6844 } else {
6845 hdspm->texts_autosync = texts_autosync_madi;
6846 hdspm->texts_autosync_items = 3;
6847 }
6848 break;
6849
6850 case MADIface:
6851
6852 break;
6853
6854 case RayDAT:
6855 if (hdspm->tco) {
6856 hdspm->texts_autosync = texts_autosync_raydat_tco;
6857 hdspm->texts_autosync_items = 9;
6858 } else {
6859 hdspm->texts_autosync = texts_autosync_raydat;
6860 hdspm->texts_autosync_items = 8;
6861 }
6862 break;
6863
6864 case AIO:
6865 if (hdspm->tco) {
6866 hdspm->texts_autosync = texts_autosync_aio_tco;
6867 hdspm->texts_autosync_items = 6;
6868 } else {
6869 hdspm->texts_autosync = texts_autosync_aio;
6870 hdspm->texts_autosync_items = 5;
6871 }
6872 break;
6873
6874 }
6875
6876 tasklet_init(&hdspm->midi_tasklet,
6877 hdspm_midi_tasklet, (unsigned long) hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006878
Adrian Knothf7de8ba2012-01-10 20:58:40 +01006879
6880 if (hdspm->io_type != MADIface) {
6881 hdspm->serial = (hdspm_read(hdspm,
6882 HDSPM_midiStatusIn0)>>8) & 0xFFFFFF;
6883 /* id contains either a user-provided value or the default
6884 * NULL. If it's the default, we're safe to
6885 * fill card->id with the serial number.
6886 *
6887 * If the serial number is 0xFFFFFF, then we're dealing with
6888 * an old PCI revision that comes without a sane number. In
6889 * this case, we don't set card->id to avoid collisions
6890 * when running with multiple cards.
6891 */
6892 if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) {
6893 sprintf(card->id, "HDSPMx%06x", hdspm->serial);
6894 snd_card_set_id(card, card->id);
6895 }
6896 }
6897
Takashi Iwai763f3562005-06-03 11:25:34 +02006898 snd_printdd("create alsa devices.\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006899 err = snd_hdspm_create_alsa_devices(card, hdspm);
6900 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006901 return err;
6902
6903 snd_hdspm_initialize_midi_flush(hdspm);
6904
6905 return 0;
6906}
6907
Adrian Knoth0dca1792011-01-26 19:32:14 +01006908
Takashi Iwai98274f02005-11-17 14:52:34 +01006909static int snd_hdspm_free(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006910{
6911
6912 if (hdspm->port) {
6913
6914 /* stop th audio, and cancel all interrupts */
6915 hdspm->control_register &=
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006916 ~(HDSPM_Start | HDSPM_AudioInterruptEnable |
Adrian Knoth0dca1792011-01-26 19:32:14 +01006917 HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable |
6918 HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable);
Takashi Iwai763f3562005-06-03 11:25:34 +02006919 hdspm_write(hdspm, HDSPM_controlRegister,
6920 hdspm->control_register);
6921 }
6922
6923 if (hdspm->irq >= 0)
6924 free_irq(hdspm->irq, (void *) hdspm);
6925
Jesper Juhlfc584222005-10-24 15:11:28 +02006926 kfree(hdspm->mixer);
Takashi Iwai763f3562005-06-03 11:25:34 +02006927
6928 if (hdspm->iobase)
6929 iounmap(hdspm->iobase);
6930
Takashi Iwai763f3562005-06-03 11:25:34 +02006931 if (hdspm->port)
6932 pci_release_regions(hdspm->pci);
6933
6934 pci_disable_device(hdspm->pci);
6935 return 0;
6936}
6937
Adrian Knoth0dca1792011-01-26 19:32:14 +01006938
Takashi Iwai98274f02005-11-17 14:52:34 +01006939static void snd_hdspm_card_free(struct snd_card *card)
Takashi Iwai763f3562005-06-03 11:25:34 +02006940{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006941 struct hdspm *hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02006942
6943 if (hdspm)
6944 snd_hdspm_free(hdspm);
6945}
6946
Adrian Knoth0dca1792011-01-26 19:32:14 +01006947
Bill Pembertone23e7a12012-12-06 12:35:10 -05006948static int snd_hdspm_probe(struct pci_dev *pci,
6949 const struct pci_device_id *pci_id)
Takashi Iwai763f3562005-06-03 11:25:34 +02006950{
6951 static int dev;
Takashi Iwai98274f02005-11-17 14:52:34 +01006952 struct hdspm *hdspm;
6953 struct snd_card *card;
Takashi Iwai763f3562005-06-03 11:25:34 +02006954 int err;
6955
6956 if (dev >= SNDRV_CARDS)
6957 return -ENODEV;
6958 if (!enable[dev]) {
6959 dev++;
6960 return -ENOENT;
6961 }
6962
Takashi Iwaie58de7b2008-12-28 16:44:30 +01006963 err = snd_card_create(index[dev], id[dev],
Adrian Knoth0dca1792011-01-26 19:32:14 +01006964 THIS_MODULE, sizeof(struct hdspm), &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01006965 if (err < 0)
6966 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02006967
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006968 hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02006969 card->private_free = snd_hdspm_card_free;
6970 hdspm->dev = dev;
6971 hdspm->pci = pci;
6972
Takashi Iwaic187c042007-02-19 15:27:33 +01006973 snd_card_set_dev(card, &pci->dev);
6974
Adrian Knoth0dca1792011-01-26 19:32:14 +01006975 err = snd_hdspm_create(card, hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006976 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006977 snd_card_free(card);
6978 return err;
6979 }
6980
Adrian Knoth0dca1792011-01-26 19:32:14 +01006981 if (hdspm->io_type != MADIface) {
6982 sprintf(card->shortname, "%s_%x",
6983 hdspm->card_name,
Adrian Knoth7d53a632012-01-04 14:31:16 +01006984 hdspm->serial);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006985 sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d",
6986 hdspm->card_name,
Adrian Knoth7d53a632012-01-04 14:31:16 +01006987 hdspm->serial,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006988 hdspm->port, hdspm->irq);
6989 } else {
6990 sprintf(card->shortname, "%s", hdspm->card_name);
6991 sprintf(card->longname, "%s at 0x%lx, irq %d",
6992 hdspm->card_name, hdspm->port, hdspm->irq);
6993 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006994
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006995 err = snd_card_register(card);
6996 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006997 snd_card_free(card);
6998 return err;
6999 }
7000
7001 pci_set_drvdata(pci, card);
7002
7003 dev++;
7004 return 0;
7005}
7006
Bill Pembertone23e7a12012-12-06 12:35:10 -05007007static void snd_hdspm_remove(struct pci_dev *pci)
Takashi Iwai763f3562005-06-03 11:25:34 +02007008{
7009 snd_card_free(pci_get_drvdata(pci));
Takashi Iwai763f3562005-06-03 11:25:34 +02007010}
7011
Takashi Iwaie9f66d92012-04-24 12:25:00 +02007012static struct pci_driver hdspm_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02007013 .name = KBUILD_MODNAME,
Takashi Iwai763f3562005-06-03 11:25:34 +02007014 .id_table = snd_hdspm_ids,
7015 .probe = snd_hdspm_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05007016 .remove = snd_hdspm_remove,
Takashi Iwai763f3562005-06-03 11:25:34 +02007017};
7018
Takashi Iwaie9f66d92012-04-24 12:25:00 +02007019module_pci_driver(hdspm_driver);