Driver Core APIs¶
Overview¶
The Linux Driver Core provides generic APIs for registering:
- Buses
- Devices
- Drivers
and coordinating device-driver matching.
These APIs form the foundation of:
- Platform Bus
- I2C
- SPI
- USB
- PCI
subsystems.
bus_register()¶
Prototype¶
Description¶
Registers a bus with the Linux Driver Core.
After registration:
is created.
The bus becomes available for:
- Device registration
- Driver registration
- Matching
Parameters¶
| Parameter | Description |
|---|---|
bus |
Bus object to register |
Return Value¶
| Value | Meaning |
|---|---|
0 |
Success |
< 0 |
Failure |
Example¶
Related APIs¶
bus_unregister()
bus_unregister()¶
Prototype¶
Description¶
Removes a previously registered bus.
All associated devices and drivers should be removed first.
Example¶
device_register()¶
Prototype¶
Description¶
Registers a device with the Driver Core.
The device becomes visible under:
and under the corresponding bus.
The Driver Core automatically attempts matching against existing drivers.
Parameters¶
| Parameter | Description |
|---|---|
dev |
Device object |
Return Value¶
| Value | Meaning |
|---|---|
0 |
Success |
< 0 |
Failure |
Example¶
Important Notes¶
A device must provide a valid release callback.
Example:
Failure to provide a release callback will trigger a kernel warning.
Related APIs¶
device_unregister()
device_unregister()¶
Prototype¶
Description¶
Removes a previously registered device.
The Driver Core automatically:
when necessary.
Example¶
driver_register()¶
Prototype¶
Description¶
Registers a driver with the Driver Core.
The driver becomes visible under:
The Driver Core automatically attempts matching against existing devices.
Parameters¶
| Parameter | Description |
|---|---|
drv |
Driver object |
Return Value¶
| Value | Meaning |
|---|---|
0 |
Success |
< 0 |
Failure |
Example¶
Important Notes¶
Successful registration does not guarantee successful probe.
Example:
In this case:
Related APIs¶
driver_unregister()
driver_unregister()¶
Prototype¶
Description¶
Removes a registered driver.
If devices are currently bound:
is performed automatically.
Example¶
Device-Driver Lifecycle¶
Removal:
Common Pitfalls¶
Missing release callback¶
Incorrect:
Correct:
Assuming driver_register() implies probe success¶
Incorrect assumption:
Actual behavior:
Related Topics¶
- Linux Driver Model
- Platform Bus Internals
- Driver Core
- Device Tree Integration
Related Labs¶
- Day71 - Linux Driver Model Fundamentals