Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | b692c3f | 2017-02-14 01:24:24 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Socionext Inc. |
| 4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | b692c3f | 2017-02-14 01:24:24 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <mmc.h> |
| 9 | #include <linux/errno.h> |
| 10 | |
| 11 | static 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 | |
| 24 | int mmc_get_env_dev(void) |
| 25 | { |
| 26 | return find_first_mmc_device(); |
| 27 | } |
| 28 | |
| 29 | static 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 Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 37 | env_set_ulong("mmc_first_dev", dev); |
Masahiro Yamada | b692c3f | 2017-02-14 01:24:24 +0900 | [diff] [blame] | 38 | return CMD_RET_SUCCESS; |
| 39 | } |
| 40 | |
| 41 | U_BOOT_CMD( |
| 42 | mmcsetn, 1, 1, do_mmcsetn, |
| 43 | "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment", |
| 44 | "" |
| 45 | ); |