From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E856C433EF for ; Sun, 8 May 2022 15:17:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8759583C0C; Sun, 8 May 2022 17:17:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J5QgA1+n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C065083C0C; Sun, 8 May 2022 17:17:49 +0200 (CEST) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 79AE083F35 for ; Sun, 8 May 2022 17:08:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jbx6244@gmail.com Received: by mail-ed1-x533.google.com with SMTP id g20so13625271edw.6 for ; Sun, 08 May 2022 08:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KmRa2pboOc8qdGDQz2rvGpQtjDRXOPRT+lIjeEZoEfs=; b=J5QgA1+nWCYx2titobvadIVHPWoXpIC4y/vldVS+1N0gUgNGdkGi2nS1wA5SWzmFwN gHp1JOhurrtXTmKyoNYDT8uvUpfnP0AP/TG6fLEnTJPVJzLYAv05CGFYqP4DC683EhM6 Xknw2iiXhZ420LwCpvELipi0ZIGwkhpPwYauD2GJqg+B4kUHWVjwCBlRAaiKtnoS3nxw xlduUBSxBwMxwp+onsQ2tq/K32eHEYWp2Ul1IIyMWZClle4aOO14SSWd1KU+b4IbHzxi Usub+NmXie557XSFa27sg5jPAVNVbZ7DvuGx7mt4sWdoYMCgH+TduuqI/l9JjS03ZDmd pq4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KmRa2pboOc8qdGDQz2rvGpQtjDRXOPRT+lIjeEZoEfs=; b=V4RKrDqFyaXwClH2zzgiKrrd8YzENAUAERk9AUrLcBUwBo9JHIoCZdPrCuQoZ4whFa 3AjgMshH2navIENm9G4v3X+thVr2wKBtJa30kNIc8JD7nzeCPaMvbp/pWABO9tvPcvR+ 7YStIaJYotPO4LmFz0nziMSogjT9c/lDkOzpxWs7+7uj/rwgdIs6LS3NjdrYglpMDJyW X1dI5mSNcd9CkV30PqT/hgUIWJy2b0sLyEFwR4dRDzmQ1narBZ5ZzPm4pX8HsBrQUj55 Kk29otjPvhN+iP60H4BlLCCeAHc5rBp+Ef90d38P7J5Z/h4+VMRooVRiXjqmqEWaghF6 AA+Q== X-Gm-Message-State: AOAM530r7EWGpOVnYuQ7Z5UAVtCh13HQ/N4xoKVbgzlyeQ8+lPWNHeC3 vHSzX7RTZe7E8Sh3wDLpR2XOLg3+BRw= X-Google-Smtp-Source: ABdhPJx7A/rI0Eqky7jmsaJaP9qGtuOeb1KmCzOriY9AYDe7C+LTdfS8UkljsTMOORkqVrLXE4SekA== X-Received: by 2002:a05:6402:128b:b0:425:d1d7:b321 with SMTP id w11-20020a056402128b00b00425d1d7b321mr12976464edv.179.1652022523527; Sun, 08 May 2022 08:08:43 -0700 (PDT) Received: from debian.home (81-204-249-205.fixed.kpn.net. [81.204.249.205]) by smtp.gmail.com with ESMTPSA id yl26-20020a17090693fa00b006f3ef214dc2sm4102721ejb.40.2022.05.08.08.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 08:08:43 -0700 (PDT) From: Johan Jonker 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 Message-Id: <20220508150825.21711-17-jbx6244@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220508150825.21711-1-jbx6244@gmail.com> References: <20220508150825.21711-1-jbx6244@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- .../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 +#include #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 +#include +#include +#include #include #include #include +#include +#include +#include #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