Commit Graph

68 Commits

Author SHA1 Message Date
Ruben Rodriguez Buchillon
51e9e69f38 power: introducing pwr_avg console command
pwr_avg provides an average voltage, current, and power over the last
1 minute. It's up to the battery drivers to implement this
functionality.
This change allows us to have better power tracking while minimizing
the power impact on the EC, because
- the pwr_avg command only needs to be called once every minute, and is
short, thus less expensive to parse on ECs without a UART buffer
- the work done to keep the avg is partially done by the batteries
already and it's just a question of retrieving it.

undefined on wheatley since no power debugging planned on that board.

usage:
> pwr_avg
mv = 7153
ma = -605
mw = -4327

BUG=chromium:752320
BRANCH=None
TEST=make buildall -j

Change-Id: Id1a3479d277aedf90dfa965afb4ee9136654b1cf
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/823884
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-01-16 04:08:26 -08:00
Philip Chen
40a693aea8 battery/max17055: Support advanced config with battery profile
We've been using the basic configuration (EZ config) to
initialize max17055.
It doesn't require battery profile, but the accuracy of fuel gauge
is not the best.

With a full battery profile in place, we should extend our driver
to import the battery profile for advanced config.
It should boost the accuracy.

BUG=b:69634899
CQ-DEPEND=CL:812481
BRANCH=none
TEST=manually test on Scarlet rev2, 'battery' command shows reasonable
reading no matter is_ez_config is set as 0 or not.

Change-Id: Iaea2d3e20f5de4207a86d4fff5f1561aaba4d362
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/813038
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-12-11 19:37:46 -08:00
Furquan Shaikh
d33eb02aef sb_fw_update: Get rid of CONFIG_SB_FIRMWARE_UPDATE
CONFIG_SB_FIRMWARE_UPDATE is dead on ToT. So, get rid it completely.

BUG=b:69695376
BRANCH=None
TEST=make -j buildall

Change-Id: Ic1eedff21d82f729a73ec9a7c1d554b6b571e827
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/792013
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-11-28 17:56:29 -08:00
Philip Chen
10dc1b8aad battery/max17055: Allow charging
We didn't set BATT_FLAG_WANT_CHARGE in battery_get_params(), so
battery command always shows 'charging not allowed'.

Let's set the flag in the same condition as it is set in
battery/smart.c.

BUG=b:68027469
BRANCH=none
TEST='battery' on EC console shows 'Charging: Allowed'

Change-Id: Ifbdb6aee2572c8fc5f67103ca940738fb221ce5d
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/749025
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-11-03 01:53:39 -07:00
Philip Chen
f28ab5c2ec battery/max17055: Use macros to clean up duplicate code
BUG=none
BRANCH=none
TEST=manually test on Scarlet rev2 and confirm max17055 still
initializes and works by 'battery' command

Change-Id: I3f553a1392cc1c4364ac605111564501bd706ec2
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/737712
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
2017-11-02 11:07:13 -07:00
Philip Chen
a109ebc3b1 battery/max17055: Measure temperature using external thermistor
By default max17055 measures from internal temperature sensor.

BUG=b:68170538
BRANCH=none
TEST=place a heat source on top of the battery pack and see
temperature rise from 'battery' command

Change-Id: I1c0bb981e366a8a73d2e14e6c1fc92327069e8f1
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/735080
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-10-24 07:29:43 -07:00
Lin Huang
3c2adda326 battery/max17055: update battery remaining capacity message dynamic
kernel will get the battery info through command "ectool battery",
so we need to get the remaining capacity dynamic.

BUG=b:65494883
BRANCH=none
TEST=run "ectool battery" in kernel, and get the battery info.

Change-Id: Idf824f6dc1e72acd17156c03d81c0ca87adc109f
Signed-off-by: Lin Huang <hl@rock-chips.com>
Reviewed-on: https://chromium-review.googlesource.com/658160
Reviewed-by: Philip Chen <philipchen@chromium.org>
2017-09-13 21:47:07 -07:00
Philip Chen
8e7bad0482 battery/max17055: Specify desired charging voltage/current
BUG=b:64821815, b:63870414
CQ-DEPEND=CL:621777
BRANCH=none
TEST=plug in AC, and check 'charger' command on ec console

