]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/soc/qcom/smd.h
1df0341a4fd3e93562a88199f45f22a87376689a
[karo-tx-linux.git] / include / linux / soc / qcom / smd.h
1 #ifndef __QCOM_SMD_H__
2 #define __QCOM_SMD_H__
3
4 #include <linux/device.h>
5 #include <linux/mod_devicetable.h>
6
7 struct qcom_smd;
8 struct qcom_smd_lookup;
9 struct qcom_smd_device;
10
11 /*
12  * SMD channel states.
13  */
14 enum smd_channel_state {
15         SMD_CHANNEL_CLOSED,
16         SMD_CHANNEL_OPENING,
17         SMD_CHANNEL_OPENED,
18         SMD_CHANNEL_FLUSHING,
19         SMD_CHANNEL_CLOSING,
20         SMD_CHANNEL_RESET,
21         SMD_CHANNEL_RESET_OPENING
22 };
23
24 /**
25  * struct qcom_smd_channel - smd channel struct
26  * @edge:               qcom_smd_edge this channel is living on
27  * @qsdev:              reference to a associated smd client device
28  * @name:               name of the channel
29  * @state:              local state of the channel
30  * @remote_state:       remote state of the channel
31  * @info:               byte aligned outgoing/incoming channel info
32  * @info_word:          word aligned outgoing/incoming channel info
33  * @tx_lock:            lock to make writes to the channel mutually exclusive
34  * @fblockread_event:   wakeup event tied to tx fBLOCKREADINTR
35  * @tx_fifo:            pointer to the outgoing ring buffer
36  * @rx_fifo:            pointer to the incoming ring buffer
37  * @fifo_size:          size of each ring buffer
38  * @bounce_buffer:      bounce buffer for reading wrapped packets
39  * @cb:                 callback function registered for this channel
40  * @recv_lock:          guard for rx info modifications and cb pointer
41  * @pkt_size:           size of the currently handled packet
42  * @list:               lite entry for @channels in qcom_smd_edge
43  */
44
45 struct qcom_smd_channel {
46         struct qcom_smd_edge *edge;
47
48         struct qcom_smd_device *qsdev;
49
50         char *name;
51         enum smd_channel_state state;
52         enum smd_channel_state remote_state;
53
54         struct smd_channel_info_pair *info;
55         struct smd_channel_info_word_pair *info_word;
56
57         struct mutex tx_lock;
58         wait_queue_head_t fblockread_event;
59
60         void *tx_fifo;
61         void *rx_fifo;
62         int fifo_size;
63
64         void *bounce_buffer;
65         qcom_smd_cb_t cb;
66
67         spinlock_t recv_lock;
68
69         int pkt_size;
70
71         struct list_head list;
72         struct list_head dev_list;
73 };
74
75 /**
76  * struct qcom_smd_id - struct used for matching a smd device
77  * @name:       name of the channel
78  */
79 struct qcom_smd_id {
80         char name[20];
81 };
82
83 /**
84  * struct qcom_smd_device - smd device struct
85  * @dev:        the device struct
86  * @channel:    handle to the smd channel for this device
87  */
88 struct qcom_smd_device {
89         struct device dev;
90         struct qcom_smd_channel *channel;
91 };
92
93 typedef int (*qcom_smd_cb_t)(struct qcom_smd_channel *, const void *, size_t);
94
95 /**
96  * struct qcom_smd_driver - smd driver struct
97  * @driver:     underlying device driver
98  * @smd_match_table: static channel match table
99  * @probe:      invoked when the smd channel is found
100  * @remove:     invoked when the smd channel is closed
101  * @callback:   invoked when an inbound message is received on the channel,
102  *              should return 0 on success or -EBUSY if the data cannot be
103  *              consumed at this time
104  */
105 struct qcom_smd_driver {
106         struct device_driver driver;
107         const struct qcom_smd_id *smd_match_table;
108
109         int (*probe)(struct qcom_smd_device *dev);
110         void (*remove)(struct qcom_smd_device *dev);
111         qcom_smd_cb_t callback;
112 };
113
114 int qcom_smd_driver_register(struct qcom_smd_driver *drv);
115 void qcom_smd_driver_unregister(struct qcom_smd_driver *drv);
116
117 void *qcom_smd_get_drvdata(struct qcom_smd_channel *channel);
118 void qcom_smd_set_drvdata(struct qcom_smd_channel *channel, void *data);
119
120 #define module_qcom_smd_driver(__smd_driver) \
121         module_driver(__smd_driver, qcom_smd_driver_register, \
122                       qcom_smd_driver_unregister)
123
124 int qcom_smd_send(struct qcom_smd_channel *channel, const void *data, int len);
125
126 struct qcom_smd_channel *qcom_smd_open_channel(struct qcom_smd_channel *channel,
127                                                const char *name,
128                                                qcom_smd_cb_t cb);
129
130 #endif