From patchwork Mon Feb 21 08:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 544400 Delivered-To: patch@linaro.org Received: by 2002:ac0:e142:0:0:0:0:0 with SMTP id r2csp3063504imn; Mon, 21 Feb 2022 00:23:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUd64IIEBDmKJ4GMn2lPu+Rrub8Hh3lVLiGYN3th1fE0off+hO9ZuNGyGFsLuulkCHINSa X-Received: by 2002:a05:6402:3508:b0:403:ba8f:4265 with SMTP id b8-20020a056402350800b00403ba8f4265mr19812816edd.184.1645431792887; Mon, 21 Feb 2022 00:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645431792; cv=none; d=google.com; s=arc-20160816; b=xf4AKL5/NoYp2ajojFGcC3UYtPlJ55FtGIQkQjcMjfEeW7D/6Qvh6MfE3W68Z+BbB+ P5rFRLMUDrgzH1aeKZnuplwiBkH9auNNrtb+GFTEakpJBGVjgfnPwgbgvjdAh1rBptpW kftk3jn5Q5L/fR2+qBgvqJ37V7n3m5gEVb9Y12labJUemjfJKBYYLnLeI7679lsYP0q2 3DYLlx+d3DZI5EriAvdOwKQdXYXvjIMl0rr6luKys34FcCSlsf095zeOTYk4vWMz4CO6 stVFjx/Bwv/uLVT5Qut4h1Yoe+DvcZKtJr1y371GoR0UFonQRh3XPERbGCqhAkBs5zBT fzjQ== 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=jyOGqf5K1MbhPmjsVZe4/5aj4EdknzssXPJCmpD4zCg=; b=ES9pEADNv+nc16wfZWKoo2L0FsnMJlm+G1X5FdcIcJsxUM+cF56PjGdyJgR43sVM6R AwRl+d2cAi+NPgbhqUo7ZU6o4ljBczKFpXCfE0rFJt8BQzKEElDfB3gnwGF9NGIUgZCE tMkMMdPVyOGF/SkLGgVH3ghrDNz36c3MFF7bmlJwMSYEgwcolgxCeRFFWzsfmV3Ck8DN XrkI8GiLbC3f4GFHx392JPmqVQ2SwprcR6xSPrC59OkyWJNAvOSyHtvwXRb6PPeO43bb +hVpk0ZkJLGDUqSdbv+4symm1MNHU+/8q3wgGsoguYvj+ySXySJmI81MJvXe6pLNhsuA Y8Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lwoLrUjH; 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 hw8si9005236ejc.598.2022.02.21.00.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 00:23:12 -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=lwoLrUjH; 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 BD3C783BFD; Mon, 21 Feb 2022 09:22:59 +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="lwoLrUjH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B4A083C20; Mon, 21 Feb 2022 09:22:55 +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-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 51B3D83C02 for ; Mon, 21 Feb 2022 09:22:47 +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-x329.google.com with SMTP id n8so9011717wms.3 for ; Mon, 21 Feb 2022 00:22:47 -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=jyOGqf5K1MbhPmjsVZe4/5aj4EdknzssXPJCmpD4zCg=; b=lwoLrUjHFRzXL2ehCxiXWAUMZr53o3QhTvQwIwYs57AGwbgLMKjFNAoBNosN6Dpt/S aFZ6cdm0YtXuS1fT7XReOsNMhE9snUJ68bkkHoEqoOVVdaZvkoOzP8DpxQ4jbOj4NSZq O8MI9NyoBxW7TnmpJXidzC5hAeUtoECFgjxf6MNqQmgSxWQYMy5gVMcZIqa1mtImrr4I /Y8MYvjT63iPhkClXG2eQS99wA77E3F8w5thkXEgsrnXMAN0m/9N74tqCSaFVtJbwtKE KIm47nDhp22ubkkUQQbT7WDLQhyAKJx4i5y3KcN6zGfpQsAw2qtXsRRKNg0oIBNuJAjo LWuw== 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=jyOGqf5K1MbhPmjsVZe4/5aj4EdknzssXPJCmpD4zCg=; b=27q3lHSSgZ7/9M17I2Dy6MW83dUtWIAAlN6DoC7d1HW3HzMlI7ROepexojkwLbgZg8 XQ0eS0RoEdtqUjhb0VRkktfMochwsP0GQQRQxeobvxNuaoAKbwIX6jex5F6wNRVPdqvK vqtkcmdflINnOocEYiZT45nb8qKQpKmWsgz+BVWbQDkY2cembv5quIDa/W+y7kPSAdm1 tWb9QcCVQN0ksmgHZhZhUVFYtuvg8STLpGWq0bHVzI9S++fFEvIcJsW5Q/CONhzkM/du D+snu5Er8+NHekckSw39aGgJqcO5DEAQ3tMcqSbCJoytNSSok1B0sdF+5KzZUykgOBxq GJUg== X-Gm-Message-State: AOAM530WWmyZELhQkjaHG04VloVtfHtbXRLS/K7+gA2AKj167gFb4tOg voSOrfCG3URATjiemVb3qWU4+2eUx3UxhuSI X-Received: by 2002:a05:600c:3d06:b0:37b:a5ea:a61b with SMTP id bh6-20020a05600c3d0600b0037ba5eaa61bmr16914016wmb.32.1645431766685; Mon, 21 Feb 2022 00:22:46 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 00:22:46 -0800 (PST) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Patrick Delaunay , Etienne Carriere , Lukasz Majewski , Sean Anderson , Jaehoon Chung Subject: [PATCH v2 3/5] scmi: change parameter dev in devm_scmi_process_msg Date: Mon, 21 Feb 2022 09:22:40 +0100 Message-Id: <20220221082242.6349-3-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 Changes devm_scmi_process_msg() first argument from target parent device to current SCMI device and lookup the SCMI agent device among SCMI device parents for find the SCMI agent operator needed for communication with the firmware. This change is needed in order to support CCF in clk_scmi driver unless what CCF will fail to find the right udevice related to exposed SCMI clocks. This patch allows to simplify the caller sequence, using SCMI device reference as parameter instead of knowing SCMI uclass topology. This change also adds some protection in case devm_scmi_process_msg() API function is called for an invalid device type. Cc: Lukasz Majewski Cc: Sean Anderson Cc: Jaehoon Chung Cc: Patrick Delaunay Reviewed-by: Patrick Delaunay Signed-off-by: Etienne Carriere --- Changes since v1: - Apply R-b tag. --- drivers/clk/clk_scmi.c | 6 +++--- drivers/firmware/scmi/scmi_agent-uclass.c | 17 +++++++++++++++-- drivers/power/regulator/scmi_regulator.c | 10 +++++----- drivers/reset/reset-scmi.c | 4 ++-- include/scmi_agent.h | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 9a0a6f6643..42fbab0d21 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -24,7 +24,7 @@ static int scmi_clk_gate(struct clk *clk, int enable) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev->parent, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret) return ret; @@ -52,7 +52,7 @@ static ulong scmi_clk_get_rate(struct clk *clk) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev->parent, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret < 0) return ret; @@ -77,7 +77,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev->parent, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret < 0) return ret; diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 4f5870b483..3819f2fa99 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -116,10 +116,23 @@ static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev) int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) { - const struct scmi_agent_ops *ops = transport_dev_ops(dev); + const struct scmi_agent_ops *ops; + struct udevice *parent = dev; + + /* Find related SCMI agent device */ + do { + parent = dev_get_parent(parent); + } while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT); + + if (!parent) { + dev_err(dev, "Invalid SCMI device, agent not found\n"); + return -ENODEV; + } + + ops = transport_dev_ops(parent); if (ops->process_msg) - return ops->process_msg(dev, msg); + return ops->process_msg(parent, msg); return -EPROTONOSUPPORT; } diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c index 3ddeaf4adc..2966bdcf83 100644 --- a/drivers/power/regulator/scmi_regulator.c +++ b/drivers/power/regulator/scmi_regulator.c @@ -38,7 +38,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable) in, out); int ret; - ret = devm_scmi_process_msg(dev->parent->parent, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret) return ret; @@ -61,7 +61,7 @@ static int scmi_voltd_get_enable(struct udevice *dev) in, out); int ret; - ret = devm_scmi_process_msg(dev->parent->parent, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -85,7 +85,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV) in, out); int ret; - ret = devm_scmi_process_msg(dev->parent->parent, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -104,7 +104,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev) in, out); int ret; - ret = devm_scmi_process_msg(dev->parent->parent, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -147,7 +147,7 @@ static int scmi_regulator_probe(struct udevice *dev) /* Check voltage domain is known from SCMI server */ in.domain_id = pdata->domain_id; - ret = devm_scmi_process_msg(dev->parent->parent, &scmi_msg); + ret = devm_scmi_process_msg(dev, &scmi_msg); if (ret) { dev_err(dev, "Failed to query voltage domain %u: %d\n", pdata->domain_id, ret); diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c index ca0135a420..850cb18886 100644 --- a/drivers/reset/reset-scmi.c +++ b/drivers/reset/reset-scmi.c @@ -26,7 +26,7 @@ static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert) in, out); int ret; - ret = devm_scmi_process_msg(rst->dev->parent, &msg); + ret = devm_scmi_process_msg(rst->dev, &msg); if (ret) return ret; @@ -58,7 +58,7 @@ static int scmi_reset_request(struct reset_ctl *rst) * We don't really care about the attribute, just check * the reset domain exists. */ - ret = devm_scmi_process_msg(rst->dev->parent, &msg); + ret = devm_scmi_process_msg(rst->dev, &msg); if (ret) return ret; diff --git a/include/scmi_agent.h b/include/scmi_agent.h index 5015c06be9..18bcd48a9d 100644 --- a/include/scmi_agent.h +++ b/include/scmi_agent.h @@ -51,7 +51,7 @@ struct scmi_msg { * Caller sets scmi_msg::out_msg_sz to the output message buffer size. * On return, scmi_msg::out_msg_sz stores the response payload size. * - * @dev: SCMI agent device + * @dev: SCMI device * @msg: Message structure reference * Return: 0 on success and a negative errno on failure */