public inbox for rulkc@linuxtesting.org
 help / color / mirror / Atom feed
From: avkrasnov at salutedevices.com (Arseniy Krasnov)
Subject: [rulkc] [PATCH v1 01/11] arch: arm: meson: sm: add commands to reboot device in different modes
Date: Tue, 29 Jul 2025 21:29:00 +0300	[thread overview]
Message-ID: <20250729182910.16127-2-avkrasnov@salutedevices.com> (raw)
In-Reply-To: <20250729182910.16127-1-avkrasnov@salutedevices.com>

From: Vladimir Mitrofanov <vvmitrofanov at salutedevices.com>

There are several commands to reboot device in specific mode
(cold, normal, etc.), these commands helps to enter flashing mode
and set boot source device:

1) MESON_SMC_CMD_BL1_FIRST_BOOT_SRC_SET

  This command tells BL1 that it must load BL2 from USB data path. It is
  used in ADNL protocol logic when burning process is started from the
  U-Boot command line: when 'adnl' is entered, this command tells BL1 to
  load BL2 from USB, then board is rebooted. After reboot BL2 and next
  stage loaders will be loaded from USB, sticky register has value that
  we are in ADNL mode, thus booted U-Boot enters ADNL mode to start data
  burning.

  Used in adnl-based SoC families: a1, s4, c1, с2, sc2, t7, etc.

2) MESON_SMC_CMD_REBOOT_MODE_SET
  Used in optimus-based SoC families: axg, g12a, g12b, sm1, etc.

3) MESON_SMC_CMD_USB_BOOT_MODE_SET
  Used in optimus-based SoC families: axg, g12a, g12b, sm1, etc.

Signed-off-by: Arseniy Krasnov <avkrasnov at salutedevices.com>
Signed-off-by: Vladimir Mitrofanov <vvmitrofanov at salutedevices.com>
Signed-off-by: Evgeny Bachinin <EABachinin at salutedevices.com>
---
 arch/arm/include/asm/arch-meson/sm.h | 98 +++++++++++++++++++++++++++-
 arch/arm/mach-meson/sm.c             | 39 +++++++++++
 drivers/sm/meson-sm.c                |  3 +
 include/meson/sm.h                   |  3 +
 4 files changed, 142 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-meson/sm.h b/arch/arm/include/asm/arch-meson/sm.h
index 4d614955fc2..087f8b4d5fa 100644
--- a/arch/arm/include/asm/arch-meson/sm.h
+++ b/arch/arm/include/asm/arch-meson/sm.h
@@ -83,7 +83,7 @@ int meson_sm_get_serial(void *buffer, size_t size);
  */
 int meson_sm_get_chip_id(struct meson_sm_chip_id *chip_id);
 
