From 60e1615193b75c510f271e57b64b78a2b0f51de0 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 4 Dec 2016 19:31:21 +0100 Subject: [PATCH] Add support for checking gpio keys for magic keypress as well --- arch/arm/include/asm/arch-mx6/mx6sl_pins.h | 4 ++ .../reMarkable/zero-gravitas/zero-gravitas.c | 38 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/arch-mx6/mx6sl_pins.h b/arch/arm/include/asm/arch-mx6/mx6sl_pins.h index d7728cfab5..157c1227e6 100644 --- a/arch/arm/include/asm/arch-mx6/mx6sl_pins.h +++ b/arch/arm/include/asm/arch-mx6/mx6sl_pins.h @@ -141,5 +141,9 @@ enum { MX6_PAD_KEY_COL0__KEY_COL0 = IOMUX_PAD(0x474, 0x16c, 0, 0x734, 0, 0), MX6_PAD_KEY_COL1__KEY_COL1 = IOMUX_PAD(0x478, 0x170, 0, 0x738, 0, 0), MX6_PAD_KEY_COL2__KEY_COL2 = IOMUX_PAD(0x47c, 0x174, 0, 0x73c, 0, 0), + + MX6_PAD_KEY_COL0__GPIO_3_24 = IOMUX_PAD(0x474, 0x16c, 5, 0x0000, 0, 0), + MX6_PAD_KEY_COL1__GPIO_3_26 = IOMUX_PAD(0x478, 0x170, 5, 0x0000, 0, 0), + MX6_PAD_KEY_COL2__GPIO_3_28 = IOMUX_PAD(0x47c, 0x174, 5, 0x0000, 0, 0), }; #endif /* __ASM_ARCH_MX6_MX6SL_PINS_H__ */ diff --git a/board/reMarkable/zero-gravitas/zero-gravitas.c b/board/reMarkable/zero-gravitas/zero-gravitas.c index d4932a46f0..1e3468e3ce 100644 --- a/board/reMarkable/zero-gravitas/zero-gravitas.c +++ b/board/reMarkable/zero-gravitas/zero-gravitas.c @@ -57,6 +57,11 @@ DECLARE_GLOBAL_DATA_PTR; #define ETH_PHY_POWER IMX_GPIO_NR(4, 21) +/* GPIO keys */ +#define GPIO_KEY_LEFT IMX_GPIO_NR(3, 24) +#define GPIO_KEY_HOME IMX_GPIO_NR(3, 26) +#define GPIO_KEY_RIGHT IMX_GPIO_NR(3, 28) + /* * For handling the keypad */ @@ -155,6 +160,12 @@ static iomux_v3_cfg_t const key_pads[] = { MX6_PAD_KEY_COL2__KEY_COL2 | MUX_PAD_CTRL(NO_PAD_CTRL), }; +static iomux_v3_cfg_t const gpio_key_pads[] = { + MX6_PAD_KEY_COL0__GPIO_3_24 | MUX_PAD_CTRL(NO_PAD_CTRL), + MX6_PAD_KEY_COL1__GPIO_3_26 | MUX_PAD_CTRL(NO_PAD_CTRL), + MX6_PAD_KEY_COL2__GPIO_3_28 | MUX_PAD_CTRL(NO_PAD_CTRL), +}; + static void setup_iomux_uart(void) { imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); @@ -415,7 +426,6 @@ static int check_charger_status(void) return gpio_get_value(BQ24133_CHRGR_OK); } - int power_init_board(void) { struct pmic *p; @@ -573,6 +583,30 @@ int board_early_init_f(void) return 0; } +/* + * Sets up GPIO keys and checks for magic key combo + */ +static int check_gpio_keypress(void) +{ + int left, home, right; + + /* Set up pins */ + imx_iomux_v3_setup_multiple_pads(gpio_key_pads, ARRAY_SIZE(gpio_key_pads)); + + gpio_request(GPIO_KEY_LEFT, "key_left"); + gpio_direction_input(GPIO_KEY_LEFT); + gpio_request(GPIO_KEY_HOME, "key_home"); + gpio_direction_input(GPIO_KEY_HOME); + gpio_request(GPIO_KEY_RIGHT, "key_right"); + gpio_direction_input(GPIO_KEY_RIGHT); + + left = gpio_get_value(GPIO_KEY_LEFT); + home = gpio_get_value(GPIO_KEY_HOME); + right = gpio_get_value(GPIO_KEY_RIGHT); + + return !left && home && !right; +} + /* * Sets up the keypad and then checks for a magic key combo */ @@ -676,7 +710,7 @@ int board_init(void) /* address of boot parameters */ gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; - if (check_keypress()) { + if (check_keypress() || check_gpio_keypress()) { printf("Magic key press detected, launching USB download mode\n"); hab_rvt_failsafe(); /* This never returns, hopefully */ }