Commit Graph

915 Commits

Author SHA1 Message Date
Alexandru M Stan
786a45347d stm32f0: deep sleep in S0
Enabled deep sleeping during S0. This was previously inhibited by
SLEEP_MASK_AP_RUN but the new config option (CONFIG_LOW_POWER_S0) will ignore it.

SPI needed a sleep mask, it essentially gets enabled and disabled whenever the
CS changes. Warning: waking up when the CS falls takes a little time, if the AP
sends fast data before the 48MHz clock is enabled characters will get corrupted;
leave about 30uS time for the clock to start.

CQ-DEPEND=CL:219997
CQ-DEPEND=CL:220243
CQ-DEPEND=CL:220461
BUG=chrome-os-partner:32223
BRANCH=none
TEST=load onto pinky, boot the AP(S0), use idlestats command to verify
that we are going into deep sleep (STOP mode). Verify that everything works
normally during S0(SPI, keyboard, anything that requires the EC to wakeup).

Change-Id: I81c4fa472332f1ad8ad93301089a99dcdb108948
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219555
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-01 22:42:25 +00:00
Vic Yang
baf3bac6d8 ryu: Use brief assertion failure message
Currently, when an assertion fails, the error message is like:

  ASSERTION FAILURE '1 + 1 == 3' in command_apreset() at common/chipset.c:24

To save flash space, let's add an option to remove the failed
expression and function name. The error message becomes:

  ASSERTION FAILURE at common/chipset.c:24

BUG=chrome-os-partner:32203
TEST=make buildall
TEST=Add an assertion and triggers it. Check error message.
BRANCH=None

Change-Id: Ie323d5b43cbff2cd8f6cd5bb46c1f34ecd16bd5e
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219670
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-01 06:53:14 +00:00
Eric Caruso
28891eaaab lightbar: treat HALT like a normal opcode
This removes the special casing around HALT. It saves us a string
literal and some logic. In total, we gain about 50 bytes and a
little cleanup for this.

BUG=None
BRANCH=ToT
TEST=Tried a program that uses HALT (i.e. red-green-blink) in
  simulator and on hardware.

Change-Id: Iffee1b559983fd1ecd385cc6b8967f72a6b968a0
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220589
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-01 01:47:39 +00:00
Vincent Palatin
400851595a add RSA signature verification code
2048-bit RSA public key cryptography signature verification code
which uses a pre-processed key for computation.

it is based on the code from vboot :
platform/vboot_reference/firmware/2lib/2rsa.c

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

BRANCH=samus
BUG=chrome-os-partner:28336
TEST=using following CL, on Zinger, verify RW firmware signature.

Change-Id: I681a29144eb805cd5758aa6efe697ce2f656a298
Reviewed-on: https://chromium-review.googlesource.com/220186
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-09-30 05:42:15 +00:00
Bill Richardson
87762fa699 Add compiler/decompiler for lightbar bytecode programs.
BUG=none
BRANCH=ToT
TEST=manual

  make BOARD=samus
  for i in extra/lightbar/programs/[g-z]*.bin; do
    ./build/samus/util/lbcc -d $i /tmp/x.lbs
    ./build/samus/util/lbcc /tmp/x.lbs /tmp/x.bin
    cmp $i /tmp/x.bin
  done

Change-Id: I86c014c425e917ecafadd1c6845fcf2e5b4edbb7
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220244
2014-09-30 01:53:53 +00:00
Duncan Laurie
fa4407c11c charge_state_v2: Send host event if charge state changes
If there is any delay between AC status and the battery charge status
it is possible for the power_manager to read the battery state when
the AC status event is sent and still see that the battery is not
yet charging.  This can cause lag in the UI battery icon because the
AP is not notified when the battery charge state changes.

In order for the host to be able to differentiate the dynamic battery
state changing (re-read ACPI _BST by sending Notify 0x80) from the
static battery info (re-read ACPI _BIX/_BIF by sending Notify 0x81)
it needs a separate host event.

BUG=chrome-os-partner:32196
BRANCH=samus
TEST=Test AC instertion and removal while watching state on the host
to ensure that an event is sent to the host which triggers power
manager to re-read the battery status and notice that the charge
state has changed if there is any delay after the AC status event:

watch -n 0.1 "cat /sys/class/power_supply/AC/online;
cat /sys/class/power_supply/BAT0/status;
tail -10 /var/log/power_manager/powerd.LATEST"

Change-Id: I18ce70719dc231c43c474cefad2068f949675a2b
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220257
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-30 01:53:41 +00:00
Bill Richardson
b88866828f Add demo_tap() function for lightbar demo mode
BUG=chrome-os-partner:29041
BRANCH=ToT
TEST=manual

From the host run

  ectool lightbar demo on

Then press the 'T' key. The lightbar should change to indicate
the charge state. Fiddle with the arrows to change the pretend
battery level and AC presence.

Change-Id: I398a829e2e5de5e1a186500aa2ed72c61e71deaa
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220024
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-26 09:21:06 +00:00
Vincent Palatin
2edf7ee161 Allow to disable default DMA interrupt handlers
The default DMA interrupt handlers are somewhat slow and not really flexible,
allow to override them in board if needed.

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

BRANCH=none
BUG=none
TEST=none

Change-Id: I909bfab265ccaa4f3b61d0a2a69bf7dfc0414be2
Reviewed-on: https://chromium-review.googlesource.com/215671
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-09-25 20:27:07 +00:00
Eric Caruso
fb5ff7b1bb lightbar: add seq type PROGRAM for user-programmable sequences
This diff allows the user to send small programs to the EC and
gain control of the lightbar. Right now, this is only exposed
through ectool, and sysfs support will come later.

To send a program to the EC, use
$ ectool lightbar program /path/to/program.bin
and then start running the program with
$ ectool lightbar seq program

BUG=None
BRANCH=ToT
TEST=Using the above steps with hand-assembled programs.
  Checked that infinite bytecode loops do not hang the EC.
  Checked that bad opcodes exit with an error.
  Stress tested pushing programs and changing sequences.

Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Change-Id: I635fb041a5dc5c403f7c26fb9a41b5563be9b6b7
Reviewed-on: https://chromium-review.googlesource.com/219558
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-09-25 07:59:16 +00:00
Gwendal Grignou
7be8ff812b [common]: Remove accelerator calibration code.
This code is used to find the orientation of the sensor.
Given sensor are aligned with the edges of the device,
it is not too dificult to find manually.

BRANCH=ToT
BUG=None
TEST=Check ACCEL_CALIBRATE is not used anymore.
Check 'make buildall -j' works.

Change-Id: I81ffcb4f6b01c530ef16baf13113a5942f615092
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219527
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-25 04:09:07 +00:00
Alec Berg
5e7c09ed3e stm32f0: samus_pd: add hibernate and enable wake pins for samus
Add hibernate functionality for stm32f0, and enable wake pins
for samus PD MCU. Samus wake pins are VBUS present on either port.

BUG=chrome-os-partner:31226
BRANCH=none
TEST=load onto samus PD. test hibernate console command:

> hibernate 0 500000
Hibernating for 0.500000 s
(5 seconds later)

--- UART initialized after reboot ---
[Reset cause: hibernate]
...
> hibernate
Hibernating until wake pin asserted.
(plug in AC)

--- UART initialized after reboot ---
[Reset cause: hibernate]

Change-Id: Ib86f2677721df29e7bf6975e239de79c25a38795
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219105
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-09-24 23:28:07 +00:00
Vic Yang
cf62055270 Add options to disable rarely used console commands
'powerindebug' is only used when there is a problem with power
sequencing. 'taskready' is rarely used and the same info can be
retrieved by 'taskinfo'.

Put both behind config flags and disable 'taskready' by default. Also
disable 'powerindebug' for Ryu.

BUG=chrome-os-partner:32203
TEST=Build Ryu and check flash space used.
BRANCH=None

