Commit Graph

113 Commits

Author SHA1 Message Date
Rong Chang
552c17543f oak: add initial support for oak board rev1
Add initial support for Oak rev1 board. This is just the
EC and includes battery charging but does not include
USB PD.

BUG=none
BRANCH=none
TEST=load on oak board and get console

Signed-off-by: Rong Chang <rongchang@chromium.org>
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Change-Id: I626f3921025fbc39ba22b04eeb6dd1084cd70777
Reviewed-on: https://chromium-review.googlesource.com/261678
2015-05-27 05:04:14 +00:00
Anton Staaf
855646e36b Producer/Consumer: Refactor to use Queue policies
Previously the Producer and Consumer interfaces tracked the
Consumer and Producer respectively at the other end of the
queue that they interacted with.  This was done to avoid
modifying the queue implementation, but resulted in a rougher
interface that required additional initialization steps and
prevented alternative configurations; many producers and one
consumer for example.

This commit uses the new queue policies to track this
information.  The new direct policy behaves as the old producer
and consumers did.  Now the producers and consumers are just
named references to the queue that they work on and a convenient
location for a notification callback when the queue is updated in
a way that is relevent to the producer or consumer.

All users of Producer and Consumer have been updated including the
stream adaptors which are in use by the echo test code and the
mcdp28x0 driver.  Use of the stream adaptors has also been
simplified.

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

BRANCH=None
BUG=None
TEST=make buildall -j
     Manual testing of Ryu (P5) and discovery board echo task

Change-Id: I704be6378a31b4e20f5063295eff9943e4900409
Reviewed-on: https://chromium-review.googlesource.com/271792
Reviewed-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
2015-05-26 19:36:21 +00:00
Anton Staaf
a0ebf0a008 Queue: Add policies to queues
Policies give a convenient place to hook into the queue operations
and notify something that there is new space free in the queue or
new units added.

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

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

Change-Id: I94b2aa94b8e8d07911191bc19a39fa827623b117
Reviewed-on: https://chromium-review.googlesource.com/271791
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
2015-05-26 19:36:15 +00:00
Todd Broch
42faec2124 mcdp28x0: Add devid console command.
BRANCH=samus
BUG=chrome-os-partner:35939
TEST=manual, with CONFIG_CMD_MCDP in board/hoho/board.h

> mcdp devid 0
devid[0] = BOBCAT
> mcdp devid 1
devid[1] = ST
> mcdp devid 2
devid[2] = IROM

Change-Id: I82938975be55bb924ced06e9d0a35f03dc47ae99
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/272693
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-05-22 22:48:17 +00:00
Todd Broch
c2af47cd37 mcdp28x0: Add info console command.
Would be useful to expose more of the GProbe commands to developers
who have access to boards console (hoho, honeybuns).  This CL adds
a console command and seeds it the 'mcdp info' command.

Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:35939
TEST=manual, with CONFIG_CMD_MCDP defined in board/hoho/board.h

  - Enter info console command multiple times and see correct
    return value.

      mcdp info
      family:000e chipid:0001 irom:1.0.0 fw:0.0.0

Change-Id: Iaf2c088d5da1af7b2dab11abcfb6e32e289066ea
Reviewed-on: https://chromium-review.googlesource.com/272692
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-05-22 21:27:40 +00:00
Todd Broch
1a996dc19c mcdp28x0: Add checksum verification to rx_serial.
Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:35939
TEST=compiles, MCDP_READY gpio still asserted.

Change-Id: If20a695380dc44d899951faeaa805bf7acfae1e1
Reviewed-on: https://chromium-review.googlesource.com/272691
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-05-22 21:27:33 +00:00
Gwendal Grignou
628bf15176 driver: Add BMM150 behind BMI160 support.
Add support for Bosh Sensortec BMM160 compass.
We access it through BMI150.

BRANCH=none
BUG=chrome-os-partner:39900
TEST=Test on a nucleo board and smaug.

Change-Id: I5b959cab4f9341ba0fcd3ed9bad815fa92f80a37
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/271525
Reviewed-by: Sheng-liang Song <ssl@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
2015-05-16 04:17:15 +00:00
Gwendal Grignou
8d04e95a49 driver: Add BMI160 basic driver support
Basic initialization of BMI160.
Fit into the existing accel/gyro framework.

BUG=chrome-os-partner:36018
BRANCH=none
TEST=Ability to read samples with accelinfo.

