From patchwork Fri Feb 11 12:07:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 541784 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp3020586imo; Fri, 11 Feb 2022 04:08:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfESFyDRrD+RaCVu5Eo5q9J2XkgNEVusiAaDlv0MyJqqjFWIQRGRQyDnwhaBT30pXWNkpP X-Received: by 2002:a17:907:96aa:: with SMTP id hd42mr1147240ejc.74.1644581303297; Fri, 11 Feb 2022 04:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644581303; cv=none; d=google.com; s=arc-20160816; b=QG88K/GB/Z2FpxrUXRSBhniWaXUQeoDF51LzCJQSo1zryx1cdWH2dOjfOh0BU65awV YsGpW3mw6xV/T1xMifL//W5BN2roVOQ/bHEZEn7328a8xHWf/ONK3PSAa/GqkXIundqo ikuLRCA9nh2AetaejODAfESIRVWY85ulANbdgNLVPSkMb3b/ZnRSYoe62YosyHQ+bgz8 jY1FPEsAJdtTIwV7rNGgm1qx0N+BIhhK9ZrE+q0jTujdug9QcV+P2afFrKAEZ3QCI6SD C2AQ6awGLfiCwOsyFq1g/qUiKtgRfdaYmSK9SJkbKHFQ80jHhxvwtCUdSCLzv5eAX2JD wffg== 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=LdfPKdSBWAqxiDBp5mxS3QHtOjKwKS0/nPK0ey8HkEs=; b=bgeZYvjwUcnIgJj56Z3E7a5cCAtJRrfz1RJpvT4MeFgseZFjyttOM1S4tx+j/Aehsc DoeF19svmhhyEDrXoGjm5/10W95UCh6T5Mp4PHSND2g2Nok0mczlK+2hdCfR6O4DOiun ZPW5PQYgvjwB0tlztuOLzTtkrANn7i4P3y8NIjO+eq8KvwwgjKDbT6rWB9wxhzcjFdjd f90hdgRn8sjRY8N7JCLVDF4ikumMRfqPRqkE+79eMeH+2GhhAdiRYmYl4f0ZqErQ8n41 hn/oYombxOwMJUwx0/kSRKysNb7IveKAlXqc43D16cmJHoDrK0BtJdUicKKftvtH1w09 nIDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oY51HRMt; 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 qa11si10227360ejc.415.2022.02.11.04.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 04:08:23 -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=oY51HRMt; 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 13D1683A8C; Fri, 11 Feb 2022 13:07:53 +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="oY51HRMt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AB2D83A66; Fri, 11 Feb 2022 13:07:49 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 D984483A8C for ; Fri, 11 Feb 2022 13:07:42 +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-x332.google.com with SMTP id m126-20020a1ca384000000b0037bb8e379feso7107275wme.5 for ; Fri, 11 Feb 2022 04:07:42 -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=LdfPKdSBWAqxiDBp5mxS3QHtOjKwKS0/nPK0ey8HkEs=; b=oY51HRMtwhv/dcx+cZ4NW30+oGDs0erHHtOBlGZPVh+hxUs+9JoDKGc8Q2G0RcyhQG yytcjSKpHAOB1/+TTGy6iRSJOURTK939s68I9G4B2AZeNytlSeHFg9Myn985GjB2fiSj vR5FG4fxfn4vqS7Biwh0OiE2JJ7KSQUxpubSzuSwWpjhoAgP6XaisJmIwLqyBMkbdxoq LoieX/Q86JOOVtKaarb1hGTJmfmmPFwE88n5i4Csgrb3erzhjAGgQEP7ykRx4dAybXUJ iIpl8eUlkDGUPkeHctNUo/JiYOkpXR6lC5P+pwYYYa/H/xX1qJg+aUMeBLuxwTLerHTA LMaw== 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=LdfPKdSBWAqxiDBp5mxS3QHtOjKwKS0/nPK0ey8HkEs=; b=T4cU75E8IzVKNtn/GV4n7sEX6MXJFgM0f5hvqjb9uulRu93u7DM/pZjZ+LjY2vuJyK ujhOnxp+AGtN9JaDqtW59t+ZeIIip0OU/snR6qpOG6ASY0D484HTKt4gd3hKTW6KEBop +GQOt198McOIi64uXaCKWDtuO/4ZKVkOICR7fyouSDOw31swjJZyCxK0CEiPOldMJGea 5HoyONULMTo6GrYkxw2b9+BL/RknwHAUAUxAk7rTuLyQucsWcHZrqy0c9KAfuiHQUop0 4gHyEMfo+SbdQ+RCF+tU5m30Kn6y1pzQHAWnCJiGMI1LqXbuDvQZl5NzpKqrAOsSDN4o InCw== X-Gm-Message-State: AOAM531Nlmi/HdooAOGs9kSrHmhdf48JcdNn1wHGWgK2dAA++cd/Hg0Q U3SvU6pSu3WrTjWYk0TTmDN9WfcuStQ5mA== X-Received: by 2002:a05:600c:4f53:: with SMTP id m19mr29219wmq.45.1644581262282; Fri, 11 Feb 2022 04:07:42 -0800 (PST) Received: from lmecxl0524.lme.st.com ([2a04:cec0:1057:737f:9927:5b5d:6280:5a68]) by smtp.gmail.com with ESMTPSA id u14sm4964439wmq.41.2022.02.11.04.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 04:07:41 -0800 (PST) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Lukasz Majewski , Sean Anderson , Clement Leger , Patrick Delaunay , Gabriel Fernandez Subject: [PATCH 5/5] clk: scmi: register scmi clocks with CCF Date: Fri, 11 Feb 2022 13:07:25 +0100 Message-Id: <20220211120725.25358-5-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220211120725.25358-1-etienne.carriere@linaro.org> References: <20220211120725.25358-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. Series-links: 246809 Cc: Lukasz Majewski Cc: Sean Anderson Cc: Clement Leger Cc: Patrick Delaunay Signed-off-by: Gabriel Fernandez Signed-off-by: Etienne Carriere Reviewed-by: Patrick Delaunay --- 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 562fe53168..25e90b721b 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