blob: b6bdeef33db19dea08197e283c4eb80ad3e57345 [file] [log] [blame]
Thomas Gleixner46fe7772019-05-31 01:09:57 -07001// SPDX-License-Identifier: GPL-2.0-only
Peter De Schrijver26fe6812012-02-10 01:47:44 +02002/*
Jon Hunter7e10cf72017-03-28 13:42:54 +01003 * drivers/soc/tegra/flowctrl.c
Peter De Schrijver26fe6812012-02-10 01:47:44 +02004 *
Jon Hunter7e10cf72017-03-28 13:42:54 +01005 * Functions and macros to control the flowcontroller
Peter De Schrijver26fe6812012-02-10 01:47:44 +02006 *
7 * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
Peter De Schrijver26fe6812012-02-10 01:47:44 +02008 */
9
Joseph Lo01459c62012-10-31 17:41:20 +080010#include <linux/cpumask.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020011#include <linux/init.h>
12#include <linux/io.h>
13#include <linux/kernel.h>
Thierry Reding783944f2014-08-26 08:14:04 +020014#include <linux/of.h>
15#include <linux/of_address.h>
Jon Hunter841fd942017-03-28 13:42:55 +010016#include <linux/platform_device.h>
Peter De Schrijver26fe6812012-02-10 01:47:44 +020017
Jon Hunter7e10cf72017-03-28 13:42:54 +010018#include <soc/tegra/common.h>
19#include <soc/tegra/flowctrl.h>
Thierry Reding304664e2014-07-11 09:52:41 +020020#include <soc/tegra/fuse.h>
21
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020022static u8 flowctrl_offset_halt_cpu[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020023 FLOW_CTRL_HALT_CPU0_EVENTS,
24 FLOW_CTRL_HALT_CPU1_EVENTS,
25 FLOW_CTRL_HALT_CPU1_EVENTS + 8,
26 FLOW_CTRL_HALT_CPU1_EVENTS + 16,
27};
28
Hiroshi Doyudeeb8d12013-01-03 08:27:05 +020029static u8 flowctrl_offset_cpu_csr[] = {
Peter De Schrijver26fe6812012-02-10 01:47:44 +020030 FLOW_CTRL_CPU0_CSR,
31 FLOW_CTRL_CPU1_CSR,
32 FLOW_CTRL_CPU1_CSR + 8,
33 FLOW_CTRL_CPU1_CSR + 16,
34};
35
Thierry Reding783944f2014-08-26 08:14:04 +020036static void __iomem *tegra_flowctrl_base;
37
Peter De Schrijver26fe6812012-02-10 01:47:44 +020038static void flowctrl_update(u8 offset, u32 value)
39{
Jon Hunter841fd942017-03-28 13:42:55 +010040 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
Jon Hunter7e10cf72017-03-28 13:42:54 +010041 "Tegra flowctrl not initialised!\n"))
42 return;
43
Thierry Reding783944f2014-08-26 08:14:04 +020044 writel(value, tegra_flowctrl_base + offset);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020045
46 /* ensure the update has reached the flow controller */
47 wmb();
Thierry Reding783944f2014-08-26 08:14:04 +020048 readl_relaxed(tegra_flowctrl_base + offset);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020049}
50
Joseph Lo01459c62012-10-31 17:41:20 +080051u32 flowctrl_read_cpu_csr(unsigned int cpuid)
52{
53 u8 offset = flowctrl_offset_cpu_csr[cpuid];
Joseph Lo01459c62012-10-31 17:41:20 +080054
Jon Hunter841fd942017-03-28 13:42:55 +010055 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
Jon Hunter7e10cf72017-03-28 13:42:54 +010056 "Tegra flowctrl not initialised!\n"))
57 return 0;
58
Thierry Reding783944f2014-08-26 08:14:04 +020059 return readl(tegra_flowctrl_base + offset);
Joseph Lo01459c62012-10-31 17:41:20 +080060}
61
Peter De Schrijver26fe6812012-02-10 01:47:44 +020062void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
63{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030064 return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020065}
66
67void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
68{
Peter De Schrijver97e7abc2012-05-14 13:27:09 +030069 return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
Peter De Schrijver26fe6812012-02-10 01:47:44 +020070}
Joseph Lo01459c62012-10-31 17:41:20 +080071
72void flowctrl_cpu_suspend_enter(unsigned int cpuid)
73{
74 unsigned int reg;
75 int i;
76
77 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +020078 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +000079 case TEGRA20:
80 /* clear wfe bitmap */
81 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
82 /* clear wfi bitmap */
83 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
84 /* pwr gating on wfe */
85 reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
86 break;
87 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +080088 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +080089 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +000090 /* clear wfe bitmap */
91 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
92 /* clear wfi bitmap */
93 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
94 /* pwr gating on wfi */
95 reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
96 break;
97 }
Joseph Lo01459c62012-10-31 17:41:20 +080098 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
99 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
Joseph Lo01459c62012-10-31 17:41:20 +0800100 reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
101 flowctrl_write_cpu_csr(cpuid, reg);
102
103 for (i = 0; i < num_possible_cpus(); i++) {
104 if (i == cpuid)
105 continue;
106 reg = flowctrl_read_cpu_csr(i);
107 reg |= FLOW_CTRL_CSR_EVENT_FLAG;
108 reg |= FLOW_CTRL_CSR_INTR_FLAG;
109 flowctrl_write_cpu_csr(i, reg);
110 }
111}
112
113void flowctrl_cpu_suspend_exit(unsigned int cpuid)
114{
115 unsigned int reg;
116
117 /* Disable powergating via flow controller for CPU0 */
118 reg = flowctrl_read_cpu_csr(cpuid);
Thierry Reding304664e2014-07-11 09:52:41 +0200119 switch (tegra_get_chip_id()) {
Joseph Loafec5812013-01-15 22:11:01 +0000120 case TEGRA20:
121 /* clear wfe bitmap */
122 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
123 /* clear wfi bitmap */
124 reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
125 break;
126 case TEGRA30:
Joseph Lodd6fe9a2013-07-03 17:50:43 +0800127 case TEGRA114:
Joseph Lof0c4ac12013-10-11 17:58:38 +0800128 case TEGRA124:
Joseph Loafec5812013-01-15 22:11:01 +0000129 /* clear wfe bitmap */
130 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
131 /* clear wfi bitmap */
132 reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
133 break;
134 }
Joseph Lo01459c62012-10-31 17:41:20 +0800135 reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
136 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
137 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
138 flowctrl_write_cpu_csr(cpuid, reg);
139}
Thierry Reding783944f2014-08-26 08:14:04 +0200140
Jon Hunter841fd942017-03-28 13:42:55 +0100141static int tegra_flowctrl_probe(struct platform_device *pdev)
142{
143 void __iomem *base = tegra_flowctrl_base;
144 struct resource *res;
145
146 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
147 tegra_flowctrl_base = devm_ioremap_resource(&pdev->dev, res);
148 if (IS_ERR(tegra_flowctrl_base))
Christophe Jailletda1dbec2017-04-11 05:40:41 +0200149 return PTR_ERR(tegra_flowctrl_base);
Jon Hunter841fd942017-03-28 13:42:55 +0100150
151 iounmap(base);
152
153 return 0;
154}
155
156static const struct of_device_id tegra_flowctrl_match[] = {
Jon Hunter1fd09e52017-03-28 13:42:58 +0100157 { .compatible = "nvidia,tegra210-flowctrl" },
Thierry Reding783944f2014-08-26 08:14:04 +0200158 { .compatible = "nvidia,tegra124-flowctrl" },
159 { .compatible = "nvidia,tegra114-flowctrl" },
160 { .compatible = "nvidia,tegra30-flowctrl" },
161 { .compatible = "nvidia,tegra20-flowctrl" },
162 { }
163};
164
Jon Hunter841fd942017-03-28 13:42:55 +0100165static struct platform_driver tegra_flowctrl_driver = {
166 .driver = {
167 .name = "tegra-flowctrl",
168 .suppress_bind_attrs = true,
169 .of_match_table = tegra_flowctrl_match,
170 },
171 .probe = tegra_flowctrl_probe,
172};
173builtin_platform_driver(tegra_flowctrl_driver);
174
Jon Hunter7e10cf72017-03-28 13:42:54 +0100175static int __init tegra_flowctrl_init(void)
Thierry Reding783944f2014-08-26 08:14:04 +0200176{
Jon Hunter1fd09e52017-03-28 13:42:58 +0100177 struct resource res;
Thierry Reding783944f2014-08-26 08:14:04 +0200178 struct device_node *np;
179
Jon Hunter7e10cf72017-03-28 13:42:54 +0100180 if (!soc_is_tegra())
181 return 0;
182
Jon Hunter841fd942017-03-28 13:42:55 +0100183 np = of_find_matching_node(NULL, tegra_flowctrl_match);
Thierry Reding783944f2014-08-26 08:14:04 +0200184 if (np) {
Jon Hunter1fd09e52017-03-28 13:42:58 +0100185 if (of_address_to_resource(np, 0, &res) < 0) {
186 pr_err("failed to get flowctrl register\n");
187 return -ENXIO;
Thierry Reding783944f2014-08-26 08:14:04 +0200188 }
Thierry Reding783944f2014-08-26 08:14:04 +0200189 of_node_put(np);
Jon Hunter1fd09e52017-03-28 13:42:58 +0100190 } else if (IS_ENABLED(CONFIG_ARM)) {
191 /*
192 * Hardcoded fallback for 32-bit Tegra
193 * devices if device tree node is missing.
194 */
195 res.start = 0x60007000;
196 res.end = 0x60007fff;
197 res.flags = IORESOURCE_MEM;
198 } else {
199 /*
200 * At this point we're running on a Tegra,
201 * that doesn't support the flow controller
202 * (eg. Tegra186), so just return.
203 */
204 return 0;
Thierry Reding783944f2014-08-26 08:14:04 +0200205 }
206
Jon Hunter1fd09e52017-03-28 13:42:58 +0100207 tegra_flowctrl_base = ioremap_nocache(res.start, resource_size(&res));
Jon Hunter7e10cf72017-03-28 13:42:54 +0100208 if (!tegra_flowctrl_base)
209 return -ENXIO;
210
211 return 0;
Thierry Reding783944f2014-08-26 08:14:04 +0200212}
Jon Hunter7e10cf72017-03-28 13:42:54 +0100213early_initcall(tegra_flowctrl_init);