mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4 v2] add wakup source
@ 2012-10-13 13:46 Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49 ` [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13 13:46 UTC (permalink / raw)
  To: barebox

HI,

	v2:
	  update against next

	add wakeup source and amek power source human readable

The following changes since commit f0c7ee4201d56ec87c8b0deff3a481644a34bb9d:

  Merge branch 'for-next-1/karo-tx53' into next (2012-10-13 14:24:49 +0200)

are available in the git repository at:


  git://git.jcrosoft.org/barebox.git delivery/reset_source

for you to fetch changes up to f4d6ae60c34f1e01bf913e3b8166b478e1b55fb2:

  at91: add reset and wakeup source detection support (2012-10-13 13:45:02 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (4):
      reset_source: make enum and string human readable
      reset_source: add software reset as possible source
      reset_resource: add wakeup source
      at91: add reset and wakeup source detection support

 arch/arm/mach-at91/Makefile                  |    1 +
 arch/arm/mach-at91/include/mach/at91_shdwc.h |   40 ++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-at91/reset_source.c            |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/imx1.c                     |    6 +++---
 arch/arm/mach-samsung/reset_source.c         |    6 +++---
 common/reset_source.c                        |   32 +++++++++++++++++++++++++-------
 drivers/watchdog/im28wd.c                    |    6 +++---
 drivers/watchdog/imxwd.c                     |    6 +++---
 include/reset_source.h                       |   22 +++++++++++++++++-----
 9 files changed, 154 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_shdwc.h
 create mode 100644 arch/arm/mach-at91/reset_source.c

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] reset_source: make enum and string human readable
  2012-10-13 13:46 [PATCH 0/4 v2] add wakup source Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13 13:49 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 2/4] reset_source: add software reset as possible source Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13 13:49 UTC (permalink / raw)
  To: barebox

Today we need to read the code to understand it

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-imx/imx1.c             |    6 +++---
 arch/arm/mach-samsung/reset_source.c |    6 +++---
 common/reset_source.c                |   14 +++++++-------
 drivers/watchdog/im28wd.c            |    6 +++---
 drivers/watchdog/imxwd.c             |    6 +++---
 include/reset_source.h               |   10 +++++-----
 6 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/arch/arm/mach-imx/imx1.c b/arch/arm/mach-imx/imx1.c
index 18901ea..53ee788 100644
--- a/arch/arm/mach-imx/imx1.c
+++ b/arch/arm/mach-imx/imx1.c
@@ -29,13 +29,13 @@ static void imx1_detect_reset_source(void)
 
 	switch (val) {
 	case RSR_EXR:
-		set_reset_source(RESET_RST);
+		set_reset_source(RESET_RESET);
 		return;
 	case RSR_WDR:
-		set_reset_source(RESET_WDG);
+		set_reset_source(RESET_WATCHDOG);
 		return;
 	case 0:
-		set_reset_source(RESET_POR);
+		set_reset_source(RESET_POWER);
 		return;
 	default:
 		/* else keep the default 'unknown' state */
diff --git a/arch/arm/mach-samsung/reset_source.c b/arch/arm/mach-samsung/reset_source.c
index 2456e3f..e2b8808 100644
--- a/arch/arm/mach-samsung/reset_source.c
+++ b/arch/arm/mach-samsung/reset_source.c
@@ -29,21 +29,21 @@ static int s3c_detect_reset_source(void)
 	u32 reg = readl(S3C_GPIO_BASE + S3C2440_GSTATUS2);
 
 	if (reg & S3C2440_GSTATUS2_PWRST) {
-		set_reset_source(RESET_POR);
+		set_reset_source(RESET_POWER);
 		writel(S3C2440_GSTATUS2_PWRST,
 					S3C_GPIO_BASE + S3C2440_GSTATUS2);
 		return 0;
 	}
 
 	if (reg & S3C2440_GSTATUS2_SLEEPRST) {
-		set_reset_source(RESET_WKE);
+		set_reset_source(RESET_WAKEUP);
 		writel(S3C2440_GSTATUS2_SLEEPRST,
 					S3C_GPIO_BASE + S3C2440_GSTATUS2);
 		return 0;
 	}
 
 	if (reg & S3C2440_GSTATUS2_WDRST) {
-		set_reset_source(RESET_WDG);
+		set_reset_source(RESET_WATCHDOG);
 		writel(S3C2440_GSTATUS2_WDRST,
 					S3C_GPIO_BASE + S3C2440_GSTATUS2);
 		return 0;
diff --git a/common/reset_source.c b/common/reset_source.c
index 2a7f9ff..ff76857 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -19,12 +19,12 @@
 #include <reset_source.h>
 
 static const char * const reset_src_names[] = {
-	[RESET_UKWN] = "unknown",
-	[RESET_POR] = "POR",
-	[RESET_RST] = "RST",
-	[RESET_WDG] = "WDG",
-	[RESET_WKE] = "WKE",
-	[RESET_JTAG] = "JTAG",
+	[RESET_UKWNOWN] = "unknown",
+	[RESET_POWER] = "power",
+	[RESET_RESET] = "reset",
+	[RESET_WATCHDOG] = "watchdog",
+	[RESET_WAKEUP] = "wakeup",
+	[RESET_JTAG] = "jtag",
 };
 
 void set_reset_source(enum reset_src_type st)
@@ -37,7 +37,7 @@ EXPORT_SYMBOL(set_reset_source);
 static int init_reset_source(void)
 {
 	globalvar_add_simple("system.reset");
-	set_reset_source(RESET_UKWN);
+	set_reset_source(RESET_UKWNOWN);
 	return 0;
 }
 
diff --git a/drivers/watchdog/im28wd.c b/drivers/watchdog/im28wd.c
index ca32a72..999f5b4 100644
--- a/drivers/watchdog/im28wd.c
+++ b/drivers/watchdog/im28wd.c
@@ -82,17 +82,17 @@ static void __maybe_unused imx28_detect_reset_source(const struct imx28_wd *p)
 	if (reg & MXS_RTC_PERSISTENT0_EXT_RST) {
 		writel(MXS_RTC_PERSISTENT0_EXT_RST,
 			p->regs + MXS_RTC_PERSISTENT0 + MXS_RTC_CLR_ADDR);
-		set_reset_source(RESET_POR);
+		set_reset_source(RESET_POWER);
 		return;
 	}
 	if (reg & MXS_RTC_PERSISTENT0_THM_RST) {
 		writel(MXS_RTC_PERSISTENT0_THM_RST,
 			p->regs + MXS_RTC_PERSISTENT0 + MXS_RTC_CLR_ADDR);
-		set_reset_source(RESET_RST);
+		set_reset_source(RESET_RESET);
 		return;
 	}
 
-	set_reset_source(RESET_RST);
+	set_reset_source(RESET_RESET);
 }
 
 static int imx28_wd_probe(struct device_d *dev)
diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index c422f98..b13247b 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -129,17 +129,17 @@ static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
 	u16 val = readw(priv->base + IMX21_WDOG_WSTR);
 
 	if (val & WSTR_COLDSTART) {
-		set_reset_source(RESET_POR);
+		set_reset_source(RESET_POWER);
 		return;
 	}
 
 	if (val & (WSTR_HARDRESET | WSTR_WARMSTART)) {
-		set_reset_source(RESET_RST);
+		set_reset_source(RESET_RESET);
 		return;
 	}
 
 	if (val & WSTR_WDOG) {
-		set_reset_source(RESET_WDG);
+		set_reset_source(RESET_WATCHDOG);
 		return;
 	}
 
diff --git a/include/reset_source.h b/include/reset_source.h
index 75e7ba8..1db1f4f 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -14,11 +14,11 @@
 # define __INCLUDE_RESET_SOURCE_H
 
 enum reset_src_type {
-	RESET_UKWN,	/* maybe the SoC cannot detect the reset source */
-	RESET_POR,	/* Power On Reset (cold start) */
-	RESET_RST,	/* generic ReSeT (warm start) */
-	RESET_WDG,	/* watchdog */
-	RESET_WKE,	/* wake-up (some SoCs can handle this) */
+	RESET_UKWNOWN,	/* maybe the SoC cannot detect the reset source */
+	RESET_POWER,	/* Power On Reset (cold start) */
+	RESET_RESET,	/* generic ReSeT (warm start) */
+	RESET_WATCHDOG,	/* watchdog */
+	RESET_WAKEUP,	/* wake-up (some SoCs can handle this) */
 	RESET_JTAG,	/* JTAG reset */
 };
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/4] reset_source: add software reset as possible source
  2012-10-13 13:49 ` [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13 13:49   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 3/4] reset_resource: add wakeup source Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 4/4] at91: add reset and wakeup source detection support Jean-Christophe PLAGNIOL-VILLARD
  2 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13 13:49 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/reset_source.c  |    1 +
 include/reset_source.h |    1 +
 2 files changed, 2 insertions(+)

diff --git a/common/reset_source.c b/common/reset_source.c
index ff76857..ec1afc0 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -22,6 +22,7 @@ static const char * const reset_src_names[] = {
 	[RESET_UKWNOWN] = "unknown",
 	[RESET_POWER] = "power",
 	[RESET_RESET] = "reset",
+	[RESET_SOFTWARE] = "software",
 	[RESET_WATCHDOG] = "watchdog",
 	[RESET_WAKEUP] = "wakeup",
 	[RESET_JTAG] = "jtag",
diff --git a/include/reset_source.h b/include/reset_source.h
index 1db1f4f..af4246a 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -17,6 +17,7 @@ enum reset_src_type {
 	RESET_UKWNOWN,	/* maybe the SoC cannot detect the reset source */
 	RESET_POWER,	/* Power On Reset (cold start) */
 	RESET_RESET,	/* generic ReSeT (warm start) */
+	RESET_SOFTWARE,	/* software */
 	RESET_WATCHDOG,	/* watchdog */
 	RESET_WAKEUP,	/* wake-up (some SoCs can handle this) */
 	RESET_JTAG,	/* JTAG reset */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/4] reset_resource: add wakeup source
  2012-10-13 13:49 ` [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 2/4] reset_source: add software reset as possible source Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13 13:49   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 18:18     ` Sascha Hauer
  2012-10-15  8:04     ` Jan Lübbe
  2012-10-13 13:49   ` [PATCH 4/4] at91: add reset and wakeup source detection support Jean-Christophe PLAGNIOL-VILLARD
  2 siblings, 2 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13 13:49 UTC (permalink / raw)
  To: barebox

This will allow to known the source of wakeup

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/reset_source.c  |   17 +++++++++++++++++
 include/reset_source.h |   11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/common/reset_source.c b/common/reset_source.c
index ec1afc0..4791d29 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -34,11 +34,28 @@ void set_reset_source(enum reset_src_type st)
 }
 EXPORT_SYMBOL(set_reset_source);
 
+static const char * const wakeup_src_names[] = {
+	[WAKEUP_UKWNOWN] = "unknown",
+	[WAKEUP_POWER] = "power",
+	[WAKEUP_RTC] = "rtc",
+	[WAKEUP_TIMER] = "timer",
+	[WAKEUP_USER] = "user",
+	[WAKEUP_WOL] = "wakeup on lan",
+};
+
+void set_wakeup_source(enum wakeup_src_type st)
+{
+	setenv("global.system.wakeup", wakeup_src_names[st]);
+}
+EXPORT_SYMBOL(set_reset_source);
+
 /* ensure this runs after the 'global' device is already registerd */
 static int init_reset_source(void)
 {
 	globalvar_add_simple("system.reset");
+	globalvar_add_simple("system.wakeup");
 	set_reset_source(RESET_UKWNOWN);
+	set_wakeup_source(WAKEUP_UKWNOWN);
 	return 0;
 }
 
diff --git a/include/reset_source.h b/include/reset_source.h
index af4246a..1777b2b 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -31,4 +31,15 @@ static inline void set_reset_source(enum reset_src_type unused)
 }
 #endif
 
+enum wakeup_src_type {
+	WAKEUP_UKWNOWN,	/* maybe the SoC cannot detect the wakeup source */
+	WAKEUP_POWER,	/* Power restore */
+	WAKEUP_RTC,	/* rtc */
+	WAKEUP_TIMER,	/* timer */
+	WAKEUP_USER,	/* user */
+	WAKEUP_WOL,	/* wakeup on lan */
+};
+
+void set_wakeup_source(enum wakeup_src_type);
+
 #endif /* __INCLUDE_RESET_SOURCE_H */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] at91: add reset and wakeup source detection support
  2012-10-13 13:49 ` [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 2/4] reset_source: add software reset as possible source Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 13:49   ` [PATCH 3/4] reset_resource: add wakeup source Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13 13:49   ` Jean-Christophe PLAGNIOL-VILLARD
  2 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13 13:49 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-at91/Makefile                  |    1 +
 arch/arm/mach-at91/include/mach/at91_shdwc.h |   40 +++++++++++++++++
 arch/arm/mach-at91/reset_source.c            |   59 ++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_shdwc.h
 create mode 100644 arch/arm/mach-at91/reset_source.c

diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 3ade725..1f912c6 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -8,6 +8,7 @@ pbl-$(CONFIG_MACH_DO_LOWLEVEL_INIT) += $(lowlevel_init-y)
 
 obj-$(CONFIG_AT91SAM9_RESET) += at91sam9_reset.o
 obj-$(CONFIG_AT91SAM9G45_RESET) += at91sam9g45_reset.o
+obj-$(CONFIG_RESET_SOURCE) += reset_source.o
 
 # CPU-specific support
 obj-$(CONFIG_ARCH_AT91RM9200)	+= at91rm9200.o at91rm9200_time.o at91rm9200_devices.o
diff --git a/arch/arm/mach-at91/include/mach/at91_shdwc.h b/arch/arm/mach-at91/include/mach/at91_shdwc.h
new file mode 100644
index 0000000..75e6801
--- /dev/null
+++ b/arch/arm/mach-at91/include/mach/at91_shdwc.h
@@ -0,0 +1,40 @@
+/*
+ * arch/arm/mach-at91/include/mach/at91_shdwc.h
+ *
+ * Copyright (C) 2007 Andrew Victor
+ * Copyright (C) 2007 Atmel Corporation.
+ *
+ * Shutdown Controller (SHDWC) - System peripherals regsters.
+ * Based on AT91SAM9261 datasheet revision D.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef AT91_SHDWC_H
+#define AT91_SHDWC_H
+
+#define AT91_SHDW_CR		(AT91_SHDWC + 0x00)	/* Shut Down Control Register */
+#define		AT91_SHDW_SHDW		(1    << 0)		/* Shut Down command */
+#define		AT91_SHDW_KEY		(0xa5 << 24)		/* KEY Password */
+
+#define AT91_SHDW_MR		(AT91_SHDWC + 0x04)	/* Shut Down Mode Register */
+#define		AT91_SHDW_WKMODE0	(3 << 0)		/* Wake-up 0 Mode Selection */
+#define			AT91_SHDW_WKMODE0_NONE		0
+#define			AT91_SHDW_WKMODE0_HIGH		1
+#define			AT91_SHDW_WKMODE0_LOW		2
+#define			AT91_SHDW_WKMODE0_ANYLEVEL	3
+#define		AT91_SHDW_CPTWK0_MAX	0xf			/* Maximum Counter On Wake Up 0 */
+#define		AT91_SHDW_CPTWK0	(AT91_SHDW_CPTWK0_MAX << 4) /* Counter On Wake Up 0 */
+#define			AT91_SHDW_CPTWK0_(x)	((x) << 4)
+#define		AT91_SHDW_RTTWKEN	(1   << 16)		/* Real Time Timer Wake-up Enable */
+#define		AT91_SHDW_RTCWKEN	(1   << 17)		/* Real Time Clock Wake-up Enable */
+
+#define AT91_SHDW_SR		(AT91_SHDWC + 0x08)	/* Shut Down Status Register */
+#define		AT91_SHDW_WAKEUP0	(1 <<  0)		/* Wake-up 0 Status */
+#define		AT91_SHDW_RTTWK		(1 << 16)		/* Real-time Timer Wake-up */
+#define		AT91_SHDW_RTCWK		(1 << 17)		/* Real-time Clock Wake-up [SAM9RL] */
+
+#endif
diff --git a/arch/arm/mach-at91/reset_source.c b/arch/arm/mach-at91/reset_source.c
new file mode 100644
index 0000000..b078941
--- /dev/null
+++ b/arch/arm/mach-at91/reset_source.c
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrsoft.com>
+ *
+ * GPLv2
+ */
+
+#include <reset_source.h>
+#include <io.h>
+#include <init.h>
+#include <mach/hardware.h>
+#include <mach/io.h>
+
+#include <mach/at91_rstc.h>
+#include <mach/at91_shdwc.h>
+
+static int at91_reset_status(void)
+{
+	u32 reset_type, wake_type;
+
+	reset_type = at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_RSTTYP;
+	wake_type = at91_sys_read(AT91_SHDW_SR);
+
+	switch (reset_type) {
+	case AT91_RSTC_RSTTYP_GENERAL:
+		set_reset_source(RESET_POWER);
+		break;
+	case AT91_RSTC_RSTTYP_WAKEUP:
+		/* board-specific code enabled the wakeup sources */
+		set_reset_source(RESET_WAKEUP);
+
+		/* "wakeup signal" */
+		if (wake_type & AT91_SHDW_WAKEUP0)
+			set_wakeup_source(WAKEUP_USER);
+		else if (wake_type & AT91_SHDW_RTTWK)	/* rtt wakeup */
+			set_wakeup_source(WAKEUP_TIMER);
+		else if (wake_type & AT91_SHDW_RTCWK)	/* rtc wakeup */
+			set_wakeup_source(WAKEUP_RTC);
+		else if (wake_type == 0)		/* power-restored wakeup */
+			set_wakeup_source(WAKEUP_POWER);
+		else					/* unknown wakeup */
+			set_wakeup_source(WAKEUP_UKWNOWN);
+		break;
+	case AT91_RSTC_RSTTYP_WATCHDOG:
+		set_reset_source(RESET_WATCHDOG);
+		break;
+	case AT91_RSTC_RSTTYP_SOFTWARE:
+		set_reset_source(RESET_SOFTWARE);
+		break;
+	case AT91_RSTC_RSTTYP_USER:
+		set_reset_source(RESET_RESET);
+		break;
+	default:
+		set_reset_source(RESET_UKWNOWN);
+		break;
+	}
+
+	return 0;
+}
+device_initcall(at91_reset_status);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] reset_resource: add wakeup source
  2012-10-13 13:49   ` [PATCH 3/4] reset_resource: add wakeup source Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13 18:18     ` Sascha Hauer
  2012-10-14  9:56       ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-15  8:04     ` Jan Lübbe
  1 sibling, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-10-13 18:18 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sat, Oct 13, 2012 at 03:49:21PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> This will allow to known the source of wakeup
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  common/reset_source.c  |   17 +++++++++++++++++
>  include/reset_source.h |   11 +++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/common/reset_source.c b/common/reset_source.c
> index ec1afc0..4791d29 100644
> --- a/common/reset_source.c
> +++ b/common/reset_source.c
> @@ -34,11 +34,28 @@ void set_reset_source(enum reset_src_type st)
>  }
>  EXPORT_SYMBOL(set_reset_source);
>  
> +static const char * const wakeup_src_names[] = {
> +	[WAKEUP_UKWNOWN] = "unknown",
> +	[WAKEUP_POWER] = "power",
> +	[WAKEUP_RTC] = "rtc",
> +	[WAKEUP_TIMER] = "timer",
> +	[WAKEUP_USER] = "user",
> +	[WAKEUP_WOL] = "wakeup on lan",
> +};

