mmc-first-dev.c 1.3 KB

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