Skip to contentSkip to conversation

add 'poweroff' support

PATCH In review Antony Pavlov 2 participants 6 messages Jun 13, 2012 – Jun 25, 2012 MIPS

lore
Share & tools
lore
#0 lore raw

This patch series adds the ability to turn power off on Ritmix RZX-50 game console.

The Ritmix RZX-50 game console is a battery-powered device. So I you keep it running barebox it can to use up the battery in 14-16 hours. So it is very desirable to be able to turn power off from barebox.

[PATCH 1/2] add 'poweroff' command
[PATCH 2/2] rzx50: add poweroff support

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/2 add 'poweroff' command

---
 commands/Kconfig    |    9 +++++++++
 commands/Makefile   |    1 +
 commands/poweroff.c |   37 +++++++++++++++++++++++++++++++++++++
 include/common.h    |    1 +
 4 files changed, 48 insertions(+)
 create mode 100644 commands/poweroff.c
commands/Kconfig +9 -0
index 52e1f17..e9f6e25 100644
@@ -6,6 +6,10 @@ config COMMAND_SUPPORT
 	depends on !SHELL_NONE
 	default y
 
+config HAS_POWEROFF
+	bool
+	default n
+
 if COMMAND_SUPPORT
 
 menu "commands                      "
@@ -422,6 +426,11 @@ config CMD_RESET
 	tristate
 	prompt "reset"
 
+config CMD_POWEROFF
+	tristate
+	depends on HAS_POWEROFF
+	prompt "poweroff"
+
 config CMD_GO
 	tristate
 	prompt "go"
commands/Makefile +1 -0
index d39c466..ad3480c 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
 obj-$(CONFIG_CMD_RESET)		+= reset.o
+obj-$(CONFIG_CMD_POWEROFF)	+= poweroff.o
 obj-$(CONFIG_CMD_GO)		+= go.o
 obj-$(CONFIG_NET)		+= net.o
 obj-$(CONFIG_CMD_PARTITION)	+= partition.o
commands/poweroff.c new file +37 -0
new file mode 100644
index 0000000..cd5542b
@@ -0,0 +1,37 @@
+/*
+ * poweroff.c - turn board's power off
+ *
+ * Copyright (C) 2011 Antony Pavlov <[email protected]>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int cmd_poweroff(struct command *cmdtp, int argc, char *argv[])
+{
+	poweroff();
+
+	/* Not reached */
+	return 1;
+}
+
+BAREBOX_CMD_START(poweroff)
+	.cmd		= cmd_poweroff,
+	.usage		= "Perform POWER OFF of the board",
+BAREBOX_CMD_END
include/common.h +1 -0
index d2347f8..9745aeb 100644
@@ -102,6 +102,7 @@ long	get_ram_size  (volatile long *, long);
 
 /* $(CPU)/cpu.c */
 void __noreturn reset_cpu(unsigned long addr);
+void __noreturn poweroff(void);
 
 /* lib_$(ARCH)/time.c */
 void	udelay (unsigned long);
Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/2 rzx50: add poweroff support

In reply to Antony Pavlov
---
 arch/mips/mach-xburst/Kconfig                     |    1 +
 arch/mips/mach-xburst/include/mach/jz4750d_regs.h |   31 +++++++++++++++++++++
 arch/mips/mach-xburst/reset-jz4750.c              |   28 +++++++++++++++++++
 3 files changed, 60 insertions(+)
arch/mips/mach-xburst/Kconfig +1 -0
index 60e411c..c72b741 100644
@@ -12,6 +12,7 @@ choice
 
 config BOARD_RZX50
 	bool "Ritmix RZX-50"
+	select HAS_POWEROFF
 	select CPU_JZ4755
 
 endchoice
arch/mips/mach-xburst/include/mach/jz4750d_regs.h +31 -0
index 717493b..eafdd2f 100644
@@ -15,6 +15,7 @@
 
 #define TCU_BASE        0xb0002000
 #define WDT_BASE        0xb0002000
+#define RTC_BASE        0xb0003000
 #define UART1_BASE      0xb0031000
 
 /*************************************************************************
@@ -77,4 +78,34 @@
 
 #define WDT_TCER_TCEN		(1 << 0)
 
+/*************************************************************************
+ * RTC
+ *************************************************************************/
+#define RTC_RCR		(RTC_BASE + 0x00) /* RTC Control Register */
+#define RTC_RSR		(RTC_BASE + 0x04) /* RTC Second Register */
+#define RTC_RSAR	(RTC_BASE + 0x08) /* RTC Second Alarm Register */
+#define RTC_RGR		(RTC_BASE + 0x0c) /* RTC Regulator Register */
+
+#define RTC_HCR		(RTC_BASE + 0x20) /* Hibernate Control Register */
+#define RTC_HWFCR	(RTC_BASE + 0x24) /* Hibernate Wakeup Filter Counter Reg */
+#define RTC_HRCR	(RTC_BASE + 0x28) /* Hibernate Reset Counter Register */
+#define RTC_HWCR	(RTC_BASE + 0x2c) /* Hibernate Wakeup Control Register */
+#define RTC_HWRSR	(RTC_BASE + 0x30) /* Hibernate Wakeup Status Register */
+#define RTC_HSPR	(RTC_BASE + 0x34) /* Hibernate Scratch Pattern Register */
+
+/* RTC Control Register */
+#define RTC_RCR_WRDY_BIT 7
+#define RTC_RCR_WRDY	(1 << 7)  /* Write Ready Flag */
+#define RTC_RCR_1HZ_BIT	6
+#define RTC_RCR_1HZ	(1 << RTC_RCR_1HZ_BIT)  /* 1Hz Flag */
+#define RTC_RCR_1HZIE	(1 << 5)  /* 1Hz Interrupt Enable */
+#define RTC_RCR_AF_BIT	4
+#define RTC_RCR_AF	(1 << RTC_RCR_AF_BIT)  /* Alarm Flag */
+#define RTC_RCR_AIE	(1 << 3)  /* Alarm Interrupt Enable */
+#define RTC_RCR_AE	(1 << 2)  /* Alarm Enable */
+#define RTC_RCR_RTCE	(1 << 0)  /* RTC Enable */
+
+/* Hibernate Control Register */
+#define RTC_HCR_PD		(1 << 0)  /* Power Down */
+
 #endif /* __JZ4750D_REGS_H__ */
arch/mips/mach-xburst/reset-jz4750.c +28 -0
index 3540ca9..4bda56c 100644
@@ -29,6 +29,19 @@
 
 #define JZ_EXTAL 24000000
 
+static void jz4750d_halt(void)
+{
+	while (1) {
+		__asm__(".set push;\n"
+			".set mips3;\n"
+			"wait;\n"
+			".set pop;\n"
+		);
+	}
+
+	unreachable();
+}
+
 void __noreturn reset_cpu(ulong addr)
 {
 	__raw_writew(WDT_TCSR_PRESCALE4 | WDT_TCSR_EXT_EN, (u16 *)WDT_TCSR);
@@ -44,3 +57,18 @@ void __noreturn reset_cpu(ulong addr)
 	unreachable();
 }
 EXPORT_SYMBOL(reset_cpu);
+
+void __noreturn poweroff()
+{
+	u32 ctrl;
+
+	shutdown_barebox();
+
+	do {
+		ctrl = readl(RTC_RCR);
+	} while (!(ctrl & RTC_RCR_WRDY));
+
+	writel(RTC_HCR_PD, RTC_HCR);
+	jz4750d_halt();
+}
+EXPORT_SYMBOL(poweroff);
Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#5 lore raw
In reply to Antony Pavlov
Quoted 10 lines · Antony Pavlov

This patch series adds the ability to turn power off on Ritmix RZX-50 game console.

The Ritmix RZX-50 game console is a battery-powered device. So I you keep it running barebox it can to use up the battery in 14-16 hours. So it is very desirable to be able to turn power off from barebox.

[PATCH 1/2] add 'poweroff' command
[PATCH 2/2] rzx50: add poweroff support

Applied, thanks

Sascha

Quoted 6 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/2] rzx50: add poweroff support

In reply to Antony Pavlov

Hi Antony,

This patch introduces some new build warnings in rx50_defconfig. Could you fix these?

arch/mips/mach-xburst/reset-jz4750.c: In function 'poweroff':
arch/mips/mach-xburst/reset-jz4750.c:68: warning: passing argument 1 of '__raw_readl' makes pointer from integer without a cast arch/mips/mach-xburst/reset-jz4750.c:71: warning: passing argument 2 of '__raw_writel' makes pointer from integer without a cast arch/mips/mach-xburst/reset-jz4750.c:73: warning: 'noreturn' function does return

Thanks
Sascha

Quoted 118 lines · Antony Pavlov
---
 arch/mips/mach-xburst/Kconfig                     |    1 +
 arch/mips/mach-xburst/include/mach/jz4750d_regs.h |   31 +++++++++++++++++++++
 arch/mips/mach-xburst/reset-jz4750.c              |   28 +++++++++++++++++++
 3 files changed, 60 insertions(+)
arch/mips/mach-xburst/Kconfig +1 -0
index 60e411c..c72b741 100644
@@ -12,6 +12,7 @@ choice
 
 config BOARD_RZX50
 	bool "Ritmix RZX-50"
+	select HAS_POWEROFF
 	select CPU_JZ4755
 
 endchoice
