1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5 */
6
7 #include <common.h>
8 #include <env.h>
9 #include <mmc.h>
10 #include <linux/errno.h>
11
find_first_mmc_device(void)12 static int find_first_mmc_device(void)
13 {
14 struct mmc *mmc;
15 int i;
16
17 for (i = 0; (mmc = find_mmc_device(i)); i++) {
18 if (!mmc_init(mmc) && IS_MMC(mmc))
19 return i;
20 }
21
22 return -ENODEV;
23 }
24
mmc_get_env_dev(void)25 int mmc_get_env_dev(void)
26 {
27 return find_first_mmc_device();
28 }
29
do_mmcsetn(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])30 static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
31 {
32 int dev;
33
34 dev = find_first_mmc_device();
35 if (dev < 0)
36 return CMD_RET_FAILURE;
37
38 env_set_ulong("mmc_first_dev", dev);
39 return CMD_RET_SUCCESS;
40 }
41
42 U_BOOT_CMD(
43 mmcsetn, 1, 1, do_mmcsetn,
44 "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
45 ""
46 );
47