Re: [PATCH v2] regulator: bd718x7: Remove struct bd718xx_pmic

2018-10-04 Thread Matti Vaittinen
Hello Axel,

On Wed, Oct 03, 2018 at 11:32:46PM +0800, Axel Lin wrote:
> All the fields in struct bd718xx_pmic are not really necessary.
> Remove struct bd718xx_pmic to simplify the code.
> 
> Signed-off-by: Axel Lin 
> ---
> v2:
> Sorry, just update the subject line.
> 
>  drivers/regulator/bd718x7-regulator.c | 59 +--
>  1 file changed, 20 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/regulator/bd718x7-regulator.c 
> b/drivers/regulator/bd718x7-regulator.c
> index d2522d4e1505..3a47e0372e77 100644
> --- a/drivers/regulator/bd718x7-regulator.c
> +++ b/drivers/regulator/bd718x7-regulator.c
> @@ -15,13 +15,6 @@
>  #include 
>  #include 
>  
> -struct bd718xx_pmic {
> - struct bd718xx_regulator_data *rdata;
> - struct bd718xx *mfd;
> - struct platform_device *pdev;
> - struct regulator_dev *rdev[BD718XX_REGULATOR_AMOUNT];
> -};

You should then also remove the references to struct bd718xx_pmic from
include/linux/mfd/rohm-bd718x7.h. Now we have there:

struct bd71837_pmic;
struct bd71837_clk;

struct bd71837 {
struct device *dev;
struct regmap *regmap;
unsigned long int id;

int chip_irq;
struct regmap_irq_chip_data *irq_data;

struct bd71837_pmic *pmic;
struct bd71837_clk *clk;
};

Other than that - simplifications are always welcome.
Reviewed-by: Matti Vaittinen 



Re: [PATCH v2] regulator: bd718x7: Remove struct bd718xx_pmic

2018-10-04 Thread Matti Vaittinen
Hello Axel,

On Wed, Oct 03, 2018 at 11:32:46PM +0800, Axel Lin wrote:
> All the fields in struct bd718xx_pmic are not really necessary.
> Remove struct bd718xx_pmic to simplify the code.
> 
> Signed-off-by: Axel Lin 
> ---
> v2:
> Sorry, just update the subject line.
> 
>  drivers/regulator/bd718x7-regulator.c | 59 +--
>  1 file changed, 20 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/regulator/bd718x7-regulator.c 
> b/drivers/regulator/bd718x7-regulator.c
> index d2522d4e1505..3a47e0372e77 100644
> --- a/drivers/regulator/bd718x7-regulator.c
> +++ b/drivers/regulator/bd718x7-regulator.c
> @@ -15,13 +15,6 @@
>  #include 
>  #include 
>  
> -struct bd718xx_pmic {
> - struct bd718xx_regulator_data *rdata;
> - struct bd718xx *mfd;
> - struct platform_device *pdev;
> - struct regulator_dev *rdev[BD718XX_REGULATOR_AMOUNT];
> -};

You should then also remove the references to struct bd718xx_pmic from
include/linux/mfd/rohm-bd718x7.h. Now we have there:

struct bd71837_pmic;
struct bd71837_clk;

struct bd71837 {
struct device *dev;
struct regmap *regmap;
unsigned long int id;

int chip_irq;
struct regmap_irq_chip_data *irq_data;

struct bd71837_pmic *pmic;
struct bd71837_clk *clk;
};

Other than that - simplifications are always welcome.
Reviewed-by: Matti Vaittinen 



[PATCH v2] regulator: bd718x7: Remove struct bd718xx_pmic

2018-10-03 Thread Axel Lin
All the fields in struct bd718xx_pmic are not really necessary.
Remove struct bd718xx_pmic to simplify the code.

Signed-off-by: Axel Lin 
---
v2:
Sorry, just update the subject line.

 drivers/regulator/bd718x7-regulator.c | 59 +--
 1 file changed, 20 insertions(+), 39 deletions(-)

diff --git a/drivers/regulator/bd718x7-regulator.c 
b/drivers/regulator/bd718x7-regulator.c
index d2522d4e1505..3a47e0372e77 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -15,13 +15,6 @@
 #include 
 #include 
 
