diff mbox series

[v4,7/8] reset: add reset controller driver for SCMI agents

Message ID 20200909164407.14327-7-etienne.carriere@linaro.org
State Accepted
Commit 34d76fefb2667d0ca138ff4fcf8bc8443032449f
Headers show
Series [v4,1/8] firmware: add SCMI agent uclass | expand

Commit Message

Etienne Carriere Sept. 9, 2020, 4:44 p.m. UTC
This change introduces a reset controller driver for SCMI agent devices.
When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent
binds a reset controller device for each SCMI reset domain protocol
devices enabled in the FDT.

SCMI reset driver is embedded upon CONFIG_RESET_SCMI=y. If enabled,
CONFIG_SCMI_AGENT is also enabled.

SCMI Reset Domain protocol is defined in the SCMI specification [1].

Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

Cc: Simon Glass <sjg@chromium.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
---

Changes in v4:
- Condition DM_GET_DRIVER(scmi_reset_domain) to
  IS_ENABLED(CONFIG_RESET_SCMI) to prevent a build error (linker) when
  CONFIG_RESET_SCMI is disabled.

Changes in v3:
- Upgrade to rename into devm_scmi_process_msg() and scmi.h split
  into scmi_*.h.
- Fix message ID used in scmi_reset_request().

Changes in v2:
- Change reset request() method to at least check the reset domain
  exists by sending a SCMI RESET_DOMAIN_ATTRIBUTE message.
- Add inline description for the several structures.
- Patch v1 R-b tag not applied since the above changes in this v2.

BACKPORTED FROM v2020.10-rc2 to V2020.04
---
 drivers/firmware/scmi/scmi_agent-uclass.c |  4 ++
 drivers/reset/Kconfig                     |  8 +++
 drivers/reset/Makefile                    |  1 +
 drivers/reset/reset-scmi.c                | 81 +++++++++++++++++++++++
 include/scmi_protocols.h                  | 60 +++++++++++++++++
 5 files changed, 154 insertions(+)
 create mode 100644 drivers/reset/reset-scmi.c

-- 
2.17.1

Comments

Simon Glass Sept. 10, 2020, 1:38 p.m. UTC | #1
On Wed, 9 Sep 2020 at 10:44, Etienne Carriere
<etienne.carriere@linaro.org> wrote:
>

> This change introduces a reset controller driver for SCMI agent devices.

> When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent

> binds a reset controller device for each SCMI reset domain protocol

> devices enabled in the FDT.

>

> SCMI reset driver is embedded upon CONFIG_RESET_SCMI=y. If enabled,

> CONFIG_SCMI_AGENT is also enabled.

>

> SCMI Reset Domain protocol is defined in the SCMI specification [1].

>

> Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi

> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

> Cc: Simon Glass <sjg@chromium.org>

> Cc: Peng Fan <peng.fan@nxp.com>

> Cc: Sudeep Holla <sudeep.holla@arm.com>

> ---

>

> Changes in v4:

> - Condition DM_GET_DRIVER(scmi_reset_domain) to

>   IS_ENABLED(CONFIG_RESET_SCMI) to prevent a build error (linker) when

>   CONFIG_RESET_SCMI is disabled.

>

> Changes in v3:

> - Upgrade to rename into devm_scmi_process_msg() and scmi.h split

>   into scmi_*.h.

> - Fix message ID used in scmi_reset_request().

>

> Changes in v2:

> - Change reset request() method to at least check the reset domain

>   exists by sending a SCMI RESET_DOMAIN_ATTRIBUTE message.

> - Add inline description for the several structures.

> - Patch v1 R-b tag not applied since the above changes in this v2.

>

> BACKPORTED FROM v2020.10-rc2 to V2020.04

> ---

>  drivers/firmware/scmi/scmi_agent-uclass.c |  4 ++

>  drivers/reset/Kconfig                     |  8 +++

>  drivers/reset/Makefile                    |  1 +

>  drivers/reset/reset-scmi.c                | 81 +++++++++++++++++++++++

>  include/scmi_protocols.h                  | 60 +++++++++++++++++

>  5 files changed, 154 insertions(+)

>  create mode 100644 drivers/reset/reset-scmi.c

>


Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Oct. 1, 2020, 2:08 p.m. UTC | #2
On Wed, Sep 09, 2020 at 06:44:06PM +0200, Etienne Carriere wrote:

> This change introduces a reset controller driver for SCMI agent devices.

> When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent

> binds a reset controller device for each SCMI reset domain protocol

> devices enabled in the FDT.

> 

> SCMI reset driver is embedded upon CONFIG_RESET_SCMI=y. If enabled,

> CONFIG_SCMI_AGENT is also enabled.

> 

> SCMI Reset Domain protocol is defined in the SCMI specification [1].

> 

> Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi

> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

> Cc: Simon Glass <sjg@chromium.org>

> Cc: Peng Fan <peng.fan@nxp.com>

> Cc: Sudeep Holla <sudeep.holla@arm.com>

> Reviewed-by: Simon Glass <sjg@chromium.org>


Applied to u-boot/next, thanks!

-- 
Tom
diff mbox series

Patch

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index 1f36f23b6d..77160b1999 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -74,6 +74,10 @@  static int scmi_bind_protocols(struct udevice *dev)
 			if (IS_ENABLED(CONFIG_CLK_SCMI))
 				drv = DM_GET_DRIVER(scmi_clock);
 			break;
+		case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+			if (IS_ENABLED(CONFIG_RESET_SCMI))
+				drv = DM_GET_DRIVER(scmi_reset_domain);
+			break;
 		default:
 			break;
 		}
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 253902ff57..ee5be0bc2f 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -173,4 +173,12 @@  config RESET_RASPBERRYPI
 	  relevant. This driver provides a reset controller capable of
 	  interfacing with RPi4's co-processor and model these firmware
 	  initialization routines as reset lines.
+
+config RESET_SCMI
+	bool "Enable SCMI reset domain driver"
+	select SCMI_FIRMWARE
+	help
+	  Enable this option if you want to support reset controller
+	  devices exposed by a SCMI agent based on SCMI reset domain
+	  protocol communication with a SCMI server.
 endmenu
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 3c7f066ae3..625ec7168e 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -26,3 +26,4 @@  obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
 obj-$(CONFIG_RESET_SIFIVE) += reset-sifive.o
 obj-$(CONFIG_RESET_SYSCON) += reset-syscon.o
 obj-$(CONFIG_RESET_RASPBERRYPI) += reset-raspberrypi.o
+obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c
new file mode 100644
index 0000000000..1bff8075ee
--- /dev/null
+++ b/drivers/reset/reset-scmi.c
@@ -0,0 +1,81 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019-2020 Linaro Limited
+ */
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <reset-uclass.h>
+#include <scmi_agent.h>
+#include <scmi_protocols.h>
+#include <asm/types.h>
+
+static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
+{
+	struct scmi_rd_reset_in in = {
+		.domain_id = rst->id,
+		.flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : 0,
+		.reset_state = 0,
+	};
+	struct scmi_rd_reset_out out;
+	struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
+					  SCMI_RESET_DOMAIN_RESET,
+					  in, out);
+	int ret;
+
+	ret = devm_scmi_process_msg(rst->dev->parent, &msg);
+	if (ret)
+		return ret;
+
+	return scmi_to_linux_errno(out.status);
+}
+
+static int scmi_reset_assert(struct reset_ctl *rst)
+{
+	return scmi_reset_set_level(rst, true);
+}
+
+static int scmi_reset_deassert(struct reset_ctl *rst)
+{
+	return scmi_reset_set_level(rst, false);
+}
+
+static int scmi_reset_request(struct reset_ctl *rst)
+{
+	struct scmi_rd_attr_in in = {
+		.domain_id = rst->id,
+	};
+	struct scmi_rd_attr_out out;
+	struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
+					  SCMI_RESET_DOMAIN_ATTRIBUTES,
+					  in, out);
+	int ret;
+
+	/*
+	 * We don't really care about the attribute, just check
+	 * the reset domain exists.
+	 */
+	ret = devm_scmi_process_msg(rst->dev->parent, &msg);
+	if (ret)
+		return ret;
+
+	return scmi_to_linux_errno(out.status);
+}
+
+static int scmi_reset_rfree(struct reset_ctl *rst)
+{
+	return 0;
+}
+
+static const struct reset_ops scmi_reset_domain_ops = {
+	.request	= scmi_reset_request,
+	.rfree		= scmi_reset_rfree,
+	.rst_assert	= scmi_reset_assert,
+	.rst_deassert	= scmi_reset_deassert,
+};
+
+U_BOOT_DRIVER(scmi_reset_domain) = {
+	.name = "scmi_reset_domain",
+	.id = UCLASS_RESET,
+	.ops = &scmi_reset_domain_ops,
+};
diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h
index 4778bcfc47..ccab97c96c 100644
--- a/include/scmi_protocols.h
+++ b/include/scmi_protocols.h
@@ -116,4 +116,64 @@  struct scmi_clk_rate_set_out {
 	s32 status;
 };
 
+/*
+ * SCMI Reset Domain Protocol
+ */
+
+enum scmi_reset_domain_message_id {
+	SCMI_RESET_DOMAIN_ATTRIBUTES = 0x3,
+	SCMI_RESET_DOMAIN_RESET = 0x4,
+};
+
+#define SCMI_RD_NAME_LEN		16
+
+#define SCMI_RD_ATTRIBUTES_FLAG_ASYNC	BIT(31)
+#define SCMI_RD_ATTRIBUTES_FLAG_NOTIF	BIT(30)
+
+#define SCMI_RD_RESET_FLAG_ASYNC	BIT(2)
+#define SCMI_RD_RESET_FLAG_ASSERT	BIT(1)
+#define SCMI_RD_RESET_FLAG_CYCLE	BIT(0)
+
+/**
+ * struct scmi_rd_attr_in - Payload for RESET_DOMAIN_ATTRIBUTES message
+ * @domain_id:	SCMI reset domain ID
+ */
+struct scmi_rd_attr_in {
+	u32 domain_id;
+};
+
+/**
+ * struct scmi_rd_attr_out - Payload for RESET_DOMAIN_ATTRIBUTES response
+ * @status:	SCMI command status
+ * @attributes:	Retrieved attributes of the reset domain
+ * @latency:	Reset cycle max lantency
+ * @name:	Reset domain name
+ */
+struct scmi_rd_attr_out {
+	s32 status;
+	u32 attributes;
+	u32 latency;
+	char name[SCMI_RD_NAME_LEN];
+};
+
+/**
+ * struct scmi_rd_reset_in - Message payload for RESET command
+ * @domain_id:		SCMI reset domain ID
+ * @flags:		Flags for the reset request
+ * @reset_state:	Reset target state
+ */
+struct scmi_rd_reset_in {
+	u32 domain_id;
+	u32 flags;
+	u32 reset_state;
+};
+
+/**
+ * struct scmi_rd_reset_out - Response payload for RESET command
+ * @status:	SCMI command status
+ */
+struct scmi_rd_reset_out {
+	s32 status;
+};
+
 #endif /* _SCMI_PROTOCOLS_H */