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 PMC_SENSOR_CTRL 0x1b0
74 #define PMC_SENSOR_CTRL_SCRATCH_WRITE (1 << 2)
75 #define PMC_SENSOR_CTRL_ENABLE_RST (1 << 1)
77 #define IO_DPD_REQ 0x1b8
78 #define IO_DPD_REQ_CODE_IDLE (0 << 30)
79 #define IO_DPD_REQ_CODE_OFF (1 << 30)
80 #define IO_DPD_REQ_CODE_ON (2 << 30)
81 #define IO_DPD_REQ_CODE_MASK (3 << 30)
83 #define IO_DPD_STATUS 0x1bc
84 #define IO_DPD2_REQ 0x1c0
85 #define IO_DPD2_STATUS 0x1c4
86 #define SEL_DPD_TIM 0x1c8
88 #define PMC_SCRATCH54 0x258
89 #define PMC_SCRATCH54_DATA_SHIFT 8
90 #define PMC_SCRATCH54_ADDR_SHIFT 0
92 #define PMC_SCRATCH55 0x25c
93 #define PMC_SCRATCH55_RESET_TEGRA (1 << 31)
94 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
95 #define PMC_SCRATCH55_PINMUX_SHIFT 24
96 #define PMC_SCRATCH55_16BITOP (1 << 15)
97 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
98 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
100 #define GPU_RG_CNTRL 0x2d4
102 struct tegra_pmc_soc {
103 unsigned int num_powergates;
104 const char *const *powergates;
105 unsigned int num_cpu_powergates;
106 const u8 *cpu_powergates;
108 bool has_tsense_reset;
113 * struct tegra_pmc - NVIDIA Tegra PMC
114 * @base: pointer to I/O remapped register region
115 * @clk: pointer to pclk clock
116 * @rate: currently configured rate of pclk
117 * @suspend_mode: lowest suspend mode available
118 * @cpu_good_time: CPU power good time (in microseconds)
119 * @cpu_off_time: CPU power off time (in microsecends)
120 * @core_osc_time: core power good OSC time (in microseconds)
121 * @core_pmu_time: core power good PMU time (in microseconds)
122 * @core_off_time: core power off time (in microseconds)
123 * @corereq_high: core power request is active-high
124 * @sysclkreq_high: system clock request is active-high
125 * @combined_req: combined power request for CPU & core
126 * @cpu_pwr_good_en: CPU power good signal is enabled
127 * @lp0_vec_phys: physical base address of the LP0 warm boot code
128 * @lp0_vec_size: size of the LP0 warm boot code
129 * @powergates_lock: mutex for power gate register access
136 const struct tegra_pmc_soc *soc;
140 enum tegra_suspend_mode suspend_mode;
149 bool cpu_pwr_good_en;
153 struct mutex powergates_lock;
156 static struct tegra_pmc *pmc = &(struct tegra_pmc) {
158 .suspend_mode = TEGRA_SUSPEND_NONE,
161 static u32 tegra_pmc_readl(unsigned long offset)
163 return readl(pmc->base + offset);
166 static void tegra_pmc_writel(u32 value, unsigned long offset)
168 writel(value, pmc->base + offset);
172 * tegra_powergate_set() - set the state of a partition
174 * @new_state: new state of the partition
176 static int tegra_powergate_set(int id, bool new_state)
180 mutex_lock(&pmc->powergates_lock);
182 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
184 if (status == new_state) {
185 mutex_unlock(&pmc->powergates_lock);
189 tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
191 mutex_unlock(&pmc->powergates_lock);
197 * tegra_powergate_power_on() - power on partition
200 int tegra_powergate_power_on(int id)
202 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
205 return tegra_powergate_set(id, true);
209 * tegra_powergate_power_off() - power off partition
212 int tegra_powergate_power_off(int id)
214 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
217 return tegra_powergate_set(id, false);
219 EXPORT_SYMBOL(tegra_powergate_power_off);
222 * tegra_powergate_is_powered() - check if partition is powered
225 int tegra_powergate_is_powered(int id)
229 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
232 status = tegra_pmc_readl(PWRGATE_STATUS) & (1 << id);
237 * tegra_powergate_remove_clamping() - remove power clamps for partition
240 int tegra_powergate_remove_clamping(int id)
244 if (!pmc->soc || id < 0 || id >= pmc->soc->num_powergates)
248 * On Tegra124 and later, the clamps for the GPU are controlled by a
249 * separate register (with different semantics).
251 if (id == TEGRA_POWERGATE_3D) {
252 if (pmc->soc->has_gpu_clamps) {
253 tegra_pmc_writel(0, GPU_RG_CNTRL);
259 * Tegra 2 has a bug where PCIE and VDE clamping masks are
260 * swapped relatively to the partition ids
262 if (id == TEGRA_POWERGATE_VDEC)
263 mask = (1 << TEGRA_POWERGATE_PCIE);
264 else if (id == TEGRA_POWERGATE_PCIE)
265 mask = (1 << TEGRA_POWERGATE_VDEC);
269 tegra_pmc_writel(mask, REMOVE_CLAMPING);
273 EXPORT_SYMBOL(tegra_powergate_remove_clamping);
276 * tegra_powergate_sequence_power_up() - power up partition
278 * @clk: clock for partition
279 * @rst: reset for partition
281 * Must be called with clk disabled, and returns with clk enabled.
283 int tegra_powergate_sequence_power_up(int id, struct clk *clk,
284 struct reset_control *rst)
288 reset_control_assert(rst);
290 ret = tegra_powergate_power_on(id);
294 ret = clk_prepare_enable(clk);
298 usleep_range(10, 20);
300 ret = tegra_powergate_remove_clamping(id);
304 usleep_range(10, 20);
305 reset_control_deassert(rst);
310 clk_disable_unprepare(clk);
312 tegra_powergate_power_off(id);
316 EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
320 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
321 * @cpuid: CPU partition ID
323 * Returns the partition ID corresponding to the CPU partition ID or a
324 * negative error code on failure.
326 static int tegra_get_cpu_powergate_id(int cpuid)
328 if (pmc->soc && cpuid > 0 && cpuid < pmc->soc->num_cpu_powergates)
329 return pmc->soc->cpu_powergates[cpuid];
335 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
336 * @cpuid: CPU partition ID
338 bool tegra_pmc_cpu_is_powered(int cpuid)
342 id = tegra_get_cpu_powergate_id(cpuid);
346 return tegra_powergate_is_powered(id);
350 * tegra_pmc_cpu_power_on() - power on CPU partition
351 * @cpuid: CPU partition ID
353 int tegra_pmc_cpu_power_on(int cpuid)
357 id = tegra_get_cpu_powergate_id(cpuid);
361 return tegra_powergate_set(id, true);
365 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
366 * @cpuid: CPU partition ID
368 int tegra_pmc_cpu_remove_clamping(int cpuid)
372 id = tegra_get_cpu_powergate_id(cpuid);
376 return tegra_powergate_remove_clamping(id);
378 #endif /* CONFIG_SMP */
381 * tegra_pmc_restart() - reboot the system
382 * @mode: which mode to reboot in
383 * @cmd: reboot command
385 void tegra_pmc_restart(enum reboot_mode mode, const char *cmd)
389 value = tegra_pmc_readl(PMC_SCRATCH0);
390 value &= ~PMC_SCRATCH0_MODE_MASK;
393 if (strcmp(cmd, "recovery") == 0)
394 value |= PMC_SCRATCH0_MODE_RECOVERY;
396 if (strcmp(cmd, "bootloader") == 0)
397 value |= PMC_SCRATCH0_MODE_BOOTLOADER;
399 if (strcmp(cmd, "forced-recovery") == 0)
400 value |= PMC_SCRATCH0_MODE_RCM;
403 tegra_pmc_writel(value, PMC_SCRATCH0);
405 value = tegra_pmc_readl(0);
407 tegra_pmc_writel(value, 0);
410 static int powergate_show(struct seq_file *s, void *data)
414 seq_printf(s, " powergate powered\n");
415 seq_printf(s, "------------------\n");
417 for (i = 0; i < pmc->soc->num_powergates; i++) {
418 if (!pmc->soc->powergates[i])
421 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
422 tegra_powergate_is_powered(i) ? "yes" : "no");
428 static int powergate_open(struct inode *inode, struct file *file)
430 return single_open(file, powergate_show, inode->i_private);
433 static const struct file_operations powergate_fops = {
434 .open = powergate_open,
437 .release = single_release,
440 static int tegra_powergate_debugfs_init(void)
444 d = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
452 static int tegra_io_rail_prepare(int id, unsigned long *request,
453 unsigned long *status, unsigned int *bit)
455 unsigned long rate, value;
461 * There are two sets of 30 bits to select IO rails, but bits 30 and
462 * 31 are control bits rather than IO rail selection bits.
464 if (id > 63 || *bit == 30 || *bit == 31)
468 *status = IO_DPD_STATUS;
469 *request = IO_DPD_REQ;
471 *status = IO_DPD2_STATUS;
472 *request = IO_DPD2_REQ;
475 clk = clk_get_sys(NULL, "pclk");
479 rate = clk_get_rate(clk);
482 tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
484 /* must be at least 200 ns, in APB (PCLK) clock cycles */
485 value = DIV_ROUND_UP(1000000000, rate);
486 value = DIV_ROUND_UP(200, value);
487 tegra_pmc_writel(value, SEL_DPD_TIM);
492 static int tegra_io_rail_poll(unsigned long offset, unsigned long mask,
493 unsigned long val, unsigned long timeout)
497 timeout = jiffies + msecs_to_jiffies(timeout);
499 while (time_after(timeout, jiffies)) {
500 value = tegra_pmc_readl(offset);
501 if ((value & mask) == val)
504 usleep_range(250, 1000);
510 static void tegra_io_rail_unprepare(void)
512 tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
515 int tegra_io_rail_power_on(int id)
517 unsigned long request, status, value;
518 unsigned int bit, mask;
521 err = tegra_io_rail_prepare(id, &request, &status, &bit);
527 value = tegra_pmc_readl(request);
529 value &= ~IO_DPD_REQ_CODE_MASK;
530 value |= IO_DPD_REQ_CODE_OFF;
531 tegra_pmc_writel(value, request);
533 err = tegra_io_rail_poll(status, mask, 0, 250);
537 tegra_io_rail_unprepare();
541 EXPORT_SYMBOL(tegra_io_rail_power_on);
543 int tegra_io_rail_power_off(int id)
545 unsigned long request, status, value;
546 unsigned int bit, mask;
549 err = tegra_io_rail_prepare(id, &request, &status, &bit);
555 value = tegra_pmc_readl(request);
557 value &= ~IO_DPD_REQ_CODE_MASK;
558 value |= IO_DPD_REQ_CODE_ON;
559 tegra_pmc_writel(value, request);
561 err = tegra_io_rail_poll(status, mask, mask, 250);
565 tegra_io_rail_unprepare();
569 EXPORT_SYMBOL(tegra_io_rail_power_off);
571 #ifdef CONFIG_PM_SLEEP
572 enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
574 return pmc->suspend_mode;
577 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
579 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
582 pmc->suspend_mode = mode;
585 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
587 unsigned long long rate = 0;
591 case TEGRA_SUSPEND_LP1:
595 case TEGRA_SUSPEND_LP2:
596 rate = clk_get_rate(pmc->clk);
603 if (WARN_ON_ONCE(rate == 0))
606 if (rate != pmc->rate) {
609 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
610 do_div(ticks, USEC_PER_SEC);
611 tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
613 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
614 do_div(ticks, USEC_PER_SEC);
615 tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
622 value = tegra_pmc_readl(PMC_CNTRL);
623 value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
624 value |= PMC_CNTRL_CPU_PWRREQ_OE;
625 tegra_pmc_writel(value, PMC_CNTRL);
629 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
631 u32 value, values[2];
633 if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
637 pmc->suspend_mode = TEGRA_SUSPEND_LP0;
641 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
645 pmc->suspend_mode = TEGRA_SUSPEND_LP2;
649 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
654 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
656 if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
657 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
659 pmc->cpu_good_time = value;
661 if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
662 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
664 pmc->cpu_off_time = value;
666 if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
667 values, ARRAY_SIZE(values)))
668 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
670 pmc->core_osc_time = values[0];
671 pmc->core_pmu_time = values[1];
673 if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
674 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
676 pmc->core_off_time = value;
678 pmc->corereq_high = of_property_read_bool(np,
679 "nvidia,core-power-req-active-high");
681 pmc->sysclkreq_high = of_property_read_bool(np,
682 "nvidia,sys-clock-req-active-high");
684 pmc->combined_req = of_property_read_bool(np,
685 "nvidia,combined-power-req");
687 pmc->cpu_pwr_good_en = of_property_read_bool(np,
688 "nvidia,cpu-pwr-good-en");
690 if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
692 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
693 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
695 pmc->lp0_vec_phys = values[0];
696 pmc->lp0_vec_size = values[1];
701 static void tegra_pmc_init(struct tegra_pmc *pmc)
705 /* Always enable CPU power request */
706 value = tegra_pmc_readl(PMC_CNTRL);
707 value |= PMC_CNTRL_CPU_PWRREQ_OE;
708 tegra_pmc_writel(value, PMC_CNTRL);
710 value = tegra_pmc_readl(PMC_CNTRL);
712 if (pmc->sysclkreq_high)
713 value &= ~PMC_CNTRL_SYSCLK_POLARITY;
715 value |= PMC_CNTRL_SYSCLK_POLARITY;
717 /* configure the output polarity while the request is tristated */
718 tegra_pmc_writel(value, PMC_CNTRL);
720 /* now enable the request */
721 value = tegra_pmc_readl(PMC_CNTRL);
722 value |= PMC_CNTRL_SYSCLK_OE;
723 tegra_pmc_writel(value, PMC_CNTRL);
726 void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
728 static const char disabled[] = "emergency thermal reset disabled";
729 u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
730 struct device *dev = pmc->dev;
731 struct device_node *np;
734 if (!pmc->soc->has_tsense_reset)
737 np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip");
739 dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
743 if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
744 dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
748 if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
749 dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
753 if (of_property_read_u32(np, "nvidia,reg-addr", ®_addr)) {
754 dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
758 if (of_property_read_u32(np, "nvidia,reg-data", ®_data)) {
759 dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
763 if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
766 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
767 value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
768 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
770 value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
771 (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
772 tegra_pmc_writel(value, PMC_SCRATCH54);
774 value = PMC_SCRATCH55_RESET_TEGRA;
775 value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
776 value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
777 value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
780 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
781 * contain the checksum and are currently zero, so they are not added.
783 checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
784 + ((value >> 24) & 0xff);
786 checksum = 0x100 - checksum;
788 value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
790 tegra_pmc_writel(value, PMC_SCRATCH55);
792 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
793 value |= PMC_SENSOR_CTRL_ENABLE_RST;
794 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
796 dev_info(pmc->dev, "emergency thermal reset enabled\n");
803 static int tegra_pmc_probe(struct platform_device *pdev)
805 void __iomem *base = pmc->base;
806 struct resource *res;
809 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
813 /* take over the memory region from the early initialization */
814 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
815 pmc->base = devm_ioremap_resource(&pdev->dev, res);
816 if (IS_ERR(pmc->base))
817 return PTR_ERR(pmc->base);
821 pmc->clk = devm_clk_get(&pdev->dev, "pclk");
822 if (IS_ERR(pmc->clk)) {
823 err = PTR_ERR(pmc->clk);
824 dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
828 pmc->dev = &pdev->dev;
832 tegra_pmc_init_tsense_reset(pmc);
834 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
835 err = tegra_powergate_debugfs_init();
843 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
844 static int tegra_pmc_suspend(struct device *dev)
846 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
851 static int tegra_pmc_resume(struct device *dev)
853 tegra_pmc_writel(0x0, PMC_SCRATCH41);
858 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
862 static const char * const tegra20_powergates[] = {
863 [TEGRA_POWERGATE_CPU] = "cpu",
864 [TEGRA_POWERGATE_3D] = "3d",
865 [TEGRA_POWERGATE_VENC] = "venc",
866 [TEGRA_POWERGATE_VDEC] = "vdec",
867 [TEGRA_POWERGATE_PCIE] = "pcie",
868 [TEGRA_POWERGATE_L2] = "l2",
869 [TEGRA_POWERGATE_MPE] = "mpe",
872 static const struct tegra_pmc_soc tegra20_pmc_soc = {
873 .num_powergates = ARRAY_SIZE(tegra20_powergates),
874 .powergates = tegra20_powergates,
875 .num_cpu_powergates = 0,
876 .cpu_powergates = NULL,
877 .has_tsense_reset = false,
878 .has_gpu_clamps = false,
881 static const char * const tegra30_powergates[] = {
882 [TEGRA_POWERGATE_CPU] = "cpu0",
883 [TEGRA_POWERGATE_3D] = "3d0",
884 [TEGRA_POWERGATE_VENC] = "venc",
885 [TEGRA_POWERGATE_VDEC] = "vdec",
886 [TEGRA_POWERGATE_PCIE] = "pcie",
887 [TEGRA_POWERGATE_L2] = "l2",
888 [TEGRA_POWERGATE_MPE] = "mpe",
889 [TEGRA_POWERGATE_HEG] = "heg",
890 [TEGRA_POWERGATE_SATA] = "sata",
891 [TEGRA_POWERGATE_CPU1] = "cpu1",
892 [TEGRA_POWERGATE_CPU2] = "cpu2",
893 [TEGRA_POWERGATE_CPU3] = "cpu3",
894 [TEGRA_POWERGATE_CELP] = "celp",
895 [TEGRA_POWERGATE_3D1] = "3d1",
898 static const u8 tegra30_cpu_powergates[] = {
900 TEGRA_POWERGATE_CPU1,
901 TEGRA_POWERGATE_CPU2,
902 TEGRA_POWERGATE_CPU3,
905 static const struct tegra_pmc_soc tegra30_pmc_soc = {
906 .num_powergates = ARRAY_SIZE(tegra30_powergates),
907 .powergates = tegra30_powergates,
908 .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
909 .cpu_powergates = tegra30_cpu_powergates,
910 .has_tsense_reset = true,
911 .has_gpu_clamps = false,
914 static const char * const tegra114_powergates[] = {
915 [TEGRA_POWERGATE_CPU] = "crail",
916 [TEGRA_POWERGATE_3D] = "3d",
917 [TEGRA_POWERGATE_VENC] = "venc",
918 [TEGRA_POWERGATE_VDEC] = "vdec",
919 [TEGRA_POWERGATE_MPE] = "mpe",
920 [TEGRA_POWERGATE_HEG] = "heg",
921 [TEGRA_POWERGATE_CPU1] = "cpu1",
922 [TEGRA_POWERGATE_CPU2] = "cpu2",
923 [TEGRA_POWERGATE_CPU3] = "cpu3",
924 [TEGRA_POWERGATE_CELP] = "celp",
925 [TEGRA_POWERGATE_CPU0] = "cpu0",
926 [TEGRA_POWERGATE_C0NC] = "c0nc",
927 [TEGRA_POWERGATE_C1NC] = "c1nc",
928 [TEGRA_POWERGATE_DIS] = "dis",
929 [TEGRA_POWERGATE_DISB] = "disb",
930 [TEGRA_POWERGATE_XUSBA] = "xusba",
931 [TEGRA_POWERGATE_XUSBB] = "xusbb",
932 [TEGRA_POWERGATE_XUSBC] = "xusbc",
935 static const u8 tegra114_cpu_powergates[] = {
936 TEGRA_POWERGATE_CPU0,
937 TEGRA_POWERGATE_CPU1,
938 TEGRA_POWERGATE_CPU2,
939 TEGRA_POWERGATE_CPU3,
942 static const struct tegra_pmc_soc tegra114_pmc_soc = {
943 .num_powergates = ARRAY_SIZE(tegra114_powergates),
944 .powergates = tegra114_powergates,
945 .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
946 .cpu_powergates = tegra114_cpu_powergates,
947 .has_tsense_reset = true,
948 .has_gpu_clamps = false,
951 static const char * const tegra124_powergates[] = {
952 [TEGRA_POWERGATE_CPU] = "crail",
953 [TEGRA_POWERGATE_3D] = "3d",
954 [TEGRA_POWERGATE_VENC] = "venc",
955 [TEGRA_POWERGATE_PCIE] = "pcie",
956 [TEGRA_POWERGATE_VDEC] = "vdec",
957 [TEGRA_POWERGATE_L2] = "l2",
958 [TEGRA_POWERGATE_MPE] = "mpe",
959 [TEGRA_POWERGATE_HEG] = "heg",
960 [TEGRA_POWERGATE_SATA] = "sata",
961 [TEGRA_POWERGATE_CPU1] = "cpu1",
962 [TEGRA_POWERGATE_CPU2] = "cpu2",
963 [TEGRA_POWERGATE_CPU3] = "cpu3",
964 [TEGRA_POWERGATE_CELP] = "celp",
965 [TEGRA_POWERGATE_CPU0] = "cpu0",
966 [TEGRA_POWERGATE_C0NC] = "c0nc",
967 [TEGRA_POWERGATE_C1NC] = "c1nc",
968 [TEGRA_POWERGATE_SOR] = "sor",
969 [TEGRA_POWERGATE_DIS] = "dis",
970 [TEGRA_POWERGATE_DISB] = "disb",
971 [TEGRA_POWERGATE_XUSBA] = "xusba",
972 [TEGRA_POWERGATE_XUSBB] = "xusbb",
973 [TEGRA_POWERGATE_XUSBC] = "xusbc",
974 [TEGRA_POWERGATE_VIC] = "vic",
975 [TEGRA_POWERGATE_IRAM] = "iram",
978 static const u8 tegra124_cpu_powergates[] = {
979 TEGRA_POWERGATE_CPU0,
980 TEGRA_POWERGATE_CPU1,
981 TEGRA_POWERGATE_CPU2,
982 TEGRA_POWERGATE_CPU3,
985 static const struct tegra_pmc_soc tegra124_pmc_soc = {
986 .num_powergates = ARRAY_SIZE(tegra124_powergates),
987 .powergates = tegra124_powergates,
988 .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
989 .cpu_powergates = tegra124_cpu_powergates,
990 .has_tsense_reset = true,
991 .has_gpu_clamps = true,
994 static const struct of_device_id tegra_pmc_match[] = {
995 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
996 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
997 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
998 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
1002 static struct platform_driver tegra_pmc_driver = {
1004 .name = "tegra-pmc",
1005 .suppress_bind_attrs = true,
1006 .of_match_table = tegra_pmc_match,
1007 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1008 .pm = &tegra_pmc_pm_ops,
1011 .probe = tegra_pmc_probe,
1013 module_platform_driver(tegra_pmc_driver);
1016 * Early initialization to allow access to registers in the very early boot
1019 static int __init tegra_pmc_early_init(void)
1021 const struct of_device_id *match;
1022 struct device_node *np;
1023 struct resource regs;
1027 if (!soc_is_tegra())
1030 np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
1032 pr_warn("PMC device node not found, disabling powergating\n");
1034 regs.start = 0x7000e400;
1035 regs.end = 0x7000e7ff;
1036 regs.flags = IORESOURCE_MEM;
1038 pr_warn("Using memory region %pR\n", ®s);
1040 pmc->soc = match->data;
1043 if (of_address_to_resource(np, 0, ®s) < 0) {
1044 pr_err("failed to get PMC registers\n");
1048 pmc->base = ioremap_nocache(regs.start, resource_size(®s));
1050 pr_err("failed to map PMC registers\n");
1054 mutex_init(&pmc->powergates_lock);
1056 invert = of_property_read_bool(np, "nvidia,invert-interrupt");
1058 value = tegra_pmc_readl(PMC_CNTRL);
1061 value |= PMC_CNTRL_INTR_POLARITY;
1063 value &= ~PMC_CNTRL_INTR_POLARITY;
1065 tegra_pmc_writel(value, PMC_CNTRL);
1069 early_initcall(tegra_pmc_early_init);