From patchwork Tue Aug 18 15:41:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 247900 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp3230922ect; Tue, 18 Aug 2020 08:45:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC1VgszlR02BOpgw7ayrp/XijNhAhnfyQNidyOjxZrgVj6cWnUdZJNgypTen4ddExc3DbZ X-Received: by 2002:a17:906:7698:: with SMTP id o24mr21517570ejm.182.1597765530663; Tue, 18 Aug 2020 08:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597765530; cv=none; d=google.com; s=arc-20160816; b=GAH9GX1czk+X9y8HMIv6u+xiXz9ttFpA1rFm2BVKL1W1Ffu2Wrrrkvbax+OoZpIiwv UdH9NzjVZhHj4SPCKVOi3e6iYorQUmxiz0QX7g0YlhsTpz1YYUJwPJqGGfBSVAXtvmS/ 5qufZAjNGCoSiYlLI6Cdi25V4clUbSzzi6+RW6W2Goh7ukBD9HM78rtyS5NyGRwfjKDJ xt5fRLuBa+z4r9vuAf63Lha/6hhW6LWILENeeqBsy5suGS4MrwIDbtscucsYSTF0dBfX vnSyYqFWPIHqGjsgZwoa0ceQ0xeIlv+ljPxZwuNNGR6fIq0l3RyZ7KO7WNz0ilvbb4OI NUyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=bJyx/Yo1hHpKSSM28YtiU4jUqHvMw3fY3xHx5cECz5o=; b=uMw8oU59hUnH/EKq8ucQEjDc0bHoC3D4y+lyyIdrMjRNGHE86yERgTOF8vO9BZe9ix X8YfRjjISKc47E8wA0tiYx7VOjtuQjAl9FH418kDpyW/OrZBhjvBtPyyzXwNYS+9rLQ6 n0SCeSdibgU3NMljCAh5lzN+ZVWxUUYjKBRD4VCqCSuAKDa147aaoFh29+tvLRr0d/8V enbydImfcO+NSpIMJa1Tw8IIcF6Iq79m/WdT4GiUu418hVWmrDEyJMqCo0/rJdbNJrqb Xyl8w8Di1fjh5yjI1LXAX7wDu6keRhbzgi/vkpCd0yDIKwxucZACaqgfetGIpjfQ6VXa 8o0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mi6a0gRy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id v14si14239859ejx.388.2020.08.18.08.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 08:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mi6a0gRy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A13DA82252; Tue, 18 Aug 2020 17:45:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Mi6a0gRy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A80D4821E2; Tue, 18 Aug 2020 17:45:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 04CEA821E2 for ; Tue, 18 Aug 2020 17:44:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=etienne.carriere@linaro.org Received: by mail-wm1-x342.google.com with SMTP id c19so15627698wmd.1 for ; Tue, 18 Aug 2020 08:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bJyx/Yo1hHpKSSM28YtiU4jUqHvMw3fY3xHx5cECz5o=; b=Mi6a0gRyRWdungzD9H4X7SHpjjgeC9fHAzADkPDHk+/A0fSapHCB/7fIQZGDfGUke+ Y4E4vjro8me6IvpeH/Ms1LHqSJUsWwPHxOCs7z7ulbJpBWm/ag43ldIjGIg++bjfsUoa OLrDD05spKJTDvAI+uXMIJB6nwWEh3jpapT/USR2Vxo50KV0pG0v4EUbcbNCJ0aSGmZS STkFDMIgzaxFx6304+tUlnf9re3PzxR5HImztdlwtRA6YPdLu1c3uN8KA1l0EWYFKfs6 y8N9kHZPPZgYCbreG3JV16Vnxn/DHLT8OA9ssJvVwWt1hSPUMB6oIqEiclk0obJuvFRe XBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bJyx/Yo1hHpKSSM28YtiU4jUqHvMw3fY3xHx5cECz5o=; b=kRscJMfTXjumqLX8oYklTpOCX0LcW8XCAPT6uybpEvdJWdXCH305wxWT3DcfJBxjuq aCG4VzdthIjE6YIxt1j5jGTXbsBO3v9G6HmgdbtYZMzHchrnpKbwkGsmjQ1NM4jt3dzh I1iNBJqvcoUpjnuUDYhaFpg+OXsGhMGm0jHs4qQSLePseR/wWA9k8yAqbmBZFQdQgJAX glVjr5xDDf9HtJDDZ6Zg+Jbc7yVK98IxOPLngsiICLhA5kTdL2FO9xHPWoSbkqQaXgF/ SNuD39xLprYR/icTK/vvpi8qw0iIg5iAHgHGoxhx+A3k2XB9vw0YXBwCsccGkHlUH7MA qwOA== X-Gm-Message-State: AOAM531z3Ch0g11uwS3HoqR3wBoo5iKvKO+eq3NMuLRs/FmbMkG3jHKx oVmye2VNKx7IiHY2N6THzs82RQjVI8kgxLTP X-Received: by 2002:a1c:f30f:: with SMTP id q15mr520267wmq.60.1597765497512; Tue, 18 Aug 2020 08:44:57 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:11d8:1838:f15d:dd00:3cff:c56f]) by smtp.gmail.com with ESMTPSA id h11sm35772645wrb.68.2020.08.18.08.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 08:44:57 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Simon Glass , Peng Fan , Sudeep Holla Subject: [PATCH v2 4/4] reset: add reset controller driver for SCMI agents Date: Tue, 18 Aug 2020 17:41:33 +0200 Message-Id: <20200818154133.22028-4-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200818154133.22028-1-etienne.carriere@linaro.org> References: <20200818154133.22028-1-etienne.carriere@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 Cc: Simon Glass Cc: Peng Fan Cc: Sudeep Holla --- 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. --- drivers/firmware/scmi.c | 3 + drivers/reset/Kconfig | 8 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-scmi.c | 143 +++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 drivers/reset/reset-scmi.c -- 2.17.1 Reviewed-by: Simon Glass diff --git a/drivers/firmware/scmi.c b/drivers/firmware/scmi.c index cddfa0bbc2..07a2b0f986 100644 --- a/drivers/firmware/scmi.c +++ b/drivers/firmware/scmi.c @@ -460,6 +460,9 @@ static int scmi_bind(struct udevice *dev) case SCMI_PROTOCOL_ID_CLOCK: drv = DM_GET_DRIVER(scmi_clock); break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + drv = DM_GET_DRIVER(scmi_reset_domain); + break; default: dev_info(dev, "Ignore unsupported SCMI protocol %u\n", protocol_id); 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..e8dabc9751 --- /dev/null +++ b/drivers/reset/reset-scmi.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019-2020 Linaro Limited + */ +#include +#include +#include +#include +#include +#include + +#define SCMI_RD_NAME_LEN 16 + +#define SCMI_RD_RESET_FLAG_ASSERT BIT(1) +#define SCMI_RD_RESET_FLAG_DEASSERT 0 + +enum scmi_reset_domain_message_id { + SCMI_RESET_DOMAIN_ATTRIBUTES = 0x3, + SCMI_RESET_DOMAIN_RESET = 0x4, +}; + +/** + * 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; +}; + +static int scmi_reset_set_state(struct reset_ctl *rst, int assert_not_deassert) +{ + struct scmi_rd_reset_in in = { + .domain_id = rst->id, + .flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : + SCMI_RD_RESET_FLAG_DEASSERT, + .reset_state = 0, + }; + struct scmi_rd_reset_out out; + struct scmi_msg scmi_msg = { + .protocol_id = SCMI_PROTOCOL_ID_RESET_DOMAIN, + .message_id = SCMI_RESET_DOMAIN_RESET, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = scmi_send_and_process_msg(rst->dev->parent, &scmi_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_state(rst, SCMI_RD_RESET_FLAG_ASSERT); +} + +static int scmi_reset_deassert(struct reset_ctl *rst) +{ + return scmi_reset_set_state(rst, SCMI_RD_RESET_FLAG_DEASSERT); +} + +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 scmi_msg = { + .protocol_id = SCMI_PROTOCOL_ID_RESET_DOMAIN, + .message_id = SCMI_RESET_DOMAIN_RESET, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + /* + * We don't really care about the attribute, just check + * the reset domain exists. + */ + ret = scmi_send_and_process_msg(rst->dev->parent, &scmi_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, +};