Commit Graph

298 Commits

Author SHA1 Message Date
Randall Spangler
319d433d68 Calculate the hash only of the actual RW code
No need to hash a bunch of 0xff's at the end.  We explicitly set a
0xea byte after the end of the code in firmware_image.lds.S.

BUG=chrome-os-partner:11087
TEST=look for the hash start line in the EC debug output:

   [0.011543 hash start 0x00014000 0x00011590]

The second number is the code size.  It should be the same size as
ec.RW.bin, instead of 0x14000.

Change-Id: Ibc94851dc1a09eb46cad46bb97dc5762f9c521f0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28300
2012-07-24 15:55:31 -07:00
Simon Glass
2de38e81a2 Revert "Revert "i2c: Support command version numbers""
This reverts commit 3bb4c6acf4ff327f956ee5e1b6deefcd84dc8fbb

Change-Id: I690baa9bcc0229502c103fc31314170bbc825f65
Reviewed-on: https://gerrit.chromium.org/gerrit/28189
Commit-Ready: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
2012-07-24 11:26:57 -07:00
Randall Spangler
1661f1cef0 Refactor flash module
This is a significant rewrite of the flash module, since it turns out
that much less of the flash logic is actually common between stm32 and
lm4.

BUG=chrome-os-partner:11699
TEST=on link,

(enable hardware wp)
flashinfo -> wp_gpio_asserted
flashwp enable
flashinfo -> wp_gpio_asserted ro_at_boot
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
flashwp disable -> error 7
flashwp now
flashinfo -> wp_gpio_asserted ro_at_boot ro_now rw_now
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
(disable hardware wp)
reboot
flashinfo -> ro_at_boot
flashwp disable
flashinfo -> (no flags)

Change-Id: If22b02373946ce1c080d49ccded4f8fa3e380115
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28200
Reviewed-by: Vic Yang <victoryang@chromium.org>
2012-07-23 23:30:33 -07:00
Bill Richardson
97131838e8 Implement something close to final lightbar code.
BUG=chrome-os-partner:8039
TEST=manual

Boot the system, look at the lightbar. It should pulse colors slowly on
battery, faster on AC.

Change-Id: I0184973d11eda51db87d652aa2c92995f5a25588
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27810
2012-07-23 14:15:47 -07:00
Simon Glass
6147b158d5 host_command: Add send_result() to the arg structure
It's a bit odd that the drivers package up a command to be processed
by host_command, but then host_command calls a global function to
pass the response back.

This adds ambiguity in the host_send_response() implementations as to
whether the command being responded to really is using the same
buffers that the driver set up.

Add a function pointer to the command, and have host_command call
that. Add status to the args structure also, which removes some of
the special case logic for error handling.

BUG=chrome-os-partner:11317
TEST=manual and a bit ad-hoc:
(note, this testing is not completed yet)
Check that snow and link still process commands correctly over I2C
from U-Boot. At this stage only the old interface is supported.
SMDK5250 # mkbp test
Old interface:

New interface:
Version 0: ec_command() returned error
Test failed with error -1
SMDK5250 #

Change-Id: I816738150bce3f8d78e7cd32abf361621aa12312
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28154
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2012-07-23 13:23:06 -07:00
Randall Spangler
e27e2f0229 Add console functionality
Keys I keep hitting should work like I expect them to.

Home or Ctrl+A = move to beginning of line
End or Ctrl+E = move to end of line
Del = delete-right
Ctrl+K = delete to end of line
Ctrl+L = clear screen and reprint current line
Ctrl+N = next command
Ctrl+P = previous command

Also, improve filtering of escape sequences and non-printable
characters, so hitting unsupported keys or control codes doesn't mess
up the current line of input.

BUG=chrome-os-partner:11666
TEST=manual

  type 'fhelpbar'
  home -> cursor moves to beginning of line
  Ctrl+E -> cursor moves to end of line
  Ctrl+A -> cursor moves to beginning of line
    (of course, if you're using Minicom, you'll need to type Ctrl+A A, since
     Minicom uses Ctrl+A as its control key)
  del -> 'helpbar'
  end -> cursor moves to end of line
  left-arrow 3 times -> cursor moves under 'b'
  Ctrl+L -> screen clears, cursor still under 'b'
  Ctrl+K -> 'help'
  Ctrl+Y Page-Up Page-Down -> nothing printed
  enter -> prints known commands (output of 'help' command)
  Ctrl+P -> 'help'
  Ctrl+N -> empty command line

Change-Id: Id893c93b26db8f3deed6ea8be5aab88a3daaead4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28143
2012-07-23 11:03:33 -07:00
Randall Spangler
085b31222b Refactor reboot command to add ap-off and cancel options
Also add 'preserve' flag, for tracking when flags have been preserved
from a previous boot.

BUG=chrome-os-partner:11663
TEST=manual

  reboot -> flags = soft
  reboot preserve -> flags = soft preserve

From ectool, 'ectool reboot_ec cold at-shutdown'

  sysinfo -> shows reboot at shutdown: 4
  reboot cancel
  sysinfo -> no longer shows pending reboot
  reboot ap-off -> flags = soft ap-off, AP is not powered on

Change-Id: I117f33fe21048edb2261be4dcdc6c828a5794d54
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28139
2012-07-23 11:03:33 -07:00
Randall Spangler
ee71c0ae1b Revert "host_command: Add send_result() to the arg structure"
This reverts commit 18db93b25b05c871826fd1853a33a560e64ed247

Breaks link checksums.

Change-Id: Ieeb278b7d4da0600bdc9ced1476b67f23abce1a1
Reviewed-on: https://gerrit.chromium.org/gerrit/28136
Commit-Ready: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
2012-07-22 13:17:04 -07:00
Randall Spangler
fbfc353cef Revert "i2c: Support command version numbers"
This reverts commit b983290238458f88a897ce3cfb06faae9ec79a40

Dependent on reverted change.

Change-Id: I3bb4c6acf4ff327f956ee5e1b6deefcd84dc8fbb
Reviewed-on: https://gerrit.chromium.org/gerrit/28138
Commit-Ready: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
2012-07-22 13:17:03 -07:00
Randall Spangler
360d91573a Support up to 24 thermal sensors
And tidy reporting fan/thermal via memmap.

BUG=chrome-os-partner:11628
TEST=manual
  ectool pwmgetfanrpm -> should report fan speed
  ectool temps N ->
    should work for N=0-9
    reports error for N=15-23
    reports invalid sensor ID for N<0 or N>23

Change-Id: I484f81399f5e9dae9c759401091cc6f5acc733ff
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28032
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-22 13:17:02 -07:00
Simon Glass
bff14cac0b i2c: Support command version numbers
Currently, I2C commands look like this:

Input:
  cmd8 [params bytes] checksum
Output:
  response8 [response_ptr bytes] checksum

Use a prefix byte of (0xDC + cmd_version) to indicate the command
version.  This is compatible with the existing protocol, since there
are no host commands in the range 0xDC-0xFB.  If the first byte of
the from-host data is 0x00-0xDB, it's a version 0 command.

There is no change to the output format, since the EC needs to hand
back a response which matches the version requested by the host.

New input:
  (0xDC+ver8) cmd8 paramlen8 [params bytes] checksum
New output:
  response8 responselen8 [response_ptr bytes] checksum

If the host gets a response of EC_RES_INVALID_COMMAND, it knows it's
talking to an old EC, and at most version 0 of the command is supported.

BUG=chrome-os-partner:11317
TEST=manual and a bit ad-hoc:
(note, this testing is not completed yet, so far only snow is tested)
Check that snow and link still process commands correctly over I2C
from U-Boot.
SMDK5250 # mkbp test
Old interface:

New interface:
Test passed

Change-Id: I1c21f2b036091e9122b4f980ca5f5af34f7fc070
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27470
2012-07-22 00:36:39 -07:00
Simon Glass
949d525e2a host_command: Add send_result() to the arg structure
It's a bit odd that the drivers package up a command to be processed
by host_command, but then host_command calls a global function to
pass the response back.

This adds ambiguity in the host_send_response() implementations as to
whether the command being responded to really is using the same
buffers that the driver set up.

Add a function pointer to the command, and have host_command call
that. Add status to the args structure also, which removes some of
the special case logic for error handling.

BUG=chrome-os-partner:11317
TEST=manual and a bit ad-hoc:
(note, this testing is not completed yet)
Check that snow and link still process commands correctly over I2C
from U-Boot. At this stage only the old interface is supported.
SMDK5250 # mkbp test
Old interface:

New interface:
Version 0: ec_command() returned error
Test failed with error -1
SMDK5250 #

Change-Id: Ic4afdcd7689666cc0f6af228abc6cffe41b0fcbf
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27468
2012-07-22 00:36:39 -07:00
Vic Yang
c26eb30863 stm32f: Fix some error in flash write protect
And also add a fake write protect pin command for futher development and
testing.

BUG=chrome-os-partner:11595
TEST=Enable pstate read/write for stm32f.
      1. 'flashinfo' -> WP pin deasserted. No blocks protected.
      2. 'flashwp enable' -> Nothing changes.
      3. 'fakewp 1'; 'flashinfo' -> WP pin asserted. No blocks
         protected.
      4. 'flashwp enable'; 'flashinfo' -> RO protected.

Change-Id: Id5b1997442d9104d9cb254a295e0bd2f8c83bc78
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28062
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2012-07-21 21:47:52 -07:00
Randall Spangler
e5bdf41f39 Add interface to charge_state for lightbar
Use these functions to get charging state and battery percent.  Use
power_ac_present() from power_button.h to find out if AC adapter is present.

BUG=chrome-os-partner:8039
TEST=none

Change-Id: Ied670c297be316b0b8fa56a450a1566470099b5b
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27830
2012-07-19 11:35:21 -07:00
Vic Yang
c51466d0d0 Add host command to exit force idle charge state
Currently the only way to exit force idle state is to unplug AC power.
Let's add a host command to do so.

Signed-off-by: Vic Yang <victoryang@chromium.org>

BUG=chrome-os-partner:9716
TEST=# ectool chargeforceidle 0
     - Check nothing happened
     # ectool chargeforceidle 1
     - Power LED blinking green. Check current = 0.
     # ectool chargeforceidle 0
     - Power LED back to yellow. Check charging.

Change-Id: Ia8f504b6cf9f42b7d57af3ce2d240f3b00a095f1
Reviewed-on: https://gerrit.chromium.org/gerrit/27768
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
2012-07-18 22:36:42 -07:00
Randall Spangler
8137b29125 Add EC flash protect command to ectool
BUG=chrome-os-partner:11150
TEST=manual

Enable WP GPIO.  Then from a root shell

   localhost ~ # ectool flashprotect
   Flash protect flags: 0x00000008 wp_gpio_asserted
   Writable flags:      0x00000005 ro_at_boot rw_now
   localhost ~ # ectool flashprotect enable
   Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now
   Writable flags:      0x00000004 rw_now
   localhost ~ # ectool flashprotect enable
   Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now
   Writable flags:      0x00000004 rw_now
   localhost ~ # ectool flashprotect now
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   localhost ~ # ectool flashprotect now
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   localhost ~ # ectool flashprotect disable
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   Unable to set requested flags (wanted mask 0x00000001 flags 0x00000000)
   Which is expected, because writable mask is 0x00000000.

Then disable WP GPIO and reboot

   localhost ~ # ectool flashprotect
   Flash protect flags: 0x00000001 ro_at_boot
   Writable flags:      0x00000001 ro_at_boot
   localhost ~ # ectool flashprotect disable
   Flash protect flags: 0x00000000
   Writable flags:      0x00000001 ro_at_boot

Change-Id: Idc5de3b3033521467aca8fb0ba9b7c378d0ad2a1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27799
2012-07-18 18:15:29 -07:00
Randall Spangler
c7b4a30a53 Use config values for flash protect/erase/write sizes
Since they're config values anyway.  Gets rid of an unneeded layer of
function call.

BUG=chrome-os-partner:11150
TEST=build link, snow, daisy; flashinfo returns same values

Change-Id: I27fa007f64a446f1ec0fe22ae16c5c1ac667f8e9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27797
2012-07-18 18:15:00 -07:00
Randall Spangler
9a8223a8db Remove flash_read()
Everything now uses flash_dataptr() to get at flash memory rather than
calling the read function, since the read function adds a needless memcpy().

BUG=chrome-os-partner:11150
TEST=manual

flashwp enable
reboot
flashinfo -> should show ro_at_boot
flashwp disable
reboot
flashinfo -> should no longer show ro_at_boot

Change-Id: I1830e2f036cf6777115c782c1737335ff2eb4ce0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27796
2012-07-18 18:14:47 -07:00
Randall Spangler
1a76325fa8 Continue refactoring flash write protect
Now properly detects partially-protected flash banks.

Also renames 'flashwp lock/unlock' to 'flashwp enable/disable'

BUG=chrome-os-partner:11150
TEST=manual

ww 0x400fe400 0x7fffffff
flashinfo -> ro_now PARTIAL
reboot
ww 0x400fe404 0x7fffffff
flashinfo -> rw_now PARTIAL
flashwp now
flashinfo -> ro_now rw_now (and NOT partial)

Change-Id: I9266a024eee6d75af052cd47e3f54468ad959a12
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27795
2012-07-18 18:14:36 -07:00
Randall Spangler
2223179cbc Move looking at write protect GPIO to button/switches module
Since that already monitors the WP signal for reporting it as a
switch.  And if we have that code in two places and the WP signal
polarity changes, we'll inevitably forget to change it in the other
place...

BUG=chrome-os-partner:11150
TEST=manual

flashinfo -> WP pin asserted
remove WP screw
flashinfo -> WP pin deasserted

Change-Id: I6091c8bb470c357e02ede8a5b184b2a76b70dc60
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27720
2012-07-18 15:51:36 -07:00
Randall Spangler
3f492b471b Continue simplifying flash write protect
Now that read-only code is protected iff the persistent state is
locked, we don't need to track per-block in the persistent state.

BUG=chrome-os-partner:11150
TEST=if it builds and boots, it's fine

Change-Id: I80e6a85c0c72136b7ed8964ce02c8abdbaafe637
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27719
2012-07-18 13:49:11 -07:00
Randall Spangler
ad2268e739 Simplify flash protection, part 1
1. If the flash protection state is locked, RO firmware is explicitly locked.
2. Protecting flash now locks the entire flash.

BUG=chrome-os-partner:11150
TEST=manual

flashinfo -> nothing protected
flashwp now
flashinfo -> unlocked,applied; everything protected
reboot
flashinfo -> nothing protected
flashwp lock ->
flashinfo -> locked,applied; now has 40 Y's at start and 1 at end
reboot
flashinfo -> locked,applied; now has 40 Y's at start and 1 at end
remove WP screw
reboot
flashinfo -> locked, not applied; nothing protected
flashwp unlock
flashinfo -> nothing protected

Change-Id: I2cf0e8bfe82ab7a5bf88b9161b7a05b889cae71a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27717
2012-07-18 13:48:46 -07:00
Randall Spangler
60e7844818 Remove old flash WP commands
These don't accurately reflect how flash write protect was/is implemented.

BUG=chrome-os-partner:11150
TEST=build link, snow

Change-Id: I126253a2ce05e5d3a51471c32211e6cacbfd85d4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27716
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-18 13:11:07 -07:00
Vic Yang
f322e1b96a Set power LED to green when we are trickle charging nearly full
When battery is nearly full, battery sometimes demands for very low
current and we are actually trickle charging. This causes the last part
of charging process very long, but the actual charged amount is only few
mAh. Let's set power LED to green in this case so that user doesn't feel
the device is charging forever.

BUG=chrome-os-partner:11248
TEST=Charge the battery to nearly full. Disconnect and connect AC power.
     Check the power LED is green when we are trickle charging.

Change-Id: Ide108778232e9f1d3abe6b61af7518af25040d10
Reviewed-on: https://gerrit.chromium.org/gerrit/27264
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2012-07-18 09:31:27 -07:00
Randall Spangler
eb93d200be Rename section A to RW, to match other platforms
BUG=chrome-os-partner:11149
TEST=make link, snow, bds; on reboot,
  sysjump rw
  sysinfo   <- should indicate current image is rw
Then on root shell,
  ectool version  <- should indicate rw

Change-Id: I833fcb814165379dd044e4cb46ae338e5da81212
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27660
2012-07-17 14:40:59 -07:00
Randall Spangler
fc7b64e186 Remove firmware B
BUG=chrome-os-partner:11449
TEST=build link, snow, bds; ectool reboot_ec cold to make sure enums line up

Change-Id: Ie09db2080a00f1a7e2c05579b9b41ea5137c1af0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27658
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-17 13:11:44 -07:00
Randall Spangler
acf6f963a1 Flash pre-init reboots if it needs to clear protection registers
BUG=chrome-os-partner:11171
TEST=manual

1. Clear some of the writable-bits in the flash registers
> ww 0x400fe40c 0xffff1234
write 0x400fe40c = 0xffff1234
> rw 0x400fe40c
read 0x400fe40c = 0xffff1234
2. Reset using power+refresh
3. Register should be clear again
> rw 0x400fe40c
read 0x400fe40c = 0xffffffff
4. Sysinfo should indicate reset-pin reason AND hard-reset reason
> sysinfo
Reset flags: 0x0000000a (reset-pin power-on)
5. Reset using power+refresh
6. Sysinfo should indicate reset-pin reason only
> sysinfo
Reset flags: 0x00000002 (reset-pin)
7. Clear writable-bits again
> ww 0x400fe40c 0xffff1234
write 0x400fe40c = 0xffff1234
8. Jump to another image.  This should NOT trigger a hard reset.
> sysjump A
> sysinfo
Reset flags: 0x00000402 (reset-pin sysjump)

Change-Id: Ie1d6af2acc68217bb82faae464798ee85d63d1ea
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27540
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-16 17:49:10 -07:00
Randall Spangler
7ee63359b8 Support preserving reset flags across a reset
This is needed for flash pre-init to be able to hard reset to clear
uncommitted write protect flags without losing the reset flags.

BUG=chrome-os-partner:11368
TEST=manual

Use reboot and sysinfo commands...

1. reset with keyboard.  flags -> reset-pin
2. 'reboot soft preserve'  flags -> soft reset-pin power-on
3. 'reboot hard preserve'  flags -> hard soft reset-pin power-on
4. 'reboot soft'.  flags -> soft
5. 'reboot hard'.  flags -> hard power-on

Change-Id: I6164a78d99c5c10330f90f651148c5795e7afdda
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27418
2012-07-16 10:20:58 -07:00
Randall Spangler
0e933d1ce9 Refactor reset reasons
Reasons are really bitflags, not a single reason.  This will make it
easier to implement flash protection on LM4, where hibernate is a
subset of power-on reasons.

Also added some additional flags we pass in a hibernate register so...
1) We don't recognize spurious RTC wake reasons
2) Hard reset via system_reset(1) is detected as a hard reset, not a RTC wake

BUG=chrome-os-partner:11368
TEST=manual

1. Keyboard reset = power-on reset-pin
2. Pull battery = power-on
3. reboot = soft
4. reboot hard = power-on rtc-alarm
5. hibernate 10 then push power button = power-on wake-pin
6. reboot 3 sec later = soft
7. hibernate 1 = power-on rtc-alarm

Change-Id: Icbbdbcf6dfd13c8a6a4f80a23f64cebebbfba26e
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27417
2012-07-16 10:17:09 -07:00
Rong Chang
3b0e13173d Debounce charging voltage when cross 8.0V
Link battery pack specification suggested a lower charging current
when voltage pass 8.0V. But the lowering the current in constant
current phase leads voltage drop. And the battery goes back to
high current zone, < 8.0V.

This CL adds a 10 seconds debounce time to prevent charging current
change too quickly.

Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:9572
TEST=manual
  watch battery V+ on oscilloscope when charging voltage cross 8.0V

Change-Id: I002f941e33b029e38f813ab2e292c6b73a054352
Reviewed-on: https://gerrit.chromium.org/gerrit/27275
Commit-Ready: Rong Chang <rongchang@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
2012-07-15 22:01:14 -07:00
Randall Spangler
e95813c34f Define __packed inside ec_commands.h
Kernel and U-boot define it elsewhere, but coreboot doesn't.  So put
it here for greatest compatibility.

BUG=none
TEST=if it builds it works

Change-Id: I595910e9198e37bc97d23cd4c249454e1ed64cd8
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27375
2012-07-13 17:28:22 -07:00
Vic Yang
37f19ecc84 Add GPIO get/set host command
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>
2012-07-13 12:24:00 -07:00
Vic Yang
23d031343f Add a host command to force charge state in IDLE mode
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>
2012-07-12 21:08:09 -07:00
Randall Spangler
8c701a7100 Add keyboard recovery event
This is set when the EC boots and sees the recovery key combo.

This is preferable to the memmap'd keyboard recovery switch, which the
host has no way of clearing.  The idea is that the host RO firmware
reads this event and sets the recovery reason.

I will be removing the memmap'd keyboard recovery switch once U-boot
and coreboot check this new event.

BUG=chrome-os-partner:10034
TEST=manual

1. power+esc+refresh; should see this even in EC log
  [0.000838 event set 0x00004000]
(time of event may vary)

2. reboot EC; should NOT see the event

Change-Id: Id0672749f63c5022624a72ec91d30dcadfea5ef8
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27328
2012-07-12 18:23:36 -07:00
Randall Spangler
7946a3eb3d Simplify host event processing
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
2012-07-12 18:22:24 -07:00
Randall Spangler
89049421a6 Add second copy of event state
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
2012-07-12 18:21:32 -07:00
Randall Spangler
02d820786c Support new-style LPC command interface in EC, ectool
Both EC and ectool are still backwards-compatible to the old interface.

BUG=chrome-os-partner:11275
TEST=manual

From U-boot prompt: mkbp hash  // test old host talking to new EC
From root shell: ectool echash // test new host talking to new EC

You can also update just the OS and use an old EC, and verify that
'ectool echash' still works, which tests a new host talking to an old
EC.

Change-Id: I2afbb208cb16836f842ba119b74b1ab6a38ce5d5
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27313
2012-07-12 18:10:30 -07:00
Randall Spangler
c304ff7d81 Use response pointer and size from host command args struct
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
2012-07-12 15:50:14 -07:00
Randall Spangler
c171fbe3dc Map 256 bytes of data for host command args/params
And retain compatibility for old requests.

BUG=chrome-os-partner:11275
TEST=from u-boot prompt, 'mkbp hash'
from root shell, 'ectool flashread 0 68084 /tmp/foo'
then compare to first 68084 bytes of ec.bin

Change-Id: Id82068773703543febde79fc820af7486502e01f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27226
2012-07-12 14:48:50 -07:00
Randall Spangler
02f0ad7ea8 Pass maximum size of response buffer in via host command handler args
BUG=chrome-os-partner:11275
TEST=from u-boot prompt, 'mkbp hash'

Change-Id: I4cf37acfdd8e4edfe2cb6259b0fc6d0860ef0f79
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27225
2012-07-12 11:32:06 -07:00
Randall Spangler
347b5062a4 Initialize memory mapped data and add data versions
BUG=chrome-os-partner:11275
TEST=manual

localhost ~ # io_read8 0x920
0x45 // 'E'
localhost ~ # io_read8 0x921
0x43 // 'C'
localhost ~ # io_read8 0x922
0x01 // version 1
localhost ~ # io_read8 0x9fe
0x00 // unused data initialized to 0

Change-Id: If8de85ddc0e5f99b7c4213214d4b2d30b1439da8
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27196
2012-07-12 11:32:06 -07:00
Vic Yang
0398874210 Add I2C read/write host command
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>
2012-07-12 02:35:21 -07:00
Randall Spangler
bdf3ba5ded Move host_cmd_handler_args farther up the call chain
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>
2012-07-11 17:22:57 -07:00
Randall Spangler
fe5c01cb6e Add host command to check what command versions are supported
BUG=chrome-os-partner:11275
TEST=manual

ectool cmdversions 0x08 -> should print 0x00000001
ectool cmdversions 0xdd -> should print command not supported

Change-Id: I7801be51492eb6a5321accaa2b66f0dc8d5a2797
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27181
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-11 14:46:31 -07:00
Randall Spangler
07ca0977fe Refactor API for host commands, and handle variable length data better
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>
2012-07-11 14:46:30 -07:00
Randall Spangler
29332907d4 Host command interface has only one slot now
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>
2012-07-10 21:52:07 -07:00
Randall Spangler
f2400b869e Move ACPI query-event handling to LPC interrupt
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>
2012-07-10 21:52:07 -07:00
Randall Spangler
42187535e4 Remove fake dev switch
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>
2012-07-10 14:56:05 -07:00
Randall Spangler
0b69d0fd57 Add option to disable system jumps
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
2012-07-09 13:38:23 -07:00
Randall Spangler
1e8e8cd6aa Add new event for host interface ready
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
2012-07-07 23:05:50 -07:00