Skip to contentSkip to conversation

clk: imx: Add PLLs driver for imx8mm soc

PATCH Superseded Jacky Bai 3 participants 10 messages Jan 8, 2019 – Jan 21, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jacky Bai

author
#0 lore raw

PATCH 1/3 clk: imx: Add PLLs driver for imx8mm soc

New PLLs are introduced on i.MX8M Mini SOC.
PLL1416X is Integer PLL, PLL1443X is a Frac PLL.

---
 drivers/clk/imx/Makefile      |   3 +-
 drivers/clk/imx/clk-pll14xx.c | 409 ++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/imx/clk.h         |  23 +++
 3 files changed, 434 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/imx/clk-pll14xx.c
drivers/clk/imx/Makefile +2 -1
index 73119fb..ff74287 100644
@@ -18,7 +18,8 @@ obj-$(CONFIG_MXC_CLK) += \
 	clk-pllv2.o \
 	clk-pllv3.o \
 	clk-pllv4.o \
-	clk-sccg-pll.o
+	clk-sccg-pll.o \
+	clk-pll14xx.o
 
 obj-$(CONFIG_MXC_CLK_SCU) += \
 	clk-scu.o \
drivers/clk/imx/clk-pll14xx.c new file +409 -0

409 lines not on this page · raw message

drivers/clk/imx/clk.h +23 -0
index 028312d..27372f7 100644
@@ -27,6 +27,29 @@ enum imx_sccg_pll_type {
 	SCCG_PLL2,
 };
 
+enum imx_pll14xx_type {
+	PLL_1416X,
+	PLL_1443X,
+};
+
+/* NOTE: Rate table should be kept sorted in descending order. */
+struct imx_pll14xx_rate_table {
+	unsigned int rate;
+	unsigned int pdiv;
+	unsigned int mdiv;
+	unsigned int sdiv;
+	unsigned int kdiv;
+};
+
+struct imx_pll14xx_clk {
+	enum imx_pll14xx_type type;
+	const struct imx_pll14xx_rate_table *rate_table;
+	int flags;
+};
+
+struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
+		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
+
 struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
 		const char *parent, void __iomem *base);
 
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 2/3 dt-bindings: imx: Add clock binding doc for imx8mm

Add the clock binding doc for i.MX8MM.

---
 .../devicetree/bindings/clock/imx8mm-clock.txt     |  19 ++
 include/dt-bindings/clock/imx8mm-clock.h           | 244 +++++++++++++++++++++
 2 files changed, 263 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/imx8mm-clock.txt
 create mode 100644 include/dt-bindings/clock/imx8mm-clock.h
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +19 -0
new file mode 100644
index 0000000..034b6d4
@@ -0,0 +1,19 @@
+* Clock bindings for NXP i.MX8M Mini
+
+Required properties:
+- compatible: Should be "fsl,imx8mm-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:
+    - "osc_32k"
+    - "osc_24m"
+    - "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/imx8mm-clock.h
+for the full list of i.MX8M Mini clock IDs.
include/dt-bindings/clock/imx8mm-clock.h new file +244 -0

244 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH 2/3] dt-bindings: imx: Add clock binding doc for imx8mm

Quoting Jacky Bai (2019-01-08 01:00:58)

Quoted 25 lines

Add the clock binding doc for i.MX8MM.

---
 .../devicetree/bindings/clock/imx8mm-clock.txt     |  19 ++
 include/dt-bindings/clock/imx8mm-clock.h           | 244 +++++++++++++++++++++
 2 files changed, 263 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/imx8mm-clock.txt
 create mode 100644 include/dt-bindings/clock/imx8mm-clock.h
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +9 -0
new file mode 100644
index 0000000..034b6d4
@@ -0,0 +1,19 @@
+* Clock bindings for NXP i.MX8M Mini
+
+Required properties:
+- compatible: Should be "fsl,imx8mm-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:

Documentation/devicetree/bindings/clock/imx8mm-clock.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +10 -0
+    - "osc_32k"
+    - "osc_24m"
+    - "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/imx8mm-clock.h
+for the full list of i.MX8M Mini clock IDs.

Any example of this node? Not the clock consumer.

author
#3 lore raw

RE: [PATCH 2/3] dt-bindings: imx: Add clock binding doc for imx8mm

Quoted 36 lines

Subject: Re: [PATCH 2/3] dt-bindings: imx: Add clock binding doc for imx8mm

Quoting Jacky Bai (2019-01-08 01:00:58)

Quoted 6 lines

Add the clock binding doc for i.MX8MM.

---
 .../devicetree/bindings/clock/imx8mm-clock.txt     |  19 ++
 include/dt-bindings/clock/imx8mm-clock.h           | 244

+++++++++++++++++++++

Quoted 26 lines
 2 files changed, 263 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/clock/imx8mm-clock.txt
 create mode 100644 include/dt-bindings/clock/imx8mm-clock.h
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +14 -0
new file mode 100644
index 0000000..034b6d4
@@ -0,0 +1,19 @@
+* Clock bindings for NXP i.MX8M Mini
+
+Required properties:
+- compatible: Should be "fsl,imx8mm-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:
+    - "osc_32k"
+    - "osc_24m"
+    - "clk_ext1"
+    - "clk_ext2"
+    - "clk_ext3"
Quoted 8 lines

Documentation/devicetree/bindings/clock/imx8mm-clock.txt line 19

Quoted 6 lines
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +6 -0
+    - "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/imx8mm-clock.h
+for the full list of i.MX8M Mini clock IDs.

Any example of this node? Not the clock consumer.

Sure, I can add an example in V2.

BR
Jacky Bai

maintainer
#4 lore raw

Re: [PATCH 2/3] dt-bindings: imx: Add clock binding doc for imx8mm

In reply to Jacky Bai
Quoted 41 lines · Jacky Bai

Add the clock binding doc for i.MX8MM.

---
 .../devicetree/bindings/clock/imx8mm-clock.txt     |  19 ++
 include/dt-bindings/clock/imx8mm-clock.h           | 244 +++++++++++++++++++++
 2 files changed, 263 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/imx8mm-clock.txt
 create mode 100644 include/dt-bindings/clock/imx8mm-clock.h
Documentation/devicetree/bindings/clock/imx8mm-clock.txt new file +19 -0
new file mode 100644
index 0000000..034b6d4
@@ -0,0 +1,19 @@
+* Clock bindings for NXP i.MX8M Mini
+
+Required properties:
+- compatible: Should be "fsl,imx8mm-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:
+    - "osc_32k"
+    - "osc_24m"
+    - "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/imx8mm-clock.h
+for the full list of i.MX8M Mini clock IDs.
include/dt-bindings/clock/imx8mm-clock.h new file +0 -0
new file mode 100644
index 0000000..0301581

include/dt-bindings/clock/imx8mm-clock.h line 9

Quoted 9 lines
include/dt-bindings/clock/imx8mm-clock.h new file +9 -0
@@ -0,0 +1,244 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright 2017-2018 NXP
+ */
+
+#ifndef __DT_BINDINGS_CLOCK_IMX8MM_H
+#define __DT_BINDINGS_CLOCK_IMX8MM_H
+
+#define	IMX8MM_CLK_DUMMY			0

Should be a space, not a tab after the #define.

Quoted 238 lines
include/dt-bindings/clock/imx8mm-clock.h new file +235 -0
+#define	IMX8MM_CLK_32K				1
+#define	IMX8MM_CLK_24M				2
+#define	IMX8MM_OSC_HDMI_CLK			3
+#define	IMX8MM_CLK_EXT1				4
+#define	IMX8MM_CLK_EXT2				5
+#define	IMX8MM_CLK_EXT3				6
+#define	IMX8MM_CLK_EXT4				7
+#define	IMX8MM_AUDIO_PLL1_REF_SEL		8
+#define	IMX8MM_AUDIO_PLL2_REF_SEL		9
+#define	IMX8MM_VIDEO_PLL1_REF_SEL		10
+#define	IMX8MM_DRAM_PLL_REF_SEL			11
+#define	IMX8MM_GPU_PLL_REF_SEL			12
+#define	IMX8MM_VPU_PLL_REF_SEL			13
+#define	IMX8MM_ARM_PLL_REF_SEL			14
+#define	IMX8MM_SYS_PLL1_REF_SEL			15
+#define	IMX8MM_SYS_PLL2_REF_SEL			16
+#define	IMX8MM_SYS_PLL3_REF_SEL			17
+#define	IMX8MM_AUDIO_PLL1			18
+#define	IMX8MM_AUDIO_PLL2			19
+#define	IMX8MM_VIDEO_PLL1			20
+#define	IMX8MM_DRAM_PLL				21
+#define	IMX8MM_GPU_PLL				22
+#define	IMX8MM_VPU_PLL				23
+#define	IMX8MM_ARM_PLL				24
+#define	IMX8MM_SYS_PLL1				25
+#define	IMX8MM_SYS_PLL2				26
+#define	IMX8MM_SYS_PLL3				27
+#define	IMX8MM_AUDIO_PLL1_BYPASS		28
+#define	IMX8MM_AUDIO_PLL2_BYPASS		29
+#define	IMX8MM_VIDEO_PLL1_BYPASS		30
+#define	IMX8MM_DRAM_PLL_BYPASS			31
+#define	IMX8MM_GPU_PLL_BYPASS			32
+#define	IMX8MM_VPU_PLL_BYPASS			33
+#define	IMX8MM_ARM_PLL_BYPASS			34
+#define	IMX8MM_SYS_PLL1_BYPASS			35
+#define	IMX8MM_SYS_PLL2_BYPASS			36
+#define	IMX8MM_SYS_PLL3_BYPASS			37
+#define	IMX8MM_AUDIO_PLL1_OUT			38
+#define	IMX8MM_AUDIO_PLL2_OUT			39
+#define	IMX8MM_VIDEO_PLL1_OUT			40
+#define	IMX8MM_DRAM_PLL_OUT			41
+#define	IMX8MM_GPU_PLL_OUT			42
+#define	IMX8MM_VPU_PLL_OUT			43
+#define	IMX8MM_ARM_PLL_OUT			44
+#define	IMX8MM_SYS_PLL1_OUT			45
+#define	IMX8MM_SYS_PLL2_OUT			46
+#define	IMX8MM_SYS_PLL3_OUT			47
+#define	IMX8MM_SYS_PLL1_40M			48
+#define	IMX8MM_SYS_PLL1_80M			49
+#define	IMX8MM_SYS_PLL1_100M			50
+#define	IMX8MM_SYS_PLL1_133M			51
+#define	IMX8MM_SYS_PLL1_160M			52
+#define	IMX8MM_SYS_PLL1_200M			53
+#define	IMX8MM_SYS_PLL1_266M			54
+#define	IMX8MM_SYS_PLL1_400M			55
+#define	IMX8MM_SYS_PLL1_800M			56
+#define	IMX8MM_SYS_PLL2_50M			57
+#define	IMX8MM_SYS_PLL2_100M			58
+#define	IMX8MM_SYS_PLL2_125M			59
+#define	IMX8MM_SYS_PLL2_166M			60
+#define	IMX8MM_SYS_PLL2_200M			61
+#define	IMX8MM_SYS_PLL2_250M			62
+#define	IMX8MM_SYS_PLL2_333M			63
+#define	IMX8MM_SYS_PLL2_500M			64
+#define	IMX8MM_SYS_PLL2_1000M			65
+
+/* core */
+#define	IMX8MM_CLK_A53_SRC			66
+#define	IMX8MM_CLK_M4_SRC			67
+#define	IMX8MM_CLK_VPU_SRC			68
+#define	IMX8MM_CLK_GPU3D_SRC			69
+#define	IMX8MM_CLK_GPU2D_SRC			70
+#define	IMX8MM_CLK_A53_CG			71
+#define	IMX8MM_CLK_M4_CG			72
+#define	IMX8MM_CLK_VPU_CG			73
+#define	IMX8MM_CLK_GPU3D_CG			74
+#define	IMX8MM_CLK_GPU2D_CG			75
+#define	IMX8MM_CLK_A53_DIV			76
+#define	IMX8MM_CLK_M4_DIV			77
+#define	IMX8MM_CLK_VPU_DIV			78
+#define	IMX8MM_CLK_GPU3D_DIV			79
+#define	IMX8MM_CLK_GPU2D_DIV			80
+
+/* bus */
+#define	IMX8MM_CLK_MAIN_AXI			81
+#define	IMX8MM_CLK_ENET_AXI			82
+#define	IMX8MM_CLK_NAND_USDHC_BUS		83
+#define	IMX8MM_CLK_VPU_BUS			84
+#define	IMX8MM_CLK_DISP_AXI			85
+#define	IMX8MM_CLK_DISP_APB			86
+#define	IMX8MM_CLK_DISP_RTRM			87
+#define	IMX8MM_CLK_USB_BUS			88
+#define	IMX8MM_CLK_GPU_AXI			89
+#define	IMX8MM_CLK_GPU_AHB			90
+#define	IMX8MM_CLK_NOC				91
+#define	IMX8MM_CLK_NOC_APB			92
+
+#define	IMX8MM_CLK_AHB				93
+#define	IMX8MM_CLK_AUDIO_AHB			94
+#define IMX8MM_CLK_IPG_ROOT			95
+#define IMX8MM_CLK_IPG_AUDIO_ROOT		96
+
+#define	IMX8MM_CLK_DRAM_ALT			97
+#define	IMX8MM_CLK_DRAM_APB			98
+#define	IMX8MM_CLK_VPU_G1			99
+#define	IMX8MM_CLK_VPU_G2			100
+#define	IMX8MM_CLK_DISP_DTRC			101
+#define	IMX8MM_CLK_DISP_DC8000			102
+#define	IMX8MM_CLK_PCIE1_CTRL			103
+#define	IMX8MM_CLK_PCIE1_PHY			104
+#define	IMX8MM_CLK_PCIE1_AUX			105
+#define	IMX8MM_CLK_DC_PIXEL			106
+#define	IMX8MM_CLK_LCDIF_PIXEL			107
+#define	IMX8MM_CLK_SAI1				108
+#define	IMX8MM_CLK_SAI2				109
+#define	IMX8MM_CLK_SAI3				110
+#define	IMX8MM_CLK_SAI4				111
+#define	IMX8MM_CLK_SAI5				112
+#define	IMX8MM_CLK_SAI6				113
+#define	IMX8MM_CLK_SPDIF1			114
+#define	IMX8MM_CLK_SPDIF2			115
+#define	IMX8MM_CLK_ENET_REF			116
+#define	IMX8MM_CLK_ENET_TIMER			117
+#define	IMX8MM_CLK_ENET_PHY_REF			118
+#define	IMX8MM_CLK_NAND				119
+#define	IMX8MM_CLK_QSPI				120
+#define	IMX8MM_CLK_USDHC1			121
+#define	IMX8MM_CLK_USDHC2			122
+#define	IMX8MM_CLK_I2C1				123
+#define	IMX8MM_CLK_I2C2				124
+#define	IMX8MM_CLK_I2C3				125
+#define	IMX8MM_CLK_I2C4				126
+#define	IMX8MM_CLK_UART1			127
+#define	IMX8MM_CLK_UART2			128
+#define	IMX8MM_CLK_UART3			129
+#define	IMX8MM_CLK_UART4			130
+#define	IMX8MM_CLK_USB_CORE_REF			131
+#define	IMX8MM_CLK_USB_PHY_REF			132
+#define	IMX8MM_CLK_ECSPI1			133
+#define	IMX8MM_CLK_ECSPI2			134
+#define	IMX8MM_CLK_PWM1				135
+#define	IMX8MM_CLK_PWM2				136
+#define	IMX8MM_CLK_PWM3				137
+#define	IMX8MM_CLK_PWM4				138
+#define	IMX8MM_CLK_GPT1				139
+#define	IMX8MM_CLK_WDOG				140
+#define	IMX8MM_CLK_WRCLK			141
+#define	IMX8MM_CLK_DSI_CORE			142
+#define	IMX8MM_CLK_DSI_PHY_REF			143
+#define	IMX8MM_CLK_DSI_DBI			144
+#define	IMX8MM_CLK_USDHC3			145
+#define	IMX8MM_CLK_CSI1_CORE			146
+#define	IMX8MM_CLK_CSI1_PHY_REF			147
+#define	IMX8MM_CLK_CSI1_ESC			148
+#define	IMX8MM_CLK_CSI2_CORE			149
+#define	IMX8MM_CLK_CSI2_PHY_REF			150
+#define	IMX8MM_CLK_CSI2_ESC			151
+#define	IMX8MM_CLK_PCIE2_CTRL			152
+#define	IMX8MM_CLK_PCIE2_PHY			153
+#define	IMX8MM_CLK_PCIE2_AUX			154
+#define	IMX8MM_CLK_ECSPI3			155
+#define	IMX8MM_CLK_PDM				156
+#define	IMX8MM_CLK_VPU_H1			157
+#define	IMX8MM_CLK_CLKO1			158
+
+#define	IMX8MM_CLK_ECSPI1_ROOT			159
+#define	IMX8MM_CLK_ECSPI2_ROOT			160
+#define	IMX8MM_CLK_ECSPI3_ROOT			161
+#define	IMX8MM_CLK_ENET1_ROOT			162
+#define	IMX8MM_CLK_GPT1_ROOT			163
+#define	IMX8MM_CLK_I2C1_ROOT			164
+#define	IMX8MM_CLK_I2C2_ROOT			165
+#define	IMX8MM_CLK_I2C3_ROOT			166
+#define	IMX8MM_CLK_I2C4_ROOT			167
+#define	IMX8MM_CLK_OCOTP_ROOT			168
+#define	IMX8MM_CLK_PCIE1_ROOT			169
+#define	IMX8MM_CLK_PWM1_ROOT			170
+#define	IMX8MM_CLK_PWM2_ROOT			171
+#define	IMX8MM_CLK_PWM3_ROOT			172
+#define	IMX8MM_CLK_PWM4_ROOT			173
+#define	IMX8MM_CLK_QSPI_ROOT			174
+#define	IMX8MM_CLK_NAND_ROOT			175
+#define	IMX8MM_CLK_SAI1_ROOT			176
+#define	IMX8MM_CLK_SAI1_IPG			177
+#define	IMX8MM_CLK_SAI2_ROOT			178
+#define	IMX8MM_CLK_SAI2_IPG			179
+#define	IMX8MM_CLK_SAI3_ROOT			180
+#define	IMX8MM_CLK_SAI3_IPG			181
+#define	IMX8MM_CLK_SAI4_ROOT			182
+#define	IMX8MM_CLK_SAI4_IPG			183
+#define	IMX8MM_CLK_SAI5_ROOT			184
+#define	IMX8MM_CLK_SAI5_IPG			185
+#define	IMX8MM_CLK_SAI6_ROOT			186
+#define	IMX8MM_CLK_SAI6_IPG			187
+#define	IMX8MM_CLK_UART1_ROOT			188
+#define	IMX8MM_CLK_UART2_ROOT			189
+#define	IMX8MM_CLK_UART3_ROOT			190
+#define	IMX8MM_CLK_UART4_ROOT			191
+#define	IMX8MM_CLK_USB1_CTRL_ROOT		192
+#define	IMX8MM_CLK_GPU3D_ROOT			193
+#define	IMX8MM_CLK_USDHC1_ROOT			194
+#define	IMX8MM_CLK_USDHC2_ROOT			195
+#define	IMX8MM_CLK_WDOG1_ROOT			196
+#define	IMX8MM_CLK_WDOG2_ROOT			197
+#define	IMX8MM_CLK_WDOG3_ROOT			198
+#define	IMX8MM_CLK_VPU_G1_ROOT			199
+#define	IMX8MM_CLK_GPU_BUS_ROOT			200
+#define	IMX8MM_CLK_VPU_H1_ROOT			201
+#define	IMX8MM_CLK_VPU_G2_ROOT			202
+#define	IMX8MM_CLK_PDM_ROOT			203
+#define	IMX8MM_CLK_DISP_ROOT			204
+#define	IMX8MM_CLK_DISP_AXI_ROOT		205
+#define	IMX8MM_CLK_DISP_APB_ROOT		206
+#define	IMX8MM_CLK_DISP_RTRM_ROOT		207
+#define	IMX8MM_CLK_USDHC3_ROOT			208
+#define	IMX8MM_CLK_TMU_ROOT			209
+#define	IMX8MM_CLK_VPU_DEC_ROOT			210
+#define	IMX8MM_CLK_SDMA1_ROOT			211
+#define	IMX8MM_CLK_SDMA2_ROOT			212
+#define	IMX8MM_CLK_SDMA3_ROOT			213
+#define	IMX8MM_CLK_GPT_3M			214
+#define	IMX8MM_CLK_ARM				215
+#define	IMX8MM_CLK_PDM_IPG			216
+#define	IMX8MM_CLK_GPU2D_ROOT			217
+#define	IMX8MM_CLK_MU_ROOT			218
+#define	IMX8MM_CLK_CSI1_ROOT			219
+
+#define IMX8MM_CLK_DRAM_CORE			220
+#define IMX8MM_CLK_DRAM_ALT_ROOT		221
+
+#define IMX8MM_CLK_NAND_USDHC_BUS_RAWNAND_CLK	222
+
+#define	IMX8MM_CLK_END				223
+
+#endif
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH 3/3 clk: imx: Add clock driver support for imx8mm

