Skip to contentSkip to conversation

dt-bindings: add binding for i.MX8MQ CCM

PATCH Superseded Abel Vesa 6 participants 25 messages Sep 24, 2018 – Nov 14, 2018 1 message not in the archive

Subsystems (4)

v9 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Abel Vesa

author
#1 lore raw

PATCH v9 1/5 dt-bindings: add binding for i.MX8MQ CCM

From: Lucas Stach <[email protected]>

This adds the binding for the i.MX8MQ Clock Controller Module.

---
 .../devicetree/bindings/clock/imx8mq-clock.txt     |  20 ++
 include/dt-bindings/clock/imx8mq-clock.h           | 395 +++++++++++++++++++++
 2 files changed, 415 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/imx8mq-clock.txt
 create mode 100644 include/dt-bindings/clock/imx8mq-clock.h
Documentation/devicetree/bindings/clock/imx8mq-clock.txt new file +20 -0
new file mode 100644
index 0000000..52de826
@@ -0,0 +1,20 @@
+* Clock bindings for NXP i.MX8M Quad
+
+Required properties:
+- compatible: Should be "fsl,imx8mq-ccm"
+- reg: Address and length of the register set
+- #clock-cells: Should be <1>
+- clocks: list of clock specifiers, must contain an entry for each required
+          entry in clock-names
+- clock-names: should include the following entries:
+    - "ckil"
+    - "osc_25m"
+    - "osc_27m"
+    - "clk_ext1"
+    - "clk_ext2"
+    - "clk_ext3"
+    - "clk_ext4"
+
+The clock consumer should specify the desired clock by having the clock
+ID in its "clocks" phandle cell.  See include/dt-bindings/clock/imx8mq-clock.h
+for the full list of i.MX8M Quad clock IDs.
include/dt-bindings/clock/imx8mq-clock.h new file +395 -0

395 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v9 2/5 clk: imx: add fractional PLL output clock

In reply to a message not in the archive

From: Lucas Stach <[email protected]>

This is a new clock type introduced on i.MX8.

---
 drivers/clk/imx/Makefile       |   1 +
 drivers/clk/imx/clk-frac-pll.c | 215 +++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h          |   3 +
 3 files changed, 219 insertions(+)
 create mode 100644 drivers/clk/imx/clk-frac-pll.c
drivers/clk/imx/Makefile +1 -0
index 8c3baa7..4893c1f 100644
@@ -6,6 +6,7 @@ obj-y += \
 	clk-cpu.o \
 	clk-fixup-div.o \
 	clk-fixup-mux.o \
+	clk-frac-pll.o \
 	clk-gate-exclusive.o \
 	clk-gate2.o \
 	clk-pllv1.o \
drivers/clk/imx/clk-frac-pll.c new file +215 -0

215 lines not on this page · raw message

drivers/clk/imx/clk.h +3 -0
index 8076ec0..13daf1c 100644
@@ -27,6 +27,9 @@ struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
 struct clk *imx_clk_pllv2(const char *name, const char *parent,
 		void __iomem *base);
 
+struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
+			     void __iomem *base);
+
 enum imx_pllv3_type {
 	IMX_PLLV3_GENERIC,
 	IMX_PLLV3_SYS,
Signature · 1 line
2.7.4
maintainer
#4 lore raw

Re: [PATCH v9 2/5] clk: imx: add fractional PLL output clock

Quoting Abel Vesa (2018-09-24 03:39:54)

Quoted 3 lines

From: Lucas Stach <[email protected]>

This is a new clock type introduced on i.MX8.

Ok, what's the clock type? Add another sentence please.

Quoted 3 lines

[..]

Quoted 6 lines
drivers/clk/imx/clk-frac-pll.c new file +0 -0
new file mode 100644
index 0000000..030df76

drivers/clk/imx/clk-frac-pll.c line 10

Quoted 10 lines
drivers/clk/imx/clk-frac-pll.c new file +10 -0
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 NXP.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/jiffies.h>

Is this used for something?

Quoted 4 lines
drivers/clk/imx/clk-frac-pll.c new file +4 -0
+#include <linux/slab.h>
+#include <linux/bitfield.h>
+
+#include "clk.h"

[...]

drivers/clk/imx/clk-frac-pll.c line 102

Quoted 13 lines
drivers/clk/imx/clk-frac-pll.c new file +13 -0
+
+static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
+       u32 val, divff, divfi, divq;
+       u64 temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       divq = ((val & PLL_OUTPUT_DIV_MASK) + 1) * 2;
+       val = readl_relaxed(pll->base + PLL_CFG1);
+       divff = FIELD_GET(PLL_FRAC_DIV_MASK, val);
+       divfi = (val & PLL_INT_DIV_MASK);

Nitpick: Drop useless parenthesis please.

Quoted 7 lines
drivers/clk/imx/clk-frac-pll.c new file +7 -0
+
+       temp64 = (u64)parent_rate * 8;
+       temp64 *= divff;
+       do_div(temp64, PLL_FRAC_DENOM);
+       temp64 /= divq;
+
+       return parent_rate * 8 * (divfi + 1) / divq + (unsigned long)temp64;

drivers/clk/imx/clk-frac-pll.c line 119

Quoted 10 lines
drivers/clk/imx/clk-frac-pll.c new file +10 -0
+}
+
+static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+                              unsigned long *prate)
+{
+       unsigned long parent_rate = *prate;
+       u32 divff, divfi;
+       u64 temp64;
+
+       parent_rate *= 8;

And parent_rate can't overflow if it's a u32? Maybe it could be a u64 so that we don't need casting later on in this function.

Quoted 30 lines
drivers/clk/imx/clk-frac-pll.c new file +30 -0
+       rate *= 2;
+       divfi = rate / parent_rate;
+       temp64 = (u64)(rate - divfi * parent_rate);
+       temp64 *= PLL_FRAC_DENOM;
+       do_div(temp64, parent_rate);
+       divff = temp64;
+
+       temp64 = (u64)parent_rate;
+       temp64 *= divff;
+       do_div(temp64, PLL_FRAC_DENOM);
+
+       return (parent_rate * divfi + (unsigned long)temp64) / 2;
+}
+
+/*
+ * To simplify the clock calculation, we can keep the 'PLL_OUTPUT_VAL' at zero
+ * (means the PLL output will be divided by 2). So the PLL output can use
+ * the below formula:
+ * pllout = parent_rate * 8 / 2 * DIVF_VAL;
+ * where DIVF_VAL = 1 + DIVFI + DIVFF / 2^24.
+ */
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
+{
+       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
+       u32 val, divfi, divff;
+       u64 temp64;
+       int ret;
+
+       parent_rate *= 8;

drivers/clk/imx/clk-frac-pll.c line 159

Quoted 10 lines
drivers/clk/imx/clk-frac-pll.c new file +10 -0
+       rate *= 2;
+       divfi = rate / parent_rate;
+       temp64 = (u64) (rate - divfi * parent_rate);
+       temp64 *= PLL_FRAC_DENOM;
+       do_div(temp64, parent_rate);
+       divff = temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG1);
+       val &= ~(PLL_FRAC_DIV_MASK | PLL_INT_DIV_MASK);
+       val |= ((divff << 7) | (divfi - 1));

Nitpick: Drop the extra parenthesis please.

Quoted 41 lines
drivers/clk/imx/clk-frac-pll.c new file +41 -0
+       writel_relaxed(val, pll->base + PLL_CFG1);
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~0x1f;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       /* Set the NEV_DIV_VAL to reload the DIVFI and DIVFF */
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val |= PLL_NEWDIV_VAL;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       ret = clk_wait_ack(pll);
+
+       /* clear the NEV_DIV_VAL */
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~PLL_NEWDIV_VAL;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       return ret;
+}
+
+static const struct clk_ops clk_frac_pll_ops = {
+       .prepare        = clk_pll_prepare,
+       .unprepare      = clk_pll_unprepare,
+       .is_prepared    = clk_pll_is_prepared,
+       .recalc_rate    = clk_pll_recalc_rate,
+       .round_rate     = clk_pll_round_rate,
+       .set_rate       = clk_pll_set_rate,
+};
+
+struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
+                            void __iomem *base)
+{
+       struct clk_init_data init;
+       struct clk_frac_pll *pll;
+       struct clk *clk;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+

drivers/clk/imx/clk-frac-pll.c line 210

Quoted 10 lines
drivers/clk/imx/clk-frac-pll.c new file +10 -0
+       pll->base = base;
+       init.name = name;
+       init.ops = &clk_frac_pll_ops;
+       init.flags = 0;
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+
+       pll->hw.init = &init;
+
+       clk = clk_register(NULL, &pll->hw);

clk_hw based please.

Quoted 5 lines
drivers/clk/imx/clk-frac-pll.c new file +5 -0
+       if (IS_ERR(clk))
+               kfree(pll);
+
+       return clk;
+}
author
#5 lore raw

Re: [PATCH v9 2/5] clk: imx: add fractional PLL output clock

Quoted 7 lines · Stephen Boyd

Quoting Abel Vesa (2018-09-24 03:39:54)

Quoted 3 lines

From: Lucas Stach <[email protected]>

This is a new clock type introduced on i.MX8.

Ok, what's the clock type? Add another sentence please.

Added in the next version a link with the pdf describing the hardware and specified in the commit message that is a fractional clock.

Quoted 14 lines
Quoted 3 lines

[..]

Quoted 10 lines
drivers/clk/imx/clk-frac-pll.c new file +4 -0
new file mode 100644
index 0000000..030df76
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 NXP.
+ */
Quoted 9 lines

drivers/clk/imx/clk-frac-pll.c line 10

Quoted 6 lines
drivers/clk/imx/clk-frac-pll.c new file +6 -0
+
+#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/jiffies.h>

Is this used for something?

Removed in the next version.

Quoted 5 lines
Quoted 4 lines
drivers/clk/imx/clk-frac-pll.c new file +4 -0
+#include <linux/slab.h>
+#include <linux/bitfield.h>
+
+#include "clk.h"

[...]

Quoted 16 lines

drivers/clk/imx/clk-frac-pll.c line 102

Quoted 13 lines
drivers/clk/imx/clk-frac-pll.c new file +13 -0
+
+static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
+       u32 val, divff, divfi, divq;
+       u64 temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       divq = ((val & PLL_OUTPUT_DIV_MASK) + 1) * 2;
+       val = readl_relaxed(pll->base + PLL_CFG1);
+       divff = FIELD_GET(PLL_FRAC_DIV_MASK, val);
+       divfi = (val & PLL_INT_DIV_MASK);

Nitpick: Drop useless parenthesis please.

Removed in the next version.

