Commit Graph

2302 Commits

Author SHA1 Message Date
Randall Spangler
57ed31bcc5 cr50: pass params to vendor commands as struct
This makes it easier to add params or flags for vendor commands
without changing all of the command handlers.  It also reduces code
size by 56 bytes.

For now, existing command handlers continue to use
DECLARE_VENDOR_COMMAND().  Added DECLARE_VENDOR_COMMAND_P() for
handlers which take the params struct directly.  The CCD command will
be the first user of that, since it will have different rules for
'open' based on where the command comes from.

No change to existing command behavior.

BUG=b:79983505
BRANCH=cr50
TEST=gsctool -I still works

Change-Id: I7ed288a9c45e381162e246b50ae88cf76e67490d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1069538
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-23 20:35:12 -07:00
Randall Spangler
f07e300fe4 cr50: tpm_alt_extension() specifies command origin is USB
Previously, calls to tpm_alt_extension() were treated as if they came
from the AP via the TPM interface, even though they actually
originated from the cr50 console, which is accessible via the USB
interface.

This affects the following console commands:

spi_hash - was already allowed as both a safe console command and via
the USB vendor command interface.  No change.

rma_auth - was allowed as a safe console command, but not via the USB
vendor command interface.  Now allowed from both.  No change in
security, since anyone could already do it via the console.
Unfortunately, getting a challenge fails because commands issued via
the USB vendor command interface have a maximum payload of 32 bytes
and the challenge is bigger than that; that's tracked in b:80098603.

ccd - was already allowed as a safe console command.  This directly
called ccd_command_wrapper() for lock, open, and password subcommands.
It made an extra check for password set for the unlock subcommand.
Moved the unlock check to the vendor command handler.  Also changed
the order of checks so that FWMP disabling unlock and open supersedes
an existing password; this matches go/ccd-open-simple.  (That has no
effect on existing systems, because CCD is disabled at a higher
level.)

Reduces code size by 8 bytes.

BUG=b:79983505
BRANCH=cr50
TEST=manual, on a CR50_DEV=1 build
	Compile with DEBUG_EXTENSION defined to print extra debug output
	'ccd lock' now shows as coming from USB
	'ccd unlock' fails because no password is set
	'ccd unlock' and 'ccd open' fail if FWMP disallows unlock
	'rma_auth' prints a challenge
	'gsctool -t -r' prints a challenge from AP root shell
	'gsctool -r 12345678' returns error 6 (incorrect challenge), rather
	     than error 127 (no such command).
	'gsctool -I' works from the host
	'gsctool -t -I' still works from AP root shell

Change-Id: I2cd1027f5135b9c336df97ee4b1b1a15354728b4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1068102
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-23 20:35:12 -07:00
Jett Rink
535c0bf4fa cleanup: remove transition code for LPC/ESPI cleanup
BRANCH=none
BUG=chromium:818804
TEST=full stack works with lpc and espi

Change-Id: I371e993bc97e7e87fb1075cf3dba82082402c0cf
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1067504
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-23 09:13:50 -07:00
Jett Rink
4d23d995c3 espi: rename remaining eSPI options
Change prefix from CONFIG_ESPI to CONFIG_HOSTCMD_ESPI for consistency.

BRANCH=none
BUG=chromium:818804
TEST=Full stack builds and works on yorp (espi) and grunt (lpc)

Change-Id: I8b6e7eea515d14a0ba9030647cec738d95aea587
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1067513
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-23 09:13:49 -07:00
Randall Spangler
9df26ce0f2 cr50: Refactor tracking vendor command origin
Added flags parameter to extension_route_command().  The caller now
specifies whether the command comes from the USB interface or the AP.

Moved USB-specific shuffling of response to embed result code into
usb_upgrade.c, so extension_route_command() can be more generic.

No change to permissions/behavior for existing commands.
ccd_command_wrapper() still sends vendor commands as if they come from
the AP.  That's fixed in the next CL.

Reduces code size by 128 bytes

BUG=b:79983505
BRANCH=cr50
TEST=manual
	Build with DEBUG_EXTENSION defined, to turn on printing each command
	'ccd lock' comes from AP and works
	From host, 'gscutil -I' comes from USB and fails
	From AP, 'gscutil -t -I' comes from AP and works

Change-Id: I7136bb54073de9c5951a174c308151b1871c56f3
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1068101
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-22 21:57:12 -07:00
Jett Rink
b34a5973cd cleanup: add comment to CONFIG_BATTERY_REVIVE_DISCONNECT
When you define CONFIG_BATTERY_REVIVE_DISCONNECT you also need to define
battery_get_disconnected_state method()

