hub.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * usb hub driver head file
  3. *
  4. * Copyright (C) 1999 Linus Torvalds
  5. * Copyright (C) 1999 Johannes Erdfelt
  6. * Copyright (C) 1999 Gregory P. Smith
  7. * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au)
  8. * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com)
  9. *
  10. * move struct usb_hub to this file.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  18. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  19. * for more details.
  20. */
  21. #include <linux/usb.h>
  22. #include <linux/usb/ch11.h>
  23. #include <linux/usb/hcd.h>
  24. #include "usb.h"
  25. struct usb_hub {
  26. struct device *intfdev; /* the "interface" device */
  27. struct usb_device *hdev;
  28. struct kref kref;
  29. struct urb *urb; /* for interrupt polling pipe */
  30. /* buffer for urb ... with extra space in case of babble */
  31. u8 (*buffer)[8];
  32. union {
  33. struct usb_hub_status hub;
  34. struct usb_port_status port;
  35. } *status; /* buffer for status reports */
  36. struct mutex status_mutex; /* for the status buffer */
  37. int error; /* last reported error */
  38. int nerrors; /* track consecutive errors */
  39. unsigned long event_bits[1]; /* status change bitmask */
  40. unsigned long change_bits[1]; /* ports with logical connect
  41. status change */
  42. unsigned long removed_bits[1]; /* ports with a "removed"
  43. device present */
  44. unsigned long wakeup_bits[1]; /* ports that have signaled
  45. remote wakeup */
  46. unsigned long power_bits[1]; /* ports that are powered */
  47. unsigned long child_usage_bits[1]; /* ports powered on for
  48. children */
  49. unsigned long warm_reset_bits[1]; /* ports requesting warm
  50. reset recovery */
  51. #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
  52. #error event_bits[] is too short!
  53. #endif
  54. struct usb_hub_descriptor *descriptor; /* class descriptor */
  55. struct usb_tt tt; /* Transaction Translator */
  56. unsigned mA_per_port; /* current for each child */
  57. #ifdef CONFIG_PM
  58. unsigned wakeup_enabled_descendants;
  59. #endif
  60. unsigned limited_power:1;
  61. unsigned quiescing:1;
  62. unsigned disconnected:1;
  63. unsigned in_reset:1;
  64. unsigned quirk_check_port_auto_suspend:1;
  65. unsigned has_indicators:1;
  66. u8 indicator[USB_MAXCHILDREN];
  67. struct delayed_work leds;
  68. struct delayed_work init_work;
  69. struct work_struct events;
  70. struct usb_port **ports;
  71. };
  72. /**
  73. * struct usb port - kernel's representation of a usb port
  74. * @child: usb device attached to the port
  75. * @dev: generic device interface
  76. * @port_owner: port's owner
  77. * @peer: related usb2 and usb3 ports (share the same connector)
  78. * @req: default pm qos request for hubs without port power control
  79. * @connect_type: port's connect type
  80. * @location: opaque representation of platform connector location
  81. * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
  82. * @portnum: port index num based one
  83. * @is_superspeed cache super-speed status
  84. */
  85. struct usb_port {
  86. struct usb_device *child;
  87. struct device dev;
  88. struct usb_dev_state *port_owner;
  89. struct usb_port *peer;
  90. struct dev_pm_qos_request *req;
  91. enum usb_port_connect_type connect_type;
  92. usb_port_location_t location;
  93. struct mutex status_lock;
  94. u8 portnum;
  95. unsigned int is_superspeed:1;
  96. };
  97. #define to_usb_port(_dev) \
  98. container_of(_dev, struct usb_port, dev)
  99. extern int usb_hub_create_port_device(struct usb_hub *hub,
  100. int port1);
  101. extern void usb_hub_remove_port_device(struct usb_hub *hub,
  102. int port1);
  103. extern int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
  104. int port1, bool set);
  105. extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev);
  106. extern int hub_port_debounce(struct usb_hub *hub, int port1,
  107. bool must_be_connected);
  108. extern int usb_clear_port_feature(struct usb_device *hdev,
  109. int port1, int feature);
  110. static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
  111. {
  112. __le16 hcs;
  113. if (!hub)
  114. return false;
  115. hcs = hub->descriptor->wHubCharacteristics;
  116. return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
  117. }
  118. static inline int hub_is_superspeed(struct usb_device *hdev)
  119. {
  120. return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS;
  121. }
  122. static inline unsigned hub_power_on_good_delay(struct usb_hub *hub)
  123. {
  124. unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2;
  125. /* Wait at least 100 msec for power to become stable */
  126. return max(delay, 100U);
  127. }
  128. static inline int hub_port_debounce_be_connected(struct usb_hub *hub,
  129. int port1)
  130. {
  131. return hub_port_debounce(hub, port1, true);
  132. }
  133. static inline int hub_port_debounce_be_stable(struct usb_hub *hub,
  134. int port1)
  135. {
  136. return hub_port_debounce(hub, port1, false);
  137. }