Commit Graph

1405 Commits

Author SHA1 Message Date
Shawn Nematbakhsh
7eaa290c35 usb_pd_protocol: Add support for charge_manager and voltage reporting
Integrate charge_manager and include several API changes designed
for reporting voltage.

1. Make pd_choose_voltage set the chosen voltage for use by caller.
2. Add voltage parameter to pd_set_input_current.
3. Add pd_get_role to grab the sync / source state of a port.
4. Add charge manager PD + type C port initialization to the pd
   state machine.

BUG=chrome-os-partner:32003
TEST=Manual on samus. Insert Apple charger, verify charge limit is
selected appropriately. Insert PD charger, verify that charge port
switches to PD port. Remove + reinsert chargers, verify that port /
limit is selected appropriately. Remove battery, insert power source, verify
that our power source port never becomes disabled.
BRANCH=samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Idf3198c71d2ddf1e401e766fc82a4b7a02aed068
Reviewed-on: https://chromium-review.googlesource.com/223758
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-22 02:23:35 +00:00
Vic Yang
7198d0303c ryu: enable lightbar on P2 boards
Ryu uses the same LEDs as Samus, so let's use the same brightness values
for them. Also, increase the stack size for console task so that
'lightbar' command doesn't cause stack overflow.

BRANCH=None
BUG=chrome-os-partner:32203
TEST=See lightbar in action on Ryu.

Change-Id: I89b61f6df2751c9dd6b40f9e374f01e1b0dfd504
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224426
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-22 00:30:46 +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
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
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
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
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
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
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
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
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
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
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
Vincent Palatin
46102d3b4e usb: export firmware version
Remove the meaningless version string in iSerialNumber, which was incorrect
since this string should be unique to a device if it exists.

Export the firmware version string as the configuration string, so it's
traceable to a given firmware build/sources.

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

BRANCH=samus
BUG=none
TEST=make buildall
from a workstation, do "sudo lsusb -v" and see the full version string
exported as the configuration name.

Change-Id: I557df2936421e2926ac0fc0003888370cec3e201
Reviewed-on: https://chromium-review.googlesource.com/222877
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-11 07:29:15 +00:00
Todd Broch
8a6c72022f pd: Enable alternate mode support for DP.
Change effects:
1. samus_pd: Acts as initiator of SVDM discovery once its reaches source
             ready and upon identifying UFP with display port
	     alternate mode enters that mode.
2. hoho: Acts as responder for SVDM discovery providing its identity,
         svids and svid capabilities which are display port only.  If
	 asked to enter display port alternate mode it does.
3. fruitpie: Acts a initiator with mock display port mode.

BRANCH=none
BUG=chrome-os-partner:30645
TEST=manual,
Plug hoho into samus_pd
- see dpout
- from console
  > typec 0
  Port C0: CC1 451 mV  CC2 111 mV (polarity:CC1)
  Superspeed DP1

Change-Id: I1a76767353a69baeceffa3e79c37dcea77b8337d
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221354
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-11 02:22:28 +00:00
Alec Berg
358aeb2877 Revert "pd: samus: ryu: add Vconn support and enable for samus and ryu"
This reverts commit 61dc089e23.

Samus polarity is wrong on VCONN due to naming mismatch. Will fix in a later CL, but should revert now to avoid problems.

Change-Id: Icabcf2967e92caec94840df7e66a6658c7cde007
Reviewed-on: https://chromium-review.googlesource.com/222717
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-10 06:54:16 +00:00
Shawn Nematbakhsh
fd7846fe09 usb_pd: Add port parameter to pd_set_input_current_limit
Some platforms may need to take different actions depending on which
port is requesting a limit. Add a new port parameter to the
pd_set_input_current_limit API to accomodate this.

BUG=chrome-os-partner:32003
TEST=Manual on samus_pd. Verify zinger charges battery.
BRANCH=samus

Change-Id: I1578252c751b3a80b4da6ca68e2a958934283cbf
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222621
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-10 02:43:39 +00:00
Eric Caruso
6713fa2d38 lightbar: Rename structs and macros for kernel cros_ec_commands
This prepends EC_ a macro exposed in ec_commands.h, moves a
macro into lbcc that is not used elsewhere, and changes lb_program
structs to lightbar_program.

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

Change-Id: I481562da72d91f846c64cf9af40338027641462c
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222406
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-09 23:29:42 +00:00
Vic Yang
e3e7999164 Don't hibernate on low battery if hiberante is not supported
If CONFIG_HIBERNATE is explicitly undefined for a board, the EC
shouldn't hibernate when the battery is running low. Otherwise, the EC
reboots because of the lack of hibernate support, and this actually
burns more power.

