Andy Yan | 62d952f | 2019-11-14 11:23:02 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
Andy Yan | 62d952f | 2019-11-14 11:23:02 +0800 | [diff] [blame] | 6 | #include <adc.h> |
Jonas Karlman | 0333e3b | 2024-04-08 18:14:11 +0000 | [diff] [blame] | 7 | #include <asm/arch-rockchip/grf_rk3308.h> |
Andy Yan | 62d952f | 2019-11-14 11:23:02 +0800 | [diff] [blame] | 8 | #include <asm/arch-rockchip/hardware.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 9 | #include <linux/bitops.h> |
Andy Yan | 62d952f | 2019-11-14 11:23:02 +0800 | [diff] [blame] | 10 | |
| 11 | #if defined(CONFIG_DEBUG_UART) |
| 12 | #define GRF_BASE 0xff000000 |
| 13 | |
| 14 | enum { |
| 15 | GPIO1C7_SHIFT = 8, |
| 16 | GPIO1C7_MASK = GENMASK(11, 8), |
| 17 | GPIO1C7_GPIO = 0, |
| 18 | GPIO1C7_UART1_RTSN, |
| 19 | GPIO1C7_UART2_TX_M0, |
| 20 | GPIO1C7_SPI2_MOSI, |
| 21 | GPIO1C7_JTAG_TMS, |
| 22 | |
| 23 | GPIO1C6_SHIFT = 4, |
| 24 | GPIO1C6_MASK = GENMASK(7, 4), |
| 25 | GPIO1C6_GPIO = 0, |
| 26 | GPIO1C6_UART1_CTSN, |
| 27 | GPIO1C6_UART2_RX_M0, |
| 28 | GPIO1C6_SPI2_MISO, |
| 29 | GPIO1C6_JTAG_TCLK, |
| 30 | |
| 31 | GPIO4D3_SHIFT = 6, |
| 32 | GPIO4D3_MASK = GENMASK(7, 6), |
| 33 | GPIO4D3_GPIO = 0, |
| 34 | GPIO4D3_SDMMC_D3, |
| 35 | GPIO4D3_UART2_TX_M1, |
| 36 | |
| 37 | GPIO4D2_SHIFT = 4, |
| 38 | GPIO4D2_MASK = GENMASK(5, 4), |
| 39 | GPIO4D2_GPIO = 0, |
| 40 | GPIO4D2_SDMMC_D2, |
| 41 | GPIO4D2_UART2_RX_M1, |
| 42 | |
| 43 | UART2_IO_SEL_SHIFT = 2, |
| 44 | UART2_IO_SEL_MASK = GENMASK(3, 2), |
| 45 | UART2_IO_SEL_M0 = 0, |
| 46 | UART2_IO_SEL_M1, |
| 47 | UART2_IO_SEL_USB, |
| 48 | }; |
| 49 | |
| 50 | void board_debug_uart_init(void) |
| 51 | { |
| 52 | static struct rk3308_grf * const grf = (void *)GRF_BASE; |
| 53 | |
| 54 | /* Enable early UART2 channel m0 on the rk3308 */ |
| 55 | rk_clrsetreg(&grf->soc_con5, UART2_IO_SEL_MASK, |
| 56 | UART2_IO_SEL_M0 << UART2_IO_SEL_SHIFT); |
| 57 | rk_clrsetreg(&grf->gpio1ch_iomux, |
| 58 | GPIO1C6_MASK | GPIO1C7_MASK, |
| 59 | GPIO1C6_UART2_RX_M0 << GPIO1C6_SHIFT | |
| 60 | GPIO1C7_UART2_TX_M0 << GPIO1C7_SHIFT); |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | #define KEY_DOWN_MIN_VAL 0 |
| 65 | #define KEY_DOWN_MAX_VAL 30 |
| 66 | |
| 67 | int rockchip_dnl_key_pressed(void) |
| 68 | { |
| 69 | unsigned int val; |
| 70 | |
John Keeping | 63e31db | 2022-07-14 15:09:12 +0100 | [diff] [blame] | 71 | if (adc_channel_single_shot("saradc@ff1e0000", 1, &val)) { |
Andy Yan | 62d952f | 2019-11-14 11:23:02 +0800 | [diff] [blame] | 72 | printf("%s read adc key val failed\n", __func__); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | if (val >= KEY_DOWN_MIN_VAL && val <= KEY_DOWN_MAX_VAL) |
| 77 | return true; |
| 78 | else |
| 79 | return false; |
| 80 | } |