mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 18:57:16 +08:00
[drivers][power] add CLI helpers and current control support#11301
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
- add msh commands to inspect/operate power supplies and regulators - expose snapshot/name helpers so shells and daemons can enumerate nodes safely - add current support for regulator - relax DM-only constraints in power/regulator stacks so basic builds work without DM/OFW - solve the problem of enabling counting for regulator
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-11-21 GuEe-GUI first version
|
||||
* 2026-03-27 Evlers add snapshot helpers and public name getter
|
||||
*/
|
||||
|
||||
#ifndef __POWER_SUPPLY_H__
|
||||
@@ -274,4 +275,8 @@ void rt_power_supply_changed(struct rt_power_supply *psy);
|
||||
struct rt_power_supply *rt_power_supply_get(struct rt_device *dev, const char *id);
|
||||
void rt_power_supply_put(struct rt_power_supply *psy);
|
||||
|
||||
const char *rt_power_supply_name(struct rt_power_supply *psy);
|
||||
struct rt_power_supply **rt_power_supply_snapshot(rt_size_t *count);
|
||||
void rt_power_supply_snapshot_free(struct rt_power_supply **nodes, rt_size_t count);
|
||||
|
||||
#endif /* __POWER_SUPPLY_H__ */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-09-23 GuEe-GUI first version
|
||||
* 2026-03-27 Evlers add current control API and snapshot helpers
|
||||
*/
|
||||
|
||||
#ifndef __REGULATOR_H__
|
||||
@@ -18,6 +19,7 @@
|
||||
#include <drivers/misc.h>
|
||||
|
||||
#define RT_REGULATOR_UVOLT_INVALID (((int)(RT_UINT32_MAX >> 1)))
|
||||
#define RT_REGULATOR_UAMP_INVALID (((int)(RT_UINT32_MAX >> 1)))
|
||||
|
||||
struct rt_regulator_param
|
||||
{
|
||||
@@ -86,6 +88,8 @@ struct rt_regulator_ops
|
||||
rt_bool_t (*is_enabled)(struct rt_regulator_node *reg);
|
||||
rt_err_t (*set_voltage)(struct rt_regulator_node *reg, int min_uvolt, int max_uvolt);
|
||||
int (*get_voltage)(struct rt_regulator_node *reg);
|
||||
rt_err_t (*set_current)(struct rt_regulator_node *reg, int min_uamp, int max_uamp);
|
||||
int (*get_current)(struct rt_regulator_node *reg);
|
||||
rt_err_t (*set_mode)(struct rt_regulator_node *reg, rt_uint32_t mode);
|
||||
rt_int32_t (*get_mode)(struct rt_regulator_node *reg);
|
||||
rt_err_t (*set_ramp_delay)(struct rt_regulator_node *reg, int ramp);
|
||||
@@ -98,6 +102,8 @@ struct rt_regulator_notifier;
|
||||
#define RT_REGULATOR_MSG_DISABLE RT_BIT(1)
|
||||
#define RT_REGULATOR_MSG_VOLTAGE_CHANGE RT_BIT(2)
|
||||
#define RT_REGULATOR_MSG_VOLTAGE_CHANGE_ERR RT_BIT(3)
|
||||
#define RT_REGULATOR_MSG_CURRENT_CHANGE RT_BIT(4)
|
||||
#define RT_REGULATOR_MSG_CURRENT_CHANGE_ERR RT_BIT(5)
|
||||
|
||||
union rt_regulator_notifier_args
|
||||
{
|
||||
@@ -107,6 +113,12 @@ union rt_regulator_notifier_args
|
||||
int min_uvolt;
|
||||
int max_uvolt;
|
||||
};
|
||||
struct
|
||||
{
|
||||
int old_uamp;
|
||||
int min_uamp;
|
||||
int max_uamp;
|
||||
};
|
||||
};
|
||||
|
||||
typedef rt_err_t (*rt_regulator_notifier_callback)(struct rt_regulator_notifier *notifier,
|
||||
@@ -140,9 +152,16 @@ rt_bool_t rt_regulator_is_supported_voltage(struct rt_regulator *reg, int min_uv
|
||||
rt_err_t rt_regulator_set_voltage(struct rt_regulator *reg, int min_uvolt, int max_uvolt);
|
||||
int rt_regulator_get_voltage(struct rt_regulator *reg);
|
||||
|
||||
rt_bool_t rt_regulator_is_supported_current(struct rt_regulator *reg, int min_uamp, int max_uamp);
|
||||
rt_err_t rt_regulator_set_current(struct rt_regulator *reg, int min_uamp, int max_uamp);
|
||||
int rt_regulator_get_current(struct rt_regulator *reg);
|
||||
|
||||
rt_err_t rt_regulator_set_mode(struct rt_regulator *reg, rt_uint32_t mode);
|
||||
rt_int32_t rt_regulator_get_mode(struct rt_regulator *reg);
|
||||
|
||||
struct rt_regulator_node **rt_regulator_nodes_snapshot(rt_size_t *count);
|
||||
void rt_regulator_nodes_snapshot_free(struct rt_regulator_node **nodes, rt_size_t count);
|
||||
|
||||
rt_inline rt_err_t rt_regulator_set_voltage_triplet(struct rt_regulator *reg,
|
||||
int min_uvolt, int target_uvolt, int max_uvolt)
|
||||
{
|
||||
@@ -154,4 +173,15 @@ rt_inline rt_err_t rt_regulator_set_voltage_triplet(struct rt_regulator *reg,
|
||||
return rt_regulator_set_voltage(reg, min_uvolt, max_uvolt);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_regulator_set_current_triplet(struct rt_regulator *reg,
|
||||
int min_uamp, int target_uamp, int max_uamp)
|
||||
{
|
||||
if (!rt_regulator_set_current(reg, target_uamp, max_uamp))
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
return rt_regulator_set_current(reg, min_uamp, max_uamp);
|
||||
}
|
||||
|
||||
#endif /* __REGULATOR_H__ */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2012-01-08 bernard first version.
|
||||
* 2014-07-12 bernard Add workqueue implementation.
|
||||
* 2026-03-27 Evlers reorder regulator/power supply headers after DM deps
|
||||
*/
|
||||
|
||||
#ifndef __RT_DEVICE_H__
|
||||
@@ -118,10 +119,6 @@ extern "C" {
|
||||
#endif /* RT_PCI_ENDPOINT */
|
||||
#endif /* RT_USING_PCI */
|
||||
|
||||
#ifdef RT_USING_REGULATOR
|
||||
#include "drivers/regulator.h"
|
||||
#endif /* RT_USING_REGULATOR */
|
||||
|
||||
#ifdef RT_USING_RESET
|
||||
#include "drivers/reset.h"
|
||||
#endif /* RT_USING_RESET */
|
||||
@@ -148,15 +145,19 @@ extern "C" {
|
||||
#include "drivers/hwcache.h"
|
||||
#endif /* RT_USING_HWCACHE */
|
||||
|
||||
#ifdef RT_USING_POWER_SUPPLY
|
||||
#include "drivers/power_supply.h"
|
||||
#endif /* RT_USING_POWER_SUPPLY */
|
||||
|
||||
#ifdef RT_USING_NVMEM
|
||||
#include "drivers/nvmem.h"
|
||||
#endif /* RT_USING_NVMEM */
|
||||
#endif /* RT_USING_DM */
|
||||
|
||||
#ifdef RT_USING_REGULATOR
|
||||
#include "drivers/regulator.h"
|
||||
#endif /* RT_USING_REGULATOR */
|
||||
|
||||
#ifdef RT_USING_POWER_SUPPLY
|
||||
#include "drivers/power_supply.h"
|
||||
#endif /* RT_USING_POWER_SUPPLY */
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
#include "drivers/dev_rtc.h"
|
||||
#ifdef RT_USING_ALARM
|
||||
|
||||
Reference in New Issue
Block a user