Commit | Line | Data |
---|---|---|
81fbc5ef PW |
1 | /* |
2 | * OMAP2+ MPU WD_TIMER-specific code | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | */ | |
9 | ||
10 | #include <linux/kernel.h> | |
11 | #include <linux/io.h> | |
12 | #include <linux/err.h> | |
13 | ||
37c67d03 | 14 | #include <linux/platform_data/omap-wd-timer.h> |
81fbc5ef | 15 | |
37c67d03 PW |
16 | #include "omap_hwmod.h" |
17 | #include "omap_device.h" | |
a9b365bd | 18 | #include "wd_timer.h" |
414e4128 | 19 | #include "common.h" |
37c67d03 PW |
20 | #include "prm.h" |
21 | #include "soc.h" | |
a9b365bd | 22 | |
81fbc5ef PW |
23 | /* |
24 | * In order to avoid any assumptions from bootloader regarding WDT | |
25 | * settings, WDT module is reset during init. This enables the watchdog | |
26 | * timer. Hence it is required to disable the watchdog after the WDT reset | |
27 | * during init. Otherwise the system would reboot as per the default | |
28 | * watchdog timer registers settings. | |
29 | */ | |
30 | #define OMAP_WDT_WPS 0x34 | |
31 | #define OMAP_WDT_SPR 0x48 | |
32 | ||
414e4128 KH |
33 | /* Maximum microseconds to wait for OMAP module to softreset */ |
34 | #define MAX_MODULE_SOFTRESET_WAIT 10000 | |
81fbc5ef PW |
35 | |
36 | int omap2_wd_timer_disable(struct omap_hwmod *oh) | |
37 | { | |
38 | void __iomem *base; | |
81fbc5ef PW |
39 | |
40 | if (!oh) { | |
41 | pr_err("%s: Could not look up wdtimer_hwmod\n", __func__); | |
42 | return -EINVAL; | |
43 | } | |
44 | ||
45 | base = omap_hwmod_get_mpu_rt_va(oh); | |
46 | if (!base) { | |
47 | pr_err("%s: Could not get the base address for %s\n", | |
48 | oh->name, __func__); | |
49 | return -EINVAL; | |
50 | } | |
51 | ||
81fbc5ef PW |
52 | /* sequence required to disable watchdog */ |
53 | __raw_writel(0xAAAA, base + OMAP_WDT_SPR); | |
54 | while (__raw_readl(base + OMAP_WDT_WPS) & 0x10) | |
55 | cpu_relax(); | |
56 | ||
57 | __raw_writel(0x5555, base + OMAP_WDT_SPR); | |
58 | while (__raw_readl(base + OMAP_WDT_WPS) & 0x10) | |
59 | cpu_relax(); | |
60 | ||
ff2516fb | 61 | return 0; |
81fbc5ef PW |
62 | } |
63 | ||
414e4128 KH |
64 | /** |
65 | * omap2_wdtimer_reset - reset and disable the WDTIMER IP block | |
66 | * @oh: struct omap_hwmod * | |
67 | * | |
68 | * After the WDTIMER IP blocks are reset on OMAP2/3, we must also take | |
69 | * care to execute the special watchdog disable sequence. This is | |
70 | * because the watchdog is re-armed upon OCP softreset. (On OMAP4, | |
71 | * this behavior was apparently changed and the watchdog is no longer | |
72 | * re-armed after an OCP soft-reset.) Returns -ETIMEDOUT if the reset | |
73 | * did not complete, or 0 upon success. | |
74 | * | |
75 | * XXX Most of this code should be moved to the omap_hwmod.c layer | |
76 | * during a normal merge window. omap_hwmod_softreset() should be | |
77 | * renamed to omap_hwmod_set_ocp_softreset(), and omap_hwmod_softreset() | |
78 | * should call the hwmod _ocp_softreset() code. | |
79 | */ | |
80 | int omap2_wd_timer_reset(struct omap_hwmod *oh) | |
81 | { | |
82 | int c = 0; | |
83 | ||
84 | /* Write to the SOFTRESET bit */ | |
85 | omap_hwmod_softreset(oh); | |
86 | ||
87 | /* Poll on RESETDONE bit */ | |
88 | omap_test_timeout((omap_hwmod_read(oh, | |
89 | oh->class->sysc->syss_offs) | |
90 | & SYSS_RESETDONE_MASK), | |
91 | MAX_MODULE_SOFTRESET_WAIT, c); | |
92 | ||
93 | if (oh->class->sysc->srst_udelay) | |
94 | udelay(oh->class->sysc->srst_udelay); | |
95 | ||
96 | if (c == MAX_MODULE_SOFTRESET_WAIT) | |
97 | pr_warning("%s: %s: softreset failed (waited %d usec)\n", | |
98 | __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT); | |
99 | else | |
100 | pr_debug("%s: %s: softreset in %d usec\n", __func__, | |
101 | oh->name, c); | |
102 | ||
103 | return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : | |
104 | omap2_wd_timer_disable(oh); | |
105 | } | |
37c67d03 PW |
106 | |
107 | static int __init omap_init_wdt(void) | |
108 | { | |
109 | int id = -1; | |
110 | struct platform_device *pdev; | |
111 | struct omap_hwmod *oh; | |
112 | char *oh_name = "wd_timer2"; | |
113 | char *dev_name = "omap_wdt"; | |
114 | struct omap_wd_timer_platform_data pdata; | |
115 | ||
116 | if (!cpu_class_is_omap2() || of_have_populated_dt()) | |
117 | return 0; | |
118 | ||
119 | oh = omap_hwmod_lookup(oh_name); | |
120 | if (!oh) { | |
121 | pr_err("Could not look up wd_timer%d hwmod\n", id); | |
122 | return -EINVAL; | |
123 | } | |
124 | ||
125 | pdata.read_reset_sources = prm_read_reset_sources; | |
126 | ||
127 | pdev = omap_device_build(dev_name, id, oh, &pdata, | |
128 | sizeof(struct omap_wd_timer_platform_data), | |
129 | NULL, 0, 0); | |
130 | WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n", | |
131 | dev_name, oh->name); | |
132 | return 0; | |
133 | } | |
134 | subsys_initcall(omap_init_wdt); |