--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * arch/arm/src/s5j/chip/s5j200_watchdog.h
+ *
+ * Copyright (C) 2009-2010, 2014-2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_S5J_CHIP_S5JT200_WATCHDOG_H
+#define __ARCH_ARM_SRC_S5J_CHIP_S5JT200_WATCHDOG_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register Address *********************************************************/
+#define S5J_WDT_WTCON 0x80030000
+#define S5J_WDT_WTDAT 0x80030004
+#define S5J_WDT_WTCNT 0x80030008
+#define S5J_WDT_WTCLRINT 0x8003000C
+
+#define S5J_WDT_OSC (26*1000*1000)
+
+/* Register Bitfield Definitions ********************************************/
+
+/* WTCON register */
+#define WTCON_PRESCALER(a) ((a & 0xF) << 8)
+#define WTCON_WATCHDOG_EN (1 << 5)
+#define WTCON_WATCHDOG_DIS (0 << 5)
+#define WTCON_CLOCK(a) ((a & 0x3) << 3)
+#define WTCON_IRQ_EN (1 << 2)
+#define WTCON_IRQ_DIS (0 << 2)
+#define WTCON_RESET_EN (1 << 0)
+#define WTCON_RESET_DIS (0 << 0)
+
+#endif /* __ARCH_ARM_SRC_S5J_CHIP_S5JT200_WATCHDOG_H */
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-#define WTCON 0x0000
-#define WTDAT 0x0004
-#define WTCNT 0x0008
-#define WTCLRINT 0x000C
-
-#define WTCON_RESET_MASK (1 << 0)
-#define WTCON_RESET_DIS (0 << 0)
-#define WTCON_RESET_EN (1 << 0)
-
-#define WTCON_IRQ_MASK (1 << 2)
-#define WTCON_IRQ_DIS (0 << 2)
-#define WTCON_IRQ_EN (1 << 2)
-
-#define WTCON_CLK_DIV_MASK (3 << 3)
-#define WTCON_CLK_DIV(x) ((x & 3) << 3)
-
-#define WTCON_EN_MASK (1 << 5)
-#define WTCON_DIS (0 << 5)
-#define WTCON_EN (1 << 5)
-
-#define WTCON_PRESCALER_MASK (0xF << 8)
-#define WTCON_PRESCALER(x) ((x & 0xF) << 8)
/****************************************************************************
* Public Functions
****************************************************************************/
void s5j_watchdog_disable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_EN_MASK) | WTCON_DIS;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_WATCHDOG_EN) | WTCON_WATCHDOG_DIS;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
#ifdef CONFIG_S5J_WATCHDOG
****************************************************************************/
void s5j_watchdog_enable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_EN_MASK) | WTCON_EN;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_WATCHDOG_EN) | WTCON_WATCHDOG_EN;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_reset_disable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_RESET_MASK) | WTCON_RESET_DIS;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_RESET_EN) | WTCON_RESET_DIS;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_reset_enable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_RESET_MASK) | WTCON_RESET_EN;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_RESET_EN) | WTCON_RESET_EN;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_irq_disable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_IRQ_MASK) | WTCON_IRQ_DIS;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_IRQ_EN) | WTCON_IRQ_DIS;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_irq_enable(void)
{
- unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_IRQ_MASK) | WTCON_IRQ_EN;
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_IRQ_EN) | WTCON_IRQ_EN;
+
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_clk_set(unsigned int prescaler, unsigned int divider)
{
- unsigned int wtcon = getreg32(S5J_WDT_BASE + WTCON);
+ unsigned int wtcon = getreg32(S5J_WDT_WTCON);
- wtcon &= ~(WTCON_PRESCALER_MASK | WTCON_CLK_DIV_MASK);
- wtcon |= WTCON_CLK_DIV(divider) | WTCON_PRESCALER(prescaler);
+ wtcon &= ~(WTCON_PRESCALER(0xFF) | WTCON_CLOCK(3));
+ wtcon |= WTCON_CLOCK(divider) | WTCON_PRESCALER(prescaler);
- putreg32(wtcon, S5J_WDT_BASE + WTCON);
+ putreg32(wtcon, S5J_WDT_WTCON);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_set_reload_val(unsigned int reload_val)
{
- putreg32(reload_val, S5J_WDT_BASE + WTDAT);
+ putreg32(reload_val, S5J_WDT_WTDAT);
}
/****************************************************************************
****************************************************************************/
unsigned int s5j_watchdog_get_curr(void)
{
- return getreg32(S5J_WDT_BASE + WTCNT);
+ return getreg32(S5J_WDT_WTCNT);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_set_curr(unsigned int curr_val)
{
- putreg32(curr_val, S5J_WDT_BASE + WTCNT);
+ putreg32(curr_val, S5J_WDT_WTCNT);
}
/****************************************************************************
****************************************************************************/
void s5j_watchdog_clear_int(void)
{
- putreg32(0xffffffff, S5J_WDT_BASE + WTCLRINT);
+ putreg32(0xffffffff, S5J_WDT_WTCLRINT);
}
#endif