blob: 149e662070ff4402a2339f74213e91926acde522 [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>
Simon Glass168068f2019-08-01 09:46:47 -06008#include <env.h>
Masahiro Yamadae5957e82017-02-14 01:24:24 +09009#include <mmc.h>
10#include <linux/errno.h>
11
12static 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
25int mmc_get_env_dev(void)
26{
27 return find_first_mmc_device();
28}
29
30static 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
Simon Glass018f5302017-08-03 12:22:10 -060038 env_set_ulong("mmc_first_dev", dev);
Masahiro Yamadae5957e82017-02-14 01:24:24 +090039 return CMD_RET_SUCCESS;
40}
41
42U_BOOT_CMD(
43 mmcsetn, 1, 1, do_mmcsetn,
44 "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
45 ""
46);