2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-19 03:17:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
2021-04-27 09:02:19 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_KEYBOARD
|
|
|
|
|
2015-10-19 03:17:10 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <keyboard.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2015-10-19 03:17:10 +00:00
|
|
|
|
|
|
|
static int keyboard_start(struct stdio_dev *sdev)
|
|
|
|
{
|
|
|
|
struct udevice *dev = sdev->priv;
|
|
|
|
struct keyboard_ops *ops = keyboard_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->start)
|
|
|
|
return ops->start(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keyboard_stop(struct stdio_dev *sdev)
|
|
|
|
{
|
|
|
|
struct udevice *dev = sdev->priv;
|
|
|
|
struct keyboard_ops *ops = keyboard_get_ops(dev);
|
|
|
|
|
|
|
|
if (ops->stop)
|
|
|
|
return ops->stop(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keyboard_tstc(struct stdio_dev *sdev)
|
|
|
|
{
|
|
|
|
struct udevice *dev = sdev->priv;
|
|
|
|
struct keyboard_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
struct keyboard_ops *ops = keyboard_get_ops(dev);
|
|
|
|
|
|
|
|
/* Just get input to do this for us if we can */
|
|
|
|
if (priv->input.dev)
|
|
|
|
return input_tstc(&priv->input);
|
|
|
|
else if (ops->tstc)
|
|
|
|
return ops->tstc(dev);
|
|
|
|
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keyboard_getc(struct stdio_dev *sdev)
|
|
|
|
{
|
|
|
|
struct udevice *dev = sdev->priv;
|
|
|
|
struct keyboard_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
struct keyboard_ops *ops = keyboard_get_ops(dev);
|
|
|
|
|
|
|
|
/* Just get input to do this for us if we can */
|
|
|
|
if (priv->input.dev)
|
|
|
|
return input_getc(&priv->input);
|
|
|
|
else if (ops->getc)
|
|
|
|
return ops->getc(dev);
|
|
|
|
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keyboard_pre_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct keyboard_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
struct stdio_dev *sdev = &priv->sdev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
strlcpy(sdev->name, dev->name, sizeof(sdev->name));
|
|
|
|
sdev->flags = DEV_FLAGS_INPUT;
|
|
|
|
sdev->getc = keyboard_getc;
|
|
|
|
sdev->tstc = keyboard_tstc;
|
|
|
|
sdev->start = keyboard_start;
|
|
|
|
sdev->stop = keyboard_stop;
|
|
|
|
sdev->priv = dev;
|
|
|
|
ret = input_init(&priv->input, 0);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Cannot set up input, ret=%d - please add DEBUG to drivers/input/input.c to figure out the cause\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCLASS_DRIVER(keyboard) = {
|
|
|
|
.id = UCLASS_KEYBOARD,
|
|
|
|
.name = "keyboard",
|
|
|
|
.pre_probe = keyboard_pre_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.per_device_auto = sizeof(struct keyboard_priv),
|
2015-10-19 03:17:10 +00:00
|
|
|
};
|