xref: /rk3399_rockchip-uboot/include/key.h (revision f05ce84792cbd2e5573a414010d421eb8fbb7689)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #ifndef _KEY_H_
8 #define _KEY_H_
9 
10 #include <asm-generic/gpio.h>
11 #include <dt-bindings/input/linux-event-codes.h>
12 
13 #define KEY_LONG_DOWN_MS	2000
14 
15 enum {
16 	INVAL_KEY = 0x0,
17 	ADC_KEY   = 0x1,
18 	GPIO_KEY  = 0x2,
19 };
20 
21 enum key_state {
22 	KEY_PRESS_NONE,	/* press without release */
23 	KEY_PRESS_DOWN,	/* press -> release */
24 	KEY_PRESS_LONG_DOWN,
25 	KEY_NOT_EXIST,
26 };
27 
28 struct input_key {
29 	struct udevice *parent;
30 	struct list_head link;
31 	const char *name;
32 	bool pre_reloc;
33 	u32 code;
34 	u8 type;
35 
36 	/* ADC key */
37 	u32 adcval;
38 	u32 vref;
39 	u8 channel;
40 
41 	/* GPIO key */
42 	u32 irq;
43 	struct gpio_desc gpio;
44 
45 	/* Event */
46 	u64 up_t;
47 	u64 down_t;
48 };
49 
50 struct dm_key_ops {
51 	const char *name;
52 };
53 
54 /* Use it instead of get_timer() in key interrupt handler */
55 uint64_t key_timer(uint64_t base);
56 
57 /* Reister you key to dm key framework */
58 void key_add(struct input_key *key);
59 
60 /* Confirm if your key value is a press event */
61 int key_is_pressed(int keyval);
62 
63 /* Read key */
64 int key_read(int code);
65 
66 #endif
67