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