</>EmbeddedInterview

What is the Linux device model (bus, device, driver)?

MediumLinux Kernel & Device Drivers

Short answer: The kernel represents hardware as devices that sit on buses (platform, I2C, SPI, PCI, USB, virtio). Drivers register with a bus and declare which devices they support (ID tables, OF/ACPI match tables). When the bus core finds a device and a driver that match, it calls the driver's probe(); on removal or unbinding it calls remove(). Everything is exposed in sysfs (/sys/bus, /sys/devices, /sys/class), and board-specific details come from the device tree or ACPI rather than driver code.

Core objects

Object Role
struct bus_type knows how to match devices and drivers (match()), probe, uevents
struct device one instance of hardware; parent/child hierarchy, power state, resources, of_node
struct device_driver probe/remove/shutdown, PM ops, match tables
struct class a user-facing grouping (input, net, tty, backlight), independent of the bus
struct kobject reference counting and sysfs representation underneath all of these

Matching order for platform devices: device tree compatible → ACPI ID → ID table (platform_device_id) → driver name.

Probe lifecycle

  1. The device is registered (from the device tree at boot, by a bus scan such as PCI/USB enumeration, or by hot-plug).
  2. The core tries each driver on that bus; the first match runs probe().
  3. If probe() returns -EPROBE_DEFER (a needed clock, regulator or GPIO provider is not ready yet), the core retries later.
  4. On remove() (module unload, unbind, hot-unplug), the driver releases everything; devm_ resources are freed automatically after remove().

Manual binding: echo 1-0048 > /sys/bus/i2c/drivers/tmp102/unbind and .../bind; driver_override forces a specific driver (used with VFIO).

Benefit: one driver works on any board; the same kernel image boots many boards; power management walks the device hierarchy in the correct order (children suspend before parents).