blob: a1508deecd26b96d08c29a3998c0697ad972a1ef [file] [log] [blame]
Gregory CLEMENT7444dad2012-08-02 11:17:51 +03001/*
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 Petazzonibd045a12014-04-14 15:50:30 +020019#define pr_fmt(fmt) "mvebu-pmsu: " fmt
20
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030021#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 Petazzoni49754ff2014-04-14 15:50:29 +020026#include <linux/resource.h>
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030027#include <asm/smp_plat.h>
Thomas Petazzoni49754ff2014-04-14 15:50:29 +020028#include "common.h"
Jisheng Zhangb12634e2013-11-07 17:02:38 +080029#include "pmsu.h"
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030030
31static void __iomem *pmsu_mp_base;
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030032
Gregory CLEMENT0c3acc72014-04-14 15:50:31 +020033#define PMSU_BASE_OFFSET 0x100
34#define PMSU_REG_SIZE 0x1000
35
36#define PMSU_BOOT_ADDR_REDIRECT_OFFSET(cpu) ((cpu * 0x100) + 0x124)
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030037
38static struct of_device_id of_pmsu_table[] = {
Gregory CLEMENT0c3acc72014-04-14 15:50:31 +020039 { .compatible = "marvell,armada-370-pmsu", },
40 { .compatible = "marvell,armada-370-xp-pmsu", },
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030041 { /* end of list */ },
42};
43
Thomas Petazzoni05ad6902014-04-14 15:53:58 +020044void mvebu_pmsu_set_cpu_boot_addr(int hw_cpu, void *boot_addr)
Gregory CLEMENT02e7b062014-04-14 15:50:33 +020045{
46 writel(virt_to_phys(boot_addr), pmsu_mp_base +
47 PMSU_BOOT_ADDR_REDIRECT_OFFSET(hw_cpu));
48}
49
Jisheng Zhangb12634e2013-11-07 17:02:38 +080050static int __init armada_370_xp_pmsu_init(void)
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030051{
52 struct device_node *np;
Thomas Petazzonibd045a12014-04-14 15:50:30 +020053 struct resource res;
54 int ret = 0;
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030055
56 np = of_find_matching_node(NULL, of_pmsu_table);
Thomas Petazzonibd045a12014-04-14 15:50:30 +020057 if (!np)
58 return 0;
59
60 pr_info("Initializing Power Management Service Unit\n");
61
62 if (of_address_to_resource(np, 0, &res)) {
63 pr_err("unable to get resource\n");
64 ret = -ENOENT;
65 goto out;
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030066 }
67
Gregory CLEMENT0c3acc72014-04-14 15:50:31 +020068 if (of_device_is_compatible(np, "marvell,armada-370-xp-pmsu")) {
69 pr_warn(FW_WARN "deprecated pmsu binding\n");
70 res.start = res.start - PMSU_BASE_OFFSET;
71 res.end = res.start + PMSU_REG_SIZE - 1;
72 }
73
Thomas Petazzonibd045a12014-04-14 15:50:30 +020074 if (!request_mem_region(res.start, resource_size(&res),
75 np->full_name)) {
76 pr_err("unable to request region\n");
77 ret = -EBUSY;
78 goto out;
79 }
80
81 pmsu_mp_base = ioremap(res.start, resource_size(&res));
82 if (!pmsu_mp_base) {
83 pr_err("unable to map registers\n");
84 release_mem_region(res.start, resource_size(&res));
85 ret = -ENOMEM;
86 goto out;
87 }
88
89 out:
90 of_node_put(np);
91 return ret;
Gregory CLEMENT7444dad2012-08-02 11:17:51 +030092}
93
94early_initcall(armada_370_xp_pmsu_init);