Skip to content

Commit 9f35a31

Browse files
puleglottiwai
authored andcommitted
ALSA: usb-audio: Add clock validity quirk for Denon MC7000/MCX8000
It should be safe to ignore clock validity check result if the following conditions are met: - only one single sample rate is supported; - the terminal is directly connected to the clock source; - the clock type is internal. This is to deal with some Denon DJ controllers that always reports that clock is invalid. Tested-by: Tobias Oszlanyi <[email protected]> Signed-off-by: Alexander Tsoy <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 7dafba3 commit 9f35a31

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

sound/usb/clock.c

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,42 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
151151
return ret;
152152
}
153153

154+
/*
155+
* Assume the clock is valid if clock source supports only one single sample
156+
* rate, the terminal is connected directly to it (there is no clock selector)
157+
* and clock type is internal. This is to deal with some Denon DJ controllers
158+
* that always reports that clock is invalid.
159+
*/
160+
static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip,
161+
struct audioformat *fmt,
162+
int source_id)
163+
{
164+
if (fmt->protocol == UAC_VERSION_2) {
165+
struct uac_clock_source_descriptor *cs_desc =
166+
snd_usb_find_clock_source(chip->ctrl_intf, source_id);
167+
168+
if (!cs_desc)
169+
return false;
170+
171+
return (fmt->nr_rates == 1 &&
172+
(fmt->clock & 0xff) == cs_desc->bClockID &&
173+
(cs_desc->bmAttributes & 0x3) !=
174+
UAC_CLOCK_SOURCE_TYPE_EXT);
175+
}
176+
177+
return false;
178+
}
179+
154180
static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
155-
int protocol,
181+
struct audioformat *fmt,
156182
int source_id)
157183
{
158184
int err;
159185
unsigned char data;
160186
struct usb_device *dev = chip->dev;
161187
u32 bmControls;
162188

163-
if (protocol == UAC_VERSION_3) {
189+
if (fmt->protocol == UAC_VERSION_3) {
164190
struct uac3_clock_source_descriptor *cs_desc =
165191
snd_usb_find_clock_source_v3(chip->ctrl_intf, source_id);
166192

@@ -194,10 +220,14 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
194220
return false;
195221
}
196222

197-
return data ? true : false;
223+
if (data)
224+
return true;
225+
else
226+
return uac_clock_source_is_valid_quirk(chip, fmt, source_id);
198227
}
199228

200-
static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
229+
static int __uac_clock_find_source(struct snd_usb_audio *chip,
230+
struct audioformat *fmt, int entity_id,
201231
unsigned long *visited, bool validate)
202232
{
203233
struct uac_clock_source_descriptor *source;
@@ -217,7 +247,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
217247
source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id);
218248
if (source) {
219249
entity_id = source->bClockID;
220-
if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_2,
250+
if (validate && !uac_clock_source_is_valid(chip, fmt,
221251
entity_id)) {
222252
usb_audio_err(chip,
223253
"clock source %d is not valid, cannot use\n",
@@ -248,8 +278,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
248278
}
249279

250280
cur = ret;
251-
ret = __uac_clock_find_source(chip, selector->baCSourceID[ret - 1],
252-
visited, validate);
281+
ret = __uac_clock_find_source(chip, fmt,
282+
selector->baCSourceID[ret - 1],
283+
visited, validate);
253284
if (!validate || ret > 0 || !chip->autoclock)
254285
return ret;
255286

@@ -260,8 +291,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
260291
if (i == cur)
261292
continue;
262293

263-
ret = __uac_clock_find_source(chip, selector->baCSourceID[i - 1],
264-
visited, true);
294+
ret = __uac_clock_find_source(chip, fmt,
295+
selector->baCSourceID[i - 1],
296+
visited, true);
265297
if (ret < 0)
266298
continue;
267299

@@ -281,14 +313,16 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
281313
/* FIXME: multipliers only act as pass-thru element for now */
282314
multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id);
283315
if (multiplier)
284-
return __uac_clock_find_source(chip, multiplier->bCSourceID,
285-
visited, validate);
316+
return __uac_clock_find_source(chip, fmt,
317+
multiplier->bCSourceID,
318+
visited, validate);
286319

287320
return -EINVAL;
288321
}
289322

290-
static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
291-
unsigned long *visited, bool validate)
323+
static int __uac3_clock_find_source(struct snd_usb_audio *chip,
324+
struct audioformat *fmt, int entity_id,
325+
unsigned long *visited, bool validate)
292326
{
293327
struct uac3_clock_source_descriptor *source;
294328
struct uac3_clock_selector_descriptor *selector;
@@ -307,7 +341,7 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
307341
source = snd_usb_find_clock_source_v3(chip->ctrl_intf, entity_id);
308342
if (source) {
309343
entity_id = source->bClockID;
310-
if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_3,
344+
if (validate && !uac_clock_source_is_valid(chip, fmt,
311345
entity_id)) {
312346
usb_audio_err(chip,
313347
"clock source %d is not valid, cannot use\n",
@@ -338,7 +372,8 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
338372
}
339373

340374
cur = ret;
341-
ret = __uac3_clock_find_source(chip, selector->baCSourceID[ret - 1],
375+
ret = __uac3_clock_find_source(chip, fmt,
376+
selector->baCSourceID[ret - 1],
342377
visited, validate);
343378
if (!validate || ret > 0 || !chip->autoclock)
344379
return ret;
@@ -350,8 +385,9 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
350385
if (i == cur)
351386
continue;
352387

353-
ret = __uac3_clock_find_source(chip, selector->baCSourceID[i - 1],
354-
visited, true);
388+
ret = __uac3_clock_find_source(chip, fmt,
389+
selector->baCSourceID[i - 1],
390+
visited, true);
355391
if (ret < 0)
356392
continue;
357393

@@ -372,7 +408,8 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
372408
multiplier = snd_usb_find_clock_multiplier_v3(chip->ctrl_intf,
373409
entity_id);
374410
if (multiplier)
375-
return __uac3_clock_find_source(chip, multiplier->bCSourceID,
411+
return __uac3_clock_find_source(chip, fmt,
412+
multiplier->bCSourceID,
376413
visited, validate);
377414

378415
return -EINVAL;
@@ -389,18 +426,18 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
389426
*
390427
* Returns the clock source UnitID (>=0) on success, or an error.
391428
*/
392-
int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol,
393-
int entity_id, bool validate)
429+
int snd_usb_clock_find_source(struct snd_usb_audio *chip,
430+
struct audioformat *fmt, bool validate)
394431
{
395432
DECLARE_BITMAP(visited, 256);
396433
memset(visited, 0, sizeof(visited));
397434

398-
switch (protocol) {
435+
switch (fmt->protocol) {
399436
case UAC_VERSION_2:
400-
return __uac_clock_find_source(chip, entity_id, visited,
437+
return __uac_clock_find_source(chip, fmt, fmt->clock, visited,
401438
validate);
402439
case UAC_VERSION_3:
403-
return __uac3_clock_find_source(chip, entity_id, visited,
440+
return __uac3_clock_find_source(chip, fmt, fmt->clock, visited,
404441
validate);
405442
default:
406443
return -EINVAL;
@@ -501,17 +538,15 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
501538
* automatic clock selection if the current clock is not
502539
* valid.
503540
*/
504-
clock = snd_usb_clock_find_source(chip, fmt->protocol,
505-
fmt->clock, true);
541+
clock = snd_usb_clock_find_source(chip, fmt, true);
506542
if (clock < 0) {
507543
/* We did not find a valid clock, but that might be
508544
* because the current sample rate does not match an
509545
* external clock source. Try again without validation
510546
* and we will do another validation after setting the
511547
* rate.
512548
*/
513-
clock = snd_usb_clock_find_source(chip, fmt->protocol,
514-
fmt->clock, false);
549+
clock = snd_usb_clock_find_source(chip, fmt, false);
515550
if (clock < 0)
516551
return clock;
517552
}
@@ -577,7 +612,7 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
577612

578613
validation:
579614
/* validate clock after rate change */
580-
if (!uac_clock_source_is_valid(chip, fmt->protocol, clock))
615+
if (!uac_clock_source_is_valid(chip, fmt, clock))
581616
return -ENXIO;
582617
return 0;
583618
}

sound/usb/clock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
66
struct usb_host_interface *alts,
77
struct audioformat *fmt, int rate);
88

9-
int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol,
10-
int entity_id, bool validate);
9+
int snd_usb_clock_find_source(struct snd_usb_audio *chip,
10+
struct audioformat *fmt, bool validate);
1111

1212
#endif /* __USBAUDIO_CLOCK_H */

sound/usb/format.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip,
336336
struct usb_device *dev = chip->dev;
337337
unsigned char tmp[2], *data;
338338
int nr_triplets, data_size, ret = 0, ret_l6;
339-
int clock = snd_usb_clock_find_source(chip, fp->protocol,
340-
fp->clock, false);
339+
int clock = snd_usb_clock_find_source(chip, fp, false);
341340

342341
if (clock < 0) {
343342
dev_err(&dev->dev,

0 commit comments

Comments
 (0)