Linux-OMAP Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 5/5] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce
@ 2021-01-17 21:48 Carl Philipp Klemm
  2021-04-04  7:21 ` Tony Lindgren
  0 siblings, 1 reply; 3+ messages in thread
From: Carl Philipp Klemm @ 2021-01-17 21:48 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-omap, Arthur Demchenkov, Tony Lindgren,
	Merlijn Wajer, Pavel Machek

Adds 80000 us sleep when the usb cable is plugged in to hopefully avoid
bouncing contacts.

Upon pluging in the usb cable vbus will bounce for some time, causing cpcap to
dissconnect charging due to detecting an undervoltage condition. This is a
scope of vbus on xt894 while quickly inserting the usb cable with firm force,
probed at the far side of the usb socket and vbus loaded with approx 1k:
http://uvos.xyz/maserati/usbplug.jpg.

As can clearly be seen, vbus is all over the place for the first 15 ms or so
with a small blip at ~40 ms this causes the cpcap to trip up and disable
charging again.

The delay helps cpcap_usb_detect avoid the worst of this. It is, however, still
not ideal as strong vibrations can cause the issue to reapear any time during
charging. I have however not been able to cause the device to stop charging due
to this in practice as it is hard to vibrate the device such that the vbus pins
start bouncing again but cpcap_usb_detect is not called again due to a detected
disconnect/reconnect event.

Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
---
 drivers/power/supply/cpcap-charger.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
index be7d1da7a5a5..3e5fbdbdd645 100644
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -650,6 +650,9 @@ static void cpcap_usb_detect(struct work_struct *work)
 		return;
 	}
 
+	/* Delay for 80ms to avoid vbus bouncing when usb cable is plugged in */
+	usleep_range(80000, 120000);
+
 	/* Throttle chrgcurr2 interrupt for charger done and retry */
 	switch (ddata->status) {
 	case POWER_SUPPLY_STATUS_CHARGING:
-- 
2.29.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 5/5] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce
  2021-01-17 21:48 [PATCH 5/5] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce Carl Philipp Klemm
@ 2021-04-04  7:21 ` Tony Lindgren
  2021-04-05  8:23   ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Tony Lindgren @ 2021-04-04  7:21 UTC (permalink / raw)
  To: Carl Philipp Klemm
  Cc: Sebastian Reichel, linux-pm, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek

* Carl Philipp Klemm <philipp@uvos.xyz> [210117 23:48]:
> Adds 80000 us sleep when the usb cable is plugged in to hopefully avoid
> bouncing contacts.
> 
> Upon pluging in the usb cable vbus will bounce for some time, causing cpcap to
> dissconnect charging due to detecting an undervoltage condition. This is a
> scope of vbus on xt894 while quickly inserting the usb cable with firm force,
> probed at the far side of the usb socket and vbus loaded with approx 1k:
> http://uvos.xyz/maserati/usbplug.jpg.
> 
> As can clearly be seen, vbus is all over the place for the first 15 ms or so
> with a small blip at ~40 ms this causes the cpcap to trip up and disable
> charging again.
> 
> The delay helps cpcap_usb_detect avoid the worst of this. It is, however, still
> not ideal as strong vibrations can cause the issue to reapear any time during
> charging. I have however not been able to cause the device to stop charging due
> to this in practice as it is hard to vibrate the device such that the vbus pins
> start bouncing again but cpcap_usb_detect is not called again due to a detected
> disconnect/reconnect event.
> 
> Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>

This patch fixes an issue where connecting a charger often fails for me:

Tested-by: Tony Lindgren <tony@atomide.com>


> ---
>  drivers/power/supply/cpcap-charger.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
> index be7d1da7a5a5..3e5fbdbdd645 100644
> --- a/drivers/power/supply/cpcap-charger.c
> +++ b/drivers/power/supply/cpcap-charger.c
> @@ -650,6 +650,9 @@ static void cpcap_usb_detect(struct work_struct *work)
>  		return;
>  	}
>  
> +	/* Delay for 80ms to avoid vbus bouncing when usb cable is plugged in */
> +	usleep_range(80000, 120000);
> +
>  	/* Throttle chrgcurr2 interrupt for charger done and retry */
>  	switch (ddata->status) {
>  	case POWER_SUPPLY_STATUS_CHARGING:
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 5/5] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce
  2021-04-04  7:21 ` Tony Lindgren
@ 2021-04-05  8:23   ` Sebastian Reichel
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2021-04-05  8:23 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Carl Philipp Klemm, linux-pm, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek


[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

Hi,

On Sun, Apr 04, 2021 at 10:21:46AM +0300, Tony Lindgren wrote:
> * Carl Philipp Klemm <philipp@uvos.xyz> [210117 23:48]:
> > Adds 80000 us sleep when the usb cable is plugged in to hopefully avoid
> > bouncing contacts.
> > 
> > Upon pluging in the usb cable vbus will bounce for some time, causing cpcap to
> > dissconnect charging due to detecting an undervoltage condition. This is a
> > scope of vbus on xt894 while quickly inserting the usb cable with firm force,
> > probed at the far side of the usb socket and vbus loaded with approx 1k:
> > http://uvos.xyz/maserati/usbplug.jpg.
> > 
> > As can clearly be seen, vbus is all over the place for the first 15 ms or so
> > with a small blip at ~40 ms this causes the cpcap to trip up and disable
> > charging again.
> > 
> > The delay helps cpcap_usb_detect avoid the worst of this. It is, however, still
> > not ideal as strong vibrations can cause the issue to reapear any time during
> > charging. I have however not been able to cause the device to stop charging due
> > to this in practice as it is hard to vibrate the device such that the vbus pins
> > start bouncing again but cpcap_usb_detect is not called again due to a detected
> > disconnect/reconnect event.
> > 
> > Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
> 
> This patch fixes an issue where connecting a charger often fails for me:
> 
> Tested-by: Tony Lindgren <tony@atomide.com>

Thanks, queued.

-- Sebastian

> > ---
> >  drivers/power/supply/cpcap-charger.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
> > index be7d1da7a5a5..3e5fbdbdd645 100644
> > --- a/drivers/power/supply/cpcap-charger.c
> > +++ b/drivers/power/supply/cpcap-charger.c
> > @@ -650,6 +650,9 @@ static void cpcap_usb_detect(struct work_struct *work)
> >  		return;
> >  	}
> >  
> > +	/* Delay for 80ms to avoid vbus bouncing when usb cable is plugged in */
> > +	usleep_range(80000, 120000);
> > +
> >  	/* Throttle chrgcurr2 interrupt for charger done and retry */
> >  	switch (ddata->status) {
> >  	case POWER_SUPPLY_STATUS_CHARGING:
> > -- 
> > 2.29.2
> > 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17 21:48 [PATCH 5/5] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce Carl Philipp Klemm
2021-04-04  7:21 ` Tony Lindgren
2021-04-05  8:23   ` Sebastian Reichel

Linux-OMAP Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-omap/0 linux-omap/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-omap linux-omap/ https://lore.kernel.org/linux-omap \
		linux-omap@vger.kernel.org
	public-inbox-index linux-omap

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-omap


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git