blob: 6f647f6984679890ac7173e799f0ba6d2c8b19a5 [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>
Nishanth Menona8f83ae2014-05-22 15:19:29 -050020#include <linux/of_irq.h>
Benoît Cousson0be16212010-09-21 10:34:10 -060021
Benoît Cousson0be16212010-09-21 10:34:10 -060022
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 Kristo28db51f2014-10-27 08:39:26 -070035static void omap44xx_prm_read_pending_irqs(unsigned long *events);
36static void omap44xx_prm_ocp_barrier(void);
37static void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask);
38static void omap44xx_prm_restore_irqen(u32 *saved_mask);
Tero Kristo4984eea2014-10-27 08:39:26 -070039static void omap44xx_prm_reconfigure_io_chain(void);
Tero Kristo28db51f2014-10-27 08:39:26 -070040
Tero Kristo2f31b512011-12-16 14:37:00 -070041static const struct omap_prcm_irq omap4_prcm_irqs[] = {
Tero Kristo2f31b512011-12-16 14:37:00 -070042 OMAP_PRCM_IRQ("io", 9, 1),
43};
44
45static struct omap_prcm_irq_setup omap4_prcm_irq_setup = {
46 .ack = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
47 .mask = OMAP4_PRM_IRQENABLE_MPU_OFFSET,
48 .nr_regs = 2,
49 .irqs = omap4_prcm_irqs,
50 .nr_irqs = ARRAY_SIZE(omap4_prcm_irqs),
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070051 .irq = 11 + OMAP44XX_IRQ_GIC_START,
Marc Zyngier0fb22a82015-01-17 10:21:08 +000052 .xlate_irq = omap4_xlate_irq,
Tero Kristo2f31b512011-12-16 14:37:00 -070053 .read_pending_irqs = &omap44xx_prm_read_pending_irqs,
54 .ocp_barrier = &omap44xx_prm_ocp_barrier,
55 .save_and_clear_irqen = &omap44xx_prm_save_and_clear_irqen,
56 .restore_irqen = &omap44xx_prm_restore_irqen,
Tero Kristo81243652014-03-31 18:15:43 +030057 .reconfigure_io_chain = &omap44xx_prm_reconfigure_io_chain,
Tero Kristo2f31b512011-12-16 14:37:00 -070058};
59
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060060/*
61 * omap44xx_prm_reset_src_map - map from bits in the PRM_RSTST
62 * hardware register (which are specific to OMAP44xx SoCs) to reset
63 * source ID bit shifts (which is an OMAP SoC-independent
64 * enumeration)
65 */
66static struct prm_reset_src_map omap44xx_prm_reset_src_map[] = {
Ivan Khoronzhuk62bafd12012-12-28 02:09:30 -070067 { OMAP4430_GLOBAL_WARM_SW_RST_SHIFT,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060068 OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT },
Ivan Khoronzhuk62bafd12012-12-28 02:09:30 -070069 { OMAP4430_GLOBAL_COLD_RST_SHIFT,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060070 OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT },
71 { OMAP4430_MPU_SECURITY_VIOL_RST_SHIFT,
72 OMAP_SECU_VIOL_RST_SRC_ID_SHIFT },
73 { OMAP4430_MPU_WDT_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
74 { OMAP4430_SECURE_WDT_RST_SHIFT, OMAP_SECU_WD_RST_SRC_ID_SHIFT },
75 { OMAP4430_EXTERNAL_WARM_RST_SHIFT, OMAP_EXTWARM_RST_SRC_ID_SHIFT },
76 { OMAP4430_VDD_MPU_VOLT_MGR_RST_SHIFT,
77 OMAP_VDD_MPU_VM_RST_SRC_ID_SHIFT },
78 { OMAP4430_VDD_IVA_VOLT_MGR_RST_SHIFT,
79 OMAP_VDD_IVA_VM_RST_SRC_ID_SHIFT },
80 { OMAP4430_VDD_CORE_VOLT_MGR_RST_SHIFT,
81 OMAP_VDD_CORE_VM_RST_SRC_ID_SHIFT },
82 { OMAP4430_ICEPICK_RST_SHIFT, OMAP_ICEPICK_RST_SRC_ID_SHIFT },
83 { OMAP4430_C2C_RST_SHIFT, OMAP_C2C_RST_SRC_ID_SHIFT },
84 { -1, -1 },
85};
86
Paul Walmsley2ace8312010-12-21 21:05:14 -070087/* PRM low-level functions */
88
89/* Read a register in a CM/PRM instance in the PRM module */
Tero Kristof3f220f2014-10-27 08:39:26 -070090static u32 omap4_prm_read_inst_reg(s16 inst, u16 reg)
Paul Walmsley2ace8312010-12-21 21:05:14 -070091{
Victor Kamenskyedfaf052014-04-15 20:37:46 +030092 return readl_relaxed(prm_base + inst + reg);
Paul Walmsley2ace8312010-12-21 21:05:14 -070093}
94
95/* Write into a register in a CM/PRM instance in the PRM module */
Tero Kristof3f220f2014-10-27 08:39:26 -070096static void omap4_prm_write_inst_reg(u32 val, s16 inst, u16 reg)
Paul Walmsley2ace8312010-12-21 21:05:14 -070097{
Victor Kamenskyedfaf052014-04-15 20:37:46 +030098 writel_relaxed(val, prm_base + inst + reg);
Paul Walmsley2ace8312010-12-21 21:05:14 -070099}
100
101/* Read-modify-write a register in a PRM module. Caller must lock */
Tero Kristof3f220f2014-10-27 08:39:26 -0700102static u32 omap4_prm_rmw_inst_reg_bits(u32 mask, u32 bits, s16 inst, s16 reg)
Paul Walmsley2ace8312010-12-21 21:05:14 -0700103{
104 u32 v;
105
106 v = omap4_prm_read_inst_reg(inst, reg);
107 v &= ~mask;
108 v |= bits;
109 omap4_prm_write_inst_reg(v, inst, reg);
110
111 return v;
112}
Kevin Hilman58aaa592011-03-28 10:52:04 -0700113
114/* PRM VP */
115
116/*
117 * struct omap4_vp - OMAP4 VP register access description.
118 * @irqstatus_mpu: offset to IRQSTATUS_MPU register for VP
119 * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
120 */
121struct omap4_vp {
122 u32 irqstatus_mpu;
123 u32 tranxdone_status;
124};
125
126static struct omap4_vp omap4_vp[] = {
127 [OMAP4_VP_VDD_MPU_ID] = {
128 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET,
129 .tranxdone_status = OMAP4430_VP_MPU_TRANXDONE_ST_MASK,
130 },
131 [OMAP4_VP_VDD_IVA_ID] = {
132 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
133 .tranxdone_status = OMAP4430_VP_IVA_TRANXDONE_ST_MASK,
134 },
135 [OMAP4_VP_VDD_CORE_ID] = {
136 .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
137 .tranxdone_status = OMAP4430_VP_CORE_TRANXDONE_ST_MASK,
138 },
139};
140
Tero Kristoe9f1ddc2014-04-04 15:52:01 +0300141static u32 omap4_prm_vp_check_txdone(u8 vp_id)
Kevin Hilman58aaa592011-03-28 10:52:04 -0700142{
143 struct omap4_vp *vp = &omap4_vp[vp_id];
144 u32 irqstatus;
145
146 irqstatus = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
147 OMAP4430_PRM_OCP_SOCKET_INST,
148 vp->irqstatus_mpu);
149 return irqstatus & vp->tranxdone_status;
150}
151
Tero Kristoe9f1ddc2014-04-04 15:52:01 +0300152static void omap4_prm_vp_clear_txdone(u8 vp_id)
Kevin Hilman58aaa592011-03-28 10:52:04 -0700153{
154 struct omap4_vp *vp = &omap4_vp[vp_id];
155
156 omap4_prminst_write_inst_reg(vp->tranxdone_status,
157 OMAP4430_PRM_PARTITION,
158 OMAP4430_PRM_OCP_SOCKET_INST,
159 vp->irqstatus_mpu);
160};
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700161
162u32 omap4_prm_vcvp_read(u8 offset)
163{
Nishanth Menon390ddc12014-05-22 15:00:55 -0500164 s32 inst = omap4_prmst_get_prm_dev_inst();
165
166 if (inst == PRM_INSTANCE_UNKNOWN)
167 return 0;
168
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700169 return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500170 inst, offset);
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700171}
172
173void omap4_prm_vcvp_write(u32 val, u8 offset)
174{
Nishanth Menon390ddc12014-05-22 15:00:55 -0500175 s32 inst = omap4_prmst_get_prm_dev_inst();
176
177 if (inst == PRM_INSTANCE_UNKNOWN)
178 return;
179
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700180 omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500181 inst, offset);
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700182}
183
184u32 omap4_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
185{
Nishanth Menon390ddc12014-05-22 15:00:55 -0500186 s32 inst = omap4_prmst_get_prm_dev_inst();
187
188 if (inst == PRM_INSTANCE_UNKNOWN)
189 return 0;
190
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700191 return omap4_prminst_rmw_inst_reg_bits(mask, bits,
192 OMAP4430_PRM_PARTITION,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500193 inst,
Kevin Hilman4bb73ad2011-03-28 10:25:12 -0700194 offset);
195}
Paul Walmsley26c98c52011-12-16 14:36:58 -0700196
197static inline u32 _read_pending_irq_reg(u16 irqen_offs, u16 irqst_offs)
198{
199 u32 mask, st;
200
201 /* XXX read mask from RAM? */
Tero Kristo553e3222012-03-12 04:30:02 -0600202 mask = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
203 irqen_offs);
204 st = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST, irqst_offs);
Paul Walmsley26c98c52011-12-16 14:36:58 -0700205
206 return mask & st;
207}
208
209/**
210 * omap44xx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
211 * @events: ptr to two consecutive u32s, preallocated by caller
212 *
213 * Read PRM_IRQSTATUS_MPU* bits, AND'ed with the currently-enabled PRM
214 * MPU IRQs, and store the result into the two u32s pointed to by @events.
215 * No return value.
216 */
Tero Kristo28db51f2014-10-27 08:39:26 -0700217static void omap44xx_prm_read_pending_irqs(unsigned long *events)
Paul Walmsley26c98c52011-12-16 14:36:58 -0700218{
219 events[0] = _read_pending_irq_reg(OMAP4_PRM_IRQENABLE_MPU_OFFSET,
220 OMAP4_PRM_IRQSTATUS_MPU_OFFSET);
221
222 events[1] = _read_pending_irq_reg(OMAP4_PRM_IRQENABLE_MPU_2_OFFSET,
223 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET);
224}
225
226/**
227 * omap44xx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
228 *
229 * Force any buffered writes to the PRM IP block to complete. Needed
230 * by the PRM IRQ handler, which reads and writes directly to the IP
231 * block, to avoid race conditions after acknowledging or clearing IRQ
232 * bits. No return value.
233 */
Tero Kristo28db51f2014-10-27 08:39:26 -0700234static void omap44xx_prm_ocp_barrier(void)
Paul Walmsley26c98c52011-12-16 14:36:58 -0700235{
Tero Kristo553e3222012-03-12 04:30:02 -0600236 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Paul Walmsley26c98c52011-12-16 14:36:58 -0700237 OMAP4_REVISION_PRM_OFFSET);
238}
Tero Kristo91285b62011-12-16 14:36:58 -0700239
240/**
241 * omap44xx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU* regs
242 * @saved_mask: ptr to a u32 array to save IRQENABLE bits
243 *
244 * Save the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers to
245 * @saved_mask. @saved_mask must be allocated by the caller.
246 * Intended to be used in the PRM interrupt handler suspend callback.
247 * The OCP barrier is needed to ensure the write to disable PRM
248 * interrupts reaches the PRM before returning; otherwise, spurious
249 * interrupts might occur. No return value.
250 */
Tero Kristo28db51f2014-10-27 08:39:26 -0700251static void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask)
Tero Kristo91285b62011-12-16 14:36:58 -0700252{
253 saved_mask[0] =
Tero Kristo553e3222012-03-12 04:30:02 -0600254 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700255 OMAP4_PRM_IRQSTATUS_MPU_OFFSET);
256 saved_mask[1] =
Tero Kristo553e3222012-03-12 04:30:02 -0600257 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700258 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET);
259
Tero Kristo553e3222012-03-12 04:30:02 -0600260 omap4_prm_write_inst_reg(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(0, OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700263 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
264
265 /* OCP barrier */
Tero Kristo553e3222012-03-12 04:30:02 -0600266 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700267 OMAP4_REVISION_PRM_OFFSET);
268}
269
270/**
271 * omap44xx_prm_restore_irqen - set PRM_IRQENABLE_MPU* registers from args
272 * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
273 *
274 * Restore the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers from
275 * @saved_mask. Intended to be used in the PRM interrupt handler resume
276 * callback to restore values saved by omap44xx_prm_save_and_clear_irqen().
277 * No OCP barrier should be needed here; any pending PRM interrupts will fire
278 * once the writes reach the PRM. No return value.
279 */
Tero Kristo28db51f2014-10-27 08:39:26 -0700280static void omap44xx_prm_restore_irqen(u32 *saved_mask)
Tero Kristo91285b62011-12-16 14:36:58 -0700281{
Tero Kristo553e3222012-03-12 04:30:02 -0600282 omap4_prm_write_inst_reg(saved_mask[0], OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700283 OMAP4_PRM_IRQENABLE_MPU_OFFSET);
Tero Kristo553e3222012-03-12 04:30:02 -0600284 omap4_prm_write_inst_reg(saved_mask[1], OMAP4430_PRM_OCP_SOCKET_INST,
Tero Kristo91285b62011-12-16 14:36:58 -0700285 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
286}
Tero Kristo2f31b512011-12-16 14:37:00 -0700287
Rajendra Nayakdea62002012-06-22 08:40:03 -0600288/**
289 * omap44xx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
290 *
291 * Clear any previously-latched I/O wakeup events and ensure that the
292 * I/O wakeup gates are aligned with the current mux settings. Works
293 * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
294 * deasserting WUCLKIN and waiting for WUCLKOUT to be deasserted.
295 * No return value. XXX Are the final two steps necessary?
296 */
Tero Kristo4984eea2014-10-27 08:39:26 -0700297static void omap44xx_prm_reconfigure_io_chain(void)
Rajendra Nayakdea62002012-06-22 08:40:03 -0600298{
299 int i = 0;
Nishanth Menon390ddc12014-05-22 15:00:55 -0500300 s32 inst = omap4_prmst_get_prm_dev_inst();
301
302 if (inst == PRM_INSTANCE_UNKNOWN)
303 return;
Rajendra Nayakdea62002012-06-22 08:40:03 -0600304
305 /* Trigger WUCLKIN enable */
306 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK,
307 OMAP4430_WUCLK_CTRL_MASK,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500308 inst,
Rajendra Nayakdea62002012-06-22 08:40:03 -0600309 OMAP4_PRM_IO_PMCTRL_OFFSET);
310 omap_test_timeout(
Nishanth Menon390ddc12014-05-22 15:00:55 -0500311 (((omap4_prm_read_inst_reg(inst,
Rajendra Nayakdea62002012-06-22 08:40:03 -0600312 OMAP4_PRM_IO_PMCTRL_OFFSET) &
313 OMAP4430_WUCLK_STATUS_MASK) >>
314 OMAP4430_WUCLK_STATUS_SHIFT) == 1),
315 MAX_IOPAD_LATCH_TIME, i);
316 if (i == MAX_IOPAD_LATCH_TIME)
317 pr_warn("PRM: I/O chain clock line assertion timed out\n");
318
319 /* Trigger WUCLKIN disable */
320 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK, 0x0,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500321 inst,
Rajendra Nayakdea62002012-06-22 08:40:03 -0600322 OMAP4_PRM_IO_PMCTRL_OFFSET);
323 omap_test_timeout(
Nishanth Menon390ddc12014-05-22 15:00:55 -0500324 (((omap4_prm_read_inst_reg(inst,
Rajendra Nayakdea62002012-06-22 08:40:03 -0600325 OMAP4_PRM_IO_PMCTRL_OFFSET) &
326 OMAP4430_WUCLK_STATUS_MASK) >>
327 OMAP4430_WUCLK_STATUS_SHIFT) == 0),
328 MAX_IOPAD_LATCH_TIME, i);
329 if (i == MAX_IOPAD_LATCH_TIME)
330 pr_warn("PRM: I/O chain clock line deassertion timed out\n");
331
332 return;
333}
334
Tero Kristo8a680ea2012-06-22 08:40:03 -0600335/**
336 * omap44xx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
337 *
338 * Activates the I/O wakeup event latches and allows events logged by
339 * those latches to signal a wakeup event to the PRCM. For I/O wakeups
340 * to occur, WAKEUPENABLE bits must be set in the pad mux registers, and
341 * omap44xx_prm_reconfigure_io_chain() must be called. No return value.
342 */
343static void __init omap44xx_prm_enable_io_wakeup(void)
344{
Nishanth Menon390ddc12014-05-22 15:00:55 -0500345 s32 inst = omap4_prmst_get_prm_dev_inst();
346
347 if (inst == PRM_INSTANCE_UNKNOWN)
348 return;
349
Tero Kristo8a680ea2012-06-22 08:40:03 -0600350 omap4_prm_rmw_inst_reg_bits(OMAP4430_GLOBAL_WUEN_MASK,
351 OMAP4430_GLOBAL_WUEN_MASK,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500352 inst,
Tero Kristo8a680ea2012-06-22 08:40:03 -0600353 OMAP4_PRM_IO_PMCTRL_OFFSET);
354}
355
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600356/**
357 * omap44xx_prm_read_reset_sources - return the last SoC reset source
358 *
359 * Return a u32 representing the last reset sources of the SoC. The
360 * returned reset source bits are standardized across OMAP SoCs.
361 */
362static u32 omap44xx_prm_read_reset_sources(void)
363{
364 struct prm_reset_src_map *p;
365 u32 r = 0;
366 u32 v;
Nishanth Menon390ddc12014-05-22 15:00:55 -0500367 s32 inst = omap4_prmst_get_prm_dev_inst();
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600368
Nishanth Menon390ddc12014-05-22 15:00:55 -0500369 if (inst == PRM_INSTANCE_UNKNOWN)
370 return 0;
371
372
373 v = omap4_prm_read_inst_reg(inst,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600374 OMAP4_RM_RSTST);
375
376 p = omap44xx_prm_reset_src_map;
377 while (p->reg_shift >= 0 && p->std_shift >= 0) {
378 if (v & (1 << p->reg_shift))
379 r |= 1 << p->std_shift;
380 p++;
381 }
382
383 return r;
384}
385
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700386/**
387 * omap44xx_prm_was_any_context_lost_old - was module hardware context lost?
388 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
389 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
390 * @idx: CONTEXT register offset
391 *
392 * Return 1 if any bits were set in the *_CONTEXT_* register
393 * identified by (@part, @inst, @idx), which means that some context
394 * was lost for that module; otherwise, return 0.
395 */
396static bool omap44xx_prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
397{
398 return (omap4_prminst_read_inst_reg(part, inst, idx)) ? 1 : 0;
399}
400
401/**
402 * omap44xx_prm_clear_context_lost_flags_old - clear context loss flags
403 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
404 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
405 * @idx: CONTEXT register offset
406 *
407 * Clear hardware context loss bits for the module identified by
408 * (@part, @inst, @idx). No return value. XXX Writes to reserved bits;
409 * is there a way to avoid this?
410 */
411static void omap44xx_prm_clear_context_loss_flags_old(u8 part, s16 inst,
412 u16 idx)
413{
414 omap4_prminst_write_inst_reg(0xffffffff, part, inst, idx);
415}
416
Paul Walmsley49815392012-10-21 01:01:10 -0600417/* Powerdomain low-level functions */
418
419static int omap4_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
420{
421 omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK,
422 (pwrst << OMAP_POWERSTATE_SHIFT),
423 pwrdm->prcm_partition,
424 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
425 return 0;
426}
427
428static int omap4_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
429{
430 u32 v;
431
432 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
433 OMAP4_PM_PWSTCTRL);
434 v &= OMAP_POWERSTATE_MASK;
435 v >>= OMAP_POWERSTATE_SHIFT;
436
437 return v;
438}
439
440static int omap4_pwrdm_read_pwrst(struct powerdomain *pwrdm)
441{
442 u32 v;
443
444 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
445 OMAP4_PM_PWSTST);
446 v &= OMAP_POWERSTATEST_MASK;
447 v >>= OMAP_POWERSTATEST_SHIFT;
448
449 return v;
450}
451
452static int omap4_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
453{
454 u32 v;
455
456 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
457 OMAP4_PM_PWSTST);
458 v &= OMAP4430_LASTPOWERSTATEENTERED_MASK;
459 v >>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT;
460
461 return v;
462}
463
464static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
465{
466 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK,
467 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT),
468 pwrdm->prcm_partition,
469 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
470 return 0;
471}
472
473static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
474{
475 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK,
476 OMAP4430_LASTPOWERSTATEENTERED_MASK,
477 pwrdm->prcm_partition,
478 pwrdm->prcm_offs, OMAP4_PM_PWSTST);
479 return 0;
480}
481
482static int omap4_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
483{
484 u32 v;
485
486 v = pwrst << __ffs(OMAP4430_LOGICRETSTATE_MASK);
487 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK, v,
488 pwrdm->prcm_partition, pwrdm->prcm_offs,
489 OMAP4_PM_PWSTCTRL);
490
491 return 0;
492}
493
494static int omap4_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
495 u8 pwrst)
496{
497 u32 m;
498
499 m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
500
501 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
502 pwrdm->prcm_partition, pwrdm->prcm_offs,
503 OMAP4_PM_PWSTCTRL);
504
505 return 0;
506}
507
508static int omap4_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
509 u8 pwrst)
510{
511 u32 m;
512
513 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
514
515 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
516 pwrdm->prcm_partition, pwrdm->prcm_offs,
517 OMAP4_PM_PWSTCTRL);
518
519 return 0;
520}
521
522static int omap4_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
523{
524 u32 v;
525
526 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
527 OMAP4_PM_PWSTST);
528 v &= OMAP4430_LOGICSTATEST_MASK;
529 v >>= OMAP4430_LOGICSTATEST_SHIFT;
530
531 return v;
532}
533
534static int omap4_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
535{
536 u32 v;
537
538 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
539 OMAP4_PM_PWSTCTRL);
540 v &= OMAP4430_LOGICRETSTATE_MASK;
541 v >>= OMAP4430_LOGICRETSTATE_SHIFT;
542
543 return v;
544}
545
546/**
547 * omap4_pwrdm_read_prev_logic_pwrst - read the previous logic powerstate
548 * @pwrdm: struct powerdomain * to read the state for
549 *
550 * Reads the previous logic powerstate for a powerdomain. This
551 * function must determine the previous logic powerstate by first
552 * checking the previous powerstate for the domain. If that was OFF,
553 * then logic has been lost. If previous state was RETENTION, the
554 * function reads the setting for the next retention logic state to
555 * see the actual value. In every other case, the logic is
556 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
557 * depending whether the logic was retained or not.
558 */
559static int omap4_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
560{
561 int state;
562
563 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
564
565 if (state == PWRDM_POWER_OFF)
566 return PWRDM_POWER_OFF;
567
568 if (state != PWRDM_POWER_RET)
569 return PWRDM_POWER_RET;
570
571 return omap4_pwrdm_read_logic_retst(pwrdm);
572}
573
574static int omap4_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
575{
576 u32 m, v;
577
578 m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
579
580 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
581 OMAP4_PM_PWSTST);
582 v &= m;
583 v >>= __ffs(m);
584
585 return v;
586}
587
588static int omap4_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
589{
590 u32 m, v;
591
592 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
593
594 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
595 OMAP4_PM_PWSTCTRL);
596 v &= m;
597 v >>= __ffs(m);
598
599 return v;
600}
601
602/**
603 * omap4_pwrdm_read_prev_mem_pwrst - reads the previous memory powerstate
604 * @pwrdm: struct powerdomain * to read mem powerstate for
605 * @bank: memory bank index
606 *
607 * Reads the previous memory powerstate for a powerdomain. This
608 * function must determine the previous memory powerstate by first
609 * checking the previous powerstate for the domain. If that was OFF,
610 * then logic has been lost. If previous state was RETENTION, the
611 * function reads the setting for the next memory retention state to
612 * see the actual value. In every other case, the logic is
613 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
614 * depending whether logic was retained or not.
615 */
616static int omap4_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
617{
618 int state;
619
620 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
621
622 if (state == PWRDM_POWER_OFF)
623 return PWRDM_POWER_OFF;
624
625 if (state != PWRDM_POWER_RET)
626 return PWRDM_POWER_RET;
627
628 return omap4_pwrdm_read_mem_retst(pwrdm, bank);
629}
630
631static int omap4_pwrdm_wait_transition(struct powerdomain *pwrdm)
632{
633 u32 c = 0;
634
635 /*
636 * REVISIT: pwrdm_wait_transition() may be better implemented
637 * via a callback and a periodic timer check -- how long do we expect
638 * powerdomain transitions to take?
639 */
640
641 /* XXX Is this udelay() value meaningful? */
642 while ((omap4_prminst_read_inst_reg(pwrdm->prcm_partition,
643 pwrdm->prcm_offs,
644 OMAP4_PM_PWSTST) &
645 OMAP_INTRANSITION_MASK) &&
646 (c++ < PWRDM_TRANSITION_BAILOUT))
647 udelay(1);
648
649 if (c > PWRDM_TRANSITION_BAILOUT) {
650 pr_err("powerdomain: %s: waited too long to complete transition\n",
651 pwrdm->name);
652 return -EAGAIN;
653 }
654
655 pr_debug("powerdomain: completed transition in %d loops\n", c);
656
657 return 0;
658}
659
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530660static int omap4_check_vcvp(void)
661{
Tero Kristo3381eb42014-10-27 08:39:23 -0700662 if (prm_features & PRM_HAS_VOLTAGE)
663 return 1;
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530664
Tero Kristo3381eb42014-10-27 08:39:23 -0700665 return 0;
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530666}
667
Paul Walmsley49815392012-10-21 01:01:10 -0600668struct pwrdm_ops omap4_pwrdm_operations = {
669 .pwrdm_set_next_pwrst = omap4_pwrdm_set_next_pwrst,
670 .pwrdm_read_next_pwrst = omap4_pwrdm_read_next_pwrst,
671 .pwrdm_read_pwrst = omap4_pwrdm_read_pwrst,
672 .pwrdm_read_prev_pwrst = omap4_pwrdm_read_prev_pwrst,
673 .pwrdm_set_lowpwrstchange = omap4_pwrdm_set_lowpwrstchange,
674 .pwrdm_clear_all_prev_pwrst = omap4_pwrdm_clear_all_prev_pwrst,
675 .pwrdm_set_logic_retst = omap4_pwrdm_set_logic_retst,
676 .pwrdm_read_logic_pwrst = omap4_pwrdm_read_logic_pwrst,
677 .pwrdm_read_prev_logic_pwrst = omap4_pwrdm_read_prev_logic_pwrst,
678 .pwrdm_read_logic_retst = omap4_pwrdm_read_logic_retst,
679 .pwrdm_read_mem_pwrst = omap4_pwrdm_read_mem_pwrst,
680 .pwrdm_read_mem_retst = omap4_pwrdm_read_mem_retst,
681 .pwrdm_read_prev_mem_pwrst = omap4_pwrdm_read_prev_mem_pwrst,
682 .pwrdm_set_mem_onst = omap4_pwrdm_set_mem_onst,
683 .pwrdm_set_mem_retst = omap4_pwrdm_set_mem_retst,
684 .pwrdm_wait_transition = omap4_pwrdm_wait_transition,
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530685 .pwrdm_has_voltdm = omap4_check_vcvp,
Paul Walmsley49815392012-10-21 01:01:10 -0600686};
687
Tero Kristob550e472014-03-31 18:15:45 +0300688static int omap44xx_prm_late_init(void);
689
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600690/*
691 * XXX document
692 */
693static struct prm_ll_data omap44xx_prm_ll_data = {
694 .read_reset_sources = &omap44xx_prm_read_reset_sources,
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700695 .was_any_context_lost_old = &omap44xx_prm_was_any_context_lost_old,
696 .clear_context_loss_flags_old = &omap44xx_prm_clear_context_loss_flags_old,
Tero Kristob550e472014-03-31 18:15:45 +0300697 .late_init = &omap44xx_prm_late_init,
Tero Kristoefd44dc2014-10-27 08:39:24 -0700698 .assert_hardreset = omap4_prminst_assert_hardreset,
Tero Kristo37fb59d2014-10-27 08:39:25 -0700699 .deassert_hardreset = omap4_prminst_deassert_hardreset,
Tero Kristo1bc28b32014-10-27 08:39:25 -0700700 .is_hardreset_asserted = omap4_prminst_is_hardreset_asserted,
Tero Kristo61c86212014-10-27 08:39:26 -0700701 .reset_system = omap4_prminst_global_warm_sw_reset,
Tero Kristoe9f1ddc2014-04-04 15:52:01 +0300702 .vp_check_txdone = omap4_prm_vp_check_txdone,
703 .vp_clear_txdone = omap4_prm_vp_clear_txdone,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600704};
Paul Walmsley49815392012-10-21 01:01:10 -0600705
Paul Walmsley63a293e2012-11-21 16:15:16 -0700706int __init omap44xx_prm_init(void)
Tero Kristo2f31b512011-12-16 14:37:00 -0700707{
Tero Kristo4e3870f2014-11-06 14:34:32 +0200708 omap_prm_base_init();
709
Nishanth Menon2aba0712014-08-11 14:58:23 -0500710 if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx())
Tero Kristo2541d152014-03-31 18:15:44 +0300711 prm_features |= PRM_HAS_IO_WAKEUP;
Paul Walmsley139563a2012-10-21 01:01:10 -0600712
Tero Kristo3381eb42014-10-27 08:39:23 -0700713 if (!soc_is_dra7xx())
714 prm_features |= PRM_HAS_VOLTAGE;
715
Paul Walmsley63a293e2012-11-21 16:15:16 -0700716 return prm_register(&omap44xx_prm_ll_data);
717}
718
Uwe Kleine-König444d2d32015-02-18 21:19:56 +0100719static const struct of_device_id omap_prm_dt_match_table[] = {
Nishanth Menona8f83ae2014-05-22 15:19:29 -0500720 { .compatible = "ti,omap4-prm" },
721 { .compatible = "ti,omap5-prm" },
722 { .compatible = "ti,dra7-prm" },
723 { }
724};
725
Tony Lindgrenea351c12014-05-16 15:26:22 -0700726static int omap44xx_prm_late_init(void)
Paul Walmsley63a293e2012-11-21 16:15:16 -0700727{
Nishanth Menona8f83ae2014-05-22 15:19:29 -0500728 struct device_node *np;
729 int irq_num;
730
Tero Kristo2541d152014-03-31 18:15:44 +0300731 if (!(prm_features & PRM_HAS_IO_WAKEUP))
Paul Walmsley63a293e2012-11-21 16:15:16 -0700732 return 0;
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600733
Nishanth Menona8f83ae2014-05-22 15:19:29 -0500734 /* OMAP4+ is DT only now */
735 if (!of_have_populated_dt())
736 return 0;
737
738 np = of_find_matching_node(NULL, omap_prm_dt_match_table);
739
740 if (!np) {
741 /* Default loaded up with OMAP4 values */
742 if (!cpu_is_omap44xx())
743 return 0;
744 } else {
745 irq_num = of_irq_get(np, 0);
746 /*
747 * Already have OMAP4 IRQ num. For all other platforms, we need
748 * IRQ numbers from DT
749 */
750 if (irq_num < 0 && !cpu_is_omap44xx()) {
751 if (irq_num == -EPROBE_DEFER)
752 return irq_num;
753
754 /* Have nothing to do */
755 return 0;
756 }
757
758 /* Once OMAP4 DT is filled as well */
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000759 if (irq_num >= 0) {
Nishanth Menona8f83ae2014-05-22 15:19:29 -0500760 omap4_prcm_irq_setup.irq = irq_num;
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000761 omap4_prcm_irq_setup.xlate_irq = NULL;
762 }
Nishanth Menona8f83ae2014-05-22 15:19:29 -0500763 }
764
Paul Walmsley139563a2012-10-21 01:01:10 -0600765 omap44xx_prm_enable_io_wakeup();
766
767 return omap_prcm_register_chain_handler(&omap4_prcm_irq_setup);
Tero Kristo2f31b512011-12-16 14:37:00 -0700768}
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600769
770static void __exit omap44xx_prm_exit(void)
771{
Tero Kristod8871cd2014-05-11 19:54:58 -0600772 prm_unregister(&omap44xx_prm_ll_data);
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600773}
774__exitcall(omap44xx_prm_exit);