This source file includes following definitions.
- hsi_register_board_info
- hsi_client_set_drvdata
- hsi_client_drvdata
- hsi_unregister_client_driver
- hsi_port_claimed
- hsi_port_set_drvdata
- hsi_port_drvdata
- hsi_add_clients_from_dt
- hsi_controller_set_drvdata
- hsi_controller_drvdata
- hsi_find_port_num
- hsi_id
- hsi_port_id
- hsi_setup
- hsi_flush
- hsi_async_read
- hsi_async_write
- hsi_start_tx
- hsi_stop_tx
1
2
3
4
5
6
7
8
9
10 #ifndef __LINUX_HSI_H__
11 #define __LINUX_HSI_H__
12
13 #include <linux/device.h>
14 #include <linux/mutex.h>
15 #include <linux/scatterlist.h>
16 #include <linux/list.h>
17 #include <linux/module.h>
18 #include <linux/notifier.h>
19
20
21 #define HSI_MSG_READ 0
22 #define HSI_MSG_WRITE 1
23
24
25 enum {
26 HSI_MODE_STREAM = 1,
27 HSI_MODE_FRAME,
28 };
29
30 enum {
31 HSI_FLOW_SYNC,
32 HSI_FLOW_PIPE,
33 };
34
35 enum {
36 HSI_ARB_RR,
37 HSI_ARB_PRIO,
38 };
39
40 #define HSI_MAX_CHANNELS 16
41
42
43 enum {
44 HSI_STATUS_COMPLETED,
45 HSI_STATUS_PENDING,
46 HSI_STATUS_PROCEEDING,
47 HSI_STATUS_QUEUED,
48 HSI_STATUS_ERROR,
49 };
50
51
52 enum {
53 HSI_EVENT_START_RX,
54 HSI_EVENT_STOP_RX,
55 };
56
57
58
59
60
61
62 struct hsi_channel {
63 unsigned int id;
64 const char *name;
65 };
66
67
68
69
70
71
72
73
74
75
76
77 struct hsi_config {
78 unsigned int mode;
79 struct hsi_channel *channels;
80 unsigned int num_channels;
81 unsigned int num_hw_channels;
82 unsigned int speed;
83 union {
84 unsigned int flow;
85 unsigned int arb_mode;
86 };
87 };
88
89
90
91
92
93
94
95
96
97
98
99 struct hsi_board_info {
100 const char *name;
101 unsigned int hsi_id;
102 unsigned int port;
103 struct hsi_config tx_cfg;
104 struct hsi_config rx_cfg;
105 void *platform_data;
106 struct dev_archdata *archdata;
107 };
108
109 #ifdef CONFIG_HSI_BOARDINFO
110 extern int hsi_register_board_info(struct hsi_board_info const *info,
111 unsigned int len);
112 #else
113 static inline int hsi_register_board_info(struct hsi_board_info const *info,
114 unsigned int len)
115 {
116 return 0;
117 }
118 #endif
119
120
121
122
123
124
125
126 struct hsi_client {
127 struct device device;
128 struct hsi_config tx_cfg;
129 struct hsi_config rx_cfg;
130
131 void (*ehandler)(struct hsi_client *, unsigned long);
132 unsigned int pclaimed:1;
133 struct notifier_block nb;
134 };
135
136 #define to_hsi_client(dev) container_of(dev, struct hsi_client, device)
137
138 static inline void hsi_client_set_drvdata(struct hsi_client *cl, void *data)
139 {
140 dev_set_drvdata(&cl->device, data);
141 }
142
143 static inline void *hsi_client_drvdata(struct hsi_client *cl)
144 {
145 return dev_get_drvdata(&cl->device);
146 }
147
148 int hsi_register_port_event(struct hsi_client *cl,
149 void (*handler)(struct hsi_client *, unsigned long));
150 int hsi_unregister_port_event(struct hsi_client *cl);
151
152
153
154
155
156 struct hsi_client_driver {
157 struct device_driver driver;
158 };
159
160 #define to_hsi_client_driver(drv) container_of(drv, struct hsi_client_driver,\
161 driver)
162
163 int hsi_register_client_driver(struct hsi_client_driver *drv);
164
165 static inline void hsi_unregister_client_driver(struct hsi_client_driver *drv)
166 {
167 driver_unregister(&drv->driver);
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 struct hsi_msg {
186 struct list_head link;
187 struct hsi_client *cl;
188 struct sg_table sgt;
189 void *context;
190
191 void (*complete)(struct hsi_msg *msg);
192 void (*destructor)(struct hsi_msg *msg);
193
194 int status;
195 unsigned int actual_len;
196 unsigned int channel;
197 unsigned int ttype:1;
198 unsigned int break_frame:1;
199 };
200
201 struct hsi_msg *hsi_alloc_msg(unsigned int n_frag, gfp_t flags);
202 void hsi_free_msg(struct hsi_msg *msg);
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 struct hsi_port {
222 struct device device;
223 struct hsi_config tx_cfg;
224 struct hsi_config rx_cfg;
225 unsigned int num;
226 unsigned int shared:1;
227 int claimed;
228 struct mutex lock;
229 int (*async)(struct hsi_msg *msg);
230 int (*setup)(struct hsi_client *cl);
231 int (*flush)(struct hsi_client *cl);
232 int (*start_tx)(struct hsi_client *cl);
233 int (*stop_tx)(struct hsi_client *cl);
234 int (*release)(struct hsi_client *cl);
235
236 struct blocking_notifier_head n_head;
237 };
238
239 #define to_hsi_port(dev) container_of(dev, struct hsi_port, device)
240 #define hsi_get_port(cl) to_hsi_port((cl)->device.parent)
241
242 int hsi_event(struct hsi_port *port, unsigned long event);
243 int hsi_claim_port(struct hsi_client *cl, unsigned int share);
244 void hsi_release_port(struct hsi_client *cl);
245
246 static inline int hsi_port_claimed(struct hsi_client *cl)
247 {
248 return cl->pclaimed;
249 }
250
251 static inline void hsi_port_set_drvdata(struct hsi_port *port, void *data)
252 {
253 dev_set_drvdata(&port->device, data);
254 }
255
256 static inline void *hsi_port_drvdata(struct hsi_port *port)
257 {
258 return dev_get_drvdata(&port->device);
259 }
260
261
262
263
264
265
266
267
268
269 struct hsi_controller {
270 struct device device;
271 struct module *owner;
272 unsigned int id;
273 unsigned int num_ports;
274 struct hsi_port **port;
275 };
276
277 #define to_hsi_controller(dev) container_of(dev, struct hsi_controller, device)
278
279 struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags);
280 void hsi_put_controller(struct hsi_controller *hsi);
281 int hsi_register_controller(struct hsi_controller *hsi);
282 void hsi_unregister_controller(struct hsi_controller *hsi);
283 struct hsi_client *hsi_new_client(struct hsi_port *port,
284 struct hsi_board_info *info);
285 int hsi_remove_client(struct device *dev, void *data);
286 void hsi_port_unregister_clients(struct hsi_port *port);
287
288 #ifdef CONFIG_OF
289 void hsi_add_clients_from_dt(struct hsi_port *port,
290 struct device_node *clients);
291 #else
292 static inline void hsi_add_clients_from_dt(struct hsi_port *port,
293 struct device_node *clients)
294 {
295 return;
296 }
297 #endif
298
299 static inline void hsi_controller_set_drvdata(struct hsi_controller *hsi,
300 void *data)
301 {
302 dev_set_drvdata(&hsi->device, data);
303 }
304
305 static inline void *hsi_controller_drvdata(struct hsi_controller *hsi)
306 {
307 return dev_get_drvdata(&hsi->device);
308 }
309
310 static inline struct hsi_port *hsi_find_port_num(struct hsi_controller *hsi,
311 unsigned int num)
312 {
313 return (num < hsi->num_ports) ? hsi->port[num] : NULL;
314 }
315
316
317
318
319 int hsi_async(struct hsi_client *cl, struct hsi_msg *msg);
320
321 int hsi_get_channel_id_by_name(struct hsi_client *cl, char *name);
322
323
324
325
326
327
328
329 static inline unsigned int hsi_id(struct hsi_client *cl)
330 {
331 return to_hsi_controller(cl->device.parent->parent)->id;
332 }
333
334
335
336
337
338
339
340 static inline unsigned int hsi_port_id(struct hsi_client *cl)
341 {
342 return to_hsi_port(cl->device.parent)->num;
343 }
344
345
346
347
348
349
350
351
352
353
354 static inline int hsi_setup(struct hsi_client *cl)
355 {
356 if (!hsi_port_claimed(cl))
357 return -EACCES;
358 return hsi_get_port(cl)->setup(cl);
359 }
360
361
362
363
364
365
366
367
368
369
370 static inline int hsi_flush(struct hsi_client *cl)
371 {
372 if (!hsi_port_claimed(cl))
373 return -EACCES;
374 return hsi_get_port(cl)->flush(cl);
375 }
376
377
378
379
380
381
382
383
384 static inline int hsi_async_read(struct hsi_client *cl, struct hsi_msg *msg)
385 {
386 msg->ttype = HSI_MSG_READ;
387 return hsi_async(cl, msg);
388 }
389
390
391
392
393
394
395
396
397 static inline int hsi_async_write(struct hsi_client *cl, struct hsi_msg *msg)
398 {
399 msg->ttype = HSI_MSG_WRITE;
400 return hsi_async(cl, msg);
401 }
402
403
404
405
406
407
408
409 static inline int hsi_start_tx(struct hsi_client *cl)
410 {
411 if (!hsi_port_claimed(cl))
412 return -EACCES;
413 return hsi_get_port(cl)->start_tx(cl);
414 }
415
416
417
418
419
420
421
422 static inline int hsi_stop_tx(struct hsi_client *cl)
423 {
424 if (!hsi_port_claimed(cl))
425 return -EACCES;
426 return hsi_get_port(cl)->stop_tx(cl);
427 }
428 #endif