blob: 900f72f0d757dde619210dc4b3a1511421ef9d82 [file] [log] [blame]
Thierry Reding72323982014-07-11 13:19:06 +02001/*
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 Reding7d71e9032015-04-29 12:42:28 +020020#define pr_fmt(fmt) "tegra-pmc: " fmt
21
Thierry Reding72323982014-07-11 13:19:06 +020022#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>
31#include <linux/of.h>
32#include <linux/of_address.h>
33#include <linux/platform_device.h>
34#include <linux/reboot.h>
35#include <linux/reset.h>
36#include <linux/seq_file.h>
37#include <linux/spinlock.h>
38
39#include <soc/tegra/common.h>
40#include <soc/tegra/fuse.h>
41#include <soc/tegra/pmc.h>
42
43#define PMC_CNTRL 0x0
44#define PMC_CNTRL_SYSCLK_POLARITY (1 << 10) /* sys clk polarity */
45#define PMC_CNTRL_SYSCLK_OE (1 << 11) /* system clock enable */
46#define PMC_CNTRL_SIDE_EFFECT_LP0 (1 << 14) /* LP0 when CPU pwr gated */
47#define PMC_CNTRL_CPU_PWRREQ_POLARITY (1 << 15) /* CPU pwr req polarity */
48#define PMC_CNTRL_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */
49#define PMC_CNTRL_INTR_POLARITY (1 << 17) /* inverts INTR polarity */
50
51#define DPD_SAMPLE 0x020
52#define DPD_SAMPLE_ENABLE (1 << 0)
53#define DPD_SAMPLE_DISABLE (0 << 0)
54
55#define PWRGATE_TOGGLE 0x30
56#define PWRGATE_TOGGLE_START (1 << 8)
57
58#define REMOVE_CLAMPING 0x34
59
60#define PWRGATE_STATUS 0x38
61
62#define PMC_SCRATCH0 0x50
63#define PMC_SCRATCH0_MODE_RECOVERY (1 << 31)
64#define PMC_SCRATCH0_MODE_BOOTLOADER (1 << 30)
65#define PMC_SCRATCH0_MODE_RCM (1 << 1)
66#define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
67 PMC_SCRATCH0_MODE_BOOTLOADER | \
68 PMC_SCRATCH0_MODE_RCM)
69
70#define PMC_CPUPWRGOOD_TIMER 0xc8
71#define PMC_CPUPWROFF_TIMER 0xcc
72
73#define PMC_SCRATCH41 0x140
74
Mikko Perttunen3568df32015-01-06 12:52:58 +020075#define PMC_SENSOR_CTRL 0x1b0
76#define PMC_SENSOR_CTRL_SCRATCH_WRITE (1 << 2)
77#define PMC_SENSOR_CTRL_ENABLE_RST (1 << 1)
78
Thierry Reding72323982014-07-11 13:19:06 +020079#define IO_DPD_REQ 0x1b8
80#define IO_DPD_REQ_CODE_IDLE (0 << 30)
81#define IO_DPD_REQ_CODE_OFF (1 << 30)
82#define IO_DPD_REQ_CODE_ON (2 << 30)
83#define IO_DPD_REQ_CODE_MASK (3 << 30)
84
85#define IO_DPD_STATUS 0x1bc
86#define IO_DPD2_REQ 0x1c0
87#define IO_DPD2_STATUS 0x1c4
88#define SEL_DPD_TIM 0x1c8
89
Mikko Perttunen3568df32015-01-06 12:52:58 +020090#define PMC_SCRATCH54 0x258
91#define PMC_SCRATCH54_DATA_SHIFT 8
92#define PMC_SCRATCH54_ADDR_SHIFT 0
93
94#define PMC_SCRATCH55 0x25c
95#define PMC_SCRATCH55_RESET_TEGRA (1 << 31)
96#define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
97#define PMC_SCRATCH55_PINMUX_SHIFT 24
98#define PMC_SCRATCH55_16BITOP (1 << 15)
99#define PMC_SCRATCH55_CHECKSUM_SHIFT 16
100#define PMC_SCRATCH55_I2CSLV1_SHIFT 0
101
Thierry Reding72323982014-07-11 13:19:06 +0200102#define GPU_RG_CNTRL 0x2d4
103
104struct tegra_pmc_soc {
105 unsigned int num_powergates;
106 const char *const *powergates;
107 unsigned int num_cpu_powergates;
108 const u8 *cpu_powergates;
Thierry Redinga9a40a42015-01-09 11:15:33 +0100109
Mikko Perttunen3568df32015-01-06 12:52:58 +0200110 bool has_tsense_reset;
Thierry Redinga9a40a42015-01-09 11:15:33 +0100111 bool has_gpu_clamps;
Thierry Reding72323982014-07-11 13:19:06 +0200112};
113
114/**
115 * struct tegra_pmc - NVIDIA Tegra PMC
Jon Hunter35b67292015-12-04 14:57:03 +0000116 * @dev: pointer to PMC device structure
Thierry Reding72323982014-07-11 13:19:06 +0200117 * @base: pointer to I/O remapped register region
118 * @clk: pointer to pclk clock
Jon Hunter35b67292015-12-04 14:57:03 +0000119 * @soc: pointer to SoC data structure
Jon Hunter3195ac62015-12-04 14:57:05 +0000120 * @debugfs: pointer to debugfs entry
Thierry Reding72323982014-07-11 13:19:06 +0200121 * @rate: currently configured rate of pclk
122 * @suspend_mode: lowest suspend mode available
123 * @cpu_good_time: CPU power good time (in microseconds)
124 * @cpu_off_time: CPU power off time (in microsecends)
125 * @core_osc_time: core power good OSC time (in microseconds)
126 * @core_pmu_time: core power good PMU time (in microseconds)
127 * @core_off_time: core power off time (in microseconds)
128 * @corereq_high: core power request is active-high
129 * @sysclkreq_high: system clock request is active-high
130 * @combined_req: combined power request for CPU & core
131 * @cpu_pwr_good_en: CPU power good signal is enabled
132 * @lp0_vec_phys: physical base address of the LP0 warm boot code
133 * @lp0_vec_size: size of the LP0 warm boot code
134 * @powergates_lock: mutex for power gate register access
135 */
136struct tegra_pmc {
Mikko Perttunen3568df32015-01-06 12:52:58 +0200137 struct device *dev;
Thierry Reding72323982014-07-11 13:19:06 +0200138 void __iomem *base;
139 struct clk *clk;
Jon Hunter3195ac62015-12-04 14:57:05 +0000140 struct dentry *debugfs;
Thierry Reding72323982014-07-11 13:19:06 +0200141
142 const struct tegra_pmc_soc *soc;
143
144 unsigned long rate;
145
146 enum tegra_suspend_mode suspend_mode;
147 u32 cpu_good_time;
148 u32 cpu_off_time;
149 u32 core_osc_time;
150 u32 core_pmu_time;
151 u32 core_off_time;
152 bool corereq_high;
153 bool sysclkreq_high;
154 bool combined_req;
155 bool cpu_pwr_good_en;
156 u32 lp0_vec_phys;
157 u32 lp0_vec_size;
158
159 struct mutex powergates_lock;
160};
161
162static struct tegra_pmc *pmc = &(struct tegra_pmc) {
163 .base = NULL,
164 .suspend_mode = TEGRA_SUSPEND_NONE,
165};
166
167static u32 tegra_pmc_readl(unsigned long offset)
168{
169 return readl(pmc->base + offset);
170}
171
172static void tegra_pmc_writel(u32 value, unsigned long offset)
173{
174 writel(value, pmc->base + offset);
175}
176
177/**
178 * tegra_powergate_set() - set the state of a partition
179 * @id: partition ID
180 * @new_state: new state of the partition
181 */
182static int tegra_powergate_set(int id, bool new_state)
183{
184 bool status;
185
186 mutex_lock(&pmc->powergates_lock);
187
188 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
189
190 if (status == new_state) {
191 mutex_unlock(&pmc->powergates_lock);
192 return 0;
193 }
194
195 tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
196
197 mutex_unlock(&pmc->powergates_lock);
198
199 return 0;
200}
201
202/**
203 * tegra_powergate_power_on() - power on partition
204 * @id: partition ID
205 */
206int tegra_powergate_power_on(int id)
207{
208 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
209 return -EINVAL;
210
211 return tegra_powergate_set(id, true);
212}
213
214/**
215 * tegra_powergate_power_off() - power off partition
216 * @id: partition ID
217 */
218int tegra_powergate_power_off(int id)
219{
220 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
221 return -EINVAL;
222
223 return tegra_powergate_set(id, false);
224}
225EXPORT_SYMBOL(tegra_powergate_power_off);
226
227/**
228 * tegra_powergate_is_powered() - check if partition is powered
229 * @id: partition ID
230 */
231int tegra_powergate_is_powered(int id)
232{
233 u32 status;
234
235 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
236 return -EINVAL;
237
238 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
239 return !!status;
240}
241
242/**
243 * tegra_powergate_remove_clamping() - remove power clamps for partition
244 * @id: partition ID
245 */
246int tegra_powergate_remove_clamping(int id)
247{
248 u32 mask;
249
250 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
251 return -EINVAL;
252
253 /*
Thierry Redinga9a40a42015-01-09 11:15:33 +0100254 * On Tegra124 and later, the clamps for the GPU are controlled by a
255 * separate register (with different semantics).
Thierry Reding72323982014-07-11 13:19:06 +0200256 */
Thierry Redinga9a40a42015-01-09 11:15:33 +0100257 if (id == TEGRA_POWERGATE_3D) {
258 if (pmc->soc->has_gpu_clamps) {
Thierry Reding72323982014-07-11 13:19:06 +0200259 tegra_pmc_writel(0, GPU_RG_CNTRL);
260 return 0;
261 }
262 }
263
264 /*
265 * Tegra 2 has a bug where PCIE and VDE clamping masks are
266 * swapped relatively to the partition ids
267 */
268 if (id == TEGRA_POWERGATE_VDEC)
269 mask = (1 << TEGRA_POWERGATE_PCIE);
270 else if (id == TEGRA_POWERGATE_PCIE)
271 mask = (1 << TEGRA_POWERGATE_VDEC);
272 else
273 mask = (1 << id);
274
275 tegra_pmc_writel(mask, REMOVE_CLAMPING);
276
277 return 0;
278}
279EXPORT_SYMBOL(tegra_powergate_remove_clamping);
280
281/**
282 * tegra_powergate_sequence_power_up() - power up partition
283 * @id: partition ID
284 * @clk: clock for partition
285 * @rst: reset for partition
286 *
287 * Must be called with clk disabled, and returns with clk enabled.
288 */
289int tegra_powergate_sequence_power_up(int id, struct clk *clk,
290 struct reset_control *rst)
291{
292 int ret;
293
294 reset_control_assert(rst);
295
296 ret = tegra_powergate_power_on(id);
297 if (ret)
298 goto err_power;
299
300 ret = clk_prepare_enable(clk);
301 if (ret)
302 goto err_clk;
303
304 usleep_range(10, 20);
305
306 ret = tegra_powergate_remove_clamping(id);
307 if (ret)
308 goto err_clamp;
309
310 usleep_range(10, 20);
311 reset_control_deassert(rst);
312
313 return 0;
314
315err_clamp:
316 clk_disable_unprepare(clk);
317err_clk:
318 tegra_powergate_power_off(id);
319err_power:
320 return ret;
321}
322EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
323
324#ifdef CONFIG_SMP
325/**
326 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
327 * @cpuid: CPU partition ID
328 *
329 * Returns the partition ID corresponding to the CPU partition ID or a
330 * negative error code on failure.
331 */
332static int tegra_get_cpu_powergate_id(int cpuid)
333{
334 if (pmc->soc && cpuid > 0 && cpuid < pmc->soc->num_cpu_powergates)
335 return pmc->soc->cpu_powergates[cpuid];
336
337 return -EINVAL;
338}
339
340/**
341 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
342 * @cpuid: CPU partition ID
343 */
344bool tegra_pmc_cpu_is_powered(int cpuid)
345{
346 int id;
347
348 id = tegra_get_cpu_powergate_id(cpuid);
349 if (id < 0)
350 return false;
351
352 return tegra_powergate_is_powered(id);
353}
354
355/**
356 * tegra_pmc_cpu_power_on() - power on CPU partition
357 * @cpuid: CPU partition ID
358 */
359int tegra_pmc_cpu_power_on(int cpuid)
360{
361 int id;
362
363 id = tegra_get_cpu_powergate_id(cpuid);
364 if (id < 0)
365 return id;
366
367 return tegra_powergate_set(id, true);
368}
369
370/**
371 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
372 * @cpuid: CPU partition ID
373 */
374int tegra_pmc_cpu_remove_clamping(int cpuid)
375{
376 int id;
377
378 id = tegra_get_cpu_powergate_id(cpuid);
379 if (id < 0)
380 return id;
381
382 return tegra_powergate_remove_clamping(id);
383}
384#endif /* CONFIG_SMP */
385
David Riley78921582015-03-18 10:52:25 +0100386static int tegra_pmc_restart_notify(struct notifier_block *this,
387 unsigned long action, void *data)
Thierry Reding72323982014-07-11 13:19:06 +0200388{
David Riley78921582015-03-18 10:52:25 +0100389 const char *cmd = data;
Thierry Reding72323982014-07-11 13:19:06 +0200390 u32 value;
391
392 value = tegra_pmc_readl(PMC_SCRATCH0);
393 value &= ~PMC_SCRATCH0_MODE_MASK;
394
395 if (cmd) {
396 if (strcmp(cmd, "recovery") == 0)
397 value |= PMC_SCRATCH0_MODE_RECOVERY;
398
399 if (strcmp(cmd, "bootloader") == 0)
400 value |= PMC_SCRATCH0_MODE_BOOTLOADER;
401
402 if (strcmp(cmd, "forced-recovery") == 0)
403 value |= PMC_SCRATCH0_MODE_RCM;
404 }
405
406 tegra_pmc_writel(value, PMC_SCRATCH0);
407
408 value = tegra_pmc_readl(0);
409 value |= 0x10;
410 tegra_pmc_writel(value, 0);
David Riley78921582015-03-18 10:52:25 +0100411
412 return NOTIFY_DONE;
Thierry Reding72323982014-07-11 13:19:06 +0200413}
414
David Riley78921582015-03-18 10:52:25 +0100415static struct notifier_block tegra_pmc_restart_handler = {
416 .notifier_call = tegra_pmc_restart_notify,
417 .priority = 128,
418};
419
Thierry Reding72323982014-07-11 13:19:06 +0200420static int powergate_show(struct seq_file *s, void *data)
421{
422 unsigned int i;
423
424 seq_printf(s, " powergate powered\n");
425 seq_printf(s, "------------------\n");
426
427 for (i = 0; i < pmc->soc->num_powergates; i++) {
428 if (!pmc->soc->powergates[i])
429 continue;
430
431 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
432 tegra_powergate_is_powered(i) ? "yes" : "no");
433 }
434
435 return 0;
436}
437
438static int powergate_open(struct inode *inode, struct file *file)
439{
440 return single_open(file, powergate_show, inode->i_private);
441}
442
443static const struct file_operations powergate_fops = {
444 .open = powergate_open,
445 .read = seq_read,
446 .llseek = seq_lseek,
447 .release = single_release,
448};
449
450static int tegra_powergate_debugfs_init(void)
451{
Jon Hunter3195ac62015-12-04 14:57:05 +0000452 pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
453 &powergate_fops);
454 if (!pmc->debugfs)
Thierry Reding72323982014-07-11 13:19:06 +0200455 return -ENOMEM;
456
457 return 0;
458}
459
460static int tegra_io_rail_prepare(int id, unsigned long *request,
461 unsigned long *status, unsigned int *bit)
462{
463 unsigned long rate, value;
Thierry Reding72323982014-07-11 13:19:06 +0200464
465 *bit = id % 32;
466
467 /*
468 * There are two sets of 30 bits to select IO rails, but bits 30 and
469 * 31 are control bits rather than IO rail selection bits.
470 */
471 if (id > 63 || *bit == 30 || *bit == 31)
472 return -EINVAL;
473
474 if (id < 32) {
475 *status = IO_DPD_STATUS;
476 *request = IO_DPD_REQ;
477 } else {
478 *status = IO_DPD2_STATUS;
479 *request = IO_DPD2_REQ;
480 }
481
Thierry Reding592431b2015-08-04 15:25:03 +0200482 rate = clk_get_rate(pmc->clk);
Thierry Reding72323982014-07-11 13:19:06 +0200483
484 tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
485
486 /* must be at least 200 ns, in APB (PCLK) clock cycles */
487 value = DIV_ROUND_UP(1000000000, rate);
488 value = DIV_ROUND_UP(200, value);
489 tegra_pmc_writel(value, SEL_DPD_TIM);
490
491 return 0;
492}
493
494static int tegra_io_rail_poll(unsigned long offset, unsigned long mask,
495 unsigned long val, unsigned long timeout)
496{
497 unsigned long value;
498
499 timeout = jiffies + msecs_to_jiffies(timeout);
500
501 while (time_after(timeout, jiffies)) {
502 value = tegra_pmc_readl(offset);
503 if ((value & mask) == val)
504 return 0;
505
506 usleep_range(250, 1000);
507 }
508
509 return -ETIMEDOUT;
510}
511
512static void tegra_io_rail_unprepare(void)
513{
514 tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
515}
516
517int tegra_io_rail_power_on(int id)
518{
519 unsigned long request, status, value;
520 unsigned int bit, mask;
521 int err;
522
523 err = tegra_io_rail_prepare(id, &request, &status, &bit);
524 if (err < 0)
525 return err;
526
527 mask = 1 << bit;
528
529 value = tegra_pmc_readl(request);
530 value |= mask;
531 value &= ~IO_DPD_REQ_CODE_MASK;
532 value |= IO_DPD_REQ_CODE_OFF;
533 tegra_pmc_writel(value, request);
534
535 err = tegra_io_rail_poll(status, mask, 0, 250);
Thierry Reding592431b2015-08-04 15:25:03 +0200536 if (err < 0) {
537 pr_info("tegra_io_rail_poll() failed: %d\n", err);
Thierry Reding72323982014-07-11 13:19:06 +0200538 return err;
Thierry Reding592431b2015-08-04 15:25:03 +0200539 }
Thierry Reding72323982014-07-11 13:19:06 +0200540
541 tegra_io_rail_unprepare();
542
543 return 0;
544}
545EXPORT_SYMBOL(tegra_io_rail_power_on);
546
547int tegra_io_rail_power_off(int id)
548{
549 unsigned long request, status, value;
550 unsigned int bit, mask;
551 int err;
552
553 err = tegra_io_rail_prepare(id, &request, &status, &bit);
Thierry Reding592431b2015-08-04 15:25:03 +0200554 if (err < 0) {
555 pr_info("tegra_io_rail_prepare() failed: %d\n", err);
Thierry Reding72323982014-07-11 13:19:06 +0200556 return err;
Thierry Reding592431b2015-08-04 15:25:03 +0200557 }
Thierry Reding72323982014-07-11 13:19:06 +0200558
559 mask = 1 << bit;
560
561 value = tegra_pmc_readl(request);
562 value |= mask;
563 value &= ~IO_DPD_REQ_CODE_MASK;
564 value |= IO_DPD_REQ_CODE_ON;
565 tegra_pmc_writel(value, request);
566
567 err = tegra_io_rail_poll(status, mask, mask, 250);
568 if (err < 0)
569 return err;
570
571 tegra_io_rail_unprepare();
572
573 return 0;
574}
575EXPORT_SYMBOL(tegra_io_rail_power_off);
576
577#ifdef CONFIG_PM_SLEEP
578enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
579{
580 return pmc->suspend_mode;
581}
582
583void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
584{
585 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
586 return;
587
588 pmc->suspend_mode = mode;
589}
590
591void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
592{
593 unsigned long long rate = 0;
594 u32 value;
595
596 switch (mode) {
597 case TEGRA_SUSPEND_LP1:
598 rate = 32768;
599 break;
600
601 case TEGRA_SUSPEND_LP2:
602 rate = clk_get_rate(pmc->clk);
603 break;
604
605 default:
606 break;
607 }
608
609 if (WARN_ON_ONCE(rate == 0))
610 rate = 100000000;
611
612 if (rate != pmc->rate) {
613 u64 ticks;
614
615 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
616 do_div(ticks, USEC_PER_SEC);
617 tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
618
619 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
620 do_div(ticks, USEC_PER_SEC);
621 tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
622
623 wmb();
624
625 pmc->rate = rate;
626 }
627
628 value = tegra_pmc_readl(PMC_CNTRL);
629 value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
630 value |= PMC_CNTRL_CPU_PWRREQ_OE;
631 tegra_pmc_writel(value, PMC_CNTRL);
632}
633#endif
634
635static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
636{
637 u32 value, values[2];
638
639 if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
640 } else {
641 switch (value) {
642 case 0:
643 pmc->suspend_mode = TEGRA_SUSPEND_LP0;
644 break;
645
646 case 1:
647 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
648 break;
649
650 case 2:
651 pmc->suspend_mode = TEGRA_SUSPEND_LP2;
652 break;
653
654 default:
655 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
656 break;
657 }
658 }
659
660 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
661
662 if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
663 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
664
665 pmc->cpu_good_time = value;
666
667 if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
668 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
669
670 pmc->cpu_off_time = value;
671
672 if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
673 values, ARRAY_SIZE(values)))
674 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
675
676 pmc->core_osc_time = values[0];
677 pmc->core_pmu_time = values[1];
678
679 if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
680 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
681
682 pmc->core_off_time = value;
683
684 pmc->corereq_high = of_property_read_bool(np,
685 "nvidia,core-power-req-active-high");
686
687 pmc->sysclkreq_high = of_property_read_bool(np,
688 "nvidia,sys-clock-req-active-high");
689
690 pmc->combined_req = of_property_read_bool(np,
691 "nvidia,combined-power-req");
692
693 pmc->cpu_pwr_good_en = of_property_read_bool(np,
694 "nvidia,cpu-pwr-good-en");
695
696 if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
697 ARRAY_SIZE(values)))
698 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
699 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
700
701 pmc->lp0_vec_phys = values[0];
702 pmc->lp0_vec_size = values[1];
703
704 return 0;
705}
706
707static void tegra_pmc_init(struct tegra_pmc *pmc)
708{
709 u32 value;
710
711 /* Always enable CPU power request */
712 value = tegra_pmc_readl(PMC_CNTRL);
713 value |= PMC_CNTRL_CPU_PWRREQ_OE;
714 tegra_pmc_writel(value, PMC_CNTRL);
715
716 value = tegra_pmc_readl(PMC_CNTRL);
717
718 if (pmc->sysclkreq_high)
719 value &= ~PMC_CNTRL_SYSCLK_POLARITY;
720 else
721 value |= PMC_CNTRL_SYSCLK_POLARITY;
722
723 /* configure the output polarity while the request is tristated */
724 tegra_pmc_writel(value, PMC_CNTRL);
725
726 /* now enable the request */
727 value = tegra_pmc_readl(PMC_CNTRL);
728 value |= PMC_CNTRL_SYSCLK_OE;
729 tegra_pmc_writel(value, PMC_CNTRL);
730}
731
Jon Hunter1e52efdf2015-12-04 14:57:04 +0000732static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
Mikko Perttunen3568df32015-01-06 12:52:58 +0200733{
734 static const char disabled[] = "emergency thermal reset disabled";
735 u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
736 struct device *dev = pmc->dev;
737 struct device_node *np;
738 u32 value, checksum;
739
740 if (!pmc->soc->has_tsense_reset)
Thierry Reding95169cd2015-07-09 09:59:55 +0200741 return;
Mikko Perttunen3568df32015-01-06 12:52:58 +0200742
743 np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip");
744 if (!np) {
745 dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
Thierry Reding95169cd2015-07-09 09:59:55 +0200746 return;
Mikko Perttunen3568df32015-01-06 12:52:58 +0200747 }
748
749 if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
750 dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
751 goto out;
752 }
753
754 if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
755 dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
756 goto out;
757 }
758
759 if (of_property_read_u32(np, "nvidia,reg-addr", &reg_addr)) {
760 dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
761 goto out;
762 }
763
764 if (of_property_read_u32(np, "nvidia,reg-data", &reg_data)) {
765 dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
766 goto out;
767 }
768
769 if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
770 pinmux = 0;
771
772 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
773 value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
774 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
775
776 value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
777 (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
778 tegra_pmc_writel(value, PMC_SCRATCH54);
779
780 value = PMC_SCRATCH55_RESET_TEGRA;
781 value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
782 value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
783 value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
784
785 /*
786 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
787 * contain the checksum and are currently zero, so they are not added.
788 */
789 checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
790 + ((value >> 24) & 0xff);
791 checksum &= 0xff;
792 checksum = 0x100 - checksum;
793
794 value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
795
796 tegra_pmc_writel(value, PMC_SCRATCH55);
797
798 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
799 value |= PMC_SENSOR_CTRL_ENABLE_RST;
800 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
801
802 dev_info(pmc->dev, "emergency thermal reset enabled\n");
803
804out:
805 of_node_put(np);
Mikko Perttunen3568df32015-01-06 12:52:58 +0200806}
807
Thierry Reding72323982014-07-11 13:19:06 +0200808static int tegra_pmc_probe(struct platform_device *pdev)
809{
Jon Hunter0259f522016-02-11 18:03:20 +0000810 void __iomem *base, *tmp;
Thierry Reding72323982014-07-11 13:19:06 +0200811 struct resource *res;
812 int err;
813
814 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
815 if (err < 0)
816 return err;
817
818 /* take over the memory region from the early initialization */
819 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jon Hunter0259f522016-02-11 18:03:20 +0000820 base = devm_ioremap_resource(&pdev->dev, res);
821 if (IS_ERR(base))
822 return PTR_ERR(base);
Thierry Reding72323982014-07-11 13:19:06 +0200823
824 pmc->clk = devm_clk_get(&pdev->dev, "pclk");
825 if (IS_ERR(pmc->clk)) {
826 err = PTR_ERR(pmc->clk);
827 dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
828 return err;
829 }
830
Mikko Perttunen3568df32015-01-06 12:52:58 +0200831 pmc->dev = &pdev->dev;
832
Thierry Reding72323982014-07-11 13:19:06 +0200833 tegra_pmc_init(pmc);
834
Mikko Perttunen3568df32015-01-06 12:52:58 +0200835 tegra_pmc_init_tsense_reset(pmc);
836
Thierry Reding72323982014-07-11 13:19:06 +0200837 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
838 err = tegra_powergate_debugfs_init();
839 if (err < 0)
840 return err;
841 }
842
David Riley78921582015-03-18 10:52:25 +0100843 err = register_restart_handler(&tegra_pmc_restart_handler);
844 if (err) {
Jon Hunter3195ac62015-12-04 14:57:05 +0000845 debugfs_remove(pmc->debugfs);
David Riley78921582015-03-18 10:52:25 +0100846 dev_err(&pdev->dev, "unable to register restart handler, %d\n",
847 err);
848 return err;
849 }
850
Jon Hunter0259f522016-02-11 18:03:20 +0000851 tmp = pmc->base;
852 pmc->base = base;
853 iounmap(tmp);
854
Thierry Reding72323982014-07-11 13:19:06 +0200855 return 0;
856}
857
Paul Walmsley2b20b612014-12-09 22:36:50 +0000858#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
Thierry Reding72323982014-07-11 13:19:06 +0200859static int tegra_pmc_suspend(struct device *dev)
860{
861 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
862
863 return 0;
864}
865
866static int tegra_pmc_resume(struct device *dev)
867{
868 tegra_pmc_writel(0x0, PMC_SCRATCH41);
869
870 return 0;
871}
Thierry Reding72323982014-07-11 13:19:06 +0200872
873static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
874
Paul Walmsley2b20b612014-12-09 22:36:50 +0000875#endif
876
Thierry Reding72323982014-07-11 13:19:06 +0200877static const char * const tegra20_powergates[] = {
878 [TEGRA_POWERGATE_CPU] = "cpu",
879 [TEGRA_POWERGATE_3D] = "3d",
880 [TEGRA_POWERGATE_VENC] = "venc",
881 [TEGRA_POWERGATE_VDEC] = "vdec",
882 [TEGRA_POWERGATE_PCIE] = "pcie",
883 [TEGRA_POWERGATE_L2] = "l2",
884 [TEGRA_POWERGATE_MPE] = "mpe",
885};
886
887static const struct tegra_pmc_soc tegra20_pmc_soc = {
888 .num_powergates = ARRAY_SIZE(tegra20_powergates),
889 .powergates = tegra20_powergates,
890 .num_cpu_powergates = 0,
891 .cpu_powergates = NULL,
Mikko Perttunen3568df32015-01-06 12:52:58 +0200892 .has_tsense_reset = false,
Thierry Redinga9a40a42015-01-09 11:15:33 +0100893 .has_gpu_clamps = false,
Thierry Reding72323982014-07-11 13:19:06 +0200894};
895
896static const char * const tegra30_powergates[] = {
897 [TEGRA_POWERGATE_CPU] = "cpu0",
898 [TEGRA_POWERGATE_3D] = "3d0",
899 [TEGRA_POWERGATE_VENC] = "venc",
900 [TEGRA_POWERGATE_VDEC] = "vdec",
901 [TEGRA_POWERGATE_PCIE] = "pcie",
902 [TEGRA_POWERGATE_L2] = "l2",
903 [TEGRA_POWERGATE_MPE] = "mpe",
904 [TEGRA_POWERGATE_HEG] = "heg",
905 [TEGRA_POWERGATE_SATA] = "sata",
906 [TEGRA_POWERGATE_CPU1] = "cpu1",
907 [TEGRA_POWERGATE_CPU2] = "cpu2",
908 [TEGRA_POWERGATE_CPU3] = "cpu3",
909 [TEGRA_POWERGATE_CELP] = "celp",
910 [TEGRA_POWERGATE_3D1] = "3d1",
911};
912
913static const u8 tegra30_cpu_powergates[] = {
914 TEGRA_POWERGATE_CPU,
915 TEGRA_POWERGATE_CPU1,
916 TEGRA_POWERGATE_CPU2,
917 TEGRA_POWERGATE_CPU3,
918};
919
920static const struct tegra_pmc_soc tegra30_pmc_soc = {
921 .num_powergates = ARRAY_SIZE(tegra30_powergates),
922 .powergates = tegra30_powergates,
923 .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
924 .cpu_powergates = tegra30_cpu_powergates,
Mikko Perttunen3568df32015-01-06 12:52:58 +0200925 .has_tsense_reset = true,
Thierry Redinga9a40a42015-01-09 11:15:33 +0100926 .has_gpu_clamps = false,
Thierry Reding72323982014-07-11 13:19:06 +0200927};
928
929static const char * const tegra114_powergates[] = {
930 [TEGRA_POWERGATE_CPU] = "crail",
931 [TEGRA_POWERGATE_3D] = "3d",
932 [TEGRA_POWERGATE_VENC] = "venc",
933 [TEGRA_POWERGATE_VDEC] = "vdec",
934 [TEGRA_POWERGATE_MPE] = "mpe",
935 [TEGRA_POWERGATE_HEG] = "heg",
936 [TEGRA_POWERGATE_CPU1] = "cpu1",
937 [TEGRA_POWERGATE_CPU2] = "cpu2",
938 [TEGRA_POWERGATE_CPU3] = "cpu3",
939 [TEGRA_POWERGATE_CELP] = "celp",
940 [TEGRA_POWERGATE_CPU0] = "cpu0",
941 [TEGRA_POWERGATE_C0NC] = "c0nc",
942 [TEGRA_POWERGATE_C1NC] = "c1nc",
943 [TEGRA_POWERGATE_DIS] = "dis",
944 [TEGRA_POWERGATE_DISB] = "disb",
945 [TEGRA_POWERGATE_XUSBA] = "xusba",
946 [TEGRA_POWERGATE_XUSBB] = "xusbb",
947 [TEGRA_POWERGATE_XUSBC] = "xusbc",
948};
949
950static const u8 tegra114_cpu_powergates[] = {
951 TEGRA_POWERGATE_CPU0,
952 TEGRA_POWERGATE_CPU1,
953 TEGRA_POWERGATE_CPU2,
954 TEGRA_POWERGATE_CPU3,
955};
956
957static const struct tegra_pmc_soc tegra114_pmc_soc = {
958 .num_powergates = ARRAY_SIZE(tegra114_powergates),
959 .powergates = tegra114_powergates,
960 .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
961 .cpu_powergates = tegra114_cpu_powergates,
Mikko Perttunen3568df32015-01-06 12:52:58 +0200962 .has_tsense_reset = true,
Thierry Redinga9a40a42015-01-09 11:15:33 +0100963 .has_gpu_clamps = false,
Thierry Reding72323982014-07-11 13:19:06 +0200964};
965
966static const char * const tegra124_powergates[] = {
967 [TEGRA_POWERGATE_CPU] = "crail",
968 [TEGRA_POWERGATE_3D] = "3d",
969 [TEGRA_POWERGATE_VENC] = "venc",
970 [TEGRA_POWERGATE_PCIE] = "pcie",
971 [TEGRA_POWERGATE_VDEC] = "vdec",
Thierry Reding72323982014-07-11 13:19:06 +0200972 [TEGRA_POWERGATE_MPE] = "mpe",
973 [TEGRA_POWERGATE_HEG] = "heg",
974 [TEGRA_POWERGATE_SATA] = "sata",
975 [TEGRA_POWERGATE_CPU1] = "cpu1",
976 [TEGRA_POWERGATE_CPU2] = "cpu2",
977 [TEGRA_POWERGATE_CPU3] = "cpu3",
978 [TEGRA_POWERGATE_CELP] = "celp",
979 [TEGRA_POWERGATE_CPU0] = "cpu0",
980 [TEGRA_POWERGATE_C0NC] = "c0nc",
981 [TEGRA_POWERGATE_C1NC] = "c1nc",
982 [TEGRA_POWERGATE_SOR] = "sor",
983 [TEGRA_POWERGATE_DIS] = "dis",
984 [TEGRA_POWERGATE_DISB] = "disb",
985 [TEGRA_POWERGATE_XUSBA] = "xusba",
986 [TEGRA_POWERGATE_XUSBB] = "xusbb",
987 [TEGRA_POWERGATE_XUSBC] = "xusbc",
988 [TEGRA_POWERGATE_VIC] = "vic",
989 [TEGRA_POWERGATE_IRAM] = "iram",
990};
991
992static const u8 tegra124_cpu_powergates[] = {
993 TEGRA_POWERGATE_CPU0,
994 TEGRA_POWERGATE_CPU1,
995 TEGRA_POWERGATE_CPU2,
996 TEGRA_POWERGATE_CPU3,
997};
998
999static const struct tegra_pmc_soc tegra124_pmc_soc = {
1000 .num_powergates = ARRAY_SIZE(tegra124_powergates),
1001 .powergates = tegra124_powergates,
1002 .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
1003 .cpu_powergates = tegra124_cpu_powergates,
Mikko Perttunen3568df32015-01-06 12:52:58 +02001004 .has_tsense_reset = true,
Thierry Redinga9a40a42015-01-09 11:15:33 +01001005 .has_gpu_clamps = true,
Thierry Reding72323982014-07-11 13:19:06 +02001006};
1007
Thierry Redingc2fe4692015-03-23 11:31:29 +01001008static const char * const tegra210_powergates[] = {
1009 [TEGRA_POWERGATE_CPU] = "crail",
1010 [TEGRA_POWERGATE_3D] = "3d",
1011 [TEGRA_POWERGATE_VENC] = "venc",
1012 [TEGRA_POWERGATE_PCIE] = "pcie",
Thierry Redingc2fe4692015-03-23 11:31:29 +01001013 [TEGRA_POWERGATE_MPE] = "mpe",
Thierry Redingc2fe4692015-03-23 11:31:29 +01001014 [TEGRA_POWERGATE_SATA] = "sata",
1015 [TEGRA_POWERGATE_CPU1] = "cpu1",
1016 [TEGRA_POWERGATE_CPU2] = "cpu2",
1017 [TEGRA_POWERGATE_CPU3] = "cpu3",
Thierry Redingc2fe4692015-03-23 11:31:29 +01001018 [TEGRA_POWERGATE_CPU0] = "cpu0",
1019 [TEGRA_POWERGATE_C0NC] = "c0nc",
Thierry Redingc2fe4692015-03-23 11:31:29 +01001020 [TEGRA_POWERGATE_SOR] = "sor",
1021 [TEGRA_POWERGATE_DIS] = "dis",
1022 [TEGRA_POWERGATE_DISB] = "disb",
1023 [TEGRA_POWERGATE_XUSBA] = "xusba",
1024 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1025 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1026 [TEGRA_POWERGATE_VIC] = "vic",
1027 [TEGRA_POWERGATE_IRAM] = "iram",
1028 [TEGRA_POWERGATE_NVDEC] = "nvdec",
1029 [TEGRA_POWERGATE_NVJPG] = "nvjpg",
1030 [TEGRA_POWERGATE_AUD] = "aud",
1031 [TEGRA_POWERGATE_DFD] = "dfd",
1032 [TEGRA_POWERGATE_VE2] = "ve2",
1033};
1034
1035static const u8 tegra210_cpu_powergates[] = {
1036 TEGRA_POWERGATE_CPU0,
1037 TEGRA_POWERGATE_CPU1,
1038 TEGRA_POWERGATE_CPU2,
1039 TEGRA_POWERGATE_CPU3,
1040};
1041
1042static const struct tegra_pmc_soc tegra210_pmc_soc = {
1043 .num_powergates = ARRAY_SIZE(tegra210_powergates),
1044 .powergates = tegra210_powergates,
1045 .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
1046 .cpu_powergates = tegra210_cpu_powergates,
1047 .has_tsense_reset = true,
1048 .has_gpu_clamps = true,
1049};
1050
Thierry Reding72323982014-07-11 13:19:06 +02001051static const struct of_device_id tegra_pmc_match[] = {
Thierry Redingc2fe4692015-03-23 11:31:29 +01001052 { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
Thierry Reding7d71e9032015-04-29 12:42:28 +02001053 { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
Thierry Reding72323982014-07-11 13:19:06 +02001054 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
1055 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
1056 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
1057 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
1058 { }
1059};
1060
1061static struct platform_driver tegra_pmc_driver = {
1062 .driver = {
1063 .name = "tegra-pmc",
1064 .suppress_bind_attrs = true,
1065 .of_match_table = tegra_pmc_match,
Paul Walmsley2b20b612014-12-09 22:36:50 +00001066#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
Thierry Reding72323982014-07-11 13:19:06 +02001067 .pm = &tegra_pmc_pm_ops,
Paul Walmsley2b20b612014-12-09 22:36:50 +00001068#endif
Thierry Reding72323982014-07-11 13:19:06 +02001069 },
1070 .probe = tegra_pmc_probe,
1071};
Paul Gortmaker7d4d9ed2015-05-01 20:10:57 -04001072builtin_platform_driver(tegra_pmc_driver);
Thierry Reding72323982014-07-11 13:19:06 +02001073
1074/*
1075 * Early initialization to allow access to registers in the very early boot
1076 * process.
1077 */
1078static int __init tegra_pmc_early_init(void)
1079{
1080 const struct of_device_id *match;
1081 struct device_node *np;
1082 struct resource regs;
1083 bool invert;
1084 u32 value;
1085
Thierry Reding72323982014-07-11 13:19:06 +02001086 np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
1087 if (!np) {
Thierry Reding7d71e9032015-04-29 12:42:28 +02001088 /*
1089 * Fall back to legacy initialization for 32-bit ARM only. All
1090 * 64-bit ARM device tree files for Tegra are required to have
1091 * a PMC node.
1092 *
1093 * This is for backwards-compatibility with old device trees
1094 * that didn't contain a PMC node. Note that in this case the
1095 * SoC data can't be matched and therefore powergating is
1096 * disabled.
1097 */
1098 if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
1099 pr_warn("DT node not found, powergating disabled\n");
Thierry Reding72323982014-07-11 13:19:06 +02001100
Thierry Reding7d71e9032015-04-29 12:42:28 +02001101 regs.start = 0x7000e400;
1102 regs.end = 0x7000e7ff;
1103 regs.flags = IORESOURCE_MEM;
Thierry Reding72323982014-07-11 13:19:06 +02001104
Thierry Reding7d71e9032015-04-29 12:42:28 +02001105 pr_warn("Using memory region %pR\n", &regs);
1106 } else {
1107 /*
1108 * At this point we're not running on Tegra, so play
1109 * nice with multi-platform kernels.
1110 */
1111 return 0;
1112 }
Thierry Reding72323982014-07-11 13:19:06 +02001113 } else {
Thierry Reding7d71e9032015-04-29 12:42:28 +02001114 /*
1115 * Extract information from the device tree if we've found a
1116 * matching node.
1117 */
1118 if (of_address_to_resource(np, 0, &regs) < 0) {
1119 pr_err("failed to get PMC registers\n");
1120 return -ENXIO;
1121 }
Thierry Reding72323982014-07-11 13:19:06 +02001122
Thierry Reding7d71e9032015-04-29 12:42:28 +02001123 pmc->soc = match->data;
Thierry Reding72323982014-07-11 13:19:06 +02001124 }
1125
1126 pmc->base = ioremap_nocache(regs.start, resource_size(&regs));
1127 if (!pmc->base) {
1128 pr_err("failed to map PMC registers\n");
1129 return -ENXIO;
1130 }
1131
1132 mutex_init(&pmc->powergates_lock);
1133
Thierry Reding7d71e9032015-04-29 12:42:28 +02001134 /*
1135 * Invert the interrupt polarity if a PMC device tree node exists and
1136 * contains the nvidia,invert-interrupt property.
1137 */
Thierry Reding72323982014-07-11 13:19:06 +02001138 invert = of_property_read_bool(np, "nvidia,invert-interrupt");
1139
1140 value = tegra_pmc_readl(PMC_CNTRL);
1141
1142 if (invert)
1143 value |= PMC_CNTRL_INTR_POLARITY;
1144 else
1145 value &= ~PMC_CNTRL_INTR_POLARITY;
1146
1147 tegra_pmc_writel(value, PMC_CNTRL);
1148
1149 return 0;
1150}
1151early_initcall(tegra_pmc_early_init);