Commit Graph

1889 Commits

Author SHA1 Message Date
Shawn Nematbakhsh
38cf4fccfb npcx: i2c: Remove needless controller state pre-check
We're now locking i2c at the controller (not port) level, so it's not
necessary to check if a given controller is busy before doing an i2c
transaction.

BUG=None
TEST=Manual on kevin, verify i2c is still functional.
BRANCH=gru

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ic0cda34f9a58c76083699990a0dc3e761bcdec4f
Reviewed-on: https://chromium-review.googlesource.com/393107
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
(cherry picked from commit 7d2e2f565b79a035a270ca083af97c6a14983739)
Reviewed-on: https://chromium-review.googlesource.com/396138
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-10-17 17:40:52 -07:00
Mary Ruthven
fb442347bd g: add usb i2c driver
This is based off of the protocol in the stm32 directory. We should
unify these implementations and the other ccd endpoints at some point.
Right now I though that I should keep the implementation the same as the
other g chips ccd drivers.

BUG=chrome-os-partner:57059
BRANCH=none
CQ-DEPEND=CL:390015
TEST=manual
	download the servo patch and run 'sudo servod -c ccd_cr50.xml -c
	reef_r1_inas.xml'

	Test the usb i2c bridge by running 'dut-control | grep pp'

	Attach servo and verify cr50 will not enable i2c

Change-Id: I0f72671505f5451a960d3baea4b2c34b6910d892
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388896
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
2016-10-14 01:02:13 -07:00
Mary Ruthven
2ddc2ae675 g: check that the rx fifo is ready before reading from it
The USB stream should check that there are bytes in the rx fifo to read
before trying to read them. This should have been in here already.

Checking if rx is valid in usb-stream makes the rx_valid call in usb_spi
unnecessary so that is removed.

BUG=none
BRANCH=none
TEST=manual
	Test CCD functionality still works on gru and reef
	AP/EC consoles
	sudo flashrom -p raiden_debug_spi:[AP|EC] -r img.bin
	usb updater

