usb.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include <linux/pm.h>
  2. /* Functions local to drivers/usb/core/ */
  3. extern int usb_create_sysfs_dev_files(struct usb_device *dev);
  4. extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
  5. extern void usb_create_sysfs_intf_files(struct usb_interface *intf);
  6. extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
  7. extern int usb_create_ep_devs(struct device *parent,
  8. struct usb_host_endpoint *endpoint,
  9. struct usb_device *udev);
  10. extern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint);
  11. extern void usb_enable_endpoint(struct usb_device *dev,
  12. struct usb_host_endpoint *ep, bool reset_toggle);
  13. extern void usb_enable_interface(struct usb_device *dev,
  14. struct usb_interface *intf, bool reset_toggles);
  15. extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
  16. bool reset_hardware);
  17. extern void usb_disable_interface(struct usb_device *dev,
  18. struct usb_interface *intf, bool reset_hardware);
  19. extern void usb_release_interface_cache(struct kref *ref);
  20. extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
  21. extern int usb_deauthorize_device(struct usb_device *);
  22. extern int usb_authorize_device(struct usb_device *);
  23. extern void usb_detect_quirks(struct usb_device *udev);
  24. extern int usb_remove_device(struct usb_device *udev);
  25. extern int usb_get_device_descriptor(struct usb_device *dev,
  26. unsigned int size);
  27. extern char *usb_cache_string(struct usb_device *udev, int index);
  28. extern int usb_set_configuration(struct usb_device *dev, int configuration);
  29. extern int usb_choose_configuration(struct usb_device *udev);
  30. extern void usb_kick_khubd(struct usb_device *dev);
  31. extern int usb_match_device(struct usb_device *dev,
  32. const struct usb_device_id *id);
  33. extern void usb_forced_unbind_intf(struct usb_interface *intf);
  34. extern void usb_rebind_intf(struct usb_interface *intf);
  35. extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port,
  36. void *owner);
  37. extern int usb_hub_release_port(struct usb_device *hdev, unsigned port,
  38. void *owner);
  39. extern void usb_hub_release_all_ports(struct usb_device *hdev, void *owner);
  40. extern bool usb_device_is_owned(struct usb_device *udev);
  41. extern int usb_hub_init(void);
  42. extern void usb_hub_cleanup(void);
  43. extern int usb_major_init(void);
  44. extern void usb_major_cleanup(void);
  45. #ifdef CONFIG_PM
  46. extern int usb_suspend(struct device *dev, pm_message_t msg);
  47. extern int usb_resume(struct device *dev, pm_message_t msg);
  48. extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
  49. extern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
  50. #else
  51. static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
  52. {
  53. return 0;
  54. }
  55. static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
  56. {
  57. return 0;
  58. }
  59. #endif
  60. #ifdef CONFIG_USB_SUSPEND
  61. extern void usb_autosuspend_device(struct usb_device *udev);
  62. extern int usb_autoresume_device(struct usb_device *udev);
  63. extern int usb_remote_wakeup(struct usb_device *dev);
  64. extern int usb_runtime_suspend(struct device *dev);
  65. extern int usb_runtime_resume(struct device *dev);
  66. extern int usb_runtime_idle(struct device *dev);
  67. #else
  68. #define usb_autosuspend_device(udev) do {} while (0)
  69. static inline int usb_autoresume_device(struct usb_device *udev)
  70. {
  71. return 0;
  72. }
  73. static inline int usb_remote_wakeup(struct usb_device *udev)
  74. {
  75. return 0;
  76. }
  77. #endif
  78. extern struct bus_type usb_bus_type;
  79. extern struct device_type usb_device_type;
  80. extern struct device_type usb_if_device_type;
  81. extern struct device_type usb_ep_device_type;
  82. extern struct usb_device_driver usb_generic_driver;
  83. static inline int is_usb_device(const struct device *dev)
  84. {
  85. return dev->type == &usb_device_type;
  86. }
  87. static inline int is_usb_interface(const struct device *dev)
  88. {
  89. return dev->type == &usb_if_device_type;
  90. }
  91. static inline int is_usb_endpoint(const struct device *dev)
  92. {
  93. return dev->type == &usb_ep_device_type;
  94. }
  95. /* Do the same for device drivers and interface drivers. */
  96. static inline int is_usb_device_driver(struct device_driver *drv)
  97. {
  98. return container_of(drv, struct usbdrv_wrap, driver)->
  99. for_devices;
  100. }
  101. /* translate USB error codes to codes user space understands */
  102. static inline int usb_translate_errors(int error_code)
  103. {
  104. switch (error_code) {
  105. case 0:
  106. case -ENOMEM:
  107. case -ENODEV:
  108. return error_code;
  109. default:
  110. return -EIO;
  111. }
  112. }
  113. /* for labeling diagnostics */
  114. extern const char *usbcore_name;
  115. /* sysfs stuff */
  116. extern const struct attribute_group *usb_device_groups[];
  117. extern const struct attribute_group *usb_interface_groups[];
  118. /* usbfs stuff */
  119. extern struct mutex usbfs_mutex;
  120. extern struct usb_driver usbfs_driver;
  121. extern const struct file_operations usbfs_devices_fops;
  122. extern const struct file_operations usbdev_file_operations;
  123. extern void usbfs_conn_disc_event(void);
  124. extern int usb_devio_init(void);
  125. extern void usb_devio_cleanup(void);
  126. /* internal notify stuff */
  127. extern void usb_notify_add_device(struct usb_device *udev);
  128. extern void usb_notify_remove_device(struct usb_device *udev);
  129. extern void usb_notify_add_bus(struct usb_bus *ubus);
  130. extern void usb_notify_remove_bus(struct usb_bus *ubus);