blob: e57b7c3039a28920e2c16ffe667ac483cbb2e2b5 [file] [log] [blame]
Tomasz Figabca28f82012-12-11 13:58:43 +09001/*
2 * Copyright (C) 2012 Samsung Electronics.
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Tomasz Figa <t.figa@samsung.com>
5 *
6 * This program is free software,you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/io.h>
13#include <linux/init.h>
14#include <linux/of.h>
15#include <linux/of_address.h>
16
Tomasz Figa2b9d9c32014-09-24 01:24:39 +090017#include <asm/cacheflush.h>
18#include <asm/cputype.h>
Tomasz Figabca28f82012-12-11 13:58:43 +090019#include <asm/firmware.h>
Tomasz Figa2b9d9c32014-09-24 01:24:39 +090020#include <asm/suspend.h>
Tomasz Figabca28f82012-12-11 13:58:43 +090021
22#include <mach/map.h>
23
Sachin Kamatb3205de2014-05-13 07:13:44 +090024#include "common.h"
Tomasz Figabca28f82012-12-11 13:58:43 +090025#include "smc.h"
26
Tomasz Figa2b9d9c32014-09-24 01:24:39 +090027#define EXYNOS_SLEEP_MAGIC 0x00000bad
28#define EXYNOS_BOOT_ADDR 0x8
29#define EXYNOS_BOOT_FLAG 0xc
30
Bartlomiej Zolnierkiewicz0b7778a2014-09-25 17:59:41 +090031static int exynos_do_idle(unsigned long mode)
Tomasz Figabca28f82012-12-11 13:58:43 +090032{
Bartlomiej Zolnierkiewicz0b7778a2014-09-25 17:59:41 +090033 switch (mode) {
34 case FW_DO_IDLE_AFTR:
35 exynos_smc(SMC_CMD_CPU0AFTR, 0, 0, 0);
36 break;
37 case FW_DO_IDLE_SLEEP:
38 exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
39 }
Tomasz Figabca28f82012-12-11 13:58:43 +090040 return 0;
41}
42
43static int exynos_cpu_boot(int cpu)
44{
Kyungmin Park989ff3f2014-05-09 06:19:18 +090045 /*
Chanwoo Choi64571582014-05-26 04:12:32 +090046 * Exynos3250 doesn't need to send smc command for secondary CPU boot
47 * because Exynos3250 removes WFE in secure mode.
48 */
49 if (soc_is_exynos3250())
50 return 0;
51
52 /*
Kyungmin Park989ff3f2014-05-09 06:19:18 +090053 * The second parameter of SMC_CMD_CPU1BOOT command means CPU id.
54 * But, Exynos4212 has only one secondary CPU so second parameter
55 * isn't used for informing secure firmware about CPU id.
56 */
57 if (soc_is_exynos4212())
58 cpu = 0;
59
Tomasz Figabca28f82012-12-11 13:58:43 +090060 exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
61 return 0;
62}
63
64static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
65{
Sachin Kamatb3205de2014-05-13 07:13:44 +090066 void __iomem *boot_reg;
67
68 if (!sysram_ns_base_addr)
69 return -ENODEV;
70
Olof Johanssonfe388fa2014-05-30 21:44:32 -070071 boot_reg = sysram_ns_base_addr + 0x1c;
Kyungmin Park989ff3f2014-05-09 06:19:18 +090072
Sachin Kamat35e75642014-07-08 08:03:49 +090073 /*
74 * Almost all Exynos-series of SoCs that run in secure mode don't need
75 * additional offset for every CPU, with Exynos4412 being the only
76 * exception.
77 */
78 if (soc_is_exynos4412())
79 boot_reg += 4 * cpu;
Tomasz Figabca28f82012-12-11 13:58:43 +090080
81 __raw_writel(boot_addr, boot_reg);
82 return 0;
83}
84
Tomasz Figa2b9d9c32014-09-24 01:24:39 +090085static int exynos_cpu_suspend(unsigned long arg)
86{
87 flush_cache_all();
88 outer_flush_all();
89
90 exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
91
92 pr_info("Failed to suspend the system\n");
93 writel(0, sysram_ns_base_addr + EXYNOS_BOOT_FLAG);
94 return 1;
95}
96
97static int exynos_suspend(void)
98{
99 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
100 /* Save Power control and Diagnostic registers */
101 asm ("mrc p15, 0, %0, c15, c0, 0\n"
102 "mrc p15, 0, %1, c15, c0, 1\n"
103 : "=r" (cp15_save_power), "=r" (cp15_save_diag)
104 : : "cc");
105 }
106
107 writel(EXYNOS_SLEEP_MAGIC, sysram_ns_base_addr + EXYNOS_BOOT_FLAG);
108 writel(virt_to_phys(exynos_cpu_resume_ns),
109 sysram_ns_base_addr + EXYNOS_BOOT_ADDR);
110
111 return cpu_suspend(0, exynos_cpu_suspend);
112}
113
114static int exynos_resume(void)
115{
116 writel(0, sysram_ns_base_addr + EXYNOS_BOOT_FLAG);
117
118 return 0;
119}
120
Tomasz Figabca28f82012-12-11 13:58:43 +0900121static const struct firmware_ops exynos_firmware_ops = {
122 .do_idle = exynos_do_idle,
123 .set_cpu_boot_addr = exynos_set_cpu_boot_addr,
124 .cpu_boot = exynos_cpu_boot,
Tomasz Figa2b9d9c32014-09-24 01:24:39 +0900125 .suspend = exynos_suspend,
126 .resume = exynos_resume,
Tomasz Figabca28f82012-12-11 13:58:43 +0900127};
128
129void __init exynos_firmware_init(void)
130{
Tomasz Figa4ee1cc72013-06-15 09:13:25 +0900131 struct device_node *nd;
132 const __be32 *addr;
Tomasz Figabca28f82012-12-11 13:58:43 +0900133
Tomasz Figa4ee1cc72013-06-15 09:13:25 +0900134 nd = of_find_compatible_node(NULL, NULL,
135 "samsung,secure-firmware");
136 if (!nd)
137 return;
Tomasz Figabca28f82012-12-11 13:58:43 +0900138
Tomasz Figa4ee1cc72013-06-15 09:13:25 +0900139 addr = of_get_address(nd, 0, NULL, NULL);
140 if (!addr) {
141 pr_err("%s: No address specified.\n", __func__);
142 return;
Tomasz Figabca28f82012-12-11 13:58:43 +0900143 }
144
145 pr_info("Running under secure firmware.\n");
146
147 register_firmware_ops(&exynos_firmware_ops);
148}