Andy Yan | 771788f | 2019-11-14 11:21:15 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2018 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <adc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Andy Yan | 771788f | 2019-11-14 11:21:15 +0800 | [diff] [blame] | 9 | |
| 10 | DECLARE_GLOBAL_DATA_PTR; |
| 11 | |
| 12 | #define KEY_DOWN_MIN_VAL 0 |
| 13 | #define KEY_DOWN_MAX_VAL 30 |
| 14 | |
| 15 | /* |
| 16 | * Two board variants whith adc channel 3 is for board id |
| 17 | * v10: 1024, v11: 512 |
| 18 | * v10: adc channel 0 for dnl key |
| 19 | * v11: adc channel 1 for dnl key |
| 20 | */ |
| 21 | int rockchip_dnl_key_pressed(void) |
| 22 | { |
| 23 | unsigned int key_val, id_val; |
| 24 | int key_ch; |
| 25 | |
| 26 | if (adc_channel_single_shot("saradc", 3, &id_val)) { |
| 27 | printf("%s read board id failed\n", __func__); |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | if (abs(id_val - 1024) <= 30) |
| 32 | key_ch = 0; |
| 33 | else |
| 34 | key_ch = 1; |
| 35 | |
| 36 | if (adc_channel_single_shot("saradc", key_ch, &key_val)) { |
| 37 | printf("%s read adc key val failed\n", __func__); |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | if (key_val >= KEY_DOWN_MIN_VAL && key_val <= KEY_DOWN_MAX_VAL) |
| 42 | return true; |
| 43 | else |
| 44 | return false; |
| 45 | } |