Commit Graph

3090 Commits

Author SHA1 Message Date
Vic Yang
00551f7331 Add new build target ryu_p2 for Ryu P2 boards
The new build target ryu_p2 is mostly based on ryu. On ryu_p2, we have a
new EC chip with bigger flash, so make the corresponding changes:
  - Pinout changes
  - HW Timer: TIM5
  - USB PD Tx Timer: TIM3_CH4
  - USB PD Rx Timer: TIM2_CH4
  - Use UART2 for EC console
  - Disable UART Tx DMA as it conflicts with USB PD Tx DMA
  - Use 24MHz HSE x2 = 48MHz for SYSCLK

BRANCH=None
BUG=chrome-os-partner:32660
TEST=Sanity check on a new board:
       - i2cscan
       - PD negotiation
       - UART console
       - gettime

Change-Id: I4ef6b53a928a2777721e3874032aeb0e6b2b4c92
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221404
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-22 00:30:42 +00:00
Vic Yang
fbefbbca1e stm32: Support UART DMA on UART2
This adds the DMA channel definition for UART2 and allows selection of
DMA channel for UART.

BRANCH=None
BUG=chrome-os-partner:32660
TEST=With the CLs to enable the new Ryu boards, check the console is
working.

Change-Id: I964c284899777dda67c264e622aea6aba752ea76
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224176
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-22 00:30:39 +00:00
Alec Berg
89feca3eb3 samus: fix false shutdown due to low battery
Fix bug causing unit to falsely shutdown due to low battery.
The shutdown warning time was not getting reset, so two false
readings of battery SOC or voltage, seperated by more than 30
seconds in time would cause "charge force shutdown due to low
battery"

BUG=chrome-os-partner:33111, chrome-os-partner:33144
BRANCH=samus
TEST=make buildall

Change-Id: I6f00187516d23aa78139e5c1565febca34176ecc
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224765
2014-10-22 00:30:35 +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
Alec Berg
60ddb3987a samus: change hibernate delay to 7 days
Add macro for default hibernate delay, and set to 7 days on samus.
Also, adds CONFIG_ option for hibernating early if low on battery.
For samus, setting early hibernate at 1 day when battery < 10%.

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

Added ccprintf("Target shutdown: %.6ld\n", target_time); to print
out target shutdown time after setting it. Verifed the following
on samus

1) If CONFIG_HIBERNATE_DELAY_SEC is left at default 3600 (samus
board.h does not overwrite it), then target time is 3600s.
2) If CONFIG_HIBERNATE_DELAY_SEC is defined in samus/board.h, then
target time equals that value.
3) If CONFIG_HIBERNATE_DELAY_SEC is defined as 1 week and
CONFIG_HIBERNATE_BATT_PCT is defined to 10% and
CONFIG_HIBERNATE_BATT_SEC is 1 day, then when battery is between 8-10%
target time is 1 day and if battery is at 11%, target time is 1 week.

Change-Id: Ief155ad6c327775fa348d3458fc47ee9dd8569c3
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224520
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-21 22:44:58 +00:00
Vincent Palatin
ba98b92bbb cortex-m0: add more constraints on atomic implementation
In ARMv6-m instruction set, the load/store address register can only be
a "low" register : r0..r7.
Update the inline assembly constraints to match the hardware.

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

BRANCH=none
BUG=none
TEST=make buildall

Change-Id: I9872aeb437b2bb6401bed8076348e26d434320dd
Reviewed-on: https://chromium-review.googlesource.com/224582
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 22:44:53 +00:00
Todd Broch
cefb58066d pd: Add DisplayPort status and configure SVDMs.
Per revisements to the DisplayPort Alternate mode specification there
are two additional SVDMs for DPout support: status & configure.

This CL adds those SVDMs and calls them (status then config) after
finding a device that supports DP Alternate mode.

Future CLs will use these SVDMs to complete providing HPD over CC
support.

BRANCH=none
BUG=chrome-os-partner:31192,chrome-os-partner:31193
TEST=manual, plug hoho/dingdong into samus and see:

1. Additional DP status [16] & DP configure [17]
2. Drives DPout properly