I'm unsure we need a second array for this. I mean RTC can't be seen as
a reset source, but with a bit of good will the watchdog for example can
be seen as a wakeup source. We have:

	WAKEUP_POWER
	WAKEUP_RTC
	WAKEUP_TIMER
	WAKEUP_USER
	WAKEUP_WOL
	RESET_POWER
	RESET_RESET
	RESET_WATCHDOG
	RESET_WAKEUP
	RESET_JTAG

WAKEUP_POWER and RESET_POWER are duplicates, RESET_WAKEUP is just an
indicator that we should look into the WAKEUP_* array. The rest are all
mutually exclusive. So we would have:

	WAKEUP_POWER
	WAKEUP_RTC
	WAKEUP_TIMER
	WAKEUP_USER
	WAKEUP_WOL
	WAKEUP_RESET
	WAKEUP_WATCHDOG
	WAKEUP_JTAG

Wouldn't that be better?

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] reset_resource: add wakeup source
  2012-10-13 18:18     ` Sascha Hauer
@ 2012-10-14  9:56       ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-14 10:34         ` Eric Bénard
  0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-14  9:56 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 20:18 Sat 13 Oct     , Sascha Hauer wrote:
> On Sat, Oct 13, 2012 at 03:49:21PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > This will allow to known the source of wakeup
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  common/reset_source.c  |   17 +++++++++++++++++
> >  include/reset_source.h |   11 +++++++++++
> >  2 files changed, 28 insertions(+)
> > 
> > diff --git a/common/reset_source.c b/common/reset_source.c
> > index ec1afc0..4791d29 100644
> > --- a/common/reset_source.c
> > +++ b/common/reset_source.c
> > @@ -34,11 +34,28 @@ void set_reset_source(enum reset_src_type st)
> >  }
> >  EXPORT_SYMBOL(set_reset_source);
> >  
> > +static const char * const wakeup_src_names[] = {
> > +	[WAKEUP_UKWNOWN] = "unknown",
> > +	[WAKEUP_POWER] = "power",
> > +	[WAKEUP_RTC] = "rtc",
> > +	[WAKEUP_TIMER] = "timer",
> > +	[WAKEUP_USER] = "user",
> > +	[WAKEUP_WOL] = "wakeup on lan",
> > +};
> 
> I'm unsure we need a second array for this. I mean RTC can't be seen as
> a reset source, but with a bit of good will the watchdog for example can
> be seen as a wakeup source. We have:
> 
> 	WAKEUP_POWER
> 	WAKEUP_RTC
> 	WAKEUP_TIMER
> 	WAKEUP_USER
> 	WAKEUP_WOL
> 	RESET_POWER
> 	RESET_RESET
> 	RESET_WATCHDOG
> 	RESET_WAKEUP
> 	RESET_JTAG
> 
> WAKEUP_POWER and RESET_POWER are duplicates, RESET_WAKEUP is just an
> indicator that we should look into the WAKEUP_* array. The rest are all
> mutually exclusive. So we would have:
for reset POWER mean inmy ming we gcc power up on the soc
not I plug the power

