Commit Graph

148 Commits

Author SHA1 Message Date
Vic Yang
cdcaf6ed8a Add interrupt support for emulator
This provides us a way to inject interrupts during a test. If a test has
interrupt_generator() defined, it will run in a separate thread. The
generator can then trigger interrupts when it decides to. The current
running task is suspended while emulator is executing ISR.

Also fixes a bug that tasks run without scheduler notifying them during
emulator start-up.

BUG=chrome-os-partner:19235
TEST=Repeatedly run all tests.
BRANCH=None

Change-Id: I0f921c47c0f848a9626da6272d9040e2b7c5ac86
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/55671
2014-01-06 12:40:45 +00:00
Vic (Chun-Ju) Yang
4e7e33f6e7 Move pseudo random number generator to common
We have three copies of the same pseudo random number generator in our
test codes. Let's consolidate them into a single copy in test_util.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: I7ea0b3476f3cfe6944855f19861e3c86af35807e
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181085
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-12-27 07:50:47 +00:00
Randall Spangler
6ab8e91658 cleanup: Remove checkpatch warnings
This make minor syntactic changes and renames some camel-cased symbols
to keep checkpatch from complaining.  The goal is to reduce the
temptation to use 'repo upload --no-verify'.

This is a big furball of find/replace, but no functional changes.

BUG=chromium:322144
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I0269b7dd95836ef9a6e33f88c003ab0f24f842a0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/180495
2013-12-19 00:12:28 +00:00
Randall Spangler
05bd0cdec7 Rename mixed-case config constants
This renames constants used in compiler conditionals to uppercase.
   BOARD_foo
   CHIP_foo
   CHIP_FAMILY_foo
   CHIP_VARIANT_foo
   CORE_foo

Mixed-case constants are still defined by the makefile, but are now no
longer used.  I will make one more pass in a week or so to catch any
that are part of someone else's CL, since otherwise this change might
silently merge correctly but result in incorrect compilation.  Then I
will remove defining the mixed-case constants.

BUG=chromium:322144
BRANCH=none
TEST=Build all boards.  Also, "git grep 'BOARD_[a-z]'" should return no
     results (similarly for CHIP, CORE, etc.)

Change-Id: I6418412e9f7ec604a35c2d426d12475dd83e7076
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179206
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-12-16 20:28:32 +00:00
Doug Anderson
1d24f4d661 keyboard: Improve kbpress reliability for automation
The "kbpress" command had a few issues if you wanted to reliably use
it for automation.  Specifically it was not possible to guarantee how
much time would pass between the press of a key and the release of a
key.  Sometimes you might press and release before the key was
officially "there" and sometimes you might get a press and hold of a
key.

Fix this:
1. Make it so that kbpress with no press/release parameter gives a
   press and release (and guarantees that the press / release will
   actually take effect).
2. Make it so that kbpress guarantees that when it finishes that the
   key has actually been pressed or released.

BRANCH=pit
BUG=chrome-os-partner:24249
TEST=kbtype is (https://chromium-review.googlesource.com/178680) reliable
TEST=make -j32 BOARD=bds tests && make BOARD=bds runtests
TEST=Pick Ibe00a796bde7d06416889b621359671a2f68e162 and test.

Change-Id: Ia213ab2e8d8da273e3ac4876d97d5452df88f47d
Signed-off-by: Doug Anderson <dianders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/178983
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 247650ecc90385417f5dcb2d60bb6ae1e5cfa32f)
Reviewed-on: https://chromium-review.googlesource.com/179325
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-12-10 03:26:43 +00:00
Randall Spangler
bc11760a58 Add uppercase defined constants for BOARD_, CHIP_, etc.
Currently, per-board defines use mixed case (BOARD_pit).  This causes
the presubmit script to complain because that's a style violation.
Using --no-verify to bypass that also allows other style violations to
creep in.

