1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/kernel.h>
20#include <linux/clk.h>
21#include <linux/io.h>
22#include <linux/err.h>
23#include <linux/delay.h>
24#include <linux/init.h>
25#include <linux/module.h>
26
27#include <asm/proc-fns.h>
28#include <asm/system.h>
29
30#include <mach/mxs.h>
31#include <mach/common.h>
32
33#define MX23_CLKCTRL_RESET_OFFSET 0x120
34#define MX28_CLKCTRL_RESET_OFFSET 0x1e0
35#define MXS_CLKCTRL_RESET_CHIP (1 << 1)
36
37#define MXS_MODULE_CLKGATE (1 << 30)
38#define MXS_MODULE_SFTRST (1 << 31)
39
40static void __iomem *mxs_clkctrl_reset_addr;
41
42
43
44
45void arch_reset(char mode, const char *cmd)
46{
47
48 __mxs_setl(MXS_CLKCTRL_RESET_CHIP, mxs_clkctrl_reset_addr);
49
50 pr_err("Failed to assert the chip reset\n");
51
52
53 mdelay(50);
54
55
56 cpu_reset(0);
57}
58
59static int __init mxs_arch_reset_init(void)
60{
61 struct clk *clk;
62
63 mxs_clkctrl_reset_addr = MXS_IO_ADDRESS(MXS_CLKCTRL_BASE_ADDR) +
64 (cpu_is_mx23() ? MX23_CLKCTRL_RESET_OFFSET :
65 MX28_CLKCTRL_RESET_OFFSET);
66
67 clk = clk_get_sys("rtc", NULL);
68 if (!IS_ERR(clk))
69 clk_enable(clk);
70
71 return 0;
72}
73core_initcall(mxs_arch_reset_init);
74
75
76
77
78
79
80static int clear_poll_bit(void __iomem *addr, u32 mask)
81{
82 int timeout = 0x400;
83
84
85 __mxs_clrl(mask, addr);
86
87
88
89
90
91 udelay(1);
92
93
94 while ((__raw_readl(addr) & mask) && --timeout)
95 ;
96
97 return !timeout;
98}
99
100int mxs_reset_block(void __iomem *reset_addr)
101{
102 int ret;
103 int timeout = 0x400;
104
105
106 ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
107 if (unlikely(ret))
108 goto error;
109
110
111 __mxs_clrl(MXS_MODULE_CLKGATE, reset_addr);
112
113
114 __mxs_setl(MXS_MODULE_SFTRST, reset_addr);
115 udelay(1);
116
117
118 while ((!(__raw_readl(reset_addr) & MXS_MODULE_CLKGATE)) && --timeout)
119 ;
120 if (unlikely(!timeout))
121 goto error;
122
123
124 ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
125 if (unlikely(ret))
126 goto error;
127
128
129 ret = clear_poll_bit(reset_addr, MXS_MODULE_CLKGATE);
130 if (unlikely(ret))
131 goto error;
132
133 return 0;
134
135error:
136 pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
137 return -ETIMEDOUT;
138}
139EXPORT_SYMBOL(mxs_reset_block);
140