Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Power Management Service Unit(PMSU) support for Armada 370/XP platforms. |
| 3 | * |
| 4 | * Copyright (C) 2012 Marvell |
| 5 | * |
| 6 | * Yehuda Yitschak <yehuday@marvell.com> |
| 7 | * Gregory Clement <gregory.clement@free-electrons.com> |
| 8 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 9 | * |
| 10 | * This file is licensed under the terms of the GNU General Public |
| 11 | * License version 2. This program is licensed "as is" without any |
| 12 | * warranty of any kind, whether express or implied. |
| 13 | * |
| 14 | * The Armada 370 and Armada XP SOCs have a power management service |
| 15 | * unit which is responsible for powering down and waking up CPUs and |
| 16 | * other SOC units |
| 17 | */ |
| 18 | |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 19 | #define pr_fmt(fmt) "mvebu-pmsu: " fmt |
| 20 | |
Gregory CLEMENT | d163ee1 | 2014-04-14 17:10:12 +0200 | [diff] [blame] | 21 | #include <linux/cpu_pm.h> |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 22 | #include <linux/init.h> |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 23 | #include <linux/io.h> |
Gregory CLEMENT | 3e32842 | 2014-07-23 15:00:39 +0200 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Gregory CLEMENT | 3076cc5 | 2014-07-23 15:00:40 +0200 | [diff] [blame] | 25 | #include <linux/mbus.h> |
Gregory CLEMENT | 3e32842 | 2014-07-23 15:00:39 +0200 | [diff] [blame] | 26 | #include <linux/of_address.h> |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 28 | #include <linux/resource.h> |
Gregory CLEMENT | 3e32842 | 2014-07-23 15:00:39 +0200 | [diff] [blame] | 29 | #include <linux/smp.h> |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 30 | #include <asm/cacheflush.h> |
| 31 | #include <asm/cp15.h> |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 32 | #include <asm/smp_plat.h> |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 33 | #include <asm/suspend.h> |
| 34 | #include <asm/tlbflush.h> |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 35 | #include "common.h" |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 36 | |
| 37 | static void __iomem *pmsu_mp_base; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 38 | |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame] | 39 | #define PMSU_BASE_OFFSET 0x100 |
| 40 | #define PMSU_REG_SIZE 0x1000 |
| 41 | |
Gregory CLEMENT | f713c7e | 2014-04-14 17:10:10 +0200 | [diff] [blame] | 42 | /* PMSU MP registers */ |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 43 | #define PMSU_CONTROL_AND_CONFIG(cpu) ((cpu * 0x100) + 0x104) |
| 44 | #define PMSU_CONTROL_AND_CONFIG_DFS_REQ BIT(18) |
| 45 | #define PMSU_CONTROL_AND_CONFIG_PWDDN_REQ BIT(16) |
| 46 | #define PMSU_CONTROL_AND_CONFIG_L2_PWDDN BIT(20) |
| 47 | |
| 48 | #define PMSU_CPU_POWER_DOWN_CONTROL(cpu) ((cpu * 0x100) + 0x108) |
| 49 | |
| 50 | #define PMSU_CPU_POWER_DOWN_DIS_SNP_Q_SKIP BIT(0) |
| 51 | |
| 52 | #define PMSU_STATUS_AND_MASK(cpu) ((cpu * 0x100) + 0x10c) |
| 53 | #define PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT BIT(16) |
| 54 | #define PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT BIT(17) |
| 55 | #define PMSU_STATUS_AND_MASK_IRQ_WAKEUP BIT(20) |
| 56 | #define PMSU_STATUS_AND_MASK_FIQ_WAKEUP BIT(21) |
| 57 | #define PMSU_STATUS_AND_MASK_DBG_WAKEUP BIT(22) |
| 58 | #define PMSU_STATUS_AND_MASK_IRQ_MASK BIT(24) |
| 59 | #define PMSU_STATUS_AND_MASK_FIQ_MASK BIT(25) |
| 60 | |
Gregory CLEMENT | f713c7e | 2014-04-14 17:10:10 +0200 | [diff] [blame] | 61 | #define PMSU_BOOT_ADDR_REDIRECT_OFFSET(cpu) ((cpu * 0x100) + 0x124) |
| 62 | |
| 63 | /* PMSU fabric registers */ |
| 64 | #define L2C_NFABRIC_PM_CTL 0x4 |
| 65 | #define L2C_NFABRIC_PM_CTL_PWR_DOWN BIT(20) |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 66 | |
Gregory CLEMENT | 3076cc5 | 2014-07-23 15:00:40 +0200 | [diff] [blame] | 67 | #define SRAM_PHYS_BASE 0xFFFF0000 |
| 68 | #define BOOTROM_BASE 0xFFF00000 |
| 69 | #define BOOTROM_SIZE 0x100000 |
| 70 | |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 71 | extern void ll_disable_coherency(void); |
| 72 | extern void ll_enable_coherency(void); |
| 73 | |
Thomas Petazzoni | 6509dc7 | 2014-06-30 14:09:25 +0200 | [diff] [blame] | 74 | extern void armada_370_xp_cpu_resume(void); |
| 75 | |
Gregory CLEMENT | 752a993 | 2014-07-23 15:00:44 +0200 | [diff] [blame] | 76 | static void *mvebu_cpu_resume; |
| 77 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 78 | static struct platform_device mvebu_v7_cpuidle_device = { |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 79 | .name = "cpuidle-armada-xp", |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 82 | static struct of_device_id of_pmsu_table[] = { |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame] | 83 | { .compatible = "marvell,armada-370-pmsu", }, |
| 84 | { .compatible = "marvell,armada-370-xp-pmsu", }, |
Thomas Petazzoni | b4bca24 | 2014-04-14 15:54:04 +0200 | [diff] [blame] | 85 | { .compatible = "marvell,armada-380-pmsu", }, |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 86 | { /* end of list */ }, |
| 87 | }; |
| 88 | |
Thomas Petazzoni | 05ad690 | 2014-04-14 15:53:58 +0200 | [diff] [blame] | 89 | void mvebu_pmsu_set_cpu_boot_addr(int hw_cpu, void *boot_addr) |
Gregory CLEMENT | 02e7b06 | 2014-04-14 15:50:33 +0200 | [diff] [blame] | 90 | { |
| 91 | writel(virt_to_phys(boot_addr), pmsu_mp_base + |
| 92 | PMSU_BOOT_ADDR_REDIRECT_OFFSET(hw_cpu)); |
| 93 | } |
| 94 | |
Gregory CLEMENT | 3076cc5 | 2014-07-23 15:00:40 +0200 | [diff] [blame] | 95 | extern unsigned char mvebu_boot_wa_start; |
| 96 | extern unsigned char mvebu_boot_wa_end; |
| 97 | |
| 98 | /* |
| 99 | * This function sets up the boot address workaround needed for SMP |
| 100 | * boot on Armada 375 Z1 and cpuidle on Armada 370. It unmaps the |
| 101 | * BootROM Mbus window, and instead remaps a crypto SRAM into which a |
| 102 | * custom piece of code is copied to replace the problematic BootROM. |
| 103 | */ |
| 104 | int mvebu_setup_boot_addr_wa(unsigned int crypto_eng_target, |
| 105 | unsigned int crypto_eng_attribute, |
| 106 | phys_addr_t resume_addr_reg) |
| 107 | { |
| 108 | void __iomem *sram_virt_base; |
| 109 | u32 code_len = &mvebu_boot_wa_end - &mvebu_boot_wa_start; |
| 110 | |
| 111 | mvebu_mbus_del_window(BOOTROM_BASE, BOOTROM_SIZE); |
| 112 | mvebu_mbus_add_window_by_id(crypto_eng_target, crypto_eng_attribute, |
| 113 | SRAM_PHYS_BASE, SZ_64K); |
| 114 | |
| 115 | sram_virt_base = ioremap(SRAM_PHYS_BASE, SZ_64K); |
| 116 | if (!sram_virt_base) { |
| 117 | pr_err("Unable to map SRAM to setup the boot address WA\n"); |
| 118 | return -ENOMEM; |
| 119 | } |
| 120 | |
| 121 | memcpy(sram_virt_base, &mvebu_boot_wa_start, code_len); |
| 122 | |
| 123 | /* |
| 124 | * The last word of the code copied in SRAM must contain the |
| 125 | * physical base address of the PMSU register. We |
| 126 | * intentionally store this address in the native endianness |
| 127 | * of the system. |
| 128 | */ |
| 129 | __raw_writel((unsigned long)resume_addr_reg, |
| 130 | sram_virt_base + code_len - 4); |
| 131 | |
| 132 | iounmap(sram_virt_base); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 137 | static int __init mvebu_v7_pmsu_init(void) |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 138 | { |
| 139 | struct device_node *np; |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 140 | struct resource res; |
| 141 | int ret = 0; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 142 | |
| 143 | np = of_find_matching_node(NULL, of_pmsu_table); |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 144 | if (!np) |
| 145 | return 0; |
| 146 | |
| 147 | pr_info("Initializing Power Management Service Unit\n"); |
| 148 | |
| 149 | if (of_address_to_resource(np, 0, &res)) { |
| 150 | pr_err("unable to get resource\n"); |
| 151 | ret = -ENOENT; |
| 152 | goto out; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 153 | } |
| 154 | |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame] | 155 | if (of_device_is_compatible(np, "marvell,armada-370-xp-pmsu")) { |
| 156 | pr_warn(FW_WARN "deprecated pmsu binding\n"); |
| 157 | res.start = res.start - PMSU_BASE_OFFSET; |
| 158 | res.end = res.start + PMSU_REG_SIZE - 1; |
| 159 | } |
| 160 | |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 161 | if (!request_mem_region(res.start, resource_size(&res), |
| 162 | np->full_name)) { |
| 163 | pr_err("unable to request region\n"); |
| 164 | ret = -EBUSY; |
| 165 | goto out; |
| 166 | } |
| 167 | |
| 168 | pmsu_mp_base = ioremap(res.start, resource_size(&res)); |
| 169 | if (!pmsu_mp_base) { |
| 170 | pr_err("unable to map registers\n"); |
| 171 | release_mem_region(res.start, resource_size(&res)); |
| 172 | ret = -ENOMEM; |
| 173 | goto out; |
| 174 | } |
| 175 | |
| 176 | out: |
| 177 | of_node_put(np); |
| 178 | return ret; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 179 | } |
| 180 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 181 | static void mvebu_v7_pmsu_enable_l2_powerdown_onidle(void) |
Gregory CLEMENT | f713c7e | 2014-04-14 17:10:10 +0200 | [diff] [blame] | 182 | { |
| 183 | u32 reg; |
| 184 | |
| 185 | if (pmsu_mp_base == NULL) |
| 186 | return; |
| 187 | |
| 188 | /* Enable L2 & Fabric powerdown in Deep-Idle mode - Fabric */ |
| 189 | reg = readl(pmsu_mp_base + L2C_NFABRIC_PM_CTL); |
| 190 | reg |= L2C_NFABRIC_PM_CTL_PWR_DOWN; |
| 191 | writel(reg, pmsu_mp_base + L2C_NFABRIC_PM_CTL); |
| 192 | } |
| 193 | |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 194 | enum pmsu_idle_prepare_flags { |
| 195 | PMSU_PREPARE_NORMAL = 0, |
| 196 | PMSU_PREPARE_DEEP_IDLE = BIT(0), |
| 197 | PMSU_PREPARE_SNOOP_DISABLE = BIT(1), |
| 198 | }; |
| 199 | |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 200 | /* No locking is needed because we only access per-CPU registers */ |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 201 | static int mvebu_v7_pmsu_idle_prepare(unsigned long flags) |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 202 | { |
| 203 | unsigned int hw_cpu = cpu_logical_map(smp_processor_id()); |
| 204 | u32 reg; |
| 205 | |
| 206 | if (pmsu_mp_base == NULL) |
Thomas Petazzoni | bbb9228 | 2014-05-30 22:18:15 +0200 | [diff] [blame] | 207 | return -EINVAL; |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Adjust the PMSU configuration to wait for WFI signal, enable |
| 211 | * IRQ and FIQ as wakeup events, set wait for snoop queue empty |
| 212 | * indication and mask IRQ and FIQ from CPU |
| 213 | */ |
| 214 | reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu)); |
| 215 | reg |= PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT | |
| 216 | PMSU_STATUS_AND_MASK_IRQ_WAKEUP | |
| 217 | PMSU_STATUS_AND_MASK_FIQ_WAKEUP | |
| 218 | PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT | |
| 219 | PMSU_STATUS_AND_MASK_IRQ_MASK | |
| 220 | PMSU_STATUS_AND_MASK_FIQ_MASK; |
| 221 | writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu)); |
| 222 | |
| 223 | reg = readl(pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu)); |
| 224 | /* ask HW to power down the L2 Cache if needed */ |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 225 | if (flags & PMSU_PREPARE_DEEP_IDLE) |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 226 | reg |= PMSU_CONTROL_AND_CONFIG_L2_PWDDN; |
| 227 | |
| 228 | /* request power down */ |
| 229 | reg |= PMSU_CONTROL_AND_CONFIG_PWDDN_REQ; |
| 230 | writel(reg, pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu)); |
| 231 | |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 232 | if (flags & PMSU_PREPARE_SNOOP_DISABLE) { |
| 233 | /* Disable snoop disable by HW - SW is taking care of it */ |
| 234 | reg = readl(pmsu_mp_base + PMSU_CPU_POWER_DOWN_CONTROL(hw_cpu)); |
| 235 | reg |= PMSU_CPU_POWER_DOWN_DIS_SNP_Q_SKIP; |
| 236 | writel(reg, pmsu_mp_base + PMSU_CPU_POWER_DOWN_CONTROL(hw_cpu)); |
| 237 | } |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 238 | |
Gregory CLEMENT | 9ce3588 | 2014-07-23 15:00:38 +0200 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | int armada_370_xp_pmsu_idle_enter(unsigned long deepidle) |
| 243 | { |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 244 | unsigned long flags = PMSU_PREPARE_SNOOP_DISABLE; |
Gregory CLEMENT | 9ce3588 | 2014-07-23 15:00:38 +0200 | [diff] [blame] | 245 | int ret; |
| 246 | |
Gregory CLEMENT | 5da964e | 2014-07-23 15:00:45 +0200 | [diff] [blame] | 247 | if (deepidle) |
| 248 | flags |= PMSU_PREPARE_DEEP_IDLE; |
| 249 | |
| 250 | ret = mvebu_v7_pmsu_idle_prepare(flags); |
Gregory CLEMENT | 9ce3588 | 2014-07-23 15:00:38 +0200 | [diff] [blame] | 251 | if (ret) |
| 252 | return ret; |
| 253 | |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 254 | v7_exit_coherency_flush(all); |
| 255 | |
| 256 | ll_disable_coherency(); |
| 257 | |
| 258 | dsb(); |
| 259 | |
| 260 | wfi(); |
| 261 | |
| 262 | /* If we are here, wfi failed. As processors run out of |
| 263 | * coherency for some time, tlbs might be stale, so flush them |
| 264 | */ |
| 265 | local_flush_tlb_all(); |
| 266 | |
| 267 | ll_enable_coherency(); |
| 268 | |
| 269 | /* Test the CR_C bit and set it if it was cleared */ |
| 270 | asm volatile( |
Gregory CLEMENT | 0d461e1 | 2014-07-04 16:22:16 +0200 | [diff] [blame] | 271 | "mrc p15, 0, r0, c1, c0, 0 \n\t" |
| 272 | "tst r0, #(1 << 2) \n\t" |
| 273 | "orreq r0, r0, #(1 << 2) \n\t" |
| 274 | "mcreq p15, 0, r0, c1, c0, 0 \n\t" |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 275 | "isb " |
Gregory CLEMENT | 0d461e1 | 2014-07-04 16:22:16 +0200 | [diff] [blame] | 276 | : : : "r0"); |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 277 | |
| 278 | pr_warn("Failed to suspend the system\n"); |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int armada_370_xp_cpu_suspend(unsigned long deepidle) |
| 284 | { |
Thomas Petazzoni | bbb9228 | 2014-05-30 22:18:15 +0200 | [diff] [blame] | 285 | return cpu_suspend(deepidle, armada_370_xp_pmsu_idle_enter); |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* No locking is needed because we only access per-CPU registers */ |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 289 | void mvebu_v7_pmsu_idle_exit(void) |
Gregory CLEMENT | c3e04ca | 2014-04-14 17:10:11 +0200 | [diff] [blame] | 290 | { |
| 291 | unsigned int hw_cpu = cpu_logical_map(smp_processor_id()); |
| 292 | u32 reg; |
| 293 | |
| 294 | if (pmsu_mp_base == NULL) |
| 295 | return; |
| 296 | |
| 297 | /* cancel ask HW to power down the L2 Cache if possible */ |
| 298 | reg = readl(pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu)); |
| 299 | reg &= ~PMSU_CONTROL_AND_CONFIG_L2_PWDDN; |
| 300 | writel(reg, pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu)); |
| 301 | |
| 302 | /* cancel Enable wakeup events and mask interrupts */ |
| 303 | reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu)); |
| 304 | reg &= ~(PMSU_STATUS_AND_MASK_IRQ_WAKEUP | PMSU_STATUS_AND_MASK_FIQ_WAKEUP); |
| 305 | reg &= ~PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT; |
| 306 | reg &= ~PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT; |
| 307 | reg &= ~(PMSU_STATUS_AND_MASK_IRQ_MASK | PMSU_STATUS_AND_MASK_FIQ_MASK); |
| 308 | writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu)); |
| 309 | } |
| 310 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 311 | static int mvebu_v7_cpu_pm_notify(struct notifier_block *self, |
Gregory CLEMENT | d163ee1 | 2014-04-14 17:10:12 +0200 | [diff] [blame] | 312 | unsigned long action, void *hcpu) |
| 313 | { |
| 314 | if (action == CPU_PM_ENTER) { |
| 315 | unsigned int hw_cpu = cpu_logical_map(smp_processor_id()); |
Gregory CLEMENT | 752a993 | 2014-07-23 15:00:44 +0200 | [diff] [blame] | 316 | mvebu_pmsu_set_cpu_boot_addr(hw_cpu, mvebu_cpu_resume); |
Gregory CLEMENT | d163ee1 | 2014-04-14 17:10:12 +0200 | [diff] [blame] | 317 | } else if (action == CPU_PM_EXIT) { |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 318 | mvebu_v7_pmsu_idle_exit(); |
Gregory CLEMENT | d163ee1 | 2014-04-14 17:10:12 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | return NOTIFY_OK; |
| 322 | } |
| 323 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 324 | static struct notifier_block mvebu_v7_cpu_pm_notifier = { |
| 325 | .notifier_call = mvebu_v7_cpu_pm_notify, |
Gregory CLEMENT | d163ee1 | 2014-04-14 17:10:12 +0200 | [diff] [blame] | 326 | }; |
| 327 | |
Gregory CLEMENT | 54a4d1b | 2014-07-23 15:00:43 +0200 | [diff] [blame] | 328 | static int __init armada_xp_cpuidle_init(void) |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 329 | { |
| 330 | struct device_node *np; |
| 331 | |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 332 | np = of_find_compatible_node(NULL, NULL, "marvell,coherency-fabric"); |
| 333 | if (!np) |
Gregory CLEMENT | 54a4d1b | 2014-07-23 15:00:43 +0200 | [diff] [blame] | 334 | return -ENODEV; |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 335 | of_node_put(np); |
| 336 | |
Gregory CLEMENT | 752a993 | 2014-07-23 15:00:44 +0200 | [diff] [blame] | 337 | mvebu_cpu_resume = armada_370_xp_cpu_resume; |
Gregory CLEMENT | 54a4d1b | 2014-07-23 15:00:43 +0200 | [diff] [blame] | 338 | mvebu_v7_cpuidle_device.dev.platform_data = armada_370_xp_cpu_suspend; |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int __init mvebu_v7_cpu_pm_init(void) |
| 344 | { |
| 345 | struct device_node *np; |
| 346 | int ret; |
| 347 | |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 348 | np = of_find_matching_node(NULL, of_pmsu_table); |
| 349 | if (!np) |
| 350 | return 0; |
| 351 | of_node_put(np); |
| 352 | |
Gregory CLEMENT | 54a4d1b | 2014-07-23 15:00:43 +0200 | [diff] [blame] | 353 | if (of_machine_is_compatible("marvell,armadaxp")) |
| 354 | ret = armada_xp_cpuidle_init(); |
| 355 | else |
| 356 | return 0; |
| 357 | |
| 358 | if (ret) |
| 359 | return ret; |
| 360 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 361 | mvebu_v7_pmsu_enable_l2_powerdown_onidle(); |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 362 | platform_device_register(&mvebu_v7_cpuidle_device); |
| 363 | cpu_pm_register_notifier(&mvebu_v7_cpu_pm_notifier); |
Gregory CLEMENT | 8c16bab | 2014-04-14 17:10:14 +0200 | [diff] [blame] | 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame] | 368 | arch_initcall(mvebu_v7_cpu_pm_init); |
| 369 | early_initcall(mvebu_v7_pmsu_init); |