Skip to contentSkip to conversation

Add i.MX8MQ clock driver

PATCH Superseded Abel Vesa 3 participants 15 messages Aug 22, 2018 – Sep 4, 2018

Subsystems (4)

v6 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Abel Vesa

author
#0 lore raw

v6 cover Add i.MX8MQ clock driver

Fifth version can be found here:

https://lkml.org/lkml/2018/8/20/83

Changes since v5:
* Fixed the predivider and divider register values as reported by Sascha.
* Changed the commit message of the 4th patch to match with what the commit is adding

Changes since v4:
* Implemented divider ops and used clk-composite as suggested by Sascha Hauer.

Changes since v3:
* Added a composite clock type to get rid of some complexity from clk-imx8mq. This new composite clock type will also be used by all the imx8 socs that will follow.
* Added back the reviewed-by tag.

Abel Vesa (1):
clk: imx: add imx composite clock

Lucas Stach (4):
dt-bindings: add binding for i.MX8MQ CCM
clk: imx: add fractional PLL output clock
clk: imx: add SCCG PLL type
clk: imx: add clock driver for i.MX8MQ CCM

 .../devicetree/bindings/clock/imx8mq-clock.txt     |  20 +
 drivers/clk/imx/Makefile                           |   6 +-
 drivers/clk/imx/clk-composite.c                    | 157 +++++
 drivers/clk/imx/clk-frac-pll.c                     | 230 ++++++++
 drivers/clk/imx/clk-imx8mq.c                       | 631 +++++++++++++++++++++
 drivers/clk/imx/clk-sccg-pll.c                     | 231 ++++++++
 drivers/clk/imx/clk.h                              |  57 ++
 include/dt-bindings/clock/imx8mq-clock.h           | 410 +++++++++++++
 8 files changed, 1741 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/clock/imx8mq-clock.txt
 create mode 100644 drivers/clk/imx/clk-composite.c
 create mode 100644 drivers/clk/imx/clk-frac-pll.c
 create mode 100644 drivers/clk/imx/clk-imx8mq.c
 create mode 100644 drivers/clk/imx/clk-sccg-pll.c
 create mode 100644 include/dt-bindings/clock/imx8mq-clock.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v6 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           | 410 +++++++++++++++++++++
 2 files changed, 430 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 +410 -0

410 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#2 lore raw

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

In reply to Abel Vesa

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 | 230 +++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h          |   3 +
 3 files changed, 234 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 +230 -0

230 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
author
#3 lore raw

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

In reply to Abel Vesa

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 | 231 +++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h          |   9 ++
 3 files changed, 242 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 +231 -0

231 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
author
#10 lore raw

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

In reply to Abel Vesa

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 | 157 ++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h           |   9 +++
 3 files changed, 167 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 +157 -0

157 lines not on this page · raw message

drivers/clk/imx/clk.h +9 -0
index 12b3fd6..9dbb680 100644
@@ -232,4 +232,13 @@ 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) \
+	imx_clk_composite_flags(name, parent_names, ARRAY_SIZE(parent_names), reg, 0)
+
+#define imx_clk_composite_critical(name, parent_names, reg) \
+	imx_clk_composite_flags(name, parent_names, ARRAY_SIZE(parent_names), reg, CLK_IS_CRITICAL)
+
 #endif
Signature · 1 line
2.7.4
author
#12 lore raw

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

In reply to Abel Vesa

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, with only some small adaptions to mainline from me.

---
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mq.c | 631 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h        |  36 +++
 3 files changed, 668 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 +631 -0

631 lines not on this page · raw message

drivers/clk/imx/clk.h +36 -0
index 9dbb680..e89c3a7 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
#4 lore raw

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

In reply to Abel Vesa

+Cc Andrey Smirnov who made me aware of this issue.

Quoted 15 lines · Abel Vesa

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/clk-sccg-pll.c new file +5 -0
+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;

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

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+	u32 divf;
+
+	divf = rate / (parent_rate * 2);
+
+	val = readl_relaxed(pll->base + PLL_CFG2);
+	val &= ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+	val |= (divf - 1) << PLL_DIVF1_SHIFT;
+	writel_relaxed(val, pll->base + PLL_CFG2);
+
+	/* FIXME: PLL lock check */

Shouldn't be too hard to add, no?

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

Quoted 12 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+	return 0;
+}
+
+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);
+	val &= ~(1 << PLL_PD);
+	writel_relaxed(val, pll->base);

pll->base + PLL_CFG0 please.

Quoted 4 lines
drivers/clk/imx/clk-sccg-pll.c new file +4 -0
+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,

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

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+	.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,
+};

So these are two PLLs that share the same enable register. Doing the prepare/unprepare for only one PLL can lead to all kinds of trouble. Finding a good abstraction the properly handles this case with the clock framework is probably also not easy.

I could imagine we'll need to track the enable state on both PLLs and only if both are disabled we disable it in hardware.

With the current code we disable the PLLs when all consumers are reparented to pll1, which probably has bad effects.

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 |
maintainer
#11 lore raw

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

In reply to Abel Vesa
Quoted 66 lines · Abel Vesa

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 | 157 ++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h           |   9 +++
 3 files changed, 167 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 +33 -0
new file mode 100644
index 0000000..a5c0080
@@ -0,0 +1,157 @@
+// 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>
+
+#include "clk.h"
+
+#define PCG_PREDIV_SHIFT	16
+#define PCG_PREDIV_WIDTH	3
+
+#define PCG_DIV_SHIFT		0
+#define PCG_DIV_WIDTH		6
+
+#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);

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

Quoted 10 lines
drivers/clk/imx/clk-composite.c new file +10 -0
+
+	prediv_rate = divider_recalc_rate(hw, parent_rate, prediv_value,
+						divider->table, 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, divider->table,
+				   divider->flags, PCG_DIV_WIDTH);

This is no table based divider, so divider->table is NULL, right? It's clearer to just write NULL here instead.

Otherwise this looks good for me now.

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 |
maintainer
#13 lore raw

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

In reply to Abel Vesa
Quoted 6 lines · Abel Vesa

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, with only some small adaptions to mainline from me.

It's time to rephrase the commit message. With the new composite clock the adaptions are no longer that small.

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

Quoted 9 lines
drivers/clk/imx/clk-imx8mq.c new file +9 -0
+
+static int const clks_init_on[] __initconst = {
+	IMX8MQ_CLK_DRAM_CORE, IMX8MQ_CLK_AHB_CG,
+	IMX8MQ_CLK_NOC, IMX8MQ_CLK_NOC_APB,
+	IMX8MQ_CLK_USB_BUS, IMX8MQ_CLK_NAND_USDHC_BUS,
+	IMX8MQ_CLK_MAIN_AXI, IMX8MQ_CLK_A53_CG,
+	IMX8MQ_CLK_AUDIO_AHB_DIV, IMX8MQ_CLK_TMU_ROOT,
+	IMX8MQ_CLK_DRAM_APB,
+};

This is unused and you seem to have converted all these clocks to add the CLK_IS_CRITICAL flag.

Are all these really needed? some clocks like IMX8MQ_CLK_AUDIO_AHB_DIV, IMX8MQ_CLK_USB_BUS and IMX8MQ_CLK_NAND_USDHC_BUS look suspicious.

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 |
author
#5 lore raw

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

In reply to Sascha Hauer
Quoted 22 lines · Sascha Hauer

+Cc Andrey Smirnov who made me aware of this issue. =20

Quoted 19 lines · Abel Vesa

From: Lucas Stach <[email protected]>
=20
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.
=20

---

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

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

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+	val =3D readl_relaxed(pll->base + PLL_CFG2);
+	val &=3D ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+	val |=3D (divf - 1) << PLL_DIVF1_SHIFT;
+	writel_relaxed(val, pll->base + PLL_CFG2);
+
+	/* FIXME: PLL lock check */

=20
Shouldn't be too hard to add, no?

Added to the next version which I intend to send today.

Quoted 15 lines

=20

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

