From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 07/13 v3] arm: at91: Enable watchdog support
Date: Tue, 2 Apr 2019 10:57:21 +0200 [thread overview]
Message-ID: <20190402085727.14552-7-sr@denx.de> (raw)
In-Reply-To: <20190402085727.14552-1-sr@denx.de>
This patch enables and starts the watchdog on the AT91 platform if
configured. The WD timeout value is read in the AT91 WD device driver
from the DT, using the "timeout-sec" DT property. If not provided in
the DT, the default value of 2 seconds is used.
Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Heiko Schocher <hs@denx.de>
Cc: Andreas Bießmann <andreas@biessmann.org>
Cc: Eugen Hristev <eugen.hristev@microchip.com>
---
v3:
- Move WDT struct and macros into arch header so that it can be used
by the arch code to start the driver (timeout value)
- This change now enables the use of the "timeout-sec" DT property
to specifiy a board specific WD timeout value
v2:
- Remove #ifdef to enable compilation also in SPL version
arch/arm/mach-at91/clock.c | 48 ++++++++++++++++++++++
arch/arm/mach-at91/include/mach/at91_wdt.h | 10 +++++
drivers/watchdog/at91sam9_wdt.c | 10 -----
3 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index 64cbc3d1ed..1d3df2c09d 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -5,12 +5,17 @@
*/
#include <common.h>
+#include <dm.h>
+#include <wdt.h>
#include <asm/io.h>
#include <asm/arch/hardware.h>
#include <asm/arch/at91_pmc.h>
+#include <asm/arch/at91_wdt.h>
#define EN_UPLL_TIMEOUT 500
+static struct udevice *watchdog_dev __attribute__((section(".data"))) = NULL;
+
void at91_periph_clk_enable(int id)
{
struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
@@ -118,3 +123,46 @@ void at91_pllicpr_init(u32 icpr)
writel(icpr, &pmc->pllicpr);
}
+
+/* Called by macro WATCHDOG_RESET */
+void watchdog_reset(void)
+{
+ static ulong next_reset;
+ ulong now;
+
+ if (!watchdog_dev)
+ return;
+
+ now = get_timer(0);
+
+ /* Do not reset the watchdog too often */
+ if (now > next_reset) {
+ next_reset = now + 1000; /* reset every 1000ms */
+ wdt_reset(watchdog_dev);
+ }
+}
+
+int arch_early_init_r(void)
+{
+ struct at91_wdt_priv *priv;
+
+ /* Init watchdog */
+ if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
+ debug("Watchdog: Not found by seq!\n");
+ if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
+ puts("Watchdog: Not found!\n");
+ return 0;
+ }
+ }
+
+ priv = dev_get_priv(watchdog_dev);
+ if (!priv) {
+ printf("Watchdog: priv not available!\n");
+ return 0;
+ }
+
+ wdt_start(watchdog_dev, priv->timeout * 1000, 0);
+ printf("Watchdog: Started\n");
+
+ return 0;
+}
diff --git a/arch/arm/mach-at91/include/mach/at91_wdt.h b/arch/arm/mach-at91/include/mach/at91_wdt.h
index cd2272367b..c977b090c8 100644
--- a/arch/arm/mach-at91/include/mach/at91_wdt.h
+++ b/arch/arm/mach-at91/include/mach/at91_wdt.h
@@ -43,4 +43,14 @@ typedef struct at91_wdt {
#define AT91_WDT_MR_WDDBGHLT 0x10000000
#define AT91_WDT_MR_WDIDLEHLT 0x20000000
+/* Hardware timeout in seconds */
+#define WDT_MAX_TIMEOUT 16
+#define WDT_DEFAULT_TIMEOUT 2
+
+struct at91_wdt_priv {
+ void __iomem *regs;
+ u32 regval;
+ u32 timeout;
+};
+
#endif
diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 1c71778bdc..793425c8d2 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -31,16 +31,6 @@ DECLARE_GLOBAL_DATA_PTR;
*/
#define WDT_SEC2TICKS(s) (((s) << 8) - 1)
-/* Hardware timeout in seconds */
-#define WDT_MAX_TIMEOUT 16
-#define WDT_DEFAULT_TIMEOUT 2
-
-struct at91_wdt_priv {
- void __iomem *regs;
- u32 regval;
- u32 timeout;
-};
-
/*
* Set the watchdog time interval in 1/256Hz (write-once)
* Counter is 12 bit.
--
2.21.0
next prev parent reply other threads:[~2019-04-02 8:57 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 8:57 [U-Boot] [PATCH 01/13 v3] arm: at91: Makefile: Compile lowlevel_init only when really necessary Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 02/13 v3] arm: at91: spl_at91.c: Call spl_early_init() if OF_CONTROL is enabled Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 03/13 v3] serial: atmel_usart: Use fixed clock value in SPL version with DM_SERIAL Stefan Roese
2019-04-02 10:12 ` Eugen.Hristev at microchip.com
2019-04-02 10:40 ` Stefan Roese
2019-04-02 10:45 ` Eugen.Hristev at microchip.com
2019-04-02 11:21 ` [U-Boot] [PATCH 3/13 v4] " Stefan Roese
2019-04-03 10:52 ` Eugen.Hristev at microchip.com
2019-04-03 10:58 ` Stefan Roese
2019-04-03 11:05 ` Eugen.Hristev at microchip.com
2019-04-03 11:11 ` Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 04/13 v3] watchdog: Handle SPL build with watchdog disabled Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 05/13 v3] watchdog: at91sam9_wdt: Fix WDT setup in at91_wdt_start() Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 06/13 v3] arm: at91: Remove CONFIG_AT91_HW_WDT_TIMEOUT Stefan Roese
2019-04-02 11:19 ` Eugen.Hristev at microchip.com
2019-04-03 5:37 ` [U-Boot] [PATCH 06/13 v4] " Stefan Roese
2019-04-02 8:57 ` Stefan Roese [this message]
2019-04-02 11:26 ` [U-Boot] [PATCH 07/13 v3] arm: at91: Enable watchdog support Eugen.Hristev at microchip.com
2019-04-02 11:50 ` Stefan Roese
2019-04-03 5:40 ` Stefan Roese
2019-04-03 5:37 ` [U-Boot] [PATCH 07/13 v4] " Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 08/13 v3] arm: at91: arm926ejs/u-boot-spl.lds: Add _image_binary_end to SPL lds Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 09/13 v3] Makefile.spl: Move generated AT91SAM NAND image boot.bin to spl directory Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 10/13 v3] Makefile: Add Kconfig option CONFIG_SPL_IMAGE to select the SPL binary Stefan Roese
2019-04-03 11:08 ` Eugen.Hristev at microchip.com
2019-04-03 11:11 ` Eugen.Hristev at microchip.com
2019-04-03 11:21 ` Stefan Roese
2019-04-03 12:22 ` Stefan Roese
2019-04-03 12:31 ` Eugen.Hristev at microchip.com
2019-04-03 12:38 ` Stefan Roese
2019-04-03 12:46 ` Eugen.Hristev at microchip.com
2019-04-03 11:19 ` Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 11/13 v3] arm: at91: siemens: Add support to generate combined SPL+U-Boot image Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 12/13 v3] arm: at91: at91sam9x5.dtsi: Add watchdog handle Stefan Roese
2019-04-02 8:57 ` [U-Boot] [PATCH 13/13 v3] arm: at91: Add gardena-gateway-at91sam support Stefan Roese
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=20190402085727.14552-7-sr@denx.de \
--to=sr@denx.de \
--cc=u-boot@lists.denx.de \
/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