xref: /rk3399_rockchip-uboot/common/usb_hub.c (revision 2ef117fe4fce4e1af282ac2bbb0be36c41d15e2b)
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 
279 	/* Reset the port */
280 	ret = legacy_hub_port_reset(dev, port, &portstatus);
281 	if (ret < 0) {
282 		if (ret != -ENXIO)
283 			printf("cannot reset port %i!?\n", port + 1);
284 		return ret;
285 	}
286 
287 	switch (portstatus & USB_PORT_STAT_SPEED_MASK) {
288 	case USB_PORT_STAT_SUPER_SPEED:
289 		speed = USB_SPEED_SUPER;
290 		break;
291 	case USB_PORT_STAT_HIGH_SPEED:
292 		speed = USB_SPEED_HIGH;
293 		break;
294 	case USB_PORT_STAT_LOW_SPEED:
295 		speed = USB_SPEED_LOW;
296 		break;
297 	default:
298 		speed = USB_SPEED_FULL;
299 		break;
300 	}
301 
302 #ifdef CONFIG_DM_USB
303 	struct udevice *child;
304 
305 	ret = usb_scan_device(dev->dev, port + 1, speed, &child);
306 #else
307 	struct usb_device *usb;
308 
309 	ret = usb_alloc_new_device(dev->controller, &usb);
310 	if (ret) {
311 		printf("cannot create new device: ret=%d", ret);
312 		return ret;
313 	}
314 
315 	dev->children[port] = usb;
316 	usb->speed = speed;
317 	usb->parent = dev;
318 	usb->portnr = port + 1;
319 	/* Run it through the hoops (find a driver, etc) */
320 	ret = usb_new_device(usb);
321 	if (ret < 0) {
322 		/* Woops, disable the port */
323 		usb_free_device(dev->controller);
324 		dev->children[port] = NULL;
325 	}
326 #endif
327 	if (ret < 0) {
328 		debug("hub: disabling port %d\n", port + 1);
329 		usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
330 	}
331 
332 	return ret;
333 }
334 
335 
336 static int usb_hub_configure(struct usb_device *dev)
337 {
338 	int i, length;
339 	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
340 	unsigned char *bitmap;
341 	short hubCharacteristics;
342 	struct usb_hub_descriptor *descriptor;
343 	struct usb_hub_device *hub;
344 	__maybe_unused struct usb_hub_status *hubsts;
345 	int ret;
346 
347 	/* "allocate" Hub device */
348 	hub = usb_hub_allocate();
349 	if (hub == NULL)
350 		return -ENOMEM;
351 	hub->pusb_dev = dev;
352 	/* Get the the hub descriptor */
353 	ret = usb_get_hub_descriptor(dev, buffer, 4);
354 	if (ret < 0) {
355 		debug("usb_hub_configure: failed to get hub " \
356 		      "descriptor, giving up %lX\n", dev->status);
357 		return ret;
358 	}
359 	descriptor = (struct usb_hub_descriptor *)buffer;
360 
361 	length = min_t(int, descriptor->bLength,
362 		       sizeof(struct usb_hub_descriptor));
363 
364 	ret = usb_get_hub_descriptor(dev, buffer, length);
365 	if (ret < 0) {
366 		debug("usb_hub_configure: failed to get hub " \
367 		      "descriptor 2nd giving up %lX\n", dev->status);
368 		return ret;
369 	}
370 	memcpy((unsigned char *)&hub->desc, buffer, length);
371 	/* adjust 16bit values */
372 	put_unaligned(le16_to_cpu(get_unaligned(
373 			&descriptor->wHubCharacteristics)),
374 			&hub->desc.wHubCharacteristics);
375 	/* set the bitmap */
376 	bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
377 	/* devices not removable by default */
378 	memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8);
379 	bitmap = (unsigned char *)&hub->desc.PortPowerCtrlMask[0];
380 	memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
381 
382 	for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
383 		hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
384 
385 	for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
386 		hub->desc.PortPowerCtrlMask[i] = descriptor->PortPowerCtrlMask[i];
387 
388 	dev->maxchild = descriptor->bNbrPorts;
389 	debug("%d ports detected\n", dev->maxchild);
390 
391 	hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics);
392 	switch (hubCharacteristics & HUB_CHAR_LPSM) {
393 	case 0x00:
394 		debug("ganged power switching\n");
395 		break;
396 	case 0x01:
397 		debug("individual port power switching\n");
398 		break;
399 	case 0x02:
400 	case 0x03:
401 		debug("unknown reserved power switching mode\n");
402 		break;
403 	}
404 
405 	if (hubCharacteristics & HUB_CHAR_COMPOUND)
406 		debug("part of a compound device\n");
407 	else
408 		debug("standalone hub\n");
409 
410 	switch (hubCharacteristics & HUB_CHAR_OCPM) {
411 	case 0x00:
412 		debug("global over-current protection\n");
413 		break;
414 	case 0x08:
415 		debug("individual port over-current protection\n");
416 		break;
417 	case 0x10:
418 	case 0x18:
419 		debug("no over-current protection\n");
420 		break;
421 	}
422 
423 	debug("power on to power good time: %dms\n",
424 	      descriptor->bPwrOn2PwrGood * 2);
425 	debug("hub controller current requirement: %dmA\n",
426 	      descriptor->bHubContrCurrent);
427 
428 	for (i = 0; i < dev->maxchild; i++)
429 		debug("port %d is%s removable\n", i + 1,
430 		      hub->desc.DeviceRemovable[(i + 1) / 8] & \
431 		      (1 << ((i + 1) % 8)) ? " not" : "");
432 
433 	if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
434 		debug("usb_hub_configure: failed to get Status - " \
435 		      "too long: %d\n", descriptor->bLength);
436 		return -EFBIG;
437 	}
438 
439 	ret = usb_get_hub_status(dev, buffer);
440 	if (ret < 0) {
441 		debug("usb_hub_configure: failed to get Status %lX\n",
442 		      dev->status);
443 		return ret;
444 	}
445 
446 #ifdef DEBUG
447 	hubsts = (struct usb_hub_status *)buffer;
448 #endif
449 
450 	debug("get_hub_status returned status %X, change %X\n",
451 	      le16_to_cpu(hubsts->wHubStatus),
452 	      le16_to_cpu(hubsts->wHubChange));
453 	debug("local power source is %s\n",
454 	      (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? \
455 	      "lost (inactive)" : "good");
456 	debug("%sover-current condition exists\n",
457 	      (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? \
458 	      "" : "no ");
459 	usb_hub_power_on(hub);
460 
461 	/*
462 	 * Reset any devices that may be in a bad state when applying
463 	 * the power.  This is a __weak function.  Resetting of the devices
464 	 * should occur in the board file of the device.
465 	 */
466 	for (i = 0; i < dev->maxchild; i++)
467 		usb_hub_reset_devices(i + 1);
468 
469 	for (i = 0; i < dev->maxchild; i++) {
470 		ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);
471 		unsigned short portstatus, portchange;
472 		int ret;
473 		ulong start = get_timer(0);
474 		uint delay = CONFIG_SYS_HZ;
475 
476 #ifdef CONFIG_SANDBOX
477 		if (state_get_skip_delays())
478 			delay = 0;
479 #endif
480 #ifdef CONFIG_DM_USB
481 		debug("\n\nScanning '%s' port %d\n", dev->dev->name, i + 1);
482 #else
483 		debug("\n\nScanning port %d\n", i + 1);
484 #endif
485 		/*
486 		 * Wait for (whichever finishes first)
487 		 *  - A maximum of 10 seconds
488 		 *    This is a purely observational value driven by connecting
489 		 *    a few broken pen drives and taking the max * 1.5 approach
490 		 *  - connection_change and connection state to report same
491 		 *    state
492 		 */
493 		do {
494 			ret = usb_get_port_status(dev, i + 1, portsts);
495 			if (ret < 0) {
496 				debug("get_port_status failed\n");
497 				break;
498 			}
499 
500 			portstatus = le16_to_cpu(portsts->wPortStatus);
501 			portchange = le16_to_cpu(portsts->wPortChange);
502 
503 			/* No connection change happened, wait a bit more. */
504 			if (!(portchange & USB_PORT_STAT_C_CONNECTION))
505 				continue;
506 
507 			/* Test if the connection came up, and if so, exit. */
508 			if (portstatus & USB_PORT_STAT_CONNECTION)
509 				break;
510 
511 		} while (get_timer(start) < delay);
512 
513 		if (ret < 0)
514 			continue;
515 
516 		debug("Port %d Status %X Change %X\n",
517 		      i + 1, portstatus, portchange);
518 
519 		if (portchange & USB_PORT_STAT_C_CONNECTION) {
520 			debug("port %d connection change\n", i + 1);
521 			usb_hub_port_connect_change(dev, i);
522 		}
523 		if (portchange & USB_PORT_STAT_C_ENABLE) {
524 			debug("port %d enable change, status %x\n",
525 			      i + 1, portstatus);
526 			usb_clear_port_feature(dev, i + 1,
527 						USB_PORT_FEAT_C_ENABLE);
528 			/*
529 			 * The following hack causes a ghost device problem
530 			 * to Faraday EHCI
531 			 */
532 #ifndef CONFIG_USB_EHCI_FARADAY
533 			/* EM interference sometimes causes bad shielded USB
534 			 * devices to be shutdown by the hub, this hack enables
535 			 * them again. Works at least with mouse driver */
536 			if (!(portstatus & USB_PORT_STAT_ENABLE) &&
537 			     (portstatus & USB_PORT_STAT_CONNECTION) &&
538 			     usb_device_has_child_on_port(dev, i)) {
539 				debug("already running port %i "  \
540 				      "disabled by hub (EMI?), " \
541 				      "re-enabling...\n", i + 1);
542 				      usb_hub_port_connect_change(dev, i);
543 			}
544 #endif
545 		}
546 		if (portstatus & USB_PORT_STAT_SUSPEND) {
547 			debug("port %d suspend change\n", i + 1);
548 			usb_clear_port_feature(dev, i + 1,
549 						USB_PORT_FEAT_SUSPEND);
550 		}
551 
552 		if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
553 			debug("port %d over-current change\n", i + 1);
554 			usb_clear_port_feature(dev, i + 1,
555 						USB_PORT_FEAT_C_OVER_CURRENT);
556 			usb_hub_power_on(hub);
557 		}
558 
559 		if (portchange & USB_PORT_STAT_C_RESET) {
560 			debug("port %d reset change\n", i + 1);
561 			usb_clear_port_feature(dev, i + 1,
562 						USB_PORT_FEAT_C_RESET);
563 		}
564 	} /* end for i all ports */
565 
566 	return 0;
567 }
568 
569 static int usb_hub_check(struct usb_device *dev, int ifnum)
570 {
571 	struct usb_interface *iface;
572 	struct usb_endpoint_descriptor *ep = NULL;
573 
574 	iface = &dev->config.if_desc[ifnum];
575 	/* Is it a hub? */
576 	if (iface->desc.bInterfaceClass != USB_CLASS_HUB)
577 		goto err;
578 	/* Some hubs have a subclass of 1, which AFAICT according to the */
579 	/*  specs is not defined, but it works */
580 	if ((iface->desc.bInterfaceSubClass != 0) &&
581 	    (iface->desc.bInterfaceSubClass != 1))
582 		goto err;
583 	/* Multiple endpoints? What kind of mutant ninja-hub is this? */
584 	if (iface->desc.bNumEndpoints != 1)
585 		goto err;
586 	ep = &iface->ep_desc[0];
587 	/* Output endpoint? Curiousier and curiousier.. */
588 	if (!(ep->bEndpointAddress & USB_DIR_IN))
589 		goto err;
590 	/* If it's not an interrupt endpoint, we'd better punt! */
591 	if ((ep->bmAttributes & 3) != 3)
592 		goto err;
593 	/* We found a hub */
594 	debug("USB hub found\n");
595 	return 0;
596 
597 err:
598 	debug("USB hub not found: bInterfaceClass=%d, bInterfaceSubClass=%d, bNumEndpoints=%d\n",
599 	      iface->desc.bInterfaceClass, iface->desc.bInterfaceSubClass,
600 	      iface->desc.bNumEndpoints);
601 	if (ep) {
602 		debug("   bEndpointAddress=%#x, bmAttributes=%d",
603 		      ep->bEndpointAddress, ep->bmAttributes);
604 	}
605 
606 	return -ENOENT;
607 }
608 
609 int usb_hub_probe(struct usb_device *dev, int ifnum)
610 {
611 	int ret;
612 
613 	ret = usb_hub_check(dev, ifnum);
614 	if (ret)
615 		return 0;
616 	ret = usb_hub_configure(dev);
617 	return ret;
618 }
619 
620 #ifdef CONFIG_DM_USB
621 int usb_hub_scan(struct udevice *hub)
622 {
623 	struct usb_device *udev = dev_get_parent_priv(hub);
624 
625 	return usb_hub_configure(udev);
626 }
627 
628 static int usb_hub_post_bind(struct udevice *dev)
629 {
630 	/* Scan the bus for devices */
631 	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
632 }
633 
634 static int usb_hub_post_probe(struct udevice *dev)
635 {
636 	debug("%s\n", __func__);
637 	return usb_hub_scan(dev);
638 }
639 
640 static const struct udevice_id usb_hub_ids[] = {
641 	{ .compatible = "usb-hub" },
642 	{ }
643 };
644 
645 U_BOOT_DRIVER(usb_generic_hub) = {
646 	.name	= "usb_hub",
647 	.id	= UCLASS_USB_HUB,
648 	.of_match = usb_hub_ids,
649 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
650 };
651 
652 UCLASS_DRIVER(usb_hub) = {
653 	.id		= UCLASS_USB_HUB,
654 	.name		= "usb_hub",
655 	.post_bind	= usb_hub_post_bind,
656 	.post_probe	= usb_hub_post_probe,
657 	.child_pre_probe	= usb_child_pre_probe,
658 	.per_child_auto_alloc_size = sizeof(struct usb_device),
659 	.per_child_platdata_auto_alloc_size = sizeof(struct usb_dev_platdata),
660 };
661 
662 static const struct usb_device_id hub_id_table[] = {
663 	{
664 		.match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS,
665 		.bDeviceClass = USB_CLASS_HUB
666 	},
667 	{ }	/* Terminating entry */
668 };
669 
670 U_BOOT_USB_DEVICE(usb_generic_hub, hub_id_table);
671 
672 #endif
673