Change-Id: I753a1f5411d6e840a80aba03afc94f9640d381a8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219490
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-09-24 06:25:33 +00:00
Anton Staaf
ece4481cd1 stm32-USB: Initial USB bulk endpoint stream driver
This stream driver works like the USART stream driver
but connects to two bulk USB endpoints.

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

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

Change-Id: I9cbd2e54a811d3e32c68a820f7ab5de693c29569
Reviewed-on: https://chromium-review.googlesource.com/216002
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-09-23 00:05:07 +00:00
Alec Berg
23ad46d3b8 samus_pd: enable low power idle
Enable low power idle for samus_pd. Low power idle is only
entered when no USB PD device is connected.

BUG=chrome-os-partner:31226
BRANCH=none
TEST=load onto samus_pd, use idlestats command to verify
that we are going into deep sleep (STOP mode). Run 30 min.
and verify no watchdog reboots or anything out of ordinary.

Also, verify that host commands from EC work when going into
deep sleep by sending host commands on the EC console with
pdcmd 0 0.

Change-Id: I3e2e04e6c4c0a84e291286dbed90945847e0dfdd
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/218957
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-09-23 00:04:59 +00:00
Anton Staaf
0a147973bb stm32-USART: Add generic stream based usart driver
This driver can be used to access multiple usarts using an abstract
stream interface.  The stream interface can also be used in drivers
for the host interface and USB console interface, providing a
consistent API across all character stream style IO.

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

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

Change-Id: Icf567f0b0fa4eb0e9ad4cdb0be8edc31c937a7de
Reviewed-on: https://chromium-review.googlesource.com/209671
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-09-23 00:04:56 +00:00
Todd Broch
85063ee72d Fixup for coreboot & portability.
Removed include for sha1 and just hardcoded the #define for now.

BRANCH=none
BUG=chrome-os-partner:32108
TEST=manual,
can compile EC & BIOS firmware for samus

Change-Id: Iab03315041ec9ac12e85ca93f97b80b850c61377
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/218809
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-19 03:00:59 +00:00
Anton Staaf
271bc1eae6 Stream: Add In and Out stream interfaces and config
These interfaces will be used by USART, USB and I2C
stream drivers to provide a uniform interface for
console mux'ing code.

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

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

Change-Id: If8938512c29708f7b8c28f6ca1c707aa6b5c1708
Reviewed-on: https://chromium-review.googlesource.com/216001
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
2014-09-18 02:59:29 +00:00
Anton Staaf
a6da62d284 Queue: Add functionality needed by new USART stream driver
Previously there was no way to remove multiple units at a time
from the queue, and the queue was wasting an entry to disambiguate
full from empty.  There was also no way to get the free entry
count from the queue, only the ability to query if it was above
a required amount.  The queue was also storing its constant
compile time configuration as well as its dynamic state in the
same structure.  This wasted RAM on configuration information
that doesn't change.

This refactor fixes these issues, making the queue suitable for
use in the new USART stream driver.

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

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

Change-Id: I284cee52d8189928dbc4c499f87ab34e14019e5a
Reviewed-on: https://chromium-review.googlesource.com/210533
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
2014-09-18 02:59:24 +00:00
Alec Berg
5bc3dc3bbe samus: add automatic retries for host commands from EC to PD
Add three retries for EC to PD host commands. With this change,
removed retry mechanism in host_command_pd.c which was a retry
only for the specific EC_CMD_PD_EXCHANGE_STATUS host command.

BUG=chrome-os-partner:32006
BRANCH=none
TEST=Loaded EC code onto samus. Added the following code
for testing failed host commands to samus_pd common/host_command.c
host_command_task():
if ((evt & TASK_EVENT_CMD_PENDING) && pending_args) {
	if (i++ != 4)
		pending_args->result =
			host_command_process(pending_args);
	else {
		pending_args->result = -7;
		i = 0;
	}
	host_send_response(pending_args);
}
This test code on samus_pd drops one in every five host commands.

