From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Cc: Peng Fan <peng.fan@nxp.com>,
Eugen Hristev <eugen.hristev@microchip.com>,
Claudiu Beznea <claudiu.beznea@microchip.com>,
Cyril Jean <cyril.jean@microchip.com>,
Lukasz Majewski <lukma@denx.de>,
Giulio Benetti <giulio.benetti@benettiengineering.com>,
Sean Anderson <seanga2@gmail.com>
Subject: [PATCH 1/2] clk: ccf: Add some helper functions for clock ops
Date: Sun, 20 Mar 2022 16:34:45 -0400 [thread overview]
Message-ID: <20220320203446.740178-1-seanga2@gmail.com> (raw)
Most CCF drivers follow a common pattern where their clock ops defer the
actual operation to the backing CCF clock. Add some generic implementations
of these functions to reduce duplication of code.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
drivers/clk/clk.c | 65 ++++++++++++++++++++++++++++++++++++
include/linux/clk-provider.h | 8 +++++
2 files changed, 73 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index eff0fa134f..a5a3461b66 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -74,3 +74,68 @@ bool clk_dev_binded(struct clk *clk)
return false;
}
+
+/* Helper functions for clock ops */
+
+ulong ccf_clk_get_rate(struct clk *clk)
+{
+ struct clk *c;
+ int err = clk_get_by_id(clk->id, &c);
+
+ if (err)
+ return err;
+ return clk_get_rate(c);
+}
+
+ulong ccf_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+ struct clk *c;
+ int err = clk_get_by_id(clk->id, &c);
+
+ if (err)
+ return err;
+ return clk_set_rate(c, rate);
+}
+
+int ccf_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+ struct clk *c, *p;
+ int err = clk_get_by_id(clk->id, &c);
+
+ if (err)
+ return err;
+
+ err = clk_get_by_id(parent->id, &p);
+ if (err)
+ return err;
+
+ return clk_set_parent(c, p);
+}
+
+static int ccf_clk_endisable(struct clk *clk, bool enable)
+{
+ struct clk *c;
+ int err = clk_get_by_id(clk->id, &c);
+
+ if (err)
+ return err;
+ return enable ? clk_enable(c) : clk_disable(c);
+}
+
+int ccf_clk_enable(struct clk *clk)
+{
+ return ccf_clk_endisable(clk, true);
+}
+
+int ccf_clk_disable(struct clk *clk)
+{
+ return ccf_clk_endisable(clk, false);
+}
+
+const struct clk_ops ccf_clk_ops = {
+ .set_rate = ccf_clk_set_rate,
+ .get_rate = ccf_clk_get_rate,
+ .set_parent = ccf_clk_set_parent,
+ .enable = ccf_clk_enable,
+ .disable = ccf_clk_disable,
+};
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 9a6116646d..2d04882d05 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -254,4 +254,12 @@ const char *clk_hw_get_name(const struct clk *hw);
ulong clk_generic_get_rate(struct clk *clk);
struct clk *dev_get_clk_ptr(struct udevice *dev);
+
+ulong ccf_clk_get_rate(struct clk *clk);
+ulong ccf_clk_set_rate(struct clk *clk, unsigned long rate);
+int ccf_clk_set_parent(struct clk *clk, struct clk *parent);
+int ccf_clk_enable(struct clk *clk);
+int ccf_clk_disable(struct clk *clk);
+extern const struct clk_ops ccf_clk_ops;
+
#endif /* __LINUX_CLK_PROVIDER_H */
--
2.34.1
next reply other threads:[~2022-03-20 20:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-20 20:34 Sean Anderson [this message]
2022-03-20 20:34 ` [PATCH 2/2] clk: Use generic CCF ops where possible Sean Anderson
2022-03-21 1:30 ` Peng Fan (OSS)
2022-03-21 13:24 ` Claudiu.Beznea
2022-03-30 19:21 ` Sean Anderson
2022-03-21 1:29 ` [PATCH 1/2] clk: ccf: Add some helper functions for clock ops Peng Fan (OSS)
2022-03-30 19:21 ` Sean Anderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220320203446.740178-1-seanga2@gmail.com \
--to=seanga2@gmail.com \
--cc=claudiu.beznea@microchip.com \
--cc=cyril.jean@microchip.com \
--cc=eugen.hristev@microchip.com \
--cc=giulio.benetti@benettiengineering.com \
--cc=lukma@denx.de \
--cc=peng.fan@nxp.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox