All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Yan <andy.yan@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 3/3] rockchip: check download key before bootup
Date: Wed, 11 Oct 2017 15:01:31 +0800	[thread overview]
Message-ID: <1507705291-10777-1-git-send-email-andy.yan@rock-chips.com> (raw)
In-Reply-To: <1507705170-10619-1-git-send-email-andy.yan@rock-chips.com>

Enter download mode if the download key pressed.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>

---

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

 arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c
index 4652490..bf0a410 100644
--- a/arch/arm/mach-rockchip/boot_mode.c
+++ b/arch/arm/mach-rockchip/boot_mode.c
@@ -5,14 +5,57 @@
  */
 
 #include <common.h>
+#include <adc.h>
 #include <asm/io.h>
 #include <asm/arch/boot_mode.h>
 
+void set_back_to_bootrom_dnl_flag(void)
+{
+	writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+}
+
+/*
+ * detect download key status by adc, most rockchip
+ * based boards use adc sample the download key status,
+ * but there are also some use gpio. So it's better to
+ * make this a weak function that can be override by
+ * some special boards.
+ */
+#define KEY_DOWN_MIN_VAL	0
+#define KEY_DOWN_MAX_VAL	30
+
+__weak int rockchip_dnl_key_pressed(void)
+{
+	unsigned int val;
+
+	if (adc_channel_single_shot("saradc", 1, &val)) {
+		printf("%s adc_channel_single_shot fail!\n", __func__);
+		return false;
+	}
+
+	if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
+		return true;
+	else
+		return false;
+}
+
+void rockchip_dnl_mode_check(void)
+{
+	if (rockchip_dnl_key_pressed()) {
+		printf("download key pressed, entering download mode...");
+		set_back_to_bootrom_dnl_flag();
+		do_reset(NULL, 0, 0, NULL);
+	}
+}
+
 int setup_boot_mode(void)
 {
 	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
 	int boot_mode = readl(reg);
 
+	rockchip_dnl_mode_check();
+
+	boot_mode = readl(reg);
 	debug("boot mode %x.\n", boot_mode);
 
 	/* Clear boot mode */
-- 
2.7.4

  parent reply	other threads:[~2017-10-11  7:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11  6:59 [U-Boot] [PATCH v3 0/3] Most rockchip platform based boards use a key to instruct Andy Yan
2017-10-11  7:00 ` [U-Boot] [PATCH v3 1/3] rockchip: make boot_mode related codes reused across all platforms Andy Yan
2017-11-20 14:06   ` [U-Boot] [U-Boot, v3, " Philipp Tomsich
2017-11-20 14:50   ` Philipp Tomsich
2017-11-21  0:48     ` Andy Yan
2017-11-21  8:25       ` Dr. Philipp Tomsich
2017-11-21 22:32   ` Philipp Tomsich
2017-10-11  7:00 ` [U-Boot] [PATCH v3 2/3] rockchip: add support for enter to bootrom download mode Andy Yan
2017-11-20 14:06   ` [U-Boot] [U-Boot, v3, " Philipp Tomsich
2017-11-20 14:07   ` Philipp Tomsich
2017-11-21 22:32   ` Philipp Tomsich
2017-10-11  7:01 ` Andy Yan [this message]
2017-11-20 14:06   ` [U-Boot] [U-Boot, v3, 3/3] rockchip: check download key before bootup Philipp Tomsich
2017-11-20 14:51   ` Philipp Tomsich
2017-11-21  1:02     ` Andy Yan
2017-11-21 12:31       ` Dr. Philipp Tomsich
2017-11-21 22:32   ` Philipp Tomsich
2017-11-17 10:09 ` [U-Boot] [PATCH v3 0/3] Most rockchip platform based boards use a key to instruct Andy Yan
2017-11-17 10:19   ` Dr. Philipp Tomsich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507705291-10777-1-git-send-email-andy.yan@rock-chips.com \
    --to=andy.yan@rock-chips.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.