so it could be WKAEUP_POWER_UP

for RESET_WAKEUP I agree
> 
> 	WAKEUP_POWER
> 	WAKEUP_RTC
> 	WAKEUP_TIMER
> 	WAKEUP_USER
> 	WAKEUP_WOL
> 	WAKEUP_RESET
> 	WAKEUP_WATCHDOG
> 	WAKEUP_JTAG
> 
> Wouldn't that be better?
Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] reset_resource: add wakeup source
  2012-10-14  9:56       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-14 10:34         ` Eric Bénard
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Bénard @ 2012-10-14 10:34 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hi Jean Christophe

Le Sun, 14 Oct 2012 11:56:16 +0200,
Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> for reset POWER mean inmy ming we gcc power up on the soc
> not I plug the power
> 
can you please make an effort in your emails or just tell me which
language should I use in google translator to understand that ? ;-)

Thanks !
Eric

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] reset_resource: add wakeup source
  2012-10-13 13:49   ` [PATCH 3/4] reset_resource: add wakeup source Jean-Christophe PLAGNIOL-VILLARD
  2012-10-13 18:18     ` Sascha Hauer
@ 2012-10-15  8:04     ` Jan Lübbe
  1 sibling, 0 replies; 10+ messages in thread
From: Jan Lübbe @ 2012-10-15  8:04 UTC (permalink / raw)
  To: barebox

On Sat, 2012-10-13 at 15:49 +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> +static const char * const wakeup_src_names[] = {
> +	[WAKEUP_UKWNOWN] = "unknown",
> +	[WAKEUP_POWER] = "power",
> +	[WAKEUP_RTC] = "rtc",
> +	[WAKEUP_TIMER] = "timer",
> +	[WAKEUP_USER] = "user",
> +	[WAKEUP_WOL] = "wakeup on lan",
> +};
> +
> +void set_wakeup_source(enum wakeup_src_type st)
> +{
> +	setenv("global.system.wakeup", wakeup_src_names[st]);
> +}
> +EXPORT_SYMBOL(set_reset_source);

The EXPORT_SYMBOL should be for _wakeup_ instead of _reset_.

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] at91: add reset and wakeup source detection support
  2012-10-13  7:51 [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-13  7:51 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-13  7:51 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-at91/Makefile                  |    1 +
 arch/arm/mach-at91/include/mach/at91_shdwc.h |   40 +++++++++++++++++
 arch/arm/mach-at91/reset_source.c            |   59 ++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_shdwc.h
 create mode 100644 arch/arm/mach-at91/reset_source.c

diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 3ade725..1f912c6 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -8,6 +8,7 @@ pbl-$(CONFIG_MACH_DO_LOWLEVEL_INIT) += $(lowlevel_init-y)
 
 obj-$(CONFIG_AT91SAM9_RESET) += at91sam9_reset.o
 obj-$(CONFIG_AT91SAM9G45_RESET) += at91sam9g45_reset.o
+obj-$(CONFIG_RESET_SOURCE) += reset_source.o
 
 # CPU-specific support
 obj-$(CONFIG_ARCH_AT91RM9200)	+= at91rm9200.o at91rm9200_time.o at91rm9200_devices.o
diff --git a/arch/arm/mach-at91/include/mach/at91_shdwc.h b/arch/arm/mach-at91/include/mach/at91_shdwc.h
new file mode 100644
index 0000000..75e6801
--- /dev/null
+++ b/arch/arm/mach-at91/include/mach/at91_shdwc.h
@@ -0,0 +1,40 @@
+/*
+ * arch/arm/mach-at91/include/mach/at91_shdwc.h
+ *
+ * Copyright (C) 2007 Andrew Victor
+ * Copyright (C) 2007 Atmel Corporation.
+ *
+ * Shutdown Controller (SHDWC) - System peripherals regsters.
+ * Based on AT91SAM9261 datasheet revision D.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef AT91_SHDWC_H
+#define AT91_SHDWC_H
+
+#define AT91_SHDW_CR		(AT91_SHDWC + 0x00)	/* Shut Down Control Register */
+#define		AT91_SHDW_SHDW		(1    << 0)		/* Shut Down command */
+#define		AT91_SHDW_KEY		(0xa5 << 24)		/* KEY Password */
+
+#define AT91_SHDW_MR		(AT91_SHDWC + 0x04)	/* Shut Down Mode Register */
+#define		AT91_SHDW_WKMODE0	(3 << 0)		/* Wake-up 0 Mode Selection */
+#define			AT91_SHDW_WKMODE0_NONE		0
+#define			AT91_SHDW_WKMODE0_HIGH		1
+#define			AT91_SHDW_WKMODE0_LOW		2
+#define			AT91_SHDW_WKMODE0_ANYLEVEL	3
+#define		AT91_SHDW_CPTWK0_MAX	0xf			/* Maximum Counter On Wake Up 0 */
+#define		AT91_SHDW_CPTWK0	(AT91_SHDW_CPTWK0_MAX << 4) /* Counter On Wake Up 0 */
+#define			AT91_SHDW_CPTWK0_(x)	((x) << 4)
+#define		AT91_SHDW_RTTWKEN	(1   << 16)		/* Real Time Timer Wake-up Enable */
+#define		AT91_SHDW_RTCWKEN	(1   << 17)		/* Real Time Clock Wake-up Enable */
+
+#define AT91_SHDW_SR		(AT91_SHDWC + 0x08)	/* Shut Down Status Register */
+#define		AT91_SHDW_WAKEUP0	(1 <<  0)		/* Wake-up 0 Status */
+#define		AT91_SHDW_RTTWK		(1 << 16)		/* Real-time Timer Wake-up */
+#define		AT91_SHDW_RTCWK		(1 << 17)		/* Real-time Clock Wake-up [SAM9RL] */
+
+#endif
diff --git a/arch/arm/mach-at91/reset_source.c b/arch/arm/mach-at91/reset_source.c
new file mode 100644
index 0000000..b078941
--- /dev/null
+++ b/arch/arm/mach-at91/reset_source.c
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrsoft.com>
+ *
+ * GPLv2
+ */
+
+#include <reset_source.h>
+#include <io.h>
+#include <init.h>
+#include <mach/hardware.h>
+#include <mach/io.h>
+
+#include <mach/at91_rstc.h>
+#include <mach/at91_shdwc.h>
+
+static int at91_reset_status(void)
+{
+	u32 reset_type, wake_type;
+
+	reset_type = at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_RSTTYP;
+	wake_type = at91_sys_read(AT91_SHDW_SR);
+
+	switch (reset_type) {
+	case AT91_RSTC_RSTTYP_GENERAL:
+		set_reset_source(RESET_POWER);
+		break;
+	case AT91_RSTC_RSTTYP_WAKEUP:
+		/* board-specific code enabled the wakeup sources */
+		set_reset_source(RESET_WAKEUP);
+
+		/* "wakeup signal" */
+		if (wake_type & AT91_SHDW_WAKEUP0)
+			set_wakeup_source(WAKEUP_USER);
+		else if (wake_type & AT91_SHDW_RTTWK)	/* rtt wakeup */
+			set_wakeup_source(WAKEUP_TIMER);
+		else if (wake_type & AT91_SHDW_RTCWK)	/* rtc wakeup */
+			set_wakeup_source(WAKEUP_RTC);
+		else if (wake_type == 0)		/* power-restored wakeup */
+			set_wakeup_source(WAKEUP_POWER);
+		else					/* unknown wakeup */
+			set_wakeup_source(WAKEUP_UKWNOWN);
+		break;
+	case AT91_RSTC_RSTTYP_WATCHDOG:
+		set_reset_source(RESET_WATCHDOG);
+		break;
+	case AT91_RSTC_RSTTYP_SOFTWARE:
+		set_reset_source(RESET_SOFTWARE);
+		break;
+	case AT91_RSTC_RSTTYP_USER:
+		set_reset_source(RESET_RESET);
+		break;
+	default:
+		set_reset_source(RESET_UKWNOWN);
+		break;
+	}
+
+	return 0;
+}
+device_initcall(at91_reset_status);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-10-15  8:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-13 13:46 [PATCH 0/4 v2] add wakup source Jean-Christophe PLAGNIOL-VILLARD
2012-10-13 13:49 ` [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
2012-10-13 13:49   ` [PATCH 2/4] reset_source: add software reset as possible source Jean-Christophe PLAGNIOL-VILLARD
2012-10-13 13:49   ` [PATCH 3/4] reset_resource: add wakeup source Jean-Christophe PLAGNIOL-VILLARD
2012-10-13 18:18     ` Sascha Hauer
2012-10-14  9:56       ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-14 10:34         ` Eric Bénard
2012-10-15  8:04     ` Jan Lübbe
2012-10-13 13:49   ` [PATCH 4/4] at91: add reset and wakeup source detection support Jean-Christophe PLAGNIOL-VILLARD
  -- strict thread matches above, loose matches on Subject: below --
2012-10-13  7:51 [PATCH 1/4] reset_source: make enum and string human readable Jean-Christophe PLAGNIOL-VILLARD
2012-10-13  7:51 ` [PATCH 4/4] at91: add reset and wakeup source detection support Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox