2 * Copyright (C) ST-Ericsson SA 2010-2013
3 * Author: Rickard Andersson <rickard.andersson@stericsson.com> for
5 * Author: Daniel Lezcano <daniel.lezcano@linaro.org> for Linaro.
6 * Author: Ulf Hansson <ulf.hansson@linaro.org> for Linaro.
8 * License terms: GNU General Public License (GPL) version 2
12 #include <linux/kernel.h>
13 #include <linux/irqchip/arm-gic.h>
14 #include <linux/delay.h>
16 #include <linux/suspend.h>
17 #include <linux/platform_data/arm-ux500-pm.h>
19 #include <linux/of_address.h>
21 #include "db8500-regs.h"
23 /* ARM WFI Standby signal register */
24 #define PRCM_ARM_WFI_STANDBY (prcmu_base + 0x130)
25 #define PRCM_ARM_WFI_STANDBY_WFI0 0x08
26 #define PRCM_ARM_WFI_STANDBY_WFI1 0x10
27 #define PRCM_IOCR (prcmu_base + 0x310)
28 #define PRCM_IOCR_IOFORCE 0x1
30 /* Dual A9 core interrupt management unit registers */
31 #define PRCM_A9_MASK_REQ (prcmu_base + 0x328)
32 #define PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ 0x1
34 #define PRCM_A9_MASK_ACK (prcmu_base + 0x32c)
35 #define PRCM_ARMITMSK31TO0 (prcmu_base + 0x11c)
36 #define PRCM_ARMITMSK63TO32 (prcmu_base + 0x120)
37 #define PRCM_ARMITMSK95TO64 (prcmu_base + 0x124)
38 #define PRCM_ARMITMSK127TO96 (prcmu_base + 0x128)
39 #define PRCM_POWER_STATE_VAL (prcmu_base + 0x25C)
40 #define PRCM_ARMITVAL31TO0 (prcmu_base + 0x260)
41 #define PRCM_ARMITVAL63TO32 (prcmu_base + 0x264)
42 #define PRCM_ARMITVAL95TO64 (prcmu_base + 0x268)
43 #define PRCM_ARMITVAL127TO96 (prcmu_base + 0x26C)
45 static void __iomem
*prcmu_base
;
46 static void __iomem
*dist_base
;
48 /* This function decouple the gic from the prcmu */
49 int prcmu_gic_decouple(void)
51 u32 val
= readl(PRCM_A9_MASK_REQ
);
53 /* Set bit 0 register value to 1 */
54 writel(val
| PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ
,
57 /* Make sure the register is updated */
58 readl(PRCM_A9_MASK_REQ
);
60 /* Wait a few cycles for the gic mask completion */
66 /* This function recouple the gic with the prcmu */
67 int prcmu_gic_recouple(void)
69 u32 val
= readl(PRCM_A9_MASK_REQ
);
71 /* Set bit 0 register value to 0 */
72 writel(val
& ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ
, PRCM_A9_MASK_REQ
);
77 #define PRCMU_GIC_NUMBER_REGS 5
80 * This function checks if there are pending irq on the gic. It only
81 * makes sense if the gic has been decoupled before with the
82 * db8500_prcmu_gic_decouple function. Disabling an interrupt only
83 * disables the forwarding of the interrupt to any CPU interface. It
84 * does not prevent the interrupt from changing state, for example
85 * becoming pending, or active and pending if it is already
86 * active. Hence, we have to check the interrupt is pending *and* is
89 bool prcmu_gic_pending_irq(void)
91 u32 pr
; /* Pending register */
92 u32 er
; /* Enable register */
95 /* 5 registers. STI & PPI not skipped */
96 for (i
= 0; i
< PRCMU_GIC_NUMBER_REGS
; i
++) {
98 pr
= readl_relaxed(dist_base
+ GIC_DIST_PENDING_SET
+ i
* 4);
99 er
= readl_relaxed(dist_base
+ GIC_DIST_ENABLE_SET
+ i
* 4);
102 return true; /* There is a pending interrupt */
109 * This function checks if there are pending interrupt on the
110 * prcmu which has been delegated to monitor the irqs with the
111 * db8500_prcmu_copy_gic_settings function.
113 bool prcmu_pending_irq(void)
118 for (i
= 0; i
< PRCMU_GIC_NUMBER_REGS
- 1; i
++) {
119 it
= readl(PRCM_ARMITVAL31TO0
+ i
* 4);
120 im
= readl(PRCM_ARMITMSK31TO0
+ i
* 4);
122 return true; /* There is a pending interrupt */
129 * This function checks if the specified cpu is in in WFI. It's usage
130 * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple
131 * function. Of course passing smp_processor_id() to this function will
132 * always return false...
134 bool prcmu_is_cpu_in_wfi(int cpu
)
136 return readl(PRCM_ARM_WFI_STANDBY
) &
137 (cpu
? PRCM_ARM_WFI_STANDBY_WFI1
: PRCM_ARM_WFI_STANDBY_WFI0
);
141 * This function copies the gic SPI settings to the prcmu in order to
142 * monitor them and abort/finish the retention/off sequence or state.
144 int prcmu_copy_gic_settings(void)
146 u32 er
; /* Enable register */
149 /* We skip the STI and PPI */
150 for (i
= 0; i
< PRCMU_GIC_NUMBER_REGS
- 1; i
++) {
151 er
= readl_relaxed(dist_base
+
152 GIC_DIST_ENABLE_SET
+ (i
+ 1) * 4);
153 writel(er
, PRCM_ARMITMSK31TO0
+ i
* 4);
159 #ifdef CONFIG_SUSPEND
160 static int ux500_suspend_enter(suspend_state_t state
)
166 static int ux500_suspend_valid(suspend_state_t state
)
168 return state
== PM_SUSPEND_MEM
|| state
== PM_SUSPEND_STANDBY
;
171 static const struct platform_suspend_ops ux500_suspend_ops
= {
172 .enter
= ux500_suspend_enter
,
173 .valid
= ux500_suspend_valid
,
175 #define UX500_SUSPEND_OPS (&ux500_suspend_ops)
177 #define UX500_SUSPEND_OPS NULL
180 void __init
ux500_pm_init(u32 phy_base
, u32 size
)
182 struct device_node
*np
;
184 prcmu_base
= ioremap(phy_base
, size
);
186 pr_err("could not remap PRCMU for PM functions\n");
189 np
= of_find_compatible_node(NULL
, NULL
, "arm,cortex-a9-gic");
190 dist_base
= of_iomap(np
, 0);
193 pr_err("could not remap GIC dist base for PM functions\n");
198 * On watchdog reboot the GIC is in some cases decoupled.
199 * This will make sure that the GIC is correctly configured.
201 prcmu_gic_recouple();
203 /* Set up ux500 suspend callbacks. */
204 suspend_set_ops(UX500_SUSPEND_OPS
);