diff mbox

[U-Boot,02/24] dm: usb: Implement usb_detect_change() for driver model

Message ID 1430760687-28505-3-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass May 4, 2015, 5:30 p.m. UTC
Support this function with driver model also (CONFIG_DM_USB).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/usb/host/usb-uclass.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Joe Hershberger May 4, 2015, 8:55 p.m. UTC | #1
Hi Simon,

On Mon, May 4, 2015 at 12:30 PM, Simon Glass <sjg@chromium.org> wrote:
> Support this function with driver model also (CONFIG_DM_USB).
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/usb/host/usb-uclass.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>
> diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
> index 714bc0e..8445a42 100644
> --- a/drivers/usb/host/usb-uclass.c
> +++ b/drivers/usb/host/usb-uclass.c
> @@ -555,6 +555,49 @@ int usb_scan_device(struct udevice *parent, int port,
>         return 0;
>  }
>
> +/*
> + * Detect if a USB device has been plugged or unplugged.
> + */
> +int usb_detect_change(void)
> +{
> +       struct udevice *hub;
> +       struct uclass *uc;
> +       int change = 0;
> +       int ret;
> +
> +       ret = uclass_get(UCLASS_USB_HUB, &uc);
> +       if (ret)
> +               return ret;
> +
> +       uclass_foreach_dev(hub, uc) {
> +               struct usb_device *udev;
> +               struct udevice *dev;
> +
> +               if (!device_active(hub))
> +                       continue;

You check this here.

> +               for (device_find_first_child(hub, &dev);
> +                    dev;
> +                    device_find_next_child(&dev)) {
> +                       struct usb_port_status status;
> +
> +                       if (!device_active(hub))
> +                               continue;

How can this be true here? Maybe you meant to check if the "dev" was active?

> +
> +                       udev = dev_get_parentdata(hub);

Why parent of the hub? Looking for an upstream hub?

> +                       if (usb_get_port_status(udev, udev->portnr, &status)
> +                                       < 0)
> +                               /* USB request failed */
> +                               continue;
> +
> +                       if (le16_to_cpu(status.wPortChange) &
> +                           USB_PORT_STAT_C_CONNECTION)
> +                               change++;
> +               }
> +       }
> +
> +       return change;
> +}
> +
>  int usb_child_post_bind(struct udevice *dev)
>  {
>         struct usb_dev_platdata *plat = dev_get_parent_platdata(dev);
> --

Thanks,
-Joe
diff mbox

Patch

diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index 714bc0e..8445a42 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -555,6 +555,49 @@  int usb_scan_device(struct udevice *parent, int port,
 	return 0;
 }
 
+/*
+ * Detect if a USB device has been plugged or unplugged.
+ */
+int usb_detect_change(void)
+{
+	struct udevice *hub;
+	struct uclass *uc;
+	int change = 0;
+	int ret;
+
+	ret = uclass_get(UCLASS_USB_HUB, &uc);
+	if (ret)
+		return ret;
+
+	uclass_foreach_dev(hub, uc) {
+		struct usb_device *udev;
+		struct udevice *dev;
+
+		if (!device_active(hub))
+			continue;
+		for (device_find_first_child(hub, &dev);
+		     dev;
+		     device_find_next_child(&dev)) {
+			struct usb_port_status status;
+
+			if (!device_active(hub))
+				continue;
+
+			udev = dev_get_parentdata(hub);
+			if (usb_get_port_status(udev, udev->portnr, &status)
+					< 0)
+				/* USB request failed */
+				continue;
+
+			if (le16_to_cpu(status.wPortChange) &
+			    USB_PORT_STAT_C_CONNECTION)
+				change++;
+		}
+	}
+
+	return change;
+}
+
 int usb_child_post_bind(struct udevice *dev)
 {
 	struct usb_dev_platdata *plat = dev_get_parent_platdata(dev);