blob: 0db416d296ca0de18ab58e0aded2a56694b46baf [file] [log] [blame]
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
4 * Copyright 2018 NXP
5 *
6 */
7#include <command.h>
8#include <asm/arch/sys_proto.h>
9#include <linux/errno.h>
10#include <asm/io.h>
11#include <stdbool.h>
12#include <mmc.h>
13#include <vsprintf.h>
14#include <env.h>
15
16static int check_mmc_autodetect(void)
17{
18 char *autodetect_str = env_get("mmcautodetect");
19
20 if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
21 return 1;
22
23 return 0;
24}
25
26/* This should be defined for each board */
27__weak int mmc_map_to_kernel_blk(int dev_no)
28{
29 return dev_no;
30}
31
32void board_late_mmc_env_init(void)
33{
34 char cmd[32];
35 u32 dev_no = mmc_get_env_dev();
36
37 if (!check_mmc_autodetect())
38 return;
39
40 env_set_ulong("mmcdev", dev_no);
41
42 /* Set mmcblk env */
43 env_set_ulong("mmcblk", mmc_map_to_kernel_blk(dev_no));
44
45 sprintf(cmd, "mmc dev %d", dev_no);
46 run_command(cmd, 0);
47}