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 #include <linux/kernel.h>
21 #include <linux/clk.h>
22 #include <linux/clk/tegra.h>
23 #include <linux/debugfs.h>
24 #include <linux/delay.h>
25 #include <linux/err.h>
26 #include <linux/export.h>
27 #include <linux/init.h>
30 #include <linux/of_address.h>
31 #include <linux/platform_device.h>
32 #include <linux/reboot.h>
33 #include <linux/reset.h>
34 #include <linux/seq_file.h>
35 #include <linux/spinlock.h>
37 #include <soc/tegra/common.h>
38 #include <soc/tegra/fuse.h>
39 #include <soc/tegra/pmc.h>
42 #define PMC_CNTRL_SYSCLK_POLARITY (1 << 10) /* sys clk polarity */
43 #define PMC_CNTRL_SYSCLK_OE (1 << 11) /* system clock enable */
44 #define PMC_CNTRL_SIDE_EFFECT_LP0 (1 << 14) /* LP0 when CPU pwr gated */
45 #define PMC_CNTRL_CPU_PWRREQ_POLARITY (1 << 15) /* CPU pwr req polarity */
46 #define PMC_CNTRL_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */
47 #define PMC_CNTRL_INTR_POLARITY (1 << 17) /* inverts INTR polarity */
49 #define DPD_SAMPLE 0x020
50 #define DPD_SAMPLE_ENABLE (1 << 0)
51 #define DPD_SAMPLE_DISABLE (0 << 0)
53 #define PWRGATE_TOGGLE 0x30
54 #define PWRGATE_TOGGLE_START (1 << 8)
56 #define REMOVE_CLAMPING 0x34
58 #define PWRGATE_STATUS 0x38
60 #define PMC_SCRATCH0 0x50
61 #define PMC_SCRATCH0_MODE_RECOVERY (1 << 31)
62 #define PMC_SCRATCH0_MODE_BOOTLOADER (1 << 30)
63 #define PMC_SCRATCH0_MODE_RCM (1 << 1)
64 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
65 PMC_SCRATCH0_MODE_BOOTLOADER | \
66 PMC_SCRATCH0_MODE_RCM)
68 #define PMC_CPUPWRGOOD_TIMER 0xc8
69 #define PMC_CPUPWROFF_TIMER 0xcc
71 #define PMC_SCRATCH41 0x140
73 #define IO_DPD_REQ 0x1b8
74 #define IO_DPD_REQ_CODE_IDLE (0 << 30)
75 #define IO_DPD_REQ_CODE_OFF (1 << 30)
76 #define IO_DPD_REQ_CODE_ON (2 << 30)
77 #define IO_DPD_REQ_CODE_MASK (3 << 30)
79 #define IO_DPD_STATUS 0x1bc
80 #define IO_DPD2_REQ 0x1c0
81 #define IO_DPD2_STATUS 0x1c4
82 #define SEL_DPD_TIM 0x1c8
84 #define GPU_RG_CNTRL 0x2d4
86 struct tegra_pmc_soc {
87 unsigned int num_powergates;
88 const char *const *powergates;
89 unsigned int num_cpu_powergates;
90 const u8 *cpu_powergates;
96 * struct tegra_pmc - NVIDIA Tegra PMC
97 * @base: pointer to I/O remapped register region
98 * @clk: pointer to pclk clock
99 * @rate: currently configured rate of pclk
100 * @suspend_mode: lowest suspend mode available
101 * @cpu_good_time: CPU power good time (in microseconds)
102 * @cpu_off_time: CPU power off time (in microsecends)
103 * @core_osc_time: core power good OSC time (in microseconds)
104 * @core_pmu_time: core power good PMU time (in microseconds)
105 * @core_off_time: core power off time (in microseconds)
106 * @corereq_high: core power request is active-high
107 * @sysclkreq_high: system clock request is active-high
108 * @combined_req: combined power request for CPU & core
109 * @cpu_pwr_good_en: CPU power good signal is enabled
110 * @lp0_vec_phys: physical base address of the LP0 warm boot code
111 * @lp0_vec_size: size of the LP0 warm boot code
112 * @powergates_lock: mutex for power gate register access
118 const struct tegra_pmc_soc *soc;
122 enum tegra_suspend_mode suspend_mode;
131 bool cpu_pwr_good_en;
135 struct mutex powergates_lock;
138 static struct tegra_pmc *pmc = &(struct tegra_pmc) {
140 .suspend_mode = TEGRA_SUSPEND_NONE,
143 static u32 tegra_pmc_readl(unsigned long offset)
145 return readl(pmc->base + offset);
148 static void tegra_pmc_writel(u32 value, unsigned long offset)
150 writel(value, pmc->base + offset);
154 * tegra_powergate_set() - set the state of a partition
156 * @new_state: new state of the partition
158 static int tegra_powergate_set(int id, bool new_state)
162 mutex_lock(&pmc->powergates_lock);
164 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
166 if (status == new_state) {
167 mutex_unlock(&pmc->powergates_lock);
171 tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
173 mutex_unlock(&pmc->powergates_lock);
179 * tegra_powergate_power_on() - power on partition
182 int tegra_powergate_power_on(int id)
184 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
187 return tegra_powergate_set(id, true);
191 * tegra_powergate_power_off() - power off partition
194 int tegra_powergate_power_off(int id)
196 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
199 return tegra_powergate_set(id, false);
201 EXPORT_SYMBOL(tegra_powergate_power_off);
204 * tegra_powergate_is_powered() - check if partition is powered
207 int tegra_powergate_is_powered(int id)
211 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
214 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
219 * tegra_powergate_remove_clamping() - remove power clamps for partition
222 int tegra_powergate_remove_clamping(int id)
226 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
230 * On Tegra124 and later, the clamps for the GPU are controlled by a
231 * separate register (with different semantics).
233 if (id == TEGRA_POWERGATE_3D) {
234 if (pmc->soc->has_gpu_clamps) {
235 tegra_pmc_writel(0, GPU_RG_CNTRL);
241 * Tegra 2 has a bug where PCIE and VDE clamping masks are
242 * swapped relatively to the partition ids
244 if (id == TEGRA_POWERGATE_VDEC)
245 mask = (1 << TEGRA_POWERGATE_PCIE);
246 else if (id == TEGRA_POWERGATE_PCIE)
247 mask = (1 << TEGRA_POWERGATE_VDEC);
251 tegra_pmc_writel(mask, REMOVE_CLAMPING);
255 EXPORT_SYMBOL(tegra_powergate_remove_clamping);
258 * tegra_powergate_sequence_power_up() - power up partition
260 * @clk: clock for partition
261 * @rst: reset for partition
263 * Must be called with clk disabled, and returns with clk enabled.
265 int tegra_powergate_sequence_power_up(int id, struct clk *clk,
266 struct reset_control *rst)
270 reset_control_assert(rst);
272 ret = tegra_powergate_power_on(id);
276 ret = clk_prepare_enable(clk);
280 usleep_range(10, 20);
282 ret = tegra_powergate_remove_clamping(id);
286 usleep_range(10, 20);
287 reset_control_deassert(rst);
292 clk_disable_unprepare(clk);
294 tegra_powergate_power_off(id);
298 EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
302 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
303 * @cpuid: CPU partition ID
305 * Returns the partition ID corresponding to the CPU partition ID or a
306 * negative error code on failure.
308 static int tegra_get_cpu_powergate_id(int cpuid)
310 if (pmc->soc && cpuid > 0 && cpuid < pmc->soc->num_cpu_powergates)
311 return pmc->soc->cpu_powergates[cpuid];
317 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
318 * @cpuid: CPU partition ID
320 bool tegra_pmc_cpu_is_powered(int cpuid)
324 id = tegra_get_cpu_powergate_id(cpuid);
328 return tegra_powergate_is_powered(id);
332 * tegra_pmc_cpu_power_on() - power on CPU partition
333 * @cpuid: CPU partition ID
335 int tegra_pmc_cpu_power_on(int cpuid)
339 id = tegra_get_cpu_powergate_id(cpuid);
343 return tegra_powergate_set(id, true);
347 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
348 * @cpuid: CPU partition ID
350 int tegra_pmc_cpu_remove_clamping(int cpuid)
354 id = tegra_get_cpu_powergate_id(cpuid);
358 return tegra_powergate_remove_clamping(id);
360 #endif /* CONFIG_SMP */
363 * tegra_pmc_restart() - reboot the system
364 * @mode: which mode to reboot in
365 * @cmd: reboot command
367 void tegra_pmc_restart(enum reboot_mode mode, const char *cmd)
371 value = tegra_pmc_readl(PMC_SCRATCH0);
372 value &= ~PMC_SCRATCH0_MODE_MASK;
375 if (strcmp(cmd, "recovery") == 0)
376 value |= PMC_SCRATCH0_MODE_RECOVERY;
378 if (strcmp(cmd, "bootloader") == 0)
379 value |= PMC_SCRATCH0_MODE_BOOTLOADER;
381 if (strcmp(cmd, "forced-recovery") == 0)
382 value |= PMC_SCRATCH0_MODE_RCM;
385 tegra_pmc_writel(value, PMC_SCRATCH0);
387 value = tegra_pmc_readl(0);
389 tegra_pmc_writel(value, 0);
392 static int powergate_show(struct seq_file *s, void *data)
396 seq_printf(s, " powergate powered\n");
397 seq_printf(s, "------------------\n");
399 for (i = 0; i < pmc->soc->num_powergates; i++) {
400 if (!pmc->soc->powergates[i])
403 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
404 tegra_powergate_is_powered(i) ? "yes" : "no");
410 static int powergate_open(struct inode *inode, struct file *file)
412 return single_open(file, powergate_show, inode->i_private);
415 static const struct file_operations powergate_fops = {
416 .open = powergate_open,
419 .release = single_release,
422 static int tegra_powergate_debugfs_init(void)
426 d = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
434 static int tegra_io_rail_prepare(int id, unsigned long *request,
435 unsigned long *status, unsigned int *bit)
437 unsigned long rate, value;
443 * There are two sets of 30 bits to select IO rails, but bits 30 and
444 * 31 are control bits rather than IO rail selection bits.
446 if (id > 63 || *bit == 30 || *bit == 31)
450 *status = IO_DPD_STATUS;
451 *request = IO_DPD_REQ;
453 *status = IO_DPD2_STATUS;
454 *request = IO_DPD2_REQ;
457 clk = clk_get_sys(NULL, "pclk");
461 rate = clk_get_rate(clk);
464 tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
466 /* must be at least 200 ns, in APB (PCLK) clock cycles */
467 value = DIV_ROUND_UP(1000000000, rate);
468 value = DIV_ROUND_UP(200, value);
469 tegra_pmc_writel(value, SEL_DPD_TIM);
474 static int tegra_io_rail_poll(unsigned long offset, unsigned long mask,
475 unsigned long val, unsigned long timeout)
479 timeout = jiffies + msecs_to_jiffies(timeout);
481 while (time_after(timeout, jiffies)) {
482 value = tegra_pmc_readl(offset);
483 if ((value & mask) == val)
486 usleep_range(250, 1000);
492 static void tegra_io_rail_unprepare(void)
494 tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
497 int tegra_io_rail_power_on(int id)
499 unsigned long request, status, value;
500 unsigned int bit, mask;
503 err = tegra_io_rail_prepare(id, &request, &status, &bit);
509 value = tegra_pmc_readl(request);
511 value &= ~IO_DPD_REQ_CODE_MASK;
512 value |= IO_DPD_REQ_CODE_OFF;
513 tegra_pmc_writel(value, request);
515 err = tegra_io_rail_poll(status, mask, 0, 250);
519 tegra_io_rail_unprepare();
523 EXPORT_SYMBOL(tegra_io_rail_power_on);
525 int tegra_io_rail_power_off(int id)
527 unsigned long request, status, value;
528 unsigned int bit, mask;
531 err = tegra_io_rail_prepare(id, &request, &status, &bit);
537 value = tegra_pmc_readl(request);
539 value &= ~IO_DPD_REQ_CODE_MASK;
540 value |= IO_DPD_REQ_CODE_ON;
541 tegra_pmc_writel(value, request);
543 err = tegra_io_rail_poll(status, mask, mask, 250);
547 tegra_io_rail_unprepare();
551 EXPORT_SYMBOL(tegra_io_rail_power_off);
553 #ifdef CONFIG_PM_SLEEP
554 enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
556 return pmc->suspend_mode;
559 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
561 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
564 pmc->suspend_mode = mode;
567 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
569 unsigned long long rate = 0;
573 case TEGRA_SUSPEND_LP1:
577 case TEGRA_SUSPEND_LP2:
578 rate = clk_get_rate(pmc->clk);
585 if (WARN_ON_ONCE(rate == 0))
588 if (rate != pmc->rate) {
591 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
592 do_div(ticks, USEC_PER_SEC);
593 tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
595 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
596 do_div(ticks, USEC_PER_SEC);
597 tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
604 value = tegra_pmc_readl(PMC_CNTRL);
605 value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
606 value |= PMC_CNTRL_CPU_PWRREQ_OE;
607 tegra_pmc_writel(value, PMC_CNTRL);
611 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
613 u32 value, values[2];
615 if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
619 pmc->suspend_mode = TEGRA_SUSPEND_LP0;
623 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
627 pmc->suspend_mode = TEGRA_SUSPEND_LP2;
631 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
636 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
638 if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
639 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
641 pmc->cpu_good_time = value;
643 if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
644 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
646 pmc->cpu_off_time = value;
648 if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
649 values, ARRAY_SIZE(values)))
650 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
652 pmc->core_osc_time = values[0];
653 pmc->core_pmu_time = values[1];
655 if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
656 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
658 pmc->core_off_time = value;
660 pmc->corereq_high = of_property_read_bool(np,
661 "nvidia,core-power-req-active-high");
663 pmc->sysclkreq_high = of_property_read_bool(np,
664 "nvidia,sys-clock-req-active-high");
666 pmc->combined_req = of_property_read_bool(np,
667 "nvidia,combined-power-req");
669 pmc->cpu_pwr_good_en = of_property_read_bool(np,
670 "nvidia,cpu-pwr-good-en");
672 if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
674 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
675 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
677 pmc->lp0_vec_phys = values[0];
678 pmc->lp0_vec_size = values[1];
683 static void tegra_pmc_init(struct tegra_pmc *pmc)
687 /* Always enable CPU power request */
688 value = tegra_pmc_readl(PMC_CNTRL);
689 value |= PMC_CNTRL_CPU_PWRREQ_OE;
690 tegra_pmc_writel(value, PMC_CNTRL);
692 value = tegra_pmc_readl(PMC_CNTRL);
694 if (pmc->sysclkreq_high)
695 value &= ~PMC_CNTRL_SYSCLK_POLARITY;
697 value |= PMC_CNTRL_SYSCLK_POLARITY;
699 /* configure the output polarity while the request is tristated */
700 tegra_pmc_writel(value, PMC_CNTRL);
702 /* now enable the request */
703 value = tegra_pmc_readl(PMC_CNTRL);
704 value |= PMC_CNTRL_SYSCLK_OE;
705 tegra_pmc_writel(value, PMC_CNTRL);
708 static int tegra_pmc_probe(struct platform_device *pdev)
710 void __iomem *base = pmc->base;
711 struct resource *res;
714 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
718 /* take over the memory region from the early initialization */
719 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
720 pmc->base = devm_ioremap_resource(&pdev->dev, res);
721 if (IS_ERR(pmc->base))
722 return PTR_ERR(pmc->base);
726 pmc->clk = devm_clk_get(&pdev->dev, "pclk");
727 if (IS_ERR(pmc->clk)) {
728 err = PTR_ERR(pmc->clk);
729 dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
735 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
736 err = tegra_powergate_debugfs_init();
744 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
745 static int tegra_pmc_suspend(struct device *dev)
747 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
752 static int tegra_pmc_resume(struct device *dev)
754 tegra_pmc_writel(0x0, PMC_SCRATCH41);
759 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
763 static const char * const tegra20_powergates[] = {
764 [TEGRA_POWERGATE_CPU] = "cpu",
765 [TEGRA_POWERGATE_3D] = "3d",
766 [TEGRA_POWERGATE_VENC] = "venc",
767 [TEGRA_POWERGATE_VDEC] = "vdec",
768 [TEGRA_POWERGATE_PCIE] = "pcie",
769 [TEGRA_POWERGATE_L2] = "l2",
770 [TEGRA_POWERGATE_MPE] = "mpe",
773 static const struct tegra_pmc_soc tegra20_pmc_soc = {
774 .num_powergates = ARRAY_SIZE(tegra20_powergates),
775 .powergates = tegra20_powergates,
776 .num_cpu_powergates = 0,
777 .cpu_powergates = NULL,
778 .has_gpu_clamps = false,
781 static const char * const tegra30_powergates[] = {
782 [TEGRA_POWERGATE_CPU] = "cpu0",
783 [TEGRA_POWERGATE_3D] = "3d0",
784 [TEGRA_POWERGATE_VENC] = "venc",
785 [TEGRA_POWERGATE_VDEC] = "vdec",
786 [TEGRA_POWERGATE_PCIE] = "pcie",
787 [TEGRA_POWERGATE_L2] = "l2",
788 [TEGRA_POWERGATE_MPE] = "mpe",
789 [TEGRA_POWERGATE_HEG] = "heg",
790 [TEGRA_POWERGATE_SATA] = "sata",
791 [TEGRA_POWERGATE_CPU1] = "cpu1",
792 [TEGRA_POWERGATE_CPU2] = "cpu2",
793 [TEGRA_POWERGATE_CPU3] = "cpu3",
794 [TEGRA_POWERGATE_CELP] = "celp",
795 [TEGRA_POWERGATE_3D1] = "3d1",
798 static const u8 tegra30_cpu_powergates[] = {
800 TEGRA_POWERGATE_CPU1,
801 TEGRA_POWERGATE_CPU2,
802 TEGRA_POWERGATE_CPU3,
805 static const struct tegra_pmc_soc tegra30_pmc_soc = {
806 .num_powergates = ARRAY_SIZE(tegra30_powergates),
807 .powergates = tegra30_powergates,
808 .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
809 .cpu_powergates = tegra30_cpu_powergates,
810 .has_gpu_clamps = false,
813 static const char * const tegra114_powergates[] = {
814 [TEGRA_POWERGATE_CPU] = "crail",
815 [TEGRA_POWERGATE_3D] = "3d",
816 [TEGRA_POWERGATE_VENC] = "venc",
817 [TEGRA_POWERGATE_VDEC] = "vdec",
818 [TEGRA_POWERGATE_MPE] = "mpe",
819 [TEGRA_POWERGATE_HEG] = "heg",
820 [TEGRA_POWERGATE_CPU1] = "cpu1",
821 [TEGRA_POWERGATE_CPU2] = "cpu2",
822 [TEGRA_POWERGATE_CPU3] = "cpu3",
823 [TEGRA_POWERGATE_CELP] = "celp",
824 [TEGRA_POWERGATE_CPU0] = "cpu0",
825 [TEGRA_POWERGATE_C0NC] = "c0nc",
826 [TEGRA_POWERGATE_C1NC] = "c1nc",
827 [TEGRA_POWERGATE_DIS] = "dis",
828 [TEGRA_POWERGATE_DISB] = "disb",
829 [TEGRA_POWERGATE_XUSBA] = "xusba",
830 [TEGRA_POWERGATE_XUSBB] = "xusbb",
831 [TEGRA_POWERGATE_XUSBC] = "xusbc",
834 static const u8 tegra114_cpu_powergates[] = {
835 TEGRA_POWERGATE_CPU0,
836 TEGRA_POWERGATE_CPU1,
837 TEGRA_POWERGATE_CPU2,
838 TEGRA_POWERGATE_CPU3,
841 static const struct tegra_pmc_soc tegra114_pmc_soc = {
842 .num_powergates = ARRAY_SIZE(tegra114_powergates),
843 .powergates = tegra114_powergates,
844 .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
845 .cpu_powergates = tegra114_cpu_powergates,
846 .has_gpu_clamps = false,
849 static const char * const tegra124_powergates[] = {
850 [TEGRA_POWERGATE_CPU] = "crail",
851 [TEGRA_POWERGATE_3D] = "3d",
852 [TEGRA_POWERGATE_VENC] = "venc",
853 [TEGRA_POWERGATE_PCIE] = "pcie",
854 [TEGRA_POWERGATE_VDEC] = "vdec",
855 [TEGRA_POWERGATE_L2] = "l2",
856 [TEGRA_POWERGATE_MPE] = "mpe",
857 [TEGRA_POWERGATE_HEG] = "heg",
858 [TEGRA_POWERGATE_SATA] = "sata",
859 [TEGRA_POWERGATE_CPU1] = "cpu1",
860 [TEGRA_POWERGATE_CPU2] = "cpu2",
861 [TEGRA_POWERGATE_CPU3] = "cpu3",
862 [TEGRA_POWERGATE_CELP] = "celp",
863 [TEGRA_POWERGATE_CPU0] = "cpu0",
864 [TEGRA_POWERGATE_C0NC] = "c0nc",
865 [TEGRA_POWERGATE_C1NC] = "c1nc",
866 [TEGRA_POWERGATE_SOR] = "sor",
867 [TEGRA_POWERGATE_DIS] = "dis",
868 [TEGRA_POWERGATE_DISB] = "disb",
869 [TEGRA_POWERGATE_XUSBA] = "xusba",
870 [TEGRA_POWERGATE_XUSBB] = "xusbb",
871 [TEGRA_POWERGATE_XUSBC] = "xusbc",
872 [TEGRA_POWERGATE_VIC] = "vic",
873 [TEGRA_POWERGATE_IRAM] = "iram",
876 static const u8 tegra124_cpu_powergates[] = {
877 TEGRA_POWERGATE_CPU0,
878 TEGRA_POWERGATE_CPU1,
879 TEGRA_POWERGATE_CPU2,
880 TEGRA_POWERGATE_CPU3,
883 static const struct tegra_pmc_soc tegra124_pmc_soc = {
884 .num_powergates = ARRAY_SIZE(tegra124_powergates),
885 .powergates = tegra124_powergates,
886 .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
887 .cpu_powergates = tegra124_cpu_powergates,
888 .has_gpu_clamps = true,
891 static const struct of_device_id tegra_pmc_match[] = {
892 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
893 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
894 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
895 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
899 static struct platform_driver tegra_pmc_driver = {
902 .suppress_bind_attrs = true,
903 .of_match_table = tegra_pmc_match,
904 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
905 .pm = &tegra_pmc_pm_ops,
908 .probe = tegra_pmc_probe,
910 module_platform_driver(tegra_pmc_driver);
913 * Early initialization to allow access to registers in the very early boot
916 static int __init tegra_pmc_early_init(void)
918 const struct of_device_id *match;
919 struct device_node *np;
920 struct resource regs;
927 np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
929 pr_warn("PMC device node not found, disabling powergating\n");
931 regs.start = 0x7000e400;
932 regs.end = 0x7000e7ff;
933 regs.flags = IORESOURCE_MEM;
935 pr_warn("Using memory region %pR\n", ®s);
937 pmc->soc = match->data;
940 if (of_address_to_resource(np, 0, ®s) < 0) {
941 pr_err("failed to get PMC registers\n");
945 pmc->base = ioremap_nocache(regs.start, resource_size(®s));
947 pr_err("failed to map PMC registers\n");
951 mutex_init(&pmc->powergates_lock);
953 invert = of_property_read_bool(np, "nvidia,invert-interrupt");
955 value = tegra_pmc_readl(PMC_CNTRL);
958 value |= PMC_CNTRL_INTR_POLARITY;
960 value &= ~PMC_CNTRL_INTR_POLARITY;
962 tegra_pmc_writel(value, PMC_CNTRL);
966 early_initcall(tegra_pmc_early_init);