BUG=chrome-os-partner:32727, chrome-os-partner:32779
TEST=Drain the battery to 2% and verify the EC is behaving.
BRANCH=None

Change-Id: I2f9f5fd8fb4b5be4d8da113da4ef26c062869a07
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222615
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-09 23:29:34 +00:00
Alec Berg
61dc089e23 pd: samus: ryu: add Vconn support and enable for samus and ryu
Add support for enabling USB type-C Vconn by defining CONFIG_USBC_VCONN.
Enable Vconn support for samus, ryu, and fruitpie.

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

Change-Id: Ibe247286c96fd5a8fa12c88a4e3a5fea02997134
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222284
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-09 23:29:24 +00:00
Todd Broch
a194bede19 pd: VDM Alternate mode support.
Successfully communicate SVDM for discovery (identity, svids, modes)
and enter mode.

Still need to:
- Add same functionality on when power role is sink too.
- determine what connected events would require exit mode.
- do proper cleanup on disconnect.
- implement real display port 'enter' mode for samus_pd
- test & cleanup

Additionally the USB Billboard class functionality needs to be added
but will likely do that in a separate CL.

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

From fruitpie,
    [Image: RO, fruitpie_v1.1.2263-d79140d-dirty 2014-09-29 17:44:15 tbroch@brisket.mtv.corp.google.com]
    [0.000383 Inits done]
    C0 st2
    Console is enabled; type HELP for help.
    > [0.250551 USB PD initialized]
    pd dualrole source
    C0 st8
    > [8.366335 PD TMOUT RX 1/1]
    RX ERR (-1)
    [8.478308 PD TMOUT RX 1/1]
    RX ERR (-1)
    [8.590280 PD TMOUT RX 1/1]
    RX ERR (-1)
    C0 st9
    Switch to 5000 V 3000 mA (for 3000/3000 mA)
    C0 st10
    C0 st11
    C0 st12
    8.867593] SVDM/4 [1] ff008081 340018d1 00000000 17000008
    8.867906] DONE
    8.871006] SVDM/2 [2] ff008082 ff010000
    8.871224] DONE
    8.875092] SVDM/7 [3] ff018083 00100081 00000000 00000000 00000000 00000000 00000000
    Entering mode w/ vdo = 00100081
    8.875492] DONE
    8.878435] SVDM/1 [4] ff018144
    8.878612] DONE

    > pe 0 dump
    SVID[0]: ff01 [0] 00100081 [1] 00000000 [2] 00000000 [3] 00000000 [4] 00000000 [5] 00000000
    MODE[0]: svid:ff01 mode:1 caps:00100081

From hoho,
    [Image: RO, hoho_v1.1.2263-d79140d-dirty 2014-09-29 17:54:59 tbroch@brisket.mtv.corp.google.com]
    [0.000375 Inits done]
    C0 st2
    Console is enabled; type HELP for help.
    > [0.250542 USB PD initialized]
    C0 st3
    [0.264637 PD TMOUT RX 1/1]
    RX ERR (-1)
    Request [1] 5V 3000mA
    C0 st4
    C0 st5
    C0 st6
    0.487451] SVDM/1 [1] ff008001
    0.487628] DONE
    0.491190] SVDM/1 [2] ff008002
    0.491346] DONE
    0.494510] SVDM/1 [3] ff018003
    0.494667] DONE
    0.498777] SVDM/1 [4] ff018104
    0.498934] DONE

Change-Id: I5e2b7802c66b8aaad97e5120dca7a02820086bc1
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219513
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-09 20:44:43 +00:00
Shawn Nematbakhsh
0938563284 zinger: Remove references to SHA1 hash
The PD protocol no longer uses a SHA1 RW hash. Instead, it uses the
first 20 bytes of the SHA-256 hash. Update constants and comments
accordingly.

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

Change-Id: Ice74b841dbd1d81205c1ef0079a5e18fca2153b6
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222446
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-09 20:44:39 +00:00
Sheng-Liang Song
ac261c00c1 samus: support sensor at different power state.
Design Goals:
1. Every time the AP boots, the same default sensor settings are configured.
2. If the AP goes to suspend (S3) and wakes back up (S0),
   then the AP sensor settings will be restored.
3. In S3 and in S5, only sample specific sensors that are needed.

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

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

Change-Id: I553c53e63ecfcb39d5e649a7189aa6ea02589471
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220371
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-08 02:51:17 +00:00
Sheng-Liang Song
ac1c82a35b samus: Fixed a bug in host_sensor_id_to_motion_sensor
BUG=chrome-os-partner:32368
BRANCH=ToT
TEST=Verified on Samus.

