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_platform.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>
48 #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
49 #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
50 #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
51 #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
52 #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
53 #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
54 #define PMC_CNTRL_MAIN_RST BIT(4)
56 #define DPD_SAMPLE 0x020
57 #define DPD_SAMPLE_ENABLE BIT(0)
58 #define DPD_SAMPLE_DISABLE (0 << 0)
60 #define PWRGATE_TOGGLE 0x30
61 #define PWRGATE_TOGGLE_START BIT(8)
63 #define REMOVE_CLAMPING 0x34
65 #define PWRGATE_STATUS 0x38
67 #define PMC_PWR_DET 0x48
69 #define PMC_SCRATCH0 0x50
70 #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
71 #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
72 #define PMC_SCRATCH0_MODE_RCM BIT(1)
73 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
74 PMC_SCRATCH0_MODE_BOOTLOADER | \
75 PMC_SCRATCH0_MODE_RCM)
77 #define PMC_CPUPWRGOOD_TIMER 0xc8
78 #define PMC_CPUPWROFF_TIMER 0xcc
80 #define PMC_PWR_DET_VALUE 0xe4
82 #define PMC_SCRATCH41 0x140
84 #define PMC_SENSOR_CTRL 0x1b0
85 #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
86 #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
88 #define PMC_RST_STATUS 0x1b4
89 #define PMC_RST_STATUS_POR 0
90 #define PMC_RST_STATUS_WATCHDOG 1
91 #define PMC_RST_STATUS_SENSOR 2
92 #define PMC_RST_STATUS_SW_MAIN 3
93 #define PMC_RST_STATUS_LP0 4
94 #define PMC_RST_STATUS_AOTAG 5
96 #define IO_DPD_REQ 0x1b8
97 #define IO_DPD_REQ_CODE_IDLE (0U << 30)
98 #define IO_DPD_REQ_CODE_OFF (1U << 30)
99 #define IO_DPD_REQ_CODE_ON (2U << 30)
100 #define IO_DPD_REQ_CODE_MASK (3U << 30)
102 #define IO_DPD_STATUS 0x1bc
103 #define IO_DPD2_REQ 0x1c0
104 #define IO_DPD2_STATUS 0x1c4
105 #define SEL_DPD_TIM 0x1c8
107 #define PMC_SCRATCH54 0x258
108 #define PMC_SCRATCH54_DATA_SHIFT 8
109 #define PMC_SCRATCH54_ADDR_SHIFT 0
111 #define PMC_SCRATCH55 0x25c
112 #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
113 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
114 #define PMC_SCRATCH55_PINMUX_SHIFT 24
115 #define PMC_SCRATCH55_16BITOP BIT(15)
116 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
117 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
119 #define GPU_RG_CNTRL 0x2d4
121 struct tegra_powergate
{
122 struct generic_pm_domain genpd
;
123 struct tegra_pmc
*pmc
;
126 unsigned int num_clks
;
127 struct reset_control
**resets
;
128 unsigned int num_resets
;
131 struct tegra_io_pad_soc
{
132 enum tegra_io_pad id
;
134 unsigned int voltage
;
137 struct tegra_pmc_soc
{
138 unsigned int num_powergates
;
139 const char *const *powergates
;
140 unsigned int num_cpu_powergates
;
141 const u8
*cpu_powergates
;
143 bool has_tsense_reset
;
146 const struct tegra_io_pad_soc
*io_pads
;
147 unsigned int num_io_pads
;
151 * struct tegra_pmc - NVIDIA Tegra PMC
152 * @dev: pointer to PMC device structure
153 * @base: pointer to I/O remapped register region
154 * @clk: pointer to pclk clock
155 * @soc: pointer to SoC data structure
156 * @debugfs: pointer to debugfs entry
157 * @rate: currently configured rate of pclk
158 * @suspend_mode: lowest suspend mode available
159 * @cpu_good_time: CPU power good time (in microseconds)
160 * @cpu_off_time: CPU power off time (in microsecends)
161 * @core_osc_time: core power good OSC time (in microseconds)
162 * @core_pmu_time: core power good PMU time (in microseconds)
163 * @core_off_time: core power off time (in microseconds)
164 * @corereq_high: core power request is active-high
165 * @sysclkreq_high: system clock request is active-high
166 * @combined_req: combined power request for CPU & core
167 * @cpu_pwr_good_en: CPU power good signal is enabled
168 * @lp0_vec_phys: physical base address of the LP0 warm boot code
169 * @lp0_vec_size: size of the LP0 warm boot code
170 * @powergates_available: Bitmap of available power gates
171 * @powergates_lock: mutex for power gate register access
177 struct dentry
*debugfs
;
179 const struct tegra_pmc_soc
*soc
;
183 enum tegra_suspend_mode suspend_mode
;
192 bool cpu_pwr_good_en
;
195 DECLARE_BITMAP(powergates_available
, TEGRA_POWERGATE_MAX
);
197 struct mutex powergates_lock
;
200 static struct tegra_pmc
*pmc
= &(struct tegra_pmc
) {
202 .suspend_mode
= TEGRA_SUSPEND_NONE
,
205 static inline struct tegra_powergate
*
206 to_powergate(struct generic_pm_domain
*domain
)
208 return container_of(domain
, struct tegra_powergate
, genpd
);
211 static u32
tegra_pmc_readl(unsigned long offset
)
213 return readl(pmc
->base
+ offset
);
216 static void tegra_pmc_writel(u32 value
, unsigned long offset
)
218 writel(value
, pmc
->base
+ offset
);
221 static inline bool tegra_powergate_state(int id
)
223 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
224 return (tegra_pmc_readl(GPU_RG_CNTRL
) & 0x1) == 0;
226 return (tegra_pmc_readl(PWRGATE_STATUS
) & BIT(id
)) != 0;
229 static inline bool tegra_powergate_is_valid(int id
)
231 return (pmc
->soc
&& pmc
->soc
->powergates
[id
]);
234 static inline bool tegra_powergate_is_available(int id
)
236 return test_bit(id
, pmc
->powergates_available
);
239 static int tegra_powergate_lookup(struct tegra_pmc
*pmc
, const char *name
)
243 if (!pmc
|| !pmc
->soc
|| !name
)
246 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
247 if (!tegra_powergate_is_valid(i
))
250 if (!strcmp(name
, pmc
->soc
->powergates
[i
]))
258 * tegra_powergate_set() - set the state of a partition
260 * @new_state: new state of the partition
262 static int tegra_powergate_set(unsigned int id
, bool new_state
)
267 if (id
== TEGRA_POWERGATE_3D
&& pmc
->soc
->has_gpu_clamps
)
270 mutex_lock(&pmc
->powergates_lock
);
272 if (tegra_powergate_state(id
) == new_state
) {
273 mutex_unlock(&pmc
->powergates_lock
);
277 tegra_pmc_writel(PWRGATE_TOGGLE_START
| id
, PWRGATE_TOGGLE
);
279 err
= readx_poll_timeout(tegra_powergate_state
, id
, status
,
280 status
== new_state
, 10, 100000);
282 mutex_unlock(&pmc
->powergates_lock
);
287 static int __tegra_powergate_remove_clamping(unsigned int id
)
291 mutex_lock(&pmc
->powergates_lock
);
294 * On Tegra124 and later, the clamps for the GPU are controlled by a
295 * separate register (with different semantics).
297 if (id
== TEGRA_POWERGATE_3D
) {
298 if (pmc
->soc
->has_gpu_clamps
) {
299 tegra_pmc_writel(0, GPU_RG_CNTRL
);
305 * Tegra 2 has a bug where PCIE and VDE clamping masks are
306 * swapped relatively to the partition ids
308 if (id
== TEGRA_POWERGATE_VDEC
)
309 mask
= (1 << TEGRA_POWERGATE_PCIE
);
310 else if (id
== TEGRA_POWERGATE_PCIE
)
311 mask
= (1 << TEGRA_POWERGATE_VDEC
);
315 tegra_pmc_writel(mask
, REMOVE_CLAMPING
);
318 mutex_unlock(&pmc
->powergates_lock
);
323 static void tegra_powergate_disable_clocks(struct tegra_powergate
*pg
)
327 for (i
= 0; i
< pg
->num_clks
; i
++)
328 clk_disable_unprepare(pg
->clks
[i
]);
331 static int tegra_powergate_enable_clocks(struct tegra_powergate
*pg
)
336 for (i
= 0; i
< pg
->num_clks
; i
++) {
337 err
= clk_prepare_enable(pg
->clks
[i
]);
346 clk_disable_unprepare(pg
->clks
[i
]);
351 static int tegra_powergate_reset_assert(struct tegra_powergate
*pg
)
356 for (i
= 0; i
< pg
->num_resets
; i
++) {
357 err
= reset_control_assert(pg
->resets
[i
]);
365 static int tegra_powergate_reset_deassert(struct tegra_powergate
*pg
)
370 for (i
= 0; i
< pg
->num_resets
; i
++) {
371 err
= reset_control_deassert(pg
->resets
[i
]);
379 static int tegra_powergate_power_up(struct tegra_powergate
*pg
,
384 err
= tegra_powergate_reset_assert(pg
);
388 usleep_range(10, 20);
390 err
= tegra_powergate_set(pg
->id
, true);
394 usleep_range(10, 20);
396 err
= tegra_powergate_enable_clocks(pg
);
400 usleep_range(10, 20);
402 err
= __tegra_powergate_remove_clamping(pg
->id
);
406 usleep_range(10, 20);
408 err
= tegra_powergate_reset_deassert(pg
);
412 usleep_range(10, 20);
415 tegra_powergate_disable_clocks(pg
);
420 tegra_powergate_disable_clocks(pg
);
421 usleep_range(10, 20);
424 tegra_powergate_set(pg
->id
, false);
429 static int tegra_powergate_power_down(struct tegra_powergate
*pg
)
433 err
= tegra_powergate_enable_clocks(pg
);
437 usleep_range(10, 20);
439 err
= tegra_powergate_reset_assert(pg
);
443 usleep_range(10, 20);
445 tegra_powergate_disable_clocks(pg
);
447 usleep_range(10, 20);
449 err
= tegra_powergate_set(pg
->id
, false);
456 tegra_powergate_enable_clocks(pg
);
457 usleep_range(10, 20);
458 tegra_powergate_reset_deassert(pg
);
459 usleep_range(10, 20);
462 tegra_powergate_disable_clocks(pg
);
467 static int tegra_genpd_power_on(struct generic_pm_domain
*domain
)
469 struct tegra_powergate
*pg
= to_powergate(domain
);
472 err
= tegra_powergate_power_up(pg
, true);
474 pr_err("failed to turn on PM domain %s: %d\n", pg
->genpd
.name
,
480 static int tegra_genpd_power_off(struct generic_pm_domain
*domain
)
482 struct tegra_powergate
*pg
= to_powergate(domain
);
485 err
= tegra_powergate_power_down(pg
);
487 pr_err("failed to turn off PM domain %s: %d\n",
488 pg
->genpd
.name
, err
);
494 * tegra_powergate_power_on() - power on partition
497 int tegra_powergate_power_on(unsigned int id
)
499 if (!tegra_powergate_is_available(id
))
502 return tegra_powergate_set(id
, true);
506 * tegra_powergate_power_off() - power off partition
509 int tegra_powergate_power_off(unsigned int id
)
511 if (!tegra_powergate_is_available(id
))
514 return tegra_powergate_set(id
, false);
516 EXPORT_SYMBOL(tegra_powergate_power_off
);
519 * tegra_powergate_is_powered() - check if partition is powered
522 int tegra_powergate_is_powered(unsigned int id
)
526 if (!tegra_powergate_is_valid(id
))
529 mutex_lock(&pmc
->powergates_lock
);
530 status
= tegra_powergate_state(id
);
531 mutex_unlock(&pmc
->powergates_lock
);
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
))
572 err
= tegra_powergate_power_up(&pg
, false);
574 pr_err("failed to turn on partition %d: %d\n", id
, err
);
578 EXPORT_SYMBOL(tegra_powergate_sequence_power_up
);
582 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
583 * @cpuid: CPU partition ID
585 * Returns the partition ID corresponding to the CPU partition ID or a
586 * negative error code on failure.
588 static int tegra_get_cpu_powergate_id(unsigned int cpuid
)
590 if (pmc
->soc
&& cpuid
< pmc
->soc
->num_cpu_powergates
)
591 return pmc
->soc
->cpu_powergates
[cpuid
];
597 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
598 * @cpuid: CPU partition ID
600 bool tegra_pmc_cpu_is_powered(unsigned int cpuid
)
604 id
= tegra_get_cpu_powergate_id(cpuid
);
608 return tegra_powergate_is_powered(id
);
612 * tegra_pmc_cpu_power_on() - power on CPU partition
613 * @cpuid: CPU partition ID
615 int tegra_pmc_cpu_power_on(unsigned int cpuid
)
619 id
= tegra_get_cpu_powergate_id(cpuid
);
623 return tegra_powergate_set(id
, true);
627 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
628 * @cpuid: CPU partition ID
630 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid
)
634 id
= tegra_get_cpu_powergate_id(cpuid
);
638 return tegra_powergate_remove_clamping(id
);
640 #endif /* CONFIG_SMP */
642 static int tegra_pmc_restart_notify(struct notifier_block
*this,
643 unsigned long action
, void *data
)
645 const char *cmd
= data
;
648 value
= tegra_pmc_readl(PMC_SCRATCH0
);
649 value
&= ~PMC_SCRATCH0_MODE_MASK
;
652 if (strcmp(cmd
, "recovery") == 0)
653 value
|= PMC_SCRATCH0_MODE_RECOVERY
;
655 if (strcmp(cmd
, "bootloader") == 0)
656 value
|= PMC_SCRATCH0_MODE_BOOTLOADER
;
658 if (strcmp(cmd
, "forced-recovery") == 0)
659 value
|= PMC_SCRATCH0_MODE_RCM
;
662 tegra_pmc_writel(value
, PMC_SCRATCH0
);
664 /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
665 value
= tegra_pmc_readl(PMC_CNTRL
);
666 value
|= PMC_CNTRL_MAIN_RST
;
667 tegra_pmc_writel(value
, PMC_CNTRL
);
672 static struct notifier_block tegra_pmc_restart_handler
= {
673 .notifier_call
= tegra_pmc_restart_notify
,
677 static int powergate_show(struct seq_file
*s
, void *data
)
682 seq_printf(s
, " powergate powered\n");
683 seq_printf(s
, "------------------\n");
685 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
686 status
= tegra_powergate_is_powered(i
);
690 seq_printf(s
, " %9s %7s\n", pmc
->soc
->powergates
[i
],
691 status
? "yes" : "no");
697 static int powergate_open(struct inode
*inode
, struct file
*file
)
699 return single_open(file
, powergate_show
, inode
->i_private
);
702 static const struct file_operations powergate_fops
= {
703 .open
= powergate_open
,
706 .release
= single_release
,
709 static int tegra_powergate_debugfs_init(void)
711 pmc
->debugfs
= debugfs_create_file("powergate", S_IRUGO
, NULL
, NULL
,
719 static int tegra_powergate_of_get_clks(struct tegra_powergate
*pg
,
720 struct device_node
*np
)
723 unsigned int i
, count
;
726 count
= of_count_phandle_with_args(np
, "clocks", "#clock-cells");
730 pg
->clks
= kcalloc(count
, sizeof(clk
), GFP_KERNEL
);
734 for (i
= 0; i
< count
; i
++) {
735 pg
->clks
[i
] = of_clk_get(np
, i
);
736 if (IS_ERR(pg
->clks
[i
])) {
737 err
= PTR_ERR(pg
->clks
[i
]);
742 pg
->num_clks
= count
;
748 clk_put(pg
->clks
[i
]);
755 static int tegra_powergate_of_get_resets(struct tegra_powergate
*pg
,
756 struct device_node
*np
, bool off
)
758 struct reset_control
*rst
;
759 unsigned int i
, count
;
762 count
= of_count_phandle_with_args(np
, "resets", "#reset-cells");
766 pg
->resets
= kcalloc(count
, sizeof(rst
), GFP_KERNEL
);
770 for (i
= 0; i
< count
; i
++) {
771 pg
->resets
[i
] = of_reset_control_get_by_index(np
, i
);
772 if (IS_ERR(pg
->resets
[i
])) {
773 err
= PTR_ERR(pg
->resets
[i
]);
778 err
= reset_control_assert(pg
->resets
[i
]);
780 err
= reset_control_deassert(pg
->resets
[i
]);
783 reset_control_put(pg
->resets
[i
]);
788 pg
->num_resets
= count
;
794 reset_control_put(pg
->resets
[i
]);
801 static void tegra_powergate_add(struct tegra_pmc
*pmc
, struct device_node
*np
)
803 struct tegra_powergate
*pg
;
807 pg
= kzalloc(sizeof(*pg
), GFP_KERNEL
);
811 id
= tegra_powergate_lookup(pmc
, np
->name
);
813 pr_err("powergate lookup failed for %s: %d\n", np
->name
, id
);
818 * Clear the bit for this powergate so it cannot be managed
819 * directly via the legacy APIs for controlling powergates.
821 clear_bit(id
, pmc
->powergates_available
);
824 pg
->genpd
.name
= np
->name
;
825 pg
->genpd
.power_off
= tegra_genpd_power_off
;
826 pg
->genpd
.power_on
= tegra_genpd_power_on
;
829 off
= !tegra_powergate_is_powered(pg
->id
);
831 err
= tegra_powergate_of_get_clks(pg
, np
);
833 pr_err("failed to get clocks for %s: %d\n", np
->name
, err
);
837 err
= tegra_powergate_of_get_resets(pg
, np
, off
);
839 pr_err("failed to get resets for %s: %d\n", np
->name
, err
);
843 if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS
)) {
845 WARN_ON(tegra_powergate_power_up(pg
, true));
851 * FIXME: If XHCI is enabled for Tegra, then power-up the XUSB
852 * host and super-speed partitions. Once the XHCI driver
853 * manages the partitions itself this code can be removed. Note
854 * that we don't register these partitions with the genpd core
855 * to avoid it from powering down the partitions as they appear
858 if (IS_ENABLED(CONFIG_USB_XHCI_TEGRA
) &&
859 (id
== TEGRA_POWERGATE_XUSBA
|| id
== TEGRA_POWERGATE_XUSBC
)) {
861 WARN_ON(tegra_powergate_power_up(pg
, true));
866 err
= pm_genpd_init(&pg
->genpd
, NULL
, off
);
868 pr_err("failed to initialise PM domain %s: %d\n", np
->name
,
873 err
= of_genpd_add_provider_simple(np
, &pg
->genpd
);
875 pr_err("failed to add PM domain provider for %s: %d\n",
880 pr_debug("added PM domain %s\n", pg
->genpd
.name
);
885 pm_genpd_remove(&pg
->genpd
);
888 while (pg
->num_resets
--)
889 reset_control_put(pg
->resets
[pg
->num_resets
]);
894 while (pg
->num_clks
--)
895 clk_put(pg
->clks
[pg
->num_clks
]);
900 set_bit(id
, pmc
->powergates_available
);
906 static void tegra_powergate_init(struct tegra_pmc
*pmc
,
907 struct device_node
*parent
)
909 struct device_node
*np
, *child
;
912 /* Create a bitmap of the available and valid partitions */
913 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++)
914 if (pmc
->soc
->powergates
[i
])
915 set_bit(i
, pmc
->powergates_available
);
917 np
= of_get_child_by_name(parent
, "powergates");
921 for_each_child_of_node(np
, child
) {
922 tegra_powergate_add(pmc
, child
);
929 static const struct tegra_io_pad_soc
*
930 tegra_io_pad_find(struct tegra_pmc
*pmc
, enum tegra_io_pad id
)
934 for (i
= 0; i
< pmc
->soc
->num_io_pads
; i
++)
935 if (pmc
->soc
->io_pads
[i
].id
== id
)
936 return &pmc
->soc
->io_pads
[i
];
941 static int tegra_io_pad_prepare(enum tegra_io_pad id
, unsigned long *request
,
942 unsigned long *status
, u32
*mask
)
944 const struct tegra_io_pad_soc
*pad
;
945 unsigned long rate
, value
;
947 pad
= tegra_io_pad_find(pmc
, id
);
949 pr_err("invalid I/O pad ID %u\n", id
);
953 if (pad
->dpd
== UINT_MAX
)
956 *mask
= BIT(pad
->dpd
% 32);
959 *status
= IO_DPD_STATUS
;
960 *request
= IO_DPD_REQ
;
962 *status
= IO_DPD2_STATUS
;
963 *request
= IO_DPD2_REQ
;
966 rate
= clk_get_rate(pmc
->clk
);
968 pr_err("failed to get clock rate\n");
972 tegra_pmc_writel(DPD_SAMPLE_ENABLE
, DPD_SAMPLE
);
974 /* must be at least 200 ns, in APB (PCLK) clock cycles */
975 value
= DIV_ROUND_UP(1000000000, rate
);
976 value
= DIV_ROUND_UP(200, value
);
977 tegra_pmc_writel(value
, SEL_DPD_TIM
);
982 static int tegra_io_pad_poll(unsigned long offset
, u32 mask
,
983 u32 val
, unsigned long timeout
)
987 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
989 while (time_after(timeout
, jiffies
)) {
990 value
= tegra_pmc_readl(offset
);
991 if ((value
& mask
) == val
)
994 usleep_range(250, 1000);
1000 static void tegra_io_pad_unprepare(void)
1002 tegra_pmc_writel(DPD_SAMPLE_DISABLE
, DPD_SAMPLE
);
1006 * tegra_io_pad_power_enable() - enable power to I/O pad
1007 * @id: Tegra I/O pad ID for which to enable power
1009 * Returns: 0 on success or a negative error code on failure.
1011 int tegra_io_pad_power_enable(enum tegra_io_pad id
)
1013 unsigned long request
, status
;
1017 mutex_lock(&pmc
->powergates_lock
);
1019 err
= tegra_io_pad_prepare(id
, &request
, &status
, &mask
);
1021 pr_err("failed to prepare I/O pad: %d\n", err
);
1025 tegra_pmc_writel(IO_DPD_REQ_CODE_OFF
| mask
, request
);
1027 err
= tegra_io_pad_poll(status
, mask
, 0, 250);
1029 pr_err("failed to enable I/O pad: %d\n", err
);
1033 tegra_io_pad_unprepare();
1036 mutex_unlock(&pmc
->powergates_lock
);
1039 EXPORT_SYMBOL(tegra_io_pad_power_enable
);
1042 * tegra_io_pad_power_disable() - disable power to I/O pad
1043 * @id: Tegra I/O pad ID for which to disable power
1045 * Returns: 0 on success or a negative error code on failure.
1047 int tegra_io_pad_power_disable(enum tegra_io_pad id
)
1049 unsigned long request
, status
;
1053 mutex_lock(&pmc
->powergates_lock
);
1055 err
= tegra_io_pad_prepare(id
, &request
, &status
, &mask
);
1057 pr_err("failed to prepare I/O pad: %d\n", err
);
1061 tegra_pmc_writel(IO_DPD_REQ_CODE_ON
| mask
, request
);
1063 err
= tegra_io_pad_poll(status
, mask
, mask
, 250);
1065 pr_err("failed to disable I/O pad: %d\n", err
);
1069 tegra_io_pad_unprepare();
1072 mutex_unlock(&pmc
->powergates_lock
);
1075 EXPORT_SYMBOL(tegra_io_pad_power_disable
);
1077 int tegra_io_pad_set_voltage(enum tegra_io_pad id
,
1078 enum tegra_io_pad_voltage voltage
)
1080 const struct tegra_io_pad_soc
*pad
;
1083 pad
= tegra_io_pad_find(pmc
, id
);
1087 if (pad
->voltage
== UINT_MAX
)
1090 mutex_lock(&pmc
->powergates_lock
);
1092 /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
1093 value
= tegra_pmc_readl(PMC_PWR_DET
);
1094 value
|= BIT(pad
->voltage
);
1095 tegra_pmc_writel(value
, PMC_PWR_DET
);
1097 /* update I/O voltage */
1098 value
= tegra_pmc_readl(PMC_PWR_DET_VALUE
);
1100 if (voltage
== TEGRA_IO_PAD_1800000UV
)
1101 value
&= ~BIT(pad
->voltage
);
1103 value
|= BIT(pad
->voltage
);
1105 tegra_pmc_writel(value
, PMC_PWR_DET_VALUE
);
1107 mutex_unlock(&pmc
->powergates_lock
);
1109 usleep_range(100, 250);
1113 EXPORT_SYMBOL(tegra_io_pad_set_voltage
);
1115 int tegra_io_pad_get_voltage(enum tegra_io_pad id
)
1117 const struct tegra_io_pad_soc
*pad
;
1120 pad
= tegra_io_pad_find(pmc
, id
);
1124 if (pad
->voltage
== UINT_MAX
)
1127 value
= tegra_pmc_readl(PMC_PWR_DET_VALUE
);
1129 if ((value
& BIT(pad
->voltage
)) == 0)
1130 return TEGRA_IO_PAD_1800000UV
;
1132 return TEGRA_IO_PAD_3300000UV
;
1134 EXPORT_SYMBOL(tegra_io_pad_get_voltage
);
1137 * tegra_io_rail_power_on() - enable power to I/O rail
1138 * @id: Tegra I/O pad ID for which to enable power
1140 * See also: tegra_io_pad_power_enable()
1142 int tegra_io_rail_power_on(unsigned int id
)
1144 return tegra_io_pad_power_enable(id
);
1146 EXPORT_SYMBOL(tegra_io_rail_power_on
);
1149 * tegra_io_rail_power_off() - disable power to I/O rail
1150 * @id: Tegra I/O pad ID for which to disable power
1152 * See also: tegra_io_pad_power_disable()
1154 int tegra_io_rail_power_off(unsigned int id
)
1156 return tegra_io_pad_power_disable(id
);
1158 EXPORT_SYMBOL(tegra_io_rail_power_off
);
1160 #ifdef CONFIG_PM_SLEEP
1161 enum tegra_suspend_mode
tegra_pmc_get_suspend_mode(void)
1163 return pmc
->suspend_mode
;
1166 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode
)
1168 if (mode
< TEGRA_SUSPEND_NONE
|| mode
>= TEGRA_MAX_SUSPEND_MODE
)
1171 pmc
->suspend_mode
= mode
;
1174 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode
)
1176 unsigned long long rate
= 0;
1180 case TEGRA_SUSPEND_LP1
:
1184 case TEGRA_SUSPEND_LP2
:
1185 rate
= clk_get_rate(pmc
->clk
);
1192 if (WARN_ON_ONCE(rate
== 0))
1195 if (rate
!= pmc
->rate
) {
1198 ticks
= pmc
->cpu_good_time
* rate
+ USEC_PER_SEC
- 1;
1199 do_div(ticks
, USEC_PER_SEC
);
1200 tegra_pmc_writel(ticks
, PMC_CPUPWRGOOD_TIMER
);
1202 ticks
= pmc
->cpu_off_time
* rate
+ USEC_PER_SEC
- 1;
1203 do_div(ticks
, USEC_PER_SEC
);
1204 tegra_pmc_writel(ticks
, PMC_CPUPWROFF_TIMER
);
1211 value
= tegra_pmc_readl(PMC_CNTRL
);
1212 value
&= ~PMC_CNTRL_SIDE_EFFECT_LP0
;
1213 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
1214 tegra_pmc_writel(value
, PMC_CNTRL
);
1218 static int tegra_pmc_parse_dt(struct tegra_pmc
*pmc
, struct device_node
*np
)
1220 u32 value
, values
[2];
1222 if (of_property_read_u32(np
, "nvidia,suspend-mode", &value
)) {
1226 pmc
->suspend_mode
= TEGRA_SUSPEND_LP0
;
1230 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1234 pmc
->suspend_mode
= TEGRA_SUSPEND_LP2
;
1238 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1243 pmc
->suspend_mode
= tegra_pm_validate_suspend_mode(pmc
->suspend_mode
);
1245 if (of_property_read_u32(np
, "nvidia,cpu-pwr-good-time", &value
))
1246 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1248 pmc
->cpu_good_time
= value
;
1250 if (of_property_read_u32(np
, "nvidia,cpu-pwr-off-time", &value
))
1251 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1253 pmc
->cpu_off_time
= value
;
1255 if (of_property_read_u32_array(np
, "nvidia,core-pwr-good-time",
1256 values
, ARRAY_SIZE(values
)))
1257 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1259 pmc
->core_osc_time
= values
[0];
1260 pmc
->core_pmu_time
= values
[1];
1262 if (of_property_read_u32(np
, "nvidia,core-pwr-off-time", &value
))
1263 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
1265 pmc
->core_off_time
= value
;
1267 pmc
->corereq_high
= of_property_read_bool(np
,
1268 "nvidia,core-power-req-active-high");
1270 pmc
->sysclkreq_high
= of_property_read_bool(np
,
1271 "nvidia,sys-clock-req-active-high");
1273 pmc
->combined_req
= of_property_read_bool(np
,
1274 "nvidia,combined-power-req");
1276 pmc
->cpu_pwr_good_en
= of_property_read_bool(np
,
1277 "nvidia,cpu-pwr-good-en");
1279 if (of_property_read_u32_array(np
, "nvidia,lp0-vec", values
,
1280 ARRAY_SIZE(values
)))
1281 if (pmc
->suspend_mode
== TEGRA_SUSPEND_LP0
)
1282 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
1284 pmc
->lp0_vec_phys
= values
[0];
1285 pmc
->lp0_vec_size
= values
[1];
1290 static void tegra_pmc_init(struct tegra_pmc
*pmc
)
1294 /* Always enable CPU power request */
1295 value
= tegra_pmc_readl(PMC_CNTRL
);
1296 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
1297 tegra_pmc_writel(value
, PMC_CNTRL
);
1299 value
= tegra_pmc_readl(PMC_CNTRL
);
1301 if (pmc
->sysclkreq_high
)
1302 value
&= ~PMC_CNTRL_SYSCLK_POLARITY
;
1304 value
|= PMC_CNTRL_SYSCLK_POLARITY
;
1306 /* configure the output polarity while the request is tristated */
1307 tegra_pmc_writel(value
, PMC_CNTRL
);
1309 /* now enable the request */
1310 value
= tegra_pmc_readl(PMC_CNTRL
);
1311 value
|= PMC_CNTRL_SYSCLK_OE
;
1312 tegra_pmc_writel(value
, PMC_CNTRL
);
1315 static void tegra_pmc_init_tsense_reset(struct tegra_pmc
*pmc
)
1317 static const char disabled
[] = "emergency thermal reset disabled";
1318 u32 pmu_addr
, ctrl_id
, reg_addr
, reg_data
, pinmux
;
1319 struct device
*dev
= pmc
->dev
;
1320 struct device_node
*np
;
1321 u32 value
, checksum
;
1323 if (!pmc
->soc
->has_tsense_reset
)
1326 np
= of_find_node_by_name(pmc
->dev
->of_node
, "i2c-thermtrip");
1328 dev_warn(dev
, "i2c-thermtrip node not found, %s.\n", disabled
);
1332 if (of_property_read_u32(np
, "nvidia,i2c-controller-id", &ctrl_id
)) {
1333 dev_err(dev
, "I2C controller ID missing, %s.\n", disabled
);
1337 if (of_property_read_u32(np
, "nvidia,bus-addr", &pmu_addr
)) {
1338 dev_err(dev
, "nvidia,bus-addr missing, %s.\n", disabled
);
1342 if (of_property_read_u32(np
, "nvidia,reg-addr", ®_addr
)) {
1343 dev_err(dev
, "nvidia,reg-addr missing, %s.\n", disabled
);
1347 if (of_property_read_u32(np
, "nvidia,reg-data", ®_data
)) {
1348 dev_err(dev
, "nvidia,reg-data missing, %s.\n", disabled
);
1352 if (of_property_read_u32(np
, "nvidia,pinmux-id", &pinmux
))
1355 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
1356 value
|= PMC_SENSOR_CTRL_SCRATCH_WRITE
;
1357 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
1359 value
= (reg_data
<< PMC_SCRATCH54_DATA_SHIFT
) |
1360 (reg_addr
<< PMC_SCRATCH54_ADDR_SHIFT
);
1361 tegra_pmc_writel(value
, PMC_SCRATCH54
);
1363 value
= PMC_SCRATCH55_RESET_TEGRA
;
1364 value
|= ctrl_id
<< PMC_SCRATCH55_CNTRL_ID_SHIFT
;
1365 value
|= pinmux
<< PMC_SCRATCH55_PINMUX_SHIFT
;
1366 value
|= pmu_addr
<< PMC_SCRATCH55_I2CSLV1_SHIFT
;
1369 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
1370 * contain the checksum and are currently zero, so they are not added.
1372 checksum
= reg_addr
+ reg_data
+ (value
& 0xff) + ((value
>> 8) & 0xff)
1373 + ((value
>> 24) & 0xff);
1375 checksum
= 0x100 - checksum
;
1377 value
|= checksum
<< PMC_SCRATCH55_CHECKSUM_SHIFT
;
1379 tegra_pmc_writel(value
, PMC_SCRATCH55
);
1381 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
1382 value
|= PMC_SENSOR_CTRL_ENABLE_RST
;
1383 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
1385 dev_info(pmc
->dev
, "emergency thermal reset enabled\n");
1391 static int tegra_pmc_probe(struct platform_device
*pdev
)
1394 struct resource
*res
;
1398 * Early initialisation should have configured an initial
1399 * register mapping and setup the soc data pointer. If these
1400 * are not valid then something went badly wrong!
1402 if (WARN_ON(!pmc
->base
|| !pmc
->soc
))
1405 err
= tegra_pmc_parse_dt(pmc
, pdev
->dev
.of_node
);
1409 /* take over the memory region from the early initialization */
1410 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1411 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1413 return PTR_ERR(base
);
1415 pmc
->clk
= devm_clk_get(&pdev
->dev
, "pclk");
1416 if (IS_ERR(pmc
->clk
)) {
1417 err
= PTR_ERR(pmc
->clk
);
1418 dev_err(&pdev
->dev
, "failed to get pclk: %d\n", err
);
1422 pmc
->dev
= &pdev
->dev
;
1424 tegra_pmc_init(pmc
);
1426 tegra_pmc_init_tsense_reset(pmc
);
1428 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1429 err
= tegra_powergate_debugfs_init();
1434 err
= register_restart_handler(&tegra_pmc_restart_handler
);
1436 debugfs_remove(pmc
->debugfs
);
1437 dev_err(&pdev
->dev
, "unable to register restart handler, %d\n",
1442 mutex_lock(&pmc
->powergates_lock
);
1445 mutex_unlock(&pmc
->powergates_lock
);
1450 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1451 static int tegra_pmc_suspend(struct device
*dev
)
1453 tegra_pmc_writel(virt_to_phys(tegra_resume
), PMC_SCRATCH41
);
1458 static int tegra_pmc_resume(struct device
*dev
)
1460 tegra_pmc_writel(0x0, PMC_SCRATCH41
);
1465 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops
, tegra_pmc_suspend
, tegra_pmc_resume
);
1469 static const char * const tegra20_powergates
[] = {
1470 [TEGRA_POWERGATE_CPU
] = "cpu",
1471 [TEGRA_POWERGATE_3D
] = "3d",
1472 [TEGRA_POWERGATE_VENC
] = "venc",
1473 [TEGRA_POWERGATE_VDEC
] = "vdec",
1474 [TEGRA_POWERGATE_PCIE
] = "pcie",
1475 [TEGRA_POWERGATE_L2
] = "l2",
1476 [TEGRA_POWERGATE_MPE
] = "mpe",
1479 static const struct tegra_pmc_soc tegra20_pmc_soc
= {
1480 .num_powergates
= ARRAY_SIZE(tegra20_powergates
),
1481 .powergates
= tegra20_powergates
,
1482 .num_cpu_powergates
= 0,
1483 .cpu_powergates
= NULL
,
1484 .has_tsense_reset
= false,
1485 .has_gpu_clamps
= false,
1488 static const char * const tegra30_powergates
[] = {
1489 [TEGRA_POWERGATE_CPU
] = "cpu0",
1490 [TEGRA_POWERGATE_3D
] = "3d0",
1491 [TEGRA_POWERGATE_VENC
] = "venc",
1492 [TEGRA_POWERGATE_VDEC
] = "vdec",
1493 [TEGRA_POWERGATE_PCIE
] = "pcie",
1494 [TEGRA_POWERGATE_L2
] = "l2",
1495 [TEGRA_POWERGATE_MPE
] = "mpe",
1496 [TEGRA_POWERGATE_HEG
] = "heg",
1497 [TEGRA_POWERGATE_SATA
] = "sata",
1498 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1499 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1500 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1501 [TEGRA_POWERGATE_CELP
] = "celp",
1502 [TEGRA_POWERGATE_3D1
] = "3d1",
1505 static const u8 tegra30_cpu_powergates
[] = {
1506 TEGRA_POWERGATE_CPU
,
1507 TEGRA_POWERGATE_CPU1
,
1508 TEGRA_POWERGATE_CPU2
,
1509 TEGRA_POWERGATE_CPU3
,
1512 static const struct tegra_pmc_soc tegra30_pmc_soc
= {
1513 .num_powergates
= ARRAY_SIZE(tegra30_powergates
),
1514 .powergates
= tegra30_powergates
,
1515 .num_cpu_powergates
= ARRAY_SIZE(tegra30_cpu_powergates
),
1516 .cpu_powergates
= tegra30_cpu_powergates
,
1517 .has_tsense_reset
= true,
1518 .has_gpu_clamps
= false,
1521 static const char * const tegra114_powergates
[] = {
1522 [TEGRA_POWERGATE_CPU
] = "crail",
1523 [TEGRA_POWERGATE_3D
] = "3d",
1524 [TEGRA_POWERGATE_VENC
] = "venc",
1525 [TEGRA_POWERGATE_VDEC
] = "vdec",
1526 [TEGRA_POWERGATE_MPE
] = "mpe",
1527 [TEGRA_POWERGATE_HEG
] = "heg",
1528 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1529 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1530 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1531 [TEGRA_POWERGATE_CELP
] = "celp",
1532 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1533 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1534 [TEGRA_POWERGATE_C1NC
] = "c1nc",
1535 [TEGRA_POWERGATE_DIS
] = "dis",
1536 [TEGRA_POWERGATE_DISB
] = "disb",
1537 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1538 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1539 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1542 static const u8 tegra114_cpu_powergates
[] = {
1543 TEGRA_POWERGATE_CPU0
,
1544 TEGRA_POWERGATE_CPU1
,
1545 TEGRA_POWERGATE_CPU2
,
1546 TEGRA_POWERGATE_CPU3
,
1549 static const struct tegra_pmc_soc tegra114_pmc_soc
= {
1550 .num_powergates
= ARRAY_SIZE(tegra114_powergates
),
1551 .powergates
= tegra114_powergates
,
1552 .num_cpu_powergates
= ARRAY_SIZE(tegra114_cpu_powergates
),
1553 .cpu_powergates
= tegra114_cpu_powergates
,
1554 .has_tsense_reset
= true,
1555 .has_gpu_clamps
= false,
1558 static const char * const tegra124_powergates
[] = {
1559 [TEGRA_POWERGATE_CPU
] = "crail",
1560 [TEGRA_POWERGATE_3D
] = "3d",
1561 [TEGRA_POWERGATE_VENC
] = "venc",
1562 [TEGRA_POWERGATE_PCIE
] = "pcie",
1563 [TEGRA_POWERGATE_VDEC
] = "vdec",
1564 [TEGRA_POWERGATE_MPE
] = "mpe",
1565 [TEGRA_POWERGATE_HEG
] = "heg",
1566 [TEGRA_POWERGATE_SATA
] = "sata",
1567 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1568 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1569 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1570 [TEGRA_POWERGATE_CELP
] = "celp",
1571 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1572 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1573 [TEGRA_POWERGATE_C1NC
] = "c1nc",
1574 [TEGRA_POWERGATE_SOR
] = "sor",
1575 [TEGRA_POWERGATE_DIS
] = "dis",
1576 [TEGRA_POWERGATE_DISB
] = "disb",
1577 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1578 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1579 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1580 [TEGRA_POWERGATE_VIC
] = "vic",
1581 [TEGRA_POWERGATE_IRAM
] = "iram",
1584 static const u8 tegra124_cpu_powergates
[] = {
1585 TEGRA_POWERGATE_CPU0
,
1586 TEGRA_POWERGATE_CPU1
,
1587 TEGRA_POWERGATE_CPU2
,
1588 TEGRA_POWERGATE_CPU3
,
1591 static const struct tegra_io_pad_soc tegra124_io_pads
[] = {
1592 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= UINT_MAX
},
1593 { .id
= TEGRA_IO_PAD_BB
, .dpd
= 15, .voltage
= UINT_MAX
},
1594 { .id
= TEGRA_IO_PAD_CAM
, .dpd
= 36, .voltage
= UINT_MAX
},
1595 { .id
= TEGRA_IO_PAD_COMP
, .dpd
= 22, .voltage
= UINT_MAX
},
1596 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
1597 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
1598 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 44, .voltage
= UINT_MAX
},
1599 { .id
= TEGRA_IO_PAD_DSI
, .dpd
= 2, .voltage
= UINT_MAX
},
1600 { .id
= TEGRA_IO_PAD_DSIB
, .dpd
= 39, .voltage
= UINT_MAX
},
1601 { .id
= TEGRA_IO_PAD_DSIC
, .dpd
= 40, .voltage
= UINT_MAX
},
1602 { .id
= TEGRA_IO_PAD_DSID
, .dpd
= 41, .voltage
= UINT_MAX
},
1603 { .id
= TEGRA_IO_PAD_HDMI
, .dpd
= 28, .voltage
= UINT_MAX
},
1604 { .id
= TEGRA_IO_PAD_HSIC
, .dpd
= 19, .voltage
= UINT_MAX
},
1605 { .id
= TEGRA_IO_PAD_HV
, .dpd
= 38, .voltage
= UINT_MAX
},
1606 { .id
= TEGRA_IO_PAD_LVDS
, .dpd
= 57, .voltage
= UINT_MAX
},
1607 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
1608 { .id
= TEGRA_IO_PAD_NAND
, .dpd
= 13, .voltage
= UINT_MAX
},
1609 { .id
= TEGRA_IO_PAD_PEX_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
1610 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 5, .voltage
= UINT_MAX
},
1611 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
1612 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= 32, .voltage
= UINT_MAX
},
1613 { .id
= TEGRA_IO_PAD_SDMMC1
, .dpd
= 33, .voltage
= UINT_MAX
},
1614 { .id
= TEGRA_IO_PAD_SDMMC3
, .dpd
= 34, .voltage
= UINT_MAX
},
1615 { .id
= TEGRA_IO_PAD_SDMMC4
, .dpd
= 35, .voltage
= UINT_MAX
},
1616 { .id
= TEGRA_IO_PAD_SYS_DDC
, .dpd
= 58, .voltage
= UINT_MAX
},
1617 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= UINT_MAX
},
1618 { .id
= TEGRA_IO_PAD_USB0
, .dpd
= 9, .voltage
= UINT_MAX
},
1619 { .id
= TEGRA_IO_PAD_USB1
, .dpd
= 10, .voltage
= UINT_MAX
},
1620 { .id
= TEGRA_IO_PAD_USB2
, .dpd
= 11, .voltage
= UINT_MAX
},
1621 { .id
= TEGRA_IO_PAD_USB_BIAS
, .dpd
= 12, .voltage
= UINT_MAX
},
1624 static const struct tegra_pmc_soc tegra124_pmc_soc
= {
1625 .num_powergates
= ARRAY_SIZE(tegra124_powergates
),
1626 .powergates
= tegra124_powergates
,
1627 .num_cpu_powergates
= ARRAY_SIZE(tegra124_cpu_powergates
),
1628 .cpu_powergates
= tegra124_cpu_powergates
,
1629 .has_tsense_reset
= true,
1630 .has_gpu_clamps
= true,
1631 .num_io_pads
= ARRAY_SIZE(tegra124_io_pads
),
1632 .io_pads
= tegra124_io_pads
,
1635 static const char * const tegra210_powergates
[] = {
1636 [TEGRA_POWERGATE_CPU
] = "crail",
1637 [TEGRA_POWERGATE_3D
] = "3d",
1638 [TEGRA_POWERGATE_VENC
] = "venc",
1639 [TEGRA_POWERGATE_PCIE
] = "pcie",
1640 [TEGRA_POWERGATE_MPE
] = "mpe",
1641 [TEGRA_POWERGATE_SATA
] = "sata",
1642 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1643 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1644 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1645 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1646 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1647 [TEGRA_POWERGATE_SOR
] = "sor",
1648 [TEGRA_POWERGATE_DIS
] = "dis",
1649 [TEGRA_POWERGATE_DISB
] = "disb",
1650 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1651 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1652 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1653 [TEGRA_POWERGATE_VIC
] = "vic",
1654 [TEGRA_POWERGATE_IRAM
] = "iram",
1655 [TEGRA_POWERGATE_NVDEC
] = "nvdec",
1656 [TEGRA_POWERGATE_NVJPG
] = "nvjpg",
1657 [TEGRA_POWERGATE_AUD
] = "aud",
1658 [TEGRA_POWERGATE_DFD
] = "dfd",
1659 [TEGRA_POWERGATE_VE2
] = "ve2",
1662 static const u8 tegra210_cpu_powergates
[] = {
1663 TEGRA_POWERGATE_CPU0
,
1664 TEGRA_POWERGATE_CPU1
,
1665 TEGRA_POWERGATE_CPU2
,
1666 TEGRA_POWERGATE_CPU3
,
1669 static const struct tegra_io_pad_soc tegra210_io_pads
[] = {
1670 { .id
= TEGRA_IO_PAD_AUDIO
, .dpd
= 17, .voltage
= 5 },
1671 { .id
= TEGRA_IO_PAD_AUDIO_HV
, .dpd
= 61, .voltage
= 18 },
1672 { .id
= TEGRA_IO_PAD_CAM
, .dpd
= 36, .voltage
= 10 },
1673 { .id
= TEGRA_IO_PAD_CSIA
, .dpd
= 0, .voltage
= UINT_MAX
},
1674 { .id
= TEGRA_IO_PAD_CSIB
, .dpd
= 1, .voltage
= UINT_MAX
},
1675 { .id
= TEGRA_IO_PAD_CSIC
, .dpd
= 42, .voltage
= UINT_MAX
},
1676 { .id
= TEGRA_IO_PAD_CSID
, .dpd
= 43, .voltage
= UINT_MAX
},
1677 { .id
= TEGRA_IO_PAD_CSIE
, .dpd
= 44, .voltage
= UINT_MAX
},
1678 { .id
= TEGRA_IO_PAD_CSIF
, .dpd
= 45, .voltage
= UINT_MAX
},
1679 { .id
= TEGRA_IO_PAD_DBG
, .dpd
= 25, .voltage
= 19 },
1680 { .id
= TEGRA_IO_PAD_DEBUG_NONAO
, .dpd
= 26, .voltage
= UINT_MAX
},
1681 { .id
= TEGRA_IO_PAD_DMIC
, .dpd
= 50, .voltage
= 20 },
1682 { .id
= TEGRA_IO_PAD_DP
, .dpd
= 51, .voltage
= UINT_MAX
},
1683 { .id
= TEGRA_IO_PAD_DSI
, .dpd
= 2, .voltage
= UINT_MAX
},
1684 { .id
= TEGRA_IO_PAD_DSIB
, .dpd
= 39, .voltage
= UINT_MAX
},
1685 { .id
= TEGRA_IO_PAD_DSIC
, .dpd
= 40, .voltage
= UINT_MAX
},
1686 { .id
= TEGRA_IO_PAD_DSID
, .dpd
= 41, .voltage
= UINT_MAX
},
1687 { .id
= TEGRA_IO_PAD_EMMC
, .dpd
= 35, .voltage
= UINT_MAX
},
1688 { .id
= TEGRA_IO_PAD_EMMC2
, .dpd
= 37, .voltage
= UINT_MAX
},
1689 { .id
= TEGRA_IO_PAD_GPIO
, .dpd
= 27, .voltage
= 21 },
1690 { .id
= TEGRA_IO_PAD_HDMI
, .dpd
= 28, .voltage
= UINT_MAX
},
1691 { .id
= TEGRA_IO_PAD_HSIC
, .dpd
= 19, .voltage
= UINT_MAX
},
1692 { .id
= TEGRA_IO_PAD_LVDS
, .dpd
= 57, .voltage
= UINT_MAX
},
1693 { .id
= TEGRA_IO_PAD_MIPI_BIAS
, .dpd
= 3, .voltage
= UINT_MAX
},
1694 { .id
= TEGRA_IO_PAD_PEX_BIAS
, .dpd
= 4, .voltage
= UINT_MAX
},
1695 { .id
= TEGRA_IO_PAD_PEX_CLK1
, .dpd
= 5, .voltage
= UINT_MAX
},
1696 { .id
= TEGRA_IO_PAD_PEX_CLK2
, .dpd
= 6, .voltage
= UINT_MAX
},
1697 { .id
= TEGRA_IO_PAD_PEX_CNTRL
, .dpd
= UINT_MAX
, .voltage
= 11 },
1698 { .id
= TEGRA_IO_PAD_SDMMC1
, .dpd
= 33, .voltage
= 12 },
1699 { .id
= TEGRA_IO_PAD_SDMMC3
, .dpd
= 34, .voltage
= 13 },
1700 { .id
= TEGRA_IO_PAD_SPI
, .dpd
= 46, .voltage
= 22 },
1701 { .id
= TEGRA_IO_PAD_SPI_HV
, .dpd
= 47, .voltage
= 23 },
1702 { .id
= TEGRA_IO_PAD_UART
, .dpd
= 14, .voltage
= 2 },
1703 { .id
= TEGRA_IO_PAD_USB0
, .dpd
= 9, .voltage
= UINT_MAX
},
1704 { .id
= TEGRA_IO_PAD_USB1
, .dpd
= 10, .voltage
= UINT_MAX
},
1705 { .id
= TEGRA_IO_PAD_USB2
, .dpd
= 11, .voltage
= UINT_MAX
},
1706 { .id
= TEGRA_IO_PAD_USB3
, .dpd
= 18, .voltage
= UINT_MAX
},
1707 { .id
= TEGRA_IO_PAD_USB_BIAS
, .dpd
= 12, .voltage
= UINT_MAX
},
1710 static const struct tegra_pmc_soc tegra210_pmc_soc
= {
1711 .num_powergates
= ARRAY_SIZE(tegra210_powergates
),
1712 .powergates
= tegra210_powergates
,
1713 .num_cpu_powergates
= ARRAY_SIZE(tegra210_cpu_powergates
),
1714 .cpu_powergates
= tegra210_cpu_powergates
,
1715 .has_tsense_reset
= true,
1716 .has_gpu_clamps
= true,
1717 .num_io_pads
= ARRAY_SIZE(tegra210_io_pads
),
1718 .io_pads
= tegra210_io_pads
,
1721 static const struct of_device_id tegra_pmc_match
[] = {
1722 { .compatible
= "nvidia,tegra210-pmc", .data
= &tegra210_pmc_soc
},
1723 { .compatible
= "nvidia,tegra132-pmc", .data
= &tegra124_pmc_soc
},
1724 { .compatible
= "nvidia,tegra124-pmc", .data
= &tegra124_pmc_soc
},
1725 { .compatible
= "nvidia,tegra114-pmc", .data
= &tegra114_pmc_soc
},
1726 { .compatible
= "nvidia,tegra30-pmc", .data
= &tegra30_pmc_soc
},
1727 { .compatible
= "nvidia,tegra20-pmc", .data
= &tegra20_pmc_soc
},
1731 static struct platform_driver tegra_pmc_driver
= {
1733 .name
= "tegra-pmc",
1734 .suppress_bind_attrs
= true,
1735 .of_match_table
= tegra_pmc_match
,
1736 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1737 .pm
= &tegra_pmc_pm_ops
,
1740 .probe
= tegra_pmc_probe
,
1742 builtin_platform_driver(tegra_pmc_driver
);
1745 * Early initialization to allow access to registers in the very early boot
1748 static int __init
tegra_pmc_early_init(void)
1750 const struct of_device_id
*match
;
1751 struct device_node
*np
;
1752 struct resource regs
;
1756 mutex_init(&pmc
->powergates_lock
);
1758 np
= of_find_matching_node_and_match(NULL
, tegra_pmc_match
, &match
);
1761 * Fall back to legacy initialization for 32-bit ARM only. All
1762 * 64-bit ARM device tree files for Tegra are required to have
1765 * This is for backwards-compatibility with old device trees
1766 * that didn't contain a PMC node. Note that in this case the
1767 * SoC data can't be matched and therefore powergating is
1770 if (IS_ENABLED(CONFIG_ARM
) && soc_is_tegra()) {
1771 pr_warn("DT node not found, powergating disabled\n");
1773 regs
.start
= 0x7000e400;
1774 regs
.end
= 0x7000e7ff;
1775 regs
.flags
= IORESOURCE_MEM
;
1777 pr_warn("Using memory region %pR\n", ®s
);
1780 * At this point we're not running on Tegra, so play
1781 * nice with multi-platform kernels.
1787 * Extract information from the device tree if we've found a
1790 if (of_address_to_resource(np
, 0, ®s
) < 0) {
1791 pr_err("failed to get PMC registers\n");
1797 pmc
->base
= ioremap_nocache(regs
.start
, resource_size(®s
));
1799 pr_err("failed to map PMC registers\n");
1805 pmc
->soc
= match
->data
;
1807 tegra_powergate_init(pmc
, np
);
1810 * Invert the interrupt polarity if a PMC device tree node
1811 * exists and contains the nvidia,invert-interrupt property.
1813 invert
= of_property_read_bool(np
, "nvidia,invert-interrupt");
1815 value
= tegra_pmc_readl(PMC_CNTRL
);
1818 value
|= PMC_CNTRL_INTR_POLARITY
;
1820 value
&= ~PMC_CNTRL_INTR_POLARITY
;
1822 tegra_pmc_writel(value
, PMC_CNTRL
);
1829 early_initcall(tegra_pmc_early_init
);