* [PATCH 1/3] regulator: axp20x: simplify poly-phase handling
@ 2016-09-20 16:09 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:09 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree, linux-arm-kernel, linux-kernel, linux-sunxi
Building a list (bitmap) of the slaves included in poly-phase groups
at probe startup time simplifies the treatment in the regulator
creation loop.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
drivers/regulator/axp20x-regulator.c | 45 +++++++++++++++++-------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 54382ef..4e5e7c8 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -477,30 +477,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work
}
/*
- * This function checks whether a regulator is part of a poly-phase
- * output setup based on the registers settings. Returns true if it is.
+ * This function checks which regulators are part of poly-phase
+ * output setups based on the registers settings.
+ * Returns a bitmap of these regulators.
*/
-static bool axp20x_is_polyphase_slave(struct axp20x_dev *axp20x, int id)
+static u32 axp20x_polyphase_slave(struct axp20x_dev *axp20x)
{
- u32 reg = 0;
-
- /* Only AXP806 has poly-phase outputs */
- if (axp20x->variant != AXP806_ID)
- return false;
+ u32 reg = 0, bitmap = 0;
regmap_read(axp20x->regmap, AXP806_DCDC_MODE_CTRL2, ®);
- switch (id) {
- case AXP806_DCDCB:
- return (((reg & GENMASK(7, 6)) == BIT(6)) ||
- ((reg & GENMASK(7, 6)) == BIT(7)));
- case AXP806_DCDCC:
- return ((reg & GENMASK(7, 6)) == BIT(7));
- case AXP806_DCDCE:
- return !!(reg & BIT(5));
- }
+ if ((reg & GENMASK(7, 6)) == BIT(5))
+ bitmap |= 1 << AXP806_DCDCE;
+ if ((reg & GENMASK(7, 6)) == BIT(6))
+ bitmap |= 1 << AXP806_DCDCB;
+ if ((reg & GENMASK(7, 6)) == BIT(7))
+ bitmap |= (1 << AXP806_DCDCB) | (1 << AXP806_DCDCC);
- return false;
+ return bitmap;
}
static int axp20x_regulator_probe(struct platform_device *pdev)
@@ -518,6 +512,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
bool drivevbus = false;
+ u32 skip_bitmap = 0;
switch (axp20x->variant) {
case AXP202_ID:
@@ -535,6 +530,13 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP806_ID:
regulators = axp806_regulators;
nregulators = AXP806_REG_ID_MAX;
+
+ /*
+ * The regulators which are slave in a poly-phase setup
+ * are skipped, as their controls are bound to the master
+ * regulator and won't work.
+ */
+ skip_bitmap |= axp20x_polyphase_slave(axp20x);
break;
case AXP809_ID:
regulators = axp809_regulators;
@@ -553,12 +555,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const struct regulator_desc *desc = ®ulators[i];
struct regulator_desc *new_desc;
- /*
- * If this regulator is a slave in a poly-phase setup,
- * skip it, as its controls are bound to the master
- * regulator and won't work.
- */
- if (axp20x_is_polyphase_slave(axp20x, i))
+ if (skip_bitmap & (1 << i))
continue;
/*
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 1/3] regulator: axp20x: simplify poly-phase handling
@ 2016-09-20 16:09 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:09 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Building a list (bitmap) of the slaves included in poly-phase groups
at probe startup time simplifies the treatment in the regulator
creation loop.
Signed-off-by: Jean-Francois Moine <moinejf-GANU6spQydw@public.gmane.org>
---
drivers/regulator/axp20x-regulator.c | 45 +++++++++++++++++-------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 54382ef..4e5e7c8 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -477,30 +477,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work
}
/*
- * This function checks whether a regulator is part of a poly-phase
- * output setup based on the registers settings. Returns true if it is.
+ * This function checks which regulators are part of poly-phase
+ * output setups based on the registers settings.
+ * Returns a bitmap of these regulators.
*/
-static bool axp20x_is_polyphase_slave(struct axp20x_dev *axp20x, int id)
+static u32 axp20x_polyphase_slave(struct axp20x_dev *axp20x)
{
- u32 reg = 0;
-
- /* Only AXP806 has poly-phase outputs */
- if (axp20x->variant != AXP806_ID)
- return false;
+ u32 reg = 0, bitmap = 0;
regmap_read(axp20x->regmap, AXP806_DCDC_MODE_CTRL2, ®);
- switch (id) {
- case AXP806_DCDCB:
- return (((reg & GENMASK(7, 6)) == BIT(6)) ||
- ((reg & GENMASK(7, 6)) == BIT(7)));
- case AXP806_DCDCC:
- return ((reg & GENMASK(7, 6)) == BIT(7));
- case AXP806_DCDCE:
- return !!(reg & BIT(5));
- }
+ if ((reg & GENMASK(7, 6)) == BIT(5))
+ bitmap |= 1 << AXP806_DCDCE;
+ if ((reg & GENMASK(7, 6)) == BIT(6))
+ bitmap |= 1 << AXP806_DCDCB;
+ if ((reg & GENMASK(7, 6)) == BIT(7))
+ bitmap |= (1 << AXP806_DCDCB) | (1 << AXP806_DCDCC);
- return false;
+ return bitmap;
}
static int axp20x_regulator_probe(struct platform_device *pdev)
@@ -518,6 +512,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
bool drivevbus = false;
+ u32 skip_bitmap = 0;
switch (axp20x->variant) {
case AXP202_ID:
@@ -535,6 +530,13 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP806_ID:
regulators = axp806_regulators;
nregulators = AXP806_REG_ID_MAX;
+
+ /*
+ * The regulators which are slave in a poly-phase setup
+ * are skipped, as their controls are bound to the master
+ * regulator and won't work.
+ */
+ skip_bitmap |= axp20x_polyphase_slave(axp20x);
break;
case AXP809_ID:
regulators = axp809_regulators;
@@ -553,12 +555,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const struct regulator_desc *desc = ®ulators[i];
struct regulator_desc *new_desc;
- /*
- * If this regulator is a slave in a poly-phase setup,
- * skip it, as its controls are bound to the master
- * regulator and won't work.
- */
- if (axp20x_is_polyphase_slave(axp20x, i))
+ if (skip_bitmap & (1 << i))
continue;
/*
--
2.10.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 1/3] regulator: axp20x: simplify poly-phase handling
@ 2016-09-20 16:09 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:09 UTC (permalink / raw)
To: linux-arm-kernel
Building a list (bitmap) of the slaves included in poly-phase groups
at probe startup time simplifies the treatment in the regulator
creation loop.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
drivers/regulator/axp20x-regulator.c | 45 +++++++++++++++++-------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 54382ef..4e5e7c8 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -477,30 +477,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work
}
/*
- * This function checks whether a regulator is part of a poly-phase
- * output setup based on the registers settings. Returns true if it is.
+ * This function checks which regulators are part of poly-phase
+ * output setups based on the registers settings.
+ * Returns a bitmap of these regulators.
*/
-static bool axp20x_is_polyphase_slave(struct axp20x_dev *axp20x, int id)
+static u32 axp20x_polyphase_slave(struct axp20x_dev *axp20x)
{
- u32 reg = 0;
-
- /* Only AXP806 has poly-phase outputs */
- if (axp20x->variant != AXP806_ID)
- return false;
+ u32 reg = 0, bitmap = 0;
regmap_read(axp20x->regmap, AXP806_DCDC_MODE_CTRL2, ®);
- switch (id) {
- case AXP806_DCDCB:
- return (((reg & GENMASK(7, 6)) == BIT(6)) ||
- ((reg & GENMASK(7, 6)) == BIT(7)));
- case AXP806_DCDCC:
- return ((reg & GENMASK(7, 6)) == BIT(7));
- case AXP806_DCDCE:
- return !!(reg & BIT(5));
- }
+ if ((reg & GENMASK(7, 6)) == BIT(5))
+ bitmap |= 1 << AXP806_DCDCE;
+ if ((reg & GENMASK(7, 6)) == BIT(6))
+ bitmap |= 1 << AXP806_DCDCB;
+ if ((reg & GENMASK(7, 6)) == BIT(7))
+ bitmap |= (1 << AXP806_DCDCB) | (1 << AXP806_DCDCC);
- return false;
+ return bitmap;
}
static int axp20x_regulator_probe(struct platform_device *pdev)
@@ -518,6 +512,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
bool drivevbus = false;
+ u32 skip_bitmap = 0;
switch (axp20x->variant) {
case AXP202_ID:
@@ -535,6 +530,13 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP806_ID:
regulators = axp806_regulators;
nregulators = AXP806_REG_ID_MAX;
+
+ /*
+ * The regulators which are slave in a poly-phase setup
+ * are skipped, as their controls are bound to the master
+ * regulator and won't work.
+ */
+ skip_bitmap |= axp20x_polyphase_slave(axp20x);
break;
case AXP809_ID:
regulators = axp809_regulators;
@@ -553,12 +555,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
const struct regulator_desc *desc = ®ulators[i];
struct regulator_desc *new_desc;
- /*
- * If this regulator is a slave in a poly-phase setup,
- * skip it, as its controls are bound to the master
- * regulator and won't work.
- */
- if (axp20x_is_polyphase_slave(axp20x, i))
+ if (skip_bitmap & (1 << i))
continue;
/*
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 2/3] regulator: axp20x: simplify the treatment of linked regulators
@ 2016-09-20 16:38 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:38 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree, linux-arm-kernel, linux-kernel, linux-sunxi
Using ancillary variables for handling the linked regulators simplifies
the loop of regulator creation and makes easier the addition of new
regulator types.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
drivers/regulator/axp20x-regulator.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 4e5e7c8..7405f5b 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -511,6 +511,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
u32 workmode;
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
+ s8 dcdc1_ix = -1;
+ s8 dcdc5_ix = -1;
+ s8 dc1sw_ix = -1;
+ s8 dc5ldo_ix = -1;
bool drivevbus = false;
u32 skip_bitmap = 0;
@@ -524,6 +528,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP223_ID:
regulators = axp22x_regulators;
nregulators = AXP22X_REG_ID_MAX;
+ dcdc1_ix = AXP22X_DCDC1;
+ dcdc5_ix = AXP22X_DCDC5;
+ dc1sw_ix = AXP22X_DC1SW;
+ dc5ldo_ix = AXP22X_DC5LDO;
drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
"x-powers,drive-vbus-en");
break;
@@ -541,6 +549,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP809_ID:
regulators = axp809_regulators;
nregulators = AXP809_REG_ID_MAX;
+ dcdc1_ix = AXP809_DCDC1;
+ dcdc5_ix = AXP809_DCDC5;
+ dc1sw_ix = AXP809_DC1SW;
+ dc5ldo_ix = AXP809_DC5LDO;
break;
default:
dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
@@ -567,8 +579,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* part of this loop to see where we save the DT defined
* name.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DC1SW) ||
- (regulators == axp809_regulators && i == AXP809_DC1SW)) {
+ if (i == dc1sw_ix && dcdc1_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -576,8 +587,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
desc = new_desc;
}
- if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) ||
- (regulators == axp809_regulators && i == AXP809_DC5LDO)) {
+ if (i == dc5ldo_ix && dcdc5_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -605,14 +615,12 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/*
* Save AXP22X DCDC1 / DCDC5 regulator names for later.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC1) ||
- (regulators == axp809_regulators && i == AXP809_DCDC1))
+ if (i == dcdc1_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc1_name);
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC5) ||
- (regulators == axp809_regulators && i == AXP809_DCDC5))
+ if (i == dcdc5_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc5_name);
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 2/3] regulator: axp20x: simplify the treatment of linked regulators
@ 2016-09-20 16:38 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:38 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Using ancillary variables for handling the linked regulators simplifies
the loop of regulator creation and makes easier the addition of new
regulator types.
Signed-off-by: Jean-Francois Moine <moinejf-GANU6spQydw@public.gmane.org>
---
drivers/regulator/axp20x-regulator.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 4e5e7c8..7405f5b 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -511,6 +511,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
u32 workmode;
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
+ s8 dcdc1_ix = -1;
+ s8 dcdc5_ix = -1;
+ s8 dc1sw_ix = -1;
+ s8 dc5ldo_ix = -1;
bool drivevbus = false;
u32 skip_bitmap = 0;
@@ -524,6 +528,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP223_ID:
regulators = axp22x_regulators;
nregulators = AXP22X_REG_ID_MAX;
+ dcdc1_ix = AXP22X_DCDC1;
+ dcdc5_ix = AXP22X_DCDC5;
+ dc1sw_ix = AXP22X_DC1SW;
+ dc5ldo_ix = AXP22X_DC5LDO;
drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
"x-powers,drive-vbus-en");
break;
@@ -541,6 +549,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP809_ID:
regulators = axp809_regulators;
nregulators = AXP809_REG_ID_MAX;
+ dcdc1_ix = AXP809_DCDC1;
+ dcdc5_ix = AXP809_DCDC5;
+ dc1sw_ix = AXP809_DC1SW;
+ dc5ldo_ix = AXP809_DC5LDO;
break;
default:
dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
@@ -567,8 +579,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* part of this loop to see where we save the DT defined
* name.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DC1SW) ||
- (regulators == axp809_regulators && i == AXP809_DC1SW)) {
+ if (i == dc1sw_ix && dcdc1_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -576,8 +587,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
desc = new_desc;
}
- if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) ||
- (regulators == axp809_regulators && i == AXP809_DC5LDO)) {
+ if (i == dc5ldo_ix && dcdc5_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -605,14 +615,12 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/*
* Save AXP22X DCDC1 / DCDC5 regulator names for later.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC1) ||
- (regulators == axp809_regulators && i == AXP809_DCDC1))
+ if (i == dcdc1_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc1_name);
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC5) ||
- (regulators == axp809_regulators && i == AXP809_DCDC5))
+ if (i == dcdc5_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc5_name);
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 2/3] regulator: axp20x: simplify the treatment of linked regulators
@ 2016-09-20 16:38 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-20 16:38 UTC (permalink / raw)
To: linux-arm-kernel
Using ancillary variables for handling the linked regulators simplifies
the loop of regulator creation and makes easier the addition of new
regulator types.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
drivers/regulator/axp20x-regulator.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 4e5e7c8..7405f5b 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -511,6 +511,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
u32 workmode;
const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
+ s8 dcdc1_ix = -1;
+ s8 dcdc5_ix = -1;
+ s8 dc1sw_ix = -1;
+ s8 dc5ldo_ix = -1;
bool drivevbus = false;
u32 skip_bitmap = 0;
@@ -524,6 +528,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP223_ID:
regulators = axp22x_regulators;
nregulators = AXP22X_REG_ID_MAX;
+ dcdc1_ix = AXP22X_DCDC1;
+ dcdc5_ix = AXP22X_DCDC5;
+ dc1sw_ix = AXP22X_DC1SW;
+ dc5ldo_ix = AXP22X_DC5LDO;
drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
"x-powers,drive-vbus-en");
break;
@@ -541,6 +549,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
case AXP809_ID:
regulators = axp809_regulators;
nregulators = AXP809_REG_ID_MAX;
+ dcdc1_ix = AXP809_DCDC1;
+ dcdc5_ix = AXP809_DCDC5;
+ dc1sw_ix = AXP809_DC1SW;
+ dc5ldo_ix = AXP809_DC5LDO;
break;
default:
dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
@@ -567,8 +579,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* part of this loop to see where we save the DT defined
* name.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DC1SW) ||
- (regulators == axp809_regulators && i == AXP809_DC1SW)) {
+ if (i == dc1sw_ix && dcdc1_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -576,8 +587,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
desc = new_desc;
}
- if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) ||
- (regulators == axp809_regulators && i == AXP809_DC5LDO)) {
+ if (i == dc5ldo_ix && dcdc5_name) {
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
@@ -605,14 +615,12 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/*
* Save AXP22X DCDC1 / DCDC5 regulator names for later.
*/
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC1) ||
- (regulators == axp809_regulators && i == AXP809_DCDC1))
+ if (i == dcdc1_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc1_name);
- if ((regulators == axp22x_regulators && i == AXP22X_DCDC5) ||
- (regulators == axp809_regulators && i == AXP809_DCDC5))
+ if (i == dcdc5_ix)
of_property_read_string(rdev->dev.of_node,
"regulator-name",
&dcdc5_name);
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-21 18:20 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-21 18:20 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree, linux-arm-kernel, linux-kernel, linux-sunxi
Use the pointer to the main regulator device instead of the pointer
to the child platform device.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
+ dev_warn(dev, "regulators node not found\n");
} else {
of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
- ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
+ ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
if (ret < 0) {
- dev_err(&pdev->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;
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(&pdev->dev, "Unsupported AXP variant: %ld\n",
+ dev_err(dev, "Unsupported AXP variant: %ld\n",
axp20x->variant);
return -EINVAL;
}
/* This only sets the dcdc freq. Ignore any errors */
- axp20x_regulator_parse_dt(pdev);
+ axp20x_regulator_parse_dt(dev);
for (i = 0; i < nregulators; i++) {
const struct regulator_desc *desc = ®ulators[i];
@@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* name.
*/
if (i == dc1sw_ix && dcdc1_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc1_name;
@@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
}
if (i == dc5ldo_ix && dcdc5_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc5_name;
desc = new_desc;
}
- rdev = devm_regulator_register(&pdev->dev, desc, &config);
+ rdev = devm_regulator_register(dev, desc, &config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register %s\n",
+ dev_err(dev, "Failed to register %s\n",
regulators[i].name);
return PTR_ERR(rdev);
@@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
&workmode);
if (!ret) {
if (axp20x_set_dcdc_workmode(rdev, i, workmode))
- dev_err(&pdev->dev, "Failed to set workmode on %s\n",
+ dev_err(dev, "Failed to set workmode on %s\n",
rdev->desc->name);
}
@@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
AXP22X_MISC_N_VBUSEN_FUNC, 0);
- rdev = devm_regulator_register(&pdev->dev,
+ rdev = devm_regulator_register(dev,
&axp22x_drivevbus_regulator,
&config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register drivevbus\n");
+ dev_err(dev, "Failed to register drivevbus\n");
return PTR_ERR(rdev);
}
}
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-21 18:20 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-21 18:20 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Use the pointer to the main regulator device instead of the pointer
to the child platform device.
Signed-off-by: Jean-Francois Moine <moinejf-GANU6spQydw@public.gmane.org>
---
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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
+ dev_warn(dev, "regulators node not found\n");
} else {
of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
- ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
+ ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
if (ret < 0) {
- dev_err(&pdev->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;
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(&pdev->dev, "Unsupported AXP variant: %ld\n",
+ dev_err(dev, "Unsupported AXP variant: %ld\n",
axp20x->variant);
return -EINVAL;
}
/* This only sets the dcdc freq. Ignore any errors */
- axp20x_regulator_parse_dt(pdev);
+ axp20x_regulator_parse_dt(dev);
for (i = 0; i < nregulators; i++) {
const struct regulator_desc *desc = ®ulators[i];
@@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* name.
*/
if (i == dc1sw_ix && dcdc1_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc1_name;
@@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
}
if (i == dc5ldo_ix && dcdc5_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc5_name;
desc = new_desc;
}
- rdev = devm_regulator_register(&pdev->dev, desc, &config);
+ rdev = devm_regulator_register(dev, desc, &config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register %s\n",
+ dev_err(dev, "Failed to register %s\n",
regulators[i].name);
return PTR_ERR(rdev);
@@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
&workmode);
if (!ret) {
if (axp20x_set_dcdc_workmode(rdev, i, workmode))
- dev_err(&pdev->dev, "Failed to set workmode on %s\n",
+ dev_err(dev, "Failed to set workmode on %s\n",
rdev->desc->name);
}
@@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
AXP22X_MISC_N_VBUSEN_FUNC, 0);
- rdev = devm_regulator_register(&pdev->dev,
+ rdev = devm_regulator_register(dev,
&axp22x_drivevbus_regulator,
&config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register drivevbus\n");
+ dev_err(dev, "Failed to register drivevbus\n");
return PTR_ERR(rdev);
}
}
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-21 18:20 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-21 18:20 UTC (permalink / raw)
To: linux-arm-kernel
Use the pointer to the main regulator device instead of the pointer
to the child platform device.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
+ dev_warn(dev, "regulators node not found\n");
} else {
of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
- ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
+ ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
if (ret < 0) {
- dev_err(&pdev->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;
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(&pdev->dev, "Unsupported AXP variant: %ld\n",
+ dev_err(dev, "Unsupported AXP variant: %ld\n",
axp20x->variant);
return -EINVAL;
}
/* This only sets the dcdc freq. Ignore any errors */
- axp20x_regulator_parse_dt(pdev);
+ axp20x_regulator_parse_dt(dev);
for (i = 0; i < nregulators; i++) {
const struct regulator_desc *desc = ®ulators[i];
@@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
* name.
*/
if (i == dc1sw_ix && dcdc1_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc1_name;
@@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
}
if (i == dc5ldo_ix && dcdc5_name) {
- new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
+ new_desc = devm_kzalloc(dev, sizeof(*desc),
GFP_KERNEL);
*new_desc = regulators[i];
new_desc->supply_name = dcdc5_name;
desc = new_desc;
}
- rdev = devm_regulator_register(&pdev->dev, desc, &config);
+ rdev = devm_regulator_register(dev, desc, &config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register %s\n",
+ dev_err(dev, "Failed to register %s\n",
regulators[i].name);
return PTR_ERR(rdev);
@@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
&workmode);
if (!ret) {
if (axp20x_set_dcdc_workmode(rdev, i, workmode))
- dev_err(&pdev->dev, "Failed to set workmode on %s\n",
+ dev_err(dev, "Failed to set workmode on %s\n",
rdev->desc->name);
}
@@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
/* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
AXP22X_MISC_N_VBUSEN_FUNC, 0);
- rdev = devm_regulator_register(&pdev->dev,
+ rdev = devm_regulator_register(dev,
&axp22x_drivevbus_regulator,
&config);
if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "Failed to register drivevbus\n");
+ dev_err(dev, "Failed to register drivevbus\n");
return PTR_ERR(rdev);
}
}
--
2.10.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 0/3] regulator: axp20x: Simplify various code
@ 2016-09-23 7:44 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-23 7:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree, linux-arm-kernel, linux-kernel, linux-sunxi
This patch series just simplifies a bit the code of the AXP20x driver.
It does not contain any fonctional changes.
It will be used as a base for adding new AXP devices (patches to come).
It applies on linux-next.
Jean-Francois Moine (3):
regulator: axp20x: simplify poly-phase handling
regulator: axp20x: simplify the treatment of linked regulators
regulator: axp20x: simplify device access
drivers/regulator/axp20x-regulator.c | 114 ++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 54 deletions(-)
--
2.10.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 0/3] regulator: axp20x: Simplify various code
@ 2016-09-23 7:44 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-23 7:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Rutland, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
This patch series just simplifies a bit the code of the AXP20x driver.
It does not contain any fonctional changes.
It will be used as a base for adding new AXP devices (patches to come).
It applies on linux-next.
Jean-Francois Moine (3):
regulator: axp20x: simplify poly-phase handling
regulator: axp20x: simplify the treatment of linked regulators
regulator: axp20x: simplify device access
drivers/regulator/axp20x-regulator.c | 114 ++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 54 deletions(-)
--
2.10.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 0/3] regulator: axp20x: Simplify various code
@ 2016-09-23 7:44 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-23 7:44 UTC (permalink / raw)
To: linux-arm-kernel
This patch series just simplifies a bit the code of the AXP20x driver.
It does not contain any fonctional changes.
It will be used as a base for adding new AXP devices (patches to come).
It applies on linux-next.
Jean-Francois Moine (3):
regulator: axp20x: simplify poly-phase handling
regulator: axp20x: simplify the treatment of linked regulators
regulator: axp20x: simplify device access
drivers/regulator/axp20x-regulator.c | 114 ++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 54 deletions(-)
--
2.10.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:29 ` Chen-Yu Tsai
0 siblings, 0 replies; 18+ messages in thread
From: Chen-Yu Tsai @ 2016-09-24 8:29 UTC (permalink / raw)
To: Jean-Francois Moine
Cc: Chen-Yu Tsai, Mark Rutland, Rob Herring, devicetree,
linux-arm-kernel, linux-kernel, linux-sunxi
Hi,
On Thu, Sep 22, 2016 at 2:20 AM, Jean-Francois Moine <moinejf@free.fr> wrote:
> Use the pointer to the main regulator device instead of the pointer
> to the child platform device.
>
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
> 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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
> + dev_warn(dev, "regulators node not found\n");
> } else {
> of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
> - ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
> + ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
> if (ret < 0) {
> - dev_err(&pdev->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(&pdev->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.
> axp20x->variant);
> return -EINVAL;
> }
>
> /* This only sets the dcdc freq. Ignore any errors */
> - axp20x_regulator_parse_dt(pdev);
> + axp20x_regulator_parse_dt(dev);
>
> for (i = 0; i < nregulators; i++) {
> const struct regulator_desc *desc = ®ulators[i];
> @@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> * name.
> */
> if (i == dc1sw_ix && dcdc1_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc1_name;
> @@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> }
>
> if (i == dc5ldo_ix && dcdc5_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
Same here. The devres lifetime should be bound to this driver, not the parent.
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc5_name;
> desc = new_desc;
> }
>
> - rdev = devm_regulator_register(&pdev->dev, desc, &config);
> + rdev = devm_regulator_register(dev, desc, &config);
Same here.
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register %s\n",
> + dev_err(dev, "Failed to register %s\n",
Same here.
> regulators[i].name);
>
> return PTR_ERR(rdev);
> @@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> &workmode);
> if (!ret) {
> if (axp20x_set_dcdc_workmode(rdev, i, workmode))
> - dev_err(&pdev->dev, "Failed to set workmode on %s\n",
> + dev_err(dev, "Failed to set workmode on %s\n",
Same here.
> rdev->desc->name);
> }
>
> @@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> /* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
> regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
> AXP22X_MISC_N_VBUSEN_FUNC, 0);
> - rdev = devm_regulator_register(&pdev->dev,
> + rdev = devm_regulator_register(dev,
Same here.
> &axp22x_drivevbus_regulator,
> &config);
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register drivevbus\n");
> + dev_err(dev, "Failed to register drivevbus\n");
Same here.
Regards
ChenYu
> return PTR_ERR(rdev);
> }
> }
> --
> 2.10.0
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:29 ` Chen-Yu Tsai
0 siblings, 0 replies; 18+ messages in thread
From: Chen-Yu Tsai @ 2016-09-24 8:29 UTC (permalink / raw)
To: Jean-Francois Moine
Cc: Chen-Yu Tsai, Mark Rutland, Rob Herring, devicetree,
linux-arm-kernel, linux-kernel, linux-sunxi
Hi,
On Thu, Sep 22, 2016 at 2:20 AM, Jean-Francois Moine <moinejf-GANU6spQydw@public.gmane.org> wrote:
> Use the pointer to the main regulator device instead of the pointer
> to the child platform device.
>
> Signed-off-by: Jean-Francois Moine <moinejf-GANU6spQydw@public.gmane.org>
> ---
> 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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
> + dev_warn(dev, "regulators node not found\n");
> } else {
> of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
> - ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
> + ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
> if (ret < 0) {
> - dev_err(&pdev->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(&pdev->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.
> axp20x->variant);
> return -EINVAL;
> }
>
> /* This only sets the dcdc freq. Ignore any errors */
> - axp20x_regulator_parse_dt(pdev);
> + axp20x_regulator_parse_dt(dev);
>
> for (i = 0; i < nregulators; i++) {
> const struct regulator_desc *desc = ®ulators[i];
> @@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> * name.
> */
> if (i == dc1sw_ix && dcdc1_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc1_name;
> @@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> }
>
> if (i == dc5ldo_ix && dcdc5_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
Same here. The devres lifetime should be bound to this driver, not the parent.
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc5_name;
> desc = new_desc;
> }
>
> - rdev = devm_regulator_register(&pdev->dev, desc, &config);
> + rdev = devm_regulator_register(dev, desc, &config);
Same here.
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register %s\n",
> + dev_err(dev, "Failed to register %s\n",
Same here.
> regulators[i].name);
>
> return PTR_ERR(rdev);
> @@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> &workmode);
> if (!ret) {
> if (axp20x_set_dcdc_workmode(rdev, i, workmode))
> - dev_err(&pdev->dev, "Failed to set workmode on %s\n",
> + dev_err(dev, "Failed to set workmode on %s\n",
Same here.
> rdev->desc->name);
> }
>
> @@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> /* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
> regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
> AXP22X_MISC_N_VBUSEN_FUNC, 0);
> - rdev = devm_regulator_register(&pdev->dev,
> + rdev = devm_regulator_register(dev,
Same here.
> &axp22x_drivevbus_regulator,
> &config);
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register drivevbus\n");
> + dev_err(dev, "Failed to register drivevbus\n");
Same here.
Regards
ChenYu
> return PTR_ERR(rdev);
> }
> }
> --
> 2.10.0
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:29 ` Chen-Yu Tsai
0 siblings, 0 replies; 18+ messages in thread
From: Chen-Yu Tsai @ 2016-09-24 8:29 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Thu, Sep 22, 2016 at 2:20 AM, Jean-Francois Moine <moinejf@free.fr> wrote:
> Use the pointer to the main regulator device instead of the pointer
> to the child platform device.
>
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
> 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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "regulators node not found\n");
> + dev_warn(dev, "regulators node not found\n");
> } else {
> of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
> - ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
> + ret = axp20x_set_dcdc_freq(dev, dcdcfreq);
> if (ret < 0) {
> - dev_err(&pdev->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(&pdev->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.
> axp20x->variant);
> return -EINVAL;
> }
>
> /* This only sets the dcdc freq. Ignore any errors */
> - axp20x_regulator_parse_dt(pdev);
> + axp20x_regulator_parse_dt(dev);
>
> for (i = 0; i < nregulators; i++) {
> const struct regulator_desc *desc = ®ulators[i];
> @@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> * name.
> */
> if (i == dc1sw_ix && dcdc1_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc1_name;
> @@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> }
>
> if (i == dc5ldo_ix && dcdc5_name) {
> - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
> + new_desc = devm_kzalloc(dev, sizeof(*desc),
> GFP_KERNEL);
Same here. The devres lifetime should be bound to this driver, not the parent.
> *new_desc = regulators[i];
> new_desc->supply_name = dcdc5_name;
> desc = new_desc;
> }
>
> - rdev = devm_regulator_register(&pdev->dev, desc, &config);
> + rdev = devm_regulator_register(dev, desc, &config);
Same here.
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register %s\n",
> + dev_err(dev, "Failed to register %s\n",
Same here.
> regulators[i].name);
>
> return PTR_ERR(rdev);
> @@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> &workmode);
> if (!ret) {
> if (axp20x_set_dcdc_workmode(rdev, i, workmode))
> - dev_err(&pdev->dev, "Failed to set workmode on %s\n",
> + dev_err(dev, "Failed to set workmode on %s\n",
Same here.
> rdev->desc->name);
> }
>
> @@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
> /* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
> regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
> AXP22X_MISC_N_VBUSEN_FUNC, 0);
> - rdev = devm_regulator_register(&pdev->dev,
> + rdev = devm_regulator_register(dev,
Same here.
> &axp22x_drivevbus_regulator,
> &config);
> if (IS_ERR(rdev)) {
> - dev_err(&pdev->dev, "Failed to register drivevbus\n");
> + dev_err(dev, "Failed to register drivevbus\n");
Same here.
Regards
ChenYu
> return PTR_ERR(rdev);
> }
> }
> --
> 2.10.0
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:59 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-24 8:59 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Mark Rutland, Rob Herring, devicetree, linux-arm-kernel,
linux-kernel, linux-sunxi
On Sat, 24 Sep 2016 16:29:11 +0800
Chen-Yu Tsai <wens@csie.org> 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(&pdev->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/
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:59 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-24 8:59 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Mark Rutland, Rob Herring, devicetree, linux-arm-kernel,
linux-kernel, linux-sunxi
On Sat, 24 Sep 2016 16:29:11 +0800
Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org> 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(&pdev->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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 3/3] regulator: axp20x: simplify device access
@ 2016-09-24 8:59 ` Jean-Francois Moine
0 siblings, 0 replies; 18+ messages in thread
From: Jean-Francois Moine @ 2016-09-24 8:59 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, 24 Sep 2016 16:29:11 +0800
Chen-Yu Tsai <wens@csie.org> 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(&pdev->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/
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2016-09-24 9:17 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-23 7:44 [PATCH 0/3] regulator: axp20x: Simplify various code Jean-Francois Moine
2016-09-23 7:44 ` Jean-Francois Moine
2016-09-23 7:44 ` Jean-Francois Moine
2016-09-20 16:09 ` [PATCH 1/3] regulator: axp20x: simplify poly-phase handling Jean-Francois Moine
2016-09-20 16:09 ` Jean-Francois Moine
2016-09-20 16:09 ` Jean-Francois Moine
2016-09-20 16:38 ` [PATCH 2/3] regulator: axp20x: simplify the treatment of linked regulators Jean-Francois Moine
2016-09-20 16:38 ` Jean-Francois Moine
2016-09-20 16:38 ` Jean-Francois Moine
2016-09-21 18:20 ` [PATCH 3/3] regulator: axp20x: simplify device access Jean-Francois Moine
2016-09-21 18:20 ` Jean-Francois Moine
2016-09-21 18:20 ` Jean-Francois Moine
2016-09-24 8:29 ` Chen-Yu Tsai
2016-09-24 8:29 ` Chen-Yu Tsai
2016-09-24 8:29 ` Chen-Yu Tsai
2016-09-24 8:59 ` Jean-Francois Moine
2016-09-24 8:59 ` Jean-Francois Moine
2016-09-24 8:59 ` Jean-Francois Moine
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.