arch/mips/mach-xburst/include/mach/jz4750d_regs.h +31 -0
index 717493b..eafdd2f 100644
@@ -15,6 +15,7 @@
 
 #define TCU_BASE        0xb0002000
 #define WDT_BASE        0xb0002000
+#define RTC_BASE        0xb0003000
 #define UART1_BASE      0xb0031000
 
 /*************************************************************************
@@ -77,4 +78,34 @@
 
 #define WDT_TCER_TCEN		(1 << 0)
 
+/*************************************************************************
+ * RTC
+ *************************************************************************/
+#define RTC_RCR		(RTC_BASE + 0x00) /* RTC Control Register */
+#define RTC_RSR		(RTC_BASE + 0x04) /* RTC Second Register */
+#define RTC_RSAR	(RTC_BASE + 0x08) /* RTC Second Alarm Register */
+#define RTC_RGR		(RTC_BASE + 0x0c) /* RTC Regulator Register */
+
+#define RTC_HCR		(RTC_BASE + 0x20) /* Hibernate Control Register */
+#define RTC_HWFCR	(RTC_BASE + 0x24) /* Hibernate Wakeup Filter Counter Reg */
+#define RTC_HRCR	(RTC_BASE + 0x28) /* Hibernate Reset Counter Register */
+#define RTC_HWCR	(RTC_BASE + 0x2c) /* Hibernate Wakeup Control Register */
+#define RTC_HWRSR	(RTC_BASE + 0x30) /* Hibernate Wakeup Status Register */
+#define RTC_HSPR	(RTC_BASE + 0x34) /* Hibernate Scratch Pattern Register */
+
+/* RTC Control Register */
+#define RTC_RCR_WRDY_BIT 7
+#define RTC_RCR_WRDY	(1 << 7)  /* Write Ready Flag */
+#define RTC_RCR_1HZ_BIT	6
+#define RTC_RCR_1HZ	(1 << RTC_RCR_1HZ_BIT)  /* 1Hz Flag */
+#define RTC_RCR_1HZIE	(1 << 5)  /* 1Hz Interrupt Enable */
+#define RTC_RCR_AF_BIT	4
+#define RTC_RCR_AF	(1 << RTC_RCR_AF_BIT)  /* Alarm Flag */
+#define RTC_RCR_AIE	(1 << 3)  /* Alarm Interrupt Enable */
+#define RTC_RCR_AE	(1 << 2)  /* Alarm Enable */
+#define RTC_RCR_RTCE	(1 << 0)  /* RTC Enable */
+
+/* Hibernate Control Register */
+#define RTC_HCR_PD		(1 << 0)  /* Power Down */
+
 #endif /* __JZ4750D_REGS_H__ */
arch/mips/mach-xburst/reset-jz4750.c +28 -0
index 3540ca9..4bda56c 100644
@@ -29,6 +29,19 @@
 
 #define JZ_EXTAL 24000000
 
+static void jz4750d_halt(void)
+{
+	while (1) {
+		__asm__(".set push;\n"
+			".set mips3;\n"
+			"wait;\n"
+			".set pop;\n"
+		);
+	}
+
+	unreachable();
+}
+
 void __noreturn reset_cpu(ulong addr)
 {
 	__raw_writew(WDT_TCSR_PRESCALE4 | WDT_TCSR_EXT_EN, (u16 *)WDT_TCSR);
@@ -44,3 +57,18 @@ void __noreturn reset_cpu(ulong addr)
 	unreachable();
 }
 EXPORT_SYMBOL(reset_cpu);
+
+void __noreturn poweroff()
+{
+	u32 ctrl;
+
+	shutdown_barebox();
+
+	do {
+		ctrl = readl(RTC_RCR);
+	} while (!(ctrl & RTC_RCR_WRDY));
+
+	writel(RTC_HCR_PD, RTC_HCR);
+	jz4750d_halt();
+}
+EXPORT_SYMBOL(poweroff);
Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 2/2] rzx50: add poweroff support

Ok, I'll fix it in a few hours.

Quoted 137 lines · Sascha Hauer

Hi Antony,

This patch introduces some new build warnings in rx50_defconfig. Could you fix these?

arch/mips/mach-xburst/reset-jz4750.c: In function 'poweroff':
arch/mips/mach-xburst/reset-jz4750.c:68: warning: passing argument 1 of '__raw_readl' makes pointer from integer without a cast arch/mips/mach-xburst/reset-jz4750.c:71: warning: passing argument 2 of '__raw_writel' makes pointer from integer without a cast arch/mips/mach-xburst/reset-jz4750.c:73: warning: 'noreturn' function does return

Thanks
 Sascha

Quoted 113 lines · Antony Pavlov