BRANCH=none
BUG=none
TEST=none

Change-Id: I0ab42c722e2511cbfa50cab2142baec0906d8263
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1055819
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-05-22 21:57:03 -07:00
Jett Rink
8f6fff795b lpc/espi: convert remaning CONFIG_LPC to CONFIG_HOSTCMD_X86
We have converted all LPC-only configs to HOSTCMD_LPC so the remaining
CONFIG_LPC defines represent the common case.

BRANCH=none
BUG=chromium:818804
TEST=Full stack builds and works on yorp (espi) and grunt (lpc)

Change-Id: Iba9a48f2cab12fadd0d9ab8eab0d5d5476eab238
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1067503
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-22 21:56:40 -07:00
Jett Rink
dbfa3cf2dc lpc/espi: define new targeted config options
Introduce CONFIG_HOSTCMD_LPC and CONFIG_HOSTCMD_ESPI which will replace
CONFIG_LPC and CONFIG_ESPI. Today the CONFIG_LPC option guards both
common code to eSPI and LPC and LPC-only code. Going forward
CONFIG_HOSTCMD_LPC will guard only LPC code, and a new option
CONFIG_HOSTCMD_X86 will guard common code to both LPC and eSPI.

I am leaving the CONFIG_LPC and CONFIG_ESPI defines in this CL so each
CL in the stack compiles.

BRANCH=none
BUG=chromium:818804
TEST=Full stack builds and works on yorp (espi) and grunt (lpc)

Change-Id: I6ae3a805167a3404701d8a53c14dc83299afb376
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1067498
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-22 21:56:37 -07:00
Scott Collyer
1168e4e70f charger: Modify manual mode to save desired current/voltage
Previously manual_mode used the current values of voltage/current to
set the desired values for each charge_request() call. Since manual
mode is entered/exited in the host command task, this can easily lead
to a race condition where the charger gets disabled in the host
command task, the reenabled by the charger task. This in turn makes
the ectool chargecontrol idle command unreliable.

This CL replaces manual mode with two variables, manual_voltage and
manual_current. The default values are -1 which means that they are
inactive. When the ectool command 'chargecontrol idle' is executed, it
sets both variables to 0. This then removes the race condition
possibility as each iteration of the charger loop will use
manual_voltage and/or manual_current if not -1.

BRANCH=coral
BUG=b:68364154
TEST=Manual
Executed 'ectool chargecontrol idle' and 'ectool chargecontrol normal'
numerous times and verified that the charging was disabled/resumed
each time as expected. Without this fix the problem could be
reproduced always in less than 10 attempts, typcially less than
5. With this CL charging is disabled reliably each time and I'm not
able to reproduce the problem.

Change-Id: I1ed9cdb42249cdf72ab34dd95b8f42c09d9a490c
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/851419
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Scott Collyer <scollyer@chromium.org>
(cherry picked from commit b7254f38979f274acc66330905399ff5ddf4129b)
Reviewed-on: https://chromium-review.googlesource.com/922069
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-05-21 18:19:24 -07:00
Philip Chen
453647e21a charge_state_v2: Throttle AP in low battery voltage
When EC sees voltage drops below BAT_LOW_VOLTAGE_THRESH,
we kick off a timer and ask AP to throttle.

When the timer expires which means EC hasn't seen under-voltage
for BAT_UVP_TIMEOUT_US, we ask AP to stop throttling.

We reset the throttling status and do nothing when AP is off (S5).

BUG=b:73050145, chromium:838754
BRANCH=scarlet
TEST=manually test on scarlet, confirm EC sends
EC_HOST_EVENT_THROTTLE_START and EC_HOST_EVENT_THROTTLE_STOP
host events when entering/exiting UVP.

Change-Id: Ia760989f760f95549f7a8a8acb1d01de23feab5a
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1064983
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: David Schneider <dnschneid@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-21 18:19:22 -07:00
Mary Ruthven
12b71fcbb0 cr50: include sleepmask in all images
sleepmask is really useful for debugging sleep issues. Add a read only
version of sleepmask to non-DBG images. It will only be accessible once
the console is unlocked.

BUG=none
BRANCH=cr50
TEST=make sure sleepmask can be modified in DBG images and can only be
read in prod images.

Change-Id: I31ef966f6302d4a7602a014cb08c9b972d13f41e
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1062804
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-18 20:08:43 -07:00
Patrick Georgi
85ddb2ce53 Shuffle const around
gcc 8.1 complains about duplicate const, and while some of these really
are duplicate, others look like they were supposed to tighten the API
contract so that variables are "const pointer to const data", but didn't
have that effect.

