blob: acb95936dfe74c350e9cea47e2b57dcfbb7e28f9 [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>
Keerthycc843712015-07-16 17:23:18 +053021#include <linux/of.h>
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"
Keerthycc843712015-07-16 17:23:18 +053028#include "prcm43xx.h"
Benoît Cousson0be16212010-09-21 10:34:10 -060029#include "prm-regbits-44xx.h"
Kevin Hilman4bb73ad2011-03-28 10:25:12 -070030#include "prcm44xx.h"
31#include "prminst44xx.h"
Paul Walmsley49815392012-10-21 01:01:10 -060032#include "powerdomain.h"
Benoît Cousson0be16212010-09-21 10:34:10 -060033
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -060034/* Static data */
35
Tero Kristo28db51f2014-10-27 08:39:26 -070036static void omap44xx_prm_read_pending_irqs(unsigned long *events);
37static void omap44xx_prm_ocp_barrier(void);
38static void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask);
39static void omap44xx_prm_restore_irqen(u32 *saved_mask);
Tero Kristo4984eea2014-10-27 08:39:26 -070040static void omap44xx_prm_reconfigure_io_chain(void);
Tero Kristo28db51f2014-10-27 08:39:26 -070041
Tero Kristo2f31b512011-12-16 14:37:00 -070042static const struct omap_prcm_irq omap4_prcm_irqs[] = {
Tero Kristo2f31b512011-12-16 14:37:00 -070043 OMAP_PRCM_IRQ("io", 9, 1),
44};
45
46static struct omap_prcm_irq_setup omap4_prcm_irq_setup = {
47 .ack = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
48 .mask = OMAP4_PRM_IRQENABLE_MPU_OFFSET,
Keerthyfac03f12015-07-16 17:23:16 +053049 .pm_ctrl = OMAP4_PRM_IO_PMCTRL_OFFSET,
Tero Kristo2f31b512011-12-16 14:37:00 -070050 .nr_regs = 2,
51 .irqs = omap4_prcm_irqs,
52 .nr_irqs = ARRAY_SIZE(omap4_prcm_irqs),
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{
Tero Kristo90129332017-05-31 18:00:00 +030092 return readl_relaxed(prm_base.va + 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{
Tero Kristo90129332017-05-31 18:00:00 +030098 writel_relaxed(val, prm_base.va + 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{
Keerthy8d4be7d2015-07-08 11:12:26 +0530219 int i;
Paul Walmsley26c98c52011-12-16 14:36:58 -0700220
Keerthy8d4be7d2015-07-08 11:12:26 +0530221 for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++)
222 events[i] = _read_pending_irq_reg(omap4_prcm_irq_setup.mask +
223 i * 4, omap4_prcm_irq_setup.ack + i * 4);
Paul Walmsley26c98c52011-12-16 14:36:58 -0700224}
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{
Keerthy8d4be7d2015-07-08 11:12:26 +0530253 int i;
254 u16 reg;
Tero Kristo91285b62011-12-16 14:36:58 -0700255
Keerthy8d4be7d2015-07-08 11:12:26 +0530256 for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++) {
257 reg = omap4_prcm_irq_setup.mask + i * 4;
258
259 saved_mask[i] =
260 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
261 reg);
262 omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST, reg);
263 }
Tero Kristo91285b62011-12-16 14:36:58 -0700264
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{
Keerthy8d4be7d2015-07-08 11:12:26 +0530282 int i;
283
284 for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++)
285 omap4_prm_write_inst_reg(saved_mask[i],
286 OMAP4430_PRM_OCP_SOCKET_INST,
287 omap4_prcm_irq_setup.mask + i * 4);
Tero Kristo91285b62011-12-16 14:36:58 -0700288}
Tero Kristo2f31b512011-12-16 14:37:00 -0700289
Rajendra Nayakdea62002012-06-22 08:40:03 -0600290/**
291 * omap44xx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
292 *
293 * Clear any previously-latched I/O wakeup events and ensure that the
294 * I/O wakeup gates are aligned with the current mux settings. Works
295 * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
296 * deasserting WUCLKIN and waiting for WUCLKOUT to be deasserted.
297 * No return value. XXX Are the final two steps necessary?
298 */
Tero Kristo4984eea2014-10-27 08:39:26 -0700299static void omap44xx_prm_reconfigure_io_chain(void)
Rajendra Nayakdea62002012-06-22 08:40:03 -0600300{
301 int i = 0;
Nishanth Menon390ddc12014-05-22 15:00:55 -0500302 s32 inst = omap4_prmst_get_prm_dev_inst();
303
304 if (inst == PRM_INSTANCE_UNKNOWN)
305 return;
Rajendra Nayakdea62002012-06-22 08:40:03 -0600306
307 /* Trigger WUCLKIN enable */
308 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK,
309 OMAP4430_WUCLK_CTRL_MASK,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500310 inst,
Keerthyfac03f12015-07-16 17:23:16 +0530311 omap4_prcm_irq_setup.pm_ctrl);
Rajendra Nayakdea62002012-06-22 08:40:03 -0600312 omap_test_timeout(
Nishanth Menon390ddc12014-05-22 15:00:55 -0500313 (((omap4_prm_read_inst_reg(inst,
Keerthyfac03f12015-07-16 17:23:16 +0530314 omap4_prcm_irq_setup.pm_ctrl) &
Rajendra Nayakdea62002012-06-22 08:40:03 -0600315 OMAP4430_WUCLK_STATUS_MASK) >>
316 OMAP4430_WUCLK_STATUS_SHIFT) == 1),
317 MAX_IOPAD_LATCH_TIME, i);
318 if (i == MAX_IOPAD_LATCH_TIME)
319 pr_warn("PRM: I/O chain clock line assertion timed out\n");
320
321 /* Trigger WUCLKIN disable */
322 omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK, 0x0,
Nishanth Menon390ddc12014-05-22 15:00:55 -0500323 inst,
Keerthyfac03f12015-07-16 17:23:16 +0530324 omap4_prcm_irq_setup.pm_ctrl);
Rajendra Nayakdea62002012-06-22 08:40:03 -0600325 omap_test_timeout(
Nishanth Menon390ddc12014-05-22 15:00:55 -0500326 (((omap4_prm_read_inst_reg(inst,
Keerthyfac03f12015-07-16 17:23:16 +0530327 omap4_prcm_irq_setup.pm_ctrl) &
Rajendra Nayakdea62002012-06-22 08:40:03 -0600328 OMAP4430_WUCLK_STATUS_MASK) >>
329 OMAP4430_WUCLK_STATUS_SHIFT) == 0),
330 MAX_IOPAD_LATCH_TIME, i);
331 if (i == MAX_IOPAD_LATCH_TIME)
332 pr_warn("PRM: I/O chain clock line deassertion timed out\n");
333
334 return;
335}
336
Tero Kristo8a680ea2012-06-22 08:40:03 -0600337/**
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700338 * omap44xx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
339 *
340 * Activates the I/O wakeup event latches and allows events logged by
341 * those latches to signal a wakeup event to the PRCM. For I/O wakeups
342 * to occur, WAKEUPENABLE bits must be set in the pad mux registers, and
343 * omap44xx_prm_reconfigure_io_chain() must be called. No return value.
344 */
345static void __init omap44xx_prm_enable_io_wakeup(void)
346{
347 s32 inst = omap4_prmst_get_prm_dev_inst();
348
349 if (inst == PRM_INSTANCE_UNKNOWN)
350 return;
351
352 omap4_prm_rmw_inst_reg_bits(OMAP4430_GLOBAL_WUEN_MASK,
353 OMAP4430_GLOBAL_WUEN_MASK,
354 inst,
355 omap4_prcm_irq_setup.pm_ctrl);
356}
357
358/**
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600359 * omap44xx_prm_read_reset_sources - return the last SoC reset source
360 *
361 * Return a u32 representing the last reset sources of the SoC. The
362 * returned reset source bits are standardized across OMAP SoCs.
363 */
364static u32 omap44xx_prm_read_reset_sources(void)
365{
366 struct prm_reset_src_map *p;
367 u32 r = 0;
368 u32 v;
Nishanth Menon390ddc12014-05-22 15:00:55 -0500369 s32 inst = omap4_prmst_get_prm_dev_inst();
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600370
Nishanth Menon390ddc12014-05-22 15:00:55 -0500371 if (inst == PRM_INSTANCE_UNKNOWN)
372 return 0;
373
374
375 v = omap4_prm_read_inst_reg(inst,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600376 OMAP4_RM_RSTST);
377
378 p = omap44xx_prm_reset_src_map;
379 while (p->reg_shift >= 0 && p->std_shift >= 0) {
380 if (v & (1 << p->reg_shift))
381 r |= 1 << p->std_shift;
382 p++;
383 }
384
385 return r;
386}
387
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700388/**
389 * omap44xx_prm_was_any_context_lost_old - was module hardware context lost?
390 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
391 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
392 * @idx: CONTEXT register offset
393 *
394 * Return 1 if any bits were set in the *_CONTEXT_* register
395 * identified by (@part, @inst, @idx), which means that some context
396 * was lost for that module; otherwise, return 0.
397 */
398static bool omap44xx_prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
399{
400 return (omap4_prminst_read_inst_reg(part, inst, idx)) ? 1 : 0;
401}
402
403/**
404 * omap44xx_prm_clear_context_lost_flags_old - clear context loss flags
405 * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
406 * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
407 * @idx: CONTEXT register offset
408 *
409 * Clear hardware context loss bits for the module identified by
410 * (@part, @inst, @idx). No return value. XXX Writes to reserved bits;
411 * is there a way to avoid this?
412 */
413static void omap44xx_prm_clear_context_loss_flags_old(u8 part, s16 inst,
414 u16 idx)
415{
416 omap4_prminst_write_inst_reg(0xffffffff, part, inst, idx);
417}
418
Paul Walmsley49815392012-10-21 01:01:10 -0600419/* Powerdomain low-level functions */
420
421static int omap4_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
422{
423 omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK,
424 (pwrst << OMAP_POWERSTATE_SHIFT),
425 pwrdm->prcm_partition,
426 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
427 return 0;
428}
429
430static int omap4_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
431{
432 u32 v;
433
434 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
435 OMAP4_PM_PWSTCTRL);
436 v &= OMAP_POWERSTATE_MASK;
437 v >>= OMAP_POWERSTATE_SHIFT;
438
439 return v;
440}
441
442static int omap4_pwrdm_read_pwrst(struct powerdomain *pwrdm)
443{
444 u32 v;
445
446 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
447 OMAP4_PM_PWSTST);
448 v &= OMAP_POWERSTATEST_MASK;
449 v >>= OMAP_POWERSTATEST_SHIFT;
450
451 return v;
452}
453
454static int omap4_pwrdm_read_prev_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_LASTPOWERSTATEENTERED_MASK;
461 v >>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT;
462
463 return v;
464}
465
466static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
467{
468 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK,
469 (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT),
470 pwrdm->prcm_partition,
471 pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
472 return 0;
473}
474
475static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
476{
477 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK,
478 OMAP4430_LASTPOWERSTATEENTERED_MASK,
479 pwrdm->prcm_partition,
480 pwrdm->prcm_offs, OMAP4_PM_PWSTST);
481 return 0;
482}
483
484static int omap4_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
485{
486 u32 v;
487
488 v = pwrst << __ffs(OMAP4430_LOGICRETSTATE_MASK);
489 omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK, v,
490 pwrdm->prcm_partition, pwrdm->prcm_offs,
491 OMAP4_PM_PWSTCTRL);
492
493 return 0;
494}
495
496static int omap4_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
497 u8 pwrst)
498{
499 u32 m;
500
501 m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
502
503 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
504 pwrdm->prcm_partition, pwrdm->prcm_offs,
505 OMAP4_PM_PWSTCTRL);
506
507 return 0;
508}
509
510static int omap4_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
511 u8 pwrst)
512{
513 u32 m;
514
515 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
516
517 omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
518 pwrdm->prcm_partition, pwrdm->prcm_offs,
519 OMAP4_PM_PWSTCTRL);
520
521 return 0;
522}
523
524static int omap4_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
525{
526 u32 v;
527
528 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
529 OMAP4_PM_PWSTST);
530 v &= OMAP4430_LOGICSTATEST_MASK;
531 v >>= OMAP4430_LOGICSTATEST_SHIFT;
532
533 return v;
534}
535
536static int omap4_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
537{
538 u32 v;
539
540 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
541 OMAP4_PM_PWSTCTRL);
542 v &= OMAP4430_LOGICRETSTATE_MASK;
543 v >>= OMAP4430_LOGICRETSTATE_SHIFT;
544
545 return v;
546}
547
548/**
549 * omap4_pwrdm_read_prev_logic_pwrst - read the previous logic powerstate
550 * @pwrdm: struct powerdomain * to read the state for
551 *
552 * Reads the previous logic powerstate for a powerdomain. This
553 * function must determine the previous logic powerstate by first
554 * checking the previous powerstate for the domain. If that was OFF,
555 * then logic has been lost. If previous state was RETENTION, the
556 * function reads the setting for the next retention logic state to
557 * see the actual value. In every other case, the logic is
558 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
559 * depending whether the logic was retained or not.
560 */
561static int omap4_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
562{
563 int state;
564
565 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
566
567 if (state == PWRDM_POWER_OFF)
568 return PWRDM_POWER_OFF;
569
570 if (state != PWRDM_POWER_RET)
571 return PWRDM_POWER_RET;
572
573 return omap4_pwrdm_read_logic_retst(pwrdm);
574}
575
576static int omap4_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
577{
578 u32 m, v;
579
580 m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
581
582 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
583 OMAP4_PM_PWSTST);
584 v &= m;
585 v >>= __ffs(m);
586
587 return v;
588}
589
590static int omap4_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
591{
592 u32 m, v;
593
594 m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
595
596 v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
597 OMAP4_PM_PWSTCTRL);
598 v &= m;
599 v >>= __ffs(m);
600
601 return v;
602}
603
604/**
605 * omap4_pwrdm_read_prev_mem_pwrst - reads the previous memory powerstate
606 * @pwrdm: struct powerdomain * to read mem powerstate for
607 * @bank: memory bank index
608 *
609 * Reads the previous memory powerstate for a powerdomain. This
610 * function must determine the previous memory powerstate by first
611 * checking the previous powerstate for the domain. If that was OFF,
612 * then logic has been lost. If previous state was RETENTION, the
613 * function reads the setting for the next memory retention state to
614 * see the actual value. In every other case, the logic is
615 * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
616 * depending whether logic was retained or not.
617 */
618static int omap4_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
619{
620 int state;
621
622 state = omap4_pwrdm_read_prev_pwrst(pwrdm);
623
624 if (state == PWRDM_POWER_OFF)
625 return PWRDM_POWER_OFF;
626
627 if (state != PWRDM_POWER_RET)
628 return PWRDM_POWER_RET;
629
630 return omap4_pwrdm_read_mem_retst(pwrdm, bank);
631}
632
633static int omap4_pwrdm_wait_transition(struct powerdomain *pwrdm)
634{
635 u32 c = 0;
636
637 /*
638 * REVISIT: pwrdm_wait_transition() may be better implemented
639 * via a callback and a periodic timer check -- how long do we expect
640 * powerdomain transitions to take?
641 */
642
643 /* XXX Is this udelay() value meaningful? */
644 while ((omap4_prminst_read_inst_reg(pwrdm->prcm_partition,
645 pwrdm->prcm_offs,
646 OMAP4_PM_PWSTST) &
647 OMAP_INTRANSITION_MASK) &&
648 (c++ < PWRDM_TRANSITION_BAILOUT))
649 udelay(1);
650
651 if (c > PWRDM_TRANSITION_BAILOUT) {
652 pr_err("powerdomain: %s: waited too long to complete transition\n",
653 pwrdm->name);
654 return -EAGAIN;
655 }
656
657 pr_debug("powerdomain: completed transition in %d loops\n", c);
658
659 return 0;
660}
661
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530662static int omap4_check_vcvp(void)
663{
Tero Kristo3381eb42014-10-27 08:39:23 -0700664 if (prm_features & PRM_HAS_VOLTAGE)
665 return 1;
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530666
Tero Kristo3381eb42014-10-27 08:39:23 -0700667 return 0;
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530668}
669
Paul Walmsley49815392012-10-21 01:01:10 -0600670struct pwrdm_ops omap4_pwrdm_operations = {
671 .pwrdm_set_next_pwrst = omap4_pwrdm_set_next_pwrst,
672 .pwrdm_read_next_pwrst = omap4_pwrdm_read_next_pwrst,
673 .pwrdm_read_pwrst = omap4_pwrdm_read_pwrst,
674 .pwrdm_read_prev_pwrst = omap4_pwrdm_read_prev_pwrst,
675 .pwrdm_set_lowpwrstchange = omap4_pwrdm_set_lowpwrstchange,
676 .pwrdm_clear_all_prev_pwrst = omap4_pwrdm_clear_all_prev_pwrst,
677 .pwrdm_set_logic_retst = omap4_pwrdm_set_logic_retst,
678 .pwrdm_read_logic_pwrst = omap4_pwrdm_read_logic_pwrst,
679 .pwrdm_read_prev_logic_pwrst = omap4_pwrdm_read_prev_logic_pwrst,
680 .pwrdm_read_logic_retst = omap4_pwrdm_read_logic_retst,
681 .pwrdm_read_mem_pwrst = omap4_pwrdm_read_mem_pwrst,
682 .pwrdm_read_mem_retst = omap4_pwrdm_read_mem_retst,
683 .pwrdm_read_prev_mem_pwrst = omap4_pwrdm_read_prev_mem_pwrst,
684 .pwrdm_set_mem_onst = omap4_pwrdm_set_mem_onst,
685 .pwrdm_set_mem_retst = omap4_pwrdm_set_mem_retst,
686 .pwrdm_wait_transition = omap4_pwrdm_wait_transition,
Rajendra Nayak9a4e3012013-07-09 13:02:14 +0530687 .pwrdm_has_voltdm = omap4_check_vcvp,
Paul Walmsley49815392012-10-21 01:01:10 -0600688};
689
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700690static int omap44xx_prm_late_init(void);
691
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600692/*
693 * XXX document
694 */
695static struct prm_ll_data omap44xx_prm_ll_data = {
696 .read_reset_sources = &omap44xx_prm_read_reset_sources,
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700697 .was_any_context_lost_old = &omap44xx_prm_was_any_context_lost_old,
698 .clear_context_loss_flags_old = &omap44xx_prm_clear_context_loss_flags_old,
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700699 .late_init = &omap44xx_prm_late_init,
Tero Kristoefd44dc2014-10-27 08:39:24 -0700700 .assert_hardreset = omap4_prminst_assert_hardreset,
Tero Kristo37fb59d2014-10-27 08:39:25 -0700701 .deassert_hardreset = omap4_prminst_deassert_hardreset,
Tero Kristo1bc28b32014-10-27 08:39:25 -0700702 .is_hardreset_asserted = omap4_prminst_is_hardreset_asserted,
Tero Kristo61c86212014-10-27 08:39:26 -0700703 .reset_system = omap4_prminst_global_warm_sw_reset,
Tero Kristoe9f1ddc2014-04-04 15:52:01 +0300704 .vp_check_txdone = omap4_prm_vp_check_txdone,
705 .vp_clear_txdone = omap4_prm_vp_clear_txdone,
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600706};
Paul Walmsley49815392012-10-21 01:01:10 -0600707
Tero Kristo219595b2014-09-08 11:44:10 +0300708static const struct omap_prcm_init_data *prm_init_data;
709
Tero Kristoab7b2ff2014-11-20 15:02:59 +0200710int __init omap44xx_prm_init(const struct omap_prcm_init_data *data)
Tero Kristo2f31b512011-12-16 14:37:00 -0700711{
Tero Kristo4e3870f2014-11-06 14:34:32 +0200712 omap_prm_base_init();
713
Tero Kristo219595b2014-09-08 11:44:10 +0300714 prm_init_data = data;
715
Tero Kristo8b5b9a22014-11-21 14:45:29 +0200716 if (data->flags & PRM_HAS_IO_WAKEUP)
Tero Kristo2541d152014-03-31 18:15:44 +0300717 prm_features |= PRM_HAS_IO_WAKEUP;
Paul Walmsley139563a2012-10-21 01:01:10 -0600718
Tero Kristo8b5b9a22014-11-21 14:45:29 +0200719 if (data->flags & PRM_HAS_VOLTAGE)
Tero Kristo3381eb42014-10-27 08:39:23 -0700720 prm_features |= PRM_HAS_VOLTAGE;
721
Tero Kristo48e0c112014-09-08 11:29:43 +0300722 omap4_prminst_set_prm_dev_inst(data->device_inst_offset);
723
Keerthycc843712015-07-16 17:23:18 +0530724 /* Add AM437X specific differences */
725 if (of_device_is_compatible(data->np, "ti,am4-prcm")) {
726 omap4_prcm_irq_setup.nr_irqs = 1;
727 omap4_prcm_irq_setup.nr_regs = 1;
728 omap4_prcm_irq_setup.pm_ctrl = AM43XX_PRM_IO_PMCTRL_OFFSET;
729 omap4_prcm_irq_setup.ack = AM43XX_PRM_IRQSTATUS_MPU_OFFSET;
730 omap4_prcm_irq_setup.mask = AM43XX_PRM_IRQENABLE_MPU_OFFSET;
731 }
732
Paul Walmsley63a293e2012-11-21 16:15:16 -0700733 return prm_register(&omap44xx_prm_ll_data);
734}
735
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700736static int omap44xx_prm_late_init(void)
737{
738 int irq_num;
739
740 if (!(prm_features & PRM_HAS_IO_WAKEUP))
741 return 0;
742
743 irq_num = of_irq_get(prm_init_data->np, 0);
Tony Lindgren3da52162017-10-10 14:27:13 -0700744 if (irq_num == -EPROBE_DEFER)
745 return irq_num;
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700746
Tony Lindgren3da52162017-10-10 14:27:13 -0700747 omap4_prcm_irq_setup.irq = irq_num;
Tony Lindgrenc5b39552017-06-30 03:37:03 -0700748
749 omap44xx_prm_enable_io_wakeup();
750
751 return omap_prcm_register_chain_handler(&omap4_prcm_irq_setup);
752}
753
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600754static void __exit omap44xx_prm_exit(void)
755{
Tero Kristod8871cd2014-05-11 19:54:58 -0600756 prm_unregister(&omap44xx_prm_ll_data);
Paul Walmsley2bb2a5d2012-10-21 01:01:13 -0600757}
758__exitcall(omap44xx_prm_exit);