Skip to contentSkip to conversation

ALSA: usb-audio: Add support for Presonus Studio 1810c

PATCH Superseded [email protected] 3 participants 5 messages Dec 26, 2019 – Jan 6, 2020 Sound

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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

---
 sound/usb/Makefile       |   1 +
 sound/usb/format.c       |  17 ++
 sound/usb/mixer_quirks.c |   5 +
 sound/usb/mixer_s1810c.c | 565 +++++++++++++++++++++++++++++++++++++++
 sound/usb/mixer_s1810c.h |   6 +
 sound/usb/quirks.c       |  34 +++
 6 files changed, 628 insertions(+)
 create mode 100644 sound/usb/mixer_s1810c.c
 create mode 100644 sound/usb/mixer_s1810c.h
sound/usb/Makefile +1 -0
index 78edd7d2f..56031026b 100644
@@ -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
index d79db7130..edf3f2a55 100644
@@ -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
index 39e27ae6c..71e705fab 100644
@@ -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 +565 -0

565 lines not on this page · raw message

sound/usb/mixer_s1810c.h new file +6 -0
new file mode 100644
index 000000000..2a9ae0922
@@ -0,0 +1,6 @@
+/* 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 +34 -0
index 349e1e529..9a0ceaaf9 100644
@@ -1216,6 +1216,36 @@ 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)
+{
+	/*
+	 * Playback:
+	 * 1: 6 Analog + 2 S/PDIF
+	 * 2: 6 Analog + 2 S/PDIF
+	 * 3: 6 Analog
+	 *
+	 * Capture:
+	 * 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 == 1 && altno != 1)
+		return 1;
+	else if (chip->setup == 2 && altno != 3)
+		return 1;
+	else if (altno != 2)
+		return 1;
+
+	return 0;
+}
+
 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
 				  int iface,
 				  int altno)
@@ -1229,6 +1259,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
#1 lore raw
I love your patch! Yet something to improve:

Hi,

I love your patch! Yet something to improve:

[auto build test ERROR on sound/for-next]
[cannot apply to v5.5-rc3 next-20191220]
[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/20191226-163321
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.5.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=m68k

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

sound/usb/mixer_s1810c.c: In function 'snd_sc1810_mixer_state_free':

>> sound/usb/mixer_s1810c.c:507:2: error: implicit declaration of function 'vfree'; did you mean 'kfree'? [-Werror=implicit-function-declaration]
     vfree(private);
     ^~~~~
     kfree
   sound/usb/mixer_s1810c.c: In function 'snd_sc1810_init_mixer':
>> sound/usb/mixer_s1810c.c:536:12: error: implicit declaration of function 'vzalloc'; did you mean 'kzalloc'? [-Werror=implicit-function-declaration]
     private = vzalloc(sizeof(struct s1810_mixer_state));
               ^~~~~~~
               kzalloc
>> sound/usb/mixer_s1810c.c:536:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     private = vzalloc(sizeof(struct s1810_mixer_state));
             ^

cc1: some warnings being treated as errors

vim +507 sound/usb/mixer_s1810c.c

503
504 static void snd_sc1810_mixer_state_free(struct usb_mixer_interface *mixer)
505 {
506 struct s1810_mixer_state *private = mixer->private_data;

 > 507		vfree(private);
   508		mixer->private_data = NULL;
   509	}
   510	
   511	/* Entry point, called from mixer_quirks.c */
   512	int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer)
   513	{
   514		struct s1810_mixer_state *private = NULL;
   515		struct snd_usb_audio *chip = mixer->chip;
   516		struct usb_device *dev = chip->dev;
   517		int ret = 0;
   518	
   519		/* Run this only once */
   520		if (!list_empty(&chip->mixer_list))
   521			return 0;
   522	
   523		dev_info(&dev->dev,
   524			 "Presonus Studio 1810c, device_setup: %u\n", chip->setup);
   525		if (chip->setup == 1)
   526			dev_info(&dev->dev, "(8out/18in @ 48KHz)\n");
   527		else if (chip->setup == 2)
   528			dev_info(&dev->dev, "(6out/8in @ 192KHz)\n");
   529		else
   530			dev_info(&dev->dev, "(8out/14in @ 96KHz)\n");
   531	
   532		ret = snd_s1810c_init_mixer_maps(chip);
   533		if (ret < 0)
   534			return ret;
   535	
 > 536		private = vzalloc(sizeof(struct s1810_mixer_state));

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Wed, 25 Dec 2019 03:34:24 +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-1810c

Quoted 6 lines

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

Thanks for the patch.

In addition to the issues kbuild bot suggested, below are my quick review comments:

Quoted 14 lines
sound/usb/format.c +6 -0
index d79db7130..edf3f2a55 100644
@@ -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) &&

