]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
e5957e8d MY |
2 | /* |
3 | * Copyright (C) 2016 Socionext Inc. | |
4 | * Author: Masahiro Yamada <[email protected]> | |
e5957e8d MY |
5 | */ |
6 | ||
7 | #include <common.h> | |
09140113 | 8 | #include <command.h> |
168068fb | 9 | #include <env.h> |
e5957e8d MY |
10 | #include <mmc.h> |
11 | #include <linux/errno.h> | |
12 | ||
ef5c7d6d | 13 | static int find_first_mmc_device(bool is_sd) |
e5957e8d MY |
14 | { |
15 | struct mmc *mmc; | |
16 | int i; | |
17 | ||
18 | for (i = 0; (mmc = find_mmc_device(i)); i++) { | |
ef5c7d6d MY |
19 | if (!mmc_init(mmc) && |
20 | ((is_sd && IS_SD(mmc)) || (!is_sd && IS_MMC(mmc)))) | |
e5957e8d MY |
21 | return i; |
22 | } | |
23 | ||
24 | return -ENODEV; | |
25 | } | |
26 | ||
27 | int mmc_get_env_dev(void) | |
28 | { | |
ef5c7d6d | 29 | return find_first_mmc_device(false); |
e5957e8d MY |
30 | } |
31 | ||
09140113 SG |
32 | static int do_mmcsetn(struct cmd_tbl *cmdtp, int flag, int argc, |
33 | char *const argv[]) | |
e5957e8d MY |
34 | { |
35 | int dev; | |
36 | ||
ef5c7d6d | 37 | dev = find_first_mmc_device(false); |
e5957e8d MY |
38 | if (dev < 0) |
39 | return CMD_RET_FAILURE; | |
40 | ||
018f5303 | 41 | env_set_ulong("mmc_first_dev", dev); |
e5957e8d MY |
42 | return CMD_RET_SUCCESS; |
43 | } | |
44 | ||
45 | U_BOOT_CMD( | |
46 | mmcsetn, 1, 1, do_mmcsetn, | |
47 | "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment", | |
48 | "" | |
49 | ); | |
ef5c7d6d | 50 | |
09140113 SG |
51 | static int do_sdsetn(struct cmd_tbl *cmdtp, int flag, int argc, |
52 | char *const argv[]) | |
ef5c7d6d MY |
53 | { |
54 | int dev; | |
55 | ||
56 | dev = find_first_mmc_device(true); | |
57 | if (dev < 0) | |
58 | return CMD_RET_FAILURE; | |
59 | ||
60 | env_set_ulong("sd_first_dev", dev); | |
61 | return CMD_RET_SUCCESS; | |
62 | } | |
63 | ||
64 | U_BOOT_CMD( | |
65 | sdsetn, 1, 1, do_sdsetn, | |
66 | "Set the first SD dev number to \"sd_first_dev\" environment", | |
67 | "" | |
68 | ); |