Commit Graph

2323 Commits

Author SHA1 Message Date
Vijay Hiremath
b49d5872e9 bq25703: Report actual input current limit
IIN_DPM register reflects the actual input current limit programmed
in the register, either from host or from ICO. After ICO, the current
limit used by DPM regulation may differ from the IIN_HOST register
settings.

BUG=b:80279932
BRANCH=none
TEST=Manually tested on BIP
     Used BC1.2 DCP charger 'charger' command yield 900mA while
     charge ramp set to 2.4A.

Change-Id: I6389205bd70d7729e9dd810fef3dfbf83a7d8c65
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1080343
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-06-04 13:31:21 -07:00
Vincent Palatin
edbfb3a43b cortex-m: add D-cache support
Add support to enable the architectural D-cache on ARMv7-M CPU
supporting it.
Update the MPU code in order to be able to declare an 'uncached' RAM
region (e.g. to store the DMA buffer).

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

BRANCH=poppy
BUG=b:78535052, b:75068419
TEST=with the following CL, on ZerbleBarn, boot and capture a finger
image.

Change-Id: I275445e7c0b558cedc3e7d6fc6840ff9b4b76285
Reviewed-on: https://chromium-review.googlesource.com/1032776
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-06-04 10:09:42 -07:00
Aseda Aboagye
32255f2989 chgstv2: Fix manual control via EC console.
There was a recent change to save the manual setting of charge current
and voltage, however it was done so assuming that the parameters were
set via the host command interface. (CL:922069) However, there are times
where the charge voltage/current would like to be manipulated without
booting the AP.  This commit simply makes the EC console command work
again.

BUG=None
BRANCH=None
TEST=make -j buildall
TEST=Flash nocturne, `chgstate idle on; charger current 256; charger
voltage 7400`; verify that the charge voltage and current is actually
changed.

Change-Id: Id250d9704f8509162518495556603950248fb267
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1081120
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Scott Collyer <scollyer@chromium.org>
2018-06-01 17:44:41 -07:00
Edward Hill
9734ec2d6b battery: Move fuel gauge code to common
Move fuel gauge code to common to avoid duplication in octopus and
grunt baseboards.

BUG=b:79704826,b:74018100
BRANCH=none
TEST=make -j buildall

Change-Id: I58a615c9ed7906cb19b49c2baa36aaa619838cf1
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1072637
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Vijay Hiremath <vijay.p.hiremath@intel.corp-partner.google.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-06-01 17:44:20 -07:00
Mary Ruthven
37fadc39b5 cr50: add command for factory reset
The factory reset command can be used to enable ccd factory mode. The
command can open ccd if write protect is removed and ccd hasn't been
restricted. Right now we check FWMP and the ccd password before allowing
factory reset. Factory reset cannot be used to get around anything that
disables ccd.

This adds 72 bytes.

BUG=b:77543904
BRANCH=cr50
TEST=Try enabling factory mode using factory reset. Verify setting write
protect, setting the FWMP disable ccd bit, or setting a ccd password
prevents factory reset from enabling factory mode.

Change-Id: I6e203bf6068250f009881aa95c13bc56cb2aa9e7
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1069369
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-31 16:22:35 -07:00
Mary Ruthven
5a23e3f49a cr50: refactor rma mode into factory mode
We're doing a bit of refactoring to break out factory mode into its own
file. Now factory reset and rma reset will be two methods of entering
factory mode. Factory mode can be disabled with the disable_factory
vendor command.

Factory mode means all ccd capabilities are set to Always and WP is
permanently disabled. When factory mode is disabled, all capabilities
are reset to Default and WP is reset to follow battery presence.

This adds 56 bytes.

BUG=none
BRANCH=cr50
TEST=verify rma reset will enable factory mode.

Change-Id: I21c6f7b4341e3a18e213e438bbd17c67739b85fa
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1069789
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-30 20:38:53 -07:00
Vadim Bendebury
7b00185216 cr50: move RMA challenge-response to P256
Using the p256 curve is beneficial, because RMA feature is currently
the only user of the x25519 curve in Cr50, whereas p256 support is
required by other subsystems and its implementation is based on
dcrypto.

The p256 public key is 65 bytes in size, appropriate adjustments are
being made for the structure storing the server public key and the key
ID.

The compact representation of the p256 public key requires 33 bytes,
including the X coordinate and one extra byte used to communicate if
the omitted Y coordinate is odd or even.

The challenge structure communicated to the RMA server allows exactly
32 bytes for the public key. To comply, the generated ephemeral public
key is used in compressed form (only the X coordinate is used).

For the server to properly uncompress the public key one extra bit is
required, to indicate if the original key's Y coordinate is odd or
even. Since there is no room for the extra bit in the challenge
structure, a convention is used where the generated ephemeral public
key is guaranteed to have an odd Y coordinate.

When generating the ephemeral key, the Y coordinate is checked, and if
it is even, generation attempt is repeated.

