From patchwork Wed Jun 2 09:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 452484 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp417488jao; Wed, 2 Jun 2021 02:56:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY+kRHax3nVBZqHsoRX+xUIFqDMeGge+Fwdhz3Qe6KXmIqmZIqa1z4pbhAlGca58Ms7wrd X-Received: by 2002:a17:906:cd0e:: with SMTP id oz14mr23395805ejb.308.1622627768767; Wed, 02 Jun 2021 02:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622627768; cv=none; d=google.com; s=arc-20160816; b=bpCFsA4HPNQg2jymQOpU/TkguwjXcwsZpCn76bxQcaxHyBAi1gbiDEWbMhnachcj0n 8AQj2pDdkz9y40oO88Y0StyMIxv0bo9NXWE0wpbSAQosoq/uermyD7addaEEzPwrPDNq Gtmn+xGMFL+G/0J2/+Z5vMawaIZmHltWucwzid8G8cJDsCGkeIaNpAOzv+MJCxofPIzq p52qecJrUaQDyhkP9QxaMFTZVzvYdkBWLyhAS2gL0NGdoHwTNLUnKC693tBYT5dL7FlS cZKdg5ESqMCyNDB2dsn86tg5/VYvKT8DAeZ4KnTDuWz2xhM4JP+P7HK5H7HJ1XI+Jsja lHvA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=8S9JaCMjNlvrij1g/8DJO28KlOVss3RIwlmd40k9cXo=; b=RJCyw9rBLU51GvhLTgjncx0DthqpSrYBsZNSKf+AA3YeTO7cVkLwvKjnWkrK7SB/K1 BoBF9HrlYtVyjRF8jBGdCFltvLAG3xO9WRkdBm4JjXxH5vETXkXq53T6yTTxB4Wan/uo yMcxQ03FHFzmUQ25Dr5QkA4S5Y2KpuzgSj2mEWkKL1SpznKxiDr3iy8jyoqpQEdsJm2p sFMBeiv5mPCpCQ/pxZubTz5AzHEbrmyRQm+ySUBkdMPEX0sEaNQJuLES+lpRmK2R1CC0 1alfTuHqpxDidOMb6xW6vG9dkelvGTTwncYvobo9ncg8MY49p4YeVNU3X56eylGz2Qyv ntmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dvSKqwv8; 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 m21si2797045ejl.33.2021.06.02.02.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:08 -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=dvSKqwv8; 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 85BA482F0B; Wed, 2 Jun 2021 11:56:06 +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="dvSKqwv8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 335C282F10; Wed, 2 Jun 2021 11:56:05 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 E8EEC82F0B for ; Wed, 2 Jun 2021 11:56:00 +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-x331.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso3374904wmh.4 for ; Wed, 02 Jun 2021 02:56:00 -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; bh=8S9JaCMjNlvrij1g/8DJO28KlOVss3RIwlmd40k9cXo=; b=dvSKqwv89DnCMd9MIjqdQNvi2BVzwyGr226uqlcxUQbOLIViMTZL5ZytFobB5M6LQi skkg3RyiPRqYZTQAe10VotkrSSjuQCNObOAp8tadtXduhVmHjZXlbPST5JOmTPpe3sOk OZyJR8Fnw7DbGzsPWjCzeMoHmkhUiw5+e1qExyLlcqdq2SvPWFfq7bt35TAdQ5ESAIT3 IxcY0rgsiQ7rtMorQC97e4dS86MTwa+rY9dwmziF5emybavADXrTsTVtRYL41pB76UfJ AC0AzGB0NZC1PLHmkW3EsbBjuBRHO39zfKPC9d578KTokQkQVUTy4UnpqAC1YZGWue1+ CKqA== 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; bh=8S9JaCMjNlvrij1g/8DJO28KlOVss3RIwlmd40k9cXo=; b=ZMYb4GLQBsnvWwJ4NtzcspJbs9/KWQfN3FdoN/BH1GRjux+EGURTqw4AztM6e+9X2/ J2tPgZYBnvLQdDTM4lDdZ6W8iIgwgXjNWylV+L3PQBhDu2dFgTiZ+Jzzbfz9Jqsku9OH 2f1QSY1YkfPaQDwBqKx+xaIOssx1OrtdhVTpcFhtg+bZdaoxwYMprJ8ybPYiLEn8lXTd Cf9HHdZhE4hfgaCZBBa49QbIQ1Msv0ifUuoDg70utmSCiLpcXotwvMH+Va+IocAa94uV F2Y5Jw6qXDdyA8VQZW9Hv2fSYjqwDfUA4dIKC2VY7lwrfOIFlTh6sZG23GwbSNKgiXdK FmJw== X-Gm-Message-State: AOAM533FXkObTdEO0ZGagdWgOUK8PuemWgJman0X+2anEu9Wd1WQHAZE LgZoPxEoVrNV2rKfL3IqD3MsFn3DRK5AymjJ X-Received: by 2002:a05:600c:3393:: with SMTP id o19mr4315383wmp.163.1622627760368; Wed, 02 Jun 2021 02:56:00 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:119f:e0e8:4829:7bc2:a82a:1daf]) by smtp.gmail.com with ESMTPSA id m23sm2581549wml.27.2021.06.02.02.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:00 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Simon Glass , Patrick Delaunay , Gabriel Fernandez , Etienne Carriere Subject: [PATCH v2 1/2] clk: scmi: register all scmi clock by name with CCF Date: Wed, 2 Jun 2021 11:54:45 +0200 Message-Id: <20210602095446.21947-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 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.4 at phobos.denx.de X-Virus-Status: Clean From: Patrick Delaunay This patch implements SCMI APIs to retrieve the number and the name of SCMI clocks using SCMI_PROTOCOL_ATTRIBUTES messages. Signed-off-by: Gabriel Fernandez Signed-off-by: Patrick Delaunay Signed-off-by: Etienne Carriere --- Changes since v1: - remove use of ERR_PTR() adn friends --- drivers/clk/clk_scmi.c | 89 ++++++++++++++++++++++++++++++++++++++++ include/scmi_protocols.h | 43 +++++++++++++++++++ 2 files changed, 132 insertions(+) -- 2.17.1 diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 93a4819501..62c85b1c6e 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -8,6 +8,50 @@ #include #include #include +#include + +static u16 scmi_clk_get_num_clock(struct udevice *dev) +{ + 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->parent, &msg); + if (ret) + return ret; + + return out.attributes & SCMI_CLK_PROTO_ATTR_COUNT_MASK; +} + +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->parent, &msg); + if (ret) + return ret; + + *name = out.clock_name; + + return 0; +} static int scmi_clk_gate(struct clk *clk, int enable) { @@ -85,6 +129,50 @@ 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; + int num_clocks; + int i, 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; + + num_clocks = scmi_clk_get_num_clock(dev); + if (!num_clocks) + return 0; + + 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->id = i; + clk_request(dev, clk); + } + } + + return 0; +} + static const struct clk_ops scmi_clk_ops = { .enable = scmi_clk_enable, .disable = scmi_clk_disable, @@ -96,4 +184,5 @@ U_BOOT_DRIVER(scmi_clock) = { .name = "scmi_clk", .id = UCLASS_CLK, .ops = &scmi_clk_ops, + .probe = &scmi_clk_probe, }; diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index 2db71697e8..3fc8ec95ef 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 From patchwork Wed Jun 2 09:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 452485 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp417580jao; Wed, 2 Jun 2021 02:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBJEvr8bZkBDl3vMuYKNCK/4l31heCRvS1qMJu4TxH406TYLAEy2GKsPnZtEFGi1o1gsIr X-Received: by 2002:a05:6402:2789:: with SMTP id b9mr37735144ede.122.1622627777157; Wed, 02 Jun 2021 02:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622627777; cv=none; d=google.com; s=arc-20160816; b=bHL5SGzBGshUbcN1GRgUEqeyxh1KpLb2VzGOL+JErJrCCW3RvFEX5RDDvmeMDDDhy3 X1cX1OHmkIQwJ5NbQq7nuQDrLbK9qXrA3NjzXxgAIxj/JcspKgj2DZzQbarcv9limxPy mSvbSgWzafAhbcfDjGazLZUTpk+JZAu+IaW/ygGbA4WX78j4XgTutn9Y9Bw4B2vZ5cPl W8lOo3CikcAXcxXL+zHxcBLQDuYVCzh7l8GUN8ybYbuBsohPCD4dheYXk21PMjUDsbUe R9ihNKaE7zNyGSAAYrxbhtv7L6BoJBOc8JGJd7rOqOLXAkcsVbkD00dY+aUpIaXvF8Ld mfeQ== 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=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=jCpsWVaYz3wFBwyPazDwLv27RWORYE/qTqg3ZNFICRTVHUL3oAHwYirTcAsmRrUj2l 4mlr4opPaKOc4jVtOWyIqeIiKfnGGCle75LtZL9LNnKUfFtjeWSTdUHOyfoJ1vYcoicv RXE1NkuA4EaOrR+g8vuAF7BCVIbZvqHNrI81w4J1ss5ctgj/bvEa7yfO/lvOAJq2pDb/ XJSn7eWEXpuH2BTooeeTuA5s1NvvLb7FzUfO80EP5qTkxaKmdpF8eoDEyz8peLIxkxmZ qCRqhOQV3oniHCintphv2Sj9oRpQ/0rdGxHBp9T4SOdBpbOybdYPxkvJaR9Iuz0mHhVs EmFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9yqjdG+; 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 a27si1920204edm.396.2021.06.02.02.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:17 -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=C9yqjdG+; 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 6C18282F15; Wed, 2 Jun 2021 11:56:11 +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="C9yqjdG+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 335C982ED6; Wed, 2 Jun 2021 11:56:10 +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 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 BB2F282F0C for ; Wed, 2 Jun 2021 11:56:01 +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-x332.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso3374930wmh.4 for ; Wed, 02 Jun 2021 02:56:01 -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=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=C9yqjdG++Y5R1+TcGcgVn2o293qcyjDS9w5b6KCSHT7tDXha1gsBTnq1/H03Pm8VtC tr2X+GjkZ6vICycDwELX2jOGmETpEwDpSf8rbBY1iAJPRmh91GL2++Sz04sR4IAwOmpl bO+Ylsn1If+5d36P0VVg8+vSjC1YyyGk6TjHs97gj0mKqlxxBJ9lkAziv+gtDVzj7X2I CQcSHM+HrXNMgugT6tpEyITjD5A3d1TR4QE3BChY2pZycDRAQK8YvcjhdrBP4s3fY3Nt LS4ceCWJpjyurHUgcJ1/YZ3ahaSQAebwhDizR7GN9dccrmY26oEyVzEkwt3dtSeY8lCZ bYLQ== 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=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=TyGmM078xrcCN+L+J9OPqHXG5kv2FOmwxWeXa6w2qltPFvt8/Ri36TA1SLZgjCZfYP /uAFDhVosADtnUEC/g3mWU9qtS+uYneWbWImzq00YL/+szOM1vxteSuuFZKHjvvZXY7N aIWQQYhfZUDFte5qtAVXHOLCKVkfT2XfS2d1tBJ+GIlk+rwe4WT0FWWlRR0t66CP/cCe rUEjhgowyeXSbirUUSeACBLf7vbifLQ7kFBcyzKZygQe1R72yHdsD0vL1WygpqYl8MJY c9OJ3XvRgroVJRFKhcE6Ipb7m7U+mjMOUAO4xAHAxySg3IKSPESFlrgnH0Ax7My6jO8y 3WIg== X-Gm-Message-State: AOAM533citgmZS3e5lpTNI/A2qSdOUYpOSP970xr258K/tZIrLp0N1eH ntghmITrLBGh2cdsvbZHXjS1fovgWtfphD2R X-Received: by 2002:a05:600c:2948:: with SMTP id n8mr4277251wmd.95.1622627761174; Wed, 02 Jun 2021 02:56:01 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:119f:e0e8:4829:7bc2:a82a:1daf]) by smtp.gmail.com with ESMTPSA id m23sm2581549wml.27.2021.06.02.02.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:00 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Simon Glass , Etienne Carriere Subject: [PATCH v2 2/2] firmware: scmi: fix sandbox and related test since clock discovery Date: Wed, 2 Jun 2021 11:54:46 +0200 Message-Id: <20210602095446.21947-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602095446.21947-1-etienne.carriere@linaro.org> References: <20210602095446.21947-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.4 at phobos.denx.de X-Virus-Status: Clean Since SCMI clock are discovered because of integration in the CCF, update SCMI emulation in sandbox accordingly. Sandbox must emulate all clocks exposed by SCMI server since CCF clock discovery will query all of them even if some clocks have no consumer. This change adds clock discovery support in the sandbox and changes clock IDs so that less clock shall be managed as each SCMI clock ID is actually an index identifier. For consistency, update also sandbox SCMI reset controller test to conform with the IDs being also indices of exposed resources as per SCMI specification. Signed-off-by: Etienne Carriere Reviewed-by: Simon Glass --- Changes since v1: - Review tag applied --- arch/sandbox/dts/test.dts | 4 +- arch/sandbox/include/asm/scmi_test.h | 2 - drivers/firmware/scmi/sandbox-scmi_agent.c | 102 ++++++++++++++++++--- test/dm/scmi.c | 29 ++++-- 4 files changed, 113 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index fe26ced31d..91e488239b 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1346,8 +1346,8 @@ sandbox_scmi { compatible = "sandbox,scmi-devices"; - clocks = <&clk_scmi0 7>, <&clk_scmi0 3>, <&clk_scmi1 1>; - resets = <&reset_scmi0 3>; + clocks = <&clk_scmi0 2>, <&clk_scmi0 0>, <&clk_scmi1 0>; + resets = <&reset_scmi0 0>; regul0-supply = <®ul0_scmi0>; regul1-supply = <®ul1_scmi0>; }; diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index 2930e686d7..bce18deeea 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -17,7 +17,6 @@ struct sandbox_scmi_service; * @rate: Clock rate in Hertz */ struct sandbox_scmi_clk { - uint id; bool enabled; ulong rate; }; @@ -28,7 +27,6 @@ struct sandbox_scmi_clk { * @asserted: Reset control state: true if asserted, false if desasserted */ struct sandbox_scmi_reset { - uint id; bool asserted; }; diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index 4b968205c2..dee9e8fb58 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -27,7 +27,7 @@ * See IDs in scmi0_clk[]/scmi0_reset[] and "sandbox-scmi-agent@0" in test.dts. * * Agent #1 simulates 1 clock. - * See IDs in scmi1_clk[] and "sandbox-scmi-agent@1" in test.dts. + * See scmi1_clk[] and "sandbox-scmi-agent@1" in test.dts. * * All clocks and regulators are default disabled and reset controller down. * @@ -40,12 +40,13 @@ #define SANDBOX_SCMI_AGENT_COUNT 2 static struct sandbox_scmi_clk scmi0_clk[] = { - { .id = 7, .rate = 1000 }, - { .id = 3, .rate = 333 }, + { .rate = 333 }, + { .rate = 200 }, + { .rate = 1000 }, }; static struct sandbox_scmi_reset scmi0_reset[] = { - { .id = 3 }, + { .asserted = false }, }; static struct sandbox_scmi_voltd scmi0_voltd[] = { @@ -54,7 +55,7 @@ static struct sandbox_scmi_voltd scmi0_voltd[] = { }; static struct sandbox_scmi_clk scmi1_clk[] = { - { .id = 1, .rate = 44 }, + { .rate = 44 }, }; /* The list saves to simulted end devices references for test purpose */ @@ -102,7 +103,6 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) { struct sandbox_scmi_clk *target = NULL; size_t target_count = 0; - size_t n; switch (agent_id) { case 0: @@ -117,9 +117,8 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) return NULL; } - for (n = 0; n < target_count; n++) - if (target[n].id == clock_id) - return target + n; + if (clock_id < target_count) + return target + clock_id; return NULL; } @@ -127,14 +126,21 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) static struct sandbox_scmi_reset *get_scmi_reset_state(uint agent_id, uint reset_id) { - size_t n; + struct sandbox_scmi_reset *target = NULL; + size_t target_count = 0; - if (agent_id == 0) { - for (n = 0; n < ARRAY_SIZE(scmi0_reset); n++) - if (scmi0_reset[n].id == reset_id) - return scmi0_reset + n; + switch (agent_id) { + case 0: + target = scmi0_reset; + target_count = ARRAY_SIZE(scmi0_reset); + break; + default: + return NULL; } + if (reset_id < target_count) + return target + reset_id; + return NULL; } @@ -156,6 +162,70 @@ static struct sandbox_scmi_voltd *get_scmi_voltd_state(uint agent_id, * Sandbox SCMI agent ops */ +static int sandbox_scmi_clock_protocol_attribs(struct udevice *dev, + struct scmi_msg *msg) +{ + struct sandbox_scmi_agent *agent = dev_get_priv(dev); + 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; + + switch (agent->idx) { + case 0: + out->attributes = ARRAY_SIZE(scmi0_clk); + out->status = SCMI_SUCCESS; + break; + case 1: + out->attributes = ARRAY_SIZE(scmi1_clk); + out->status = SCMI_SUCCESS; + break; + default: + out->status = SCMI_INVALID_PARAMETERS; + break; + } + + return 0; +} + +static int sandbox_scmi_clock_attribs(struct udevice *dev, struct scmi_msg *msg) +{ + struct sandbox_scmi_agent *agent = dev_get_priv(dev); + 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(agent->idx, 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) { @@ -479,6 +549,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/test/dm/scmi.c b/test/dm/scmi.c index c938e6d4fc..7d0a6799b7 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -58,7 +58,7 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, ut_asserteq(2, scmi_ctx->agent_count); ut_assertnonnull(agent0); - ut_asserteq(2, agent0->clk_count); + ut_asserteq(3, agent0->clk_count); ut_assertnonnull(agent0->clk); ut_asserteq(1, agent0->reset_count); ut_assertnonnull(agent0->reset); @@ -128,6 +128,15 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) if (ret) return ret; + /* + * As stated in sandbox test.dts: + * - Sandbox device clock #0 relates to SCMI server #0 clock #2 + * - Sandbox device clock #1 relates to SCMI server #0 clock #0 + * - Sandbox device clock #2 relates to SCMI server #1 clock #0 + * + * Note there exists a SCMI server #0 clock #1 but is it not + * used but the sandbox test device. + */ scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); agent0 = scmi_ctx->agent[0]; @@ -141,8 +150,9 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); ut_assert(!ret_dev || ret_dev == 1088); - ut_asserteq(1000, agent0->clk[0].rate); - ut_asserteq(1088, agent0->clk[1].rate); + ut_asserteq(1088, agent0->clk[0].rate); + ut_asserteq(200, agent0->clk[1].rate); + ut_asserteq(1000, agent0->clk[2 ].rate); ut_asserteq(44, agent1->clk[0].rate); ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); @@ -156,20 +166,23 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) /* Test SCMI clocks gating manipulation */ ut_assert(!agent0->clk[0].enabled); ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent0->clk[2].enabled); ut_assert(!agent1->clk[0].enabled); - ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); + ut_asserteq(0, clk_enable(&scmi_devices->clk[0])); ut_asserteq(0, clk_enable(&scmi_devices->clk[2])); ut_assert(!agent0->clk[0].enabled); - ut_assert(agent0->clk[1].enabled); + ut_assert(!agent0->clk[1].enabled); + ut_assert(agent0->clk[2].enabled); ut_assert(agent1->clk[0].enabled); - ut_assertok(clk_disable(&scmi_devices->clk[1])); + ut_assertok(clk_disable(&scmi_devices->clk[0])); ut_assertok(clk_disable(&scmi_devices->clk[2])); ut_assert(!agent0->clk[0].enabled); ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent0->clk[2].enabled); ut_assert(!agent1->clk[0].enabled); return release_sandbox_scmi_test_devices(uts, dev); @@ -188,6 +201,10 @@ static int dm_test_scmi_resets(struct unit_test_state *uts) if (ret) return ret; + /* + * As stated in sandbox test.dts: + * - Sandbox device reset ctrl #0 relates to SCMI #0 reset domain #0 + */ scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); agent0 = scmi_ctx->agent[0];