Quoted 12 lines
Quoted 12 lines
drivers/clk/imx/clk-frac-pll.c new file +12 -0
+
+       temp64 = (u64)parent_rate * 8;
+       temp64 *= divff;
+       do_div(temp64, PLL_FRAC_DENOM);
+       temp64 /= divq;
+
+       return parent_rate * 8 * (divfi + 1) / divq + (unsigned long)temp64;
+}
+
+static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+                              unsigned long *prate)
+{
Quoted 9 lines

drivers/clk/imx/clk-frac-pll.c line 119

Quoted 5 lines
drivers/clk/imx/clk-frac-pll.c new file +5 -0
+       unsigned long parent_rate = *prate;
+       u32 divff, divfi;
+       u64 temp64;
+
+       parent_rate *= 8;

And parent_rate can't overflow if it's a u32? Maybe it could be a u64 so that we don't need casting later on in this function.

Fixed in the next version.

Quoted 34 lines
Quoted 34 lines
drivers/clk/imx/clk-frac-pll.c new file +34 -0
+       rate *= 2;
+       divfi = rate / parent_rate;
+       temp64 = (u64)(rate - divfi * parent_rate);
+       temp64 *= PLL_FRAC_DENOM;
+       do_div(temp64, parent_rate);
+       divff = temp64;
+
+       temp64 = (u64)parent_rate;
+       temp64 *= divff;
+       do_div(temp64, PLL_FRAC_DENOM);
+
+       return (parent_rate * divfi + (unsigned long)temp64) / 2;
+}
+
+/*
+ * To simplify the clock calculation, we can keep the 'PLL_OUTPUT_VAL' at zero
+ * (means the PLL output will be divided by 2). So the PLL output can use
+ * the below formula:
+ * pllout = parent_rate * 8 / 2 * DIVF_VAL;
+ * where DIVF_VAL = 1 + DIVFI + DIVFF / 2^24.
+ */
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
+{
+       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
+       u32 val, divfi, divff;
+       u64 temp64;
+       int ret;
+
+       parent_rate *= 8;
+       rate *= 2;
+       divfi = rate / parent_rate;
+       temp64 = (u64) (rate - divfi * parent_rate);
+       temp64 *= PLL_FRAC_DENOM;
Quoted 9 lines

drivers/clk/imx/clk-frac-pll.c line 159

Quoted 6 lines
drivers/clk/imx/clk-frac-pll.c new file +6 -0
+       do_div(temp64, parent_rate);
+       divff = temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG1);
+       val &= ~(PLL_FRAC_DIV_MASK | PLL_INT_DIV_MASK);
+       val |= ((divff << 7) | (divfi - 1));

Nitpick: Drop the extra parenthesis please.

Removed in the next version.

Quoted 45 lines
Quoted 45 lines
drivers/clk/imx/clk-frac-pll.c new file +45 -0
+       writel_relaxed(val, pll->base + PLL_CFG1);
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~0x1f;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       /* Set the NEV_DIV_VAL to reload the DIVFI and DIVFF */
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val |= PLL_NEWDIV_VAL;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       ret = clk_wait_ack(pll);
+
+       /* clear the NEV_DIV_VAL */
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~PLL_NEWDIV_VAL;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       return ret;
+}
+
+static const struct clk_ops clk_frac_pll_ops = {
+       .prepare        = clk_pll_prepare,
+       .unprepare      = clk_pll_unprepare,
+       .is_prepared    = clk_pll_is_prepared,
+       .recalc_rate    = clk_pll_recalc_rate,
+       .round_rate     = clk_pll_round_rate,
+       .set_rate       = clk_pll_set_rate,
+};
+
+struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
+                            void __iomem *base)
+{
+       struct clk_init_data init;
+       struct clk_frac_pll *pll;
+       struct clk *clk;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->base = base;
+       init.name = name;
+       init.ops = &clk_frac_pll_ops;
+       init.flags = 0;
Quoted 9 lines

drivers/clk/imx/clk-frac-pll.c line 210

Quoted 6 lines
drivers/clk/imx/clk-frac-pll.c new file +6 -0
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+
+       pll->hw.init = &init;
+
+       clk = clk_register(NULL, &pll->hw);

clk_hw based please.

Fixed in the next version.

Quoted 5 lines
Quoted 5 lines
drivers/clk/imx/clk-frac-pll.c new file +5 -0
+       if (IS_ERR(clk))
+               kfree(pll);
+
+       return clk;
+}
author
#6 lore raw

PATCH v9 3/5 clk: imx: add SCCG PLL type

In reply to a message not in the archive

From: Lucas Stach <[email protected]>

The SCCG is a new PLL type introduced on i.MX8. Add support for this. The driver currently misses the PLL lock check, as the preliminary documentation mentions lock configurations, but is quiet about where to find the actual lock status signal.

---
 drivers/clk/imx/Makefile       |   3 +-
 drivers/clk/imx/clk-sccg-pll.c | 237 +++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h          |   9 ++
 3 files changed, 248 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/imx/clk-sccg-pll.c
drivers/clk/imx/Makefile +2 -1
index 4893c1f..b87513c 100644
@@ -12,7 +12,8 @@ obj-y += \
 	clk-pllv1.o \
 	clk-pllv2.o \
 	clk-pllv3.o \
-	clk-pfd.o
+	clk-pfd.o \
+	clk-sccg-pll.o
 
 obj-$(CONFIG_SOC_IMX1)   += clk-imx1.o
 obj-$(CONFIG_SOC_IMX21)  += clk-imx21.o
drivers/clk/imx/clk-sccg-pll.c new file +237 -0

237 lines not on this page · raw message

drivers/clk/imx/clk.h +9 -0
index 13daf1c..12b3fd6 100644
@@ -21,6 +21,11 @@ enum imx_pllv1_type {
 	IMX_PLLV1_IMX35,
 };
 
+enum imx_sccg_pll_type {
+	SCCG_PLL1,
+	SCCG_PLL2,
+};
+
 struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
 		const char *parent, void __iomem *base);
 
@@ -30,6 +35,10 @@ struct clk *imx_clk_pllv2(const char *name, const char *parent,
 struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
 			     void __iomem *base);
 
+struct clk *imx_clk_sccg_pll(const char *name, const char *parent_name,
+			     void __iomem *base,
+			     enum imx_sccg_pll_type pll_type);
+
 enum imx_pllv3_type {
 	IMX_PLLV3_GENERIC,
 	IMX_PLLV3_SYS,
Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoting Abel Vesa (2018-09-24 03:39:55)

drivers/clk/imx/clk-sccg-pll.c line 6

Quoted 12 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
new file mode 100644
index 0000000..a9837fa
@@ -0,0 +1,237 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright 2018 NXP.
+ */
+
+#include <linux/clk.h>

Is this include used? Otherwise should see clk-provider.h included here.

Quoted 61 lines
drivers/clk/imx/clk-sccg-pll.c new file +61 -0
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitfield.h>
+
+#include "clk.h"
+
+/* PLL CFGs */
+#define PLL_CFG0               0x0
+#define PLL_CFG1               0x4
+#define PLL_CFG2               0x8
+
+#define PLL_DIVF1_MASK         GENMASK(18, 13)
+#define PLL_DIVF2_MASK         GENMASK(12, 7)
+#define PLL_DIVR1_MASK         GENMASK(27, 25)
+#define PLL_DIVR2_MASK         GENMASK(24, 19)
+#define PLL_REF_MASK           GENMASK(2, 0)
+
+#define PLL_LOCK_MASK          BIT(31)
+#define PLL_PD_MASK            BIT(7)
+
+#define OSC_25M                        25000000
+#define OSC_27M                        27000000
+
+#define PLL_SCCG_LOCK_TIMEOUT  70
+
+struct clk_sccg_pll {
+       struct clk_hw   hw;
+       void __iomem    *base;
+};
+
+#define to_clk_sccg_pll(_hw) container_of(_hw, struct clk_sccg_pll, hw)
+
+static int clk_pll_wait_lock(struct clk_sccg_pll *pll)
+{
+       u32 val;
+
+       return readl_poll_timeout(pll->base, val, val & PLL_LOCK_MASK, 0,
+                                       PLL_SCCG_LOCK_TIMEOUT);
+}
+
+static int clk_pll1_is_prepared(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       return (val & PLL_PD_MASK) ? 0 : 1;
+}
+
+static unsigned long clk_pll1_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, divf;
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divf = FIELD_GET(PLL_DIVF1_MASK, val);
+

drivers/clk/imx/clk-sccg-pll.c line 77

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       return parent_rate * 2 * (divf + 1);
+}
+
+static long clk_pll1_round_rate(struct clk_hw *hw, unsigned long rate,
+                              unsigned long *prate)
+{
+       unsigned long parent_rate = *prate;
+       u32 div;
+
+       div = rate / (parent_rate * 2);

Can parent_rate be 0?

drivers/clk/imx/clk-sccg-pll.c line 89

Quoted 12 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+       return parent_rate * div * 2;
+}
+
+static int clk_pll1_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+       u32 divf;
+
+       divf = rate / (parent_rate * 2);

Can parent_rate be 0?

