Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To write an embedded Linux device driver, first identify the kernel subsystem that owns the hardware, then connect the device to that subsystem through the correct bus and firmware description. The driver’s probe function should acquire its resources and initialize the device; its operational callbacks, teardown, power management, and user-space interface must follow the same subsystem’s rules. A sound driver is more than register reads and writes: it participates in the Linux driver model and must remain correct under concurrency, errors, and device removal.

Start by choosing the right subsystem

Before writing code, use the schematic and datasheet to establish what the hardware does, how it connects to the processor, and which kernel subsystem represents that function. A peripheral may be attached to the SoC through the platform bus but still belong to a higher-level subsystem such as GPIO, IIO, input, DRM, ALSA, or networking. The bus describes how Linux discovers and communicates with the device; the subsystem defines the behavior and interface expected of that kind of device.

Using an existing subsystem usually gives user space a standard interface and lets the kernel provide shared behavior. For example, a sensor will generally fit IIO better than a custom character device, while a button is usually an input device rather than a bespoke file interface. Use a platform driver when the hardware is an integrated SoC peripheral and no more specific subsystem is appropriate—not simply because the device is soldered onto a board.

Approach Typical discovery or connection What it means for the driver
Platform driver Often described by Device Tree or ACPI; may also use board data Handles an SoC-integrated device and its memory, IRQ, and other platform resources. It can register with a more specific subsystem.
I2C or SPI driver Enumerated or described on an I2C or SPI controller Uses that bus’s transfer and device model rather than treating the peripheral as a platform device.
USB or PCI driver Discovered through bus enumeration and device identifiers Matches the enumerated device and follows that bus’s lifecycle and resource conventions.
Subsystem driver Depends on the underlying bus or parent device Implements a domain-specific framework—such as IIO, input, GPIO, or ALSA—so applications can use its established ABI.

These categories can combine: an I2C sensor driver, for instance, uses the I2C bus and registers with IIO. Compare current drivers for the same hardware class before choosing an architecture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How device discovery and matching work

The Linux driver model connects a device object to a driver object on a bus. For embedded SoC peripherals, the platform bus is a common path: platform devices represent autonomous devices, often controllers integrated into an SoC, and typically expose resources such as memory addresses and IRQs. The platform driver supplies lifecycle callbacks, especially probe and remove; shutdown and power-management hooks may also be relevant. The kernel’s Platform Devices and Drivers documentation is the baseline for this model.

On a Device-Tree-based board, the hardware description identifies the device and its properties. A platform driver commonly matches a compatible string from that description. ACPI-based systems use their firmware identification mechanism; other buses may enumerate devices themselves, and older systems may use static board data. Confirm which method the target board actually uses: a correct driver cannot bind if the device is absent, described incorrectly, or identified with a value the driver does not match.

Probe receives the bound device and is where the driver validates configuration, obtains resources, and initializes hardware. Depending on the device, those resources can include a memory-mapped register range, IRQ, clock, regulator, GPIO, reset control, or DMA configuration. Acquire each through the relevant kernel framework rather than embedding board-specific addresses or assumptions in the driver. A missing or invalid resource should produce a clear error and unwind any work already completed.

Build the driver around its lifecycle

The lifecycle is a sequence, not a one-time initialization call: firmware or bus discovery creates a device, matching selects a driver, probe prepares it for operation, subsystem callbacks handle use, and removal or power transitions change its state. Design every step so that failures are recoverable and resources are not used after their lifetime ends.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  1. Match: provide identifiers appropriate to the bus and firmware description. Keep the binding specific enough to avoid attaching to unrelated hardware.
  2. Probe: validate device data, acquire resources, initialize locks and work items, configure the hardware, and register with the relevant subsystem. Return an error if setup fails.
  3. Operate: implement the subsystem or bus callbacks. Define how reads, writes, interrupts, buffered data, and background work interact.
  4. Remove or shut down: stop new activity, disable or synchronize interrupts and work, unregister interfaces, and release resources in a safe order. Follow the target kernel version’s callback signatures.
  5. Handle power transitions: quiesce and restore device state as required by runtime and system suspend/resume, including clocks, regulators, and wakeup behavior.

The kernel Device Drivers model documentation describes driver objects as statically allocated: initialize at least the name and bus fields, and initialize as many callbacks as the driver needs. Each callback is optional in the model. A minimal driver should therefore implement only meaningful callbacks, but it must provide the callbacks required by its bus, subsystem, and supported lifecycle.

What belongs in a platform driver probe function?

A platform driver probe function should turn a matched device into a usable subsystem device without assuming that every resource exists or every initialization step succeeds. A practical order is:

  1. Read and validate firmware properties or platform data, including required values and supported variants.
  2. Acquire managed or explicitly managed resources using the APIs documented for the target kernel and subsystem. For memory-mapped I/O, use the platform resource rather than a hard-coded physical address.
  3. Set up synchronization, state, and any deferred work before enabling a hardware source that can trigger callbacks.
  4. Initialize the peripheral, checking every operation that can fail and restoring a safe state if initialization is incomplete.
  5. Register the device with its subsystem only when the hardware and driver state are ready for callbacks.

Managed resource APIs can simplify cleanup when probe fails or the device is removed, but they do not make ordering irrelevant. In particular, stop asynchronous activity before the state it accesses is released. Check the current driver API and in-tree examples for the precise helper names, callback signatures, and subsystem registration sequence; kernel APIs evolve.

