[U-Boot] [PATCH] arm: Add support for poweroff via PSCI

Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com ---
arch/arm/cpu/armv8/fwcall.c | 7 +++++++ arch/arm/lib/Makefile | 1 + arch/arm/lib/poweroff.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 arch/arm/lib/poweroff.c
diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c index 7dfd27002916..af716cac4094 100644 --- a/arch/arm/cpu/armv8/fwcall.c +++ b/arch/arm/cpu/armv8/fwcall.c @@ -114,6 +114,13 @@ void __noreturn __efi_runtime psci_system_off(void) ; }
+#ifdef CONFIG_CMD_POWEROFF +void poweroff_misc(void) +{ + psci_system_off(); +} +#endif + #ifdef CONFIG_PSCI_RESET void reset_misc(void) { diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index f162c1428c85..c3d4248ba3eb 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -55,6 +55,7 @@ endif ifndef CONFIG_SYSRESET obj-y += reset.o endif +obj-$(CONFIG_CMD_POWEROFF) += poweroff.o
obj-y += cache.o ifndef CONFIG_ARM64 diff --git a/arch/arm/lib/poweroff.c b/arch/arm/lib/poweroff.c new file mode 100644 index 000000000000..956d2c06af66 --- /dev/null +++ b/arch/arm/lib/poweroff.c @@ -0,0 +1,47 @@ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger mgroeger@sysgo.de + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Alex Zuepke azu@sysgo.de + * + * (C) Copyright 2002 + * Gary Jennejohn, DENX Software Engineering, garyj@denx.de + * + * (C) Copyright 2004 + * DAVE Srl + * http://www.dave-tech.it + * http://www.wawnet.biz + * mailto:info@wawnet.biz + * + * (C) Copyright 2004 Texas Insturments + * + * (C) Copyright 2017, Xilinx Inc. + * + * Based on reset.c + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> + +__weak void poweroff_misc(void) +{ +} + +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + puts("poweroff ...\n"); + + udelay(50000); /* wait 50 ms */ + + disable_interrupts(); + + poweroff_misc(); + + /*NOTREACHED*/ + return 0; +} +

On 29 May 2017 at 01:11, Michal Simek michal.simek@xilinx.com wrote:
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com
arch/arm/cpu/armv8/fwcall.c | 7 +++++++ arch/arm/lib/Makefile | 1 + arch/arm/lib/poweroff.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 arch/arm/lib/poweroff.c
Reviewed-by: Simon Glass sjg@chromium.org
BTW I think we use printf() instead of puts() instead.

On 1.6.2017 05:11, Simon Glass wrote:
On 29 May 2017 at 01:11, Michal Simek michal.simek@xilinx.com wrote:
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com
arch/arm/cpu/armv8/fwcall.c | 7 +++++++ arch/arm/lib/Makefile | 1 + arch/arm/lib/poweroff.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 arch/arm/lib/poweroff.c
Reviewed-by: Simon Glass sjg@chromium.org
BTW I think we use printf() instead of puts() instead.
Thanks for review.
This is what was used in reset.c and normally puts is used for simple prints. If this is something what we should use then I think that will be the best to run one big sed and replace all puts by printfs and deprecate it.
Thanks, Michal

+Tom
On 31 May 2017 at 23:40, Michal Simek michal.simek@xilinx.com wrote:
On 1.6.2017 05:11, Simon Glass wrote:
On 29 May 2017 at 01:11, Michal Simek michal.simek@xilinx.com wrote:
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com
arch/arm/cpu/armv8/fwcall.c | 7 +++++++ arch/arm/lib/Makefile | 1 + arch/arm/lib/poweroff.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 arch/arm/lib/poweroff.c
Reviewed-by: Simon Glass sjg@chromium.org
BTW I think we use printf() instead of puts() instead.
Thanks for review.
This is what was used in reset.c and normally puts is used for simple prints. If this is something what we should use then I think that will be the best to run one big sed and replace all puts by printfs and deprecate it.
Tom, what do you think?
Regards, Simon

From: Michal Simek michal.simek@xilinx.com
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Simon Glass sjg@chromium.org [trini: Move all logic in to fwcall.c as other ARMs implement poweroff via PMIC] Signed-off-by: Tom Rini trini@konsulko.com --- arch/arm/cpu/armv8/fwcall.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c index 7dfd27002916..c2202675366f 100644 --- a/arch/arm/cpu/armv8/fwcall.c +++ b/arch/arm/cpu/armv8/fwcall.c @@ -1,5 +1,6 @@ /** * (C) Copyright 2014, Cavium Inc. + * (C) Copyright 2017, Xilinx Inc. * * SPDX-License-Identifier: GPL-2.0+ **/ @@ -114,6 +115,22 @@ void __noreturn __efi_runtime psci_system_off(void) ; }
+#ifdef CONFIG_CMD_POWEROFF +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + puts("poweroff ...\n"); + + udelay(50000); /* wait 50 ms */ + + disable_interrupts(); + + psci_system_off(); + + /*NOTREACHED*/ + return 0; +} +#endif + #ifdef CONFIG_PSCI_RESET void reset_misc(void) {

On 5.6.2017 17:43, Tom Rini wrote:
From: Michal Simek michal.simek@xilinx.com
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Simon Glass sjg@chromium.org [trini: Move all logic in to fwcall.c as other ARMs implement poweroff via PMIC] Signed-off-by: Tom Rini trini@konsulko.com
arch/arm/cpu/armv8/fwcall.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c index 7dfd27002916..c2202675366f 100644 --- a/arch/arm/cpu/armv8/fwcall.c +++ b/arch/arm/cpu/armv8/fwcall.c @@ -1,5 +1,6 @@ /**
- (C) Copyright 2014, Cavium Inc.
- (C) Copyright 2017, Xilinx Inc.
- SPDX-License-Identifier: GPL-2.0+
**/ @@ -114,6 +115,22 @@ void __noreturn __efi_runtime psci_system_off(void) ; }
+#ifdef CONFIG_CMD_POWEROFF +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{
- puts("poweroff ...\n");
- udelay(50000); /* wait 50 ms */
- disable_interrupts();
- psci_system_off();
- /*NOTREACHED*/
- return 0;
+} +#endif
#ifdef CONFIG_PSCI_RESET void reset_misc(void) {
Looks good to me. BTW: there was a question from Simon if we should use puts or printf.
Thanks, Michal

On Mon, Jun 05, 2017 at 05:47:11PM +0200, Michal Simek wrote:
On 5.6.2017 17:43, Tom Rini wrote:
From: Michal Simek michal.simek@xilinx.com
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Simon Glass sjg@chromium.org [trini: Move all logic in to fwcall.c as other ARMs implement poweroff via PMIC] Signed-off-by: Tom Rini trini@konsulko.com
arch/arm/cpu/armv8/fwcall.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c index 7dfd27002916..c2202675366f 100644 --- a/arch/arm/cpu/armv8/fwcall.c +++ b/arch/arm/cpu/armv8/fwcall.c @@ -1,5 +1,6 @@ /**
- (C) Copyright 2014, Cavium Inc.
- (C) Copyright 2017, Xilinx Inc.
- SPDX-License-Identifier: GPL-2.0+
**/ @@ -114,6 +115,22 @@ void __noreturn __efi_runtime psci_system_off(void) ; }
+#ifdef CONFIG_CMD_POWEROFF +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{
- puts("poweroff ...\n");
- udelay(50000); /* wait 50 ms */
- disable_interrupts();
- psci_system_off();
- /*NOTREACHED*/
- return 0;
+} +#endif
#ifdef CONFIG_PSCI_RESET void reset_misc(void) {
Looks good to me. BTW: there was a question from Simon if we should use puts or printf.
puts or printf, either way is fine. In very-much-theory we could get away with using only printf, I think, and save a tiny amount of space. Maybe. I know long ago I was pushing puts vs printf, but then it turns out to not matter, so I stopped pushing that.

On Mon, Jun 05, 2017 at 11:43:19AM -0400, Tom Rini wrote:
From: Michal Simek michal.simek@xilinx.com
Add support for calling poweroff in case of psci is wired. Based on the same solution as is used for reset.
Signed-off-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Simon Glass sjg@chromium.org [trini: Move all logic in to fwcall.c as other ARMs implement poweroff via PMIC] Signed-off-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (3)
-
Michal Simek
-
Simon Glass
-
Tom Rini