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 /* clock sources as returned from register of Saffire Pro 10 and 26 */
31 #define SAFFIREPRO_CLOCK_SOURCE_INTERNAL 0
32 #define SAFFIREPRO_CLOCK_SOURCE_SKIP 1 /* never used on hardware */
33 #define SAFFIREPRO_CLOCK_SOURCE_SPDIF 2
34 #define SAFFIREPRO_CLOCK_SOURCE_ADAT1 3 /* not used on s.pro. 10 */
35 #define SAFFIREPRO_CLOCK_SOURCE_ADAT2 4 /* not used on s.pro. 10 */
36 #define SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK 5
37 #define SAFFIREPRO_CLOCK_SOURCE_COUNT 6
39 /* S/PDIF, ADAT1, ADAT2 is enabled or not. three quadlets */
40 #define SAFFIREPRO_ENABLE_DIG_IFACES 0x01a4
42 /* saffirepro has its own parameter for sampling frequency */
43 #define SAFFIREPRO_RATE_NOREBOOT 0x01cc
44 /* index is the value for this register */
45 static const unsigned int rates
[] = {
55 /* saffire(no label)/saffire LE has metering */
56 #define SAFFIRE_OFFSET_METER 0x0100
57 #define SAFFIRE_LE_OFFSET_METER 0x0168
60 saffire_read_block(struct snd_bebob
*bebob
, u64 offset
,
61 u32
*buf
, unsigned int size
)
65 __be32
*tmp
= (__be32
*)buf
;
67 err
= snd_fw_transaction(bebob
->unit
, TCODE_READ_BLOCK_REQUEST
,
68 SAFFIRE_ADDRESS_BASE
+ offset
,
73 for (i
= 0; i
< size
/ sizeof(u32
); i
++)
74 buf
[i
] = be32_to_cpu(tmp
[i
]);
80 saffire_read_quad(struct snd_bebob
*bebob
, u64 offset
, u32
*value
)
85 err
= snd_fw_transaction(bebob
->unit
, TCODE_READ_QUADLET_REQUEST
,
86 SAFFIRE_ADDRESS_BASE
+ offset
,
87 &tmp
, sizeof(__be32
), 0);
91 *value
= be32_to_cpu(tmp
);
97 saffire_write_quad(struct snd_bebob
*bebob
, u64 offset
, u32 value
)
99 __be32 data
= cpu_to_be32(value
);
101 return snd_fw_transaction(bebob
->unit
, TCODE_WRITE_QUADLET_REQUEST
,
102 SAFFIRE_ADDRESS_BASE
+ offset
,
103 &data
, sizeof(__be32
), 0);
106 static const char *const saffirepro_10_clk_src_labels
[] = {
107 SND_BEBOB_CLOCK_INTERNAL
, "S/PDIF", "Word Clock"
109 static enum snd_bebob_clock_type saffirepro_10_clk_src_types
[] = {
110 SND_BEBOB_CLOCK_TYPE_INTERNAL
,
111 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* S/PDIF */
112 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* Word Clock */
114 static const char *const saffirepro_26_clk_src_labels
[] = {
115 SND_BEBOB_CLOCK_INTERNAL
, "S/PDIF", "ADAT1", "ADAT2", "Word Clock"
117 static enum snd_bebob_clock_type saffirepro_26_clk_src_types
[] = {
118 SND_BEBOB_CLOCK_TYPE_INTERNAL
,
119 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* S/PDIF */
120 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* ADAT1 */
121 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* ADAT2 */
122 SND_BEBOB_CLOCK_TYPE_EXTERNAL
, /* Word Clock */
124 /* Value maps between registers and labels for SaffirePro 10/26. */
125 static const signed char saffirepro_clk_maps
[][SAFFIREPRO_CLOCK_SOURCE_COUNT
] = {
128 [SAFFIREPRO_CLOCK_SOURCE_INTERNAL
] = 0,
129 [SAFFIREPRO_CLOCK_SOURCE_SKIP
] = -1, /* not supported */
130 [SAFFIREPRO_CLOCK_SOURCE_SPDIF
] = 1,
131 [SAFFIREPRO_CLOCK_SOURCE_ADAT1
] = -1, /* not supported */
132 [SAFFIREPRO_CLOCK_SOURCE_ADAT2
] = -1, /* not supported */
133 [SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK
] = 2,
137 [SAFFIREPRO_CLOCK_SOURCE_INTERNAL
] = 0,
138 [SAFFIREPRO_CLOCK_SOURCE_SKIP
] = -1, /* not supported */
139 [SAFFIREPRO_CLOCK_SOURCE_SPDIF
] = 1,
140 [SAFFIREPRO_CLOCK_SOURCE_ADAT1
] = 2,
141 [SAFFIREPRO_CLOCK_SOURCE_ADAT2
] = 3,
142 [SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK
] = 4,
147 saffirepro_both_clk_freq_get(struct snd_bebob
*bebob
, unsigned int *rate
)
152 err
= saffire_read_quad(bebob
, SAFFIREPRO_RATE_NOREBOOT
, &id
);
155 if (id
>= ARRAY_SIZE(rates
))
163 saffirepro_both_clk_freq_set(struct snd_bebob
*bebob
, unsigned int rate
)
167 for (id
= 0; id
< ARRAY_SIZE(rates
); id
++) {
168 if (rates
[id
] == rate
)
171 if (id
== ARRAY_SIZE(rates
))
174 return saffire_write_quad(bebob
, SAFFIREPRO_RATE_NOREBOOT
, id
);
178 * query hardware for current clock source, return our internally
179 * used clock index in *id, depending on hardware.
182 saffirepro_both_clk_src_get(struct snd_bebob
*bebob
, unsigned int *id
)
185 u32 value
; /* clock source read from hw register */
186 const signed char *map
;
188 err
= saffire_read_quad(bebob
, SAFFIREPRO_OFFSET_CLOCK_SOURCE
, &value
);
192 /* depending on hardware, use a different mapping */
193 if (bebob
->spec
->clock
->types
== saffirepro_10_clk_src_types
)
194 map
= saffirepro_clk_maps
[0];
196 map
= saffirepro_clk_maps
[1];
198 /* In a case that this driver cannot handle the value of register. */
199 if (value
>= SAFFIREPRO_CLOCK_SOURCE_COUNT
|| map
[value
] < 0) {
204 *id
= (unsigned int)map
[value
];
209 struct snd_bebob_spec saffire_le_spec
;
210 static const char *const saffire_both_clk_src_labels
[] = {
211 SND_BEBOB_CLOCK_INTERNAL
, "S/PDIF"
213 static enum snd_bebob_clock_type saffire_both_clk_src_types
[] = {
214 SND_BEBOB_CLOCK_TYPE_INTERNAL
,
215 SND_BEBOB_CLOCK_TYPE_EXTERNAL
,
218 saffire_both_clk_src_get(struct snd_bebob
*bebob
, unsigned int *id
)
223 err
= saffire_read_quad(bebob
, SAFFIRE_OFFSET_CLOCK_SOURCE
, &value
);
229 static const char *const saffire_le_meter_labels
[] = {
230 ANA_IN
, ANA_IN
, DIG_IN
,
231 ANA_OUT
, ANA_OUT
, ANA_OUT
, ANA_OUT
,
234 static const char *const saffire_meter_labels
[] = {
236 STM_IN
, STM_IN
, STM_IN
, STM_IN
, STM_IN
,
239 saffire_meter_get(struct snd_bebob
*bebob
, u32
*buf
, unsigned int size
)
241 struct snd_bebob_meter_spec
*spec
= bebob
->spec
->meter
;
242 unsigned int channels
;
246 if (spec
->labels
== saffire_le_meter_labels
)
247 offset
= SAFFIRE_LE_OFFSET_METER
;
249 offset
= SAFFIRE_OFFSET_METER
;
251 channels
= spec
->num
* 2;
252 if (size
< channels
* sizeof(u32
))
255 err
= saffire_read_block(bebob
, offset
, buf
, size
);
256 if (err
>= 0 && spec
->labels
== saffire_le_meter_labels
) {
257 swap(buf
[1], buf
[3]);
258 swap(buf
[2], buf
[3]);
259 swap(buf
[3], buf
[4]);
261 swap(buf
[7], buf
[10]);
262 swap(buf
[8], buf
[10]);
263 swap(buf
[9], buf
[11]);
264 swap(buf
[11], buf
[12]);
266 swap(buf
[15], buf
[16]);
272 static struct snd_bebob_rate_spec saffirepro_both_rate_spec
= {
273 .get
= &saffirepro_both_clk_freq_get
,
274 .set
= &saffirepro_both_clk_freq_set
,
276 /* Saffire Pro 26 I/O */
277 static struct snd_bebob_clock_spec saffirepro_26_clk_spec
= {
278 .num
= ARRAY_SIZE(saffirepro_26_clk_src_types
),
279 .labels
= saffirepro_26_clk_src_labels
,
280 .types
= saffirepro_26_clk_src_types
,
281 .get
= &saffirepro_both_clk_src_get
,
283 struct snd_bebob_spec saffirepro_26_spec
= {
284 .clock
= &saffirepro_26_clk_spec
,
285 .rate
= &saffirepro_both_rate_spec
,
288 /* Saffire Pro 10 I/O */
289 static struct snd_bebob_clock_spec saffirepro_10_clk_spec
= {
290 .num
= ARRAY_SIZE(saffirepro_10_clk_src_types
),
291 .labels
= saffirepro_10_clk_src_labels
,
292 .types
= saffirepro_10_clk_src_types
,
293 .get
= &saffirepro_both_clk_src_get
,
295 struct snd_bebob_spec saffirepro_10_spec
= {
296 .clock
= &saffirepro_10_clk_spec
,
297 .rate
= &saffirepro_both_rate_spec
,
301 static struct snd_bebob_rate_spec saffire_both_rate_spec
= {
302 .get
= &snd_bebob_stream_get_rate
,
303 .set
= &snd_bebob_stream_set_rate
,
305 static struct snd_bebob_clock_spec saffire_both_clk_spec
= {
306 .num
= ARRAY_SIZE(saffire_both_clk_src_types
),
307 .labels
= saffire_both_clk_src_labels
,
308 .types
= saffire_both_clk_src_types
,
309 .get
= &saffire_both_clk_src_get
,
312 static struct snd_bebob_meter_spec saffire_le_meter_spec
= {
313 .num
= ARRAY_SIZE(saffire_le_meter_labels
),
314 .labels
= saffire_le_meter_labels
,
315 .get
= &saffire_meter_get
,
317 struct snd_bebob_spec saffire_le_spec
= {
318 .clock
= &saffire_both_clk_spec
,
319 .rate
= &saffire_both_rate_spec
,
320 .meter
= &saffire_le_meter_spec
323 static struct snd_bebob_meter_spec saffire_meter_spec
= {
324 .num
= ARRAY_SIZE(saffire_meter_labels
),
325 .labels
= saffire_meter_labels
,
326 .get
= &saffire_meter_get
,
328 struct snd_bebob_spec saffire_spec
= {
329 .clock
= &saffire_both_clk_spec
,
330 .rate
= &saffire_both_rate_spec
,
331 .meter
= &saffire_meter_spec