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