ALSA: usb-audio: Scarlett Gen 2 mixer interface
PATCH RESEND v6 1/1 ALSA: usb-audio: Scarlett Gen 2 mixer interface
Add mixer quirk for the Focusrite Scarlett 6i6, 18i8, and 18i20 Gen 2 audio interfaces. Although the interfaces are USB compliant, additional input/output level controls and hardware routing/mixing functionality are available using proprietary USB requests.
---
Hi all,
This patch adds the following controls for the Scarlett 6i6, 18i8, and 18i20 Gen 2:
- Master volume knob indicator (18i20 only)
- Mute and dim switches (18i20 only)
- Volume controls for the analogue HW outputs
- HW/SW volume switches for the 10 analogue HW outputs (18i20 only)
- Line Level/Instrument Level and Pad controls (6i6 and 18i8 only)
- Output mux (where the sound for the HW outputs comes from; defaults to PCM outputs)
- Capture mux (where the sound for PCM recording comes from; defaults to HW inputs)
- Matrix mux (where the sound going into the mixer comes from; 18 inputs default off)
- Mixer matrix (18 inputs * 10 outputs = 180 controls)
- Level meters
Changes since v1:
- Add support for the Scarlett 18i8 Gen 2
- Save configuration parameters to NVRAM
- Implemented feedback from Takashi's email 24/Apr/2019
- Moved private field from struct snd_usb_audio to struct usb_mixer_interface
- Added timer and buffer fields to struct usb_mixer_interface
- Other small code fixes/cleanups/improvements
Changes since v2:
- Add support for the Scarlett 6i6 Gen 2
- Add support for controlling the mute/dim switches (18i20 only)
- Implemented feedback from Takashi's email 29/Apr/2019: One pointer field private_data and one function pointer private_free. Replaced timer with delayed work (thanks for that suggestion; it makes the code a *lot* simpler!).
- The new functionality is disabled by default as there were reports of some Gen 2 devices not responding to the initialisation sequence and hanging. Added module parameter "scarlett_gen2_mixer_enable". If this parameter is not set, logs a message "Focusrite Scarlett Gen 2 Mixer Driver disabled; use options snd_usb_audio scarlett_gen2_mixer_enable=1 to enable and report any issues to [email protected]".
Changes since v3:
- No functional changes; fix checkpatch.pl error and typo in declaration.
Changes since v4:
- Implemented feedback from Takashi's email 9/Jul/2019: cancel delayed work on suspend, drop copyright texts, remove unnecessary blank lines, and run kmalloc outside the mutex.
Changes since v5:
- Implemented feedback from Takashi's emails 9-10/Jul/2019: use chip->setup value (device_setup option) instead of the scarlett_gen2_mixer_enable option and sync config to NVRAM immediately on suspend.
- Fixed issue where the config save delayed work would be cancelled and not restarted if a scarlett2_*_ctl_put() function was called and the parameter value was not changed.
- Renaming definitions and functions for consistency and move private free/suspend functions above their use so pre-declaration isn't necessary.
sound/usb/Makefile +1 -0
@@ -11,6 +11,7 @@ snd-usb-audio-objs := card.o \ mixer.o \ mixer_quirks.o \ mixer_scarlett.o \ + mixer_scarlett_gen2.o \ mixer_us16x08.o \ pcm.o \ power.o \
sound/usb/mixer.c +4 -0
@@ -3505,6 +3505,8 @@ void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer)usb_kill_urb (mixer->urb);if (mixer->rc_urb)usb_kill_urb (mixer->rc_urb); +if (mixer->private_free) + mixer->private_free (mixer); mixer->disconnected = true; }
@@ -3532,6 +3534,8 @@ static int snd_usb_mixer_activate(struct usb_mixer_interface *mixer)int snd_usb_mixer_suspend (struct usb_mixer_interface *mixer) {snd_usb_mixer_inactivate (mixer); +if (mixer->private_suspend) + mixer->private_suspend (mixer);return 0 ; }
sound/usb/mixer.h +4 -0
@@ -28,6 +28,10 @@ struct usb_mixer_interface {struct media_mixer_ctl *media_mixer_ctl;bool disconnected; + +void *private_data; +void (*private_free)(struct usb_mixer_interface *mixer); +void (*private_suspend)(struct usb_mixer_interface *mixer); };#define MAX_CHANNELS 16/* max logical channels */
sound/usb/mixer_quirks.c +7 -0
@@ -32,6 +32,7 @@#include "mixer.h" #include "mixer_quirks.h" #include "mixer_scarlett.h" +#include "mixer_scarlett_gen2.h" #include "mixer_us16x08.h" #include "helper.h"
@@ -2258,6 +2259,12 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) err =snd_scarlett_controls_create (mixer);break ; +case USB_ID (0x1235 ,0x8203 ):/* Focusrite Scarlett 6i6 2nd Gen */ +case USB_ID (0x1235 ,0x8204 ):/* Focusrite Scarlett 18i8 2nd Gen */ +case USB_ID (0x1235 ,0x8201 ):/* Focusrite Scarlett 18i20 2nd Gen */ + err =snd_scarlett_gen2_controls_create (mixer); +break ; +case USB_ID (0x041e ,0x323b ):/* Creative Sound Blaster E1 */ err =snd_soundblaster_e1_switch_create (mixer);break ;
sound/usb/mixer_scarlett_gen2.c new file +2076 -0
2,076 lines not on this page · raw message
sound/usb/mixer_scarlett_gen2.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __USB_MIXER_SCARLETT_GEN2_H +#define __USB_MIXER_SCARLETT_GEN2_H + +int snd_scarlett_gen2_controls_create (struct usb_mixer_interface *mixer); + +#endif /* __USB_MIXER_SCARLETT_GEN2_H */
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 59 lines · Geoffrey D. Bennett
Add mixer quirk for the Focusrite Scarlett 6i6, 18i8, and 18i20 Gen 2 audio interfaces. Although the interfaces are USB compliant, additional input/output level controls and hardware routing/mixing functionality are available using proprietary USB requests.
Signed-off-by Geoffrey D. Bennett <[email protected]>---
Hi all,This patch adds the following controls for the Scarlett 6i6, 18i8, and 18i20 Gen 2:
- Master volume knob indicator (18i20 only)
- Mute and dim switches (18i20 only)
- Volume controls for the analogue HW outputs
- HW/SW volume switches for the 10 analogue HW outputs (18i20 only)
- Line Level/Instrument Level and Pad controls (6i6 and 18i8 only)
- Output mux (where the sound for the HW outputs comes from; defaults to PCM outputs)
- Capture mux (where the sound for PCM recording comes from; defaults to HW inputs)
- Matrix mux (where the sound going into the mixer comes from; 18 inputs default off)
- Mixer matrix (18 inputs * 10 outputs = 180 controls)
- Level metersChanges since v1:
- Add support for the Scarlett 18i8 Gen 2
- Save configuration parameters to NVRAM
- Implemented feedback from Takashi's email 24/Apr/2019
- Moved private field from structsnd_usb_audioto structusb_mixer_interface
- Added timer and buffer fields to structusb_mixer_interface
- Other small code fixes/cleanups/improvementsChanges since v2:
- Add support for the Scarlett 6i6 Gen 2
- Add support for controlling the mute/dim switches (18i20 only)
- Implemented feedback from Takashi's email 29/Apr/2019: One pointer fieldprivate_dataand one function pointerprivate_free. Replaced timer with delayed work (thanks for that suggestion; it makes the code a *lot* simpler!).
- The new functionality is disabled by default as there were reports of some Gen 2 devices not responding to the initialisation sequence and hanging. Added module parameter "scarlett_gen2_mixer_enable". If this parameter is not set, logs a message "Focusrite Scarlett Gen 2 Mixer Driver disabled; use optionssnd_usb_audioscarlett_gen2_mixer_enable=1 to enable and report any issues to [email protected]".Changes since v3:
- No functional changes; fix checkpatch.pl error and typo in declaration.Changes since v4:
- Implemented feedback from Takashi's email 9/Jul/2019: cancel delayed work on suspend, drop copyright texts, remove unnecessary blank lines, and run kmalloc outside the mutex.
Quoted 11 lines
Changes since v5:
- Implemented feedback from Takashi's emails 9-10/Jul/2019: usechip->setupvalue (device_setupoption) instead of thescarlett_gen2_mixer_enableoption and sync config to NVRAM immediately on suspend.
- Fixed issue where the config save delayed work would be cancelled and not restarted if a scarlett2_*_ctl_put() function was called and the parameter value was not changed.
- Renaming definitions and functions for consistency and move private free/suspend functions above their use so pre-declaration isn't necessary.
Thanks, the patch looks almost good, but it's already too late for 5.3, so I'm going to queue this for 5.4 after 5.3 merge window is closed in this week.
But, before that, maybe one more refresh would be appreciated. Namely,
- We need a verification of the fixed pipe before actually submitting urb. scarlett2_usb() calls with usb_sndctrlpipe(), and this pipe has to be verified beforehand. See the commit 801ebf1043ae for details.
- Some pointers seem to be initialized as "0". Use NULL instead.
Takashi
Hi Takashi,
On Thu, Jul 18, 2019 at 05:53:13PM +0200, Takashi Iwai wrote:
[...]
Quoted 3 lines
Thanks, the patch looks almost good, but it's already too late for 5.3, so I'm going to queue this for 5.4 after 5.3 merge window is closed in this week.
Thank you. I really appreciate your assistance and feedback.
Quoted 7 lines
But, before that, maybe one more refresh would be appreciated. Namely,
- We need a verification of the fixed pipe before actually submitting urb.
scarlett2_usb()calls withusb_sndctrlpipe(), and this pipe has to be verified beforehand. See the commit801ebf1043aefor details.
I had a look at that commit, and I think I don't need to change scarlett2_usb() because it calls snd_usb_ctl_msg() which already calls the snd_usb_pipe_sanity_check() function to verify the pipe.
I'm thinking though that scarlett2_mixer_status_create() which does something like this:
struct usb_device *dev = mixer->chip->dev; unsigned int pipe = usb_rcvintpipe(dev, SCARLETT2_USB_INTERRUPT_ENDPOINT); ... usb_fill_int_urb(mixer->urb, dev, pipe, ...); usb_submit_urb(mixer->urb, GFP_KERNEL);
probably needs this added:
if (snd_usb_pipe_sanity_check(dev, pipe))
return -EINVAL;
Do you agree?
Quoted 1 line
- Some pointers seem to be initialized as "0". Use NULL instead.
Will fix.
Regards,
Geoffrey.
Quoted 14 lines · Geoffrey D. Bennett
Hi Takashi,
On Thu, Jul 18, 2019 at 05:53:13PM +0200, Takashi Iwai wrote:
[...]Quoted 3 lines
Thanks, the patch looks almost good, but it's already too late for 5.3, so I'm going to queue this for 5.4 after 5.3 merge window is closed in this week.
Thank you. I really appreciate your assistance and feedback.
Quoted 3 lines
But, before that, maybe one more refresh would be appreciated. Namely,
Quoted 8 lines
Quoted 4 lines
- We need a verification of the fixed pipe before actually submitting urb.
scarlett2_usb()calls withusb_sndctrlpipe(), and this pipe has to be verified beforehand. See the commit801ebf1043aefor details.I had a look at that commit, and I think I don't need to change
scarlett2_usb()because it callssnd_usb_ctl_msg()which already calls thesnd_usb_pipe_sanity_check()function to verify the pipe.
Ah right, then it's superfluous.
Quoted 9 lines
I'm thinking though that
scarlett2_mixer_status_create()which does something like this:struct usb_device *dev = mixer->chip->dev; unsigned int pipe = usb_rcvintpipe(dev, SCARLETT2_USB_INTERRUPT_ENDPOINT); ... usb_fill_int_urb(mixer->urb, dev, pipe, ...); usb_submit_urb(mixer->urb, GFP_KERNEL);
Quoted 6 lines
probably needs this added:
if (
snd_usb_pipe_sanity_check(dev, pipe))return -EINVAL;Do you agree?
Yes, if you call directly, you need the verification.
thanks,
Takashi