In reply to Jacky Bai

Add clock driver support for i.MX8MM SOC.

---
 drivers/clk/imx/Kconfig      |   6 +
 drivers/clk/imx/Makefile     |   1 +
 drivers/clk/imx/clk-imx8mm.c | 686 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 693 insertions(+)
 create mode 100644 drivers/clk/imx/clk-imx8mm.c
drivers/clk/imx/Kconfig +6 -0
index 4aae31a..0eaf418 100644
@@ -8,6 +8,12 @@ config MXC_CLK_SCU
 	bool
 	depends on IMX_SCU
 
+config CLK_IMX8MM
+	bool "IMX8MM CCM Clock Driver"
+	depends on ARCH_MXC && ARM64
+	help
+	    Build the driver for i.MX8MM CCM Clock Driver
+
 config CLK_IMX8MQ
 	bool "IMX8MQ CCM Clock Driver"
 	depends on ARCH_MXC && ARM64
drivers/clk/imx/Makefile +1 -0
index ff74287..0d5180f 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_MXC_CLK_SCU) += \
 	clk-scu.o \
 	clk-lpcg-scu.o
 
+obj-$(CONFIG_CLK_IMX8MM) += clk-imx8mm.o
 obj-$(CONFIG_CLK_IMX8MQ) += clk-imx8mq.o
 obj-$(CONFIG_CLK_IMX8QXP) += clk-imx8qxp.o clk-imx8qxp-lpcg.o
 
drivers/clk/imx/clk-imx8mm.c new file +686 -0

686 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#6 lore raw

Re: [PATCH 3/3] clk: imx: Add clock driver support for imx8mm

Quoting Jacky Bai (2019-01-08 01:01:04)

drivers/clk/imx/clk-imx8mm.c line 380

Quoted 7 lines
drivers/clk/imx/clk-imx8mm.c new file +7 -0
+
+static int imx8mm_clocks_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       void __iomem *base;
+       int ret = 0;

Please don't assign ret here. Just let it be assigned later on.

drivers/clk/imx/clk-imx8mm.c line 393

Quoted 13 lines
drivers/clk/imx/clk-imx8mm.c new file +13 -0
+
+       clks[IMX8MM_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
+       clks[IMX8MM_CLK_24M] = of_clk_get_by_name(np, "osc_24m");
+       clks[IMX8MM_CLK_32K] = of_clk_get_by_name(np, "osc_32k"); /* Check more */
+       clks[IMX8MM_CLK_EXT1] = of_clk_get_by_name(np, "clk_ext1");
+       clks[IMX8MM_CLK_EXT2] = of_clk_get_by_name(np, "clk_ext2");
+       clks[IMX8MM_CLK_EXT3] = of_clk_get_by_name(np, "clk_ext3");
+       clks[IMX8MM_CLK_EXT4] = of_clk_get_by_name(np, "clk_ext4");
+
+       np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
+       base = of_iomap(np, 0);
+       if (WARN_ON(!base))
+               return -ENOMEM;

Why do we need to reach into some other node to get the memory region to map?

Quoted 5 lines
drivers/clk/imx/clk-imx8mm.c new file +5 -0
+
+       clks[IMX8MM_AUDIO_PLL1_REF_SEL] = imx_clk_mux("audio_pll1_ref_sel", base + 0x0, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MM_AUDIO_PLL2_REF_SEL] = imx_clk_mux("audio_pll2_ref_sel", base + 0x14, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MM_VIDEO_PLL1_REF_SEL] = imx_clk_mux("video_pll1_ref_sel", base + 0x28, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
+       clks[IMX8MM_DRAM_PLL_REF_SEL] = imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

[...]

drivers/clk/imx/clk-imx8mm.c line 477

Quoted 8 lines
drivers/clk/imx/clk-imx8mm.c new file +8 -0
+       clks[IMX8MM_SYS_PLL2_333M] = imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3);
+       clks[IMX8MM_SYS_PLL2_500M] = imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2);
+       clks[IMX8MM_SYS_PLL2_1000M] = imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1);
+
+       np = dev->of_node;
+       base = of_iomap(np, 0);
+       if (WARN_ON(!base))
+               return -ENOMEM;

This can surely use the platform device APIs to map and retrieve memory regions.

Quoted 1 line

+

[...]

Quoted 4 lines
drivers/clk/imx/clk-imx8mm.c new file +4 -0
+
+       imx_check_clocks(clks, ARRAY_SIZE(clks));
+
+       clk_data.clks = clks;

drivers/clk/imx/clk-imx8mm.c line 668

Quoted 10 lines
drivers/clk/imx/clk-imx8mm.c new file +10 -0
+       clk_data.clk_num = ARRAY_SIZE(clks);
+       ret = of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
+       if (ret < 0) {
+               dev_err(dev, "failed to register clks for i.MX8MM\n");
+               return -EINVAL;
+       }
+
+       imx_register_uart_clocks(uart_clks);
+
+       pr_info("i.MX8MM clock driver init done\n");

Please no "I"m alive" messages.

Quoted 4 lines
drivers/clk/imx/clk-imx8mm.c new file +4 -0
+
+       return 0;
+}
+
author
#7 lore raw

RE: [PATCH 3/3] clk: imx: Add clock driver support for imx8mm

Quoted 12 lines

Subject: Re: [PATCH 3/3] clk: imx: Add clock driver support for imx8mm

Quoting Jacky Bai (2019-01-08 01:01:04)

drivers/clk/imx/clk-imx8mm.c line 380

Quoted 6 lines
drivers/clk/imx/clk-imx8mm.c new file +6 -0
+
+static int imx8mm_clocks_probe(struct platform_device *pdev) {
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       void __iomem *base;
+       int ret = 0;

Please don't assign ret here. Just let it be assigned later on.

Sure.

Quoted 11 lines

drivers/clk/imx/clk-imx8mm.c

Quoted 4 lines
drivers/clk/imx/clk-imx8mm.c new file +4 -0
+
+       clks[IMX8MM_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
+       clks[IMX8MM_CLK_24M] = of_clk_get_by_name(np, "osc_24m");
+       clks[IMX8MM_CLK_32K] = of_clk_get_by_name(np, "osc_32k");

/* Check more */

drivers/clk/imx/clk-imx8mm.c

Quoted 6 lines
drivers/clk/imx/clk-imx8mm.c new file +6 -0
+       clks[IMX8MM_CLK_EXT1] = of_clk_get_by_name(np, "clk_ext1");
+       clks[IMX8MM_CLK_EXT2] = of_clk_get_by_name(np, "clk_ext2");
+       clks[IMX8MM_CLK_EXT3] = of_clk_get_by_name(np, "clk_ext3");
+       clks[IMX8MM_CLK_EXT4] = of_clk_get_by_name(np, "clk_ext4");
+
+       np = of_find_compatible_node(NULL, NULL,
Quoted 8 lines

"fsl,imx8mm-anatop");

drivers/clk/imx/clk-imx8mm.c line 393

Quoted 3 lines
drivers/clk/imx/clk-imx8mm.c new file +3 -0
+       base = of_iomap(np, 0);
+       if (WARN_ON(!base))
+               return -ENOMEM;

Why do we need to reach into some other node to get the memory region to map?

The PLLs' config register is in a sperate memory region. As we registered all the PLLs clocks in this driver, the PLLs memory region Need to be read out from its corresponding node. This is the method that we used on our all i.MX platform.

Quoted 26 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       clks[IMX8MM_AUDIO_PLL1_REF_SEL] =

imx_clk_mux("audio_pll1_ref_sel", base + 0x0, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

Quoted 1 line

+ clks[IMX8MM_AUDIO_PLL2_REF_SEL] =

imx_clk_mux("audio_pll2_ref_sel", base + 0x14, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

Quoted 1 line

+ clks[IMX8MM_VIDEO_PLL1_REF_SEL] =

imx_clk_mux("video_pll1_ref_sel", base + 0x28, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));

Quoted 3 lines

+ clks[IMX8MM_DRAM_PLL_REF_SEL] =
+ imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2, pll_ref_sels,
+ ARRAY_SIZE(pll_ref_sels));

[...]

Quoted 1 line

+ clks[IMX8MM_SYS_PLL2_333M] =

imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3);

Quoted 1 line

+ clks[IMX8MM_SYS_PLL2_500M] =

imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2);

drivers/clk/imx/clk-imx8mm.c line 477

Quoted 7 lines
drivers/clk/imx/clk-imx8mm.c new file +7 -0
+       clks[IMX8MM_SYS_PLL2_1000M] =
+ imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1);
+
+       np = dev->of_node;
+       base = of_iomap(np, 0);
+       if (WARN_ON(!base))
+               return -ENOMEM;
Quoted 3 lines

This can surely use the platform device APIs to map and retrieve memory regions.

Ok, will fix it

Quoted 18 lines
Quoted 1 line

+

[...]

Quoted 4 lines
drivers/clk/imx/clk-imx8mm.c new file +4 -0
+
+       imx_check_clocks(clks, ARRAY_SIZE(clks));
+
+       clk_data.clks = clks;

drivers/clk/imx/clk-imx8mm.c line 668

Quoted 10 lines
drivers/clk/imx/clk-imx8mm.c new file +10 -0
+       clk_data.clk_num = ARRAY_SIZE(clks);
+       ret = of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
+       if (ret < 0) {
+               dev_err(dev, "failed to register clks for i.MX8MM\n");
+               return -EINVAL;
+       }
+
+       imx_register_uart_clocks(uart_clks);
+
+       pr_info("i.MX8MM clock driver init done\n");

Please no "I"m alive" messages.

I will remove it in V2.

BR

Quoted 5 lines
Quoted 5 lines
drivers/clk/imx/clk-imx8mm.c new file +4 -0
+
+       return 0;
+}
+
maintainer
#8 lore raw
In reply to Jacky Bai

Quoting Jacky Bai (2019-01-08 01:00:45)

Quoted 47 lines
drivers/clk/imx/clk-pll14xx.c new file +41 -0
new file mode 100644
index 0000000..c9f83fd
@@ -0,0 +1,409 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2017-2018 NXP.
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+
+#include "clk.h"
+
+#define GNRL_CTL       0x0
+#define DIV_CTL                0x4
+#define LOCK_STATUS    BIT(31)
+#define LOCK_SEL_MASK  BIT(29)
+#define CLKE_MASK      BIT(11)
+#define RST_MASK       BIT(9)
+#define BYPASS_MASK    BIT(4)
+#define MDIV_SHIFT     12
+#define MDIV_MASK      GENMASK(21, 12)
+#define PDIV_SHIFT     4
+#define PDIV_MASK      GENMASK(9, 4)
+#define SDIV_SHIFT     0
+#define SDIV_MASK      GENMASK(2, 0)
+#define KDIV_SHIFT     0
+#define KDIV_MASK      GENMASK(15, 0)
+
+struct clk_pll14xx {
+       struct clk_hw                   hw;
+       void __iomem                    *base;
+       enum imx_pll14xx_type           type;
+       struct imx_pll14xx_rate_table   *rate_table;
+       int rate_count;
+};
+
+#define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw)
+

drivers/clk/imx/clk-pll14xx.c line 51

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+static const struct imx_pll14xx_rate_table *imx_get_pll_settings(
+               struct clk_pll14xx *pll, unsigned long rate)
+{
+       const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
+       int i;
+
+       for (i = 0; i < pll->rate_count; i++) {
+               if (rate == rate_table[i].rate)
+                       return &rate_table[i];
+       }

Nitpick: Drop the brackets.

Quoted 27 lines
drivers/clk/imx/clk-pll14xx.c new file +27 -0
+
+       return NULL;
+}
+
+static long clk_pll14xx_round_rate(struct clk_hw *hw, unsigned long rate,
+                       unsigned long *prate)
+{
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
+       int i;
+
+       /* Assumming rate_table is in descending order */
+       for (i = 0; i < pll->rate_count; i++) {
+               if (rate >= rate_table[i].rate)
+                       return rate_table[i].rate;
+       }
+       /* return minimum supported value */
+       return rate_table[i - 1].rate;
+}
+
+static unsigned long clk_pll1416x_recalc_rate(struct clk_hw *hw,
+                                                 unsigned long parent_rate)
+{
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       u32 mdiv, pdiv, sdiv, pll_gnrl, pll_div;
+       u64 fvco = parent_rate;
+

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

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+       pll_gnrl = readl_relaxed(pll->base);
+       pll_div = readl_relaxed(pll->base + 4);
+       mdiv = (pll_div & MDIV_MASK) >> MDIV_SHIFT;
+       pdiv = (pll_div & PDIV_MASK) >> PDIV_SHIFT;
+       sdiv = (pll_div & SDIV_MASK) >> SDIV_SHIFT;
+
+       fvco *= mdiv;
+       do_div(fvco, pdiv << sdiv);
+
+       return (unsigned long)fvco;

Nitpick: Drop the cast.

Quoted 15 lines
drivers/clk/imx/clk-pll14xx.c new file +15 -0
+}
+
+static unsigned long clk_pll1443x_recalc_rate(struct clk_hw *hw,
+                                                 unsigned long parent_rate)
+{
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       u32 mdiv, pdiv, sdiv, pll_gnrl, pll_div_ctl0, pll_div_ctl1;
+       short int kdiv;
+       u64 fvco = parent_rate;
+
+       pll_gnrl = readl_relaxed(pll->base);
+       pll_div_ctl0 = readl_relaxed(pll->base + 4);
+       pll_div_ctl1 = readl_relaxed(pll->base + 8);
+       mdiv = (pll_div_ctl0 & MDIV_MASK) >> MDIV_SHIFT;
+       pdiv = (pll_div_ctl0 & PDIV_MASK) >> PDIV_SHIFT;

drivers/clk/imx/clk-pll14xx.c line 113

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+       sdiv = (pll_div_ctl0 & SDIV_MASK) >> SDIV_SHIFT;
+       kdiv = pll_div_ctl1 & KDIV_MASK;
+
+       /* fvco = (m * 65536 + k) * Fin / (p * 65536) */
+       fvco *= (mdiv * 65536 + kdiv);
+       pdiv *= 65536;
+
+       do_div(fvco, pdiv << sdiv);
+
+       return (unsigned long)fvco;

Nitpick: Drop the cast.

Quoted 27 lines
drivers/clk/imx/clk-pll14xx.c new file +27 -0
+}
+
+static inline bool clk_pll1416x_mp_change(const struct imx_pll14xx_rate_table *rate,
+                                         u32 pll_div)
+{
+       u32 old_mdiv, old_pdiv;
+
+       old_mdiv = (pll_div >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div >> PDIV_SHIFT) & PDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv);
+}
+
+static inline bool clk_pll1443x_mpk_change(const struct imx_pll14xx_rate_table *rate,
+                                         u32 pll_div_ctl0, u32 pll_div_ctl1)
+{
+       u32 old_mdiv, old_pdiv, old_kdiv;
+
+       old_mdiv = (pll_div_ctl0 >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div_ctl0 >> PDIV_SHIFT) & PDIV_MASK;
+       old_kdiv = (pll_div_ctl1 >> KDIV_SHIFT) & KDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv ||
+               rate->kdiv != old_kdiv);
+}
+
+static inline bool clk_pll1443x_mp_change(const struct imx_pll14xx_rate_table *rate,

drivers/clk/imx/clk-pll14xx.c line 150

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+                                         u32 pll_div_ctl0, u32 pll_div_ctl1)
+{
+       u32 old_mdiv, old_pdiv, old_kdiv;
+
+       old_mdiv = (pll_div_ctl0 >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div_ctl0 >> PDIV_SHIFT) & PDIV_MASK;
+       old_kdiv = (pll_div_ctl1 >> KDIV_SHIFT) & KDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv ||
+               rate->kdiv != old_kdiv);

Nitpick: Please drop the parenthesis on all the returns above.

Quoted 5 lines
drivers/clk/imx/clk-pll14xx.c new file +5 -0
+}
+
+static int clk_pll14xx_wait_lock(struct clk_pll14xx *pll)
+{
+       unsigned long timeout = jiffies + msecs_to_jiffies(10);

drivers/clk/imx/clk-pll14xx.c line 165

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+
+       /* Wait for PLL to lock */
+       do {
+               if (readl_relaxed(pll->base) & LOCK_STATUS)
+                       break;
+               if (time_after(jiffies, timeout))
+                       break;
+       } while (1);
+
+       return readl_relaxed(pll->base) & LOCK_STATUS ? 0 : -ETIMEDOUT;

Is this readl_poll_timeout()?

Quoted 2 lines
drivers/clk/imx/clk-pll14xx.c new file +2 -0
+}
+

[...]

Quoted 17 lines
drivers/clk/imx/clk-pll14xx.c new file +17 -0
+
+struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
+                           void __iomem *base,
+                           const struct imx_pll14xx_clk *pll_clk)
+{
+       struct clk_pll14xx *pll;
+       struct clk *clk;
+       struct clk_init_data init;
+       int len;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       init.name = name;
+       init.flags = pll_clk->flags;
+       init.parent_names = &parent_name;

drivers/clk/imx/clk-pll14xx.c line 377

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+       init.num_parents = 1;
+
+       if (pll_clk->rate_table) {
+               for (len = 0; pll_clk->rate_table[len].rate != 0; )
+                       len++;
+
+               pll->rate_count = len;
+               pll->rate_table = kmemdup(pll_clk->rate_table,
+                                         pll->rate_count *
+                                         sizeof(struct imx_pll14xx_rate_table),

Is this struct_size()?

drivers/clk/imx/clk-pll14xx.c line 379

Quoted 2 lines
drivers/clk/imx/clk-pll14xx.c new file +2 -0
+                                         GFP_KERNEL);
+               WARN(!pll->rate_table, "%s : could not alloc rate table\n", __func__);

Allocations will fail with a loud message indicating as such, so this WARN is not necessary.

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+       }
+
+       switch (pll_clk->type) {
+       case PLL_1416X:
+               if (!pll->rate_table)
+                       init.ops = &clk_pll1416x_min_ops;
+               else
+                       init.ops = &clk_pll1416x_ops;
+               break;
+       case PLL_1443X:
author
#9 lore raw
Quoted 53 lines

Subject: Re: [PATCH 1/3] clk: imx: Add PLLs driver for imx8mm soc

Quoting Jacky Bai (2019-01-08 01:00:45)

Quoted 50 lines
(quoted diff) +0 -0

b/drivers/clk/imx/clk-pll14xx.c new file mode 100644 index 0000000..c9f83fd

drivers/clk/imx/clk-pll14xx.c new file +44 -0
@@ -0,0 +1,409 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2017-2018 NXP.
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+
+#include "clk.h"
+
+#define GNRL_CTL       0x0
+#define DIV_CTL                0x4
+#define LOCK_STATUS    BIT(31)
+#define LOCK_SEL_MASK  BIT(29)
+#define CLKE_MASK      BIT(11)
+#define RST_MASK       BIT(9)
+#define BYPASS_MASK    BIT(4)
+#define MDIV_SHIFT     12
+#define MDIV_MASK      GENMASK(21, 12)
+#define PDIV_SHIFT     4
+#define PDIV_MASK      GENMASK(9, 4)
+#define SDIV_SHIFT     0
+#define SDIV_MASK      GENMASK(2, 0)
+#define KDIV_SHIFT     0
+#define KDIV_MASK      GENMASK(15, 0)
+
+struct clk_pll14xx {
+       struct clk_hw                   hw;
+       void __iomem                    *base;
+       enum imx_pll14xx_type           type;
+       struct imx_pll14xx_rate_table   *rate_table;
+       int rate_count;
+};
+
+#define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw)
+
+static const struct imx_pll14xx_rate_table *imx_get_pll_settings(
+               struct clk_pll14xx *pll, unsigned long rate) {
+       const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
Quoted 9 lines

drivers/clk/imx/clk-pll14xx.c line 51

Quoted 6 lines
drivers/clk/imx/clk-pll14xx.c new file +6 -0
+       int i;
+
+       for (i = 0; i < pll->rate_count; i++) {
+               if (rate == rate_table[i].rate)
+                       return &rate_table[i];
+       }

Nitpick: Drop the brackets.

Thanks, will fix it in V2.

Quoted 29 lines
Quoted 29 lines
drivers/clk/imx/clk-pll14xx.c new file +29 -0
+
+       return NULL;
+}
+
+static long clk_pll14xx_round_rate(struct clk_hw *hw, unsigned long rate,
+                       unsigned long *prate) {
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
+       int i;
+
+       /* Assumming rate_table is in descending order */
+       for (i = 0; i < pll->rate_count; i++) {
+               if (rate >= rate_table[i].rate)
+                       return rate_table[i].rate;
+       }
+       /* return minimum supported value */
+       return rate_table[i - 1].rate; }
+
+static unsigned long clk_pll1416x_recalc_rate(struct clk_hw *hw,
+                                                 unsigned long
+parent_rate) {
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       u32 mdiv, pdiv, sdiv, pll_gnrl, pll_div;
+       u64 fvco = parent_rate;
+
+       pll_gnrl = readl_relaxed(pll->base);
+       pll_div = readl_relaxed(pll->base + 4);
+       mdiv = (pll_div & MDIV_MASK) >> MDIV_SHIFT;
+       pdiv = (pll_div & PDIV_MASK) >> PDIV_SHIFT;
Quoted 9 lines

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

Quoted 6 lines
drivers/clk/imx/clk-pll14xx.c new file +6 -0
+       sdiv = (pll_div & SDIV_MASK) >> SDIV_SHIFT;
+
+       fvco *= mdiv;
+       do_div(fvco, pdiv << sdiv);
+
+       return (unsigned long)fvco;

Nitpick: Drop the cast.

Thanks, will fix it in V2.

Quoted 19 lines
Quoted 19 lines
drivers/clk/imx/clk-pll14xx.c new file +19 -0
+}
+
+static unsigned long clk_pll1443x_recalc_rate(struct clk_hw *hw,
+                                                 unsigned long
+parent_rate) {
+       struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+       u32 mdiv, pdiv, sdiv, pll_gnrl, pll_div_ctl0, pll_div_ctl1;
+       short int kdiv;
+       u64 fvco = parent_rate;
+
+       pll_gnrl = readl_relaxed(pll->base);
+       pll_div_ctl0 = readl_relaxed(pll->base + 4);
+       pll_div_ctl1 = readl_relaxed(pll->base + 8);
+       mdiv = (pll_div_ctl0 & MDIV_MASK) >> MDIV_SHIFT;
+       pdiv = (pll_div_ctl0 & PDIV_MASK) >> PDIV_SHIFT;
+       sdiv = (pll_div_ctl0 & SDIV_MASK) >> SDIV_SHIFT;
+       kdiv = pll_div_ctl1 & KDIV_MASK;
+
+       /* fvco = (m * 65536 + k) * Fin / (p * 65536) */
Quoted 9 lines

drivers/clk/imx/clk-pll14xx.c line 113

Quoted 6 lines
drivers/clk/imx/clk-pll14xx.c new file +6 -0
+       fvco *= (mdiv * 65536 + kdiv);
+       pdiv *= 65536;
+
+       do_div(fvco, pdiv << sdiv);
+
+       return (unsigned long)fvco;

Nitpick: Drop the cast.

Will fix in V2.

Quoted 27 lines

drivers/clk/imx/clk-pll14xx.c

Quoted 3 lines
drivers/clk/imx/clk-pll14xx.c new file +3 -0
+}
+
+static inline bool clk_pll1416x_mp_change(const struct

imx_pll14xx_rate_table *rate,

drivers/clk/imx/clk-pll14xx.c

Quoted 9 lines
drivers/clk/imx/clk-pll14xx.c new file +9 -0
+                                         u32 pll_div) {
+       u32 old_mdiv, old_pdiv;
+
+       old_mdiv = (pll_div >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div >> PDIV_SHIFT) & PDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv); }
+
+static inline bool clk_pll1443x_mpk_change(const struct

imx_pll14xx_rate_table *rate,

drivers/clk/imx/clk-pll14xx.c

Quoted 12 lines
drivers/clk/imx/clk-pll14xx.c new file +12 -0
+                                         u32 pll_div_ctl0, u32
+pll_div_ctl1) {
+       u32 old_mdiv, old_pdiv, old_kdiv;
+
+       old_mdiv = (pll_div_ctl0 >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div_ctl0 >> PDIV_SHIFT) & PDIV_MASK;
+       old_kdiv = (pll_div_ctl1 >> KDIV_SHIFT) & KDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv ||
+               rate->kdiv != old_kdiv); }
+
+static inline bool clk_pll1443x_mp_change(const struct

imx_pll14xx_rate_table *rate,

Quoted 13 lines

drivers/clk/imx/clk-pll14xx.c line 137

Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+                                         u32 pll_div_ctl0, u32
+pll_div_ctl1) {
+       u32 old_mdiv, old_pdiv, old_kdiv;
+
+       old_mdiv = (pll_div_ctl0 >> MDIV_SHIFT) & MDIV_MASK;
+       old_pdiv = (pll_div_ctl0 >> PDIV_SHIFT) & PDIV_MASK;
+       old_kdiv = (pll_div_ctl1 >> KDIV_SHIFT) & KDIV_MASK;
+
+       return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv ||
+               rate->kdiv != old_kdiv);

