Dynamic Platform Driver Problem – How to Fix It
In this article
Yes, you can resolve a dynamic platform driver problem by verifying the device tree, ensuring the driver is compiled and loaded, and correcting the binding information.
What You’ll Need
- A Linux development workstation with root access
- The kernel source tree that matches the running kernel
- Access to the target board’s device tree source (DTS) files
- Basic knowledge of make, grep, and the Linux kernel build system
- Serial console or SSH access to the target for log inspection
Step‑by‑Step
- Confirm the symptom. Open a terminal on the target and run
dmesg | grep -i "platform". Look for messages such as “no driver found for …” or “failed to bind driver”. Note the exact compatible string or node name that the kernel reports. - Identify the driver source. Search the kernel tree for the driver that should handle the device. For example,
grep -R "MODULE_ALIAS.*mydevice" $(pwd)/drivers/will reveal the source file and theof_match_tableentries. - Check the device‑tree entry. Open the relevant
.dtsor.dtsifile and verify that thecompatibleproperty exactly matches one of the strings in the driver’sof_match_table. The match is case‑sensitive and must include any required version suffixes. - Validate the kernel configuration. Run
make menuconfig(ormake nconfig) in the kernel source and ensure that the driver’s config option is set tom(module) ory(built‑in). Look under the appropriate subsystem (e.g., “Device Drivers → Platform drivers”). Save and exit. - Rebuild and install the kernel or module. If the driver is a module, execute
make modulesand thenmake modules_install. For a built‑in driver, rebuild the whole kernel withmake -j$(nproc)and flash the new image to the board. - Load the driver. For a module, run
modprobe mydriveron the target. Verify that the module appears inlsmodand thatdmesgnow shows a successful bind message. - Refresh the device tree. If you edited the DTS, recompile it to a DTB with
dtc -I dts -O dtb -o myboard.dtb myboard.dtsand copy the DTB to the boot partition. Update the bootloader configuration (e.g.,bootargsin U‑Boot) to point to the new DTB. - Reboot the board. Power‑cycle or issue
reboot. After the system comes up, rundmesg | grep -i mydriverto confirm that the driver bound without errors. - Test functionality. Use the driver’s sysfs entries, character device, or any provided utility to exercise the hardware. For example,
cat /sys/class/mydevice/statusormytool --testshould return expected values. - Document the fix. Record the compatible string, kernel config option, and any DTS modifications in your project’s README. This prevents the same issue from resurfacing after future updates.
Common Mistakes
- Using a mismatched compatible string – even a missing dash or extra space prevents the of‑match from succeeding.
- Leaving the driver compiled as
CONFIG_MYDRIVER=n– the kernel will never load a disabled driver. - Editing the DTS but forgetting to recompile to DTB or to update the bootloader’s DTB path.
- Loading a module before the device tree has been parsed; the driver may miss the probe opportunity.
- Overlooking required clock or regulator definitions in the device tree, which can cause the driver to abort during init.
Tips
- Enable
CONFIG_DEBUG_DRIVERandCONFIG_OF_DYNAMICto get more verbose binding logs. - Use
of_property_read_string()in a temporary test module to print the exact compatible string the kernel sees. - When working with multiple similar devices, give each node a unique
labeland reference it in the driver’splatform_get_resource_byname()calls. - Keep a copy of the original DTB; you can always compare it with
diffafter changes to avoid accidental deletions. - If the driver is built‑in, you can still force a reload by writing
1to/sys/bus/platform/drivers/mydriver/unbindand thenbindwith the device’s name.
Troubleshooting
If the driver still does not bind after following the steps above, try the following escalation path:
- Restart the kernel log. Run
dmesg -Cbefore rebooting to clear old messages. After reboot, immediately rundmesg | tail -n 30to capture fresh output. - Verify the DTB in use. On the target, execute
cat /proc/device-tree/compatible(or navigate the/proc/device-tree/hierarchy) to confirm the compatible string present at runtime. - Check for duplicate nodes. Two nodes with the same
compatiblecan cause the kernel to bind the first and ignore the second. Usedtc -I dtb -O dts -o - myboard.dtb | grep compatibleto list all entries. - Inspect regulator and clock dependencies. Missing or incorrectly named regulators will appear as “failed to get regulator xyz”. Add the missing
regulatorsnode or correct the name. - Force a manual bind. Echo the device’s full path into the driver’s bind file, e.g.,
echo /sys/devices/platform/mydevice > /sys/bus/platform/drivers/mydriver/bind. Any error message will hint at the missing prerequisite. - Recompile with debug prints. Add
pr_debug()statements inside the driver’sprobe()function, rebuild, and watchdmesg. This reveals exactly where the probe fails. - Revert recent changes. If the problem appeared after a kernel upgrade, boot the previous kernel version to see whether the driver works there. This isolates upstream regressions.
- Seek upstream help. Gather the kernel version, driver source, DTS snippet, and full
dmesgoutput. Open a bug report on the kernel mailing list or the SoC vendor’s support portal.
Frequently Asked Questions
Why does the driver bind on some boards but not others?
Different boards often use distinct compatible strings or require additional resources such as clocks. If the string does not match the driver’s of_match_table, the kernel will skip the probe.
Can I load a platform driver as a module if it was originally built‑in?
Yes, but you must enable the driver’s CONFIG_* option as m, rebuild the kernel, and install the resulting .ko. The driver will then be loadable with modprobe.
What if the device tree shows the correct compatible string but the driver still refuses to bind?
Check for missing regulator or clock definitions, and ensure the driver’s probe() does not return an error due to unavailable resources.
Is it safe to edit the device tree on a production system?
Yes, as long as you keep a backup of the original DTB and test the new DTB on a non‑critical unit first. A malformed DTB can prevent the system from booting.
How do I know which kernel version introduced the binding issue?
Boot previous kernel versions and compare dmesg output. The first version where the driver binds successfully indicates the regression point.
Do I need to restart the whole board after loading a new module?
No. After modprobe, the driver will attempt to bind to any matching devices that are already present. A full reboot is only required after changing the device tree.