Any interest in kernel patches to speed up USB charging?

Search This thread
Feb 11, 2014
29
31
Dear all,

As I'm still collecting more posts to reach this silly 10-posts-until-you-can-write-in-the-development-boards-limit I thought about providing useful information :)

So as I always wanted it I implemented a patched intel_mdf_battery that supports forcing charger currents higher than the environment suggests.

Facts:
When you connect any "real" or "smart" device to a regular USB port, it can only draw 100 mA or up to 500 mA if the host allows. This limits charging speed to about 350 mA at our Razr I (because you have to substract some amount for running the smartphone, in addition there is a ~350 mA cap in the charging chip).

Mostly all current USB ports are able to deliver much more power. In addition, sometimes you want to use a wall charger that does not correctly express its capability to deliver more than 500 mA (by shorting D+/D-).

There comes this handy patch:

By writing to an existing sysfs node for charger control (previously that featured only _limiting_ the total input current to 500 mA), you can now override the input current limit a) to 950 mA b) to 1500 mA (limit given by Razr I hardware).

How to:
Patch your custom compiled kernel with attached patch and install it :)
write 5 (950 mA) or 6 (no limit) to
/sys/devices/ipc/msic_battery/charge_enable

Charging current will be updated on next status update, usually every 30 seconds. Watch that update in dmesg or just see the actual charging current in
/sys/devices/pci0000:00/0000:00:00.4/i2c-1/1-0036/power_supply/max170xx_battery/current_now (or current_avg for a few seconds average)

In addition I am looking forward to implementing a charge threshold as the battery identifies itself as a 4,35V model. Being charged to 4,35 volts for prolonged time periods has a drastic negative effect on battery life! I wanna have an override because mostly I charge the device every day. Would be a lot better to use the battery from 85 to 35 percent (so max. 4,1V or so) than from 100 to 50 percent.

Is there any interest in those patches published, made nice (maybe a gui control program) or integrated in existing custom mods?

WARNING: I TAKE NO RESPONSIBILITY FOR ANY HARM DONE TO YOUR DEVICES BY USING THIS CHARGE CURRENT OVERRIDE.
YOU REALLY CAN FRY YOUR USB PORT!

(but it is very unlikely. Know about those handy charge-only usb cables that charge at up to 1A? I use them on different kinds of devices all the time and never hat any problem)

Oh, btw, attached patch also patches an ARRAY OUT OF BOUNDS write in original code! I did not look into details but i think that it did not have any effect because there are very unimportand arrays declared directly after the affected one.
 

Attachments

  • razri_usb_power_override.patch
    2.7 KB · Views: 96

YaPeL

Senior Member
Mar 1, 2011
453
154
thats amazing, great job.

edit: chances fo seeing this on the stock kernel without unlocked bl?
 
Last edited:
Dec 24, 2010
15
2
Awesome!

Have you considered submitting it as a patch to Omar's kernel? github 'link': github.com/oxavelar/XT890-Kernel-Gamma
 

Merinorus

Senior Member
Dec 16, 2013
59
22
I always been interested in this kind of stuff. If you didn't read this article yet you'll find some useful information about Lithium batteries :
batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries

Setting the limit up to 4200mV instead of 4350mV would approximately reduce by 10% the autonomy and double the longevity. Motorola, as many others, seem to favour autonomy ;) You'll do a great work if you succeed in finding how to do that !

How about USB 3 ? Is the limit still 350mA ? But for USB2 I think there is no point in increasing the limit. They're talking about it here but it lacks of technical details :
batteryuniversity.com/learn/article/charging_from_a_usb_port

Maybe you'll increasing the current up to 450mA, which would be nice actually.

USB 3 should handle 900mA while transferring data. It's close to the official charger (850mA at 5,1V). Could someone tell what current usb3 deliver on RAZR i ?

I'll try to find a way to implementing your patch because i've no idea :p Good work !

Sorry for my English
 
Feb 11, 2014
29
31
Setting the limit up to 4200mV instead of 4350mV would approximately reduce by 10% the autonomy and double the longevity. Motorola, as many others, seem to favour autonomy ;) You'll do a great work if you succeed in finding how to do that !
Yeah, I know quite good about batteries, thanks :) Implementing that change is very straightforward and easy, but we will need a nice app to control the settings at runtime.
How about USB 3 ? Is the limit still 350mA ? But for USB2 I think there is no point in increasing the limit. [...]

Maybe you'll increasing the current up to 450mA, which would be nice actually.

