Day77 - GPIO Consumer Driver and gpiod APIs¶
Objective¶
Learn how Linux GPIO consumer drivers acquire GPIO resources from Device Tree and access GPIO lines through the gpiod API.
Topics covered:
- GPIO consumer driver architecture
- Device Tree GPIO lookup
devm_gpiod_get()devm_gpiod_get_optional()gpiod_direction_input()gpiod_direction_output()gpiod_get_value()gpiod_set_value()- GPIO consumer driver probe/remove flow
Lab1 - Raspberry Pi GPIO Consumer Investigation¶
Goal¶
Investigate how real Linux drivers consume GPIO resources from Device Tree.
Discover GPIO Properties¶
Search Device Tree GPIO properties:
Example:
Inspect GPIO Specifiers¶
Example:
Result:
Meaning:
Verify GPIO Flags¶
Examples:
| Property | Flags |
|---|---|
| shutdown-gpios | 0 |
| phy-reset-gpios | 1 |
| led-act gpios | 1 |
Verified:
Inspect GPIO Consumer Ownership¶
Check:
Examples:
Verified:
Lab2 - GPIO Consumer API Simulation¶
Goal¶
Simulate Linux GPIO consumer APIs.
Added Device Tree Lookup Layer¶
Implemented:
demo_gpio_dt_register_chip()
demo_gpio_dt_unregister_chip()
demo_gpio_dt_find_chip()
demo_of_get_gpio()
Lookup flow:
Added Consumer API Layer¶
Implemented:
devm_gpiod_get()
devm_gpiod_get_optional()
gpiod_direction_input()
gpiod_direction_output()
gpiod_get_value()
gpiod_set_value()
Architecture:
Test Result¶
Initial:
Reset GPIO:
Enable GPIO:
Verified:
Optional GPIO Test¶
Output:
Verified:
Lab3 - GPIO Consumer Driver Simulation¶
Goal¶
Simulate a Linux GPIO consumer driver.
Driver Private Data¶
Probe Flow¶
Implemented:
Flow:
Remove Flow¶
Implemented:
Flow:
Test Result¶
Initial:
Probe:
Meaning:
Remove:
Meaning:
Key Takeaways¶
Linux GPIO consumer drivers operate on GPIO descriptors rather than GPIO controller hardware.
The complete access path is:
This is the standard GPIO usage model used by Linux platform drivers.