From patchwork Sat Jul 13 08:45:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3207 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 570A940F45 for ; Sat, 13 Jul 2024 10:45:34 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57c93227bbesf2631936a12.3 for ; Sat, 13 Jul 2024 01:45:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720860334; cv=pass; d=google.com; s=arc-20160816; b=LoFO2T3VE47/nO/5qbGBwQXGzSQ2bLeX97umXVbdd7z3ftwNQeqecECjMUrU7jTEzZ A0mHSMAFb2chim446jgIiwAssIs7cUM3C8RUISNkQQTuHeGDmB1WOES+3wjN13RfLlHl KKYtLWc26ID/7NKFIbsgSbbZ9KNIMpvfQvJCMm1mNsaf7Xb4T/Exz6HOAqgM9FAzNwnZ r4A9W0uBjkme6m8Wo+OwCIiUPS6s1nolxkYyDxD2onWUoptFO3oMJUSqbcFBlfvgE1+V KohQY7xQ3iCsB5EF7FfRr3CI9scByDkohTQAdDBLM1F8iexwkIy2k8FP6Iwewilpk/pQ U4VA== 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=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; fh=Ds5ekb0u2UZWVVAmczgo5Fj7ap/nCnoKqbzqS5h3koU=; b=sHdMiuHUAreSE0httPL8lMxIR+/G/u64l0rZAOIUvrmE5P7lezaCYXs1UOYEtxKq/K MxZKRxtUxU7HnpNhd6r/CsAfiztvjjYgG3c2H3YfOxkS123cl0wwLjkNXQC+V0o/YXgN M4upgUcTMM2hHUUud6/taLBnDK7ZFZdRJebctLKPpdBD49nNJ51OX9JDLcGMHNzPMnMs GO4LyjdH0vTI0ozW6Qiz6ANMmDry7lu2iqN6Gba3C7c0AGJjkfWIozqlKuHGwzddxINl LHarr52zBGQvqwaYIwNICRIymjrZkqaRmGtcPIsFF1sOgmbAqWWW8/bWA7nZtTHc8Kyl Nfrg==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MWfruml6; 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=1720860334; x=1721465134; 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=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; b=nj6NKG6HTZwp46JM26g4NdmTwyqT2TjhNeA1aHRRf6yVqUPOuB7OtwzCrmlSvyoTZf 2QzjzTrQ9AtKH7lu6eAOAMfcdW18h6N5Mct+TXttIabYUbE3YKnwlhmlyYXn9bKyVdq/ Em1LMVrTYSp2QseLc4t9buz69xxTAnb1mN6ho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720860334; x=1721465134; 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=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; b=E+AuCk2gp6ls754mVtq2TXyIe9Wza63wa0RnuiOgRPjPIp7rUNidzR0OX5o3JP6A71 BWwbv6iNL6CjGKhfYjXc4mGV2lvcHnxSIZ6+0Vo3cmiWmf5VBThZQ7LIDKeqM6Y/hI+N GsUFDZprqnxq4/tm3UsC1+ppxduIszp4p/laiKH/cZD4NQbubleJx4r6ryo8dOpQJS9f ykNTbgvm8uDJ+Iee9Pd2fZBrS50a9nShXe3Z+gLZtsKy2ZvRtFZa1duKJAvJjdH4oZez qnDNot1IIlEgyFoxXfZfnln2PDouV++zK+M4G1YQyJskRduI1rppPPJyzTvcMxEp0bH9 GjIw== X-Forwarded-Encrypted: i=2; AJvYcCVq/ZiaXiWpAHkuAD5r89upZCr6LR8lJzGd7yj1yE06tuH7B3odlmzcmrAgTKksgSw8JQIil8H3MH/8l1PWURQAvLjjd81uBHCMNMFg5X4/EHzY6p8uAsNFg8uhtA== X-Gm-Message-State: AOJu0Yx01OMrSax1OBzQUV9MAoWBT14imnRSPIyVVKKhrudACzJZsWIw 3t2pXJt29Fgj0sEzyaUnYV4Td7VMSOHEdb6KxlUEWUycPRqPSwWq2Klf5mLgRzRdgw== X-Google-Smtp-Source: AGHT+IHHm+TDZRglPiiRkLKb6SuE5RVgytQew9CNWxKGx2am4i3JVQsHb2g0wvpJdsNTegdr9JGJ0g== X-Received: by 2002:a05:6402:2114:b0:58c:a94b:9356 with SMTP id 4fb4d7f45d1cf-594baf910e8mr9999918a12.18.1720860333769; Sat, 13 Jul 2024 01:45:33 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:cc91:0:b0:585:2014:4d17 with SMTP id 4fb4d7f45d1cf-59821dad88cls1502935a12.0.-pod-prod-09-eu; Sat, 13 Jul 2024 01:45:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVzR3qmM1VhIZVdcn2BqON25opnHhqqzMsLRXPThYdTBWry6qMUIyV+71aUPyzbC0qnaeixVlYc+2EDhdeqV6QeZ9uPlkrCr97qg9mWYjbxcoZq X-Received: by 2002:a17:907:d90:b0:a77:d773:54e0 with SMTP id a640c23a62f3a-a780b89ea4emr1170564266b.68.1720860331944; Sat, 13 Jul 2024 01:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720860331; cv=none; d=google.com; s=arc-20160816; b=Pygm8SSGw0+4yOpj6W6Nj0PAI/2STkFTqvPBudP7xTccN9aKaAuBVN/vNsjvEHhHL7 jILy5grfdGNCT1rL6Pjyd7GbzS4yo2HNNNQrNFz4OMufFLaeVU0UA/j9w++E37t73TPu 2gjvxkzGJo47GPtPmPZ+1jhXR6lzal40GUOyDoErM5vMlfTjv7UtHSk0MgT86I/8luTM juFX+zckvPNdSlWeM2u1OleM9fPJZlHpeWfORXPuO7dPCShTUJCbzeJmMsZHHqgxFPxv xxiTL4BKLepk+/YPEVmi3rvTs0LcVqBP1oOXhtdKTC1LCUvK4hEOjEshugPuAxqOr2ft Nofg== 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=mLFlSS3LOz2z5PbDNHqhhOO8pKuSllLzwO6lu7HBbUw=; fh=P6Gag59oPNPqoNeya0/1dv9MKI/rJeDEfqjhXm61znA=; b=lqpKDlLJp3tWNG360Jpp4k5/GYKI+W36RlN0Tg1p/IA+fZVAT8xpxQNYJCvGV3ChHs t1200/+8/ncRhtZJMLLFmB5T6TDovwzFSUpQivhC1HQAQX0g+wR0SLlb7ZTKf70qBQTW vAEu9qvp3e1DfEyazqcMXm18+C4wv7ogigoU8iOvut/3hxsjceJS9M4E4nyaeqdKfKQ1 s4X1Q1Eq88hDGfXcZhlQZd4HeteJLqvywWh1KH+6tdaeWlqZn2XZHAshMxABaGaesetB LOf2IUpaeJaoYbqnXQL47bKg1zaWepml5nBh07Qgn2W3ckWe421G8sj9DRgWGrUV7/D6 jfmQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MWfruml6; 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 a640c23a62f3a-a79bc87eb59sor10557166b.19.2024.07.13.01.45.31 for (Google Transport Security); Sat, 13 Jul 2024 01:45:31 -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; AJvYcCXgsdhafXfKMZIVm4nDT5i/wo9rN8+9lNFQSM39iiiQ3AkBzbQXTKWoewHf0S3Bo3x0uNhQCNZ/1mKqUTmEDsQOoXORwvNVLCz85j6kQ6CBswBc X-Received: by 2002:a17:907:2d2c:b0:a77:cacf:58b5 with SMTP id a640c23a62f3a-a780b68a364mr1237583266b.1.1720860331281; Sat, 13 Jul 2024 01:45:31 -0700 (PDT) Received: from panicking.amarulasolutions.com (93-35-128-17.ip55.fastwebnet.it. [93.35.128.17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1e20sm31483966b.116.2024.07.13.01.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 01:45:30 -0700 (PDT) From: Michael Trimarchi To: Michael Trimarchi Cc: Dario Binacchi , Patrick Barsanti , linux-amarula@amarulasolutions.com, Sam Protsenko Subject: [PATCH 01/21] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present for gate and mux Date: Sat, 13 Jul 2024 10:45:06 +0200 Message-ID: <20240713084526.922537-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=MWfruml6; 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(-) diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index bf1c6a93b4..bd0d3d44ac 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 62477e15d2..4feb8e8c82 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 4c832f1a53..d768e5ad2e 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -516,6 +516,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 b8c2e8d531..67c6b23231 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 af23e4f347..1900377edd 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 59f9c241b8..459fa2d15c 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);