sound/usb/format.c static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, · line 280

Quoted 10 lines
sound/usb/format.c +10 -0
+			((rate > 48000 && fp->altsetting == 1) ||
+			 ((rate < 88200 || rate > 96000)
+			  && fp->altsetting == 2) ||
+			 ((rate < 176400 || rate > 192000)
+			  && fp->altsetting == 3))) {
+				if (res)
+					continue;
+				else
+					break;
+			}

It's hard to imagine what result this would lead to, because the conditions are so complex.
Maybe better to prepare a fixed table instead? Or, can we simply take a fixed quirk?

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +4 -0
new file mode 100644
index 000000000..ff86e4aab
@@ -0,0 +1,565 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Presonus Studio 1810c driver for ALSA
+ * Copyright (C) 2019 Nick Kossifidis <[email protected]>

sound/usb/mixer_s1810c.c line 14

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10 -0
+ *
+ * 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.
+ */

Usually place a blank line here.

sound/usb/mixer_s1810c.c line 18

Quoted 4 lines
sound/usb/mixer_s1810c.c new file +4 -0
+#include <linux/usb.h>
+#include <linux/usb/audio-v2.h>
+#include <sound/control.h>
+#include <linux/slab.h>

The common practice is to group linux/*.h first, followed by sound/*.h. And <sound/core.h> is almost always needed before other sound/*.h.

sound/usb/mixer_s1810c.c line 88

Quoted 8 lines
sound/usb/mixer_s1810c.c new file +8 -0
+struct s1810c_ctl_packet {
+	uint32_t a;
+	uint32_t b;
+	uint32_t fixed1;
+	uint32_t fixed2;
+	uint32_t c;
+	uint32_t d;
+	uint32_t e;

Use u32, u16 or such types instead of uint*_t.
It's the standard type for kernel codes.
Also applied in other places in the patch, too.

Quoted 4 lines
sound/usb/mixer_s1810c.c new file +4 -0
+static int
+snd_sc1810c_get_status_field(struct usb_device *dev,
+			     uint32_t *field, int field_idx, uint16_t *seqnum)
+{

sound/usb/mixer_s1810c.c line 183

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10 -0
+	struct s1810c_state_packet pkt_out = { 0 };
+	struct s1810c_state_packet pkt_in = { 0 };
+	int ret = 0;
+
+	pkt_out.fields[SC1810C_STATE_F1_IDX] = SC1810C_SET_STATE_F1;
+	pkt_out.fields[SC1810C_STATE_F2_IDX] = SC1810C_SET_STATE_F2;
+	ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
+			      SC1810C_SET_STATE_REQ,
+			      SC1810C_SET_STATE_REQTYPE,
+			      (*seqnum), 0, &pkt_out, sizeof(pkt_out));

Avoid unnecessary parentheses around *seqnum.
Ditto for other possible places.

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10 -0
+static int
+snd_s1810c_switch_set(struct snd_kcontrol *kctl,
+		      struct snd_ctl_elem_value *ctl_elem)
+{
+	struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
+	struct usb_mixer_interface *mixer = list->mixer;
+	uint32_t curval = 0;
+	uint32_t newval = (uint32_t) ctl_elem->value.integer.value[0];
+	int ret = 0;
+

sound/usb/mixer_s1810c.c line 413

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10 -0
+	ret = snd_s1810c_get_switch_state(mixer, kctl, &curval);
+	if (ret < 0)
+		return 0;
+
+	if (curval == newval)
+		return 0;
+
+	kctl->private_value &= ~(0x1 << 16);
+	kctl->private_value |= (unsigned int)(newval & 0x1) << 16;
+	ret = snd_s1810c_set_switch_state(mixer, kctl);

Hm, this can be racy. The control get/put isn't protected, so you might get the inconsistency here when multiple kctls are accessed concurrently.

sound/usb/mixer_s1810c.c line 452

Quoted 7 lines
sound/usb/mixer_s1810c.c new file +7 -0
+static int
+snd_s1810c_line_sw_info(struct snd_kcontrol *kctl,
+			struct snd_ctl_elem_info *uinfo)
+{
+	static const char *const texts[2] = { "Preamp on (Mic/Inst)",
+		"Preamp off (Line in)"
+	};

Better to put "Preamp on..." item in the next line.

sound/usb/mixer_s1810c.c line 457

Quoted 1 line
sound/usb/mixer_s1810c.c new file +1 -0
+static struct snd_kcontrol_new snd_s1810c_line_sw = {

This (and other following definitions) can be const?

sound/usb/mixer_s1810c.c line 459

Quoted 2 lines
sound/usb/mixer_s1810c.c new file +2 -0
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "Line 1/2 source type",

The control name should consist of words starting with a capital letter, so it should be "Line 1/2 Source Type".
Also, usually a control name needs a standard suffix. Though, this has a special return enum type, so it can be OK as is.

However...

sound/usb/mixer_s1810c.c line 462

Quoted 3 lines
sound/usb/mixer_s1810c.c new file +3 -0
+	.info = snd_s1810c_line_sw_info,
+	.get = snd_s1810c_switch_get,
+	.put = snd_s1810c_switch_set,

... this shows that the combination is invalid. The enum type doesn't get/put the values in integer fields. It's incompatible.

sound/usb/mixer_s1810c.c line 468

Quoted 6 lines
sound/usb/mixer_s1810c.c new file +6 -0
+	.private_value = (SC1810C_STATE_LINE_SW | SC1810C_CTL_LINE_SW << 8)
+};
+
+static struct snd_kcontrol_new snd_s1810c_mute_sw = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "Mute Main Out",

... and this one, for example, should deserve for "Switch" suffix, as it's a standard boolean switch (which use integer fields unlike enum).

Quoted 16 lines
sound/usb/mixer_s1810c.c new file +16 -0
+/* Entry point, called from mixer_quirks.c */
+int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer)
+{
+	struct s1810_mixer_state *private = NULL;
+	struct snd_usb_audio *chip = mixer->chip;
+	struct usb_device *dev = chip->dev;
+	int ret = 0;
+
+	/* Run this only once */
+	if (!list_empty(&chip->mixer_list))
+		return 0;
+
+	dev_info(&dev->dev,
+		 "Presonus Studio 1810c, device_setup: %u\n", chip->setup);
+	if (chip->setup == 1)
+		dev_info(&dev->dev, "(8out/18in @ 48KHz)\n");

sound/usb/mixer_s1810c.c line 536

Quoted 10 lines
sound/usb/mixer_s1810c.c new file +10 -0
+	else if (chip->setup == 2)
+		dev_info(&dev->dev, "(6out/8in @ 192KHz)\n");
+	else
+		dev_info(&dev->dev, "(8out/14in @ 96KHz)\n");
+
+	ret = snd_s1810c_init_mixer_maps(chip);
+	if (ret < 0)
+		return ret;
+
+	private = vzalloc(sizeof(struct s1810_mixer_state));

I don't think vmalloc is needed here, as the object is so small. Use kzalloc() and kfree() instead (unless I overlook something).

sound/usb/mixer_s1810c.c line 538

Quoted 2 lines
sound/usb/mixer_s1810c.c new file +2 -0
+	if (!private) {
+		dev_err(&dev->dev, "could not allocate mixer state\n");

The error message is usually superfluous, as kernel spews the warning in anyway at each allocation error.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

Hello Takashi, happy new year and thanks for the feedback,

Quoted 21 lines · Takashi Iwai
Quoted 21 lines
sound/usb/format.c +13 -0
index d79db7130..edf3f2a55 100644
@@ -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;
Quoted 9 lines

sound/usb/format.c static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, · line 280

Quoted 3 lines
sound/usb/format.c +3 -0
+                             else
+                                     break;
+                     }

It's hard to imagine what result this would lead to, because the conditions are so complex.
Maybe better to prepare a fixed table instead? Or, can we simply take a fixed quirk?

I thought of using a fixed table but on the other hand the card does support reporting rates via the UAC2-compliant command and I noticed there are similar quirks on parse_audio_format_rates_v1. Maybe have a new quirk function that we can call from within the for loop for both UAC1/2 to filter misreported rates in one place ? I think it'll be cleaner that way.

Quoted 16 lines
Quoted 16 lines
sound/usb/format.c +16 -0
+static int
+snd_s1810c_switch_set(struct snd_kcontrol *kctl,
+                   struct snd_ctl_elem_value *ctl_elem)
+{
+     struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
+     struct usb_mixer_interface *mixer = list->mixer;
+     uint32_t curval = 0;
+     uint32_t newval = (uint32_t) ctl_elem->value.integer.value[0];
+     int ret = 0;
+
+     ret = snd_s1810c_get_switch_state(mixer, kctl, &curval);
+     if (ret < 0)
+             return 0;
+
+     if (curval == newval)
+             return 0;
Quoted 9 lines

sound/usb/format.c

Quoted 4 lines
sound/usb/format.c +4 -0
+
+     kctl->private_value &= ~(0x1 << 16);
+     kctl->private_value |= (unsigned int)(newval & 0x1) << 16;
+     ret = snd_s1810c_set_switch_state(mixer, kctl);

Hm, this can be racy. The control get/put isn't protected, so you might get the inconsistency here when multiple kctls are accessed concurrently.

There is a lock on get/set_switch_state to serialize access to the card, it should take care of that.

Quoted 8 lines

sound/usb/format.c

Quoted 2 lines
sound/usb/format.c +2 -0
+     .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+     .name = "Line 1/2 source type",

The control name should consist of words starting with a capital letter, so it should be "Line 1/2 Source Type".
Also, usually a control name needs a standard suffix. Though, this has a special return enum type, so it can be OK as is.

Quoted 9 lines

However...

sound/usb/format.c

Quoted 3 lines
sound/usb/format.c +3 -0
+     .info = snd_s1810c_line_sw_info,
+     .get = snd_s1810c_switch_get,
+     .put = snd_s1810c_switch_set,

... this shows that the combination is invalid. The enum type doesn't get/put the values in integer fields. It's incompatible.

I didn't get that one, isn't enum type an integer ? All controls added here are on/off switches and use the same get/set functions, I just wanted to provide some more info for some of them so I added custom .info functions.

Quoted 11 lines

sound/usb/format.c

Quoted 6 lines
sound/usb/format.c +6 -0
+     .private_value = (SC1810C_STATE_LINE_SW | SC1810C_CTL_LINE_SW << 8)
+};
+
+static struct snd_kcontrol_new snd_s1810c_mute_sw = {
+     .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+     .name = "Mute Main Out",

... and this one, for example, should deserve for "Switch" suffix, as it's a standard boolean switch (which use integer fields unlike enum).

Isn't "Switch" superfluous ? I don't see anything similar on the mixer controls of my other sound cards, e.g. it says "Mic Boost" not "Switch Mic Boost on". Also I still don't get the enum part, how can this be a standard boolean switch and the others not ? You mean because it uses snd_ctl_boolean_mono_info ?

Quoted 21 lines
Quoted 21 lines
sound/usb/format.c +21 -0
+/* Entry point, called from mixer_quirks.c */
+int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer)
+{
+     struct s1810_mixer_state *private = NULL;
+     struct snd_usb_audio *chip = mixer->chip;
+     struct usb_device *dev = chip->dev;
+     int ret = 0;
+
+     /* Run this only once */
+     if (!list_empty(&chip->mixer_list))
+             return 0;
+
+     dev_info(&dev->dev,
+              "Presonus Studio 1810c, device_setup: %u\n", chip->setup);
+     if (chip->setup == 1)
+             dev_info(&dev->dev, "(8out/18in @ 48KHz)\n");
+     else if (chip->setup == 2)
+             dev_info(&dev->dev, "(6out/8in @ 192KHz)\n");
+     else
+             dev_info(&dev->dev, "(8out/14in @ 96KHz)\n");
+
Quoted 9 lines

sound/usb/format.c

Quoted 5 lines
sound/usb/format.c +5 -0
+     ret = snd_s1810c_init_mixer_maps(chip);
+     if (ret < 0)
+             return ret;
+
+     private = vzalloc(sizeof(struct s1810_mixer_state));

I don't think vmalloc is needed here, as the object is so small. Use kzalloc() and kfree() instead (unless I overlook something).

Good point, I'll switch to kzalloc/kfree, this will also make the bot happy.

Signature · 7 lines
GPG ID: 0xEE878588
As you read this post global entropy rises. Have Fun ;-)
Nick
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#4 lore raw
Quoted 36 lines · Nick Kossifidis

Hello Takashi, happy new year and thanks for the feedback,

Quoted 21 lines · Takashi Iwai
Quoted 21 lines
sound/usb/format.c +13 -0
index d79db7130..edf3f2a55 100644
@@ -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;
Quoted 9 lines

sound/usb/format.c static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, · line 280

Quoted 3 lines
sound/usb/format.c +3 -0
+                             else
+                                     break;
+                     }

