This source file includes following definitions.
- i3c_device_do_priv_xfers
- i3c_device_get_info
- i3c_device_disable_ibi
- i3c_device_enable_ibi
- i3c_device_request_ibi
- i3c_device_free_ibi
- i3cdev_to_dev
- dev_to_i3cdev
- i3c_device_match_id
- i3c_driver_register_with_owner
- i3c_driver_unregister
1
2
3
4
5
6
7
8 #include <linux/atomic.h>
9 #include <linux/bug.h>
10 #include <linux/completion.h>
11 #include <linux/device.h>
12 #include <linux/mutex.h>
13 #include <linux/slab.h>
14
15 #include "internals.h"
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 int i3c_device_do_priv_xfers(struct i3c_device *dev,
32 struct i3c_priv_xfer *xfers,
33 int nxfers)
34 {
35 int ret, i;
36
37 if (nxfers < 1)
38 return 0;
39
40 for (i = 0; i < nxfers; i++) {
41 if (!xfers[i].len || !xfers[i].data.in)
42 return -EINVAL;
43 }
44
45 i3c_bus_normaluse_lock(dev->bus);
46 ret = i3c_dev_do_priv_xfers_locked(dev->desc, xfers, nxfers);
47 i3c_bus_normaluse_unlock(dev->bus);
48
49 return ret;
50 }
51 EXPORT_SYMBOL_GPL(i3c_device_do_priv_xfers);
52
53
54
55
56
57
58
59
60
61 void i3c_device_get_info(struct i3c_device *dev,
62 struct i3c_device_info *info)
63 {
64 if (!info)
65 return;
66
67 i3c_bus_normaluse_lock(dev->bus);
68 if (dev->desc)
69 *info = dev->desc->info;
70 i3c_bus_normaluse_unlock(dev->bus);
71 }
72 EXPORT_SYMBOL_GPL(i3c_device_get_info);
73
74
75
76
77
78
79
80
81
82
83 int i3c_device_disable_ibi(struct i3c_device *dev)
84 {
85 int ret = -ENOENT;
86
87 i3c_bus_normaluse_lock(dev->bus);
88 if (dev->desc) {
89 mutex_lock(&dev->desc->ibi_lock);
90 ret = i3c_dev_disable_ibi_locked(dev->desc);
91 mutex_unlock(&dev->desc->ibi_lock);
92 }
93 i3c_bus_normaluse_unlock(dev->bus);
94
95 return ret;
96 }
97 EXPORT_SYMBOL_GPL(i3c_device_disable_ibi);
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 int i3c_device_enable_ibi(struct i3c_device *dev)
113 {
114 int ret = -ENOENT;
115
116 i3c_bus_normaluse_lock(dev->bus);
117 if (dev->desc) {
118 mutex_lock(&dev->desc->ibi_lock);
119 ret = i3c_dev_enable_ibi_locked(dev->desc);
120 mutex_unlock(&dev->desc->ibi_lock);
121 }
122 i3c_bus_normaluse_unlock(dev->bus);
123
124 return ret;
125 }
126 EXPORT_SYMBOL_GPL(i3c_device_enable_ibi);
127
128
129
130
131
132
133
134
135
136
137
138
139 int i3c_device_request_ibi(struct i3c_device *dev,
140 const struct i3c_ibi_setup *req)
141 {
142 int ret = -ENOENT;
143
144 if (!req->handler || !req->num_slots)
145 return -EINVAL;
146
147 i3c_bus_normaluse_lock(dev->bus);
148 if (dev->desc) {
149 mutex_lock(&dev->desc->ibi_lock);
150 ret = i3c_dev_request_ibi_locked(dev->desc, req);
151 mutex_unlock(&dev->desc->ibi_lock);
152 }
153 i3c_bus_normaluse_unlock(dev->bus);
154
155 return ret;
156 }
157 EXPORT_SYMBOL_GPL(i3c_device_request_ibi);
158
159
160
161
162
163
164
165
166
167 void i3c_device_free_ibi(struct i3c_device *dev)
168 {
169 i3c_bus_normaluse_lock(dev->bus);
170 if (dev->desc) {
171 mutex_lock(&dev->desc->ibi_lock);
172 i3c_dev_free_ibi_locked(dev->desc);
173 mutex_unlock(&dev->desc->ibi_lock);
174 }
175 i3c_bus_normaluse_unlock(dev->bus);
176 }
177 EXPORT_SYMBOL_GPL(i3c_device_free_ibi);
178
179
180
181
182
183
184
185 struct device *i3cdev_to_dev(struct i3c_device *i3cdev)
186 {
187 return &i3cdev->dev;
188 }
189 EXPORT_SYMBOL_GPL(i3cdev_to_dev);
190
191
192
193
194
195
196
197 struct i3c_device *dev_to_i3cdev(struct device *dev)
198 {
199 return container_of(dev, struct i3c_device, dev);
200 }
201 EXPORT_SYMBOL_GPL(dev_to_i3cdev);
202
203
204
205
206
207
208
209
210 const struct i3c_device_id *
211 i3c_device_match_id(struct i3c_device *i3cdev,
212 const struct i3c_device_id *id_table)
213 {
214 struct i3c_device_info devinfo;
215 const struct i3c_device_id *id;
216
217 i3c_device_get_info(i3cdev, &devinfo);
218
219
220
221
222
223 if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) {
224 u16 manuf = I3C_PID_MANUF_ID(devinfo.pid);
225 u16 part = I3C_PID_PART_ID(devinfo.pid);
226 u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
227
228
229 for (id = id_table; id->match_flags != 0; id++) {
230 if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) !=
231 I3C_MATCH_MANUF_AND_PART)
232 continue;
233
234 if (manuf != id->manuf_id || part != id->part_id)
235 continue;
236
237 if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
238 ext_info != id->extra_info)
239 continue;
240
241 return id;
242 }
243 }
244
245
246 for (id = id_table; id->match_flags != 0; id++) {
247 if ((id->match_flags & I3C_MATCH_DCR) &&
248 id->dcr == devinfo.dcr)
249 return id;
250 }
251
252 return NULL;
253 }
254 EXPORT_SYMBOL_GPL(i3c_device_match_id);
255
256
257
258
259
260
261
262
263
264
265
266 int i3c_driver_register_with_owner(struct i3c_driver *drv, struct module *owner)
267 {
268 drv->driver.owner = owner;
269 drv->driver.bus = &i3c_bus_type;
270
271 return driver_register(&drv->driver);
272 }
273 EXPORT_SYMBOL_GPL(i3c_driver_register_with_owner);
274
275
276
277
278
279
280
281
282 void i3c_driver_unregister(struct i3c_driver *drv)
283 {
284 driver_unregister(&drv->driver);
285 }
286 EXPORT_SYMBOL_GPL(i3c_driver_unregister);