cd /sys/bus/iio/devices/iio:device0
cat *peak_scale

Change-Id: I2b0606e55bfa5e498255c6c42240ee3f9236e4f1
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220991
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-08 02:51:00 +00:00
Vic Yang
91cfdd0dac Remove PULSE and TEST sequences from lightbar module
PULSE and TEST sequences are not used anywhere. Remove them to save
flash space. Also, fix msleep(MSEC) calls in the unit test; it's
essentially usleep(SECOND) written in an incorrect way.

BUG=chrome-os-partner:32203
TEST=make buildall
BRANCH=None

Change-Id: I61ba897df632538eb89364a4c913d5fee87f3864
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220711
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-08 02:50:54 +00:00
Mohammed Habibulla
5c8da35f87 ectool: hostcmd support to set fans auto control individually
ectool autofanctrl 1 - set auto fan control for fan 1

BUG=chrome-os-partner:23803
TEST=Tested the above EC command on Auron
BRANCH=none

Change-Id: Idcd3690ad98d7965420f26f7cc445207fe73704d
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221816
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-07 20:58:33 +00:00
Alec Berg
7b305b752b zinger: samus_pd: increment zinger hardware id minor revision
Add a minor revision to the PD device hardware ID field in the info
custom VDM and set increment this minor ID from 0 to 1 for zinger.
This differentiates zingers for the auto-update payload, so we can
update only those with a specific major and minor ID version.

BUG=none
BRANCH=samus
TEST=load onto samus and zinger. when connect zinger, see on PD
console: Dev:0x0401 SW:2289 RW:0, which shows the appropriate
device ID.

Change-Id: I482ee2d850332b608cdd81537f68d4dc509bfc1a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221320
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-07 05:53:26 +00:00
Alec Berg
d5d2a71c96 pd: zinger: move sending info VDM from UFP to DFP
Changed sending of info VDM from the UFP side in SNK_DISCONNECTED
to the DFP side in SRC_READY to match the PD spec. Only the DFP
is supposed to send VDMs, and by default the power source is the
DFP. This affects simple DFPs such as power adapters, they must
initiate the info VDM once a power contract has been negotiated.

BUG=none
BRANCH=samus
TEST=load onto samus_pd and zinger and make sure that when you
attached zinger to samus, samus receives info VDM and prints out
something like:
VDM/7 [11] 18d1000b
Dev:1 SW:2280 RW:0

Change-Id: I16ceac31939fdc1c74be7323e628dd8706e1283b
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221174
Reviewed-by: Todd Broch <tbroch@chromium.org>
2014-10-07 05:53:13 +00:00
Vincent Palatin
c817472c07 Update Zinger flashing process
Convert the Zinger flash update commands to the new RSA signature
mechanism.

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

BRANCH=samus
BUG=chrome-os-partner:28336
TEST=from the workstation:
./util/flash_pd.py -m 1 build/zinger/ec.RW.bin
from Samus command-line :
ectool --name=cros_pd flashpd 0 1 ec.RW.bin

Change-Id: Ie8cd7f644ec94e461c5775a4dbbcd408782c72e1
Reviewed-on: https://chromium-review.googlesource.com/221560
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2014-10-07 03:37:48 +00:00
Mohammed Habibulla
876b0f0bdc ectool: Add hostcmd support to set fan duty cycle for each fan separately
ectool fanduty <percent>	- set all fans to <percent> duty cycle
ectool fanduty <fan> <percent>	- set <fan> to <percent> duty cycle

BUG=chrome-os-partner:23803
TEST=Tested the above EC commands on Auron
BRANCH=none

Change-Id: I06ca1552bd8f3412f6e90245da302c9f86ab6103
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221505
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-07 01:29:36 +00:00
Vic Yang
f0dc012cf7 Add back unit test for usb_pd"
This is mostly the same as previous commits, but with increased delay.
Previously, we have short delays (e.g. 3ms) which is too short and may
cause instability.

Now that we have slowed down the time when running unit tests and
increased the delay, this shouldn't cause problems anymore.

BUG=chrome-os-partner:31200
TEST=Repeatedly run multiple unit tests in parallel.
BRANCH=Samus

Change-Id: Ib55e3adc5fd27a8e233996b4799dab3cefd62318
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220734
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-04 21:08:48 +00:00
Eric Caruso
15eced0374 lightbar: refactoring RAMP_ONCE and CYCLE_ONCE
These opcodes basically do the same thing, but with minor
changes. We can factor this out to avoid code duplication.
Saves 90 bytes.