Change-Id: Ieb77e35cc471b1f97d540ea4560591f0f40dd600
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/397858
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-13 04:32:11 -07:00
CHLin
57ad82c274 npxc: lpc: correct setting for SCI/SMI gererated from PM module
In current FW implement, there are two ways to generate SMI/SCI:
(1) Controlled by GPIO module register.(#define CONFIG_SCI_GPIO)
(2) Controlled by PM module register.(#undef CONFIG_SCI_GPIO)
This CL fix for case(2):
In this case, these two dedicated pins(GPIOC6/GPIO76) are used
as SMI/SCI and must be enabled by pinmux. Set the related pinmux
at initial.
By default, the SMI/SCI polarity is negative. This means SMI/SCI
is inverted when writing to SMI/SCIB but not inverted when reading
from them(see Section 5.2.2, figure 61 in datasheet). It will cause
the code more complicated to implement. Disable negative polarity
at init.

Modified drivers:
1. lpc.c: set pinmux for dedicated SMI/SCI pins and disable the
          negative polarity.

BUG=chrome-os-partner:34346
BRANCH=none
TEST=make buildall; try hostevent(lid switch) on Wheatley with
CONFIG_SCL_GPIO undefined.

Change-Id: Ia317e54deb6861d7189b3594bd7414b53408b933
Signed-off-by: CHLin <CHLIN56@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/396718
Commit-Ready: CH Lin <chlin56@nuvoton.com>
Tested-by: CH Lin <chlin56@nuvoton.com>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@google.com>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2016-10-12 06:30:26 -07:00
Mary Ruthven
4aa7cd72cf g: use devid 0 and 1 to create a serial number
To be able to identify different cr50 devices connected to the same
machine we need a serial number. This change uses dev id 0 and 1 to come
up with one.

BUG=chrome-os-partner:56641
BUG=chrome-os-partner:58342
BRANCH=none
TEST=lsusb -vd 18d1:5014 | grep iSerial shows different numbers for
different devices. Verify when ccd is disabled the serial number is 0.

Change-Id: I85c54af4a21bdfd0542019c02aa8420d9a879fae
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/395633
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-11 23:01:59 -07:00
Marius Schilder
02915f491f Update TRNG handling.
Enable post processing and churn.
Slice low 2 bits.
Increase timeout and retry counters.

BRANCH=none
BUG=none
TEST=tcg_tests pass
Change-Id: I3a8a6d14d4b113fb6831a5c8b253e5544ce70f8e
Reviewed-on: https://chromium-review.googlesource.com/394130
Commit-Ready: Marius Schilder <mschilder@chromium.org>
Tested-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: William Wesson <wesson@google.com>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-11 23:01:44 -07:00
Mulin Chao
d809d1614f npcx: Enable VW's valid bits of SCI#/SMI# if no CONFIG_SCI_GPIO.
Enable valid bits of SCI#/SMI# of eSPI's VW if there's no CONFIG_SCI_GPIO
definition in board-level driver. This CL also fixed the order of VW
event bits in comments.

Modified sources:
1. espi.c: Enable valid bits of SCI#/SMI#.

BRANCH=none
BUG=chrome-os-partner:34346
TEST=make all; test nuvoton IC specific drivers

Change-Id: I8d094513284b4ed42c5c26fe1975d71bbf050aa4
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/396618
Reviewed-by: Duncan Laurie <dlaurie@google.com>
2016-10-11 23:01:37 -07:00
Mary Ruthven
6abbb63639 cr50: add press and release options to powerbtn command
This change adds options to the powerbtn console command to press and
release the power button.

BUG=chrome-os-partner:58123
BRANCH=none
TEST=manual
	'powerbtn press' force a power button press
	'powerbtn release' release the power button. This will not
	override the signal if the button is physically pressed.

Change-Id: I52631d30dbae874ba6637f728cb6e435cb626e12
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/396207
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-11 01:48:21 -07:00
Scott
7bfcb41d2c Cr50: I2CM: Enable i2c master for accessing INA chips
On both Reef and Gru there are INA (shunt bus voltage monitor) ICs
connected to the Cr50 I2C master bus. The use case for these chips is
in a lab setting using case closed debugging. Power to the INA chips
is controlled by a separate Cr50 gpio signal.

By default, the INAs are powered off and the I2C master bus is not
connected. A function ina_connect() is provided which needs to be
called prior to attempting to access the INAs via I2C.

BRANCH=none
BUG=chrome-os-partner:57059
TEST=manual
Tested both Reef and Gru. Verified that console command 'ccd ina
on|off' works as expected and that can repeatedly read registers on
the INA using the following command "i2cxfer r16 0 0x40 0".
Read 0x2771 [10097] which is the default value. In addition
wrote register 14 (bits 15:1 are writeable) and verified the value was
able to read the value back which was written.

Change-Id: I670f7897555dae29642264531599dc4471c52bbd
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/394168
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-11 01:47:47 -07:00
Scott
8c370fedba g: Added I2CM driver to support chip_i2c_xfer()
Added i2cm driver to support chip_i2c-xfer function. The initial use
case is for INA chips on the Reef/Gru platforms. Note that this CL
does not include any board specific changes and therefore does not
include an I2C port definition or required pinmux settings.

BRANCH=none
BUG=chrome-os-partner:57059,chrome-os-partner:58355
TEST=manual
Used console command "i2cxfer r16 0 0x40 0" to read the config
register. Read 0x2771 [10097] which is the default value. In addition
wrote register 14 and read back the value.

Change-Id: If9e377da4c8f4835d4676281872a0f079fe56aa6
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388794
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-11 01:47:46 -07:00
Vadim Bendebury
36b39b5fc9 cr50: provide means of posting reboot request
Usually CR50 TPM reset happens when the AP reboots, the CR50 RO does
not get a chance to run in this case, so the running RW does not
change either,

Once the idle RW section was updated, the only way to start it is to
reboot the CR50 completely, Rebooting CR50 causes the whole system
reset, so it should not be happening at random moments in time.

This patch introduces a mechanism to delay reboot to the moment when
the TPM is reset. The reboot request would be posted in the end of the
update, and then the AP would reboot, triggering a TPM reboot, which
in turn would trigger the CR50 reset.

The USB update handler now posts the reboot request instead of
triggering the reboot immediately.

BRANCH=none
BUG=chrome-os-partner:58226
TEST=with the rest of the patches applied verified that the system
     gets reset and the new image version kicks in on both gru (over
     SPI) and reef (over USB).

Change-Id: Iff859f2e7a48c5035a27fffd17aefe7e318af569
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/395627
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-08 01:04:48 -07:00
Bill Richardson
afcfb4b998 g: Upgrade protocol returns the keyid for RO/RW
The keyid field of struct SignedHeader is what distinguishes prod
keys from dev keys. This may be useful someday, so let's have the
update protocol return those values for the active RO and RW
images.

Bump the UPGRADE_PROTOCOL_VERSION accordingly.

Note: This doesn't enforce any keyid matches, it just returns the
current values as part of the initial upgrade handshake in case
we want to know.

BUG=chrome-os-partner:57956
BRANCH=none
TEST=make buildall; try on Gru

Make sure that Cr50 can be freely updated and downgraded between
firmwares that speak either v4 or v5 of the protocol, by using
the v5-aware usb_updater tool.

And of course, make sure that v5 images report their keyids. Duh.

Change-Id: If2cc0d4023dca2078b9398fd899618dc2cd409b9
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/394732
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-10-07 16:47:09 -07:00
Shawn Nematbakhsh
3f6232f2d3 hibernate: Re-init GPIO levels on hibernate wake
Reset-on-hibernate wake performs a soft-reset, which re-initializes GPIO
states to ROM POR values. Therefore, it is necessary to re-init GPIO
states once again based on board-level GPIO settings.

BUG=chrome-os-partner:58077
BRANCH=gru
TEST=Run `hibernate` on gru, wake, then run `bd99955_dump`. Verify
actual register values are printed rather than zeros.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ib3eb1dd6aa264d00d42d8e386bfd1ef7f6cf7717
Reviewed-on: https://chromium-review.googlesource.com/395426
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-10-07 16:47:00 -07:00
Mary Ruthven
2e4d4e2e05 cr50: add console commands to have parity with servo
This change adds apreset, ecreset, ec_rst, sys_rst and powerbtn options
to the ccd console command.

BUG=chrome-os-partner:58123
BUG=chrome-os-partner:56835
BRANCH=none
TEST=manual
	sysrst resets the AP
	sysrst on/off controls SYS_RST_L

	ecrst resets the ec
	ecrst on/off controls EC_RST_L

	powerbtn 500 will simulate a power button press for 500 ms

Change-Id: I89adc88eb407730c9d57811a07bfef8fcf63c5b9
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/393809
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-05 20:58:47 -07:00
philipchen
84db5ed037 Enable spi_flash_read to read > SPI_FLASH_MAX_READ_SIZE
BUG=chromium:542789
BRANCH=none
TEST=make buildall

Change-Id: I55bf5bdb09b10be1c522ea4d843690abcc45abb2
Reviewed-on: https://chromium-review.googlesource.com/391867
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2016-10-05 20:58:37 -07:00
Daisuke Nojiri
3afd683d68 cts: Add I2C tests for read8/16/32 and write8/16/32
This patch adds tests for i2c_read8/16/32 and i2c_write8/16/32.

BUG=chromium:653183
BRANCH=none
TEST=make buildall. Run cts.py -m i2c for 100kHz with 10k ohms
pull-up registers on SCL and SDA. TH=stm32l476g-eval DUT=nucleo-f072rb.

Change-Id: I8121b1c5dc7542da45141543e35036ef41364c38
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/393331
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-10-05 20:58:20 -07:00
Daisuke Nojiri
c0c66cdd12 stm32l4: Add i2c driver
This patch adds master and slave drivers for stm32l4 family. Only slave
functionality is tested.

BUG=none
BRANCH=none
TEST=Run cts.py -m i2c. Make buildall.

Change-Id: Ied77081ca0333ab3fec055cd4f0fcbdf8a79d388
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/393329
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-10-05 20:58:17 -07:00
Daisuke Nojiri
5f70312a26 i2c: Move I2C_MAX_HOST_PACKET_SIZE to i2c.h
This patch moves I2C_MAX_HOST_PACKET_SIZE to include/i2c.h. It's currently
used only by i2c-stm32*.c but should be commonly available for other chips.
It also moves i2c_get_protocol_info to common/i2c.c for the same reason.

BUG=none
BRANCH=none
TEST=make runtest

Change-Id: I28d8bca0167bb7b2ce99574601a6efb62fc20eca
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/393328
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-10-05 17:11:37 -07:00
Shawn Nematbakhsh
03857a3b35 spi: Add lock around spi_transaction
spi_transaction() can be called from motionsense, hooks, hostcmd,
console, and chipset tasks, so add a mutex to ensure an in-process
transaction isn't preempted by another transaction.

BUG=chrome-os-partner:57912
BRANCH=gru
TEST=On kevin, run "while true; do ectool motionsense odr 0 0; sleep 1;
ectool motionsense odr 0 1000000; sleep 1; done", verify watchdog crash
not encountered after 20 minutes.

Change-Id: I7ec495bab295dc03ce02372c20e5c7c5c196715d
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/391892
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit eabdea443775fab834aaabbb7afae871306c7530)
Reviewed-on: https://chromium-review.googlesource.com/392226
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-10-04 16:33:21 -07:00
Scott
9cd10a5a47 Cr50: Removed Reef EVT workarounds
- changed the pad assignment for plt_rst_l from DIOA13 to DIOM3;
- removed the board property used to keep uart rx disabled, Uart0 is
  now enabled by default on Cr50.
- removed resetting fallback counter on USB updates for reef boards,
  they are going to use the same mechanism as kevin and gru.

BRANCH=none
BUG=chrome-os-partner:56540
TEST=Tested on Reef Board ID 1 and Gru Board ID 1. Verfied that
     plt_rst_l signal is being detected and that there are no
     interrupt storms related to not having a pullup resistor on the
     uart rx line. Verified that both platforms successfully boot into
     chrome OS using cr50 TPM.

Change-Id: I300a0c75e60acbecf93500b46aced303955a192a
Signed-off-by: Scott <scollyer@chromium.org>
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/391140
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-10-04 05:55:50 -07:00
Vadim Bendebury
0f7d6806b7 i2cs: reset local variables when reinitializing.
When tpm is reset the i2c slave interface initialization function is
called, but it does not quite re-initialize the interface.

This patch adds both a hardware pulse to make sure that the i2c slave
interface state machine is set into the initial state, and code to
zero static variables of the driver.

BRANCH=none
BUG=none
TEST=with the change on the AP firmware side which prevents losing i2c
     ready interrupts early in the process tpm reset became much more
     reliable. Resetting from EC, AP of cr50 consoles reliably
     restarts reef without any TPM communications problems.

Change-Id: I604607c32d4dfc554b245d3d3d82b9ad38271962
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/392306
Reviewed-by: Scott Collyer <scollyer@chromium.org>
2016-10-04 00:33:58 -07:00
Bill Richardson
b5b06e4ac9 Cr50: fix CR50_DEV=1 override
Commit 9e7c12b added a command-line option to "make" to build
development versions of the Cr50 board. This makes the symbol
definition useful in makefiles and not just C code.

BUG=chrome-os-partner:57408
BRANCH=none
TEST=make buildall; try on Gru with and without CR50_DEV=1

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Id0719d63263b00e192a2e4866dbe1551ae49e23c
Reviewed-on: https://chromium-review.googlesource.com/391127
Commit-Ready: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-10-02 18:59:22 -07:00
Bill Richardson
fd88db3e9a g: CONFIG_FLASH should be optional
The application may need to read/write/erase the flash memory,
but we not want console users to do so. This CL adds
CONFIG_FLASH_PHYSICAL, which allows the higher-level CONFIG_FLASH
to be undefined while still providing the chip-specific
flash_physical_* accessor functions.

There aren't many board.h files that needed changes, since
CONFIG_FLASH_PHYSICAL is enabled by default, just like CONFIG_FLASH.

BUG=chrome-os-partner:57408
BRANCH=none
TEST=make buildall; try on Gru with and without CR50_DEV=1

See that it still boots, updates, wipes, restores, etc. without
linking common/flash.o in the production image; and that the
flash commands are still there in the dev build.

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: I7eb1bbcb414b1c70ee427c4fcb5cea899dbb9e93
Reviewed-on: https://chromium-review.googlesource.com/391188
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-10-02 15:19:21 -07:00
Bill Richardson
6356e17eef g: The hid command is only useful for debugging
And even that's a bit of a stretch. This entire endpoint will
probably be deactivated until it's more useful. In the meantime,
we can just leave the one little debug command for debug builds.

BUG=chrome-os-partner:57408
BRANCH=none
TEST=make buildall; try on Gru with and without CR50_DEV=1

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Id4c185fe66d52fa49fcbee6a549df41d297c41af
Reviewed-on: https://chromium-review.googlesource.com/391045
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-10-01 03:14:28 +00:00
Bill Richardson
fa7f71cd84 g: Remove the test_rdd command
The rdd features are working (and it's better to test with
hardware anyway), so just delete this command.

BUG=chrome-os-partner:57408
BRANCH=none
TEST=make buildall; try on Gru with and without CR50_DEV=1

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Ifcfc8c8a0e61a9fe31d28f0c96bcb50c3e2b93b5
Reviewed-on: https://chromium-review.googlesource.com/391314
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-10-01 03:14:17 +00:00
Sam Hurst
c0f9e3f411 npcx: pwm: Fix prescaler calculation
The pwm prescaler wasn't being calculated properly when used with
the 32 Khz clock.

BUG=chrome-os-partner:57526
BRANCH=none
TEST=Manuel
- With PWM frequency set to 100Hz, I verified on the scope that
  the duty cycle changed from 0 to 100% in 10% increments.

- Verified on the scope that PWM frequency could be set to 100Hz,
  200Hz, 300Hz, 400Hz, and  2600Hz.

Change-Id: Idf8ffb6b20d469c9ea58e5a34e944f79d475eb15
Reviewed-on: https://chromium-review.googlesource.com/388814
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-29 19:14:41 -07:00
Chris Chen
91d23fa94d stm32: Fixed bugs with stm32l4 register masks
Also filled out rest of CCIPR register defs
for stm32l4 chip family

BRANCH=None
BUG=None
TEST=make buildall

Change-Id: Ic9d1f966068915e304a0994c49fa9bbafec6cdf4
Reviewed-on: https://chromium-review.googlesource.com/367830
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2016-09-27 20:34:13 -07:00
Shawn Nematbakhsh
77a96c4b4d npcx: watchdog: Log watchdog panic information
On EC panic events such as assertion fail, watchdog, etc. log the EC
state to our persistent panic log so that it can be retrieved later.

BUG=chrome-os-partner:57794
BRANCH=Kevin
TEST=Run `crash watchdog` on kevin, then `panicinfo` on subsequent boot.
Verify saved panic log matches watchdog dump.

Change-Id: I06414f986458af1426b9b9720025144cd38a7a59
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/389591
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/389957
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-27 20:33:54 -07:00
Vadim Bendebury
5a6bb19a88 tpm: reset communications channels when resetting TPM
TPM resets happen asynchronously, conceivably there is some interface
(i2cs or sps) activity under way when TPM is reset.

Sps driver provides a means of disconnecting the client of the driver,
while the i2cs driver does not. Come to think of it, there is no real
need to provide a special function to disconnect a client, this makes
API simpler and allows to add driver initialization to the client
registration function.

To make tpm_registers.c more flexible - allow to register a callback
for interface initialization, this way when TPM is reset, the
interface can be also re-initialized and is guaranteed to start from
scratch after reset.

BRANCH=none
BUG=chrome-os-partner:52366
TEST=both firmware_TPMExtend and firmware_TPMKernelVersion autotests
     pass

Change-Id: I212166a23f9cd512d8f75315377d1f5620aea070
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388886
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-09-26 22:16:45 -07:00
Scott
672ea89dba Cr50: I2CS TPM: Prevent sleep when I2CS is active
Similar to the TPM SPI interface, added code to disable sleep an I2CS
interrupt is received. Enabling sleep follwoing a 1 second delay when
the TPM fifo register has been read by the host. The I2CS TPM layer
doesn't know when a command has finished, but the one second delay is
more than enough delay since sleep will be disabled again when the
next I2CS interrupt is received.

BRANCH=none
BUG=chrome-os-partner:40397
TEST=manual
Tested without these changes first. Shortened sleep delay to 30
seconds, and disconnected suzyq. Waited 30 seconds then issued the
command on the AP console:

tpmc read 0x1007 0xa
[   59.796813] tpm tpm0: tpm_transmit: tpm_send: error -16
ERROR: write failure to TPM device: Device or resource busy

In addition, using logic analyzer verifed that there was activity on
SDA/SCL but no response from Cr50. With this CL in place, ran the
test and got the following:

tpmc read 0x1007 0xa
2 0 1 0 1 0 0 0 0 4f

With the logic analyzer I was able to confirm that there was no
activity from the host on the I2CS bus until the command was issued.

Change-Id: If07573ae8f72b983bca57979d53c22660b91b95e
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/387910
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-09-25 17:47:29 -07:00
Scott
66ad05dfd7 Cr50: I2CS: Fixed i2cs word aligned fifo write function
Fixed an issue with word aligned write to fifo routine. There were two
errors. In the top section, the fifo was being read always from the
beginning word or the hw fito, but the updated word was written back
to the proper location.

The same error was in the section that dealt with the last < 4 bytes.
Both have been corrected. The error in the top section would in practice
be invisible because flow control prevents TPM fifo reads from
happening while one is in progress. The error in the bottom section
was responsible for the problem as described in chrome-os-partner:57782.

BRANCH=none
BUG=chrome-os-partner:57782
TEST=manual
Used special AP fw build that supports a 'tpm_raw' command to initiate
the Cr50 TPM fifo write/read.
'tpm_raw 0x80 0x01 0x00 0x00 0x00 0x16 0x00 0x00 0x01 0x7a 0x00
0x00 0x00 0x06 0x00 0x00 0x02 0x00 0x00 0x00 0x00 0x7f'
Without this CL, the 1st two bytes were incorrect ~50% of the time.
With the fix in place, verified that the first two bytes returned were
always correct.

Change-Id: Iff7620561eee463d599abfa6c07455c56bb5a5a6
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388785
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-09-25 17:47:27 -07:00
Vadim Bendebury
e5f8132483 cr50: make sure board resets when cr50 resets
cr50 should pretty much never reset, but when it does, for whatever
reason, the device it is running on must reset as well.

This patch makes every cr50 reset (be it command line induced, or
caused by an exception) a hard reset, such that it re-initializes the
R-box, which in turn causes reset of the entire platform.

CQ-DEPEND=CL:361680
BRANCH=none
BUG=chrome-os-partner:55948
TEST=verified that running commands like 'reset' or 'md 0xf0000'
     (which triggers an exception) causes the entire chromebook to reboot.

Change-Id: Ifa160450b9b4c5ef25e512caf1ffdced9c97acd6
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388007
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-09-24 16:22:39 -07:00
Randall Spangler
b94747d501 cr50: reset only the TPM state on SYS_RST_L
Rather than doing a full cr50 reset when the system reset SYS_RST_L is
asserted, just reset the state of the TPM task and library.  Re-clear
.bss for those modules, then re-initialize.

BRANCH=none
BUG=chrome-os-partner:52366
CQ-DEPEND=CL:366792
TEST=make buildall; test on Gru

Trigger a SYS_RST_L by using the AP's reboot command, power
off/on, log in/out/in.

See that the Cr50 does not reboot and the firmware and userspace
are still happy about the TPM.

Change-Id: I32cd2bb72316f68c74db77a20a8d09112b402d4b
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/361680
2016-09-24 13:53:26 -07:00
Shawn Nematbakhsh
5fa727805c npcx: gpio: Remove DEBUG_GPIO to make gpio_interrupt reentrant
GPIO interrupt priority levels can vary (notably, SHI CS interrupt is
higher) so gpio_interrupt must be reentrant.

BUG=chrome-os-partner:57434
BRANCH=Kevin
TEST=Stress test on kevin 'pd 1 reset' with OEM charger attached, verify
pdcmd task never gets wedged with TCPC ALERT stuck low.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: If853b80ebcef622480389a7cc94e851de0f8bb20
Reviewed-on: https://chromium-review.googlesource.com/388745
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit 011da7eb51c10a8e108bae0e489ff3ddc848ee33)
Reviewed-on: https://chromium-review.googlesource.com/388749
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-23 21:09:34 -07:00
Mulin Chao
a6525c9791 npcx: Selectively filter WDT reset in reset_flags
NPCX reboots by triggering the watchdog which in turn causes
the watchdog reset flag to be set as one of the system-wide
reset_flags. However, other software can confuse the presence
of the watchdog reset flag as a panic.

