From patchwork Wed May 12 14:54:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 435538 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4902809jao; Wed, 12 May 2021 07:55:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6Y8QEQhlgQ7mxI1Gr4/kUXT8c8KIPGNtu3+l3m9sTCbqyraYIZvaNcbVGBSXQpqIRtA2B X-Received: by 2002:a50:ce5c:: with SMTP id k28mr43698299edj.84.1620831345156; Wed, 12 May 2021 07:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620831345; cv=none; d=google.com; s=arc-20160816; b=v8FnXyoFo/tozt67+/9j5Uw5oaiRwQvIqBW1FOOPzJukIt+SHkTtzDA4+iJ7nDVnpc vaGl+YM9VFr4ez+aKqnC4OgI0C1onKCiY/blzfeA4bgAJFbL5/NJqbytyKdzoUTeioTS VKj9gJk9e8rs99Qd8fcxTWQPyCyyIf+7LwFAZLrSi1VKmuDrcOn+nQradQqAt903NDr8 rlfWdtj3w9Zlrx7T1zQksMpSXQ6+6SPCYNW8RmSvfUYBifQJav/fjJucJRfbKji872cP 2WtEnmJdMwOxoA7MqkvVWZOrCbP1MSfS7Z/FTbPN+QRL6ZWhl4koG97pC0tUwNR7cboY 5uLw== 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=BaDbgJUu2YVImVzPq6FYpnK/a5pKU7hPJE1E6bm0pDY=; b=Y6+j//HAYPFHQbT9Q+Y8whoqdQIPMRSx8AiMofGfz835QUVZV53Czk+P0Loo5GHgm6 221ULLsi29koKU7xSsg94DF4WTjL8myYWeXfcfU3SVD4T8VLlx+D0cjT1zkuAJ6kq/Mp 1eQhhfJTJBldq+cQBkvRecN05WjoZ4u+cISkVycuXMBxvK6M0rc1dOgVvWEMizzaezSq sgcNKwFXaI8JKyFzKI8WrTwc/Hc22aexoJl105hSLiDr3u1ZR7/99stHKrix3CIyZ+VI FjGaJ7poOspjNFsaqYq9g9aoa/R6r0VXhXWw7/p27qtWADnGvLjQwJrrI7GU1eTxpEPp Mm1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s5OzursS; 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 pw5si160975ejb.531.2021.05.12.07.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 07:55:45 -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=s5OzursS; 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 E8A3682CF6; Wed, 12 May 2021 16:55:41 +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="s5OzursS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D848782D52; Wed, 12 May 2021 16:55:39 +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-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 89C7E82CF6 for ; Wed, 12 May 2021 16:55:36 +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-wr1-x430.google.com with SMTP id m9so23949679wrx.3 for ; Wed, 12 May 2021 07:55:36 -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=BaDbgJUu2YVImVzPq6FYpnK/a5pKU7hPJE1E6bm0pDY=; b=s5OzursSlJai2Ph4n9JEpzD65+NMloqg8nFoeWuVjNJZvtUwRcIK9q36xeaSnfMDKi /xLvO3wdgvgrHThhk/NwSyprEsqqYFSWb/7JIFqpg0jp1jioQjzXgnpJPslFjlSdgYQm ZuYd2xjTzUDsQNp+iFeJZdwXHa8VdWi7B3pjfLD9cd28S7hi9nSVJ1ebDxscn7SCDhXm 8Agjm6UZ+W0+zlS8i8LJty+Dy6PR1vW8hJu8oTVjo6ueBmyDH6B8/21D9MWjQHKp1Mcs Wp+O46jTfvbKH4xt44hu8zX5XSvQVY88dkbK44bcXd7i8woCyheiCyCfLLkhr4+7qDqR Q0XQ== 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=BaDbgJUu2YVImVzPq6FYpnK/a5pKU7hPJE1E6bm0pDY=; b=svyGyLpPakoQFTU+ZjW4uIE2LBNCQt6KoJtptGNZje7MItOaHSDoq/sR2i9Z7Wuuxg dKXquuGImmUDlCff58XYF5+0+NL1QXgXldsTO/w+0/Prx2DvMUlsqzWtuBYXbelquXjw vq91LGwT0jIB7+ftlstEasP5rKHeGzmUFaFeBbaq0QHlgI85JqjcbF8xRnNKTljsqShg 9s/3NTkCJbx7WeBIVR6dXT6b+pa/bCp27DGXIMj9UMrJ4mffyWRj4f1pW3R4I9irHCic /MWW35P5Kc6ejJZwG733Q6cJaORsQSLybJ9tIAOJiCcK/03Xsxq0SuEADpl80hqdDOxw mlPw== X-Gm-Message-State: AOAM5315zx76MNsfQtNs7edFp37cWzdaBC3GuPrk/I7SJDD5l/GUxNBq Seb+ZdyjDU0jrVpjh0TFPDy895RaHHRgI8c+xT8= X-Received: by 2002:a5d:4a87:: with SMTP id o7mr46161501wrq.102.1620831335954; Wed, 12 May 2021 07:55:35 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058b850800452ff0effb46d5f4.ipv6.abo.wanadoo.fr. [2a01:cb05:8b85:800:452f:f0ef:fb46:d5f4]) by smtp.gmail.com with ESMTPSA id f203sm6111423wmf.20.2021.05.12.07.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 07:55:35 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Simon Glass , Patrick Delaunay , Gabriel Fernandez , Etienne Carriere Subject: [PATCH 1/2] clk: scmi: register all scmi clock by name with CCF Date: Wed, 12 May 2021 16:54:23 +0200 Message-Id: <20210512145424.13184-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 --- drivers/clk/clk_scmi.c | 101 +++++++++++++++++++++++++++++++++++++++ include/scmi_protocols.h | 43 +++++++++++++++++ 2 files changed, 144 insertions(+) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 93a4819501..2a4c10a427 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,62 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) return scmi_clk_get_rate(clk); } +static struct clk *scmi_clk_register(struct udevice *dev, const char *name) +{ + struct clk *clk; + int ret; + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk) + return ERR_PTR(-ENOMEM); + + ret = clk_register(clk, dev->driver->name, name, dev->name); + if (ret) { + kfree(clk); + return ERR_PTR(ret); + } + + return clk; +} + +static int scmi_clk_probe(struct udevice *dev) +{ + struct clk *clk; + int num_clocks; + int i; + + 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 = scmi_clk_register(dev, clock_name); + if (!IS_ERR(clk)) { + clk->id = i; + clk_request(dev, clk); + } else { + free(clock_name); + + return PTR_ERR(clk); + } + } + } + + return 0; +} + static const struct clk_ops scmi_clk_ops = { .enable = scmi_clk_enable, .disable = scmi_clk_disable, @@ -96,4 +196,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 May 12 14:54:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 435539 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4902962jao; Wed, 12 May 2021 07:55:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxBiIGmEpznWWiG/cAvT5yHqkLvrdhwkycCCdUm7UYl68Sa9YOnc0vwCu5foJC1IsCnz7K X-Received: by 2002:a17:906:b03:: with SMTP id u3mr37435440ejg.381.1620831355217; Wed, 12 May 2021 07:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620831355; cv=none; d=google.com; s=arc-20160816; b=MU/daW8JBod65O2dLvgxEZJArf7UbNjJx2dZT+s6FAy3BdKOCu96H7SNK1MEFLixWq 7PBxtTmFhAoizv0hkVD+FH8KSM3MvUruvco96Ydgcwk+FeP5hhi+ea5CE/WPO3/1C3eP BzOYyYSAA01NHe8cLZzcsD4y3tgM/gRc9+S4wcY09SFnPNlb1ARBWwDeMQCjF48y9MBv z8iRQiCamQkSBgBpKNSLOLaZx7vfFD/rBJddvqzJAQQZFvSth1Giw4kTs6Xm2BNV7SRZ P6QwtiD5JPiqDbTg3fVdO3xUh3bYIUGBBPJivSLfShtSC20CkxpWyHnXgpr4yiwOwo5q dJAQ== 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=C8mCE6JMWdUnRfD9jUXD2y1VP9mOoU3udzUHKa8t0Y0=; b=kaisQ2/Tv4UQZnhDqRX2FHfzu4jGzXDVI419Aptm3eIL6Zmm3j4Cqd1v5foeR3jMuH RRiyLd9AFAVf2eTX5dD983UGUjDgn4KEomxTFRDSpmbisiHN0MtnfMev9/2kqpUzmPXf uAbrTm3kq6IxPA4i56T4DSEcm5yRC3xWNa9tK/FjAR5uZlTYEdWbCXb+pLO4DUsjEwML reURDSSW+hWwG42nnosViEjvadJeAKB0DyJMxg79XyFpp96mHdNYI5oCLAv4crLDcrXm BK+ocnk5X5VK15a0sYiREm6TILjHk1j855t8L4HJRnRc2DttGrdEiFuzdfmmAcliCwSx YTlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n5x9ZBP/"; 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 jg13si297148ejc.80.2021.05.12.07.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 07:55:55 -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="n5x9ZBP/"; 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 B9B9C82D4F; Wed, 12 May 2021 16:55:45 +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="n5x9ZBP/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F35AA82D56; Wed, 12 May 2021 16:55:43 +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-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 2909A82D4F for ; Wed, 12 May 2021 16:55:37 +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-wr1-x429.google.com with SMTP id t18so23949992wry.1 for ; Wed, 12 May 2021 07:55:37 -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=C8mCE6JMWdUnRfD9jUXD2y1VP9mOoU3udzUHKa8t0Y0=; b=n5x9ZBP/d1V8SrQJLZHyIO4oJah2Nm3X+kWgaDaVOEjBP5I42BJWDPQk3cnHdQdMAc pfz5WJ272SA2gltewWfAmx6cZqtr7nohFRaq1ROgFHHFQ32vzDONqOxF2kE9ZKCp9Uc3 Fdxv8F/LnQ6ALhHmOMvElqYY+PY3g0jbSel16v7V3fRQcX4gNKrpB65LaoGMuDg0hlDC DFEBdYbZ3zvo3C6NFeAhjP3FOnulx1I1SoCBSyX/sVDVJo4Te9B7eXERlwPDi0DT9uIL V8UtfPhLww9yq/agMBX1S8acl0n1zo9ocTF7q18fUAajOJkswzWVFN67M6y8WLF8oH1P ZEbw== 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=C8mCE6JMWdUnRfD9jUXD2y1VP9mOoU3udzUHKa8t0Y0=; b=jKOzPleXXE0thjrt/Cnn2mJobqrJpYsS3aq5cO/Wlc8zjdaKhS2BU6a1+GKIblP4LM O4vmnETZHDNmvHO/NO4VWytDp348aYbWWhw/2T3U3LeasVy6OUYUNvknaxpWR4MhcXjd XIR1ipq4HoVY5ksoYtzrJBjcjLyxkrTMxa8kwqznJsK7oA9IwVSe5I+dOBuZNDwt2ZqH BkcdMF0gEvOxGp7q6jFcfSK150etoWz0GT4VJvrPXxBg8odvptrCWrVJUx42rwpnPRHG A1cLDxd/GMqia7jjoNPKNdJKpCqivs8LCo6mWueKJdKfs7oHgs/0GjF5K2PQSJ3KV4va 6Mxw== X-Gm-Message-State: AOAM532yn3ef7pjLaCz71mKahZF5ezeNp7mVuJLElXakX6Gp27+tUoGf cxJRxq6d8VQosQsmIYXZYuH6XtS6d54ZSAAB9BY= X-Received: by 2002:a05:6000:1866:: with SMTP id d6mr46214923wri.141.1620831336443; Wed, 12 May 2021 07:55:36 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058b850800452ff0effb46d5f4.ipv6.abo.wanadoo.fr. [2a01:cb05:8b85:800:452f:f0ef:fb46:d5f4]) by smtp.gmail.com with ESMTPSA id f203sm6111423wmf.20.2021.05.12.07.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 07:55:36 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Simon Glass , Etienne Carriere Subject: [PATCH 2/2] firmware: scmi: fix sandbox and related test since clock discovery Date: Wed, 12 May 2021 16:54:24 +0200 Message-Id: <20210512145424.13184-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210512145424.13184-1-etienne.carriere@linaro.org> References: <20210512145424.13184-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 --- 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 Reviewed-by: Simon Glass 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];