usb.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Most of this source has been derived from the Linux USB
  4. * project:
  5. * (C) Copyright Linus Torvalds 1999
  6. * (C) Copyright Johannes Erdfelt 1999-2001
  7. * (C) Copyright Andreas Gal 1999
  8. * (C) Copyright Gregory P. Smith 1999
  9. * (C) Copyright Deti Fliegl 1999 (new USB architecture)
  10. * (C) Copyright Randy Dunlap 2000
  11. * (C) Copyright David Brownell 2000 (kernel hotplug, usb_device_id)
  12. * (C) Copyright Yggdrasil Computing, Inc. 2000
  13. * (usb_device_id matching changes by Adam J. Richter)
  14. *
  15. * Adapted for U-Boot:
  16. * (C) Copyright 2001 Denis Peter, MPL AG Switzerland
  17. */
  18. /*
  19. * How it works:
  20. *
  21. * Since this is a bootloader, the devices will not be automatic
  22. * (re)configured on hotplug, but after a restart of the USB the
  23. * device should work.
  24. *
  25. * For each transfer (except "Interrupt") we wait for completion.
  26. */
  27. #include <common.h>
  28. #include <command.h>
  29. #include <dm.h>
  30. #include <malloc.h>
  31. #include <memalign.h>
  32. #include <asm/processor.h>
  33. #include <linux/compiler.h>
  34. #include <linux/ctype.h>
  35. #include <asm/byteorder.h>
  36. #include <asm/unaligned.h>
  37. #include <errno.h>
  38. #include <usb.h>
  39. #define USB_BUFSIZ 512
  40. static int asynch_allowed;
  41. char usb_started; /* flag for the started/stopped USB status */
  42. #if !CONFIG_IS_ENABLED(DM_USB)
  43. static struct usb_device usb_dev[USB_MAX_DEVICE];
  44. static int dev_index;
  45. #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
  46. #define CONFIG_USB_MAX_CONTROLLER_COUNT 1
  47. #endif
  48. /***************************************************************************
  49. * Init USB Device
  50. */
  51. int usb_init(void)
  52. {
  53. void *ctrl;
  54. struct usb_device *dev;
  55. int i, start_index = 0;
  56. int controllers_initialized = 0;
  57. int ret;
  58. dev_index = 0;
  59. asynch_allowed = 1;
  60. usb_hub_reset();
  61. /* first make all devices unknown */
  62. for (i = 0; i < USB_MAX_DEVICE; i++) {
  63. memset(&usb_dev[i], 0, sizeof(struct usb_device));
  64. usb_dev[i].devnum = -1;
  65. }
  66. /* init low_level USB */
  67. for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
  68. /* init low_level USB */
  69. printf("USB%d: ", i);
  70. ret = usb_lowlevel_init(i, USB_INIT_HOST, &ctrl);
  71. if (ret == -ENODEV) { /* No such device. */
  72. puts("Port not available.\n");
  73. controllers_initialized++;
  74. continue;
  75. }
  76. if (ret) { /* Other error. */
  77. puts("lowlevel init failed\n");
  78. continue;
  79. }
  80. /*
  81. * lowlevel init is OK, now scan the bus for devices
  82. * i.e. search HUBs and configure them
  83. */
  84. controllers_initialized++;
  85. start_index = dev_index;
  86. printf("scanning bus %d for devices... ", i);
  87. ret = usb_alloc_new_device(ctrl, &dev);
  88. if (ret)
  89. break;
  90. /*
  91. * device 0 is always present
  92. * (root hub, so let it analyze)
  93. */
  94. ret = usb_new_device(dev);
  95. if (ret)
  96. usb_free_device(dev->controller);
  97. if (start_index == dev_index) {
  98. puts("No USB Device found\n");
  99. continue;
  100. } else {
  101. printf("%d USB Device(s) found\n",
  102. dev_index - start_index);
  103. }
  104. usb_started = 1;
  105. }
  106. debug("scan end\n");
  107. /* if we were not able to find at least one working bus, bail out */
  108. if (controllers_initialized == 0)
  109. puts("USB error: all controllers failed lowlevel init\n");
  110. return usb_started ? 0 : -ENODEV;
  111. }
  112. /******************************************************************************
  113. * Stop USB this stops the LowLevel Part and deregisters USB devices.
  114. */
  115. int usb_stop(void)
  116. {
  117. int i;
  118. if (usb_started) {
  119. asynch_allowed = 1;
  120. usb_started = 0;
  121. usb_hub_reset();
  122. for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
  123. if (usb_lowlevel_stop(i))
  124. printf("failed to stop USB controller %d\n", i);
  125. }
  126. }
  127. return 0;
  128. }
  129. /******************************************************************************
  130. * Detect if a USB device has been plugged or unplugged.
  131. */
  132. int usb_detect_change(void)
  133. {
  134. int i, j;
  135. int change = 0;
  136. for (j = 0; j < USB_MAX_DEVICE; j++) {
  137. for (i = 0; i < usb_dev[j].maxchild; i++) {
  138. struct usb_port_status status;
  139. if (usb_get_port_status(&usb_dev[j], i + 1,
  140. &status) < 0)
  141. /* USB request failed */
  142. continue;
  143. if (le16_to_cpu(status.wPortChange) &
  144. USB_PORT_STAT_C_CONNECTION)
  145. change++;
  146. }
  147. }
  148. return change;
  149. }
  150. /*
  151. * disables the asynch behaviour of the control message. This is used for data
  152. * transfers that uses the exclusiv access to the control and bulk messages.
  153. * Returns the old value so it can be restored later.
  154. */
  155. int usb_disable_asynch(int disable)
  156. {
  157. int old_value = asynch_allowed;
  158. asynch_allowed = !disable;
  159. return old_value;
  160. }
  161. #endif /* !CONFIG_IS_ENABLED(DM_USB) */
  162. /*-------------------------------------------------------------------
  163. * Message wrappers.
  164. *
  165. */
  166. /*
  167. * submits an Interrupt Message. Some drivers may implement non-blocking
  168. * polling: when non-block is true and the device is not responding return
  169. * -EAGAIN instead of waiting for device to respond.
  170. */
  171. int usb_int_msg(struct usb_device *dev, unsigned long pipe,
  172. void *buffer, int transfer_len, int interval, bool nonblock)
  173. {
  174. return submit_int_msg(dev, pipe, buffer, transfer_len, interval,
  175. nonblock);
  176. }
  177. /*
  178. * submits a control message and waits for comletion (at least timeout * 1ms)
  179. * If timeout is 0, we don't wait for completion (used as example to set and
  180. * clear keyboards LEDs). For data transfers, (storage transfers) we don't
  181. * allow control messages with 0 timeout, by previousely resetting the flag
  182. * asynch_allowed (usb_disable_asynch(1)).
  183. * returns the transferred length if OK or -1 if error. The transferred length
  184. * and the current status are stored in the dev->act_len and dev->status.
  185. */
  186. int usb_control_msg(struct usb_device *dev, unsigned int pipe,
  187. unsigned char request, unsigned char requesttype,
  188. unsigned short value, unsigned short index,
  189. void *data, unsigned short size, int timeout)
  190. {
  191. ALLOC_CACHE_ALIGN_BUFFER(struct devrequest, setup_packet, 1);
  192. int err;
  193. if ((timeout == 0) && (!asynch_allowed)) {
  194. /* request for a asynch control pipe is not allowed */
  195. return -EINVAL;
  196. }
  197. /* set setup command */
  198. setup_packet->requesttype = requesttype;
  199. setup_packet->request = request;
  200. setup_packet->value = cpu_to_le16(value);
  201. setup_packet->index = cpu_to_le16(index);
  202. setup_packet->length = cpu_to_le16(size);
  203. debug("usb_control_msg: request: 0x%X, requesttype: 0x%X, " \
  204. "value 0x%X index 0x%X length 0x%X\n",
  205. request, requesttype, value, index, size);
  206. dev->status = USB_ST_NOT_PROC; /*not yet processed */
  207. err = submit_control_msg(dev, pipe, data, size, setup_packet);
  208. if (err < 0)
  209. return err;
  210. if (timeout == 0)
  211. return (int)size;
  212. /*
  213. * Wait for status to update until timeout expires, USB driver
  214. * interrupt handler may set the status when the USB operation has
  215. * been completed.
  216. */
  217. while (timeout--) {
  218. if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
  219. break;
  220. mdelay(1);
  221. }
  222. if (dev->status)
  223. return -1;
  224. return dev->act_len;
  225. }
  226. /*-------------------------------------------------------------------
  227. * submits bulk message, and waits for completion. returns 0 if Ok or
  228. * negative if Error.
  229. * synchronous behavior
  230. */
  231. int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
  232. void *data, int len, int *actual_length, int timeout)
  233. {
  234. if (len < 0)
  235. return -EINVAL;
  236. dev->status = USB_ST_NOT_PROC; /*not yet processed */
  237. if (submit_bulk_msg(dev, pipe, data, len) < 0)
  238. return -EIO;
  239. while (timeout--) {
  240. if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
  241. break;
  242. mdelay(1);
  243. }
  244. *actual_length = dev->act_len;
  245. if (dev->status == 0)
  246. return 0;
  247. else
  248. return -EIO;
  249. }
  250. /*-------------------------------------------------------------------
  251. * Max Packet stuff
  252. */
  253. /*
  254. * returns the max packet size, depending on the pipe direction and
  255. * the configurations values
  256. */
  257. int usb_maxpacket(struct usb_device *dev, unsigned long pipe)
  258. {
  259. /* direction is out -> use emaxpacket out */
  260. if ((pipe & USB_DIR_IN) == 0)
  261. return dev->epmaxpacketout[((pipe>>15) & 0xf)];
  262. else
  263. return dev->epmaxpacketin[((pipe>>15) & 0xf)];
  264. }
  265. /*
  266. * The routine usb_set_maxpacket_ep() is extracted from the loop of routine
  267. * usb_set_maxpacket(), because the optimizer of GCC 4.x chokes on this routine
  268. * when it is inlined in 1 single routine. What happens is that the register r3
  269. * is used as loop-count 'i', but gets overwritten later on.
  270. * This is clearly a compiler bug, but it is easier to workaround it here than
  271. * to update the compiler (Occurs with at least several GCC 4.{1,2},x
  272. * CodeSourcery compilers like e.g. 2007q3, 2008q1, 2008q3 lite editions on ARM)
  273. *
  274. * NOTE: Similar behaviour was observed with GCC4.6 on ARMv5.
  275. */
  276. static void noinline
  277. usb_set_maxpacket_ep(struct usb_device *dev, int if_idx, int ep_idx)
  278. {
  279. int b;
  280. struct usb_endpoint_descriptor *ep;
  281. u16 ep_wMaxPacketSize;
  282. ep = &dev->config.if_desc[if_idx].ep_desc[ep_idx];
  283. b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  284. ep_wMaxPacketSize = get_unaligned(&ep->wMaxPacketSize);
  285. if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  286. USB_ENDPOINT_XFER_CONTROL) {
  287. /* Control => bidirectional */
  288. dev->epmaxpacketout[b] = ep_wMaxPacketSize;
  289. dev->epmaxpacketin[b] = ep_wMaxPacketSize;
  290. debug("##Control EP epmaxpacketout/in[%d] = %d\n",
  291. b, dev->epmaxpacketin[b]);
  292. } else {
  293. if ((ep->bEndpointAddress & 0x80) == 0) {
  294. /* OUT Endpoint */
  295. if (ep_wMaxPacketSize > dev->epmaxpacketout[b]) {
  296. dev->epmaxpacketout[b] = ep_wMaxPacketSize;
  297. debug("##EP epmaxpacketout[%d] = %d\n",
  298. b, dev->epmaxpacketout[b]);
  299. }
  300. } else {
  301. /* IN Endpoint */
  302. if (ep_wMaxPacketSize > dev->epmaxpacketin[b]) {
  303. dev->epmaxpacketin[b] = ep_wMaxPacketSize;
  304. debug("##EP epmaxpacketin[%d] = %d\n",
  305. b, dev->epmaxpacketin[b]);
  306. }
  307. } /* if out */
  308. } /* if control */
  309. }
  310. /*
  311. * set the max packed value of all endpoints in the given configuration
  312. */
  313. static int usb_set_maxpacket(struct usb_device *dev)
  314. {
  315. int i, ii;
  316. for (i = 0; i < dev->config.desc.bNumInterfaces; i++)
  317. for (ii = 0; ii < dev->config.if_desc[i].desc.bNumEndpoints; ii++)
  318. usb_set_maxpacket_ep(dev, i, ii);
  319. return 0;
  320. }
  321. /*******************************************************************************
  322. * Parse the config, located in buffer, and fills the dev->config structure.
  323. * Note that all little/big endian swapping are done automatically.
  324. * (wTotalLength has already been swapped and sanitized when it was read.)
  325. */
  326. static int usb_parse_config(struct usb_device *dev,
  327. unsigned char *buffer, int cfgno)
  328. {
  329. struct usb_descriptor_header *head;
  330. int index, ifno, epno, curr_if_num;
  331. u16 ep_wMaxPacketSize;
  332. struct usb_interface *if_desc = NULL;
  333. ifno = -1;
  334. epno = -1;
  335. curr_if_num = -1;
  336. dev->configno = cfgno;
  337. head = (struct usb_descriptor_header *) &buffer[0];
  338. if (head->bDescriptorType != USB_DT_CONFIG) {
  339. printf(" ERROR: NOT USB_CONFIG_DESC %x\n",
  340. head->bDescriptorType);
  341. return -EINVAL;
  342. }
  343. if (head->bLength != USB_DT_CONFIG_SIZE) {
  344. printf("ERROR: Invalid USB CFG length (%d)\n", head->bLength);
  345. return -EINVAL;
  346. }
  347. memcpy(&dev->config, head, USB_DT_CONFIG_SIZE);
  348. dev->config.no_of_if = 0;
  349. index = dev->config.desc.bLength;
  350. /* Ok the first entry must be a configuration entry,
  351. * now process the others */
  352. head = (struct usb_descriptor_header *) &buffer[index];
  353. while (index + 1 < dev->config.desc.wTotalLength && head->bLength) {
  354. switch (head->bDescriptorType) {
  355. case USB_DT_INTERFACE:
  356. if (head->bLength != USB_DT_INTERFACE_SIZE) {
  357. printf("ERROR: Invalid USB IF length (%d)\n",
  358. head->bLength);
  359. break;
  360. }
  361. if (index + USB_DT_INTERFACE_SIZE >
  362. dev->config.desc.wTotalLength) {
  363. puts("USB IF descriptor overflowed buffer!\n");
  364. break;
  365. }
  366. if (((struct usb_interface_descriptor *) \
  367. head)->bInterfaceNumber != curr_if_num) {
  368. /* this is a new interface, copy new desc */
  369. ifno = dev->config.no_of_if;
  370. if (ifno >= USB_MAXINTERFACES) {
  371. puts("Too many USB interfaces!\n");
  372. /* try to go on with what we have */
  373. return -EINVAL;
  374. }
  375. if_desc = &dev->config.if_desc[ifno];
  376. dev->config.no_of_if++;
  377. memcpy(if_desc, head,
  378. USB_DT_INTERFACE_SIZE);
  379. if_desc->no_of_ep = 0;
  380. if_desc->num_altsetting = 1;
  381. curr_if_num =
  382. if_desc->desc.bInterfaceNumber;
  383. } else {
  384. /* found alternate setting for the interface */
  385. if (ifno >= 0) {
  386. if_desc = &dev->config.if_desc[ifno];
  387. if_desc->num_altsetting++;
  388. }
  389. }
  390. break;
  391. case USB_DT_ENDPOINT:
  392. if (head->bLength != USB_DT_ENDPOINT_SIZE &&
  393. head->bLength != USB_DT_ENDPOINT_AUDIO_SIZE) {
  394. printf("ERROR: Invalid USB EP length (%d)\n",
  395. head->bLength);
  396. break;
  397. }
  398. if (index + head->bLength >
  399. dev->config.desc.wTotalLength) {
  400. puts("USB EP descriptor overflowed buffer!\n");
  401. break;
  402. }
  403. if (ifno < 0) {
  404. puts("Endpoint descriptor out of order!\n");
  405. break;
  406. }
  407. epno = dev->config.if_desc[ifno].no_of_ep;
  408. if_desc = &dev->config.if_desc[ifno];
  409. if (epno >= USB_MAXENDPOINTS) {
  410. printf("Interface %d has too many endpoints!\n",
  411. if_desc->desc.bInterfaceNumber);
  412. return -EINVAL;
  413. }
  414. /* found an endpoint */
  415. if_desc->no_of_ep++;
  416. memcpy(&if_desc->ep_desc[epno], head,
  417. USB_DT_ENDPOINT_SIZE);
  418. ep_wMaxPacketSize = get_unaligned(&dev->config.\
  419. if_desc[ifno].\
  420. ep_desc[epno].\
  421. wMaxPacketSize);
  422. put_unaligned(le16_to_cpu(ep_wMaxPacketSize),
  423. &dev->config.\
  424. if_desc[ifno].\
  425. ep_desc[epno].\
  426. wMaxPacketSize);
  427. debug("if %d, ep %d\n", ifno, epno);
  428. break;
  429. case USB_DT_SS_ENDPOINT_COMP:
  430. if (head->bLength != USB_DT_SS_EP_COMP_SIZE) {
  431. printf("ERROR: Invalid USB EPC length (%d)\n",
  432. head->bLength);
  433. break;
  434. }
  435. if (index + USB_DT_SS_EP_COMP_SIZE >
  436. dev->config.desc.wTotalLength) {
  437. puts("USB EPC descriptor overflowed buffer!\n");
  438. break;
  439. }
  440. if (ifno < 0 || epno < 0) {
  441. puts("EPC descriptor out of order!\n");
  442. break;
  443. }
  444. if_desc = &dev->config.if_desc[ifno];
  445. memcpy(&if_desc->ss_ep_comp_desc[epno], head,
  446. USB_DT_SS_EP_COMP_SIZE);
  447. break;
  448. default:
  449. if (head->bLength == 0)
  450. return -EINVAL;
  451. debug("unknown Description Type : %x\n",
  452. head->bDescriptorType);
  453. #ifdef DEBUG
  454. {
  455. unsigned char *ch = (unsigned char *)head;
  456. int i;
  457. for (i = 0; i < head->bLength; i++)
  458. debug("%02X ", *ch++);
  459. debug("\n\n\n");
  460. }
  461. #endif
  462. break;
  463. }
  464. index += head->bLength;
  465. head = (struct usb_descriptor_header *)&buffer[index];
  466. }
  467. return 0;
  468. }
  469. /***********************************************************************
  470. * Clears an endpoint
  471. * endp: endpoint number in bits 0-3;
  472. * direction flag in bit 7 (1 = IN, 0 = OUT)
  473. */
  474. int usb_clear_halt(struct usb_device *dev, int pipe)
  475. {
  476. int result;
  477. int endp = usb_pipeendpoint(pipe)|(usb_pipein(pipe)<<7);
  478. result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  479. USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0,
  480. endp, NULL, 0, USB_CNTL_TIMEOUT * 3);
  481. /* don't clear if failed */
  482. if (result < 0)
  483. return result;
  484. /*
  485. * NOTE: we do not get status and verify reset was successful
  486. * as some devices are reported to lock up upon this check..
  487. */
  488. usb_endpoint_running(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe));
  489. /* toggle is reset on clear */
  490. usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0);
  491. return 0;
  492. }
  493. /**********************************************************************
  494. * get_descriptor type
  495. */
  496. static int usb_get_descriptor(struct usb_device *dev, unsigned char type,
  497. unsigned char index, void *buf, int size)
  498. {
  499. return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  500. USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
  501. (type << 8) + index, 0, buf, size,
  502. USB_CNTL_TIMEOUT);
  503. }
  504. /**********************************************************************
  505. * gets len of configuration cfgno
  506. */
  507. int usb_get_configuration_len(struct usb_device *dev, int cfgno)
  508. {
  509. int result;
  510. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, 9);
  511. struct usb_config_descriptor *config;
  512. config = (struct usb_config_descriptor *)&buffer[0];
  513. result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9);
  514. if (result < 9) {
  515. if (result < 0)
  516. printf("unable to get descriptor, error %lX\n",
  517. dev->status);
  518. else
  519. printf("config descriptor too short " \
  520. "(expected %i, got %i)\n", 9, result);
  521. return -EIO;
  522. }
  523. return le16_to_cpu(config->wTotalLength);
  524. }
  525. /**********************************************************************
  526. * gets configuration cfgno and store it in the buffer
  527. */
  528. int usb_get_configuration_no(struct usb_device *dev, int cfgno,
  529. unsigned char *buffer, int length)
  530. {
  531. int result;
  532. struct usb_config_descriptor *config;
  533. config = (struct usb_config_descriptor *)&buffer[0];
  534. result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, length);
  535. debug("get_conf_no %d Result %d, wLength %d\n", cfgno, result,
  536. le16_to_cpu(config->wTotalLength));
  537. config->wTotalLength = result; /* validated, with CPU byte order */
  538. return result;
  539. }
  540. /********************************************************************
  541. * set address of a device to the value in dev->devnum.
  542. * This can only be done by addressing the device via the default address (0)
  543. */
  544. static int usb_set_address(struct usb_device *dev)
  545. {
  546. debug("set address %d\n", dev->devnum);
  547. return usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS,
  548. 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT);
  549. }
  550. /********************************************************************
  551. * set interface number to interface
  552. */
  553. int usb_set_interface(struct usb_device *dev, int interface, int alternate)
  554. {
  555. struct usb_interface *if_face = NULL;
  556. int ret, i;
  557. for (i = 0; i < dev->config.desc.bNumInterfaces; i++) {
  558. if (dev->config.if_desc[i].desc.bInterfaceNumber == interface) {
  559. if_face = &dev->config.if_desc[i];
  560. break;
  561. }
  562. }
  563. if (!if_face) {
  564. printf("selecting invalid interface %d", interface);
  565. return -EINVAL;
  566. }
  567. /*
  568. * We should return now for devices with only one alternate setting.
  569. * According to 9.4.10 of the Universal Serial Bus Specification
  570. * Revision 2.0 such devices can return with a STALL. This results in
  571. * some USB sticks timeouting during initialization and then being
  572. * unusable in U-Boot.
  573. */
  574. if (if_face->num_altsetting == 1)
  575. return 0;
  576. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  577. USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
  578. alternate, interface, NULL, 0,
  579. USB_CNTL_TIMEOUT * 5);
  580. if (ret < 0)
  581. return ret;
  582. return 0;
  583. }
  584. /********************************************************************
  585. * set configuration number to configuration
  586. */
  587. static int usb_set_configuration(struct usb_device *dev, int configuration)
  588. {
  589. int res;
  590. debug("set configuration %d\n", configuration);
  591. /* set setup command */
  592. res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  593. USB_REQ_SET_CONFIGURATION, 0,
  594. configuration, 0,
  595. NULL, 0, USB_CNTL_TIMEOUT);
  596. if (res == 0) {
  597. dev->toggle[0] = 0;
  598. dev->toggle[1] = 0;
  599. return 0;
  600. } else
  601. return -EIO;
  602. }
  603. /********************************************************************
  604. * set protocol to protocol
  605. */
  606. int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol)
  607. {
  608. return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  609. USB_REQ_SET_PROTOCOL, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  610. protocol, ifnum, NULL, 0, USB_CNTL_TIMEOUT);
  611. }
  612. /********************************************************************
  613. * set idle
  614. */
  615. int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id)
  616. {
  617. return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  618. USB_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  619. (duration << 8) | report_id, ifnum, NULL, 0, USB_CNTL_TIMEOUT);
  620. }
  621. /********************************************************************
  622. * get report
  623. */
  624. int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
  625. unsigned char id, void *buf, int size)
  626. {
  627. return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  628. USB_REQ_GET_REPORT,
  629. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  630. (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT);
  631. }
  632. /********************************************************************
  633. * get class descriptor
  634. */
  635. int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
  636. unsigned char type, unsigned char id, void *buf, int size)
  637. {
  638. return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  639. USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
  640. (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT);
  641. }
  642. /********************************************************************
  643. * get string index in buffer
  644. */
  645. static int usb_get_string(struct usb_device *dev, unsigned short langid,
  646. unsigned char index, void *buf, int size)
  647. {
  648. int i;
  649. int result;
  650. for (i = 0; i < 3; ++i) {
  651. /* some devices are flaky */
  652. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  653. USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
  654. (USB_DT_STRING << 8) + index, langid, buf, size,
  655. USB_CNTL_TIMEOUT);
  656. if (result > 0)
  657. break;
  658. }
  659. return result;
  660. }
  661. static void usb_try_string_workarounds(unsigned char *buf, int *length)
  662. {
  663. int newlength, oldlength = *length;
  664. for (newlength = 2; newlength + 1 < oldlength; newlength += 2)
  665. if (!isprint(buf[newlength]) || buf[newlength + 1])
  666. break;
  667. if (newlength > 2) {
  668. buf[0] = newlength;
  669. *length = newlength;
  670. }
  671. }
  672. static int usb_string_sub(struct usb_device *dev, unsigned int langid,
  673. unsigned int index, unsigned char *buf)
  674. {
  675. int rc;
  676. /* Try to read the string descriptor by asking for the maximum
  677. * possible number of bytes */
  678. rc = usb_get_string(dev, langid, index, buf, 255);
  679. /* If that failed try to read the descriptor length, then
  680. * ask for just that many bytes */
  681. if (rc < 2) {
  682. rc = usb_get_string(dev, langid, index, buf, 2);
  683. if (rc == 2)
  684. rc = usb_get_string(dev, langid, index, buf, buf[0]);
  685. }
  686. if (rc >= 2) {
  687. if (!buf[0] && !buf[1])
  688. usb_try_string_workarounds(buf, &rc);
  689. /* There might be extra junk at the end of the descriptor */
  690. if (buf[0] < rc)
  691. rc = buf[0];
  692. rc = rc - (rc & 1); /* force a multiple of two */
  693. }
  694. if (rc < 2)
  695. rc = -EINVAL;
  696. return rc;
  697. }
  698. /********************************************************************
  699. * usb_string:
  700. * Get string index and translate it to ascii.
  701. * returns string length (> 0) or error (< 0)
  702. */
  703. int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
  704. {
  705. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, mybuf, USB_BUFSIZ);
  706. unsigned char *tbuf;
  707. int err;
  708. unsigned int u, idx;
  709. if (size <= 0 || !buf || !index)
  710. return -EINVAL;
  711. buf[0] = 0;
  712. tbuf = &mybuf[0];
  713. /* get langid for strings if it's not yet known */
  714. if (!dev->have_langid) {
  715. err = usb_string_sub(dev, 0, 0, tbuf);
  716. if (err < 0) {
  717. debug("error getting string descriptor 0 " \
  718. "(error=%lx)\n", dev->status);
  719. return -EIO;
  720. } else if (tbuf[0] < 4) {
  721. debug("string descriptor 0 too short\n");
  722. return -EIO;
  723. } else {
  724. dev->have_langid = -1;
  725. dev->string_langid = tbuf[2] | (tbuf[3] << 8);
  726. /* always use the first langid listed */
  727. debug("USB device number %d default " \
  728. "language ID 0x%x\n",
  729. dev->devnum, dev->string_langid);
  730. }
  731. }
  732. err = usb_string_sub(dev, dev->string_langid, index, tbuf);
  733. if (err < 0)
  734. return err;
  735. size--; /* leave room for trailing NULL char in output buffer */
  736. for (idx = 0, u = 2; u < err; u += 2) {
  737. if (idx >= size)
  738. break;
  739. if (tbuf[u+1]) /* high byte */
  740. buf[idx++] = '?'; /* non-ASCII character */
  741. else
  742. buf[idx++] = tbuf[u];
  743. }
  744. buf[idx] = 0;
  745. err = idx;
  746. return err;
  747. }
  748. /********************************************************************
  749. * USB device handling:
  750. * the USB device are static allocated [USB_MAX_DEVICE].
  751. */
  752. #if !CONFIG_IS_ENABLED(DM_USB)
  753. /* returns a pointer to the device with the index [index].
  754. * if the device is not assigned (dev->devnum==-1) returns NULL
  755. */
  756. struct usb_device *usb_get_dev_index(int index)
  757. {
  758. if (usb_dev[index].devnum == -1)
  759. return NULL;
  760. else
  761. return &usb_dev[index];
  762. }
  763. int usb_alloc_new_device(struct udevice *controller, struct usb_device **devp)
  764. {
  765. int i;
  766. debug("New Device %d\n", dev_index);
  767. if (dev_index == USB_MAX_DEVICE) {
  768. printf("ERROR, too many USB Devices, max=%d\n", USB_MAX_DEVICE);
  769. return -ENOSPC;
  770. }
  771. /* default Address is 0, real addresses start with 1 */
  772. usb_dev[dev_index].devnum = dev_index + 1;
  773. usb_dev[dev_index].maxchild = 0;
  774. for (i = 0; i < USB_MAXCHILDREN; i++)
  775. usb_dev[dev_index].children[i] = NULL;
  776. usb_dev[dev_index].parent = NULL;
  777. usb_dev[dev_index].controller = controller;
  778. dev_index++;
  779. *devp = &usb_dev[dev_index - 1];
  780. return 0;
  781. }
  782. /*
  783. * Free the newly created device node.
  784. * Called in error cases where configuring a newly attached
  785. * device fails for some reason.
  786. */
  787. void usb_free_device(struct udevice *controller)
  788. {
  789. dev_index--;
  790. debug("Freeing device node: %d\n", dev_index);
  791. memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
  792. usb_dev[dev_index].devnum = -1;
  793. }
  794. /*
  795. * XHCI issues Enable Slot command and thereafter
  796. * allocates device contexts. Provide a weak alias
  797. * function for the purpose, so that XHCI overrides it
  798. * and EHCI/OHCI just work out of the box.
  799. */
  800. __weak int usb_alloc_device(struct usb_device *udev)
  801. {
  802. return 0;
  803. }
  804. #endif /* !CONFIG_IS_ENABLED(DM_USB) */
  805. static int usb_hub_port_reset(struct usb_device *dev, struct usb_device *hub)
  806. {
  807. if (!hub)
  808. usb_reset_root_port(dev);
  809. return 0;
  810. }
  811. static int get_descriptor_len(struct usb_device *dev, int len, int expect_len)
  812. {
  813. __maybe_unused struct usb_device_descriptor *desc;
  814. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
  815. int err;
  816. desc = (struct usb_device_descriptor *)tmpbuf;
  817. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, len);
  818. if (err < expect_len) {
  819. if (err < 0) {
  820. printf("unable to get device descriptor (error=%d)\n",
  821. err);
  822. return err;
  823. } else {
  824. printf("USB device descriptor short read (expected %i, got %i)\n",
  825. expect_len, err);
  826. return -EIO;
  827. }
  828. }
  829. memcpy(&dev->descriptor, tmpbuf, sizeof(dev->descriptor));
  830. return 0;
  831. }
  832. static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
  833. {
  834. /*
  835. * This is a Windows scheme of initialization sequence, with double
  836. * reset of the device (Linux uses the same sequence)
  837. * Some equipment is said to work only with such init sequence; this
  838. * patch is based on the work by Alan Stern:
  839. * http://sourceforge.net/mailarchive/forum.php?
  840. * thread_id=5729457&forum_id=5398
  841. */
  842. /*
  843. * send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
  844. * only 18 bytes long, this will terminate with a short packet. But if
  845. * the maxpacket size is 8 or 16 the device may be waiting to transmit
  846. * some more, or keeps on retransmitting the 8 byte header.
  847. */
  848. if (dev->speed == USB_SPEED_LOW) {
  849. dev->descriptor.bMaxPacketSize0 = 8;
  850. dev->maxpacketsize = PACKET_SIZE_8;
  851. } else {
  852. dev->descriptor.bMaxPacketSize0 = 64;
  853. dev->maxpacketsize = PACKET_SIZE_64;
  854. }
  855. dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
  856. dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
  857. if (do_read && dev->speed == USB_SPEED_FULL) {
  858. int err;
  859. /*
  860. * Validate we've received only at least 8 bytes, not that
  861. * we've received the entire descriptor. The reasoning is:
  862. * - The code only uses fields in the first 8 bytes, so
  863. * that's all we need to have fetched at this stage.
  864. * - The smallest maxpacket size is 8 bytes. Before we know
  865. * the actual maxpacket the device uses, the USB controller
  866. * may only accept a single packet. Consequently we are only
  867. * guaranteed to receive 1 packet (at least 8 bytes) even in
  868. * a non-error case.
  869. *
  870. * At least the DWC2 controller needs to be programmed with
  871. * the number of packets in addition to the number of bytes.
  872. * A request for 64 bytes of data with the maxpacket guessed
  873. * as 64 (above) yields a request for 1 packet.
  874. */
  875. err = get_descriptor_len(dev, 64, 8);
  876. if (err)
  877. return err;
  878. }
  879. dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
  880. dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
  881. switch (dev->descriptor.bMaxPacketSize0) {
  882. case 8:
  883. dev->maxpacketsize = PACKET_SIZE_8;
  884. break;
  885. case 16:
  886. dev->maxpacketsize = PACKET_SIZE_16;
  887. break;
  888. case 32:
  889. dev->maxpacketsize = PACKET_SIZE_32;
  890. break;
  891. case 64:
  892. dev->maxpacketsize = PACKET_SIZE_64;
  893. break;
  894. default:
  895. printf("%s: invalid max packet size\n", __func__);
  896. return -EIO;
  897. }
  898. return 0;
  899. }
  900. static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
  901. struct usb_device *parent)
  902. {
  903. int err;
  904. /*
  905. * Allocate usb 3.0 device context.
  906. * USB 3.0 (xHCI) protocol tries to allocate device slot
  907. * and related data structures first. This call does that.
  908. * Refer to sec 4.3.2 in xHCI spec rev1.0
  909. */
  910. err = usb_alloc_device(dev);
  911. if (err) {
  912. printf("Cannot allocate device context to get SLOT_ID\n");
  913. return err;
  914. }
  915. err = usb_setup_descriptor(dev, do_read);
  916. if (err)
  917. return err;
  918. err = usb_hub_port_reset(dev, parent);
  919. if (err)
  920. return err;
  921. dev->devnum = addr;
  922. err = usb_set_address(dev); /* set address */
  923. if (err < 0) {
  924. printf("\n USB device not accepting new address " \
  925. "(error=%lX)\n", dev->status);
  926. return err;
  927. }
  928. mdelay(10); /* Let the SET_ADDRESS settle */
  929. /*
  930. * If we haven't read device descriptor before, read it here
  931. * after device is assigned an address. This is only applicable
  932. * to xHCI so far.
  933. */
  934. if (!do_read) {
  935. err = usb_setup_descriptor(dev, true);
  936. if (err)
  937. return err;
  938. }
  939. return 0;
  940. }
  941. int usb_select_config(struct usb_device *dev)
  942. {
  943. unsigned char *tmpbuf = NULL;
  944. int err;
  945. err = get_descriptor_len(dev, USB_DT_DEVICE_SIZE, USB_DT_DEVICE_SIZE);
  946. if (err)
  947. return err;
  948. /* correct le values */
  949. le16_to_cpus(&dev->descriptor.bcdUSB);
  950. le16_to_cpus(&dev->descriptor.idVendor);
  951. le16_to_cpus(&dev->descriptor.idProduct);
  952. le16_to_cpus(&dev->descriptor.bcdDevice);
  953. /*
  954. * Kingston DT Ultimate 32GB USB 3.0 seems to be extremely sensitive
  955. * about this first Get Descriptor request. If there are any other
  956. * requests in the first microframe, the stick crashes. Wait about
  957. * one microframe duration here (1mS for USB 1.x , 125uS for USB 2.0).
  958. */
  959. mdelay(1);
  960. /* only support for one config for now */
  961. err = usb_get_configuration_len(dev, 0);
  962. if (err >= 0) {
  963. tmpbuf = (unsigned char *)malloc_cache_aligned(err);
  964. if (!tmpbuf)
  965. err = -ENOMEM;
  966. else
  967. err = usb_get_configuration_no(dev, 0, tmpbuf, err);
  968. }
  969. if (err < 0) {
  970. printf("usb_new_device: Cannot read configuration, " \
  971. "skipping device %04x:%04x\n",
  972. dev->descriptor.idVendor, dev->descriptor.idProduct);
  973. free(tmpbuf);
  974. return err;
  975. }
  976. usb_parse_config(dev, tmpbuf, 0);
  977. free(tmpbuf);
  978. usb_set_maxpacket(dev);
  979. /*
  980. * we set the default configuration here
  981. * This seems premature. If the driver wants a different configuration
  982. * it will need to select itself.
  983. */
  984. err = usb_set_configuration(dev, dev->config.desc.bConfigurationValue);
  985. if (err < 0) {
  986. printf("failed to set default configuration " \
  987. "len %d, status %lX\n", dev->act_len, dev->status);
  988. return err;
  989. }
  990. /*
  991. * Wait until the Set Configuration request gets processed by the
  992. * device. This is required by at least SanDisk Cruzer Pop USB 2.0
  993. * and Kingston DT Ultimate 32GB USB 3.0 on DWC2 OTG controller.
  994. */
  995. mdelay(10);
  996. debug("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
  997. dev->descriptor.iManufacturer, dev->descriptor.iProduct,
  998. dev->descriptor.iSerialNumber);
  999. memset(dev->mf, 0, sizeof(dev->mf));
  1000. memset(dev->prod, 0, sizeof(dev->prod));
  1001. memset(dev->serial, 0, sizeof(dev->serial));
  1002. if (dev->descriptor.iManufacturer)
  1003. usb_string(dev, dev->descriptor.iManufacturer,
  1004. dev->mf, sizeof(dev->mf));
  1005. if (dev->descriptor.iProduct)
  1006. usb_string(dev, dev->descriptor.iProduct,
  1007. dev->prod, sizeof(dev->prod));
  1008. if (dev->descriptor.iSerialNumber)
  1009. usb_string(dev, dev->descriptor.iSerialNumber,
  1010. dev->serial, sizeof(dev->serial));
  1011. debug("Manufacturer %s\n", dev->mf);
  1012. debug("Product %s\n", dev->prod);
  1013. debug("SerialNumber %s\n", dev->serial);
  1014. return 0;
  1015. }
  1016. int usb_setup_device(struct usb_device *dev, bool do_read,
  1017. struct usb_device *parent)
  1018. {
  1019. int addr;
  1020. int ret;
  1021. /* We still haven't set the Address yet */
  1022. addr = dev->devnum;
  1023. dev->devnum = 0;
  1024. ret = usb_prepare_device(dev, addr, do_read, parent);
  1025. if (ret)
  1026. return ret;
  1027. ret = usb_select_config(dev);
  1028. return ret;
  1029. }
  1030. #if !CONFIG_IS_ENABLED(DM_USB)
  1031. /*
  1032. * By the time we get here, the device has gotten a new device ID
  1033. * and is in the default state. We need to identify the thing and
  1034. * get the ball rolling..
  1035. *
  1036. * Returns 0 for success, != 0 for error.
  1037. */
  1038. int usb_new_device(struct usb_device *dev)
  1039. {
  1040. bool do_read = true;
  1041. int err;
  1042. /*
  1043. * XHCI needs to issue a Address device command to setup
  1044. * proper device context structures, before it can interact
  1045. * with the device. So a get_descriptor will fail before any
  1046. * of that is done for XHCI unlike EHCI.
  1047. */
  1048. #ifdef CONFIG_USB_XHCI_HCD
  1049. do_read = false;
  1050. #endif
  1051. err = usb_setup_device(dev, do_read, dev->parent);
  1052. if (err)
  1053. return err;
  1054. /* Now probe if the device is a hub */
  1055. err = usb_hub_probe(dev, 0);
  1056. if (err < 0)
  1057. return err;
  1058. return 0;
  1059. }
  1060. #endif
  1061. __weak
  1062. int board_usb_init(int index, enum usb_init_type init)
  1063. {
  1064. return 0;
  1065. }
  1066. __weak
  1067. int board_usb_cleanup(int index, enum usb_init_type init)
  1068. {
  1069. return 0;
  1070. }
  1071. bool usb_device_has_child_on_port(struct usb_device *parent, int port)
  1072. {
  1073. #if CONFIG_IS_ENABLED(DM_USB)
  1074. return false;
  1075. #else
  1076. return parent->children[port] != NULL;
  1077. #endif
  1078. }
  1079. #if CONFIG_IS_ENABLED(DM_USB)
  1080. void usb_find_usb2_hub_address_port(struct usb_device *udev,
  1081. uint8_t *hub_address, uint8_t *hub_port)
  1082. {
  1083. struct udevice *parent;
  1084. struct usb_device *uparent, *ttdev;
  1085. /*
  1086. * When called from usb-uclass.c: usb_scan_device() udev->dev points
  1087. * to the parent udevice, not the actual udevice belonging to the
  1088. * udev as the device is not instantiated yet. So when searching
  1089. * for the first usb-2 parent start with udev->dev not
  1090. * udev->dev->parent .
  1091. */
  1092. ttdev = udev;
  1093. parent = udev->dev;
  1094. uparent = dev_get_parent_priv(parent);
  1095. while (uparent->speed != USB_SPEED_HIGH) {
  1096. struct udevice *dev = parent;
  1097. if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB) {
  1098. printf("Error: Cannot find high speed parent of usb-1 device\n");
  1099. *hub_address = 0;
  1100. *hub_port = 0;
  1101. return;
  1102. }
  1103. ttdev = dev_get_parent_priv(dev);
  1104. parent = dev->parent;
  1105. uparent = dev_get_parent_priv(parent);
  1106. }
  1107. *hub_address = uparent->devnum;
  1108. *hub_port = ttdev->portnr;
  1109. }
  1110. #else
  1111. void usb_find_usb2_hub_address_port(struct usb_device *udev,
  1112. uint8_t *hub_address, uint8_t *hub_port)
  1113. {
  1114. /* Find out the nearest parent which is high speed */
  1115. while (udev->parent->parent != NULL)
  1116. if (udev->parent->speed != USB_SPEED_HIGH) {
  1117. udev = udev->parent;
  1118. } else {
  1119. *hub_address = udev->parent->devnum;
  1120. *hub_port = udev->portnr;
  1121. return;
  1122. }
  1123. printf("Error: Cannot find high speed parent of usb-1 device\n");
  1124. *hub_address = 0;
  1125. *hub_port = 0;
  1126. }
  1127. #endif
  1128. /* EOF */