BUG=b:65441143
BRANCH=none
TEST=building Chrome EC as part of upstream coreboot's build with a
gcc 8.1 compiler now works (better. there are other issues left)

Change-Id: I6016c5f282516471746f08d5714ea07ebdd10331
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1039812
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-18 10:05:13 -07:00
Edward Hill
ed45aba4bd keyboard_scan: Add refresh and power button boot key options
Make Esc+Refresh+Power on Grunt enter Recovery Mode.

If Power is released fast:
[0.045303 KB init state: -- 02 08 -- -- -- -- -- -- -- -- -- --]
Add CONFIG_KEYBOARD_IGNORE_REFRESH_BOOT_KEY to handle this case.

If Power is held longer:
[0.045448 KB init state: 08 0a 08 08 08 -- 08 -- 08 08 -- 08 08]
Add CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI3 to handle this case.

BUG=b:79758966
BRANCH=none
TEST=Esc+Refresh+Power gives recovery screen on Grunt

Change-Id: I43a7d485535ff7b0d9bfce59f28c0049ee989818
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1063032
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
2018-05-16 22:49:42 -07:00
Stefan Adolfsson
86734119fc Reland "npcx: CEC: Send CEC message in mkbp event"
This reverts commit f139d3a0ca.

Reason for revert: Verified that the problem is in the kernel, not EC.

Original change's description:
> Revert "npcx: CEC: Send CEC message in mkbp event"
>
> This reverts commit 74b5a2ccb5.
>
> Suspected to have broken perf tests by keeping a CPU busy on kevin/bob.
>
> BUG=chromium:842873, b:76467407
>
> Change-Id: Iebbbb4623116840b851656e3ec28e75dc99cff79
> Reviewed-on: https://chromium-review.googlesource.com/1060073
> Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
> Tested-by: Ilja H. Friedel <ihf@chromium.org>

Bug: chromium:842873, b:76467407
Change-Id: I7d8990b2b8901b7de08f190a993bec645bbdacd2
Reviewed-on: https://chromium-review.googlesource.com/1061854
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-16 16:43:03 -07:00
Daisuke Nojiri
5252c73936 cbi-util: Allow field size to be specified
Currently, field sizes are automatically set to the smallest size
which can fit a given value. This patch makes cbi-util allow field
sizes to be specified.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=b:79514391
BRANCH=none
TEST=Tested as follows:
1. Create CBI image:
$ cbi-util create --file cbi.bin --board_version 0x202 \
  --oem_id 0xabcd:2 --sku_id 0xff:4 --size 256
2. Verify the image:
$ cbi-util show --file cbi.bin
CBI image: /home/dnojiri/tmp/nami/tmp/cbi.new.bin
  TOTAL_SIZE: 22
  Data Field: name: value (hex, tag, size)
    BOARD_VERSION: 514 (0x202, 0, 2)
    OEM_ID: 43981 (0xabcd, 1, 2)
    SKU_ID: 255 (0xff, 2, 4)
3. Verify the output matches with the previous output if field sizes
are not specified.

Change-Id: Ic7149274d6e4a118ea12bbf03199b548b7089a3e
Reviewed-on: https://chromium-review.googlesource.com/1056201
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2018-05-16 16:42:47 -07:00
Vadim Bendebury
607865dca4 cr50: in dev mode allow unverified certificates
When running signed with dev keys and the fallback certificate is not
available, proceed installing unverified root certificate. This at
least allows to keep basic TPM functions like storing objects in NVMEM
to keep going. Added a new return value to indicate this condition.

BRANCH=cr50, cr50-mp
BUG=none
TEST=verified that it is possible to switch chromebook between prod
     and dev modes when running with a dev signed Cr50.

Change-Id: I5b16d0bcbcfb25368f65075e1d2d485a69cb729f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1054990
Reviewed-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-05-16 12:41:38 -07:00
Vincent Palatin
d9354c9cd9 fpsensor: add capture type for reset pixel test
Add the FP_CAPTURE_RESET_TEST capture mode to be able to perform the
reset pixel values test.
Update ectool accordingly and also remove the deprecated 'fpcheckpixels'
command.

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

BRANCH=poppy
BUG=b:78597564
TEST=run 'ectool --name=cros_fp fpmode capture test_reset',
then 'ectool --name=cros_fp fpframe > test.pnm'
CQ-DEPEND=CL:*626747

Change-Id: I183f33b1cb9ba4db67219b8f7740d29dc0551f2d
Reviewed-on: https://chromium-review.googlesource.com/1061074
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-16 12:41:30 -07:00
Ilja H. Friedel
f139d3a0ca Revert "npcx: CEC: Send CEC message in mkbp event"
This reverts commit 74b5a2ccb5.

Suspected to have broken perf tests by keeping a CPU busy on kevin/bob.

BUG=chromium:842873, b:76467407

Change-Id: Iebbbb4623116840b851656e3ec28e75dc99cff79
Reviewed-on: https://chromium-review.googlesource.com/1060073
Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
Tested-by: Ilja H. Friedel <ihf@chromium.org>
2018-05-15 17:00:53 +00:00
Alexandru M Stan
1d518fb85c motion_sense: Lower jitter of EC->AP timestamp
When the EC sends an interrupt to the AP notifying it of new
accelerometer data we need to make sure the spot we record the timestamp
of the event is virtually identical to the spot the AP records the same
point in time.

Therefore a better spot for that is right next to the gpio toggling of
the interrupt line.

BUG=b:67743747
TEST=In the kernel, fifo_info->info.timestamp still has sane values.
TEST=CTS should still pass
BRANCH=master

Change-Id: Ic77101a045123e779f576c46b401c765304976fd
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/802976
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-14 15:32:47 -07:00
Stefan Adolfsson
74b5a2ccb5 npcx: CEC: Send CEC message in mkbp event
Instead of fetching incoming CEC messages using a specific read
command, extend the standard mkbp event so the CEC message can
be delivered directly inside the event.

Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org>

BUG=b:76467407
BRANCH=none
TEST="ectool cec read" still working with a kernel that has support
for the increased mkbp size.
CQ-DEPEND=CL:1046186,CL:1051085

Change-Id: Id9d944be86ba85084b979d1df9057f7f3e7a1fd0
Reviewed-on: https://chromium-review.googlesource.com/1051105
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-12 12:06:06 -07:00
Daisuke Nojiri
94b4c511a6 kblight: Add keyboard backlight control module
This patch promotes board/nami/keyboard_backlight.c to common
directory.
Board customization is done via board_kblight_init callback.
It currently supports two drivers: direct PWM control and lm3509.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=b:78360907,b:78141647
BRANCH=none
TEST=On Nami (for lm3509) and Sona (pwm), verify the followings:
1. Alt + brightness up/down works
2. After suspend-resume, brightness is restored
3. Lid close/open
4. After screen is off, keyboard backlight is turned off

Change-Id: I584c06e8702fe7b289999698f277311cfd3400bd
Reviewed-on: https://chromium-review.googlesource.com/1051027
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-05-11 12:10:44 -07:00
Fabien Parent
7034d8b711 charge_manager: add host cmd to get port count
The kernel is only able to know the number of USB PD port through
EC_CMD_USB_PD_PORTS, but the kernel needs also to be able to know
that there is a dedicated port. Add a host command that will
return the total number of charge port (USB PD + BJ).

BRANCH=None
BUG=chromium:841944
TEST=Called command from kernel driver and checked that the port count
was the expected value.

Change-Id: I6ccd8a2dee35bbe8bb66dfbe09d1cc09c54b73a0
Signed-off-by: Fabien Parent <fparent@baylibre.com>
Reviewed-on: https://chromium-review.googlesource.com/1046593
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-05-11 02:58:45 -07:00
Philip Chen
bf62593ebd charge_state_v2: Throttle AP in high battery discharge current
When EC sees discharge current hit BAT_MAX_DISCHG_CURRENT,
we kick off a timer and ask AP to throttle.

Then EC keeps monitoring discharge current. If the current doesn't
drop below BAT_MAX_DISCHG_CURRENT - BAT_OCP_HYSTERESIS, we restart
the timer and notify AP again, which shouldn't happen unless
AP misses or ignores the first notification.

When the timer expires, which means EC hasn't seen over-current
for BAT_OCP_TIMEOUT_US, we ask AP to stop throttling.

BUG=b:74321682, chromium:838754
BRANCH=scarlet
TEST=manually test on scarlet, confirm EC sends
EC_HOST_EVENT_THROTTLE_START and EC_HOST_EVENT_THROTTLE_STOP
host events when entering/exiting OCP.

Change-Id: I1e55fc23249596d8afec52a3885655ca9c1f2151
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/994188
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
2018-05-10 19:41:04 -07:00
Stefan Adolfsson
221ecb5dd0 CEC: Add CONFIG_CEC
Turning on CONFIG_CEC enables the CEC feature code and the
CEC console.

Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org>

BUG=b:76467407
BRANCH=none
TEST=Build ec-utils and chromeos-ec with CONFIG_CEC set
CQ-DEPEND=CL:995440