This patch selectively sets the watchdog reset flag only if we're
not explicitly doing a soft or hard reset or waking from hibernate.

Patch created by Mulin Chao <mlchao@nuvoton.com>

BUG=chrome-os-partner:56594
BRANCH=none
TEST=panic reset no longer observed

Change-Id: I016b59ffda4f6334cf41e196960edcbb87f6c049
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388853
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2016-09-23 21:09:18 -07:00
Aseda Aboagye
0567596eb1 system: Add print_system_rtc().
This commit adds a function that allows the real-time clock to be
printed on the EC console.  This could be helpful in trying to correlate
events between the EC's log and the kernel's.

BUG=chrome-os-partner:57731
BRANCH=gru
TEST=make -j buildall

Change-Id: I5e20692a173bddea3dc5c20cc0f2061cc170ce7d
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/388856
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-23 21:08:54 -07:00
Mary Ruthven
1ae3ffc608 cr50: use RXILVL to trigger fewer UART RXINTs
This change sets UART_FIFO_RXILVL to 3 for the AP and EC UART. With this
change RXINT will only be triggered when 4 characters are received
instead of for every character.

The change also flushes the RX FIFO whenever console input is received
through usb make sure to the user can see their input as they are typing.

BUG=none
BRANCH=none
TEST=run taskinfo after the system finishes booting.

	Before Change the IRQ count for 181 should be around 20000.
	After the change it should be around 5000.

	Use the AP and EC console over USB and verify there is no
        noticeable change in their usability.

Change-Id: I134ea0d2bc254038dad6c341b94f822adb90c000
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/387175
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-09-23 12:22:06 -07:00
Randall Spangler
818dea4a07 flash: Add command to get SPI flash chip info
Previously, there was no way to identify which flash chip was used by
the EC, for ECs using an external SPI flash.  Now, 'ectool flashinfo'
will print more information about the SPI flash chip in these cases.

BUG=chrome-os-partner:56765
BRANCH=any EC with MEC1322 or NPCX still going through factory
TEST=define CONFIG_HOSTCMD_FLASH_SPI_INFO, then
     'ectool flashspiinfo' on samus indicates no SPI flash info,
     and prints additional info on chell and kevin.  Without
     the config defined, all platforms report no spi flash info.
CQ-DEPEND=CL:386368

Change-Id: I3c162f7ad12ed4b30ab951c03f24476683382114
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/385702
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-23 12:21:51 -07:00
Furquan Shaikh
773c5db6d4 chip/npcx: Close LPC window before sysjump
Before performing a sysjump, ensure that:
1. LPC interrupts are disabled : Ensures interrupts are not taken until
next enable.
2. LPC window is closed by writing 0xfffffff8 to window base addresses:
Prevents any memory corruption by host.

BUG=chrome-os-partner:57642
BRANCH=None
TEST=Verfied that LPC communication works after sysjump to RW.

Change-Id: I7b7826b2544f1c94cfa9c96b6ac82bc3517b1820
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388755
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2016-09-23 12:21:29 -07:00
Furquan Shaikh
4a974141a5 chip/npcx: Fix interrupt enabling during lpc_init
1. interrupt enabling should be the last thing done when lpc_init
completes required intialization
2. memset to 0 of static uninitialized variables is not required. Remove
that.

BUG=chrome-os-partner:57642
BRANCH=None
TEST=Verified that LPC communication is fine after sysjump to RW.

Change-Id: Ib8891dccf2b301590ebca41b75680d954d88a4d3
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/388752
Tested-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2016-09-23 12:21:27 -07:00
Shawn Nematbakhsh
27a5f04632 npcx: shi: Clear EOR bit at start of legit transaction
Prevent EOR from cascading from one failed transaction to the next by
explicitly clearing it when CS is asserted.

BUG=chrome-os-partner:57563
BRANCH=Kevin
TEST=Package new EC image into recovery installer, verify recovery
completes without failure.

Change-Id: I44112f81cb712bb1e93fc10d2aff58f527e7a0fe
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/387236
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
(cherry picked from commit 50fc635fc8335df767e209488493d25e6548c641)
Reviewed-on: https://chromium-review.googlesource.com/387625
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-09-21 19:37:51 -07:00
Dino Li
0174d4f85b it83xx: EC sleep mode for system hibernate
The typical power consumption in sleep mode is 65uA.

IT83xx uses deep doze mode for low power idle task. The typical power
consumption in this state is 280uA (depends on EC tasks, it should be more)
and the wake up time is in microsecond. We are using deep doze mode for
low power idle task instead of sleep mode is because the wake up time
will be 6ms more.

While in system hibernate (EC sleep mode), EC won't wake up frequently so
we can keep the power consumption at 65uA.

Signed-off-by: Dino Li <dino.li@ite.com.tw>

BRANCH=none
BUG=none
TEST=- hibernate 0 [1|999999]
     - hibernate [1|5|10|600]
     - hibernate then press power button.
     - hibernate then lid open.

Change-Id: I94884c010264f01ede4950c6bb1b0a444d7b1e6d
Reviewed-on: https://chromium-review.googlesource.com/383332
Commit-Ready: Dino Li <dino0303@gmail.com>
Tested-by: Dino Li <dino0303@gmail.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-21 19:37:17 -07:00
Mulin Chao
7d430cde7e npcx: Fixed bug i2c sometime cannot generates NACK in Read Byte protocol
We should clear STASTR to release SCL only after NACK/STOP bits are set.
If an interrupt which priority is higher than i2c's issues at this moment,
i2c hardware might not generate NACK since SCL is already released by
clearing stall's pending bit.

Modified sources:
1. i2c.c: Fixed bug i2c sometime cannot generate NACK during Read Byte.

BRANCH=none
BUG=chrome-os-partner:34346,chrome-os-partner:57452
TEST=make buildall; passed "while(1); do; ectool i2cread 8 0 0x50 0x44;
done;" on reef.

Change-Id: I68ee5bf3d703cbe4fceefcfcc9afab9cb14bc2dc
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/386586
Commit-Ready: Kevin K Wong <kevin.k.wong@intel.com>
Tested-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-21 12:48:43 -07:00
Mulin Chao
7cb5f24596 npcx: flash: Lock mutex during flash operations
Lock mutex during mapped flash read and when issuing flash commands to
ensure no conflict between tasks.

BUG=chrome-os-partner:55781
BRANCH=Gru
TEST=Stress test flashrom, verify no verify failure occurs for 100 flashes.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I6036754dd4d84c45cd689ce5033d68c655431b14
Reviewed-on: https://chromium-review.googlesource.com/386419
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit 9123cc86c9fb15d8b9fbdcd4a93a785b37381fbe)
Reviewed-on: https://chromium-review.googlesource.com/386448
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-16 21:59:11 -07:00
Shawn Nematbakhsh
def0a47cee npcx: shi: Enable SHI interrupt from CS interrupt
Enable the SHI interrupt only after we have received and begun
processing our host command. Disable the SHI interrupt once our
transaction is complete (with either success or error status). This will
prevent the SHI interrupt from being asserted at the same time as the CS
interrupt, which can lead to the SHI interrupt being serviced first.
Also, it avoids needless, non-useful SHI interrupts during error
transactions.

