From: Andre Przywara <andre.przywara@arm.com>
To: Jagan Teki <jagan@amarulasolutions.com>
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
Chen-Yu Tsai <wens@csie.org>, Hauke Mehrtens <hauke@hauke-m.de>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Icenowy Zheng <icenowy@aosc.xyz>,
Joe Hershberger <joe.hershberger@ni.com>,
Wolfgang Denk <wd@denx.de>,
Daniel Wagenknecht <dwagenk@mailbox.org>,
u-boot@lists.denx.de
Subject: [PATCH 7/7] sunxi: H6: Enable SPI0 in DT when no eMMC is used
Date: Tue, 11 Jan 2022 12:46:07 +0000 [thread overview]
Message-ID: <20220111124607.863952-8-andre.przywara@arm.com> (raw)
In-Reply-To: <20220111124607.863952-1-andre.przywara@arm.com>
On the Allwinner H6 SoC both the SPI0 and the eMMC device share one pin,
so cannot be used simultaneously. On Linux this is a showstopper, since
only one of them would be able to claim the pin, and the probe order is
somewhat random. The DT consequently disables SPI0 in favour of the more
useful eMMC.
But a comment in the DT actually suggests that this could be reversed by
U-Boot, if no eMMC is actually connected. Let's now implement this:
When we fix up the device tree before booting a kernel, we iterate over
all MMC devices, and check if there is an eMMC device among them. If none
can be found, we enable SPI0 instead, to allow Linux access to the SPI
flash.
Since this fixup is not really universally applicable to all boards,
let's hide it behind a Kconfig option, and enable it only on the one
supported board where this makes sense: the Pine H64.
Please note that the SPI functionality is still disabled in U-Boot
proper, the pinmux clash affects us too: it would always disable the eMMC
and so spoil this algorithm here.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
arch/arm/mach-sunxi/Kconfig | 10 ++++++++
board/sunxi/board.c | 50 +++++++++++++++++++++++++++++++++++++
configs/pine_h64_defconfig | 1 +
3 files changed, 61 insertions(+)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 56ff1e197c..ce66453029 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -1047,6 +1047,16 @@ config BLUETOOTH_DT_DEVICE_FIXUP
The used address is "bdaddr" if set, and "ethaddr" with the LSB
flipped elsewise.
+config SUNXI_H6_ENABLE_SPIFLASH
+ bool "Enable H6 SPI flash vs. eMMC enablement"
+ depends on MACH_SUN50I_H6
+ default n
+ help
+ Enable this option if you want U-Boot check for an eMMC device
+ on Allwinner H6 boards, and enable the SPI flash if none is found.
+ SPI0 and MMC2 share one pin, so cannot coexist in Linux. The
+ DT prefers eMMC, but if none is used, we can safely enable SPI.
+
endif
config CHIP_DIP_SCAN
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 2472343d00..e943a16e16 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -942,6 +942,32 @@ static void bluetooth_dt_fixup(void *blob)
"local-bd-address", bdaddr, ETH_ALEN, 1);
}
+/* Iterate over all MMC devices to check if there is an eMMC among them. */
+static bool has_emmc_device(void)
+{
+ struct udevice *dev;
+
+ if (CONFIG_MMC_SUNXI_SLOT_EXTRA == -1)
+ return false;
+
+ for (uclass_first_device(UCLASS_MMC, &dev);
+ dev;
+ uclass_next_device(&dev)) {
+ struct mmc *mmc = mmc_get_mmc_dev(dev);
+
+ mmc_init(mmc);
+ if (!mmc->has_init)
+ continue;
+
+ if (IS_SD(mmc))
+ continue;
+
+ return true;
+ }
+
+ return false;
+}
+
int ft_board_setup(void *blob, struct bd_info *bd)
{
int __maybe_unused r;
@@ -959,6 +985,30 @@ int ft_board_setup(void *blob, struct bd_info *bd)
if (r)
return r;
#endif
+
+ /*
+ * On the H6 SPI0 and MMC2 share one pin, so cannot be used together
+ * (in Linux). The DT thus disables SPI0 in favour of the more
+ * useful eMMC. However if there is no eMMC connected, we can enable
+ * SPI0, to allows access to a SPI flash, for instance.
+ */
+ if (IS_ENABLED(CONFIG_SUNXI_H6_ENABLE_SPIFLASH)) {
+ const char *spi_status, *emmc_status;
+
+ if (has_emmc_device()) {
+ emmc_status = "okay";
+ spi_status = "disabled";
+ } else {
+ emmc_status = "disabled";
+ spi_status = "okay";
+ }
+
+ do_fixup_by_path(blob, "/soc/spi@5010000", "status",
+ spi_status, strlen(spi_status), 0);
+ do_fixup_by_path(blob, "/soc/mmc@4022000", "status",
+ emmc_status, strlen(emmc_status), 0);
+ }
+
return 0;
}
diff --git a/configs/pine_h64_defconfig b/configs/pine_h64_defconfig
index 1e730dd9fa..9220af1429 100644
--- a/configs/pine_h64_defconfig
+++ b/configs/pine_h64_defconfig
@@ -9,6 +9,7 @@ CONFIG_MMC0_CD_PIN="PF6"
CONFIG_MMC_SUNXI_SLOT_EXTRA=2
CONFIG_USB3_VBUS_PIN="PL5"
CONFIG_SPL_SPI_SUNXI=y
+CONFIG_SUNXI_H6_ENABLE_SPIFLASH=y
# CONFIG_PSCI_RESET is not set
# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
CONFIG_SPI_FLASH_WINBOND=y
--
2.25.1
next prev parent reply other threads:[~2022-01-11 12:47 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 12:46 [PATCH 0/7] sunxi: Fix U-Boot proper SPI operation Andre Przywara
2022-01-11 12:46 ` [PATCH 1/7] sunxi: SPI: fix pinmuxing for Allwinner H6 SoCs Andre Przywara
2022-01-11 12:46 ` [PATCH 2/7] sunxi: Kconfig: Fix up SPI configuration Andre Przywara
2022-01-24 17:02 ` Andre Przywara
2022-02-24 7:26 ` Jagan Teki
2022-02-24 7:26 ` Jagan Teki
2022-01-11 12:46 ` [PATCH 3/7] env: sunxi: Define location in SPI flash Andre Przywara
2022-01-11 12:46 ` [PATCH 4/7] sunxi: use boot source for determining environment location Andre Przywara
2022-04-15 17:28 ` Chris Morgan
2022-04-20 23:33 ` Andre Przywara
2022-05-05 15:43 ` Chris Morgan
2022-01-11 12:46 ` [PATCH 5/7] env: sunxi: enable ENV_IS_IN_SPI_FLASH Andre Przywara
2022-01-11 12:46 ` [PATCH 6/7] sunxi: boards: Enable SPI flash support in U-Boot proper Andre Przywara
2022-01-11 12:46 ` Andre Przywara [this message]
2022-01-20 13:38 ` [PATCH 7/7] sunxi: H6: Enable SPI0 in DT when no eMMC is used Jagan Teki
2022-01-20 14:06 ` Andre Przywara
2022-01-20 14:36 ` Jagan Teki
2022-02-24 7:30 ` Jagan Teki
2022-02-24 11:00 ` Andre Przywara
2022-03-10 12:05 ` [PATCH 0/7] sunxi: Fix U-Boot proper SPI operation Jagan Teki
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=20220111124607.863952-8-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=dwagenk@mailbox.org \
--cc=hauke@hauke-m.de \
--cc=icenowy@aosc.xyz \
--cc=jagan@amarulasolutions.com \
--cc=jernej.skrabec@gmail.com \
--cc=joe.hershberger@ni.com \
--cc=samuel@sholland.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=wd@denx.de \
--cc=wens@csie.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