With this code, from the EC, I send "pdcmd 0 0", and verified that
1 out of 5 times the EC prints a host command failed code, but then
retries successfully.

Change-Id: Ibf43feefbfc7d791c45c6689b82c66f5d71046ab
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217461
Reviewed-by: Todd Broch <tbroch@chromium.org>
2014-09-17 01:24:05 +00:00
Todd Broch
f5b7b32423 samus: enhance usbpd host command to return port status.
CL provides some useful information similar to the EC console command
'pd state <port>' when host command 'usbpd <port>' is sent from host
with no additional arguments.

Also added a few build asserts for role & mux strings.

BRANCH=none
BUG=chrome-os-partner:31690
TEST=manual

  ectool --interface=lpc --dev=1 usbpd 1
  Port C1 is enabled. Role:SNK Polarity:CC1 State:6
  # has zinger attached
  ectool --interface=lpc --dev=1 usbpd 0
  Port C0 is enabled. Role:SNK Polarity:CC1 State:2

Change-Id: Id44eb7bf6a6fcfa888a0008a2249601967c50bcc
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217138
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-11 20:00:12 +00:00
Todd Broch
7698c323ea samus: Add host command to query USB type-C accessory attached.
PD accessories that are RW update-able will broadcast their rw_hash
SHA1 digest upon connection to the PD MCU which will store it.

For update purposes, the host needs that accessories device id and
rw_hash to determine its proper firmware update payload.

This CL creates a host command that requests the type-C accessory info
attached to a particular port.  It also implements an ectool command
to expose the host command.

BRANCH=none
BUG=chrome-os-partner:31361
TEST=manual,
  # connect zinger to port 1 on samus
  ectool --dev=1 --interface=lpc infopddev 1
  Port:0 Device:1 Hash:  0x7f4d7a13 0xf07b65b9 0x41181e10 0xb99b3d5f 0x9dee1206

  ectool --dev=1 --interface=lpc infopddev 0
  Port:0 has no valid device

Also do the same on port 0 with similar results.

Change-Id: Id63c7edad77a43d43c14d8cd6bd96e08d0d9b501
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216814
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-11 20:00:07 +00:00
Todd Broch
d9c6380a66 samus: Add host command to store USB PD device id & rw_hash entry.
PD accessories that are RW update-able will broadcast their rw_hash
SHA1 digest upon connection and remain in RO briefly for a response.

In order to speed-up the response and decouple common case of
accessory is up-to-date, the PD MCU will keep a small 4 entry table of
PD accessory device ids and their corresponding RW hashes for quick
lookup.

The AP will be the source of new updates and their corresponding
device id's and RW hashes and therefore needs a method to update the
PD MCU table.

This CL creates the table, host command & ectool command to facilitate
future driver / daemon to update the RW hash entries.

BRANCH=none
BUG=chrome-os-partner:31361
TEST=manual,

  # from AP
  for i in `seq 1 8` ; do
    ectool --dev=1 --interface=lpc rwhashpd $i $i $i $i $i $i
  done

  # from samus_pd console
  pd rwhash
  Device:5 Hash: 0x00000005 0x00000005 0x00000005 0x00000005 0x00000005
  Device:6 Hash: 0x00000006 0x00000006 0x00000006 0x00000006 0x00000006
  Device:7 Hash: 0x00000007 0x00000007 0x00000007 0x00000007 0x00000007
  Device:8 Hash: 0x00000008 0x00000008 0x00000008 0x00000008 0x00000008

Change-Id: Ibe87b3594793cd5215eba42160489b26974aadbc
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214366
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-09-11 19:59:59 +00:00
Anton Staaf
dcf496c788 Util: Make MAX and MIN macros side effect safe
Previously the MAX and MIN macros evaluated their
arguments twice.  This can cause problems with parameters
that have side effects, or parameters that are volatile.

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

BRANCH=none
TEST=make buildall -j

Change-Id: I51c6c6c207d9cd4d11a3b4d237eb9e491a9c4935
Reviewed-on: https://chromium-review.googlesource.com/215990
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-09-09 20:59:41 +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
Vic Yang
e523cf49b2 Put 'hostcmd' console command behind a config flag
This command was intended to be used for testing, but we have moved on
to the compiled unit tests. Let's put this command behind a config flag
to save precious flash space. This frees up about 640 bytes.

To make sure no one is using this, I searched for "hostcmd" in
platform/ec/test and third_party/autotest/files/server/site_tests.

BUG=None
TEST=make buildall
BRANCH=None

Change-Id: I3192214b71c033c2388f687ed891203d1d119bb9
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214828
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-09-01 11:06:57 +00:00
Vic Yang
1b358e2c93 ryu: disable system hibernate
Hibernate is not supported on STM32F0. Disable system hibernate so that
the system doesn't auto-reboot after an hour in G3. This also benefits
us in terms of firmware size.

BUG=chrome-os-partner:31665
TEST=Boot on Ryu. Check 'hibdelay' and 'hibernate' commands are absent.
TEST=Boot Ryu from G3.
TEST=Change default hibernation delay to 1 second. Put system in G3.
Check it does not reboot.
BRANCH=None

Change-Id: Ia01d2d74bc5c22c01e29e5877bd4bd38ee7dddc8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214834
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-29 03:00:07 +00:00
Sheng-Liang Song
7bea5174a1 EC: Add smbus interface read & write APIs
Ref: http://smbus.org/specs/smbus20.pdf

- Support software CRC8 generation and checking.
- Support read/write word (2-bytes)
- Support read/write blocks (up to 32 bytes)

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

Change-Id: Ic2e7f759af80c06741ed49fee1826213429fbf8a
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209747
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-29 02:57:00 +00:00
Alec Berg
b7f1d52619 zinger: samus_pd: change zinger SW ver to report commit count
Change the zinger software version returned by VDO_CMD_READ_INFO
to report the commit count portion of the version string to make
the software version automatically change. This software version
is important for debugging and is printed to PD console every time
a zinger is attached.

BUG=none
BRANCH=none
TEST=load onto zinger and samus, plug in zinger and see:
Dev:1 SW:2147 RW:0
compare to the version string in zinger binary and we see:
zinger_v1.1.2147-...

Change-Id: Ieafe89b4b16cee076be17bcbc6774bbd7fc24f8e
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214428
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-28 20:12:52 +00:00
Alec Berg
d9fe6f32c4 pd: add sending read info VDM every time source is plugged in
Every time a type-C source is plugged in, send a special VDM to
read device info. Device info will contain RW Hash (sha1), a
unique hardware descriptor (USB_PD_HARDWARE_DEVICE_ID), a
software version number just for debugging (USB_PD_DBG_SW_VERSION),
and a flag for if the device is in RW. This feature is off by
default and can be turned on by defining
CONFIG_USB_PD_READ_INFO_ON_CONNECT, currently defined for samus
and ryu only.

Renamed the read RW_HASH VDM to READ_INFO since it now returns
more than just the hash.

When device info is received, we store the RW hash. In the future
we will use this to check if device needs an update.

BUG=chrome-os-partner:31361
BRANCH=none
TEST=load onto a samus and a zinger. test when you attach zinger
we send a VDM, and we get device info printed to console. also
use "pd 0 hash" to query last hash received.

Change-Id: I0ca57651cf8506ea738b080a6cf8e7b020ef8724
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213832
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2014-08-27 01:30:03 +00:00
Alec Berg
1933fb8ff7 samus: add ability for PD MCU to send host event to AP
Add host event for PD up to AP. The PD toggles a gpio line to
EC causing an interrupt on EC. The EC then sends host command
down to PD MCU to get its status. There is a new status bit for
PD host event, so when EC see's the PD host event status bit,
it sends a PD host event to the AP.

There is currently only one host event for PD to AP.

BUG=chrome-os-partner:31361
BRANCH=none
TEST=added PD console command pdevent, which initiates the host
event. when sent, verified on EC that it sets the correct host
event bit using hostevent console command

