Commit Graph

1072 Commits

Author SHA1 Message Date
Vincent Palatin
61d50195e1 disable DMA before sysjumping
It's not safe to sysjump with a DMA enabled as it can led to memory
corruption after we have landed in the new image before that piece of
hardware is re-configured.

Implement and call dma_disable_all() on all platforms with generic DMA.

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

BRANCH=all
BUG=chrome-os-partner:34865
TEST=on various boards, call "sysjump rw".

Change-Id: I2a6b63ff19c2d932a5e31bc375bf468bc8ae5125
Reviewed-on: https://chromium-review.googlesource.com/237340
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2015-01-08 22:36:31 +00:00
Todd Broch
a5a2b263f8 pd: Return immediately to host from erase RW.
With CL:
 5ef45ad pd: Add timeout for HC flash commands.

I thought I'd licked the timeout related issues with flashing dingdong
& hoho.

With further testing however I found I was occassionally hitting the
failure where I couldn't return from 'flash erase' on PD peripheral
prior to the 1 second limit for host command timeout.

That could be remedied by retrying the erase on the host side which
then succeeds quickly.  That solution seems non-optimal however.
Additionally, even when erase does succeed in <1sec we have the shared
i2c bus pending.  That too is non-optimal.

For those reasons I've decide to return immediately from flash erase
command and instead put the burden of waiting the necessary time on
the host which at least does have some wider perspective on what the
system is attached to and doing.

CL also adds following related changes:
  1. corresponding ectool edit to delay 3sec after RW erase.
  2. fixup to error returns from hc_remote_flash for timeouts.

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

BRANCH=samus
BUG=chrome-os-partner:33947
TEST=flashing dingdong/hoho via ectool works reliably.

Change-Id: I8fbfb592f760273b26bcb16b67210d569454eee2
Reviewed-on: https://chromium-review.googlesource.com/239253
Trybot-Ready: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-08 21:03:38 +00:00
Todd Broch
d63c3b4f92 pd: Refactor exit mode.
Refactor pd_exit_mode to be only a DFP function.  Additionally make
pe_init a public function and call it during hard reset.

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

BRANCH=samus
BUG=chrome-os-partner:33946
TEST=manual, using pdsetmode from later patches see proper exit and
resetting of pe struct.

Change-Id: I45afe1f82926f1c32f4d84eb60c65f1f39b19d81
Reviewed-on: https://chromium-review.googlesource.com/236958
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-01-08 21:03:33 +00:00
Vincent Palatin
cca794d2fe pd: dingdong/hoho: Enable flash write-protection
These USB type-C accessories don't have a write-protect GPIO.
Add a configure flag (CONFIG_WP_ALWAYS) to force the flash
write-protection on the dongles.

Also set the read protection (by elevating RDP to level 1),
so trying to unprotect the flash will trigger a full erase.

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

BRANCH=samus
BUG=chrome-os-partner:35088
TEST=boot Hoho,
check the flash OBR and WRPR registers:
"rw 0x4002201c" / "rw 0x40022020"
and the option bytes write-protect bits: "rw 0x1FFFF808"
dump the logical state with "flashinfo" command.
> rw 0x4002201c
read 0x40022020 = 0xffff0002
> rw 0x40022020
read 0x40022020 = 0xffff0000
> rw 0x1FFFF808
read 0x1ffff808 = 0xff00ff00
> flashinfo
Physical: 128 KB
Usable:   128 KB
Write:      2 B (ideal 2 B)
Erase:   2048 B (to 1-bits)
Protect: 4096 B
Flags:   wp_gpio_asserted ro_at_boot ro_now
Protected now:
    YYYYYYYY YYYYYYYY ........ ........

Change-Id: I45bbc0bce40ecc174b6b8a1ebacf4f53d2fd372d
Reviewed-on: https://chromium-review.googlesource.com/238893
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-01-08 00:38:17 +00:00
Anton Staaf
dc1362ca82 Queue: Add methods that accept a memcpy routine
These versions of the queue add and remove methods support
using memcpy like routines to access regions of memory with
specific requirements.  In particular, this will allow for
transfers between queues and USB packet RAM on the STM32
which has specific access requirements.

This change also includes an update to the mem* util routines
to make their prototypes compatible with C89 and POSIX
standards.

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

