Magellan Linux

Annotation of /tags/udev-165-r1/udev-sound-card.rules.magellan

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1238 - (hide annotations) (download)
Thu Dec 16 17:40:15 2010 UTC (13 years, 4 months ago) by niro
File size: 5345 byte(s)
tagged 'udev-165-r1'
1 niro 884 # /etc/udev/rules/78-sound-card.rules: device naming rules for udev
2 niro 1016 # $Header: /root/magellan-cvs/src/udev/udev-sound-card.rules.magellan,v 1.2 2010-04-06 23:46:22 niro Exp $
3 niro 884 #
4     # There are a number of modifiers that are allowed to be used in some
5     # of the different fields. They provide the following subsitutions:
6     # %n - the "kernel number" of the device.
7     # For example, 'sda3' has a "kernel number" of '3'
8     # %k - the kernel name for the device.
9     # %M - the kernel major number for the device
10     # %m - the kernel minor number for the device
11     # %b - the bus id for the device
12     # %c - the string returned by the PROGRAM. (Note, this doesn't work within
13     # the PROGRAM field for the obvious reason.)
14     # %s{filename} - the content of a sysfs attribute.
15     # %% - the '%' char itself.
16     #
17     # Try not to modify this file, if you wish to change things, create a new rule
18     # file that can be run before this one.
19     #
20    
21     SUBSYSTEM!="sound", GOTO="sound_end"
22    
23     ACTION=="add|change", KERNEL=="controlC*", ATTR{../uevent}="change"
24     ACTION!="change", GOTO="sound_end"
25    
26     # Ok, we probably need a little explanation here for what the two lines above
27     # are good for.
28     #
29     # The story goes like this: when ALSA registers a new sound card it emits a
30     # series of 'add' events to userspace, for the main card device and for all the
31     # child device nodes that belong to it. udev relays those to applications,
32     # however only maintains the order between father and child, but not between
33     # the siblings. The control device node creation can be used as synchronization
34     # point. All other devices that belong to a card are created in the kernel
35     # before it. However unfortunately due to the fact that siblings are forwarded
36     # out of order by udev this fact is lost to applications.
37     #
38     # OTOH before an application can open a device it needs to make sure that all
39     # its device nodes are completely created and set up.
40     #
41     # As a workaround for this issue we have added the udev rule above which will
42     # generate a 'change' event on the main card device from the 'add' event of the
43     # card's control device. Due to the ordering semantics of udev this event will
44     # only be relayed after all child devices have finished processing properly.
45     # When an application needs to listen for appearing devices it can hence look
46     # for 'change' events only, and ignore the actual 'add' events.
47     #
48     # When the application is initialized at the same time as a device is plugged
49     # in it may need to figure out if the 'change' event has already been triggered
50     # or not for a card. To find that out we store the flag environment variable
51     # SOUND_INITIALIZED on the device which simply tells us if the card 'change'
52     # event has already been processed.
53    
54     KERNEL!="card*", GOTO="sound_end"
55    
56     ENV{SOUND_INITIALIZED}="1"
57    
58     SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{program}="usb_id --export %p"
59     SUBSYSTEMS=="usb", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="usb-db %p"
60     SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}"
61     SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}!="", ENV{ID_IFACE}="$attr{bInterfaceNumber}"
62     SUBSYSTEMS=="usb", GOTO="skip_pci"
63    
64     SUBSYSTEMS=="pci", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="pci-db %p"
65     SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
66    
67     LABEL="skip_pci"
68    
69 niro 1016 ENV{ID_SERIAL}=="?*", ENV{ID_IFACE}=="?*", ENV{ID_ID}="$env{ID_BUS}-$env{ID_SERIAL}-$env{ID_IFACE}-$attr{id}"
70     ENV{ID_SERIAL}=="?*", ENV{ID_IFACE}=="", ENV{ID_ID}="$env{ID_BUS}-$env{ID_SERIAL}-$attr{id}"
71 niro 884
72 niro 1016 ENV{ID_PATH}=="", IMPORT{program}="path_id %p/controlC%n"
73 niro 884
74     # The values used here for $SOUND_FORM_FACTOR and $SOUND_CLASS should be kept
75     # in sync with those defined for PulseAudio's src/pulse/proplist.h
76     # PA_PROP_DEVICE_FORM_FACTOR, PA_PROP_DEVICE_CLASS properties.
77    
78     # If the first PCM device of this card has the pcm class 'modem', then the card is a modem
79     ATTR{pcmC%nD0p/pcm_class}=="modem", ENV{SOUND_CLASS}="modem", GOTO="sound_end"
80    
81     # Identify cards on the internal PCI bus as internal
82     SUBSYSTEMS=="pci", DEVPATH=="*/0000:00:??.?/sound/*", ENV{SOUND_FORM_FACTOR}="internal", GOTO="sound_end"
83    
84     # Devices that also support Image/Video interfaces are most likely webcams
85     SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACES}=="*:0e????:*", ENV{SOUND_FORM_FACTOR}="webcam", GOTO="sound_end"
86    
87     # Matching on the model strings is a bit ugly, I admit
88     ENV{ID_MODEL}=="*[Ss]peaker*", ENV{SOUND_FORM_FACTOR}="speaker", GOTO="sound_end"
89     ENV{ID_MODEL_FROM_DATABASE}=="*[Ss]peaker*", ENV{SOUND_FORM_FACTOR}="speaker", GOTO="sound_end"
90    
91     ENV{ID_MODEL}=="*[Hh]eadphone*", ENV{SOUND_FORM_FACTOR}="headphone", GOTO="sound_end"
92     ENV{ID_MODEL_FROM_DATABASE}=="*[Hh]eadphone*", ENV{SOUND_FORM_FACTOR}="headphone", GOTO="sound_end"
93    
94     ENV{ID_MODEL}=="*[Hh]eadset*", ENV{SOUND_FORM_FACTOR}="headset", GOTO="sound_end"
95     ENV{ID_MODEL_FROM_DATABASE}=="*[Hh]eadset*", ENV{SOUND_FORM_FACTOR}="headset", GOTO="sound_end"
96    
97     ENV{ID_MODEL}=="*[Hh]andset*", ENV{SOUND_FORM_FACTOR}="handset", GOTO="sound_end"
98     ENV{ID_MODEL_FROM_DATABASE}=="*[Hh]andset*", ENV{SOUND_FORM_FACTOR}="handset", GOTO="sound_end"
99    
100     ENV{ID_MODEL}=="*[Mm]icrophone*", ENV{SOUND_FORM_FACTOR}="microphone", GOTO="sound_end"
101     ENV{ID_MODEL_FROM_DATABASE}=="*[Mm]icrophone*", ENV{SOUND_FORM_FACTOR}="microphone", GOTO="sound_end"
102    
103     LABEL="sound_end"