blob: e98dc008de0b91e4b7e73f776081893fafa04084 [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 */
Martin Dausel69358fc2013-07-05 11:28:23 +020041
42/* ************* Register Documentation *******************************************************
43 *
44 * Work in progress! Documentation is based on the code in this file.
45 *
46 * --------- HDSPM_controlRegister ---------
47 * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte
48 * :||||.||||:||||.||||:||||.||||:||||.||||:
49 * :3322.2222:2222.1111:1111.1100:0000.0000: bit number
50 * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31
51 * :||||.||||:||||.||||:||||.||||:||||.||||:
52 * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
53 * : . : . : . : x . : HDSPM_AudioInterruptEnable \_ setting both bits
54 * : . : . : . : . x: HDSPM_Start / enables audio IO
55 * : . : . : . : x. : HDSPM_ClockModeMaster - 1: Master, 0: Slave
56 * : . : . : . : .210 : HDSPM_LatencyMask - 3 Bit value for latency
57 * : . : . : . : . : 0:64, 1:128, 2:256, 3:512,
58 * : . : . : . : . : 4:1024, 5:2048, 6:4096, 7:8192
59 * :x . : . : . x:xx . : HDSPM_FrequencyMask
60 * : . : . : . :10 . : HDSPM_Frequency1|HDSPM_Frequency0: 1=32K,2=44.1K,3=48K,0=??
61 * : . : . : . x: . : <MADI> HDSPM_DoubleSpeed
62 * :x . : . : . : . : <MADI> HDSPM_QuadSpeed
63 * : . 3 : . 10: 2 . : . : HDSPM_SyncRefMask :
64 * : . : . x: . : . : HDSPM_SyncRef0
65 * : . : . x : . : . : HDSPM_SyncRef1
66 * : . : . : x . : . : <AES32> HDSPM_SyncRef2
67 * : . x : . : . : . : <AES32> HDSPM_SyncRef3
68 * : . : . 10: . : . : <MADI> sync ref: 0:WC, 1:Madi, 2:TCO, 3:SyncIn
69 * : . 3 : . 10: 2 . : . : <AES32> 0:WC, 1:AES1 ... 8:AES8, 9: TCO, 10:SyncIn?
70 * : . x : . : . : . : <MADIe> HDSPe_FLOAT_FORMAT
71 * : . : . : x . : . : <MADI> HDSPM_InputSelect0 : 0=optical,1=coax
72 * : . : . :x . : . : <MADI> HDSPM_InputSelect1
73 * : . : .x : . : . : <MADI> HDSPM_clr_tms
74 * : . : . : . x : . : <MADI> HDSPM_TX_64ch
75 * : . : . : . x : . : <AES32> HDSPM_Emphasis
76 * : . : . : .x : . : <MADI> HDSPM_AutoInp
77 * : . : . x : . : . : <MADI> HDSPM_SMUX
78 * : . : .x : . : . : <MADI> HDSPM_clr_tms
79 * : . : x. : . : . : <MADI> HDSPM_taxi_reset
80 * : . x: . : . : . : <MADI> HDSPM_LineOut
81 * : . x: . : . : . : <AES32> ??????????????????
82 * : . : x. : . : . : <AES32> HDSPM_WCK48
83 * : . : . : .x : . : <AES32> HDSPM_Dolby
84 * : . : x . : . : . : HDSPM_Midi0InterruptEnable
85 * : . :x . : . : . : HDSPM_Midi1InterruptEnable
86 * : . : x . : . : . : HDSPM_Midi2InterruptEnable
87 * : . x : . : . : . : <MADI> HDSPM_Midi3InterruptEnable
88 * : . x : . : . : . : <AES32> HDSPM_DS_DoubleWire
89 * : .x : . : . : . : <AES32> HDSPM_QS_DoubleWire
90 * : x. : . : . : . : <AES32> HDSPM_QS_QuadWire
91 * : . : . : . x : . : <AES32> HDSPM_Professional
92 * : x . : . : . : . : HDSPM_wclk_sel
93 * : . : . : . : . :
94 * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte
95 * :||||.||||:||||.||||:||||.||||:||||.||||:
96 * :3322.2222:2222.1111:1111.1100:0000.0000: bit number
97 * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31
98 * :||||.||||:||||.||||:||||.||||:||||.||||:
99 * :8421.8421:8421.8421:8421.8421:8421.8421:hex digit
100 *
101 *
102 *
103 * AIO / RayDAT only
104 *
105 * ------------ HDSPM_WR_SETTINGS ----------
106 * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte
107 * :1098.7654:3210.9876:5432.1098:7654.3210:
108 * :||||.||||:||||.||||:||||.||||:||||.||||: bit number
109 * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31
110 * :||||.||||:||||.||||:||||.||||:||||.||||:
111 * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
112 * : . : . : . : . x: HDSPM_c0Master 1: Master, 0: Slave
113 * : . : . : . : . x : HDSPM_c0_SyncRef0
114 * : . : . : . : . x : HDSPM_c0_SyncRef1
115 * : . : . : . : .x : HDSPM_c0_SyncRef2
116 * : . : . : . : x. : HDSPM_c0_SyncRef3
117 * : . : . : . : 3.210 : HDSPM_c0_SyncRefMask:
118 * : . : . : . : . : RayDat: 0:WC, 1:AES, 2:SPDIF, 3..6: ADAT1..4,
119 * : . : . : . : . : 9:TCO, 10:SyncIn
120 * : . : . : . : . : AIO: 0:WC, 1:AES, 2: SPDIF, 3: ATAT,
121 * : . : . : . : . : 9:TCO, 10:SyncIn
122 * : . : . : . : . :
123 * : . : . : . : . :
124 * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte
125 * :1098.7654:3210.9876:5432.1098:7654.3210:
126 * :||||.||||:||||.||||:||||.||||:||||.||||: bit number
127 * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31
128 * :||||.||||:||||.||||:||||.||||:||||.||||:
129 * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit
130 *
131 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200132#include <linux/init.h>
133#include <linux/delay.h>
134#include <linux/interrupt.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -0400135#include <linux/module.h>
Takashi Iwai763f3562005-06-03 11:25:34 +0200136#include <linux/slab.h>
137#include <linux/pci.h>
Takashi Iwai3f7440a2009-06-05 17:40:04 +0200138#include <linux/math64.h>
Takashi Iwai763f3562005-06-03 11:25:34 +0200139#include <asm/io.h>
140
141#include <sound/core.h>
142#include <sound/control.h>
143#include <sound/pcm.h>
Adrian Knoth0dca1792011-01-26 19:32:14 +0100144#include <sound/pcm_params.h>
Takashi Iwai763f3562005-06-03 11:25:34 +0200145#include <sound/info.h>
146#include <sound/asoundef.h>
147#include <sound/rawmidi.h>
148#include <sound/hwdep.h>
149#include <sound/initval.h>
150
151#include <sound/hdspm.h>
152
153static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
154static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +1030155static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
Takashi Iwai763f3562005-06-03 11:25:34 +0200156
Takashi Iwai763f3562005-06-03 11:25:34 +0200157module_param_array(index, int, NULL, 0444);
158MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
159
160module_param_array(id, charp, NULL, 0444);
161MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
162
163module_param_array(enable, bool, NULL, 0444);
164MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
165
Takashi Iwai763f3562005-06-03 11:25:34 +0200166
167MODULE_AUTHOR
Adrian Knoth0dca1792011-01-26 19:32:14 +0100168(
169 "Winfried Ritsch <ritsch_AT_iem.at>, "
170 "Paul Davis <paul@linuxaudiosystems.com>, "
171 "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, "
172 "Remy Bruno <remy.bruno@trinnov.com>, "
173 "Florian Faber <faberman@linuxproaudio.org>, "
174 "Adrian Knoth <adi@drcomp.erfurt.thur.de>"
175);
Takashi Iwai763f3562005-06-03 11:25:34 +0200176MODULE_DESCRIPTION("RME HDSPM");
177MODULE_LICENSE("GPL");
178MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
179
Adrian Knoth0dca1792011-01-26 19:32:14 +0100180/* --- Write registers. ---
Takashi Iwai763f3562005-06-03 11:25:34 +0200181 These are defined as byte-offsets from the iobase value. */
182
Adrian Knoth0dca1792011-01-26 19:32:14 +0100183#define HDSPM_WR_SETTINGS 0
184#define HDSPM_outputBufferAddress 32
185#define HDSPM_inputBufferAddress 36
Takashi Iwai763f3562005-06-03 11:25:34 +0200186#define HDSPM_controlRegister 64
187#define HDSPM_interruptConfirmation 96
188#define HDSPM_control2Reg 256 /* not in specs ???????? */
Martin Dausel69358fc2013-07-05 11:28:23 +0200189#define HDSPM_freqReg 256 /* for setting arbitrary clock values (DDS feature) */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100190#define HDSPM_midiDataOut0 352 /* just believe in old code */
191#define HDSPM_midiDataOut1 356
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100192#define HDSPM_eeprom_wr 384 /* for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200193
194/* DMA enable for 64 channels, only Bit 0 is relevant */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100195#define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
Takashi Iwai763f3562005-06-03 11:25:34 +0200196#define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
197
Adrian Knoth0dca1792011-01-26 19:32:14 +0100198/* 16 page addresses for each of the 64 channels DMA buffer in and out
Takashi Iwai763f3562005-06-03 11:25:34 +0200199 (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */
200#define HDSPM_pageAddressBufferOut 8192
201#define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4)
202
203#define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */
204
205#define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */
206
207/* --- Read registers. ---
208 These are defined as byte-offsets from the iobase value */
209#define HDSPM_statusRegister 0
Remy Bruno3cee5a62006-10-16 12:46:32 +0200210/*#define HDSPM_statusRegister2 96 */
211/* after RME Windows driver sources, status2 is 4-byte word # 48 = word at
212 * offset 192, for AES32 *and* MADI
213 * => need to check that offset 192 is working on MADI */
214#define HDSPM_statusRegister2 192
215#define HDSPM_timecodeRegister 128
Takashi Iwai763f3562005-06-03 11:25:34 +0200216
Adrian Knoth0dca1792011-01-26 19:32:14 +0100217/* AIO, RayDAT */
218#define HDSPM_RD_STATUS_0 0
219#define HDSPM_RD_STATUS_1 64
220#define HDSPM_RD_STATUS_2 128
221#define HDSPM_RD_STATUS_3 192
222
223#define HDSPM_RD_TCO 256
224#define HDSPM_RD_PLL_FREQ 512
225#define HDSPM_WR_TCO 128
226
227#define HDSPM_TCO1_TCO_lock 0x00000001
228#define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002
229#define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004
230#define HDSPM_TCO1_LTC_Input_valid 0x00000008
231#define HDSPM_TCO1_WCK_Input_valid 0x00000010
232#define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020
233#define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040
234
235#define HDSPM_TCO1_set_TC 0x00000100
236#define HDSPM_TCO1_set_drop_frame_flag 0x00000200
237#define HDSPM_TCO1_LTC_Format_LSB 0x00000400
238#define HDSPM_TCO1_LTC_Format_MSB 0x00000800
239
240#define HDSPM_TCO2_TC_run 0x00010000
241#define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000
242#define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000
243#define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000
244#define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000
245#define HDSPM_TCO2_set_jam_sync 0x00200000
246#define HDSPM_TCO2_set_flywheel 0x00400000
247
248#define HDSPM_TCO2_set_01_4 0x01000000
249#define HDSPM_TCO2_set_pull_down 0x02000000
250#define HDSPM_TCO2_set_pull_up 0x04000000
251#define HDSPM_TCO2_set_freq 0x08000000
252#define HDSPM_TCO2_set_term_75R 0x10000000
253#define HDSPM_TCO2_set_input_LSB 0x20000000
254#define HDSPM_TCO2_set_input_MSB 0x40000000
255#define HDSPM_TCO2_set_freq_from_app 0x80000000
256
257
258#define HDSPM_midiDataOut0 352
259#define HDSPM_midiDataOut1 356
260#define HDSPM_midiDataOut2 368
261
Takashi Iwai763f3562005-06-03 11:25:34 +0200262#define HDSPM_midiDataIn0 360
263#define HDSPM_midiDataIn1 364
Adrian Knoth0dca1792011-01-26 19:32:14 +0100264#define HDSPM_midiDataIn2 372
265#define HDSPM_midiDataIn3 376
Takashi Iwai763f3562005-06-03 11:25:34 +0200266
267/* status is data bytes in MIDI-FIFO (0-128) */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100268#define HDSPM_midiStatusOut0 384
269#define HDSPM_midiStatusOut1 388
270#define HDSPM_midiStatusOut2 400
271
272#define HDSPM_midiStatusIn0 392
273#define HDSPM_midiStatusIn1 396
274#define HDSPM_midiStatusIn2 404
275#define HDSPM_midiStatusIn3 408
Takashi Iwai763f3562005-06-03 11:25:34 +0200276
277
278/* the meters are regular i/o-mapped registers, but offset
279 considerably from the rest. the peak registers are reset
Adrian Knoth0dca1792011-01-26 19:32:14 +0100280 when read; the least-significant 4 bits are full-scale counters;
Takashi Iwai763f3562005-06-03 11:25:34 +0200281 the actual peak value is in the most-significant 24 bits.
282*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100283
284#define HDSPM_MADI_INPUT_PEAK 4096
285#define HDSPM_MADI_PLAYBACK_PEAK 4352
286#define HDSPM_MADI_OUTPUT_PEAK 4608
287
288#define HDSPM_MADI_INPUT_RMS_L 6144
289#define HDSPM_MADI_PLAYBACK_RMS_L 6400
290#define HDSPM_MADI_OUTPUT_RMS_L 6656
291
292#define HDSPM_MADI_INPUT_RMS_H 7168
293#define HDSPM_MADI_PLAYBACK_RMS_H 7424
294#define HDSPM_MADI_OUTPUT_RMS_H 7680
Takashi Iwai763f3562005-06-03 11:25:34 +0200295
296/* --- Control Register bits --------- */
297#define HDSPM_Start (1<<0) /* start engine */
298
299#define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */
300#define HDSPM_Latency1 (1<<2) /* where n is defined */
301#define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */
302
Adrian Knoth0dca1792011-01-26 19:32:14 +0100303#define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */
304#define HDSPM_c0Master 0x1 /* Master clock bit in settings
305 register [RayDAT, AIO] */
Takashi Iwai763f3562005-06-03 11:25:34 +0200306
307#define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */
308
309#define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
310#define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */
311#define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200312#define HDSPM_QuadSpeed (1<<31) /* quad speed bit */
Takashi Iwai763f3562005-06-03 11:25:34 +0200313
Remy Bruno3cee5a62006-10-16 12:46:32 +0200314#define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200315#define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200316 56channelMODE=0 */ /* MADI ONLY*/
317#define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200318
Adrian Knoth0dca1792011-01-26 19:32:14 +0100319#define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200320 0=off, 1=on */ /* MADI ONLY */
321#define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200322
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200323#define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax
324 * -- MADI ONLY
325 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200326#define HDSPM_InputSelect1 (1<<15) /* should be 0 */
327
Remy Bruno3cee5a62006-10-16 12:46:32 +0200328#define HDSPM_SyncRef2 (1<<13)
329#define HDSPM_SyncRef3 (1<<25)
Takashi Iwai763f3562005-06-03 11:25:34 +0200330
Remy Bruno3cee5a62006-10-16 12:46:32 +0200331#define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100332#define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
Takashi Iwai763f3562005-06-03 11:25:34 +0200333 AES additional bits in
334 lower 5 Audiodatabits ??? */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200335#define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */
336#define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200337
Adrian Knoth0dca1792011-01-26 19:32:14 +0100338#define HDSPM_Midi0InterruptEnable 0x0400000
339#define HDSPM_Midi1InterruptEnable 0x0800000
340#define HDSPM_Midi2InterruptEnable 0x0200000
341#define HDSPM_Midi3InterruptEnable 0x4000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200342
343#define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100344#define HDSPe_FLOAT_FORMAT 0x2000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200345
Remy Bruno3cee5a62006-10-16 12:46:32 +0200346#define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */
347#define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */
348#define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */
349
350#define HDSPM_wclk_sel (1<<30)
Takashi Iwai763f3562005-06-03 11:25:34 +0200351
Adrian Knoth384f7782013-07-05 11:27:53 +0200352/* additional control register bits for AIO*/
353#define HDSPM_c0_Wck48 0x20 /* also RayDAT */
354#define HDSPM_c0_Input0 0x1000
355#define HDSPM_c0_Input1 0x2000
356#define HDSPM_c0_Spdif_Opt 0x4000
357#define HDSPM_c0_Pro 0x8000
358#define HDSPM_c0_clr_tms 0x10000
359#define HDSPM_c0_AEB1 0x20000
360#define HDSPM_c0_AEB2 0x40000
361#define HDSPM_c0_LineOut 0x80000
362#define HDSPM_c0_AD_GAIN0 0x100000
363#define HDSPM_c0_AD_GAIN1 0x200000
364#define HDSPM_c0_DA_GAIN0 0x400000
365#define HDSPM_c0_DA_GAIN1 0x800000
366#define HDSPM_c0_PH_GAIN0 0x1000000
367#define HDSPM_c0_PH_GAIN1 0x2000000
368#define HDSPM_c0_Sym6db 0x4000000
369
370
Takashi Iwai763f3562005-06-03 11:25:34 +0200371/* --- bit helper defines */
372#define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200373#define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\
374 HDSPM_DoubleSpeed|HDSPM_QuadSpeed)
Takashi Iwai763f3562005-06-03 11:25:34 +0200375#define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
376#define HDSPM_InputOptical 0
377#define HDSPM_InputCoaxial (HDSPM_InputSelect0)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200378#define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\
379 HDSPM_SyncRef2|HDSPM_SyncRef3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200380
Adrian Knoth0dca1792011-01-26 19:32:14 +0100381#define HDSPM_c0_SyncRef0 0x2
382#define HDSPM_c0_SyncRef1 0x4
383#define HDSPM_c0_SyncRef2 0x8
384#define HDSPM_c0_SyncRef3 0x10
385#define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\
386 HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3)
387
388#define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */
389#define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */
390#define HDSPM_SYNC_FROM_TCO 2
391#define HDSPM_SYNC_FROM_SYNC_IN 3
Takashi Iwai763f3562005-06-03 11:25:34 +0200392
393#define HDSPM_Frequency32KHz HDSPM_Frequency0
394#define HDSPM_Frequency44_1KHz HDSPM_Frequency1
395#define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0)
396#define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0)
397#define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200398#define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\
399 HDSPM_Frequency0)
Remy Bruno3cee5a62006-10-16 12:46:32 +0200400#define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0)
401#define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200402#define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\
403 HDSPM_Frequency0)
Takashi Iwai763f3562005-06-03 11:25:34 +0200404
Takashi Iwai763f3562005-06-03 11:25:34 +0200405
406/* Synccheck Status */
407#define HDSPM_SYNC_CHECK_NO_LOCK 0
408#define HDSPM_SYNC_CHECK_LOCK 1
409#define HDSPM_SYNC_CHECK_SYNC 2
410
411/* AutoSync References - used by "autosync_ref" control switch */
412#define HDSPM_AUTOSYNC_FROM_WORD 0
413#define HDSPM_AUTOSYNC_FROM_MADI 1
Adrian Knoth0dca1792011-01-26 19:32:14 +0100414#define HDSPM_AUTOSYNC_FROM_TCO 2
415#define HDSPM_AUTOSYNC_FROM_SYNC_IN 3
416#define HDSPM_AUTOSYNC_FROM_NONE 4
Takashi Iwai763f3562005-06-03 11:25:34 +0200417
418/* Possible sources of MADI input */
419#define HDSPM_OPTICAL 0 /* optical */
420#define HDSPM_COAXIAL 1 /* BNC */
421
422#define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100423#define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1))
Takashi Iwai763f3562005-06-03 11:25:34 +0200424
425#define hdspm_encode_in(x) (((x)&0x3)<<14)
426#define hdspm_decode_in(x) (((x)>>14)&0x3)
427
428/* --- control2 register bits --- */
429#define HDSPM_TMS (1<<0)
430#define HDSPM_TCK (1<<1)
431#define HDSPM_TDI (1<<2)
432#define HDSPM_JTAG (1<<3)
433#define HDSPM_PWDN (1<<4)
434#define HDSPM_PROGRAM (1<<5)
435#define HDSPM_CONFIG_MODE_0 (1<<6)
436#define HDSPM_CONFIG_MODE_1 (1<<7)
437/*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/
438#define HDSPM_BIGENDIAN_MODE (1<<9)
439#define HDSPM_RD_MULTIPLE (1<<10)
440
Remy Bruno3cee5a62006-10-16 12:46:32 +0200441/* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200442 that do not conflict with specific bits for AES32 seem to be valid also
443 for the AES32
444 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200445#define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200446#define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */
447#define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1
448 * (like inp0)
449 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100450
Takashi Iwai763f3562005-06-03 11:25:34 +0200451#define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100452#define HDSPM_madiSync (1<<18) /* MADI is in sync */
453
Adrian Knothb0bf5502013-07-05 11:28:05 +0200454#define HDSPM_tcoLockMadi 0x00000020 /* Optional TCO locked status for HDSPe MADI*/
455#define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status for HDSPe MADI and AES32!*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100456
Adrian Knothb0bf5502013-07-05 11:28:05 +0200457#define HDSPM_syncInLock 0x00010000 /* Sync In lock status for HDSPe MADI! */
458#define HDSPM_syncInSync 0x00020000 /* Sync In sync status for HDSPe MADI! */
Takashi Iwai763f3562005-06-03 11:25:34 +0200459
460#define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100461 /* since 64byte accurate, last 6 bits are not used */
Takashi Iwai763f3562005-06-03 11:25:34 +0200462
Adrian Knoth0dca1792011-01-26 19:32:14 +0100463
464
Takashi Iwai763f3562005-06-03 11:25:34 +0200465#define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
466
467#define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */
468#define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */
469#define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */
470#define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */
471
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200472#define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with
473 * Interrupt
474 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100475#define HDSPM_tco_detect 0x08000000
Adrian Knothb0bf5502013-07-05 11:28:05 +0200476#define HDSPM_tcoLockAes 0x20000000 /* Optional TCO locked status for HDSPe AES */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100477
478#define HDSPM_s2_tco_detect 0x00000040
479#define HDSPM_s2_AEBO_D 0x00000080
480#define HDSPM_s2_AEBI_D 0x00000100
481
482
483#define HDSPM_midi0IRQPending 0x40000000
484#define HDSPM_midi1IRQPending 0x80000000
485#define HDSPM_midi2IRQPending 0x20000000
486#define HDSPM_midi2IRQPendingAES 0x00000020
487#define HDSPM_midi3IRQPending 0x00200000
Takashi Iwai763f3562005-06-03 11:25:34 +0200488
489/* --- status bit helpers */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200490#define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\
491 HDSPM_madiFreq2|HDSPM_madiFreq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200492#define HDSPM_madiFreq32 (HDSPM_madiFreq0)
493#define HDSPM_madiFreq44_1 (HDSPM_madiFreq1)
494#define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1)
495#define HDSPM_madiFreq64 (HDSPM_madiFreq2)
496#define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2)
497#define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2)
498#define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2)
499#define HDSPM_madiFreq176_4 (HDSPM_madiFreq3)
500#define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0)
501
Remy Bruno3cee5a62006-10-16 12:46:32 +0200502/* Status2 Register bits */ /* MADI ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200503
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300504#define HDSPM_version0 (1<<0) /* not really defined but I guess */
Takashi Iwai763f3562005-06-03 11:25:34 +0200505#define HDSPM_version1 (1<<1) /* in former cards it was ??? */
506#define HDSPM_version2 (1<<2)
507
508#define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
509#define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
510
511#define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */
512#define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */
Adrian Knotha8cd7142013-05-31 12:57:09 +0200513#define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, 111=128 */
514#define HDSPM_wc_freq3 0x800 /* 1000=176.4, 1001=192 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200515
Adrian Knoth0dca1792011-01-26 19:32:14 +0100516#define HDSPM_SyncRef0 0x10000 /* Sync Reference */
517#define HDSPM_SyncRef1 0x20000
518
519#define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */
Takashi Iwai763f3562005-06-03 11:25:34 +0200520#define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
521#define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
522
523#define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
524
Adrian Knotha8cd7142013-05-31 12:57:09 +0200525#define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\
526 HDSPM_wc_freq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200527#define HDSPM_wcFreq32 (HDSPM_wc_freq0)
528#define HDSPM_wcFreq44_1 (HDSPM_wc_freq1)
529#define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1)
530#define HDSPM_wcFreq64 (HDSPM_wc_freq2)
531#define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2)
532#define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2)
Adrian Knotha8cd7142013-05-31 12:57:09 +0200533#define HDSPM_wcFreq128 (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2)
534#define HDSPM_wcFreq176_4 (HDSPM_wc_freq3)
535#define HDSPM_wcFreq192 (HDSPM_wc_freq0|HDSPM_wc_freq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200536
Adrian Knoth0dca1792011-01-26 19:32:14 +0100537#define HDSPM_status1_F_0 0x0400000
538#define HDSPM_status1_F_1 0x0800000
539#define HDSPM_status1_F_2 0x1000000
540#define HDSPM_status1_F_3 0x2000000
541#define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3)
542
Takashi Iwai763f3562005-06-03 11:25:34 +0200543
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200544#define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
545 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200546#define HDSPM_SelSyncRef_WORD 0
547#define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100548#define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1)
549#define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200550#define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
551 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200552
Remy Bruno3cee5a62006-10-16 12:46:32 +0200553/*
554 For AES32, bits for status, status2 and timecode are different
555*/
556/* status */
557#define HDSPM_AES32_wcLock 0x0200000
Andre Schramm56bde0f2013-01-09 14:40:18 +0100558#define HDSPM_AES32_wcSync 0x0100000
Remy Bruno3cee5a62006-10-16 12:46:32 +0200559#define HDSPM_AES32_wcFreq_bit 22
Adrian Knoth0dca1792011-01-26 19:32:14 +0100560/* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function
Remy Bruno3cee5a62006-10-16 12:46:32 +0200561 HDSPM_bit2freq */
562#define HDSPM_AES32_syncref_bit 16
563/* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */
564
565#define HDSPM_AES32_AUTOSYNC_FROM_WORD 0
566#define HDSPM_AES32_AUTOSYNC_FROM_AES1 1
567#define HDSPM_AES32_AUTOSYNC_FROM_AES2 2
568#define HDSPM_AES32_AUTOSYNC_FROM_AES3 3
569#define HDSPM_AES32_AUTOSYNC_FROM_AES4 4
570#define HDSPM_AES32_AUTOSYNC_FROM_AES5 5
571#define HDSPM_AES32_AUTOSYNC_FROM_AES6 6
572#define HDSPM_AES32_AUTOSYNC_FROM_AES7 7
573#define HDSPM_AES32_AUTOSYNC_FROM_AES8 8
Adrian Knothb0bf5502013-07-05 11:28:05 +0200574#define HDSPM_AES32_AUTOSYNC_FROM_TCO 9
575#define HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN 10
576#define HDSPM_AES32_AUTOSYNC_FROM_NONE 11
Remy Bruno3cee5a62006-10-16 12:46:32 +0200577
578/* status2 */
579/* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */
580#define HDSPM_LockAES 0x80
581#define HDSPM_LockAES1 0x80
582#define HDSPM_LockAES2 0x40
583#define HDSPM_LockAES3 0x20
584#define HDSPM_LockAES4 0x10
585#define HDSPM_LockAES5 0x8
586#define HDSPM_LockAES6 0x4
587#define HDSPM_LockAES7 0x2
588#define HDSPM_LockAES8 0x1
589/*
590 Timecode
591 After windows driver sources, bits 4*i to 4*i+3 give the input frequency on
592 AES i+1
593 bits 3210
594 0001 32kHz
595 0010 44.1kHz
596 0011 48kHz
597 0100 64kHz
598 0101 88.2kHz
599 0110 96kHz
600 0111 128kHz
601 1000 176.4kHz
602 1001 192kHz
603 NB: Timecode register doesn't seem to work on AES32 card revision 230
604*/
605
Takashi Iwai763f3562005-06-03 11:25:34 +0200606/* Mixer Values */
607#define UNITY_GAIN 32768 /* = 65536/2 */
608#define MINUS_INFINITY_GAIN 0
609
Takashi Iwai763f3562005-06-03 11:25:34 +0200610/* Number of channels for different Speed Modes */
611#define MADI_SS_CHANNELS 64
612#define MADI_DS_CHANNELS 32
613#define MADI_QS_CHANNELS 16
614
Adrian Knoth0dca1792011-01-26 19:32:14 +0100615#define RAYDAT_SS_CHANNELS 36
616#define RAYDAT_DS_CHANNELS 20
617#define RAYDAT_QS_CHANNELS 12
618
619#define AIO_IN_SS_CHANNELS 14
620#define AIO_IN_DS_CHANNELS 10
621#define AIO_IN_QS_CHANNELS 8
622#define AIO_OUT_SS_CHANNELS 16
623#define AIO_OUT_DS_CHANNELS 12
624#define AIO_OUT_QS_CHANNELS 10
625
Adrian Knothd2d10a22011-02-28 15:14:47 +0100626#define AES32_CHANNELS 16
627
Takashi Iwai763f3562005-06-03 11:25:34 +0200628/* the size of a substream (1 mono data stream) */
629#define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024)
630#define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES)
631
632/* the size of the area we need to allocate for DMA transfers. the
633 size is the same regardless of the number of channels, and
Adrian Knoth0dca1792011-01-26 19:32:14 +0100634 also the latency to use.
Takashi Iwai763f3562005-06-03 11:25:34 +0200635 for one direction !!!
636*/
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100637#define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
Takashi Iwai763f3562005-06-03 11:25:34 +0200638#define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
639
Adrian Knoth0dca1792011-01-26 19:32:14 +0100640#define HDSPM_RAYDAT_REV 211
641#define HDSPM_AIO_REV 212
642#define HDSPM_MADIFACE_REV 213
Remy Bruno3cee5a62006-10-16 12:46:32 +0200643
Remy Bruno65345992007-08-31 12:21:08 +0200644/* speed factor modes */
645#define HDSPM_SPEED_SINGLE 0
646#define HDSPM_SPEED_DOUBLE 1
647#define HDSPM_SPEED_QUAD 2
Adrian Knoth0dca1792011-01-26 19:32:14 +0100648
Remy Bruno65345992007-08-31 12:21:08 +0200649/* names for speed modes */
650static char *hdspm_speed_names[] = { "single", "double", "quad" };
651
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200652static const char *const texts_autosync_aes_tco[] = { "Word Clock",
Adrian Knoth0dca1792011-01-26 19:32:14 +0100653 "AES1", "AES2", "AES3", "AES4",
654 "AES5", "AES6", "AES7", "AES8",
Adrian Knothdb2d1a92013-07-05 11:28:08 +0200655 "TCO", "Sync In"
656};
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200657static const char *const texts_autosync_aes[] = { "Word Clock",
Adrian Knoth0dca1792011-01-26 19:32:14 +0100658 "AES1", "AES2", "AES3", "AES4",
Adrian Knothdb2d1a92013-07-05 11:28:08 +0200659 "AES5", "AES6", "AES7", "AES8",
660 "Sync In"
661};
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200662static const char *const texts_autosync_madi_tco[] = { "Word Clock",
Adrian Knoth0dca1792011-01-26 19:32:14 +0100663 "MADI", "TCO", "Sync In" };
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200664static const char *const texts_autosync_madi[] = { "Word Clock",
Adrian Knoth0dca1792011-01-26 19:32:14 +0100665 "MADI", "Sync In" };
666
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200667static const char *const texts_autosync_raydat_tco[] = {
Adrian Knoth0dca1792011-01-26 19:32:14 +0100668 "Word Clock",
669 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
670 "AES", "SPDIF", "TCO", "Sync In"
671};
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200672static const char *const texts_autosync_raydat[] = {
Adrian Knoth0dca1792011-01-26 19:32:14 +0100673 "Word Clock",
674 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
675 "AES", "SPDIF", "Sync In"
676};
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200677static const char *const texts_autosync_aio_tco[] = {
Adrian Knoth0dca1792011-01-26 19:32:14 +0100678 "Word Clock",
679 "ADAT", "AES", "SPDIF", "TCO", "Sync In"
680};
Adrian Knotheb0d4db2013-07-05 11:28:21 +0200681static const char *const texts_autosync_aio[] = { "Word Clock",
Adrian Knoth0dca1792011-01-26 19:32:14 +0100682 "ADAT", "AES", "SPDIF", "Sync In" };
683
Adrian Knoth38816542013-07-05 11:28:20 +0200684static const char *const texts_freq[] = {
Adrian Knoth0dca1792011-01-26 19:32:14 +0100685 "No Lock",
686 "32 kHz",
687 "44.1 kHz",
688 "48 kHz",
689 "64 kHz",
690 "88.2 kHz",
691 "96 kHz",
692 "128 kHz",
693 "176.4 kHz",
694 "192 kHz"
695};
696
Adrian Knoth0dca1792011-01-26 19:32:14 +0100697static char *texts_ports_madi[] = {
698 "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6",
699 "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12",
700 "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18",
701 "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24",
702 "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30",
703 "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36",
704 "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42",
705 "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48",
706 "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54",
707 "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60",
708 "MADI.61", "MADI.62", "MADI.63", "MADI.64",
709};
710
711
712static char *texts_ports_raydat_ss[] = {
713 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6",
714 "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
715 "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2",
716 "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8",
717 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6",
718 "ADAT4.7", "ADAT4.8",
719 "AES.L", "AES.R",
720 "SPDIF.L", "SPDIF.R"
721};
722
723static char *texts_ports_raydat_ds[] = {
724 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4",
725 "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
726 "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4",
727 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4",
728 "AES.L", "AES.R",
729 "SPDIF.L", "SPDIF.R"
730};
731
732static char *texts_ports_raydat_qs[] = {
733 "ADAT1.1", "ADAT1.2",
734 "ADAT2.1", "ADAT2.2",
735 "ADAT3.1", "ADAT3.2",
736 "ADAT4.1", "ADAT4.2",
737 "AES.L", "AES.R",
738 "SPDIF.L", "SPDIF.R"
739};
740
741
742static char *texts_ports_aio_in_ss[] = {
743 "Analogue.L", "Analogue.R",
744 "AES.L", "AES.R",
745 "SPDIF.L", "SPDIF.R",
746 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200747 "ADAT.7", "ADAT.8",
748 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100749};
750
751static char *texts_ports_aio_out_ss[] = {
752 "Analogue.L", "Analogue.R",
753 "AES.L", "AES.R",
754 "SPDIF.L", "SPDIF.R",
755 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
756 "ADAT.7", "ADAT.8",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200757 "Phone.L", "Phone.R",
758 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100759};
760
761static char *texts_ports_aio_in_ds[] = {
762 "Analogue.L", "Analogue.R",
763 "AES.L", "AES.R",
764 "SPDIF.L", "SPDIF.R",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200765 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
766 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100767};
768
769static char *texts_ports_aio_out_ds[] = {
770 "Analogue.L", "Analogue.R",
771 "AES.L", "AES.R",
772 "SPDIF.L", "SPDIF.R",
773 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200774 "Phone.L", "Phone.R",
775 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100776};
777
778static char *texts_ports_aio_in_qs[] = {
779 "Analogue.L", "Analogue.R",
780 "AES.L", "AES.R",
781 "SPDIF.L", "SPDIF.R",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200782 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
783 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100784};
785
786static char *texts_ports_aio_out_qs[] = {
787 "Analogue.L", "Analogue.R",
788 "AES.L", "AES.R",
789 "SPDIF.L", "SPDIF.R",
790 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
Adrian Knoth3de9db22013-07-05 11:28:02 +0200791 "Phone.L", "Phone.R",
792 "AEB.1", "AEB.2", "AEB.3", "AEB.4"
Adrian Knoth0dca1792011-01-26 19:32:14 +0100793};
794
Adrian Knoth432d2502011-02-23 11:43:08 +0100795static char *texts_ports_aes32[] = {
796 "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7",
797 "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14",
798 "AES.15", "AES.16"
799};
800
Adrian Knoth55a57602011-01-27 11:23:15 +0100801/* These tables map the ALSA channels 1..N to the channels that we
802 need to use in order to find the relevant channel buffer. RME
803 refers to this kind of mapping as between "the ADAT channel and
804 the DMA channel." We index it using the logical audio channel,
805 and the value is the DMA channel (i.e. channel buffer number)
806 where the data for that channel can be read/written from/to.
807*/
808
809static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = {
810 0, 1, 2, 3, 4, 5, 6, 7,
811 8, 9, 10, 11, 12, 13, 14, 15,
812 16, 17, 18, 19, 20, 21, 22, 23,
813 24, 25, 26, 27, 28, 29, 30, 31,
814 32, 33, 34, 35, 36, 37, 38, 39,
815 40, 41, 42, 43, 44, 45, 46, 47,
816 48, 49, 50, 51, 52, 53, 54, 55,
817 56, 57, 58, 59, 60, 61, 62, 63
818};
819
Adrian Knoth55a57602011-01-27 11:23:15 +0100820static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = {
821 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */
822 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */
823 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */
824 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */
825 0, 1, /* AES */
826 2, 3, /* SPDIF */
827 -1, -1, -1, -1,
828 -1, -1, -1, -1, -1, -1, -1, -1,
829 -1, -1, -1, -1, -1, -1, -1, -1,
830 -1, -1, -1, -1, -1, -1, -1, -1,
831};
832
833static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = {
834 4, 5, 6, 7, /* ADAT 1 */
835 8, 9, 10, 11, /* ADAT 2 */
836 12, 13, 14, 15, /* ADAT 3 */
837 16, 17, 18, 19, /* ADAT 4 */
838 0, 1, /* AES */
839 2, 3, /* SPDIF */
840 -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 -1, -1, -1, -1, -1, -1, -1, -1,
846};
847
848static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = {
849 4, 5, /* ADAT 1 */
850 6, 7, /* ADAT 2 */
851 8, 9, /* ADAT 3 */
852 10, 11, /* ADAT 4 */
853 0, 1, /* AES */
854 2, 3, /* SPDIF */
855 -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 -1, -1, -1, -1, -1, -1, -1, -1,
862};
863
864static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = {
865 0, 1, /* line in */
866 8, 9, /* aes in, */
867 10, 11, /* spdif in */
868 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200869 2, 3, 4, 5, /* AEB */
870 -1, -1, -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100871 -1, -1, -1, -1, -1, -1, -1, -1,
872 -1, -1, -1, -1, -1, -1, -1, -1,
873 -1, -1, -1, -1, -1, -1, -1, -1,
874 -1, -1, -1, -1, -1, -1, -1, -1,
875 -1, -1, -1, -1, -1, -1, -1, -1,
876};
877
878static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = {
879 0, 1, /* line out */
880 8, 9, /* aes out */
881 10, 11, /* spdif out */
882 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */
883 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200884 2, 3, 4, 5, /* AEB */
885 -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100886 -1, -1, -1, -1, -1, -1, -1, -1,
887 -1, -1, -1, -1, -1, -1, -1, -1,
888 -1, -1, -1, -1, -1, -1, -1, -1,
889 -1, -1, -1, -1, -1, -1, -1, -1,
890 -1, -1, -1, -1, -1, -1, -1, -1,
891};
892
893static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = {
894 0, 1, /* line in */
895 8, 9, /* aes in */
896 10, 11, /* spdif in */
897 12, 14, 16, 18, /* adat in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200898 2, 3, 4, 5, /* AEB */
899 -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100900 -1, -1, -1, -1, -1, -1, -1, -1,
901 -1, -1, -1, -1, -1, -1, -1, -1,
902 -1, -1, -1, -1, -1, -1, -1, -1,
903 -1, -1, -1, -1, -1, -1, -1, -1,
904 -1, -1, -1, -1, -1, -1, -1, -1,
905 -1, -1, -1, -1, -1, -1, -1, -1
906};
907
908static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = {
909 0, 1, /* line out */
910 8, 9, /* aes out */
911 10, 11, /* spdif out */
912 12, 14, 16, 18, /* adat out */
913 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200914 2, 3, 4, 5, /* AEB */
Adrian Knoth55a57602011-01-27 11:23:15 +0100915 -1, -1, -1, -1, -1, -1, -1, -1,
916 -1, -1, -1, -1, -1, -1, -1, -1,
917 -1, -1, -1, -1, -1, -1, -1, -1,
918 -1, -1, -1, -1, -1, -1, -1, -1,
919 -1, -1, -1, -1, -1, -1, -1, -1,
920 -1, -1, -1, -1, -1, -1, -1, -1
921};
922
923static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = {
924 0, 1, /* line in */
925 8, 9, /* aes in */
926 10, 11, /* spdif in */
927 12, 16, /* adat in */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200928 2, 3, 4, 5, /* AEB */
929 -1, -1, -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100930 -1, -1, -1, -1, -1, -1, -1, -1,
931 -1, -1, -1, -1, -1, -1, -1, -1,
932 -1, -1, -1, -1, -1, -1, -1, -1,
933 -1, -1, -1, -1, -1, -1, -1, -1,
934 -1, -1, -1, -1, -1, -1, -1, -1,
935 -1, -1, -1, -1, -1, -1, -1, -1
936};
937
938static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = {
939 0, 1, /* line out */
940 8, 9, /* aes out */
941 10, 11, /* spdif out */
942 12, 16, /* adat out */
943 6, 7, /* phone out */
Adrian Knoth3de9db22013-07-05 11:28:02 +0200944 2, 3, 4, 5, /* AEB */
945 -1, -1,
Adrian Knoth55a57602011-01-27 11:23:15 +0100946 -1, -1, -1, -1, -1, -1, -1, -1,
947 -1, -1, -1, -1, -1, -1, -1, -1,
948 -1, -1, -1, -1, -1, -1, -1, -1,
949 -1, -1, -1, -1, -1, -1, -1, -1,
950 -1, -1, -1, -1, -1, -1, -1, -1,
951 -1, -1, -1, -1, -1, -1, -1, -1
952};
953
Adrian Knoth432d2502011-02-23 11:43:08 +0100954static char channel_map_aes32[HDSPM_MAX_CHANNELS] = {
955 0, 1, 2, 3, 4, 5, 6, 7,
956 8, 9, 10, 11, 12, 13, 14, 15,
957 -1, -1, -1, -1, -1, -1, -1, -1,
958 -1, -1, -1, -1, -1, -1, -1, -1,
959 -1, -1, -1, -1, -1, -1, -1, -1,
960 -1, -1, -1, -1, -1, -1, -1, -1,
961 -1, -1, -1, -1, -1, -1, -1, -1,
962 -1, -1, -1, -1, -1, -1, -1, -1
963};
964
Takashi Iwai98274f02005-11-17 14:52:34 +0100965struct hdspm_midi {
966 struct hdspm *hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +0200967 int id;
Takashi Iwai98274f02005-11-17 14:52:34 +0100968 struct snd_rawmidi *rmidi;
969 struct snd_rawmidi_substream *input;
970 struct snd_rawmidi_substream *output;
Takashi Iwai763f3562005-06-03 11:25:34 +0200971 char istimer; /* timer in use */
972 struct timer_list timer;
973 spinlock_t lock;
974 int pending;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100975 int dataIn;
976 int statusIn;
977 int dataOut;
978 int statusOut;
979 int ie;
980 int irq;
981};
982
983struct hdspm_tco {
Martin Dausel69358fc2013-07-05 11:28:23 +0200984 int input; /* 0: LTC, 1:Video, 2: WC*/
985 int framerate; /* 0=24, 1=25, 2=29.97, 3=29.97d, 4=30, 5=30d */
986 int wordclock; /* 0=1:1, 1=44.1->48, 2=48->44.1 */
987 int samplerate; /* 0=44.1, 1=48, 2= freq from app */
988 int pull; /* 0=0, 1=+0.1%, 2=-0.1%, 3=+4%, 4=-4%*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100989 int term; /* 0 = off, 1 = on */
Takashi Iwai763f3562005-06-03 11:25:34 +0200990};
991
Takashi Iwai98274f02005-11-17 14:52:34 +0100992struct hdspm {
Takashi Iwai763f3562005-06-03 11:25:34 +0200993 spinlock_t lock;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200994 /* only one playback and/or capture stream */
995 struct snd_pcm_substream *capture_substream;
996 struct snd_pcm_substream *playback_substream;
Takashi Iwai763f3562005-06-03 11:25:34 +0200997
998 char *card_name; /* for procinfo */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200999 unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/
1000
Adrian Knoth0dca1792011-01-26 19:32:14 +01001001 uint8_t io_type;
Takashi Iwai763f3562005-06-03 11:25:34 +02001002
Takashi Iwai763f3562005-06-03 11:25:34 +02001003 int monitor_outs; /* set up monitoring outs init flag */
1004
1005 u32 control_register; /* cached value */
1006 u32 control2_register; /* cached value */
Martin Dausel69358fc2013-07-05 11:28:23 +02001007 u32 settings_register; /* cached value for AIO / RayDat (sync reference, master/slave) */
Takashi Iwai763f3562005-06-03 11:25:34 +02001008
Adrian Knoth0dca1792011-01-26 19:32:14 +01001009 struct hdspm_midi midi[4];
Takashi Iwai763f3562005-06-03 11:25:34 +02001010 struct tasklet_struct midi_tasklet;
1011
1012 size_t period_bytes;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001013 unsigned char ss_in_channels;
1014 unsigned char ds_in_channels;
1015 unsigned char qs_in_channels;
1016 unsigned char ss_out_channels;
1017 unsigned char ds_out_channels;
1018 unsigned char qs_out_channels;
1019
1020 unsigned char max_channels_in;
1021 unsigned char max_channels_out;
1022
Takashi Iwai286bed02011-06-30 12:45:36 +02001023 signed char *channel_map_in;
1024 signed char *channel_map_out;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001025
Takashi Iwai286bed02011-06-30 12:45:36 +02001026 signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs;
1027 signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001028
1029 char **port_names_in;
1030 char **port_names_out;
1031
1032 char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs;
1033 char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs;
Takashi Iwai763f3562005-06-03 11:25:34 +02001034
1035 unsigned char *playback_buffer; /* suitably aligned address */
1036 unsigned char *capture_buffer; /* suitably aligned address */
1037
1038 pid_t capture_pid; /* process id which uses capture */
1039 pid_t playback_pid; /* process id which uses capture */
1040 int running; /* running status */
1041
1042 int last_external_sample_rate; /* samplerate mystic ... */
1043 int last_internal_sample_rate;
1044 int system_sample_rate;
1045
Takashi Iwai763f3562005-06-03 11:25:34 +02001046 int dev; /* Hardware vars... */
1047 int irq;
1048 unsigned long port;
1049 void __iomem *iobase;
1050
1051 int irq_count; /* for debug */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001052 int midiPorts;
Takashi Iwai763f3562005-06-03 11:25:34 +02001053
Takashi Iwai98274f02005-11-17 14:52:34 +01001054 struct snd_card *card; /* one card */
1055 struct snd_pcm *pcm; /* has one pcm */
1056 struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */
Takashi Iwai763f3562005-06-03 11:25:34 +02001057 struct pci_dev *pci; /* and an pci info */
1058
1059 /* Mixer vars */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001060 /* fast alsa mixer */
1061 struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS];
1062 /* but input to much, so not used */
1063 struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS];
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001064 /* full mixer accessible over mixer ioctl or hwdep-device */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001065 struct hdspm_mixer *mixer;
Takashi Iwai763f3562005-06-03 11:25:34 +02001066
Adrian Knoth0dca1792011-01-26 19:32:14 +01001067 struct hdspm_tco *tco; /* NULL if no TCO detected */
Takashi Iwai763f3562005-06-03 11:25:34 +02001068
Adrian Knotheb0d4db2013-07-05 11:28:21 +02001069 const char *const *texts_autosync;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001070 int texts_autosync_items;
Takashi Iwai763f3562005-06-03 11:25:34 +02001071
Adrian Knoth0dca1792011-01-26 19:32:14 +01001072 cycles_t last_interrupt;
Jaroslav Kysela730a5862011-01-27 13:03:15 +01001073
Adrian Knoth7d53a632012-01-04 14:31:16 +01001074 unsigned int serial;
1075
Jaroslav Kysela730a5862011-01-27 13:03:15 +01001076 struct hdspm_peak_rms peak_rms;
Takashi Iwai763f3562005-06-03 11:25:34 +02001077};
1078
Takashi Iwai763f3562005-06-03 11:25:34 +02001079
Alexey Dobriyancebe41d2010-02-06 00:21:03 +02001080static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = {
Takashi Iwai763f3562005-06-03 11:25:34 +02001081 {
1082 .vendor = PCI_VENDOR_ID_XILINX,
1083 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
1084 .subvendor = PCI_ANY_ID,
1085 .subdevice = PCI_ANY_ID,
1086 .class = 0,
1087 .class_mask = 0,
1088 .driver_data = 0},
1089 {0,}
1090};
1091
1092MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
1093
1094/* prototypes */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001095static int snd_hdspm_create_alsa_devices(struct snd_card *card,
1096 struct hdspm *hdspm);
1097static int snd_hdspm_create_pcm(struct snd_card *card,
1098 struct hdspm *hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001099
Adrian Knoth0dca1792011-01-26 19:32:14 +01001100static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
Adrian Knoth3f7bf912013-03-10 00:37:21 +01001101static inline int hdspm_get_pll_freq(struct hdspm *hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001102static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
1103static int hdspm_autosync_ref(struct hdspm *hdspm);
Adrian Knoth34be7eb2013-07-05 11:27:56 +02001104static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001105static int snd_hdspm_set_defaults(struct hdspm *hdspm);
Adrian Knoth21a164d2012-10-19 17:42:23 +02001106static int hdspm_system_clock_mode(struct hdspm *hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001107static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +02001108 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +02001109 unsigned int reg, int channels);
1110
Adrian Knoth5b266352013-07-05 11:28:10 +02001111static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx);
1112static int hdspm_wc_sync_check(struct hdspm *hdspm);
1113static int hdspm_tco_sync_check(struct hdspm *hdspm);
1114static int hdspm_sync_in_sync_check(struct hdspm *hdspm);
1115
1116static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index);
1117static int hdspm_get_tco_sample_rate(struct hdspm *hdspm);
1118static int hdspm_get_wc_sample_rate(struct hdspm *hdspm);
1119
1120
1121
Remy Bruno3cee5a62006-10-16 12:46:32 +02001122static inline int HDSPM_bit2freq(int n)
1123{
Denys Vlasenko62cef822008-04-14 13:04:18 +02001124 static const int bit2freq_tab[] = {
1125 0, 32000, 44100, 48000, 64000, 88200,
Remy Bruno3cee5a62006-10-16 12:46:32 +02001126 96000, 128000, 176400, 192000 };
1127 if (n < 1 || n > 9)
1128 return 0;
1129 return bit2freq_tab[n];
1130}
1131
Adrian Knothb2ed6322013-07-05 11:27:54 +02001132static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm)
1133{
1134 return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type));
1135}
1136
1137
Adrian Knoth0dca1792011-01-26 19:32:14 +01001138/* Write/read to/from HDSPM with Adresses in Bytes
Takashi Iwai763f3562005-06-03 11:25:34 +02001139 not words but only 32Bit writes are allowed */
1140
Takashi Iwai98274f02005-11-17 14:52:34 +01001141static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
Takashi Iwai763f3562005-06-03 11:25:34 +02001142 unsigned int val)
1143{
1144 writel(val, hdspm->iobase + reg);
1145}
1146
Takashi Iwai98274f02005-11-17 14:52:34 +01001147static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
Takashi Iwai763f3562005-06-03 11:25:34 +02001148{
1149 return readl(hdspm->iobase + reg);
1150}
1151
Adrian Knoth0dca1792011-01-26 19:32:14 +01001152/* for each output channel (chan) I have an Input (in) and Playback (pb) Fader
1153 mixer is write only on hardware so we have to cache him for read
Takashi Iwai763f3562005-06-03 11:25:34 +02001154 each fader is a u32, but uses only the first 16 bit */
1155
Takashi Iwai98274f02005-11-17 14:52:34 +01001156static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001157 unsigned int in)
1158{
Adrian Bunk5bab24822006-03-13 14:15:04 +01001159 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001160 return 0;
1161
1162 return hdspm->mixer->ch[chan].in[in];
1163}
1164
Takashi Iwai98274f02005-11-17 14:52:34 +01001165static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001166 unsigned int pb)
1167{
Adrian Bunk5bab24822006-03-13 14:15:04 +01001168 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001169 return 0;
1170 return hdspm->mixer->ch[chan].pb[pb];
1171}
1172
Denys Vlasenko62cef822008-04-14 13:04:18 +02001173static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001174 unsigned int in, unsigned short data)
1175{
1176 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
1177 return -1;
1178
1179 hdspm_write(hdspm,
1180 HDSPM_MADI_mixerBase +
1181 ((in + 128 * chan) * sizeof(u32)),
1182 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
1183 return 0;
1184}
1185
Denys Vlasenko62cef822008-04-14 13:04:18 +02001186static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001187 unsigned int pb, unsigned short data)
1188{
1189 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
1190 return -1;
1191
1192 hdspm_write(hdspm,
1193 HDSPM_MADI_mixerBase +
1194 ((64 + pb + 128 * chan) * sizeof(u32)),
1195 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
1196 return 0;
1197}
1198
1199
1200/* enable DMA for specific channels, now available for DSP-MADI */
Takashi Iwai98274f02005-11-17 14:52:34 +01001201static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001202{
1203 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
1204}
1205
Takashi Iwai98274f02005-11-17 14:52:34 +01001206static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001207{
1208 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
1209}
1210
1211/* check if same process is writing and reading */
Denys Vlasenko62cef822008-04-14 13:04:18 +02001212static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001213{
1214 unsigned long flags;
1215 int ret = 1;
1216
1217 spin_lock_irqsave(&hdspm->lock, flags);
1218 if ((hdspm->playback_pid != hdspm->capture_pid) &&
1219 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
1220 ret = 0;
1221 }
1222 spin_unlock_irqrestore(&hdspm->lock, flags);
1223 return ret;
1224}
1225
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001226/* round arbitary sample rates to commonly known rates */
1227static int hdspm_round_frequency(int rate)
1228{
1229 if (rate < 38050)
1230 return 32000;
1231 if (rate < 46008)
1232 return 44100;
1233 else
1234 return 48000;
1235}
1236
Adrian Knotha8a729f2013-05-31 12:57:10 +02001237/* QS and DS rates normally can not be detected
1238 * automatically by the card. Only exception is MADI
1239 * in 96k frame mode.
1240 *
1241 * So if we read SS values (32 .. 48k), check for
1242 * user-provided DS/QS bits in the control register
1243 * and multiply the base frequency accordingly.
1244 */
1245static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate)
1246{
1247 if (rate <= 48000) {
1248 if (hdspm->control_register & HDSPM_QuadSpeed)
1249 return rate * 4;
1250 else if (hdspm->control_register &
1251 HDSPM_DoubleSpeed)
1252 return rate * 2;
Fengguang Wu68593c92013-07-15 21:41:32 +08001253 }
Adrian Knotha8a729f2013-05-31 12:57:10 +02001254 return rate;
1255}
1256
Adrian Knoth5b266352013-07-05 11:28:10 +02001257/* check for external sample rate, returns the sample rate in Hz*/
Denys Vlasenko62cef822008-04-14 13:04:18 +02001258static int hdspm_external_sample_rate(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001259{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001260 unsigned int status, status2, timecode;
1261 int syncref, rate = 0, rate_bits;
Takashi Iwai763f3562005-06-03 11:25:34 +02001262
Adrian Knoth0dca1792011-01-26 19:32:14 +01001263 switch (hdspm->io_type) {
1264 case AES32:
1265 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1266 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01001267 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001268
1269 syncref = hdspm_autosync_ref(hdspm);
Adrian Knothdbae4a02013-07-05 11:28:14 +02001270 switch (syncref) {
1271 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
1272 /* Check WC sync and get sample rate */
1273 if (hdspm_wc_sync_check(hdspm))
1274 return HDSPM_bit2freq(hdspm_get_wc_sample_rate(hdspm));
1275 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001276
Adrian Knothdbae4a02013-07-05 11:28:14 +02001277 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
1278 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
1279 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
1280 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
1281 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
1282 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
1283 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
1284 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
1285 /* Check AES sync and get sample rate */
1286 if (hdspm_aes_sync_check(hdspm, syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))
1287 return HDSPM_bit2freq(hdspm_get_aes_sample_rate(hdspm,
1288 syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1));
1289 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001290
Adrian Knothdbae4a02013-07-05 11:28:14 +02001291
1292 case HDSPM_AES32_AUTOSYNC_FROM_TCO:
1293 /* Check TCO sync and get sample rate */
1294 if (hdspm_tco_sync_check(hdspm))
1295 return HDSPM_bit2freq(hdspm_get_tco_sample_rate(hdspm));
1296 break;
1297 default:
1298 return 0;
1299 } /* end switch(syncref) */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001300 break;
1301
1302 case MADIface:
1303 status = hdspm_read(hdspm, HDSPM_statusRegister);
1304
1305 if (!(status & HDSPM_madiLock)) {
1306 rate = 0; /* no lock */
1307 } else {
1308 switch (status & (HDSPM_status1_freqMask)) {
1309 case HDSPM_status1_F_0*1:
1310 rate = 32000; break;
1311 case HDSPM_status1_F_0*2:
1312 rate = 44100; break;
1313 case HDSPM_status1_F_0*3:
1314 rate = 48000; break;
1315 case HDSPM_status1_F_0*4:
1316 rate = 64000; break;
1317 case HDSPM_status1_F_0*5:
1318 rate = 88200; break;
1319 case HDSPM_status1_F_0*6:
1320 rate = 96000; break;
1321 case HDSPM_status1_F_0*7:
1322 rate = 128000; break;
1323 case HDSPM_status1_F_0*8:
1324 rate = 176400; break;
1325 case HDSPM_status1_F_0*9:
1326 rate = 192000; break;
1327 default:
1328 rate = 0; break;
1329 }
1330 }
1331
1332 break;
1333
1334 case MADI:
1335 case AIO:
1336 case RayDAT:
1337 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1338 status = hdspm_read(hdspm, HDSPM_statusRegister);
1339 rate = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02001340
Remy Bruno3cee5a62006-10-16 12:46:32 +02001341 /* if wordclock has synced freq and wordclock is valid */
1342 if ((status2 & HDSPM_wcLock) != 0 &&
Adrian Knothfedf1532011-06-12 17:26:18 +02001343 (status2 & HDSPM_SelSyncRef0) == 0) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02001344
1345 rate_bits = status2 & HDSPM_wcFreqMask;
1346
Adrian Knoth0dca1792011-01-26 19:32:14 +01001347
Remy Bruno3cee5a62006-10-16 12:46:32 +02001348 switch (rate_bits) {
1349 case HDSPM_wcFreq32:
1350 rate = 32000;
1351 break;
1352 case HDSPM_wcFreq44_1:
1353 rate = 44100;
1354 break;
1355 case HDSPM_wcFreq48:
1356 rate = 48000;
1357 break;
1358 case HDSPM_wcFreq64:
1359 rate = 64000;
1360 break;
1361 case HDSPM_wcFreq88_2:
1362 rate = 88200;
1363 break;
1364 case HDSPM_wcFreq96:
1365 rate = 96000;
1366 break;
Adrian Knotha8cd7142013-05-31 12:57:09 +02001367 case HDSPM_wcFreq128:
1368 rate = 128000;
1369 break;
1370 case HDSPM_wcFreq176_4:
1371 rate = 176400;
1372 break;
1373 case HDSPM_wcFreq192:
1374 rate = 192000;
1375 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001376 default:
1377 rate = 0;
1378 break;
1379 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001380 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001381
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001382 /* if rate detected and Syncref is Word than have it,
1383 * word has priority to MADI
1384 */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001385 if (rate != 0 &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01001386 (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
Adrian Knoth7b559392013-05-31 12:57:11 +02001387 return hdspm_rate_multiplier(hdspm, rate);
Remy Bruno3cee5a62006-10-16 12:46:32 +02001388
Adrian Knoth0dca1792011-01-26 19:32:14 +01001389 /* maybe a madi input (which is taken if sel sync is madi) */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001390 if (status & HDSPM_madiLock) {
1391 rate_bits = status & HDSPM_madiFreqMask;
1392
1393 switch (rate_bits) {
1394 case HDSPM_madiFreq32:
1395 rate = 32000;
1396 break;
1397 case HDSPM_madiFreq44_1:
1398 rate = 44100;
1399 break;
1400 case HDSPM_madiFreq48:
1401 rate = 48000;
1402 break;
1403 case HDSPM_madiFreq64:
1404 rate = 64000;
1405 break;
1406 case HDSPM_madiFreq88_2:
1407 rate = 88200;
1408 break;
1409 case HDSPM_madiFreq96:
1410 rate = 96000;
1411 break;
1412 case HDSPM_madiFreq128:
1413 rate = 128000;
1414 break;
1415 case HDSPM_madiFreq176_4:
1416 rate = 176400;
1417 break;
1418 case HDSPM_madiFreq192:
1419 rate = 192000;
1420 break;
1421 default:
1422 rate = 0;
1423 break;
1424 }
Adrian Knothd12c51d2011-07-29 03:11:03 +02001425
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001426 } /* endif HDSPM_madiLock */
1427
1428 /* check sample rate from TCO or SYNC_IN */
1429 {
1430 bool is_valid_input = 0;
1431 bool has_sync = 0;
1432
1433 syncref = hdspm_autosync_ref(hdspm);
1434 if (HDSPM_AUTOSYNC_FROM_TCO == syncref) {
1435 is_valid_input = 1;
1436 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1437 hdspm_tco_sync_check(hdspm));
1438 } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) {
1439 is_valid_input = 1;
1440 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1441 hdspm_sync_in_sync_check(hdspm));
Adrian Knothd12c51d2011-07-29 03:11:03 +02001442 }
Adrian Knothfcdc4ba2013-03-10 00:37:22 +01001443
1444 if (is_valid_input && has_sync) {
1445 rate = hdspm_round_frequency(
1446 hdspm_get_pll_freq(hdspm));
1447 }
1448 }
1449
Adrian Knotha8a729f2013-05-31 12:57:10 +02001450 rate = hdspm_rate_multiplier(hdspm, rate);
1451
Adrian Knoth0dca1792011-01-26 19:32:14 +01001452 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001453 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01001454
1455 return rate;
Takashi Iwai763f3562005-06-03 11:25:34 +02001456}
1457
Adrian Knoth7cb155f2011-08-15 00:22:53 +02001458/* return latency in samples per period */
1459static int hdspm_get_latency(struct hdspm *hdspm)
1460{
1461 int n;
1462
1463 n = hdspm_decode_latency(hdspm->control_register);
1464
1465 /* Special case for new RME cards with 32 samples period size.
1466 * The three latency bits in the control register
1467 * (HDSP_LatencyMask) encode latency values of 64 samples as
1468 * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
1469 * denotes 8192 samples, but on new cards like RayDAT or AIO,
1470 * it corresponds to 32 samples.
1471 */
1472 if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
1473 n = -1;
1474
1475 return 1 << (n + 6);
1476}
1477
Takashi Iwai763f3562005-06-03 11:25:34 +02001478/* Latency function */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001479static inline void hdspm_compute_period_size(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001480{
Adrian Knoth7cb155f2011-08-15 00:22:53 +02001481 hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001482}
1483
Adrian Knoth0dca1792011-01-26 19:32:14 +01001484
1485static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001486{
1487 int position;
1488
1489 position = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth483cee72011-02-23 11:43:09 +01001490
1491 switch (hdspm->io_type) {
1492 case RayDAT:
1493 case AIO:
1494 position &= HDSPM_BufferPositionMask;
1495 position /= 4; /* Bytes per sample */
1496 break;
1497 default:
1498 position = (position & HDSPM_BufferID) ?
1499 (hdspm->period_bytes / 4) : 0;
1500 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001501
1502 return position;
1503}
1504
1505
Takashi Iwai98274f02005-11-17 14:52:34 +01001506static inline void hdspm_start_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001507{
1508 s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
1509 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1510}
1511
Takashi Iwai98274f02005-11-17 14:52:34 +01001512static inline void hdspm_stop_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001513{
1514 s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
1515 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1516}
1517
1518/* should I silence all or only opened ones ? doit all for first even is 4MB*/
Denys Vlasenko62cef822008-04-14 13:04:18 +02001519static void hdspm_silence_playback(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001520{
1521 int i;
1522 int n = hdspm->period_bytes;
1523 void *buf = hdspm->playback_buffer;
1524
Remy Bruno3cee5a62006-10-16 12:46:32 +02001525 if (buf == NULL)
1526 return;
Takashi Iwai763f3562005-06-03 11:25:34 +02001527
1528 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
1529 memset(buf, 0, n);
1530 buf += HDSPM_CHANNEL_BUFFER_BYTES;
1531 }
1532}
1533
Adrian Knoth0dca1792011-01-26 19:32:14 +01001534static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
Takashi Iwai763f3562005-06-03 11:25:34 +02001535{
1536 int n;
1537
1538 spin_lock_irq(&s->lock);
1539
Adrian Knoth2e610272011-08-15 00:22:54 +02001540 if (32 == frames) {
1541 /* Special case for new RME cards like RayDAT/AIO which
1542 * support period sizes of 32 samples. Since latency is
1543 * encoded in the three bits of HDSP_LatencyMask, we can only
1544 * have values from 0 .. 7. While 0 still means 64 samples and
1545 * 6 represents 4096 samples on all cards, 7 represents 8192
1546 * on older cards and 32 samples on new cards.
1547 *
1548 * In other words, period size in samples is calculated by
1549 * 2^(n+6) with n ranging from 0 .. 7.
1550 */
1551 n = 7;
1552 } else {
1553 frames >>= 7;
1554 n = 0;
1555 while (frames) {
1556 n++;
1557 frames >>= 1;
1558 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001559 }
Adrian Knoth2e610272011-08-15 00:22:54 +02001560
Takashi Iwai763f3562005-06-03 11:25:34 +02001561 s->control_register &= ~HDSPM_LatencyMask;
1562 s->control_register |= hdspm_encode_latency(n);
1563
1564 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1565
1566 hdspm_compute_period_size(s);
1567
1568 spin_unlock_irq(&s->lock);
1569
1570 return 0;
1571}
1572
Adrian Knoth0dca1792011-01-26 19:32:14 +01001573static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
1574{
1575 u64 freq_const;
1576
1577 if (period == 0)
1578 return 0;
1579
1580 switch (hdspm->io_type) {
1581 case MADI:
1582 case AES32:
1583 freq_const = 110069313433624ULL;
1584 break;
1585 case RayDAT:
1586 case AIO:
1587 freq_const = 104857600000000ULL;
1588 break;
1589 case MADIface:
1590 freq_const = 131072000000000ULL;
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001591 break;
1592 default:
1593 snd_BUG();
1594 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001595 }
1596
1597 return div_u64(freq_const, period);
1598}
1599
1600
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001601static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
1602{
1603 u64 n;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001604
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001605 if (rate >= 112000)
1606 rate /= 4;
1607 else if (rate >= 56000)
1608 rate /= 2;
1609
Adrian Knoth0dca1792011-01-26 19:32:14 +01001610 switch (hdspm->io_type) {
1611 case MADIface:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001612 n = 131072000000000ULL; /* 125 MHz */
1613 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001614 case MADI:
1615 case AES32:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001616 n = 110069313433624ULL; /* 105 MHz */
1617 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001618 case RayDAT:
1619 case AIO:
Takashi Iwai3d56c8e2011-08-05 12:30:12 +02001620 n = 104857600000000ULL; /* 100 MHz */
1621 break;
1622 default:
1623 snd_BUG();
1624 return;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001625 }
1626
Takashi Iwai3f7440a2009-06-05 17:40:04 +02001627 n = div_u64(n, rate);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001628 /* n should be less than 2^32 for being written to FREQ register */
Takashi Iwaida3cec32008-08-08 17:12:14 +02001629 snd_BUG_ON(n >> 32);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001630 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
1631}
Takashi Iwai763f3562005-06-03 11:25:34 +02001632
1633/* dummy set rate lets see what happens */
Takashi Iwai98274f02005-11-17 14:52:34 +01001634static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
Takashi Iwai763f3562005-06-03 11:25:34 +02001635{
Takashi Iwai763f3562005-06-03 11:25:34 +02001636 int current_rate;
1637 int rate_bits;
1638 int not_set = 0;
Remy Bruno65345992007-08-31 12:21:08 +02001639 int current_speed, target_speed;
Takashi Iwai763f3562005-06-03 11:25:34 +02001640
1641 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
1642 it (e.g. during module initialization).
1643 */
1644
1645 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
1646
Adrian Knoth0dca1792011-01-26 19:32:14 +01001647 /* SLAVE --- */
Takashi Iwai763f3562005-06-03 11:25:34 +02001648 if (called_internally) {
1649
Adrian Knoth0dca1792011-01-26 19:32:14 +01001650 /* request from ctl or card initialization
1651 just make a warning an remember setting
1652 for future master mode switching */
1653
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001654 snd_printk(KERN_WARNING "HDSPM: "
1655 "Warning: device is not running "
1656 "as a clock master.\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001657 not_set = 1;
1658 } else {
1659
1660 /* hw_param request while in AutoSync mode */
1661 int external_freq =
1662 hdspm_external_sample_rate(hdspm);
1663
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001664 if (hdspm_autosync_ref(hdspm) ==
1665 HDSPM_AUTOSYNC_FROM_NONE) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001666
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001667 snd_printk(KERN_WARNING "HDSPM: "
1668 "Detected no Externel Sync \n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001669 not_set = 1;
1670
1671 } else if (rate != external_freq) {
1672
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001673 snd_printk(KERN_WARNING "HDSPM: "
1674 "Warning: No AutoSync source for "
1675 "requested rate\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001676 not_set = 1;
1677 }
1678 }
1679 }
1680
1681 current_rate = hdspm->system_sample_rate;
1682
1683 /* Changing between Singe, Double and Quad speed is not
1684 allowed if any substreams are open. This is because such a change
1685 causes a shift in the location of the DMA buffers and a reduction
1686 in the number of available buffers.
1687
1688 Note that a similar but essentially insoluble problem exists for
1689 externally-driven rate changes. All we can do is to flag rate
Adrian Knoth0dca1792011-01-26 19:32:14 +01001690 changes in the read/write routines.
Takashi Iwai763f3562005-06-03 11:25:34 +02001691 */
1692
Remy Bruno65345992007-08-31 12:21:08 +02001693 if (current_rate <= 48000)
1694 current_speed = HDSPM_SPEED_SINGLE;
1695 else if (current_rate <= 96000)
1696 current_speed = HDSPM_SPEED_DOUBLE;
1697 else
1698 current_speed = HDSPM_SPEED_QUAD;
1699
1700 if (rate <= 48000)
1701 target_speed = HDSPM_SPEED_SINGLE;
1702 else if (rate <= 96000)
1703 target_speed = HDSPM_SPEED_DOUBLE;
1704 else
1705 target_speed = HDSPM_SPEED_QUAD;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001706
Takashi Iwai763f3562005-06-03 11:25:34 +02001707 switch (rate) {
1708 case 32000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001709 rate_bits = HDSPM_Frequency32KHz;
1710 break;
1711 case 44100:
Takashi Iwai763f3562005-06-03 11:25:34 +02001712 rate_bits = HDSPM_Frequency44_1KHz;
1713 break;
1714 case 48000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001715 rate_bits = HDSPM_Frequency48KHz;
1716 break;
1717 case 64000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001718 rate_bits = HDSPM_Frequency64KHz;
1719 break;
1720 case 88200:
Takashi Iwai763f3562005-06-03 11:25:34 +02001721 rate_bits = HDSPM_Frequency88_2KHz;
1722 break;
1723 case 96000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001724 rate_bits = HDSPM_Frequency96KHz;
1725 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001726 case 128000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001727 rate_bits = HDSPM_Frequency128KHz;
1728 break;
1729 case 176400:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001730 rate_bits = HDSPM_Frequency176_4KHz;
1731 break;
1732 case 192000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001733 rate_bits = HDSPM_Frequency192KHz;
1734 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001735 default:
1736 return -EINVAL;
1737 }
1738
Remy Bruno65345992007-08-31 12:21:08 +02001739 if (current_speed != target_speed
Takashi Iwai763f3562005-06-03 11:25:34 +02001740 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
1741 snd_printk
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001742 (KERN_ERR "HDSPM: "
Remy Bruno65345992007-08-31 12:21:08 +02001743 "cannot change from %s speed to %s speed mode "
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001744 "(capture PID = %d, playback PID = %d)\n",
Remy Bruno65345992007-08-31 12:21:08 +02001745 hdspm_speed_names[current_speed],
1746 hdspm_speed_names[target_speed],
Takashi Iwai763f3562005-06-03 11:25:34 +02001747 hdspm->capture_pid, hdspm->playback_pid);
1748 return -EBUSY;
1749 }
1750
1751 hdspm->control_register &= ~HDSPM_FrequencyMask;
1752 hdspm->control_register |= rate_bits;
1753 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1754
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001755 /* For AES32, need to set DDS value in FREQ register
1756 For MADI, also apparently */
1757 hdspm_set_dds_value(hdspm, rate);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001758
1759 if (AES32 == hdspm->io_type && rate != current_rate)
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001760 hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
Takashi Iwai763f3562005-06-03 11:25:34 +02001761
1762 hdspm->system_sample_rate = rate;
1763
Adrian Knoth0dca1792011-01-26 19:32:14 +01001764 if (rate <= 48000) {
1765 hdspm->channel_map_in = hdspm->channel_map_in_ss;
1766 hdspm->channel_map_out = hdspm->channel_map_out_ss;
1767 hdspm->max_channels_in = hdspm->ss_in_channels;
1768 hdspm->max_channels_out = hdspm->ss_out_channels;
1769 hdspm->port_names_in = hdspm->port_names_in_ss;
1770 hdspm->port_names_out = hdspm->port_names_out_ss;
1771 } else if (rate <= 96000) {
1772 hdspm->channel_map_in = hdspm->channel_map_in_ds;
1773 hdspm->channel_map_out = hdspm->channel_map_out_ds;
1774 hdspm->max_channels_in = hdspm->ds_in_channels;
1775 hdspm->max_channels_out = hdspm->ds_out_channels;
1776 hdspm->port_names_in = hdspm->port_names_in_ds;
1777 hdspm->port_names_out = hdspm->port_names_out_ds;
1778 } else {
1779 hdspm->channel_map_in = hdspm->channel_map_in_qs;
1780 hdspm->channel_map_out = hdspm->channel_map_out_qs;
1781 hdspm->max_channels_in = hdspm->qs_in_channels;
1782 hdspm->max_channels_out = hdspm->qs_out_channels;
1783 hdspm->port_names_in = hdspm->port_names_in_qs;
1784 hdspm->port_names_out = hdspm->port_names_out_qs;
1785 }
1786
Takashi Iwai763f3562005-06-03 11:25:34 +02001787 if (not_set != 0)
1788 return -1;
1789
1790 return 0;
1791}
1792
1793/* mainly for init to 0 on load */
Takashi Iwai98274f02005-11-17 14:52:34 +01001794static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
Takashi Iwai763f3562005-06-03 11:25:34 +02001795{
1796 int i, j;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001797 unsigned int gain;
1798
1799 if (sgain > UNITY_GAIN)
1800 gain = UNITY_GAIN;
1801 else if (sgain < 0)
1802 gain = 0;
1803 else
1804 gain = sgain;
Takashi Iwai763f3562005-06-03 11:25:34 +02001805
1806 for (i = 0; i < HDSPM_MIXER_CHANNELS; i++)
1807 for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) {
1808 hdspm_write_in_gain(hdspm, i, j, gain);
1809 hdspm_write_pb_gain(hdspm, i, j, gain);
1810 }
1811}
1812
1813/*----------------------------------------------------------------------------
1814 MIDI
1815 ----------------------------------------------------------------------------*/
1816
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001817static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm,
1818 int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001819{
1820 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001821 return hdspm_read(hdspm, hdspm->midi[id].dataIn);
Takashi Iwai763f3562005-06-03 11:25:34 +02001822}
1823
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001824static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1825 int val)
Takashi Iwai763f3562005-06-03 11:25:34 +02001826{
1827 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001828 return hdspm_write(hdspm, hdspm->midi[id].dataOut, val);
Takashi Iwai763f3562005-06-03 11:25:34 +02001829}
1830
Takashi Iwai98274f02005-11-17 14:52:34 +01001831static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001832{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001833 return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001834}
1835
Takashi Iwai98274f02005-11-17 14:52:34 +01001836static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001837{
1838 int fifo_bytes_used;
1839
Adrian Knoth0dca1792011-01-26 19:32:14 +01001840 fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001841
1842 if (fifo_bytes_used < 128)
1843 return 128 - fifo_bytes_used;
1844 else
1845 return 0;
1846}
1847
Denys Vlasenko62cef822008-04-14 13:04:18 +02001848static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001849{
1850 while (snd_hdspm_midi_input_available (hdspm, id))
1851 snd_hdspm_midi_read_byte (hdspm, id);
1852}
1853
Takashi Iwai98274f02005-11-17 14:52:34 +01001854static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001855{
1856 unsigned long flags;
1857 int n_pending;
1858 int to_write;
1859 int i;
1860 unsigned char buf[128];
1861
1862 /* Output is not interrupt driven */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001863
Takashi Iwai763f3562005-06-03 11:25:34 +02001864 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001865 if (hmidi->output &&
1866 !snd_rawmidi_transmit_empty (hmidi->output)) {
1867 n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
1868 hmidi->id);
1869 if (n_pending > 0) {
1870 if (n_pending > (int)sizeof (buf))
1871 n_pending = sizeof (buf);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001872
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001873 to_write = snd_rawmidi_transmit (hmidi->output, buf,
1874 n_pending);
1875 if (to_write > 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001876 for (i = 0; i < to_write; ++i)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001877 snd_hdspm_midi_write_byte (hmidi->hdspm,
1878 hmidi->id,
1879 buf[i]);
Takashi Iwai763f3562005-06-03 11:25:34 +02001880 }
1881 }
1882 }
1883 spin_unlock_irqrestore (&hmidi->lock, flags);
1884 return 0;
1885}
1886
Takashi Iwai98274f02005-11-17 14:52:34 +01001887static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001888{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001889 unsigned char buf[128]; /* this buffer is designed to match the MIDI
1890 * input FIFO size
1891 */
Takashi Iwai763f3562005-06-03 11:25:34 +02001892 unsigned long flags;
1893 int n_pending;
1894 int i;
1895
1896 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001897 n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
1898 if (n_pending > 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001899 if (hmidi->input) {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001900 if (n_pending > (int)sizeof (buf))
Takashi Iwai763f3562005-06-03 11:25:34 +02001901 n_pending = sizeof (buf);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001902 for (i = 0; i < n_pending; ++i)
1903 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm,
1904 hmidi->id);
1905 if (n_pending)
1906 snd_rawmidi_receive (hmidi->input, buf,
1907 n_pending);
Takashi Iwai763f3562005-06-03 11:25:34 +02001908 } else {
1909 /* flush the MIDI input FIFO */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001910 while (n_pending--)
1911 snd_hdspm_midi_read_byte (hmidi->hdspm,
1912 hmidi->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02001913 }
1914 }
1915 hmidi->pending = 0;
Adrian Knothc0da0012011-06-12 17:26:17 +02001916 spin_unlock_irqrestore(&hmidi->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001917
Adrian Knothc0da0012011-06-12 17:26:17 +02001918 spin_lock_irqsave(&hmidi->hdspm->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001919 hmidi->hdspm->control_register |= hmidi->ie;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001920 hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
1921 hmidi->hdspm->control_register);
Adrian Knothc0da0012011-06-12 17:26:17 +02001922 spin_unlock_irqrestore(&hmidi->hdspm->lock, flags);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001923
Takashi Iwai763f3562005-06-03 11:25:34 +02001924 return snd_hdspm_midi_output_write (hmidi);
1925}
1926
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001927static void
1928snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001929{
Takashi Iwai98274f02005-11-17 14:52:34 +01001930 struct hdspm *hdspm;
1931 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001932 unsigned long flags;
Takashi Iwai763f3562005-06-03 11:25:34 +02001933
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001934 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001935 hdspm = hmidi->hdspm;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001936
Takashi Iwai763f3562005-06-03 11:25:34 +02001937 spin_lock_irqsave (&hdspm->lock, flags);
1938 if (up) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001939 if (!(hdspm->control_register & hmidi->ie)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001940 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001941 hdspm->control_register |= hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001942 }
1943 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001944 hdspm->control_register &= ~hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001945 }
1946
1947 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1948 spin_unlock_irqrestore (&hdspm->lock, flags);
1949}
1950
1951static void snd_hdspm_midi_output_timer(unsigned long data)
1952{
Takashi Iwai98274f02005-11-17 14:52:34 +01001953 struct hdspm_midi *hmidi = (struct hdspm_midi *) data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001954 unsigned long flags;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001955
Takashi Iwai763f3562005-06-03 11:25:34 +02001956 snd_hdspm_midi_output_write(hmidi);
1957 spin_lock_irqsave (&hmidi->lock, flags);
1958
1959 /* this does not bump hmidi->istimer, because the
1960 kernel automatically removed the timer when it
1961 expired, and we are now adding it back, thus
Adrian Knoth0dca1792011-01-26 19:32:14 +01001962 leaving istimer wherever it was set before.
Takashi Iwai763f3562005-06-03 11:25:34 +02001963 */
1964
1965 if (hmidi->istimer) {
1966 hmidi->timer.expires = 1 + jiffies;
1967 add_timer(&hmidi->timer);
1968 }
1969
1970 spin_unlock_irqrestore (&hmidi->lock, flags);
1971}
1972
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001973static void
1974snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001975{
Takashi Iwai98274f02005-11-17 14:52:34 +01001976 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001977 unsigned long flags;
1978
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001979 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001980 spin_lock_irqsave (&hmidi->lock, flags);
1981 if (up) {
1982 if (!hmidi->istimer) {
1983 init_timer(&hmidi->timer);
1984 hmidi->timer.function = snd_hdspm_midi_output_timer;
1985 hmidi->timer.data = (unsigned long) hmidi;
1986 hmidi->timer.expires = 1 + jiffies;
1987 add_timer(&hmidi->timer);
1988 hmidi->istimer++;
1989 }
1990 } else {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001991 if (hmidi->istimer && --hmidi->istimer <= 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02001992 del_timer (&hmidi->timer);
Takashi Iwai763f3562005-06-03 11:25:34 +02001993 }
1994 spin_unlock_irqrestore (&hmidi->lock, flags);
1995 if (up)
1996 snd_hdspm_midi_output_write(hmidi);
1997}
1998
Takashi Iwai98274f02005-11-17 14:52:34 +01001999static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02002000{
Takashi Iwai98274f02005-11-17 14:52:34 +01002001 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02002002
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002003 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02002004 spin_lock_irq (&hmidi->lock);
2005 snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
2006 hmidi->input = substream;
2007 spin_unlock_irq (&hmidi->lock);
2008
2009 return 0;
2010}
2011
Takashi Iwai98274f02005-11-17 14:52:34 +01002012static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02002013{
Takashi Iwai98274f02005-11-17 14:52:34 +01002014 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02002015
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002016 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02002017 spin_lock_irq (&hmidi->lock);
2018 hmidi->output = substream;
2019 spin_unlock_irq (&hmidi->lock);
2020
2021 return 0;
2022}
2023
Takashi Iwai98274f02005-11-17 14:52:34 +01002024static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02002025{
Takashi Iwai98274f02005-11-17 14:52:34 +01002026 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02002027
2028 snd_hdspm_midi_input_trigger (substream, 0);
2029
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002030 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02002031 spin_lock_irq (&hmidi->lock);
2032 hmidi->input = NULL;
2033 spin_unlock_irq (&hmidi->lock);
2034
2035 return 0;
2036}
2037
Takashi Iwai98274f02005-11-17 14:52:34 +01002038static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02002039{
Takashi Iwai98274f02005-11-17 14:52:34 +01002040 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02002041
2042 snd_hdspm_midi_output_trigger (substream, 0);
2043
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002044 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02002045 spin_lock_irq (&hmidi->lock);
2046 hmidi->output = NULL;
2047 spin_unlock_irq (&hmidi->lock);
2048
2049 return 0;
2050}
2051
Takashi Iwai98274f02005-11-17 14:52:34 +01002052static struct snd_rawmidi_ops snd_hdspm_midi_output =
Takashi Iwai763f3562005-06-03 11:25:34 +02002053{
2054 .open = snd_hdspm_midi_output_open,
2055 .close = snd_hdspm_midi_output_close,
2056 .trigger = snd_hdspm_midi_output_trigger,
2057};
2058
Takashi Iwai98274f02005-11-17 14:52:34 +01002059static struct snd_rawmidi_ops snd_hdspm_midi_input =
Takashi Iwai763f3562005-06-03 11:25:34 +02002060{
2061 .open = snd_hdspm_midi_input_open,
2062 .close = snd_hdspm_midi_input_close,
2063 .trigger = snd_hdspm_midi_input_trigger,
2064};
2065
Bill Pembertone23e7a12012-12-06 12:35:10 -05002066static int snd_hdspm_create_midi(struct snd_card *card,
2067 struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02002068{
2069 int err;
2070 char buf[32];
2071
2072 hdspm->midi[id].id = id;
Takashi Iwai763f3562005-06-03 11:25:34 +02002073 hdspm->midi[id].hdspm = hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +02002074 spin_lock_init (&hdspm->midi[id].lock);
2075
Adrian Knoth0dca1792011-01-26 19:32:14 +01002076 if (0 == id) {
2077 if (MADIface == hdspm->io_type) {
2078 /* MIDI-over-MADI on HDSPe MADIface */
2079 hdspm->midi[0].dataIn = HDSPM_midiDataIn2;
2080 hdspm->midi[0].statusIn = HDSPM_midiStatusIn2;
2081 hdspm->midi[0].dataOut = HDSPM_midiDataOut2;
2082 hdspm->midi[0].statusOut = HDSPM_midiStatusOut2;
2083 hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable;
2084 hdspm->midi[0].irq = HDSPM_midi2IRQPending;
2085 } else {
2086 hdspm->midi[0].dataIn = HDSPM_midiDataIn0;
2087 hdspm->midi[0].statusIn = HDSPM_midiStatusIn0;
2088 hdspm->midi[0].dataOut = HDSPM_midiDataOut0;
2089 hdspm->midi[0].statusOut = HDSPM_midiStatusOut0;
2090 hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable;
2091 hdspm->midi[0].irq = HDSPM_midi0IRQPending;
2092 }
2093 } else if (1 == id) {
2094 hdspm->midi[1].dataIn = HDSPM_midiDataIn1;
2095 hdspm->midi[1].statusIn = HDSPM_midiStatusIn1;
2096 hdspm->midi[1].dataOut = HDSPM_midiDataOut1;
2097 hdspm->midi[1].statusOut = HDSPM_midiStatusOut1;
2098 hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable;
2099 hdspm->midi[1].irq = HDSPM_midi1IRQPending;
2100 } else if ((2 == id) && (MADI == hdspm->io_type)) {
2101 /* MIDI-over-MADI on HDSPe MADI */
2102 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
2103 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
2104 hdspm->midi[2].dataOut = HDSPM_midiDataOut2;
2105 hdspm->midi[2].statusOut = HDSPM_midiStatusOut2;
2106 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
2107 hdspm->midi[2].irq = HDSPM_midi2IRQPending;
2108 } else if (2 == id) {
2109 /* TCO MTC, read only */
2110 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
2111 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
2112 hdspm->midi[2].dataOut = -1;
2113 hdspm->midi[2].statusOut = -1;
2114 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
2115 hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES;
2116 } else if (3 == id) {
2117 /* TCO MTC on HDSPe MADI */
2118 hdspm->midi[3].dataIn = HDSPM_midiDataIn3;
2119 hdspm->midi[3].statusIn = HDSPM_midiStatusIn3;
2120 hdspm->midi[3].dataOut = -1;
2121 hdspm->midi[3].statusOut = -1;
2122 hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable;
2123 hdspm->midi[3].irq = HDSPM_midi3IRQPending;
2124 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002125
Adrian Knoth0dca1792011-01-26 19:32:14 +01002126 if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) ||
2127 (MADIface == hdspm->io_type)))) {
2128 if ((id == 0) && (MADIface == hdspm->io_type)) {
2129 sprintf(buf, "%s MIDIoverMADI", card->shortname);
2130 } else if ((id == 2) && (MADI == hdspm->io_type)) {
2131 sprintf(buf, "%s MIDIoverMADI", card->shortname);
2132 } else {
2133 sprintf(buf, "%s MIDI %d", card->shortname, id+1);
2134 }
2135 err = snd_rawmidi_new(card, buf, id, 1, 1,
2136 &hdspm->midi[id].rmidi);
2137 if (err < 0)
2138 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02002139
Adrian Knoth0dca1792011-01-26 19:32:14 +01002140 sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d",
2141 card->id, id+1);
2142 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
Takashi Iwai763f3562005-06-03 11:25:34 +02002143
Adrian Knoth0dca1792011-01-26 19:32:14 +01002144 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2145 SNDRV_RAWMIDI_STREAM_OUTPUT,
2146 &snd_hdspm_midi_output);
2147 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2148 SNDRV_RAWMIDI_STREAM_INPUT,
2149 &snd_hdspm_midi_input);
2150
2151 hdspm->midi[id].rmidi->info_flags |=
2152 SNDRV_RAWMIDI_INFO_OUTPUT |
2153 SNDRV_RAWMIDI_INFO_INPUT |
2154 SNDRV_RAWMIDI_INFO_DUPLEX;
2155 } else {
2156 /* TCO MTC, read only */
2157 sprintf(buf, "%s MTC %d", card->shortname, id+1);
2158 err = snd_rawmidi_new(card, buf, id, 1, 1,
2159 &hdspm->midi[id].rmidi);
2160 if (err < 0)
2161 return err;
2162
2163 sprintf(hdspm->midi[id].rmidi->name,
2164 "%s MTC %d", card->id, id+1);
2165 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
2166
2167 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
2168 SNDRV_RAWMIDI_STREAM_INPUT,
2169 &snd_hdspm_midi_input);
2170
2171 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
2172 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002173
2174 return 0;
2175}
2176
2177
2178static void hdspm_midi_tasklet(unsigned long arg)
2179{
Takashi Iwai98274f02005-11-17 14:52:34 +01002180 struct hdspm *hdspm = (struct hdspm *)arg;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002181 int i = 0;
2182
2183 while (i < hdspm->midiPorts) {
2184 if (hdspm->midi[i].pending)
2185 snd_hdspm_midi_input_read(&hdspm->midi[i]);
2186
2187 i++;
2188 }
2189}
Takashi Iwai763f3562005-06-03 11:25:34 +02002190
2191
2192/*-----------------------------------------------------------------------------
2193 Status Interface
2194 ----------------------------------------------------------------------------*/
2195
2196/* get the system sample rate which is set */
2197
Adrian Knoth0dca1792011-01-26 19:32:14 +01002198
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002199static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
2200{
2201 unsigned int period, rate;
2202
2203 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
2204 rate = hdspm_calc_dds_value(hdspm, period);
2205
2206 return rate;
2207}
2208
Adrian Knoth0dca1792011-01-26 19:32:14 +01002209/**
2210 * Calculate the real sample rate from the
2211 * current DDS value.
2212 **/
2213static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
2214{
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002215 unsigned int rate;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002216
Adrian Knoth3f7bf912013-03-10 00:37:21 +01002217 rate = hdspm_get_pll_freq(hdspm);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002218
Adrian Knotha97bda72012-05-30 14:23:18 +02002219 if (rate > 207000) {
Adrian Knoth21a164d2012-10-19 17:42:23 +02002220 /* Unreasonable high sample rate as seen on PCI MADI cards. */
2221 if (0 == hdspm_system_clock_mode(hdspm)) {
2222 /* master mode, return internal sample rate */
2223 rate = hdspm->system_sample_rate;
2224 } else {
2225 /* slave mode, return external sample rate */
2226 rate = hdspm_external_sample_rate(hdspm);
2227 }
Adrian Knotha97bda72012-05-30 14:23:18 +02002228 }
2229
Adrian Knoth0dca1792011-01-26 19:32:14 +01002230 return rate;
2231}
2232
2233
Takashi Iwai763f3562005-06-03 11:25:34 +02002234#define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02002235{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2236 .name = xname, \
2237 .index = xindex, \
2238 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2239 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2240 .info = snd_hdspm_info_system_sample_rate, \
2241 .put = snd_hdspm_put_system_sample_rate, \
2242 .get = snd_hdspm_get_system_sample_rate \
Takashi Iwai763f3562005-06-03 11:25:34 +02002243}
2244
Takashi Iwai98274f02005-11-17 14:52:34 +01002245static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol,
2246 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002247{
2248 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2249 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002250 uinfo->value.integer.min = 27000;
2251 uinfo->value.integer.max = 207000;
2252 uinfo->value.integer.step = 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002253 return 0;
2254}
2255
Adrian Knoth0dca1792011-01-26 19:32:14 +01002256
Takashi Iwai98274f02005-11-17 14:52:34 +01002257static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol,
2258 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02002259 ucontrol)
2260{
Takashi Iwai98274f02005-11-17 14:52:34 +01002261 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002262
Adrian Knoth0dca1792011-01-26 19:32:14 +01002263 ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002264 return 0;
2265}
2266
Adrian Knoth41285a92012-10-19 17:42:22 +02002267static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
2268 struct snd_ctl_elem_value *
2269 ucontrol)
2270{
2271 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2272
2273 hdspm_set_dds_value(hdspm, ucontrol->value.enumerated.item[0]);
2274 return 0;
2275}
2276
Adrian Knoth0dca1792011-01-26 19:32:14 +01002277
2278/**
2279 * Returns the WordClock sample rate class for the given card.
2280 **/
2281static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
2282{
2283 int status;
2284
2285 switch (hdspm->io_type) {
2286 case RayDAT:
2287 case AIO:
2288 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2289 return (status >> 16) & 0xF;
2290 break;
Adrian Knotha57fea82013-07-05 11:28:11 +02002291 case AES32:
2292 status = hdspm_read(hdspm, HDSPM_statusRegister);
2293 return (status >> HDSPM_AES32_wcFreq_bit) & 0xF;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002294 default:
2295 break;
2296 }
2297
2298
2299 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002300}
2301
Adrian Knoth0dca1792011-01-26 19:32:14 +01002302
2303/**
2304 * Returns the TCO sample rate class for the given card.
2305 **/
2306static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
2307{
2308 int status;
2309
2310 if (hdspm->tco) {
2311 switch (hdspm->io_type) {
2312 case RayDAT:
2313 case AIO:
2314 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2315 return (status >> 20) & 0xF;
2316 break;
Adrian Knoth051c44f2013-07-05 11:28:12 +02002317 case AES32:
2318 status = hdspm_read(hdspm, HDSPM_statusRegister);
2319 return (status >> 1) & 0xF;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002320 default:
2321 break;
2322 }
2323 }
2324
2325 return 0;
2326}
2327
2328
2329/**
2330 * Returns the SYNC_IN sample rate class for the given card.
2331 **/
2332static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2333{
2334 int status;
2335
2336 if (hdspm->tco) {
2337 switch (hdspm->io_type) {
2338 case RayDAT:
2339 case AIO:
2340 status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2341 return (status >> 12) & 0xF;
2342 break;
2343 default:
2344 break;
2345 }
2346 }
2347
2348 return 0;
2349}
2350
Adrian Knothd3c36ed2013-07-05 11:28:09 +02002351/**
2352 * Returns the AES sample rate class for the given card.
2353 **/
2354static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index)
2355{
2356 int timecode;
2357
2358 switch (hdspm->io_type) {
2359 case AES32:
2360 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
2361 return (timecode >> (4*index)) & 0xF;
2362 break;
2363 default:
2364 break;
2365 }
2366 return 0;
2367}
Adrian Knoth0dca1792011-01-26 19:32:14 +01002368
2369/**
2370 * Returns the sample rate class for input source <idx> for
2371 * 'new style' cards like the AIO and RayDAT.
2372 **/
2373static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2374{
2375 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2376
2377 return (status >> (idx*4)) & 0xF;
2378}
2379
Adrian Knoth8cea5712013-07-05 11:27:59 +02002380#define ENUMERATED_CTL_INFO(info, texts) \
Adrian Knoth38816542013-07-05 11:28:20 +02002381 snd_ctl_enum_info(info, 1, ARRAY_SIZE(texts), texts)
Adrian Knoth8cea5712013-07-05 11:27:59 +02002382
Adrian Knoth0dca1792011-01-26 19:32:14 +01002383
Adrian Knoth23361422013-07-05 11:28:17 +02002384/* Helper function to query the external sample rate and return the
2385 * corresponding enum to be returned to userspace.
2386 */
2387static int hdspm_external_rate_to_enum(struct hdspm *hdspm)
2388{
2389 int rate = hdspm_external_sample_rate(hdspm);
2390 int i, selected_rate = 0;
2391 for (i = 1; i < 10; i++)
2392 if (HDSPM_bit2freq(i) == rate) {
2393 selected_rate = i;
2394 break;
2395 }
2396 return selected_rate;
2397}
2398
Adrian Knoth0dca1792011-01-26 19:32:14 +01002399
2400#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
2401{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2402 .name = xname, \
2403 .private_value = xindex, \
2404 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2405 .info = snd_hdspm_info_autosync_sample_rate, \
2406 .get = snd_hdspm_get_autosync_sample_rate \
2407}
2408
2409
Takashi Iwai98274f02005-11-17 14:52:34 +01002410static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2411 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002412{
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01002413 ENUMERATED_CTL_INFO(uinfo, texts_freq);
Takashi Iwai763f3562005-06-03 11:25:34 +02002414 return 0;
2415}
2416
Adrian Knoth0dca1792011-01-26 19:32:14 +01002417
Takashi Iwai98274f02005-11-17 14:52:34 +01002418static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2419 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02002420 ucontrol)
2421{
Takashi Iwai98274f02005-11-17 14:52:34 +01002422 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002423
Adrian Knoth0dca1792011-01-26 19:32:14 +01002424 switch (hdspm->io_type) {
2425 case RayDAT:
2426 switch (kcontrol->private_value) {
2427 case 0:
2428 ucontrol->value.enumerated.item[0] =
2429 hdspm_get_wc_sample_rate(hdspm);
2430 break;
2431 case 7:
2432 ucontrol->value.enumerated.item[0] =
2433 hdspm_get_tco_sample_rate(hdspm);
2434 break;
2435 case 8:
2436 ucontrol->value.enumerated.item[0] =
2437 hdspm_get_sync_in_sample_rate(hdspm);
2438 break;
2439 default:
2440 ucontrol->value.enumerated.item[0] =
2441 hdspm_get_s1_sample_rate(hdspm,
2442 kcontrol->private_value-1);
2443 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002444 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002445
Adrian Knoth0dca1792011-01-26 19:32:14 +01002446 case AIO:
2447 switch (kcontrol->private_value) {
2448 case 0: /* WC */
2449 ucontrol->value.enumerated.item[0] =
2450 hdspm_get_wc_sample_rate(hdspm);
2451 break;
2452 case 4: /* TCO */
2453 ucontrol->value.enumerated.item[0] =
2454 hdspm_get_tco_sample_rate(hdspm);
2455 break;
2456 case 5: /* SYNC_IN */
2457 ucontrol->value.enumerated.item[0] =
2458 hdspm_get_sync_in_sample_rate(hdspm);
2459 break;
2460 default:
2461 ucontrol->value.enumerated.item[0] =
2462 hdspm_get_s1_sample_rate(hdspm,
Adrian Knoth1cb7dbf2013-07-05 11:28:03 +02002463 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002464 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002465 break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002466
2467 case AES32:
2468
2469 switch (kcontrol->private_value) {
2470 case 0: /* WC */
2471 ucontrol->value.enumerated.item[0] =
2472 hdspm_get_wc_sample_rate(hdspm);
2473 break;
2474 case 9: /* TCO */
2475 ucontrol->value.enumerated.item[0] =
2476 hdspm_get_tco_sample_rate(hdspm);
2477 break;
2478 case 10: /* SYNC_IN */
2479 ucontrol->value.enumerated.item[0] =
2480 hdspm_get_sync_in_sample_rate(hdspm);
2481 break;
Adrian Knoth2d63ec32013-07-05 11:28:18 +02002482 case 11: /* External Rate */
2483 ucontrol->value.enumerated.item[0] =
2484 hdspm_external_rate_to_enum(hdspm);
2485 break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002486 default: /* AES1 to AES8 */
2487 ucontrol->value.enumerated.item[0] =
Adrian Knoth2d63ec32013-07-05 11:28:18 +02002488 hdspm_get_aes_sample_rate(hdspm,
2489 kcontrol->private_value -
2490 HDSPM_AES32_AUTOSYNC_FROM_AES1);
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002491 break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01002492 }
Adrian Knothd681dea2012-10-19 17:42:25 +02002493 break;
Adrian Knothb8812c52012-10-19 17:42:26 +02002494
2495 case MADI:
2496 case MADIface:
Adrian Knoth23361422013-07-05 11:28:17 +02002497 ucontrol->value.enumerated.item[0] =
2498 hdspm_external_rate_to_enum(hdspm);
Adrian Knothb8812c52012-10-19 17:42:26 +02002499 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002500 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002501 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002502 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002503
Takashi Iwai763f3562005-06-03 11:25:34 +02002504 return 0;
2505}
2506
Adrian Knoth0dca1792011-01-26 19:32:14 +01002507
Takashi Iwai763f3562005-06-03 11:25:34 +02002508#define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002509{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2510 .name = xname, \
2511 .index = xindex, \
2512 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2513 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2514 .info = snd_hdspm_info_system_clock_mode, \
2515 .get = snd_hdspm_get_system_clock_mode, \
2516 .put = snd_hdspm_put_system_clock_mode, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002517}
2518
2519
Adrian Knoth0dca1792011-01-26 19:32:14 +01002520/**
2521 * Returns the system clock mode for the given card.
2522 * @returns 0 - master, 1 - slave
2523 **/
2524static int hdspm_system_clock_mode(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002525{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002526 switch (hdspm->io_type) {
2527 case AIO:
2528 case RayDAT:
2529 if (hdspm->settings_register & HDSPM_c0Master)
2530 return 0;
2531 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002532
Adrian Knoth0dca1792011-01-26 19:32:14 +01002533 default:
2534 if (hdspm->control_register & HDSPM_ClockModeMaster)
2535 return 0;
2536 }
2537
Takashi Iwai763f3562005-06-03 11:25:34 +02002538 return 1;
2539}
2540
Adrian Knoth0dca1792011-01-26 19:32:14 +01002541
2542/**
2543 * Sets the system clock mode.
2544 * @param mode 0 - master, 1 - slave
2545 **/
2546static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
2547{
Adrian Knoth34be7eb2013-07-05 11:27:56 +02002548 hdspm_set_toggle_setting(hdspm,
2549 (hdspm_is_raydat_or_aio(hdspm)) ?
2550 HDSPM_c0Master : HDSPM_ClockModeMaster,
2551 (0 == mode));
Adrian Knoth0dca1792011-01-26 19:32:14 +01002552}
2553
2554
Takashi Iwai98274f02005-11-17 14:52:34 +01002555static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
2556 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002557{
Adrian Knoth38816542013-07-05 11:28:20 +02002558 static const char *const texts[] = { "Master", "AutoSync" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01002559 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02002560 return 0;
2561}
2562
Takashi Iwai98274f02005-11-17 14:52:34 +01002563static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol,
2564 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002565{
Takashi Iwai98274f02005-11-17 14:52:34 +01002566 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002567
Adrian Knoth0dca1792011-01-26 19:32:14 +01002568 ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002569 return 0;
2570}
2571
Adrian Knoth0dca1792011-01-26 19:32:14 +01002572static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol,
2573 struct snd_ctl_elem_value *ucontrol)
2574{
2575 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2576 int val;
2577
2578 if (!snd_hdspm_use_is_exclusive(hdspm))
2579 return -EBUSY;
2580
2581 val = ucontrol->value.enumerated.item[0];
2582 if (val < 0)
2583 val = 0;
2584 else if (val > 1)
2585 val = 1;
2586
2587 hdspm_set_system_clock_mode(hdspm, val);
2588
2589 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002590}
2591
Adrian Knoth0dca1792011-01-26 19:32:14 +01002592
2593#define HDSPM_INTERNAL_CLOCK(xname, xindex) \
2594{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2595 .name = xname, \
2596 .index = xindex, \
2597 .info = snd_hdspm_info_clock_source, \
2598 .get = snd_hdspm_get_clock_source, \
2599 .put = snd_hdspm_put_clock_source \
2600}
2601
2602
Takashi Iwai98274f02005-11-17 14:52:34 +01002603static int hdspm_clock_source(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002604{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002605 switch (hdspm->system_sample_rate) {
2606 case 32000: return 0;
2607 case 44100: return 1;
2608 case 48000: return 2;
2609 case 64000: return 3;
2610 case 88200: return 4;
2611 case 96000: return 5;
2612 case 128000: return 6;
2613 case 176400: return 7;
2614 case 192000: return 8;
Takashi Iwai763f3562005-06-03 11:25:34 +02002615 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002616
2617 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002618}
2619
Takashi Iwai98274f02005-11-17 14:52:34 +01002620static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
Takashi Iwai763f3562005-06-03 11:25:34 +02002621{
2622 int rate;
2623 switch (mode) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002624 case 0:
2625 rate = 32000; break;
2626 case 1:
2627 rate = 44100; break;
2628 case 2:
2629 rate = 48000; break;
2630 case 3:
2631 rate = 64000; break;
2632 case 4:
2633 rate = 88200; break;
2634 case 5:
2635 rate = 96000; break;
2636 case 6:
2637 rate = 128000; break;
2638 case 7:
2639 rate = 176400; break;
2640 case 8:
2641 rate = 192000; break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002642 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002643 rate = 48000;
Takashi Iwai763f3562005-06-03 11:25:34 +02002644 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002645 hdspm_set_rate(hdspm, rate, 1);
2646 return 0;
2647}
2648
Takashi Iwai98274f02005-11-17 14:52:34 +01002649static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
2650 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002651{
Takashi Iwai763f3562005-06-03 11:25:34 +02002652 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2653 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002654 uinfo->value.enumerated.items = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002655
2656 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2657 uinfo->value.enumerated.item =
2658 uinfo->value.enumerated.items - 1;
2659
2660 strcpy(uinfo->value.enumerated.name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01002661 texts_freq[uinfo->value.enumerated.item+1]);
Takashi Iwai763f3562005-06-03 11:25:34 +02002662
2663 return 0;
2664}
2665
Takashi Iwai98274f02005-11-17 14:52:34 +01002666static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
2667 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002668{
Takashi Iwai98274f02005-11-17 14:52:34 +01002669 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002670
2671 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
2672 return 0;
2673}
2674
Takashi Iwai98274f02005-11-17 14:52:34 +01002675static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
2676 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002677{
Takashi Iwai98274f02005-11-17 14:52:34 +01002678 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002679 int change;
2680 int val;
2681
2682 if (!snd_hdspm_use_is_exclusive(hdspm))
2683 return -EBUSY;
2684 val = ucontrol->value.enumerated.item[0];
2685 if (val < 0)
2686 val = 0;
Remy Bruno65345992007-08-31 12:21:08 +02002687 if (val > 9)
2688 val = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002689 spin_lock_irq(&hdspm->lock);
2690 if (val != hdspm_clock_source(hdspm))
2691 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
2692 else
2693 change = 0;
2694 spin_unlock_irq(&hdspm->lock);
2695 return change;
2696}
2697
Adrian Knoth0dca1792011-01-26 19:32:14 +01002698
Takashi Iwai763f3562005-06-03 11:25:34 +02002699#define HDSPM_PREF_SYNC_REF(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02002700{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002701 .name = xname, \
2702 .index = xindex, \
2703 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2704 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2705 .info = snd_hdspm_info_pref_sync_ref, \
2706 .get = snd_hdspm_get_pref_sync_ref, \
2707 .put = snd_hdspm_put_pref_sync_ref \
Takashi Iwai763f3562005-06-03 11:25:34 +02002708}
2709
Adrian Knoth0dca1792011-01-26 19:32:14 +01002710
2711/**
2712 * Returns the current preferred sync reference setting.
2713 * The semantics of the return value are depending on the
2714 * card, please see the comments for clarification.
2715 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002716static int hdspm_pref_sync_ref(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002717{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002718 switch (hdspm->io_type) {
2719 case AES32:
Remy Bruno3cee5a62006-10-16 12:46:32 +02002720 switch (hdspm->control_register & HDSPM_SyncRefMask) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002721 case 0: return 0; /* WC */
2722 case HDSPM_SyncRef0: return 1; /* AES 1 */
2723 case HDSPM_SyncRef1: return 2; /* AES 2 */
2724 case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */
2725 case HDSPM_SyncRef2: return 4; /* AES 4 */
2726 case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */
2727 case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */
2728 case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0:
2729 return 7; /* AES 7 */
2730 case HDSPM_SyncRef3: return 8; /* AES 8 */
2731 case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002732 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002733 break;
2734
2735 case MADI:
2736 case MADIface:
2737 if (hdspm->tco) {
2738 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2739 case 0: return 0; /* WC */
2740 case HDSPM_SyncRef0: return 1; /* MADI */
2741 case HDSPM_SyncRef1: return 2; /* TCO */
2742 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2743 return 3; /* SYNC_IN */
2744 }
2745 } else {
2746 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2747 case 0: return 0; /* WC */
2748 case HDSPM_SyncRef0: return 1; /* MADI */
2749 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2750 return 2; /* SYNC_IN */
2751 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02002752 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002753 break;
2754
2755 case RayDAT:
2756 if (hdspm->tco) {
2757 switch ((hdspm->settings_register &
2758 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2759 case 0: return 0; /* WC */
2760 case 3: return 1; /* ADAT 1 */
2761 case 4: return 2; /* ADAT 2 */
2762 case 5: return 3; /* ADAT 3 */
2763 case 6: return 4; /* ADAT 4 */
2764 case 1: return 5; /* AES */
2765 case 2: return 6; /* SPDIF */
2766 case 9: return 7; /* TCO */
2767 case 10: return 8; /* SYNC_IN */
2768 }
2769 } else {
2770 switch ((hdspm->settings_register &
2771 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2772 case 0: return 0; /* WC */
2773 case 3: return 1; /* ADAT 1 */
2774 case 4: return 2; /* ADAT 2 */
2775 case 5: return 3; /* ADAT 3 */
2776 case 6: return 4; /* ADAT 4 */
2777 case 1: return 5; /* AES */
2778 case 2: return 6; /* SPDIF */
2779 case 10: return 7; /* SYNC_IN */
2780 }
2781 }
2782
2783 break;
2784
2785 case AIO:
2786 if (hdspm->tco) {
2787 switch ((hdspm->settings_register &
2788 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2789 case 0: return 0; /* WC */
2790 case 3: return 1; /* ADAT */
2791 case 1: return 2; /* AES */
2792 case 2: return 3; /* SPDIF */
2793 case 9: return 4; /* TCO */
2794 case 10: return 5; /* SYNC_IN */
2795 }
2796 } else {
2797 switch ((hdspm->settings_register &
2798 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2799 case 0: return 0; /* WC */
2800 case 3: return 1; /* ADAT */
2801 case 1: return 2; /* AES */
2802 case 2: return 3; /* SPDIF */
2803 case 10: return 4; /* SYNC_IN */
2804 }
2805 }
2806
2807 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002808 }
2809
Adrian Knoth0dca1792011-01-26 19:32:14 +01002810 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002811}
2812
Adrian Knoth0dca1792011-01-26 19:32:14 +01002813
2814/**
2815 * Set the preferred sync reference to <pref>. The semantics
2816 * of <pref> are depending on the card type, see the comments
2817 * for clarification.
2818 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002819static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
Takashi Iwai763f3562005-06-03 11:25:34 +02002820{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002821 int p = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002822
Adrian Knoth0dca1792011-01-26 19:32:14 +01002823 switch (hdspm->io_type) {
2824 case AES32:
2825 hdspm->control_register &= ~HDSPM_SyncRefMask;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002826 switch (pref) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002827 case 0: /* WC */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002828 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002829 case 1: /* AES 1 */
2830 hdspm->control_register |= HDSPM_SyncRef0;
2831 break;
2832 case 2: /* AES 2 */
2833 hdspm->control_register |= HDSPM_SyncRef1;
2834 break;
2835 case 3: /* AES 3 */
2836 hdspm->control_register |=
2837 HDSPM_SyncRef1+HDSPM_SyncRef0;
2838 break;
2839 case 4: /* AES 4 */
2840 hdspm->control_register |= HDSPM_SyncRef2;
2841 break;
2842 case 5: /* AES 5 */
2843 hdspm->control_register |=
2844 HDSPM_SyncRef2+HDSPM_SyncRef0;
2845 break;
2846 case 6: /* AES 6 */
2847 hdspm->control_register |=
2848 HDSPM_SyncRef2+HDSPM_SyncRef1;
2849 break;
2850 case 7: /* AES 7 */
2851 hdspm->control_register |=
2852 HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
2853 break;
2854 case 8: /* AES 8 */
2855 hdspm->control_register |= HDSPM_SyncRef3;
2856 break;
2857 case 9: /* TCO */
2858 hdspm->control_register |=
2859 HDSPM_SyncRef3+HDSPM_SyncRef0;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002860 break;
2861 default:
2862 return -1;
2863 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002864
2865 break;
2866
2867 case MADI:
2868 case MADIface:
2869 hdspm->control_register &= ~HDSPM_SyncRefMask;
2870 if (hdspm->tco) {
2871 switch (pref) {
2872 case 0: /* WC */
2873 break;
2874 case 1: /* MADI */
2875 hdspm->control_register |= HDSPM_SyncRef0;
2876 break;
2877 case 2: /* TCO */
2878 hdspm->control_register |= HDSPM_SyncRef1;
2879 break;
2880 case 3: /* SYNC_IN */
2881 hdspm->control_register |=
2882 HDSPM_SyncRef0+HDSPM_SyncRef1;
2883 break;
2884 default:
2885 return -1;
2886 }
2887 } else {
2888 switch (pref) {
2889 case 0: /* WC */
2890 break;
2891 case 1: /* MADI */
2892 hdspm->control_register |= HDSPM_SyncRef0;
2893 break;
2894 case 2: /* SYNC_IN */
2895 hdspm->control_register |=
2896 HDSPM_SyncRef0+HDSPM_SyncRef1;
2897 break;
2898 default:
2899 return -1;
2900 }
2901 }
2902
2903 break;
2904
2905 case RayDAT:
2906 if (hdspm->tco) {
2907 switch (pref) {
2908 case 0: p = 0; break; /* WC */
2909 case 1: p = 3; break; /* ADAT 1 */
2910 case 2: p = 4; break; /* ADAT 2 */
2911 case 3: p = 5; break; /* ADAT 3 */
2912 case 4: p = 6; break; /* ADAT 4 */
2913 case 5: p = 1; break; /* AES */
2914 case 6: p = 2; break; /* SPDIF */
2915 case 7: p = 9; break; /* TCO */
2916 case 8: p = 10; break; /* SYNC_IN */
2917 default: return -1;
2918 }
2919 } else {
2920 switch (pref) {
2921 case 0: p = 0; break; /* WC */
2922 case 1: p = 3; break; /* ADAT 1 */
2923 case 2: p = 4; break; /* ADAT 2 */
2924 case 3: p = 5; break; /* ADAT 3 */
2925 case 4: p = 6; break; /* ADAT 4 */
2926 case 5: p = 1; break; /* AES */
2927 case 6: p = 2; break; /* SPDIF */
2928 case 7: p = 10; break; /* SYNC_IN */
2929 default: return -1;
2930 }
2931 }
2932 break;
2933
2934 case AIO:
2935 if (hdspm->tco) {
2936 switch (pref) {
2937 case 0: p = 0; break; /* WC */
2938 case 1: p = 3; break; /* ADAT */
2939 case 2: p = 1; break; /* AES */
2940 case 3: p = 2; break; /* SPDIF */
2941 case 4: p = 9; break; /* TCO */
2942 case 5: p = 10; break; /* SYNC_IN */
2943 default: return -1;
2944 }
2945 } else {
2946 switch (pref) {
2947 case 0: p = 0; break; /* WC */
2948 case 1: p = 3; break; /* ADAT */
2949 case 2: p = 1; break; /* AES */
2950 case 3: p = 2; break; /* SPDIF */
2951 case 4: p = 10; break; /* SYNC_IN */
2952 default: return -1;
2953 }
2954 }
2955 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002956 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002957
2958 switch (hdspm->io_type) {
2959 case RayDAT:
2960 case AIO:
2961 hdspm->settings_register &= ~HDSPM_c0_SyncRefMask;
2962 hdspm->settings_register |= HDSPM_c0_SyncRef0 * p;
2963 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
2964 break;
2965
2966 case MADI:
2967 case MADIface:
2968 case AES32:
2969 hdspm_write(hdspm, HDSPM_controlRegister,
2970 hdspm->control_register);
2971 }
2972
Takashi Iwai763f3562005-06-03 11:25:34 +02002973 return 0;
2974}
2975
Adrian Knoth0dca1792011-01-26 19:32:14 +01002976
Takashi Iwai98274f02005-11-17 14:52:34 +01002977static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol,
2978 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002979{
Remy Bruno3cee5a62006-10-16 12:46:32 +02002980 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002981
Adrian Knotheb0d4db2013-07-05 11:28:21 +02002982 snd_ctl_enum_info(uinfo, 1, hdspm->texts_autosync_items, hdspm->texts_autosync);
Remy Bruno3cee5a62006-10-16 12:46:32 +02002983
Takashi Iwai763f3562005-06-03 11:25:34 +02002984 return 0;
2985}
2986
Takashi Iwai98274f02005-11-17 14:52:34 +01002987static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol,
2988 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002989{
Takashi Iwai98274f02005-11-17 14:52:34 +01002990 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002991 int psf = hdspm_pref_sync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002992
Adrian Knoth0dca1792011-01-26 19:32:14 +01002993 if (psf >= 0) {
2994 ucontrol->value.enumerated.item[0] = psf;
2995 return 0;
2996 }
2997
2998 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002999}
3000
Takashi Iwai98274f02005-11-17 14:52:34 +01003001static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,
3002 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003003{
Takashi Iwai98274f02005-11-17 14:52:34 +01003004 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01003005 int val, change = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02003006
3007 if (!snd_hdspm_use_is_exclusive(hdspm))
3008 return -EBUSY;
3009
Adrian Knoth0dca1792011-01-26 19:32:14 +01003010 val = ucontrol->value.enumerated.item[0];
3011
3012 if (val < 0)
3013 val = 0;
3014 else if (val >= hdspm->texts_autosync_items)
3015 val = hdspm->texts_autosync_items-1;
Takashi Iwai763f3562005-06-03 11:25:34 +02003016
3017 spin_lock_irq(&hdspm->lock);
Adrian Knoth0dca1792011-01-26 19:32:14 +01003018 if (val != hdspm_pref_sync_ref(hdspm))
3019 change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0;
3020
Takashi Iwai763f3562005-06-03 11:25:34 +02003021 spin_unlock_irq(&hdspm->lock);
3022 return change;
3023}
3024
Adrian Knoth0dca1792011-01-26 19:32:14 +01003025
Takashi Iwai763f3562005-06-03 11:25:34 +02003026#define HDSPM_AUTOSYNC_REF(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003027{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3028 .name = xname, \
3029 .index = xindex, \
3030 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
3031 .info = snd_hdspm_info_autosync_ref, \
3032 .get = snd_hdspm_get_autosync_ref, \
Takashi Iwai763f3562005-06-03 11:25:34 +02003033}
3034
Adrian Knoth0dca1792011-01-26 19:32:14 +01003035static int hdspm_autosync_ref(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003036{
Adrian Knoth2d60fc72013-07-05 11:28:15 +02003037 /* This looks at the autosync selected sync reference */
Adrian Knoth0dca1792011-01-26 19:32:14 +01003038 if (AES32 == hdspm->io_type) {
Takashi Iwai763f3562005-06-03 11:25:34 +02003039
Adrian Knoth2d60fc72013-07-05 11:28:15 +02003040 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
3041 unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF;
3042 if ((syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD) &&
3043 (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN)) {
3044 return syncref;
3045 }
3046 return HDSPM_AES32_AUTOSYNC_FROM_NONE;
3047
3048 } else if (MADI == hdspm->io_type) {
3049
3050 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003051 switch (status2 & HDSPM_SelSyncRefMask) {
3052 case HDSPM_SelSyncRef_WORD:
3053 return HDSPM_AUTOSYNC_FROM_WORD;
3054 case HDSPM_SelSyncRef_MADI:
3055 return HDSPM_AUTOSYNC_FROM_MADI;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003056 case HDSPM_SelSyncRef_TCO:
3057 return HDSPM_AUTOSYNC_FROM_TCO;
3058 case HDSPM_SelSyncRef_SyncIn:
3059 return HDSPM_AUTOSYNC_FROM_SYNC_IN;
Remy Bruno3cee5a62006-10-16 12:46:32 +02003060 case HDSPM_SelSyncRef_NVALID:
3061 return HDSPM_AUTOSYNC_FROM_NONE;
3062 default:
Adrian Knothe71b95a2013-07-05 11:28:06 +02003063 return HDSPM_AUTOSYNC_FROM_NONE;
Remy Bruno3cee5a62006-10-16 12:46:32 +02003064 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003065
Takashi Iwai763f3562005-06-03 11:25:34 +02003066 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01003067 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02003068}
3069
Adrian Knoth0dca1792011-01-26 19:32:14 +01003070
Takashi Iwai98274f02005-11-17 14:52:34 +01003071static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol,
3072 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003073{
Remy Bruno3cee5a62006-10-16 12:46:32 +02003074 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003075
Adrian Knoth0dca1792011-01-26 19:32:14 +01003076 if (AES32 == hdspm->io_type) {
Adrian Knoth04659f92013-07-05 11:28:22 +02003077 static const char *const texts[] = { "WordClock", "AES1", "AES2", "AES3",
Adrian Knothdb2d1a92013-07-05 11:28:08 +02003078 "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In", "None"};
Remy Bruno3cee5a62006-10-16 12:46:32 +02003079
Adrian Knoth04659f92013-07-05 11:28:22 +02003080 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01003081 } else if (MADI == hdspm->io_type) {
Adrian Knoth04659f92013-07-05 11:28:22 +02003082 static const char *const texts[] = {"Word Clock", "MADI", "TCO",
Adrian Knoth0dca1792011-01-26 19:32:14 +01003083 "Sync In", "None" };
Remy Bruno3cee5a62006-10-16 12:46:32 +02003084
Adrian Knoth04659f92013-07-05 11:28:22 +02003085 ENUMERATED_CTL_INFO(uinfo, texts);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003086 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003087 return 0;
3088}
3089
Takashi Iwai98274f02005-11-17 14:52:34 +01003090static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
3091 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003092{
Takashi Iwai98274f02005-11-17 14:52:34 +01003093 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003094
Remy Bruno65345992007-08-31 12:21:08 +02003095 ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02003096 return 0;
3097}
3098
Adrian Knothf99c7882013-03-10 00:37:26 +01003099
3100
3101#define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \
3102{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3103 .name = xname, \
3104 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3105 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3106 .info = snd_hdspm_info_tco_video_input_format, \
3107 .get = snd_hdspm_get_tco_video_input_format, \
3108}
3109
3110static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol,
3111 struct snd_ctl_elem_info *uinfo)
3112{
Adrian Knoth38816542013-07-05 11:28:20 +02003113 static const char *const texts[] = {"No video", "NTSC", "PAL"};
Adrian Knothf99c7882013-03-10 00:37:26 +01003114 ENUMERATED_CTL_INFO(uinfo, texts);
3115 return 0;
3116}
3117
3118static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol,
3119 struct snd_ctl_elem_value *ucontrol)
3120{
3121 u32 status;
3122 int ret = 0;
3123
3124 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3125 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3126 switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC |
3127 HDSPM_TCO1_Video_Input_Format_PAL)) {
3128 case HDSPM_TCO1_Video_Input_Format_NTSC:
3129 /* ntsc */
3130 ret = 1;
3131 break;
3132 case HDSPM_TCO1_Video_Input_Format_PAL:
3133 /* pal */
3134 ret = 2;
3135 break;
3136 default:
3137 /* no video */
3138 ret = 0;
3139 break;
3140 }
3141 ucontrol->value.enumerated.item[0] = ret;
3142 return 0;
3143}
3144
3145
3146
3147#define HDSPM_TCO_LTC_FRAMES(xname, xindex) \
3148{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3149 .name = xname, \
3150 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
3151 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3152 .info = snd_hdspm_info_tco_ltc_frames, \
3153 .get = snd_hdspm_get_tco_ltc_frames, \
3154}
3155
3156static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3157 struct snd_ctl_elem_info *uinfo)
3158{
Adrian Knoth38816542013-07-05 11:28:20 +02003159 static const char *const texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps",
Adrian Knothf99c7882013-03-10 00:37:26 +01003160 "30 fps"};
3161 ENUMERATED_CTL_INFO(uinfo, texts);
3162 return 0;
3163}
3164
3165static int hdspm_tco_ltc_frames(struct hdspm *hdspm)
3166{
3167 u32 status;
3168 int ret = 0;
3169
3170 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3171 if (status & HDSPM_TCO1_LTC_Input_valid) {
3172 switch (status & (HDSPM_TCO1_LTC_Format_LSB |
3173 HDSPM_TCO1_LTC_Format_MSB)) {
3174 case 0:
3175 /* 24 fps */
Adrian Knoth1568b882013-08-19 17:20:31 +02003176 ret = fps_24;
Adrian Knothf99c7882013-03-10 00:37:26 +01003177 break;
3178 case HDSPM_TCO1_LTC_Format_LSB:
3179 /* 25 fps */
Adrian Knoth1568b882013-08-19 17:20:31 +02003180 ret = fps_25;
Adrian Knothf99c7882013-03-10 00:37:26 +01003181 break;
3182 case HDSPM_TCO1_LTC_Format_MSB:
Adrian Knoth1568b882013-08-19 17:20:31 +02003183 /* 29.97 fps */
3184 ret = fps_2997;
Adrian Knothf99c7882013-03-10 00:37:26 +01003185 break;
3186 default:
3187 /* 30 fps */
Adrian Knoth1568b882013-08-19 17:20:31 +02003188 ret = fps_30;
Adrian Knothf99c7882013-03-10 00:37:26 +01003189 break;
3190 }
3191 }
3192
3193 return ret;
3194}
3195
3196static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3197 struct snd_ctl_elem_value *ucontrol)
3198{
3199 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3200
3201 ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm);
3202 return 0;
3203}
3204
Adrian Knothbf0ff872012-12-03 14:55:49 +01003205#define HDSPM_TOGGLE_SETTING(xname, xindex) \
3206{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3207 .name = xname, \
3208 .private_value = xindex, \
3209 .info = snd_hdspm_info_toggle_setting, \
3210 .get = snd_hdspm_get_toggle_setting, \
3211 .put = snd_hdspm_put_toggle_setting \
3212}
3213
3214static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask)
3215{
Adrian Knothce13f3f2013-07-05 11:27:55 +02003216 u32 reg;
3217
3218 if (hdspm_is_raydat_or_aio(hdspm))
3219 reg = hdspm->settings_register;
3220 else
3221 reg = hdspm->control_register;
3222
3223 return (reg & regmask) ? 1 : 0;
Adrian Knothbf0ff872012-12-03 14:55:49 +01003224}
3225
3226static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out)
3227{
Adrian Knothce13f3f2013-07-05 11:27:55 +02003228 u32 *reg;
3229 u32 target_reg;
3230
3231 if (hdspm_is_raydat_or_aio(hdspm)) {
3232 reg = &(hdspm->settings_register);
3233 target_reg = HDSPM_WR_SETTINGS;
3234 } else {
3235 reg = &(hdspm->control_register);
3236 target_reg = HDSPM_controlRegister;
3237 }
3238
Adrian Knothbf0ff872012-12-03 14:55:49 +01003239 if (out)
Adrian Knothce13f3f2013-07-05 11:27:55 +02003240 *reg |= regmask;
Adrian Knothbf0ff872012-12-03 14:55:49 +01003241 else
Adrian Knothce13f3f2013-07-05 11:27:55 +02003242 *reg &= ~regmask;
3243
3244 hdspm_write(hdspm, target_reg, *reg);
Adrian Knothbf0ff872012-12-03 14:55:49 +01003245
3246 return 0;
3247}
3248
3249#define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info
3250
3251static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol,
3252 struct snd_ctl_elem_value *ucontrol)
3253{
3254 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3255 u32 regmask = kcontrol->private_value;
3256
3257 spin_lock_irq(&hdspm->lock);
3258 ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask);
3259 spin_unlock_irq(&hdspm->lock);
3260 return 0;
3261}
3262
3263static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol,
3264 struct snd_ctl_elem_value *ucontrol)
3265{
3266 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3267 u32 regmask = kcontrol->private_value;
3268 int change;
3269 unsigned int val;
3270
3271 if (!snd_hdspm_use_is_exclusive(hdspm))
3272 return -EBUSY;
3273 val = ucontrol->value.integer.value[0] & 1;
3274 spin_lock_irq(&hdspm->lock);
3275 change = (int) val != hdspm_toggle_setting(hdspm, regmask);
3276 hdspm_set_toggle_setting(hdspm, regmask, val);
3277 spin_unlock_irq(&hdspm->lock);
3278 return change;
3279}
3280
Takashi Iwai763f3562005-06-03 11:25:34 +02003281#define HDSPM_INPUT_SELECT(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003282{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3283 .name = xname, \
3284 .index = xindex, \
3285 .info = snd_hdspm_info_input_select, \
3286 .get = snd_hdspm_get_input_select, \
3287 .put = snd_hdspm_put_input_select \
Takashi Iwai763f3562005-06-03 11:25:34 +02003288}
3289
Takashi Iwai98274f02005-11-17 14:52:34 +01003290static int hdspm_input_select(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003291{
3292 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
3293}
3294
Takashi Iwai98274f02005-11-17 14:52:34 +01003295static int hdspm_set_input_select(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02003296{
3297 if (out)
3298 hdspm->control_register |= HDSPM_InputSelect0;
3299 else
3300 hdspm->control_register &= ~HDSPM_InputSelect0;
3301 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3302
3303 return 0;
3304}
3305
Takashi Iwai98274f02005-11-17 14:52:34 +01003306static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
3307 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003308{
Adrian Knoth38816542013-07-05 11:28:20 +02003309 static const char *const texts[] = { "optical", "coaxial" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003310 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02003311 return 0;
3312}
3313
Takashi Iwai98274f02005-11-17 14:52:34 +01003314static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol,
3315 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003316{
Takashi Iwai98274f02005-11-17 14:52:34 +01003317 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003318
3319 spin_lock_irq(&hdspm->lock);
3320 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
3321 spin_unlock_irq(&hdspm->lock);
3322 return 0;
3323}
3324
Takashi Iwai98274f02005-11-17 14:52:34 +01003325static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,
3326 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003327{
Takashi Iwai98274f02005-11-17 14:52:34 +01003328 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003329 int change;
3330 unsigned int val;
3331
3332 if (!snd_hdspm_use_is_exclusive(hdspm))
3333 return -EBUSY;
3334 val = ucontrol->value.integer.value[0] & 1;
3335 spin_lock_irq(&hdspm->lock);
3336 change = (int) val != hdspm_input_select(hdspm);
3337 hdspm_set_input_select(hdspm, val);
3338 spin_unlock_irq(&hdspm->lock);
3339 return change;
3340}
3341
Adrian Knoth0dca1792011-01-26 19:32:14 +01003342
Remy Bruno3cee5a62006-10-16 12:46:32 +02003343#define HDSPM_DS_WIRE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003344{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3345 .name = xname, \
3346 .index = xindex, \
3347 .info = snd_hdspm_info_ds_wire, \
3348 .get = snd_hdspm_get_ds_wire, \
3349 .put = snd_hdspm_put_ds_wire \
Remy Bruno3cee5a62006-10-16 12:46:32 +02003350}
3351
3352static int hdspm_ds_wire(struct hdspm * hdspm)
3353{
3354 return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
3355}
3356
3357static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
3358{
3359 if (ds)
3360 hdspm->control_register |= HDSPM_DS_DoubleWire;
3361 else
3362 hdspm->control_register &= ~HDSPM_DS_DoubleWire;
3363 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3364
3365 return 0;
3366}
3367
3368static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
3369 struct snd_ctl_elem_info *uinfo)
3370{
Adrian Knoth38816542013-07-05 11:28:20 +02003371 static const char *const texts[] = { "Single", "Double" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003372 ENUMERATED_CTL_INFO(uinfo, texts);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003373 return 0;
3374}
3375
3376static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol,
3377 struct snd_ctl_elem_value *ucontrol)
3378{
3379 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3380
3381 spin_lock_irq(&hdspm->lock);
3382 ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
3383 spin_unlock_irq(&hdspm->lock);
3384 return 0;
3385}
3386
3387static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,
3388 struct snd_ctl_elem_value *ucontrol)
3389{
3390 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3391 int change;
3392 unsigned int val;
3393
3394 if (!snd_hdspm_use_is_exclusive(hdspm))
3395 return -EBUSY;
3396 val = ucontrol->value.integer.value[0] & 1;
3397 spin_lock_irq(&hdspm->lock);
3398 change = (int) val != hdspm_ds_wire(hdspm);
3399 hdspm_set_ds_wire(hdspm, val);
3400 spin_unlock_irq(&hdspm->lock);
3401 return change;
3402}
3403
Adrian Knoth0dca1792011-01-26 19:32:14 +01003404
Remy Bruno3cee5a62006-10-16 12:46:32 +02003405#define HDSPM_QS_WIRE(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003406{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3407 .name = xname, \
3408 .index = xindex, \
3409 .info = snd_hdspm_info_qs_wire, \
3410 .get = snd_hdspm_get_qs_wire, \
3411 .put = snd_hdspm_put_qs_wire \
Remy Bruno3cee5a62006-10-16 12:46:32 +02003412}
3413
3414static int hdspm_qs_wire(struct hdspm * hdspm)
3415{
3416 if (hdspm->control_register & HDSPM_QS_DoubleWire)
3417 return 1;
3418 if (hdspm->control_register & HDSPM_QS_QuadWire)
3419 return 2;
3420 return 0;
3421}
3422
3423static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
3424{
3425 hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
3426 switch (mode) {
3427 case 0:
3428 break;
3429 case 1:
3430 hdspm->control_register |= HDSPM_QS_DoubleWire;
3431 break;
3432 case 2:
3433 hdspm->control_register |= HDSPM_QS_QuadWire;
3434 break;
3435 }
3436 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3437
3438 return 0;
3439}
3440
3441static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
3442 struct snd_ctl_elem_info *uinfo)
3443{
Adrian Knoth38816542013-07-05 11:28:20 +02003444 static const char *const texts[] = { "Single", "Double", "Quad" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003445 ENUMERATED_CTL_INFO(uinfo, texts);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003446 return 0;
3447}
3448
3449static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol,
3450 struct snd_ctl_elem_value *ucontrol)
3451{
3452 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3453
3454 spin_lock_irq(&hdspm->lock);
3455 ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
3456 spin_unlock_irq(&hdspm->lock);
3457 return 0;
3458}
3459
3460static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
3461 struct snd_ctl_elem_value *ucontrol)
3462{
3463 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3464 int change;
3465 int val;
3466
3467 if (!snd_hdspm_use_is_exclusive(hdspm))
3468 return -EBUSY;
3469 val = ucontrol->value.integer.value[0];
3470 if (val < 0)
3471 val = 0;
3472 if (val > 2)
3473 val = 2;
3474 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003475 change = val != hdspm_qs_wire(hdspm);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003476 hdspm_set_qs_wire(hdspm, val);
3477 spin_unlock_irq(&hdspm->lock);
3478 return change;
3479}
3480
Adrian Knothacf14762013-07-05 11:28:00 +02003481#define HDSPM_CONTROL_TRISTATE(xname, xindex) \
3482{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3483 .name = xname, \
3484 .private_value = xindex, \
3485 .info = snd_hdspm_info_tristate, \
3486 .get = snd_hdspm_get_tristate, \
3487 .put = snd_hdspm_put_tristate \
3488}
3489
3490static int hdspm_tristate(struct hdspm *hdspm, u32 regmask)
3491{
3492 u32 reg = hdspm->settings_register & (regmask * 3);
3493 return reg / regmask;
3494}
3495
3496static int hdspm_set_tristate(struct hdspm *hdspm, int mode, u32 regmask)
3497{
3498 hdspm->settings_register &= ~(regmask * 3);
3499 hdspm->settings_register |= (regmask * mode);
3500 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
3501
3502 return 0;
3503}
3504
3505static int snd_hdspm_info_tristate(struct snd_kcontrol *kcontrol,
3506 struct snd_ctl_elem_info *uinfo)
3507{
3508 u32 regmask = kcontrol->private_value;
3509
Adrian Knoth38816542013-07-05 11:28:20 +02003510 static const char *const texts_spdif[] = { "Optical", "Coaxial", "Internal" };
3511 static const char *const texts_levels[] = { "Hi Gain", "+4 dBu", "-10 dBV" };
Adrian Knothacf14762013-07-05 11:28:00 +02003512
3513 switch (regmask) {
3514 case HDSPM_c0_Input0:
3515 ENUMERATED_CTL_INFO(uinfo, texts_spdif);
3516 break;
3517 default:
3518 ENUMERATED_CTL_INFO(uinfo, texts_levels);
3519 break;
3520 }
3521 return 0;
3522}
3523
3524static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol,
3525 struct snd_ctl_elem_value *ucontrol)
3526{
3527 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3528 u32 regmask = kcontrol->private_value;
3529
3530 spin_lock_irq(&hdspm->lock);
3531 ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask);
3532 spin_unlock_irq(&hdspm->lock);
3533 return 0;
3534}
3535
3536static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol,
3537 struct snd_ctl_elem_value *ucontrol)
3538{
3539 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3540 u32 regmask = kcontrol->private_value;
3541 int change;
3542 int val;
3543
3544 if (!snd_hdspm_use_is_exclusive(hdspm))
3545 return -EBUSY;
3546 val = ucontrol->value.integer.value[0];
3547 if (val < 0)
3548 val = 0;
3549 if (val > 2)
3550 val = 2;
3551
3552 spin_lock_irq(&hdspm->lock);
3553 change = val != hdspm_tristate(hdspm, regmask);
3554 hdspm_set_tristate(hdspm, val, regmask);
3555 spin_unlock_irq(&hdspm->lock);
3556 return change;
3557}
3558
Adrian Knoth700d1ef2011-07-29 03:11:02 +02003559#define HDSPM_MADI_SPEEDMODE(xname, xindex) \
3560{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3561 .name = xname, \
3562 .index = xindex, \
3563 .info = snd_hdspm_info_madi_speedmode, \
3564 .get = snd_hdspm_get_madi_speedmode, \
3565 .put = snd_hdspm_put_madi_speedmode \
3566}
3567
3568static int hdspm_madi_speedmode(struct hdspm *hdspm)
3569{
3570 if (hdspm->control_register & HDSPM_QuadSpeed)
3571 return 2;
3572 if (hdspm->control_register & HDSPM_DoubleSpeed)
3573 return 1;
3574 return 0;
3575}
3576
3577static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode)
3578{
3579 hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed);
3580 switch (mode) {
3581 case 0:
3582 break;
3583 case 1:
3584 hdspm->control_register |= HDSPM_DoubleSpeed;
3585 break;
3586 case 2:
3587 hdspm->control_register |= HDSPM_QuadSpeed;
3588 break;
3589 }
3590 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3591
3592 return 0;
3593}
3594
3595static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
3596 struct snd_ctl_elem_info *uinfo)
3597{
Adrian Knoth38816542013-07-05 11:28:20 +02003598 static const char *const texts[] = { "Single", "Double", "Quad" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003599 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth700d1ef2011-07-29 03:11:02 +02003600 return 0;
3601}
3602
3603static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol,
3604 struct snd_ctl_elem_value *ucontrol)
3605{
3606 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3607
3608 spin_lock_irq(&hdspm->lock);
3609 ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm);
3610 spin_unlock_irq(&hdspm->lock);
3611 return 0;
3612}
3613
3614static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol,
3615 struct snd_ctl_elem_value *ucontrol)
3616{
3617 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3618 int change;
3619 int val;
3620
3621 if (!snd_hdspm_use_is_exclusive(hdspm))
3622 return -EBUSY;
3623 val = ucontrol->value.integer.value[0];
3624 if (val < 0)
3625 val = 0;
3626 if (val > 2)
3627 val = 2;
3628 spin_lock_irq(&hdspm->lock);
3629 change = val != hdspm_madi_speedmode(hdspm);
3630 hdspm_set_madi_speedmode(hdspm, val);
3631 spin_unlock_irq(&hdspm->lock);
3632 return change;
3633}
Takashi Iwai763f3562005-06-03 11:25:34 +02003634
3635#define HDSPM_MIXER(xname, xindex) \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003636{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3637 .name = xname, \
3638 .index = xindex, \
3639 .device = 0, \
3640 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3641 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3642 .info = snd_hdspm_info_mixer, \
3643 .get = snd_hdspm_get_mixer, \
3644 .put = snd_hdspm_put_mixer \
Takashi Iwai763f3562005-06-03 11:25:34 +02003645}
3646
Takashi Iwai98274f02005-11-17 14:52:34 +01003647static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol,
3648 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003649{
3650 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3651 uinfo->count = 3;
3652 uinfo->value.integer.min = 0;
3653 uinfo->value.integer.max = 65535;
3654 uinfo->value.integer.step = 1;
3655 return 0;
3656}
3657
Takashi Iwai98274f02005-11-17 14:52:34 +01003658static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,
3659 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003660{
Takashi Iwai98274f02005-11-17 14:52:34 +01003661 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003662 int source;
3663 int destination;
3664
3665 source = ucontrol->value.integer.value[0];
3666 if (source < 0)
3667 source = 0;
3668 else if (source >= 2 * HDSPM_MAX_CHANNELS)
3669 source = 2 * HDSPM_MAX_CHANNELS - 1;
3670
3671 destination = ucontrol->value.integer.value[1];
3672 if (destination < 0)
3673 destination = 0;
3674 else if (destination >= HDSPM_MAX_CHANNELS)
3675 destination = HDSPM_MAX_CHANNELS - 1;
3676
3677 spin_lock_irq(&hdspm->lock);
3678 if (source >= HDSPM_MAX_CHANNELS)
3679 ucontrol->value.integer.value[2] =
3680 hdspm_read_pb_gain(hdspm, destination,
3681 source - HDSPM_MAX_CHANNELS);
3682 else
3683 ucontrol->value.integer.value[2] =
3684 hdspm_read_in_gain(hdspm, destination, source);
3685
3686 spin_unlock_irq(&hdspm->lock);
3687
3688 return 0;
3689}
3690
Takashi Iwai98274f02005-11-17 14:52:34 +01003691static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,
3692 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003693{
Takashi Iwai98274f02005-11-17 14:52:34 +01003694 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003695 int change;
3696 int source;
3697 int destination;
3698 int gain;
3699
3700 if (!snd_hdspm_use_is_exclusive(hdspm))
3701 return -EBUSY;
3702
3703 source = ucontrol->value.integer.value[0];
3704 destination = ucontrol->value.integer.value[1];
3705
3706 if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
3707 return -1;
3708 if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
3709 return -1;
3710
3711 gain = ucontrol->value.integer.value[2];
3712
3713 spin_lock_irq(&hdspm->lock);
3714
3715 if (source >= HDSPM_MAX_CHANNELS)
3716 change = gain != hdspm_read_pb_gain(hdspm, destination,
3717 source -
3718 HDSPM_MAX_CHANNELS);
3719 else
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003720 change = gain != hdspm_read_in_gain(hdspm, destination,
3721 source);
Takashi Iwai763f3562005-06-03 11:25:34 +02003722
3723 if (change) {
3724 if (source >= HDSPM_MAX_CHANNELS)
3725 hdspm_write_pb_gain(hdspm, destination,
3726 source - HDSPM_MAX_CHANNELS,
3727 gain);
3728 else
3729 hdspm_write_in_gain(hdspm, destination, source,
3730 gain);
3731 }
3732 spin_unlock_irq(&hdspm->lock);
3733
3734 return change;
3735}
3736
3737/* The simple mixer control(s) provide gain control for the
3738 basic 1:1 mappings of playback streams to output
Adrian Knoth0dca1792011-01-26 19:32:14 +01003739 streams.
Takashi Iwai763f3562005-06-03 11:25:34 +02003740*/
3741
3742#define HDSPM_PLAYBACK_MIXER \
Adrian Knothf27a64f2012-10-19 17:42:30 +02003743{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3744 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
3745 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3746 .info = snd_hdspm_info_playback_mixer, \
3747 .get = snd_hdspm_get_playback_mixer, \
3748 .put = snd_hdspm_put_playback_mixer \
Takashi Iwai763f3562005-06-03 11:25:34 +02003749}
3750
Takashi Iwai98274f02005-11-17 14:52:34 +01003751static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol,
3752 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003753{
3754 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3755 uinfo->count = 1;
3756 uinfo->value.integer.min = 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003757 uinfo->value.integer.max = 64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003758 uinfo->value.integer.step = 1;
3759 return 0;
3760}
3761
Takashi Iwai98274f02005-11-17 14:52:34 +01003762static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
3763 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003764{
Takashi Iwai98274f02005-11-17 14:52:34 +01003765 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003766 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003767
3768 channel = ucontrol->id.index - 1;
3769
Takashi Iwaida3cec32008-08-08 17:12:14 +02003770 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3771 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003772
Takashi Iwai763f3562005-06-03 11:25:34 +02003773 spin_lock_irq(&hdspm->lock);
3774 ucontrol->value.integer.value[0] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003775 (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN;
Takashi Iwai763f3562005-06-03 11:25:34 +02003776 spin_unlock_irq(&hdspm->lock);
3777
Takashi Iwai763f3562005-06-03 11:25:34 +02003778 return 0;
3779}
3780
Takashi Iwai98274f02005-11-17 14:52:34 +01003781static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
3782 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003783{
Takashi Iwai98274f02005-11-17 14:52:34 +01003784 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003785 int change;
3786 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003787 int gain;
3788
3789 if (!snd_hdspm_use_is_exclusive(hdspm))
3790 return -EBUSY;
3791
3792 channel = ucontrol->id.index - 1;
3793
Takashi Iwaida3cec32008-08-08 17:12:14 +02003794 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3795 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003796
Adrian Knoth0dca1792011-01-26 19:32:14 +01003797 gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003798
3799 spin_lock_irq(&hdspm->lock);
3800 change =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003801 gain != hdspm_read_pb_gain(hdspm, channel,
3802 channel);
Takashi Iwai763f3562005-06-03 11:25:34 +02003803 if (change)
Adrian Knoth0dca1792011-01-26 19:32:14 +01003804 hdspm_write_pb_gain(hdspm, channel, channel,
Takashi Iwai763f3562005-06-03 11:25:34 +02003805 gain);
3806 spin_unlock_irq(&hdspm->lock);
3807 return change;
3808}
3809
Adrian Knoth0dca1792011-01-26 19:32:14 +01003810#define HDSPM_SYNC_CHECK(xname, xindex) \
3811{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3812 .name = xname, \
3813 .private_value = xindex, \
3814 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3815 .info = snd_hdspm_info_sync_check, \
3816 .get = snd_hdspm_get_sync_check \
Takashi Iwai763f3562005-06-03 11:25:34 +02003817}
3818
Adrian Knoth34542212013-03-10 00:37:25 +01003819#define HDSPM_TCO_LOCK_CHECK(xname, xindex) \
3820{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3821 .name = xname, \
3822 .private_value = xindex, \
3823 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3824 .info = snd_hdspm_tco_info_lock_check, \
3825 .get = snd_hdspm_get_sync_check \
3826}
3827
3828
Adrian Knoth0dca1792011-01-26 19:32:14 +01003829
Takashi Iwai98274f02005-11-17 14:52:34 +01003830static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
3831 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003832{
Adrian Knoth38816542013-07-05 11:28:20 +02003833 static const char *const texts[] = { "No Lock", "Lock", "Sync", "N/A" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01003834 ENUMERATED_CTL_INFO(uinfo, texts);
Takashi Iwai763f3562005-06-03 11:25:34 +02003835 return 0;
3836}
3837
Adrian Knoth34542212013-03-10 00:37:25 +01003838static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol,
3839 struct snd_ctl_elem_info *uinfo)
3840{
Adrian Knoth38816542013-07-05 11:28:20 +02003841 static const char *const texts[] = { "No Lock", "Lock" };
Adrian Knoth34542212013-03-10 00:37:25 +01003842 ENUMERATED_CTL_INFO(uinfo, texts);
3843 return 0;
3844}
3845
Adrian Knoth0dca1792011-01-26 19:32:14 +01003846static int hdspm_wc_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003847{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003848 int status, status2;
3849
3850 switch (hdspm->io_type) {
3851 case AES32:
3852 status = hdspm_read(hdspm, HDSPM_statusRegister);
Andre Schramm56bde0f2013-01-09 14:40:18 +01003853 if (status & HDSPM_AES32_wcLock) {
3854 if (status & HDSPM_AES32_wcSync)
3855 return 2;
3856 else
3857 return 1;
3858 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02003859 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003860 break;
3861
3862 case MADI:
3863 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003864 if (status2 & HDSPM_wcLock) {
3865 if (status2 & HDSPM_wcSync)
3866 return 2;
3867 else
3868 return 1;
3869 }
3870 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003871 break;
3872
3873 case RayDAT:
3874 case AIO:
3875 status = hdspm_read(hdspm, HDSPM_statusRegister);
3876
3877 if (status & 0x2000000)
3878 return 2;
3879 else if (status & 0x1000000)
3880 return 1;
3881 return 0;
3882
3883 break;
3884
3885 case MADIface:
3886 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02003887 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003888
Takashi Iwai763f3562005-06-03 11:25:34 +02003889
Adrian Knoth0dca1792011-01-26 19:32:14 +01003890 return 3;
Takashi Iwai763f3562005-06-03 11:25:34 +02003891}
3892
3893
Adrian Knoth0dca1792011-01-26 19:32:14 +01003894static int hdspm_madi_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003895{
3896 int status = hdspm_read(hdspm, HDSPM_statusRegister);
3897 if (status & HDSPM_madiLock) {
3898 if (status & HDSPM_madiSync)
3899 return 2;
3900 else
3901 return 1;
3902 }
3903 return 0;
3904}
3905
Adrian Knoth0dca1792011-01-26 19:32:14 +01003906
3907static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx)
3908{
3909 int status, lock, sync;
3910
3911 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3912
3913 lock = (status & (0x1<<idx)) ? 1 : 0;
3914 sync = (status & (0x100<<idx)) ? 1 : 0;
3915
3916 if (lock && sync)
3917 return 2;
3918 else if (lock)
3919 return 1;
3920 return 0;
3921}
3922
3923
3924static int hdspm_sync_in_sync_check(struct hdspm *hdspm)
3925{
3926 int status, lock = 0, sync = 0;
3927
3928 switch (hdspm->io_type) {
3929 case RayDAT:
3930 case AIO:
3931 status = hdspm_read(hdspm, HDSPM_RD_STATUS_3);
3932 lock = (status & 0x400) ? 1 : 0;
3933 sync = (status & 0x800) ? 1 : 0;
3934 break;
3935
3936 case MADI:
Adrian Knoth2e0452f2012-10-19 17:42:27 +02003937 status = hdspm_read(hdspm, HDSPM_statusRegister);
3938 lock = (status & HDSPM_syncInLock) ? 1 : 0;
3939 sync = (status & HDSPM_syncInSync) ? 1 : 0;
3940 break;
3941
Adrian Knoth0dca1792011-01-26 19:32:14 +01003942 case AES32:
3943 status = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth9a215f42012-10-19 17:42:28 +02003944 lock = (status & 0x100000) ? 1 : 0;
3945 sync = (status & 0x200000) ? 1 : 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003946 break;
3947
3948 case MADIface:
3949 break;
3950 }
3951
3952 if (lock && sync)
3953 return 2;
3954 else if (lock)
3955 return 1;
3956
3957 return 0;
3958}
3959
3960static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
3961{
3962 int status2, lock, sync;
3963 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3964
3965 lock = (status2 & (0x0080 >> idx)) ? 1 : 0;
3966 sync = (status2 & (0x8000 >> idx)) ? 1 : 0;
3967
3968 if (sync)
3969 return 2;
3970 else if (lock)
3971 return 1;
3972 return 0;
3973}
3974
Adrian Knoth34542212013-03-10 00:37:25 +01003975static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask)
3976{
3977 u32 status;
3978 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3979
3980 return (status & mask) ? 1 : 0;
3981}
3982
Adrian Knoth0dca1792011-01-26 19:32:14 +01003983
3984static int hdspm_tco_sync_check(struct hdspm *hdspm)
3985{
3986 int status;
3987
3988 if (hdspm->tco) {
3989 switch (hdspm->io_type) {
3990 case MADI:
Adrian Knothb0bf5502013-07-05 11:28:05 +02003991 status = hdspm_read(hdspm, HDSPM_statusRegister);
3992 if (status & HDSPM_tcoLockMadi) {
3993 if (status & HDSPM_tcoSync)
3994 return 2;
3995 else
3996 return 1;
3997 }
3998 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003999 case AES32:
4000 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knothb0bf5502013-07-05 11:28:05 +02004001 if (status & HDSPM_tcoLockAes) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01004002 if (status & HDSPM_tcoSync)
4003 return 2;
4004 else
4005 return 1;
4006 }
4007 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004008 case RayDAT:
4009 case AIO:
4010 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
4011
4012 if (status & 0x8000000)
4013 return 2; /* Sync */
4014 if (status & 0x4000000)
4015 return 1; /* Lock */
4016 return 0; /* No signal */
Adrian Knoth0dca1792011-01-26 19:32:14 +01004017
4018 default:
4019 break;
4020 }
4021 }
4022
4023 return 3; /* N/A */
4024}
4025
4026
4027static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
4028 struct snd_ctl_elem_value *ucontrol)
4029{
4030 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4031 int val = -1;
4032
4033 switch (hdspm->io_type) {
4034 case RayDAT:
4035 switch (kcontrol->private_value) {
4036 case 0: /* WC */
4037 val = hdspm_wc_sync_check(hdspm); break;
4038 case 7: /* TCO */
4039 val = hdspm_tco_sync_check(hdspm); break;
4040 case 8: /* SYNC IN */
4041 val = hdspm_sync_in_sync_check(hdspm); break;
4042 default:
Adrian Knothd1a3c982012-11-07 18:00:09 +01004043 val = hdspm_s1_sync_check(hdspm,
4044 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004045 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004046 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004047
4048 case AIO:
4049 switch (kcontrol->private_value) {
4050 case 0: /* WC */
4051 val = hdspm_wc_sync_check(hdspm); break;
4052 case 4: /* TCO */
4053 val = hdspm_tco_sync_check(hdspm); break;
4054 case 5: /* SYNC IN */
4055 val = hdspm_sync_in_sync_check(hdspm); break;
4056 default:
Adrian Knoth1cb7dbf2013-07-05 11:28:03 +02004057 val = hdspm_s1_sync_check(hdspm,
4058 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004059 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004060 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004061
4062 case MADI:
4063 switch (kcontrol->private_value) {
4064 case 0: /* WC */
4065 val = hdspm_wc_sync_check(hdspm); break;
4066 case 1: /* MADI */
4067 val = hdspm_madi_sync_check(hdspm); break;
4068 case 2: /* TCO */
4069 val = hdspm_tco_sync_check(hdspm); break;
4070 case 3: /* SYNC_IN */
4071 val = hdspm_sync_in_sync_check(hdspm); break;
4072 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004073 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004074
4075 case MADIface:
4076 val = hdspm_madi_sync_check(hdspm); /* MADI */
4077 break;
4078
4079 case AES32:
4080 switch (kcontrol->private_value) {
4081 case 0: /* WC */
4082 val = hdspm_wc_sync_check(hdspm); break;
4083 case 9: /* TCO */
4084 val = hdspm_tco_sync_check(hdspm); break;
4085 case 10 /* SYNC IN */:
4086 val = hdspm_sync_in_sync_check(hdspm); break;
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01004087 default: /* AES1 to AES8 */
Adrian Knoth0dca1792011-01-26 19:32:14 +01004088 val = hdspm_aes_sync_check(hdspm,
Adrian Knoth7c4a95b2011-02-23 11:43:13 +01004089 kcontrol->private_value-1);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004090 }
Adrian Knothfba30fd2012-10-19 17:42:24 +02004091 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004092
4093 }
4094
Adrian Knoth34542212013-03-10 00:37:25 +01004095 if (hdspm->tco) {
4096 switch (kcontrol->private_value) {
4097 case 11:
4098 /* Check TCO for lock state of its current input */
4099 val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock);
4100 break;
4101 case 12:
4102 /* Check TCO for valid time code on LTC input. */
4103 val = hdspm_tco_input_check(hdspm,
4104 HDSPM_TCO1_LTC_Input_valid);
4105 break;
4106 default:
4107 break;
4108 }
4109 }
4110
Adrian Knoth0dca1792011-01-26 19:32:14 +01004111 if (-1 == val)
4112 val = 3;
4113
4114 ucontrol->value.enumerated.item[0] = val;
4115 return 0;
4116}
4117
4118
4119
4120/**
4121 * TCO controls
4122 **/
4123static void hdspm_tco_write(struct hdspm *hdspm)
4124{
4125 unsigned int tc[4] = { 0, 0, 0, 0};
4126
4127 switch (hdspm->tco->input) {
4128 case 0:
4129 tc[2] |= HDSPM_TCO2_set_input_MSB;
4130 break;
4131 case 1:
4132 tc[2] |= HDSPM_TCO2_set_input_LSB;
4133 break;
4134 default:
4135 break;
4136 }
4137
4138 switch (hdspm->tco->framerate) {
4139 case 1:
4140 tc[1] |= HDSPM_TCO1_LTC_Format_LSB;
4141 break;
4142 case 2:
4143 tc[1] |= HDSPM_TCO1_LTC_Format_MSB;
4144 break;
4145 case 3:
4146 tc[1] |= HDSPM_TCO1_LTC_Format_MSB +
4147 HDSPM_TCO1_set_drop_frame_flag;
4148 break;
4149 case 4:
4150 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4151 HDSPM_TCO1_LTC_Format_MSB;
4152 break;
4153 case 5:
4154 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
4155 HDSPM_TCO1_LTC_Format_MSB +
4156 HDSPM_TCO1_set_drop_frame_flag;
4157 break;
4158 default:
4159 break;
4160 }
4161
4162 switch (hdspm->tco->wordclock) {
4163 case 1:
4164 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB;
4165 break;
4166 case 2:
4167 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB;
4168 break;
4169 default:
4170 break;
4171 }
4172
4173 switch (hdspm->tco->samplerate) {
4174 case 1:
4175 tc[2] |= HDSPM_TCO2_set_freq;
4176 break;
4177 case 2:
4178 tc[2] |= HDSPM_TCO2_set_freq_from_app;
4179 break;
4180 default:
4181 break;
4182 }
4183
4184 switch (hdspm->tco->pull) {
4185 case 1:
4186 tc[2] |= HDSPM_TCO2_set_pull_up;
4187 break;
4188 case 2:
4189 tc[2] |= HDSPM_TCO2_set_pull_down;
4190 break;
4191 case 3:
4192 tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4;
4193 break;
4194 case 4:
4195 tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4;
4196 break;
4197 default:
4198 break;
4199 }
4200
4201 if (1 == hdspm->tco->term) {
4202 tc[2] |= HDSPM_TCO2_set_term_75R;
4203 }
4204
4205 hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]);
4206 hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]);
4207 hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]);
4208 hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]);
4209}
4210
4211
4212#define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \
4213{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4214 .name = xname, \
4215 .index = xindex, \
4216 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4217 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4218 .info = snd_hdspm_info_tco_sample_rate, \
4219 .get = snd_hdspm_get_tco_sample_rate, \
4220 .put = snd_hdspm_put_tco_sample_rate \
4221}
4222
4223static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
4224 struct snd_ctl_elem_info *uinfo)
4225{
Martin Dausel69358fc2013-07-05 11:28:23 +02004226 /* TODO freq from app could be supported here, see tco->samplerate */
Adrian Knoth38816542013-07-05 11:28:20 +02004227 static const char *const texts[] = { "44.1 kHz", "48 kHz" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004228 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004229 return 0;
4230}
4231
4232static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol,
4233 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02004234{
Takashi Iwai98274f02005-11-17 14:52:34 +01004235 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02004236
Adrian Knoth0dca1792011-01-26 19:32:14 +01004237 ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate;
4238
Takashi Iwai763f3562005-06-03 11:25:34 +02004239 return 0;
4240}
4241
Adrian Knoth0dca1792011-01-26 19:32:14 +01004242static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol,
4243 struct snd_ctl_elem_value *ucontrol)
Remy Bruno3cee5a62006-10-16 12:46:32 +02004244{
Adrian Knoth0dca1792011-01-26 19:32:14 +01004245 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4246
4247 if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) {
4248 hdspm->tco->samplerate = ucontrol->value.enumerated.item[0];
4249
4250 hdspm_tco_write(hdspm);
4251
4252 return 1;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004253 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01004254
Remy Bruno3cee5a62006-10-16 12:46:32 +02004255 return 0;
4256}
4257
Adrian Knoth0dca1792011-01-26 19:32:14 +01004258
4259#define HDSPM_TCO_PULL(xname, xindex) \
4260{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4261 .name = xname, \
4262 .index = xindex, \
4263 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4264 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4265 .info = snd_hdspm_info_tco_pull, \
4266 .get = snd_hdspm_get_tco_pull, \
4267 .put = snd_hdspm_put_tco_pull \
4268}
4269
4270static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
4271 struct snd_ctl_elem_info *uinfo)
4272{
Adrian Knoth38816542013-07-05 11:28:20 +02004273 static const char *const texts[] = { "0", "+ 0.1 %", "- 0.1 %",
4274 "+ 4 %", "- 4 %" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004275 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004276 return 0;
4277}
4278
4279static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol,
4280 struct snd_ctl_elem_value *ucontrol)
4281{
4282 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4283
4284 ucontrol->value.enumerated.item[0] = hdspm->tco->pull;
4285
4286 return 0;
4287}
4288
4289static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol,
4290 struct snd_ctl_elem_value *ucontrol)
4291{
4292 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4293
4294 if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) {
4295 hdspm->tco->pull = ucontrol->value.enumerated.item[0];
4296
4297 hdspm_tco_write(hdspm);
4298
4299 return 1;
4300 }
4301
4302 return 0;
4303}
4304
4305#define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \
4306{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4307 .name = xname, \
4308 .index = xindex, \
4309 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4310 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4311 .info = snd_hdspm_info_tco_wck_conversion, \
4312 .get = snd_hdspm_get_tco_wck_conversion, \
4313 .put = snd_hdspm_put_tco_wck_conversion \
4314}
4315
4316static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4317 struct snd_ctl_elem_info *uinfo)
4318{
Adrian Knoth38816542013-07-05 11:28:20 +02004319 static const char *const texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004320 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004321 return 0;
4322}
4323
4324static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4325 struct snd_ctl_elem_value *ucontrol)
4326{
4327 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4328
4329 ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock;
4330
4331 return 0;
4332}
4333
4334static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4335 struct snd_ctl_elem_value *ucontrol)
4336{
4337 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4338
4339 if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) {
4340 hdspm->tco->wordclock = ucontrol->value.enumerated.item[0];
4341
4342 hdspm_tco_write(hdspm);
4343
4344 return 1;
4345 }
4346
4347 return 0;
4348}
4349
4350
4351#define HDSPM_TCO_FRAME_RATE(xname, xindex) \
4352{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4353 .name = xname, \
4354 .index = xindex, \
4355 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4356 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4357 .info = snd_hdspm_info_tco_frame_rate, \
4358 .get = snd_hdspm_get_tco_frame_rate, \
4359 .put = snd_hdspm_put_tco_frame_rate \
4360}
4361
4362static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
4363 struct snd_ctl_elem_info *uinfo)
4364{
Adrian Knoth38816542013-07-05 11:28:20 +02004365 static const char *const texts[] = { "24 fps", "25 fps", "29.97fps",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004366 "29.97 dfps", "30 fps", "30 dfps" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004367 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004368 return 0;
4369}
4370
4371static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol,
Remy Bruno3cee5a62006-10-16 12:46:32 +02004372 struct snd_ctl_elem_value *ucontrol)
4373{
Remy Bruno3cee5a62006-10-16 12:46:32 +02004374 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4375
Adrian Knoth0dca1792011-01-26 19:32:14 +01004376 ucontrol->value.enumerated.item[0] = hdspm->tco->framerate;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004377
Remy Bruno3cee5a62006-10-16 12:46:32 +02004378 return 0;
4379}
Takashi Iwai763f3562005-06-03 11:25:34 +02004380
Adrian Knoth0dca1792011-01-26 19:32:14 +01004381static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol,
4382 struct snd_ctl_elem_value *ucontrol)
4383{
4384 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4385
4386 if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) {
4387 hdspm->tco->framerate = ucontrol->value.enumerated.item[0];
4388
4389 hdspm_tco_write(hdspm);
4390
4391 return 1;
4392 }
4393
4394 return 0;
4395}
4396
4397
4398#define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \
4399{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4400 .name = xname, \
4401 .index = xindex, \
4402 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4403 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4404 .info = snd_hdspm_info_tco_sync_source, \
4405 .get = snd_hdspm_get_tco_sync_source, \
4406 .put = snd_hdspm_put_tco_sync_source \
4407}
4408
4409static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
4410 struct snd_ctl_elem_info *uinfo)
4411{
Adrian Knoth38816542013-07-05 11:28:20 +02004412 static const char *const texts[] = { "LTC", "Video", "WCK" };
Adrian Knothe5b7b1f2013-03-10 00:37:24 +01004413 ENUMERATED_CTL_INFO(uinfo, texts);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004414 return 0;
4415}
4416
4417static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol,
4418 struct snd_ctl_elem_value *ucontrol)
4419{
4420 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4421
4422 ucontrol->value.enumerated.item[0] = hdspm->tco->input;
4423
4424 return 0;
4425}
4426
4427static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol,
4428 struct snd_ctl_elem_value *ucontrol)
4429{
4430 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4431
4432 if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) {
4433 hdspm->tco->input = ucontrol->value.enumerated.item[0];
4434
4435 hdspm_tco_write(hdspm);
4436
4437 return 1;
4438 }
4439
4440 return 0;
4441}
4442
4443
4444#define HDSPM_TCO_WORD_TERM(xname, xindex) \
4445{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4446 .name = xname, \
4447 .index = xindex, \
4448 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4449 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4450 .info = snd_hdspm_info_tco_word_term, \
4451 .get = snd_hdspm_get_tco_word_term, \
4452 .put = snd_hdspm_put_tco_word_term \
4453}
4454
4455static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol,
4456 struct snd_ctl_elem_info *uinfo)
4457{
4458 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4459 uinfo->count = 1;
4460 uinfo->value.integer.min = 0;
4461 uinfo->value.integer.max = 1;
4462
4463 return 0;
4464}
4465
4466
4467static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol,
4468 struct snd_ctl_elem_value *ucontrol)
4469{
4470 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4471
4472 ucontrol->value.enumerated.item[0] = hdspm->tco->term;
4473
4474 return 0;
4475}
4476
4477
4478static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol,
4479 struct snd_ctl_elem_value *ucontrol)
4480{
4481 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4482
4483 if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) {
4484 hdspm->tco->term = ucontrol->value.enumerated.item[0];
4485
4486 hdspm_tco_write(hdspm);
4487
4488 return 1;
4489 }
4490
4491 return 0;
4492}
4493
4494
4495
Takashi Iwai763f3562005-06-03 11:25:34 +02004496
Remy Bruno3cee5a62006-10-16 12:46:32 +02004497static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
Takashi Iwai763f3562005-06-03 11:25:34 +02004498 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004499 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Takashi Iwai763f3562005-06-03 11:25:34 +02004500 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4501 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4502 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4503 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Adrian Knothb8812c52012-10-19 17:42:26 +02004504 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004505 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4506 HDSPM_SYNC_CHECK("MADI SyncCheck", 1),
Adrian Knoth930f4ff2012-10-19 17:42:29 +02004507 HDSPM_SYNC_CHECK("TCO SyncCheck", 2),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004508 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
Adrian Knothc9e16682012-12-03 14:55:50 +01004509 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4510 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
Adrian Knoth696be0f2013-03-10 00:37:23 +01004511 HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX),
Adrian Knothc9e16682012-12-03 14:55:50 +01004512 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4513 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
Adrian Knoth700d1ef2011-07-29 03:11:02 +02004514 HDSPM_INPUT_SELECT("Input Select", 0),
4515 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004516};
4517
4518
4519static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = {
4520 HDSPM_MIXER("Mixer", 0),
4521 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4522 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4523 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4524 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4525 HDSPM_SYNC_CHECK("MADI SyncCheck", 0),
Adrian Knothc9e16682012-12-03 14:55:50 +01004526 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
4527 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4528 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
Adrian Knoth700d1ef2011-07-29 03:11:02 +02004529 HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004530};
4531
Adrian Knoth0dca1792011-01-26 19:32:14 +01004532static struct snd_kcontrol_new snd_hdspm_controls_aio[] = {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004533 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004534 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004535 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4536 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004537 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004538 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004539 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4540 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4541 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4542 HDSPM_SYNC_CHECK("ADAT SyncCheck", 3),
4543 HDSPM_SYNC_CHECK("TCO SyncCheck", 4),
4544 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5),
4545 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4546 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4547 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4548 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3),
4549 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4),
Adrian Knothfb0f1212013-07-05 11:27:58 +02004550 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5),
Adrian Knoth42f4c122013-07-05 11:28:01 +02004551 HDSPM_CONTROL_TRISTATE("S/PDIF Input", HDSPM_c0_Input0),
Adrian Knothfb0f1212013-07-05 11:27:58 +02004552 HDSPM_TOGGLE_SETTING("S/PDIF Out Optical", HDSPM_c0_Spdif_Opt),
4553 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4554 HDSPM_TOGGLE_SETTING("ADAT internal (AEB/TEB)", HDSPM_c0_AEB1),
4555 HDSPM_TOGGLE_SETTING("XLR Breakout Cable", HDSPM_c0_Sym6db),
Adrian Knoth42f4c122013-07-05 11:28:01 +02004556 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48),
4557 HDSPM_CONTROL_TRISTATE("Input Level", HDSPM_c0_AD_GAIN0),
4558 HDSPM_CONTROL_TRISTATE("Output Level", HDSPM_c0_DA_GAIN0),
4559 HDSPM_CONTROL_TRISTATE("Phones Level", HDSPM_c0_PH_GAIN0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004560
4561 /*
4562 HDSPM_INPUT_SELECT("Input Select", 0),
4563 HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0),
4564 HDSPM_PROFESSIONAL("SPDIF Out Professional", 0);
4565 HDSPM_SPDIF_IN("SPDIF In", 0);
4566 HDSPM_BREAKOUT_CABLE("Breakout Cable", 0);
4567 HDSPM_INPUT_LEVEL("Input Level", 0);
4568 HDSPM_OUTPUT_LEVEL("Output Level", 0);
4569 HDSPM_PHONES("Phones", 0);
4570 */
4571};
4572
4573static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = {
4574 HDSPM_MIXER("Mixer", 0),
4575 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4576 HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0),
4577 HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0),
4578 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4579 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4580 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4581 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4582 HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3),
4583 HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4),
4584 HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5),
4585 HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6),
4586 HDSPM_SYNC_CHECK("TCO SyncCheck", 7),
4587 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8),
4588 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4589 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4590 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4591 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3),
4592 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4),
4593 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5),
4594 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6),
4595 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7),
Adrian Knoth11a5cd32013-07-05 11:27:57 +02004596 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8),
4597 HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro),
4598 HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004599};
4600
4601static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = {
4602 HDSPM_MIXER("Mixer", 0),
4603 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4604 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4605 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4606 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4607 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Adrian Knoth2d63ec32013-07-05 11:28:18 +02004608 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 11),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004609 HDSPM_SYNC_CHECK("WC Sync Check", 0),
4610 HDSPM_SYNC_CHECK("AES1 Sync Check", 1),
4611 HDSPM_SYNC_CHECK("AES2 Sync Check", 2),
4612 HDSPM_SYNC_CHECK("AES3 Sync Check", 3),
4613 HDSPM_SYNC_CHECK("AES4 Sync Check", 4),
4614 HDSPM_SYNC_CHECK("AES5 Sync Check", 5),
4615 HDSPM_SYNC_CHECK("AES6 Sync Check", 6),
4616 HDSPM_SYNC_CHECK("AES7 Sync Check", 7),
4617 HDSPM_SYNC_CHECK("AES8 Sync Check", 8),
4618 HDSPM_SYNC_CHECK("TCO Sync Check", 9),
4619 HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10),
4620 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4621 HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1),
4622 HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2),
4623 HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3),
4624 HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4),
4625 HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5),
4626 HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6),
4627 HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7),
4628 HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8),
4629 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9),
4630 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10),
Adrian Knothc9e16682012-12-03 14:55:50 +01004631 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4632 HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis),
4633 HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby),
4634 HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional),
4635 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004636 HDSPM_DS_WIRE("Double Speed Wire Mode", 0),
4637 HDSPM_QS_WIRE("Quad Speed Wire Mode", 0),
4638};
4639
Adrian Knoth0dca1792011-01-26 19:32:14 +01004640
4641
4642/* Control elements for the optional TCO module */
4643static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
4644 HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0),
4645 HDSPM_TCO_PULL("TCO Pull", 0),
4646 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
4647 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
4648 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
Adrian Knotha8176502013-03-10 00:37:27 +01004649 HDSPM_TCO_WORD_TERM("TCO Word Term", 0),
4650 HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11),
4651 HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12),
4652 HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0),
4653 HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0)
Adrian Knoth0dca1792011-01-26 19:32:14 +01004654};
4655
4656
Takashi Iwai98274f02005-11-17 14:52:34 +01004657static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
Takashi Iwai763f3562005-06-03 11:25:34 +02004658
4659
Takashi Iwai98274f02005-11-17 14:52:34 +01004660static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004661{
4662 int i;
4663
Adrian Knoth0dca1792011-01-26 19:32:14 +01004664 for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) {
Takashi Iwai763f3562005-06-03 11:25:34 +02004665 if (hdspm->system_sample_rate > 48000) {
4666 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004667 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
4668 SNDRV_CTL_ELEM_ACCESS_READ |
4669 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004670 } else {
4671 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004672 SNDRV_CTL_ELEM_ACCESS_READWRITE |
4673 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004674 }
4675 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
Adrian Knoth0dca1792011-01-26 19:32:14 +01004676 SNDRV_CTL_EVENT_MASK_INFO,
4677 &hdspm->playback_mixer_ctls[i]->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02004678 }
4679
4680 return 0;
4681}
4682
4683
Adrian Knoth0dca1792011-01-26 19:32:14 +01004684static int snd_hdspm_create_controls(struct snd_card *card,
4685 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004686{
4687 unsigned int idx, limit;
4688 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01004689 struct snd_kcontrol *kctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004690 struct snd_kcontrol_new *list = NULL;
Takashi Iwai763f3562005-06-03 11:25:34 +02004691
Adrian Knoth0dca1792011-01-26 19:32:14 +01004692 switch (hdspm->io_type) {
4693 case MADI:
4694 list = snd_hdspm_controls_madi;
4695 limit = ARRAY_SIZE(snd_hdspm_controls_madi);
4696 break;
4697 case MADIface:
4698 list = snd_hdspm_controls_madiface;
4699 limit = ARRAY_SIZE(snd_hdspm_controls_madiface);
4700 break;
4701 case AIO:
4702 list = snd_hdspm_controls_aio;
4703 limit = ARRAY_SIZE(snd_hdspm_controls_aio);
4704 break;
4705 case RayDAT:
4706 list = snd_hdspm_controls_raydat;
4707 limit = ARRAY_SIZE(snd_hdspm_controls_raydat);
4708 break;
4709 case AES32:
4710 list = snd_hdspm_controls_aes32;
4711 limit = ARRAY_SIZE(snd_hdspm_controls_aes32);
4712 break;
4713 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004714
Adrian Knoth0dca1792011-01-26 19:32:14 +01004715 if (NULL != list) {
4716 for (idx = 0; idx < limit; idx++) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004717 err = snd_ctl_add(card,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004718 snd_ctl_new1(&list[idx], hdspm));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004719 if (err < 0)
4720 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004721 }
4722 }
4723
Takashi Iwai763f3562005-06-03 11:25:34 +02004724
Adrian Knoth0dca1792011-01-26 19:32:14 +01004725 /* create simple 1:1 playback mixer controls */
Takashi Iwai763f3562005-06-03 11:25:34 +02004726 snd_hdspm_playback_mixer.name = "Chn";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004727 if (hdspm->system_sample_rate >= 128000) {
4728 limit = hdspm->qs_out_channels;
4729 } else if (hdspm->system_sample_rate >= 64000) {
4730 limit = hdspm->ds_out_channels;
4731 } else {
4732 limit = hdspm->ss_out_channels;
4733 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004734 for (idx = 0; idx < limit; ++idx) {
4735 snd_hdspm_playback_mixer.index = idx + 1;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004736 kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm);
4737 err = snd_ctl_add(card, kctl);
4738 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004739 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004740 hdspm->playback_mixer_ctls[idx] = kctl;
4741 }
4742
Adrian Knoth0dca1792011-01-26 19:32:14 +01004743
4744 if (hdspm->tco) {
4745 /* add tco control elements */
4746 list = snd_hdspm_controls_tco;
4747 limit = ARRAY_SIZE(snd_hdspm_controls_tco);
4748 for (idx = 0; idx < limit; idx++) {
4749 err = snd_ctl_add(card,
4750 snd_ctl_new1(&list[idx], hdspm));
4751 if (err < 0)
4752 return err;
4753 }
4754 }
4755
Takashi Iwai763f3562005-06-03 11:25:34 +02004756 return 0;
4757}
4758
4759/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01004760 /proc interface
Takashi Iwai763f3562005-06-03 11:25:34 +02004761 ------------------------------------------------------------*/
4762
4763static void
Adrian Knoth57601072013-07-05 11:28:04 +02004764snd_hdspm_proc_read_tco(struct snd_info_entry *entry,
4765 struct snd_info_buffer *buffer)
Takashi Iwai763f3562005-06-03 11:25:34 +02004766{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004767 struct hdspm *hdspm = entry->private_data;
Adrian Knoth57601072013-07-05 11:28:04 +02004768 unsigned int status, control;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004769 int a, ltc, frames, seconds, minutes, hours;
4770 unsigned int period;
4771 u64 freq_const = 0;
4772 u32 rate;
4773
Adrian Knoth57601072013-07-05 11:28:04 +02004774 snd_iprintf(buffer, "--- TCO ---\n");
4775
Takashi Iwai763f3562005-06-03 11:25:34 +02004776 status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004777 control = hdspm->control_register;
Takashi Iwai763f3562005-06-03 11:25:34 +02004778
Adrian Knoth0dca1792011-01-26 19:32:14 +01004779
Adrian Knoth0dca1792011-01-26 19:32:14 +01004780 if (status & HDSPM_tco_detect) {
4781 snd_iprintf(buffer, "TCO module detected.\n");
4782 a = hdspm_read(hdspm, HDSPM_RD_TCO+4);
4783 if (a & HDSPM_TCO1_LTC_Input_valid) {
4784 snd_iprintf(buffer, " LTC valid, ");
4785 switch (a & (HDSPM_TCO1_LTC_Format_LSB |
4786 HDSPM_TCO1_LTC_Format_MSB)) {
4787 case 0:
4788 snd_iprintf(buffer, "24 fps, ");
4789 break;
4790 case HDSPM_TCO1_LTC_Format_LSB:
4791 snd_iprintf(buffer, "25 fps, ");
4792 break;
4793 case HDSPM_TCO1_LTC_Format_MSB:
4794 snd_iprintf(buffer, "29.97 fps, ");
4795 break;
4796 default:
4797 snd_iprintf(buffer, "30 fps, ");
4798 break;
4799 }
4800 if (a & HDSPM_TCO1_set_drop_frame_flag) {
4801 snd_iprintf(buffer, "drop frame\n");
4802 } else {
4803 snd_iprintf(buffer, "full frame\n");
4804 }
4805 } else {
4806 snd_iprintf(buffer, " no LTC\n");
4807 }
4808 if (a & HDSPM_TCO1_Video_Input_Format_NTSC) {
4809 snd_iprintf(buffer, " Video: NTSC\n");
4810 } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) {
4811 snd_iprintf(buffer, " Video: PAL\n");
4812 } else {
4813 snd_iprintf(buffer, " No video\n");
4814 }
4815 if (a & HDSPM_TCO1_TCO_lock) {
4816 snd_iprintf(buffer, " Sync: lock\n");
4817 } else {
4818 snd_iprintf(buffer, " Sync: no lock\n");
4819 }
4820
4821 switch (hdspm->io_type) {
4822 case MADI:
4823 case AES32:
4824 freq_const = 110069313433624ULL;
4825 break;
4826 case RayDAT:
4827 case AIO:
4828 freq_const = 104857600000000ULL;
4829 break;
4830 case MADIface:
4831 break; /* no TCO possible */
4832 }
4833
4834 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
4835 snd_iprintf(buffer, " period: %u\n", period);
4836
4837
4838 /* rate = freq_const/period; */
4839 rate = div_u64(freq_const, period);
4840
4841 if (control & HDSPM_QuadSpeed) {
4842 rate *= 4;
4843 } else if (control & HDSPM_DoubleSpeed) {
4844 rate *= 2;
4845 }
4846
4847 snd_iprintf(buffer, " Frequency: %u Hz\n",
4848 (unsigned int) rate);
4849
4850 ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
4851 frames = ltc & 0xF;
4852 ltc >>= 4;
4853 frames += (ltc & 0x3) * 10;
4854 ltc >>= 4;
4855 seconds = ltc & 0xF;
4856 ltc >>= 4;
4857 seconds += (ltc & 0x7) * 10;
4858 ltc >>= 4;
4859 minutes = ltc & 0xF;
4860 ltc >>= 4;
4861 minutes += (ltc & 0x7) * 10;
4862 ltc >>= 4;
4863 hours = ltc & 0xF;
4864 ltc >>= 4;
4865 hours += (ltc & 0x3) * 10;
4866 snd_iprintf(buffer,
4867 " LTC In: %02d:%02d:%02d:%02d\n",
4868 hours, minutes, seconds, frames);
4869
4870 } else {
4871 snd_iprintf(buffer, "No TCO module detected.\n");
4872 }
Adrian Knoth57601072013-07-05 11:28:04 +02004873}
4874
4875static void
4876snd_hdspm_proc_read_madi(struct snd_info_entry *entry,
4877 struct snd_info_buffer *buffer)
4878{
4879 struct hdspm *hdspm = entry->private_data;
4880 unsigned int status, status2, control, freq;
4881
4882 char *pref_sync_ref;
4883 char *autosync_ref;
4884 char *system_clock_mode;
4885 char *insel;
4886 int x, x2;
4887
4888 status = hdspm_read(hdspm, HDSPM_statusRegister);
4889 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
4890 control = hdspm->control_register;
4891 freq = hdspm_read(hdspm, HDSPM_timecodeRegister);
4892
4893 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
4894 hdspm->card_name, hdspm->card->number + 1,
4895 hdspm->firmware_rev,
4896 (status2 & HDSPM_version0) |
4897 (status2 & HDSPM_version1) | (status2 &
4898 HDSPM_version2));
4899
4900 snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n",
4901 (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF,
4902 hdspm->serial);
4903
4904 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
4905 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
4906
4907 snd_iprintf(buffer, "--- System ---\n");
4908
4909 snd_iprintf(buffer,
4910 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
4911 status & HDSPM_audioIRQPending,
4912 (status & HDSPM_midi0IRQPending) ? 1 : 0,
4913 (status & HDSPM_midi1IRQPending) ? 1 : 0,
4914 hdspm->irq_count);
4915 snd_iprintf(buffer,
4916 "HW pointer: id = %d, rawptr = %d (%d->%d) "
4917 "estimated= %ld (bytes)\n",
4918 ((status & HDSPM_BufferID) ? 1 : 0),
4919 (status & HDSPM_BufferPositionMask),
4920 (status & HDSPM_BufferPositionMask) %
4921 (2 * (int)hdspm->period_bytes),
4922 ((status & HDSPM_BufferPositionMask) - 64) %
4923 (2 * (int)hdspm->period_bytes),
4924 (long) hdspm_hw_pointer(hdspm) * 4);
4925
4926 snd_iprintf(buffer,
4927 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
4928 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
4929 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
4930 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
4931 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
4932 snd_iprintf(buffer,
4933 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
4934 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
4935 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
4936 snd_iprintf(buffer,
4937 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
4938 "status2=0x%x\n",
4939 hdspm->control_register, hdspm->control2_register,
4940 status, status2);
4941
Takashi Iwai763f3562005-06-03 11:25:34 +02004942
4943 snd_iprintf(buffer, "--- Settings ---\n");
4944
Adrian Knoth7cb155f2011-08-15 00:22:53 +02004945 x = hdspm_get_latency(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02004946
4947 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004948 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
4949 x, (unsigned long) hdspm->period_bytes);
Takashi Iwai763f3562005-06-03 11:25:34 +02004950
Adrian Knoth0dca1792011-01-26 19:32:14 +01004951 snd_iprintf(buffer, "Line out: %s\n",
4952 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004953
4954 switch (hdspm->control_register & HDSPM_InputMask) {
4955 case HDSPM_InputOptical:
4956 insel = "Optical";
4957 break;
4958 case HDSPM_InputCoaxial:
4959 insel = "Coaxial";
4960 break;
4961 default:
Masanari Iidaec8f53f2012-11-02 00:28:50 +09004962 insel = "Unknown";
Takashi Iwai763f3562005-06-03 11:25:34 +02004963 }
4964
Takashi Iwai763f3562005-06-03 11:25:34 +02004965 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004966 "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
4967 "Auto Input %s\n",
4968 (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off",
4969 (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56",
4970 (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004971
Adrian Knoth0dca1792011-01-26 19:32:14 +01004972
Remy Bruno3cee5a62006-10-16 12:46:32 +02004973 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
Adrian Knoth0dca1792011-01-26 19:32:14 +01004974 system_clock_mode = "AutoSync";
Remy Bruno3cee5a62006-10-16 12:46:32 +02004975 else
Takashi Iwai763f3562005-06-03 11:25:34 +02004976 system_clock_mode = "Master";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004977 snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode);
Takashi Iwai763f3562005-06-03 11:25:34 +02004978
4979 switch (hdspm_pref_sync_ref(hdspm)) {
4980 case HDSPM_SYNC_FROM_WORD:
4981 pref_sync_ref = "Word Clock";
4982 break;
4983 case HDSPM_SYNC_FROM_MADI:
4984 pref_sync_ref = "MADI Sync";
4985 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004986 case HDSPM_SYNC_FROM_TCO:
4987 pref_sync_ref = "TCO";
4988 break;
4989 case HDSPM_SYNC_FROM_SYNC_IN:
4990 pref_sync_ref = "Sync In";
4991 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02004992 default:
4993 pref_sync_ref = "XXXX Clock";
4994 break;
4995 }
4996 snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004997 pref_sync_ref);
Takashi Iwai763f3562005-06-03 11:25:34 +02004998
4999 snd_iprintf(buffer, "System Clock Frequency: %d\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01005000 hdspm->system_sample_rate);
Takashi Iwai763f3562005-06-03 11:25:34 +02005001
5002
5003 snd_iprintf(buffer, "--- Status:\n");
5004
5005 x = status & HDSPM_madiSync;
5006 x2 = status2 & HDSPM_wcSync;
5007
5008 snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01005009 (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
5010 "NoLock",
5011 (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
5012 "NoLock");
Takashi Iwai763f3562005-06-03 11:25:34 +02005013
5014 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005015 case HDSPM_AUTOSYNC_FROM_SYNC_IN:
5016 autosync_ref = "Sync In";
5017 break;
5018 case HDSPM_AUTOSYNC_FROM_TCO:
5019 autosync_ref = "TCO";
5020 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02005021 case HDSPM_AUTOSYNC_FROM_WORD:
5022 autosync_ref = "Word Clock";
5023 break;
5024 case HDSPM_AUTOSYNC_FROM_MADI:
5025 autosync_ref = "MADI Sync";
5026 break;
5027 case HDSPM_AUTOSYNC_FROM_NONE:
5028 autosync_ref = "Input not valid";
5029 break;
5030 default:
5031 autosync_ref = "---";
5032 break;
5033 }
5034 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005035 "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
5036 autosync_ref, hdspm_external_sample_rate(hdspm),
5037 (status & HDSPM_madiFreqMask) >> 22,
5038 (status2 & HDSPM_wcFreqMask) >> 5);
Takashi Iwai763f3562005-06-03 11:25:34 +02005039
5040 snd_iprintf(buffer, "Input: %s, Mode=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01005041 (status & HDSPM_AB_int) ? "Coax" : "Optical",
5042 (status & HDSPM_RX_64ch) ? "64 channels" :
5043 "56 channels");
Takashi Iwai763f3562005-06-03 11:25:34 +02005044
Adrian Knoth57601072013-07-05 11:28:04 +02005045 /* call readout function for TCO specific status */
5046 snd_hdspm_proc_read_tco(entry, buffer);
5047
Takashi Iwai763f3562005-06-03 11:25:34 +02005048 snd_iprintf(buffer, "\n");
5049}
5050
Remy Bruno3cee5a62006-10-16 12:46:32 +02005051static void
5052snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
5053 struct snd_info_buffer *buffer)
5054{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005055 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005056 unsigned int status;
5057 unsigned int status2;
5058 unsigned int timecode;
Andre Schramm56bde0f2013-01-09 14:40:18 +01005059 unsigned int wcLock, wcSync;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005060 int pref_syncref;
5061 char *autosync_ref;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005062 int x;
5063
5064 status = hdspm_read(hdspm, HDSPM_statusRegister);
5065 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
5066 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
5067
5068 snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n",
5069 hdspm->card_name, hdspm->card->number + 1,
5070 hdspm->firmware_rev);
5071
5072 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
5073 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
5074
5075 snd_iprintf(buffer, "--- System ---\n");
5076
5077 snd_iprintf(buffer,
5078 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
5079 status & HDSPM_audioIRQPending,
5080 (status & HDSPM_midi0IRQPending) ? 1 : 0,
5081 (status & HDSPM_midi1IRQPending) ? 1 : 0,
5082 hdspm->irq_count);
5083 snd_iprintf(buffer,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005084 "HW pointer: id = %d, rawptr = %d (%d->%d) "
5085 "estimated= %ld (bytes)\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005086 ((status & HDSPM_BufferID) ? 1 : 0),
5087 (status & HDSPM_BufferPositionMask),
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005088 (status & HDSPM_BufferPositionMask) %
5089 (2 * (int)hdspm->period_bytes),
5090 ((status & HDSPM_BufferPositionMask) - 64) %
5091 (2 * (int)hdspm->period_bytes),
Remy Bruno3cee5a62006-10-16 12:46:32 +02005092 (long) hdspm_hw_pointer(hdspm) * 4);
5093
5094 snd_iprintf(buffer,
5095 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
5096 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
5097 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
5098 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
5099 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
5100 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005101 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
5102 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
5103 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
5104 snd_iprintf(buffer,
5105 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
5106 "status2=0x%x\n",
5107 hdspm->control_register, hdspm->control2_register,
5108 status, status2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02005109
5110 snd_iprintf(buffer, "--- Settings ---\n");
5111
Adrian Knoth7cb155f2011-08-15 00:22:53 +02005112 x = hdspm_get_latency(hdspm);
Remy Bruno3cee5a62006-10-16 12:46:32 +02005113
5114 snd_iprintf(buffer,
5115 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
5116 x, (unsigned long) hdspm->period_bytes);
5117
Adrian Knoth0dca1792011-01-26 19:32:14 +01005118 snd_iprintf(buffer, "Line out: %s\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005119 (hdspm->
Adrian Knoth0dca1792011-01-26 19:32:14 +01005120 control_register & HDSPM_LineOut) ? "on " : "off");
Remy Bruno3cee5a62006-10-16 12:46:32 +02005121
5122 snd_iprintf(buffer,
5123 "ClearTrackMarker %s, Emphasis %s, Dolby %s\n",
5124 (hdspm->
5125 control_register & HDSPM_clr_tms) ? "on" : "off",
5126 (hdspm->
5127 control_register & HDSPM_Emphasis) ? "on" : "off",
5128 (hdspm->
5129 control_register & HDSPM_Dolby) ? "on" : "off");
5130
Remy Bruno3cee5a62006-10-16 12:46:32 +02005131
5132 pref_syncref = hdspm_pref_sync_ref(hdspm);
5133 if (pref_syncref == 0)
5134 snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n");
5135 else
5136 snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n",
5137 pref_syncref);
5138
5139 snd_iprintf(buffer, "System Clock Frequency: %d\n",
5140 hdspm->system_sample_rate);
5141
5142 snd_iprintf(buffer, "Double speed: %s\n",
5143 hdspm->control_register & HDSPM_DS_DoubleWire?
5144 "Double wire" : "Single wire");
5145 snd_iprintf(buffer, "Quad speed: %s\n",
5146 hdspm->control_register & HDSPM_QS_DoubleWire?
5147 "Double wire" :
5148 hdspm->control_register & HDSPM_QS_QuadWire?
5149 "Quad wire" : "Single wire");
5150
5151 snd_iprintf(buffer, "--- Status:\n");
5152
Andre Schramm56bde0f2013-01-09 14:40:18 +01005153 wcLock = status & HDSPM_AES32_wcLock;
5154 wcSync = wcLock && (status & HDSPM_AES32_wcSync);
5155
Remy Bruno3cee5a62006-10-16 12:46:32 +02005156 snd_iprintf(buffer, "Word: %s Frequency: %d\n",
Andre Schramm56bde0f2013-01-09 14:40:18 +01005157 (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005158 HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02005159
5160 for (x = 0; x < 8; x++) {
5161 snd_iprintf(buffer, "AES%d: %s Frequency: %d\n",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005162 x+1,
5163 (status2 & (HDSPM_LockAES >> x)) ?
Adrian Knoth0dca1792011-01-26 19:32:14 +01005164 "Sync " : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005165 HDSPM_bit2freq((timecode >> (4*x)) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02005166 }
5167
5168 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005169 case HDSPM_AES32_AUTOSYNC_FROM_NONE:
5170 autosync_ref = "None"; break;
5171 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
5172 autosync_ref = "Word Clock"; break;
5173 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
5174 autosync_ref = "AES1"; break;
5175 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
5176 autosync_ref = "AES2"; break;
5177 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
5178 autosync_ref = "AES3"; break;
5179 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
5180 autosync_ref = "AES4"; break;
5181 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
5182 autosync_ref = "AES5"; break;
5183 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
5184 autosync_ref = "AES6"; break;
5185 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
5186 autosync_ref = "AES7"; break;
5187 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
5188 autosync_ref = "AES8"; break;
Adrian Knoth194062d2013-07-05 11:28:16 +02005189 case HDSPM_AES32_AUTOSYNC_FROM_TCO:
5190 autosync_ref = "TCO"; break;
5191 case HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN:
5192 autosync_ref = "Sync In"; break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005193 default:
5194 autosync_ref = "---"; break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005195 }
5196 snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref);
5197
Adrian Knoth194062d2013-07-05 11:28:16 +02005198 /* call readout function for TCO specific status */
5199 snd_hdspm_proc_read_tco(entry, buffer);
5200
Remy Bruno3cee5a62006-10-16 12:46:32 +02005201 snd_iprintf(buffer, "\n");
5202}
5203
Adrian Knoth0dca1792011-01-26 19:32:14 +01005204static void
5205snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
5206 struct snd_info_buffer *buffer)
5207{
5208 struct hdspm *hdspm = entry->private_data;
5209 unsigned int status1, status2, status3, control, i;
5210 unsigned int lock, sync;
5211
5212 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
5213 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
5214 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
5215
5216 control = hdspm->control_register;
5217
5218 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
5219 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
5220 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
5221
5222
5223 snd_iprintf(buffer, "\n*** CLOCK MODE\n\n");
5224
5225 snd_iprintf(buffer, "Clock mode : %s\n",
5226 (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave");
5227 snd_iprintf(buffer, "System frequency: %d Hz\n",
5228 hdspm_get_system_sample_rate(hdspm));
5229
5230 snd_iprintf(buffer, "\n*** INPUT STATUS\n\n");
5231
5232 lock = 0x1;
5233 sync = 0x100;
5234
5235 for (i = 0; i < 8; i++) {
5236 snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n",
5237 i,
5238 (status1 & lock) ? 1 : 0,
5239 (status1 & sync) ? 1 : 0,
5240 texts_freq[(status2 >> (i * 4)) & 0xF]);
5241
5242 lock = lock<<1;
5243 sync = sync<<1;
5244 }
5245
5246 snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n",
5247 (status1 & 0x1000000) ? 1 : 0,
5248 (status1 & 0x2000000) ? 1 : 0,
5249 texts_freq[(status1 >> 16) & 0xF]);
5250
5251 snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n",
5252 (status1 & 0x4000000) ? 1 : 0,
5253 (status1 & 0x8000000) ? 1 : 0,
5254 texts_freq[(status1 >> 20) & 0xF]);
5255
5256 snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n",
5257 (status3 & 0x400) ? 1 : 0,
5258 (status3 & 0x800) ? 1 : 0,
5259 texts_freq[(status2 >> 12) & 0xF]);
5260
5261}
5262
Remy Bruno3cee5a62006-10-16 12:46:32 +02005263#ifdef CONFIG_SND_DEBUG
5264static void
Adrian Knoth0dca1792011-01-26 19:32:14 +01005265snd_hdspm_proc_read_debug(struct snd_info_entry *entry,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005266 struct snd_info_buffer *buffer)
5267{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005268 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005269
5270 int j,i;
5271
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005272 for (i = 0; i < 256 /* 1024*64 */; i += j) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02005273 snd_iprintf(buffer, "0x%08X: ", i);
5274 for (j = 0; j < 16; j += 4)
5275 snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
5276 snd_iprintf(buffer, "\n");
5277 }
5278}
5279#endif
5280
5281
Adrian Knoth0dca1792011-01-26 19:32:14 +01005282static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry,
5283 struct snd_info_buffer *buffer)
5284{
5285 struct hdspm *hdspm = entry->private_data;
5286 int i;
Remy Bruno3cee5a62006-10-16 12:46:32 +02005287
Adrian Knoth0dca1792011-01-26 19:32:14 +01005288 snd_iprintf(buffer, "# generated by hdspm\n");
5289
5290 for (i = 0; i < hdspm->max_channels_in; i++) {
5291 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]);
5292 }
5293}
5294
5295static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry,
5296 struct snd_info_buffer *buffer)
5297{
5298 struct hdspm *hdspm = entry->private_data;
5299 int i;
5300
5301 snd_iprintf(buffer, "# generated by hdspm\n");
5302
5303 for (i = 0; i < hdspm->max_channels_out; i++) {
5304 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]);
5305 }
5306}
5307
5308
Bill Pembertone23e7a12012-12-06 12:35:10 -05005309static void snd_hdspm_proc_init(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005310{
Takashi Iwai98274f02005-11-17 14:52:34 +01005311 struct snd_info_entry *entry;
Takashi Iwai763f3562005-06-03 11:25:34 +02005312
Adrian Knoth0dca1792011-01-26 19:32:14 +01005313 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) {
5314 switch (hdspm->io_type) {
5315 case AES32:
5316 snd_info_set_text_ops(entry, hdspm,
5317 snd_hdspm_proc_read_aes32);
5318 break;
5319 case MADI:
5320 snd_info_set_text_ops(entry, hdspm,
5321 snd_hdspm_proc_read_madi);
5322 break;
5323 case MADIface:
5324 /* snd_info_set_text_ops(entry, hdspm,
5325 snd_hdspm_proc_read_madiface); */
5326 break;
5327 case RayDAT:
5328 snd_info_set_text_ops(entry, hdspm,
5329 snd_hdspm_proc_read_raydat);
5330 break;
5331 case AIO:
5332 break;
5333 }
5334 }
5335
5336 if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) {
5337 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in);
5338 }
5339
5340 if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) {
5341 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out);
5342 }
5343
Remy Bruno3cee5a62006-10-16 12:46:32 +02005344#ifdef CONFIG_SND_DEBUG
5345 /* debug file to read all hdspm registers */
5346 if (!snd_card_proc_new(hdspm->card, "debug", &entry))
5347 snd_info_set_text_ops(entry, hdspm,
5348 snd_hdspm_proc_read_debug);
5349#endif
Takashi Iwai763f3562005-06-03 11:25:34 +02005350}
5351
5352/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005353 hdspm intitialize
Takashi Iwai763f3562005-06-03 11:25:34 +02005354 ------------------------------------------------------------*/
5355
Takashi Iwai98274f02005-11-17 14:52:34 +01005356static int snd_hdspm_set_defaults(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005357{
Takashi Iwai763f3562005-06-03 11:25:34 +02005358 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
Joe Perches561de312007-12-18 13:13:47 +01005359 hold it (e.g. during module initialization).
Adrian Knoth0dca1792011-01-26 19:32:14 +01005360 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005361
5362 /* set defaults: */
5363
Adrian Knoth0dca1792011-01-26 19:32:14 +01005364 hdspm->settings_register = 0;
5365
5366 switch (hdspm->io_type) {
5367 case MADI:
5368 case MADIface:
5369 hdspm->control_register =
5370 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5371 break;
5372
5373 case RayDAT:
5374 case AIO:
5375 hdspm->settings_register = 0x1 + 0x1000;
5376 /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0,
5377 * line_out */
5378 hdspm->control_register =
5379 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5380 break;
5381
5382 case AES32:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005383 hdspm->control_register =
Adrian Knothe71b95a2013-07-05 11:28:06 +02005384 HDSPM_ClockModeMaster | /* Master Clock Mode on */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005385 hdspm_encode_latency(7) | /* latency max=8192samples */
Remy Bruno3cee5a62006-10-16 12:46:32 +02005386 HDSPM_SyncRef0 | /* AES1 is syncclock */
5387 HDSPM_LineOut | /* Analog output in */
5388 HDSPM_Professional; /* Professional mode */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005389 break;
5390 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005391
5392 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5393
Adrian Knoth0dca1792011-01-26 19:32:14 +01005394 if (AES32 == hdspm->io_type) {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005395 /* No control2 register for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005396#ifdef SNDRV_BIG_ENDIAN
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005397 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
Takashi Iwai763f3562005-06-03 11:25:34 +02005398#else
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005399 hdspm->control2_register = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02005400#endif
5401
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005402 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
5403 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005404 hdspm_compute_period_size(hdspm);
5405
5406 /* silence everything */
5407
5408 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
5409
Adrian Knothb2ed6322013-07-05 11:27:54 +02005410 if (hdspm_is_raydat_or_aio(hdspm))
Adrian Knoth0dca1792011-01-26 19:32:14 +01005411 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
Takashi Iwai763f3562005-06-03 11:25:34 +02005412
5413 /* set a default rate so that the channel map is set up. */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005414 hdspm_set_rate(hdspm, 48000, 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02005415
5416 return 0;
5417}
5418
5419
5420/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005421 interrupt
Takashi Iwai763f3562005-06-03 11:25:34 +02005422 ------------------------------------------------------------*/
5423
David Howells7d12e782006-10-05 14:55:46 +01005424static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
Takashi Iwai763f3562005-06-03 11:25:34 +02005425{
Takashi Iwai98274f02005-11-17 14:52:34 +01005426 struct hdspm *hdspm = (struct hdspm *) dev_id;
Takashi Iwai763f3562005-06-03 11:25:34 +02005427 unsigned int status;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005428 int i, audio, midi, schedule = 0;
5429 /* cycles_t now; */
Takashi Iwai763f3562005-06-03 11:25:34 +02005430
5431 status = hdspm_read(hdspm, HDSPM_statusRegister);
5432
5433 audio = status & HDSPM_audioIRQPending;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005434 midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending |
5435 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
Takashi Iwai763f3562005-06-03 11:25:34 +02005436
Adrian Knoth0dca1792011-01-26 19:32:14 +01005437 /* now = get_cycles(); */
5438 /**
5439 * LAT_2..LAT_0 period counter (win) counter (mac)
5440 * 6 4096 ~256053425 ~514672358
5441 * 5 2048 ~128024983 ~257373821
5442 * 4 1024 ~64023706 ~128718089
5443 * 3 512 ~32005945 ~64385999
5444 * 2 256 ~16003039 ~32260176
5445 * 1 128 ~7998738 ~16194507
5446 * 0 64 ~3998231 ~8191558
5447 **/
5448 /*
5449 snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n",
5450 now-hdspm->last_interrupt, status & 0xFFC0);
5451 hdspm->last_interrupt = now;
5452 */
5453
5454 if (!audio && !midi)
Takashi Iwai763f3562005-06-03 11:25:34 +02005455 return IRQ_NONE;
5456
5457 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
5458 hdspm->irq_count++;
5459
Takashi Iwai763f3562005-06-03 11:25:34 +02005460
5461 if (audio) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005462 if (hdspm->capture_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005463 snd_pcm_period_elapsed(hdspm->capture_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005464
5465 if (hdspm->playback_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005466 snd_pcm_period_elapsed(hdspm->playback_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005467 }
5468
Adrian Knoth0dca1792011-01-26 19:32:14 +01005469 if (midi) {
5470 i = 0;
5471 while (i < hdspm->midiPorts) {
5472 if ((hdspm_read(hdspm,
5473 hdspm->midi[i].statusIn) & 0xff) &&
5474 (status & hdspm->midi[i].irq)) {
5475 /* we disable interrupts for this input until
5476 * processing is done
5477 */
5478 hdspm->control_register &= ~hdspm->midi[i].ie;
5479 hdspm_write(hdspm, HDSPM_controlRegister,
5480 hdspm->control_register);
5481 hdspm->midi[i].pending = 1;
5482 schedule = 1;
5483 }
5484
5485 i++;
5486 }
5487
5488 if (schedule)
5489 tasklet_hi_schedule(&hdspm->midi_tasklet);
Takashi Iwai763f3562005-06-03 11:25:34 +02005490 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005491
Takashi Iwai763f3562005-06-03 11:25:34 +02005492 return IRQ_HANDLED;
5493}
5494
5495/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005496 pcm interface
Takashi Iwai763f3562005-06-03 11:25:34 +02005497 ------------------------------------------------------------*/
5498
5499
Adrian Knoth0dca1792011-01-26 19:32:14 +01005500static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream
5501 *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005502{
Takashi Iwai98274f02005-11-17 14:52:34 +01005503 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005504 return hdspm_hw_pointer(hdspm);
5505}
5506
Takashi Iwai763f3562005-06-03 11:25:34 +02005507
Takashi Iwai98274f02005-11-17 14:52:34 +01005508static int snd_hdspm_reset(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005509{
Takashi Iwai98274f02005-11-17 14:52:34 +01005510 struct snd_pcm_runtime *runtime = substream->runtime;
5511 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5512 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005513
5514 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5515 other = hdspm->capture_substream;
5516 else
5517 other = hdspm->playback_substream;
5518
5519 if (hdspm->running)
5520 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
5521 else
5522 runtime->status->hw_ptr = 0;
5523 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005524 struct snd_pcm_substream *s;
5525 struct snd_pcm_runtime *oruntime = other->runtime;
Takashi Iwaief991b92007-02-22 12:52:53 +01005526 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005527 if (s == other) {
5528 oruntime->status->hw_ptr =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005529 runtime->status->hw_ptr;
Takashi Iwai763f3562005-06-03 11:25:34 +02005530 break;
5531 }
5532 }
5533 }
5534 return 0;
5535}
5536
Takashi Iwai98274f02005-11-17 14:52:34 +01005537static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5538 struct snd_pcm_hw_params *params)
Takashi Iwai763f3562005-06-03 11:25:34 +02005539{
Takashi Iwai98274f02005-11-17 14:52:34 +01005540 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005541 int err;
5542 int i;
5543 pid_t this_pid;
5544 pid_t other_pid;
Takashi Iwai763f3562005-06-03 11:25:34 +02005545
5546 spin_lock_irq(&hdspm->lock);
5547
5548 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5549 this_pid = hdspm->playback_pid;
5550 other_pid = hdspm->capture_pid;
5551 } else {
5552 this_pid = hdspm->capture_pid;
5553 other_pid = hdspm->playback_pid;
5554 }
5555
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005556 if (other_pid > 0 && this_pid != other_pid) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005557
5558 /* The other stream is open, and not by the same
5559 task as this one. Make sure that the parameters
5560 that matter are the same.
Adrian Knoth0dca1792011-01-26 19:32:14 +01005561 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005562
5563 if (params_rate(params) != hdspm->system_sample_rate) {
5564 spin_unlock_irq(&hdspm->lock);
5565 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005566 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005567 return -EBUSY;
5568 }
5569
5570 if (params_period_size(params) != hdspm->period_bytes / 4) {
5571 spin_unlock_irq(&hdspm->lock);
5572 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005573 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005574 return -EBUSY;
5575 }
5576
5577 }
5578 /* We're fine. */
5579 spin_unlock_irq(&hdspm->lock);
5580
5581 /* how to make sure that the rate matches an externally-set one ? */
5582
5583 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005584 err = hdspm_set_rate(hdspm, params_rate(params), 0);
5585 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005586 snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005587 spin_unlock_irq(&hdspm->lock);
5588 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005589 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005590 return err;
5591 }
5592 spin_unlock_irq(&hdspm->lock);
5593
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005594 err = hdspm_set_interrupt_interval(hdspm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005595 params_period_size(params));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005596 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005597 snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005598 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005599 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005600 return err;
5601 }
5602
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005603 /* Memory allocation, takashi's method, dont know if we should
5604 * spinlock
5605 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005606 /* malloc all buffer even if not enabled to get sure */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005607 /* Update for MADI rev 204: we need to allocate for all channels,
5608 * otherwise it doesn't work at 96kHz */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005609
Takashi Iwai763f3562005-06-03 11:25:34 +02005610 err =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005611 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
5612 if (err < 0) {
5613 snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005614 return err;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005615 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005616
Takashi Iwai763f3562005-06-03 11:25:34 +02005617 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5618
Takashi Iwai77a23f22008-08-21 13:00:13 +02005619 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
Takashi Iwai763f3562005-06-03 11:25:34 +02005620 params_channels(params));
5621
5622 for (i = 0; i < params_channels(params); ++i)
5623 snd_hdspm_enable_out(hdspm, i, 1);
5624
5625 hdspm->playback_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005626 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005627 snd_printdd("Allocated sample buffer for playback at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005628 hdspm->playback_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005629 } else {
Takashi Iwai77a23f22008-08-21 13:00:13 +02005630 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
Takashi Iwai763f3562005-06-03 11:25:34 +02005631 params_channels(params));
5632
5633 for (i = 0; i < params_channels(params); ++i)
5634 snd_hdspm_enable_in(hdspm, i, 1);
5635
5636 hdspm->capture_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005637 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005638 snd_printdd("Allocated sample buffer for capture at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005639 hdspm->capture_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005640 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005641
Remy Bruno3cee5a62006-10-16 12:46:32 +02005642 /*
5643 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
5644 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5645 "playback" : "capture",
Takashi Iwai77a23f22008-08-21 13:00:13 +02005646 snd_pcm_sgbuf_get_addr(substream, 0));
Adrian Knoth0dca1792011-01-26 19:32:14 +01005647 */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005648 /*
Adrian Knoth0dca1792011-01-26 19:32:14 +01005649 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
5650 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5651 "playback" : "capture",
5652 params_rate(params), params_channels(params),
5653 params_buffer_size(params));
5654 */
5655
5656
Adrian Knoth3ac9b0a2013-07-05 11:28:13 +02005657 /* For AES cards, the float format bit is the same as the
5658 * preferred sync reference. Since we don't want to break
5659 * sync settings, we have to skip the remaining part of this
5660 * function.
5661 */
5662 if (hdspm->io_type == AES32) {
5663 return 0;
5664 }
5665
5666
Adrian Knoth0dca1792011-01-26 19:32:14 +01005667 /* Switch to native float format if requested */
5668 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
5669 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
5670 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n");
5671
5672 hdspm->control_register |= HDSPe_FLOAT_FORMAT;
5673 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
5674 if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
5675 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n");
5676
5677 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
5678 }
5679 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5680
Takashi Iwai763f3562005-06-03 11:25:34 +02005681 return 0;
5682}
5683
Takashi Iwai98274f02005-11-17 14:52:34 +01005684static int snd_hdspm_hw_free(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005685{
5686 int i;
Takashi Iwai98274f02005-11-17 14:52:34 +01005687 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005688
5689 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5690
Adrian Knoth0dca1792011-01-26 19:32:14 +01005691 /* params_channels(params) should be enough,
Takashi Iwai763f3562005-06-03 11:25:34 +02005692 but to get sure in case of error */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005693 for (i = 0; i < hdspm->max_channels_out; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005694 snd_hdspm_enable_out(hdspm, i, 0);
5695
5696 hdspm->playback_buffer = NULL;
5697 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005698 for (i = 0; i < hdspm->max_channels_in; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005699 snd_hdspm_enable_in(hdspm, i, 0);
5700
5701 hdspm->capture_buffer = NULL;
5702
5703 }
5704
5705 snd_pcm_lib_free_pages(substream);
5706
5707 return 0;
5708}
5709
Adrian Knoth0dca1792011-01-26 19:32:14 +01005710
Takashi Iwai98274f02005-11-17 14:52:34 +01005711static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005712 struct snd_pcm_channel_info *info)
Takashi Iwai763f3562005-06-03 11:25:34 +02005713{
Takashi Iwai98274f02005-11-17 14:52:34 +01005714 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005715
Adrian Knoth0dca1792011-01-26 19:32:14 +01005716 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5717 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
5718 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel);
5719 return -EINVAL;
5720 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005721
Adrian Knoth0dca1792011-01-26 19:32:14 +01005722 if (hdspm->channel_map_out[info->channel] < 0) {
5723 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel);
5724 return -EINVAL;
5725 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005726
Adrian Knoth0dca1792011-01-26 19:32:14 +01005727 info->offset = hdspm->channel_map_out[info->channel] *
5728 HDSPM_CHANNEL_BUFFER_BYTES;
5729 } else {
5730 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
5731 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel);
5732 return -EINVAL;
5733 }
5734
5735 if (hdspm->channel_map_in[info->channel] < 0) {
5736 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel);
5737 return -EINVAL;
5738 }
5739
5740 info->offset = hdspm->channel_map_in[info->channel] *
5741 HDSPM_CHANNEL_BUFFER_BYTES;
5742 }
5743
Takashi Iwai763f3562005-06-03 11:25:34 +02005744 info->first = 0;
5745 info->step = 32;
5746 return 0;
5747}
5748
Adrian Knoth0dca1792011-01-26 19:32:14 +01005749
Takashi Iwai98274f02005-11-17 14:52:34 +01005750static int snd_hdspm_ioctl(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005751 unsigned int cmd, void *arg)
Takashi Iwai763f3562005-06-03 11:25:34 +02005752{
5753 switch (cmd) {
5754 case SNDRV_PCM_IOCTL1_RESET:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005755 return snd_hdspm_reset(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005756
5757 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
Adrian Knoth0dca1792011-01-26 19:32:14 +01005758 {
5759 struct snd_pcm_channel_info *info = arg;
5760 return snd_hdspm_channel_info(substream, info);
5761 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005762 default:
5763 break;
5764 }
5765
5766 return snd_pcm_lib_ioctl(substream, cmd, arg);
5767}
5768
Takashi Iwai98274f02005-11-17 14:52:34 +01005769static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)
Takashi Iwai763f3562005-06-03 11:25:34 +02005770{
Takashi Iwai98274f02005-11-17 14:52:34 +01005771 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5772 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005773 int running;
5774
5775 spin_lock(&hdspm->lock);
5776 running = hdspm->running;
5777 switch (cmd) {
5778 case SNDRV_PCM_TRIGGER_START:
5779 running |= 1 << substream->stream;
5780 break;
5781 case SNDRV_PCM_TRIGGER_STOP:
5782 running &= ~(1 << substream->stream);
5783 break;
5784 default:
5785 snd_BUG();
5786 spin_unlock(&hdspm->lock);
5787 return -EINVAL;
5788 }
5789 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5790 other = hdspm->capture_substream;
5791 else
5792 other = hdspm->playback_substream;
5793
5794 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005795 struct snd_pcm_substream *s;
Takashi Iwaief991b92007-02-22 12:52:53 +01005796 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005797 if (s == other) {
5798 snd_pcm_trigger_done(s, substream);
5799 if (cmd == SNDRV_PCM_TRIGGER_START)
5800 running |= 1 << s->stream;
5801 else
5802 running &= ~(1 << s->stream);
5803 goto _ok;
5804 }
5805 }
5806 if (cmd == SNDRV_PCM_TRIGGER_START) {
5807 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
Adrian Knoth0dca1792011-01-26 19:32:14 +01005808 && substream->stream ==
5809 SNDRV_PCM_STREAM_CAPTURE)
Takashi Iwai763f3562005-06-03 11:25:34 +02005810 hdspm_silence_playback(hdspm);
5811 } else {
5812 if (running &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01005813 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Takashi Iwai763f3562005-06-03 11:25:34 +02005814 hdspm_silence_playback(hdspm);
5815 }
5816 } else {
5817 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
5818 hdspm_silence_playback(hdspm);
5819 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005820_ok:
Takashi Iwai763f3562005-06-03 11:25:34 +02005821 snd_pcm_trigger_done(substream, substream);
5822 if (!hdspm->running && running)
5823 hdspm_start_audio(hdspm);
5824 else if (hdspm->running && !running)
5825 hdspm_stop_audio(hdspm);
5826 hdspm->running = running;
5827 spin_unlock(&hdspm->lock);
5828
5829 return 0;
5830}
5831
Takashi Iwai98274f02005-11-17 14:52:34 +01005832static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005833{
5834 return 0;
5835}
5836
Takashi Iwai98274f02005-11-17 14:52:34 +01005837static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005838 .info = (SNDRV_PCM_INFO_MMAP |
5839 SNDRV_PCM_INFO_MMAP_VALID |
5840 SNDRV_PCM_INFO_NONINTERLEAVED |
5841 SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
5842 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5843 .rates = (SNDRV_PCM_RATE_32000 |
5844 SNDRV_PCM_RATE_44100 |
5845 SNDRV_PCM_RATE_48000 |
5846 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005847 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5848 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ),
Takashi Iwai763f3562005-06-03 11:25:34 +02005849 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005850 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005851 .channels_min = 1,
5852 .channels_max = HDSPM_MAX_CHANNELS,
5853 .buffer_bytes_max =
5854 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
Adrian Knoth1b6fa102011-08-15 00:22:51 +02005855 .period_bytes_min = (32 * 4),
Takashi Iwai52e6fb42011-08-15 10:40:59 +02005856 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005857 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005858 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005859 .fifo_size = 0
5860};
5861
Takashi Iwai98274f02005-11-17 14:52:34 +01005862static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005863 .info = (SNDRV_PCM_INFO_MMAP |
5864 SNDRV_PCM_INFO_MMAP_VALID |
5865 SNDRV_PCM_INFO_NONINTERLEAVED |
5866 SNDRV_PCM_INFO_SYNC_START),
5867 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5868 .rates = (SNDRV_PCM_RATE_32000 |
5869 SNDRV_PCM_RATE_44100 |
5870 SNDRV_PCM_RATE_48000 |
5871 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005872 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5873 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000),
Takashi Iwai763f3562005-06-03 11:25:34 +02005874 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005875 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005876 .channels_min = 1,
5877 .channels_max = HDSPM_MAX_CHANNELS,
5878 .buffer_bytes_max =
5879 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
Adrian Knoth1b6fa102011-08-15 00:22:51 +02005880 .period_bytes_min = (32 * 4),
Takashi Iwai52e6fb42011-08-15 10:40:59 +02005881 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005882 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005883 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005884 .fifo_size = 0
5885};
5886
Adrian Knoth0dca1792011-01-26 19:32:14 +01005887static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5888 struct snd_pcm_hw_rule *rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005889{
Takashi Iwai98274f02005-11-17 14:52:34 +01005890 struct hdspm *hdspm = rule->private;
5891 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005892 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005893 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005894 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5895
Adrian Knoth0dca1792011-01-26 19:32:14 +01005896 if (r->min > 96000 && r->max <= 192000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005897 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005898 .min = hdspm->qs_in_channels,
5899 .max = hdspm->qs_in_channels,
5900 .integer = 1,
5901 };
5902 return snd_interval_refine(c, &t);
5903 } else if (r->min > 48000 && r->max <= 96000) {
5904 struct snd_interval t = {
5905 .min = hdspm->ds_in_channels,
5906 .max = hdspm->ds_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005907 .integer = 1,
5908 };
5909 return snd_interval_refine(c, &t);
5910 } else if (r->max < 64000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005911 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005912 .min = hdspm->ss_in_channels,
5913 .max = hdspm->ss_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005914 .integer = 1,
5915 };
5916 return snd_interval_refine(c, &t);
5917 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005918
Takashi Iwai763f3562005-06-03 11:25:34 +02005919 return 0;
5920}
5921
Adrian Knoth0dca1792011-01-26 19:32:14 +01005922static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
Takashi Iwai98274f02005-11-17 14:52:34 +01005923 struct snd_pcm_hw_rule * rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005924{
Takashi Iwai98274f02005-11-17 14:52:34 +01005925 struct hdspm *hdspm = rule->private;
5926 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005927 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005928 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005929 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5930
Adrian Knoth0dca1792011-01-26 19:32:14 +01005931 if (r->min > 96000 && r->max <= 192000) {
5932 struct snd_interval t = {
5933 .min = hdspm->qs_out_channels,
5934 .max = hdspm->qs_out_channels,
5935 .integer = 1,
5936 };
5937 return snd_interval_refine(c, &t);
5938 } else if (r->min > 48000 && r->max <= 96000) {
5939 struct snd_interval t = {
5940 .min = hdspm->ds_out_channels,
5941 .max = hdspm->ds_out_channels,
5942 .integer = 1,
5943 };
5944 return snd_interval_refine(c, &t);
5945 } else if (r->max < 64000) {
5946 struct snd_interval t = {
5947 .min = hdspm->ss_out_channels,
5948 .max = hdspm->ss_out_channels,
5949 .integer = 1,
5950 };
5951 return snd_interval_refine(c, &t);
5952 } else {
5953 }
5954 return 0;
5955}
5956
5957static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
5958 struct snd_pcm_hw_rule * rule)
5959{
5960 struct hdspm *hdspm = rule->private;
5961 struct snd_interval *c =
5962 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5963 struct snd_interval *r =
5964 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5965
5966 if (c->min >= hdspm->ss_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005967 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005968 .min = 32000,
5969 .max = 48000,
5970 .integer = 1,
5971 };
5972 return snd_interval_refine(r, &t);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005973 } else if (c->max <= hdspm->qs_in_channels) {
5974 struct snd_interval t = {
5975 .min = 128000,
5976 .max = 192000,
5977 .integer = 1,
5978 };
5979 return snd_interval_refine(r, &t);
5980 } else if (c->max <= hdspm->ds_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005981 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005982 .min = 64000,
5983 .max = 96000,
5984 .integer = 1,
5985 };
Takashi Iwai763f3562005-06-03 11:25:34 +02005986 return snd_interval_refine(r, &t);
5987 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005988
5989 return 0;
5990}
5991static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
5992 struct snd_pcm_hw_rule *rule)
5993{
5994 struct hdspm *hdspm = rule->private;
5995 struct snd_interval *c =
5996 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5997 struct snd_interval *r =
5998 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5999
6000 if (c->min >= hdspm->ss_out_channels) {
6001 struct snd_interval t = {
6002 .min = 32000,
6003 .max = 48000,
6004 .integer = 1,
6005 };
6006 return snd_interval_refine(r, &t);
6007 } else if (c->max <= hdspm->qs_out_channels) {
6008 struct snd_interval t = {
6009 .min = 128000,
6010 .max = 192000,
6011 .integer = 1,
6012 };
6013 return snd_interval_refine(r, &t);
6014 } else if (c->max <= hdspm->ds_out_channels) {
6015 struct snd_interval t = {
6016 .min = 64000,
6017 .max = 96000,
6018 .integer = 1,
6019 };
6020 return snd_interval_refine(r, &t);
6021 }
6022
Takashi Iwai763f3562005-06-03 11:25:34 +02006023 return 0;
6024}
6025
Adrian Knoth0dca1792011-01-26 19:32:14 +01006026static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params,
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006027 struct snd_pcm_hw_rule *rule)
6028{
6029 unsigned int list[3];
6030 struct hdspm *hdspm = rule->private;
6031 struct snd_interval *c = hw_param_interval(params,
6032 SNDRV_PCM_HW_PARAM_CHANNELS);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006033
6034 list[0] = hdspm->qs_in_channels;
6035 list[1] = hdspm->ds_in_channels;
6036 list[2] = hdspm->ss_in_channels;
6037 return snd_interval_list(c, 3, list, 0);
6038}
6039
6040static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params,
6041 struct snd_pcm_hw_rule *rule)
6042{
6043 unsigned int list[3];
6044 struct hdspm *hdspm = rule->private;
6045 struct snd_interval *c = hw_param_interval(params,
6046 SNDRV_PCM_HW_PARAM_CHANNELS);
6047
6048 list[0] = hdspm->qs_out_channels;
6049 list[1] = hdspm->ds_out_channels;
6050 list[2] = hdspm->ss_out_channels;
6051 return snd_interval_list(c, 3, list, 0);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006052}
6053
6054
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006055static unsigned int hdspm_aes32_sample_rates[] = {
6056 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
6057};
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006058
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006059static struct snd_pcm_hw_constraint_list
6060hdspm_hw_constraints_aes32_sample_rates = {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006061 .count = ARRAY_SIZE(hdspm_aes32_sample_rates),
6062 .list = hdspm_aes32_sample_rates,
6063 .mask = 0
6064};
6065
Takashi Iwai98274f02005-11-17 14:52:34 +01006066static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006067{
Takashi Iwai98274f02005-11-17 14:52:34 +01006068 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6069 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02006070
Takashi Iwai763f3562005-06-03 11:25:34 +02006071 spin_lock_irq(&hdspm->lock);
6072
6073 snd_pcm_set_sync(substream);
6074
Adrian Knoth0dca1792011-01-26 19:32:14 +01006075
Takashi Iwai763f3562005-06-03 11:25:34 +02006076 runtime->hw = snd_hdspm_playback_subinfo;
6077
6078 if (hdspm->capture_substream == NULL)
6079 hdspm_stop_audio(hdspm);
6080
6081 hdspm->playback_pid = current->pid;
6082 hdspm->playback_substream = substream;
6083
6084 spin_unlock_irq(&hdspm->lock);
6085
6086 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
Takashi Iwaid8776812011-08-15 10:45:42 +02006087 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02006088
Adrian Knoth0dca1792011-01-26 19:32:14 +01006089 switch (hdspm->io_type) {
6090 case AIO:
6091 case RayDAT:
Takashi Iwaid8776812011-08-15 10:45:42 +02006092 snd_pcm_hw_constraint_minmax(runtime,
6093 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6094 32, 4096);
6095 /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
6096 snd_pcm_hw_constraint_minmax(runtime,
6097 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6098 16384, 16384);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006099 break;
6100
6101 default:
Takashi Iwaid8776812011-08-15 10:45:42 +02006102 snd_pcm_hw_constraint_minmax(runtime,
6103 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6104 64, 8192);
6105 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006106 }
6107
6108 if (AES32 == hdspm->io_type) {
Takashi Iwai3fa9e3d2011-08-15 10:42:23 +02006109 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006110 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6111 &hdspm_hw_constraints_aes32_sample_rates);
6112 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006113 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006114 snd_hdspm_hw_rule_rate_out_channels, hdspm,
6115 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006116 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006117
6118 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6119 snd_hdspm_hw_rule_out_channels, hdspm,
6120 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6121
6122 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6123 snd_hdspm_hw_rule_out_channels_rate, hdspm,
6124 SNDRV_PCM_HW_PARAM_RATE, -1);
6125
Takashi Iwai763f3562005-06-03 11:25:34 +02006126 return 0;
6127}
6128
Takashi Iwai98274f02005-11-17 14:52:34 +01006129static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006130{
Takashi Iwai98274f02005-11-17 14:52:34 +01006131 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02006132
6133 spin_lock_irq(&hdspm->lock);
6134
6135 hdspm->playback_pid = -1;
6136 hdspm->playback_substream = NULL;
6137
6138 spin_unlock_irq(&hdspm->lock);
6139
6140 return 0;
6141}
6142
6143
Takashi Iwai98274f02005-11-17 14:52:34 +01006144static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006145{
Takashi Iwai98274f02005-11-17 14:52:34 +01006146 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6147 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02006148
6149 spin_lock_irq(&hdspm->lock);
6150 snd_pcm_set_sync(substream);
6151 runtime->hw = snd_hdspm_capture_subinfo;
6152
6153 if (hdspm->playback_substream == NULL)
6154 hdspm_stop_audio(hdspm);
6155
6156 hdspm->capture_pid = current->pid;
6157 hdspm->capture_substream = substream;
6158
6159 spin_unlock_irq(&hdspm->lock);
6160
6161 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
Takashi Iwaid8776812011-08-15 10:45:42 +02006162 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6163
Adrian Knoth0dca1792011-01-26 19:32:14 +01006164 switch (hdspm->io_type) {
6165 case AIO:
6166 case RayDAT:
Takashi Iwaid8776812011-08-15 10:45:42 +02006167 snd_pcm_hw_constraint_minmax(runtime,
6168 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6169 32, 4096);
6170 snd_pcm_hw_constraint_minmax(runtime,
6171 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6172 16384, 16384);
6173 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006174
6175 default:
Takashi Iwaid8776812011-08-15 10:45:42 +02006176 snd_pcm_hw_constraint_minmax(runtime,
6177 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6178 64, 8192);
6179 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006180 }
6181
6182 if (AES32 == hdspm->io_type) {
Takashi Iwai3fa9e3d2011-08-15 10:42:23 +02006183 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006184 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6185 &hdspm_hw_constraints_aes32_sample_rates);
6186 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006187 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006188 snd_hdspm_hw_rule_rate_in_channels, hdspm,
6189 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01006190 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01006191
6192 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6193 snd_hdspm_hw_rule_in_channels, hdspm,
6194 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6195
6196 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6197 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6198 SNDRV_PCM_HW_PARAM_RATE, -1);
6199
Takashi Iwai763f3562005-06-03 11:25:34 +02006200 return 0;
6201}
6202
Takashi Iwai98274f02005-11-17 14:52:34 +01006203static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02006204{
Takashi Iwai98274f02005-11-17 14:52:34 +01006205 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02006206
6207 spin_lock_irq(&hdspm->lock);
6208
6209 hdspm->capture_pid = -1;
6210 hdspm->capture_substream = NULL;
6211
6212 spin_unlock_irq(&hdspm->lock);
6213 return 0;
6214}
6215
Adrian Knoth0dca1792011-01-26 19:32:14 +01006216static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
Takashi Iwai763f3562005-06-03 11:25:34 +02006217{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006218 /* we have nothing to initialize but the call is required */
6219 return 0;
6220}
6221
6222static inline int copy_u32_le(void __user *dest, void __iomem *src)
6223{
6224 u32 val = readl(src);
6225 return copy_to_user(dest, &val, 4);
6226}
6227
6228static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006229 unsigned int cmd, unsigned long arg)
Adrian Knoth0dca1792011-01-26 19:32:14 +01006230{
6231 void __user *argp = (void __user *)arg;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006232 struct hdspm *hdspm = hw->private_data;
Takashi Iwai98274f02005-11-17 14:52:34 +01006233 struct hdspm_mixer_ioctl mixer;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006234 struct hdspm_config info;
6235 struct hdspm_status status;
Takashi Iwai98274f02005-11-17 14:52:34 +01006236 struct hdspm_version hdspm_version;
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006237 struct hdspm_peak_rms *levels;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006238 struct hdspm_ltc ltc;
6239 unsigned int statusregister;
6240 long unsigned int s;
6241 int i = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02006242
6243 switch (cmd) {
6244
Takashi Iwai763f3562005-06-03 11:25:34 +02006245 case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006246 levels = &hdspm->peak_rms;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006247 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006248 levels->input_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006249 readl(hdspm->iobase +
6250 HDSPM_MADI_INPUT_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006251 levels->playback_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006252 readl(hdspm->iobase +
6253 HDSPM_MADI_PLAYBACK_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006254 levels->output_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006255 readl(hdspm->iobase +
6256 HDSPM_MADI_OUTPUT_PEAK + i*4);
6257
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006258 levels->input_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006259 ((uint64_t) readl(hdspm->iobase +
6260 HDSPM_MADI_INPUT_RMS_H + i*4) << 32) |
6261 (uint64_t) readl(hdspm->iobase +
6262 HDSPM_MADI_INPUT_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006263 levels->playback_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006264 ((uint64_t)readl(hdspm->iobase +
6265 HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) |
6266 (uint64_t)readl(hdspm->iobase +
6267 HDSPM_MADI_PLAYBACK_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006268 levels->output_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006269 ((uint64_t)readl(hdspm->iobase +
6270 HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) |
6271 (uint64_t)readl(hdspm->iobase +
6272 HDSPM_MADI_OUTPUT_RMS_L + i*4);
6273 }
6274
6275 if (hdspm->system_sample_rate > 96000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006276 levels->speed = qs;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006277 } else if (hdspm->system_sample_rate > 48000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006278 levels->speed = ds;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006279 } else {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006280 levels->speed = ss;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006281 }
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006282 levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006283
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006284 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
Adrian Knoth0dca1792011-01-26 19:32:14 +01006285 if (0 != s) {
6286 /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu
6287 [Levels]\n", sizeof(struct hdspm_peak_rms), s);
6288 */
Takashi Iwai763f3562005-06-03 11:25:34 +02006289 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006290 }
6291 break;
6292
6293 case SNDRV_HDSPM_IOCTL_GET_LTC:
6294 ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
6295 i = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
6296 if (i & HDSPM_TCO1_LTC_Input_valid) {
6297 switch (i & (HDSPM_TCO1_LTC_Format_LSB |
6298 HDSPM_TCO1_LTC_Format_MSB)) {
6299 case 0:
6300 ltc.format = fps_24;
6301 break;
6302 case HDSPM_TCO1_LTC_Format_LSB:
6303 ltc.format = fps_25;
6304 break;
6305 case HDSPM_TCO1_LTC_Format_MSB:
6306 ltc.format = fps_2997;
6307 break;
6308 default:
Adrian Knoth17d2f002013-08-19 17:20:30 +02006309 ltc.format = fps_30;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006310 break;
6311 }
6312 if (i & HDSPM_TCO1_set_drop_frame_flag) {
6313 ltc.frame = drop_frame;
6314 } else {
6315 ltc.frame = full_frame;
6316 }
6317 } else {
6318 ltc.format = format_invalid;
6319 ltc.frame = frame_invalid;
6320 }
6321 if (i & HDSPM_TCO1_Video_Input_Format_NTSC) {
6322 ltc.input_format = ntsc;
6323 } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) {
6324 ltc.input_format = pal;
6325 } else {
6326 ltc.input_format = no_video;
6327 }
6328
6329 s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc));
6330 if (0 != s) {
6331 /*
6332 snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
Takashi Iwai763f3562005-06-03 11:25:34 +02006333 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006334 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006335
6336 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02006337
Adrian Knoth0dca1792011-01-26 19:32:14 +01006338 case SNDRV_HDSPM_IOCTL_GET_CONFIG:
Takashi Iwai763f3562005-06-03 11:25:34 +02006339
Adrian Knoth4ab69a22011-02-23 11:43:14 +01006340 memset(&info, 0, sizeof(info));
Takashi Iwai763f3562005-06-03 11:25:34 +02006341 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006342 info.pref_sync_ref = hdspm_pref_sync_ref(hdspm);
6343 info.wordclock_sync_check = hdspm_wc_sync_check(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006344
6345 info.system_sample_rate = hdspm->system_sample_rate;
6346 info.autosync_sample_rate =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006347 hdspm_external_sample_rate(hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006348 info.system_clock_mode = hdspm_system_clock_mode(hdspm);
6349 info.clock_source = hdspm_clock_source(hdspm);
6350 info.autosync_ref = hdspm_autosync_ref(hdspm);
Adrian Knothc9e16682012-12-03 14:55:50 +01006351 info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut);
Takashi Iwai763f3562005-06-03 11:25:34 +02006352 info.passthru = 0;
6353 spin_unlock_irq(&hdspm->lock);
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006354 if (copy_to_user(argp, &info, sizeof(info)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006355 return -EFAULT;
6356 break;
6357
Adrian Knoth0dca1792011-01-26 19:32:14 +01006358 case SNDRV_HDSPM_IOCTL_GET_STATUS:
Dan Carpenter643d6bb2011-09-23 09:24:21 +03006359 memset(&status, 0, sizeof(status));
6360
Adrian Knoth0dca1792011-01-26 19:32:14 +01006361 status.card_type = hdspm->io_type;
6362
6363 status.autosync_source = hdspm_autosync_ref(hdspm);
6364
6365 status.card_clock = 110069313433624ULL;
6366 status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
6367
6368 switch (hdspm->io_type) {
6369 case MADI:
6370 case MADIface:
6371 status.card_specific.madi.sync_wc =
6372 hdspm_wc_sync_check(hdspm);
6373 status.card_specific.madi.sync_madi =
6374 hdspm_madi_sync_check(hdspm);
6375 status.card_specific.madi.sync_tco =
6376 hdspm_tco_sync_check(hdspm);
6377 status.card_specific.madi.sync_in =
6378 hdspm_sync_in_sync_check(hdspm);
6379
6380 statusregister =
6381 hdspm_read(hdspm, HDSPM_statusRegister);
6382 status.card_specific.madi.madi_input =
6383 (statusregister & HDSPM_AB_int) ? 1 : 0;
6384 status.card_specific.madi.channel_format =
Adrian Knoth9e6ff522011-10-27 21:57:52 +02006385 (statusregister & HDSPM_RX_64ch) ? 1 : 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006386 /* TODO: Mac driver sets it when f_s>48kHz */
6387 status.card_specific.madi.frame_format = 0;
6388
6389 default:
6390 break;
6391 }
6392
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006393 if (copy_to_user(argp, &status, sizeof(status)))
Adrian Knoth0dca1792011-01-26 19:32:14 +01006394 return -EFAULT;
6395
6396
6397 break;
6398
Takashi Iwai763f3562005-06-03 11:25:34 +02006399 case SNDRV_HDSPM_IOCTL_GET_VERSION:
Dan Carpenter643d6bb2011-09-23 09:24:21 +03006400 memset(&hdspm_version, 0, sizeof(hdspm_version));
6401
Adrian Knoth0dca1792011-01-26 19:32:14 +01006402 hdspm_version.card_type = hdspm->io_type;
Takashi Iwai57a44512013-10-29 15:26:12 +01006403 strlcpy(hdspm_version.cardname, hdspm->card_name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006404 sizeof(hdspm_version.cardname));
Adrian Knoth7d53a632012-01-04 14:31:16 +01006405 hdspm_version.serial = hdspm->serial;
Takashi Iwai763f3562005-06-03 11:25:34 +02006406 hdspm_version.firmware_rev = hdspm->firmware_rev;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006407 hdspm_version.addons = 0;
6408 if (hdspm->tco)
6409 hdspm_version.addons |= HDSPM_ADDON_TCO;
6410
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006411 if (copy_to_user(argp, &hdspm_version,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006412 sizeof(hdspm_version)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006413 return -EFAULT;
6414 break;
6415
6416 case SNDRV_HDSPM_IOCTL_GET_MIXER:
Dan Carpenter2ca595a2011-09-23 09:25:05 +03006417 if (copy_from_user(&mixer, argp, sizeof(mixer)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006418 return -EFAULT;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006419 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006420 sizeof(struct hdspm_mixer)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006421 return -EFAULT;
6422 break;
6423
6424 default:
6425 return -EINVAL;
6426 }
6427 return 0;
6428}
6429
Takashi Iwai98274f02005-11-17 14:52:34 +01006430static struct snd_pcm_ops snd_hdspm_playback_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006431 .open = snd_hdspm_playback_open,
6432 .close = snd_hdspm_playback_release,
6433 .ioctl = snd_hdspm_ioctl,
6434 .hw_params = snd_hdspm_hw_params,
6435 .hw_free = snd_hdspm_hw_free,
6436 .prepare = snd_hdspm_prepare,
6437 .trigger = snd_hdspm_trigger,
6438 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006439 .page = snd_pcm_sgbuf_ops_page,
6440};
6441
Takashi Iwai98274f02005-11-17 14:52:34 +01006442static struct snd_pcm_ops snd_hdspm_capture_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006443 .open = snd_hdspm_capture_open,
6444 .close = snd_hdspm_capture_release,
6445 .ioctl = snd_hdspm_ioctl,
6446 .hw_params = snd_hdspm_hw_params,
6447 .hw_free = snd_hdspm_hw_free,
6448 .prepare = snd_hdspm_prepare,
6449 .trigger = snd_hdspm_trigger,
6450 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006451 .page = snd_pcm_sgbuf_ops_page,
6452};
6453
Bill Pembertone23e7a12012-12-06 12:35:10 -05006454static int snd_hdspm_create_hwdep(struct snd_card *card,
6455 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006456{
Takashi Iwai98274f02005-11-17 14:52:34 +01006457 struct snd_hwdep *hw;
Takashi Iwai763f3562005-06-03 11:25:34 +02006458 int err;
6459
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006460 err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw);
6461 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006462 return err;
6463
6464 hdspm->hwdep = hw;
6465 hw->private_data = hdspm;
6466 strcpy(hw->name, "HDSPM hwdep interface");
6467
Adrian Knoth0dca1792011-01-26 19:32:14 +01006468 hw->ops.open = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006469 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
Adrian Knoth8de5d6f2012-03-08 15:38:04 +01006470 hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006471 hw->ops.release = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006472
6473 return 0;
6474}
6475
6476
6477/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01006478 memory interface
Takashi Iwai763f3562005-06-03 11:25:34 +02006479 ------------------------------------------------------------*/
Bill Pembertone23e7a12012-12-06 12:35:10 -05006480static int snd_hdspm_preallocate_memory(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006481{
6482 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01006483 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006484 size_t wanted;
6485
6486 pcm = hdspm->pcm;
6487
Remy Bruno3cee5a62006-10-16 12:46:32 +02006488 wanted = HDSPM_DMA_AREA_BYTES;
Takashi Iwai763f3562005-06-03 11:25:34 +02006489
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006490 err =
Takashi Iwai763f3562005-06-03 11:25:34 +02006491 snd_pcm_lib_preallocate_pages_for_all(pcm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006492 SNDRV_DMA_TYPE_DEV_SG,
Takashi Iwai763f3562005-06-03 11:25:34 +02006493 snd_dma_pci_data(hdspm->pci),
6494 wanted,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006495 wanted);
6496 if (err < 0) {
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006497 snd_printdd("Could not preallocate %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006498
6499 return err;
6500 } else
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006501 snd_printdd(" Preallocated %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006502
6503 return 0;
6504}
6505
Adrian Knoth0dca1792011-01-26 19:32:14 +01006506
6507static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +02006508 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +02006509 unsigned int reg, int channels)
6510{
6511 int i;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006512
6513 /* continuous memory segment */
Takashi Iwai763f3562005-06-03 11:25:34 +02006514 for (i = 0; i < (channels * 16); i++)
6515 hdspm_write(hdspm, reg + 4 * i,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006516 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
Takashi Iwai763f3562005-06-03 11:25:34 +02006517}
6518
Adrian Knoth0dca1792011-01-26 19:32:14 +01006519
Takashi Iwai763f3562005-06-03 11:25:34 +02006520/* ------------- ALSA Devices ---------------------------- */
Bill Pembertone23e7a12012-12-06 12:35:10 -05006521static int snd_hdspm_create_pcm(struct snd_card *card,
6522 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006523{
Takashi Iwai98274f02005-11-17 14:52:34 +01006524 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006525 int err;
6526
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006527 err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm);
6528 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006529 return err;
6530
6531 hdspm->pcm = pcm;
6532 pcm->private_data = hdspm;
6533 strcpy(pcm->name, hdspm->card_name);
6534
6535 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6536 &snd_hdspm_playback_ops);
6537 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6538 &snd_hdspm_capture_ops);
6539
6540 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6541
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006542 err = snd_hdspm_preallocate_memory(hdspm);
6543 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006544 return err;
6545
6546 return 0;
6547}
6548
Takashi Iwai98274f02005-11-17 14:52:34 +01006549static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006550{
Adrian Knoth7c7102b2011-02-28 15:14:50 +01006551 int i;
6552
6553 for (i = 0; i < hdspm->midiPorts; i++)
6554 snd_hdspm_flush_midi_input(hdspm, i);
Takashi Iwai763f3562005-06-03 11:25:34 +02006555}
6556
Bill Pembertone23e7a12012-12-06 12:35:10 -05006557static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6558 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006559{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006560 int err, i;
Takashi Iwai763f3562005-06-03 11:25:34 +02006561
6562 snd_printdd("Create card...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006563 err = snd_hdspm_create_pcm(card, hdspm);
6564 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006565 return err;
6566
Adrian Knoth0dca1792011-01-26 19:32:14 +01006567 i = 0;
6568 while (i < hdspm->midiPorts) {
6569 err = snd_hdspm_create_midi(card, hdspm, i);
6570 if (err < 0) {
6571 return err;
6572 }
6573 i++;
6574 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006575
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006576 err = snd_hdspm_create_controls(card, hdspm);
6577 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006578 return err;
6579
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006580 err = snd_hdspm_create_hwdep(card, hdspm);
6581 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006582 return err;
6583
6584 snd_printdd("proc init...\n");
6585 snd_hdspm_proc_init(hdspm);
6586
6587 hdspm->system_sample_rate = -1;
6588 hdspm->last_external_sample_rate = -1;
6589 hdspm->last_internal_sample_rate = -1;
6590 hdspm->playback_pid = -1;
6591 hdspm->capture_pid = -1;
6592 hdspm->capture_substream = NULL;
6593 hdspm->playback_substream = NULL;
6594
6595 snd_printdd("Set defaults...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006596 err = snd_hdspm_set_defaults(hdspm);
6597 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006598 return err;
6599
6600 snd_printdd("Update mixer controls...\n");
6601 hdspm_update_simple_mixer_controls(hdspm);
6602
6603 snd_printdd("Initializeing complete ???\n");
6604
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006605 err = snd_card_register(card);
6606 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006607 snd_printk(KERN_ERR "HDSPM: error registering card\n");
6608 return err;
6609 }
6610
6611 snd_printdd("... yes now\n");
6612
6613 return 0;
6614}
6615
Bill Pembertone23e7a12012-12-06 12:35:10 -05006616static int snd_hdspm_create(struct snd_card *card,
6617 struct hdspm *hdspm)
6618{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006619
Takashi Iwai763f3562005-06-03 11:25:34 +02006620 struct pci_dev *pci = hdspm->pci;
6621 int err;
Takashi Iwai763f3562005-06-03 11:25:34 +02006622 unsigned long io_extent;
6623
6624 hdspm->irq = -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02006625 hdspm->card = card;
6626
6627 spin_lock_init(&hdspm->lock);
6628
Takashi Iwai763f3562005-06-03 11:25:34 +02006629 pci_read_config_word(hdspm->pci,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006630 PCI_CLASS_REVISION, &hdspm->firmware_rev);
Remy Bruno3cee5a62006-10-16 12:46:32 +02006631
Takashi Iwai763f3562005-06-03 11:25:34 +02006632 strcpy(card->mixername, "Xilinx FPGA");
Adrian Knoth0dca1792011-01-26 19:32:14 +01006633 strcpy(card->driver, "HDSPM");
6634
6635 switch (hdspm->firmware_rev) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01006636 case HDSPM_RAYDAT_REV:
6637 hdspm->io_type = RayDAT;
6638 hdspm->card_name = "RME RayDAT";
6639 hdspm->midiPorts = 2;
6640 break;
6641 case HDSPM_AIO_REV:
6642 hdspm->io_type = AIO;
6643 hdspm->card_name = "RME AIO";
6644 hdspm->midiPorts = 1;
6645 break;
6646 case HDSPM_MADIFACE_REV:
6647 hdspm->io_type = MADIface;
6648 hdspm->card_name = "RME MADIface";
6649 hdspm->midiPorts = 1;
6650 break;
Adrian Knoth5027f342011-02-28 15:14:49 +01006651 default:
Adrian Knothc09403d2011-10-27 21:57:54 +02006652 if ((hdspm->firmware_rev == 0xf0) ||
6653 ((hdspm->firmware_rev >= 0xe6) &&
6654 (hdspm->firmware_rev <= 0xea))) {
6655 hdspm->io_type = AES32;
6656 hdspm->card_name = "RME AES32";
6657 hdspm->midiPorts = 2;
Adrian Knoth05c7cc92011-11-21 16:15:36 +01006658 } else if ((hdspm->firmware_rev == 0xd2) ||
Adrian Knothc09403d2011-10-27 21:57:54 +02006659 ((hdspm->firmware_rev >= 0xc8) &&
6660 (hdspm->firmware_rev <= 0xcf))) {
6661 hdspm->io_type = MADI;
6662 hdspm->card_name = "RME MADI";
6663 hdspm->midiPorts = 3;
6664 } else {
6665 snd_printk(KERN_ERR
6666 "HDSPM: unknown firmware revision %x\n",
Adrian Knoth5027f342011-02-28 15:14:49 +01006667 hdspm->firmware_rev);
Adrian Knothc09403d2011-10-27 21:57:54 +02006668 return -ENODEV;
6669 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02006670 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006671
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006672 err = pci_enable_device(pci);
6673 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006674 return err;
6675
6676 pci_set_master(hdspm->pci);
6677
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006678 err = pci_request_regions(pci, "hdspm");
6679 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006680 return err;
6681
6682 hdspm->port = pci_resource_start(pci, 0);
6683 io_extent = pci_resource_len(pci, 0);
6684
6685 snd_printdd("grabbed memory region 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006686 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006687
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006688 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
6689 if (!hdspm->iobase) {
6690 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006691 "unable to remap region 0x%lx-0x%lx\n",
6692 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006693 return -EBUSY;
6694 }
6695 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006696 (unsigned long)hdspm->iobase, hdspm->port,
6697 hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006698
6699 if (request_irq(pci->irq, snd_hdspm_interrupt,
Takashi Iwai934c2b62011-06-10 16:36:37 +02006700 IRQF_SHARED, KBUILD_MODNAME, hdspm)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006701 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq);
6702 return -EBUSY;
6703 }
6704
6705 snd_printdd("use IRQ %d\n", pci->irq);
6706
6707 hdspm->irq = pci->irq;
Takashi Iwai763f3562005-06-03 11:25:34 +02006708
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006709 snd_printdd("kmalloc Mixer memory of %zd Bytes\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006710 sizeof(struct hdspm_mixer));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006711 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
6712 if (!hdspm->mixer) {
6713 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006714 "unable to kmalloc Mixer memory of %d Bytes\n",
6715 (int)sizeof(struct hdspm_mixer));
Julia Lawallb17cbdd2012-08-19 09:02:54 +02006716 return -ENOMEM;
Takashi Iwai763f3562005-06-03 11:25:34 +02006717 }
6718
Adrian Knoth0dca1792011-01-26 19:32:14 +01006719 hdspm->port_names_in = NULL;
6720 hdspm->port_names_out = NULL;
6721
6722 switch (hdspm->io_type) {
6723 case AES32:
Adrian Knothd2d10a22011-02-28 15:14:47 +01006724 hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS;
6725 hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS;
6726 hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS;
Adrian Knoth432d2502011-02-23 11:43:08 +01006727
6728 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6729 channel_map_aes32;
6730 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6731 channel_map_aes32;
6732 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6733 channel_map_aes32;
6734 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6735 texts_ports_aes32;
6736 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6737 texts_ports_aes32;
6738 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6739 texts_ports_aes32;
6740
Adrian Knothd2d10a22011-02-28 15:14:47 +01006741 hdspm->max_channels_out = hdspm->max_channels_in =
6742 AES32_CHANNELS;
Adrian Knoth432d2502011-02-23 11:43:08 +01006743 hdspm->port_names_in = hdspm->port_names_out =
6744 texts_ports_aes32;
6745 hdspm->channel_map_in = hdspm->channel_map_out =
6746 channel_map_aes32;
6747
Adrian Knoth0dca1792011-01-26 19:32:14 +01006748 break;
6749
6750 case MADI:
6751 case MADIface:
6752 hdspm->ss_in_channels = hdspm->ss_out_channels =
6753 MADI_SS_CHANNELS;
6754 hdspm->ds_in_channels = hdspm->ds_out_channels =
6755 MADI_DS_CHANNELS;
6756 hdspm->qs_in_channels = hdspm->qs_out_channels =
6757 MADI_QS_CHANNELS;
6758
6759 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6760 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006761 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006762 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006763 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006764 channel_map_unity_ss;
6765
6766 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6767 texts_ports_madi;
6768 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6769 texts_ports_madi;
6770 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6771 texts_ports_madi;
6772 break;
6773
6774 case AIO:
Adrian Knoth0dca1792011-01-26 19:32:14 +01006775 hdspm->ss_in_channels = AIO_IN_SS_CHANNELS;
6776 hdspm->ds_in_channels = AIO_IN_DS_CHANNELS;
6777 hdspm->qs_in_channels = AIO_IN_QS_CHANNELS;
6778 hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS;
6779 hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS;
6780 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
6781
Adrian Knoth3de9db22013-07-05 11:28:02 +02006782 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
6783 snd_printk(KERN_INFO "HDSPM: AEB input board found\n");
6784 hdspm->ss_in_channels += 4;
6785 hdspm->ds_in_channels += 4;
6786 hdspm->qs_in_channels += 4;
6787 }
6788
6789 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) {
6790 snd_printk(KERN_INFO "HDSPM: AEB output board found\n");
6791 hdspm->ss_out_channels += 4;
6792 hdspm->ds_out_channels += 4;
6793 hdspm->qs_out_channels += 4;
6794 }
6795
Adrian Knoth0dca1792011-01-26 19:32:14 +01006796 hdspm->channel_map_out_ss = channel_map_aio_out_ss;
6797 hdspm->channel_map_out_ds = channel_map_aio_out_ds;
6798 hdspm->channel_map_out_qs = channel_map_aio_out_qs;
6799
6800 hdspm->channel_map_in_ss = channel_map_aio_in_ss;
6801 hdspm->channel_map_in_ds = channel_map_aio_in_ds;
6802 hdspm->channel_map_in_qs = channel_map_aio_in_qs;
6803
6804 hdspm->port_names_in_ss = texts_ports_aio_in_ss;
6805 hdspm->port_names_out_ss = texts_ports_aio_out_ss;
6806 hdspm->port_names_in_ds = texts_ports_aio_in_ds;
6807 hdspm->port_names_out_ds = texts_ports_aio_out_ds;
6808 hdspm->port_names_in_qs = texts_ports_aio_in_qs;
6809 hdspm->port_names_out_qs = texts_ports_aio_out_qs;
6810
6811 break;
6812
6813 case RayDAT:
6814 hdspm->ss_in_channels = hdspm->ss_out_channels =
6815 RAYDAT_SS_CHANNELS;
6816 hdspm->ds_in_channels = hdspm->ds_out_channels =
6817 RAYDAT_DS_CHANNELS;
6818 hdspm->qs_in_channels = hdspm->qs_out_channels =
6819 RAYDAT_QS_CHANNELS;
6820
6821 hdspm->max_channels_in = RAYDAT_SS_CHANNELS;
6822 hdspm->max_channels_out = RAYDAT_SS_CHANNELS;
6823
6824 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6825 channel_map_raydat_ss;
6826 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6827 channel_map_raydat_ds;
6828 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6829 channel_map_raydat_qs;
6830 hdspm->channel_map_in = hdspm->channel_map_out =
6831 channel_map_raydat_ss;
6832
6833 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6834 texts_ports_raydat_ss;
6835 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6836 texts_ports_raydat_ds;
6837 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6838 texts_ports_raydat_qs;
6839
6840
6841 break;
6842
6843 }
6844
6845 /* TCO detection */
6846 switch (hdspm->io_type) {
6847 case AIO:
6848 case RayDAT:
6849 if (hdspm_read(hdspm, HDSPM_statusRegister2) &
6850 HDSPM_s2_tco_detect) {
6851 hdspm->midiPorts++;
6852 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6853 GFP_KERNEL);
6854 if (NULL != hdspm->tco) {
6855 hdspm_tco_write(hdspm);
6856 }
6857 snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n");
6858 } else {
6859 hdspm->tco = NULL;
6860 }
6861 break;
6862
6863 case MADI:
Adrian Knoth0dc831b2013-07-05 11:28:19 +02006864 case AES32:
Adrian Knoth0dca1792011-01-26 19:32:14 +01006865 if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) {
6866 hdspm->midiPorts++;
6867 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6868 GFP_KERNEL);
6869 if (NULL != hdspm->tco) {
6870 hdspm_tco_write(hdspm);
6871 }
Adrian Knothe71b95a2013-07-05 11:28:06 +02006872 snd_printk(KERN_INFO "HDSPM: MADI/AES TCO module found\n");
Adrian Knoth0dca1792011-01-26 19:32:14 +01006873 } else {
6874 hdspm->tco = NULL;
6875 }
6876 break;
6877
6878 default:
6879 hdspm->tco = NULL;
6880 }
6881
6882 /* texts */
6883 switch (hdspm->io_type) {
6884 case AES32:
6885 if (hdspm->tco) {
6886 hdspm->texts_autosync = texts_autosync_aes_tco;
Adrian Knothe71b95a2013-07-05 11:28:06 +02006887 hdspm->texts_autosync_items =
6888 ARRAY_SIZE(texts_autosync_aes_tco);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006889 } else {
6890 hdspm->texts_autosync = texts_autosync_aes;
Adrian Knothe71b95a2013-07-05 11:28:06 +02006891 hdspm->texts_autosync_items =
6892 ARRAY_SIZE(texts_autosync_aes);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006893 }
6894 break;
6895
6896 case MADI:
6897 if (hdspm->tco) {
6898 hdspm->texts_autosync = texts_autosync_madi_tco;
6899 hdspm->texts_autosync_items = 4;
6900 } else {
6901 hdspm->texts_autosync = texts_autosync_madi;
6902 hdspm->texts_autosync_items = 3;
6903 }
6904 break;
6905
6906 case MADIface:
6907
6908 break;
6909
6910 case RayDAT:
6911 if (hdspm->tco) {
6912 hdspm->texts_autosync = texts_autosync_raydat_tco;
6913 hdspm->texts_autosync_items = 9;
6914 } else {
6915 hdspm->texts_autosync = texts_autosync_raydat;
6916 hdspm->texts_autosync_items = 8;
6917 }
6918 break;
6919
6920 case AIO:
6921 if (hdspm->tco) {
6922 hdspm->texts_autosync = texts_autosync_aio_tco;
6923 hdspm->texts_autosync_items = 6;
6924 } else {
6925 hdspm->texts_autosync = texts_autosync_aio;
6926 hdspm->texts_autosync_items = 5;
6927 }
6928 break;
6929
6930 }
6931
6932 tasklet_init(&hdspm->midi_tasklet,
6933 hdspm_midi_tasklet, (unsigned long) hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006934
Adrian Knothf7de8ba2012-01-10 20:58:40 +01006935
6936 if (hdspm->io_type != MADIface) {
6937 hdspm->serial = (hdspm_read(hdspm,
6938 HDSPM_midiStatusIn0)>>8) & 0xFFFFFF;
6939 /* id contains either a user-provided value or the default
6940 * NULL. If it's the default, we're safe to
6941 * fill card->id with the serial number.
6942 *
6943 * If the serial number is 0xFFFFFF, then we're dealing with
6944 * an old PCI revision that comes without a sane number. In
6945 * this case, we don't set card->id to avoid collisions
6946 * when running with multiple cards.
6947 */
6948 if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) {
6949 sprintf(card->id, "HDSPMx%06x", hdspm->serial);
6950 snd_card_set_id(card, card->id);
6951 }
6952 }
6953
Takashi Iwai763f3562005-06-03 11:25:34 +02006954 snd_printdd("create alsa devices.\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006955 err = snd_hdspm_create_alsa_devices(card, hdspm);
6956 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006957 return err;
6958
6959 snd_hdspm_initialize_midi_flush(hdspm);
6960
6961 return 0;
6962}
6963
Adrian Knoth0dca1792011-01-26 19:32:14 +01006964
Takashi Iwai98274f02005-11-17 14:52:34 +01006965static int snd_hdspm_free(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006966{
6967
6968 if (hdspm->port) {
6969
6970 /* stop th audio, and cancel all interrupts */
6971 hdspm->control_register &=
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006972 ~(HDSPM_Start | HDSPM_AudioInterruptEnable |
Adrian Knoth0dca1792011-01-26 19:32:14 +01006973 HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable |
6974 HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable);
Takashi Iwai763f3562005-06-03 11:25:34 +02006975 hdspm_write(hdspm, HDSPM_controlRegister,
6976 hdspm->control_register);
6977 }
6978
6979 if (hdspm->irq >= 0)
6980 free_irq(hdspm->irq, (void *) hdspm);
6981
Jesper Juhlfc584222005-10-24 15:11:28 +02006982 kfree(hdspm->mixer);
Takashi Iwai763f3562005-06-03 11:25:34 +02006983
6984 if (hdspm->iobase)
6985 iounmap(hdspm->iobase);
6986
Takashi Iwai763f3562005-06-03 11:25:34 +02006987 if (hdspm->port)
6988 pci_release_regions(hdspm->pci);
6989
6990 pci_disable_device(hdspm->pci);
6991 return 0;
6992}
6993
Adrian Knoth0dca1792011-01-26 19:32:14 +01006994
Takashi Iwai98274f02005-11-17 14:52:34 +01006995static void snd_hdspm_card_free(struct snd_card *card)
Takashi Iwai763f3562005-06-03 11:25:34 +02006996{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006997 struct hdspm *hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02006998
6999 if (hdspm)
7000 snd_hdspm_free(hdspm);
7001}
7002
Adrian Knoth0dca1792011-01-26 19:32:14 +01007003
Bill Pembertone23e7a12012-12-06 12:35:10 -05007004static int snd_hdspm_probe(struct pci_dev *pci,
7005 const struct pci_device_id *pci_id)
Takashi Iwai763f3562005-06-03 11:25:34 +02007006{
7007 static int dev;
Takashi Iwai98274f02005-11-17 14:52:34 +01007008 struct hdspm *hdspm;
7009 struct snd_card *card;
Takashi Iwai763f3562005-06-03 11:25:34 +02007010 int err;
7011
7012 if (dev >= SNDRV_CARDS)
7013 return -ENODEV;
7014 if (!enable[dev]) {
7015 dev++;
7016 return -ENOENT;
7017 }
7018
Takashi Iwaie58de7b2008-12-28 16:44:30 +01007019 err = snd_card_create(index[dev], id[dev],
Adrian Knoth0dca1792011-01-26 19:32:14 +01007020 THIS_MODULE, sizeof(struct hdspm), &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01007021 if (err < 0)
7022 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02007023
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02007024 hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02007025 card->private_free = snd_hdspm_card_free;
7026 hdspm->dev = dev;
7027 hdspm->pci = pci;
7028
Takashi Iwaic187c042007-02-19 15:27:33 +01007029 snd_card_set_dev(card, &pci->dev);
7030
Adrian Knoth0dca1792011-01-26 19:32:14 +01007031 err = snd_hdspm_create(card, hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02007032 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02007033 snd_card_free(card);
7034 return err;
7035 }
7036
Adrian Knoth0dca1792011-01-26 19:32:14 +01007037 if (hdspm->io_type != MADIface) {
7038 sprintf(card->shortname, "%s_%x",
7039 hdspm->card_name,
Adrian Knoth7d53a632012-01-04 14:31:16 +01007040 hdspm->serial);
Adrian Knoth0dca1792011-01-26 19:32:14 +01007041 sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d",
7042 hdspm->card_name,
Adrian Knoth7d53a632012-01-04 14:31:16 +01007043 hdspm->serial,
Adrian Knoth0dca1792011-01-26 19:32:14 +01007044 hdspm->port, hdspm->irq);
7045 } else {
7046 sprintf(card->shortname, "%s", hdspm->card_name);
7047 sprintf(card->longname, "%s at 0x%lx, irq %d",
7048 hdspm->card_name, hdspm->port, hdspm->irq);
7049 }
Takashi Iwai763f3562005-06-03 11:25:34 +02007050
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02007051 err = snd_card_register(card);
7052 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02007053 snd_card_free(card);
7054 return err;
7055 }
7056
7057 pci_set_drvdata(pci, card);
7058
7059 dev++;
7060 return 0;
7061}
7062
Bill Pembertone23e7a12012-12-06 12:35:10 -05007063static void snd_hdspm_remove(struct pci_dev *pci)
Takashi Iwai763f3562005-06-03 11:25:34 +02007064{
7065 snd_card_free(pci_get_drvdata(pci));
Takashi Iwai763f3562005-06-03 11:25:34 +02007066}
7067
Takashi Iwaie9f66d92012-04-24 12:25:00 +02007068static struct pci_driver hdspm_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02007069 .name = KBUILD_MODNAME,
Takashi Iwai763f3562005-06-03 11:25:34 +02007070 .id_table = snd_hdspm_ids,
7071 .probe = snd_hdspm_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05007072 .remove = snd_hdspm_remove,
Takashi Iwai763f3562005-06-03 11:25:34 +02007073};
7074
Takashi Iwaie9f66d92012-04-24 12:25:00 +02007075module_pci_driver(hdspm_driver);