Some clean up is also included: even with debug enabled, generated
challenge is displayed only once as a long string, convenient for
copying and pasting.

The new feature is not yet enabled, p256 support on the RMA server
side is not yet available.

Enabling p256 curve for RMA authentication saves 5336 bytes of the
flash space.

BRANCH=cr50, cr50-mp
BUG=b:73296606
TEST=enabled CONFIG_RMA_AUTH_USE_P256 in board.h, generated challenge
     and verified matching auth code generated by the rma_reset
     utility.

Change-Id: I857543c89a7c33c6fc2dc00e142fe9fa6fc642cf
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1074743
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-30 20:38:52 -07:00
paris_yeh
e8f009b64b keyboard_scan: Add option to support keyboards with language ID
ID pins are considered additional KSOs while keycode scanning works
for the existing KSI0 ~ KSI7. While diriving ID pins, the state of
interconnection between ID pins and KSI pins could be used for
identifiers to tell keyboard itself. (e.g. US, Japan,and UK keyboard)

BRANCH=master
BUG=b:80168723
TEST="make -j buildall"
TEST=Verified 5 distinct keyboard samples w/ different Language ID values
     on the same reworked Coral, which VOL_UP and VOL_DOWN were reworked
     for ID pins. crrev.com/c/1053617 is my experimental patch on top of
     this for further verification

Change-Id: I1d6e647df74c50d60bc1264c045b2587d0bf23d8
Signed-off-by: paris_yeh <pyeh@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1068951
Commit-Ready: Paris Yeh <pyeh@chromium.org>
Tested-by: Paris Yeh <pyeh@chromium.org>
Reviewed-by: Paris Yeh <pyeh@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-30 12:50:39 -07:00
Alexandru M Stan
b317d2d65d sensors: Make sync driver more robust
Use a queue now for sync events, this will allow multiple interrupts to be
called before the motion sense task executes. The events (including
timestamps) get stored in a small queue. 8 events for the queue size should
be plenty, most applications will have latency concerns anyway once we
get a couple of queued up events.

Also changed the init function to be a little bit more robust to race
conditions. Added count argument to the "sync" simulation command to test
the queue behavior.

BRANCH=master
BUG=b:73551961, b:67743747
TEST="sync 4" yields 4 events on the AP, whereas before it would only
give the AP the last event.

Change-Id: I9fcb1fb8b35eb5f8ffcc21afbfcb0f0d9bc33804
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1065149
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-05-30 01:02:37 -07:00
Philip Chen
0de5b8ed69 system: Enable/Disable low power idle in run time
We have enable_sleep()/disable_sleep() to enable/disable
EC deep sleep mode in runtime.

Here we introduce similar interfaces to enable/disable
EC idle (sleep) mode.

BUG=b:78792296
BRANCH=scarlet
TEST=Confirm idle mode is enabled/disabled when
enable_idle() and disable_idle() are called.

Change-Id: I2484f08a066523441064968da99c47de9342ecf0
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1072370
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
Commit-Queue: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
(cherry picked from commit c6b6626cdccef04b0ff203aaed0d84dbdcecf8b7)
Reviewed-on: https://chromium-review.googlesource.com/1076708
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
2018-05-30 01:02:36 -07:00
Emil Lundmark
aca6cb220c acpi: Add map for controlling USB port power
Some devices have GPIO pins that control USB port power connected to
the EC, so they cannot be toggled by ACPI. This patch adds a memory
map between the EC and ACPI that can be used on such devices. It can
hold the power state of up to 8 USB ports. Currently, only dumb power
ports are supported.

BUG=chromium:833436
BRANCH=fizz
TEST=On a fizz that runs BIOS with EC_ACPI_MEM_USB_PORT_POWER mapped,
check that both reads and writes are propagated.

Change-Id: I413defcb9e4d234fea7f54d46b6b8a1a10efa31e
Signed-off-by: Emil Lundmark <lndmrk@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1069273
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-29 17:15:25 -07:00
Nicolas Boichat
ecd0d1b576 rsa: Further optimization of multiplications for Cortex-M0
In RSA, we often need to actually compute (a*b)+c+d: provide some
assembly optimized functions for that.

With -O3, 3072-bit exponent, lower verification time from 104 ms to
88 ms on STM32F072 @48Mhz.

BRANCH=poppy
BUG=b:35647963
BUG=b:77608104
TEST=On staff, flash, verification successful
TEST=make test-rsa, make test-rsa3
TEST=make BOARD=hammer test-utils test-rsa3, test on board

Change-Id: I80e8a7258d091e4f6adea11797729ac657dfd85d
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1071411
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-29 06:02:19 -07:00
Nicolas Boichat
49ff62bf0b rsa: Optimization of multiplications for Cortex-M0
We multiply 2 32-bit numbers (and not 64-bit numbers), and then add
another 32-bit number, which makes it possible to optimize the
assembly and save a few instructions.

With -O3, 3072-bit exponent, lower verification time from 122 ms to
104 ms on STM32F072 @48Mhz.

Optimized mac function from Dmitry Grinberg <dmitrygr@google.com>.

BRANCH=poppy
BUG=b:35647963
BUG=b:77608104
TEST=On staff, flash, verification successful
TEST=make test-rsa, make test-rsa3
TEST=Flash test-utils and test-rsa to hammer => pass

Change-Id: I584c54c631a3f59f691849a279b308e8d4b4b22d
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/449024
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-28 22:46:28 -07:00
Nicolas Boichat
43a5152a2e console_output: Clarify help text for CONFIG_CONSOLE_CHANNEL
BRANCH=poppy
BUG=b:35647963
TEST=N/A

Change-Id: I85dd6553cf3ebace4e19813a308d0a024eba2915
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1071412
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-26 00:21:47 -07:00
Furquan Shaikh
1910779d41 it83xx: Add a config option for enabling mouse LDN
Not all boards using ITE83XX use mouse LDN. This change adds a config
option to allow boards to explicity enable this device. Currently,
this device is enabled only for glkrvp_ite and it83xx_evb. It is
disabled for reef_ite and bip.

Change-Id: I7149fd0cb35cc9f49f2b7b80f6c2deefe2edda55
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1070785
Commit-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Dino Li <dino.li@ite.corp-partner.google.com>
2018-05-26 00:21:44 -07:00
Nicolas Boichat
b5cebbaadb console_channel.inc: Add more ifdef to reduce number of channels
There are still more ifdef than can be added: this just takes out
the low hanging fruits.

BRANCH=poppy
BUG=b:35647963
TEST=make buildall -j, see that we gain from 0 to 64 bytes on many
     boards.

Change-Id: Ibe85b8bfa5d5c22c160e4a6656104256067beee9
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1070948
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-26 00:21:42 -07:00
Nicolas Boichat
5c5eba404c cheza: Add stubs and ifdefs to fix tests
BRANCH=none
BUG=none
TEST=make BOARD=cheza tests -j

Change-Id: Ifec4653bf71b870b616669f0a32ba528c1e38787
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1072217
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-05-26 00:21:41 -07:00
Randall Spangler
d7705eb311 ccd_config: Simplify open and password
Allow setting password from the AP, but not from USB.  Remove the old
password control logic, which is no longer needed.

Allow open if:
- Not explicitly blocked
- Not blocked via FWMP
- One of the following is true:
  - A password is set
  - Battery is removed (also doesn't require physical presence)
  - Dev mode is on, and request came from the AP

Reduces cr50 binary by 152 bytes.

BUG=b:79983505
BRANCH=cr50
TEST=manual, with a CR50_DEV=1 build

	ccd oops
	ccd lock
	ccd unlock -> fails
	gsctool -U -> fails from host
	gsctool -t -U -> fails from AP

	ccd oops
	ccd password foo -> fails from console
	gsctool -P -> fails from host
	gsctool -t -P -> works from AP
	ccd get -> confirms password set

	ccd lock
	ccd unlock foo -> works
	ccd lock
	gsctool -U -> works from host, if correct password supplied
	ccd lock
	gsctool -t -U -> works from AP, if correct password supplied

	ccd open foo -> works
	ccd lock
	gsctool -O -> works from host, if correct password supplied
	ccd lock
	gsctool -t -O -> works from AP, if correct password supplied

	ccd oops
	ccd lock
	(remove battery)
	ccd open -> works without physical presence
	(reattach battery)
	ccd lock
	gsctool -O -> works from host
	ccd lock
	gsctool -t -O -> works from AP, if dev mode is enabled

Change-Id: I364b322d03db250e7dd140767d7a22dbb3ac1eef
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1072957
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-25 20:31:57 -07:00
Jett Rink
4a65a62f85 ppc: making driver non-const
We need to update the driver based on the runtime board id, so we need
to remove the const attribute.

BRANCH=none
BUG=b:78896495,b:78021059
TEST=build all -j

Change-Id: I5f751c33cf4ec68a38aeb8644170df4987c87d7b
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1068030
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-05-24 15:44:30 -07:00
Nicolas Boichat
db24bed78d timer: Allow disabling gettime console command
hammer does not need that command, let's just remove it.

BRANCH=poppy
BUG=b:35647963
TEST=make newsizes, saves 112 bytes of flash

Change-Id: I24ed979f8a9053128d4eb56fc5af00429f7ba0ae
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1070950
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-24 04:10:04 -07:00
Nicolas Boichat
35e278bb41 console_output: Add option to disable console channels
On hammer, we do not need the console channels, so we can just
disable them to save flash size.

BRANCH=poppy
BUG=b:35647963
TEST=make newsizes, staff image size shrinks by 704 bytes

Change-Id: I7a493ae57573814b166d45e57f1ad3d885f26086
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1070949
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-24 04:10:04 -07:00
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