Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/drivers/include/drivers/regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ struct rt_regulator_param
int ramp_delay; /* In uV/usec */
int enable_delay; /* In usec */
int off_on_delay; /* In usec */
int settling_time;
int settling_time_up;
int settling_time_down;

rt_uint32_t enable_active_high:1;
rt_uint32_t boot_on:1; /* Is enabled on boot */
rt_uint32_t always_on:1; /* Must be enabled */
rt_uint32_t soft_start:1; /* Ramp voltage slowly */
rt_uint32_t pull_down:1; /* Pull down resistor when regulator off */
rt_uint32_t over_current_protection:1; /* Auto disable on over current */
rt_uint32_t ramp_disable:1; /* Disable ramp delay */
};

struct rt_regulator_ops;
Expand Down
65 changes: 60 additions & 5 deletions components/drivers/regulator/regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static rt_err_t regulator_disable(struct rt_regulator_node *reg_np);

rt_err_t rt_regulator_register(struct rt_regulator_node *reg_np)
{
rt_err_t err;
const struct rt_regulator_param *param;

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

reg_np->parent = RT_NULL;

if ((param->ramp_delay || param->ramp_disable) &&
reg_np->ops->set_ramp_delay)
{
if ((err = reg_np->ops->set_ramp_delay(reg_np, param->ramp_delay)))
{
LOG_E("Set ramp error = %s\n", rt_strerror(err));
return err;
}
}

#ifdef RT_USING_OFW
if (reg_np->dev->ofw_node)
{
Expand Down Expand Up @@ -184,6 +195,40 @@ static rt_uint32_t regulator_get_enable_time(struct rt_regulator_node *reg_np)
return 0;
}

static rt_uint32_t regulator_set_voltage_time(struct rt_regulator_node *reg_np,
int old_uvolt, int new_uvolt)
{
unsigned int ramp_delay = 0;

if (reg_np->param->ramp_delay)
{
ramp_delay = reg_np->param->ramp_delay;
}
else if (reg_np->param->ramp_delay)
{
ramp_delay = reg_np->param->ramp_delay;
}
else if (reg_np->param->settling_time)
{
return reg_np->param->settling_time;
}
else if (reg_np->param->settling_time_up && new_uvolt > old_uvolt)
{
return reg_np->param->settling_time_up;
}
else if (reg_np->param->settling_time_down && new_uvolt < old_uvolt)
{
return reg_np->param->settling_time_down;
}

if (ramp_delay == 0)
{
return 0;
}

return RT_DIV_ROUND_UP(rt_abs(new_uvolt - old_uvolt), ramp_delay);
}

static void regulator_delay(rt_uint32_t delay)
{
rt_uint32_t ms = delay / 1000;
Expand Down Expand Up @@ -227,14 +272,15 @@ static void regulator_delay(rt_uint32_t delay)
static rt_err_t regulator_enable(struct rt_regulator_node *reg_np)
{
rt_err_t err = RT_EOK;
rt_uint32_t enable_delay = regulator_get_enable_time(reg_np);

if (reg_np->ops->enable)
{
err = reg_np->ops->enable(reg_np);

if (!err)
{
rt_uint32_t enable_delay = regulator_get_enable_time(reg_np);

if (enable_delay)
{
regulator_delay(enable_delay);
Expand Down Expand Up @@ -369,7 +415,17 @@ static rt_err_t regulator_set_voltage(struct rt_regulator_node *reg_np, int min_
err = reg_np->ops->set_voltage(reg_np, min_uvolt, max_uvolt);
}

if (err)
if (!err)
{
rt_uint32_t delay = regulator_set_voltage_time(reg_np,
args.old_uvolt, reg_np->ops->get_voltage(reg_np));

if (delay)
{
regulator_delay(delay);
}
}
else
{
regulator_notifier_call_chain(reg_np, RT_REGULATOR_MSG_VOLTAGE_CHANGE_ERR,
(void *)(rt_base_t)args.old_uvolt);
Expand Down Expand Up @@ -538,7 +594,7 @@ static void regulator_check_parent(struct rt_regulator_node *reg_np)
rt_list_insert_after(&reg_np->parent->children_nodes, &reg_np->list);
rt_ofw_node_put(np);
}
#endif
#endif /* RT_USING_OFW */
}
}

Expand Down Expand Up @@ -581,11 +637,10 @@ struct rt_regulator *rt_regulator_get(struct rt_device *dev, const char *id)
reg_np = rt_ofw_data(np);
rt_ofw_node_put(np);
}
#endif
#endif /* RT_USING_OFW */

if (!reg_np)
{
reg = rt_err_ptr(-RT_ENOSYS);
goto _end;
}

Expand Down
19 changes: 19 additions & 0 deletions components/drivers/regulator/regulator_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,31 @@ rt_err_t regulator_ofw_parse(struct rt_ofw_node *np, struct rt_regulator_param *
{
param->ramp_delay = pval;
}
else
{
param->ramp_disable = RT_TRUE;
}

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

if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-us", &pval))
{
param->settling_time = pval;
}

if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-up-us", &pval))
{
param->settling_time_up = pval;
}

if (!rt_ofw_prop_read_u32(np, "regulator-settling-time-down-us", &pval))
{
param->settling_time_down = pval;
}

param->enable_active_high = rt_ofw_prop_read_bool(np, "enable-active-high");
param->boot_on = rt_ofw_prop_read_bool(np, "regulator-boot-on");
param->always_on = rt_ofw_prop_read_bool(np, "regulator-always-on");
Expand Down
9 changes: 5 additions & 4 deletions components/drivers/spi/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ if GetDepend('RT_USING_SFUD'):
if GetDepend('RT_SFUD_USING_SFDP'):
src_device += ['sfud/src/sfud_sfdp.c']

if rtconfig.PLATFORM in GetGCCLikePLATFORM():
LOCAL_CFLAGS += ' -std=c99'
elif rtconfig.PLATFORM in ['armcc']:
LOCAL_CFLAGS += ' --c99'
if not GetDepend('RT_USING_DM'):
if rtconfig.PLATFORM in GetGCCLikePLATFORM():
LOCAL_CFLAGS += ' -std=c99'
elif rtconfig.PLATFORM in ['armcc']:
LOCAL_CFLAGS += ' --c99'

if GetDepend('RT_USING_DM'):
src += ['dev_spi_dm.c', 'dev_spi_bus.c']
Expand Down
1 change: 1 addition & 0 deletions components/drivers/spi/sfud/inc/sfud_flash_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ typedef struct {
{"F25L004", SFUD_MF_ID_ESMT, 0x20, 0x13, 512L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \
{"PCT25VF016B", SFUD_MF_ID_SST, 0x25, 0x41, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \
{"NM25Q128EVB", SFUD_MF_ID_NOR_MEM, 0x21, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
{"W25Q128JWPIM", SFUD_MF_ID_MACRONIX, 0x25, 0x38, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
}
#endif /* SFUD_USING_FLASH_INFO_TABLE */

Expand Down