BRANCH=None
BUG=None
TEST=make buildall -j
     Test USB Echo functionality on discovery-stm32f072 board to
     ensure that queues still function correctly.

Change-Id: I557064d99abfc3e8cfc98099a1d94334a976550c
Reviewed-on: https://chromium-review.googlesource.com/239217
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
2015-01-08 00:38:13 +00:00
Anton Staaf
18d3bde7f8 USB: Add memcpy_from_usbram and update existing memcpy
Previously there was just a memcpy_usbram that copied to
USB packet memory, and no routine to copy out.  This adds
the "from" version and renames and improves to "to" version.

The improvement is that the new "to" version correctly
handles unaligned beginning and endings of the region to
be copied.  These need to be read/modify/write accesses since
the USB packet ram has to be manipulated in 16-bit chunks.

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

BRANCH=None
BUG=None
TEST=make buildall -j
     Verify that discovery-stm32f072 still enumerates and communicates
     correctly over USB.

Change-Id: I94353e66ad0248d4e674abb29f9a88e979767655
Reviewed-on: https://chromium-review.googlesource.com/238764
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
2015-01-08 00:38:09 +00:00
Anton Staaf
b1f0a4ca4e USB: Delete mass storage driver
This was an attempt at providing support for flashing a
SPI flash device over USB, but it suffered from being
rather complex and large.  A simpler solution of bridging
SPI over USB directly and writing a SPI over USB driver
for flashrom is being used instead.

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

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

Change-Id: I0d1ef8f17f5d6a4de46003096a8bff4a33b41cb7
Reviewed-on: https://chromium-review.googlesource.com/238763
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: David Schneider <dnschneid@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
2015-01-08 00:37:46 +00:00
Anton Staaf
e75c33e283 OutStream: Remove unused prototypes
These prototypes are for functions that didn't make
the final cut and should have been removed before this
header was committed.

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

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

Change-Id: I46726d20c25898681890caa95ad71500272fb7f6
Reviewed-on: https://chromium-review.googlesource.com/238753
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
2015-01-07 19:44:21 +00:00
Alec Berg
09ad65d4ad pd: fix bug when forcing port to sink
When changing a port that is sourcing power to a force sink role,
then make sure VBUS is turned off before going to SNK_DISCONNECTED.

BUG=chrome-os-partner:34036
BRANCH=samus
TEST=test on plankton with samus. verify can change from source to
sink multiple times with no problems

Change-Id: I781f6f4395845f949d00b322e4e87c150aeba187
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/233755
2015-01-07 18:44:31 +00:00
Vic Yang
140aa36904 pd: Show literal PD state name for 'ectool usbpd'
Currently, 'ectool usbpd' shows PD task state in numerical format. Every
time we add/remove a state, the number changes, and this makes the
command difficult to use. Modify the command to print the name of the PD
task state.

BRANCH=Samus,Ryu
BUG=chrome-os-partner:34296
TEST=Run 'ectool usbpd 0' with different combination of new/old PD
firmware and new/old ectool.

Change-Id: Ic0daa03e9f7565c1322166713c2cce3b7cb93a30
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/237623
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
2015-01-07 17:48:15 +00:00
Todd Broch
5ef45ad19e pd: Add timeout for HC flash commands.
For flash commands add timeout so if VDM doesn't return properly host
can receive error message.

Note, for flash erase its performed by page at a cost of 20-40ms
according to datasheet. For hoho/dingdong that leaves maximum erase
time at 40ms * 32 =< 1280ms which is above the host command timeout.

Increasing the host command delay (i2c bus pending) is not an option
and since the erase will complete and subsequent erases will be much
faster do to early out in physical_flash_erase this solution should be
acceptable.

Future CLs could alternatively push the burden of command latency to
host altogether and return EC_RES_SUCCESS in similar fashion to reboot
command.

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

BRANCH=samus
BUG=chrome-os-partner:33947
TEST=manual, if VDM doesn't return by timeout HC command is properly returned
EC_RES_TIMEOUT error code.

Change-Id: I33c515200c2999dd97fdd690a7e900c5548b2d47
Reviewed-on: https://chromium-review.googlesource.com/238290
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-07 08:45:38 +00:00
Todd Broch
c0f64b13e9 pd: vdm: Add VDM related timeouts and busy response handling.
Initial VDM implementation had a very conservative 500msec timeout period.  This
CL adds the timeouts defined in the USB-PD specification for various commands.