Change-Id: I5c86d4c3964eb6f876dd4042e5019195ffcca4ed
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/270454
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-05-12 23:35:56 +00:00
Gwendal Grignou
a9a9ae1abc driver: Use common data structure to store default accel values
Move structure used by lms6ds0 to motion_sense.h,
so that bosh driver can use the same mechanism.
Use code to avoid reading chip range when reading data.

BUG=none
BRANCH=none
TEST=Check Bosh driver is working as expected.

Change-Id: Id8b5bb8735e479a122ef32ab9a400fba189d7488
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/270453
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-05-12 23:35:51 +00:00
Kevin K Wong
6fb50e9090 bq24770: Corrected charger driver used an incorrect SMBUS address.
BUG=none
TEST=Verified with a SMBus analyzer that only the expected device
address is detected on the bus.
BRANCH=none

Change-Id: Ib8c8589544b9ec11127619a1120eb21f211fd690
Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/267472
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Divya Jyothi <divya.jyothi@intel.com>
2015-04-29 18:40:48 +00:00
Vincent Palatin
94baa433bc bq2589x: update driver
Update the BQ2589x charger driver to configure properly the boost
used as a VBUS 5V source.
Define the bits used for I2C registers configuration.
Return success in unused charger callbacks to avoid blocking the
charge state machine.

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

BRANCH=none
BUG=chrome-os-partner:38603
TEST=On Ryu P4 reworked with BQ25892, plug a C-A receptacle adapter and
see the 5V VBUS coming up, un-plug it and see VBUS going away,
try several PD/type-C charger and check the selected current limit.

Change-Id: I24b832b6d130ff6dfda1ce47f5e445d65279fa7d
Reviewed-on: https://chromium-review.googlesource.com/266063
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>
2015-04-21 00:18:50 +00:00
Aseda Aboagye
d02620a05d lsm6ds0: Cache ODR and range on EC.
For the driver functions get_range and get_data_rate, each call would
end up executing an i2c transaction even if the value had not
changed. Therefore, I modified the lsm6ds0 driver to cache the output
data rate as well as the range. This prevents unecessary i2c
transactions from occuring.

BUG=chromium:476226
TEST=Flashed EC on samus and verified that the accelrange and accelrate
commands still worked and that the sensors were functional.
TEST=Verified Double Tap still worked.
TEST=make -j buildall tests
BRANCH=none

Change-Id: Ie432979266dc4e4892978005de5d1df62cc0654f
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/265933
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
2015-04-20 18:46:08 +00:00
Vincent Palatin
de24d51162 charger: add TI BQ2589x charger driver
Driver for Texas Instrument bq25890/bq25892/bq25895 battery charger
chip.

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

BRANCH=none
BUG=chrome-os-partner:38603
TEST=On a modified board with BQ25892, charge a 1S battery and check ADC
values.

Change-Id: I536c6b58438464a63ad3d3536b9bb84ff35920e8
Reviewed-on: https://chromium-review.googlesource.com/263458
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2015-04-02 19:01:27 +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
james_chao
e846dcf892 charger: bq24773: Fix read input current error
'ectool chargestate show' shows the wrong input current since
the function charger_get_input_current() uses REG8_TO_CURRENT.

BUG=None
TEST=Use 'ectool chargestate show' or UART command 'charger'
     check the input current value.
BRANCH=None

Signed-off-by: james_chao <james_chao@asus.com>
Change-Id: I29229ea1ef22811035b500c7a33fedee6562db35
Reviewed-on: https://chromium-review.googlesource.com/259842
Reviewed-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Divya Jyothi <divya.jyothi@intel.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Divya Jyothi <divya.jyothi@intel.com>
Commit-Queue: Shawn N <shawnn@chromium.org>
2015-03-24 18:26:31 +00:00
james_chao
0db4de8d68 charger: Add support for bq24770
Add support for bq24770 (smbus) in the bq24773 (i2c) driver.

BUG=None
TEST=Use the UART command "charger" and check the charger information.
BRANCH=None

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ie5f5af60e93aa73d9ef68115af36a8d28f6d6c2b
Reviewed-on: https://chromium-review.googlesource.com/259870
Reviewed-by: BoChao Jhan <james_chao@asus.com>
Reviewed-by: Divya Jyothi <divya.jyothi@intel.com>
Commit-Queue: Divya Jyothi <divya.jyothi@intel.com>
Tested-by: Divya Jyothi <divya.jyothi@intel.com>
2015-03-24 18:26:25 +00:00
Shawn Nematbakhsh
1746c5b0d9 pi3usb9281: Always set reserved control bits
Bits 1 and 3 of the control register are read 1, write 1, but RO
firmware may have zero'd these bits. Therefore, always set the bits
high, ignoring the read value.