Quoted 12 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+	return 0;
+}
+
+static int clk_pll1_prepare(struct clk_hw *hw)
+{
+	struct clk_sccg_pll *pll =3D to_clk_sccg_pll(hw);
+	u32 val;
+
+	val =3D readl_relaxed(pll->base);
+	val &=3D ~(1 << PLL_PD);
+	writel_relaxed(val, pll->base);

=20
pll->base + PLL_CFG0 please.

Same as above.

Quoted 19 lines

=20

Quoted 4 lines
(quoted diff) +4 -0
+static const struct clk_ops clk_sccg_pll1_ops =3D {
+	.is_prepared	=3D clk_pll1_is_prepared,
+	.recalc_rate	=3D clk_pll1_recalc_rate,
+	.round_rate	=3D clk_pll1_round_rate,

Review

Quoted 10 lines
(quoted diff) +10 -0
+	.set_rate	=3D clk_pll1_set_rate,
+};
+
+static const struct clk_ops clk_sccg_pll2_ops =3D {
+	.prepare	=3D clk_pll1_prepare,
+	.unprepare	=3D clk_pll1_unprepare,
+	.recalc_rate	=3D clk_pll2_recalc_rate,
+	.round_rate	=3D clk_pll2_round_rate,
+	.set_rate	=3D clk_pll2_set_rate,
+};

=20
So these are two PLLs that share the same enable register. Doing the prepare/unprepare for only one PLL can lead to all kinds of trouble. Finding a good abstraction the properly handles this case with the

Quoted 8 lines

clock framework is probably also not easy.
=20
I could imagine we'll need to track the enable state on both PLLs and only if both are disabled we disable it in hardware.
=20
With the current code we disable the PLLs when all consumers are reparented to pll1, which probably has bad effects.
=20

So it took me a while to understand exactly why this needs to stay like it = is.

The PLL1 is never used by any device, instead it is used as a source for PL= L2.

But because the interlink between the two of them is too complicated, the PLLs 1 and 2 need to be separate clocks.

As for the disabling, it's safe to disable just the second one because, as mentioned above, the first PLL is never used alone by a device.

If there isn't anything else here to discuss, I would like to send the next version of this patchset with all the other comments taken care of.

Abel

Quoted 4 lines

Sascha
=20
--=20
Pengutronix e.K. | =

|

Quoted 1 line

Industrial Linux Solutions | https://emea01.safelinks.pro=

tection.outlook.com/?url=3Dhttp%3A%2F%2Fwww.pengutronix.de%2F&amp;data=3D02= %7C01%7Cabel.vesa%40nxp.com%7C5e9c7c6f9e464ed522f108d60994d471%7C686ea1d3bc= 2b4c6fa92cd99c5c301635%7C0%7C0%7C636706932168087639&amp;sdata=3DXbfFq5z%2FR= tkq6yGgwSyk6dNCZVuXOzY%2Fiygmwle3C2I%3D&amp;reserved=3D0 |

Quoted 1 line

Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 =

|

Quoted 1 line

Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 =

|

-- =

#14 lore raw

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

In reply to Abel Vesa
Quoted 360 lines · Abel Vesa

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, with only some small adaptions to mainline from me.

---
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mq.c | 631 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h        |  36 +++
 3 files changed, 668 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 +328 -0
new file mode 100644
index 0000000..d3a9e31
@@ -0,0 +1,631 @@
+// 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>
+#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;
+
+static struct clk *clks[IMX8MQ_CLK_END];
+
+static const char *pll_ref_sels[] = { "osc_25m", "osc_27m", "dummy", "dummy", };
+static const char *arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", };
+static const char *gpu_pll_bypass_sels[] = {"gpu_pll", "gpu_pll_ref_sel", };
+static const char *vpu_pll_bypass_sels[] = {"vpu_pll", "vpu_pll_ref_sel", };
+static const char *audio_pll1_bypass_sels[] = {"audio_pll1", "audio_pll1_ref_sel", };
+static const char *audio_pll2_bypass_sels[] = {"audio_pll2", "audio_pll2_ref_sel", };
+static const char *video_pll1_bypass_sels[] = {"video_pll1", "video_pll1_ref_sel", };
+
+static const char *sys1_pll1_out_sels[] = {"sys1_pll1", "sys1_pll1_ref_sel", };
+static const char *sys2_pll1_out_sels[] = {"sys2_pll1", "sys1_pll1_ref_sel", };
+static const char *sys3_pll1_out_sels[] = {"sys3_pll1", "sys3_pll1_ref_sel", };
+static const char *dram_pll1_out_sels[] = {"dram_pll1", "dram_pll1_ref_sel", };
+static const char *video2_pll1_out_sels[] = {"video2_pll1", "video2_pll1_ref_sel", };
+
+static const char *sys1_pll2_out_sels[] = {"sys1_pll2_div", "sys1_pll1_ref_sel", };
+static const char *sys2_pll2_out_sels[] = {"sys2_pll2_div", "sys2_pll1_ref_sel", };
+static const char *sys3_pll2_out_sels[] = {"sys3_pll2_div", "sys2_pll1_ref_sel", };
+static const char *dram_pll2_out_sels[] = {"dram_pll2_div", "dram_pll1_ref_sel", };
+static const char *video2_pll2_out_sels[] = {"video2_pll2_div", "video2_pll1_ref_sel", };
+
+/* CCM ROOT */
+static const char *imx8mq_a53_sels[] = {"osc_25m", "arm_pll_out", "sys2_pll_500m", "sys2_pll_1000m",
+                                       "sys1_pll_800m", "sys1_pll_400m", "audio_pll1_out", "sys3_pll2_out", };
+
+static const char *imx8mq_vpu_sels[] = {"osc_25m", "arm_pll_out", "sys2_pll_500m", "sys2_pll_1000m",
+                                       "sys1_pll_800m", "sys1_pll_400m", "audio_pll1_out", "vpu_pll_out", };
+
+static const char *imx8mq_gpu_core_sels[] = {"osc_25m", "gpu_pll_out", "sys1_pll_800m", "sys3_pll2_out",
+                                            "sys2_pll_1000m", "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_gpu_shader_sels[] = {"osc_25m", "gpu_pll_out", "sys1_pll_800m", "sys3_pll2_out",
+                                              "sys2_pll_1000m", "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_main_axi_sels[] = {"osc_25m", "sys2_pll_333m", "sys1_pll_800m", "sys2_pll_250m",
+                                            "sys2_pll_1000m", "audio_pll1_out", "video_pll1_out", "sys1_pll_100m",};
+
+static const char *imx8mq_enet_axi_sels[] = {"osc_25m", "sys1_pll_266m", "sys1_pll_800m", "sys2_pll_250m",
+                                            "sys2_pll_200m", "audio_pll1_out", "video_pll1_out", "sys3_pll2_out", };
+
+static const char *imx8mq_nand_usdhc_sels[] = {"osc_25m", "sys1_pll_266m", "sys1_pll_800m", "sys2_pll_200m",
+                                              "sys1_pll_133m", "sys3_pll2_out", "sys2_pll_250m", "audio_pll1_out", };
+
+static const char *imx8mq_vpu_bus_sels[] = {"osc_25m", "sys1_pll_800m", "vpu_pll_out", "audio_pll2_out", "sys3_pll2_out", "sys2_pll_1000m", "sys2_pll_200m", "sys1_pll_100m", };
+
+static const char *imx8mq_disp_axi_sels[] = {"osc_25m", "sys2_pll_125m", "sys1_pll_800m", "sys3_pll2_out", "sys1_pll_400m", "audio_pll2_out", "clk_ext1", "clk_ext4", };
+
+static const char *imx8mq_disp_apb_sels[] = {"osc_25m", "sys2_pll_125m", "sys1_pll_800m", "sys3_pll2_out",
+                                            "sys1_pll_40m", "audio_pll2_out", "clk_ext1", "clk_ext3", };
+
+static const char *imx8mq_disp_rtrm_sels[] = {"osc_25m", "sys1_pll_800m", "sys2_pll_200m", "sys1_pll_400m",
+                                             "audio_pll1_out", "video_pll1_out", "clk_ext2", "clk_ext3", };
+
+static const char *imx8mq_usb_bus_sels[] = {"osc_25m", "sys2_pll_500m", "sys1_pll_800m", "sys2_pll_100m",
+                                           "sys2_pll_200m", "clk_ext2", "clk_ext4", "audio_pll2_out", };
+
+static const char *imx8mq_gpu_axi_sels[] = {"osc_25m", "sys1_pll_800m", "gpu_pll_out", "sys3_pll2_out", "sys2_pll_1000m",
+                                           "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_gpu_ahb_sels[] = {"osc_25m", "sys1_pll_800m", "gpu_pll_out", "sys3_pll2_out", "sys2_pll_1000m",
+                                           "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_noc_sels[] = {"osc_25m", "sys1_pll_800m", "sys3_pll2_out", "sys2_pll_1000m", "sys2_pll_500m",
+                                       "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_noc_apb_sels[] = {"osc_25m", "sys1_pll_400m", "sys3_pll2_out", "sys2_pll_333m", "sys2_pll_200m",
+                                           "sys1_pll_800m", "audio_pll1_out", "video_pll1_out", };
+
+static const char *imx8mq_ahb_sels[] = {"osc_25m", "sys1_pll_133m", "sys1_pll_800m", "sys1_pll_400m",
+                                       "sys2_pll_125m", "sys3_pll2_out", "audio_pll1_out", "video_pll1_out", };
+
+static const char *imx8mq_audio_ahb_sels[] = {"osc_25m", "sys2_pll_500m", "sys1_pll_800m", "sys2_pll_1000m",
+                                                 "sys2_pll_166m", "sys3_pll2_out", "audio_pll1_out", "video_pll1_out", };
+
+static const char *imx8mq_dsi_ahb_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_800m",
+                                               "sys2_pll_1000m", "sys3_pll2_out", "clk_ext3", "audio_pll2_out"};
+
+static const char *imx8mq_dram_alt_sels[] = {"osc_25m", "sys1_pll_800m", "sys1_pll_100m", "sys2_pll_500m",
+                                               "sys2_pll_250m", "sys1_pll_400m", "audio_pll1_out", "sys1_pll_266m", };
+
+static const char *imx8mq_dram_apb_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_vpu_g1_sels[] = {"osc_25m", "vpu_pll_out", "sys1_pll_800m", "sys2_pll_1000m", "sys1_pll_100m", "sys2_pll_125m", "sys3_pll2_out", "audio_pll1_out", };
+
+static const char *imx8mq_vpu_g2_sels[] = {"osc_25m", "vpu_pll_out", "sys1_pll_800m", "sys2_pll_1000m", "sys1_pll_100m", "sys2_pll_125m", "sys3_pll2_out", "audio_pll1_out", };
+
+static const char *imx8mq_disp_dtrc_sels[] = {"osc_25m", "vpu_pll_out", "sys1_pll_800m", "sys2_pll_1000m", "sys1_pll_160m", "sys2_pll_100m", "sys3_pll2_out", "audio_pll2_out", };
+
+static const char *imx8mq_disp_dc8000_sels[] = {"osc_25m", "vpu_pll_out", "sys1_pll_800m", "sys2_pll_1000m", "sys1_pll_160m", "sys2_pll_100m", "sys3_pll2_out", "audio_pll2_out", };
+
+static const char *imx8mq_pcie1_ctrl_sels[] = {"osc_25m", "sys2_pll_250m", "sys2_pll_200m", "sys1_pll_266m",
+                                              "sys1_pll_800m", "sys2_pll_500m", "sys2_pll_250m", "sys3_pll2_out", };
+
+static const char *imx8mq_pcie1_phy_sels[] = {"osc_25m", "sys2_pll_100m", "sys2_pll_500m", "clk_ext1", "clk_ext2",
+                                             "clk_ext3", "clk_ext4", };
+
+static const char *imx8mq_pcie1_aux_sels[] = {"osc_25m", "sys2_pll_200m", "sys2_pll_500m", "sys3_pll2_out",
+                                             "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_160m", "sys1_pll_200m", };
+
+static const char *imx8mq_dc_pixel_sels[] = {"osc_25m", "video_pll1_out", "audio_pll2_out", "audio_pll1_out", "sys1_pll_800m", "sys2_pll_1000m", "sys3_pll2_out", "clk_ext4", };
+
+static const char *imx8mq_lcdif_pixel_sels[] = {"osc_25m", "video_pll1_out", "audio_pll2_out", "audio_pll1_out", "sys1_pll_800m", "sys2_pll_1000m", "sys3_pll2_out", "clk_ext4", };
+
+static const char *imx8mq_sai1_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext1", "clk_ext2", };
+
+static const char *imx8mq_sai2_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext2", "clk_ext3", };
+
+static const char *imx8mq_sai3_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext3", "clk_ext4", };
+
+static const char *imx8mq_sai4_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext1", "clk_ext2", };
+
+static const char *imx8mq_sai5_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext2", "clk_ext3", };
+
+static const char *imx8mq_sai6_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext3", "clk_ext4", };
+
+static const char *imx8mq_spdif1_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext2", "clk_ext3", };
+
+static const char *imx8mq_spdif2_sels[] = {"osc_25m", "audio_pll1_out", "audio_pll2_out", "video_pll1_out", "sys1_pll_133m", "osc_27m", "clk_ext3", "clk_ext4", };
+
+static const char *imx8mq_enet_ref_sels[] = {"osc_25m", "sys2_pll_125m", "sys2_pll_500m", "sys2_pll_100m",
+                                            "sys1_pll_160m", "audio_pll1_out", "video_pll1_out", "clk_ext4", };
+
+static const char *imx8mq_enet_timer_sels[] = {"osc_25m", "sys2_pll_100m", "audio_pll1_out", "clk_ext1", "clk_ext2",
+                                              "clk_ext3", "clk_ext4", "video_pll1_out", };
+
+static const char *imx8mq_enet_phy_sels[] = {"osc_25m", "sys2_pll_50m", "sys2_pll_125m", "sys2_pll_500m",
+                                            "audio_pll1_out", "video_pll1_out", "audio_pll2_out", };
+
+static const char *imx8mq_nand_sels[] = {"osc_25m", "sys2_pll_500m", "audio_pll1_out", "sys1_pll_400m",
+                                        "audio_pll2_out", "sys3_pll2_out", "sys2_pll_250m", "video_pll1_out", };
+
+static const char *imx8mq_qspi_sels[] = {"osc_25m", "sys1_pll_400m", "sys1_pll_800m", "sys2_pll_500m",
+                                        "audio_pll2_out", "sys1_pll_266m", "sys3_pll2_out", "sys1_pll_100m", };
+
+static const char *imx8mq_usdhc1_sels[] = {"osc_25m", "sys1_pll_400m", "sys1_pll_800m", "sys2_pll_500m",
+                                        "audio_pll2_out", "sys1_pll_266m", "sys3_pll2_out", "sys1_pll_100m", };
+
+static const char *imx8mq_usdhc2_sels[] = {"osc_25m", "sys1_pll_400m", "sys1_pll_800m", "sys2_pll_500m",
+                                        "audio_pll2_out", "sys1_pll_266m", "sys3_pll2_out", "sys1_pll_100m", };
+
+static const char *imx8mq_i2c1_sels[] = {"osc_25m", "sys1_pll_160m", "sys2_pll_50m", "sys3_pll2_out", "audio_pll1_out",
+                                        "video_pll1_out", "audio_pll2_out", "sys1_pll_133m", };
+
+static const char *imx8mq_i2c2_sels[] = {"osc_25m", "sys1_pll_160m", "sys2_pll_50m", "sys3_pll2_out", "audio_pll1_out",
+                                        "video_pll1_out", "audio_pll2_out", "sys1_pll_133m", };
+
+static const char *imx8mq_i2c3_sels[] = {"osc_25m", "sys1_pll_160m", "sys2_pll_50m", "sys3_pll2_out", "audio_pll1_out",
+                                        "video_pll1_out", "audio_pll2_out", "sys1_pll_133m", };
+
+static const char *imx8mq_i2c4_sels[] = {"osc_25m", "sys1_pll_160m", "sys2_pll_50m", "sys3_pll2_out", "audio_pll1_out",
+                                        "video_pll1_out", "audio_pll2_out", "sys1_pll_133m", };
+
+static const char *imx8mq_uart1_sels[] = {"osc_25m", "sys1_pll_80m", "sys2_pll_200m", "sys2_pll_100m",
+                                         "sys3_pll2_out", "clk_ext2", "clk_ext4", "audio_pll2_out", };
+
+static const char *imx8mq_uart2_sels[] = {"osc_25m", "sys1_pll_80m", "sys2_pll_200m", "sys2_pll_100m",
+                                         "sys3_pll2_out", "clk_ext2", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_uart3_sels[] = {"osc_25m", "sys1_pll_80m", "sys2_pll_200m", "sys2_pll_100m",
+                                         "sys3_pll2_out", "clk_ext2", "clk_ext4", "audio_pll2_out", };
+
+static const char *imx8mq_uart4_sels[] = {"osc_25m", "sys1_pll_80m", "sys2_pll_200m", "sys2_pll_100m",
+                                         "sys3_pll2_out", "clk_ext2", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_usb_core_sels[] = {"osc_25m", "sys1_pll_100m", "sys1_pll_40m", "sys2_pll_100m",
+                                            "sys2_pll_200m", "clk_ext2", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_usb_phy_sels[] = {"osc_25m", "sys1_pll_100m", "sys1_pll_40m", "sys2_pll_100m",
+                                            "sys2_pll_200m", "clk_ext2", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_ecspi1_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_ecspi2_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_pwm1_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_160m", "sys1_pll_40m",
+                                        "sys3_pll2_out", "clk_ext1", "sys1_pll_80m", "video_pll1_out", };
+
+static const char *imx8mq_pwm2_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_160m", "sys1_pll_40m",
+                                        "sys3_pll2_out", "clk_ext1", "sys1_pll_80m", "video_pll1_out", };
+
+static const char *imx8mq_pwm3_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_160m", "sys1_pll_40m",
+                                        "sys3_pll2_out", "clk_ext2", "sys1_pll_80m", "video_pll1_out", };
+
+static const char *imx8mq_pwm4_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_160m", "sys1_pll_40m",
+                                        "sys3_pll2_out", "clk_ext2", "sys1_pll_80m", "video_pll1_out", };
+
+static const char *imx8mq_gpt1_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_400m", "sys1_pll_40m",
+                                        "sys1_pll_80m", "audio_pll1_out", "clk_ext1", };
+
+static const char *imx8mq_wdog_sels[] = {"osc_25m", "sys1_pll_133m", "sys1_pll_160m", "vpu_pll_out",
+                                        "sys2_pll_125m", "sys3_pll2_out", "sys1_pll_80m", "sys2_pll_166m", };
+
+static const char *imx8mq_wrclk_sels[] = {"osc_25m", "sys1_pll_40m", "vpu_pll_out", "sys3_pll2_out", "sys2_pll_200m",
+                                         "sys1_pll_266m", "sys2_pll_500m", "sys1_pll_100m", };
+
+static const char *imx8mq_dsi_core_sels[] = {"osc_25m", "sys1_pll_266m", "sys2_pll_250m", "sys1_pll_800m",
+                                            "sys2_pll_1000m", "sys3_pll2_out", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_dsi_phy_sels[] = {"osc_25m", "sys2_pll_125m", "sys2_pll_100m", "sys1_pll_800m",
+                                           "sys2_pll_1000m", "clk_ext2", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_dsi_dbi_sels[] = {"osc_25m", "sys1_pll_266m", "sys2_pll_100m", "sys1_pll_800m",
+                                           "sys2_pll_1000m", "sys3_pll2_out", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_dsi_esc_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_800m",
+                                           "sys2_pll_1000m", "sys3_pll2_out", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_csi1_core_sels[] = {"osc_25m", "sys1_pll_266m", "sys2_pll_250m", "sys1_pll_800m",
+                                             "sys2_pll_1000m", "sys3_pll2_out", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_csi1_phy_sels[] = {"osc_25m", "sys2_pll_125m", "sys2_pll_100m", "sys1_pll_800m",
+                                            "sys2_pll_1000m", "clk_ext2", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_csi1_esc_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_800m",
+                                            "sys2_pll_1000m", "sys3_pll2_out", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_csi2_core_sels[] = {"osc_25m", "sys1_pll_266m", "sys2_pll_250m", "sys1_pll_800m",
+                                             "sys2_pll_1000m", "sys3_pll2_out", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_csi2_phy_sels[] = {"osc_25m", "sys2_pll_125m", "sys2_pll_100m", "sys1_pll_800m",
+                                            "sys2_pll_1000m", "clk_ext2", "audio_pll2_out", "video_pll1_out", };
+
+static const char *imx8mq_csi2_esc_sels[] = {"osc_25m", "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_800m",
+                                            "sys2_pll_1000m", "sys3_pll2_out", "clk_ext3", "audio_pll2_out", };
+
+static const char *imx8mq_pcie2_ctrl_sels[] = {"osc_25m", "sys2_pll_250m", "sys2_pll_200m", "sys1_pll_266m",
+                                              "sys1_pll_800m", "sys2_pll_500m", "sys2_pll_333m", "sys3_pll2_out", };
+
+static const char *imx8mq_pcie2_phy_sels[] = {"osc_25m", "sys2_pll_100m", "sys2_pll_500m", "clk_ext1",
+                                             "clk_ext2", "clk_ext3", "clk_ext4", "sys1_pll_400m", };
+
+static const char *imx8mq_pcie2_aux_sels[] = {"osc_25m", "sys2_pll_200m", "sys2_pll_50m", "sys3_pll2_out",
+                                             "sys2_pll_100m", "sys1_pll_80m", "sys1_pll_160m", "sys1_pll_200m", };
+
+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 int const clks_init_on[] __initconst = {
+       IMX8MQ_CLK_DRAM_CORE, IMX8MQ_CLK_AHB_CG,
+       IMX8MQ_CLK_NOC, IMX8MQ_CLK_NOC_APB,
+       IMX8MQ_CLK_USB_BUS, IMX8MQ_CLK_NAND_USDHC_BUS,
+       IMX8MQ_CLK_MAIN_AXI, IMX8MQ_CLK_A53_CG,
+       IMX8MQ_CLK_AUDIO_AHB_DIV, IMX8MQ_CLK_TMU_ROOT,
+       IMX8MQ_CLK_DRAM_APB,
+};
+
+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");
+       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);
+
+       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));
+       clks[IMX8MQ_AUDIO_PLL2_REF_SEL] = imx_clk_mux("audio_pll2_ref_sel", base + 0x8, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_VIDEO_PLL1_REF_SEL] = imx_clk_mux("video_pll1_ref_sel", base + 0x10, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_SYS1_PLL1_REF_SEL]  = imx_clk_mux("sys1_pll1_ref_sel", base + 0x30, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_SYS2_PLL1_REF_SEL]  = imx_clk_mux("sys2_pll1_ref_sel", base + 0x3c, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_SYS3_PLL1_REF_SEL]  = imx_clk_mux("sys3_pll1_ref_sel", base + 0x48, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_DRAM_PLL1_REF_SEL]  = imx_clk_mux("dram_pll1_ref_sel", base + 0x60, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MQ_VIDEO2_PLL1_REF_SEL] = imx_clk_mux("video2_pll1_ref_sel", base + 0x54, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+
+       clks[IMX8MQ_ARM_PLL_REF_DIV]    = imx_clk_divider("arm_pll_ref_div", "arm_pll_ref_sel", base + 0x28, 5, 6);
+       clks[IMX8MQ_GPU_PLL_REF_DIV]    = imx_clk_divider("gpu_pll_ref_div", "gpu_pll_ref_sel", base + 0x18, 5, 6);
+       clks[IMX8MQ_VPU_PLL_REF_DIV]    = imx_clk_divider("vpu_pll_ref_div", "vpu_pll_ref_sel", base + 0x20, 5, 6);
+       clks[IMX8MQ_AUDIO_PLL1_REF_DIV] = imx_clk_divider("audio_pll1_ref_div", "audio_pll1_ref_sel", base + 0x0, 5, 6);
+       clks[IMX8MQ_AUDIO_PLL2_REF_DIV] = imx_clk_divider("audio_pll2_ref_div", "audio_pll2_ref_sel", base + 0x8, 5, 6);
+       clks[IMX8MQ_VIDEO_PLL1_REF_DIV] = imx_clk_divider("video_pll1_ref_div", "video_pll1_ref_sel", base + 0x10, 5, 6);
+       clks[IMX8MQ_SYS1_PLL1_REF_DIV]  = imx_clk_divider("sys1_pll1_ref_div", "sys1_pll1_ref_sel", base + 0x38, 25, 3);
+       clks[IMX8MQ_SYS2_PLL1_REF_DIV]  = imx_clk_divider("sys2_pll1_ref_div", "sys2_pll1_ref_sel", base + 0x44, 25, 3);
+       clks[IMX8MQ_SYS3_PLL1_REF_DIV]  = imx_clk_divider("sys3_pll1_ref_div", "sys3_pll1_ref_sel", base + 0x50, 25, 3);
+       clks[IMX8MQ_DRAM_PLL1_REF_DIV]  = imx_clk_divider("dram_pll1_ref_div", "dram_pll1_ref_sel", base + 0x68, 25, 3);
+       clks[IMX8MQ_VIDEO2_PLL1_REF_DIV]  = imx_clk_divider("video2_pll1_ref_div", "video2_pll1_ref_sel", base + 0x5c, 25, 3);
+
+       clks[IMX8MQ_ARM_PLL] = imx_clk_frac_pll("arm_pll", "arm_pll_ref_div", base + 0x28);

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

Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c new file +10 -0
+       clks[IMX8MQ_GPU_PLL] = imx_clk_frac_pll("gpu_pll", "gpu_pll_ref_div", base + 0x18);
+       clks[IMX8MQ_VPU_PLL] = imx_clk_frac_pll("vpu_pll", "vpu_pll_ref_div", base + 0x20);
+       clks[IMX8MQ_AUDIO_PLL1] = imx_clk_frac_pll("audio_pll1", "audio_pll1_ref_div", base + 0x0);
+       clks[IMX8MQ_AUDIO_PLL2] = imx_clk_frac_pll("audio_pll2", "audio_pll2_ref_div", base + 0x8);
+       clks[IMX8MQ_VIDEO_PLL1] = imx_clk_frac_pll("video_pll1", "video_pll1_ref_div", base + 0x10);
+       clks[IMX8MQ_SYS1_PLL1] = imx_clk_sccg_pll("sys1_pll1", "sys1_pll1_ref_div", base + 0x30, SCCG_PLL1);
+       clks[IMX8MQ_SYS2_PLL1] = imx_clk_sccg_pll("sys2_pll1", "sys2_pll1_ref_div", base + 0x3c, SCCG_PLL1);
+       clks[IMX8MQ_SYS3_PLL1] = imx_clk_sccg_pll("sys3_pll1", "sys3_pll1_ref_div", base + 0x48, SCCG_PLL1);
+       clks[IMX8MQ_DRAM_PLL1] = imx_clk_sccg_pll("dram_pll1", "dram_pll1_ref_div", base + 0x60, SCCG_PLL1);
+       clks[IMX8MQ_VIDEO2_PLL1] = imx_clk_sccg_pll("video2_pll1", "video2_pll1_ref_div", base + 0x5c, 3);

This is a bug which will result in a crash once IMX8MQ_VIDEO2_PLL1 is exercised (I know that from having to debug this issue when using this code in Barebox). Last argument should be SCCG_PLL1.

Thanks,
Andrey Smirnov

#9 lore raw

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

In reply to Abel Vesa
Quoted 245 lines · Abel Vesa

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 | 231 +++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h          |   9 ++
 3 files changed, 242 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 +208 -0
new file mode 100644
index 0000000..886ae03
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright 2018 NXP.
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+
+#include "clk.h"
+
+/* PLL CFGs */
+#define PLL_CFG0       0x0
+#define PLL_CFG1       0x4
+#define PLL_CFG2       0x8
+
+#define PLL_DIVF1_SHIFT        13
+#define PLL_DIVF2_SHIFT        7
+#define PLL_DIVF_MASK  0x3f
+
+#define PLL_DIVR1_SHIFT        25
+#define PLL_DIVR2_SHIFT        19
+#define PLL_DIVR1_MASK 0x3
+#define PLL_DIVR2_MASK 0x3f
+#define PLL_REF_SHIFT  0
+#define PLL_REF_MASK   0x3
+
+#define PLL_LOCK       31
+#define PLL_PD         7
+
+#define OSC_25M                25000000
+#define OSC_27M                27000000
+
+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_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 & (1 << PLL_PD)) ? 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 = (val >> PLL_DIVF1_SHIFT) & PLL_DIVF_MASK;
+
+       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);
+
+       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);
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+       val |= (divf - 1) << PLL_DIVF1_SHIFT;
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       /* FIXME: PLL lock check */
+
+       return 0;
+}
+
+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);
+       val &= ~(1 << PLL_PD);
+       writel_relaxed(val, pll->base);
+
+       /* FIXME: PLL lock check */
+
+       return 0;
+}
+
+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);
+       val |= (1 << PLL_PD);
+       writel_relaxed(val, pll->base);
+}
+
+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 ((val >> PLL_REF_SHIFT) & PLL_REF_MASK) {
+       case 0:
+               ref = OSC_25M;
+               break;
+       case 1:
+               ref = OSC_27M;
+               break;
+       default:
+               ref = OSC_25M;
+               break;
+       }
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       divr1 = (val >> PLL_DIVR1_SHIFT) & PLL_DIVR1_MASK;
+       divr2 = (val >> PLL_DIVR2_SHIFT) & PLL_DIVR2_MASK;
+       divf1 = (val >> PLL_DIVF1_SHIFT) & PLL_DIVF_MASK;
+       divf2 = (val >> PLL_DIVF2_SHIFT) & PLL_DIVF_MASK;
+
+       temp64 = ref * 2;
+       temp64 *= (divf1 + 1) * (divf2 + 1);
+
+       do_div(temp64, (divr1 + 1) * (divr2 + 1));
+
+       return (unsigned long)temp64;
+}
+
+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)
+{
+       u32 val;
+       u32 divf;
+       struct clk_sccg_pll *pll = to_clk_sccg_pll(hw);
+
+       divf = rate / (parent_rate);
+
+       val = readl_relaxed(pll->base + PLL_CFG2);
+       val &= ~(PLL_DIVF_MASK << PLL_DIVF2_SHIFT);
+       val |= (divf - 1) << PLL_DIVF2_SHIFT;
+       writel_relaxed(val, pll->base + PLL_CFG2);
+
+       /* FIXME: PLL lock check */
+
+       return 0;
+}
+
+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);
+

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

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+       pll->base = base;
+       init.name = name;
+       switch (pll_type) {
+       case SCCG_PLL1:
+               init.ops = &clk_sccg_pll1_ops;
+               break;
+       case SCCG_PLL2:
+               init.ops = &clk_sccg_pll2_ops;
+               break;
+       }

