* [PATCH v6 1/4] power: supply: twl4030-charger: allocate iio by devm_iio_channel_get() and fix error path
2017-06-14 9:25 [PATCH v6 0/4] More fixes for twl4030 charger H. Nikolaus Schaller
@ 2017-06-14 9:25 ` H. Nikolaus Schaller
2017-06-14 20:13 ` Sebastian Reichel
2017-06-14 9:25 ` [PATCH v6 2/4] power: supply: twl4030-charger: move allocation of iio channel to the beginning H. Nikolaus Schaller
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: H. Nikolaus Schaller @ 2017-06-14 9:25 UTC (permalink / raw)
To: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Sebastian Reichel, Marek Belisko,
H. Nikolaus Schaller
Cc: linux-kernel, devicetree, linux-pm, letux-kernel, notasas,
linux-omap
Suggested-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/power/supply/twl4030_charger.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 785a07bc4f39..9507c24495ba 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -1017,7 +1017,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
return ret;
}
- bci->channel_vac = iio_channel_get(&pdev->dev, "vac");
+ bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
if (IS_ERR(bci->channel_vac)) {
bci->channel_vac = NULL;
dev_warn(&pdev->dev, "could not request vac iio channel");
@@ -1044,7 +1044,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
TWL4030_INTERRUPTS_BCIIMR1A);
if (ret < 0) {
dev_err(&pdev->dev, "failed to unmask interrupts: %d\n", ret);
- goto fail;
+ return ret;
}
reg = ~(u32)(TWL4030_VBATOV | TWL4030_VBUSOV | TWL4030_ACCHGOV);
@@ -1073,10 +1073,6 @@ static int twl4030_bci_probe(struct platform_device *pdev)
twl4030_charger_enable_backup(0, 0);
return 0;
-fail:
- iio_channel_release(bci->channel_vac);
-
- return ret;
}
static int twl4030_bci_remove(struct platform_device *pdev)
@@ -1087,8 +1083,6 @@ static int twl4030_bci_remove(struct platform_device *pdev)
twl4030_charger_enable_usb(bci, false);
twl4030_charger_enable_backup(0, 0);
- iio_channel_release(bci->channel_vac);
-
device_remove_file(&bci->usb->dev, &dev_attr_mode);
device_remove_file(&bci->ac->dev, &dev_attr_mode);
/* mask interrupts */
--
2.12.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v6 1/4] power: supply: twl4030-charger: allocate iio by devm_iio_channel_get() and fix error path
2017-06-14 9:25 ` [PATCH v6 1/4] power: supply: twl4030-charger: allocate iio by devm_iio_channel_get() and fix error path H. Nikolaus Schaller
@ 2017-06-14 20:13 ` Sebastian Reichel
0 siblings, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2017-06-14 20:13 UTC (permalink / raw)
To: H. Nikolaus Schaller
Cc: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Marek Belisko, linux-kernel, devicetree, linux-pm,
letux-kernel, notasas, linux-omap
[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]
Hi,
On Wed, Jun 14, 2017 at 11:25:53AM +0200, H. Nikolaus Schaller wrote:
> Suggested-by: Sebastian Reichel <sre@kernel.org>
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
> ---
> drivers/power/supply/twl4030_charger.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
> index 785a07bc4f39..9507c24495ba 100644
> --- a/drivers/power/supply/twl4030_charger.c
> +++ b/drivers/power/supply/twl4030_charger.c
> @@ -1017,7 +1017,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
> return ret;
> }
>
> - bci->channel_vac = iio_channel_get(&pdev->dev, "vac");
> + bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
> if (IS_ERR(bci->channel_vac)) {
> bci->channel_vac = NULL;
> dev_warn(&pdev->dev, "could not request vac iio channel");
> @@ -1044,7 +1044,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
> TWL4030_INTERRUPTS_BCIIMR1A);
> if (ret < 0) {
> dev_err(&pdev->dev, "failed to unmask interrupts: %d\n", ret);
> - goto fail;
> + return ret;
> }
>
> reg = ~(u32)(TWL4030_VBATOV | TWL4030_VBUSOV | TWL4030_ACCHGOV);
> @@ -1073,10 +1073,6 @@ static int twl4030_bci_probe(struct platform_device *pdev)
> twl4030_charger_enable_backup(0, 0);
>
> return 0;
> -fail:
> - iio_channel_release(bci->channel_vac);
> -
> - return ret;
> }
>
> static int twl4030_bci_remove(struct platform_device *pdev)
> @@ -1087,8 +1083,6 @@ static int twl4030_bci_remove(struct platform_device *pdev)
> twl4030_charger_enable_usb(bci, false);
> twl4030_charger_enable_backup(0, 0);
>
> - iio_channel_release(bci->channel_vac);
> -
> device_remove_file(&bci->usb->dev, &dev_attr_mode);
> device_remove_file(&bci->ac->dev, &dev_attr_mode);
> /* mask interrupts */
Thanks, queued.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v6 2/4] power: supply: twl4030-charger: move allocation of iio channel to the beginning
2017-06-14 9:25 [PATCH v6 0/4] More fixes for twl4030 charger H. Nikolaus Schaller
2017-06-14 9:25 ` [PATCH v6 1/4] power: supply: twl4030-charger: allocate iio by devm_iio_channel_get() and fix error path H. Nikolaus Schaller
@ 2017-06-14 9:25 ` H. Nikolaus Schaller
[not found] ` <0aa7052c6c8183ef12c08ed6aa069ddf8c748809.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2017-06-14 9:25 ` [PATCH v6 3/4] power: supply: twl4030-charger: move irq allocation to just before irqs are enabled H. Nikolaus Schaller
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: H. Nikolaus Schaller @ 2017-06-14 9:25 UTC (permalink / raw)
To: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Sebastian Reichel, Marek Belisko,
H. Nikolaus Schaller
Cc: linux-kernel, devicetree, linux-pm, letux-kernel, notasas,
linux-omap
This is in prepraration for EPROBE_DEFER handling because it is quite
likely that geting the (madc) iio channel is deferred more often than
later steps.
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/power/supply/twl4030_charger.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 9507c24495ba..1fbbe0cc216a 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -984,6 +984,12 @@ static int twl4030_bci_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, bci);
+ bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
+ if (IS_ERR(bci->channel_vac)) {
+ bci->channel_vac = NULL;
+ dev_warn(&pdev->dev, "could not request vac iio channel");
+ }
+
bci->ac = devm_power_supply_register(&pdev->dev, &twl4030_bci_ac_desc,
NULL);
if (IS_ERR(bci->ac)) {
@@ -1017,12 +1023,6 @@ static int twl4030_bci_probe(struct platform_device *pdev)
return ret;
}
- bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
- if (IS_ERR(bci->channel_vac)) {
- bci->channel_vac = NULL;
- dev_warn(&pdev->dev, "could not request vac iio channel");
- }
-
INIT_WORK(&bci->work, twl4030_bci_usb_work);
INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker);
--
2.12.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v6 3/4] power: supply: twl4030-charger: move irq allocation to just before irqs are enabled
2017-06-14 9:25 [PATCH v6 0/4] More fixes for twl4030 charger H. Nikolaus Schaller
2017-06-14 9:25 ` [PATCH v6 1/4] power: supply: twl4030-charger: allocate iio by devm_iio_channel_get() and fix error path H. Nikolaus Schaller
2017-06-14 9:25 ` [PATCH v6 2/4] power: supply: twl4030-charger: move allocation of iio channel to the beginning H. Nikolaus Schaller
@ 2017-06-14 9:25 ` H. Nikolaus Schaller
[not found] ` <0eeffa7a6ab8e4213f518e2caf6982d2b77dc0b2.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
[not found] ` <cover.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2017-06-14 9:29 ` [PATCH v6 0/4] More fixes for twl4030 charger H. Nikolaus Schaller
4 siblings, 1 reply; 11+ messages in thread
From: H. Nikolaus Schaller @ 2017-06-14 9:25 UTC (permalink / raw)
To: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Sebastian Reichel, Marek Belisko,
H. Nikolaus Schaller
Cc: linux-kernel, devicetree, linux-pm, letux-kernel, notasas,
linux-omap
This avoids a potential race if irqs are enabled and triggered too early
before the worker is properly set up.
Suggested-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/power/supply/twl4030_charger.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 1fbbe0cc216a..3bebeecb4a1f 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -984,6 +984,16 @@ static int twl4030_bci_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, bci);
+ if (bci->dev->of_node) {
+ struct device_node *phynode;
+
+ phynode = of_find_compatible_node(bci->dev->of_node->parent,
+ NULL, "ti,twl4030-usb");
+ if (phynode)
+ bci->transceiver = devm_usb_get_phy_by_node(
+ bci->dev, phynode, &bci->usb_nb);
+ }
+
bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
if (IS_ERR(bci->channel_vac)) {
bci->channel_vac = NULL;
@@ -1006,6 +1016,10 @@ static int twl4030_bci_probe(struct platform_device *pdev)
return ret;
}
+ INIT_WORK(&bci->work, twl4030_bci_usb_work);
+ INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker);
+
+ bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
ret = devm_request_threaded_irq(&pdev->dev, bci->irq_chg, NULL,
twl4030_charger_interrupt, IRQF_ONESHOT, pdev->name,
bci);
@@ -1023,20 +1037,6 @@ static int twl4030_bci_probe(struct platform_device *pdev)
return ret;
}
- INIT_WORK(&bci->work, twl4030_bci_usb_work);
- INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker);
-
- bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
- if (bci->dev->of_node) {
- struct device_node *phynode;
-
- phynode = of_find_compatible_node(bci->dev->of_node->parent,
- NULL, "ti,twl4030-usb");
- if (phynode)
- bci->transceiver = devm_usb_get_phy_by_node(
- bci->dev, phynode, &bci->usb_nb);
- }
-
/* Enable interrupts now. */
reg = ~(u32)(TWL4030_ICHGLOW | TWL4030_ICHGEOC | TWL4030_TBATOR2 |
TWL4030_TBATOR1 | TWL4030_BATSTS);
--
2.12.2
^ permalink raw reply related [flat|nested] 11+ messages in thread[parent not found: <cover.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>]
* [PATCH v6 4/4] power: supply: twl4030-charger: add deferred probing for phy and iio
[not found] ` <cover.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
@ 2017-06-14 9:25 ` H. Nikolaus Schaller
[not found] ` <6573ec523aa73971562c9b7e7d89f6045185d8c4.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: H. Nikolaus Schaller @ 2017-06-14 9:25 UTC (permalink / raw)
To: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Sebastian Reichel, Marek Belisko,
H. Nikolaus Schaller
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
letux-kernel-S0jZdbWzriLCfDggNXIi3w,
notasas-Re5JQEeQqe8AvxtiuMwx3w, linux-omap-u79uwXL29TY76Z2rM5mHXA
This fixes an issue if both this twl4030_charger driver and
phy-twl4030-usb are compiled as modules and loaded in random order.
It has been observed on GTA04 and OpenPandora devices that in worst
case the boot process hangs and in best case the AC detection fails
with a warning.
Therefore we add deferred probing checks for the usb_phy and the
iio channel for AC detection.
Signed-off-by: H. Nikolaus Schaller <hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
---
drivers/power/supply/twl4030_charger.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 3bebeecb4a1f..6ac8816262bd 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -989,15 +989,21 @@ static int twl4030_bci_probe(struct platform_device *pdev)
phynode = of_find_compatible_node(bci->dev->of_node->parent,
NULL, "ti,twl4030-usb");
- if (phynode)
+ if (phynode) {
bci->transceiver = devm_usb_get_phy_by_node(
bci->dev, phynode, &bci->usb_nb);
+ if (IS_ERR(bci->transceiver) &&
+ PTR_ERR(bci->transceiver) == -EPROBE_DEFER)
+ return -EPROBE_DEFER; /* PHY not ready */
+ }
}
bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
if (IS_ERR(bci->channel_vac)) {
- bci->channel_vac = NULL;
+ if (PTR_ERR(bci->channel_vac) == -EPROBE_DEFER)
+ return -EPROBE_DEFER; /* iio not ready */
dev_warn(&pdev->dev, "could not request vac iio channel");
+ bci->channel_vac = NULL;
}
bci->ac = devm_power_supply_register(&pdev->dev, &twl4030_bci_ac_desc,
--
2.12.2
--
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] 11+ messages in thread
* Re: [PATCH v6 0/4] More fixes for twl4030 charger
2017-06-14 9:25 [PATCH v6 0/4] More fixes for twl4030 charger H. Nikolaus Schaller
` (3 preceding siblings ...)
[not found] ` <cover.1497432355.git.hns-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
@ 2017-06-14 9:29 ` H. Nikolaus Schaller
4 siblings, 0 replies; 11+ messages in thread
From: H. Nikolaus Schaller @ 2017-06-14 9:29 UTC (permalink / raw)
To: Grygorii Strashko, NeilBrown, Rob Herring, Mark Rutland,
Russell King, Sebastian Reichel, Marek Belisko, Nikolaus Schaller
Cc: linux-kernel, devicetree, linux-pm, letux-kernel, notasas,
linux-omap
> Am 14.06.2017 um 11:25 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
>
> Changes V6:
> * split up -EPROBE_DEFER and irq allocation patch into small steps:
> * convert iio to devm allocation (by Sebsatian Reichel)
> * fix potentially wrong initialization sequence (by Grygorii Strashko)
> * add -EPROBE_DEFER
>
> 2017-05-21 12:38:24: Changes V5:
> * reworked max_current removal patch (comments by Sebastian Reichel)
> * resubmit missing madc connection for AC power detection
> * resubmit patch for irq allocation and -EPROBE_DEFER
> * rebased on 4.12-rc1
>
> Changes V4:
> * resent commit (original one did contain material not upstream)
>
> 2017-04-14 21:29:39: 2017-04-14 20:26:00: Changes V3:
> * worked in comments by Sebsatian Reichel
> * clarifications of some commit messages
> * rebased on v4.11rc-6
>
> It took a while (18 months) until we propose an updated patch for upstream...
>
> 2015-11-02 12:27:39: Changes V2:
> * worked in comments by Nishanth Menon <nm@ti.com>
> * added another patch which solves a probing/boot stall problem (irq allocation vs. -EPROBE_DEFER)
>
> V1:
> 4.3-rc1 introduced a new charger driver for the twl4030. This patch set fixes some
> issues.
>
> While making twl4030 changes from 4.3 operable we have found some issues
> during testing on GTA04 and OpenPandora.
>
> H. Nikolaus Schaller (4):
> power: supply: twl4030-charger: allocate iio by devm_iio_channel_get()
> and fix error path
> power: supply: twl4030-charger: move allocation of iio channel to the
> beginning
> power: supply: twl4030-charger: move irq allocation to just before
> irqs are enabled
> power: supply: twl4030-charger: add deferred probing for phy and iio
I should note that I have split up the original single commit into 4 separate patches.
If maintainers thing this is too fine granularity, please squash them.
The result is tested to work on GTA04.
^ permalink raw reply [flat|nested] 11+ messages in thread