Masahiro Yamada | b692c3f | 2017-02-14 01:24:24 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Socionext Inc. |
| 3 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mmc.h> |
| 10 | #include <linux/errno.h> |
| 11 | |
| 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 | |
| 25 | int mmc_get_env_dev(void) |
| 26 | { |
| 27 | return find_first_mmc_device(); |
| 28 | } |
| 29 | |
| 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 | |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 38 | env_set_ulong("mmc_first_dev", dev); |
Masahiro Yamada | b692c3f | 2017-02-14 01:24:24 +0900 | [diff] [blame] | 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 | ); |