usb.c 34 KB

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