Skip to contentSkip to conversation

stm32mp1: update clock driver

PATCH New Patrick Delaunay 2 participants 16 messages Jan 30, 2019 – Feb 10, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover stm32mp1: update clock driver

This serie udpates the stm32mp1 clock driver with the latest patches and prepare alignment with latest kernel device tree.

This patch is applicable on the top of the serie
"stm32mp1: add trusted boot with TF-A"

http://patchwork.ozlabs.org/project/uboot/list/?series=88521

Patrick Delaunay (7):
clk: stm32mp1: no more get ck_usbo_48m in device tree
clk: stm32mp1: add IPCC clock
clk: stm32mp1: correct access to RCC_OCENSETR/RCC_OCENCLRR
clk: stm32mp1: recalculate counter when switching freq
clk: stm32mp1: add debug information
dts: stm32mp1: clock tree update
clk: stm32mp1: correctly handle Clock Spreading Generator

 arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi       |  27 +++---
 configs/stm32mp15_basic_defconfig              |   1 +
 configs/stm32mp15_trusted_defconfig            |   1 +
 doc/device-tree-bindings/clock/st,stm32mp1.txt |  10 +--
 drivers/clk/clk_stm32mp1.c                     | 120 +++++++++++++++++++++----
 include/dt-bindings/clock/stm32mp1-clks.h      |   3 -
 6 files changed, 124 insertions(+), 38 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/7 clk: stm32mp1: no more get ck_usbo_48m in device tree

Remove support of ck_usbo_48m clock node in device tree, but force 48MHz frequency to prepare alignment with kernel device tree.

---

 drivers/clk/clk_stm32mp1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/clk_stm32mp1.c +3 -3
index 9e9c667..e3ea29a 100644
@@ -243,7 +243,6 @@ enum stm32mp1_parent_id {
 	_LSI,
 	_LSE,
 	_I2S_CKIN,
-	_USB_PHY_48,
 	NB_OSC,
 
 /* other parent source */
@@ -275,6 +274,7 @@ enum stm32mp1_parent_id {
 	_CK_MPU,
 	_CK_MCU,
 	_DSI_PHY,
+	_USB_PHY_48,
 	_PARENT_NB,
 	_UNKNOWN_ID = 0xff,
 };
@@ -1081,7 +1081,7 @@ static ulong stm32mp1_clk_get(struct stm32mp1_clk_priv *priv, int p)
 		break;
 	/* other */
 	case _USB_PHY_48:
-		clock = stm32mp1_clk_get_fixed(priv, _USB_PHY_48);
+		clock = 48000000;
 		break;
 	case _DSI_PHY:
 	{
@@ -1861,7 +1861,7 @@ static void stm32mp1_osc_init(struct udevice *dev)
 		[_HSE] = "clk-hse",
 		[_CSI] = "clk-csi",
 		[_I2S_CKIN] = "i2s_ckin",
-		[_USB_PHY_48] = "ck_usbo_48m"};
+	};
 
 	for (i = 0; i < NB_OSC; i++) {
 		stm32mp1_osc_clk_init(name[i], priv, i);
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/7 clk: stm32mp1: no more get ck_usbo_48m in device tree

Quoted 5 lines · Patrick Delaunay

Remove support of ck_usbo_48m clock node in device tree, but force 48MHz frequency to prepare alignment with kernel device tree.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/a0080e6c/attachment.sig>
#3 lore raw

PATCH 2/7 clk: stm32mp1: add IPCC clock

In reply to Patrick Delaunay

Add support for enable/disable of IPCC clock using AHB3 registers

---

 drivers/clk/clk_stm32mp1.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/clk_stm32mp1.c +1 -0
index e3ea29a..e1477a1 100644
@@ -538,6 +538,7 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
 	STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 16, SDMMC3_K, _SDMMC3_SEL),
 
 	STM32MP1_CLK_SET_CLR(RCC_MP_AHB3ENSETR, 11, HSEM, _UNKNOWN_SEL),