Change-Id: I23bb50d9456a07de7a9e7ea8bfc71f42c5e52778
Reviewed-on: https://chromium-review.googlesource.com/1030214
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-09 22:36:19 -07:00
Stefan Adolfsson
f04ec041b2 CEC: Add CEC API
Add HDMI CEC commands and events. Will be used by npcx CEC
implementation.

Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org>

BUG=b:76467407
BRANCH=none
TEST=Build ec-utils and chromeos-ec

Change-Id: I9008eb77179c296d6d07d321f48ba24585323607
Reviewed-on: https://chromium-review.googlesource.com/995440
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-09 22:36:18 -07:00
Daisuke Nojiri
c7559fea4e tablet_mode: Define common interrupt handler for tablet switch
This patch adds an interrupt handler for a tablet switch and an init
hook to enable the interrupt.

The handler does the typical tasks for convertible devices: 1. sets
tablet mode then 2. disables peripherals if tablet mode is on.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=b:77298177
BRANCH=none
TEST=buildall. Verify on Nami.

Change-Id: If7fb5ea15f388d2b6084d800d2bc05efafd1945e
Reviewed-on: https://chromium-review.googlesource.com/1043057
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-05-09 14:40:08 -07:00
Tom Wai-Hong Tam
aafc4f5d1a cheza: Support PD and charging
Port 0:
  TCPC: ANX3429
  PPC: SN5S330
  BC1.2: PI3USB9281

Port 1:
  TCPC: PS8751
  Power switch (sink): NX5P3290
  Power switch (source): NX20P5090
  BC1.2: PI3USB9281

Charger: ISL9238

BRANCH=none
BUG=b:74395451
TEST=make buildall -j
TEST=Did "gpioset EN_PP5000_A 1" before the folllowing tests:
 * Plugged adapter to port-0/port-1/both and saw charging
 * Plugged USB device to port-0/port-1/both and saw sourcing VBUS
 * Plugged adapter to one port and USB device to another port
 * Plugged USB disk to port-0 and booted into kernel
 * When AP off, not sourcing VBUS to USB device
 * Rebooting AP still works

Change-Id: Icde5e24c2cda3d0f2046486528a210af84befcca
Signed-off-by: Tom Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/969701
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-05-09 14:40:02 -07:00
Vincent Palatin
6c78f0fae7 fpsensor: export matched finger index
Update the fingerprint match event to include the index of the template
which matched.

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

BRANCH=poppy
BUG=b:77516790
TEST=on ZerbleBarn, enroll 5 fingers and do matching from the console,
see the proper finger index in the trace.
TEST=on Meowth, check unmodified biod still works for match with the
updated MCU firmware.
CQ-DEPEND=CL:*621808

Change-Id: I5be77ba65ce232989606274aba9a6c20841d533c
Reviewed-on: https://chromium-review.googlesource.com/1047267
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Nicolas Norvez <norvez@chromium.org>
2018-05-09 11:21:30 -07:00
Tom Wai-Hong Tam
548e4d9708 cheza: Support confirmation of power lost
Keep the timestamp of the latest power lost. Add a handler to wake
the chipset task to check if power lost stays low for a while (the
time between now and the latest power lost is longer than a period).

BRANCH=none
BUG=b:78455067
TEST=Toggle EC GPIO SYS_RST_L for a low pulse to execute PMIC reset
sequence and verified AP reset but not a transition S0 -> S5.
TEST=Toggle EC GPIO PMIC_KPD_PWR_ODL and SYS_RST_L for a low pulse
(see power_off function) to execute PMIC shutdown sequence and verified
a power-lost transition S0 -> S5.

Change-Id: I8ed789d701e834195865bfdf2d302388d42618d2
Signed-off-by: Tom Wai-Hong Tam <waihong@google.com>
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1028831
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-08 13:17:14 -07:00
Wai-Hong Tam
71e966af61 cheza: Enable AP_RST_REQ as a request from AP to reset itself
This makes the EC listen to the AP_RST_REQ GPIO from AP. The rising
edge interrupts to trigger a hook to call chipset_reset().

As the hook task will be preempted by the chipset task, it adds a
flag bypass_power_lost_trigger to avoid triggering to S5 as the
chipset state machines sees power lost during the reset.

So far the chipset_reset() implementation is to do a cold reset;
will be revised to a warm reset after the PMIC registers are
reprogrammed.

BRANCH=none
BUG=b:74395451
TEST=make buildall -j
TEST=Ran 'reboot' on AP console which toggles the GPIO.

