From: narmstrong@baylibre.com (Neil Armstrong)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 03/13] scpi: Add legacy send, prepare and handle remote functions
Date: Thu, 18 Aug 2016 12:10:56 +0200 [thread overview]
Message-ID: <1471515066-3626-4-git-send-email-narmstrong@baylibre.com> (raw)
In-Reply-To: <1471515066-3626-1-git-send-email-narmstrong@baylibre.com>
In order to support the legacy SCPI procotol, add specific message_send,
prepare_tx and handle_remote functions since the legacy procotol
do not support message queuing and does not store the command word in the
tx_payload data.
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
drivers/firmware/arm_scpi.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
index 0bb6134..50b1297 100644
--- a/drivers/firmware/arm_scpi.c
+++ b/drivers/firmware/arm_scpi.c
@@ -202,6 +202,7 @@ struct scpi_chan {
spinlock_t rx_lock; /* locking for the rx pending list */
struct mutex xfers_lock;
u8 token;
+ struct scpi_xfer *t;
};
struct scpi_drvinfo {
@@ -364,6 +365,23 @@ static void scpi_handle_remote_msg(struct mbox_client *c, void *msg)
scpi_process_cmd(ch, cmd);
}
+static void legacy_scpi_handle_remote_msg(struct mbox_client *c, void *__msg)
+{
+ struct scpi_chan *ch =
+ container_of(c, struct scpi_chan, cl);
+ struct legacy_scpi_shared_mem *mem = ch->rx_payload;
+ unsigned int len;
+
+ len = ch->t->rx_len;
+
+ ch->t->status = le32_to_cpu(mem->status);
+
+ if (len)
+ memcpy_fromio(ch->t->rx_buf, mem->payload, len);
+
+ complete(&ch->t->done);
+}
+
static void scpi_tx_prepare(struct mbox_client *c, void *msg)
{
unsigned long flags;
@@ -384,6 +402,15 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
mem->command = cpu_to_le32(t->cmd);
}
+static void legacy_scpi_tx_prepare(struct mbox_client *c, void *__msg)
+{
+ struct scpi_chan *ch =
+ container_of(c, struct scpi_chan, cl);
+
+ if (ch->t->tx_buf && ch->t->tx_len)
+ memcpy_toio(ch->tx_payload, ch->t->tx_buf, ch->t->tx_len);
+}
+
static int legacy_high_priority_cmds[] = {
LEGACY_SCPI_CMD_GET_CSS_PWR_STATE,
LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT,
@@ -434,6 +461,48 @@ static void put_scpi_xfer(struct scpi_xfer *t, struct scpi_chan *ch)
mutex_unlock(&ch->xfers_lock);
}
+static int legacy_scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len,
+ void *rx_buf, unsigned int rx_len)
+{
+ int ret;
+ u8 chan;
+ struct scpi_xfer *msg;
+ struct scpi_chan *scpi_chan;
+
+ chan = legacy_scpi_get_chan(cmd);
+ scpi_chan = scpi_info->channels + chan;
+
+ msg = get_scpi_xfer(scpi_chan);
+ if (!msg)
+ return -ENOMEM;
+
+ mutex_lock(&scpi_chan->xfers_lock);
+
+ msg->cmd = PACK_LEGACY_SCPI_CMD(cmd, tx_len);
+ msg->tx_buf = tx_buf;
+ msg->tx_len = tx_len;
+ msg->rx_buf = rx_buf;
+ msg->rx_len = rx_len;
+ init_completion(&msg->done);
+ scpi_chan->t = msg;
+
+ ret = mbox_send_message(scpi_chan->chan, &msg->cmd);
+ if (ret < 0)
+ goto out;
+
+ if (!wait_for_completion_timeout(&msg->done, MAX_RX_TIMEOUT))
+ ret = -ETIMEDOUT;
+ else
+ /* first status word */
+ ret = msg->status;
+out:
+ mutex_unlock(&scpi_chan->xfers_lock);
+
+ put_scpi_xfer(msg, scpi_chan);
+ /* SCPI error codes > 0, translate them to Linux scale*/
+ return ret > 0 ? scpi_to_linux_errno(ret) : ret;
+}
+
static int __scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len,
void *rx_buf, unsigned int rx_len, bool extn)
{
--
1.9.1
next prev parent reply other threads:[~2016-08-18 10:10 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-18 10:10 [PATCH 00/13] scpi: Add support for legacy SCPI protocol Neil Armstrong
2016-08-18 10:10 ` [PATCH 01/13] scpi: Add vendor_send_message to enable access to vendor commands Neil Armstrong
2016-08-18 15:53 ` Sudeep Holla
2016-08-19 8:00 ` Neil Armstrong
2016-08-19 10:39 ` Sudeep Holla
2016-08-18 10:10 ` [PATCH 02/13] scpi: Add alternative legacy structures and macros Neil Armstrong
2016-08-18 17:16 ` Sudeep Holla
2016-08-23 8:09 ` Neil Armstrong
2016-08-18 10:10 ` Neil Armstrong [this message]
2016-08-19 16:13 ` [PATCH 03/13] scpi: Add legacy send, prepare and handle remote functions Sudeep Holla
2016-08-23 8:15 ` Neil Armstrong
2016-08-23 14:42 ` Sudeep Holla
2016-08-18 10:10 ` [PATCH 04/13] scpi: Add legacy SCP functions calling legacy_scpi_send_message Neil Armstrong
2016-08-19 16:22 ` Sudeep Holla
2016-08-23 8:19 ` Neil Armstrong
2016-08-23 14:47 ` Sudeep Holla
2016-08-18 10:10 ` [PATCH 05/13] scpi: move of_match table before probe functions Neil Armstrong
2016-08-19 16:24 ` Sudeep Holla
2016-08-23 8:20 ` Neil Armstrong
2016-08-18 10:10 ` [PATCH 06/13] scpi: add priv_scpi_ops and fill legacy structure Neil Armstrong
2016-08-19 16:39 ` Sudeep Holla
2016-08-23 8:22 ` Neil Armstrong
2016-08-23 14:50 ` Sudeep Holla
2016-08-18 10:11 ` [PATCH 07/13] scpi: ignore init_versions failure if reported not supported Neil Armstrong
2016-08-19 16:46 ` Sudeep Holla
2016-08-23 8:23 ` Neil Armstrong
2016-08-23 14:54 ` Sudeep Holla
2016-08-23 14:55 ` Neil Armstrong
2016-08-23 15:01 ` Sudeep Holla
2016-08-18 10:11 ` [PATCH 08/13] scpi: add a vendor_msg mechanism in case the mailbox message differs Neil Armstrong
2016-08-19 16:47 ` Sudeep Holla
2016-08-18 10:11 ` [PATCH 09/13] scpi: implement rockchip support via the vendor_msg mechanism Neil Armstrong
2016-08-18 10:11 ` [PATCH 10/13] scpi: grow MAX_DVFS_OPPS to 16 entries Neil Armstrong
2016-08-18 10:11 ` [PATCH 11/13] dt-bindings: Add support for Amlogic GXBB SCPI Interface Neil Armstrong
2016-08-19 13:45 ` Rob Herring
2016-08-18 10:11 ` [PATCH 12/13] ARM64: dts: meson-gxbb: Add SRAM node Neil Armstrong
2016-08-18 10:11 ` [PATCH 13/13] ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors Nodes Neil Armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471515066-3626-4-git-send-email-narmstrong@baylibre.com \
--to=narmstrong@baylibre.com \
--cc=linus-amlogic@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).