[linux-sunxi] Re: [PATCH 3/3] regulator: axp20x: simplify device access

2016-09-24 Thread Jean-Francois Moine
On Sat, 24 Sep 2016 16:29:11 +0800
Chen-Yu Tsai  wrote:

[snip]
> >  static int axp20x_regulator_probe(struct platform_device *pdev)
> >  {
> > +   struct device *dev = pdev->dev.parent;
> 
> There are 2 struct device's in play in this function, 1 from the parent,
> and 1 for the platform device for this regulator sub-device.
> 
> > struct regulator_dev *rdev;
> > -   struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> > +   struct axp20x_dev *axp20x = dev_get_drvdata(dev);
> > const struct regulator_desc *regulators;
> > struct regulator_config config = {
> > -   .dev = pdev->dev.parent,
> > +   .dev = dev,
> > .regmap = axp20x->regmap,
> > .driver_data = axp20x,
> > };
> > @@ -532,7 +533,7 @@ static int axp20x_regulator_probe(struct 
> > platform_device *pdev)
> > dcdc5_ix = AXP22X_DCDC5;
> > dc1sw_ix = AXP22X_DC1SW;
> > dc5ldo_ix = AXP22X_DC5LDO;
> > -   drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
> > +   drivevbus = of_property_read_bool(dev->of_node,
> >   "x-powers,drive-vbus-en");
> > break;
> > case AXP806_ID:
> > @@ -555,13 +556,13 @@ static int axp20x_regulator_probe(struct 
> > platform_device *pdev)
> > dc5ldo_ix = AXP809_DC5LDO;
> > break;
> > default:
> > -   dev_err(>dev, "Unsupported AXP variant: %ld\n",
> > +   dev_err(dev, "Unsupported AXP variant: %ld\n",
> 
> So this one is incorrect. You should use this device's struct,
> not the parent. It's possible the mfd driver supports a PMIC,
> but the regulator driver is still missing.

Why do you need a regulator driver? The 'regulator' node in the DT is
not a real device. It is just a container and it could be removed
without any problem.

-- 
Ken ar c'hentaƱ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[linux-sunxi] Re: [PATCH 3/3] regulator: axp20x: simplify device access

2016-09-24 Thread Chen-Yu Tsai
Hi,

On Thu, Sep 22, 2016 at 2:20 AM, Jean-Francois Moine  wrote:
> Use the pointer to the main regulator device instead of the pointer
> to the child platform device.
>
> Signed-off-by: Jean-Francois Moine 
> ---
>  drivers/regulator/axp20x-regulator.c | 45 
> ++--
>  1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/regulator/axp20x-regulator.c 
> b/drivers/regulator/axp20x-regulator.c
> index 7405f5b..244ddc3 100644
> --- a/drivers/regulator/axp20x-regulator.c
> +++ b/drivers/regulator/axp20x-regulator.c
> @@ -347,9 +347,9 @@ static const struct regulator_desc axp809_regulators[] = {
> AXP_DESC_SW(AXP809, SW, "sw", "swin", AXP22X_PWR_OUT_CTRL2, BIT(6)),
>  };
>
> -static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
> +static int axp20x_set_dcdc_freq(struct device *dev, u32 dcdcfreq)
>  {
> -   struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> +   struct axp20x_dev *axp20x = dev_get_drvdata(dev);
> unsigned int reg = AXP20X_DCDC_FREQ;
> u32 min, max, def, step;
>
> @@ -378,7 +378,7 @@ static int axp20x_set_dcdc_freq(struct platform_device 
> *pdev, u32 dcdcfreq)
> step = 150;
> break;
> default:
> -   dev_err(>dev,
> +   dev_err(dev,
> "Setting DCDC frequency for unsupported AXP 
> variant\n");
> return -EINVAL;
> }
> @@ -388,13 +388,13 @@ static int axp20x_set_dcdc_freq(struct platform_device 
> *pdev, u32 dcdcfreq)
>
> if (dcdcfreq < min) {
> dcdcfreq = min;
> -   dev_warn(>dev, "DCDC frequency too low. Set to %ukHz\n",
> +   dev_warn(dev, "DCDC frequency too low. Set to %ukHz\n",
>  min);
> }
>
> if (dcdcfreq > max) {
> dcdcfreq = max;
> -   dev_warn(>dev, "DCDC frequency too high. Set to 
> %ukHz\n",
> +   dev_warn(dev, "DCDC frequency too high. Set to %ukHz\n",
>  max);
> }
>
> @@ -404,24 +404,24 @@ static int axp20x_set_dcdc_freq(struct platform_device 
> *pdev, u32 dcdcfreq)
>   AXP20X_FREQ_DCDC_MASK, dcdcfreq);
>  }
>
> -static int axp20x_regulator_parse_dt(struct platform_device *pdev)
> +static int axp20x_regulator_parse_dt(struct device *dev)
>  {
> struct device_node *np, *regulators;
> int ret;
> u32 dcdcfreq = 0;
>
> -   np = of_node_get(pdev->dev.parent->of_node);
> +   np = of_node_get(dev->of_node);
> if (!np)
> return 0;
>
> regulators = of_get_child_by_name(np, "regulators");
> if (!regulators) {
> -   dev_warn(>dev, "regulators node not found\n");
> +   dev_warn(dev, "regulators node not found\n");
> } else {
> of_property_read_u32(regulators, "x-powers,dcdc-freq", 
> );
> -   ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
> +   ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
> if (ret < 0) {
> -   dev_err(>dev, "Error setting dcdc frequency: 
> %d\n", ret);
> +   dev_err(dev, "Error setting dcdc frequency: %d\n", 
> ret);
> return ret;
> }
>
> @@ -499,11 +499,12 @@ static u32 axp20x_polyphase_slave(struct axp20x_dev 
> *axp20x)
>
>  static int axp20x_regulator_probe(struct platform_device *pdev)
>  {
> +   struct device *dev = pdev->dev.parent;

There are 2 struct device's in play in this function, 1 from the parent,
and 1 for the platform device for this regulator sub-device.

> struct regulator_dev *rdev;
> -   struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> +   struct axp20x_dev *axp20x = dev_get_drvdata(dev);
> const struct regulator_desc *regulators;
> struct regulator_config config = {
> -   .dev = pdev->dev.parent,
> +   .dev = dev,
> .regmap = axp20x->regmap,
> .driver_data = axp20x,
> };
> @@ -532,7 +533,7 @@ static int axp20x_regulator_probe(struct platform_device 
> *pdev)
> dcdc5_ix = AXP22X_DCDC5;
> dc1sw_ix = AXP22X_DC1SW;
> dc5ldo_ix = AXP22X_DC5LDO;
> -   drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
> +   drivevbus = of_property_read_bool(dev->of_node,
>   "x-powers,drive-vbus-en");
> break;
> case AXP806_ID:
> @@ -555,13 +556,13 @@ static int axp20x_regulator_probe(struct 
> platform_device *pdev)
> dc5ldo_ix = AXP809_DC5LDO;
> break;
> default:
> -   dev_err(>dev, "Unsupported AXP variant: %ld\n",
> +   dev_err(dev, "Unsupported AXP variant: