usb.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include <linux/pm.h>
  2. #include <linux/acpi.h>
  3. struct usb_hub_descriptor;
  4. struct usb_dev_state;
  5. /* Functions local to drivers/usb/core/ */
  6. extern int usb_create_sysfs_dev_files(struct usb_device *dev);
  7. extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
  8. extern void usb_create_sysfs_intf_files(struct usb_interface *intf);
  9. extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
  10. extern int usb_create_ep_devs(struct device *parent,
  11. struct usb_host_endpoint *endpoint,
  12. struct usb_device *udev);
  13. extern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint);
  14. extern void usb_enable_endpoint(struct usb_device *dev,
  15. struct usb_host_endpoint *ep, bool reset_toggle);
  16. extern void usb_enable_interface(struct usb_device *dev,
  17. struct usb_interface *intf, bool reset_toggles);
  18. extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
  19. bool reset_hardware);
  20. extern void usb_disable_interface(struct usb_device *dev,
  21. struct usb_interface *intf, bool reset_hardware);
  22. extern void usb_release_interface_cache(struct kref *ref);
  23. extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
  24. extern int usb_deauthorize_device(struct usb_device *);
  25. extern int usb_authorize_device(struct usb_device *);
  26. extern void usb_deauthorize_interface(struct usb_interface *);
  27. extern void usb_authorize_interface(struct usb_interface *);
  28. extern void usb_detect_quirks(struct usb_device *udev);
  29. extern void usb_detect_interface_quirks(struct usb_device *udev);
  30. extern int usb_remove_device(struct usb_device *udev);
  31. extern int usb_get_device_descriptor(struct usb_device *dev,
  32. unsigned int size);
  33. extern int usb_get_bos_descriptor(struct usb_device *dev);
  34. extern void usb_release_bos_descriptor(struct usb_device *dev);
  35. extern char *usb_cache_string(struct usb_device *udev, int index);
  36. extern int usb_set_configuration(struct usb_device *dev, int configuration);
  37. extern int usb_choose_configuration(struct usb_device *udev);
  38. static inline unsigned usb_get_max_power(struct usb_device *udev,
  39. struct usb_host_config *c)
  40. {
  41. /* SuperSpeed power is in 8 mA units; others are in 2 mA units */
  42. unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2);
  43. return c->desc.bMaxPower * mul;
  44. }
  45. extern void usb_kick_hub_wq(struct usb_device *dev);
  46. extern int usb_match_one_id_intf(struct usb_device *dev,
  47. struct usb_host_interface *intf,
  48. const struct usb_device_id *id);
  49. extern int usb_match_device(struct usb_device *dev,
  50. const struct usb_device_id *id);
  51. extern void usb_forced_unbind_intf(struct usb_interface *intf);
  52. extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
  53. extern void usb_hub_release_all_ports(struct usb_device *hdev,
  54. struct usb_dev_state *owner);
  55. extern bool usb_device_is_owned(struct usb_device *udev);
  56. extern int usb_hub_init(void);
  57. extern void usb_hub_cleanup(void);
  58. extern int usb_major_init(void);
  59. extern void usb_major_cleanup(void);
  60. extern int usb_device_supports_lpm(struct usb_device *udev);
  61. #ifdef CONFIG_PM
  62. extern int usb_suspend(struct device *dev, pm_message_t msg);
  63. extern int usb_resume(struct device *dev, pm_message_t msg);
  64. extern int usb_resume_complete(struct device *dev);
  65. extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
  66. extern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
  67. extern void usb_autosuspend_device(struct usb_device *udev);
  68. extern int usb_autoresume_device(struct usb_device *udev);
  69. extern int usb_remote_wakeup(struct usb_device *dev);
  70. extern int usb_runtime_suspend(struct device *dev);
  71. extern int usb_runtime_resume(struct device *dev);
  72. extern int usb_runtime_idle(struct device *dev);
  73. extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
  74. #else
  75. static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
  76. {
  77. return 0;
  78. }
  79. static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
  80. {
  81. return 0;
  82. }
  83. #define usb_autosuspend_device(udev) do {} while (0)
  84. static inline int usb_autoresume_device(struct usb_device *udev)
  85. {
  86. return 0;
  87. }
  88. static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
  89. {
  90. return 0;
  91. }
  92. #endif
  93. extern struct bus_type usb_bus_type;
  94. extern struct mutex usb_port_peer_mutex;
  95. extern struct device_type usb_device_type;
  96. extern struct device_type usb_if_device_type;
  97. extern struct device_type usb_ep_device_type;
  98. extern struct device_type usb_port_device_type;
  99. extern struct usb_device_driver usb_generic_driver;
  100. static inline int is_usb_device(const struct device *dev)
  101. {
  102. return dev->type == &usb_device_type;
  103. }
  104. static inline int is_usb_interface(const struct device *dev)
  105. {
  106. return dev->type == &usb_if_device_type;
  107. }
  108. static inline int is_usb_endpoint(const struct device *dev)
  109. {
  110. return dev->type == &usb_ep_device_type;
  111. }
  112. static inline int is_usb_port(const struct device *dev)
  113. {
  114. return dev->type == &usb_port_device_type;
  115. }
  116. /* Do the same for device drivers and interface drivers. */
  117. static inline int is_usb_device_driver(struct device_driver *drv)
  118. {
  119. return container_of(drv, struct usbdrv_wrap, driver)->
  120. for_devices;
  121. }
  122. /* for labeling diagnostics */
  123. extern const char *usbcore_name;
  124. /* sysfs stuff */
  125. extern const struct attribute_group *usb_device_groups[];
  126. extern const struct attribute_group *usb_interface_groups[];
  127. /* usbfs stuff */
  128. extern struct mutex usbfs_mutex;
  129. extern struct usb_driver usbfs_driver;
  130. extern const struct file_operations usbfs_devices_fops;
  131. extern const struct file_operations usbdev_file_operations;
  132. extern void usbfs_conn_disc_event(void);
  133. extern int usb_devio_init(void);
  134. extern void usb_devio_cleanup(void);
  135. /*
  136. * Firmware specific cookie identifying a port's location. '0' == no location
  137. * data available
  138. */
  139. typedef u32 usb_port_location_t;
  140. /* internal notify stuff */
  141. extern void usb_notify_add_device(struct usb_device *udev);
  142. extern void usb_notify_remove_device(struct usb_device *udev);
  143. extern void usb_notify_add_bus(struct usb_bus *ubus);
  144. extern void usb_notify_remove_bus(struct usb_bus *ubus);
  145. extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
  146. struct usb_hub_descriptor *desc);
  147. #ifdef CONFIG_ACPI
  148. extern int usb_acpi_register(void);
  149. extern void usb_acpi_unregister(void);
  150. extern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
  151. int port1);
  152. #else
  153. static inline int usb_acpi_register(void) { return 0; };
  154. static inline void usb_acpi_unregister(void) { };
  155. #endif