Change-Id: I52b373085ddc330e4afb1d1883d2621bc2e4ee95
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223260
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 22:44:45 +00:00
Todd Broch
3e2f1329ab pd: Correct use of console printing in USB PD policy files.
All non-interactive console prints should use their tasks channel
parameter to make it easy for developers to inhibit console output.

This CL corrects printf's in the various usb_pd_policy files that
belong to the USB PD task to use cprintf(CC_USBPD, ...) instead of the
macro reserved for interactive console commands ccprintf.

BRANCH=none
BUG=none
TEST=manual, set 'chan 1' and see none of the previous chatter
relating to USB PD.  set 'chan 0x08000000' and see it return.

    Output from DFP side for SVDM discovery now looks:

    SVDM/4 [1] ff008041 340018d1 00000000 11000008
    [1119.966911 DONE]
    SVDM/2 [2] ff008042 ff010000
    [1119.970135 DONE]
    SVDM/2 [3] ff018043 00100081
    [1119.973437 DONE]
    SVDM/1 [4] ff018184

Change-Id: I47e5f4ec2d4a6a25f171177ead5ebc99409f80b6
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224191
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 22:44:36 +00:00
Alexandru M Stan
5d12e9b410 stm32f0: Pinky: Fix power leak caused by SPI at startup
Seems like we were setting outputs too early during boot, sometimes causing a
power leak. SPI should only turn on power levels more active than S3, not on the
S5->S3 transition.

BUG=chrome-os-partner:32824
BRANCH=None
TEST=Pinky powers on, Scope VCC33_PMUIO and VCC33_IO, note that they're smooth

Change-Id: I05c3622d124c2539222b883b895bc9092c5f0b12
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224508
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-21 22:44:26 +00:00
Alexandru M Stan
791d98d0b5 Pinky: Reoganize power on sequencing
This is the first step to fix a leak when powering up the system.

Some stuff should wait till after the rails are up.

The SPI timeout was removed because there's a simpler way to determine this:
SPI is only ready when the AP goes from S3->S0

BUG=chrome-os-partner:32824
BRANCH=None
TEST=Pinky powers on

Change-Id: Ia4281f54f7735d4efe2bc3e8ba1e462fccc51fd0
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222632
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-21 22:44:22 +00:00
Alec Berg
647ac36fda pd: do not respond to unknown SVDMs
bug fix: if we see an unknown SVDM, do not respond to it.

BUG=none
BRANCH=samus
TEST=test with third party that sends unknown SVDM

Change-Id: I3ef6c38be029d57bf3784ba832b7ae137f379049
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224179
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 20:04:02 +00:00
Alec Berg
5d76ffc62d pd: add data role to pd message header
Added data role bit to PD message header. The data role
is currently tied to power role: source = DFP, sink = UFP.

BUG=none
BRANCH=samus
TEST=tested with third part protocol analyzer

Change-Id: Ic56ea92899d20013aace108cee794d10c3780364
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224178
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 20:03:58 +00:00
Vic Yang
959dcf9854 stm32f: Add DMA interrupt handlers for channel 1 to 3
We already have interrupt handlers for channel 4 to 7. We need channel 3
for the new Ryu boards. Add the handlers for channel 1 to 3. Also,
instead of copy-pasting interrupt handlers, define a macro and declare
interrupt handlers with it.

BRANCH=None
BUG=chrome-os-partner:32660
TEST=make buildall
TEST=Check PD communication on the new Ryu board (with other CLs to
enable the new boards.)

Change-Id: I51d6bd16739f31a7efbeb4ec19bb91a1546fe21d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224175
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 00:44:39 +00:00
Vic Yang
d0d6befc3f Add stm32mon support for STM32F37xx
This is needed for the new Ryu boards.

BRANCH=none
BUG=chrome-os-partner:32660
TEST=Program STM32F373 chip.

Change-Id: Ib7a58826945090300b7e086e888c43c46fb499ab
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223893
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 00:44:29 +00:00
Vic Yang
017b4478b2 Fix flash bank size for STM32F373
The write protect granularity is 4-page instead of 2-page, so the bank
size should be 8K.

BRANCH=None
BUG=chrome-os-partner:32660
TEST=None

Change-Id: Ifb8be289cc0d05cbe538062ad860727c9a652943
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223891
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 00:44:22 +00:00
Vic Yang
eb939f655c Allow full Cortex-M4 instruction set for STM32F3xx
STM32F3xx has a Cortex-M4 core. Allow the full instruction set.

BRANCH=None
BUG=chrome-os-partner:32660
TEST=None

Change-Id: Ibb1dc0e36eed6b3042bde60cf2870a108176d919
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223890
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 00:44:14 +00:00
Vic Yang
46f0331711 pd: allow selection of Tx timer channel
So far, we always use channel 1 of the Tx timer and the configuration
code is hard coded. We need to support other channels for new Ryu
boards. Let's make this a configurable bit.

BRANCH=samus
BUG=chrome-os-partner:32660
TEST=make buildall
TEST=Plug in Zinger to Ryu and see 20V come up.

Change-Id: Id08d4eb0d6a5721d8a03672484d0892a0714383b
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223836
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-21 00:44:07 +00:00
Todd Broch
0e3497762c pd: alternate mode: Limit response to valid modes during discovery.
Previous reading of specification left some doubt about how SVDM
responder to 'discover modes' command communicated the number of valid
modes.  It is communicated via the 'object position' field in the VDM
header where: opos = modes + 1.

This change adds the mode count to the opos field and sends only that
amount of data back to the initiator.  Initiator stores that mode_cnt
so that it can correctly choose a mode when 'enter mode' phase occurs.

BRANCH=none
BUG=chrome-os-partner:30645
TEST=manual,
1. see SVDM responder to Discover modes only send supported number of
modes for SVID.
2. 'pe 0 dump' displays correct set of discovered modes on initiator.

Change-Id: I9b626dd6dd3e85e80b4f0596332300d74b1830ee
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223981
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-20 22:25:19 +00:00
Todd Broch
a4d51baf7c pd: alternate mode: simplify mode entry choice.
Original implementation was complicated by belief that we'd want PD
MCU to manage entry of multiple alternate modes.  This simply won't be
practical given the upper level system policies that would need to
weigh in on these decisions as well as the seemingly endless additions
to the alternate mode ecosystem.

Longer term we'll need to pass the generic alternate mode discovery
VDO info to the kernel/userland to implement remainder of policy.

However, for short term lets implement single mode entry instead.

BRANCH=none
BUG=chrome-os-partner:30645
TEST=manual, mode entry is successful on both ports.

Change-Id: Ia24f5ee4d59c13c62d68b30f8587b5e5fbdb2fa0
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223980
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-20 22:25:15 +00:00
Vincent Palatin
ece9501f06 Twinkie: update sniffer code
- Remove hardware double-buffering : it's complex to get right and does
  not provide any performance improvement.
- Increase buffer size x2 to decrease overflow frequency.
- Fix buffering and simplify code.

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

BRANCH=none
BUG=chrome-os-partner:28337
TEST=make BOARD=twinkie
do a long acquisition on a sample pattern from the function generator
and verify that no packet are missing and the waveform looks good.

Change-Id: I12a9e8370d3f238e8894f15ce0190e2e0fbc26d7
Reviewed-on: https://chromium-review.googlesource.com/223565
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-20 19:59:43 +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
Alec Berg
316f369f1c samus: add tap for battery
Adds double tap detection for samus. When user double taps
in S3 or lower to show battery state of charge on lightbar.

BUG=chrome-os-partner:29041
BRANCH=samus
TEST=make buildall
Tap the lid in S3 or lower.

Change-Id: Ic5f4709bdee2472cb7e91717318337b04bae1fc8
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221965
Reviewed-by: David Schneider <dnschneid@chromium.org>
2014-10-18 07:38:26 +00:00
Vic Yang
5d4846ee52 plankton: Implement cable flip
When the cable flip button is pressed, instead of only flipping on
Plankton side, we should also signal the port partner to flip. This is
done by sending a custom VDM. Upon receiving the flip VDM, the port
partner is responsible of flipping the DP/USB polarity.

Note that the "flip" here only affects the superspeed lanes. The CC
lines polarity is not changed. We need this for factory test automation,
and this "flip" function should only be used for testing purpose as it
clearly violates the USB PD spec and it only works on devices that
accept the custom flip VDM.

