2 * bebob_focusrite.c - a part of driver for BeBoB based devices
4 * Copyright (c) 2013-2014 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 #define ANA_IN "Analog In"
12 #define DIG_IN "Digital In"
13 #define ANA_OUT "Analog Out"
14 #define DIG_OUT "Digital Out"
15 #define STM_IN "Stream In"
17 #define SAFFIRE_ADDRESS_BASE 0x000100000000ULL
19 #define SAFFIRE_OFFSET_CLOCK_SOURCE 0x00f8
20 #define SAFFIREPRO_OFFSET_CLOCK_SOURCE 0x0174
22 /* whether sync to external device or not */
23 #define SAFFIRE_OFFSET_CLOCK_SYNC_EXT 0x013c
24 #define SAFFIRE_LE_OFFSET_CLOCK_SYNC_EXT 0x0432
25 #define SAFFIREPRO_OFFSET_CLOCK_SYNC_EXT 0x0164
27 #define SAFFIRE_CLOCK_SOURCE_INTERNAL 0
28 #define SAFFIRE_CLOCK_SOURCE_SPDIF 1
30 /* '1' is absent, why... */
31 #define SAFFIREPRO_CLOCK_SOURCE_INTERNAL 0
32 #define SAFFIREPRO_CLOCK_SOURCE_SPDIF 2
33 #define SAFFIREPRO_CLOCK_SOURCE_ADAT1 3
34 #define SAFFIREPRO_CLOCK_SOURCE_ADAT2 4
35 #define SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK 5
37 /* S/PDIF, ADAT1, ADAT2 is enabled or not. three quadlets */
38 #define SAFFIREPRO_ENABLE_DIG_IFACES 0x01a4
40 /* saffirepro has its own parameter for sampling frequency */
41 #define SAFFIREPRO_RATE_NOREBOOT 0x01cc
42 /* index is the value for this register */
43 static const unsigned int rates[] = {
53 /* saffire(no label)/saffire LE has metering */
54 #define SAFFIRE_OFFSET_METER 0x0100
55 #define SAFFIRE_LE_OFFSET_METER 0x0168
58 saffire_read_block(struct snd_bebob *bebob, u64 offset,
59 u32 *buf, unsigned int size)
63 __be32 *tmp = (__be32 *)buf;
65 err = snd_fw_transaction(bebob->unit, TCODE_READ_BLOCK_REQUEST,
66 SAFFIRE_ADDRESS_BASE + offset,
71 for (i = 0; i < size / sizeof(u32); i++)
72 buf[i] = be32_to_cpu(tmp[i]);
78 saffire_read_quad(struct snd_bebob *bebob, u64 offset, u32 *value)
83 err = snd_fw_transaction(bebob->unit, TCODE_READ_QUADLET_REQUEST,
84 SAFFIRE_ADDRESS_BASE + offset,
85 &tmp, sizeof(__be32), 0);
89 *value = be32_to_cpu(tmp);
95 saffire_write_quad(struct snd_bebob *bebob, u64 offset, u32 value)
97 __be32 data = cpu_to_be32(value);
99 return snd_fw_transaction(bebob->unit, TCODE_WRITE_QUADLET_REQUEST,
100 SAFFIRE_ADDRESS_BASE + offset,
101 &data, sizeof(__be32), 0);
104 static char *const saffirepro_26_clk_src_labels[] = {
105 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "ADAT1", "ADAT2", "Word Clock"
108 static char *const saffirepro_10_clk_src_labels[] = {
109 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "Word Clock"
112 saffirepro_both_clk_freq_get(struct snd_bebob *bebob, unsigned int *rate)
117 err = saffire_read_quad(bebob, SAFFIREPRO_RATE_NOREBOOT, &id);
120 if (id >= ARRAY_SIZE(rates))
128 saffirepro_both_clk_freq_set(struct snd_bebob *bebob, unsigned int rate)
132 for (id = 0; id < ARRAY_SIZE(rates); id++) {
133 if (rates[id] == rate)
136 if (id == ARRAY_SIZE(rates))
139 return saffire_write_quad(bebob, SAFFIREPRO_RATE_NOREBOOT, id);
142 saffirepro_both_clk_src_get(struct snd_bebob *bebob, unsigned int *id)
147 err = saffire_read_quad(bebob, SAFFIREPRO_OFFSET_CLOCK_SOURCE, &value);
151 if (bebob->spec->clock->labels == saffirepro_10_clk_src_labels) {
152 if (value == SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK)
154 else if (value == SAFFIREPRO_CLOCK_SOURCE_SPDIF)
156 } else if (value > 1) {
163 struct snd_bebob_spec saffire_le_spec;
164 static char *const saffire_both_clk_src_labels[] = {
165 SND_BEBOB_CLOCK_INTERNAL, "S/PDIF"
168 saffire_both_clk_src_get(struct snd_bebob *bebob, unsigned int *id)
173 err = saffire_read_quad(bebob, SAFFIRE_OFFSET_CLOCK_SOURCE, &value);
179 static char *const saffire_le_meter_labels[] = {
180 ANA_IN, ANA_IN, DIG_IN,
181 ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,
184 static char *const saffire_meter_labels[] = {
186 STM_IN, STM_IN, STM_IN, STM_IN, STM_IN,
189 saffire_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)
191 struct snd_bebob_meter_spec *spec = bebob->spec->meter;
192 unsigned int channels;
196 if (spec->labels == saffire_le_meter_labels)
197 offset = SAFFIRE_LE_OFFSET_METER;
199 offset = SAFFIRE_OFFSET_METER;
201 channels = spec->num * 2;
202 if (size < channels * sizeof(u32))
205 err = saffire_read_block(bebob, offset, buf, size);
206 if (err >= 0 && spec->labels == saffire_le_meter_labels) {
207 swap(buf[1], buf[3]);
208 swap(buf[2], buf[3]);
209 swap(buf[3], buf[4]);
211 swap(buf[7], buf[10]);
212 swap(buf[8], buf[10]);
213 swap(buf[9], buf[11]);
214 swap(buf[11], buf[12]);
216 swap(buf[15], buf[16]);
222 static struct snd_bebob_rate_spec saffirepro_both_rate_spec = {
223 .get = &saffirepro_both_clk_freq_get,
224 .set = &saffirepro_both_clk_freq_set,
226 /* Saffire Pro 26 I/O */
227 static struct snd_bebob_clock_spec saffirepro_26_clk_spec = {
228 .num = ARRAY_SIZE(saffirepro_26_clk_src_labels),
229 .labels = saffirepro_26_clk_src_labels,
230 .get = &saffirepro_both_clk_src_get,
232 struct snd_bebob_spec saffirepro_26_spec = {
233 .clock = &saffirepro_26_clk_spec,
234 .rate = &saffirepro_both_rate_spec,
237 /* Saffire Pro 10 I/O */
238 static struct snd_bebob_clock_spec saffirepro_10_clk_spec = {
239 .num = ARRAY_SIZE(saffirepro_10_clk_src_labels),
240 .labels = saffirepro_10_clk_src_labels,
241 .get = &saffirepro_both_clk_src_get,
243 struct snd_bebob_spec saffirepro_10_spec = {
244 .clock = &saffirepro_10_clk_spec,
245 .rate = &saffirepro_both_rate_spec,
249 static struct snd_bebob_rate_spec saffire_both_rate_spec = {
250 .get = &snd_bebob_stream_get_rate,
251 .set = &snd_bebob_stream_set_rate,
253 static struct snd_bebob_clock_spec saffire_both_clk_spec = {
254 .num = ARRAY_SIZE(saffire_both_clk_src_labels),
255 .labels = saffire_both_clk_src_labels,
256 .get = &saffire_both_clk_src_get,
259 static struct snd_bebob_meter_spec saffire_le_meter_spec = {
260 .num = ARRAY_SIZE(saffire_le_meter_labels),
261 .labels = saffire_le_meter_labels,
262 .get = &saffire_meter_get,
264 struct snd_bebob_spec saffire_le_spec = {
265 .clock = &saffire_both_clk_spec,
266 .rate = &saffire_both_rate_spec,
267 .meter = &saffire_le_meter_spec
270 static struct snd_bebob_meter_spec saffire_meter_spec = {
271 .num = ARRAY_SIZE(saffire_meter_labels),
272 .labels = saffire_meter_labels,
273 .get = &saffire_meter_get,
275 struct snd_bebob_spec saffire_spec = {
276 .clock = &saffire_both_clk_spec,
277 .rate = &saffire_both_rate_spec,
278 .meter = &saffire_meter_spec