Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1492668rdb; Mon, 2 Oct 2023 11:07:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3JsMgFLPugIoIy5Ufw7Y0NTRJG3TUXiYUW+dcZX6K6EZakN+rM+zFHChRcNShnFOByEwo X-Received: by 2002:a25:ae1e:0:b0:d80:57d0:e56d with SMTP id a30-20020a25ae1e000000b00d8057d0e56dmr11496238ybj.38.1696270053164; Mon, 02 Oct 2023 11:07:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696270053; cv=none; d=google.com; s=arc-20160816; b=SEGhY8gG5YQVyDp5nnLsxxVGYKm3zuPEt5cejly/8QkvkXkOCTpJCjyRy/Ca+yz5Ew EtQ2qwYt9lmO7cD2f8hHK+lSjTypnwBu4JZMWSxcL4K/lPtRRZfxCZNqRwkux/6jVQgU kzA9qKvYr98PtIv+b+mMTZBH+6qpOM1S1wG/WXYA88+T14jIk/F+jmnQ1ZjdmxIL8O3x ywP74F5otM31O1X/Gz4csicw0mF03KXzfmSXg5/IrvYwO6Nka0r460hq+RnLqcu6rk3X mLulI2JsErAVGD9+IKHGiqr1duW5xpQtt/LpvmP5d4/+wEWs7mL6HbQinQqorXso7Lio nzDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FqVGboZHb7nl9r4RHOvhsHnumM2Y5i08pKuLsuOULgg=; fh=BBdJAghi9pm8qjpByQXMplV9mGpia5aTpr9cWuK/g1E=; b=HPDd1+bhk9u3Das5T4Ada2bbXCoNv8Aa/4mJN+/RWogG1BA6UvjEYV+o1rSBQXY6pV 51RVoFl+ItIO6EFLeyI2FnR6YUwavMB8FL1J02HM5fYgxhFlTHb7fdfAVzCrF3lmd6wb bumUSMJNBuvXSWIeEVHp1Q9h8X2aYtSbCKrAVmd00sNYF+Z85BlE3EoJgF4u5or8a5Mn wbmp9ZP5Z5Dz676Pi22jobGwVtmvVFCPLH781soWrby//T+LC24hKU6vmA+Wfv3xy69D 0R9vcqrzIt+cYhFQp5qMyks5w1KPqsqLlixm5wHmIZd9M3qYQFyl0PeyIKv2isLxnVXW shKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a193-20020a6390ca000000b005648d3f2031si8370254pge.362.2023.10.02.11.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 11:07:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4088E8049054; Mon, 2 Oct 2023 10:58:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238650AbjJBR6B (ORCPT + 99 others); Mon, 2 Oct 2023 13:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbjJBR6A (ORCPT ); Mon, 2 Oct 2023 13:58:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F65CB7; Mon, 2 Oct 2023 10:57:56 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C9281C15; Mon, 2 Oct 2023 10:58:34 -0700 (PDT) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 349313F59C; Mon, 2 Oct 2023 10:57:54 -0700 (PDT) Date: Mon, 2 Oct 2023 18:57:51 +0100 From: Cristian Marussi To: "Peng Fan (OSS)" Cc: Sudeep Holla , Michael Turquette , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Peng Fan Subject: Re: [PATCH v3 2/2] clk: scmi: add set/get_parent support Message-ID: References: <20231001-scmi-clock-v2-v3-0-898bd92d8939@nxp.com> <20231001-scmi-clock-v2-v3-2-898bd92d8939@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231001-scmi-clock-v2-v3-2-898bd92d8939@nxp.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 10:58:04 -0700 (PDT) On Sun, Oct 01, 2023 at 12:38:44PM +0800, Peng Fan (OSS) wrote: > From: Peng Fan > > SCMI v3.2 adds set/get parent clock commands, so update the clk driver > to support them. > Hi, a few notes down below. > Signed-off-by: Peng Fan > --- > drivers/clk/clk-scmi.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 49 insertions(+), 1 deletion(-) > > diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c > index 2e1337b511eb..5aaca674830f 100644 > --- a/drivers/clk/clk-scmi.c > +++ b/drivers/clk/clk-scmi.c > @@ -24,6 +24,7 @@ struct scmi_clk { > struct clk_hw hw; > const struct scmi_clock_info *info; > const struct scmi_protocol_handle *ph; > + struct clk_parent_data *parent_data; > }; > > #define to_scmi_clk(clk) container_of(clk, struct scmi_clk, hw) > @@ -78,6 +79,35 @@ static int scmi_clk_set_rate(struct clk_hw *hw, unsigned long rate, > return scmi_proto_clk_ops->rate_set(clk->ph, clk->id, rate); > } > > +static int scmi_clk_set_parent(struct clk_hw *hw, u8 parent_index) > +{ > + struct scmi_clk *clk = to_scmi_clk(hw); > + > + return scmi_proto_clk_ops->parent_set(clk->ph, clk->id, parent_index); > +} > + > +static u8 scmi_clk_get_parent(struct clk_hw *hw) > +{ > + struct scmi_clk *clk = to_scmi_clk(hw); > + u32 parent_id; > + int ret; > + > + ret = scmi_proto_clk_ops->parent_get(clk->ph, clk->id, &parent_id); > + if (ret) > + return 0; > + > + return parent_id; > +} > + While testing using CLK Debugfs with CLOCK_ALLOW_WRITE_DEBUGFS 1 I noticed that I can correctly change the clk_parent and then read back the clk_possible_parents, BUT if I read clk_parent right after boot (OR after loading the clk-scmi module) I cannot get back any value from debugfs even though I can see the correct SCMI messages being exchanged from the traces. My guess was that, while scmi_clk_set_parent is invoked by the CLK core with a parent_index that has been remapped by the core to the SCMI clock domain ID, this is not done by scmi_clk_get_parent() so you are returning to the clock framework as parent_id the raw SCMI clock domain id as returned by the platform instead of the clk parent id used by the core. This does not happen after you issue at first a reparent because in that case on the following read of clk_parent the CLK framework returns the last value you have set that it had cached previously. This fixes for me the issue: ---8<---- diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 5aaca674830f..fd47232d4021 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -89,14 +89,21 @@ static int scmi_clk_set_parent(struct clk_hw *hw, u8 parent_index) static u8 scmi_clk_get_parent(struct clk_hw *hw) { struct scmi_clk *clk = to_scmi_clk(hw); - u32 parent_id; + u32 parent_id, p_idx; int ret; ret = scmi_proto_clk_ops->parent_get(clk->ph, clk->id, &parent_id); if (ret) return 0; - return parent_id; + for (p_idx = 0; p_idx < clk->info->num_parents; p_idx++) + if (clk->parent_data[p_idx].index == parent_id) + break; + + if (p_idx == clk->info->num_parents) + return 0; + + return p_idx; } ----8<----- Not sure if there is a clever way to do it. Aside from this, another inherent issue is that you cannot really return an error from .get_parent() so if the SCMI get_parent ops should fail (ex. timeout) you return 0... (and me too in the above fix) but this is due to the CLK framework callback definition itself. Thanks, Cristian