Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, Jun 05, 2018 at 04:58:43PM +0300, Andy Shevchenko wrote: > On Tue, May 29, 2018 at 1:02 PM, Matti Vaittinen > wrote: > > Support for controlling the 8 bucks and 7 LDOs the PMIC contains. > Thanks for the comments Andy. The regulator part of patch set v4 was already applied by Mark but I am going to do some further work on this afer I get the MFD and clk portions done. I'll store these comments and address issues in next set of patches. Br, Matti Vaittinen
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, Jun 05, 2018 at 04:58:43PM +0300, Andy Shevchenko wrote: > On Tue, May 29, 2018 at 1:02 PM, Matti Vaittinen > wrote: > > Support for controlling the 8 bucks and 7 LDOs the PMIC contains. > Thanks for the comments Andy. The regulator part of patch set v4 was already applied by Mark but I am going to do some further work on this afer I get the MFD and clk portions done. I'll store these comments and address issues in next set of patches. Br, Matti Vaittinen
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, May 29, 2018 at 1:02 PM, Matti Vaittinen wrote: > Support for controlling the 8 bucks and 7 LDOs the PMIC contains. > +#include > +#include > +#include One of these is redundant. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include Can you keep the list ordered? > + dev_dbg(&(pmic->pdev->dev), "Buck[%d] Set Ramp = %d\n", id + 1, > + ramp_delay); Redundant parens. > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) > +{ > + int ret = -EINVAL; Redundant assignment. > + if (!set) > + ret = regulator_disable_regmap(rdev); > + else > + ret = regulator_enable_regmap(rdev); > + return ret; > +} > +static int bd71837_probe(struct platform_device *pdev) > +{ > + pmic = devm_kzalloc(>dev, sizeof(struct bd71837_pmic), > + GFP_KERNEL); sizeof(*pmic) and one line as result? > + if (!pmic) > + return -ENOMEM; > + if (!pmic->mfd) { > + dev_err(>dev, "No MFD driver data\n"); > + err = -EINVAL; > + goto err; Plain return? > + } > + dev_dbg(>pdev->dev, "%s: Unlocked lock register 0x%x\n", > + __func__, BD71837_REG_REGLOCK); __func__ part is redundant. > + for (i = 0; i < ARRAY_SIZE(pmic_regulator_inits); i++) { > + Redundant blank line. > + rdev = devm_regulator_register(>dev, desc, ); > + if (IS_ERR(rdev)) { > + dev_err(pmic->mfd->dev, > + "failed to register %s regulator\n", > + desc->name); > + err = PTR_ERR(rdev); > + goto err; Plain return ... > +err: > + return err; Redundant. > +} > +static struct platform_driver bd71837_regulator = { > + .driver = { > + .name = "bd71837-pmic", > + .owner = THIS_MODULE, This done by macro you are using below. Thus, redundant. > + }, > + .probe = bd71837_probe, > +}; > + > +module_platform_driver(bd71837_regulator); -- With Best Regards, Andy Shevchenko
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, May 29, 2018 at 1:02 PM, Matti Vaittinen wrote: > Support for controlling the 8 bucks and 7 LDOs the PMIC contains. > +#include > +#include > +#include One of these is redundant. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include Can you keep the list ordered? > + dev_dbg(&(pmic->pdev->dev), "Buck[%d] Set Ramp = %d\n", id + 1, > + ramp_delay); Redundant parens. > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) > +{ > + int ret = -EINVAL; Redundant assignment. > + if (!set) > + ret = regulator_disable_regmap(rdev); > + else > + ret = regulator_enable_regmap(rdev); > + return ret; > +} > +static int bd71837_probe(struct platform_device *pdev) > +{ > + pmic = devm_kzalloc(>dev, sizeof(struct bd71837_pmic), > + GFP_KERNEL); sizeof(*pmic) and one line as result? > + if (!pmic) > + return -ENOMEM; > + if (!pmic->mfd) { > + dev_err(>dev, "No MFD driver data\n"); > + err = -EINVAL; > + goto err; Plain return? > + } > + dev_dbg(>pdev->dev, "%s: Unlocked lock register 0x%x\n", > + __func__, BD71837_REG_REGLOCK); __func__ part is redundant. > + for (i = 0; i < ARRAY_SIZE(pmic_regulator_inits); i++) { > + Redundant blank line. > + rdev = devm_regulator_register(>dev, desc, ); > + if (IS_ERR(rdev)) { > + dev_err(pmic->mfd->dev, > + "failed to register %s regulator\n", > + desc->name); > + err = PTR_ERR(rdev); > + goto err; Plain return ... > +err: > + return err; Redundant. > +} > +static struct platform_driver bd71837_regulator = { > + .driver = { > + .name = "bd71837-pmic", > + .owner = THIS_MODULE, This done by macro you are using below. Thus, redundant. > + }, > + .probe = bd71837_probe, > +}; > + > +module_platform_driver(bd71837_regulator); -- With Best Regards, Andy Shevchenko
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
Hello, On Tue, May 29, 2018 at 12:47:40PM +0100, Mark Brown wrote: > On Tue, May 29, 2018 at 01:02:15PM +0300, Matti Vaittinen wrote: > > > @@ -0,0 +1,677 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 ROHM Semiconductors */ > > +/* > > + * bd71837-regulator.c ROHM BD71837MWV regulator driver > > + */ > > The SPDX header (and the rest of the block) need to be C++ comments. Oh. My bad. I mixed up the C and Cpp style comments. So I will convert the SPDX and following block to // (Cpp -style) comments. > > > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int > > set) > > +{ > > + int ret = -EINVAL; > > + struct bd71837_pmic *pmic = rdev->reg_data; > > + > > + /* According to the data sheet we must not change regulator voltage > > +* when it is enabled. Thus we need to check if regulator is enabled > > +* before changing the voltage. This mutex is used to avoid race where > > +* we might enable regulator after it's state has been checked but > > +* before the voltage is changed > > +*/ > > + mutex_lock(>mtx); > > + if (!set) > > + ret = regulator_disable_regmap(rdev); > > + else > > + ret = regulator_enable_regmap(rdev); > > + mutex_unlock(>mtx); > > + > > This still has the weird locking/wrapper thing going on. The regulator > core will ensure that only one operation is called on a given regulator > at once. Ok. I''ll remove the mutex and wrapper since core handles this. Also, after re-reading the data sheet I see that this restriction to voltage changes (regulator must be disabled when voltage is changed) is not mentioned for first 4 bucks. I will confirm if they can be changed when enabled and also reflect this in next patch set. > > > +static const struct regulator_desc bd71837_regulators[] = { > > + { > > +.name = "buck1", > > The indentation style here is weird, please follow CodingStyle. Looks > like the second level is just indented by a space for some reason, and > there's similar problems elsewhere. I'll change this too. Br, Matti Vaittinen
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
Hello, On Tue, May 29, 2018 at 12:47:40PM +0100, Mark Brown wrote: > On Tue, May 29, 2018 at 01:02:15PM +0300, Matti Vaittinen wrote: > > > @@ -0,0 +1,677 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 ROHM Semiconductors */ > > +/* > > + * bd71837-regulator.c ROHM BD71837MWV regulator driver > > + */ > > The SPDX header (and the rest of the block) need to be C++ comments. Oh. My bad. I mixed up the C and Cpp style comments. So I will convert the SPDX and following block to // (Cpp -style) comments. > > > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int > > set) > > +{ > > + int ret = -EINVAL; > > + struct bd71837_pmic *pmic = rdev->reg_data; > > + > > + /* According to the data sheet we must not change regulator voltage > > +* when it is enabled. Thus we need to check if regulator is enabled > > +* before changing the voltage. This mutex is used to avoid race where > > +* we might enable regulator after it's state has been checked but > > +* before the voltage is changed > > +*/ > > + mutex_lock(>mtx); > > + if (!set) > > + ret = regulator_disable_regmap(rdev); > > + else > > + ret = regulator_enable_regmap(rdev); > > + mutex_unlock(>mtx); > > + > > This still has the weird locking/wrapper thing going on. The regulator > core will ensure that only one operation is called on a given regulator > at once. Ok. I''ll remove the mutex and wrapper since core handles this. Also, after re-reading the data sheet I see that this restriction to voltage changes (regulator must be disabled when voltage is changed) is not mentioned for first 4 bucks. I will confirm if they can be changed when enabled and also reflect this in next patch set. > > > +static const struct regulator_desc bd71837_regulators[] = { > > + { > > +.name = "buck1", > > The indentation style here is weird, please follow CodingStyle. Looks > like the second level is just indented by a space for some reason, and > there's similar problems elsewhere. I'll change this too. Br, Matti Vaittinen
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, May 29, 2018 at 01:02:15PM +0300, Matti Vaittinen wrote: > @@ -0,0 +1,677 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright (C) 2018 ROHM Semiconductors */ > +/* > + * bd71837-regulator.c ROHM BD71837MWV regulator driver > + */ The SPDX header (and the rest of the block) need to be C++ comments. > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) > +{ > + int ret = -EINVAL; > + struct bd71837_pmic *pmic = rdev->reg_data; > + > + /* According to the data sheet we must not change regulator voltage > + * when it is enabled. Thus we need to check if regulator is enabled > + * before changing the voltage. This mutex is used to avoid race where > + * we might enable regulator after it's state has been checked but > + * before the voltage is changed > + */ > + mutex_lock(>mtx); > + if (!set) > + ret = regulator_disable_regmap(rdev); > + else > + ret = regulator_enable_regmap(rdev); > + mutex_unlock(>mtx); > + This still has the weird locking/wrapper thing going on. The regulator core will ensure that only one operation is called on a given regulator at once. > +static const struct regulator_desc bd71837_regulators[] = { > + { > + .name = "buck1", The indentation style here is weird, please follow CodingStyle. Looks like the second level is just indented by a space for some reason, and there's similar problems elsewhere. signature.asc Description: PGP signature
Re: [PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
On Tue, May 29, 2018 at 01:02:15PM +0300, Matti Vaittinen wrote: > @@ -0,0 +1,677 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright (C) 2018 ROHM Semiconductors */ > +/* > + * bd71837-regulator.c ROHM BD71837MWV regulator driver > + */ The SPDX header (and the rest of the block) need to be C++ comments. > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) > +{ > + int ret = -EINVAL; > + struct bd71837_pmic *pmic = rdev->reg_data; > + > + /* According to the data sheet we must not change regulator voltage > + * when it is enabled. Thus we need to check if regulator is enabled > + * before changing the voltage. This mutex is used to avoid race where > + * we might enable regulator after it's state has been checked but > + * before the voltage is changed > + */ > + mutex_lock(>mtx); > + if (!set) > + ret = regulator_disable_regmap(rdev); > + else > + ret = regulator_enable_regmap(rdev); > + mutex_unlock(>mtx); > + This still has the weird locking/wrapper thing going on. The regulator core will ensure that only one operation is called on a given regulator at once. > +static const struct regulator_desc bd71837_regulators[] = { > + { > + .name = "buck1", The indentation style here is weird, please follow CodingStyle. Looks like the second level is just indented by a space for some reason, and there's similar problems elsewhere. signature.asc Description: PGP signature
[PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
Support for controlling the 8 bucks and 7 LDOs the PMIC contains. Signed-off-by: Matti Vaittinen --- drivers/regulator/Kconfig | 11 + drivers/regulator/Makefile| 1 + drivers/regulator/bd71837-regulator.c | 677 ++ 3 files changed, 689 insertions(+) create mode 100644 drivers/regulator/bd71837-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 097f61784a7d..139f4b53fea0 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -180,6 +180,17 @@ config REGULATOR_BCM590XX BCM590xx PMUs. This will enable support for the software controllable LDO/Switching regulators. +config REGULATOR_BD71837 + tristate "ROHM BD71837 Power Regulator" + depends on MFD_BD71837 + help + This driver supports voltage regulators on ROHM BD71837 PMIC. + This will enable support for the software controllable buck + and LDO regulators. + + This driver can also be built as a module. If so, the module + will be called bd71837-regulator. + config REGULATOR_BD9571MWV tristate "ROHM BD9571MWV Regulators" depends on MFD_BD9571MWV diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 590674fbecd7..1b4d8ec416c2 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o +obj-$(CONFIG_REGULATOR_BD71837) += bd71837-regulator.o obj-$(CONFIG_REGULATOR_BD9571MWV) += bd9571mwv-regulator.o obj-$(CONFIG_REGULATOR_DA903X) += da903x.o obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o diff --git a/drivers/regulator/bd71837-regulator.c b/drivers/regulator/bd71837-regulator.c new file mode 100644 index ..826c1ce3c6d6 --- /dev/null +++ b/drivers/regulator/bd71837-regulator.c @@ -0,0 +1,677 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 ROHM Semiconductors */ +/* + * bd71837-regulator.c ROHM BD71837MWV regulator driver + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct bd71837_pmic { + struct regulator_desc descs[BD71837_REGULATOR_CNT]; + struct bd71837 *mfd; + struct platform_device *pdev; + struct regulator_dev *rdev[BD71837_REGULATOR_CNT]; + struct mutex mtx; +}; + +/* + * BUCK1/2/3/4 + * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting + * 00: 10.00mV/usec 10mV 1uS + * 01: 5.00mV/usec 10mV 2uS + * 10: 2.50mV/usec 10mV 4uS + * 11: 1.25mV/usec 10mV 8uS + */ +static int bd71837_buck1234_set_ramp_delay(struct regulator_dev *rdev, + int ramp_delay) +{ + struct bd71837_pmic *pmic = rdev_get_drvdata(rdev); + struct bd71837 *mfd = pmic->mfd; + int id = rdev->desc->id; + unsigned int ramp_value = BUCK_RAMPRATE_10P00MV; + + dev_dbg(&(pmic->pdev->dev), "Buck[%d] Set Ramp = %d\n", id + 1, + ramp_delay); + switch (ramp_delay) { + case 1 ... 1250: + ramp_value = BUCK_RAMPRATE_1P25MV; + break; + case 1251 ... 2500: + ramp_value = BUCK_RAMPRATE_2P50MV; + break; + case 2501 ... 5000: + ramp_value = BUCK_RAMPRATE_5P00MV; + break; + case 5001 ... 1: + ramp_value = BUCK_RAMPRATE_10P00MV; + break; + default: + ramp_value = BUCK_RAMPRATE_10P00MV; + dev_err(>pdev->dev, + "%s: ramp_delay: %d not supported, setting 1mV//us\n", + rdev->desc->name, ramp_delay); + } + + return regmap_update_bits(mfd->regmap, BD71837_REG_BUCK1_CTRL + id, + BUCK_RAMPRATE_MASK, ramp_value << 6); +} + +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) +{ + int ret = -EINVAL; + struct bd71837_pmic *pmic = rdev->reg_data; + + /* According to the data sheet we must not change regulator voltage +* when it is enabled. Thus we need to check if regulator is enabled +* before changing the voltage. This mutex is used to avoid race where +* we might enable regulator after it's state has been checked but +* before the voltage is changed +*/ + mutex_lock(>mtx); + if (!set) + ret = regulator_disable_regmap(rdev); + else + ret = regulator_enable_regmap(rdev); + mutex_unlock(>mtx); + + return ret; +} + +static int bd71837_regulator_enable_regmap(struct regulator_dev *rdev) +{ + return bd71837_regulator_set_regmap(rdev, 1); +} + +static int
[PATCH v3 6/6] regulator: bd71837: BD71837 PMIC regulator driver
Support for controlling the 8 bucks and 7 LDOs the PMIC contains. Signed-off-by: Matti Vaittinen --- drivers/regulator/Kconfig | 11 + drivers/regulator/Makefile| 1 + drivers/regulator/bd71837-regulator.c | 677 ++ 3 files changed, 689 insertions(+) create mode 100644 drivers/regulator/bd71837-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 097f61784a7d..139f4b53fea0 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -180,6 +180,17 @@ config REGULATOR_BCM590XX BCM590xx PMUs. This will enable support for the software controllable LDO/Switching regulators. +config REGULATOR_BD71837 + tristate "ROHM BD71837 Power Regulator" + depends on MFD_BD71837 + help + This driver supports voltage regulators on ROHM BD71837 PMIC. + This will enable support for the software controllable buck + and LDO regulators. + + This driver can also be built as a module. If so, the module + will be called bd71837-regulator. + config REGULATOR_BD9571MWV tristate "ROHM BD9571MWV Regulators" depends on MFD_BD9571MWV diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 590674fbecd7..1b4d8ec416c2 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o +obj-$(CONFIG_REGULATOR_BD71837) += bd71837-regulator.o obj-$(CONFIG_REGULATOR_BD9571MWV) += bd9571mwv-regulator.o obj-$(CONFIG_REGULATOR_DA903X) += da903x.o obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o diff --git a/drivers/regulator/bd71837-regulator.c b/drivers/regulator/bd71837-regulator.c new file mode 100644 index ..826c1ce3c6d6 --- /dev/null +++ b/drivers/regulator/bd71837-regulator.c @@ -0,0 +1,677 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 ROHM Semiconductors */ +/* + * bd71837-regulator.c ROHM BD71837MWV regulator driver + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct bd71837_pmic { + struct regulator_desc descs[BD71837_REGULATOR_CNT]; + struct bd71837 *mfd; + struct platform_device *pdev; + struct regulator_dev *rdev[BD71837_REGULATOR_CNT]; + struct mutex mtx; +}; + +/* + * BUCK1/2/3/4 + * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting + * 00: 10.00mV/usec 10mV 1uS + * 01: 5.00mV/usec 10mV 2uS + * 10: 2.50mV/usec 10mV 4uS + * 11: 1.25mV/usec 10mV 8uS + */ +static int bd71837_buck1234_set_ramp_delay(struct regulator_dev *rdev, + int ramp_delay) +{ + struct bd71837_pmic *pmic = rdev_get_drvdata(rdev); + struct bd71837 *mfd = pmic->mfd; + int id = rdev->desc->id; + unsigned int ramp_value = BUCK_RAMPRATE_10P00MV; + + dev_dbg(&(pmic->pdev->dev), "Buck[%d] Set Ramp = %d\n", id + 1, + ramp_delay); + switch (ramp_delay) { + case 1 ... 1250: + ramp_value = BUCK_RAMPRATE_1P25MV; + break; + case 1251 ... 2500: + ramp_value = BUCK_RAMPRATE_2P50MV; + break; + case 2501 ... 5000: + ramp_value = BUCK_RAMPRATE_5P00MV; + break; + case 5001 ... 1: + ramp_value = BUCK_RAMPRATE_10P00MV; + break; + default: + ramp_value = BUCK_RAMPRATE_10P00MV; + dev_err(>pdev->dev, + "%s: ramp_delay: %d not supported, setting 1mV//us\n", + rdev->desc->name, ramp_delay); + } + + return regmap_update_bits(mfd->regmap, BD71837_REG_BUCK1_CTRL + id, + BUCK_RAMPRATE_MASK, ramp_value << 6); +} + +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) +{ + int ret = -EINVAL; + struct bd71837_pmic *pmic = rdev->reg_data; + + /* According to the data sheet we must not change regulator voltage +* when it is enabled. Thus we need to check if regulator is enabled +* before changing the voltage. This mutex is used to avoid race where +* we might enable regulator after it's state has been checked but +* before the voltage is changed +*/ + mutex_lock(>mtx); + if (!set) + ret = regulator_disable_regmap(rdev); + else + ret = regulator_enable_regmap(rdev); + mutex_unlock(>mtx); + + return ret; +} + +static int bd71837_regulator_enable_regmap(struct regulator_dev *rdev) +{ + return bd71837_regulator_set_regmap(rdev, 1); +} + +static int