Thread (2 messages) 2 messages, 2 authors, 2014-07-01

sysfs bind/unbind attributes usage

From: bjorn@mork.no (Bjørn Mork)
Date: 2014-07-01 10:43:58

Raghavendra [off-list ref] writes:
Hello,

I would like to know more about manually probing/removing the devices 
through sysfs attributes.
After searching for a while I came across two attributes 'bind' and 
'unbind' present in all the drivers.

Now how may I correctly use them to probe my devices.
I sense the probing syntax is different for different kinds of drivers 
(I2C, SPI, PCI, USB, etc).
I am mainly looking for probing I2C and SPI devices.
sysfs attributes are supposed to be documented under
'Documentation/ABI/' but there seems to be a few holes there:

bjorn at nemi:/usr/local/src/git/linux$ git grep bind Documentation/ABI/
Documentation/ABI/testing/configfs-usb-gadget:          UDC             - bind a gadget to UDC/unbind a gadget;
Documentation/ABI/testing/configfs-usb-gadget:                          to bind a gadget, empty string "" to unbind.
Documentation/ABI/testing/sysfs-bus-pci:What:           /sys/bus/pci/drivers/.../bind
Documentation/ABI/testing/sysfs-bus-pci:                the driver to attempt to bind to the device found at
Documentation/ABI/testing/sysfs-bus-pci:                bindings.  The format for the location is: DDDD:BB:DD.F.
Documentation/ABI/testing/sysfs-bus-pci:                # echo 0000:00:19.0 > /sys/bus/pci/drivers/foo/bind
Documentation/ABI/testing/sysfs-bus-pci:What:           /sys/bus/pci/drivers/.../unbind
Documentation/ABI/testing/sysfs-bus-pci:                driver to attempt to unbind from the device found at
Documentation/ABI/testing/sysfs-bus-pci:                bindings.  The format for the location is: DDDD:BB:DD.F.
Documentation/ABI/testing/sysfs-bus-pci:                # echo 0000:00:19.0 > /sys/bus/pci/drivers/foo/unbind
Documentation/ABI/testing/sysfs-bus-pci:                for the device and attempt to bind to it.  For example:
Documentation/ABI/testing/sysfs-bus-pci:                to driver_override will have an opportunity to bind to the
Documentation/ABI/testing/sysfs-bus-pci:                This returns the device to standard matching rules binding.
Documentation/ABI/testing/sysfs-bus-pci:                Writing to driver_override does not automatically unbind the
Documentation/ABI/testing/sysfs-bus-pci:                will not bind to any driver.  This also allows devices to
Documentation/ABI/testing/sysfs-bus-pci:                opt-out of driver binding using a driver_override name such as
Documentation/ABI/testing/sysfs-bus-usb:                for the device and attempt to bind to it.  For example:


I am pretty sure patches to fix this are accepted...

The bind/unbind attributes normally (always?) take a bus specific device
name as input.  I.e something like the '0000:00:19.0' shown above for
PCI, or '4-2:1.2' for USB.
Also I found related attributes called 'new_id and remove_id' (for PCI 
drivers) and also 'new_device and delete_device' (present in the i2c 
adapter devices).
These are better documented:

bjorn at nemi:/usr/local/src/git/linux$ git grep new_id Documentation/ABI/
Documentation/ABI/testing/sysfs-bus-pci:What:           /sys/bus/pci/drivers/.../new_id
Documentation/ABI/testing/sysfs-bus-pci:                # echo "8086 10f5" > /sys/bus/pci/drivers/foo/new_id
Documentation/ABI/testing/sysfs-bus-pci:                that was dynamically added via the new_id sysfs entry.
Documentation/ABI/testing/sysfs-bus-usb:What:           /sys/bus/usb/drivers/.../new_id
Documentation/ABI/testing/sysfs-bus-usb:                # echo "8086 10f5" > /sys/bus/usb/drivers/foo/new_id
Documentation/ABI/testing/sysfs-bus-usb:                # echo "0458 7045 0 0458 704c" > /sys/bus/usb/drivers/foo/new_id
Documentation/ABI/testing/sysfs-bus-usb:                # cat /sys/bus/usb/drivers/foo/new_id
Documentation/ABI/testing/sysfs-bus-usb:What:           /sys/bus/usb-serial/drivers/.../new_id
Documentation/ABI/testing/sysfs-bus-usb:                "/sys/bus/usb/drivers/.../new_id" apply.
Documentation/ABI/testing/sysfs-bus-usb:                that was dynamically added via the new_id sysfs entry.
Documentation/ABI/testing/sysfs-bus-usb:                "/sys/bus/usb/drivers/.../new_id"

Now how are they different from the bind/unbind 
attributes, because as far as I know, even they do the same thing.
No, they do different things.

The bind/unbind attributes tries to attach/detach a driver to/from a
device supported by that driver.  The new_id/remove_id attributes
adds/removes device IDs to/from the list of devices supported by the
driver.

Adding a new device ID to a driver will usually cause previously unbound
devices with a matching ID to be bound though, which I guess is the part
confusing you.
Could any one guide me through any documentation regarding all these issues
Looks like you'll have to write some of that documentation ;-)


Bj?rn
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help