Skip to contentSkip to conversation

add some imx8m power and clock control

PATCH Superseded Angus Ainslie 3 participants 9 messages Dec 17, 2021 – Dec 18, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover add some imx8m power and clock control

Enable some imx8m subsystems used when booting the librem5 phone

Angus Ainslie (3):
imx8m: clock_imx8mq: Add the ecspi clocks
arch: imx8m: imx-regs.h add the USB regs
arch: imx8m: Add USB power control

 arch/arm/include/asm/arch-imx8m/imx-regs.h  | 14 +++++
 arch/arm/include/asm/arch-imx8m/sys_proto.h |  1 +
 arch/arm/mach-imx/imx8m/clock_imx8mq.c      | 38 ++++++++++++++
 arch/arm/mach-imx/imx8m/soc.c               | 57 +++++++++++++++++++++
 4 files changed, 110 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 imx8m: clock_imx8mq: Add the ecspi clocks

Enable the clocks for spi buses 1 through 3

---
 arch/arm/include/asm/arch-imx8m/imx-regs.h |  9 +++++
 arch/arm/mach-imx/imx8m/clock_imx8mq.c     | 38 ++++++++++++++++++++++
 2 files changed, 47 insertions(+)
arch/arm/include/asm/arch-imx8m/imx-regs.h +9 -0
index b800da13a1..8cb499d3a3 100644
@@ -94,6 +94,15 @@
 #define SRC_DDR1_RCR_CORE_RESET_N_MASK	BIT(1)
 #define SRC_DDR1_RCR_PRESET_N_MASK	BIT(0)
 
+#define IMX_CSPI1_BASE		0x30820000
+#define IMX_CSPI2_BASE		0x30830000
+#define IMX_CSPI3_BASE		0x30840000
+
+#define MXC_SPI_BASE_ADDRESSES \
+	IMX_CSPI1_BASE, \
+	IMX_CSPI2_BASE, \
+	IMX_CSPI3_BASE
+
 struct iomuxc_gpr_base_regs {
 	u32 gpr[47];
 };
arch/arm/mach-imx/imx8m/clock_imx8mq.c +38 -0
index 60e2218a3c..834a7bfa01 100644
@@ -505,6 +505,31 @@ int set_clk_qspi(void)
 	return 0;
 }
 
+int set_clk_ecspi(int sel)
+{
+	int clk = ECSPI1_CLK_ROOT;
+
+	switch (sel) {
+	case 1:
+		clk = ECSPI1_CLK_ROOT;
+		break;
+	case 2:
+		clk = ECSPI2_CLK_ROOT;
+		break;
+	case 3:
+		clk = ECSPI3_CLK_ROOT;
+		break;
+	}
+
+	clock_enable(clk, 0);
+	/*
+	 * TODO: configure clock
+	 */
+	clock_enable(clk, 1);
+
+	return 0;
+}
+
 #ifdef CONFIG_FEC_MXC
 int set_clk_enet(enum enet_freq type)
 {
@@ -772,6 +797,19 @@ int clock_init(void)
 	clock_enable(CCGR_TSENSOR, 1);
 	clock_enable(CCGR_OCOTP, 1);
 
+	/*
+	 * set ecspi roots
+	 */
+	clock_enable(CCGR_ECSPI1, 0);
+	clock_enable(CCGR_ECSPI2, 0);
+	clock_enable(CCGR_ECSPI3, 0);
+	clock_set_target_val(ECSPI1_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(0));
+	clock_set_target_val(ECSPI2_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(0));
+	clock_set_target_val(ECSPI3_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(0));
+	clock_enable(CCGR_ECSPI1, 1);
+	clock_enable(CCGR_ECSPI2, 1);
+	clock_enable(CCGR_ECSPI3, 1);
+
 	/* config GIC ROOT to sys_pll2_200m */
 	clock_enable(CCGR_GIC, 0);
 	clock_set_target_val(GIC_CLK_ROOT,
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/3 arch: imx8m: imx-regs.h add the USB regs

In reply to Angus Ainslie

Add the USB regs for SDP mode

---
 arch/arm/include/asm/arch-imx8m/imx-regs.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/include/asm/arch-imx8m/imx-regs.h +5 -0
index 8cb499d3a3..bd474f88a6 100644
@@ -103,6 +103,11 @@
 	IMX_CSPI2_BASE, \
 	IMX_CSPI3_BASE
 
+#define USB1_BASE_ADDR		0x38100000
+#define USB2_BASE_ADDR		0x38200000
+#define USB1_PHY_BASE_ADDR	0x381F0000
+#define USB2_PHY_BASE_ADDR	0x382F0000
+
 struct iomuxc_gpr_base_regs {
 	u32 gpr[47];
 };
Signature · 1 line
2.25.1
reviewer
#3 lore raw

Re: [PATCH 2/3] arch: imx8m: imx-regs.h add the USB regs

Hi Angus,

Quoted 13 lines · Angus Ainslie

Add the USB regs for SDP mode

---
 arch/arm/include/asm/arch-imx8m/imx-regs.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/include/asm/arch-imx8m/imx-regs.h +0 -0
index 8cb499d3a3..bd474f88a6 100644

arch/arm/include/asm/arch-imx8m/imx-regs.h line 109

Quoted 7 lines
arch/arm/include/asm/arch-imx8m/imx-regs.h +4 -0
@@ -103,6 +103,11 @@
        IMX_CSPI2_BASE, \
        IMX_CSPI3_BASE
 
+#define USB1_BASE_ADDR         0x38100000
+#define USB2_BASE_ADDR         0x38200000
+#define USB1_PHY_BASE_ADDR     0x381F0000
+#define USB2_PHY_BASE_ADDR     0x382F0000

Some time ago I sent a similar patch and the feedback from Marek was that these base addresses should be retrieved from the devicetree instead.

#4 lore raw

Re: [PATCH 2/3] arch: imx8m: imx-regs.h add the USB regs

Hi Fabio,

Quoted 19 lines · Fabio Estevam

Hi Angus,

Quoted 16 lines · Angus Ainslie

Add the USB regs for SDP mode

---
 arch/arm/include/asm/arch-imx8m/imx-regs.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/include/asm/arch-imx8m/imx-regs.h +0 -0
index 8cb499d3a3..bd474f88a6 100644
@@ -103,6 +103,11 @@
        IMX_CSPI2_BASE, \
        IMX_CSPI3_BASE
 
Quoted 7 lines

arch/arm/include/asm/arch-imx8m/imx-regs.h line 109

Quoted 4 lines
arch/arm/include/asm/arch-imx8m/imx-regs.h +4 -0
+#define USB1_BASE_ADDR         0x38100000
+#define USB2_BASE_ADDR         0x38200000
+#define USB1_PHY_BASE_ADDR     0x381F0000
+#define USB2_PHY_BASE_ADDR     0x382F0000

Some time ago I sent a similar patch and the feedback from Marek was that these base addresses should be retrieved from the devicetree instead.

I had problems getting the dwc3 to initialize properly when using the device model in the SPL. I'm currently just using this in the SPL and the device model in u-boot.

I'll take another shot at initializing the dwc3 in the SPL with the DM.

Thanks
Angus

#5 lore raw

Re: [PATCH 2/3] arch: imx8m: imx-regs.h add the USB regs

Quoted 32 lines · Angus Ainslie

Hi Fabio,

Quoted 28 lines · Fabio Estevam

Hi Angus,

Quoted 14 lines · Angus Ainslie

Add the USB regs for SDP mode

---
 arch/arm/include/asm/arch-imx8m/imx-regs.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/include/asm/arch-imx8m/imx-regs.h +0 -0
index 8cb499d3a3..bd474f88a6 100644

arch/arm/include/asm/arch-imx8m/imx-regs.h line 109

Quoted 7 lines
arch/arm/include/asm/arch-imx8m/imx-regs.h +4 -0
@@ -103,6 +103,11 @@
        IMX_CSPI2_BASE, \
        IMX_CSPI3_BASE
 
+#define USB1_BASE_ADDR         0x38100000
+#define USB2_BASE_ADDR         0x38200000
+#define USB1_PHY_BASE_ADDR     0x381F0000
+#define USB2_PHY_BASE_ADDR     0x382F0000

Some time ago I sent a similar patch and the feedback from Marek was that these
base addresses should be retrieved from the devicetree instead.

I didn't think Driver model was a requirement for SPL.

Quoted 6 lines

I had problems getting the dwc3 to initialize properly when using the device model in the SPL. I'm currently just using this in the SPL and the device model in u-boot.

I'll take another shot at initializing the dwc3 in the SPL with the DM.

Could we compromise by putting the #define statements in an ifdef to only enable them when SPL is being built?

Quoted 3 lines

Thanks
Angus

reviewer
#6 lore raw

Re: [PATCH 2/3] arch: imx8m: imx-regs.h add the USB regs

Quoted 1 line · Adam Ford

I didn't think Driver model was a requirement for SPL.

That's my understanding as well.

Quoted 8 lines
Quoted 5 lines

I had problems getting the dwc3 to initialize properly when using the device model in the SPL. I'm currently just using this in the SPL and the device model in u-boot.

I'll take another shot at initializing the dwc3 in the SPL with the DM.

Could we compromise by putting the #define statements in an ifdef to only enable them when SPL is being built?

This looks like a a good idea.

#7 lore raw

Re: [PATCH 2/3] arch: imx8m: imx-regs.h add the USB regs

Quoted 10 lines · Fabio Estevam
Quoted 1 line · Adam Ford

I didn't think Driver model was a requirement for SPL.

That's my understanding as well.

Quoted 4 lines
Quoted 4 lines

I had problems getting the dwc3 to initialize properly when using the device model in the SPL. I'm currently just using this in the SPL and the device model in u-boot.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I'll take another shot at initializing the dwc3 in the SPL with the DM.

Could we compromise by putting the #define statements in an ifdef to only enable them when SPL is being built?

This looks like a a good idea.

Thanks Fabian and Adam, I'll rework with the CONFIG_SPL_BUILD guards in place.

Angus

#8 lore raw

PATCH 3/3 arch: imx8m: Add USB power control

In reply to Angus Ainslie

Enable turning on USB power for SDP mode

---
 arch/arm/include/asm/arch-imx8m/sys_proto.h |  1 +
 arch/arm/mach-imx/imx8m/soc.c               | 57 +++++++++++++++++++++
 2 files changed, 58 insertions(+)
arch/arm/include/asm/arch-imx8m/sys_proto.h +1 -0
index d328542ece..98a958166a 100644
@@ -14,4 +14,5 @@ void restore_boot_params(void);
 extern unsigned long rom_pointer[];
 enum boot_device get_boot_device(void);
 bool is_usb_boot(void);
+int imx8m_usb_power(int usb_id, bool on);
 #endif
arch/arm/mach-imx/imx8m/soc.c +57 -0

63 lines not on this page · raw message

Signature · 1 line
2.25.1