networkimprov / arch-packages

1 stars 0 forks source link

battery charger driver #39

Open networkimprov opened 8 years ago

networkimprov commented 8 years ago

Manual: http://www.ti.com/lit/ds/symlink/bq24190.pdf PMIC TRM: http://www.droid-developers.org/images/2/21/Tps65950_TRM.pdf Source: https://github.com/networkimprov/linux/blob/anvl-v4.7/drivers/power/bq24190_charger.c Discussion of USB charging: https://lwn.net/Articles/694062/ Charger Manager API: https://github.com/networkimprov/linux/blob/anvl-v4.7/include/linux/power/charger-manager.h See also: https://github.com/networkimprov/usb-manager/issues/3

1) Review commits to mainline source since it landed. Code was originally commissioned for anvl project. https://github.com/torvalds/linux/commits/master/drivers/power/bq24190_charger.c

2) Check these variations of the driver for stuff we might need... bq2419x from android 3.10 Tegra kernel: https://android.googlesource.com/kernel/tegra/+/android-tegra-3.10/drivers/power/bq2419x-charger.c patches for it: https://github.com/CaptainThrowback/kernel_android-tegra-flounder-3.10/commits/BeyondStock-M/drivers/power/bq2419x-charger.c another variation, pt 1: https://github.com/CaptainThrowback/kernel_android-tegra-flounder-3.10/blob/BeyondStock-M/drivers/power/bq2419x-charger-htc.c pt 2: https://github.com/CaptainThrowback/kernel_android-tegra-flounder-3.10/blob/BeyondStock-M/drivers/power/htc_battery_bq2419x.c charge-related patches in that repo: https://github.com/CaptainThrowback/kernel_android-tegra-flounder-3.10/commits/BeyondStock-M

3) Attempt to enable charging after a disconnect on error. This can happen if the USB cable is not plugged into a hub in a straight angle and the USB hub port is loose enough to allow slight sideways movement.

4) Handle OTG pin if its gpio is specified in the dts. See https://github.com/networkimprov/arch-packages/blob/master/archlinux-anvl/anvl-util/anvl-otg.sh

5) power_supply_changed() uevents don't indicate what changed, so we can't write a udev rule that triggers only when vbus_stat changes. Possible fixes: a) un/register bq24190-charger on vbus-up/down to issue add/remove uevents. Move the sysfs group to bq24190-battery. Enables this: http://unix.stackexchange.com/questions/63232/what-is-the-correct-way-to-write-a-udev-rule-to-stop-a-service-under-systemd b) un/register a virtual device on vbus-up/down to issue add/remove uevents. See http://stackoverflow.com/questions/5970595/create-a-device-node-in-code c) register a 3rd power_supply to call power_supply_changed on vbus up/down. See https://github.com/networkimprov/linux/commits/anvl-v4.7-hack_bq24190 (note: crashes on boot if usb connected) d) add user_stat field to let the user maintain a state value (e.g. previously reported vbus_stat value). This cannot be done with udev env{x} variables; see [1] below. e) implement sysfs_notify, so user apps can poll() /sys...charger/*

6) uevent for disconnect often appears long after the plug is pulled. musb-hdrc sees it immediately. If we can't get a prompt event from the charger, we'll need one from usb subsystem.

7) Issue bq24190-battery changed uevents only if f_reg or ss_reg change is relevant to battery.

8) bq24190_charger_supplied_to gives "main-battery". Is there such an entity, if not should it be "bq24190-battery", and in either case would it actually receive charger events since no external_power_changed callback is implemented? https://www.kernel.org/doc/Documentation/power/power_supply_class.txt

9) Call power_supply_changed with good reason. Clear bdi->ss_reg/f_reg in probe() and in resume() before interrupts enabled. Drop bdi->first_time. Do set_mode_host() in resume. Drop power_supply_changed() in resume(). See https://github.com/networkimprov/linux/commits/anvl-v4.7-lb-bq24190-a/drivers/power/bq24190_charger.c

10) Fault mgmt looks wrong. irq_handler_thread() should read fault reg 2x on fault; if 1st read!=0, cache 2nd read, else cache 0. Attribute getters use cache. Use RW spinlocks http://www.makelinux.net/ldd3/chp-5-sect-5