BUG=None
BRANCH=ToT
TEST=Inspected programs that use RAMP_ONCE and CYCLE_ONCE with
  both nonzero and zero ramp delay.

Change-Id: I0105dbd4fc0af86beea993dbef85a0e0f01a0a90
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220604
Reviewed-by: Vic Yang <victoryang@chromium.org>
2014-10-04 21:08:45 +00:00
Mohammed Habibulla
7b1e58cc43 ectool: Add host command support to set fan RPM for each fan separately
First case is for legacy support
ectool pwmsetfanrpm <targetrpm>		- set all fans to <targetrpm>
ectool pwmsetfanrpm <fan> <targetrpm>	- set <fan> to <targetrpm>

BUG=chrome-os-partner:23803
TEST=Tested the above EC commands on Auron
BRANCH=none
CQ-DEPEND=CL:220960

Change-Id: I8f447f53289abaa9c5cc1285f9f0921328fbf32c
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221291
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-03 22:27:03 +00:00
Alec Berg
ba624e7241 zinger: add hibernate if disconnected for 60s
Automatically go into hibernate (standby mode) if not powering
anything for 60 seconds. Will wake up when it is plugged into
something (senses pull-down on CC line).

BUG=chrome-os-partner:28335
BRANCH=samus
TEST=load onto zinger. if disconnected for 60s, see hibernate
print on zinger console. when connected to a device, verified
it boots again.

Change-Id: I2564c6192395bb5e4f6d7586c2725f13a4581049
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220837
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-10-03 04:29:57 +00:00
Vincent Palatin
beaddbf1a3 zinger: check RW firmware signature
The Zinger RW is now signed with 2048-bit RSA key (using SHA-256 as
digest).
This CL implements the verification mechanism.

note: the RSA key used for signing must be provided as a .pem file.
The path to .pem file must be provided in the PEM environment variable.
By default, it's using the dev key stored in zinger_dev_key.pem.

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

BRANCH=samus
BUG=chrome-os-partner:28336
TEST=on Zinger, run with properly signed RW firmware and corrupted
firmware and check the serial traces.

Change-Id: Ia58482458904a3ed72d6b0e95996cae86a0ead83
Reviewed-on: https://chromium-review.googlesource.com/220178
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-02 23:18:25 +00:00
Vic Yang
cac05af1aa Remove 'param' option in lightbar console command
We can use ectool to set/get lightbar parameters and don't need a huge
console command option for this. Let's get rid of it to save flash
space.

BUG=chrome-os-partner:32203
TEST=make buildall
BRANCH=None

Change-Id: Ifbc122c887a36accaf3f8dce43f091d7d1333550
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220710
2014-10-02 18:24:43 +00:00
Eric Caruso
d3ebcb18ca lightbar: hide program command over console
This doesn't make any sense to expose to the console, so we can
save some logic and string literals by only compiling it for the
simulator.

BUG=chrome-os-partner:32203
BRANCH=ToT
TEST=Checked console does not support command. ectool still
  works and the lightbar simulator still has the command.

Change-Id: Ib216c7c11fd3d0d2d444ef7fc0dda4e451103219
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220834
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-01 22:42:30 +00:00
Vic Yang
813ac32380 pd: Translate host command parameters with lookup tables
We have giant switch-case just for translating USB PD host command
parameters. Let's change this to lookup tables so that it's clearer and
also reduces code size.

BUG=chrome-os-partner:32203
TEST=make buildall
BRANCH=None

Change-Id: Ieef0e989bd0faa95e261748a73250c53f0942dad
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220511
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-01 10:19:52 +00:00
Eric Caruso
71df668d46 lightbar: Removing unused space in ramp table
We don't need the upper two bytes of any elements in the ramp table,
since none of them are big enough to flow into them. This saves us
another 60-70 bytes.

BUG=None
BRANCH=ToT
TEST=Manual, visual inspection

Change-Id: Id9d03b8f63e61172c5cc6b36b010582957c7bb22
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220595
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-01 06:53:25 +00:00
Eric Caruso
fcdbcfe5e0 lightbar: simplify JUMP, SET_DELAY_TIME opcode execution
We do some unnecessary work here. All we are trying to do is decode,
and decode already does all the error checking we want. Saves
20 bytes.

BUG=None
BRANCH=ToT
TEST=Run programs with JUMP and SET_DELAY_TIME opcodes in simulator
  and on hardware.

Change-Id: Ia55f9010da50fe748bda565e069359162cc92b4f
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220630
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-10-01 06:53:22 +00:00