Thomas Gleixner | 46fe777 | 2019-05-31 01:09:57 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 2 | /* |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 3 | * drivers/soc/tegra/flowctrl.c |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 4 | * |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 5 | * Functions and macros to control the flowcontroller |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 6 | * |
| 7 | * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved. |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 10 | #include <linux/cpumask.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/kernel.h> |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 17 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 18 | #include <soc/tegra/common.h> |
| 19 | #include <soc/tegra/flowctrl.h> |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 20 | #include <soc/tegra/fuse.h> |
| 21 | |
Hiroshi Doyu | deeb8d1 | 2013-01-03 08:27:05 +0200 | [diff] [blame] | 22 | static u8 flowctrl_offset_halt_cpu[] = { |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 23 | 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 Doyu | deeb8d1 | 2013-01-03 08:27:05 +0200 | [diff] [blame] | 29 | static u8 flowctrl_offset_cpu_csr[] = { |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 30 | FLOW_CTRL_CPU0_CSR, |
| 31 | FLOW_CTRL_CPU1_CSR, |
| 32 | FLOW_CTRL_CPU1_CSR + 8, |
| 33 | FLOW_CTRL_CPU1_CSR + 16, |
| 34 | }; |
| 35 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 36 | static void __iomem *tegra_flowctrl_base; |
| 37 | |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 38 | static void flowctrl_update(u8 offset, u32 value) |
| 39 | { |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 40 | if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base), |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 41 | "Tegra flowctrl not initialised!\n")) |
| 42 | return; |
| 43 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 44 | writel(value, tegra_flowctrl_base + offset); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 45 | |
| 46 | /* ensure the update has reached the flow controller */ |
| 47 | wmb(); |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 48 | readl_relaxed(tegra_flowctrl_base + offset); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 51 | u32 flowctrl_read_cpu_csr(unsigned int cpuid) |
| 52 | { |
| 53 | u8 offset = flowctrl_offset_cpu_csr[cpuid]; |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 54 | |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 55 | if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base), |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 56 | "Tegra flowctrl not initialised!\n")) |
| 57 | return 0; |
| 58 | |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 59 | return readl(tegra_flowctrl_base + offset); |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 60 | } |
| 61 | |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 62 | void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value) |
| 63 | { |
Peter De Schrijver | 97e7abc | 2012-05-14 13:27:09 +0300 | [diff] [blame] | 64 | return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value) |
| 68 | { |
Peter De Schrijver | 97e7abc | 2012-05-14 13:27:09 +0300 | [diff] [blame] | 69 | return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value); |
Peter De Schrijver | 26fe681 | 2012-02-10 01:47:44 +0200 | [diff] [blame] | 70 | } |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 71 | |
| 72 | void flowctrl_cpu_suspend_enter(unsigned int cpuid) |
| 73 | { |
| 74 | unsigned int reg; |
| 75 | int i; |
| 76 | |
| 77 | reg = flowctrl_read_cpu_csr(cpuid); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 78 | switch (tegra_get_chip_id()) { |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 79 | 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 Lo | dd6fe9a | 2013-07-03 17:50:43 +0800 | [diff] [blame] | 88 | case TEGRA114: |
Joseph Lo | f0c4ac1 | 2013-10-11 17:58:38 +0800 | [diff] [blame] | 89 | case TEGRA124: |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 90 | /* 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 Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 98 | reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */ |
| 99 | reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */ |
Joseph Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 100 | 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 | |
| 113 | void 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 Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 119 | switch (tegra_get_chip_id()) { |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 120 | 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 Lo | dd6fe9a | 2013-07-03 17:50:43 +0800 | [diff] [blame] | 127 | case TEGRA114: |
Joseph Lo | f0c4ac1 | 2013-10-11 17:58:38 +0800 | [diff] [blame] | 128 | case TEGRA124: |
Joseph Lo | afec581 | 2013-01-15 22:11:01 +0000 | [diff] [blame] | 129 | /* 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 Lo | 01459c6 | 2012-10-31 17:41:20 +0800 | [diff] [blame] | 135 | 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 Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 140 | |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 141 | static 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 Jaillet | da1dbec | 2017-04-11 05:40:41 +0200 | [diff] [blame] | 149 | return PTR_ERR(tegra_flowctrl_base); |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 150 | |
| 151 | iounmap(base); |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static const struct of_device_id tegra_flowctrl_match[] = { |
Jon Hunter | 1fd09e5 | 2017-03-28 13:42:58 +0100 | [diff] [blame] | 157 | { .compatible = "nvidia,tegra210-flowctrl" }, |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 158 | { .compatible = "nvidia,tegra124-flowctrl" }, |
| 159 | { .compatible = "nvidia,tegra114-flowctrl" }, |
| 160 | { .compatible = "nvidia,tegra30-flowctrl" }, |
| 161 | { .compatible = "nvidia,tegra20-flowctrl" }, |
| 162 | { } |
| 163 | }; |
| 164 | |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 165 | static 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 | }; |
| 173 | builtin_platform_driver(tegra_flowctrl_driver); |
| 174 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 175 | static int __init tegra_flowctrl_init(void) |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 176 | { |
Jon Hunter | 1fd09e5 | 2017-03-28 13:42:58 +0100 | [diff] [blame] | 177 | struct resource res; |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 178 | struct device_node *np; |
| 179 | |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 180 | if (!soc_is_tegra()) |
| 181 | return 0; |
| 182 | |
Jon Hunter | 841fd94 | 2017-03-28 13:42:55 +0100 | [diff] [blame] | 183 | np = of_find_matching_node(NULL, tegra_flowctrl_match); |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 184 | if (np) { |
Jon Hunter | 1fd09e5 | 2017-03-28 13:42:58 +0100 | [diff] [blame] | 185 | if (of_address_to_resource(np, 0, &res) < 0) { |
| 186 | pr_err("failed to get flowctrl register\n"); |
| 187 | return -ENXIO; |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 188 | } |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 189 | of_node_put(np); |
Jon Hunter | 1fd09e5 | 2017-03-28 13:42:58 +0100 | [diff] [blame] | 190 | } 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 Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Jon Hunter | 1fd09e5 | 2017-03-28 13:42:58 +0100 | [diff] [blame] | 207 | tegra_flowctrl_base = ioremap_nocache(res.start, resource_size(&res)); |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 208 | if (!tegra_flowctrl_base) |
| 209 | return -ENXIO; |
| 210 | |
| 211 | return 0; |
Thierry Reding | 783944f | 2014-08-26 08:14:04 +0200 | [diff] [blame] | 212 | } |
Jon Hunter | 7e10cf7 | 2017-03-28 13:42:54 +0100 | [diff] [blame] | 213 | early_initcall(tegra_flowctrl_init); |