Commit 697033cbf0a0bf0e0564b08c8b02dd543b431a2f

Authored by Simon Glass
1 parent 603afaf0e5

dm: usb: Support driver model with USB keyboards

Allow USB keyboards to work with driver model. The main difference is that
we can have multiple buses (each with its own device numbering) and each
bus must be scanned.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>

Showing 1 changed file with 33 additions and 1 deletions Side-by-side Diff

... ... @@ -8,6 +8,7 @@
8 8 * SPDX-License-Identifier: GPL-2.0+
9 9 */
10 10 #include <common.h>
  11 +#include <dm.h>
11 12 #include <errno.h>
12 13 #include <malloc.h>
13 14 #include <stdio_dev.h>
... ... @@ -520,7 +521,37 @@
520 521 {
521 522 int error, i;
522 523  
523   - debug("%s: Probing for keyboard\n", __func__);/* Scan all USB Devices */
  524 + debug("%s: Probing for keyboard\n", __func__);
  525 +#ifdef CONFIG_DM_USB
  526 + /*
  527 + * TODO: We should add USB_DEVICE() declarations to each USB ethernet
  528 + * driver and then most of this file can be removed.
  529 + */
  530 + struct udevice *bus;
  531 + struct uclass *uc;
  532 + int ret;
  533 +
  534 + ret = uclass_get(UCLASS_USB, &uc);
  535 + if (ret)
  536 + return ret;
  537 + uclass_foreach_dev(bus, uc) {
  538 + for (i = 0; i < USB_MAX_DEVICE; i++) {
  539 + struct usb_device *dev;
  540 +
  541 + dev = usb_get_dev_index(bus, i); /* get device */
  542 + debug("i=%d, %p\n", i, dev);
  543 + if (!dev)
  544 + break; /* no more devices available */
  545 +
  546 + error = probe_usb_keyboard(dev);
  547 + if (!error)
  548 + return 1;
  549 + if (error && error != -ENOENT)
  550 + return error;
  551 + } /* for */
  552 + }
  553 +#else
  554 + /* Scan all USB Devices */
524 555 for (i = 0; i < USB_MAX_DEVICE; i++) {
525 556 struct usb_device *dev;
526 557  
... ... @@ -538,6 +569,7 @@
538 569 if (error && error != -ENOENT)
539 570 return error;
540 571 }
  572 +#endif
541 573  
542 574 /* No USB Keyboard found */
543 575 return -1;