mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
6aa8700150
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>
108 lines
2.5 KiB
C
108 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* UAC3 Power Domain state management functions
|
|
*/
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/usb.h>
|
|
#include <linux/usb/audio.h>
|
|
#include <linux/usb/audio-v2.h>
|
|
#include <linux/usb/audio-v3.h>
|
|
|
|
#include "usbaudio.h"
|
|
#include "helper.h"
|
|
#include "power.h"
|
|
|
|
struct snd_usb_power_domain *
|
|
snd_usb_find_power_domain(struct usb_host_interface *ctrl_iface,
|
|
unsigned char id)
|
|
{
|
|
struct snd_usb_power_domain *pd;
|
|
void *p;
|
|
|
|
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
|
|
if (!pd)
|
|
return NULL;
|
|
|
|
p = NULL;
|
|
while ((p = snd_usb_find_csint_desc(ctrl_iface->extra,
|
|
ctrl_iface->extralen,
|
|
p, UAC3_POWER_DOMAIN)) != NULL) {
|
|
struct uac3_power_domain_descriptor *pd_desc = p;
|
|
int i;
|
|
|
|
if (!snd_usb_validate_audio_desc(p, UAC_VERSION_3))
|
|
continue;
|
|
for (i = 0; i < pd_desc->bNrEntities; i++) {
|
|
if (pd_desc->baEntityID[i] == id) {
|
|
pd->pd_id = pd_desc->bPowerDomainID;
|
|
pd->pd_d1d0_rec =
|
|
le16_to_cpu(pd_desc->waRecoveryTime1);
|
|
pd->pd_d2d0_rec =
|
|
le16_to_cpu(pd_desc->waRecoveryTime2);
|
|
pd->ctrl_iface = ctrl_iface;
|
|
return pd;
|
|
}
|
|
}
|
|
}
|
|
|
|
kfree(pd);
|
|
return NULL;
|
|
}
|
|
|
|
int snd_usb_power_domain_set(struct snd_usb_audio *chip,
|
|
struct snd_usb_power_domain *pd,
|
|
unsigned char state)
|
|
{
|
|
struct usb_device *dev = chip->dev;
|
|
unsigned char current_state;
|
|
int err, idx;
|
|
|
|
idx = snd_usb_ctrl_intf(pd->ctrl_iface) | (pd->pd_id << 8);
|
|
|
|
err = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0),
|
|
UAC2_CS_CUR,
|
|
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
|
|
UAC3_AC_POWER_DOMAIN_CONTROL << 8, idx,
|
|
¤t_state, sizeof(current_state));
|
|
if (err < 0) {
|
|
dev_err(&dev->dev, "Can't get UAC3 power state for id %d\n",
|
|
pd->pd_id);
|
|
return err;
|
|
}
|
|
|
|
if (current_state == state) {
|
|
dev_dbg(&dev->dev, "UAC3 power domain id %d already in state %d\n",
|
|
pd->pd_id, state);
|
|
return 0;
|
|
}
|
|
|
|
err = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC2_CS_CUR,
|
|
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
|
|
UAC3_AC_POWER_DOMAIN_CONTROL << 8, idx,
|
|
&state, sizeof(state));
|
|
if (err < 0) {
|
|
dev_err(&dev->dev, "Can't set UAC3 power state to %d for id %d\n",
|
|
state, pd->pd_id);
|
|
return err;
|
|
}
|
|
|
|
if (state == UAC3_PD_STATE_D0) {
|
|
switch (current_state) {
|
|
case UAC3_PD_STATE_D2:
|
|
udelay(pd->pd_d2d0_rec * 50);
|
|
break;
|
|
case UAC3_PD_STATE_D1:
|
|
udelay(pd->pd_d1d0_rec * 50);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
dev_dbg(&dev->dev, "UAC3 power domain id %d change to state %d\n",
|
|
pd->pd_id, state);
|
|
|
|
return 0;
|
|
}
|