11) Do we get vbus_stat & chrg_stat interrupts after hw_init() if USB connected before boot?

12) What causes periodic 3-4s bursts of uevents when connected to usb charging port (usb phy modules blacklisted, no gadget config)?

13) Verify that charger draws 1.5A from charging port given suitable cable.

14) For USB host mode, we need to add regulator framework support to the charger driver so the USB PHY driver can just request the regulator for 5V VBUS as needed.

15) Disable omap off_mode while charging (while usb connected?) as this triggers a bug which loses interrupts.

[1] These rules give multiple on and zero off results because env{vbus} gets erased KERNEL=="bq24190-charger", ATTR{f_vbus_stat}!="0", ENV{VBUS}!="1", ENV{VBUS}="1", RUN+="/bin/bash -c 'echo vbus_on > /dev/console'" KERNEL=="bq24190-charger", ATTR{f_vbus_stat}=="0", ENV{VBUS}=="1", ENV{VBUS}="0", RUN+="/bin/bash -c 'echo vbus_off > /dev/console'"

networkimprov commented 8 years ago

Any response re twl4030 phy uevent patch?

I'd like to delete these branches from github; s'OK?

https://github.com/networkimprov/linux/commits/anvl-v4.7-bq24190-v2 (yours) https://github.com/networkimprov/linux/commits/anvl-v4.7-mjr-bq24190 https://github.com/networkimprov/linux/commits/anvl-v4.7-mjr-musb https://github.com/networkimprov/linux/commits/anvl-v4.7-hack_bq24190 (mine) https://github.com/networkimprov/linux/commits/anvl-v4.7-lb-bq24190-a

mranostay commented 8 years ago

On Thu, Sep 22, 2016 at 12:58 AM, Liam notifications@github.com wrote:

Any response re twl4030 phy uevent patch?

Nothing so far. Just Tony's Acked-by.

Also I just submitted the power supply poll interval patchset to the LKML.. so expect feedback from that as well.

I'd like to delete these branches from github; s'OK?

I'll review today and delete the un-needed branches

https://github.com/networkimprov/linux/commits/anvl-v4.7-bq24190-v2 (yours) https://github.com/networkimprov/linux/commits/anvl-v4.7-mjr-bq24190 https://github.com/networkimprov/linux/commits/anvl-v4.7-mjr-musb https://github.com/networkimprov/linux/commits/anvl-v4.7-hack_bq24190 (mine) https://github.com/networkimprov/linux/commits/anvl-v4.7-lb-bq24190-a

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/networkimprov/arch-packages/issues/39#issuecomment-248836466, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwXOSgxD0-82hLEXCHXai-Ros8lw1drks5qsjUIgaJpZM4GveUL .

networkimprov commented 8 years ago

Is this in our repo? Or an accident? It conflicts with the rest of our changes, which we can submit in a single patchset after a bit more testing... http://lkml.iu.edu/hypermail/linux/kernel/1609.2/05302.html

mranostay commented 8 years ago

On Mon, Sep 26, 2016 at 2:15 PM, Liam notifications@github.com wrote:

Is this in our repo? Or an accident? It conflicts with the rest of our changes, which we can submit in a single patchset after a bit more testing... http://lkml.iu.edu/hypermail/linux/kernel/1609.2/05302.html

Doesn't have any real functional changes but I can fix the conflict easily. We change add it to the patchset series as well.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/networkimprov/arch-packages/issues/39#issuecomment-249699882, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwXOYF6Z9fBAD58hQ_fh3Hj7mtv-Rgdks5quDYHgaJpZM4GveUL .

networkimprov commented 8 years ago

Let's withdraw it. It only fits in the patchset as a revert; that variable is gone. Pls post to a branch here before upstreaming, since I might have other ideas :-)

networkimprov commented 8 years ago

Deleted these branches from github: anvl-v4.7-bq24190-v2 anvl-v4.7-mjr-bq24190 anvl-v4.7-mjr-musb anvl-v4.7-hack_bq24190 anvl-v4.7-lb-bq24190-a

networkimprov commented 8 years ago

Added item to main list above re disabling off_mode during charge/connect.

networkimprov commented 8 years ago

Re QoS patch, this usually is clearer to me than if/else:

    pm_qos_update_request(&bdi->pm_qos_request,
        ss_reg & BQ24190_REG_SS_VBUS_STAT_MASK ? 30000 : PM_QOS_DEFAULT_VALUE)
networkimprov commented 8 years ago

Can you rebase QoS patch onto anvl-v4.7-lb-bq24190-2 so I can test this with those changes?

mranostay commented 8 years ago

On Thu, Oct 6, 2016 at 2:24 PM, Liam notifications@github.com wrote:

Can you rebase QoS patch onto anvl-v4.7-lb-bq24190-2 so I can test this with those changes?

Rebased and pushed to anvl-v4.7-qos-v2

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/networkimprov/arch-packages/issues/39#issuecomment-252093225, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwXOVr6FyeUf_mhI_LBruRo-xp-8c24ks5qxWcfgaJpZM4GveUL .

networkimprov commented 8 years ago

Posted a fix, see description for details: https://github.com/networkimprov/linux/commit/eed01ad0

mranostay commented 8 years ago

On Fri, Oct 7, 2016 at 2:15 AM, Liam notifications@github.com wrote:

Posted a fix, see description for details: networkimprov/linux@eed01ad https://github.com/networkimprov/linux/commit/eed01ad0

That is what I get for trusting the conflict lines of code :)

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/networkimprov/arch-packages/issues/39#issuecomment-252191191, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwXOWAzdZ7llhr-HlmUeX4emxtQDGUtks5qxg2YgaJpZM4GveUL .

networkimprov commented 8 years ago

Well the test only succeeded on disconnect, which is the disappearing event this code is supposed to prevent loss of :-)

mranostay commented 7 years ago

On Sat, Dec 10, 2016 at 5:25 PM, Liam notifications@github.com wrote:

Matt, why do I get this failure: [ 12.951202] bq24190-charger 1-006b: invalid value for ti,minimum-sys-voltage: 0 [ 12.958923] bq24190-charger 1-006b: invalid value for ti,precharge-current: 0 [ 12.966613] bq24190-charger 1-006b: invalid value for ti,termination-current: 0

For this data:

Probably should be using of_property_read_u32() since by default all integers are 32-bit sized when compiled in a dtb.

&i2c2 { ... bq24190: charger@6b { reg = <0x6b>; compatible = "ti,bq24190"; pinctrl-names = "default"; pinctrl-0 = <&bq24190_irq_pin>; interrupt-parent = <&gpio5>; interrupts = <24 0x0>; / gpio152 / ti,minimum-sys-voltage = <3200>; ti,precharge-current = <256>; ti,termination-current = <128>; }; };

With this code:

    if (of_property_read_u16(bdi->dev->of_node, "ti,minimum-sys-voltage", &input)==0) {
            if (input >= BQ24190_REG_POC_SYS_MIN_MIN
             && input <= BQ24190_REG_POC_SYS_MIN_MAX)
                    bdi->sys_min = input;
            else
                    dev_err(bdi->dev, "invalid value for ti,minimum-sys-voltage: %u\n",input);
    }

    if (of_property_read_u16(bdi->dev->of_node, "ti,precharge-current", &input)==0) {
            if (input >= BQ24190_REG_PCTCC_IPRECHG_MIN
             && input <= BQ24190_REG_PCTCC_IPRECHG_MAX)
                    bdi->iprechg = input;
            else
                    dev_err(bdi->dev, "invalid value for ti,precharge-current: %u\n",input);
    }

    if (of_property_read_u16(bdi->dev->of_node, "ti,termination-current", &input)==0) {
            if (input >= BQ24190_REG_PCTCC_ITERM_MIN
             && input <= BQ24190_REG_PCTCC_ITERM_MAX)
                    bdi->iterm = input;
            else
                    dev_err(bdi->dev, "invalid value for ti,termination-current: %u\n",input);
    }

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

networkimprov commented 7 years ago

That was it. _read_u16() should give a compile error on this platform, grr.