Skip to content

Commit e3865c8

Browse files
sumanannaandersson
authored andcommitted
remoteproc: k3-r5: Refactor mbox request code in start
Refactor out the mailbox request and associated ping logic code from k3_r5_rproc_start() function into its own separate function so that it can be re-used in the soon to be added .attach() ops callback. Signed-off-by: Suman Anna <s-anna@ti.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220213201246.25952-3-s-anna@ti.com
1 parent c13b780 commit e3865c8

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* TI K3 R5F (MCU) Remote Processor driver
44
*
5-
* Copyright (C) 2017-2020 Texas Instruments Incorporated - https://www.ti.com/
5+
* Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
66
* Suman Anna <s-anna@ti.com>
77
*/
88

@@ -376,6 +376,44 @@ static inline int k3_r5_core_run(struct k3_r5_core *core)
376376
0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT);
377377
}
378378

379+
static int k3_r5_rproc_request_mbox(struct rproc *rproc)
380+
{
381+
struct k3_r5_rproc *kproc = rproc->priv;
382+
struct mbox_client *client = &kproc->client;
383+
struct device *dev = kproc->dev;
384+
int ret;
385+
386+
client->dev = dev;
387+
client->tx_done = NULL;
388+
client->rx_callback = k3_r5_rproc_mbox_callback;
389+
client->tx_block = false;
390+
client->knows_txdone = false;
391+
392+
kproc->mbox = mbox_request_channel(client, 0);
393+
if (IS_ERR(kproc->mbox)) {
394+
ret = -EBUSY;
395+
dev_err(dev, "mbox_request_channel failed: %ld\n",
396+
PTR_ERR(kproc->mbox));
397+
return ret;
398+
}
399+
400+
/*
401+
* Ping the remote processor, this is only for sanity-sake for now;
402+
* there is no functional effect whatsoever.
403+
*
404+
* Note that the reply will _not_ arrive immediately: this message
405+
* will wait in the mailbox fifo until the remote processor is booted.
406+
*/
407+
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
408+
if (ret < 0) {
409+
dev_err(dev, "mbox_send_message failed: %d\n", ret);
410+
mbox_free_channel(kproc->mbox);
411+
return ret;
412+
}
413+
414+
return 0;
415+
}
416+
379417
/*
380418
* The R5F cores have controls for both a reset and a halt/run. The code
381419
* execution from DDR requires the initial boot-strapping code to be run
@@ -495,38 +533,14 @@ static int k3_r5_rproc_start(struct rproc *rproc)
495533
{
496534
struct k3_r5_rproc *kproc = rproc->priv;
497535
struct k3_r5_cluster *cluster = kproc->cluster;
498-
struct mbox_client *client = &kproc->client;
499536
struct device *dev = kproc->dev;
500537
struct k3_r5_core *core;
501538
u32 boot_addr;
502539
int ret;
503540

504-
client->dev = dev;
505-
client->tx_done = NULL;
506-
client->rx_callback = k3_r5_rproc_mbox_callback;
507-
client->tx_block = false;
508-
client->knows_txdone = false;
509-
510-
kproc->mbox = mbox_request_channel(client, 0);
511-
if (IS_ERR(kproc->mbox)) {
512-
ret = -EBUSY;
513-
dev_err(dev, "mbox_request_channel failed: %ld\n",
514-
PTR_ERR(kproc->mbox));
541+
ret = k3_r5_rproc_request_mbox(rproc);
542+
if (ret)
515543
return ret;
516-
}
517-
518-
/*
519-
* Ping the remote processor, this is only for sanity-sake for now;
520-
* there is no functional effect whatsoever.
521-
*
522-
* Note that the reply will _not_ arrive immediately: this message
523-
* will wait in the mailbox fifo until the remote processor is booted.
524-
*/
525-
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
526-
if (ret < 0) {
527-
dev_err(dev, "mbox_send_message failed: %d\n", ret);
528-
goto put_mbox;
529-
}
530544

531545
boot_addr = rproc->bootaddr;
532546
/* TODO: add boot_addr sanity checking */

0 commit comments

Comments
 (0)