+	STM32MP1_CLK_SET_CLR(RCC_MP_AHB3ENSETR, 12, IPCC, _UNKNOWN_SEL),
 
 	STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 0, GPIOA, _UNKNOWN_SEL),
 	STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 1, GPIOB, _UNKNOWN_SEL),
Signature · 1 line
2.7.4
#4 lore raw

PATCH 2/7 clk: stm32mp1: add IPCC clock

Quoted 3 lines · Patrick Delaunay

Add support for enable/disable of IPCC clock using AHB3 registers

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/f508b3bb/attachment.sig>
#5 lore raw

PATCH 3/7 clk: stm32mp1: correct access to RCC_OCENSETR/RCC_OCENCLRR

In reply to Patrick Delaunay

Remove unnecessary setbits on set/clear registers. Avoid to deactivate HSI with HSE.

---

 drivers/clk/clk_stm32mp1.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/clk/clk_stm32mp1.c +5 -8
index e1477a1..5f2b2f1 100644
@@ -1182,10 +1182,7 @@ static void stm32mp1_ls_osc_set(int enable, fdt_addr_t rcc, u32 offset,
 
 static void stm32mp1_hs_ocs_set(int enable, fdt_addr_t rcc, u32 mask_on)
 {
-	if (enable)
-		setbits_le32(rcc + RCC_OCENSETR, mask_on);
-	else
-		setbits_le32(rcc + RCC_OCENCLRR, mask_on);
+	writel(mask_on, rcc + (enable ? RCC_OCENSETR : RCC_OCENCLRR));
 }
 
 static int stm32mp1_osc_wait(int enable, fdt_addr_t rcc, u32 offset,
@@ -1256,20 +1253,20 @@ static void stm32mp1_lsi_set(fdt_addr_t rcc, int enable)
 static void stm32mp1_hse_enable(fdt_addr_t rcc, int bypass, int digbyp, int css)
 {
 	if (digbyp)
-		setbits_le32(rcc + RCC_OCENSETR, RCC_OCENR_DIGBYP);
+		writel(RCC_OCENR_DIGBYP, rcc + RCC_OCENSETR);
 	if (bypass || digbyp)
-		setbits_le32(rcc + RCC_OCENSETR, RCC_OCENR_HSEBYP);
+		writel(RCC_OCENR_HSEBYP, rcc + RCC_OCENSETR);
 
 	stm32mp1_hs_ocs_set(1, rcc, RCC_OCENR_HSEON);
 	stm32mp1_osc_wait(1, rcc, RCC_OCRDYR, RCC_OCRDYR_HSERDY);
 
 	if (css)
-		setbits_le32(rcc + RCC_OCENSETR, RCC_OCENR_HSECSSON);
+		writel(RCC_OCENR_HSECSSON, rcc + RCC_OCENSETR);
 }
 
 static void stm32mp1_csi_set(fdt_addr_t rcc, int enable)
 {
-	stm32mp1_ls_osc_set(enable, rcc, RCC_OCENSETR, RCC_OCENR_CSION);
+	stm32mp1_hs_ocs_set(enable, rcc, RCC_OCENR_CSION);
 	stm32mp1_osc_wait(enable, rcc, RCC_OCRDYR, RCC_OCRDYR_CSIRDY);
 }
 
Signature · 1 line
2.7.4
#6 lore raw

PATCH 3/7 clk: stm32mp1: correct access to RCC_OCENSETR/RCC_OCENCLRR

Quoted 4 lines · Patrick Delaunay

Remove unnecessary setbits on set/clear registers. Avoid to deactivate HSI with HSE.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/1e4dd7e6/attachment.sig>
#7 lore raw

PATCH 3/7 clk: stm32mp1: correct access to RCC_OCENSETR/RCC_OCENCLRR

In reply to Patrick Delaunay
Quoted 4 lines · Patrick Delaunay

Remove unnecessary setbits on set/clear registers. Avoid to deactivate HSI with HSE.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/cf6c3c41/attachment.sig>
#8 lore raw

PATCH 4/7 clk: stm32mp1: recalculate counter when switching freq

In reply to Patrick Delaunay

Because stgen is initialized with HSI clock, we need to recalculate the counter when changing frequency.

---

 drivers/clk/clk_stm32mp1.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clk/clk_stm32mp1.c +7 -2
index 5f2b2f1..ca98e0b 100644
@@ -1471,10 +1471,15 @@ static void stgen_config(struct stm32mp1_clk_priv *priv)
 	rate = stm32mp1_clk_get(priv, p);
 
 	if (cntfid0 != rate) {
+		u64 counter;
+
 		pr_debug("System Generic Counter (STGEN) update\n");
 		clrbits_le32(stgenc + STGENC_CNTCR, STGENC_CNTCR_EN);
-		writel(0x0, stgenc + STGENC_CNTCVL);
-		writel(0x0, stgenc + STGENC_CNTCVU);
+		counter = (u64)readl(stgenc + STGENC_CNTCVL);
+		counter |= ((u64)(readl(stgenc + STGENC_CNTCVU))) << 32;
+		counter = lldiv(counter * (u64)rate, cntfid0);
+		writel((u32)counter, stgenc + STGENC_CNTCVL);
+		writel((u32)(counter >> 32), stgenc + STGENC_CNTCVU);
 		writel(rate, stgenc + STGENC_CNTFID0);
 		setbits_le32(stgenc + STGENC_CNTCR, STGENC_CNTCR_EN);
 
Signature · 1 line
2.7.4
#9 lore raw

PATCH 4/7 clk: stm32mp1: recalculate counter when switching freq

Quoted 5 lines · Patrick Delaunay

Because stgen is initialized with HSI clock, we need to recalculate the counter when changing frequency.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/ded8d3ea/attachment.sig>
#10 lore raw

PATCH 5/7 clk: stm32mp1: add debug information

In reply to Patrick Delaunay

Add support of clk dump command and
display information during probe (under CONFIG_DISPLAY_CPUINFO).

---

 configs/stm32mp15_basic_defconfig   |  1 +
 configs/stm32mp15_trusted_defconfig |  1 +
 drivers/clk/clk_stm32mp1.c          | 83 +++++++++++++++++++++++++++++++++++--
 3 files changed, 81 insertions(+), 4 deletions(-)
configs/stm32mp15_basic_defconfig +1 -0
index 304688e..d20b2ab 100644
@@ -19,6 +19,7 @@ CONFIG_SYS_PROMPT="STM32MP> "
 # CONFIG_CMD_IMPORTENV is not set
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_ADC=y
+CONFIG_CMD_CLK=y
 CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
configs/stm32mp15_trusted_defconfig +1 -0
index e905ae1..62ab010 100644
@@ -13,6 +13,7 @@ CONFIG_SYS_PROMPT="STM32MP> "
 # CONFIG_CMD_IMPORTENV is not set
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_ADC=y
+CONFIG_CMD_CLK=y
 CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
drivers/clk/clk_stm32mp1.c +79 -4

113 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

PATCH 5/7 clk: stm32mp1: add debug information

Quoted 4 lines · Patrick Delaunay

Add support of clk dump command and
display information during probe (under CONFIG_DISPLAY_CPUINFO).

After dropping the hunk to the "trusted" defconfig, applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/5f64b00e/attachment.sig>
#12 lore raw

PATCH 6/7 dts: stm32mp1: clock tree update

In reply to Patrick Delaunay

- Add st,digbypass on clk_hse node (needed for board rev.C)
- MLAHB/AHB max frequency increased from 200 to 209MHz, with:
- PLL3P set to 208.8MHz for MCU sub-system
- PLL3Q set to 24.57MHz for 48kHz SAI/SPI2S
- PLL3R set to 11.29MHz for 44.1kHz SAI/SPI2S
- PLL4P set to 99MHz for SDMMC and SPDIFRX
- PLL4Q set to 74.25MHz for EVAL board

---

 arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi  | 27 +++++++++++++++------------
 include/dt-bindings/clock/stm32mp1-clks.h |  3 ---
 2 files changed, 15 insertions(+), 15 deletions(-)
arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi +15 -12
index 4898483..70bbf66 100644
@@ -39,6 +39,10 @@
 	};
 };
 
+&clk_hse {
+	st,digbypass;
+};
+
 &uart4_pins_a {
 	u-boot,dm-pre-reloc;
 	pins1 {
@@ -68,7 +72,6 @@
 	u-boot,dm-pre-reloc;
 };
 
-/* CLOCK init */
 &rcc {
 	st,clksrc = <
 		CLK_MPU_PLL1P
@@ -101,7 +104,7 @@
 		CLK_FMC_ACLK
 		CLK_QSPI_ACLK
 		CLK_ETH_DISABLED
-		CLK_SDMMC12_PLL3R
+		CLK_SDMMC12_PLL4P
 		CLK_DSI_DSIPLL
 		CLK_STGEN_HSE
 		CLK_USBPHY_HSE
@@ -110,7 +113,7 @@
 		CLK_SPI45_HSI
 		CLK_SPI6_HSI
 		CLK_I2C46_HSI
-		CLK_SDMMC3_PLL3R
+		CLK_SDMMC3_PLL4P
 		CLK_USBO_USBPHY
 		CLK_ADC_CKPER
 		CLK_CEC_LSE
@@ -121,17 +124,17 @@
 		CLK_UART35_HSI
 		CLK_UART6_HSI
 		CLK_UART78_HSI
-		CLK_SPDIF_PLL3Q
+		CLK_SPDIF_PLL4P
 		CLK_FDCAN_PLL4Q
 		CLK_SAI1_PLL3Q
 		CLK_SAI2_PLL3Q
 		CLK_SAI3_PLL3Q
 		CLK_SAI4_PLL3Q
-		CLK_RNG1_CSI
-		CLK_RNG2_CSI
+		CLK_RNG1_LSI
+		CLK_RNG2_LSI
 		CLK_LPTIM1_PCLK1
 		CLK_LPTIM23_PCLK3
-		CLK_LPTIM45_PCLK3
+		CLK_LPTIM45_LSE
 	>;
 
 	/* VCO = 1300.0 MHz => P = 650 (CPU) */
@@ -148,16 +151,16 @@
 		u-boot,dm-pre-reloc;
 	};
 
-	/* VCO = 786.4 MHz => P = 197, Q = 49, R = 98 */
+	/* VCO = 417.8 MHz => P = 209, Q = 24, R = 11 */
 	pll3: st,pll at 2 {
-		cfg = < 2 97 3 15 7 PQR(1,1,1) >;
-		frac = < 0x9ba >;
+		cfg = < 1 33 1 16 36 PQR(1,1,1) >;
+		frac = < 0x1a04 >;
 		u-boot,dm-pre-reloc;
 	};
 
-	/* VCO = 508.0 MHz => P = 56, Q = 56, R = 56 */
+	/* VCO = 594.0 MHz => P = 99, Q = 74, R = 74 */
 	pll4: st,pll at 3 {
-		cfg = < 5 126 8 8 8 PQR(1,1,1) >;
+		cfg = < 3 98 5 7 7 PQR(1,1,1) >;
 		u-boot,dm-pre-reloc;
 	};
 };
include/dt-bindings/clock/stm32mp1-clks.h +0 -3
index 90ec780..4cdaf13 100644
@@ -248,7 +248,4 @@
 
 #define STM32MP1_LAST_CLK 232
 
-#define LTDC_K		LTDC_PX
-#define ETHMAC_K	ETHCK_K
-
 #endif /* _DT_BINDINGS_STM32MP1_CLKS_H_ */
Signature · 1 line
2.7.4
#13 lore raw

PATCH 6/7 dts: stm32mp1: clock tree update

Quoted 9 lines · Patrick Delaunay

- Add st,digbypass on clk_hse node (needed for board rev.C)
- MLAHB/AHB max frequency increased from 200 to 209MHz, with:
- PLL3P set to 208.8MHz for MCU sub-system
- PLL3Q set to 24.57MHz for 48kHz SAI/SPI2S
- PLL3R set to 11.29MHz for 44.1kHz SAI/SPI2S
- PLL4P set to 99MHz for SDMMC and SPDIFRX
- PLL4Q set to 74.25MHz for EVAL board

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/1d8b3990/attachment.sig>
#14 lore raw

PATCH 7/7 clk: stm32mp1: correctly handle Clock Spreading Generator

In reply to Patrick Delaunay

To activate the csg option, the driver need to set the bit2 of PLLNCR register = SSCG_CTRL: Spread Spectrum Clock Generator of PLLn enable.

---

 doc/device-tree-bindings/clock/st,stm32mp1.txt | 10 +++++-----
 drivers/clk/clk_stm32mp1.c                     |  8 +++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)
