Discussion:
[Alsa-user] Controlling card number assignments
Paul D. DeRocco
2017-07-07 00:47:10 UTC
Permalink
I've got a Raspberry Pi with a HiFiBerry DAC on it, and a USB to MIDI
converter plugged into it. It's running a GUI-less embedded Linux created
with Yocto, which uses systemd and udev. The card numbers assigned to
these two devices is unpredictable. What can I do to fix the card numbers?
Or barring that, what else can I do so that my app can use fixed names for
referring to both?
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
chris hermansen
2017-07-07 01:53:15 UTC
Permalink
Paul and list,

On Jul 6, 2017 18:06, "Paul D. DeRocco" <***@ix.netcom.com> wrote:

I've got a Raspberry Pi with a HiFiBerry DAC on it, and a USB to MIDI
converter plugged into it. It's running a GUI-less embedded Linux created
with Yocto, which uses systemd and udev. The card numbers assigned to
these two devices is unpredictable. What can I do to fix the card numbers?
Or barring that, what else can I do so that my app can use fixed names for
referring to both?


Try sudo aplay -L to get a list of symbolic names.

On my Cubox I see for example

hw:CARD=Schiit,DEV=0

Which is what I want to use (you might want plughw or some other interface).
Clemens Ladisch
2017-07-07 07:47:11 UTC
Permalink
Post by Paul D. DeRocco
I've got a Raspberry Pi with a HiFiBerry DAC on it, and a USB to MIDI
converter plugged into it. It's running a GUI-less embedded Linux created
with Yocto, which uses systemd and udev. The card numbers assigned to
these two devices is unpredictable. What can I do to fix the card numbers?
You could use the vid/pid options of the driver. See
<http://alsa.opensrc.org/MultipleUSBAudioDevices> or
<https://help.ubuntu.com/community/UbuntuStudio/UsbAudioDevices>.


Regards,
Clemens
Paul D. DeRocco
2017-07-07 17:55:10 UTC
Permalink
Post by Clemens Ladisch
You could use the vid/pid options of the driver. See
<http://alsa.opensrc.org/MultipleUSBAudioDevices> or
<https://help.ubuntu.com/community/UbuntuStudio/UsbAudioDevices>.
The DAC isn't a USB device. It connects to the RPi's I2S interface, and is
controlled by I2C, and enumerated via a .dto file. It does, however, have
a consistent name, so I'm alright with that.

The USB to MIDI converters are a different matter. They're USB, but they
could be any brand. I have a cheap Chinese converter whose name comes up
as "Interface", and an E-Mu device called "XMidiX1". It would be really
nice to have some geographic way to refer to them, based on the USB port
they're plugged into. But I guess that's something I should ask about on
the systemd list.
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Takashi Iwai
2017-07-07 18:21:25 UTC
Permalink
On Fri, 07 Jul 2017 19:55:10 +0200,
Post by Paul D. DeRocco
Post by Clemens Ladisch
You could use the vid/pid options of the driver. See
<http://alsa.opensrc.org/MultipleUSBAudioDevices> or
<https://help.ubuntu.com/community/UbuntuStudio/UsbAudioDevices>.
The DAC isn't a USB device. It connects to the RPi's I2S interface, and is
controlled by I2C, and enumerated via a .dto file. It does, however, have
a consistent name, so I'm alright with that.
The USB to MIDI converters are a different matter. They're USB, but they
could be any brand. I have a cheap Chinese converter whose name comes up
as "Interface", and an E-Mu device called "XMidiX1". It would be really
nice to have some geographic way to refer to them, based on the USB port
they're plugged into. But I guess that's something I should ask about on
the systemd list.
The patch below adds a new module option to USB-audio driver for
specifying the devpath string. Together with index option, you can
define the card index for the fixed devpath. Would it work for you?

The patch has been floating around over years, and not merged just
because I haven't heard of the good usage of it.


Takashi

-- 8< --
From: Takashi Iwai <***@suse.de>
Subject: [PATCH] ALSA: usb-audio - Add devpath option

Added devpath module option to specify the USB devpath for the
specific device index.

Signed-off-by: Takashi Iwai <***@suse.de>
---
sound/usb/card.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 6640277a725b..a9af497d19bf 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -79,6 +79,7 @@ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card *
/* Vendor/product IDs for this card */
static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
+static char *devpath[SNDRV_CARDS];
static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
static bool ignore_ctl_error;
static bool autoclock = true;
@@ -94,6 +95,8 @@ module_param_array(vid, int, NULL, 0444);
MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
module_param_array(pid, int, NULL, 0444);
MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
+module_param_array(devpath, charp, NULL, 0444);
+MODULE_PARM_DESC(devpath, "USB devpath for the specific index.");
module_param_array(device_setup, int, NULL, 0444);
MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
module_param(ignore_ctl_error, bool, 0444);
@@ -506,6 +509,21 @@ get_alias_quirk(struct usb_device *dev, unsigned int id)
return NULL;
}

+static int is_matching_device(int i, u32 id, struct usb_device *dev)
+{
+ if (vid[i] != -1 && vid[i] != USB_ID_VENDOR(id))
+ return 0;
+ if (pid[i] != -1 && pid[i] != USB_ID_PRODUCT(id))
+ return 0;
+ if (devpath[i]) {
+ char tmppath[64];
+ usb_make_path(dev, tmppath, sizeof(tmppath));
+ if (strcmp(devpath[i], tmppath))
+ return 0;
+ }
+ return 1;
+}
+
/*
* probe the active usb device
*
@@ -566,8 +584,7 @@ static int usb_audio_probe(struct usb_interface *intf,
*/
for (i = 0; i < SNDRV_CARDS; i++)
if (enable[i] && ! usb_chip[i] &&
- (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
- (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
+ is_matching_device(i, id, dev)) {
err = snd_usb_audio_create(intf, dev, i, quirk,
id, &chip);
if (err < 0)
--
2.13.2
Clemens Ladisch
2017-07-07 18:59:55 UTC
Permalink
Post by Paul D. DeRocco
Post by Clemens Ladisch
You could use the vid/pid options of the driver. See
<http://alsa.opensrc.org/MultipleUSBAudioDevices> or
<https://help.ubuntu.com/community/UbuntuStudio/UsbAudioDevices>.
The DAC isn't a USB device.
With different modules, you can simply order them by adding something
like this to a .conf file in /etc/modprobe.d/:

options snd slots=snd-usb-audio,snd-whatevertheothermoduleisnamed


Regards,
Clemens
Paul D. DeRocco
2017-07-08 00:09:23 UTC
Permalink
Post by Clemens Ladisch
With different modules, you can simply order them by adding something
options snd slots=snd-usb-audio,snd-whatevertheothermoduleisnamed
Thanks. The following seems to work for me.

options snd slots=snd-soc-hifiberry-dacplus,snd-usb-audio

The USB MIDI devices come up in a predictable order if they're present on
boot, but obviously if they're plugged in afterwards they are numbered in
the order they're plugged in. It would still be nice to associate a
consistent name with each USB port, even if it doesn't gracefully handle
cases like external hubs.
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Loading...