blob: 96a75f575b58b2fcc92fb9d635788d4ffd9e1b3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
@page page_device_power_charger Charger (gpio-charger)
# Charger as `rt_power_supply`
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: @ref page_device_power_supply.
**Kconfig**: **`RT_POWER_SUPPLY_CHARGER_GPIO`** → **`components/drivers/power/supply/gpio-charger.c`**.
---
## Registration flow (`gpio-charger`)
```
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)
```dts
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`**.
---
## `get_property` / `set_property`
| 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
- @ref page_device_power_supply
- @ref page_device_regulator
- @ref page_device_pin
- `components/drivers/power/supply/gpio-charger.c`
|