summaryrefslogtreecommitdiff
path: root/common/include/asm
diff options
context:
space:
mode:
authorOlivier Dufour2012-09-19 10:46:21 +0200
committerJérémy Dufour2012-10-18 10:25:03 +0200
commitef7574d6c17218f2e3125c2433b9545d0297333f (patch)
tree44a1d582c2a7f1d1d052459cc93352233b2f7d5e /common/include/asm
parente0f4e08c89c4e4e1825ff214e1245e6391b70ef7 (diff)
{cleo,polux}/linux/arm/wdt: move some functions to header, refs #3272
In order to be able to add support for watchdog functions in boot sequence, functions to start and refresh it need to be defined directly in header files.
Diffstat (limited to 'common/include/asm')
-rw-r--r--common/include/asm/arch/wdt.h95
1 files changed, 84 insertions, 11 deletions
diff --git a/common/include/asm/arch/wdt.h b/common/include/asm/arch/wdt.h
index 52ccddffa3..9e1e9ecbc0 100644
--- a/common/include/asm/arch/wdt.h
+++ b/common/include/asm/arch/wdt.h
@@ -21,6 +21,7 @@
#define __ASM_ARCH_WDT_H
#include <asm/arch/ips/wdt.h>
+#include <linux/errno.h>
#define WDT_DEFAULT_TIME 5 //seconds
#define WDT_MAX_TIME 21 //seconds
@@ -31,6 +32,66 @@
extern uint32_t spc300_wdt_user_mode;
/**
+ * Refresh watchdog timer.
+ *
+ * \param va true if need to use virtual address to access register, false
+ * for physical address.
+ */
+static void spc300_wdt_refresh_(bool va)
+{
+ uint32_t reg = WDT_BF(CR, WDT_CR_VAL);
+ if (va)
+ WDT_CRR_VA = reg;
+ else
+ WDT_CRR_PA = reg;
+}
+
+/**
+ * Start watchdog timer countdown.
+ *
+ * \param timeout_s timeout of the watchdog (in second).
+ * \param va true if need to use virtual address to access register, false
+ * for physical address.
+ * \return 0 if no error, error value otherwise (-EINVAL if timeout_s is too
+ * big).
+ */
+static int spc300_wdt_start_(uint timeout_s, bool va)
+{
+ uint32_t cnt_value, top, reg;
+
+ //Timeout period = (2^(16+ TOP_reg)) / PCLK
+
+ // Configure timeout?
+ if(timeout_s)
+ {
+ if(timeout_s > WDT_MAX_TIME)
+ return -EINVAL;
+
+ cnt_value = timeout_s * PCLK;
+
+ for(top=15 ; top>0 ; top--)
+ {
+ if(cnt_value >= (1<<(top+16)))
+ {
+ if (va)
+ WDT_TORR_VA = WDT_BFINS(TOP, top, WDT_TORR_VA);
+ else
+ WDT_TORR_PA = WDT_BFINS(TOP, top, WDT_TORR_PA);
+ break;
+ }
+ }
+ }
+ //Enable WDT with reset pulse = 32pclk and without interrupt management
+ reg = WDT_BF(RPL, 4) | WDT_BF(RMOD, 0) | WDT_BF(EN, 1);
+ if (va)
+ WDT_CR_VA = reg;
+ else
+ WDT_CR_PA = reg;
+ spc300_wdt_refresh_(va);
+ return 0;
+}
+
+/**
* Start watchdog timer countdown.
*
* \param timeout_s timeout of the watchdog (in second).
@@ -40,35 +101,47 @@ extern uint32_t spc300_wdt_user_mode;
* This function can be called even if the watchdog is already counting down:
* it is used to both start and configure the watchdog.
*/
-int spc300_wdt_start(uint timeout_s);
+static inline int spc300_wdt_start(uint timeout_s)
+{
+ return spc300_wdt_start_(timeout_s, true);
+}
/**
* Start watchdog timer countdown (using physical address).
*
* \param timeout_s timeout of the watchdog (in second).
- * \return 0 if no error, error value otherwise (EINVAL if timeout_s is too
+ * \return 0 if no error, error value otherwise (-EINVAL if timeout_s is too
* big).
*
* This function is the same as spc300_wdt_start but using physical address.
*/
-int spc300_wdt_start_pa(uint timeout_s);
+static inline int spc300_wdt_start_pa(uint timeout_s)
+{
+ return spc300_wdt_start_(timeout_s, false);
+}
/**
- * Switch watchdog between user and kernel mode.
- *
- * \param use_umode 1 to switch to user mode.
+ * Refresh watchdog timer.
*/
-void spc300_wdt_switch(int use_umode);
+static inline void spc300_wdt_refresh(void)
+{
+ spc300_wdt_refresh_ (true);
+}
/**
- * Refresh watchdog timer.
+ * Refresh watchdog timer (using physical address).
*/
-void spc300_wdt_refresh(void);
+static inline void spc300_wdt_refresh_pa(void)
+{
+ spc300_wdt_refresh_ (false);
+}
/**
- * Refresh watchdog timer (using physical address).
+ * Switch watchdog between user and kernel mode.
+ *
+ * \param use_umode 1 to switch to user mode.
*/
-void spc300_wdt_refresh_pa(void);
+void spc300_wdt_switch(int use_umode);
/**
* Get the watchdog time interval.