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