1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
10 static int keyboard_start(struct stdio_dev *sdev)
12 struct udevice *dev = sdev->priv;
13 struct keyboard_ops *ops = keyboard_get_ops(dev);
16 return ops->start(dev);
21 static int keyboard_stop(struct stdio_dev *sdev)
23 struct udevice *dev = sdev->priv;
24 struct keyboard_ops *ops = keyboard_get_ops(dev);
27 return ops->stop(dev);
32 static int keyboard_tstc(struct stdio_dev *sdev)
34 struct udevice *dev = sdev->priv;
35 struct keyboard_priv *priv = dev_get_uclass_priv(dev);
36 struct keyboard_ops *ops = keyboard_get_ops(dev);
38 /* Just get input to do this for us if we can */
40 return input_tstc(&priv->input);
42 return ops->tstc(dev);
47 static int keyboard_getc(struct stdio_dev *sdev)
49 struct udevice *dev = sdev->priv;
50 struct keyboard_priv *priv = dev_get_uclass_priv(dev);
51 struct keyboard_ops *ops = keyboard_get_ops(dev);
53 /* Just get input to do this for us if we can */
55 return input_getc(&priv->input);
57 return ops->getc(dev);
62 static int keyboard_pre_probe(struct udevice *dev)
64 struct keyboard_priv *priv = dev_get_uclass_priv(dev);
65 struct stdio_dev *sdev = &priv->sdev;
68 strlcpy(sdev->name, dev->name, sizeof(sdev->name));
69 sdev->flags = DEV_FLAGS_INPUT;
70 sdev->getc = keyboard_getc;
71 sdev->tstc = keyboard_tstc;
72 sdev->start = keyboard_start;
73 sdev->stop = keyboard_stop;
75 ret = input_init(&priv->input, 0);
77 debug("%s: Cannot set up input, ret=%d - please add DEBUG to drivers/input/input.c to figure out the cause\n",
85 UCLASS_DRIVER(keyboard) = {
86 .id = UCLASS_KEYBOARD,
88 .pre_probe = keyboard_pre_probe,
89 .per_device_auto_alloc_size = sizeof(struct keyboard_priv),