From 5a523605afa7d3b54b2e7041f8c9e6bc39872a7e Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Tue, 10 Sep 2013 15:45:05 +0530 Subject: regulator: core: provide fixed voltage in desc for single voltage rail If given rail has the single voltage (n_voltages = 1) then provide the rail voltage through regulator descriptor so that core can use this value for finding voltage. This will avoid the implementation of the callback for get_voltage() or list_voltage() callback on regulator driver. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown --- include/linux/regulator/driver.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 67e13aa5a478..9e8241a9f28f 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -207,6 +207,7 @@ enum regulator_type { * @min_uV: Voltage given by the lowest selector (if linear mapping) * @uV_step: Voltage increase with each selector (if linear mapping) * @linear_min_sel: Minimal selector for starting linear mapping + * @fixed_uV: Fixed voltage of rails. * @ramp_delay: Time to settle down after voltage change (unit: uV/us) * @volt_table: Voltage mapping table (if table based mapping) * @@ -239,6 +240,7 @@ struct regulator_desc { unsigned int min_uV; unsigned int uV_step; unsigned int linear_min_sel; + int fixed_uV; unsigned int ramp_delay; const struct regulator_linear_range *linear_ranges; -- cgit v1.2.3 From b33e46bcdc4e598d738ed12a5a7906be4e11d786 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Sat, 31 Aug 2013 11:58:26 +0100 Subject: regulator: core: Provide managed regulator registration Many regulator drivers have a remove function that consists solely of calling regulator_unregister() so provide a devm_regulator_register() in order to allow this repeated code to be removed and help eliminate error handling code. Signed-off-by: Mark Brown --- Documentation/driver-model/devres.txt | 1 + drivers/regulator/core.c | 66 +++++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 5 +++ 3 files changed, 72 insertions(+) (limited to 'include') diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index fcb34a5697ea..3d9c2a766230 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -283,6 +283,7 @@ REGULATOR devm_regulator_get() devm_regulator_put() devm_regulator_bulk_get() + devm_regulator_register() CLOCK devm_clk_get() diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a01b8b3b70ca..5f995d281672 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3492,6 +3492,44 @@ clean: } EXPORT_SYMBOL_GPL(regulator_register); +static void devm_rdev_release(struct device *dev, void *res) +{ + regulator_unregister(*(struct regulator_dev **)res); +} + +/** + * devm_regulator_register - Resource managed regulator_register() + * @regulator_desc: regulator to register + * @config: runtime configuration for regulator + * + * Called by regulator drivers to register a regulator. Returns a + * valid pointer to struct regulator_dev on success or an ERR_PTR() on + * error. The regulator will automaticall be released when the device + * is unbound. + */ +struct regulator_dev *devm_regulator_register(struct device *dev, + const struct regulator_desc *regulator_desc, + const struct regulator_config *config) +{ + struct regulator_dev **ptr, *rdev; + + ptr = devres_alloc(devm_rdev_release, sizeof(*ptr), + GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + rdev = regulator_register(regulator_desc, config); + if (!IS_ERR(rdev)) { + *ptr = rdev; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return rdev; +} +EXPORT_SYMBOL_GPL(devm_regulator_register); + /** * regulator_unregister - unregister regulator * @rdev: regulator to unregister @@ -3521,6 +3559,34 @@ void regulator_unregister(struct regulator_dev *rdev) } EXPORT_SYMBOL_GPL(regulator_unregister); +static int devm_rdev_match(struct device *dev, void *res, void *data) +{ + struct regulator_dev **r = res; + if (!r || !*r) { + WARN_ON(!r || !*r); + return 0; + } + return *r == data; +} + +/** + * devm_regulator_unregister - Resource managed regulator_unregister() + * @regulator: regulator to free + * + * Unregister a regulator registered with devm_regulator_register(). + * Normally this function will not need to be called and the resource + * management code will ensure that the resource is freed. + */ +void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev) +{ + int rc; + + rc = devres_release(dev, devm_rdev_release, devm_rdev_match, rdev); + if (rc != 0) + WARN_ON(rc); +} +EXPORT_SYMBOL_GPL(devm_regulator_unregister); + /** * regulator_suspend_prepare - prepare regulators for system wide suspend * @state: system suspend state diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 67e13aa5a478..8474c7f88745 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -334,7 +334,12 @@ struct regulator_dev { struct regulator_dev * regulator_register(const struct regulator_desc *regulator_desc, const struct regulator_config *config); +struct regulator_dev * +devm_regulator_register(struct device *dev, + const struct regulator_desc *regulator_desc, + const struct regulator_config *config); void regulator_unregister(struct regulator_dev *rdev); +void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev); int regulator_notifier_call_chain(struct regulator_dev *rdev, unsigned long event, void *data); -- cgit v1.2.3 From 4f0ac6dabf867095b31f851ba0d0ceaca2f87e2e Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 13 Sep 2013 19:51:47 +0100 Subject: regulator: core: Remove unused regulator_use_dummy_regulator() No boards have used this functionality and the new default of providing dummy regulators by default provides a better solution to the problem it was trying to solve. Signed-off-by: Mark Brown --- drivers/regulator/core.c | 17 ----------------- include/linux/regulator/machine.h | 5 ----- 2 files changed, 22 deletions(-) (limited to 'include') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 8fd170788c3e..ac3a864d3635 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -53,7 +53,6 @@ static LIST_HEAD(regulator_list); static LIST_HEAD(regulator_map_list); static LIST_HEAD(regulator_ena_gpio_list); static bool has_full_constraints; -static bool board_wants_dummy_regulator; static struct dentry *debugfs_root; @@ -3615,22 +3614,6 @@ void regulator_has_full_constraints(void) } EXPORT_SYMBOL_GPL(regulator_has_full_constraints); -/** - * regulator_use_dummy_regulator - Provide a dummy regulator when none is found - * - * Calling this function will cause the regulator API to provide a - * dummy regulator to consumers if no physical regulator is found, - * allowing most consumers to proceed as though a regulator were - * configured. This allows systems such as those with software - * controllable regulators for the CPU core only to be brought up more - * readily. - */ -void regulator_use_dummy_regulator(void) -{ - board_wants_dummy_regulator = true; -} -EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator); - /** * rdev_get_drvdata - get rdev regulator driver data * @rdev: regulator diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 999b20ce06cf..a9f7c55a4d4d 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -193,15 +193,10 @@ int regulator_suspend_finish(void); #ifdef CONFIG_REGULATOR void regulator_has_full_constraints(void); -void regulator_use_dummy_regulator(void); #else static inline void regulator_has_full_constraints(void) { } - -static inline void regulator_use_dummy_regulator(void) -{ -} #endif #endif -- cgit v1.2.3 From 00c877c69ba315d6c565a4df51c71b11e82cdeb8 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Wed, 18 Sep 2013 18:18:02 +0530 Subject: regulator: core: add support for configuring turn-on time through constraints The turn-on time of the regulator depends on the regulator device's electrical characteristics. Sometimes regulator turn-on time also depends on the capacitive load on the given platform and it can be more than the datasheet value. The driver provides the enable-time as per datasheet. Add support for configure the enable ramp time through regulator constraints so that regulator core can take this value for enable time for that regulator. Signed-off-by: Laxman Dewangan Acked-by: Stephen Warren Signed-off-by: Mark Brown --- Documentation/devicetree/bindings/regulator/regulator.txt | 5 +++++ drivers/regulator/core.c | 2 ++ drivers/regulator/of_regulator.c | 6 ++++++ include/linux/regulator/machine.h | 2 ++ 4 files changed, 15 insertions(+) (limited to 'include') diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt index 2bd8f0978765..e2c7f1e7251a 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.txt +++ b/Documentation/devicetree/bindings/regulator/regulator.txt @@ -14,6 +14,11 @@ Optional properties: - regulator-ramp-delay: ramp delay for regulator(in uV/uS) For hardwares which support disabling ramp rate, it should be explicitly intialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay. +- regulator-enable-ramp-delay: The time taken, in microseconds, for the supply + rail to reach the target voltage, plus/minus whatever tolerance the board + design requires. This property describes the total system ramp time + required due to the combination of internal ramping of the regulator itself, + and board design issues such as trace capacitance and load on the supply. Deprecated properties: - regulator-compatible: If a regulator chip contains multiple diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a01b8b3b70ca..5217c1964c32 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1186,6 +1186,8 @@ overflow_err: static int _regulator_get_enable_time(struct regulator_dev *rdev) { + if (rdev->constraints && rdev->constraints->enable_time) + return rdev->constraints->enable_time; if (!rdev->desc->ops->enable_time) return rdev->desc->enable_time; return rdev->desc->ops->enable_time(rdev); diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 7827384680d6..ea4f36f2cbe2 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -23,6 +23,8 @@ static void of_get_regulation_constraints(struct device_node *np, const __be32 *min_uA, *max_uA, *ramp_delay; struct property *prop; struct regulation_constraints *constraints = &(*init_data)->constraints; + int ret; + u32 pval; constraints->name = of_get_property(np, "regulator-name", NULL); @@ -73,6 +75,10 @@ static void of_get_regulation_constraints(struct device_node *np, else constraints->ramp_disable = true; } + + ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval); + if (!ret) + constraints->enable_time = pval; } /** diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 999b20ce06cf..8108751acb86 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -95,6 +95,7 @@ struct regulator_state { * @initial_state: Suspend state to set by default. * @initial_mode: Mode to set at startup. * @ramp_delay: Time to settle down after voltage change (unit: uV/us) + * @enable_time: Turn-on time of the rails (unit: microseconds) */ struct regulation_constraints { @@ -129,6 +130,7 @@ struct regulation_constraints { unsigned int initial_mode; unsigned int ramp_delay; + unsigned int enable_time; /* constraint flags */ unsigned always_on:1; /* regulator never off when system is on */ -- cgit v1.2.3 From e277e656804c85a0729d4fd8cdd3c8ab3e6b3b86 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 11 Oct 2013 09:30:24 +0800 Subject: regulator: Remove max_uV from struct regulator_linear_range linear ranges means each range has linear voltage settings. So we can calculate max_uV for each linear range in regulator core rather than set the max_uV field in drivers. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/88pm800.c | 14 ++++++-------- drivers/regulator/as3711-regulator.c | 25 +++++++++++-------------- drivers/regulator/as3722-regulator.c | 1 - drivers/regulator/da903x.c | 6 ++---- drivers/regulator/helpers.c | 6 +++++- drivers/regulator/tps65217-regulator.c | 24 ++++++++---------------- drivers/regulator/tps65912-regulator.c | 9 +++------ drivers/regulator/wm831x-ldo.c | 12 ++++-------- drivers/regulator/wm8350-regulator.c | 6 ++---- drivers/regulator/wm8400-regulator.c | 6 ++---- include/linux/regulator/driver.h | 2 -- 11 files changed, 43 insertions(+), 68 deletions(-) (limited to 'include') diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 3459f60dcfd1..22ba4c4280ee 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c @@ -141,18 +141,16 @@ struct pm800_regulators { /* Ranges are sorted in ascending order. */ static const struct regulator_linear_range buck1_volt_range[] = { - { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f, - .uV_step = 12500 }, - { .min_uV = 1600000, .max_uV = 1800000, .min_sel = 0x50, - .max_sel = 0x54, .uV_step = 50000 }, + { .min_uV = 600000, .min_sel = 0, .max_sel = 0x4f, .uV_step = 12500 }, + { .min_uV = 1600000, .min_sel = 0x50, .max_sel = 0x54, + .uV_step = 50000 }, }; /* BUCK 2~5 have same ranges. */ static const struct regulator_linear_range buck2_5_volt_range[] = { - { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f, - .uV_step = 12500 }, - { .min_uV = 1600000, .max_uV = 3300000, .min_sel = 0x50, - .max_sel = 0x72, .uV_step = 50000 }, + { .min_uV = 600000, .min_sel = 0, .max_sel = 0x4f, .uV_step = 12500 }, + { .min_uV = 1600000, .min_sel = 0x50, .max_sel = 0x72, + .uV_step = 50000 }, }; static const unsigned int ldo1_volt_table[] = { diff --git a/drivers/regulator/as3711-regulator.c b/drivers/regulator/as3711-regulator.c index 8406cd745da2..d0a97e5ea431 100644 --- a/drivers/regulator/as3711-regulator.c +++ b/drivers/regulator/as3711-regulator.c @@ -117,26 +117,23 @@ static struct regulator_ops as3711_dldo_ops = { }; static const struct regulator_linear_range as3711_sd_ranges[] = { - { .min_uV = 612500, .max_uV = 1400000, - .min_sel = 0x1, .max_sel = 0x40, .uV_step = 12500 }, - { .min_uV = 1425000, .max_uV = 2600000, - .min_sel = 0x41, .max_sel = 0x70, .uV_step = 25000 }, - { .min_uV = 2650000, .max_uV = 3350000, - .min_sel = 0x71, .max_sel = 0x7f, .uV_step = 50000 }, + { .min_uV = 612500, .min_sel = 0x1, .max_sel = 0x40, .uV_step = 12500 }, + { .min_uV = 1425000, .min_sel = 0x41, .max_sel = 0x70, + .uV_step = 25000 }, + { .min_uV = 2650000, .min_sel = 0x71, .max_sel = 0x7f, + .uV_step = 50000 }, }; static const struct regulator_linear_range as3711_aldo_ranges[] = { - { .min_uV = 1200000, .max_uV = 1950000, - .min_sel = 0, .max_sel = 0xf, .uV_step = 50000 }, - { .min_uV = 1800000, .max_uV = 3300000, - .min_sel = 0x10, .max_sel = 0x1f, .uV_step = 100000 }, + { .min_uV = 1200000, .min_sel = 0, .max_sel = 0xf, .uV_step = 50000 }, + { .min_uV = 1800000, .min_sel = 0x10, .max_sel = 0x1f, + .uV_step = 100000 }, }; static const struct regulator_linear_range as3711_dldo_ranges[] = { - { .min_uV = 900000, .max_uV = 1700000, - .min_sel = 0, .max_sel = 0x10, .uV_step = 50000 }, - { .min_uV = 1750000, .max_uV = 3300000, - .min_sel = 0x20, .max_sel = 0x3f, .uV_step = 50000 }, + { .min_uV = 900000, .min_sel = 0, .max_sel = 0x10, .uV_step = 50000 }, + { .min_uV = 1750000, .min_sel = 0x20, .max_sel = 0x3f, + .uV_step = 50000 }, }; #define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \ diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index d7b71a9c41f1..240ae6d2ee2a 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -441,7 +441,6 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .max_sel = _max_sel, \ .uV_step = _step_uV, \ .min_uV = _min_uV, \ - .max_uV = _min_uV + (_max_sel - _min_sel) * _step_uV, \ } static const struct regulator_linear_range as3722_ldo_ranges[] = { diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index f06854cf8cf5..90d55e066447 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c @@ -253,10 +253,8 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev, } static const struct regulator_linear_range da9034_ldo12_ranges[] = { - { .min_uV = 1700000, .max_uV = 2050000, .min_sel = 0, .max_sel = 7, - .uV_step = 50000 }, - { .min_uV = 2700000, .max_uV = 3050000, .min_sel = 8, .max_sel = 15, - .uV_step = 50000 }, + { .min_uV = 1700000, .min_sel = 0, .max_sel = 7, .uV_step = 50000 }, + { .min_uV = 2700000, .min_sel = 8, .max_sel = 15, .uV_step = 50000 }, }; static struct regulator_ops da903x_regulator_ldo_ops = { diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index 6e30df14714b..e221a271ba56 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -284,9 +284,13 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev, } for (i = 0; i < rdev->desc->n_linear_ranges; i++) { + int linear_max_uV; + range = &rdev->desc->linear_ranges[i]; + linear_max_uV = range->min_uV + + (range->max_sel - range->min_sel) * range->uV_step; - if (!(min_uV <= range->max_uV && max_uV >= range->min_uV)) + if (!(min_uV <= linear_max_uV && max_uV >= range->min_uV)) continue; if (min_uV <= range->min_uV) diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 90861d68a0b0..484866f43681 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c @@ -52,25 +52,17 @@ static const unsigned int LDO1_VSEL_table[] = { }; static const struct regulator_linear_range tps65217_uv1_ranges[] = { - { .min_uV = 900000, .max_uV = 1500000, .min_sel = 0, .max_sel = 24, - .uV_step = 25000 }, - { .min_uV = 1550000, .max_uV = 1800000, .min_sel = 25, .max_sel = 30, - .uV_step = 50000 }, - { .min_uV = 1850000, .max_uV = 2900000, .min_sel = 31, .max_sel = 52, - .uV_step = 50000 }, - { .min_uV = 3000000, .max_uV = 3200000, .min_sel = 53, .max_sel = 55, - .uV_step = 100000 }, - { .min_uV = 3300000, .max_uV = 3300000, .min_sel = 56, .max_sel = 62, - .uV_step = 0 }, + { .min_uV = 900000, .min_sel = 0, .max_sel = 24, .uV_step = 25000 }, + { .min_uV = 1550000, .min_sel = 25, .max_sel = 30, .uV_step = 50000 }, + { .min_uV = 1850000, .min_sel = 31, .max_sel = 52, .uV_step = 50000 }, + { .min_uV = 3000000, .min_sel = 53, .max_sel = 55, .uV_step = 100000 }, + { .min_uV = 3300000, .min_sel = 56, .max_sel = 62, .uV_step = 0 }, }; static const struct regulator_linear_range tps65217_uv2_ranges[] = { - { .min_uV = 1500000, .max_uV = 1900000, .min_sel = 0, .max_sel = 8, - .uV_step = 50000 }, - { .min_uV = 2000000, .max_uV = 2400000, .min_sel = 9, .max_sel = 13, - .uV_step = 100000 }, - { .min_uV = 2450000, .max_uV = 3300000, .min_sel = 14, .max_sel = 31, - .uV_step = 50000 }, + { .min_uV = 1500000, .min_sel = 0, .max_sel = 8, .uV_step = 50000 }, + { .min_uV = 2000000, .min_sel = 9, .max_sel = 13, .uV_step = 100000 }, + { .min_uV = 2450000, .min_sel = 14, .max_sel = 31, .uV_step = 50000 }, }; static int tps65217_pmic_enable(struct regulator_dev *dev) diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index 281e52ac64ba..9fc87d8c9ce5 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -119,12 +119,9 @@ struct tps65912_reg { }; static const struct regulator_linear_range tps65912_ldo_ranges[] = { - { .min_uV = 800000, .max_uV = 1600000, .min_sel = 0, .max_sel = 32, - .uV_step = 25000 }, - { .min_uV = 1650000, .max_uV = 3000000, .min_sel = 33, .max_sel = 60, - .uV_step = 50000 }, - { .min_uV = 3100000, .max_uV = 3300000, .min_sel = 61, .max_sel = 63, - .uV_step = 100000 }, + { .min_uV = 800000, .min_sel = 0, .max_sel = 32, .uV_step = 25000 }, + { .min_uV = 1650000, .min_sel = 33, .max_sel = 60, .uV_step = 50000 }, + { .min_uV = 3100000, .min_sel = 61, .max_sel = 63, .uV_step = 100000 }, }; static int tps65912_get_range(struct tps65912_reg *pmic, int id) diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 2205fbc2c37b..a95814027b24 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c @@ -63,10 +63,8 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) */ static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = { - { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14, - .uV_step = 50000 }, - { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31, - .uV_step = 100000 }, + { .min_uV = 900000, .min_sel = 0, .max_sel = 14, .uV_step = 50000 }, + { .min_uV = 1700000, .min_sel = 15, .max_sel = 31, .uV_step = 100000 }, }; static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, @@ -332,10 +330,8 @@ static struct platform_driver wm831x_gp_ldo_driver = { */ static const struct regulator_linear_range wm831x_aldo_ranges[] = { - { .min_uV = 1000000, .max_uV = 1600000, .min_sel = 0, .max_sel = 12, - .uV_step = 50000 }, - { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31, - .uV_step = 100000 }, + { .min_uV = 1000000, .min_sel = 0, .max_sel = 12, .uV_step = 50000 }, + { .min_uV = 1700000, .min_sel = 13, .max_sel = 31, .uV_step = 100000 }, }; static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 61ca9292a429..de9de26d0bfc 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -543,10 +543,8 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, } static const struct regulator_linear_range wm8350_ldo_ranges[] = { - { .min_uV = 900000, .max_uV = 1650000, .min_sel = 0, .max_sel = 15, - .uV_step = 50000 }, - { .min_uV = 1800000, .max_uV = 3300000, .min_sel = 16, .max_sel = 31, - .uV_step = 100000 }, + { .min_uV = 900000, .min_sel = 0, .max_sel = 15, .uV_step = 50000 }, + { .min_uV = 1800000, .min_sel = 16, .max_sel = 31, .uV_step = 100000 }, }; static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 58f51bec13f2..3352b2090ed5 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c @@ -20,10 +20,8 @@ #include static const struct regulator_linear_range wm8400_ldo_ranges[] = { - { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14, - .uV_step = 50000 }, - { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31, - .uV_step = 100000 }, + { .min_uV = 900000, .min_sel = 0, .max_sel = 14, .uV_step = 50000 }, + { .min_uV = 1700000, .min_sel = 15, .max_sel = 31, .uV_step = 100000 }, }; static struct regulator_ops wm8400_ldo_ops = { diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 9bdad43ad228..997ff5c4d880 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -46,14 +46,12 @@ enum regulator_status { * regulator_list_linear_range(). * * @min_uV: Lowest voltage in range - * @max_uV: Highest voltage in range * @min_sel: Lowest selector for range * @max_sel: Highest selector for range * @uV_step: Step size */ struct regulator_linear_range { unsigned int min_uV; - unsigned int max_uV; unsigned int min_sel; unsigned int max_sel; unsigned int uV_step; -- cgit v1.2.3 From 8828bae464b129abed95b748263f1ab53bdc5755 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 11 Oct 2013 09:32:18 +0800 Subject: regulator: Add REGULATOR_LINEAR_RANGE macro Add REGULATOR_LINEAR_RANGE macro and convert regulator drivers to use it. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/88pm800.c | 10 ++++------ drivers/regulator/as3711-regulator.c | 18 +++++++----------- drivers/regulator/as3722-regulator.c | 18 +++++------------- drivers/regulator/da903x.c | 4 ++-- drivers/regulator/tps65217-regulator.c | 16 ++++++++-------- drivers/regulator/tps65912-regulator.c | 6 +++--- drivers/regulator/wm831x-ldo.c | 8 ++++---- drivers/regulator/wm8350-regulator.c | 4 ++-- drivers/regulator/wm8400-regulator.c | 4 ++-- include/linux/regulator/driver.h | 9 +++++++++ 10 files changed, 46 insertions(+), 51 deletions(-) (limited to 'include') diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 22ba4c4280ee..d333f7eac106 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c @@ -141,16 +141,14 @@ struct pm800_regulators { /* Ranges are sorted in ascending order. */ static const struct regulator_linear_range buck1_volt_range[] = { - { .min_uV = 600000, .min_sel = 0, .max_sel = 0x4f, .uV_step = 12500 }, - { .min_uV = 1600000, .min_sel = 0x50, .max_sel = 0x54, - .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(600000, 0, 0x4f, 12500), + REGULATOR_LINEAR_RANGE(1600000, 0x50, 0x54, 50000), }; /* BUCK 2~5 have same ranges. */ static const struct regulator_linear_range buck2_5_volt_range[] = { - { .min_uV = 600000, .min_sel = 0, .max_sel = 0x4f, .uV_step = 12500 }, - { .min_uV = 1600000, .min_sel = 0x50, .max_sel = 0x72, - .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(600000, 0, 0x4f, 12500), + REGULATOR_LINEAR_RANGE(1600000, 0x50, 0x72, 50000), }; static const unsigned int ldo1_volt_table[] = { diff --git a/drivers/regulator/as3711-regulator.c b/drivers/regulator/as3711-regulator.c index d0a97e5ea431..f8524f988bdc 100644 --- a/drivers/regulator/as3711-regulator.c +++ b/drivers/regulator/as3711-regulator.c @@ -117,23 +117,19 @@ static struct regulator_ops as3711_dldo_ops = { }; static const struct regulator_linear_range as3711_sd_ranges[] = { - { .min_uV = 612500, .min_sel = 0x1, .max_sel = 0x40, .uV_step = 12500 }, - { .min_uV = 1425000, .min_sel = 0x41, .max_sel = 0x70, - .uV_step = 25000 }, - { .min_uV = 2650000, .min_sel = 0x71, .max_sel = 0x7f, - .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(612500, 0x1, 0x40, 12500), + REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000), + REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7f, 50000), }; static const struct regulator_linear_range as3711_aldo_ranges[] = { - { .min_uV = 1200000, .min_sel = 0, .max_sel = 0xf, .uV_step = 50000 }, - { .min_uV = 1800000, .min_sel = 0x10, .max_sel = 0x1f, - .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(1200000, 0, 0xf, 50000), + REGULATOR_LINEAR_RANGE(1800000, 0x10, 0x1f, 100000), }; static const struct regulator_linear_range as3711_dldo_ranges[] = { - { .min_uV = 900000, .min_sel = 0, .max_sel = 0x10, .uV_step = 50000 }, - { .min_uV = 1750000, .min_sel = 0x20, .max_sel = 0x3f, - .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(900000, 0, 0x10, 50000), + REGULATOR_LINEAR_RANGE(1750000, 0x20, 0x3f, 50000), }; #define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \ diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index 240ae6d2ee2a..5917fe3dc983 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -435,17 +435,9 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .get_current_limit = as3722_ldo3_get_current_limit, }; -#define regulator_lin_range(_min_sel, _max_sel, _min_uV, _step_uV) \ - { \ - .min_sel = _min_sel, \ - .max_sel = _max_sel, \ - .uV_step = _step_uV, \ - .min_uV = _min_uV, \ - } - static const struct regulator_linear_range as3722_ldo_ranges[] = { - regulator_lin_range(0x01, 0x24, 825000, 25000), - regulator_lin_range(0x40, 0x7F, 1725000, 25000), + REGULATOR_LINEAR_RANGE(825000, 0x01, 0x24, 25000), + REGULATOR_LINEAR_RANGE(1725000, 0x40, 0x7F, 25000), }; static struct regulator_ops as3722_ldo_ops = { @@ -604,9 +596,9 @@ static int as3722_sd016_set_current_limit(struct regulator_dev *rdev, } static const struct regulator_linear_range as3722_sd2345_ranges[] = { - regulator_lin_range(0x01, 0x40, 612500, 12500), - regulator_lin_range(0x41, 0x70, 1425000, 25000), - regulator_lin_range(0x71, 0x7F, 2650000, 50000), + REGULATOR_LINEAR_RANGE(612500, 0x01, 0x40, 12500), + REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000), + REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7F, 50000), }; static struct regulator_ops as3722_sd016_ops = { diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index 90d55e066447..6d1b799ad86b 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c @@ -253,8 +253,8 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev, } static const struct regulator_linear_range da9034_ldo12_ranges[] = { - { .min_uV = 1700000, .min_sel = 0, .max_sel = 7, .uV_step = 50000 }, - { .min_uV = 2700000, .min_sel = 8, .max_sel = 15, .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(1700000, 0, 7, 50000), + REGULATOR_LINEAR_RANGE(2700000, 8, 15, 50000), }; static struct regulator_ops da903x_regulator_ldo_ops = { diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 484866f43681..bbc7277fa097 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c @@ -52,17 +52,17 @@ static const unsigned int LDO1_VSEL_table[] = { }; static const struct regulator_linear_range tps65217_uv1_ranges[] = { - { .min_uV = 900000, .min_sel = 0, .max_sel = 24, .uV_step = 25000 }, - { .min_uV = 1550000, .min_sel = 25, .max_sel = 30, .uV_step = 50000 }, - { .min_uV = 1850000, .min_sel = 31, .max_sel = 52, .uV_step = 50000 }, - { .min_uV = 3000000, .min_sel = 53, .max_sel = 55, .uV_step = 100000 }, - { .min_uV = 3300000, .min_sel = 56, .max_sel = 62, .uV_step = 0 }, + REGULATOR_LINEAR_RANGE(900000, 0, 24, 25000), + REGULATOR_LINEAR_RANGE(1550000, 25, 30, 50000), + REGULATOR_LINEAR_RANGE(1850000, 31, 52, 50000), + REGULATOR_LINEAR_RANGE(3000000, 53, 55, 100000), + REGULATOR_LINEAR_RANGE(3300000, 56, 62, 0), }; static const struct regulator_linear_range tps65217_uv2_ranges[] = { - { .min_uV = 1500000, .min_sel = 0, .max_sel = 8, .uV_step = 50000 }, - { .min_uV = 2000000, .min_sel = 9, .max_sel = 13, .uV_step = 100000 }, - { .min_uV = 2450000, .min_sel = 14, .max_sel = 31, .uV_step = 50000 }, + REGULATOR_LINEAR_RANGE(1500000, 0, 8, 50000), + REGULATOR_LINEAR_RANGE(2000000, 9, 13, 100000), + REGULATOR_LINEAR_RANGE(2450000, 14, 31, 50000), }; static int tps65217_pmic_enable(struct regulator_dev *dev) diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index 9fc87d8c9ce5..697eab8e74d8 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -119,9 +119,9 @@ struct tps65912_reg { }; static const struct regulator_linear_range tps65912_ldo_ranges[] = { - { .min_uV = 800000, .min_sel = 0, .max_sel = 32, .uV_step = 25000 }, - { .min_uV = 1650000, .min_sel = 33, .max_sel = 60, .uV_step = 50000 }, - { .min_uV = 3100000, .min_sel = 61, .max_sel = 63, .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(800000, 0, 32, 25000), + REGULATOR_LINEAR_RANGE(1650000, 33, 60, 50000), + REGULATOR_LINEAR_RANGE(3100000, 61, 63, 100000), }; static int tps65912_get_range(struct tps65912_reg *pmic, int id) diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index a95814027b24..9111b651c353 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c @@ -63,8 +63,8 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) */ static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = { - { .min_uV = 900000, .min_sel = 0, .max_sel = 14, .uV_step = 50000 }, - { .min_uV = 1700000, .min_sel = 15, .max_sel = 31, .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000), + REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000), }; static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, @@ -330,8 +330,8 @@ static struct platform_driver wm831x_gp_ldo_driver = { */ static const struct regulator_linear_range wm831x_aldo_ranges[] = { - { .min_uV = 1000000, .min_sel = 0, .max_sel = 12, .uV_step = 50000 }, - { .min_uV = 1700000, .min_sel = 13, .max_sel = 31, .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(1000000, 0, 12, 50000), + REGULATOR_LINEAR_RANGE(1700000, 13, 31, 100000), }; static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index de9de26d0bfc..3827539f3ad7 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -543,8 +543,8 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, } static const struct regulator_linear_range wm8350_ldo_ranges[] = { - { .min_uV = 900000, .min_sel = 0, .max_sel = 15, .uV_step = 50000 }, - { .min_uV = 1800000, .min_sel = 16, .max_sel = 31, .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(900000, 0, 15, 50000), + REGULATOR_LINEAR_RANGE(1800000, 16, 31, 100000), }; static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 3352b2090ed5..8eedba2953f9 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c @@ -20,8 +20,8 @@ #include static const struct regulator_linear_range wm8400_ldo_ranges[] = { - { .min_uV = 900000, .min_sel = 0, .max_sel = 14, .uV_step = 50000 }, - { .min_uV = 1700000, .min_sel = 15, .max_sel = 31, .uV_step = 100000 }, + REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000), + REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000), }; static struct regulator_ops wm8400_ldo_ops = { diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 997ff5c4d880..edb11b716dd3 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -57,6 +57,15 @@ struct regulator_linear_range { unsigned int uV_step; }; +/* Initialize struct regulator_linear_range */ +#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ +{ \ + .min_uV = _min_uV, \ + .min_sel = _min_sel, \ + .max_sel = _max_sel, \ + .uV_step = _step_uV, \ +} + /** * struct regulator_ops - regulator operations. * -- cgit v1.2.3 From a06ccd9c3785fa5550917ae036944f4e080b5749 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Tue, 15 Oct 2013 20:14:20 +0100 Subject: regulator: core: Add ability to create a lookup alias for supply These patches add the ability to create an alternative device on which a lookup for a certain supply should be conducted. A common use-case for this would be devices that are logically represented as a collection of drivers within Linux but are are presented as a single device from device tree. It this case it is necessary for each sub device to locate their supply data on the main device. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/core.c | 170 +++++++++++++++++++++++++++++++++++++ drivers/regulator/devres.c | 163 +++++++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 79 +++++++++++++++++ 3 files changed, 412 insertions(+) (limited to 'include') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 906deb7354ed..16427de56ce8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -53,6 +53,7 @@ static DEFINE_MUTEX(regulator_list_mutex); static LIST_HEAD(regulator_list); static LIST_HEAD(regulator_map_list); static LIST_HEAD(regulator_ena_gpio_list); +static LIST_HEAD(regulator_supply_alias_list); static bool has_full_constraints; static bool board_wants_dummy_regulator; @@ -83,6 +84,19 @@ struct regulator_enable_gpio { unsigned int ena_gpio_invert:1; }; +/* + * struct regulator_supply_alias + * + * Used to map lookups for a supply onto an alternative device. + */ +struct regulator_supply_alias { + struct list_head list; + struct device *src_dev; + const char *src_supply; + struct device *alias_dev; + const char *alias_supply; +}; + static int _regulator_is_enabled(struct regulator_dev *rdev); static int _regulator_disable(struct regulator_dev *rdev); static int _regulator_get_voltage(struct regulator_dev *rdev); @@ -1173,6 +1187,32 @@ static int _regulator_get_enable_time(struct regulator_dev *rdev) return rdev->desc->ops->enable_time(rdev); } +static struct regulator_supply_alias *regulator_find_supply_alias( + struct device *dev, const char *supply) +{ + struct regulator_supply_alias *map; + + list_for_each_entry(map, ®ulator_supply_alias_list, list) + if (map->src_dev == dev && strcmp(map->src_supply, supply) == 0) + return map; + + return NULL; +} + +static void regulator_supply_alias(struct device **dev, const char **supply) +{ + struct regulator_supply_alias *map; + + map = regulator_find_supply_alias(*dev, *supply); + if (map) { + dev_dbg(*dev, "Mapping supply %s to %s,%s\n", + *supply, map->alias_supply, + dev_name(map->alias_dev)); + *dev = map->alias_dev; + *supply = map->alias_supply; + } +} + static struct regulator_dev *regulator_dev_lookup(struct device *dev, const char *supply, int *ret) @@ -1182,6 +1222,8 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, struct regulator_map *map; const char *devname = NULL; + regulator_supply_alias(&dev, &supply); + /* first do a dt based lookup */ if (dev && dev->of_node) { node = of_get_regulator(dev, supply); @@ -1432,6 +1474,134 @@ void regulator_put(struct regulator *regulator) } EXPORT_SYMBOL_GPL(regulator_put); +/** + * regulator_register_supply_alias - Provide device alias for supply lookup + * + * @dev: device that will be given as the regulator "consumer" + * @id: Supply name or regulator ID + * @alias_dev: device that should be used to lookup the supply + * @alias_id: Supply name or regulator ID that should be used to lookup the + * supply + * + * All lookups for id on dev will instead be conducted for alias_id on + * alias_dev. + */ +int regulator_register_supply_alias(struct device *dev, const char *id, + struct device *alias_dev, + const char *alias_id) +{ + struct regulator_supply_alias *map; + + map = regulator_find_supply_alias(dev, id); + if (map) + return -EEXIST; + + map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL); + if (!map) + return -ENOMEM; + + map->src_dev = dev; + map->src_supply = id; + map->alias_dev = alias_dev; + map->alias_supply = alias_id; + + list_add(&map->list, ®ulator_supply_alias_list); + + pr_info("Adding alias for supply %s,%s -> %s,%s\n", + id, dev_name(dev), alias_id, dev_name(alias_dev)); + + return 0; +} +EXPORT_SYMBOL_GPL(regulator_register_supply_alias); + +/** + * regulator_unregister_supply_alias - Remove device alias + * + * @dev: device that will be given as the regulator "consumer" + * @id: Supply name or regulator ID + * + * Remove a lookup alias if one exists for id on dev. + */ +void regulator_unregister_supply_alias(struct device *dev, const char *id) +{ + struct regulator_supply_alias *map; + + map = regulator_find_supply_alias(dev, id); + if (map) { + list_del(&map->list); + kfree(map); + } +} +EXPORT_SYMBOL_GPL(regulator_unregister_supply_alias); + +/** + * regulator_bulk_register_supply_alias - register multiple aliases + * + * @dev: device that will be given as the regulator "consumer" + * @id: List of supply names or regulator IDs + * @alias_dev: device that should be used to lookup the supply + * @alias_id: List of supply names or regulator IDs that should be used to + * lookup the supply + * @num_id: Number of aliases to register + * + * @return 0 on success, an errno on failure. + * + * This helper function allows drivers to register several supply + * aliases in one operation. If any of the aliases cannot be + * registered any aliases that were registered will be removed + * before returning to the caller. + */ +int regulator_bulk_register_supply_alias(struct device *dev, const char **id, + struct device *alias_dev, + const char **alias_id, + int num_id) +{ + int i; + int ret; + + for (i = 0; i < num_id; ++i) { + ret = regulator_register_supply_alias(dev, id[i], alias_dev, + alias_id[i]); + if (ret < 0) + goto err; + } + + return 0; + +err: + dev_err(dev, + "Failed to create supply alias %s,%s -> %s,%s\n", + id[i], dev_name(dev), alias_id[i], dev_name(alias_dev)); + + while (--i >= 0) + regulator_unregister_supply_alias(dev, id[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(regulator_bulk_register_supply_alias); + +/** + * regulator_bulk_unregister_supply_alias - unregister multiple aliases + * + * @dev: device that will be given as the regulator "consumer" + * @id: List of supply names or regulator IDs + * @num_id: Number of aliases to unregister + * + * This helper function allows drivers to unregister several supply + * aliases in one operation. + */ +void regulator_bulk_unregister_supply_alias(struct device *dev, + const char **id, + int num_id) +{ + int i; + + for (i = 0; i < num_id; ++i) + regulator_unregister_supply_alias(dev, id[i]); +} +EXPORT_SYMBOL_GPL(regulator_bulk_unregister_supply_alias); + + /* Manage enable GPIO list. Same GPIO pin can be shared among regulators */ static int regulator_ena_gpio_request(struct regulator_dev *rdev, const struct regulator_config *config) diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 2672a029fa25..f44818b838dc 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -250,3 +250,166 @@ void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev) WARN_ON(rc); } EXPORT_SYMBOL_GPL(devm_regulator_unregister); + +struct regulator_supply_alias_match { + struct device *dev; + const char *id; +}; + +static int devm_regulator_match_supply_alias(struct device *dev, void *res, + void *data) +{ + struct regulator_supply_alias_match *match = res; + struct regulator_supply_alias_match *target = data; + + return match->dev == target->dev && strcmp(match->id, target->id) == 0; +} + +static void devm_regulator_destroy_supply_alias(struct device *dev, void *res) +{ + struct regulator_supply_alias_match *match = res; + + regulator_unregister_supply_alias(match->dev, match->id); +} + +/** + * devm_regulator_register_supply_alias - Resource managed + * regulator_register_supply_alias() + * + * @dev: device that will be given as the regulator "consumer" + * @id: Supply name or regulator ID + * @alias_dev: device that should be used to lookup the supply + * @alias_id: Supply name or regulator ID that should be used to lookup the + * supply + * + * The supply alias will automatically be unregistered when the source + * device is unbound. + */ +int devm_regulator_register_supply_alias(struct device *dev, const char *id, + struct device *alias_dev, + const char *alias_id) +{ + struct regulator_supply_alias_match *match; + int ret; + + match = devres_alloc(devm_regulator_destroy_supply_alias, + sizeof(struct regulator_supply_alias_match), + GFP_KERNEL); + if (!match) + return -ENOMEM; + + match->dev = dev; + match->id = id; + + ret = regulator_register_supply_alias(dev, id, alias_dev, alias_id); + if (ret < 0) { + devres_free(match); + return ret; + } + + devres_add(dev, match); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_regulator_register_supply_alias); + +/** + * devm_regulator_unregister_supply_alias - Resource managed + * regulator_unregister_supply_alias() + * + * @dev: device that will be given as the regulator "consumer" + * @id: Supply name or regulator ID + * + * Unregister an alias registered with + * devm_regulator_register_supply_alias(). Normally this function + * will not need to be called and the resource management code + * will ensure that the resource is freed. + */ +void devm_regulator_unregister_supply_alias(struct device *dev, const char *id) +{ + struct regulator_supply_alias_match match; + int rc; + + match.dev = dev; + match.id = id; + + rc = devres_release(dev, devm_regulator_destroy_supply_alias, + devm_regulator_match_supply_alias, &match); + if (rc != 0) + WARN_ON(rc); +} +EXPORT_SYMBOL_GPL(devm_regulator_unregister_supply_alias); + +/** + * devm_regulator_bulk_register_supply_alias - Managed register + * multiple aliases + * + * @dev: device that will be given as the regulator "consumer" + * @id: List of supply names or regulator IDs + * @alias_dev: device that should be used to lookup the supply + * @alias_id: List of supply names or regulator IDs that should be used to + * lookup the supply + * @num_id: Number of aliases to register + * + * @return 0 on success, an errno on failure. + * + * This helper function allows drivers to register several supply + * aliases in one operation, the aliases will be automatically + * unregisters when the source device is unbound. If any of the + * aliases cannot be registered any aliases that were registered + * will be removed before returning to the caller. + */ +int devm_regulator_bulk_register_supply_alias(struct device *dev, + const char **id, + struct device *alias_dev, + const char **alias_id, + int num_id) +{ + int i; + int ret; + + for (i = 0; i < num_id; ++i) { + ret = devm_regulator_register_supply_alias(dev, id[i], + alias_dev, + alias_id[i]); + if (ret < 0) + goto err; + } + + return 0; + +err: + dev_err(dev, + "Failed to create supply alias %s,%s -> %s,%s\n", + id[i], dev_name(dev), alias_id[i], dev_name(alias_dev)); + + while (--i >= 0) + devm_regulator_unregister_supply_alias(dev, id[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_regulator_bulk_register_supply_alias); + +/** + * devm_regulator_bulk_unregister_supply_alias - Managed unregister + * multiple aliases + * + * @dev: device that will be given as the regulator "consumer" + * @id: List of supply names or regulator IDs + * @num_id: Number of aliases to unregister + * + * Unregister aliases registered with + * devm_regulator_bulk_register_supply_alias(). Normally this function + * will not need to be called and the resource management code + * will ensure that the resource is freed. + */ +void devm_regulator_bulk_unregister_supply_alias(struct device *dev, + const char **id, + int num_id) +{ + int i; + + for (i = 0; i < num_id; ++i) + devm_regulator_unregister_supply_alias(dev, id[i]); +} +EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias); diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 27be915caa96..e530681bea70 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -146,6 +146,32 @@ struct regulator *__must_check devm_regulator_get_optional(struct device *dev, void regulator_put(struct regulator *regulator); void devm_regulator_put(struct regulator *regulator); +int regulator_register_supply_alias(struct device *dev, const char *id, + struct device *alias_dev, + const char *alias_id); +void regulator_unregister_supply_alias(struct device *dev, const char *id); + +int regulator_bulk_register_supply_alias(struct device *dev, const char **id, + struct device *alias_dev, + const char **alias_id, int num_id); +void regulator_bulk_unregister_supply_alias(struct device *dev, + const char **id, int num_id); + +int devm_regulator_register_supply_alias(struct device *dev, const char *id, + struct device *alias_dev, + const char *alias_id); +void devm_regulator_unregister_supply_alias(struct device *dev, + const char *id); + +int devm_regulator_bulk_register_supply_alias(struct device *dev, + const char **id, + struct device *alias_dev, + const char **alias_id, + int num_id); +void devm_regulator_bulk_unregister_supply_alias(struct device *dev, + const char **id, + int num_id); + /* regulator output control and status */ int __must_check regulator_enable(struct regulator *regulator); int regulator_disable(struct regulator *regulator); @@ -250,6 +276,59 @@ static inline void devm_regulator_put(struct regulator *regulator) { } +static inline int regulator_register_supply_alias(struct device *dev, + const char *id, + struct device *alias_dev, + const char *alias_id) +{ + return 0; +} + +static inline void regulator_unregister_supply_alias(struct device *dev, + const char *id) +{ +} + +static inline int regulator_bulk_register_supply_alias(struct device *dev, + const char **id, + struct device *alias_dev, + const char **alias_id, + int num_id) +{ + return 0; +} + +static inline void regulator_bulk_unregister_supply_alias(struct device *dev, + const char **id, + int num_id) +{ +} + +static inline int devm_regulator_register_supply_alias(struct device *dev, + const char *id, + struct device *alias_dev, + const char *alias_id) +{ + return 0; +} + +static inline void devm_regulator_unregister_supply_alias(struct device *dev, + const char *id) +{ +} + +static inline int devm_regulator_bulk_register_supply_alias( + struct device *dev, const char **id, struct device *alias_dev, + const char **alias_id, int num_id) +{ + return 0; +} + +static inline void devm_regulator_bulk_unregister_supply_alias( + struct device *dev, const char **id, int num_id) +{ +} + static inline int regulator_enable(struct regulator *regulator) { return 0; -- cgit v1.2.3 From 7fcd427465e710d0c4e2737d2f02b2ffa14b9bb3 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Tue, 15 Oct 2013 20:14:21 +0100 Subject: mfd: Allow mapping regulator supplies to MFD device from children Occasionally, it is useful to map supplies from a child device onto the MFD device. A typical usecase for this would be if the MFD device is represented as a single node in device tree. All supplies will be defined in device tree as existing on the MFD device. When a child depends on frameworks which might have no knowledge of MFD to lookup supplies on its behalf the supply will not be found. This patch adds a list of supplies that should be looked up on the parent rather than the child as part of the mfd_cell structure. Signed-off-by: Charles Keepax Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/mfd/mfd-core.c | 22 +++++++++++++++++----- include/linux/mfd/core.h | 6 ++++++ 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index f421586f29fb..adc8ea36e7c4 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -20,6 +20,7 @@ #include #include #include +#include static struct device_type mfd_dev_type = { .name = "mfd_device", @@ -99,6 +100,13 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.dma_mask = parent->dma_mask; pdev->dev.dma_parms = parent->dma_parms; + ret = devm_regulator_bulk_register_supply_alias( + &pdev->dev, cell->parent_supplies, + parent, cell->parent_supplies, + cell->num_parent_supplies); + if (ret < 0) + goto fail_res; + if (parent->of_node && cell->of_compatible) { for_each_child_of_node(parent->of_node, np) { if (of_device_is_compatible(np, cell->of_compatible)) { @@ -112,12 +120,12 @@ static int mfd_add_device(struct device *parent, int id, ret = platform_device_add_data(pdev, cell->platform_data, cell->pdata_size); if (ret) - goto fail_res; + goto fail_alias; } ret = mfd_platform_add_cell(pdev, cell); if (ret) - goto fail_res; + goto fail_alias; for (r = 0; r < cell->num_resources; r++) { res[r].name = cell->resources[r].name; @@ -152,17 +160,17 @@ static int mfd_add_device(struct device *parent, int id, if (!cell->ignore_resource_conflicts) { ret = acpi_check_resource_conflict(&res[r]); if (ret) - goto fail_res; + goto fail_alias; } } ret = platform_device_add_resources(pdev, res, cell->num_resources); if (ret) - goto fail_res; + goto fail_alias; ret = platform_device_add(pdev); if (ret) - goto fail_res; + goto fail_alias; if (cell->pm_runtime_no_callbacks) pm_runtime_no_callbacks(&pdev->dev); @@ -171,6 +179,10 @@ static int mfd_add_device(struct device *parent, int id, return 0; +fail_alias: + devm_regulator_bulk_unregister_supply_alias(&pdev->dev, + cell->parent_supplies, + cell->num_parent_supplies); fail_res: kfree(res); fail_device: diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h index cebe97ee98b8..7314fc4e6d25 100644 --- a/include/linux/mfd/core.h +++ b/include/linux/mfd/core.h @@ -59,6 +59,12 @@ struct mfd_cell { * pm_runtime_no_callbacks(). */ bool pm_runtime_no_callbacks; + + /* A list of regulator supplies that should be mapped to the MFD + * device rather than the child device when requested + */ + const char **parent_supplies; + int num_parent_supplies; }; /* -- cgit v1.2.3