blob: 75dfe8efdfe02fe21a073ad1ced2282b2d5b80cb [file] [log] [blame]
Paul Walmsley139563a2012-10-21 01:01:10 -06001/*
2 * OMAP3xxx PRM module functions
3 *
4 * Copyright (C) 2010-2012 Texas Instruments, Inc.
5 * 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>
Paul Walmsley139563a2012-10-21 01:01: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/errno.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/irq.h>
20
Tony Lindgrene8d3d472012-12-16 11:29:58 -080021#include "soc.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060022#include "common.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060023#include "vp.h"
Paul Walmsley49815392012-10-21 01:01:10 -060024#include "powerdomain.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060025#include "prm3xxx.h"
Paul Walmsley49815392012-10-21 01:01:10 -060026#include "prm2xxx_3xxx.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060027#include "cm2xxx_3xxx.h"
28#include "prm-regbits-34xx.h"
Tero Kristo0efc0f62014-02-25 15:40:30 +020029#include "cm3xxx.h"
30#include "cm-regbits-34xx.h"
Tero Kristo9de367f2014-02-25 18:04:56 +020031#include "control.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060032
33static const struct omap_prcm_irq omap3_prcm_irqs[] = {
34 OMAP_PRCM_IRQ("wkup", 0, 0),
35 OMAP_PRCM_IRQ("io", 9, 1),
36};
37
38static struct omap_prcm_irq_setup omap3_prcm_irq_setup = {
39 .ack = OMAP3_PRM_IRQSTATUS_MPU_OFFSET,
40 .mask = OMAP3_PRM_IRQENABLE_MPU_OFFSET,
41 .nr_regs = 1,
42 .irqs = omap3_prcm_irqs,
43 .nr_irqs = ARRAY_SIZE(omap3_prcm_irqs),
44 .irq = 11 + OMAP_INTC_START,
45 .read_pending_irqs = &omap3xxx_prm_read_pending_irqs,
46 .ocp_barrier = &omap3xxx_prm_ocp_barrier,
47 .save_and_clear_irqen = &omap3xxx_prm_save_and_clear_irqen,
48 .restore_irqen = &omap3xxx_prm_restore_irqen,
Tero Kristo81243652014-03-31 18:15:43 +030049 .reconfigure_io_chain = &omap3xxx_prm_reconfigure_io_chain,
Paul Walmsley139563a2012-10-21 01:01:10 -060050};
51
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060052/*
53 * omap3_prm_reset_src_map - map from bits in the PRM_RSTST hardware
54 * register (which are specific to OMAP3xxx SoCs) to reset source ID
55 * bit shifts (which is an OMAP SoC-independent enumeration)
56 */
57static struct prm_reset_src_map omap3xxx_prm_reset_src_map[] = {
58 { OMAP3430_GLOBAL_COLD_RST_SHIFT, OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT },
59 { OMAP3430_GLOBAL_SW_RST_SHIFT, OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT },
60 { OMAP3430_SECURITY_VIOL_RST_SHIFT, OMAP_SECU_VIOL_RST_SRC_ID_SHIFT },
61 { OMAP3430_MPU_WD_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
62 { OMAP3430_SECURE_WD_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
63 { OMAP3430_EXTERNAL_WARM_RST_SHIFT, OMAP_EXTWARM_RST_SRC_ID_SHIFT },
64 { OMAP3430_VDD1_VOLTAGE_MANAGER_RST_SHIFT,
65 OMAP_VDD_MPU_VM_RST_SRC_ID_SHIFT },
66 { OMAP3430_VDD2_VOLTAGE_MANAGER_RST_SHIFT,
67 OMAP_VDD_CORE_VM_RST_SRC_ID_SHIFT },
68 { OMAP3430_ICEPICK_RST_SHIFT, OMAP_ICEPICK_RST_SRC_ID_SHIFT },
69 { OMAP3430_ICECRUSHER_RST_SHIFT, OMAP_ICECRUSHER_RST_SRC_ID_SHIFT },
70 { -1, -1 },
71};
72
Paul Walmsley139563a2012-10-21 01:01:10 -060073/* PRM VP */
74
75/*
76 * struct omap3_vp - OMAP3 VP register access description.
77 * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
78 */
79struct omap3_vp {
80 u32 tranxdone_status;
81};
82
83static struct omap3_vp omap3_vp[] = {
84 [OMAP3_VP_VDD_MPU_ID] = {
85 .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK,
86 },
87 [OMAP3_VP_VDD_CORE_ID] = {
88 .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK,
89 },
90};
91
92#define MAX_VP_ID ARRAY_SIZE(omap3_vp);
93
94u32 omap3_prm_vp_check_txdone(u8 vp_id)
95{
96 struct omap3_vp *vp = &omap3_vp[vp_id];
97 u32 irqstatus;
98
99 irqstatus = omap2_prm_read_mod_reg(OCP_MOD,
100 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
101 return irqstatus & vp->tranxdone_status;
102}
103
104void omap3_prm_vp_clear_txdone(u8 vp_id)
105{
106 struct omap3_vp *vp = &omap3_vp[vp_id];
107
108 omap2_prm_write_mod_reg(vp->tranxdone_status,
109 OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
110}
111
112u32 omap3_prm_vcvp_read(u8 offset)
113{
114 return omap2_prm_read_mod_reg(OMAP3430_GR_MOD, offset);
115}
116
117void omap3_prm_vcvp_write(u32 val, u8 offset)
118{
119 omap2_prm_write_mod_reg(val, OMAP3430_GR_MOD, offset);
120}
121
122u32 omap3_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
123{
124 return omap2_prm_rmw_mod_reg_bits(mask, bits, OMAP3430_GR_MOD, offset);
125}
126
127/**
Paul Walmsleyd08cce62012-10-29 20:55:46 -0600128 * omap3xxx_prm_dpll3_reset - use DPLL3 reset to reboot the OMAP SoC
129 *
130 * Set the DPLL3 reset bit, which should reboot the SoC. This is the
131 * recommended way to restart the SoC, considering Errata i520. No
132 * return value.
133 */
134void omap3xxx_prm_dpll3_reset(void)
135{
136 omap2_prm_set_mod_reg_bits(OMAP_RST_DPLL3_MASK, OMAP3430_GR_MOD,
137 OMAP2_RM_RSTCTRL);
138 /* OCP barrier */
139 omap2_prm_read_mod_reg(OMAP3430_GR_MOD, OMAP2_RM_RSTCTRL);
140}
141
142/**
Paul Walmsley139563a2012-10-21 01:01:10 -0600143 * omap3xxx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
144 * @events: ptr to a u32, preallocated by caller
145 *
146 * Read PRM_IRQSTATUS_MPU bits, AND'ed with the currently-enabled PRM
147 * MPU IRQs, and store the result into the u32 pointed to by @events.
148 * No return value.
149 */
150void omap3xxx_prm_read_pending_irqs(unsigned long *events)
151{
152 u32 mask, st;
153
154 /* XXX Can the mask read be avoided (e.g., can it come from RAM?) */
155 mask = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
156 st = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
157
158 events[0] = mask & st;
159}
160
161/**
162 * omap3xxx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
163 *
164 * Force any buffered writes to the PRM IP block to complete. Needed
165 * by the PRM IRQ handler, which reads and writes directly to the IP
166 * block, to avoid race conditions after acknowledging or clearing IRQ
167 * bits. No return value.
168 */
169void omap3xxx_prm_ocp_barrier(void)
170{
171 omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
172}
173
174/**
175 * omap3xxx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU reg
176 * @saved_mask: ptr to a u32 array to save IRQENABLE bits
177 *
178 * Save the PRM_IRQENABLE_MPU register to @saved_mask. @saved_mask
179 * must be allocated by the caller. Intended to be used in the PRM
180 * interrupt handler suspend callback. The OCP barrier is needed to
181 * ensure the write to disable PRM interrupts reaches the PRM before
182 * returning; otherwise, spurious interrupts might occur. No return
183 * value.
184 */
185void omap3xxx_prm_save_and_clear_irqen(u32 *saved_mask)
186{
187 saved_mask[0] = omap2_prm_read_mod_reg(OCP_MOD,
188 OMAP3_PRM_IRQENABLE_MPU_OFFSET);
189 omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
190
191 /* OCP barrier */
192 omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
193}
194
195/**
196 * omap3xxx_prm_restore_irqen - set PRM_IRQENABLE_MPU register from args
197 * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
198 *
199 * Restore the PRM_IRQENABLE_MPU register from @saved_mask. Intended
200 * to be used in the PRM interrupt handler resume callback to restore
201 * values saved by omap3xxx_prm_save_and_clear_irqen(). No OCP
202 * barrier should be needed here; any pending PRM interrupts will fire
203 * once the writes reach the PRM. No return value.
204 */
205void omap3xxx_prm_restore_irqen(u32 *saved_mask)
206{
207 omap2_prm_write_mod_reg(saved_mask[0], OCP_MOD,
208 OMAP3_PRM_IRQENABLE_MPU_OFFSET);
209}
210
211/**
Tero Kristo0efc0f62014-02-25 15:40:30 +0200212 * omap3xxx_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
213 * @module: PRM module to clear wakeups from
214 * @regs: register set to clear, 1 or 3
215 * @ignore_bits: wakeup status bits to ignore
216 *
217 * The purpose of this function is to clear any wake-up events latched
218 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
219 * may occur whilst attempting to clear a PM_WKST_x register and thus
220 * set another bit in this register. A while loop is used to ensure
221 * that any peripheral wake-up events occurring while attempting to
222 * clear the PM_WKST_x are detected and cleared.
223 */
224int omap3xxx_prm_clear_mod_irqs(s16 module, u8 regs, u32 ignore_bits)
225{
226 u32 wkst, fclk, iclk, clken;
227 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
228 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
229 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
230 u16 grpsel_off = (regs == 3) ?
231 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
232 int c = 0;
233
234 wkst = omap2_prm_read_mod_reg(module, wkst_off);
235 wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
236 wkst &= ~ignore_bits;
237 if (wkst) {
238 iclk = omap2_cm_read_mod_reg(module, iclk_off);
239 fclk = omap2_cm_read_mod_reg(module, fclk_off);
240 while (wkst) {
241 clken = wkst;
242 omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
243 /*
244 * For USBHOST, we don't know whether HOST1 or
245 * HOST2 woke us up, so enable both f-clocks
246 */
247 if (module == OMAP3430ES2_USBHOST_MOD)
248 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
249 omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
250 omap2_prm_write_mod_reg(wkst, module, wkst_off);
251 wkst = omap2_prm_read_mod_reg(module, wkst_off);
252 wkst &= ~ignore_bits;
253 c++;
254 }
255 omap2_cm_write_mod_reg(iclk, module, iclk_off);
256 omap2_cm_write_mod_reg(fclk, module, fclk_off);
257 }
258
259 return c;
260}
261
262/**
Tero Kristo55c6c3a2014-03-04 15:48:33 +0200263 * omap3_prm_reset_modem - toggle reset signal for modem
264 *
265 * Toggles the reset signal to modem IP block. Required to allow
266 * OMAP3430 without stacked modem to idle properly.
267 */
268void __init omap3_prm_reset_modem(void)
269{
270 omap2_prm_write_mod_reg(
271 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
272 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
273 CORE_MOD, OMAP2_RM_RSTCTRL);
274 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
275}
276
277/**
Tero Kristoc5180a22014-02-26 17:30:43 +0200278 * omap3_prm_init_pm - initialize PM related registers for PRM
279 * @has_uart4: SoC has UART4
280 * @has_iva: SoC has IVA
281 *
282 * Initializes PRM registers for PM use. Called from PM init.
283 */
284void __init omap3_prm_init_pm(bool has_uart4, bool has_iva)
285{
286 u32 en_uart4_mask;
287 u32 grpsel_uart4_mask;
288
289 /*
290 * Enable control of expternal oscillator through
291 * sys_clkreq. In the long run clock framework should
292 * take care of this.
293 */
294 omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
295 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
296 OMAP3430_GR_MOD,
297 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
298
299 /* setup wakup source */
300 omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
301 OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
302 WKUP_MOD, PM_WKEN);
303 /* No need to write EN_IO, that is always enabled */
304 omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
305 OMAP3430_GRPSEL_GPT1_MASK |
306 OMAP3430_GRPSEL_GPT12_MASK,
307 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
308
309 /* Enable PM_WKEN to support DSS LPR */
310 omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
311 OMAP3430_DSS_MOD, PM_WKEN);
312
313 if (has_uart4) {
314 en_uart4_mask = OMAP3630_EN_UART4_MASK;
315 grpsel_uart4_mask = OMAP3630_GRPSEL_UART4_MASK;
316 }
317
318 /* Enable wakeups in PER */
319 omap2_prm_write_mod_reg(en_uart4_mask |
320 OMAP3430_EN_GPIO2_MASK |
321 OMAP3430_EN_GPIO3_MASK |
322 OMAP3430_EN_GPIO4_MASK |
323 OMAP3430_EN_GPIO5_MASK |
324 OMAP3430_EN_GPIO6_MASK |
325 OMAP3430_EN_UART3_MASK |
326 OMAP3430_EN_MCBSP2_MASK |
327 OMAP3430_EN_MCBSP3_MASK |
328 OMAP3430_EN_MCBSP4_MASK,
329 OMAP3430_PER_MOD, PM_WKEN);
330
331 /* and allow them to wake up MPU */
332 omap2_prm_write_mod_reg(grpsel_uart4_mask |
333 OMAP3430_GRPSEL_GPIO2_MASK |
334 OMAP3430_GRPSEL_GPIO3_MASK |
335 OMAP3430_GRPSEL_GPIO4_MASK |
336 OMAP3430_GRPSEL_GPIO5_MASK |
337 OMAP3430_GRPSEL_GPIO6_MASK |
338 OMAP3430_GRPSEL_UART3_MASK |
339 OMAP3430_GRPSEL_MCBSP2_MASK |
340 OMAP3430_GRPSEL_MCBSP3_MASK |
341 OMAP3430_GRPSEL_MCBSP4_MASK,
342 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
343
344 /* Don't attach IVA interrupts */
345 if (has_iva) {
346 omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
347 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
348 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
349 omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD,
350 OMAP3430_PM_IVAGRPSEL);
351 }
352
353 /* Clear any pending 'reset' flags */
354 omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
355 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
356 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
357 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
358 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
359 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
360 omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD,
361 OMAP2_RM_RSTST);
362
363 /* Clear any pending PRCM interrupts */
364 omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Tero Kristoc2148e52014-03-04 17:24:21 +0200365
366 /* We need to idle iva2_pwrdm even on am3703 with no iva2. */
367 omap3xxx_prm_iva_idle();
368
369 omap3_ctrl_setup_d2d_padconf();
370
371 omap3_prm_reset_modem();
Tero Kristoc5180a22014-02-26 17:30:43 +0200372}
373
374/**
Paul Walmsley139563a2012-10-21 01:01:10 -0600375 * omap3xxx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
376 *
377 * Clear any previously-latched I/O wakeup events and ensure that the
378 * I/O wakeup gates are aligned with the current mux settings. Works
379 * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
380 * deasserting WUCLKIN and clearing the ST_IO_CHAIN WKST bit. No
381 * return value.
382 */
383void omap3xxx_prm_reconfigure_io_chain(void)
384{
385 int i = 0;
386
387 omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
388 PM_WKEN);
389
390 omap_test_timeout(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST) &
391 OMAP3430_ST_IO_CHAIN_MASK,
392 MAX_IOPAD_LATCH_TIME, i);
393 if (i == MAX_IOPAD_LATCH_TIME)
394 pr_warn("PRM: I/O chain clock line assertion timed out\n");
395
396 omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
397 PM_WKEN);
398
399 omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK, WKUP_MOD,
400 PM_WKST);
401
402 omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST);
403}
404
405/**
406 * omap3xxx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
407 *
408 * Activates the I/O wakeup event latches and allows events logged by
409 * those latches to signal a wakeup event to the PRCM. For I/O
410 * wakeups to occur, WAKEUPENABLE bits must be set in the pad mux
411 * registers, and omap3xxx_prm_reconfigure_io_chain() must be called.
412 * No return value.
413 */
414static void __init omap3xxx_prm_enable_io_wakeup(void)
415{
Tero Kristo2541d152014-03-31 18:15:44 +0300416 if (prm_features & PRM_HAS_IO_WAKEUP)
Paul Walmsley139563a2012-10-21 01:01:10 -0600417 omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
418 PM_WKEN);
419}
420
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600421/**
422 * omap3xxx_prm_read_reset_sources - return the last SoC reset source
423 *
424 * Return a u32 representing the last reset sources of the SoC. The
425 * returned reset source bits are standardized across OMAP SoCs.
426 */
427static u32 omap3xxx_prm_read_reset_sources(void)
428{
429 struct prm_reset_src_map *p;
430 u32 r = 0;
431 u32 v;
432
433 v = omap2_prm_read_mod_reg(WKUP_MOD, OMAP2_RM_RSTST);
434
435 p = omap3xxx_prm_reset_src_map;
436 while (p->reg_shift >= 0 && p->std_shift >= 0) {
437 if (v & (1 << p->reg_shift))
438 r |= 1 << p->std_shift;
439 p++;
440 }
441
442 return r;
443}
444
Tero Kristo9de367f2014-02-25 18:04:56 +0200445/**
446 * omap3xxx_prm_iva_idle - ensure IVA is in idle so it can be put into retention
447 *
448 * In cases where IVA2 is activated by bootcode, it may prevent
449 * full-chip retention or off-mode because it is not idle. This
450 * function forces the IVA2 into idle state so it can go
451 * into retention/off and thus allow full-chip retention/off.
452 */
453void omap3xxx_prm_iva_idle(void)
454{
455 /* ensure IVA2 clock is disabled */
456 omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
457
458 /* if no clock activity, nothing else to do */
459 if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
460 OMAP3430_CLKACTIVITY_IVA2_MASK))
461 return;
462
463 /* Reset IVA2 */
464 omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
465 OMAP3430_RST2_IVA2_MASK |
466 OMAP3430_RST3_IVA2_MASK,
467 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
468
469 /* Enable IVA2 clock */
470 omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
471 OMAP3430_IVA2_MOD, CM_FCLKEN);
472
473 /* Set IVA2 boot mode to 'idle' */
474 omap3_ctrl_set_iva_bootmode_idle();
475
476 /* Un-reset IVA2 */
477 omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
478
479 /* Disable IVA2 clock */
480 omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
481
482 /* Reset IVA2 */
483 omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
484 OMAP3430_RST2_IVA2_MASK |
485 OMAP3430_RST3_IVA2_MASK,
486 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
487}
488
Tero Kristo9efcea02014-02-26 11:54:29 +0200489/**
490 * omap3xxx_prm_clear_global_cold_reset - checks the global cold reset status
491 * and clears it if asserted
492 *
493 * Checks if cold-reset has occurred and clears the status bit if yes. Returns
494 * 1 if cold-reset has occurred, 0 otherwise.
495 */
496int omap3xxx_prm_clear_global_cold_reset(void)
497{
498 if (omap2_prm_read_mod_reg(OMAP3430_GR_MOD, OMAP3_PRM_RSTST_OFFSET) &
499 OMAP3430_GLOBAL_COLD_RST_MASK) {
500 omap2_prm_set_mod_reg_bits(OMAP3430_GLOBAL_COLD_RST_MASK,
501 OMAP3430_GR_MOD,
502 OMAP3_PRM_RSTST_OFFSET);
503 return 1;
504 }
505
506 return 0;
507}
508
Tero Kristo7e28b4652014-02-26 12:00:16 +0200509void omap3_prm_save_scratchpad_contents(u32 *ptr)
510{
511 *ptr++ = omap2_prm_read_mod_reg(OMAP3430_GR_MOD,
512 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
513
514 *ptr++ = omap2_prm_read_mod_reg(OMAP3430_GR_MOD,
515 OMAP3_PRM_CLKSEL_OFFSET);
516}
517
Paul Walmsley49815392012-10-21 01:01:10 -0600518/* Powerdomain low-level functions */
519
Paul Walmsley7e7fff82012-12-28 02:10:44 -0700520static int omap3_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
521{
522 omap2_prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
523 (pwrst << OMAP_POWERSTATE_SHIFT),
524 pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
525 return 0;
526}
527
528static int omap3_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
529{
530 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
531 OMAP2_PM_PWSTCTRL,
532 OMAP_POWERSTATE_MASK);
533}
534
535static int omap3_pwrdm_read_pwrst(struct powerdomain *pwrdm)
536{
537 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
538 OMAP2_PM_PWSTST,
539 OMAP_POWERSTATEST_MASK);
540}
541
Paul Walmsley49815392012-10-21 01:01:10 -0600542/* Applicable only for OMAP3. Not supported on OMAP2 */
543static int omap3_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
544{
545 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
546 OMAP3430_PM_PREPWSTST,
547 OMAP3430_LASTPOWERSTATEENTERED_MASK);
548}
549
550static int omap3_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
551{
552 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
553 OMAP2_PM_PWSTST,
554 OMAP3430_LOGICSTATEST_MASK);
555}
556
557static int omap3_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
558{
559 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
560 OMAP2_PM_PWSTCTRL,
561 OMAP3430_LOGICSTATEST_MASK);
562}
563
564static int omap3_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
565{
566 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
567 OMAP3430_PM_PREPWSTST,
568 OMAP3430_LASTLOGICSTATEENTERED_MASK);
569}
570
571static int omap3_get_mem_bank_lastmemst_mask(u8 bank)
572{
573 switch (bank) {
574 case 0:
575 return OMAP3430_LASTMEM1STATEENTERED_MASK;
576 case 1:
577 return OMAP3430_LASTMEM2STATEENTERED_MASK;
578 case 2:
579 return OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK;
580 case 3:
581 return OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK;
582 default:
583 WARN_ON(1); /* should never happen */
584 return -EEXIST;
585 }
586 return 0;
587}
588
589static int omap3_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
590{
591 u32 m;
592
593 m = omap3_get_mem_bank_lastmemst_mask(bank);
594
595 return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
596 OMAP3430_PM_PREPWSTST, m);
597}
598
599static int omap3_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
600{
601 omap2_prm_write_mod_reg(0, pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST);
602 return 0;
603}
604
605static int omap3_pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
606{
607 return omap2_prm_rmw_mod_reg_bits(0,
608 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
609 pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
610}
611
612static int omap3_pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
613{
614 return omap2_prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
615 0, pwrdm->prcm_offs,
616 OMAP2_PM_PWSTCTRL);
617}
618
619struct pwrdm_ops omap3_pwrdm_operations = {
Paul Walmsley7e7fff82012-12-28 02:10:44 -0700620 .pwrdm_set_next_pwrst = omap3_pwrdm_set_next_pwrst,
621 .pwrdm_read_next_pwrst = omap3_pwrdm_read_next_pwrst,
622 .pwrdm_read_pwrst = omap3_pwrdm_read_pwrst,
Paul Walmsley49815392012-10-21 01:01:10 -0600623 .pwrdm_read_prev_pwrst = omap3_pwrdm_read_prev_pwrst,
624 .pwrdm_set_logic_retst = omap2_pwrdm_set_logic_retst,
625 .pwrdm_read_logic_pwrst = omap3_pwrdm_read_logic_pwrst,
626 .pwrdm_read_logic_retst = omap3_pwrdm_read_logic_retst,
627 .pwrdm_read_prev_logic_pwrst = omap3_pwrdm_read_prev_logic_pwrst,
628 .pwrdm_set_mem_onst = omap2_pwrdm_set_mem_onst,
629 .pwrdm_set_mem_retst = omap2_pwrdm_set_mem_retst,
630 .pwrdm_read_mem_pwrst = omap2_pwrdm_read_mem_pwrst,
631 .pwrdm_read_mem_retst = omap2_pwrdm_read_mem_retst,
632 .pwrdm_read_prev_mem_pwrst = omap3_pwrdm_read_prev_mem_pwrst,
633 .pwrdm_clear_all_prev_pwrst = omap3_pwrdm_clear_all_prev_pwrst,
634 .pwrdm_enable_hdwr_sar = omap3_pwrdm_enable_hdwr_sar,
635 .pwrdm_disable_hdwr_sar = omap3_pwrdm_disable_hdwr_sar,
636 .pwrdm_wait_transition = omap2_pwrdm_wait_transition,
637};
638
639/*
640 *
641 */
642
Tero Kristob550e472014-03-31 18:15:45 +0300643static int omap3xxx_prm_late_init(void);
644
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600645static struct prm_ll_data omap3xxx_prm_ll_data = {
646 .read_reset_sources = &omap3xxx_prm_read_reset_sources,
Tero Kristob550e472014-03-31 18:15:45 +0300647 .late_init = &omap3xxx_prm_late_init,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600648};
649
Paul Walmsley63a293e2012-11-21 16:15:16 -0700650int __init omap3xxx_prm_init(void)
651{
Tero Kristo2541d152014-03-31 18:15:44 +0300652 if (omap3_has_io_wakeup())
653 prm_features |= PRM_HAS_IO_WAKEUP;
Paul Walmsley63a293e2012-11-21 16:15:16 -0700654
655 return prm_register(&omap3xxx_prm_ll_data);
656}
657
Tony Lindgrenea351c12014-05-16 15:26:22 -0700658static int omap3xxx_prm_late_init(void)
Paul Walmsley139563a2012-10-21 01:01:10 -0600659{
660 int ret;
661
Tero Kristo2541d152014-03-31 18:15:44 +0300662 if (!(prm_features & PRM_HAS_IO_WAKEUP))
Paul Walmsley139563a2012-10-21 01:01:10 -0600663 return 0;
664
665 omap3xxx_prm_enable_io_wakeup();
666 ret = omap_prcm_register_chain_handler(&omap3_prcm_irq_setup);
667 if (!ret)
668 irq_set_status_flags(omap_prcm_event_to_irq("io"),
669 IRQ_NOAUTOEN);
670
671 return ret;
672}
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600673
674static void __exit omap3xxx_prm_exit(void)
675{
Tero Kristod8871cd2014-05-11 19:54:58 -0600676 prm_unregister(&omap3xxx_prm_ll_data);
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600677}
678__exitcall(omap3xxx_prm_exit);