Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / arm / plat-samsung / watchdog-reset.c
blob2ecb50bea04462c89ebb471273c4dcbcdfb5b85a
1 /* arch/arm/plat-samsung/watchdog-reset.c
3 * Copyright (c) 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Coyright (c) 2013 Tomasz Figa <tomasz.figa@gmail.com>
8 * Watchdog reset support for Samsung SoCs.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/io.h>
18 #include <linux/delay.h>
19 #include <linux/of.h>
20 #include <linux/of_address.h>
22 #define S3C2410_WTCON 0x00
23 #define S3C2410_WTDAT 0x04
24 #define S3C2410_WTCNT 0x08
26 #define S3C2410_WTCON_ENABLE (1 << 5)
27 #define S3C2410_WTCON_DIV16 (0 << 3)
28 #define S3C2410_WTCON_RSTEN (1 << 0)
29 #define S3C2410_WTCON_PRESCALE(x) ((x) << 8)
31 static void __iomem *wdt_base;
32 static struct clk *wdt_clock;
34 void samsung_wdt_reset(void)
36 if (!wdt_base) {
37 pr_err("%s: wdt reset not initialized\n", __func__);
38 /* delay to allow the serial port to show the message */
39 mdelay(50);
40 return;
43 if (!IS_ERR(wdt_clock))
44 clk_prepare_enable(wdt_clock);
46 /* disable watchdog, to be safe */
47 __raw_writel(0, wdt_base + S3C2410_WTCON);
49 /* put initial values into count and data */
50 __raw_writel(0x80, wdt_base + S3C2410_WTCNT);
51 __raw_writel(0x80, wdt_base + S3C2410_WTDAT);
53 /* set the watchdog to go and reset... */
54 __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 |
55 S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20),
56 wdt_base + S3C2410_WTCON);
58 /* wait for reset to assert... */
59 mdelay(500);
61 pr_err("Watchdog reset failed to assert reset\n");
63 /* delay to allow the serial port to show the message */
64 mdelay(50);
67 #ifdef CONFIG_OF
68 static const struct of_device_id s3c2410_wdt_match[] = {
69 { .compatible = "samsung,s3c2410-wdt" },
70 {},
73 void __init samsung_wdt_reset_of_init(void)
75 struct device_node *np;
77 np = of_find_matching_node(NULL, s3c2410_wdt_match);
78 if (!np) {
79 pr_err("%s: failed to find watchdog node\n", __func__);
80 return;
83 wdt_base = of_iomap(np, 0);
84 if (!wdt_base) {
85 pr_err("%s: failed to map watchdog registers\n", __func__);
86 return;
89 wdt_clock = of_clk_get(np, 0);
91 #endif
93 void __init samsung_wdt_reset_init(void __iomem *base)
95 wdt_base = base;
96 wdt_clock = clk_get(NULL, "watchdog");