From patchwork Fri Jul 5 07:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 3172 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2981E3FA1A for ; Fri, 5 Jul 2024 09:14:28 +0200 (CEST) Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-52e9763468asf1847722e87.1 for ; Fri, 05 Jul 2024 00:14:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720163667; cv=pass; d=google.com; s=arc-20160816; b=0SgbYmdaIYgCJIiRcX9eI0+pTE6SMwG8svrnxsv+EuIc1SmcmFpT71JolcuJTQh/zG cSYVBZvd95Ha58wIwSsIY1igZl/PylU0p4mkEh2Ea+6T41SVSB/Mf9dSEs5rLAeav/Pf 0Ahi8vCgSuxOGYYttwX5NBDhzLezm6jk5EawJphdZwbKRm8d4x59gVIW/SKZcT+NLW/9 WiVJLb80lj21sf4Yvw6tynYjhz296JseGwugQasVoY8ehpZedaLJf6dxBR875NZfeVTh pDwmt+pk33wGI1YDF5cs1giK4rPVx8e7CdFQYvu4IwDl254/LVrJexomjcfCS83LOWWr Me0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=CY4XqoU0Rbhh5HMtv1hLcLZZl0aogF8wvmHVGvKKnoM=; fh=emBPqQ0aLPFB1gF4DalcUlkaOY/rhuPNI06E0dcNv+Y=; b=Y92RxPKMBS6hwZGj3T8fRZMsPeQvLav1yLonFlXkuXfjq9+Gl8bFppBJn83AQG0vtb OiJ11DlFz63ygjyv1QvdmU2M0r7/VlIInYD62rQyO0xzo+wz+hHrJiHMY1oCGOfkwqDp 1N49X59qqyPXu6AYc5TdyTsQ4NYA1Nytyg55u0Cui6KRx+2fBAPEtr0MRP1HNzdkhrv7 aPeimi+MB3u/9zkuNPKPVY+M3mCCnAX5Hs+xhJ2U1MBGx8rxwS1iVWASN+4GU7m+djkc aspib+Os0TZuapXGZQUMtqndp2j07Z9nlqdTGtOE0zEVH7asLkLnrpe2WHaaREeWNSt8 OtKw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="q03/x5OB"; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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=1720163667; x=1720768467; 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:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=CY4XqoU0Rbhh5HMtv1hLcLZZl0aogF8wvmHVGvKKnoM=; b=FZI9+rL2IxXJ6jqPumn6yDjgiJ+ZAQFpE5ajEs+K5in4841iFfQmlkfruAMG+H8NTK G2gc+7KzbtSUomRjaWxMUXwyOzQS7aSmasjhdycDM7jrBXEjSDH7mic5k2HwDogkuH9n +RuNnKFeOaFb2NZ4tS5j1HfiOVKCFTRnCwrgU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163667; x=1720768467; 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 :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CY4XqoU0Rbhh5HMtv1hLcLZZl0aogF8wvmHVGvKKnoM=; b=nwuW1/KtBBSr3Zr22hM+CEURz3uwKHWl6mnArEVjdsgvRuU9UJOKd0pFP+3EcRHESz E/1HjCWeGlhmDkMpEsWv4w9/c1FVJ4AqP5pyiObQVc3ljtCF8nIadFL/e8RDjokNNRhN mErsz1IHFBs/lmT3Qq9ZLcJ94uNIBOMaKfTJkvLOW4Q3VgQYOqSDQCPZf+ewQIwKVWYt rQkVia7txh2OWxX+pGd34lOTk1HPJLs9p2ch6JlS/ruHzbnj2jviVjouLnUUFpViST0S e4inXcCmm6F0lOy8+RyM0H281s2fE+HvvEaZhpPqzMLIDvGEqoQjpIOq+LWa2Uohp/yV 1TXg== X-Forwarded-Encrypted: i=2; AJvYcCXv0QG8f7Fms351ucSuWo2732rTcRWh2BoEXiOmjQ84FMEkFLuV311ROTIGDhGvpr4jwhK5WeiD49LeFS9qcJHWzgxQtbIf/ofQnc98KQdh2eJI0LB1giRiY2sLhw== X-Gm-Message-State: AOJu0Yz8hRYp2Bpjs3dX9Lv2Q5D7DARTDd4S3jCy7oZwYeKtKQSNNUiU HlO795X9e7vRJIb6Ld3UpZJi/By9lMW8AA1X+f0rlnsN/rxoj+Rjw8WKREu11ZcHZA== X-Google-Smtp-Source: AGHT+IFlKnDXqt1GlhCIh9dboINwPWhEW4950Gr9G+0RSn0la3yY6p+jTf0GIoj7L9ql697dCDRaUg== X-Received: by 2002:ac2:5315:0:b0:52c:db76:2a7a with SMTP id 2adb3069b0e04-52ea0632597mr3053443e87.34.1720163667341; Fri, 05 Jul 2024 00:14:27 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a19:4344:0:b0:52e:9d2f:232 with SMTP id 2adb3069b0e04-52e9f14c3d4ls712998e87.0.-pod-prod-05-eu; Fri, 05 Jul 2024 00:14:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHvcLtUQD/dNi1lT7Lc03msmICHXdK4tXdGUY9Bm8BGIuWY0iq3gtg5Ym3jCSiYRjLebV6lkRlhnWgfWuBSgOYhSKgCsdlnK8omRaPhsKnLLSE X-Received: by 2002:ac2:4ed0:0:b0:52e:9904:71e with SMTP id 2adb3069b0e04-52ea062ac85mr3161277e87.28.1720163665211; Fri, 05 Jul 2024 00:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720163665; cv=none; d=google.com; s=arc-20160816; b=Mhe8KIH2LuF2XEFo03ztBzwzN7OULX1pSrc1XCrP/mcu6qQQUS7LwJQfp54Io2T5ti mo0DhF8svIw4S3rWjZmlYYOEMuUN4FX92wBl6SftnQsYsANsBPMiFkNokXvYkiTqknbY 57r+3XWf4v/Y0uXJ5gF3HNO1XkxVya4Ffb+suAe8+loIxpmG10TfUGl9KxG7w7+kvvWI qs6mgJgBcUstadiuoRgEwAWfYAAFoFhadwgY4y5EFtnH7gkHvvMcuN2TI7o4NnsV2R9t NirYW6xCtMazihV6GOErqaD/tPj4NNBgA7q+yg1ck+kMeTbRGc99nOQBP73G9B8hlz4v Pl0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=mdXSrxeHzpq2ucZicZoEzC7KYWny6VM9o50UFJdp7f8=; fh=VuFAljEWGB10/7yFp9BG4OoewWARffsKIDcamPuibXE=; b=pnJbO8OgkTkHnIbHHyLdO73ps15vlFvT6ys2DXForW2T8TuNTECbVAQHyQzq7ZN3ic xs2/x4YqT5iSgICRSakWE2R/MEYJdyCZEEeF8ApX57CBT/7g7T+eFhXPzVi56pp6sp+O MyAR4ixfejlBSuIt5zgc0BLshy4Dsb5PE3kMp2q9ROfXJfB2hxu8QWgt8KztpIGvQBBq k7D3xsQXRM2f/oYTC1/zCOqEKxZkpSlguhlX8x/xIQSRbrE7ugdmuAcuoMFZabeBirlJ OEVshAQdbRWdGBT5dwZpjuUVx81Vr4CZuZcf0INy17uwjOigmdgQViUm2pap9VKqrpPQ /Bpw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="q03/x5OB"; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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 2adb3069b0e04-52ea0abea75sor885943e87.7.2024.07.05.00.14.25 for (Google Transport Security); Fri, 05 Jul 2024 00:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCXCIzuC0iNyoPnXFn1NKkTZbsmHGYn+CKPIBteemXMSpptUMt/GEe1X86K4HkId+2fIzS+A1331r7Ox7PT/PrKmG4DvTqQVX12TloLZRIZmoHAU X-Received: by 2002:a05:6512:3456:b0:52c:8b69:e039 with SMTP id 2adb3069b0e04-52ea060d76emr2933354e87.4.1720163664570; Fri, 05 Jul 2024 00:14:24 -0700 (PDT) Received: from panicking.. ([2001:b07:6474:ebbf:a3e:4288:e106:2eef]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77d52c498esm15065266b.34.2024.07.05.00.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:14:24 -0700 (PDT) From: Michael Trimarchi To: Lukasz Majewski , Sean Anderson Cc: Tom Rini , linux-amarula@amarulasolutions.com, u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Sam Protsenko Subject: [PATCH V2] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present for gate and mux Date: Fri, 5 Jul 2024 09:14:19 +0200 Message-ID: <20240705071419.11521-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="q03/x5OB"; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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: , Gate and mux does not have .set_rate operation, but they could 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). Add clk_generic_set_rate to allow them to trasverse the clock tree. Cc: Sam Protsenko Signed-off-by: Michael Trimarchi --- drivers/clk/clk-gate.c | 1 + drivers/clk/clk-mux.c | 2 +- drivers/clk/clk-uclass.c | 20 ++++++++++++++++++++ drivers/clk/clk.c | 9 +++++++++ include/clk.h | 9 +++++++++ include/linux/clk-provider.h | 1 + 6 files changed, 41 insertions(+), 1 deletion(-) --- V1->V2: Fix missing include --- diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index cfd90b717e7..c86083ac5a3 100644 --- a/drivers/clk/clk-gate.c +++ b/drivers/clk/clk-gate.c @@ -116,6 +116,7 @@ const struct clk_ops clk_gate_ops = { .enable = clk_gate_enable, .disable = clk_gate_disable, .get_rate = clk_generic_get_rate, + .set_rate = clk_generic_set_rate, }; struct clk *clk_register_gate(struct device *dev, const char *name, diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index e3481be95fa..f99a67ebd35 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -151,13 +151,13 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent) #else writel(reg, mux->reg); #endif - return 0; } const struct clk_ops clk_mux_ops = { .get_rate = clk_generic_get_rate, .set_parent = clk_mux_set_parent, + .set_rate = clk_generic_set_rate, }; struct clk *clk_hw_register_mux_table(struct device *dev, const char *name, diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ed6e60bc484..638864e6774 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -517,6 +517,26 @@ ulong clk_get_parent_rate(struct clk *clk) return pclk->rate; } +ulong clk_set_parent_rate(struct clk *clk, ulong rate) +{ + const struct clk_ops *ops; + struct clk *pclk; + + debug("%s(clk=%p)\n", __func__, clk); + if (!clk_valid(clk)) + return 0; + + pclk = clk_get_parent(clk); + if (IS_ERR(pclk)) + return -ENODEV; + + ops = clk_dev_ops(pclk->dev); + if (!ops->set_rate) + return -ENOSYS; + + return clk_set_rate(pclk, rate); +} + ulong clk_round_rate(struct clk *clk, ulong rate) { const struct clk_ops *ops; diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 6ede1b4d4dc..febd5314df2 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -14,6 +14,7 @@ #include #include #include +#include int clk_register(struct clk *clk, const char *drv_name, const char *name, const char *parent_name) @@ -61,6 +62,14 @@ ulong clk_generic_get_rate(struct clk *clk) return clk_get_parent_rate(clk); } +ulong clk_generic_set_rate(struct clk *clk, ulong rate) +{ + if (clk->flags & CLK_SET_RATE_PARENT) + return clk_set_parent_rate(clk, rate); + + return clk_get_parent_rate(clk); +} + const char *clk_hw_get_name(const struct clk *hw) { assert(hw); diff --git a/include/clk.h b/include/clk.h index af23e4f3475..1900377eddb 100644 --- a/include/clk.h +++ b/include/clk.h @@ -452,6 +452,15 @@ struct clk *clk_get_parent(struct clk *clk); */ ulong clk_get_parent_rate(struct clk *clk); +/** + * clk_set_parent_rate() - Set parent of current clock rate. + * @clk: A clock struct that was previously successfully requested by + * clk_request/get_by_*(). + * + * Return: clock rate in Hz, or -ve error code. + */ +ulong clk_set_parent_rate(struct clk *clk, ulong rate); + /** * clk_round_rate() - Adjust a rate to the exact rate a clock can provide * @clk: A clock struct that was previously successfully requested by diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 59f9c241b84..459fa2d15ce 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -253,6 +253,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, const char *clk_hw_get_name(const struct clk *hw); ulong clk_generic_get_rate(struct clk *clk); +ulong clk_generic_set_rate(struct clk *clk, ulong rate); struct clk *dev_get_clk_ptr(struct udevice *dev);