Change-Id: I946cb029541ce018a8ed1ce25681d38998a7f4b6
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1023986
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-08 13:17:13 -07:00
Nicolas Boichat
6e8cbe40ee shared_mem: Assert that shared memory size is large enough
We add a configuration option to set the minimum shared memory
size (CONFIG_SHAREDMEM_MINIMUM_SIZE), so that the link will fail
if there is not enough IRAM left.

Also, we add 2 macros around shared_mem_acquire, that check, at
build time, that the shared memory size is sufficient for the
allocation:
 - SHARED_MEM_ACQUIRE_CHECK should be used instead of
   shared_mem_acquire, when size is known in advance.
 - SHARED_MEM_CHECK_SIZE should be used when only a maximum size
   is known.

This does not account for "jump tags" that boards often add on
jump from RO to RW. Luckily, RW usually does not do verification,
and does not need as much shared memory.

BRANCH=none
BUG=chromium:739771
TEST=make buildall -j, no error

Change-Id: Ic4c72938affe65fe8f8bc17ee5111c1798fc536f
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1002713
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-07 20:45:54 -07:00
Daisuke Nojiri
84a843bf63 CBI: Disallow board version and OEM ID to be reprogrammed
This patch makes CBI refuse to change board version and OEM ID.
When CONFIG_SYSTEM_UNLOCKED is defined, this restriction is removed.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=b:74946347
BRANCH=none
TEST=buildall

Change-Id: I6ceda5764af56ed18a575f5563eaf294bb2876d0
Reviewed-on: https://chromium-review.googlesource.com/1017225
Commit-Ready: Jett Rink <jettrink@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-04 03:02:49 -07:00
Wai-Hong Tam
f7aec0ceb5 cheza: Add SDM845 power sequence for rev-0 board
This is the power sequence for rev-0 board. Confirmed the behavior of
reprogramming the PMIC registers to enable the instant reset and
shutdown.

BRANCH=none
BUG=b:74395451
TEST=make buildall -j
TEST=Tried the following cases:
* Cold reset:
  $ dut-control cold_reset:on sleep:0.2 cold_reset:off
  Result: G3 -> S0
* Long power press to shutdown:
  $ dut-control pwr_button:press sleep:8.2 pwr_button:release
  Result: S0 -> S5 -> G3
* Long power press to power-on but then shutdown:
  $ dut-control pwr_button:press sleep:8.2 pwr_button:release
  Result: G3 -> S0 -> S5 -> G3
* Short power press to power-on:
  $ dut-control pwr_button:press sleep:0.2 pwr_button:release
  Result: G3 -> S0
* Console command: apreset
  Result: S0 -> S5 -> S0
* Console command: power off
  Result: S0 -> S5 -> G3
* Console command: power on
  Result: G3 -> S0
* Console command: apshutdown
  Result: S0 -> S5 -> G3
* Lid open to power-on:
  $ dut-control lid_open:no sleep:0.2 lid_open:yes
  Result: G3 -> S0

Change-Id: Ia9d44b1dccac66b5b580c08c6c1697ef5989b923
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/969702
2018-05-04 03:02:16 -07:00
Duncan Laurie
d0d1ea3d46 usb_pd_protocol: Add PD_ROLE_DISCONNECTED for data role swaps
Add a state to indicate that a data role is actually disconnected and
notify the board-level data swap function with this state when a cable
is unplugged.  This allows the board to clean up and restore any state
that may have been set up with a data role swap.

BUG=b:78308749
BRANCH=eve,poppy
TEST=manual on eve: plug in C-to-C cable, execute data swap on port 0
with 'pd 0 swap data' and ensure the OTG pins are asserted.  Then unplug
the cable and ensure OTG pins are now deasserted.

Change-Id: I7d8fff22dd5836b4b5af54f0ede71ee1b6e40b5c
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1035423
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-05-03 21:28:00 -07:00
Jett Rink
e47daed322 octopus: move common CONFIG defines into baseboard
The `make BOARD=yorp print-configs` and bip version
show no diff before and after this change.

BRANCH=none
BUG=none
TEST=verify the print-configs output does not change.

Change-Id: If2cdc39b685f529ece707b9831052daf58e91dfa
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1038898
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Vijay Hiremath <vijay.p.hiremath@intel.corp-partner.google.com>
2018-05-02 22:20:31 -07:00
Jett Rink
8476a6695d usb mux: add comment describing mux_state_t
It is a combination of flags and also represents typec_mux enum.

BRANCH=none
BUG=none
TEST=none

Change-Id: Ib44f41af6c99f62d76fe29230c82b64537ff0665
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1037423
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-05-02 14:01:16 +00:00
Jett Rink
a5695793ba anx7447: convert automatic OCM erase into command
We do not want to erase the OCM flash automatically so we
can ensure that we fix our supply chain issues. Add a command
that will erase the OCM if needed.

