USB OTG Charging, Nexus 7 Flo (2013)

OK, so the USB OTG works just fine, i’ve added the driver for my ‘easycap’ for rearview-camera, and enabled module loading.

Now to dig into how to enable the use of charging while using USB OTG.

In the msm kernel directory, there is a file ./Documentation/usb/msm_otg.txt.

We want ID_A: Configure device to act as host and don’t supply VBUS. The corresponding code is in ./drivers/usb/otg/msm_otg.c

So I plug in a ‘Y’ cable. I plug in a USB device on the ‘OTG’ segment and its detected properly (so far so good).

I plug in power to the other side of the Y, and I get:

msm_otg msm_otg: Failed notifying 1 charger type to PMIC
msm_otg msm_otg: Avail curr from USB = 2
msm_otg msm_otg: current: 500 -> 2 (mA)
msm_hsusb msm_hsusb: CI13XXX_CONTROLLER_SUSPEND_EVENT received
VBUS_DET = H
notifying plugin
msm_otg msm_otg: Failed notifying 0 charger type to PMIC
msm_otg msm_otg: Avail curr from USB = 0
msm_hsusb msm_hsusb: CI13XXX_CONTROLLER_DISCONNECT_EVENT received
android_work: android_work: sent uevent USB_STATE=DISCONNECTED
mtp_release
INOK=H
========================================================
bq27541_battery_callback usb_cable_state = 0
========================================================
battery_callback cable_wake_lock 5 sec...
elan-ktf3k 3-0010: Update power source to 0
The USB cable status = CHARGER_NONE
msm_otg msm_otg: Failed notifying 0 charger type to PMIC
msm_otg msm_otg: phy_reset: success
bq27541_get_capacity = 67% ret= 69
bq27541_get_psp voltage_now= 3997000 uV
bq27541_get_psp temperature= 260 (0.1¢XC)
bq27541_get_psp status: Not charging ret= 0x0100
msm_otg msm_otg: USB in low power mode
request_suspend_state: wakeup (3->0) at 11409619596093 (2013-08-03 19:32:30.799981455 UTC)
late_resume: call handlers

Hmm. No charge indication, but action occurred.

This comes from msm_otg_notify_charger() which calls msm_otg_notify_chg_type() and gets an error. There’s a big TODO in that latter function 🙂

OK, the chg_type it used was CHARGER_CDP, and the work was done in pm8921_set_usb_power_supply_type(), being passed POWER_SUPPLY_TYPE_USB_CDP as the mode.

Looking in pm8921_set_usb_power_supply_type(), we see:

int pm8921_set_usb_power_supply_type(enum power_supply_type type)
{
 if (!the_chip) {
 pr_err("called before init\n");
 return -EINVAL;
 }
if (type < POWER_SUPPLY_TYPE_USB)
 return -EINVAL;
power_supply_changed(&the_chip->usb_psy);
 power_supply_changed(&the_chip->dc_psy);
 return 0;
}

Now, ignoring the use of a < in an enum (tsk tsk), that part is not failing (see include/linux/power_supply.h), and presumably the called before init is not the issue, so how could this be an error?

However, its actually using the inline code from include/linux/mfd/pm8xxx/pm8921-charger.h:

static inline int pm8921_set_usb_power_supply_type(enum power_supply_type type)
{
 return -ENXIO;
}

Hmm…  CONFIG_PM8921_CHARGER is not set in the config. (see https://android.googlesource.com/kernel/msm.git/+/android-msm-flo-3.4-jb-mr2/arch/arm/configs/flo_defconfig)

And there’s probably a reason. the board-flo.c references it, and SMB345. CONFIG_CHARGER_SMB345 is set. The SMB345 is presumably from Summit Microelectronics (http://www.summitmicro.com/prod_select/products.htm), and presumably very similar to the 346 & 347.

the driver doesn’t get initialised (even w/ CONFIG_PM8921_CHARGER set), so i’m a bit puzzled.

Comments

4 Responses to “USB OTG Charging, Nexus 7 Flo (2013)”

  1. greg

    Any progress with this? I’ve applied the Timur Mehrvarz patches and gotten usb + OTG charging to work in the v1 (grouper) nexus 7 kernel. I’d like to get a nexus 7 v2 (flo / razor), but I’m holding back while I try to find out whether anyone has managed to hack OTG charging (with fast charge) into the kernel.

    thanks for posting this! These will be good notes if I bite the bullet, buy one of these, and end up tinkering with usb otg charging on it myself.

    1. Don Bowman

      I’ve made some progress. I am hoping to have it operational this week.

      I have found where the missing code is in the smb345 driver, and have a trigger arriving when i plug in the power to the OTG cable. But i am still experimenting w/ what to send to the pmic driver to cause the charging to start.

      will post when i have it.

      1. spereree

        I believe this (the first code snippet) is the problem why my (and hundreds of other owner’s) HTC Ones won’t charge. It throws an error in the notifications bar: “Can’t charge while in USB Host mode” – while nothing is connected. I’m looking for a kernel that will fix this… see these posts in xda-developers forums
        http://forum.xda-developers.com/showthread.php?t=2417377

  2. Alexey

    Any updates on this? Experiencing the same problem, wondering if solution has been found.

Leave a Reply

Your email address will not be published. Required fields are marked *