---
 arch/mips/mach-xburst/Kconfig                     |    1 + arch/mips/mach-xburst/include/mach/jz4750d_regs.h |   31 +++++++++++++++++++++ arch/mips/mach-xburst/reset-jz4750.c              |   28 +++++++++++++++++++

 3 files changed, 60 insertions(+)
arch/mips/mach-xburst/Kconfig +0 -0
index 60e411c..c72b741 100644
@@ -12,6 +12,7 @@ choice
 

 config BOARD_RZX50
      bool "Ritmix RZX-50"
+     select HAS_POWEROFF
      select CPU_JZ4755

 endchoice

arch/mips/mach-xburst/include/mach/jz4750d_regs.h +31 -0
index 717493b..eafdd2f 100644
@@ -15,6 +15,7 @@
 
  #define TCU_BASE        0xb0002000
  #define WDT_BASE        0xb0002000
+#define RTC_BASE        0xb0003000
  #define UART1_BASE      0xb0031000
 
  /*************************************************************************
@@ -77,4 +78,34 @@
 
  #define WDT_TCER_TCEN                (1 << 0)
 
+/*************************************************************************
+ * RTC
+ *************************************************************************/
+#define RTC_RCR              (RTC_BASE + 0x00) /* RTC Control Register */
+#define RTC_RSR              (RTC_BASE + 0x04) /* RTC Second Register */
+#define RTC_RSAR     (RTC_BASE + 0x08) /* RTC Second Alarm Register */
+#define RTC_RGR              (RTC_BASE + 0x0c) /* RTC Regulator Register */
+
+#define RTC_HCR              (RTC_BASE + 0x20) /* Hibernate Control Register */
+#define RTC_HWFCR    (RTC_BASE + 0x24) /* Hibernate Wakeup Filter Counter Reg */
+#define RTC_HRCR     (RTC_BASE + 0x28) /* Hibernate Reset Counter Register */
+#define RTC_HWCR     (RTC_BASE + 0x2c) /* Hibernate Wakeup Control Register */
+#define RTC_HWRSR    (RTC_BASE + 0x30) /* Hibernate Wakeup Status Register */
+#define RTC_HSPR     (RTC_BASE + 0x34) /* Hibernate Scratch Pattern Register */
+
+/* RTC Control Register */
+#define RTC_RCR_WRDY_BIT 7
+#define RTC_RCR_WRDY (1 << 7)  /* Write Ready Flag */
+#define RTC_RCR_1HZ_BIT      6
+#define RTC_RCR_1HZ  (1 << RTC_RCR_1HZ_BIT)  /* 1Hz Flag */
+#define RTC_RCR_1HZIE        (1 << 5)  /* 1Hz Interrupt Enable */
+#define RTC_RCR_AF_BIT       4
+#define RTC_RCR_AF   (1 << RTC_RCR_AF_BIT)  /* Alarm Flag */
+#define RTC_RCR_AIE  (1 << 3)  /* Alarm Interrupt Enable */
+#define RTC_RCR_AE   (1 << 2)  /* Alarm Enable */
+#define RTC_RCR_RTCE (1 << 0)  /* RTC Enable */
+
+/* Hibernate Control Register */
+#define RTC_HCR_PD           (1 << 0)  /* Power Down */
+
  #endif /* __JZ4750D_REGS_H__ */
arch/mips/mach-xburst/reset-jz4750.c +28 -1
index 3540ca9..4bda56c 100644
@@ -29,6 +29,19 @@
 
  #define JZ_EXTAL 24000000
 
+static void jz4750d_halt(void)
+{
+     while (1) {
+             __asm__(".set push;\n"
+                     ".set mips3;\n"
+                     "wait;\n"
+                     ".set pop;\n"
+             );
+     }
+
+     unreachable();
+}
+
  void __noreturn reset_cpu(ulong addr)
  {
       __raw_writew(WDT_TCSR_PRESCALE4 | WDT_TCSR_EXT_EN, (u16 *)WDT_TCSR);
@@ -44,3 +57,18 @@ void __noreturn reset_cpu(ulong addr)
       unreachable();
  }
  EXPORT_SYMBOL(reset_cpu);
+
+void __noreturn poweroff()
+{
+     u32 ctrl;
+
+     shutdown_barebox();
+
+     do {
+             ctrl = readl(RTC_RCR);
+     } while (!(ctrl & RTC_RCR_WRDY));
+
+     writel(RTC_HCR_PD, RTC_HCR);
+     jz4750d_halt();
+}
+EXPORT_SYMBOL(poweroff);
--

1.7.10

Quoted 5 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

--
Pengutronix e.K.                           |                             | Industrial Linux Solutions                 | http://www.pengutronix.de/  | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    | Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox