Skip to contentSkip to conversation

ddr: imx8m: implement i.MX8MQ support

PATCH Applied Lucas Stach 3 participants 8 messages Dec 27, 2020 – Jan 6, 2021

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

PATCH 1/5 ddr: imx8m: implement i.MX8MQ support

The i.MX8MQ uses a different PLL type than the later i.MX8M family members, so the PLL setup did not actually work on this SoC. In U-Boot the used PLL setup routine is a compile time decision. As we want our DRAM init code to work for multi-image builds, this passes the SoC type through to the PLL init, so we can use the correct setup routine depending on the SoC we are running on.

---
 drivers/ddr/imx8m/ddr_init.c     |   4 +-
 drivers/ddr/imx8m/ddrphy_train.c |   4 +-
 drivers/ddr/imx8m/ddrphy_utils.c | 107 ++++++++++++++++++++++++++++---
 include/soc/imx8m/ddr.h          |   4 +-
 4 files changed, 104 insertions(+), 15 deletions(-)
drivers/ddr/imx8m/ddr_init.c +2 -2
index 1cd7b7406dc7..34da44af6446 100644
@@ -62,7 +62,7 @@ static int imx8m_ddr_init(struct dram_timing_info *dram_timing,
 
 	initial_drate = dram_timing->fsp_msg[0].drate;
 	/* default to the frequency point 0 clock */
-	ddrphy_init_set_dfi_clk(initial_drate);
+	ddrphy_init_set_dfi_clk(initial_drate, type);
 
 	/* D-aasert the presetn */
 	reg32_write(src_ddrc_rcr, 0x8F000006);
@@ -115,7 +115,7 @@ static int imx8m_ddr_init(struct dram_timing_info *dram_timing,
 	 */
 	pr_debug("ddrphy config start\n");
 
-	ret = ddr_cfg_phy(dram_timing);
+	ret = ddr_cfg_phy(dram_timing, type);
 	if (ret)
 		return ret;
 
drivers/ddr/imx8m/ddrphy_train.c +2 -2
index 9280c853aa1c..a4677f903c6b 100644
@@ -31,7 +31,7 @@ void ddr_load_train_code(enum fw_type type)
 			       DDRC_PHY_DMEM, dmem, dsize);
 }
 
