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 |
| 5 | * |
| 6 | * Author: |
| 7 | * Colin Cross <ccross@google.com> |
| 8 | * |
| 9 | * This software is licensed under the terms of the GNU General Public |
| 10 | * License version 2, as published by the Free Software Foundation, and |
| 11 | * may be copied, distributed, and modified under those terms. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 20 | #define pr_fmt(fmt) "tegra-pmc: " fmt |
| 21 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/clk/tegra.h> |
| 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/export.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/io.h> |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 31 | #include <linux/iopoll.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_address.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 34 | #include <linux/of_platform.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 35 | #include <linux/platform_device.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 36 | #include <linux/pm_domain.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 37 | #include <linux/reboot.h> |
| 38 | #include <linux/reset.h> |
| 39 | #include <linux/seq_file.h> |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 40 | #include <linux/slab.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 41 | #include <linux/spinlock.h> |
| 42 | |
| 43 | #include <soc/tegra/common.h> |
| 44 | #include <soc/tegra/fuse.h> |
| 45 | #include <soc/tegra/pmc.h> |
| 46 | |
| 47 | #define PMC_CNTRL 0x0 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 48 | #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */ |
Thierry Reding | 95b780b | 2016-10-10 13:13:36 +0200 | [diff] [blame] | 49 | #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */ |
| 50 | #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */ |
| 51 | #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */ |
| 52 | #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */ |
| 53 | #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */ |
| 54 | #define PMC_CNTRL_MAIN_RST BIT(4) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 55 | |
| 56 | #define DPD_SAMPLE 0x020 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 57 | #define DPD_SAMPLE_ENABLE BIT(0) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 58 | #define DPD_SAMPLE_DISABLE (0 << 0) |
| 59 | |
| 60 | #define PWRGATE_TOGGLE 0x30 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 61 | #define PWRGATE_TOGGLE_START BIT(8) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 62 | |
| 63 | #define REMOVE_CLAMPING 0x34 |
| 64 | |
| 65 | #define PWRGATE_STATUS 0x38 |
| 66 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 67 | #define PMC_PWR_DET 0x48 |
| 68 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 69 | #define PMC_SCRATCH0 0x50 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 70 | #define PMC_SCRATCH0_MODE_RECOVERY BIT(31) |
| 71 | #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30) |
| 72 | #define PMC_SCRATCH0_MODE_RCM BIT(1) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 73 | #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \ |
| 74 | PMC_SCRATCH0_MODE_BOOTLOADER | \ |
| 75 | PMC_SCRATCH0_MODE_RCM) |
| 76 | |
| 77 | #define PMC_CPUPWRGOOD_TIMER 0xc8 |
| 78 | #define PMC_CPUPWROFF_TIMER 0xcc |
| 79 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 80 | #define PMC_PWR_DET_VALUE 0xe4 |
| 81 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 82 | #define PMC_SCRATCH41 0x140 |
| 83 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 84 | #define PMC_SENSOR_CTRL 0x1b0 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 85 | #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2) |
| 86 | #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1) |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 87 | |
Thierry Reding | f5353c6 | 2015-12-30 17:13:29 +0100 | [diff] [blame] | 88 | #define PMC_RST_STATUS 0x1b4 |
| 89 | #define PMC_RST_STATUS_POR 0 |
| 90 | #define PMC_RST_STATUS_WATCHDOG 1 |
| 91 | #define PMC_RST_STATUS_SENSOR 2 |
| 92 | #define PMC_RST_STATUS_SW_MAIN 3 |
| 93 | #define PMC_RST_STATUS_LP0 4 |
| 94 | #define PMC_RST_STATUS_AOTAG 5 |
| 95 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 96 | #define IO_DPD_REQ 0x1b8 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 97 | #define IO_DPD_REQ_CODE_IDLE (0U << 30) |
| 98 | #define IO_DPD_REQ_CODE_OFF (1U << 30) |
| 99 | #define IO_DPD_REQ_CODE_ON (2U << 30) |
| 100 | #define IO_DPD_REQ_CODE_MASK (3U << 30) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 101 | |
| 102 | #define IO_DPD_STATUS 0x1bc |
| 103 | #define IO_DPD2_REQ 0x1c0 |
| 104 | #define IO_DPD2_STATUS 0x1c4 |
| 105 | #define SEL_DPD_TIM 0x1c8 |
| 106 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 107 | #define PMC_SCRATCH54 0x258 |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 108 | #define PMC_SCRATCH54_DATA_SHIFT 8 |
| 109 | #define PMC_SCRATCH54_ADDR_SHIFT 0 |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 110 | |
| 111 | #define PMC_SCRATCH55 0x25c |
Laxman Dewangan | 6c0bd21 | 2016-06-17 18:36:12 +0530 | [diff] [blame] | 112 | #define PMC_SCRATCH55_RESET_TEGRA BIT(31) |
| 113 | #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27 |
| 114 | #define PMC_SCRATCH55_PINMUX_SHIFT 24 |
| 115 | #define PMC_SCRATCH55_16BITOP BIT(15) |
| 116 | #define PMC_SCRATCH55_CHECKSUM_SHIFT 16 |
| 117 | #define PMC_SCRATCH55_I2CSLV1_SHIFT 0 |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 118 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 119 | #define GPU_RG_CNTRL 0x2d4 |
| 120 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 121 | struct tegra_powergate { |
| 122 | struct generic_pm_domain genpd; |
| 123 | struct tegra_pmc *pmc; |
| 124 | unsigned int id; |
| 125 | struct clk **clks; |
| 126 | unsigned int num_clks; |
| 127 | struct reset_control **resets; |
| 128 | unsigned int num_resets; |
| 129 | }; |
| 130 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 131 | struct tegra_io_pad_soc { |
| 132 | enum tegra_io_pad id; |
| 133 | unsigned int dpd; |
| 134 | unsigned int voltage; |
| 135 | }; |
| 136 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 137 | struct tegra_pmc_soc { |
| 138 | unsigned int num_powergates; |
| 139 | const char *const *powergates; |
| 140 | unsigned int num_cpu_powergates; |
| 141 | const u8 *cpu_powergates; |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 142 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 143 | bool has_tsense_reset; |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 144 | bool has_gpu_clamps; |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 145 | |
| 146 | const struct tegra_io_pad_soc *io_pads; |
| 147 | unsigned int num_io_pads; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * struct tegra_pmc - NVIDIA Tegra PMC |
Jon Hunter | 35b6729 | 2015-12-04 14:57:03 +0000 | [diff] [blame] | 152 | * @dev: pointer to PMC device structure |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 153 | * @base: pointer to I/O remapped register region |
| 154 | * @clk: pointer to pclk clock |
Jon Hunter | 35b6729 | 2015-12-04 14:57:03 +0000 | [diff] [blame] | 155 | * @soc: pointer to SoC data structure |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 156 | * @debugfs: pointer to debugfs entry |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 157 | * @rate: currently configured rate of pclk |
| 158 | * @suspend_mode: lowest suspend mode available |
| 159 | * @cpu_good_time: CPU power good time (in microseconds) |
| 160 | * @cpu_off_time: CPU power off time (in microsecends) |
| 161 | * @core_osc_time: core power good OSC time (in microseconds) |
| 162 | * @core_pmu_time: core power good PMU time (in microseconds) |
| 163 | * @core_off_time: core power off time (in microseconds) |
| 164 | * @corereq_high: core power request is active-high |
| 165 | * @sysclkreq_high: system clock request is active-high |
| 166 | * @combined_req: combined power request for CPU & core |
| 167 | * @cpu_pwr_good_en: CPU power good signal is enabled |
| 168 | * @lp0_vec_phys: physical base address of the LP0 warm boot code |
| 169 | * @lp0_vec_size: size of the LP0 warm boot code |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 170 | * @powergates_available: Bitmap of available power gates |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 171 | * @powergates_lock: mutex for power gate register access |
| 172 | */ |
| 173 | struct tegra_pmc { |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 174 | struct device *dev; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 175 | void __iomem *base; |
| 176 | struct clk *clk; |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 177 | struct dentry *debugfs; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 178 | |
| 179 | const struct tegra_pmc_soc *soc; |
| 180 | |
| 181 | unsigned long rate; |
| 182 | |
| 183 | enum tegra_suspend_mode suspend_mode; |
| 184 | u32 cpu_good_time; |
| 185 | u32 cpu_off_time; |
| 186 | u32 core_osc_time; |
| 187 | u32 core_pmu_time; |
| 188 | u32 core_off_time; |
| 189 | bool corereq_high; |
| 190 | bool sysclkreq_high; |
| 191 | bool combined_req; |
| 192 | bool cpu_pwr_good_en; |
| 193 | u32 lp0_vec_phys; |
| 194 | u32 lp0_vec_size; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 195 | DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 196 | |
| 197 | struct mutex powergates_lock; |
| 198 | }; |
| 199 | |
| 200 | static struct tegra_pmc *pmc = &(struct tegra_pmc) { |
| 201 | .base = NULL, |
| 202 | .suspend_mode = TEGRA_SUSPEND_NONE, |
| 203 | }; |
| 204 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 205 | static inline struct tegra_powergate * |
| 206 | to_powergate(struct generic_pm_domain *domain) |
| 207 | { |
| 208 | return container_of(domain, struct tegra_powergate, genpd); |
| 209 | } |
| 210 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 211 | static u32 tegra_pmc_readl(unsigned long offset) |
| 212 | { |
| 213 | return readl(pmc->base + offset); |
| 214 | } |
| 215 | |
| 216 | static void tegra_pmc_writel(u32 value, unsigned long offset) |
| 217 | { |
| 218 | writel(value, pmc->base + offset); |
| 219 | } |
| 220 | |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 221 | static inline bool tegra_powergate_state(int id) |
| 222 | { |
Jon Hunter | bc9af23 | 2016-02-15 12:38:11 +0000 | [diff] [blame] | 223 | if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) |
| 224 | return (tegra_pmc_readl(GPU_RG_CNTRL) & 0x1) == 0; |
| 225 | else |
| 226 | return (tegra_pmc_readl(PWRGATE_STATUS) & BIT(id)) != 0; |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Jon Hunter | 0a243bd | 2016-02-11 18:03:24 +0000 | [diff] [blame] | 229 | static inline bool tegra_powergate_is_valid(int id) |
| 230 | { |
| 231 | return (pmc->soc && pmc->soc->powergates[id]); |
| 232 | } |
| 233 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 234 | static inline bool tegra_powergate_is_available(int id) |
| 235 | { |
| 236 | return test_bit(id, pmc->powergates_available); |
| 237 | } |
| 238 | |
| 239 | static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name) |
| 240 | { |
| 241 | unsigned int i; |
| 242 | |
| 243 | if (!pmc || !pmc->soc || !name) |
| 244 | return -EINVAL; |
| 245 | |
| 246 | for (i = 0; i < pmc->soc->num_powergates; i++) { |
| 247 | if (!tegra_powergate_is_valid(i)) |
| 248 | continue; |
| 249 | |
| 250 | if (!strcmp(name, pmc->soc->powergates[i])) |
| 251 | return i; |
| 252 | } |
| 253 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 254 | return -ENODEV; |
| 255 | } |
| 256 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 257 | /** |
| 258 | * tegra_powergate_set() - set the state of a partition |
| 259 | * @id: partition ID |
| 260 | * @new_state: new state of the partition |
| 261 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 262 | static int tegra_powergate_set(unsigned int id, bool new_state) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 263 | { |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 264 | bool status; |
| 265 | int err; |
| 266 | |
Jon Hunter | bc9af23 | 2016-02-15 12:38:11 +0000 | [diff] [blame] | 267 | if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) |
| 268 | return -EINVAL; |
| 269 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 270 | mutex_lock(&pmc->powergates_lock); |
| 271 | |
Jon Hunter | 0ecf2d3 | 2016-02-11 18:03:23 +0000 | [diff] [blame] | 272 | if (tegra_powergate_state(id) == new_state) { |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 273 | mutex_unlock(&pmc->powergates_lock); |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE); |
| 278 | |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 279 | err = readx_poll_timeout(tegra_powergate_state, id, status, |
| 280 | status == new_state, 10, 100000); |
| 281 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 282 | mutex_unlock(&pmc->powergates_lock); |
| 283 | |
Jon Hunter | 0a2d87e | 2016-02-26 15:48:40 +0000 | [diff] [blame] | 284 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 287 | static int __tegra_powergate_remove_clamping(unsigned int id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 288 | { |
| 289 | u32 mask; |
| 290 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 291 | mutex_lock(&pmc->powergates_lock); |
| 292 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 293 | /* |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 294 | * On Tegra124 and later, the clamps for the GPU are controlled by a |
| 295 | * separate register (with different semantics). |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 296 | */ |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 297 | if (id == TEGRA_POWERGATE_3D) { |
| 298 | if (pmc->soc->has_gpu_clamps) { |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 299 | tegra_pmc_writel(0, GPU_RG_CNTRL); |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 300 | goto out; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * Tegra 2 has a bug where PCIE and VDE clamping masks are |
| 306 | * swapped relatively to the partition ids |
| 307 | */ |
| 308 | if (id == TEGRA_POWERGATE_VDEC) |
| 309 | mask = (1 << TEGRA_POWERGATE_PCIE); |
| 310 | else if (id == TEGRA_POWERGATE_PCIE) |
| 311 | mask = (1 << TEGRA_POWERGATE_VDEC); |
| 312 | else |
| 313 | mask = (1 << id); |
| 314 | |
| 315 | tegra_pmc_writel(mask, REMOVE_CLAMPING); |
| 316 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 317 | out: |
| 318 | mutex_unlock(&pmc->powergates_lock); |
| 319 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 320 | return 0; |
| 321 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 322 | |
| 323 | static void tegra_powergate_disable_clocks(struct tegra_powergate *pg) |
| 324 | { |
| 325 | unsigned int i; |
| 326 | |
| 327 | for (i = 0; i < pg->num_clks; i++) |
| 328 | clk_disable_unprepare(pg->clks[i]); |
| 329 | } |
| 330 | |
| 331 | static int tegra_powergate_enable_clocks(struct tegra_powergate *pg) |
| 332 | { |
| 333 | unsigned int i; |
| 334 | int err; |
| 335 | |
| 336 | for (i = 0; i < pg->num_clks; i++) { |
| 337 | err = clk_prepare_enable(pg->clks[i]); |
| 338 | if (err) |
| 339 | goto out; |
| 340 | } |
| 341 | |
| 342 | return 0; |
| 343 | |
| 344 | out: |
| 345 | while (i--) |
| 346 | clk_disable_unprepare(pg->clks[i]); |
| 347 | |
| 348 | return err; |
| 349 | } |
| 350 | |
| 351 | static int tegra_powergate_reset_assert(struct tegra_powergate *pg) |
| 352 | { |
| 353 | unsigned int i; |
| 354 | int err; |
| 355 | |
| 356 | for (i = 0; i < pg->num_resets; i++) { |
| 357 | err = reset_control_assert(pg->resets[i]); |
| 358 | if (err) |
| 359 | return err; |
| 360 | } |
| 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static int tegra_powergate_reset_deassert(struct tegra_powergate *pg) |
| 366 | { |
| 367 | unsigned int i; |
| 368 | int err; |
| 369 | |
| 370 | for (i = 0; i < pg->num_resets; i++) { |
| 371 | err = reset_control_deassert(pg->resets[i]); |
| 372 | if (err) |
| 373 | return err; |
| 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int tegra_powergate_power_up(struct tegra_powergate *pg, |
| 380 | bool disable_clocks) |
| 381 | { |
| 382 | int err; |
| 383 | |
| 384 | err = tegra_powergate_reset_assert(pg); |
| 385 | if (err) |
| 386 | return err; |
| 387 | |
| 388 | usleep_range(10, 20); |
| 389 | |
| 390 | err = tegra_powergate_set(pg->id, true); |
| 391 | if (err < 0) |
| 392 | return err; |
| 393 | |
| 394 | usleep_range(10, 20); |
| 395 | |
| 396 | err = tegra_powergate_enable_clocks(pg); |
| 397 | if (err) |
| 398 | goto disable_clks; |
| 399 | |
| 400 | usleep_range(10, 20); |
| 401 | |
| 402 | err = __tegra_powergate_remove_clamping(pg->id); |
| 403 | if (err) |
| 404 | goto disable_clks; |
| 405 | |
| 406 | usleep_range(10, 20); |
| 407 | |
| 408 | err = tegra_powergate_reset_deassert(pg); |
| 409 | if (err) |
| 410 | goto powergate_off; |
| 411 | |
| 412 | usleep_range(10, 20); |
| 413 | |
| 414 | if (disable_clocks) |
| 415 | tegra_powergate_disable_clocks(pg); |
| 416 | |
| 417 | return 0; |
| 418 | |
| 419 | disable_clks: |
| 420 | tegra_powergate_disable_clocks(pg); |
| 421 | usleep_range(10, 20); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 422 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 423 | powergate_off: |
| 424 | tegra_powergate_set(pg->id, false); |
| 425 | |
| 426 | return err; |
| 427 | } |
| 428 | |
| 429 | static int tegra_powergate_power_down(struct tegra_powergate *pg) |
| 430 | { |
| 431 | int err; |
| 432 | |
| 433 | err = tegra_powergate_enable_clocks(pg); |
| 434 | if (err) |
| 435 | return err; |
| 436 | |
| 437 | usleep_range(10, 20); |
| 438 | |
| 439 | err = tegra_powergate_reset_assert(pg); |
| 440 | if (err) |
| 441 | goto disable_clks; |
| 442 | |
| 443 | usleep_range(10, 20); |
| 444 | |
| 445 | tegra_powergate_disable_clocks(pg); |
| 446 | |
| 447 | usleep_range(10, 20); |
| 448 | |
| 449 | err = tegra_powergate_set(pg->id, false); |
| 450 | if (err) |
| 451 | goto assert_resets; |
| 452 | |
| 453 | return 0; |
| 454 | |
| 455 | assert_resets: |
| 456 | tegra_powergate_enable_clocks(pg); |
| 457 | usleep_range(10, 20); |
| 458 | tegra_powergate_reset_deassert(pg); |
| 459 | usleep_range(10, 20); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 460 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 461 | disable_clks: |
| 462 | tegra_powergate_disable_clocks(pg); |
| 463 | |
| 464 | return err; |
| 465 | } |
| 466 | |
| 467 | static int tegra_genpd_power_on(struct generic_pm_domain *domain) |
| 468 | { |
| 469 | struct tegra_powergate *pg = to_powergate(domain); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 470 | int err; |
| 471 | |
| 472 | err = tegra_powergate_power_up(pg, true); |
| 473 | if (err) |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 474 | pr_err("failed to turn on PM domain %s: %d\n", pg->genpd.name, |
| 475 | err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 476 | |
| 477 | return err; |
| 478 | } |
| 479 | |
| 480 | static int tegra_genpd_power_off(struct generic_pm_domain *domain) |
| 481 | { |
| 482 | struct tegra_powergate *pg = to_powergate(domain); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 483 | int err; |
| 484 | |
| 485 | err = tegra_powergate_power_down(pg); |
| 486 | if (err) |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 487 | pr_err("failed to turn off PM domain %s: %d\n", |
| 488 | pg->genpd.name, err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 489 | |
| 490 | return err; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * tegra_powergate_power_on() - power on partition |
| 495 | * @id: partition ID |
| 496 | */ |
| 497 | int tegra_powergate_power_on(unsigned int id) |
| 498 | { |
| 499 | if (!tegra_powergate_is_available(id)) |
| 500 | return -EINVAL; |
| 501 | |
| 502 | return tegra_powergate_set(id, true); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * tegra_powergate_power_off() - power off partition |
| 507 | * @id: partition ID |
| 508 | */ |
| 509 | int tegra_powergate_power_off(unsigned int id) |
| 510 | { |
| 511 | if (!tegra_powergate_is_available(id)) |
| 512 | return -EINVAL; |
| 513 | |
| 514 | return tegra_powergate_set(id, false); |
| 515 | } |
| 516 | EXPORT_SYMBOL(tegra_powergate_power_off); |
| 517 | |
| 518 | /** |
| 519 | * tegra_powergate_is_powered() - check if partition is powered |
| 520 | * @id: partition ID |
| 521 | */ |
| 522 | int tegra_powergate_is_powered(unsigned int id) |
| 523 | { |
| 524 | int status; |
| 525 | |
| 526 | if (!tegra_powergate_is_valid(id)) |
| 527 | return -EINVAL; |
| 528 | |
| 529 | mutex_lock(&pmc->powergates_lock); |
| 530 | status = tegra_powergate_state(id); |
| 531 | mutex_unlock(&pmc->powergates_lock); |
| 532 | |
| 533 | return status; |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * tegra_powergate_remove_clamping() - remove power clamps for partition |
| 538 | * @id: partition ID |
| 539 | */ |
| 540 | int tegra_powergate_remove_clamping(unsigned int id) |
| 541 | { |
| 542 | if (!tegra_powergate_is_available(id)) |
| 543 | return -EINVAL; |
| 544 | |
| 545 | return __tegra_powergate_remove_clamping(id); |
| 546 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 547 | EXPORT_SYMBOL(tegra_powergate_remove_clamping); |
| 548 | |
| 549 | /** |
| 550 | * tegra_powergate_sequence_power_up() - power up partition |
| 551 | * @id: partition ID |
| 552 | * @clk: clock for partition |
| 553 | * @rst: reset for partition |
| 554 | * |
| 555 | * Must be called with clk disabled, and returns with clk enabled. |
| 556 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 557 | int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 558 | struct reset_control *rst) |
| 559 | { |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 560 | struct tegra_powergate pg; |
| 561 | int err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 562 | |
Jon Hunter | 403db2d | 2016-06-28 11:38:23 +0100 | [diff] [blame] | 563 | if (!tegra_powergate_is_available(id)) |
| 564 | return -EINVAL; |
| 565 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 566 | pg.id = id; |
| 567 | pg.clks = &clk; |
| 568 | pg.num_clks = 1; |
| 569 | pg.resets = &rst; |
| 570 | pg.num_resets = 1; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 571 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 572 | err = tegra_powergate_power_up(&pg, false); |
| 573 | if (err) |
| 574 | pr_err("failed to turn on partition %d: %d\n", id, err); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 575 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 576 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 577 | } |
| 578 | EXPORT_SYMBOL(tegra_powergate_sequence_power_up); |
| 579 | |
| 580 | #ifdef CONFIG_SMP |
| 581 | /** |
| 582 | * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID |
| 583 | * @cpuid: CPU partition ID |
| 584 | * |
| 585 | * Returns the partition ID corresponding to the CPU partition ID or a |
| 586 | * negative error code on failure. |
| 587 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 588 | static int tegra_get_cpu_powergate_id(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 589 | { |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 590 | if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 591 | return pmc->soc->cpu_powergates[cpuid]; |
| 592 | |
| 593 | return -EINVAL; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * tegra_pmc_cpu_is_powered() - check if CPU partition is powered |
| 598 | * @cpuid: CPU partition ID |
| 599 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 600 | bool tegra_pmc_cpu_is_powered(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 601 | { |
| 602 | int id; |
| 603 | |
| 604 | id = tegra_get_cpu_powergate_id(cpuid); |
| 605 | if (id < 0) |
| 606 | return false; |
| 607 | |
| 608 | return tegra_powergate_is_powered(id); |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * tegra_pmc_cpu_power_on() - power on CPU partition |
| 613 | * @cpuid: CPU partition ID |
| 614 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 615 | int tegra_pmc_cpu_power_on(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 616 | { |
| 617 | int id; |
| 618 | |
| 619 | id = tegra_get_cpu_powergate_id(cpuid); |
| 620 | if (id < 0) |
| 621 | return id; |
| 622 | |
| 623 | return tegra_powergate_set(id, true); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition |
| 628 | * @cpuid: CPU partition ID |
| 629 | */ |
Jon Hunter | 70293ed | 2016-02-11 18:03:22 +0000 | [diff] [blame] | 630 | int tegra_pmc_cpu_remove_clamping(unsigned int cpuid) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 631 | { |
| 632 | int id; |
| 633 | |
| 634 | id = tegra_get_cpu_powergate_id(cpuid); |
| 635 | if (id < 0) |
| 636 | return id; |
| 637 | |
| 638 | return tegra_powergate_remove_clamping(id); |
| 639 | } |
| 640 | #endif /* CONFIG_SMP */ |
| 641 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 642 | static int tegra_pmc_restart_notify(struct notifier_block *this, |
| 643 | unsigned long action, void *data) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 644 | { |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 645 | const char *cmd = data; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 646 | u32 value; |
| 647 | |
| 648 | value = tegra_pmc_readl(PMC_SCRATCH0); |
| 649 | value &= ~PMC_SCRATCH0_MODE_MASK; |
| 650 | |
| 651 | if (cmd) { |
| 652 | if (strcmp(cmd, "recovery") == 0) |
| 653 | value |= PMC_SCRATCH0_MODE_RECOVERY; |
| 654 | |
| 655 | if (strcmp(cmd, "bootloader") == 0) |
| 656 | value |= PMC_SCRATCH0_MODE_BOOTLOADER; |
| 657 | |
| 658 | if (strcmp(cmd, "forced-recovery") == 0) |
| 659 | value |= PMC_SCRATCH0_MODE_RCM; |
| 660 | } |
| 661 | |
| 662 | tegra_pmc_writel(value, PMC_SCRATCH0); |
| 663 | |
Thierry Reding | f5353c6 | 2015-12-30 17:13:29 +0100 | [diff] [blame] | 664 | /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */ |
| 665 | value = tegra_pmc_readl(PMC_CNTRL); |
| 666 | value |= PMC_CNTRL_MAIN_RST; |
| 667 | tegra_pmc_writel(value, PMC_CNTRL); |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 668 | |
| 669 | return NOTIFY_DONE; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 670 | } |
| 671 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 672 | static struct notifier_block tegra_pmc_restart_handler = { |
| 673 | .notifier_call = tegra_pmc_restart_notify, |
| 674 | .priority = 128, |
| 675 | }; |
| 676 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 677 | static int powergate_show(struct seq_file *s, void *data) |
| 678 | { |
| 679 | unsigned int i; |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 680 | int status; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 681 | |
| 682 | seq_printf(s, " powergate powered\n"); |
| 683 | seq_printf(s, "------------------\n"); |
| 684 | |
| 685 | for (i = 0; i < pmc->soc->num_powergates; i++) { |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 686 | status = tegra_powergate_is_powered(i); |
| 687 | if (status < 0) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 688 | continue; |
| 689 | |
| 690 | seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i], |
Jon Hunter | c3ea297 | 2016-02-11 18:03:25 +0000 | [diff] [blame] | 691 | status ? "yes" : "no"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static int powergate_open(struct inode *inode, struct file *file) |
| 698 | { |
| 699 | return single_open(file, powergate_show, inode->i_private); |
| 700 | } |
| 701 | |
| 702 | static const struct file_operations powergate_fops = { |
| 703 | .open = powergate_open, |
| 704 | .read = seq_read, |
| 705 | .llseek = seq_lseek, |
| 706 | .release = single_release, |
| 707 | }; |
| 708 | |
| 709 | static int tegra_powergate_debugfs_init(void) |
| 710 | { |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 711 | pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL, |
| 712 | &powergate_fops); |
| 713 | if (!pmc->debugfs) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 714 | return -ENOMEM; |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 719 | static int tegra_powergate_of_get_clks(struct tegra_powergate *pg, |
| 720 | struct device_node *np) |
| 721 | { |
| 722 | struct clk *clk; |
| 723 | unsigned int i, count; |
| 724 | int err; |
| 725 | |
| 726 | count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); |
| 727 | if (count == 0) |
| 728 | return -ENODEV; |
| 729 | |
| 730 | pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL); |
| 731 | if (!pg->clks) |
| 732 | return -ENOMEM; |
| 733 | |
| 734 | for (i = 0; i < count; i++) { |
| 735 | pg->clks[i] = of_clk_get(np, i); |
| 736 | if (IS_ERR(pg->clks[i])) { |
| 737 | err = PTR_ERR(pg->clks[i]); |
| 738 | goto err; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | pg->num_clks = count; |
| 743 | |
| 744 | return 0; |
| 745 | |
| 746 | err: |
| 747 | while (i--) |
| 748 | clk_put(pg->clks[i]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 749 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 750 | kfree(pg->clks); |
| 751 | |
| 752 | return err; |
| 753 | } |
| 754 | |
| 755 | static int tegra_powergate_of_get_resets(struct tegra_powergate *pg, |
Jon Hunter | 05cfb98 | 2016-06-29 10:17:47 +0100 | [diff] [blame] | 756 | struct device_node *np, bool off) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 757 | { |
| 758 | struct reset_control *rst; |
| 759 | unsigned int i, count; |
| 760 | int err; |
| 761 | |
| 762 | count = of_count_phandle_with_args(np, "resets", "#reset-cells"); |
| 763 | if (count == 0) |
| 764 | return -ENODEV; |
| 765 | |
| 766 | pg->resets = kcalloc(count, sizeof(rst), GFP_KERNEL); |
| 767 | if (!pg->resets) |
| 768 | return -ENOMEM; |
| 769 | |
| 770 | for (i = 0; i < count; i++) { |
| 771 | pg->resets[i] = of_reset_control_get_by_index(np, i); |
| 772 | if (IS_ERR(pg->resets[i])) { |
| 773 | err = PTR_ERR(pg->resets[i]); |
| 774 | goto error; |
| 775 | } |
Jon Hunter | 05cfb98 | 2016-06-29 10:17:47 +0100 | [diff] [blame] | 776 | |
| 777 | if (off) |
| 778 | err = reset_control_assert(pg->resets[i]); |
| 779 | else |
| 780 | err = reset_control_deassert(pg->resets[i]); |
| 781 | |
| 782 | if (err) { |
| 783 | reset_control_put(pg->resets[i]); |
| 784 | goto error; |
| 785 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | pg->num_resets = count; |
| 789 | |
| 790 | return 0; |
| 791 | |
| 792 | error: |
| 793 | while (i--) |
| 794 | reset_control_put(pg->resets[i]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 795 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 796 | kfree(pg->resets); |
| 797 | |
| 798 | return err; |
| 799 | } |
| 800 | |
| 801 | static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) |
| 802 | { |
| 803 | struct tegra_powergate *pg; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 804 | int id, err; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 805 | bool off; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 806 | |
| 807 | pg = kzalloc(sizeof(*pg), GFP_KERNEL); |
| 808 | if (!pg) |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 809 | return; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 810 | |
| 811 | id = tegra_powergate_lookup(pmc, np->name); |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 812 | if (id < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 813 | pr_err("powergate lookup failed for %s: %d\n", np->name, id); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 814 | goto free_mem; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 815 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 816 | |
| 817 | /* |
| 818 | * Clear the bit for this powergate so it cannot be managed |
| 819 | * directly via the legacy APIs for controlling powergates. |
| 820 | */ |
| 821 | clear_bit(id, pmc->powergates_available); |
| 822 | |
| 823 | pg->id = id; |
| 824 | pg->genpd.name = np->name; |
| 825 | pg->genpd.power_off = tegra_genpd_power_off; |
| 826 | pg->genpd.power_on = tegra_genpd_power_on; |
| 827 | pg->pmc = pmc; |
| 828 | |
Jon Hunter | 05cfb98 | 2016-06-29 10:17:47 +0100 | [diff] [blame] | 829 | off = !tegra_powergate_is_powered(pg->id); |
| 830 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 831 | err = tegra_powergate_of_get_clks(pg, np); |
| 832 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 833 | pr_err("failed to get clocks for %s: %d\n", np->name, err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 834 | goto set_available; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 835 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 836 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 837 | err = tegra_powergate_of_get_resets(pg, np, off); |
| 838 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 839 | pr_err("failed to get resets for %s: %d\n", np->name, err); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 840 | goto remove_clks; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 841 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 842 | |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 843 | if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) { |
| 844 | if (off) |
| 845 | WARN_ON(tegra_powergate_power_up(pg, true)); |
| 846 | |
| 847 | goto remove_resets; |
| 848 | } |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 849 | |
Jon Hunter | 8df1274 | 2016-06-30 11:56:26 +0100 | [diff] [blame] | 850 | /* |
| 851 | * FIXME: If XHCI is enabled for Tegra, then power-up the XUSB |
| 852 | * host and super-speed partitions. Once the XHCI driver |
| 853 | * manages the partitions itself this code can be removed. Note |
| 854 | * that we don't register these partitions with the genpd core |
| 855 | * to avoid it from powering down the partitions as they appear |
| 856 | * to be unused. |
| 857 | */ |
| 858 | if (IS_ENABLED(CONFIG_USB_XHCI_TEGRA) && |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 859 | (id == TEGRA_POWERGATE_XUSBA || id == TEGRA_POWERGATE_XUSBC)) { |
| 860 | if (off) |
| 861 | WARN_ON(tegra_powergate_power_up(pg, true)); |
| 862 | |
| 863 | goto remove_resets; |
| 864 | } |
Jon Hunter | 8df1274 | 2016-06-30 11:56:26 +0100 | [diff] [blame] | 865 | |
Jon Hunter | cd5ceda | 2016-10-22 20:23:55 +0100 | [diff] [blame] | 866 | err = pm_genpd_init(&pg->genpd, NULL, off); |
| 867 | if (err < 0) { |
Thierry Reding | 4522112 | 2016-11-08 11:05:03 +0100 | [diff] [blame] | 868 | pr_err("failed to initialise PM domain %s: %d\n", np->name, |
Jon Hunter | cd5ceda | 2016-10-22 20:23:55 +0100 | [diff] [blame] | 869 | err); |
| 870 | goto remove_resets; |
| 871 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 872 | |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 873 | err = of_genpd_add_provider_simple(np, &pg->genpd); |
| 874 | if (err < 0) { |
Thierry Reding | 4522112 | 2016-11-08 11:05:03 +0100 | [diff] [blame] | 875 | pr_err("failed to add PM domain provider for %s: %d\n", |
| 876 | np->name, err); |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 877 | goto remove_genpd; |
Jon Hunter | c2710ac | 2016-06-30 11:56:24 +0100 | [diff] [blame] | 878 | } |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 879 | |
Thierry Reding | 4522112 | 2016-11-08 11:05:03 +0100 | [diff] [blame] | 880 | pr_debug("added PM domain %s\n", pg->genpd.name); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 881 | |
| 882 | return; |
| 883 | |
Jon Hunter | 0b13734 | 2016-10-22 20:23:56 +0100 | [diff] [blame] | 884 | remove_genpd: |
| 885 | pm_genpd_remove(&pg->genpd); |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 886 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 887 | remove_resets: |
| 888 | while (pg->num_resets--) |
| 889 | reset_control_put(pg->resets[pg->num_resets]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 890 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 891 | kfree(pg->resets); |
| 892 | |
| 893 | remove_clks: |
| 894 | while (pg->num_clks--) |
| 895 | clk_put(pg->clks[pg->num_clks]); |
Thierry Reding | da8f4b4 | 2016-06-30 12:12:55 +0200 | [diff] [blame] | 896 | |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 897 | kfree(pg->clks); |
| 898 | |
| 899 | set_available: |
| 900 | set_bit(id, pmc->powergates_available); |
| 901 | |
| 902 | free_mem: |
| 903 | kfree(pg); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 904 | } |
| 905 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 906 | static void tegra_powergate_init(struct tegra_pmc *pmc, |
| 907 | struct device_node *parent) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 908 | { |
| 909 | struct device_node *np, *child; |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 910 | unsigned int i; |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 911 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 912 | /* Create a bitmap of the available and valid partitions */ |
| 913 | for (i = 0; i < pmc->soc->num_powergates; i++) |
| 914 | if (pmc->soc->powergates[i]) |
| 915 | set_bit(i, pmc->powergates_available); |
| 916 | |
| 917 | np = of_get_child_by_name(parent, "powergates"); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 918 | if (!np) |
| 919 | return; |
| 920 | |
Tuomas Tynkkynen | 0c106e5 | 2017-07-29 02:58:43 +0300 | [diff] [blame^] | 921 | for_each_child_of_node(np, child) |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 922 | tegra_powergate_add(pmc, child); |
Jon Hunter | a380451 | 2016-03-30 10:15:15 +0100 | [diff] [blame] | 923 | |
| 924 | of_node_put(np); |
| 925 | } |
| 926 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 927 | static const struct tegra_io_pad_soc * |
| 928 | 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] | 929 | { |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 930 | unsigned int i; |
| 931 | |
| 932 | for (i = 0; i < pmc->soc->num_io_pads; i++) |
| 933 | if (pmc->soc->io_pads[i].id == id) |
| 934 | return &pmc->soc->io_pads[i]; |
| 935 | |
| 936 | return NULL; |
| 937 | } |
| 938 | |
| 939 | static int tegra_io_pad_prepare(enum tegra_io_pad id, unsigned long *request, |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 940 | unsigned long *status, u32 *mask) |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 941 | { |
| 942 | const struct tegra_io_pad_soc *pad; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 943 | unsigned long rate, value; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 944 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 945 | pad = tegra_io_pad_find(pmc, id); |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 946 | if (!pad) { |
| 947 | pr_err("invalid I/O pad ID %u\n", id); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 948 | return -ENOENT; |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 949 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 950 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 951 | if (pad->dpd == UINT_MAX) |
| 952 | return -ENOTSUPP; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 953 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 954 | *mask = BIT(pad->dpd % 32); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 955 | |
| 956 | if (pad->dpd < 32) { |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 957 | *status = IO_DPD_STATUS; |
| 958 | *request = IO_DPD_REQ; |
| 959 | } else { |
| 960 | *status = IO_DPD2_STATUS; |
| 961 | *request = IO_DPD2_REQ; |
| 962 | } |
| 963 | |
Thierry Reding | 592431b | 2015-08-04 15:25:03 +0200 | [diff] [blame] | 964 | rate = clk_get_rate(pmc->clk); |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 965 | if (!rate) { |
| 966 | pr_err("failed to get clock rate\n"); |
Jon Hunter | f4392d6 | 2016-10-22 20:23:52 +0100 | [diff] [blame] | 967 | return -ENODEV; |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 968 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 969 | |
| 970 | tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE); |
| 971 | |
| 972 | /* must be at least 200 ns, in APB (PCLK) clock cycles */ |
| 973 | value = DIV_ROUND_UP(1000000000, rate); |
| 974 | value = DIV_ROUND_UP(200, value); |
| 975 | tegra_pmc_writel(value, SEL_DPD_TIM); |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 980 | static int tegra_io_pad_poll(unsigned long offset, u32 mask, |
| 981 | u32 val, unsigned long timeout) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 982 | { |
Laxman Dewangan | 84cf85e | 2016-06-17 18:36:13 +0530 | [diff] [blame] | 983 | u32 value; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 984 | |
| 985 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 986 | |
| 987 | while (time_after(timeout, jiffies)) { |
| 988 | value = tegra_pmc_readl(offset); |
| 989 | if ((value & mask) == val) |
| 990 | return 0; |
| 991 | |
| 992 | usleep_range(250, 1000); |
| 993 | } |
| 994 | |
| 995 | return -ETIMEDOUT; |
| 996 | } |
| 997 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 998 | static void tegra_io_pad_unprepare(void) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 999 | { |
| 1000 | tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE); |
| 1001 | } |
| 1002 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1003 | /** |
| 1004 | * tegra_io_pad_power_enable() - enable power to I/O pad |
| 1005 | * @id: Tegra I/O pad ID for which to enable power |
| 1006 | * |
| 1007 | * Returns: 0 on success or a negative error code on failure. |
| 1008 | */ |
| 1009 | int tegra_io_pad_power_enable(enum tegra_io_pad id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1010 | { |
Vince Hsu | a9ccc123 | 2016-08-11 09:13:36 +0800 | [diff] [blame] | 1011 | unsigned long request, status; |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1012 | u32 mask; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1013 | int err; |
| 1014 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1015 | mutex_lock(&pmc->powergates_lock); |
| 1016 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1017 | err = tegra_io_pad_prepare(id, &request, &status, &mask); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1018 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1019 | pr_err("failed to prepare I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1020 | goto unlock; |
| 1021 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1022 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1023 | tegra_pmc_writel(IO_DPD_REQ_CODE_OFF | mask, request); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1024 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1025 | err = tegra_io_pad_poll(status, mask, 0, 250); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1026 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1027 | pr_err("failed to enable I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1028 | goto unlock; |
Thierry Reding | 592431b | 2015-08-04 15:25:03 +0200 | [diff] [blame] | 1029 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1030 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1031 | tegra_io_pad_unprepare(); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1032 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1033 | unlock: |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1034 | mutex_unlock(&pmc->powergates_lock); |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1035 | return err; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1036 | } |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1037 | EXPORT_SYMBOL(tegra_io_pad_power_enable); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1038 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1039 | /** |
| 1040 | * tegra_io_pad_power_disable() - disable power to I/O pad |
| 1041 | * @id: Tegra I/O pad ID for which to disable power |
| 1042 | * |
| 1043 | * Returns: 0 on success or a negative error code on failure. |
| 1044 | */ |
| 1045 | int tegra_io_pad_power_disable(enum tegra_io_pad id) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1046 | { |
Vince Hsu | a9ccc123 | 2016-08-11 09:13:36 +0800 | [diff] [blame] | 1047 | unsigned long request, status; |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1048 | u32 mask; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1049 | int err; |
| 1050 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1051 | mutex_lock(&pmc->powergates_lock); |
| 1052 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1053 | err = tegra_io_pad_prepare(id, &request, &status, &mask); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1054 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1055 | pr_err("failed to prepare I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1056 | goto unlock; |
Thierry Reding | 592431b | 2015-08-04 15:25:03 +0200 | [diff] [blame] | 1057 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1058 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1059 | tegra_pmc_writel(IO_DPD_REQ_CODE_ON | mask, request); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1060 | |
Jon Hunter | 27b12b4e | 2016-10-22 20:23:53 +0100 | [diff] [blame] | 1061 | err = tegra_io_pad_poll(status, mask, mask, 250); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1062 | if (err < 0) { |
Thierry Reding | 54e2472 | 2016-11-08 10:58:32 +0100 | [diff] [blame] | 1063 | pr_err("failed to disable I/O pad: %d\n", err); |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1064 | goto unlock; |
| 1065 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1066 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1067 | tegra_io_pad_unprepare(); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1068 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1069 | unlock: |
| 1070 | mutex_unlock(&pmc->powergates_lock); |
| 1071 | return err; |
| 1072 | } |
| 1073 | EXPORT_SYMBOL(tegra_io_pad_power_disable); |
| 1074 | |
| 1075 | int tegra_io_pad_set_voltage(enum tegra_io_pad id, |
| 1076 | enum tegra_io_pad_voltage voltage) |
| 1077 | { |
| 1078 | const struct tegra_io_pad_soc *pad; |
| 1079 | u32 value; |
| 1080 | |
| 1081 | pad = tegra_io_pad_find(pmc, id); |
| 1082 | if (!pad) |
| 1083 | return -ENOENT; |
| 1084 | |
| 1085 | if (pad->voltage == UINT_MAX) |
| 1086 | return -ENOTSUPP; |
| 1087 | |
| 1088 | mutex_lock(&pmc->powergates_lock); |
| 1089 | |
| 1090 | /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */ |
| 1091 | value = tegra_pmc_readl(PMC_PWR_DET); |
| 1092 | value |= BIT(pad->voltage); |
| 1093 | tegra_pmc_writel(value, PMC_PWR_DET); |
| 1094 | |
| 1095 | /* update I/O voltage */ |
| 1096 | value = tegra_pmc_readl(PMC_PWR_DET_VALUE); |
| 1097 | |
| 1098 | if (voltage == TEGRA_IO_PAD_1800000UV) |
| 1099 | value &= ~BIT(pad->voltage); |
| 1100 | else |
| 1101 | value |= BIT(pad->voltage); |
| 1102 | |
| 1103 | tegra_pmc_writel(value, PMC_PWR_DET_VALUE); |
| 1104 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1105 | mutex_unlock(&pmc->powergates_lock); |
| 1106 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1107 | usleep_range(100, 250); |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | EXPORT_SYMBOL(tegra_io_pad_set_voltage); |
| 1112 | |
| 1113 | int tegra_io_pad_get_voltage(enum tegra_io_pad id) |
| 1114 | { |
| 1115 | const struct tegra_io_pad_soc *pad; |
| 1116 | u32 value; |
| 1117 | |
| 1118 | pad = tegra_io_pad_find(pmc, id); |
| 1119 | if (!pad) |
| 1120 | return -ENOENT; |
| 1121 | |
| 1122 | if (pad->voltage == UINT_MAX) |
| 1123 | return -ENOTSUPP; |
| 1124 | |
| 1125 | value = tegra_pmc_readl(PMC_PWR_DET_VALUE); |
| 1126 | |
| 1127 | if ((value & BIT(pad->voltage)) == 0) |
| 1128 | return TEGRA_IO_PAD_1800000UV; |
| 1129 | |
| 1130 | return TEGRA_IO_PAD_3300000UV; |
| 1131 | } |
| 1132 | EXPORT_SYMBOL(tegra_io_pad_get_voltage); |
| 1133 | |
| 1134 | /** |
| 1135 | * tegra_io_rail_power_on() - enable power to I/O rail |
| 1136 | * @id: Tegra I/O pad ID for which to enable power |
| 1137 | * |
| 1138 | * See also: tegra_io_pad_power_enable() |
| 1139 | */ |
| 1140 | int tegra_io_rail_power_on(unsigned int id) |
| 1141 | { |
| 1142 | return tegra_io_pad_power_enable(id); |
| 1143 | } |
| 1144 | EXPORT_SYMBOL(tegra_io_rail_power_on); |
| 1145 | |
| 1146 | /** |
| 1147 | * tegra_io_rail_power_off() - disable power to I/O rail |
| 1148 | * @id: Tegra I/O pad ID for which to disable power |
| 1149 | * |
| 1150 | * See also: tegra_io_pad_power_disable() |
| 1151 | */ |
| 1152 | int tegra_io_rail_power_off(unsigned int id) |
| 1153 | { |
| 1154 | return tegra_io_pad_power_disable(id); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1155 | } |
| 1156 | EXPORT_SYMBOL(tegra_io_rail_power_off); |
| 1157 | |
| 1158 | #ifdef CONFIG_PM_SLEEP |
| 1159 | enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void) |
| 1160 | { |
| 1161 | return pmc->suspend_mode; |
| 1162 | } |
| 1163 | |
| 1164 | void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode) |
| 1165 | { |
| 1166 | if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE) |
| 1167 | return; |
| 1168 | |
| 1169 | pmc->suspend_mode = mode; |
| 1170 | } |
| 1171 | |
| 1172 | void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode) |
| 1173 | { |
| 1174 | unsigned long long rate = 0; |
| 1175 | u32 value; |
| 1176 | |
| 1177 | switch (mode) { |
| 1178 | case TEGRA_SUSPEND_LP1: |
| 1179 | rate = 32768; |
| 1180 | break; |
| 1181 | |
| 1182 | case TEGRA_SUSPEND_LP2: |
| 1183 | rate = clk_get_rate(pmc->clk); |
| 1184 | break; |
| 1185 | |
| 1186 | default: |
| 1187 | break; |
| 1188 | } |
| 1189 | |
| 1190 | if (WARN_ON_ONCE(rate == 0)) |
| 1191 | rate = 100000000; |
| 1192 | |
| 1193 | if (rate != pmc->rate) { |
| 1194 | u64 ticks; |
| 1195 | |
| 1196 | ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1; |
| 1197 | do_div(ticks, USEC_PER_SEC); |
| 1198 | tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER); |
| 1199 | |
| 1200 | ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1; |
| 1201 | do_div(ticks, USEC_PER_SEC); |
| 1202 | tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER); |
| 1203 | |
| 1204 | wmb(); |
| 1205 | |
| 1206 | pmc->rate = rate; |
| 1207 | } |
| 1208 | |
| 1209 | value = tegra_pmc_readl(PMC_CNTRL); |
| 1210 | value &= ~PMC_CNTRL_SIDE_EFFECT_LP0; |
| 1211 | value |= PMC_CNTRL_CPU_PWRREQ_OE; |
| 1212 | tegra_pmc_writel(value, PMC_CNTRL); |
| 1213 | } |
| 1214 | #endif |
| 1215 | |
| 1216 | static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np) |
| 1217 | { |
| 1218 | u32 value, values[2]; |
| 1219 | |
| 1220 | if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) { |
| 1221 | } else { |
| 1222 | switch (value) { |
| 1223 | case 0: |
| 1224 | pmc->suspend_mode = TEGRA_SUSPEND_LP0; |
| 1225 | break; |
| 1226 | |
| 1227 | case 1: |
| 1228 | pmc->suspend_mode = TEGRA_SUSPEND_LP1; |
| 1229 | break; |
| 1230 | |
| 1231 | case 2: |
| 1232 | pmc->suspend_mode = TEGRA_SUSPEND_LP2; |
| 1233 | break; |
| 1234 | |
| 1235 | default: |
| 1236 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode); |
| 1242 | |
| 1243 | if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value)) |
| 1244 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1245 | |
| 1246 | pmc->cpu_good_time = value; |
| 1247 | |
| 1248 | if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value)) |
| 1249 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1250 | |
| 1251 | pmc->cpu_off_time = value; |
| 1252 | |
| 1253 | if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time", |
| 1254 | values, ARRAY_SIZE(values))) |
| 1255 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1256 | |
| 1257 | pmc->core_osc_time = values[0]; |
| 1258 | pmc->core_pmu_time = values[1]; |
| 1259 | |
| 1260 | if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value)) |
| 1261 | pmc->suspend_mode = TEGRA_SUSPEND_NONE; |
| 1262 | |
| 1263 | pmc->core_off_time = value; |
| 1264 | |
| 1265 | pmc->corereq_high = of_property_read_bool(np, |
| 1266 | "nvidia,core-power-req-active-high"); |
| 1267 | |
| 1268 | pmc->sysclkreq_high = of_property_read_bool(np, |
| 1269 | "nvidia,sys-clock-req-active-high"); |
| 1270 | |
| 1271 | pmc->combined_req = of_property_read_bool(np, |
| 1272 | "nvidia,combined-power-req"); |
| 1273 | |
| 1274 | pmc->cpu_pwr_good_en = of_property_read_bool(np, |
| 1275 | "nvidia,cpu-pwr-good-en"); |
| 1276 | |
| 1277 | if (of_property_read_u32_array(np, "nvidia,lp0-vec", values, |
| 1278 | ARRAY_SIZE(values))) |
| 1279 | if (pmc->suspend_mode == TEGRA_SUSPEND_LP0) |
| 1280 | pmc->suspend_mode = TEGRA_SUSPEND_LP1; |
| 1281 | |
| 1282 | pmc->lp0_vec_phys = values[0]; |
| 1283 | pmc->lp0_vec_size = values[1]; |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | static void tegra_pmc_init(struct tegra_pmc *pmc) |
| 1289 | { |
| 1290 | u32 value; |
| 1291 | |
| 1292 | /* Always enable CPU power request */ |
| 1293 | value = tegra_pmc_readl(PMC_CNTRL); |
| 1294 | value |= PMC_CNTRL_CPU_PWRREQ_OE; |
| 1295 | tegra_pmc_writel(value, PMC_CNTRL); |
| 1296 | |
| 1297 | value = tegra_pmc_readl(PMC_CNTRL); |
| 1298 | |
| 1299 | if (pmc->sysclkreq_high) |
| 1300 | value &= ~PMC_CNTRL_SYSCLK_POLARITY; |
| 1301 | else |
| 1302 | value |= PMC_CNTRL_SYSCLK_POLARITY; |
| 1303 | |
| 1304 | /* configure the output polarity while the request is tristated */ |
| 1305 | tegra_pmc_writel(value, PMC_CNTRL); |
| 1306 | |
| 1307 | /* now enable the request */ |
| 1308 | value = tegra_pmc_readl(PMC_CNTRL); |
| 1309 | value |= PMC_CNTRL_SYSCLK_OE; |
| 1310 | tegra_pmc_writel(value, PMC_CNTRL); |
| 1311 | } |
| 1312 | |
Jon Hunter | 1e52efdf | 2015-12-04 14:57:04 +0000 | [diff] [blame] | 1313 | static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc) |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1314 | { |
| 1315 | static const char disabled[] = "emergency thermal reset disabled"; |
| 1316 | u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux; |
| 1317 | struct device *dev = pmc->dev; |
| 1318 | struct device_node *np; |
| 1319 | u32 value, checksum; |
| 1320 | |
| 1321 | if (!pmc->soc->has_tsense_reset) |
Thierry Reding | 95169cd | 2015-07-09 09:59:55 +0200 | [diff] [blame] | 1322 | return; |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1323 | |
| 1324 | np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip"); |
| 1325 | if (!np) { |
| 1326 | dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled); |
Thierry Reding | 95169cd | 2015-07-09 09:59:55 +0200 | [diff] [blame] | 1327 | return; |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) { |
| 1331 | dev_err(dev, "I2C controller ID missing, %s.\n", disabled); |
| 1332 | goto out; |
| 1333 | } |
| 1334 | |
| 1335 | if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) { |
| 1336 | dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled); |
| 1337 | goto out; |
| 1338 | } |
| 1339 | |
| 1340 | if (of_property_read_u32(np, "nvidia,reg-addr", ®_addr)) { |
| 1341 | dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled); |
| 1342 | goto out; |
| 1343 | } |
| 1344 | |
| 1345 | if (of_property_read_u32(np, "nvidia,reg-data", ®_data)) { |
| 1346 | dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled); |
| 1347 | goto out; |
| 1348 | } |
| 1349 | |
| 1350 | if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux)) |
| 1351 | pinmux = 0; |
| 1352 | |
| 1353 | value = tegra_pmc_readl(PMC_SENSOR_CTRL); |
| 1354 | value |= PMC_SENSOR_CTRL_SCRATCH_WRITE; |
| 1355 | tegra_pmc_writel(value, PMC_SENSOR_CTRL); |
| 1356 | |
| 1357 | value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) | |
| 1358 | (reg_addr << PMC_SCRATCH54_ADDR_SHIFT); |
| 1359 | tegra_pmc_writel(value, PMC_SCRATCH54); |
| 1360 | |
| 1361 | value = PMC_SCRATCH55_RESET_TEGRA; |
| 1362 | value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT; |
| 1363 | value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT; |
| 1364 | value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT; |
| 1365 | |
| 1366 | /* |
| 1367 | * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will |
| 1368 | * contain the checksum and are currently zero, so they are not added. |
| 1369 | */ |
| 1370 | checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff) |
| 1371 | + ((value >> 24) & 0xff); |
| 1372 | checksum &= 0xff; |
| 1373 | checksum = 0x100 - checksum; |
| 1374 | |
| 1375 | value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT; |
| 1376 | |
| 1377 | tegra_pmc_writel(value, PMC_SCRATCH55); |
| 1378 | |
| 1379 | value = tegra_pmc_readl(PMC_SENSOR_CTRL); |
| 1380 | value |= PMC_SENSOR_CTRL_ENABLE_RST; |
| 1381 | tegra_pmc_writel(value, PMC_SENSOR_CTRL); |
| 1382 | |
| 1383 | dev_info(pmc->dev, "emergency thermal reset enabled\n"); |
| 1384 | |
| 1385 | out: |
| 1386 | of_node_put(np); |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1389 | static int tegra_pmc_probe(struct platform_device *pdev) |
| 1390 | { |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1391 | void __iomem *base; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1392 | struct resource *res; |
| 1393 | int err; |
| 1394 | |
Jon Hunter | a83f1fc | 2016-06-28 11:38:28 +0100 | [diff] [blame] | 1395 | /* |
| 1396 | * Early initialisation should have configured an initial |
| 1397 | * register mapping and setup the soc data pointer. If these |
| 1398 | * are not valid then something went badly wrong! |
| 1399 | */ |
| 1400 | if (WARN_ON(!pmc->base || !pmc->soc)) |
| 1401 | return -ENODEV; |
| 1402 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1403 | err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node); |
| 1404 | if (err < 0) |
| 1405 | return err; |
| 1406 | |
| 1407 | /* take over the memory region from the early initialization */ |
| 1408 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 1409 | base = devm_ioremap_resource(&pdev->dev, res); |
| 1410 | if (IS_ERR(base)) |
| 1411 | return PTR_ERR(base); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1412 | |
| 1413 | pmc->clk = devm_clk_get(&pdev->dev, "pclk"); |
| 1414 | if (IS_ERR(pmc->clk)) { |
| 1415 | err = PTR_ERR(pmc->clk); |
| 1416 | dev_err(&pdev->dev, "failed to get pclk: %d\n", err); |
| 1417 | return err; |
| 1418 | } |
| 1419 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1420 | pmc->dev = &pdev->dev; |
| 1421 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1422 | tegra_pmc_init(pmc); |
| 1423 | |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1424 | tegra_pmc_init_tsense_reset(pmc); |
| 1425 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1426 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
| 1427 | err = tegra_powergate_debugfs_init(); |
| 1428 | if (err < 0) |
| 1429 | return err; |
| 1430 | } |
| 1431 | |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 1432 | err = register_restart_handler(&tegra_pmc_restart_handler); |
| 1433 | if (err) { |
Jon Hunter | 3195ac6 | 2015-12-04 14:57:05 +0000 | [diff] [blame] | 1434 | debugfs_remove(pmc->debugfs); |
David Riley | 7892158 | 2015-03-18 10:52:25 +0100 | [diff] [blame] | 1435 | dev_err(&pdev->dev, "unable to register restart handler, %d\n", |
| 1436 | err); |
| 1437 | return err; |
| 1438 | } |
| 1439 | |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1440 | mutex_lock(&pmc->powergates_lock); |
| 1441 | iounmap(pmc->base); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 1442 | pmc->base = base; |
Jon Hunter | e8cf661 | 2016-02-11 18:03:21 +0000 | [diff] [blame] | 1443 | mutex_unlock(&pmc->powergates_lock); |
Jon Hunter | 0259f52 | 2016-02-11 18:03:20 +0000 | [diff] [blame] | 1444 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1445 | return 0; |
| 1446 | } |
| 1447 | |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 1448 | #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1449 | static int tegra_pmc_suspend(struct device *dev) |
| 1450 | { |
| 1451 | tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41); |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | static int tegra_pmc_resume(struct device *dev) |
| 1457 | { |
| 1458 | tegra_pmc_writel(0x0, PMC_SCRATCH41); |
| 1459 | |
| 1460 | return 0; |
| 1461 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1462 | |
| 1463 | static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume); |
| 1464 | |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 1465 | #endif |
| 1466 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1467 | static const char * const tegra20_powergates[] = { |
| 1468 | [TEGRA_POWERGATE_CPU] = "cpu", |
| 1469 | [TEGRA_POWERGATE_3D] = "3d", |
| 1470 | [TEGRA_POWERGATE_VENC] = "venc", |
| 1471 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 1472 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 1473 | [TEGRA_POWERGATE_L2] = "l2", |
| 1474 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 1475 | }; |
| 1476 | |
| 1477 | static const struct tegra_pmc_soc tegra20_pmc_soc = { |
| 1478 | .num_powergates = ARRAY_SIZE(tegra20_powergates), |
| 1479 | .powergates = tegra20_powergates, |
| 1480 | .num_cpu_powergates = 0, |
| 1481 | .cpu_powergates = NULL, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1482 | .has_tsense_reset = false, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 1483 | .has_gpu_clamps = false, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1484 | }; |
| 1485 | |
| 1486 | static const char * const tegra30_powergates[] = { |
| 1487 | [TEGRA_POWERGATE_CPU] = "cpu0", |
| 1488 | [TEGRA_POWERGATE_3D] = "3d0", |
| 1489 | [TEGRA_POWERGATE_VENC] = "venc", |
| 1490 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 1491 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 1492 | [TEGRA_POWERGATE_L2] = "l2", |
| 1493 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 1494 | [TEGRA_POWERGATE_HEG] = "heg", |
| 1495 | [TEGRA_POWERGATE_SATA] = "sata", |
| 1496 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 1497 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 1498 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 1499 | [TEGRA_POWERGATE_CELP] = "celp", |
| 1500 | [TEGRA_POWERGATE_3D1] = "3d1", |
| 1501 | }; |
| 1502 | |
| 1503 | static const u8 tegra30_cpu_powergates[] = { |
| 1504 | TEGRA_POWERGATE_CPU, |
| 1505 | TEGRA_POWERGATE_CPU1, |
| 1506 | TEGRA_POWERGATE_CPU2, |
| 1507 | TEGRA_POWERGATE_CPU3, |
| 1508 | }; |
| 1509 | |
| 1510 | static const struct tegra_pmc_soc tegra30_pmc_soc = { |
| 1511 | .num_powergates = ARRAY_SIZE(tegra30_powergates), |
| 1512 | .powergates = tegra30_powergates, |
| 1513 | .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates), |
| 1514 | .cpu_powergates = tegra30_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1515 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 1516 | .has_gpu_clamps = false, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1517 | }; |
| 1518 | |
| 1519 | static const char * const tegra114_powergates[] = { |
| 1520 | [TEGRA_POWERGATE_CPU] = "crail", |
| 1521 | [TEGRA_POWERGATE_3D] = "3d", |
| 1522 | [TEGRA_POWERGATE_VENC] = "venc", |
| 1523 | [TEGRA_POWERGATE_VDEC] = "vdec", |
| 1524 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 1525 | [TEGRA_POWERGATE_HEG] = "heg", |
| 1526 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 1527 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 1528 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 1529 | [TEGRA_POWERGATE_CELP] = "celp", |
| 1530 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 1531 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
| 1532 | [TEGRA_POWERGATE_C1NC] = "c1nc", |
| 1533 | [TEGRA_POWERGATE_DIS] = "dis", |
| 1534 | [TEGRA_POWERGATE_DISB] = "disb", |
| 1535 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 1536 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 1537 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 1538 | }; |
| 1539 | |
| 1540 | static const u8 tegra114_cpu_powergates[] = { |
| 1541 | TEGRA_POWERGATE_CPU0, |
| 1542 | TEGRA_POWERGATE_CPU1, |
| 1543 | TEGRA_POWERGATE_CPU2, |
| 1544 | TEGRA_POWERGATE_CPU3, |
| 1545 | }; |
| 1546 | |
| 1547 | static const struct tegra_pmc_soc tegra114_pmc_soc = { |
| 1548 | .num_powergates = ARRAY_SIZE(tegra114_powergates), |
| 1549 | .powergates = tegra114_powergates, |
| 1550 | .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates), |
| 1551 | .cpu_powergates = tegra114_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1552 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 1553 | .has_gpu_clamps = false, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1554 | }; |
| 1555 | |
| 1556 | static const char * const tegra124_powergates[] = { |
| 1557 | [TEGRA_POWERGATE_CPU] = "crail", |
| 1558 | [TEGRA_POWERGATE_3D] = "3d", |
| 1559 | [TEGRA_POWERGATE_VENC] = "venc", |
| 1560 | [TEGRA_POWERGATE_PCIE] = "pcie", |
| 1561 | [TEGRA_POWERGATE_VDEC] = "vdec", |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1562 | [TEGRA_POWERGATE_MPE] = "mpe", |
| 1563 | [TEGRA_POWERGATE_HEG] = "heg", |
| 1564 | [TEGRA_POWERGATE_SATA] = "sata", |
| 1565 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 1566 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 1567 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
| 1568 | [TEGRA_POWERGATE_CELP] = "celp", |
| 1569 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 1570 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
| 1571 | [TEGRA_POWERGATE_C1NC] = "c1nc", |
| 1572 | [TEGRA_POWERGATE_SOR] = "sor", |
| 1573 | [TEGRA_POWERGATE_DIS] = "dis", |
| 1574 | [TEGRA_POWERGATE_DISB] = "disb", |
| 1575 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 1576 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 1577 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 1578 | [TEGRA_POWERGATE_VIC] = "vic", |
| 1579 | [TEGRA_POWERGATE_IRAM] = "iram", |
| 1580 | }; |
| 1581 | |
| 1582 | static const u8 tegra124_cpu_powergates[] = { |
| 1583 | TEGRA_POWERGATE_CPU0, |
| 1584 | TEGRA_POWERGATE_CPU1, |
| 1585 | TEGRA_POWERGATE_CPU2, |
| 1586 | TEGRA_POWERGATE_CPU3, |
| 1587 | }; |
| 1588 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1589 | static const struct tegra_io_pad_soc tegra124_io_pads[] = { |
| 1590 | { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = UINT_MAX }, |
| 1591 | { .id = TEGRA_IO_PAD_BB, .dpd = 15, .voltage = UINT_MAX }, |
| 1592 | { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = UINT_MAX }, |
| 1593 | { .id = TEGRA_IO_PAD_COMP, .dpd = 22, .voltage = UINT_MAX }, |
| 1594 | { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX }, |
| 1595 | { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX }, |
| 1596 | { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX }, |
| 1597 | { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX }, |
| 1598 | { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX }, |
| 1599 | { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX }, |
| 1600 | { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX }, |
| 1601 | { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX }, |
| 1602 | { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX }, |
| 1603 | { .id = TEGRA_IO_PAD_HV, .dpd = 38, .voltage = UINT_MAX }, |
| 1604 | { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX }, |
| 1605 | { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX }, |
| 1606 | { .id = TEGRA_IO_PAD_NAND, .dpd = 13, .voltage = UINT_MAX }, |
| 1607 | { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX }, |
| 1608 | { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX }, |
| 1609 | { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX }, |
| 1610 | { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = 32, .voltage = UINT_MAX }, |
| 1611 | { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = UINT_MAX }, |
| 1612 | { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = UINT_MAX }, |
| 1613 | { .id = TEGRA_IO_PAD_SDMMC4, .dpd = 35, .voltage = UINT_MAX }, |
| 1614 | { .id = TEGRA_IO_PAD_SYS_DDC, .dpd = 58, .voltage = UINT_MAX }, |
| 1615 | { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = UINT_MAX }, |
| 1616 | { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX }, |
| 1617 | { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX }, |
| 1618 | { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX }, |
| 1619 | { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX }, |
| 1620 | }; |
| 1621 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1622 | static const struct tegra_pmc_soc tegra124_pmc_soc = { |
| 1623 | .num_powergates = ARRAY_SIZE(tegra124_powergates), |
| 1624 | .powergates = tegra124_powergates, |
| 1625 | .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates), |
| 1626 | .cpu_powergates = tegra124_cpu_powergates, |
Mikko Perttunen | 3568df3 | 2015-01-06 12:52:58 +0200 | [diff] [blame] | 1627 | .has_tsense_reset = true, |
Thierry Reding | a9a40a4 | 2015-01-09 11:15:33 +0100 | [diff] [blame] | 1628 | .has_gpu_clamps = true, |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1629 | .num_io_pads = ARRAY_SIZE(tegra124_io_pads), |
| 1630 | .io_pads = tegra124_io_pads, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1631 | }; |
| 1632 | |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1633 | static const char * const tegra210_powergates[] = { |
| 1634 | [TEGRA_POWERGATE_CPU] = "crail", |
| 1635 | [TEGRA_POWERGATE_3D] = "3d", |
| 1636 | [TEGRA_POWERGATE_VENC] = "venc", |
| 1637 | [TEGRA_POWERGATE_PCIE] = "pcie", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1638 | [TEGRA_POWERGATE_MPE] = "mpe", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1639 | [TEGRA_POWERGATE_SATA] = "sata", |
| 1640 | [TEGRA_POWERGATE_CPU1] = "cpu1", |
| 1641 | [TEGRA_POWERGATE_CPU2] = "cpu2", |
| 1642 | [TEGRA_POWERGATE_CPU3] = "cpu3", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1643 | [TEGRA_POWERGATE_CPU0] = "cpu0", |
| 1644 | [TEGRA_POWERGATE_C0NC] = "c0nc", |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1645 | [TEGRA_POWERGATE_SOR] = "sor", |
| 1646 | [TEGRA_POWERGATE_DIS] = "dis", |
| 1647 | [TEGRA_POWERGATE_DISB] = "disb", |
| 1648 | [TEGRA_POWERGATE_XUSBA] = "xusba", |
| 1649 | [TEGRA_POWERGATE_XUSBB] = "xusbb", |
| 1650 | [TEGRA_POWERGATE_XUSBC] = "xusbc", |
| 1651 | [TEGRA_POWERGATE_VIC] = "vic", |
| 1652 | [TEGRA_POWERGATE_IRAM] = "iram", |
| 1653 | [TEGRA_POWERGATE_NVDEC] = "nvdec", |
| 1654 | [TEGRA_POWERGATE_NVJPG] = "nvjpg", |
| 1655 | [TEGRA_POWERGATE_AUD] = "aud", |
| 1656 | [TEGRA_POWERGATE_DFD] = "dfd", |
| 1657 | [TEGRA_POWERGATE_VE2] = "ve2", |
| 1658 | }; |
| 1659 | |
| 1660 | static const u8 tegra210_cpu_powergates[] = { |
| 1661 | TEGRA_POWERGATE_CPU0, |
| 1662 | TEGRA_POWERGATE_CPU1, |
| 1663 | TEGRA_POWERGATE_CPU2, |
| 1664 | TEGRA_POWERGATE_CPU3, |
| 1665 | }; |
| 1666 | |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1667 | static const struct tegra_io_pad_soc tegra210_io_pads[] = { |
| 1668 | { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = 5 }, |
| 1669 | { .id = TEGRA_IO_PAD_AUDIO_HV, .dpd = 61, .voltage = 18 }, |
| 1670 | { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = 10 }, |
| 1671 | { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX }, |
| 1672 | { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX }, |
| 1673 | { .id = TEGRA_IO_PAD_CSIC, .dpd = 42, .voltage = UINT_MAX }, |
| 1674 | { .id = TEGRA_IO_PAD_CSID, .dpd = 43, .voltage = UINT_MAX }, |
| 1675 | { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX }, |
| 1676 | { .id = TEGRA_IO_PAD_CSIF, .dpd = 45, .voltage = UINT_MAX }, |
| 1677 | { .id = TEGRA_IO_PAD_DBG, .dpd = 25, .voltage = 19 }, |
| 1678 | { .id = TEGRA_IO_PAD_DEBUG_NONAO, .dpd = 26, .voltage = UINT_MAX }, |
| 1679 | { .id = TEGRA_IO_PAD_DMIC, .dpd = 50, .voltage = 20 }, |
| 1680 | { .id = TEGRA_IO_PAD_DP, .dpd = 51, .voltage = UINT_MAX }, |
| 1681 | { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX }, |
| 1682 | { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX }, |
| 1683 | { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX }, |
| 1684 | { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX }, |
| 1685 | { .id = TEGRA_IO_PAD_EMMC, .dpd = 35, .voltage = UINT_MAX }, |
| 1686 | { .id = TEGRA_IO_PAD_EMMC2, .dpd = 37, .voltage = UINT_MAX }, |
| 1687 | { .id = TEGRA_IO_PAD_GPIO, .dpd = 27, .voltage = 21 }, |
| 1688 | { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX }, |
| 1689 | { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX }, |
| 1690 | { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX }, |
| 1691 | { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX }, |
| 1692 | { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX }, |
| 1693 | { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX }, |
| 1694 | { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX }, |
| 1695 | { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = UINT_MAX, .voltage = 11 }, |
| 1696 | { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = 12 }, |
| 1697 | { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = 13 }, |
| 1698 | { .id = TEGRA_IO_PAD_SPI, .dpd = 46, .voltage = 22 }, |
| 1699 | { .id = TEGRA_IO_PAD_SPI_HV, .dpd = 47, .voltage = 23 }, |
| 1700 | { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = 2 }, |
| 1701 | { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX }, |
| 1702 | { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX }, |
| 1703 | { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX }, |
| 1704 | { .id = TEGRA_IO_PAD_USB3, .dpd = 18, .voltage = UINT_MAX }, |
| 1705 | { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX }, |
| 1706 | }; |
| 1707 | |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1708 | static const struct tegra_pmc_soc tegra210_pmc_soc = { |
| 1709 | .num_powergates = ARRAY_SIZE(tegra210_powergates), |
| 1710 | .powergates = tegra210_powergates, |
| 1711 | .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates), |
| 1712 | .cpu_powergates = tegra210_cpu_powergates, |
| 1713 | .has_tsense_reset = true, |
| 1714 | .has_gpu_clamps = true, |
Laxman Dewangan | 21b4991 | 2016-10-10 15:14:34 +0200 | [diff] [blame] | 1715 | .num_io_pads = ARRAY_SIZE(tegra210_io_pads), |
| 1716 | .io_pads = tegra210_io_pads, |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1717 | }; |
| 1718 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1719 | static const struct of_device_id tegra_pmc_match[] = { |
Thierry Reding | c2fe469 | 2015-03-23 11:31:29 +0100 | [diff] [blame] | 1720 | { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc }, |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1721 | { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc }, |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1722 | { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc }, |
| 1723 | { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc }, |
| 1724 | { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc }, |
| 1725 | { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc }, |
| 1726 | { } |
| 1727 | }; |
| 1728 | |
| 1729 | static struct platform_driver tegra_pmc_driver = { |
| 1730 | .driver = { |
| 1731 | .name = "tegra-pmc", |
| 1732 | .suppress_bind_attrs = true, |
| 1733 | .of_match_table = tegra_pmc_match, |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 1734 | #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM) |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1735 | .pm = &tegra_pmc_pm_ops, |
Paul Walmsley | 2b20b61 | 2014-12-09 22:36:50 +0000 | [diff] [blame] | 1736 | #endif |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1737 | }, |
| 1738 | .probe = tegra_pmc_probe, |
| 1739 | }; |
Paul Gortmaker | 7d4d9ed | 2015-05-01 20:10:57 -0400 | [diff] [blame] | 1740 | builtin_platform_driver(tegra_pmc_driver); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1741 | |
| 1742 | /* |
| 1743 | * Early initialization to allow access to registers in the very early boot |
| 1744 | * process. |
| 1745 | */ |
| 1746 | static int __init tegra_pmc_early_init(void) |
| 1747 | { |
| 1748 | const struct of_device_id *match; |
| 1749 | struct device_node *np; |
| 1750 | struct resource regs; |
| 1751 | bool invert; |
| 1752 | u32 value; |
| 1753 | |
Jon Hunter | 61fd284 | 2016-06-28 11:38:26 +0100 | [diff] [blame] | 1754 | mutex_init(&pmc->powergates_lock); |
| 1755 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1756 | np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match); |
| 1757 | if (!np) { |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1758 | /* |
| 1759 | * Fall back to legacy initialization for 32-bit ARM only. All |
| 1760 | * 64-bit ARM device tree files for Tegra are required to have |
| 1761 | * a PMC node. |
| 1762 | * |
| 1763 | * This is for backwards-compatibility with old device trees |
| 1764 | * that didn't contain a PMC node. Note that in this case the |
| 1765 | * SoC data can't be matched and therefore powergating is |
| 1766 | * disabled. |
| 1767 | */ |
| 1768 | if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) { |
| 1769 | pr_warn("DT node not found, powergating disabled\n"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1770 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1771 | regs.start = 0x7000e400; |
| 1772 | regs.end = 0x7000e7ff; |
| 1773 | regs.flags = IORESOURCE_MEM; |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1774 | |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1775 | pr_warn("Using memory region %pR\n", ®s); |
| 1776 | } else { |
| 1777 | /* |
| 1778 | * At this point we're not running on Tegra, so play |
| 1779 | * nice with multi-platform kernels. |
| 1780 | */ |
| 1781 | return 0; |
| 1782 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1783 | } else { |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1784 | /* |
| 1785 | * Extract information from the device tree if we've found a |
| 1786 | * matching node. |
| 1787 | */ |
| 1788 | if (of_address_to_resource(np, 0, ®s) < 0) { |
| 1789 | pr_err("failed to get PMC registers\n"); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 1790 | of_node_put(np); |
Thierry Reding | 7d71e903 | 2015-04-29 12:42:28 +0200 | [diff] [blame] | 1791 | return -ENXIO; |
| 1792 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | pmc->base = ioremap_nocache(regs.start, resource_size(®s)); |
| 1796 | if (!pmc->base) { |
| 1797 | pr_err("failed to map PMC registers\n"); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 1798 | of_node_put(np); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1799 | return -ENXIO; |
| 1800 | } |
| 1801 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 1802 | if (np) { |
Jon Hunter | 718a242 | 2016-06-28 11:38:25 +0100 | [diff] [blame] | 1803 | pmc->soc = match->data; |
| 1804 | |
Jon Hunter | e2d1796 | 2016-06-30 11:56:25 +0100 | [diff] [blame] | 1805 | tegra_powergate_init(pmc, np); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1806 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 1807 | /* |
| 1808 | * Invert the interrupt polarity if a PMC device tree node |
| 1809 | * exists and contains the nvidia,invert-interrupt property. |
| 1810 | */ |
| 1811 | invert = of_property_read_bool(np, "nvidia,invert-interrupt"); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1812 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 1813 | value = tegra_pmc_readl(PMC_CNTRL); |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1814 | |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 1815 | if (invert) |
| 1816 | value |= PMC_CNTRL_INTR_POLARITY; |
| 1817 | else |
| 1818 | value &= ~PMC_CNTRL_INTR_POLARITY; |
| 1819 | |
| 1820 | tegra_pmc_writel(value, PMC_CNTRL); |
Jon Hunter | b69a625 | 2016-06-28 11:38:27 +0100 | [diff] [blame] | 1821 | |
| 1822 | of_node_put(np); |
Jon Hunter | 1113189 | 2016-06-28 11:38:24 +0100 | [diff] [blame] | 1823 | } |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 1824 | |
| 1825 | return 0; |
| 1826 | } |
| 1827 | early_initcall(tegra_pmc_early_init); |