It's hard to imagine what result this would lead to, because the conditions are so complex.
Maybe better to prepare a fixed table instead? Or, can we simply take a fixed quirk?

Quoted 6 lines

I thought of using a fixed table but on the other hand the card does support reporting rates via the UAC2-compliant command and I noticed there are similar quirks on parse_audio_format_rates_v1. Maybe have a new quirk function that we can call from within the for loop for both UAC1/2 to filter misreported rates in one place ? I think it'll be cleaner that way.

Let's try in some different ways and compare how they look like. If the current code is the best in the end, we should give some more comments about the resultant rate tables.

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
sound/usb/format.c +16 -0
+static int
+snd_s1810c_switch_set(struct snd_kcontrol *kctl,
+                   struct snd_ctl_elem_value *ctl_elem)
+{
+     struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
+     struct usb_mixer_interface *mixer = list->mixer;
+     uint32_t curval = 0;
+     uint32_t newval = (uint32_t) ctl_elem->value.integer.value[0];
+     int ret = 0;
+
+     ret = snd_s1810c_get_switch_state(mixer, kctl, &curval);
+     if (ret < 0)
+             return 0;
+
+     if (curval == newval)
+             return 0;
Quoted 9 lines

sound/usb/format.c

Quoted 4 lines
sound/usb/format.c +4 -0
+
+     kctl->private_value &= ~(0x1 << 16);
+     kctl->private_value |= (unsigned int)(newval & 0x1) << 16;
+     ret = snd_s1810c_set_switch_state(mixer, kctl);

Hm, this can be racy. The control get/put isn't protected, so you might get the inconsistency here when multiple kctls are accessed concurrently.

Quoted 2 lines

There is a lock on get/set_switch_state to serialize access to the card, it should take care of that.

The lock doesn't cover the two lines above fiddling with kctl->private_value. That's the racy point.

Quoted 14 lines
Quoted 14 lines

sound/usb/format.c

Quoted 2 lines
sound/usb/format.c +2 -0
+     .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+     .name = "Line 1/2 source type",

The control name should consist of words starting with a capital letter, so it should be "Line 1/2 Source Type".
Also, usually a control name needs a standard suffix. Though, this has a special return enum type, so it can be OK as is.

However...

Quoted 3 lines
sound/usb/format.c +3 -0
+     .info = snd_s1810c_line_sw_info,
+     .get = snd_s1810c_switch_get,
+     .put = snd_s1810c_switch_set,
Quoted 5 lines
Quoted 3 lines

... this shows that the combination is invalid. The enum type doesn't get/put the values in integer fields. It's incompatible.

I didn't get that one, isn't enum type an integer ?

No, it takes a different type, value.enumerated.item[]. It's an int array, while value.integer.value[] (which is used for SNDRV_CTL_ELEM_TYPE_BOOLEAN and SNDRV_CTL_ELEM_TYPE_INTEGER) is a long array, hence the size differs on 64bit arch.

Quoted 17 lines

All controls added
here are on/off switches and use the same get/set functions, I just wanted to provide some more info for some of them so I added custom .info functions.

Quoted 11 lines

sound/usb/format.c

Quoted 6 lines
sound/usb/format.c +6 -0
+     .private_value = (SC1810C_STATE_LINE_SW | SC1810C_CTL_LINE_SW << 8)
+};
+
+static struct snd_kcontrol_new snd_s1810c_mute_sw = {
+     .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+     .name = "Mute Main Out",

... and this one, for example, should deserve for "Switch" suffix, as it's a standard boolean switch (which use integer fields unlike enum).

Quoted 5 lines

Isn't "Switch" superfluous ? I don't see anything similar on the mixer controls of my other sound cards, e.g. it says "Mic Boost" not "Switch Mic Boost on". Also I still don't get the enum part, how can this be a standard boolean switch and the others not ? You mean because it uses snd_ctl_boolean_mono_info ?

There is a standard control name definition, see Documentation/sound/designs/control-names.rst. "Mic Boost" is one of standard names, hence it's OK. Although many drivers already don't follow that rule, you'll still see some conceptual idea there.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel