From patchwork Fri Mar 8 00:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 778763 Delivered-To: patch@linaro.org Received: by 2002:a5d:604e:0:b0:33e:7753:30bd with SMTP id j14csp12005wrt; Thu, 7 Mar 2024 16:04:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWTiPRvHt2Y0z9nJwBOpNdRC18UGPF/mMiiKllty1VlaFEZkGur9MBb4CwnODKl4rzjOW+zQ2QPC8WfpPimCvd9 X-Google-Smtp-Source: AGHT+IFlcnNAylJzkWqj+TMeK7gAWHCICNICxG9SJ8srfYCK9bACg3hI1oYvwAO/u6sohEEX5dHa X-Received: by 2002:adf:f350:0:b0:33e:592c:d7e5 with SMTP id e16-20020adff350000000b0033e592cd7e5mr4377608wrp.31.1709856282934; Thu, 07 Mar 2024 16:04:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709856282; cv=none; d=google.com; s=arc-20160816; b=0FuwmL3yzdMY//Gmnhnknf3P5JqJiSWv6ZxdCIJ1213SOYuc6BF5QzI4q/GP9fB+lw IjXWbCWweG783aKn6/SXnTthoDnOuSHC87RyArhs9HeuzjgsnEb/vtE9mMju+rW+5slV Hs5VqkK8Yt5tKELOXvNTOVMpj1sjghz/OwOZoYIhLDz4FCXhX7VT5w6hA2mw9OdpshEV WDys1w4+B3BxKzfxwsm8ZZwY2OKa72EKYhxruYmbHfcMZCQQvbNuXKKZ24KqYyMjNG31 AkNny6wFOj/Q+PYph8TF6H9joBiqA9WNTokbNlwTWgD9tvKdsrigmOw3aTX0PbcEGWbT ZYiw== 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:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=8WpmdhQC3KMXqD/OnNVkffYCf1720asOXYrEz50/bNM=; fh=L0XVp+PHAin/anklqISun2383g9IAHryAyIpDHb7cGo=; b=l6DCjxTOXUSSEWdNWfL50kMd5lVMLr28ik8pXrN2SYqsQsxKt72A81zjfumSJS4X1w 8nAgr4OloUp3cj4mTF/E7sLTKdVxGjzxlNOXqFZmnJrZUiV5LCz814p6hXPlA3MVt+dy anUaj7KWg3cF0PgwfAXqqmIYOh8pPSvc+P0QWmi+c2zeby2iBlN/wMxax57WjnS6qF8Q BsOROcCkC5S5lve04STrG5wIYavDZdg2LU5MaauG1xFyVKevdTuhbniAgJpWiX6F3rau T4/w4xSJAY7p/vIO/LIPUsjKRHvQWjUvKnN8F2iEa8B1KJ6n1HjSnjRfscvQUnGe/Y9v khxQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XDbr+tDk; 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 h9-20020a056000000900b0033df86cceefsi9517724wrx.944.2024.03.07.16.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 16:04:42 -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=XDbr+tDk; 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 8C8C687D60; Fri, 8 Mar 2024 01:04:41 +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="XDbr+tDk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D38887D80; Fri, 8 Mar 2024 01:04:39 +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=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) (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 078AE83339 for ; Fri, 8 Mar 2024 01:04:34 +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=semen.protsenko@linaro.org Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-22195b3a8fbso200689fac.3 for ; Thu, 07 Mar 2024 16:04:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709856273; x=1710461073; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8WpmdhQC3KMXqD/OnNVkffYCf1720asOXYrEz50/bNM=; b=XDbr+tDkcT5ql5JkPer+D52zjR9PctRfR5LyYSMgtbnRqk75f53GBhCqTXmoeND63S kk5ZopkScOzDiiNoM2v7Wck3xLRnb1hRcEsJF+5Brt7JxqO7d1nYKm/tkiTGwgGlvBgh FGZiPX2w3GnlXKEUSbkSbkjitE15umST6k0RI/f1Ggbt5tP5ggbSOk6KROdmR4Bo2E4T pTWFln5RVxbNjUyZswi+xXjCqx1NhkBTSygsaAT1E3769pReM9J+fmjPwbBIUBWVeqzd +1+7u5OYCevsO+jyzaLtB8E1ErsnR9cIufXyz66kTAn0oshladWuiuN5bKgQqc340gTS kmGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709856273; x=1710461073; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8WpmdhQC3KMXqD/OnNVkffYCf1720asOXYrEz50/bNM=; b=urGwa19KIuUl8bcVKKoPl7npbGiytXAx8bR4b0IxYYpa8PDph3s7Jd05bp+IdxHU3S IRylNVzMKyiIufBdAbU5wH8mvbwadW8XLhutq0FeZtAmDLY6FeuvA3AvFiV4twhknxnu WCAjrZPCyCMg5iKuGKB3afd82njfIYJK0IO+DH+UBkzKy3S/55K3ajz0NsnV45aaNUTG J422GEfRJqiuOwBUD5UP5Nr9S0k0hNvQqS7ZbIWBUdD9RGEa/CJ2d/FF9aHqMVUdNhCl Z4g2QTurUxEcbX+27L9ewHNr9agPQv/CkEtcWRle4FH3Lu/Io3yMYF+1UmW2sI8PmmPW 2ZSQ== X-Forwarded-Encrypted: i=1; AJvYcCUAJgUs7poCP1KktDnV4JOENj8Bop3gjwBUwtOepfMqCS/8Yno7mxrefioxV1p0+VJ5gfsVQVV1NHJmDXF78xEWc3K6KA== X-Gm-Message-State: AOJu0YzRizyJxuKt13tGnKzrMmmDgvpVHDTvvQrGjqnbDXFcIem5cB1i 8qzECLsJAYn090bp65/whM3TGnrY17rIPrfS7i3oWqkA0kraVbvpwEMTO0RV/RU= X-Received: by 2002:a05:6870:724d:b0:221:1c2f:21e9 with SMTP id y13-20020a056870724d00b002211c2f21e9mr1473109oaf.58.1709856272891; Thu, 07 Mar 2024 16:04:32 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id wh13-20020a056871a68d00b002208ca7a9aesm4248713oab.57.2024.03.07.16.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 16:04:32 -0800 (PST) From: Sam Protsenko To: Lukasz Majewski , Sean Anderson , Tom Rini Cc: Nathan Barrett-Morrison , Michal Simek , Ashok Reddy Soma , Eugen Hristev , Yang Xiwen , Julien Masson , u-boot@lists.denx.de Subject: [PATCH] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present Date: Thu, 7 Mar 2024 18:04:32 -0600 Message-Id: <20240308000432.32369-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean Sometimes clocks provided to a consumer might not have .set_rate operation (like gate or mux clocks), but have CLK_SET_PARENT_RATE flag set. In that case it's usually possible to find a parent up the tree which is capable of setting the rate (div, pll, etc). Implement a simple lookup procedure for such cases, to traverse the clock tree until .set_rate capable parent is found, and use that parent to actually change the rate. The search will stop once the first .set_rate capable clock is found, which is usually enough to handle most cases. Signed-off-by: Sam Protsenko --- drivers/clk/clk-uclass.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ed6e60bc4841..755f05f34669 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -571,8 +571,20 @@ ulong clk_set_rate(struct clk *clk, ulong rate) return 0; ops = clk_dev_ops(clk->dev); - if (!ops->set_rate) - return -ENOSYS; + /* Try to find parents which can set rate */ + while (!ops->set_rate) { + struct clk *parent; + + if (!(clk->flags & CLK_SET_RATE_PARENT)) + return -ENOSYS; + + parent = clk_get_parent(clk); + if (IS_ERR_OR_NULL(parent) || !clk_valid(parent)) + return -ENODEV; + + clk = parent; + ops = clk_dev_ops(clk->dev); + } /* get private clock struct used for cache */ clk_get_priv(clk, &clkp);