ARM: OMAP2+: CM: make clkdm_hwsup operations static
[deliverable/linux.git] / arch / arm / mach-omap2 / cminst44xx.c
CommitLineData
2ace831f
PW
1/*
2 * OMAP4 CM instance functions
3 *
4 * Copyright (C) 2009 Nokia Corporation
4bd5259e 5 * Copyright (C) 2008-2011 Texas Instruments, Inc.
2ace831f 6 * Paul Walmsley
4bd5259e 7 * Rajendra Nayak <rnayak@ti.com>
2ace831f
PW
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This is needed since CM instances can be in the PRM, PRCM_MPU, CM1,
14 * or CM2 hardware modules. For example, the EMU_CM CM instance is in
15 * the PRM hardware module. What a mess...
16 */
17
18#include <linux/kernel.h>
19#include <linux/types.h>
20#include <linux/errno.h>
21#include <linux/err.h>
22#include <linux/io.h>
23
4bd5259e 24#include "clockdomain.h"
2ace831f
PW
25#include "cm.h"
26#include "cm1_44xx.h"
27#include "cm2_44xx.h"
28#include "cm44xx.h"
29#include "cminst44xx.h"
bd2122ca 30#include "cm-regbits-34xx.h"
2ace831f
PW
31#include "prcm44xx.h"
32#include "prm44xx.h"
33#include "prcm_mpu44xx.h"
610eb8c2 34#include "prcm-common.h"
2ace831f 35
70fcebf1
TK
36#define OMAP4430_IDLEST_SHIFT 16
37#define OMAP4430_IDLEST_MASK (0x3 << 16)
38#define OMAP4430_CLKTRCTRL_SHIFT 0
39#define OMAP4430_CLKTRCTRL_MASK (0x3 << 0)
40#define OMAP4430_MODULEMODE_SHIFT 0
41#define OMAP4430_MODULEMODE_MASK (0x3 << 0)
42
d0f0631d
BC
43/*
44 * CLKCTRL_IDLEST_*: possible values for the CM_*_CLKCTRL.IDLEST bitfield:
45 *
46 * 0x0 func: Module is fully functional, including OCP
47 * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep
48 * abortion
49 * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if
50 * using separate functional clock
51 * 0x3 disabled: Module is disabled and cannot be accessed
52 *
53 */
54#define CLKCTRL_IDLEST_FUNCTIONAL 0x0
55#define CLKCTRL_IDLEST_INTRANSITION 0x1
56#define CLKCTRL_IDLEST_INTERFACE_IDLE 0x2
57#define CLKCTRL_IDLEST_DISABLED 0x3
58
610eb8c2
S
59static void __iomem *_cm_bases[OMAP4_MAX_PRCM_PARTITIONS];
60
61/**
62 * omap_cm_base_init - Populates the cm partitions
63 *
64 * Populates the base addresses of the _cm_bases
65 * array used for read/write of cm module registers.
66 */
67void omap_cm_base_init(void)
68{
69 _cm_bases[OMAP4430_PRM_PARTITION] = prm_base;
70 _cm_bases[OMAP4430_CM1_PARTITION] = cm_base;
71 _cm_bases[OMAP4430_CM2_PARTITION] = cm2_base;
72 _cm_bases[OMAP4430_PRCM_MPU_PARTITION] = prcm_mpu_base;
73}
2ace831f 74
d0f0631d
BC
75/* Private functions */
76
77/**
78 * _clkctrl_idlest - read a CM_*_CLKCTRL register; mask & shift IDLEST bitfield
79 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
80 * @inst: CM instance register offset (*_INST macro)
d0f0631d
BC
81 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
82 *
83 * Return the IDLEST bitfield of a CM_*_CLKCTRL register, shifted down to
84 * bit 0.
85 */
9907f85e 86static u32 _clkctrl_idlest(u8 part, u16 inst, u16 clkctrl_offs)
d0f0631d
BC
87{
88 u32 v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
89 v &= OMAP4430_IDLEST_MASK;
90 v >>= OMAP4430_IDLEST_SHIFT;
91 return v;
92}
93
94/**
95 * _is_module_ready - can module registers be accessed without causing an abort?
96 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
97 * @inst: CM instance register offset (*_INST macro)
d0f0631d
BC
98 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
99 *
100 * Returns true if the module's CM_*_CLKCTRL.IDLEST bitfield is either
101 * *FUNCTIONAL or *INTERFACE_IDLE; false otherwise.
102 */
9907f85e 103static bool _is_module_ready(u8 part, u16 inst, u16 clkctrl_offs)
d0f0631d
BC
104{
105 u32 v;
106
9907f85e 107 v = _clkctrl_idlest(part, inst, clkctrl_offs);
d0f0631d
BC
108
109 return (v == CLKCTRL_IDLEST_FUNCTIONAL ||
110 v == CLKCTRL_IDLEST_INTERFACE_IDLE) ? true : false;
111}
112
113/* Public functions */
114
2ace831f 115/* Read a register in a CM instance */
d3f5d551 116u32 omap4_cminst_read_inst_reg(u8 part, u16 inst, u16 idx)
2ace831f
PW
117{
118 BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
119 part == OMAP4430_INVALID_PRCM_PARTITION ||
120 !_cm_bases[part]);
edfaf05c 121 return readl_relaxed(_cm_bases[part] + inst + idx);
2ace831f
PW
122}
123
124/* Write into a register in a CM instance */
d3f5d551 125void omap4_cminst_write_inst_reg(u32 val, u8 part, u16 inst, u16 idx)
2ace831f
PW
126{
127 BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
128 part == OMAP4430_INVALID_PRCM_PARTITION ||
129 !_cm_bases[part]);
edfaf05c 130 writel_relaxed(val, _cm_bases[part] + inst + idx);
2ace831f
PW
131}
132
133/* Read-modify-write a register in CM1. Caller must lock */
d3f5d551 134u32 omap4_cminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, u16 inst,
2ace831f
PW
135 s16 idx)
136{
137 u32 v;
138
139 v = omap4_cminst_read_inst_reg(part, inst, idx);
140 v &= ~mask;
141 v |= bits;
142 omap4_cminst_write_inst_reg(v, part, inst, idx);
143
144 return v;
145}
146
d3f5d551 147u32 omap4_cminst_set_inst_reg_bits(u32 bits, u8 part, u16 inst, s16 idx)
04eb7773
RN
148{
149 return omap4_cminst_rmw_inst_reg_bits(bits, bits, part, inst, idx);
150}
151
d3f5d551 152u32 omap4_cminst_clear_inst_reg_bits(u32 bits, u8 part, u16 inst, s16 idx)
04eb7773
RN
153{
154 return omap4_cminst_rmw_inst_reg_bits(bits, 0x0, part, inst, idx);
155}
156
157u32 omap4_cminst_read_inst_reg_bits(u8 part, u16 inst, s16 idx, u32 mask)
158{
159 u32 v;
160
161 v = omap4_cminst_read_inst_reg(part, inst, idx);
162 v &= mask;
163 v >>= __ffs(mask);
164
165 return v;
166}
167
bd2122ca
PW
168/*
169 *
170 */
171
172/**
173 * _clktrctrl_write - write @c to a CM_CLKSTCTRL.CLKTRCTRL register bitfield
174 * @c: CLKTRCTRL register bitfield (LSB = bit 0, i.e., unshifted)
175 * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
176 * @inst: CM instance register offset (*_INST macro)
177 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
178 *
179 * @c must be the unshifted value for CLKTRCTRL - i.e., this function
180 * will handle the shift itself.
181 */
d3f5d551 182static void _clktrctrl_write(u8 c, u8 part, u16 inst, u16 cdoffs)
bd2122ca
PW
183{
184 u32 v;
185
186 v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
187 v &= ~OMAP4430_CLKTRCTRL_MASK;
188 v |= c << OMAP4430_CLKTRCTRL_SHIFT;
189 omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
190}
191
192/**
193 * omap4_cminst_is_clkdm_in_hwsup - is a clockdomain in hwsup idle mode?
194 * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
195 * @inst: CM instance register offset (*_INST macro)
196 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
197 *
198 * Returns true if the clockdomain referred to by (@part, @inst, @cdoffs)
199 * is in hardware-supervised idle mode, or 0 otherwise.
200 */
f2650d6e 201static bool omap4_cminst_is_clkdm_in_hwsup(u8 part, u16 inst, u16 cdoffs)
bd2122ca
PW
202{
203 u32 v;
204
205 v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
206 v &= OMAP4430_CLKTRCTRL_MASK;
207 v >>= OMAP4430_CLKTRCTRL_SHIFT;
208
209 return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
210}
211
212/**
213 * omap4_cminst_clkdm_enable_hwsup - put a clockdomain in hwsup-idle mode
214 * @part: PRCM partition ID that the clockdomain registers exist in
215 * @inst: CM instance register offset (*_INST macro)
216 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
217 *
218 * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
219 * hardware-supervised idle mode. No return value.
220 */
f2650d6e 221static void omap4_cminst_clkdm_enable_hwsup(u8 part, u16 inst, u16 cdoffs)
bd2122ca
PW
222{
223 _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
224}
225
226/**
227 * omap4_cminst_clkdm_disable_hwsup - put a clockdomain in swsup-idle mode
228 * @part: PRCM partition ID that the clockdomain registers exist in
229 * @inst: CM instance register offset (*_INST macro)
230 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
231 *
232 * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
233 * software-supervised idle mode, i.e., controlled manually by the
234 * Linux OMAP clockdomain code. No return value.
235 */
f2650d6e 236static void omap4_cminst_clkdm_disable_hwsup(u8 part, u16 inst, u16 cdoffs)
bd2122ca
PW
237{
238 _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
239}
240
bd2122ca
PW
241/**
242 * omap4_cminst_clkdm_force_sleep - try to take a clockdomain out of idle
243 * @part: PRCM partition ID that the clockdomain registers exist in
244 * @inst: CM instance register offset (*_INST macro)
245 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
246 *
247 * Take a clockdomain referred to by (@part, @inst, @cdoffs) out of idle,
248 * waking it up. No return value.
249 */
f2650d6e 250static void omap4_cminst_clkdm_force_wakeup(u8 part, u16 inst, u16 cdoffs)
bd2122ca
PW
251{
252 _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
253}
254
255/*
256 *
257 */
2ace831f 258
f2650d6e 259static void omap4_cminst_clkdm_force_sleep(u8 part, u16 inst, u16 cdoffs)
f67f04ba
DG
260{
261 _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, part, inst, cdoffs);
262}
263
2ace831f 264/**
d0f0631d
BC
265 * omap4_cminst_wait_module_ready - wait for a module to be in 'func' state
266 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
267 * @inst: CM instance register offset (*_INST macro)
d0f0631d 268 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
021b6ff0 269 * @bit_shift: bit shift for the register, ignored for OMAP4+
2ace831f
PW
270 *
271 * Wait for the module IDLEST to be functional. If the idle state is in any
272 * the non functional state (trans, idle or disabled), module and thus the
273 * sysconfig cannot be accessed and will probably lead to an "imprecise
274 * external abort"
2ace831f 275 */
021b6ff0
TK
276static int omap4_cminst_wait_module_ready(u8 part, s16 inst, u16 clkctrl_offs,
277 u8 bit_shift)
2ace831f
PW
278{
279 int i = 0;
280
d0f0631d 281 if (!clkctrl_offs)
2ace831f
PW
282 return 0;
283
9907f85e 284 omap_test_timeout(_is_module_ready(part, inst, clkctrl_offs),
d0f0631d 285 MAX_MODULE_READY_TIME, i);
2ace831f
PW
286
287 return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
288}
289
11b10341
BC
290/**
291 * omap4_cminst_wait_module_idle - wait for a module to be in 'disabled'
292 * state
293 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
294 * @inst: CM instance register offset (*_INST macro)
11b10341 295 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
a8ae5afa 296 * @bit_shift: Bit shift for the register, ignored for OMAP4+
11b10341
BC
297 *
298 * Wait for the module IDLEST to be disabled. Some PRCM transition,
299 * like reset assertion or parent clock de-activation must wait the
300 * module to be fully disabled.
301 */
a8ae5afa
TK
302static int omap4_cminst_wait_module_idle(u8 part, s16 inst, u16 clkctrl_offs,
303 u8 bit_shift)
11b10341
BC
304{
305 int i = 0;
306
307 if (!clkctrl_offs)
308 return 0;
309
9907f85e 310 omap_test_timeout((_clkctrl_idlest(part, inst, clkctrl_offs) ==
11b10341 311 CLKCTRL_IDLEST_DISABLED),
b8f15b7e 312 MAX_MODULE_DISABLE_TIME, i);
11b10341 313
b8f15b7e 314 return (i < MAX_MODULE_DISABLE_TIME) ? 0 : -EBUSY;
11b10341 315}
288d6a16
BC
316
317/**
318 * omap4_cminst_module_enable - Enable the modulemode inside CLKCTRL
319 * @mode: Module mode (SW or HW)
320 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
321 * @inst: CM instance register offset (*_INST macro)
322 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
323 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
324 *
325 * No return value.
326 */
327void omap4_cminst_module_enable(u8 mode, u8 part, u16 inst, s16 cdoffs,
328 u16 clkctrl_offs)
329{
330 u32 v;
331
332 v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
333 v &= ~OMAP4430_MODULEMODE_MASK;
334 v |= mode << OMAP4430_MODULEMODE_SHIFT;
335 omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
336}
337
338/**
339 * omap4_cminst_module_disable - Disable the module inside CLKCTRL
340 * @part: PRCM partition ID that the CM_CLKCTRL register exists in
341 * @inst: CM instance register offset (*_INST macro)
342 * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
343 * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
344 *
345 * No return value.
346 */
347void omap4_cminst_module_disable(u8 part, u16 inst, s16 cdoffs,
348 u16 clkctrl_offs)
349{
350 u32 v;
351
352 v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
353 v &= ~OMAP4430_MODULEMODE_MASK;
354 omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
355}
4bd5259e
PW
356
357/*
358 * Clockdomain low-level functions
359 */
360
361static int omap4_clkdm_add_wkup_sleep_dep(struct clockdomain *clkdm1,
362 struct clockdomain *clkdm2)
363{
364 omap4_cminst_set_inst_reg_bits((1 << clkdm2->dep_bit),
365 clkdm1->prcm_partition,
366 clkdm1->cm_inst, clkdm1->clkdm_offs +
367 OMAP4_CM_STATICDEP);
368 return 0;
369}
370
371static int omap4_clkdm_del_wkup_sleep_dep(struct clockdomain *clkdm1,
372 struct clockdomain *clkdm2)
373{
374 omap4_cminst_clear_inst_reg_bits((1 << clkdm2->dep_bit),
375 clkdm1->prcm_partition,
376 clkdm1->cm_inst, clkdm1->clkdm_offs +
377 OMAP4_CM_STATICDEP);
378 return 0;
379}
380
381static int omap4_clkdm_read_wkup_sleep_dep(struct clockdomain *clkdm1,
382 struct clockdomain *clkdm2)
383{
384 return omap4_cminst_read_inst_reg_bits(clkdm1->prcm_partition,
385 clkdm1->cm_inst,
386 clkdm1->clkdm_offs +
387 OMAP4_CM_STATICDEP,
388 (1 << clkdm2->dep_bit));
389}
390
391static int omap4_clkdm_clear_all_wkup_sleep_deps(struct clockdomain *clkdm)
392{
393 struct clkdm_dep *cd;
394 u32 mask = 0;
395
396 if (!clkdm->prcm_partition)
397 return 0;
398
399 for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
400 if (!cd->clkdm)
401 continue; /* only happens if data is erroneous */
402
403 mask |= 1 << cd->clkdm->dep_bit;
92493870 404 cd->wkdep_usecount = 0;
4bd5259e
PW
405 }
406
407 omap4_cminst_clear_inst_reg_bits(mask, clkdm->prcm_partition,
408 clkdm->cm_inst, clkdm->clkdm_offs +
409 OMAP4_CM_STATICDEP);
410 return 0;
411}
412
413static int omap4_clkdm_sleep(struct clockdomain *clkdm)
414{
f67f04ba
DG
415 if (clkdm->flags & CLKDM_CAN_HWSUP)
416 omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
417 clkdm->cm_inst,
418 clkdm->clkdm_offs);
419 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP)
420 omap4_cminst_clkdm_force_sleep(clkdm->prcm_partition,
421 clkdm->cm_inst,
422 clkdm->clkdm_offs);
423 else
424 return -EINVAL;
425
4bd5259e
PW
426 return 0;
427}
428
429static int omap4_clkdm_wakeup(struct clockdomain *clkdm)
430{
431 omap4_cminst_clkdm_force_wakeup(clkdm->prcm_partition,
432 clkdm->cm_inst, clkdm->clkdm_offs);
433 return 0;
434}
435
436static void omap4_clkdm_allow_idle(struct clockdomain *clkdm)
437{
438 omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
439 clkdm->cm_inst, clkdm->clkdm_offs);
440}
441
442static void omap4_clkdm_deny_idle(struct clockdomain *clkdm)
443{
444 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
445 omap4_clkdm_wakeup(clkdm);
446 else
447 omap4_cminst_clkdm_disable_hwsup(clkdm->prcm_partition,
448 clkdm->cm_inst,
449 clkdm->clkdm_offs);
450}
451
452static int omap4_clkdm_clk_enable(struct clockdomain *clkdm)
453{
454 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
455 return omap4_clkdm_wakeup(clkdm);
456
457 return 0;
458}
459
460static int omap4_clkdm_clk_disable(struct clockdomain *clkdm)
461{
462 bool hwsup = false;
463
464 if (!clkdm->prcm_partition)
465 return 0;
466
467 /*
468 * The CLKDM_MISSING_IDLE_REPORTING flag documentation has
469 * more details on the unpleasant problem this is working
470 * around
471 */
472 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING &&
473 !(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
474 omap4_clkdm_allow_idle(clkdm);
475 return 0;
476 }
477
478 hwsup = omap4_cminst_is_clkdm_in_hwsup(clkdm->prcm_partition,
479 clkdm->cm_inst, clkdm->clkdm_offs);
480
481 if (!hwsup && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
482 omap4_clkdm_sleep(clkdm);
483
484 return 0;
485}
486
487struct clkdm_ops omap4_clkdm_operations = {
488 .clkdm_add_wkdep = omap4_clkdm_add_wkup_sleep_dep,
489 .clkdm_del_wkdep = omap4_clkdm_del_wkup_sleep_dep,
490 .clkdm_read_wkdep = omap4_clkdm_read_wkup_sleep_dep,
491 .clkdm_clear_all_wkdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
492 .clkdm_add_sleepdep = omap4_clkdm_add_wkup_sleep_dep,
493 .clkdm_del_sleepdep = omap4_clkdm_del_wkup_sleep_dep,
494 .clkdm_read_sleepdep = omap4_clkdm_read_wkup_sleep_dep,
495 .clkdm_clear_all_sleepdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
496 .clkdm_sleep = omap4_clkdm_sleep,
497 .clkdm_wakeup = omap4_clkdm_wakeup,
498 .clkdm_allow_idle = omap4_clkdm_allow_idle,
499 .clkdm_deny_idle = omap4_clkdm_deny_idle,
500 .clkdm_clk_enable = omap4_clkdm_clk_enable,
501 .clkdm_clk_disable = omap4_clkdm_clk_disable,
502};
c9218fe6
A
503
504struct clkdm_ops am43xx_clkdm_operations = {
505 .clkdm_sleep = omap4_clkdm_sleep,
506 .clkdm_wakeup = omap4_clkdm_wakeup,
507 .clkdm_allow_idle = omap4_clkdm_allow_idle,
508 .clkdm_deny_idle = omap4_clkdm_deny_idle,
509 .clkdm_clk_enable = omap4_clkdm_clk_enable,
510 .clkdm_clk_disable = omap4_clkdm_clk_disable,
511};
7632a02f 512
021b6ff0
TK
513static struct cm_ll_data omap4xxx_cm_ll_data = {
514 .wait_module_ready = &omap4_cminst_wait_module_ready,
a8ae5afa 515 .wait_module_idle = &omap4_cminst_wait_module_idle,
021b6ff0 516};
7632a02f
TK
517
518int __init omap4_cm_init(void)
519{
520 return cm_register(&omap4xxx_cm_ll_data);
521}
522
523static void __exit omap4_cm_exit(void)
524{
525 cm_unregister(&omap4xxx_cm_ll_data);
526}
527__exitcall(omap4_cm_exit);
This page took 0.232402 seconds and 5 git commands to generate.