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> |
| 8 | |
| 9 | DECLARE_GLOBAL_DATA_PTR; |
| 10 | |
| 11 | #define KEY_DOWN_MIN_VAL 0 |
| 12 | #define KEY_DOWN_MAX_VAL 30 |
| 13 | |
| 14 | /* |
| 15 | * Two board variants whith adc channel 3 is for board id |
| 16 | * v10: 1024, v11: 512 |
| 17 | * v10: adc channel 0 for dnl key |
| 18 | * v11: adc channel 1 for dnl key |
| 19 | */ |
| 20 | int rockchip_dnl_key_pressed(void) |
| 21 | { |
| 22 | unsigned int key_val, id_val; |
| 23 | int key_ch; |
| 24 | |
| 25 | if (adc_channel_single_shot("saradc", 3, &id_val)) { |
| 26 | printf("%s read board id failed\n", __func__); |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | if (abs(id_val - 1024) <= 30) |
| 31 | key_ch = 0; |
| 32 | else |
| 33 | key_ch = 1; |
| 34 | |
| 35 | if (adc_channel_single_shot("saradc", key_ch, &key_val)) { |
| 36 | printf("%s read adc key val failed\n", __func__); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | if (key_val >= KEY_DOWN_MIN_VAL && key_val <= KEY_DOWN_MAX_VAL) |
| 41 | return true; |
| 42 | else |
| 43 | return false; |
| 44 | } |