[PlanetCCRMA] usb audio and midi devices: loading and unloading drivers

Fernando Pablo Lopez-Lezcano nando@ccrma.Stanford.EDU
Wed Mar 5 16:09:01 2003


The problem: in RedHat the usb subsystem is activated very early in the
boot sequence (/etc/rc.d/rc.sysinit). Any usb sound or midi card that is
plugged in while the system boots will automatically load the
snd-usb-midi alsa kernel module (through hotplug). When the time for
alsa to start arrives later in the boot sequence, the standard alsasound
script (/etc/rc.d/init.d/alsasound) determines that the driver is
already running by testing for the existence of /proc/asound, and fails
to load any remaining drivers for other cards or devices. 

Solution: install the alsasound script (see below for short HOWTO) that
I include as an attachment at the end of this email. It has been
modified to load any remaining kernel modules so that the early load of
snd-usb-audio does not stop the other modules from loading. It will be
included in the next Planet CCRMA revision of the alsa-driver package. 

Caveat: I have _not_ tested this a lot :-)

Caveat 2: do _not_ blacklist "snd-usb-audio", but do blacklist "audio"
and "usb-midi" (the oss usb audio and midi kernel modules). Blacklist a
module so that hotplug ignores it by adding its name in a line in
/etc/hotplug/blacklist. 

You have to have configured the /etc/modules.conf file properly for
multiple cards, at the very least your "cards_limit" entry in snd
"options snd" line has to be equal to the maximum number of cards
(including usb devices) that you expect to connect. If you do not
explicitly include an entry for snd-usb-audio then the module will _not_
be loaded by the alsasound script (but it will load when you plug in the
device, or when you boot with the device attached to the computer, but
if you then stop and restart the alsa driver it will _not_ be loaded). 

So far this is the behavior I have tested so far:

- start computer, usb device connected: hotplug starts
  snd-usb-audio, the rest of the drivers are started by alsasound.

- start computer, usb device disconnected: alsasound starts all drivers
  including snd-usb-audio (because I have configured it in
  modules.conf). Snd-usb-audio is loaded but not active because there
  are not audio or midi usb devices. Connect usb device: hotplug
  registers the device with snd-usb-audio and makes it active. 

- running system, all drivers loaded, usb device connected: disconnect
  usb device: snd-usb-audio remains loaded but the device in
  /proc/asound dissapears. Connect usb device: device is reregistered
  and reappears in /proc/asound.

- running system, all drivers loaded, usb device connected: run
  "/etc/rc.d/init.d/alsasound stop", all devices are unloaded including
  snd-usb-audio. Run "/etc/rc.d/init.d/alsasound start": all devices are
  loaded including snd-usb-audio. 

- running system, all drivers loaded, usb device connected: run
  "/etc/rc.d/init.d/alsasound start" (without first stopping the
  driver), devices are not reloaded but the mixer configuration is
  reloaded. 

So it looks good...
To install the script just copy it to /etc/rc.d/init.d/, and make sure
it is executable (chmod +x /etc/rc.d/init.d/alsasound)

Let me know of any problems. 
-- Fernando

PS: obviously I have to rewrite the configuration stuff in the Planet
CCRMA pages to include all of this... yet to be done...