-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Add CP9314 regulator driver #68177
Add CP9314 regulator driver #68177
Conversation
9fc7075
to
e26dfa6
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.
Is there a datasheet for this part available?
drivers/regulator/regulator_cp9314.c
Outdated
static struct cp9314_reg_patch b0_reg_patch[18] = { | ||
{CP9314_REG_CRUS_CTRL, GENMASK(7, 0), CP9314_CRUS_KEY_UNLOCK}, | ||
{CP9314_REG_LION_COMP_CTRL_3, CP9314_VIN_OV_CFG, 0x1B}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VOUT_OV_CFG_0, 0x30}, | ||
{CP9314_REG_LION_COMP_CTRL_2, CP9314_VOUT_OV_CFG_1, 0xC}, | ||
{CP9314_REG_VIN2OUT_OVP, CP9314_VIN2OUT_OVP, 0x2}, | ||
{CP9314_REG_VIN2OUT_UVP, CP9314_VIN2OUT_UVP, 0x1}, | ||
{CP9314_REG_VOUT_UVP, CP9314_VOUT_UVP_DIS, 0}, | ||
{CP9314_REG_VOUT_UVP, CP9314_VOUT_UVP, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VIN_SWITCH_OK_DIS_0, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_4, CP9314_VIN_SWITCH_OK_DIS_1, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VIN_SWITCH_OK_CFG, 0}, | ||
{CP9314_REG_LION_CFG_3, CP9314_LB_MIN_FREQ_SEL_0, 0x80}, | ||
{CP9314_REG_LB_CTRL, CP9314_LB_MIN_FREQ_SEL_1, 0x4}, | ||
{CP9314_REG_TRIM_8, CP9314_MODE_CTRL_UPDATE_BW_0, 0x2}, | ||
{CP9314_REG_LION_CFG_3, CP9314_MODE_CTRL_UPDATE_BW_1, 0x2}, | ||
{CP9314_REG_IIN_OCP, CP9314_IIN_OCP_DIS, CP9314_IIN_OCP_DIS}, | ||
{CP9314_REG_IIN_PEAK_OCP, CP9314_IIN_PEAK_OCP_DIS, CP9314_IIN_PEAK_OCP_DIS}, | ||
{CP9314_REG_CRUS_CTRL, GENMASK(7, 0), CP9314_CRUS_KEY_LOCK}, | ||
}; | ||
|
||
static struct cp9314_reg_patch otp_1_patch[3] = { | ||
{CP9314_REG_OPTION_REG_1, CP9314_LB1_DELAY_CFG, 0}, | ||
{CP9314_REG_BST_CP_PD_CFG, CP9314_LB1_BLANK_CFG, CP9314_LB1_BLANK_CFG}, | ||
{CP9314_REG_TSBAT_CTRL, CP9314_LB1_STOP_PHASE_SEL, CP9314_LB1_STOP_PHASE_SEL}, | ||
}; |
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 probably deserve some docstring explaining what they are
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.
ping
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.
ack, let me know if the added comments are sufficient.
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.
It could do with an overall comment for the block giving a rough indication of what it is for, so that users can see what is being fixed.
e.g.
/** Patch for b0 silicon to correct trim errata and feedback scaling errors */
drivers/regulator/regulator_cp9314.c
Outdated
{CP9314_REG_TSBAT_CTRL, CP9314_LB1_STOP_PHASE_SEL, CP9314_LB1_STOP_PHASE_SEL}, | ||
}; | ||
|
||
LOG_MODULE_REGISTER(CP9314); |
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.
by convention, move just after includes. This also misses a log level.
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.
ack
drivers/regulator/regulator_cp9314.c
Outdated
return ret; | ||
} | ||
|
||
data->op_mode = mode; |
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.
data->op_mode doesn't seem to be used anywhere else.
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.
ack. A leftover from the earlier silicon revision.
drivers/regulator/regulator_cp9314.c
Outdated
int i, ret = 0; | ||
|
||
for (i = 0; i < ARRAY_SIZE(b0_reg_patch); i++) { |
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
scope can be reduced, for (size_t i = 0U; ...
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.
ack
drivers/regulator/regulator_cp9314.c
Outdated
ret |= i2c_reg_update_byte_dt(&config->i2c, b0_reg_patch[i].reg_addr, | ||
b0_reg_patch[i].mask, b0_reg_patch[i].value); |
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.
you should fail fast, also, errno can't be ored together.
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.
ack
drivers/regulator/regulator_cp9314.c
Outdated
return ret; | ||
} | ||
|
||
k_msleep(200); |
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 sleep, please define
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.
ack
drivers/regulator/regulator_cp9314.c
Outdated
uint8_t value; | ||
int i, ret; | ||
|
||
/** |
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.
not a doxygen docstring, use /*
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.
ack
drivers/regulator/regulator_cp9314.c
Outdated
return -ENOTSUP; | ||
} | ||
|
||
data->rev_id = value; |
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.
data->rev_id
is not used
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.
ack
/** | ||
* @name CP9314 Regulator modes | ||
* @{ | ||
*/ | ||
/** 2:1 mode */ | ||
#define CP9314_MODE_2TO1 1 | ||
/** 3:1 mode */ | ||
#define CP9314_MODE_3TO1 2 | ||
/** @} */ |
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.
can datasheet or details about these modes be provided? are these regulation modes?
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.
ack #68177 (comment)
@aasinclair and @gmarull
Unfortunately not one that can be shared. This is kind of a more quirky power IC, so I can expand on a bit here and update some of the block comments in the source as well. The power converter: This IC is meant for portable systems with 2 or 3 battery cells in series (ex. Laptop). The ICs purpose is to take the 2 or 3 cell battery voltage and buck down to a single cell battery voltage, this is the 2:1/3:1 operational modes. This sort of power converter (switched capacitor) is able to convert the power without resistive elements (greatly reducing heat aka power wasted) but is fixed to these sort of n:1 operational modes. So it's not really aiming for a regulated target voltage but rather only performing the immediate large power conversion. The functionality: The IC conversion operation can be switched on and off via GPIO or I2C command from the host. The operational mode (2:1 or 3:1) can be controlled via I2C from the host. Additionally, the IC can exist standalone or paired in parallel via a shared clock line provided by the initiator instance of the IC. In this mode, the ICs each have a unique I2C address and must be configured by the host based on their Let me know if this is enough detail to clarify what's going on in the source. Thanks |
e0684e5
to
9042103
Compare
9042103
to
768daf2
Compare
Is this something that the user is expected to change at runtime, or is it likely to be fixed by the design? Thanks |
It is fixed to the design. I will take an action to remove the runtime control of the op mode.
The default is set with a resistor. We do have one customer using the same BOM for two different SKUs (therefore different op modes), so the driver needs to be able to initialize and overwrite the op mode. |
Ah, my bad. If I get rid of Let me know if you would rather the initialization flag approach or just leaving it alone. |
I think this would be better implemented as a custom property, rather than as a mode. zephyr/dts/bindings/regulator/nxp,vref.yaml Lines 23 to 27 in 592a7cd
|
c1f6dcd
to
6621d76
Compare
Implemented it as |
|
||
include: | ||
- name: i2c-device.yaml | ||
- name: regulator.yaml |
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.
shouldn't this filter allowed props?
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.
ack. The only regulator we can use right now is regulator-boot-on
. Some protection properties may be added from regulator.yaml
down the line.
drivers/regulator/regulator_cp9314.c
Outdated
static struct cp9314_reg_patch b0_reg_patch[18] = { | ||
{CP9314_REG_CRUS_CTRL, GENMASK(7, 0), CP9314_CRUS_KEY_UNLOCK}, | ||
{CP9314_REG_LION_COMP_CTRL_3, CP9314_VIN_OV_CFG, 0x1B}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VOUT_OV_CFG_0, 0x30}, | ||
{CP9314_REG_LION_COMP_CTRL_2, CP9314_VOUT_OV_CFG_1, 0xC}, | ||
{CP9314_REG_VIN2OUT_OVP, CP9314_VIN2OUT_OVP, 0x2}, | ||
{CP9314_REG_VIN2OUT_UVP, CP9314_VIN2OUT_UVP, 0x1}, | ||
{CP9314_REG_VOUT_UVP, CP9314_VOUT_UVP_DIS, 0}, | ||
{CP9314_REG_VOUT_UVP, CP9314_VOUT_UVP, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VIN_SWITCH_OK_DIS_0, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_4, CP9314_VIN_SWITCH_OK_DIS_1, 0}, | ||
{CP9314_REG_LION_COMP_CTRL_1, CP9314_VIN_SWITCH_OK_CFG, 0}, | ||
{CP9314_REG_LION_CFG_3, CP9314_LB_MIN_FREQ_SEL_0, 0x80}, | ||
{CP9314_REG_LB_CTRL, CP9314_LB_MIN_FREQ_SEL_1, 0x4}, | ||
{CP9314_REG_TRIM_8, CP9314_MODE_CTRL_UPDATE_BW_0, 0x2}, | ||
{CP9314_REG_LION_CFG_3, CP9314_MODE_CTRL_UPDATE_BW_1, 0x2}, | ||
{CP9314_REG_IIN_OCP, CP9314_IIN_OCP_DIS, CP9314_IIN_OCP_DIS}, | ||
{CP9314_REG_IIN_PEAK_OCP, CP9314_IIN_PEAK_OCP_DIS, CP9314_IIN_PEAK_OCP_DIS}, | ||
{CP9314_REG_CRUS_CTRL, GENMASK(7, 0), CP9314_CRUS_KEY_LOCK}, | ||
}; | ||
|
||
static struct cp9314_reg_patch otp_1_patch[3] = { | ||
{CP9314_REG_OPTION_REG_1, CP9314_LB1_DELAY_CFG, 0}, | ||
{CP9314_REG_BST_CP_PD_CFG, CP9314_LB1_BLANK_CFG, CP9314_LB1_BLANK_CFG}, | ||
{CP9314_REG_TSBAT_CTRL, CP9314_LB1_STOP_PHASE_SEL, CP9314_LB1_STOP_PHASE_SEL}, | ||
}; |
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.
ping
*/ | ||
/** 2:1 mode */ | ||
#define CP9314_MODE_2TO1 1 | ||
/** 3:1 mode */ | ||
#define CP9314_MODE_3TO1 2 | ||
/** @} */ |
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 these used now? If for the new vendor property, please, add an example in the bindings file showing its usage.
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.
also, an enum on such property (if used there) to avoid user mistakes would be useful 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.
If you use enums & ENUM_IDX macros, you can remove this file.
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.
ack
*/ | ||
/** 2:1 mode */ | ||
#define CP9314_MODE_2TO1 1 | ||
/** 3:1 mode */ | ||
#define CP9314_MODE_3TO1 2 | ||
/** @} */ |
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.
If you use enums & ENUM_IDX macros, you can remove this file.
6621d76
to
0d3f8a8
Compare
Adds devicetree bindings for the Cirrus CP9314 Switched Capacitor 3:1/2:1 DC/DC converter. Signed-off-by: Ricardo Rivera-Matos <[email protected]>
0d3f8a8
to
11b313a
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.
Typo nit, but otherwise looks great.
Adds support for the CP9314 switched capacitor converter. The CP9314 is a multi-level DC/DC converter capable of operating in 2:1 and 3:1 modes. Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Adds the CP9314 device to the regulator build_all test suite. Signed-off-by: Ricardo Rivera-Matos <[email protected]>
11b313a
to
14e7375
Compare
Adds support for the CP9314 switched-capacitor regulator. Functional modes supported:
Only B0 silicon is supported.