2 * drivers/soc/tegra/pmc.c
4 * Copyright (c) 2010 Google, Inc
7 * Colin Cross <ccross@google.com>
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.
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.
20 #define pr_fmt(fmt) "tegra-pmc: " fmt
22 #include <linux/kernel.h>
23 #include <linux/clk.h>
24 #include <linux/clk/tegra.h>
25 #include <linux/debugfs.h>
26 #include <linux/delay.h>
27 #include <linux/err.h>
28 #include <linux/export.h>
29 #include <linux/init.h>
31 #include <linux/iopoll.h>
33 #include <linux/of_address.h>
34 #include <linux/of_clk.h>
35 #include <linux/of_platform.h>
36 #include <linux/platform_device.h>
37 #include <linux/pm_domain.h>
38 #include <linux/reboot.h>
39 #include <linux/reset.h>
40 #include <linux/seq_file.h>
41 #include <linux/slab.h>
42 #include <linux/spinlock.h>
44 #include <soc/tegra/common.h>
45 #include <soc/tegra/fuse.h>
46 #include <soc/tegra/pmc.h>
49 #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
50 #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
51 #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
52 #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
53 #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
54 #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
55 #define PMC_CNTRL_MAIN_RST BIT(4)
57 #define DPD_SAMPLE 0x020
58 #define DPD_SAMPLE_ENABLE BIT(0)
59 #define DPD_SAMPLE_DISABLE (0 << 0)
61 #define PWRGATE_TOGGLE 0x30
62 #define PWRGATE_TOGGLE_START BIT(8)
64 #define REMOVE_CLAMPING 0x34
66 #define PWRGATE_STATUS 0x38
68 #define PMC_IMPL_E_33V_PWR 0x40
70 #define PMC_PWR_DET 0x48
72 #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
73 #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
74 #define PMC_SCRATCH0_MODE_RCM BIT(1)
75 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
76 PMC_SCRATCH0_MODE_BOOTLOADER | \
77 PMC_SCRATCH0_MODE_RCM)
79 #define PMC_CPUPWRGOOD_TIMER 0xc8
80 #define PMC_CPUPWROFF_TIMER 0xcc
82 #define PMC_PWR_DET_VALUE 0xe4
84 #define PMC_SCRATCH41 0x140
86 #define PMC_SENSOR_CTRL 0x1b0
87 #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
88 #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
90 #define PMC_RST_STATUS 0x1b4
91 #define PMC_RST_STATUS_POR 0
92 #define PMC_RST_STATUS_WATCHDOG 1
93 #define PMC_RST_STATUS_SENSOR 2
94 #define PMC_RST_STATUS_SW_MAIN 3
95 #define PMC_RST_STATUS_LP0 4
96 #define PMC_RST_STATUS_AOTAG 5
98 #define IO_DPD_REQ 0x1b8
99 #define IO_DPD_REQ_CODE_IDLE (0U << 30)
100 #define IO_DPD_REQ_CODE_OFF (1U << 30)
101 #define IO_DPD_REQ_CODE_ON (2U << 30)
102 #define IO_DPD_REQ_CODE_MASK (3U << 30)
104 #define IO_DPD_STATUS 0x1bc
105 #define IO_DPD2_REQ 0x1c0
106 #define IO_DPD2_STATUS 0x1c4
107 #define SEL_DPD_TIM 0x1c8
109 #define PMC_SCRATCH54 0x258
110 #define PMC_SCRATCH54_DATA_SHIFT 8
111 #define PMC_SCRATCH54_ADDR_SHIFT 0
113 #define PMC_SCRATCH55 0x25c
114 #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
115 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
116 #define PMC_SCRATCH55_PINMUX_SHIFT 24
117 #define PMC_SCRATCH55_16BITOP BIT(15)
118 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
119 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
121 #define GPU_RG_CNTRL 0x2d4
123 /* Tegra186 and later */
124 #define WAKE_AOWAKE_CTRL 0x4f4
125 #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0)
127 struct tegra_powergate
{
128 struct generic_pm_domain genpd
;
129 struct tegra_pmc
*pmc
;
132 unsigned int num_clks
;
133 struct reset_control
*reset
;
136 struct tegra_io_pad_soc
{
137 enum tegra_io_pad id
;
139 unsigned int voltage
;
142 struct tegra_pmc_regs
{
143 unsigned int scratch0
;
144 unsigned int dpd_req
;
145 unsigned int dpd_status
;
146 unsigned int dpd2_req
;
147 unsigned int dpd2_status
;
150 struct tegra_pmc_soc
{
151 unsigned int num_powergates
;
152 const char *const *powergates
;
153 unsigned int num_cpu_powergates
;
154 const u8
*cpu_powergates
;
156 bool has_tsense_reset
;
158 bool needs_mbist_war
;
159 bool has_impl_33v_pwr
;
161 const struct tegra_io_pad_soc
*io_pads
;
162 unsigned int num_io_pads
;
164 const struct tegra_pmc_regs
*regs
;
165 void (*init
)(struct tegra_pmc
*pmc
);
166 void (*setup_irq_polarity
)(struct tegra_pmc
*pmc
,
167 struct device_node
*np
,
172 * struct tegra_pmc - NVIDIA Tegra PMC
173 * @dev: pointer to PMC device structure
174 * @base: pointer to I/O remapped register region
175 * @clk: pointer to pclk clock
176 * @soc: pointer to SoC data structure
177 * @debugfs: pointer to debugfs entry
178 * @rate: currently configured rate of pclk
179 * @suspend_mode: lowest suspend mode available
180 * @cpu_good_time: CPU power good time (in microseconds)
181 * @cpu_off_time: CPU power off time (in microsecends)
182 * @core_osc_time: core power good OSC time (in microseconds)
183 * @core_pmu_time: core power good PMU time (in microseconds)
184 * @core_off_time: core power off time (in microseconds)
185 * @corereq_high: core power request is active-high
186 * @sysclkreq_high: system clock request is active-high
187 * @combined_req: combined power request for CPU & core
188 * @cpu_pwr_good_en: CPU power good signal is enabled
189 * @lp0_vec_phys: physical base address of the LP0 warm boot code
190 * @lp0_vec_size: size of the LP0 warm boot code
191 * @powergates_available: Bitmap of available power gates
192 * @powergates_lock: mutex for power gate register access
199 void __iomem
*scratch
;
201 struct dentry
*debugfs
;
203 const struct tegra_pmc_soc
*soc
;
207 enum tegra_suspend_mode suspend_mode
;
216 bool cpu_pwr_good_en
;
219 DECLARE_BITMAP(powergates_available
, TEGRA_POWERGATE_MAX
);
221 struct mutex powergates_lock
;
224 static struct tegra_pmc
*pmc
= &(struct tegra_pmc
) {
226 .suspend_mode
= TEGRA_SUSPEND_NONE
,
229 static inline struct tegra_powergate
*
230 to_powergate(struct generic_pm_domain
*domain
)
232 return container_of(domain
, struct tegra_powergate
, genpd
);
235 static u32
tegra_pmc_readl(unsigned long offset
)
237 return readl(pmc
->base
+ offset
);
240 static void tegra_pmc_writel(u32 value
, unsigned long offset
)
242 writel(value
, pmc
->base
+ offset
);
245 static inline bool tegra_powergate_state(int id
)
247 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
248 return (tegra_pmc_readl(GPU_RG_CNTRL
) & 0x1) == 0;
250 return (tegra_pmc_readl(PWRGATE_STATUS
) & BIT(id
)) != 0;
253 static inline bool tegra_powergate_is_valid(int id
)
255 return (pmc
->soc
&& pmc
->soc
->powergates
[id
]);
258 static inline bool tegra_powergate_is_available(int id
)
260 return test_bit(id
, pmc
->powergates_available
);
263 static int tegra_powergate_lookup(struct tegra_pmc
*pmc
, const char *name
)
267 if (!pmc
|| !pmc
->soc
|| !name
)
270 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
271 if (!tegra_powergate_is_valid(i
))
274 if (!strcmp(name
, pmc
->soc
->powergates
[i
]))
282 * tegra_powergate_set() - set the state of a partition
284 * @new_state: new state of the partition
286 static int tegra_powergate_set(unsigned int id
, bool new_state
)
291 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
294 mutex_lock(&pmc
->powergates_lock
);
296 if (tegra_powergate_state(id
) == new_state
) {
297 mutex_unlock(&pmc
->powergates_lock
);
301 tegra_pmc_writel(PWRGATE_TOGGLE_START
| id
, PWRGATE_TOGGLE
);
303 err
= readx_poll_timeout(tegra_powergate_state
, id
, status
,
304 status
== new_state
, 10, 100000);
306 mutex_unlock(&pmc
->powergates_lock
);
311 static int __tegra_powergate_remove_clamping(unsigned int id
)
315 mutex_lock(&pmc
->powergates_lock
);
318 * On Tegra124 and later, the clamps for the GPU are controlled by a
319 * separate register (with different semantics).
321 if (id
== TEGRA_POWERGATE_3D
) {
322 if (pmc
->soc
->has_gpu_clamps
) {
323 tegra_pmc_writel(0, GPU_RG_CNTRL
);
329 * Tegra 2 has a bug where PCIE and VDE clamping masks are
330 * swapped relatively to the partition ids
332 if (id
== TEGRA_POWERGATE_VDEC
)
333 mask
= (1 << TEGRA_POWERGATE_PCIE
);
334 else if (id
== TEGRA_POWERGATE_PCIE
)
335 mask
= (1 << TEGRA_POWERGATE_VDEC
);
339 tegra_pmc_writel(mask
, REMOVE_CLAMPING
);
342 mutex_unlock(&pmc
->powergates_lock
);
347 static void tegra_powergate_disable_clocks(struct tegra_powergate
*pg
)
351 for (i
= 0; i
< pg
->num_clks
; i
++)
352 clk_disable_unprepare(pg
->clks
[i
]);
355 static int tegra_powergate_enable_clocks(struct tegra_powergate
*pg
)
360 for (i
= 0; i
< pg
->num_clks
; i
++) {
361 err
= clk_prepare_enable(pg
->clks
[i
]);
370 clk_disable_unprepare(pg
->clks
[i
]);
375 int __weak
tegra210_clk_handle_mbist_war(unsigned int id
)
380 static int tegra_powergate_power_up(struct tegra_powergate
*pg
,
385 err
= reset_control_assert(pg
->reset
);
389 usleep_range(10, 20);
391 err
= tegra_powergate_set(pg
->id
, true);
395 usleep_range(10, 20);
397 err
= tegra_powergate_enable_clocks(pg
);
401 usleep_range(10, 20);
403 err
= __tegra_powergate_remove_clamping(pg
->id
);
407 usleep_range(10, 20);
409 err
= reset_control_deassert(pg
->reset
);
413 usleep_range(10, 20);
415 if (pg
->pmc
->soc
->needs_mbist_war
)
416 err
= tegra210_clk_handle_mbist_war(pg
->id
);
421 tegra_powergate_disable_clocks(pg
);
426 tegra_powergate_disable_clocks(pg
);
427 usleep_range(10, 20);
430 tegra_powergate_set(pg
->id
, false);
435 static int tegra_powergate_power_down(struct tegra_powergate
*pg
)
439 err
= tegra_powergate_enable_clocks(pg
);
443 usleep_range(10, 20);
445 err
= reset_control_assert(pg
->reset
);
449 usleep_range(10, 20);
451 tegra_powergate_disable_clocks(pg
);
453 usleep_range(10, 20);
455 err
= tegra_powergate_set(pg
->id
, false);
462 tegra_powergate_enable_clocks(pg
);
463 usleep_range(10, 20);
464 reset_control_deassert(pg
->reset
);
465 usleep_range(10, 20);
468 tegra_powergate_disable_clocks(pg
);
473 static int tegra_genpd_power_on(struct generic_pm_domain
*domain
)
475 struct tegra_powergate
*pg
= to_powergate(domain
);
478 err
= tegra_powergate_power_up(pg
, true);
480 pr_err("failed to turn on PM domain %s: %d\n", pg
->genpd
.name
,
486 static int tegra_genpd_power_off(struct generic_pm_domain
*domain
)
488 struct tegra_powergate
*pg
= to_powergate(domain
);
491 err
= tegra_powergate_power_down(pg
);
493 pr_err("failed to turn off PM domain %s: %d\n",
494 pg
->genpd
.name
, err
);
500 * tegra_powergate_power_on() - power on partition
503 int tegra_powergate_power_on(unsigned int id
)
505 if (!tegra_powergate_is_available(id
))
508 return tegra_powergate_set(id
, true);
512 * tegra_powergate_power_off() - power off partition
515 int tegra_powergate_power_off(unsigned int id
)
517 if (!tegra_powergate_is_available(id
))
520 return tegra_powergate_set(id
, false);
522 EXPORT_SYMBOL(tegra_powergate_power_off
);
525 * tegra_powergate_is_powered() - check if partition is powered
528 int tegra_powergate_is_powered(unsigned int id
)
530 if (!tegra_powergate_is_valid(id
))
533 return tegra_powergate_state(id
);
537 * tegra_powergate_remove_clamping() - remove power clamps for partition
540 int tegra_powergate_remove_clamping(unsigned int id
)
542 if (!tegra_powergate_is_available(id
))
545 return __tegra_powergate_remove_clamping(id
);
547 EXPORT_SYMBOL(tegra_powergate_remove_clamping
);
550 * tegra_powergate_sequence_power_up() - power up partition
552 * @clk: clock for partition
553 * @rst: reset for partition
555 * Must be called with clk disabled, and returns with clk enabled.
557 int tegra_powergate_sequence_power_up(unsigned int id
, struct clk
*clk
,
558 struct reset_control
*rst
)
560 struct tegra_powergate
*pg
;
563 if (!tegra_powergate_is_available(id
))
566 pg
= kzalloc(sizeof(*pg
), GFP_KERNEL
);
576 err
= tegra_powergate_power_up(pg
, false);
578 pr_err("failed to turn on partition %d: %d\n", id
, err
);
584 EXPORT_SYMBOL(tegra_powergate_sequence_power_up
);
588 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
589 * @cpuid: CPU partition ID
591 * Returns the partition ID corresponding to the CPU partition ID or a
592 * negative error code on failure.
594 static int tegra_get_cpu_powergate_id(unsigned int cpuid
)
596 if (pmc
->soc
&& cpuid
< pmc
->soc
->num_cpu_powergates
)
597 return pmc
->soc
->cpu_powergates
[cpuid
];
603 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
604 * @cpuid: CPU partition ID
606 bool tegra_pmc_cpu_is_powered(unsigned int cpuid
)
610 id
= tegra_get_cpu_powergate_id(cpuid
);
614 return tegra_powergate_is_powered(id
);
618 * tegra_pmc_cpu_power_on() - power on CPU partition
619 * @cpuid: CPU partition ID
621 int tegra_pmc_cpu_power_on(unsigned int cpuid
)
625 id
= tegra_get_cpu_powergate_id(cpuid
);
629 return tegra_powergate_set(id
, true);
633 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
634 * @cpuid: CPU partition ID
636 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid
)
640 id
= tegra_get_cpu_powergate_id(cpuid
);
644 return tegra_powergate_remove_clamping(id
);
646 #endif /* CONFIG_SMP */
648 static int tegra_pmc_restart_notify(struct notifier_block
*this,
649 unsigned long action
, void *data
)
651 const char *cmd
= data
;
654 value
= readl(pmc
->scratch
+ pmc
->soc
->regs
->scratch0
);
655 value
&= ~PMC_SCRATCH0_MODE_MASK
;
658 if (strcmp(cmd
, "recovery") == 0)
659 value
|= PMC_SCRATCH0_MODE_RECOVERY
;
661 if (strcmp(cmd
, "bootloader") == 0)
662 value
|= PMC_SCRATCH0_MODE_BOOTLOADER
;
664 if (strcmp(cmd
, "forced-recovery") == 0)
665 value
|= PMC_SCRATCH0_MODE_RCM
;
668 writel(value
, pmc
->scratch
+ pmc
->soc
->regs
->scratch0
);
670 /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
671 value
= tegra_pmc_readl(PMC_CNTRL
);
672 value
|= PMC_CNTRL_MAIN_RST
;
673 tegra_pmc_writel(value
, PMC_CNTRL
);
678 static struct notifier_block tegra_pmc_restart_handler
= {
679 .notifier_call
= tegra_pmc_restart_notify
,
683 static int powergate_show(struct seq_file
*s
, void *data
)
688 seq_printf(s
, " powergate powered\n");
689 seq_printf(s
, "------------------\n");
691 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
692 status
= tegra_powergate_is_powered(i
);
696 seq_printf(s
, " %9s %7s\n", pmc
->soc
->powergates
[i
],
697 status
? "yes" : "no");
703 static int powergate_open(struct inode
*inode
, struct file
*file
)
705 return single_open(file
, powergate_show
, inode
->i_private
);
708 static const struct file_operations powergate_fops
= {
709 .open
= powergate_open
,
712 .release
= single_release
,
715 static int tegra_powergate_debugfs_init(void)
717 pmc
->debugfs
= debugfs_create_file("powergate", S_IRUGO
, NULL
, NULL
,
725 static int tegra_powergate_of_get_clks(struct tegra_powergate
*pg
,
726 struct device_node
*np
)
729 unsigned int i
, count
;
732 count
= of_clk_get_parent_count(np
);
736 pg
->clks
= kcalloc(count
, sizeof(clk
), GFP_KERNEL
);
740 for (i
= 0; i
< count
; i
++) {
741 pg
->clks
[i
] = of_clk_get(np
, i
);
742 if (IS_ERR(pg
->clks
[i
])) {
743 err
= PTR_ERR(pg
->clks
[i
]);
748 pg
->num_clks
= count
;
754 clk_put(pg
->clks
[i
]);
761 static int tegra_powergate_of_get_resets(struct tegra_powergate
*pg
,
762 struct device_node
*np
, bool off
)
766 pg
->reset
= of_reset_control_array_get_exclusive(np
);
767 if (IS_ERR(pg
->reset
)) {
768 err
= PTR_ERR(pg
->reset
);
769 pr_err("failed to get device resets: %d\n", err
);
774 err
= reset_control_assert(pg
->reset
);
776 err
= reset_control_deassert(pg
->reset
);
779 reset_control_put(pg
->reset
);
784 static void tegra_powergate_add(struct tegra_pmc
*pmc
, struct device_node
*np
)
786 struct tegra_powergate
*pg
;
790 pg
= kzalloc(sizeof(*pg
), GFP_KERNEL
);
794 id
= tegra_powergate_lookup(pmc
, np
->name
);
796 pr_err("powergate lookup failed for %s: %d\n", np
->name
, id
);
801 * Clear the bit for this powergate so it cannot be managed
802 * directly via the legacy APIs for controlling powergates.
804 clear_bit(id
, pmc
->powergates_available
);
807 pg
->genpd
.name
= np
->name
;
808 pg
->genpd
.power_off
= tegra_genpd_power_off
;
809 pg
->genpd
.power_on
= tegra_genpd_power_on
;
812 off
= !tegra_powergate_is_powered(pg
->id
);
814 err
= tegra_powergate_of_get_clks(pg
, np
);
816 pr_err("failed to get clocks for %s: %d\n", np
->name
, err
);
820 err
= tegra_powergate_of_get_resets(pg
, np
, off
);
822 pr_err("failed to get resets for %s: %d\n", np
->name
, err
);
826 if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS
)) {
828 WARN_ON(tegra_powergate_power_up(pg
, true));
834 * FIXME: If XHCI is enabled for Tegra, then power-up the XUSB
835 * host and super-speed partitions. Once the XHCI driver
836 * manages the partitions itself this code can be removed. Note
837 * that we don't register these partitions with the genpd core
838 * to avoid it from powering down the partitions as they appear
841 if (IS_ENABLED(CONFIG_USB_XHCI_TEGRA
) &&
842 (id
== TEGRA_POWERGATE_XUSBA
|| id
== TEGRA_POWERGATE_XUSBC
)) {
844 WARN_ON(tegra_powergate_power_up(pg
, true));
849 err
= pm_genpd_init(&pg
->genpd
, NULL
, off
);
851 pr_err("failed to initialise PM domain %s: %d\n", np
->name
,
856 err
= of_genpd_add_provider_simple(np
, &pg
->genpd
);
858 pr_err("failed to add PM domain provider for %s: %d\n",
863 pr_debug("added PM domain %s\n", pg
->genpd
.name
);
868 pm_genpd_remove(&pg
->genpd
);
871 reset_control_put(pg
->reset
);
874 while (pg
->num_clks
--)
875 clk_put(pg
->clks
[pg
->num_clks
]);
880 set_bit(id
, pmc
->powergates_available
);
886 static void tegra_powergate_init(struct tegra_pmc
*pmc
,
887 struct device_node
*parent
)
889 struct device_node
*np
, *child
;
892 /* Create a bitmap of the available and valid partitions */
893 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++)
894 if (pmc
->soc
->powergates
[i
])
895 set_bit(i
, pmc
->powergates_available
);
897 np
= of_get_child_by_name(parent
, "powergates");
901 for_each_child_of_node(np
, child
)
902 tegra_powergate_add(pmc
, child
);
907 static const struct tegra_io_pad_soc
*
908 tegra_io_pad_find(struct tegra_pmc
*pmc
, enum tegra_io_pad id
)
912 for (i
= 0; i
< pmc
->soc
->num_io_pads
; i
++)
913 if (pmc
->soc
->io_pads
[i
].id
== id
)
914 return &pmc
->soc
->io_pads
[i
];
919 static int tegra_io_pad_prepare(enum tegra_io_pad id
, unsigned long *request
,
920 unsigned long *status
, u32
*mask
)
922 const struct tegra_io_pad_soc
*pad
;
923 unsigned long rate
, value
;
925 pad
= tegra_io_pad_find(pmc
, id
);
927 pr_err("invalid I/O pad ID %u\n", id
);
931 if (pad
->dpd
== UINT_MAX
)
934 *mask
= BIT(pad
->dpd
% 32);
937 *status
= pmc
->soc
->regs
->dpd_status
;
938 *request
= pmc
->soc
->regs
->dpd_req
;
940 *status
= pmc
->soc
->regs
->dpd2_status
;
941 *request
= pmc
->soc
->regs
->dpd2_req
;
945 rate
= clk_get_rate(pmc
->clk
);
947 pr_err("failed to get clock rate\n");
951 tegra_pmc_writel(DPD_SAMPLE_ENABLE
, DPD_SAMPLE
);
953 /* must be at least 200 ns, in APB (PCLK) clock cycles */
954 value
= DIV_ROUND_UP(1000000000, rate
);
955 value
= DIV_ROUND_UP(200, value
);
956 tegra_pmc_writel(value
, SEL_DPD_TIM
);
962 static int tegra_io_pad_poll(unsigned long offset
, u32 mask
,
963 u32 val
, unsigned long timeout
)
967 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
969 while (time_after(timeout
, jiffies
)) {
970 value
= tegra_pmc_readl(offset
);
971 if ((value
& mask
) == val
)
974 usleep_range(250, 1000);
980 static void tegra_io_pad_unprepare(void)
983 tegra_pmc_writel(DPD_SAMPLE_DISABLE
, DPD_SAMPLE
);
987 * tegra_io_pad_power_enable() - enable power to I/O pad
988 * @id: Tegra I/O pad ID for which to enable power
990 * Returns: 0 on success or a negative error code on failure.
992 int tegra_io_pad_power_enable(enum tegra_io_pad id
)
994 unsigned long request
, status
;
998 mutex_lock(&pmc
->powergates_lock
);
1000 err
= tegra_io_pad_prepare(id
, &request
, &status
, &mask
);
1002 pr_err("failed to prepare I/O pad: %d\n", err
);
1006 tegra_pmc_writel(IO_DPD_REQ_CODE_OFF
| mask
, request
);
1008 err
= tegra_io_pad_poll(status
, mask
, 0, 250);
1010 pr_err("failed to enable I/O pad: %d\n", err
);
1014 tegra_io_pad_unprepare();
1017 mutex_unlock(&pmc
->powergates_lock
);
1020 EXPORT_SYMBOL(tegra_io_pad_power_enable
);
1023 * tegra_io_pad_power_disable() - disable power to I/O pad
1024 * @id: Tegra I/O pad ID for which to disable power
1026 * Returns: 0 on success or a negative error code on failure.
1028 int tegra_io_pad_power_disable(enum tegra_io_pad id
)
1030 unsigned long request
, status
;
1034 mutex_lock(&pmc
->powergates_lock
);
1036 err
= tegra_io_pad_prepare(id
, &request
, &status
, &mask
);
1038 pr_err("failed to prepare I/O pad: %d\n", err
);
1042 tegra_pmc_writel(IO_DPD_REQ_CODE_ON
| mask
, request
);
1044 err
= tegra_io_pad_poll(status
, mask
, mask
, 250);
1046 pr_err("failed to disable I/O pad: %d\n", err
);
1050 tegra_io_pad_unprepare();
1053 mutex_unlock(&pmc
->powergates_lock
);
1056 EXPORT_SYMBOL(tegra_io_pad_power_disable
);
1058 int tegra_io_pad_set_voltage(enum tegra_io_pad id
,
1059 enum tegra_io_pad_voltage voltage
)
1061 const struct tegra_io_pad_soc
*pad
;
1064 pad
= tegra_io_pad_find(pmc
, id
);
1068 if (pad
->voltage
== UINT_MAX
)
1071 mutex_lock(&pmc
->powergates_lock
);
1073 if (pmc
->soc
->has_impl_33v_pwr
) {
1074 value
= tegra_pmc_readl(PMC_IMPL_E_33V_PWR
);
1076 if (voltage
== TEGRA_IO_PAD_1800000UV
)
1077 value
&= ~BIT(pad
->voltage
);
1079 value
|= BIT(pad
->voltage
);
1081 tegra_pmc_writel(value
, PMC_IMPL_E_33V_PWR
);
1083 /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
1084 value
= tegra_pmc_readl(PMC_PWR_DET
);
1085 value
|= BIT(pad
->voltage
);
1086 tegra_pmc_writel(value
, PMC_PWR_DET
);
1088 /* update I/O voltage */
1089 value
= tegra_pmc_readl(PMC_PWR_DET_VALUE
);
1091 if (voltage
== TEGRA_IO_PAD_1800000UV
)
1092 value
&= ~BIT(pad
->voltage
);
1094 value
|= BIT(pad
->voltage
);
1096 tegra_pmc_writel(value
, PMC_PWR_DET_VALUE
);
1099 mutex_unlock(&pmc
->powergates_lock
);
1101 usleep_range(100, 250);
1105 EXPORT_SYMBOL(tegra_io_pad_set_voltage
);
1107 int tegra_io_pad_get_voltage(enum tegra_io_pad id
)
1109 const struct tegra_io_pad_soc
*pad
;
1112 pad
= tegra_io_pad_find(pmc
, id
);
1116 if (pad
->voltage
== UINT_MAX
)
1119 if (pmc
->soc
->has_impl_33v_pwr
)
1120 value
= tegra_pmc_readl(PMC_IMPL_E_33V_PWR
);
1122 value
= tegra_pmc_readl(PMC_PWR_DET_VALUE
);
1124 if ((value
& BIT(pad
->voltage
)) == 0)
1125 return TEGRA_IO_PAD_1800000UV
;
1127 return TEGRA_IO_PAD_3300000UV
;
1129 EXPORT_SYMBOL(tegra_io_pad_get_voltage
);
1132 * tegra_io_rail_power_on() - enable power to I/O rail
1133 * @id: Tegra I/O pad ID for which to enable power
1135 * See also: tegra_io_pad_power_enable()
1137 int tegra_io_rail_power_on(unsigned int id
)
1139 return tegra_io_pad_power_enable(id
);
1141 EXPORT_SYMBOL(tegra_io_rail_power_on
);
1144 * tegra_io_rail_power_off() - disable power to I/O rail
1145 * @id: Tegra I/O pad ID for which to disable power
1147 * See also: tegra_io_pad_power_disable()
1149 int tegra_io_rail_power_off(unsigned int id
)
1151 return tegra_io_pad_power_disable(id
);
1153 EXPORT_SYMBOL(tegra_io_rail_power_off
);
1155 #ifdef CONFIG_PM_SLEEP
1156 enum tegra_suspend_mode
tegra_pmc_get_suspend_mode(void)
1158 return pmc
->suspend_mode
;
1161 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode
)
1163 if (mode
< TEGRA_SUSPEND_NONE
|| mode
>= TEGRA_MAX_SUSPEND_MODE
)
1166 pmc
->suspend_mode
= mode
;
1169 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode
)
1171 unsigned long long rate
= 0;
1175 case TEGRA_SUSPEND_LP1
:
1179 case TEGRA_SUSPEND_LP2
:
1180 rate
= clk_get_rate(pmc
->clk
);
1187 if (WARN_ON_ONCE(rate
== 0))
1190 if (rate
!= pmc
->rate
) {
1193 ticks
= pmc
->cpu_good_time
* rate
+ USEC_PER_SEC
- 1;
1194 do_div(ticks
, USEC_PER_SEC
);
1195 tegra_pmc_writel(ticks
, PMC_CPUPWRGOOD_TIMER
);
1197 ticks
= pmc
->cpu_off_time
* rate
+ USEC_PER_SEC
- 1;
1198 do_div(ticks
, USEC_PER_SEC
);
1199 tegra_pmc_writel(ticks
, PMC_CPUPWROFF_TIMER
);
1206 value
= tegra_pmc_readl(PMC_CNTRL
);
1207 value
&= ~PMC_CNTRL_SIDE_EFFECT_LP0
;
1208 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
1209 tegra_pmc_writel(value
, PMC_CNTRL
);
1213 static int tegra_pmc_parse_dt(struct tegra_pmc
*pmc
, struct device_node
*np
)
1215 u32 value
, values
[2];
1217 if (of_property_read_u32(np
, "nvidia,suspend-mode", &value
)) {
1221 pmc
->suspend_mode
= TEGRA_SUSPEND_LP0
;
1225 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1229 pmc
->suspend_mode
= TEGRA_SUSPEND_LP2
;
1233 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1238 pmc
->suspend_mode
= tegra_pm_validate_suspend_mode(pmc
->suspend_mode
);
1240 if (of_property_read_u32(np
, "nvidia,cpu-pwr-good-time", &value
))
1241 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1243 pmc
->cpu_good_time
= value
;
1245 if (of_property_read_u32(np
, "nvidia,cpu-pwr-off-time", &value
))
1246 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1248 pmc
->cpu_off_time
= value
;
1250 if (of_property_read_u32_array(np
, "nvidia,core-pwr-good-time",
1251 values
, ARRAY_SIZE(values
)))
1252 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1254 pmc
->core_osc_time
= values
[0];
1255 pmc
->core_pmu_time
= values
[1];
1257 if (of_property_read_u32(np
, "nvidia,core-pwr-off-time", &value
))
1258 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1260 pmc
->core_off_time
= value
;
1262 pmc
->corereq_high
= of_property_read_bool(np
,
1263 "nvidia,core-power-req-active-high");
1265 pmc
->sysclkreq_high
= of_property_read_bool(np
,
1266 "nvidia,sys-clock-req-active-high");
1268 pmc
->combined_req
= of_property_read_bool(np
,
1269 "nvidia,combined-power-req");
1271 pmc
->cpu_pwr_good_en
= of_property_read_bool(np
,
1272 "nvidia,cpu-pwr-good-en");
1274 if (of_property_read_u32_array(np
, "nvidia,lp0-vec", values
,
1275 ARRAY_SIZE(values
)))
1276 if (pmc
->suspend_mode
== TEGRA_SUSPEND_LP0
)
1277 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1279 pmc
->lp0_vec_phys
= values
[0];
1280 pmc
->lp0_vec_size
= values
[1];
1285 static void tegra_pmc_init(struct tegra_pmc
*pmc
)
1288 pmc
->soc
->init(pmc
);
1291 static void tegra_pmc_init_tsense_reset(struct tegra_pmc
*pmc
)
1293 static const char disabled
[] = "emergency thermal reset disabled";
1294 u32 pmu_addr
, ctrl_id
, reg_addr
, reg_data
, pinmux
;
1295 struct device
*dev
= pmc
->dev
;
1296 struct device_node
*np
;
1297 u32 value
, checksum
;
1299 if (!pmc
->soc
->has_tsense_reset
)
1302 np
= of_get_child_by_name(pmc
->dev
->of_node
, "i2c-thermtrip");
1304 dev_warn(dev
, "i2c-thermtrip node not found, %s.\n", disabled
);
1308 if (of_property_read_u32(np
, "nvidia,i2c-controller-id", &ctrl_id
)) {
1309 dev_err(dev
, "I2C controller ID missing, %s.\n", disabled
);
1313 if (of_property_read_u32(np
, "nvidia,bus-addr", &pmu_addr
)) {
1314 dev_err(dev
, "nvidia,bus-addr missing, %s.\n", disabled
);
1318 if (of_property_read_u32(np
, "nvidia,reg-addr", ®_addr
)) {
1319 dev_err(dev
, "nvidia,reg-addr missing, %s.\n", disabled
);
1323 if (of_property_read_u32(np
, "nvidia,reg-data", ®_data
)) {
1324 dev_err(dev
, "nvidia,reg-data missing, %s.\n", disabled
);
1328 if (of_property_read_u32(np
, "nvidia,pinmux-id", &pinmux
))
1331 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
1332 value
|= PMC_SENSOR_CTRL_SCRATCH_WRITE
;
1333 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
1335 value
= (reg_data
<< PMC_SCRATCH54_DATA_SHIFT
) |
1336 (reg_addr
<< PMC_SCRATCH54_ADDR_SHIFT
);
1337 tegra_pmc_writel(value
, PMC_SCRATCH54
);
1339 value
= PMC_SCRATCH55_RESET_TEGRA
;
1340 value
|= ctrl_id
<< PMC_SCRATCH55_CNTRL_ID_SHIFT
;
1341 value
|= pinmux
<< PMC_SCRATCH55_PINMUX_SHIFT
;
1342 value
|= pmu_addr
<< PMC_SCRATCH55_I2CSLV1_SHIFT
;
1345 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
1346 * contain the checksum and are currently zero, so they are not added.
1348 checksum
= reg_addr
+ reg_data
+ (value
& 0xff) + ((value
>> 8) & 0xff)
1349 + ((value
>> 24) & 0xff);
1351 checksum
= 0x100 - checksum
;
1353 value
|= checksum
<< PMC_SCRATCH55_CHECKSUM_SHIFT
;
1355 tegra_pmc_writel(value
, PMC_SCRATCH55
);
1357 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
1358 value
|= PMC_SENSOR_CTRL_ENABLE_RST
;
1359 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
1361 dev_info(pmc
->dev
, "emergency thermal reset enabled\n");
1367 static int tegra_pmc_probe(struct platform_device
*pdev
)
1370 struct resource
*res
;
1374 * Early initialisation should have configured an initial
1375 * register mapping and setup the soc data pointer. If these
1376 * are not valid then something went badly wrong!
1378 if (WARN_ON(!pmc
->base
|| !pmc
->soc
))
1381 err
= tegra_pmc_parse_dt(pmc
, pdev
->dev
.of_node
);
1385 /* take over the memory region from the early initialization */
1386 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1387 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1389 return PTR_ERR(base
);
1391 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "wake");
1393 pmc
->wake
= devm_ioremap_resource(&pdev
->dev
, res
);
1394 if (IS_ERR(pmc
->wake
))
1395 return PTR_ERR(pmc
->wake
);
1400 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "aotag");
1402 pmc
->aotag
= devm_ioremap_resource(&pdev
->dev
, res
);
1403 if (IS_ERR(pmc
->aotag
))
1404 return PTR_ERR(pmc
->aotag
);
1409 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "scratch");
1411 pmc
->scratch
= devm_ioremap_resource(&pdev
->dev
, res
);
1412 if (IS_ERR(pmc
->scratch
))
1413 return PTR_ERR(pmc
->scratch
);
1415 pmc
->scratch
= base
;
1418 pmc
->clk
= devm_clk_get(&pdev
->dev
, "pclk");
1419 if (IS_ERR(pmc
->clk
)) {
1420 err
= PTR_ERR(pmc
->clk
);
1422 if (err
!= -ENOENT
) {
1423 dev_err(&pdev
->dev
, "failed to get pclk: %d\n", err
);
1430 pmc
->dev
= &pdev
->dev
;
1432 tegra_pmc_init(pmc
);
1434 tegra_pmc_init_tsense_reset(pmc
);
1436 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1437 err
= tegra_powergate_debugfs_init();
1442 err
= register_restart_handler(&tegra_pmc_restart_handler
);
1444 debugfs_remove(pmc
->debugfs
);
1445 dev_err(&pdev
->dev
, "unable to register restart handler, %d\n",
1450 mutex_lock(&pmc
->powergates_lock
);
1453 mutex_unlock(&pmc
->powergates_lock
);
1458 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1459 static int tegra_pmc_suspend(struct device
*dev
)
1461 tegra_pmc_writel(virt_to_phys(tegra_resume
), PMC_SCRATCH41
);
1466 static int tegra_pmc_resume(struct device
*dev
)
1468 tegra_pmc_writel(0x0, PMC_SCRATCH41
);
1473 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops
, tegra_pmc_suspend
, tegra_pmc_resume
);
1477 static const char * const tegra20_powergates
[] = {
1478 [TEGRA_POWERGATE_CPU
] = "cpu",
1479 [TEGRA_POWERGATE_3D
] = "3d",
1480 [TEGRA_POWERGATE_VENC
] = "venc",
1481 [TEGRA_POWERGATE_VDEC
] = "vdec",
1482 [TEGRA_POWERGATE_PCIE
] = "pcie",
1483 [TEGRA_POWERGATE_L2
] = "l2",
1484 [TEGRA_POWERGATE_MPE
] = "mpe",
1487 static const struct tegra_pmc_regs tegra20_pmc_regs
= {
1490 .dpd_status
= 0x1bc,
1492 .dpd2_status
= 0x1c4,
1495 static void tegra20_pmc_init(struct tegra_pmc
*pmc
)
1499 /* Always enable CPU power request */
1500 value
= tegra_pmc_readl(PMC_CNTRL
);
1501 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
1502 tegra_pmc_writel(value
, PMC_CNTRL
);
1504 value
= tegra_pmc_readl(PMC_CNTRL
);
1506 if (pmc
->sysclkreq_high
)
1507 value
&= ~PMC_CNTRL_SYSCLK_POLARITY
;
1509 value
|= PMC_CNTRL_SYSCLK_POLARITY
;
1511 /* configure the output polarity while the request is tristated */
1512 tegra_pmc_writel(value
, PMC_CNTRL
);
1514 /* now enable the request */
1515 value
= tegra_pmc_readl(PMC_CNTRL
);
1516 value
|= PMC_CNTRL_SYSCLK_OE
;
1517 tegra_pmc_writel(value
, PMC_CNTRL
);
1520 static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc
*pmc
,
1521 struct device_node
*np
,
1526 value
= tegra_pmc_readl(PMC_CNTRL
);
1529 value
|= PMC_CNTRL_INTR_POLARITY
;
1531 value
&= ~PMC_CNTRL_INTR_POLARITY
;
1533 tegra_pmc_writel(value
, PMC_CNTRL
);
1536 static const struct tegra_pmc_soc tegra20_pmc_soc
= {
1537 .num_powergates
= ARRAY_SIZE(tegra20_powergates
),
1538 .powergates
= tegra20_powergates
,
1539 .num_cpu_powergates
= 0,
1540 .cpu_powergates
= NULL
,
1541 .has_tsense_reset
= false,
1542 .has_gpu_clamps
= false,
1545 .regs
= &tegra20_pmc_regs
,
1546 .init
= tegra20_pmc_init
,
1547 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
1550 static const char * const tegra30_powergates
[] = {
1551 [TEGRA_POWERGATE_CPU
] = "cpu0",
1552 [TEGRA_POWERGATE_3D
] = "3d0",
1553 [TEGRA_POWERGATE_VENC
] = "venc",
1554 [TEGRA_POWERGATE_VDEC
] = "vdec",
1555 [TEGRA_POWERGATE_PCIE
] = "pcie",
1556 [TEGRA_POWERGATE_L2
] = "l2",
1557 [TEGRA_POWERGATE_MPE
] = "mpe",
1558 [TEGRA_POWERGATE_HEG
] = "heg",
1559 [TEGRA_POWERGATE_SATA
] = "sata",
1560 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1561 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1562 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1563 [TEGRA_POWERGATE_CELP
] = "celp",
1564 [TEGRA_POWERGATE_3D1
] = "3d1",
1567 static const u8 tegra30_cpu_powergates
[] = {
1568 TEGRA_POWERGATE_CPU
,
1569 TEGRA_POWERGATE_CPU1
,
1570 TEGRA_POWERGATE_CPU2
,
1571 TEGRA_POWERGATE_CPU3
,
1574 static const struct tegra_pmc_soc tegra30_pmc_soc
= {
1575 .num_powergates
= ARRAY_SIZE(tegra30_powergates
),
1576 .powergates
= tegra30_powergates
,
1577 .num_cpu_powergates
= ARRAY_SIZE(tegra30_cpu_powergates
),
1578 .cpu_powergates
= tegra30_cpu_powergates
,
1579 .has_tsense_reset
= true,
1580 .has_gpu_clamps
= false,
1581 .has_impl_33v_pwr
= false,
1584 .regs
= &tegra20_pmc_regs
,
1585 .init
= tegra20_pmc_init
,
1586 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
1589 static const char * const tegra114_powergates
[] = {
1590 [TEGRA_POWERGATE_CPU
] = "crail",
1591 [TEGRA_POWERGATE_3D
] = "3d",
1592 [TEGRA_POWERGATE_VENC
] = "venc",
1593 [TEGRA_POWERGATE_VDEC
] = "vdec",
1594 [TEGRA_POWERGATE_MPE
] = "mpe",
1595 [TEGRA_POWERGATE_HEG
] = "heg",
1596 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1597 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1598 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1599 [TEGRA_POWERGATE_CELP
] = "celp",
1600 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1601 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1602 [TEGRA_POWERGATE_C1NC
] = "c1nc",
1603 [TEGRA_POWERGATE_DIS
] = "dis",
1604 [TEGRA_POWERGATE_DISB
] = "disb",
1605 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1606 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1607 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1610 static const u8 tegra114_cpu_powergates
[] = {
1611 TEGRA_POWERGATE_CPU0
,
1612 TEGRA_POWERGATE_CPU1
,
1613 TEGRA_POWERGATE_CPU2
,
1614 TEGRA_POWERGATE_CPU3
,
1617 static const struct tegra_pmc_soc tegra114_pmc_soc
= {
1618 .num_powergates
= ARRAY_SIZE(tegra114_powergates
),
1619 .powergates
= tegra114_powergates
,
1620 .num_cpu_powergates
= ARRAY_SIZE(tegra114_cpu_powergates
),
1621 .cpu_powergates
= tegra114_cpu_powergates
,
1622 .has_tsense_reset
= true,
1623 .has_gpu_clamps
= false,
1624 .has_impl_33v_pwr
= false,
1627 .regs
= &tegra20_pmc_regs
,
1628 .init
= tegra20_pmc_init
,
1629 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
1632 static const char * const tegra124_powergates
[] = {
1633 [TEGRA_POWERGATE_CPU
] = "crail",
1634 [TEGRA_POWERGATE_3D
] = "3d",
1635 [TEGRA_POWERGATE_VENC
] = "venc",
1636 [TEGRA_POWERGATE_PCIE
] = "pcie",
1637 [TEGRA_POWERGATE_VDEC
] = "vdec",
1638 [TEGRA_POWERGATE_MPE
] = "mpe",
1639 [TEGRA_POWERGATE_HEG
] = "heg",
1640 [TEGRA_POWERGATE_SATA
] = "sata",
1641 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1642 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1643 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1644 [TEGRA_POWERGATE_CELP
] = "celp",
1645 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1646 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1647 [TEGRA_POWERGATE_C1NC
] = "c1nc",
1648 [TEGRA_POWERGATE_SOR
] = "sor",
1649 [TEGRA_POWERGATE_DIS
] = "dis",
1650 [TEGRA_POWERGATE_DISB
] = "disb",
1651 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1652 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1653 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1654 [TEGRA_POWERGATE_VIC
] = "vic",
1655 [TEGRA_POWERGATE_IRAM
] = "iram",
1658 static const u8 tegra124_cpu_powergates
[] = {
1659 TEGRA_POWERGATE_CPU0
,
1660 TEGRA_POWERGATE_CPU1
,
1661 TEGRA_POWERGATE_CPU2
,
1662 TEGRA_POWERGATE_CPU3
,
1665 static const struct tegra_io_pad_soc tegra124_io_pads
[] = {
1666 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= UINT_MAX
},
1667 { .id
= TEGRA_IO_PAD_BB
, .dpd
= 15, .voltage
= UINT_MAX
},
1668 { .id
= TEGRA_IO_PAD_CAM
, .dpd
= 36, .voltage
= UINT_MAX
},
1669 { .id
= TEGRA_IO_PAD_COMP
, .dpd
= 22, .voltage
= UINT_MAX
},
1670 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
1671 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
1672 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 44, .voltage
= UINT_MAX
},
1673 { .id
= TEGRA_IO_PAD_DSI
, .dpd
= 2, .voltage
= UINT_MAX
},
1674 { .id
= TEGRA_IO_PAD_DSIB
, .dpd
= 39, .voltage
= UINT_MAX
},
1675 { .id
= TEGRA_IO_PAD_DSIC
, .dpd
= 40, .voltage
= UINT_MAX
},
1676 { .id
= TEGRA_IO_PAD_DSID
, .dpd
= 41, .voltage
= UINT_MAX
},
1677 { .id
= TEGRA_IO_PAD_HDMI
, .dpd
= 28, .voltage
= UINT_MAX
},
1678 { .id
= TEGRA_IO_PAD_HSIC
, .dpd
= 19, .voltage
= UINT_MAX
},
1679 { .id
= TEGRA_IO_PAD_HV
, .dpd
= 38, .voltage
= UINT_MAX
},
1680 { .id
= TEGRA_IO_PAD_LVDS
, .dpd
= 57, .voltage
= UINT_MAX
},
1681 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
1682 { .id
= TEGRA_IO_PAD_NAND
, .dpd
= 13, .voltage
= UINT_MAX
},
1683 { .id
= TEGRA_IO_PAD_PEX_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
1684 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 5, .voltage
= UINT_MAX
},
1685 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
1686 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= 32, .voltage
= UINT_MAX
},
1687 { .id
= TEGRA_IO_PAD_SDMMC1
, .dpd
= 33, .voltage
= UINT_MAX
},
1688 { .id
= TEGRA_IO_PAD_SDMMC3
, .dpd
= 34, .voltage
= UINT_MAX
},
1689 { .id
= TEGRA_IO_PAD_SDMMC4
, .dpd
= 35, .voltage
= UINT_MAX
},
1690 { .id
= TEGRA_IO_PAD_SYS_DDC
, .dpd
= 58, .voltage
= UINT_MAX
},
1691 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= UINT_MAX
},
1692 { .id
= TEGRA_IO_PAD_USB0
, .dpd
= 9, .voltage
= UINT_MAX
},
1693 { .id
= TEGRA_IO_PAD_USB1
, .dpd
= 10, .voltage
= UINT_MAX
},
1694 { .id
= TEGRA_IO_PAD_USB2
, .dpd
= 11, .voltage
= UINT_MAX
},
1695 { .id
= TEGRA_IO_PAD_USB_BIAS
, .dpd
= 12, .voltage
= UINT_MAX
},
1698 static const struct tegra_pmc_soc tegra124_pmc_soc
= {
1699 .num_powergates
= ARRAY_SIZE(tegra124_powergates
),
1700 .powergates
= tegra124_powergates
,
1701 .num_cpu_powergates
= ARRAY_SIZE(tegra124_cpu_powergates
),
1702 .cpu_powergates
= tegra124_cpu_powergates
,
1703 .has_tsense_reset
= true,
1704 .has_gpu_clamps
= true,
1705 .has_impl_33v_pwr
= false,
1706 .num_io_pads
= ARRAY_SIZE(tegra124_io_pads
),
1707 .io_pads
= tegra124_io_pads
,
1708 .regs
= &tegra20_pmc_regs
,
1709 .init
= tegra20_pmc_init
,
1710 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
1713 static const char * const tegra210_powergates
[] = {
1714 [TEGRA_POWERGATE_CPU
] = "crail",
1715 [TEGRA_POWERGATE_3D
] = "3d",
1716 [TEGRA_POWERGATE_VENC
] = "venc",
1717 [TEGRA_POWERGATE_PCIE
] = "pcie",
1718 [TEGRA_POWERGATE_MPE
] = "mpe",
1719 [TEGRA_POWERGATE_SATA
] = "sata",
1720 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1721 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1722 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1723 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1724 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1725 [TEGRA_POWERGATE_SOR
] = "sor",
1726 [TEGRA_POWERGATE_DIS
] = "dis",
1727 [TEGRA_POWERGATE_DISB
] = "disb",
1728 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1729 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1730 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1731 [TEGRA_POWERGATE_VIC
] = "vic",
1732 [TEGRA_POWERGATE_IRAM
] = "iram",
1733 [TEGRA_POWERGATE_NVDEC
] = "nvdec",
1734 [TEGRA_POWERGATE_NVJPG
] = "nvjpg",
1735 [TEGRA_POWERGATE_AUD
] = "aud",
1736 [TEGRA_POWERGATE_DFD
] = "dfd",
1737 [TEGRA_POWERGATE_VE2
] = "ve2",
1740 static const u8 tegra210_cpu_powergates
[] = {
1741 TEGRA_POWERGATE_CPU0
,
1742 TEGRA_POWERGATE_CPU1
,
1743 TEGRA_POWERGATE_CPU2
,
1744 TEGRA_POWERGATE_CPU3
,
1747 static const struct tegra_io_pad_soc tegra210_io_pads
[] = {
1748 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= 5 },
1749 { .id
= TEGRA_IO_PAD_AUDIO_HV
, .dpd
= 61, .voltage
= 18 },
1750 { .id
= TEGRA_IO_PAD_CAM
, .dpd
= 36, .voltage
= 10 },
1751 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
1752 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
1753 { .id
= TEGRA_IO_PAD_CSIC
, .dpd
= 42, .voltage
= UINT_MAX
},
1754 { .id
= TEGRA_IO_PAD_CSID
, .dpd
= 43, .voltage
= UINT_MAX
},
1755 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 44, .voltage
= UINT_MAX
},
1756 { .id
= TEGRA_IO_PAD_CSIF
, .dpd
= 45, .voltage
= UINT_MAX
},
1757 { .id
= TEGRA_IO_PAD_DBG
, .dpd
= 25, .voltage
= 19 },
1758 { .id
= TEGRA_IO_PAD_DEBUG_NONAO
, .dpd
= 26, .voltage
= UINT_MAX
},
1759 { .id
= TEGRA_IO_PAD_DMIC
, .dpd
= 50, .voltage
= 20 },
1760 { .id
= TEGRA_IO_PAD_DP
, .dpd
= 51, .voltage
= UINT_MAX
},
1761 { .id
= TEGRA_IO_PAD_DSI
, .dpd
= 2, .voltage
= UINT_MAX
},
1762 { .id
= TEGRA_IO_PAD_DSIB
, .dpd
= 39, .voltage
= UINT_MAX
},
1763 { .id
= TEGRA_IO_PAD_DSIC
, .dpd
= 40, .voltage
= UINT_MAX
},
1764 { .id
= TEGRA_IO_PAD_DSID
, .dpd
= 41, .voltage
= UINT_MAX
},
1765 { .id
= TEGRA_IO_PAD_EMMC
, .dpd
= 35, .voltage
= UINT_MAX
},
1766 { .id
= TEGRA_IO_PAD_EMMC2
, .dpd
= 37, .voltage
= UINT_MAX
},
1767 { .id
= TEGRA_IO_PAD_GPIO
, .dpd
= 27, .voltage
= 21 },
1768 { .id
= TEGRA_IO_PAD_HDMI
, .dpd
= 28, .voltage
= UINT_MAX
},
1769 { .id
= TEGRA_IO_PAD_HSIC
, .dpd
= 19, .voltage
= UINT_MAX
},
1770 { .id
= TEGRA_IO_PAD_LVDS
, .dpd
= 57, .voltage
= UINT_MAX
},
1771 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
1772 { .id
= TEGRA_IO_PAD_PEX_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
1773 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 5, .voltage
= UINT_MAX
},
1774 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
1775 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= UINT_MAX
, .voltage
= 11 },
1776 { .id
= TEGRA_IO_PAD_SDMMC1
, .dpd
= 33, .voltage
= 12 },
1777 { .id
= TEGRA_IO_PAD_SDMMC3
, .dpd
= 34, .voltage
= 13 },
1778 { .id
= TEGRA_IO_PAD_SPI
, .dpd
= 46, .voltage
= 22 },
1779 { .id
= TEGRA_IO_PAD_SPI_HV
, .dpd
= 47, .voltage
= 23 },
1780 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= 2 },
1781 { .id
= TEGRA_IO_PAD_USB0
, .dpd
= 9, .voltage
= UINT_MAX
},
1782 { .id
= TEGRA_IO_PAD_USB1
, .dpd
= 10, .voltage
= UINT_MAX
},
1783 { .id
= TEGRA_IO_PAD_USB2
, .dpd
= 11, .voltage
= UINT_MAX
},
1784 { .id
= TEGRA_IO_PAD_USB3
, .dpd
= 18, .voltage
= UINT_MAX
},
1785 { .id
= TEGRA_IO_PAD_USB_BIAS
, .dpd
= 12, .voltage
= UINT_MAX
},
1788 static const struct tegra_pmc_soc tegra210_pmc_soc
= {
1789 .num_powergates
= ARRAY_SIZE(tegra210_powergates
),
1790 .powergates
= tegra210_powergates
,
1791 .num_cpu_powergates
= ARRAY_SIZE(tegra210_cpu_powergates
),
1792 .cpu_powergates
= tegra210_cpu_powergates
,
1793 .has_tsense_reset
= true,
1794 .has_gpu_clamps
= true,
1795 .has_impl_33v_pwr
= false,
1796 .needs_mbist_war
= true,
1797 .num_io_pads
= ARRAY_SIZE(tegra210_io_pads
),
1798 .io_pads
= tegra210_io_pads
,
1799 .regs
= &tegra20_pmc_regs
,
1800 .init
= tegra20_pmc_init
,
1801 .setup_irq_polarity
= tegra20_pmc_setup_irq_polarity
,
1804 static const struct tegra_io_pad_soc tegra186_io_pads
[] = {
1805 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
1806 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
1807 { .id
= TEGRA_IO_PAD_DSI
, .dpd
= 2, .voltage
= UINT_MAX
},
1808 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
1809 { .id
= TEGRA_IO_PAD_PEX_CLK_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
1810 { .id
= TEGRA_IO_PAD_PEX_CLK3
, .dpd
= 5, .voltage
= UINT_MAX
},
1811 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
1812 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 7, .voltage
= UINT_MAX
},
1813 { .id
= TEGRA_IO_PAD_USB0
, .dpd
= 9, .voltage
= UINT_MAX
},
1814 { .id
= TEGRA_IO_PAD_USB1
, .dpd
= 10, .voltage
= UINT_MAX
},
1815 { .id
= TEGRA_IO_PAD_USB2
, .dpd
= 11, .voltage
= UINT_MAX
},
1816 { .id
= TEGRA_IO_PAD_USB_BIAS
, .dpd
= 12, .voltage
= UINT_MAX
},
1817 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= UINT_MAX
},
1818 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= UINT_MAX
},
1819 { .id
= TEGRA_IO_PAD_HSIC
, .dpd
= 19, .voltage
= UINT_MAX
},
1820 { .id
= TEGRA_IO_PAD_DBG
, .dpd
= 25, .voltage
= UINT_MAX
},
1821 { .id
= TEGRA_IO_PAD_HDMI_DP0
, .dpd
= 28, .voltage
= UINT_MAX
},
1822 { .id
= TEGRA_IO_PAD_HDMI_DP1
, .dpd
= 29, .voltage
= UINT_MAX
},
1823 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= 32, .voltage
= UINT_MAX
},
1824 { .id
= TEGRA_IO_PAD_SDMMC2_HV
, .dpd
= 34, .voltage
= 5 },
1825 { .id
= TEGRA_IO_PAD_SDMMC4
, .dpd
= 36, .voltage
= UINT_MAX
},
1826 { .id
= TEGRA_IO_PAD_CAM
, .dpd
= 38, .voltage
= UINT_MAX
},
1827 { .id
= TEGRA_IO_PAD_DSIB
, .dpd
= 40, .voltage
= UINT_MAX
},
1828 { .id
= TEGRA_IO_PAD_DSIC
, .dpd
= 41, .voltage
= UINT_MAX
},
1829 { .id
= TEGRA_IO_PAD_DSID
, .dpd
= 42, .voltage
= UINT_MAX
},
1830 { .id
= TEGRA_IO_PAD_CSIC
, .dpd
= 43, .voltage
= UINT_MAX
},
1831 { .id
= TEGRA_IO_PAD_CSID
, .dpd
= 44, .voltage
= UINT_MAX
},
1832 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 45, .voltage
= UINT_MAX
},
1833 { .id
= TEGRA_IO_PAD_CSIF
, .dpd
= 46, .voltage
= UINT_MAX
},
1834 { .id
= TEGRA_IO_PAD_SPI
, .dpd
= 47, .voltage
= UINT_MAX
},
1835 { .id
= TEGRA_IO_PAD_UFS
, .dpd
= 49, .voltage
= UINT_MAX
},
1836 { .id
= TEGRA_IO_PAD_DMIC_HV
, .dpd
= 52, .voltage
= 2 },
1837 { .id
= TEGRA_IO_PAD_EDP
, .dpd
= 53, .voltage
= UINT_MAX
},
1838 { .id
= TEGRA_IO_PAD_SDMMC1_HV
, .dpd
= 55, .voltage
= 4 },
1839 { .id
= TEGRA_IO_PAD_SDMMC3_HV
, .dpd
= 56, .voltage
= 6 },
1840 { .id
= TEGRA_IO_PAD_CONN
, .dpd
= 60, .voltage
= UINT_MAX
},
1841 { .id
= TEGRA_IO_PAD_AUDIO_HV
, .dpd
= 61, .voltage
= 1 },
1842 { .id
= TEGRA_IO_PAD_AO_HV
, .dpd
= UINT_MAX
, .voltage
= 0 },
1845 static const struct tegra_pmc_regs tegra186_pmc_regs
= {
1850 .dpd2_status
= 0x80,
1853 static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc
*pmc
,
1854 struct device_node
*np
,
1857 struct resource regs
;
1862 index
= of_property_match_string(np
, "reg-names", "wake");
1864 pr_err("failed to find PMC wake registers\n");
1868 of_address_to_resource(np
, index
, ®s
);
1870 wake
= ioremap_nocache(regs
.start
, resource_size(®s
));
1872 pr_err("failed to map PMC wake registers\n");
1876 value
= readl(wake
+ WAKE_AOWAKE_CTRL
);
1879 value
|= WAKE_AOWAKE_CTRL_INTR_POLARITY
;
1881 value
&= ~WAKE_AOWAKE_CTRL_INTR_POLARITY
;
1883 writel(value
, wake
+ WAKE_AOWAKE_CTRL
);
1888 static const struct tegra_pmc_soc tegra186_pmc_soc
= {
1889 .num_powergates
= 0,
1891 .num_cpu_powergates
= 0,
1892 .cpu_powergates
= NULL
,
1893 .has_tsense_reset
= false,
1894 .has_gpu_clamps
= false,
1895 .has_impl_33v_pwr
= true,
1896 .num_io_pads
= ARRAY_SIZE(tegra186_io_pads
),
1897 .io_pads
= tegra186_io_pads
,
1898 .regs
= &tegra186_pmc_regs
,
1900 .setup_irq_polarity
= tegra186_pmc_setup_irq_polarity
,
1903 static const struct of_device_id tegra_pmc_match
[] = {
1904 { .compatible
= "nvidia,tegra194-pmc", .data
= &tegra186_pmc_soc
},
1905 { .compatible
= "nvidia,tegra186-pmc", .data
= &tegra186_pmc_soc
},
1906 { .compatible
= "nvidia,tegra210-pmc", .data
= &tegra210_pmc_soc
},
1907 { .compatible
= "nvidia,tegra132-pmc", .data
= &tegra124_pmc_soc
},
1908 { .compatible
= "nvidia,tegra124-pmc", .data
= &tegra124_pmc_soc
},
1909 { .compatible
= "nvidia,tegra114-pmc", .data
= &tegra114_pmc_soc
},
1910 { .compatible
= "nvidia,tegra30-pmc", .data
= &tegra30_pmc_soc
},
1911 { .compatible
= "nvidia,tegra20-pmc", .data
= &tegra20_pmc_soc
},
1915 static struct platform_driver tegra_pmc_driver
= {
1917 .name
= "tegra-pmc",
1918 .suppress_bind_attrs
= true,
1919 .of_match_table
= tegra_pmc_match
,
1920 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1921 .pm
= &tegra_pmc_pm_ops
,
1924 .probe
= tegra_pmc_probe
,
1926 builtin_platform_driver(tegra_pmc_driver
);
1929 * Early initialization to allow access to registers in the very early boot
1932 static int __init
tegra_pmc_early_init(void)
1934 const struct of_device_id
*match
;
1935 struct device_node
*np
;
1936 struct resource regs
;
1939 mutex_init(&pmc
->powergates_lock
);
1941 np
= of_find_matching_node_and_match(NULL
, tegra_pmc_match
, &match
);
1944 * Fall back to legacy initialization for 32-bit ARM only. All
1945 * 64-bit ARM device tree files for Tegra are required to have
1948 * This is for backwards-compatibility with old device trees
1949 * that didn't contain a PMC node. Note that in this case the
1950 * SoC data can't be matched and therefore powergating is
1953 if (IS_ENABLED(CONFIG_ARM
) && soc_is_tegra()) {
1954 pr_warn("DT node not found, powergating disabled\n");
1956 regs
.start
= 0x7000e400;
1957 regs
.end
= 0x7000e7ff;
1958 regs
.flags
= IORESOURCE_MEM
;
1960 pr_warn("Using memory region %pR\n", ®s
);
1963 * At this point we're not running on Tegra, so play
1964 * nice with multi-platform kernels.
1970 * Extract information from the device tree if we've found a
1973 if (of_address_to_resource(np
, 0, ®s
) < 0) {
1974 pr_err("failed to get PMC registers\n");
1980 pmc
->base
= ioremap_nocache(regs
.start
, resource_size(®s
));
1982 pr_err("failed to map PMC registers\n");
1988 pmc
->soc
= match
->data
;
1990 tegra_powergate_init(pmc
, np
);
1993 * Invert the interrupt polarity if a PMC device tree node
1994 * exists and contains the nvidia,invert-interrupt property.
1996 invert
= of_property_read_bool(np
, "nvidia,invert-interrupt");
1998 pmc
->soc
->setup_irq_polarity(pmc
, np
, invert
);
2005 early_initcall(tegra_pmc_early_init
);