-struct bd718xx_pmic {
-   struct bd718xx_regulator_data *rdata;
-   struct bd718xx *mfd;
-   struct platform_device *pdev;
-   struct regulator_dev *rdev[BD718XX_REGULATOR_AMOUNT];
-};
-
 /*
  * BUCK1/2/3/4
  * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
@@ -33,12 +26,10 @@ struct bd718xx_pmic {
 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
   int ramp_delay)
 {
-   struct bd718xx_pmic *pmic = rdev_get_drvdata(rdev);
-   struct bd718xx *mfd = pmic->mfd;
int id = rdev->desc->id;
unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
 
-   dev_dbg(>pdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
+   dev_dbg(>dev, "Buck[%d] Set Ramp = %d\n", id + 1,
ramp_delay);
switch (ramp_delay) {
case 1 ... 1250:
@@ -55,12 +46,12 @@ static int bd718xx_buck1234_set_ramp_delay(struct 
regulator_dev *rdev,
break;
default:
ramp_value = BUCK_RAMPRATE_10P00MV;
-   dev_err(>pdev->dev,
+   dev_err(>dev,
"%s: ramp_delay: %d not supported, setting 
1mV//us\n",
rdev->desc->name, ramp_delay);
}
 
-   return regmap_update_bits(mfd->regmap, BD718XX_REG_BUCK1_CTRL + id,
+   return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
  BUCK_RAMPRATE_MASK, ramp_value << 6);
 }
 
@@ -1022,7 +1013,7 @@ struct bd718xx_pmic_inits {
 
 static int bd718xx_probe(struct platform_device *pdev)
 {
-   struct bd718xx_pmic *pmic;
+   struct bd718xx *mfd;
struct regulator_config config = { 0 };
struct bd718xx_pmic_inits pmic_regulators[] = {
[BD718XX_TYPE_BD71837] = {
@@ -1037,54 +1028,46 @@ static int bd718xx_probe(struct platform_device *pdev)
 
int i, j, err;
 
-   pmic = devm_kzalloc(>dev, sizeof(*pmic), GFP_KERNEL);
-   if (!pmic)
-   return -ENOMEM;
-
-   pmic->pdev = pdev;
-   pmic->mfd = dev_get_drvdata(pdev->dev.parent);
-
-   if (!pmic->mfd) {
+   mfd = dev_get_drvdata(pdev->dev.parent);
+   if (!mfd) {
dev_err(>dev, "No MFD driver data\n");
err = -EINVAL;
goto err;
}
-   if (pmic->mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
-   !pmic_regulators[pmic->mfd->chip_type].r_datas) {
+
+   if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
+   !pmic_regulators[mfd->chip_type].r_datas) {
dev_err(>dev, "Unsupported chip type\n");
err = -EINVAL;
goto err;
}
 
-   platform_set_drvdata(pdev, pmic);
-
/* Register LOCK release */
-   err = regmap_update_bits(pmic->mfd->regmap, BD718XX_REG_REGLOCK,
+   err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
if (err) {
-   dev_err(>pdev->dev, "Failed to unlock PMIC (%d)\n", err);
+   dev_err(>dev, "Failed to unlock PMIC (%d)\n", err);
goto err;
} else {
-   dev_dbg(>pdev->dev, "Unlocked lock register 0x%x\n",
+   dev_dbg(>dev, "Unlocked lock register 0x%x\n",
BD718XX_REG_REGLOCK);
}
 
-   for (i = 0; i < pmic_regulators[pmic->mfd->chip_type].r_amount; i++) {
+   for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
 
const struct regulator_desc *desc;
struct regulator_dev *rdev;
const struct bd718xx_regulator_data *r;
 
-   r = &(*pmic_regulators[pmic->mfd->chip_type].r_datas)[i];
+   r = &(*pmic_regulators[mfd->chip_type].r_datas)[i];
desc = >desc;
 
config.dev = pdev->dev.parent;
-   config.driver_data = pmic;
-   config.regmap = pmic->mfd->regmap;
+   config.regmap = mfd->regmap;
 
rdev = devm_regulator_register(>dev, desc, );
if (IS_ERR(rdev)) {
-   dev_err(pmic->mfd->dev,
+   dev_err(>dev,
"failed to register %s regulator\n",
desc->name);
err = PTR_ERR(rdev);
@@ -1096,28 +1079,26 @@ static int 

[PATCH v2] regulator: bd718x7: Remove struct bd718xx_pmic

2018-10-03 Thread Axel Lin
All the fields in struct bd718xx_pmic are not really necessary.
Remove struct bd718xx_pmic to simplify the code.

Signed-off-by: Axel Lin 
---
v2:
Sorry, just update the subject line.

 drivers/regulator/bd718x7-regulator.c | 59 +--
 1 file changed, 20 insertions(+), 39 deletions(-)

diff --git a/drivers/regulator/bd718x7-regulator.c 
b/drivers/regulator/bd718x7-regulator.c
index d2522d4e1505..3a47e0372e77 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -15,13 +15,6 @@
 #include 
 #include 
 
-struct bd718xx_pmic {
-   struct bd718xx_regulator_data *rdata;
-   struct bd718xx *mfd;
-   struct platform_device *pdev;
-   struct regulator_dev *rdev[BD718XX_REGULATOR_AMOUNT];
-};
-
 /*
  * BUCK1/2/3/4
  * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
@@ -33,12 +26,10 @@ struct bd718xx_pmic {
 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
   int ramp_delay)
 {
-   struct bd718xx_pmic *pmic = rdev_get_drvdata(rdev);
-   struct bd718xx *mfd = pmic->mfd;
int id = rdev->desc->id;
unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
 
-   dev_dbg(>pdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
+   dev_dbg(>dev, "Buck[%d] Set Ramp = %d\n", id + 1,
ramp_delay);
switch (ramp_delay) {
case 1 ... 1250:
@@ -55,12 +46,12 @@ static int bd718xx_buck1234_set_ramp_delay(struct 
regulator_dev *rdev,
break;
default:
ramp_value = BUCK_RAMPRATE_10P00MV;
-   dev_err(>pdev->dev,
+   dev_err(>dev,
"%s: ramp_delay: %d not supported, setting 
1mV//us\n",
rdev->desc->name, ramp_delay);
}
 
-   return regmap_update_bits(mfd->regmap, BD718XX_REG_BUCK1_CTRL + id,
+   return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
  BUCK_RAMPRATE_MASK, ramp_value << 6);
 }
 
@@ -1022,7 +1013,7 @@ struct bd718xx_pmic_inits {
 
 static int bd718xx_probe(struct platform_device *pdev)
 {
-   struct bd718xx_pmic *pmic;
+   struct bd718xx *mfd;
struct regulator_config config = { 0 };
struct bd718xx_pmic_inits pmic_regulators[] = {
[BD718XX_TYPE_BD71837] = {
@@ -1037,54 +1028,46 @@ static int bd718xx_probe(struct platform_device *pdev)
 
int i, j, err;
 
-   pmic = devm_kzalloc(>dev, sizeof(*pmic), GFP_KERNEL);
-   if (!pmic)
-   return -ENOMEM;
-
-   pmic->pdev = pdev;
-   pmic->mfd = dev_get_drvdata(pdev->dev.parent);
-
-   if (!pmic->mfd) {
+   mfd = dev_get_drvdata(pdev->dev.parent);
+   if (!mfd) {
dev_err(>dev, "No MFD driver data\n");
err = -EINVAL;
goto err;
}
-   if (pmic->mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
-   !pmic_regulators[pmic->mfd->chip_type].r_datas) {
+
+   if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
+   !pmic_regulators[mfd->chip_type].r_datas) {
dev_err(>dev, "Unsupported chip type\n");
err = -EINVAL;
goto err;
}
 
-   platform_set_drvdata(pdev, pmic);
-
/* Register LOCK release */
-   err = regmap_update_bits(pmic->mfd->regmap, BD718XX_REG_REGLOCK,
+   err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
if (err) {
-   dev_err(>pdev->dev, "Failed to unlock PMIC (%d)\n", err);
+   dev_err(>dev, "Failed to unlock PMIC (%d)\n", err);
goto err;
} else {
-   dev_dbg(>pdev->dev, "Unlocked lock register 0x%x\n",
+   dev_dbg(>dev, "Unlocked lock register 0x%x\n",
BD718XX_REG_REGLOCK);
}
 
-   for (i = 0; i < pmic_regulators[pmic->mfd->chip_type].r_amount; i++) {
+   for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
 
const struct regulator_desc *desc;
struct regulator_dev *rdev;
const struct bd718xx_regulator_data *r;
 
-   r = &(*pmic_regulators[pmic->mfd->chip_type].r_datas)[i];
+   r = &(*pmic_regulators[mfd->chip_type].r_datas)[i];
desc = >desc;
 
config.dev = pdev->dev.parent;
-   config.driver_data = pmic;
-   config.regmap = pmic->mfd->regmap;
+   config.regmap = mfd->regmap;
 
rdev = devm_regulator_register(>dev, desc, );
if (IS_ERR(rdev)) {
-   dev_err(pmic->mfd->dev,
+   dev_err(>dev,
"failed to register %s regulator\n",
desc->name);
err = PTR_ERR(rdev);
@@ -1096,28 +1079,26 @@ static int