Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 1 | /* |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 2 | * drivers/soc/tegra/flowctrl.c |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 3 | * |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 4 | * Functions and macros to control the flowcontroller |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 5 | * |
| 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 Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 21 | #include <linux/cpumask.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/kernel.h> |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_address.h> |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 27 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 28 | #include <soc/tegra/common.h> |
| 29 | #include <soc/tegra/flowctrl.h> |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 30 | #include <soc/tegra/fuse.h> |
| 31 | |
Hiroshi Doyu | deeb8d1 | 2013-01-03 08:27:05 +0200 | [diff] [blame] | 32 | static u8 flowctrl_offset_halt_cpu[] = { |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 33 | FLOW_CTRL_HALT_CPU0_EVENTS, |
| 34 | FLOW_CTRL_HALT_CPU1_EVENTS, |
| 35 | FLOW_CTRL_HALT_CPU1_EVENTS + 8, |
| 36 | FLOW_CTRL_HALT_CPU1_EVENTS + 16, |
| 37 | }; |
| 38 | |
Hiroshi Doyu | deeb8d1 | 2013-01-03 08:27:05 +0200 | [diff] [blame] | 39 | static u8 flowctrl_offset_cpu_csr[] = { |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 40 | FLOW_CTRL_CPU0_CSR, |
| 41 | FLOW_CTRL_CPU1_CSR, |
| 42 | FLOW_CTRL_CPU1_CSR + 8, |
| 43 | FLOW_CTRL_CPU1_CSR + 16, |
| 44 | }; |
| 45 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 46 | static void __iomem *tegra_flowctrl_base; |
| 47 | |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 48 | static void flowctrl_update(u8 offset, u32 value) |
| 49 | { |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 50 | if (WARN_ONCE(!tegra_flowctrl_base, |
| 51 | "Tegra flowctrl not initialised!\n")) |
| 52 | return; |
| 53 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 54 | writel(value, tegra_flowctrl_base + offset); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 55 | |
| 56 | /* ensure the update has reached the flow controller */ |
| 57 | wmb(); |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 58 | readl_relaxed(tegra_flowctrl_base + offset); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 61 | u32 flowctrl_read_cpu_csr(unsigned int cpuid) |
| 62 | { |
| 63 | u8 offset = flowctrl_offset_cpu_csr[cpuid]; |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 64 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 65 | if (WARN_ONCE(!tegra_flowctrl_base, |
| 66 | "Tegra flowctrl not initialised!\n")) |
| 67 | return 0; |
| 68 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 69 | return readl(tegra_flowctrl_base + offset); |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 70 | } |
| 71 | |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 72 | void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value) |
| 73 | { |
Peter De Schrijver | 97e7abc | 2012-05-14 13:27:09 +0300 | [diff] [blame] | 74 | return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value) |
| 78 | { |
Peter De Schrijver | 97e7abc | 2012-05-14 13:27:09 +0300 | [diff] [blame] | 79 | return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 80 | } |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 81 | |
| 82 | void flowctrl_cpu_suspend_enter(unsigned int cpuid) |
| 83 | { |
| 84 | unsigned int reg; |
| 85 | int i; |
| 86 | |
| 87 | reg = flowctrl_read_cpu_csr(cpuid); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 88 | switch (tegra_get_chip_id()) { |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 89 | case TEGRA20: |
| 90 | /* clear wfe bitmap */ |
| 91 | reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP; |
| 92 | /* clear wfi bitmap */ |
| 93 | reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP; |
| 94 | /* pwr gating on wfe */ |
| 95 | reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid; |
| 96 | break; |
| 97 | case TEGRA30: |
Joseph Lo | dd6fe9a | 2013-07-03 17:50:43 +0800 | [diff] [blame] | 98 | case TEGRA114: |
Joseph Lo | f0c4ac1 | 2013-10-11 17:58:38 +0800 | [diff] [blame] | 99 | case TEGRA124: |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 100 | /* clear wfe bitmap */ |
| 101 | reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; |
| 102 | /* clear wfi bitmap */ |
| 103 | reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; |
| 104 | /* pwr gating on wfi */ |
| 105 | reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid; |
| 106 | break; |
| 107 | } |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 108 | reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */ |
| 109 | reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */ |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 110 | reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */ |
| 111 | flowctrl_write_cpu_csr(cpuid, reg); |
| 112 | |
| 113 | for (i = 0; i < num_possible_cpus(); i++) { |
| 114 | if (i == cpuid) |
| 115 | continue; |
| 116 | reg = flowctrl_read_cpu_csr(i); |
| 117 | reg |= FLOW_CTRL_CSR_EVENT_FLAG; |
| 118 | reg |= FLOW_CTRL_CSR_INTR_FLAG; |
| 119 | flowctrl_write_cpu_csr(i, reg); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void flowctrl_cpu_suspend_exit(unsigned int cpuid) |
| 124 | { |
| 125 | unsigned int reg; |
| 126 | |
| 127 | /* Disable powergating via flow controller for CPU0 */ |
| 128 | reg = flowctrl_read_cpu_csr(cpuid); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 129 | switch (tegra_get_chip_id()) { |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 130 | case TEGRA20: |
| 131 | /* clear wfe bitmap */ |
| 132 | reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP; |
| 133 | /* clear wfi bitmap */ |
| 134 | reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP; |
| 135 | break; |
| 136 | case TEGRA30: |
Joseph Lo | dd6fe9a | 2013-07-03 17:50:43 +0800 | [diff] [blame] | 137 | case TEGRA114: |
Joseph Lo | f0c4ac1 | 2013-10-11 17:58:38 +0800 | [diff] [blame] | 138 | case TEGRA124: |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 139 | /* clear wfe bitmap */ |
| 140 | reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; |
| 141 | /* clear wfi bitmap */ |
| 142 | reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; |
| 143 | break; |
| 144 | } |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 145 | reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */ |
| 146 | reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */ |
| 147 | reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */ |
| 148 | flowctrl_write_cpu_csr(cpuid, reg); |
| 149 | } |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 150 | |
| 151 | static const struct of_device_id matches[] __initconst = { |
| 152 | { .compatible = "nvidia,tegra124-flowctrl" }, |
| 153 | { .compatible = "nvidia,tegra114-flowctrl" }, |
| 154 | { .compatible = "nvidia,tegra30-flowctrl" }, |
| 155 | { .compatible = "nvidia,tegra20-flowctrl" }, |
| 156 | { } |
| 157 | }; |
| 158 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 159 | static int __init tegra_flowctrl_init(void) |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 160 | { |
| 161 | /* hardcoded fallback if device tree node is missing */ |
| 162 | unsigned long base = 0x60007000; |
| 163 | unsigned long size = SZ_4K; |
| 164 | struct device_node *np; |
| 165 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 166 | if (!soc_is_tegra()) |
| 167 | return 0; |
| 168 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 169 | np = of_find_matching_node(NULL, matches); |
| 170 | if (np) { |
| 171 | struct resource res; |
| 172 | |
| 173 | if (of_address_to_resource(np, 0, &res) == 0) { |
| 174 | size = resource_size(&res); |
| 175 | base = res.start; |
| 176 | } |
| 177 | |
| 178 | of_node_put(np); |
| 179 | } |
| 180 | |
| 181 | tegra_flowctrl_base = ioremap_nocache(base, size); |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 182 | if (!tegra_flowctrl_base) |
| 183 | return -ENXIO; |
| 184 | |
| 185 | return 0; |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 186 | } |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame^] | 187 | early_initcall(tegra_flowctrl_init); |