From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: linux-kernel@vger.kernel.org
Cc: angelo@amarulasolutions.com, michael@amarulasolutions.com,
tommaso.merciai@amarulasolutions.com,
Chen-Yu Tsai <wenst@chromium.org>,
linux-amarula@amarulasolutions.com, anthony@amarulasolutions.com,
jagan@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Abel Vesa <abelvesa@kernel.org>,
Fabio Estevam <festevam@gmail.com>,
Michael Turquette <mturquette@baylibre.com>,
NXP Linux Team <linux-imx@nxp.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
Shawn Guo <shawnguo@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org
Subject: [RFC PATCH v2 03/11] clk: imx8mn: add gate driver
Date: Sun, 1 Jan 2023 18:57:32 +0100 [thread overview]
Message-ID: <20230101175740.1010258-4-dario.binacchi@amarulasolutions.com> (raw)
In-Reply-To: <20230101175740.1010258-1-dario.binacchi@amarulasolutions.com>
The patch adds support for imx8mn gate clocks to be initialized directly
from the device tree. Currently all i.MX gate clocks are initialized by
legacy code with hardwired parameters. This approach has generated a
proliferation of setup functions with unclear names:
git grep "#define imx_clk_hw_gate" drivers/clk/imx/clk.h
drivers/clk/imx/clk.h:#define imx_clk_hw_gate(name, parent, reg, shift) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate2(name, parent, reg, shift) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate_dis(name, parent, reg, shift) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate_dis_flags(name, parent, reg, shift, flags) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate_flags(name, parent, reg, shift, flags) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate2_flags(name, parent, reg, shift, flags) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate2_shared(name, parent, reg, shift, shared_count) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate2_shared2(name, parent, reg, shift, shared_count) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate3(name, parent, reg, shift) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate3_flags(name, parent, reg, shift, flags) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate4(name, parent, reg, shift) \
drivers/clk/imx/clk.h:#define imx_clk_hw_gate4_flags(name, parent, reg, shift, flags) \
So, let's start with this specific clock driver and hope that other
variants can be handled in the future, causing the legacy code to be
removed.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
(no changes since v1)
drivers/clk/imx/Makefile | 1 +
drivers/clk/imx/clk-gate.c | 156 +++++++++++++++++++++++++++++++++++++
2 files changed, 157 insertions(+)
create mode 100644 drivers/clk/imx/clk-gate.c
diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile
index e8aacb0ee6ac..72e1f08d49dc 100644
--- a/drivers/clk/imx/Makefile
+++ b/drivers/clk/imx/Makefile
@@ -11,6 +11,7 @@ mxc-clk-objs += clk-divider-gate.o
mxc-clk-objs += clk-fixup-div.o
mxc-clk-objs += clk-fixup-mux.o
mxc-clk-objs += clk-frac-pll.o
+mxc-clk-objs += clk-gate.o
mxc-clk-objs += clk-gate2.o
mxc-clk-objs += clk-gate-93.o
mxc-clk-objs += clk-gate-exclusive.o
diff --git a/drivers/clk/imx/clk-gate.c b/drivers/clk/imx/clk-gate.c
new file mode 100644
index 000000000000..841ff9a37f30
--- /dev/null
+++ b/drivers/clk/imx/clk-gate.c
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Amarula Solutions
+ *
+ * Dario Binacchi <dario.binacchi@amarulasolutions.com>
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/regmap.h>
+
+#include "clk.h"
+
+#undef pr_fmt
+#define pr_fmt(fmt) "%s: " fmt, __func__
+
+#define to_clk_imx_gate(_hw) container_of(_hw, struct clk_imx_gate, hw)
+
+struct clk_imx_gate {
+ struct clk_hw hw;
+ struct imx_clk_reg reg;
+ u32 enable_mask;
+};
+
+static int imx_clk_gate_enable(struct clk_hw *hw)
+{
+ struct clk_imx_gate *gate = to_clk_imx_gate(hw);
+ struct imx_clk_reg *reg = &gate->reg;
+
+ return regmap_update_bits(reg->regmap, reg->offset, gate->enable_mask,
+ gate->enable_mask);
+}
+
+static void imx_clk_gate_disable(struct clk_hw *hw)
+{
+ struct clk_imx_gate *gate = to_clk_imx_gate(hw);
+ struct imx_clk_reg *reg = &gate->reg;
+
+ regmap_update_bits(reg->regmap, reg->offset, gate->enable_mask, 0);
+}
+
+static int imx_clk_gate_is_enabled(struct clk_hw *hw)
+{
+ struct clk_imx_gate *gate = to_clk_imx_gate(hw);
+ struct imx_clk_reg *reg = &gate->reg;
+ unsigned int val;
+
+ if (regmap_read(reg->regmap, reg->offset, &val))
+ return -EIO;
+
+ return !!(val & gate->enable_mask);
+}
+
+const struct clk_ops imx_clk_gate_ops = {
+ .enable = &imx_clk_gate_enable,
+ .disable = &imx_clk_gate_disable,
+ .is_enabled = &imx_clk_gate_is_enabled,
+};
+
+static void imx_clk_hw_unregister_gate(struct clk_hw *hw)
+{
+ struct clk_imx_gate *gate = to_clk_imx_gate(hw);
+
+ clk_hw_unregister(hw);
+ kfree(gate);
+}
+
+static struct clk_hw *imx_clk_hw_register_gate(struct device_node *node,
+ const char *name,
+ unsigned long flags,
+ struct imx_clk_reg *reg,
+ u8 enable_bit)
+{
+ struct clk_parent_data pdata = { .index = 0 };
+ struct clk_init_data init = { NULL };
+ struct clk_imx_gate *gate;
+ struct clk_hw *hw;
+ int ret;
+
+ gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+ if (!gate)
+ return ERR_PTR(-ENOMEM);
+
+ init.name = name;
+ init.flags = flags;
+ init.ops = &imx_clk_gate_ops;
+ init.parent_data = &pdata;
+ init.num_parents = 1;
+
+ memcpy(&gate->reg, reg, sizeof(*reg));
+ gate->enable_mask = BIT(enable_bit);
+ gate->hw.init = &init;
+
+ hw = &gate->hw;
+ ret = of_clk_hw_register(node, hw);
+ if (ret) {
+ kfree(gate);
+ return ERR_PTR(ret);
+ }
+
+ return hw;
+}
+
+/**
+ * of_imx_gate_clk_setup() - Setup function for imx gate clock
+ * @node: device node for the clock
+ */
+static void __init of_imx_gate_clk_setup(struct device_node *node)
+{
+ struct clk_hw *hw;
+ struct imx_clk_reg reg;
+ const char *name = node->name;
+ u8 enable_bit = 0;
+ u32 val;
+
+ reg.regmap = syscon_regmap_lookup_by_phandle(node, "fsl,anatop");
+ if (IS_ERR(reg.regmap)) {
+ pr_err("missing regmap for %pOFn\n", node);
+ return;
+ }
+
+ if (of_property_read_u32_index(node, "fsl,anatop", 1, &val)) {
+ pr_err("missing register offset for %pOFn\n", node);
+ return;
+ }
+
+ reg.offset = val;
+
+ if (!of_property_read_u32(node, "fsl,bit-shift", &val))
+ enable_bit = val;
+
+ if (of_clk_get_parent_count(node) != 1) {
+ pr_err("%pOFn must have 1 parent clock\n", node);
+ return;
+ }
+
+ of_property_read_string(node, "clock-output-names", &name);
+
+ hw = imx_clk_hw_register_gate(node, name, 0, ®, enable_bit);
+ if (IS_ERR(hw))
+ return;
+
+ if (of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw)) {
+ imx_clk_hw_unregister_gate(hw);
+ return;
+ }
+
+ pr_debug("name: %s, offset: 0x%x, enable-bit: %d\n", name, reg.offset,
+ enable_bit);
+}
+CLK_OF_DECLARE(fsl_imx8mn_gate_clk, "fsl,imx8mn-gate-clock",
+ of_imx_gate_clk_setup);
--
2.32.0
next prev parent reply other threads:[~2023-01-01 17:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-01 17:57 [RFC PATCH v2 00/11] clk: imx8mn: setup clocks from the device tree Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 01/11] clk: imx: add structure to extend register accesses Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 02/11] clk: imx: add clk_hw based API imx_get_clk_hw_from_dt() Dario Binacchi
2023-01-01 17:57 ` Dario Binacchi [this message]
2023-01-01 17:57 ` [RFC PATCH v2 04/11] clk: imx8mn: add mux driver Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 05/11] clk: imx8mn: add divider driver Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 06/11] clk: imx: pll14xx: add device tree support Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 07/11] clk: imx: composite-8m: " Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 08/11] clk: imx: gate2: " Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 09/11] clk: imx: cpu: " Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 10/11] arm64: dts: imx8mn: add dumy clock Dario Binacchi
2023-01-01 17:57 ` [RFC PATCH v2 11/11] arm64: dts: imx8mn: add clocks description Dario Binacchi
2023-01-16 14:35 ` Abel Vesa
2023-01-20 17:47 ` Dario Binacchi
2023-01-02 23:04 ` [RFC PATCH v2 00/11] clk: imx8mn: setup clocks from the device tree Marek Vasut
2023-01-04 16:09 ` Dario Binacchi
2023-01-25 21:10 ` Stephen Boyd
2023-01-26 10:49 ` Michael Nazzareno Trimarchi
2023-02-10 22:49 ` Stephen Boyd
2023-02-11 9:19 ` Michael Nazzareno Trimarchi
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=20230101175740.1010258-4-dario.binacchi@amarulasolutions.com \
--to=dario.binacchi@amarulasolutions.com \
--cc=abelvesa@kernel.org \
--cc=angelo@amarulasolutions.com \
--cc=anthony@amarulasolutions.com \
--cc=festevam@gmail.com \
--cc=jagan@amarulasolutions.com \
--cc=kernel@pengutronix.de \
--cc=linux-amarula@amarulasolutions.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@amarulasolutions.com \
--cc=mturquette@baylibre.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
--cc=tommaso.merciai@amarulasolutions.com \
--cc=wenst@chromium.org \
/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
all inboxes | Powered by JetHome®