xref: /OK3568_Linux_fs/u-boot/include/key.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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_event {
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 dm_key_uclass_platdata {
29 	const char *name;
30 	bool pre_reloc;
31 	u32 code;
32 	u8 type;
33 
34 	/* ADC key */
35 	u8 channel;
36 	int in_volt;
37 	int center;
38 	int min;
39 	int max;
40 
41 	/* GPIO key */
42 	u32 irq;
43 	u32 gpios[2];	/* gpios[0]: gpio controller phandle, gpios[1]: pin */
44 	struct gpio_desc gpio;
45 
46 	u64 rise_ms;
47 	u64 fall_ms;
48 
49 	u32 trig_cnt;
50 
51 	int skip_irq_init;
52 
53 	/* Only for pwrkey gpio irq */
54 	void (*irq_thread)(int irq, struct udevice *dev);
55 };
56 
57 /* Use it instead of get_timer() in key interrupt handler */
58 uint64_t key_timer(uint64_t base);
59 
60 /* Confirm if your key value is a press event */
61 int key_is_pressed(int keyval);
62 
63 /* Pwrkey download mode init */
64 int pwrkey_download_init(void);
65 
66 /* Read key */
67 int key_read(int code);
68 
69 /* Check whether the key is exist or not, 1: exist, 0: not exist */
70 int key_exist(int code);
71 
72 int key_bind_children(struct udevice *dev, const char *drv_name);
73 
74 #endif
75