• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2008 Simtec Electronics
4 //	Ben Dooks <ben@simtec.co.uk>
5 //
6 // Copyright (c) 2013 Tomasz Figa <tomasz.figa@gmail.com>
7 //
8 // Watchdog reset support for Samsung SoCs.
9 
10 #include <linux/clk.h>
11 #include <linux/err.h>
12 #include <linux/io.h>
13 #include <linux/delay.h>
14 #include <linux/of.h>
15 #include <linux/of_address.h>
16 
17 #define S3C2410_WTCON			0x00
18 #define S3C2410_WTDAT			0x04
19 #define S3C2410_WTCNT			0x08
20 
21 #define S3C2410_WTCON_ENABLE		(1 << 5)
22 #define S3C2410_WTCON_DIV16		(0 << 3)
23 #define S3C2410_WTCON_RSTEN		(1 << 0)
24 #define S3C2410_WTCON_PRESCALE(x)	((x) << 8)
25 
26 static void __iomem *wdt_base;
27 static struct clk *wdt_clock;
28 
samsung_wdt_reset(void)29 void samsung_wdt_reset(void)
30 {
31 	if (!wdt_base) {
32 		pr_err("%s: wdt reset not initialized\n", __func__);
33 		/* delay to allow the serial port to show the message */
34 		mdelay(50);
35 		return;
36 	}
37 
38 	if (!IS_ERR(wdt_clock))
39 		clk_prepare_enable(wdt_clock);
40 
41 	/* disable watchdog, to be safe  */
42 	__raw_writel(0, wdt_base + S3C2410_WTCON);
43 
44 	/* put initial values into count and data */
45 	__raw_writel(0x80, wdt_base + S3C2410_WTCNT);
46 	__raw_writel(0x80, wdt_base + S3C2410_WTDAT);
47 
48 	/* set the watchdog to go and reset... */
49 	__raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 |
50 			S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20),
51 			wdt_base + S3C2410_WTCON);
52 
53 	/* wait for reset to assert... */
54 	mdelay(500);
55 
56 	pr_err("Watchdog reset failed to assert reset\n");
57 
58 	/* delay to allow the serial port to show the message */
59 	mdelay(50);
60 }
61 
62 #ifdef CONFIG_OF
63 static const struct of_device_id s3c2410_wdt_match[] = {
64 	{ .compatible = "samsung,s3c2410-wdt" },
65 	{ .compatible = "samsung,s3c6410-wdt" },
66 	{},
67 };
68 
samsung_wdt_reset_of_init(void)69 void __init samsung_wdt_reset_of_init(void)
70 {
71 	struct device_node *np;
72 
73 	np = of_find_matching_node(NULL, s3c2410_wdt_match);
74 	if (!np) {
75 		pr_err("%s: failed to find watchdog node\n", __func__);
76 		return;
77 	}
78 
79 	wdt_base = of_iomap(np, 0);
80 	if (!wdt_base) {
81 		pr_err("%s: failed to map watchdog registers\n", __func__);
82 		return;
83 	}
84 
85 	wdt_clock = of_clk_get(np, 0);
86 }
87 #endif
88 
samsung_wdt_reset_init(void __iomem * base)89 void __init samsung_wdt_reset_init(void __iomem *base)
90 {
91 	wdt_base = base;
92 	wdt_clock = clk_get(NULL, "watchdog");
93 }
94