Additionally it adds a state to the vdm state machine to allow proper busy
response handling.

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

BRANCH=samus
BUG=chrome-os-partner:30645
TEST=manual,
Alternate mode and flashing still work.  Creating a VDM responder which returns
busy shows retries from initiator after at least 100msec.

Change-Id: I79f5da557ca9faf63d2299bb77009f6d98a782bd
Reviewed-on: https://chromium-review.googlesource.com/235682
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-07 08:45:34 +00:00
Alec Berg
98daf2a9d1 samus: add hot keys alt+voldown+0|1|2 to set charging port
Add hot key detection for alt + volume down + 0|1|2 to set the
charging port by sending the charge override command to PD MCU.

This should be removed once hot-keys (or some other UI) is added
to higher layers.

BUG=chrome-os-partner:34850
BRANCH=samus
TEST=load onto samus and connect to another samus. use hot keys
and see that charge override command gets set appropriately on
PD MCU.

Change-Id: I7e72d597a02b7aca3326911796d20003f6697077
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238226
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-07 02:32:52 +00:00
Alec Berg
e39f43ed2d samus: pd: on PD connection, if sink, ask for power swap
For samus, on PD connection or on resume to S0, if we are a sink,
and the other side supports PR_SWAP, then attempt a power swap.

This adds callback functions into board policy file to check
and issue power or data swaps if required by the product.

BUG=chrome-os-partner:31195
BRANCH=samus
TEST=connect samus to zinger and make sure zinger always ends up
as SRC-UFP.

connect samus to samus with both in S0 and see that
they swap power roles once and not data roles.

connect one samus in S0 to one samus in S5 and see that the one
in S5 is sink. then when you boot the one in S5 it switches to a
source.

connect samus to samus with both in S0. do chgoverride 1 on one
side to start charging from the other samus. then on the same
side, turn off the machine (S5) and resume (S0), and see that it
is still charging from the other samus (ie has not switched roles
to source).

Change-Id: Ifab2465fccef77448ac4771a3c2de1c867cbbec4
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238302
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-07 02:32:38 +00:00
Alec Berg
5348dff126 pd: Add NoResponseTimer to disconnect after no response
Add NoResponseTimer to go to disconnected state after some number
of hard resets with the port partner non-responsive. This only takes
affect when the port partner is known to be PD capable, i.e. has sent
us PD communications in the past. This is useful as a last resort to
attempt to restore PD communications with a port partner.

BUG=chrome-os-partner:34976
BRANCH=samus
TEST=load onto two samus', connect with C to C cable, and let them
form a PD contract, then on one side disable PD comms with "pd enable 0"
and from the other side initiate some PD traffic, such as "pd 1 soft".
See that the side with PD communications enabled sends two hard resets
and then goes to disconnected state, then goes to discovery state and
acts as if a non-PD capable device is attached.

Change-Id: Id40ce7eb05b8b7ae6a4f70b9d08ce6cad0d471fe
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238300
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-06 22:19:22 +00:00
Todd Broch
2b364421a4 pd: Add CONFIG_CMD_TYPEC to optionally remove 'typec' console command.
Create optional config to remove 'typec' command for flash savings.
While its a useful command to many developers its not used in any
factory flows and costs ~500bytes of flash space.

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=manual, compiles and command still there.  If #undef saves ~500bytes.

Change-Id: I02c0ec1dd503b02f86d8ac3d5e99ed6ad493c95c
Reviewed-on: https://chromium-review.googlesource.com/238462
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-06 04:46:01 +00:00
Todd Broch
efb28cc783 Add CONFIG_CMD_HASH to optionally remove 'hash' console command.
Create optional config to remove 'hash' console command and undef it
for a few space-constrained boards (ryu*, samus_pd).

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=manual,

- compile for ryu, samus_pd and save ~400bytes
- 'hash' command no longer appears as a console command

Change-Id: I054fd4473911dd362c2c1d171ee7aaad859d893a
Reviewed-on: https://chromium-review.googlesource.com/238433
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-01-06 04:45:53 +00:00
Vic Yang
c3adc315b3 Support command versioning of new host command range
We've extended host command range from 8-bit to 16-bit. Extend
EC_CMD_GET_CMD_VERSIONS so that the host may query supported command
versions of the new host commands.