doc/device-tree-bindings/clock/st,stm32mp1.txt +5 -5
index 6a9397e..ffcf8cd 100644
@@ -132,15 +132,15 @@ Optional Properties:
 				frac = < 0x810 >;
 			};
 			st,pll at 1 {
-				cfg = < 1 43 1 0 0 PQR(0,1,1)>;
-				csg = <10 20 1>;
+				cfg = < 1 43 1 0 0 PQR(0,1,1) >;
+				csg = < 10 20 1 >;
 			};
 			st,pll at 2 {
-				cfg = < 2 85 3 13 3 0>;
-				csg = <10 20 SSCG_MODE_CENTER_SPREAD>;
+				cfg = < 2 85 3 13 3 0 >;
+				csg = < 10 20 SSCG_MODE_CENTER_SPREAD >;
 			};
 			st,pll at 3 {
-				cfg = < 2 78 4 7 9 3>;
+				cfg = < 2 78 4 7 9 3 >;
 			};
 			st,pkcs = <
 					CLK_STGEN_HSE
drivers/clk/clk_stm32mp1.c +7 -1
index 76b7b5a..24859fd 100644
@@ -167,6 +167,7 @@
 /* used for ALL PLLNCR registers */
 #define RCC_PLLNCR_PLLON	BIT(0)
 #define RCC_PLLNCR_PLLRDY	BIT(1)
