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