Quoted 39 lines
drivers/clk/imx/clk-sccg-pll.c new file +39 -0
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~PLL_DIVF1_MASK;
+       val |= FIELD_PREP(PLL_DIVF1_MASK, divf - 1);
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static int clk_pll1_prepare(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~PLL_PD_MASK;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static void clk_pll1_unprepare(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val |= PLL_PD_MASK;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+}
+
+static unsigned long clk_pll2_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, ref, divr1, divf1, divr2, divf2;
+       u64 temp64;
+

drivers/clk/imx/clk-sccg-pll.c line 138

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       switch (FIELD_GET(PLL_REF_MASK, val)) {
+       case 0:
+               ref = OSC_25M;
+               break;
+       case 1:
+               ref = OSC_27M;
+               break;
+       default:
+               ref = OSC_25M;

Does this information not come through 'parent_rate'?

drivers/clk/imx/clk-sccg-pll.c line 151

Quoted 13 lines
drivers/clk/imx/clk-sccg-pll.c new file +13 -0
+               break;
+       }
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divr1 = FIELD_GET(PLL_DIVR1_MASK, val);
+       divr2 = FIELD_GET(PLL_DIVR2_MASK, val);
+       divf1 = FIELD_GET(PLL_DIVF1_MASK, val);
+       divf2 = FIELD_GET(PLL_DIVF2_MASK, val);
+
+       temp64 = ref * 2;
+       temp64 *= (divf1 + 1) * (divf2 + 1);
+
+       do_div(temp64, (divr1 + 1) * (divr2 + 1));

Nitpicks: A comment with the equation may be helpful to newcomers.

drivers/clk/imx/clk-sccg-pll.c line 153

Quoted 2 lines
drivers/clk/imx/clk-sccg-pll.c new file +2 -0
+
+       return (unsigned long)temp64;

Drop useless cast please.

Quoted 11 lines
drivers/clk/imx/clk-sccg-pll.c new file +11 -0
+}
+
+static long clk_pll2_round_rate(struct clk_hw *hw, unsigned long rate,
+                              unsigned long *prate)
+{
+       u32 div;
+       unsigned long parent_rate = *prate;
+
+       div = rate / (parent_rate);
+
+       return parent_rate * div;

drivers/clk/imx/clk-sccg-pll.c line 174

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+}
+
+static int clk_pll2_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
+{
+       u32 val;
+       u32 divf;
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+
+       divf = rate / (parent_rate);

Drop useless parenthesis please.

Quoted 39 lines
drivers/clk/imx/clk-sccg-pll.c new file +39 -0
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~PLL_DIVF2_MASK;
+       val |= FIELD_PREP(PLL_DIVF2_MASK, divf - 1);
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static const struct clk_ops clk_sccg_pll1_ops = {
+       .is_prepared    = clk_pll1_is_prepared,
+       .recalc_rate    = clk_pll1_recalc_rate,
+       .round_rate     = clk_pll1_round_rate,
+       .set_rate       = clk_pll1_set_rate,
+};
+
+static const struct clk_ops clk_sccg_pll2_ops = {
+       .prepare        = clk_pll1_prepare,
+       .unprepare      = clk_pll1_unprepare,
+       .recalc_rate    = clk_pll2_recalc_rate,
+       .round_rate     = clk_pll2_round_rate,
+       .set_rate       = clk_pll2_set_rate,
+};
+
+struct clk *imx_clk_sccg_pll(const char *name,
+                               const char *parent_name,
+                               void __iomem *base,
+                               enum imx_sccg_pll_type pll_type)
+{
+       struct clk_sccg_pll *pll;
+       struct clk *clk;
+       struct clk_init_data init;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->base = base;
+       init.name = name;

drivers/clk/imx/clk-sccg-pll.c line 223

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       switch (pll_type) {
+       case SCCG_PLL1:
+               init.ops = &clk_sccg_pll1_ops;
+               break;
+       case SCCG_PLL2:
+               init.ops = &clk_sccg_pll2_ops;
+               break;
+       default:
+               kfree(pll);
+               return ERR_PTR(-EINVAL);

Do this case statement before allocating? So that kfree() isn't required here?

drivers/clk/imx/clk-sccg-pll.c line 232

Quoted 9 lines
drivers/clk/imx/clk-sccg-pll.c new file +9 -0
+       }
+
+       init.flags = 0;
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+
+       pll->hw.init = &init;
+
+       clk = clk_register(NULL, &pll->hw);

Any chance to use clk_hw based registration APIs?

Quoted 4 lines
drivers/clk/imx/clk-sccg-pll.c new file +4 -0
+       if (IS_ERR(clk))
+               kfree(pll);
+
+       return clk;
author
#8 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoted 16 lines · Stephen Boyd

Quoting Abel Vesa (2018-09-24 03:39:55)

drivers/clk/imx/clk-sccg-pll.c line 6

Quoted 12 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
new file mode 100644
index 0000000..a9837fa
@@ -0,0 +1,237 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright 2018 NXP.
+ */
+
+#include <linux/clk.h>

Is this include used? Otherwise should see clk-provider.h included here.

Fixed in the next version.

Quoted 65 lines
Quoted 65 lines
drivers/clk/imx/clk-sccg-pll.c new file +65 -0
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitfield.h>
+
+#include "clk.h"
+
+/* PLL CFGs */
+#define PLL_CFG0               0x0
+#define PLL_CFG1               0x4
+#define PLL_CFG2               0x8
+
+#define PLL_DIVF1_MASK         GENMASK(18, 13)
+#define PLL_DIVF2_MASK         GENMASK(12, 7)
+#define PLL_DIVR1_MASK         GENMASK(27, 25)
+#define PLL_DIVR2_MASK         GENMASK(24, 19)
+#define PLL_REF_MASK           GENMASK(2, 0)
+
+#define PLL_LOCK_MASK          BIT(31)
+#define PLL_PD_MASK            BIT(7)
+
+#define OSC_25M                        25000000
+#define OSC_27M                        27000000
+
+#define PLL_SCCG_LOCK_TIMEOUT  70
+
+struct clk_sccg_pll {
+       struct clk_hw   hw;
+       void __iomem    *base;
+};
+
+#define to_clk_sccg_pll(_hw) container_of(_hw, struct clk_sccg_pll, hw)
+
+static int clk_pll_wait_lock(struct clk_sccg_pll *pll)
+{
+       u32 val;
+
+       return readl_poll_timeout(pll->base, val, val & PLL_LOCK_MASK, 0,
+                                       PLL_SCCG_LOCK_TIMEOUT);
+}
+
+static int clk_pll1_is_prepared(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       return (val & PLL_PD_MASK) ? 0 : 1;
+}
+
+static unsigned long clk_pll1_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, divf;
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divf = FIELD_GET(PLL_DIVF1_MASK, val);
+
+       return parent_rate * 2 * (divf + 1);
+}
+
+static long clk_pll1_round_rate(struct clk_hw *hw, unsigned long rate,
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 77

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+                              unsigned long *prate)
+{
+       unsigned long parent_rate = *prate;
+       u32 div;
+
+       div = rate / (parent_rate * 2);

Can parent_rate be 0?

Fixed in the next version.

Quoted 6 lines
Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+
+       return parent_rate * div * 2;
+}
+
+static int clk_pll1_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 89

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+       u32 divf;
+
+       divf = rate / (parent_rate * 2);

Can parent_rate be 0?

Fixed in the next version.

Quoted 43 lines
Quoted 43 lines
drivers/clk/imx/clk-sccg-pll.c new file +43 -0
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~PLL_DIVF1_MASK;
+       val |= FIELD_PREP(PLL_DIVF1_MASK, divf - 1);
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static int clk_pll1_prepare(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val &= ~PLL_PD_MASK;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static void clk_pll1_unprepare(struct clk_hw *hw)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       val |= PLL_PD_MASK;
+       writel_relaxed(val, pll->base + PLL_CFG0);
+
+}
+
+static unsigned long clk_pll2_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, ref, divr1, divf1, divr2, divf2;
+       u64 temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       switch (FIELD_GET(PLL_REF_MASK, val)) {
+       case 0:
+               ref = OSC_25M;
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 138

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+               break;
+       case 1:
+               ref = OSC_27M;
+               break;
+       default:
+               ref = OSC_25M;

Does this information not come through 'parent_rate'?

No. So basically both pll1 and pll2 and the divider after it form together this SCCG:

https://www.nxp.com/docs/en/reference-manual/IMX8MDQLQRM.pdf#page=834

See: Figure 5-8. SSCG PLL Block Diagram

We're basically reading the input of the pll 1 in order to compute the output of the entire SCCG.

I know it's a mess. I'm working on cleaning it up, but for now we need this in in order to boot up.

Quoted 7 lines
Quoted 7 lines
drivers/clk/imx/clk-sccg-pll.c new file +7 -0
+               break;
+       }
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divr1 = FIELD_GET(PLL_DIVR1_MASK, val);
+       divr2 = FIELD_GET(PLL_DIVR2_MASK, val);
+       divf1 = FIELD_GET(PLL_DIVF1_MASK, val);
Quoted 8 lines

drivers/clk/imx/clk-sccg-pll.c line 151

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+       divf2 = FIELD_GET(PLL_DIVF2_MASK, val);
+
+       temp64 = ref * 2;
+       temp64 *= (divf1 + 1) * (divf2 + 1);
+
+       do_div(temp64, (divr1 + 1) * (divr2 + 1));

Nitpicks: A comment with the equation may be helpful to newcomers.

Since the SCCG is contructed by multiple different types of clocks here, the equation doesn't help since it is spread in all constructing blocks.

Quoted 6 lines

drivers/clk/imx/clk-sccg-pll.c line 153

Quoted 3 lines
drivers/clk/imx/clk-sccg-pll.c new file +2 -0
+
+       return (unsigned long)temp64;

Drop useless cast please.

Fixed in the next version.

Quoted 15 lines
Quoted 15 lines
drivers/clk/imx/clk-sccg-pll.c new file +15 -0
+}
+
+static long clk_pll2_round_rate(struct clk_hw *hw, unsigned long rate,
+                              unsigned long *prate)
+{
+       u32 div;
+       unsigned long parent_rate = *prate;
+
+       div = rate / (parent_rate);
+
+       return parent_rate * div;
+}
+
+static int clk_pll2_set_rate(struct clk_hw *hw, unsigned long rate,
+                           unsigned long parent_rate)
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 174

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+{
+       u32 val;
+       u32 divf;
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+
+       divf = rate / (parent_rate);

Drop useless parenthesis please.

Fixed in the next version.

Quoted 44 lines
Quoted 44 lines
drivers/clk/imx/clk-sccg-pll.c new file +44 -0
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~PLL_DIVF2_MASK;
+       val |= FIELD_PREP(PLL_DIVF2_MASK, divf - 1);
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       return clk_pll_wait_lock(pll);
+}
+
+static const struct clk_ops clk_sccg_pll1_ops = {
+       .is_prepared    = clk_pll1_is_prepared,
+       .recalc_rate    = clk_pll1_recalc_rate,
+       .round_rate     = clk_pll1_round_rate,
+       .set_rate       = clk_pll1_set_rate,
+};
+
+static const struct clk_ops clk_sccg_pll2_ops = {
+       .prepare        = clk_pll1_prepare,
+       .unprepare      = clk_pll1_unprepare,
+       .recalc_rate    = clk_pll2_recalc_rate,
+       .round_rate     = clk_pll2_round_rate,
+       .set_rate       = clk_pll2_set_rate,
+};
+
+struct clk *imx_clk_sccg_pll(const char *name,
+                               const char *parent_name,
+                               void __iomem *base,
+                               enum imx_sccg_pll_type pll_type)
+{
+       struct clk_sccg_pll *pll;
+       struct clk *clk;
+       struct clk_init_data init;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->base = base;
+       init.name = name;
+       switch (pll_type) {
+       case SCCG_PLL1:
+               init.ops = &clk_sccg_pll1_ops;
+               break;
+       case SCCG_PLL2:
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 223

Quoted 5 lines
drivers/clk/imx/clk-sccg-pll.c new file +5 -0
+               init.ops = &clk_sccg_pll2_ops;
+               break;
+       default:
+               kfree(pll);
+               return ERR_PTR(-EINVAL);

Do this case statement before allocating? So that kfree() isn't required here?

Fixed in the next version.

Quoted 12 lines

drivers/clk/imx/clk-sccg-pll.c line 232

Quoted 9 lines
drivers/clk/imx/clk-sccg-pll.c new file +9 -0
+       }
+
+       init.flags = 0;
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+
+       pll->hw.init = &init;
+
+       clk = clk_register(NULL, &pll->hw);

Any chance to use clk_hw based registration APIs?

Fixed in the next version.

Quoted 4 lines
Quoted 4 lines
drivers/clk/imx/clk-sccg-pll.c new file +4 -0
+       if (IS_ERR(clk))
+               kfree(pll);
+
+       return clk;
maintainer
#9 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoting Abel Vesa (2018-11-07 03:54:45)

Quoted 23 lines · Stephen Boyd
Quoted 12 lines

Quoting Abel Vesa (2018-09-24 03:39:55)

Quoted 11 lines
drivers/clk/imx/clk-sccg-pll.c new file +11 -0
+static unsigned long clk_pll2_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, ref, divr1, divf1, divr2, divf2;
+       u64 temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       switch (FIELD_GET(PLL_REF_MASK, val)) {
+       case 0:
+               ref = OSC_25M;
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 138

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+               break;
+       case 1:
+               ref = OSC_27M;
+               break;
+       default:
+               ref = OSC_25M;

Does this information not come through 'parent_rate'?

Quoted 5 lines

No. So basically both pll1 and pll2 and the divider after it form together this SCCG:

https://www.nxp.com/docs/en/reference-manual/IMX8MDQLQRM.pdf#page=834

See: Figure 5-8. SSCG PLL Block Diagram

Thanks for the link!

Quoted 4 lines

We're basically reading the input of the pll 1 in order to compute the output of the entire SCCG.

I know it's a mess. I'm working on cleaning it up, but for now we need this in in order to boot up.

What's the plan to clean it up?

Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
drivers/clk/imx/clk-sccg-pll.c new file +3 -0
+               break;
+       }
+

drivers/clk/imx/clk-sccg-pll.c line 151

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divr1 = FIELD_GET(PLL_DIVR1_MASK, val);
+       divr2 = FIELD_GET(PLL_DIVR2_MASK, val);
+       divf1 = FIELD_GET(PLL_DIVF1_MASK, val);
+       divf2 = FIELD_GET(PLL_DIVF2_MASK, val);
+
+       temp64 = ref * 2;
+       temp64 *= (divf1 + 1) * (divf2 + 1);
+
+       do_div(temp64, (divr1 + 1) * (divr2 + 1));

Nitpicks: A comment with the equation may be helpful to newcomers.

Quoted 2 lines

Since the SCCG is contructed by multiple different types of clocks here, the equation doesn't help since it is spread in all constructing blocks.

Ok.

author
#10 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoted 30 lines · Stephen Boyd

Quoting Abel Vesa (2018-11-07 03:54:45)

Quoted 23 lines · Stephen Boyd
Quoted 12 lines

Quoting Abel Vesa (2018-09-24 03:39:55)

Quoted 11 lines
drivers/clk/imx/clk-sccg-pll.c new file +11 -0
+static unsigned long clk_pll2_recalc_rate(struct clk_hw *hw,
+                                        unsigned long parent_rate)
+{
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+       u32 val, ref, divr1, divf1, divr2, divf2;
+       u64 temp64;
+
+       val = readl_relaxed(pll->base + PLL_CFG0);
+       switch (FIELD_GET(PLL_REF_MASK, val)) {
+       case 0:
+               ref = OSC_25M;
Quoted 9 lines

drivers/clk/imx/clk-sccg-pll.c line 138

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+               break;
+       case 1:
+               ref = OSC_27M;
+               break;
+       default:
+               ref = OSC_25M;

Does this information not come through 'parent_rate'?

Quoted 5 lines

No. So basically both pll1 and pll2 and the divider after it form together this SCCG:

https://www.nxp.com/docs/en/reference-manual/IMX8MDQLQRM.pdf#page=834

See: Figure 5-8. SSCG PLL Block Diagram

Quoted 8 lines

Thanks for the link!

Quoted 4 lines

We're basically reading the input of the pll 1 in order to compute the output of the entire SCCG.

I know it's a mess. I'm working on cleaning it up, but for now we need this in in order to boot up.

What's the plan to clean it up?

So I'm doing this in our internal tree first to make sure I don't break the other (newer) socs.

I already have a prototype in testing but it's a long way to upstream it.

Basically, I'm replacing all of this with a single, more like a composite, more complex, clock type that does all the magic inside.

One of the problems is the fact that the bypasses can have the same sources and in my case, I'm implementing that as a list of parents name, but the parent names list doesn't work with duplicates, so I have to find some other way to do it.

Once I have something clean and tested enough I'll send it upstream.

Quoted 23 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/clk/imx/clk-sccg-pll.c new file +3 -0
+               break;
+       }
+

drivers/clk/imx/clk-sccg-pll.c line 151

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divr1 = FIELD_GET(PLL_DIVR1_MASK, val);
+       divr2 = FIELD_GET(PLL_DIVR2_MASK, val);
+       divf1 = FIELD_GET(PLL_DIVF1_MASK, val);
+       divf2 = FIELD_GET(PLL_DIVF2_MASK, val);
+
+       temp64 = ref * 2;
+       temp64 *= (divf1 + 1) * (divf2 + 1);
+
+       do_div(temp64, (divr1 + 1) * (divr2 + 1));

Nitpicks: A comment with the equation may be helpful to newcomers.

Quoted 2 lines

Since the SCCG is contructed by multiple different types of clocks here, the equation doesn't help since it is spread in all constructing blocks.

Ok.

maintainer
#11 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoting Abel Vesa (2018-11-07 12:26:25)

Quoted 13 lines · Stephen Boyd
Quoted 3 lines

What's the plan to clean it up?

So I'm doing this in our internal tree first to make sure I don't break the other (newer) socs.

I already have a prototype in testing but it's a long way to upstream it.

Basically, I'm replacing all of this with a single, more like a composite, more complex, clock type that does all the magic inside.

Quoted 6 lines

One of the problems is the fact that the bypasses can have the same sources and in my case, I'm implementing that as a list of parents name, but the parent names list doesn't work with duplicates, so I have to find some other way to do it.

Once I have something clean and tested enough I'll send it upstream.

Ok. Thanks for the info.

author
#12 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoted 14 lines · Stephen Boyd

Quoting Abel Vesa (2018-11-07 12:26:25)

Quoted 13 lines · Stephen Boyd
Quoted 3 lines

What's the plan to clean it up?

So I'm doing this in our internal tree first to make sure I don't break the other (newer) socs.

I already have a prototype in testing but it's a long way to upstream it.

Basically, I'm replacing all of this with a single, more like a composite, more complex, clock type that does all the magic inside.

Quoted 9 lines
Quoted 6 lines

One of the problems is the fact that the bypasses can have the same sources and in my case, I'm implementing that as a list of parents name, but the parent names list doesn't work with duplicates, so I have to find some other way to do it.

Once I have something clean and tested enough I'll send it upstream.

Ok. Thanks for the info.

Just to avoid any kind of confusion.

The whole refactoring of the SCCG clock will be done in a separate (later) change and will not be part of this patchset.

I already sent the 12th version of this current patch series and I would really like to get this in ASAP so that the booting up of imx8mq will not be delayed.

Thanks
Abel

maintainer
#13 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoting Abel Vesa (2018-11-08 04:29:39)

Quoted 25 lines · Stephen Boyd
Quoted 14 lines

Quoting Abel Vesa (2018-11-07 12:26:25)

Quoted 13 lines · Stephen Boyd
Quoted 3 lines

What's the plan to clean it up?

So I'm doing this in our internal tree first to make sure I don't break the other (newer) socs.

I already have a prototype in testing but it's a long way to upstream it.

Basically, I'm replacing all of this with a single, more like a composite, more complex, clock type that does all the magic inside.

Quoted 9 lines
Quoted 6 lines

One of the problems is the fact that the bypasses can have the same sources and in my case, I'm implementing that as a list of parents name, but the parent names list doesn't work with duplicates, so I have to find some other way to do it.

Once I have something clean and tested enough I'll send it upstream.

Ok. Thanks for the info.

Quoted 8 lines

Just to avoid any kind of confusion.

The whole refactoring of the SCCG clock will be done in a separate (later) change and will not be part of this patchset.

I already sent the 12th version of this current patch series and I would really like to get this in ASAP so that the booting up of imx8mq will not be delayed.

Ok. Well we're in rc1 right now, and so we're not merging new drivers into mainline. I can merge the clk driver into clk-next, but you'll have to wait for the stabilization period to end (approximately 6 or 7 weeks) before this can get into the next kernel version. It will be in linux-next much sooner of course.

#14 lore raw

RE: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Hi Stephen,

[...]

Quoted 9 lines
Quoted 2 lines

I already sent the 12th version of this current patch series and I would really like to get this in ASAP so that the booting up of imx8mq will

not be delayed.

Quoted 1 line

Ok. Well we're in rc1 right now, and so we're not merging new drivers into mainline. I can merge the clk driver into clk-next, but you'll have to wait for the stabilization period to end (approximately 6 or 7 weeks) before this can get into the next kernel version. It will be in linux-next much sooner of course.

That would be great if you can help that.
We're now working with SUSE to enable i.MX8 support.
Their criteria is only backporting patches which must be at least in maintainer's next tree already. So either picked up by you or Shawn would help a lot on it.

BTW, one simple question is that because MX8MQ DTS patches depends on this clock driver series. How would you suggest this series to go through your tree or Shawn's tree?

Regards
Dong Aisheng

#15 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoted 13 lines · A.s. Dong

Hi Stephen,

[...]

Quoted 9 lines
Quoted 2 lines

I already sent the 12th version of this current patch series and I would really like to get this in ASAP so that the booting up of imx8mq will

not be delayed.

Quoted 1 line

Ok. Well we're in rc1 right now, and so we're not merging new drivers into mainline. I can merge the clk driver into clk-next, but you'll have to wait for the stabilization period to end (approximately 6 or 7 weeks) before this can get into the next kernel version. It will be in linux-next much sooner of course.

Quoted 8 lines

That would be great if you can help that.
We're now working with SUSE to enable i.MX8 support.
Their criteria is only backporting patches which must be at least in maintainer's next tree already. So either picked up by you or Shawn would help a lot on it.

BTW, one simple question is that because MX8MQ DTS patches depends on this clock driver series. How would you suggest this series to go through your tree or Shawn's tree?

Once Stephen has a topic branch for the patches, I can pull it into my tree to resolve the DT dependency.

Shawn

maintainer
#16 lore raw

Re: [PATCH v9 3/5] clk: imx: add SCCG PLL type

Quoting Shawn Guo (2018-11-13 06:25:36)

Quoted 19 lines · A.s. Dong
Quoted 18 lines

Hi Stephen,

[...]

Quoted 9 lines
Quoted 2 lines

I already sent the 12th version of this current patch series and I would really like to get this in ASAP so that the booting up of imx8mq will

not be delayed.

Quoted 1 line

Ok. Well we're in rc1 right now, and so we're not merging new drivers into mainline. I can merge the clk driver into clk-next, but you'll have to wait for the stabilization period to end (approximately 6 or 7 weeks) before this can get into the next kernel version. It will be in linux-next much sooner of course.

That would be great if you can help that.
We're now working with SUSE to enable i.MX8 support.
Their criteria is only backporting patches which must be at least in maintainer's next tree already. So either picked up by you or Shawn would help a lot on it.

Quoted 7 lines
Quoted 3 lines

BTW, one simple question is that because MX8MQ DTS patches depends on this clock driver series. How would you suggest this series to go through your tree or Shawn's tree?

Once Stephen has a topic branch for the patches, I can pull it into my tree to resolve the DT dependency.

Sounds like a plan. Expect something next week.

author
#17 lore raw

PATCH v9 4/5 clk: imx: add imx composite clock

In reply to a message not in the archive

Since a lot of clocks on imx8 are formed by a mux, gate, predivider and divider, the idea here is to combine all of those into one composite clock, but we need to deal with both predivider and divider at the same time and therefore we add the imx_clk_composite_divider_ops and register the composite clock with those.

---
 drivers/clk/imx/Makefile        |   1 +
 drivers/clk/imx/clk-composite.c | 181 ++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h           |  14 ++++
 3 files changed, 196 insertions(+)
 create mode 100644 drivers/clk/imx/clk-composite.c
drivers/clk/imx/Makefile +1 -0
index b87513c..4fabb0a 100644
@@ -3,6 +3,7 @@
 obj-y += \
 	clk.o \
 	clk-busy.o \
+	clk-composite.o \
 	clk-cpu.o \
 	clk-fixup-div.o \
 	clk-fixup-mux.o \
drivers/clk/imx/clk-composite.c new file +181 -0

181 lines not on this page · raw message

drivers/clk/imx/clk.h +14 -0
index 12b3fd6..9d7c9c8 100644
@@ -232,4 +232,18 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 		struct clk *div, struct clk *mux, struct clk *pll,
 		struct clk *step);
 
+struct clk *imx_clk_composite_flags(const char *name, const char **parent_names,
+		int num_parents, void __iomem *reg, unsigned long flags);
+
+#define __imx_clk_composite(name, parent_names, reg, flags) \
+	imx_clk_composite_flags(name, parent_names, \
+		ARRAY_SIZE(parent_names), reg, \
+		flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
+
+#define imx_clk_composite(name, parent_names, reg) \
+	__imx_clk_composite(name, parent_names, reg, 0)
+
+#define imx_clk_composite_critical(name, parent_names, reg) \
+	__imx_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
+
 #endif
Signature · 1 line
2.7.4
reviewer
#18 lore raw

Re: [PATCH v9 4/5] clk: imx: add imx composite clock

Hi Abel,

drivers/clk/imx/clk-composite.c line 85

Quoted 11 lines · Abel Vesa
drivers/clk/imx/clk-composite.c new file +11 -0
+static long imx_clk_composite_divider_round_rate(struct clk_hw *hw,
+                                               unsigned long rate,
+                                               unsigned long *prate)
+{
+       int prediv_value;
+       int div_value;
+
+       imx_clk_composite_compute_dividers(rate, *prate,
+                                               &prediv_value, &div_value);
+
+       rate = DIV_ROUND_UP_ULL((u64)*prate, prediv_value);

You assing a value to 'rate' here.

Quoted 1 line

+ rate = DIV_ROUND_UP_ULL((u64)rate, div_value);

And then overwrite it immediately after.

Is this really the intended behavior?

maintainer
#19 lore raw

Re: [PATCH v9 4/5] clk: imx: add imx composite clock

Quoted 18 lines · Fabio Estevam

Hi Abel,

drivers/clk/imx/clk-composite.c line 85

Quoted 11 lines · Abel Vesa
drivers/clk/imx/clk-composite.c new file +11 -0
+static long imx_clk_composite_divider_round_rate(struct clk_hw *hw,
+                                               unsigned long rate,
+                                               unsigned long *prate)
+{
+       int prediv_value;
+       int div_value;
+
+       imx_clk_composite_compute_dividers(rate, *prate,
+                                               &prediv_value, &div_value);
+
+       rate = DIV_ROUND_UP_ULL((u64)*prate, prediv_value);

You assing a value to 'rate' here.

Quoted 3 lines
Quoted 1 line

+ rate = DIV_ROUND_UP_ULL((u64)rate, div_value);

And then overwrite it immediately after.

It's:

	rate = *prate / prediv_value;
	rate = rate / div_value;

To me this looks correct. However, For an unsigned long type we have DIV_ROUND_UP() with which we do not need any casting. For 64bit code unsigned long is 64bit anyway which makes the cast a no-op and for 32bit code there's also no point in exanding the initial 32bit value to 64bit.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
reviewer
#20 lore raw

Re: [PATCH v9 4/5] clk: imx: add imx composite clock

Hi Sascha,

Quoted 3 lines · Sascha Hauer

It's:

        rate = *prate / prediv_value;
        rate = rate / div_value;

Yes, this looks correct. Thanks for the feedback.

Quoted 4 lines

To me this looks correct. However, For an unsigned long type we have DIV_ROUND_UP() with which we do not need any casting. For 64bit code unsigned long is 64bit anyway which makes the cast a no-op and for 32bit code there's also no point in exanding the initial 32bit value to 64bit.

That's a good point too.

Thanks

maintainer
#21 lore raw

Re: [PATCH v9 4/5] clk: imx: add imx composite clock

In reply to Abel Vesa

Quoting Abel Vesa (2018-09-24 03:39:56)

Quoted 6 lines
drivers/clk/imx/clk-composite.c new file +0 -0
new file mode 100644
index 0000000..4b03107

drivers/clk/imx/clk-composite.c line 9

Quoted 9 lines
drivers/clk/imx/clk-composite.c new file +9 -0
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 NXP
+ */
+
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/clk-provider.h>
+#include <linux/clk.h>

Is this include used?

Quoted 69 lines
drivers/clk/imx/clk-composite.c new file +69 -0
+
+#include "clk.h"
+
+#define PCG_PREDIV_SHIFT       16
+#define PCG_PREDIV_WIDTH       3
+#define PCG_PREDIV_MAX         8
+
+#define PCG_DIV_SHIFT          0
+#define PCG_DIV_WIDTH          6
+#define PCG_DIV_MAX            64
+
+#define PCG_PCS_SHIFT          24
+#define PCG_PCS_MASK           0x7
+
+#define PCG_CGC_SHIFT          28
+
+static unsigned long imx_clk_composite_divider_recalc_rate(struct clk_hw *hw,
+                                               unsigned long parent_rate)
+{
+       struct clk_divider *divider = to_clk_divider(hw);
+       unsigned long prediv_rate;
+       unsigned int prediv_value;
+       unsigned int div_value;
+
+       prediv_value = clk_readl(divider->reg) >> divider->shift;
+       prediv_value &= clk_div_mask(divider->width);
+
+       prediv_rate = divider_recalc_rate(hw, parent_rate, prediv_value,
+                                               NULL, divider->flags,
+                                               divider->width);
+
+       div_value = clk_readl(divider->reg) >> PCG_DIV_SHIFT;
+       div_value &= clk_div_mask(PCG_DIV_WIDTH);
+
+       return divider_recalc_rate(hw, prediv_rate, div_value, NULL,
+                                  divider->flags, PCG_DIV_WIDTH);
+}
+
+static int imx_clk_composite_compute_dividers(unsigned long rate,
+                                               unsigned long parent_rate,
+                                               int *prediv, int *postdiv)
+{
+       int div1, div2;
+       int error = INT_MAX;
+       int ret = -EINVAL;
+
+       /* default values */
+       *prediv = 1;
+       *postdiv = 1;
+
+       for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
+               for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
+                       int new_error = ((parent_rate / div1) / div2) - rate;
+
+                       if (abs(new_error) < abs(error)) {
+                               *prediv = div1;
+                               *postdiv = div2;
+                               error = new_error;
+                               ret = 0;
+                       }
+               }
+       }
+       return ret;
+}
+
+static long imx_clk_composite_divider_round_rate(struct clk_hw *hw,
+                                               unsigned long rate,
+                                               unsigned long *prate)
+{

drivers/clk/imx/clk-composite.c line 88

Quoted 10 lines
drivers/clk/imx/clk-composite.c new file +10 -0
+       int prediv_value;
+       int div_value;
+
+       imx_clk_composite_compute_dividers(rate, *prate,
+                                               &prediv_value, &div_value);
+
+       rate = DIV_ROUND_UP_ULL((u64)*prate, prediv_value);
+       rate = DIV_ROUND_UP_ULL((u64)rate, div_value);
+
+       return rate;

Looks the same as another patch, maybe it is?

Anyway, same nitpick about returning the DIV_ROUND_UP_ULL() result.

Quoted 17 lines
drivers/clk/imx/clk-composite.c new file +17 -0
+}
+
+static int imx_clk_composite_divider_set_rate(struct clk_hw *hw,
+                                       unsigned long rate,
+                                       unsigned long parent_rate)
+{
+       struct clk_divider *divider = to_clk_divider(hw);
+       unsigned long flags = 0;
+       int prediv_value;
+       int div_value;
+       int ret = 0;
+       u32 val;
+
+       ret = imx_clk_composite_compute_dividers(rate, parent_rate,
+                                               &prediv_value, &div_value);
+       if (ret)
+               return -EINVAL;

drivers/clk/imx/clk-composite.c line 115

Quoted 10 lines
drivers/clk/imx/clk-composite.c new file +10 -0
+
+       spin_lock_irqsave(divider->lock, flags);
+
+       val = clk_readl(divider->reg);
+       val &= ~((clk_div_mask(divider->width) << divider->shift) |
+                       (clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT));
+
+       val |= (u32)(prediv_value  - 1) << divider->shift;
+       val |= (u32)(div_value - 1) << PCG_DIV_SHIFT;
+       clk_writel(val, divider->reg);

Please don't use clk_writel().

Quoted 45 lines
drivers/clk/imx/clk-composite.c new file +45 -0
+
+       spin_unlock_irqrestore(divider->lock, flags);
+
+       return ret;
+}
+
+static const struct clk_ops imx_clk_composite_divider_ops = {
+       .recalc_rate = imx_clk_composite_divider_recalc_rate,
+       .round_rate = imx_clk_composite_divider_round_rate,
+       .set_rate = imx_clk_composite_divider_set_rate,
+};
+
+struct clk *imx_clk_composite_flags(const char *name,
+                                       const char **parent_names,
+                                       int num_parents, void __iomem *reg,
+                                       unsigned long flags)
+{
+       struct clk_hw *mux_hw = NULL, *div_hw = NULL, *gate_hw = NULL;
+       struct clk_divider *div = NULL;
+       struct clk_gate *gate = NULL;
+       struct clk_mux *mux = NULL;
+       struct clk *clk = ERR_PTR(-ENOMEM);
+
+       mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+       if (!mux)
+               goto fail;
+
+       mux_hw = &mux->hw;
+       mux->reg = reg;
+       mux->shift = PCG_PCS_SHIFT;
+       mux->mask = PCG_PCS_MASK;
+
+       div = kzalloc(sizeof(*div), GFP_KERNEL);
+       if (!div)
+               goto fail;
+
+       div_hw = &div->hw;
+       div->reg = reg;
+       div->shift = PCG_PREDIV_SHIFT;
+       div->width = PCG_PREDIV_WIDTH;
+       div->lock = &imx_ccm_lock;
+       div->flags = CLK_DIVIDER_ROUND_CLOSEST;
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)

drivers/clk/imx/clk-composite.c line 170

Quoted 10 lines
drivers/clk/imx/clk-composite.c new file +10 -0
+               goto fail;
+
+       gate_hw = &gate->hw;
+       gate->reg = reg;
+       gate->bit_idx = PCG_CGC_SHIFT;
+
+       clk = clk_register_composite(NULL, name, parent_names, num_parents,
+                                       mux_hw, &clk_mux_ops, div_hw,
+                                       &imx_clk_composite_divider_ops, gate_hw,
+                                       &clk_gate_ops, flags);

Didn't I already review this? I'd prefer we move this to using clk_hw based APIs and then return the clk pointer if needed.

Quoted 11 lines
drivers/clk/imx/clk-composite.c new file +11 -0
+       if (IS_ERR(clk))
+               goto fail;
+
+       return clk;
+
+fail:
+       kfree(gate);
+       kfree(div);
+       kfree(mux);
+       return clk;
+}
author
#22 lore raw

Re: [PATCH v9 4/5] clk: imx: add imx composite clock

Quoted 9 lines · Stephen Boyd

Quoting Abel Vesa (2018-09-24 03:39:56)

drivers/clk/imx/clk-composite.c line 170

Quoted 4 lines
drivers/clk/imx/clk-composite.c new file +4 -0
+       clk = clk_register_composite(NULL, name, parent_names, num_parents,
+                                       mux_hw, &clk_mux_ops, div_hw,
+                                       &imx_clk_composite_divider_ops, gate_hw,
+                                       &clk_gate_ops, flags);

Didn't I already review this? I'd prefer we move this to using clk_hw based APIs and then return the clk pointer if needed.

Yes, you reviewed the v11, so you can ignore this 9th version.

I'll implement all the comments from you in the 12th version before sending.

I'll also switch all clk based register functions call sites to clk_hw based ones.

Thanks

Quoted 11 lines
Quoted 11 lines
drivers/clk/imx/clk-composite.c new file +11 -0
+       if (IS_ERR(clk))
+               goto fail;
+
+       return clk;
+
+fail:
+       kfree(gate);
+       kfree(div);
+       kfree(mux);
+       return clk;
+}
author
#23 lore raw