+#define RCC_PLLNCR_SSCG_CTRL	BIT(2)
 #define RCC_PLLNCR_DIVPEN	BIT(4)
 #define RCC_PLLNCR_DIVQEN	BIT(5)
 #define RCC_PLLNCR_DIVREN	BIT(6)
@@ -1321,7 +1322,10 @@ static void pll_start(struct stm32mp1_clk_priv *priv, int pll_id)
 {
 	const struct stm32mp1_clk_pll *pll = priv->data->pll;
 
-	writel(RCC_PLLNCR_PLLON, priv->base + pll[pll_id].pllxcr);
+	clrsetbits_le32(priv->base + pll[pll_id].pllxcr,
+			RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN |
+			RCC_PLLNCR_DIVREN,
+			RCC_PLLNCR_PLLON);
 }
 
 static int pll_output(struct stm32mp1_clk_priv *priv, int pll_id, int output)
@@ -1440,6 +1444,8 @@ static void pll_csg(struct stm32mp1_clk_priv *priv, int pll_id, u32 *csg)
 		    RCC_PLLNCSGR_SSCG_MODE_MASK);
 
 	writel(pllxcsg, priv->base + pll[pll_id].pllxcsgr);
+
+	setbits_le32(priv->base + pll[pll_id].pllxcr, RCC_PLLNCR_SSCG_CTRL);
 }
 
 static int set_clksrc(struct stm32mp1_clk_priv *priv, unsigned int clksrc)
Signature · 1 line
2.7.4
#15 lore raw

PATCH 7/7 clk: stm32mp1: correctly handle Clock Spreading Generator

Quoted 5 lines · Patrick Delaunay

To activate the csg option, the driver need to set the bit2 of PLLNCR register = SSCG_CTRL: Spread Spectrum Clock Generator of PLLn enable.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190210/303aeb2b/attachment.sig>