boot_mode.c 1.6 KB

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