2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-05-31 12:51:31 +00:00
|
|
|
/*
|
|
|
|
* Clock domain and sample rate management functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/audio.h>
|
|
|
|
#include <linux/usb/audio-v2.h>
|
2018-03-21 00:03:59 +00:00
|
|
|
#include <linux/usb/audio-v3.h>
|
2010-05-31 12:51:31 +00:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/info.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
|
|
|
|
#include "usbaudio.h"
|
|
|
|
#include "card.h"
|
|
|
|
#include "helper.h"
|
2010-06-16 15:57:27 +00:00
|
|
|
#include "clock.h"
|
2013-04-09 16:56:03 +00:00
|
|
|
#include "quirks.h"
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc {
|
|
|
|
struct uac_clock_source_descriptor v2;
|
|
|
|
struct uac3_clock_source_descriptor v3;
|
|
|
|
};
|
|
|
|
|
|
|
|
union uac23_clock_selector_desc {
|
|
|
|
struct uac_clock_selector_descriptor v2;
|
|
|
|
struct uac3_clock_selector_descriptor v3;
|
|
|
|
};
|
|
|
|
|
|
|
|
union uac23_clock_multiplier_desc {
|
|
|
|
struct uac_clock_multiplier_descriptor v2;
|
|
|
|
struct uac_clock_multiplier_descriptor v3;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_VAL(p, proto, field) \
|
|
|
|
((proto) == UAC_VERSION_3 ? (p)->v3.field : (p)->v2.field)
|
|
|
|
|
2018-04-03 15:34:57 +00:00
|
|
|
static void *find_uac_clock_desc(struct usb_host_interface *iface, int id,
|
2021-05-18 15:21:11 +00:00
|
|
|
bool (*validator)(void *, int, int),
|
|
|
|
u8 type, int proto)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
2018-04-03 15:34:57 +00:00
|
|
|
void *cs = NULL;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2018-04-03 15:34:57 +00:00
|
|
|
while ((cs = snd_usb_find_csint_desc(iface->extra, iface->extralen,
|
|
|
|
cs, type))) {
|
2021-05-18 15:21:11 +00:00
|
|
|
if (validator(cs, id, proto))
|
2010-05-31 12:51:31 +00:00
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
static bool validate_clock_source(void *p, int id, int proto)
|
2018-03-21 00:03:59 +00:00
|
|
|
{
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc *cs = p;
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
return GET_VAL(cs, proto, bClockID) == id;
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
static bool validate_clock_selector(void *p, int id, int proto)
|
2018-03-21 00:03:59 +00:00
|
|
|
{
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_selector_desc *cs = p;
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
return GET_VAL(cs, proto, bClockID) == id;
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
static bool validate_clock_multiplier(void *p, int id, int proto)
|
2018-03-21 00:03:59 +00:00
|
|
|
{
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_multiplier_desc *cs = p;
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
return GET_VAL(cs, proto, bClockID) == id;
|
2018-04-03 15:34:57 +00:00
|
|
|
}
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
#define DEFINE_FIND_HELPER(name, obj, validator, type2, type3) \
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
static obj *name(struct snd_usb_audio *chip, int id, \
|
|
|
|
const struct audioformat *fmt) \
|
2021-05-18 15:21:11 +00:00
|
|
|
{ \
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf = \
|
|
|
|
snd_usb_find_ctrl_interface(chip, fmt->iface); \
|
|
|
|
return find_uac_clock_desc(ctrl_intf, id, validator, \
|
|
|
|
fmt->protocol == UAC_VERSION_3 ? (type3) : (type2), \
|
|
|
|
fmt->protocol); \
|
2018-03-21 00:03:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 15:34:57 +00:00
|
|
|
DEFINE_FIND_HELPER(snd_usb_find_clock_source,
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc, validate_clock_source,
|
|
|
|
UAC2_CLOCK_SOURCE, UAC3_CLOCK_SOURCE);
|
2018-04-03 15:34:57 +00:00
|
|
|
DEFINE_FIND_HELPER(snd_usb_find_clock_selector,
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_selector_desc, validate_clock_selector,
|
|
|
|
UAC2_CLOCK_SELECTOR, UAC3_CLOCK_SELECTOR);
|
2018-04-03 15:34:57 +00:00
|
|
|
DEFINE_FIND_HELPER(snd_usb_find_clock_multiplier,
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_multiplier_desc, validate_clock_multiplier,
|
|
|
|
UAC2_CLOCK_MULTIPLIER, UAC3_CLOCK_MULTIPLIER);
|
2018-04-03 15:34:57 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
static int uac_clock_selector_get_val(struct snd_usb_audio *chip,
|
|
|
|
int selector_id, int iface_no)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2010-05-31 12:51:31 +00:00
|
|
|
unsigned char buf;
|
|
|
|
int ret;
|
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, iface_no);
|
2010-05-31 12:51:31 +00:00
|
|
|
ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0),
|
|
|
|
UAC2_CS_CUR,
|
|
|
|
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
|
2010-06-11 15:34:20 +00:00
|
|
|
UAC2_CX_CLOCK_SELECTOR << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (selector_id << 8),
|
2011-09-26 19:15:27 +00:00
|
|
|
&buf, sizeof(buf));
|
2010-05-31 12:51:31 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
static int uac_clock_selector_set_val(struct snd_usb_audio *chip,
|
|
|
|
int selector_id, unsigned char pin, int iface_no)
|
2013-04-03 21:18:55 +00:00
|
|
|
{
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2013-04-03 21:18:55 +00:00
|
|
|
int ret;
|
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, iface_no);
|
2013-04-03 21:18:55 +00:00
|
|
|
ret = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
|
|
|
|
UAC2_CS_CUR,
|
|
|
|
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
|
|
|
|
UAC2_CX_CLOCK_SELECTOR << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (selector_id << 8),
|
2013-04-03 21:18:55 +00:00
|
|
|
&pin, sizeof(pin));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret != sizeof(pin)) {
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_err(chip,
|
|
|
|
"setting selector (id %d) unexpected length %d\n",
|
|
|
|
selector_id, ret);
|
2013-04-03 21:18:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ret = uac_clock_selector_get_val(chip, selector_id, iface_no);
|
2013-04-03 21:18:55 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret != pin) {
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_err(chip,
|
|
|
|
"setting selector (id %d) to %x failed (current: %d)\n",
|
|
|
|
selector_id, pin, ret);
|
2013-04-03 21:18:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-02-12 23:54:50 +00:00
|
|
|
static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt,
|
2020-02-12 23:54:50 +00:00
|
|
|
int source_id)
|
|
|
|
{
|
2020-02-29 15:18:15 +00:00
|
|
|
bool ret = false;
|
|
|
|
int count;
|
|
|
|
unsigned char data;
|
|
|
|
struct usb_device *dev = chip->dev;
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc *cs_desc;
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2020-02-29 15:18:15 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface);
|
|
|
|
cs_desc = snd_usb_find_clock_source(chip, source_id, fmt);
|
2021-05-18 15:21:11 +00:00
|
|
|
if (!cs_desc)
|
|
|
|
return false;
|
2020-02-12 23:54:50 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
if (fmt->protocol == UAC_VERSION_2) {
|
2020-02-29 15:18:15 +00:00
|
|
|
/*
|
|
|
|
* Assume the clock is valid if clock source supports only one
|
|
|
|
* single sample rate, the terminal is connected directly to it
|
|
|
|
* (there is no clock selector) and clock type is internal.
|
|
|
|
* This is to deal with some Denon DJ controllers that always
|
|
|
|
* reports that clock is invalid.
|
|
|
|
*/
|
|
|
|
if (fmt->nr_rates == 1 &&
|
2021-05-18 15:21:11 +00:00
|
|
|
(fmt->clock & 0xff) == cs_desc->v2.bClockID &&
|
|
|
|
(cs_desc->v2.bmAttributes & 0x3) !=
|
2020-02-29 15:18:15 +00:00
|
|
|
UAC_CLOCK_SOURCE_TYPE_EXT)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MOTU MicroBook IIc
|
|
|
|
* Sample rate changes takes more than 2 seconds for this device. Clock
|
|
|
|
* validity request returns false during that period.
|
|
|
|
*/
|
|
|
|
if (chip->usb_id == USB_ID(0x07fd, 0x0004)) {
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
while ((!ret) && (count < 50)) {
|
|
|
|
int err;
|
|
|
|
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
|
|
|
|
UAC2_CS_CONTROL_CLOCK_VALID << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (source_id << 8),
|
2020-02-29 15:18:15 +00:00
|
|
|
&data, sizeof(data));
|
|
|
|
if (err < 0) {
|
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"%s(): cannot get clock validity for id %d\n",
|
|
|
|
__func__, source_id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = !!data;
|
|
|
|
count++;
|
|
|
|
}
|
2020-02-12 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 15:18:15 +00:00
|
|
|
return ret;
|
2020-02-12 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:03:59 +00:00
|
|
|
static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt,
|
2018-03-21 00:03:59 +00:00
|
|
|
int source_id)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned char data;
|
|
|
|
struct usb_device *dev = chip->dev;
|
2018-03-21 00:03:59 +00:00
|
|
|
u32 bmControls;
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc *cs_desc;
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2018-03-21 00:03:59 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface);
|
|
|
|
cs_desc = snd_usb_find_clock_source(chip, source_id, fmt);
|
2021-05-18 15:21:11 +00:00
|
|
|
if (!cs_desc)
|
|
|
|
return false;
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
if (fmt->protocol == UAC_VERSION_3)
|
|
|
|
bmControls = le32_to_cpu(cs_desc->v3.bmControls);
|
|
|
|
else
|
|
|
|
bmControls = cs_desc->v2.bmControls;
|
2011-05-18 09:28:44 +00:00
|
|
|
|
|
|
|
/* If a clock source can't tell us whether it's valid, we assume it is */
|
2018-03-21 00:03:59 +00:00
|
|
|
if (!uac_v2v3_control_is_readable(bmControls,
|
2018-03-22 21:39:55 +00:00
|
|
|
UAC2_CS_CONTROL_CLOCK_VALID))
|
2019-10-29 17:52:00 +00:00
|
|
|
return true;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
|
|
|
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
|
2010-06-11 15:34:20 +00:00
|
|
|
UAC2_CS_CONTROL_CLOCK_VALID << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (source_id << 8),
|
2011-09-26 19:15:27 +00:00
|
|
|
&data, sizeof(data));
|
2010-05-31 12:51:31 +00:00
|
|
|
|
|
|
|
if (err < 0) {
|
2014-02-26 12:02:17 +00:00
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"%s(): cannot get clock validity for id %d\n",
|
2010-05-31 12:51:31 +00:00
|
|
|
__func__, source_id);
|
2019-10-29 17:52:00 +00:00
|
|
|
return false;
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:54:50 +00:00
|
|
|
if (data)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return uac_clock_source_is_valid_quirk(chip, fmt, source_id);
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:54:50 +00:00
|
|
|
static int __uac_clock_find_source(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt, int entity_id,
|
2018-03-21 00:03:59 +00:00
|
|
|
unsigned long *visited, bool validate)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc *source;
|
|
|
|
union uac23_clock_selector_desc *selector;
|
|
|
|
union uac23_clock_multiplier_desc *multiplier;
|
|
|
|
int ret, i, cur, err, pins, clock_id;
|
|
|
|
const u8 *sources;
|
|
|
|
int proto = fmt->protocol;
|
2024-01-25 20:54:57 +00:00
|
|
|
bool readable, writeable;
|
|
|
|
u32 bmControls;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
|
|
|
entity_id &= 0xff;
|
|
|
|
|
|
|
|
if (test_and_set_bit(entity_id, visited)) {
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_warn(chip,
|
|
|
|
"%s(): recursive clock topology detected, id %d.\n",
|
|
|
|
__func__, entity_id);
|
2010-05-31 12:51:31 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-09-25 02:33:51 +00:00
|
|
|
/* first, see if the ID we're looking at is a clock source already */
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
source = snd_usb_find_clock_source(chip, entity_id, fmt);
|
2013-04-03 21:18:54 +00:00
|
|
|
if (source) {
|
2021-05-18 15:21:11 +00:00
|
|
|
entity_id = GET_VAL(source, proto, bClockID);
|
2020-02-12 23:54:50 +00:00
|
|
|
if (validate && !uac_clock_source_is_valid(chip, fmt,
|
2018-03-21 00:03:59 +00:00
|
|
|
entity_id)) {
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_err(chip,
|
|
|
|
"clock source %d is not valid, cannot use\n",
|
|
|
|
entity_id);
|
2013-04-03 21:18:54 +00:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
return entity_id;
|
|
|
|
}
|
2010-05-31 12:51:31 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
selector = snd_usb_find_clock_selector(chip, entity_id, fmt);
|
2010-05-31 12:51:31 +00:00
|
|
|
if (selector) {
|
2021-05-18 15:21:11 +00:00
|
|
|
pins = GET_VAL(selector, proto, bNrInPins);
|
|
|
|
clock_id = GET_VAL(selector, proto, bClockID);
|
|
|
|
sources = GET_VAL(selector, proto, baCSourceID);
|
2021-05-20 12:37:42 +00:00
|
|
|
cur = 0;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2024-01-25 20:54:57 +00:00
|
|
|
if (proto == UAC_VERSION_3)
|
|
|
|
bmControls = le32_to_cpu(*(__le32 *)(&selector->v3.baCSourceID[0] + pins));
|
|
|
|
else
|
|
|
|
bmControls = *(__u8 *)(&selector->v2.baCSourceID[0] + pins);
|
|
|
|
|
|
|
|
readable = uac_v2v3_control_is_readable(bmControls,
|
|
|
|
UAC2_CX_CLOCK_SELECTOR);
|
|
|
|
writeable = uac_v2v3_control_is_writeable(bmControls,
|
|
|
|
UAC2_CX_CLOCK_SELECTOR);
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
if (pins == 1) {
|
2021-01-20 21:39:31 +00:00
|
|
|
ret = 1;
|
|
|
|
goto find_source;
|
|
|
|
}
|
|
|
|
|
2024-01-25 20:54:57 +00:00
|
|
|
/* for now just warn about buggy device */
|
|
|
|
if (!readable)
|
|
|
|
usb_audio_warn(chip,
|
|
|
|
"%s(): clock selector control is not readable, id %d\n",
|
|
|
|
__func__, clock_id);
|
|
|
|
|
2021-09-25 02:33:51 +00:00
|
|
|
/* the entity ID we are looking at is a selector.
|
2010-05-31 12:51:31 +00:00
|
|
|
* find out what it currently selects */
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ret = uac_clock_selector_get_val(chip, clock_id, fmt->iface);
|
2021-05-18 15:21:12 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
if (!chip->autoclock)
|
|
|
|
return ret;
|
|
|
|
goto find_others;
|
|
|
|
}
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2010-06-16 15:57:30 +00:00
|
|
|
/* Selector values are one-based */
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
if (ret > pins || ret < 1) {
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_err(chip,
|
2010-05-31 12:51:31 +00:00
|
|
|
"%s(): selector reported illegal value, id %d, ret %d\n",
|
2021-05-18 15:21:11 +00:00
|
|
|
__func__, clock_id, ret);
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2021-05-18 15:21:12 +00:00
|
|
|
if (!chip->autoclock)
|
|
|
|
return -EINVAL;
|
|
|
|
goto find_others;
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 21:39:31 +00:00
|
|
|
find_source:
|
2013-04-03 21:18:55 +00:00
|
|
|
cur = ret;
|
2020-02-12 23:54:50 +00:00
|
|
|
ret = __uac_clock_find_source(chip, fmt,
|
2021-05-18 15:21:11 +00:00
|
|
|
sources[ret - 1],
|
2020-02-12 23:54:50 +00:00
|
|
|
visited, validate);
|
2021-04-13 08:41:52 +00:00
|
|
|
if (ret > 0) {
|
2021-07-29 07:38:52 +00:00
|
|
|
/* Skip setting clock selector again for some devices */
|
2024-01-23 13:46:35 +00:00
|
|
|
if (chip->quirk_flags & QUIRK_FLAG_SKIP_CLOCK_SELECTOR ||
|
2024-01-28 13:23:38 +00:00
|
|
|
!writeable)
|
2021-07-24 04:23:41 +00:00
|
|
|
return ret;
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
err = uac_clock_selector_set_val(chip, entity_id, cur, fmt->iface);
|
2024-02-01 11:53:08 +00:00
|
|
|
if (err < 0) {
|
|
|
|
if (pins == 1) {
|
|
|
|
usb_audio_dbg(chip,
|
|
|
|
"%s(): selector returned an error, "
|
|
|
|
"assuming a firmware bug, id %d, ret %d\n",
|
|
|
|
__func__, clock_id, err);
|
|
|
|
return ret;
|
|
|
|
}
|
2021-04-13 08:41:52 +00:00
|
|
|
return err;
|
2024-02-01 11:53:08 +00:00
|
|
|
}
|
2021-04-13 08:41:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 21:18:56 +00:00
|
|
|
if (!validate || ret > 0 || !chip->autoclock)
|
2013-04-03 21:18:55 +00:00
|
|
|
return ret;
|
|
|
|
|
2021-05-18 15:21:12 +00:00
|
|
|
find_others:
|
2024-01-25 20:54:57 +00:00
|
|
|
if (!writeable)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2013-04-03 21:18:55 +00:00
|
|
|
/* The current clock source is invalid, try others. */
|
2021-05-18 15:21:11 +00:00
|
|
|
for (i = 1; i <= pins; i++) {
|
2013-04-03 21:18:55 +00:00
|
|
|
if (i == cur)
|
|
|
|
continue;
|
|
|
|
|
2020-02-12 23:54:50 +00:00
|
|
|
ret = __uac_clock_find_source(chip, fmt,
|
2021-05-18 15:21:11 +00:00
|
|
|
sources[i - 1],
|
2020-02-12 23:54:50 +00:00
|
|
|
visited, true);
|
2013-04-03 21:18:55 +00:00
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
err = uac_clock_selector_set_val(chip, entity_id, i, fmt->iface);
|
2013-04-03 21:18:55 +00:00
|
|
|
if (err < 0)
|
|
|
|
continue;
|
|
|
|
|
2014-02-26 12:02:17 +00:00
|
|
|
usb_audio_info(chip,
|
|
|
|
"found and selected valid clock source %d\n",
|
|
|
|
ret);
|
2013-04-03 21:18:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENXIO;
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: multipliers only act as pass-thru element for now */
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
multiplier = snd_usb_find_clock_multiplier(chip, entity_id, fmt);
|
2010-05-31 12:51:31 +00:00
|
|
|
if (multiplier)
|
2020-02-12 23:54:50 +00:00
|
|
|
return __uac_clock_find_source(chip, fmt,
|
2021-05-18 15:21:11 +00:00
|
|
|
GET_VAL(multiplier, proto, bCSourceID),
|
2018-03-21 00:03:59 +00:00
|
|
|
visited, validate);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-16 15:57:30 +00:00
|
|
|
/*
|
|
|
|
* For all kinds of sample rate settings and other device queries,
|
|
|
|
* the clock source (end-leaf) must be used. However, clock selectors,
|
|
|
|
* clock multipliers and sample rate converters may be specified as
|
|
|
|
* clock source input to terminal. This functions walks the clock path
|
|
|
|
* to its end and tries to find the source.
|
|
|
|
*
|
|
|
|
* The 'visited' bitfield is used internally to detect recursive loops.
|
|
|
|
*
|
|
|
|
* Returns the clock source UnitID (>=0) on success, or an error.
|
|
|
|
*/
|
2020-02-12 23:54:50 +00:00
|
|
|
int snd_usb_clock_find_source(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt, bool validate)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
|
|
|
DECLARE_BITMAP(visited, 256);
|
|
|
|
memset(visited, 0, sizeof(visited));
|
2018-03-21 00:03:59 +00:00
|
|
|
|
2020-02-12 23:54:50 +00:00
|
|
|
switch (fmt->protocol) {
|
2018-03-21 00:03:59 +00:00
|
|
|
case UAC_VERSION_2:
|
|
|
|
case UAC_VERSION_3:
|
2021-05-18 15:21:11 +00:00
|
|
|
return __uac_clock_find_source(chip, fmt, fmt->clock, visited,
|
2018-03-21 00:03:59 +00:00
|
|
|
validate);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 08:53:25 +00:00
|
|
|
static int set_sample_rate_v1(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt, int rate)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
|
|
|
struct usb_device *dev = chip->dev;
|
|
|
|
unsigned char data[3];
|
|
|
|
int err, crate;
|
|
|
|
|
|
|
|
/* if endpoint doesn't have sampling rate control, bail out */
|
2010-07-08 14:38:01 +00:00
|
|
|
if (!(fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE))
|
2010-05-31 12:51:31 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
data[0] = rate;
|
|
|
|
data[1] = rate >> 8;
|
|
|
|
data[2] = rate >> 16;
|
2018-05-27 13:18:22 +00:00
|
|
|
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
|
2021-01-18 07:58:14 +00:00
|
|
|
UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
|
|
|
|
fmt->endpoint, data, sizeof(data));
|
2018-05-27 13:18:22 +00:00
|
|
|
if (err < 0) {
|
2014-02-26 12:02:17 +00:00
|
|
|
dev_err(&dev->dev, "%d:%d: cannot set freq %d to ep %#x\n",
|
2021-01-18 07:58:14 +00:00
|
|
|
fmt->iface, fmt->altsetting, rate, fmt->endpoint);
|
2010-05-31 12:51:31 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-02-16 20:44:33 +00:00
|
|
|
/* Don't check the sample rate for devices which we know don't
|
|
|
|
* support reading */
|
2021-07-29 07:38:47 +00:00
|
|
|
if (chip->quirk_flags & QUIRK_FLAG_GET_SAMPLE_RATE)
|
2015-02-16 20:44:33 +00:00
|
|
|
return 0;
|
2016-04-29 09:49:04 +00:00
|
|
|
/* the firmware is likely buggy, don't repeat to fail too many times */
|
|
|
|
if (chip->sample_rate_read_error > 2)
|
|
|
|
return 0;
|
2015-02-16 20:44:33 +00:00
|
|
|
|
2018-05-27 13:18:22 +00:00
|
|
|
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
|
2021-01-18 07:58:14 +00:00
|
|
|
UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
|
|
|
|
fmt->endpoint, data, sizeof(data));
|
2018-05-27 13:18:22 +00:00
|
|
|
if (err < 0) {
|
2014-02-26 12:02:17 +00:00
|
|
|
dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n",
|
2021-01-18 07:58:14 +00:00
|
|
|
fmt->iface, fmt->altsetting, fmt->endpoint);
|
2016-04-29 09:49:04 +00:00
|
|
|
chip->sample_rate_read_error++;
|
2010-05-31 12:51:31 +00:00
|
|
|
return 0; /* some devices don't support reading */
|
|
|
|
}
|
|
|
|
|
|
|
|
crate = data[0] | (data[1] << 8) | (data[2] << 16);
|
2020-12-18 14:58:58 +00:00
|
|
|
if (!crate) {
|
|
|
|
dev_info(&dev->dev, "failed to read current rate; disabling the check\n");
|
|
|
|
chip->sample_rate_read_error = 3; /* three strikes, see above */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-31 12:51:31 +00:00
|
|
|
if (crate != rate) {
|
2014-02-26 12:02:17 +00:00
|
|
|
dev_warn(&dev->dev, "current rate %d is different from the runtime rate %d\n", crate, rate);
|
2010-05-31 12:51:31 +00:00
|
|
|
// runtime->rate = crate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:03:59 +00:00
|
|
|
static int get_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
|
2013-04-03 17:08:29 +00:00
|
|
|
int altsetting, int clock)
|
|
|
|
{
|
|
|
|
struct usb_device *dev = chip->dev;
|
2013-04-03 21:18:53 +00:00
|
|
|
__le32 data;
|
2013-04-03 17:08:29 +00:00
|
|
|
int err;
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2013-04-03 17:08:29 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, iface);
|
2013-04-03 17:08:29 +00:00
|
|
|
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
|
|
|
|
UAC2_CS_CONTROL_SAM_FREQ << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (clock << 8),
|
2013-04-03 21:18:53 +00:00
|
|
|
&data, sizeof(data));
|
2013-04-03 17:08:29 +00:00
|
|
|
if (err < 0) {
|
2018-03-21 00:03:59 +00:00
|
|
|
dev_warn(&dev->dev, "%d:%d: cannot get freq (v2/v3): err %d\n",
|
2014-02-26 12:02:17 +00:00
|
|
|
iface, altsetting, err);
|
2013-04-03 17:08:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:18:53 +00:00
|
|
|
return le32_to_cpu(data);
|
2013-04-03 17:08:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 08:53:09 +00:00
|
|
|
/*
|
|
|
|
* Try to set the given sample rate:
|
|
|
|
*
|
|
|
|
* Return 0 if the clock source is read-only, the actual rate on success,
|
|
|
|
* or a negative error code.
|
|
|
|
*
|
|
|
|
* This function gets called from format.c to validate each sample rate, too.
|
|
|
|
* Hence no message is shown upon error
|
|
|
|
*/
|
|
|
|
int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip,
|
|
|
|
const struct audioformat *fmt,
|
|
|
|
int clock, int rate)
|
|
|
|
{
|
|
|
|
bool writeable;
|
|
|
|
u32 bmControls;
|
|
|
|
__le32 data;
|
|
|
|
int err;
|
2021-05-18 15:21:11 +00:00
|
|
|
union uac23_clock_source_desc *cs_desc;
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
struct usb_host_interface *ctrl_intf;
|
2020-11-23 08:53:09 +00:00
|
|
|
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface);
|
|
|
|
cs_desc = snd_usb_find_clock_source(chip, clock, fmt);
|
2021-10-24 11:17:36 +00:00
|
|
|
|
|
|
|
if (!cs_desc)
|
|
|
|
return 0;
|
|
|
|
|
2021-05-18 15:21:11 +00:00
|
|
|
if (fmt->protocol == UAC_VERSION_3)
|
|
|
|
bmControls = le32_to_cpu(cs_desc->v3.bmControls);
|
|
|
|
else
|
|
|
|
bmControls = cs_desc->v2.bmControls;
|
2020-11-23 08:53:09 +00:00
|
|
|
|
|
|
|
writeable = uac_v2v3_control_is_writeable(bmControls,
|
|
|
|
UAC2_CS_CONTROL_SAM_FREQ);
|
|
|
|
if (!writeable)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
data = cpu_to_le32(rate);
|
|
|
|
err = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC2_CS_CUR,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
|
|
|
|
UAC2_CS_CONTROL_SAM_FREQ << 8,
|
ALSA: usb-audio: Support multiple control interfaces
Registering Numark Party Mix II fails with error 'bogus bTerminalLink 1'.
The problem stems from the driver not being able to find input/output
terminals required to configure audio streaming. The information about
those terminals is stored in AudioControl Interface. Numark device
contains 2 AudioControl Interfaces and the driver checks only one of them.
According to the USB standard, a device can have multiple audio functions,
each represented by Audio Interface Collection. Every audio function is
considered to be closed box and will contain unique AudioControl Interface
and zero or more AudioStreaming and MIDIStreaming Interfaces.
The Numark device adheres to the standard and defines two audio functions:
- MIDIStreaming function
- AudioStreaming function
It starts with MIDI function, followed by the audio function. The driver
saves the first AudioControl Interface in `snd_usb_audio` structure
associated with the entire device. It then attempts to use this interface
to query for terminals and clocks. However, this fails because the correct
information is stored in the second AudioControl Interface, defined in the
second Audio Interface Collection.
This patch introduces a structure holding association between each
MIDI/Audio Interface and its corresponding AudioControl Interface,
instead of relying on AudioControl Interface defined for the entire
device. This structure is populated during usb probing phase and leveraged
later when querying for terminals and when sending USB requests.
Alternative solutions considered include:
- defining a quirk for Numark where the order of interface is manually
changed, or terminals are hardcoded in the driver. This solution would
have fixed only this model, though it seems that device is USB compliant,
and it also seems that other devices from this company may be affected.
What's more, it looks like products from other manufacturers have similar
problems, i.e. Rane One DJ console
- keeping a list of all AudioControl Interfaces and querying all of them
to find required information. That would have solved my problem and have
low probability of breaking other devices, as we would always start with
the same logic of querying first AudioControl Interface. This solution
would not have followed the standard though.
This patch preserves the `snd_usb_audio.ctrl_intf` variable, which holds
the first AudioControl Interface, and uses it as a fallback when some
interfaces are not parsed correctly and lack an associated AudioControl
Interface, i.e., when configured via quirks.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217865
Signed-off-by: Karol Kosik <k.kosik@outlook.com>
Link: https://patch.msgid.link/AS8P190MB1285893F4735C8B32AD3886BEC852@AS8P190MB1285.EURP190.PROD.OUTLOOK.COM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-08-12 00:29:56 +00:00
|
|
|
snd_usb_ctrl_intf(ctrl_intf) | (clock << 8),
|
2020-11-23 08:53:09 +00:00
|
|
|
&data, sizeof(data));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return get_sample_rate_v2v3(chip, fmt->iface, fmt->altsetting, clock);
|
|
|
|
}
|
|
|
|
|
2020-11-23 08:53:25 +00:00
|
|
|
static int set_sample_rate_v2v3(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt, int rate)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
2020-11-23 08:53:09 +00:00
|
|
|
int cur_rate, prev_rate;
|
2013-04-03 21:18:55 +00:00
|
|
|
int clock;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2018-07-18 20:41:05 +00:00
|
|
|
/* First, try to find a valid clock. This may trigger
|
|
|
|
* automatic clock selection if the current clock is not
|
|
|
|
* valid.
|
|
|
|
*/
|
2020-02-12 23:54:50 +00:00
|
|
|
clock = snd_usb_clock_find_source(chip, fmt, true);
|
2018-07-18 20:41:05 +00:00
|
|
|
if (clock < 0) {
|
|
|
|
/* We did not find a valid clock, but that might be
|
|
|
|
* because the current sample rate does not match an
|
|
|
|
* external clock source. Try again without validation
|
|
|
|
* and we will do another validation after setting the
|
|
|
|
* rate.
|
|
|
|
*/
|
2020-02-12 23:54:50 +00:00
|
|
|
clock = snd_usb_clock_find_source(chip, fmt, false);
|
2021-06-10 08:35:28 +00:00
|
|
|
|
2021-07-29 07:38:52 +00:00
|
|
|
/* Hardcoded sample rates */
|
|
|
|
if (chip->quirk_flags & QUIRK_FLAG_IGNORE_CLOCK_SOURCE)
|
2021-06-10 08:35:28 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-07-18 20:41:05 +00:00
|
|
|
if (clock < 0)
|
|
|
|
return clock;
|
|
|
|
}
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2020-11-23 08:53:25 +00:00
|
|
|
prev_rate = get_sample_rate_v2v3(chip, fmt->iface, fmt->altsetting, clock);
|
2013-04-25 12:32:24 +00:00
|
|
|
if (prev_rate == rate)
|
2018-07-18 20:41:05 +00:00
|
|
|
goto validation;
|
2013-03-26 21:10:05 +00:00
|
|
|
|
2020-11-23 08:53:09 +00:00
|
|
|
cur_rate = snd_usb_set_sample_rate_v2v3(chip, fmt, clock, rate);
|
|
|
|
if (cur_rate < 0) {
|
|
|
|
usb_audio_err(chip,
|
|
|
|
"%d:%d: cannot set freq %d (v2/v3): err %d\n",
|
2020-11-23 08:53:25 +00:00
|
|
|
fmt->iface, fmt->altsetting, rate, cur_rate);
|
2020-11-23 08:53:09 +00:00
|
|
|
return cur_rate;
|
2018-03-21 00:03:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 08:53:09 +00:00
|
|
|
if (!cur_rate)
|
2013-04-03 21:18:58 +00:00
|
|
|
cur_rate = prev_rate;
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2013-03-26 21:10:05 +00:00
|
|
|
if (cur_rate != rate) {
|
2021-02-27 08:20:02 +00:00
|
|
|
usb_audio_dbg(chip,
|
|
|
|
"%d:%d: freq mismatch: req %d, clock runs @%d\n",
|
|
|
|
fmt->iface, fmt->altsetting, rate, cur_rate);
|
|
|
|
/* continue processing */
|
2013-03-26 21:10:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-21 06:46:27 +00:00
|
|
|
/* FIXME - TEAC devices require the immediate interface setup */
|
2022-05-31 13:07:49 +00:00
|
|
|
if (USB_ID_VENDOR(chip->usb_id) == 0x0644) {
|
|
|
|
bool cur_base_48k = (rate % 48000 == 0);
|
|
|
|
bool prev_base_48k = (prev_rate % 48000 == 0);
|
|
|
|
if (cur_base_48k != prev_base_48k) {
|
|
|
|
usb_set_interface(chip->dev, fmt->iface, fmt->altsetting);
|
|
|
|
if (chip->quirk_flags & QUIRK_FLAG_IFACE_DELAY)
|
|
|
|
msleep(50);
|
|
|
|
}
|
2022-05-21 06:46:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:41:05 +00:00
|
|
|
validation:
|
|
|
|
/* validate clock after rate change */
|
2020-02-12 23:54:50 +00:00
|
|
|
if (!uac_clock_source_is_valid(chip, fmt, clock))
|
2018-07-18 20:41:05 +00:00
|
|
|
return -ENXIO;
|
2010-05-31 12:51:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-23 08:53:25 +00:00
|
|
|
int snd_usb_init_sample_rate(struct snd_usb_audio *chip,
|
2020-11-23 08:53:33 +00:00
|
|
|
const struct audioformat *fmt, int rate)
|
2010-05-31 12:51:31 +00:00
|
|
|
{
|
ALSA: usb-audio: Refactor endpoint management
This is an intensive surgery for the endpoint and stream management
for achieving more robust and clean code.
The goals of this patch are:
- More clear endpoint resource changes
- The interface altsetting control in a single place
Below are brief description of the whole changes.
First off, most of the endpoint operations are moved into endpoint.c,
so that the snd_usb_endpoint object is only referred in other places.
The endpoint object is acquired and released via the new functions
snd_usb_endpoint_open() and snd_usb_endpoint_close() that are called
at PCM hw_params and hw_free callbacks, respectively. Those are
ref-counted and EPs can manage the multiple opens.
The open callback receives the audioformat and hw_params arguments,
and those are used for initializing the EP parameters; especially the
endpoint, interface and altset numbers are read from there, as well as
the PCM parameters like the format, rate and channels. Those are
stored in snd_usb_endpoint object. If it's the secondary open, the
function checks whether the given parameters are compatible with the
already opened EP setup, too.
The coupling with a sync EP (including an implicit feedback sync) is
done by the sole snd_usb_endpoint_set_sync() call.
The configuration of each endpoint is done in a single shot via
snd_usb_endpoint_configure() call. This is the place where most of
PCM configurations are done. A few flags and special handling in the
snd_usb_substream are dropped along with this change.
A significant difference wrt the configuration from the previous code
is the order of USB host interface setups. Now the interface is
always disabled at beginning and (re-)enabled at the last step of
snd_usb_endpoint_configure(), in order to be compliant with the
standard UAC2/3. For UAC1, the interface is set before the parameter
setups since there seem devices that require it (e.g. Yamaha THR10),
just like how it was done in the previous driver code.
The start/stop are almost same as before, also single-shots. The URB
callbacks need to be set via snd_usb_endpoint_set_callback() like the
previous code at the trigger phase, too.
Finally, the flag for the re-setup is set at the device suspend
through the full EP list, instead of PCM trigger. This catches the
overlooked cases where the PCM hasn't been running yet but the device
needs the full setup after resume.
Tested-by: Keith Milner <kamilner@superlative.org>
Tested-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-26-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-11-23 08:53:31 +00:00
|
|
|
usb_audio_dbg(chip, "%d:%d Set sample rate %d, clock %d\n",
|
|
|
|
fmt->iface, fmt->altsetting, rate, fmt->clock);
|
|
|
|
|
2013-01-31 20:39:17 +00:00
|
|
|
switch (fmt->protocol) {
|
2010-05-31 12:51:31 +00:00
|
|
|
case UAC_VERSION_1:
|
2010-09-03 08:53:11 +00:00
|
|
|
default:
|
2020-11-23 08:53:25 +00:00
|
|
|
return set_sample_rate_v1(chip, fmt, rate);
|
2010-05-31 12:51:31 +00:00
|
|
|
|
2018-03-21 00:03:59 +00:00
|
|
|
case UAC_VERSION_3:
|
2018-05-04 01:24:04 +00:00
|
|
|
if (chip->badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) {
|
|
|
|
if (rate != UAC3_BADD_SAMPLING_RATE)
|
|
|
|
return -ENXIO;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-08 20:32:36 +00:00
|
|
|
fallthrough;
|
2018-05-04 01:24:04 +00:00
|
|
|
case UAC_VERSION_2:
|
2020-11-23 08:53:25 +00:00
|
|
|
return set_sample_rate_v2v3(chip, fmt, rate);
|
2010-05-31 12:51:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|