mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support
@ 2022-02-21 10:36 Ahmad Fatoum
  2022-02-21 10:36 ` [PATCH 2/2] ARM: stm32mp: add board support for STM32MP135F-DK Ahmad Fatoum
  2022-02-23 11:29 ` [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-02-21 10:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Full buswidth for STM32MP131 means 2 byte wide, not 4 as the memory bus
is restricted to 16-bit. Teach barebox the difference.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-stm32mp/ddrctrl.c               | 26 ++++++++++++++-----
 arch/arm/mach-stm32mp/include/mach/revision.h |  8 ++++++
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-stm32mp/ddrctrl.c b/arch/arm/mach-stm32mp/ddrctrl.c
index 93996d0afc79..7f0944d7e77c 100644
--- a/arch/arm/mach-stm32mp/ddrctrl.c
+++ b/arch/arm/mach-stm32mp/ddrctrl.c
@@ -9,6 +9,7 @@
 #include <mach/ddr_regs.h>
 #include <mach/entry.h>
 #include <mach/stm32.h>
+#include <mach/revision.h>
 #include <asm/barebox-arm.h>
 #include <asm/memory.h>
 #include <pbl.h>
@@ -62,7 +63,8 @@ enum ddrctrl_buswidth {
 };
 
 static unsigned long ddrctrl_addrmap_ramsize(struct stm32mp1_ddrctl __iomem *d,
-					     enum ddrctrl_buswidth buswidth)
+					     enum ddrctrl_buswidth buswidth,
+					     unsigned nb_bytes)
 {
 	unsigned banks = 3, cols = 12, rows = 16;
 	u32 reg;
@@ -99,21 +101,26 @@ static unsigned long ddrctrl_addrmap_ramsize(struct stm32mp1_ddrctl __iomem *d,
 	if (LINE_UNUSED(reg, ADDRMAP6_ROW_B13)) rows--;
 	if (LINE_UNUSED(reg, ADDRMAP6_ROW_B12)) rows--;
 
-	return memory_sdram_size(cols, rows, BIT(banks), 4 / BIT(buswidth));
+	return memory_sdram_size(cols, rows, BIT(banks), nb_bytes / BIT(buswidth));
 }
 
-static inline unsigned ddrctrl_ramsize(void __iomem *base)
+static inline unsigned ddrctrl_ramsize(void __iomem *base, unsigned nb_bytes)
 {
 	struct stm32mp1_ddrctl __iomem *ddrctl = base;
 	unsigned buswidth = readl(&ddrctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK;
 	buswidth >>= DDRCTRL_MSTR_DATA_BUS_WIDTH_SHIFT;
 
-	return ddrctrl_addrmap_ramsize(ddrctl, buswidth);
+	return ddrctrl_addrmap_ramsize(ddrctl, buswidth, nb_bytes);
 }
 
 static inline unsigned stm32mp1_ddrctrl_ramsize(void)
 {
-	return ddrctrl_ramsize(IOMEM(STM32_DDRCTL_BASE));
+	u32 nb_bytes = 4;
+
+	if (cpu_stm32_is_stm32mp13())
+		nb_bytes /= 2;
+
+	return ddrctrl_ramsize(IOMEM(STM32_DDRCTL_BASE), nb_bytes);
 }
 
 void __noreturn stm32mp1_barebox_entry(void *boarddata)
@@ -126,17 +133,22 @@ static int stm32mp1_ddr_probe(struct device_d *dev)
 {
 	struct resource *iores;
 	void __iomem *base;
+	unsigned long nb_bytes;
 
 	iores = dev_request_mem_resource(dev, 0);
 	if (IS_ERR(iores))
 		return PTR_ERR(iores);
 	base = IOMEM(iores->start);
 
-	return arm_add_mem_device("ram0", STM32_DDR_BASE, ddrctrl_ramsize(base));
+	nb_bytes = (unsigned long)device_get_match_data(dev);
+
+	return arm_add_mem_device("ram0", STM32_DDR_BASE,
+				  ddrctrl_ramsize(base, nb_bytes));
 }
 
 static __maybe_unused struct of_device_id stm32mp1_ddr_dt_ids[] = {
-	{ .compatible = "st,stm32mp1-ddr" },
+	{ .compatible = "st,stm32mp1-ddr", .data = (void *)4 },
+	{ .compatible = "st,stm32mp13-ddr", .data = (void *)2 },
 	{ /* sentinel */ }
 };
 
diff --git a/arch/arm/mach-stm32mp/include/mach/revision.h b/arch/arm/mach-stm32mp/include/mach/revision.h
index 2ef8ef30c3ae..c141b925a156 100644
--- a/arch/arm/mach-stm32mp/include/mach/revision.h
+++ b/arch/arm/mach-stm32mp/include/mach/revision.h
@@ -32,6 +32,14 @@
 #define CPU_STM32MP151Fxx	0x050000AE
 #define CPU_STM32MP151Dxx	0x050000AF
 
+#define cpu_stm32_is(mask, val) ({ \
+	u32 type; \
+	__stm32mp_get_cpu_type(&type) == 0 ? (type & mask) == val : 0; \
+})
+
+#define cpu_stm32_is_stm32mp15() cpu_stm32_is(0xFFFF0000, 0x05000000)
+#define cpu_stm32_is_stm32mp13() cpu_stm32_is(0xFFFF0000, 0x05010000)
+
 /* silicon revisions */
 #define CPU_REV_A	0x1000
 #define CPU_REV_B	0x2000
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ARM: stm32mp: add board support for STM32MP135F-DK
  2022-02-21 10:36 [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Ahmad Fatoum
@ 2022-02-21 10:36 ` Ahmad Fatoum
  2022-02-23 11:29 ` [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-02-21 10:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already have the needed drivers in place to support the upcoming
STM32MP131. Linux already has a basic DT for the DK board. Add a barebox
board that leverages it. To try it out modify the existing FIP with:

  fiptool update --nt-fw build/images/barebox-stm32mp-generic-bl33.img \
                 --hw-config build/arch/arm/dts/stm32mp135f-dk.dtb \
		 mmcblk0p3

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Documentation/boards/stm32mp.rst          |  1 +
 arch/arm/boards/Makefile                  |  1 +
 arch/arm/boards/stm32mp13xx-dk/Makefile   |  2 ++
 arch/arm/boards/stm32mp13xx-dk/lowlevel.c | 19 +++++++++++++++++++
 arch/arm/dts/Makefile                     |  1 +
 arch/arm/dts/stm32mp131.dtsi              | 14 ++++++++++++++
 arch/arm/dts/stm32mp135f-dk.dts           | 12 ++++++++++++
 arch/arm/mach-stm32mp/Kconfig             |  8 ++++++++
 images/Makefile.stm32mp                   |  1 +
 9 files changed, 59 insertions(+)
 create mode 100644 arch/arm/boards/stm32mp13xx-dk/Makefile
 create mode 100644 arch/arm/boards/stm32mp13xx-dk/lowlevel.c
 create mode 100644 arch/arm/dts/stm32mp131.dtsi
 create mode 100644 arch/arm/dts/stm32mp135f-dk.dts

diff --git a/Documentation/boards/stm32mp.rst b/Documentation/boards/stm32mp.rst
index 55bdafe78579..6f4b14049ad4 100644
--- a/Documentation/boards/stm32mp.rst
+++ b/Documentation/boards/stm32mp.rst
@@ -33,6 +33,7 @@ There's a single ``stm32mp_defconfig`` for all STM32MP boards::
 The resulting images will be placed under ``images/``::
 
   barebox-stm32mp-generic-bl33.img
+  barebox-stm32mp13xx-dk.stm32
   barebox-stm32mp15xx-dkx.stm32
   barebox-stm32mp15x-ev1.stm32
   barebox-stm32mp157c-lxa-mc1.stm32
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index a15963c775ce..8557e1dca8c6 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -139,6 +139,7 @@ obj-$(CONFIG_MACH_SOCFPGA_TERASIC_SOCKIT)	+= terasic-sockit/
 obj-$(CONFIG_MACH_SOLIDRUN_CUBOX)		+= solidrun-cubox/
 obj-$(CONFIG_MACH_SOLIDRUN_MICROSOM)		+= solidrun-microsom/
 obj-$(CONFIG_MACH_STM32MP15XX_DKX)		+= stm32mp15xx-dkx/
+obj-$(CONFIG_MACH_STM32MP13XX_DK)		+= stm32mp13xx-dk/
 obj-$(CONFIG_MACH_LXA_MC1)			+= lxa-mc1/
 obj-$(CONFIG_MACH_STM32MP15X_EV1)		+= stm32mp15x-ev1/
 obj-$(CONFIG_MACH_TECHNEXION_PICO_HOBBIT)	+= technexion-pico-hobbit/
diff --git a/arch/arm/boards/stm32mp13xx-dk/Makefile b/arch/arm/boards/stm32mp13xx-dk/Makefile
new file mode 100644
index 000000000000..9961af02a3ea
--- /dev/null
+++ b/arch/arm/boards/stm32mp13xx-dk/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/stm32mp13xx-dk/lowlevel.c b/arch/arm/boards/stm32mp13xx-dk/lowlevel.c
new file mode 100644
index 000000000000..ac4fa40e1960
--- /dev/null
+++ b/arch/arm/boards/stm32mp13xx-dk/lowlevel.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <mach/entry.h>
+#include <debug_ll.h>
+
+extern char __dtb_z_stm32mp135f_dk_start[];
+
+ENTRY_FUNCTION(start_stm32mp13xx_dk, r0, r1, r2)
+{
+	void *fdt;
+
+	stm32mp_cpu_lowlevel_init();
+
+	putc_ll('>');
+
+	fdt = __dtb_z_stm32mp135f_dk_start  + get_runtime_offset();
+
+	stm32mp1_barebox_entry(fdt);
+}
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d419e8394d53..e0bb66580f38 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -127,6 +127,7 @@ lwl-$(CONFIG_MACH_SKOV_IMX6) += imx6s-skov-imx6.dtb.o imx6dl-skov-imx6.dtb.o imx
 lwl-$(CONFIG_MACH_SKOV_ARM9CPU) += at91-skov-arm9cpu.dtb.o
 lwl-$(CONFIG_MACH_SEEED_ODYSSEY) += stm32mp157c-odyssey.dtb.o
 lwl-$(CONFIG_MACH_STM32MP15XX_DKX) += stm32mp157c-dk2.dtb.o stm32mp157a-dk1.dtb.o
+lwl-$(CONFIG_MACH_STM32MP13XX_DK) += stm32mp135f-dk.dtb.o
 lwl-$(CONFIG_MACH_LXA_MC1) += stm32mp157c-lxa-mc1.dtb.o
 lwl-$(CONFIG_MACH_STM32MP15X_EV1) += stm32mp157c-ev1.dtb.o
 lwl-$(CONFIG_MACH_SCB9328) += imx1-scb9328.dtb.o
diff --git a/arch/arm/dts/stm32mp131.dtsi b/arch/arm/dts/stm32mp131.dtsi
new file mode 100644
index 000000000000..2ecad85f086e
--- /dev/null
+++ b/arch/arm/dts/stm32mp131.dtsi
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/ {
+	aliases {
+		mmc0 = &sdmmc1;
+	};
+};
+
+&{/soc} {
+	memory-controller@5a003000 {
+		compatible = "st,stm32mp13-ddr";
+		reg = <0x5a003000 0x1000>;
+	};
+};
diff --git a/arch/arm/dts/stm32mp135f-dk.dts b/arch/arm/dts/stm32mp135f-dk.dts
new file mode 100644
index 000000000000..104886e8af88
--- /dev/null
+++ b/arch/arm/dts/stm32mp135f-dk.dts
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+
+#include <arm/stm32mp135f-dk.dts>
+#include "stm32mp131.dtsi"
+
+/ {
+	model = "STM32MP153F-DK";
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+	};
+};
diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig
index 38c1a44770c9..57c1691591e7 100644
--- a/arch/arm/mach-stm32mp/Kconfig
+++ b/arch/arm/mach-stm32mp/Kconfig
@@ -6,10 +6,18 @@ config ARCH_NR_GPIO
 	int
 	default 416
 
+config ARCH_STM32MP13
+	select ARM_PSCI_CLIENT
+	bool
+
 config ARCH_STM32MP157
 	select ARM_PSCI_CLIENT
 	bool
 
+config MACH_STM32MP13XX_DK
+	select ARCH_STM32MP13
+	bool "STM32MP137F DK board"
+
 config MACH_STM32MP15XX_DKX
 	select ARCH_STM32MP157
 	bool "STM32MP157 DK1 and DK2 boards"
diff --git a/images/Makefile.stm32mp b/images/Makefile.stm32mp
index fa79e09f952f..abe70a6a5037 100644
--- a/images/Makefile.stm32mp
+++ b/images/Makefile.stm32mp
@@ -30,6 +30,7 @@ pblb-$(CONFIG_ARCH_STM32MP) += start_stm32mp_bl33
 FILE_barebox-stm32mp-generic-bl33.img  = start_stm32mp_bl33.pblb
 image-$(CONFIG_ARCH_STM32MP) += barebox-stm32mp-generic-bl33.img
 
+$(call build_stm32mp_image, CONFIG_MACH_STM32MP13XX_DK, start_stm32mp13xx_dk, stm32mp13xx-dk)
 $(call build_stm32mp_image, CONFIG_MACH_STM32MP15XX_DKX, start_stm32mp15xx_dkx, stm32mp15xx-dkx)
 $(call build_stm32mp_image, CONFIG_MACH_STM32MP15X_EV1, start_stm32mp15x_ev1, stm32mp15x-ev1)
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support
  2022-02-21 10:36 [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Ahmad Fatoum
  2022-02-21 10:36 ` [PATCH 2/2] ARM: stm32mp: add board support for STM32MP135F-DK Ahmad Fatoum
@ 2022-02-23 11:29 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-02-23 11:29 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Feb 21, 2022 at 11:36:24AM +0100, Ahmad Fatoum wrote:
> Full buswidth for STM32MP131 means 2 byte wide, not 4 as the memory bus
> is restricted to 16-bit. Teach barebox the difference.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  arch/arm/mach-stm32mp/ddrctrl.c               | 26 ++++++++++++++-----
>  arch/arm/mach-stm32mp/include/mach/revision.h |  8 ++++++
>  2 files changed, 27 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/mach-stm32mp/ddrctrl.c b/arch/arm/mach-stm32mp/ddrctrl.c
> index 93996d0afc79..7f0944d7e77c 100644
> --- a/arch/arm/mach-stm32mp/ddrctrl.c
> +++ b/arch/arm/mach-stm32mp/ddrctrl.c
> @@ -9,6 +9,7 @@
>  #include <mach/ddr_regs.h>
>  #include <mach/entry.h>
>  #include <mach/stm32.h>
> +#include <mach/revision.h>
>  #include <asm/barebox-arm.h>
>  #include <asm/memory.h>
>  #include <pbl.h>
> @@ -62,7 +63,8 @@ enum ddrctrl_buswidth {
>  };
>  
>  static unsigned long ddrctrl_addrmap_ramsize(struct stm32mp1_ddrctl __iomem *d,
> -					     enum ddrctrl_buswidth buswidth)
> +					     enum ddrctrl_buswidth buswidth,
> +					     unsigned nb_bytes)
>  {
>  	unsigned banks = 3, cols = 12, rows = 16;
>  	u32 reg;
> @@ -99,21 +101,26 @@ static unsigned long ddrctrl_addrmap_ramsize(struct stm32mp1_ddrctl __iomem *d,
>  	if (LINE_UNUSED(reg, ADDRMAP6_ROW_B13)) rows--;
>  	if (LINE_UNUSED(reg, ADDRMAP6_ROW_B12)) rows--;
>  
> -	return memory_sdram_size(cols, rows, BIT(banks), 4 / BIT(buswidth));
> +	return memory_sdram_size(cols, rows, BIT(banks), nb_bytes / BIT(buswidth));
>  }
>  
> -static inline unsigned ddrctrl_ramsize(void __iomem *base)
> +static inline unsigned ddrctrl_ramsize(void __iomem *base, unsigned nb_bytes)
>  {
>  	struct stm32mp1_ddrctl __iomem *ddrctl = base;
>  	unsigned buswidth = readl(&ddrctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK;
>  	buswidth >>= DDRCTRL_MSTR_DATA_BUS_WIDTH_SHIFT;
>  
> -	return ddrctrl_addrmap_ramsize(ddrctl, buswidth);
> +	return ddrctrl_addrmap_ramsize(ddrctl, buswidth, nb_bytes);
>  }
>  
>  static inline unsigned stm32mp1_ddrctrl_ramsize(void)
>  {
> -	return ddrctrl_ramsize(IOMEM(STM32_DDRCTL_BASE));
> +	u32 nb_bytes = 4;
> +
> +	if (cpu_stm32_is_stm32mp13())
> +		nb_bytes /= 2;
> +
> +	return ddrctrl_ramsize(IOMEM(STM32_DDRCTL_BASE), nb_bytes);
>  }
>  
>  void __noreturn stm32mp1_barebox_entry(void *boarddata)
> @@ -126,17 +133,22 @@ static int stm32mp1_ddr_probe(struct device_d *dev)
>  {
>  	struct resource *iores;
>  	void __iomem *base;
> +	unsigned long nb_bytes;
>  
>  	iores = dev_request_mem_resource(dev, 0);
>  	if (IS_ERR(iores))
>  		return PTR_ERR(iores);
>  	base = IOMEM(iores->start);
>  
> -	return arm_add_mem_device("ram0", STM32_DDR_BASE, ddrctrl_ramsize(base));
> +	nb_bytes = (unsigned long)device_get_match_data(dev);
> +
> +	return arm_add_mem_device("ram0", STM32_DDR_BASE,
> +				  ddrctrl_ramsize(base, nb_bytes));
>  }
>  
>  static __maybe_unused struct of_device_id stm32mp1_ddr_dt_ids[] = {
> -	{ .compatible = "st,stm32mp1-ddr" },
> +	{ .compatible = "st,stm32mp1-ddr", .data = (void *)4 },
> +	{ .compatible = "st,stm32mp13-ddr", .data = (void *)2 },
>  	{ /* sentinel */ }
>  };
>  
> diff --git a/arch/arm/mach-stm32mp/include/mach/revision.h b/arch/arm/mach-stm32mp/include/mach/revision.h
> index 2ef8ef30c3ae..c141b925a156 100644
> --- a/arch/arm/mach-stm32mp/include/mach/revision.h
> +++ b/arch/arm/mach-stm32mp/include/mach/revision.h
> @@ -32,6 +32,14 @@
>  #define CPU_STM32MP151Fxx	0x050000AE
>  #define CPU_STM32MP151Dxx	0x050000AF
>  
> +#define cpu_stm32_is(mask, val) ({ \
> +	u32 type; \
> +	__stm32mp_get_cpu_type(&type) == 0 ? (type & mask) == val : 0; \
> +})
> +
> +#define cpu_stm32_is_stm32mp15() cpu_stm32_is(0xFFFF0000, 0x05000000)
> +#define cpu_stm32_is_stm32mp13() cpu_stm32_is(0xFFFF0000, 0x05010000)
> +
>  /* silicon revisions */
>  #define CPU_REV_A	0x1000
>  #define CPU_REV_B	0x2000
> -- 
> 2.30.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-23 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 10:36 [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Ahmad Fatoum
2022-02-21 10:36 ` [PATCH 2/2] ARM: stm32mp: add board support for STM32MP135F-DK Ahmad Fatoum
2022-02-23 11:29 ` [PATCH 1/2] ARM: stm32mp: ddrctl: add STM32MP131 RAM size querying support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox