drivers/mailbox/mtk-adsp-mailbox.c

Source file repositories/reference/linux-study-clean/drivers/mailbox/mtk-adsp-mailbox.c

File Facts

System
Linux kernel
Corpus path
drivers/mailbox/mtk-adsp-mailbox.c
Extension
.c
Size
4703 bytes
Lines
186
Domain
Driver Families
Bucket
drivers/mailbox
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mtk_adsp_mbox_priv {
	struct device *dev;
	struct mbox_controller mbox;
	void __iomem *va_mboxreg;
	const struct mtk_adsp_mbox_cfg *cfg;
};

struct mtk_adsp_mbox_cfg {
	u32 set_in;
	u32 set_out;
	u32 clr_in;
	u32 clr_out;
};

static inline struct mtk_adsp_mbox_priv *get_mtk_adsp_mbox_priv(struct mbox_controller *mbox)
{
	return container_of(mbox, struct mtk_adsp_mbox_priv, mbox);
}

static irqreturn_t mtk_adsp_mbox_irq(int irq, void *data)
{
	struct mbox_chan *chan = data;
	struct mtk_adsp_mbox_priv *priv = get_mtk_adsp_mbox_priv(chan->mbox);
	u32 op = readl(priv->va_mboxreg + priv->cfg->set_out);

	writel(op, priv->va_mboxreg + priv->cfg->clr_out);

	return IRQ_WAKE_THREAD;
}

static irqreturn_t mtk_adsp_mbox_isr(int irq, void *data)
{
	struct mbox_chan *chan = data;

	mbox_chan_received_data(chan, NULL);

	return IRQ_HANDLED;
}

static struct mbox_chan *mtk_adsp_mbox_xlate(struct mbox_controller *mbox,
					     const struct of_phandle_args *sp)
{
	return mbox->chans;
}

static int mtk_adsp_mbox_startup(struct mbox_chan *chan)
{
	struct mtk_adsp_mbox_priv *priv = get_mtk_adsp_mbox_priv(chan->mbox);

	/* Clear ADSP mbox command */
	writel(0xFFFFFFFF, priv->va_mboxreg + priv->cfg->clr_in);
	writel(0xFFFFFFFF, priv->va_mboxreg + priv->cfg->clr_out);

	return 0;
}

static void mtk_adsp_mbox_shutdown(struct mbox_chan *chan)
{
	struct mtk_adsp_mbox_priv *priv = get_mtk_adsp_mbox_priv(chan->mbox);

	/* Clear ADSP mbox command */
	writel(0xFFFFFFFF, priv->va_mboxreg + priv->cfg->clr_in);
	writel(0xFFFFFFFF, priv->va_mboxreg + priv->cfg->clr_out);
}

static int mtk_adsp_mbox_send_data(struct mbox_chan *chan, void *data)
{
	struct mtk_adsp_mbox_priv *priv = get_mtk_adsp_mbox_priv(chan->mbox);
	u32 *msg = data;

	writel(*msg, priv->va_mboxreg + priv->cfg->set_in);

	return 0;
}

static bool mtk_adsp_mbox_last_tx_done(struct mbox_chan *chan)
{
	struct mtk_adsp_mbox_priv *priv = get_mtk_adsp_mbox_priv(chan->mbox);

	return readl(priv->va_mboxreg + priv->cfg->set_in) == 0;
}

static const struct mbox_chan_ops mtk_adsp_mbox_chan_ops = {
	.send_data	= mtk_adsp_mbox_send_data,
	.startup	= mtk_adsp_mbox_startup,
	.shutdown	= mtk_adsp_mbox_shutdown,
	.last_tx_done	= mtk_adsp_mbox_last_tx_done,
};

static int mtk_adsp_mbox_probe(struct platform_device *pdev)

Annotation

Implementation Notes