From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] at91: add reset and wakeup source detection support
Date: Sat, 13 Oct 2012 15:49:22 +0200 [thread overview]
Message-ID: <1350136162-22061-4-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1350136162-22061-1-git-send-email-plagnioj@jcrosoft.com>
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
next prev parent reply other threads:[~2012-10-13 13:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
-- 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
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=1350136162-22061-4-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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