drivers: regulator: refactor PMIC binding to use physical PMIC IC

Refactor binding to use root PMIC IC, so that properties can be shared
between regulator devices. Each individual regulator output is still
created as an individual device, since the regulator API aligns with
these devices better than the PMIC IC itself.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-10-06 15:45:05 -05:00 committed by Carles Cufí
commit f367897bce
4 changed files with 129 additions and 113 deletions

View file

@ -156,9 +156,9 @@ arduino_serial: &flexcomm12 {
pca9420: pca9420@61 {
reg = <0x61>;
compatible = "regulator-pmic";
pca9420_sw1: sw1_buck {
compatible = "regulator-pmic";
voltage-range = <PCA9420_SW1_VOLTAGE_RANGE>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
num-voltages = <42>;
@ -175,7 +175,6 @@ arduino_serial: &flexcomm12 {
};
pca9420_sw2: sw2_buck {
compatible = "regulator-pmic";
voltage-range = <PCA9420_SW2_VOLTAGE_RANGE>;
num-voltages = <50>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
@ -192,7 +191,6 @@ arduino_serial: &flexcomm12 {
};
pca9420_ldo1: ldo1_reg {
compatible = "regulator-pmic";
voltage-range = <PCA9420_LDO1_VOLTAGE_RANGE>;
num-voltages = <9>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
@ -209,7 +207,6 @@ arduino_serial: &flexcomm12 {
};
pca9420_ldo2: ldo2_reg {
compatible = "regulator-pmic";
voltage-range = <PCA9420_LDO2_VOLTAGE_RANGE>;
num-voltages = <50>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;

View file

@ -230,9 +230,9 @@ i2s1: &flexcomm3 {
pca9420: pca9420@61 {
reg = <0x61>;
compatible = "regulator-pmic";
pca9420_sw1: sw1_buck {
compatible = "regulator-pmic";
voltage-range = <PCA9420_SW1_VOLTAGE_RANGE>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
num-voltages = <42>;
@ -249,7 +249,6 @@ i2s1: &flexcomm3 {
};
pca9420_sw2: sw2_buck {
compatible = "regulator-pmic";
voltage-range = <PCA9420_SW2_VOLTAGE_RANGE>;
num-voltages = <50>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
@ -266,7 +265,6 @@ i2s1: &flexcomm3 {
};
pca9420_ldo1: ldo1_reg {
compatible = "regulator-pmic";
voltage-range = <PCA9420_LDO1_VOLTAGE_RANGE>;
num-voltages = <9>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;
@ -283,7 +281,6 @@ i2s1: &flexcomm3 {
};
pca9420_ldo2: ldo2_reg {
compatible = "regulator-pmic";
voltage-range = <PCA9420_LDO2_VOLTAGE_RANGE>;
num-voltages = <50>;
current-levels = <PCA9420_CURRENT_LIMIT_LEVELS>;

View file

@ -308,32 +308,52 @@ static const struct regulator_driver_api api = {
.disable = disable_regulator
};
#define CONFIGURE_REGULATOR(id) \
static uint32_t pmic_reg_##id##_cur_limits[] = \
DT_INST_PROP_OR(id, current_levels, {}); \
static uint32_t pmic_reg_##id##_vol_range[] = \
DT_INST_PROP(id, voltage_range); \
static struct regulator_data pmic_reg_##id##_data; \
static struct regulator_config pmic_reg_##id##_cfg = { \
.vsel_mask = DT_INST_PROP(id, vsel_mask), \
.vsel_reg = DT_INST_PROP(id, vsel_reg), \
.num_voltages = DT_INST_PROP(id, num_voltages), \
.num_current_levels = DT_INST_PROP(id, num_current_levels), \
.enable_reg = DT_INST_PROP(id, enable_reg), \
.enable_mask = DT_INST_PROP(id, enable_mask), \
.enable_val = DT_INST_PROP(id, enable_val), \
.min_uV = DT_INST_PROP(id, min_uv), \
.max_uV = DT_INST_PROP(id, max_uv), \
.ilim_reg = DT_INST_PROP_OR(id, ilim_reg, 0), \
.ilim_mask = DT_INST_PROP_OR(id, ilim_mask, 0), \
.enable_inverted = DT_INST_PROP(id, enable_inverted), \
.i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(id)), \
.voltage_array = pmic_reg_##id##_vol_range, \
.current_array = pmic_reg_##id##_cur_limits, \
/*
* Each regulator output will be initialized as a separate device struct,
* and implement the regulator API. Since the DT binding is defined for the
* entire regulator, this macro will be called for each child node of the
* regulator device. This allows the regulator to have common DTS properties
* shared between each regulator output
*/
#define CONFIGURE_REGULATOR_OUTPUT(node, ord) \
static uint32_t pmic_reg_##ord##_cur_limits[] = \
DT_PROP_OR(node, current_levels, {}); \
static uint32_t pmic_reg_##ord##_vol_range[] = \
DT_PROP(node, voltage_range); \
static struct regulator_data pmic_reg_##ord##_data; \
static struct regulator_config pmic_reg_##ord##_cfg = { \
.vsel_mask = DT_PROP(node, vsel_mask), \
.vsel_reg = DT_PROP(node, vsel_reg), \
.num_voltages = DT_PROP(node, num_voltages), \
.num_current_levels = DT_PROP(node, num_current_levels), \
.enable_reg = DT_PROP(node, enable_reg), \
.enable_mask = DT_PROP(node, enable_mask), \
.enable_val = DT_PROP(node, enable_val), \
.min_uV = DT_PROP(node, min_uv), \
.max_uV = DT_PROP(node, max_uv), \
.ilim_reg = DT_PROP_OR(node, ilim_reg, 0), \
.ilim_mask = DT_PROP_OR(node, ilim_mask, 0), \
.enable_inverted = DT_PROP(node, enable_inverted), \
.i2c = I2C_DT_SPEC_GET(DT_PARENT(node)), \
.voltage_array = pmic_reg_##ord##_vol_range, \
.current_array = pmic_reg_##ord##_cur_limits, \
}; \
DEVICE_DT_INST_DEFINE(id, pmic_reg_init, NULL, \
&pmic_reg_##id##_data, &pmic_reg_##id##_cfg, \
DEVICE_DT_DEFINE(node, pmic_reg_init, NULL, \
&pmic_reg_##ord##_data, \
&pmic_reg_##ord##_cfg, \
POST_KERNEL, CONFIG_PMIC_REGULATOR_INIT_PRIORITY, \
&api); \
/* Intermediate macros to extract DT node ordinal
* (used as a unique token for variable names)
*/
#define _CONFIGURE_REGULATOR_OUTPUT(node, ord) \
CONFIGURE_REGULATOR_OUTPUT(node, ord)
#define __CONFIGURE_REGULATOR_OUTPUT(node) \
_CONFIGURE_REGULATOR_OUTPUT(node, DT_DEP_ORD(node))
#define CONFIGURE_REGULATOR(id) \
DT_INST_FOREACH_CHILD(id, __CONFIGURE_REGULATOR_OUTPUT)
DT_INST_FOREACH_STATUS_OKAY(CONFIGURE_REGULATOR)

View file

@ -7,7 +7,9 @@ include: regulator.yaml
compatible: "regulator-pmic"
properties:
child-binding:
description: Voltage output of PMIC controller regulator
properties:
voltage-range:
type: array
required: true