Commit Graph

1147 Commits

Author SHA1 Message Date
Shawn Nematbakhsh
6ee7b1e34e ACPI: Support accessing memmap data over ACPI CMD / DATA ports
Some platforms are unable to access the 900h-9ffh region over LPC and
must instead access memmap data through the ACPI CMD / DATA ports. To
avoid racing with data updates, disallow changes to multi-byte memmap
data while in burst mode.

Linux currently enables burst mode when accessing multi-byte data and
disables it immediately afterward, though the ACPI spec defines burst mode
in a more general way.

BUG=chrome-os-partner:38224
TEST=Manual on Samus. Undefine LPC_MEMMAP and modify asl to move memmap
data to ERAM at offset 0x20. Verify system boots cleanly and battery
status is updated immediately on plug / unplug.
BRANCH=None

Change-Id: Ib848bdb491fdfece96ad0cee7a44ba85b4a1a50b
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/262072
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-03-25 20:09:52 +00:00
james_chao
0db4de8d68 charger: Add support for bq24770
Add support for bq24770 (smbus) in the bq24773 (i2c) driver.

BUG=None
TEST=Use the UART command "charger" and check the charger information.
BRANCH=None

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ie5f5af60e93aa73d9ef68115af36a8d28f6d6c2b
Reviewed-on: https://chromium-review.googlesource.com/259870
Reviewed-by: BoChao Jhan <james_chao@asus.com>
Reviewed-by: Divya Jyothi <divya.jyothi@intel.com>
Commit-Queue: Divya Jyothi <divya.jyothi@intel.com>
Tested-by: Divya Jyothi <divya.jyothi@intel.com>
2015-03-24 18:26:25 +00:00
Anton Staaf
4002d66297 USB-SPI: Set the interface SubClass to Google SPI
This SubClass will provide a simple mechanism for
host tools to discover SPI bridge enabled devices.

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

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

Change-Id: I0c800ca7b1a2ac58584eab8ba201a6b2a5a894ea
Reviewed-on: https://chromium-review.googlesource.com/260963
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2015-03-23 19:23:32 +00:00
Sheng-Liang Song
3f061f1864 cr50: Added macros for register read/write
Added macros for register read/write.

BRANCH=none
BUG=chrome-os-partner:33815
TEST="make buildall -j; Verified on RevA1 chip"

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

Change-Id: I25c6f6b5865c7fdde002b2191b1f2eaaba15f589
Reviewed-on: https://chromium-review.googlesource.com/236402
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Sheng-liang Song <ssl@chromium.org>
Tested-by: Sheng-liang Song <ssl@chromium.org>
2015-03-20 23:06:58 +00:00
Shawn Nematbakhsh
746debdf20 spi_flash: Rework protection translation functions
Previously we defined separate functions to map registers to protect
ranges for each supported SPI ROM. This change instead adds a protect range
table + flags for each supported SPI ROM and adds common functions for
translation between ranges + registers. This makes supporting new parts
easier. Since we will never use most supported protection ranges, we can
even simplfy the tables.

The implementation is now similar to flashrom.

BUG=chrome-os-partner:37688
TEST=Manual on Glower.
flashwp disable  + spi_flash_rsr --> 0
flashinfo --> shows no protection
spi_flash_prot 0 0x10000 + spi_flash_rsr --> 0x24
flashinfo --> shows 64KB protected
spi_flash_prot 0 0x20000 + spi_flash_rsr --> 0x28
flashinfo --> shows all 96KB protected
spi_flash_prot 0 0x40000 + spi_flash_rsr --> 0x2c
spi_flash_prot 0 0x80000 + spi_flash_rsr --> 0x10
spi_flash_prot 0 0 + spi_flash_rsr --> 0x00
spi_flash_prot 0 0x1000 --> error
spi_flash_prot 0x10000 0x10000 --> error
BRANCH=None

Change-Id: Ie5908ce687b7ff207b09794c7b001a4fbd9e0f5a
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/259310
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-17 01:42:30 +00:00
Shawn Nematbakhsh
90ef8b7006 lm4: stm32: Store panic data in backup registers on hard reset
On hard reset / hibernate, RAM will be erased and panic data will
normally be lost. When software panic data saving is enabled, try to
save this data just before hard reset and restore it when we come back
up.

BUG=chrome-os-partner:37380
TEST=Manual on Samus with WP + SW sync enabled. Boot AP, then run "crash
divzero" on console. After hard reset, verify that "panicinfo" dumps
data and shows divzero exception code.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I9516dd4b6db12ef35e512cc4710f9b97d7e663cb
Reviewed-on: https://chromium-review.googlesource.com/255912
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-14 03:22:37 +00:00
Vincent Palatin
4c75ac48d3 pd: make source-only PD devices compatible with the common runtime
Add the proper checks to be able to compile source-only PD devices with
the common runtime.

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

BRANCH=none
BUG=chrome-os-partner:37078
TEST=make buildall
build honeybuns without CONFIG_USB_PD_DUAL_ROLE defined

Change-Id: I7ad0b39b2e62736117ec2d7b5163502afbf14786
Reviewed-on: https://chromium-review.googlesource.com/259112
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2015-03-13 03:40:49 +00:00
Shawn Nematbakhsh
27199e7b64 spi_flash: Add protect support for W25X40
W25X40 uses a different protection register encoding than our existing
W25Q64 code. Move the SPI ROM option to a config, and add support for
the new part.

BUG=chrome-os-partner:37688
TEST=`make buildall -j`. W25X40 protection code tested in a subsequent
commit.
BRANCH=None

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Iaaeabf42c6c62c20debc91afd2cf8671c14244c8
Reviewed-on: https://chromium-review.googlesource.com/258440
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-11 23:18:09 +00:00
Alec Berg
d09405203f samus: ryu: allow charge ramp on CDP and proprietary chargers
Modify charge ramp so that when it ramps it ramps from 500mA and
up to the maximum allowed by that supplier. Also modify Samus and
Ryu to use charge ramping for CDP and proprietary chargers due
to the possibility that they may not be able to supply the amount
that is supposed to be guaranteed by their advertisement.

BUG=chrome-os-partner:37549
BRANCH=samus
TEST=test on a proprietary charger, make sure we can ramp. test
a DCP and make sure we also ramp as before.

Change-Id: I08fd43c8f0b21aa54d114fbe5a1296c9556357e4
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256972
Reviewed-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
2015-03-07 03:38:38 +00:00
Alec Berg
4e58d5c46a samus: change tap for battery to not show dimmed last segment
Change tap for battery lightbar sequence to not show the last segment
dimmed as a percentage of your battery.

BUG=chrome-os-partner:37335
BRANCH=samus
TEST=use battfake console command to test out every increment of 10%
and use "lightbar seq tap" to show tap.

Change-Id: I4f38d26a8cfbecfa6efc86fcc8751ca8cb34879b
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256191
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-03-06 08:48:50 +00:00
Alexandru M Stan
d0ec94203f motion_sense: Add required header
include/motion_lid.h is generally included by board.c in the various boards.
But include/motion_lid.h actually needs host_command.h defined or else
including it in board.c will cause a confusing error.

This probably doesn't show up on other platforms like samus and glimmer
because they define a few custom commands in board.c, but veyron
doesn't need that. motion_lid ought to just include it directly if it really
needs it.

BUG=None, see next commits in the series, they won't compile without this
TEST=See series
BRANCH=veyron

Change-Id: I42e966d891dbbcca7df484b59c9d1bb35d1357bc
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256696
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2015-03-06 08:48:39 +00:00
Alec Berg
7cbc5a0186 samus_pd: disable i2cxfer console command to save space
Disable the i2cxfer console command by default to save space

BUG=chrome-os-partner:37167
BRANCH=samus
TEST=make -j buildall
From .map file, 576 bytes of flash saved

Change-Id: I0b50161ef0a49231e45c422da5042db77874aed1
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256071
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2015-03-06 03:50:43 +00:00
Todd Broch
5e9eb3263d pd: Bugfix for write log entry command.
BRANCH=samus
BUG=chrome-os-partner:37264
TEST=manual,

ectool --name cros_pd pdsetmode 0 0xff01 1 0 successfully exits displayPort
mode again.

Change-Id: Ica2faf8de92460f01c2af9be829795c0cd538135
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/254990
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-03-02 10:06:30 +00:00
Randall Spangler
16eec7f14c Remove unused CONFIG_PSTATE_AT_END option
All current boards in ToT place pstate at the end of the RO section.
Remove the unused option to place it at the end of the RW section;
we'll never do that again.

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

Change-Id: I0d279a4c9786bb33367a7387423481cc9b94e115
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/253636
Reviewed-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-02-27 19:56:47 +00:00
Shawn Nematbakhsh
c7bc5965fa charge_manager: Classify VBUS supplier type
Add a new supplier type for VBUS chargers (USB chargers which supply VBUS
but are not identified as another charger type).

BUG=chrome-os-partner:37168
TEST=Manual on Samus with subsequent kernel commit. Modify code to
reject all non-VBUS suppliers, charge with SDP port, and verify charge
icon appears in OS.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I5fbdb1cb57bd0224b01aaf5a763f93b678b6d204
Reviewed-on: https://chromium-review.googlesource.com/254346
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-27 02:21:25 +00:00
Randall Spangler
6aebf13a6b Add CONFIG_FLASH_PSTATE option to enable persistent flash WP state
Previously, the flash module assumed it needed to emulate a SPI write
protect register using a bank of flash to hold the persistent flash
write protect state.  This is not true for mec and ncpx chips under
development, which use external SPI flash.  So, gate that code with
CONFIG_FLASH_PSTATE.  For compatibility, leave it on by default (as we
do with CONFIG_FLASH_MAPPED).

