Skip to content

Commit f1ff557

Browse files
jcroledakartben
authored andcommitted
samples: drivers: Add MFD-Charger sample
Adds sample application for an MFD charger driver, supporting fuel gauge, charger, and regulator subsystems in a single device. Signed-off-by: Jan Carlo Roleda <jancarlo.roleda@analog.com> Reviewed-by: Francis Roi Manabat <francisroi.manabat@analog.com>
1 parent 6a8bb68 commit f1ff557

6 files changed

Lines changed: 587 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(mfd_charger)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. zephyr:code-sample:: mfd_charger
2+
:name: Multi-Function Device (MFD) with Charger, Fuel Gauge, and Regulators
3+
:relevant-api: charger_interface fuel_gauge_interface regulator_interface mfd_interfaces
4+
5+
Demonstrate a multi-function device using charger, fuel gauge, and regulator subsystems.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates how to use a multi-function power management device (MFD)
11+
with Zephyr's driver subsystems. The sample is designed to work with any MFD that
12+
provides charger, fuel gauge, and regulator functionality through the standard
13+
Zephyr driver interfaces.
14+
15+
The sample shows how to:
16+
17+
* Initialize and configure an MFD (Multi-Function Device) driver
18+
* Monitor battery charging status and health using the :ref:`Charger API <charger_api>`
19+
* Read battery voltage, state of charge, and cycle count using the :ref:`Fuel Gauge API <fuel_gauge_api>`
20+
* Control and monitor voltage regulators using the :ref:`Regulator API <regulator_api>`
21+
* Handle interrupts, power-good signals, and reset signals from the device
22+
23+
The application continuously polls the charger and fuel gauge to display real-time
24+
battery and charging information, including:
25+
26+
* Charger configuration (current limits, charge currents, voltages)
27+
* Charging status (online, present, charging state, health)
28+
* Battery fuel gauge data (voltage, state of charge, cycle count)
29+
* Regulator output voltages
30+
31+
Requirements
32+
************
33+
34+
The sample requires a board with an MFD device that supports charger, fuel gauge,
35+
and regulator functionality. The MFD device must be defined in the devicetree with
36+
appropriate labels so that the sample code can access the individual subsystems.
37+
38+
The devicetree must include:
39+
40+
* A node with the label ``charger`` for the charger interface
41+
* A node with the label ``fuelgauge`` for the fuel gauge interface
42+
* A node with the label ``buck`` for the buck regulator (or similar)
43+
* A node with the label ``buckboost`` for the buck-boost regulator (or similar)
44+
45+
An example MFD device overlay is provided showing how to configure these labels
46+
for a specific board and MFD chip. Refer to the overlay file for your board to
47+
understand how to adapt it for other MFD devices.
48+
49+
Hardware Setup
50+
==============
51+
52+
The specific hardware connections depend on the MFD device being used. Refer to the
53+
device datasheet and the overlay file for your board for detailed connection
54+
instructions.
55+
56+
At minimum, the MFD requires:
57+
58+
* A communications bus
59+
* Power supply
60+
* A battery connected to the charger and fuel gauge subsystems for proper operation
61+
62+
Building and Running
63+
********************
64+
65+
The code can be found in :zephyr_file:`samples/drivers/mfd_charger`.
66+
67+
To build and flash the application for your board:
68+
69+
.. zephyr-app-commands::
70+
:zephyr-app: samples/drivers/mfd_charger
71+
:board: <board>
72+
:goals: build flash
73+
:compact:
74+
75+
Replace ``<board>`` with your target board name.
76+
77+
If your board does not have an MFD overlay, you will need to create one. Create a file
78+
in the ``boards/`` subdirectory named ``<board>.overlay`` with the appropriate devicetree
79+
configuration for your MFD device. See the board-specific documentation for examples.
80+
81+
Sample Output
82+
=============
83+
84+
The sample output will vary based on the specific MFD device and configuration.
85+
A typical output showing battery charging and monitoring information might look like:
86+
87+
.. code-block:: console
88+
89+
[0:00:00.003]: Found device "charger", getting charger data
90+
[0:00:00.006]: Current (Fast Charge): 20000 uA
91+
[0:00:00.009]: Input Regulation Voltage: 3800000 uV
92+
[0:00:00.012]: Current (Termination): 5000 uA
93+
[0:00:03.021]: Fuel gauge Battery Capacity: 1000
94+
[0:00:03.024]: Buck Output Voltage: 1300000
95+
[0:00:03.027]: Buck Boost Output Voltage: 3300000
96+
[0:00:03.030]: Online: Charger is active.
97+
[0:00:03.033]: Present: Battery is Present.
98+
[0:00:03.036]: Status: Charger is Charging.
99+
[0:00:03.039]: Mode: Charger is in Fast Mode (CC).
100+
[0:00:03.042]: Health: Battery is Cool.
101+
[0:00:03.045]: Fuel gauge Voltage: 3950000
102+
[0:00:03.048]: Fuel gauge Status 0x0
103+
[0:00:03.051]: Fuel gauge SoC: 75
104+
105+
.. note:: The values shown above will vary depending on the actual MFD device used,
106+
the battery state of charge, and the device configuration.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2026 Analog Devices Inc
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/regulator/adp5360.h>
8+
9+
dev: &i2c1 {
10+
status = "okay";
11+
12+
mfd: adp5360@46 {
13+
compatible = "adi,adp5360";
14+
reg = <0x46>;
15+
16+
charger: charger {
17+
compatible = "adi,adp5360-charger";
18+
19+
battery-name = "dummy-charger";
20+
device-chemistry = "lithium-ion";
21+
charge-term-current-microamp = <5000>;
22+
constant-charge-current-max-microamp = <20000>;
23+
constant-charge-voltage-max-microvolt = <4160000>;
24+
re-charge-voltage-microvolt = <120000>;
25+
precharge-current-microamp = <5000>;
26+
};
27+
28+
fuelgauge: fuel-gauge {
29+
compatible = "adi,adp5360-fuel-gauge";
30+
status = "okay";
31+
};
32+
33+
regulators {
34+
compatible = "adi,adp5360-regulator";
35+
36+
buck: buck {
37+
regulator-boot-on;
38+
regulator-active-discharge = <1>;
39+
regulator-allowed-modes = <ADP5360_MODE_HYS ADP5360_MODE_PWM>;
40+
adi,enable-stop-pulse;
41+
regulator-init-microvolt = <1300000>;
42+
regulator-initial-mode = <ADP5360_MODE_PWM>;
43+
regulator-max-microvolt = <3750000>;
44+
regulator-min-microvolt = <600000>;
45+
};
46+
47+
buckboost: buckboost {
48+
regulator-boot-on;
49+
regulator-active-discharge = <0>;
50+
regulator-init-microvolt = <3300000>;
51+
regulator-max-microvolt = <5500000>;
52+
regulator-min-microvolt = <1800000>;
53+
};
54+
};
55+
};
56+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_PM_DEVICE=y
2+
CONFIG_STDOUT_CONSOLE=y
3+
CONFIG_CBPRINTF_FP_SUPPORT=y
4+
CONFIG_CHARGER=y
5+
CONFIG_FUEL_GAUGE=y
6+
CONFIG_REGULATOR=y
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sample:
2+
name: Multi-Function Device (MFD) Sample
3+
description: Sample for generic MFD with Charger, Fuel Gauge, and Regulator support
4+
common:
5+
tags:
6+
- charger
7+
- fuel_gauge
8+
- regulator
9+
harness: console
10+
harness_config:
11+
type: multi_line
12+
regex:
13+
- "Current.*uA"
14+
- "Charger is.*"
15+
- "Fuel gauge.*Capacity"
16+
- "Fuel gauge SoC"
17+
- ".*Output Voltage.*"
18+
tests:
19+
sample.drivers.mfd_charger:
20+
filter: dt_nodelabel_enabled("charger") and dt_nodelabel_enabled("fuelgauge") and
21+
dt_nodelabel_enabled("buck") and dt_nodelabel_enabled("buckboost")
22+
platform_allow:
23+
- nucleo_u575zi_q

0 commit comments

Comments
 (0)