Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/soc/tegra/pmc.c |
| 3 | * |
| 4 | * Copyright (c) 2010 Google, Inc |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 5 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 6 | * |
| 7 | * Author: |
| 8 | * Colin Cross <ccross@google.com> |
| 9 | * |
| 10 | * This software is licensed under the terms of the GNU General Public |
| 11 | * License version 2, as published by the Free Software Foundation, and |
| 12 | * may be copied, distributed, and modified under those terms. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | */ |
| 20 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 21 | #define pr_fmt(fmt) "tegra-pmc: " fmt |
| 22 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 23 | #include <linux/arm-smccc.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 24 | #include <linux/clk.h> |
| 25 | #include <linux/clk/tegra.h> |
| 26 | #include <linux/debugfs.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/err.h> |
| 29 | #include <linux/export.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/io.h> |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 32 | #include <linux/iopoll.h> |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 33 | #include <linux/irqdomain.h> |
Thierry Reding | 4659db5 | 2019-01-25 11:22:49 +0100 | [diff] [blame] | 34 | #include <linux/irq.h> |
| 35 | #include <linux/kernel.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 36 | #include <linux/of_address.h> |
Geert Uytterhoeven | 3fd0121 | 2018-04-18 16:50:04 +0200 | [diff] [blame] | 37 | #include <linux/of_clk.h> |
Thierry Reding | 4659db5 | 2019-01-25 11:22:49 +0100 | [diff] [blame] | 38 | #include <linux/of.h> |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 39 | #include <linux/of_irq.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 40 | #include <linux/of_platform.h> |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 41 | #include <linux/pinctrl/pinconf-generic.h> |
Thierry Reding | 4659db5 | 2019-01-25 11:22:49 +0100 | [diff] [blame] | 42 | #include <linux/pinctrl/pinconf.h> |
| 43 | #include <linux/pinctrl/pinctrl.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 44 | #include <linux/platform_device.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 45 | #include <linux/pm_domain.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 46 | #include <linux/reboot.h> |
| 47 | #include <linux/reset.h> |
| 48 | #include <linux/seq_file.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 49 | #include <linux/slab.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 50 | #include <linux/spinlock.h> |
| 51 | |
| 52 | #include <soc/tegra/common.h> |
| 53 | #include <soc/tegra/fuse.h> |
| 54 | #include <soc/tegra/pmc.h> |
| 55 | |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 56 | #include <dt-bindings/interrupt-controller/arm-gic.h> |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 57 | #include <dt-bindings/pinctrl/pinctrl-tegra-io-pad.h> |
Thierry Reding | e59333c | 2018-09-19 18:41:59 +0200 | [diff] [blame] | 58 | #include <dt-bindings/gpio/tegra186-gpio.h> |
Thierry Reding | e3e403c | 2018-09-19 18:42:37 +0200 | [diff] [blame] | 59 | #include <dt-bindings/gpio/tegra194-gpio.h> |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 60 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 61 | #define PMC_CNTRL 0x0 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 62 | #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */ |
Thierry Reding | 95b780b | 2016-10-10 13:13:36 +0200 | [diff] [blame] | 63 | #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */ |
| 64 | #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */ |
| 65 | #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */ |
| 66 | #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */ |
| 67 | #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */ |
| 68 | #define PMC_CNTRL_MAIN_RST BIT(4) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 69 | |
| 70 | #define DPD_SAMPLE 0x020 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 71 | #define DPD_SAMPLE_ENABLE BIT(0) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 72 | #define DPD_SAMPLE_DISABLE (0 << 0) |
| 73 | |
| 74 | #define PWRGATE_TOGGLE 0x30 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 75 | #define PWRGATE_TOGGLE_START BIT(8) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 76 | |
| 77 | #define REMOVE_CLAMPING 0x34 |
| 78 | |
| 79 | #define PWRGATE_STATUS 0x38 |
| 80 | |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 81 | #define PMC_IMPL_E_33V_PWR 0x40 |
| 82 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 83 | #define PMC_PWR_DET 0x48 |
| 84 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 85 | #define PMC_SCRATCH0_MODE_RECOVERY BIT(31) |
| 86 | #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30) |
| 87 | #define PMC_SCRATCH0_MODE_RCM BIT(1) |
| 88 | #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \ |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 89 | PMC_SCRATCH0_MODE_BOOTLOADER | \ |
| 90 | PMC_SCRATCH0_MODE_RCM) |
| 91 | |
| 92 | #define PMC_CPUPWRGOOD_TIMER 0xc8 |
| 93 | #define PMC_CPUPWROFF_TIMER 0xcc |
| 94 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 95 | #define PMC_PWR_DET_VALUE 0xe4 |
| 96 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 97 | #define PMC_SCRATCH41 0x140 |
| 98 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 99 | #define PMC_SENSOR_CTRL 0x1b0 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 100 | #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2) |
| 101 | #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1) |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 102 | |
Thierry Reding | f5353c6 | 2015-12-30 17:13:29 +0100 | [diff] [blame] | 103 | #define PMC_RST_STATUS_POR 0 |
| 104 | #define PMC_RST_STATUS_WATCHDOG 1 |
| 105 | #define PMC_RST_STATUS_SENSOR 2 |
| 106 | #define PMC_RST_STATUS_SW_MAIN 3 |
| 107 | #define PMC_RST_STATUS_LP0 4 |
| 108 | #define PMC_RST_STATUS_AOTAG 5 |
| 109 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 110 | #define IO_DPD_REQ 0x1b8 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 111 | #define IO_DPD_REQ_CODE_IDLE (0U << 30) |
| 112 | #define IO_DPD_REQ_CODE_OFF (1U << 30) |
| 113 | #define IO_DPD_REQ_CODE_ON (2U << 30) |
| 114 | #define IO_DPD_REQ_CODE_MASK (3U << 30) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 115 | |
| 116 | #define IO_DPD_STATUS 0x1bc |
| 117 | #define IO_DPD2_REQ 0x1c0 |
| 118 | #define IO_DPD2_STATUS 0x1c4 |
| 119 | #define SEL_DPD_TIM 0x1c8 |
| 120 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 121 | #define PMC_SCRATCH54 0x258 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 122 | #define PMC_SCRATCH54_DATA_SHIFT 8 |
| 123 | #define PMC_SCRATCH54_ADDR_SHIFT 0 |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 124 | |
| 125 | #define PMC_SCRATCH55 0x25c |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 126 | #define PMC_SCRATCH55_RESET_TEGRA BIT(31) |
| 127 | #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27 |
| 128 | #define PMC_SCRATCH55_PINMUX_SHIFT 24 |
| 129 | #define PMC_SCRATCH55_16BITOP BIT(15) |
| 130 | #define PMC_SCRATCH55_CHECKSUM_SHIFT 16 |
| 131 | #define PMC_SCRATCH55_I2CSLV1_SHIFT 0 |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 132 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 133 | #define GPU_RG_CNTRL 0x2d4 |
| 134 | |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 135 | /* Tegra186 and later */ |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 136 | #define WAKE_AOWAKE_CNTRL(x) (0x000 + ((x) << 2)) |
| 137 | #define WAKE_AOWAKE_CNTRL_LEVEL (1 << 3) |
| 138 | #define WAKE_AOWAKE_MASK_W(x) (0x180 + ((x) << 2)) |
| 139 | #define WAKE_AOWAKE_MASK_R(x) (0x300 + ((x) << 2)) |
| 140 | #define WAKE_AOWAKE_STATUS_W(x) (0x30c + ((x) << 2)) |
| 141 | #define WAKE_AOWAKE_STATUS_R(x) (0x48c + ((x) << 2)) |
| 142 | #define WAKE_AOWAKE_TIER0_ROUTING(x) (0x4b4 + ((x) << 2)) |
| 143 | #define WAKE_AOWAKE_TIER1_ROUTING(x) (0x4c0 + ((x) << 2)) |
| 144 | #define WAKE_AOWAKE_TIER2_ROUTING(x) (0x4cc + ((x) << 2)) |
| 145 | |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 146 | #define WAKE_AOWAKE_CTRL 0x4f4 |
| 147 | #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0) |
| 148 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 149 | /* for secure PMC */ |
| 150 | #define TEGRA_SMC_PMC 0xc2fffe00 |
| 151 | #define TEGRA_SMC_PMC_READ 0xaa |
| 152 | #define TEGRA_SMC_PMC_WRITE 0xbb |
| 153 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 154 | struct tegra_powergate { |
| 155 | struct generic_pm_domain genpd; |
| 156 | struct tegra_pmc *pmc; |
| 157 | unsigned int id; |
| 158 | struct clk **clks; |
| 159 | unsigned int num_clks; |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 160 | struct reset_control *reset; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 163 | struct tegra_io_pad_soc { |
| 164 | enum tegra_io_pad id; |
| 165 | unsigned int dpd; |
| 166 | unsigned int voltage; |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 167 | const char *name; |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 168 | }; |
| 169 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 170 | struct tegra_pmc_regs { |
| 171 | unsigned int scratch0; |
| 172 | unsigned int dpd_req; |
| 173 | unsigned int dpd_status; |
| 174 | unsigned int dpd2_req; |
| 175 | unsigned int dpd2_status; |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 176 | unsigned int rst_status; |
| 177 | unsigned int rst_source_shift; |
| 178 | unsigned int rst_source_mask; |
| 179 | unsigned int rst_level_shift; |
| 180 | unsigned int rst_level_mask; |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 183 | struct tegra_wake_event { |
| 184 | const char *name; |
| 185 | unsigned int id; |
| 186 | unsigned int irq; |
| 187 | struct { |
| 188 | unsigned int instance; |
| 189 | unsigned int pin; |
| 190 | } gpio; |
| 191 | }; |
| 192 | |
| 193 | #define TEGRA_WAKE_IRQ(_name, _id, _irq) \ |
| 194 | { \ |
| 195 | .name = _name, \ |
| 196 | .id = _id, \ |
| 197 | .irq = _irq, \ |
| 198 | .gpio = { \ |
| 199 | .instance = UINT_MAX, \ |
| 200 | .pin = UINT_MAX, \ |
| 201 | }, \ |
| 202 | } |
| 203 | |
| 204 | #define TEGRA_WAKE_GPIO(_name, _id, _instance, _pin) \ |
| 205 | { \ |
| 206 | .name = _name, \ |
| 207 | .id = _id, \ |
| 208 | .irq = 0, \ |
| 209 | .gpio = { \ |
| 210 | .instance = _instance, \ |
| 211 | .pin = _pin, \ |
| 212 | }, \ |
| 213 | } |
| 214 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 215 | struct tegra_pmc_soc { |
| 216 | unsigned int num_powergates; |
| 217 | const char *const *powergates; |
| 218 | unsigned int num_cpu_powergates; |
| 219 | const u8 *cpu_powergates; |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 220 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 221 | bool has_tsense_reset; |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 222 | bool has_gpu_clamps; |
Peter De Schrijver | a263394a | 2018-01-25 16:00:13 +0200 | [diff] [blame] | 223 | bool needs_mbist_war; |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 224 | bool has_impl_33v_pwr; |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 225 | bool maybe_tz_only; |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 226 | |
| 227 | const struct tegra_io_pad_soc *io_pads; |
| 228 | unsigned int num_io_pads; |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 229 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 230 | const struct pinctrl_pin_desc *pin_descs; |
| 231 | unsigned int num_pin_descs; |
| 232 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 233 | const struct tegra_pmc_regs *regs; |
| 234 | void (*init)(struct tegra_pmc *pmc); |
| 235 | void (*setup_irq_polarity)(struct tegra_pmc *pmc, |
| 236 | struct device_node *np, |
| 237 | bool invert); |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 238 | |
| 239 | const char * const *reset_sources; |
| 240 | unsigned int num_reset_sources; |
| 241 | const char * const *reset_levels; |
| 242 | unsigned int num_reset_levels; |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 243 | |
| 244 | const struct tegra_wake_event *wake_events; |
| 245 | unsigned int num_wake_events; |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | static const char * const tegra186_reset_sources[] = { |
| 249 | "SYS_RESET", |
| 250 | "AOWDT", |
| 251 | "MCCPLEXWDT", |
| 252 | "BPMPWDT", |
| 253 | "SCEWDT", |
| 254 | "SPEWDT", |
| 255 | "APEWDT", |
| 256 | "BCCPLEXWDT", |
| 257 | "SENSOR", |
| 258 | "AOTAG", |
| 259 | "VFSENSOR", |
| 260 | "SWREST", |
| 261 | "SC7", |
| 262 | "HSM", |
| 263 | "CORESIGHT" |
| 264 | }; |
| 265 | |
| 266 | static const char * const tegra186_reset_levels[] = { |
| 267 | "L0", "L1", "L2", "WARM" |
| 268 | }; |
| 269 | |
| 270 | static const char * const tegra30_reset_sources[] = { |
| 271 | "POWER_ON_RESET", |
| 272 | "WATCHDOG", |
| 273 | "SENSOR", |
| 274 | "SW_MAIN", |
| 275 | "LP0", |
| 276 | "AOTAG" |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | /** |
| 280 | * struct tegra_pmc - NVIDIA Tegra PMC |
Jon Hunter | 35b6729 | 2015-12-04 14:57:03 +0000 | [diff] [blame] | 281 | * @dev: pointer to PMC device structure |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 282 | * @base: pointer to I/O remapped register region |
Thierry Reding | bbe5af6 | 2019-01-25 11:22:50 +0100 | [diff] [blame] | 283 | * @wake: pointer to I/O remapped region for WAKE registers |
| 284 | * @aotag: pointer to I/O remapped region for AOTAG registers |
| 285 | * @scratch: pointer to I/O remapped region for scratch registers |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 286 | * @clk: pointer to pclk clock |
Jon Hunter | 35b6729 | 2015-12-04 14:57:03 +0000 | [diff] [blame] | 287 | * @soc: pointer to SoC data structure |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 288 | * @tz_only: flag specifying if the PMC can only be accessed via TrustZone |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 289 | * @debugfs: pointer to debugfs entry |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 290 | * @rate: currently configured rate of pclk |
| 291 | * @suspend_mode: lowest suspend mode available |
| 292 | * @cpu_good_time: CPU power good time (in microseconds) |
| 293 | * @cpu_off_time: CPU power off time (in microsecends) |
| 294 | * @core_osc_time: core power good OSC time (in microseconds) |
| 295 | * @core_pmu_time: core power good PMU time (in microseconds) |
| 296 | * @core_off_time: core power off time (in microseconds) |
| 297 | * @corereq_high: core power request is active-high |
| 298 | * @sysclkreq_high: system clock request is active-high |
| 299 | * @combined_req: combined power request for CPU & core |
| 300 | * @cpu_pwr_good_en: CPU power good signal is enabled |
| 301 | * @lp0_vec_phys: physical base address of the LP0 warm boot code |
| 302 | * @lp0_vec_size: size of the LP0 warm boot code |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 303 | * @powergates_available: Bitmap of available power gates |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 304 | * @powergates_lock: mutex for power gate register access |
Thierry Reding | bbe5af6 | 2019-01-25 11:22:50 +0100 | [diff] [blame] | 305 | * @pctl_dev: pin controller exposed by the PMC |
| 306 | * @domain: IRQ domain provided by the PMC |
| 307 | * @irq: chip implementation for the IRQ domain |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 308 | */ |
| 309 | struct tegra_pmc { |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 310 | struct device *dev; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 311 | void __iomem *base; |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 312 | void __iomem *wake; |
| 313 | void __iomem *aotag; |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 314 | void __iomem *scratch; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 315 | struct clk *clk; |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 316 | struct dentry *debugfs; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 317 | |
| 318 | const struct tegra_pmc_soc *soc; |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 319 | bool tz_only; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 320 | |
| 321 | unsigned long rate; |
| 322 | |
| 323 | enum tegra_suspend_mode suspend_mode; |
| 324 | u32 cpu_good_time; |
| 325 | u32 cpu_off_time; |
| 326 | u32 core_osc_time; |
| 327 | u32 core_pmu_time; |
| 328 | u32 core_off_time; |
| 329 | bool corereq_high; |
| 330 | bool sysclkreq_high; |
| 331 | bool combined_req; |
| 332 | bool cpu_pwr_good_en; |
| 333 | u32 lp0_vec_phys; |
| 334 | u32 lp0_vec_size; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 335 | DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 336 | |
| 337 | struct mutex powergates_lock; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 338 | |
| 339 | struct pinctrl_dev *pctl_dev; |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 340 | |
| 341 | struct irq_domain *domain; |
| 342 | struct irq_chip irq; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static struct tegra_pmc *pmc = &(struct tegra_pmc) { |
| 346 | .base = NULL, |
| 347 | .suspend_mode = TEGRA_SUSPEND_NONE, |
| 348 | }; |
| 349 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 350 | static inline struct tegra_powergate * |
| 351 | to_powergate(struct generic_pm_domain *domain) |
| 352 | { |
| 353 | return container_of(domain, struct tegra_powergate, genpd); |
| 354 | } |
| 355 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 356 | static u32 tegra_pmc_readl(struct tegra_pmc *pmc, unsigned long offset) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 357 | { |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 358 | struct arm_smccc_res res; |
| 359 | |
| 360 | if (pmc->tz_only) { |
| 361 | arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_READ, offset, 0, 0, |
| 362 | 0, 0, 0, &res); |
| 363 | if (res.a0) { |
| 364 | if (pmc->dev) |
| 365 | dev_warn(pmc->dev, "%s(): SMC failed: %lu\n", |
| 366 | __func__, res.a0); |
| 367 | else |
| 368 | pr_warn("%s(): SMC failed: %lu\n", __func__, |
| 369 | res.a0); |
| 370 | } |
| 371 | |
| 372 | return res.a1; |
| 373 | } |
| 374 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 375 | return readl(pmc->base + offset); |
| 376 | } |
| 377 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 378 | static void tegra_pmc_writel(struct tegra_pmc *pmc, u32 value, |
| 379 | unsigned long offset) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 380 | { |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 381 | struct arm_smccc_res res; |
| 382 | |
| 383 | if (pmc->tz_only) { |
| 384 | arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_WRITE, offset, |
| 385 | value, 0, 0, 0, 0, &res); |
| 386 | if (res.a0) { |
| 387 | if (pmc->dev) |
| 388 | dev_warn(pmc->dev, "%s(): SMC failed: %lu\n", |
| 389 | __func__, res.a0); |
| 390 | else |
| 391 | pr_warn("%s(): SMC failed: %lu\n", __func__, |
| 392 | res.a0); |
| 393 | } |
| 394 | } else { |
| 395 | writel(value, pmc->base + offset); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | static u32 tegra_pmc_scratch_readl(struct tegra_pmc *pmc, unsigned long offset) |
| 400 | { |
| 401 | if (pmc->tz_only) |
| 402 | return tegra_pmc_readl(pmc, offset); |
| 403 | |
| 404 | return readl(pmc->scratch + offset); |
| 405 | } |
| 406 | |
| 407 | static void tegra_pmc_scratch_writel(struct tegra_pmc *pmc, u32 value, |
| 408 | unsigned long offset) |
| 409 | { |
| 410 | if (pmc->tz_only) |
| 411 | tegra_pmc_writel(pmc, value, offset); |
| 412 | else |
| 413 | writel(value, pmc->scratch + offset); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 416 | /* |
| 417 | * TODO Figure out a way to call this with the struct tegra_pmc * passed in. |
| 418 | * This currently doesn't work because readx_poll_timeout() can only operate |
| 419 | * on functions that take a single argument. |
| 420 | */ |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 421 | static inline bool tegra_powergate_state(int id) |
| 422 | { |
Jon Hunter | bc9af23 | 2016-02-15 12:38:11 +0000 | [diff] [blame] | 423 | if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 424 | return (tegra_pmc_readl(pmc, GPU_RG_CNTRL) & 0x1) == 0; |
Jon Hunter | bc9af23 | 2016-02-15 12:38:11 +0000 | [diff] [blame] | 425 | else |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 426 | return (tegra_pmc_readl(pmc, PWRGATE_STATUS) & BIT(id)) != 0; |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 429 | static inline bool tegra_powergate_is_valid(struct tegra_pmc *pmc, int id) |
Jon Hunter | 0a243bd | 2016-02-11 18:03:24 +0000 | [diff] [blame] | 430 | { |
| 431 | return (pmc->soc && pmc->soc->powergates[id]); |
| 432 | } |
| 433 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 434 | static inline bool tegra_powergate_is_available(struct tegra_pmc *pmc, int id) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 435 | { |
| 436 | return test_bit(id, pmc->powergates_available); |
| 437 | } |
| 438 | |
| 439 | static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name) |
| 440 | { |
| 441 | unsigned int i; |
| 442 | |
| 443 | if (!pmc || !pmc->soc || !name) |
| 444 | return -EINVAL; |
| 445 | |
| 446 | for (i = 0; i < pmc->soc->num_powergates; i++) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 447 | if (!tegra_powergate_is_valid(pmc, i)) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 448 | continue; |
| 449 | |
| 450 | if (!strcmp(name, pmc->soc->powergates[i])) |
| 451 | return i; |
| 452 | } |
| 453 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 454 | return -ENODEV; |
| 455 | } |
| 456 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 457 | /** |
| 458 | * tegra_powergate_set() - set the state of a partition |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 459 | * @pmc: power management controller |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 460 | * @id: partition ID |
| 461 | * @new_state: new state of the partition |
| 462 | */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 463 | static int tegra_powergate_set(struct tegra_pmc *pmc, unsigned int id, |
| 464 | bool new_state) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 465 | { |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 466 | bool status; |
| 467 | int err; |
| 468 | |
Jon Hunter | bc9af23 | 2016-02-15 12:38:11 +0000 | [diff] [blame] | 469 | if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) |
| 470 | return -EINVAL; |
| 471 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 472 | mutex_lock(&pmc->powergates_lock); |
| 473 | |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 474 | if (tegra_powergate_state(id) == new_state) { |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 475 | mutex_unlock(&pmc->powergates_lock); |
| 476 | return 0; |
| 477 | } |
| 478 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 479 | tegra_pmc_writel(pmc, PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 480 | |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 481 | err = readx_poll_timeout(tegra_powergate_state, id, status, |
| 482 | status == new_state, 10, 100000); |
| 483 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 484 | mutex_unlock(&pmc->powergates_lock); |
| 485 | |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 486 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 489 | static int __tegra_powergate_remove_clamping(struct tegra_pmc *pmc, |
| 490 | unsigned int id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 491 | { |
| 492 | u32 mask; |
| 493 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 494 | mutex_lock(&pmc->powergates_lock); |
| 495 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 496 | /* |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 497 | * On Tegra124 and later, the clamps for the GPU are controlled by a |
| 498 | * separate register (with different semantics). |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 499 | */ |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 500 | if (id == TEGRA_POWERGATE_3D) { |
| 501 | if (pmc->soc->has_gpu_clamps) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 502 | tegra_pmc_writel(pmc, 0, GPU_RG_CNTRL); |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 503 | goto out; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Tegra 2 has a bug where PCIE and VDE clamping masks are |
| 509 | * swapped relatively to the partition ids |
| 510 | */ |
| 511 | if (id == TEGRA_POWERGATE_VDEC) |
| 512 | mask = (1 << TEGRA_POWERGATE_PCIE); |
| 513 | else if (id == TEGRA_POWERGATE_PCIE) |
| 514 | mask = (1 << TEGRA_POWERGATE_VDEC); |
| 515 | else |
| 516 | mask = (1 << id); |
| 517 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 518 | tegra_pmc_writel(pmc, mask, REMOVE_CLAMPING); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 519 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 520 | out: |
| 521 | mutex_unlock(&pmc->powergates_lock); |
| 522 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 523 | return 0; |
| 524 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 525 | |
| 526 | static void tegra_powergate_disable_clocks(struct tegra_powergate *pg) |
| 527 | { |
| 528 | unsigned int i; |
| 529 | |
| 530 | for (i = 0; i < pg->num_clks; i++) |
| 531 | clk_disable_unprepare(pg->clks[i]); |
| 532 | } |
| 533 | |
| 534 | static int tegra_powergate_enable_clocks(struct tegra_powergate *pg) |
| 535 | { |
| 536 | unsigned int i; |
| 537 | int err; |
| 538 | |
| 539 | for (i = 0; i < pg->num_clks; i++) { |
| 540 | err = clk_prepare_enable(pg->clks[i]); |
| 541 | if (err) |
| 542 | goto out; |
| 543 | } |
| 544 | |
| 545 | return 0; |
| 546 | |
| 547 | out: |
| 548 | while (i--) |
| 549 | clk_disable_unprepare(pg->clks[i]); |
| 550 | |
| 551 | return err; |
| 552 | } |
| 553 | |
Peter De Schrijver | a263394a | 2018-01-25 16:00:13 +0200 | [diff] [blame] | 554 | int __weak tegra210_clk_handle_mbist_war(unsigned int id) |
| 555 | { |
| 556 | return 0; |
| 557 | } |
| 558 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 559 | static int tegra_powergate_power_up(struct tegra_powergate *pg, |
| 560 | bool disable_clocks) |
| 561 | { |
| 562 | int err; |
| 563 | |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 564 | err = reset_control_assert(pg->reset); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 565 | if (err) |
| 566 | return err; |
| 567 | |
| 568 | usleep_range(10, 20); |
| 569 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 570 | err = tegra_powergate_set(pg->pmc, pg->id, true); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 571 | if (err < 0) |
| 572 | return err; |
| 573 | |
| 574 | usleep_range(10, 20); |
| 575 | |
| 576 | err = tegra_powergate_enable_clocks(pg); |
| 577 | if (err) |
| 578 | goto disable_clks; |
| 579 | |
| 580 | usleep_range(10, 20); |
| 581 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 582 | err = __tegra_powergate_remove_clamping(pg->pmc, pg->id); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 583 | if (err) |
| 584 | goto disable_clks; |
| 585 | |
| 586 | usleep_range(10, 20); |
| 587 | |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 588 | err = reset_control_deassert(pg->reset); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 589 | if (err) |
| 590 | goto powergate_off; |
| 591 | |
| 592 | usleep_range(10, 20); |
| 593 | |
Peter De Schrijver | a263394a | 2018-01-25 16:00:13 +0200 | [diff] [blame] | 594 | if (pg->pmc->soc->needs_mbist_war) |
| 595 | err = tegra210_clk_handle_mbist_war(pg->id); |
| 596 | if (err) |
| 597 | goto disable_clks; |
| 598 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 599 | if (disable_clocks) |
| 600 | tegra_powergate_disable_clocks(pg); |
| 601 | |
| 602 | return 0; |
| 603 | |
| 604 | disable_clks: |
| 605 | tegra_powergate_disable_clocks(pg); |
| 606 | usleep_range(10, 20); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 607 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 608 | powergate_off: |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 609 | tegra_powergate_set(pg->pmc, pg->id, false); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 610 | |
| 611 | return err; |
| 612 | } |
| 613 | |
| 614 | static int tegra_powergate_power_down(struct tegra_powergate *pg) |
| 615 | { |
| 616 | int err; |
| 617 | |
| 618 | err = tegra_powergate_enable_clocks(pg); |
| 619 | if (err) |
| 620 | return err; |
| 621 | |
| 622 | usleep_range(10, 20); |
| 623 | |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 624 | err = reset_control_assert(pg->reset); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 625 | if (err) |
| 626 | goto disable_clks; |
| 627 | |
| 628 | usleep_range(10, 20); |
| 629 | |
| 630 | tegra_powergate_disable_clocks(pg); |
| 631 | |
| 632 | usleep_range(10, 20); |
| 633 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 634 | err = tegra_powergate_set(pg->pmc, pg->id, false); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 635 | if (err) |
| 636 | goto assert_resets; |
| 637 | |
| 638 | return 0; |
| 639 | |
| 640 | assert_resets: |
| 641 | tegra_powergate_enable_clocks(pg); |
| 642 | usleep_range(10, 20); |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 643 | reset_control_deassert(pg->reset); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 644 | usleep_range(10, 20); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 645 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 646 | disable_clks: |
| 647 | tegra_powergate_disable_clocks(pg); |
| 648 | |
| 649 | return err; |
| 650 | } |
| 651 | |
| 652 | static int tegra_genpd_power_on(struct generic_pm_domain *domain) |
| 653 | { |
| 654 | struct tegra_powergate *pg = to_powergate(domain); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 655 | struct device *dev = pg->pmc->dev; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 656 | int err; |
| 657 | |
| 658 | err = tegra_powergate_power_up(pg, true); |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 659 | if (err) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 660 | dev_err(dev, "failed to turn on PM domain %s: %d\n", |
| 661 | pg->genpd.name, err); |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 662 | goto out; |
| 663 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 664 | |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 665 | reset_control_release(pg->reset); |
| 666 | |
| 667 | out: |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 668 | return err; |
| 669 | } |
| 670 | |
| 671 | static int tegra_genpd_power_off(struct generic_pm_domain *domain) |
| 672 | { |
| 673 | struct tegra_powergate *pg = to_powergate(domain); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 674 | struct device *dev = pg->pmc->dev; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 675 | int err; |
| 676 | |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 677 | err = reset_control_acquire(pg->reset); |
| 678 | if (err < 0) { |
| 679 | pr_err("failed to acquire resets: %d\n", err); |
| 680 | return err; |
| 681 | } |
| 682 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 683 | err = tegra_powergate_power_down(pg); |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 684 | if (err) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 685 | dev_err(dev, "failed to turn off PM domain %s: %d\n", |
| 686 | pg->genpd.name, err); |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 687 | reset_control_release(pg->reset); |
| 688 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 689 | |
| 690 | return err; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * tegra_powergate_power_on() - power on partition |
| 695 | * @id: partition ID |
| 696 | */ |
| 697 | int tegra_powergate_power_on(unsigned int id) |
| 698 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 699 | if (!tegra_powergate_is_available(pmc, id)) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 700 | return -EINVAL; |
| 701 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 702 | return tegra_powergate_set(pmc, id, true); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /** |
| 706 | * tegra_powergate_power_off() - power off partition |
| 707 | * @id: partition ID |
| 708 | */ |
| 709 | int tegra_powergate_power_off(unsigned int id) |
| 710 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 711 | if (!tegra_powergate_is_available(pmc, id)) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 712 | return -EINVAL; |
| 713 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 714 | return tegra_powergate_set(pmc, id, false); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 715 | } |
| 716 | EXPORT_SYMBOL(tegra_powergate_power_off); |
| 717 | |
| 718 | /** |
| 719 | * tegra_powergate_is_powered() - check if partition is powered |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 720 | * @pmc: power management controller |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 721 | * @id: partition ID |
| 722 | */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 723 | static int tegra_powergate_is_powered(struct tegra_pmc *pmc, unsigned int id) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 724 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 725 | if (!tegra_powergate_is_valid(pmc, id)) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 726 | return -EINVAL; |
| 727 | |
Dmitry Osipenko | b6e1fd1 | 2018-10-21 21:36:14 +0300 | [diff] [blame] | 728 | return tegra_powergate_state(id); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /** |
| 732 | * tegra_powergate_remove_clamping() - remove power clamps for partition |
| 733 | * @id: partition ID |
| 734 | */ |
| 735 | int tegra_powergate_remove_clamping(unsigned int id) |
| 736 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 737 | if (!tegra_powergate_is_available(pmc, id)) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 738 | return -EINVAL; |
| 739 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 740 | return __tegra_powergate_remove_clamping(pmc, id); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 741 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 742 | EXPORT_SYMBOL(tegra_powergate_remove_clamping); |
| 743 | |
| 744 | /** |
| 745 | * tegra_powergate_sequence_power_up() - power up partition |
| 746 | * @id: partition ID |
| 747 | * @clk: clock for partition |
| 748 | * @rst: reset for partition |
| 749 | * |
| 750 | * Must be called with clk disabled, and returns with clk enabled. |
| 751 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 752 | int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 753 | struct reset_control *rst) |
| 754 | { |
Viresh Kumar | 495ac33 | 2018-05-03 13:56:17 +0530 | [diff] [blame] | 755 | struct tegra_powergate *pg; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 756 | int err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 757 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 758 | if (!tegra_powergate_is_available(pmc, id)) |
Jon Hunter | 403db2d | 2016-06-28 11:38:23 +0100 | [diff] [blame] | 759 | return -EINVAL; |
| 760 | |
Viresh Kumar | 495ac33 | 2018-05-03 13:56:17 +0530 | [diff] [blame] | 761 | pg = kzalloc(sizeof(*pg), GFP_KERNEL); |
| 762 | if (!pg) |
| 763 | return -ENOMEM; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 764 | |
Viresh Kumar | 495ac33 | 2018-05-03 13:56:17 +0530 | [diff] [blame] | 765 | pg->id = id; |
| 766 | pg->clks = &clk; |
| 767 | pg->num_clks = 1; |
| 768 | pg->reset = rst; |
| 769 | pg->pmc = pmc; |
| 770 | |
| 771 | err = tegra_powergate_power_up(pg, false); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 772 | if (err) |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 773 | dev_err(pmc->dev, "failed to turn on partition %d: %d\n", id, |
| 774 | err); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 775 | |
Viresh Kumar | 495ac33 | 2018-05-03 13:56:17 +0530 | [diff] [blame] | 776 | kfree(pg); |
| 777 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 778 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 779 | } |
| 780 | EXPORT_SYMBOL(tegra_powergate_sequence_power_up); |
| 781 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 782 | /** |
| 783 | * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 784 | * @pmc: power management controller |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 785 | * @cpuid: CPU partition ID |
| 786 | * |
| 787 | * Returns the partition ID corresponding to the CPU partition ID or a |
| 788 | * negative error code on failure. |
| 789 | */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 790 | static int tegra_get_cpu_powergate_id(struct tegra_pmc *pmc, |
| 791 | unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 792 | { |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 793 | if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 794 | return pmc->soc->cpu_powergates[cpuid]; |
| 795 | |
| 796 | return -EINVAL; |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * tegra_pmc_cpu_is_powered() - check if CPU partition is powered |
| 801 | * @cpuid: CPU partition ID |
| 802 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 803 | bool tegra_pmc_cpu_is_powered(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 804 | { |
| 805 | int id; |
| 806 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 807 | id = tegra_get_cpu_powergate_id(pmc, cpuid); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 808 | if (id < 0) |
| 809 | return false; |
| 810 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 811 | return tegra_powergate_is_powered(pmc, id); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | /** |
| 815 | * tegra_pmc_cpu_power_on() - power on CPU partition |
| 816 | * @cpuid: CPU partition ID |
| 817 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 818 | int tegra_pmc_cpu_power_on(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 819 | { |
| 820 | int id; |
| 821 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 822 | id = tegra_get_cpu_powergate_id(pmc, cpuid); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 823 | if (id < 0) |
| 824 | return id; |
| 825 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 826 | return tegra_powergate_set(pmc, id, true); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
| 830 | * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition |
| 831 | * @cpuid: CPU partition ID |
| 832 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 833 | int tegra_pmc_cpu_remove_clamping(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 834 | { |
| 835 | int id; |
| 836 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 837 | id = tegra_get_cpu_powergate_id(pmc, cpuid); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 838 | if (id < 0) |
| 839 | return id; |
| 840 | |
| 841 | return tegra_powergate_remove_clamping(id); |
| 842 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 843 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 844 | static int tegra_pmc_restart_notify(struct notifier_block *this, |
| 845 | unsigned long action, void *data) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 846 | { |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 847 | const char *cmd = data; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 848 | u32 value; |
| 849 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 850 | value = tegra_pmc_scratch_readl(pmc, pmc->soc->regs->scratch0); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 851 | value &= ~PMC_SCRATCH0_MODE_MASK; |
| 852 | |
| 853 | if (cmd) { |
| 854 | if (strcmp(cmd, "recovery") == 0) |
| 855 | value |= PMC_SCRATCH0_MODE_RECOVERY; |
| 856 | |
| 857 | if (strcmp(cmd, "bootloader") == 0) |
| 858 | value |= PMC_SCRATCH0_MODE_BOOTLOADER; |
| 859 | |
| 860 | if (strcmp(cmd, "forced-recovery") == 0) |
| 861 | value |= PMC_SCRATCH0_MODE_RCM; |
| 862 | } |
| 863 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 864 | tegra_pmc_scratch_writel(pmc, value, pmc->soc->regs->scratch0); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 865 | |
Thierry Reding | f5353c6 | 2015-12-30 17:13:29 +0100 | [diff] [blame] | 866 | /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 867 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | f5353c6 | 2015-12-30 17:13:29 +0100 | [diff] [blame] | 868 | value |= PMC_CNTRL_MAIN_RST; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 869 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 870 | |
| 871 | return NOTIFY_DONE; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 872 | } |
| 873 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 874 | static struct notifier_block tegra_pmc_restart_handler = { |
| 875 | .notifier_call = tegra_pmc_restart_notify, |
| 876 | .priority = 128, |
| 877 | }; |
| 878 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 879 | static int powergate_show(struct seq_file *s, void *data) |
| 880 | { |
| 881 | unsigned int i; |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 882 | int status; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 883 | |
| 884 | seq_printf(s, " powergate powered\n"); |
| 885 | seq_printf(s, "------------------\n"); |
| 886 | |
| 887 | for (i = 0; i < pmc->soc->num_powergates; i++) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 888 | status = tegra_powergate_is_powered(pmc, i); |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 889 | if (status < 0) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 890 | continue; |
| 891 | |
| 892 | seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i], |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 893 | status ? "yes" : "no"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Yangtao Li | 57ba33d | 2018-11-22 08:12:07 -0500 | [diff] [blame] | 899 | DEFINE_SHOW_ATTRIBUTE(powergate); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 900 | |
| 901 | static int tegra_powergate_debugfs_init(void) |
| 902 | { |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 903 | pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL, |
| 904 | &powergate_fops); |
| 905 | if (!pmc->debugfs) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 906 | return -ENOMEM; |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 911 | static int tegra_powergate_of_get_clks(struct tegra_powergate *pg, |
| 912 | struct device_node *np) |
| 913 | { |
| 914 | struct clk *clk; |
| 915 | unsigned int i, count; |
| 916 | int err; |
| 917 | |
Geert Uytterhoeven | 3fd0121 | 2018-04-18 16:50:04 +0200 | [diff] [blame] | 918 | count = of_clk_get_parent_count(np); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 919 | if (count == 0) |
| 920 | return -ENODEV; |
| 921 | |
| 922 | pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL); |
| 923 | if (!pg->clks) |
| 924 | return -ENOMEM; |
| 925 | |
| 926 | for (i = 0; i < count; i++) { |
| 927 | pg->clks[i] = of_clk_get(np, i); |
| 928 | if (IS_ERR(pg->clks[i])) { |
| 929 | err = PTR_ERR(pg->clks[i]); |
| 930 | goto err; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | pg->num_clks = count; |
| 935 | |
| 936 | return 0; |
| 937 | |
| 938 | err: |
| 939 | while (i--) |
| 940 | clk_put(pg->clks[i]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 941 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 942 | kfree(pg->clks); |
| 943 | |
| 944 | return err; |
| 945 | } |
| 946 | |
| 947 | static int tegra_powergate_of_get_resets(struct tegra_powergate *pg, |
Jon Hunter | 05cfb98 | 2016-06-29 10:17:47 +0100 | [diff] [blame] | 948 | struct device_node *np, bool off) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 949 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 950 | struct device *dev = pg->pmc->dev; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 951 | int err; |
| 952 | |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 953 | pg->reset = of_reset_control_array_get_exclusive_released(np); |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 954 | if (IS_ERR(pg->reset)) { |
| 955 | err = PTR_ERR(pg->reset); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 956 | dev_err(dev, "failed to get device resets: %d\n", err); |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 957 | return err; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 960 | err = reset_control_acquire(pg->reset); |
| 961 | if (err < 0) { |
| 962 | pr_err("failed to acquire resets: %d\n", err); |
| 963 | goto out; |
| 964 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 965 | |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 966 | if (off) { |
| 967 | err = reset_control_assert(pg->reset); |
| 968 | } else { |
| 969 | err = reset_control_deassert(pg->reset); |
| 970 | if (err < 0) |
| 971 | goto out; |
| 972 | |
| 973 | reset_control_release(pg->reset); |
| 974 | } |
| 975 | |
| 976 | out: |
| 977 | if (err) { |
| 978 | reset_control_release(pg->reset); |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 979 | reset_control_put(pg->reset); |
Thierry Reding | 7fe5719 | 2019-02-18 17:36:43 +0100 | [diff] [blame^] | 980 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 981 | |
| 982 | return err; |
| 983 | } |
| 984 | |
| 985 | static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) |
| 986 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 987 | struct device *dev = pmc->dev; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 988 | struct tegra_powergate *pg; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 989 | int id, err; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 990 | bool off; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 991 | |
| 992 | pg = kzalloc(sizeof(*pg), GFP_KERNEL); |
| 993 | if (!pg) |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 994 | return; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 995 | |
| 996 | id = tegra_powergate_lookup(pmc, np->name); |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 997 | if (id < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 998 | dev_err(dev, "powergate lookup failed for %pOFn: %d\n", np, id); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 999 | goto free_mem; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1000 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1001 | |
| 1002 | /* |
| 1003 | * Clear the bit for this powergate so it cannot be managed |
| 1004 | * directly via the legacy APIs for controlling powergates. |
| 1005 | */ |
| 1006 | clear_bit(id, pmc->powergates_available); |
| 1007 | |
| 1008 | pg->id = id; |
| 1009 | pg->genpd.name = np->name; |
| 1010 | pg->genpd.power_off = tegra_genpd_power_off; |
| 1011 | pg->genpd.power_on = tegra_genpd_power_on; |
| 1012 | pg->pmc = pmc; |
| 1013 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1014 | off = !tegra_powergate_is_powered(pmc, pg->id); |
Jon Hunter | 05cfb98 | 2016-06-29 10:17:47 +0100 | [diff] [blame] | 1015 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1016 | err = tegra_powergate_of_get_clks(pg, np); |
| 1017 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1018 | dev_err(dev, "failed to get clocks for %pOFn: %d\n", np, err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1019 | goto set_available; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1020 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1021 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1022 | err = tegra_powergate_of_get_resets(pg, np, off); |
| 1023 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1024 | dev_err(dev, "failed to get resets for %pOFn: %d\n", np, err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1025 | goto remove_clks; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1026 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1027 | |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 1028 | if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) { |
| 1029 | if (off) |
| 1030 | WARN_ON(tegra_powergate_power_up(pg, true)); |
| 1031 | |
| 1032 | goto remove_resets; |
| 1033 | } |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1034 | |
Jon Hunter | cd5ceda | 2016-10-22 20:23:55 +0100 | [diff] [blame] | 1035 | err = pm_genpd_init(&pg->genpd, NULL, off); |
| 1036 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1037 | dev_err(dev, "failed to initialise PM domain %pOFn: %d\n", np, |
Jon Hunter | cd5ceda | 2016-10-22 20:23:55 +0100 | [diff] [blame] | 1038 | err); |
| 1039 | goto remove_resets; |
| 1040 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1041 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1042 | err = of_genpd_add_provider_simple(np, &pg->genpd); |
| 1043 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1044 | dev_err(dev, "failed to add PM domain provider for %pOFn: %d\n", |
| 1045 | np, err); |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 1046 | goto remove_genpd; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 1047 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1048 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1049 | dev_dbg(dev, "added PM domain %s\n", pg->genpd.name); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1050 | |
| 1051 | return; |
| 1052 | |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 1053 | remove_genpd: |
| 1054 | pm_genpd_remove(&pg->genpd); |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1055 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1056 | remove_resets: |
Vivek Gautam | 4c817cc | 2017-07-19 17:59:08 +0200 | [diff] [blame] | 1057 | reset_control_put(pg->reset); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1058 | |
| 1059 | remove_clks: |
| 1060 | while (pg->num_clks--) |
| 1061 | clk_put(pg->clks[pg->num_clks]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 1062 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1063 | kfree(pg->clks); |
| 1064 | |
| 1065 | set_available: |
| 1066 | set_bit(id, pmc->powergates_available); |
| 1067 | |
| 1068 | free_mem: |
| 1069 | kfree(pg); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1072 | static void tegra_powergate_init(struct tegra_pmc *pmc, |
| 1073 | struct device_node *parent) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1074 | { |
| 1075 | struct device_node *np, *child; |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1076 | unsigned int i; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1077 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1078 | /* Create a bitmap of the available and valid partitions */ |
| 1079 | for (i = 0; i < pmc->soc->num_powergates; i++) |
| 1080 | if (pmc->soc->powergates[i]) |
| 1081 | set_bit(i, pmc->powergates_available); |
| 1082 | |
| 1083 | np = of_get_child_by_name(parent, "powergates"); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1084 | if (!np) |
| 1085 | return; |
| 1086 | |
Tuomas Tynkkynen | 0c106e5 | 2017-07-29 02:58:43 +0300 | [diff] [blame] | 1087 | for_each_child_of_node(np, child) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1088 | tegra_powergate_add(pmc, child); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 1089 | |
| 1090 | of_node_put(np); |
| 1091 | } |
| 1092 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1093 | static const struct tegra_io_pad_soc * |
| 1094 | tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1095 | { |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1096 | unsigned int i; |
| 1097 | |
| 1098 | for (i = 0; i < pmc->soc->num_io_pads; i++) |
| 1099 | if (pmc->soc->io_pads[i].id == id) |
| 1100 | return &pmc->soc->io_pads[i]; |
| 1101 | |
| 1102 | return NULL; |
| 1103 | } |
| 1104 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1105 | static int tegra_io_pad_get_dpd_register_bit(struct tegra_pmc *pmc, |
| 1106 | enum tegra_io_pad id, |
Aapo Vienamo | 00ead3c | 2018-08-10 21:08:08 +0300 | [diff] [blame] | 1107 | unsigned long *request, |
| 1108 | unsigned long *status, |
| 1109 | u32 *mask) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1110 | { |
| 1111 | const struct tegra_io_pad_soc *pad; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1112 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1113 | pad = tegra_io_pad_find(pmc, id); |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1114 | if (!pad) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1115 | dev_err(pmc->dev, "invalid I/O pad ID %u\n", id); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1116 | return -ENOENT; |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1117 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1118 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1119 | if (pad->dpd == UINT_MAX) |
| 1120 | return -ENOTSUPP; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1121 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1122 | *mask = BIT(pad->dpd % 32); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1123 | |
| 1124 | if (pad->dpd < 32) { |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1125 | *status = pmc->soc->regs->dpd_status; |
| 1126 | *request = pmc->soc->regs->dpd_req; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1127 | } else { |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1128 | *status = pmc->soc->regs->dpd2_status; |
| 1129 | *request = pmc->soc->regs->dpd2_req; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Aapo Vienamo | 00ead3c | 2018-08-10 21:08:08 +0300 | [diff] [blame] | 1132 | return 0; |
| 1133 | } |
| 1134 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1135 | static int tegra_io_pad_prepare(struct tegra_pmc *pmc, enum tegra_io_pad id, |
| 1136 | unsigned long *request, unsigned long *status, |
| 1137 | u32 *mask) |
Aapo Vienamo | 00ead3c | 2018-08-10 21:08:08 +0300 | [diff] [blame] | 1138 | { |
| 1139 | unsigned long rate, value; |
| 1140 | int err; |
| 1141 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1142 | err = tegra_io_pad_get_dpd_register_bit(pmc, id, request, status, mask); |
Aapo Vienamo | 00ead3c | 2018-08-10 21:08:08 +0300 | [diff] [blame] | 1143 | if (err) |
| 1144 | return err; |
| 1145 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1146 | if (pmc->clk) { |
| 1147 | rate = clk_get_rate(pmc->clk); |
| 1148 | if (!rate) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1149 | dev_err(pmc->dev, "failed to get clock rate\n"); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1150 | return -ENODEV; |
| 1151 | } |
| 1152 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1153 | tegra_pmc_writel(pmc, DPD_SAMPLE_ENABLE, DPD_SAMPLE); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1154 | |
| 1155 | /* must be at least 200 ns, in APB (PCLK) clock cycles */ |
| 1156 | value = DIV_ROUND_UP(1000000000, rate); |
| 1157 | value = DIV_ROUND_UP(200, value); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1158 | tegra_pmc_writel(pmc, value, SEL_DPD_TIM); |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1159 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1160 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1161 | return 0; |
| 1162 | } |
| 1163 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1164 | static int tegra_io_pad_poll(struct tegra_pmc *pmc, unsigned long offset, |
| 1165 | u32 mask, u32 val, unsigned long timeout) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1166 | { |
Laxman Dewangan | 84cf85e | 2016-06-17 18:36:13 +0530 | [diff] [blame] | 1167 | u32 value; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1168 | |
| 1169 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 1170 | |
| 1171 | while (time_after(timeout, jiffies)) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1172 | value = tegra_pmc_readl(pmc, offset); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1173 | if ((value & mask) == val) |
| 1174 | return 0; |
| 1175 | |
| 1176 | usleep_range(250, 1000); |
| 1177 | } |
| 1178 | |
| 1179 | return -ETIMEDOUT; |
| 1180 | } |
| 1181 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1182 | static void tegra_io_pad_unprepare(struct tegra_pmc *pmc) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1183 | { |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1184 | if (pmc->clk) |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1185 | tegra_pmc_writel(pmc, DPD_SAMPLE_DISABLE, DPD_SAMPLE); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1188 | /** |
| 1189 | * tegra_io_pad_power_enable() - enable power to I/O pad |
| 1190 | * @id: Tegra I/O pad ID for which to enable power |
| 1191 | * |
| 1192 | * Returns: 0 on success or a negative error code on failure. |
| 1193 | */ |
| 1194 | int tegra_io_pad_power_enable(enum tegra_io_pad id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1195 | { |
Vince Hsu | a9ccc123 | 2016-08-11 09:13:36 +0800 | [diff] [blame] | 1196 | unsigned long request, status; |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1197 | u32 mask; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1198 | int err; |
| 1199 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1200 | mutex_lock(&pmc->powergates_lock); |
| 1201 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1202 | err = tegra_io_pad_prepare(pmc, id, &request, &status, &mask); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1203 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1204 | dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1205 | goto unlock; |
| 1206 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1207 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1208 | tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_OFF | mask, request); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1209 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1210 | err = tegra_io_pad_poll(pmc, status, mask, 0, 250); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1211 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1212 | dev_err(pmc->dev, "failed to enable I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1213 | goto unlock; |
Thierry Reding | 592431b | 2015-08-04 15:25:03 +0200 | [diff] [blame] | 1214 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1215 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1216 | tegra_io_pad_unprepare(pmc); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1217 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1218 | unlock: |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1219 | mutex_unlock(&pmc->powergates_lock); |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1220 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1221 | } |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1222 | EXPORT_SYMBOL(tegra_io_pad_power_enable); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1223 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1224 | /** |
| 1225 | * tegra_io_pad_power_disable() - disable power to I/O pad |
| 1226 | * @id: Tegra I/O pad ID for which to disable power |
| 1227 | * |
| 1228 | * Returns: 0 on success or a negative error code on failure. |
| 1229 | */ |
| 1230 | int tegra_io_pad_power_disable(enum tegra_io_pad id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1231 | { |
Vince Hsu | a9ccc123 | 2016-08-11 09:13:36 +0800 | [diff] [blame] | 1232 | unsigned long request, status; |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1233 | u32 mask; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1234 | int err; |
| 1235 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1236 | mutex_lock(&pmc->powergates_lock); |
| 1237 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1238 | err = tegra_io_pad_prepare(pmc, id, &request, &status, &mask); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1239 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1240 | dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1241 | goto unlock; |
Thierry Reding | 592431b | 2015-08-04 15:25:03 +0200 | [diff] [blame] | 1242 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1243 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1244 | tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_ON | mask, request); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1245 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1246 | err = tegra_io_pad_poll(pmc, status, mask, mask, 250); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1247 | if (err < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1248 | dev_err(pmc->dev, "failed to disable I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1249 | goto unlock; |
| 1250 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1251 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1252 | tegra_io_pad_unprepare(pmc); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1253 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1254 | unlock: |
| 1255 | mutex_unlock(&pmc->powergates_lock); |
| 1256 | return err; |
| 1257 | } |
| 1258 | EXPORT_SYMBOL(tegra_io_pad_power_disable); |
| 1259 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1260 | static int tegra_io_pad_is_powered(struct tegra_pmc *pmc, enum tegra_io_pad id) |
Aapo Vienamo | f142b9d | 2018-08-10 21:08:09 +0300 | [diff] [blame] | 1261 | { |
| 1262 | unsigned long request, status; |
| 1263 | u32 mask, value; |
| 1264 | int err; |
| 1265 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1266 | err = tegra_io_pad_get_dpd_register_bit(pmc, id, &request, &status, |
| 1267 | &mask); |
Aapo Vienamo | f142b9d | 2018-08-10 21:08:09 +0300 | [diff] [blame] | 1268 | if (err) |
| 1269 | return err; |
| 1270 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1271 | value = tegra_pmc_readl(pmc, status); |
Aapo Vienamo | f142b9d | 2018-08-10 21:08:09 +0300 | [diff] [blame] | 1272 | |
| 1273 | return !(value & mask); |
| 1274 | } |
| 1275 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1276 | static int tegra_io_pad_set_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id, |
| 1277 | int voltage) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1278 | { |
| 1279 | const struct tegra_io_pad_soc *pad; |
| 1280 | u32 value; |
| 1281 | |
| 1282 | pad = tegra_io_pad_find(pmc, id); |
| 1283 | if (!pad) |
| 1284 | return -ENOENT; |
| 1285 | |
| 1286 | if (pad->voltage == UINT_MAX) |
| 1287 | return -ENOTSUPP; |
| 1288 | |
| 1289 | mutex_lock(&pmc->powergates_lock); |
| 1290 | |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1291 | if (pmc->soc->has_impl_33v_pwr) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1292 | value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1293 | |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 1294 | if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8) |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1295 | value &= ~BIT(pad->voltage); |
| 1296 | else |
| 1297 | value |= BIT(pad->voltage); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1298 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1299 | tegra_pmc_writel(pmc, value, PMC_IMPL_E_33V_PWR); |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1300 | } else { |
| 1301 | /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1302 | value = tegra_pmc_readl(pmc, PMC_PWR_DET); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1303 | value |= BIT(pad->voltage); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1304 | tegra_pmc_writel(pmc, value, PMC_PWR_DET); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1305 | |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1306 | /* update I/O voltage */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1307 | value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE); |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1308 | |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 1309 | if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8) |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1310 | value &= ~BIT(pad->voltage); |
| 1311 | else |
| 1312 | value |= BIT(pad->voltage); |
| 1313 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1314 | tegra_pmc_writel(pmc, value, PMC_PWR_DET_VALUE); |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1315 | } |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1316 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1317 | mutex_unlock(&pmc->powergates_lock); |
| 1318 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1319 | usleep_range(100, 250); |
| 1320 | |
| 1321 | return 0; |
| 1322 | } |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1323 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1324 | static int tegra_io_pad_get_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1325 | { |
| 1326 | const struct tegra_io_pad_soc *pad; |
| 1327 | u32 value; |
| 1328 | |
| 1329 | pad = tegra_io_pad_find(pmc, id); |
| 1330 | if (!pad) |
| 1331 | return -ENOENT; |
| 1332 | |
| 1333 | if (pad->voltage == UINT_MAX) |
| 1334 | return -ENOTSUPP; |
| 1335 | |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1336 | if (pmc->soc->has_impl_33v_pwr) |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1337 | value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR); |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 1338 | else |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1339 | value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1340 | |
| 1341 | if ((value & BIT(pad->voltage)) == 0) |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 1342 | return TEGRA_IO_PAD_VOLTAGE_1V8; |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1343 | |
Aapo Vienamo | fccf0f7 | 2018-08-10 21:08:11 +0300 | [diff] [blame] | 1344 | return TEGRA_IO_PAD_VOLTAGE_3V3; |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1345 | } |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1346 | |
| 1347 | /** |
| 1348 | * tegra_io_rail_power_on() - enable power to I/O rail |
| 1349 | * @id: Tegra I/O pad ID for which to enable power |
| 1350 | * |
| 1351 | * See also: tegra_io_pad_power_enable() |
| 1352 | */ |
| 1353 | int tegra_io_rail_power_on(unsigned int id) |
| 1354 | { |
| 1355 | return tegra_io_pad_power_enable(id); |
| 1356 | } |
| 1357 | EXPORT_SYMBOL(tegra_io_rail_power_on); |
| 1358 | |
| 1359 | /** |
| 1360 | * tegra_io_rail_power_off() - disable power to I/O rail |
| 1361 | * @id: Tegra I/O pad ID for which to disable power |
| 1362 | * |
| 1363 | * See also: tegra_io_pad_power_disable() |
| 1364 | */ |
| 1365 | int tegra_io_rail_power_off(unsigned int id) |
| 1366 | { |
| 1367 | return tegra_io_pad_power_disable(id); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1368 | } |
| 1369 | EXPORT_SYMBOL(tegra_io_rail_power_off); |
| 1370 | |
| 1371 | #ifdef CONFIG_PM_SLEEP |
| 1372 | enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void) |
| 1373 | { |
| 1374 | return pmc->suspend_mode; |
| 1375 | } |
| 1376 | |
| 1377 | void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode) |
| 1378 | { |
| 1379 | if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE) |
| 1380 | return; |
| 1381 | |
| 1382 | pmc->suspend_mode = mode; |
| 1383 | } |
| 1384 | |
| 1385 | void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode) |
| 1386 | { |
| 1387 | unsigned long long rate = 0; |
| 1388 | u32 value; |
| 1389 | |
| 1390 | switch (mode) { |
| 1391 | case TEGRA_SUSPEND_LP1: |
| 1392 | rate = 32768; |
| 1393 | break; |
| 1394 | |
| 1395 | case TEGRA_SUSPEND_LP2: |
| 1396 | rate = clk_get_rate(pmc->clk); |
| 1397 | break; |
| 1398 | |
| 1399 | default: |
| 1400 | break; |
| 1401 | } |
| 1402 | |
| 1403 | if (WARN_ON_ONCE(rate == 0)) |
| 1404 | rate = 100000000; |
| 1405 | |
| 1406 | if (rate != pmc->rate) { |
| 1407 | u64 ticks; |
| 1408 | |
| 1409 | ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1; |
| 1410 | do_div(ticks, USEC_PER_SEC); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1411 | tegra_pmc_writel(pmc, ticks, PMC_CPUPWRGOOD_TIMER); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1412 | |
| 1413 | ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1; |
| 1414 | do_div(ticks, USEC_PER_SEC); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1415 | tegra_pmc_writel(pmc, ticks, PMC_CPUPWROFF_TIMER); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1416 | |
| 1417 | wmb(); |
| 1418 | |
| 1419 | pmc->rate = rate; |
| 1420 | } |
| 1421 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1422 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1423 | value &= ~PMC_CNTRL_SIDE_EFFECT_LP0; |
| 1424 | value |= PMC_CNTRL_CPU_PWRREQ_OE; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1425 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1426 | } |
| 1427 | #endif |
| 1428 | |
| 1429 | static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np) |
| 1430 | { |
| 1431 | u32 value, values[2]; |
| 1432 | |
| 1433 | if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) { |
| 1434 | } else { |
| 1435 | switch (value) { |
| 1436 | case 0: |
| 1437 | pmc->suspend_mode = TEGRA_SUSPEND_LP0; |
| 1438 | break; |
| 1439 | |
| 1440 | case 1: |
| 1441 | pmc->suspend_mode = TEGRA_SUSPEND_LP1; |
| 1442 | break; |
| 1443 | |
| 1444 | case 2: |
| 1445 | pmc->suspend_mode = TEGRA_SUSPEND_LP2; |
| 1446 | break; |
| 1447 | |
| 1448 | default: |
| 1449 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1450 | break; |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode); |
| 1455 | |
| 1456 | if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value)) |
| 1457 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1458 | |
| 1459 | pmc->cpu_good_time = value; |
| 1460 | |
| 1461 | if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value)) |
| 1462 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1463 | |
| 1464 | pmc->cpu_off_time = value; |
| 1465 | |
| 1466 | if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time", |
| 1467 | values, ARRAY_SIZE(values))) |
| 1468 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1469 | |
| 1470 | pmc->core_osc_time = values[0]; |
| 1471 | pmc->core_pmu_time = values[1]; |
| 1472 | |
| 1473 | if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value)) |
| 1474 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1475 | |
| 1476 | pmc->core_off_time = value; |
| 1477 | |
| 1478 | pmc->corereq_high = of_property_read_bool(np, |
| 1479 | "nvidia,core-power-req-active-high"); |
| 1480 | |
| 1481 | pmc->sysclkreq_high = of_property_read_bool(np, |
| 1482 | "nvidia,sys-clock-req-active-high"); |
| 1483 | |
| 1484 | pmc->combined_req = of_property_read_bool(np, |
| 1485 | "nvidia,combined-power-req"); |
| 1486 | |
| 1487 | pmc->cpu_pwr_good_en = of_property_read_bool(np, |
| 1488 | "nvidia,cpu-pwr-good-en"); |
| 1489 | |
| 1490 | if (of_property_read_u32_array(np, "nvidia,lp0-vec", values, |
| 1491 | ARRAY_SIZE(values))) |
| 1492 | if (pmc->suspend_mode == TEGRA_SUSPEND_LP0) |
| 1493 | pmc->suspend_mode = TEGRA_SUSPEND_LP1; |
| 1494 | |
| 1495 | pmc->lp0_vec_phys = values[0]; |
| 1496 | pmc->lp0_vec_size = values[1]; |
| 1497 | |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | static void tegra_pmc_init(struct tegra_pmc *pmc) |
| 1502 | { |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 1503 | if (pmc->soc->init) |
| 1504 | pmc->soc->init(pmc); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
Jon Hunter | 1e52efdf | 2015-12-04 14:57:04 +0000 | [diff] [blame] | 1507 | static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc) |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1508 | { |
| 1509 | static const char disabled[] = "emergency thermal reset disabled"; |
| 1510 | u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux; |
| 1511 | struct device *dev = pmc->dev; |
| 1512 | struct device_node *np; |
| 1513 | u32 value, checksum; |
| 1514 | |
| 1515 | if (!pmc->soc->has_tsense_reset) |
Thierry Reding | 95169cd | 2015-07-09 09:59:55 +0200 | [diff] [blame] | 1516 | return; |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1517 | |
Johan Hovold | 1dc6bd5 | 2017-11-15 10:44:58 +0100 | [diff] [blame] | 1518 | np = of_get_child_by_name(pmc->dev->of_node, "i2c-thermtrip"); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1519 | if (!np) { |
| 1520 | dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled); |
Thierry Reding | 95169cd | 2015-07-09 09:59:55 +0200 | [diff] [blame] | 1521 | return; |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) { |
| 1525 | dev_err(dev, "I2C controller ID missing, %s.\n", disabled); |
| 1526 | goto out; |
| 1527 | } |
| 1528 | |
| 1529 | if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) { |
| 1530 | dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled); |
| 1531 | goto out; |
| 1532 | } |
| 1533 | |
| 1534 | if (of_property_read_u32(np, "nvidia,reg-addr", ®_addr)) { |
| 1535 | dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled); |
| 1536 | goto out; |
| 1537 | } |
| 1538 | |
| 1539 | if (of_property_read_u32(np, "nvidia,reg-data", ®_data)) { |
| 1540 | dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled); |
| 1541 | goto out; |
| 1542 | } |
| 1543 | |
| 1544 | if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux)) |
| 1545 | pinmux = 0; |
| 1546 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1547 | value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1548 | value |= PMC_SENSOR_CTRL_SCRATCH_WRITE; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1549 | tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1550 | |
| 1551 | value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) | |
| 1552 | (reg_addr << PMC_SCRATCH54_ADDR_SHIFT); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1553 | tegra_pmc_writel(pmc, value, PMC_SCRATCH54); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1554 | |
| 1555 | value = PMC_SCRATCH55_RESET_TEGRA; |
| 1556 | value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT; |
| 1557 | value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT; |
| 1558 | value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT; |
| 1559 | |
| 1560 | /* |
| 1561 | * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will |
| 1562 | * contain the checksum and are currently zero, so they are not added. |
| 1563 | */ |
| 1564 | checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff) |
| 1565 | + ((value >> 24) & 0xff); |
| 1566 | checksum &= 0xff; |
| 1567 | checksum = 0x100 - checksum; |
| 1568 | |
| 1569 | value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT; |
| 1570 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1571 | tegra_pmc_writel(pmc, value, PMC_SCRATCH55); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1572 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1573 | value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1574 | value |= PMC_SENSOR_CTRL_ENABLE_RST; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1575 | tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1576 | |
| 1577 | dev_info(pmc->dev, "emergency thermal reset enabled\n"); |
| 1578 | |
| 1579 | out: |
| 1580 | of_node_put(np); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1581 | } |
| 1582 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1583 | static int tegra_io_pad_pinctrl_get_groups_count(struct pinctrl_dev *pctl_dev) |
| 1584 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1585 | struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); |
| 1586 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1587 | return pmc->soc->num_io_pads; |
| 1588 | } |
| 1589 | |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1590 | static const char *tegra_io_pad_pinctrl_get_group_name(struct pinctrl_dev *pctl, |
| 1591 | unsigned int group) |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1592 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1593 | struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl); |
| 1594 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1595 | return pmc->soc->io_pads[group].name; |
| 1596 | } |
| 1597 | |
| 1598 | static int tegra_io_pad_pinctrl_get_group_pins(struct pinctrl_dev *pctl_dev, |
| 1599 | unsigned int group, |
| 1600 | const unsigned int **pins, |
| 1601 | unsigned int *num_pins) |
| 1602 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1603 | struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); |
| 1604 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1605 | *pins = &pmc->soc->io_pads[group].id; |
| 1606 | *num_pins = 1; |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1607 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1608 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | static const struct pinctrl_ops tegra_io_pad_pinctrl_ops = { |
| 1612 | .get_groups_count = tegra_io_pad_pinctrl_get_groups_count, |
| 1613 | .get_group_name = tegra_io_pad_pinctrl_get_group_name, |
| 1614 | .get_group_pins = tegra_io_pad_pinctrl_get_group_pins, |
| 1615 | .dt_node_to_map = pinconf_generic_dt_node_to_map_pin, |
| 1616 | .dt_free_map = pinconf_generic_dt_free_map, |
| 1617 | }; |
| 1618 | |
| 1619 | static int tegra_io_pad_pinconf_get(struct pinctrl_dev *pctl_dev, |
| 1620 | unsigned int pin, unsigned long *config) |
| 1621 | { |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1622 | enum pin_config_param param = pinconf_to_config_param(*config); |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1623 | struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); |
| 1624 | const struct tegra_io_pad_soc *pad; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1625 | int ret; |
| 1626 | u32 arg; |
| 1627 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1628 | pad = tegra_io_pad_find(pmc, pin); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1629 | if (!pad) |
| 1630 | return -EINVAL; |
| 1631 | |
| 1632 | switch (param) { |
| 1633 | case PIN_CONFIG_POWER_SOURCE: |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1634 | ret = tegra_io_pad_get_voltage(pmc, pad->id); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1635 | if (ret < 0) |
| 1636 | return ret; |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1637 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1638 | arg = ret; |
| 1639 | break; |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1640 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1641 | case PIN_CONFIG_LOW_POWER_MODE: |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1642 | ret = tegra_io_pad_is_powered(pmc, pad->id); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1643 | if (ret < 0) |
| 1644 | return ret; |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1645 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1646 | arg = !ret; |
| 1647 | break; |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1648 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1649 | default: |
| 1650 | return -EINVAL; |
| 1651 | } |
| 1652 | |
| 1653 | *config = pinconf_to_config_packed(param, arg); |
| 1654 | |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | static int tegra_io_pad_pinconf_set(struct pinctrl_dev *pctl_dev, |
| 1659 | unsigned int pin, unsigned long *configs, |
| 1660 | unsigned int num_configs) |
| 1661 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1662 | struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); |
| 1663 | const struct tegra_io_pad_soc *pad; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1664 | enum pin_config_param param; |
| 1665 | unsigned int i; |
| 1666 | int err; |
| 1667 | u32 arg; |
| 1668 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1669 | pad = tegra_io_pad_find(pmc, pin); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1670 | if (!pad) |
| 1671 | return -EINVAL; |
| 1672 | |
| 1673 | for (i = 0; i < num_configs; ++i) { |
| 1674 | param = pinconf_to_config_param(configs[i]); |
| 1675 | arg = pinconf_to_config_argument(configs[i]); |
| 1676 | |
| 1677 | switch (param) { |
| 1678 | case PIN_CONFIG_LOW_POWER_MODE: |
| 1679 | if (arg) |
| 1680 | err = tegra_io_pad_power_disable(pad->id); |
| 1681 | else |
| 1682 | err = tegra_io_pad_power_enable(pad->id); |
| 1683 | if (err) |
| 1684 | return err; |
| 1685 | break; |
| 1686 | case PIN_CONFIG_POWER_SOURCE: |
| 1687 | if (arg != TEGRA_IO_PAD_VOLTAGE_1V8 && |
| 1688 | arg != TEGRA_IO_PAD_VOLTAGE_3V3) |
| 1689 | return -EINVAL; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1690 | err = tegra_io_pad_set_voltage(pmc, pad->id, arg); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1691 | if (err) |
| 1692 | return err; |
| 1693 | break; |
| 1694 | default: |
| 1695 | return -EINVAL; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | static const struct pinconf_ops tegra_io_pad_pinconf_ops = { |
| 1703 | .pin_config_get = tegra_io_pad_pinconf_get, |
| 1704 | .pin_config_set = tegra_io_pad_pinconf_set, |
| 1705 | .is_generic = true, |
| 1706 | }; |
| 1707 | |
| 1708 | static struct pinctrl_desc tegra_pmc_pctl_desc = { |
| 1709 | .pctlops = &tegra_io_pad_pinctrl_ops, |
| 1710 | .confops = &tegra_io_pad_pinconf_ops, |
| 1711 | }; |
| 1712 | |
| 1713 | static int tegra_pmc_pinctrl_init(struct tegra_pmc *pmc) |
| 1714 | { |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1715 | int err; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1716 | |
| 1717 | if (!pmc->soc->num_pin_descs) |
| 1718 | return 0; |
| 1719 | |
| 1720 | tegra_pmc_pctl_desc.name = dev_name(pmc->dev); |
| 1721 | tegra_pmc_pctl_desc.pins = pmc->soc->pin_descs; |
| 1722 | tegra_pmc_pctl_desc.npins = pmc->soc->num_pin_descs; |
| 1723 | |
| 1724 | pmc->pctl_dev = devm_pinctrl_register(pmc->dev, &tegra_pmc_pctl_desc, |
| 1725 | pmc); |
| 1726 | if (IS_ERR(pmc->pctl_dev)) { |
| 1727 | err = PTR_ERR(pmc->pctl_dev); |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1728 | dev_err(pmc->dev, "failed to register pin controller: %d\n", |
| 1729 | err); |
| 1730 | return err; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1731 | } |
| 1732 | |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1733 | return 0; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 1734 | } |
| 1735 | |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1736 | static ssize_t reset_reason_show(struct device *dev, |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1737 | struct device_attribute *attr, char *buf) |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1738 | { |
| 1739 | u32 value, rst_src; |
| 1740 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1741 | value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status); |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1742 | rst_src = (value & pmc->soc->regs->rst_source_mask) >> |
| 1743 | pmc->soc->regs->rst_source_shift; |
| 1744 | |
| 1745 | return sprintf(buf, "%s\n", pmc->soc->reset_sources[rst_src]); |
| 1746 | } |
| 1747 | |
| 1748 | static DEVICE_ATTR_RO(reset_reason); |
| 1749 | |
| 1750 | static ssize_t reset_level_show(struct device *dev, |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1751 | struct device_attribute *attr, char *buf) |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1752 | { |
| 1753 | u32 value, rst_lvl; |
| 1754 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 1755 | value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status); |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1756 | rst_lvl = (value & pmc->soc->regs->rst_level_mask) >> |
| 1757 | pmc->soc->regs->rst_level_shift; |
| 1758 | |
| 1759 | return sprintf(buf, "%s\n", pmc->soc->reset_levels[rst_lvl]); |
| 1760 | } |
| 1761 | |
| 1762 | static DEVICE_ATTR_RO(reset_level); |
| 1763 | |
| 1764 | static void tegra_pmc_reset_sysfs_init(struct tegra_pmc *pmc) |
| 1765 | { |
| 1766 | struct device *dev = pmc->dev; |
| 1767 | int err = 0; |
| 1768 | |
| 1769 | if (pmc->soc->reset_sources) { |
| 1770 | err = device_create_file(dev, &dev_attr_reset_reason); |
| 1771 | if (err < 0) |
| 1772 | dev_warn(dev, |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1773 | "failed to create attr \"reset_reason\": %d\n", |
| 1774 | err); |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | if (pmc->soc->reset_levels) { |
| 1778 | err = device_create_file(dev, &dev_attr_reset_level); |
| 1779 | if (err < 0) |
| 1780 | dev_warn(dev, |
Thierry Reding | f1d9129 | 2019-01-25 11:22:53 +0100 | [diff] [blame] | 1781 | "failed to create attr \"reset_level\": %d\n", |
| 1782 | err); |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 1786 | static int tegra_pmc_irq_translate(struct irq_domain *domain, |
| 1787 | struct irq_fwspec *fwspec, |
| 1788 | unsigned long *hwirq, |
| 1789 | unsigned int *type) |
| 1790 | { |
| 1791 | if (WARN_ON(fwspec->param_count < 2)) |
| 1792 | return -EINVAL; |
| 1793 | |
| 1794 | *hwirq = fwspec->param[0]; |
| 1795 | *type = fwspec->param[1]; |
| 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
| 1800 | static int tegra_pmc_irq_alloc(struct irq_domain *domain, unsigned int virq, |
| 1801 | unsigned int num_irqs, void *data) |
| 1802 | { |
| 1803 | struct tegra_pmc *pmc = domain->host_data; |
| 1804 | const struct tegra_pmc_soc *soc = pmc->soc; |
| 1805 | struct irq_fwspec *fwspec = data; |
| 1806 | unsigned int i; |
| 1807 | int err = 0; |
| 1808 | |
| 1809 | for (i = 0; i < soc->num_wake_events; i++) { |
| 1810 | const struct tegra_wake_event *event = &soc->wake_events[i]; |
| 1811 | |
| 1812 | if (fwspec->param_count == 2) { |
| 1813 | struct irq_fwspec spec; |
| 1814 | |
| 1815 | if (event->id != fwspec->param[0]) |
| 1816 | continue; |
| 1817 | |
| 1818 | err = irq_domain_set_hwirq_and_chip(domain, virq, |
| 1819 | event->id, |
| 1820 | &pmc->irq, pmc); |
| 1821 | if (err < 0) |
| 1822 | break; |
| 1823 | |
| 1824 | spec.fwnode = &pmc->dev->of_node->fwnode; |
| 1825 | spec.param_count = 3; |
| 1826 | spec.param[0] = GIC_SPI; |
| 1827 | spec.param[1] = event->irq; |
| 1828 | spec.param[2] = fwspec->param[1]; |
| 1829 | |
| 1830 | err = irq_domain_alloc_irqs_parent(domain, virq, |
| 1831 | num_irqs, &spec); |
| 1832 | |
| 1833 | break; |
| 1834 | } |
| 1835 | |
| 1836 | if (fwspec->param_count == 3) { |
| 1837 | if (event->gpio.instance != fwspec->param[0] || |
| 1838 | event->gpio.pin != fwspec->param[1]) |
| 1839 | continue; |
| 1840 | |
| 1841 | err = irq_domain_set_hwirq_and_chip(domain, virq, |
| 1842 | event->id, |
| 1843 | &pmc->irq, pmc); |
| 1844 | |
| 1845 | break; |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | if (i == soc->num_wake_events) |
| 1850 | err = irq_domain_set_hwirq_and_chip(domain, virq, ULONG_MAX, |
| 1851 | &pmc->irq, pmc); |
| 1852 | |
| 1853 | return err; |
| 1854 | } |
| 1855 | |
| 1856 | static const struct irq_domain_ops tegra_pmc_irq_domain_ops = { |
| 1857 | .translate = tegra_pmc_irq_translate, |
| 1858 | .alloc = tegra_pmc_irq_alloc, |
| 1859 | }; |
| 1860 | |
| 1861 | static int tegra_pmc_irq_set_wake(struct irq_data *data, unsigned int on) |
| 1862 | { |
| 1863 | struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data); |
| 1864 | unsigned int offset, bit; |
| 1865 | u32 value; |
| 1866 | |
| 1867 | offset = data->hwirq / 32; |
| 1868 | bit = data->hwirq % 32; |
| 1869 | |
| 1870 | /* clear wake status */ |
| 1871 | writel(0x1, pmc->wake + WAKE_AOWAKE_STATUS_W(data->hwirq)); |
| 1872 | |
| 1873 | /* route wake to tier 2 */ |
| 1874 | value = readl(pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset)); |
| 1875 | |
| 1876 | if (!on) |
| 1877 | value &= ~(1 << bit); |
| 1878 | else |
| 1879 | value |= 1 << bit; |
| 1880 | |
| 1881 | writel(value, pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset)); |
| 1882 | |
| 1883 | /* enable wakeup event */ |
| 1884 | writel(!!on, pmc->wake + WAKE_AOWAKE_MASK_W(data->hwirq)); |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
| 1889 | static int tegra_pmc_irq_set_type(struct irq_data *data, unsigned int type) |
| 1890 | { |
| 1891 | struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data); |
| 1892 | u32 value; |
| 1893 | |
| 1894 | if (data->hwirq == ULONG_MAX) |
| 1895 | return 0; |
| 1896 | |
| 1897 | value = readl(pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq)); |
| 1898 | |
| 1899 | switch (type) { |
| 1900 | case IRQ_TYPE_EDGE_RISING: |
| 1901 | case IRQ_TYPE_LEVEL_HIGH: |
| 1902 | value |= WAKE_AOWAKE_CNTRL_LEVEL; |
| 1903 | break; |
| 1904 | |
| 1905 | case IRQ_TYPE_EDGE_FALLING: |
| 1906 | case IRQ_TYPE_LEVEL_LOW: |
| 1907 | value &= ~WAKE_AOWAKE_CNTRL_LEVEL; |
| 1908 | break; |
| 1909 | |
| 1910 | case IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING: |
| 1911 | value ^= WAKE_AOWAKE_CNTRL_LEVEL; |
| 1912 | break; |
| 1913 | |
| 1914 | default: |
| 1915 | return -EINVAL; |
| 1916 | } |
| 1917 | |
| 1918 | writel(value, pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq)); |
| 1919 | |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
| 1923 | static int tegra_pmc_irq_init(struct tegra_pmc *pmc) |
| 1924 | { |
| 1925 | struct irq_domain *parent = NULL; |
| 1926 | struct device_node *np; |
| 1927 | |
| 1928 | np = of_irq_find_parent(pmc->dev->of_node); |
| 1929 | if (np) { |
| 1930 | parent = irq_find_host(np); |
| 1931 | of_node_put(np); |
| 1932 | } |
| 1933 | |
| 1934 | if (!parent) |
| 1935 | return 0; |
| 1936 | |
| 1937 | pmc->irq.name = dev_name(pmc->dev); |
| 1938 | pmc->irq.irq_mask = irq_chip_mask_parent; |
| 1939 | pmc->irq.irq_unmask = irq_chip_unmask_parent; |
| 1940 | pmc->irq.irq_eoi = irq_chip_eoi_parent; |
| 1941 | pmc->irq.irq_set_affinity = irq_chip_set_affinity_parent; |
| 1942 | pmc->irq.irq_set_type = tegra_pmc_irq_set_type; |
| 1943 | pmc->irq.irq_set_wake = tegra_pmc_irq_set_wake; |
| 1944 | |
| 1945 | pmc->domain = irq_domain_add_hierarchy(parent, 0, 96, pmc->dev->of_node, |
| 1946 | &tegra_pmc_irq_domain_ops, pmc); |
| 1947 | if (!pmc->domain) { |
| 1948 | dev_err(pmc->dev, "failed to allocate domain\n"); |
| 1949 | return -ENOMEM; |
| 1950 | } |
| 1951 | |
| 1952 | return 0; |
| 1953 | } |
| 1954 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1955 | static int tegra_pmc_probe(struct platform_device *pdev) |
| 1956 | { |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1957 | void __iomem *base; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1958 | struct resource *res; |
| 1959 | int err; |
| 1960 | |
Jon Hunter | a83f1fc | 2016-06-28 11:38:28 +0100 | [diff] [blame] | 1961 | /* |
| 1962 | * Early initialisation should have configured an initial |
| 1963 | * register mapping and setup the soc data pointer. If these |
| 1964 | * are not valid then something went badly wrong! |
| 1965 | */ |
| 1966 | if (WARN_ON(!pmc->base || !pmc->soc)) |
| 1967 | return -ENODEV; |
| 1968 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1969 | err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node); |
| 1970 | if (err < 0) |
| 1971 | return err; |
| 1972 | |
| 1973 | /* take over the memory region from the early initialization */ |
| 1974 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 1975 | base = devm_ioremap_resource(&pdev->dev, res); |
| 1976 | if (IS_ERR(base)) |
| 1977 | return PTR_ERR(base); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1978 | |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 1979 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wake"); |
| 1980 | if (res) { |
| 1981 | pmc->wake = devm_ioremap_resource(&pdev->dev, res); |
| 1982 | if (IS_ERR(pmc->wake)) |
| 1983 | return PTR_ERR(pmc->wake); |
| 1984 | } else { |
| 1985 | pmc->wake = base; |
| 1986 | } |
| 1987 | |
| 1988 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aotag"); |
| 1989 | if (res) { |
| 1990 | pmc->aotag = devm_ioremap_resource(&pdev->dev, res); |
| 1991 | if (IS_ERR(pmc->aotag)) |
| 1992 | return PTR_ERR(pmc->aotag); |
| 1993 | } else { |
| 1994 | pmc->aotag = base; |
| 1995 | } |
| 1996 | |
| 1997 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "scratch"); |
| 1998 | if (res) { |
| 1999 | pmc->scratch = devm_ioremap_resource(&pdev->dev, res); |
| 2000 | if (IS_ERR(pmc->scratch)) |
| 2001 | return PTR_ERR(pmc->scratch); |
| 2002 | } else { |
| 2003 | pmc->scratch = base; |
| 2004 | } |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2005 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2006 | pmc->clk = devm_clk_get(&pdev->dev, "pclk"); |
| 2007 | if (IS_ERR(pmc->clk)) { |
| 2008 | err = PTR_ERR(pmc->clk); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2009 | |
| 2010 | if (err != -ENOENT) { |
| 2011 | dev_err(&pdev->dev, "failed to get pclk: %d\n", err); |
| 2012 | return err; |
| 2013 | } |
| 2014 | |
| 2015 | pmc->clk = NULL; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2018 | pmc->dev = &pdev->dev; |
| 2019 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2020 | tegra_pmc_init(pmc); |
| 2021 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2022 | tegra_pmc_init_tsense_reset(pmc); |
| 2023 | |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2024 | tegra_pmc_reset_sysfs_init(pmc); |
| 2025 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2026 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
| 2027 | err = tegra_powergate_debugfs_init(); |
| 2028 | if (err < 0) |
| 2029 | return err; |
| 2030 | } |
| 2031 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 2032 | err = register_restart_handler(&tegra_pmc_restart_handler); |
| 2033 | if (err) { |
| 2034 | dev_err(&pdev->dev, "unable to register restart handler, %d\n", |
| 2035 | err); |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2036 | goto cleanup_debugfs; |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2039 | err = tegra_pmc_pinctrl_init(pmc); |
| 2040 | if (err) |
| 2041 | goto cleanup_restart_handler; |
| 2042 | |
Thierry Reding | 19906e6 | 2018-09-17 15:08:17 +0200 | [diff] [blame] | 2043 | err = tegra_pmc_irq_init(pmc); |
| 2044 | if (err < 0) |
| 2045 | goto cleanup_restart_handler; |
| 2046 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 2047 | mutex_lock(&pmc->powergates_lock); |
| 2048 | iounmap(pmc->base); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 2049 | pmc->base = base; |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 2050 | mutex_unlock(&pmc->powergates_lock); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 2051 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2052 | platform_set_drvdata(pdev, pmc); |
| 2053 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2054 | return 0; |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2055 | |
| 2056 | cleanup_restart_handler: |
| 2057 | unregister_restart_handler(&tegra_pmc_restart_handler); |
| 2058 | cleanup_debugfs: |
| 2059 | debugfs_remove(pmc->debugfs); |
| 2060 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2061 | } |
| 2062 | |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 2063 | #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2064 | static int tegra_pmc_suspend(struct device *dev) |
| 2065 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2066 | struct tegra_pmc *pmc = dev_get_drvdata(dev); |
| 2067 | |
| 2068 | tegra_pmc_writel(pmc, virt_to_phys(tegra_resume), PMC_SCRATCH41); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2069 | |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
| 2073 | static int tegra_pmc_resume(struct device *dev) |
| 2074 | { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2075 | struct tegra_pmc *pmc = dev_get_drvdata(dev); |
| 2076 | |
| 2077 | tegra_pmc_writel(pmc, 0x0, PMC_SCRATCH41); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2078 | |
| 2079 | return 0; |
| 2080 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2081 | |
| 2082 | static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume); |
| 2083 | |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 2084 | #endif |
| 2085 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2086 | static const char * const tegra20_powergates[] = { |
| 2087 | [TEGRA_POWERGATE_CPU] = "cpu", |
| 2088 | [TEGRA_POWERGATE_3D] = "3d", |
| 2089 | [TEGRA_POWERGATE_VENC] = "venc", |
| 2090 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 2091 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 2092 | [TEGRA_POWERGATE_L2] = "l2", |
| 2093 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 2094 | }; |
| 2095 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2096 | static const struct tegra_pmc_regs tegra20_pmc_regs = { |
| 2097 | .scratch0 = 0x50, |
| 2098 | .dpd_req = 0x1b8, |
| 2099 | .dpd_status = 0x1bc, |
| 2100 | .dpd2_req = 0x1c0, |
| 2101 | .dpd2_status = 0x1c4, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2102 | .rst_status = 0x1b4, |
| 2103 | .rst_source_shift = 0x0, |
| 2104 | .rst_source_mask = 0x7, |
| 2105 | .rst_level_shift = 0x0, |
| 2106 | .rst_level_mask = 0x0, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2107 | }; |
| 2108 | |
| 2109 | static void tegra20_pmc_init(struct tegra_pmc *pmc) |
| 2110 | { |
| 2111 | u32 value; |
| 2112 | |
| 2113 | /* Always enable CPU power request */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2114 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2115 | value |= PMC_CNTRL_CPU_PWRREQ_OE; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2116 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2117 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2118 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2119 | |
| 2120 | if (pmc->sysclkreq_high) |
| 2121 | value &= ~PMC_CNTRL_SYSCLK_POLARITY; |
| 2122 | else |
| 2123 | value |= PMC_CNTRL_SYSCLK_POLARITY; |
| 2124 | |
| 2125 | /* configure the output polarity while the request is tristated */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2126 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2127 | |
| 2128 | /* now enable the request */ |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2129 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2130 | value |= PMC_CNTRL_SYSCLK_OE; |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2131 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc, |
| 2135 | struct device_node *np, |
| 2136 | bool invert) |
| 2137 | { |
| 2138 | u32 value; |
| 2139 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2140 | value = tegra_pmc_readl(pmc, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2141 | |
| 2142 | if (invert) |
| 2143 | value |= PMC_CNTRL_INTR_POLARITY; |
| 2144 | else |
| 2145 | value &= ~PMC_CNTRL_INTR_POLARITY; |
| 2146 | |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2147 | tegra_pmc_writel(pmc, value, PMC_CNTRL); |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2150 | static const struct tegra_pmc_soc tegra20_pmc_soc = { |
| 2151 | .num_powergates = ARRAY_SIZE(tegra20_powergates), |
| 2152 | .powergates = tegra20_powergates, |
| 2153 | .num_cpu_powergates = 0, |
| 2154 | .cpu_powergates = NULL, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2155 | .has_tsense_reset = false, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 2156 | .has_gpu_clamps = false, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2157 | .needs_mbist_war = false, |
| 2158 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2159 | .maybe_tz_only = false, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2160 | .num_io_pads = 0, |
| 2161 | .io_pads = NULL, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2162 | .num_pin_descs = 0, |
| 2163 | .pin_descs = NULL, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2164 | .regs = &tegra20_pmc_regs, |
| 2165 | .init = tegra20_pmc_init, |
| 2166 | .setup_irq_polarity = tegra20_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2167 | .reset_sources = NULL, |
| 2168 | .num_reset_sources = 0, |
| 2169 | .reset_levels = NULL, |
| 2170 | .num_reset_levels = 0, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2171 | }; |
| 2172 | |
| 2173 | static const char * const tegra30_powergates[] = { |
| 2174 | [TEGRA_POWERGATE_CPU] = "cpu0", |
| 2175 | [TEGRA_POWERGATE_3D] = "3d0", |
| 2176 | [TEGRA_POWERGATE_VENC] = "venc", |
| 2177 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 2178 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 2179 | [TEGRA_POWERGATE_L2] = "l2", |
| 2180 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 2181 | [TEGRA_POWERGATE_HEG] = "heg", |
| 2182 | [TEGRA_POWERGATE_SATA] = "sata", |
| 2183 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 2184 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 2185 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 2186 | [TEGRA_POWERGATE_CELP] = "celp", |
| 2187 | [TEGRA_POWERGATE_3D1] = "3d1", |
| 2188 | }; |
| 2189 | |
| 2190 | static const u8 tegra30_cpu_powergates[] = { |
| 2191 | TEGRA_POWERGATE_CPU, |
| 2192 | TEGRA_POWERGATE_CPU1, |
| 2193 | TEGRA_POWERGATE_CPU2, |
| 2194 | TEGRA_POWERGATE_CPU3, |
| 2195 | }; |
| 2196 | |
| 2197 | static const struct tegra_pmc_soc tegra30_pmc_soc = { |
| 2198 | .num_powergates = ARRAY_SIZE(tegra30_powergates), |
| 2199 | .powergates = tegra30_powergates, |
| 2200 | .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates), |
| 2201 | .cpu_powergates = tegra30_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2202 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 2203 | .has_gpu_clamps = false, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2204 | .needs_mbist_war = false, |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 2205 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2206 | .maybe_tz_only = false, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2207 | .num_io_pads = 0, |
| 2208 | .io_pads = NULL, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2209 | .num_pin_descs = 0, |
| 2210 | .pin_descs = NULL, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2211 | .regs = &tegra20_pmc_regs, |
| 2212 | .init = tegra20_pmc_init, |
| 2213 | .setup_irq_polarity = tegra20_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2214 | .reset_sources = tegra30_reset_sources, |
| 2215 | .num_reset_sources = 5, |
| 2216 | .reset_levels = NULL, |
| 2217 | .num_reset_levels = 0, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | static const char * const tegra114_powergates[] = { |
| 2221 | [TEGRA_POWERGATE_CPU] = "crail", |
| 2222 | [TEGRA_POWERGATE_3D] = "3d", |
| 2223 | [TEGRA_POWERGATE_VENC] = "venc", |
| 2224 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 2225 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 2226 | [TEGRA_POWERGATE_HEG] = "heg", |
| 2227 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 2228 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 2229 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 2230 | [TEGRA_POWERGATE_CELP] = "celp", |
| 2231 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 2232 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
| 2233 | [TEGRA_POWERGATE_C1NC] = "c1nc", |
| 2234 | [TEGRA_POWERGATE_DIS] = "dis", |
| 2235 | [TEGRA_POWERGATE_DISB] = "disb", |
| 2236 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 2237 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 2238 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 2239 | }; |
| 2240 | |
| 2241 | static const u8 tegra114_cpu_powergates[] = { |
| 2242 | TEGRA_POWERGATE_CPU0, |
| 2243 | TEGRA_POWERGATE_CPU1, |
| 2244 | TEGRA_POWERGATE_CPU2, |
| 2245 | TEGRA_POWERGATE_CPU3, |
| 2246 | }; |
| 2247 | |
| 2248 | static const struct tegra_pmc_soc tegra114_pmc_soc = { |
| 2249 | .num_powergates = ARRAY_SIZE(tegra114_powergates), |
| 2250 | .powergates = tegra114_powergates, |
| 2251 | .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates), |
| 2252 | .cpu_powergates = tegra114_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2253 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 2254 | .has_gpu_clamps = false, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2255 | .needs_mbist_war = false, |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 2256 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2257 | .maybe_tz_only = false, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2258 | .num_io_pads = 0, |
| 2259 | .io_pads = NULL, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2260 | .num_pin_descs = 0, |
| 2261 | .pin_descs = NULL, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2262 | .regs = &tegra20_pmc_regs, |
| 2263 | .init = tegra20_pmc_init, |
| 2264 | .setup_irq_polarity = tegra20_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2265 | .reset_sources = tegra30_reset_sources, |
| 2266 | .num_reset_sources = 5, |
| 2267 | .reset_levels = NULL, |
| 2268 | .num_reset_levels = 0, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2269 | }; |
| 2270 | |
| 2271 | static const char * const tegra124_powergates[] = { |
| 2272 | [TEGRA_POWERGATE_CPU] = "crail", |
| 2273 | [TEGRA_POWERGATE_3D] = "3d", |
| 2274 | [TEGRA_POWERGATE_VENC] = "venc", |
| 2275 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 2276 | [TEGRA_POWERGATE_VDEC] = "vdec", |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2277 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 2278 | [TEGRA_POWERGATE_HEG] = "heg", |
| 2279 | [TEGRA_POWERGATE_SATA] = "sata", |
| 2280 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 2281 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 2282 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 2283 | [TEGRA_POWERGATE_CELP] = "celp", |
| 2284 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 2285 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
| 2286 | [TEGRA_POWERGATE_C1NC] = "c1nc", |
| 2287 | [TEGRA_POWERGATE_SOR] = "sor", |
| 2288 | [TEGRA_POWERGATE_DIS] = "dis", |
| 2289 | [TEGRA_POWERGATE_DISB] = "disb", |
| 2290 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 2291 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 2292 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 2293 | [TEGRA_POWERGATE_VIC] = "vic", |
| 2294 | [TEGRA_POWERGATE_IRAM] = "iram", |
| 2295 | }; |
| 2296 | |
| 2297 | static const u8 tegra124_cpu_powergates[] = { |
| 2298 | TEGRA_POWERGATE_CPU0, |
| 2299 | TEGRA_POWERGATE_CPU1, |
| 2300 | TEGRA_POWERGATE_CPU2, |
| 2301 | TEGRA_POWERGATE_CPU3, |
| 2302 | }; |
| 2303 | |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2304 | #define TEGRA_IO_PAD(_id, _dpd, _voltage, _name) \ |
| 2305 | ((struct tegra_io_pad_soc) { \ |
| 2306 | .id = (_id), \ |
| 2307 | .dpd = (_dpd), \ |
| 2308 | .voltage = (_voltage), \ |
| 2309 | .name = (_name), \ |
| 2310 | }) |
| 2311 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2312 | #define TEGRA_IO_PIN_DESC(_id, _dpd, _voltage, _name) \ |
| 2313 | ((struct pinctrl_pin_desc) { \ |
| 2314 | .number = (_id), \ |
| 2315 | .name = (_name) \ |
| 2316 | }) |
| 2317 | |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2318 | #define TEGRA124_IO_PAD_TABLE(_pad) \ |
| 2319 | /* .id .dpd .voltage .name */ \ |
| 2320 | _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \ |
| 2321 | _pad(TEGRA_IO_PAD_BB, 15, UINT_MAX, "bb"), \ |
| 2322 | _pad(TEGRA_IO_PAD_CAM, 36, UINT_MAX, "cam"), \ |
| 2323 | _pad(TEGRA_IO_PAD_COMP, 22, UINT_MAX, "comp"), \ |
| 2324 | _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \ |
| 2325 | _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csb"), \ |
| 2326 | _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "cse"), \ |
| 2327 | _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \ |
| 2328 | _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \ |
| 2329 | _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \ |
| 2330 | _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \ |
| 2331 | _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \ |
| 2332 | _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \ |
| 2333 | _pad(TEGRA_IO_PAD_HV, 38, UINT_MAX, "hv"), \ |
| 2334 | _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \ |
| 2335 | _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \ |
| 2336 | _pad(TEGRA_IO_PAD_NAND, 13, UINT_MAX, "nand"), \ |
| 2337 | _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \ |
| 2338 | _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \ |
| 2339 | _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \ |
| 2340 | _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \ |
| 2341 | _pad(TEGRA_IO_PAD_SDMMC1, 33, UINT_MAX, "sdmmc1"), \ |
| 2342 | _pad(TEGRA_IO_PAD_SDMMC3, 34, UINT_MAX, "sdmmc3"), \ |
| 2343 | _pad(TEGRA_IO_PAD_SDMMC4, 35, UINT_MAX, "sdmmc4"), \ |
| 2344 | _pad(TEGRA_IO_PAD_SYS_DDC, 58, UINT_MAX, "sys_ddc"), \ |
| 2345 | _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \ |
| 2346 | _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \ |
| 2347 | _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \ |
| 2348 | _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \ |
| 2349 | _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb_bias") |
| 2350 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2351 | static const struct tegra_io_pad_soc tegra124_io_pads[] = { |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2352 | TEGRA124_IO_PAD_TABLE(TEGRA_IO_PAD) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2353 | }; |
| 2354 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2355 | static const struct pinctrl_pin_desc tegra124_pin_descs[] = { |
| 2356 | TEGRA124_IO_PAD_TABLE(TEGRA_IO_PIN_DESC) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2357 | }; |
| 2358 | |
| 2359 | static const struct tegra_pmc_soc tegra124_pmc_soc = { |
| 2360 | .num_powergates = ARRAY_SIZE(tegra124_powergates), |
| 2361 | .powergates = tegra124_powergates, |
| 2362 | .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates), |
| 2363 | .cpu_powergates = tegra124_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 2364 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 2365 | .has_gpu_clamps = true, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2366 | .needs_mbist_war = false, |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 2367 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2368 | .maybe_tz_only = false, |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2369 | .num_io_pads = ARRAY_SIZE(tegra124_io_pads), |
| 2370 | .io_pads = tegra124_io_pads, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2371 | .num_pin_descs = ARRAY_SIZE(tegra124_pin_descs), |
| 2372 | .pin_descs = tegra124_pin_descs, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2373 | .regs = &tegra20_pmc_regs, |
| 2374 | .init = tegra20_pmc_init, |
| 2375 | .setup_irq_polarity = tegra20_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2376 | .reset_sources = tegra30_reset_sources, |
| 2377 | .num_reset_sources = 5, |
| 2378 | .reset_levels = NULL, |
| 2379 | .num_reset_levels = 0, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2380 | }; |
| 2381 | |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2382 | static const char * const tegra210_powergates[] = { |
| 2383 | [TEGRA_POWERGATE_CPU] = "crail", |
| 2384 | [TEGRA_POWERGATE_3D] = "3d", |
| 2385 | [TEGRA_POWERGATE_VENC] = "venc", |
| 2386 | [TEGRA_POWERGATE_PCIE] = "pcie", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2387 | [TEGRA_POWERGATE_MPE] = "mpe", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2388 | [TEGRA_POWERGATE_SATA] = "sata", |
| 2389 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 2390 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 2391 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2392 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 2393 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2394 | [TEGRA_POWERGATE_SOR] = "sor", |
| 2395 | [TEGRA_POWERGATE_DIS] = "dis", |
| 2396 | [TEGRA_POWERGATE_DISB] = "disb", |
| 2397 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 2398 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 2399 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 2400 | [TEGRA_POWERGATE_VIC] = "vic", |
| 2401 | [TEGRA_POWERGATE_IRAM] = "iram", |
| 2402 | [TEGRA_POWERGATE_NVDEC] = "nvdec", |
| 2403 | [TEGRA_POWERGATE_NVJPG] = "nvjpg", |
| 2404 | [TEGRA_POWERGATE_AUD] = "aud", |
| 2405 | [TEGRA_POWERGATE_DFD] = "dfd", |
| 2406 | [TEGRA_POWERGATE_VE2] = "ve2", |
| 2407 | }; |
| 2408 | |
| 2409 | static const u8 tegra210_cpu_powergates[] = { |
| 2410 | TEGRA_POWERGATE_CPU0, |
| 2411 | TEGRA_POWERGATE_CPU1, |
| 2412 | TEGRA_POWERGATE_CPU2, |
| 2413 | TEGRA_POWERGATE_CPU3, |
| 2414 | }; |
| 2415 | |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2416 | #define TEGRA210_IO_PAD_TABLE(_pad) \ |
| 2417 | /* .id .dpd .voltage .name */ \ |
| 2418 | _pad(TEGRA_IO_PAD_AUDIO, 17, 5, "audio"), \ |
| 2419 | _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 18, "audio-hv"), \ |
| 2420 | _pad(TEGRA_IO_PAD_CAM, 36, 10, "cam"), \ |
| 2421 | _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \ |
| 2422 | _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \ |
| 2423 | _pad(TEGRA_IO_PAD_CSIC, 42, UINT_MAX, "csic"), \ |
| 2424 | _pad(TEGRA_IO_PAD_CSID, 43, UINT_MAX, "csid"), \ |
| 2425 | _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "csie"), \ |
| 2426 | _pad(TEGRA_IO_PAD_CSIF, 45, UINT_MAX, "csif"), \ |
| 2427 | _pad(TEGRA_IO_PAD_DBG, 25, 19, "dbg"), \ |
| 2428 | _pad(TEGRA_IO_PAD_DEBUG_NONAO, 26, UINT_MAX, "debug-nonao"), \ |
| 2429 | _pad(TEGRA_IO_PAD_DMIC, 50, 20, "dmic"), \ |
| 2430 | _pad(TEGRA_IO_PAD_DP, 51, UINT_MAX, "dp"), \ |
| 2431 | _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \ |
| 2432 | _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \ |
| 2433 | _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \ |
| 2434 | _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \ |
| 2435 | _pad(TEGRA_IO_PAD_EMMC, 35, UINT_MAX, "emmc"), \ |
| 2436 | _pad(TEGRA_IO_PAD_EMMC2, 37, UINT_MAX, "emmc2"), \ |
| 2437 | _pad(TEGRA_IO_PAD_GPIO, 27, 21, "gpio"), \ |
| 2438 | _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \ |
| 2439 | _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \ |
| 2440 | _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \ |
| 2441 | _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \ |
| 2442 | _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \ |
| 2443 | _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \ |
| 2444 | _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \ |
| 2445 | _pad(TEGRA_IO_PAD_PEX_CNTRL, UINT_MAX, 11, "pex-cntrl"), \ |
| 2446 | _pad(TEGRA_IO_PAD_SDMMC1, 33, 12, "sdmmc1"), \ |
| 2447 | _pad(TEGRA_IO_PAD_SDMMC3, 34, 13, "sdmmc3"), \ |
| 2448 | _pad(TEGRA_IO_PAD_SPI, 46, 22, "spi"), \ |
| 2449 | _pad(TEGRA_IO_PAD_SPI_HV, 47, 23, "spi-hv"), \ |
| 2450 | _pad(TEGRA_IO_PAD_UART, 14, 2, "uart"), \ |
| 2451 | _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \ |
| 2452 | _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \ |
| 2453 | _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \ |
| 2454 | _pad(TEGRA_IO_PAD_USB3, 18, UINT_MAX, "usb3"), \ |
| 2455 | _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias") |
| 2456 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2457 | static const struct tegra_io_pad_soc tegra210_io_pads[] = { |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2458 | TEGRA210_IO_PAD_TABLE(TEGRA_IO_PAD) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2459 | }; |
| 2460 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2461 | static const struct pinctrl_pin_desc tegra210_pin_descs[] = { |
| 2462 | TEGRA210_IO_PAD_TABLE(TEGRA_IO_PIN_DESC) |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2463 | }; |
| 2464 | |
| 2465 | static const struct tegra_pmc_soc tegra210_pmc_soc = { |
| 2466 | .num_powergates = ARRAY_SIZE(tegra210_powergates), |
| 2467 | .powergates = tegra210_powergates, |
| 2468 | .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates), |
| 2469 | .cpu_powergates = tegra210_cpu_powergates, |
| 2470 | .has_tsense_reset = true, |
| 2471 | .has_gpu_clamps = true, |
Peter De Schrijver | a263394a | 2018-01-25 16:00:13 +0200 | [diff] [blame] | 2472 | .needs_mbist_war = true, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2473 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2474 | .maybe_tz_only = true, |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 2475 | .num_io_pads = ARRAY_SIZE(tegra210_io_pads), |
| 2476 | .io_pads = tegra210_io_pads, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2477 | .num_pin_descs = ARRAY_SIZE(tegra210_pin_descs), |
| 2478 | .pin_descs = tegra210_pin_descs, |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2479 | .regs = &tegra20_pmc_regs, |
| 2480 | .init = tegra20_pmc_init, |
| 2481 | .setup_irq_polarity = tegra20_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2482 | .reset_sources = tegra30_reset_sources, |
| 2483 | .num_reset_sources = 5, |
| 2484 | .reset_levels = NULL, |
| 2485 | .num_reset_levels = 0, |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2486 | }; |
| 2487 | |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2488 | #define TEGRA186_IO_PAD_TABLE(_pad) \ |
| 2489 | /* .id .dpd .voltage .name */ \ |
| 2490 | _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \ |
| 2491 | _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \ |
| 2492 | _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \ |
| 2493 | _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \ |
| 2494 | _pad(TEGRA_IO_PAD_PEX_CLK_BIAS, 4, UINT_MAX, "pex-clk-bias"), \ |
| 2495 | _pad(TEGRA_IO_PAD_PEX_CLK3, 5, UINT_MAX, "pex-clk3"), \ |
| 2496 | _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \ |
| 2497 | _pad(TEGRA_IO_PAD_PEX_CLK1, 7, UINT_MAX, "pex-clk1"), \ |
| 2498 | _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \ |
| 2499 | _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \ |
| 2500 | _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \ |
| 2501 | _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias"), \ |
| 2502 | _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \ |
| 2503 | _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \ |
| 2504 | _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \ |
| 2505 | _pad(TEGRA_IO_PAD_DBG, 25, UINT_MAX, "dbg"), \ |
| 2506 | _pad(TEGRA_IO_PAD_HDMI_DP0, 28, UINT_MAX, "hdmi-dp0"), \ |
| 2507 | _pad(TEGRA_IO_PAD_HDMI_DP1, 29, UINT_MAX, "hdmi-dp1"), \ |
| 2508 | _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \ |
| 2509 | _pad(TEGRA_IO_PAD_SDMMC2_HV, 34, 5, "sdmmc2-hv"), \ |
| 2510 | _pad(TEGRA_IO_PAD_SDMMC4, 36, UINT_MAX, "sdmmc4"), \ |
| 2511 | _pad(TEGRA_IO_PAD_CAM, 38, UINT_MAX, "cam"), \ |
| 2512 | _pad(TEGRA_IO_PAD_DSIB, 40, UINT_MAX, "dsib"), \ |
| 2513 | _pad(TEGRA_IO_PAD_DSIC, 41, UINT_MAX, "dsic"), \ |
| 2514 | _pad(TEGRA_IO_PAD_DSID, 42, UINT_MAX, "dsid"), \ |
| 2515 | _pad(TEGRA_IO_PAD_CSIC, 43, UINT_MAX, "csic"), \ |
| 2516 | _pad(TEGRA_IO_PAD_CSID, 44, UINT_MAX, "csid"), \ |
| 2517 | _pad(TEGRA_IO_PAD_CSIE, 45, UINT_MAX, "csie"), \ |
| 2518 | _pad(TEGRA_IO_PAD_CSIF, 46, UINT_MAX, "csif"), \ |
| 2519 | _pad(TEGRA_IO_PAD_SPI, 47, UINT_MAX, "spi"), \ |
| 2520 | _pad(TEGRA_IO_PAD_UFS, 49, UINT_MAX, "ufs"), \ |
| 2521 | _pad(TEGRA_IO_PAD_DMIC_HV, 52, 2, "dmic-hv"), \ |
| 2522 | _pad(TEGRA_IO_PAD_EDP, 53, UINT_MAX, "edp"), \ |
| 2523 | _pad(TEGRA_IO_PAD_SDMMC1_HV, 55, 4, "sdmmc1-hv"), \ |
| 2524 | _pad(TEGRA_IO_PAD_SDMMC3_HV, 56, 6, "sdmmc3-hv"), \ |
| 2525 | _pad(TEGRA_IO_PAD_CONN, 60, UINT_MAX, "conn"), \ |
| 2526 | _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 1, "audio-hv"), \ |
| 2527 | _pad(TEGRA_IO_PAD_AO_HV, UINT_MAX, 0, "ao-hv") |
| 2528 | |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2529 | static const struct tegra_io_pad_soc tegra186_io_pads[] = { |
Aapo Vienamo | 437c4f2 | 2018-08-10 21:08:10 +0300 | [diff] [blame] | 2530 | TEGRA186_IO_PAD_TABLE(TEGRA_IO_PAD) |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2531 | }; |
| 2532 | |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2533 | static const struct pinctrl_pin_desc tegra186_pin_descs[] = { |
| 2534 | TEGRA186_IO_PAD_TABLE(TEGRA_IO_PIN_DESC) |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2535 | }; |
| 2536 | |
| 2537 | static const struct tegra_pmc_regs tegra186_pmc_regs = { |
| 2538 | .scratch0 = 0x2000, |
| 2539 | .dpd_req = 0x74, |
| 2540 | .dpd_status = 0x78, |
| 2541 | .dpd2_req = 0x7c, |
| 2542 | .dpd2_status = 0x80, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2543 | .rst_status = 0x70, |
| 2544 | .rst_source_shift = 0x2, |
| 2545 | .rst_source_mask = 0x3C, |
| 2546 | .rst_level_shift = 0x0, |
| 2547 | .rst_level_mask = 0x3, |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2548 | }; |
| 2549 | |
| 2550 | static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc, |
| 2551 | struct device_node *np, |
| 2552 | bool invert) |
| 2553 | { |
| 2554 | struct resource regs; |
| 2555 | void __iomem *wake; |
| 2556 | u32 value; |
| 2557 | int index; |
| 2558 | |
| 2559 | index = of_property_match_string(np, "reg-names", "wake"); |
| 2560 | if (index < 0) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2561 | dev_err(pmc->dev, "failed to find PMC wake registers\n"); |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2562 | return; |
| 2563 | } |
| 2564 | |
| 2565 | of_address_to_resource(np, index, ®s); |
| 2566 | |
| 2567 | wake = ioremap_nocache(regs.start, resource_size(®s)); |
| 2568 | if (!wake) { |
Thierry Reding | 589997a | 2019-01-25 11:22:52 +0100 | [diff] [blame] | 2569 | dev_err(pmc->dev, "failed to map PMC wake registers\n"); |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2570 | return; |
| 2571 | } |
| 2572 | |
| 2573 | value = readl(wake + WAKE_AOWAKE_CTRL); |
| 2574 | |
| 2575 | if (invert) |
| 2576 | value |= WAKE_AOWAKE_CTRL_INTR_POLARITY; |
| 2577 | else |
| 2578 | value &= ~WAKE_AOWAKE_CTRL_INTR_POLARITY; |
| 2579 | |
| 2580 | writel(value, wake + WAKE_AOWAKE_CTRL); |
| 2581 | |
| 2582 | iounmap(wake); |
| 2583 | } |
| 2584 | |
Thierry Reding | e59333c | 2018-09-19 18:41:59 +0200 | [diff] [blame] | 2585 | static const struct tegra_wake_event tegra186_wake_events[] = { |
Thierry Reding | 532700e | 2019-01-23 12:38:43 +0100 | [diff] [blame] | 2586 | TEGRA_WAKE_GPIO("power", 29, 1, TEGRA186_AON_GPIO(FF, 0)), |
Thierry Reding | e59333c | 2018-09-19 18:41:59 +0200 | [diff] [blame] | 2587 | TEGRA_WAKE_IRQ("rtc", 73, 10), |
| 2588 | }; |
| 2589 | |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2590 | static const struct tegra_pmc_soc tegra186_pmc_soc = { |
| 2591 | .num_powergates = 0, |
| 2592 | .powergates = NULL, |
| 2593 | .num_cpu_powergates = 0, |
| 2594 | .cpu_powergates = NULL, |
| 2595 | .has_tsense_reset = false, |
| 2596 | .has_gpu_clamps = false, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2597 | .needs_mbist_war = false, |
Aapo Vienamo | 13136a4 | 2018-08-10 21:08:07 +0300 | [diff] [blame] | 2598 | .has_impl_33v_pwr = true, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2599 | .maybe_tz_only = false, |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2600 | .num_io_pads = ARRAY_SIZE(tegra186_io_pads), |
| 2601 | .io_pads = tegra186_io_pads, |
Aapo Vienamo | 4a37f11 | 2018-08-10 21:08:12 +0300 | [diff] [blame] | 2602 | .num_pin_descs = ARRAY_SIZE(tegra186_pin_descs), |
| 2603 | .pin_descs = tegra186_pin_descs, |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2604 | .regs = &tegra186_pmc_regs, |
| 2605 | .init = NULL, |
| 2606 | .setup_irq_polarity = tegra186_pmc_setup_irq_polarity, |
Sandipan Patra | 5f84bb1 | 2018-10-24 12:38:00 +0530 | [diff] [blame] | 2607 | .reset_sources = tegra186_reset_sources, |
| 2608 | .num_reset_sources = 14, |
| 2609 | .reset_levels = tegra186_reset_levels, |
| 2610 | .num_reset_levels = 3, |
Thierry Reding | e59333c | 2018-09-19 18:41:59 +0200 | [diff] [blame] | 2611 | .num_wake_events = ARRAY_SIZE(tegra186_wake_events), |
| 2612 | .wake_events = tegra186_wake_events, |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2613 | }; |
| 2614 | |
Thierry Reding | eac9c48 | 2018-01-25 14:43:45 +0200 | [diff] [blame] | 2615 | static const struct tegra_io_pad_soc tegra194_io_pads[] = { |
| 2616 | { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX }, |
| 2617 | { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX }, |
| 2618 | { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX }, |
| 2619 | { .id = TEGRA_IO_PAD_PEX_CLK_BIAS, .dpd = 4, .voltage = UINT_MAX }, |
| 2620 | { .id = TEGRA_IO_PAD_PEX_CLK3, .dpd = 5, .voltage = UINT_MAX }, |
| 2621 | { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX }, |
| 2622 | { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 7, .voltage = UINT_MAX }, |
| 2623 | { .id = TEGRA_IO_PAD_EQOS, .dpd = 8, .voltage = UINT_MAX }, |
| 2624 | { .id = TEGRA_IO_PAD_PEX_CLK2_BIAS, .dpd = 9, .voltage = UINT_MAX }, |
| 2625 | { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 10, .voltage = UINT_MAX }, |
| 2626 | { .id = TEGRA_IO_PAD_DAP3, .dpd = 11, .voltage = UINT_MAX }, |
| 2627 | { .id = TEGRA_IO_PAD_DAP5, .dpd = 12, .voltage = UINT_MAX }, |
| 2628 | { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = UINT_MAX }, |
| 2629 | { .id = TEGRA_IO_PAD_PWR_CTL, .dpd = 15, .voltage = UINT_MAX }, |
| 2630 | { .id = TEGRA_IO_PAD_SOC_GPIO53, .dpd = 16, .voltage = UINT_MAX }, |
| 2631 | { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = UINT_MAX }, |
| 2632 | { .id = TEGRA_IO_PAD_GP_PWM2, .dpd = 18, .voltage = UINT_MAX }, |
| 2633 | { .id = TEGRA_IO_PAD_GP_PWM3, .dpd = 19, .voltage = UINT_MAX }, |
| 2634 | { .id = TEGRA_IO_PAD_SOC_GPIO12, .dpd = 20, .voltage = UINT_MAX }, |
| 2635 | { .id = TEGRA_IO_PAD_SOC_GPIO13, .dpd = 21, .voltage = UINT_MAX }, |
| 2636 | { .id = TEGRA_IO_PAD_SOC_GPIO10, .dpd = 22, .voltage = UINT_MAX }, |
| 2637 | { .id = TEGRA_IO_PAD_UART4, .dpd = 23, .voltage = UINT_MAX }, |
| 2638 | { .id = TEGRA_IO_PAD_UART5, .dpd = 24, .voltage = UINT_MAX }, |
| 2639 | { .id = TEGRA_IO_PAD_DBG, .dpd = 25, .voltage = UINT_MAX }, |
| 2640 | { .id = TEGRA_IO_PAD_HDMI_DP3, .dpd = 26, .voltage = UINT_MAX }, |
| 2641 | { .id = TEGRA_IO_PAD_HDMI_DP2, .dpd = 27, .voltage = UINT_MAX }, |
| 2642 | { .id = TEGRA_IO_PAD_HDMI_DP0, .dpd = 28, .voltage = UINT_MAX }, |
| 2643 | { .id = TEGRA_IO_PAD_HDMI_DP1, .dpd = 29, .voltage = UINT_MAX }, |
| 2644 | { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = 32, .voltage = UINT_MAX }, |
| 2645 | { .id = TEGRA_IO_PAD_PEX_CTL2, .dpd = 33, .voltage = UINT_MAX }, |
| 2646 | { .id = TEGRA_IO_PAD_PEX_L0_RST_N, .dpd = 34, .voltage = UINT_MAX }, |
| 2647 | { .id = TEGRA_IO_PAD_PEX_L1_RST_N, .dpd = 35, .voltage = UINT_MAX }, |
| 2648 | { .id = TEGRA_IO_PAD_SDMMC4, .dpd = 36, .voltage = UINT_MAX }, |
| 2649 | { .id = TEGRA_IO_PAD_PEX_L5_RST_N, .dpd = 37, .voltage = UINT_MAX }, |
| 2650 | { .id = TEGRA_IO_PAD_CSIC, .dpd = 43, .voltage = UINT_MAX }, |
| 2651 | { .id = TEGRA_IO_PAD_CSID, .dpd = 44, .voltage = UINT_MAX }, |
| 2652 | { .id = TEGRA_IO_PAD_CSIE, .dpd = 45, .voltage = UINT_MAX }, |
| 2653 | { .id = TEGRA_IO_PAD_CSIF, .dpd = 46, .voltage = UINT_MAX }, |
| 2654 | { .id = TEGRA_IO_PAD_SPI, .dpd = 47, .voltage = UINT_MAX }, |
| 2655 | { .id = TEGRA_IO_PAD_UFS, .dpd = 49, .voltage = UINT_MAX }, |
| 2656 | { .id = TEGRA_IO_PAD_CSIG, .dpd = 50, .voltage = UINT_MAX }, |
| 2657 | { .id = TEGRA_IO_PAD_CSIH, .dpd = 51, .voltage = UINT_MAX }, |
| 2658 | { .id = TEGRA_IO_PAD_EDP, .dpd = 53, .voltage = UINT_MAX }, |
| 2659 | { .id = TEGRA_IO_PAD_SDMMC1_HV, .dpd = 55, .voltage = UINT_MAX }, |
| 2660 | { .id = TEGRA_IO_PAD_SDMMC3_HV, .dpd = 56, .voltage = UINT_MAX }, |
| 2661 | { .id = TEGRA_IO_PAD_CONN, .dpd = 60, .voltage = UINT_MAX }, |
| 2662 | { .id = TEGRA_IO_PAD_AUDIO_HV, .dpd = 61, .voltage = UINT_MAX }, |
| 2663 | }; |
| 2664 | |
Thierry Reding | e3e403c | 2018-09-19 18:42:37 +0200 | [diff] [blame] | 2665 | static const struct tegra_wake_event tegra194_wake_events[] = { |
| 2666 | TEGRA_WAKE_GPIO("power", 29, 1, TEGRA194_AON_GPIO(EE, 4)), |
| 2667 | TEGRA_WAKE_IRQ("rtc", 73, 10), |
| 2668 | }; |
| 2669 | |
Thierry Reding | eac9c48 | 2018-01-25 14:43:45 +0200 | [diff] [blame] | 2670 | static const struct tegra_pmc_soc tegra194_pmc_soc = { |
| 2671 | .num_powergates = 0, |
| 2672 | .powergates = NULL, |
| 2673 | .num_cpu_powergates = 0, |
| 2674 | .cpu_powergates = NULL, |
| 2675 | .has_tsense_reset = false, |
| 2676 | .has_gpu_clamps = false, |
Thierry Reding | fa3bc04 | 2019-01-25 11:22:54 +0100 | [diff] [blame] | 2677 | .needs_mbist_war = false, |
| 2678 | .has_impl_33v_pwr = false, |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2679 | .maybe_tz_only = false, |
Thierry Reding | eac9c48 | 2018-01-25 14:43:45 +0200 | [diff] [blame] | 2680 | .num_io_pads = ARRAY_SIZE(tegra194_io_pads), |
| 2681 | .io_pads = tegra194_io_pads, |
| 2682 | .regs = &tegra186_pmc_regs, |
| 2683 | .init = NULL, |
| 2684 | .setup_irq_polarity = tegra186_pmc_setup_irq_polarity, |
Thierry Reding | e3e403c | 2018-09-19 18:42:37 +0200 | [diff] [blame] | 2685 | .num_wake_events = ARRAY_SIZE(tegra194_wake_events), |
| 2686 | .wake_events = tegra194_wake_events, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2687 | }; |
| 2688 | |
| 2689 | static const struct of_device_id tegra_pmc_match[] = { |
Thierry Reding | eac9c48 | 2018-01-25 14:43:45 +0200 | [diff] [blame] | 2690 | { .compatible = "nvidia,tegra194-pmc", .data = &tegra194_pmc_soc }, |
Thierry Reding | c641ec6 | 2017-08-30 12:42:34 +0200 | [diff] [blame] | 2691 | { .compatible = "nvidia,tegra186-pmc", .data = &tegra186_pmc_soc }, |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 2692 | { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc }, |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2693 | { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc }, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2694 | { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc }, |
| 2695 | { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc }, |
| 2696 | { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc }, |
| 2697 | { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc }, |
| 2698 | { } |
| 2699 | }; |
| 2700 | |
| 2701 | static struct platform_driver tegra_pmc_driver = { |
| 2702 | .driver = { |
| 2703 | .name = "tegra-pmc", |
| 2704 | .suppress_bind_attrs = true, |
| 2705 | .of_match_table = tegra_pmc_match, |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 2706 | #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2707 | .pm = &tegra_pmc_pm_ops, |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 2708 | #endif |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2709 | }, |
| 2710 | .probe = tegra_pmc_probe, |
| 2711 | }; |
Paul Gortmaker | 7d4d9ed | 2015-05-01 20:10:57 -0400 | [diff] [blame] | 2712 | builtin_platform_driver(tegra_pmc_driver); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2713 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2714 | static bool __init tegra_pmc_detect_tz_only(struct tegra_pmc *pmc) |
| 2715 | { |
| 2716 | u32 value, saved; |
| 2717 | |
| 2718 | saved = readl(pmc->base + pmc->soc->regs->scratch0); |
| 2719 | value = saved ^ 0xffffffff; |
| 2720 | |
| 2721 | if (value == 0xffffffff) |
| 2722 | value = 0xdeadbeef; |
| 2723 | |
| 2724 | /* write pattern and read it back */ |
| 2725 | writel(value, pmc->base + pmc->soc->regs->scratch0); |
| 2726 | value = readl(pmc->base + pmc->soc->regs->scratch0); |
| 2727 | |
| 2728 | /* if we read all-zeroes, access is restricted to TZ only */ |
| 2729 | if (value == 0) { |
| 2730 | pr_info("access to PMC is restricted to TZ\n"); |
| 2731 | return true; |
| 2732 | } |
| 2733 | |
| 2734 | /* restore original value */ |
| 2735 | writel(saved, pmc->base + pmc->soc->regs->scratch0); |
| 2736 | |
| 2737 | return false; |
| 2738 | } |
| 2739 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2740 | /* |
| 2741 | * Early initialization to allow access to registers in the very early boot |
| 2742 | * process. |
| 2743 | */ |
| 2744 | static int __init tegra_pmc_early_init(void) |
| 2745 | { |
| 2746 | const struct of_device_id *match; |
| 2747 | struct device_node *np; |
| 2748 | struct resource regs; |
| 2749 | bool invert; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2750 | |
Jon Hunter | 61fd284 | 2016-06-28 11:38:26 +0100 | [diff] [blame] | 2751 | mutex_init(&pmc->powergates_lock); |
| 2752 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2753 | np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match); |
| 2754 | if (!np) { |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2755 | /* |
| 2756 | * Fall back to legacy initialization for 32-bit ARM only. All |
| 2757 | * 64-bit ARM device tree files for Tegra are required to have |
| 2758 | * a PMC node. |
| 2759 | * |
| 2760 | * This is for backwards-compatibility with old device trees |
| 2761 | * that didn't contain a PMC node. Note that in this case the |
| 2762 | * SoC data can't be matched and therefore powergating is |
| 2763 | * disabled. |
| 2764 | */ |
| 2765 | if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) { |
| 2766 | pr_warn("DT node not found, powergating disabled\n"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2767 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2768 | regs.start = 0x7000e400; |
| 2769 | regs.end = 0x7000e7ff; |
| 2770 | regs.flags = IORESOURCE_MEM; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2771 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2772 | pr_warn("Using memory region %pR\n", ®s); |
| 2773 | } else { |
| 2774 | /* |
| 2775 | * At this point we're not running on Tegra, so play |
| 2776 | * nice with multi-platform kernels. |
| 2777 | */ |
| 2778 | return 0; |
| 2779 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2780 | } else { |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2781 | /* |
| 2782 | * Extract information from the device tree if we've found a |
| 2783 | * matching node. |
| 2784 | */ |
| 2785 | if (of_address_to_resource(np, 0, ®s) < 0) { |
| 2786 | pr_err("failed to get PMC registers\n"); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 2787 | of_node_put(np); |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 2788 | return -ENXIO; |
| 2789 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | pmc->base = ioremap_nocache(regs.start, resource_size(®s)); |
| 2793 | if (!pmc->base) { |
| 2794 | pr_err("failed to map PMC registers\n"); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 2795 | of_node_put(np); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2796 | return -ENXIO; |
| 2797 | } |
| 2798 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 2799 | if (np) { |
Jon Hunter | 718a242 | 2016-06-28 11:38:25 +0100 | [diff] [blame] | 2800 | pmc->soc = match->data; |
| 2801 | |
Mikko Perttunen | e247dea | 2019-01-25 11:22:55 +0100 | [diff] [blame] | 2802 | if (pmc->soc->maybe_tz_only) |
| 2803 | pmc->tz_only = tegra_pmc_detect_tz_only(pmc); |
| 2804 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 2805 | tegra_powergate_init(pmc, np); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2806 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 2807 | /* |
| 2808 | * Invert the interrupt polarity if a PMC device tree node |
| 2809 | * exists and contains the nvidia,invert-interrupt property. |
| 2810 | */ |
| 2811 | invert = of_property_read_bool(np, "nvidia,invert-interrupt"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2812 | |
Thierry Reding | 5be2255 | 2017-08-30 12:32:58 +0200 | [diff] [blame] | 2813 | pmc->soc->setup_irq_polarity(pmc, np, invert); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 2814 | |
| 2815 | of_node_put(np); |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 2816 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 2817 | |
| 2818 | return 0; |
| 2819 | } |
| 2820 | early_initcall(tegra_pmc_early_init); |