2017-09-18 11:41:54 +00:00
|
|
|
/*
|
|
|
|
|
* (C) Copyright 2017 Rockchip Electronics Co., Ltd
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _KEY_H_
|
|
|
|
|
#define _KEY_H_
|
|
|
|
|
|
2018-07-19 11:43:59 +00:00
|
|
|
#include <asm-generic/gpio.h>
|
2018-03-06 06:21:32 +00:00
|
|
|
#include <dt-bindings/input/linux-event-codes.h>
|
2018-02-22 07:07:04 +00:00
|
|
|
|
2017-11-28 10:25:53 +00:00
|
|
|
#define KEY_LONG_DOWN_MS 2000
|
|
|
|
|
|
2018-07-19 11:43:59 +00:00
|
|
|
enum {
|
|
|
|
|
INVAL_KEY = 0x0,
|
|
|
|
|
ADC_KEY = 0x1,
|
|
|
|
|
GPIO_KEY = 0x2,
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-18 11:41:54 +00:00
|
|
|
enum key_state {
|
2018-03-20 12:10:37 +00:00
|
|
|
KEY_PRESS_NONE, /* press without release */
|
|
|
|
|
KEY_PRESS_DOWN, /* press -> release */
|
2017-11-28 10:25:53 +00:00
|
|
|
KEY_PRESS_LONG_DOWN,
|
2018-01-30 07:34:49 +00:00
|
|
|
KEY_NOT_EXIST,
|
2017-09-18 11:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2018-01-30 07:34:49 +00:00
|
|
|
struct input_key {
|
2018-07-19 11:43:59 +00:00
|
|
|
struct udevice *parent;
|
|
|
|
|
struct list_head link;
|
2018-01-30 07:34:49 +00:00
|
|
|
const char *name;
|
|
|
|
|
u32 code;
|
2018-07-19 11:43:59 +00:00
|
|
|
u8 type;
|
|
|
|
|
|
|
|
|
|
/* ADC key */
|
|
|
|
|
u32 adcval;
|
2018-01-30 07:34:49 +00:00
|
|
|
u32 vref;
|
2018-07-19 11:43:59 +00:00
|
|
|
u8 channel;
|
2018-01-30 07:34:49 +00:00
|
|
|
|
2018-07-19 11:43:59 +00:00
|
|
|
/* GPIO key */
|
2018-01-30 07:34:49 +00:00
|
|
|
u32 irq;
|
2018-07-19 11:43:59 +00:00
|
|
|
struct gpio_desc gpio;
|
|
|
|
|
|
|
|
|
|
/* Event */
|
2018-01-30 07:34:49 +00:00
|
|
|
u64 up_t;
|
|
|
|
|
u64 down_t;
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-19 11:43:59 +00:00
|
|
|
struct dm_key_ops {
|
|
|
|
|
const char *name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Use it instead of get_timer() in key interrupt handler */
|
|
|
|
|
uint64_t key_timer(uint64_t base);
|
2017-09-18 11:41:54 +00:00
|
|
|
|
2018-07-19 11:43:59 +00:00
|
|
|
/* Reister you key to dm key framework */
|
|
|
|
|
void key_add(struct input_key *key);
|
|
|
|
|
|
|
|
|
|
/* Confirm if your key value is a press event */
|
|
|
|
|
int key_is_pressed(int keyval);
|
|
|
|
|
|
|
|
|
|
/* Read key */
|
|
|
|
|
int key_read(int code);
|
|
|
|
|
|
2017-09-18 11:41:54 +00:00
|
|
|
#endif
|