BRANCH=Samus
BUG=chrome-os-partner:32163
TEST=COnnect Plankton and Ryu. Press the button on Plankton and make
sure the polarity GPIOs on Ryu are negated.

Change-Id: I7ee5ea70067de4f422a7478623fe7fe8d3724372
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223325
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-18 07:38:22 +00:00
Duncan Laurie
18cc8ab5fd samus: Wait for VCORE_PGOOD before asserting SYS_PWROK
VCORE needs time to come up after PCH_PWROK is asserted and we
should be waiting for VCORE_PGOOD to be 1 before proceeding.

This also moves the 5ms delay for PCIe to be before SYS_PWROK
since that is where it is requried according to the power
sequence specification (rev 1.3 figure 2-4).

BUG=chrome-os-partner:33027
BRANCH=samus
TEST=build and boot on samus

Change-Id: I4bd969bdb56ecf14cc68754318452861b70f0539
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224033
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-18 01:39:08 +00:00
Sheng-Liang Song
1246bca1f8 samus: added sensor init retry logic
- Added sensor init retry logic to avoid intermitent i2c init error.
- Fixed shutdown hook to set data rate to 0 before changing sensor state.

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

Signed-off-by: Sheng-Liang Song <ssl@chromium.org>

Change-Id: I04ccf6547114e9f6c62756b38b8df27c2bc70de9
Reviewed-on: https://chromium-review.googlesource.com/223631
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Sheng-liang Song <ssl@chromium.org>
Tested-by: Sheng-liang Song <ssl@chromium.org>
2014-10-18 01:38:59 +00:00
Alec Berg
5a116de475 pd: if no SVIDS are returned, do not attempt discover modes
If no SVID is returned from discover SVIDS command, then don't
attempt to discover modes.

BUG=none
BRANCH=samus
TEST=test with device that does not return any SVIDS

Signed-off-by: Alec Berg <alecaberg@chromium.org>

Change-Id: I22201451cdc87b389734279d9294cf27d4740043
Reviewed-on: https://chromium-review.googlesource.com/223830
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
2014-10-18 01:38:52 +00:00
Vincent Palatin
05f37410ab pd: update the tPSTransition timeout
The timeout when we are not seeing a PS_READY message has been updated
to 450-550 ms in the PD specification, reflect that change in the code.

In case we are reaching this timeout, we need to send a HARD_RESET.

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

BRANCH=samus
BUG=none
TEST=plug a PD source with a 300ms delay before PS_READY.

Change-Id: I116a858c42a55f2036b3f2e13730cf29392a3420
Reviewed-on: https://chromium-review.googlesource.com/223785
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 05:52:53 +00:00
Vincent Palatin
24699aead9 pd: NACK unsupported VDM requests
When a VDM request is not supported, return a proper NAK message rather
than trying to execute a NULL pointer.

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

BRANCH=samus
BUG=none
TEST=plug a power source sending discovery VDM to Samus.

Change-Id: Iba60fd29d950c99fd981f9e8ecf3e911409147d5
Reviewed-on: https://chromium-review.googlesource.com/223780
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 05:52:45 +00:00
Vincent Palatin
fd709edf12 pd: fix VDM commands numbering
In structured VDMs, the ACK command is b01 and the NAK command is b10,
update the defines accordingly.

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

BRANCH=samus
BUG=none
TEST=interoperability test with another power source.

Change-Id: I8050ae262dc5ab538d973f802111c2874358ea37
Reviewed-on: https://chromium-review.googlesource.com/223725
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 05:52:40 +00:00
Vincent Palatin
66d75af877 pd: reset the message ID on connection
The message ID counter in our message needs to be reset to 0 on a new
connection.

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

BRANCH=samus
BUG=none
TEST=dump the sequence with the USB PD protocol analyzer.

Change-Id: I1bddddf4075fba646b1e8c7886059c4a11e5fec9
Reviewed-on: https://chromium-review.googlesource.com/223759
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 03:25:20 +00:00
Alec Berg
0a44f24035 zinger: enable hibernate
Enable hibernate on zinger for DVT. Note: this may break
some EVT zingers.

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

Hibernate tested in CL:220837

Change-Id: I65f4776d27ad88beee101fb00d0b6221ba272a26
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223738
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 01:14:10 +00:00
Vincent Palatin
e0f5bca27d pd: update standard revision field
USB Power Delivery standard for the BMC variant was finally rev'ed to
2.0 : update the revision field in the PD packets.

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

BRANCH=samus
BUG=none
TEST=dump packet with the PD protocol analyzer

Change-Id: I218861d74da61da388bed10e070c9faf6f81fd00
Reviewed-on: https://chromium-review.googlesource.com/223757
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-10-17 01:14:03 +00:00
Todd Broch
9953322daf hoho: Disable spi master by default.
BRANCH=none
BUG=none
TEST=manual, HDMI tranceiver functions correctly at power-on

Change-Id: I348f22250da7290809fb39319283ec9d4bc4fcc7
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223614
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-16 21:18:15 +00:00
Todd Broch
97c527fa45 hoho: correct CONFIG1 GPIO direction.
BRANCH=none
BUG=none
TEST=manual, compile boots, can read GPIO.

Change-Id: If68d56cc4fcafd3872f7df16a5578542e34d5093
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223613
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-16 21:18:11 +00:00
Vic Yang
f8fd63f135 Fix incorrect valid and writable flash flags
The valid and writable flags the EC sends back to the AP are incorrect.
They are a little bit different on differnt chips, so let's move it to
flash physical layer. This is not any causing problem, but we should fix
this.

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

Change-Id: Ibcda5ae770f5ea02cde094490997a5bc447df88f
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222661
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 23:56:27 +00:00
Todd Broch
847eb1ec44 samus_pd: Initial DFP_D HPD GPIOs.
USB PD spec now calls for HPD signal to be managed across the USB PD
protocal.  In preparation this CL makes the HPD GPIOs outputs and
initially low.

This should NOT effect older revs of the design as GPIOs were unused
(had unstuffed option for external XTAL).

BRANCH=samus
BUG=chrome-os-partner:30645
TEST=compiles & runs.  With reworked board can manually trigger HPD.

Change-Id: I0a64c1daf8d8c866f5de237c3daf4be028eecd63
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223462
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 23:56:01 +00:00
Vic Yang
82915c2502 Write protect support for STM32F0
On STM32F0, we cannot work around the hard fault triggered when trying
to protect the whole flash. Therefore, we need to go with the
ALL_AT_BOOT approach. When write protect is enabled, instead of setting
ALL_NOW flag to immediately lock down the entire flash, we need to set
ALL_AT_BOOT and then reboot to have the protection take effect.

BUG=chrome-os-partner:32745
TEST=Along with the next CL. On Ryu:
  1. Enable HW WP. Check the output of 'ectool flashprotect' and see
     correct flags.
  2. 'flashrom -p ec --wp-range 0 0x10000'. Check RO_AT_BOOT is set.
  3. Reboot EC and check RO_NOW is enabled.
  4. Boot the system and check ALL_NOW is set.
  5. Update BIOS and reboot. Check software sync updates EC-RW.
  6. 'flashrom -p ec --wp-disable' and check it fails.
  7. Disable HW WP and reboot EC. Check RO_NOW and ALL_NOW are cleared.
  8. 'flashrom -p ec --wp-disable' and check RO_AT_BOOT is cleared.
TEST=Enable/disable WP on Spring. Check RO_AT_BOOT/ALL_NOW can be set
properly.
BRANCH=samus

Change-Id: I1c7c4f98f2535f1c8a1c7daaa88d47412d015977
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222622
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 23:55:55 +00:00
Anton Staaf
5ff320f66e discovery-stm32f072: fix USB version string
The change to a dynamic version string was lost
in a rebase.  This fixes it.

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

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

Change-Id: I388dcf7fc67b02dc0ab350b1cbb08f2e5d0c7000
Reviewed-on: https://chromium-review.googlesource.com/223389
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-10-15 23:55:49 +00:00
Alec Berg
27d60bb83e zinger: fix double ADC interrupt bug
The ADC interrupt does not clear the NVIC pending register. This
can cause the interrupt to fire more than once for a given
interrupt.

BUG=none
BRANCH=samus
TEST=Send hard reset from samus to zinger using "pd 1 hard" on
PD MCU console. This causes zinger to cut its output voltage
and go into voltage discharging mode. When voltage discharge is
complete, we get an ADC interrupt and switch back to current
monitoring. Before this CL, sometimes (1 out of 20) times the
ADC interrupt will fire twice, causing an OCP to be detected.
With this CL, we never see the double fire.

Change-Id: I91397a04773d04e263bc80a698c8799342b80a2e
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223381
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 20:49:40 +00:00
Vic Yang
4a9cabc3f9 Factor out common flash code for STM32F and STM32F0
This is a preparatory work for the following change for write protection
support on STM32F0.

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

Change-Id: Ic4deea06e26c4a6ac024a5388e1a5783b40e9876
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222660
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 20:49:35 +00:00
Shawn Nematbakhsh
b8f73a451d charge_manager: Add module for managing battery charge limits
charge_manager is intended to manage charge limits from various tasks
(typically PD charge tasks and USB / BC 1.2 charge tasks). These tasks
can update the charge limit of a port by calling charge_manager_update
(thread-safe function). If the charge limit has changed,
charge_manager_refresh will be queued as a deferred task, which will
select the "best" charge port and set the proper charge limit.

In order to use charge_manager, a board needs to do the following:

1. Declare PD_PORT_COUNT in usb_pd_config.h
2. Implement board_set_charge_limit
3. Implement board_set_active_charge_port
4. Call charge_manager_update whenever the available charge on a port changes.

BUG=chrome-os-partner:31361
TEST=Manual on samus_pd, with subsequent commit. Insert and remove
various chargers, check console to verify PD charger always has priority
and correct current limit is set based upon 'best' charger.
BRANCH=samus

Change-Id: Iede120b69e0b46ed329bcf9b7e07c39ba5e9f77b
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222723
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-15 18:22:44 +00:00
Eric Caruso
bcc5057ad3 lightbar: interpreter additions to encode other patterns
Makes a significant encoding change to existing opcodes and
adds several opcodes to allow for encoding the more complicated
patterns that we have on the lightbar (S0, etc.) as well as
condense the ones we technically could encode but couldn't
fit in the 192-byte footprint allotted to us (KONAMI).

We need this to remove sequences from the EC code.

BUG=chrome-os-partner:32203
BRANCH=ToT
TEST=run test programs on hardware and lightbar simulator

Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Change-Id: I12fe908d3a43a924aa39f24ad66adbe53f7f38e1
Reviewed-on: https://chromium-review.googlesource.com/222949
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-15 18:22:37 +00:00
Bill Richardson
8fc80e86e4 lightbar: bring the TAP sequence in gradually
With only four LED segments, it's confusing to indicate a power
percentage by dimming the top segment unless you can see the
indicator smoothly ramping up from all-off. This does that.
Kind of pretty, if I say so myself.

BUG=chrome-os-partner:29041
BRANCH=ToT, Samus
TEST=make buildall

Run "ectool lightbar demo on", then press the T key to invoke the
pattern and the arrow keys to fake the charge state.

Change-Id: Ib6a56aea56078b8c1fc9edddda469d7f41735ff7
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223300
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-15 18:22:33 +00:00
Vic Yang
9a2afe9f78 ryu: plankton: Increase PD task stack size
The PD task is using more space in the stack and I'm seeing frequent
stack overflow on Plankton. On Samus, we already increased the stack
size. Let's also increase this on Ryu and Plankton.

BUG=None
TEST=make buildall
BRANCH=None

Change-Id: I468985303b7fd38455dd1fed9db54544581c49cf
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223368
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 18:22:15 +00:00
Alec Berg
c1e908fcac samus: display battery status on lightbar on AC change
Display battery percentage on the lightbar whenever AC status
changes.

BUG=chrome-os-partner:32894
BRANCH=samus
TEST=Plug and unplug AC in S0 and in G3 and make sure that lightbar
displays battery percentage each time

Change-Id: I281c9242d185da06b0c778de12e4f6340779a840
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223362
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-15 18:22:10 +00:00
Todd Broch
fca5deab2f dingdong: Add USB Billboard class device.
BRANCH=none
BUG=chrome-os-partner:31193
TEST=manual
Plug dingdong into samus and see:
    # lsusb -d 18d1:5011 -v

    Bus 001 Device 013: ID 18d1:5011 Google Inc.
    Device Descriptor:
      bLength                18
      bDescriptorType         1
      bcdUSB               2.01
      bDeviceClass           17
      bDeviceSubClass         0
      bDeviceProtocol         0
      bMaxPacketSize0        64
      idVendor           0x18d1 Google Inc.
      idProduct          0x5011
      bcdDevice            2.00
      iManufacturer           1 Google Inc.
      iProduct                2 Dingdong
      iSerial                 0
      bNumConfigurations      1
      Configuration Descriptor:
	bLength                 9
	bDescriptorType         2
	wTotalLength           10
	bNumInterfaces          0
	bConfigurationValue     1
	iConfiguration          3 dingdong_v1.1.2338-562101b
	bmAttributes         0x80
	  (Bus Powered)
	MaxPower              500mA
    Binary Object Store Descriptor:
      bLength                 5
      bDescriptorType        15
      wTotalLength           73
      bNumDeviceCaps          2
    FIXME: alloc bigger buffer for device capability descriptors
    Device Status:     0x0000
      (Bus Powered)

Change-Id: Icfc2e7eab9c88d6c8a05a33782213717e64ddcf0
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223003
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 00:09:56 +00:00
Alec Berg
ce6cb6effa pd: implement source recovery time after hard reset
Implemented source recovery time following a hard reset. According
to the spec:

After a hard reset, the source must dissipate output voltage
to vSafe5V. After establishing the safe voltage condition on VBUS,
the power supply shall wait tSrcRecover before powering VBUS to
vSafe5V.

BUG=none
BRANCH=samus
TEST=plug in a type-c to type-a adapter to samus. then issue a hard
reset from the console and verify that it takes nearly a second before
samus re-enables vbus.

Change-Id: Id21eb7cf03759b7ecd64ad11c3c57e66cf35370a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222935
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 00:09:55 +00:00
Alec Berg
2e1c48823c pd: implement sink hard reset counter
For a sink, when there is no source cap packet within SinkWaitCapTimer,
then it sends a hard reset. Once the hard reset has been retried
nHardResetCount times then it shall be assumed that the remote
device is non-responsive, and we stop sending the hard reset.

BUG=none
BRANCH=samus
TEST=Tested with a non-PD charger. When plugged in, we see two hard
resets and then it stops

VBUS 1, 1!
C1 st3
C1 st14
C1 st2
HARD RESET!
[494.906344 HC 0x100]
C1 st3
C1 st14
C1 st2
HARD RESET!
[495.668624 HC 0x100]
C1 st3
> adc
  C0_CC1_PD = 20
  C1_CC1_PD = 1783
  C0_CC2_PD = 36
  C1_CC2_PD = 21
  V_BOOSTIN = 5329
>

Change-Id: Ib0fc49642aba754015b8055cf1971577b48ac058
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222853
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 00:09:55 +00:00
Alec Berg
8b0fe91407 pd: samus: ryu: add back in Vconn support correctly
Add support for enabling Vconn on Raiden ports by defining
CONFIG_USBC_VCONN. This is enabled by default for ryu, samus,
and fruitpie.

BUG=chrome-os-partner:30445
BRANCH=samus
TEST=Load onto samus. Make sure we can still charge from zinger.
Plug in type-A to type-C adapter with pulldown and see that samus
becomes power source. Do a gpioget and verify that only one VCONN
GPIO is enabled (low), and the VCONN that is enabled is opposite of
the polarity queried by pd 1 state. Try both ports, both polarities
and make sure the correct VCONN gpio is enabled.

Change-Id: Icea4c18b9c813cf7e8e21fd4f455bbd5fb4dbc91
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222850
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-15 00:09:32 +00:00
Todd Broch
c222d7b700 pd: hoho: de-assert PD_SBU_ENABLE at boot.
Per alternate mode this GPIO should not be enabled until alternate
mode has been successfully entered.

BRANCH=none
BUG=chrome-os-partner:31192
TEST=manual, compile & boot on hoho gpioget PD_SBU_ENABLE = 0

Change-Id: Ide2a47851f30812b289221e302a930134a58a8a0
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/223159
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-14 23:59:19 +00:00