udev: detect USB webcam sound cards through the usb-interface hwdb

Instead of matching ID_USB_INTERFACES directly in 78-sound-card.rules to
identify USB sound cards that also expose a video interface, add a new
ID_VIDEO property that is set for devices exposing an interface of
class 0e (Video) by the usb-interface hwdb, and match on that.

The rules are evaluated for the sound card device, a descendant of the USB
device, which does not inherit the properties set by the hwdb lookup done in
50-udev-default.rules.in for the USB device itself. So the lookup is also
done in 78-sound-card.rules, right after usb_id has set the properties used
to build the key. Only ID_VIDEO is imported there, using --filter=.
This commit is contained in:
Yu Watanabe committed 2026-10-31 23:07:10 +09:00
1 parent e22b38b0c4
commit b8c83187eb
3 files changed
+11 -1

No files matched your search

+7
View File
@@ -29,6 +29,9 @@
# Specify the protocol used to interact with a debug appliance, see
# 70-debug-appliance.hwdb
# ID_DEBUG_APPLIANCE=?*
#
# Specify if a device has a video interface, e.g. a webcam
# ID_VIDEO=0|1
# USB3 Vision devices exposing the device control interface
usb-interface:v*p*:ef0500:*
@@ -63,3 +66,7 @@ usb-interface:v*p*:dc0201:*
usb-interface:v*p*:ff4201:*
usb-interface:v*p*:ff4203:*
ID_DEBUG_APPLIANCE=android
# Devices exposing a video interface, e.g. webcams (interface class 0e)
usb-interface:v*p*:0e????:*
ID_VIDEO=1
+1
View File
@@ -224,6 +224,7 @@ def property_grammar():
('ID_PRINTER', zero_one),
('ID_SMARTCARD_READER', zero_one),
('ID_PTP_MTP', zero_one),
('ID_VIDEO', zero_one),
('POINTINGSTICK_SENSITIVITY', INTEGER),
('ID_INTEGRATION', Or(('internal', 'external'))),
('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))),
+3 -1
View File
@@ -39,6 +39,8 @@ ENV{SOUND_INITIALIZED}="1"
IMPORT{builtin}="hwdb"
SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACES}=="?*", \
IMPORT{builtin}="hwdb --filter=ID_VIDEO 'usb-interface:v$env{ID_USB_VENDOR_ID}p$env{ID_USB_MODEL_ID}$env{ID_USB_INTERFACES}'"
SUBSYSTEMS=="usb", GOTO="skip_pci"
SUBSYSTEMS=="firewire", ATTRS{guid}=="?*", \
@@ -75,7 +77,7 @@ ATTR{pcmC%nD0p/pcm_class}=="modem", ENV{SOUND_CLASS}="modem", GOTO="sound_end"
SUBSYSTEMS=="pci", DEVPATH=="*/0000:00:??.?/sound/*", ENV{SOUND_FORM_FACTOR}="internal", GOTO="sound_end"
# Devices that also support Image/Video interfaces are most likely webcams
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACES}=="*:0e????:*", ENV{SOUND_FORM_FACTOR}="webcam", GOTO="sound_end"
ENV{ID_VIDEO}=="1", ENV{SOUND_FORM_FACTOR}="webcam", GOTO="sound_end"
# Matching on the model strings is a bit ugly, I admit
ENV{ID_MODEL}=="*[Ss]peaker*", ENV{SOUND_FORM_FACTOR}="speaker", GOTO="sound_end"