From patchwork Mon Feb 21 08:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 544402 Delivered-To: patch@linaro.org Received: by 2002:ac0:e142:0:0:0:0:0 with SMTP id r2csp3063663imn; Mon, 21 Feb 2022 00:23:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrUItZgj6u5j0c1CblZepjQ0RTSa9jBY0XcEND5LAmD5Zhm14McUuBaBQkx4HXK6NgIw8g X-Received: by 2002:a05:6402:170e:b0:40b:657:ac3f with SMTP id y14-20020a056402170e00b0040b0657ac3fmr19818077edu.354.1645431815391; Mon, 21 Feb 2022 00:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645431815; cv=none; d=google.com; s=arc-20160816; b=WiLiRaGHS2itG+FeeNeKsSAOny5CnyGt9xfmObNNyWR37CzV0wQEZCuQu33hkHsvqx bYLDZIQi0Zusc9X4YLDlr/5c/szwhFR9/lKVWs6PXq+ut7FgEmO43O3tBSPmfnYhrR89 jJE8SEfoCERPREyrvaZQNcLWmzVEtkipJaq9XuRDYhC/FD0AaHZv/RvthI30qfm4T3bc 2a30isPT0M8gFfgC/NnVgopP4o8pXCb4mxz6eyplr+pEWzMijPcANGKpSG6GmjpjcTto Zy3/3oUSQmEtBGJd65q9jS23VHB2c+sEyTR/5ZsEnh58vR6kOCrJXzT0gaPFIZsDoSwl LSeQ== 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=uvPh/7+2LgPQq98e8O2rAIMROkgnuu0w4s7IKIiQRsk=; b=UlQojG9V6CWPxmV1EHeo7RrVcBFOeMC8VjGFn6mzoSGoCP1lxEKf84sTQmDgRzSefD Q+j+WRBZu9NBSOT3MgOee2SmUyk19IJCWgO/z8NuetSrZ/Zm9rKLPGftRU9ZH3Fcw8Nz gDOO3IRp4ZGf8fT6kFqeWgIgNXgcwHjf2q/TS+2aXvrPssRXhz+UH2q9n0ifFSEP0R+/ pNryT+OSGo7X/8ZEmH86Kiyj836xKS21B5yZel2Zy8/QIXsNUC9I78TcTI8Zeu+q44Sr Q2tWpYuzHK5I2F7Di6WGEjlhzJOoBKLE/PDrkY89y8Wm8h7lCxLtfk/Oey/h4O1cEJ7i 0Kcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eWa7piNs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id w5si10582025edu.254.2022.02.21.00.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 00:23:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eWa7piNs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 1B5E582F65; Mon, 21 Feb 2022 09:23:13 +0100 (CET) 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="eWa7piNs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7076A83BCA; Mon, 21 Feb 2022 09:22:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (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 0093B83C0D for ; Mon, 21 Feb 2022 09:22:48 +0100 (CET) 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-x32e.google.com with SMTP id d14-20020a05600c34ce00b0037bf4d14dc7so10618728wmq.3 for ; Mon, 21 Feb 2022 00:22:48 -0800 (PST) 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=uvPh/7+2LgPQq98e8O2rAIMROkgnuu0w4s7IKIiQRsk=; b=eWa7piNs9VMsiJfyKtgHVfX48KglU5wQOrg+1NSbiVRPLcdWIxqytv0EJ1R9loc4o6 j79UU/9IYbIkTZeEFRghuWyfVEaBt5NsuyvLE6m+Khz03xgulha2t97s6HJfgP/ppEey pVY8wZAYTKR7byDyDzYq1s69jha/tGdV469+JKiiZnUJdQiGzBui7IKSCCo5PGjgSsgg hWoOMWVjCyuhdlGMhM4sjC1nZ1efyfOopPsx4xuhRU6Slqh9bYE8CUmNeyILpPgDstbU xQIbbxGj6qwHWjYRAdSHrCI06udx6rJomMoCrDuUEuP2UqpMzfjA0QjoSGZmbEGUJ8BT 68Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uvPh/7+2LgPQq98e8O2rAIMROkgnuu0w4s7IKIiQRsk=; b=BhoKtP+BdPOoi1OxfCbqQJ3Ed7lXNDyc/xDaaoc87B4+eVHOcbuLbbMcO7UVXcr5+m TK1bAVvd2mDdIwJKxr1J0CzYoorOGzwZW4AdE4XrcOZqydzbRYFQBUIFdM58fSRWyaRJ vv4ik59hVN/AFPVz8usJGvITYmIMzEHFqsEJd29iDMc0EQ220gvCl+7wNLc1Ohq1pNQT 8TYnDRsnyxg9maSLVIdWR5YfJbqk/6kMh/McbXxwKHTc+jIJj9YnNg877Bz/UJIAC7hb 6Vv/4/W9cQehNkSQkyrE5cCB9DYdQ4IyJZB9pA4W1jHcqqcmJg8IFVHSbgvsnr6WMkUl nvWQ== X-Gm-Message-State: AOAM533ZdmlfvJFrhV3M4Pcxi1tjv6CLq8U2zeaS4AKsYLVPU7W+ymbX +rjKXiw11Ikr3I2Jq8YcEG+mY7fFhVVbYp3F X-Received: by 2002:a05:600c:4fd0:b0:37b:ddf7:aeb9 with SMTP id o16-20020a05600c4fd000b0037bddf7aeb9mr20152806wmq.190.1645431768376; Mon, 21 Feb 2022 00:22:48 -0800 (PST) Received: from lmecxl0524.home (2a01cb058b8508003664a9fffe03a3fa.ipv6.abo.wanadoo.fr. [2a01:cb05:8b85:800:3664:a9ff:fe03:a3fa]) by smtp.gmail.com with ESMTPSA id m13-20020a05600c3b0d00b0037c00e01771sm6912286wms.34.2022.02.21.00.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 00:22:48 -0800 (PST) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Patrick Delaunay , Etienne Carriere , Lukasz Majewski , Sean Anderson , Clement Leger , Gabriel Fernandez Subject: [PATCH v2 5/5] clk: scmi: register scmi clocks with CCF Date: Mon, 21 Feb 2022 09:22:42 +0100 Message-Id: <20220221082242.6349-5-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220221082242.6349-1-etienne.carriere@linaro.org> References: <20220221082242.6349-1-etienne.carriere@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean Implements SCMI APIs to retrieve the number exposed SCMI clocks using SCMI_PROTOCOL_ATTRIBUTES messages and the names of the clocks using SCMI_CLOCK_ATTRIBUTES messages. This change updates sandbox SCMI clock test driver to manage these 2 new message IDs. Cc: Lukasz Majewski Cc: Sean Anderson Cc: Clement Leger Cc: Patrick Delaunay Reviewed-by: Patrick Delaunay Signed-off-by: Gabriel Fernandez Signed-off-by: Etienne Carriere --- Changes since v1: - Remove Series-links tag and apply R-b tag. --- drivers/clk/clk_scmi.c | 90 ++++++++++++++++++++++ drivers/firmware/scmi/sandbox-scmi_agent.c | 53 +++++++++++++ include/scmi_protocols.h | 43 +++++++++++ 3 files changed, 186 insertions(+) diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 42fbab0d21..57022685e2 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -11,6 +11,52 @@ #include #include #include +#include + +static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks) +{ + struct scmi_clk_protocol_attr_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_CLOCK, + .message_id = SCMI_PROTOCOL_ATTRIBUTES, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + + *num_clocks = out.attributes & SCMI_CLK_PROTO_ATTR_COUNT_MASK; + + return 0; +} + +static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name) +{ + struct scmi_clk_attribute_in in = { + .clock_id = clkid, + }; + struct scmi_clk_attribute_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_CLOCK, + .message_id = SCMI_CLOCK_ATTRIBUTES, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + + *name = out.clock_name; + + return 0; +} static int scmi_clk_gate(struct clk *clk, int enable) { @@ -88,6 +134,49 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) return scmi_clk_get_rate(clk); } +static int scmi_clk_probe(struct udevice *dev) +{ + struct clk *clk; + size_t num_clocks, i; + int ret; + + if (!CONFIG_IS_ENABLED(CLK_CCF)) + return 0; + + /* register CCF children: CLK UCLASS, no probed again */ + if (device_get_uclass_id(dev->parent) == UCLASS_CLK) + return 0; + + ret = scmi_clk_get_num_clock(dev, &num_clocks); + if (ret) + return ret; + + for (i = 0; i < num_clocks; i++) { + char *name; + + if (!scmi_clk_get_attibute(dev, i, &name)) { + char *clock_name = strdup(name); + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk || !clock_name) + ret = -ENOMEM; + else + ret = clk_register(clk, dev->driver->name, + clock_name, dev->name); + + if (ret) { + free(clk); + free(clock_name); + return ret; + } + + clk_dm(i, clk); + } + } + + return 0; +} + static const struct clk_ops scmi_clk_ops = { .enable = scmi_clk_enable, .disable = scmi_clk_disable, @@ -99,4 +188,5 @@ U_BOOT_DRIVER(scmi_clock) = { .name = "scmi_clk", .id = UCLASS_CLK, .ops = &scmi_clk_ops, + .probe = &scmi_clk_probe, }; diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index fc717a8aea..c555164d19 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -114,6 +114,55 @@ static struct sandbox_scmi_voltd *get_scmi_voltd_state(uint domain_id) * Sandbox SCMI agent ops */ +static int sandbox_scmi_clock_protocol_attribs(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_clk_protocol_attr_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_clk_protocol_attr_out *)msg->out_msg; + out->attributes = ARRAY_SIZE(scmi_clk); + out->status = SCMI_SUCCESS; + + return 0; +} + +static int sandbox_scmi_clock_attribs(struct udevice *dev, struct scmi_msg *msg) +{ + struct scmi_clk_attribute_in *in = NULL; + struct scmi_clk_attribute_out *out = NULL; + struct sandbox_scmi_clk *clk_state = NULL; + int ret; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(*in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + in = (struct scmi_clk_attribute_in *)msg->in_msg; + out = (struct scmi_clk_attribute_out *)msg->out_msg; + + clk_state = get_scmi_clk_state(in->clock_id); + if (!clk_state) { + dev_err(dev, "Unexpected clock ID %u\n", in->clock_id); + + out->status = SCMI_NOT_FOUND; + } else { + memset(out, 0, sizeof(*out)); + + if (clk_state->enabled) + out->attributes = 1; + + ret = snprintf(out->clock_name, sizeof(out->clock_name), + "clk%u", in->clock_id); + assert(ret > 0 && ret < sizeof(out->clock_name)); + + out->status = SCMI_SUCCESS; + } + + return 0; +} static int sandbox_scmi_clock_rate_set(struct udevice *dev, struct scmi_msg *msg) { @@ -427,6 +476,10 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, switch (msg->protocol_id) { case SCMI_PROTOCOL_ID_CLOCK: switch (msg->message_id) { + case SCMI_PROTOCOL_ATTRIBUTES: + return sandbox_scmi_clock_protocol_attribs(dev, msg); + case SCMI_CLOCK_ATTRIBUTES: + return sandbox_scmi_clock_attribs(dev, msg); case SCMI_CLOCK_RATE_SET: return sandbox_scmi_clock_rate_set(dev, msg); case SCMI_CLOCK_RATE_GET: diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index ef26e72176..a220cb2a91 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -40,22 +40,65 @@ enum scmi_status_code { SCMI_PROTOCOL_ERROR = -10, }; +/* + * Generic message IDs + */ +enum scmi_discovery_id { + SCMI_PROTOCOL_VERSION = 0x0, + SCMI_PROTOCOL_ATTRIBUTES = 0x1, + SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, +}; + /* * SCMI Clock Protocol */ enum scmi_clock_message_id { + SCMI_CLOCK_ATTRIBUTES = 0x3, SCMI_CLOCK_RATE_SET = 0x5, SCMI_CLOCK_RATE_GET = 0x6, SCMI_CLOCK_CONFIG_SET = 0x7, }; +#define SCMI_CLK_PROTO_ATTR_COUNT_MASK GENMASK(15, 0) #define SCMI_CLK_RATE_ASYNC_NOTIFY BIT(0) #define SCMI_CLK_RATE_ASYNC_NORESP (BIT(0) | BIT(1)) #define SCMI_CLK_RATE_ROUND_DOWN 0 #define SCMI_CLK_RATE_ROUND_UP BIT(2) #define SCMI_CLK_RATE_ROUND_CLOSEST BIT(3) +#define SCMI_CLOCK_NAME_LENGTH_MAX 16 + +/** + * struct scmi_clk_get_nb_out - Response for SCMI_PROTOCOL_ATTRIBUTES command + * @status: SCMI command status + * @attributes: Attributes of the clock protocol, mainly number of clocks exposed + */ +struct scmi_clk_protocol_attr_out { + s32 status; + u32 attributes; +}; + +/** + * struct scmi_clk_attribute_in - Message payload for SCMI_CLOCK_ATTRIBUTES command + * @clock_id: SCMI clock ID + */ +struct scmi_clk_attribute_in { + u32 clock_id; +}; + +/** + * struct scmi_clk_get_nb_out - Response payload for SCMI_CLOCK_ATTRIBUTES command + * @status: SCMI command status + * @attributes: clock attributes + * @clock_name: name of the clock + */ +struct scmi_clk_attribute_out { + s32 status; + u32 attributes; + char clock_name[SCMI_CLOCK_NAME_LENGTH_MAX]; +}; + /** * struct scmi_clk_state_in - Message payload for CLOCK_CONFIG_SET command * @clock_id: SCMI clock ID