There is no change to the behavior of currently supported chips, since
all of them already assume pstate is present.  Removing this feature
from npcx will be done in a subsequent change.

BUG=chrome-os-partner:34346
BRANCH=strago
TEST=make buildall -j; verify flash wp and flashinfo work properly on samus

Change-Id: Ie044eb042863e4a7359ea540166ffd8d0089589d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/253632
Reviewed-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2015-02-26 20:31:51 +00:00
Todd Broch
e20d019fc4 pd: Massage initialization at task start.
Refactoring effort to unify the set of PD intialization tasks that
need to occur.  Those areas include:

  1. host mode as it relates to power & pull-ups/downs
  2. PD tx init
  3. PD mux settings

Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:36481
TEST=manual,

1. compiles and functions on samus_pd
2. If sysjump w/ dongle connected than alternate mode re-entered
   properly including muxing and HPD

Change-Id: I47f32acaeccbd7745e1e01a8b085b1804c4c5000
Reviewed-on: https://chromium-review.googlesource.com/249273
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
2015-02-25 03:33:12 +00:00
Shawn Nematbakhsh
a8628526a3 panic: Send host event on panic detect
If a panic caused us to reboot, send a host event to notify the AP.

BUG=chrome-os-partner:36985
TEST=Manual on Samus. Trigger EC panic, verify that "Panic Reset in
previous boot" is seen in /var/log/eventlog.
BRANCH=Samus

Change-Id: Icf0d00a8cfc7aa788f3ceadd65fe3139f40df503
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/252410
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-24 03:08:03 +00:00
Anton Staaf
1a0235e69f Streams: Define a lower level abstraction for queue access
This adds a new pair of interfaces called producer and consumer
which are simpler (in that they don't hold onto the underlying
queue) than the stream interfaces.  This makes it easier to
share a single queue between the endpoints that will manipulate
it.  It was not possible to share a queue between two objects
that implemented the in_stream and out_stream interfaces.

This also adds a pair of adaptors that can convert a producer
or consumer into a stream of the correct type.  These adaptors
will be used for existing code once the usb-stream and usart
drivers are converted over to use the producer/consumer
interfaces instead of the stream interfaces.

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

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

Change-Id: I42b4b1ac15cca28e1adc6d3cea315f15e17a0b4d
Reviewed-on: https://chromium-review.googlesource.com/250941
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2015-02-24 00:27:50 +00:00
Alec Berg
fc144e940c samus_pd: make shmem command optional, disable on samus_pd
To save flash space, disable "shmem" console command on samus_pd
to save 128 bytes.

BUG=none
BRANCH=samus_pd
TEST=make-j buildall

Change-Id: I0d0277a0c4a80dffd90dcbf2c3ee77eba2408c57
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/251911
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-02-24 00:27:42 +00:00
Vic Yang
1ef0f27e65 stm32f3: Allow per-board ADC sampling time
Depending on the hardware, each ADC channel may need a different
sampling time. To keep things simple, let's allow per-board ADC sampling
time configuration instead of per-channel configuration.

BRANCH=Ryu
BUG=None
TEST=Configure sampling time to 3 and measure IADP on Ryu P4 and check
it's more accurate.

Change-Id: I3c1eeea22439c0340f84fdeb3624fc84450358ca
Signed-off-by: Vic Yang <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/251701
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
2015-02-21 09:19:57 +00:00
Myles Watson
db19a8e2c9 common: Add the possibility to filter UART input
Add CONFIG_UART_INPUT_FILTER, which is undefined by default.

BUG=chrome-os-partner:36745
TEST=buildall for the case where it is not defined.
Added a filter function to the btle code on hadoken.
Tested reset, transmit test, receive test, test end, and test mode end.

BRANCH=None

Signed-off-by: Myles Watson <mylesgw@chromium.org>

Change-Id: I3a9c067ffcb114449b61f468271a48491a8c7ec5
Reviewed-on: https://chromium-review.googlesource.com/250580
Tested-by: Myles Watson <mylesgw@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Myles Watson <mylesgw@chromium.org>
2015-02-21 00:49:36 +00:00
Bill Richardson
02013f6aa3 cr50: Separate ARM core GPIOs from pinmux configuration
This separates the configuration of the ARM core GPIOs from the
routing of internal peripherals to external pins. Both are still
described in the gpio.inc file, but are less dependent on each
other.

BUG=chrome-os-partner:33818
BRANCH=none
TEST=manual

Before this CL, running "sysjump rw" or trying to use more than 8
GPIOs caused hangs and reboots. Now it doesn't.

Change-Id: If962a7c5ad4136837b2ea00ae016a440f07d7e23
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/251015
Reviewed-by: Sheng-liang Song <ssl@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-20 03:00:04 +00:00
Bill Richardson
b4274d04f3 cleanup: bitmasks should be unsigned values
Change the struct gpio_info to use uint32_t for the mask field,
instead of signed integer.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: I8cc7e3d06a00bd3c890522a896e36e1eb18a862e
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/251013
Reviewed-by: Sheng-liang Song <ssl@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-20 02:59:57 +00:00
Alec Berg
02d0ce1526 samus: panic reboot EC if PD MCU crashes
Use the EC to check if PD MCU has crashed. The EC knows this
by checking the PD status bits: if PD MCU was in RW, and is
now in RO, AND it did not get to RO via a sysjump, then it
must have crashed. When the EC detects this, the EC will also
panic and reboot the entire system, so that we can software
sync to a known good state.

Also, when EC panics due to PD crash, it will log panic info.

BUG=chrome-os-partner:36636
BRANCH=samus
TEST=load onto samus EC and PD, try sysjump'ing back and forth
on PD MCU console and verify EC does not do anything. Crash
the PD MCU when in RW by reboot command and crash divzero command,
and make sure the EC panics with PD crash panic message. Crash
the PD MCU when in RO (before sysjumping to RW) and make sure
EC does not panic.

Change-Id: I57961028e6b23a878b8e477a9d8e180cb121a742
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/250100
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-02-18 04:53:59 +00:00
Shawn Nematbakhsh
d008477824 cortex-m*: Save panicinfo on non-exception panics
Make non-exception "software" panics such as stack overflow and assert
failure save a panic log. Log the panic type in r4, and misc. panic data
in r5 so that panic reasons can be distinguished.

BUG=chrome-os-partner:36744
TEST=Manual on samus_pd. Run 'crash divzero' then 'panicinfo' after
reboot. Verify that panic info is printed with "r4 :dead6660". Trigger
stack overflow, verify that panic info is printed with "r4 :dead6661".
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I5f7a8eb0a5c2ac5799d29bb241deb24fabf38f68
Reviewed-on: https://chromium-review.googlesource.com/249912
Tested-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-18 04:53:51 +00:00
Bill Richardson
d64bb99149 samus: Only update fan speeds every N seconds
This adds CONFIG_FAN_UPDATE_PERIOD to limit the frequency at which
the fan speeds are updated. Short version: the CPU core temp
fluctuates rapidly, causing the fans turn off and on annoyingly
often (assuming you have good hearing and are in a quiet room).

With this CL, we limit the speed changes to only once every N
seconds. N should be long enough to be less annoying, yet short
enough that the CPU doesn't overheat while we're not looking.

BUG=chrome-os-partner:34789
BRANCH=ToT,samus
TEST=manual

Let it sit quietly, then visit a busy webpage, then let it sit a
while. The fan speed should only change every 10 seconds or so,
not every second.

Change-Id: Id985350394f24d56dc4a1e51af09487ac643285b
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/250501
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-02-18 04:53:30 +00:00
Alec Berg
a573a6c0fd charge_ramp: initial commit of charge ramp module
Add new charge_ramp module which works with charge_manager to
slowly increase input current limit in order to find the optimal
charging current. To do this it looks for either VBUS drooping
too low or for the charger to over-current.

BUG=chrome-os-partner:34946
BRANCH=samus
TEST=tested with a variety of BC1.2 chargers, type-C only chargers,
and PD chargers to make sure we always stabilize charging at an
appropriate current limit.

Change-Id: Icc95aa2738ddb221f163f91c14a342a0674f9e0f
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247304
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-02-18 04:53:22 +00:00
Alec Berg
aaa7625681 samus: disable i2cscan console command to save space
Disable the i2cscan console command by default to save space

BUG=none
BRANCH=samus
TEST=make -j buildall
From .map file, 512 bytes of flash saved

Change-Id: I4bcb50b00e843abbc3523a3e0d4cc599a1e01d3a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/249850
Reviewed-by: Vic Yang <victoryang@chromium.org>
2015-02-18 04:52:56 +00:00
Vincent Palatin
4b774f07d3 make idlestats console command optional
To save flash space, disable "idlestats" console command on samus_pd.
This saves 384 B of flash

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

BRANCH=samus
BUG=chrome-os-partner:34489
TEST=make buildall and check firmware size.
=== build/samus_pd/ BASELINE ===
FLASH 57.8k / 60.0k  [ text 48.0k rodat  9.7k data  0.1k ]
RAM   11.8k / 16.0k  [ data  0.1k bss   11.7k ]

=== #undef CONFIG_CMD_IDLE_STATS ===
FLASH 57.4k / 60.0k  [ text 47.9k rodat  9.4k data  0.1k ]
RAM   11.8k / 16.0k  [ data  0.1k bss   11.7k ]

Change-Id: Iba9654a88ec195026945881bc2687a1e67747706
Reviewed-on: https://chromium-review.googlesource.com/241452
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
2015-02-18 04:52:49 +00:00
Shawn Nematbakhsh
96536de3f4 pd_log: Add command to request PD MCU to write a log
When we find that charging is in a wedged state, we may wish to write a
PD log entry, but the PD MCU cannot detect such a state on its own.
Therefore, add a new command to ask the PD MCU to write a log of a given
type, and add a new board-specific custom log event.

BUG=chrome-os-partner:36668
TEST=Manual on samus:
./ectool --dev=1 pdwritelog charge 0
./ectool --dev=1 pdwritelog charge 1
./ectool --dev=1 pdwritelog 1 0
./ectool --dev=1 pdwritelog 2 0
./ectool --dev=1 pdlog
Verify log output matches expectation:
2015-02-12 11:12:49.290 P0 SRC
2015-02-12 11:12:49.296 P1 SNK Charger PD 20286mV max 20000mV / 3000mA
2015-02-12 11:12:49.303 P0 New connection
2015-02-12 11:12:49.310 P0 Board-custom event
--- END OF LOG --
Also, verify kernel logging of wedged event:
[  181.378420] PDLOG 2015/02/12 19:13:44.019 P0 Event 02 (0000) []
Also, trigger wedged state on Samus and verify log entry is written.
BRANCH=Samus
Change-Id: I55c7c839cf8300fcd3931dccdaaf16c1065e31a8
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/248981
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-12 23:08:45 +00:00
Alexandru M Stan
80778ad0eb cortex-m0: Add deferred scheduler
If 2 interrupts happen at the same time, there is a chance that the nested
interrupt will not call svc_handler when it needs to. In extreme cases this
could lead to tasks not getting woken up when they're supposed to and watchdog
resetting.

The reason stuff worked was because there were enough other interrupts
around to eventually call the scheduler and switch to the ready task.

This change modifies the interrupt calls to not call the scheduler directly
(because in nested interrupt situation this causes problems), but defer the
call to scheduling until after the irq finishes by triggering a low priority
interrupt which will for sure call svc_host at the end. The PendSV irq was
used for this purpose.

BUG=chrome-os-partner:36193
TEST=No more SPI errors caused by scheduler problems
TEST=usleeps now are more accurate, they're guaranteed to not take forever now
BRANCH=veyron

Change-Id: I42acde6b3eb7be2540a0de9a8562dee2ea2be7ab
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/248902
Tested-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
2015-02-12 06:44:04 +00:00
Shawn Nematbakhsh
ea3dbb98b4 charge_manager: Minimize log spew
Previously, we tried to minimize log spew by keeping track of previous
log entries and not writing new entries in some cases. Instead, we can
write a log on the following events only:

1. A port becomes active or
2. A port becomes inactive or
3. The active charge port power limit changes or
4. Any supplier change on an inactive port

Also, make charge_manager_save_log a non-static charge manager API
function, so that other modules can record a log, if they have reason to
believe a port has changed outside of a charge manager change.

BUG=chrome-os-partner:33248
TEST=Manual on Samus. Make various power actions and observe logging.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I5d5d3e186e85fdb1c59797ffbfb2f5a6ec04d94d
Reviewed-on: https://chromium-review.googlesource.com/247891
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-11 04:48:37 +00:00
Shawn Nematbakhsh
c1fe8f2173 charge_manager: Store dualrole capability in charge manager
Since charge manager is now informed of all capability changes as they
happen, it makes sense to store the port capability within charge manager,
rather than storing in pd.

BUG=chrome-os-partner:36390
TEST=Manual on Samus. Insert 1A Apple charger, verify correct detection.
Run 'chgoverride -2' to prevent charging, then repeatedly insert +
remove a dual-role charger on the other charge port. Verify that
charging is still prevented. Finally, insert a dedicated charger and
verify that the override is removed. Also, pass unit tests and verify
correct detection in various scenarios with various chargers.
BRANCH=Samus

Change-Id: I3669050b37ddd67f6608bf790a07e74f86b6ac01
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247724
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-11 04:48:32 +00:00
Anton Staaf
5444205f79 CCD: Remove CCD specific board connect and disconnect
Previously the Case Closed Debugging system provided a
way for the board to connect and disconnect the CCD USB
lines correctly, but this functionality is better
implemented by board_set_usb_mux.

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

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

Change-Id: I697ee9740c64ac93557d9fca8b2d10e858c51193
Reviewed-on: https://chromium-review.googlesource.com/247721
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2015-02-10 23:07:16 +00:00
Alexandru M Stan
6136b1fb09 Power Button: Wait for power button to be stable when waiting for release
The debounce timer might be too slow to actually update the state of
debounced_power_pressed by the time we do power_button_is_pressed in the S3->S5
state transition. Solution is to move the power_button_wait_for_release function
here and make sure there are no deferreds active.

BUG=chrome-os-partner:35948
TEST=During dev mode screen, press power button, note the device stays off
TEST=Print debounced_power_pressed in power_button_is_pressed(void), note it's
not 0 when power button is actually pressed
BRANCH=veyron

Change-Id: I8258e9e5524bd65d6ea9c77ea5649304d2195bf0
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244590
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-10 23:07:14 +00:00
Vic Yang
049463f8ad stm32: Add delay after enabling peripheral clock
We need a dummy read after enabling AHB peripheral clock before we can
access the peripheral. For APB, we also need a dummy read for STM32F3.

BRANCH=All affected
BUG=chrome-os-partner:33007
TEST=make buildall

Change-Id: I47f4a024dca294f555428c3f2053c1d32835ebe0
Signed-off-by: Vic Yang <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/246181
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
2015-02-10 10:47:07 +00:00
Shawn Nematbakhsh
96895743b0 charge_manager: Wait for dualrole determination before charging
If a dual-role charger is plugged, we will not realize it is dual-role
until after we see a type-C charge source. It can cause us to briefly
charge from a dual-role charger, which has bad side effects related to
charge override and the lightbar. Fix this by not charging from a port
until we are fairly certain that it is a dedicated charger (based upon
PD discovery timeout).

BUG=chrome-os-partner:36390
TEST=Manual on Samus. Insert 1A Apple charger, verify correct detection.
Run 'chgoverride -2' to prevent charging, then repeatedly insert +
remove a dual-role charger on the other charge port. Verify that
charging is still prevented. Finally, insert a dedicated charger and
verify that the override is removed. Also, pass unit tests and verify
correct detection in various scenarios with various chargers.
BRANCH=Samus

Change-Id: Ia4154f34dd0a850b6e72bebadbd938f034532f14
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247130
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-08 03:27:51 +00:00
Randall Spangler
f8af89c40d Support vboot hash and system version if flash isn't memory-mapped
Some EC chips (mec1322) use external SPI flash which is not mapped
into the EC CPU's address space.  These must explicitly read data from
flash when calculating the vboot hash or reading the version string of
the image which isn't currently loaded into code RAM.

To test this bug, I used a board with known working mapped flash, and
temporarily patched it to act like it didn't have mapped flash.

Also add a flashread console command, useful for manually testing.

BUG=chrome-os-partner:35308
BRANCH=glower,strago
TEST=manual
	1. Apply this patch to samus
	2. Check result for 'vboot hash RW'
	3. Check result for 'version'

	4a. In board/samus/board.h, #undef CONFIG_FLASH_MAPPED and
            #define CONFIG_CMD_FLASH
	4b. In chip/lm4/flash.c, add the following:

	int flash_physical_read(int offset, int size, char *data)
	{
		const char *src;
		if (offset > CONFIG_FLASH_SIZE ||
		    offset + size > CONFIG_FLASH_SIZE)
		return EC_ERROR_INVAL;

		src = (const char *)((uintptr_t)CONFIG_FLASH_BASE + offset);
		memcpy(data, src, size);
		return EC_SUCCESS;
	}

	Steps 4a,4b will make the LM4 chip act like it doesn't have
	memory-mapped flash.

	5. From the dev system, util/flash_ec --board=samus --ro
	6. Check result for 'vboot hash RW'.  Should be same as 2.
	7. Check result for 'version' for RW version.  Should be same as in 3.
	8. From the dev system, util/flash_ec --board=samus
	9. sysjump rw
	10. Check result for 'version' for RO version.  Should be same as in 3.
	11. Compare 'flashread 0x100 0x100' with 'md 0x100 0x40'.  The results
            should be the same (but endian-swapped, since flashread is byte
	    ordered and md is 32-bit ordered).
	12. Revert changes from steps 4a-4b.

Change-Id: I951d6f5603a84e326740936e4e84dfe6296a0f59
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246200
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-02-05 21:03:01 +00:00
Randall Spangler
fd6a6900f7 Convert motion sense calculations to fixed point.
Motion sense calculations do not require huge amounts of precision, so
fixed point is plenty accurate.  And fixed point works on Cortex-M0,
which lacks a FPU.

BUG=chrome-os-partner:36126
BRANCH=minnie (samus already works with the FPU, but could grab this if we
       want additional testing)
TEST=manual
    1. Boot system
    2. At EC console: accelinfo on 250
    3. Move lid through several different angles (30 degrees to max open) and
       see that it updates correctly and relatively smoothly.  A few degrees
       of angle jitter is normal.
    4. At several angles, rotate the chromebook around and see that the lid
       angle remains relatively stable.
    5. If the hinge is made normal to the ground (or within 15 degrees of
       vertical), the angle should read 500, since the acceleration vectors
       don't yield good results in that orientation (for either fixed or float
       math).
    And run 'make buildall -j', which tests arc_cos() and lid angle calculations