Nitpick: Please drop the parenthesis on all the returns above.

Will fix in V2.

Quoted 9 lines
Quoted 9 lines
drivers/clk/imx/clk-pll14xx.c new file +9 -0
+}
+
+static int clk_pll14xx_wait_lock(struct clk_pll14xx *pll) {
+       unsigned long timeout = jiffies + msecs_to_jiffies(10);
+
+       /* Wait for PLL to lock */
+       do {
+               if (readl_relaxed(pll->base) & LOCK_STATUS)
+                       break;
Quoted 9 lines

drivers/clk/imx/clk-pll14xx.c

Quoted 6 lines
drivers/clk/imx/clk-pll14xx.c new file +6 -0
+               if (time_after(jiffies, timeout))
+                       break;
+       } while (1);
+
+       return readl_relaxed(pll->base) & LOCK_STATUS ? 0 :
+ -ETIMEDOUT;

Is this readl_poll_timeout()?

Yes, will fix it.

Quoted 24 lines
Quoted 2 lines
drivers/clk/imx/clk-pll14xx.c new file +2 -0
+}
+

[...]

Quoted 21 lines
drivers/clk/imx/clk-pll14xx.c new file +21 -0
+
+struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
+                           void __iomem *base,
+                           const struct imx_pll14xx_clk *pll_clk) {
+       struct clk_pll14xx *pll;
+       struct clk *clk;
+       struct clk_init_data init;
+       int len;
+
+       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       init.name = name;
+       init.flags = pll_clk->flags;
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+
+       if (pll_clk->rate_table) {
+               for (len = 0; pll_clk->rate_table[len].rate != 0; )
+                       len++;
Quoted 8 lines

drivers/clk/imx/clk-pll14xx.c

Quoted 6 lines
drivers/clk/imx/clk-pll14xx.c new file +6 -0
+
+               pll->rate_count = len;
+               pll->rate_table = kmemdup(pll_clk->rate_table,
+                                         pll->rate_count *
+                                         sizeof(struct
+ imx_pll14xx_rate_table),

Is this struct_size()?

Will fix it in V2

Quoted 8 lines

drivers/clk/imx/clk-pll14xx.c

Quoted 4 lines
drivers/clk/imx/clk-pll14xx.c new file +3 -0
+                                         GFP_KERNEL);
+               WARN(!pll->rate_table, "%s : could not alloc rate
+ table\n", __func__);

Allocations will fail with a loud message indicating as such, so this WARN is not necessary.

Will fix in V2

BR

Quoted 10 lines
Quoted 10 lines
drivers/clk/imx/clk-pll14xx.c new file +10 -0
+       }
+
+       switch (pll_clk->type) {
+       case PLL_1416X:
+               if (!pll->rate_table)
+                       init.ops = &clk_pll1416x_min_ops;
+               else
+                       init.ops = &clk_pll1416x_ops;
+               break;
+       case PLL_1443X: