@@ -31,6 +31,7 @@ static rt_err_t regulator_disable(struct rt_regulator_node *reg_np);
3131
3232rt_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+
187232static 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)
227272static 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 );
0 commit comments