BRANCH=All
BUG=chrome-os-partner:26577
TEST=Extend 'usbpd' to version 1. Test that we can check its version.
TEST=Run 'ectool gpioget' with new ectool and old EC.
TEST=Run 'ectool gpioget' with old ectool and new EC.

Change-Id: I1651aaf21ac2604aea101244b5e53713ead8c1af
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/237622
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-06 02:33:04 +00:00
Shawn Nematbakhsh
6fec4e4a69 lightbar: Pulse lightbar in S5 if power-up is inhibited
Add a lightbar indicator if a charger is attached and we refuse to
power-up the AP due to battery level.

BUG=chrome-os-partner:31127
TEST=Manual on Samus. Attach charger with depleted battery, verify that
lightbar pulses red. Remove charger and verify that lightbar stops
pulsing. Also verify the same with missing battery.
BRANCH=Samus

Change-Id: Icddd543dc34e36ac04957ea07bde0e2d5709f74b
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236023
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-06 01:19:06 +00:00
Todd Broch
7121b003d6 pd: remove PD remote flashing console command by default.
Add config option, CONFIG_CMD_PD_FLASH,  and undef by default.  This subcmd in
the 'pd' command is large (500 bytes) and can be performed from host via
ectool.

Additionally the python script, util/flash_pd.py, is likely outdated or needs
adjustments for various timing related nuances.

Note, as flash command contained subcmd 'version' have added that under
'pd <port> vdm vers' to keep that functionality by default.

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=manual,
 run 'pd 1 flash signature' get 'parameter 1 invalid'
 run 'pd 1 vdm vers' w/ zinger in port 1 see version string returned.

Change-Id: If282933c1d29febb43b5cf476a121be6b5a1071b
Reviewed-on: https://chromium-review.googlesource.com/238291
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-01-05 22:42:18 +00:00
Alec Berg
20cf373463 pd: change receive timeout to 1.8ms
Change PD receive timeout to 1.8ms. The max packet ever received
should be ~1.59ms, so this should be safe.

BUG=chrome-os-partner:33693
BRANCH=samus
TEST=load onto zinger and samus and connect a bunch of times.
also tested with PD communication disabled on samus and verified
that zinger sends source cap 50 times (each with 4 retries) and
then stops.

Change-Id: If82b2905d6f9118956229682d7f259fb94da0258
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238305
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-05 19:11:03 +00:00
Alec Berg
71fb0f9e11 pd: add new state to wait for getSinkCap response
Add new state to wait for getSinkCap response. We use the READY states
in the PD state machine to indicate that we are not waiting on a response.
This assumption is necessary for VDMs to know whether or not it is ok
to send. This CL fixes a bug in that assumption.

BUG=chrome-os-partner:33861
BRANCH=samus
TEST=load onto zinger. without this change, under the right circumstances
it was possible for a collision between a VDM (response to discover identity)
and an incoming response to the getSinkCap. This would cause the discovery
identity response to get dropped. with this change, when discover identity
response is queued it is delayed until after the getSinkCap response.

Change-Id: I16f4d5272e68bf699d0aecba12bdf6d6b8ff7fc7
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238239
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-03 02:26:42 +00:00
Alec Berg
2b08951797 samus: when battery is full, and not in S0, stop charging
When battery is full and system is not in S0, then stop charging
and allow battery to power the system. Once battery is no longer
full and requests current, allow charging again. This is to work
around power consumption issues in our AC input path. The charge
override port is stored upon entering S3 and restored going back
to S0 so that the charge override port is not affected by this.

This also fixes lightbar so lightbar checks if battery is full
instead of checking raw percentage. The lightbar is also changed
to use the last tap direction if no charger is plugged in. And
the lightbar tap for battery threshold for turning green is
lowered to 95%.

This also moves some samus_pd board code out of interrupt handlers
and in to deferred functions to minimize time in interrupts.

BUG=chrome-os-partner:34640, chrome-os-partner:34847
BRANCH=samus
TEST=load onto samus. use battfake command from pd console to
set battery percentage. when system is in G3, see that
batt = 100% stops charging, and when batt < 100% it starts
charging again.

tested that we receive host command from EC with battery
information every time battery changes SOC.

