1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/kernel.h>
17#include <linux/types.h>
18#include <linux/errno.h>
19#include <linux/err.h>
20#include <linux/io.h>
21
22#include <plat/common.h>
23
24#include "cm.h"
25#include "cm1_44xx.h"
26#include "cm2_44xx.h"
27#include "cm44xx.h"
28#include "cminst44xx.h"
29#include "cm-regbits-34xx.h"
30#include "cm-regbits-44xx.h"
31#include "prcm44xx.h"
32#include "prm44xx.h"
33#include "prcm_mpu44xx.h"
34
35static u32 _cm_bases[OMAP4_MAX_PRCM_PARTITIONS] = {
36 [OMAP4430_INVALID_PRCM_PARTITION] = 0,
37 [OMAP4430_PRM_PARTITION] = OMAP4430_PRM_BASE,
38 [OMAP4430_CM1_PARTITION] = OMAP4430_CM1_BASE,
39 [OMAP4430_CM2_PARTITION] = OMAP4430_CM2_BASE,
40 [OMAP4430_SCRM_PARTITION] = 0,
41 [OMAP4430_PRCM_MPU_PARTITION] = OMAP4430_PRCM_MPU_BASE,
42};
43
44
45u32 omap4_cminst_read_inst_reg(u8 part, s16 inst, u16 idx)
46{
47 BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
48 part == OMAP4430_INVALID_PRCM_PARTITION ||
49 !_cm_bases[part]);
50 return __raw_readl(OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
51}
52
53
54void omap4_cminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
55{
56 BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
57 part == OMAP4430_INVALID_PRCM_PARTITION ||
58 !_cm_bases[part]);
59 __raw_writel(val, OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
60}
61
62
63u32 omap4_cminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
64 s16 idx)
65{
66 u32 v;
67
68 v = omap4_cminst_read_inst_reg(part, inst, idx);
69 v &= ~mask;
70 v |= bits;
71 omap4_cminst_write_inst_reg(v, part, inst, idx);
72
73 return v;
74}
75
76u32 omap4_cminst_set_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
77{
78 return omap4_cminst_rmw_inst_reg_bits(bits, bits, part, inst, idx);
79}
80
81u32 omap4_cminst_clear_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
82{
83 return omap4_cminst_rmw_inst_reg_bits(bits, 0x0, part, inst, idx);
84}
85
86u32 omap4_cminst_read_inst_reg_bits(u8 part, u16 inst, s16 idx, u32 mask)
87{
88 u32 v;
89
90 v = omap4_cminst_read_inst_reg(part, inst, idx);
91 v &= mask;
92 v >>= __ffs(mask);
93
94 return v;
95}
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111static void _clktrctrl_write(u8 c, u8 part, s16 inst, u16 cdoffs)
112{
113 u32 v;
114
115 v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
116 v &= ~OMAP4430_CLKTRCTRL_MASK;
117 v |= c << OMAP4430_CLKTRCTRL_SHIFT;
118 omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
119}
120
121
122
123
124
125
126
127
128
129
130bool omap4_cminst_is_clkdm_in_hwsup(u8 part, s16 inst, u16 cdoffs)
131{
132 u32 v;
133
134 v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
135 v &= OMAP4430_CLKTRCTRL_MASK;
136 v >>= OMAP4430_CLKTRCTRL_SHIFT;
137
138 return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
139}
140
141
142
143
144
145
146
147
148
149
150void omap4_cminst_clkdm_enable_hwsup(u8 part, s16 inst, u16 cdoffs)
151{
152 _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
153}
154
155
156
157
158
159
160
161
162
163
164
165void omap4_cminst_clkdm_disable_hwsup(u8 part, s16 inst, u16 cdoffs)
166{
167 _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
168}
169
170
171
172
173
174
175
176
177
178
179void omap4_cminst_clkdm_force_sleep(u8 part, s16 inst, u16 cdoffs)
180{
181 _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, part, inst, cdoffs);
182}
183
184
185
186
187
188
189
190
191
192
193void omap4_cminst_clkdm_force_wakeup(u8 part, s16 inst, u16 cdoffs)
194{
195 _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
196}
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220int omap4_cm_wait_module_ready(void __iomem *clkctrl_reg)
221{
222 int i = 0;
223
224 if (!clkctrl_reg)
225 return 0;
226
227 omap_test_timeout((
228 ((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) == 0) ||
229 (((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) >>
230 OMAP4430_IDLEST_SHIFT) == 0x2)),
231 MAX_MODULE_READY_TIME, i);
232
233 return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
234}
235
236