]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
board/tq: Add common mmc API
authorMax Merchel <Max.Merchel@ew.tq-group.com>
Mon, 23 Mar 2026 13:47:38 +0000 (14:47 +0100)
committerFabio Estevam <festevam@nabladev.com>
Thu, 2 Apr 2026 12:05:46 +0000 (09:05 -0300)
Reduce code duplication by adding a default implementation

Signed-off-by: Max Merchel <Max.Merchel@ew.tq-group.com>
board/tq/common/Kconfig
board/tq/common/Makefile
board/tq/common/tq_sdmmc.c [new file with mode: 0644]

index a4a1d17bb9c243b69aaae485ad87cee3efc45d87..a1896929ea36153bc876f0564e73cecab4bd0f74 100644 (file)
@@ -8,3 +8,6 @@
 config TQ_COMMON_BB
        bool
        default y
+
+config TQ_COMMON_SDMMC
+       bool
index b643321fcb04586004d297015c03b1bceb529f8c..ac564a713fd1729dee67a263dc442e6ddc70438f 100644 (file)
@@ -6,3 +6,4 @@
 #
 
 obj-$(CONFIG_TQ_COMMON_BB) += tq_bb.o
+obj-$(CONFIG_TQ_COMMON_SDMMC) += tq_sdmmc.o
diff --git a/board/tq/common/tq_sdmmc.c b/board/tq/common/tq_sdmmc.c
new file mode 100644 (file)
index 0000000..b7336fa
--- /dev/null
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright (C) 2018-2026 TQ-Systems GmbH <u-boot@ew.tq-group.com>,
+ * D-82229 Seefeld, Germany.
+ */
+
+#include <command.h>
+#include <env.h>
+#include <mmc.h>
+#include <stdbool.h>
+#include <vsprintf.h>
+#include <asm/arch/sys_proto.h>
+#include <asm/io.h>
+#include <linux/errno.h>
+
+#include "tq_bb.h"
+
+static int check_mmc_autodetect(void)
+{
+       /* NO or unset: 0 / YES: 1 */
+       return (env_get_yesno("mmcautodetect") > 0);
+}
+
+/* This should be defined for each board */
+__weak int mmc_map_to_kernel_blk(int dev_no)
+{
+       return dev_no;
+}
+
+void board_late_mmc_env_init(void)
+{
+       char cmd[32];
+       u32 dev_no;
+
+       dev_no = mmc_get_env_dev();
+
+       if (!check_mmc_autodetect())
+               return;
+
+       env_set_ulong("mmcdev", dev_no);
+       env_set_ulong("mmcblkdev", mmc_map_to_kernel_blk(dev_no));
+
+       snprintf(cmd, ARRAY_SIZE(cmd), "mmc dev %d", dev_no);
+       run_command(cmd, 0);
+}