PATCH v9 5/5 clk: imx: add clock driver for i.MX8MQ CCM

In reply to a message not in the archive

From: Lucas Stach <[email protected]>

Add driver for the Clock Control Module found on i.MX8MQ.

This is largely based on the downstream driver from Anson Huang and Bai Ping at NXP, plus the imx composite clock from Abel Vesa at NXP, with only some small adaptions to mainline from me.

---
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mq.c | 602 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h        |  36 +++
 3 files changed, 639 insertions(+)
 create mode 100644 drivers/clk/imx/clk-imx8mq.c
drivers/clk/imx/Makefile +1 -0
index 4fabb0a..64e695c 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_SOC_IMX6SX) += clk-imx6sx.o
 obj-$(CONFIG_SOC_IMX6UL) += clk-imx6ul.o
 obj-$(CONFIG_SOC_IMX7D)  += clk-imx7d.o
 obj-$(CONFIG_SOC_VF610)  += clk-vf610.o
+obj-$(CONFIG_SOC_IMX8MQ) += clk-imx8mq.o
drivers/clk/imx/clk-imx8mq.c new file +602 -0

602 lines not on this page · raw message

drivers/clk/imx/clk.h +36 -0
index 9d7c9c8..64faf27 100644
@@ -128,6 +128,15 @@ static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
 			reg, shift, width, 0, &imx_ccm_lock);
 }
 
+static inline struct clk *imx_clk_divider2_flags(const char *name,
+		const char *parent, void __iomem *reg, u8 shift, u8 width,
+		unsigned long flags)
+{
+	return clk_register_divider(NULL, name, parent,
+			flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, width, 0, &imx_ccm_lock);
+}
+
 static inline struct clk *imx_clk_gate(const char *name, const char *parent,
 		void __iomem *reg, u8 shift)
 {
@@ -195,6 +204,15 @@ static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
 			reg, shift, 0, &imx_ccm_lock);
 }
 
+static inline struct clk *imx_clk_gate3_flags(const char *name,
+		const char *parent, void __iomem *reg, u8 shift,
+		unsigned long flags)
+{
+	return clk_register_gate(NULL, name, parent,
+			flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, 0, &imx_ccm_lock);
+}
+
 static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
 		void __iomem *reg, u8 shift)
 {
@@ -203,6 +221,15 @@ static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
 			reg, shift, 0x3, 0, &imx_ccm_lock, NULL);
 }
 
+static inline struct clk *imx_clk_gate4_flags(const char *name,
+		const char *parent, void __iomem *reg, u8 shift,
+		unsigned long flags)
+{
+	return clk_register_gate2(NULL, name, parent,
+			flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, 0x3, 0, &imx_ccm_lock, NULL);
+}
+
 static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, int num_parents)
 {
@@ -228,6 +255,15 @@ static inline struct clk *imx_clk_mux_flags(const char *name,
 			&imx_ccm_lock);
 }
 
