ALSA: usb-audio: Add support for Presonus Studio 1810c
PATCH v2 1/1 ALSA: usb-audio: Add support for Presonus Studio 1810c
This patch adds support for Presonus Studio 1810c, a usb interface that's UAC2 compliant with a few quirks and a few extra hw-specific controls. I've tested all 3 altsettings and the added switch controls and they work as expected.
More infos on the card:
https://www.presonus.com/products/Studio-1810c
Note that this work is based on packet inspection with usbmon. I just wanted to get this card to work for using it on our open-source radio station:
https://github.com/UoC-Radio
v2 address issues reported by Takashi:
* Properly get/set enum type controls
* Prevent race condition on switch_get/set
* Various control naming changes
* Various coding style fixes
--- sound/usb/Makefile | 1 + sound/usb/format.c | 17 ++ sound/usb/mixer_quirks.c | 5 + sound/usb/mixer_s1810c.c | 595 +++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_s1810c.h | 7 + sound/usb/quirks.c | 36 +++ 6 files changed, 661 insertions(+) create mode 100644 sound/usb/mixer_s1810c.c create mode 100644 sound/usb/mixer_s1810c.h
sound/usb/Makefile +1 -0
@@ -13,6 +13,7 @@ snd-usb-audio-objs := card.o \ mixer_scarlett.o \ mixer_scarlett_gen2.o \ mixer_us16x08.o \ + mixer_s1810c.o \ pcm.o \ power.o \ proc.o \
sound/usb/format.c +17 -0
@@ -262,6 +262,23 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, }for (rate = min; rate <= max; rate += res) { + +/* +* Presonus Studio 1810c anounces invalid +* sampling rates for its streams. +*/ +if (chip->usb_id ==USB_ID (0x0194f ,0x010c ) && + ((rate >48000 && fp->altsetting ==1 ) || + ((rate <88200 || rate >96000 ) + && fp->altsetting ==2 ) || + ((rate <176400 || rate >192000 ) + && fp->altsetting ==3 ))) { +if (res) +continue ; +else +break ; + } +if (fp->rate_table) fp->rate_table[nr_rates] = rate;if (!fp->rate_min || rate < fp->rate_min)
sound/usb/mixer_quirks.c +5 -0
@@ -34,6 +34,7 @@#include "mixer_scarlett.h" #include "mixer_scarlett_gen2.h" #include "mixer_us16x08.h" +#include "mixer_s1810c.h" #include "helper.h" struct std_mono_table {
@@ -2277,6 +2278,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)case USB_ID (0x2a39 ,0x3fd4 ):/* RME */ err =snd_rme_controls_create (mixer);break ; + +case USB_ID (0x0194f ,0x010c ):/* Presonus Studio 1810c */ + err =snd_sc1810_init_mixer (mixer); +break ; }return err;
sound/usb/mixer_s1810c.c new file +595 -0
595 lines not on this page · raw message
sound/usb/mixer_s1810c.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Presonus Studio 1810c driver for ALSA +* Copyright (C) 2019 Nick Kossifidis <[email protected]> +*/ + +int snd_sc1810_init_mixer (struct usb_mixer_interface *mixer);
sound/usb/quirks.c +36 -0
@@ -1227,6 +1227,38 @@ static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,return 0 ;/* keep this altsetting */ } +static int s1810c_skip_setting_quirk (struct snd_usb_audio *chip, +int iface,int altno) +{ +/* +* Altno settings: +* +* Playback (Interface 1): +* 1: 6 Analog + 2 S/PDIF +* 2: 6 Analog + 2 S/PDIF +* 3: 6 Analog +* +* Capture (Interface 2): +* 1: 8 Analog + 2 S/PDIF + 8 ADAT +* 2: 8 Analog + 2 S/PDIF + 4 ADAT +* 3: 8 Analog +*/ + +/* +* I'll leave 2 as the default one and +* use device_setup to switch to the +* other two. +*/ +if ((chip->setup ==0 || chip->setup >2 ) && altno !=2 ) +return 1 ; +else if (chip->setup ==1 && altno !=1 ) +return 1 ; +else if (chip->setup ==2 && altno !=3 ) +return 1 ; + +return 0 ; +} +int snd_usb_apply_interface_quirk (struct snd_usb_audio *chip,int iface,int altno)
@@ -1240,6 +1272,10 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,/* fasttrackpro usb: skip altsets incompatible with device_setup */ if (chip->usb_id ==USB_ID (0x0763 ,0x2012 ))return fasttrackpro_skip_setting_quirk (chip, iface, altno); +/* presonus studio 1810c: skip altsets incompatible with device_setup */ +if (chip->usb_id ==USB_ID (0x0194f ,0x010c )) +return s1810c_skip_setting_quirk (chip, iface, altno); +return 0 ; }
Signature · 6 lines
2.23.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 14 lines · On Sat, 11 Jan 2020 18:40:56 +0100, [email protected] wrote:
This patch adds support for Presonus Studio 1810c, a usb interface that's UAC2 compliant with a few quirks and a few extra hw-specific controls. I've tested all 3 altsettings and the added switch controls and they work as expected.
More infos on the card:
https://www.presonus.com/products/Studio-1810cNote that this work is based on packet inspection with usbmon. I just wanted to get this card to work for using it on our open-source radio station:
https://github.com/UoC-Radio
Quoted 7 lines
v2 address issues reported by Takashi:
* Properly get/set enum type controls
* Prevent race condition on switch_get/set
* Various control naming changes
* Various coding style fixesSigned-off-by Nick Kossifidis <[email protected]>
Thanks, the patch looks almost good for merge, just a couple of nitpicks:
Quoted 7 lines
sound/usb/format.c +1
-0@@ -262,6 +262,23 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, }for (rate = min; rate <= max; rate += res) { +
sound/usb/format.c static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, · line 275
Quoted 10 lines
sound/usb/format.c +10
-0+/* +* Presonus Studio 1810c anounces invalid +* sampling rates for its streams. +*/ +if (chip->usb_id ==USB_ID (0x0194f ,0x010c ) && + ((rate >48000 && fp->altsetting ==1 ) || + ((rate <88200 || rate >96000 ) + && fp->altsetting ==2 ) || + ((rate <176400 || rate >192000 ) + && fp->altsetting ==3 ))) {
I still find it too hard to read. Maybe better to factor out this check into a function. Also it's clearer in a form of something like:
static bool sc1810c_valid_sample_rate()
{
switch (fp->altsetting) {
case 1:
return rate <= 48000;
case 2:
return rate >= 88200 && rate <= 96000;
case 3:
return rate >= 176400 && rate <= 192000;
default:
return true;
}
}Quoted 18 lines
sound/usb/mixer_s1810c.c new file +15
-0@@ -0,0 +1,595 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Presonus Studio 1810c driver for ALSA +* Copyright (C) 2019 Nick Kossifidis <[email protected]> +* +* Based on reverse engineering of the communication protocol +* between the windows driver / Univeral Control (UC) program +* and the device, through usbmon. +* +* For now this bypasses the mixer, with all channels split, +* so that the software can mix with greater flexibility. +* It also adds controls for the 4 buttons on the front of +* the device. +*/ +
sound/usb/mixer_s1810c.c line 25
Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10
-0+#include <linux/usb.h> +#include <linux/usb/audio-v2.h> +#include <linux/slab.h> +#include <sound/core.h> +#include <sound/control.h> + +#include "usbaudio.h" +#include "mixer.h" +#include "mixer_quirks.h" +#include "helper.h"
Include mixer_s1810c.h here, too, for the function declaration.
sound/usb/mixer_s1810c.c line 489
Quoted 3 lines
sound/usb/mixer_s1810c.c new file +3
-0+static const struct snd_kcontrol_new snd_s1810c_line_sw = { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Line 1/2 Source Type Switch" ,
This one is with an enum, so better to avoid "Switch" suffix. The user-space expects a "Switch" suffix is for a boolean blindly. Either omit the switch suffix, or use "Route" suffix, in any.
Also, when I apply with git-am, the author is taken from From: line, which doesn't contain your full name . The best would to submit the patch with git-send-email, then it'll add a proper From: line if needed.
thanks,
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
kbuild test robot
build botI love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on sound/for-next]
[also build test WARNING on v5.5-rc5 next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/mickflemm-gmail-com/ALSA-usb-audio-Add-support-for-Presonus-Studio-1810c/20200112-014426 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next config: x86_64-randconfig-s2-20200113 (attached as .config) compiler: gcc-4.9 (Debian 4.9.2-10+deb8u1) 4.9.2 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
sound/usb/mixer_s1810c.c: In function 'snd_sc1810c_get_status_field':
>> sound/usb/mixer_s1810c.c:177:9: warning: missing braces around initializer [-Wmissing-braces]
struct s1810c_state_packet pkt_out = { 0 };
^
sound/usb/mixer_s1810c.c:177:9: warning: (near initialization for 'pkt_out.fields') [-Wmissing-braces]
sound/usb/mixer_s1810c.c:178:9: warning: missing braces around initializer [-Wmissing-braces]
struct s1810c_state_packet pkt_in = { 0 };
^ sound/usb/mixer_s1810c.c:178:9: warning: (near initialization for 'pkt_in.fields') [-Wmissing-braces]
vim +177 sound/usb/mixer_s1810c.c
163
164 /*
165 * When opening Universal Control the program periodicaly
166 * sends and receives state packets for syncinc state between
167 * the device and the host.
168 *
169 * Note that if we send only the request to get data back we'll
170 * get an error, we need to first send an empty state packet and
171 * then ask to receive a filled. Their seqnumbers must also match.
172 */
173 static int
174 snd_sc1810c_get_status_field(struct usb_device *dev,
175 u32 *field, int field_idx, uint16_t *seqnum)
176 {
> 177 struct s1810c_state_packet pkt_out = { 0 };
178 struct s1810c_state_packet pkt_in = { 0 };
179 int ret = 0;
180
181 pkt_out.fields[SC1810C_STATE_F1_IDX] = SC1810C_SET_STATE_F1;
182 pkt_out.fields[SC1810C_STATE_F2_IDX] = SC1810C_SET_STATE_F2;
183 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
184 SC1810C_SET_STATE_REQ,
185 SC1810C_SET_STATE_REQTYPE,
186 (*seqnum), 0, &pkt_out, sizeof(pkt_out));
187 if (ret < 0) {
188 dev_warn(&dev->dev, "could not send state packet (%d)\n", ret);
189 return ret;
190 }
191
192 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
193 SC1810C_GET_STATE_REQ,
194 SC1810C_GET_STATE_REQTYPE,
195 (*seqnum), 0, &pkt_in, sizeof(pkt_in)); 196 if (ret < 0) {
197 dev_warn(&dev->dev, "could not get state field %u (%d)\n",
198 field_idx, ret);
199 return ret;
200 }
201
202 (*field) = pkt_in.fields[field_idx];
203 (*seqnum)++;
204 return 0;
205 }
206
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation