From 38ddecb897578109525c38c89966059bf381ec4a Mon Sep 17 00:00:00 2001 From: Tom Wai-Hong Tam Date: Fri, 21 Aug 2015 02:32:41 +0800 Subject: [PATCH] Ryu: Add a console command to control the buttons VolUp and VolDown (cherry-pick back to ToT) FAFT needs these buttons (VolUp and VolDown) be controllable such that it can automate the firmware mode switching flows. It is done by EC overwriting the GPIO values such that AP can see the results. BRANCH=ToT,smaug BUG=None TEST=AP boots into the firmware menu screen. Run the following commands in EC console: > btnpress voldown 1 > btnpress voldown 0 # See the next option selected, like a real button pressed > btnpress volup 1 > btnpress volup 0 # Boot in the selected option, like a real button pressed > btnpress volup Button volup pressed = 0 Change-Id: I5e0b514d9986b8e5729ffd3560560d650669e0b7 Signed-off-by: Vic Yang Signed-off-by: Tom Wai-Hong Tam Reviewed-on: https://chromium-review.googlesource.com/294882 Reviewed-by: Randall Spangler (cherry picked from commit 77291b156d10f31dd059a4662aa249a8f8ea762e) Reviewed-on: https://chromium-review.googlesource.com/295162 --- board/ryu/board.c | 42 ++++++++++++++++++++++++++++++++++++++++++ board/ryu/gpio.inc | 4 ++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/board/ryu/board.c b/board/ryu/board.c index ed18f40a60..c38a9823da 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -561,3 +561,45 @@ static int host_event_status_host_cmd(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_PD_HOST_EVENT_STATUS, host_event_status_host_cmd, EC_VER_MASK(0)); + +/****************************************************************************/ +/* Console commands */ + +static int cmd_btn_press(int argc, char **argv) +{ + enum gpio_signal gpio; + char *e; + int v; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + + if (!strcasecmp(argv[1], "volup")) + gpio = GPIO_BTN_VOLU_L; + else if (!strcasecmp(argv[1], "voldown")) + gpio = GPIO_BTN_VOLD_L; + else + return EC_ERROR_PARAM1; + + if (argc < 3) { + /* Just reading */ + ccprintf("Button %s pressed = %d\n", argv[1], + !gpio_get_level(gpio)); + return EC_SUCCESS; + } + + v = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + + if (v) + gpio_set_flags(gpio, GPIO_OUT_LOW); + else + gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_UP); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(btnpress, cmd_btn_press, + " [0|1]", + "Simulate button press", + NULL); diff --git a/board/ryu/gpio.inc b/board/ryu/gpio.inc index 936c9a1bb0..5871bd9271 100644 --- a/board/ryu/gpio.inc +++ b/board/ryu/gpio.inc @@ -26,8 +26,8 @@ GPIO(CAM_SYNC_INT_L, PIN(C, 7), GPIO_INT_FALLING) GPIO(COMPASS_DRDY, PIN(A, 8), GPIO_INPUT) /* Buttons */ -GPIO(BTN_VOLD_L, PIN(C, 0), GPIO_INPUT | GPIO_PULL_UP) -GPIO(BTN_VOLU_L, PIN(A, 2), GPIO_INPUT | GPIO_PULL_UP) +GPIO(BTN_VOLD_L, PIN(C, 0), GPIO_ODR_HIGH | GPIO_PULL_UP) +GPIO(BTN_VOLU_L, PIN(A, 2), GPIO_ODR_HIGH | GPIO_PULL_UP) /* PD RX/TX */ GPIO(USBC_CC1_PD, PIN(A, 1), GPIO_ANALOG)