usb_hub.c 17 KB

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