mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v1 08/12] ARM: stm32mp157c-dk2: add board-specific sysconf fixups
Date: Mon, 17 Jun 2019 17:07:47 +0200	[thread overview]
Message-ID: <20190617150751.3421-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20190617150751.3421-1-a.fatoum@pengutronix.de>

This imports the syscfg configuration done in the vendor U-Boot's
board_init into barebox. Only part missing is the CONFIG_DM_REGULATOR
protected clause that adjusts SYSCFG_IOCTRLSETR for operation above
~50MHz. These adjustments are only undertaken if VDD < 2.7V as they're
unsafe otherwise. As the barebox port doesn't yet support querying the
regulator, skip these adjustments for now.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/boards/stm32mp157c-dk2/board.c | 94 +++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/arch/arm/boards/stm32mp157c-dk2/board.c b/arch/arm/boards/stm32mp157c-dk2/board.c
index cbfe21db6a8c..5572231d525c 100644
--- a/arch/arm/boards/stm32mp157c-dk2/board.c
+++ b/arch/arm/boards/stm32mp157c-dk2/board.c
@@ -4,6 +4,55 @@
 #include <init.h>
 #include <asm/memory.h>
 #include <mach/stm32.h>
+#include <mfd/syscon.h>
+
+#define SYSCFG_BOOTR		0x00
+#define SYSCFG_PMCSETR		0x04
+#define SYSCFG_IOCTRLSETR	0x18
+#define SYSCFG_ICNR		0x1C
+#define SYSCFG_CMPCR		0x20
+#define SYSCFG_CMPENSETR	0x24
+#define SYSCFG_PMCCLRR		0x44
+
+#define SYSCFG_BOOTR_BOOT_MASK		GENMASK(2, 0)
+#define SYSCFG_BOOTR_BOOTPD_SHIFT	4
+
+#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE		BIT(0)
+#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI	BIT(1)
+#define SYSCFG_IOCTRLSETR_HSLVEN_ETH		BIT(2)
+#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC		BIT(3)
+#define SYSCFG_IOCTRLSETR_HSLVEN_SPI		BIT(4)
+
+#define SYSCFG_CMPCR_SW_CTRL		BIT(1)
+#define SYSCFG_CMPCR_READY		BIT(8)
+
+#define SYSCFG_CMPENSETR_MPU_EN		BIT(0)
+
+#define SYSCFG_PMCSETR_ETH_CLK_SEL	BIT(16)
+#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL	BIT(17)
+
+#define SYSCFG_PMCSETR_ETH_SELMII	BIT(20)
+
+#define SYSCFG_PMCSETR_ETH_SEL_MASK	GENMASK(23, 16)
+#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII	(0 << 21)
+#define SYSCFG_PMCSETR_ETH_SEL_RGMII	(1 << 21)
+#define SYSCFG_PMCSETR_ETH_SEL_RMII	(4 << 21)
+
+#define pr_debug_syscfg(syscfg, reg) do {			\
+	int ret;						\
+	u32 val;						\
+								\
+	if (MSG_DEBUG > LOGLEVEL)				\
+		break;						\
+								\
+	ret = regmap_read(syscfg, reg, &val);			\
+								\
+	if (ret == 0)						\
+		pr_debug(#reg "= 0x%08x\n", val);		\
+	else							\
+		pr_debug(#reg "= ERROR (%d)\n", ret);		\
+} while (0)
+
 
 static int dk2_postcore_init(void)
 {
@@ -15,3 +64,48 @@ static int dk2_postcore_init(void)
 	return 0;
 }
 mem_initcall(dk2_postcore_init);
+
+static int dk2_sysconf_init(void)
+{
+	struct regmap *syscfg;
+	u32 reg;
+
+	if (!of_machine_is_compatible("st,stm32mp157c-dk2"))
+		return 0;
+
+	// TODO this function should be skipped if TF-A is used as first stage.
+	// Any way to determine this at runtime?
+
+	syscfg = syscon_regmap_lookup_by_compatible("st,stm32mp157-syscfg");
+
+	/* interconnect update : select master using the port 1 */
+	/* LTDC = AXI_M9 */
+	/* GPU  = AXI_M8 */
+	/* for now information is hardcoded */
+	regmap_write(syscfg, SYSCFG_ICNR, BIT(9));
+	pr_debug_syscfg(syscfg, SYSCFG_ICNR);
+
+	/* disable Pull-Down for boot pin connected to VDD */
+	regmap_read(syscfg, SYSCFG_BOOTR, &reg);
+	reg &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
+	reg |= (reg & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
+	regmap_write(syscfg, SYSCFG_BOOTR, reg);
+	pr_debug_syscfg(syscfg, SYSCFG_BOOTR);
+
+	// TODO: Port High Speed Low Voltage Pad mode Enable from U-Boot
+
+	/* activate automatic I/O compensation
+	 * warning: need to ensure CSI enabled and ready in clock driver
+	 */
+	regmap_write(syscfg, SYSCFG_CMPENSETR, SYSCFG_CMPENSETR_MPU_EN);
+
+	do {
+		regmap_read(syscfg, SYSCFG_CMPCR, &reg);
+	} while (!(reg & SYSCFG_CMPCR_READY));
+
+	regmap_update_bits(syscfg, SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL, 0);
+	pr_debug_syscfg(syscfg, SYSCFG_CMPCR);
+
+	return 0;
+}
+coredevice_initcall(dk2_sysconf_init);
-- 
2.20.1


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

  parent reply	other threads:[~2019-06-17 15:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-17 15:07 [PATCH v1 00/12] ARM: stm32mp: add drivers for GPIO, pinctrl Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 01/12] ARM: dts: stm32mp157a-dk1.dts: include upstream dts before barebox' Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 02/12] ARM: dts: stm32mp: factor out common DK nodes into dtsi Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 03/12] gpiolib: add gpio_get_chip helper Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 04/12] driver: add stubs for hardware spinlocks Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 05/12] pinctrl: add driver for STM32 GPIO and pin multiplexer Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 06/12] ARM: dts: stm32mp157a-dk1: enable heartbeat and error LEDs Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 07/12] ARM: stm32mp: turn on GPIO related options Ahmad Fatoum
2019-06-17 15:07 ` Ahmad Fatoum [this message]
2019-06-17 15:14   ` [PATCH v1 08/12] ARM: stm32mp157c-dk2: add board-specific sysconf fixups Ahmad Fatoum
2019-06-18  5:43     ` Rouven Czerwinski
2019-06-17 15:07 ` [PATCH v1 09/12] ARM: psci: fix erroneous call of ->system_reset on system_off Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 10/12] ARM: sm: move get_gicd_base_address to header for reuse Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 11/12] ARM: stm32mp: implement PSCI support Ahmad Fatoum
2019-06-17 15:07 ` [PATCH v1 12/12] ARM: stm32mp157c-dk2: boot kernel in nonsecure mode Ahmad Fatoum
2019-06-20 14:32 ` [PATCH v1 00/12] ARM: stm32mp: add drivers for GPIO, pinctrl Sascha Hauer
2019-07-03 16:51   ` Ahmad Fatoum
2019-07-04  5:39     ` Ahmad Fatoum
2019-07-04  7:01       ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190617150751.3421-9-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox