Skip to content

Commit bcd085d

Browse files
author
Danilo Krummrich
committed
docs: driver-model: document driver_override
Now that we support driver_override as a driver-core feature through struct device and struct bus_type, add some documentation in the context of how a device / driver binding is established. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/20260303115720.48783-3-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent cb3d104 commit bcd085d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Documentation/driver-api/driver-model/binding.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,51 @@ of the driver is decremented. All symlinks between the two are removed.
9999
When a driver is removed, the list of devices that it supports is
100100
iterated over, and the driver's remove callback is called for each
101101
one. The device is removed from that list and the symlinks removed.
102+
103+
104+
Driver Override
105+
~~~~~~~~~~~~~~~
106+
107+
Userspace may override the standard matching by writing a driver name to
108+
a device's ``driver_override`` sysfs attribute. When set, only a driver
109+
whose name matches the override will be considered during binding. This
110+
bypasses all bus-specific matching (OF, ACPI, ID tables, etc.).
111+
112+
The override may be cleared by writing an empty string, which returns
113+
the device to standard matching rules. Writing to ``driver_override``
114+
does not automatically unbind the device from its current driver or
115+
make any attempt to load the specified driver.
116+
117+
Buses opt into this mechanism by setting the ``driver_override`` flag in
118+
their ``struct bus_type``::
119+
120+
const struct bus_type example_bus_type = {
121+
...
122+
.driver_override = true,
123+
};
124+
125+
When the flag is set, the driver core automatically creates the
126+
``driver_override`` sysfs attribute for every device on that bus.
127+
128+
The bus's ``match()`` callback should check the override before performing
129+
its own matching, using ``device_match_driver_override()``::
130+
131+
static int example_match(struct device *dev, const struct device_driver *drv)
132+
{
133+
int ret;
134+
135+
ret = device_match_driver_override(dev, drv);
136+
if (ret >= 0)
137+
return ret;
138+
139+
/* Fall through to bus-specific matching... */
140+
}
141+
142+
``device_match_driver_override()`` returns > 0 if the override matches
143+
the given driver, 0 if the override is set but does not match, or < 0 if
144+
no override is set at all.
145+
146+
Additional helpers are available:
147+
148+
- ``device_set_driver_override()`` - set or clear the override from kernel code.
149+
- ``device_has_driver_override()`` - check whether an override is set.

0 commit comments

Comments
 (0)