New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: regulator: add LDO/DCDC support for Smartbond. #65226
drivers: regulator: add LDO/DCDC support for Smartbond. #65226
Conversation
09d3ae0
to
23c607b
Compare
@gmarull separate PR as requested |
drivers/regulator/Kconfig.da1469x
Outdated
|
||
config REGULATOR_DA1469X_INIT_PRIORITY | ||
int "Renesas DA1469x regulators driver init priority" | ||
default KERNEL_INIT_PRIORITY_OBJECTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a device, please use a number or KERNEL_INIT_PRIORITY_DEVICE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
static const uint32_t voltages_vdd[] = { | ||
900000, 1000000, 1100000, 1200000 | ||
}; | ||
|
||
static const uint32_t voltages_vdd_sleep[] = { | ||
750000, 800000, 850000, 900000, | ||
}; | ||
|
||
static const uint32_t voltages_v14[] = { | ||
1200000, 1250000, 1300000, 1350000, | ||
1400000, 1450000, 1500000, 1550000 | ||
}; | ||
|
||
static const uint32_t voltages_v30[] = { | ||
3000000, 3300000 | ||
}; | ||
|
||
static const uint32_t voltages_v18[] = { | ||
1200000, 1800000 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are all linear, so linear range can be used for these. See an example where some are linear and some are not: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/regulator/regulator_npm6001.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V30 was non-liner till 3.45 was remove per @ioannis-karachalios request.
Voltages are selected by indices in registers since at lease one is non-linear all are treated the same with district values kept in code.
If Renesas decides yet again that V30 (or other rail) can have other values code will not require extensive change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linear range API can support non-contiguous ranges, e.g:
zephyr/drivers/sensor/npm1300_charger/npm1300_charger.c
Lines 131 to 132 in 063ce9c
static const struct linear_range charger_volt_ranges[] = { | |
LINEAR_RANGE_INIT(3500000, 50000, 0U, 3U), LINEAR_RANGE_INIT(4000000, 50000, 4U, 13U)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to linear ranges
default: | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-ENOTSUP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
const struct regulator_da1469x_config *config = dev->config; | ||
|
||
switch (config->rail) { | ||
case VDD: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__fallthrough;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is required in Zephyr for series of cases with no code. __fallthrough
would be needed if case with some statements was continued in next case without break
.
default: | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-ENOTSUP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
case VDD: | ||
DCDC_REG_SET(VDD, CUR_LIM_MAX_HV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(VDD, CUR_LIM_MAX_LV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(VDD, CUR_LIM_MIN, ((max_ua / 30000) - 1)); | ||
break; | ||
case V14: | ||
DCDC_REG_SET(V14, CUR_LIM_MAX_HV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V14, CUR_LIM_MAX_LV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V14, CUR_LIM_MIN, ((max_ua / 30000) - 1)); | ||
break; | ||
case V18: | ||
DCDC_REG_SET(V18, CUR_LIM_MAX_HV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V18, CUR_LIM_MAX_LV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V18, CUR_LIM_MIN, ((max_ua / 30000) - 1)); | ||
break; | ||
case V18P: | ||
DCDC_REG_SET(V18P, CUR_LIM_MAX_HV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V18P, CUR_LIM_MAX_LV, ((max_ua / 30000) - 1)); | ||
DCDC_REG_SET(V18P, CUR_LIM_MIN, ((max_ua / 30000) - 1)); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic numbers here, remember current is given in a range as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to linear ranges
DCDC_REG_SET(V18P, CUR_LIM_MIN, ((max_ua / 30000) - 1)); | ||
break; | ||
default: | ||
ret = -ENOSYS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect usage of ENOSYS, should be ENOTSUP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
regulator_common_data_init(dev); | ||
|
||
if (config->rail == V30) { | ||
POWER_REG_SET(LDO_3V0_REF, DT_INST_PROP_OR(DT_NODELABEL(V30), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unsafe: what if we have >1 instance of V30? please, store the value in driver's config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no point is storing it drivers config. There is only one V30 rail in this soc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but driver is designed to be multi-instance, and this construct is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valued set from config
regulator-init-microvolt = <706000>; | ||
}; | ||
vdd_sleep: VDD_SLEEP { | ||
regulator-boot-on; | ||
regulator-init-microvolt = <750000>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are all these init values board specific? why are they defined in soc dts files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not board specific, they can be changed for board but they are soc specific values used here to achieve lowest power consumption.
#define DA1469X_MODE_LDO_VBAT_ON 0x10 | ||
#define DA1469X_MODE_V30_VBAT_CLAMP_ON 0x20 | ||
|
||
#define DCDC_REG_FIELD_MSK(dcdc, field) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have these macros come from an SDK, or were they written specifically for this driver?
I find them rather difficult to follow.
I think this would be better approached with a description structure for each regulator containing appropriate masks and fields, e.g:
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/regulator/regulator_pca9420.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All macros removed, pure SDK fields used across file
DCDC_REG_SET(VDD, ENABLE_HV, | ||
!!(config->flags & DA1469X_MODE_DCDC_HIGH_BATTERY_VOLTAGE_ON)); | ||
DCDC_REG_SET(VDD, ENABLE_LV, | ||
!!(config->flags & DA1469X_MODE_DCDC_LOW_BATTERY_VOLTAGE_ON)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be combined into a single write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after rework registers modified in one write
2b9e663
to
161e2ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reworking this, looks great.
Just a config nit from me remaining.
drivers/regulator/Kconfig.da1469x
Outdated
if REGULATOR_DA1469X | ||
|
||
config REGULATOR_DA1469X_INIT_PRIORITY | ||
int "Renesas DA1469x regulators driver init priority" | ||
default KERNEL_INIT_PRIORITY_DEVICE | ||
help | ||
Init priority for the Renesas DA1469x regulators driver. | ||
|
||
endif # REGULATOR_DA1469X |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single configs should use depends
if REGULATOR_DA1469X | |
config REGULATOR_DA1469X_INIT_PRIORITY | |
int "Renesas DA1469x regulators driver init priority" | |
default KERNEL_INIT_PRIORITY_DEVICE | |
help | |
Init priority for the Renesas DA1469x regulators driver. | |
endif # REGULATOR_DA1469X | |
config REGULATOR_DA1469X_INIT_PRIORITY | |
int "Renesas DA1469x regulators driver init priority" | |
default KERNEL_INIT_PRIORITY_DEVICE | |
depends on REGULATOR_DA1469X | |
help | |
Init priority for the Renesas DA1469x regulators driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aasinclair thanks for a hint, change applied as suggested
This add regulator driver for Smartbond DA1469X SOC. Driver can control VDD, V14, V18, V18P, V30 rails, full voltage range supported by SOC is covered. For VDD, V14, V18, V18P DCDC can be configured. Special VDD_CLAMP (always on) and VDD_SLEPP are added to allow configuration of VDD in sleep modes. Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
161e2ac
to
1bd1815
Compare
This add regulator driver for Smartbond DA1469X SOC. Driver can control VDD, V14, V18, V18P, V30 rails, full voltage range supported by SOC is covered.
For VDD, V14, V18, V18P DCDC can be configured.
Special VDD_CLAMP (always on) and VDD_SLEPP are added to allow configuration of VDD in sleep modes.
Whole configuration can be done in device tree and alter changed by Zephyr regulator API.