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