Lines Matching +full:imx +full:- +full:scu
1 // SPDX-License-Identifier: GPL-2.0+
6 * Implementation of the SCU IPC functions using MUs (client side).
11 #include <linux/firmware/imx/ipc.h>
12 #include <linux/firmware/imx/sci.h>
36 /* SCU uses 4 Tx and 4 Rx channels */
43 /* temporarily store the SCU msg */
70 -EINVAL, /* IMX_SC_ERR_VERSION */
71 -EINVAL, /* IMX_SC_ERR_CONFIG */
72 -EINVAL, /* IMX_SC_ERR_PARM */
73 -EACCES, /* IMX_SC_ERR_NOACCESS */
74 -EACCES, /* IMX_SC_ERR_LOCKED */
75 -ERANGE, /* IMX_SC_ERR_UNAVAILABLE */
76 -EEXIST, /* IMX_SC_ERR_NOTFOUND */
77 -EPERM, /* IMX_SC_ERR_NOPOWER */
78 -EPIPE, /* IMX_SC_ERR_IPC */
79 -EBUSY, /* IMX_SC_ERR_BUSY */
80 -EIO, /* IMX_SC_ERR_FAIL */
89 return -EIO;
93 * Get the default handle used by SCU
98 return -EPROBE_DEFER;
105 /* Callback called when the word of a message is ack-ed, eg read by SCU */
110 complete(&sc_chan->tx_done);
116 struct imx_sc_ipc *sc_ipc = sc_chan->sc_ipc;
121 if (!sc_ipc->msg) {
122 dev_warn(sc_ipc->dev, "unexpected rx idx %d 0x%08x, ignore!\n",
123 sc_chan->idx, *data);
127 if (sc_ipc->fast_ipc) {
129 sc_ipc->rx_size = hdr->size;
130 sc_ipc->msg[0] = *data++;
132 for (i = 1; i < sc_ipc->rx_size; i++)
133 sc_ipc->msg[i] = *data++;
135 complete(&sc_ipc->done);
140 if (sc_chan->idx == 0) {
142 sc_ipc->rx_size = hdr->size;
143 dev_dbg(sc_ipc->dev, "msg rx size %u\n", sc_ipc->rx_size);
144 if (sc_ipc->rx_size > 4)
145 dev_warn(sc_ipc->dev, "RPC does not support receiving over 4 words: %u\n",
146 sc_ipc->rx_size);
149 sc_ipc->msg[sc_chan->idx] = *data;
150 sc_ipc->count++;
152 dev_dbg(sc_ipc->dev, "mu %u msg %u 0x%x\n", sc_chan->idx,
153 sc_ipc->count, *data);
155 if ((sc_ipc->rx_size != 0) && (sc_ipc->count == sc_ipc->rx_size))
156 complete(&sc_ipc->done);
170 return -EINVAL;
172 dev_dbg(sc_ipc->dev, "RPC SVC %u FUNC %u SIZE %u\n", hdr.svc,
175 size = sc_ipc->fast_ipc ? 1 : hdr.size;
177 sc_chan = &sc_ipc->chans[i % 4];
180 * SCU requires that all messages words are written
183 * different channels must be ensured by SCU API interface.
188 if (!sc_ipc->fast_ipc) {
189 wait_for_completion(&sc_chan->tx_done);
190 reinit_completion(&sc_chan->tx_done);
193 ret = mbox_send_message(sc_chan->ch, &data[i]);
211 return -EINVAL;
213 mutex_lock(&sc_ipc->lock);
214 reinit_completion(&sc_ipc->done);
217 sc_ipc->msg = msg;
218 saved_svc = ((struct imx_sc_rpc_msg *)msg)->svc;
219 saved_func = ((struct imx_sc_rpc_msg *)msg)->func;
221 sc_ipc->count = 0;
224 dev_err(sc_ipc->dev, "RPC send msg failed: %d\n", ret);
229 if (!wait_for_completion_timeout(&sc_ipc->done,
231 dev_err(sc_ipc->dev, "RPC send msg timeout\n");
232 mutex_unlock(&sc_ipc->lock);
233 return -ETIMEDOUT;
236 /* response status is stored in hdr->func field */
238 ret = hdr->func;
240 * Some special SCU firmware APIs do NOT have return value
241 * in hdr->func, but they do have response data, those special
242 * APIs are defined as void function in SCU firmware, so they
252 sc_ipc->msg = NULL;
253 mutex_unlock(&sc_ipc->lock);
255 dev_dbg(sc_ipc->dev, "RPC SVC done\n");
263 struct device *dev = &pdev->dev;
275 return -ENOMEM;
277 ret = of_parse_phandle_with_args(pdev->dev.of_node, "mboxes",
278 "#mbox-cells", 0, &args);
282 sc_ipc->fast_ipc = of_device_is_compatible(args.np, "fsl,imx8-mu-scu");
285 num_channel = sc_ipc->fast_ipc ? 2 : SCU_MU_CHAN_NUM;
291 i - num_channel / 2);
294 return -ENOMEM;
296 sc_chan = &sc_ipc->chans[i];
297 cl = &sc_chan->cl;
298 cl->dev = dev;
299 cl->tx_block = false;
300 cl->knows_txdone = true;
301 cl->rx_callback = imx_scu_rx_callback;
303 if (!sc_ipc->fast_ipc) {
305 cl->tx_done = imx_scu_tx_done;
306 init_completion(&sc_chan->tx_done);
307 complete(&sc_chan->tx_done);
310 sc_chan->sc_ipc = sc_ipc;
311 sc_chan->idx = i % (num_channel / 2);
312 sc_chan->ch = mbox_request_channel_byname(cl, chan_name);
313 if (IS_ERR(sc_chan->ch)) {
314 ret = PTR_ERR(sc_chan->ch);
326 sc_ipc->dev = dev;
327 mutex_init(&sc_ipc->lock);
328 init_completion(&sc_ipc->done);
341 dev_info(dev, "NXP i.MX SCU Initialized\n");
347 { .compatible = "fsl,imx-scu", },
353 .name = "imx-scu",
366 MODULE_DESCRIPTION("IMX SCU firmware protocol driver");