Please add error checking in the switch above since it's pretty clear that a wrong kind of argument can be passed as a pll_type without it being noticeable.

Thanks,
Andrey Smirnov

#6 lore raw

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

In reply to Abel Vesa
Quoted 74 lines · Abel Vesa
Quoted 22 lines · Sascha Hauer

+Cc Andrey Smirnov who made me aware of this issue.

Quoted 19 lines · Abel Vesa

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/clk-sccg-pll.c new file +9 -0
+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);
+
Quoted 8 lines

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

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+   val = readl_relaxed(pll->base + PLL_CFG2);
+   val &= ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+   val |= (divf - 1) << PLL_DIVF1_SHIFT;
+   writel_relaxed(val, pll->base + PLL_CFG2);
+
+   /* FIXME: PLL lock check */

Shouldn't be too hard to add, no?

Added to the next version which I intend to send today.

Quoted 15 lines

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

Quoted 13 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+   return 0;
+}
+
+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);
+   val &= ~(1 << PLL_PD);
+   writel_relaxed(val, pll->base);

pll->base + PLL_CFG0 please.

Same as above.

Quoted 21 lines
Quoted 5 lines
drivers/clk/imx/clk-sccg-pll.c new file +4 -0
+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,

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

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+   .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,
+};

So these are two PLLs that share the same enable register. Doing the prepare/unprepare for only one PLL can lead to all kinds of trouble. Finding a good abstraction the properly handles this case with the clock framework is probably also not easy.