TEST=Manual on Samus. Starting from .90 RO, flash new RW and verify
BC1.2 charger detection is working.
BUG=chrome-os-partner:37241
BRANCH=Samus

Change-Id: I2f71718f74e50fe9b664dbe3da1578ee4c995136
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/254880
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-03-04 22:08:09 +00:00
Anton Staaf
65f049b977 Producer/Consumer: Convert USART and USB Stream drivers
Previously the USART and USB Stream drivers exposed in_stream
and out_stream interfaces, which don't allow for sharing their
queues easily.  This change converts these drivers over to the
producer/consumer model and updates the two uses.

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

BRANCH=None
BUG=None
TEST=make buildall -j
     Verify that the discovery echo functionality is unchanged.

Change-Id: I29f043ab1712373f638e1621378df98647d736cf
Reviewed-on: https://chromium-review.googlesource.com/252820
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2015-03-02 18:48:40 +00:00
Shawn Nematbakhsh
c0be440952 pi3usb9281: Fix handling of REG_CONTROL (02H) reserved bits
REG_CONTROL has two sets of reserved bits:
- Bits 5 thru 7 are read x, write 0.
- Bits 1 and 3 have undocumented function and should not be changed from
  read value.

BUG=chrome-os-partner:36360
TEST=Manual on Samus. Cold boot unit and insert 2.4A charger. Verify
that charger is correctly detected.
BRANCH=Samus

Change-Id: I240d352817910eda404b72be13e2c913a4b76079
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246560
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-05 21:02:56 +00:00
Alec Berg
fd9dd63e5c samus: automatically recover from charge circuit failures
Occasionally the charge circuit on samus gets wedged and will not
charge. This change detects when the charge circuit has failed
and automatically recovers from it. It uses the BQ PROCHOT warning
to detect the failure by setting PROCHOT to trigger when the BQ
thinks input current is higher than the input current limit. When
the failure is detected, the EC disables charging and tells PD MCU
to disable CHARGE_EN, then a couple seconds later, it re-enables
charging.

This CL also adds more communication between EC and PD for the EC
to be able to set the charge state for the PD. Valid charge states
are: No charging allowed, 5V charging only, and max charging. The
EC uses this as such:
- When the EC gets AC present interrupt, it sets off a deferred
function to change charge state to max charging after some delay
to give time for the charge circuit to settle down.
- When the EC gets AC disconnect interrupt, it disables charging
briefly, enables learn mode, and then sets 5V charging allowed.
This allows for the same starting conditions in the charge circuit
for every AC attach.
- When the EC detects a wedged charge circuit, it disables charging
and waits a few seconds before re-enabling 5V only charging.

Additionally, this change moves the charging cutoff in S3/S5/G3 when
the battery is full to the EC. With the added control for the EC
to set the PD charging state, it is more convenient for the EC to
manage cutting off charging when battery is full.

BUG=chrome-os-partner:36081
BRANCH=samus
TEST=test the basics:
- connect/disconnect zinger a bunch of times
- connect and disconnect two zingers in different order
- connect two zingers and charge override between the two

test the automatic charge wedge recover:
- wedge the charge circuit by setting charger voltage under battery
voltage: "charger voltage 7000"
- wait a few seconds for the system to recover and check it is charging
with "battery" command

test full battery charge cutoff:
- added console command to change battery soc in board/samus/extpower.c:
static int cmd_battfake(int argc, char **argv)
{
	char *e;

	battery_soc = strtoi(argv[1], &e, 10);
	batt_soc_change();
	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battfake, cmd_battfake, "", "", NULL);
- in S0, tested "battfake 100" does not disable charging.
- in G3, tested "battfake 100" disables charging and "battfake 99"
re-enables charging.
- set "battfake 100" and tested transitioning to S0 enables charging and
transitioning to S5 disables charging.
- attached two chargers and used charge override to select active port.
then toggled "battfake 100" to "battfake 99" back and forth and verified
charge override port is still the same.

test third-party 12V charger:
- plug in a bunch of times and make sure we stay at 5V for 500ms and then
transition to 12V

