u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Johan Jonker <jbx6244@gmail.com>
To: kever.yang@rock-chips.com
Cc: sjg@chromium.org, philipp.tomsich@vrull.eu, lukma@denx.de,
	marex@denx.de, u-boot@lists.denx.de
Subject: [PATCH v1 16/17] rockchip: rk3066: add recovery mode in spl
Date: Sun,  8 May 2022 17:08:24 +0200	[thread overview]
Message-ID: <20220508150825.21711-17-jbx6244@gmail.com> (raw)
In-Reply-To: <20220508150825.21711-1-jbx6244@gmail.com>

Add a recovery button test as condition to enter the recovery mode
in spl. Run the rockusb gadget for MMC while connected to a USB host.
Allow external user defined functions by labeling these functions
as "__weak".

Signed-off-by: Johan Jonker <jbx6244@gmail.com>
---
 .../arm/include/asm/arch-rockchip/f_rockusb.h |  1 +
 arch/arm/mach-rockchip/rk3066/rk3066.c        | 86 +++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/arch/arm/include/asm/arch-rockchip/f_rockusb.h b/arch/arm/include/asm/arch-rockchip/f_rockusb.h
index e9c7f793..ab1e2c2f 100644
--- a/arch/arm/include/asm/arch-rockchip/f_rockusb.h
+++ b/arch/arm/include/asm/arch-rockchip/f_rockusb.h
@@ -8,6 +8,7 @@
 #ifndef _F_ROCKUSB_H_
 #define _F_ROCKUSB_H_
 #include <blk.h>
+#include <linux/usb/composite.h>
 
 #define ROCKUSB_VERSION		"0.1"
 
diff --git a/arch/arm/mach-rockchip/rk3066/rk3066.c b/arch/arm/mach-rockchip/rk3066/rk3066.c
index 1d1b8687..be19400c 100644
--- a/arch/arm/mach-rockchip/rk3066/rk3066.c
+++ b/arch/arm/mach-rockchip/rk3066/rk3066.c
@@ -4,9 +4,15 @@
  */
 
 #include <common.h>
+#include <adc.h>
+#include <g_dnl.h>
+#include <spl.h>
 #include <asm/io.h>
 #include <asm/arch-rockchip/bootrom.h>
 #include <asm/arch-rockchip/grf_rk3066.h>
+#include <asm/arch-rockchip/f_rockusb.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
 
 #define GRF_BASE	0x20008000
 
@@ -26,6 +32,81 @@ void board_debug_uart_init(void)
 		     GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
 }
 
+__weak void do_spl(void)
+{
+	if (CONFIG_IS_ENABLED(OF_PLATDATA))
+		return;
+
+#if IS_ENABLED(CONFIG_SPL_USB_FUNCTION_ROCKUSB)
+	char *dev_type;
+	int dev_index;
+	int ret;
+
+	switch (spl_boot_device()) {
+	case BOOT_DEVICE_MMC1:
+		dev_type = "mmc";
+		dev_index = 0;
+		break;
+	default:
+		return;
+	}
+
+	rockusb_dev_init(dev_type, dev_index);
+
+	ret = usb_gadget_initialize(0);
+	if (ret) {
+		printf("USB init failed: %d\n", ret);
+		return;
+	}
+
+	g_dnl_clear_detach();
+	ret = g_dnl_register("usb_dnl_rockusb");
+	if (ret)
+		return;
+
+	if (!g_dnl_board_usb_cable_connected()) {
+		printf("\rUSB cable not detected\n");
+		goto exit;
+	}
+
+	while (1) {
+		if (g_dnl_detach())
+			break;
+		if (ctrlc())
+			break;
+		usb_gadget_handle_interrupts(0);
+	}
+
+exit:
+	g_dnl_unregister();
+	g_dnl_clear_detach();
+	usb_gadget_release(0);
+#endif
+	return;
+}
+
+#define KEY_DOWN_MIN_VAL	0
+#define KEY_DOWN_MAX_VAL	30
+
+__weak int rockchip_dnl_key_pressed(void)
+{
+#if IS_ENABLED(CONFIG_SPL_SARADC_ROCKCHIP)
+	unsigned int val;
+	int ret;
+
+	ret = adc_channel_single_shot("saradc@2006c000", 1, &val);
+
+	if (ret) {
+		printf("Read adc key val failed\n");
+		return false;
+	}
+
+	if (val >= KEY_DOWN_MIN_VAL && val <= KEY_DOWN_MAX_VAL)
+		return true;
+#endif
+	return false;
+}
+
 void spl_board_init(void)
 {
 	__maybe_unused struct rk3066_grf * const grf = (void *)GRF_BASE;
@@ -49,4 +130,9 @@ void spl_board_init(void)
 			     GPIO3B5_SDMMC0_DATA3  << GPIO3B5_SHIFT |
 			     GPIO3B6_SDMMC0_DECTN  << GPIO3B6_SHIFT);
 	}
+
+	if (rockchip_dnl_key_pressed()) {
+		printf("Recovery button was pressed!\n");
+		do_spl();
+	}
 }
-- 
2.20.1


  parent reply	other threads:[~2022-05-08 15:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-08 15:08 [PATCH v1 00/17] Add rk3066 ADC and USB support Johan Jonker
2022-05-08 15:08 ` [PATCH v1 01/17] rockchip: spl: fix reloc gd and FDT blob pointer Johan Jonker
2022-05-08 15:08 ` [PATCH v1 02/17] rockchip: spl: allow more boot devices Johan Jonker
2022-05-08 15:08 ` [PATCH v1 03/17] rockchip: spl-boot-order: add usb boot option Johan Jonker
2022-05-08 15:08 ` [PATCH v1 04/17] rockchip: board: allow spl compile for usb init functions Johan Jonker
2022-05-08 15:08 ` [PATCH v1 05/17] rockchip: usb: gadget: rockusb: enable spl compile Johan Jonker
2022-05-08 15:08 ` [PATCH v1 06/17] rockchip: configs: mk808: add spl usb configs Johan Jonker
2022-05-08 15:08 ` [PATCH v1 07/17] arm: dts: rockchip: mk808: add adc usb required properties for spl Johan Jonker
2022-05-08 15:08 ` [PATCH v1 08/17] rockchip: adc: enable spl compile class driver Johan Jonker
2022-05-08 15:08 ` [PATCH v1 09/17] rockchip: adc: reduce error notifications from " Johan Jonker
2022-05-08 15:08 ` [PATCH v1 10/17] rockchip: adc: enable spl compile rockchip-saradc driver Johan Jonker
2022-05-08 15:08 ` [PATCH v1 11/17] rockchip: adc: fix adc timer Johan Jonker
2022-05-08 15:08 ` [PATCH v1 12/17] rockchip: adc: fix the hangups Johan Jonker
2022-05-08 15:08 ` [PATCH v1 13/17] rockchip: adc: make adc branch compile in SPL Johan Jonker
2022-05-08 15:08 ` [PATCH v1 14/17] rockchip: adc: move config items in a sub menu Johan Jonker
2022-05-08 15:08 ` [PATCH v1 15/17] rockchip: rk3066: config nand data pins in spl Johan Jonker
2022-05-08 15:08 ` Johan Jonker [this message]
2022-05-08 15:08 ` [PATCH v1 17/17] rockchip: configs: mk808: enable usb support Johan Jonker

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=20220508150825.21711-17-jbx6244@gmail.com \
    --to=jbx6244@gmail.com \
    --cc=kever.yang@rock-chips.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).