1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright 2024 Google LLC
4 */
5 #ifndef __ANDROID_CONFIGFS_UEVENT_H
6 #define __ANDROID_CONFIGFS_UEVENT_H
7
8 #ifdef CONFIG_ANDROID_USB_CONFIGFS_UEVENT
9 #include <linux/usb/android_configfs_uevent.h>
10
11 /**
12 * android_class_create - essentially the __init() function for the
13 * configfs_uevent library, since it is not a standalone driver.
14 *
15 * Creates the android_usb class of device
16 *
17 * Returns: the result of class_register (0 for success, err otherwise)
18 */
19 int android_class_create(void);
20
21 /**
22 * android_class_destroy - essentially the __exit() function for the
23 * configfs_uevent library, since it is not a standalone driver.
24 *
25 * Removes the android_usb class of devices and performs any necessary
26 * cleanup.
27 */
28 void android_class_destroy(void);
29
30 /**
31 * android_device_create - Creates an android device instance and
32 * a state attribute file which can be read to determine the state of the
33 * usb gadget.
34 * @opts: contextual data for the configfs_uevent library.
35 *
36 * Note: the state file created by this function mimics the functionaltiy
37 * of the UDC driver and is likely redundant, but maintained for legacy
38 * support.
39 *
40 * The state can be one of "DISCONNECTED", "CONNECTED", or "CONFIGURED"
41 *
42 * Returns: 0 for success, or if an error is encountered during ida_allocation
43 * or device_creation, that error is returned.
44 */
45 int android_device_create(struct android_uevent_opts *opts);
46
47 /**
48 * android_device_destroy - Removes the android device instance and performs
49 * any necessary cleanup.
50 * @opts: contextual data for the configfs_uevent library.
51 */
52 void android_device_destroy(struct android_uevent_opts *opts);
53
54 /**
55 * android_set_connected - set the internal state of android_uevent_opts to
56 * connected and schedule the work to emit a uevent with this status update.
57 * @opts: contextual data for the configfs_uevent library
58 *
59 * This should be called by the gadget composite driver when a usb_ctrlrequest
60 * is received by the gadget driver.
61 *
62 * This function locks the android specific android_uevent_opts->lock and
63 * therefore should not require locking the containing composite device
64 * structure as the internal lock is also used in the teardown path of the
65 * composite driver in android_device_destroy().
66 */
67 void android_set_connected(struct android_uevent_opts *opts);
68
69 /**
70 * android_set_disconnected - reset the internal state of android_uevent_opts to
71 * disconnected and schedule the work to emit a uevent with this status update.
72 * @opts: contextual data for the configfs_uevent library
73 *
74 * This should be called by the gadget composite driver when the link is
75 * disconnected.
76 *
77 * This function locks the android specific android_uevent_opts->lock and
78 * therefore should not require locking the containing composite device
79 * structure as the internal lock is also used in the teardown path of the
80 * composite driver in android_device_destroy().
81 */
82 void android_set_disconnected(struct android_uevent_opts *opts);
83
84 /**
85 * android_set_configured - set the internal state of android_uevent_opts to
86 * configured and schedule the work to emit a uevent with this status update.
87 * @opts: contextual data for the configfs_uevent library
88 *
89 * This should be called by the gadget composite driver when the configuration
90 * is applied to the gadget composite device
91 *
92 * This function locks the android specific android_uevent_opts->lock and
93 * therefore should not require locking the containing composite device
94 * structure as the internal lock is also used in the teardown path of the
95 * composite driver in android_device_destroy().
96 */
97 void android_set_configured(struct android_uevent_opts *opts);
98
99 /**
100 * android_set_unconfigured - reset the internal state of android_uevent_opts to
101 * unconfigured and schedule the work to emit a uevent with this status update.
102 * @opts: contextual data for the configfs_uevent library
103 *
104 * This should be called by the gadget composite driver when the gadget
105 * configuration is torn down.
106 *
107 * This function locks the android specific android_uevent_opts->lock and
108 * therefore should not require locking the containing composite device
109 * structure as the internal lock is also used in the teardown path of the
110 * composite driver in android_device_destroy().
111 */
112 void android_set_unconfigured(struct android_uevent_opts *opts);
113
114 #else
115
android_class_create(void)116 static inline int android_class_create(void)
117 {
118 return 0;
119 }
120
android_class_destroy(void)121 static inline void android_class_destroy(void)
122 {
123 }
124
android_device_create(struct android_uevent_opts * opts)125 static inline int android_device_create(struct android_uevent_opts *opts)
126 {
127 return 0;
128 }
129
android_device_destroy(struct android_uevent_opts * opts)130 static inline void android_device_destroy(struct android_uevent_opts *opts)
131 {
132 }
133
android_set_connected(struct android_uevent_opts * opts)134 static inline void android_set_connected(struct android_uevent_opts *opts)
135 {
136 }
137
android_set_disconnected(struct android_uevent_opts * opts)138 static inline void android_set_disconnected(struct android_uevent_opts *opts)
139 {
140 }
141
android_set_configured(struct android_uevent_opts * opts)142 static inline void android_set_configured(struct android_uevent_opts *opts)
143 {
144 }
145
android_set_unconfigured(struct android_uevent_opts * opts)146 static inline void android_set_unconfigured(struct android_uevent_opts *opts)
147 {
148 }
149 #endif /* CONFIG_ANDROID_USB_CONFIGFS_UEVENT */
150 #endif /* __ANDROID_CONFIGFS_UEVENT_H */
151