BRANCH=none
BUG=b:77658388
TEST=verified command works on yorp

Change-Id: Iaf6ada3b1e223d15ae0d9624bdcc54b90cb33b64
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1035428
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2018-05-01 02:13:29 -07:00
Allen Webb
1820ecce31 Cr50: Add logging functionality to PinWeaver.
In order to be able to recover from the AP and Cr50 getting out of
sync, this logging functionality gives Cr50 a way to track the
state changes of the merkle tree so that the AP can be updated to
the current state as long as it has a recent enough copy.

This involves packing the important information so it can be stored
efficiently on flash, and adding the necessary messages for the
replay.

CQ-DEPEND=CL:895395,CL:929430
BRANCH=none
BUG=chromium:809729, chromium:809745
TEST=cd ~/src/platform/ec && V=1 make run-weaver_ng -j

Change-Id: I40f98de2c8e9706cccb5b922215699f2132fa121
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/963773
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-04-27 12:22:26 -07:00
Allen Webb
826a3876b4 Cr50: Add VENDOR_CC_PINWEAVER vendor command.
This connects the pinweaver code to the tpm vendor
specific command code.

CQ-DEPEND=CL:895395
BRANCH=none
BUG=chromium:809741
TEST=TBD

Change-Id: I2a6c4bf52ad77b7bf0395095404e925e1dd48dbc
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/929430
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-04-27 12:22:26 -07:00
Allen Webb
c61479bbd8 Cr50: Added Pinweaver base implementation.
This adds some of the ground work for hardware backed brute force
resistance on Cr50. The feature is called Pinweaver. It will
initially be used to enable PIN authentication on CrOS devices
without reducing the security of the platform. A Merkle tree is
used to validate encrypted metadata used to track login attempts.

The metadata tracks counts of failed attempts, a timestamp of the
last failed attempt, the secrets, and any associated parameters.
Instead of storing the metadata on Cr50 an AES-CTR is used with an
HMAC to encrypt the data so it can be stored off-chip and loaded
when needed.

The Merkle tree is used to track the current state of all the
metadata to prevent replay attacks of previously exported copies.
It is a tree of hashes whose root hash is stored on Cr50, and whose
leaves are the HMACs of the encrypted metadata.

BRANCH=none
BUG=chromium:809730, chromium:809741, chromium:809743, chromium:809747
TEST=cd ~/src/platform/ec && V=1 make run-pinweaver -j

Change-Id: Id10bb49d8ebc5a487dd90c6093bc0f51dadbd124
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/895395
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-04-27 12:22:25 -07:00
Aseda Aboagye
36980ec169 pd: Properly assign data role on reset
According to PD spec:
- Data role shall not be reset on soft reset.
- Data role shall be reset to power-role default on hard reset.

Implement the above. Even if both ports follow spec, it's still possible
for a data role conflict to occur if, for example, data role swap occurs
(data role mismatches power role default) followed by a hardware reset
of one port (such that data role gets reset to power role default).
Handle such cases by taking error recovery actions.

BUG=b:71333840,chromium:805040

TEST=Connect scarlet to powered Apple accessory, verify scarlet comes up
in SNK-DFP after soft reset and issuing "reboot" on EC console.  After
issuing a hard reset, the port comes up in SNK-UFP (which is the
power-role default).

BRANCH=None

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: I65139f277d59a0612f8323d711080f52425ff5e7
Reviewed-on: https://chromium-review.googlesource.com/885462
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-04-25 23:00:01 -07:00
Aseda Aboagye
a112d2495b pd: Save power role in BBRAM.
In order to re-initialize our PD state variables properly following a
reset, we need to save our current power role.  This commit adds a bit
in the BBRAM PD flags for the power role.

BUG=b:71333840,chromium:805040
BRANCH=None
TEST=Add code to save data role and restore both roles, verify that both
are saved accordingly.

Change-Id: I156ae8179c8e12c63322132d1f0078990bd215f8
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/979264
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-04-25 23:00:00 -07:00
Aseda Aboagye
7dc83bed48 USB PD: Save explicit contract state for port 2.
pd_get/set_saved_active() made the assumption that there were only two
ports.  But now, we have a board that turned that port count all the way
up to 3.  This commit adds in that new port BBRAM index.  It also turns
the byte where the port information was stored into a byte of flags,
where bit 0 indicates whether there was an explicit contract in place or
not.

BUG=b:72838807
BRANCH=None
TEST=With some code to check for explicit contract state for port 2,
verify it's functional.

