aboutsummaryrefslogtreecommitdiff
path: root/include/keyboard.h
diff options
context:
space:
mode:
authorSimon Glass2015-10-18 21:17:10 -0600
committerSimon Glass2015-11-19 20:13:39 -0700
commite84421d8f3fe4f4b6956c9045b22729383620442 (patch)
tree81d2d363b1b9e72e05987bcd673e53e38c43d327 /include/keyboard.h
parent34ab37eef5a5f8023abc657ab38f7b9fe11c38b3 (diff)
dm: input: Create a keyboard uclass
Add a uclass for keyboard input, mirroring the existing stdio methods. This is enabled by a new CONFIG_DM_KEYBOARD option. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'include/keyboard.h')
-rw-r--r--include/keyboard.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/include/keyboard.h b/include/keyboard.h
index 88ae12bc0f3..5216d59fb78 100644
--- a/include/keyboard.h
+++ b/include/keyboard.h
@@ -1,6 +1,84 @@
#ifndef __KEYBOARD_H
#define __KEYBOARD_H
+#ifdef CONFIG_DM_KEYBOARD
+#include <input.h>
+#include <stdio_dev.h>
+
+/**
+ * struct keyboard_priv - information about a keyboard, for the uclass
+ *
+ * @sdev: stdio device
+ * @input: input configuration (the driver may use this if desired)
+ */
+struct keyboard_priv {
+ struct stdio_dev sdev;
+
+ /*
+ * This is set up by the uclass but will only be used if the driver
+ * sets input.dev to its device pointer (it is initially NULL).
+ */
+ struct input_config input;
+};
+
+/**
+ * struct keyboard_ops - keyboard device operations
+ */
+struct keyboard_ops {
+ /**
+ * start() - enable the keyboard ready for use
+ *
+ * @dev: Device to enable
+ * @return 0 if OK, -ve on error
+ */
+ int (*start)(struct udevice *dev);
+
+ /**
+ * stop() - disable the keyboard when no-longer needed
+ *
+ * @dev: Device to disable
+ * @return 0 if OK, -ve on error
+ */
+ int (*stop)(struct udevice *dev);
+
+ /**
+ * tstc() - check if a key is available
+ *
+ * @dev: Device to check
+ * @return 0 if no key is available, 1 if a key is available, -ve on
+ * error
+ */
+ int (*tstc)(struct udevice *dev);
+
+ /**
+ * getc() - get a key
+ *
+ * TODO(sjg@chromium.org): At present this method may wait if it calls
+ * input_getc().
+ *
+ * @dev: Device to read from
+ * @return -EAGAIN if no key is available, otherwise key value read
+ * (as ASCII).
+ */
+ int (*getc)(struct udevice *dev);
+
+ /**
+ * update_leds() - update keyboard LEDs
+ *
+ * This is called when the LEDs have changed and need to be updated.
+ * For example, if 'caps lock' is pressed then this method will be
+ * called with the new LED value.
+ *
+ * @dev: Device to update
+ * @leds: New LED mask (see INPUT_LED_... in input.h)
+ */
+ int (*update_leds)(struct udevice *dev, int leds);
+};
+
+#define keyboard_get_ops(dev) ((struct keyboard_ops *)(dev)->driver->ops)
+
+#else
+
#ifdef CONFIG_PS2MULT
#include <ps2mult.h>
#endif
@@ -18,5 +96,6 @@ extern int kbd_init (void);
extern void handle_scancode(unsigned char scancode);
extern int kbd_init_hw(void);
extern void pckbd_leds(unsigned char leds);
+#endif /* !CONFIG_DM_KEYBOARD */
#endif /* __KEYBOARD_H */