BUG=chrome-os-partner:55710,chrome-os-partner:55795,chrome-os-partner:56254
BRANCH=None
TEST=Manual on gru. Stress test flashrom w/ unpowered Donette attached
(for host command spam), verify no errors encountered after 100 minutes.
Also verify host command interface functions properly after sysjump.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/384583
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit 668763721aab31a102ead348d7cfe1c72f50cb71)

Change-Id: I7292d1b34d3e1c71628a8b5d663ce9fd865493f4
Reviewed-on: https://chromium-review.googlesource.com/386447
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-16 21:59:09 -07:00
Shawn Nematbakhsh
fd41823595 flash: Call lock function prior to mapped external read
Mapped read access to external flash may conflict with direct access
through SPI commands, so call a chip-level function to lock access prior
to doing such reads.

BUG=chrome-os-partner:55781
BRANCH=Gru
TEST=Verify 'ver' still works fine on kevin, and vboot hashing completes
successfully.

Change-Id: I009d6d5ee61c83260fb49ad4ee137fa3f4cd625a
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/385165
Tested-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
(cherry picked from commit a7f3e3fa376731709f4823a0c1d464b4d1deae14)
Reviewed-on: https://chromium-review.googlesource.com/386446
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-16 21:59:08 -07:00
Bill Richardson
f2dba9d779 g: Add support for hardware dcrypto
BUG=chrome-os-partner:54101
BRANCH=none
CQ-DEPEND=CL:*287736
TEST=make buildall; try on Cr50 hardware

All TCG tests passed before and after this CL.

Change-Id: I65e31792b2912d588868cc298a01b0142ac7dadc
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/386258
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-09-16 19:56:34 -07:00
Mary Ruthven
17aa84b8b8 cr50: enable deep sleep on chipset shutdown
On CHIPSET_SHUTDOWN set the idle_action to deep sleep. If sleep is
enabled it will go into deep sleep. If not it will wait until sleep is
sleep is enabled.

This change also sets the idle_action to IDLE_DEFAULT when resuming from
deep sleep or during init. Before cr50 kept track of the previous idle
state in a PWRDN register and then used that state during the next
resume. If we went into deep sleep, on resume we want the idle action to
be reset to sleep and then only enter deep sleep if we have detected the
AP is off.

BUG=chrome-os-partner:56100
BUG=chrome-os-partner:55747
BRANCH=none
TEST=manual
	run 'poweroff' on the AP and see that cr50 enables deep sleep

	verify that even if the ap is powered off it doesn't prevent ccd
	from working and when suzyq is unplugged cr50 will go into deep
	sleep

	After running poweroff on the AP wait a while and run powerbtn
	on the EC. Verify the system can boot up fully without going
	into recovery.

	Do this on gru and reef.

Change-Id: I07f5a9d85dd0467cd22e499d4261c75caf653563
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/373139
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-09-16 17:43:32 -07:00
Mulin Chao
a4c2b141f8 npcx: Fixed bug that api utility in ROM doesn't enable burst mode.
We found the api utility in ROM doesn't enable burst mode of GDMA. It
influences the performance of FW download a lot. The CL modified GDMA
for moving the code of the other region from flash to ram. And move a
function that kicks off GMDA transactions to suspend ram in case this
utility is erased by itself. This issue will be fixed in our next
generation.

Modified sources:
1. system.c: Implement GDMA bypass.
2. system_chip.h: Import flash addresses for GDMA bypass code.
3. registers.h: Add GDMA register definitions.
4. cortex-m/ec.lds.S: Add lowpower_ram2 section in linker script.

BRANCH=none
BUG=chrome-os-partner:56794
TEST=make BOARD=npcx_evb; test sysjump and measure download time

Change-Id: I8490f8f2e5a8cdcb6fd10511878c4a4af8073bbf
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/381779
Commit-Ready: Shawn N <shawnn@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-09-15 16:16:22 -07:00
Bill Richardson
9e7c12b74e Cr50: #define CR50_DEV in source when used manually
We want the default build to be ready for production use, without
any unlocked security features, development-only tests, etc.

Running "make buildall" or "make BOARD=cr50" builds the
default (production) image.

To build a development image, use

  CR50_DEV=1 make BOARD=cr50

This CL adds "-DCR50_DEV=$(CR50_DEV)" to the CFLAGS for use in
compiled code.

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

Verify that

  #ifdef CR50_DEV
    [stuff]
  #endif

works inside C code.

Change-Id: Id5e16e9ba0135828f4365fc1ac4a23384f30ba01
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/385059
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-09-13 22:22:25 -07:00