hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
 *
 * SPDX-License-Identifier:     GPL-2.0+
 */
 
#ifndef _KEY_H_
#define _KEY_H_
 
#include <asm-generic/gpio.h>
#include <dt-bindings/input/linux-event-codes.h>
 
#define KEY_LONG_DOWN_MS    2000
 
enum {
   INVAL_KEY = 0x0,
   ADC_KEY   = 0x1,
   GPIO_KEY  = 0x2,
};
 
enum key_event {
   KEY_PRESS_NONE,    /* press without release */
   KEY_PRESS_DOWN,    /* press -> release */
   KEY_PRESS_LONG_DOWN,
   KEY_NOT_EXIST,
};
 
struct dm_key_uclass_platdata {
   const char *name;
   bool pre_reloc;
   u32 code;
   u8 type;
 
   /* ADC key */
   u8 channel;
   int in_volt;
   int center;
   int min;
   int max;
 
   /* GPIO key */
   u32 irq;
   u32 gpios[2];    /* gpios[0]: gpio controller phandle, gpios[1]: pin */
   struct gpio_desc gpio;
 
   u64 rise_ms;
   u64 fall_ms;
 
   u32 trig_cnt;
 
   int skip_irq_init;
 
   /* Only for pwrkey gpio irq */
   void (*irq_thread)(int irq, struct udevice *dev);
};
 
/* Use it instead of get_timer() in key interrupt handler */
uint64_t key_timer(uint64_t base);
 
/* Confirm if your key value is a press event */
int key_is_pressed(int keyval);
 
/* Pwrkey download mode init */
int pwrkey_download_init(void);
 
/* Read key */
int key_read(int code);
 
/* Check whether the key is exist or not, 1: exist, 0: not exist */
int key_exist(int code);
 
int key_bind_children(struct udevice *dev, const char *drv_name);
 
#endif