Skip to contentSkip to conversation

ALSA: usb-audio: Scarlett Gen 2 mixer interface

RFC PATCH Superseded Geoffrey D. Bennett 2 participants 2 messages Apr 29, 2019 Sound

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 ALSA: usb-audio: Scarlett Gen 2 mixer interface

Add mixer quirk for the Focusrite Scarlett 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 18i8 and 18i20 Gen 2:
- Master volume knob indicator (18i20 only)
- Volume controls for the analogue HW outputs
- HW/SW volume switches for the 10 analogue HW outputs (18i20 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)
- Mute and dim indicators (18i20 only)
- Line Level/Instrument Level and Pad controls (18i8 only)
- 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

Outstanding issues/questions:

- Adding fields to struct usb_mixer_interface seemed a better place than struct snd_usb_audio as in version 1 of this patch (I think these new fields are used in the same sort of context as the "Sound Blaster remote control stuff" fields, and I am reusing rc_urb and rc_setup_packet). I wasn't sure of the naming; should they be named generically ("timer", "private") or specifically ("scarlett2_buffer")? Should the Sound Blaster RC fields that I'm reusing be renamed to have generic names?

- There are software controllable pads on the 18i8 line-inputs. I called the controls "Line In %d Pad Capture Switch". They work correctly in alsamixer (shown in the capture view as e.g. "Line In 1 Pad") but the "on" state is displayed as "L R CAPTURE" which looks unusual. I could use an Enum with Off/On values, but I thought this is what "Switch" is for (as per control-names.rst). Should I leave this as-is, or is there a better name that will make this show up as a regular on/off switch?

amixer contents shows:

numid=15,iface=MIXER,name='Line In 1 Pad Capture Switch'

    ; type=BOOLEAN,access=rw------,values=1
    : values=off

amixer scontents shows:

Simple mixer control 'Line In 1 Pad',0
Capabilities: cswitch cswitch-joined
Capture channels: Mono
Mono: Capture [off]

Thanks,
Geoffrey.

sound/usb/Makefile +1 -0
index d330f74c90e6..8cf7081e17cb 100644
@@ -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 +3 -0
index e7d441d0e839..8cd1fc2f7580 100644
@@ -3521,6 +3521,9 @@ 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);
+	kfree(mixer->scarlett2_buffer);
+	del_timer_sync(&mixer->timer);
+	kfree(mixer->private);
 	mixer->disconnected = true;
 }
 
sound/usb/mixer.h +5 -0
index 3d12af8bf191..d009f6cb74b9 100644
@@ -25,6 +25,11 @@ struct usb_mixer_interface {
 	u8 rc_buffer[6];
 
 	bool disconnected;
+
+	/* Scarlett Gen 2 */
+	void *scarlett2_buffer;
+	struct timer_list timer;
+	void *private;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
sound/usb/mixer_quirks.c +6 -0
index 85ae0ff2382a..faa5e149ef10 100644
@@ -45,6 +45,7 @@
 #include "mixer.h"
 #include "mixer_quirks.h"
 #include "mixer_scarlett.h"
+#include "mixer_scarlett_gen2.h"
 #include "mixer_us16x08.h"
 #include "helper.h"
 
@@ -2273,6 +2274,11 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 		err = snd_scarlett_controls_create(mixer);
 		break;
 
+	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 +2032 -0

2,032 lines not on this page · raw message

sound/usb/mixer_scarlett_gen2.h new file +7 -0
new file mode 100644
index 000000000000..52e1dad77afd
@@ -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

#1 lore raw
Quoted 37 lines · Geoffrey D. Bennett

Add mixer quirk for the Focusrite Scarlett 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 18i8 and 18i20 Gen 2:
- Master volume knob indicator (18i20 only)
- Volume controls for the analogue HW outputs
- HW/SW volume switches for the 10 analogue HW outputs (18i20 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)
- Mute and dim indicators (18i20 only)
- Line Level/Instrument Level and Pad controls (18i8 only)
- 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

Outstanding issues/questions:

Quoted 8 lines

- Adding fields to struct usb_mixer_interface seemed a better place than struct snd_usb_audio as in version 1 of this patch (I think these new fields are used in the same sort of context as the "Sound Blaster remote control stuff" fields, and I am reusing rc_urb and rc_setup_packet). I wasn't sure of the naming; should they be named generically ("timer", "private") or specifically ("scarlett2_buffer")? Should the Sound Blaster RC fields that I'm reusing be renamed to have generic names?

The best would be completely without it, but it's a better place, indeed. However, the addition should be only one pointer field private_data and one function pointer private_free. Put the all device specific stuff to private_data and release via the own private_free callback instead.

Quoted 15 lines

- There are software controllable pads on the 18i8 line-inputs. I called the controls "Line In %d Pad Capture Switch". They work correctly in alsamixer (shown in the capture view as e.g. "Line In 1 Pad") but the "on" state is displayed as "L R CAPTURE" which looks unusual. I could use an Enum with Off/On values, but I thought this is what "Switch" is for (as per control-names.rst). Should I leave this as-is, or is there a better name that will make this show up as a regular on/off switch?

amixer contents shows:

numid=15,iface=MIXER,name='Line In 1 Pad Capture Switch'

    ; type=BOOLEAN,access=rw------,values=1
    : values=off
Quoted 6 lines

amixer scontents shows:

Simple mixer control 'Line In 1 Pad',0
Capabilities: cswitch cswitch-joined
Capture channels: Mono
Mono: Capture [off]

It's possible to override per device-specific stuff via a shared-object plugin in alsa-lib, but this is far too complex. Rather leave it as is. alsamixer isn't the best tool for a complicated mixer UI, after all.

About the other changes:
a timer is no suitable choice for such a purpose. The easier option would be the delayed work. Then you can use GFP_KERNEL instead of GFP_ATOMIC.

Also, the delayed work needs to be canceled or flushed at PM suspend callback as well as disconnecting.

thanks,

Takashi