dm: key: provide universal key read interface
clean up code. Change-Id: I532be111dc971ff0fdd9014e7e01a13ea50483fd Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
6e806ac8f7
commit
a2df960601
|
|
@ -6,35 +6,62 @@
|
|||
|
||||
#include <dm.h>
|
||||
#include <key.h>
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
|
||||
int key_read(struct udevice *dev)
|
||||
static inline uint64_t arch_counter_get_cntpct(void)
|
||||
{
|
||||
uint64_t cval = 0;
|
||||
|
||||
isb();
|
||||
#ifdef CONFIG_ARM64
|
||||
asm volatile("mrs %0, cntpct_el0" : "=r" (cval));
|
||||
#else
|
||||
asm volatile ("mrrc p15, 0, %Q0, %R0, c14" : "=r" (cval));
|
||||
#endif
|
||||
return cval;
|
||||
}
|
||||
|
||||
uint64_t key_get_timer(uint64_t base)
|
||||
{
|
||||
uint64_t cntpct;
|
||||
|
||||
cntpct = arch_counter_get_cntpct() / 24000UL;
|
||||
return (cntpct > base) ? (cntpct - base) : 0;
|
||||
}
|
||||
|
||||
static int key_state_valid(int state)
|
||||
{
|
||||
return (state >= KEY_PRESS_NONE && state < KEY_NOT_EXIST);
|
||||
}
|
||||
|
||||
static int key_read(struct udevice *dev, int code)
|
||||
{
|
||||
const struct dm_key_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->read)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->read(dev);
|
||||
return ops->read(dev, code);
|
||||
}
|
||||
|
||||
int key_type(struct udevice *dev)
|
||||
int platform_key_read(int code)
|
||||
{
|
||||
const struct dm_key_ops *ops = dev_get_driver_ops(dev);
|
||||
struct udevice *dev;
|
||||
int report = KEY_NOT_EXIST;
|
||||
|
||||
if (!ops || !ops->type)
|
||||
return -ENOSYS;
|
||||
for (uclass_first_device(UCLASS_KEY, &dev);
|
||||
dev;
|
||||
uclass_next_device(&dev)) {
|
||||
debug("key dev.name = %s, code = %d\n", dev->name, code);
|
||||
report = key_read(dev, code);
|
||||
if (key_state_valid(report)) {
|
||||
debug("key dev.name = %s, state=%d\n", dev->name, report);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ops->type;
|
||||
}
|
||||
|
||||
const char *key_name(struct udevice *dev)
|
||||
{
|
||||
const struct dm_key_ops *ops = dev_get_driver_ops(dev);
|
||||
|
||||
if (!ops || !ops->name)
|
||||
return NULL;
|
||||
|
||||
return ops->name;
|
||||
return report;
|
||||
}
|
||||
|
||||
UCLASS_DRIVER(key) = {
|
||||
|
|
|
|||
|
|
@ -14,16 +14,31 @@ enum key_state {
|
|||
KEY_PRESS_UP,
|
||||
KEY_PRESS_DOWN,
|
||||
KEY_PRESS_LONG_DOWN,
|
||||
KEY_NOT_EXIST,
|
||||
};
|
||||
|
||||
struct dm_key_ops {
|
||||
int type;
|
||||
const char *name;
|
||||
int (*read)(struct udevice *dev);
|
||||
int (*read)(struct udevice *dev, int code);
|
||||
int (*exist)(struct udevice *dev, int code);
|
||||
};
|
||||
|
||||
int key_read(struct udevice *dev);
|
||||
int key_type(struct udevice *dev);
|
||||
const char *key_label(struct udevice *dev);
|
||||
struct input_key {
|
||||
const char *name;
|
||||
u32 code;
|
||||
u32 channel;
|
||||
u32 value;
|
||||
u32 margin;
|
||||
u32 vref;
|
||||
int flag;
|
||||
|
||||
u32 irq;
|
||||
u64 up_t;
|
||||
u64 down_t;
|
||||
};
|
||||
|
||||
uint64_t key_get_timer(uint64_t base);
|
||||
int platform_key_read(int code);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue