blob: 5a8629ff0ab0e8c0cbe5013ac6c381b8f2b8ba7c [file] [log] [blame]
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -07001/*
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
Paul Walmsley37c67d02012-10-29 20:49:44 -060014#include <linux/platform_data/omap-wd-timer.h>
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070015
Paul Walmsley37c67d02012-10-29 20:49:44 -060016#include "omap_hwmod.h"
17#include "omap_device.h"
Nishanth Menona9b365b2011-01-06 19:49:29 -080018#include "wd_timer.h"
Kevin Hilman414e4122012-05-08 11:34:30 -060019#include "common.h"
Paul Walmsley37c67d02012-10-29 20:49:44 -060020#include "prm.h"
21#include "soc.h"
Nishanth Menona9b365b2011-01-06 19:49:29 -080022
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070023/*
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
Kevin Hilman414e4122012-05-08 11:34:30 -060033/* Maximum microseconds to wait for OMAP module to softreset */
34#define MAX_MODULE_SOFTRESET_WAIT 10000
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070035
36int omap2_wd_timer_disable(struct omap_hwmod *oh)
37{
38 void __iomem *base;
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070039
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
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070052 /* 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
Paul Walmsleyff2516f2010-12-21 15:39:15 -070061 return 0;
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -070062}
63
Kevin Hilman414e4122012-05-08 11:34:30 -060064/**
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 */
80int 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}
Paul Walmsley37c67d02012-10-29 20:49:44 -0600106
107static 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}
134subsys_initcall(omap_init_wdt);