aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffrey D. Bennett2021-06-22 03:39:13 +0930
committerTakashi Iwai2021-06-22 21:35:59 +0200
commitacf91b8122c7f61d60e05852bcbb880b72c00968 (patch)
tree986bc92a994274a59fdd357f16e59ee3d10598ff
parent1f7fa6e5afbf20a28ce7c20149825946f25c1059 (diff)
ALSA: usb-audio: scarlett2: Update initialisation sequence
The old initialisation code only works with Gen 2 devices. Replace it with an initialisation sequence that works on both Gen 2 and Gen 3 devices. Signed-off-by: Geoffrey D. Bennett <g@b4.vu> Link: https://lore.kernel.org/r/6e5c4fedb74b813872f6a4b7fba30b6c471fa63a.1624294591.git.g@b4.vu Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/usb/mixer_scarlett_gen2.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 6b77582d8e3d..ed89e28548c8 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -453,10 +453,12 @@ static int scarlett2_get_port_start_num(const struct scarlett2_ports *ports,
#define SCARLETT2_USB_NOTIFY_MONITOR 0x00400000
/* Commands for sending/receiving requests/responses */
+#define SCARLETT2_USB_CMD_INIT 0
#define SCARLETT2_USB_CMD_REQ 2
#define SCARLETT2_USB_CMD_RESP 3
-#define SCARLETT2_USB_INIT_SEQ 0x00000000
+#define SCARLETT2_USB_INIT_1 0x00000000
+#define SCARLETT2_USB_INIT_2 0x00000002
#define SCARLETT2_USB_GET_METER 0x00001001
#define SCARLETT2_USB_GET_MIX 0x00002001
#define SCARLETT2_USB_SET_MIX 0x00002002
@@ -650,14 +652,19 @@ static int scarlett2_usb(
if (err != resp_buf_size) {
usb_audio_err(
mixer->chip,
- "Scarlett Gen 2 USB response result cmd %x was %d\n",
- cmd, err);
+ "Scarlett Gen 2 USB response result cmd %x was %d "
+ "expected %d\n",
+ cmd, err, resp_buf_size);
err = -EINVAL;
goto unlock;
}
+ /* cmd/seq/size should match except when initialising
+ * seq sent = 1, response = 0
+ */
if (resp->cmd != req->cmd ||
- resp->seq != req->seq ||
+ (resp->seq != req->seq &&
+ (le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
resp_size != le16_to_cpu(resp->size) ||
resp->error ||
resp->pad) {
@@ -675,7 +682,7 @@ static int scarlett2_usb(
goto unlock;
}
- if (resp_size > 0)
+ if (resp_data && resp_size > 0)
memcpy(resp_data, resp->data, resp_size);
unlock:
@@ -1924,13 +1931,12 @@ static int scarlett2_find_fc_interface(struct usb_device *dev,
return -EINVAL;
}
-/* Initialise private data, sequence number, and get the USB data */
+/* Initialise private data */
static int scarlett2_init_private(struct usb_mixer_interface *mixer,
const struct scarlett2_device_info *info)
{
struct scarlett2_data *private =
kzalloc(sizeof(struct scarlett2_data), GFP_KERNEL);
- int err;
if (!private)
return -ENOMEM;
@@ -1948,12 +1954,35 @@ static int scarlett2_init_private(struct usb_mixer_interface *mixer,
private->scarlett2_seq = 0;
private->mixer = mixer;
- err = scarlett2_find_fc_interface(mixer->chip->dev, private);
+ return scarlett2_find_fc_interface(mixer->chip->dev, private);
+}
+
+/* Cargo cult proprietary initialisation sequence */
+static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
+{
+ struct usb_device *dev = mixer->chip->dev;
+ struct scarlett2_data *private = mixer->private_data;
+ u8 buf[24];
+ int err;
+
+ if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
+ return -EINVAL;
+
+ /* step 0 */
+ err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
+ SCARLETT2_USB_CMD_INIT, buf, sizeof(buf));
if (err < 0)
return err;
- /* Initialise the sequence number used for the proprietary commands */
- return scarlett2_usb(mixer, SCARLETT2_USB_INIT_SEQ, NULL, 0, NULL, 0);
+ /* step 1 */
+ private->scarlett2_seq = 1;
+ err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_1, NULL, 0, NULL, 0);
+ if (err < 0)
+ return err;
+
+ /* step 2 */
+ private->scarlett2_seq = 1;
+ return scarlett2_usb(mixer, SCARLETT2_USB_INIT_2, NULL, 0, NULL, 84);
}
/* Read configuration from the interface on start */
@@ -2128,11 +2157,16 @@ static int snd_scarlett_gen2_controls_create(struct usb_mixer_interface *mixer,
{
int err;
- /* Initialise private data, sequence number, and get the USB data */
+ /* Initialise private data */
err = scarlett2_init_private(mixer, info);
if (err < 0)
return err;
+ /* Send proprietary USB initialisation sequence */
+ err = scarlett2_usb_init(mixer);
+ if (err < 0)
+ return err;
+
/* Read volume levels and controls from the interface */
err = scarlett2_read_configs(mixer);
if (err < 0)