1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP Remote Processor driver
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Copyright (C) 2011 Google, Inc.
8 * Ohad Ben-Cohen <ohad@wizery.com>
9 * Brian Swetland <swetland@google.com>
10 * Fernando Guzman Lugo <fernando.lugo@ti.com>
11 * Mark Grosen <mgrosen@ti.com>
12 * Suman Anna <s-anna@ti.com>
13 * Hari Kanigeri <h-kanigeri2@ti.com>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/remoteproc.h>
22 #include <linux/mailbox_client.h>
23 #include <linux/omap-mailbox.h>
25 #include <linux/platform_data/remoteproc-omap.h>
27 #include "omap_remoteproc.h"
28 #include "remoteproc_internal.h"
31 * struct omap_rproc - omap remote processor state
32 * @mbox: mailbox channel handle
33 * @client: mailbox client to request the mailbox channel
34 * @rproc: rproc handle
37 struct mbox_chan
*mbox
;
38 struct mbox_client client
;
43 * omap_rproc_mbox_callback() - inbound mailbox message handler
44 * @client: mailbox client pointer used for requesting the mailbox channel
45 * @data: mailbox payload
47 * This handler is invoked by omap's mailbox driver whenever a mailbox
48 * message is received. Usually, the mailbox payload simply contains
49 * the index of the virtqueue that is kicked by the remote processor,
50 * and we let remoteproc core handle it.
52 * In addition to virtqueue indices, we also have some out-of-band values
53 * that indicates different events. Those values are deliberately very
54 * big so they don't coincide with virtqueue indices.
56 static void omap_rproc_mbox_callback(struct mbox_client
*client
, void *data
)
58 struct omap_rproc
*oproc
= container_of(client
, struct omap_rproc
,
60 struct device
*dev
= oproc
->rproc
->dev
.parent
;
61 const char *name
= oproc
->rproc
->name
;
64 dev_dbg(dev
, "mbox msg: 0x%x\n", msg
);
68 /* just log this for now. later, we'll also do recovery */
69 dev_err(dev
, "omap rproc %s crashed\n", name
);
71 case RP_MBOX_ECHO_REPLY
:
72 dev_info(dev
, "received echo reply from %s\n", name
);
75 /* msg contains the index of the triggered vring */
76 if (rproc_vq_interrupt(oproc
->rproc
, msg
) == IRQ_NONE
)
77 dev_dbg(dev
, "no message was found in vqid %d\n", msg
);
81 /* kick a virtqueue */
82 static void omap_rproc_kick(struct rproc
*rproc
, int vqid
)
84 struct omap_rproc
*oproc
= rproc
->priv
;
85 struct device
*dev
= rproc
->dev
.parent
;
88 /* send the index of the triggered virtqueue in the mailbox payload */
89 ret
= mbox_send_message(oproc
->mbox
, (void *)vqid
);
91 dev_err(dev
, "failed to send mailbox message, status = %d\n",
96 * Power up the remote processor.
98 * This function will be invoked only after the firmware for this rproc
99 * was loaded, parsed successfully, and all of its resource requirements
102 static int omap_rproc_start(struct rproc
*rproc
)
104 struct omap_rproc
*oproc
= rproc
->priv
;
105 struct device
*dev
= rproc
->dev
.parent
;
106 struct platform_device
*pdev
= to_platform_device(dev
);
107 struct omap_rproc_pdata
*pdata
= pdev
->dev
.platform_data
;
109 struct mbox_client
*client
= &oproc
->client
;
111 if (pdata
->set_bootaddr
)
112 pdata
->set_bootaddr(rproc
->bootaddr
);
115 client
->tx_done
= NULL
;
116 client
->rx_callback
= omap_rproc_mbox_callback
;
117 client
->tx_block
= false;
118 client
->knows_txdone
= false;
120 oproc
->mbox
= omap_mbox_request_channel(client
, pdata
->mbox_name
);
121 if (IS_ERR(oproc
->mbox
)) {
123 dev_err(dev
, "mbox_request_channel failed: %ld\n",
124 PTR_ERR(oproc
->mbox
));
129 * Ping the remote processor. this is only for sanity-sake;
130 * there is no functional effect whatsoever.
132 * Note that the reply will _not_ arrive immediately: this message
133 * will wait in the mailbox fifo until the remote processor is booted.
135 ret
= mbox_send_message(oproc
->mbox
, (void *)RP_MBOX_ECHO_REQUEST
);
137 dev_err(dev
, "mbox_send_message failed: %d\n", ret
);
141 ret
= pdata
->device_enable(pdev
);
143 dev_err(dev
, "omap_device_enable failed: %d\n", ret
);
150 mbox_free_channel(oproc
->mbox
);
154 /* power off the remote processor */
155 static int omap_rproc_stop(struct rproc
*rproc
)
157 struct device
*dev
= rproc
->dev
.parent
;
158 struct platform_device
*pdev
= to_platform_device(dev
);
159 struct omap_rproc_pdata
*pdata
= pdev
->dev
.platform_data
;
160 struct omap_rproc
*oproc
= rproc
->priv
;
163 ret
= pdata
->device_shutdown(pdev
);
167 mbox_free_channel(oproc
->mbox
);
172 static const struct rproc_ops omap_rproc_ops
= {
173 .start
= omap_rproc_start
,
174 .stop
= omap_rproc_stop
,
175 .kick
= omap_rproc_kick
,
178 static int omap_rproc_probe(struct platform_device
*pdev
)
180 struct omap_rproc_pdata
*pdata
= pdev
->dev
.platform_data
;
181 struct omap_rproc
*oproc
;
185 ret
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
187 dev_err(&pdev
->dev
, "dma_set_coherent_mask: %d\n", ret
);
191 rproc
= rproc_alloc(&pdev
->dev
, pdata
->name
, &omap_rproc_ops
,
192 pdata
->firmware
, sizeof(*oproc
));
197 oproc
->rproc
= rproc
;
198 /* All existing OMAP IPU and DSP processors have an MMU */
199 rproc
->has_iommu
= true;
201 platform_set_drvdata(pdev
, rproc
);
203 ret
= rproc_add(rproc
);
214 static int omap_rproc_remove(struct platform_device
*pdev
)
216 struct rproc
*rproc
= platform_get_drvdata(pdev
);
224 static struct platform_driver omap_rproc_driver
= {
225 .probe
= omap_rproc_probe
,
226 .remove
= omap_rproc_remove
,
228 .name
= "omap-rproc",
232 module_platform_driver(omap_rproc_driver
);
234 MODULE_LICENSE("GPL v2");
235 MODULE_DESCRIPTION("OMAP Remote Processor control driver");