RT-Thread RTOS
An open source embedded real-time operating system
Charger (gpio-charger)

Charger as <tt>rt_power_supply</tt>

Chargers are not a separate class. A charger is a **struct rt_power_supply** with USB/mains **type** and properties such as **ONLINE**, **STATUS**, **CONSTANT_CHARGE_CURRENT_MAX**.

Core registration flow: Power supply.

Kconfig: **RT_POWER_SUPPLY_CHARGER_GPIO** → **components/drivers/power/supply/gpio-charger.c**.


Registration flow (<tt>gpio-charger</tt>)

RT_PLATFORM_DRIVER_EXPORT(gpio_charger_driver)
|
v
gpio_charger_probe(pdev)
|
+-- rt_pin_get_named_pin (VBUS / status GPIOs)
+-- optional charge-current-limit GPIOs + mapping table
+-- parse charger-type → psy->type
+-- build gpio_charger_properties[] (only supported props)
+-- psy->dev = &pdev->parent; psy->ops = &gpio_charger_ops
+-- rt_power_supply_register(&gpioc->parent)
+-- GPIO IRQ → gpio_charger_isr → rt_power_supply_changed()

Device tree (typical)

charger {
compatible = "gpio-charger";
charger-type = "usb-dcp";
gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; /* online */
charge-status-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
charge-current-limit-gpios = <&gpio0 14>, <&gpio0 15>;
charge-current-limit-mapping = <100000 0>, <500000 1>, <1500000 3>;
};

Properties actually exposed depend on which GPIOs/mapping are present — the driver builds **properties[]** dynamically in **probe**.


<tt>get_property</tt> / <tt>set_property</tt>

Property Behavior
**ONLINE** Read VBUS GPIO
**STATUS** Charging vs not from **charge-status** GPIO
**CONSTANT_CHARGE_CURRENT_MAX** Mapping table + limit GPIOs; **set_property** selects limit

Emulator

**emu-power.c** (**RT_POWER_SUPPLY_EMU**): registers test battery + charger; MSH **emu_charger** toggles state for thermal/PM tests.


See also