Change-Id: Ia8e0721508e34ee3630f5e5b0c2f431a00329caf
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236411
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-03 02:26:21 +00:00
Alec Berg
415a994d58 pd: change hard reset power supply off delay
Change delay between sending hard reset and cutting VBUS
from PD_T_SINK_TRANSITION (35ms) to the new timeout
PD_T_PS_HARD_RESET (15ms).

BUG=chrome-os-partner:34985
BRANCH=samus
TEST=make -j buildall

Change-Id: I1dfcdc790ae748aa56350814d8c40d376eba68fc
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238230
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-03 00:46:20 +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
Kevin K Wong
850ef52982 mec1322: Added support to use crystal vs oscillator based on board's clock circuitry.
BUG=None
TEST=make -j buildall
BRANCH=None

Change-Id: I88fa219cd9e573c1544400d24d00c4fdec93840f
Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/237272
Reviewed-by: Vic Yang <victoryang@chromium.org>
2014-12-29 19:04:38 +00:00
Todd Broch
97730b5be1 pd: vdm: remove replicated VDM code.
Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:30645
TEST=manual,
Still see alternate mode entry and can use flash VDMS

Change-Id: Id7371960a20e7d26a15b3a40ca40aa03b6595956
Reviewed-on: https://chromium-review.googlesource.com/235681
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2014-12-22 21:50:23 +00:00
Todd Broch
89559b0d67 pd: Remove pe dump command by default.
Marginally useful command being replaced by host command
in later patch (ectool --name cros_pd pdgetmode).

Hide behind config option CONFIG_CMD_USB_PD_PE.

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=compiles, command is gone and gain >700 bytes of flash.

Change-Id: I09deeb997744757a836438eb3217f9b432bdd11c
Reviewed-on: https://chromium-review.googlesource.com/236957
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2014-12-22 21:50:13 +00:00
Shawn Nematbakhsh
29a57a037a system: Add function to convert passed system_image_copy_t to string
This conversion is needed in files outside of system.c, so add a new
function.

BUG=chrome-os-partner:34599
TEST=Manual on samus_pd. Run "pd 0 info" and verify "Image RW" is
printed.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>

Change-Id: Ia905ba9cf985f3714fa75c81670b8a39e9608f3d
Reviewed-on: https://chromium-review.googlesource.com/236980
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Shawn Nematbakhsh <shawnn@chromium.org>
2014-12-22 21:50:07 +00:00
Shawn Nematbakhsh
c69e9ceb31 pd: Modify EC_CMD_USB_PD_RW_HASH_ENTRY to return PD device image type
This addition allows the AP to query whether the PD device is currently
running from RO or RW FW.

BUG=chrome-os-partner:34599
TEST=Manual on Samus. Run 'ectool --name cros_pd infopddev 0' and verify
that correct RO/RW status of Zinger is printed. Verify that the output
matches the index printed by "pd 1 hash" on samus_pd console.
BRANCH=Samus

Change-Id: I4266cae931f5c7855ca0531717c4a18b138b2d62
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236771
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-20 08:54:18 +00:00
Myles Watson
221e5ca878 Add support for shared interrupts.
The nRF51 chips from Nordic have shared interrupts.

Having a flag for that makes it easier to implement.

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

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

Change-Id: I89c78ace99085c359db8515667eaffb5617f0162
Reviewed-on: https://chromium-review.googlesource.com/234390
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Myles Watson <mylesgw@chromium.org>
Tested-by: Myles Watson <mylesgw@chromium.org>
2014-12-19 00:05:16 +00:00
Shawn Nematbakhsh
86835f7067 charge_manager: Allow board to reject a selected charge port
Modify board_set_active_charge_port to return status indicating whether
the selected charge port was rejected. If rejected, zero out its
available charge and attempt to select a different charge port.

Also, reduce the length of related console prints.

BUG=chrome-os-partner:34677
TEST=Manual on Samus. Plug C-to-Arec into port 1, verify that charge
manager does not select port 1 as active and charging icon is not seen
in OS.
BRANCH=Samus.

Change-Id: I56e3337f90c04b93ef7cc9873af6ee0f4b1ffc7d
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236361
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-17 22:26:56 +00:00
Shawn Nematbakhsh
a7bae3588c power_button_x86: Inhibit AP power-on if battery level is too low
Allow CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON to be defined at the board
level to be the minimum battery percentage required for power-on. If the
battery level is below the threshold, or if the battery is missing,
power button presses will be ignored.

