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