Skip to content

Linux Device Model

Overview

Linux kernel uses a structured model to manage hardware devices.

Instead of drivers directly accessing hardware, the kernel introduces an abstraction:

Bus <-> Device <-> Driver

Core Components

Device

Represents a physical or virtual hardware component.

Examples: - UART controller - SPI device - I2C controller - GPIO - Custom device (e.g., test-device)


Driver

Kernel code that knows how to control a specific type of device.

Examples: - UART driver - SPI driver - Platform driver


Bus

Responsible for managing devices and drivers and matching them together.

Common buses: - platform (most important in embedded Linux) - i2c - spi - pci - usb


Driver Matching Mechanism

When a driver and device are compatible, the kernel will call:

probe()

probe()

Called when: - A device is discovered - A matching driver is found

Typical responsibilities: - Initialize hardware - Map registers (ioremap) - Request IRQ - Register char device or sysfs entries


remove()

Called when: - Driver is unloaded - Device is removed

Typical responsibilities: - Free resources - Unregister device - Cleanup memory


Platform Bus (Important for Embedded Linux)

In embedded systems, hardware is usually fixed (non-discoverable).

Thus Linux uses:

Device Tree -> platform_device -> platform_driver

sysfs and Device Model

The device model is exposed via:

/sys

Important paths:

  • /sys/bus/ → all bus types
  • /sys/devices/ → actual device hierarchy
  • /sys/class/ → categorized view

Key Takeaways

  • Linux separates device and driver via bus abstraction
  • probe() is the entry point of driver initialization
  • platform bus is widely used in embedded systems
  • sysfs reflects kernel internal device structure