From patchwork Tue Sep 12 13:58:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Yan X-Patchwork-Id: 812860 X-Patchwork-Delegate: philipp.tomsich@theobroma-systems.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xs5zQ48Pcz9s7B for ; Wed, 13 Sep 2017 00:00:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 58735C2221E; Tue, 12 Sep 2017 14:00:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_SORBS_WEB autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BBF7CC22219; Tue, 12 Sep 2017 13:59:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 99046C2221A; Tue, 12 Sep 2017 13:58:50 +0000 (UTC) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.99.134]) by lists.denx.de (Postfix) with ESMTPS id 6DB78C221BA for ; Tue, 12 Sep 2017 13:58:44 +0000 (UTC) Received: from andy.yan?rock-chips.com (unknown [192.168.167.227]) by regular1.263xmail.com (Postfix) with ESMTP id 3A1AE8116 for ; Tue, 12 Sep 2017 21:58:38 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 9CCC0360; Tue, 12 Sep 2017 21:58:39 +0800 (CST) X-RL-SENDER: andy.yan@rock-chips.com X-FST-TO: philipp.tomsich@theobroma-systems.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: andy.yan@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: yxj@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 38066PVGN1; Tue, 12 Sep 2017 21:58:40 +0800 (CST) From: Andy Yan To: philipp.tomsich@theobroma-systems.com, sjg@chromium.org Date: Tue, 12 Sep 2017 21:58:33 +0800 Message-Id: <1505224713-30097-1-git-send-email-andy.yan@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505224549-29936-1-git-send-email-andy.yan@rock-chips.com> References: <1505224549-29936-1-git-send-email-andy.yan@rock-chips.com> Cc: u-boot@lists.denx.de, Andy Yan Subject: [U-Boot] [PATCH 3/3] rockchip: check download key before bootup X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Enter download mode if the download key pressed. Signed-off-by: Andy Yan --- arch/arm/mach-rockchip/boot_mode.c | 27 ++++++++++++++++++++++++++- board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index 7b3cbc5..bff1cbc 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -8,11 +8,36 @@ #include #include +void set_back_to_bootrom_dnl_flag(void) +{ + writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); +} + +/* + * some boards use a adc key, but some use gpio + */ +__weak int rockchip_dnl_key_pressed(void) +{ + return false; +} + +void rockchip_dnl_mode_check(void) +{ + if (rockchip_dnl_key_pressed()) { + printf("download key pressed, enter 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); + int boot_mode; + + rockchip_dnl_mode_check(); + boot_mode = readl(reg); debug("boot mode %x.\n", boot_mode); /* Clear boot mode */ diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c index d50c59d..738d942 100644 --- a/board/rockchip/evb_rk3399/evb-rk3399.c +++ b/board/rockchip/evb_rk3399/evb-rk3399.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include +#include #include #include #include @@ -13,6 +14,33 @@ DECLARE_GLOBAL_DATA_PTR; +#define KEY_DOWN_MIN_VAL 1 +#define KEY_DOWN_MAX_VAL 20 + +int rockchip_dnl_key_pressed(void) +{ + unsigned int ret; + unsigned int i; + unsigned int val; + int cnt = 0; + + for (i = 0; i < 10; i++) { + ret = adc_channel_single_shot("saradc", 1, &val); + if (ret) { + printf("%s adc_channel_single_shot fail!\n", __func__); + break; + } + + if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL)) + cnt++; + } + + if (cnt >= 8) + return true; + else + return false; +} + int board_init(void) { struct udevice *pinctrl, *regulator;