boot_mode.c 1.7 KB

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