[{"id":1767551,"web_url":"http://patchwork.ozlabs.org/comment/1767551/","msgid":"<CAPnjgZ2wYHfahmR2aXAfjrvLFJy6jG-1sXLvBDO5rXDJ-YQe6Q@mail.gmail.com>","list_archive_url":null,"date":"2017-09-13T04:26:39","subject":"Re: [U-Boot] [PATCH 3/3] rockchip: check download key before bootup","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/people/6170/","name":"Simon Glass","email":"sjg@chromium.org"},"content":"Hi Andy,\n\nOn 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote:\n> Enter download mode if the download key pressed.\n>\n> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>\n> ---\n>\n>  arch/arm/mach-rockchip/boot_mode.c     | 27 ++++++++++++++++++++++++++-\n>  board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++\n>  2 files changed, 54 insertions(+), 1 deletion(-)\n>\n> diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c\n> index 7b3cbc5..bff1cbc 100644\n> --- a/arch/arm/mach-rockchip/boot_mode.c\n> +++ b/arch/arm/mach-rockchip/boot_mode.c\n> @@ -8,11 +8,36 @@\n>  #include <asm/io.h>\n>  #include <asm/arch/boot_mode.h>\n>\n> +void set_back_to_bootrom_dnl_flag(void)\n> +{\n> +       writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);\n> +}\n> +\n> +/*\n> + * some boards use a adc key, but some use gpio\n> + */\n> +__weak int rockchip_dnl_key_pressed(void)\n\nCan you please declare this in a header file and add a full comment as\nto what this does?\n\n> +{\n> +       return false;\n> +}\n> +\n> +void rockchip_dnl_mode_check(void)\n> +{\n> +       if (rockchip_dnl_key_pressed()) {\n> +               printf(\"download key pressed, enter download mode...\");\n\nshould that be 'entering'?\n\n> +               set_back_to_bootrom_dnl_flag();\n> +               do_reset(NULL, 0, 0, NULL);\n> +       }\n> +}\n> +\n>  int setup_boot_mode(void)\n>  {\n>         void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;\n> -       int boot_mode = readl(reg);\n> +       int boot_mode;\n> +\n> +       rockchip_dnl_mode_check();\n>\n> +       boot_mode = readl(reg);\n>         debug(\"boot mode %x.\\n\", boot_mode);\n>\n>         /* Clear boot mode */\n> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c\n> index d50c59d..738d942 100644\n> --- a/board/rockchip/evb_rk3399/evb-rk3399.c\n> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c\n> @@ -4,6 +4,7 @@\n>   * SPDX-License-Identifier:     GPL-2.0+\n>   */\n>  #include <common.h>\n> +#include <adc.h>\n>  #include <dm.h>\n>  #include <ram.h>\n>  #include <dm/pinctrl.h>\n> @@ -13,6 +14,33 @@\n>\n>  DECLARE_GLOBAL_DATA_PTR;\n>\n> +#define KEY_DOWN_MIN_VAL       1\n> +#define KEY_DOWN_MAX_VAL       20\n> +\n> +int rockchip_dnl_key_pressed(void)\n> +{\n> +       unsigned int ret;\n> +       unsigned int i;\n> +       unsigned int val;\n> +       int cnt = 0;\n> +\n\nPlease document what is going on here - why the loop? What is the\ncheck against min/max value?\n\n> +       for (i = 0; i < 10; i++) {\n> +               ret = adc_channel_single_shot(\"saradc\", 1, &val);\n> +               if (ret) {\n> +                       printf(\"%s adc_channel_single_shot fail!\\n\", __func__);\n> +                       break;\n> +               }\n> +\n> +               if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))\n> +                       cnt++;\n> +       }\n> +\n> +       if (cnt >= 8)\n> +               return true;\n> +       else\n> +               return false;\n> +}\n> +\n>  int board_init(void)\n>  {\n>         struct udevice *pinctrl, *regulator;\n> --\n> 2.7.4\n>\n>\n\nRegards,\nSimon","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"GYhJyUU8\"; \n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"kE8te57W\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xsTPB3CbXz9rvt\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 14:35:42 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 2B09CC22502; Wed, 13 Sep 2017 04:34:00 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 9DAF2C224FC;\n\tWed, 13 Sep 2017 04:31:27 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 8ABC3C223D4; Wed, 13 Sep 2017 04:27:04 +0000 (UTC)","from mail-qt0-f180.google.com (mail-qt0-f180.google.com\n\t[209.85.216.180])\n\tby lists.denx.de (Postfix) with ESMTPS id F1659C223D1\n\tfor <u-boot@lists.denx.de>; Wed, 13 Sep 2017 04:27:00 +0000 (UTC)","by mail-qt0-f180.google.com with SMTP id b1so20237654qtc.4\n\tfor <u-boot@lists.denx.de>; Tue, 12 Sep 2017 21:27:00 -0700 (PDT)","by 10.200.37.200 with HTTP; Tue, 12 Sep 2017 21:26:39 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable\n\tautolearn_force=no version=3.4.0","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=20161025; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc;\n\tbh=kYxb6VKUpPzCaf+KG/StScZ/TfPOrnXlEC7nVNBD5Dw=;\n\tb=GYhJyUU8M8Ul72udtfnCJCazeZCHled2NjVLWs5Pr+UfSu3q/K7GSyg32KkA2k4Bw0\n\t8NyfwpZeyeiJEA72UNtjJgHLgDUcZarkebU2b4sdJeTAZjKWwsQSzAUaD+q8AZCozPu6\n\tU9GdUiXtVAAXyZkdYAgL0iTsf4TZvw5q7z4X7fIO+VtSnjrwvFeCs6/n+dC28oS9e4yO\n\tsKmqMtFY2mUraDw1HNyoU/8AhICKudguA9xIxM9uqfWkC1esdPl5HmH1JKSdMYx7+u9Y\n\tD5uNXaXYW520Op8eplGHIgNGBluqIrF6ntjToGJOprPyVPKi7aJLKMwr812+l44VBNc3\n\tWAKg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc;\n\tbh=kYxb6VKUpPzCaf+KG/StScZ/TfPOrnXlEC7nVNBD5Dw=;\n\tb=kE8te57WTWUl32xbNYp70g6xVImARh8f1Gk3Qf/Y0bfUiDGYRez9dLuI36n6teNYMB\n\tYOzJLcP7rukxr1CCZEBitHRJ8XDtpMYjAQItwrlAS+EDZkrq2JTecYSck7qPO+R4CCJY\n\tVEOn8d31GZElIKbarcNYEFGJ3l5CuW7KsN4GA="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:sender:in-reply-to:references:from\n\t:date:message-id:subject:to:cc;\n\tbh=kYxb6VKUpPzCaf+KG/StScZ/TfPOrnXlEC7nVNBD5Dw=;\n\tb=I0RpOmd8r2BbEIyUTg7vu2ZQojRNU9ftxSUZPcsJdRYvov8tTXLK2C2nh+KFvplHIH\n\t3Yii37/QYWZ4cEMxO+EGGK+o6j5c/9NiCdVPFla8iE2CBotAgCrzNweFYz8EY0Uf6LCH\n\tL0krMiSNN/P+3fg1p9PEhnbbyhyTdgGaWczrQ1NfV0bOkgZ7laiTulhfYxmVQCh6T+t1\n\tCmat0sw2xUZMj85TJPIeczruearW/ENhM2xQqnYXfPWXthfUE/AVk3JO9sC91IFjNsqF\n\tsEZjkklefSTeZQ3j87hkI0S6oXRM3o+6tBCTg5WRu4Dy5LRc9yiKmAHW2STqVlCwMSWX\n\treOA==","X-Gm-Message-State":"AHPjjUg4U9bjuJCbV7JJLMYCW5P5UGjg/YbJnuNrUgIEB+J3UJCi2hc6\n\tOnJ2VR10IXIlAEM+gULgiVljcAzC+Qf4Z1vQk1Buow==","X-Google-Smtp-Source":"AOwi7QBXi0Yzf2XXIt6yhQx0z9wRDM0O/YjRDF512s4Eq5U+n55NzX+BE5/rtuy2BMgcjbdyizDdUNN2APhuArnaJZ8=","X-Received":"by 10.200.5.132 with SMTP id a4mr25368989qth.318.1505276819672; \n\tTue, 12 Sep 2017 21:26:59 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<1505224713-30097-1-git-send-email-andy.yan@rock-chips.com>","References":"<1505224549-29936-1-git-send-email-andy.yan@rock-chips.com>\n\t<1505224713-30097-1-git-send-email-andy.yan@rock-chips.com>","From":"Simon Glass <sjg@chromium.org>","Date":"Tue, 12 Sep 2017 22:26:39 -0600","X-Google-Sender-Auth":"KwCx6Q4SO9UHntbY1063mlA9htg","Message-ID":"<CAPnjgZ2wYHfahmR2aXAfjrvLFJy6jG-1sXLvBDO5rXDJ-YQe6Q@mail.gmail.com>","To":"Andy Yan <andy.yan@rock-chips.com>","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>","Subject":"Re: [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 <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1767592,"web_url":"http://patchwork.ozlabs.org/comment/1767592/","msgid":"<94989b1e-b231-6e22-9065-67af1e8779a8@rock-chips.com>","list_archive_url":null,"date":"2017-09-13T06:14:01","subject":"Re: [U-Boot] [PATCH 3/3] rockchip: check download key before bootup","submitter":{"id":65124,"url":"http://patchwork.ozlabs.org/api/people/65124/","name":"Andy Yan","email":"andy.yan@rock-chips.com"},"content":"Hi Simon:\n\n\nOn 2017年09月13日 12:26, Simon Glass wrote:\n> Hi Andy,\n>\n> On 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote:\n>> Enter download mode if the download key pressed.\n>>\n>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>\n>> ---\n>>\n>>   arch/arm/mach-rockchip/boot_mode.c     | 27 ++++++++++++++++++++++++++-\n>>   board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++\n>>   2 files changed, 54 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c\n>> index 7b3cbc5..bff1cbc 100644\n>> --- a/arch/arm/mach-rockchip/boot_mode.c\n>> +++ b/arch/arm/mach-rockchip/boot_mode.c\n>> @@ -8,11 +8,36 @@\n>>   #include <asm/io.h>\n>>   #include <asm/arch/boot_mode.h>\n>>\n>> +void set_back_to_bootrom_dnl_flag(void)\n>> +{\n>> +       writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);\n>> +}\n>> +\n>> +/*\n>> + * some boards use a adc key, but some use gpio\n>> + */\n>> +__weak int rockchip_dnl_key_pressed(void)\n> Can you please declare this in a header file and add a full comment as\n> to what this does?\n\n     This function is only used in this file and can be override by \nother boards. So I don't\nthink this is a necessary to declare this in a header file.\n      Of course, I will add a full comment for it.\n>> +{\n>> +       return false;\n>> +}\n>> +\n>> +void rockchip_dnl_mode_check(void)\n>> +{\n>> +       if (rockchip_dnl_key_pressed()) {\n>> +               printf(\"download key pressed, enter download mode...\");\n> should that be 'entering'?\n\n     Okay, should be 'entering'\n>> +               set_back_to_bootrom_dnl_flag();\n>> +               do_reset(NULL, 0, 0, NULL);\n>> +       }\n>> +}\n>> +\n>>   int setup_boot_mode(void)\n>>   {\n>>          void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;\n>> -       int boot_mode = readl(reg);\n>> +       int boot_mode;\n>> +\n>> +       rockchip_dnl_mode_check();\n>>\n>> +       boot_mode = readl(reg);\n>>          debug(\"boot mode %x.\\n\", boot_mode);\n>>\n>>          /* Clear boot mode */\n>> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c\n>> index d50c59d..738d942 100644\n>> --- a/board/rockchip/evb_rk3399/evb-rk3399.c\n>> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c\n>> @@ -4,6 +4,7 @@\n>>    * SPDX-License-Identifier:     GPL-2.0+\n>>    */\n>>   #include <common.h>\n>> +#include <adc.h>\n>>   #include <dm.h>\n>>   #include <ram.h>\n>>   #include <dm/pinctrl.h>\n>> @@ -13,6 +14,33 @@\n>>\n>>   DECLARE_GLOBAL_DATA_PTR;\n>>\n>> +#define KEY_DOWN_MIN_VAL       1\n>> +#define KEY_DOWN_MAX_VAL       20\n>> +\n>> +int rockchip_dnl_key_pressed(void)\n>> +{\n>> +       unsigned int ret;\n>> +       unsigned int i;\n>> +       unsigned int val;\n>> +       int cnt = 0;\n>> +\n> Please document what is going on here - why the loop? What is the\n> check against min/max value?\n\n     This if for voltage debounce, according to my experience on the \nrk3399 evb board, in the 10 adc sample results,\nwe will met 2 ~ 4 result vals are out of the MIN~MAX range.\n>\n>> +       for (i = 0; i < 10; i++) {\n>> +               ret = adc_channel_single_shot(\"saradc\", 1, &val);\n>> +               if (ret) {\n>> +                       printf(\"%s adc_channel_single_shot fail!\\n\", __func__);\n>> +                       break;\n>> +               }\n>> +\n>> +               if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))\n>> +                       cnt++;\n>> +       }\n>> +\n>> +       if (cnt >= 8)\n>> +               return true;\n>> +       else\n>> +               return false;\n>> +}\n>> +\n>>   int board_init(void)\n>>   {\n>>          struct udevice *pinctrl, *regulator;\n>> --\n>> 2.7.4\n>>\n>>\n> Regards,\n> Simon\n>\n>\n>","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xsWb152H2z9sRV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 16:14:21 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 35C1EC22350; Wed, 13 Sep 2017 06:14:12 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 4E9EFC21DF0;\n\tWed, 13 Sep 2017 06:14:10 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid B5497C21EE2; Wed, 13 Sep 2017 06:14:09 +0000 (UTC)","from regular1.263xmail.com (regular1.263xmail.com [211.150.99.133])\n\tby lists.denx.de (Postfix) with ESMTPS id B91B3C21D58\n\tfor <u-boot@lists.denx.de>; Wed, 13 Sep 2017 06:14:08 +0000 (UTC)","from andy.yan?rock-chips.com (unknown [192.168.167.243])\n\tby regular1.263xmail.com (Postfix) with ESMTP id BC951905C\n\tfor <u-boot@lists.denx.de>; Wed, 13 Sep 2017 14:14:03 +0800 (CST)","from [172.16.12.133] (localhost [127.0.0.1])\n\tby smtp.263.net (Postfix) with ESMTPA id 26F643D0;\n\tWed, 13 Sep 2017 14:14:01 +0800 (CST)","from [172.16.12.133] (unknown [58.22.7.114])\n\tby smtp.263.net (Postfix) whith ESMTP id 2947UQCNZ1;\n\tWed, 13 Sep 2017 14:14:04 +0800 (CST)"],"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,\n\tRCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB autolearn=no\n\tautolearn_force=no version=3.4.0","X-263anti-spam":"KSV:0;","X-MAIL-GRAY":"0","X-MAIL-DELIVERY":"1","X-KSVirus-check":"0","X-ABS-CHECKED":"4","X-RL-SENDER":"andy.yan@rock-chips.com","X-FST-TO":"david.wu@rock-chips.com","X-SENDER-IP":"58.22.7.114","X-LOGIN-NAME":"andy.yan@rock-chips.com","X-UNIQUE-TAG":"<3edf74c6af3175c7db585684933eb5c4>","X-ATTACHMENT-NUM":"0","X-SENDER":"yxj@rock-chips.com","X-DNS-TYPE":"0","To":"Simon Glass <sjg@chromium.org>","References":"<1505224549-29936-1-git-send-email-andy.yan@rock-chips.com>\n\t<1505224713-30097-1-git-send-email-andy.yan@rock-chips.com>\n\t<CAPnjgZ2wYHfahmR2aXAfjrvLFJy6jG-1sXLvBDO5rXDJ-YQe6Q@mail.gmail.com>","From":"Andy Yan <andy.yan@rock-chips.com>","Message-ID":"<94989b1e-b231-6e22-9065-67af1e8779a8@rock-chips.com>","Date":"Wed, 13 Sep 2017 14:14:01 +0800","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<CAPnjgZ2wYHfahmR2aXAfjrvLFJy6jG-1sXLvBDO5rXDJ-YQe6Q@mail.gmail.com>","Content-Language":"en-US","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>, david.wu@rock-chips.com","Subject":"Re: [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 <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Transfer-Encoding":"base64","Content-Type":"text/plain; charset=\"utf-8\"; Format=\"flowed\"","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1769754,"web_url":"http://patchwork.ozlabs.org/comment/1769754/","msgid":"<CAPnjgZ2423F5K+q6XfFmw8p96-NHaHnQvDpZZDCoteTE5emBkQ@mail.gmail.com>","list_archive_url":null,"date":"2017-09-17T17:52:37","subject":"Re: [U-Boot] [PATCH 3/3] rockchip: check download key before bootup","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/people/6170/","name":"Simon Glass","email":"sjg@chromium.org"},"content":"Hi Andy,\n\nOn 13 September 2017 at 00:14, Andy Yan <andy.yan@rock-chips.com> wrote:\n> Hi Simon:\n>\n>\n>\n> On 2017年09月13日 12:26, Simon Glass wrote:\n>>\n>> Hi Andy,\n>>\n>> On 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote:\n>>>\n>>> Enter download mode if the download key pressed.\n>>>\n>>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>\n>>> ---\n>>>\n>>>   arch/arm/mach-rockchip/boot_mode.c     | 27 ++++++++++++++++++++++++++-\n>>>   board/rockchip/evb_rk3399/evb-rk3399.c | 28\n>>> ++++++++++++++++++++++++++++\n>>>   2 files changed, 54 insertions(+), 1 deletion(-)\n>>>\n>>> diff --git a/arch/arm/mach-rockchip/boot_mode.c\n>>> b/arch/arm/mach-rockchip/boot_mode.c\n>>> index 7b3cbc5..bff1cbc 100644\n>>> --- a/arch/arm/mach-rockchip/boot_mode.c\n>>> +++ b/arch/arm/mach-rockchip/boot_mode.c\n>>> @@ -8,11 +8,36 @@\n>>>   #include <asm/io.h>\n>>>   #include <asm/arch/boot_mode.h>\n>>>\n>>> +void set_back_to_bootrom_dnl_flag(void)\n>>> +{\n>>> +       writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);\n>>> +}\n>>> +\n>>> +/*\n>>> + * some boards use a adc key, but some use gpio\n>>> + */\n>>> +__weak int rockchip_dnl_key_pressed(void)\n>>\n>> Can you please declare this in a header file and add a full comment as\n>> to what this does?\n>\n>\n>     This function is only used in this file and can be override by other\n> boards. So I don't\n> think this is a necessary to declare this in a header file.\n\nThe reason is that all exported functions should be declared\nsomewhere. Otherwise the function can be used / overridden somewhere\nelse without any argument checking.\n\n>      Of course, I will add a full comment for it.\n>>>\n>>> +{\n>>> +       return false;\n>>> +}\n>>> +\n>>> +void rockchip_dnl_mode_check(void)\n>>> +{\n>>> +       if (rockchip_dnl_key_pressed()) {\n>>> +               printf(\"download key pressed, enter download mode...\");\n>>\n>> should that be 'entering'?\n>\n>\n>     Okay, should be 'entering'\n>\n>>> +               set_back_to_bootrom_dnl_flag();\n>>> +               do_reset(NULL, 0, 0, NULL);\n>>> +       }\n>>> +}\n>>> +\n>>>   int setup_boot_mode(void)\n>>>   {\n>>>          void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;\n>>> -       int boot_mode = readl(reg);\n>>> +       int boot_mode;\n>>> +\n>>> +       rockchip_dnl_mode_check();\n>>>\n>>> +       boot_mode = readl(reg);\n>>>          debug(\"boot mode %x.\\n\", boot_mode);\n>>>\n>>>          /* Clear boot mode */\n>>> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c\n>>> b/board/rockchip/evb_rk3399/evb-rk3399.c\n>>> index d50c59d..738d942 100644\n>>> --- a/board/rockchip/evb_rk3399/evb-rk3399.c\n>>> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c\n>>> @@ -4,6 +4,7 @@\n>>>    * SPDX-License-Identifier:     GPL-2.0+\n>>>    */\n>>>   #include <common.h>\n>>> +#include <adc.h>\n>>>   #include <dm.h>\n>>>   #include <ram.h>\n>>>   #include <dm/pinctrl.h>\n>>> @@ -13,6 +14,33 @@\n>>>\n>>>   DECLARE_GLOBAL_DATA_PTR;\n>>>\n>>> +#define KEY_DOWN_MIN_VAL       1\n>>> +#define KEY_DOWN_MAX_VAL       20\n>>> +\n>>> +int rockchip_dnl_key_pressed(void)\n>>> +{\n>>> +       unsigned int ret;\n>>> +       unsigned int i;\n>>> +       unsigned int val;\n>>> +       int cnt = 0;\n>>> +\n>>\n>> Please document what is going on here - why the loop? What is the\n>> check against min/max value?\n>\n>\n>     This if for voltage debounce, according to my experience on the rk3399\n> evb board, in the 10 adc sample results,\n> we will met 2 ~ 4 result vals are out of the MIN~MAX range.\n\nOK great, please add a comment here about this.\n\n>\n>>\n>>> +       for (i = 0; i < 10; i++) {\n>>> +               ret = adc_channel_single_shot(\"saradc\", 1, &val);\n>>> +               if (ret) {\n>>> +                       printf(\"%s adc_channel_single_shot fail!\\n\",\n>>> __func__);\n>>> +                       break;\n>>> +               }\n>>> +\n>>> +               if ((val >= KEY_DOWN_MIN_VAL) && (val <=\n>>> KEY_DOWN_MAX_VAL))\n>>> +                       cnt++;\n>>> +       }\n>>> +\n>>> +       if (cnt >= 8)\n>>> +               return true;\n>>> +       else\n>>> +               return false;\n>>> +}\n>>> +\n>>>   int board_init(void)\n>>>   {\n>>>          struct udevice *pinctrl, *regulator;\n>>> --\n>>> 2.7.4Regards,\nSimon","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"qBIYZjLK\"; \n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"Rj+VGb48\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xwH4804Lcz9sPm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 04:00:39 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 3FC38C21F34; Sun, 17 Sep 2017 18:00:38 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 5157DC21CB1;\n\tSun, 17 Sep 2017 17:53:05 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid BE521C21CB1; Sun, 17 Sep 2017 17:53:03 +0000 (UTC)","from mail-qt0-f174.google.com (mail-qt0-f174.google.com\n\t[209.85.216.174])\n\tby lists.denx.de (Postfix) with ESMTPS id 110F7C21C2B\n\tfor <u-boot@lists.denx.de>; Sun, 17 Sep 2017 17:52:59 +0000 (UTC)","by mail-qt0-f174.google.com with SMTP id i50so5777492qtf.0\n\tfor <u-boot@lists.denx.de>; Sun, 17 Sep 2017 10:52:59 -0700 (PDT)","by 10.200.37.200 with HTTP; Sun, 17 Sep 2017 10:52:37 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable\n\tautolearn_force=no version=3.4.0","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=20161025; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-transfer-encoding;\n\tbh=cn/frQqtzVpxiqJX+bfW/OtH4nOVn7FoFEr12IsZCMI=;\n\tb=qBIYZjLKWheEFDEIkyu56RvTGkZOiKnh5edzjy8RKEvUBeUvzqP7FULohuNzE+9YSb\n\tE1HGkJLTWC/WGcivLPL85/7e+oAfyh2m4mST+dEquiYUchHUZ7OV79Et4lPEGTEwHr56\n\tmh7rTOuJIdbz9uDwxJHEKlSKVYQyfpXbrsLX8FSdsHHS75t3b2IOLYu8+2IOaacLqkN2\n\t36/XHLfv1bXMHDcdqAmdDbkScUkPT++QGXjJTjpGyMUYeFbukLwu9KcKzbN4I+IF+u2A\n\tvxp8FNfLdVgMaGF6hlZfWv0daESp0CxQ2WwlFAfMnC5NeDYEkZ+vFOxRZSvjiM/Qvovd\n\tumnw==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:sender:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-transfer-encoding;\n\tbh=cn/frQqtzVpxiqJX+bfW/OtH4nOVn7FoFEr12IsZCMI=;\n\tb=Rj+VGb48gCLpo1hBIKgDmQZw/GDPya6cipmUkBB4hlle5H7PxB3lhgvzDDEzKtfJuh\n\tpkN6Jyezr35YyJWOiZELsMx1Wjmu0/RAlNVwTY7zBN4v8nLKvHP7Tza0ag7pnFzaM8AS\n\tsZGhWUreIqZ3zYOB/WEarzRJAKvxBf9uHXx9A="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:sender:in-reply-to:references:from\n\t:date:message-id:subject:to:cc:content-transfer-encoding;\n\tbh=cn/frQqtzVpxiqJX+bfW/OtH4nOVn7FoFEr12IsZCMI=;\n\tb=pq+0G85tALB+C3DP848d24BFqm6mG0Qr0wKpx2rjJDFCkFziRUzgKufc6l31zCgMQN\n\ttMIaHpMTOyg1sEt7VmzuBMkPBwoW3JdE8pbNwlQLK0wYFuSOdFlxoMf7D/wS4QTVVVep\n\tdUaCidp1C8tFLs/UIbfY3WBDfnkCh1r1xTtvf2Ye6oSNiwHrgKfMGcCvhtZnoj8uswoC\n\t6KEyKi9TeU3vj35B9PXY/aakUoIrqvJcbj6VhXrfgO8O2wVvw/7d4mpXYUOqBnk81Yos\n\tqW9yAd79PEzozUBGHYwgxEZa6cYG0YA/G43RPO1P3l/iDdcLwWFqJR/nXVHsW3g1I4th\n\tyOQw==","X-Gm-Message-State":"AHPjjUhcsUXksUCYK6V8FejYykcPirgvhtyol9qQterqFsQnQfiF6bG3\n\t1q10ZEAkCQH9QKJuox39G3JTGhpq5HUzZ/I7+Tn3xA==","X-Google-Smtp-Source":"AOwi7QDvnS4DTCjM52D2posYNOeW8HLVJn7k5b2oWOXSPWZviZeVPfQ1gFSA3aICcTbwOodbaKOxwD+b4UkgZQ7fGk8=","X-Received":"by 10.200.63.154 with SMTP id d26mr47118693qtk.212.1505670777793;\n\tSun, 17 Sep 2017 10:52:57 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<94989b1e-b231-6e22-9065-67af1e8779a8@rock-chips.com>","References":"<1505224549-29936-1-git-send-email-andy.yan@rock-chips.com>\n\t<1505224713-30097-1-git-send-email-andy.yan@rock-chips.com>\n\t<CAPnjgZ2wYHfahmR2aXAfjrvLFJy6jG-1sXLvBDO5rXDJ-YQe6Q@mail.gmail.com>\n\t<94989b1e-b231-6e22-9065-67af1e8779a8@rock-chips.com>","From":"Simon Glass <sjg@chromium.org>","Date":"Sun, 17 Sep 2017 11:52:37 -0600","X-Google-Sender-Auth":"4tEzefv314jkMy47Pzu6QE7W88g","Message-ID":"<CAPnjgZ2423F5K+q6XfFmw8p96-NHaHnQvDpZZDCoteTE5emBkQ@mail.gmail.com>","To":"Andy Yan <andy.yan@rock-chips.com>","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>,\n\t\"David.Wu\" <david.wu@rock-chips.com>","Subject":"Re: [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 <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]