2 * drivers/soc/tegra/flowctrl.c
4 * Functions and macros to control the flowcontroller
6 * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
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.
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
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/>.
21 #include <linux/cpumask.h>
22 #include <linux/init.h>
24 #include <linux/kernel.h>
26 #include <linux/of_address.h>
27 #include <linux/platform_device.h>
29 #include <soc/tegra/common.h>
30 #include <soc/tegra/flowctrl.h>
31 #include <soc/tegra/fuse.h>
33 static u8 flowctrl_offset_halt_cpu
[] = {
34 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,
40 static u8 flowctrl_offset_cpu_csr
[] = {
43 FLOW_CTRL_CPU1_CSR
+ 8,
44 FLOW_CTRL_CPU1_CSR
+ 16,
47 static void __iomem
*tegra_flowctrl_base
;
49 static void flowctrl_update(u8 offset
, u32 value
)
51 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base
),
52 "Tegra flowctrl not initialised!\n"))
55 writel(value
, tegra_flowctrl_base
+ offset
);
57 /* ensure the update has reached the flow controller */
59 readl_relaxed(tegra_flowctrl_base
+ offset
);
62 u32
flowctrl_read_cpu_csr(unsigned int cpuid
)
64 u8 offset
= flowctrl_offset_cpu_csr
[cpuid
];
66 if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base
),
67 "Tegra flowctrl not initialised!\n"))
70 return readl(tegra_flowctrl_base
+ offset
);
73 void flowctrl_write_cpu_csr(unsigned int cpuid
, u32 value
)
75 return flowctrl_update(flowctrl_offset_cpu_csr
[cpuid
], value
);
78 void flowctrl_write_cpu_halt(unsigned int cpuid
, u32 value
)
80 return flowctrl_update(flowctrl_offset_halt_cpu
[cpuid
], value
);
83 void flowctrl_cpu_suspend_enter(unsigned int cpuid
)
88 reg
= flowctrl_read_cpu_csr(cpuid
);
89 switch (tegra_get_chip_id()) {
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
;
101 /* 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
;
109 reg
|= FLOW_CTRL_CSR_INTR_FLAG
; /* clear intr flag */
110 reg
|= FLOW_CTRL_CSR_EVENT_FLAG
; /* clear event flag */
111 reg
|= FLOW_CTRL_CSR_ENABLE
; /* pwr gating */
112 flowctrl_write_cpu_csr(cpuid
, reg
);
114 for (i
= 0; i
< num_possible_cpus(); i
++) {
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
);
124 void flowctrl_cpu_suspend_exit(unsigned int cpuid
)
128 /* Disable powergating via flow controller for CPU0 */
129 reg
= flowctrl_read_cpu_csr(cpuid
);
130 switch (tegra_get_chip_id()) {
132 /* clear wfe bitmap */
133 reg
&= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP
;
134 /* clear wfi bitmap */
135 reg
&= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP
;
140 /* clear wfe bitmap */
141 reg
&= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP
;
142 /* clear wfi bitmap */
143 reg
&= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP
;
146 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
);
152 static int tegra_flowctrl_probe(struct platform_device
*pdev
)
154 void __iomem
*base
= tegra_flowctrl_base
;
155 struct resource
*res
;
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
))
160 return PTR_ERR(tegra_flowctrl_base
);
167 static const struct of_device_id tegra_flowctrl_match
[] = {
168 { .compatible
= "nvidia,tegra210-flowctrl" },
169 { .compatible
= "nvidia,tegra124-flowctrl" },
170 { .compatible
= "nvidia,tegra114-flowctrl" },
171 { .compatible
= "nvidia,tegra30-flowctrl" },
172 { .compatible
= "nvidia,tegra20-flowctrl" },
176 static struct platform_driver tegra_flowctrl_driver
= {
178 .name
= "tegra-flowctrl",
179 .suppress_bind_attrs
= true,
180 .of_match_table
= tegra_flowctrl_match
,
182 .probe
= tegra_flowctrl_probe
,
184 builtin_platform_driver(tegra_flowctrl_driver
);
186 static int __init
tegra_flowctrl_init(void)
189 struct device_node
*np
;
194 np
= of_find_matching_node(NULL
, tegra_flowctrl_match
);
196 if (of_address_to_resource(np
, 0, &res
) < 0) {
197 pr_err("failed to get flowctrl register\n");
201 } else if (IS_ENABLED(CONFIG_ARM
)) {
203 * Hardcoded fallback for 32-bit Tegra
204 * devices if device tree node is missing.
206 res
.start
= 0x60007000;
207 res
.end
= 0x60007fff;
208 res
.flags
= IORESOURCE_MEM
;
211 * At this point we're running on a Tegra,
212 * that doesn't support the flow controller
213 * (eg. Tegra186), so just return.
218 tegra_flowctrl_base
= ioremap_nocache(res
.start
, resource_size(&res
));
219 if (!tegra_flowctrl_base
)
224 early_initcall(tegra_flowctrl_init
);