-int ddr_cfg_phy(struct dram_timing_info *dram_timing)
+int ddr_cfg_phy(struct dram_timing_info *dram_timing, enum ddrc_type type)
 {
 	struct dram_cfg_param *dram_cfg;
 	struct dram_fsp_msg *fsp_msg;
@@ -54,7 +54,7 @@ int ddr_cfg_phy(struct dram_timing_info *dram_timing)
 	for (i = 0; i < dram_timing->fsp_msg_num; i++) {
 		pr_debug("DRAM PHY training for %dMTS\n", fsp_msg->drate);
 		/* set dram PHY input clocks to desired frequency */
-		ddrphy_init_set_dfi_clk(fsp_msg->drate);
+		ddrphy_init_set_dfi_clk(fsp_msg->drate, type);
 
 		/* load the dram training firmware image */
 		dwc_ddrphy_apb_wr(0xd0000, 0x0);
drivers/ddr/imx8m/ddrphy_utils.c +98 -9

140 lines not on this page · raw message

include/soc/imx8m/ddr.h +2 -2
index a5a610909212..78b15f1d461a 100644
@@ -372,14 +372,14 @@ enum ddrc_type {
 int imx8mm_ddr_init(struct dram_timing_info *timing_info);
 int imx8mq_ddr_init(struct dram_timing_info *timing_info);
 int imx8mp_ddr_init(struct dram_timing_info *timing_info);
-int ddr_cfg_phy(struct dram_timing_info *timing_info);
+int ddr_cfg_phy(struct dram_timing_info *timing_info, enum ddrc_type type);
 void load_lpddr4_phy_pie(void);
 void ddrphy_trained_csr_save(struct dram_cfg_param *param, unsigned int num);
 void dram_config_save(struct dram_timing_info *info, unsigned long base);
 
 /* utils function for ddr phy training */
 int wait_ddrphy_training_complete(void);
-void ddrphy_init_set_dfi_clk(unsigned int drate);
+void ddrphy_init_set_dfi_clk(unsigned int drate, enum ddrc_type type);
 void ddrphy_init_read_msg_block(enum fw_type type);
 
 void update_umctl2_rank_space_setting(unsigned int pstat_num,
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/5 ddr: imx8m: remove bogus defines

Most of those defines aren't used. Whether DDR_ONE_RANK should be defined is really dependent on the used DRAM on a specific board, so move this from the common header into the board DRAM setup.

---
 arch/arm/boards/nxp-imx8mm-evk/lpddr4-timing.c | 2 ++
 include/soc/imx8m/lpddr4_define.h              | 7 -------
 2 files changed, 2 insertions(+), 7 deletions(-)
arch/arm/boards/nxp-imx8mm-evk/lpddr4-timing.c +2 -0
index 8d6cc389ba9b..e7c01f9cc9a0 100644
@@ -5,6 +5,8 @@
 
 #include <common.h>
 #include <soc/imx8m/ddr.h>
+
+#define DDR_ONE_RANK
 #include <soc/imx8m/lpddr4_define.h>
 
 static struct dram_cfg_param lpddr4_ddrc_cfg[] = {
include/soc/imx8m/lpddr4_define.h +0 -7
index caf5bafb6d02..805357959349 100644
@@ -6,13 +6,6 @@
 #ifndef __LPDDR4_DEFINE_H_
 #define __LPDDR4_DEFINE_H_
 
-#define LPDDR4_DVFS_DBI
-#define DDR_ONE_RANK
-/* #define LPDDR4_DBI_ON */
-#define DFI_BUG_WR
-#define M845S_4GBx2
-#define PRETRAIN
-
 /* DRAM MR setting */
 #ifdef LPDDR4_DBI_ON
 #define LPDDR4_MR3			0xf1
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/5 ARM: i.mx8mq: add PAD CTL defines

In reply to Lucas Stach

Allows a more readable pad setup.

---
 arch/arm/mach-imx/include/mach/iomux-mx8mq.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm/mach-imx/include/mach/iomux-mx8mq.h +17 -0
index d397e975c023..b6efdda4ff4a 100644
@@ -623,6 +623,23 @@ enum {
 	IMX8MQ_PAD_UART4_TXD__GPIO5_IO29			= IOMUX_PAD(0x04B8, 0x0250, 5, 0x0000, 0, 0),
 };
 
+#define MX8MQ_PAD_CTL_DSE_HIZ	(0 << 0)
+#define MX8MQ_PAD_CTL_DSE_255R	(1 << 0)
+#define MX8MQ_PAD_CTL_DSE_155R	(2 << 0)
+#define MX8MQ_PAD_CTL_DSE_75R	(3 << 0)
+#define MX8MQ_PAD_CTL_DSE_85R	(4 << 0)
+#define MX8MQ_PAD_CTL_DSE_65R	(5 << 0)
+#define MX8MQ_PAD_CTL_DSE_45R	(6 << 0)
+#define MX8MQ_PAD_CTL_DSE_40R	(7 << 0)
+#define MX8MQ_PAD_CTL_SR_50M	(0 << 3)
+#define MX8MQ_PAD_CTL_SR_100M	(1 << 3)
+#define MX8MQ_PAD_CTL_SR_150M	(2 << 3)
+#define MX8MQ_PAD_CTL_SR_200M	(3 << 3)
+#define MX8MQ_PAD_CTL_ODE	BIT(5)
+#define MX8MQ_PAD_CTL_PUE	BIT(6)
+#define MX8MQ_PAD_CTL_HYS	BIT(7)
+#define MX8MQ_PAD_CTL_LVTTL	BIT(8)
+
 static inline void imx8mq_setup_pad(iomux_v3_cfg_t pad)
 {
 	void __iomem *iomux = IOMEM(MX8MQ_IOMUXC_BASE_ADDR);
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 4/5 net: phy: at803x: sync RX/TX delay setup with Linux

In reply to Lucas Stach

The RX/TX delay setup was pretty broken in that it only handled one specific delay case. Sync the whole code with with the Linux driver to get correct and consistent behavior.

---
 drivers/net/phy/at803x.c | 88 ++++++++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 12 deletions(-)
drivers/net/phy/at803x.c +76 -12
index 016ed97020ad..e0e147b1913e 100644
@@ -27,8 +27,10 @@
 #define AT803X_FUNC_DATA			0x4003
 #define AT803X_DEBUG_ADDR			0x1D
 #define AT803X_DEBUG_DATA			0x1E
-#define AT803X_DEBUG_SYSTEM_MODE_CTRL		0x05
-#define AT803X_DEBUG_RGMII_TX_CLK_DLY		(1 << 8)
+#define AT803X_DEBUG_REG_0			0x00
+#define AT803X_DEBUG_RX_CLK_DLY_EN		BIT(15)
+#define AT803X_DEBUG_REG_5			0x05
+#define AT803X_DEBUG_TX_CLK_DLY_EN		BIT(8)
 
 /* AT803x supports either the XTAL input pad, an internal PLL or the
  * DSP as clock reference for the clock output pad. The XTAL reference
@@ -74,6 +76,58 @@ struct at803x_priv {
 	u16 clk_25m_mask;
 };
 
+static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
+{
+	int ret;
+
+	ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
+	if (ret < 0)
+		return ret;
+
+	return phy_read(phydev, AT803X_DEBUG_DATA);
+}
+
+static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
+				 u16 clear, u16 set)
+{
+	u16 val;
+	int ret;
+
+	ret = at803x_debug_reg_read(phydev, reg);
+	if (ret < 0)
+		return ret;
+
+	val = ret & 0xffff;
+	val &= ~clear;
+	val |= set;
+
+	return phy_write(phydev, AT803X_DEBUG_DATA, val);
+}
+
+static int at803x_enable_rx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
+				     AT803X_DEBUG_RX_CLK_DLY_EN);
+}
+
+static int at803x_enable_tx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0,
+				     AT803X_DEBUG_TX_CLK_DLY_EN);
+}
+
+static int at803x_disable_rx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
+				     AT803X_DEBUG_RX_CLK_DLY_EN, 0);
+}
+
+static int at803x_disable_tx_delay(struct phy_device *phydev)
+{
+	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
+				     AT803X_DEBUG_TX_CLK_DLY_EN, 0);
+}
+
 static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id)
 {
 	struct phy_driver *drv = to_phy_driver(phydev->dev.driver);
@@ -196,16 +250,26 @@ static int at803x_config_init(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
-	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-		ret = phy_write(phydev, AT803X_DEBUG_ADDR,
-				AT803X_DEBUG_SYSTEM_MODE_CTRL);
-		if (ret)
-			return ret;
-		ret = phy_write(phydev, AT803X_DEBUG_DATA,
-				AT803X_DEBUG_RGMII_TX_CLK_DLY);
-		if (ret)
-			return ret;
-	}
+	/* The RX and TX delay default is:
+	 *   after HW reset: RX delay enabled and TX delay disabled
+	 *   after SW reset: RX delay enabled, while TX delay retains the
+	 *   value before reset.
+	 */
+	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
+	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
+		ret = at803x_enable_rx_delay(phydev);
+	else
+		ret = at803x_disable_rx_delay(phydev);
+	if (ret < 0)
+		return ret;
+
+	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
+	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
+		ret = at803x_enable_tx_delay(phydev);
+	else
+		ret = at803x_disable_tx_delay(phydev);
+	if (ret < 0)
+		return ret;
 
 	return at803x_clk_out_config(phydev);
 }
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 5/5 ARM: i.MX: add MNT Reform board support

In reply to Lucas Stach

The MNT Reform is a DIY Laptop, built around a Boundarydevices i.MX8MQ SoM. This adds a pretty minimal support, as there is no upstream DT yet. It also does not properly abstract the SoM (power supply init in MNT Reform lowlevel code and only single DRAM configuration supported), as there are a lot of variants of the SoM and I'm only able to test the single one that will be shipped with the Reform.

What has been tested to work:
- SD card
- eMMC
- Gigabit network
- NVMe storage

There is a quirk in the board support: the Nitrogen SoM only allows to configure one of the BOOT_MODE straps, which means the choices for the boot selection are only "boot from fuses", which means eMMC boot and "serial boot". As serial boot isn't really useful on the device (requires USB A<->A cable with VBUS protection), we rely on the BootROM fallback to boot from SD card in this mode. The board support code thus treats the bootsource "serial" as SD card boot.

---
 arch/arm/boards/Makefile                      |    1 +
 arch/arm/boards/mnt-reform/Makefile           |    2 +
 arch/arm/boards/mnt-reform/board.c            |   40 +
 .../mnt-reform/flash-header-mnt-reform.imxcfg |    6 +
 arch/arm/boards/mnt-reform/lowlevel.c         |  187 +++
 arch/arm/boards/mnt-reform/lpddr4-timing.c    | 1012 +++++++++++++++++
 arch/arm/dts/Makefile                         |    1 +
 arch/arm/dts/imx8mq-mnt-reform2.dts           |  223 ++++
 arch/arm/mach-imx/Kconfig                     |    9 +
 images/Makefile.imx                           |    6 +
 10 files changed, 1487 insertions(+)
 create mode 100644 arch/arm/boards/mnt-reform/Makefile
 create mode 100644 arch/arm/boards/mnt-reform/board.c
 create mode 100644 arch/arm/boards/mnt-reform/flash-header-mnt-reform.imxcfg
 create mode 100644 arch/arm/boards/mnt-reform/lowlevel.c
 create mode 100644 arch/arm/boards/mnt-reform/lpddr4-timing.c
 create mode 100644 arch/arm/dts/imx8mq-mnt-reform2.dts
arch/arm/boards/Makefile +1 -0
index 81c228efd614..f8cdd90ed6e6 100644
@@ -178,3 +178,4 @@ obj-$(CONFIG_MACH_ZII_IMX7D_DEV)		+= zii-imx7d-dev/
 obj-$(CONFIG_MACH_WAGO_PFC_AM35XX)		+= wago-pfc-am35xx/
 obj-$(CONFIG_MACH_LS1046ARDB)			+= ls1046ardb/
 obj-$(CONFIG_MACH_TQMLS1046A)			+= tqmls1046a/
+obj-$(CONFIG_MACH_MNT_REFORM)			+= mnt-reform/
arch/arm/boards/mnt-reform/Makefile new file +2 -0
new file mode 100644
index 000000000000..a3da88fbe68f
@@ -0,0 +1,2 @@
+obj-y += board.o
+lwl-y += lowlevel.o lpddr4-timing.o
\ No newline at end of file
arch/arm/boards/mnt-reform/board.c new file +40 -0
new file mode 100644
index 000000000000..e2d628586a50
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Lucas Stach <[email protected]>
+ */
+
+#include <bootsource.h>
+#include <common.h>
+#include <init.h>
+#include <mach/bbu.h>
+
+static int mnt_reform_probe(struct device_d *dev)
+{
+	int emmc_bbu_flag = 0;
+	int sd_bbu_flag = 0;
+
+	if (bootsource_get() == BOOTSOURCE_MMC) {
+		of_device_enable_path("/chosen/environment-emmc");
+		emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+	} else {
+		of_device_enable_path("/chosen/environment-sd");
+		sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+	}
+
+	imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", sd_bbu_flag);
+	imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", emmc_bbu_flag);
+
+	return 0;
+}
+
+static const struct of_device_id mnt_reform_of_match[] = {
+	{ .compatible = "mnt,reform2"},
+	{ /* sentinel */ },
+};
+
+static struct driver_d mnt_reform_board_driver = {
+	.name = "board-mnt-reform",
+	.probe = mnt_reform_probe,
+	.of_compatible = DRV_OF_COMPAT(mnt_reform_of_match),
+};
+device_platform_driver(mnt_reform_board_driver);
arch/arm/boards/mnt-reform/flash-header-mnt-reform.imxcfg new file +6 -0
new file mode 100644
index 000000000000..80ce03e22c3a
@@ -0,0 +1,6 @@
+soc imx8mq
+
+loadaddr 0x007E1000
+max_load_size 0x3F000
+ivtofs 0x400
+#include <mach/habv4-imx8-gencsf.h>
arch/arm/boards/mnt-reform/lowlevel.c new file +187 -0

187 lines not on this page · raw message

arch/arm/boards/mnt-reform/lpddr4-timing.c new file +1012 -0

1,012 lines not on this page · raw message

arch/arm/dts/Makefile +1 -0
index a1e0bb6a4168..63bd73dfaa5d 100644
@@ -169,5 +169,6 @@ lwl-$(CONFIG_MACH_WAGO_PFC_AM35XX) += am35xx-pfc-750_820x.dtb.o
 lwl-$(CONFIG_MACH_LS1046ARDB) += fsl-ls1046a-rdb.dtb.o
 lwl-$(CONFIG_MACH_TQMLS1046A) += fsl-tqmls1046a-mbls10xxa.dtb.o
 lwl-$(CONFIG_MACH_ZEDBOARD) += zynq-zed.dtb.o
+lwl-$(CONFIG_MACH_MNT_REFORM) += imx8mq-mnt-reform2.dtb.o
 
 clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.lzo
arch/arm/dts/imx8mq-mnt-reform2.dts new file +223 -0

223 lines not on this page · raw message

arch/arm/mach-imx/Kconfig +9 -0
index dd49537fd560..3f8012c73211 100644
@@ -583,6 +583,15 @@ config MACH_WEBASTO_CCBV2
 	select ARCH_IMX6UL
 	select ARM_USE_COMPRESSED_DTB
 
+config MACH_MNT_REFORM
+	bool "MNT Reform"
+	select ARCH_IMX8MQ
+	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	select FIRMWARE_IMX8MQ_ATF
+	select ARM_SMCCC
+	select MCI_IMX_ESDHC_PBL
+	select I2C_IMX_EARLY
+
 endif
 
 # ----------------------------------------------------------
images/Makefile.imx +6 -0
index 514db326bb8a..b892ec0196c4 100644
@@ -432,3 +432,9 @@ CFG_start_phytec_phycore_imx8mq.pblb.imximg = $(board)/phytec-som-imx8mq/flash-h
 MAX_PBL_MEMORY_SIZE_start_phytec_phycore_imx8mq = 0x3f000
 FILE_barebox-phytec-phycore-imx8mq.img = start_phytec_phycore_imx8mq.pblb.imximg
 image-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ) += barebox-phytec-phycore-imx8mq.img
+
+pblb-$(CONFIG_MACH_MNT_REFORM) += start_mnt_reform
+CFG_start_mnt_reform.pblb.imximg = $(board)/mnt-reform/flash-header-mnt-reform.imxcfg
+MAX_PBL_MEMORY_SIZE_start_mnt_reform = 0x3f000
+FILE_barebox-mnt-reform.img = start_mnt_reform.pblb.imximg
+image-$(CONFIG_MACH_MNT_REFORM) += barebox-mnt-reform.img
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 5/5] ARM: i.MX: add MNT Reform board support

On Sun, 27 Dec 2020 22:50:42 +0100
Lucas Stach <[email protected]> wrote:

Hi!

I'm very glad to see that barebox runs on MNT Reform!

Are you planning to add MIPI DSI display output?

Quoted 41 lines

The MNT Reform is a DIY Laptop, built around a Boundarydevices i.MX8MQ SoM. This adds a pretty minimal support, as there is no upstream DT yet. It also does not properly abstract the SoM (power supply init in MNT Reform lowlevel code and only single DRAM configuration supported), as there are a lot of variants of the SoM and I'm only able to test the single one that will be shipped with the Reform.

What has been tested to work:
- SD card
- eMMC
- Gigabit network
- NVMe storage

There is a quirk in the board support: the Nitrogen SoM only allows to configure one of the BOOT_MODE straps, which means the choices for the boot selection are only "boot from fuses", which means eMMC boot and "serial boot". As serial boot isn't really useful on the device (requires USB A<->A cable with VBUS protection), we rely on the BootROM fallback to boot from SD card in this mode. The board support code thus treats the bootsource "serial" as SD card boot.

---
 arch/arm/boards/Makefile                      |    1 +
 arch/arm/boards/mnt-reform/Makefile           |    2 +
 arch/arm/boards/mnt-reform/board.c            |   40 +
 .../mnt-reform/flash-header-mnt-reform.imxcfg |    6 +
 arch/arm/boards/mnt-reform/lowlevel.c         |  187 +++
 arch/arm/boards/mnt-reform/lpddr4-timing.c    | 1012 +++++++++++++++++
 arch/arm/dts/Makefile                         |    1 +
 arch/arm/dts/imx8mq-mnt-reform2.dts           |  223 ++++
 arch/arm/mach-imx/Kconfig                     |    9 +
 images/Makefile.imx                           |    6 +
 10 files changed, 1487 insertions(+)
 create mode 100644 arch/arm/boards/mnt-reform/Makefile
 create mode 100644 arch/arm/boards/mnt-reform/board.c
 create mode 100644 arch/arm/boards/mnt-reform/flash-header-mnt-reform.imxcfg
 create mode 100644 arch/arm/boards/mnt-reform/lowlevel.c
 create mode 100644 arch/arm/boards/mnt-reform/lpddr4-timing.c
 create mode 100644 arch/arm/dts/imx8mq-mnt-reform2.dts

...

Quoted 6 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH 5/5] ARM: i.MX: add MNT Reform board support

Hi Antony,

Am Montag, dem 28.12.2020 um 09:48 +0300 schrieb Antony Pavlov:

Quoted 8 lines

On Sun, 27 Dec 2020 22:50:42 +0100
Lucas Stach <[email protected]> wrote:

Hi!

I'm very glad to see that barebox runs on MNT Reform!

Are you planning to add MIPI DSI display output?

Yes, I think I will eventually get around to it. For now the focus is on getting the Linux kernel support into shape for upstream, however. As I needed a convenient way to boot Linux on the device for this task a Barebox port was the logical first step. ;) It may take a while until I circle back to improve the Barebox support.

Quoted 7 lines
Quoted 7 lines

The MNT Reform is a DIY Laptop, built around a Boundarydevices i.MX8MQ SoM. This adds a pretty minimal support, as there is no upstream DT yet. It also does not properly abstract the SoM (power supply init in MNT Reform lowlevel code and only single DRAM configuration supported), as there are a lot of variants of the SoM and I'm only able to test the single one that will be shipped with the Reform.

Quoted 5 lines
Quoted 5 lines

What has been tested to work:
- SD card
- eMMC
- Gigabit network
- NVMe storage

Forgot to mention: USB is also supported.

Regards,
Lucas

Quoted 29 lines
Quoted 22 lines

There is a quirk in the board support: the Nitrogen SoM only allows to configure one of the BOOT_MODE straps, which means the choices for the boot selection are only "boot from fuses", which means eMMC boot and "serial boot". As serial boot isn't really useful on the device (requires USB A<->A cable with VBUS protection), we rely on the BootROM fallback to boot from SD card in this mode. The board support code thus treats the bootsource "serial" as SD card boot.

---

 arch/arm/boards/Makefile                      |    1 +
 arch/arm/boards/mnt-reform/Makefile           |    2 +
 arch/arm/boards/mnt-reform/board.c            |   40 +
 .../mnt-reform/flash-header-mnt-reform.imxcfg |    6 +
 arch/arm/boards/mnt-reform/lowlevel.c         |  187 +++
 arch/arm/boards/mnt-reform/lpddr4-timing.c    | 1012 +++++++++++++++++
 arch/arm/dts/Makefile                         |    1 +
 arch/arm/dts/imx8mq-mnt-reform2.dts           |  223 ++++
 arch/arm/mach-imx/Kconfig                     |    9 +
 images/Makefile.imx                           |    6 +
 10 files changed, 1487 insertions(+)
Quoted 7 lines

 create mode 100644 arch/arm/boards/mnt-reform/Makefile
 create mode 100644 arch/arm/boards/mnt-reform/board.c
 create mode 100644 arch/arm/boards/mnt-reform/flash-header-mnt-reform.imxcfg create mode 100644 arch/arm/boards/mnt-reform/lowlevel.c
 create mode 100644 arch/arm/boards/mnt-reform/lpddr4-timing.c create mode 100644 arch/arm/dts/imx8mq-mnt-reform2.dts

Quoted 8 lines

...

Quoted 6 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Applied
#7 lore raw
In reply to Lucas Stach
Quoted 7 lines · Lucas Stach

The i.MX8MQ uses a different PLL type than the later i.MX8M family members, so the PLL setup did not actually work on this SoC. In U-Boot the used PLL setup routine is a compile time decision. As we want our DRAM init code to work for multi-image builds, this passes the SoC type through to the PLL init, so we can use the correct setup routine depending on the SoC we are running on.

Quoted 7 lines
---
 drivers/ddr/imx8m/ddr_init.c     |   4 +-
 drivers/ddr/imx8m/ddrphy_train.c |   4 +-
 drivers/ddr/imx8m/ddrphy_utils.c | 107 ++++++++++++++++++++++++++++---
 include/soc/imx8m/ddr.h          |   4 +-
 4 files changed, 104 insertions(+), 15 deletions(-)

Applied, thanks

Sascha

Quoted 221 lines
drivers/ddr/imx8m/ddr_init.c +2 -2
index 1cd7b7406dc7..34da44af6446 100644
@@ -62,7 +62,7 @@ static int imx8m_ddr_init(struct dram_timing_info *dram_timing,
 
 	initial_drate = dram_timing->fsp_msg[0].drate;
 	/* default to the frequency point 0 clock */
-	ddrphy_init_set_dfi_clk(initial_drate);
+	ddrphy_init_set_dfi_clk(initial_drate, type);
 
 	/* D-aasert the presetn */
 	reg32_write(src_ddrc_rcr, 0x8F000006);
@@ -115,7 +115,7 @@ static int imx8m_ddr_init(struct dram_timing_info *dram_timing,
 	 */
 	pr_debug("ddrphy config start\n");
 
-	ret = ddr_cfg_phy(dram_timing);
+	ret = ddr_cfg_phy(dram_timing, type);
 	if (ret)
 		return ret;
 
drivers/ddr/imx8m/ddrphy_train.c +2 -2
index 9280c853aa1c..a4677f903c6b 100644
@@ -31,7 +31,7 @@ void ddr_load_train_code(enum fw_type type)
 			       DDRC_PHY_DMEM, dmem, dsize);
 }
 
-int ddr_cfg_phy(struct dram_timing_info *dram_timing)
+int ddr_cfg_phy(struct dram_timing_info *dram_timing, enum ddrc_type type)
 {
 	struct dram_cfg_param *dram_cfg;
 	struct dram_fsp_msg *fsp_msg;
@@ -54,7 +54,7 @@ int ddr_cfg_phy(struct dram_timing_info *dram_timing)
 	for (i = 0; i < dram_timing->fsp_msg_num; i++) {
 		pr_debug("DRAM PHY training for %dMTS\n", fsp_msg->drate);
 		/* set dram PHY input clocks to desired frequency */
-		ddrphy_init_set_dfi_clk(fsp_msg->drate);
+		ddrphy_init_set_dfi_clk(fsp_msg->drate, type);
 
 		/* load the dram training firmware image */
 		dwc_ddrphy_apb_wr(0xd0000, 0x0);
drivers/ddr/imx8m/ddrphy_utils.c +98 -9
index c48372491015..9a4e1a22ee5e 100644
@@ -214,7 +214,7 @@ static struct imx_int_pll_rate_table *fracpll(u32 freq)
 	return NULL;
 }
 
-static int dram_pll_init(u32 freq)
+static int dram_frac_pll_init(u32 freq)
 {
 	volatile int i;
 	u32 tmp;
@@ -261,35 +261,124 @@ static int dram_pll_init(u32 freq)
 	return 0;
 }
 
-void ddrphy_init_set_dfi_clk(unsigned int drate)
+#define SSCG_PLL_LOCK			BIT(31)
+#define SSCG_PLL_DRAM_PLL_CLKE		BIT(9)
+#define SSCG_PLL_PD			BIT(7)
+#define SSCG_PLL_BYPASS1		BIT(5)
+#define SSCG_PLL_BYPASS2		BIT(4)
+
+#define SSCG_PLL_REF_DIVR2_MASK		(0x3f << 19)
+#define SSCG_PLL_REF_DIVR2_VAL(n)	(((n) << 19) & SSCG_PLL_REF_DIVR2_MASK)
+#define SSCG_PLL_FEEDBACK_DIV_F1_MASK	(0x3f << 13)
+#define SSCG_PLL_FEEDBACK_DIV_F1_VAL(n)	(((n) << 13) & SSCG_PLL_FEEDBACK_DIV_F1_MASK)
+#define SSCG_PLL_FEEDBACK_DIV_F2_MASK	(0x3f << 7)
+#define SSCG_PLL_FEEDBACK_DIV_F2_VAL(n)	(((n) << 7) & SSCG_PLL_FEEDBACK_DIV_F2_MASK)
+#define SSCG_PLL_OUTPUT_DIV_VAL_MASK	(0x3f << 1)
+#define SSCG_PLL_OUTPUT_DIV_VAL(n)	(((n) << 1) & SSCG_PLL_OUTPUT_DIV_VAL_MASK)
+
+static int dram_sscg_pll_init(u32 freq)
+{
+	u32 val;
+	void __iomem *pll_base = IOMEM(MX8M_ANATOP_BASE_ADDR) + 0x60;
+
+	/* Bypass */
+	setbits_le32(pll_base, SSCG_PLL_BYPASS1 | SSCG_PLL_BYPASS2);
+
+	val = readl(pll_base + 0x8);
+	val &= ~(SSCG_PLL_OUTPUT_DIV_VAL_MASK |
+		 SSCG_PLL_FEEDBACK_DIV_F2_MASK |
+		 SSCG_PLL_FEEDBACK_DIV_F1_MASK |
+		 SSCG_PLL_REF_DIVR2_MASK);
+
+	switch (freq) {
+	case MHZ(800):
+		val |= SSCG_PLL_OUTPUT_DIV_VAL(0);
+		val |= SSCG_PLL_FEEDBACK_DIV_F2_VAL(11);
+		val |= SSCG_PLL_FEEDBACK_DIV_F1_VAL(39);
+		val |= SSCG_PLL_REF_DIVR2_VAL(29);
+		break;
+	case MHZ(600):
+		val |= SSCG_PLL_OUTPUT_DIV_VAL(1);
+		val |= SSCG_PLL_FEEDBACK_DIV_F2_VAL(17);
+		val |= SSCG_PLL_FEEDBACK_DIV_F1_VAL(39);
+		val |= SSCG_PLL_REF_DIVR2_VAL(29);
+		break;
+	case MHZ(400):
+		val |= SSCG_PLL_OUTPUT_DIV_VAL(1);
+		val |= SSCG_PLL_FEEDBACK_DIV_F2_VAL(11);
+		val |= SSCG_PLL_FEEDBACK_DIV_F1_VAL(39);
+		val |= SSCG_PLL_REF_DIVR2_VAL(29);
+		break;
+	case MHZ(167):
+		val |= SSCG_PLL_OUTPUT_DIV_VAL(3);
+		val |= SSCG_PLL_FEEDBACK_DIV_F2_VAL(8);
+		val |= SSCG_PLL_FEEDBACK_DIV_F1_VAL(45);
+		val |= SSCG_PLL_REF_DIVR2_VAL(30);
+		break;
+	default:
+		break;
+	}
+
+	writel(val, pll_base + 0x8);
+
+	/* Clear power down bit */
+	clrbits_le32(pll_base, SSCG_PLL_PD);
+	/* Enable PLL  */
+	setbits_le32(pll_base, SSCG_PLL_DRAM_PLL_CLKE);
+
+	/* Clear bypass */
+	clrbits_le32(pll_base, SSCG_PLL_BYPASS1);
+	udelay(100);
+	clrbits_le32(pll_base, SSCG_PLL_BYPASS2);
+	/* Wait lock */
+	while (!(readl(pll_base) & SSCG_PLL_LOCK))
+		;
+
+	return 0;
+}
+
+static int dram_pll_init(u32 freq, enum ddrc_type type)
+{
+	switch (type) {
+	case DDRC_TYPE_MQ:
+		return dram_sscg_pll_init(freq);
+	case DDRC_TYPE_MM:
+	case DDRC_TYPE_MP:
+		return dram_frac_pll_init(freq);
+	default:
+		return -ENODEV;
+	}
+}
+
+void ddrphy_init_set_dfi_clk(unsigned int drate, enum ddrc_type type)
 {
 	switch (drate) {
 	case 4000:
-		dram_pll_init(MHZ(1000));
+		dram_pll_init(MHZ(1000), type);
 		dram_disable_bypass();
 		break;
 	case 3200:
-		dram_pll_init(MHZ(800));
+		dram_pll_init(MHZ(800), type);
 		dram_disable_bypass();
 		break;
 	case 3000:
-		dram_pll_init(MHZ(750));
+		dram_pll_init(MHZ(750), type);
 		dram_disable_bypass();
 		break;
 	case 2400:
-		dram_pll_init(MHZ(600));
+		dram_pll_init(MHZ(600), type);
 		dram_disable_bypass();
 		break;
 	case 1600:
-		dram_pll_init(MHZ(400));
+		dram_pll_init(MHZ(400), type);
 		dram_disable_bypass();
 		break;
 	case 1066:
-		dram_pll_init(MHZ(266));
+		dram_pll_init(MHZ(266),type);
 		dram_disable_bypass();
 		break;
 	case 667:
-		dram_pll_init(MHZ(167));
+		dram_pll_init(MHZ(167), type);
 		dram_disable_bypass();
 		break;
 	case 400:
include/soc/imx8m/ddr.h +2 -2
index a5a610909212..78b15f1d461a 100644
@@ -372,14 +372,14 @@ enum ddrc_type {
 int imx8mm_ddr_init(struct dram_timing_info *timing_info);
 int imx8mq_ddr_init(struct dram_timing_info *timing_info);
 int imx8mp_ddr_init(struct dram_timing_info *timing_info);
-int ddr_cfg_phy(struct dram_timing_info *timing_info);
+int ddr_cfg_phy(struct dram_timing_info *timing_info, enum ddrc_type type);
 void load_lpddr4_phy_pie(void);
 void ddrphy_trained_csr_save(struct dram_cfg_param *param, unsigned int num);
 void dram_config_save(struct dram_timing_info *info, unsigned long base);
 
 /* utils function for ddr phy training */
 int wait_ddrphy_training_complete(void);
-void ddrphy_init_set_dfi_clk(unsigned int drate);
+void ddrphy_init_set_dfi_clk(unsigned int drate, enum ddrc_type type);
 void ddrphy_init_read_msg_block(enum fw_type type);
 
 void update_umctl2_rank_space_setting(unsigned int pstat_num,
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox