diff mbox series

[v3,1/1] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce

Message ID 20210104213223.a87d9e47050d5fb5ac3948e7@uvos.xyz
State New
Headers show
Series [v3,1/1] power: supply: cpcap-charger: Add usleep to cpcap charger to avoid usb plug bounce | expand

Commit Message

Carl Philipp Klemm Jan. 4, 2021, 8:32 p.m. UTC
Adds 40000 us sleep when the usb cable is plugged in to hopfully avoid bounceing
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 soccet 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 at 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 sutch that the vbus pins
start bouncing again but cpcap_usb_detect is not called again due to a detected
dissconnect/reconnect event.

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

Patch

diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
index c0d452e3dc8b..e6b230dd6de4 100644
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -613,6 +613,9 @@  static void cpcap_usb_detect(struct work_struct *work)
        if (error)
                return;
 
+    /* Delay for 40ms to avoid vbus bouncing when usb cable is plugged in */
+       usleep_range(40000, 60000);
+
        /* Just init the state if a charger is connected with no chrg_det set */
        if (!s.chrg_det && s.chrgcurr1 && s.vbusvld) {
                cpcap_charger_update_state(ddata, CPCAP_CHARGER_DETECTING);