The Complete Guide to the Linux Device Model and Driver Subsystems
How the Linux 6.12 device model binds drivers to devices, and how platform drivers use device tree, devres and runtime PM to expose hardware through subsystems.

A Linux driver is rarely written against the hardware alone. It is written against a model: a set of kernel objects that represent buses, devices, drivers and classes, rules for how a driver is matched to a device, helpers that manage the resources a driver acquires, and subsystems that decide what interface the rest of the system sees. Once that model is clear, the individual driver posts in this cluster, for GPIO, LEDs, watchdogs, clocks and the rest, read as variations on one pattern. This guide builds that pattern from the bottom. It explains the objects and how they appear in sysfs, walks a driver from device tree node to bound device, covers managed resources, deferred probing and runtime power management, and shows how to choose and use a subsystem for new hardware. The kernel version is Linux 6.12.
The short version is this. The kernel represents every device as a struct device on a bus, and every driver as a struct device_driver registered with that bus. The bus matches devices to drivers and calls the driver's probe. The driver acquires resources, preferably through managed devm_ functions that release themselves, and registers its device with a subsystem, such as input, LED, watchdog or network, which gives user space a standard interface. Device tree, ACPI and discoverable buses describe what exists, the driver says how to run it, and the subsystem says how it looks from outside.
The reference documents are the kernel's driver model overview, the device driver design patterns and the device tree usage model.
Why there is a model at all
Early Linux drivers each found their hardware in their own way and created their own device files. That worked for a handful of devices and fell apart as soon as power management, hotplug and thousands of device types arrived. A system that can suspend must tell every driver to stop, in the right order: a USB disk before its controller, a controller before its bridge. Hotplug needs a uniform way to say a device appeared or left. And user space wants to ask "what devices exist, and which driver runs each one" without knowing every driver.
The device model answers all three with one set of objects and one tree. Every device sits somewhere in a hierarchy that mirrors how it is connected, the hierarchy is exported through sysfs, and the core uses it for power-management ordering, hotplug events and driver binding. A driver author gets those for free by using the model's structures and does not rebuild them.
The four objects
Four kinds of object carry most of the model:
| Object | Structure | Represents |
|---|---|---|
| Bus | struct bus_type | A way devices are connected and matched: PCI, USB, platform, I2C, SPI |
| Device | struct device | One piece of hardware or one logical device, with a parent |
| Driver | struct device_driver | Code that can control some devices on one bus |
| Class | struct class | A group of devices that share a function, regardless of bus |
A bus defines how matching works. The PCI bus compares vendor and device IDs, the USB bus compares IDs and interface classes, and the platform bus compares names or device tree compatible strings. Each bus type keeps a list of its devices and a list of its drivers and runs the match when either list changes.
A device is the thing that has a driver. It has a name, a parent, a bus, a pointer to its bound driver and a place in sysfs. Most subsystem structures embed one: a pci_dev, a usb_interface, a platform_device and a net_device each contain or point to a struct device.
A driver has a name, the bus it belongs to, and the callbacks the model uses: probe, remove, shutdown and the power-management hooks. A driver registers with its bus, and the bus walks its devices looking for matches.
A class is orthogonal to the bus. A USB serial adapter and an on-board UART are on different buses and both are in the tty class. User space looks at /sys/class/ to find all devices of one function regardless of where they are wired, which is how /sys/class/net, /sys/class/leds and /sys/class/rtc work.
What sysfs shows
Sysfs is the model rendered as a filesystem, and reading it is the quickest way to see what the kernel believes. Three trees matter. /sys/devices is the physical hierarchy, with each device under its parent. /sys/bus/<bus>/devices and /sys/bus/<bus>/drivers list the devices and drivers of each bus, with symbolic links into the first tree. /sys/class/<class> lists devices by function, again with links.
ls /sys/bus/platform/drivers | head -n 4
ls /sys/bus/platform/drivers/sample-ledalarmtimer
bcm2835-gpio
bcm2835-wdt
dma-pl330
10000000.led bind module uevent unbindInside a driver's directory, each bound device is a link, and the bind and unbind files change the binding by hand. Inside a device's directory, driver links to the bound driver, subsystem links to its bus or class, power holds the runtime power-management state, and attributes the driver created sit beside them. The post on the PCI lookup with lspci -k and the USB equivalent use these same links, as do tools such as udev.
How a driver gets bound
Binding is what the model does that nothing else does. It happens in the same way for every bus, in four steps.
First, a device is registered with a bus. On a discoverable bus, the bus code does it after enumeration. On a platform with a device tree, the kernel creates a platform_device for each node that is enabled, at boot.
Second, a driver is registered with the same bus, either at boot for built-in drivers or when a module loads.
Third, the bus's match function compares the two. For the platform bus, a driver can match by name, by an of_match_table of device tree compatible strings, or by an ACPI ID table. The driver's table is also exported to the module metadata, so modprobe can load the right module when a device appears.
Fourth, on a match the core calls the driver's probe. If probe returns zero, the device is bound and its driver link appears. If it returns a negative error, the device stays unbound, and the core may try other drivers. The special error -EPROBE_DEFER means "a resource I need is not ready yet", and the core retries later, which matters so much that it gets its own section below.
The model also lets you override the choice. Writing a driver name to a device's driver_override file makes the next bind use that driver and no other, which is how VFIO claims a PCI device, as in the VFIO post. Writing a device name to a driver's unbind file detaches it, and writing it to bind attaches it.
Describing hardware: device tree and the platform bus
Many embedded devices are not discoverable. A UART controller at a fixed address does not announce itself, so the kernel needs a description from outside, and on Arm and RISC-V boards that is the device tree. A device tree node names the device, says which driver can handle it, and lists the resources it uses:
uart1: serial@10003000 {
compatible = "example,sample-uart";
reg = <0x10003000 0x100>;
interrupts = <0 42 4>;
clocks = <&clk_peri 7>;
clock-names = "baud";
resets = <&rst 3>;
vdd-supply = <®_3v3>;
pinctrl-names = "default";
pinctrl-0 = <&uart1_pins>;
status = "okay";
};Each property is a statement about the hardware, and the driver reads the ones it needs. compatible is the match key. reg is the register range, which becomes a memory resource of the platform device. interrupts becomes an IRQ resource. clocks, resets and vdd-supply name providers of a clock, a reset line and a regulator. pinctrl-0 names the pin configuration to apply before the driver starts, covered in the pin controller post. status = "okay" enables the node, and a node with status = "disabled" creates no device.
The point of the arrangement is separation. The same driver binary runs on every board that has this UART, and what differs per board is the device tree: the address, the interrupt, which clock feeds it. A new board needs a new tree and no new driver code.
On systems with ACPI, the same information comes from firmware tables with different names, and the driver reaches it through the generic property functions in <linux/property.h> such as device_property_read_u32(), which work with either source. A driver that uses them runs under device tree and ACPI unchanged.
A complete platform driver
Putting the pieces together, this driver for the UART-like block takes every kind of resource from the device tree and releases all of them on its own:
// SPDX-License-Identifier: GPL-2.0
#include <linux/clk.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/reset.h>
#define REG_CTRL 0x00
#define REG_STATUS 0x04
#define CTRL_ENABLE BIT(0)
struct sample {
struct device *dev;
void __iomem *regs;
struct clk *clk;
int irq;
};
static irqreturn_t sample_irq(int irq, void *data)
{
struct sample *s = data;
u32 status = ioread32(s->regs + REG_STATUS);
if (!status)
return IRQ_NONE;
iowrite32(status, s->regs + REG_STATUS);
return IRQ_HANDLED;
}
static int sample_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct reset_control *rst;
struct sample *s;
u32 baud = 115200;
int ret;
s = devm_kzalloc(dev, sizeof(*s), GFP_KERNEL);
if (!s)
return -ENOMEM;
s->dev = dev;
s->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(s->regs))
return PTR_ERR(s->regs);
s->irq = platform_get_irq(pdev, 0);
if (s->irq < 0)
return s->irq;
ret = devm_regulator_get_enable(dev, "vdd");
if (ret)
return dev_err_probe(dev, ret, "cannot enable supply\n");
s->clk = devm_clk_get_enabled(dev, "baud");
if (IS_ERR(s->clk))
return dev_err_probe(dev, PTR_ERR(s->clk), "no baud clock\n");
rst = devm_reset_control_get_optional_exclusive(dev, NULL);
if (IS_ERR(rst))
return dev_err_probe(dev, PTR_ERR(rst), "reset line\n");
reset_control_deassert(rst);
device_property_read_u32(dev, "current-speed", &baud);
ret = devm_request_irq(dev, s->irq, sample_irq, 0, dev_name(dev), s);
if (ret)
return ret;
iowrite32(CTRL_ENABLE, s->regs + REG_CTRL);
platform_set_drvdata(pdev, s);
dev_info(dev, "ready, clock %lu Hz, speed %u\n",
clk_get_rate(s->clk), baud);
return 0;
}
static const struct of_device_id sample_of_match[] = {
{ .compatible = "example,sample-uart" },
{ }
};
MODULE_DEVICE_TABLE(of, sample_of_match);
static struct platform_driver sample_driver = {
.probe = sample_probe,
.driver = {
.name = "sample-uart",
.of_match_table = sample_of_match,
},
};
module_platform_driver(sample_driver);
MODULE_DESCRIPTION("Platform driver walkthrough");
MODULE_LICENSE("GPL");With a 48 MHz clock and no current-speed property, the log shows:
sample-uart 10003000.serial: ready, clock 48000000 Hz, speed 115200The device name 10003000.serial is the node's unit address and its label, which is how the platform bus names devices created from the tree. The driver has no remove function, and that is not an omission. Everything it acquired is managed, and the core releases it in reverse order of acquisition when the driver detaches.
Managed resources
The devm_ prefix marks a family of functions that attach a resource to the device and release it automatically. The mechanism, called devres, keeps a list of release actions on the struct device. Each devm_ call adds an entry, and when the driver detaches, whether because probe failed or because of unbind, the core runs the entries in the opposite order.
This removes the largest source of driver bugs, an error path that forgets one release. It also changes how a driver is written. A probe that returns an error at any line cleans up everything above it, with no labels. The order of release matches the reverse of acquisition, which is what a hand-written unwinding aims for and often gets wrong.
Three rules keep managed code correct. First, anything freed by devres is freed after remove returns, so a remove that needs a resource to shut the hardware down still has it. Second, a handler that runs until the last moment, such as an interrupt, is freed by devres in the right position relative to what it uses, as long as it was requested after the resources it touches. The order of the devm_request_irq() call in the example, after the clock and registers, is deliberate. Third, a managed resource tied to the wrong device is released at the wrong time: pass the device that owns the lifetime you want, which is almost always the one probe received.
A managed call exists for most of what a driver acquires. The ones used above:
| Function | Resource |
|---|---|
devm_kzalloc() | Memory |
devm_platform_ioremap_resource() | Register mapping, with the region claimed |
devm_request_irq() | An interrupt handler |
devm_clk_get_enabled() | A clock, acquired and enabled |
devm_regulator_get_enable() | A power supply, acquired and enabled |
devm_reset_control_get_optional_exclusive() | A reset line that may be absent |
devm_gpiod_get() | A GPIO line, as in the descriptor post |
When no managed form exists for a custom action, devm_add_action_or_reset() registers any function as a release step, so even a hardware shutdown can run in order.
Deferred probing
Resources have an order, and the kernel starts drivers in no particular order. A UART that needs a clock cannot probe before the clock driver has registered its provider, and the clock driver itself may need a pin controller. If the UART's probe runs first, devm_clk_get_enabled() finds no provider and returns -EPROBE_DEFER.
That error is a request, not a failure. The core puts the device on a deferred list and retries after other drivers have probed, and again whenever a new driver binds, until probe succeeds or nothing else can change. The driver's only duties are to return the error from the failed call unchanged, and to avoid side effects before it, since the function will run again. That second rule is the one that matters: a probe that registers a node, programs a register and then defers leaves a half-initialized device behind. Acquire everything that might defer first, and act on the hardware afterwards.
dev_err_probe() exists for this case. It prints a real error message normally, but when the error is -EPROBE_DEFER it records the reason quietly instead of printing it. The list of devices waiting is in debugfs, which is the first place to look when a device never appears:
sudo cat /sys/kernel/debug/devices_deferred10003000.serial sample-uart: baud clockThe line names the device, the driver and the reason string the driver gave. A device that sits here forever means the provider never appeared: the clock driver is not enabled in the kernel configuration, the device tree names a provider that does not exist, or a cycle makes each wait for the other. The kernel's fw_devlink machinery reads the dependencies from the tree and orders probing so most deferrals never happen, but it cannot repair a missing provider.
Subsystems: the interface the world sees
A platform driver that stops at probe does nothing visible. Its value comes from registering with a subsystem, a framework that defines what a certain kind of device looks like to the rest of the system. The subsystem provides the user-space interface, the common behavior and often a large part of the code. The driver supplies a small table of operations and the hardware knowledge.
| Hardware | Subsystem | What user space gets | Cluster post |
|---|---|---|---|
| Buttons, keys, sensors that report events | input | /dev/input/eventN | input driver |
| Indicator lights | LED class | /sys/class/leds/ | LED driver |
| Hardware watchdog timers | watchdog | /dev/watchdogN | watchdog driver |
| Clocks that keep calendar time | RTC | /dev/rtcN, /sys/class/rtc/ | RTC driver |
| Pulse width modulation | PWM | /sys/class/pwm/ | PWM consumer |
| Pins and their functions | GPIO and pinctrl | /dev/gpiochipN | GPIO chip, pin controller |
| Network interfaces | net | an interface in ip link | network driver |
| Displays | DRM/KMS | /dev/dri/cardN | DRM/KMS structure |
| Temperature, voltage, fans | hwmon | /sys/class/hwmon/ | not covered here |
| Analog converters and sensors | IIO | /sys/bus/iio/devices/ | not covered here |
The posts in that table all follow the same arc as the platform driver above: take resources in probe, fill in a structure of callbacks for the subsystem, register, and let the framework do the rest. The structure names change, from led_classdev to watchdog_device to rtc_class_ops, and the shape does not. Reading one subsystem well transfers to the others.
Choosing a subsystem
For new hardware, the first decision is which subsystem owns it, and the answer comes from what the device does for the user, not from how it connects. A temperature sensor on I2C belongs to hwmon or IIO, not to an "I2C subsystem". A button on a GPIO belongs to input. Check the table: if one row fits, use it, and the interface comes with it.
If none fits, the choices narrow. A device that really is its own thing can register a misc or character device with its own ioctl interface, at the cost of defining a new user-space interface, which the kernel community will review hard because it has to be maintained indefinitely. A device that only a single program will use is a candidate for user space, through /dev/mem-style access on a restricted system, UIO or VFIO. In every case, avoid inventing an interface for something the kernel already knows how to present.
Attributes and class devices
A driver adds its own files to sysfs through attributes, small read and write handlers attached to the device. They are the right place for settings and status that do not justify a subsystem. A read-only attribute needs a show function:
static ssize_t clock_rate_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct sample *s = dev_get_drvdata(dev);
return sysfs_emit(buf, "%lu\n", clk_get_rate(s->clk));
}
static DEVICE_ATTR_RO(clock_rate);
static struct attribute *sample_attrs[] = {
&dev_attr_clock_rate.attr,
NULL,
};
ATTRIBUTE_GROUPS(sample);Pointing the driver's .dev_groups at the group makes the core create the file when the device binds and remove it when it unbinds, with no code in probe or remove:
.driver = {
.name = "sample-uart",
.of_match_table = sample_of_match,
.dev_groups = sample_groups,
},cat /sys/devices/platform/10003000.serial/clock_rate then prints 48000000. sysfs_emit() is the correct way to write into the buffer, since it knows the buffer is one page and refuses to overflow it. Attributes are an interface to user space, and the same stability expectations apply: choose the name and units once, document them, and keep them.
Runtime power management
A device that is idle should cost no power. The model supports this with runtime power management, in which the core suspends a device when no one is using it and resumes it on demand. A driver takes part by providing two callbacks and by telling the framework when it is using the hardware.
static int sample_runtime_suspend(struct device *dev)
{
struct sample *s = dev_get_drvdata(dev);
iowrite32(0, s->regs + REG_CTRL);
clk_disable_unprepare(s->clk);
return 0;
}
static int sample_runtime_resume(struct device *dev)
{
struct sample *s = dev_get_drvdata(dev);
int ret = clk_prepare_enable(s->clk);
if (ret)
return ret;
iowrite32(CTRL_ENABLE, s->regs + REG_CTRL);
return 0;
}
static const struct dev_pm_ops sample_pm_ops = {
RUNTIME_PM_OPS(sample_runtime_suspend, sample_runtime_resume, NULL)
};The driver names the table in .driver.pm = pm_ptr(&sample_pm_ops), and the rest is bracketing. Around every access to the hardware, the driver takes a reference and then drops it:
ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
return ret;
val = ioread32(s->regs + REG_STATUS);
pm_runtime_put(dev);pm_runtime_resume_and_get() makes sure the device is powered, calling the resume callback if it was suspended, and pm_runtime_put() allows the framework to suspend it again after an optional delay. In probe, the driver enables the mechanism with devm_pm_runtime_enable() and tells the framework its initial state. The state is visible in sysfs as power/runtime_status, which reads suspended or active, and power/control set to on forbids runtime suspend, a useful switch when debugging.
System sleep is separate. The callbacks for suspend to RAM are .suspend and .resume in the same table, and for many drivers the right implementation is to force the runtime state: SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) reuses the runtime callbacks, which is correct whenever the two kinds of sleep need the same steps.
Debugging the model
When a driver does not work, the question is almost always in the model and not in the hardware code, and a few checks answer it. Does the device exist? ls /sys/bus/platform/devices shows every platform device, and a device tree node with status = "disabled", a typo in the node, or a missing compatible leaves no entry. Is a driver registered for it? ls /sys/bus/platform/drivers and the modalias of the device against the module's aliases answer that, using the method from the PCI lookup post. Did probe run? The driver link in the device directory says whether it bound. If it did not, devices_deferred says whether it is waiting, and dmesg has the error otherwise.
Dynamic debug turns on a module's dev_dbg() lines at run time, without a rebuild:
echo 'module sample_plat +p' | sudo tee /sys/kernel/debug/dynamic_debug/controlFor ordering problems, the boot parameter driver_probe_timeout sets how long the kernel waits for deferred probes before giving up on them, and fw_devlink=permissive relaxes the dependency enforcement, which separates "my provider is missing" from "the dependency tracking is wrong". Both are diagnostics, not fixes, and a production system should not need either.
Testing a driver in the model
Because the model defines the lifecycle, the lifecycle is what to test. Load the module and confirm the bound device and the log line. Unbind and rebind in a loop to confirm that managed cleanup is complete:
for i in $(seq 1 50); do
echo 10003000.serial | sudo tee /sys/bus/platform/drivers/sample-uart/unbind > /dev/null
echo 10003000.serial | sudo tee /sys/bus/platform/drivers/sample-uart/bind > /dev/null
done
sudo dmesg | tail -n 1sample-uart 10003000.serial: ready, clock 48000000 Hz, speed 115200Unload and reload the module with the device present, which exercises the match at registration. Remove a provider, such as unloading the clock driver, and confirm the failure message is clear and the system survives. If the driver supports runtime power management, read power/runtime_status with the device idle, and check that it suspends and wakes without errors. Each step covers one rule of the model, and a driver that passes them has a sound lifecycle regardless of what its hardware does.
Device tree bindings
A device tree node is an interface, and like any interface it needs a definition. For drivers meant for the kernel, the definition is a binding document in YAML, validated by the dt-schema tooling, and it is part of the submission. A short binding for the example:
%YAML 1.2
---
$id: http://devicetree.org/schemas/serial/example,sample-uart.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Example sample UART
maintainers:
- Example Maintainer <[email protected]>
properties:
compatible:
const: example,sample-uart
reg:
maxItems: 1
interrupts:
maxItems: 1
clocks:
maxItems: 1
clock-names:
const: baud
vdd-supply: true
current-speed:
default: 115200
required:
- compatible
- reg
- interrupts
- clocks
- clock-names
additionalProperties: falseThe binding is the contract between the driver and every board file that uses it. Properties are named, typed and either required or optional, and additionalProperties: false rejects anything not listed, which catches typos at build time instead of at run time. The driver must treat the binding as stable: renaming a property breaks every existing tree, so a change adds the new name and keeps the old one as a fallback.
One boot, from the tree to a device node
It helps to follow a single device through the whole sequence once, since the pieces above happen in a fixed order. At boot, the kernel unpacks the flattened device tree handed over by the bootloader and walks it. For every node under a bus-like parent with status set to okay, the platform code creates a platform_device with the node's resources: the reg ranges as memory resources, the interrupts as IRQ resources, and a pointer to the node itself so the driver can read other properties later. These devices register with the platform bus.
Drivers register as their code initializes. A built-in driver registers early, in an initcall level; a module registers when it loads. Each registration makes the platform bus walk its device list and try to match. On the match, the core runs the driver's probe, which for the example reads resources, requests the clock and the regulator and so on.
Suppose the clock provider has not registered yet. The call to devm_clk_get_enabled() returns -EPROBE_DEFER, probe returns it, the device goes onto the deferred list and nothing is created. Later the clock driver probes, registers its provider, and the core retries every deferred device, including this one. This time probe completes, the device is bound and the driver registers with its subsystem. If that subsystem is a character interface, udev sees the uevent the registration produced and creates the node under /dev. From the first line of the tree to a node a program can open, nobody wrote ordering code. The model sequenced it from the dependencies the drivers declared.
You can watch this happen by raising the boot log verbosity with initcall_debug on the command line, which prints each initcall and probe with its duration, and by reading devices_deferred early. The sequence differs between boots, since drivers may initialize in any order, and the correct driver is the one whose result does not depend on it.
Interrupts, DMA and the other resources
The platform bus gives a driver the same resources as PCI does, through different calls. platform_get_irq() returns the Linux interrupt number for the nth interrupts entry or a negative error that includes -EPROBE_DEFER when the interrupt controller is not ready. It already translates the controller's local numbering into the global one, which is why drivers never use the raw number from the tree. devm_request_irq() and devm_request_threaded_irq() attach handlers, with the same rules for handlers as in the PCI driver guide: short top halves, no sleeping, acknowledge your own cause.
DMA on a platform device follows the DMA API in the DMA post: set the mask for the device with dma_set_mask_and_coherent(), then use coherent or streaming mappings. Where the device tree says the device is not cache coherent with the CPU, the core handles it through the dma-coherent property and the right DMA operations are selected for the device, so the driver code is identical on coherent and non-coherent systems.
A device can also own sub-resources the model understands. A device with a dmas property asks a DMA controller driver for a channel with dma_request_chan(), and one with iommus gets its DMA translated automatically by the IOMMU attached to it. These are the same producer and consumer relationship as clocks and regulators: the tree names a provider, the consumer API resolves the name, and a missing provider defers the probe. A driver written against the consumer APIs rather than the provider's registers will run on any chip that supplies the resource, which is the whole point.
Hotplug, uevents and udev
The model reports every change as a uevent, a small message sent from the kernel to user space with a set of key and value pairs: the action (add, remove, bind, unbind, change), the device path, the subsystem and driver information. udevd listens, matches rules, and acts: it creates device nodes with the right permissions, loads modules whose aliases match, creates stable symbolic links and runs programs. The kernel does not create nodes in /dev on its own, except through the minimal devtmpfs that gives early boot something to use.
The link between the two halves is the module alias. When a device is added, the uevent carries a MODALIAS string that encodes its identity, of:NsampleCexample,sample-uart for a device tree device, or the PCI and USB forms seen in the earlier posts, and udev runs modprobe with it. The module's MODULE_DEVICE_TABLE() is what built the alias database that modprobe searches, so a driver without that line never loads automatically. You can watch the stream with udevadm monitor:
udevadm monitor --kernel --subsystem-match=platformKERNEL[512.401234] add /devices/platform/soc/10003000.serial (platform)
KERNEL[512.410812] bind /devices/platform/soc/10003000.serial (platform)The first line is the device appearing, and the second is the driver binding to it. A driver that registers a class device generates a further add for the class entry, and that is the event that creates the /dev node. When you need a stable name for a device that can come up under different numbers, a udev rule matching the attributes in sysfs creates a link that does not change, and rules like that belong in the system configuration, never in the driver.
Portability: device tree, ACPI and the property API
A driver that reads the device tree directly, with calls such as of_property_read_u32(), runs only on device tree systems. For a driver that might meet ACPI, or that is meant to be reusable, the generic property API in <linux/property.h> is the better layer. device_property_read_u32(), device_property_present() and the fwnode handles it exposes read the same information from a tree, an ACPI _DSD table or a software node, and the driver does not care which. The driver in this guide already uses it for current-speed.
The match tables follow the same logic: a driver lists of_match_table for the tree and acpi_match_table for ACPI, and the core picks whichever the firmware provides. Where hardware is handled on a PC through ACPI, the clock and regulator resources do not exist as tree nodes, because the firmware manages them itself. The driver must then treat those consumers as optional, using the _optional variants, and rely on the firmware to have powered the device. That is a real difference in practice, and a driver tested only on one firmware type will fail on the other for exactly this reason.
A review checklist
Before treating a platform driver as done, read it against these questions. Each is a class of bug that has shipped.
| Area | Question |
|---|---|
| Matching | Does the match table cover every compatible the driver supports, with the module table exported? |
| Resources | Is every resource taken through a managed call, in the order the hardware needs? |
| Deferral | Is -EPROBE_DEFER returned unchanged, and is the hardware untouched before any call that may defer? |
| Errors | Do errors use dev_err_probe() so deferral stays quiet? |
| State | Is per-device state in one structure, with no globals? |
| Interrupts | Does the handler stay short, return IRQ_NONE for foreign causes and acknowledge its own? |
| Subsystem | Is the device registered with the right subsystem, last in probe, after everything it uses is ready? |
| Attributes | Do sysfs files use sysfs_emit() and stable names, and are they in dev_groups? |
| Power | Is hardware access bracketed by runtime PM calls, with both callbacks provided? |
| Binding | Is there a YAML binding that matches what the driver reads? |
| Lifecycle | Does repeated unbind, bind and module reload leave no leaks and no warnings? |
The row about registering with a subsystem last deserves emphasis. The moment a device is registered, user space can use it, so everything it needs must already work. A driver that registers early and finishes initialization afterward exposes a node that fails when opened in the gap.
Failures and where they come from
Symptoms in this area are distinctive, and a short map pays off. A device that never appears in /sys/bus/platform/devices is a tree problem: the node is disabled, misspelled or under a parent that is not a bus. A device that appears with no driver link has no matching driver or has deferred, and the two are told apart by devices_deferred and by comparing the modalias with the driver's table. A driver that probes and then does nothing registered no subsystem device, or registered it before the hardware worked.
A probe that fails with an error on every board but the one you developed on is usually an optional resource coded as required, or a property that the other boards' trees do not set. A kernel warning about a resource "already requested" names a conflict between two drivers that claim the same range, which is a tree error, since two nodes cover the same registers. A crash on unbind is a handler or a work item running after something it uses was released, and it is cured by acquiring in the right order, so that the managed release order is the right order.
A power management bug shows up as a device that works once and then returns garbage: it suspended while in use, because a code path touches the hardware without taking a runtime PM reference. Setting power/control to on for that device removes the symptom and confirms the cause.
Where this guide does not apply
This guide covers drivers written for the kernel's model on a single system. It does not cover the internals of the sysfs and kobject layer, which a driver author rarely touches, and it does not cover writing a new bus type, which is needed only for a new kind of interconnect. It does not go into the details of any one subsystem, since each has a post in this cluster and a document in the kernel tree. It does not cover user-space device management by udev, which reacts to the events the model generates, or container device passthrough, which builds on them.
It also assumes drivers that live in the kernel. Out-of-tree and user-space drivers use the same model from the outside: a VFIO or libusb driver still binds to a device through the core, and the comparison in the libusb post covers when that is the better choice. Finally, the examples assume a device tree system. A PC with ACPI uses the same model, with ACPI tables playing the role of the tree, and the generic property API keeps one driver portable between them.


