Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mailbox: imx: add SCU MU support

i.MX8/8X SCU MU is dedicated for communication between SCU and Cortex-A
cores from hardware design, and could not be reused for other purpose.

Per i.MX8/8X Reference mannual, Chapter "12.9.2.3.2 Messaging Examples",
Passing short messages: Transmit register(s) can be used to pass
short messages from one to four words in length. For example, when
a four-word message is desired, only one of the registers needs to
have its corresponding interrupt enable bit set at the receiver side;
the message’s first three words are written to the registers whose
interrupt is masked, and the fourth word is written to the other
register (which triggers an interrupt at the receiver side).

i.MX8/8X SCU firmware IPC is an implementation of passing short
messages. But current imx-mailbox driver only support one word
message, i.MX8/8X linux side firmware has to request four TX
and four RX to support IPC to SCU firmware. This is low efficent
and more interrupts triggered compared with one TX and
one RX.

To make SCU MU work,
- parse the size of msg.
- Only enable TR0/RR0 interrupt for transmit/receive message.
- For TX/RX, only support one TX channel and one RX channel
- For RX, support receive msg larger than 4 u32 words.
- Support 6 channels, TX0/RX0/RXDB[0-3], not support TXDB.

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>

authored by

Peng Fan and committed by
Jassi Brar
0a67003b 63b38357

+155
+155
drivers/mailbox/imx-mailbox.c
··· 4 4 */ 5 5 6 6 #include <linux/clk.h> 7 + #include <linux/firmware/imx/ipc.h> 7 8 #include <linux/interrupt.h> 8 9 #include <linux/io.h> 10 + #include <linux/iopoll.h> 9 11 #include <linux/kernel.h> 10 12 #include <linux/mailbox_controller.h> 11 13 #include <linux/module.h> ··· 29 27 #define IMX_MU_xCR_GIRn(x) BIT(16 + (3 - (x))) 30 28 31 29 #define IMX_MU_CHANS 16 30 + /* TX0/RX0/RXDB[0-3] */ 31 + #define IMX_MU_SCU_CHANS 6 32 32 #define IMX_MU_CHAN_NAME_SIZE 20 33 33 34 34 enum imx_mu_chan_type { ··· 38 34 IMX_MU_TYPE_RX, /* Rx */ 39 35 IMX_MU_TYPE_TXDB, /* Tx doorbell */ 40 36 IMX_MU_TYPE_RXDB, /* Rx doorbell */ 37 + }; 38 + 39 + struct imx_sc_rpc_msg_max { 40 + struct imx_sc_rpc_msg hdr; 41 + u32 data[7]; 41 42 }; 42 43 43 44 struct imx_mu_con_priv { ··· 139 130 140 131 dat = imx_mu_read(priv, priv->dcfg->xRR[cp->idx]); 141 132 mbox_chan_received_data(cp->chan, (void *)&dat); 133 + 134 + return 0; 135 + } 136 + 137 + static int imx_mu_scu_tx(struct imx_mu_priv *priv, 138 + struct imx_mu_con_priv *cp, 139 + void *data) 140 + { 141 + struct imx_sc_rpc_msg_max *msg = data; 142 + u32 *arg = data; 143 + int i, ret; 144 + u32 xsr; 145 + 146 + switch (cp->type) { 147 + case IMX_MU_TYPE_TX: 148 + if (msg->hdr.size > sizeof(*msg)) { 149 + /* 150 + * The real message size can be different to 151 + * struct imx_sc_rpc_msg_max size 152 + */ 153 + dev_err(priv->dev, "Exceed max msg size (%zu) on TX, got: %i\n", sizeof(*msg), msg->hdr.size); 154 + return -EINVAL; 155 + } 156 + 157 + for (i = 0; i < 4 && i < msg->hdr.size; i++) 158 + imx_mu_write(priv, *arg++, priv->dcfg->xTR[i % 4]); 159 + for (; i < msg->hdr.size; i++) { 160 + ret = readl_poll_timeout(priv->base + priv->dcfg->xSR, 161 + xsr, 162 + xsr & IMX_MU_xSR_TEn(i % 4), 163 + 0, 100); 164 + if (ret) { 165 + dev_err(priv->dev, "Send data index: %d timeout\n", i); 166 + return ret; 167 + } 168 + imx_mu_write(priv, *arg++, priv->dcfg->xTR[i % 4]); 169 + } 170 + 171 + imx_mu_xcr_rmw(priv, IMX_MU_xCR_TIEn(cp->idx), 0); 172 + break; 173 + default: 174 + dev_warn_ratelimited(priv->dev, "Send data on wrong channel type: %d\n", cp->type); 175 + return -EINVAL; 176 + } 177 + 178 + return 0; 179 + } 180 + 181 + static int imx_mu_scu_rx(struct imx_mu_priv *priv, 182 + struct imx_mu_con_priv *cp) 183 + { 184 + struct imx_sc_rpc_msg_max msg; 185 + u32 *data = (u32 *)&msg; 186 + int i, ret; 187 + u32 xsr; 188 + 189 + imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_RIEn(0)); 190 + *data++ = imx_mu_read(priv, priv->dcfg->xRR[0]); 191 + 192 + if (msg.hdr.size > sizeof(msg)) { 193 + dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n", 194 + sizeof(msg), msg.hdr.size); 195 + return -EINVAL; 196 + } 197 + 198 + for (i = 1; i < msg.hdr.size; i++) { 199 + ret = readl_poll_timeout(priv->base + priv->dcfg->xSR, xsr, 200 + xsr & IMX_MU_xSR_RFn(i % 4), 0, 100); 201 + if (ret) { 202 + dev_err(priv->dev, "timeout read idx %d\n", i); 203 + return ret; 204 + } 205 + *data++ = imx_mu_read(priv, priv->dcfg->xRR[i % 4]); 206 + } 207 + 208 + imx_mu_xcr_rmw(priv, IMX_MU_xCR_RIEn(0), 0); 209 + mbox_chan_received_data(cp->chan, (void *)&msg); 142 210 143 211 return 0; 144 212 } ··· 349 263 .shutdown = imx_mu_shutdown, 350 264 }; 351 265 266 + static struct mbox_chan *imx_mu_scu_xlate(struct mbox_controller *mbox, 267 + const struct of_phandle_args *sp) 268 + { 269 + u32 type, idx, chan; 270 + 271 + if (sp->args_count != 2) { 272 + dev_err(mbox->dev, "Invalid argument count %d\n", sp->args_count); 273 + return ERR_PTR(-EINVAL); 274 + } 275 + 276 + type = sp->args[0]; /* channel type */ 277 + idx = sp->args[1]; /* index */ 278 + 279 + switch (type) { 280 + case IMX_MU_TYPE_TX: 281 + case IMX_MU_TYPE_RX: 282 + if (idx != 0) 283 + dev_err(mbox->dev, "Invalid chan idx: %d\n", idx); 284 + chan = type; 285 + break; 286 + case IMX_MU_TYPE_RXDB: 287 + chan = 2 + idx; 288 + break; 289 + default: 290 + dev_err(mbox->dev, "Invalid chan type: %d\n", type); 291 + return NULL; 292 + } 293 + 294 + if (chan >= mbox->num_chans) { 295 + dev_err(mbox->dev, "Not supported channel number: %d. (type: %d, idx: %d)\n", chan, type, idx); 296 + return ERR_PTR(-EINVAL); 297 + } 298 + 299 + return &mbox->chans[chan]; 300 + } 301 + 352 302 static struct mbox_chan * imx_mu_xlate(struct mbox_controller *mbox, 353 303 const struct of_phandle_args *sp) 354 304 { ··· 427 305 428 306 if (priv->side_b) 429 307 return; 308 + 309 + /* Set default MU configuration */ 310 + imx_mu_write(priv, 0, priv->dcfg->xCR); 311 + } 312 + 313 + static void imx_mu_init_scu(struct imx_mu_priv *priv) 314 + { 315 + unsigned int i; 316 + 317 + for (i = 0; i < IMX_MU_SCU_CHANS; i++) { 318 + struct imx_mu_con_priv *cp = &priv->con_priv[i]; 319 + 320 + cp->idx = i < 2 ? 0 : i - 2; 321 + cp->type = i < 2 ? i : IMX_MU_TYPE_RXDB; 322 + cp->chan = &priv->mbox_chans[i]; 323 + priv->mbox_chans[i].con_priv = cp; 324 + snprintf(cp->irq_desc, sizeof(cp->irq_desc), 325 + "imx_mu_chan[%i-%i]", cp->type, cp->idx); 326 + } 327 + 328 + priv->mbox.num_chans = IMX_MU_SCU_CHANS; 329 + priv->mbox.of_xlate = imx_mu_scu_xlate; 430 330 431 331 /* Set default MU configuration */ 432 332 imx_mu_write(priv, 0, priv->dcfg->xCR); ··· 540 396 .xCR = 0x64, 541 397 }; 542 398 399 + static const struct imx_mu_dcfg imx_mu_cfg_imx8_scu = { 400 + .tx = imx_mu_scu_tx, 401 + .rx = imx_mu_scu_rx, 402 + .init = imx_mu_init_scu, 403 + .xTR = {0x0, 0x4, 0x8, 0xc}, 404 + .xRR = {0x10, 0x14, 0x18, 0x1c}, 405 + .xSR = 0x20, 406 + .xCR = 0x24, 407 + }; 408 + 543 409 static const struct of_device_id imx_mu_dt_ids[] = { 544 410 { .compatible = "fsl,imx7ulp-mu", .data = &imx_mu_cfg_imx7ulp }, 545 411 { .compatible = "fsl,imx6sx-mu", .data = &imx_mu_cfg_imx6sx }, 412 + { .compatible = "fsl,imx8-mu-scu", .data = &imx_mu_cfg_imx8_scu }, 546 413 { }, 547 414 }; 548 415 MODULE_DEVICE_TABLE(of, imx_mu_dt_ids);