[Nexus 5X Q&A, Help & Troubleshooting] alvinhochun:
Since the Google engineer Benson Leung is reviewing some USB Type-C to Type-A/B adapters and bringing the proper USB spec to our attention, I decided to investigate some of the things related to charging in the Nexus 5X.

Related posts:

http://xdaforums.com/nexus-5x/accessories/google-engineer-reviewing-usb-type-c-t3241104

https://plus.google.com/+BensonLeung/posts/LH4PPgVrKVN

https://plus.google.com/+BensonLeung/posts/3Xf724K84HP

Here is the relevant dmesg of me plugging in an out-of-spec (10kΩ pullup) cable:

[59722.367419] __qpnpint_handle_irq: 1 triggered [0x2, 0x13,0x0] usbin-uv
[59722.542304] fusb301 5-0021: fusb301_work_handler: int_sts[0x05]
[59722.542899] fusb301 5-0021: sts[0x2f], type[0x08]
[59722.542909] fusb301 5-0021: fusb301_src_detected: FUSB_STATE_ATTACHED_SNK
[59723.370779] msm-dwc3 f9200000.ssusb: DWC3 exited from low power mode
[59723.513914] dwc3 f9200000.dwc3: Avail curr from USB = 3000
[59723.724676] android_work: android_work: sent uevent USB_STATE=CONNECTED
[59723.729421] android_work: android_work: sent uevent USB_STATE=DISCONNECTED
[59723.834497] android_work: android_work: sent uevent USB_STATE=CONNECTED
[59723.846230] android_usb gadget: high-speed config #1: fe80f0c8.android_usb
[59723.902145] android_work: android_work: sent uevent USB_STATE=CONFIGURED

Note the line that writes "Avail curr from USB = 3000". This line indicates that the USB controller detected the 10k pullup in the connector and configured the maximum available current is 3000mA (aka 3A).

On the lock screen, it says "charging rapidly".

In this case, `/sys/class/power_supply/usb/voltage_now` shows `4609780`, which indicates that the USB voltage detected on the device end is about 4.6V, which is 0.4V lower than 5V.. So, even though it is pulling 3A and luckily didn't fry the USB 3.0 port of my laptop, it probably won't charge as fast as the LG charger due to the huge voltage drop..

---

Here is the relevant dmesg of me plugging in another out-of-spec (10kΩ pullup) cable (which is noticeably thinner than the one before):

[59656.433560] __qpnpint_handle_irq: 1 triggered [0x2, 0x13,0x0] usbin-uv
[59656.644386] fusb301 5-0021: fusb301_work_handler: int_sts[0x05]
[59656.645294] fusb301 5-0021: sts[0x1f], type[0x08]
[59656.645313] fusb301 5-0021: fusb301_src_detected: FUSB_STATE_ATTACHED_SNK
[59657.426205] msm-dwc3 f9200000.ssusb: DWC3 exited from low power mode
[59657.573627] dwc3 f9200000.dwc3: Avail curr from USB = 3000
[59657.784381] android_work: android_work: sent uevent USB_STATE=CONNECTED
[59657.788909] android_work: android_work: sent uevent USB_STATE=DISCONNECTED
[59657.853872] SMBCHG: smbchg_update_input_max: update iusb = 500
[59657.895507] android_work: android_work: sent uevent USB_STATE=CONNECTED
[59657.907950] android_usb gadget: high-speed config #1: fe80f0c8.android_usb
[59657.962062] android_work: android_work: sent uevent USB_STATE=CONFIGURED

Now, this might seem similar to the previous one.

But notice the additional line "SMBCHG: smbchg_update_input_max: update iusb = 500". What does it mean? The lock screen also shows "charging slowly" at the same time.

Searching `smbchg_update_input_max` didn't yield any results.

Looking at the sysfs, I found this interesting entry `/sys/module/qpnp_smbcharger/parameters/smbchg_ibat_ocp_threshold_ua` which has the value `4500000`.

It appears to me that the driver `qpnp-smbcharger` is detecting the USB voltage, and if the voltage is below 4.5V it automatically changes the maximum USB input current to 500mA in order to keep the USB voltage within range. This slows down the charging by quite a lot, but at the same time it prevents the USB port/charger/battery pack from becoming a flaming toaster.

Relevant kernel source code: https://android.googlesource.com/ke...allow-dr/drivers/power/qpnp-smbcharger.c#3093

I am thinking that it may be possible to limit the USB input current (to 0.5 or 1.5A) by software, so that even if the USB cable is out of spec and doesn't follow the correct pullup arrangement, it can be used to charge the phone safely without exceeding the safe current limits.

How do you think?