blob: 5433cc7a043e147f8e6a0165e09ef4f9ae86ac54 [file] [log] [blame]
Peter De Schrijver26fe6812012-02-10 01:47:44 +02001/*
Jon Hunter7e10cf72017-03-28 13:42:54 +01002 * drivers/soc/tegra/flowctrl.c
Peter De Schrijver26fe6812012-02-10 01:47:44 +02003 *
Jon Hunter7e10cf72017-03-28 13:42:54 +01004 * Functions and macros to control the flowcontroller
Peter De Schrijver26fe6812012-02-10 01:47:44 +02005 *
6 * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
Joseph Lo01459c62012-10-31 17:41:20 +080021#include <linux/cpumask.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020022#include <linux/init.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
Thierry Reding783944f2014-08-26 08:14:04 +020025#include <linux/of.h>
26#include <linux/of_address.h>
Jon Hunter841fd942017-03-28 13:42:55 +010027#include <linux/platform_device.h>
Peter De Schrijver26fe6812012-02-10 01:47:44 +020028
Jon Hunter7e10cf72017-03-28 13:42:54 +010029#include <soc/tegra/common.h>
30#include <soc/tegra/flowctrl.h>
Thierry Reding304664e2014-07-11 09:52:41 +020031#include <soc/tegra/fuse.h>
32
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020033static u8 flowctrl_offset_halt_cpu[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020034 FLOW_CTRL_HALT_CPU0_EVENTS,
35 FLOW_CTRL_HALT_CPU1_EVENTS,
36 FLOW_CTRL_HALT_CPU1_EVENTS + 8,
37 FLOW_CTRL_HALT_CPU1_EVENTS + 16,
38};
39
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020040static u8 flowctrl_offset_cpu_csr[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020041 FLOW_CTRL_CPU0_CSR,
42 FLOW_CTRL_CPU1_CSR,
43 FLOW_CTRL_CPU1_CSR + 8,
44 FLOW_CTRL_CPU1_CSR + 16,
45};
46
Thierry Reding783944f2014-08-26 08:14:04 +020047static void __iomem *tegra_flowctrl_base;
48
Peter De Schrijver26fe6812012-02-10 01:47:44 +020049static void flowctrl_update(u8 offset, u32 value)
50{
Jon Hunter841fd942017-03-28 13:42:55 +010051 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
Jon Hunter7e10cf72017-03-28 13:42:54 +010052 "Tegra flowctrl not initialised!\n"))
53 return;
54
Thierry Reding783944f2014-08-26 08:14:04 +020055 writel(value, tegra_flowctrl_base + offset);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020056
57 /* ensure the update has reached the flow controller */
58 wmb();
Thierry Reding783944f2014-08-26 08:14:04 +020059 readl_relaxed(tegra_flowctrl_base + offset);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020060}
61
Joseph Lo01459c62012-10-31 17:41:20 +080062u32 flowctrl_read_cpu_csr(unsigned int cpuid)
63{
64 u8 offset = flowctrl_offset_cpu_csr[cpuid];
Joseph Lo01459c62012-10-31 17:41:20 +080065
Jon Hunter841fd942017-03-28 13:42:55 +010066 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
Jon Hunter7e10cf72017-03-28 13:42:54 +010067 "Tegra flowctrl not initialised!\n"))
68 return 0;
69
Thierry Reding783944f2014-08-26 08:14:04 +020070 return readl(tegra_flowctrl_base + offset);
Joseph Lo01459c62012-10-31 17:41:20 +080071}
72
Peter De Schrijver26fe6812012-02-10 01:47:44 +020073void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
74{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030075 return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020076}
77
78void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
79{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030080 return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020081}
Joseph Lo01459c62012-10-31 17:41:20 +080082
83void flowctrl_cpu_suspend_enter(unsigned int cpuid)
84{
85 unsigned int reg;
86 int i;
87
88 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +020089 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +000090 case TEGRA20:
91 /* clear wfe bitmap */
92 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
93 /* clear wfi bitmap */
94 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
95 /* pwr gating on wfe */
96 reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
97 break;
98 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +080099 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +0800100 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +0000101 /* clear wfe bitmap */
102 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
103 /* clear wfi bitmap */
104 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
105 /* pwr gating on wfi */
106 reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
107 break;
108 }
Joseph Lo01459c62012-10-31 17:41:20 +0800109 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
110 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
Joseph Lo01459c62012-10-31 17:41:20 +0800111 reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
112 flowctrl_write_cpu_csr(cpuid, reg);
113
114 for (i = 0; i < num_possible_cpus(); i++) {
115 if (i == cpuid)
116 continue;
117 reg = flowctrl_read_cpu_csr(i);
118 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
119 reg |= FLOW_CTRL_CSR_INTR_FLAG;
120 flowctrl_write_cpu_csr(i, reg);
121 }
122}
123
124void flowctrl_cpu_suspend_exit(unsigned int cpuid)
125{
126 unsigned int reg;
127
128 /* Disable powergating via flow controller for CPU0 */
129 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +0200130 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +0000131 case TEGRA20:
132 /* clear wfe bitmap */
133 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
134 /* clear wfi bitmap */
135 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
136 break;
137 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +0800138 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +0800139 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +0000140 /* clear wfe bitmap */
141 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
142 /* clear wfi bitmap */
143 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
144 break;
145 }
Joseph Lo01459c62012-10-31 17:41:20 +0800146 reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
147 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
148 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
149 flowctrl_write_cpu_csr(cpuid, reg);
150}
Thierry Reding783944f2014-08-26 08:14:04 +0200151
Jon Hunter841fd942017-03-28 13:42:55 +0100152static int tegra_flowctrl_probe(struct platform_device *pdev)
153{
154 void __iomem *base = tegra_flowctrl_base;
155 struct resource *res;
156
157 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
158 tegra_flowctrl_base = devm_ioremap_resource(&pdev->dev, res);
159 if (IS_ERR(tegra_flowctrl_base))
Christophe Jailletda1dbec2017-04-11 05:40:41 +0200160 return PTR_ERR(tegra_flowctrl_base);
Jon Hunter841fd942017-03-28 13:42:55 +0100161
162 iounmap(base);
163
164 return 0;
165}
166
167static const struct of_device_id tegra_flowctrl_match[] = {
Jon Hunter1fd09e52017-03-28 13:42:58 +0100168 { .compatible = "nvidia,tegra210-flowctrl" },
Thierry Reding783944f2014-08-26 08:14:04 +0200169 { .compatible = "nvidia,tegra124-flowctrl" },
170 { .compatible = "nvidia,tegra114-flowctrl" },
171 { .compatible = "nvidia,tegra30-flowctrl" },
172 { .compatible = "nvidia,tegra20-flowctrl" },
173 { }
174};
175
Jon Hunter841fd942017-03-28 13:42:55 +0100176static struct platform_driver tegra_flowctrl_driver = {
177 .driver = {
178 .name = "tegra-flowctrl",
179 .suppress_bind_attrs = true,
180 .of_match_table = tegra_flowctrl_match,
181 },
182 .probe = tegra_flowctrl_probe,
183};
184builtin_platform_driver(tegra_flowctrl_driver);
185
Jon Hunter7e10cf72017-03-28 13:42:54 +0100186static int __init tegra_flowctrl_init(void)
Thierry Reding783944f2014-08-26 08:14:04 +0200187{
Jon Hunter1fd09e52017-03-28 13:42:58 +0100188 struct resource res;
Thierry Reding783944f2014-08-26 08:14:04 +0200189 struct device_node *np;
190
Jon Hunter7e10cf72017-03-28 13:42:54 +0100191 if (!soc_is_tegra())
192 return 0;
193
Jon Hunter841fd942017-03-28 13:42:55 +0100194 np = of_find_matching_node(NULL, tegra_flowctrl_match);
Thierry Reding783944f2014-08-26 08:14:04 +0200195 if (np) {
Jon Hunter1fd09e52017-03-28 13:42:58 +0100196 if (of_address_to_resource(np, 0, &res) < 0) {
197 pr_err("failed to get flowctrl register\n");
198 return -ENXIO;
Thierry Reding783944f2014-08-26 08:14:04 +0200199 }
Thierry Reding783944f2014-08-26 08:14:04 +0200200 of_node_put(np);
Jon Hunter1fd09e52017-03-28 13:42:58 +0100201 } else if (IS_ENABLED(CONFIG_ARM)) {
202 /*
203 * Hardcoded fallback for 32-bit Tegra
204 * devices if device tree node is missing.
205 */
206 res.start = 0x60007000;
207 res.end = 0x60007fff;
208 res.flags = IORESOURCE_MEM;
209 } else {
210 /*
211 * At this point we're running on a Tegra,
212 * that doesn't support the flow controller
213 * (eg. Tegra186), so just return.
214 */
215 return 0;
Thierry Reding783944f2014-08-26 08:14:04 +0200216 }
217
Jon Hunter1fd09e52017-03-28 13:42:58 +0100218 tegra_flowctrl_base = ioremap_nocache(res.start, resource_size(&res));
Jon Hunter7e10cf72017-03-28 13:42:54 +0100219 if (!tegra_flowctrl_base)
220 return -ENXIO;
221
222 return 0;
Thierry Reding783944f2014-08-26 08:14:04 +0200223}
Jon Hunter7e10cf72017-03-28 13:42:54 +0100224early_initcall(tegra_flowctrl_init);