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

mailbox: imx: restructure code to make easy for new MU

Add imx_mu_generic_tx for data send and imx_mu_generic_rx for interrupt
data receive.

Pack original mu chans related code into imx_mu_init_generic

Add tx/rx/init hooks into imx_mu_dcfg

With these, it will be a bit easy to introduce i.MX8/8X SCU type
MU dedicated to communicate with SCU.

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
63b38357 eabb8b8c

+83 -54
+83 -54
drivers/mailbox/imx-mailbox.c
··· 36 36 IMX_MU_TYPE_RXDB, /* Rx doorbell */ 37 37 }; 38 38 39 - struct imx_mu_dcfg { 40 - u32 xTR[4]; /* Transmit Registers */ 41 - u32 xRR[4]; /* Receive Registers */ 42 - u32 xSR; /* Status Register */ 43 - u32 xCR; /* Control Register */ 44 - }; 45 - 46 39 struct imx_mu_con_priv { 47 40 unsigned int idx; 48 41 char irq_desc[IMX_MU_CHAN_NAME_SIZE]; ··· 60 67 bool side_b; 61 68 }; 62 69 63 - static const struct imx_mu_dcfg imx_mu_cfg_imx6sx = { 64 - .xTR = {0x0, 0x4, 0x8, 0xc}, 65 - .xRR = {0x10, 0x14, 0x18, 0x1c}, 66 - .xSR = 0x20, 67 - .xCR = 0x24, 68 - }; 69 - 70 - static const struct imx_mu_dcfg imx_mu_cfg_imx7ulp = { 71 - .xTR = {0x20, 0x24, 0x28, 0x2c}, 72 - .xRR = {0x40, 0x44, 0x48, 0x4c}, 73 - .xSR = 0x60, 74 - .xCR = 0x64, 70 + struct imx_mu_dcfg { 71 + int (*tx)(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp, void *data); 72 + int (*rx)(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp); 73 + void (*init)(struct imx_mu_priv *priv); 74 + u32 xTR[4]; /* Transmit Registers */ 75 + u32 xRR[4]; /* Receive Registers */ 76 + u32 xSR; /* Status Register */ 77 + u32 xCR; /* Control Register */ 75 78 }; 76 79 77 80 static struct imx_mu_priv *to_imx_mu_priv(struct mbox_controller *mbox) ··· 100 111 return val; 101 112 } 102 113 114 + static int imx_mu_generic_tx(struct imx_mu_priv *priv, 115 + struct imx_mu_con_priv *cp, 116 + void *data) 117 + { 118 + u32 *arg = data; 119 + 120 + switch (cp->type) { 121 + case IMX_MU_TYPE_TX: 122 + imx_mu_write(priv, *arg, priv->dcfg->xTR[cp->idx]); 123 + imx_mu_xcr_rmw(priv, IMX_MU_xCR_TIEn(cp->idx), 0); 124 + break; 125 + case IMX_MU_TYPE_TXDB: 126 + imx_mu_xcr_rmw(priv, IMX_MU_xCR_GIRn(cp->idx), 0); 127 + tasklet_schedule(&cp->txdb_tasklet); 128 + break; 129 + default: 130 + dev_warn_ratelimited(priv->dev, "Send data on wrong channel type: %d\n", cp->type); 131 + return -EINVAL; 132 + } 133 + 134 + return 0; 135 + } 136 + 137 + static int imx_mu_generic_rx(struct imx_mu_priv *priv, 138 + struct imx_mu_con_priv *cp) 139 + { 140 + u32 dat; 141 + 142 + dat = imx_mu_read(priv, priv->dcfg->xRR[cp->idx]); 143 + mbox_chan_received_data(cp->chan, (void *)&dat); 144 + 145 + return 0; 146 + } 147 + 103 148 static void imx_mu_txdb_tasklet(unsigned long data) 104 149 { 105 150 struct imx_mu_con_priv *cp = (struct imx_mu_con_priv *)data; ··· 146 123 struct mbox_chan *chan = p; 147 124 struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); 148 125 struct imx_mu_con_priv *cp = chan->con_priv; 149 - u32 val, ctrl, dat; 126 + u32 val, ctrl; 150 127 151 128 ctrl = imx_mu_read(priv, priv->dcfg->xCR); 152 129 val = imx_mu_read(priv, priv->dcfg->xSR); ··· 175 152 imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_TIEn(cp->idx)); 176 153 mbox_chan_txdone(chan, 0); 177 154 } else if (val == IMX_MU_xSR_RFn(cp->idx)) { 178 - dat = imx_mu_read(priv, priv->dcfg->xRR[cp->idx]); 179 - mbox_chan_received_data(chan, (void *)&dat); 155 + priv->dcfg->rx(priv, cp); 180 156 } else if (val == IMX_MU_xSR_GIPn(cp->idx)) { 181 157 imx_mu_write(priv, IMX_MU_xSR_GIPn(cp->idx), priv->dcfg->xSR); 182 158 mbox_chan_received_data(chan, NULL); ··· 191 169 { 192 170 struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); 193 171 struct imx_mu_con_priv *cp = chan->con_priv; 194 - u32 *arg = data; 195 172 196 - switch (cp->type) { 197 - case IMX_MU_TYPE_TX: 198 - imx_mu_write(priv, *arg, priv->dcfg->xTR[cp->idx]); 199 - imx_mu_xcr_rmw(priv, IMX_MU_xCR_TIEn(cp->idx), 0); 200 - break; 201 - case IMX_MU_TYPE_TXDB: 202 - imx_mu_xcr_rmw(priv, IMX_MU_xCR_GIRn(cp->idx), 0); 203 - tasklet_schedule(&cp->txdb_tasklet); 204 - break; 205 - default: 206 - dev_warn_ratelimited(priv->dev, "Send data on wrong channel type: %d\n", cp->type); 207 - return -EINVAL; 208 - } 209 - 210 - return 0; 173 + return priv->dcfg->tx(priv, cp, data); 211 174 } 212 175 213 176 static int imx_mu_startup(struct mbox_chan *chan) ··· 287 280 288 281 static void imx_mu_init_generic(struct imx_mu_priv *priv) 289 282 { 283 + unsigned int i; 284 + 285 + for (i = 0; i < IMX_MU_CHANS; i++) { 286 + struct imx_mu_con_priv *cp = &priv->con_priv[i]; 287 + 288 + cp->idx = i % 4; 289 + cp->type = i >> 2; 290 + cp->chan = &priv->mbox_chans[i]; 291 + priv->mbox_chans[i].con_priv = cp; 292 + snprintf(cp->irq_desc, sizeof(cp->irq_desc), 293 + "imx_mu_chan[%i-%i]", cp->type, cp->idx); 294 + } 295 + 296 + priv->mbox.num_chans = IMX_MU_CHANS; 297 + priv->mbox.of_xlate = imx_mu_xlate; 298 + 290 299 if (priv->side_b) 291 300 return; 292 301 ··· 316 293 struct device_node *np = dev->of_node; 317 294 struct imx_mu_priv *priv; 318 295 const struct imx_mu_dcfg *dcfg; 319 - unsigned int i; 320 296 int ret; 321 297 322 298 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ··· 351 329 return ret; 352 330 } 353 331 354 - for (i = 0; i < IMX_MU_CHANS; i++) { 355 - struct imx_mu_con_priv *cp = &priv->con_priv[i]; 356 - 357 - cp->idx = i % 4; 358 - cp->type = i >> 2; 359 - cp->chan = &priv->mbox_chans[i]; 360 - priv->mbox_chans[i].con_priv = cp; 361 - snprintf(cp->irq_desc, sizeof(cp->irq_desc), 362 - "imx_mu_chan[%i-%i]", cp->type, cp->idx); 363 - } 364 - 365 332 priv->side_b = of_property_read_bool(np, "fsl,mu-side-b"); 333 + 334 + priv->dcfg->init(priv); 366 335 367 336 spin_lock_init(&priv->xcr_lock); 368 337 369 338 priv->mbox.dev = dev; 370 339 priv->mbox.ops = &imx_mu_ops; 371 340 priv->mbox.chans = priv->mbox_chans; 372 - priv->mbox.num_chans = IMX_MU_CHANS; 373 - priv->mbox.of_xlate = imx_mu_xlate; 374 341 priv->mbox.txdone_irq = true; 375 342 376 343 platform_set_drvdata(pdev, priv); 377 - 378 - imx_mu_init_generic(priv); 379 344 380 345 return devm_mbox_controller_register(dev, &priv->mbox); 381 346 } ··· 375 366 376 367 return 0; 377 368 } 369 + 370 + static const struct imx_mu_dcfg imx_mu_cfg_imx6sx = { 371 + .tx = imx_mu_generic_tx, 372 + .rx = imx_mu_generic_rx, 373 + .init = imx_mu_init_generic, 374 + .xTR = {0x0, 0x4, 0x8, 0xc}, 375 + .xRR = {0x10, 0x14, 0x18, 0x1c}, 376 + .xSR = 0x20, 377 + .xCR = 0x24, 378 + }; 379 + 380 + static const struct imx_mu_dcfg imx_mu_cfg_imx7ulp = { 381 + .tx = imx_mu_generic_tx, 382 + .rx = imx_mu_generic_rx, 383 + .init = imx_mu_init_generic, 384 + .xTR = {0x20, 0x24, 0x28, 0x2c}, 385 + .xRR = {0x40, 0x44, 0x48, 0x4c}, 386 + .xSR = 0x60, 387 + .xCR = 0x64, 388 + }; 378 389 379 390 static const struct of_device_id imx_mu_dt_ids[] = { 380 391 { .compatible = "fsl,imx7ulp-mu", .data = &imx_mu_cfg_imx7ulp },