Quoted 9 lines
Quoted 6 lines

I could imagine we'll need to track the enable state on both PLLs and only if both are disabled we disable it in hardware.

With the current code we disable the PLLs when all consumers are reparented to pll1, which probably has bad effects.

So it took me a while to understand exactly why this needs to stay like it is.

IMHO this means that, if nothing else, all of the below should be documented in code as a comment, otherwise simpletons like me are going to continue stumbling over it and wondering what's going on.

Quoted 5 lines

The PLL1 is never used by any device, instead it is used as a source for PLL2.

But because the interlink between the two of them is too complicated, the PLLs 1 and 2 need to be separate clocks.

Can you go a little bit more into detail as for why PLL1 needs to be exposed in the first place and can't just be dealt with behind the scenes as a part of PLL2 abstraction? Are there use-cases where the rates of the two are going to be adjusted individually in Linux?

Thanks,
Andrey Smirnov

author
#7 lore raw

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

Quoted 9 lines · Andrey Smirnov
Quoted 8 lines · Abel Vesa
Quoted 6 lines · Sascha Hauer

+Cc Andrey Smirnov who made me aware of this issue.

Quoted 3 lines · Abel Vesa

From: Lucas Stach <[email protected]>

The SCCG is a new PLL type introduced on i.MX8. Add support for thi=

s.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The driver currently misses the PLL lock check, as the preliminary documentation mentions lock configurations, but is quiet about wher=

e

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

to find the actual lock status signal.

---
+static int clk_pll1_set_rate(struct clk_hw *hw, unsigned long rate=

,

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

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

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+   val =3D readl_relaxed(pll->base + PLL_CFG2);
+   val &=3D ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+   val |=3D (divf - 1) << PLL_DIVF1_SHIFT;
+   writel_relaxed(val, pll->base + PLL_CFG2);
+
+   /* FIXME: PLL lock check */

Shouldn't be too hard to add, no?

Added to the next version which I intend to send today.

Quoted 15 lines

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

Quoted 13 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+   return 0;
+}
+
+static int clk_pll1_prepare(struct clk_hw *hw)
+{
+   struct clk_sccg_pll *pll =3D to_clk_sccg_pll(hw);
+   u32 val;
+
+   val =3D readl_relaxed(pll->base);
+   val &=3D ~(1 << PLL_PD);
+   writel_relaxed(val, pll->base);

pll->base + PLL_CFG0 please.

Same as above.

Quoted 21 lines
Quoted 5 lines
(quoted diff) +4 -0
+static const struct clk_ops clk_sccg_pll1_ops =3D {
+   .is_prepared    =3D clk_pll1_is_prepared,
+   .recalc_rate    =3D clk_pll1_recalc_rate,
+   .round_rate     =3D clk_pll1_round_rate,

Review

Quoted 10 lines
(quoted diff) +10 -0
+   .set_rate       =3D clk_pll1_set_rate,
+};
+
+static const struct clk_ops clk_sccg_pll2_ops =3D {
+   .prepare        =3D clk_pll1_prepare,
+   .unprepare      =3D clk_pll1_unprepare,
+   .recalc_rate    =3D clk_pll2_recalc_rate,
+   .round_rate     =3D clk_pll2_round_rate,
+   .set_rate       =3D clk_pll2_set_rate,
+};

So these are two PLLs that share the same enable register. Doing the prepare/unprepare for only one PLL can lead to all kinds of trouble. Finding a good abstraction the properly handles this case with the clock framework is probably also not easy.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

I could imagine we'll need to track the enable state on both PLLs and only if both are disabled we disable it in hardware.

With the current code we disable the PLLs when all consumers are reparented to pll1, which probably has bad effects.

So it took me a while to understand exactly why this needs to stay like=

it is.

Quoted 5 lines
Quoted 1 line

=20
IMHO this means that, if nothing else, all of the below should be documented in code as a comment, otherwise simpletons like me are going to continue stumbling over it and wondering what's going on.

Will try to add proper comment to explain what's happening.

Quoted 2 lines

=20

Quoted 1 line

The PLL1 is never used by any device, instead it is used as a source fo=

r PLL2.

Quoted 10 lines
Quoted 4 lines

But because the interlink between the two of them is too complicated, the PLLs 1 and 2 need to be separate clocks.

=20
Can you go a little bit more into detail as for why PLL1 needs to be exposed in the first place and can't just be dealt with behind the scenes as a part of PLL2 abstraction? Are there use-cases where the rates of the two are going to be adjusted individually in Linux? =20

Here is the SCCG PLL Block Diagram:

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

Now lets take the System PLL 2 for example. If you follow the hierarchy, when you reach the sys2_pll1_out you can see that one of its selectors is actually sys1_pll1_ref_sel. Same thing applies to sys3_pll2_out with sys2_pll1_ref_sel. This means there is an input reference clock interlinkin= g
between different System PLLs.

Quoted 2 lines

Thanks,
Andrey Smirnov

-- =

#8 lore raw

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

Quoted 108 lines · Abel Vesa
Quoted 82 lines · Andrey Smirnov
Quoted 81 lines · Abel Vesa
Quoted 22 lines · Sascha Hauer

+Cc Andrey Smirnov who made me aware of this issue.

Quoted 19 lines · Abel Vesa

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/clk-sccg-pll.c new file +9 -0
+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);
+
Quoted 8 lines

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

Quoted 6 lines
drivers/clk/imx/clk-sccg-pll.c new file +6 -0
+   val = readl_relaxed(pll->base + PLL_CFG2);
+   val &= ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT);
+   val |= (divf - 1) << PLL_DIVF1_SHIFT;
+   writel_relaxed(val, pll->base + PLL_CFG2);
+
+   /* FIXME: PLL lock check */

Shouldn't be too hard to add, no?

Added to the next version which I intend to send today.

Quoted 15 lines

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

Quoted 13 lines
drivers/clk/imx/clk-sccg-pll.c new file +12 -0
+
+   return 0;
+}
+
+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);
+   val &= ~(1 << PLL_PD);
+   writel_relaxed(val, pll->base);

pll->base + PLL_CFG0 please.

Same as above.

Quoted 27 lines
Quoted 5 lines
drivers/clk/imx/clk-sccg-pll.c new file +4 -0
+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,

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

Quoted 10 lines
drivers/clk/imx/clk-sccg-pll.c new file +10 -0
+   .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,
+};

So these are two PLLs that share the same enable register. Doing the prepare/unprepare for only one PLL can lead to all kinds of trouble. Finding a good abstraction the properly handles this case with the clock framework is probably also not easy.

I could imagine we'll need to track the enable state on both PLLs and only if both are disabled we disable it in hardware.

With the current code we disable the PLLs when all consumers are reparented to pll1, which probably has bad effects.

Quoted 6 lines
Quoted 2 lines

So it took me a while to understand exactly why this needs to stay like it is.

IMHO this means that, if nothing else, all of the below should be documented in code as a comment, otherwise simpletons like me are going to continue stumbling over it and wondering what's going on.

Will try to add proper comment to explain what's happening.

Quoted 12 lines
Quoted 6 lines

The PLL1 is never used by any device, instead it is used as a source for PLL2.

But because the interlink between the two of them is too complicated, the PLLs 1 and 2 need to be separate clocks.

Can you go a little bit more into detail as for why PLL1 needs to be exposed in the first place and can't just be dealt with behind the scenes as a part of PLL2 abstraction? Are there use-cases where the rates of the two are going to be adjusted individually in Linux?

Here is the SCCG PLL Block Diagram:

Quoted 8 lines

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

Now lets take the System PLL 2 for example. If you follow the hierarchy, when you reach the sys2_pll1_out you can see that one of its selectors is actually sys1_pll1_ref_sel. Same thing applies to sys3_pll2_out with sys2_pll1_ref_sel. This means there is an input reference clock interlinking between different System PLLs.

Hmm, I am not sure I see how this would prevent you from treating a PLL pair as a black box, but OTOH, doing that probably wouldn't result cleaner or simpler code. IMHO, it's unfortunate that PD bit is shared between the two clocks, but if PLL1 could only be ever connected to corresponding PLL2, then my concerns were probably misguided and current implementation is good enough.

Thanks,
Andrey Smirnov