diff mbox series

[U-Boot,v3,3/3] rockchip: check download key before bootup

Message ID 1507705291-10777-1-git-send-email-andy.yan@rock-chips.com
State Accepted
Delegated to: Philipp Tomsich
Headers show
Series Most rockchip platform based boards use a key to instruct | expand

Commit Message

Andy Yan Oct. 11, 2017, 7:01 a.m. UTC
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(+)

Comments

Philipp Tomsich Nov. 20, 2017, 2:06 p.m. UTC | #1
> 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(+)
> 

Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Philipp Tomsich Nov. 20, 2017, 2:51 p.m. UTC | #2
On Wed, 11 Oct 2017, Andy Yan wrote:

> Enter download mode if the download key pressed.
>
> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>

Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>

See below for requested changes.

> ---
>
> 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__);

This should be a pr_debug() or pr_err().
Thanks.

> +		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 */
>
Andy Yan Nov. 21, 2017, 1:02 a.m. UTC | #3
Hi Philipp:


On 2017年11月20日 22:51, Philipp Tomsich wrote:
>
>
> On Wed, 11 Oct 2017, Andy Yan wrote:
>
>> Enter download mode if the download key pressed.
>>
>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
>> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
>
> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
>
> See below for requested changes.
>
>> ---
>>
>> 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__);
>
> This should be a pr_debug() or pr_err().

     Okay, I will update it.
> Thanks.
>
>> +        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 */
>>
>
>
>
Philipp Tomsich Nov. 21, 2017, 12:31 p.m. UTC | #4
Andy,

> On 21 Nov 2017, at 02:02, Andy Yan <andy.yan@rock-chips.com> wrote:
> 
> Hi Philipp:
> 
> 
> On 2017年11月20日 22:51, Philipp Tomsich wrote:
>> 
>> 
>> On Wed, 11 Oct 2017, Andy Yan wrote:
>> 
>>> Enter download mode if the download key pressed.
>>> 
>>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
>>> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
>> 
>> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
>> 
>> See below for requested changes.
>> 
>>> ---
>>> 
>>> 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__);
>> 
>> This should be a pr_debug() or pr_err().
> 
>     Okay, I will update it.

Never mind. I’ll change this to a pr_err() when I commit.

>> Thanks.
>> 
>>> +        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 */
Philipp Tomsich Nov. 21, 2017, 10:32 p.m. UTC | #5
> Enter download mode if the download key pressed.
> 
> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.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(+)
> 

Applied to u-boot-rockchip, thanks!
diff mbox series

Patch

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 */