Commit Graph

63 Commits

Author SHA1 Message Date
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
Sheng-Liang Song
7d40063d46 samus: added gyro support for lsm6ds0
Changed motion_sense task to assume sensors are unpowered in G3
and re-initialize sensors every time coming out of G3.

Added EC command line test utils as well.
Fixed some bug during unit tests.

BUG=chrome-os-partner:27313,27320
BRANCH=ToT
TEST=Verified on Samus.

Tested with accel EC CLIs
accelread, accelrange, accelrate, accelres

Tested accelcalib, a ACCEL calibration util, and it succeeded.

Tested sysfs interface:
cd /sys/bus/iio/devices/iio:device1
 cat in_accel_*_gyro_raw

Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Change-Id: I5752b00c03e1942c790ea4f28610fda83fa2dcbc
Reviewed-on: https://chromium-review.googlesource.com/211484
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-26 03:05:55 +00:00
Shawn Nematbakhsh
a048d76e0d Refactor accel / gyro driver to accomodate various configurations
Previously our accel / gyro drivers assumed that we had exactly two of
each identical part in the system. Some systems may have different
configurations, so allow this to be specified at the board-level.

Note that our motion_sense algorithm currently assumes that we have one
accelerometer in the lid and one in the base -- we'll need to fix that
in another CL.

BUG=chrome-os-partner:27320
TEST=Compile-only. Tested in future Samus commit.
BRANCH=None.

Change-Id: I1fae1f6c578fedebe78b473a5d66a5794ccaae00
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212321
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-19 06:59:28 +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
Dominic Chen
fe1981a414 pi3usb9281: Implement driver for Pericom USB switch
BRANCH=none
BUG=none
TEST=verify that usb switch funcitons

Change-Id: Ie897a2ae94042abefbb349d30dfa183caaec9ed0
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209846
Reviewed-by: Vic Yang <victoryang@chromium.org>
2014-08-13 13:21:00 +00:00
Alec Berg
283fe98939 samus: ryu: fix charge state machine init of input current
Currently charge state machine resets input current limit to default
every time AC is connected. Problem is by the time charge state machine
gets around to setting input current, it could have already been set
by successful PD negotiation, and this ends up overriding that value.
This fix has the state machine store desired input current limit, as
determined from PD negotation or any other place, and send last desired
input current limit on AC connect.

BUG=chrome-os-partner:24461
BRANCH=none
TEST=load on samus, test toggling between "pd 0 dev 5" and "pd 0 dev 20",
and test plugging and unplugging zinger numerous times, and verify charger
command always gives the expected input current limit based on PD
negotiation.

Change-Id: I18d8acc9e2085739e783c9c70c682d46bcce7fdb
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211639
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-08-12 05:11:39 +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
Anton Staaf
2ebf92a0a8 cprints: Revert some changes from CPRINTF to CPRINTS
These changes were made in files that did not have the [%T ... ]
pattern.  These files were broken by the change because they still
contained uses of the CPRINTF macro.  There were two options to fix
this, switch to the CPRINTS macro and get the timestamp added to
these strings, or switch those files back to defining the CPRINTF
macro.  Switching back seems like the right thing since it doesn't
change the output of those debug messages.

This commit also adds newline termination to a few invocations of
CPRINTF that were missing it, but obviously wanted it.

This breakage is only visible with a particular set of CONFIG_
defines that no boards currently use.

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

BRANCH=none
TEST=make buildall -j

Change-Id: I784b52dc385b29f05d7b9bc1521e37597409153b
Reviewed-on: https://chromium-review.googlesource.com/206281
Reviewed-by: Vic Yang <victoryang@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-07-03 02:52:35 +00:00
Duncan Laurie
635a57eede samus: hack to read AC present state from PD
The ACOK input to the EC is not connected to the charger so
that signal cannot be relied on for AC presence.  Instead
have the PD report when it negotiates to 20V and when it
disconnects and have the EC use that for AC presence.

BUG=chrome-os-partner:29841
BRANCH=none
TEST=test charging with zinger on samus system.

Change-Id: Ia9096a24ab05d110e31910218dc8c214a846a9a4
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/205145
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-06-27 18:31:31 +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
Vincent Palatin
b162ac513a twinkie: initialize INAs at startup
Disable INA1 to avoid leaking current from VCONN2.
Put the calibration in INA0.

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

BRANCH=none
BUG=chrome-os-partner:28337
TEST=plug Twinkie and measure VBUS current/voltage.

Change-Id: I6b063460a86a7a3dd87ec5e3c2c9b992b66db146
Reviewed-on: https://chromium-review.googlesource.com/204468
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2014-06-18 21:11:15 +00:00
Dominic Chen
5408b10490 tsu6721: add function to control output pins
BRANCH=none
BUG=none
TEST=check mux actually switches

Change-Id: If157302329c2b570814d2a071078949bfe368356
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/203492
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-06-13 03:12:45 +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
Vincent Palatin
976260dc69 add INA231 driver
Add a driver for INA231 Power/Current monitoring I2C chip.

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

BRANCH=none
BUG=chrome-os-partner:28337
TEST=make BOARD=twinkie
and run "ina" command on Twinkie.

Change-Id: Id322aca74cbb6bbf866aed22e7815c0e01951414
Reviewed-on: https://chromium-review.googlesource.com/202205
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-06-03 23:23:50 +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
Vic Yang
ffac23c0ea Add cprints() and ccprints()
Our code base contains a lot of debug messages in this pattern:
  CPRINTF("[%T xxx]\n") or ccprintf("[%T xxx]\n")
The strings are taking up spaces in the EC binaries, so let's refactor
this by adding cprints() and ccprints().

cprints() is just like cprintf(), except that it adds the brackets
and the timestamp. ccprints() is equivalent to cprints(CC_CONSOLE, ...)

This saves us hundreds of bytes in EC binaries.

BUG=chromium:374575
TEST=Build and check flash size
BRANCH=None

Change-Id: Ifafe8dc1b80e698b28ed42b70518c7917b49ee51
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/200490
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-05-21 20:32:17 +00:00
Bill Richardson
10aecec841 Replace magic numbers with #defines for charger bq24773.c
BUG=none
BRANCH=none
TEST=buildall -j

Change-Id: I125fbe7716f6c8b78011c3a39745ec4992074795
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/199796
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-05-15 05:26:35 +00:00
Alec Berg
ac78a35cf1 fruitpie: disable battery charging chip ILIM pin
Typically bq24xxx charging chip limits input current to minimum of
register value and ILIM pin. For fruitpie, the current limit will
be decided solely in software, and the hardware pin will be ignored.

BUG=chrome-os-partner:28611,chrome-os-partner:28311
BRANCH=none
TEST=Tested on fruitpie. Verified that current limit can be set
above the ILIM pin value of 500mA.

Change-Id: Ia687446f95f9d18fde9d2b4ebb0e1c093aebf885
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/198940
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-05-14 20:53:03 +00:00
Bill Richardson
3f94eba930 Samus: Update configuration for proto1.9
Start of changes to Samus' board.h and board.c to support proto1.9

BUG=chrome-os-partner:28721
BRANCH=ToT
TEST=make buildall

Change-Id: I70590c1f9845430801a6c2939ac92be289750ca3
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/199242
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-05-12 20:02:34 +00:00
Wonjoon Lee
0a166c0467 Adding waiting function when battery boot-up
Some battery uses clock stretching feature, and this could disturb
PMU communication before battery going stable.
AP does not know and will attempt PMU setting, and could get fail
For various battery indicates usually 1s for stable
(even if it is much less in real world 200ms~700ms)
Let's checking 'battery is ready' when first pump-up power.

BRANCH=ToT
BUG=chrome-os-partner:28289
TEST=Going battery shipmode and plug-in AC, See booting and EC log
Disconnect battery, and plug-in and see booting and EC log

Change-Id: Idd8ae2ab4ec164b11fe67413bbf647cad18bc481
Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com>
Reviewed-on: https://chromium-review.googlesource.com/197990
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Doug Anderson <dianders@chromium.org>
Tested-by: Doug Anderson <dianders@chromium.org>
2014-05-07 21:43:04 +00:00
Louis Yung-Chieh Lo
4ba7a1502d cleanup: add square brackets to make test parser easier
This may not contain all. I filtered out possible code by the
following command:

  find . -name "*.h*" -o -name "*.c*" | xargs grep -n CPRINTF |  \
      grep -v "\[" | grep -v define | less

