1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/soc/tegra/pmc.c
5 * Copyright (c) 2010 Google, Inc
6 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
9 * Colin Cross <ccross@google.com>
12 #define pr_fmt(fmt) "tegra-pmc: " fmt
14 #include <linux/arm-smccc.h>
15 #include <linux/clk.h>
16 #include <linux/clk/tegra.h>
17 #include <linux/debugfs.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/export.h>
21 #include <linux/init.h>
23 #include <linux/iopoll.h>
24 #include <linux/irqdomain.h>
25 #include <linux/irq.h>
26 #include <linux/kernel.h>
27 #include <linux/of_address.h>
28 #include <linux/of_clk.h>
30 #include <linux/of_irq.h>
31 #include <linux/of_platform.h>
32 #include <linux/pinctrl/pinconf-generic.h>
33 #include <linux/pinctrl/pinconf.h>
34 #include <linux/pinctrl/pinctrl.h>
35 #include <linux/platform_device.h>
36 #include <linux/pm_domain.h>
37 #include <linux/reboot.h>
38 #include <linux/reset.h>
39 #include <linux/seq_file.h>
40 #include <linux/slab.h>
41 #include <linux/spinlock.h>
43 #include <soc/tegra/common.h>
44 #include <soc/tegra/fuse.h>
45 #include <soc/tegra/pmc.h>
47 #include <dt-bindings/interrupt-controller/arm-gic.h>
48 #include <dt-bindings/pinctrl/pinctrl-tegra-io-pad.h>
49 #include <dt-bindings/gpio/tegra186-gpio.h>
50 #include <dt-bindings/gpio/tegra194-gpio.h>
53 #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
54 #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
55 #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
56 #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
57 #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
58 #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
59 #define PMC_CNTRL_PWRREQ_POLARITY BIT(8)
60 #define PMC_CNTRL_MAIN_RST BIT(4)
62 #define PMC_WAKE_MASK 0x0c
63 #define PMC_WAKE_LEVEL 0x10
64 #define PMC_WAKE_STATUS 0x14
65 #define PMC_SW_WAKE_STATUS 0x18
67 #define DPD_SAMPLE 0x020
68 #define DPD_SAMPLE_ENABLE BIT(0)
69 #define DPD_SAMPLE_DISABLE (0 << 0)
71 #define PWRGATE_TOGGLE 0x30
72 #define PWRGATE_TOGGLE_START BIT(8)
74 #define REMOVE_CLAMPING 0x34
76 #define PWRGATE_STATUS 0x38
78 #define PMC_IMPL_E_33V_PWR 0x40
80 #define PMC_PWR_DET 0x48
82 #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
83 #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
84 #define PMC_SCRATCH0_MODE_RCM BIT(1)
85 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
86 PMC_SCRATCH0_MODE_BOOTLOADER | \
87 PMC_SCRATCH0_MODE_RCM)
89 #define PMC_CPUPWRGOOD_TIMER 0xc8
90 #define PMC_CPUPWROFF_TIMER 0xcc
91 #define PMC_COREPWRGOOD_TIMER 0x3c
92 #define PMC_COREPWROFF_TIMER 0xe0
94 #define PMC_PWR_DET_VALUE 0xe4
96 #define PMC_SCRATCH41 0x140
98 #define PMC_WAKE2_MASK 0x160
99 #define PMC_WAKE2_LEVEL 0x164
100 #define PMC_WAKE2_STATUS 0x168
101 #define PMC_SW_WAKE2_STATUS 0x16c
103 #define PMC_SENSOR_CTRL 0x1b0
104 #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
105 #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
107 #define PMC_RST_STATUS_POR 0
108 #define PMC_RST_STATUS_WATCHDOG 1
109 #define PMC_RST_STATUS_SENSOR 2
110 #define PMC_RST_STATUS_SW_MAIN 3
111 #define PMC_RST_STATUS_LP0 4
112 #define PMC_RST_STATUS_AOTAG 5
114 #define IO_DPD_REQ 0x1b8
115 #define IO_DPD_REQ_CODE_IDLE (0U << 30)
116 #define IO_DPD_REQ_CODE_OFF (1U << 30)
117 #define IO_DPD_REQ_CODE_ON (2U << 30)
118 #define IO_DPD_REQ_CODE_MASK (3U << 30)
120 #define IO_DPD_STATUS 0x1bc
121 #define IO_DPD2_REQ 0x1c0
122 #define IO_DPD2_STATUS 0x1c4
123 #define SEL_DPD_TIM 0x1c8
125 #define PMC_SCRATCH54 0x258
126 #define PMC_SCRATCH54_DATA_SHIFT 8
127 #define PMC_SCRATCH54_ADDR_SHIFT 0
129 #define PMC_SCRATCH55 0x25c
130 #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
131 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
132 #define PMC_SCRATCH55_PINMUX_SHIFT 24
133 #define PMC_SCRATCH55_16BITOP BIT(15)
134 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
135 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
137 #define GPU_RG_CNTRL 0x2d4
139 /* Tegra186 and later */
140 #define WAKE_AOWAKE_CNTRL(x) (0x000 + ((x) << 2))
141 #define WAKE_AOWAKE_CNTRL_LEVEL (1 << 3)
142 #define WAKE_AOWAKE_MASK_W(x) (0x180 + ((x) << 2))
143 #define WAKE_AOWAKE_MASK_R(x) (0x300 + ((x) << 2))
144 #define WAKE_AOWAKE_STATUS_W(x) (0x30c + ((x) << 2))
145 #define WAKE_AOWAKE_STATUS_R(x) (0x48c + ((x) << 2))
146 #define WAKE_AOWAKE_TIER0_ROUTING(x) (0x4b4 + ((x) << 2))
147 #define WAKE_AOWAKE_TIER1_ROUTING(x) (0x4c0 + ((x) << 2))
148 #define WAKE_AOWAKE_TIER2_ROUTING(x) (0x4cc + ((x) << 2))
150 #define WAKE_AOWAKE_CTRL 0x4f4
151 #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0)
154 #define TEGRA_SMC_PMC 0xc2fffe00
155 #define TEGRA_SMC_PMC_READ 0xaa
156 #define TEGRA_SMC_PMC_WRITE 0xbb
158 struct tegra_powergate
{
159 struct generic_pm_domain genpd
;
160 struct tegra_pmc
*pmc
;
163 unsigned int num_clks
;
164 struct reset_control
*reset
;
167 struct tegra_io_pad_soc
{
168 enum tegra_io_pad id
;
170 unsigned int voltage
;
174 struct tegra_pmc_regs
{
175 unsigned int scratch0
;
176 unsigned int dpd_req
;
177 unsigned int dpd_status
;
178 unsigned int dpd2_req
;
179 unsigned int dpd2_status
;
180 unsigned int rst_status
;
181 unsigned int rst_source_shift
;
182 unsigned int rst_source_mask
;
183 unsigned int rst_level_shift
;
184 unsigned int rst_level_mask
;
187 struct tegra_wake_event
{
192 unsigned int instance
;
197 #define TEGRA_WAKE_IRQ(_name, _id, _irq) \
203 .instance = UINT_MAX, \
208 #define TEGRA_WAKE_GPIO(_name, _id, _instance, _pin) \
214 .instance = _instance, \
219 struct tegra_pmc_soc
{
220 unsigned int num_powergates
;
221 const char *const *powergates
;
222 unsigned int num_cpu_powergates
;
223 const u8
*cpu_powergates
;
225 bool has_tsense_reset
;
227 bool needs_mbist_war
;
228 bool has_impl_33v_pwr
;
231 const struct tegra_io_pad_soc
*io_pads
;
232 unsigned int num_io_pads
;
234 const struct pinctrl_pin_desc
*pin_descs
;
235 unsigned int num_pin_descs
;
237 const struct tegra_pmc_regs
*regs
;
238 void (*init
)(struct tegra_pmc
*pmc
);
239 void (*setup_irq_polarity
)(struct tegra_pmc
*pmc
,
240 struct device_node
*np
,
242 int (*irq_set_wake
)(struct irq_data
*data
, unsigned int on
);
243 int (*irq_set_type
)(struct irq_data
*data
, unsigned int type
);
245 const char * const *reset_sources
;
246 unsigned int num_reset_sources
;
247 const char * const *reset_levels
;
248 unsigned int num_reset_levels
;
251 * These describe events that can wake the system from sleep (i.e.
252 * LP0 or SC7). Wakeup from other sleep states (such as LP1 or LP2)
253 * are dealt with in the LIC.
255 const struct tegra_wake_event
*wake_events
;
256 unsigned int num_wake_events
;
259 static const char * const tegra186_reset_sources
[] = {
277 static const char * const tegra186_reset_levels
[] = {
278 "L0", "L1", "L2", "WARM"
281 static const char * const tegra30_reset_sources
[] = {
289 static const char * const tegra210_reset_sources
[] = {
299 * struct tegra_pmc - NVIDIA Tegra PMC
300 * @dev: pointer to PMC device structure
301 * @base: pointer to I/O remapped register region
302 * @wake: pointer to I/O remapped region for WAKE registers
303 * @aotag: pointer to I/O remapped region for AOTAG registers
304 * @scratch: pointer to I/O remapped region for scratch registers
305 * @clk: pointer to pclk clock
306 * @soc: pointer to SoC data structure
307 * @tz_only: flag specifying if the PMC can only be accessed via TrustZone
308 * @debugfs: pointer to debugfs entry
309 * @rate: currently configured rate of pclk
310 * @suspend_mode: lowest suspend mode available
311 * @cpu_good_time: CPU power good time (in microseconds)
312 * @cpu_off_time: CPU power off time (in microsecends)
313 * @core_osc_time: core power good OSC time (in microseconds)
314 * @core_pmu_time: core power good PMU time (in microseconds)
315 * @core_off_time: core power off time (in microseconds)
316 * @corereq_high: core power request is active-high
317 * @sysclkreq_high: system clock request is active-high
318 * @combined_req: combined power request for CPU & core
319 * @cpu_pwr_good_en: CPU power good signal is enabled
320 * @lp0_vec_phys: physical base address of the LP0 warm boot code
321 * @lp0_vec_size: size of the LP0 warm boot code
322 * @powergates_available: Bitmap of available power gates
323 * @powergates_lock: mutex for power gate register access
324 * @pctl_dev: pin controller exposed by the PMC
325 * @domain: IRQ domain provided by the PMC
326 * @irq: chip implementation for the IRQ domain
327 * @clk_nb: pclk clock changes handler
334 void __iomem
*scratch
;
336 struct dentry
*debugfs
;
338 const struct tegra_pmc_soc
*soc
;
343 enum tegra_suspend_mode suspend_mode
;
352 bool cpu_pwr_good_en
;
355 DECLARE_BITMAP(powergates_available
, TEGRA_POWERGATE_MAX
);
357 struct mutex powergates_lock
;
359 struct pinctrl_dev
*pctl_dev
;
361 struct irq_domain
*domain
;
364 struct notifier_block clk_nb
;
367 static struct tegra_pmc
*pmc
= &(struct tegra_pmc
) {
369 .suspend_mode
= TEGRA_SUSPEND_NONE
,
372 static inline struct tegra_powergate
*
373 to_powergate(struct generic_pm_domain
*domain
)
375 return container_of(domain
, struct tegra_powergate
, genpd
);
378 static u32
tegra_pmc_readl(struct tegra_pmc
*pmc
, unsigned long offset
)
380 struct arm_smccc_res res
;
383 arm_smccc_smc(TEGRA_SMC_PMC
, TEGRA_SMC_PMC_READ
, offset
, 0, 0,
387 dev_warn(pmc
->dev
, "%s(): SMC failed: %lu\n",
390 pr_warn("%s(): SMC failed: %lu\n", __func__
,
397 return readl(pmc
->base
+ offset
);
400 static void tegra_pmc_writel(struct tegra_pmc
*pmc
, u32 value
,
401 unsigned long offset
)
403 struct arm_smccc_res res
;
406 arm_smccc_smc(TEGRA_SMC_PMC
, TEGRA_SMC_PMC_WRITE
, offset
,
407 value
, 0, 0, 0, 0, &res
);
410 dev_warn(pmc
->dev
, "%s(): SMC failed: %lu\n",
413 pr_warn("%s(): SMC failed: %lu\n", __func__
,
417 writel(value
, pmc
->base
+ offset
);
421 static u32
tegra_pmc_scratch_readl(struct tegra_pmc
*pmc
, unsigned long offset
)
424 return tegra_pmc_readl(pmc
, offset
);
426 return readl(pmc
->scratch
+ offset
);
429 static void tegra_pmc_scratch_writel(struct tegra_pmc
*pmc
, u32 value
,
430 unsigned long offset
)
433 tegra_pmc_writel(pmc
, value
, offset
);
435 writel(value
, pmc
->scratch
+ offset
);
439 * TODO Figure out a way to call this with the struct tegra_pmc * passed in.
440 * This currently doesn't work because readx_poll_timeout() can only operate
441 * on functions that take a single argument.
443 static inline bool tegra_powergate_state(int id
)
445 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
446 return (tegra_pmc_readl(pmc
, GPU_RG_CNTRL
) & 0x1) == 0;
448 return (tegra_pmc_readl(pmc
, PWRGATE_STATUS
) & BIT(id
)) != 0;
451 static inline bool tegra_powergate_is_valid(struct tegra_pmc
*pmc
, int id
)
453 return (pmc
->soc
&& pmc
->soc
->powergates
[id
]);
456 static inline bool tegra_powergate_is_available(struct tegra_pmc
*pmc
, int id
)
458 return test_bit(id
, pmc
->powergates_available
);
461 static int tegra_powergate_lookup(struct tegra_pmc
*pmc
, const char *name
)
465 if (!pmc
|| !pmc
->soc
|| !name
)
468 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
469 if (!tegra_powergate_is_valid(pmc
, i
))
472 if (!strcmp(name
, pmc
->soc
->powergates
[i
]))
480 * tegra_powergate_set() - set the state of a partition
481 * @pmc: power management controller
483 * @new_state: new state of the partition
485 static int tegra_powergate_set(struct tegra_pmc
*pmc
, unsigned int id
,
491 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
494 mutex_lock(&pmc
->powergates_lock
);
496 if (tegra_powergate_state(id
) == new_state
) {
497 mutex_unlock(&pmc
->powergates_lock
);
501 tegra_pmc_writel(pmc
, PWRGATE_TOGGLE_START
| id
, PWRGATE_TOGGLE
);
503 err
= readx_poll_timeout(tegra_powergate_state
, id
, status
,
504 status
== new_state
, 10, 100000);
506 mutex_unlock(&pmc
->powergates_lock
);
511 static int __tegra_powergate_remove_clamping(struct tegra_pmc
*pmc
,
516 mutex_lock(&pmc
->powergates_lock
);
519 * On Tegra124 and later, the clamps for the GPU are controlled by a
520 * separate register (with different semantics).
522 if (id
== TEGRA_POWERGATE_3D
) {
523 if (pmc
->soc
->has_gpu_clamps
) {
524 tegra_pmc_writel(pmc
, 0, GPU_RG_CNTRL
);
530 * Tegra 2 has a bug where PCIE and VDE clamping masks are
531 * swapped relatively to the partition ids
533 if (id
== TEGRA_POWERGATE_VDEC
)
534 mask
= (1 << TEGRA_POWERGATE_PCIE
);
535 else if (id
== TEGRA_POWERGATE_PCIE
)
536 mask
= (1 << TEGRA_POWERGATE_VDEC
);
540 tegra_pmc_writel(pmc
, mask
, REMOVE_CLAMPING
);
543 mutex_unlock(&pmc
->powergates_lock
);
548 static void tegra_powergate_disable_clocks(struct tegra_powergate
*pg
)
552 for (i
= 0; i
< pg
->num_clks
; i
++)
553 clk_disable_unprepare(pg
->clks
[i
]);
556 static int tegra_powergate_enable_clocks(struct tegra_powergate
*pg
)
561 for (i
= 0; i
< pg
->num_clks
; i
++) {
562 err
= clk_prepare_enable(pg
->clks
[i
]);
571 clk_disable_unprepare(pg
->clks
[i
]);
576 int __weak
tegra210_clk_handle_mbist_war(unsigned int id
)
581 static int tegra_powergate_power_up(struct tegra_powergate
*pg
,
586 err
= reset_control_assert(pg
->reset
);
590 usleep_range(10, 20);
592 err
= tegra_powergate_set(pg
->pmc
, pg
->id
, true);
596 usleep_range(10, 20);
598 err
= tegra_powergate_enable_clocks(pg
);
602 usleep_range(10, 20);
604 err
= __tegra_powergate_remove_clamping(pg
->pmc
, pg
->id
);
608 usleep_range(10, 20);
610 err
= reset_control_deassert(pg
->reset
);
614 usleep_range(10, 20);
616 if (pg
->pmc
->soc
->needs_mbist_war
)
617 err
= tegra210_clk_handle_mbist_war(pg
->id
);
622 tegra_powergate_disable_clocks(pg
);
627 tegra_powergate_disable_clocks(pg
);
628 usleep_range(10, 20);
631 tegra_powergate_set(pg
->pmc
, pg
->id
, false);
636 static int tegra_powergate_power_down(struct tegra_powergate
*pg
)
640 err
= tegra_powergate_enable_clocks(pg
);
644 usleep_range(10, 20);
646 err
= reset_control_assert(pg
->reset
);
650 usleep_range(10, 20);
652 tegra_powergate_disable_clocks(pg
);
654 usleep_range(10, 20);
656 err
= tegra_powergate_set(pg
->pmc
, pg
->id
, false);
663 tegra_powergate_enable_clocks(pg
);
664 usleep_range(10, 20);
665 reset_control_deassert(pg
->reset
);
666 usleep_range(10, 20);
669 tegra_powergate_disable_clocks(pg
);
674 static int tegra_genpd_power_on(struct generic_pm_domain
*domain
)
676 struct tegra_powergate
*pg
= to_powergate(domain
);
677 struct device
*dev
= pg
->pmc
->dev
;
680 err
= tegra_powergate_power_up(pg
, true);
682 dev_err(dev
, "failed to turn on PM domain %s: %d\n",
683 pg
->genpd
.name
, err
);
687 reset_control_release(pg
->reset
);
693 static int tegra_genpd_power_off(struct generic_pm_domain
*domain
)
695 struct tegra_powergate
*pg
= to_powergate(domain
);
696 struct device
*dev
= pg
->pmc
->dev
;
699 err
= reset_control_acquire(pg
->reset
);
701 pr_err("failed to acquire resets: %d\n", err
);
705 err
= tegra_powergate_power_down(pg
);
707 dev_err(dev
, "failed to turn off PM domain %s: %d\n",
708 pg
->genpd
.name
, err
);
709 reset_control_release(pg
->reset
);
716 * tegra_powergate_power_on() - power on partition
719 int tegra_powergate_power_on(unsigned int id
)
721 if (!tegra_powergate_is_available(pmc
, id
))
724 return tegra_powergate_set(pmc
, id
, true);
726 EXPORT_SYMBOL(tegra_powergate_power_on
);
729 * tegra_powergate_power_off() - power off partition
732 int tegra_powergate_power_off(unsigned int id
)
734 if (!tegra_powergate_is_available(pmc
, id
))
737 return tegra_powergate_set(pmc
, id
, false);
739 EXPORT_SYMBOL(tegra_powergate_power_off
);
742 * tegra_powergate_is_powered() - check if partition is powered
743 * @pmc: power management controller
746 static int tegra_powergate_is_powered(struct tegra_pmc
*pmc
, unsigned int id
)
748 if (!tegra_powergate_is_valid(pmc
, id
))
751 return tegra_powergate_state(id
);
755 * tegra_powergate_remove_clamping() - remove power clamps for partition
758 int tegra_powergate_remove_clamping(unsigned int id
)
760 if (!tegra_powergate_is_available(pmc
, id
))
763 return __tegra_powergate_remove_clamping(pmc
, id
);
765 EXPORT_SYMBOL(tegra_powergate_remove_clamping
);
768 * tegra_powergate_sequence_power_up() - power up partition
770 * @clk: clock for partition
771 * @rst: reset for partition
773 * Must be called with clk disabled, and returns with clk enabled.
775 int tegra_powergate_sequence_power_up(unsigned int id
, struct clk
*clk
,
776 struct reset_control
*rst
)
778 struct tegra_powergate
*pg
;
781 if (!tegra_powergate_is_available(pmc
, id
))
784 pg
= kzalloc(sizeof(*pg
), GFP_KERNEL
);
794 err
= tegra_powergate_power_up(pg
, false);
796 dev_err(pmc
->dev
, "failed to turn on partition %d: %d\n", id
,
803 EXPORT_SYMBOL(tegra_powergate_sequence_power_up
);
806 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
807 * @pmc: power management controller
808 * @cpuid: CPU partition ID
810 * Returns the partition ID corresponding to the CPU partition ID or a
811 * negative error code on failure.
813 static int tegra_get_cpu_powergate_id(struct tegra_pmc
*pmc
,
816 if (pmc
->soc
&& cpuid
< pmc
->soc
->num_cpu_powergates
)
817 return pmc
->soc
->cpu_powergates
[cpuid
];
823 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
824 * @cpuid: CPU partition ID
826 bool tegra_pmc_cpu_is_powered(unsigned int cpuid
)
830 id
= tegra_get_cpu_powergate_id(pmc
, cpuid
);
834 return tegra_powergate_is_powered(pmc
, id
);
838 * tegra_pmc_cpu_power_on() - power on CPU partition
839 * @cpuid: CPU partition ID
841 int tegra_pmc_cpu_power_on(unsigned int cpuid
)
845 id
= tegra_get_cpu_powergate_id(pmc
, cpuid
);
849 return tegra_powergate_set(pmc
, id
, true);
853 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
854 * @cpuid: CPU partition ID
856 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid
)
860 id
= tegra_get_cpu_powergate_id(pmc
, cpuid
);
864 return tegra_powergate_remove_clamping(id
);
867 static int tegra_pmc_restart_notify(struct notifier_block
*this,
868 unsigned long action
, void *data
)
870 const char *cmd
= data
;
873 value
= tegra_pmc_scratch_readl(pmc
, pmc
->soc
->regs
->scratch0
);
874 value
&= ~PMC_SCRATCH0_MODE_MASK
;
877 if (strcmp(cmd
, "recovery") == 0)
878 value
|= PMC_SCRATCH0_MODE_RECOVERY
;
880 if (strcmp(cmd
, "bootloader") == 0)
881 value
|= PMC_SCRATCH0_MODE_BOOTLOADER
;
883 if (strcmp(cmd
, "forced-recovery") == 0)
884 value
|= PMC_SCRATCH0_MODE_RCM
;
887 tegra_pmc_scratch_writel(pmc
, value
, pmc
->soc
->regs
->scratch0
);
889 /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
890 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
891 value
|= PMC_CNTRL_MAIN_RST
;
892 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
897 static struct notifier_block tegra_pmc_restart_handler
= {
898 .notifier_call
= tegra_pmc_restart_notify
,
902 static int powergate_show(struct seq_file
*s
, void *data
)
907 seq_printf(s
, " powergate powered\n");
908 seq_printf(s
, "------------------\n");
910 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
911 status
= tegra_powergate_is_powered(pmc
, i
);
915 seq_printf(s
, " %9s %7s\n", pmc
->soc
->powergates
[i
],
916 status
? "yes" : "no");
922 DEFINE_SHOW_ATTRIBUTE(powergate
);
924 static int tegra_powergate_debugfs_init(void)
926 pmc
->debugfs
= debugfs_create_file("powergate", S_IRUGO
, NULL
, NULL
,
934 static int tegra_powergate_of_get_clks(struct tegra_powergate
*pg
,
935 struct device_node
*np
)
938 unsigned int i
, count
;
941 count
= of_clk_get_parent_count(np
);
945 pg
->clks
= kcalloc(count
, sizeof(clk
), GFP_KERNEL
);
949 for (i
= 0; i
< count
; i
++) {
950 pg
->clks
[i
] = of_clk_get(np
, i
);
951 if (IS_ERR(pg
->clks
[i
])) {
952 err
= PTR_ERR(pg
->clks
[i
]);
957 pg
->num_clks
= count
;
963 clk_put(pg
->clks
[i
]);
970 static int tegra_powergate_of_get_resets(struct tegra_powergate
*pg
,
971 struct device_node
*np
, bool off
)
973 struct device
*dev
= pg
->pmc
->dev
;
976 pg
->reset
= of_reset_control_array_get_exclusive_released(np
);
977 if (IS_ERR(pg
->reset
)) {
978 err
= PTR_ERR(pg
->reset
);
979 dev_err(dev
, "failed to get device resets: %d\n", err
);
983 err
= reset_control_acquire(pg
->reset
);
985 pr_err("failed to acquire resets: %d\n", err
);
990 err
= reset_control_assert(pg
->reset
);
992 err
= reset_control_deassert(pg
->reset
);
996 reset_control_release(pg
->reset
);
1001 reset_control_release(pg
->reset
);
1002 reset_control_put(pg
->reset
);
1008 static int tegra_powergate_add(struct tegra_pmc
*pmc
, struct device_node
*np
)
1010 struct device
*dev
= pmc
->dev
;
1011 struct tegra_powergate
*pg
;
1015 pg
= kzalloc(sizeof(*pg
), GFP_KERNEL
);
1019 id
= tegra_powergate_lookup(pmc
, np
->name
);
1021 dev_err(dev
, "powergate lookup failed for %pOFn: %d\n", np
, id
);
1027 * Clear the bit for this powergate so it cannot be managed
1028 * directly via the legacy APIs for controlling powergates.
1030 clear_bit(id
, pmc
->powergates_available
);
1033 pg
->genpd
.name
= np
->name
;
1034 pg
->genpd
.power_off
= tegra_genpd_power_off
;
1035 pg
->genpd
.power_on
= tegra_genpd_power_on
;
1038 off
= !tegra_powergate_is_powered(pmc
, pg
->id
);
1040 err
= tegra_powergate_of_get_clks(pg
, np
);
1042 dev_err(dev
, "failed to get clocks for %pOFn: %d\n", np
, err
);
1046 err
= tegra_powergate_of_get_resets(pg
, np
, off
);
1048 dev_err(dev
, "failed to get resets for %pOFn: %d\n", np
, err
);
1052 if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS
)) {
1054 WARN_ON(tegra_powergate_power_up(pg
, true));
1059 err
= pm_genpd_init(&pg
->genpd
, NULL
, off
);
1061 dev_err(dev
, "failed to initialise PM domain %pOFn: %d\n", np
,
1066 err
= of_genpd_add_provider_simple(np
, &pg
->genpd
);
1068 dev_err(dev
, "failed to add PM domain provider for %pOFn: %d\n",
1073 dev_dbg(dev
, "added PM domain %s\n", pg
->genpd
.name
);
1078 pm_genpd_remove(&pg
->genpd
);
1081 reset_control_put(pg
->reset
);
1084 while (pg
->num_clks
--)
1085 clk_put(pg
->clks
[pg
->num_clks
]);
1090 set_bit(id
, pmc
->powergates_available
);
1098 static int tegra_powergate_init(struct tegra_pmc
*pmc
,
1099 struct device_node
*parent
)
1101 struct device_node
*np
, *child
;
1104 np
= of_get_child_by_name(parent
, "powergates");
1108 for_each_child_of_node(np
, child
) {
1109 err
= tegra_powergate_add(pmc
, child
);
1121 static void tegra_powergate_remove(struct generic_pm_domain
*genpd
)
1123 struct tegra_powergate
*pg
= to_powergate(genpd
);
1125 reset_control_put(pg
->reset
);
1127 while (pg
->num_clks
--)
1128 clk_put(pg
->clks
[pg
->num_clks
]);
1132 set_bit(pg
->id
, pmc
->powergates_available
);
1137 static void tegra_powergate_remove_all(struct device_node
*parent
)
1139 struct generic_pm_domain
*genpd
;
1140 struct device_node
*np
, *child
;
1142 np
= of_get_child_by_name(parent
, "powergates");
1146 for_each_child_of_node(np
, child
) {
1147 of_genpd_del_provider(child
);
1149 genpd
= of_genpd_remove_last(child
);
1153 tegra_powergate_remove(genpd
);
1159 static const struct tegra_io_pad_soc
*
1160 tegra_io_pad_find(struct tegra_pmc
*pmc
, enum tegra_io_pad id
)
1164 for (i
= 0; i
< pmc
->soc
->num_io_pads
; i
++)
1165 if (pmc
->soc
->io_pads
[i
].id
== id
)
1166 return &pmc
->soc
->io_pads
[i
];
1171 static int tegra_io_pad_get_dpd_register_bit(struct tegra_pmc
*pmc
,
1172 enum tegra_io_pad id
,
1173 unsigned long *request
,
1174 unsigned long *status
,
1177 const struct tegra_io_pad_soc
*pad
;
1179 pad
= tegra_io_pad_find(pmc
, id
);
1181 dev_err(pmc
->dev
, "invalid I/O pad ID %u\n", id
);
1185 if (pad
->dpd
== UINT_MAX
)
1188 *mask
= BIT(pad
->dpd
% 32);
1190 if (pad
->dpd
< 32) {
1191 *status
= pmc
->soc
->regs
->dpd_status
;
1192 *request
= pmc
->soc
->regs
->dpd_req
;
1194 *status
= pmc
->soc
->regs
->dpd2_status
;
1195 *request
= pmc
->soc
->regs
->dpd2_req
;
1201 static int tegra_io_pad_prepare(struct tegra_pmc
*pmc
, enum tegra_io_pad id
,
1202 unsigned long *request
, unsigned long *status
,
1205 unsigned long rate
, value
;
1208 err
= tegra_io_pad_get_dpd_register_bit(pmc
, id
, request
, status
, mask
);
1215 dev_err(pmc
->dev
, "failed to get clock rate\n");
1219 tegra_pmc_writel(pmc
, DPD_SAMPLE_ENABLE
, DPD_SAMPLE
);
1221 /* must be at least 200 ns, in APB (PCLK) clock cycles */
1222 value
= DIV_ROUND_UP(1000000000, rate
);
1223 value
= DIV_ROUND_UP(200, value
);
1224 tegra_pmc_writel(pmc
, value
, SEL_DPD_TIM
);
1230 static int tegra_io_pad_poll(struct tegra_pmc
*pmc
, unsigned long offset
,
1231 u32 mask
, u32 val
, unsigned long timeout
)
1235 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
1237 while (time_after(timeout
, jiffies
)) {
1238 value
= tegra_pmc_readl(pmc
, offset
);
1239 if ((value
& mask
) == val
)
1242 usleep_range(250, 1000);
1248 static void tegra_io_pad_unprepare(struct tegra_pmc
*pmc
)
1251 tegra_pmc_writel(pmc
, DPD_SAMPLE_DISABLE
, DPD_SAMPLE
);
1255 * tegra_io_pad_power_enable() - enable power to I/O pad
1256 * @id: Tegra I/O pad ID for which to enable power
1258 * Returns: 0 on success or a negative error code on failure.
1260 int tegra_io_pad_power_enable(enum tegra_io_pad id
)
1262 unsigned long request
, status
;
1266 mutex_lock(&pmc
->powergates_lock
);
1268 err
= tegra_io_pad_prepare(pmc
, id
, &request
, &status
, &mask
);
1270 dev_err(pmc
->dev
, "failed to prepare I/O pad: %d\n", err
);
1274 tegra_pmc_writel(pmc
, IO_DPD_REQ_CODE_OFF
| mask
, request
);
1276 err
= tegra_io_pad_poll(pmc
, status
, mask
, 0, 250);
1278 dev_err(pmc
->dev
, "failed to enable I/O pad: %d\n", err
);
1282 tegra_io_pad_unprepare(pmc
);
1285 mutex_unlock(&pmc
->powergates_lock
);
1288 EXPORT_SYMBOL(tegra_io_pad_power_enable
);
1291 * tegra_io_pad_power_disable() - disable power to I/O pad
1292 * @id: Tegra I/O pad ID for which to disable power
1294 * Returns: 0 on success or a negative error code on failure.
1296 int tegra_io_pad_power_disable(enum tegra_io_pad id
)
1298 unsigned long request
, status
;
1302 mutex_lock(&pmc
->powergates_lock
);
1304 err
= tegra_io_pad_prepare(pmc
, id
, &request
, &status
, &mask
);
1306 dev_err(pmc
->dev
, "failed to prepare I/O pad: %d\n", err
);
1310 tegra_pmc_writel(pmc
, IO_DPD_REQ_CODE_ON
| mask
, request
);
1312 err
= tegra_io_pad_poll(pmc
, status
, mask
, mask
, 250);
1314 dev_err(pmc
->dev
, "failed to disable I/O pad: %d\n", err
);
1318 tegra_io_pad_unprepare(pmc
);
1321 mutex_unlock(&pmc
->powergates_lock
);
1324 EXPORT_SYMBOL(tegra_io_pad_power_disable
);
1326 static int tegra_io_pad_is_powered(struct tegra_pmc
*pmc
, enum tegra_io_pad id
)
1328 unsigned long request
, status
;
1332 err
= tegra_io_pad_get_dpd_register_bit(pmc
, id
, &request
, &status
,
1337 value
= tegra_pmc_readl(pmc
, status
);
1339 return !(value
& mask
);
1342 static int tegra_io_pad_set_voltage(struct tegra_pmc
*pmc
, enum tegra_io_pad id
,
1345 const struct tegra_io_pad_soc
*pad
;
1348 pad
= tegra_io_pad_find(pmc
, id
);
1352 if (pad
->voltage
== UINT_MAX
)
1355 mutex_lock(&pmc
->powergates_lock
);
1357 if (pmc
->soc
->has_impl_33v_pwr
) {
1358 value
= tegra_pmc_readl(pmc
, PMC_IMPL_E_33V_PWR
);
1360 if (voltage
== TEGRA_IO_PAD_VOLTAGE_1V8
)
1361 value
&= ~BIT(pad
->voltage
);
1363 value
|= BIT(pad
->voltage
);
1365 tegra_pmc_writel(pmc
, value
, PMC_IMPL_E_33V_PWR
);
1367 /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
1368 value
= tegra_pmc_readl(pmc
, PMC_PWR_DET
);
1369 value
|= BIT(pad
->voltage
);
1370 tegra_pmc_writel(pmc
, value
, PMC_PWR_DET
);
1372 /* update I/O voltage */
1373 value
= tegra_pmc_readl(pmc
, PMC_PWR_DET_VALUE
);
1375 if (voltage
== TEGRA_IO_PAD_VOLTAGE_1V8
)
1376 value
&= ~BIT(pad
->voltage
);
1378 value
|= BIT(pad
->voltage
);
1380 tegra_pmc_writel(pmc
, value
, PMC_PWR_DET_VALUE
);
1383 mutex_unlock(&pmc
->powergates_lock
);
1385 usleep_range(100, 250);
1390 static int tegra_io_pad_get_voltage(struct tegra_pmc
*pmc
, enum tegra_io_pad id
)
1392 const struct tegra_io_pad_soc
*pad
;
1395 pad
= tegra_io_pad_find(pmc
, id
);
1399 if (pad
->voltage
== UINT_MAX
)
1402 if (pmc
->soc
->has_impl_33v_pwr
)
1403 value
= tegra_pmc_readl(pmc
, PMC_IMPL_E_33V_PWR
);
1405 value
= tegra_pmc_readl(pmc
, PMC_PWR_DET_VALUE
);
1407 if ((value
& BIT(pad
->voltage
)) == 0)
1408 return TEGRA_IO_PAD_VOLTAGE_1V8
;
1410 return TEGRA_IO_PAD_VOLTAGE_3V3
;
1414 * tegra_io_rail_power_on() - enable power to I/O rail
1415 * @id: Tegra I/O pad ID for which to enable power
1417 * See also: tegra_io_pad_power_enable()
1419 int tegra_io_rail_power_on(unsigned int id
)
1421 return tegra_io_pad_power_enable(id
);
1423 EXPORT_SYMBOL(tegra_io_rail_power_on
);
1426 * tegra_io_rail_power_off() - disable power to I/O rail
1427 * @id: Tegra I/O pad ID for which to disable power
1429 * See also: tegra_io_pad_power_disable()
1431 int tegra_io_rail_power_off(unsigned int id
)
1433 return tegra_io_pad_power_disable(id
);
1435 EXPORT_SYMBOL(tegra_io_rail_power_off
);
1437 #ifdef CONFIG_PM_SLEEP
1438 enum tegra_suspend_mode
tegra_pmc_get_suspend_mode(void)
1440 return pmc
->suspend_mode
;
1443 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode
)
1445 if (mode
< TEGRA_SUSPEND_NONE
|| mode
>= TEGRA_MAX_SUSPEND_MODE
)
1448 pmc
->suspend_mode
= mode
;
1451 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode
)
1453 unsigned long long rate
= 0;
1458 case TEGRA_SUSPEND_LP1
:
1462 case TEGRA_SUSPEND_LP2
:
1470 if (WARN_ON_ONCE(rate
== 0))
1473 ticks
= pmc
->cpu_good_time
* rate
+ USEC_PER_SEC
- 1;
1474 do_div(ticks
, USEC_PER_SEC
);
1475 tegra_pmc_writel(pmc
, ticks
, PMC_CPUPWRGOOD_TIMER
);
1477 ticks
= pmc
->cpu_off_time
* rate
+ USEC_PER_SEC
- 1;
1478 do_div(ticks
, USEC_PER_SEC
);
1479 tegra_pmc_writel(pmc
, ticks
, PMC_CPUPWROFF_TIMER
);
1481 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
1482 value
&= ~PMC_CNTRL_SIDE_EFFECT_LP0
;
1483 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
1484 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
1488 static int tegra_pmc_parse_dt(struct tegra_pmc
*pmc
, struct device_node
*np
)
1490 u32 value
, values
[2];
1492 if (of_property_read_u32(np
, "nvidia,suspend-mode", &value
)) {
1496 pmc
->suspend_mode
= TEGRA_SUSPEND_LP0
;
1500 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1504 pmc
->suspend_mode
= TEGRA_SUSPEND_LP2
;
1508 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1513 pmc
->suspend_mode
= tegra_pm_validate_suspend_mode(pmc
->suspend_mode
);
1515 if (of_property_read_u32(np
, "nvidia,cpu-pwr-good-time", &value
))
1516 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1518 pmc
->cpu_good_time
= value
;
1520 if (of_property_read_u32(np
, "nvidia,cpu-pwr-off-time", &value
))
1521 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1523 pmc
->cpu_off_time
= value
;
1525 if (of_property_read_u32_array(np
, "nvidia,core-pwr-good-time",
1526 values
, ARRAY_SIZE(values
)))
1527 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1529 pmc
->core_osc_time
= values
[0];
1530 pmc
->core_pmu_time
= values
[1];
1532 if (of_property_read_u32(np
, "nvidia,core-pwr-off-time", &value
))
1533 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1535 pmc
->core_off_time
= value
;
1537 pmc
->corereq_high
= of_property_read_bool(np
,
1538 "nvidia,core-power-req-active-high");
1540 pmc
->sysclkreq_high
= of_property_read_bool(np
,
1541 "nvidia,sys-clock-req-active-high");
1543 pmc
->combined_req
= of_property_read_bool(np
,
1544 "nvidia,combined-power-req");
1546 pmc
->cpu_pwr_good_en
= of_property_read_bool(np
,
1547 "nvidia,cpu-pwr-good-en");
1549 if (of_property_read_u32_array(np
, "nvidia,lp0-vec", values
,
1550 ARRAY_SIZE(values
)))
1551 if (pmc
->suspend_mode
== TEGRA_SUSPEND_LP0
)
1552 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1554 pmc
->lp0_vec_phys
= values
[0];
1555 pmc
->lp0_vec_size
= values
[1];
1560 static void tegra_pmc_init(struct tegra_pmc
*pmc
)
1563 pmc
->soc
->init(pmc
);
1566 static void tegra_pmc_init_tsense_reset(struct tegra_pmc
*pmc
)
1568 static const char disabled
[] = "emergency thermal reset disabled";
1569 u32 pmu_addr
, ctrl_id
, reg_addr
, reg_data
, pinmux
;
1570 struct device
*dev
= pmc
->dev
;
1571 struct device_node
*np
;
1572 u32 value
, checksum
;
1574 if (!pmc
->soc
->has_tsense_reset
)
1577 np
= of_get_child_by_name(pmc
->dev
->of_node
, "i2c-thermtrip");
1579 dev_warn(dev
, "i2c-thermtrip node not found, %s.\n", disabled
);
1583 if (of_property_read_u32(np
, "nvidia,i2c-controller-id", &ctrl_id
)) {
1584 dev_err(dev
, "I2C controller ID missing, %s.\n", disabled
);
1588 if (of_property_read_u32(np
, "nvidia,bus-addr", &pmu_addr
)) {
1589 dev_err(dev
, "nvidia,bus-addr missing, %s.\n", disabled
);
1593 if (of_property_read_u32(np
, "nvidia,reg-addr", ®_addr
)) {
1594 dev_err(dev
, "nvidia,reg-addr missing, %s.\n", disabled
);
1598 if (of_property_read_u32(np
, "nvidia,reg-data", ®_data
)) {
1599 dev_err(dev
, "nvidia,reg-data missing, %s.\n", disabled
);
1603 if (of_property_read_u32(np
, "nvidia,pinmux-id", &pinmux
))
1606 value
= tegra_pmc_readl(pmc
, PMC_SENSOR_CTRL
);
1607 value
|= PMC_SENSOR_CTRL_SCRATCH_WRITE
;
1608 tegra_pmc_writel(pmc
, value
, PMC_SENSOR_CTRL
);
1610 value
= (reg_data
<< PMC_SCRATCH54_DATA_SHIFT
) |
1611 (reg_addr
<< PMC_SCRATCH54_ADDR_SHIFT
);
1612 tegra_pmc_writel(pmc
, value
, PMC_SCRATCH54
);
1614 value
= PMC_SCRATCH55_RESET_TEGRA
;
1615 value
|= ctrl_id
<< PMC_SCRATCH55_CNTRL_ID_SHIFT
;
1616 value
|= pinmux
<< PMC_SCRATCH55_PINMUX_SHIFT
;
1617 value
|= pmu_addr
<< PMC_SCRATCH55_I2CSLV1_SHIFT
;
1620 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
1621 * contain the checksum and are currently zero, so they are not added.
1623 checksum
= reg_addr
+ reg_data
+ (value
& 0xff) + ((value
>> 8) & 0xff)
1624 + ((value
>> 24) & 0xff);
1626 checksum
= 0x100 - checksum
;
1628 value
|= checksum
<< PMC_SCRATCH55_CHECKSUM_SHIFT
;
1630 tegra_pmc_writel(pmc
, value
, PMC_SCRATCH55
);
1632 value
= tegra_pmc_readl(pmc
, PMC_SENSOR_CTRL
);
1633 value
|= PMC_SENSOR_CTRL_ENABLE_RST
;
1634 tegra_pmc_writel(pmc
, value
, PMC_SENSOR_CTRL
);
1636 dev_info(pmc
->dev
, "emergency thermal reset enabled\n");
1642 static int tegra_io_pad_pinctrl_get_groups_count(struct pinctrl_dev
*pctl_dev
)
1644 struct tegra_pmc
*pmc
= pinctrl_dev_get_drvdata(pctl_dev
);
1646 return pmc
->soc
->num_io_pads
;
1649 static const char *tegra_io_pad_pinctrl_get_group_name(struct pinctrl_dev
*pctl
,
1652 struct tegra_pmc
*pmc
= pinctrl_dev_get_drvdata(pctl
);
1654 return pmc
->soc
->io_pads
[group
].name
;
1657 static int tegra_io_pad_pinctrl_get_group_pins(struct pinctrl_dev
*pctl_dev
,
1659 const unsigned int **pins
,
1660 unsigned int *num_pins
)
1662 struct tegra_pmc
*pmc
= pinctrl_dev_get_drvdata(pctl_dev
);
1664 *pins
= &pmc
->soc
->io_pads
[group
].id
;
1670 static const struct pinctrl_ops tegra_io_pad_pinctrl_ops
= {
1671 .get_groups_count
= tegra_io_pad_pinctrl_get_groups_count
,
1672 .get_group_name
= tegra_io_pad_pinctrl_get_group_name
,
1673 .get_group_pins
= tegra_io_pad_pinctrl_get_group_pins
,
1674 .dt_node_to_map
= pinconf_generic_dt_node_to_map_pin
,
1675 .dt_free_map
= pinconf_generic_dt_free_map
,
1678 static int tegra_io_pad_pinconf_get(struct pinctrl_dev
*pctl_dev
,
1679 unsigned int pin
, unsigned long *config
)
1681 enum pin_config_param param
= pinconf_to_config_param(*config
);
1682 struct tegra_pmc
*pmc
= pinctrl_dev_get_drvdata(pctl_dev
);
1683 const struct tegra_io_pad_soc
*pad
;
1687 pad
= tegra_io_pad_find(pmc
, pin
);
1692 case PIN_CONFIG_POWER_SOURCE
:
1693 ret
= tegra_io_pad_get_voltage(pmc
, pad
->id
);
1700 case PIN_CONFIG_LOW_POWER_MODE
:
1701 ret
= tegra_io_pad_is_powered(pmc
, pad
->id
);
1712 *config
= pinconf_to_config_packed(param
, arg
);
1717 static int tegra_io_pad_pinconf_set(struct pinctrl_dev
*pctl_dev
,
1718 unsigned int pin
, unsigned long *configs
,
1719 unsigned int num_configs
)
1721 struct tegra_pmc
*pmc
= pinctrl_dev_get_drvdata(pctl_dev
);
1722 const struct tegra_io_pad_soc
*pad
;
1723 enum pin_config_param param
;
1728 pad
= tegra_io_pad_find(pmc
, pin
);
1732 for (i
= 0; i
< num_configs
; ++i
) {
1733 param
= pinconf_to_config_param(configs
[i
]);
1734 arg
= pinconf_to_config_argument(configs
[i
]);
1737 case PIN_CONFIG_LOW_POWER_MODE
:
1739 err
= tegra_io_pad_power_disable(pad
->id
);
1741 err
= tegra_io_pad_power_enable(pad
->id
);
1745 case PIN_CONFIG_POWER_SOURCE
:
1746 if (arg
!= TEGRA_IO_PAD_VOLTAGE_1V8
&&
1747 arg
!= TEGRA_IO_PAD_VOLTAGE_3V3
)
1749 err
= tegra_io_pad_set_voltage(pmc
, pad
->id
, arg
);
1761 static const struct pinconf_ops tegra_io_pad_pinconf_ops
= {
1762 .pin_config_get
= tegra_io_pad_pinconf_get
,
1763 .pin_config_set
= tegra_io_pad_pinconf_set
,
1767 static struct pinctrl_desc tegra_pmc_pctl_desc
= {
1768 .pctlops
= &tegra_io_pad_pinctrl_ops
,
1769 .confops
= &tegra_io_pad_pinconf_ops
,
1772 static int tegra_pmc_pinctrl_init(struct tegra_pmc
*pmc
)
1776 if (!pmc
->soc
->num_pin_descs
)
1779 tegra_pmc_pctl_desc
.name
= dev_name(pmc
->dev
);
1780 tegra_pmc_pctl_desc
.pins
= pmc
->soc
->pin_descs
;
1781 tegra_pmc_pctl_desc
.npins
= pmc
->soc
->num_pin_descs
;
1783 pmc
->pctl_dev
= devm_pinctrl_register(pmc
->dev
, &tegra_pmc_pctl_desc
,
1785 if (IS_ERR(pmc
->pctl_dev
)) {
1786 err
= PTR_ERR(pmc
->pctl_dev
);
1787 dev_err(pmc
->dev
, "failed to register pin controller: %d\n",
1795 static ssize_t
reset_reason_show(struct device
*dev
,
1796 struct device_attribute
*attr
, char *buf
)
1800 value
= tegra_pmc_readl(pmc
, pmc
->soc
->regs
->rst_status
);
1801 value
&= pmc
->soc
->regs
->rst_source_mask
;
1802 value
>>= pmc
->soc
->regs
->rst_source_shift
;
1804 if (WARN_ON(value
>= pmc
->soc
->num_reset_sources
))
1805 return sprintf(buf
, "%s\n", "UNKNOWN");
1807 return sprintf(buf
, "%s\n", pmc
->soc
->reset_sources
[value
]);
1810 static DEVICE_ATTR_RO(reset_reason
);
1812 static ssize_t
reset_level_show(struct device
*dev
,
1813 struct device_attribute
*attr
, char *buf
)
1817 value
= tegra_pmc_readl(pmc
, pmc
->soc
->regs
->rst_status
);
1818 value
&= pmc
->soc
->regs
->rst_level_mask
;
1819 value
>>= pmc
->soc
->regs
->rst_level_shift
;
1821 if (WARN_ON(value
>= pmc
->soc
->num_reset_levels
))
1822 return sprintf(buf
, "%s\n", "UNKNOWN");
1824 return sprintf(buf
, "%s\n", pmc
->soc
->reset_levels
[value
]);
1827 static DEVICE_ATTR_RO(reset_level
);
1829 static void tegra_pmc_reset_sysfs_init(struct tegra_pmc
*pmc
)
1831 struct device
*dev
= pmc
->dev
;
1834 if (pmc
->soc
->reset_sources
) {
1835 err
= device_create_file(dev
, &dev_attr_reset_reason
);
1838 "failed to create attr \"reset_reason\": %d\n",
1842 if (pmc
->soc
->reset_levels
) {
1843 err
= device_create_file(dev
, &dev_attr_reset_level
);
1846 "failed to create attr \"reset_level\": %d\n",
1851 static int tegra_pmc_irq_translate(struct irq_domain
*domain
,
1852 struct irq_fwspec
*fwspec
,
1853 unsigned long *hwirq
,
1856 if (WARN_ON(fwspec
->param_count
< 2))
1859 *hwirq
= fwspec
->param
[0];
1860 *type
= fwspec
->param
[1];
1865 static int tegra_pmc_irq_alloc(struct irq_domain
*domain
, unsigned int virq
,
1866 unsigned int num_irqs
, void *data
)
1868 struct tegra_pmc
*pmc
= domain
->host_data
;
1869 const struct tegra_pmc_soc
*soc
= pmc
->soc
;
1870 struct irq_fwspec
*fwspec
= data
;
1874 if (WARN_ON(num_irqs
> 1))
1877 for (i
= 0; i
< soc
->num_wake_events
; i
++) {
1878 const struct tegra_wake_event
*event
= &soc
->wake_events
[i
];
1880 if (fwspec
->param_count
== 2) {
1881 struct irq_fwspec spec
;
1883 if (event
->id
!= fwspec
->param
[0])
1886 err
= irq_domain_set_hwirq_and_chip(domain
, virq
,
1892 spec
.fwnode
= &pmc
->dev
->of_node
->fwnode
;
1893 spec
.param_count
= 3;
1894 spec
.param
[0] = GIC_SPI
;
1895 spec
.param
[1] = event
->irq
;
1896 spec
.param
[2] = fwspec
->param
[1];
1898 err
= irq_domain_alloc_irqs_parent(domain
, virq
,
1904 if (fwspec
->param_count
== 3) {
1905 if (event
->gpio
.instance
!= fwspec
->param
[0] ||
1906 event
->gpio
.pin
!= fwspec
->param
[1])
1909 err
= irq_domain_set_hwirq_and_chip(domain
, virq
,
1914 * GPIOs don't have an equivalent interrupt in the
1915 * parent controller (GIC). However some code, such
1916 * as the one in irq_get_irqchip_state(), require a
1917 * valid IRQ chip to be set. Make sure that's the
1918 * case by passing NULL here, which will install a
1919 * dummy IRQ chip for the interrupt in the parent
1923 irq_domain_set_hwirq_and_chip(domain
->parent
,
1932 * For interrupts that don't have associated wake events, assign a
1933 * dummy hardware IRQ number. This is used in the ->irq_set_type()
1934 * and ->irq_set_wake() callbacks to return early for these IRQs.
1936 if (i
== soc
->num_wake_events
) {
1937 err
= irq_domain_set_hwirq_and_chip(domain
, virq
, ULONG_MAX
,
1941 * Interrupts without a wake event don't have a corresponding
1942 * interrupt in the parent controller (GIC). Pass NULL for the
1943 * chip here, which causes a dummy IRQ chip to be installed
1944 * for the interrupt in the parent domain, to make this
1948 irq_domain_set_hwirq_and_chip(domain
->parent
, virq
, 0,
1955 static const struct irq_domain_ops tegra_pmc_irq_domain_ops
= {
1956 .translate
= tegra_pmc_irq_translate
,
1957 .alloc
= tegra_pmc_irq_alloc
,
1960 static int tegra210_pmc_irq_set_wake(struct irq_data
*data
, unsigned int on
)
1962 struct tegra_pmc
*pmc
= irq_data_get_irq_chip_data(data
);
1963 unsigned int offset
, bit
;
1966 if (data
->hwirq
== ULONG_MAX
)
1969 offset
= data
->hwirq
/ 32;
1970 bit
= data
->hwirq
% 32;
1972 /* clear wake status */
1973 tegra_pmc_writel(pmc
, 0, PMC_SW_WAKE_STATUS
);
1974 tegra_pmc_writel(pmc
, 0, PMC_SW_WAKE2_STATUS
);
1976 tegra_pmc_writel(pmc
, 0, PMC_WAKE_STATUS
);
1977 tegra_pmc_writel(pmc
, 0, PMC_WAKE2_STATUS
);
1979 /* enable PMC wake */
1980 if (data
->hwirq
>= 32)
1981 offset
= PMC_WAKE2_MASK
;
1983 offset
= PMC_WAKE_MASK
;
1985 value
= tegra_pmc_readl(pmc
, offset
);
1992 tegra_pmc_writel(pmc
, value
, offset
);
1997 static int tegra210_pmc_irq_set_type(struct irq_data
*data
, unsigned int type
)
1999 struct tegra_pmc
*pmc
= irq_data_get_irq_chip_data(data
);
2000 unsigned int offset
, bit
;
2003 if (data
->hwirq
== ULONG_MAX
)
2006 offset
= data
->hwirq
/ 32;
2007 bit
= data
->hwirq
% 32;
2009 if (data
->hwirq
>= 32)
2010 offset
= PMC_WAKE2_LEVEL
;
2012 offset
= PMC_WAKE_LEVEL
;
2014 value
= tegra_pmc_readl(pmc
, offset
);
2017 case IRQ_TYPE_EDGE_RISING
:
2018 case IRQ_TYPE_LEVEL_HIGH
:
2022 case IRQ_TYPE_EDGE_FALLING
:
2023 case IRQ_TYPE_LEVEL_LOW
:
2027 case IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
:
2035 tegra_pmc_writel(pmc
, value
, offset
);
2040 static int tegra186_pmc_irq_set_wake(struct irq_data
*data
, unsigned int on
)
2042 struct tegra_pmc
*pmc
= irq_data_get_irq_chip_data(data
);
2043 unsigned int offset
, bit
;
2046 /* nothing to do if there's no associated wake event */
2047 if (WARN_ON(data
->hwirq
== ULONG_MAX
))
2050 offset
= data
->hwirq
/ 32;
2051 bit
= data
->hwirq
% 32;
2053 /* clear wake status */
2054 writel(0x1, pmc
->wake
+ WAKE_AOWAKE_STATUS_W(data
->hwirq
));
2056 /* route wake to tier 2 */
2057 value
= readl(pmc
->wake
+ WAKE_AOWAKE_TIER2_ROUTING(offset
));
2060 value
&= ~(1 << bit
);
2064 writel(value
, pmc
->wake
+ WAKE_AOWAKE_TIER2_ROUTING(offset
));
2066 /* enable wakeup event */
2067 writel(!!on
, pmc
->wake
+ WAKE_AOWAKE_MASK_W(data
->hwirq
));
2072 static int tegra186_pmc_irq_set_type(struct irq_data
*data
, unsigned int type
)
2074 struct tegra_pmc
*pmc
= irq_data_get_irq_chip_data(data
);
2077 /* nothing to do if there's no associated wake event */
2078 if (data
->hwirq
== ULONG_MAX
)
2081 value
= readl(pmc
->wake
+ WAKE_AOWAKE_CNTRL(data
->hwirq
));
2084 case IRQ_TYPE_EDGE_RISING
:
2085 case IRQ_TYPE_LEVEL_HIGH
:
2086 value
|= WAKE_AOWAKE_CNTRL_LEVEL
;
2089 case IRQ_TYPE_EDGE_FALLING
:
2090 case IRQ_TYPE_LEVEL_LOW
:
2091 value
&= ~WAKE_AOWAKE_CNTRL_LEVEL
;
2094 case IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
:
2095 value
^= WAKE_AOWAKE_CNTRL_LEVEL
;
2102 writel(value
, pmc
->wake
+ WAKE_AOWAKE_CNTRL(data
->hwirq
));
2107 static int tegra_pmc_irq_init(struct tegra_pmc
*pmc
)
2109 struct irq_domain
*parent
= NULL
;
2110 struct device_node
*np
;
2112 np
= of_irq_find_parent(pmc
->dev
->of_node
);
2114 parent
= irq_find_host(np
);
2121 pmc
->irq
.name
= dev_name(pmc
->dev
);
2122 pmc
->irq
.irq_mask
= irq_chip_mask_parent
;
2123 pmc
->irq
.irq_unmask
= irq_chip_unmask_parent
;
2124 pmc
->irq
.irq_eoi
= irq_chip_eoi_parent
;
2125 pmc
->irq
.irq_set_affinity
= irq_chip_set_affinity_parent
;
2126 pmc
->irq
.irq_set_type
= pmc
->soc
->irq_set_type
;
2127 pmc
->irq
.irq_set_wake
= pmc
->soc
->irq_set_wake
;
2129 pmc
->domain
= irq_domain_add_hierarchy(parent
, 0, 96, pmc
->dev
->of_node
,
2130 &tegra_pmc_irq_domain_ops
, pmc
);
2132 dev_err(pmc
->dev
, "failed to allocate domain\n");
2139 static int tegra_pmc_clk_notify_cb(struct notifier_block
*nb
,
2140 unsigned long action
, void *ptr
)
2142 struct tegra_pmc
*pmc
= container_of(nb
, struct tegra_pmc
, clk_nb
);
2143 struct clk_notifier_data
*data
= ptr
;
2146 case PRE_RATE_CHANGE
:
2147 mutex_lock(&pmc
->powergates_lock
);
2150 case POST_RATE_CHANGE
:
2151 pmc
->rate
= data
->new_rate
;
2154 case ABORT_RATE_CHANGE
:
2155 mutex_unlock(&pmc
->powergates_lock
);
2160 return notifier_from_errno(-EINVAL
);
2166 static int tegra_pmc_probe(struct platform_device
*pdev
)
2169 struct resource
*res
;
2173 * Early initialisation should have configured an initial
2174 * register mapping and setup the soc data pointer. If these
2175 * are not valid then something went badly wrong!
2177 if (WARN_ON(!pmc
->base
|| !pmc
->soc
))
2180 err
= tegra_pmc_parse_dt(pmc
, pdev
->dev
.of_node
);
2184 /* take over the memory region from the early initialization */
2185 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2186 base
= devm_ioremap_resource(&pdev
->dev
, res
);
2188 return PTR_ERR(base
);
2190 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "wake");
2192 pmc
->wake
= devm_ioremap_resource(&pdev
->dev
, res
);
2193 if (IS_ERR(pmc
->wake
))
2194 return PTR_ERR(pmc
->wake
);
2199 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "aotag");
2201 pmc
->aotag
= devm_ioremap_resource(&pdev
->dev
, res
);
2202 if (IS_ERR(pmc
->aotag
))
2203 return PTR_ERR(pmc
->aotag
);
2208 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "scratch");
2210 pmc
->scratch
= devm_ioremap_resource(&pdev
->dev
, res
);
2211 if (IS_ERR(pmc
->scratch
))
2212 return PTR_ERR(pmc
->scratch
);
2214 pmc
->scratch
= base
;
2217 pmc
->clk
= devm_clk_get(&pdev
->dev
, "pclk");
2218 if (IS_ERR(pmc
->clk
)) {
2219 err
= PTR_ERR(pmc
->clk
);
2221 if (err
!= -ENOENT
) {
2222 dev_err(&pdev
->dev
, "failed to get pclk: %d\n", err
);
2230 * PCLK clock rate can't be retrieved using CLK API because it
2231 * causes lockup if CPU enters LP2 idle state from some other
2232 * CLK notifier, hence we're caching the rate's value locally.
2235 pmc
->clk_nb
.notifier_call
= tegra_pmc_clk_notify_cb
;
2236 err
= clk_notifier_register(pmc
->clk
, &pmc
->clk_nb
);
2239 "failed to register clk notifier\n");
2243 pmc
->rate
= clk_get_rate(pmc
->clk
);
2246 pmc
->dev
= &pdev
->dev
;
2248 tegra_pmc_init(pmc
);
2250 tegra_pmc_init_tsense_reset(pmc
);
2252 tegra_pmc_reset_sysfs_init(pmc
);
2254 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
2255 err
= tegra_powergate_debugfs_init();
2260 err
= register_restart_handler(&tegra_pmc_restart_handler
);
2262 dev_err(&pdev
->dev
, "unable to register restart handler, %d\n",
2264 goto cleanup_debugfs
;
2267 err
= tegra_pmc_pinctrl_init(pmc
);
2269 goto cleanup_restart_handler
;
2271 err
= tegra_powergate_init(pmc
, pdev
->dev
.of_node
);
2273 goto cleanup_powergates
;
2275 err
= tegra_pmc_irq_init(pmc
);
2277 goto cleanup_powergates
;
2279 mutex_lock(&pmc
->powergates_lock
);
2282 mutex_unlock(&pmc
->powergates_lock
);
2284 platform_set_drvdata(pdev
, pmc
);
2289 tegra_powergate_remove_all(pdev
->dev
.of_node
);
2290 cleanup_restart_handler
:
2291 unregister_restart_handler(&tegra_pmc_restart_handler
);
2293 debugfs_remove(pmc
->debugfs
);
2295 device_remove_file(&pdev
->dev
, &dev_attr_reset_reason
);
2296 device_remove_file(&pdev
->dev
, &dev_attr_reset_level
);
2297 clk_notifier_unregister(pmc
->clk
, &pmc
->clk_nb
);
2302 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
2303 static int tegra_pmc_suspend(struct device
*dev
)
2305 struct tegra_pmc
*pmc
= dev_get_drvdata(dev
);
2307 tegra_pmc_writel(pmc
, virt_to_phys(tegra_resume
), PMC_SCRATCH41
);
2312 static int tegra_pmc_resume(struct device
*dev
)
2314 struct tegra_pmc
*pmc
= dev_get_drvdata(dev
);
2316 tegra_pmc_writel(pmc
, 0x0, PMC_SCRATCH41
);
2321 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops
, tegra_pmc_suspend
, tegra_pmc_resume
);
2325 static const char * const tegra20_powergates
[] = {
2326 [TEGRA_POWERGATE_CPU
] = "cpu",
2327 [TEGRA_POWERGATE_3D
] = "3d",
2328 [TEGRA_POWERGATE_VENC
] = "venc",
2329 [TEGRA_POWERGATE_VDEC
] = "vdec",
2330 [TEGRA_POWERGATE_PCIE
] = "pcie",
2331 [TEGRA_POWERGATE_L2
] = "l2",
2332 [TEGRA_POWERGATE_MPE
] = "mpe",
2335 static const struct tegra_pmc_regs tegra20_pmc_regs
= {
2338 .dpd_status
= 0x1bc,
2340 .dpd2_status
= 0x1c4,
2341 .rst_status
= 0x1b4,
2342 .rst_source_shift
= 0x0,
2343 .rst_source_mask
= 0x7,
2344 .rst_level_shift
= 0x0,
2345 .rst_level_mask
= 0x0,
2348 static void tegra20_pmc_init(struct tegra_pmc
*pmc
)
2350 u32 value
, osc
, pmu
, off
;
2352 /* Always enable CPU power request */
2353 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
2354 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
2355 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
2357 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
2359 if (pmc
->sysclkreq_high
)
2360 value
&= ~PMC_CNTRL_SYSCLK_POLARITY
;
2362 value
|= PMC_CNTRL_SYSCLK_POLARITY
;
2364 if (pmc
->corereq_high
)
2365 value
&= ~PMC_CNTRL_PWRREQ_POLARITY
;
2367 value
|= PMC_CNTRL_PWRREQ_POLARITY
;
2369 /* configure the output polarity while the request is tristated */
2370 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
2372 /* now enable the request */
2373 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
2374 value
|= PMC_CNTRL_SYSCLK_OE
;
2375 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
2377 /* program core timings which are applicable only for suspend state */
2378 if (pmc
->suspend_mode
!= TEGRA_SUSPEND_NONE
) {
2379 osc
= DIV_ROUND_UP(pmc
->core_osc_time
* 8192, 1000000);
2380 pmu
= DIV_ROUND_UP(pmc
->core_pmu_time
* 32768, 1000000);
2381 off
= DIV_ROUND_UP(pmc
->core_off_time
* 32768, 1000000);
2382 tegra_pmc_writel(pmc
, ((osc
<< 8) & 0xff00) | (pmu
& 0xff),
2383 PMC_COREPWRGOOD_TIMER
);
2384 tegra_pmc_writel(pmc
, off
, PMC_COREPWROFF_TIMER
);
2388 static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc
*pmc
,
2389 struct device_node
*np
,
2394 value
= tegra_pmc_readl(pmc
, PMC_CNTRL
);
2397 value
|= PMC_CNTRL_INTR_POLARITY
;
2399 value
&= ~PMC_CNTRL_INTR_POLARITY
;
2401 tegra_pmc_writel(pmc
, value
, PMC_CNTRL
);
2404 static const struct tegra_pmc_soc tegra20_pmc_soc
= {
2405 .num_powergates
= ARRAY_SIZE(tegra20_powergates
),
2406 .powergates
= tegra20_powergates
,
2407 .num_cpu_powergates
= 0,
2408 .cpu_powergates
= NULL
,
2409 .has_tsense_reset
= false,
2410 .has_gpu_clamps
= false,
2411 .needs_mbist_war
= false,
2412 .has_impl_33v_pwr
= false,
2413 .maybe_tz_only
= false,
2418 .regs
= &tegra20_pmc_regs
,
2419 .init
= tegra20_pmc_init
,
2420 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
2421 .reset_sources
= NULL
,
2422 .num_reset_sources
= 0,
2423 .reset_levels
= NULL
,
2424 .num_reset_levels
= 0,
2427 static const char * const tegra30_powergates
[] = {
2428 [TEGRA_POWERGATE_CPU
] = "cpu0",
2429 [TEGRA_POWERGATE_3D
] = "3d0",
2430 [TEGRA_POWERGATE_VENC
] = "venc",
2431 [TEGRA_POWERGATE_VDEC
] = "vdec",
2432 [TEGRA_POWERGATE_PCIE
] = "pcie",
2433 [TEGRA_POWERGATE_L2
] = "l2",
2434 [TEGRA_POWERGATE_MPE
] = "mpe",
2435 [TEGRA_POWERGATE_HEG
] = "heg",
2436 [TEGRA_POWERGATE_SATA
] = "sata",
2437 [TEGRA_POWERGATE_CPU1
] = "cpu1",
2438 [TEGRA_POWERGATE_CPU2
] = "cpu2",
2439 [TEGRA_POWERGATE_CPU3
] = "cpu3",
2440 [TEGRA_POWERGATE_CELP
] = "celp",
2441 [TEGRA_POWERGATE_3D1
] = "3d1",
2444 static const u8 tegra30_cpu_powergates
[] = {
2445 TEGRA_POWERGATE_CPU
,
2446 TEGRA_POWERGATE_CPU1
,
2447 TEGRA_POWERGATE_CPU2
,
2448 TEGRA_POWERGATE_CPU3
,
2451 static const struct tegra_pmc_soc tegra30_pmc_soc
= {
2452 .num_powergates
= ARRAY_SIZE(tegra30_powergates
),
2453 .powergates
= tegra30_powergates
,
2454 .num_cpu_powergates
= ARRAY_SIZE(tegra30_cpu_powergates
),
2455 .cpu_powergates
= tegra30_cpu_powergates
,
2456 .has_tsense_reset
= true,
2457 .has_gpu_clamps
= false,
2458 .needs_mbist_war
= false,
2459 .has_impl_33v_pwr
= false,
2460 .maybe_tz_only
= false,
2465 .regs
= &tegra20_pmc_regs
,
2466 .init
= tegra20_pmc_init
,
2467 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
2468 .reset_sources
= tegra30_reset_sources
,
2469 .num_reset_sources
= ARRAY_SIZE(tegra30_reset_sources
),
2470 .reset_levels
= NULL
,
2471 .num_reset_levels
= 0,
2474 static const char * const tegra114_powergates
[] = {
2475 [TEGRA_POWERGATE_CPU
] = "crail",
2476 [TEGRA_POWERGATE_3D
] = "3d",
2477 [TEGRA_POWERGATE_VENC
] = "venc",
2478 [TEGRA_POWERGATE_VDEC
] = "vdec",
2479 [TEGRA_POWERGATE_MPE
] = "mpe",
2480 [TEGRA_POWERGATE_HEG
] = "heg",
2481 [TEGRA_POWERGATE_CPU1
] = "cpu1",
2482 [TEGRA_POWERGATE_CPU2
] = "cpu2",
2483 [TEGRA_POWERGATE_CPU3
] = "cpu3",
2484 [TEGRA_POWERGATE_CELP
] = "celp",
2485 [TEGRA_POWERGATE_CPU0
] = "cpu0",
2486 [TEGRA_POWERGATE_C0NC
] = "c0nc",
2487 [TEGRA_POWERGATE_C1NC
] = "c1nc",
2488 [TEGRA_POWERGATE_DIS
] = "dis",
2489 [TEGRA_POWERGATE_DISB
] = "disb",
2490 [TEGRA_POWERGATE_XUSBA
] = "xusba",
2491 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
2492 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
2495 static const u8 tegra114_cpu_powergates
[] = {
2496 TEGRA_POWERGATE_CPU0
,
2497 TEGRA_POWERGATE_CPU1
,
2498 TEGRA_POWERGATE_CPU2
,
2499 TEGRA_POWERGATE_CPU3
,
2502 static const struct tegra_pmc_soc tegra114_pmc_soc
= {
2503 .num_powergates
= ARRAY_SIZE(tegra114_powergates
),
2504 .powergates
= tegra114_powergates
,
2505 .num_cpu_powergates
= ARRAY_SIZE(tegra114_cpu_powergates
),
2506 .cpu_powergates
= tegra114_cpu_powergates
,
2507 .has_tsense_reset
= true,
2508 .has_gpu_clamps
= false,
2509 .needs_mbist_war
= false,
2510 .has_impl_33v_pwr
= false,
2511 .maybe_tz_only
= false,
2516 .regs
= &tegra20_pmc_regs
,
2517 .init
= tegra20_pmc_init
,
2518 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
2519 .reset_sources
= tegra30_reset_sources
,
2520 .num_reset_sources
= ARRAY_SIZE(tegra30_reset_sources
),
2521 .reset_levels
= NULL
,
2522 .num_reset_levels
= 0,
2525 static const char * const tegra124_powergates
[] = {
2526 [TEGRA_POWERGATE_CPU
] = "crail",
2527 [TEGRA_POWERGATE_3D
] = "3d",
2528 [TEGRA_POWERGATE_VENC
] = "venc",
2529 [TEGRA_POWERGATE_PCIE
] = "pcie",
2530 [TEGRA_POWERGATE_VDEC
] = "vdec",
2531 [TEGRA_POWERGATE_MPE
] = "mpe",
2532 [TEGRA_POWERGATE_HEG
] = "heg",
2533 [TEGRA_POWERGATE_SATA
] = "sata",
2534 [TEGRA_POWERGATE_CPU1
] = "cpu1",
2535 [TEGRA_POWERGATE_CPU2
] = "cpu2",
2536 [TEGRA_POWERGATE_CPU3
] = "cpu3",
2537 [TEGRA_POWERGATE_CELP
] = "celp",
2538 [TEGRA_POWERGATE_CPU0
] = "cpu0",
2539 [TEGRA_POWERGATE_C0NC
] = "c0nc",
2540 [TEGRA_POWERGATE_C1NC
] = "c1nc",
2541 [TEGRA_POWERGATE_SOR
] = "sor",
2542 [TEGRA_POWERGATE_DIS
] = "dis",
2543 [TEGRA_POWERGATE_DISB
] = "disb",
2544 [TEGRA_POWERGATE_XUSBA
] = "xusba",
2545 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
2546 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
2547 [TEGRA_POWERGATE_VIC
] = "vic",
2548 [TEGRA_POWERGATE_IRAM
] = "iram",
2551 static const u8 tegra124_cpu_powergates
[] = {
2552 TEGRA_POWERGATE_CPU0
,
2553 TEGRA_POWERGATE_CPU1
,
2554 TEGRA_POWERGATE_CPU2
,
2555 TEGRA_POWERGATE_CPU3
,
2558 #define TEGRA_IO_PAD(_id, _dpd, _voltage, _name) \
2559 ((struct tegra_io_pad_soc) { \
2562 .voltage = (_voltage), \
2566 #define TEGRA_IO_PIN_DESC(_id, _dpd, _voltage, _name) \
2567 ((struct pinctrl_pin_desc) { \
2572 #define TEGRA124_IO_PAD_TABLE(_pad) \
2573 /* .id .dpd .voltage .name */ \
2574 _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \
2575 _pad(TEGRA_IO_PAD_BB, 15, UINT_MAX, "bb"), \
2576 _pad(TEGRA_IO_PAD_CAM, 36, UINT_MAX, "cam"), \
2577 _pad(TEGRA_IO_PAD_COMP, 22, UINT_MAX, "comp"), \
2578 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
2579 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csb"), \
2580 _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "cse"), \
2581 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
2582 _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \
2583 _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \
2584 _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \
2585 _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \
2586 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
2587 _pad(TEGRA_IO_PAD_HV, 38, UINT_MAX, "hv"), \
2588 _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \
2589 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
2590 _pad(TEGRA_IO_PAD_NAND, 13, UINT_MAX, "nand"), \
2591 _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \
2592 _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \
2593 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
2594 _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \
2595 _pad(TEGRA_IO_PAD_SDMMC1, 33, UINT_MAX, "sdmmc1"), \
2596 _pad(TEGRA_IO_PAD_SDMMC3, 34, UINT_MAX, "sdmmc3"), \
2597 _pad(TEGRA_IO_PAD_SDMMC4, 35, UINT_MAX, "sdmmc4"), \
2598 _pad(TEGRA_IO_PAD_SYS_DDC, 58, UINT_MAX, "sys_ddc"), \
2599 _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \
2600 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
2601 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
2602 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
2603 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb_bias")
2605 static const struct tegra_io_pad_soc tegra124_io_pads
[] = {
2606 TEGRA124_IO_PAD_TABLE(TEGRA_IO_PAD
)
2609 static const struct pinctrl_pin_desc tegra124_pin_descs
[] = {
2610 TEGRA124_IO_PAD_TABLE(TEGRA_IO_PIN_DESC
)
2613 static const struct tegra_pmc_soc tegra124_pmc_soc
= {
2614 .num_powergates
= ARRAY_SIZE(tegra124_powergates
),
2615 .powergates
= tegra124_powergates
,
2616 .num_cpu_powergates
= ARRAY_SIZE(tegra124_cpu_powergates
),
2617 .cpu_powergates
= tegra124_cpu_powergates
,
2618 .has_tsense_reset
= true,
2619 .has_gpu_clamps
= true,
2620 .needs_mbist_war
= false,
2621 .has_impl_33v_pwr
= false,
2622 .maybe_tz_only
= false,
2623 .num_io_pads
= ARRAY_SIZE(tegra124_io_pads
),
2624 .io_pads
= tegra124_io_pads
,
2625 .num_pin_descs
= ARRAY_SIZE(tegra124_pin_descs
),
2626 .pin_descs
= tegra124_pin_descs
,
2627 .regs
= &tegra20_pmc_regs
,
2628 .init
= tegra20_pmc_init
,
2629 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
2630 .reset_sources
= tegra30_reset_sources
,
2631 .num_reset_sources
= ARRAY_SIZE(tegra30_reset_sources
),
2632 .reset_levels
= NULL
,
2633 .num_reset_levels
= 0,
2636 static const char * const tegra210_powergates
[] = {
2637 [TEGRA_POWERGATE_CPU
] = "crail",
2638 [TEGRA_POWERGATE_3D
] = "3d",
2639 [TEGRA_POWERGATE_VENC
] = "venc",
2640 [TEGRA_POWERGATE_PCIE
] = "pcie",
2641 [TEGRA_POWERGATE_MPE
] = "mpe",
2642 [TEGRA_POWERGATE_SATA
] = "sata",
2643 [TEGRA_POWERGATE_CPU1
] = "cpu1",
2644 [TEGRA_POWERGATE_CPU2
] = "cpu2",
2645 [TEGRA_POWERGATE_CPU3
] = "cpu3",
2646 [TEGRA_POWERGATE_CPU0
] = "cpu0",
2647 [TEGRA_POWERGATE_C0NC
] = "c0nc",
2648 [TEGRA_POWERGATE_SOR
] = "sor",
2649 [TEGRA_POWERGATE_DIS
] = "dis",
2650 [TEGRA_POWERGATE_DISB
] = "disb",
2651 [TEGRA_POWERGATE_XUSBA
] = "xusba",
2652 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
2653 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
2654 [TEGRA_POWERGATE_VIC
] = "vic",
2655 [TEGRA_POWERGATE_IRAM
] = "iram",
2656 [TEGRA_POWERGATE_NVDEC
] = "nvdec",
2657 [TEGRA_POWERGATE_NVJPG
] = "nvjpg",
2658 [TEGRA_POWERGATE_AUD
] = "aud",
2659 [TEGRA_POWERGATE_DFD
] = "dfd",
2660 [TEGRA_POWERGATE_VE2
] = "ve2",
2663 static const u8 tegra210_cpu_powergates
[] = {
2664 TEGRA_POWERGATE_CPU0
,
2665 TEGRA_POWERGATE_CPU1
,
2666 TEGRA_POWERGATE_CPU2
,
2667 TEGRA_POWERGATE_CPU3
,
2670 #define TEGRA210_IO_PAD_TABLE(_pad) \
2671 /* .id .dpd .voltage .name */ \
2672 _pad(TEGRA_IO_PAD_AUDIO, 17, 5, "audio"), \
2673 _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 18, "audio-hv"), \
2674 _pad(TEGRA_IO_PAD_CAM, 36, 10, "cam"), \
2675 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
2676 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \
2677 _pad(TEGRA_IO_PAD_CSIC, 42, UINT_MAX, "csic"), \
2678 _pad(TEGRA_IO_PAD_CSID, 43, UINT_MAX, "csid"), \
2679 _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "csie"), \
2680 _pad(TEGRA_IO_PAD_CSIF, 45, UINT_MAX, "csif"), \
2681 _pad(TEGRA_IO_PAD_DBG, 25, 19, "dbg"), \
2682 _pad(TEGRA_IO_PAD_DEBUG_NONAO, 26, UINT_MAX, "debug-nonao"), \
2683 _pad(TEGRA_IO_PAD_DMIC, 50, 20, "dmic"), \
2684 _pad(TEGRA_IO_PAD_DP, 51, UINT_MAX, "dp"), \
2685 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
2686 _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \
2687 _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \
2688 _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \
2689 _pad(TEGRA_IO_PAD_EMMC, 35, UINT_MAX, "emmc"), \
2690 _pad(TEGRA_IO_PAD_EMMC2, 37, UINT_MAX, "emmc2"), \
2691 _pad(TEGRA_IO_PAD_GPIO, 27, 21, "gpio"), \
2692 _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \
2693 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
2694 _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \
2695 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
2696 _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \
2697 _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \
2698 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
2699 _pad(TEGRA_IO_PAD_PEX_CNTRL, UINT_MAX, 11, "pex-cntrl"), \
2700 _pad(TEGRA_IO_PAD_SDMMC1, 33, 12, "sdmmc1"), \
2701 _pad(TEGRA_IO_PAD_SDMMC3, 34, 13, "sdmmc3"), \
2702 _pad(TEGRA_IO_PAD_SPI, 46, 22, "spi"), \
2703 _pad(TEGRA_IO_PAD_SPI_HV, 47, 23, "spi-hv"), \
2704 _pad(TEGRA_IO_PAD_UART, 14, 2, "uart"), \
2705 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
2706 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
2707 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
2708 _pad(TEGRA_IO_PAD_USB3, 18, UINT_MAX, "usb3"), \
2709 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias")
2711 static const struct tegra_io_pad_soc tegra210_io_pads
[] = {
2712 TEGRA210_IO_PAD_TABLE(TEGRA_IO_PAD
)
2715 static const struct pinctrl_pin_desc tegra210_pin_descs
[] = {
2716 TEGRA210_IO_PAD_TABLE(TEGRA_IO_PIN_DESC
)
2719 static const struct tegra_wake_event tegra210_wake_events
[] = {
2720 TEGRA_WAKE_IRQ("rtc", 16, 2),
2723 static const struct tegra_pmc_soc tegra210_pmc_soc
= {
2724 .num_powergates
= ARRAY_SIZE(tegra210_powergates
),
2725 .powergates
= tegra210_powergates
,
2726 .num_cpu_powergates
= ARRAY_SIZE(tegra210_cpu_powergates
),
2727 .cpu_powergates
= tegra210_cpu_powergates
,
2728 .has_tsense_reset
= true,
2729 .has_gpu_clamps
= true,
2730 .needs_mbist_war
= true,
2731 .has_impl_33v_pwr
= false,
2732 .maybe_tz_only
= true,
2733 .num_io_pads
= ARRAY_SIZE(tegra210_io_pads
),
2734 .io_pads
= tegra210_io_pads
,
2735 .num_pin_descs
= ARRAY_SIZE(tegra210_pin_descs
),
2736 .pin_descs
= tegra210_pin_descs
,
2737 .regs
= &tegra20_pmc_regs
,
2738 .init
= tegra20_pmc_init
,
2739 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
2740 .irq_set_wake
= tegra210_pmc_irq_set_wake
,
2741 .irq_set_type
= tegra210_pmc_irq_set_type
,
2742 .reset_sources
= tegra210_reset_sources
,
2743 .num_reset_sources
= ARRAY_SIZE(tegra210_reset_sources
),
2744 .reset_levels
= NULL
,
2745 .num_reset_levels
= 0,
2746 .num_wake_events
= ARRAY_SIZE(tegra210_wake_events
),
2747 .wake_events
= tegra210_wake_events
,
2750 #define TEGRA186_IO_PAD_TABLE(_pad) \
2751 /* .id .dpd .voltage .name */ \
2752 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
2753 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \
2754 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
2755 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
2756 _pad(TEGRA_IO_PAD_PEX_CLK_BIAS, 4, UINT_MAX, "pex-clk-bias"), \
2757 _pad(TEGRA_IO_PAD_PEX_CLK3, 5, UINT_MAX, "pex-clk3"), \
2758 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
2759 _pad(TEGRA_IO_PAD_PEX_CLK1, 7, UINT_MAX, "pex-clk1"), \
2760 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
2761 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
2762 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
2763 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias"), \
2764 _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \
2765 _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \
2766 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
2767 _pad(TEGRA_IO_PAD_DBG, 25, UINT_MAX, "dbg"), \
2768 _pad(TEGRA_IO_PAD_HDMI_DP0, 28, UINT_MAX, "hdmi-dp0"), \
2769 _pad(TEGRA_IO_PAD_HDMI_DP1, 29, UINT_MAX, "hdmi-dp1"), \
2770 _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \
2771 _pad(TEGRA_IO_PAD_SDMMC2_HV, 34, 5, "sdmmc2-hv"), \
2772 _pad(TEGRA_IO_PAD_SDMMC4, 36, UINT_MAX, "sdmmc4"), \
2773 _pad(TEGRA_IO_PAD_CAM, 38, UINT_MAX, "cam"), \
2774 _pad(TEGRA_IO_PAD_DSIB, 40, UINT_MAX, "dsib"), \
2775 _pad(TEGRA_IO_PAD_DSIC, 41, UINT_MAX, "dsic"), \
2776 _pad(TEGRA_IO_PAD_DSID, 42, UINT_MAX, "dsid"), \
2777 _pad(TEGRA_IO_PAD_CSIC, 43, UINT_MAX, "csic"), \
2778 _pad(TEGRA_IO_PAD_CSID, 44, UINT_MAX, "csid"), \
2779 _pad(TEGRA_IO_PAD_CSIE, 45, UINT_MAX, "csie"), \
2780 _pad(TEGRA_IO_PAD_CSIF, 46, UINT_MAX, "csif"), \
2781 _pad(TEGRA_IO_PAD_SPI, 47, UINT_MAX, "spi"), \
2782 _pad(TEGRA_IO_PAD_UFS, 49, UINT_MAX, "ufs"), \
2783 _pad(TEGRA_IO_PAD_DMIC_HV, 52, 2, "dmic-hv"), \
2784 _pad(TEGRA_IO_PAD_EDP, 53, UINT_MAX, "edp"), \
2785 _pad(TEGRA_IO_PAD_SDMMC1_HV, 55, 4, "sdmmc1-hv"), \
2786 _pad(TEGRA_IO_PAD_SDMMC3_HV, 56, 6, "sdmmc3-hv"), \
2787 _pad(TEGRA_IO_PAD_CONN, 60, UINT_MAX, "conn"), \
2788 _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 1, "audio-hv"), \
2789 _pad(TEGRA_IO_PAD_AO_HV, UINT_MAX, 0, "ao-hv")
2791 static const struct tegra_io_pad_soc tegra186_io_pads
[] = {
2792 TEGRA186_IO_PAD_TABLE(TEGRA_IO_PAD
)
2795 static const struct pinctrl_pin_desc tegra186_pin_descs
[] = {
2796 TEGRA186_IO_PAD_TABLE(TEGRA_IO_PIN_DESC
)
2799 static const struct tegra_pmc_regs tegra186_pmc_regs
= {
2804 .dpd2_status
= 0x80,
2806 .rst_source_shift
= 0x2,
2807 .rst_source_mask
= 0x3c,
2808 .rst_level_shift
= 0x0,
2809 .rst_level_mask
= 0x3,
2812 static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc
*pmc
,
2813 struct device_node
*np
,
2816 struct resource regs
;
2821 index
= of_property_match_string(np
, "reg-names", "wake");
2823 dev_err(pmc
->dev
, "failed to find PMC wake registers\n");
2827 of_address_to_resource(np
, index
, ®s
);
2829 wake
= ioremap(regs
.start
, resource_size(®s
));
2831 dev_err(pmc
->dev
, "failed to map PMC wake registers\n");
2835 value
= readl(wake
+ WAKE_AOWAKE_CTRL
);
2838 value
|= WAKE_AOWAKE_CTRL_INTR_POLARITY
;
2840 value
&= ~WAKE_AOWAKE_CTRL_INTR_POLARITY
;
2842 writel(value
, wake
+ WAKE_AOWAKE_CTRL
);
2847 static const struct tegra_wake_event tegra186_wake_events
[] = {
2848 TEGRA_WAKE_GPIO("power", 29, 1, TEGRA186_AON_GPIO(FF
, 0)),
2849 TEGRA_WAKE_IRQ("rtc", 73, 10),
2852 static const struct tegra_pmc_soc tegra186_pmc_soc
= {
2853 .num_powergates
= 0,
2855 .num_cpu_powergates
= 0,
2856 .cpu_powergates
= NULL
,
2857 .has_tsense_reset
= false,
2858 .has_gpu_clamps
= false,
2859 .needs_mbist_war
= false,
2860 .has_impl_33v_pwr
= true,
2861 .maybe_tz_only
= false,
2862 .num_io_pads
= ARRAY_SIZE(tegra186_io_pads
),
2863 .io_pads
= tegra186_io_pads
,
2864 .num_pin_descs
= ARRAY_SIZE(tegra186_pin_descs
),
2865 .pin_descs
= tegra186_pin_descs
,
2866 .regs
= &tegra186_pmc_regs
,
2868 .setup_irq_polarity
= tegra186_pmc_setup_irq_polarity
,
2869 .irq_set_wake
= tegra186_pmc_irq_set_wake
,
2870 .irq_set_type
= tegra186_pmc_irq_set_type
,
2871 .reset_sources
= tegra186_reset_sources
,
2872 .num_reset_sources
= ARRAY_SIZE(tegra186_reset_sources
),
2873 .reset_levels
= tegra186_reset_levels
,
2874 .num_reset_levels
= ARRAY_SIZE(tegra186_reset_levels
),
2875 .num_wake_events
= ARRAY_SIZE(tegra186_wake_events
),
2876 .wake_events
= tegra186_wake_events
,
2879 static const struct tegra_io_pad_soc tegra194_io_pads
[] = {
2880 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
2881 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
2882 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
2883 { .id
= TEGRA_IO_PAD_PEX_CLK_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
2884 { .id
= TEGRA_IO_PAD_PEX_CLK3
, .dpd
= 5, .voltage
= UINT_MAX
},
2885 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
2886 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 7, .voltage
= UINT_MAX
},
2887 { .id
= TEGRA_IO_PAD_EQOS
, .dpd
= 8, .voltage
= UINT_MAX
},
2888 { .id
= TEGRA_IO_PAD_PEX_CLK2_BIAS
, .dpd
= 9, .voltage
= UINT_MAX
},
2889 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 10, .voltage
= UINT_MAX
},
2890 { .id
= TEGRA_IO_PAD_DAP3
, .dpd
= 11, .voltage
= UINT_MAX
},
2891 { .id
= TEGRA_IO_PAD_DAP5
, .dpd
= 12, .voltage
= UINT_MAX
},
2892 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= UINT_MAX
},
2893 { .id
= TEGRA_IO_PAD_PWR_CTL
, .dpd
= 15, .voltage
= UINT_MAX
},
2894 { .id
= TEGRA_IO_PAD_SOC_GPIO53
, .dpd
= 16, .voltage
= UINT_MAX
},
2895 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= UINT_MAX
},
2896 { .id
= TEGRA_IO_PAD_GP_PWM2
, .dpd
= 18, .voltage
= UINT_MAX
},
2897 { .id
= TEGRA_IO_PAD_GP_PWM3
, .dpd
= 19, .voltage
= UINT_MAX
},
2898 { .id
= TEGRA_IO_PAD_SOC_GPIO12
, .dpd
= 20, .voltage
= UINT_MAX
},
2899 { .id
= TEGRA_IO_PAD_SOC_GPIO13
, .dpd
= 21, .voltage
= UINT_MAX
},
2900 { .id
= TEGRA_IO_PAD_SOC_GPIO10
, .dpd
= 22, .voltage
= UINT_MAX
},
2901 { .id
= TEGRA_IO_PAD_UART4
, .dpd
= 23, .voltage
= UINT_MAX
},
2902 { .id
= TEGRA_IO_PAD_UART5
, .dpd
= 24, .voltage
= UINT_MAX
},
2903 { .id
= TEGRA_IO_PAD_DBG
, .dpd
= 25, .voltage
= UINT_MAX
},
2904 { .id
= TEGRA_IO_PAD_HDMI_DP3
, .dpd
= 26, .voltage
= UINT_MAX
},
2905 { .id
= TEGRA_IO_PAD_HDMI_DP2
, .dpd
= 27, .voltage
= UINT_MAX
},
2906 { .id
= TEGRA_IO_PAD_HDMI_DP0
, .dpd
= 28, .voltage
= UINT_MAX
},
2907 { .id
= TEGRA_IO_PAD_HDMI_DP1
, .dpd
= 29, .voltage
= UINT_MAX
},
2908 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= 32, .voltage
= UINT_MAX
},
2909 { .id
= TEGRA_IO_PAD_PEX_CTL2
, .dpd
= 33, .voltage
= UINT_MAX
},
2910 { .id
= TEGRA_IO_PAD_PEX_L0_RST_N
, .dpd
= 34, .voltage
= UINT_MAX
},
2911 { .id
= TEGRA_IO_PAD_PEX_L1_RST_N
, .dpd
= 35, .voltage
= UINT_MAX
},
2912 { .id
= TEGRA_IO_PAD_SDMMC4
, .dpd
= 36, .voltage
= UINT_MAX
},
2913 { .id
= TEGRA_IO_PAD_PEX_L5_RST_N
, .dpd
= 37, .voltage
= UINT_MAX
},
2914 { .id
= TEGRA_IO_PAD_CSIC
, .dpd
= 43, .voltage
= UINT_MAX
},
2915 { .id
= TEGRA_IO_PAD_CSID
, .dpd
= 44, .voltage
= UINT_MAX
},
2916 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 45, .voltage
= UINT_MAX
},
2917 { .id
= TEGRA_IO_PAD_CSIF
, .dpd
= 46, .voltage
= UINT_MAX
},
2918 { .id
= TEGRA_IO_PAD_SPI
, .dpd
= 47, .voltage
= UINT_MAX
},
2919 { .id
= TEGRA_IO_PAD_UFS
, .dpd
= 49, .voltage
= UINT_MAX
},
2920 { .id
= TEGRA_IO_PAD_CSIG
, .dpd
= 50, .voltage
= UINT_MAX
},
2921 { .id
= TEGRA_IO_PAD_CSIH
, .dpd
= 51, .voltage
= UINT_MAX
},
2922 { .id
= TEGRA_IO_PAD_EDP
, .dpd
= 53, .voltage
= UINT_MAX
},
2923 { .id
= TEGRA_IO_PAD_SDMMC1_HV
, .dpd
= 55, .voltage
= UINT_MAX
},
2924 { .id
= TEGRA_IO_PAD_SDMMC3_HV
, .dpd
= 56, .voltage
= UINT_MAX
},
2925 { .id
= TEGRA_IO_PAD_CONN
, .dpd
= 60, .voltage
= UINT_MAX
},
2926 { .id
= TEGRA_IO_PAD_AUDIO_HV
, .dpd
= 61, .voltage
= UINT_MAX
},
2929 static const struct tegra_pmc_regs tegra194_pmc_regs
= {
2934 .dpd2_status
= 0x80,
2936 .rst_source_shift
= 0x2,
2937 .rst_source_mask
= 0x7c,
2938 .rst_level_shift
= 0x0,
2939 .rst_level_mask
= 0x3,
2942 static const char * const tegra194_reset_sources
[] = {
2966 static const struct tegra_wake_event tegra194_wake_events
[] = {
2967 TEGRA_WAKE_GPIO("power", 29, 1, TEGRA194_AON_GPIO(EE
, 4)),
2968 TEGRA_WAKE_IRQ("rtc", 73, 10),
2971 static const struct tegra_pmc_soc tegra194_pmc_soc
= {
2972 .num_powergates
= 0,
2974 .num_cpu_powergates
= 0,
2975 .cpu_powergates
= NULL
,
2976 .has_tsense_reset
= false,
2977 .has_gpu_clamps
= false,
2978 .needs_mbist_war
= false,
2979 .has_impl_33v_pwr
= false,
2980 .maybe_tz_only
= false,
2981 .num_io_pads
= ARRAY_SIZE(tegra194_io_pads
),
2982 .io_pads
= tegra194_io_pads
,
2983 .regs
= &tegra194_pmc_regs
,
2985 .setup_irq_polarity
= tegra186_pmc_setup_irq_polarity
,
2986 .irq_set_wake
= tegra186_pmc_irq_set_wake
,
2987 .irq_set_type
= tegra186_pmc_irq_set_type
,
2988 .reset_sources
= tegra194_reset_sources
,
2989 .num_reset_sources
= ARRAY_SIZE(tegra194_reset_sources
),
2990 .reset_levels
= tegra186_reset_levels
,
2991 .num_reset_levels
= ARRAY_SIZE(tegra186_reset_levels
),
2992 .num_wake_events
= ARRAY_SIZE(tegra194_wake_events
),
2993 .wake_events
= tegra194_wake_events
,
2996 static const struct of_device_id tegra_pmc_match
[] = {
2997 { .compatible
= "nvidia,tegra194-pmc", .data
= &tegra194_pmc_soc
},
2998 { .compatible
= "nvidia,tegra186-pmc", .data
= &tegra186_pmc_soc
},
2999 { .compatible
= "nvidia,tegra210-pmc", .data
= &tegra210_pmc_soc
},
3000 { .compatible
= "nvidia,tegra132-pmc", .data
= &tegra124_pmc_soc
},
3001 { .compatible
= "nvidia,tegra124-pmc", .data
= &tegra124_pmc_soc
},
3002 { .compatible
= "nvidia,tegra114-pmc", .data
= &tegra114_pmc_soc
},
3003 { .compatible
= "nvidia,tegra30-pmc", .data
= &tegra30_pmc_soc
},
3004 { .compatible
= "nvidia,tegra20-pmc", .data
= &tegra20_pmc_soc
},
3008 static struct platform_driver tegra_pmc_driver
= {
3010 .name
= "tegra-pmc",
3011 .suppress_bind_attrs
= true,
3012 .of_match_table
= tegra_pmc_match
,
3013 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
3014 .pm
= &tegra_pmc_pm_ops
,
3017 .probe
= tegra_pmc_probe
,
3019 builtin_platform_driver(tegra_pmc_driver
);
3021 static bool __init
tegra_pmc_detect_tz_only(struct tegra_pmc
*pmc
)
3025 saved
= readl(pmc
->base
+ pmc
->soc
->regs
->scratch0
);
3026 value
= saved
^ 0xffffffff;
3028 if (value
== 0xffffffff)
3031 /* write pattern and read it back */
3032 writel(value
, pmc
->base
+ pmc
->soc
->regs
->scratch0
);
3033 value
= readl(pmc
->base
+ pmc
->soc
->regs
->scratch0
);
3035 /* if we read all-zeroes, access is restricted to TZ only */
3037 pr_info("access to PMC is restricted to TZ\n");
3041 /* restore original value */
3042 writel(saved
, pmc
->base
+ pmc
->soc
->regs
->scratch0
);
3048 * Early initialization to allow access to registers in the very early boot
3051 static int __init
tegra_pmc_early_init(void)
3053 const struct of_device_id
*match
;
3054 struct device_node
*np
;
3055 struct resource regs
;
3059 mutex_init(&pmc
->powergates_lock
);
3061 np
= of_find_matching_node_and_match(NULL
, tegra_pmc_match
, &match
);
3064 * Fall back to legacy initialization for 32-bit ARM only. All
3065 * 64-bit ARM device tree files for Tegra are required to have
3068 * This is for backwards-compatibility with old device trees
3069 * that didn't contain a PMC node. Note that in this case the
3070 * SoC data can't be matched and therefore powergating is
3073 if (IS_ENABLED(CONFIG_ARM
) && soc_is_tegra()) {
3074 pr_warn("DT node not found, powergating disabled\n");
3076 regs
.start
= 0x7000e400;
3077 regs
.end
= 0x7000e7ff;
3078 regs
.flags
= IORESOURCE_MEM
;
3080 pr_warn("Using memory region %pR\n", ®s
);
3083 * At this point we're not running on Tegra, so play
3084 * nice with multi-platform kernels.
3090 * Extract information from the device tree if we've found a
3093 if (of_address_to_resource(np
, 0, ®s
) < 0) {
3094 pr_err("failed to get PMC registers\n");
3100 pmc
->base
= ioremap(regs
.start
, resource_size(®s
));
3102 pr_err("failed to map PMC registers\n");
3108 pmc
->soc
= match
->data
;
3110 if (pmc
->soc
->maybe_tz_only
)
3111 pmc
->tz_only
= tegra_pmc_detect_tz_only(pmc
);
3113 /* Create a bitmap of the available and valid partitions */
3114 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++)
3115 if (pmc
->soc
->powergates
[i
])
3116 set_bit(i
, pmc
->powergates_available
);
3119 * Invert the interrupt polarity if a PMC device tree node
3120 * exists and contains the nvidia,invert-interrupt property.
3122 invert
= of_property_read_bool(np
, "nvidia,invert-interrupt");
3124 pmc
->soc
->setup_irq_polarity(pmc
, np
, invert
);
3131 early_initcall(tegra_pmc_early_init
);