Skip to content

Commit 33d9c50

Browse files
GuEe-GUIRbb666
authored andcommitted
[DM][REGULATOR] Support operator delay
Signed-off-by: GuEe-GUI <2991707448@qq.com>
1 parent 7ebc10a commit 33d9c50

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

components/drivers/include/drivers/regulator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ struct rt_regulator_param
3030
int ramp_delay; /* In uV/usec */
3131
int enable_delay; /* In usec */
3232
int off_on_delay; /* In usec */
33+
int settling_time;
34+
int settling_time_up;
35+
int settling_time_down;
3336

3437
rt_uint32_t enable_active_high:1;
3538
rt_uint32_t boot_on:1; /* Is enabled on boot */
3639
rt_uint32_t always_on:1; /* Must be enabled */
3740
rt_uint32_t soft_start:1; /* Ramp voltage slowly */
3841
rt_uint32_t pull_down:1; /* Pull down resistor when regulator off */
3942
rt_uint32_t over_current_protection:1; /* Auto disable on over current */
43+
rt_uint32_t ramp_disable:1; /* Disable ramp delay */
4044
};
4145

4246
struct rt_regulator_ops;

components/drivers/regulator/regulator.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static rt_err_t regulator_disable(struct rt_regulator_node *reg_np);
3131

3232
rt_err_t rt_regulator_register(struct rt_regulator_node *reg_np)
3333
{
34+
rt_err_t err;
3435
const struct rt_regulator_param *param;
3536

3637
if (!reg_np || !reg_np->dev || !reg_np->param || !reg_np->ops)
@@ -48,6 +49,16 @@ rt_err_t rt_regulator_register(struct rt_regulator_node *reg_np)
4849

4950
reg_np->parent = RT_NULL;
5051

52+
if ((param->ramp_delay || param->ramp_disable) &&
53+
reg_np->ops->set_ramp_delay)
54+
{
55+
if ((err = reg_np->ops->set_ramp_delay(reg_np, param->ramp_delay)))
56+
{
57+
LOG_E("Set ramp error = %s\n", rt_strerror(err));
58+
return err;
59+
}
60+
}
61+
5162
#ifdef RT_USING_OFW
5263
if (reg_np->dev->ofw_node)
5364
{
@@ -184,6 +195,40 @@ static rt_uint32_t regulator_get_enable_time(struct rt_regulator_node *reg_np)
184195
return 0;
185196
}
186197

198+
static rt_uint32_t regulator_set_voltage_time(struct rt_regulator_node *reg_np,
199+
int old_uvolt, int new_uvolt)
200+
{
201+
unsigned int ramp_delay = 0;
202+
203+
if (reg_np->param->ramp_delay)
204+
{
205+
ramp_delay = reg_np->param->ramp_delay;
206+
}
207+
else if (reg_np->param->ramp_delay)
208+
{
209+
ramp_delay = reg_np->param->ramp_delay;
210+
}
211+
else if (reg_np->param->settling_time)
212+
{
213+
return reg_np->param->settling_time;
214+
}
215+
else if (reg_np->param->settling_time_up && new_uvolt > old_uvolt)
216+
{
217+
return reg_np->param->settling_time_up;
218+
}
219+
else if (reg_np->param->settling_time_down && new_uvolt < old_uvolt)
220+
{
221+
return reg_np->param->settling_time_down;
222+
}
223+
224+
if (ramp_delay == 0)
225+
{
226+
return 0;
227+
}
228+
229+
return RT_DIV_ROUND_UP(rt_abs(new_uvolt - old_uvolt), ramp_delay);
230+
}
231+
187232
static void regulator_delay(rt_uint32_t delay)
188233
{
189234
rt_uint32_t ms = delay / 1000;
@@ -227,14 +272,15 @@ static void regulator_delay(rt_uint32_t delay)
227272
static rt_err_t regulator_enable(struct rt_regulator_node *reg_np)
228273
{
229274
rt_err_t err = RT_EOK;
230-
rt_uint32_t enable_delay = regulator_get_enable_time(reg_np);
231275

232276
if (reg_np->ops->enable)
233277
{
234278
err = reg_np->ops->enable(reg_np);
235279

236280
if (!err)
237281
{
282+
rt_uint32_t enable_delay = regulator_get_enable_time(reg_np);
283+
238284
if (enable_delay)
239285
{
240286
regulator_delay(enable_delay);
@@ -369,7 +415,17 @@ static rt_err_t regulator_set_voltage(struct rt_regulator_node *reg_np, int min_
369415
err = reg_np->ops->set_voltage(reg_np, min_uvolt, max_uvolt);
370416
}
371417

372-
if (err)
418+
if (!err)
419+
{
420+
rt_uint32_t delay = regulator_set_voltage_time(reg_np,
421+
args.old_uvolt, reg_np->ops->get_voltage(reg_np));
422+
423+
if (delay)
424+
{
425+
regulator_delay(delay);
426+
}
427+
}
428+
else
373429
{
374430
regulator_notifier_call_chain(reg_np, RT_REGULATOR_MSG_VOLTAGE_CHANGE_ERR,
375431
(void *)(rt_base_t)args.old_uvolt);

components/drivers/regulator/regulator_dm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,31 @@ rt_err_t regulator_ofw_parse(struct rt_ofw_node *np, struct rt_regulator_param *
4141
{
4242
param->ramp_delay = pval;
4343
}
44+
else
45+
{
46+
param->ramp_disable = RT_TRUE;
47+
}
4448

4549
if (!rt_ofw_prop_read_u32(np, "regulator-enable-ramp-delay", &pval))
4650
{
4751
param->enable_delay = pval;
4852
}
4953

54+
if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-us", &pval))
55+
{
56+
param->settling_time = pval;
57+
}
58+
59+
if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-up-us", &pval))
60+
{
61+
param->settling_time_up = pval;
62+
}
63+
64+
if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-down-us", &pval))
65+
{
66+
param->settling_time_down = pval;
67+
}
68+
5069
param->enable_active_high = rt_ofw_prop_read_bool(np, "enable-active-high");
5170
param->boot_on = rt_ofw_prop_read_bool(np, "regulator-boot-on");
5271
param->always_on = rt_ofw_prop_read_bool(np, "regulator-always-on");

0 commit comments

Comments
 (0)