Change-Id: I6f062f67bd3c47dd43ea7e24e844a9286fa37af9
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905923
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-04-25 22:59:58 -07:00
Aseda Aboagye
3dfcaaaf0b npcx: Add BBRM idx for a 3rd PD port.
Currently, there's only one board with 3 PD ports and it uses NPCX.
Therefore, this commit just adds the index to NPCX which will be used to
save the fact that there was an explicit contract in place.

BUG=b:72838807
BRANCH=None
TEST=make -j buildall

CQ-DEPEND=CL:905390

Change-Id: Ic960f14a52f2a740adbe08bc340c45edfefbbf26
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905922
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-04-25 22:59:58 -07:00
Jett Rink
58f790b2c1 mux: add mode for TCPCI mux that is not the TCPC
We need to use the PS8751 as the USB mux without configuring
it as the TCPC. Add mode that allows passing in i2c port
and address instead using tcpc_config_t values.

BRANCH=none
BUG=b:78341944
TEST=build using bip

Change-Id: I45b420ef890dfa8c5e5052864b7a2bb66d8734d6
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1024486
2018-04-24 18:53:06 -07:00
Jett Rink
fb712058ee bq25703: initial commit for bq25703 driver
BRANCH=none
BUG=b:76429930
TEST=building with bip

Change-Id: Ibed206e1e0b578b3a4b70709509a7288284fc23b
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1019606
Reviewed-by: Justin TerAvest <teravest@chromium.org>
2018-04-23 18:09:09 -07:00
Furquan Shaikh
8faa22cb27 APL/GLK boards: Use chipset_pre_init_callback
This change updates all APL/GLK boards to use
chipset_pre_init_callback instead of hook.

BUG=b:78259506
BRANCH=None
TEST=Verified that yorp still boots.

Change-Id: I71ab0f1111e89a254db83fc58abfdfe8eacd3575
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1018734
Commit-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-04-19 19:28:42 -07:00
Furquan Shaikh
e54c3e1728 chipset: Add callback for chipset pre-initialization
This change adds a callback for chipset_pre_init_callback which is
made by x86 common power state machine when in G3S5 state. Until now,
there was a hook CHIPSET_PRE_INIT_CALLBACK that was notified by
chipset task when in G3S5 state. However, there are at least following
reasons why this should be a callback and not a hook notification:
1. The initialization that is done as part of pre-init could be
essential for the power state machine to make progress. Though the
chipset task goes to sleep waiting for power signals after the hook
notification, pre-initialization can all be done as part of a callback
since it is mostly board-specific code that is doing work to
initialize PMIC.
2. Typically, boards use I2C transactions to setup PMIC on getting
chipset pre-init notification. However, since i2c transfers are not
encouraged in hook task, they have to be deferred anyways.
3. Since the initialization is being done as part of hook task, use of
any constructs e.g. pwr_5v_en_req which allows multiple consumers to
enable/disable power rails will use task id for hook task. Instead it
is better to provide correct information about the task by letting
chipset task perform this request.

Thus, this change adds a callback chipset_pre_init_callback in G3S5
state for x86 power state machine. This callback is guarded by
CONFIG_CHIPSET_HAS_PRE_INIT_CALLBACK.

The hook notification is left as is for now until all x86 boards are
moved over to using the newly added callback.

BUG=b:78259506
BRANCH=None
TEST=None

Change-Id: I2e1d73e5308759fef41680ae715ef71268b61780
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1018733
Commit-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-04-19 19:28:41 -07:00
Jett Rink
ff9248fbaa system: update board version to return an error if encountered
Now that board version can come from CBI, we can have a real error
reading it. We should pass that error to the console or to the
AP on the host command and let the AP firmware (or user) decided how to
handle that error case

Also update the CONFIG_BOARD_VERSION to be derived instead of needed
in most cases.

BRANCH=none
BUG=b:77972120
TEST=Error reported on EC console and AP console when CBI is
 invalid on yorp

Change-Id: Ib8d80f610ea226265a61e68b61965150cdc9bb04
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1015776
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-04-19 12:46:14 -07:00
Aseda Aboagye
b107af470e isl923x: Add 'charger_dump' console command.
This commit adds an optional console command that will dump the contents
of the battery charger IC registers.  Currently, the only chargers
supported are the BD9995x as well as the ISL923x.

BUG=None
BRANCH=None
TEST=Enable on meowth; Flash; Verify that the command works without any
issues.

Change-Id: I2221efe0ed6e0f6063c97547e0da2d775bf4da45
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1016004
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-04-18 02:08:11 -07:00