The charger task relies on calc_next_state() performing a delay before
returning. My reading of the code suggests that this doesn't happen
always. For example:
When pre-charging:
if (battery_temperature(&batt_temp) == EC_SUCCESS)
return ST_CHARGING;
When discharging and capacity is low:
/* Check remaining charge % */
if (battery_state_of_charge(&capacity) == 0 && capacity < 10)
return notify_battery_low();
I would like to suggest that the code be refactored to more like:
int next_checkms = 5000; /* next time to check battery */
while (1) {
int action = ACTION_NONE;
err = get_state(&state);
if (!err) {
action = calculate_action(&state);
err = perform_action(action, &next_check_ms);
}
usleep(next_check_ms * 1000);
}
so that the delays are really clear, the state is all read at once,
there is no reliance on earlier state, and we always delay even on
error.
In the meantime, this CL inserts a mandatory 5 second delay in the
loop, which should prevent the charger task lockup.
BUG=chrome-os-partner:11285
TEST=manual
(please do this test before committing)
1. boot to kernel, see that battery can be seen
2. suspend and resume device
3. see that the charger loop does not cause an EC watchdog reset and
AP power off/reset. There should be no watchdog warning message on the
EC console.
Change-Id: I141e374933c4dc0ec60bcdccf96443f57067c585
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27353
Reviewed-by: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Tested-by: Katie Roberts-Hoffman <katierh@chromium.org>
Commit-Ready: Katie Roberts-Hoffman <katierh@chromium.org>
These commands are used in factory test. If system is locked, GPIO
commands are disabled for security reason.
BUG=chrome-os-partner:11164
TEST= - 'ectool gpioget enable_backlight' gives 1.
- 'ectool gpioset enable_backlight 0' turns off display.
- Lock system. Check these commands return error.
Change-Id: I3ea41285075ebe963ba7d30e4ae183cef9b1c105
Reviewed-on: https://gerrit.chromium.org/gerrit/27019
Commit-Ready: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
This command should only be accessible when flash write protect is
unlocked.
BUG=chrome-os-partner:9716
TEST= - Check we can charge and discharge normally.
- Connect AC and force idle. Check battery current is 0 mA.
Change-Id: I74a318c1f5562d6a23b722736615fd1f883dc35a
Reviewed-on: https://gerrit.chromium.org/gerrit/27259
Commit-Ready: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Now both copies of the event state live in host_event_commands.c, and
lpc / memmap just shadows the main copy.
BUG=chrome-os-partner:11172
TEST=manual
Boot system. should see events 0x2000, 0x80, 0x08 get set and then cleared.
At U-boot prompt, type on keyboard. Should set event 0x1000 get set,
but only on the first keypress (because U-boot doesn't consume that
event).
Then from EC console,
hostevent clear 0x1000 -> see event 0x1000 clear
hostevent clear 0x1000 -> no debug output (it's already clear)
hostevent clearb 0x1000 -> see event copy B 0x1000 clear
hostevent clearb 0x1000 -> no debug output (copy B is already clear)
Change-Id: I855c035865649ba1490cd9027157d5bcdcc9895f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27321
U-boot and ectool need this to see what events have occurred, in a way
which doesn't conflict with ACPI/SCI/SMI.
BUG=chrome-os-partner:11172
TEST=manual
- boot EC
- look at event set / event clear debug output; that's for copy A
- from ec console,
hostevent -> events=0, events-B = 0x2088
hostevent clearb 0x2000 -> events-B = 0x88
Change-Id: If842b157914426df593d82af2bfb08a923caa34b
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27317
Saves 2 params being passed around needlessly.
BUG=chrome-os-partner:11275
TEST=mkbp hash from u-boot console should still work
Change-Id: I958e4a09f16413e4d051e278dc0384aa9b791aa4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27312
These commands are only available when system is unlocked.
BUG=chrome-os-partner:9716
TEST=When system is unlocked, check we can read/write I2C bus.
When system is locked, check the commands return error.
Change-Id: I8c4a8a42ab13d62c7e47bf33e2a7abc6f61e43fa
Reviewed-on: https://gerrit.chromium.org/gerrit/27254
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
The spec of link internal battery pack changed. This CL adds
parameter for new pack, and renames vendor specific source file
accordingly.
The new trickle charging current limit should fix the slow
pre-charging issue.
Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:11298,10201
TEST=manual
The minimum trickle charging current should be very close to
0.01 C (85mA). Previous battery pack firmware uses 5mA in pre-
charging.
Change-Id: I0bad679db7dd087894297e6eb0e85c9b12fdf444
Reviewed-on: https://gerrit.chromium.org/gerrit/27256
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
This is necessary for an imminent change which passes version data
from the host bus (LPC/I2C/SPI) into the host command handler.
BUG=chrome-os-partner:11275
TEST=from u-boot prompt, 'mkbp hash'
Change-Id: If34d0d7c6dc320ad5632becf512c30900fd61aca
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27190
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Added version mask field to DECLARE_HOST_COMMAND() because it's
convenient to do so when I'm touching all host command
implementations, but all commands simply declare version 0 and nothing
checks it yet. Will add version support in a followup CL.
This change is internal to the EC; it does not change the data sent
over the host interface.
BUG=chrome-os-partner:11275
TEST=manual
ectool version && ectool echash; should get sane data from both
ectool flashread 0x80 0x40 /tmp/foo && od -tx1 /tmp/foo
should match data from offset 0x80 of ec.bin (od -j128 -n64 -tx1 ec.bin)
Change-Id: I5699f72b8d5e1ac23929353c9a34158d76c44206
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27172
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Now that ACPI events are handled directly in the LPC interrupt
handler, we can simplify the host event code.
BUG=chrome-os-partner:11240
TEST=boot system; should boot
close lid; should send SMI and suspend system
Change-Id: I8c73ea31a66e94310e4460a008635a103220413e
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27100
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
And only support it for port 62/66.
Also remove 'ectool queryec', because it can't touch port 62/66 once
the kernel/ACPI owns it, and query-event isn't supported on the user
command port.
BUG=chrome-os-partner:11240
TEST=boot system and check EC console output; should see event clears between
host commands 0x23, 0x8e, but no hostcmd 0x84.
[0.396780 LPC RESET# deasserted]
[0.486953 Port 80: 0x29]
[0.487415 hostcmd1 0x23]
[0.764407 Port 80: 0x88]
[0.764579 event clear 0x00000008 -> 00002080]
[0.764928 event clear 0x00000080 -> 00002000]
[0.765224 event clear 0x00002000 -> 00000000]
[0.765578 hostcmd1 0x8e]
[0.765868 hostcmd1 0x06]
Change-Id: I8ed161dbccd396d685ddf6829a27dfef87d919fb
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27095
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
BUG=chrome-os-partner:9922
TEST=manual
Press power+refresh+d.
From ec console, 'optget'. No reference to fake dev switch
From host, 'ectool vboot'. Should see either 'fake_dev=0' or no mention of fake dev switch at all.
Change-Id: I66bc5e926d6e639b206563e764bcc730cce9227c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27061
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Currently host_command_reboot() casts the supplied buffer and access
it directly. This works until about half-way thru the function when
the same buffer potentially gets overwritten when sending the response
code to the host.
This CL gets around that by copying the reboot parameters into a
separate buffer.
Signed-off-by: David Hendricks <dhendrix@chromium.org>
BUG=none
TEST=Tested using 'ectool reboot_ec' on Snow (see below)
Before, EC console displayed "[Executing host reboot command]" and
ectool showed no actual change (reboot command was being overwritten
with EC_REBOOT_CANCEL):
localhost ~ # ectool version | grep 'Firmware copy'
Firmware copy: RO
localhost ~ # ectool reboot_ec A
localhost ~ # ectool version | grep 'Firmware copy'
Firmware copy: RO
With the patch applied, the EC console shows the EC boot-up messages
and ectool confirms that the jump took place:
localhost ~ # ectool version | grep 'Firmware copy'
Firmware copy: RO
localhost ~ # ectool reboot_ec A
localhost ~ # ectool version | grep 'Firmware copy'
Firmware copy: A
Change-Id: I8aca8d468d1125c3fb8d320ec0fb79d2822b0b20
Reviewed-on: https://gerrit.chromium.org/gerrit/26998
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>
Commit-Ready: David Hendricks <dhendrix@chromium.org>
BUG=chrome-os-partner:11046
TEST=manual
1. Try 'ectool kbpress' command from root shell with a few params when system is unlocked (WP disabled). Should work.
2. Try again when WP is enabled and locked ('flashwp lock' then 'reboot' from EC console). Should fail.
2b. Alternately, use 'syslock' to lock system for just the current boot.
Change-Id: Ic271b13b1973ff3cb83a113274d4e33655c0cf85
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26936
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Allows 'reboot cold' as an alias for 'reboot hard', since I keep
mis-typing that anyway. Returns error for any other option.
('reboot' by itself still does a warm reboot).
BUG=none
TEST=manual
reboot -> does warm reboot
reboot hard -> does hard reboot (reason = rtc alarm)
reboot cold -> ditto
reboot foo -> prints error
Change-Id: I183714d4ba09abee3bd9a6f0d5df82389becf410
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26924
This allows the console or AP to keep the EC in its RO code.
Previously, the EC could jump from RO to RW even if the system was
locked in pre-init.
Also, sysjump console command doesn't need to check if system is
disabled before calling system_run_image_copy(), because that function
also checks. This now matches how the host command works.
BUG=chrome-os-partner:11147
TEST=manual
syslock
sysjump A -> works
reboot
syslock
sysjump disable
sysjump A -> fails
Repeat, using 'ectool reboot_ec disable-jump' at root shell instead of
'sysjump disable' at EC console.
Change-Id: I0b168a93e97802ba30e7c225b01d70ea66e8db58
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26898
EC software sync still needs to be able to sysjump later after the AP
decides which image the EC should be running.
BUG=chrome-os-partner:11087
TEST=manual
sysjump A
sysjump RO
sysjump A
sysjump RO
Change-Id: I74eaf10dacf6eaa6aeabae2ff3b21ad387517605
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26896
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This makes it easier to test functionality which should be disabled
when the system is locked.
BUG=chrome-os-partner:11154
TEST=manual
sysjump a
sysjump ro
sysjump a
syslock
sysjump ro -> should fail
Change-Id: I637d5a9a795948dd45817c5e110433d12bb6618e
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26897
This test checks charging state machine works correctly:
- Charge when AC plugged. Discharge when AC unplugged.
- Shutdown when over/under-temperature during discharging.
- Stop charging when over/under-temperature during charging.
BUG=chrome-os-partner:10270
TEST=Test passed
Change-Id: I460645c70f5dcd30e258c43956ffe416c8bce906
Reviewed-on: https://gerrit.chromium.org/gerrit/26383
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Also add new 'invalid' host event bit; if the host reads this, it
knows the memory-mapped data for current events is invalid.
BUG=chrome-os-partner:11146
TEST=manual
On host, ectool eventget -> should print events = 0
On EC, hostevent set 0x80000000
On host, ectool eventget -> should print events = invalid
Reboot EC; should see debug output where event mask 0x2000 is set
during the boot process.
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: I8d3f161eec25db50ac06e3642a1a1fb8edb9590e
Reviewed-on: https://gerrit.chromium.org/gerrit/26876
512 bytes isn't enough to capture all the debug output early in the
init process, and Link EC has lots of unused RAM. stm32 doesn't, so
only do this for LM4 processor.
BUG=none
TEST=build; debug output during init shouldn't be garbled
Change-Id: Ie4fd204fa4e0c6ca99ea7eae94b095ef175836e4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26877
This adds a small interrupt handler for lid open/close event which
updates a state variable and wakes up the power task to decide if
action must be taken. For the suspend mode path, it will determine
which state to set the power LED in.
BUG=chrome-os-partner:9708
TEST=Lid open turns on Snow, suspend mode to be tested separately
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Change-Id: Ib8bb682affc5b9f6d729eb5f05d23098074e1a77
Reviewed-on: https://gerrit.chromium.org/gerrit/26647
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>
Commit-Ready: David Hendricks <dhendrix@chromium.org>
BUG=chrome-os-partner:11090
TEST=suspend laptop, then press power button; should resume from suspend
Change-Id: I36b7c62b2e115bb97d37defcd3c783af0f91d5f8
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26730
And fix returning memory-mapped string length on LPC as well.
BUG=chrome-os-partner:11090
TEST=manual
from EC, 'hostevent set 0x40000'
from host, 'ectool eventget' --> should print 0x40000
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: I9edbd0a1468b5d4160ce67c471332226e51fa868
Reviewed-on: https://gerrit.chromium.org/gerrit/26719
Reviewed-by: Simon Glass <sjg@chromium.org>
This command is primarily useful for testing, since it repeatedly
hammers the i2c bus.
Enable the command on snow for now.
BUG=chrome-os-partner:10888
TEST=manual:
run 'pmu 100' on snow and see that it displays the correct output.
Change-Id: I36c15af195d17f67dff4c05559d1756693a65c19
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26829
Reviewed-by: David Hendricks <dhendrix@chromium.org>
The power button module now needs to know whether the chipset is in
the on state at init-time, in which case it doesn't need to send a
power button pulse to the chipset.
BUG=chrome-os-partner:11085
TEST=manual
1. power on AP to BIOS screen (e.g., in recovery mode)
2. At EC console, 'sysjump A'
3. system should stay powered on
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: Ic1f509204f502d1ddf87314f0e1582c21c991156
Reviewed-on: https://gerrit.chromium.org/gerrit/26700
Reviewed-by: Simon Glass <sjg@chromium.org>
If flash starts at zero, then flash_dataptr() will return NULL for a valid
region. Change the function around so that it can be used in this case.
BUG=chrome-os-partner:10146
TEST=manual:
Modify code it print out parameters and problems, then:
Writing 256 bytes to 0x0...
0 256 64
ok 131072
Command returned error 1
> flashwrite 0 256
Writing 256 bytes to 0x0...
0 256 64
ok 131072
Command returned error 1
> flashwrite 0 255
Writing 255 bytes to 0x0...
0 255 64
Command usage/param invalid.
Usage: flashwrite offset [size]
Change-Id: I5683fc181ef780310ceff50f120735659e973784
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26749
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
Rather than go through the task queue, host_command_process() processes
the command immediately, has all of its required state passed in,
allowing the caller complete control of the buffers.
BUG=chrome-os-partner:10533
TEST=manual:
build and boot on link, see that messages are stil processed
build and boot on snow, which uses this new command
See that the SPI keyboard works now
Change-Id: Ib7587de10c42caf01bc95bb4d515fd0afc3da7d8
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/25983
Reviewed-by: David Hendricks <dhendrix@chromium.org>
We see some intermittent failure on PECI read. This CL lower PECI baud
rate from 150K to 100K. Also, we poll PECI temperature 4 times per
second and average over last 4 values. We only report read error when
last 4 read all fails.
This CL also increases the external path delay, increases retry count,
and also enable timing negotiation error bypass.
BUG=chrome-os-partner:10382
TEST=Still able to read from all temperature sensors
Change-Id: I38cefeabd9e3eff4bb8e4df4138c4ffd49cd84a2
Reviewed-on: https://gerrit.chromium.org/gerrit/26554
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Sometimes it is useful to get access to the flash directly, without using
flash_read(). Add a function to do this.
Since the range checking is done in every function in flash_common,
use the new function to do it for us. That way we get a slight (64 byte)
code size reduction.
BUG=chrome-os-partner:10146
TEST=manual:
build and boot on snow with SPI flash emulation, in U-Boot:
See that the 32KB of flash has been provided correctly.
Change-Id: I6622a24234edaed371dd5b9bf43d1f3974d55e39
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26174
This allows us to repeatedly read the battery for testing.
BUG=chrome-os-partner:10888
TEST=manual:
build for all boards
boot on snow (cannot test i2c as it is
Change-Id: I0ed99d59355e1f228486070dcf37863563b16023
Reviewed-on: https://gerrit.chromium.org/gerrit/26290
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Simon Glass <sjg@chromium.org>
This seems to be a hangover from the LPC protocol. We can send a result
just by sending a response with no data.
Drop this function and remove all uses of it.
Also use 'enum ec_status' instead of int, since this is the correct
response type.
BUG=chrome-os-partner:10533
TEST=manual:
build for all boards
build and boot on daisy
Change-Id: I93a029bd6ba8cec567b61af3b410bcead015b5c0
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/25980
This drives the power LED for Snow (PB3) using TIM2 in PWM mode.
Since timer setup and manipulation is STM32-specific, the power LED
logic moved to to chip/stm32/power_led.c.
This also adds a "powerled" console command for testing.
Signed-off-by: David Hendricks <dhendrix@chromium.org>
BUG=chrome-os-partner:10647
TEST=Tested on Snow with powerled command, compiled for Daisy
Change-Id: I5a7dc20d201ea058767e3e76d54e7c8567a3b83c
Reviewed-on: https://gerrit.chromium.org/gerrit/26267
Commit-Ready: David Hendricks <dhendrix@chromium.org>
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>
This change fixes mutiple snow charging issues. Including:
- disable i2c host auto selection
- i2c_read8 got wrong output value
- pmu CHARGE_EN control workaround
Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:11010
TEST=Only test on snow dvt with AP turned off
plug/unplug ac adapter and check charging led
check console command 'battery'
Change-Id: I29d554b3daa4cfc538bd5bf5ba5233976d381861
Reviewed-on: https://gerrit.chromium.org/gerrit/26529
Tested-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
This is now superseded by the hash command, which uses a more robust
SHA-256 check.
BUG=none
TEST=if it compiles it's fine
Change-Id: I5ad9256e7af346464301252d62b47bd37852d24a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26452
Now that the EC powers on the AP unconditionally on startup, we need a
way to quickly shut the AP down if it's running without a heatsink.
(Also cleaned up comments and line spacing to kernel style)
BUG=none
TEST=boot system; when x86 is booting, type 'x86shutdown'.
Change-Id: I4dd5a2d5d27b624d0d0f9228baac257587b4808a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26274
Reviewed-by: Simon Glass <sjg@chromium.org>