blob: 9db1bd279f8eb8b4e93082e8989875d3d28834f4 [file] [log] [blame]
Benoît Cousson0be16212010-09-21 10:34:10 -06001/*
2 * OMAP4 PRM module functions
3 *
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -06004 * Copyright (C) 2011-2012 Texas Instruments, Inc.
Benoît Cousson0be16212010-09-21 10:34:10 -06005 * Copyright (C) 2010 Nokia Corporation
6 * Benoît Cousson
7 * Paul Walmsley
Paul Walmsley49815392012-10-21 01:01:10 -06008 * Rajendra Nayak <rnayak@ti.com>
Benoît Cousson0be16212010-09-21 10:34:10 -06009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/kernel.h>
16#include <linux/delay.h>
17#include <linux/errno.h>
18#include <linux/err.h>
Paul Walmsley2ace8312010-12-21 21:05:14 -070019#include <linux/io.h>
Benoît Cousson0be16212010-09-21 10:34:10 -060020
Benoît Cousson0be16212010-09-21 10:34:10 -060021
Tony Lindgrendbc04162012-08-31 10:59:07 -070022#include "soc.h"
Tony Lindgrenee0839c2012-02-24 10:34:35 -080023#include "iomap.h"
24#include "common.h"
Kevin Hilman58aaa592011-03-28 10:52:04 -070025#include "vp.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -070026#include "prm44xx.h"
Benoît Cousson0be16212010-09-21 10:34:10 -060027#include "prm-regbits-44xx.h"
Kevin Hilman4bb73ad2011-03-28 10:25:12 -070028#include "prcm44xx.h"
29#include "prminst44xx.h"
Paul Walmsley49815392012-10-21 01:01:10 -060030#include "powerdomain.h"
Benoît Cousson0be16212010-09-21 10:34:10 -060031
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060032/* Static data */
33
Tero Kristo2f31b512011-12-16 14:37:00 -070034static const struct omap_prcm_irq omap4_prcm_irqs[] = {
35 OMAP_PRCM_IRQ("wkup", 0, 0),
36 OMAP_PRCM_IRQ("io", 9, 1),
37};
38
39static struct omap_prcm_irq_setup omap4_prcm_irq_setup = {
40 .ack = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
41 .mask = OMAP4_PRM_IRQENABLE_MPU_OFFSET,
42 .nr_regs = 2,
43 .irqs = omap4_prcm_irqs,
44 .nr_irqs = ARRAY_SIZE(omap4_prcm_irqs),
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070045 .irq = 11 + OMAP44XX_IRQ_GIC_START,
Tero Kristo2f31b512011-12-16 14:37:00 -070046 .read_pending_irqs = &omap44xx_prm_read_pending_irqs,
47 .ocp_barrier = &omap44xx_prm_ocp_barrier,
48 .save_and_clear_irqen = &omap44xx_prm_save_and_clear_irqen,
49 .restore_irqen = &omap44xx_prm_restore_irqen,
50};
51
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060052/*
53 * omap44xx_prm_reset_src_map - map from bits in the PRM_RSTST
54 * hardware register (which are specific to OMAP44xx SoCs) to reset
55 * source ID bit shifts (which is an OMAP SoC-independent
56 * enumeration)
57 */
58static struct prm_reset_src_map omap44xx_prm_reset_src_map[] = {
59 { OMAP4430_RST_GLOBAL_WARM_SW_SHIFT,
60 OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT },
61 { OMAP4430_RST_GLOBAL_COLD_SW_SHIFT,
62 OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT },
63 { OMAP4430_MPU_SECURITY_VIOL_RST_SHIFT,
64 OMAP_SECU_VIOL_RST_SRC_ID_SHIFT },
65 { OMAP4430_MPU_WDT_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
66 { OMAP4430_SECURE_WDT_RST_SHIFT, OMAP_SECU_WD_RST_SRC_ID_SHIFT },
67 { OMAP4430_EXTERNAL_WARM_RST_SHIFT, OMAP_EXTWARM_RST_SRC_ID_SHIFT },
68 { OMAP4430_VDD_MPU_VOLT_MGR_RST_SHIFT,
69 OMAP_VDD_MPU_VM_RST_SRC_ID_SHIFT },
70 { OMAP4430_VDD_IVA_VOLT_MGR_RST_SHIFT,
71 OMAP_VDD_IVA_VM_RST_SRC_ID_SHIFT },
72 { OMAP4430_VDD_CORE_VOLT_MGR_RST_SHIFT,
73 OMAP_VDD_CORE_VM_RST_SRC_ID_SHIFT },
74 { OMAP4430_ICEPICK_RST_SHIFT, OMAP_ICEPICK_RST_SRC_ID_SHIFT },
75 { OMAP4430_C2C_RST_SHIFT, OMAP_C2C_RST_SRC_ID_SHIFT },
76 { -1, -1 },
77};
78
Paul Walmsley2ace8312010-12-21 21:05:14 -070079/* PRM low-level functions */
80
81/* Read a register in a CM/PRM instance in the PRM module */
82u32 omap4_prm_read_inst_reg(s16 inst, u16 reg)
83{
84 return __raw_readl(OMAP44XX_PRM_REGADDR(inst, reg));
85}
86
87/* Write into a register in a CM/PRM instance in the PRM module */
88void omap4_prm_write_inst_reg(u32 val, s16 inst, u16 reg)
89{
90 __raw_writel(val, OMAP44XX_PRM_REGADDR(inst, reg));
91}
92
93/* Read-modify-write a register in a PRM module. Caller must lock */
94u32 omap4_prm_rmw_inst_reg_bits(u32 mask, u32 bits, s16 inst, s16 reg)
95{
96 u32 v;
97
98 v = omap4_prm_read_inst_reg(inst, reg);
99 v &= ~mask;
100 v |= bits;
101 omap4_prm_write_inst_reg(v, inst, reg);
102
103 return v;
104}
Kevin Hilman58aaa592011-03-28 10:52:04 -0700105
106/* PRM VP */
107
108/*
109 * struct omap4_vp - OMAP4 VP register access description.
110 * @irqstatus_mpu: offset to IRQSTATUS_MPU register for VP
111 * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
112 */
113struct omap4_vp {
114 u32 irqstatus_mpu;
115 u32 tranxdone_status;
116};
117
118static struct omap4_vp omap4_vp[] = {
119 [OMAP4_VP_VDD_MPU_ID] = {
120 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET,
121 .tranxdone_status = OMAP4430_VP_MPU_TRANXDONE_ST_MASK,
122 },
123 [OMAP4_VP_VDD_IVA_ID] = {
124 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
125 .tranxdone_status = OMAP4430_VP_IVA_TRANXDONE_ST_MASK,
126 },
127 [OMAP4_VP_VDD_CORE_ID] = {
128 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
129 .tranxdone_status = OMAP4430_VP_CORE_TRANXDONE_ST_MASK,
130 },
131};
132
133u32 omap4_prm_vp_check_txdone(u8 vp_id)
134{
135 struct omap4_vp *vp = &omap4_vp[vp_id];
136 u32 irqstatus;
137
138 irqstatus = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
139 OMAP4430_PRM_OCP_SOCKET_INST,
140 vp->irqstatus_mpu);
141 return irqstatus & vp->tranxdone_status;
142}
143
144void omap4_prm_vp_clear_txdone(u8 vp_id)
145{
146 struct omap4_vp *vp = &omap4_vp[vp_id];
147
148 omap4_prminst_write_inst_reg(vp->tranxdone_status,
149 OMAP4430_PRM_PARTITION,
150 OMAP4430_PRM_OCP_SOCKET_INST,
151 vp->irqstatus_mpu);
152};
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700153
154u32 omap4_prm_vcvp_read(u8 offset)
155{
156 return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
157 OMAP4430_PRM_DEVICE_INST, offset);
158}
159
160void omap4_prm_vcvp_write(u32 val, u8 offset)
161{
162 omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION,
163 OMAP4430_PRM_DEVICE_INST, offset);
164}
165
166u32 omap4_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
167{
168 return omap4_prminst_rmw_inst_reg_bits(mask, bits,
169 OMAP4430_PRM_PARTITION,
170 OMAP4430_PRM_DEVICE_INST,
171 offset);
172}
Paul Walmsley26c98c52011-12-16 14:36:58 -0700173
174static inline u32 _read_pending_irq_reg(u16 irqen_offs, u16 irqst_offs)
175{
176 u32 mask, st;
177
178 /* XXX read mask from RAM? */
Tero Kristo553e3222012-03-12 04:30:02 -0600179 mask = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
180 irqen_offs);
181 st = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST, irqst_offs);
Paul Walmsley26c98c52011-12-16 14:36:58 -0700182
183 return mask & st;
184}
185
186/**
187 * omap44xx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
188 * @events: ptr to two consecutive u32s, preallocated by caller
189 *
190 * Read PRM_IRQSTATUS_MPU* bits, AND'ed with the currently-enabled PRM
191 * MPU IRQs, and store the result into the two u32s pointed to by @events.
192 * No return value.
193 */
194void omap44xx_prm_read_pending_irqs(unsigned long *events)
195{
196 events[0] = _read_pending_irq_reg(OMAP4_PRM_IRQENABLE_MPU_OFFSET,
197 OMAP4_PRM_IRQSTATUS_MPU_OFFSET);
198
199 events[1] = _read_pending_irq_reg(OMAP4_PRM_IRQENABLE_MPU_2_OFFSET,
200 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET);
201}
202
203/**
204 * omap44xx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
205 *
206 * Force any buffered writes to the PRM IP block to complete. Needed
207 * by the PRM IRQ handler, which reads and writes directly to the IP
208 * block, to avoid race conditions after acknowledging or clearing IRQ
209 * bits. No return value.
210 */
211void omap44xx_prm_ocp_barrier(void)
212{
Tero Kristo553e3222012-03-12 04:30:02 -0600213 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Paul Walmsley26c98c52011-12-16 14:36:58 -0700214 OMAP4_REVISION_PRM_OFFSET);
215}
Tero Kristo91285b62011-12-16 14:36:58 -0700216
217/**
218 * omap44xx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU* regs
219 * @saved_mask: ptr to a u32 array to save IRQENABLE bits
220 *
221 * Save the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers to
222 * @saved_mask. @saved_mask must be allocated by the caller.
223 * Intended to be used in the PRM interrupt handler suspend callback.
224 * The OCP barrier is needed to ensure the write to disable PRM
225 * interrupts reaches the PRM before returning; otherwise, spurious
226 * interrupts might occur. No return value.
227 */
228void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask)
229{
230 saved_mask[0] =
Tero Kristo553e3222012-03-12 04:30:02 -0600231 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700232 OMAP4_PRM_IRQSTATUS_MPU_OFFSET);
233 saved_mask[1] =
Tero Kristo553e3222012-03-12 04:30:02 -0600234 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700235 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET);
236
Tero Kristo553e3222012-03-12 04:30:02 -0600237 omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700238 OMAP4_PRM_IRQENABLE_MPU_OFFSET);
Tero Kristo553e3222012-03-12 04:30:02 -0600239 omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700240 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
241
242 /* OCP barrier */
Tero Kristo553e3222012-03-12 04:30:02 -0600243 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700244 OMAP4_REVISION_PRM_OFFSET);
245}
246
247/**
248 * omap44xx_prm_restore_irqen - set PRM_IRQENABLE_MPU* registers from args
249 * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
250 *
251 * Restore the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers from
252 * @saved_mask. Intended to be used in the PRM interrupt handler resume
253 * callback to restore values saved by omap44xx_prm_save_and_clear_irqen().
254 * No OCP barrier should be needed here; any pending PRM interrupts will fire
255 * once the writes reach the PRM. No return value.
256 */
257void omap44xx_prm_restore_irqen(u32 *saved_mask)
258{
Tero Kristo553e3222012-03-12 04:30:02 -0600259 omap4_prm_write_inst_reg(saved_mask[0], OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700260 OMAP4_PRM_IRQENABLE_MPU_OFFSET);
Tero Kristo553e3222012-03-12 04:30:02 -0600261 omap4_prm_write_inst_reg(saved_mask[1], OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700262 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
263}
Tero Kristo2f31b512011-12-16 14:37:00 -0700264
Rajendra Nayakdea62002012-06-22 08:40:03 -0600265/**
266 * omap44xx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
267 *
268 * Clear any previously-latched I/O wakeup events and ensure that the
269 * I/O wakeup gates are aligned with the current mux settings. Works
270 * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
271 * deasserting WUCLKIN and waiting for WUCLKOUT to be deasserted.
272 * No return value. XXX Are the final two steps necessary?
273 */
274void omap44xx_prm_reconfigure_io_chain(void)
275{
276 int i = 0;
Rajendra Nayakdea62002012-06-22 08:40:03 -0600277
278 /* Trigger WUCLKIN enable */
279 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK,
280 OMAP4430_WUCLK_CTRL_MASK,
281 OMAP4430_PRM_DEVICE_INST,
282 OMAP4_PRM_IO_PMCTRL_OFFSET);
283 omap_test_timeout(
284 (((omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST,
285 OMAP4_PRM_IO_PMCTRL_OFFSET) &
286 OMAP4430_WUCLK_STATUS_MASK) >>
287 OMAP4430_WUCLK_STATUS_SHIFT) == 1),
288 MAX_IOPAD_LATCH_TIME, i);
289 if (i == MAX_IOPAD_LATCH_TIME)
290 pr_warn("PRM: I/O chain clock line assertion timed out\n");
291
292 /* Trigger WUCLKIN disable */
293 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK, 0x0,
294 OMAP4430_PRM_DEVICE_INST,
295 OMAP4_PRM_IO_PMCTRL_OFFSET);
296 omap_test_timeout(
297 (((omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST,
298 OMAP4_PRM_IO_PMCTRL_OFFSET) &
299 OMAP4430_WUCLK_STATUS_MASK) >>
300 OMAP4430_WUCLK_STATUS_SHIFT) == 0),
301 MAX_IOPAD_LATCH_TIME, i);
302 if (i == MAX_IOPAD_LATCH_TIME)
303 pr_warn("PRM: I/O chain clock line deassertion timed out\n");
304
305 return;
306}
307
Tero Kristo8a680ea2012-06-22 08:40:03 -0600308/**
309 * omap44xx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
310 *
311 * Activates the I/O wakeup event latches and allows events logged by
312 * those latches to signal a wakeup event to the PRCM. For I/O wakeups
313 * to occur, WAKEUPENABLE bits must be set in the pad mux registers, and
314 * omap44xx_prm_reconfigure_io_chain() must be called. No return value.
315 */
316static void __init omap44xx_prm_enable_io_wakeup(void)
317{
318 omap4_prm_rmw_inst_reg_bits(OMAP4430_GLOBAL_WUEN_MASK,
319 OMAP4430_GLOBAL_WUEN_MASK,
320 OMAP4430_PRM_DEVICE_INST,
321 OMAP4_PRM_IO_PMCTRL_OFFSET);
322}
323
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600324/**
325 * omap44xx_prm_read_reset_sources - return the last SoC reset source
326 *
327 * Return a u32 representing the last reset sources of the SoC. The
328 * returned reset source bits are standardized across OMAP SoCs.
329 */
330static u32 omap44xx_prm_read_reset_sources(void)
331{
332 struct prm_reset_src_map *p;
333 u32 r = 0;
334 u32 v;
335
336 v = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
337 OMAP4_RM_RSTST);
338
339 p = omap44xx_prm_reset_src_map;
340 while (p->reg_shift >= 0 && p->std_shift >= 0) {
341 if (v & (1 << p->reg_shift))
342 r |= 1 << p->std_shift;
343 p++;
344 }
345
346 return r;
347}
348
Paul Walmsley49815392012-10-21 01:01:10 -0600349/* Powerdomain low-level functions */
350
351static int omap4_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
352{
353 omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK,
354 (pwrst << OMAP_POWERSTATE_SHIFT),
355 pwrdm->prcm_partition,
356 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
357 return 0;
358}
359
360static int omap4_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
361{
362 u32 v;
363
364 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
365 OMAP4_PM_PWSTCTRL);
366 v &= OMAP_POWERSTATE_MASK;
367 v >>= OMAP_POWERSTATE_SHIFT;
368
369 return v;
370}
371
372static int omap4_pwrdm_read_pwrst(struct powerdomain *pwrdm)
373{
374 u32 v;
375
376 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
377 OMAP4_PM_PWSTST);
378 v &= OMAP_POWERSTATEST_MASK;
379 v >>= OMAP_POWERSTATEST_SHIFT;
380
381 return v;
382}
383
384static int omap4_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
385{
386 u32 v;
387
388 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
389 OMAP4_PM_PWSTST);
390 v &= OMAP4430_LASTPOWERSTATEENTERED_MASK;
391 v >>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT;
392
393 return v;
394}
395
396static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
397{
398 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK,
399 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT),
400 pwrdm->prcm_partition,
401 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
402 return 0;
403}
404
405static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
406{
407 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK,
408 OMAP4430_LASTPOWERSTATEENTERED_MASK,
409 pwrdm->prcm_partition,
410 pwrdm->prcm_offs, OMAP4_PM_PWSTST);
411 return 0;
412}
413
414static int omap4_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
415{
416 u32 v;
417
418 v = pwrst << __ffs(OMAP4430_LOGICRETSTATE_MASK);
419 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK, v,
420 pwrdm->prcm_partition, pwrdm->prcm_offs,
421 OMAP4_PM_PWSTCTRL);
422
423 return 0;
424}
425
426static int omap4_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
427 u8 pwrst)
428{
429 u32 m;
430
431 m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
432
433 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
434 pwrdm->prcm_partition, pwrdm->prcm_offs,
435 OMAP4_PM_PWSTCTRL);
436
437 return 0;
438}
439
440static int omap4_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
441 u8 pwrst)
442{
443 u32 m;
444
445 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
446
447 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
448 pwrdm->prcm_partition, pwrdm->prcm_offs,
449 OMAP4_PM_PWSTCTRL);
450
451 return 0;
452}
453
454static int omap4_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
455{
456 u32 v;
457
458 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
459 OMAP4_PM_PWSTST);
460 v &= OMAP4430_LOGICSTATEST_MASK;
461 v >>= OMAP4430_LOGICSTATEST_SHIFT;
462
463 return v;
464}
465
466static int omap4_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
467{
468 u32 v;
469
470 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
471 OMAP4_PM_PWSTCTRL);
472 v &= OMAP4430_LOGICRETSTATE_MASK;
473 v >>= OMAP4430_LOGICRETSTATE_SHIFT;
474
475 return v;
476}
477
478/**
479 * omap4_pwrdm_read_prev_logic_pwrst - read the previous logic powerstate
480 * @pwrdm: struct powerdomain * to read the state for
481 *
482 * Reads the previous logic powerstate for a powerdomain. This
483 * function must determine the previous logic powerstate by first
484 * checking the previous powerstate for the domain. If that was OFF,
485 * then logic has been lost. If previous state was RETENTION, the
486 * function reads the setting for the next retention logic state to
487 * see the actual value. In every other case, the logic is
488 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
489 * depending whether the logic was retained or not.
490 */
491static int omap4_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
492{
493 int state;
494
495 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
496
497 if (state == PWRDM_POWER_OFF)
498 return PWRDM_POWER_OFF;
499
500 if (state != PWRDM_POWER_RET)
501 return PWRDM_POWER_RET;
502
503 return omap4_pwrdm_read_logic_retst(pwrdm);
504}
505
506static int omap4_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
507{
508 u32 m, v;
509
510 m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
511
512 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
513 OMAP4_PM_PWSTST);
514 v &= m;
515 v >>= __ffs(m);
516
517 return v;
518}
519
520static int omap4_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
521{
522 u32 m, v;
523
524 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
525
526 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
527 OMAP4_PM_PWSTCTRL);
528 v &= m;
529 v >>= __ffs(m);
530
531 return v;
532}
533
534/**
535 * omap4_pwrdm_read_prev_mem_pwrst - reads the previous memory powerstate
536 * @pwrdm: struct powerdomain * to read mem powerstate for
537 * @bank: memory bank index
538 *
539 * Reads the previous memory powerstate for a powerdomain. This
540 * function must determine the previous memory powerstate by first
541 * checking the previous powerstate for the domain. If that was OFF,
542 * then logic has been lost. If previous state was RETENTION, the
543 * function reads the setting for the next memory retention state to
544 * see the actual value. In every other case, the logic is
545 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
546 * depending whether logic was retained or not.
547 */
548static int omap4_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
549{
550 int state;
551
552 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
553
554 if (state == PWRDM_POWER_OFF)
555 return PWRDM_POWER_OFF;
556
557 if (state != PWRDM_POWER_RET)
558 return PWRDM_POWER_RET;
559
560 return omap4_pwrdm_read_mem_retst(pwrdm, bank);
561}
562
563static int omap4_pwrdm_wait_transition(struct powerdomain *pwrdm)
564{
565 u32 c = 0;
566
567 /*
568 * REVISIT: pwrdm_wait_transition() may be better implemented
569 * via a callback and a periodic timer check -- how long do we expect
570 * powerdomain transitions to take?
571 */
572
573 /* XXX Is this udelay() value meaningful? */
574 while ((omap4_prminst_read_inst_reg(pwrdm->prcm_partition,
575 pwrdm->prcm_offs,
576 OMAP4_PM_PWSTST) &
577 OMAP_INTRANSITION_MASK) &&
578 (c++ < PWRDM_TRANSITION_BAILOUT))
579 udelay(1);
580
581 if (c > PWRDM_TRANSITION_BAILOUT) {
582 pr_err("powerdomain: %s: waited too long to complete transition\n",
583 pwrdm->name);
584 return -EAGAIN;
585 }
586
587 pr_debug("powerdomain: completed transition in %d loops\n", c);
588
589 return 0;
590}
591
592struct pwrdm_ops omap4_pwrdm_operations = {
593 .pwrdm_set_next_pwrst = omap4_pwrdm_set_next_pwrst,
594 .pwrdm_read_next_pwrst = omap4_pwrdm_read_next_pwrst,
595 .pwrdm_read_pwrst = omap4_pwrdm_read_pwrst,
596 .pwrdm_read_prev_pwrst = omap4_pwrdm_read_prev_pwrst,
597 .pwrdm_set_lowpwrstchange = omap4_pwrdm_set_lowpwrstchange,
598 .pwrdm_clear_all_prev_pwrst = omap4_pwrdm_clear_all_prev_pwrst,
599 .pwrdm_set_logic_retst = omap4_pwrdm_set_logic_retst,
600 .pwrdm_read_logic_pwrst = omap4_pwrdm_read_logic_pwrst,
601 .pwrdm_read_prev_logic_pwrst = omap4_pwrdm_read_prev_logic_pwrst,
602 .pwrdm_read_logic_retst = omap4_pwrdm_read_logic_retst,
603 .pwrdm_read_mem_pwrst = omap4_pwrdm_read_mem_pwrst,
604 .pwrdm_read_mem_retst = omap4_pwrdm_read_mem_retst,
605 .pwrdm_read_prev_mem_pwrst = omap4_pwrdm_read_prev_mem_pwrst,
606 .pwrdm_set_mem_onst = omap4_pwrdm_set_mem_onst,
607 .pwrdm_set_mem_retst = omap4_pwrdm_set_mem_retst,
608 .pwrdm_wait_transition = omap4_pwrdm_wait_transition,
609};
610
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600611/*
612 * XXX document
613 */
614static struct prm_ll_data omap44xx_prm_ll_data = {
615 .read_reset_sources = &omap44xx_prm_read_reset_sources,
616};
Paul Walmsley49815392012-10-21 01:01:10 -0600617
Paul Walmsley63a293e2012-11-21 16:15:16 -0700618int __init omap44xx_prm_init(void)
Tero Kristo2f31b512011-12-16 14:37:00 -0700619{
Paul Walmsley139563a2012-10-21 01:01:10 -0600620 if (!cpu_is_omap44xx())
621 return 0;
622
Paul Walmsley63a293e2012-11-21 16:15:16 -0700623 return prm_register(&omap44xx_prm_ll_data);
624}
625
626static int __init omap44xx_prm_late_init(void)
627{
628 if (!cpu_is_omap44xx())
629 return 0;
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600630
Paul Walmsley139563a2012-10-21 01:01:10 -0600631 omap44xx_prm_enable_io_wakeup();
632
633 return omap_prcm_register_chain_handler(&omap4_prcm_irq_setup);
Tero Kristo2f31b512011-12-16 14:37:00 -0700634}
Paul Walmsley63a293e2012-11-21 16:15:16 -0700635subsys_initcall(omap44xx_prm_late_init);
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600636
637static void __exit omap44xx_prm_exit(void)
638{
639 if (!cpu_is_omap44xx())
640 return;
641
642 /* Should never happen */
643 WARN(prm_unregister(&omap44xx_prm_ll_data),
644 "%s: prm_ll_data function pointer mismatch\n", __func__);
645}
646__exitcall(omap44xx_prm_exit);