-enum {
+enum meson_reboot_mode {
 	REBOOT_REASON_COLD = 0,
 	REBOOT_REASON_NORMAL = 1,
 	REBOOT_REASON_RECOVERY = 2,
@@ -134,4 +134,100 @@ int meson_sm_pwrdm_set(size_t index, int cmd);
 #define meson_sm_pwrdm_on(index) \
 	meson_sm_pwrdm_set(index, PWRDM_ON)
 
+/*
+ * Below is the list of SCPI_CMD commands, issued by U-Boot and passed to SCP
+ * co-processor via SMC to BL31 (TF-A). BL31 routes these commands to SCP
+ * via mailbox.
+ *
+ * Commands instruct the SCP how to set/control POC pins in order to choose
+ * first boot source, specified by the particular command below. These POC pins
+ * are readable by BootROM and used to determine the boot sequence. Usually,
+ * the normal default boot sequence, seen on production device is
+ *     NAND/eMMC -> SD -> USB
+ *
+ * Commands below change the first boot source.
+ *
+ * NOTE:
+ * these commands are used along with meson_sm_set_bl1_first_boot_source() on
+ * Amlogic SoCs where ADNL burning protocol is utilized.
+ * Refer to meson_sm_set_usb_boot_mode() for the same functionality but on SoCs
+ * with Optimus burning protocol.
+ */
+
+/**
+ * define SCPI_CMD_USB_BOOT - sets the first boot source into USB with timeout
+ *
+ * Additionally, force the BootROM (BL1) to wait for the Host's enumeration
+ * with timeout
+ */
+#define SCPI_CMD_USB_BOOT 0xB0
+
+/**
+ * define SCPI_CMD_USB_UNBOOT - sets the first boot source into USB w/o timeout
+ *
+ * Additionally, force the BootROM to wait for the Host's enumeration with
+ * uninterruptible wait, i.e. forever
+ */
+#define SCPI_CMD_USB_UNBOOT 0xB1
+
+/**
+ * define SCPI_CMD_SDCARD_BOOT - sets the first boot source into SD card
+ */
+#define SCPI_CMD_SDCARD_BOOT 0xB2
+
+/**
+ * define SCPI_CMD_CLEAR_BOOT - sets the first boot source into default one
+ *
+ * BootROM follows a pre-defined boot sequence stored in SoC ROM code.
+ */
+#define SCPI_CMD_CLEAR_BOOT 0xB3
+
+/**
+ * meson_sm_set_bl1_first_boot_source - sets the first boot source for BootROM.
+ * @cmd: command to set first boot source visible to BootROM during boot.
+ *       Use SCPI_CMD_* as commands.
+ *
+ * BootROM checks POC-pins (POC0, POC1, POC2) to determine in which order it
+ * must probe the various methods of booting the system. The order is usually
+ * pre-defined. But function changes the first boot source of that pre-defined
+ * order.
+ *
+ * @return: zero on success or error code on failure.
+ */
+int meson_sm_set_bl1_first_boot_source(u64 cmd);
+
+/**
+ * meson_sm_reboot - reboots device in a appropriate mode
+ * All possible modes described in &enum meson_reboot_mode
+ *
+ * @mode: reboot mode.
+ * @return: zero on success or error code on failure.
+ */
+int meson_sm_reboot(u64 mode);
+
+/**
+ * enum meson_usb_boot_mode - modes for meson_sm_set_usb_boot_mode()
+ * @FORCE_USB_BOOT: Forces BootROM to boot with firmware transferred by PC
+ * 		    burning tool via USB. This mode has influence despite of the
+ * 		    previously selected boot source. This mode persists between
+ * 		    reboots and must be cleared.
+ * @CLEAR_USB_BOOT: Clears previous mode.
+ *
+ * These modes are used in conjunction with meson_sm_set_usb_boot_mode() on
+ * Amlogic SoCs where Optimus burning protocol is utilized.
+ */
+enum meson_usb_boot_mode {
+	CLEAR_USB_BOOT = 1,
+	FORCE_USB_BOOT = 2,
+};
+
+/**
+ * meson_sm_set_usb_boot_mode - sets the mode of usb interface that will be used during boot
+ * All possible modes described in &enum meson_usb_boot_mode
+ *
+ * @mode: reboot mode.
+ * @return: zero on success or error code on failure.
+ */
+int meson_sm_set_usb_boot_mode(u64 mode);
+
 #endif /* __MESON_SM_H__ */
diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c
index b1f91ca29ce..53b07e1dfe9 100644
--- a/arch/arm/mach-meson/sm.c
+++ b/arch/arm/mach-meson/sm.c
@@ -236,6 +236,17 @@ int meson_sm_get_reboot_reason(void)
 	return FIELD_GET(REBOOT_REASON_MASK, reason);
 }
 
+static int meson_sm_call(u32 smc, struct pt_regs *regs, s32 *retval)
+{
+	struct udevice *dev;
+
+	dev = meson_get_sm_device();
+	if (IS_ERR(dev))
+		return PTR_ERR(dev);
+
+	return sm_call(dev, smc, retval, regs);
+}
+
 int meson_sm_pwrdm_set(size_t index, int cmd)
 {
 	struct udevice *dev;
@@ -256,3 +267,31 @@ int meson_sm_pwrdm_set(size_t index, int cmd)
 
 	return err;
 }
+
+int meson_sm_set_bl1_first_boot_source(u64 cmd)
+{
+	struct pt_regs regs = { 0 };
+
+	regs.regs[1] = cmd;
+
+	return meson_sm_call(MESON_SMC_CMD_BL1_FIRST_BOOT_SRC_SET,
+			     &regs, NULL);
+}
+
+int meson_sm_reboot(u64 mode)
+{
+	struct pt_regs regs = { 0 };
+
+	regs.regs[1] = mode;
+
+	return meson_sm_call(MESON_SMC_CMD_REBOOT_MODE_SET, &regs, NULL);
+}
+
+int meson_sm_set_usb_boot_mode(u64 mode)
+{
+	struct pt_regs regs = { 0 };
+
+	regs.regs[1] = mode;
+
+	return meson_sm_call(MESON_SMC_CMD_USB_BOOT_MODE_SET, &regs, NULL);
+}
diff --git a/drivers/sm/meson-sm.c b/drivers/sm/meson-sm.c
index 87eba1486db..f413d8335b3 100644
--- a/drivers/sm/meson-sm.c
+++ b/drivers/sm/meson-sm.c
@@ -168,8 +168,11 @@ static const struct meson_sm_data meson_sm_gxbb_data = {
 	.cmd = {
 		SET_CMD(MESON_SMC_CMD_EFUSE_READ,  0x82000030),
 		SET_CMD(MESON_SMC_CMD_EFUSE_WRITE, 0x82000031),
+		SET_CMD(MESON_SMC_CMD_USB_BOOT_MODE_SET, 0x82000043),
 		SET_CMD(MESON_SMC_CMD_CHIP_ID_GET, 0x82000044),
+		SET_CMD(MESON_SMC_CMD_BL1_FIRST_BOOT_SRC_SET, 0x82000087),
 		SET_CMD(MESON_SMC_CMD_PWRDM_SET,   0x82000093),
+		SET_CMD(MESON_SMC_CMD_REBOOT_MODE_SET, 0x84000009),
 	},
 };
 
diff --git a/include/meson/sm.h b/include/meson/sm.h
index fbaab1f1ee0..b9621f95cbe 100644
--- a/include/meson/sm.h
+++ b/include/meson/sm.h
@@ -13,6 +13,9 @@ enum meson_smc_cmd {
 	MESON_SMC_CMD_EFUSE_WRITE, /* write efuse memory */
 	MESON_SMC_CMD_CHIP_ID_GET, /* readh chip unique id */
 	MESON_SMC_CMD_PWRDM_SET,   /* do command at specified power domain */
+	MESON_SMC_CMD_BL1_FIRST_BOOT_SRC_SET, /* setup first boot source for BootROM */
+	MESON_SMC_CMD_REBOOT_MODE_SET, /* Reboot device in desired mode */
+	MESON_SMC_CMD_USB_BOOT_MODE_SET, /* Run boot from USB device */
 	MESON_SMC_CMD_COUNT,
 };
 
-- 
2.30.1



  reply	other threads:[~2025-07-29 18:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-29 18:28 [rulkc] [PATCH v1 00/11] Amlogic: ADNL and Optimus protocols support avkrasnov
2025-07-29 18:29 ` avkrasnov [this message]
2025-07-29 18:29 ` [rulkc] [PATCH v1 02/11] arch: arm: meson: use 'meson_sm_call()' in 'meson_sm_pwrdm_set()' avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 03/11] usb: gadget: fastboot: make part of USB fastboot code shared avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 04/11] usb: gadget: amlogic: common code for Amlogic flashing commands avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 05/11] mtd: rawnand: meson: move some defines to dedicated header avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 06/11] arch: arm: meson: bootloader write support avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 07/11] arm: meson: a1: add A1_SYSCTRL_SEC_STICKY_REG2 avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 08/11] usb: gadget: amlogic: implement ADNL protocol avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 09/11] arm: meson: a1: ADNL protocol support avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 10/11] usb: gadget: amlogic: implement Optimus protocol avkrasnov
2025-07-29 18:29 ` [rulkc] [PATCH v1 11/11] arch: arm: axg: Optimus protocol support avkrasnov
2025-07-31  1:07 ` [rulkc] [PATCH v1 00/11] Amlogic: ADNL and Optimus protocols support slava

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=20250729182910.16127-2-avkrasnov@salutedevices.com \
    --to=rulkc@linuxtesting.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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

all inboxes | Powered by JetHome®