From patchwork Fri Sep 13 09:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3469 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3FF6D41280 for ; Fri, 13 Sep 2024 11:57:04 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a8d15eff783sf112229866b.3 for ; Fri, 13 Sep 2024 02:57:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1726221424; cv=pass; d=google.com; s=arc-20240605; b=FEquHWIsI6ynhbcWcdvGovzjI389pq+0uZmu+xrROtHHgGn2BZ0CQHt9bUNk/+COVa UPZylwNgCr8lvFIse5RD/A/UEFf895VNZZ9QG4RHFyvSNpLycEiKsnyeE3yJAOnsR2i4 ZkCSVHvCoz8oKV7tznoQHFeMdjwzTvVDVU3gtdK7Tk9KkSrrfL+Q4syXRenkQbtmRmHm WHu1GbKiEqomsIeP4YUJvzcq8AnoyB59EftO/BIL2ccj8uo4RHTuOlB2ujkOIqVkT+h7 klzQFFCiFtVSTIT+bWW7Q53GB6gbm/XGUFe9s78mn3ueAn5sqmr+6gPzUy4u1BaBTp+l lySQ== 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=lKavKFMmh3C3a3RQxVc+z8GTUqYYPBpzHKzY7t3mR80=; fh=PJQfx2Dk93IevpdN6liEEP59LS23+nJPPO4eXsNvVZY=; b=KO3W12Vx0pEcUiENQn25bNyFYOMwDumT/+gXxxr8Pxi3xIeqV+Ra8dohWvKPAFxiSx vOX0DjgkY+Jg5xNAQCiJKprZ/BIESK0LJK41QgrhWJOfhq4uYEbOlL46tro6UkMvyFJp FzOcHl4HLKzzQz8Hh3kS3CcpxvIXK5qZC2uTSy+XW92W4MTL607mEIqu8bDUNKzPXk3+ 5hmVYpm5iru124JsC73lLlMTu/By+w4HDUkKKiuVaTLyDoJHgc68BgTPf4rwJ2UVCpMm 73WvdAs6NHvOpyPbO13y1P7RphteP4LF0Yqs17fHsUCKJQslLVatphFRrXSaVAac90hs xiCA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OK+Wixix; 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=1726221424; x=1726826224; 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=lKavKFMmh3C3a3RQxVc+z8GTUqYYPBpzHKzY7t3mR80=; b=oRx9q/EvqdMBGTxpLHGx0gd1NaMDdmojliDr/xhLuEOLWVccl4UoKJvUNfBHDAGft9 X7npudFI9+rHa0Q77STjPlY3l3mY8HPzfeeAsyrupOxrrGeGNpzLoVzguVjJ6KHPtlmX JG0j1eY3JrORXhnPGEckJZb/3iGdvhkH3Ay6Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726221424; x=1726826224; 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=lKavKFMmh3C3a3RQxVc+z8GTUqYYPBpzHKzY7t3mR80=; b=Qs84gyb+C3Uxuk1IbQv5HR2E63hs+CeyIPXzzWXhOLz0Wxd6jIKOA+qsrS5WRDTl/F 2HKCeYgN/heanID0uhqw0KdCEeV4Fq/gUepB8NLgYtX+AHtLV4Ros/OVtmUhInDBPW4u 2XUF47YBawZjph3vHr+eAfSXJK0Ck8H/iF1PTziRJ3NRPNH3PDswJ5cuaINnDaeb83sO YloT8IEQlqnBgWoA3OjlAHoH1ebd+4JZFhPg0kv4IRIwiCx0WyimJOcHYXJvOo5hMnUn XxySTH1ytIBvl8jdCNjTJYBJVkK6s9Yc2B+hPq7wDxPpHZ7AcATMuL/vP3w5IrssNrWW vRwQ== X-Forwarded-Encrypted: i=2; AJvYcCX+I7k8bcIk9HVoLVLmEpGjdoGPCW0qRdHSGryBulstLun7DlhND8+/jxmVbUR8LtCXtW1z/fw7qKGT0Qy3@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YzRm0Jt5qHNj/1CaiucpofTjBJe09aAhTyFe890ft3XdQOLXYOw MoXhKtFl3B7UpTyGExICpd2XbwBSqE9pxzjDRVKCzicakOsl8X6sdmL0s+QRjJDJ/g== X-Google-Smtp-Source: AGHT+IFSYBbn6SgxrlZQXWmwHmD2phiUd2sU9WDUE9Edqv9YYIyt5mlHtBb9B+GwqQVPxxPl4W5X+g== X-Received: by 2002:a50:c94b:0:b0:5a2:68a2:ae57 with SMTP id 4fb4d7f45d1cf-5c413e522ddmr3820026a12.31.1726221423618; Fri, 13 Sep 2024 02:57:03 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:524b:b0:5c3:cb56:e6b0 with SMTP id 4fb4d7f45d1cf-5c413e236afls672407a12.0.-pod-prod-07-eu; Fri, 13 Sep 2024 02:57:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVKoyPOYQAo0PnXs1ylmp4jROth/+NKdWPOb2hDS7wRfJ1wXxaXjHoIyb9wftsIxgj+xbC90pVBNN7SivdS@amarulasolutions.com X-Received: by 2002:a17:907:e24e:b0:a86:8f8f:4761 with SMTP id a640c23a62f3a-a9029452990mr529364066b.25.1726221422035; Fri, 13 Sep 2024 02:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726221422; cv=none; d=google.com; s=arc-20160816; b=e5z4v0bX0MatDoJ8A6V3k0XYPL9+ey/GGaLSZCa/DVwCH9+vqZp8aZpKEI0kCA08o8 oOrHToHgsLE3l1L68GS9T27G8GbIGWAbQq1IE06a2e6bYRsGlZfNGJEMcoHz/dHM0WEB hExE3ibu56zSf/dUSHzvTVOI4RPLkc27V82jzwUUV/dLqDInlzqqRugvEN1+48NOtBnp PC2hrZwaUp9PFYS9ppf5+pCuDuHg6XWvmNBHHS20peSSXPYa22HyqABOkcRYS0UO+TzW 6r9cotK9F73ZsKVt5eDbiqygfT/P26TIAmQ3DZxS5/acHpQXM/AP7xBmcXiDYDdDt/Ta Whtg== 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=jE25Jwvxv1lQqd9B0PMvAa/3bguXHPwmlQrK/A2JMtE=; fh=JG4AH/5QjmqBTYfdJ6V+SDfDDKJuW7qvp7kg6uYOmXc=; b=wRehaPlvAhRNK2eKwIa05FvJzoHFYhQX6N/S1xMDe/6Wd0aY8jPsCcq83rmJoJHE4D sTQnWhTkuCFRpOChuf+Q+yPD3JjSwxV47YdEf2wD4bWcoVWCzrq2WapBqiZUB065LBBn YaaopVxcci119kxZZLWzI8gFQFs+QLi/qnkHwyvLerEU/r3bdyNauCzpfJTyGMVuP7Tz ZyrWuNKSy8RZgAshPAqEprobuGq+We+ofvsaTipteUZNTSV+HQL/tIaTiD4o59UhMnsj e23ijIuslhYVRO446mi2X7aXkbqSjPp0c/kCgLWwh6+vLZk6Z6TmUzGUI2zwCFVwgvaD RFtQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OK+Wixix; 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-a8d25d2938bsor430959266b.21.2024.09.13.02.57.01 for (Google Transport Security); Fri, 13 Sep 2024 02:57:02 -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; AJvYcCX/Z7t5Plz6GDE4tHUPvhm9FiL4V+0KAEcp/pW2PB4hmQTuqiA+uFDf0+pBqVrZBFm/0zhP6E1u0vimhuK8@amarulasolutions.com X-Received: by 2002:a17:906:bc26:b0:a8d:2ec3:94f4 with SMTP id a640c23a62f3a-a902964d007mr497794666b.54.1726221420786; Fri, 13 Sep 2024 02:57:00 -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.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 02:57:00 -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 , Alexander Dahl , Ashok Reddy Soma , Eugen Hristev , Igor Prusov , Jan Kiszka , Julien Masson , Lukasz Majewski , Marek Vasut , Mattijs Korpershoek , Sean Anderson , Simon Glass , Tom Rini , Yang Xiwen Subject: [PATCH 01/26] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present for gate and mux Date: Fri, 13 Sep 2024 11:55:43 +0200 Message-ID: <20240913095622.72377-2-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=OK+Wixix; 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 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. Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- 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(-) diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index bf1c6a93b468..bd0d3d44ac8c 100644 --- a/drivers/clk/clk-gate.c +++ b/drivers/clk/clk-gate.c @@ -115,6 +115,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 62477e15d27a..4feb8e8c821d 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -150,13 +150,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 16169dac2340..e8db9b0ff2fd 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -515,6 +515,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 b8c2e8d531b9..67c6b23231ff 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -13,6 +13,7 @@ #include #include #include +#include int clk_register(struct clk *clk, const char *drv_name, const char *name, const char *parent_name) @@ -60,6 +61,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 045e923a529b..f0fd524ee519 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 59f9c241b846..459fa2d15ceb 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);