Change-Id: If1a59a3232e2f9a49f272c6dee5319254d87b9a9
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213371
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-27 01:29:58 +00:00
Alec Berg
e913bc15b8 samus: add host commands for flashing zinger RW
This adds a new host commmand for sending RW updates to PD devices.
The host command has a variety of sub-commands for performing the
update, including: erase RW, reboot, write new hash, write flash.

To program zinger RW, you should send host commands in this order:
write new hash to all 0's
reboot (zinger boots into RO since RW hash doesn't match)
erase RW
write flash
write new hash to match contents of RW
reboot

This also adds an ectool command to write a new RW. Just pass it
the RW .flat or .bin file.

BUG=chrome-os-partner:31361
BRANCH=none
TEST=ectool --dev=1 --interface=lpc flashpd 0 0 zinger.RW.flat

Change-Id: Ia81615001b83ad7ee69b1af2bf1d7059177cde04
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213239
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-26 23:06:23 +00:00
Vic Yang
b22c10ce2e ryu: gate SCL to PI3USB9281
As a short term workaround for the I2C problem of PI3USB9281, we're
gating its SCL input when it's not addressed. This workaround will be
removed once we have the silicon fix.

BUG=chrome-os-partner:31526
TEST=Sanity check on P0 boards.
BRANCH=None

Change-Id: I57daf25f2ad2d94ac7e4192050b4d6bbdae9d51d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/214064
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-26 21:02:49 +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
Vic Yang
050c7df011 Add inductive charging control module
This module controls the inductive charging transmitter. For now, the
policy is to charge whenever possible.

BUG=chrome-os-partner:31392
TEST=Unit test passed
BRANCH=None

Change-Id: Ie48a38ad92fe2bc3329c4962e96572f2bc40b4e6
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212715
2014-08-25 20:52:32 +00:00
Duncan Laurie
9e79ca7949 Support inverted ILIM_SEL for smart USB port power
Some platforms may have active low ILIM_SEL that is per-port
and the output needs to be inverted.

BUG=chrome-os-partner:31549
BRANCH=samus
TEST=emerge-samus chromeos-ec, not used until EVT

Change-Id: I1e164d9aa46df119467113eb175e7deec4fd8a21
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213743
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-23 02:42:21 +00:00
Bill Richardson
e307172bd5 lightbar: Enable tap-for-battery even in G3
This adds an optional lb_power() function that the lightbar TAP sequence can
use to briefly power up the lightbar rails while the AP is shut down.

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

Shut the AP down, then from the EC console run "lightbar seq tap". The
lightbar should light up and briefly indicate the current power levels. You
can manully force the battery status with "lightbar demo on", then use the
arrow keys to change the state.

Note that the Samus that I tested on had trouble recognizing when it was
charging or not. That's a separate bug.

Change-Id: Iad3f08506d9e049e89d0711af00da2f1aa2337e0
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213664
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-08-22 05:47:54 +00:00
Alec Berg
c7c312d057 zinger: add custom VDM to read last measured current
Add custom VDM to read last measured output current in mA.

BUG=chrome-os-partner:30850
BRANCH=none
TEST=Run "pd 0 vdm curr" on samus pd console and verify
reasonable current

Change-Id: Ie1f1ab235560eb4e90f399ceac31c5cd93003d80
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212981
2014-08-22 05:47:49 +00:00
Alec Berg
445691932c pd: zinger: Turn off pings by default
Turn off sending pings in SRC_READY by default. Added custom VDM
to turn pings back on, which only zinger supports right now.
Changed the "pd ping" console command to be used to enabled/disable
pings in SRC_READY.

BUG=chrome-os-partner:31409
BRANCH=none
TEST=loaded onto samus and zinger. on samus_pd, enabled highest
level of debug info: "pd 0 debug 2" to allow printing ping received.
Then plugged in zinger. By default, we negotiate to SNK_READY and
receive no pings. Then send "pd 0 vdm ping 1" to send VDM to zinger
to enable pings, and verified we start receiving pings. Sending
"pd 0 vdm ping 0" sends VDM to stop sending pings.

Change-Id: I4f64c6fc59bb734146eeca5e3ea3a24954c786b2
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212965
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2014-08-22 05:47:44 +00:00
Aaron Durbin
97a4fd2751 power_button: expose raw signal assertion
It's useful to expose the logic of the power button assertion
according to the CONFIG active level at the hardware input.
Therefore, provide power_button_signal_asserted().

BUG=chrome-os-partner:31481
BRANCH=None
TEST=Benson tested this on ryu since has the button cables.

Change-Id: Ica48bfe981550700a067406cb72908e14dbccba9
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213298
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-21 08:02:00 +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
Dominic Chen
f3c308108b usb: add CONFIG_USB_INHIBIT to prevent automatically starting USB
BUG=none
BRANCH=none
TEST=usb does not autostart, and can be enabled/disabled

Change-Id: I22a7bf3ca9cb7013cc4964dbdabff7524985d9ba
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212509
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-16 05:22:50 +00:00
Dominic Chen
c9809547c2 usb: add support for mass storage (bulk-only)
implement USB mass storage class using the bulk-only transport
protocol with the transparent SCSI command set.

BRANCH=none
BUG=none
TEST=verify that usb mass storage functions on windows xp, 7, 8, mac os x, goobuntu precise

Change-Id: Ideecad55bd275df7b30aa4a3ed263304a3a109cd
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206303
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-15 17:55:04 +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
c8fa85d0b4 module: add constant MODULE_USB_DEBUG for closed-case debugging
BUG=none
BRANCH=none
TEST=make buildall -j

Change-Id: I0fdc166f1b2664da84c7e375b0670db32887807e
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212371
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-14 22:44:40 +00:00
Vic Yang
116080b151 pd: issue PD soft reset on sysjump
On sysjump, we are losing all of our PD states. Instead of trying to
remember all the states and deal with on-going transmission, let's just
issue a soft reset so that the communication starts over.

BUG=chrome-os-partner:31207
TEST=With Ryu/Zinger, do 'sysjump rw' and check EC doesn't reboot.
BRANCH=None

Change-Id: I8779b74491a402434931b3455fa93ff2e178cb1f
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212123
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-14 09:09:11 +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
49ee1cb872 pd: modify PD to allow sending VDMs anytime
Change the VDM implementation in the PD task to allow for VDMs
at any time when connected without disrupting any regular PD
communications.

BUG=none
BRANCH=none
TEST=load on a samus and on a zinger and test sending VDMs:
pd 0 flash version
pd 0 flash reboot

Also, test using the flash_pd.py script to write zinger RW using
VDMs.

Change-Id: I48352978d8c45f78e8a5a7735d65b013a853f3e2
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210746
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-11 22:05:21 +00:00
Vic Yang
5ab558117d pd: use interrupt on Rx retry
After sending a message, we wait for up to 2.7 ms for reply. If we don't
get one, we retry for up to twice. Therefore, a undelivered message
could take up to >8ms. To prevent starving other tasks, let's yield to
other tasks on retries and rely on interrupt to wake us.

BUG=chrome-os-partner:28341
TEST=Plug in zinger on port 0 and C-to-A dongle on port 1. Check that
port 0 drops connection less frequently.
BRANCH=None

Change-Id: If85a70fd1140fef69d79243b198703ce601f8030
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211281
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-08-11 09:05:23 +00:00
Vincent Palatin
b61bfc8feb Add more build conditions on x86-only code.
ACPI and thermal throttling are used only by x86 platforms.
Modify the conditional build to avoid building them where they are not
used.

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

BRANCH=none
BUG=none
TEST=make buildall
check the flash size on Ryu and see we are saving about 200 bytes with
this changes.

Change-Id: Ie5e1603fb3bea95eaa5cb1e6cb19f4ddb0e235e8
Reviewed-on: https://chromium-review.googlesource.com/210056
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-08-10 18:39:24 +00:00