From 2e4d4e2e058adafe8ce18d4a71d7b2604170d837 Mon Sep 17 00:00:00 2001 From: Mary Ruthven Date: Wed, 5 Oct 2016 11:06:26 -0700 Subject: cr50: add console commands to have parity with servo This change adds apreset, ecreset, ec_rst, sys_rst and powerbtn options to the ccd console command. BUG=chrome-os-partner:58123 BUG=chrome-os-partner:56835 BRANCH=none TEST=manual sysrst resets the AP sysrst on/off controls SYS_RST_L ecrst resets the ec ecrst on/off controls EC_RST_L powerbtn 500 will simulate a power button press for 500 ms Change-Id: I89adc88eb407730c9d57811a07bfef8fcf63c5b9 Signed-off-by: Mary Ruthven Reviewed-on: https://chromium-review.googlesource.com/393809 Reviewed-by: Bill Richardson --- board/cr50/rdd.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ chip/g/rbox.c | 18 ++++++++++++++ chip/g/rbox.h | 11 ++++++++ 3 files changed, 105 insertions(+) create mode 100644 chip/g/rbox.h diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index ac2557ef3e..0bb7055ca2 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -8,6 +8,7 @@ #include "device_state.h" #include "gpio.h" #include "hooks.h" +#include "rbox.h" #include "rdd.h" #include "registers.h" #include "system.h" @@ -218,3 +219,78 @@ static int command_ccd(int argc, char **argv) DECLARE_CONSOLE_COMMAND(ccd, command_ccd, "[uart] []", "Get/set the case closed debug state"); + +static int command_sys_rst(int argc, char **argv) +{ + int val; + + if (argc > 1) { + if (parse_bool(argv[1], &val)) { + if (val) + assert_sys_rst(); + else + deassert_sys_rst(); + } else + return EC_ERROR_PARAM1; + ccprintf("SYS_RST_L is %s\n", is_sys_rst_asserted() ? + "asserted" : "deasserted"); + } else { + ccprintf("Issuing AP reset\n"); + assert_sys_rst(); + usleep(200); + deassert_sys_rst(); + } + + return EC_SUCCESS; + +} +DECLARE_SAFE_CONSOLE_COMMAND(sysrst, command_sys_rst, + "[]", + "Assert/deassert SYS_RST_L to reset the AP"); + +static int command_ec_rst(int argc, char **argv) +{ + int val; + + + if (argc > 1) { + if (parse_bool(argv[1], &val)) { + if (val) + assert_ec_rst(); + else + deassert_ec_rst(); + } else + return EC_ERROR_PARAM1; + + ccprintf("EC_RST_L is %s\n", is_ec_rst_asserted() ? + "asserted" : "deasserted"); + } else { + ccprintf("Issuing EC reset\n"); + assert_ec_rst(); + usleep(200); + deassert_ec_rst(); + } + return EC_SUCCESS; +} +DECLARE_SAFE_CONSOLE_COMMAND(ecrst, command_ec_rst, + "[]", + "Assert/deassert EC_RST_L"); + +static int command_powerbtn(int argc, char **argv) +{ + char *e; + int ms = 200; + + if (argc == 2) { + ms = strtoi(argv[1], &e, 0); + if (*e) + return EC_ERROR_PARAM1; + } + ccprintf("Simulating %dms power button press\n", ms); + rbox_press_power_btn(ms); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn, + "ms", + "Simulate a power button press"); diff --git a/chip/g/rbox.c b/chip/g/rbox.c index 627c587563..9813123a84 100644 --- a/chip/g/rbox.c +++ b/chip/g/rbox.c @@ -6,6 +6,24 @@ #include "clock.h" #include "hooks.h" #include "registers.h" +#include "timer.h" + +#define POWER_BUTTON 2 + +void rbox_press_power_btn(int ms) +{ + uint8_t val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL); + + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, ~(1 << POWER_BUTTON) & val); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 1 << POWER_BUTTON); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 1 << POWER_BUTTON); + + msleep(ms); + + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 0); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 0); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, val); +} static void rbox_release_ec_reset(void) { diff --git a/chip/g/rbox.h b/chip/g/rbox.h new file mode 100644 index 0000000000..0d90b2ce25 --- /dev/null +++ b/chip/g/rbox.h @@ -0,0 +1,11 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_RBOX_H +#define __CROS_RBOX_H + +/* Simultate a power button press */ +void rbox_press_power_btn(int ms); +#endif /* __CROS_RBOX_H */ -- cgit v1.2.1