This change adds uppercase variants (BOARD_PIT).  It also adds a CORE_
define with '-' changed to '_', since CORE_cortex-m isn't a valid
symbol but CORE_CORTEX_M is (so now we can #ifdef CORE_CORTEX_M).

This does not remove the old mixed-case defines yet, nor does it
find/replace them in the C source files.  This is intentional, so this
change can be cherry-picked into branches without needing to change
files in the branch that may have picked up new #ifdefs.

I will rename the constants in the C source files and remove the old
mixed-case defines in a follow-on CL, which should not need to get
picked into existing branches.

BUG=chromium:322144
BRANCH=none (but might need it if you later cherry-pick something with
       an uppercase #ifdef BOARD_FOO
TEST=Build each board with V=1 option: 'make V=1 BOARD=foo all tests'.
     Check that the compile command line has both mixed-case and
     uppercase defines.  Check that per-board tests from test/build.mk
     were built (for example, BOARD_PIT should compile kb_scan and
     stress, and BOARD_SAMUS should build none of them).

Change-Id: I5eb0d1fe57f1c694d7449e5f148e2f13fb290a39
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179205
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-12-09 18:29:12 +00:00
Randall Spangler
34b94121c7 Remove bolt, daisy, kirby, puppy, slippy boards
These boards are unloved and unsupported.  They'll never grow up to be
laptops, and hardware is increasingly hard to come by.

Comparable functionality is available in the other, more-loved boards.

Removing these boards speeds up util/make_all.sh by 40%.  (If you're
not running that before every upload, you should be...)

BUG=chrome-os-partner:24062
BRANCH=none
TEST=build all remaining platforms and pass unit tests

Change-Id: I4d8a49e4d52d7393471f1b1cbef059c8db4a4f77
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177373
2013-11-21 22:21:56 +00:00
Randall Spangler
5d672b91a7 Clean up hook priorties on LM4
Fan no longer needs a special priority to wait for the host memmap to
become available, since LPC inits earlier.

I2C and PECI don't need explicit ordering on freq change.

Thermal now uses the explicit prio for temp sensors done.

Commented hook test.

BUG=chromium:314768
BRANCH=none
TEST=boot link; enable/disable PLL; verify fanset and temps commands work afterwards.

Change-Id: I71766614dff2950dd307acd0635405e6b59e330a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175601
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-11-04 23:15:38 +00:00
Bill Richardson
88503ab4ec Provide multiple fan support within the EC itself
This adds explicit "int fan" args to the exported functions from
common/fan.c: fan_set_percent_needed() and fan_percent_to_rpm(). Within that
file, multiple fans are handled independently.

This is not complete, though. Host commands and sysjump support still only
handle a single fan, so at the moment multiple fans are treated identically
in those cases.

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

All boards build, "make runtests" passes.

On a multi-fan system, the EC command "faninfo" displays multiple results:

  > faninfo
  Fan 0 Actual:    0 rpm
  Fan 0 Target:    0 rpm
  Fan 0 Duty:   0%
  Fan 0 Status: 0 (not spinning)
  Fan 0 Mode:   rpm
  Fan 0 Auto:   yes
  Fan 0 Enable: yes

  Fan 1 Actual:    0 rpm
  Fan 1 Target:    0 rpm
  Fan 1 Duty:   0%
  Fan 1 Status: 0 (not spinning)
  Fan 1 Mode:   rpm
  Fan 1 Auto:   no
  Fan 1 Enable: no
  >

and the "fanduty", "fanset", and "fanauto" all require the fan number as the
first arg:

  > fanduty 0 30
  Setting fan 0 duty cycle to 30%
  > fanset 1 2000
  Setting fan 1 rpm target to 2000
  > fanauto 0
  > fanauto 1

On single-fan systems, there is no visible change.

Change-Id: Idb8b818122e157960d56779b2a86e5ba433bee1b
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175368
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-11-02 01:07:16 +00:00
Randall Spangler
3266ae6a7e cleanup: Even more TODO comments
Update comments with more info, or remove if no longer applicable.

No code changes.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all platforms; pass unit tests

Change-Id: I5b56eeb500bc0f00e84e91ef99684f4b1b310972
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175418
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-11-01 20:07:24 +00:00
Randall Spangler
d16a246ea9 cleanup: mkbp keyboard module
Rather than compile it by default for host-based tests, only compile
it for the few tests that actually use it.  Since those (and all
boards) now only use if if they also have a keyscan task, we can get
rid of the #ifdefs in keyboard_mkbp.c as well.

And remove a TODO we'll never do...

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests.  These pass:
     util/make_all.sh
     make BOARD=pit tests

Change-Id: I44d1806cfb375027a7ed0b33a5e9bdbbed8ccddc
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/174513
2013-10-30 23:10:13 +00:00
Bill Richardson
e48a9d9c21 Separate fan_t from pwm_t
There is a logical difference between PWM controls for things like
backlights and fan controls for actual fans. This change separates them into
two different data structures, for better abstraction.

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

make runtests, make all boards, test on Link and Falco.

Change-Id: Ib63f2d1518fcc2ee367f81bf5d803360c1aa5c76
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175151
2013-10-30 23:10:10 +00:00
Bill Richardson
034e96c128 Rename CONFIG_FAN to CONFIG_FANS
Instead of just configuring fan support as yes/no, we'll use it to specify
the number of fans on the board. Undefined (not zero!) means no fan support
at all.

Syntax change only. No new functionality.

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

make runtests, build all platforms, build and test on Link.

Change-Id: Iff65efa69e05f3e1a54fdc2a8da9001b4e8487ca
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175150
2013-10-30 23:10:07 +00:00
Bill Richardson
c7b930606b Separate common fan behavior from implementation
This looks like a lot, but it's really just moving the non-board-specific
stuff from chip/lm4/fan.c into common/fan.c, updating the appropriate
headers, and renaming functions to better match the new location.

This is entirely code refactoring and renaming. No new functionality.

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

make runtests, build all platforms, build and test on Link.

Change-Id: I7dc03d6732bad83cf838a86600b42a7cff5aa7aa
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175012
2013-10-30 21:51:50 +00:00
Vic Yang
e589e87b48 Remove QEMU tests
QEMU tests served us well, but it has been more and more difficult to
maintain as we now have more chips and use more functionality from each
EC chip. With emulator tests in place to test common code and hardware
test to test per-chip/per-board drivers, it's time to remove QEMU tests
to simplify our code base.

QEMU tests that are covered by other emulator tests are removed
completely; tests that are not covered are left alone for now to
preserve the test logic.

BUG=chrome-os-partner:18343
TEST=util/make_all.sh
BRANCH=None

Change-Id: I5a4dd2f5ac42f7f66f86fdce0b62dbd2c65bf66a
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/174669
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-10-29 03:55:35 +00:00
Randall Spangler
df541c6ffd cleanup: rename I2C_PORT_HOST to I2C_PORT_MASTER
Previously, it was really confusing whether I2C_PORT_HOST meant the
port where the EC was the master, or the port used to talk to the AP.

No functional changes, just a global find/replace and some tidying of
unused comments.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all platforms; pass unit tests

Change-Id: Ia591ba4577d3399729556e0234ba0db3a0e3c5ea
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/174546
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2013-10-25 01:32:15 +00:00
Randall Spangler
2ad076f8a0 cleanup: Rename and move header files
Device-specific headers belong in driver/ or chip/.  The include/
directory should be for common interfaces.

Code should not normally need to include driver-specific headers.  If
it does, it should use the full relative path from the EC project root
(for example, drivers/charger/bq24715.h).

Change-Id: Id23db37a431e2d802a74ec601db6f69b613352ba
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/173746
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-23 21:27:40 +00:00
Vic Yang
99472d5cb5 Re-enable basic tests for most LM4-based boards
Basic tests are actually working for most LM4-based boards. Let's
re-enable them except for Bolt and Samus. These two boards have
board-specific chipset code, which fails test compilation.

BUG=chrome-os-partner:18598
TEST=Run affected tests on Link
TEST=util/make_all.sh
TEST='make tests' for all board
BRANCH=None

Change-Id: I46bc39c14ec43ccc29e9b0c46f349cac2755e684
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/172982
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Jeremy Thorpe <jeremyt@chromium.org>
2013-10-17 09:24:13 +00:00
Randall Spangler
99157c265c cleanup: Battery header files and filenames
battery.h is the high-level interface.  battery_smart.h is the
low-level interface.  Most things don't need the low-level interface,
but were including smart_battery.h solely to get at battery.h.  Fixed
this.  Also merged battery_pack.h into battery.h, since it was odd to
split that data across multiple header files.  Tidied the function
comments in battery.h as well.

No functional changes, just renaming files and adding comments.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I5ef372f0a5f8f5f36e09a3a1ce24008685c1fd0d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171967
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-07 18:30:50 +00:00
Randall Spangler
90a6676ad5 cleanup: Move board-specific LED state machines to board dirs
The LED state machine ends up being very board-specific, as does the
specific configuration of LEDs and whether they're PWM'd or just
GPIOs.  dparker has some clever ideas for how to move more of the
functionality to common/led_common.c (used at present only by peppy);
that will be done as a follow-on to this CL.

There's a unit test for the spring LED implementation.  To keep that
compiling, just use a symlink to the spring-specific implementation.

No code changes; just moving around files.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I5973e701a29a72575db9a161dc146855ab21cca6
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171771
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-07 18:30:45 +00:00
Vic Yang
bd74ad1e20 Test more error cases of host command handling
This adds tests of invalid command version and invalid command.

BUG=chrome-os-partner:19236
TEST=Pass host_command test
BRANCH=None

Change-Id: I49ce1b4c8b31ef98d9ee8203e88adfa521471d6d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170935
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-10-01 08:16:38 +00:00
Vic Yang
c77575ac0d Emulator support of fake GPIO input
For all GPIOs, the current values are recorded. A test can then change
the value of a GPIO input by gpio_set_level(). The changed value is
recorded and also interrupt is fired if the change fits the interrupt
flags defined in board/host/board.c.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: If8e547e5adf4a20dcb118f5fe2187293005d4ca3
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170907
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-10-01 08:16:34 +00:00
Bill Richardson
af34e526db Create samus board config
This just does a copy/rename from Bolt. Tweaking for Samus' peculiarities
will come next.

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

The only thing we can check is that it compiles:

  cd src/platform/ec
  make BOARD=samus

Change-Id: Ied95ebdd1137548b21334b4a65a298c68482c517
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171081
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-30 18:58:19 +00:00
Randall Spangler
84ba188120 Support backlight control via lid only
The old backlight_x86 code did

  (backlight enable) = (lid is open) && (GPIO request from AP)

Newer systems will AND those signals in hardware.  Support those
systems by separating CONFIG_BACKLIGHT_LID and
CONFIG_BACKLIGHT_REQ_GPIO, and add tests for the case where the enable
signal is dependent only on the lid position.

BUG=chrome-os-partner:22960
BRANCH=none
TEST=pass unit tests

Change-Id: I1909426e49f00a8acd5047fd88c801cba1dacd76
Reviewed-on: https://chromium-review.googlesource.com/170925
Tested-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Randall Spangler <rspangler@chromium.org>
2013-09-27 23:07:21 +00:00
Vic Yang
1e16031f75 Add a test for x86 backlight passthrough
This checks x86 backlight passthrough by toggling lid switch and PCH
backlight output, and also by host command.

Also fix a bug that backlight switch host command can never be invoked
due to incorrect version mask.

BUG=chrome-os-partner:19236
TEST=util/make_all.sh
BRANCH=None (unless some platform needs backlight switch host command)

Change-Id: Iefc5f4b7387c4d2aa43059d073bd70aed879fe34
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170758
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-27 04:33:40 +00:00
Vic Yang
1b1bf3f03f Test charging error state when battery is detached
This checks charge state machine goes into error state when battery is
not responding.

BUG=chrome-os-partner:19236
TEST=Pass sbs_charging test
BRANCH=None

Change-Id: I61970c4d88cbb0d6242613cdc87b88da7ae3f2f4
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170753
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-27 04:33:36 +00:00
Vic Yang
9ce364fce0 Add test for LP5562 LED control
This adds a test for LP5562 LED control. The test mocks charging and
battery status and check LED behavior is as expected.

BUG=chrome-os-partner:19236
TEST=Pass the new test
BRANCH=None

Change-Id: Iac6b538b24c555bf48b6824f880091cd11a585d4
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170597
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-25 19:18:20 +00:00
Vic Yang
45bcffd91a Add test for memory-mapped switch information
This checks power button and lid switch states are updated correctly to
memory-mapped region.

BUG=chrome-os-partner:19236
TEST=Pass power_button and lid_sw tests
BRANCH=None

Change-Id: Ia49b5a3142b5fd47985bc6f53b1bbffd6d4bbeac
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170438
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-25 19:18:15 +00:00
Vic Yang
1e08d488bd Mock flash erase/write function at physical layer
This moves the mock function from common layer down to physical layer to
complete the test of common layer.

Also disable flash test for hardware tests, as this is only testing
common layer.

BUG=chrome-os-partner:19236
TEST=util/make_all.sh
BRANCH=None

Change-Id: Idd1c2c44591952894486f84d428872cfbf2cfdad
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170297
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-24 21:00:25 +00:00
Randall Spangler
6277f7e336 Fix thermal.c compilation if fans are not present.
Currently, it doesn't compile unless CONFIG_FAN is defined.

BUG=chrome-os-partner:22803
BRANCH=none
TEST=temporarily undefine CONFIG_FAN in board/link/board.h; code compiles
     and all unit tests pass

Change-Id: I251d670ccd299f7a50b1455364a817e07fad4cb1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170106
2013-09-23 21:26:26 +00:00
Vic Yang
eff7a1910a Support multi-bit mask in STM32L's GPIO functions
The definition of GPIO interface allows passing in multi-bit mask, and
this is what's done by gpio_config_module(). Fix STM32L's function so
that it doesn't accidentally set incorrect GPIO register values.

BUG=chrome-os-partner:22605
TEST=On Kirby, do 'led r 0' and check the value of 0x40020800 is
0x01540000.
BRANCH=None

Change-Id: I9a1c8074aab7345485a590ecf138bf99d0742997
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168739
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
2013-09-11 19:45:38 +00:00
Bill Richardson
793b52f327 Handle multiple independent sources and types of CPU throttling
Depending on the system, the AP can be throttled in at least two different
ways - politely, where it's just asked to slow down a bit, and forcefully
using a hardware signal (like PROCHOT). In addition, the request for
throttling can come from multiple tasks.

This CL provides a single interface, specifying both the type of throttling
desired and the source of the throttling request.

For each type, any source can can start throttling, but all sources must
agree before it stops. The changes are protected by a mutex, so that
requests from multiple tasks don't interfere with each other.

BUG=chrome-os-partner:20739,chromium:287985,chromium:287983
BRANCH=ToT
TEST=manual

Build-time test:

  cd src/platform/ec
  make BOARD=falco runtests

Run-time test: Lower the temp thresholds, turn the fan off, and watch the
throttling turn off and on as things heat up. For example, on the EC
console:

  > temps
    PECI                : 339 K = 66 C
    ECInternal          : 324 K = 51 C
    G781Internal        : 328 K = 55 C
    G781External        : 327 K = 54 C
  > thermalset 0 341 343
  sensor  warn  high  halt   fan_off fan_max   name
    0      341   343    383    333     363     PECI
    1        0     0      0      0       0     ECInternal
    2        0     0      0      0       0     G781Internal
    3        0     0      0      0       0     G781External
  >
  > temps
    PECI                : 339 K = 66 C
    ECInternal          : 324 K = 51 C
    G781Internal        : 328 K = 55 C
    G781External        : 327 K = 54 C
  >
  > fanduty 0
  Setting fan duty cycle to 0%
  >
  > apthrottle
  AP throttling type 0 is off (0x00000000)
  AP throttling type 1 is off (0x00000000)
  >
  [430.152000 thermal WARN]
  [430.152233 event set 0x00020000]
  [430.152497 event clear 0x00020000]
  [430.152714 ACPI query = 18]
  [430.152444 sci 0x00020000]
  [430.153051 set AP throttling type 0 to on (0x00000001)]
  > gpioget CPU_PROCHOT
    0  CPU_PROCHOT
  >
  [436.153742 thermal HIGH]
  [436.153979 set AP throttling type 1 to on (0x00000001)]
  > gpioget CPU_PROCHOT
    1* CPU_PROCHOT
  > [441.155319 thermal no longer high]
  [441.155587 set AP throttling type 1 to off (0x00000000)]
  [442.155604 thermal HIGH]
  [442.155841 set AP throttling type 1 to on (0x00000001)]
  [446.156623 thermal no longer high]
  [446.156890 set AP throttling type 1 to off (0x00000000)]
  temps
    PECI                : 343 K = 70 C
    ECInternal          : 324 K = 51 C
    G781Internal        : 328 K = 55 C
    G781External        : 327 K = 54 C
  >
  [447.156827 thermal HIGH]
  [447.157064 set AP throttling type 1 to on (0x00000001)]
  apthrottle
  AP throttling type 0 is on (0x00000001)
  AP throttling type 1 is on (0x00000001)
  > gpioget CPU_PROCHOT
    1  CPU_PROCHOT
  >

Now turn the fan back on:

  > fanauto
  >
  [456.159306 thermal no longer high]
  [456.159574 set AP throttling type 1 to off (0x00000000)]
  > apthrottle
  AP throttling type 0 is on (0x00000001)
  AP throttling type 1 is off (0x00000000)
  > temps
    PECI                : 341 K = 68 C
    ECInternal          : 324 K = 51 C
    G781Internal        : 328 K = 55 C
    G781External        : 327 K = 54 C
  >
  [473.163905 thermal no longer warn]
  [473.164168 event set 0x00040000]
  [473.164453 event clear 0x00040000]
  [473.164670 ACPI query = 19]
  [473.164379 sci 0x00040000]
  [473.164987 set AP throttling type 0 to off (0x00000000)]
  temps
    PECI                : 340 K = 67 C
    ECInternal          : 324 K = 51 C
    G781Internal        : 328 K = 55 C
    G781External        : 327 K = 54 C
  >
  > apthrottle
  AP throttling type 0 is off (0x00000000)
  AP throttling type 1 is off (0x00000000)
  >

Change-Id: I9ee1491a637d7766395c71e57483fbd9177ea554
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168802
2013-09-11 01:49:48 +00:00
Vic Yang
b448746bac Add boot key test
This checks boot key combination like Power-F3-ESC and Power-F3-Down can
be properly detected.

BUG=chrome-os-partner:19236
TEST=Pass kb_scan test
BRANCH=None

Change-Id: I180918977299219a8421798dac2ab9fed84ef9a2
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167802
2013-09-05 07:20:56 +00:00
Vic Yang
6c3be20539 Add multi-step test support
We already have a multi-step test. Let's move it to test_util.c so that
upcoming tests can also use it.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: I6b7a036297f3b4b2778687488d1dc5b5bb4fe255
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167950
2013-09-05 07:20:46 +00:00
Vic Yang
93cb494a7e Add BQ27541 battery driver
BQ27541 is not a smart battery IC, and thus we cannot use existing smart
battery driver. Let's add a driver that implements a smart-battery-like
interface.

The 'battery' console command is also moved to battery.c so that it can
be reused by different battery driver.

BUG=chrome-os-partner:22048
TEST=Type 'battery' and check the reported values are sane.
TEST=Check 'battery' command works fine on Spring.
BRANCH=None

Change-Id: I5d1eaeb3f801478f3b9473fd43c1f2a2eda75859
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/66340
2013-09-05 07:19:59 +00:00
Vic Yang
74b6f76872 Implement emulator clock fast-forwarding
When running an unit test, the emulator is sitting in idle task for most
of the time. Since we don't have interrupt support now, the emulator is
just waiting for the next wake-up timer to fire. To save time, we can
actually just figure out which task is the next to wake up, and then
fast-forward the system clock to that time.

With this, all tests run faster and we can remove time-scaling for all
current tests. This improves not only run time but also stability.

If one day we have interrupt support, then we will have to modify this
to take into account the fact that an interrupt might wake a task before
any wake-up timer fires.

BUG=chrome-os-partner:19235
TEST=Run all tests in parallel for 1000 times.
BRANCH=None

Change-Id: I4cd33b041230267c110af015d425dd78d124f963
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167801
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-04 20:32:55 +00:00
Vic Yang
844f4127e8 Add host command test
This test checks host command interface handles errors correctly.

BUG=chrome-os-partner:19236
TEST=Pass host_command test
BRANCH=None

Change-Id: I62764977d2063edf5abd37e78e074384eec5f0d4
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167762
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-09-04 20:32:52 +00:00
Vic Yang
04d8465b75 Also test temp sensor read delegation in thermal test
Temperature sensor read is delegated to functions defined in board.c.
Let's mock that function instead of the one in temp_sensor module.

BUG=chrome-os-partner:19236
TEST=Pass thermal test.
BRANCH=None

Change-Id: Ic0387bd6a49e3f032e593c11c6f80bd36f8474e7
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167761
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-09-04 20:32:49 +00:00
Vic Yang
1764246ee9 Add unit test for 'chan' command
Command 'chan' is used by servod. Let's add an unit test for it.

BUG=chrome-os-partner:19236
TEST=Pass console_edit test
BRANCH=None

Change-Id: If86e052fa6720d952a8d9fe8745432dc4a458869
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167614
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-04 20:32:37 +00:00
Vic Yang
4bdfc7eb7b Add more charge state machine test
This includes:
  - Charge mode control host command
  - Low battery shutdown/hibernate

Also, speed up the test by 20x since we now need to wait for more than
30 seconds for low battery state test.

BUG=chrome-os-partner:19236
TEST=Pass the test
BRANCH=None

Change-Id: If2e91a33f3a80f58da01a6c3da128cb603101dea
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167613
Reviewed-by: Rong Chang <rongchang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-09-04 20:32:33 +00:00
Bill Richardson
8c7a18616f Falco: throttle if battery current drain is too high
I missed this requirement the first time. Now it's here. Also adding a test
for it as well.

BUG=chrome-os-partner:20739
BRANCH=falco
TEST=manual

make BOARD=falco runtests

Change-Id: I88aac8d12d09f7970b04c4aa02b6986b5ea16306
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/66684
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2013-08-23 10:38:57 -07:00
Bill Richardson
fcce7223a5 Completely new thermal/fan implementation
Problems with existing thermal control loop:
* Not multi-board friendly. thermal.c only supports Link and needs
  refactoring. Temp thresholds and fan speeds are hard-coded.
* Only the PECI temp is used to determine the fan speed. Other temp sensors
  are ignored.
* Has confusing data structures. Values in the CPU temp thresholds array mix
  ACPI thresholds with fan step values.

With this change, the thermal task monitors all temp sensors in order to
perform two completely independent functions:

Function one: Determine if the host needs to be throttled by or informed of
              any thermal events.

For thermal events, each temp sensor will have three threshold levels.

TEMP_HOST_WARN
* When any sensor goes above this level, host_throttle_cpu(1) will be called
  to ask the CPU to slow itself down.
* When all sensors drop below this level, host_throttle_cpu(0) will be called.
* Exactly AT this level, nothing happens (this provides hysteresis).

TEMP_HOST_HIGH
* When any sensor goes above this level, chipset_throttle_cpu(1) will be
  called to slow the CPU down whether it wants to or not.
* When all sensors drop below this level, chipset_throttle_cpu(0) will be
  called.
* Exactly AT this level, nothing happens (this provides hysteresis).

TEMP_HOST_SHUTDOWN
* When any sensor is above this level, chipset_force_shutdown() will be
  called to halt the CPU.
* Nothing turns the CPU back on again - the user just has to wait for things
  to cool off. Pressing the power button too soon will just trigger shutdown
  again as soon as the EC can read the host temp.

Function two: Determine the amount of fan cooling needed

For fan cooling, each temp sensor will have two levels.

TEMP_FAN_OFF
* At or below this temperature, no active cooling is needed.

TEMP_FAN_MAX
* At or above this temperature, active cooling should be running at maximum.

The highest level of all temp sensors will be used to request the amount of
active cooling needed. The function pwm_fan_percent_to_rpm() is invoked to
convert the amount of cooling to the target fan RPM.

The default pwm_fan_percent_to_rpm() function converts smoothly between the
configured CONFIG_PWM_FAN_RPM_MIN and CONFIG_PWM_FAN_RPM_MAX for percentages
between 1 and 100. 0% means "off".

The default function probably provide the smoothest and quietest behavior,
but individual boards can provide their own pwm_fan_percent_to_rpm() to
implement whatever curves, hysteresis, feedback, or other hackery they wish.

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

Compile-time test with

  make BOARD=falco runtests

On the EC console, the existing fan commands should work correctly:

  faninfo       - display the fan state
  fanduty NUM   - force the fan PWM to the specified percentage (0-100)
  fanset RPM    - force the fan to the specified RPM
  fanset NUM%   - force the fan to the specified percentage (0-100) between
                  its configured minimum and maximum speeds from board.h
                  (CONFIG_PWM_FAN_RPM_MIN and CONFIG_PWM_FAN_RPM_MAX)
  fanauto       - let the EC control the fan automatically

You can test the default pwm_fan_percent_to_rpm() with

  fanset 1%
  faninfo

The fan should be turning at CONFIG_PWM_FAN_RPM_MIN. Let the EC control it
automatically again with

  fanauto

Also on the EC console, the thermal settings can be examined or changed:

  > temps
  PECI                : 327 K = 54 C
  ECInternal          : 320 K = 47 C
  G781Internal        : 319 K = 46 C
  G781External        : 318 K = 45 C
  >
  > thermalget
  sensor  warn  high  shutdown   fan_off fan_max   name
    0      373   387    383        333     363     PECI
    1        0     0      0          0       0     ECInternal
    2        0     0      0          0       0     G781Internal
    3        0     0      0          0       0     G781External
  >
  > help thermalset
  Usage: thermalset sensor warn [high [shutdown [fan_off [fan_max]]]]
  set thermal parameters (-1 to skip)
  >
  > thermalset 2 -1 -1 999
  sensor  warn  high  shutdown   fan_off fan_max   name
    0      373   387    383        333     363     PECI
    1        0     0      0          0       0     ECInternal
    2        0     0    999          0       0     G781Internal
    3        0     0      0          0       0     G781External
  >

From the host, ectool can be used to get and set these parameters with
nearly identical commands:

  ectool thermalget
  ectool thermalset 2 -1 -1 999

Change-Id: Idb27977278f766826045fb7d41929953ec6b1cca
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/66688
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-08-23 10:38:36 -07:00
Vic Yang
0e9d829e91 Add test for console command history
This tests that command history is as expected. Also fix a bug that some
checks in console_edit test are skipped.

BUG=chrome-os-partner:19236
TEST=Pass console_edit test.
BRANCH=None

Change-Id: Ifbd3d1690f25b35bf5efe523e656b013aa534d26
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64837
2013-08-18 04:27:27 -07:00
Dave Parker
2de1f07579 Remove board 'wolf' from master/ToT branch.
Firmware development for this board is happening on the
firmware-wolf-4389.24.B branch.

BUG=chrome-os-partner:21815
BRANCH=None
TEST=Run util/make_all.sh. Verify all is made.

Change-Id: I4b58a982a87562231453f3f201024b809c6a24fb
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/65514
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-08-12 18:19:57 -07:00
Bill Richardson
0c8c2e453a Add abstract "cond_t" type to detect state transitions.
We often need to watch for transitions between one state and another, so
that we can issue warnings or take action ONCE. This abstracts that "have I
already reacted to this" stuff into a single set of functions.

For example, this code reads a GPIO every time through the loop, but it only
generates an event when the GPIO value changes from 0 to 1:

    cond_t c;

    cond_init_false(&c);

    while(1) {
        int val = read_some_gpio();
        cond_set(&c, val);

        if (cond_went_true(&c))
            host_event(SOMETHING_HAPPENED);

        sleep(1);
    }

BUG=none
BRANCH=falco,peppy
TEST=manual

make BOARD=falco runtests

Change-Id: I42393fcf3c4eb71b9551118a0f442d55c0691315
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/65071
2013-08-09 15:44:09 -07:00
Vic Yang
19e30d9c7d Remove proxy config flags for unit tests
This moves per-test config flags from test_config.mk to test_config.h,
where one can define/undefine config flags for individual test.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: I096aded2007881433d3b6414d37f8bfdc6a2c45c
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64367
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-08-04 13:11:08 -07:00
Bill Richardson
298a7276c2 Add turbo mode charger support, and tests for it.
Some chargers can run in a "turbo" mode, which lets it draw from the battery
to provide extra power to the AP in short bursts. In order for this to work
properly, the EC has to watch the current closely to make sure specific
limits are observed. It also has to recognize specific adapters, since those
limits vary depending on the rated power that the adapter can provide.

This adds the basic functionality, plus a test for it.

BUG=chrome-os-partner:20739
BRANCH=falco,peppy
TEST=manual

  make BOARD=${BOARD} runtests

On Falco, you can also use the "adapter" EC command to see what's going on.
Try replacing the adapters and running that command to be sure they're
correctly identified, too:

  > adapter
  Adapter 65W (590mv), turbo 1, AP_throttled 0
  >

We currently support 45W, 65W, and 90W adapters. Unknown adapters are
treated as 65W, but don't enable turbo mode.

Change-Id: I7e5407db825ce7e596cb495fb8cb4d1dd1ff639c
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/63372
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-07-25 15:50:13 -07:00
Bill Richardson
4231660869 Change macro names used for test configurations
We can't change CONFIG_ options from the gcc commandline, because
include/configs.h explicitly undefs them again. So for some tests, we add a
-DFOO to the command line and then put this in the source:

This change just uses TEST_FOO instead of FOO, so it's more obvious what's
happening.

BUG=chrome-os-partner:20739
BRANCH=falco,peppy
TEST=manual

No functional change, just renaming. Run

  make BOARD=${BOARD} runtests

Everything should still pass.

Change-Id: I17e10180f8d779dff0961cf411f5b61cfc70c316
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/63371
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-07-25 15:50:12 -07:00
Rong Chang
6c280b1b32 Move TPSChrome charging temperature range to battery pack
This change moves vendor specific temperature ranges to battery pack
files or board setup files. And added a host test case to verify that
does not change x86 smart battery charging state machine behavior.

BUG=chrome-os-partner:21181
BRANCH=None
TEST=manual
  build test: util/ecmakeall.sh
  hosttests: make hosttests && make runtests

Change-Id: I48e76826b5555f64b78e3c063ce5f02416c72aa2
Signed-off-by: Rong Chang <rongchang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/62978
Reviewed-by: Vic Yang <victoryang@chromium.org>
2013-07-24 13:07:13 -07:00
Aaron Durbin
7b95d397fe bolt: add prelimnary support
The preliminary bolt support allows the board to boot
with all the necessary peripherals working except for the
following things:
- Not all board temp sensors are added.
- WLAN is not powered on because of inrush issues.
- USB power chargers are fixed to normal mode for now.

BUG=chrome-os-partner:20372
BRANCH=None
TEST=Built and booted

Change-Id: Iea7a39e812bb396e5731f212630b7fe97c164bf2
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/62210
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-07-24 12:09:50 -07:00