summaryrefslogtreecommitdiffstats
path: root/common/usb_kbd.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-09-08 11:15:11 -0600
committerSimon Glass <sjg@chromium.org>2015-11-19 20:13:39 -0700
commit34ab37eef5a5f8023abc657ab38f7b9fe11c38b3 (patch)
tree3a8917301e9cffb9286c343a04f45316d4d164da /common/usb_kbd.c
parent2b24e09c66480f3723b137f434a6c3b0db764817 (diff)
downloadblackbird-obmc-uboot-34ab37eef5a5f8023abc657ab38f7b9fe11c38b3.tar.gz
blackbird-obmc-uboot-34ab37eef5a5f8023abc657ab38f7b9fe11c38b3.zip
dm: usb: Add support for USB keyboards with driver model
Switch USB keyboards over to use driver model instead of scanning with the horrible usb_get_dev_index() function. This involves creating a new uclass for keyboards, although so far there is no API. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/usb_kbd.c')
-rw-r--r--common/usb_kbd.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index 0302e5bc93..137ec65e19 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -399,7 +399,7 @@ static int usb_kbd_getc(struct stdio_dev *sdev)
}
/* probes the USB device dev for keyboard type. */
-static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
+static int usb_kbd_probe_dev(struct usb_device *dev, unsigned int ifnum)
{
struct usb_interface *iface;
struct usb_endpoint_descriptor *ep;
@@ -496,7 +496,7 @@ static int probe_usb_keyboard(struct usb_device *dev)
int error;
/* Try probing the keyboard */
- if (usb_kbd_probe(dev, 0) != 1)
+ if (usb_kbd_probe_dev(dev, 0) != 1)
return -ENOENT;
/* Register the keyboard */
@@ -533,6 +533,7 @@ static int probe_usb_keyboard(struct usb_device *dev)
return 0;
}
+#ifndef CONFIG_DM_USB
/* Search for keyboard and register it if found. */
int drv_usb_kbd_init(void)
{
@@ -591,6 +592,7 @@ int drv_usb_kbd_init(void)
/* No USB Keyboard found */
return -1;
}
+#endif
/* Deregister the keyboard. */
int usb_kbd_deregister(int force)
@@ -622,3 +624,49 @@ int usb_kbd_deregister(int force)
return 1;
#endif
}
+
+#ifdef CONFIG_DM_USB
+
+static int usb_kbd_probe(struct udevice *dev)
+{
+ struct usb_device *udev = dev_get_parent_priv(dev);
+ int ret;
+
+ ret = probe_usb_keyboard(udev);
+
+ return ret;
+}
+
+static const struct udevice_id usb_kbd_ids[] = {
+ { .compatible = "usb-keyboard" },
+ { }
+};
+
+U_BOOT_DRIVER(usb_kbd) = {
+ .name = "usb_kbd",
+ .id = UCLASS_KEYBOARD,
+ .of_match = usb_kbd_ids,
+ .probe = usb_kbd_probe,
+};
+
+/* TODO(sjg@chromium.org): Move this into a common location */
+UCLASS_DRIVER(keyboard) = {
+ .id = UCLASS_KEYBOARD,
+ .name = "keyboard",
+};
+
+static const struct usb_device_id kbd_id_table[] = {
+ {
+ .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
+ USB_DEVICE_ID_MATCH_INT_SUBCLASS |
+ USB_DEVICE_ID_MATCH_INT_PROTOCOL,
+ .bInterfaceClass = USB_CLASS_HID,
+ .bInterfaceSubClass = 1,
+ .bInterfaceProtocol = 1,
+ },
+ { } /* Terminating entry */
+};
+
+U_BOOT_USB_DEVICE(usb_kbd, kbd_id_table);
+
+#endif
OpenPOWER on IntegriCloud