From 74b060d6845f09a5b2db6df653a3c0e90d4fa560 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 10 Mar 2019 23:06:09 +0800 Subject: regulator: palmas: Remove *rdev[PALMAS_NUM_REGS] from struct palmas_pmic This driver is using devm_regulator_register() so it is not necessary to save *rdev for clean up. Actually the pmic->rdev[id] is not used now. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/palmas-regulator.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index 7fb9e8dd834e..f13c7c8b1061 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c @@ -991,9 +991,6 @@ static int palmas_ldo_registration(struct palmas_pmic *pmic, return PTR_ERR(rdev); } - /* Save regulator for cleanup */ - pmic->rdev[id] = rdev; - /* Initialise sleep/init values from platform data */ if (pdata) { reg_init = pdata->reg_init[id]; @@ -1101,9 +1098,6 @@ static int tps65917_ldo_registration(struct palmas_pmic *pmic, return PTR_ERR(rdev); } - /* Save regulator for cleanup */ - pmic->rdev[id] = rdev; - /* Initialise sleep/init values from platform data */ if (pdata) { reg_init = pdata->reg_init[id]; @@ -1288,9 +1282,6 @@ static int palmas_smps_registration(struct palmas_pmic *pmic, pdev_name); return PTR_ERR(rdev); } - - /* Save regulator for cleanup */ - pmic->rdev[id] = rdev; } return 0; @@ -1395,9 +1386,6 @@ static int tps65917_smps_registration(struct palmas_pmic *pmic, pdev_name); return PTR_ERR(rdev); } - - /* Save regulator for cleanup */ - pmic->rdev[id] = rdev; } return 0; -- cgit v1.2.3 From 5b60ee576a02cb6b2371dec085ef2623a7df77b9 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 7 Mar 2019 21:53:56 +0800 Subject: regulator: ab3100: Remove ab3100_regulators_remove function Current code is using devm_regulator_register() so it is not necessary to save reg->rdev for clean up. Remove *rdev from struct ab3100_regulator, then ab3100_regulators_remove() can be removed as well. Signed-off-by: Axel Lin Reviewed-by: Linus Walleij Signed-off-by: Mark Brown --- drivers/regulator/ab3100.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index de2644490f0d..c92966a79a7e 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c @@ -48,7 +48,6 @@ * @regreg: regulator register number in the AB3100 */ struct ab3100_regulator { - struct regulator_dev *rdev; struct device *dev; struct ab3100_platform_data *plfdata; u8 regreg; @@ -545,8 +544,6 @@ static int ab3100_regulator_register(struct platform_device *pdev, return err; } - /* Then set a pointer back to the registered regulator */ - reg->rdev = rdev; return 0; } @@ -609,18 +606,6 @@ static const u8 ab3100_reg_initvals[] = { LDO_D_SETTING, }; -static int ab3100_regulators_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < AB3100_NUM_REGULATORS; i++) { - struct ab3100_regulator *reg = &ab3100_regulators[i]; - - reg->rdev = NULL; - } - return 0; -} - static int ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np) { @@ -647,10 +632,8 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np) pdev, NULL, ab3100_regulator_matches[i].init_data, ab3100_regulator_matches[i].of_node, (unsigned long)ab3100_regulator_matches[i].driver_data); - if (err) { - ab3100_regulators_remove(pdev); + if (err) return err; - } } return 0; @@ -709,10 +692,8 @@ static int ab3100_regulators_probe(struct platform_device *pdev) err = ab3100_regulator_register(pdev, plfdata, NULL, NULL, desc->id); - if (err) { - ab3100_regulators_remove(pdev); + if (err) return err; - } } return 0; @@ -723,7 +704,6 @@ static struct platform_driver ab3100_regulators_driver = { .name = "ab3100-regulators", }, .probe = ab3100_regulators_probe, - .remove = ab3100_regulators_remove, }; static __init int ab3100_regulators_init(void) -- cgit v1.2.3 From e08abeca39673e1045ca1e5a90bd7fef69d0fe8f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 27 Feb 2019 09:30:53 +0800 Subject: regulator: wm8400: Get rid of wm8400_block_read/wm8400_set_bits functions The only user of wm8400_block_read/wm8400_set_bits functions is the wm8400 regulator driver. At the context of all the callers, we can use regmap_bulk_read/regmap_update_bits directly. Thus remove wm8400_block_read/wm8400_set_bits functions. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm8400-regulator.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index fb1837657b64..40c4e6628471 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c @@ -36,13 +36,12 @@ static const struct regulator_ops wm8400_ldo_ops = { static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) { - struct wm8400 *wm8400 = rdev_get_drvdata(dev); + struct regmap *rmap = rdev_get_regmap(dev); int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; u16 data[2]; int ret; - ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2, - data); + ret = regmap_bulk_read(rmap, WM8400_DCDC1_CONTROL_1 + offset, data, 2); if (ret != 0) return 0; @@ -63,36 +62,36 @@ static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode) { - struct wm8400 *wm8400 = rdev_get_drvdata(dev); + struct regmap *rmap = rdev_get_regmap(dev); int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; int ret; switch (mode) { case REGULATOR_MODE_FAST: /* Datasheet: active with force PWM */ - ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset, + ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset, WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM); if (ret != 0) return ret; - return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, + return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset, WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, WM8400_DC1_ACTIVE); case REGULATOR_MODE_NORMAL: /* Datasheet: active */ - ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset, + ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset, WM8400_DC1_FRC_PWM, 0); if (ret != 0) return ret; - return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, + return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset, WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, WM8400_DC1_ACTIVE); case REGULATOR_MODE_IDLE: /* Datasheet: standby */ - return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, + return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset, WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0); default: return -EINVAL; -- cgit v1.2.3 From 178d08ea81b1538ea0b2c432a3ddda53b7fec296 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 27 Feb 2019 13:54:21 +0800 Subject: regulator: wm8400: Fix trivial typo Use WM8400_DC2_ENA_MASK for DCDC2 enable_mask. The define is the same as WM8400_DC1_ENA_MASK, just a cleanup. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm8400-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 40c4e6628471..5ce86b92851b 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c @@ -194,7 +194,7 @@ static struct regulator_desc regulators[] = { .id = WM8400_DCDC2, .ops = &wm8400_dcdc_ops, .enable_reg = WM8400_DCDC2_CONTROL_1, - .enable_mask = WM8400_DC1_ENA_MASK, + .enable_mask = WM8400_DC2_ENA_MASK, .n_voltages = WM8400_DC2_VSEL_MASK + 1, .vsel_reg = WM8400_DCDC2_CONTROL_1, .vsel_mask = WM8400_DC2_VSEL_MASK, -- cgit v1.2.3 From 7cdc2ee7bf10705f737c22dcd4b002b87849badb Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 8 Mar 2019 14:15:28 +0800 Subject: regulator: gpio: Convert to devm_regulator_register Use devm_regulator_register to simplify the code. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/gpio-regulator.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 6157001df0a4..967338bf1dc1 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -36,7 +36,6 @@ struct gpio_regulator_data { struct regulator_desc desc; - struct regulator_dev *dev; struct gpio_desc **gpiods; int nr_gpios; @@ -233,6 +232,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct gpio_regulator_data *drvdata; struct regulator_config cfg = { }; + struct regulator_dev *rdev; enum gpiod_flags gflags; int ptr, ret, state, i; @@ -326,9 +326,9 @@ static int gpio_regulator_probe(struct platform_device *pdev) if (IS_ERR(cfg.ena_gpiod)) return PTR_ERR(cfg.ena_gpiod); - drvdata->dev = regulator_register(&drvdata->desc, &cfg); - if (IS_ERR(drvdata->dev)) { - ret = PTR_ERR(drvdata->dev); + rdev = devm_regulator_register(dev, &drvdata->desc, &cfg); + if (IS_ERR(rdev)) { + ret = PTR_ERR(rdev); dev_err(dev, "Failed to register regulator: %d\n", ret); return ret; } @@ -338,15 +338,6 @@ static int gpio_regulator_probe(struct platform_device *pdev) return 0; } -static int gpio_regulator_remove(struct platform_device *pdev) -{ - struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev); - - regulator_unregister(drvdata->dev); - - return 0; -} - #if defined(CONFIG_OF) static const struct of_device_id regulator_gpio_of_match[] = { { .compatible = "regulator-gpio", }, @@ -357,7 +348,6 @@ MODULE_DEVICE_TABLE(of, regulator_gpio_of_match); static struct platform_driver gpio_regulator_driver = { .probe = gpio_regulator_probe, - .remove = gpio_regulator_remove, .driver = { .name = "gpio-regulator", .of_match_table = of_match_ptr(regulator_gpio_of_match), -- cgit v1.2.3 From 705e2a905a0407c3fffb248b43c8d7d1de6b4e51 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 8 Mar 2019 14:15:29 +0800 Subject: regulator: gpio: Constify regulator_ops gpio_regulator_voltage_ops and gpio_regulator_current_ops should never change, make them const. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/gpio-regulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 967338bf1dc1..f50d86a66138 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -124,7 +124,7 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev, return 0; } -static struct regulator_ops gpio_regulator_voltage_ops = { +static const struct regulator_ops gpio_regulator_voltage_ops = { .get_voltage = gpio_regulator_get_value, .set_voltage = gpio_regulator_set_voltage, .list_voltage = gpio_regulator_list_voltage, @@ -220,7 +220,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, return config; } -static struct regulator_ops gpio_regulator_current_ops = { +static const struct regulator_ops gpio_regulator_current_ops = { .get_current_limit = gpio_regulator_get_value, .set_current_limit = gpio_regulator_set_current_limit, }; -- cgit v1.2.3 From 5e6afb3832bedf420dd8e4c5b32ed85117c5087d Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 14:59:59 +0000 Subject: regulator: da9055: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: f6130be652d0 ("regulator: DA9055 regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 3c6fac793658..3ade4b8d204e 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -487,8 +487,10 @@ static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data) { struct da9055_regulator *regulator = data; + regulator_lock(regulator->rdev); regulator_notifier_call_chain(regulator->rdev, REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(regulator->rdev); return IRQ_HANDLED; } -- cgit v1.2.3 From 978995def0f6030aa6b3b494682f673aca13881b Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:19:34 +0000 Subject: regulator: da9062: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 4068e5182ada ("regulator: da9062: DA9062 regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/da9062-regulator.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c index b064d8a19d4c..bab88ddfc509 100644 --- a/drivers/regulator/da9062-regulator.c +++ b/drivers/regulator/da9062-regulator.c @@ -974,8 +974,10 @@ static irqreturn_t da9062_ldo_lim_event(int irq, void *data) continue; if (BIT(regl->info->oc_event.lsb) & bits) { + regulator_lock(regl->rdev); regulator_notifier_call_chain(regl->rdev, REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(regl->rdev); handled = IRQ_HANDLED; } } -- cgit v1.2.3 From 1867af94cfdf37fc70fe67b3d522e78352800196 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:44:54 +0000 Subject: regulator: pv88080: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 99cf3af5e2d5 ("regulator: pv88080: new regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/pv88080-regulator.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/pv88080-regulator.c b/drivers/regulator/pv88080-regulator.c index bdddacdbeb99..6279216fb254 100644 --- a/drivers/regulator/pv88080-regulator.c +++ b/drivers/regulator/pv88080-regulator.c @@ -345,9 +345,11 @@ static irqreturn_t pv88080_irq_handler(int irq, void *data) if (reg_val & PV88080_E_VDD_FLT) { for (i = 0; i < PV88080_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + regulator_unlock(chip->rdev[i]); } } @@ -362,9 +364,11 @@ static irqreturn_t pv88080_irq_handler(int irq, void *data) if (reg_val & PV88080_E_OVER_TEMP) { for (i = 0; i < PV88080_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_OVER_TEMP, NULL); + regulator_unlock(chip->rdev[i]); } } -- cgit v1.2.3 From 275513b7695a61b75b2546406ecd0f8e3d9fc8be Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:46:55 +0000 Subject: regulator: pv88090: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: c90456e36d9c ("regulator: pv88090: new regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/pv88090-regulator.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/pv88090-regulator.c b/drivers/regulator/pv88090-regulator.c index 6e97cc6df2ee..90f4f907fb3f 100644 --- a/drivers/regulator/pv88090-regulator.c +++ b/drivers/regulator/pv88090-regulator.c @@ -237,9 +237,11 @@ static irqreturn_t pv88090_irq_handler(int irq, void *data) if (reg_val & PV88090_E_VDD_FLT) { for (i = 0; i < PV88090_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + regulator_unlock(chip->rdev[i]); } } @@ -254,9 +256,11 @@ static irqreturn_t pv88090_irq_handler(int irq, void *data) if (reg_val & PV88090_E_OVER_TEMP) { for (i = 0; i < PV88090_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_OVER_TEMP, NULL); + regulator_unlock(chip->rdev[i]); } } -- cgit v1.2.3 From 119c4f5085c45b60cb23c5595e45d06135b89518 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:48:46 +0000 Subject: regulator: wm831x: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: e4ee831f949a ("regulator: Add WM831x DC-DC buck convertor support") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm831x-dcdc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 12b422373580..d1873f94bca7 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c @@ -183,9 +183,11 @@ static irqreturn_t wm831x_dcdc_uv_irq(int irq, void *data) { struct wm831x_dcdc *dcdc = data; + regulator_lock(dcdc->regulator); regulator_notifier_call_chain(dcdc->regulator, REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + regulator_unlock(dcdc->regulator); return IRQ_HANDLED; } @@ -194,9 +196,11 @@ static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data) { struct wm831x_dcdc *dcdc = data; + regulator_lock(dcdc->regulator); regulator_notifier_call_chain(dcdc->regulator, REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(dcdc->regulator); return IRQ_HANDLED; } -- cgit v1.2.3 From 29d40b4a5776ec4727c9f0e00a884423dd5e3366 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:23:02 +0000 Subject: regulator: da9063: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 69ca3e58d178 ("regulator: da9063: Add Dialog DA9063 voltage regulators support.") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/da9063-regulator.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c index 2b0c7a85306a..d7bdb95b7602 100644 --- a/drivers/regulator/da9063-regulator.c +++ b/drivers/regulator/da9063-regulator.c @@ -615,9 +615,12 @@ static irqreturn_t da9063_ldo_lim_event(int irq, void *data) if (regl->info->oc_event.reg != DA9063_REG_STATUS_D) continue; - if (BIT(regl->info->oc_event.lsb) & bits) + if (BIT(regl->info->oc_event.lsb) & bits) { + regulator_lock(regl->rdev); regulator_notifier_call_chain(regl->rdev, REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(regl->rdev); + } } return IRQ_HANDLED; -- cgit v1.2.3 From 65378de3359d30ebce44762d8b8027f372b5b1c4 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:27:57 +0000 Subject: regulator: da9211: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 1028a37daa14 ("regulator: da9211: new regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/da9211-regulator.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c index 109ee12d4362..4d7fe4819c1c 100644 --- a/drivers/regulator/da9211-regulator.c +++ b/drivers/regulator/da9211-regulator.c @@ -322,8 +322,10 @@ static irqreturn_t da9211_irq_handler(int irq, void *data) goto error_i2c; if (reg_val & DA9211_E_OV_CURR_A) { + regulator_lock(chip->rdev[0]); regulator_notifier_call_chain(chip->rdev[0], REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(chip->rdev[0]); err = regmap_write(chip->regmap, DA9211_REG_EVENT_B, DA9211_E_OV_CURR_A); @@ -334,8 +336,10 @@ static irqreturn_t da9211_irq_handler(int irq, void *data) } if (reg_val & DA9211_E_OV_CURR_B) { + regulator_lock(chip->rdev[1]); regulator_notifier_call_chain(chip->rdev[1], REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(chip->rdev[1]); err = regmap_write(chip->regmap, DA9211_REG_EVENT_B, DA9211_E_OV_CURR_B); -- cgit v1.2.3 From 89b2758c192c35068b07766a6830433bfbdc1f44 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:32:18 +0000 Subject: regulator: lp8755: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: b59320cc5a5e ("regulator: lp8755: new driver for LP8755") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/lp8755.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/lp8755.c b/drivers/regulator/lp8755.c index 14fd38807134..2e16a6ab491d 100644 --- a/drivers/regulator/lp8755.c +++ b/drivers/regulator/lp8755.c @@ -372,10 +372,13 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) if ((flag0 & (0x4 << icnt)) && (pchip->irqmask & (0x04 << icnt)) - && (pchip->rdev[icnt] != NULL)) + && (pchip->rdev[icnt] != NULL)) { + regulator_lock(pchip->rdev[icnt]); regulator_notifier_call_chain(pchip->rdev[icnt], LP8755_EVENT_PWR_FAULT, NULL); + regulator_unlock(pchip->rdev[icnt]); + } /* read flag1 register */ ret = lp8755_read(pchip, 0x0E, &flag1); @@ -389,18 +392,24 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) /* send OCP event to all regulator devices */ if ((flag1 & 0x01) && (pchip->irqmask & 0x01)) for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) - if (pchip->rdev[icnt] != NULL) + if (pchip->rdev[icnt] != NULL) { + regulator_lock(pchip->rdev[icnt]); regulator_notifier_call_chain(pchip->rdev[icnt], LP8755_EVENT_OCP, NULL); + regulator_unlock(pchip->rdev[icnt]); + } /* send OVP event to all regulator devices */ if ((flag1 & 0x02) && (pchip->irqmask & 0x02)) for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) - if (pchip->rdev[icnt] != NULL) + if (pchip->rdev[icnt] != NULL) { + regulator_lock(pchip->rdev[icnt]); regulator_notifier_call_chain(pchip->rdev[icnt], LP8755_EVENT_OVP, NULL); + regulator_unlock(pchip->rdev[icnt]); + } return IRQ_HANDLED; err_i2c: -- cgit v1.2.3 From f132da2534ec6599c78c4adcef15340cff2e9dd9 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:35:35 +0000 Subject: regulator: ltc3589: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 3eb2c7ecb7ea ("regulator: Add LTC3589 support") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/ltc3589.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c index 63f724f260ef..75089b037b72 100644 --- a/drivers/regulator/ltc3589.c +++ b/drivers/regulator/ltc3589.c @@ -419,16 +419,22 @@ static irqreturn_t ltc3589_isr(int irq, void *dev_id) if (irqstat & LTC3589_IRQSTAT_THERMAL_WARN) { event = REGULATOR_EVENT_OVER_TEMP; - for (i = 0; i < LTC3589_NUM_REGULATORS; i++) + for (i = 0; i < LTC3589_NUM_REGULATORS; i++) { + regulator_lock(ltc3589->regulators[i]); regulator_notifier_call_chain(ltc3589->regulators[i], event, NULL); + regulator_unlock(ltc3589->regulators[i]); + } } if (irqstat & LTC3589_IRQSTAT_UNDERVOLT_WARN) { event = REGULATOR_EVENT_UNDER_VOLTAGE; - for (i = 0; i < LTC3589_NUM_REGULATORS; i++) + for (i = 0; i < LTC3589_NUM_REGULATORS; i++) { + regulator_lock(ltc3589->regulators[i]); regulator_notifier_call_chain(ltc3589->regulators[i], event, NULL); + regulator_unlock(ltc3589->regulators[i]); + } } /* Clear warning condition */ -- cgit v1.2.3 From 769fc8d4182c1d1875db7859852afeb436714c5c Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:38:56 +0000 Subject: regulator: ltc3676: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: 37b918a034fe ("regulator: Add LTC3676 support") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/ltc3676.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ltc3676.c b/drivers/regulator/ltc3676.c index e6d66e492b85..4be90c78c720 100644 --- a/drivers/regulator/ltc3676.c +++ b/drivers/regulator/ltc3676.c @@ -285,17 +285,23 @@ static irqreturn_t ltc3676_isr(int irq, void *dev_id) if (irqstat & LTC3676_IRQSTAT_THERMAL_WARN) { dev_warn(dev, "Over-temperature Warning\n"); event = REGULATOR_EVENT_OVER_TEMP; - for (i = 0; i < LTC3676_NUM_REGULATORS; i++) + for (i = 0; i < LTC3676_NUM_REGULATORS; i++) { + regulator_lock(ltc3676->regulators[i]); regulator_notifier_call_chain(ltc3676->regulators[i], event, NULL); + regulator_unlock(ltc3676->regulators[i]); + } } if (irqstat & LTC3676_IRQSTAT_UNDERVOLT_WARN) { dev_info(dev, "Undervoltage Warning\n"); event = REGULATOR_EVENT_UNDER_VOLTAGE; - for (i = 0; i < LTC3676_NUM_REGULATORS; i++) + for (i = 0; i < LTC3676_NUM_REGULATORS; i++) { + regulator_lock(ltc3676->regulators[i]); regulator_notifier_call_chain(ltc3676->regulators[i], event, NULL); + regulator_unlock(ltc3676->regulators[i]); + } } /* Clear warning condition */ -- cgit v1.2.3 From f58213637206e190453e3bd91f98f535566290a3 Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:42:50 +0000 Subject: regulator: pv88060: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: f307a7e9b7af ("regulator: pv88060: new regulator driver") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/pv88060-regulator.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/pv88060-regulator.c b/drivers/regulator/pv88060-regulator.c index 1600f9821891..810816e9df5d 100644 --- a/drivers/regulator/pv88060-regulator.c +++ b/drivers/regulator/pv88060-regulator.c @@ -244,9 +244,11 @@ static irqreturn_t pv88060_irq_handler(int irq, void *data) if (reg_val & PV88060_E_VDD_FLT) { for (i = 0; i < PV88060_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + regulator_unlock(chip->rdev[i]); } } @@ -261,9 +263,11 @@ static irqreturn_t pv88060_irq_handler(int irq, void *data) if (reg_val & PV88060_E_OVER_TEMP) { for (i = 0; i < PV88060_MAX_REGULATORS; i++) { if (chip->rdev[i] != NULL) { + regulator_lock(chip->rdev[i]); regulator_notifier_call_chain(chip->rdev[i], REGULATOR_EVENT_OVER_TEMP, NULL); + regulator_unlock(chip->rdev[i]); } } -- cgit v1.2.3 From 0077aaaeeb69b5dcfe15a398e38d71bf28c9505d Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 7 Mar 2019 11:26:02 +0100 Subject: regulator: da903x: don't build with clang The da903x driver produces an annoying false-positive warning when built with clang: drivers/regulator/da903x.c:395:2: error: division by zero is undefined [-Werror,-Wdivision-by-zero] DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */ ^ ~ drivers/regulator/da903x.c:359:2: note: expanded from macro 'DA9030_LDO' DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit) ^ ~~~~ drivers/regulator/da903x.c:320:39: note: expanded from macro 'DA903x_LDO' .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ ^ ~~~~ drivers/regulator/da903x.c:415:2: error: division by zero is undefined [-Werror,-Wdivision-by-zero] DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */ ^ ~ drivers/regulator/da903x.c:356:2: note: expanded from macro 'DA9034_LDO' DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit) ^ ~~~~ drivers/regulator/da903x.c:320:39: note: expanded from macro 'DA903x_LDO' .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ ^ ~~~~ I already reported this as a bug in clang, but it may take a while to fix it. As I have not been able to come up with any reasonable workaround, I would just disable compilation here. Link: https://bugs.llvm.org/show_bug.cgi?id=38789 Signed-off-by: Arnd Bergmann Reviewed-by: Nick Desaulniers Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index b7f249ee5e68..6d2651cd9887 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -223,6 +223,7 @@ config REGULATOR_CPCAP config REGULATOR_DA903X tristate "Dialog Semiconductor DA9030/DA9034 regulators" depends on PMIC_DA903X + depends on !CC_IS_CLANG # https://bugs.llvm.org/show_bug.cgi?id=38789 help Say y here to support the BUCKs and LDOs regulators found on Dialog Semiconductor DA9030/DA9034 PMIC. -- cgit v1.2.3 From ae15c519a6b97fff087cf69502bdf8fc8892f4be Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 12 Mar 2019 23:52:41 +0800 Subject: regulator: max14577: Get rid of match_init_data/match_of_node functions This driver has been converted to use regulator core's simplified DT parsing code. So the match_init_data/match_of_node functions are not necessary now, remove them. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/max14577-regulator.c | 55 ---------------------------------- 1 file changed, 55 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/max14577-regulator.c b/drivers/regulator/max14577-regulator.c index 85a88a9e4d42..07a150c9bbf2 100644 --- a/drivers/regulator/max14577-regulator.c +++ b/drivers/regulator/max14577-regulator.c @@ -155,58 +155,6 @@ static const struct regulator_desc max77836_supported_regulators[] = { [MAX77836_LDO2] = MAX77836_LDO_REG(2), }; -#ifdef CONFIG_OF -static struct of_regulator_match max14577_regulator_matches[] = { - { .name = "SAFEOUT", }, - { .name = "CHARGER", }, -}; - -static struct of_regulator_match max77836_regulator_matches[] = { - { .name = "SAFEOUT", }, - { .name = "CHARGER", }, - { .name = "LDO1", }, - { .name = "LDO2", }, -}; - -static inline struct regulator_init_data *match_init_data(int index, - enum maxim_device_type dev_type) -{ - switch (dev_type) { - case MAXIM_DEVICE_TYPE_MAX77836: - return max77836_regulator_matches[index].init_data; - - case MAXIM_DEVICE_TYPE_MAX14577: - default: - return max14577_regulator_matches[index].init_data; - } -} - -static inline struct device_node *match_of_node(int index, - enum maxim_device_type dev_type) -{ - switch (dev_type) { - case MAXIM_DEVICE_TYPE_MAX77836: - return max77836_regulator_matches[index].of_node; - - case MAXIM_DEVICE_TYPE_MAX14577: - default: - return max14577_regulator_matches[index].of_node; - } -} -#else /* CONFIG_OF */ -static inline struct regulator_init_data *match_init_data(int index, - enum maxim_device_type dev_type) -{ - return NULL; -} - -static inline struct device_node *match_of_node(int index, - enum maxim_device_type dev_type) -{ - return NULL; -} -#endif /* CONFIG_OF */ - /** * Registers for regulators of max77836 use different I2C slave addresses so * different regmaps must be used for them. @@ -265,9 +213,6 @@ static int max14577_regulator_probe(struct platform_device *pdev) if (pdata && pdata->regulators) { config.init_data = pdata->regulators[i].initdata; config.of_node = pdata->regulators[i].of_node; - } else { - config.init_data = match_init_data(i, dev_type); - config.of_node = match_of_node(i, dev_type); } config.regmap = max14577_get_regmap(max14577, supported_regulators[i].id); -- cgit v1.2.3 From f7a621728a6a23bfd2c6ac4d3e42e1303aefde0f Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:51:28 +0000 Subject: regulator: wm831x isink: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: d4d6b722e780 ("regulator: Add WM831x ISINK support") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm831x-isink.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 6dd891d7eee3..11f351191dba 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -140,9 +140,11 @@ static irqreturn_t wm831x_isink_irq(int irq, void *data) { struct wm831x_isink *isink = data; + regulator_lock(isink->regulator); regulator_notifier_call_chain(isink->regulator, REGULATOR_EVENT_OVER_CURRENT, NULL); + regulator_unlock(isink->regulator); return IRQ_HANDLED; } -- cgit v1.2.3 From 8be64b6d87bd47d81753b60ddafe70102ebfd76b Mon Sep 17 00:00:00 2001 From: Steve Twiss Date: Tue, 26 Feb 2019 15:54:01 +0000 Subject: regulator: wm831x ldo: Fix notifier mutex lock warning The mutex for the regulator_dev must be controlled by the caller of the regulator_notifier_call_chain(), as described in the comment for that function. Failure to mutex lock and unlock surrounding the notifier call results in a kernel WARN_ON_ONCE() which will dump a backtrace for the regulator_notifier_call_chain() when that function call is first made. The mutex can be controlled using the regulator_lock/unlock() API. Fixes: d1c6b4fe668b ("regulator: Add WM831x LDO support") Suggested-by: Adam Thomson Signed-off-by: Steve Twiss Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm831x-ldo.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index e4a6f888484e..fcd038e7cd80 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c @@ -51,9 +51,11 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) { struct wm831x_ldo *ldo = data; + regulator_lock(ldo->regulator); regulator_notifier_call_chain(ldo->regulator, REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + regulator_unlock(ldo->regulator); return IRQ_HANDLED; } -- cgit v1.2.3 From 45aa908d9b720f9fe44100fe099d6fd5ab9f12ab Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Mar 2019 00:33:54 +0800 Subject: regulator: wm831x-isink: Select maximum current in specific range .set_current_limit callback should select the current closest to max_uA. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm831x-isink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 11f351191dba..5611890a724b 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -99,7 +99,7 @@ static int wm831x_isink_set_current(struct regulator_dev *rdev, struct wm831x *wm831x = isink->wm831x; int ret, i; - for (i = 0; i < ARRAY_SIZE(wm831x_isinkv_values); i++) { + for (i = ARRAY_SIZE(wm831x_isinkv_values) - 1; i >= 0; i--) { int val = wm831x_isinkv_values[i]; if (min_uA <= val && val <= max_uA) { ret = wm831x_set_bits(wm831x, isink->reg, -- cgit v1.2.3 From 5816df2f75f52f74b6fe48b1b20579acd4dfe8fb Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Mar 2019 00:33:55 +0800 Subject: regulator: wm8350: Select maximum current in specific range .set_current_limit callback should select the current closest to max_uA. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm8350-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index a1c7dfee5c37..d1758a2bc769 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -99,7 +99,7 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting) { int i; - for (i = 0; i < ARRAY_SIZE(isink_cur); i++) { + for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) { if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { *setting = i; return 0; -- cgit v1.2.3 From d48acfd0377f901f348b6c48bdcc03723f19d9e7 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Mar 2019 00:33:56 +0800 Subject: regulator: wm831x-isink: Convert to use regulator_set/get_current_limit_regmap Use regulator_set/get_current_limit_regmap helpers to save some code. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm831x-isink.c | 45 +++++++--------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 5611890a724b..bdc521a6f048 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -92,48 +92,12 @@ static int wm831x_isink_is_enabled(struct regulator_dev *rdev) return 0; } -static int wm831x_isink_set_current(struct regulator_dev *rdev, - int min_uA, int max_uA) -{ - struct wm831x_isink *isink = rdev_get_drvdata(rdev); - struct wm831x *wm831x = isink->wm831x; - int ret, i; - - for (i = ARRAY_SIZE(wm831x_isinkv_values) - 1; i >= 0; i--) { - int val = wm831x_isinkv_values[i]; - if (min_uA <= val && val <= max_uA) { - ret = wm831x_set_bits(wm831x, isink->reg, - WM831X_CS1_ISEL_MASK, i); - return ret; - } - } - - return -EINVAL; -} - -static int wm831x_isink_get_current(struct regulator_dev *rdev) -{ - struct wm831x_isink *isink = rdev_get_drvdata(rdev); - struct wm831x *wm831x = isink->wm831x; - int ret; - - ret = wm831x_reg_read(wm831x, isink->reg); - if (ret < 0) - return ret; - - ret &= WM831X_CS1_ISEL_MASK; - if (ret > WM831X_ISINK_MAX_ISEL) - ret = WM831X_ISINK_MAX_ISEL; - - return wm831x_isinkv_values[ret]; -} - static const struct regulator_ops wm831x_isink_ops = { .is_enabled = wm831x_isink_is_enabled, .enable = wm831x_isink_enable, .disable = wm831x_isink_disable, - .set_current_limit = wm831x_isink_set_current, - .get_current_limit = wm831x_isink_get_current, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, }; static irqreturn_t wm831x_isink_irq(int irq, void *data) @@ -189,10 +153,15 @@ static int wm831x_isink_probe(struct platform_device *pdev) isink->desc.ops = &wm831x_isink_ops; isink->desc.type = REGULATOR_CURRENT; isink->desc.owner = THIS_MODULE; + isink->desc.curr_table = wm831x_isinkv_values, + isink->desc.n_current_limits = ARRAY_SIZE(wm831x_isinkv_values), + isink->desc.csel_reg = isink->reg, + isink->desc.csel_mask = WM831X_CS1_ISEL_MASK, config.dev = pdev->dev.parent; config.init_data = pdata->isink[id]; config.driver_data = isink; + config.regmap = wm831x->regmap; isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc, &config); -- cgit v1.2.3 From dfeb7a93bf3b26e6779e0b38b25877c0540652e6 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Mar 2019 00:33:57 +0800 Subject: regulator: wm8350: Convert to use regulator_set/get_current_limit_regmap Use regulator_set/get_current_limit_regmap helpers to save some code. Signed-off-by: Axel Lin Acked-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/wm8350-regulator.c | 81 +++++------------------------------- 1 file changed, 11 insertions(+), 70 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index d1758a2bc769..0eb3f3a33caa 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -28,7 +28,7 @@ #define WM8350_DCDC_MAX_VSEL 0x66 /* Microamps */ -static const int isink_cur[] = { +static const unsigned int isink_cur[] = { 4, 5, 6, @@ -95,73 +95,6 @@ static const int isink_cur[] = { 223191 }; -static int get_isink_val(int min_uA, int max_uA, u16 *setting) -{ - int i; - - for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) { - if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { - *setting = i; - return 0; - } - } - return -EINVAL; -} - -static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, - int max_uA) -{ - struct wm8350 *wm8350 = rdev_get_drvdata(rdev); - int isink = rdev_get_id(rdev); - u16 val, setting; - int ret; - - ret = get_isink_val(min_uA, max_uA, &setting); - if (ret != 0) - return ret; - - switch (isink) { - case WM8350_ISINK_A: - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & - ~WM8350_CS1_ISEL_MASK; - wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A, - val | setting); - break; - case WM8350_ISINK_B: - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & - ~WM8350_CS1_ISEL_MASK; - wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B, - val | setting); - break; - default: - return -EINVAL; - } - - return 0; -} - -static int wm8350_isink_get_current(struct regulator_dev *rdev) -{ - struct wm8350 *wm8350 = rdev_get_drvdata(rdev); - int isink = rdev_get_id(rdev); - u16 val; - - switch (isink) { - case WM8350_ISINK_A: - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & - WM8350_CS1_ISEL_MASK; - break; - case WM8350_ISINK_B: - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & - WM8350_CS1_ISEL_MASK; - break; - default: - return 0; - } - - return isink_cur[val]; -} - /* turn on ISINK followed by DCDC */ static int wm8350_isink_enable(struct regulator_dev *rdev) { @@ -982,8 +915,8 @@ static const struct regulator_ops wm8350_ldo_ops = { }; static const struct regulator_ops wm8350_isink_ops = { - .set_current_limit = wm8350_isink_set_current, - .get_current_limit = wm8350_isink_get_current, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, .enable = wm8350_isink_enable, .disable = wm8350_isink_disable, .is_enabled = wm8350_isink_is_enabled, @@ -1138,6 +1071,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { .irq = WM8350_IRQ_CS1, .type = REGULATOR_CURRENT, .owner = THIS_MODULE, + .curr_table = isink_cur, + .n_current_limits = ARRAY_SIZE(isink_cur), + .csel_reg = WM8350_CURRENT_SINK_DRIVER_A, + .csel_mask = WM8350_CS1_ISEL_MASK, }, { .name = "ISINKB", @@ -1146,6 +1083,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { .irq = WM8350_IRQ_CS2, .type = REGULATOR_CURRENT, .owner = THIS_MODULE, + .curr_table = isink_cur, + .n_current_limits = ARRAY_SIZE(isink_cur), + .csel_reg = WM8350_CURRENT_SINK_DRIVER_B, + .csel_mask = WM8350_CS2_ISEL_MASK, }, }; -- cgit v1.2.3 From 6cabb8b7fc1428eb573f426a17a853d81227d095 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 14 Mar 2019 19:55:19 +0800 Subject: regulator: 88pm800: Get rid of struct pm800_regulators The struct pm800_regulators only has 2 members: *chip and *map. The pm800_data->chip is not used. The pm800_data->map is not necessary. Thus remove the struct pm800_regulators. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/88pm800.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 89bbd6e8bad1..9fd379732d18 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c @@ -77,11 +77,6 @@ struct pm800_regulator_info { int max_ua; }; -struct pm800_regulators { - struct pm80x_chip *chip; - struct regmap *map; -}; - /* * vreg - the buck regs string. * ereg - the string for the enable register. @@ -235,7 +230,6 @@ static int pm800_regulator_probe(struct platform_device *pdev) { struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); - struct pm800_regulators *pm800_data; struct regulator_config config = { }; struct regulator_init_data *init_data; int i, ret; @@ -252,18 +246,8 @@ static int pm800_regulator_probe(struct platform_device *pdev) return -EINVAL; } - pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), - GFP_KERNEL); - if (!pm800_data) - return -ENOMEM; - - pm800_data->map = chip->subchip->regmap_power; - pm800_data->chip = chip; - - platform_set_drvdata(pdev, pm800_data); - config.dev = chip->dev; - config.regmap = pm800_data->map; + config.regmap = chip->subchip->regmap_power; for (i = 0; i < PM800_ID_RG_MAX; i++) { struct regulator_dev *regulator; -- cgit v1.2.3 From 67ddc68a78b1b762a8799a8cd9c075c7edcd546a Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 12 Mar 2019 23:47:58 +0800 Subject: regulator: da9052: Convert to regulator core's simplified DT parsing code Use regulator core's simplified DT parsing code to simply the driver implementation. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/da9052-regulator.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index cefa3558236d..98d486372b8c 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c @@ -294,6 +294,8 @@ static const struct regulator_ops da9052_ldo_ops = { {\ .reg_desc = {\ .name = #_name,\ + .of_match = of_match_ptr(#_name),\ + .regulators_node = of_match_ptr("regulators"),\ .ops = &da9052_ldo_ops,\ .type = REGULATOR_VOLTAGE,\ .id = DA9052_ID_##_id,\ @@ -314,6 +316,8 @@ static const struct regulator_ops da9052_ldo_ops = { {\ .reg_desc = {\ .name = #_name,\ + .of_match = of_match_ptr(#_name),\ + .regulators_node = of_match_ptr("regulators"),\ .ops = &da9052_dcdc_ops,\ .type = REGULATOR_VOLTAGE,\ .id = DA9052_ID_##_id,\ @@ -417,36 +421,11 @@ static int da9052_regulator_probe(struct platform_device *pdev) return -EINVAL; } - config.dev = &pdev->dev; + config.dev = da9052->dev; config.driver_data = regulator; config.regmap = da9052->regmap; - if (pdata) { + if (pdata) config.init_data = pdata->regulators[cell->id]; - } else { -#ifdef CONFIG_OF - struct device_node *nproot = da9052->dev->of_node; - struct device_node *np; - - if (!nproot) - return -ENODEV; - - nproot = of_get_child_by_name(nproot, "regulators"); - if (!nproot) - return -ENODEV; - - for_each_child_of_node(nproot, np) { - if (of_node_name_eq(np, - regulator->info->reg_desc.name)) { - config.init_data = of_get_regulator_init_data( - &pdev->dev, np, - ®ulator->info->reg_desc); - config.of_node = np; - break; - } - } - of_node_put(nproot); -#endif - } regulator->rdev = devm_regulator_register(&pdev->dev, ®ulator->info->reg_desc, -- cgit v1.2.3 From db7ecb493cab3f27da72c6460991e1de9969f9b8 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 12 Mar 2019 23:47:59 +0800 Subject: regulator: da9055: Convert to regulator core's simplified DT parsing code Use regulator core's simplified DT parsing code to simply the driver implementation. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 67 ++++-------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 3ade4b8d204e..bcbc2fbd7fea 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -338,6 +338,8 @@ static const struct regulator_ops da9055_ldo_ops = { {\ .reg_desc = {\ .name = #_id,\ + .of_match = of_match_ptr(#_id),\ + .regulators_node = of_match_ptr("regulators"),\ .ops = &da9055_ldo_ops,\ .type = REGULATOR_VOLTAGE,\ .id = DA9055_ID_##_id,\ @@ -366,6 +368,8 @@ static const struct regulator_ops da9055_ldo_ops = { {\ .reg_desc = {\ .name = #_id,\ + .of_match = of_match_ptr(#_id),\ + .regulators_node = of_match_ptr("regulators"),\ .ops = &da9055_buck_ops,\ .type = REGULATOR_VOLTAGE,\ .id = DA9055_ID_##_id,\ @@ -509,59 +513,6 @@ static inline struct da9055_regulator_info *find_regulator_info(int id) return NULL; } -#ifdef CONFIG_OF -static struct of_regulator_match da9055_reg_matches[] = { - { .name = "BUCK1", }, - { .name = "BUCK2", }, - { .name = "LDO1", }, - { .name = "LDO2", }, - { .name = "LDO3", }, - { .name = "LDO4", }, - { .name = "LDO5", }, - { .name = "LDO6", }, -}; - -static int da9055_regulator_dt_init(struct platform_device *pdev, - struct da9055_regulator *regulator, - struct regulator_config *config, - int regid) -{ - struct device_node *nproot, *np; - int ret; - - nproot = of_node_get(pdev->dev.parent->of_node); - if (!nproot) - return -ENODEV; - - np = of_get_child_by_name(nproot, "regulators"); - if (!np) - return -ENODEV; - - ret = of_regulator_match(&pdev->dev, np, &da9055_reg_matches[regid], 1); - of_node_put(nproot); - if (ret < 0) { - dev_err(&pdev->dev, "Error matching regulator: %d\n", ret); - return ret; - } - - config->init_data = da9055_reg_matches[regid].init_data; - config->of_node = da9055_reg_matches[regid].of_node; - - if (!config->of_node) - return -ENODEV; - - return 0; -} -#else -static inline int da9055_regulator_dt_init(struct platform_device *pdev, - struct da9055_regulator *regulator, - struct regulator_config *config, - int regid) -{ - return -ENODEV; -} -#endif /* CONFIG_OF */ - static int da9055_regulator_probe(struct platform_device *pdev) { struct regulator_config config = { }; @@ -582,18 +533,12 @@ static int da9055_regulator_probe(struct platform_device *pdev) } regulator->da9055 = da9055; - config.dev = &pdev->dev; + config.dev = da9055->dev; config.driver_data = regulator; config.regmap = da9055->regmap; - if (pdata) { + if (pdata) config.init_data = pdata->regulators[pdev->id]; - } else { - ret = da9055_regulator_dt_init(pdev, regulator, &config, - pdev->id); - if (ret < 0) - return ret; - } ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); if (ret < 0) -- cgit v1.2.3 From 9cff03710d403f8872d1225d36a4b69432ae007d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 16 Mar 2019 09:50:30 +0800 Subject: regulator: da9052: Include linux/of.h to fix build warning for of_match_ptr Remove #ifdef CONFIG_OF guard so linux/of.h will be included when !CONFIG_OF. This fixes build warnings when !CONFIG_OF. Reported-by: kbuild test robot Signed-off-by: Axel Lin Acked-by: Steve Twiss Signed-off-by: Mark Brown --- drivers/regulator/da9052-regulator.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index 98d486372b8c..b90a7ac3f3de 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c @@ -19,10 +19,8 @@ #include #include #include -#ifdef CONFIG_OF #include #include -#endif #include #include -- cgit v1.2.3 From 4d92ac7bd9f8af387d387173b380f58ad6f98b51 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 16 Mar 2019 11:52:57 +0800 Subject: regulator: as3722: Remove *rdevs[] from struct as3722_regulators Current code is using devm_regulator_register() so it is not necessary to save as3722_regs->rdevs[id] for clean up. The *rdevs[] is not used now, remove it. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/as3722-regulator.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index e5fed289b52d..7a315adbe6c4 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -81,7 +81,6 @@ struct as3722_regulator_config_data { struct as3722_regulators { struct device *dev; struct as3722 *as3722; - struct regulator_dev *rdevs[AS3722_REGULATOR_ID_MAX]; struct regulator_desc desc[AS3722_REGULATOR_ID_MAX]; struct as3722_regulator_config_data reg_config_data[AS3722_REGULATOR_ID_MAX]; @@ -929,7 +928,6 @@ static int as3722_regulator_probe(struct platform_device *pdev) return ret; } - as3722_regs->rdevs[id] = rdev; if (reg_config->ext_control) { ret = regulator_enable_regmap(rdev); if (ret < 0) { -- cgit v1.2.3 From 2106e9bbffb9d91b2bc1a33c09efadc8cb3906d2 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 16 Mar 2019 22:35:57 +0800 Subject: regulator: cpcap: Remove unneeded init_data setting This driver is using regulator core's simplified DT parsing code, so regulator will call regulator_of_get_init_data() to get init_data. No need to set config.init_data. In additional, current code does not properly set the init_data setting, so just remove it. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/cpcap-regulator.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c index e7dab5c4d1d1..c9d805d7a979 100644 --- a/drivers/regulator/cpcap-regulator.c +++ b/drivers/regulator/cpcap-regulator.c @@ -507,7 +507,6 @@ static int cpcap_regulator_probe(struct platform_device *pdev) struct cpcap_ddata *ddata; const struct of_device_id *match; struct regulator_config config; - struct regulator_init_data init_data; int i; match = of_match_device(of_match_ptr(cpcap_regulator_id_table), @@ -534,10 +533,8 @@ static int cpcap_regulator_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ddata); memset(&config, 0, sizeof(config)); - memset(&init_data, 0, sizeof(init_data)); config.dev = &pdev->dev; config.regmap = ddata->reg; - config.init_data = &init_data; for (i = 0; i < CPCAP_NR_REGULATORS; i++) { const struct cpcap_regulator *regulator = &ddata->soc[i]; -- cgit v1.2.3 From f4192c2cc923ecd79da6cc1619794164fbafcbc4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 16 Mar 2019 22:35:58 +0800 Subject: regulator: cpcap: Convert to use of_device_get_match_data Use of_device_get_match_data to simplify the code a bit. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/cpcap-regulator.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c index c9d805d7a979..d3284361e594 100644 --- a/drivers/regulator/cpcap-regulator.c +++ b/drivers/regulator/cpcap-regulator.c @@ -505,16 +505,12 @@ MODULE_DEVICE_TABLE(of, cpcap_regulator_id_table); static int cpcap_regulator_probe(struct platform_device *pdev) { struct cpcap_ddata *ddata; - const struct of_device_id *match; + const struct cpcap_regulator *match_data; struct regulator_config config; int i; - match = of_match_device(of_match_ptr(cpcap_regulator_id_table), - &pdev->dev); - if (!match) - return -EINVAL; - - if (!match->data) { + match_data = of_device_get_match_data(&pdev->dev); + if (!match_data) { dev_err(&pdev->dev, "no configuration data found\n"); return -