USB 3 should handle 900mA while transferring data. It's close to the official charger (850mA at 5,1V). Could someone tell what current usb3 deliver on RAZR i ?
As the device is USB2, the host port would fall back to USB2 also and announce 500mA capability. All Limits we talk about are total input currents. Powermanagement ICs these days are specially made for requirements with limited input current (no one is really interested in the charge current, limit is nearly always the supply as in laptops or USB devices).

Please reread my first post. We are IGNORING the USB spec and just draw more power here. That is totally fine (although not recommended and in no way guaranteed by me) for most standard usb host ports.

I'll try to find a way to implementing your patch because i've no idea :p Good work !

Well, maybe you should not :) You need a complete build environment for that, should take you a few days if you have never done such things. Just wait for some binary releases.
 

AthlonLozano

Senior Member
Apr 9, 2013
72
9
Interesting idea

Hey all!

I checked my /sys/devices/ipc/msic_battery/charge_enable and it's value is 4.

Well, can I change it manually to 5 or 6? Or it will mess with the phone?

Thanks in advance :D
 
Feb 11, 2014
29
31
Hey all!

I checked my /sys/devices/ipc/msic_battery/charge_enable and it's value is 4.

Well, can I change it manually to 5 or 6? Or it will mess with the phone?

It's supposed to be 4 at default.

Writing 5 or 6 without my patch will not work (will return Value Error). With a patched kernel it will do exactly what stated above, so yes, it will mess with the phone to disable USB charging limit :)

Please, as always, read before doing anything...
 

zlamar

Senior Member
Nov 9, 2011
103
13
Mars
It's supposed to be 4 at default.

Writing 5 or 6 without my patch will not work (will return Value Error). With a patched kernel it will do exactly what stated above, so yes, it will mess with the phone to disable USB charging limit :)

Please, as always, read before doing anything...

How and where to install this patch?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    Dear all,

    As I'm still collecting more posts to reach this silly 10-posts-until-you-can-write-in-the-development-boards-limit I thought about providing useful information :)

    So as I always wanted it I implemented a patched intel_mdf_battery that supports forcing charger currents higher than the environment suggests.

    Facts:
    When you connect any "real" or "smart" device to a regular USB port, it can only draw 100 mA or up to 500 mA if the host allows. This limits charging speed to about 350 mA at our Razr I (because you have to substract some amount for running the smartphone, in addition there is a ~350 mA cap in the charging chip).

    Mostly all current USB ports are able to deliver much more power. In addition, sometimes you want to use a wall charger that does not correctly express its capability to deliver more than 500 mA (by shorting D+/D-).

    There comes this handy patch:

    By writing to an existing sysfs node for charger control (previously that featured only _limiting_ the total input current to 500 mA), you can now override the input current limit a) to 950 mA b) to 1500 mA (limit given by Razr I hardware).

    How to:
    Patch your custom compiled kernel with attached patch and install it :)
    write 5 (950 mA) or 6 (no limit) to
    /sys/devices/ipc/msic_battery/charge_enable

    Charging current will be updated on next status update, usually every 30 seconds. Watch that update in dmesg or just see the actual charging current in
    /sys/devices/pci0000:00/0000:00:00.4/i2c-1/1-0036/power_supply/max170xx_battery/current_now (or current_avg for a few seconds average)

    In addition I am looking forward to implementing a charge threshold as the battery identifies itself as a 4,35V model. Being charged to 4,35 volts for prolonged time periods has a drastic negative effect on battery life! I wanna have an override because mostly I charge the device every day. Would be a lot better to use the battery from 85 to 35 percent (so max. 4,1V or so) than from 100 to 50 percent.

    Is there any interest in those patches published, made nice (maybe a gui control program) or integrated in existing custom mods?

    WARNING: I TAKE NO RESPONSIBILITY FOR ANY HARM DONE TO YOUR DEVICES BY USING THIS CHARGE CURRENT OVERRIDE.
    YOU REALLY CAN FRY YOUR USB PORT!

    (but it is very unlikely. Know about those handy charge-only usb cables that charge at up to 1A? I use them on different kinds of devices all the time and never hat any problem)

    Oh, btw, attached patch also patches an ARRAY OUT OF BOUNDS write in original code! I did not look into details but i think that it did not have any effect because there are very unimportand arrays declared directly after the affected one.
    2
    thats amazing, great job.

    edit: chances fo seeing this on the stock kernel without unlocked bl?

    Well, the changed are not that hard and so far only implemented as a proof of concept...

    Using with stock kernel not possible as that original driver is compiled into the kernel, so overriding it by module loading is not possible.