regulator: Allow regulators to register with no init_data
PATCH 1/1 regulator: Allow regulators to register with no init_data
This allows read-only access to the device configuration which may be useful for diagnostics.
Signed-off-by Mark Brown <[email protected]>
--- drivers/regulator/core.c | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-)
drivers/regulator/core.c +15 -10
@@ -912,8 +912,12 @@ static int set_machine_constraints(struct regulator_dev *rdev,int ret =0 ;struct regulator_ops *ops = rdev->desc->ops; - rdev->constraints =kmemdup (constraints,sizeof (*constraints), -GFP_KERNEL ); +if (constraints) + rdev->constraints =kmemdup (constraints,sizeof (*constraints), +GFP_KERNEL ); +else + rdev->constraints =kzalloc (sizeof (*constraints), +GFP_KERNEL );if (!rdev->constraints)return -ENOMEM ;
@@ -922,7 +926,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, goto out;/* do we need to setup our suspend state */ -if (constraints->initial_state) { +if (rdev->constraints->initial_state) { ret =suspend_prepare (rdev, rdev->constraints->initial_state);if (ret <0 ) {rdev_err (rdev,"failed to set suspend state\n" );
@@ -930,7 +934,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, } } -if (constraints->initial_mode) { +if (rdev->constraints->initial_mode) {if (!ops->set_mode) {rdev_err (rdev,"no set_mode operation\n" ); ret = -EINVAL ;
@@ -2697,6 +2701,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, struct device *dev, const struct regulator_init_data *init_data, void *driver_data, struct device_node *of_node) { + const struct regulation_constraints *constraints = NULL;static atomic_t regulator_no =ATOMIC_INIT (0 );struct regulator_dev *rdev;int ret, i;
@@ -2712,9 +2717,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, regulator_desc->type != REGULATOR_CURRENT)return ERR_PTR (-EINVAL ); -if (!init_data) -return ERR_PTR (-EINVAL ); -/* Only one of each should be implemented */ WARN_ON (regulator_desc->ops->get_voltage && regulator_desc->ops->get_voltage_sel);
@@ -2747,7 +2749,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,INIT_DELAYED_WORK (&rdev->disable_work, regulator_disable_work);/* preform any regulator specific init */ -if (init_data->regulator_init) { +if (init_data && init_data->regulator_init) { ret = init_data->regulator_init (rdev->reg_data);if (ret <0 ) goto clean;
@@ -2768,7 +2770,10 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,dev_set_drvdata (&rdev->dev, rdev);/* set regulator constraints */ - ret =set_machine_constraints (rdev, &init_data->constraints); +if (init_data) + constraints = &init_data->constraints; + + ret =set_machine_constraints (rdev, constraints);if (ret <0 ) goto scrub;
@@ -2777,7 +2782,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,if (ret <0 ) goto scrub; -if (init_data->supply_regulator) +if (init_data && init_data->supply_regulator) supply = init_data->supply_regulator;else if (regulator_desc->supply_name) supply = regulator_desc->supply_name;
Signature · 1 line
1.7.7.3
Quoted 4 lines · Mark Brown
This allows read-only access to the device configuration which may be useful for diagnostics.
Signed-off-by Mark Brown <[email protected]>
Acked-by Liam Girdwood <[email protected]>