xref: /openbmc/linux/drivers/usb/core/usb.h (revision 643d1f7f)
1 /* Functions local to drivers/usb/core/ */
2 
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 int 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_files(struct device *parent,
8 				struct usb_host_endpoint *endpoint,
9 				struct usb_device *udev);
10 extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
11 
12 extern void usb_enable_endpoint(struct usb_device *dev,
13 		struct usb_host_endpoint *ep);
14 extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr);
15 extern void usb_disable_interface(struct usb_device *dev,
16 		struct usb_interface *intf);
17 extern void usb_release_interface_cache(struct kref *ref);
18 extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
19 extern int usb_deauthorize_device(struct usb_device *);
20 extern int usb_authorize_device(struct usb_device *);
21 extern void usb_detect_quirks(struct usb_device *udev);
22 
23 extern int usb_get_device_descriptor(struct usb_device *dev,
24 		unsigned int size);
25 extern char *usb_cache_string(struct usb_device *udev, int index);
26 extern int usb_set_configuration(struct usb_device *dev, int configuration);
27 extern int usb_choose_configuration(struct usb_device *udev);
28 
29 extern void usb_kick_khubd(struct usb_device *dev);
30 extern int usb_match_device(struct usb_device *dev,
31 			    const struct usb_device_id *id);
32 
33 extern int  usb_hub_init(void);
34 extern void usb_hub_cleanup(void);
35 extern int usb_major_init(void);
36 extern void usb_major_cleanup(void);
37 extern int usb_host_init(void);
38 extern void usb_host_cleanup(void);
39 
40 #ifdef	CONFIG_PM
41 
42 extern void usb_autosuspend_work(struct work_struct *work);
43 extern int usb_port_suspend(struct usb_device *dev);
44 extern int usb_port_resume(struct usb_device *dev);
45 extern int usb_external_suspend_device(struct usb_device *udev,
46 		pm_message_t msg);
47 extern int usb_external_resume_device(struct usb_device *udev);
48 
49 static inline void usb_pm_lock(struct usb_device *udev)
50 {
51 	mutex_lock_nested(&udev->pm_mutex, udev->level);
52 }
53 
54 static inline void usb_pm_unlock(struct usb_device *udev)
55 {
56 	mutex_unlock(&udev->pm_mutex);
57 }
58 
59 #else
60 
61 static inline int usb_port_suspend(struct usb_device *udev)
62 {
63 	return 0;
64 }
65 
66 static inline int usb_port_resume(struct usb_device *udev)
67 {
68 	return 0;
69 }
70 
71 static inline void usb_pm_lock(struct usb_device *udev) {}
72 static inline void usb_pm_unlock(struct usb_device *udev) {}
73 
74 #endif
75 
76 #ifdef CONFIG_USB_SUSPEND
77 
78 extern void usb_autosuspend_device(struct usb_device *udev);
79 extern void usb_try_autosuspend_device(struct usb_device *udev);
80 extern int usb_autoresume_device(struct usb_device *udev);
81 
82 #else
83 
84 #define usb_autosuspend_device(udev)		do {} while (0)
85 #define usb_try_autosuspend_device(udev)	do {} while (0)
86 static inline int usb_autoresume_device(struct usb_device *udev)
87 {
88 	return 0;
89 }
90 
91 #endif
92 
93 extern struct workqueue_struct *ksuspend_usb_wq;
94 extern struct bus_type usb_bus_type;
95 extern struct device_type usb_device_type;
96 extern struct device_type usb_if_device_type;
97 extern struct usb_device_driver usb_generic_driver;
98 
99 static inline int is_usb_device(const struct device *dev)
100 {
101 	return dev->type == &usb_device_type;
102 }
103 
104 /* Do the same for device drivers and interface drivers. */
105 
106 static inline int is_usb_device_driver(struct device_driver *drv)
107 {
108 	return container_of(drv, struct usbdrv_wrap, driver)->
109 			for_devices;
110 }
111 
112 /* Interfaces and their "power state" are owned by usbcore */
113 
114 static inline void mark_active(struct usb_interface *f)
115 {
116 	f->is_active = 1;
117 	f->dev.power.power_state.event = PM_EVENT_ON;
118 }
119 
120 static inline void mark_quiesced(struct usb_interface *f)
121 {
122 	f->is_active = 0;
123 	f->dev.power.power_state.event = PM_EVENT_SUSPEND;
124 }
125 
126 static inline int is_active(const struct usb_interface *f)
127 {
128 	return f->is_active;
129 }
130 
131 
132 /* for labeling diagnostics */
133 extern const char *usbcore_name;
134 
135 /* usbfs stuff */
136 extern struct mutex usbfs_mutex;
137 extern struct usb_driver usbfs_driver;
138 extern const struct file_operations usbfs_devices_fops;
139 extern const struct file_operations usbdev_file_operations;
140 extern void usbfs_conn_disc_event(void);
141 
142 extern int usb_devio_init(void);
143 extern void usb_devio_cleanup(void);
144 
145 struct dev_state {
146 	struct list_head list;      /* state list */
147 	struct usb_device *dev;
148 	struct file *file;
149 	spinlock_t lock;            /* protects the async urb lists */
150 	struct list_head async_pending;
151 	struct list_head async_completed;
152 	wait_queue_head_t wait;     /* wake up if a request completed */
153 	unsigned int discsignr;
154 	struct pid *disc_pid;
155 	uid_t disc_uid, disc_euid;
156 	void __user *disccontext;
157 	unsigned long ifclaimed;
158 	u32 secid;
159 };
160 
161 /* internal notify stuff */
162 extern void usb_notify_add_device(struct usb_device *udev);
163 extern void usb_notify_remove_device(struct usb_device *udev);
164 extern void usb_notify_add_bus(struct usb_bus *ubus);
165 extern void usb_notify_remove_bus(struct usb_bus *ubus);
166 
167