Change-Id: I70a0d08b8914629a3e21ae5578cbe8e50f29ad68
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244116
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-02-05 19:41:41 +00:00
Alec Berg
19b6e5da23 samus: fix lightbar tap sequence doesn't always show on AC event
Fix bug on samus that the battery status doesn't always show on
lightbar when AC is plugged/unplugged. It doesn't show when the
battery is full is S3 or S5 because in these states we turn off
CHARGE_EN so that ACOK to the EC never toggles.

Instead, what we want to do is display battery status whenever the
active charge port changes. This will happen when AC is plugged or
unplugged OR if a user has AC on both ports and toggles between
them using the charge override hot-keys.

BUG=chrome-os-partner:36317
BRANCH=samus
TEST=test plugging and unplugging AC on both sides when battery is
full and unit is in S0, and when unit is in S5. also tested lightbar
flashes battery percentage when two zingers are plugged in and you
switch between them using Ctrl+Search+0|1|2.

Change-Id: I5cd7fff4f466adf857f1e63f07f3b0c7ae8422c7
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245922
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-02-04 23:32:37 +00:00
Alec Berg
fd9dd63e5c samus: automatically recover from charge circuit failures
Occasionally the charge circuit on samus gets wedged and will not
charge. This change detects when the charge circuit has failed
and automatically recovers from it. It uses the BQ PROCHOT warning
to detect the failure by setting PROCHOT to trigger when the BQ
thinks input current is higher than the input current limit. When
the failure is detected, the EC disables charging and tells PD MCU
to disable CHARGE_EN, then a couple seconds later, it re-enables
charging.

This CL also adds more communication between EC and PD for the EC
to be able to set the charge state for the PD. Valid charge states
are: No charging allowed, 5V charging only, and max charging. The
EC uses this as such:
- When the EC gets AC present interrupt, it sets off a deferred
function to change charge state to max charging after some delay
to give time for the charge circuit to settle down.
- When the EC gets AC disconnect interrupt, it disables charging
briefly, enables learn mode, and then sets 5V charging allowed.
This allows for the same starting conditions in the charge circuit
for every AC attach.
- When the EC detects a wedged charge circuit, it disables charging
and waits a few seconds before re-enabling 5V only charging.

Additionally, this change moves the charging cutoff in S3/S5/G3 when
the battery is full to the EC. With the added control for the EC
to set the PD charging state, it is more convenient for the EC to
manage cutting off charging when battery is full.

BUG=chrome-os-partner:36081
BRANCH=samus
TEST=test the basics:
- connect/disconnect zinger a bunch of times
- connect and disconnect two zingers in different order
- connect two zingers and charge override between the two

test the automatic charge wedge recover:
- wedge the charge circuit by setting charger voltage under battery
voltage: "charger voltage 7000"
- wait a few seconds for the system to recover and check it is charging
with "battery" command

test full battery charge cutoff:
- added console command to change battery soc in board/samus/extpower.c:
static int cmd_battfake(int argc, char **argv)
{
	char *e;

	battery_soc = strtoi(argv[1], &e, 10);
	batt_soc_change();
	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battfake, cmd_battfake, "", "", NULL);
- in S0, tested "battfake 100" does not disable charging.
- in G3, tested "battfake 100" disables charging and "battfake 99"
re-enables charging.
- set "battfake 100" and tested transitioning to S0 enables charging and
transitioning to S5 disables charging.
- attached two chargers and used charge override to select active port.
then toggled "battfake 100" to "battfake 99" back and forth and verified
charge override port is still the same.

test third-party 12V charger:
- plug in a bunch of times and make sure we stay at 5V for 500ms and then
transition to 12V

test with no battery:
- tested five different units with no battery and just zinger. 3/5 boot,
while the other 2 don't. But, the 2 that don't boot without battery also
can't boot w/o battery when this CL is reverted, so I don't think this
change is causing the problem, I think there is an electrical limitation.

test with EVT zinger:
- EVT zingers (P2 - C2) negotiate very quickly after connection, which
can cause INA problems w/o this CL. Tested an EVT zinger with samus and
did a bunch of connections and disconnections and verified that we always
wait at 5V for 500ms and that we don't wedge the INA circuit on connect.

test backwards compatibility:
- test new PD with old EC and make sure we can charge with zinger.
(note that if the charge circuit wedges, we won't be able to unwedge it).
- test old PD with new EC and make sure we can charge with zinger.

Change-Id: I7703b7a2ab1209d7f559b265b03517e79c74b16a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245253
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2015-02-03 08:21:36 +00:00
Alec Berg
0cfc6a087f hooks: add hook for battery state of charge change
Add hook for battery state of charge change. Hook will be used
to cleanup the samus charging workarounds to follow.

BUG=none
BRANCH=samus
TEST=make -j buildall

Change-Id: I99cbb8264783802139cac689804b056623063695
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245252
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-02-03 05:39:18 +00:00
Shawn Nematbakhsh
d93544bbed mcdp28x0: Move structure definitions to ec_commands.h
mcdp_info is a logging payload, so related structures need to be moved
to the public include file.

BUG=chrome-os-partner:35935
TEST=make buildall -j
BRANCH=Samus

Change-Id: Idb939db884821fa85faafbfe643e713f5bcdbc59
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244780
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-31 04:32:30 +00:00
Todd Broch
54aa5e16d0 pd: Log events for dingdong & hoho
Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:35935
TEST=manual, see new events for dingdong & hoho.  Note must be in GFU
mode to facilitate.

Change-Id: I1b79237512748796cf98765a553af8c9978cb594
Reviewed-on: https://chromium-review.googlesource.com/243374
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-28 11:14:08 +00:00
Todd Broch
17f68998fb pd: Allow multiple mode entry.
Current simplified implementation allows single mode entry.  Specification
allows multiple mode entry and its advantageous for things like flashing RW
while staying in DisplayPort mode on video dongles.

CL adds capability on DFP to track as many alternate modes as supported by the
DFP.  Initial mode entered is still the default supported mode ( 1st entry, 1st
opos).  Policy manager can then use host command, EC_CMD_USB_PD_SET_AMODE, to
enter additional supported modes.

On the UFP (hoho, dingdong) a small modification to track multiple svid mode
entries was made.

Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:33946
TEST=manual, On hoho
1. Still successfully enter default mode DP
2. Using ectool's pdsetmode can successfully enter/exit multiple modes.
   For example,
   # port:1 svid:18d1 opos:1 cmd:1==enter
   ectool --name cros_pd pdsetmode 1 0x18d1 1 1

   Checking with pdgetmode shows both modes entered.

3. Works across hard & soft resets
4. Can flash via ectool --name cros_pd flashpd 4 <port> <RW image>
5. Still drives external display.  With bootarg drm.debug=0x6 and following
   command: 'tail -f /var/log/messages | grep "Received HPD" &'
   I see HPD assert & deassert when switching between GFU and DP mode.
   If both modes entered screen stays lit (after reboot) during write.

Change-Id: I7a21ebea377402eb1b0a0cf1d29df59694e301b1
Reviewed-on: https://chromium-review.googlesource.com/241790
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-28 11:13:58 +00:00
Todd Broch
4ce63213f0 pd: refactor object position index.
Renaming this to 'opos' for consistency with USP-PD specifications
'object position' in VDM header.

Signed-off-by: Todd Broch <tbroch@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:35495
TEST=manual, On hoho
1. Still successfully enter default mode DP
2. Using ectool's pdgetmode pdsetmode can successfully enter/exit
other modes
3. Works across hard & soft resets

Change-Id: I08cb8e003ced4de481adcb503bcba3437ebb1ab7
Reviewed-on: https://chromium-review.googlesource.com/241718
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
2015-01-28 11:13:50 +00:00
Alec Berg
342499a6d0 samus: change charge override hot keys to ctrl+search+0|1|2
Change the charge override hot keys to ctrol+search+0|1|2

BUG=none
BRANCH=samus
TEST=use the hot keys and verify that the PD console shows
charge override host command

Change-Id: I5551190743ea064a967164b9d95143cc966662e1
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/242832
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-01-24 06:42:02 +00:00
Vincent Palatin
6f4af26809 pd: poll PD events only on Google accessories
Poll USB PD accessories for event log entries only after we have
performed a Discover Identity and identified them as a Google device
(USB VID = 0x18d1) in order to avoid confusing third party devices with
our logging VDM.

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

BRANCH=samus
BUG=chrome-os-partner:35858
TEST=connect Zinger to Samus and see the proper PD log entries.

Change-Id: I022fa0d19dc012e46a27b786a724ff251280eeaf
Reviewed-on: https://chromium-review.googlesource.com/242871
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
2015-01-24 00:32:33 +00:00
Vincent Palatin
b13063c247 pd: retrieve logs from accessories
Send the VDO_CMD_GET_LOG VDM to accessories to get their PD event log
and append it to the PD MCU log.

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

BRANCH=samus
BUG=chrome-os-partner:33248 chrome-os-partner:32785
TEST=ectool --name=cros_pd pdlog

Change-Id: Ib52d1e2cae5f77dcec6d0489eaa49527388b02b6
Reviewed-on: https://chromium-review.googlesource.com/242013
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
2015-01-21 06:44:33 +00:00