Merge branch 'mvebu/soc-pmsu' into mvebu/soc
[deliverable/linux.git] / arch / arm / mach-mvebu / pmsu.c
CommitLineData
7444dad2
GC
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
bd045a1e
TP
19#define pr_fmt(fmt) "mvebu-pmsu: " fmt
20
7444dad2
GC
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>
49754ffe 26#include <linux/resource.h>
7444dad2 27#include <asm/smp_plat.h>
49754ffe 28#include "common.h"
b12634e3 29#include "pmsu.h"
7444dad2
GC
30
31static void __iomem *pmsu_mp_base;
7444dad2 32
0c3acc74
GC
33#define PMSU_BASE_OFFSET 0x100
34#define PMSU_REG_SIZE 0x1000
35
36#define PMSU_BOOT_ADDR_REDIRECT_OFFSET(cpu) ((cpu * 0x100) + 0x124)
7444dad2
GC
37
38static struct of_device_id of_pmsu_table[] = {
0c3acc74
GC
39 { .compatible = "marvell,armada-370-pmsu", },
40 { .compatible = "marvell,armada-370-xp-pmsu", },
7444dad2
GC
41 { /* end of list */ },
42};
43
02e7b067
GC
44static void mvebu_pmsu_set_cpu_boot_addr(int hw_cpu, void *boot_addr)
45{
46 writel(virt_to_phys(boot_addr), pmsu_mp_base +
47 PMSU_BOOT_ADDR_REDIRECT_OFFSET(hw_cpu));
48}
49
7444dad2
GC
50#ifdef CONFIG_SMP
51int armada_xp_boot_cpu(unsigned int cpu_id, void *boot_addr)
52{
49754ffe 53 int hw_cpu, ret;
7444dad2 54
49754ffe 55 if (!pmsu_mp_base) {
7444dad2 56 pr_warn("Can't boot CPU. PMSU is uninitialized\n");
49754ffe 57 return -ENODEV;
7444dad2
GC
58 }
59
60 hw_cpu = cpu_logical_map(cpu_id);
61
02e7b067 62 mvebu_pmsu_set_cpu_boot_addr(hw_cpu, boot_addr);
7444dad2 63
49754ffe
TP
64 ret = mvebu_cpu_reset_deassert(hw_cpu);
65 if (ret) {
66 pr_warn("unable to boot CPU: %d\n", ret);
67 return ret;
68 }
7444dad2
GC
69
70 return 0;
71}
72#endif
73
b12634e3 74static int __init armada_370_xp_pmsu_init(void)
7444dad2
GC
75{
76 struct device_node *np;
bd045a1e
TP
77 struct resource res;
78 int ret = 0;
7444dad2
GC
79
80 np = of_find_matching_node(NULL, of_pmsu_table);
bd045a1e
TP
81 if (!np)
82 return 0;
83
84 pr_info("Initializing Power Management Service Unit\n");
85
86 if (of_address_to_resource(np, 0, &res)) {
87 pr_err("unable to get resource\n");
88 ret = -ENOENT;
89 goto out;
7444dad2
GC
90 }
91
0c3acc74
GC
92 if (of_device_is_compatible(np, "marvell,armada-370-xp-pmsu")) {
93 pr_warn(FW_WARN "deprecated pmsu binding\n");
94 res.start = res.start - PMSU_BASE_OFFSET;
95 res.end = res.start + PMSU_REG_SIZE - 1;
96 }
97
bd045a1e
TP
98 if (!request_mem_region(res.start, resource_size(&res),
99 np->full_name)) {
100 pr_err("unable to request region\n");
101 ret = -EBUSY;
102 goto out;
103 }
104
105 pmsu_mp_base = ioremap(res.start, resource_size(&res));
106 if (!pmsu_mp_base) {
107 pr_err("unable to map registers\n");
108 release_mem_region(res.start, resource_size(&res));
109 ret = -ENOMEM;
110 goto out;
111 }
112
113 out:
114 of_node_put(np);
115 return ret;
7444dad2
GC
116}
117
118early_initcall(armada_370_xp_pmsu_init);
This page took 0.122211 seconds and 5 git commands to generate.