Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1 | /* |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2 | * 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 Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 8 | * Modified 2006-06-01 for AES32 support by Remy Bruno |
| 9 | * <remy.bruno@trinnov.com> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 10 | * |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 11 | * 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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 26 | * This program is free software; you can redistribute it and/or modify |
| 27 | * it under the terms of the GNU General Public License as published by |
| 28 | * the Free Software Foundation; either version 2 of the License, or |
| 29 | * (at your option) any later version. |
| 30 | * |
| 31 | * This program is distributed in the hope that it will be useful, |
| 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 | * GNU General Public License for more details. |
| 35 | * |
| 36 | * You should have received a copy of the GNU General Public License |
| 37 | * along with this program; if not, write to the Free Software |
| 38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 39 | * |
| 40 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 41 | #include <linux/init.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/interrupt.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 44 | #include <linux/module.h> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 45 | #include <linux/slab.h> |
| 46 | #include <linux/pci.h> |
Takashi Iwai | 3f7440a | 2009-06-05 17:40:04 +0200 | [diff] [blame] | 47 | #include <linux/math64.h> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 48 | #include <asm/io.h> |
| 49 | |
| 50 | #include <sound/core.h> |
| 51 | #include <sound/control.h> |
| 52 | #include <sound/pcm.h> |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 53 | #include <sound/pcm_params.h> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 54 | #include <sound/info.h> |
| 55 | #include <sound/asoundef.h> |
| 56 | #include <sound/rawmidi.h> |
| 57 | #include <sound/hwdep.h> |
| 58 | #include <sound/initval.h> |
| 59 | |
| 60 | #include <sound/hdspm.h> |
| 61 | |
| 62 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 63 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 64 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 65 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 66 | module_param_array(index, int, NULL, 0444); |
| 67 | MODULE_PARM_DESC(index, "Index value for RME HDSPM interface."); |
| 68 | |
| 69 | module_param_array(id, charp, NULL, 0444); |
| 70 | MODULE_PARM_DESC(id, "ID string for RME HDSPM interface."); |
| 71 | |
| 72 | module_param_array(enable, bool, NULL, 0444); |
| 73 | MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards."); |
| 74 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 77 | ( |
| 78 | "Winfried Ritsch <ritsch_AT_iem.at>, " |
| 79 | "Paul Davis <paul@linuxaudiosystems.com>, " |
| 80 | "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, " |
| 81 | "Remy Bruno <remy.bruno@trinnov.com>, " |
| 82 | "Florian Faber <faberman@linuxproaudio.org>, " |
| 83 | "Adrian Knoth <adi@drcomp.erfurt.thur.de>" |
| 84 | ); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 85 | MODULE_DESCRIPTION("RME HDSPM"); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); |
| 88 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 89 | /* --- Write registers. --- |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 90 | These are defined as byte-offsets from the iobase value. */ |
| 91 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 92 | #define HDSPM_WR_SETTINGS 0 |
| 93 | #define HDSPM_outputBufferAddress 32 |
| 94 | #define HDSPM_inputBufferAddress 36 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 95 | #define HDSPM_controlRegister 64 |
| 96 | #define HDSPM_interruptConfirmation 96 |
| 97 | #define HDSPM_control2Reg 256 /* not in specs ???????? */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 98 | #define HDSPM_freqReg 256 /* for AES32 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 99 | #define HDSPM_midiDataOut0 352 /* just believe in old code */ |
| 100 | #define HDSPM_midiDataOut1 356 |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 101 | #define HDSPM_eeprom_wr 384 /* for AES32 */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 102 | |
| 103 | /* DMA enable for 64 channels, only Bit 0 is relevant */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 104 | #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 105 | #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */ |
| 106 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 107 | /* 16 page addresses for each of the 64 channels DMA buffer in and out |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 108 | (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */ |
| 109 | #define HDSPM_pageAddressBufferOut 8192 |
| 110 | #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4) |
| 111 | |
| 112 | #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */ |
| 113 | |
| 114 | #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */ |
| 115 | |
| 116 | /* --- Read registers. --- |
| 117 | These are defined as byte-offsets from the iobase value */ |
| 118 | #define HDSPM_statusRegister 0 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 119 | /*#define HDSPM_statusRegister2 96 */ |
| 120 | /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at |
| 121 | * offset 192, for AES32 *and* MADI |
| 122 | * => need to check that offset 192 is working on MADI */ |
| 123 | #define HDSPM_statusRegister2 192 |
| 124 | #define HDSPM_timecodeRegister 128 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 125 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 126 | /* AIO, RayDAT */ |
| 127 | #define HDSPM_RD_STATUS_0 0 |
| 128 | #define HDSPM_RD_STATUS_1 64 |
| 129 | #define HDSPM_RD_STATUS_2 128 |
| 130 | #define HDSPM_RD_STATUS_3 192 |
| 131 | |
| 132 | #define HDSPM_RD_TCO 256 |
| 133 | #define HDSPM_RD_PLL_FREQ 512 |
| 134 | #define HDSPM_WR_TCO 128 |
| 135 | |
| 136 | #define HDSPM_TCO1_TCO_lock 0x00000001 |
| 137 | #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002 |
| 138 | #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004 |
| 139 | #define HDSPM_TCO1_LTC_Input_valid 0x00000008 |
| 140 | #define HDSPM_TCO1_WCK_Input_valid 0x00000010 |
| 141 | #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020 |
| 142 | #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040 |
| 143 | |
| 144 | #define HDSPM_TCO1_set_TC 0x00000100 |
| 145 | #define HDSPM_TCO1_set_drop_frame_flag 0x00000200 |
| 146 | #define HDSPM_TCO1_LTC_Format_LSB 0x00000400 |
| 147 | #define HDSPM_TCO1_LTC_Format_MSB 0x00000800 |
| 148 | |
| 149 | #define HDSPM_TCO2_TC_run 0x00010000 |
| 150 | #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000 |
| 151 | #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000 |
| 152 | #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000 |
| 153 | #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000 |
| 154 | #define HDSPM_TCO2_set_jam_sync 0x00200000 |
| 155 | #define HDSPM_TCO2_set_flywheel 0x00400000 |
| 156 | |
| 157 | #define HDSPM_TCO2_set_01_4 0x01000000 |
| 158 | #define HDSPM_TCO2_set_pull_down 0x02000000 |
| 159 | #define HDSPM_TCO2_set_pull_up 0x04000000 |
| 160 | #define HDSPM_TCO2_set_freq 0x08000000 |
| 161 | #define HDSPM_TCO2_set_term_75R 0x10000000 |
| 162 | #define HDSPM_TCO2_set_input_LSB 0x20000000 |
| 163 | #define HDSPM_TCO2_set_input_MSB 0x40000000 |
| 164 | #define HDSPM_TCO2_set_freq_from_app 0x80000000 |
| 165 | |
| 166 | |
| 167 | #define HDSPM_midiDataOut0 352 |
| 168 | #define HDSPM_midiDataOut1 356 |
| 169 | #define HDSPM_midiDataOut2 368 |
| 170 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 171 | #define HDSPM_midiDataIn0 360 |
| 172 | #define HDSPM_midiDataIn1 364 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 173 | #define HDSPM_midiDataIn2 372 |
| 174 | #define HDSPM_midiDataIn3 376 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 175 | |
| 176 | /* status is data bytes in MIDI-FIFO (0-128) */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 177 | #define HDSPM_midiStatusOut0 384 |
| 178 | #define HDSPM_midiStatusOut1 388 |
| 179 | #define HDSPM_midiStatusOut2 400 |
| 180 | |
| 181 | #define HDSPM_midiStatusIn0 392 |
| 182 | #define HDSPM_midiStatusIn1 396 |
| 183 | #define HDSPM_midiStatusIn2 404 |
| 184 | #define HDSPM_midiStatusIn3 408 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 185 | |
| 186 | |
| 187 | /* the meters are regular i/o-mapped registers, but offset |
| 188 | considerably from the rest. the peak registers are reset |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 189 | when read; the least-significant 4 bits are full-scale counters; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 190 | the actual peak value is in the most-significant 24 bits. |
| 191 | */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 192 | |
| 193 | #define HDSPM_MADI_INPUT_PEAK 4096 |
| 194 | #define HDSPM_MADI_PLAYBACK_PEAK 4352 |
| 195 | #define HDSPM_MADI_OUTPUT_PEAK 4608 |
| 196 | |
| 197 | #define HDSPM_MADI_INPUT_RMS_L 6144 |
| 198 | #define HDSPM_MADI_PLAYBACK_RMS_L 6400 |
| 199 | #define HDSPM_MADI_OUTPUT_RMS_L 6656 |
| 200 | |
| 201 | #define HDSPM_MADI_INPUT_RMS_H 7168 |
| 202 | #define HDSPM_MADI_PLAYBACK_RMS_H 7424 |
| 203 | #define HDSPM_MADI_OUTPUT_RMS_H 7680 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 204 | |
| 205 | /* --- Control Register bits --------- */ |
| 206 | #define HDSPM_Start (1<<0) /* start engine */ |
| 207 | |
| 208 | #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */ |
| 209 | #define HDSPM_Latency1 (1<<2) /* where n is defined */ |
| 210 | #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */ |
| 211 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 212 | #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */ |
| 213 | #define HDSPM_c0Master 0x1 /* Master clock bit in settings |
| 214 | register [RayDAT, AIO] */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 215 | |
| 216 | #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */ |
| 217 | |
| 218 | #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */ |
| 219 | #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */ |
| 220 | #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 221 | #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 222 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 223 | #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 224 | #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 225 | 56channelMODE=0 */ /* MADI ONLY*/ |
| 226 | #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 227 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 228 | #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 229 | 0=off, 1=on */ /* MADI ONLY */ |
| 230 | #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 231 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 232 | #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax |
| 233 | * -- MADI ONLY |
| 234 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 235 | #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ |
| 236 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 237 | #define HDSPM_SyncRef2 (1<<13) |
| 238 | #define HDSPM_SyncRef3 (1<<25) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 239 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 240 | #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 241 | #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 242 | AES additional bits in |
| 243 | lower 5 Audiodatabits ??? */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 244 | #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */ |
| 245 | #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 246 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 247 | #define HDSPM_Midi0InterruptEnable 0x0400000 |
| 248 | #define HDSPM_Midi1InterruptEnable 0x0800000 |
| 249 | #define HDSPM_Midi2InterruptEnable 0x0200000 |
| 250 | #define HDSPM_Midi3InterruptEnable 0x4000000 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 251 | |
| 252 | #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 253 | #define HDSPe_FLOAT_FORMAT 0x2000000 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 254 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 255 | #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */ |
| 256 | #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */ |
| 257 | #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */ |
| 258 | |
| 259 | #define HDSPM_wclk_sel (1<<30) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 260 | |
| 261 | /* --- bit helper defines */ |
| 262 | #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 263 | #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\ |
| 264 | HDSPM_DoubleSpeed|HDSPM_QuadSpeed) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 265 | #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) |
| 266 | #define HDSPM_InputOptical 0 |
| 267 | #define HDSPM_InputCoaxial (HDSPM_InputSelect0) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 268 | #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\ |
| 269 | HDSPM_SyncRef2|HDSPM_SyncRef3) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 270 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 271 | #define HDSPM_c0_SyncRef0 0x2 |
| 272 | #define HDSPM_c0_SyncRef1 0x4 |
| 273 | #define HDSPM_c0_SyncRef2 0x8 |
| 274 | #define HDSPM_c0_SyncRef3 0x10 |
| 275 | #define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\ |
| 276 | HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3) |
| 277 | |
| 278 | #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */ |
| 279 | #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */ |
| 280 | #define HDSPM_SYNC_FROM_TCO 2 |
| 281 | #define HDSPM_SYNC_FROM_SYNC_IN 3 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 282 | |
| 283 | #define HDSPM_Frequency32KHz HDSPM_Frequency0 |
| 284 | #define HDSPM_Frequency44_1KHz HDSPM_Frequency1 |
| 285 | #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0) |
| 286 | #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0) |
| 287 | #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 288 | #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\ |
| 289 | HDSPM_Frequency0) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 290 | #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) |
| 291 | #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 292 | #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\ |
| 293 | HDSPM_Frequency0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 294 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 295 | |
| 296 | /* Synccheck Status */ |
| 297 | #define HDSPM_SYNC_CHECK_NO_LOCK 0 |
| 298 | #define HDSPM_SYNC_CHECK_LOCK 1 |
| 299 | #define HDSPM_SYNC_CHECK_SYNC 2 |
| 300 | |
| 301 | /* AutoSync References - used by "autosync_ref" control switch */ |
| 302 | #define HDSPM_AUTOSYNC_FROM_WORD 0 |
| 303 | #define HDSPM_AUTOSYNC_FROM_MADI 1 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 304 | #define HDSPM_AUTOSYNC_FROM_TCO 2 |
| 305 | #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3 |
| 306 | #define HDSPM_AUTOSYNC_FROM_NONE 4 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 307 | |
| 308 | /* Possible sources of MADI input */ |
| 309 | #define HDSPM_OPTICAL 0 /* optical */ |
| 310 | #define HDSPM_COAXIAL 1 /* BNC */ |
| 311 | |
| 312 | #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 313 | #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1)) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 314 | |
| 315 | #define hdspm_encode_in(x) (((x)&0x3)<<14) |
| 316 | #define hdspm_decode_in(x) (((x)>>14)&0x3) |
| 317 | |
| 318 | /* --- control2 register bits --- */ |
| 319 | #define HDSPM_TMS (1<<0) |
| 320 | #define HDSPM_TCK (1<<1) |
| 321 | #define HDSPM_TDI (1<<2) |
| 322 | #define HDSPM_JTAG (1<<3) |
| 323 | #define HDSPM_PWDN (1<<4) |
| 324 | #define HDSPM_PROGRAM (1<<5) |
| 325 | #define HDSPM_CONFIG_MODE_0 (1<<6) |
| 326 | #define HDSPM_CONFIG_MODE_1 (1<<7) |
| 327 | /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/ |
| 328 | #define HDSPM_BIGENDIAN_MODE (1<<9) |
| 329 | #define HDSPM_RD_MULTIPLE (1<<10) |
| 330 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 331 | /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 332 | that do not conflict with specific bits for AES32 seem to be valid also |
| 333 | for the AES32 |
| 334 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 335 | #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 336 | #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */ |
| 337 | #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 |
| 338 | * (like inp0) |
| 339 | */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 340 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 341 | #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 342 | #define HDSPM_madiSync (1<<18) /* MADI is in sync */ |
| 343 | |
| 344 | #define HDSPM_tcoLock 0x00000020 /* Optional TCO locked status FOR HDSPe MADI! */ |
| 345 | #define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status */ |
| 346 | |
| 347 | #define HDSPM_syncInLock 0x00010000 /* Sync In lock status FOR HDSPe MADI! */ |
| 348 | #define HDSPM_syncInSync 0x00020000 /* Sync In sync status FOR HDSPe MADI! */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 349 | |
| 350 | #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 351 | /* since 64byte accurate, last 6 bits are not used */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 352 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 353 | |
| 354 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 355 | #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */ |
| 356 | |
| 357 | #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */ |
| 358 | #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */ |
| 359 | #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */ |
| 360 | #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */ |
| 361 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 362 | #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with |
| 363 | * Interrupt |
| 364 | */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 365 | #define HDSPM_tco_detect 0x08000000 |
| 366 | #define HDSPM_tco_lock 0x20000000 |
| 367 | |
| 368 | #define HDSPM_s2_tco_detect 0x00000040 |
| 369 | #define HDSPM_s2_AEBO_D 0x00000080 |
| 370 | #define HDSPM_s2_AEBI_D 0x00000100 |
| 371 | |
| 372 | |
| 373 | #define HDSPM_midi0IRQPending 0x40000000 |
| 374 | #define HDSPM_midi1IRQPending 0x80000000 |
| 375 | #define HDSPM_midi2IRQPending 0x20000000 |
| 376 | #define HDSPM_midi2IRQPendingAES 0x00000020 |
| 377 | #define HDSPM_midi3IRQPending 0x00200000 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 378 | |
| 379 | /* --- status bit helpers */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 380 | #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\ |
| 381 | HDSPM_madiFreq2|HDSPM_madiFreq3) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 382 | #define HDSPM_madiFreq32 (HDSPM_madiFreq0) |
| 383 | #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1) |
| 384 | #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1) |
| 385 | #define HDSPM_madiFreq64 (HDSPM_madiFreq2) |
| 386 | #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2) |
| 387 | #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2) |
| 388 | #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2) |
| 389 | #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3) |
| 390 | #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0) |
| 391 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 392 | /* Status2 Register bits */ /* MADI ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 393 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 394 | #define HDSPM_version0 (1<<0) /* not really defined but I guess */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 395 | #define HDSPM_version1 (1<<1) /* in former cards it was ??? */ |
| 396 | #define HDSPM_version2 (1<<2) |
| 397 | |
| 398 | #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */ |
| 399 | #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */ |
| 400 | |
| 401 | #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */ |
| 402 | #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */ |
| 403 | #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, */ |
| 404 | /* missing Bit for 111=128, 1000=176.4, 1001=192 */ |
| 405 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 406 | #define HDSPM_SyncRef0 0x10000 /* Sync Reference */ |
| 407 | #define HDSPM_SyncRef1 0x20000 |
| 408 | |
| 409 | #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 410 | #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */ |
| 411 | #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */ |
| 412 | |
| 413 | #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync) |
| 414 | |
| 415 | #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2) |
| 416 | #define HDSPM_wcFreq32 (HDSPM_wc_freq0) |
| 417 | #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1) |
| 418 | #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1) |
| 419 | #define HDSPM_wcFreq64 (HDSPM_wc_freq2) |
| 420 | #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2) |
| 421 | #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2) |
| 422 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 423 | #define HDSPM_status1_F_0 0x0400000 |
| 424 | #define HDSPM_status1_F_1 0x0800000 |
| 425 | #define HDSPM_status1_F_2 0x1000000 |
| 426 | #define HDSPM_status1_F_3 0x2000000 |
| 427 | #define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3) |
| 428 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 429 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 430 | #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
| 431 | HDSPM_SelSyncRef2) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 432 | #define HDSPM_SelSyncRef_WORD 0 |
| 433 | #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 434 | #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1) |
| 435 | #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 436 | #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
| 437 | HDSPM_SelSyncRef2) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 438 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 439 | /* |
| 440 | For AES32, bits for status, status2 and timecode are different |
| 441 | */ |
| 442 | /* status */ |
| 443 | #define HDSPM_AES32_wcLock 0x0200000 |
Andre Schramm | 56bde0f | 2013-01-09 14:40:18 +0100 | [diff] [blame] | 444 | #define HDSPM_AES32_wcSync 0x0100000 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 445 | #define HDSPM_AES32_wcFreq_bit 22 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 446 | /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 447 | HDSPM_bit2freq */ |
| 448 | #define HDSPM_AES32_syncref_bit 16 |
| 449 | /* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */ |
| 450 | |
| 451 | #define HDSPM_AES32_AUTOSYNC_FROM_WORD 0 |
| 452 | #define HDSPM_AES32_AUTOSYNC_FROM_AES1 1 |
| 453 | #define HDSPM_AES32_AUTOSYNC_FROM_AES2 2 |
| 454 | #define HDSPM_AES32_AUTOSYNC_FROM_AES3 3 |
| 455 | #define HDSPM_AES32_AUTOSYNC_FROM_AES4 4 |
| 456 | #define HDSPM_AES32_AUTOSYNC_FROM_AES5 5 |
| 457 | #define HDSPM_AES32_AUTOSYNC_FROM_AES6 6 |
| 458 | #define HDSPM_AES32_AUTOSYNC_FROM_AES7 7 |
| 459 | #define HDSPM_AES32_AUTOSYNC_FROM_AES8 8 |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 460 | #define HDSPM_AES32_AUTOSYNC_FROM_NONE 9 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 461 | |
| 462 | /* status2 */ |
| 463 | /* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */ |
| 464 | #define HDSPM_LockAES 0x80 |
| 465 | #define HDSPM_LockAES1 0x80 |
| 466 | #define HDSPM_LockAES2 0x40 |
| 467 | #define HDSPM_LockAES3 0x20 |
| 468 | #define HDSPM_LockAES4 0x10 |
| 469 | #define HDSPM_LockAES5 0x8 |
| 470 | #define HDSPM_LockAES6 0x4 |
| 471 | #define HDSPM_LockAES7 0x2 |
| 472 | #define HDSPM_LockAES8 0x1 |
| 473 | /* |
| 474 | Timecode |
| 475 | After windows driver sources, bits 4*i to 4*i+3 give the input frequency on |
| 476 | AES i+1 |
| 477 | bits 3210 |
| 478 | 0001 32kHz |
| 479 | 0010 44.1kHz |
| 480 | 0011 48kHz |
| 481 | 0100 64kHz |
| 482 | 0101 88.2kHz |
| 483 | 0110 96kHz |
| 484 | 0111 128kHz |
| 485 | 1000 176.4kHz |
| 486 | 1001 192kHz |
| 487 | NB: Timecode register doesn't seem to work on AES32 card revision 230 |
| 488 | */ |
| 489 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 490 | /* Mixer Values */ |
| 491 | #define UNITY_GAIN 32768 /* = 65536/2 */ |
| 492 | #define MINUS_INFINITY_GAIN 0 |
| 493 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 494 | /* Number of channels for different Speed Modes */ |
| 495 | #define MADI_SS_CHANNELS 64 |
| 496 | #define MADI_DS_CHANNELS 32 |
| 497 | #define MADI_QS_CHANNELS 16 |
| 498 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 499 | #define RAYDAT_SS_CHANNELS 36 |
| 500 | #define RAYDAT_DS_CHANNELS 20 |
| 501 | #define RAYDAT_QS_CHANNELS 12 |
| 502 | |
| 503 | #define AIO_IN_SS_CHANNELS 14 |
| 504 | #define AIO_IN_DS_CHANNELS 10 |
| 505 | #define AIO_IN_QS_CHANNELS 8 |
| 506 | #define AIO_OUT_SS_CHANNELS 16 |
| 507 | #define AIO_OUT_DS_CHANNELS 12 |
| 508 | #define AIO_OUT_QS_CHANNELS 10 |
| 509 | |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 510 | #define AES32_CHANNELS 16 |
| 511 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 512 | /* the size of a substream (1 mono data stream) */ |
| 513 | #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024) |
| 514 | #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES) |
| 515 | |
| 516 | /* the size of the area we need to allocate for DMA transfers. the |
| 517 | size is the same regardless of the number of channels, and |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 518 | also the latency to use. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 519 | for one direction !!! |
| 520 | */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 521 | #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 522 | #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024) |
| 523 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 524 | #define HDSPM_RAYDAT_REV 211 |
| 525 | #define HDSPM_AIO_REV 212 |
| 526 | #define HDSPM_MADIFACE_REV 213 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 527 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 528 | /* speed factor modes */ |
| 529 | #define HDSPM_SPEED_SINGLE 0 |
| 530 | #define HDSPM_SPEED_DOUBLE 1 |
| 531 | #define HDSPM_SPEED_QUAD 2 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 532 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 533 | /* names for speed modes */ |
| 534 | static char *hdspm_speed_names[] = { "single", "double", "quad" }; |
| 535 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 536 | static char *texts_autosync_aes_tco[] = { "Word Clock", |
| 537 | "AES1", "AES2", "AES3", "AES4", |
| 538 | "AES5", "AES6", "AES7", "AES8", |
| 539 | "TCO" }; |
| 540 | static char *texts_autosync_aes[] = { "Word Clock", |
| 541 | "AES1", "AES2", "AES3", "AES4", |
| 542 | "AES5", "AES6", "AES7", "AES8" }; |
| 543 | static char *texts_autosync_madi_tco[] = { "Word Clock", |
| 544 | "MADI", "TCO", "Sync In" }; |
| 545 | static char *texts_autosync_madi[] = { "Word Clock", |
| 546 | "MADI", "Sync In" }; |
| 547 | |
| 548 | static char *texts_autosync_raydat_tco[] = { |
| 549 | "Word Clock", |
| 550 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", |
| 551 | "AES", "SPDIF", "TCO", "Sync In" |
| 552 | }; |
| 553 | static char *texts_autosync_raydat[] = { |
| 554 | "Word Clock", |
| 555 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", |
| 556 | "AES", "SPDIF", "Sync In" |
| 557 | }; |
| 558 | static char *texts_autosync_aio_tco[] = { |
| 559 | "Word Clock", |
| 560 | "ADAT", "AES", "SPDIF", "TCO", "Sync In" |
| 561 | }; |
| 562 | static char *texts_autosync_aio[] = { "Word Clock", |
| 563 | "ADAT", "AES", "SPDIF", "Sync In" }; |
| 564 | |
| 565 | static char *texts_freq[] = { |
| 566 | "No Lock", |
| 567 | "32 kHz", |
| 568 | "44.1 kHz", |
| 569 | "48 kHz", |
| 570 | "64 kHz", |
| 571 | "88.2 kHz", |
| 572 | "96 kHz", |
| 573 | "128 kHz", |
| 574 | "176.4 kHz", |
| 575 | "192 kHz" |
| 576 | }; |
| 577 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 578 | static char *texts_ports_madi[] = { |
| 579 | "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6", |
| 580 | "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12", |
| 581 | "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18", |
| 582 | "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24", |
| 583 | "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30", |
| 584 | "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36", |
| 585 | "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42", |
| 586 | "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48", |
| 587 | "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54", |
| 588 | "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60", |
| 589 | "MADI.61", "MADI.62", "MADI.63", "MADI.64", |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | static char *texts_ports_raydat_ss[] = { |
| 594 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6", |
| 595 | "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", |
| 596 | "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2", |
| 597 | "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8", |
| 598 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6", |
| 599 | "ADAT4.7", "ADAT4.8", |
| 600 | "AES.L", "AES.R", |
| 601 | "SPDIF.L", "SPDIF.R" |
| 602 | }; |
| 603 | |
| 604 | static char *texts_ports_raydat_ds[] = { |
| 605 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", |
| 606 | "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", |
| 607 | "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", |
| 608 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", |
| 609 | "AES.L", "AES.R", |
| 610 | "SPDIF.L", "SPDIF.R" |
| 611 | }; |
| 612 | |
| 613 | static char *texts_ports_raydat_qs[] = { |
| 614 | "ADAT1.1", "ADAT1.2", |
| 615 | "ADAT2.1", "ADAT2.2", |
| 616 | "ADAT3.1", "ADAT3.2", |
| 617 | "ADAT4.1", "ADAT4.2", |
| 618 | "AES.L", "AES.R", |
| 619 | "SPDIF.L", "SPDIF.R" |
| 620 | }; |
| 621 | |
| 622 | |
| 623 | static char *texts_ports_aio_in_ss[] = { |
| 624 | "Analogue.L", "Analogue.R", |
| 625 | "AES.L", "AES.R", |
| 626 | "SPDIF.L", "SPDIF.R", |
| 627 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", |
| 628 | "ADAT.7", "ADAT.8" |
| 629 | }; |
| 630 | |
| 631 | static char *texts_ports_aio_out_ss[] = { |
| 632 | "Analogue.L", "Analogue.R", |
| 633 | "AES.L", "AES.R", |
| 634 | "SPDIF.L", "SPDIF.R", |
| 635 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", |
| 636 | "ADAT.7", "ADAT.8", |
| 637 | "Phone.L", "Phone.R" |
| 638 | }; |
| 639 | |
| 640 | static char *texts_ports_aio_in_ds[] = { |
| 641 | "Analogue.L", "Analogue.R", |
| 642 | "AES.L", "AES.R", |
| 643 | "SPDIF.L", "SPDIF.R", |
| 644 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" |
| 645 | }; |
| 646 | |
| 647 | static char *texts_ports_aio_out_ds[] = { |
| 648 | "Analogue.L", "Analogue.R", |
| 649 | "AES.L", "AES.R", |
| 650 | "SPDIF.L", "SPDIF.R", |
| 651 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", |
| 652 | "Phone.L", "Phone.R" |
| 653 | }; |
| 654 | |
| 655 | static char *texts_ports_aio_in_qs[] = { |
| 656 | "Analogue.L", "Analogue.R", |
| 657 | "AES.L", "AES.R", |
| 658 | "SPDIF.L", "SPDIF.R", |
| 659 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" |
| 660 | }; |
| 661 | |
| 662 | static char *texts_ports_aio_out_qs[] = { |
| 663 | "Analogue.L", "Analogue.R", |
| 664 | "AES.L", "AES.R", |
| 665 | "SPDIF.L", "SPDIF.R", |
| 666 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", |
| 667 | "Phone.L", "Phone.R" |
| 668 | }; |
| 669 | |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 670 | static char *texts_ports_aes32[] = { |
| 671 | "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7", |
| 672 | "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14", |
| 673 | "AES.15", "AES.16" |
| 674 | }; |
| 675 | |
Adrian Knoth | 55a5760 | 2011-01-27 11:23:15 +0100 | [diff] [blame] | 676 | /* These tables map the ALSA channels 1..N to the channels that we |
| 677 | need to use in order to find the relevant channel buffer. RME |
| 678 | refers to this kind of mapping as between "the ADAT channel and |
| 679 | the DMA channel." We index it using the logical audio channel, |
| 680 | and the value is the DMA channel (i.e. channel buffer number) |
| 681 | where the data for that channel can be read/written from/to. |
| 682 | */ |
| 683 | |
| 684 | static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { |
| 685 | 0, 1, 2, 3, 4, 5, 6, 7, |
| 686 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 687 | 16, 17, 18, 19, 20, 21, 22, 23, |
| 688 | 24, 25, 26, 27, 28, 29, 30, 31, |
| 689 | 32, 33, 34, 35, 36, 37, 38, 39, |
| 690 | 40, 41, 42, 43, 44, 45, 46, 47, |
| 691 | 48, 49, 50, 51, 52, 53, 54, 55, |
| 692 | 56, 57, 58, 59, 60, 61, 62, 63 |
| 693 | }; |
| 694 | |
Adrian Knoth | 55a5760 | 2011-01-27 11:23:15 +0100 | [diff] [blame] | 695 | static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { |
| 696 | 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */ |
| 697 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */ |
| 698 | 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */ |
| 699 | 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */ |
| 700 | 0, 1, /* AES */ |
| 701 | 2, 3, /* SPDIF */ |
| 702 | -1, -1, -1, -1, |
| 703 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 704 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 705 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 706 | }; |
| 707 | |
| 708 | static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { |
| 709 | 4, 5, 6, 7, /* ADAT 1 */ |
| 710 | 8, 9, 10, 11, /* ADAT 2 */ |
| 711 | 12, 13, 14, 15, /* ADAT 3 */ |
| 712 | 16, 17, 18, 19, /* ADAT 4 */ |
| 713 | 0, 1, /* AES */ |
| 714 | 2, 3, /* SPDIF */ |
| 715 | -1, -1, -1, -1, |
| 716 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 717 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 718 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 719 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 720 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 721 | }; |
| 722 | |
| 723 | static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { |
| 724 | 4, 5, /* ADAT 1 */ |
| 725 | 6, 7, /* ADAT 2 */ |
| 726 | 8, 9, /* ADAT 3 */ |
| 727 | 10, 11, /* ADAT 4 */ |
| 728 | 0, 1, /* AES */ |
| 729 | 2, 3, /* SPDIF */ |
| 730 | -1, -1, -1, -1, |
| 731 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 732 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 733 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 734 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 735 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 736 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 737 | }; |
| 738 | |
| 739 | static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { |
| 740 | 0, 1, /* line in */ |
| 741 | 8, 9, /* aes in, */ |
| 742 | 10, 11, /* spdif in */ |
| 743 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */ |
| 744 | -1, -1, |
| 745 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 746 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 747 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 748 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 749 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 750 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 751 | }; |
| 752 | |
| 753 | static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { |
| 754 | 0, 1, /* line out */ |
| 755 | 8, 9, /* aes out */ |
| 756 | 10, 11, /* spdif out */ |
| 757 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */ |
| 758 | 6, 7, /* phone out */ |
| 759 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 760 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 761 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 762 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 763 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 764 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 765 | }; |
| 766 | |
| 767 | static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { |
| 768 | 0, 1, /* line in */ |
| 769 | 8, 9, /* aes in */ |
| 770 | 10, 11, /* spdif in */ |
| 771 | 12, 14, 16, 18, /* adat in */ |
| 772 | -1, -1, -1, -1, -1, -1, |
| 773 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 774 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 775 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 776 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 777 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 778 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 779 | }; |
| 780 | |
| 781 | static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { |
| 782 | 0, 1, /* line out */ |
| 783 | 8, 9, /* aes out */ |
| 784 | 10, 11, /* spdif out */ |
| 785 | 12, 14, 16, 18, /* adat out */ |
| 786 | 6, 7, /* phone out */ |
| 787 | -1, -1, -1, -1, |
| 788 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 789 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 790 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 791 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 792 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 793 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 794 | }; |
| 795 | |
| 796 | static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { |
| 797 | 0, 1, /* line in */ |
| 798 | 8, 9, /* aes in */ |
| 799 | 10, 11, /* spdif in */ |
| 800 | 12, 16, /* adat in */ |
| 801 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 802 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 803 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 804 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 805 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 806 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 807 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 808 | }; |
| 809 | |
| 810 | static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { |
| 811 | 0, 1, /* line out */ |
| 812 | 8, 9, /* aes out */ |
| 813 | 10, 11, /* spdif out */ |
| 814 | 12, 16, /* adat out */ |
| 815 | 6, 7, /* phone out */ |
| 816 | -1, -1, -1, -1, -1, -1, |
| 817 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 818 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 819 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 820 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 821 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 822 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 823 | }; |
| 824 | |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 825 | static char channel_map_aes32[HDSPM_MAX_CHANNELS] = { |
| 826 | 0, 1, 2, 3, 4, 5, 6, 7, |
| 827 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 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 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 832 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 833 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 834 | }; |
| 835 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 836 | struct hdspm_midi { |
| 837 | struct hdspm *hdspm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 838 | int id; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 839 | struct snd_rawmidi *rmidi; |
| 840 | struct snd_rawmidi_substream *input; |
| 841 | struct snd_rawmidi_substream *output; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 842 | char istimer; /* timer in use */ |
| 843 | struct timer_list timer; |
| 844 | spinlock_t lock; |
| 845 | int pending; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 846 | int dataIn; |
| 847 | int statusIn; |
| 848 | int dataOut; |
| 849 | int statusOut; |
| 850 | int ie; |
| 851 | int irq; |
| 852 | }; |
| 853 | |
| 854 | struct hdspm_tco { |
| 855 | int input; |
| 856 | int framerate; |
| 857 | int wordclock; |
| 858 | int samplerate; |
| 859 | int pull; |
| 860 | int term; /* 0 = off, 1 = on */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 861 | }; |
| 862 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 863 | struct hdspm { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 864 | spinlock_t lock; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 865 | /* only one playback and/or capture stream */ |
| 866 | struct snd_pcm_substream *capture_substream; |
| 867 | struct snd_pcm_substream *playback_substream; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 868 | |
| 869 | char *card_name; /* for procinfo */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 870 | unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ |
| 871 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 872 | uint8_t io_type; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 873 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 874 | int monitor_outs; /* set up monitoring outs init flag */ |
| 875 | |
| 876 | u32 control_register; /* cached value */ |
| 877 | u32 control2_register; /* cached value */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 878 | u32 settings_register; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 879 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 880 | struct hdspm_midi midi[4]; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 881 | struct tasklet_struct midi_tasklet; |
| 882 | |
| 883 | size_t period_bytes; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 884 | unsigned char ss_in_channels; |
| 885 | unsigned char ds_in_channels; |
| 886 | unsigned char qs_in_channels; |
| 887 | unsigned char ss_out_channels; |
| 888 | unsigned char ds_out_channels; |
| 889 | unsigned char qs_out_channels; |
| 890 | |
| 891 | unsigned char max_channels_in; |
| 892 | unsigned char max_channels_out; |
| 893 | |
Takashi Iwai | 286bed0 | 2011-06-30 12:45:36 +0200 | [diff] [blame] | 894 | signed char *channel_map_in; |
| 895 | signed char *channel_map_out; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 896 | |
Takashi Iwai | 286bed0 | 2011-06-30 12:45:36 +0200 | [diff] [blame] | 897 | signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; |
| 898 | signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 899 | |
| 900 | char **port_names_in; |
| 901 | char **port_names_out; |
| 902 | |
| 903 | char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs; |
| 904 | char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 905 | |
| 906 | unsigned char *playback_buffer; /* suitably aligned address */ |
| 907 | unsigned char *capture_buffer; /* suitably aligned address */ |
| 908 | |
| 909 | pid_t capture_pid; /* process id which uses capture */ |
| 910 | pid_t playback_pid; /* process id which uses capture */ |
| 911 | int running; /* running status */ |
| 912 | |
| 913 | int last_external_sample_rate; /* samplerate mystic ... */ |
| 914 | int last_internal_sample_rate; |
| 915 | int system_sample_rate; |
| 916 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 917 | int dev; /* Hardware vars... */ |
| 918 | int irq; |
| 919 | unsigned long port; |
| 920 | void __iomem *iobase; |
| 921 | |
| 922 | int irq_count; /* for debug */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 923 | int midiPorts; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 924 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 925 | struct snd_card *card; /* one card */ |
| 926 | struct snd_pcm *pcm; /* has one pcm */ |
| 927 | struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 928 | struct pci_dev *pci; /* and an pci info */ |
| 929 | |
| 930 | /* Mixer vars */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 931 | /* fast alsa mixer */ |
| 932 | struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; |
| 933 | /* but input to much, so not used */ |
| 934 | struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 935 | /* full mixer accessible over mixer ioctl or hwdep-device */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 936 | struct hdspm_mixer *mixer; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 937 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 938 | struct hdspm_tco *tco; /* NULL if no TCO detected */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 939 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 940 | char **texts_autosync; |
| 941 | int texts_autosync_items; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 942 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 943 | cycles_t last_interrupt; |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 944 | |
Adrian Knoth | 7d53a63 | 2012-01-04 14:31:16 +0100 | [diff] [blame] | 945 | unsigned int serial; |
| 946 | |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 947 | struct hdspm_peak_rms peak_rms; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 948 | }; |
| 949 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 950 | |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 951 | static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 952 | { |
| 953 | .vendor = PCI_VENDOR_ID_XILINX, |
| 954 | .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI, |
| 955 | .subvendor = PCI_ANY_ID, |
| 956 | .subdevice = PCI_ANY_ID, |
| 957 | .class = 0, |
| 958 | .class_mask = 0, |
| 959 | .driver_data = 0}, |
| 960 | {0,} |
| 961 | }; |
| 962 | |
| 963 | MODULE_DEVICE_TABLE(pci, snd_hdspm_ids); |
| 964 | |
| 965 | /* prototypes */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 966 | static int snd_hdspm_create_alsa_devices(struct snd_card *card, |
| 967 | struct hdspm *hdspm); |
| 968 | static int snd_hdspm_create_pcm(struct snd_card *card, |
| 969 | struct hdspm *hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 970 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 971 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm); |
Adrian Knoth | 3f7bf91 | 2013-03-10 00:37:21 +0100 | [diff] [blame] | 972 | static inline int hdspm_get_pll_freq(struct hdspm *hdspm); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 973 | static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm); |
| 974 | static int hdspm_autosync_ref(struct hdspm *hdspm); |
| 975 | static int snd_hdspm_set_defaults(struct hdspm *hdspm); |
Adrian Knoth | 21a164d | 2012-10-19 17:42:23 +0200 | [diff] [blame] | 976 | static int hdspm_system_clock_mode(struct hdspm *hdspm); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 977 | static void hdspm_set_sgbuf(struct hdspm *hdspm, |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 978 | struct snd_pcm_substream *substream, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 979 | unsigned int reg, int channels); |
| 980 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 981 | static inline int HDSPM_bit2freq(int n) |
| 982 | { |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 983 | static const int bit2freq_tab[] = { |
| 984 | 0, 32000, 44100, 48000, 64000, 88200, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 985 | 96000, 128000, 176400, 192000 }; |
| 986 | if (n < 1 || n > 9) |
| 987 | return 0; |
| 988 | return bit2freq_tab[n]; |
| 989 | } |
| 990 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 991 | /* Write/read to/from HDSPM with Adresses in Bytes |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 992 | not words but only 32Bit writes are allowed */ |
| 993 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 994 | static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 995 | unsigned int val) |
| 996 | { |
| 997 | writel(val, hdspm->iobase + reg); |
| 998 | } |
| 999 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1000 | static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1001 | { |
| 1002 | return readl(hdspm->iobase + reg); |
| 1003 | } |
| 1004 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1005 | /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader |
| 1006 | mixer is write only on hardware so we have to cache him for read |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1007 | each fader is a u32, but uses only the first 16 bit */ |
| 1008 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1009 | static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1010 | unsigned int in) |
| 1011 | { |
Adrian Bunk | 5bab2482 | 2006-03-13 14:15:04 +0100 | [diff] [blame] | 1012 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1013 | return 0; |
| 1014 | |
| 1015 | return hdspm->mixer->ch[chan].in[in]; |
| 1016 | } |
| 1017 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1018 | static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1019 | unsigned int pb) |
| 1020 | { |
Adrian Bunk | 5bab2482 | 2006-03-13 14:15:04 +0100 | [diff] [blame] | 1021 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1022 | return 0; |
| 1023 | return hdspm->mixer->ch[chan].pb[pb]; |
| 1024 | } |
| 1025 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1026 | static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1027 | unsigned int in, unsigned short data) |
| 1028 | { |
| 1029 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) |
| 1030 | return -1; |
| 1031 | |
| 1032 | hdspm_write(hdspm, |
| 1033 | HDSPM_MADI_mixerBase + |
| 1034 | ((in + 128 * chan) * sizeof(u32)), |
| 1035 | (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF)); |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1039 | static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1040 | unsigned int pb, unsigned short data) |
| 1041 | { |
| 1042 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) |
| 1043 | return -1; |
| 1044 | |
| 1045 | hdspm_write(hdspm, |
| 1046 | HDSPM_MADI_mixerBase + |
| 1047 | ((64 + pb + 128 * chan) * sizeof(u32)), |
| 1048 | (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF)); |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | /* enable DMA for specific channels, now available for DSP-MADI */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1054 | static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1055 | { |
| 1056 | hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v); |
| 1057 | } |
| 1058 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1059 | static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1060 | { |
| 1061 | hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v); |
| 1062 | } |
| 1063 | |
| 1064 | /* check if same process is writing and reading */ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1065 | static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1066 | { |
| 1067 | unsigned long flags; |
| 1068 | int ret = 1; |
| 1069 | |
| 1070 | spin_lock_irqsave(&hdspm->lock, flags); |
| 1071 | if ((hdspm->playback_pid != hdspm->capture_pid) && |
| 1072 | (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) { |
| 1073 | ret = 0; |
| 1074 | } |
| 1075 | spin_unlock_irqrestore(&hdspm->lock, flags); |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
Adrian Knoth | fcdc4ba | 2013-03-10 00:37:22 +0100 | [diff] [blame] | 1079 | /* round arbitary sample rates to commonly known rates */ |
| 1080 | static int hdspm_round_frequency(int rate) |
| 1081 | { |
| 1082 | if (rate < 38050) |
| 1083 | return 32000; |
| 1084 | if (rate < 46008) |
| 1085 | return 44100; |
| 1086 | else |
| 1087 | return 48000; |
| 1088 | } |
| 1089 | |
| 1090 | static int hdspm_tco_sync_check(struct hdspm *hdspm); |
| 1091 | static int hdspm_sync_in_sync_check(struct hdspm *hdspm); |
| 1092 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1093 | /* check for external sample rate */ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1094 | static int hdspm_external_sample_rate(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1095 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1096 | unsigned int status, status2, timecode; |
| 1097 | int syncref, rate = 0, rate_bits; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1098 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1099 | switch (hdspm->io_type) { |
| 1100 | case AES32: |
| 1101 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 1102 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 1103 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1104 | |
| 1105 | syncref = hdspm_autosync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1106 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1107 | if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD && |
| 1108 | status & HDSPM_AES32_wcLock) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1109 | return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF); |
| 1110 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1111 | if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1112 | syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 && |
| 1113 | status2 & (HDSPM_LockAES >> |
| 1114 | (syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))) |
| 1115 | return HDSPM_bit2freq((timecode >> (4*(syncref-HDSPM_AES32_AUTOSYNC_FROM_AES1))) & 0xF); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1116 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1117 | break; |
| 1118 | |
| 1119 | case MADIface: |
| 1120 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 1121 | |
| 1122 | if (!(status & HDSPM_madiLock)) { |
| 1123 | rate = 0; /* no lock */ |
| 1124 | } else { |
| 1125 | switch (status & (HDSPM_status1_freqMask)) { |
| 1126 | case HDSPM_status1_F_0*1: |
| 1127 | rate = 32000; break; |
| 1128 | case HDSPM_status1_F_0*2: |
| 1129 | rate = 44100; break; |
| 1130 | case HDSPM_status1_F_0*3: |
| 1131 | rate = 48000; break; |
| 1132 | case HDSPM_status1_F_0*4: |
| 1133 | rate = 64000; break; |
| 1134 | case HDSPM_status1_F_0*5: |
| 1135 | rate = 88200; break; |
| 1136 | case HDSPM_status1_F_0*6: |
| 1137 | rate = 96000; break; |
| 1138 | case HDSPM_status1_F_0*7: |
| 1139 | rate = 128000; break; |
| 1140 | case HDSPM_status1_F_0*8: |
| 1141 | rate = 176400; break; |
| 1142 | case HDSPM_status1_F_0*9: |
| 1143 | rate = 192000; break; |
| 1144 | default: |
| 1145 | rate = 0; break; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | break; |
| 1150 | |
| 1151 | case MADI: |
| 1152 | case AIO: |
| 1153 | case RayDAT: |
| 1154 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 1155 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 1156 | rate = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1157 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1158 | /* if wordclock has synced freq and wordclock is valid */ |
| 1159 | if ((status2 & HDSPM_wcLock) != 0 && |
Adrian Knoth | fedf153 | 2011-06-12 17:26:18 +0200 | [diff] [blame] | 1160 | (status2 & HDSPM_SelSyncRef0) == 0) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1161 | |
| 1162 | rate_bits = status2 & HDSPM_wcFreqMask; |
| 1163 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1164 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1165 | switch (rate_bits) { |
| 1166 | case HDSPM_wcFreq32: |
| 1167 | rate = 32000; |
| 1168 | break; |
| 1169 | case HDSPM_wcFreq44_1: |
| 1170 | rate = 44100; |
| 1171 | break; |
| 1172 | case HDSPM_wcFreq48: |
| 1173 | rate = 48000; |
| 1174 | break; |
| 1175 | case HDSPM_wcFreq64: |
| 1176 | rate = 64000; |
| 1177 | break; |
| 1178 | case HDSPM_wcFreq88_2: |
| 1179 | rate = 88200; |
| 1180 | break; |
| 1181 | case HDSPM_wcFreq96: |
| 1182 | rate = 96000; |
| 1183 | break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1184 | default: |
| 1185 | rate = 0; |
| 1186 | break; |
| 1187 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1188 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1189 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1190 | /* if rate detected and Syncref is Word than have it, |
| 1191 | * word has priority to MADI |
| 1192 | */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1193 | if (rate != 0 && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1194 | (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1195 | return rate; |
| 1196 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1197 | /* maybe a madi input (which is taken if sel sync is madi) */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1198 | if (status & HDSPM_madiLock) { |
| 1199 | rate_bits = status & HDSPM_madiFreqMask; |
| 1200 | |
| 1201 | switch (rate_bits) { |
| 1202 | case HDSPM_madiFreq32: |
| 1203 | rate = 32000; |
| 1204 | break; |
| 1205 | case HDSPM_madiFreq44_1: |
| 1206 | rate = 44100; |
| 1207 | break; |
| 1208 | case HDSPM_madiFreq48: |
| 1209 | rate = 48000; |
| 1210 | break; |
| 1211 | case HDSPM_madiFreq64: |
| 1212 | rate = 64000; |
| 1213 | break; |
| 1214 | case HDSPM_madiFreq88_2: |
| 1215 | rate = 88200; |
| 1216 | break; |
| 1217 | case HDSPM_madiFreq96: |
| 1218 | rate = 96000; |
| 1219 | break; |
| 1220 | case HDSPM_madiFreq128: |
| 1221 | rate = 128000; |
| 1222 | break; |
| 1223 | case HDSPM_madiFreq176_4: |
| 1224 | rate = 176400; |
| 1225 | break; |
| 1226 | case HDSPM_madiFreq192: |
| 1227 | rate = 192000; |
| 1228 | break; |
| 1229 | default: |
| 1230 | rate = 0; |
| 1231 | break; |
| 1232 | } |
Adrian Knoth | d12c51d | 2011-07-29 03:11:03 +0200 | [diff] [blame] | 1233 | |
Adrian Knoth | fcdc4ba | 2013-03-10 00:37:22 +0100 | [diff] [blame] | 1234 | } /* endif HDSPM_madiLock */ |
| 1235 | |
| 1236 | /* check sample rate from TCO or SYNC_IN */ |
| 1237 | { |
| 1238 | bool is_valid_input = 0; |
| 1239 | bool has_sync = 0; |
| 1240 | |
| 1241 | syncref = hdspm_autosync_ref(hdspm); |
| 1242 | if (HDSPM_AUTOSYNC_FROM_TCO == syncref) { |
| 1243 | is_valid_input = 1; |
| 1244 | has_sync = (HDSPM_SYNC_CHECK_SYNC == |
| 1245 | hdspm_tco_sync_check(hdspm)); |
| 1246 | } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) { |
| 1247 | is_valid_input = 1; |
| 1248 | has_sync = (HDSPM_SYNC_CHECK_SYNC == |
| 1249 | hdspm_sync_in_sync_check(hdspm)); |
Adrian Knoth | d12c51d | 2011-07-29 03:11:03 +0200 | [diff] [blame] | 1250 | } |
Adrian Knoth | fcdc4ba | 2013-03-10 00:37:22 +0100 | [diff] [blame] | 1251 | |
| 1252 | if (is_valid_input && has_sync) { |
| 1253 | rate = hdspm_round_frequency( |
| 1254 | hdspm_get_pll_freq(hdspm)); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | /* QS and DS rates normally can not be detected |
| 1259 | * automatically by the card. Only exception is MADI |
| 1260 | * in 96k frame mode. |
| 1261 | * |
| 1262 | * So if we read SS values (32 .. 48k), check for |
| 1263 | * user-provided DS/QS bits in the control register |
| 1264 | * and multiply the base frequency accordingly. |
| 1265 | */ |
| 1266 | if (rate <= 48000) { |
| 1267 | if (hdspm->control_register & HDSPM_QuadSpeed) |
| 1268 | rate *= 4; |
| 1269 | else if (hdspm->control_register & |
| 1270 | HDSPM_DoubleSpeed) |
| 1271 | rate *= 2; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1272 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1273 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1274 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1275 | |
| 1276 | return rate; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 1279 | /* return latency in samples per period */ |
| 1280 | static int hdspm_get_latency(struct hdspm *hdspm) |
| 1281 | { |
| 1282 | int n; |
| 1283 | |
| 1284 | n = hdspm_decode_latency(hdspm->control_register); |
| 1285 | |
| 1286 | /* Special case for new RME cards with 32 samples period size. |
| 1287 | * The three latency bits in the control register |
| 1288 | * (HDSP_LatencyMask) encode latency values of 64 samples as |
| 1289 | * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7 |
| 1290 | * denotes 8192 samples, but on new cards like RayDAT or AIO, |
| 1291 | * it corresponds to 32 samples. |
| 1292 | */ |
| 1293 | if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type)) |
| 1294 | n = -1; |
| 1295 | |
| 1296 | return 1 << (n + 6); |
| 1297 | } |
| 1298 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1299 | /* Latency function */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1300 | static inline void hdspm_compute_period_size(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1301 | { |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 1302 | hdspm->period_bytes = 4 * hdspm_get_latency(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1305 | |
| 1306 | static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1307 | { |
| 1308 | int position; |
| 1309 | |
| 1310 | position = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 483cee7 | 2011-02-23 11:43:09 +0100 | [diff] [blame] | 1311 | |
| 1312 | switch (hdspm->io_type) { |
| 1313 | case RayDAT: |
| 1314 | case AIO: |
| 1315 | position &= HDSPM_BufferPositionMask; |
| 1316 | position /= 4; /* Bytes per sample */ |
| 1317 | break; |
| 1318 | default: |
| 1319 | position = (position & HDSPM_BufferID) ? |
| 1320 | (hdspm->period_bytes / 4) : 0; |
| 1321 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1322 | |
| 1323 | return position; |
| 1324 | } |
| 1325 | |
| 1326 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1327 | static inline void hdspm_start_audio(struct hdspm * s) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1328 | { |
| 1329 | s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start); |
| 1330 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1331 | } |
| 1332 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1333 | static inline void hdspm_stop_audio(struct hdspm * s) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1334 | { |
| 1335 | s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable); |
| 1336 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1337 | } |
| 1338 | |
| 1339 | /* should I silence all or only opened ones ? doit all for first even is 4MB*/ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1340 | static void hdspm_silence_playback(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1341 | { |
| 1342 | int i; |
| 1343 | int n = hdspm->period_bytes; |
| 1344 | void *buf = hdspm->playback_buffer; |
| 1345 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1346 | if (buf == NULL) |
| 1347 | return; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1348 | |
| 1349 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { |
| 1350 | memset(buf, 0, n); |
| 1351 | buf += HDSPM_CHANNEL_BUFFER_BYTES; |
| 1352 | } |
| 1353 | } |
| 1354 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1355 | static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1356 | { |
| 1357 | int n; |
| 1358 | |
| 1359 | spin_lock_irq(&s->lock); |
| 1360 | |
Adrian Knoth | 2e61027 | 2011-08-15 00:22:54 +0200 | [diff] [blame] | 1361 | if (32 == frames) { |
| 1362 | /* Special case for new RME cards like RayDAT/AIO which |
| 1363 | * support period sizes of 32 samples. Since latency is |
| 1364 | * encoded in the three bits of HDSP_LatencyMask, we can only |
| 1365 | * have values from 0 .. 7. While 0 still means 64 samples and |
| 1366 | * 6 represents 4096 samples on all cards, 7 represents 8192 |
| 1367 | * on older cards and 32 samples on new cards. |
| 1368 | * |
| 1369 | * In other words, period size in samples is calculated by |
| 1370 | * 2^(n+6) with n ranging from 0 .. 7. |
| 1371 | */ |
| 1372 | n = 7; |
| 1373 | } else { |
| 1374 | frames >>= 7; |
| 1375 | n = 0; |
| 1376 | while (frames) { |
| 1377 | n++; |
| 1378 | frames >>= 1; |
| 1379 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1380 | } |
Adrian Knoth | 2e61027 | 2011-08-15 00:22:54 +0200 | [diff] [blame] | 1381 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1382 | s->control_register &= ~HDSPM_LatencyMask; |
| 1383 | s->control_register |= hdspm_encode_latency(n); |
| 1384 | |
| 1385 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1386 | |
| 1387 | hdspm_compute_period_size(s); |
| 1388 | |
| 1389 | spin_unlock_irq(&s->lock); |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1394 | static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period) |
| 1395 | { |
| 1396 | u64 freq_const; |
| 1397 | |
| 1398 | if (period == 0) |
| 1399 | return 0; |
| 1400 | |
| 1401 | switch (hdspm->io_type) { |
| 1402 | case MADI: |
| 1403 | case AES32: |
| 1404 | freq_const = 110069313433624ULL; |
| 1405 | break; |
| 1406 | case RayDAT: |
| 1407 | case AIO: |
| 1408 | freq_const = 104857600000000ULL; |
| 1409 | break; |
| 1410 | case MADIface: |
| 1411 | freq_const = 131072000000000ULL; |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1412 | break; |
| 1413 | default: |
| 1414 | snd_BUG(); |
| 1415 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | return div_u64(freq_const, period); |
| 1419 | } |
| 1420 | |
| 1421 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1422 | static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) |
| 1423 | { |
| 1424 | u64 n; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1425 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1426 | if (rate >= 112000) |
| 1427 | rate /= 4; |
| 1428 | else if (rate >= 56000) |
| 1429 | rate /= 2; |
| 1430 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1431 | switch (hdspm->io_type) { |
| 1432 | case MADIface: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1433 | n = 131072000000000ULL; /* 125 MHz */ |
| 1434 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1435 | case MADI: |
| 1436 | case AES32: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1437 | n = 110069313433624ULL; /* 105 MHz */ |
| 1438 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1439 | case RayDAT: |
| 1440 | case AIO: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1441 | n = 104857600000000ULL; /* 100 MHz */ |
| 1442 | break; |
| 1443 | default: |
| 1444 | snd_BUG(); |
| 1445 | return; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
Takashi Iwai | 3f7440a | 2009-06-05 17:40:04 +0200 | [diff] [blame] | 1448 | n = div_u64(n, rate); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1449 | /* n should be less than 2^32 for being written to FREQ register */ |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1450 | snd_BUG_ON(n >> 32); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1451 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); |
| 1452 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1453 | |
| 1454 | /* dummy set rate lets see what happens */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1455 | static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1456 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1457 | int current_rate; |
| 1458 | int rate_bits; |
| 1459 | int not_set = 0; |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1460 | int current_speed, target_speed; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1461 | |
| 1462 | /* ASSUMPTION: hdspm->lock is either set, or there is no need for |
| 1463 | it (e.g. during module initialization). |
| 1464 | */ |
| 1465 | |
| 1466 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) { |
| 1467 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1468 | /* SLAVE --- */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1469 | if (called_internally) { |
| 1470 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1471 | /* request from ctl or card initialization |
| 1472 | just make a warning an remember setting |
| 1473 | for future master mode switching */ |
| 1474 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1475 | snd_printk(KERN_WARNING "HDSPM: " |
| 1476 | "Warning: device is not running " |
| 1477 | "as a clock master.\n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1478 | not_set = 1; |
| 1479 | } else { |
| 1480 | |
| 1481 | /* hw_param request while in AutoSync mode */ |
| 1482 | int external_freq = |
| 1483 | hdspm_external_sample_rate(hdspm); |
| 1484 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1485 | if (hdspm_autosync_ref(hdspm) == |
| 1486 | HDSPM_AUTOSYNC_FROM_NONE) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1487 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1488 | snd_printk(KERN_WARNING "HDSPM: " |
| 1489 | "Detected no Externel Sync \n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1490 | not_set = 1; |
| 1491 | |
| 1492 | } else if (rate != external_freq) { |
| 1493 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1494 | snd_printk(KERN_WARNING "HDSPM: " |
| 1495 | "Warning: No AutoSync source for " |
| 1496 | "requested rate\n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1497 | not_set = 1; |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | current_rate = hdspm->system_sample_rate; |
| 1503 | |
| 1504 | /* Changing between Singe, Double and Quad speed is not |
| 1505 | allowed if any substreams are open. This is because such a change |
| 1506 | causes a shift in the location of the DMA buffers and a reduction |
| 1507 | in the number of available buffers. |
| 1508 | |
| 1509 | Note that a similar but essentially insoluble problem exists for |
| 1510 | externally-driven rate changes. All we can do is to flag rate |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1511 | changes in the read/write routines. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1512 | */ |
| 1513 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1514 | if (current_rate <= 48000) |
| 1515 | current_speed = HDSPM_SPEED_SINGLE; |
| 1516 | else if (current_rate <= 96000) |
| 1517 | current_speed = HDSPM_SPEED_DOUBLE; |
| 1518 | else |
| 1519 | current_speed = HDSPM_SPEED_QUAD; |
| 1520 | |
| 1521 | if (rate <= 48000) |
| 1522 | target_speed = HDSPM_SPEED_SINGLE; |
| 1523 | else if (rate <= 96000) |
| 1524 | target_speed = HDSPM_SPEED_DOUBLE; |
| 1525 | else |
| 1526 | target_speed = HDSPM_SPEED_QUAD; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1527 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1528 | switch (rate) { |
| 1529 | case 32000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1530 | rate_bits = HDSPM_Frequency32KHz; |
| 1531 | break; |
| 1532 | case 44100: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1533 | rate_bits = HDSPM_Frequency44_1KHz; |
| 1534 | break; |
| 1535 | case 48000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1536 | rate_bits = HDSPM_Frequency48KHz; |
| 1537 | break; |
| 1538 | case 64000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1539 | rate_bits = HDSPM_Frequency64KHz; |
| 1540 | break; |
| 1541 | case 88200: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1542 | rate_bits = HDSPM_Frequency88_2KHz; |
| 1543 | break; |
| 1544 | case 96000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1545 | rate_bits = HDSPM_Frequency96KHz; |
| 1546 | break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1547 | case 128000: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1548 | rate_bits = HDSPM_Frequency128KHz; |
| 1549 | break; |
| 1550 | case 176400: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1551 | rate_bits = HDSPM_Frequency176_4KHz; |
| 1552 | break; |
| 1553 | case 192000: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1554 | rate_bits = HDSPM_Frequency192KHz; |
| 1555 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1556 | default: |
| 1557 | return -EINVAL; |
| 1558 | } |
| 1559 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1560 | if (current_speed != target_speed |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1561 | && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { |
| 1562 | snd_printk |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1563 | (KERN_ERR "HDSPM: " |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1564 | "cannot change from %s speed to %s speed mode " |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1565 | "(capture PID = %d, playback PID = %d)\n", |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1566 | hdspm_speed_names[current_speed], |
| 1567 | hdspm_speed_names[target_speed], |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1568 | hdspm->capture_pid, hdspm->playback_pid); |
| 1569 | return -EBUSY; |
| 1570 | } |
| 1571 | |
| 1572 | hdspm->control_register &= ~HDSPM_FrequencyMask; |
| 1573 | hdspm->control_register |= rate_bits; |
| 1574 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 1575 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1576 | /* For AES32, need to set DDS value in FREQ register |
| 1577 | For MADI, also apparently */ |
| 1578 | hdspm_set_dds_value(hdspm, rate); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1579 | |
| 1580 | if (AES32 == hdspm->io_type && rate != current_rate) |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1581 | hdspm_write(hdspm, HDSPM_eeprom_wr, 0); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1582 | |
| 1583 | hdspm->system_sample_rate = rate; |
| 1584 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1585 | if (rate <= 48000) { |
| 1586 | hdspm->channel_map_in = hdspm->channel_map_in_ss; |
| 1587 | hdspm->channel_map_out = hdspm->channel_map_out_ss; |
| 1588 | hdspm->max_channels_in = hdspm->ss_in_channels; |
| 1589 | hdspm->max_channels_out = hdspm->ss_out_channels; |
| 1590 | hdspm->port_names_in = hdspm->port_names_in_ss; |
| 1591 | hdspm->port_names_out = hdspm->port_names_out_ss; |
| 1592 | } else if (rate <= 96000) { |
| 1593 | hdspm->channel_map_in = hdspm->channel_map_in_ds; |
| 1594 | hdspm->channel_map_out = hdspm->channel_map_out_ds; |
| 1595 | hdspm->max_channels_in = hdspm->ds_in_channels; |
| 1596 | hdspm->max_channels_out = hdspm->ds_out_channels; |
| 1597 | hdspm->port_names_in = hdspm->port_names_in_ds; |
| 1598 | hdspm->port_names_out = hdspm->port_names_out_ds; |
| 1599 | } else { |
| 1600 | hdspm->channel_map_in = hdspm->channel_map_in_qs; |
| 1601 | hdspm->channel_map_out = hdspm->channel_map_out_qs; |
| 1602 | hdspm->max_channels_in = hdspm->qs_in_channels; |
| 1603 | hdspm->max_channels_out = hdspm->qs_out_channels; |
| 1604 | hdspm->port_names_in = hdspm->port_names_in_qs; |
| 1605 | hdspm->port_names_out = hdspm->port_names_out_qs; |
| 1606 | } |
| 1607 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1608 | if (not_set != 0) |
| 1609 | return -1; |
| 1610 | |
| 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | /* mainly for init to 0 on load */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1615 | static void all_in_all_mixer(struct hdspm * hdspm, int sgain) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1616 | { |
| 1617 | int i, j; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1618 | unsigned int gain; |
| 1619 | |
| 1620 | if (sgain > UNITY_GAIN) |
| 1621 | gain = UNITY_GAIN; |
| 1622 | else if (sgain < 0) |
| 1623 | gain = 0; |
| 1624 | else |
| 1625 | gain = sgain; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1626 | |
| 1627 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) |
| 1628 | for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { |
| 1629 | hdspm_write_in_gain(hdspm, i, j, gain); |
| 1630 | hdspm_write_pb_gain(hdspm, i, j, gain); |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | /*---------------------------------------------------------------------------- |
| 1635 | MIDI |
| 1636 | ----------------------------------------------------------------------------*/ |
| 1637 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1638 | static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, |
| 1639 | int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1640 | { |
| 1641 | /* the hardware already does the relevant bit-mask with 0xff */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1642 | return hdspm_read(hdspm, hdspm->midi[id].dataIn); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1643 | } |
| 1644 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1645 | static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, |
| 1646 | int val) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1647 | { |
| 1648 | /* the hardware already does the relevant bit-mask with 0xff */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1649 | return hdspm_write(hdspm, hdspm->midi[id].dataOut, val); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1650 | } |
| 1651 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1652 | static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1653 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1654 | return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1655 | } |
| 1656 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1657 | static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1658 | { |
| 1659 | int fifo_bytes_used; |
| 1660 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1661 | fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1662 | |
| 1663 | if (fifo_bytes_used < 128) |
| 1664 | return 128 - fifo_bytes_used; |
| 1665 | else |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1669 | static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1670 | { |
| 1671 | while (snd_hdspm_midi_input_available (hdspm, id)) |
| 1672 | snd_hdspm_midi_read_byte (hdspm, id); |
| 1673 | } |
| 1674 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1675 | static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1676 | { |
| 1677 | unsigned long flags; |
| 1678 | int n_pending; |
| 1679 | int to_write; |
| 1680 | int i; |
| 1681 | unsigned char buf[128]; |
| 1682 | |
| 1683 | /* Output is not interrupt driven */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1684 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1685 | spin_lock_irqsave (&hmidi->lock, flags); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1686 | if (hmidi->output && |
| 1687 | !snd_rawmidi_transmit_empty (hmidi->output)) { |
| 1688 | n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, |
| 1689 | hmidi->id); |
| 1690 | if (n_pending > 0) { |
| 1691 | if (n_pending > (int)sizeof (buf)) |
| 1692 | n_pending = sizeof (buf); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1693 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1694 | to_write = snd_rawmidi_transmit (hmidi->output, buf, |
| 1695 | n_pending); |
| 1696 | if (to_write > 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1697 | for (i = 0; i < to_write; ++i) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1698 | snd_hdspm_midi_write_byte (hmidi->hdspm, |
| 1699 | hmidi->id, |
| 1700 | buf[i]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1708 | static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1709 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1710 | unsigned char buf[128]; /* this buffer is designed to match the MIDI |
| 1711 | * input FIFO size |
| 1712 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1713 | unsigned long flags; |
| 1714 | int n_pending; |
| 1715 | int i; |
| 1716 | |
| 1717 | spin_lock_irqsave (&hmidi->lock, flags); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1718 | n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); |
| 1719 | if (n_pending > 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1720 | if (hmidi->input) { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1721 | if (n_pending > (int)sizeof (buf)) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1722 | n_pending = sizeof (buf); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1723 | for (i = 0; i < n_pending; ++i) |
| 1724 | buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, |
| 1725 | hmidi->id); |
| 1726 | if (n_pending) |
| 1727 | snd_rawmidi_receive (hmidi->input, buf, |
| 1728 | n_pending); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1729 | } else { |
| 1730 | /* flush the MIDI input FIFO */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1731 | while (n_pending--) |
| 1732 | snd_hdspm_midi_read_byte (hmidi->hdspm, |
| 1733 | hmidi->id); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | hmidi->pending = 0; |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1737 | spin_unlock_irqrestore(&hmidi->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1738 | |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1739 | spin_lock_irqsave(&hmidi->hdspm->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1740 | hmidi->hdspm->control_register |= hmidi->ie; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1741 | hdspm_write(hmidi->hdspm, HDSPM_controlRegister, |
| 1742 | hmidi->hdspm->control_register); |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1743 | spin_unlock_irqrestore(&hmidi->hdspm->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1744 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1745 | return snd_hdspm_midi_output_write (hmidi); |
| 1746 | } |
| 1747 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1748 | static void |
| 1749 | snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1750 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1751 | struct hdspm *hdspm; |
| 1752 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1753 | unsigned long flags; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1754 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1755 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1756 | hdspm = hmidi->hdspm; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1757 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1758 | spin_lock_irqsave (&hdspm->lock, flags); |
| 1759 | if (up) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1760 | if (!(hdspm->control_register & hmidi->ie)) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1761 | snd_hdspm_flush_midi_input (hdspm, hmidi->id); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1762 | hdspm->control_register |= hmidi->ie; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1763 | } |
| 1764 | } else { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1765 | hdspm->control_register &= ~hmidi->ie; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 1769 | spin_unlock_irqrestore (&hdspm->lock, flags); |
| 1770 | } |
| 1771 | |
| 1772 | static void snd_hdspm_midi_output_timer(unsigned long data) |
| 1773 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1774 | struct hdspm_midi *hmidi = (struct hdspm_midi *) data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1775 | unsigned long flags; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1776 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1777 | snd_hdspm_midi_output_write(hmidi); |
| 1778 | spin_lock_irqsave (&hmidi->lock, flags); |
| 1779 | |
| 1780 | /* this does not bump hmidi->istimer, because the |
| 1781 | kernel automatically removed the timer when it |
| 1782 | expired, and we are now adding it back, thus |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1783 | leaving istimer wherever it was set before. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1784 | */ |
| 1785 | |
| 1786 | if (hmidi->istimer) { |
| 1787 | hmidi->timer.expires = 1 + jiffies; |
| 1788 | add_timer(&hmidi->timer); |
| 1789 | } |
| 1790 | |
| 1791 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1792 | } |
| 1793 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1794 | static void |
| 1795 | snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1796 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1797 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1798 | unsigned long flags; |
| 1799 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1800 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1801 | spin_lock_irqsave (&hmidi->lock, flags); |
| 1802 | if (up) { |
| 1803 | if (!hmidi->istimer) { |
| 1804 | init_timer(&hmidi->timer); |
| 1805 | hmidi->timer.function = snd_hdspm_midi_output_timer; |
| 1806 | hmidi->timer.data = (unsigned long) hmidi; |
| 1807 | hmidi->timer.expires = 1 + jiffies; |
| 1808 | add_timer(&hmidi->timer); |
| 1809 | hmidi->istimer++; |
| 1810 | } |
| 1811 | } else { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1812 | if (hmidi->istimer && --hmidi->istimer <= 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1813 | del_timer (&hmidi->timer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1814 | } |
| 1815 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1816 | if (up) |
| 1817 | snd_hdspm_midi_output_write(hmidi); |
| 1818 | } |
| 1819 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1820 | static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1821 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1822 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1823 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1824 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1825 | spin_lock_irq (&hmidi->lock); |
| 1826 | snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); |
| 1827 | hmidi->input = substream; |
| 1828 | spin_unlock_irq (&hmidi->lock); |
| 1829 | |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1833 | static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1834 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1835 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1836 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1837 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1838 | spin_lock_irq (&hmidi->lock); |
| 1839 | hmidi->output = substream; |
| 1840 | spin_unlock_irq (&hmidi->lock); |
| 1841 | |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1845 | static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1846 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1847 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1848 | |
| 1849 | snd_hdspm_midi_input_trigger (substream, 0); |
| 1850 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1851 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1852 | spin_lock_irq (&hmidi->lock); |
| 1853 | hmidi->input = NULL; |
| 1854 | spin_unlock_irq (&hmidi->lock); |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1859 | static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1860 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1861 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1862 | |
| 1863 | snd_hdspm_midi_output_trigger (substream, 0); |
| 1864 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1865 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1866 | spin_lock_irq (&hmidi->lock); |
| 1867 | hmidi->output = NULL; |
| 1868 | spin_unlock_irq (&hmidi->lock); |
| 1869 | |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1873 | static struct snd_rawmidi_ops snd_hdspm_midi_output = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1874 | { |
| 1875 | .open = snd_hdspm_midi_output_open, |
| 1876 | .close = snd_hdspm_midi_output_close, |
| 1877 | .trigger = snd_hdspm_midi_output_trigger, |
| 1878 | }; |
| 1879 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1880 | static struct snd_rawmidi_ops snd_hdspm_midi_input = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1881 | { |
| 1882 | .open = snd_hdspm_midi_input_open, |
| 1883 | .close = snd_hdspm_midi_input_close, |
| 1884 | .trigger = snd_hdspm_midi_input_trigger, |
| 1885 | }; |
| 1886 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1887 | static int snd_hdspm_create_midi(struct snd_card *card, |
| 1888 | struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1889 | { |
| 1890 | int err; |
| 1891 | char buf[32]; |
| 1892 | |
| 1893 | hdspm->midi[id].id = id; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1894 | hdspm->midi[id].hdspm = hdspm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1895 | spin_lock_init (&hdspm->midi[id].lock); |
| 1896 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1897 | if (0 == id) { |
| 1898 | if (MADIface == hdspm->io_type) { |
| 1899 | /* MIDI-over-MADI on HDSPe MADIface */ |
| 1900 | hdspm->midi[0].dataIn = HDSPM_midiDataIn2; |
| 1901 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn2; |
| 1902 | hdspm->midi[0].dataOut = HDSPM_midiDataOut2; |
| 1903 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut2; |
| 1904 | hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable; |
| 1905 | hdspm->midi[0].irq = HDSPM_midi2IRQPending; |
| 1906 | } else { |
| 1907 | hdspm->midi[0].dataIn = HDSPM_midiDataIn0; |
| 1908 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn0; |
| 1909 | hdspm->midi[0].dataOut = HDSPM_midiDataOut0; |
| 1910 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut0; |
| 1911 | hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable; |
| 1912 | hdspm->midi[0].irq = HDSPM_midi0IRQPending; |
| 1913 | } |
| 1914 | } else if (1 == id) { |
| 1915 | hdspm->midi[1].dataIn = HDSPM_midiDataIn1; |
| 1916 | hdspm->midi[1].statusIn = HDSPM_midiStatusIn1; |
| 1917 | hdspm->midi[1].dataOut = HDSPM_midiDataOut1; |
| 1918 | hdspm->midi[1].statusOut = HDSPM_midiStatusOut1; |
| 1919 | hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable; |
| 1920 | hdspm->midi[1].irq = HDSPM_midi1IRQPending; |
| 1921 | } else if ((2 == id) && (MADI == hdspm->io_type)) { |
| 1922 | /* MIDI-over-MADI on HDSPe MADI */ |
| 1923 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; |
| 1924 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; |
| 1925 | hdspm->midi[2].dataOut = HDSPM_midiDataOut2; |
| 1926 | hdspm->midi[2].statusOut = HDSPM_midiStatusOut2; |
| 1927 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; |
| 1928 | hdspm->midi[2].irq = HDSPM_midi2IRQPending; |
| 1929 | } else if (2 == id) { |
| 1930 | /* TCO MTC, read only */ |
| 1931 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; |
| 1932 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; |
| 1933 | hdspm->midi[2].dataOut = -1; |
| 1934 | hdspm->midi[2].statusOut = -1; |
| 1935 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; |
| 1936 | hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES; |
| 1937 | } else if (3 == id) { |
| 1938 | /* TCO MTC on HDSPe MADI */ |
| 1939 | hdspm->midi[3].dataIn = HDSPM_midiDataIn3; |
| 1940 | hdspm->midi[3].statusIn = HDSPM_midiStatusIn3; |
| 1941 | hdspm->midi[3].dataOut = -1; |
| 1942 | hdspm->midi[3].statusOut = -1; |
| 1943 | hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable; |
| 1944 | hdspm->midi[3].irq = HDSPM_midi3IRQPending; |
| 1945 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1946 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1947 | if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) || |
| 1948 | (MADIface == hdspm->io_type)))) { |
| 1949 | if ((id == 0) && (MADIface == hdspm->io_type)) { |
| 1950 | sprintf(buf, "%s MIDIoverMADI", card->shortname); |
| 1951 | } else if ((id == 2) && (MADI == hdspm->io_type)) { |
| 1952 | sprintf(buf, "%s MIDIoverMADI", card->shortname); |
| 1953 | } else { |
| 1954 | sprintf(buf, "%s MIDI %d", card->shortname, id+1); |
| 1955 | } |
| 1956 | err = snd_rawmidi_new(card, buf, id, 1, 1, |
| 1957 | &hdspm->midi[id].rmidi); |
| 1958 | if (err < 0) |
| 1959 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1960 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1961 | sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d", |
| 1962 | card->id, id+1); |
| 1963 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1964 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1965 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1966 | SNDRV_RAWMIDI_STREAM_OUTPUT, |
| 1967 | &snd_hdspm_midi_output); |
| 1968 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1969 | SNDRV_RAWMIDI_STREAM_INPUT, |
| 1970 | &snd_hdspm_midi_input); |
| 1971 | |
| 1972 | hdspm->midi[id].rmidi->info_flags |= |
| 1973 | SNDRV_RAWMIDI_INFO_OUTPUT | |
| 1974 | SNDRV_RAWMIDI_INFO_INPUT | |
| 1975 | SNDRV_RAWMIDI_INFO_DUPLEX; |
| 1976 | } else { |
| 1977 | /* TCO MTC, read only */ |
| 1978 | sprintf(buf, "%s MTC %d", card->shortname, id+1); |
| 1979 | err = snd_rawmidi_new(card, buf, id, 1, 1, |
| 1980 | &hdspm->midi[id].rmidi); |
| 1981 | if (err < 0) |
| 1982 | return err; |
| 1983 | |
| 1984 | sprintf(hdspm->midi[id].rmidi->name, |
| 1985 | "%s MTC %d", card->id, id+1); |
| 1986 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; |
| 1987 | |
| 1988 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1989 | SNDRV_RAWMIDI_STREAM_INPUT, |
| 1990 | &snd_hdspm_midi_input); |
| 1991 | |
| 1992 | hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; |
| 1993 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | static void hdspm_midi_tasklet(unsigned long arg) |
| 2000 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2001 | struct hdspm *hdspm = (struct hdspm *)arg; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2002 | int i = 0; |
| 2003 | |
| 2004 | while (i < hdspm->midiPorts) { |
| 2005 | if (hdspm->midi[i].pending) |
| 2006 | snd_hdspm_midi_input_read(&hdspm->midi[i]); |
| 2007 | |
| 2008 | i++; |
| 2009 | } |
| 2010 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2011 | |
| 2012 | |
| 2013 | /*----------------------------------------------------------------------------- |
| 2014 | Status Interface |
| 2015 | ----------------------------------------------------------------------------*/ |
| 2016 | |
| 2017 | /* get the system sample rate which is set */ |
| 2018 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2019 | |
Adrian Knoth | 3f7bf91 | 2013-03-10 00:37:21 +0100 | [diff] [blame] | 2020 | static inline int hdspm_get_pll_freq(struct hdspm *hdspm) |
| 2021 | { |
| 2022 | unsigned int period, rate; |
| 2023 | |
| 2024 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 2025 | rate = hdspm_calc_dds_value(hdspm, period); |
| 2026 | |
| 2027 | return rate; |
| 2028 | } |
| 2029 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2030 | /** |
| 2031 | * Calculate the real sample rate from the |
| 2032 | * current DDS value. |
| 2033 | **/ |
| 2034 | static int hdspm_get_system_sample_rate(struct hdspm *hdspm) |
| 2035 | { |
Adrian Knoth | 3f7bf91 | 2013-03-10 00:37:21 +0100 | [diff] [blame] | 2036 | unsigned int rate; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2037 | |
Adrian Knoth | 3f7bf91 | 2013-03-10 00:37:21 +0100 | [diff] [blame] | 2038 | rate = hdspm_get_pll_freq(hdspm); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2039 | |
Adrian Knoth | a97bda7 | 2012-05-30 14:23:18 +0200 | [diff] [blame] | 2040 | if (rate > 207000) { |
Adrian Knoth | 21a164d | 2012-10-19 17:42:23 +0200 | [diff] [blame] | 2041 | /* Unreasonable high sample rate as seen on PCI MADI cards. */ |
| 2042 | if (0 == hdspm_system_clock_mode(hdspm)) { |
| 2043 | /* master mode, return internal sample rate */ |
| 2044 | rate = hdspm->system_sample_rate; |
| 2045 | } else { |
| 2046 | /* slave mode, return external sample rate */ |
| 2047 | rate = hdspm_external_sample_rate(hdspm); |
| 2048 | } |
Adrian Knoth | a97bda7 | 2012-05-30 14:23:18 +0200 | [diff] [blame] | 2049 | } |
| 2050 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2051 | return rate; |
| 2052 | } |
| 2053 | |
| 2054 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2055 | #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 2056 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2057 | .name = xname, \ |
| 2058 | .index = xindex, \ |
| 2059 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 2060 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2061 | .info = snd_hdspm_info_system_sample_rate, \ |
| 2062 | .put = snd_hdspm_put_system_sample_rate, \ |
| 2063 | .get = snd_hdspm_get_system_sample_rate \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2064 | } |
| 2065 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2066 | static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol, |
| 2067 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2068 | { |
| 2069 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2070 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2071 | uinfo->value.integer.min = 27000; |
| 2072 | uinfo->value.integer.max = 207000; |
| 2073 | uinfo->value.integer.step = 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2074 | return 0; |
| 2075 | } |
| 2076 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2077 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2078 | static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol, |
| 2079 | struct snd_ctl_elem_value * |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2080 | ucontrol) |
| 2081 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2082 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2083 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2084 | ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2085 | return 0; |
| 2086 | } |
| 2087 | |
Adrian Knoth | 41285a9 | 2012-10-19 17:42:22 +0200 | [diff] [blame] | 2088 | static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol, |
| 2089 | struct snd_ctl_elem_value * |
| 2090 | ucontrol) |
| 2091 | { |
| 2092 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 2093 | |
| 2094 | hdspm_set_dds_value(hdspm, ucontrol->value.enumerated.item[0]); |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2098 | |
| 2099 | /** |
| 2100 | * Returns the WordClock sample rate class for the given card. |
| 2101 | **/ |
| 2102 | static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) |
| 2103 | { |
| 2104 | int status; |
| 2105 | |
| 2106 | switch (hdspm->io_type) { |
| 2107 | case RayDAT: |
| 2108 | case AIO: |
| 2109 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 2110 | return (status >> 16) & 0xF; |
| 2111 | break; |
| 2112 | default: |
| 2113 | break; |
| 2114 | } |
| 2115 | |
| 2116 | |
| 2117 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2118 | } |
| 2119 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2120 | |
| 2121 | /** |
| 2122 | * Returns the TCO sample rate class for the given card. |
| 2123 | **/ |
| 2124 | static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) |
| 2125 | { |
| 2126 | int status; |
| 2127 | |
| 2128 | if (hdspm->tco) { |
| 2129 | switch (hdspm->io_type) { |
| 2130 | case RayDAT: |
| 2131 | case AIO: |
| 2132 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 2133 | return (status >> 20) & 0xF; |
| 2134 | break; |
| 2135 | default: |
| 2136 | break; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | return 0; |
| 2141 | } |
| 2142 | |
| 2143 | |
| 2144 | /** |
| 2145 | * Returns the SYNC_IN sample rate class for the given card. |
| 2146 | **/ |
| 2147 | static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) |
| 2148 | { |
| 2149 | int status; |
| 2150 | |
| 2151 | if (hdspm->tco) { |
| 2152 | switch (hdspm->io_type) { |
| 2153 | case RayDAT: |
| 2154 | case AIO: |
| 2155 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); |
| 2156 | return (status >> 12) & 0xF; |
| 2157 | break; |
| 2158 | default: |
| 2159 | break; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | /** |
| 2168 | * Returns the sample rate class for input source <idx> for |
| 2169 | * 'new style' cards like the AIO and RayDAT. |
| 2170 | **/ |
| 2171 | static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) |
| 2172 | { |
| 2173 | int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); |
| 2174 | |
| 2175 | return (status >> (idx*4)) & 0xF; |
| 2176 | } |
| 2177 | |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 2178 | #define ENUMERATED_CTL_INFO(info, texts) \ |
| 2179 | { \ |
| 2180 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; \ |
| 2181 | uinfo->count = 1; \ |
| 2182 | uinfo->value.enumerated.items = ARRAY_SIZE(texts); \ |
| 2183 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) \ |
| 2184 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; \ |
| 2185 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); \ |
| 2186 | } |
| 2187 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2188 | |
| 2189 | |
| 2190 | #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ |
| 2191 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2192 | .name = xname, \ |
| 2193 | .private_value = xindex, \ |
| 2194 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ |
| 2195 | .info = snd_hdspm_info_autosync_sample_rate, \ |
| 2196 | .get = snd_hdspm_get_autosync_sample_rate \ |
| 2197 | } |
| 2198 | |
| 2199 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2200 | static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
| 2201 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2202 | { |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 2203 | ENUMERATED_CTL_INFO(uinfo, texts_freq); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2204 | return 0; |
| 2205 | } |
| 2206 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2207 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2208 | static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
| 2209 | struct snd_ctl_elem_value * |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2210 | ucontrol) |
| 2211 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2212 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2213 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2214 | switch (hdspm->io_type) { |
| 2215 | case RayDAT: |
| 2216 | switch (kcontrol->private_value) { |
| 2217 | case 0: |
| 2218 | ucontrol->value.enumerated.item[0] = |
| 2219 | hdspm_get_wc_sample_rate(hdspm); |
| 2220 | break; |
| 2221 | case 7: |
| 2222 | ucontrol->value.enumerated.item[0] = |
| 2223 | hdspm_get_tco_sample_rate(hdspm); |
| 2224 | break; |
| 2225 | case 8: |
| 2226 | ucontrol->value.enumerated.item[0] = |
| 2227 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2228 | break; |
| 2229 | default: |
| 2230 | ucontrol->value.enumerated.item[0] = |
| 2231 | hdspm_get_s1_sample_rate(hdspm, |
| 2232 | kcontrol->private_value-1); |
| 2233 | } |
Adrian Knoth | d681dea | 2012-10-19 17:42:25 +0200 | [diff] [blame] | 2234 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2235 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2236 | case AIO: |
| 2237 | switch (kcontrol->private_value) { |
| 2238 | case 0: /* WC */ |
| 2239 | ucontrol->value.enumerated.item[0] = |
| 2240 | hdspm_get_wc_sample_rate(hdspm); |
| 2241 | break; |
| 2242 | case 4: /* TCO */ |
| 2243 | ucontrol->value.enumerated.item[0] = |
| 2244 | hdspm_get_tco_sample_rate(hdspm); |
| 2245 | break; |
| 2246 | case 5: /* SYNC_IN */ |
| 2247 | ucontrol->value.enumerated.item[0] = |
| 2248 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2249 | break; |
| 2250 | default: |
| 2251 | ucontrol->value.enumerated.item[0] = |
| 2252 | hdspm_get_s1_sample_rate(hdspm, |
| 2253 | ucontrol->id.index-1); |
| 2254 | } |
Adrian Knoth | d681dea | 2012-10-19 17:42:25 +0200 | [diff] [blame] | 2255 | break; |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 2256 | |
| 2257 | case AES32: |
| 2258 | |
| 2259 | switch (kcontrol->private_value) { |
| 2260 | case 0: /* WC */ |
| 2261 | ucontrol->value.enumerated.item[0] = |
| 2262 | hdspm_get_wc_sample_rate(hdspm); |
| 2263 | break; |
| 2264 | case 9: /* TCO */ |
| 2265 | ucontrol->value.enumerated.item[0] = |
| 2266 | hdspm_get_tco_sample_rate(hdspm); |
| 2267 | break; |
| 2268 | case 10: /* SYNC_IN */ |
| 2269 | ucontrol->value.enumerated.item[0] = |
| 2270 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2271 | break; |
| 2272 | default: /* AES1 to AES8 */ |
| 2273 | ucontrol->value.enumerated.item[0] = |
| 2274 | hdspm_get_s1_sample_rate(hdspm, |
| 2275 | kcontrol->private_value-1); |
| 2276 | break; |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 2277 | } |
Adrian Knoth | d681dea | 2012-10-19 17:42:25 +0200 | [diff] [blame] | 2278 | break; |
Adrian Knoth | b8812c5 | 2012-10-19 17:42:26 +0200 | [diff] [blame] | 2279 | |
| 2280 | case MADI: |
| 2281 | case MADIface: |
| 2282 | { |
| 2283 | int rate = hdspm_external_sample_rate(hdspm); |
| 2284 | int i, selected_rate = 0; |
| 2285 | for (i = 1; i < 10; i++) |
| 2286 | if (HDSPM_bit2freq(i) == rate) { |
| 2287 | selected_rate = i; |
| 2288 | break; |
| 2289 | } |
| 2290 | ucontrol->value.enumerated.item[0] = selected_rate; |
| 2291 | } |
| 2292 | break; |
| 2293 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2294 | default: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2295 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2296 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2297 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2298 | return 0; |
| 2299 | } |
| 2300 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2301 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2302 | #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2303 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2304 | .name = xname, \ |
| 2305 | .index = xindex, \ |
| 2306 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 2307 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2308 | .info = snd_hdspm_info_system_clock_mode, \ |
| 2309 | .get = snd_hdspm_get_system_clock_mode, \ |
| 2310 | .put = snd_hdspm_put_system_clock_mode, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2314 | /** |
| 2315 | * Returns the system clock mode for the given card. |
| 2316 | * @returns 0 - master, 1 - slave |
| 2317 | **/ |
| 2318 | static int hdspm_system_clock_mode(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2319 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2320 | switch (hdspm->io_type) { |
| 2321 | case AIO: |
| 2322 | case RayDAT: |
| 2323 | if (hdspm->settings_register & HDSPM_c0Master) |
| 2324 | return 0; |
| 2325 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2326 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2327 | default: |
| 2328 | if (hdspm->control_register & HDSPM_ClockModeMaster) |
| 2329 | return 0; |
| 2330 | } |
| 2331 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2332 | return 1; |
| 2333 | } |
| 2334 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2335 | |
| 2336 | /** |
| 2337 | * Sets the system clock mode. |
| 2338 | * @param mode 0 - master, 1 - slave |
| 2339 | **/ |
| 2340 | static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode) |
| 2341 | { |
| 2342 | switch (hdspm->io_type) { |
| 2343 | case AIO: |
| 2344 | case RayDAT: |
| 2345 | if (0 == mode) |
| 2346 | hdspm->settings_register |= HDSPM_c0Master; |
| 2347 | else |
| 2348 | hdspm->settings_register &= ~HDSPM_c0Master; |
| 2349 | |
| 2350 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
| 2351 | break; |
| 2352 | |
| 2353 | default: |
| 2354 | if (0 == mode) |
| 2355 | hdspm->control_register |= HDSPM_ClockModeMaster; |
| 2356 | else |
| 2357 | hdspm->control_register &= ~HDSPM_ClockModeMaster; |
| 2358 | |
| 2359 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 2360 | hdspm->control_register); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2365 | static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2366 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2367 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2368 | static char *texts[] = { "Master", "AutoSync" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 2369 | ENUMERATED_CTL_INFO(uinfo, texts); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2370 | return 0; |
| 2371 | } |
| 2372 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2373 | static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2374 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2375 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2376 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2377 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2378 | ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2379 | return 0; |
| 2380 | } |
| 2381 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2382 | static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2383 | struct snd_ctl_elem_value *ucontrol) |
| 2384 | { |
| 2385 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 2386 | int val; |
| 2387 | |
| 2388 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2389 | return -EBUSY; |
| 2390 | |
| 2391 | val = ucontrol->value.enumerated.item[0]; |
| 2392 | if (val < 0) |
| 2393 | val = 0; |
| 2394 | else if (val > 1) |
| 2395 | val = 1; |
| 2396 | |
| 2397 | hdspm_set_system_clock_mode(hdspm, val); |
| 2398 | |
| 2399 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2402 | |
| 2403 | #define HDSPM_INTERNAL_CLOCK(xname, xindex) \ |
| 2404 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2405 | .name = xname, \ |
| 2406 | .index = xindex, \ |
| 2407 | .info = snd_hdspm_info_clock_source, \ |
| 2408 | .get = snd_hdspm_get_clock_source, \ |
| 2409 | .put = snd_hdspm_put_clock_source \ |
| 2410 | } |
| 2411 | |
| 2412 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2413 | static int hdspm_clock_source(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2414 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2415 | switch (hdspm->system_sample_rate) { |
| 2416 | case 32000: return 0; |
| 2417 | case 44100: return 1; |
| 2418 | case 48000: return 2; |
| 2419 | case 64000: return 3; |
| 2420 | case 88200: return 4; |
| 2421 | case 96000: return 5; |
| 2422 | case 128000: return 6; |
| 2423 | case 176400: return 7; |
| 2424 | case 192000: return 8; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2425 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2426 | |
| 2427 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2430 | static int hdspm_set_clock_source(struct hdspm * hdspm, int mode) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2431 | { |
| 2432 | int rate; |
| 2433 | switch (mode) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2434 | case 0: |
| 2435 | rate = 32000; break; |
| 2436 | case 1: |
| 2437 | rate = 44100; break; |
| 2438 | case 2: |
| 2439 | rate = 48000; break; |
| 2440 | case 3: |
| 2441 | rate = 64000; break; |
| 2442 | case 4: |
| 2443 | rate = 88200; break; |
| 2444 | case 5: |
| 2445 | rate = 96000; break; |
| 2446 | case 6: |
| 2447 | rate = 128000; break; |
| 2448 | case 7: |
| 2449 | rate = 176400; break; |
| 2450 | case 8: |
| 2451 | rate = 192000; break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2452 | default: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2453 | rate = 48000; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2454 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2455 | hdspm_set_rate(hdspm, rate, 1); |
| 2456 | return 0; |
| 2457 | } |
| 2458 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2459 | static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol, |
| 2460 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2461 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2462 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2463 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2464 | uinfo->value.enumerated.items = 9; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2465 | |
| 2466 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2467 | uinfo->value.enumerated.item = |
| 2468 | uinfo->value.enumerated.items - 1; |
| 2469 | |
| 2470 | strcpy(uinfo->value.enumerated.name, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2471 | texts_freq[uinfo->value.enumerated.item+1]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2472 | |
| 2473 | return 0; |
| 2474 | } |
| 2475 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2476 | static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol, |
| 2477 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2478 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2479 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2480 | |
| 2481 | ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm); |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2485 | static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, |
| 2486 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2487 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2488 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2489 | int change; |
| 2490 | int val; |
| 2491 | |
| 2492 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2493 | return -EBUSY; |
| 2494 | val = ucontrol->value.enumerated.item[0]; |
| 2495 | if (val < 0) |
| 2496 | val = 0; |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 2497 | if (val > 9) |
| 2498 | val = 9; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2499 | spin_lock_irq(&hdspm->lock); |
| 2500 | if (val != hdspm_clock_source(hdspm)) |
| 2501 | change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; |
| 2502 | else |
| 2503 | change = 0; |
| 2504 | spin_unlock_irq(&hdspm->lock); |
| 2505 | return change; |
| 2506 | } |
| 2507 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2508 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2509 | #define HDSPM_PREF_SYNC_REF(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 2510 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2511 | .name = xname, \ |
| 2512 | .index = xindex, \ |
| 2513 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 2514 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2515 | .info = snd_hdspm_info_pref_sync_ref, \ |
| 2516 | .get = snd_hdspm_get_pref_sync_ref, \ |
| 2517 | .put = snd_hdspm_put_pref_sync_ref \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2518 | } |
| 2519 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2520 | |
| 2521 | /** |
| 2522 | * Returns the current preferred sync reference setting. |
| 2523 | * The semantics of the return value are depending on the |
| 2524 | * card, please see the comments for clarification. |
| 2525 | **/ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2526 | static int hdspm_pref_sync_ref(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2527 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2528 | switch (hdspm->io_type) { |
| 2529 | case AES32: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2530 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2531 | case 0: return 0; /* WC */ |
| 2532 | case HDSPM_SyncRef0: return 1; /* AES 1 */ |
| 2533 | case HDSPM_SyncRef1: return 2; /* AES 2 */ |
| 2534 | case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */ |
| 2535 | case HDSPM_SyncRef2: return 4; /* AES 4 */ |
| 2536 | case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */ |
| 2537 | case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */ |
| 2538 | case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2539 | return 7; /* AES 7 */ |
| 2540 | case HDSPM_SyncRef3: return 8; /* AES 8 */ |
| 2541 | case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2542 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2543 | break; |
| 2544 | |
| 2545 | case MADI: |
| 2546 | case MADIface: |
| 2547 | if (hdspm->tco) { |
| 2548 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
| 2549 | case 0: return 0; /* WC */ |
| 2550 | case HDSPM_SyncRef0: return 1; /* MADI */ |
| 2551 | case HDSPM_SyncRef1: return 2; /* TCO */ |
| 2552 | case HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2553 | return 3; /* SYNC_IN */ |
| 2554 | } |
| 2555 | } else { |
| 2556 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
| 2557 | case 0: return 0; /* WC */ |
| 2558 | case HDSPM_SyncRef0: return 1; /* MADI */ |
| 2559 | case HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2560 | return 2; /* SYNC_IN */ |
| 2561 | } |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2562 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2563 | break; |
| 2564 | |
| 2565 | case RayDAT: |
| 2566 | if (hdspm->tco) { |
| 2567 | switch ((hdspm->settings_register & |
| 2568 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2569 | case 0: return 0; /* WC */ |
| 2570 | case 3: return 1; /* ADAT 1 */ |
| 2571 | case 4: return 2; /* ADAT 2 */ |
| 2572 | case 5: return 3; /* ADAT 3 */ |
| 2573 | case 6: return 4; /* ADAT 4 */ |
| 2574 | case 1: return 5; /* AES */ |
| 2575 | case 2: return 6; /* SPDIF */ |
| 2576 | case 9: return 7; /* TCO */ |
| 2577 | case 10: return 8; /* SYNC_IN */ |
| 2578 | } |
| 2579 | } else { |
| 2580 | switch ((hdspm->settings_register & |
| 2581 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2582 | case 0: return 0; /* WC */ |
| 2583 | case 3: return 1; /* ADAT 1 */ |
| 2584 | case 4: return 2; /* ADAT 2 */ |
| 2585 | case 5: return 3; /* ADAT 3 */ |
| 2586 | case 6: return 4; /* ADAT 4 */ |
| 2587 | case 1: return 5; /* AES */ |
| 2588 | case 2: return 6; /* SPDIF */ |
| 2589 | case 10: return 7; /* SYNC_IN */ |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | break; |
| 2594 | |
| 2595 | case AIO: |
| 2596 | if (hdspm->tco) { |
| 2597 | switch ((hdspm->settings_register & |
| 2598 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2599 | case 0: return 0; /* WC */ |
| 2600 | case 3: return 1; /* ADAT */ |
| 2601 | case 1: return 2; /* AES */ |
| 2602 | case 2: return 3; /* SPDIF */ |
| 2603 | case 9: return 4; /* TCO */ |
| 2604 | case 10: return 5; /* SYNC_IN */ |
| 2605 | } |
| 2606 | } else { |
| 2607 | switch ((hdspm->settings_register & |
| 2608 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2609 | case 0: return 0; /* WC */ |
| 2610 | case 3: return 1; /* ADAT */ |
| 2611 | case 1: return 2; /* AES */ |
| 2612 | case 2: return 3; /* SPDIF */ |
| 2613 | case 10: return 4; /* SYNC_IN */ |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2618 | } |
| 2619 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2620 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2621 | } |
| 2622 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2623 | |
| 2624 | /** |
| 2625 | * Set the preferred sync reference to <pref>. The semantics |
| 2626 | * of <pref> are depending on the card type, see the comments |
| 2627 | * for clarification. |
| 2628 | **/ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2629 | static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2630 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2631 | int p = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2632 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2633 | switch (hdspm->io_type) { |
| 2634 | case AES32: |
| 2635 | hdspm->control_register &= ~HDSPM_SyncRefMask; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2636 | switch (pref) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2637 | case 0: /* WC */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2638 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2639 | case 1: /* AES 1 */ |
| 2640 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2641 | break; |
| 2642 | case 2: /* AES 2 */ |
| 2643 | hdspm->control_register |= HDSPM_SyncRef1; |
| 2644 | break; |
| 2645 | case 3: /* AES 3 */ |
| 2646 | hdspm->control_register |= |
| 2647 | HDSPM_SyncRef1+HDSPM_SyncRef0; |
| 2648 | break; |
| 2649 | case 4: /* AES 4 */ |
| 2650 | hdspm->control_register |= HDSPM_SyncRef2; |
| 2651 | break; |
| 2652 | case 5: /* AES 5 */ |
| 2653 | hdspm->control_register |= |
| 2654 | HDSPM_SyncRef2+HDSPM_SyncRef0; |
| 2655 | break; |
| 2656 | case 6: /* AES 6 */ |
| 2657 | hdspm->control_register |= |
| 2658 | HDSPM_SyncRef2+HDSPM_SyncRef1; |
| 2659 | break; |
| 2660 | case 7: /* AES 7 */ |
| 2661 | hdspm->control_register |= |
| 2662 | HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; |
| 2663 | break; |
| 2664 | case 8: /* AES 8 */ |
| 2665 | hdspm->control_register |= HDSPM_SyncRef3; |
| 2666 | break; |
| 2667 | case 9: /* TCO */ |
| 2668 | hdspm->control_register |= |
| 2669 | HDSPM_SyncRef3+HDSPM_SyncRef0; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2670 | break; |
| 2671 | default: |
| 2672 | return -1; |
| 2673 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2674 | |
| 2675 | break; |
| 2676 | |
| 2677 | case MADI: |
| 2678 | case MADIface: |
| 2679 | hdspm->control_register &= ~HDSPM_SyncRefMask; |
| 2680 | if (hdspm->tco) { |
| 2681 | switch (pref) { |
| 2682 | case 0: /* WC */ |
| 2683 | break; |
| 2684 | case 1: /* MADI */ |
| 2685 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2686 | break; |
| 2687 | case 2: /* TCO */ |
| 2688 | hdspm->control_register |= HDSPM_SyncRef1; |
| 2689 | break; |
| 2690 | case 3: /* SYNC_IN */ |
| 2691 | hdspm->control_register |= |
| 2692 | HDSPM_SyncRef0+HDSPM_SyncRef1; |
| 2693 | break; |
| 2694 | default: |
| 2695 | return -1; |
| 2696 | } |
| 2697 | } else { |
| 2698 | switch (pref) { |
| 2699 | case 0: /* WC */ |
| 2700 | break; |
| 2701 | case 1: /* MADI */ |
| 2702 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2703 | break; |
| 2704 | case 2: /* SYNC_IN */ |
| 2705 | hdspm->control_register |= |
| 2706 | HDSPM_SyncRef0+HDSPM_SyncRef1; |
| 2707 | break; |
| 2708 | default: |
| 2709 | return -1; |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | break; |
| 2714 | |
| 2715 | case RayDAT: |
| 2716 | if (hdspm->tco) { |
| 2717 | switch (pref) { |
| 2718 | case 0: p = 0; break; /* WC */ |
| 2719 | case 1: p = 3; break; /* ADAT 1 */ |
| 2720 | case 2: p = 4; break; /* ADAT 2 */ |
| 2721 | case 3: p = 5; break; /* ADAT 3 */ |
| 2722 | case 4: p = 6; break; /* ADAT 4 */ |
| 2723 | case 5: p = 1; break; /* AES */ |
| 2724 | case 6: p = 2; break; /* SPDIF */ |
| 2725 | case 7: p = 9; break; /* TCO */ |
| 2726 | case 8: p = 10; break; /* SYNC_IN */ |
| 2727 | default: return -1; |
| 2728 | } |
| 2729 | } else { |
| 2730 | switch (pref) { |
| 2731 | case 0: p = 0; break; /* WC */ |
| 2732 | case 1: p = 3; break; /* ADAT 1 */ |
| 2733 | case 2: p = 4; break; /* ADAT 2 */ |
| 2734 | case 3: p = 5; break; /* ADAT 3 */ |
| 2735 | case 4: p = 6; break; /* ADAT 4 */ |
| 2736 | case 5: p = 1; break; /* AES */ |
| 2737 | case 6: p = 2; break; /* SPDIF */ |
| 2738 | case 7: p = 10; break; /* SYNC_IN */ |
| 2739 | default: return -1; |
| 2740 | } |
| 2741 | } |
| 2742 | break; |
| 2743 | |
| 2744 | case AIO: |
| 2745 | if (hdspm->tco) { |
| 2746 | switch (pref) { |
| 2747 | case 0: p = 0; break; /* WC */ |
| 2748 | case 1: p = 3; break; /* ADAT */ |
| 2749 | case 2: p = 1; break; /* AES */ |
| 2750 | case 3: p = 2; break; /* SPDIF */ |
| 2751 | case 4: p = 9; break; /* TCO */ |
| 2752 | case 5: p = 10; break; /* SYNC_IN */ |
| 2753 | default: return -1; |
| 2754 | } |
| 2755 | } else { |
| 2756 | switch (pref) { |
| 2757 | case 0: p = 0; break; /* WC */ |
| 2758 | case 1: p = 3; break; /* ADAT */ |
| 2759 | case 2: p = 1; break; /* AES */ |
| 2760 | case 3: p = 2; break; /* SPDIF */ |
| 2761 | case 4: p = 10; break; /* SYNC_IN */ |
| 2762 | default: return -1; |
| 2763 | } |
| 2764 | } |
| 2765 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2766 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2767 | |
| 2768 | switch (hdspm->io_type) { |
| 2769 | case RayDAT: |
| 2770 | case AIO: |
| 2771 | hdspm->settings_register &= ~HDSPM_c0_SyncRefMask; |
| 2772 | hdspm->settings_register |= HDSPM_c0_SyncRef0 * p; |
| 2773 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
| 2774 | break; |
| 2775 | |
| 2776 | case MADI: |
| 2777 | case MADIface: |
| 2778 | case AES32: |
| 2779 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 2780 | hdspm->control_register); |
| 2781 | } |
| 2782 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2783 | return 0; |
| 2784 | } |
| 2785 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2786 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2787 | static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2788 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2789 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2790 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2791 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2792 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2793 | uinfo->count = 1; |
| 2794 | uinfo->value.enumerated.items = hdspm->texts_autosync_items; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2795 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2796 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2797 | uinfo->value.enumerated.item = |
| 2798 | uinfo->value.enumerated.items - 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2799 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2800 | strcpy(uinfo->value.enumerated.name, |
| 2801 | hdspm->texts_autosync[uinfo->value.enumerated.item]); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2802 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2803 | return 0; |
| 2804 | } |
| 2805 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2806 | static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2807 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2808 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2809 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2810 | int psf = hdspm_pref_sync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2811 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2812 | if (psf >= 0) { |
| 2813 | ucontrol->value.enumerated.item[0] = psf; |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
| 2817 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2818 | } |
| 2819 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2820 | static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2821 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2822 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2823 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2824 | int val, change = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2825 | |
| 2826 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2827 | return -EBUSY; |
| 2828 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2829 | val = ucontrol->value.enumerated.item[0]; |
| 2830 | |
| 2831 | if (val < 0) |
| 2832 | val = 0; |
| 2833 | else if (val >= hdspm->texts_autosync_items) |
| 2834 | val = hdspm->texts_autosync_items-1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2835 | |
| 2836 | spin_lock_irq(&hdspm->lock); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2837 | if (val != hdspm_pref_sync_ref(hdspm)) |
| 2838 | change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0; |
| 2839 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2840 | spin_unlock_irq(&hdspm->lock); |
| 2841 | return change; |
| 2842 | } |
| 2843 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2844 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2845 | #define HDSPM_AUTOSYNC_REF(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 2846 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2847 | .name = xname, \ |
| 2848 | .index = xindex, \ |
| 2849 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ |
| 2850 | .info = snd_hdspm_info_autosync_ref, \ |
| 2851 | .get = snd_hdspm_get_autosync_ref, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2854 | static int hdspm_autosync_ref(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2855 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2856 | if (AES32 == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2857 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2858 | unsigned int syncref = |
| 2859 | (status >> HDSPM_AES32_syncref_bit) & 0xF; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2860 | if (syncref == 0) |
| 2861 | return HDSPM_AES32_AUTOSYNC_FROM_WORD; |
| 2862 | if (syncref <= 8) |
| 2863 | return syncref; |
| 2864 | return HDSPM_AES32_AUTOSYNC_FROM_NONE; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2865 | } else if (MADI == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2866 | /* This looks at the autosync selected sync reference */ |
| 2867 | unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2868 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2869 | switch (status2 & HDSPM_SelSyncRefMask) { |
| 2870 | case HDSPM_SelSyncRef_WORD: |
| 2871 | return HDSPM_AUTOSYNC_FROM_WORD; |
| 2872 | case HDSPM_SelSyncRef_MADI: |
| 2873 | return HDSPM_AUTOSYNC_FROM_MADI; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2874 | case HDSPM_SelSyncRef_TCO: |
| 2875 | return HDSPM_AUTOSYNC_FROM_TCO; |
| 2876 | case HDSPM_SelSyncRef_SyncIn: |
| 2877 | return HDSPM_AUTOSYNC_FROM_SYNC_IN; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2878 | case HDSPM_SelSyncRef_NVALID: |
| 2879 | return HDSPM_AUTOSYNC_FROM_NONE; |
| 2880 | default: |
| 2881 | return 0; |
| 2882 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2883 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2884 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2885 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2886 | } |
| 2887 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2888 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2889 | static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol, |
| 2890 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2891 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2892 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2893 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2894 | if (AES32 == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2895 | static char *texts[] = { "WordClock", "AES1", "AES2", "AES3", |
| 2896 | "AES4", "AES5", "AES6", "AES7", "AES8", "None"}; |
| 2897 | |
| 2898 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2899 | uinfo->count = 1; |
| 2900 | uinfo->value.enumerated.items = 10; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 2901 | if (uinfo->value.enumerated.item >= |
| 2902 | uinfo->value.enumerated.items) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2903 | uinfo->value.enumerated.item = |
| 2904 | uinfo->value.enumerated.items - 1; |
| 2905 | strcpy(uinfo->value.enumerated.name, |
| 2906 | texts[uinfo->value.enumerated.item]); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2907 | } else if (MADI == hdspm->io_type) { |
| 2908 | static char *texts[] = {"Word Clock", "MADI", "TCO", |
| 2909 | "Sync In", "None" }; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2910 | |
| 2911 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2912 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2913 | uinfo->value.enumerated.items = 5; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 2914 | if (uinfo->value.enumerated.item >= |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2915 | uinfo->value.enumerated.items) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2916 | uinfo->value.enumerated.item = |
| 2917 | uinfo->value.enumerated.items - 1; |
| 2918 | strcpy(uinfo->value.enumerated.name, |
| 2919 | texts[uinfo->value.enumerated.item]); |
| 2920 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2921 | return 0; |
| 2922 | } |
| 2923 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2924 | static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, |
| 2925 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2926 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2927 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2928 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 2929 | ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2930 | return 0; |
| 2931 | } |
| 2932 | |
Adrian Knoth | f99c788 | 2013-03-10 00:37:26 +0100 | [diff] [blame^] | 2933 | |
| 2934 | |
| 2935 | #define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \ |
| 2936 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2937 | .name = xname, \ |
| 2938 | .access = SNDRV_CTL_ELEM_ACCESS_READ |\ |
| 2939 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2940 | .info = snd_hdspm_info_tco_video_input_format, \ |
| 2941 | .get = snd_hdspm_get_tco_video_input_format, \ |
| 2942 | } |
| 2943 | |
| 2944 | static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol, |
| 2945 | struct snd_ctl_elem_info *uinfo) |
| 2946 | { |
| 2947 | static char *texts[] = {"No video", "NTSC", "PAL"}; |
| 2948 | ENUMERATED_CTL_INFO(uinfo, texts); |
| 2949 | return 0; |
| 2950 | } |
| 2951 | |
| 2952 | static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol, |
| 2953 | struct snd_ctl_elem_value *ucontrol) |
| 2954 | { |
| 2955 | u32 status; |
| 2956 | int ret = 0; |
| 2957 | |
| 2958 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 2959 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); |
| 2960 | switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC | |
| 2961 | HDSPM_TCO1_Video_Input_Format_PAL)) { |
| 2962 | case HDSPM_TCO1_Video_Input_Format_NTSC: |
| 2963 | /* ntsc */ |
| 2964 | ret = 1; |
| 2965 | break; |
| 2966 | case HDSPM_TCO1_Video_Input_Format_PAL: |
| 2967 | /* pal */ |
| 2968 | ret = 2; |
| 2969 | break; |
| 2970 | default: |
| 2971 | /* no video */ |
| 2972 | ret = 0; |
| 2973 | break; |
| 2974 | } |
| 2975 | ucontrol->value.enumerated.item[0] = ret; |
| 2976 | return 0; |
| 2977 | } |
| 2978 | |
| 2979 | |
| 2980 | |
| 2981 | #define HDSPM_TCO_LTC_FRAMES(xname, xindex) \ |
| 2982 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2983 | .name = xname, \ |
| 2984 | .access = SNDRV_CTL_ELEM_ACCESS_READ |\ |
| 2985 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2986 | .info = snd_hdspm_info_tco_ltc_frames, \ |
| 2987 | .get = snd_hdspm_get_tco_ltc_frames, \ |
| 2988 | } |
| 2989 | |
| 2990 | static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol, |
| 2991 | struct snd_ctl_elem_info *uinfo) |
| 2992 | { |
| 2993 | static char *texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps", |
| 2994 | "30 fps"}; |
| 2995 | ENUMERATED_CTL_INFO(uinfo, texts); |
| 2996 | return 0; |
| 2997 | } |
| 2998 | |
| 2999 | static int hdspm_tco_ltc_frames(struct hdspm *hdspm) |
| 3000 | { |
| 3001 | u32 status; |
| 3002 | int ret = 0; |
| 3003 | |
| 3004 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); |
| 3005 | if (status & HDSPM_TCO1_LTC_Input_valid) { |
| 3006 | switch (status & (HDSPM_TCO1_LTC_Format_LSB | |
| 3007 | HDSPM_TCO1_LTC_Format_MSB)) { |
| 3008 | case 0: |
| 3009 | /* 24 fps */ |
| 3010 | ret = 1; |
| 3011 | break; |
| 3012 | case HDSPM_TCO1_LTC_Format_LSB: |
| 3013 | /* 25 fps */ |
| 3014 | ret = 2; |
| 3015 | break; |
| 3016 | case HDSPM_TCO1_LTC_Format_MSB: |
| 3017 | /* 25 fps */ |
| 3018 | ret = 3; |
| 3019 | break; |
| 3020 | default: |
| 3021 | /* 30 fps */ |
| 3022 | ret = 4; |
| 3023 | break; |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | return ret; |
| 3028 | } |
| 3029 | |
| 3030 | static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol, |
| 3031 | struct snd_ctl_elem_value *ucontrol) |
| 3032 | { |
| 3033 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3034 | |
| 3035 | ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm); |
| 3036 | return 0; |
| 3037 | } |
| 3038 | |
Adrian Knoth | bf0ff87 | 2012-12-03 14:55:49 +0100 | [diff] [blame] | 3039 | #define HDSPM_TOGGLE_SETTING(xname, xindex) \ |
| 3040 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3041 | .name = xname, \ |
| 3042 | .private_value = xindex, \ |
| 3043 | .info = snd_hdspm_info_toggle_setting, \ |
| 3044 | .get = snd_hdspm_get_toggle_setting, \ |
| 3045 | .put = snd_hdspm_put_toggle_setting \ |
| 3046 | } |
| 3047 | |
| 3048 | static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask) |
| 3049 | { |
| 3050 | return (hdspm->control_register & regmask) ? 1 : 0; |
| 3051 | } |
| 3052 | |
| 3053 | static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out) |
| 3054 | { |
| 3055 | if (out) |
| 3056 | hdspm->control_register |= regmask; |
| 3057 | else |
| 3058 | hdspm->control_register &= ~regmask; |
| 3059 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3060 | |
| 3061 | return 0; |
| 3062 | } |
| 3063 | |
| 3064 | #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info |
| 3065 | |
| 3066 | static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol, |
| 3067 | struct snd_ctl_elem_value *ucontrol) |
| 3068 | { |
| 3069 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3070 | u32 regmask = kcontrol->private_value; |
| 3071 | |
| 3072 | spin_lock_irq(&hdspm->lock); |
| 3073 | ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask); |
| 3074 | spin_unlock_irq(&hdspm->lock); |
| 3075 | return 0; |
| 3076 | } |
| 3077 | |
| 3078 | static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol, |
| 3079 | struct snd_ctl_elem_value *ucontrol) |
| 3080 | { |
| 3081 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3082 | u32 regmask = kcontrol->private_value; |
| 3083 | int change; |
| 3084 | unsigned int val; |
| 3085 | |
| 3086 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3087 | return -EBUSY; |
| 3088 | val = ucontrol->value.integer.value[0] & 1; |
| 3089 | spin_lock_irq(&hdspm->lock); |
| 3090 | change = (int) val != hdspm_toggle_setting(hdspm, regmask); |
| 3091 | hdspm_set_toggle_setting(hdspm, regmask, val); |
| 3092 | spin_unlock_irq(&hdspm->lock); |
| 3093 | return change; |
| 3094 | } |
| 3095 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3096 | #define HDSPM_INPUT_SELECT(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 3097 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3098 | .name = xname, \ |
| 3099 | .index = xindex, \ |
| 3100 | .info = snd_hdspm_info_input_select, \ |
| 3101 | .get = snd_hdspm_get_input_select, \ |
| 3102 | .put = snd_hdspm_put_input_select \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3103 | } |
| 3104 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3105 | static int hdspm_input_select(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3106 | { |
| 3107 | return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0; |
| 3108 | } |
| 3109 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3110 | static int hdspm_set_input_select(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3111 | { |
| 3112 | if (out) |
| 3113 | hdspm->control_register |= HDSPM_InputSelect0; |
| 3114 | else |
| 3115 | hdspm->control_register &= ~HDSPM_InputSelect0; |
| 3116 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3117 | |
| 3118 | return 0; |
| 3119 | } |
| 3120 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3121 | static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol, |
| 3122 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3123 | { |
| 3124 | static char *texts[] = { "optical", "coaxial" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3125 | ENUMERATED_CTL_INFO(uinfo, texts); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3126 | return 0; |
| 3127 | } |
| 3128 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3129 | static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, |
| 3130 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3131 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3132 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3133 | |
| 3134 | spin_lock_irq(&hdspm->lock); |
| 3135 | ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm); |
| 3136 | spin_unlock_irq(&hdspm->lock); |
| 3137 | return 0; |
| 3138 | } |
| 3139 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3140 | static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol, |
| 3141 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3142 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3143 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3144 | int change; |
| 3145 | unsigned int val; |
| 3146 | |
| 3147 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3148 | return -EBUSY; |
| 3149 | val = ucontrol->value.integer.value[0] & 1; |
| 3150 | spin_lock_irq(&hdspm->lock); |
| 3151 | change = (int) val != hdspm_input_select(hdspm); |
| 3152 | hdspm_set_input_select(hdspm, val); |
| 3153 | spin_unlock_irq(&hdspm->lock); |
| 3154 | return change; |
| 3155 | } |
| 3156 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3157 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3158 | #define HDSPM_DS_WIRE(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 3159 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3160 | .name = xname, \ |
| 3161 | .index = xindex, \ |
| 3162 | .info = snd_hdspm_info_ds_wire, \ |
| 3163 | .get = snd_hdspm_get_ds_wire, \ |
| 3164 | .put = snd_hdspm_put_ds_wire \ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | static int hdspm_ds_wire(struct hdspm * hdspm) |
| 3168 | { |
| 3169 | return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0; |
| 3170 | } |
| 3171 | |
| 3172 | static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds) |
| 3173 | { |
| 3174 | if (ds) |
| 3175 | hdspm->control_register |= HDSPM_DS_DoubleWire; |
| 3176 | else |
| 3177 | hdspm->control_register &= ~HDSPM_DS_DoubleWire; |
| 3178 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3179 | |
| 3180 | return 0; |
| 3181 | } |
| 3182 | |
| 3183 | static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol, |
| 3184 | struct snd_ctl_elem_info *uinfo) |
| 3185 | { |
| 3186 | static char *texts[] = { "Single", "Double" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3187 | ENUMERATED_CTL_INFO(uinfo, texts); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3188 | return 0; |
| 3189 | } |
| 3190 | |
| 3191 | static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, |
| 3192 | struct snd_ctl_elem_value *ucontrol) |
| 3193 | { |
| 3194 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3195 | |
| 3196 | spin_lock_irq(&hdspm->lock); |
| 3197 | ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm); |
| 3198 | spin_unlock_irq(&hdspm->lock); |
| 3199 | return 0; |
| 3200 | } |
| 3201 | |
| 3202 | static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol, |
| 3203 | struct snd_ctl_elem_value *ucontrol) |
| 3204 | { |
| 3205 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3206 | int change; |
| 3207 | unsigned int val; |
| 3208 | |
| 3209 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3210 | return -EBUSY; |
| 3211 | val = ucontrol->value.integer.value[0] & 1; |
| 3212 | spin_lock_irq(&hdspm->lock); |
| 3213 | change = (int) val != hdspm_ds_wire(hdspm); |
| 3214 | hdspm_set_ds_wire(hdspm, val); |
| 3215 | spin_unlock_irq(&hdspm->lock); |
| 3216 | return change; |
| 3217 | } |
| 3218 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3219 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3220 | #define HDSPM_QS_WIRE(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 3221 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3222 | .name = xname, \ |
| 3223 | .index = xindex, \ |
| 3224 | .info = snd_hdspm_info_qs_wire, \ |
| 3225 | .get = snd_hdspm_get_qs_wire, \ |
| 3226 | .put = snd_hdspm_put_qs_wire \ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | static int hdspm_qs_wire(struct hdspm * hdspm) |
| 3230 | { |
| 3231 | if (hdspm->control_register & HDSPM_QS_DoubleWire) |
| 3232 | return 1; |
| 3233 | if (hdspm->control_register & HDSPM_QS_QuadWire) |
| 3234 | return 2; |
| 3235 | return 0; |
| 3236 | } |
| 3237 | |
| 3238 | static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode) |
| 3239 | { |
| 3240 | hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire); |
| 3241 | switch (mode) { |
| 3242 | case 0: |
| 3243 | break; |
| 3244 | case 1: |
| 3245 | hdspm->control_register |= HDSPM_QS_DoubleWire; |
| 3246 | break; |
| 3247 | case 2: |
| 3248 | hdspm->control_register |= HDSPM_QS_QuadWire; |
| 3249 | break; |
| 3250 | } |
| 3251 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3252 | |
| 3253 | return 0; |
| 3254 | } |
| 3255 | |
| 3256 | static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol, |
| 3257 | struct snd_ctl_elem_info *uinfo) |
| 3258 | { |
| 3259 | static char *texts[] = { "Single", "Double", "Quad" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3260 | ENUMERATED_CTL_INFO(uinfo, texts); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3261 | return 0; |
| 3262 | } |
| 3263 | |
| 3264 | static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, |
| 3265 | struct snd_ctl_elem_value *ucontrol) |
| 3266 | { |
| 3267 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3268 | |
| 3269 | spin_lock_irq(&hdspm->lock); |
| 3270 | ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm); |
| 3271 | spin_unlock_irq(&hdspm->lock); |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, |
| 3276 | struct snd_ctl_elem_value *ucontrol) |
| 3277 | { |
| 3278 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3279 | int change; |
| 3280 | int val; |
| 3281 | |
| 3282 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3283 | return -EBUSY; |
| 3284 | val = ucontrol->value.integer.value[0]; |
| 3285 | if (val < 0) |
| 3286 | val = 0; |
| 3287 | if (val > 2) |
| 3288 | val = 2; |
| 3289 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 3290 | change = val != hdspm_qs_wire(hdspm); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3291 | hdspm_set_qs_wire(hdspm, val); |
| 3292 | spin_unlock_irq(&hdspm->lock); |
| 3293 | return change; |
| 3294 | } |
| 3295 | |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 3296 | #define HDSPM_MADI_SPEEDMODE(xname, xindex) \ |
| 3297 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3298 | .name = xname, \ |
| 3299 | .index = xindex, \ |
| 3300 | .info = snd_hdspm_info_madi_speedmode, \ |
| 3301 | .get = snd_hdspm_get_madi_speedmode, \ |
| 3302 | .put = snd_hdspm_put_madi_speedmode \ |
| 3303 | } |
| 3304 | |
| 3305 | static int hdspm_madi_speedmode(struct hdspm *hdspm) |
| 3306 | { |
| 3307 | if (hdspm->control_register & HDSPM_QuadSpeed) |
| 3308 | return 2; |
| 3309 | if (hdspm->control_register & HDSPM_DoubleSpeed) |
| 3310 | return 1; |
| 3311 | return 0; |
| 3312 | } |
| 3313 | |
| 3314 | static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode) |
| 3315 | { |
| 3316 | hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed); |
| 3317 | switch (mode) { |
| 3318 | case 0: |
| 3319 | break; |
| 3320 | case 1: |
| 3321 | hdspm->control_register |= HDSPM_DoubleSpeed; |
| 3322 | break; |
| 3323 | case 2: |
| 3324 | hdspm->control_register |= HDSPM_QuadSpeed; |
| 3325 | break; |
| 3326 | } |
| 3327 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3328 | |
| 3329 | return 0; |
| 3330 | } |
| 3331 | |
| 3332 | static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3333 | struct snd_ctl_elem_info *uinfo) |
| 3334 | { |
| 3335 | static char *texts[] = { "Single", "Double", "Quad" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3336 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 3337 | return 0; |
| 3338 | } |
| 3339 | |
| 3340 | static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3341 | struct snd_ctl_elem_value *ucontrol) |
| 3342 | { |
| 3343 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3344 | |
| 3345 | spin_lock_irq(&hdspm->lock); |
| 3346 | ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm); |
| 3347 | spin_unlock_irq(&hdspm->lock); |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3352 | struct snd_ctl_elem_value *ucontrol) |
| 3353 | { |
| 3354 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3355 | int change; |
| 3356 | int val; |
| 3357 | |
| 3358 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3359 | return -EBUSY; |
| 3360 | val = ucontrol->value.integer.value[0]; |
| 3361 | if (val < 0) |
| 3362 | val = 0; |
| 3363 | if (val > 2) |
| 3364 | val = 2; |
| 3365 | spin_lock_irq(&hdspm->lock); |
| 3366 | change = val != hdspm_madi_speedmode(hdspm); |
| 3367 | hdspm_set_madi_speedmode(hdspm, val); |
| 3368 | spin_unlock_irq(&hdspm->lock); |
| 3369 | return change; |
| 3370 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3371 | |
| 3372 | #define HDSPM_MIXER(xname, xindex) \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 3373 | { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \ |
| 3374 | .name = xname, \ |
| 3375 | .index = xindex, \ |
| 3376 | .device = 0, \ |
| 3377 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 3378 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3379 | .info = snd_hdspm_info_mixer, \ |
| 3380 | .get = snd_hdspm_get_mixer, \ |
| 3381 | .put = snd_hdspm_put_mixer \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3382 | } |
| 3383 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3384 | static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol, |
| 3385 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3386 | { |
| 3387 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3388 | uinfo->count = 3; |
| 3389 | uinfo->value.integer.min = 0; |
| 3390 | uinfo->value.integer.max = 65535; |
| 3391 | uinfo->value.integer.step = 1; |
| 3392 | return 0; |
| 3393 | } |
| 3394 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3395 | static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, |
| 3396 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3397 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3398 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3399 | int source; |
| 3400 | int destination; |
| 3401 | |
| 3402 | source = ucontrol->value.integer.value[0]; |
| 3403 | if (source < 0) |
| 3404 | source = 0; |
| 3405 | else if (source >= 2 * HDSPM_MAX_CHANNELS) |
| 3406 | source = 2 * HDSPM_MAX_CHANNELS - 1; |
| 3407 | |
| 3408 | destination = ucontrol->value.integer.value[1]; |
| 3409 | if (destination < 0) |
| 3410 | destination = 0; |
| 3411 | else if (destination >= HDSPM_MAX_CHANNELS) |
| 3412 | destination = HDSPM_MAX_CHANNELS - 1; |
| 3413 | |
| 3414 | spin_lock_irq(&hdspm->lock); |
| 3415 | if (source >= HDSPM_MAX_CHANNELS) |
| 3416 | ucontrol->value.integer.value[2] = |
| 3417 | hdspm_read_pb_gain(hdspm, destination, |
| 3418 | source - HDSPM_MAX_CHANNELS); |
| 3419 | else |
| 3420 | ucontrol->value.integer.value[2] = |
| 3421 | hdspm_read_in_gain(hdspm, destination, source); |
| 3422 | |
| 3423 | spin_unlock_irq(&hdspm->lock); |
| 3424 | |
| 3425 | return 0; |
| 3426 | } |
| 3427 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3428 | static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, |
| 3429 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3430 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3431 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3432 | int change; |
| 3433 | int source; |
| 3434 | int destination; |
| 3435 | int gain; |
| 3436 | |
| 3437 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3438 | return -EBUSY; |
| 3439 | |
| 3440 | source = ucontrol->value.integer.value[0]; |
| 3441 | destination = ucontrol->value.integer.value[1]; |
| 3442 | |
| 3443 | if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS) |
| 3444 | return -1; |
| 3445 | if (destination < 0 || destination >= HDSPM_MAX_CHANNELS) |
| 3446 | return -1; |
| 3447 | |
| 3448 | gain = ucontrol->value.integer.value[2]; |
| 3449 | |
| 3450 | spin_lock_irq(&hdspm->lock); |
| 3451 | |
| 3452 | if (source >= HDSPM_MAX_CHANNELS) |
| 3453 | change = gain != hdspm_read_pb_gain(hdspm, destination, |
| 3454 | source - |
| 3455 | HDSPM_MAX_CHANNELS); |
| 3456 | else |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 3457 | change = gain != hdspm_read_in_gain(hdspm, destination, |
| 3458 | source); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3459 | |
| 3460 | if (change) { |
| 3461 | if (source >= HDSPM_MAX_CHANNELS) |
| 3462 | hdspm_write_pb_gain(hdspm, destination, |
| 3463 | source - HDSPM_MAX_CHANNELS, |
| 3464 | gain); |
| 3465 | else |
| 3466 | hdspm_write_in_gain(hdspm, destination, source, |
| 3467 | gain); |
| 3468 | } |
| 3469 | spin_unlock_irq(&hdspm->lock); |
| 3470 | |
| 3471 | return change; |
| 3472 | } |
| 3473 | |
| 3474 | /* The simple mixer control(s) provide gain control for the |
| 3475 | basic 1:1 mappings of playback streams to output |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3476 | streams. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3477 | */ |
| 3478 | |
| 3479 | #define HDSPM_PLAYBACK_MIXER \ |
Adrian Knoth | f27a64f | 2012-10-19 17:42:30 +0200 | [diff] [blame] | 3480 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3481 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \ |
| 3482 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3483 | .info = snd_hdspm_info_playback_mixer, \ |
| 3484 | .get = snd_hdspm_get_playback_mixer, \ |
| 3485 | .put = snd_hdspm_put_playback_mixer \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3486 | } |
| 3487 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3488 | static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3489 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3490 | { |
| 3491 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3492 | uinfo->count = 1; |
| 3493 | uinfo->value.integer.min = 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3494 | uinfo->value.integer.max = 64; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3495 | uinfo->value.integer.step = 1; |
| 3496 | return 0; |
| 3497 | } |
| 3498 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3499 | static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3500 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3501 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3502 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3503 | int channel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3504 | |
| 3505 | channel = ucontrol->id.index - 1; |
| 3506 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3507 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
| 3508 | return -EINVAL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3509 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3510 | spin_lock_irq(&hdspm->lock); |
| 3511 | ucontrol->value.integer.value[0] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3512 | (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3513 | spin_unlock_irq(&hdspm->lock); |
| 3514 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3515 | return 0; |
| 3516 | } |
| 3517 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3518 | static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3519 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3520 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3521 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3522 | int change; |
| 3523 | int channel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3524 | int gain; |
| 3525 | |
| 3526 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3527 | return -EBUSY; |
| 3528 | |
| 3529 | channel = ucontrol->id.index - 1; |
| 3530 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3531 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
| 3532 | return -EINVAL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3533 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3534 | gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3535 | |
| 3536 | spin_lock_irq(&hdspm->lock); |
| 3537 | change = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3538 | gain != hdspm_read_pb_gain(hdspm, channel, |
| 3539 | channel); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3540 | if (change) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3541 | hdspm_write_pb_gain(hdspm, channel, channel, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3542 | gain); |
| 3543 | spin_unlock_irq(&hdspm->lock); |
| 3544 | return change; |
| 3545 | } |
| 3546 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3547 | #define HDSPM_SYNC_CHECK(xname, xindex) \ |
| 3548 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3549 | .name = xname, \ |
| 3550 | .private_value = xindex, \ |
| 3551 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3552 | .info = snd_hdspm_info_sync_check, \ |
| 3553 | .get = snd_hdspm_get_sync_check \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3554 | } |
| 3555 | |
Adrian Knoth | 3454221 | 2013-03-10 00:37:25 +0100 | [diff] [blame] | 3556 | #define HDSPM_TCO_LOCK_CHECK(xname, xindex) \ |
| 3557 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3558 | .name = xname, \ |
| 3559 | .private_value = xindex, \ |
| 3560 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3561 | .info = snd_hdspm_tco_info_lock_check, \ |
| 3562 | .get = snd_hdspm_get_sync_check \ |
| 3563 | } |
| 3564 | |
| 3565 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3566 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3567 | static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, |
| 3568 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3569 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3570 | static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3571 | ENUMERATED_CTL_INFO(uinfo, texts); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3572 | return 0; |
| 3573 | } |
| 3574 | |
Adrian Knoth | 3454221 | 2013-03-10 00:37:25 +0100 | [diff] [blame] | 3575 | static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol, |
| 3576 | struct snd_ctl_elem_info *uinfo) |
| 3577 | { |
| 3578 | static char *texts[] = { "No Lock", "Lock" }; |
| 3579 | ENUMERATED_CTL_INFO(uinfo, texts); |
| 3580 | return 0; |
| 3581 | } |
| 3582 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3583 | static int hdspm_wc_sync_check(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3584 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3585 | int status, status2; |
| 3586 | |
| 3587 | switch (hdspm->io_type) { |
| 3588 | case AES32: |
| 3589 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
Andre Schramm | 56bde0f | 2013-01-09 14:40:18 +0100 | [diff] [blame] | 3590 | if (status & HDSPM_AES32_wcLock) { |
| 3591 | if (status & HDSPM_AES32_wcSync) |
| 3592 | return 2; |
| 3593 | else |
| 3594 | return 1; |
| 3595 | } |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3596 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3597 | break; |
| 3598 | |
| 3599 | case MADI: |
| 3600 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3601 | if (status2 & HDSPM_wcLock) { |
| 3602 | if (status2 & HDSPM_wcSync) |
| 3603 | return 2; |
| 3604 | else |
| 3605 | return 1; |
| 3606 | } |
| 3607 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3608 | break; |
| 3609 | |
| 3610 | case RayDAT: |
| 3611 | case AIO: |
| 3612 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3613 | |
| 3614 | if (status & 0x2000000) |
| 3615 | return 2; |
| 3616 | else if (status & 0x1000000) |
| 3617 | return 1; |
| 3618 | return 0; |
| 3619 | |
| 3620 | break; |
| 3621 | |
| 3622 | case MADIface: |
| 3623 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3624 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3625 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3626 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3627 | return 3; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3631 | static int hdspm_madi_sync_check(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3632 | { |
| 3633 | int status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3634 | if (status & HDSPM_madiLock) { |
| 3635 | if (status & HDSPM_madiSync) |
| 3636 | return 2; |
| 3637 | else |
| 3638 | return 1; |
| 3639 | } |
| 3640 | return 0; |
| 3641 | } |
| 3642 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3643 | |
| 3644 | static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx) |
| 3645 | { |
| 3646 | int status, lock, sync; |
| 3647 | |
| 3648 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 3649 | |
| 3650 | lock = (status & (0x1<<idx)) ? 1 : 0; |
| 3651 | sync = (status & (0x100<<idx)) ? 1 : 0; |
| 3652 | |
| 3653 | if (lock && sync) |
| 3654 | return 2; |
| 3655 | else if (lock) |
| 3656 | return 1; |
| 3657 | return 0; |
| 3658 | } |
| 3659 | |
| 3660 | |
| 3661 | static int hdspm_sync_in_sync_check(struct hdspm *hdspm) |
| 3662 | { |
| 3663 | int status, lock = 0, sync = 0; |
| 3664 | |
| 3665 | switch (hdspm->io_type) { |
| 3666 | case RayDAT: |
| 3667 | case AIO: |
| 3668 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_3); |
| 3669 | lock = (status & 0x400) ? 1 : 0; |
| 3670 | sync = (status & 0x800) ? 1 : 0; |
| 3671 | break; |
| 3672 | |
| 3673 | case MADI: |
Adrian Knoth | 2e0452f | 2012-10-19 17:42:27 +0200 | [diff] [blame] | 3674 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3675 | lock = (status & HDSPM_syncInLock) ? 1 : 0; |
| 3676 | sync = (status & HDSPM_syncInSync) ? 1 : 0; |
| 3677 | break; |
| 3678 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3679 | case AES32: |
| 3680 | status = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | 9a215f4 | 2012-10-19 17:42:28 +0200 | [diff] [blame] | 3681 | lock = (status & 0x100000) ? 1 : 0; |
| 3682 | sync = (status & 0x200000) ? 1 : 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3683 | break; |
| 3684 | |
| 3685 | case MADIface: |
| 3686 | break; |
| 3687 | } |
| 3688 | |
| 3689 | if (lock && sync) |
| 3690 | return 2; |
| 3691 | else if (lock) |
| 3692 | return 1; |
| 3693 | |
| 3694 | return 0; |
| 3695 | } |
| 3696 | |
| 3697 | static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx) |
| 3698 | { |
| 3699 | int status2, lock, sync; |
| 3700 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 3701 | |
| 3702 | lock = (status2 & (0x0080 >> idx)) ? 1 : 0; |
| 3703 | sync = (status2 & (0x8000 >> idx)) ? 1 : 0; |
| 3704 | |
| 3705 | if (sync) |
| 3706 | return 2; |
| 3707 | else if (lock) |
| 3708 | return 1; |
| 3709 | return 0; |
| 3710 | } |
| 3711 | |
Adrian Knoth | 3454221 | 2013-03-10 00:37:25 +0100 | [diff] [blame] | 3712 | static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask) |
| 3713 | { |
| 3714 | u32 status; |
| 3715 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); |
| 3716 | |
| 3717 | return (status & mask) ? 1 : 0; |
| 3718 | } |
| 3719 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3720 | |
| 3721 | static int hdspm_tco_sync_check(struct hdspm *hdspm) |
| 3722 | { |
| 3723 | int status; |
| 3724 | |
| 3725 | if (hdspm->tco) { |
| 3726 | switch (hdspm->io_type) { |
| 3727 | case MADI: |
| 3728 | case AES32: |
| 3729 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3730 | if (status & HDSPM_tcoLock) { |
| 3731 | if (status & HDSPM_tcoSync) |
| 3732 | return 2; |
| 3733 | else |
| 3734 | return 1; |
| 3735 | } |
| 3736 | return 0; |
| 3737 | |
| 3738 | break; |
| 3739 | |
| 3740 | case RayDAT: |
| 3741 | case AIO: |
| 3742 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 3743 | |
| 3744 | if (status & 0x8000000) |
| 3745 | return 2; /* Sync */ |
| 3746 | if (status & 0x4000000) |
| 3747 | return 1; /* Lock */ |
| 3748 | return 0; /* No signal */ |
| 3749 | break; |
| 3750 | |
| 3751 | default: |
| 3752 | break; |
| 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | return 3; /* N/A */ |
| 3757 | } |
| 3758 | |
| 3759 | |
| 3760 | static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol, |
| 3761 | struct snd_ctl_elem_value *ucontrol) |
| 3762 | { |
| 3763 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3764 | int val = -1; |
| 3765 | |
| 3766 | switch (hdspm->io_type) { |
| 3767 | case RayDAT: |
| 3768 | switch (kcontrol->private_value) { |
| 3769 | case 0: /* WC */ |
| 3770 | val = hdspm_wc_sync_check(hdspm); break; |
| 3771 | case 7: /* TCO */ |
| 3772 | val = hdspm_tco_sync_check(hdspm); break; |
| 3773 | case 8: /* SYNC IN */ |
| 3774 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3775 | default: |
Adrian Knoth | d1a3c98 | 2012-11-07 18:00:09 +0100 | [diff] [blame] | 3776 | val = hdspm_s1_sync_check(hdspm, |
| 3777 | kcontrol->private_value-1); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3778 | } |
Adrian Knoth | fba30fd | 2012-10-19 17:42:24 +0200 | [diff] [blame] | 3779 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3780 | |
| 3781 | case AIO: |
| 3782 | switch (kcontrol->private_value) { |
| 3783 | case 0: /* WC */ |
| 3784 | val = hdspm_wc_sync_check(hdspm); break; |
| 3785 | case 4: /* TCO */ |
| 3786 | val = hdspm_tco_sync_check(hdspm); break; |
| 3787 | case 5: /* SYNC IN */ |
| 3788 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3789 | default: |
| 3790 | val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1); |
| 3791 | } |
Adrian Knoth | fba30fd | 2012-10-19 17:42:24 +0200 | [diff] [blame] | 3792 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3793 | |
| 3794 | case MADI: |
| 3795 | switch (kcontrol->private_value) { |
| 3796 | case 0: /* WC */ |
| 3797 | val = hdspm_wc_sync_check(hdspm); break; |
| 3798 | case 1: /* MADI */ |
| 3799 | val = hdspm_madi_sync_check(hdspm); break; |
| 3800 | case 2: /* TCO */ |
| 3801 | val = hdspm_tco_sync_check(hdspm); break; |
| 3802 | case 3: /* SYNC_IN */ |
| 3803 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3804 | } |
Adrian Knoth | fba30fd | 2012-10-19 17:42:24 +0200 | [diff] [blame] | 3805 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3806 | |
| 3807 | case MADIface: |
| 3808 | val = hdspm_madi_sync_check(hdspm); /* MADI */ |
| 3809 | break; |
| 3810 | |
| 3811 | case AES32: |
| 3812 | switch (kcontrol->private_value) { |
| 3813 | case 0: /* WC */ |
| 3814 | val = hdspm_wc_sync_check(hdspm); break; |
| 3815 | case 9: /* TCO */ |
| 3816 | val = hdspm_tco_sync_check(hdspm); break; |
| 3817 | case 10 /* SYNC IN */: |
| 3818 | val = hdspm_sync_in_sync_check(hdspm); break; |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 3819 | default: /* AES1 to AES8 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3820 | val = hdspm_aes_sync_check(hdspm, |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 3821 | kcontrol->private_value-1); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3822 | } |
Adrian Knoth | fba30fd | 2012-10-19 17:42:24 +0200 | [diff] [blame] | 3823 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3824 | |
| 3825 | } |
| 3826 | |
Adrian Knoth | 3454221 | 2013-03-10 00:37:25 +0100 | [diff] [blame] | 3827 | if (hdspm->tco) { |
| 3828 | switch (kcontrol->private_value) { |
| 3829 | case 11: |
| 3830 | /* Check TCO for lock state of its current input */ |
| 3831 | val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock); |
| 3832 | break; |
| 3833 | case 12: |
| 3834 | /* Check TCO for valid time code on LTC input. */ |
| 3835 | val = hdspm_tco_input_check(hdspm, |
| 3836 | HDSPM_TCO1_LTC_Input_valid); |
| 3837 | break; |
| 3838 | default: |
| 3839 | break; |
| 3840 | } |
| 3841 | } |
| 3842 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3843 | if (-1 == val) |
| 3844 | val = 3; |
| 3845 | |
| 3846 | ucontrol->value.enumerated.item[0] = val; |
| 3847 | return 0; |
| 3848 | } |
| 3849 | |
| 3850 | |
| 3851 | |
| 3852 | /** |
| 3853 | * TCO controls |
| 3854 | **/ |
| 3855 | static void hdspm_tco_write(struct hdspm *hdspm) |
| 3856 | { |
| 3857 | unsigned int tc[4] = { 0, 0, 0, 0}; |
| 3858 | |
| 3859 | switch (hdspm->tco->input) { |
| 3860 | case 0: |
| 3861 | tc[2] |= HDSPM_TCO2_set_input_MSB; |
| 3862 | break; |
| 3863 | case 1: |
| 3864 | tc[2] |= HDSPM_TCO2_set_input_LSB; |
| 3865 | break; |
| 3866 | default: |
| 3867 | break; |
| 3868 | } |
| 3869 | |
| 3870 | switch (hdspm->tco->framerate) { |
| 3871 | case 1: |
| 3872 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB; |
| 3873 | break; |
| 3874 | case 2: |
| 3875 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB; |
| 3876 | break; |
| 3877 | case 3: |
| 3878 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB + |
| 3879 | HDSPM_TCO1_set_drop_frame_flag; |
| 3880 | break; |
| 3881 | case 4: |
| 3882 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + |
| 3883 | HDSPM_TCO1_LTC_Format_MSB; |
| 3884 | break; |
| 3885 | case 5: |
| 3886 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + |
| 3887 | HDSPM_TCO1_LTC_Format_MSB + |
| 3888 | HDSPM_TCO1_set_drop_frame_flag; |
| 3889 | break; |
| 3890 | default: |
| 3891 | break; |
| 3892 | } |
| 3893 | |
| 3894 | switch (hdspm->tco->wordclock) { |
| 3895 | case 1: |
| 3896 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB; |
| 3897 | break; |
| 3898 | case 2: |
| 3899 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB; |
| 3900 | break; |
| 3901 | default: |
| 3902 | break; |
| 3903 | } |
| 3904 | |
| 3905 | switch (hdspm->tco->samplerate) { |
| 3906 | case 1: |
| 3907 | tc[2] |= HDSPM_TCO2_set_freq; |
| 3908 | break; |
| 3909 | case 2: |
| 3910 | tc[2] |= HDSPM_TCO2_set_freq_from_app; |
| 3911 | break; |
| 3912 | default: |
| 3913 | break; |
| 3914 | } |
| 3915 | |
| 3916 | switch (hdspm->tco->pull) { |
| 3917 | case 1: |
| 3918 | tc[2] |= HDSPM_TCO2_set_pull_up; |
| 3919 | break; |
| 3920 | case 2: |
| 3921 | tc[2] |= HDSPM_TCO2_set_pull_down; |
| 3922 | break; |
| 3923 | case 3: |
| 3924 | tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4; |
| 3925 | break; |
| 3926 | case 4: |
| 3927 | tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4; |
| 3928 | break; |
| 3929 | default: |
| 3930 | break; |
| 3931 | } |
| 3932 | |
| 3933 | if (1 == hdspm->tco->term) { |
| 3934 | tc[2] |= HDSPM_TCO2_set_term_75R; |
| 3935 | } |
| 3936 | |
| 3937 | hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]); |
| 3938 | hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]); |
| 3939 | hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]); |
| 3940 | hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]); |
| 3941 | } |
| 3942 | |
| 3943 | |
| 3944 | #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \ |
| 3945 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3946 | .name = xname, \ |
| 3947 | .index = xindex, \ |
| 3948 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 3949 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3950 | .info = snd_hdspm_info_tco_sample_rate, \ |
| 3951 | .get = snd_hdspm_get_tco_sample_rate, \ |
| 3952 | .put = snd_hdspm_put_tco_sample_rate \ |
| 3953 | } |
| 3954 | |
| 3955 | static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 3956 | struct snd_ctl_elem_info *uinfo) |
| 3957 | { |
| 3958 | static char *texts[] = { "44.1 kHz", "48 kHz" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 3959 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3960 | return 0; |
| 3961 | } |
| 3962 | |
| 3963 | static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 3964 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3965 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3966 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3967 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3968 | ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate; |
| 3969 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3970 | return 0; |
| 3971 | } |
| 3972 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3973 | static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 3974 | struct snd_ctl_elem_value *ucontrol) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3975 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3976 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3977 | |
| 3978 | if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) { |
| 3979 | hdspm->tco->samplerate = ucontrol->value.enumerated.item[0]; |
| 3980 | |
| 3981 | hdspm_tco_write(hdspm); |
| 3982 | |
| 3983 | return 1; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3984 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3985 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3986 | return 0; |
| 3987 | } |
| 3988 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3989 | |
| 3990 | #define HDSPM_TCO_PULL(xname, xindex) \ |
| 3991 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3992 | .name = xname, \ |
| 3993 | .index = xindex, \ |
| 3994 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 3995 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3996 | .info = snd_hdspm_info_tco_pull, \ |
| 3997 | .get = snd_hdspm_get_tco_pull, \ |
| 3998 | .put = snd_hdspm_put_tco_pull \ |
| 3999 | } |
| 4000 | |
| 4001 | static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol, |
| 4002 | struct snd_ctl_elem_info *uinfo) |
| 4003 | { |
| 4004 | static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 4005 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4006 | return 0; |
| 4007 | } |
| 4008 | |
| 4009 | static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol, |
| 4010 | struct snd_ctl_elem_value *ucontrol) |
| 4011 | { |
| 4012 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4013 | |
| 4014 | ucontrol->value.enumerated.item[0] = hdspm->tco->pull; |
| 4015 | |
| 4016 | return 0; |
| 4017 | } |
| 4018 | |
| 4019 | static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol, |
| 4020 | struct snd_ctl_elem_value *ucontrol) |
| 4021 | { |
| 4022 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4023 | |
| 4024 | if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) { |
| 4025 | hdspm->tco->pull = ucontrol->value.enumerated.item[0]; |
| 4026 | |
| 4027 | hdspm_tco_write(hdspm); |
| 4028 | |
| 4029 | return 1; |
| 4030 | } |
| 4031 | |
| 4032 | return 0; |
| 4033 | } |
| 4034 | |
| 4035 | #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \ |
| 4036 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4037 | .name = xname, \ |
| 4038 | .index = xindex, \ |
| 4039 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4040 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4041 | .info = snd_hdspm_info_tco_wck_conversion, \ |
| 4042 | .get = snd_hdspm_get_tco_wck_conversion, \ |
| 4043 | .put = snd_hdspm_put_tco_wck_conversion \ |
| 4044 | } |
| 4045 | |
| 4046 | static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4047 | struct snd_ctl_elem_info *uinfo) |
| 4048 | { |
| 4049 | static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 4050 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4051 | return 0; |
| 4052 | } |
| 4053 | |
| 4054 | static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4055 | struct snd_ctl_elem_value *ucontrol) |
| 4056 | { |
| 4057 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4058 | |
| 4059 | ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock; |
| 4060 | |
| 4061 | return 0; |
| 4062 | } |
| 4063 | |
| 4064 | static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4065 | struct snd_ctl_elem_value *ucontrol) |
| 4066 | { |
| 4067 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4068 | |
| 4069 | if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) { |
| 4070 | hdspm->tco->wordclock = ucontrol->value.enumerated.item[0]; |
| 4071 | |
| 4072 | hdspm_tco_write(hdspm); |
| 4073 | |
| 4074 | return 1; |
| 4075 | } |
| 4076 | |
| 4077 | return 0; |
| 4078 | } |
| 4079 | |
| 4080 | |
| 4081 | #define HDSPM_TCO_FRAME_RATE(xname, xindex) \ |
| 4082 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4083 | .name = xname, \ |
| 4084 | .index = xindex, \ |
| 4085 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4086 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4087 | .info = snd_hdspm_info_tco_frame_rate, \ |
| 4088 | .get = snd_hdspm_get_tco_frame_rate, \ |
| 4089 | .put = snd_hdspm_put_tco_frame_rate \ |
| 4090 | } |
| 4091 | |
| 4092 | static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol, |
| 4093 | struct snd_ctl_elem_info *uinfo) |
| 4094 | { |
| 4095 | static char *texts[] = { "24 fps", "25 fps", "29.97fps", |
| 4096 | "29.97 dfps", "30 fps", "30 dfps" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 4097 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4098 | return 0; |
| 4099 | } |
| 4100 | |
| 4101 | static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4102 | struct snd_ctl_elem_value *ucontrol) |
| 4103 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4104 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4105 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4106 | ucontrol->value.enumerated.item[0] = hdspm->tco->framerate; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4107 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4108 | return 0; |
| 4109 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4110 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4111 | static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol, |
| 4112 | struct snd_ctl_elem_value *ucontrol) |
| 4113 | { |
| 4114 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4115 | |
| 4116 | if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) { |
| 4117 | hdspm->tco->framerate = ucontrol->value.enumerated.item[0]; |
| 4118 | |
| 4119 | hdspm_tco_write(hdspm); |
| 4120 | |
| 4121 | return 1; |
| 4122 | } |
| 4123 | |
| 4124 | return 0; |
| 4125 | } |
| 4126 | |
| 4127 | |
| 4128 | #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \ |
| 4129 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4130 | .name = xname, \ |
| 4131 | .index = xindex, \ |
| 4132 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4133 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4134 | .info = snd_hdspm_info_tco_sync_source, \ |
| 4135 | .get = snd_hdspm_get_tco_sync_source, \ |
| 4136 | .put = snd_hdspm_put_tco_sync_source \ |
| 4137 | } |
| 4138 | |
| 4139 | static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4140 | struct snd_ctl_elem_info *uinfo) |
| 4141 | { |
| 4142 | static char *texts[] = { "LTC", "Video", "WCK" }; |
Adrian Knoth | e5b7b1f | 2013-03-10 00:37:24 +0100 | [diff] [blame] | 4143 | ENUMERATED_CTL_INFO(uinfo, texts); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4144 | return 0; |
| 4145 | } |
| 4146 | |
| 4147 | static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4148 | struct snd_ctl_elem_value *ucontrol) |
| 4149 | { |
| 4150 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4151 | |
| 4152 | ucontrol->value.enumerated.item[0] = hdspm->tco->input; |
| 4153 | |
| 4154 | return 0; |
| 4155 | } |
| 4156 | |
| 4157 | static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4158 | struct snd_ctl_elem_value *ucontrol) |
| 4159 | { |
| 4160 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4161 | |
| 4162 | if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) { |
| 4163 | hdspm->tco->input = ucontrol->value.enumerated.item[0]; |
| 4164 | |
| 4165 | hdspm_tco_write(hdspm); |
| 4166 | |
| 4167 | return 1; |
| 4168 | } |
| 4169 | |
| 4170 | return 0; |
| 4171 | } |
| 4172 | |
| 4173 | |
| 4174 | #define HDSPM_TCO_WORD_TERM(xname, xindex) \ |
| 4175 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4176 | .name = xname, \ |
| 4177 | .index = xindex, \ |
| 4178 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4179 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4180 | .info = snd_hdspm_info_tco_word_term, \ |
| 4181 | .get = snd_hdspm_get_tco_word_term, \ |
| 4182 | .put = snd_hdspm_put_tco_word_term \ |
| 4183 | } |
| 4184 | |
| 4185 | static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4186 | struct snd_ctl_elem_info *uinfo) |
| 4187 | { |
| 4188 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 4189 | uinfo->count = 1; |
| 4190 | uinfo->value.integer.min = 0; |
| 4191 | uinfo->value.integer.max = 1; |
| 4192 | |
| 4193 | return 0; |
| 4194 | } |
| 4195 | |
| 4196 | |
| 4197 | static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4198 | struct snd_ctl_elem_value *ucontrol) |
| 4199 | { |
| 4200 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4201 | |
| 4202 | ucontrol->value.enumerated.item[0] = hdspm->tco->term; |
| 4203 | |
| 4204 | return 0; |
| 4205 | } |
| 4206 | |
| 4207 | |
| 4208 | static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4209 | struct snd_ctl_elem_value *ucontrol) |
| 4210 | { |
| 4211 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4212 | |
| 4213 | if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) { |
| 4214 | hdspm->tco->term = ucontrol->value.enumerated.item[0]; |
| 4215 | |
| 4216 | hdspm_tco_write(hdspm); |
| 4217 | |
| 4218 | return 1; |
| 4219 | } |
| 4220 | |
| 4221 | return 0; |
| 4222 | } |
| 4223 | |
| 4224 | |
| 4225 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4226 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4227 | static struct snd_kcontrol_new snd_hdspm_controls_madi[] = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4228 | HDSPM_MIXER("Mixer", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4229 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4230 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4231 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4232 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4233 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
Adrian Knoth | b8812c5 | 2012-10-19 17:42:26 +0200 | [diff] [blame] | 4234 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4235 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4236 | HDSPM_SYNC_CHECK("MADI SyncCheck", 1), |
Adrian Knoth | 930f4ff | 2012-10-19 17:42:29 +0200 | [diff] [blame] | 4237 | HDSPM_SYNC_CHECK("TCO SyncCheck", 2), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4238 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3), |
Adrian Knoth | c9e1668 | 2012-12-03 14:55:50 +0100 | [diff] [blame] | 4239 | HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), |
| 4240 | HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), |
Adrian Knoth | 696be0f | 2013-03-10 00:37:23 +0100 | [diff] [blame] | 4241 | HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX), |
Adrian Knoth | c9e1668 | 2012-12-03 14:55:50 +0100 | [diff] [blame] | 4242 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), |
| 4243 | HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 4244 | HDSPM_INPUT_SELECT("Input Select", 0), |
| 4245 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4246 | }; |
| 4247 | |
| 4248 | |
| 4249 | static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { |
| 4250 | HDSPM_MIXER("Mixer", 0), |
| 4251 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4252 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4253 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4254 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
| 4255 | HDSPM_SYNC_CHECK("MADI SyncCheck", 0), |
Adrian Knoth | c9e1668 | 2012-12-03 14:55:50 +0100 | [diff] [blame] | 4256 | HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), |
| 4257 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), |
| 4258 | HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 4259 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4260 | }; |
| 4261 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4262 | static struct snd_kcontrol_new snd_hdspm_controls_aio[] = { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4263 | HDSPM_MIXER("Mixer", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4264 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4265 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4266 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4267 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4268 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4269 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4270 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4271 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), |
| 4272 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), |
| 4273 | HDSPM_SYNC_CHECK("ADAT SyncCheck", 3), |
| 4274 | HDSPM_SYNC_CHECK("TCO SyncCheck", 4), |
| 4275 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5), |
| 4276 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4277 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), |
| 4278 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), |
| 4279 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3), |
| 4280 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4), |
| 4281 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5) |
| 4282 | |
| 4283 | /* |
| 4284 | HDSPM_INPUT_SELECT("Input Select", 0), |
| 4285 | HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0), |
| 4286 | HDSPM_PROFESSIONAL("SPDIF Out Professional", 0); |
| 4287 | HDSPM_SPDIF_IN("SPDIF In", 0); |
| 4288 | HDSPM_BREAKOUT_CABLE("Breakout Cable", 0); |
| 4289 | HDSPM_INPUT_LEVEL("Input Level", 0); |
| 4290 | HDSPM_OUTPUT_LEVEL("Output Level", 0); |
| 4291 | HDSPM_PHONES("Phones", 0); |
| 4292 | */ |
| 4293 | }; |
| 4294 | |
| 4295 | static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { |
| 4296 | HDSPM_MIXER("Mixer", 0), |
| 4297 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4298 | HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0), |
| 4299 | HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0), |
| 4300 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4301 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4302 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), |
| 4303 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), |
| 4304 | HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3), |
| 4305 | HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4), |
| 4306 | HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5), |
| 4307 | HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6), |
| 4308 | HDSPM_SYNC_CHECK("TCO SyncCheck", 7), |
| 4309 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8), |
| 4310 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4311 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), |
| 4312 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), |
| 4313 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3), |
| 4314 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4), |
| 4315 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5), |
| 4316 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6), |
| 4317 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7), |
| 4318 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8) |
| 4319 | }; |
| 4320 | |
| 4321 | static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { |
| 4322 | HDSPM_MIXER("Mixer", 0), |
| 4323 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4324 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4325 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4326 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4327 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4328 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
| 4329 | HDSPM_SYNC_CHECK("WC Sync Check", 0), |
| 4330 | HDSPM_SYNC_CHECK("AES1 Sync Check", 1), |
| 4331 | HDSPM_SYNC_CHECK("AES2 Sync Check", 2), |
| 4332 | HDSPM_SYNC_CHECK("AES3 Sync Check", 3), |
| 4333 | HDSPM_SYNC_CHECK("AES4 Sync Check", 4), |
| 4334 | HDSPM_SYNC_CHECK("AES5 Sync Check", 5), |
| 4335 | HDSPM_SYNC_CHECK("AES6 Sync Check", 6), |
| 4336 | HDSPM_SYNC_CHECK("AES7 Sync Check", 7), |
| 4337 | HDSPM_SYNC_CHECK("AES8 Sync Check", 8), |
| 4338 | HDSPM_SYNC_CHECK("TCO Sync Check", 9), |
| 4339 | HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10), |
| 4340 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4341 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1), |
| 4342 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2), |
| 4343 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3), |
| 4344 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4), |
| 4345 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5), |
| 4346 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6), |
| 4347 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7), |
| 4348 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8), |
| 4349 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9), |
| 4350 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10), |
Adrian Knoth | c9e1668 | 2012-12-03 14:55:50 +0100 | [diff] [blame] | 4351 | HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), |
| 4352 | HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis), |
| 4353 | HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby), |
| 4354 | HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional), |
| 4355 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4356 | HDSPM_DS_WIRE("Double Speed Wire Mode", 0), |
| 4357 | HDSPM_QS_WIRE("Quad Speed Wire Mode", 0), |
| 4358 | }; |
| 4359 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4360 | |
| 4361 | |
| 4362 | /* Control elements for the optional TCO module */ |
| 4363 | static struct snd_kcontrol_new snd_hdspm_controls_tco[] = { |
| 4364 | HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0), |
| 4365 | HDSPM_TCO_PULL("TCO Pull", 0), |
| 4366 | HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), |
| 4367 | HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0), |
| 4368 | HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0), |
| 4369 | HDSPM_TCO_WORD_TERM("TCO Word Term", 0) |
| 4370 | }; |
| 4371 | |
| 4372 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4373 | static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4374 | |
| 4375 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4376 | static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4377 | { |
| 4378 | int i; |
| 4379 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4380 | for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4381 | if (hdspm->system_sample_rate > 48000) { |
| 4382 | hdspm->playback_mixer_ctls[i]->vd[0].access = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4383 | SNDRV_CTL_ELEM_ACCESS_INACTIVE | |
| 4384 | SNDRV_CTL_ELEM_ACCESS_READ | |
| 4385 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4386 | } else { |
| 4387 | hdspm->playback_mixer_ctls[i]->vd[0].access = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4388 | SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 4389 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4390 | } |
| 4391 | snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4392 | SNDRV_CTL_EVENT_MASK_INFO, |
| 4393 | &hdspm->playback_mixer_ctls[i]->id); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | return 0; |
| 4397 | } |
| 4398 | |
| 4399 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4400 | static int snd_hdspm_create_controls(struct snd_card *card, |
| 4401 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4402 | { |
| 4403 | unsigned int idx, limit; |
| 4404 | int err; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4405 | struct snd_kcontrol *kctl; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4406 | struct snd_kcontrol_new *list = NULL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4407 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4408 | switch (hdspm->io_type) { |
| 4409 | case MADI: |
| 4410 | list = snd_hdspm_controls_madi; |
| 4411 | limit = ARRAY_SIZE(snd_hdspm_controls_madi); |
| 4412 | break; |
| 4413 | case MADIface: |
| 4414 | list = snd_hdspm_controls_madiface; |
| 4415 | limit = ARRAY_SIZE(snd_hdspm_controls_madiface); |
| 4416 | break; |
| 4417 | case AIO: |
| 4418 | list = snd_hdspm_controls_aio; |
| 4419 | limit = ARRAY_SIZE(snd_hdspm_controls_aio); |
| 4420 | break; |
| 4421 | case RayDAT: |
| 4422 | list = snd_hdspm_controls_raydat; |
| 4423 | limit = ARRAY_SIZE(snd_hdspm_controls_raydat); |
| 4424 | break; |
| 4425 | case AES32: |
| 4426 | list = snd_hdspm_controls_aes32; |
| 4427 | limit = ARRAY_SIZE(snd_hdspm_controls_aes32); |
| 4428 | break; |
| 4429 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4430 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4431 | if (NULL != list) { |
| 4432 | for (idx = 0; idx < limit; idx++) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4433 | err = snd_ctl_add(card, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4434 | snd_ctl_new1(&list[idx], hdspm)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4435 | if (err < 0) |
| 4436 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4437 | } |
| 4438 | } |
| 4439 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4440 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4441 | /* create simple 1:1 playback mixer controls */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4442 | snd_hdspm_playback_mixer.name = "Chn"; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4443 | if (hdspm->system_sample_rate >= 128000) { |
| 4444 | limit = hdspm->qs_out_channels; |
| 4445 | } else if (hdspm->system_sample_rate >= 64000) { |
| 4446 | limit = hdspm->ds_out_channels; |
| 4447 | } else { |
| 4448 | limit = hdspm->ss_out_channels; |
| 4449 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4450 | for (idx = 0; idx < limit; ++idx) { |
| 4451 | snd_hdspm_playback_mixer.index = idx + 1; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4452 | kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm); |
| 4453 | err = snd_ctl_add(card, kctl); |
| 4454 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4455 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4456 | hdspm->playback_mixer_ctls[idx] = kctl; |
| 4457 | } |
| 4458 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4459 | |
| 4460 | if (hdspm->tco) { |
| 4461 | /* add tco control elements */ |
| 4462 | list = snd_hdspm_controls_tco; |
| 4463 | limit = ARRAY_SIZE(snd_hdspm_controls_tco); |
| 4464 | for (idx = 0; idx < limit; idx++) { |
| 4465 | err = snd_ctl_add(card, |
| 4466 | snd_ctl_new1(&list[idx], hdspm)); |
| 4467 | if (err < 0) |
| 4468 | return err; |
| 4469 | } |
| 4470 | } |
| 4471 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4472 | return 0; |
| 4473 | } |
| 4474 | |
| 4475 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4476 | /proc interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4477 | ------------------------------------------------------------*/ |
| 4478 | |
| 4479 | static void |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4480 | snd_hdspm_proc_read_madi(struct snd_info_entry * entry, |
| 4481 | struct snd_info_buffer *buffer) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4482 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4483 | struct hdspm *hdspm = entry->private_data; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4484 | unsigned int status, status2, control, freq; |
| 4485 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4486 | char *pref_sync_ref; |
| 4487 | char *autosync_ref; |
| 4488 | char *system_clock_mode; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4489 | char *insel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4490 | int x, x2; |
| 4491 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4492 | /* TCO stuff */ |
| 4493 | int a, ltc, frames, seconds, minutes, hours; |
| 4494 | unsigned int period; |
| 4495 | u64 freq_const = 0; |
| 4496 | u32 rate; |
| 4497 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4498 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 4499 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4500 | control = hdspm->control_register; |
| 4501 | freq = hdspm_read(hdspm, HDSPM_timecodeRegister); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4502 | |
| 4503 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4504 | hdspm->card_name, hdspm->card->number + 1, |
| 4505 | hdspm->firmware_rev, |
| 4506 | (status2 & HDSPM_version0) | |
| 4507 | (status2 & HDSPM_version1) | (status2 & |
| 4508 | HDSPM_version2)); |
| 4509 | |
| 4510 | snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n", |
| 4511 | (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF, |
Adrian Knoth | 7d53a63 | 2012-01-04 14:31:16 +0100 | [diff] [blame] | 4512 | hdspm->serial); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4513 | |
| 4514 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4515 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4516 | |
| 4517 | snd_iprintf(buffer, "--- System ---\n"); |
| 4518 | |
| 4519 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4520 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", |
| 4521 | status & HDSPM_audioIRQPending, |
| 4522 | (status & HDSPM_midi0IRQPending) ? 1 : 0, |
| 4523 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
| 4524 | hdspm->irq_count); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4525 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4526 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
| 4527 | "estimated= %ld (bytes)\n", |
| 4528 | ((status & HDSPM_BufferID) ? 1 : 0), |
| 4529 | (status & HDSPM_BufferPositionMask), |
| 4530 | (status & HDSPM_BufferPositionMask) % |
| 4531 | (2 * (int)hdspm->period_bytes), |
| 4532 | ((status & HDSPM_BufferPositionMask) - 64) % |
| 4533 | (2 * (int)hdspm->period_bytes), |
| 4534 | (long) hdspm_hw_pointer(hdspm) * 4); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4535 | |
| 4536 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4537 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", |
| 4538 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, |
| 4539 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, |
| 4540 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
| 4541 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4542 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4543 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
| 4544 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, |
| 4545 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); |
| 4546 | snd_iprintf(buffer, |
| 4547 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " |
| 4548 | "status2=0x%x\n", |
| 4549 | hdspm->control_register, hdspm->control2_register, |
| 4550 | status, status2); |
| 4551 | if (status & HDSPM_tco_detect) { |
| 4552 | snd_iprintf(buffer, "TCO module detected.\n"); |
| 4553 | a = hdspm_read(hdspm, HDSPM_RD_TCO+4); |
| 4554 | if (a & HDSPM_TCO1_LTC_Input_valid) { |
| 4555 | snd_iprintf(buffer, " LTC valid, "); |
| 4556 | switch (a & (HDSPM_TCO1_LTC_Format_LSB | |
| 4557 | HDSPM_TCO1_LTC_Format_MSB)) { |
| 4558 | case 0: |
| 4559 | snd_iprintf(buffer, "24 fps, "); |
| 4560 | break; |
| 4561 | case HDSPM_TCO1_LTC_Format_LSB: |
| 4562 | snd_iprintf(buffer, "25 fps, "); |
| 4563 | break; |
| 4564 | case HDSPM_TCO1_LTC_Format_MSB: |
| 4565 | snd_iprintf(buffer, "29.97 fps, "); |
| 4566 | break; |
| 4567 | default: |
| 4568 | snd_iprintf(buffer, "30 fps, "); |
| 4569 | break; |
| 4570 | } |
| 4571 | if (a & HDSPM_TCO1_set_drop_frame_flag) { |
| 4572 | snd_iprintf(buffer, "drop frame\n"); |
| 4573 | } else { |
| 4574 | snd_iprintf(buffer, "full frame\n"); |
| 4575 | } |
| 4576 | } else { |
| 4577 | snd_iprintf(buffer, " no LTC\n"); |
| 4578 | } |
| 4579 | if (a & HDSPM_TCO1_Video_Input_Format_NTSC) { |
| 4580 | snd_iprintf(buffer, " Video: NTSC\n"); |
| 4581 | } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) { |
| 4582 | snd_iprintf(buffer, " Video: PAL\n"); |
| 4583 | } else { |
| 4584 | snd_iprintf(buffer, " No video\n"); |
| 4585 | } |
| 4586 | if (a & HDSPM_TCO1_TCO_lock) { |
| 4587 | snd_iprintf(buffer, " Sync: lock\n"); |
| 4588 | } else { |
| 4589 | snd_iprintf(buffer, " Sync: no lock\n"); |
| 4590 | } |
| 4591 | |
| 4592 | switch (hdspm->io_type) { |
| 4593 | case MADI: |
| 4594 | case AES32: |
| 4595 | freq_const = 110069313433624ULL; |
| 4596 | break; |
| 4597 | case RayDAT: |
| 4598 | case AIO: |
| 4599 | freq_const = 104857600000000ULL; |
| 4600 | break; |
| 4601 | case MADIface: |
| 4602 | break; /* no TCO possible */ |
| 4603 | } |
| 4604 | |
| 4605 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 4606 | snd_iprintf(buffer, " period: %u\n", period); |
| 4607 | |
| 4608 | |
| 4609 | /* rate = freq_const/period; */ |
| 4610 | rate = div_u64(freq_const, period); |
| 4611 | |
| 4612 | if (control & HDSPM_QuadSpeed) { |
| 4613 | rate *= 4; |
| 4614 | } else if (control & HDSPM_DoubleSpeed) { |
| 4615 | rate *= 2; |
| 4616 | } |
| 4617 | |
| 4618 | snd_iprintf(buffer, " Frequency: %u Hz\n", |
| 4619 | (unsigned int) rate); |
| 4620 | |
| 4621 | ltc = hdspm_read(hdspm, HDSPM_RD_TCO); |
| 4622 | frames = ltc & 0xF; |
| 4623 | ltc >>= 4; |
| 4624 | frames += (ltc & 0x3) * 10; |
| 4625 | ltc >>= 4; |
| 4626 | seconds = ltc & 0xF; |
| 4627 | ltc >>= 4; |
| 4628 | seconds += (ltc & 0x7) * 10; |
| 4629 | ltc >>= 4; |
| 4630 | minutes = ltc & 0xF; |
| 4631 | ltc >>= 4; |
| 4632 | minutes += (ltc & 0x7) * 10; |
| 4633 | ltc >>= 4; |
| 4634 | hours = ltc & 0xF; |
| 4635 | ltc >>= 4; |
| 4636 | hours += (ltc & 0x3) * 10; |
| 4637 | snd_iprintf(buffer, |
| 4638 | " LTC In: %02d:%02d:%02d:%02d\n", |
| 4639 | hours, minutes, seconds, frames); |
| 4640 | |
| 4641 | } else { |
| 4642 | snd_iprintf(buffer, "No TCO module detected.\n"); |
| 4643 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4644 | |
| 4645 | snd_iprintf(buffer, "--- Settings ---\n"); |
| 4646 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 4647 | x = hdspm_get_latency(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4648 | |
| 4649 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4650 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
| 4651 | x, (unsigned long) hdspm->period_bytes); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4652 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4653 | snd_iprintf(buffer, "Line out: %s\n", |
| 4654 | (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4655 | |
| 4656 | switch (hdspm->control_register & HDSPM_InputMask) { |
| 4657 | case HDSPM_InputOptical: |
| 4658 | insel = "Optical"; |
| 4659 | break; |
| 4660 | case HDSPM_InputCoaxial: |
| 4661 | insel = "Coaxial"; |
| 4662 | break; |
| 4663 | default: |
Masanari Iida | ec8f53f | 2012-11-02 00:28:50 +0900 | [diff] [blame] | 4664 | insel = "Unknown"; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4665 | } |
| 4666 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4667 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4668 | "ClearTrackMarker = %s, Transmit in %s Channel Mode, " |
| 4669 | "Auto Input %s\n", |
| 4670 | (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off", |
| 4671 | (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56", |
| 4672 | (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4673 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4674 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4675 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4676 | system_clock_mode = "AutoSync"; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4677 | else |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4678 | system_clock_mode = "Master"; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4679 | snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4680 | |
| 4681 | switch (hdspm_pref_sync_ref(hdspm)) { |
| 4682 | case HDSPM_SYNC_FROM_WORD: |
| 4683 | pref_sync_ref = "Word Clock"; |
| 4684 | break; |
| 4685 | case HDSPM_SYNC_FROM_MADI: |
| 4686 | pref_sync_ref = "MADI Sync"; |
| 4687 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4688 | case HDSPM_SYNC_FROM_TCO: |
| 4689 | pref_sync_ref = "TCO"; |
| 4690 | break; |
| 4691 | case HDSPM_SYNC_FROM_SYNC_IN: |
| 4692 | pref_sync_ref = "Sync In"; |
| 4693 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4694 | default: |
| 4695 | pref_sync_ref = "XXXX Clock"; |
| 4696 | break; |
| 4697 | } |
| 4698 | snd_iprintf(buffer, "Preferred Sync Reference: %s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4699 | pref_sync_ref); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4700 | |
| 4701 | snd_iprintf(buffer, "System Clock Frequency: %d\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4702 | hdspm->system_sample_rate); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4703 | |
| 4704 | |
| 4705 | snd_iprintf(buffer, "--- Status:\n"); |
| 4706 | |
| 4707 | x = status & HDSPM_madiSync; |
| 4708 | x2 = status2 & HDSPM_wcSync; |
| 4709 | |
| 4710 | snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4711 | (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") : |
| 4712 | "NoLock", |
| 4713 | (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") : |
| 4714 | "NoLock"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4715 | |
| 4716 | switch (hdspm_autosync_ref(hdspm)) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4717 | case HDSPM_AUTOSYNC_FROM_SYNC_IN: |
| 4718 | autosync_ref = "Sync In"; |
| 4719 | break; |
| 4720 | case HDSPM_AUTOSYNC_FROM_TCO: |
| 4721 | autosync_ref = "TCO"; |
| 4722 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4723 | case HDSPM_AUTOSYNC_FROM_WORD: |
| 4724 | autosync_ref = "Word Clock"; |
| 4725 | break; |
| 4726 | case HDSPM_AUTOSYNC_FROM_MADI: |
| 4727 | autosync_ref = "MADI Sync"; |
| 4728 | break; |
| 4729 | case HDSPM_AUTOSYNC_FROM_NONE: |
| 4730 | autosync_ref = "Input not valid"; |
| 4731 | break; |
| 4732 | default: |
| 4733 | autosync_ref = "---"; |
| 4734 | break; |
| 4735 | } |
| 4736 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4737 | "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n", |
| 4738 | autosync_ref, hdspm_external_sample_rate(hdspm), |
| 4739 | (status & HDSPM_madiFreqMask) >> 22, |
| 4740 | (status2 & HDSPM_wcFreqMask) >> 5); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4741 | |
| 4742 | snd_iprintf(buffer, "Input: %s, Mode=%s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4743 | (status & HDSPM_AB_int) ? "Coax" : "Optical", |
| 4744 | (status & HDSPM_RX_64ch) ? "64 channels" : |
| 4745 | "56 channels"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4746 | |
| 4747 | snd_iprintf(buffer, "\n"); |
| 4748 | } |
| 4749 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4750 | static void |
| 4751 | snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, |
| 4752 | struct snd_info_buffer *buffer) |
| 4753 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4754 | struct hdspm *hdspm = entry->private_data; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4755 | unsigned int status; |
| 4756 | unsigned int status2; |
| 4757 | unsigned int timecode; |
Andre Schramm | 56bde0f | 2013-01-09 14:40:18 +0100 | [diff] [blame] | 4758 | unsigned int wcLock, wcSync; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4759 | int pref_syncref; |
| 4760 | char *autosync_ref; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4761 | int x; |
| 4762 | |
| 4763 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 4764 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 4765 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); |
| 4766 | |
| 4767 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n", |
| 4768 | hdspm->card_name, hdspm->card->number + 1, |
| 4769 | hdspm->firmware_rev); |
| 4770 | |
| 4771 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", |
| 4772 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); |
| 4773 | |
| 4774 | snd_iprintf(buffer, "--- System ---\n"); |
| 4775 | |
| 4776 | snd_iprintf(buffer, |
| 4777 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", |
| 4778 | status & HDSPM_audioIRQPending, |
| 4779 | (status & HDSPM_midi0IRQPending) ? 1 : 0, |
| 4780 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
| 4781 | hdspm->irq_count); |
| 4782 | snd_iprintf(buffer, |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4783 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
| 4784 | "estimated= %ld (bytes)\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4785 | ((status & HDSPM_BufferID) ? 1 : 0), |
| 4786 | (status & HDSPM_BufferPositionMask), |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4787 | (status & HDSPM_BufferPositionMask) % |
| 4788 | (2 * (int)hdspm->period_bytes), |
| 4789 | ((status & HDSPM_BufferPositionMask) - 64) % |
| 4790 | (2 * (int)hdspm->period_bytes), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4791 | (long) hdspm_hw_pointer(hdspm) * 4); |
| 4792 | |
| 4793 | snd_iprintf(buffer, |
| 4794 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", |
| 4795 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, |
| 4796 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, |
| 4797 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
| 4798 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
| 4799 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4800 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
| 4801 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, |
| 4802 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); |
| 4803 | snd_iprintf(buffer, |
| 4804 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " |
| 4805 | "status2=0x%x\n", |
| 4806 | hdspm->control_register, hdspm->control2_register, |
| 4807 | status, status2); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4808 | |
| 4809 | snd_iprintf(buffer, "--- Settings ---\n"); |
| 4810 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 4811 | x = hdspm_get_latency(hdspm); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4812 | |
| 4813 | snd_iprintf(buffer, |
| 4814 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
| 4815 | x, (unsigned long) hdspm->period_bytes); |
| 4816 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4817 | snd_iprintf(buffer, "Line out: %s\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4818 | (hdspm-> |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4819 | control_register & HDSPM_LineOut) ? "on " : "off"); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4820 | |
| 4821 | snd_iprintf(buffer, |
| 4822 | "ClearTrackMarker %s, Emphasis %s, Dolby %s\n", |
| 4823 | (hdspm-> |
| 4824 | control_register & HDSPM_clr_tms) ? "on" : "off", |
| 4825 | (hdspm-> |
| 4826 | control_register & HDSPM_Emphasis) ? "on" : "off", |
| 4827 | (hdspm-> |
| 4828 | control_register & HDSPM_Dolby) ? "on" : "off"); |
| 4829 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4830 | |
| 4831 | pref_syncref = hdspm_pref_sync_ref(hdspm); |
| 4832 | if (pref_syncref == 0) |
| 4833 | snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n"); |
| 4834 | else |
| 4835 | snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n", |
| 4836 | pref_syncref); |
| 4837 | |
| 4838 | snd_iprintf(buffer, "System Clock Frequency: %d\n", |
| 4839 | hdspm->system_sample_rate); |
| 4840 | |
| 4841 | snd_iprintf(buffer, "Double speed: %s\n", |
| 4842 | hdspm->control_register & HDSPM_DS_DoubleWire? |
| 4843 | "Double wire" : "Single wire"); |
| 4844 | snd_iprintf(buffer, "Quad speed: %s\n", |
| 4845 | hdspm->control_register & HDSPM_QS_DoubleWire? |
| 4846 | "Double wire" : |
| 4847 | hdspm->control_register & HDSPM_QS_QuadWire? |
| 4848 | "Quad wire" : "Single wire"); |
| 4849 | |
| 4850 | snd_iprintf(buffer, "--- Status:\n"); |
| 4851 | |
Andre Schramm | 56bde0f | 2013-01-09 14:40:18 +0100 | [diff] [blame] | 4852 | wcLock = status & HDSPM_AES32_wcLock; |
| 4853 | wcSync = wcLock && (status & HDSPM_AES32_wcSync); |
| 4854 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4855 | snd_iprintf(buffer, "Word: %s Frequency: %d\n", |
Andre Schramm | 56bde0f | 2013-01-09 14:40:18 +0100 | [diff] [blame] | 4856 | (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4857 | HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4858 | |
| 4859 | for (x = 0; x < 8; x++) { |
| 4860 | snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4861 | x+1, |
| 4862 | (status2 & (HDSPM_LockAES >> x)) ? |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4863 | "Sync " : "No Lock", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4864 | HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | switch (hdspm_autosync_ref(hdspm)) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4868 | case HDSPM_AES32_AUTOSYNC_FROM_NONE: |
| 4869 | autosync_ref = "None"; break; |
| 4870 | case HDSPM_AES32_AUTOSYNC_FROM_WORD: |
| 4871 | autosync_ref = "Word Clock"; break; |
| 4872 | case HDSPM_AES32_AUTOSYNC_FROM_AES1: |
| 4873 | autosync_ref = "AES1"; break; |
| 4874 | case HDSPM_AES32_AUTOSYNC_FROM_AES2: |
| 4875 | autosync_ref = "AES2"; break; |
| 4876 | case HDSPM_AES32_AUTOSYNC_FROM_AES3: |
| 4877 | autosync_ref = "AES3"; break; |
| 4878 | case HDSPM_AES32_AUTOSYNC_FROM_AES4: |
| 4879 | autosync_ref = "AES4"; break; |
| 4880 | case HDSPM_AES32_AUTOSYNC_FROM_AES5: |
| 4881 | autosync_ref = "AES5"; break; |
| 4882 | case HDSPM_AES32_AUTOSYNC_FROM_AES6: |
| 4883 | autosync_ref = "AES6"; break; |
| 4884 | case HDSPM_AES32_AUTOSYNC_FROM_AES7: |
| 4885 | autosync_ref = "AES7"; break; |
| 4886 | case HDSPM_AES32_AUTOSYNC_FROM_AES8: |
| 4887 | autosync_ref = "AES8"; break; |
| 4888 | default: |
| 4889 | autosync_ref = "---"; break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4890 | } |
| 4891 | snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref); |
| 4892 | |
| 4893 | snd_iprintf(buffer, "\n"); |
| 4894 | } |
| 4895 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4896 | static void |
| 4897 | snd_hdspm_proc_read_raydat(struct snd_info_entry *entry, |
| 4898 | struct snd_info_buffer *buffer) |
| 4899 | { |
| 4900 | struct hdspm *hdspm = entry->private_data; |
| 4901 | unsigned int status1, status2, status3, control, i; |
| 4902 | unsigned int lock, sync; |
| 4903 | |
| 4904 | status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */ |
| 4905 | status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */ |
| 4906 | status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */ |
| 4907 | |
| 4908 | control = hdspm->control_register; |
| 4909 | |
| 4910 | snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1); |
| 4911 | snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2); |
| 4912 | snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3); |
| 4913 | |
| 4914 | |
| 4915 | snd_iprintf(buffer, "\n*** CLOCK MODE\n\n"); |
| 4916 | |
| 4917 | snd_iprintf(buffer, "Clock mode : %s\n", |
| 4918 | (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave"); |
| 4919 | snd_iprintf(buffer, "System frequency: %d Hz\n", |
| 4920 | hdspm_get_system_sample_rate(hdspm)); |
| 4921 | |
| 4922 | snd_iprintf(buffer, "\n*** INPUT STATUS\n\n"); |
| 4923 | |
| 4924 | lock = 0x1; |
| 4925 | sync = 0x100; |
| 4926 | |
| 4927 | for (i = 0; i < 8; i++) { |
| 4928 | snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n", |
| 4929 | i, |
| 4930 | (status1 & lock) ? 1 : 0, |
| 4931 | (status1 & sync) ? 1 : 0, |
| 4932 | texts_freq[(status2 >> (i * 4)) & 0xF]); |
| 4933 | |
| 4934 | lock = lock<<1; |
| 4935 | sync = sync<<1; |
| 4936 | } |
| 4937 | |
| 4938 | snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n", |
| 4939 | (status1 & 0x1000000) ? 1 : 0, |
| 4940 | (status1 & 0x2000000) ? 1 : 0, |
| 4941 | texts_freq[(status1 >> 16) & 0xF]); |
| 4942 | |
| 4943 | snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n", |
| 4944 | (status1 & 0x4000000) ? 1 : 0, |
| 4945 | (status1 & 0x8000000) ? 1 : 0, |
| 4946 | texts_freq[(status1 >> 20) & 0xF]); |
| 4947 | |
| 4948 | snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n", |
| 4949 | (status3 & 0x400) ? 1 : 0, |
| 4950 | (status3 & 0x800) ? 1 : 0, |
| 4951 | texts_freq[(status2 >> 12) & 0xF]); |
| 4952 | |
| 4953 | } |
| 4954 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4955 | #ifdef CONFIG_SND_DEBUG |
| 4956 | static void |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4957 | snd_hdspm_proc_read_debug(struct snd_info_entry *entry, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4958 | struct snd_info_buffer *buffer) |
| 4959 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4960 | struct hdspm *hdspm = entry->private_data; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4961 | |
| 4962 | int j,i; |
| 4963 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4964 | for (i = 0; i < 256 /* 1024*64 */; i += j) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4965 | snd_iprintf(buffer, "0x%08X: ", i); |
| 4966 | for (j = 0; j < 16; j += 4) |
| 4967 | snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); |
| 4968 | snd_iprintf(buffer, "\n"); |
| 4969 | } |
| 4970 | } |
| 4971 | #endif |
| 4972 | |
| 4973 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4974 | static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry, |
| 4975 | struct snd_info_buffer *buffer) |
| 4976 | { |
| 4977 | struct hdspm *hdspm = entry->private_data; |
| 4978 | int i; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4979 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4980 | snd_iprintf(buffer, "# generated by hdspm\n"); |
| 4981 | |
| 4982 | for (i = 0; i < hdspm->max_channels_in; i++) { |
| 4983 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]); |
| 4984 | } |
| 4985 | } |
| 4986 | |
| 4987 | static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry, |
| 4988 | struct snd_info_buffer *buffer) |
| 4989 | { |
| 4990 | struct hdspm *hdspm = entry->private_data; |
| 4991 | int i; |
| 4992 | |
| 4993 | snd_iprintf(buffer, "# generated by hdspm\n"); |
| 4994 | |
| 4995 | for (i = 0; i < hdspm->max_channels_out; i++) { |
| 4996 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]); |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 5001 | static void snd_hdspm_proc_init(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5002 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5003 | struct snd_info_entry *entry; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5004 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5005 | if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) { |
| 5006 | switch (hdspm->io_type) { |
| 5007 | case AES32: |
| 5008 | snd_info_set_text_ops(entry, hdspm, |
| 5009 | snd_hdspm_proc_read_aes32); |
| 5010 | break; |
| 5011 | case MADI: |
| 5012 | snd_info_set_text_ops(entry, hdspm, |
| 5013 | snd_hdspm_proc_read_madi); |
| 5014 | break; |
| 5015 | case MADIface: |
| 5016 | /* snd_info_set_text_ops(entry, hdspm, |
| 5017 | snd_hdspm_proc_read_madiface); */ |
| 5018 | break; |
| 5019 | case RayDAT: |
| 5020 | snd_info_set_text_ops(entry, hdspm, |
| 5021 | snd_hdspm_proc_read_raydat); |
| 5022 | break; |
| 5023 | case AIO: |
| 5024 | break; |
| 5025 | } |
| 5026 | } |
| 5027 | |
| 5028 | if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) { |
| 5029 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in); |
| 5030 | } |
| 5031 | |
| 5032 | if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) { |
| 5033 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out); |
| 5034 | } |
| 5035 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5036 | #ifdef CONFIG_SND_DEBUG |
| 5037 | /* debug file to read all hdspm registers */ |
| 5038 | if (!snd_card_proc_new(hdspm->card, "debug", &entry)) |
| 5039 | snd_info_set_text_ops(entry, hdspm, |
| 5040 | snd_hdspm_proc_read_debug); |
| 5041 | #endif |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5045 | hdspm intitialize |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5046 | ------------------------------------------------------------*/ |
| 5047 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5048 | static int snd_hdspm_set_defaults(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5049 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5050 | /* ASSUMPTION: hdspm->lock is either held, or there is no need to |
Joe Perches | 561de31 | 2007-12-18 13:13:47 +0100 | [diff] [blame] | 5051 | hold it (e.g. during module initialization). |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5052 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5053 | |
| 5054 | /* set defaults: */ |
| 5055 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5056 | hdspm->settings_register = 0; |
| 5057 | |
| 5058 | switch (hdspm->io_type) { |
| 5059 | case MADI: |
| 5060 | case MADIface: |
| 5061 | hdspm->control_register = |
| 5062 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; |
| 5063 | break; |
| 5064 | |
| 5065 | case RayDAT: |
| 5066 | case AIO: |
| 5067 | hdspm->settings_register = 0x1 + 0x1000; |
| 5068 | /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0, |
| 5069 | * line_out */ |
| 5070 | hdspm->control_register = |
| 5071 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; |
| 5072 | break; |
| 5073 | |
| 5074 | case AES32: |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5075 | hdspm->control_register = |
| 5076 | HDSPM_ClockModeMaster | /* Master Cloack Mode on */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5077 | hdspm_encode_latency(7) | /* latency max=8192samples */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5078 | HDSPM_SyncRef0 | /* AES1 is syncclock */ |
| 5079 | HDSPM_LineOut | /* Analog output in */ |
| 5080 | HDSPM_Professional; /* Professional mode */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5081 | break; |
| 5082 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5083 | |
| 5084 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 5085 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5086 | if (AES32 == hdspm->io_type) { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5087 | /* No control2 register for AES32 */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5088 | #ifdef SNDRV_BIG_ENDIAN |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5089 | hdspm->control2_register = HDSPM_BIGENDIAN_MODE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5090 | #else |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5091 | hdspm->control2_register = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5092 | #endif |
| 5093 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5094 | hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register); |
| 5095 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5096 | hdspm_compute_period_size(hdspm); |
| 5097 | |
| 5098 | /* silence everything */ |
| 5099 | |
| 5100 | all_in_all_mixer(hdspm, 0 * UNITY_GAIN); |
| 5101 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5102 | if (hdspm->io_type == AIO || hdspm->io_type == RayDAT) { |
| 5103 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /* set a default rate so that the channel map is set up. */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5107 | hdspm_set_rate(hdspm, 48000, 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5108 | |
| 5109 | return 0; |
| 5110 | } |
| 5111 | |
| 5112 | |
| 5113 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5114 | interrupt |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5115 | ------------------------------------------------------------*/ |
| 5116 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5117 | static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5118 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5119 | struct hdspm *hdspm = (struct hdspm *) dev_id; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5120 | unsigned int status; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5121 | int i, audio, midi, schedule = 0; |
| 5122 | /* cycles_t now; */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5123 | |
| 5124 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 5125 | |
| 5126 | audio = status & HDSPM_audioIRQPending; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5127 | midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending | |
| 5128 | HDSPM_midi2IRQPending | HDSPM_midi3IRQPending); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5129 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5130 | /* now = get_cycles(); */ |
| 5131 | /** |
| 5132 | * LAT_2..LAT_0 period counter (win) counter (mac) |
| 5133 | * 6 4096 ~256053425 ~514672358 |
| 5134 | * 5 2048 ~128024983 ~257373821 |
| 5135 | * 4 1024 ~64023706 ~128718089 |
| 5136 | * 3 512 ~32005945 ~64385999 |
| 5137 | * 2 256 ~16003039 ~32260176 |
| 5138 | * 1 128 ~7998738 ~16194507 |
| 5139 | * 0 64 ~3998231 ~8191558 |
| 5140 | **/ |
| 5141 | /* |
| 5142 | snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n", |
| 5143 | now-hdspm->last_interrupt, status & 0xFFC0); |
| 5144 | hdspm->last_interrupt = now; |
| 5145 | */ |
| 5146 | |
| 5147 | if (!audio && !midi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5148 | return IRQ_NONE; |
| 5149 | |
| 5150 | hdspm_write(hdspm, HDSPM_interruptConfirmation, 0); |
| 5151 | hdspm->irq_count++; |
| 5152 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5153 | |
| 5154 | if (audio) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5155 | if (hdspm->capture_substream) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5156 | snd_pcm_period_elapsed(hdspm->capture_substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5157 | |
| 5158 | if (hdspm->playback_substream) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5159 | snd_pcm_period_elapsed(hdspm->playback_substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5160 | } |
| 5161 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5162 | if (midi) { |
| 5163 | i = 0; |
| 5164 | while (i < hdspm->midiPorts) { |
| 5165 | if ((hdspm_read(hdspm, |
| 5166 | hdspm->midi[i].statusIn) & 0xff) && |
| 5167 | (status & hdspm->midi[i].irq)) { |
| 5168 | /* we disable interrupts for this input until |
| 5169 | * processing is done |
| 5170 | */ |
| 5171 | hdspm->control_register &= ~hdspm->midi[i].ie; |
| 5172 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 5173 | hdspm->control_register); |
| 5174 | hdspm->midi[i].pending = 1; |
| 5175 | schedule = 1; |
| 5176 | } |
| 5177 | |
| 5178 | i++; |
| 5179 | } |
| 5180 | |
| 5181 | if (schedule) |
| 5182 | tasklet_hi_schedule(&hdspm->midi_tasklet); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5183 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5184 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5185 | return IRQ_HANDLED; |
| 5186 | } |
| 5187 | |
| 5188 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5189 | pcm interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5190 | ------------------------------------------------------------*/ |
| 5191 | |
| 5192 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5193 | static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream |
| 5194 | *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5195 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5196 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5197 | return hdspm_hw_pointer(hdspm); |
| 5198 | } |
| 5199 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5200 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5201 | static int snd_hdspm_reset(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5202 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5203 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 5204 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5205 | struct snd_pcm_substream *other; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5206 | |
| 5207 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 5208 | other = hdspm->capture_substream; |
| 5209 | else |
| 5210 | other = hdspm->playback_substream; |
| 5211 | |
| 5212 | if (hdspm->running) |
| 5213 | runtime->status->hw_ptr = hdspm_hw_pointer(hdspm); |
| 5214 | else |
| 5215 | runtime->status->hw_ptr = 0; |
| 5216 | if (other) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5217 | struct snd_pcm_substream *s; |
| 5218 | struct snd_pcm_runtime *oruntime = other->runtime; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 5219 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5220 | if (s == other) { |
| 5221 | oruntime->status->hw_ptr = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5222 | runtime->status->hw_ptr; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5223 | break; |
| 5224 | } |
| 5225 | } |
| 5226 | } |
| 5227 | return 0; |
| 5228 | } |
| 5229 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5230 | static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, |
| 5231 | struct snd_pcm_hw_params *params) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5232 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5233 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5234 | int err; |
| 5235 | int i; |
| 5236 | pid_t this_pid; |
| 5237 | pid_t other_pid; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5238 | |
| 5239 | spin_lock_irq(&hdspm->lock); |
| 5240 | |
| 5241 | if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5242 | this_pid = hdspm->playback_pid; |
| 5243 | other_pid = hdspm->capture_pid; |
| 5244 | } else { |
| 5245 | this_pid = hdspm->capture_pid; |
| 5246 | other_pid = hdspm->playback_pid; |
| 5247 | } |
| 5248 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5249 | if (other_pid > 0 && this_pid != other_pid) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5250 | |
| 5251 | /* The other stream is open, and not by the same |
| 5252 | task as this one. Make sure that the parameters |
| 5253 | that matter are the same. |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5254 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5255 | |
| 5256 | if (params_rate(params) != hdspm->system_sample_rate) { |
| 5257 | spin_unlock_irq(&hdspm->lock); |
| 5258 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5259 | SNDRV_PCM_HW_PARAM_RATE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5260 | return -EBUSY; |
| 5261 | } |
| 5262 | |
| 5263 | if (params_period_size(params) != hdspm->period_bytes / 4) { |
| 5264 | spin_unlock_irq(&hdspm->lock); |
| 5265 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5266 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5267 | return -EBUSY; |
| 5268 | } |
| 5269 | |
| 5270 | } |
| 5271 | /* We're fine. */ |
| 5272 | spin_unlock_irq(&hdspm->lock); |
| 5273 | |
| 5274 | /* how to make sure that the rate matches an externally-set one ? */ |
| 5275 | |
| 5276 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5277 | err = hdspm_set_rate(hdspm, params_rate(params), 0); |
| 5278 | if (err < 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5279 | snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5280 | spin_unlock_irq(&hdspm->lock); |
| 5281 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5282 | SNDRV_PCM_HW_PARAM_RATE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5283 | return err; |
| 5284 | } |
| 5285 | spin_unlock_irq(&hdspm->lock); |
| 5286 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5287 | err = hdspm_set_interrupt_interval(hdspm, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5288 | params_period_size(params)); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5289 | if (err < 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5290 | snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5291 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5292 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5293 | return err; |
| 5294 | } |
| 5295 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5296 | /* Memory allocation, takashi's method, dont know if we should |
| 5297 | * spinlock |
| 5298 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5299 | /* malloc all buffer even if not enabled to get sure */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5300 | /* Update for MADI rev 204: we need to allocate for all channels, |
| 5301 | * otherwise it doesn't work at 96kHz */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5302 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5303 | err = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5304 | snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES); |
| 5305 | if (err < 0) { |
| 5306 | snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5307 | return err; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5308 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5309 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5310 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5311 | |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5312 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5313 | params_channels(params)); |
| 5314 | |
| 5315 | for (i = 0; i < params_channels(params); ++i) |
| 5316 | snd_hdspm_enable_out(hdspm, i, 1); |
| 5317 | |
| 5318 | hdspm->playback_buffer = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5319 | (unsigned char *) substream->runtime->dma_area; |
Takashi Iwai | 54bf5dd | 2006-11-06 15:38:55 +0100 | [diff] [blame] | 5320 | snd_printdd("Allocated sample buffer for playback at %p\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5321 | hdspm->playback_buffer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5322 | } else { |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5323 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5324 | params_channels(params)); |
| 5325 | |
| 5326 | for (i = 0; i < params_channels(params); ++i) |
| 5327 | snd_hdspm_enable_in(hdspm, i, 1); |
| 5328 | |
| 5329 | hdspm->capture_buffer = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5330 | (unsigned char *) substream->runtime->dma_area; |
Takashi Iwai | 54bf5dd | 2006-11-06 15:38:55 +0100 | [diff] [blame] | 5331 | snd_printdd("Allocated sample buffer for capture at %p\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5332 | hdspm->capture_buffer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5333 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5334 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5335 | /* |
| 5336 | snd_printdd("Allocated sample buffer for %s at 0x%08X\n", |
| 5337 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 5338 | "playback" : "capture", |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5339 | snd_pcm_sgbuf_get_addr(substream, 0)); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5340 | */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5341 | /* |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5342 | snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", |
| 5343 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 5344 | "playback" : "capture", |
| 5345 | params_rate(params), params_channels(params), |
| 5346 | params_buffer_size(params)); |
| 5347 | */ |
| 5348 | |
| 5349 | |
| 5350 | /* Switch to native float format if requested */ |
| 5351 | if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) { |
| 5352 | if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT)) |
| 5353 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n"); |
| 5354 | |
| 5355 | hdspm->control_register |= HDSPe_FLOAT_FORMAT; |
| 5356 | } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) { |
| 5357 | if (hdspm->control_register & HDSPe_FLOAT_FORMAT) |
| 5358 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n"); |
| 5359 | |
| 5360 | hdspm->control_register &= ~HDSPe_FLOAT_FORMAT; |
| 5361 | } |
| 5362 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 5363 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5364 | return 0; |
| 5365 | } |
| 5366 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5367 | static int snd_hdspm_hw_free(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5368 | { |
| 5369 | int i; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5370 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5371 | |
| 5372 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5373 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5374 | /* params_channels(params) should be enough, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5375 | but to get sure in case of error */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5376 | for (i = 0; i < hdspm->max_channels_out; ++i) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5377 | snd_hdspm_enable_out(hdspm, i, 0); |
| 5378 | |
| 5379 | hdspm->playback_buffer = NULL; |
| 5380 | } else { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5381 | for (i = 0; i < hdspm->max_channels_in; ++i) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5382 | snd_hdspm_enable_in(hdspm, i, 0); |
| 5383 | |
| 5384 | hdspm->capture_buffer = NULL; |
| 5385 | |
| 5386 | } |
| 5387 | |
| 5388 | snd_pcm_lib_free_pages(substream); |
| 5389 | |
| 5390 | return 0; |
| 5391 | } |
| 5392 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5393 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5394 | static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5395 | struct snd_pcm_channel_info *info) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5396 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5397 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5398 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5399 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5400 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) { |
| 5401 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel); |
| 5402 | return -EINVAL; |
| 5403 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5404 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5405 | if (hdspm->channel_map_out[info->channel] < 0) { |
| 5406 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel); |
| 5407 | return -EINVAL; |
| 5408 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5409 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5410 | info->offset = hdspm->channel_map_out[info->channel] * |
| 5411 | HDSPM_CHANNEL_BUFFER_BYTES; |
| 5412 | } else { |
| 5413 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) { |
| 5414 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel); |
| 5415 | return -EINVAL; |
| 5416 | } |
| 5417 | |
| 5418 | if (hdspm->channel_map_in[info->channel] < 0) { |
| 5419 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel); |
| 5420 | return -EINVAL; |
| 5421 | } |
| 5422 | |
| 5423 | info->offset = hdspm->channel_map_in[info->channel] * |
| 5424 | HDSPM_CHANNEL_BUFFER_BYTES; |
| 5425 | } |
| 5426 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5427 | info->first = 0; |
| 5428 | info->step = 32; |
| 5429 | return 0; |
| 5430 | } |
| 5431 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5432 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5433 | static int snd_hdspm_ioctl(struct snd_pcm_substream *substream, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5434 | unsigned int cmd, void *arg) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5435 | { |
| 5436 | switch (cmd) { |
| 5437 | case SNDRV_PCM_IOCTL1_RESET: |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5438 | return snd_hdspm_reset(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5439 | |
| 5440 | case SNDRV_PCM_IOCTL1_CHANNEL_INFO: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5441 | { |
| 5442 | struct snd_pcm_channel_info *info = arg; |
| 5443 | return snd_hdspm_channel_info(substream, info); |
| 5444 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5445 | default: |
| 5446 | break; |
| 5447 | } |
| 5448 | |
| 5449 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 5450 | } |
| 5451 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5452 | static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5453 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5454 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5455 | struct snd_pcm_substream *other; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5456 | int running; |
| 5457 | |
| 5458 | spin_lock(&hdspm->lock); |
| 5459 | running = hdspm->running; |
| 5460 | switch (cmd) { |
| 5461 | case SNDRV_PCM_TRIGGER_START: |
| 5462 | running |= 1 << substream->stream; |
| 5463 | break; |
| 5464 | case SNDRV_PCM_TRIGGER_STOP: |
| 5465 | running &= ~(1 << substream->stream); |
| 5466 | break; |
| 5467 | default: |
| 5468 | snd_BUG(); |
| 5469 | spin_unlock(&hdspm->lock); |
| 5470 | return -EINVAL; |
| 5471 | } |
| 5472 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 5473 | other = hdspm->capture_substream; |
| 5474 | else |
| 5475 | other = hdspm->playback_substream; |
| 5476 | |
| 5477 | if (other) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5478 | struct snd_pcm_substream *s; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 5479 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5480 | if (s == other) { |
| 5481 | snd_pcm_trigger_done(s, substream); |
| 5482 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 5483 | running |= 1 << s->stream; |
| 5484 | else |
| 5485 | running &= ~(1 << s->stream); |
| 5486 | goto _ok; |
| 5487 | } |
| 5488 | } |
| 5489 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 5490 | if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5491 | && substream->stream == |
| 5492 | SNDRV_PCM_STREAM_CAPTURE) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5493 | hdspm_silence_playback(hdspm); |
| 5494 | } else { |
| 5495 | if (running && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5496 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5497 | hdspm_silence_playback(hdspm); |
| 5498 | } |
| 5499 | } else { |
| 5500 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 5501 | hdspm_silence_playback(hdspm); |
| 5502 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5503 | _ok: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5504 | snd_pcm_trigger_done(substream, substream); |
| 5505 | if (!hdspm->running && running) |
| 5506 | hdspm_start_audio(hdspm); |
| 5507 | else if (hdspm->running && !running) |
| 5508 | hdspm_stop_audio(hdspm); |
| 5509 | hdspm->running = running; |
| 5510 | spin_unlock(&hdspm->lock); |
| 5511 | |
| 5512 | return 0; |
| 5513 | } |
| 5514 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5515 | static int snd_hdspm_prepare(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5516 | { |
| 5517 | return 0; |
| 5518 | } |
| 5519 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5520 | static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5521 | .info = (SNDRV_PCM_INFO_MMAP | |
| 5522 | SNDRV_PCM_INFO_MMAP_VALID | |
| 5523 | SNDRV_PCM_INFO_NONINTERLEAVED | |
| 5524 | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), |
| 5525 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 5526 | .rates = (SNDRV_PCM_RATE_32000 | |
| 5527 | SNDRV_PCM_RATE_44100 | |
| 5528 | SNDRV_PCM_RATE_48000 | |
| 5529 | SNDRV_PCM_RATE_64000 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5530 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
| 5531 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5532 | .rate_min = 32000, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5533 | .rate_max = 192000, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5534 | .channels_min = 1, |
| 5535 | .channels_max = HDSPM_MAX_CHANNELS, |
| 5536 | .buffer_bytes_max = |
| 5537 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
Adrian Knoth | 1b6fa10 | 2011-08-15 00:22:51 +0200 | [diff] [blame] | 5538 | .period_bytes_min = (32 * 4), |
Takashi Iwai | 52e6fb4 | 2011-08-15 10:40:59 +0200 | [diff] [blame] | 5539 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5540 | .periods_min = 2, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5541 | .periods_max = 512, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5542 | .fifo_size = 0 |
| 5543 | }; |
| 5544 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5545 | static struct snd_pcm_hardware snd_hdspm_capture_subinfo = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5546 | .info = (SNDRV_PCM_INFO_MMAP | |
| 5547 | SNDRV_PCM_INFO_MMAP_VALID | |
| 5548 | SNDRV_PCM_INFO_NONINTERLEAVED | |
| 5549 | SNDRV_PCM_INFO_SYNC_START), |
| 5550 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 5551 | .rates = (SNDRV_PCM_RATE_32000 | |
| 5552 | SNDRV_PCM_RATE_44100 | |
| 5553 | SNDRV_PCM_RATE_48000 | |
| 5554 | SNDRV_PCM_RATE_64000 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5555 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
| 5556 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5557 | .rate_min = 32000, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5558 | .rate_max = 192000, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5559 | .channels_min = 1, |
| 5560 | .channels_max = HDSPM_MAX_CHANNELS, |
| 5561 | .buffer_bytes_max = |
| 5562 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
Adrian Knoth | 1b6fa10 | 2011-08-15 00:22:51 +0200 | [diff] [blame] | 5563 | .period_bytes_min = (32 * 4), |
Takashi Iwai | 52e6fb4 | 2011-08-15 10:40:59 +0200 | [diff] [blame] | 5564 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5565 | .periods_min = 2, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5566 | .periods_max = 512, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5567 | .fifo_size = 0 |
| 5568 | }; |
| 5569 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5570 | static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, |
| 5571 | struct snd_pcm_hw_rule *rule) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5572 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5573 | struct hdspm *hdspm = rule->private; |
| 5574 | struct snd_interval *c = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5575 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5576 | struct snd_interval *r = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5577 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5578 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5579 | if (r->min > 96000 && r->max <= 192000) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5580 | struct snd_interval t = { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5581 | .min = hdspm->qs_in_channels, |
| 5582 | .max = hdspm->qs_in_channels, |
| 5583 | .integer = 1, |
| 5584 | }; |
| 5585 | return snd_interval_refine(c, &t); |
| 5586 | } else if (r->min > 48000 && r->max <= 96000) { |
| 5587 | struct snd_interval t = { |
| 5588 | .min = hdspm->ds_in_channels, |
| 5589 | .max = hdspm->ds_in_channels, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5590 | .integer = 1, |
| 5591 | }; |
| 5592 | return snd_interval_refine(c, &t); |
| 5593 | } else if (r->max < 64000) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5594 | struct snd_interval t = { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5595 | .min = hdspm->ss_in_channels, |
| 5596 | .max = hdspm->ss_in_channels, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5597 | .integer = 1, |
| 5598 | }; |
| 5599 | return snd_interval_refine(c, &t); |
| 5600 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5601 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5602 | return 0; |
| 5603 | } |
| 5604 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5605 | static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params, |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5606 | struct snd_pcm_hw_rule * rule) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5607 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5608 | struct hdspm *hdspm = rule->private; |
| 5609 | struct snd_interval *c = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5610 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5611 | struct snd_interval *r = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5612 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5613 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5614 | if (r->min > 96000 && r->max <= 192000) { |
| 5615 | struct snd_interval t = { |
| 5616 | .min = hdspm->qs_out_channels, |
| 5617 | .max = hdspm->qs_out_channels, |
| 5618 | .integer = 1, |
| 5619 | }; |
| 5620 | return snd_interval_refine(c, &t); |
| 5621 | } else if (r->min > 48000 && r->max <= 96000) { |
| 5622 | struct snd_interval t = { |
| 5623 | .min = hdspm->ds_out_channels, |
| 5624 | .max = hdspm->ds_out_channels, |
| 5625 | .integer = 1, |
| 5626 | }; |
| 5627 | return snd_interval_refine(c, &t); |
| 5628 | } else if (r->max < 64000) { |
| 5629 | struct snd_interval t = { |
| 5630 | .min = hdspm->ss_out_channels, |
| 5631 | .max = hdspm->ss_out_channels, |
| 5632 | .integer = 1, |
| 5633 | }; |
| 5634 | return snd_interval_refine(c, &t); |
| 5635 | } else { |
| 5636 | } |
| 5637 | return 0; |
| 5638 | } |
| 5639 | |
| 5640 | static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params, |
| 5641 | struct snd_pcm_hw_rule * rule) |
| 5642 | { |
| 5643 | struct hdspm *hdspm = rule->private; |
| 5644 | struct snd_interval *c = |
| 5645 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5646 | struct snd_interval *r = |
| 5647 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5648 | |
| 5649 | if (c->min >= hdspm->ss_in_channels) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5650 | struct snd_interval t = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5651 | .min = 32000, |
| 5652 | .max = 48000, |
| 5653 | .integer = 1, |
| 5654 | }; |
| 5655 | return snd_interval_refine(r, &t); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5656 | } else if (c->max <= hdspm->qs_in_channels) { |
| 5657 | struct snd_interval t = { |
| 5658 | .min = 128000, |
| 5659 | .max = 192000, |
| 5660 | .integer = 1, |
| 5661 | }; |
| 5662 | return snd_interval_refine(r, &t); |
| 5663 | } else if (c->max <= hdspm->ds_in_channels) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5664 | struct snd_interval t = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5665 | .min = 64000, |
| 5666 | .max = 96000, |
| 5667 | .integer = 1, |
| 5668 | }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5669 | return snd_interval_refine(r, &t); |
| 5670 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5671 | |
| 5672 | return 0; |
| 5673 | } |
| 5674 | static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params, |
| 5675 | struct snd_pcm_hw_rule *rule) |
| 5676 | { |
| 5677 | struct hdspm *hdspm = rule->private; |
| 5678 | struct snd_interval *c = |
| 5679 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5680 | struct snd_interval *r = |
| 5681 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5682 | |
| 5683 | if (c->min >= hdspm->ss_out_channels) { |
| 5684 | struct snd_interval t = { |
| 5685 | .min = 32000, |
| 5686 | .max = 48000, |
| 5687 | .integer = 1, |
| 5688 | }; |
| 5689 | return snd_interval_refine(r, &t); |
| 5690 | } else if (c->max <= hdspm->qs_out_channels) { |
| 5691 | struct snd_interval t = { |
| 5692 | .min = 128000, |
| 5693 | .max = 192000, |
| 5694 | .integer = 1, |
| 5695 | }; |
| 5696 | return snd_interval_refine(r, &t); |
| 5697 | } else if (c->max <= hdspm->ds_out_channels) { |
| 5698 | struct snd_interval t = { |
| 5699 | .min = 64000, |
| 5700 | .max = 96000, |
| 5701 | .integer = 1, |
| 5702 | }; |
| 5703 | return snd_interval_refine(r, &t); |
| 5704 | } |
| 5705 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5706 | return 0; |
| 5707 | } |
| 5708 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5709 | static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params, |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5710 | struct snd_pcm_hw_rule *rule) |
| 5711 | { |
| 5712 | unsigned int list[3]; |
| 5713 | struct hdspm *hdspm = rule->private; |
| 5714 | struct snd_interval *c = hw_param_interval(params, |
| 5715 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5716 | |
| 5717 | list[0] = hdspm->qs_in_channels; |
| 5718 | list[1] = hdspm->ds_in_channels; |
| 5719 | list[2] = hdspm->ss_in_channels; |
| 5720 | return snd_interval_list(c, 3, list, 0); |
| 5721 | } |
| 5722 | |
| 5723 | static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params, |
| 5724 | struct snd_pcm_hw_rule *rule) |
| 5725 | { |
| 5726 | unsigned int list[3]; |
| 5727 | struct hdspm *hdspm = rule->private; |
| 5728 | struct snd_interval *c = hw_param_interval(params, |
| 5729 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5730 | |
| 5731 | list[0] = hdspm->qs_out_channels; |
| 5732 | list[1] = hdspm->ds_out_channels; |
| 5733 | list[2] = hdspm->ss_out_channels; |
| 5734 | return snd_interval_list(c, 3, list, 0); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5738 | static unsigned int hdspm_aes32_sample_rates[] = { |
| 5739 | 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 |
| 5740 | }; |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5741 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5742 | static struct snd_pcm_hw_constraint_list |
| 5743 | hdspm_hw_constraints_aes32_sample_rates = { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5744 | .count = ARRAY_SIZE(hdspm_aes32_sample_rates), |
| 5745 | .list = hdspm_aes32_sample_rates, |
| 5746 | .mask = 0 |
| 5747 | }; |
| 5748 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5749 | static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5750 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5751 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5752 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5753 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5754 | spin_lock_irq(&hdspm->lock); |
| 5755 | |
| 5756 | snd_pcm_set_sync(substream); |
| 5757 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5758 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5759 | runtime->hw = snd_hdspm_playback_subinfo; |
| 5760 | |
| 5761 | if (hdspm->capture_substream == NULL) |
| 5762 | hdspm_stop_audio(hdspm); |
| 5763 | |
| 5764 | hdspm->playback_pid = current->pid; |
| 5765 | hdspm->playback_substream = substream; |
| 5766 | |
| 5767 | spin_unlock_irq(&hdspm->lock); |
| 5768 | |
| 5769 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5770 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5771 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5772 | switch (hdspm->io_type) { |
| 5773 | case AIO: |
| 5774 | case RayDAT: |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5775 | snd_pcm_hw_constraint_minmax(runtime, |
| 5776 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 5777 | 32, 4096); |
| 5778 | /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */ |
| 5779 | snd_pcm_hw_constraint_minmax(runtime, |
| 5780 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 5781 | 16384, 16384); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5782 | break; |
| 5783 | |
| 5784 | default: |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5785 | snd_pcm_hw_constraint_minmax(runtime, |
| 5786 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 5787 | 64, 8192); |
| 5788 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | if (AES32 == hdspm->io_type) { |
Takashi Iwai | 3fa9e3d | 2011-08-15 10:42:23 +0200 | [diff] [blame] | 5792 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5793 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 5794 | &hdspm_hw_constraints_aes32_sample_rates); |
| 5795 | } else { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5796 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5797 | snd_hdspm_hw_rule_rate_out_channels, hdspm, |
| 5798 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5799 | } |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 5800 | |
| 5801 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 5802 | snd_hdspm_hw_rule_out_channels, hdspm, |
| 5803 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 5804 | |
| 5805 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 5806 | snd_hdspm_hw_rule_out_channels_rate, hdspm, |
| 5807 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 5808 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5809 | return 0; |
| 5810 | } |
| 5811 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5812 | static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5813 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5814 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5815 | |
| 5816 | spin_lock_irq(&hdspm->lock); |
| 5817 | |
| 5818 | hdspm->playback_pid = -1; |
| 5819 | hdspm->playback_substream = NULL; |
| 5820 | |
| 5821 | spin_unlock_irq(&hdspm->lock); |
| 5822 | |
| 5823 | return 0; |
| 5824 | } |
| 5825 | |
| 5826 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5827 | static int snd_hdspm_capture_open(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5828 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5829 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5830 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5831 | |
| 5832 | spin_lock_irq(&hdspm->lock); |
| 5833 | snd_pcm_set_sync(substream); |
| 5834 | runtime->hw = snd_hdspm_capture_subinfo; |
| 5835 | |
| 5836 | if (hdspm->playback_substream == NULL) |
| 5837 | hdspm_stop_audio(hdspm); |
| 5838 | |
| 5839 | hdspm->capture_pid = current->pid; |
| 5840 | hdspm->capture_substream = substream; |
| 5841 | |
| 5842 | spin_unlock_irq(&hdspm->lock); |
| 5843 | |
| 5844 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5845 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
| 5846 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5847 | switch (hdspm->io_type) { |
| 5848 | case AIO: |
| 5849 | case RayDAT: |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5850 | snd_pcm_hw_constraint_minmax(runtime, |
| 5851 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 5852 | 32, 4096); |
| 5853 | snd_pcm_hw_constraint_minmax(runtime, |
| 5854 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 5855 | 16384, 16384); |
| 5856 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5857 | |
| 5858 | default: |
Takashi Iwai | d877681 | 2011-08-15 10:45:42 +0200 | [diff] [blame] | 5859 | snd_pcm_hw_constraint_minmax(runtime, |
| 5860 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 5861 | 64, 8192); |
| 5862 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | if (AES32 == hdspm->io_type) { |
Takashi Iwai | 3fa9e3d | 2011-08-15 10:42:23 +0200 | [diff] [blame] | 5866 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5867 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 5868 | &hdspm_hw_constraints_aes32_sample_rates); |
| 5869 | } else { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5870 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 5871 | snd_hdspm_hw_rule_rate_in_channels, hdspm, |
| 5872 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5873 | } |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 5874 | |
| 5875 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 5876 | snd_hdspm_hw_rule_in_channels, hdspm, |
| 5877 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 5878 | |
| 5879 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 5880 | snd_hdspm_hw_rule_in_channels_rate, hdspm, |
| 5881 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 5882 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5883 | return 0; |
| 5884 | } |
| 5885 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5886 | static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5887 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5888 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5889 | |
| 5890 | spin_lock_irq(&hdspm->lock); |
| 5891 | |
| 5892 | hdspm->capture_pid = -1; |
| 5893 | hdspm->capture_substream = NULL; |
| 5894 | |
| 5895 | spin_unlock_irq(&hdspm->lock); |
| 5896 | return 0; |
| 5897 | } |
| 5898 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5899 | static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5900 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5901 | /* we have nothing to initialize but the call is required */ |
| 5902 | return 0; |
| 5903 | } |
| 5904 | |
| 5905 | static inline int copy_u32_le(void __user *dest, void __iomem *src) |
| 5906 | { |
| 5907 | u32 val = readl(src); |
| 5908 | return copy_to_user(dest, &val, 4); |
| 5909 | } |
| 5910 | |
| 5911 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, |
Dan Carpenter | 2ca595a | 2011-09-23 09:25:05 +0300 | [diff] [blame] | 5912 | unsigned int cmd, unsigned long arg) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5913 | { |
| 5914 | void __user *argp = (void __user *)arg; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5915 | struct hdspm *hdspm = hw->private_data; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5916 | struct hdspm_mixer_ioctl mixer; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5917 | struct hdspm_config info; |
| 5918 | struct hdspm_status status; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5919 | struct hdspm_version hdspm_version; |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5920 | struct hdspm_peak_rms *levels; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5921 | struct hdspm_ltc ltc; |
| 5922 | unsigned int statusregister; |
| 5923 | long unsigned int s; |
| 5924 | int i = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5925 | |
| 5926 | switch (cmd) { |
| 5927 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5928 | case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5929 | levels = &hdspm->peak_rms; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5930 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5931 | levels->input_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5932 | readl(hdspm->iobase + |
| 5933 | HDSPM_MADI_INPUT_PEAK + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5934 | levels->playback_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5935 | readl(hdspm->iobase + |
| 5936 | HDSPM_MADI_PLAYBACK_PEAK + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5937 | levels->output_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5938 | readl(hdspm->iobase + |
| 5939 | HDSPM_MADI_OUTPUT_PEAK + i*4); |
| 5940 | |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5941 | levels->input_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5942 | ((uint64_t) readl(hdspm->iobase + |
| 5943 | HDSPM_MADI_INPUT_RMS_H + i*4) << 32) | |
| 5944 | (uint64_t) readl(hdspm->iobase + |
| 5945 | HDSPM_MADI_INPUT_RMS_L + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5946 | levels->playback_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5947 | ((uint64_t)readl(hdspm->iobase + |
| 5948 | HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) | |
| 5949 | (uint64_t)readl(hdspm->iobase + |
| 5950 | HDSPM_MADI_PLAYBACK_RMS_L + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5951 | levels->output_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5952 | ((uint64_t)readl(hdspm->iobase + |
| 5953 | HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) | |
| 5954 | (uint64_t)readl(hdspm->iobase + |
| 5955 | HDSPM_MADI_OUTPUT_RMS_L + i*4); |
| 5956 | } |
| 5957 | |
| 5958 | if (hdspm->system_sample_rate > 96000) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5959 | levels->speed = qs; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5960 | } else if (hdspm->system_sample_rate > 48000) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5961 | levels->speed = ds; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5962 | } else { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5963 | levels->speed = ss; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5964 | } |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5965 | levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5966 | |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 5967 | s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms)); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5968 | if (0 != s) { |
| 5969 | /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu |
| 5970 | [Levels]\n", sizeof(struct hdspm_peak_rms), s); |
| 5971 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5972 | return -EFAULT; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5973 | } |
| 5974 | break; |
| 5975 | |
| 5976 | case SNDRV_HDSPM_IOCTL_GET_LTC: |
| 5977 | ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO); |
| 5978 | i = hdspm_read(hdspm, HDSPM_RD_TCO + 4); |
| 5979 | if (i & HDSPM_TCO1_LTC_Input_valid) { |
| 5980 | switch (i & (HDSPM_TCO1_LTC_Format_LSB | |
| 5981 | HDSPM_TCO1_LTC_Format_MSB)) { |
| 5982 | case 0: |
| 5983 | ltc.format = fps_24; |
| 5984 | break; |
| 5985 | case HDSPM_TCO1_LTC_Format_LSB: |
| 5986 | ltc.format = fps_25; |
| 5987 | break; |
| 5988 | case HDSPM_TCO1_LTC_Format_MSB: |
| 5989 | ltc.format = fps_2997; |
| 5990 | break; |
| 5991 | default: |
| 5992 | ltc.format = 30; |
| 5993 | break; |
| 5994 | } |
| 5995 | if (i & HDSPM_TCO1_set_drop_frame_flag) { |
| 5996 | ltc.frame = drop_frame; |
| 5997 | } else { |
| 5998 | ltc.frame = full_frame; |
| 5999 | } |
| 6000 | } else { |
| 6001 | ltc.format = format_invalid; |
| 6002 | ltc.frame = frame_invalid; |
| 6003 | } |
| 6004 | if (i & HDSPM_TCO1_Video_Input_Format_NTSC) { |
| 6005 | ltc.input_format = ntsc; |
| 6006 | } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) { |
| 6007 | ltc.input_format = pal; |
| 6008 | } else { |
| 6009 | ltc.input_format = no_video; |
| 6010 | } |
| 6011 | |
| 6012 | s = copy_to_user(argp, <c, sizeof(struct hdspm_ltc)); |
| 6013 | if (0 != s) { |
| 6014 | /* |
| 6015 | snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6016 | return -EFAULT; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6017 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6018 | |
| 6019 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6020 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6021 | case SNDRV_HDSPM_IOCTL_GET_CONFIG: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6022 | |
Adrian Knoth | 4ab69a2 | 2011-02-23 11:43:14 +0100 | [diff] [blame] | 6023 | memset(&info, 0, sizeof(info)); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6024 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6025 | info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); |
| 6026 | info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6027 | |
| 6028 | info.system_sample_rate = hdspm->system_sample_rate; |
| 6029 | info.autosync_sample_rate = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6030 | hdspm_external_sample_rate(hdspm); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6031 | info.system_clock_mode = hdspm_system_clock_mode(hdspm); |
| 6032 | info.clock_source = hdspm_clock_source(hdspm); |
| 6033 | info.autosync_ref = hdspm_autosync_ref(hdspm); |
Adrian Knoth | c9e1668 | 2012-12-03 14:55:50 +0100 | [diff] [blame] | 6034 | info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6035 | info.passthru = 0; |
| 6036 | spin_unlock_irq(&hdspm->lock); |
Dan Carpenter | 2ca595a | 2011-09-23 09:25:05 +0300 | [diff] [blame] | 6037 | if (copy_to_user(argp, &info, sizeof(info))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6038 | return -EFAULT; |
| 6039 | break; |
| 6040 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6041 | case SNDRV_HDSPM_IOCTL_GET_STATUS: |
Dan Carpenter | 643d6bb | 2011-09-23 09:24:21 +0300 | [diff] [blame] | 6042 | memset(&status, 0, sizeof(status)); |
| 6043 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6044 | status.card_type = hdspm->io_type; |
| 6045 | |
| 6046 | status.autosync_source = hdspm_autosync_ref(hdspm); |
| 6047 | |
| 6048 | status.card_clock = 110069313433624ULL; |
| 6049 | status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 6050 | |
| 6051 | switch (hdspm->io_type) { |
| 6052 | case MADI: |
| 6053 | case MADIface: |
| 6054 | status.card_specific.madi.sync_wc = |
| 6055 | hdspm_wc_sync_check(hdspm); |
| 6056 | status.card_specific.madi.sync_madi = |
| 6057 | hdspm_madi_sync_check(hdspm); |
| 6058 | status.card_specific.madi.sync_tco = |
| 6059 | hdspm_tco_sync_check(hdspm); |
| 6060 | status.card_specific.madi.sync_in = |
| 6061 | hdspm_sync_in_sync_check(hdspm); |
| 6062 | |
| 6063 | statusregister = |
| 6064 | hdspm_read(hdspm, HDSPM_statusRegister); |
| 6065 | status.card_specific.madi.madi_input = |
| 6066 | (statusregister & HDSPM_AB_int) ? 1 : 0; |
| 6067 | status.card_specific.madi.channel_format = |
Adrian Knoth | 9e6ff52 | 2011-10-27 21:57:52 +0200 | [diff] [blame] | 6068 | (statusregister & HDSPM_RX_64ch) ? 1 : 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6069 | /* TODO: Mac driver sets it when f_s>48kHz */ |
| 6070 | status.card_specific.madi.frame_format = 0; |
| 6071 | |
| 6072 | default: |
| 6073 | break; |
| 6074 | } |
| 6075 | |
Dan Carpenter | 2ca595a | 2011-09-23 09:25:05 +0300 | [diff] [blame] | 6076 | if (copy_to_user(argp, &status, sizeof(status))) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6077 | return -EFAULT; |
| 6078 | |
| 6079 | |
| 6080 | break; |
| 6081 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6082 | case SNDRV_HDSPM_IOCTL_GET_VERSION: |
Dan Carpenter | 643d6bb | 2011-09-23 09:24:21 +0300 | [diff] [blame] | 6083 | memset(&hdspm_version, 0, sizeof(hdspm_version)); |
| 6084 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6085 | hdspm_version.card_type = hdspm->io_type; |
| 6086 | strncpy(hdspm_version.cardname, hdspm->card_name, |
| 6087 | sizeof(hdspm_version.cardname)); |
Adrian Knoth | 7d53a63 | 2012-01-04 14:31:16 +0100 | [diff] [blame] | 6088 | hdspm_version.serial = hdspm->serial; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6089 | hdspm_version.firmware_rev = hdspm->firmware_rev; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6090 | hdspm_version.addons = 0; |
| 6091 | if (hdspm->tco) |
| 6092 | hdspm_version.addons |= HDSPM_ADDON_TCO; |
| 6093 | |
Dan Carpenter | 2ca595a | 2011-09-23 09:25:05 +0300 | [diff] [blame] | 6094 | if (copy_to_user(argp, &hdspm_version, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6095 | sizeof(hdspm_version))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6096 | return -EFAULT; |
| 6097 | break; |
| 6098 | |
| 6099 | case SNDRV_HDSPM_IOCTL_GET_MIXER: |
Dan Carpenter | 2ca595a | 2011-09-23 09:25:05 +0300 | [diff] [blame] | 6100 | if (copy_from_user(&mixer, argp, sizeof(mixer))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6101 | return -EFAULT; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6102 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6103 | sizeof(struct hdspm_mixer))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6104 | return -EFAULT; |
| 6105 | break; |
| 6106 | |
| 6107 | default: |
| 6108 | return -EINVAL; |
| 6109 | } |
| 6110 | return 0; |
| 6111 | } |
| 6112 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6113 | static struct snd_pcm_ops snd_hdspm_playback_ops = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6114 | .open = snd_hdspm_playback_open, |
| 6115 | .close = snd_hdspm_playback_release, |
| 6116 | .ioctl = snd_hdspm_ioctl, |
| 6117 | .hw_params = snd_hdspm_hw_params, |
| 6118 | .hw_free = snd_hdspm_hw_free, |
| 6119 | .prepare = snd_hdspm_prepare, |
| 6120 | .trigger = snd_hdspm_trigger, |
| 6121 | .pointer = snd_hdspm_hw_pointer, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6122 | .page = snd_pcm_sgbuf_ops_page, |
| 6123 | }; |
| 6124 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6125 | static struct snd_pcm_ops snd_hdspm_capture_ops = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6126 | .open = snd_hdspm_capture_open, |
| 6127 | .close = snd_hdspm_capture_release, |
| 6128 | .ioctl = snd_hdspm_ioctl, |
| 6129 | .hw_params = snd_hdspm_hw_params, |
| 6130 | .hw_free = snd_hdspm_hw_free, |
| 6131 | .prepare = snd_hdspm_prepare, |
| 6132 | .trigger = snd_hdspm_trigger, |
| 6133 | .pointer = snd_hdspm_hw_pointer, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6134 | .page = snd_pcm_sgbuf_ops_page, |
| 6135 | }; |
| 6136 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6137 | static int snd_hdspm_create_hwdep(struct snd_card *card, |
| 6138 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6139 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6140 | struct snd_hwdep *hw; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6141 | int err; |
| 6142 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6143 | err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw); |
| 6144 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6145 | return err; |
| 6146 | |
| 6147 | hdspm->hwdep = hw; |
| 6148 | hw->private_data = hdspm; |
| 6149 | strcpy(hw->name, "HDSPM hwdep interface"); |
| 6150 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6151 | hw->ops.open = snd_hdspm_hwdep_dummy_op; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6152 | hw->ops.ioctl = snd_hdspm_hwdep_ioctl; |
Adrian Knoth | 8de5d6f | 2012-03-08 15:38:04 +0100 | [diff] [blame] | 6153 | hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6154 | hw->ops.release = snd_hdspm_hwdep_dummy_op; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6155 | |
| 6156 | return 0; |
| 6157 | } |
| 6158 | |
| 6159 | |
| 6160 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6161 | memory interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6162 | ------------------------------------------------------------*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6163 | static int snd_hdspm_preallocate_memory(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6164 | { |
| 6165 | int err; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6166 | struct snd_pcm *pcm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6167 | size_t wanted; |
| 6168 | |
| 6169 | pcm = hdspm->pcm; |
| 6170 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6171 | wanted = HDSPM_DMA_AREA_BYTES; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6172 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6173 | err = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6174 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6175 | SNDRV_DMA_TYPE_DEV_SG, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6176 | snd_dma_pci_data(hdspm->pci), |
| 6177 | wanted, |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6178 | wanted); |
| 6179 | if (err < 0) { |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6180 | snd_printdd("Could not preallocate %zd Bytes\n", wanted); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6181 | |
| 6182 | return err; |
| 6183 | } else |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6184 | snd_printdd(" Preallocated %zd Bytes\n", wanted); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6185 | |
| 6186 | return 0; |
| 6187 | } |
| 6188 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6189 | |
| 6190 | static void hdspm_set_sgbuf(struct hdspm *hdspm, |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 6191 | struct snd_pcm_substream *substream, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6192 | unsigned int reg, int channels) |
| 6193 | { |
| 6194 | int i; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6195 | |
| 6196 | /* continuous memory segment */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6197 | for (i = 0; i < (channels * 16); i++) |
| 6198 | hdspm_write(hdspm, reg + 4 * i, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6199 | snd_pcm_sgbuf_get_addr(substream, 4096 * i)); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6200 | } |
| 6201 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6202 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6203 | /* ------------- ALSA Devices ---------------------------- */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6204 | static int snd_hdspm_create_pcm(struct snd_card *card, |
| 6205 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6206 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6207 | struct snd_pcm *pcm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6208 | int err; |
| 6209 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6210 | err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm); |
| 6211 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6212 | return err; |
| 6213 | |
| 6214 | hdspm->pcm = pcm; |
| 6215 | pcm->private_data = hdspm; |
| 6216 | strcpy(pcm->name, hdspm->card_name); |
| 6217 | |
| 6218 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 6219 | &snd_hdspm_playback_ops); |
| 6220 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 6221 | &snd_hdspm_capture_ops); |
| 6222 | |
| 6223 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 6224 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6225 | err = snd_hdspm_preallocate_memory(hdspm); |
| 6226 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6227 | return err; |
| 6228 | |
| 6229 | return 0; |
| 6230 | } |
| 6231 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6232 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6233 | { |
Adrian Knoth | 7c7102b | 2011-02-28 15:14:50 +0100 | [diff] [blame] | 6234 | int i; |
| 6235 | |
| 6236 | for (i = 0; i < hdspm->midiPorts; i++) |
| 6237 | snd_hdspm_flush_midi_input(hdspm, i); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6238 | } |
| 6239 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6240 | static int snd_hdspm_create_alsa_devices(struct snd_card *card, |
| 6241 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6242 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6243 | int err, i; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6244 | |
| 6245 | snd_printdd("Create card...\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6246 | err = snd_hdspm_create_pcm(card, hdspm); |
| 6247 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6248 | return err; |
| 6249 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6250 | i = 0; |
| 6251 | while (i < hdspm->midiPorts) { |
| 6252 | err = snd_hdspm_create_midi(card, hdspm, i); |
| 6253 | if (err < 0) { |
| 6254 | return err; |
| 6255 | } |
| 6256 | i++; |
| 6257 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6258 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6259 | err = snd_hdspm_create_controls(card, hdspm); |
| 6260 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6261 | return err; |
| 6262 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6263 | err = snd_hdspm_create_hwdep(card, hdspm); |
| 6264 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6265 | return err; |
| 6266 | |
| 6267 | snd_printdd("proc init...\n"); |
| 6268 | snd_hdspm_proc_init(hdspm); |
| 6269 | |
| 6270 | hdspm->system_sample_rate = -1; |
| 6271 | hdspm->last_external_sample_rate = -1; |
| 6272 | hdspm->last_internal_sample_rate = -1; |
| 6273 | hdspm->playback_pid = -1; |
| 6274 | hdspm->capture_pid = -1; |
| 6275 | hdspm->capture_substream = NULL; |
| 6276 | hdspm->playback_substream = NULL; |
| 6277 | |
| 6278 | snd_printdd("Set defaults...\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6279 | err = snd_hdspm_set_defaults(hdspm); |
| 6280 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6281 | return err; |
| 6282 | |
| 6283 | snd_printdd("Update mixer controls...\n"); |
| 6284 | hdspm_update_simple_mixer_controls(hdspm); |
| 6285 | |
| 6286 | snd_printdd("Initializeing complete ???\n"); |
| 6287 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6288 | err = snd_card_register(card); |
| 6289 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6290 | snd_printk(KERN_ERR "HDSPM: error registering card\n"); |
| 6291 | return err; |
| 6292 | } |
| 6293 | |
| 6294 | snd_printdd("... yes now\n"); |
| 6295 | |
| 6296 | return 0; |
| 6297 | } |
| 6298 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6299 | static int snd_hdspm_create(struct snd_card *card, |
| 6300 | struct hdspm *hdspm) |
| 6301 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6302 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6303 | struct pci_dev *pci = hdspm->pci; |
| 6304 | int err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6305 | unsigned long io_extent; |
| 6306 | |
| 6307 | hdspm->irq = -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6308 | hdspm->card = card; |
| 6309 | |
| 6310 | spin_lock_init(&hdspm->lock); |
| 6311 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6312 | pci_read_config_word(hdspm->pci, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6313 | PCI_CLASS_REVISION, &hdspm->firmware_rev); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6314 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6315 | strcpy(card->mixername, "Xilinx FPGA"); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6316 | strcpy(card->driver, "HDSPM"); |
| 6317 | |
| 6318 | switch (hdspm->firmware_rev) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6319 | case HDSPM_RAYDAT_REV: |
| 6320 | hdspm->io_type = RayDAT; |
| 6321 | hdspm->card_name = "RME RayDAT"; |
| 6322 | hdspm->midiPorts = 2; |
| 6323 | break; |
| 6324 | case HDSPM_AIO_REV: |
| 6325 | hdspm->io_type = AIO; |
| 6326 | hdspm->card_name = "RME AIO"; |
| 6327 | hdspm->midiPorts = 1; |
| 6328 | break; |
| 6329 | case HDSPM_MADIFACE_REV: |
| 6330 | hdspm->io_type = MADIface; |
| 6331 | hdspm->card_name = "RME MADIface"; |
| 6332 | hdspm->midiPorts = 1; |
| 6333 | break; |
Adrian Knoth | 5027f34 | 2011-02-28 15:14:49 +0100 | [diff] [blame] | 6334 | default: |
Adrian Knoth | c09403d | 2011-10-27 21:57:54 +0200 | [diff] [blame] | 6335 | if ((hdspm->firmware_rev == 0xf0) || |
| 6336 | ((hdspm->firmware_rev >= 0xe6) && |
| 6337 | (hdspm->firmware_rev <= 0xea))) { |
| 6338 | hdspm->io_type = AES32; |
| 6339 | hdspm->card_name = "RME AES32"; |
| 6340 | hdspm->midiPorts = 2; |
Adrian Knoth | 05c7cc9 | 2011-11-21 16:15:36 +0100 | [diff] [blame] | 6341 | } else if ((hdspm->firmware_rev == 0xd2) || |
Adrian Knoth | c09403d | 2011-10-27 21:57:54 +0200 | [diff] [blame] | 6342 | ((hdspm->firmware_rev >= 0xc8) && |
| 6343 | (hdspm->firmware_rev <= 0xcf))) { |
| 6344 | hdspm->io_type = MADI; |
| 6345 | hdspm->card_name = "RME MADI"; |
| 6346 | hdspm->midiPorts = 3; |
| 6347 | } else { |
| 6348 | snd_printk(KERN_ERR |
| 6349 | "HDSPM: unknown firmware revision %x\n", |
Adrian Knoth | 5027f34 | 2011-02-28 15:14:49 +0100 | [diff] [blame] | 6350 | hdspm->firmware_rev); |
Adrian Knoth | c09403d | 2011-10-27 21:57:54 +0200 | [diff] [blame] | 6351 | return -ENODEV; |
| 6352 | } |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6353 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6354 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6355 | err = pci_enable_device(pci); |
| 6356 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6357 | return err; |
| 6358 | |
| 6359 | pci_set_master(hdspm->pci); |
| 6360 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6361 | err = pci_request_regions(pci, "hdspm"); |
| 6362 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6363 | return err; |
| 6364 | |
| 6365 | hdspm->port = pci_resource_start(pci, 0); |
| 6366 | io_extent = pci_resource_len(pci, 0); |
| 6367 | |
| 6368 | snd_printdd("grabbed memory region 0x%lx-0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6369 | hdspm->port, hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6370 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6371 | hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); |
| 6372 | if (!hdspm->iobase) { |
| 6373 | snd_printk(KERN_ERR "HDSPM: " |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6374 | "unable to remap region 0x%lx-0x%lx\n", |
| 6375 | hdspm->port, hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6376 | return -EBUSY; |
| 6377 | } |
| 6378 | snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6379 | (unsigned long)hdspm->iobase, hdspm->port, |
| 6380 | hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6381 | |
| 6382 | if (request_irq(pci->irq, snd_hdspm_interrupt, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 6383 | IRQF_SHARED, KBUILD_MODNAME, hdspm)) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6384 | snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq); |
| 6385 | return -EBUSY; |
| 6386 | } |
| 6387 | |
| 6388 | snd_printdd("use IRQ %d\n", pci->irq); |
| 6389 | |
| 6390 | hdspm->irq = pci->irq; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6391 | |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6392 | snd_printdd("kmalloc Mixer memory of %zd Bytes\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6393 | sizeof(struct hdspm_mixer)); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6394 | hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL); |
| 6395 | if (!hdspm->mixer) { |
| 6396 | snd_printk(KERN_ERR "HDSPM: " |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6397 | "unable to kmalloc Mixer memory of %d Bytes\n", |
| 6398 | (int)sizeof(struct hdspm_mixer)); |
Julia Lawall | b17cbdd | 2012-08-19 09:02:54 +0200 | [diff] [blame] | 6399 | return -ENOMEM; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6400 | } |
| 6401 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6402 | hdspm->port_names_in = NULL; |
| 6403 | hdspm->port_names_out = NULL; |
| 6404 | |
| 6405 | switch (hdspm->io_type) { |
| 6406 | case AES32: |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 6407 | hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS; |
| 6408 | hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS; |
| 6409 | hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS; |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 6410 | |
| 6411 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6412 | channel_map_aes32; |
| 6413 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
| 6414 | channel_map_aes32; |
| 6415 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
| 6416 | channel_map_aes32; |
| 6417 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6418 | texts_ports_aes32; |
| 6419 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6420 | texts_ports_aes32; |
| 6421 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6422 | texts_ports_aes32; |
| 6423 | |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 6424 | hdspm->max_channels_out = hdspm->max_channels_in = |
| 6425 | AES32_CHANNELS; |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 6426 | hdspm->port_names_in = hdspm->port_names_out = |
| 6427 | texts_ports_aes32; |
| 6428 | hdspm->channel_map_in = hdspm->channel_map_out = |
| 6429 | channel_map_aes32; |
| 6430 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6431 | break; |
| 6432 | |
| 6433 | case MADI: |
| 6434 | case MADIface: |
| 6435 | hdspm->ss_in_channels = hdspm->ss_out_channels = |
| 6436 | MADI_SS_CHANNELS; |
| 6437 | hdspm->ds_in_channels = hdspm->ds_out_channels = |
| 6438 | MADI_DS_CHANNELS; |
| 6439 | hdspm->qs_in_channels = hdspm->qs_out_channels = |
| 6440 | MADI_QS_CHANNELS; |
| 6441 | |
| 6442 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6443 | channel_map_unity_ss; |
Adrian Knoth | 01e9607 | 2011-02-23 11:43:11 +0100 | [diff] [blame] | 6444 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6445 | channel_map_unity_ss; |
Adrian Knoth | 01e9607 | 2011-02-23 11:43:11 +0100 | [diff] [blame] | 6446 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6447 | channel_map_unity_ss; |
| 6448 | |
| 6449 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6450 | texts_ports_madi; |
| 6451 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6452 | texts_ports_madi; |
| 6453 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6454 | texts_ports_madi; |
| 6455 | break; |
| 6456 | |
| 6457 | case AIO: |
| 6458 | if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) { |
| 6459 | snd_printk(KERN_INFO "HDSPM: AEB input board found, but not supported\n"); |
| 6460 | } |
| 6461 | |
| 6462 | hdspm->ss_in_channels = AIO_IN_SS_CHANNELS; |
| 6463 | hdspm->ds_in_channels = AIO_IN_DS_CHANNELS; |
| 6464 | hdspm->qs_in_channels = AIO_IN_QS_CHANNELS; |
| 6465 | hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS; |
| 6466 | hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS; |
| 6467 | hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS; |
| 6468 | |
| 6469 | hdspm->channel_map_out_ss = channel_map_aio_out_ss; |
| 6470 | hdspm->channel_map_out_ds = channel_map_aio_out_ds; |
| 6471 | hdspm->channel_map_out_qs = channel_map_aio_out_qs; |
| 6472 | |
| 6473 | hdspm->channel_map_in_ss = channel_map_aio_in_ss; |
| 6474 | hdspm->channel_map_in_ds = channel_map_aio_in_ds; |
| 6475 | hdspm->channel_map_in_qs = channel_map_aio_in_qs; |
| 6476 | |
| 6477 | hdspm->port_names_in_ss = texts_ports_aio_in_ss; |
| 6478 | hdspm->port_names_out_ss = texts_ports_aio_out_ss; |
| 6479 | hdspm->port_names_in_ds = texts_ports_aio_in_ds; |
| 6480 | hdspm->port_names_out_ds = texts_ports_aio_out_ds; |
| 6481 | hdspm->port_names_in_qs = texts_ports_aio_in_qs; |
| 6482 | hdspm->port_names_out_qs = texts_ports_aio_out_qs; |
| 6483 | |
| 6484 | break; |
| 6485 | |
| 6486 | case RayDAT: |
| 6487 | hdspm->ss_in_channels = hdspm->ss_out_channels = |
| 6488 | RAYDAT_SS_CHANNELS; |
| 6489 | hdspm->ds_in_channels = hdspm->ds_out_channels = |
| 6490 | RAYDAT_DS_CHANNELS; |
| 6491 | hdspm->qs_in_channels = hdspm->qs_out_channels = |
| 6492 | RAYDAT_QS_CHANNELS; |
| 6493 | |
| 6494 | hdspm->max_channels_in = RAYDAT_SS_CHANNELS; |
| 6495 | hdspm->max_channels_out = RAYDAT_SS_CHANNELS; |
| 6496 | |
| 6497 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6498 | channel_map_raydat_ss; |
| 6499 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
| 6500 | channel_map_raydat_ds; |
| 6501 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
| 6502 | channel_map_raydat_qs; |
| 6503 | hdspm->channel_map_in = hdspm->channel_map_out = |
| 6504 | channel_map_raydat_ss; |
| 6505 | |
| 6506 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6507 | texts_ports_raydat_ss; |
| 6508 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6509 | texts_ports_raydat_ds; |
| 6510 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6511 | texts_ports_raydat_qs; |
| 6512 | |
| 6513 | |
| 6514 | break; |
| 6515 | |
| 6516 | } |
| 6517 | |
| 6518 | /* TCO detection */ |
| 6519 | switch (hdspm->io_type) { |
| 6520 | case AIO: |
| 6521 | case RayDAT: |
| 6522 | if (hdspm_read(hdspm, HDSPM_statusRegister2) & |
| 6523 | HDSPM_s2_tco_detect) { |
| 6524 | hdspm->midiPorts++; |
| 6525 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), |
| 6526 | GFP_KERNEL); |
| 6527 | if (NULL != hdspm->tco) { |
| 6528 | hdspm_tco_write(hdspm); |
| 6529 | } |
| 6530 | snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n"); |
| 6531 | } else { |
| 6532 | hdspm->tco = NULL; |
| 6533 | } |
| 6534 | break; |
| 6535 | |
| 6536 | case MADI: |
| 6537 | if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) { |
| 6538 | hdspm->midiPorts++; |
| 6539 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), |
| 6540 | GFP_KERNEL); |
| 6541 | if (NULL != hdspm->tco) { |
| 6542 | hdspm_tco_write(hdspm); |
| 6543 | } |
| 6544 | snd_printk(KERN_INFO "HDSPM: MADI TCO module found\n"); |
| 6545 | } else { |
| 6546 | hdspm->tco = NULL; |
| 6547 | } |
| 6548 | break; |
| 6549 | |
| 6550 | default: |
| 6551 | hdspm->tco = NULL; |
| 6552 | } |
| 6553 | |
| 6554 | /* texts */ |
| 6555 | switch (hdspm->io_type) { |
| 6556 | case AES32: |
| 6557 | if (hdspm->tco) { |
| 6558 | hdspm->texts_autosync = texts_autosync_aes_tco; |
| 6559 | hdspm->texts_autosync_items = 10; |
| 6560 | } else { |
| 6561 | hdspm->texts_autosync = texts_autosync_aes; |
| 6562 | hdspm->texts_autosync_items = 9; |
| 6563 | } |
| 6564 | break; |
| 6565 | |
| 6566 | case MADI: |
| 6567 | if (hdspm->tco) { |
| 6568 | hdspm->texts_autosync = texts_autosync_madi_tco; |
| 6569 | hdspm->texts_autosync_items = 4; |
| 6570 | } else { |
| 6571 | hdspm->texts_autosync = texts_autosync_madi; |
| 6572 | hdspm->texts_autosync_items = 3; |
| 6573 | } |
| 6574 | break; |
| 6575 | |
| 6576 | case MADIface: |
| 6577 | |
| 6578 | break; |
| 6579 | |
| 6580 | case RayDAT: |
| 6581 | if (hdspm->tco) { |
| 6582 | hdspm->texts_autosync = texts_autosync_raydat_tco; |
| 6583 | hdspm->texts_autosync_items = 9; |
| 6584 | } else { |
| 6585 | hdspm->texts_autosync = texts_autosync_raydat; |
| 6586 | hdspm->texts_autosync_items = 8; |
| 6587 | } |
| 6588 | break; |
| 6589 | |
| 6590 | case AIO: |
| 6591 | if (hdspm->tco) { |
| 6592 | hdspm->texts_autosync = texts_autosync_aio_tco; |
| 6593 | hdspm->texts_autosync_items = 6; |
| 6594 | } else { |
| 6595 | hdspm->texts_autosync = texts_autosync_aio; |
| 6596 | hdspm->texts_autosync_items = 5; |
| 6597 | } |
| 6598 | break; |
| 6599 | |
| 6600 | } |
| 6601 | |
| 6602 | tasklet_init(&hdspm->midi_tasklet, |
| 6603 | hdspm_midi_tasklet, (unsigned long) hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6604 | |
Adrian Knoth | f7de8ba | 2012-01-10 20:58:40 +0100 | [diff] [blame] | 6605 | |
| 6606 | if (hdspm->io_type != MADIface) { |
| 6607 | hdspm->serial = (hdspm_read(hdspm, |
| 6608 | HDSPM_midiStatusIn0)>>8) & 0xFFFFFF; |
| 6609 | /* id contains either a user-provided value or the default |
| 6610 | * NULL. If it's the default, we're safe to |
| 6611 | * fill card->id with the serial number. |
| 6612 | * |
| 6613 | * If the serial number is 0xFFFFFF, then we're dealing with |
| 6614 | * an old PCI revision that comes without a sane number. In |
| 6615 | * this case, we don't set card->id to avoid collisions |
| 6616 | * when running with multiple cards. |
| 6617 | */ |
| 6618 | if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) { |
| 6619 | sprintf(card->id, "HDSPMx%06x", hdspm->serial); |
| 6620 | snd_card_set_id(card, card->id); |
| 6621 | } |
| 6622 | } |
| 6623 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6624 | snd_printdd("create alsa devices.\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6625 | err = snd_hdspm_create_alsa_devices(card, hdspm); |
| 6626 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6627 | return err; |
| 6628 | |
| 6629 | snd_hdspm_initialize_midi_flush(hdspm); |
| 6630 | |
| 6631 | return 0; |
| 6632 | } |
| 6633 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6634 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6635 | static int snd_hdspm_free(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6636 | { |
| 6637 | |
| 6638 | if (hdspm->port) { |
| 6639 | |
| 6640 | /* stop th audio, and cancel all interrupts */ |
| 6641 | hdspm->control_register &= |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6642 | ~(HDSPM_Start | HDSPM_AudioInterruptEnable | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6643 | HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable | |
| 6644 | HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6645 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 6646 | hdspm->control_register); |
| 6647 | } |
| 6648 | |
| 6649 | if (hdspm->irq >= 0) |
| 6650 | free_irq(hdspm->irq, (void *) hdspm); |
| 6651 | |
Jesper Juhl | fc58422 | 2005-10-24 15:11:28 +0200 | [diff] [blame] | 6652 | kfree(hdspm->mixer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6653 | |
| 6654 | if (hdspm->iobase) |
| 6655 | iounmap(hdspm->iobase); |
| 6656 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6657 | if (hdspm->port) |
| 6658 | pci_release_regions(hdspm->pci); |
| 6659 | |
| 6660 | pci_disable_device(hdspm->pci); |
| 6661 | return 0; |
| 6662 | } |
| 6663 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6664 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6665 | static void snd_hdspm_card_free(struct snd_card *card) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6666 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6667 | struct hdspm *hdspm = card->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6668 | |
| 6669 | if (hdspm) |
| 6670 | snd_hdspm_free(hdspm); |
| 6671 | } |
| 6672 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6673 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6674 | static int snd_hdspm_probe(struct pci_dev *pci, |
| 6675 | const struct pci_device_id *pci_id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6676 | { |
| 6677 | static int dev; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6678 | struct hdspm *hdspm; |
| 6679 | struct snd_card *card; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6680 | int err; |
| 6681 | |
| 6682 | if (dev >= SNDRV_CARDS) |
| 6683 | return -ENODEV; |
| 6684 | if (!enable[dev]) { |
| 6685 | dev++; |
| 6686 | return -ENOENT; |
| 6687 | } |
| 6688 | |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 6689 | err = snd_card_create(index[dev], id[dev], |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6690 | THIS_MODULE, sizeof(struct hdspm), &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 6691 | if (err < 0) |
| 6692 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6693 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6694 | hdspm = card->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6695 | card->private_free = snd_hdspm_card_free; |
| 6696 | hdspm->dev = dev; |
| 6697 | hdspm->pci = pci; |
| 6698 | |
Takashi Iwai | c187c04 | 2007-02-19 15:27:33 +0100 | [diff] [blame] | 6699 | snd_card_set_dev(card, &pci->dev); |
| 6700 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6701 | err = snd_hdspm_create(card, hdspm); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6702 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6703 | snd_card_free(card); |
| 6704 | return err; |
| 6705 | } |
| 6706 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6707 | if (hdspm->io_type != MADIface) { |
| 6708 | sprintf(card->shortname, "%s_%x", |
| 6709 | hdspm->card_name, |
Adrian Knoth | 7d53a63 | 2012-01-04 14:31:16 +0100 | [diff] [blame] | 6710 | hdspm->serial); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6711 | sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d", |
| 6712 | hdspm->card_name, |
Adrian Knoth | 7d53a63 | 2012-01-04 14:31:16 +0100 | [diff] [blame] | 6713 | hdspm->serial, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6714 | hdspm->port, hdspm->irq); |
| 6715 | } else { |
| 6716 | sprintf(card->shortname, "%s", hdspm->card_name); |
| 6717 | sprintf(card->longname, "%s at 0x%lx, irq %d", |
| 6718 | hdspm->card_name, hdspm->port, hdspm->irq); |
| 6719 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6720 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6721 | err = snd_card_register(card); |
| 6722 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6723 | snd_card_free(card); |
| 6724 | return err; |
| 6725 | } |
| 6726 | |
| 6727 | pci_set_drvdata(pci, card); |
| 6728 | |
| 6729 | dev++; |
| 6730 | return 0; |
| 6731 | } |
| 6732 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6733 | static void snd_hdspm_remove(struct pci_dev *pci) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6734 | { |
| 6735 | snd_card_free(pci_get_drvdata(pci)); |
| 6736 | pci_set_drvdata(pci, NULL); |
| 6737 | } |
| 6738 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 6739 | static struct pci_driver hdspm_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 6740 | .name = KBUILD_MODNAME, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6741 | .id_table = snd_hdspm_ids, |
| 6742 | .probe = snd_hdspm_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 6743 | .remove = snd_hdspm_remove, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6744 | }; |
| 6745 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 6746 | module_pci_driver(hdspm_driver); |