boot_mode.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * (C) Copyright 2016 Rockchip Electronics Co., Ltd
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <adc.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/boot_mode.h>
  10. #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
  11. int setup_boot_mode(void)
  12. {
  13. return 0;
  14. }
  15. #else
  16. void set_back_to_bootrom_dnl_flag(void)
  17. {
  18. writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
  19. }
  20. /*
  21. * detect download key status by adc, most rockchip
  22. * based boards use adc sample the download key status,
  23. * but there are also some use gpio. So it's better to
  24. * make this a weak function that can be override by
  25. * some special boards.
  26. */
  27. #define KEY_DOWN_MIN_VAL 0
  28. #define KEY_DOWN_MAX_VAL 30
  29. __weak int rockchip_dnl_key_pressed(void)
  30. {
  31. unsigned int val;
  32. if (adc_channel_single_shot("saradc", 1, &val)) {
  33. pr_err("%s: adc_channel_single_shot fail!\n", __func__);
  34. return false;
  35. }
  36. if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
  37. return true;
  38. else
  39. return false;
  40. }
  41. void rockchip_dnl_mode_check(void)
  42. {
  43. if (rockchip_dnl_key_pressed()) {
  44. printf("download key pressed, entering download mode...");
  45. set_back_to_bootrom_dnl_flag();
  46. do_reset(NULL, 0, 0, NULL);
  47. }
  48. }
  49. int setup_boot_mode(void)
  50. {
  51. void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
  52. int boot_mode = readl(reg);
  53. rockchip_dnl_mode_check();
  54. boot_mode = readl(reg);
  55. debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
  56. /* Clear boot mode */
  57. writel(BOOT_NORMAL, reg);
  58. switch (boot_mode) {
  59. case BOOT_FASTBOOT:
  60. debug("%s: enter fastboot!\n", __func__);
  61. env_set("preboot", "setenv preboot; fastboot usb0");
  62. break;
  63. case BOOT_UMS:
  64. debug("%s: enter UMS!\n", __func__);
  65. env_set("preboot", "setenv preboot; ums mmc 0");
  66. break;
  67. }
  68. return 0;
  69. }
  70. #endif