BUG=chrome-os-partner:31127
TEST=Manual on Samus with subsequent commit. Verify that AP continues
to boot normally when charge level exceeds
CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON. Verify that power button
presses are ignored when the charge level is below the threshold, and
we return to G3.
BRANCH=Samus

Change-Id: I0ff3f7ddabf38080332470e172c8b2e307bf1655
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236021
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-17 18:07:10 +00:00
Alec Berg
6c980a4dbf pd: check for collisions before transmitting
Added check for collision just before transmitting on CC line.
To check for collision, RX monitoring is left on all the time
(except when in the act of receiving or transmitting, or in
between receiving and sending a goodCRC), and a
simple check for RX transmission started is used to see if the
CC line is idle or not.

RX monitoring is also changed to only trigger on 3 edges within
20us, as per the PD spec.

When a collision is detected by seeing that CC is not idle, the
transmitting packet is dropped.

BUG=chrome-os-partner:30135
BRANCH=samus
TEST=load onto samus and zinger. make sure we negotiate and make
sure custom VDMs succeed. enabled pings and made sure we stay
alive with pings for a few min.

Also added code to pd_rx_handler to toggle a test point on EVT
board to verify the timing of when we get RX interrupts:

Change-Id: I22d172163319437d3d901e019eda79d4d592f6b8
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/226118
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-12-17 03:27:17 +00:00
Alec Berg
3c0d9166cf host_command: add rate limiter to HCs to prevent EC watchdog
Add a rate limiter to host commands so that a host that is continuously
sending host commands doesn't watchdog the EC.

BUG=chrome-os-partner:33905
BRANCH=samus
TEST=loaded onto samus and tested remote update of zinger 10 times.
also tested EC + PD software sync.

Change-Id: Ia024179c46b2180ee97ea1902de343306142311c
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/235530
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-12-17 02:12:57 +00:00
Todd Broch
07203ac931 Add config option to reduce GPIO name string size.
In order to reduce flash size on some constrained boards this CL
modifies the GPIO macro in gpio_list.h to change the name field from
that listed 'name' to the concat of 'port' and 'pin'.

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=manual
1. build with and without CONFIG_COMMON_GPIO_SHORTNAMES
See 897 bytes savings with config option
2. See reduced names for gpioget
  > gpioget
    0  E6
    0  F2
    1  B0

Change-Id: Ife1e1e2bcfa620ba87fe6c1ce2b47fe258c46514
Reviewed-on: https://chromium-review.googlesource.com/234587
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2014-12-16 22:47:50 +00:00
Gwendal Grignou
91ca05cf3a ryu_sh_loader: Add board directory for load image
Ryu sensor hub has asymectric RO/RW images. The first one is very limited
(not i2c master, no sensor drivers, gesture recognition).

Image size is alter to offer more space for the RW firmware image,
compiled with ryu_sh board.

To write RO image and basic RW image:
flashrom -V -p ec:type=sh,block=0x800 --fast-verify -w /tmp/ryu_sh_loader/ec.bin
To write the expected RW image:
flashrom -V -p ec:type=sh,block=0x800 --fast-verify -w -i EC_RW:/tmp/ryu_sh/ec.bin

BRANCH=ToT
BUG=chrome-os-partner:33908
CQ-DEPEND=CL:231970,CL:233233
TEST=load on Ryu, confirmed limited operation.

Change-Id: Ib976e2b048935adfb9b2b072c071db5be2bc1c09
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/231984
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-12-15 22:46:21 +00:00
Alec Berg
fca4977983 samus: add high battery temp warning to charge state machine
Add high (and low) battery temperature warning which sends host
event to AP. After 30 seconds of out of range temp readings force
shut off AP and hibernate the EC.

BUG=chrome-os-partner:27641, chrome-os-partner:33111
BRANCH=samus
TEST=make buildall, and write unit tests to test this condition.

Change-Id: I95b7d9d753c17e4b76218a9845aa63dd1b96a500
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/235645
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-12-15 22:44:28 +00:00
Alec Berg
6cc992c3d7 samus: fix charge state machine's handling of low power chargers
On samus it is possible to have AC plugged in but have the battery
discharging. So, add a new variable to charge state machine for
battery charging status and use that where necessary. For example,
the low battery shutdown code should now be based on whether or
not battery is charging rather than if AC is present.

This also changes the hibernate behavior when battery is low. The
change is to wait 30 seconds in G3 of low battery with no charging
before hibernating because for some chargers, like a USB PD charger,
the charger may increase it's current limit after a little bit of
time.

BUG=chrome-os-partner:34485
BRANCH=samus
TEST=test on samus. use low power charger and make sure that
ectool battery shows the "DISCHARGING" flag. use zinger and see
"CHARGING" flag. also use power_supply_info to make sure that
the battery state accurately reflects reality.

Change-Id: I8ac0267dd393071c4ca1fa24fbc9a13bf27848a9
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/235491
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-12-15 19:53:46 +00:00
Alec Berg
34fe8658ab pd: refactor pd policy layer request voltage functions
Remove common code across all PD policy layers to select the requested
voltage and build a Request Data Object (RDO).

BUG=none
BRANCH=samus
TEST=Load onto samus and connect zinger. Make sure we request the right
voltage (first 5V, then after initial contract is made, 20V). Make
sure input current limit is set appropriately by checking limit on EC
console using charger command.

Change-Id: Ic6bda5e23b2d7b7d710ffdf085e7fbc1b0c3add9
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/233673
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Shawn Nematbakhsh <shawnn@chromium.org>
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
2014-12-11 21:13:48 +00:00
Bill Richardson
401498bb6a lightbar: ask the PD MCU for the charge direction
This exposes the pd_exchange_status() function and lets it
return the charge port that the PD reports, so that the lightbar
TAP sequence can decide which direction to display.

BUG=chrome-os-partner:32227
BRANCH=ToT, samus
TEST=make buildall -j

Change-Id: I78b57fbeaaf38fee15c86eca4d90abce77e2f722
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/232092
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-11 04:23:33 +00:00
Vincent Palatin
1b1c3089af g: implement GPIOs
Add a driver for the GPIO controller.

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

BRANCH=none
BUG=chrome-os-partner:33816
TEST=press the push buttons on the board and see the console text
message and the LEDs lighting up.

Change-Id: Idb408fe1c341beb8a97f2047ba6740e0d40cedf5
Reviewed-on: https://chromium-review.googlesource.com/233307
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-12-10 22:14:07 +00:00
Shawn Nematbakhsh
6f010b635d charge_manager: Add delayed port override for role swap
If override charge is selected on a port currently acting as a charge
source, but the attached device is also capable of acting as a source,
request a charge role swap and initiate a pending delayed port override.
If the role swap completes successfully and a charge source is found,
the selected port will become the override port. If the role swap fails
or no charge source is found within 2 seconds, the delayed port override
will be lost.

BUG=chrome-os-partner:28343,chrome-os-partner:31195
TEST=Manual on Samus. Connect two Samus units together through charge
ports.
"pd 1 swap power" - put port on test device into source role
"chgoverride 1" - set charge override, verify that role swap takes
effect and charge manager selects PD charge source, 900mA @ 5V
Disconnect charge cable, verify that charge manager goes back to not
charging.
BRANCH=Samus

Change-Id: Iadcc4dc98631661f254245eeff18973df517f652
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/231900
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-09 02:07:03 +00:00
Anton Staaf
0967049df6 USB: Add setup packet struct and parsing routine
This can be used by interface specific EP0 setup
packet callbacks.  The USB-SPI bridge will use
this to handle enabling and disabling the bridge.

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

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

Change-Id: I3f3db65934707243f54bed9e093f376b6978d271
Reviewed-on: https://chromium-review.googlesource.com/232367
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
2014-12-08 21:51:43 +00:00
Alec Berg
8bb26a29b0 pd: before sysjump send soft reset and then disable PD comms
Before sysjump we need to send a soft reset to any attached devices
and then disable PD communication so that we don't re-negotiate again
before the sysjump. This will guarantee expected message ID is cleared
for after the sysjump.

This also moves executing soft reset from before sending the soft reset
command to after the port partner accepts a soft reset.

BUG=none
BRANCH=samus
TEST=test on samus. without this change, when sysjumping the PD MCU
has time to re-negotiate (at least partially) before the sysjump, which
causes various problems. with this change, when sysjumping, the PD
MCU sends soft reset, and then does not send anything else.

Change-Id: Id7a60c62c8908ee4ab33dfbe995ef136b0aa83de
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/233751
2014-12-08 21:51:38 +00:00
Todd Broch
bc16903667 pd: Re-factor common flash vdms.
CL to migrate the flashing VDMs from zinger's custom vdm to
common/usb_pd_flash.c such that other updateable type-C devices can
share.

Additionally adds gaskets to call standard runtime flashing facilities
for USB-PD devices using it.

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

BRANCH=samus
BUG=chrome-os-partner:31192,chrome-os-partner:31193
TEST=manual,

Try following:
    1. From samus_pd console w/ zinger in port 1

    pd 1 flash version
    pd 1 flash reboot
    pd 1 flash info

    2. From samus linux prompt  w/ zinger in port 1

    ectool --name cros_pd flashpd 1 1 <zinger RW payload>

    Reading 16384 bytes from
    /usr/local/zinger_v1.1.2528-d809e42.ec.RW.bin...
    Erasing expected RW hash
    Rebooting
    Erasing RW flash
    Writing RW flash
    Rebooting PD into new RW
    Complete

    3. Repeat 1&2 above on hoho & dingdong.

Change-Id: I018055fa9de128f937c57debdc21dea026137bcf
Reviewed-on: https://chromium-review.googlesource.com/231835
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>
2014-12-05 10:06:25 +00:00
Todd Broch
b5557217aa pd: dingdong/hoho: Fix hard reset recovery timeout.
dingdong/hoho have no capability to measure VBUS which is advantageous
in determining what timeouts to honor.  Previously we simply assumed
vbus was on and that made things happy until,

  e0c80ac pd: on hard reset go to a hard reset recovery state

which introduced proper handling around sink & source reset recovery.

With VBUS assumed 'on' this leads to short timeouts chosen
(PD_T_SAFE_0V) which in turn causes sink to resend hard resets before
source has had time (PD_T_SRC_RECOVER) to handle request.

This change creates config CONFIG_USB_PD_NO_VBUS_DETECT for devices
without the capability to account for lack of VBUS detect.

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

BRANCH=samus
BUG=chrome-os-partner:34090
TEST=manual
from samus_pd 'pd 1 flash reboot' is successful

Change-Id: I9ef9b0115c7be6c56c64556d2ce8c296f95c614e
Reviewed-on: https://chromium-review.googlesource.com/233024
Tested-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2014-12-05 10:06:19 +00:00
Bernard Shyu
fb04700b3a usb_pd: Battery PDO protocol definition errors
PDO_BATT_OP_POWER() inadvertently adopted its calculation from OP_CURR,
resulting in different division bases: 250mW vs 10mA.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: Ia03681d72fba325899566039c275e2776b212793
Reviewed-on: https://chromium-review.googlesource.com/233064
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Bernard Shyu <bernard_shyu@bizlinktech.com>
Tested-by: Bernard Shyu <bernard_shyu@bizlinktech.com>
2014-12-05 07:05:13 +00:00
Todd Broch
2bc0b68c86 pd: move get_info to common file.
get_info command needs to be used by all type-C accessories that would
entertain being updated in the field.  This CL migrates function to
common/usb_pd_protocol.c for other boards to use.

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

BRANCH=samus
BUG=chrome-os-partner:31192,chrome-os-partner:31193
TEST=manual,

Using
  ectool --name=cros_pd infopddev <0|1>

Port:1 Devid 1.1 Hash:  0x00ec9619 0x811f3e68 0x4b90c8e9 0xd5b98fa8 0xfd373777
Port:1 Devid 3.0 Hash:  0x682fd366 0x7213f55e 0xddefb802 0xbedfec42 0x5cdcc226
Port:0 Devid 4.0 Hash:  0x57b1e4e0 0x7204075f 0x65c0fa72 0xdcca15ed 0xf3231237

Change-Id: Iffa8699056351f62cf90fdecbc7ef5cee81e67bb
Reviewed-on: https://chromium-review.googlesource.com/226891
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2014-12-05 01:09:39 +00:00
Anton Staaf
0f10bf88b2 USB: Interface callbacks now return an error code
A non-zero error code returned by the callback causes EP0 to STALL.
This is the common mechanism used in USB to indicate an error while
processing a control request.  This simplifies the implementation
of interface callbacks.

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

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

Change-Id: I89ceb4892f9f810fcaf6e975e6982fc5b2ae447b
Reviewed-on: https://chromium-review.googlesource.com/232368
Reviewed-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-12-02 21:11:35 +00:00