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 | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/of_address.h> |
| 24 | #include <linux/io.h> |
| 25 | #include <linux/smp.h> |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 26 | #include <linux/resource.h> |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 27 | #include <asm/smp_plat.h> |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 28 | #include "common.h" |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 29 | #include "pmsu.h" |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 30 | |
| 31 | static void __iomem *pmsu_mp_base; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 32 | |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame^] | 33 | #define PMSU_BASE_OFFSET 0x100 |
| 34 | #define PMSU_REG_SIZE 0x1000 |
| 35 | |
| 36 | #define PMSU_BOOT_ADDR_REDIRECT_OFFSET(cpu) ((cpu * 0x100) + 0x124) |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 37 | |
| 38 | static struct of_device_id of_pmsu_table[] = { |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame^] | 39 | { .compatible = "marvell,armada-370-pmsu", }, |
| 40 | { .compatible = "marvell,armada-370-xp-pmsu", }, |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 41 | { /* end of list */ }, |
| 42 | }; |
| 43 | |
| 44 | #ifdef CONFIG_SMP |
| 45 | int armada_xp_boot_cpu(unsigned int cpu_id, void *boot_addr) |
| 46 | { |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 47 | int hw_cpu, ret; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 48 | |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 49 | if (!pmsu_mp_base) { |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 50 | pr_warn("Can't boot CPU. PMSU is uninitialized\n"); |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 51 | return -ENODEV; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | hw_cpu = cpu_logical_map(cpu_id); |
| 55 | |
| 56 | writel(virt_to_phys(boot_addr), pmsu_mp_base + |
| 57 | PMSU_BOOT_ADDR_REDIRECT_OFFSET(hw_cpu)); |
| 58 | |
Thomas Petazzoni | 49754ff | 2014-04-14 15:50:29 +0200 | [diff] [blame] | 59 | ret = mvebu_cpu_reset_deassert(hw_cpu); |
| 60 | if (ret) { |
| 61 | pr_warn("unable to boot CPU: %d\n", ret); |
| 62 | return ret; |
| 63 | } |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | #endif |
| 68 | |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 69 | static int __init armada_370_xp_pmsu_init(void) |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 70 | { |
| 71 | struct device_node *np; |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 72 | struct resource res; |
| 73 | int ret = 0; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 74 | |
| 75 | np = of_find_matching_node(NULL, of_pmsu_table); |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 76 | if (!np) |
| 77 | return 0; |
| 78 | |
| 79 | pr_info("Initializing Power Management Service Unit\n"); |
| 80 | |
| 81 | if (of_address_to_resource(np, 0, &res)) { |
| 82 | pr_err("unable to get resource\n"); |
| 83 | ret = -ENOENT; |
| 84 | goto out; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 85 | } |
| 86 | |
Gregory CLEMENT | 0c3acc7 | 2014-04-14 15:50:31 +0200 | [diff] [blame^] | 87 | if (of_device_is_compatible(np, "marvell,armada-370-xp-pmsu")) { |
| 88 | pr_warn(FW_WARN "deprecated pmsu binding\n"); |
| 89 | res.start = res.start - PMSU_BASE_OFFSET; |
| 90 | res.end = res.start + PMSU_REG_SIZE - 1; |
| 91 | } |
| 92 | |
Thomas Petazzoni | bd045a1 | 2014-04-14 15:50:30 +0200 | [diff] [blame] | 93 | if (!request_mem_region(res.start, resource_size(&res), |
| 94 | np->full_name)) { |
| 95 | pr_err("unable to request region\n"); |
| 96 | ret = -EBUSY; |
| 97 | goto out; |
| 98 | } |
| 99 | |
| 100 | pmsu_mp_base = ioremap(res.start, resource_size(&res)); |
| 101 | if (!pmsu_mp_base) { |
| 102 | pr_err("unable to map registers\n"); |
| 103 | release_mem_region(res.start, resource_size(&res)); |
| 104 | ret = -ENOMEM; |
| 105 | goto out; |
| 106 | } |
| 107 | |
| 108 | out: |
| 109 | of_node_put(np); |
| 110 | return ret; |
Gregory CLEMENT | 7444dad | 2012-08-02 11:17:51 +0300 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | early_initcall(armada_370_xp_pmsu_init); |