blob: 3fbf52b5817677c7b83fcff9381f1308460db1d7 [file] [log] [blame]
Jan Kundrát149e05a2017-09-29 18:32:30 +02001From 7242f6d20423a7705080d54828468b3a31071566 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= <jan.kundrat@cesnet.cz>
3Date: Fri, 29 Sep 2017 18:11:04 +0200
4Subject: [PATCH] Unconditionally enable watchdog timer on Clearfog
5
6We will only be booting kernels that support the watchdog, so there's no
7risk in leaving our WD running while we hand over to the kernel.
8
9The code was copied from the Turris Omnia version and used as-is. The
10only exception is the built-in MCU reset which is not present on our
11boards.
12---
13 board/solidrun/clearfog/clearfog.c | 43 ++++++++++++++++++++++++++++++++++++++
14 configs/clearfog_defconfig | 2 ++
15 include/configs/clearfog.h | 5 +++++
16 3 files changed, 50 insertions(+)
17
18diff --git a/board/solidrun/clearfog/clearfog.c b/board/solidrun/clearfog/clearfog.c
19index 8906636f76..f94bd5e465 100644
20--- a/board/solidrun/clearfog/clearfog.c
21+++ b/board/solidrun/clearfog/clearfog.c
22@@ -11,10 +11,15 @@
23 #include <asm/io.h>
24 #include <asm/arch/cpu.h>
25 #include <asm/arch/soc.h>
26+#include <dm/uclass.h>
27
28 #include "../drivers/ddr/marvell/a38x/ddr3_a38x_topology.h"
29 #include <../serdes/a38x/high_speed_env_spec.h>
30
31+#ifdef CONFIG_WDT_ORION
32+# include <wdt.h>
33+#endif
34+
35 DECLARE_GLOBAL_DATA_PTR;
36
37 #define ETH_PHY_CTRL_REG 0
38@@ -122,6 +127,10 @@ int board_early_init_f(void)
39 return 0;
40 }
41
42+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT_ORION)
43+static struct udevice *watchdog_dev = NULL;
44+#endif
45+
46 int board_init(void)
47 {
48 int i;
49@@ -129,6 +138,18 @@ int board_init(void)
50 /* Address of boot parameters */
51 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
52
53+#ifndef CONFIG_SPL_BUILD
54+# ifdef CONFIG_WDT_ORION
55+ if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
56+ puts("Cannot find Armada 385 watchdog!\n");
57+ } else {
58+ puts("Enabling Armada 385 watchdog.\n");
59+ /* one minute */
60+ wdt_start(watchdog_dev, (u32) 25000000 * 60, 0);
61+ }
62+# endif
63+#endif
64+
65 /* Toggle GPIO41 to reset onboard switch and phy */
66 clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
67 clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
68@@ -147,6 +168,28 @@ int board_init(void)
69 return 0;
70 }
71
72+#ifdef CONFIG_WATCHDOG
73+/* Called by macro WATCHDOG_RESET */
74+void watchdog_reset(void)
75+{
76+# if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT_ORION)
77+ static ulong next_reset = 0;
78+ ulong now;
79+
80+ if (!watchdog_dev)
81+ return;
82+
83+ now = timer_get_us();
84+
85+ /* Do not reset the watchdog too often */
86+ if (now > next_reset) {
87+ wdt_reset(watchdog_dev);
88+ next_reset = now + 1000;
89+ }
90+# endif
91+}
92+#endif
93+
94 int checkboard(void)
95 {
96 puts("Board: SolidRun ClearFog\n");
97diff --git a/configs/clearfog_defconfig b/configs/clearfog_defconfig
98index 5eceacf491..fd48b0db02 100644
99--- a/configs/clearfog_defconfig
100+++ b/configs/clearfog_defconfig
101@@ -46,3 +46,5 @@ CONFIG_USB=y
102 CONFIG_DM_USB=y
103 CONFIG_USB_EHCI_HCD=y
104 CONFIG_USB_STORAGE=y
105+CONFIG_WDT=y
106+CONFIG_WDT_ORION=y
107diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h
108index 5061f6c6fd..eac1e8bbce 100644
109--- a/include/configs/clearfog.h
110+++ b/include/configs/clearfog.h
111@@ -32,6 +32,11 @@
112 #define CONFIG_SYS_I2C_SLAVE 0x0
113 #define CONFIG_SYS_I2C_SPEED 100000
114
115+/* Watchdog */
116+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT_ORION)
117+# define CONFIG_WATCHDOG
118+#endif
119+
120 /* SPI NOR flash default params, used by sf commands */
121 #define CONFIG_SF_DEFAULT_SPEED 1000000
122 #define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
123--
1242.14.1
125