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