Day73 - Platform Driver Development¶
Objective¶
Understand how a platform driver:
- Acquires hardware resources
- Stores private driver state
- Obtains IRQ resources
- Registers interrupt handlers
- Uses devm-managed resources
- Implements delayed work debounce
Background¶
Previous sessions covered:
- Linux Driver Model
- Platform Bus Internals
- Device Tree → platform_device creation
- platform_driver matching and probe flow
This lab focuses on the next stage:
Lab 1 - Platform Resource Acquisition¶
Device Tree Overlay¶
demo@10000000 {
compatible = "demo,platform-lab";
reg = <0x0 0x10000000 0x1000>;
interrupt-parent = <&rp1_gpio>;
interrupts = <23 2>;
status = "okay";
};
Probe Flow¶
priv = devm_kzalloc(...);
res = platform_get_resource(
pdev,
IORESOURCE_MEM,
0);
irq = platform_get_irq(
pdev,
0);
platform_set_drvdata(
pdev,
priv);
Validation¶
Expected output:
Observed:
Key Observation¶
The Linux IRQ number is not necessarily identical to the Device Tree interrupt specifier.
Interrupt mapping is performed through the irqdomain framework.
Lab 2 - Driver Private Data¶
Private Data Structure¶
Store Driver Data¶
Retrieve Driver Data¶
Validation¶
Probe:
Remove:
Result¶
Verified driver state persistence across:
Lab 3 - IRQ Registration¶
Interrupt Handler¶
Register IRQ¶
Result¶
GPIO23 successfully generated interrupts.
Observed:
Key Observation¶
The private data pointer passed to:
is received by:
through the handler context argument.
Lab 4 - Delayed Work Debounce¶
Motivation¶
Mechanical switches generate multiple interrupts due to contact bouncing.
Observed behavior:
Delayed Work Initialization¶
Debounce Logic¶
Debounce Flow¶
Repeated interrupts refresh the timeout instead of scheduling multiple workers.
Result¶
Multiple bounce interrupts were merged into a single delayed work execution.
Platform Driver Initialization Flow¶
Final initialization sequence:
probe()
↓
devm_kzalloc()
↓
platform_get_resource()
↓
platform_get_irq()
↓
platform_set_drvdata()
↓
devm_request_irq()
↓
INIT_DELAYED_WORK()
↓
Ready
Conclusion¶
This lab verified the complete platform driver initialization path:
Device Tree
↓
platform_device
↓
resource acquisition
↓
private driver state
↓
IRQ registration
↓
delayed work handling
The driver now demonstrates the typical structure used by many real-world platform drivers.