+static inline struct clk *imx_clk_mux2_flags(const char *name,
+		void __iomem *reg, u8 shift, u8 width, const char **parents,
+		int num_parents, unsigned long flags)
+{
+	return clk_register_mux(NULL, name, parents, num_parents,
+			flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, width, 0, &imx_ccm_lock);
+}
+
 struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 		struct clk *div, struct clk *mux, struct clk *pll,
 		struct clk *step);
Signature · 1 line
2.7.4
maintainer
#24 lore raw

Re: [PATCH v9 5/5] clk: imx: add clock driver for i.MX8MQ CCM

Quoting Abel Vesa (2018-09-24 03:39:57)

Quoted 7 lines

From: Lucas Stach <[email protected]>

Add driver for the Clock Control Module found on i.MX8MQ.

This is largely based on the downstream driver from Anson Huang and Bai Ping at NXP, plus the imx composite clock from Abel Vesa at NXP, with only some small adaptions to mainline from me.

Can you point to the downstream driver so we can know what small adaptations were made.

Quoted 15 lines
---
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mq.c | 602 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h        |  36 +++
 3 files changed, 639 insertions(+)
 create mode 100644 drivers/clk/imx/clk-imx8mq.c
drivers/clk/imx/Makefile +0 -0
index 4fabb0a..64e695c 100644

drivers/clk/imx/Makefile obj-$(CONFIG_SOC_IMX6SX) += clk-imx6sx.o · line 33

Quoted 4 lines
drivers/clk/imx/Makefile +1 -0
@@ -30,3 +30,4 @@ obj-$(CONFIG_SOC_IMX6SX) += clk-imx6sx.o
 obj-$(CONFIG_SOC_IMX6UL) += clk-imx6ul.o
 obj-$(CONFIG_SOC_IMX7D)  += clk-imx7d.o
 obj-$(CONFIG_SOC_VF610)  += clk-vf610.o
+obj-$(CONFIG_SOC_IMX8MQ) += clk-imx8mq.o

Please try to keep this alphabetical on CONFIG symbol.

Quoted 6 lines
drivers/clk/imx/clk-imx8mq.c new file +0 -0
new file mode 100644
index 0000000..aadb523

drivers/clk/imx/clk-imx8mq.c line 9

Quoted 9 lines
drivers/clk/imx/clk-imx8mq.c new file +9 -0
@@ -0,0 +1,602 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 NXP.
+ * Copyright (C) 2017 Pengutronix, Lucas Stach <[email protected]>
+ */
+
+#include <dt-bindings/clock/imx8mq-clock.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>

Are these two includes used?

Quoted 19 lines
drivers/clk/imx/clk-imx8mq.c new file +19 -0
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/types.h>
+
+#include "clk.h"
+
+static u32 share_count_sai1;
+static u32 share_count_sai2;
+static u32 share_count_sai3;
+static u32 share_count_sai4;
+static u32 share_count_sai5;
+static u32 share_count_sai6;
+static u32 share_count_dcss;
+static u32 share_count_nand;
+

[...]

Quoted 18 lines
drivers/clk/imx/clk-imx8mq.c new file +18 -0
+
+static const char *imx8mq_ecspi3_sels[] = {"osc_25m", "sys2_pll_200m", "sys1_pll_40m", "sys1_pll_160m",
+                                          "sys1_pll_800m", "sys3_pll2_out", "sys2_pll_250m", "audio_pll2_out", };
+static const char *imx8mq_dram_core_sels[] = {"dram_pll_out", "dram_alt_root", };
+
+static const char *imx8mq_clko2_sels[] = {"osc_25m", "sys2_pll_200m", "sys1_pll_400m", "sys2_pll_166m", "audio_pll1_out",
+                                        "video_pll1_out", "ckil", };
+
+static struct clk_onecell_data clk_data;
+
+static void __init imx8mq_clocks_init(struct device_node *ccm_node)
+{
+       struct device_node *np;
+       void __iomem *base;
+       int i;
+
+       clks[IMX8MQ_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
+       clks[IMX8MQ_CLK_32K] = of_clk_get_by_name(ccm_node, "ckil");

drivers/clk/imx/clk-imx8mq.c line 291

Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c new file +10 -0
+       clks[IMX8MQ_CLK_25M] = of_clk_get_by_name(ccm_node, "osc_25m");
+       clks[IMX8MQ_CLK_27M] = of_clk_get_by_name(ccm_node, "osc_27m");
+       clks[IMX8MQ_CLK_EXT1] = of_clk_get_by_name(ccm_node, "clk_ext1");
+       clks[IMX8MQ_CLK_EXT2] = of_clk_get_by_name(ccm_node, "clk_ext2");
+       clks[IMX8MQ_CLK_EXT3] = of_clk_get_by_name(ccm_node, "clk_ext3");
+       clks[IMX8MQ_CLK_EXT4] = of_clk_get_by_name(ccm_node, "clk_ext4");
+
+       np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-anatop");
+       base = of_iomap(np, 0);
+       WARN_ON(!base);

And if that fails? return without continuing?

Quoted 5 lines
drivers/clk/imx/clk-imx8mq.c new file +5 -0
+
+       clks[IMX8MQ_ARM_PLL_REF_SEL] = imx_clk_mux("arm_pll_ref_sel", base + 0x28, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_GPU_PLL_REF_SEL] = imx_clk_mux("gpu_pll_ref_sel", base + 0x18, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_VPU_PLL_REF_SEL] = imx_clk_mux("vpu_pll_ref_sel", base + 0x20, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_AUDIO_PLL1_REF_SEL] = imx_clk_mux("audio_pll1_ref_sel", base + 0x0, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

[..]

Quoted 7 lines
drivers/clk/imx/clk-imx8mq.c new file +7 -0
+       clks[IMX8MQ_CLK_DSI_CORE] = imx_clk_composite("dsi_core", imx8mq_dsi_core_sels, base + 0xbb00);
+       clks[IMX8MQ_CLK_DSI_PHY_REF] = imx_clk_composite("dsi_phy_ref", imx8mq_dsi_phy_sels, base + 0xbb80);
+       clks[IMX8MQ_CLK_DSI_DBI] = imx_clk_composite("dsi_dbi", imx8mq_dsi_dbi_sels, base + 0xbc00);
+       clks[IMX8MQ_CLK_DSI_ESC] = imx_clk_composite("dsi_esc", imx8mq_dsi_esc_sels, base + 0xbc80);
+       clks[IMX8MQ_CLK_DSI_AHB] = imx_clk_composite("dsi_ahb", imx8mq_dsi_ahb_sels, base + 0x9200);
+       clks[IMX8MQ_CLK_CSI1_CORE] = imx_clk_composite("csi1_core", imx8mq_csi1_core_sels, base + 0xbd00);
+       clks[IMX8MQ_CLK_CSI1_PHY_REF] = imx_clk_composite("csi1_phy_ref", imx8mq_csi1_phy_sels, base + 0xbd80);

drivers/clk/imx/clk-imx8mq.c line 505

Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c new file +10 -0
+       clks[IMX8MQ_CLK_CSI1_ESC] = imx_clk_composite("csi1_esc", imx8mq_csi1_esc_sels, base + 0xbe00);
+       clks[IMX8MQ_CLK_CSI2_CORE] = imx_clk_composite("csi2_core", imx8mq_csi2_core_sels, base + 0xbe80);
+       clks[IMX8MQ_CLK_CSI2_PHY_REF] = imx_clk_composite("csi2_phy_ref", imx8mq_csi2_phy_sels, base + 0xbf00);
+       clks[IMX8MQ_CLK_CSI2_ESC] = imx_clk_composite("csi2_esc", imx8mq_csi2_esc_sels, base + 0xbf80);
+       clks[IMX8MQ_CLK_PCIE2_CTRL] = imx_clk_composite("pcie2_ctrl", imx8mq_pcie2_ctrl_sels, base + 0xc000);
+       clks[IMX8MQ_CLK_PCIE2_PHY] = imx_clk_composite("pcie2_phy", imx8mq_pcie2_phy_sels, base + 0xc080);
+       clks[IMX8MQ_CLK_PCIE2_AUX] = imx_clk_composite("pcie2_aux", imx8mq_pcie2_aux_sels, base + 0xc100);
+       clks[IMX8MQ_CLK_ECSPI3] = imx_clk_composite("ecspi3", imx8mq_ecspi3_sels, base + 0xc180);
+
+       /*FIXME, the doc is not ready now */

What does this mean?

Quoted 5 lines
drivers/clk/imx/clk-imx8mq.c new file +5 -0
+       clks[IMX8MQ_CLK_ECSPI1_ROOT] = imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0);
+       clks[IMX8MQ_CLK_ECSPI2_ROOT] = imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0);
+       clks[IMX8MQ_CLK_ECSPI3_ROOT] = imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0);
+       clks[IMX8MQ_CLK_ENET1_ROOT] = imx_clk_gate4("enet1_root_clk", "enet_axi", base + 0x40a0, 0);
+       clks[IMX8MQ_CLK_GPT1_ROOT] = imx_clk_gate4("gpt1_root_clk", "gpt1", base + 0x4100, 0);

[...]

drivers/clk/imx/clk-imx8mq.c line 575

Quoted 12 lines
drivers/clk/imx/clk-imx8mq.c new file +12 -0
+
+       clks[IMX8MQ_GPT_3M_CLK] = imx_clk_fixed_factor("gpt_3m", "osc_25m", 1, 8);
+       clks[IMX8MQ_CLK_DRAM_ALT_ROOT] = imx_clk_fixed_factor("dram_alt_root", "dram_alt", 1, 4);
+
+       for (i = 0; i < IMX8MQ_CLK_END; i++)
+               if (IS_ERR(clks[i]))
+                       pr_err("i.MX8mq clk %u register failed with %ld\n",
+                              i, PTR_ERR(clks[i]));
+
+       clk_data.clks = clks;
+       clk_data.clk_num = ARRAY_SIZE(clks);
+       of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);

Any chance to move to using clk_hw based provider and clk registration APIs?

Quoted 14 lines
drivers/clk/imx/clk-imx8mq.c new file +14 -0
+
+       clk_set_parent(clks[IMX8MQ_CLK_AHB], clks[IMX8MQ_SYS1_PLL_133M]);
+       clk_set_parent(clks[IMX8MQ_CLK_NAND_USDHC_BUS], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_AUDIO_AHB], clks[IMX8MQ_SYS2_PLL_500M]);
+
+       /* config video_pll1 clock */
+       clk_set_parent(clks[IMX8MQ_VIDEO_PLL1_REF_SEL], clks[IMX8MQ_CLK_27M]);
+       clk_set_rate(clks[IMX8MQ_VIDEO_PLL1], 593999999);
+
+       /* increase NOC clock to achieve best DDR access performance */
+       clk_set_rate(clks[IMX8MQ_CLK_NOC], clk_get_rate(clks[IMX8MQ_SYS1_PLL_800M]));
+
+       /* set pcie root's parent clk source */
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE1_CTRL], clks[IMX8MQ_SYS2_PLL_250M]);

drivers/clk/imx/clk-imx8mq.c line 599

Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c new file +10 -0
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE1_PHY], clks[IMX8MQ_SYS2_PLL_100M]);
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE2_CTRL], clks[IMX8MQ_SYS2_PLL_250M]);
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE2_PHY], clks[IMX8MQ_SYS2_PLL_100M]);
+
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_CORE], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_PHY_REF], clks[IMX8MQ_SYS2_PLL_1000M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_ESC], clks[IMX8MQ_SYS1_PLL_800M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_CORE], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_PHY_REF], clks[IMX8MQ_SYS2_PLL_1000M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_ESC], clks[IMX8MQ_SYS1_PLL_800M]);

Can this be done with assigned clock parents and assigned clock rates?

drivers/clk/imx/clk-imx8mq.c line 602

Quoted 3 lines
drivers/clk/imx/clk-imx8mq.c new file +3 -0
+}
+
+CLK_OF_DECLARE(imx8mq, "fsl,imx8mq-ccm", imx8mq_clocks_init);

Can you please add a comment indicating why this can't be done with a platform driver, or convert this to be a platform driver?

author
#25 lore raw

Re: [PATCH v9 5/5] clk: imx: add clock driver for i.MX8MQ CCM

Quoted 12 lines · Stephen Boyd

Quoting Abel Vesa (2018-09-24 03:39:57)

Quoted 7 lines

From: Lucas Stach <[email protected]>

Add driver for the Clock Control Module found on i.MX8MQ.

This is largely based on the downstream driver from Anson Huang and Bai Ping at NXP, plus the imx composite clock from Abel Vesa at NXP, with only some small adaptions to mainline from me.

Can you point to the downstream driver so we can know what small adaptations were made.

It's was implemented originally in NXP's internal tree. The adaptations to the initial implementation are not that small anymore. I even changed the authorship since it has changed quite a lot compared to the initial version.

Quoted 10 lines
Quoted 10 lines
---
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mq.c | 602 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h        |  36 +++
 3 files changed, 639 insertions(+)
 create mode 100644 drivers/clk/imx/clk-imx8mq.c
Quoted 12 lines

drivers/clk/imx/Makefile obj-$(CONFIG_SOC_IMX6SX) += clk-imx6sx.o · line 33

Quoted 9 lines
drivers/clk/imx/Makefile +1 -0
index 4fabb0a..64e695c 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_SOC_IMX6SX) += clk-imx6sx.o
 obj-$(CONFIG_SOC_IMX6UL) += clk-imx6ul.o
 obj-$(CONFIG_SOC_IMX7D)  += clk-imx7d.o
 obj-$(CONFIG_SOC_VF610)  += clk-vf610.o
+obj-$(CONFIG_SOC_IMX8MQ) += clk-imx8mq.o

Please try to keep this alphabetical on CONFIG symbol.

Fixed in the next version.

Quoted 9 lines
Quoted 9 lines
drivers/clk/imx/clk-imx8mq.c new file +3 -0
new file mode 100644
index 0000000..aadb523
@@ -0,0 +1,602 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 NXP.
Quoted 9 lines

drivers/clk/imx/clk-imx8mq.c line 9

Quoted 6 lines
drivers/clk/imx/clk-imx8mq.c new file +6 -0
+ * Copyright (C) 2017 Pengutronix, Lucas Stach <[email protected]>
+ */
+
+#include <dt-bindings/clock/imx8mq-clock.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>

Are these two includes used?

clkdev.h include is removed in the next version.
clk.h is needed by of_clk_get_by_name.