BUG=none
BRANCH=none
TEST=make buildall tuntests

Change-Id: I674f84f5966b34aeb8d4321d22629b450627a120
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/197997
2014-05-07 03:41:22 +00:00
Dave Parker
6f21e3f5c1 Rename battery_vendor_params() to battery_override_params()
Charger V1 only. This is a clearer name for the intent of
the function to override the charging parameters requested
by the battery. This also disabmiguates this function with
a new host command to get and set arbitrary vendor
parameters in the battery.

BUG=chrome-os-partner:25145
BRANCH=ToT
TEST=`make buildall -j`.

Change-Id: I1e8762d359c0e91c5b2a539553d22c12c9850c03
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/195823
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/197164
Reviewed-by: Yung-chieh Lo <yjlou@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-04-29 03:11:05 +00:00
Louis Yung-Chieh Lo
3ac560d41b battery: don't talk to battery after cut-off
Add a shortcut in smart battery driver and i2c passthru. Once
the battery cut-off order is submitted (in the factory line),
the EC will no longer talk to battery.

BUG=chrome-os-partner:28248
BRANCH=tot,nyan
TEST=See below
> remove AC, cutoff: expect system is off.
> cutoff, then remove AC: expect system is off.
> cutoff, wait for 1 min, then remove AC: expect system is off.

Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>

Change-Id: Ied963c19d17d581ce99e4543469cf2fa165f0439
Reviewed-on: https://chromium-review.googlesource.com/196657
Tested-by: Yung-chieh Lo <yjlou@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Yung-chieh Lo <yjlou@chromium.org>
2014-04-25 03:41:58 +00:00
cloud_lin
295e409ea9 Big: Correct the charger IC driver
Add bq24735 driver and move to here for further developing

BRANCH=big
BUG=None
TEST=test basic charing/discharging function

Change-Id: I66c22a29cf94383cec86c5cf53db82494504fa77
Reviewed-on: https://chromium-review.googlesource.com/196541
Reviewed-by: Yung-chieh Lo <yjlou@chromium.org>
Tested-by: Lin Cloud <cloud_lin@compal.com>
Commit-Queue: Lin Cloud <cloud_lin@compal.com>
2014-04-24 08:35:03 +00:00
Alec Berg
3b36337be1 accel: add accel driver for lsm6ds0
This adds the basics for the accelerometer potion only of the ST
lsm6ds0 accel/gyro. Still need to add the acceleration interrupt
functionality, and all of the gyro portion of the chip.

BUG=none
BRANCH=none
TEST=Tested on a samus prototype hacked up to have the lsm6ds0 connected
to the EC i2c bus. Added motion sense task to the samus tasklist, added
accelerometer information to the samus board file, and tested console
functions interacting with accelerometer. The data seems reasonable,
and can successfully change data rate and range.

Change-Id: I7949d9c20642a40ede82dc291b2c80f01b0a7d8b
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/196426
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-04-23 20:50:34 +00:00
Dave Parker
cdb70250d0 Smart Battery: Buffer battery parameters while they are updated
BUG=chrome-os-partner:27736
BRANCH=ToT
TEST=Verify battery charges and 'battery' console command returns
sane values.

Original-Change-Id: I57d9d432bce4ed28678dddc43fa5166905525557
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193338
Reviewed-by: Bill Richardson <wfrichar@chromium.org>

Conflicts:
	driver/battery/smart.c

Change-Id: Idae79859961da888e652b3af306ba49c467b412e
Reviewed-on: https://chromium-review.googlesource.com/193655
Tested-by: Dave Parker <dparker@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Dave Parker <dparker@chromium.org>
2014-04-12 01:49:37 +00:00
Alec Berg
529548208c accel: add host command to modify accel params and add ectool command
Created a host command to set/get various motion sensor parameters and
added an ectool command to use that host command.

The host command is created such that the first argument is a
sub-command. Sub-commands created include:
dump: dumps all current motion sensor data
info: returns general information about each motion sensor
ec_rate: set/get the EC sampling rate of sensors
sensor_range: set/get the sensor range (ie +/- 2G,4G,8G)
sensor_odr: set/get the sensor output data rate (ie 50Hz, 100Hz, ...)

For sensor_range and sensor_odr parameters, since the host doesn't know
what are valid values for the parameter, the host can specify to round
up or down to the nearest valid value. For example, the host can specify
to set the output data rate to at least 100Hz, and the EC will return
the closest valid output data rate that is at least 100Hz.

BUG=chrome-os-partner:27321
BRANCH=rambi
TEST=Test on a glimmer using ectool from vt-2 prompt:

> ectool motionsense help
Usage:
  motionsense                            - dump all motion data
  motionsense info NUM                   - print sensor info
  motionsense ec_rate [RATE_MS]          - set/get sample rate
  motionsense odr NUM [ODR [ROUNDUP]]    - set/get sensor ODR
  motionsense range NUM [RANGE [ROUNDUP]]- set/get sensor range
>
> ectool motionsense
Sensor 0: 0, 0, 1024
Sensor 1: 1024, 0, 0
Sensor 2: None
> ectool motionsense info 0
Type:     accel
Location: base
Chip:     kxcj9
> ectool motionsense ec_rate
10
> ectool motionsense ec_rate 1000
1000
> ectool motionsense odr 0
100000
> ectool motionsense odr 0 40000 1
50000
> ectool motionsense range 0 8
8

After running this I verified on the EC console that all the parameters
were set appropriately. I tested the EC sampling rate was 1000ms by
running lidangle on and making sure samples were displayed roughly every
second. I verified the sensor odr and range by defining
CONFIG_CMD_ACCELS and typing:

> accelrange 0
8
> accelrate 0
50000

Change-Id: I444e2f0eafabd607f1c7aa78b5c4e91f6cb06387
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/192064
Reviewed-on: https://chromium-review.googlesource.com/193307
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-04-05 03:25:47 +00:00
Bill Richardson
f06ad7e2ab Add host command to control charge state v2
This replaces the obsolete and temporary (ha!) EC_CMD_CHARGE_DUMP host
command with EC_CMD_CHARGE_STATE. This is used to monitor and adjust the new
charge state implementation, including any board-specific customizations.

This command is a single catch-all command with multiple subcommands
(similar to EC_CMD_LIGHTBAR_CMD) so that we don't have to keep adding new
top-level host commands just to support incremental changes.

BUG=chrome-os-partner:23776
BRANCH=ToT
TEST=manual

From the AP, try these commands:

  ectool chargestate show
  ectool chargestate param
  ectool chargestate param <NUM>
  ectool chargestate param <NUM> <VALUE>

Watch the EC console and use its "chg" command to verify the effects of
setting various params.

Note: the Samus-specific fast-charging profile override is param 0x10000.
You can check it with the EC console "fastcharge" command.

Change-Id: Iad2f773a085bc25c05073b3eed9866f122ae9d78
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193305
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-04-05 01:42:21 +00:00
Bill Richardson
9f40d3f90e Add charge_state_v2 algorithm for use by Samus
This is a complete rewrite of the charge_state task used by x86 platforms.
Rather than having a bunch of state-specific functions, each with their own
error handling and special cases, this is organized like so:

  Forever:
  1. Read everything we can from the battery and charger.
  2. Figure out what we'd like to do (including error handling).
  3. Allow for customization to override that.
  4. Do it.

Things I need to file bugs for are marked with "TODO(wfrichar)". I'll file
the bugs after this CL goes in, so that they'll have something relevant to
refer to.

BUG=chrome-os-partner:20881
BRANCH=ToT
TEST=manual

  make buildall -j

Try it on Samus, watch it charge from nearly empty to full, both with and
without fastcharge enabled.

Also undefine CONFIG_BATTERY_PRESENT_CUSTOM, plug and unplug the battery to
be sure the trickle charging logic is correct when it can't tell if the
battery is present.

Change-Id: I3935cd3b87f322eb52178f8a675a886c16b75d58
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191767
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-04-01 21:37:32 +00:00
Vincent Palatin
5945c6462f Add driver for TI BQ24773 charger
Add support TI BQ24773 1S/2S/3S NVDC battery charger.

This is not a "Smart Battery" compliant charger IC, it should and cannot
use the sbc_ helpers.

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

BRANCH=none
BUG=none
TEST=on FruitPie, run "charger" command on the EC console,
add the charger task and see the battery charging.

Change-Id: I6f470184f0ce424a05007e493d802dcdb2156477
Reviewed-on: https://chromium-review.googlesource.com/191212
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-03-29 02:17:27 +00:00
Bill Richardson
91a5fa0194 Add more fields and error flags to struct batt_params
This adds two battery parameters that need to be monitored constantly:
remaining_capacity and full_capacity (that one only changes occasionally,
but we have to notify the AP when it does).

It also adds the is_present field to indicate whether the battery is
physically present or not (when we can tell), so we know whether to try to
wake up a deep-discharged battery.

Along with that, we clean up the error flags to provide indication of which
fields were unable to be read, and replace the manual logical-or of all
errors as they were set with a bitmask (BATT_FLAG_BAD_ANY).

No functionality is changed, only new & better information is provided for
use in the upcoming cleanup of the charge state machine.

BUG=chrome-os-partner:20881
BRANCH=ToT
TEST=make buildall -j

All targets build; all tests pass.

Change-Id: I4312c2fdd3cf2dd9570718e90571eff796b269db
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191917
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-28 15:23:01 +00:00
Alec Berg
6d745d8fd3 accel: added mutex to protect critical code in kxcj9 accel driver
Added a mutex in kxcj9 accelerometer driver to prevent concurrent
accesses when writing to critical registers on sensor.

Also added more console debugging functions behind CONFIG_CMD_ACCELS
to allow writing a new range, resolution, or data rate to each
sensor.

BUG=chrome-os-partner:26884
BRANCH=rambi
TEST=Tested by defining CONFIG_CMD_ACCELS and playing around with
writing/reading various parameters on each sensor and making sure
that the accelerometer is still reporting data every so often using
the lidangle on command.

Change-Id: Ic009951d508b125d1c479d042455713c9c8de761
Original-Change-Id: I2038f167fc8ca51723b0d1330aa090ab5158cf15
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191173
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191611
2014-03-27 18:43:08 +00:00
Alec Berg
9cb8f02605 accel: Add disable and re-enable accel around critical register writes
According to the kionix datasheet, you are supposed to disable the
accel before writing to various critical registers. We haven't had
a problem thus far, but better to match the datasheet to avoid future
problems.

BUG=none
BRANCH=rambi
TEST=ran on glimmer. made sure accels still work using lidangle command.

Change-Id: I363435862ed473b315afdf6d2aea64cebe3bac55
Original-Change-Id: If2d86c39c24c6ba13e118850c5e3f6c0174f4eb7
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190486
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191610
2014-03-27 18:43:05 +00:00
Alec Berg
eb14066447 accel: clapper: glimmer: Add support for accelerometer interrupt.
Adding in support for accelerometer interrupt for use currently
in clapper and glimmer. This is disabled by default and can
be enabled with CONFIG_ACCEL_INTERRUPTS.

BUG=none
BRANCH=rambi
TEST=Manual test on a glimmer using accelint console command.

On console enter:
accelint 0 32
When you tap the lid, it should fire the interrupt and print msg
to console.

accelint 1 32
Tap the base and it will fire another interrupt.

Change-Id: Iaab324945e34d527140399ec4f06efd812a62840
Original-Change-Id: I0329112fdcae3c8adc0ca07e74fef7a591d4b9a1
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190099
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191549
2014-03-26 19:31:25 +00:00
Alec Berg
5bd3d71259 rambi: change EC accel sampling rate and default sensor output data rate.
Two accelerometer changes:
- Lower accel sampling rate when chipset is off to 10Hz. Increase
sampling rate back up to 100Hz when transitioning to S0.
- Change the default output data rate of the accelerometers to 100Hz
which matches the EC sampling rate when in S0.

