From patchwork Wed Sep 11 15:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3435 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D2A5F3F251 for ; Wed, 11 Sep 2024 17:10:47 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-374b981dd62sf1126943f8f.3 for ; Wed, 11 Sep 2024 08:10:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1726067447; cv=pass; d=google.com; s=arc-20240605; b=DuApqJ86NBdlUQvwdDE46++eVNUK4V+NkI9Dgu8byWk2RNhpj2cxnz+nP47Mdhz+iJ VAOaD51K+HU4u01+X1UU1g9cdomvaCdYq5HhbuxhcDVaWBPyCJwTahEDs9pMBiVBGd4a QFcmNNEtPTMEGnFb8GExxOew3IRIQg8H5DqZs4AUapZJzuILDmGbZ/YpIHYeHIoWb6vg +AYQeriYzP6X5iKk+ohzIiBGs1UcCA2cIx2Y1uv7IfUTWbUx+q+UgT1Th7MsN825DNZj vmyEUwia4MMBIzWmJjxYFaiJ8p7rOTrit8j8MY5MN+OvaHelsWMnx9F7INyLvf6NY9ZT KsVw== 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:to:from:dkim-signature; bh=3cbXJCzhgmZMFX6CdOZO/HaMhXvnRkZctjE0kNj1+x4=; fh=5Vzml24XOX0wWNwyeimJd+TcPbcmTJhAohMtrIHzgV8=; b=Z02uzbNF2xYX2IIFh2mV+MxKZbSzh8bdRJ9I5ju1Akm30JkQFfbesR6c9Bve3T50F9 7B1ogWt+Jq0K+bZ0iekg5LoEL9jnkC8zKKPwjcD87xcpoczAAxUhqCeR8sqQ0y98rAAC VNMMKku6s+sGqMWUMv2KnKT8FrlYi2Xjh/Jq1bWyYICF/yYLDpyZjZgwB14ByBGFpuKc EhsFM5KqVpvehHnTGHasQUngsKSex2hbRBoRig+CC0q9DU/5OhqcI/Ip7AkU/LIG1WyU 5xTpKACNTpfB/9W+xtzIUJ2qPg6iEvU2BSA1lhcIt4CG+jVyz4EDkto0+5b7sAHAfKOq 9isg==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XYzoITJJ; 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=1726067447; x=1726672247; 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:to:from:from:to:cc:subject:date:message-id:reply-to; bh=3cbXJCzhgmZMFX6CdOZO/HaMhXvnRkZctjE0kNj1+x4=; b=FkG0rZchKQ7Z50fiZWO48D2yB7fByjzzYfCUkMGxeAoyFtS8TpeRg75Z3j6rv4kAO5 kKaJou+qKyQ9Ccfx+mn6dfMlXWQSVqrl5575JDZrLFgX2gu/Bl95fSmHM5GbpaLn7/Qr XQoaFmabPwcaqLSnMSVLM2WxF+yCJIJfdm01A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067447; x=1726672247; 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:to:from:x-beenthere :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3cbXJCzhgmZMFX6CdOZO/HaMhXvnRkZctjE0kNj1+x4=; b=hq24rduDVFWQSsNwfNz4hk1z+omUFBeJyKvjQsydshiwf3sxl63udabXKD47sStL+B TW5DUXnh9r9JrKvRqsSFw4yQ9Agu4WiiaTttiXU2TpvrwKQYUyizl20hCOFSmvN279v/ 07Dd8BvaE6eApG3WjRI/vt5pp27oS7gWSNZBSJXe0AJ9eCkilyCXYpRVD7R4jN13A9ZS FkcWD2jX9c+A9jXpfjI/zOYHALBU4l4zBwxOu53gd5jdAEEeqh12qcg4ZlbkQpjUEeUT 0TGcQ23ODNyr8pNR+S/qng3ZvaBh0ulVYijxpGYvzO2vmwiA2t9yhjw/gBHWd7fvQm9e 2dPA== X-Forwarded-Encrypted: i=2; AJvYcCVEn9psix/An9OTGhH2VEcX0GqkDTsdkijK+6RxC6oZ6w/H8MRt23hxCOVkgR2cNAVbkurw36IcHrKRB2X0@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YxilYQAA6MNwKFtOmKnqxnuNNIpSwD1auN9jg0ANuSgCEJ748QT nSs5nt+2hg+FyQrbUiB/1lrZpmKsbcuYTiFaGH1uQCLlErecUL3jqI4mDhzZJ0XT2A== X-Google-Smtp-Source: AGHT+IFGV7ztaTc0bm5PVPZGjotH/37yJl8vMjt1KFhmMkeGe8e11uFAPIEsbMe1GUXQzHKBe7ex5g== X-Received: by 2002:a5d:4907:0:b0:377:284d:9946 with SMTP id ffacd0b85a97d-378b07c8664mr2326282f8f.30.1726067447388; Wed, 11 Sep 2024 08:10:47 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3b87:b0:42c:af42:6403 with SMTP id 5b1f17b1804b1-42cbde647e2ls12291385e9.0.-pod-prod-02-eu; Wed, 11 Sep 2024 08:10:46 -0700 (PDT) X-Received: by 2002:a05:600c:3b0f:b0:428:23c8:1e54 with SMTP id 5b1f17b1804b1-42ccd32deb6mr31961605e9.18.1726067445823; Wed, 11 Sep 2024 08:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726067445; cv=none; d=google.com; s=arc-20160816; b=C0iYGSKhEoSpMKwUfz6VlbOM27+9YdWew5NtkC6GAyvv/Q4pwcYbG2qMEdgcFGtl0p Ffc19fCbKdGsPBDP5XIYH6gHzpiYdVGkMKxY4XiUwuNH/+D/deLYuETluhh7ybiu51Rg V6YyBpGR+NmPg6ew4K3MQWB4lsFcXLBpHSsqWKWswcGt27zsfUqPjX81i30+FSrEKdmw o7nCor4aJso6jFwExWNioJ+F90a7WmaJC0VVnIYTgn6KTf7BdkSzN9TDT2Crcm1yUKsy PQEvM0mlf5qplWDR0GA4DBftGb+POYQleQ+Qu4CSn2igleh69dFVfIHcOz/Xk4wYafd3 zUbQ== 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:to:from:dkim-signature; bh=lvYIhATKa8CPAeak+8bmtlwFxaGBD71PECtAMFCv/Bg=; fh=FtQepR0uNoeKT2PVdKfTKOkvEYfwbRmoVE9BmlYw3tk=; b=oVfKXb7X/4liyVQXqNRj8u8lVpEz4U/cKijLoB61HzRKGOry6+vXd4Jzc3tk/hEx9m O/IL2jRZXLdoqWPi+Jv/1uvX2wW4XrlcfaHwhI2VYHO5vp/29StcD2tCNzaLyNz+FPv9 ngPhY9axt3f42t0G3RHGCKAxgWU20kCYKMMbIU3y92rcdDv1qh9JjEYh6rFjsN87MAWb Npi4rQPjG/+U6ZNXKzly0OrOpuIiMPg+Berb+hZ6ea049tThjllFU+aK419QHAfDQFau LFyrLDM3iqpBeSAMbx+GLBFPSiAkljHx6eP0a7yIyG0vy3L/DErqvJ8jrMVea4Pv3h+m GtMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XYzoITJJ; 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 5b1f17b1804b1-42caf2b17d4sor29475455e9.4.2024.09.11.08.10.45 for (Google Transport Security); Wed, 11 Sep 2024 08:10:45 -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-Received: by 2002:a05:600c:4ecf:b0:426:66a2:b200 with SMTP id 5b1f17b1804b1-42ccd29c3cbmr29921705e9.0.1726067445100; Wed, 11 Sep 2024 08:10:45 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.41.3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb116f44esm137688375e9.45.2024.09.11.08.10.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:10:44 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Subject: [PATCH v2 05/27] clk: clk-uclass: Implement CLK_OPS_PARENT_ENABLE Date: Wed, 11 Sep 2024 17:10:17 +0200 Message-ID: <20240911151039.2914886-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240911151039.2914886-1-dario.binacchi@amarulasolutions.com> References: <20240911151039.2914886-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=XYzoITJJ; 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 --- 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 4c2ca9909469..fdce69cb48e0 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; }