From patchwork Fri Sep 13 09:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3472 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3336941280 for ; Fri, 13 Sep 2024 11:57:07 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5c2483adeeasf402114a12.1 for ; Fri, 13 Sep 2024 02:57:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1726221427; cv=pass; d=google.com; s=arc-20240605; b=L4mRbsn9Ud3EnOvXievBN3hWaVVYlPZrkpF/h2ZVH48PfuPv+Vq5bjsQTEBfwOn3Yz LZcOElkcU36beIIqdlaUD8u8T9wIf6yEo1lUJWEp/1/PWV3g30L0Njg+K53REUGDY5Dh hfFXKNkz48JsQekaMausptnAQu6pWvH8zT2xl73OxKaMER2NR/m0yQTG/LNyj31ufqVx AX7O0KLgN2xqJr9sx5tPdsQ8+K4vVcNwD42NK75h3yFOWRwnhEvOxCZefhgq/qkVhqYg pAjp6vtOMpw0RkPjaZM+1sQCAM8tPyrRDgZMd6CBatKbmdQfNK0uCAG1cGBXbQN6Vvga /Dtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=fZIwj3jt3oMrXU07Zq48yDI5uQ+ZJLXFK6HeytY1BvI=; fh=kU5w7wtY5geboDSdi6POmZL/SeRPWXeAvLwf6ogtb9U=; b=lgHW3tXcIR1m//ls/e7dEc540J+8IQS2HvdhE1RDEr+kCib6kxUnK/zicxnNyUuZEm SlHHXlWjPYZl0YPgkUzFlWFs/mxbpstdaTK8Jjo/YVfY5/wszf0dipEwti7fLCx9oE1K WSpjSgXG4FaZujk0535UsMjy2un7kieDMtDT+SMiiPbV+mDxl7r2zZORpmv8BoUtSim0 PlXbECr2gJxip25Av3tkGe5w7dvTbZ4/g/VgdPwpBYysDxZ88BPdWg9KcJsZlX7i03Np ceQV43/xQLrJervdMw2ZOVdw7LunxlQcUhRWJIgBIozwopclvvqyxGRM2WP4CBDN4fss qobw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BKXOeLKu; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1726221427; x=1726826227; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=fZIwj3jt3oMrXU07Zq48yDI5uQ+ZJLXFK6HeytY1BvI=; b=adxr+RtohWpzwcMCqCX+6BCpCvi9XAYtc2zXsPQq7VxDAtJXYb8hYt7mgD9DwgPBYJ +cQ2AKp3W6s5sQ4UmGvHJGESdZKthrs0B78vWi+YyVEEcUwRT8GPOCZWmO3EKQ0SmkZ3 NW+mEBbjDRmoVvfnccSHJZqpO+vTB71wKRBqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726221427; x=1726826227; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fZIwj3jt3oMrXU07Zq48yDI5uQ+ZJLXFK6HeytY1BvI=; b=mfTFuntK2sXRH5CCaDSc2gwvc4fXnpvxJFLcmdfqxZmr/zlyDYLfkWHALWn9UGzobF fI+GXoWVkxTJSc3SIceNpM+8Zi8NQjQu8Uc5SzVeMRy9H5ueSRAsB6QvZGprZTcReQTM xHbdRjQpe7v2YalItZhg2aP3Z10Bguh7QiPy/l/CRncXZIT+6ptqfBxdSa9djBPOmUet l1PIchK74a0IGelXKDHFinkisa++qoEK4oPtA5jNZMM3INa0iOSBmZoJsl9zrGnYsa0r 2hGI6TtvqS+wvFd14MXID7nzuyN8JSu/lz4otKIi4CRr1saMN6FH9zhJk7bNimzR+BmI cH/A== X-Forwarded-Encrypted: i=2; AJvYcCVN1c316INqMukFWQvlBw48CwgmsRAABIHU9T3GLRu2saZcPlr6fFC7oumljvaXQSEpNo0N5B+zRkz16iJO@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yzu6q4kR0cqD248yjemTPktyEBesLwIyTbTRGw4kVW+ZrTyE1y6 xPQDoyLRU9phepmLoVYJgVIHGBXhnMLKAyXjsEQi8AbIzHRrwJIB1kXv7boobTWiDQ== X-Google-Smtp-Source: AGHT+IHQxFVBOnrEaeOo8KKpNuOlw16fv+CjVm1ku74+7jpZwnEiWq1XYQ+nmgzFmRNAIG1MpOnuew== X-Received: by 2002:a05:6402:27ca:b0:5c4:13c7:971c with SMTP id 4fb4d7f45d1cf-5c413c7979emr6032092a12.12.1726221426618; Fri, 13 Sep 2024 02:57:06 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:524b:b0:5c2:2b24:94d3 with SMTP id 4fb4d7f45d1cf-5c413e2627cls3820a12.0.-pod-prod-00-eu; Fri, 13 Sep 2024 02:57:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWsXaNhOmy488X/EVOhlMCHIT9jhTsaVDjVyCN6YqS2n/ccmD6FWNar9e1e7Pmg7C8bEDdfY6PmrABLlxKw@amarulasolutions.com X-Received: by 2002:a17:907:869f:b0:a8d:55e1:a653 with SMTP id a640c23a62f3a-a8ffab6fb3cmr1086871866b.13.1726221424935; Fri, 13 Sep 2024 02:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726221424; cv=none; d=google.com; s=arc-20160816; b=C8ZE0nitHe+SmuOnSi53IFNMu+PiwjECYaOfpgcTKTlY2XNdGcUy0Y7DSH3fxmgYan KzsTQFB9K2VAnQrfICogX0NbqmtqhBFP1FHqTi+YcTB470wb6jAlpNWhVZooOwugAA3K uI81m2ps994BkO4qkp7W9jkmo1EH42+uAOOlgerdvRIFvheMc2aqebSt09l9VDUTRmpf bBWQBaWTyeiCuwGDFrrq5sMYjeJ3LzUAM18WIYMiRqesjdck8G2qaWRWN3H8exxzve6J aMizScEsktqXlyuUIP0v823tCOYSa5UgRGoKZRGi6M/6fdJNNVQvnoLAuTWAnPqv8eaJ h7VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=o+wxQULqTeVZWboi9dNaAJm4xPm5Im/JzcL1kgm415c=; fh=JQh9fXFBwH4EtdSOCpYvBI9pVf0xuMetat1tXB9A4ko=; b=ROkLKFG7qGXMtgU3g5udF2+SIgr+FV5b3MHadDxpsyrIxfAL8qNx21pW7BcY2qkw4i d4uL4ModweC8cBjLkuYnGU3JMDbDpYnOI1CC9gFUYcQP7A3SaKZYTmAGMswzCoQGD+ic j2IGIo+JgOsVW6a7UzHNehOjlavFCk4vfolppGndwgeLTbxPUm3He4I0/8pJzqj32o3v 4wb/qDTnUBUuu+Iv24GJqcJFrMGDi2xPumJ4pClLEfBb0GHzCnY0Y+fgg/rVSQu6KrYn zr1OG0plclzZ5bLywCbqGvkNDAVySEe/AWCUdgtih/R0zdJANxXtQKzT5/ohYH5d0mG7 /Fpw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BKXOeLKu; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id a640c23a62f3a-a9047750edbsor60517666b.5.2024.09.13.02.57.04 for (Google Transport Security); Fri, 13 Sep 2024 02:57:04 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCWfsEFJZCThHowqyup/Vo+aJeWtClKj5LqPIWauXxenX0DtzOIlH84obbn3KdujfppkPMNjfO19iiNTtFgo@amarulasolutions.com X-Received: by 2002:a17:907:1c1b:b0:a8d:4e69:4030 with SMTP id a640c23a62f3a-a8ffabc2359mr1172142966b.19.1726221424382; Fri, 13 Sep 2024 02:57:04 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-87-4-102-18.retail.telecomitalia.it. [87.4.102.18]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25cee72bsm863224766b.173.2024.09.13.02.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 02:57:04 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Fabio Estevam , linux-amarula@amarulasolutions.com, michael@amarulasolutions.com, Miquel Raynal , Dario Binacchi , Ashok Reddy Soma , Eugen Hristev , Julien Masson , Lukasz Majewski , Maksim Kiselev , Mattijs Korpershoek , Sam Protsenko , Sean Anderson , Tom Rini Subject: [PATCH 04/26] clk: clk-uclass: Implement CLK_OPS_PARENT_ENABLE Date: Fri, 13 Sep 2024 11:55:46 +0200 Message-ID: <20240913095622.72377-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240913095622.72377-1-dario.binacchi@amarulasolutions.com> References: <20240913095622.72377-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BKXOeLKu; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Michael Trimarchi There are scenario that we need to enable the new parent clock before reparent, or we need to do the same with clk_set_rate. The patch cover those scenario Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- drivers/clk/clk-uclass.c | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index e8db9b0ff2fd..b571a3620222 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -582,7 +582,9 @@ static void clk_clean_rate_cache(struct clk *clk) ulong clk_set_rate(struct clk *clk, ulong rate) { const struct clk_ops *ops; + struct clk *pclk; struct clk *clkp; + ulong ret; debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate); if (!clk_valid(clk)) @@ -597,11 +599,37 @@ ulong clk_set_rate(struct clk *clk, ulong rate) /* Clean up cached rates for us and all child clocks */ clk_clean_rate_cache(clkp); - return ops->set_rate(clk, rate); + if (clk->flags & CLK_SET_RATE_UNGATE) { + ret = clk_enable(clk); + if (ret) + return ret; + } + + pclk = clk_get_parent(clk); + if (pclk) { + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + ret = clk_enable(pclk); + if (ret) + goto out; + } + } + + ret = ops->set_rate(clk, rate); + + if (pclk && clk->flags & CLK_OPS_PARENT_ENABLE) + clk_disable(pclk); + +out: + if (clk->flags & CLK_SET_RATE_UNGATE) + clk_disable(clk); + + return ret; } int clk_set_parent(struct clk *clk, struct clk *parent) { + struct clk *old_parent; + const struct clk_ops *ops; int ret; @@ -613,6 +641,15 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (!ops->set_parent) return -ENOSYS; + if (clk->enable_count) + clk_enable(parent); + + old_parent = clk_get_parent(clk); + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + clk_enable(old_parent); + clk_enable(parent); + } + ret = ops->set_parent(clk, parent); if (ret) return ret; @@ -620,6 +657,14 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (CONFIG_IS_ENABLED(CLK_CCF)) ret = device_reparent(clk->dev, parent->dev); + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + clk_disable(parent); + clk_disable(old_parent); + } + + if (clk->enable_count) + clk_disable(old_parent); + return ret; }