mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-13 16:37:30 +00:00
88a304f864
Change SCMI mailbox transport drivers to use platform data rather than private data for channel reference since it only stores platform data retrieved from the DT. Consequently the probe handler is replaced with a of_to_plat handler. Cc: Simon Glass <sjg@chromium.org> Cc: Patrice Chotard <patrice.chotard@foss.st.com> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
101 lines
2.2 KiB
C
101 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2020 Linaro Limited.
|
|
*/
|
|
|
|
#define LOG_CATEGORY UCLASS_SCMI_AGENT
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <errno.h>
|
|
#include <mailbox.h>
|
|
#include <scmi_agent.h>
|
|
#include <scmi_agent-uclass.h>
|
|
#include <dm/device_compat.h>
|
|
#include <dm/devres.h>
|
|
#include <linux/compat.h>
|
|
|
|
#include "smt.h"
|
|
|
|
#define TIMEOUT_US_10MS 10000
|
|
|
|
/**
|
|
* struct scmi_mbox_channel - Description of an SCMI mailbox transport
|
|
* @smt: Shared memory buffer
|
|
* @mbox: Mailbox channel description
|
|
* @timeout_us: Timeout in microseconds for the mailbox transfer
|
|
*/
|
|
struct scmi_mbox_channel {
|
|
struct scmi_smt smt;
|
|
struct mbox_chan mbox;
|
|
ulong timeout_us;
|
|
};
|
|
|
|
static int scmi_mbox_process_msg(struct udevice *dev, struct scmi_msg *msg)
|
|
{
|
|
struct scmi_mbox_channel *chan = dev_get_plat(dev);
|
|
int ret;
|
|
|
|
ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* Give shm addr to mbox in case it is meaningful */
|
|
ret = mbox_send(&chan->mbox, chan->smt.buf);
|
|
if (ret) {
|
|
dev_err(dev, "Message send failed: %d\n", ret);
|
|
goto out;
|
|
}
|
|
|
|
/* Receive the response */
|
|
ret = mbox_recv(&chan->mbox, chan->smt.buf, chan->timeout_us);
|
|
if (ret) {
|
|
dev_err(dev, "Response failed: %d, abort\n", ret);
|
|
goto out;
|
|
}
|
|
|
|
ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
|
|
|
|
out:
|
|
scmi_clear_smt_channel(&chan->smt);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int scmi_mbox_of_to_plat(struct udevice *dev)
|
|
{
|
|
struct scmi_mbox_channel *chan = dev_get_plat(dev);
|
|
int ret;
|
|
|
|
chan->timeout_us = TIMEOUT_US_10MS;
|
|
|
|
ret = mbox_get_by_index(dev, 0, &chan->mbox);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to find mailbox: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
|
|
if (ret)
|
|
dev_err(dev, "Failed to get shm resources: %d\n", ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static const struct udevice_id scmi_mbox_ids[] = {
|
|
{ .compatible = "arm,scmi" },
|
|
{ }
|
|
};
|
|
|
|
static const struct scmi_agent_ops scmi_mbox_ops = {
|
|
.process_msg = scmi_mbox_process_msg,
|
|
};
|
|
|
|
U_BOOT_DRIVER(scmi_mbox) = {
|
|
.name = "scmi-over-mailbox",
|
|
.id = UCLASS_SCMI_AGENT,
|
|
.of_match = scmi_mbox_ids,
|
|
.plat_auto = sizeof(struct scmi_mbox_channel),
|
|
.of_to_plat = scmi_mbox_of_to_plat,
|
|
.ops = &scmi_mbox_ops,
|
|
};
|