xref: /rk3399_rockchip-uboot/common/usb_hub.c (revision f7f601002d26cd5afc2241728a1e4d6106044184)
1 /*
2  * Most of this source has been derived from the Linux USB
3  * project:
4  * (C) Copyright Linus Torvalds 1999
5  * (C) Copyright Johannes Erdfelt 1999-2001
6  * (C) Copyright Andreas Gal 1999
7  * (C) Copyright Gregory P. Smith 1999
8  * (C) Copyright Deti Fliegl 1999 (new USB architecture)
9  * (C) Copyright Randy Dunlap 2000
10  * (C) Copyright David Brownell 2000 (kernel hotplug, usb_device_id)
11  * (C) Copyright Yggdrasil Computing, Inc. 2000
12  *     (usb_device_id matching changes by Adam J. Richter)
13  *
14  * Adapted for U-Boot:
15  * (C) Copyright 2001 Denis Peter, MPL AG Switzerland
16  *
17  * SPDX-License-Identifier:	GPL-2.0+
18  */
19 
20 /****************************************************************************
21  * HUB "Driver"
22  * Probes device for being a hub and configurate it
23  */
24 
25 #include <common.h>
26 #include <command.h>
27 #include <dm.h>
28 #include <errno.h>
29 #include <memalign.h>
30 #include <asm/processor.h>
31 #include <asm/unaligned.h>
32 #include <linux/ctype.h>
33 #include <asm/byteorder.h>
34 #ifdef CONFIG_SANDBOX
35 #include <asm/state.h>
36 #endif
37 #include <asm/unaligned.h>
38 #include <dm/root.h>
39 
40 DECLARE_GLOBAL_DATA_PTR;
41 
42 #include <usb.h>
43 #ifdef CONFIG_4xx
44 #include <asm/4xx_pci.h>
45 #endif
46 
47 #define USB_BUFSIZ	512
48 
49 #define HUB_SHORT_RESET_TIME	20
50 #define HUB_LONG_RESET_TIME	200
51 
52 /* TODO(sjg@chromium.org): Remove this when CONFIG_DM_USB is defined */
53 static struct usb_hub_device hub_dev[USB_MAX_HUB];
54 static int usb_hub_index;
55 
56 __weak void usb_hub_reset_devices(int port)
57 {
58 	return;
59 }
60 
61 static int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
62 {
63 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
64 		USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
65 		USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT);
66 }
67 
68 static int usb_clear_port_feature(struct usb_device *dev, int port, int feature)
69 {
70 	return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
71 				USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature,
72 				port, NULL, 0, USB_CNTL_TIMEOUT);
73 }
74 
75 static int usb_set_port_feature(struct usb_device *dev, int port, int feature)
76 {
77 	return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
78 				USB_REQ_SET_FEATURE, USB_RT_PORT, feature,
79 				port, NULL, 0, USB_CNTL_TIMEOUT);
80 }
81 
82 static int usb_get_hub_status(struct usb_device *dev, void *data)
83 {
84 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
85 			USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0,
86 			data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
87 }
88 
89 int usb_get_port_status(struct usb_device *dev, int port, void *data)
90 {
91 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
92 			USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port,
93 			data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
94 }
95 
96 
97 static void usb_hub_power_on(struct usb_hub_device *hub)
98 {
99 	int i;
100 	struct usb_device *dev;
101 	unsigned pgood_delay = hub->desc.bPwrOn2PwrGood * 2;
102 	const char *env;
103 
104 	dev = hub->pusb_dev;
105 
106 	debug("enabling power on all ports\n");
107 	for (i = 0; i < dev->maxchild; i++) {
108 		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
109 		debug("port %d returns %lX\n", i + 1, dev->status);
110 	}
111 
112 	/*
113 	 * Wait for power to become stable,
114 	 * plus spec-defined max time for device to connect
115 	 * but allow this time to be increased via env variable as some
116 	 * devices break the spec and require longer warm-up times
117 	 */
118 	env = getenv("usb_pgood_delay");
119 	if (env)
120 		pgood_delay = max(pgood_delay,
121 			          (unsigned)simple_strtol(env, NULL, 0));
122 	debug("pgood_delay=%dms\n", pgood_delay);
123 	mdelay(pgood_delay + 1000);
124 }
125 
126 void usb_hub_reset(void)
127 {
128 	usb_hub_index = 0;
129 }
130 
131 static struct usb_hub_device *usb_hub_allocate(void)
132 {
133 	if (usb_hub_index < USB_MAX_HUB)
134 		return &hub_dev[usb_hub_index++];
135 
136 	printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB);
137 	return NULL;
138 }
139 
140 #define MAX_TRIES 5
141 
142 static inline char *portspeed(int portstatus)
143 {
144 	char *speed_str;
145 
146 	switch (portstatus & USB_PORT_STAT_SPEED_MASK) {
147 	case USB_PORT_STAT_SUPER_SPEED:
148 		speed_str = "5 Gb/s";
149 		break;
150 	case USB_PORT_STAT_HIGH_SPEED:
151 		speed_str = "480 Mb/s";
152 		break;
153 	case USB_PORT_STAT_LOW_SPEED:
154 		speed_str = "1.5 Mb/s";
155 		break;
156 	default:
157 		speed_str = "12 Mb/s";
158 		break;
159 	}
160 
161 	return speed_str;
162 }
163 
164 int legacy_hub_port_reset(struct usb_device *dev, int port,
165 			unsigned short *portstat)
166 {
167 	int err, tries;
168 	ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);
169 	unsigned short portstatus, portchange;
170 	int delay = HUB_SHORT_RESET_TIME; /* start with short reset delay */
171 
172 #ifdef CONFIG_DM_USB
173 	debug("%s: resetting '%s' port %d...\n", __func__, dev->dev->name,
174 	      port + 1);
175 #else
176 	debug("%s: resetting port %d...\n", __func__, port + 1);
177 #endif
178 	for (tries = 0; tries < MAX_TRIES; tries++) {
179 		err = usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
180 		if (err < 0)
181 			return err;
182 
183 		mdelay(delay);
184 
185 		if (usb_get_port_status(dev, port + 1, portsts) < 0) {
186 			debug("get_port_status failed status %lX\n",
187 			      dev->status);
188 			return -1;
189 		}
190 		portstatus = le16_to_cpu(portsts->wPortStatus);
191 		portchange = le16_to_cpu(portsts->wPortChange);
192 
193 		debug("portstatus %x, change %x, %s\n", portstatus, portchange,
194 							portspeed(portstatus));
195 
196 		debug("STAT_C_CONNECTION = %d STAT_CONNECTION = %d" \
197 		      "  USB_PORT_STAT_ENABLE %d\n",
198 		      (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0,
199 		      (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0,
200 		      (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
201 
202 		/*
203 		 * Perhaps we should check for the following here:
204 		 * - C_CONNECTION hasn't been set.
205 		 * - CONNECTION is still set.
206 		 *
207 		 * Doing so would ensure that the device is still connected
208 		 * to the bus, and hasn't been unplugged or replaced while the
209 		 * USB bus reset was going on.
210 		 *
211 		 * However, if we do that, then (at least) a San Disk Ultra
212 		 * USB 3.0 16GB device fails to reset on (at least) an NVIDIA
213 		 * Tegra Jetson TK1 board. For some reason, the device appears
214 		 * to briefly drop off the bus when this second bus reset is
215 		 * executed, yet if we retry this loop, it'll eventually come
216 		 * back after another reset or two.
217 		 */
218 
219 		if (portstatus & USB_PORT_STAT_ENABLE)
220 			break;
221 
222 		/* Switch to long reset delay for the next round */
223 		delay = HUB_LONG_RESET_TIME;
224 	}
225 
226 	if (tries == MAX_TRIES) {
227 		debug("Cannot enable port %i after %i retries, " \
228 		      "disabling port.\n", port + 1, MAX_TRIES);
229 		debug("Maybe the USB cable is bad?\n");
230 		return -1;
231 	}
232 
233 	usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET);
234 	*portstat = portstatus;
235 	return 0;
236 }
237 
238 #ifdef CONFIG_DM_USB
239 int hub_port_reset(struct udevice *dev, int port, unsigned short *portstat)
240 {
241 	struct usb_device *udev = dev_get_parent_priv(dev);
242 
243 	return legacy_hub_port_reset(udev, port, portstat);
244 }
245 #endif
246 
247 int usb_hub_port_connect_change(struct usb_device *dev, int port)
248 {
249 	ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);
250 	unsigned short portstatus;
251 	int ret, speed;
252 
253 	/* Check status */
254 	ret = usb_get_port_status(dev, port + 1, portsts);
255 	if (ret < 0) {
256 		debug("get_port_status failed\n");
257 		return ret;
258 	}
259 
260 	portstatus = le16_to_cpu(portsts->wPortStatus);
261 	debug("portstatus %x, change %x, %s\n",
262 	      portstatus,
263 	      le16_to_cpu(portsts->wPortChange),
264 	      portspeed(portstatus));
265 
266 	/* Clear the connection change status */
267 	usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
268 
269 	/* Disconnect any existing devices under this port */
270 	if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
271 	     (!(portstatus & USB_PORT_STAT_ENABLE))) ||
272 	    usb_device_has_child_on_port(dev, port)) {
273 		debug("usb_disconnect(&hub->children[port]);\n");
274 		/* Return now if nothing is connected */
275 		if (!(portstatus & USB_PORT_STAT_CONNECTION))
276 			return -ENOTCONN;
277 	}
278 	mdelay(200);
279 
280 	/* Reset the port */
281 	ret = legacy_hub_port_reset(dev, port, &portstatus);
282 	if (ret < 0) {
283 		if (ret != -ENXIO)
284 			printf("cannot reset port %i!?\n", port + 1);
285 		return ret;
286 	}
287 
288 	mdelay(200);
289 
290 	switch (portstatus & USB_PORT_STAT_SPEED_MASK) {
291 	case USB_PORT_STAT_SUPER_SPEED:
292 		speed = USB_SPEED_SUPER;
293 		break;
294 	case USB_PORT_STAT_HIGH_SPEED:
295 		speed = USB_SPEED_HIGH;
296 		break;
297 	case USB_PORT_STAT_LOW_SPEED:
298 		speed = USB_SPEED_LOW;
299 		break;
300 	default:
301 		speed = USB_SPEED_FULL;
302 		break;
303 	}
304 
305 #ifdef CONFIG_DM_USB
306 	struct udevice *child;
307 
308 	ret = usb_scan_device(dev->dev, port + 1, speed, &child);
309 #else
310 	struct usb_device *usb;
311 
312 	ret = usb_alloc_new_device(dev->controller, &usb);
313 	if (ret) {
314 		printf("cannot create new device: ret=%d", ret);
315 		return ret;
316 	}
317 
318 	dev->children[port] = usb;
319 	usb->speed = speed;
320 	usb->parent = dev;
321 	usb->portnr = port + 1;
322 	/* Run it through the hoops (find a driver, etc) */
323 	ret = usb_new_device(usb);
324 	if (ret < 0) {
325 		/* Woops, disable the port */
326 		usb_free_device(dev->controller);
327 		dev->children[port] = NULL;
328 	}
329 #endif
330 	if (ret < 0) {
331 		debug("hub: disabling port %d\n", port + 1);
332 		usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
333 	}
334 
335 	return ret;
336 }
337 
338 
339 static int usb_hub_configure(struct usb_device *dev)
340 {
341 	int i, length;
342 	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
343 	unsigned char *bitmap;
344 	short hubCharacteristics;
345 	struct usb_hub_descriptor *descriptor;
346 	struct usb_hub_device *hub;
347 	__maybe_unused struct usb_hub_status *hubsts;
348 	int ret;
349 
350 	/* "allocate" Hub device */
351 	hub = usb_hub_allocate();
352 	if (hub == NULL)
353 		return -ENOMEM;
354 	hub->pusb_dev = dev;
355 	/* Get the the hub descriptor */
356 	ret = usb_get_hub_descriptor(dev, buffer, 4);
357 	if (ret < 0) {
358 		debug("usb_hub_configure: failed to get hub " \
359 		      "descriptor, giving up %lX\n", dev->status);
360 		return ret;
361 	}
362 	descriptor = (struct usb_hub_descriptor *)buffer;
363 
364 	length = min_t(int, descriptor->bLength,
365 		       sizeof(struct usb_hub_descriptor));
366 
367 	ret = usb_get_hub_descriptor(dev, buffer, length);
368 	if (ret < 0) {
369 		debug("usb_hub_configure: failed to get hub " \
370 		      "descriptor 2nd giving up %lX\n", dev->status);
371 		return ret;
372 	}
373 	memcpy((unsigned char *)&hub->desc, buffer, length);
374 	/* adjust 16bit values */
375 	put_unaligned(le16_to_cpu(get_unaligned(
376 			&descriptor->wHubCharacteristics)),
377 			&hub->desc.wHubCharacteristics);
378 	/* set the bitmap */
379 	bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
380 	/* devices not removable by default */
381 	memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8);
382 	bitmap = (unsigned char *)&hub->desc.PortPowerCtrlMask[0];
383 	memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
384 
385 	for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
386 		hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
387 
388 	for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
389 		hub->desc.PortPowerCtrlMask[i] = descriptor->PortPowerCtrlMask[i];
390 
391 	dev->maxchild = descriptor->bNbrPorts;
392 	debug("%d ports detected\n", dev->maxchild);
393 
394 	hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics);
395 	switch (hubCharacteristics & HUB_CHAR_LPSM) {
396 	case 0x00:
397 		debug("ganged power switching\n");
398 		break;
399 	case 0x01:
400 		debug("individual port power switching\n");
401 		break;
402 	case 0x02:
403 	case 0x03:
404 		debug("unknown reserved power switching mode\n");
405 		break;
406 	}
407 
408 	if (hubCharacteristics & HUB_CHAR_COMPOUND)
409 		debug("part of a compound device\n");
410 	else
411 		debug("standalone hub\n");
412 
413 	switch (hubCharacteristics & HUB_CHAR_OCPM) {
414 	case 0x00:
415 		debug("global over-current protection\n");
416 		break;
417 	case 0x08:
418 		debug("individual port over-current protection\n");
419 		break;
420 	case 0x10:
421 	case 0x18:
422 		debug("no over-current protection\n");
423 		break;
424 	}
425 
426 	debug("power on to power good time: %dms\n",
427 	      descriptor->bPwrOn2PwrGood * 2);
428 	debug("hub controller current requirement: %dmA\n",
429 	      descriptor->bHubContrCurrent);
430 
431 	for (i = 0; i < dev->maxchild; i++)
432 		debug("port %d is%s removable\n", i + 1,
433 		      hub->desc.DeviceRemovable[(i + 1) / 8] & \
434 		      (1 << ((i + 1) % 8)) ? " not" : "");
435 
436 	if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
437 		debug("usb_hub_configure: failed to get Status - " \
438 		      "too long: %d\n", descriptor->bLength);
439 		return -EFBIG;
440 	}
441 
442 	ret = usb_get_hub_status(dev, buffer);
443 	if (ret < 0) {
444 		debug("usb_hub_configure: failed to get Status %lX\n",
445 		      dev->status);
446 		return ret;
447 	}
448 
449 #ifdef DEBUG
450 	hubsts = (struct usb_hub_status *)buffer;
451 #endif
452 
453 	debug("get_hub_status returned status %X, change %X\n",
454 	      le16_to_cpu(hubsts->wHubStatus),
455 	      le16_to_cpu(hubsts->wHubChange));
456 	debug("local power source is %s\n",
457 	      (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? \
458 	      "lost (inactive)" : "good");
459 	debug("%sover-current condition exists\n",
460 	      (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? \
461 	      "" : "no ");
462 	usb_hub_power_on(hub);
463 
464 	/*
465 	 * Reset any devices that may be in a bad state when applying
466 	 * the power.  This is a __weak function.  Resetting of the devices
467 	 * should occur in the board file of the device.
468 	 */
469 	for (i = 0; i < dev->maxchild; i++)
470 		usb_hub_reset_devices(i + 1);
471 
472 	for (i = 0; i < dev->maxchild; i++) {
473 		ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);
474 		unsigned short portstatus, portchange;
475 		int ret;
476 		ulong start = get_timer(0);
477 		uint delay = CONFIG_SYS_HZ;
478 
479 #ifdef CONFIG_SANDBOX
480 		if (state_get_skip_delays())
481 			delay = 0;
482 #endif
483 #ifdef CONFIG_DM_USB
484 		debug("\n\nScanning '%s' port %d\n", dev->dev->name, i + 1);
485 #else
486 		debug("\n\nScanning port %d\n", i + 1);
487 #endif
488 		/*
489 		 * Wait for (whichever finishes first)
490 		 *  - A maximum of 10 seconds
491 		 *    This is a purely observational value driven by connecting
492 		 *    a few broken pen drives and taking the max * 1.5 approach
493 		 *  - connection_change and connection state to report same
494 		 *    state
495 		 */
496 		do {
497 			ret = usb_get_port_status(dev, i + 1, portsts);
498 			if (ret < 0) {
499 				debug("get_port_status failed\n");
500 				break;
501 			}
502 
503 			portstatus = le16_to_cpu(portsts->wPortStatus);
504 			portchange = le16_to_cpu(portsts->wPortChange);
505 
506 			/* No connection change happened, wait a bit more. */
507 			if (!(portchange & USB_PORT_STAT_C_CONNECTION))
508 				continue;
509 
510 			/* Test if the connection came up, and if so, exit. */
511 			if (portstatus & USB_PORT_STAT_CONNECTION)
512 				break;
513 
514 		} while (get_timer(start) < delay);
515 
516 		if (ret < 0)
517 			continue;
518 
519 		debug("Port %d Status %X Change %X\n",
520 		      i + 1, portstatus, portchange);
521 
522 		if (portchange & USB_PORT_STAT_C_CONNECTION) {
523 			debug("port %d connection change\n", i + 1);
524 			usb_hub_port_connect_change(dev, i);
525 		}
526 		if (portchange & USB_PORT_STAT_C_ENABLE) {
527 			debug("port %d enable change, status %x\n",
528 			      i + 1, portstatus);
529 			usb_clear_port_feature(dev, i + 1,
530 						USB_PORT_FEAT_C_ENABLE);
531 			/*
532 			 * The following hack causes a ghost device problem
533 			 * to Faraday EHCI
534 			 */
535 #ifndef CONFIG_USB_EHCI_FARADAY
536 			/* EM interference sometimes causes bad shielded USB
537 			 * devices to be shutdown by the hub, this hack enables
538 			 * them again. Works at least with mouse driver */
539 			if (!(portstatus & USB_PORT_STAT_ENABLE) &&
540 			     (portstatus & USB_PORT_STAT_CONNECTION) &&
541 			     usb_device_has_child_on_port(dev, i)) {
542 				debug("already running port %i "  \
543 				      "disabled by hub (EMI?), " \
544 				      "re-enabling...\n", i + 1);
545 				      usb_hub_port_connect_change(dev, i);
546 			}
547 #endif
548 		}
549 		if (portstatus & USB_PORT_STAT_SUSPEND) {
550 			debug("port %d suspend change\n", i + 1);
551 			usb_clear_port_feature(dev, i + 1,
552 						USB_PORT_FEAT_SUSPEND);
553 		}
554 
555 		if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
556 			debug("port %d over-current change\n", i + 1);
557 			usb_clear_port_feature(dev, i + 1,
558 						USB_PORT_FEAT_C_OVER_CURRENT);
559 			usb_hub_power_on(hub);
560 		}
561 
562 		if (portchange & USB_PORT_STAT_C_RESET) {
563 			debug("port %d reset change\n", i + 1);
564 			usb_clear_port_feature(dev, i + 1,
565 						USB_PORT_FEAT_C_RESET);
566 		}
567 	} /* end for i all ports */
568 
569 	return 0;
570 }
571 
572 static int usb_hub_check(struct usb_device *dev, int ifnum)
573 {
574 	struct usb_interface *iface;
575 	struct usb_endpoint_descriptor *ep = NULL;
576 
577 	iface = &dev->config.if_desc[ifnum];
578 	/* Is it a hub? */
579 	if (iface->desc.bInterfaceClass != USB_CLASS_HUB)
580 		goto err;
581 	/* Some hubs have a subclass of 1, which AFAICT according to the */
582 	/*  specs is not defined, but it works */
583 	if ((iface->desc.bInterfaceSubClass != 0) &&
584 	    (iface->desc.bInterfaceSubClass != 1))
585 		goto err;
586 	/* Multiple endpoints? What kind of mutant ninja-hub is this? */
587 	if (iface->desc.bNumEndpoints != 1)
588 		goto err;
589 	ep = &iface->ep_desc[0];
590 	/* Output endpoint? Curiousier and curiousier.. */
591 	if (!(ep->bEndpointAddress & USB_DIR_IN))
592 		goto err;
593 	/* If it's not an interrupt endpoint, we'd better punt! */
594 	if ((ep->bmAttributes & 3) != 3)
595 		goto err;
596 	/* We found a hub */
597 	debug("USB hub found\n");
598 	return 0;
599 
600 err:
601 	debug("USB hub not found: bInterfaceClass=%d, bInterfaceSubClass=%d, bNumEndpoints=%d\n",
602 	      iface->desc.bInterfaceClass, iface->desc.bInterfaceSubClass,
603 	      iface->desc.bNumEndpoints);
604 	if (ep) {
605 		debug("   bEndpointAddress=%#x, bmAttributes=%d",
606 		      ep->bEndpointAddress, ep->bmAttributes);
607 	}
608 
609 	return -ENOENT;
610 }
611 
612 int usb_hub_probe(struct usb_device *dev, int ifnum)
613 {
614 	int ret;
615 
616 	ret = usb_hub_check(dev, ifnum);
617 	if (ret)
618 		return 0;
619 	ret = usb_hub_configure(dev);
620 	return ret;
621 }
622 
623 #ifdef CONFIG_DM_USB
624 int usb_hub_scan(struct udevice *hub)
625 {
626 	struct usb_device *udev = dev_get_parent_priv(hub);
627 
628 	return usb_hub_configure(udev);
629 }
630 
631 static int usb_hub_post_bind(struct udevice *dev)
632 {
633 	/* Scan the bus for devices */
634 	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
635 }
636 
637 static int usb_hub_post_probe(struct udevice *dev)
638 {
639 	debug("%s\n", __func__);
640 	return usb_hub_scan(dev);
641 }
642 
643 static const struct udevice_id usb_hub_ids[] = {
644 	{ .compatible = "usb-hub" },
645 	{ }
646 };
647 
648 U_BOOT_DRIVER(usb_generic_hub) = {
649 	.name	= "usb_hub",
650 	.id	= UCLASS_USB_HUB,
651 	.of_match = usb_hub_ids,
652 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
653 };
654 
655 UCLASS_DRIVER(usb_hub) = {
656 	.id		= UCLASS_USB_HUB,
657 	.name		= "usb_hub",
658 	.post_bind	= usb_hub_post_bind,
659 	.post_probe	= usb_hub_post_probe,
660 	.child_pre_probe	= usb_child_pre_probe,
661 	.per_child_auto_alloc_size = sizeof(struct usb_device),
662 	.per_child_platdata_auto_alloc_size = sizeof(struct usb_dev_platdata),
663 };
664 
665 static const struct usb_device_id hub_id_table[] = {
666 	{
667 		.match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS,
668 		.bDeviceClass = USB_CLASS_HUB
669 	},
670 	{ }	/* Terminating entry */
671 };
672 
673 U_BOOT_USB_DEVICE(usb_generic_hub, hub_id_table);
674 
675 #endif
676