Quoted 42 lines
Quoted 19 lines
drivers/clk/imx/clk-imx8mq.c new file +19 -0
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/types.h>
+
+#include "clk.h"
+
+static u32 share_count_sai1;
+static u32 share_count_sai2;
+static u32 share_count_sai3;
+static u32 share_count_sai4;
+static u32 share_count_sai5;
+static u32 share_count_sai6;
+static u32 share_count_dcss;
+static u32 share_count_nand;
+

[...]

Quoted 22 lines
drivers/clk/imx/clk-imx8mq.c new file +22 -0
+
+static const char *imx8mq_ecspi3_sels[] = {"osc_25m", "sys2_pll_200m", "sys1_pll_40m", "sys1_pll_160m",
+                                          "sys1_pll_800m", "sys3_pll2_out", "sys2_pll_250m", "audio_pll2_out", };
+static const char *imx8mq_dram_core_sels[] = {"dram_pll_out", "dram_alt_root", };
+
+static const char *imx8mq_clko2_sels[] = {"osc_25m", "sys2_pll_200m", "sys1_pll_400m", "sys2_pll_166m", "audio_pll1_out",
+                                        "video_pll1_out", "ckil", };
+
+static struct clk_onecell_data clk_data;
+
+static void __init imx8mq_clocks_init(struct device_node *ccm_node)
+{
+       struct device_node *np;
+       void __iomem *base;
+       int i;
+
+       clks[IMX8MQ_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
+       clks[IMX8MQ_CLK_32K] = of_clk_get_by_name(ccm_node, "ckil");
+       clks[IMX8MQ_CLK_25M] = of_clk_get_by_name(ccm_node, "osc_25m");
+       clks[IMX8MQ_CLK_27M] = of_clk_get_by_name(ccm_node, "osc_27m");
+       clks[IMX8MQ_CLK_EXT1] = of_clk_get_by_name(ccm_node, "clk_ext1");
+       clks[IMX8MQ_CLK_EXT2] = of_clk_get_by_name(ccm_node, "clk_ext2");
Quoted 9 lines

drivers/clk/imx/clk-imx8mq.c line 291

Quoted 6 lines
drivers/clk/imx/clk-imx8mq.c new file +6 -0
+       clks[IMX8MQ_CLK_EXT3] = of_clk_get_by_name(ccm_node, "clk_ext3");
+       clks[IMX8MQ_CLK_EXT4] = of_clk_get_by_name(ccm_node, "clk_ext4");
+
+       np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-anatop");
+       base = of_iomap(np, 0);
+       WARN_ON(!base);

And if that fails? return without continuing?

Fixed in the next version.

Quoted 24 lines
Quoted 5 lines
drivers/clk/imx/clk-imx8mq.c new file +5 -0
+
+       clks[IMX8MQ_ARM_PLL_REF_SEL] = imx_clk_mux("arm_pll_ref_sel", base + 0x28, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_GPU_PLL_REF_SEL] = imx_clk_mux("gpu_pll_ref_sel", base + 0x18, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_VPU_PLL_REF_SEL] = imx_clk_mux("vpu_pll_ref_sel", base + 0x20, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_AUDIO_PLL1_REF_SEL] = imx_clk_mux("audio_pll1_ref_sel", base + 0x0, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

[..]

Quoted 7 lines
drivers/clk/imx/clk-imx8mq.c new file +7 -0
+       clks[IMX8MQ_CLK_DSI_CORE] = imx_clk_composite("dsi_core", imx8mq_dsi_core_sels, base + 0xbb00);
+       clks[IMX8MQ_CLK_DSI_PHY_REF] = imx_clk_composite("dsi_phy_ref", imx8mq_dsi_phy_sels, base + 0xbb80);
+       clks[IMX8MQ_CLK_DSI_DBI] = imx_clk_composite("dsi_dbi", imx8mq_dsi_dbi_sels, base + 0xbc00);
+       clks[IMX8MQ_CLK_DSI_ESC] = imx_clk_composite("dsi_esc", imx8mq_dsi_esc_sels, base + 0xbc80);
+       clks[IMX8MQ_CLK_DSI_AHB] = imx_clk_composite("dsi_ahb", imx8mq_dsi_ahb_sels, base + 0x9200);
+       clks[IMX8MQ_CLK_CSI1_CORE] = imx_clk_composite("csi1_core", imx8mq_csi1_core_sels, base + 0xbd00);
+       clks[IMX8MQ_CLK_CSI1_PHY_REF] = imx_clk_composite("csi1_phy_ref", imx8mq_csi1_phy_sels, base + 0xbd80);

drivers/clk/imx/clk-imx8mq.c line 505

Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c new file +10 -0
+       clks[IMX8MQ_CLK_CSI1_ESC] = imx_clk_composite("csi1_esc", imx8mq_csi1_esc_sels, base + 0xbe00);
+       clks[IMX8MQ_CLK_CSI2_CORE] = imx_clk_composite("csi2_core", imx8mq_csi2_core_sels, base + 0xbe80);
+       clks[IMX8MQ_CLK_CSI2_PHY_REF] = imx_clk_composite("csi2_phy_ref", imx8mq_csi2_phy_sels, base + 0xbf00);
+       clks[IMX8MQ_CLK_CSI2_ESC] = imx_clk_composite("csi2_esc", imx8mq_csi2_esc_sels, base + 0xbf80);
+       clks[IMX8MQ_CLK_PCIE2_CTRL] = imx_clk_composite("pcie2_ctrl", imx8mq_pcie2_ctrl_sels, base + 0xc000);
+       clks[IMX8MQ_CLK_PCIE2_PHY] = imx_clk_composite("pcie2_phy", imx8mq_pcie2_phy_sels, base + 0xc080);
+       clks[IMX8MQ_CLK_PCIE2_AUX] = imx_clk_composite("pcie2_aux", imx8mq_pcie2_aux_sels, base + 0xc100);
+       clks[IMX8MQ_CLK_ECSPI3] = imx_clk_composite("ecspi3", imx8mq_ecspi3_sels, base + 0xc180);
+
+       /*FIXME, the doc is not ready now */
Quoted 2 lines

What does this mean?

The comment does not apply anymore. It is remoed in the next version. When the driver was initially implemented, the specs doc was not ready.

Quoted 6 lines
Quoted 5 lines
drivers/clk/imx/clk-imx8mq.c new file +5 -0
+       clks[IMX8MQ_CLK_ECSPI1_ROOT] = imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0);
+       clks[IMX8MQ_CLK_ECSPI2_ROOT] = imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0);
+       clks[IMX8MQ_CLK_ECSPI3_ROOT] = imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0);
+       clks[IMX8MQ_CLK_ENET1_ROOT] = imx_clk_gate4("enet1_root_clk", "enet_axi", base + 0x40a0, 0);
+       clks[IMX8MQ_CLK_GPT1_ROOT] = imx_clk_gate4("gpt1_root_clk", "gpt1", base + 0x4100, 0);

[...]

Quoted 16 lines

drivers/clk/imx/clk-imx8mq.c line 575

Quoted 12 lines
drivers/clk/imx/clk-imx8mq.c new file +12 -0
+
+       clks[IMX8MQ_GPT_3M_CLK] = imx_clk_fixed_factor("gpt_3m", "osc_25m", 1, 8);
+       clks[IMX8MQ_CLK_DRAM_ALT_ROOT] = imx_clk_fixed_factor("dram_alt_root", "dram_alt", 1, 4);
+
+       for (i = 0; i < IMX8MQ_CLK_END; i++)
+               if (IS_ERR(clks[i]))
+                       pr_err("i.MX8mq clk %u register failed with %ld\n",
+                              i, PTR_ERR(clks[i]));
+
+       clk_data.clks = clks;
+       clk_data.clk_num = ARRAY_SIZE(clks);
+       of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);

Any chance to move to using clk_hw based provider and clk registration APIs?

Since a lot of the imx clocks that are already upstream and since it's not quite a small change, I would prefer if this would go in as is. I intend to make the switch to clk_hw based registration later, but it will take some time for me to get that ready and that would delay the upstream of imx8mq drivers even more.

All the new clock types introduced now are clk_hw based.

Quoted 18 lines
Quoted 18 lines
drivers/clk/imx/clk-imx8mq.c new file +18 -0
+
+       clk_set_parent(clks[IMX8MQ_CLK_AHB], clks[IMX8MQ_SYS1_PLL_133M]);
+       clk_set_parent(clks[IMX8MQ_CLK_NAND_USDHC_BUS], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_AUDIO_AHB], clks[IMX8MQ_SYS2_PLL_500M]);
+
+       /* config video_pll1 clock */
+       clk_set_parent(clks[IMX8MQ_VIDEO_PLL1_REF_SEL], clks[IMX8MQ_CLK_27M]);
+       clk_set_rate(clks[IMX8MQ_VIDEO_PLL1], 593999999);
+
+       /* increase NOC clock to achieve best DDR access performance */
+       clk_set_rate(clks[IMX8MQ_CLK_NOC], clk_get_rate(clks[IMX8MQ_SYS1_PLL_800M]));
+
+       /* set pcie root's parent clk source */
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE1_CTRL], clks[IMX8MQ_SYS2_PLL_250M]);
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE1_PHY], clks[IMX8MQ_SYS2_PLL_100M]);
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE2_CTRL], clks[IMX8MQ_SYS2_PLL_250M]);
+       clk_set_parent(clks[IMX8MQ_CLK_PCIE2_PHY], clks[IMX8MQ_SYS2_PLL_100M]);
+
Quoted 9 lines

drivers/clk/imx/clk-imx8mq.c line 599

Quoted 6 lines
drivers/clk/imx/clk-imx8mq.c new file +6 -0
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_CORE], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_PHY_REF], clks[IMX8MQ_SYS2_PLL_1000M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI1_ESC], clks[IMX8MQ_SYS1_PLL_800M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_CORE], clks[IMX8MQ_SYS1_PLL_266M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_PHY_REF], clks[IMX8MQ_SYS2_PLL_1000M]);
+       clk_set_parent(clks[IMX8MQ_CLK_CSI2_ESC], clks[IMX8MQ_SYS1_PLL_800M]);

Can this be done with assigned clock parents and assigned clock rates?

Fair enough. Removed entirely in the next version. Each driver will set its own rate and parent in dts later on.

Quoted 7 lines

drivers/clk/imx/clk-imx8mq.c line 602

Quoted 3 lines
drivers/clk/imx/clk-imx8mq.c new file +3 -0
+}
+
+CLK_OF_DECLARE(imx8mq, "fsl,imx8mq-ccm", imx8mq_clocks_init);

Can you please add a comment indicating why this can't be done with a platform driver, or convert this to be a platform driver?

Good point. Switched to platform driver.

Thanks