Change-Id: Ic60bcab7fd0ccc2ea73471ac46e9b0b887f251d9
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/621776
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-08-21 12:52:13 -07:00
Philip Chen
d2108bbcaa battery/max17055: Wait longer for initial config
max17055 sometimes fails to finish configuration due to timeout.
Let's wait longer.

BUG=b:63870414
BRANCH=none
TEST=boot scarlet rev1 10 times and ensure MODELCFG.REFRESH bit is
cleared when retries value > 10.

Change-Id: I62984c19014a244a378180bab6683e2e6f842cd1
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/617653
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2017-08-18 14:27:19 -07:00
Philip Chen
20f05a3488 battery/max17055: Process negative current/temperature right
On max17055, current/temperature register values are in 2's
complement format.

Therefore we need to consider the case of negative values before
doing bitwise operation.

BUG=b:63870414
BRANCH=none
TEST=run 'battery' command and confirm the reported discharge
current looks reasonable.

Change-Id: Iea0c554aecf2b410fc27b547e01ee7a583a0dd00
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/617654
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-08-18 14:27:19 -07:00
Philip Chen
19bd0659b3 battery/max17055: Add max17055 fuel gauge driver
BUG=chromium:736603
BRANCH=none
TEST=Follow the steps below
1) add MAX17055 config to Scarlet and build the code
2) hook up max17055 eval board and a single cell battery
3) battery command from ec console shows reasonable numbers
   for temperature, voltage, and charge percentage

Change-Id: I3f838ff92c591665e9f1d0a7ba636ff83d9b7612
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/578300
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-07-27 15:44:01 -07:00
Sam Hurst
edf46467b9 cleanup: Remove charge_state_v1
All boards have been transitioned to charge_state_v2.c
So charge_state_v1.c, HOOK_CHARGE_STATE_CHANGE, and
CONFIG_CHARGER_TIMEOUT_HOURS can be removed

BUG=chrome-os-partner:36272
TEST=make -j buildall
BRANCH=none

Change-Id: I3f20c5198ea75185f9894deb792575a1be31432a
Reviewed-on: https://chromium-review.googlesource.com/435467
Commit-Ready: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-02-06 14:50:32 -08:00
Vijay Hiremath
66ea614158 smart_battery: Cleanup smart battery & SB users code
BUG=chrome-os-partner:61173
BRANCH=none
TEST=Manually tested on Reef. Battery info works.

Change-Id: I6e867eee38885186f8e63a934f52e826f0cf72fd
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/422998
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2017-01-02 16:16:59 -08:00
Vijay Hiremath
98402bb466 smart_battery: Add console command to read ManufacturerAccess() data
Added console command to read ManufacturerAccess() data on a given
register block.

BUG=chrome-os-partner:59660
BRANCH=none
TEST=Enabled config on Reef.
     Successfully able to read ManufacturerAccess() data

Change-Id: Ic86ae1b44ca8016634c48b54b1130d30fdd2d3fa
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/409638
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-12 23:55:08 -08:00
Vijay Hiremath
bc34c98edd smart_battery: Remove smart charger unreachable code
Smart battery code has I2C read/write code for smart chargers
which is an unreachable code for few boards hence removed it.

BUG=none
BRANCH=none
TEST=make buildall -j

Change-Id: I79933f61893c66447c686a81073c92f6a16e2d48
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/396279
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-10-11 01:47:52 -07:00
Vijay Hiremath
f9272713da i2c: Add i2ctest console command
Added i2ctest console command to test the reliability of the I2C.
By reading/writing to the known registers this tests provides the
number of successful read and writes.

BUG=chrome-os-partner:57487
TEST=Enabled the i2ctest config on Reef and tested the
     i2c read/writes.
BRANCH=none

Change-Id: I9e27ff96f2b85422933bc590d112a083990e2dfb
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/290427
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-23 15:10:08 -07:00
Bill Richardson
bb15561db5 cleanup: DECLARE_CONSOLE_COMMAND only needs 4 args
Since pretty much always, we've declared console commands to take
a "longhelp" argument with detailed explanations of what the
command does. But since almost as long, we've never actually used
that argument for anything - we just silently throw it away in
the macro. There's only one command (usbchargemode) that even
thinks it defines that argument.

We're never going to use this, let's just get rid of it.

BUG=none
BRANCH=none
CQ-DEPEND=CL:*279060
CQ-DEPEND=CL:*279158
CQ-DEPEND=CL:*279037
TEST=make buildall; tested on Cr50 hardware

Everything builds. Since we never used this arg anyway, there had
better not be any difference in the result.

Change-Id: Id3f71a53d02e3dc625cfcc12aa71ecb50e35eb9f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/374163
Reviewed-by: Myles Watson <mylesgw@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-08-24 16:30:10 +00:00
Victor Prupis
a56aabfc65 Standard locations for board specific battery code
Moved battery code for samus and ryu from driver tree to board tree.

BUG=chrome-os-partner:42486
BRANCH=master
TEST=none

Change-Id: Iaad1456323f85e5852d8aa8e3e2d453b26e2d452
Signed-off-by: Victor Prupis <vprupis@google.com>
Reviewed-on: https://chromium-review.googlesource.com/371402
Reviewed-by: Stefan Reinauer <reinauer@google.com>
2016-08-19 14:21:17 -07:00
Anton Staaf
068cd08506 Deferred: Use deferred_data instead of function pointer
Previously calls to hook_call_deferred were passed the function to call,
which was then looked up in the .rodata.deferred section with a linear
search.  This linear search can be replaced with a subtract by passing
the pointer to the deferred_data object created when DECLARE_DEFERRED
was invoked.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
CQ-DEPEND=CL:*255812
TEST=make buildall -j

Change-Id: I951dd1541302875b102dd086154cf05591694440
Reviewed-on: https://chromium-review.googlesource.com/334315
Commit-Ready: Bill Richardson <wfrichar@chromium.org>
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-04-18 17:32:40 -07:00
Kyoung Kim
e6902404a2 Kunimitsu: remove console commands for code size
Remove following EC console commands to reduce code size:
- battfake
- apthrottle
And none of commands above are used in 'auto test'.

This is a squash of
- https://chromium-review.googlesource.com/337657
- https://chromium-review.googlesource.com/338018

BUG=none
BRANCH=firmware-glados-7820.B
TEST=make -j buildall

Change-Id: I11d2c5514f2714f0a46416feec2b2c47666fb462
Signed-off-by: Kyoung Kim <kyoung.il.kim@intel.com>
Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/338893
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-04-14 17:28:17 -07:00
Mary Ruthven
bf91b00486 Smart battery: wait for any battery response
Currently the EC waits until it reads a battery status with the flag
STATUS_INITIALIZED set, but the EC does not use this flag for charging
or any other battery operation. If this flag is not set, it does not
mean that the battery is unusable, it just means that its values may not
be trustworthy.

This change will remove the check for STATUS_INITIALIZED and just check
that the battery responds. The battery response shows that the battery
is connected and can be used by the EC.

BRANCH=none
BUG=chromium:564893
TEST=see that device without STATUS_INITIALIZED set will exit
battery_wait_for_stable() without timing out.

Change-Id: I07778e8570b6d9400b61beec6b2e222984a40692
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/315200
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-12-03 02:22:03 -08:00
Mary Ruthven
cb4a76e802 i2c: get battery information from charge state
ARM systems currently use SBS kernel driver which talks to the battery
through I2C passthu in the EC. Instead when asking for battery
information try getting it from the charge state machine first, and
then try the battery if charge state does not have the information.
This reduces latency by cutting out the battery response time.

BUG=chromium:484841
BRANCH=none
TEST=check that power_supply_info works properly on Jerry

Change-Id: If4da15ccabe412adc31fc94b189089ebb3e9265c
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/307905
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-10-27 11:52:34 -07:00
Alec Berg
9669eeede2 charge_state_v2: fix battfake command race condition
This moves battfake console command to the battery driver.
This fixes a race condition with using the 'battfake' command
where charge_state_v2 could return the real battery percentage
even when a faked percentage is specified, if a higher priority
task uses the battery state of charge in between when the
battery is read, and when the fake state of charge overwrites
the battery parameter.

BUG=chrome-os-partner:45878
BRANCH=none
TEST=use tap for battery with a faked state of charge. the tap
for battery queries the battery percentage a lot, so without
this CL, the tap sequence often temporarily jumps to different
percentages and colors. with this CL, the tap sequence works
great.

Change-Id: I3ae0866d1ff7bb8d0c51355cd6b958310766f19e
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/302711
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-10-06 22:57:08 -07:00
Vincent Palatin
2aebfda07f ryu: update charging temperature upper limit
Do not charge above 48 C.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=smaug
BUG=chrome-os-partner:45631
TEST=none

