1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2018 MediaTek Inc.
10 #include <linux/mailbox_client.h>
11 #include <linux/mailbox/mtk-cmdq-mailbox.h>
12 #include <linux/timer.h>
14 #define CMDQ_ADDR_HIGH(addr) ((u32)(((addr) >> 16) & GENMASK(31, 0)))
15 #define CMDQ_ADDR_LOW(addr) ((u16)(addr) | BIT(1))
19 struct cmdq_client_reg {
26 struct mbox_client client;
27 struct mbox_chan *chan;
31 * cmdq_dev_get_client_reg() - parse cmdq client reg from the device
33 * @dev: device of CMDQ mailbox client
34 * @client_reg: CMDQ client reg pointer
35 * @idx: the index of desired reg
37 * Return: 0 for success; else the error code is returned
39 * Help CMDQ client parsing the cmdq client reg
40 * from the device node of CMDQ client.
42 int cmdq_dev_get_client_reg(struct device *dev,
43 struct cmdq_client_reg *client_reg, int idx);
46 * cmdq_mbox_create() - create CMDQ mailbox client and channel
47 * @dev: device of CMDQ mailbox client
48 * @index: index of CMDQ mailbox channel
50 * Return: CMDQ mailbox client pointer
52 struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
55 * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
56 * @client: the CMDQ mailbox client
58 void cmdq_mbox_destroy(struct cmdq_client *client);
61 * cmdq_pkt_create() - create a CMDQ packet
62 * @client: the CMDQ mailbox client
63 * @size: required CMDQ buffer size
65 * Return: CMDQ packet pointer
67 struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
70 * cmdq_pkt_destroy() - destroy the CMDQ packet
71 * @pkt: the CMDQ packet
73 void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
76 * cmdq_pkt_write() - append write command to the CMDQ packet
77 * @pkt: the CMDQ packet
78 * @subsys: the CMDQ sub system code
79 * @offset: register offset from CMDQ sub system
80 * @value: the specified target register value
82 * Return: 0 for success; else the error code is returned
84 int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value);
87 * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet
88 * @pkt: the CMDQ packet
89 * @subsys: the CMDQ sub system code
90 * @offset: register offset from CMDQ sub system
91 * @value: the specified target register value
92 * @mask: the specified target register mask
94 * Return: 0 for success; else the error code is returned
96 int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
97 u16 offset, u32 value, u32 mask);
100 * cmdq_pkt_read_s() - append read_s command to the CMDQ packet
101 * @pkt: the CMDQ packet
102 * @high_addr_reg_idx: internal register ID which contains high address of pa
103 * @addr_low: low address of pa
104 * @reg_idx: the CMDQ internal register ID to cache read data
106 * Return: 0 for success; else the error code is returned
108 int cmdq_pkt_read_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx, u16 addr_low,
112 * cmdq_pkt_write_s() - append write_s command to the CMDQ packet
113 * @pkt: the CMDQ packet
114 * @high_addr_reg_idx: internal register ID which contains high address of pa
115 * @addr_low: low address of pa
116 * @src_reg_idx: the CMDQ internal register ID which cache source value
118 * Return: 0 for success; else the error code is returned
120 * Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
121 * to get high address and call cmdq_pkt_assign() to assign value into internal
122 * reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
123 * call to this function.
125 int cmdq_pkt_write_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
126 u16 addr_low, u16 src_reg_idx);
129 * cmdq_pkt_write_s_mask() - append write_s with mask command to the CMDQ packet
130 * @pkt: the CMDQ packet
131 * @high_addr_reg_idx: internal register ID which contains high address of pa
132 * @addr_low: low address of pa
133 * @src_reg_idx: the CMDQ internal register ID which cache source value
134 * @mask: the specified target address mask, use U32_MAX if no need
136 * Return: 0 for success; else the error code is returned
138 * Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
139 * to get high address and call cmdq_pkt_assign() to assign value into internal
140 * reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
141 * call to this function.
143 int cmdq_pkt_write_s_mask(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
144 u16 addr_low, u16 src_reg_idx, u32 mask);
147 * cmdq_pkt_write_s_value() - append write_s command to the CMDQ packet which
148 * write value to a physical address
149 * @pkt: the CMDQ packet
150 * @high_addr_reg_idx: internal register ID which contains high address of pa
151 * @addr_low: low address of pa
152 * @value: the specified target value
154 * Return: 0 for success; else the error code is returned
156 int cmdq_pkt_write_s_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
157 u16 addr_low, u32 value);
160 * cmdq_pkt_write_s_mask_value() - append write_s command with mask to the CMDQ
161 * packet which write value to a physical
163 * @pkt: the CMDQ packet
164 * @high_addr_reg_idx: internal register ID which contains high address of pa
165 * @addr_low: low address of pa
166 * @value: the specified target value
167 * @mask: the specified target mask
169 * Return: 0 for success; else the error code is returned
171 int cmdq_pkt_write_s_mask_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
172 u16 addr_low, u32 value, u32 mask);
175 * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet
176 * @pkt: the CMDQ packet
177 * @event: the desired event type to wait
178 * @clear: clear event or not after event arrive
180 * Return: 0 for success; else the error code is returned
182 int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear);
185 * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet
186 * @pkt: the CMDQ packet
187 * @event: the desired event to be cleared
189 * Return: 0 for success; else the error code is returned
191 int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
194 * cmdq_pkt_set_event() - append set event command to the CMDQ packet
195 * @pkt: the CMDQ packet
196 * @event: the desired event to be set
198 * Return: 0 for success; else the error code is returned
200 int cmdq_pkt_set_event(struct cmdq_pkt *pkt, u16 event);
203 * cmdq_pkt_poll() - Append polling command to the CMDQ packet, ask GCE to
204 * execute an instruction that wait for a specified
205 * hardware register to check for the value w/o mask.
206 * All GCE hardware threads will be blocked by this
208 * @pkt: the CMDQ packet
209 * @subsys: the CMDQ sub system code
210 * @offset: register offset from CMDQ sub system
211 * @value: the specified target register value
213 * Return: 0 for success; else the error code is returned
215 int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
216 u16 offset, u32 value);
219 * cmdq_pkt_poll_mask() - Append polling command to the CMDQ packet, ask GCE to
220 * execute an instruction that wait for a specified
221 * hardware register to check for the value w/ mask.
222 * All GCE hardware threads will be blocked by this
224 * @pkt: the CMDQ packet
225 * @subsys: the CMDQ sub system code
226 * @offset: register offset from CMDQ sub system
227 * @value: the specified target register value
228 * @mask: the specified target register mask
230 * Return: 0 for success; else the error code is returned
232 int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
233 u16 offset, u32 value, u32 mask);
236 * cmdq_pkt_assign() - Append logic assign command to the CMDQ packet, ask GCE
237 * to execute an instruction that set a constant value into
238 * internal register and use as value, mask or address in
239 * read/write instruction.
240 * @pkt: the CMDQ packet
241 * @reg_idx: the CMDQ internal register ID
242 * @value: the specified value
244 * Return: 0 for success; else the error code is returned
246 int cmdq_pkt_assign(struct cmdq_pkt *pkt, u16 reg_idx, u32 value);
249 * cmdq_pkt_jump() - Append jump command to the CMDQ packet, ask GCE
250 * to execute an instruction that change current thread PC to
251 * a physical address which should contains more instruction.
252 * @pkt: the CMDQ packet
253 * @addr: physical address of target instruction buffer
255 * Return: 0 for success; else the error code is returned
257 int cmdq_pkt_jump(struct cmdq_pkt *pkt, dma_addr_t addr);
260 * cmdq_pkt_finalize() - Append EOC and jump command to pkt.
261 * @pkt: the CMDQ packet
263 * Return: 0 for success; else the error code is returned
265 int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
268 * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
269 * packet and call back at the end of done packet
270 * @pkt: the CMDQ packet
271 * @cb: called at the end of done packet
272 * @data: this data will pass back to cb
274 * Return: 0 for success; else the error code is returned
276 * Trigger CMDQ to asynchronously execute the CMDQ packet and call back
277 * at the end of done packet. Note that this is an ASYNC function. When the
278 * function returned, it may or may not be finished.
280 int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
283 #endif /* __MTK_CMDQ_H__ */