BUG=none
BRANCH=rambi
TEST=manual testing. used lidangle command to verify that in S0,
EC is sampling at 100Hz, and in S3 or lower it is sampling at 10Hz.

Change-Id: Ie4e20f45f9371d674c3325a362d2729c331fac4f
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190032
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-20 23:51:55 +00:00
cloud_lin
24417669a6 Big: Add ectool discharge command.
BRANCH=big
BUG=None
TEST=Run ectool chargecontrol command with each option (normal,
 idle, discharge) on Big. Verifiy battery is discharging
 in discharge mode via EC console 'battery' command.
Signed-off-by: Cloud Lin <Cloud_Lin@compal.com>

Change-Id: Iab150c36df64016d06831a6a6c620742738ae2af
Reviewed-on: https://chromium-review.googlesource.com/189450
Reviewed-by: Katie Roberts-Hoffman <katierh@chromium.org>
Tested-by: Lin Cloud <cloud_lin@compal.com>
Commit-Queue: Lin Cloud <cloud_lin@compal.com>
2014-03-18 11:24:20 +00:00
Alec Berg
0e3ff013cc rambi: fix potential bug in accelerometer init
Fixed a potential bug in accelerometer initialization that could result
in failing to write the desired accelereometer settings. Before writing
the desired settings, we first send a command to perform a software reset.
While waiting for software reset to complete, if we have an I2C error,
then we could interpret this as software reset complete and go on to write
the accelerometer settings before the reset has actually completed.

BUG=none
BRANCH=rambi
TEST=Code inspection. I haven't actually seen this bug, I just saw the
potential for it.

Change-Id: I78757106291ffbaeff27f94aa6f74c9cea81e0b9
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/189064
(cherry picked from commit 521a99e38428fcfe928616f4932b5d1167e2f6cb)
Reviewed-on: https://chromium-review.googlesource.com/189233
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-08 02:31:26 +00:00
Randall Spangler
c42bf99402 samus: Add host command to read raw tmp006 data
This is needed to calibrate the tmp006 remote sensor values.

BUG=chrome-os-partner:26581
BRANCH=none
TEST='ectool tmp006raw N' works for N=0,1,2,3
     And fails with invalid param for N=4.
     Data matches result of tmp006 ec console command.

Change-Id: I04ec093c7727b55caca7d02baaf373d1ff234731
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/189207
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-03-07 20:33:31 +00:00
Alec Berg
832a0c7988 rambi: fix two bugs with accelerometer driver
Two bugs are:
- Need to grab the I2C port mutex before performing i2cxfer.
- Added sending software reset command to accelerometers on init.
This is necessary because the accelerometers can be powered
through an EC reboot, and it's important we restore them to a
known state.

BUG=none
BRANCH=rambi
TEST=Manually set accelerometer setting, rebooted, manually read
that setting and verified it was restored to default.

Change-Id: Ic3034ae39c936e07ca28458a60557b9623674ff1
Original-Change-Id: I0ea571f3a8dc46052128def24cbb5c1c29638469
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/188349
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/188387
2014-03-01 02:36:06 +00:00
Bill Richardson
cb8cfec66c Mark some private functions static in unused driver
The BQ24192 driver exports some functions that should be static. Let's mark
them so, mostly so I don't keep finding them when I search through the code
for common functions.

Note that nothing in the ToT branch uses this module anyway.

BUG=chrome-os-partner:23815
BRANCH=ToT
TEST=make buildall -j

Change-Id: I012111a2c9b9b84f0f3bfacc3bdc8804a83116a6
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/188179
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-02-28 19:12:05 +00:00
ChromeOS Developer
463e38b534 Enable IDPM for bq24715 charge controller
Dynamic Power Management enables proper regulation of
the input adapter current set in board.h.

BUG=chrome-os-partner:24933
BRANCH=None
TEST=Power a DUT with a bench supply. Verify the
input current doesn't exceed the input current limit
set in board.h while the system is under load and
charging the battery.

Change-Id: Ie68d92afe0ef89c691f460d120f8574cb17e2c4e
Original-Change-Id: Ida6b05f1d89b21d7cf1553f5e9936360679f8149
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187517
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187911
2014-02-26 01:52:58 +00:00
Alec Berg
9305b84ab2 rambi: Accelerometer driver for kxcj9.
Added accelerometer driver for kxcj9 accelerometers. Currently
the accelerometers aren't being used by anything, but there are
console commands, accelwrite and accelread, to perform transactions.

BUG=none
BRANCH=rambi
TEST=Used EC console commands to test that accelerometers respond
and data looks reasonable.

Original-Change-Id: I6ddcf04ec278adeacb148c19b10c3c296b467954
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/184693
Reviewed-by: Randall Spangler <rspangler@chromium.org>
(cherry picked from commit 5e1d2052b034b2400b98b2126243e01397a2ce56)

Conflicts:
	board/clapper/board.c
	board/clapper/board.h
	board/glimmer/board.c
	board/glimmer/board.h

Change-Id: If8744ddc3273fc08e29830adfd068dc302dd120a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187432
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-02-22 00:48:25 +00:00
Justin Chuang
fc91a7f7fd Support discharge on BQ24715 for Rambi and Squawks
BUG=chrome-os-partner:25031
BRANCH=rambi
TEST=Manually
  make BOARD=peppy
  make BOARD=falco
  make BOARD=rambi
  make BOARD=squawks
  On rambi and squawks, connect charger
     ectool chargecontrol discharge
     ectool i2cread 16 0 0x16 0x0a
     It should return 16-bit negative integer.

Change-Id: I8a8dfa90d2ad82595ac7a420c3c8ffc13b12cde6
Signed-off-by: Justin Chuang <jchuang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/182586
Reviewed-by: Dave Parker <dparker@chromium.org>
2014-01-16 06:43:05 +00:00
Randall Spangler
6ab8e91658 cleanup: Remove checkpatch warnings
This make minor syntactic changes and renames some camel-cased symbols
to keep checkpatch from complaining.  The goal is to reduce the
temptation to use 'repo upload --no-verify'.

This is a big furball of find/replace, but no functional changes.

BUG=chromium:322144
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I0269b7dd95836ef9a6e33f88c003ab0f24f842a0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/180495
2013-12-19 00:12:28 +00:00
ChromeOS Developer
f762717059 Clean up g781 temp sensor function names
BUG=None
BRANCH=None
TEST=Manual. Run the following console commands:
g781 - verify temps and status look sane.
temps - verify local and remote values for the 781 are listed
g781 settemp 0x05 80 - verify local high alarm set to 80C
g781 setbyte 0x09 0x80 - verify config register is 1000 0000

Change-Id: Ia437647fd052295dfd8901c2ef241ff69c0d950e
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179152
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-12-09 18:29:09 +00:00
ChromeOS Developer
d53fe7b79b Basic driver for tmp432 temperature sensor
This allows local and remote temp values to be added
to a board's list of temp sensors. It also adds a
'tmp432' EC console command to query temps
and set alert thresholds. Fractional degrees are not
supported. DPTF support is not addressed.

BUG=chrome-os-partner:23985
BRANCH=none
TEST=Add tmp432 support to a board with the sensor
then run the 'tmp432' and 'temps' EC console commands.

Signed-off-by: Dave Parker <dparker@chromium.org>

Change-Id: Ifee47cf4d4cf5eedef9ef2bfa2149f183f1d7a7b
Reviewed-on: https://chromium-review.googlesource.com/178688
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Dave Parker <dparker@chromium.org>
Tested-by: Dave Parker <dparker@chromium.org>
2013-12-07 00:57:24 +00:00
Randall Spangler
3b0a4055d1 Move battery temp ranges to battery_info struct
This allows boards to detect the battery and return the correct temp
ranges, which will be needed for upcoming boards.

In the board-specific implementations, it's pretty much just moving
the fields from one const struct to another, so the impact is minor.

BUG=chrome-os-partner:24310
BRANCH=none
TEST=build all platforms; verify pit and rambi still charge

Change-Id: I7be075b3abb4039577f6362316adc1860c121d5c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/178424
Reviewed-by: Yung-chieh Lo <yjlou@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
2013-12-03 07:28:50 +00:00