test with no battery:
- tested five different units with no battery and just zinger. 3/5 boot,
while the other 2 don't. But, the 2 that don't boot without battery also
can't boot w/o battery when this CL is reverted, so I don't think this
change is causing the problem, I think there is an electrical limitation.

test with EVT zinger:
- EVT zingers (P2 - C2) negotiate very quickly after connection, which
can cause INA problems w/o this CL. Tested an EVT zinger with samus and
did a bunch of connections and disconnections and verified that we always
wait at 5V for 500ms and that we don't wedge the INA circuit on connect.

test backwards compatibility:
- test new PD with old EC and make sure we can charge with zinger.
(note that if the charge circuit wedges, we won't be able to unwedge it).
- test old PD with new EC and make sure we can charge with zinger.

Change-Id: I7703b7a2ab1209d7f559b265b03517e79c74b16a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245253
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-02-03 08:21:36 +00:00
Shawn Nematbakhsh
d93544bbed mcdp28x0: Move structure definitions to ec_commands.h
mcdp_info is a logging payload, so related structures need to be moved
to the public include file.

BUG=chrome-os-partner:35935
TEST=make buildall -j
BRANCH=Samus

Change-Id: Idb939db884821fa85faafbfe643e713f5bcdbc59
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244780
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-31 04:32:30 +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
Todd Broch
70afa3898c ectool: parse accessory logs for dingdong & hoho
Signed-off-by: Todd Broch <tbroch@chromium.org>

BUG=chrome-os-partner:35935
TEST=manual

  # With dingdong in C0 & hoho in C1

  # Enter GFU mode for dingdong & hoho
  ectool --name cros_pd pdsetmode 0 0x18d1 1 1
  ectool --name cros_pd pdsetmode 1 0x18d1 1 1

  # read logs
  ectool --name cros_pd pdlog

  2015-01-26 14:36:54.787 P0 SRC
  2015-01-26 14:36:54.780 P1 SRC
  2015-01-26 14:36:53.680 P0 DP mode enabled
  2015-01-26 14:36:53.375 P1 HDMI Codec: family:000e chipid:0001 irom:1.0.0 fw:0.0.0
  2015-01-26 14:36:53.771 P1 DP mode enabled

  # remove hoho & plug in zinger instead
  ectool --name cros_pd pdlog

  2015-01-26 14:44:36.991 P1 SNK Charger Type-C 5153mV max 5000mV / 3000mA
  2015-01-26 14:44:37.011 P1 SNK Charger PD 5021mV max 20000mV / 3000mA
  2015-01-26 14:44:37.116 P1 SNK Charger PD 20211mV max 20000mV / 3000mA

Change-Id: I0289cfd1d43ef1a22123b437bc8df86920fbf1a7
Reviewed-on: https://chromium-review.googlesource.com/243375
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-28 11:14:27 +00:00
Alec Berg
2737321ecd bq24773: turn off prochot warning
Turn off prochot warning on bq24773 by default because our
battery can always supply enough power for the whole system
so we don't need to throttle the CPU if the BQ senses too much
input current.

BUG=chrome-os-partner:34885
BRANCH=samus
TEST=force BQ into it's prochot condition on samus by setting
the charging voltage temporarily below the battery voltage, which
causes INA to turn off and the BQ to think IADP is > 4.1A. in
this condition PROCHOT is normally asserted and CPU slows down,
but with this patch PROCHOT is not asserted and the CPU does not
slow down.

Change-Id: I658dbe568b7bfe94944ef90d6d59656a0683c8a0
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243231
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
2015-01-26 21:01:50 +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
Shawn Nematbakhsh
2f6f8b3548 pi3usb9281: Lock access to MUX GPIO while in use
Lock access to the MUX GPIO to prevent other tasks from toggling away
from our active chip while in use.

BUG=chrome-os-partner:35567
TEST=Manual on samus_pd. Boot system, verify that no "write failed"
print is seen. Also verify that charger detection functions as expected.
BRANCH=Samus

Change-Id: Ica02b8fbd8f9ee04f6389ce0b0e5bd58104ff698
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/242125
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-21 06:44:41 +00:00
Bill Richardson
43806f07e3 samus: Add scale factor to account for ALS attenuation
This adds a sensor-specific attentuation factor, which will be
applied to the ALS raw sensor readings on the EC. This is to
account for the attenutation due to glass, tinting, etc.

BUG=chrome-os-partner:34590
BRANCH=ToT,Samus
TEST=manual

In a root shell, run this:

  cd /sys/bus/acpi/drivers/acpi_als/ACPI0008:00/iio:device1
  while true; do cat in_illuminance_raw; sleep 1 ;done

Shine a flashlight on the ALS. Note that the readings are 5X
higher than they were before this CL.

Change-Id: I2a53872ecb5fab62e5f443d43588a26d3d7e697f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/241191
Reviewed-by: Bryan Freed <bfreed@chromium.org>
2015-01-21 05:05:47 +00:00
Shawn Nematbakhsh
7dec6938c9 pi3usb9281: Accept alternate device id
PI3USB9281A is compatible with our existing driver but has a different
device ID.

BUG=chrome-os-partner:35567
TEST=Manual on samus_pd. Verify that "invalid ID 0x18" prints are not
seen on console.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I275ed50fcbcb3c2e385292408be6de51055903fb
Reviewed-on: https://chromium-review.googlesource.com/241764
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-18 20:04:58 +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
c5a2bf58da accel: fix accel bug where if no new data, it uses wrong data
Fix accelerometer bug in which, if there is no new data from
the lsm6ds0 accel, it will use the old ajusted xyz instead of
the old raw xyz.

BUG=chrome-os-partner:34952
BRANCH=samus
TEST=add printf to case where it uses old data and sample faster
then ODR to read wrong data.

Change-Id: If0a6bbdec71d84567eae107aca6f1d0ab754919a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/237664
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2014-12-30 22:03:58 +00:00
Todd Broch
b9b457173e pd: hoho: mcdp28x0 serial driver.
Add initial serial driver for mdcp2850 dp->hdmi converter.  Driver
implements 'get information' (cmd:0x40) to provide rudimentary method
to test mcdp for functionality and assert GPIO if successful.

Future CLs may expose more serial functionality if necessary.

Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:34122
TEST=manual, when compiles with #define MCDP_DEBUG see successful
serial communication and result from get info.

  buf:[00]0x04 [01]0x40 [02]0x00 [03]0xbc
  ...
  buf:[00]0x0f [01]0x40 [02]0x00 [03]0x0e
      [04]0x00 [05]0x01 [06]0x01 [07]0x00
      [08]0x00 [09]0x00 [10]0x00 [11]0x00
      [12]0x00 [13]0x00
  family:000e chipid:0001 irom:1.0.0 fw:0.0.0

Change-Id: I35f9d9b0437633d1bd6a6c9fa14413bedb12f5c2
Reviewed-on: https://chromium-review.googlesource.com/235930
Trybot-Ready: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2014-12-23 22:10:56 +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
Shawn Nematbakhsh
91131f7387 pi3usb9281: Limit DCP port to 500mA charge current
According to specification, a DCP port is only required to provide 500mA
@ 4.75V, though actual supply limit can vary upward significantly. Set
the current limit on DCP ports to 500mA to reflect this reality.

BUG=chrome-os-partner:32003
TEST=None
BRANCH=Samus

Change-Id: I46e25b44baaa41ddf173880e52d7485d952ebf23
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236772
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-19 09:17:34 +00:00
Shawn Nematbakhsh
c8f98e80fd samus_pd: Open USB data switches in UFP mode
Samus USB ports can't actually act as UFPs, so open switches when in
UFP mode.

BUG=chrome-os-partner:32003
TEST=Manual on Samus. Connect two Samus units, run `pd 1 swap data`,
verify that switches are opened on switch to UFP. Unplug samus and
connect a USB 2.0 device instead, verify that ports are again closed.
BRANCH=samus

Change-Id: I9e1ca58089caf29e419698c8426bf8b72500833a
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/233711
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-09 02:06:56 +00:00
Gwendal Grignou
4b154c6f95 motion: Add decoding for MOTION_CMD_DUMP v1 command
MOTIONSENSE_CMD_DUMP is deprecated, replaced with MOTIONSENSE_CMD_GET_DATA
Also use vector_3_t instead of x,y,z

ectool motionsense commands only work with newer firmware, to
handle a dynamic number of sensors.
- The host sends the number of sensor it has allocated space for.
- If 0, the EC just sends the number of sensors available
- Otherwise returns sensor information up to the limit imposed by the host.

Remove MOTIONSENSE_GET_STATUS: not needed. It is only useful for LPC,
to guarantee atomicity of the data.
Remove MOTIONSENSE_GET_DATA: not needed since we increase the version
number of MOTIONSENSE command.

BUG=chrome-os-partner:31071,chromium:430792
BRANCH=ToT
TEST=Compile. On a firmware that support the new command:
/usr/sbin/ectool --name=cros_sh motionsense
Motion sensing active
Sensor 0: 92    15      1030
Sensor 1: -94   -63     718
/usr/sbin/ectool --name=cros_sh motionsense active
0
On a machine with older firmware (samus), check these
functions are not working anymore.

Change-Id: I64b62afff96670fb93457760d43d4e64e26e029f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/226880
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-11-18 05:19:08 +00:00
Alec Berg
498abf833c samus_pd: add host command to get type-c port power info
Get type-c port power info including power role, charger type,
and charging info. Also added host command to get number of type-c
ports.

Also adds new charging suppliers for pericom identified chargers
including DCP, CDP, SDP, proprietary, and other chargers. Priority
of these for charging is set in samus board file.

BUG=chrome-os-partner:32650
BRANCH=samus
TEST=run 'ectool --name=cros_pd usbpdpower' and verify correct
status with minimuffin, zinger, and type-C to type-A adapter.

Change-Id: I1dabbe7de4185a23df5684a5ea9a2d944f1f6ff5
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223523
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-30 04:31:34 +00:00
Gwendal Grignou
66164f2784 Samus: Split motion sense and lid angle
Split motion_sense.c.
Translate the accel data in the Android coordinate right away.

BUG=chrome-os-partner:32002
BRANCH=ToT
TEST=On samus, check lid angle are still correct.

Change-Id: If743e25245dc1ce4cdacb8a4d5af22616c4a79e4
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225486
Reviewed-by: Sheng-liang Song <ssl@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-29 22:23:54 +00:00
Bill Richardson
f36a859e06 samus: new algorithm for tmp006 object temperature
The original algorithm is given in the TMP006 User's Guide
(SBOU107.pdf). The algorithm we previously implemented is that,
plus some additional and completely undocumented massaging of the
Tdie and Vobj registers. The original meaning of that hack is now
lost in the mists of time, thanks to our email retention policy.

This CL introduces a new algorithm variant, but at least this
time the details are in the bug report. It's essentially the same
as the User's Guide algorithm, except that we apply one-stage FIR
filters to the Tdie input and the Tobj output.

There are five new parameters: d0, d1, ds, e0, e1. Refer to
tmp006_read_object_temp_k() in ec/driver/temp_sensor/tmp006.c to
see how these new parameters are applied.

CAUTION: The tmp006 sensor algorithm is mostly math and magic
numbers. The spreadsheet attached to the bug report has six
sheets with wildly varying values for those parameters. Since the
correct parameter values haven't yet been determined for Samus,
all I can be sure of with this CL is that it seems to work and
isn't any worse than the old one.

Oh, and note that the EC's 't6cal' console command has been
disabled until/unless we add support for floating point IO. Use
ectool from the host to get and set the params instead.

BUG=chrome-os-partner:32260
BRANCH=ToT,Samus
TEST=manual

After booting, look at the sensor values using ectool:

  localhost ~ # ectool temps all
  0: 312
  1: 314
  2: 313
  Sensor 3 not calibrated
  4: 311
  Sensor 5 not calibrated
  6: 305
  Sensor 7 not calibrated
  8: 306
  Sensor 9 not calibrated
  10: 307
  Sensor 11 not calibrated
  12: 312
  Sensor 13 not calibrated
  localhost ~ #
  localhost ~ # ectool tempsinfo all
  0: 0 PECI
  1: 1 ECInternal
  2: 1 I2C-Charger-Die
  3: 2 I2C-Charger-Object
  4: 1 I2C-CPU-Die
  5: 2 I2C-CPU-Object
  6: 1 I2C-Left C-Die
  7: 2 I2C-Left C-Object
  8: 1 I2C-Right C-Die
  9: 2 I2C-Right C-Object
  10: 1 I2C-Right D-Die
  11: 2 I2C-Right D-Object
  12: 1 I2C-Left D-Die
  13: 2 I2C-Left D-Object
  EC result 2 (ERROR)
  ...
  localhost ~ #

There are six tmp006 object temps that need calibrating. The
index used for the calibration is for the tmp006 objects, not the
3,5,7,.. numbers reported for all temp sensors. See the current
values with tmp006cal:

  localhost ~ # /tmp/ectool tmp006cal 5
  algorithm:  1
  params:
    s0  0.000000e+00
    a1  1.750000e-03
    a2  -1.678000e-05
    b0  -2.940000e-05
    b1  -5.700000e-07
    b2  4.630000e-09
    c2  1.340000e+01
    d0  2.000000e-01
    d1  8.000000e-01
    ds  1.480000e-04
    e0  1.000000e-01
    e1  9.000000e-01
  localhost ~ #

If the s0 param is zero, this sensor is uncalibrated. The params
are entered in the order in which they're displayed You can
change any or all of the parameters. Skip the ones you don't want
to update by specifying '-' for its position. (Note: throw in an
extra '--' first so that ectool doesn't think that negative
numbers are command options).

For example, to change s0 and b0:

  localhost ~ # ectool -- tmp006cal 5 1.0 - - -3.0
  localhost ~ #
  localhost ~ # ectool tmp006cal 5
  algorithm:  1
  params:
    s0  1.000000e+00
    a1  1.750000e-03
    a2  -1.678000e-05
    b0  -3.000000e+00
    b1  -5.700000e-07
    b2  4.630000e-09
    c2  1.340000e+01
    d0  2.000000e-01
    d1  8.000000e-01
    ds  1.480000e-04
    e0  1.000000e-01
    e1  9.000000e-01
  localhost ~ #

Now sensor 13 (tmp006 object index 5) is calibrated:

  localhost ~ # ectool temps all
  0: 310
  1: 315
  2: 313
  Sensor 3 not calibrated
  4: 310
  Sensor 5 not calibrated
  6: 305
  Sensor 7 not calibrated
  8: 307
  Sensor 9 not calibrated
  10: 307
  Sensor 11 not calibrated
  12: 312
  13: 313

Change-Id: I61b5da486f5e053a028c533ca9e00b9a82a91615
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224409
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-22 00:30:31 +00:00
Vic Yang
ccc270368b Extend INA231 driver to support INA219 on Plankton
The register format of INA231 and INA219 are very much alike. In our
use case, we only need to use different coversion coefficient.

BRANCH=None
BUG=chrome-os-partner:32764
TEST='ina 0' on Plankton V2.
TEST=Build twinkie.

Change-Id: I9c8e21e30ed844566793dcc1221f865400c3d90d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223370
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-18 07:38:30 +00:00
Shawn Nematbakhsh
ac2b30d1e7 pi3usb9281: Add function for translating registers to current limit
Decode Pericom registers to current limits.

BUG=chrome-os-partner:32003
TEST=Manual on samus_pd. Insert 1A Apple charger, verify current limit
is correctly detected as 1A.
BRANCH=samus

Change-Id: I310d9f22cef80e97c1734e6a56f0034ebe01df31
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222638
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-10 06:54:22 +00:00
Mohammed Habibulla
f92f70d04c Disable LEARN option during charger init
When charger is initialized disable the LEARN option i.e. reenable
charging on AC power

BUG=chrome-os-partner:32320
TEST=set DUT to discharge on AC and then reflash EC. Ensure that
charging begins again.
BRANCH=none

Change-Id: I3e83db27ab49548d5491548fa624899865c11bfb
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222644
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-10 04:36:46 +00:00
Sheng-Liang Song
ac261c00c1 samus: support sensor at different power state.
Design Goals:
1. Every time the AP boots, the same default sensor settings are configured.
2. If the AP goes to suspend (S3) and wakes back up (S0),
   then the AP sensor settings will be restored.
3. In S3 and in S5, only sample specific sensors that are needed.

BUG=chrome-os-partner:32368
BRANCH=ToT
TEST=Verified on Samus.

Verified suspend and resume logic with EC console messages.
- Test Case0: close lid & open lid
- Test Case1: powerd_dbus_suspend

Change-Id: I553c53e63ecfcb39d5e649a7189aa6ea02589471
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220371
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-08 02:51:17 +00:00
Vic Yang
cc0843d270 Plankton: Add console command to reset USB hub
This command resets the USB hub through the IO expander.

BUG=None
TEST=Reset the hub on Plankton.
BRANCH=None

Change-Id: Ia77a1e326adc6aba65438534158a4c461479727a
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/218758
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-23 06:28:38 +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