RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
regulator.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-09-23 GuEe-GUI first version
9 */
10
11#ifndef __REGULATOR_H__
12#define __REGULATOR_H__
13
14#include <ref.h>
15#include <rthw.h>
16#include <rtthread.h>
17
18#include <drivers/misc.h>
19
20#define RT_REGULATOR_UVOLT_INVALID (((int)(RT_UINT32_MAX >> 1)))
21
23{
24 const char *name;
25
26 int min_uvolt; /* In uV */
27 int max_uvolt; /* In uV */
28 int min_uamp; /* In uA */
29 int max_uamp; /* In uA */
30 int ramp_delay; /* In uV/usec */
31 int enable_delay; /* In usec */
32 int off_on_delay; /* In usec */
33
35 rt_uint32_t boot_on:1; /* Is enabled on boot */
36 rt_uint32_t always_on:1; /* Must be enabled */
37 rt_uint32_t soft_start:1; /* Ramp voltage slowly */
38 rt_uint32_t pull_down:1; /* Pull down resistor when regulator off */
39 rt_uint32_t over_current_protection:1; /* Auto disable on over current */
40};
41
42struct rt_regulator_ops;
43
64
65/*
66 * NOTE: Power regulator control is dangerous work. We don't want non-internal
67 * consumer could access the power regulator tree without regulator's API. So
68 * we defined the `rt_regulator` member in core instead of here.
69 */
70struct rt_regulator;
71
72#define RT_REGULATOR_MODE_INVALID 0
73#define RT_REGULATOR_MODE_FAST RT_BIT(0)
74#define RT_REGULATOR_MODE_NORMAL RT_BIT(1)
75#define RT_REGULATOR_MODE_IDLE RT_BIT(2)
76#define RT_REGULATOR_MODE_STANDBY RT_BIT(3)
77
79{
83 rt_err_t (*set_voltage)(struct rt_regulator_node *reg, int min_uvolt, int max_uvolt);
84 int (*get_voltage)(struct rt_regulator_node *reg);
87 rt_err_t (*set_ramp_delay)(struct rt_regulator_node *reg, int ramp);
89};
90
92
93#define RT_REGULATOR_MSG_ENABLE RT_BIT(0)
94#define RT_REGULATOR_MSG_DISABLE RT_BIT(1)
95#define RT_REGULATOR_MSG_VOLTAGE_CHANGE RT_BIT(2)
96#define RT_REGULATOR_MSG_VOLTAGE_CHANGE_ERR RT_BIT(3)
97
99{
100 struct
101 {
105 };
106};
107
109 rt_ubase_t msg, void *data);
110
119
122
124 struct rt_regulator_notifier *notifier);
126 struct rt_regulator_notifier *notifier);
127
128struct rt_regulator *rt_regulator_get(struct rt_device *dev, const char *id);
129void rt_regulator_put(struct rt_regulator *reg);
130
131rt_err_t rt_regulator_enable(struct rt_regulator *reg);
132rt_err_t rt_regulator_disable(struct rt_regulator *reg);
133rt_bool_t rt_regulator_is_enabled(struct rt_regulator *reg);
134
135rt_bool_t rt_regulator_is_supported_voltage(struct rt_regulator *reg, int min_uvolt, int max_uvolt);
136rt_err_t rt_regulator_set_voltage(struct rt_regulator *reg, int min_uvolt, int max_uvolt);
137int rt_regulator_get_voltage(struct rt_regulator *reg);
138
139rt_err_t rt_regulator_set_mode(struct rt_regulator *reg, rt_uint32_t mode);
140rt_int32_t rt_regulator_get_mode(struct rt_regulator *reg);
141
142rt_inline rt_err_t rt_regulator_set_voltage_triplet(struct rt_regulator *reg,
143 int min_uvolt, int target_uvolt, int max_uvolt)
144{
145 if (!rt_regulator_set_voltage(reg, target_uvolt, max_uvolt))
146 {
147 return RT_EOK;
148 }
149
150 return rt_regulator_set_voltage(reg, min_uvolt, max_uvolt);
151}
152
153#endif /* __REGULATOR_H__ */
struct rt_regulator * rt_regulator_get(struct rt_device *dev, const char *id)
rt_bool_t rt_regulator_is_supported_voltage(struct rt_regulator *reg, int min_uvolt, int max_uvolt)
int rt_regulator_get_voltage(struct rt_regulator *reg)
rt_err_t(* rt_regulator_notifier_callback)(struct rt_regulator_notifier *notifier, rt_ubase_t msg, void *data)
rt_err_t rt_regulator_unregister(struct rt_regulator_node *reg_np)
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)
void rt_regulator_put(struct rt_regulator *reg)
rt_err_t rt_regulator_notifier_register(struct rt_regulator *reg, struct rt_regulator_notifier *notifier)
rt_err_t rt_regulator_enable(struct rt_regulator *reg)
rt_err_t rt_regulator_register(struct rt_regulator_node *reg_np)
rt_inline rt_err_t rt_regulator_set_voltage_triplet(struct rt_regulator *reg, int min_uvolt, int target_uvolt, int max_uvolt)
rt_err_t rt_regulator_disable(struct rt_regulator *reg)
rt_err_t rt_regulator_notifier_unregister(struct rt_regulator *reg, struct rt_regulator_notifier *notifier)
rt_err_t rt_regulator_set_voltage(struct rt_regulator *reg, int min_uvolt, int max_uvolt)
rt_bool_t rt_regulator_is_enabled(struct rt_regulator *reg)
int rt_bool_t
rt_base_t rt_err_t
rt_base_t rt_atomic_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
rt_uint32_t rt_ubase_t
signed int rt_int32_t
const char * supply_name
rt_atomic_t enabled_count
const struct rt_regulator_param * param
const struct rt_regulator_ops * ops
struct rt_regulator_node * parent
struct rt_device * dev
struct rt_ref ref
rt_regulator_notifier_callback callback
struct rt_regulator * regulator
rt_uint32_t(* enable_time)(struct rt_regulator_node *reg)
rt_int32_t(* get_mode)(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_mode)(struct rt_regulator_node *reg, rt_uint32_t mode)
rt_err_t(* set_ramp_delay)(struct rt_regulator_node *reg, int ramp)
rt_err_t(* disable)(struct rt_regulator_node *reg)
rt_bool_t(* is_enabled)(struct rt_regulator_node *reg)
rt_err_t(* enable)(struct rt_regulator_node *reg)
rt_uint32_t enable_active_high
rt_uint32_t over_current_protection