Make register access and concurrency safe

Read the hardware datasheet for register width, alignment, access semantics, reset values, byte order, and timing requirements. Use the kernel’s I/O accessors for mapped device registers rather than ordinary pointer dereferences. Do not assume that a register read is harmless: some registers clear status on read, require a specific sequence, or are valid only while a clock is enabled. Respect documented delays and timeouts, and return meaningful errors when the device does not reach the expected state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Choose the data path deliberately. A low-rate status signal may be polled; a device that signals events may use interrupts; sustained data may require a buffer, DMA, or queued processing. An interrupt handler runs in a constrained context: it must not sleep or perform operations that can block. Keep top-half work short and defer sleepable work to a threaded interrupt handler or workqueue when appropriate. Establish how interrupts are disabled, synchronized, and drained during failure and removal.

Shared state needs an explicit synchronization design. A mutex can protect operations that may sleep; a spinlock may be needed for short critical sections shared with interrupt context. Do not hold a spinlock across sleeping calls. Consider races among user requests, interrupt handlers, deferred work, suspend/resume, and removal—not just two simultaneous reads. For DMA, follow the DMA API’s mapping, ownership, and synchronization rules; CPU and device memory ordering are separate concerns from ordinary locking. Use the memory-barrier and accessor guidance applicable to the target architecture and API rather than assuming that source-code order alone guarantees device-visible order.

Choose and document the user-space interface

Prefer the ABI of the existing subsystem. It gives applications a consistent way to discover and operate the device and avoids a private interface that only one driver understands. Use sysfs for suitable small configuration or status attributes, not as a substitute for a streaming data path. A custom character device is appropriate only when no existing subsystem expresses the device’s behavior.

If a character device or ioctl is necessary, treat its interface as a long-lived contract. Specify data types and structure layout, blocking and nonblocking behavior, poll/select readiness, permissions, and error codes. Consider compatibility between 32-bit applications and 64-bit kernels where relevant, and define how users discover device instances. Avoid exposing raw register access as a general-purpose interface unless that is an intentional, secured product requirement; it couples applications to hardware details and can bypass driver invariants.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Integrate firmware and power management

Firmware description and driver behavior must agree. For Device Tree, the binding should document compatible values, required and optional properties, and the meaning of each resource. The driver should reject unsupported configurations instead of silently interpreting missing or malformed properties as guessed defaults. Keep board wiring in firmware description rather than scattering board-specific GPIO numbers, addresses, or timing assumptions through generic driver code.

Decide whether the device needs runtime power management, system suspend/resume support, or wakeup signaling. Runtime transitions may gate clocks or regulators while the device is idle; system sleep may require saving state, quiescing I/O, or enabling a wake IRQ. Coordinate those transitions with active operations and deferred work so that no callback touches hardware after it has been powered down. If firmware must be loaded, define when loading occurs, what happens on failure, and whether the device can safely remain unavailable until it succeeds. Use the current power-management and subsystem documentation for the APIs and ordering rules that apply to the target kernel.

Build, load, and debug in stages

An out-of-tree module can be useful for an early experiment, but it is not a substitute for integrating a production driver with the kernel tree and its configuration. Whether the driver is built in or loadable depends on boot requirements, configuration, and deployment policy; systems that enforce module signing must also account for signing and verification. Keep build integration reproducible for the exact kernel source and configuration used by the board.

  1. Enable the required bus, subsystem, and driver configuration options in the target kernel.
  2. Check that firmware description, compatible identifiers, resources, and pin or power configuration match the board design.
  3. Build against the target kernel tree and configuration; do not assume a module built for another kernel is compatible.
  4. Load the module if applicable, or boot the kernel with the driver built in. Inspect kernel logs for probe errors and confirm that the expected subsystem device appears.
  5. Use dynamic debug, tracing, and available fault-injection facilities to investigate specific paths. Remove temporary diagnostics that expose sensitive data or create excessive logging.
  6. Validate against the actual hardware, including error paths, repeated bind/unbind where supported, interrupt behavior, suspend/resume, and concurrent use.

A successful compile proves that the code builds against that tree; it does not establish correct electrical behavior or reliable operation on the board. Confirm behavior with the schematic, datasheet, and controlled hardware tests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Review for maintainability and upstream fit

Compare the implementation with current in-tree drivers for the same subsystem and bus. Follow kernel coding style, document the firmware binding, and avoid duplicating an existing framework or embedding assumptions that only fit one board. Make failure paths as carefully reviewable as the successful path, especially where probe partially enables hardware or asynchronous work has started.

The kernel development HOWTO frames driver development as work within the broader kernel project; Linux is written mostly in C, with some architecture-dependent parts in assembly. A driver intended for upstreaming should fit the relevant subsystem conventions, include appropriate documentation and tests, and identify a maintainer path. The kernel’s driver implementer API guide and API index organize the documentation by driver basics, the driver model, infrastructure, ioctl interfaces, CPU and device power management, buses, and support libraries. Consult the documentation corresponding to the kernel version being targeted rather than treating older examples as authoritative API references.

Linux Device Drivers, 3rd Edition by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman remains a foundational conceptual reference, but it was published in 2005 and should not be used as a current API manual. Kaiwan N Billimoria’s Linux Kernel Programming Part 2: Char Device Drivers and Kernel Synchronization has a 2021 edition and a 2024 second edition; check the edition available in your region. For actual implementation details, current kernel documentation and in-tree code take precedence.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.