Change-Id: I43260ab6079732ab3779d77ed64e3d872c5da4bd
Reviewed-on: https://chromium-review.googlesource.com/302442
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 071b068816722958cebf326857b68b4bb06ecb5b)
Reviewed-on: https://chromium-review.googlesource.com/302475
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2015-10-02 12:55:50 -07:00
Vincent Palatin
bd34af5d78 ryu: change charging temperature limits
Do not charge below 5 C or above 50 C.
Still charge at 0.1C between 5 C and 10 C.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=smaug
BUG=chrome-os-partner:45631
TEST=none

Change-Id: I6788088054ef4a5eb176eb2185b5e1c576128e09
Reviewed-on: https://chromium-review.googlesource.com/302232
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-09-24 19:36:20 -07:00
Vincent Palatin
3154abd5c3 ryu: put additional temperature checks for battery charging
Whatever the battery gas gauge returns, ensure we never charge below 0 C
and above 60 C.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=smaug
BUG=chrome-os-partner:44820
TEST=charge a Smaug DVT, use a cold spray on the battery and see the
charge stop.

Change-Id: I8670fbe1713b35aa079bebc9c5bb70e9f28cf8ac
Reviewed-on: https://chromium-review.googlesource.com/299945
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 1d19259be3b0721667835ce01bfe719fb547785e)
Reviewed-on: https://chromium-review.googlesource.com/299906
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
2015-09-15 19:17:52 -07:00
Vijay Hiremath
1b45f6ed71 Driver: Add macros to conditionally compile the console commands
Added macros to conditionally compile the console commands to save the
memory. These macros can be enabled/disabled in the board specific files.

BUG=none
TEST=make buildall -j
BRANCH=none

Change-Id: I108a072c333762cd24ea973612202c9cc4d40914
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/288950
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-07-29 21:18:25 +00:00
Bill Richardson
104f811e67 cleanup: fix all the header guards
This unifies all the EC header files to use __CROS_EC_FILENAME_H
as the include guard. Well, except for test/ util/ and extra/
which use __TEST_ __UTIL_ and __EXTRA_ prefixes respectively.

BUG=chromium:496895
BRANCH=none
TEST=make buildall -j

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Iea71b3a08bdec94a11239de810a2b2e152b15029
Reviewed-on: https://chromium-review.googlesource.com/278121
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-06-18 19:07:00 +00:00
Randall Spangler
fe9e3bf565 Remove obsolete board-specific code
Now that we've removed boards from ToT, also delete board-specific
code used only by the removed boards.

There are still more things to remove (unused charging chips, LED
drivers, COMx support).  More CLs coming.

BUG=chromium:493866
BRANCH=none
TEST=make buildall -j

Change-Id: Ie6bdeaf96e61cadd77e3f6336c73b9b54ff4eabb
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/276524
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-06-10 18:24:05 +00:00
Vincent Palatin
142a950aff Skip the battery device name reading on BQ27742
Contrary to the BQ2751 and BQ27741 it is sharing code with, BQ27742 does
not have a "device name" register. So we need to skip the I2C reads else
the battery_device_name() function returns an I2C error and the charge
code retries until the end-of-time to read it hogging the CPU.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=chrome-os-partner:38401
TEST=run on Ryu P4 and verify that we are no longer seeing 20ms of I2C
transactions every 100ms on the battery I2C bus.

Change-Id: I961af54017f661ee928058b346a42b7206ad8217
Reviewed-on: https://chromium-review.googlesource.com/262449
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2015-03-26 19:56:11 +00:00
Vic Yang
920d701647 ryu: Implement charging profile
This allows us to charge at a faster rate.

BRANCH=Ryu
BUG=None
TEST=Charge Ryu P3 in S5 and check charging current.

Change-Id: If8fbaa42d34df45f3d4db35ba50031c511b0c7af
Signed-off-by: Vic Yang <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/242666
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
2015-01-29 23:32:13 +00:00
Alec Berg
6fb8ab3369 samus: modify fast charging profile to avoid charge problems
Several modifications to samus fast charging to fix bug where
charging circuit stops charging the battery.

- Fix bug: if we have a bad temperature reading, fast charging should
  ignore it.
- Change the fast charging high temperature profile to set a charging
  voltage equal to the maximum of 8.3V and the current battery voltage.
- Divide the normal temperature profile into two phases, low voltage
  charging and high voltage charging. Once we transition to second
  phase, don't allow it to go back to phase 1 unless AC is removed.

On samus, we have to make sure we never command the BQ to a charging
voltage that is below the present battery voltage or else the INA will
lose power and we will not be able to charge the battery until AC
is disconnected.

This also changes charge_state_v2 so that the fast charging profile
override is called even when AC is disconnected to avoid jumps in
temperature as seen by the fast charging code.

Also changes the voltage threshold for transitioning from phase 1 to
phase 2 of normal temp charging so that the transition is taken a little
earlier to match the desired profile slightly better.

BUG=chrome-os-partner:35491
BRANCH=samus
TEST=Added custom console command to be able to directly control the
battery temperature that charger_profile_override() uses:

static int command_chgtemp(int argc, char **argv)
{
	char *e;
	if (argc < 2)
		return EC_ERROR_PARAM_COUNT;

	chg_temp = strtoi(argv[1], &e, 10);
	if (*e)
		return EC_ERROR_PARAM1;

	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(chgtemp, command_chgtemp,
			"",
			"",
			NULL);

Using this command, I jumped back and forth between all three temperature
fast charging regions and made sure that (1) we never set a charging voltage
below the present battery voltage and (2) we never stop charging the battery.
I ran this test at low battery and high battery percentage and with low load
(G3) and high load (S0 with webgl aquarium).

Change-Id: I035603a4ab48a156ab43f8c93f21200c4b664aab
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243143
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-01-26 19:45:42 +00:00
Alec Berg
0ef55f5899 samus: add battery cutoff
Add battery cutoff to samus.

BUG=chrome-os-partner:35744
BRANCH=samus
TEST=tested "cutoff" console command cuts off battery
and "ectool batterycutoff" from host cuts off battery

Change-Id: I88194c9c601594dee144933cabef5b1dc536ab0d
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/242830
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-24 06:41:59 +00:00
Vic Yang
48eed0bebc bq27541: report battery present state
The battery driver is not reporting battery present state, and as a
result, is_present flag always remain NOT_SURE. Fix it.

BRANCH=Ryu
BUG=None
TEST=On Ryu, 'chgstate' and see 'is_present = YES'.

Change-Id: I84bedc390158797bf1e67e612d0bb3f526292dfa
Signed-off-by: Vic Yang <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/242970
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
2015-01-24 01:45:47 +00:00
Myles Watson
c171751654 driver: BQ27621 scaling bug fix
Design capacity and Design Energy need to be multiplied by the scaling factor.

BUG=None
TEST=Manual test with hadoken without charging enabled.  Observed the battery
level decreasing.
BRANCH=NONE

Change-Id: Icb5f74766c2416128277df4fe1bb00fc7307f5e5
Signed-off-by: Myles Watson <mylesgw@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/242890
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-24 00:32:29 +00:00
Myles Watson
f0fe0160a5 battery: Add support for TI's BQ27621_g1 fuel gauge.
define CONFIG_CMD_BATDEBUG to enable console commands.

If the battery is larger than 6Ah or smaller than 150mAh, scale the parameters
transparently to the user using macros.

BUG=chrome-os-partner:34477
BRANCH=none
TEST=Custom console commands for the fuel gauge
I also used a Logic16 from Saleae and the fuel gauge on hadoken.

Signed-off-by: Myles Watson <mylesgw@chromium.org>

Change-Id: I959d51c3188336e4ad0983528ad7e53a2955a764
Reviewed-on: https://chromium-review.googlesource.com/234285
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Myles Watson <mylesgw@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Myles Watson <mylesgw@chromium.org>
2014-12-31 00:01:00 +00:00
Alec Berg
91bbfb780c samus: set BQ voltage to battery voltage when AC disconnected
Set charge state machine voltage to just above the battery voltage
when AC is disconnected. Also send new current before sending new
voltage to charger when there is a change. These changes reduce
input current spikes caused by current inrush into the battery and
thereby decrease chance of overcurrenting power supply on connect.

BUG=chrome-os-partner:33862
BRANCH=samus
TEST=load onto samus instrumented with input current probe. when
AC is attached note that initial current spike is much lower with
this change.

Change-Id: I7760cd2b709c6b3536cf2a9449bb1f46800ce10a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/237245
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2014-12-23 18:16:18 +00:00
Alec Berg
ccb45ff8a2 samus: enabled fast charging for EVT ATL cells
Enable fast charging with profile designed for ATL cells
that will be used in EVT.

BUG=chrome-os-partner:23776
BRANCH=none
TEST=Took detailed charging/discharging data and verified
that the actual profile matches the desired profile and that
the fast charging profile is actually faster than the
standard. See bug report for more info and data collected.

Change-Id: Ic11ab89e48afb73987b8013abf8b0564e1138156
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212980
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-09-23 00:04:49 +00:00
Vic Yang
d86f672d14 Add support for BQ27742 battery gauge chip
This reuses most of the existing BQ27541 driver, but changed necessary
parts to make it work.

BUG=none
TEST=Boot on Ryu. See battery charging.
BRANCH=factory-ryu-6212.B

Change-Id: I3a7325a821c81f84396bcc328036b6a5e7749a2e
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217198
Reviewed-by: Alec Berg <alecaberg@chromium.org>
(cherry picked from commit f44593e20bf61a2243d7baaae901c912ca798d75)
Reviewed-on: https://chromium-review.googlesource.com/218413
2014-09-17 01:24:11 +00:00
Sheng-Liang Song
51a279cf3a EC: smart battery using smbus API
Ref: Common Smart Battery System Inferface Specification v8.0.
Ref: http://smbus.org/specs/smbus20.pdf

- Enable smbus read/write APIs with compile options

BUG=chrome-os-partner:30930
BRANCH=ToT,glimmer
TEST=Verified with LGC & Simplo firmware update.

Change-Id: I3f4bb23147f22365adb378c2e39c40d5ba100889
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209906
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-09-03 22:49:57 +00:00
Sheng-Liang Song
51e48026c2 EC: Add smart battery firmware update driver
Ref: Common Smart Battery System Inferface Specification v8.0.

- Added 2 new AP->EC Command APIs
	EC_CMD_SB_FW_UPDATE, EC_CMD_ENTERING_MODE
- Implemented common smart battery update drivers.

BUG=chrome-os-partner:24741
CQ-DEPEND=CL:210032
CQ-DEPEND=CL:210033
CQ-DEPEND=CL:215720
BRANCH=ToT,glimmer
TEST=Verified on LGC & Simplo smart battery

Change-Id: Ice6e60b1b04762217ae7613356d6925777c06abf
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/205323
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-09-03 22:49:28 +00:00
Sheng-Liang Song
dcb9bb6026 EC: clean up i2c_read_string
- Removed duplicate (similar) i2c_read_string functions.
- Kept one generic (weak) copy in common/i2c.c.
- TBD: Need support start/stop flags for STM32 family devices

BUG=chrome-os-partner:23569
BRANCH=ToT
TEST=Verified with smart battery firmware update application on glimmer.
Passed LGC & Simplo Battery.

Change-Id: I6d9446c60b6a36aef9a6179242c081084199c8e2
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209866
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-29 03:00:20 +00:00
Vic Yang
9262797ee6 pd: Print warning before flash erase if on PD power
During flash erase operation, read is stalled and thus interrupt might
be serviced later. This can cause PD communication to fail and thus the
board reboots if there is no battery. Print a warning message in this
case.

BUG=chrome-os-partner:31127,chrome-os-partner:31207,chrome-os-partner:31362
TEST=Boot Ryu, on software sync, see warning message before board
reboots.
BRANCH=None

Change-Id: If327a4f533fd2dfa83f92531148bd52ace927e03
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212264
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-14 22:44:44 +00:00
Alec Berg
0815df9cbf samus: ryu: set input current limit based on PD negotiation
Set input current limit based on the max current from the
PD negotiation. For samus, this information is passed to
the EC as a host command. For ryu, the max current is set
directly following a negotiation.

CONFIG_CHARGER_INPUT_CURRENT is now just the default limit,
but after a successful PD negotiation, the limit can be
raised.

Note, for now the input current limit for samus is set to
2/3 of the value negotiated for. This is due to hardware
problems measuring input current on p2b boards.

BUG=chrome-os-partner:28532, chrome-os-partner:24461
BRANCH=none
TEST=tested on a samus. Verified input current limit using
"charger" console command from EC. Input current limit
after a reboot is 512. When zinger is plugged in, it jumps
to the appropriate value (currently 1280mA), and when
the negotiation is changed using the "pd 0 dev 5" command
on the PD console, the input current limit is adjusted to
match (2000mA).

Change-Id: Iab9186a0f9814655e3240217a9baf4a38f15f84d
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211023
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-09 00:20:06 +00:00
Vincent Palatin
63429076b3 battery: fix BQ27541/BQ27741 gas gauge driver
Update the code to be compatible with charge v2 expectations :
never return EC_ERROR_UNIMPLEMENTED for battery information else the
charge code continuously tries to read them again.

Fix the State Of Charge reading : on BQ27741 the gas gauge gets confused
if we do a 16-bit I2C read while a 8-bit read works perfectly.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=none
TEST=run a Ryu connected to a Kirby battery and check the output of the
"battery" command.

Change-Id: Ic1d6128dc02efa47662fa5ca5b9e5de62420ebe8
Reviewed-on: https://chromium-review.googlesource.com/207273
Reviewed-by: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
2014-07-29 02:20:11 +00:00
Vic Yang
915224b6d7 ryu: Kick battery out of disconnect state when AC is attached
Like Samus, the battery can be placed into a disconnect state. This CL
implements the necessary function to determine if it is so and kick it
out of this state when possible.

BUG=chrome-os-partner:30633
TEST=Put a battery in this state. Plug in AC. Verify the battery is
revived.
BRANCH=None

Change-Id: I074a72a2efe3844cbdfb0eda16a25fd8d1755a9b
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209634
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-07-25 03:46:03 +00:00
Shawn Nematbakhsh
b9677a48c8 samus: Kick battery out of disconnect state when AC is attached
The Samus battery can be placed into a disconnect state by asserting a
disconnect input signal. In this state, the battery will not function
until a charging current is applied. This patch adds detection of the
disconnect state. If a battery in disconnect state is found, a current
is force-applied to the battery to kick it out of disconnect.

BRANCH=None
TEST=Manual on Samus.
1. Put battery into disconnect state
2. Pull AC, then reattach AC
3. Verify "found battery in disconnect state" is seen on the
EC console.
4. Pull AC and verify that EC console is still accessable
Also verify that battery gets out of reset state:
1. Pull AC
2. Issue "i2cxfer w16 0 0x16 0x0 0x12" command on EC console
3. Re-attach AC
4. Pull AC and verify that EC console is still accessable
BUG=chrome-os-partner:29465

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ib4268887fb483094ac4e641749200268160d3014
Reviewed-on: https://chromium-review.googlesource.com/209013
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
2014-07-23 02:29:59 +00:00
Duncan Laurie
447eafb55a samus: fix input current to 2048
This changes the input current limit to 2048mA with no ramp up.
Problem is that the bq24773 is doing a really poor job of measuring
input current, so even though the zinger side can support 3A, the
samus side can cause over currents down to 2300mA. This is set
consertavily to avoid over current errors and will need to be
updated when the hardware allows.

BUG=chrome-os-partner:24461
BRANCH=none
TEST=Used bench top power supply to power multiple samus 2A proto
boards and gathered data on max current samus was drawing based on
input current setting. Samus was often underestimating current by
300-700mA.

Change-Id: Iabeb0d026f2b72a9ee539d92579ee6d11aeaa56b
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/205143
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-06-24 20:04:55 +00:00
Alec Berg
49cc3902b0 samus: allow charging of dead battery requesting nil
On samus battery, when the battery is dead it reports 0 for desired
voltage, current, and state of charge. In this case we should allow
charging.

Added a CONFIG option for this that should be removed as soon as
the battery side is fixed.

With this CL, when a dead samus battery is used and a charger is
connected, we attempt to charge it.

BUG=chrome-os-partner:29465
BRANCH=none
TEST=test on a samus with a dead battery. w/o this CL, the battery
never charges because the charging not allowed flag is set. With this
CL, the battery charges.

Change-Id: Ic61f27a27237166d33cb9ea5f024d3ef6360ce82
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202603
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-06-07 01:29:53 +00:00
Alec Berg
113ea43a69 samus: limit input current to 2.5A to prevent over currenting zinger
Set maximum input current limit to ~2.5A to prevent over current
faults on zinger. Note, we still get over current faults sometimes
but it always clears in < 10seconds.

BUG=chrome-os-partner:28611
BRANCH=none
TEST=Test with a samus 1.9 and a zinger. Plug and unplug charger
many times and make sure that we are eventually able to successfully
negotiate for power and start charging.

Change-Id: I5a7adf9fc7f5ed7a0c7dfdb620e0c1474f72a878
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/201154
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-05-23 04:50:19 +00:00