From patchwork Tue Sep 3 15:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3377 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7A4663FA49 for ; Tue, 3 Sep 2024 17:31:08 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42bb5950d1asf61947015e9.2 for ; Tue, 03 Sep 2024 08:31:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1725377468; cv=pass; d=google.com; s=arc-20240605; b=LRGKlLeQm5zVfLo7Li9FroXoLa/x+fPtEBjHyrbihVdDGj9bLmz8wywwzsb/aZL/xk SpUMXfDKaCaidWlbNgpK38b4rDOTAiATHgvBO0zdyxHi8CjwbSJgrxAhuQKhu3N9C3Pb bL2CmG5elyZWsArEx2fTio+X4V+WTuiJxjworLDURE9X3+3Nw36TwFL4SjaGCPeCOIXo 22fnBw+IaRYFLj0kO6KU1c+KkZrTsjwDTPxy7a6+Ob1GqVMa5nuft+Z9Pz1uPNePB9m/ sY4I1mORYUNIaiPCL/cvn4HN9rSYzQLFyFBWNxo4LF8ENv/gOl6uQVPEFg8Ygm6Iza/8 r1TA== 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=z/bSuNkNfQvXZUDf0YZNnof+1SZ/1CtVqaoMZpznaoE=; b=aufDtkt7wMXdJj0TNE7/znx0yM2WFpMoOQlqA0JZn9Ex9nuMGRdnk20un6ZVuIPcTv Pl3q8/lo+swJ2Bs9I5fj2zxOpbjmD7SWK6z4Erdj58oC0Y8Mjq23KcsJR6Z/cQmLjTL5 rtZoq2T/2IAoOq8cy5td7b/APwn8oOE9f0PSCG129wfL9jijdkN8ax0sO1aA1y9klbFy BW+mD954tK9S15qReSrVZOWd3f9S2iA+cEpBl4nR7XE7Q8U9i5/lsDXtQexM9379p4CU 1weQSaUNVKcfkWO9qLxoJhd4UoB7fMeuE2O6pNYEUpGgA7TshNypPHI8200A2F707BD4 KLZA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dM3eWFj1; 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=1725377468; x=1725982268; 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=Q5re/M+vcO3wjLDQEMEbQFD5JxZz3JTLmEJGuoMjR8R6LezOz4el1RvoECsd997AhI FgdBjqV5GNi6iqSEhySwqZH8ZJb5MkJDrwGHzoDp6Pu9ROLPTvM/ULUUUPk9obcsDdvQ LfYskE/vulReSu03A63w+sU4XwsEA+fghOEk4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725377468; x=1725982268; 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=gLYLZ7T4wPH7wK9q9MEAUvX50K5rEq0cSJzbj2PtEqoCFzsb6UT3HgZrVapy5Cdu2z gbcIPXjG/4UqxXyC/0tC4cPf8MvrdXtyBY/dcNr7dwHz7w0qO7yNFjmCJnrE/bCwgW6i Al2hllsGnGXSERbzkru1opmryTR7NfUSJek7yzrAr2Uugj1673FnmHMoakAgShqAqKw+ fZDmlOfp9KyCK1OzxZvU4E0uDe0z4lplD91z7JtS/Pt5eXefmFUfs/f5sza3OqTzk1TS spFBiVDp0kBGHeDi7wnhLbBvT2yTPfXpbBPrzdDRCEFclxqfOCrSefXCqb29A4KTCbSD 57WQ== X-Forwarded-Encrypted: i=2; AJvYcCXVnDTVZi8/VwQuj9M2HJqfWo8Ipnkd1e6bRBEJkDmR3uC6KrsMCX9l9Bfxh/afTwDHKOXwdADubqVniRfV@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YxiWgH+zW/mYPajwFSdcyOLKU5igAhDqhOG43H2FNWzgoKemApr 1NhjqMqeGDYuwhkUcfWk/HvxaC3f0c/RUtJlXc3hU/tJK++zadTwi2Axd0Or3KEjog== X-Google-Smtp-Source: AGHT+IEclw/FJZAQA50/i8L9e4dMVx2TGEmwJG3+8Gh1KYzmlFwtSvEy8HsR87slsYa1rn/0+VE0xQ== X-Received: by 2002:a05:600c:4fd3:b0:426:5e1c:1ac2 with SMTP id 5b1f17b1804b1-42bb01ad75dmr164436255e9.8.1725377468074; Tue, 03 Sep 2024 08:31:08 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:4506:b0:426:7318:c5a0 with SMTP id 5b1f17b1804b1-42bb2a0f33cls1304935e9.2.-pod-prod-05-eu; Tue, 03 Sep 2024 08:31:06 -0700 (PDT) X-Received: by 2002:a05:600c:3b8e:b0:428:d31:ef25 with SMTP id 5b1f17b1804b1-42bb01b91dbmr156947015e9.12.1725377466257; Tue, 03 Sep 2024 08:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725377466; cv=none; d=google.com; s=arc-20160816; b=kxNqkMYLXrMAHYJboNYJsmfocJSXOBEdLuDeT2U4Qp5PopMpO7HlQx9mlahWxahyrd 8b1SYgon0HDYU4AydVVWxsaC9PQ/90ZtZIDkwaXGqRs+WXgngV62AIDXIts+dr4ndXSl 74zcfa+7gljCsIjlux49RMrI0mdWX1NNesw0unZLKe8qY96BBuZ7hDzsFqs3rtQAkIxV U4Pl2PN+QX6Gri/OXbPGtdWRKnsyhmLW/PkIM3Af+OtoIc+CqjX//G86FtxEYk6LtSym 6sWtLguDzYyF0rI8l3doDzTS01ygDgaZ3tzKsQ8vX9id1H/wcT1MZUMs9Ihgbn3YVtTS xvIg== 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=FEd3GCh7NuGkLrwJqI5oZ2PJ1lrQv6vLE6K7e3lxU3T/8Rdi/n/RbdHJ4j7lpEy3pZ BeGVxoEgVeyD3XOJLTvqg+s+SvaL5MpZYX9ED2uqdiDF4A2oJizexlisw78FCn1v2V48 //O7bv9w8bWS6etjX7danlJo2/Wvrzre/KWtR8r9AmRbpfYE/Gx/BgH+A5VOjuP5czq8 BOL8OWimkT7Z+jOxr1+vtGW39HFhXbWZiXxZbbhLS5n6cbmmkHSQ/q8dKV/GJ21mihqE lJG6af+Q1L3aLqRh1/XRivvOrH7HAU7zsfmv8nNHvpQBPidMZ83qwakAMy5eVyu7PHaQ 2p9w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dM3eWFj1; 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-42c8e41b1f9sor3571605e9.7.2024.09.03.08.31.06 for (Google Transport Security); Tue, 03 Sep 2024 08:31:06 -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:a5d:5c87:0:b0:374:c8eb:9b18 with SMTP id ffacd0b85a97d-374c8eb9b69mr5257085f8f.24.1725377465651; Tue, 03 Sep 2024 08:31:05 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.42.65]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e273e3sm174168685e9.30.2024.09.03.08.31.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 08:31:05 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Subject: [PATCH 05/29] clk: clk-uclass: Implement CLK_OPS_PARENT_ENABLE Date: Tue, 3 Sep 2024 17:30:36 +0200 Message-ID: <20240903153100.918077-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240903153100.918077-1-dario.binacchi@amarulasolutions.com> References: <20240903153100.918077-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=dM3eWFj1; 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; }