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/platform_device.h>
35 #include <linux/reboot.h>
36 #include <linux/reset.h>
37 #include <linux/seq_file.h>
38 #include <linux/spinlock.h>
40 #include <soc/tegra/common.h>
41 #include <soc/tegra/fuse.h>
42 #include <soc/tegra/pmc.h>
45 #define PMC_CNTRL_SYSCLK_POLARITY (1 << 10) /* sys clk polarity */
46 #define PMC_CNTRL_SYSCLK_OE (1 << 11) /* system clock enable */
47 #define PMC_CNTRL_SIDE_EFFECT_LP0 (1 << 14) /* LP0 when CPU pwr gated */
48 #define PMC_CNTRL_CPU_PWRREQ_POLARITY (1 << 15) /* CPU pwr req polarity */
49 #define PMC_CNTRL_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */
50 #define PMC_CNTRL_INTR_POLARITY (1 << 17) /* inverts INTR polarity */
52 #define DPD_SAMPLE 0x020
53 #define DPD_SAMPLE_ENABLE (1 << 0)
54 #define DPD_SAMPLE_DISABLE (0 << 0)
56 #define PWRGATE_TOGGLE 0x30
57 #define PWRGATE_TOGGLE_START (1 << 8)
59 #define REMOVE_CLAMPING 0x34
61 #define PWRGATE_STATUS 0x38
63 #define PMC_SCRATCH0 0x50
64 #define PMC_SCRATCH0_MODE_RECOVERY (1 << 31)
65 #define PMC_SCRATCH0_MODE_BOOTLOADER (1 << 30)
66 #define PMC_SCRATCH0_MODE_RCM (1 << 1)
67 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
68 PMC_SCRATCH0_MODE_BOOTLOADER | \
69 PMC_SCRATCH0_MODE_RCM)
71 #define PMC_CPUPWRGOOD_TIMER 0xc8
72 #define PMC_CPUPWROFF_TIMER 0xcc
74 #define PMC_SCRATCH41 0x140
76 #define PMC_SENSOR_CTRL 0x1b0
77 #define PMC_SENSOR_CTRL_SCRATCH_WRITE (1 << 2)
78 #define PMC_SENSOR_CTRL_ENABLE_RST (1 << 1)
80 #define IO_DPD_REQ 0x1b8
81 #define IO_DPD_REQ_CODE_IDLE (0 << 30)
82 #define IO_DPD_REQ_CODE_OFF (1 << 30)
83 #define IO_DPD_REQ_CODE_ON (2 << 30)
84 #define IO_DPD_REQ_CODE_MASK (3 << 30)
86 #define IO_DPD_STATUS 0x1bc
87 #define IO_DPD2_REQ 0x1c0
88 #define IO_DPD2_STATUS 0x1c4
89 #define SEL_DPD_TIM 0x1c8
91 #define PMC_SCRATCH54 0x258
92 #define PMC_SCRATCH54_DATA_SHIFT 8
93 #define PMC_SCRATCH54_ADDR_SHIFT 0
95 #define PMC_SCRATCH55 0x25c
96 #define PMC_SCRATCH55_RESET_TEGRA (1 << 31)
97 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
98 #define PMC_SCRATCH55_PINMUX_SHIFT 24
99 #define PMC_SCRATCH55_16BITOP (1 << 15)
100 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
101 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
103 #define GPU_RG_CNTRL 0x2d4
105 struct tegra_pmc_soc {
106 unsigned int num_powergates;
107 const char *const *powergates;
108 unsigned int num_cpu_powergates;
109 const u8 *cpu_powergates;
111 bool has_tsense_reset;
116 * struct tegra_pmc - NVIDIA Tegra PMC
117 * @dev: pointer to PMC device structure
118 * @base: pointer to I/O remapped register region
119 * @clk: pointer to pclk clock
120 * @soc: pointer to SoC data structure
121 * @debugfs: pointer to debugfs entry
122 * @rate: currently configured rate of pclk
123 * @suspend_mode: lowest suspend mode available
124 * @cpu_good_time: CPU power good time (in microseconds)
125 * @cpu_off_time: CPU power off time (in microsecends)
126 * @core_osc_time: core power good OSC time (in microseconds)
127 * @core_pmu_time: core power good PMU time (in microseconds)
128 * @core_off_time: core power off time (in microseconds)
129 * @corereq_high: core power request is active-high
130 * @sysclkreq_high: system clock request is active-high
131 * @combined_req: combined power request for CPU & core
132 * @cpu_pwr_good_en: CPU power good signal is enabled
133 * @lp0_vec_phys: physical base address of the LP0 warm boot code
134 * @lp0_vec_size: size of the LP0 warm boot code
135 * @powergates_lock: mutex for power gate register access
141 struct dentry *debugfs;
143 const struct tegra_pmc_soc *soc;
147 enum tegra_suspend_mode suspend_mode;
156 bool cpu_pwr_good_en;
160 struct mutex powergates_lock;
163 static struct tegra_pmc *pmc = &(struct tegra_pmc) {
165 .suspend_mode = TEGRA_SUSPEND_NONE,
168 static u32 tegra_pmc_readl(unsigned long offset)
170 return readl(pmc->base + offset);
173 static void tegra_pmc_writel(u32 value, unsigned long offset)
175 writel(value, pmc->base + offset);
178 static inline bool tegra_powergate_state(int id)
180 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
181 return (tegra_pmc_readl(GPU_RG_CNTRL) & 0x1) == 0;
183 return (tegra_pmc_readl(PWRGATE_STATUS) & BIT(id)) != 0;
186 static inline bool tegra_powergate_is_valid(int id)
188 return (pmc->soc && pmc->soc->powergates[id]);
192 * tegra_powergate_set() - set the state of a partition
194 * @new_state: new state of the partition
196 static int tegra_powergate_set(unsigned int id, bool new_state)
201 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
204 mutex_lock(&pmc->powergates_lock);
206 if (tegra_powergate_state(id) == new_state) {
207 mutex_unlock(&pmc->powergates_lock);
211 tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
213 err = readx_poll_timeout(tegra_powergate_state, id, status,
214 status == new_state, 10, 100000);
216 mutex_unlock(&pmc->powergates_lock);
222 * tegra_powergate_power_on() - power on partition
225 int tegra_powergate_power_on(unsigned int id)
227 if (!tegra_powergate_is_valid(id))
230 return tegra_powergate_set(id, true);
234 * tegra_powergate_power_off() - power off partition
237 int tegra_powergate_power_off(unsigned int id)
239 if (!tegra_powergate_is_valid(id))
242 return tegra_powergate_set(id, false);
244 EXPORT_SYMBOL(tegra_powergate_power_off);
247 * tegra_powergate_is_powered() - check if partition is powered
250 int tegra_powergate_is_powered(unsigned int id)
254 if (!tegra_powergate_is_valid(id))
257 mutex_lock(&pmc->powergates_lock);
258 status = tegra_powergate_state(id);
259 mutex_unlock(&pmc->powergates_lock);
265 * tegra_powergate_remove_clamping() - remove power clamps for partition
268 int tegra_powergate_remove_clamping(unsigned int id)
272 if (!tegra_powergate_is_valid(id))
275 mutex_lock(&pmc->powergates_lock);
278 * On Tegra124 and later, the clamps for the GPU are controlled by a
279 * separate register (with different semantics).
281 if (id == TEGRA_POWERGATE_3D) {
282 if (pmc->soc->has_gpu_clamps) {
283 tegra_pmc_writel(0, GPU_RG_CNTRL);
289 * Tegra 2 has a bug where PCIE and VDE clamping masks are
290 * swapped relatively to the partition ids
292 if (id == TEGRA_POWERGATE_VDEC)
293 mask = (1 << TEGRA_POWERGATE_PCIE);
294 else if (id == TEGRA_POWERGATE_PCIE)
295 mask = (1 << TEGRA_POWERGATE_VDEC);
299 tegra_pmc_writel(mask, REMOVE_CLAMPING);
302 mutex_unlock(&pmc->powergates_lock);
306 EXPORT_SYMBOL(tegra_powergate_remove_clamping);
309 * tegra_powergate_sequence_power_up() - power up partition
311 * @clk: clock for partition
312 * @rst: reset for partition
314 * Must be called with clk disabled, and returns with clk enabled.
316 int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
317 struct reset_control *rst)
321 reset_control_assert(rst);
323 ret = tegra_powergate_power_on(id);
327 ret = clk_prepare_enable(clk);
331 usleep_range(10, 20);
333 ret = tegra_powergate_remove_clamping(id);
337 usleep_range(10, 20);
338 reset_control_deassert(rst);
343 clk_disable_unprepare(clk);
345 tegra_powergate_power_off(id);
349 EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
353 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
354 * @cpuid: CPU partition ID
356 * Returns the partition ID corresponding to the CPU partition ID or a
357 * negative error code on failure.
359 static int tegra_get_cpu_powergate_id(unsigned int cpuid)
361 if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates)
362 return pmc->soc->cpu_powergates[cpuid];
368 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
369 * @cpuid: CPU partition ID
371 bool tegra_pmc_cpu_is_powered(unsigned int cpuid)
375 id = tegra_get_cpu_powergate_id(cpuid);
379 return tegra_powergate_is_powered(id);
383 * tegra_pmc_cpu_power_on() - power on CPU partition
384 * @cpuid: CPU partition ID
386 int tegra_pmc_cpu_power_on(unsigned int cpuid)
390 id = tegra_get_cpu_powergate_id(cpuid);
394 return tegra_powergate_set(id, true);
398 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
399 * @cpuid: CPU partition ID
401 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)
405 id = tegra_get_cpu_powergate_id(cpuid);
409 return tegra_powergate_remove_clamping(id);
411 #endif /* CONFIG_SMP */
413 static int tegra_pmc_restart_notify(struct notifier_block *this,
414 unsigned long action, void *data)
416 const char *cmd = data;
419 value = tegra_pmc_readl(PMC_SCRATCH0);
420 value &= ~PMC_SCRATCH0_MODE_MASK;
423 if (strcmp(cmd, "recovery") == 0)
424 value |= PMC_SCRATCH0_MODE_RECOVERY;
426 if (strcmp(cmd, "bootloader") == 0)
427 value |= PMC_SCRATCH0_MODE_BOOTLOADER;
429 if (strcmp(cmd, "forced-recovery") == 0)
430 value |= PMC_SCRATCH0_MODE_RCM;
433 tegra_pmc_writel(value, PMC_SCRATCH0);
435 value = tegra_pmc_readl(0);
437 tegra_pmc_writel(value, 0);
442 static struct notifier_block tegra_pmc_restart_handler = {
443 .notifier_call = tegra_pmc_restart_notify,
447 static int powergate_show(struct seq_file *s, void *data)
452 seq_printf(s, " powergate powered\n");
453 seq_printf(s, "------------------\n");
455 for (i = 0; i < pmc->soc->num_powergates; i++) {
456 status = tegra_powergate_is_powered(i);
460 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
461 status ? "yes" : "no");
467 static int powergate_open(struct inode *inode, struct file *file)
469 return single_open(file, powergate_show, inode->i_private);
472 static const struct file_operations powergate_fops = {
473 .open = powergate_open,
476 .release = single_release,
479 static int tegra_powergate_debugfs_init(void)
481 pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
489 static int tegra_io_rail_prepare(unsigned int id, unsigned long *request,
490 unsigned long *status, unsigned int *bit)
492 unsigned long rate, value;
497 * There are two sets of 30 bits to select IO rails, but bits 30 and
498 * 31 are control bits rather than IO rail selection bits.
500 if (id > 63 || *bit == 30 || *bit == 31)
504 *status = IO_DPD_STATUS;
505 *request = IO_DPD_REQ;
507 *status = IO_DPD2_STATUS;
508 *request = IO_DPD2_REQ;
511 rate = clk_get_rate(pmc->clk);
513 tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
515 /* must be at least 200 ns, in APB (PCLK) clock cycles */
516 value = DIV_ROUND_UP(1000000000, rate);
517 value = DIV_ROUND_UP(200, value);
518 tegra_pmc_writel(value, SEL_DPD_TIM);
523 static int tegra_io_rail_poll(unsigned long offset, unsigned long mask,
524 unsigned long val, unsigned long timeout)
528 timeout = jiffies + msecs_to_jiffies(timeout);
530 while (time_after(timeout, jiffies)) {
531 value = tegra_pmc_readl(offset);
532 if ((value & mask) == val)
535 usleep_range(250, 1000);
541 static void tegra_io_rail_unprepare(void)
543 tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
546 int tegra_io_rail_power_on(unsigned int id)
548 unsigned long request, status, value;
549 unsigned int bit, mask;
552 mutex_lock(&pmc->powergates_lock);
554 err = tegra_io_rail_prepare(id, &request, &status, &bit);
560 value = tegra_pmc_readl(request);
562 value &= ~IO_DPD_REQ_CODE_MASK;
563 value |= IO_DPD_REQ_CODE_OFF;
564 tegra_pmc_writel(value, request);
566 err = tegra_io_rail_poll(status, mask, 0, 250);
568 pr_info("tegra_io_rail_poll() failed: %d\n", err);
572 tegra_io_rail_unprepare();
575 mutex_unlock(&pmc->powergates_lock);
579 EXPORT_SYMBOL(tegra_io_rail_power_on);
581 int tegra_io_rail_power_off(unsigned int id)
583 unsigned long request, status, value;
584 unsigned int bit, mask;
587 mutex_lock(&pmc->powergates_lock);
589 err = tegra_io_rail_prepare(id, &request, &status, &bit);
591 pr_info("tegra_io_rail_prepare() failed: %d\n", err);
597 value = tegra_pmc_readl(request);
599 value &= ~IO_DPD_REQ_CODE_MASK;
600 value |= IO_DPD_REQ_CODE_ON;
601 tegra_pmc_writel(value, request);
603 err = tegra_io_rail_poll(status, mask, mask, 250);
607 tegra_io_rail_unprepare();
610 mutex_unlock(&pmc->powergates_lock);
614 EXPORT_SYMBOL(tegra_io_rail_power_off);
616 #ifdef CONFIG_PM_SLEEP
617 enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
619 return pmc->suspend_mode;
622 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
624 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
627 pmc->suspend_mode = mode;
630 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
632 unsigned long long rate = 0;
636 case TEGRA_SUSPEND_LP1:
640 case TEGRA_SUSPEND_LP2:
641 rate = clk_get_rate(pmc->clk);
648 if (WARN_ON_ONCE(rate == 0))
651 if (rate != pmc->rate) {
654 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
655 do_div(ticks, USEC_PER_SEC);
656 tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
658 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
659 do_div(ticks, USEC_PER_SEC);
660 tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
667 value = tegra_pmc_readl(PMC_CNTRL);
668 value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
669 value |= PMC_CNTRL_CPU_PWRREQ_OE;
670 tegra_pmc_writel(value, PMC_CNTRL);
674 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
676 u32 value, values[2];
678 if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
682 pmc->suspend_mode = TEGRA_SUSPEND_LP0;
686 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
690 pmc->suspend_mode = TEGRA_SUSPEND_LP2;
694 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
699 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
701 if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
702 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
704 pmc->cpu_good_time = value;
706 if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
707 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
709 pmc->cpu_off_time = value;
711 if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
712 values, ARRAY_SIZE(values)))
713 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
715 pmc->core_osc_time = values[0];
716 pmc->core_pmu_time = values[1];
718 if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
719 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
721 pmc->core_off_time = value;
723 pmc->corereq_high = of_property_read_bool(np,
724 "nvidia,core-power-req-active-high");
726 pmc->sysclkreq_high = of_property_read_bool(np,
727 "nvidia,sys-clock-req-active-high");
729 pmc->combined_req = of_property_read_bool(np,
730 "nvidia,combined-power-req");
732 pmc->cpu_pwr_good_en = of_property_read_bool(np,
733 "nvidia,cpu-pwr-good-en");
735 if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
737 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
738 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
740 pmc->lp0_vec_phys = values[0];
741 pmc->lp0_vec_size = values[1];
746 static void tegra_pmc_init(struct tegra_pmc *pmc)
750 /* Always enable CPU power request */
751 value = tegra_pmc_readl(PMC_CNTRL);
752 value |= PMC_CNTRL_CPU_PWRREQ_OE;
753 tegra_pmc_writel(value, PMC_CNTRL);
755 value = tegra_pmc_readl(PMC_CNTRL);
757 if (pmc->sysclkreq_high)
758 value &= ~PMC_CNTRL_SYSCLK_POLARITY;
760 value |= PMC_CNTRL_SYSCLK_POLARITY;
762 /* configure the output polarity while the request is tristated */
763 tegra_pmc_writel(value, PMC_CNTRL);
765 /* now enable the request */
766 value = tegra_pmc_readl(PMC_CNTRL);
767 value |= PMC_CNTRL_SYSCLK_OE;
768 tegra_pmc_writel(value, PMC_CNTRL);
771 static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
773 static const char disabled[] = "emergency thermal reset disabled";
774 u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
775 struct device *dev = pmc->dev;
776 struct device_node *np;
779 if (!pmc->soc->has_tsense_reset)
782 np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip");
784 dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
788 if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
789 dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
793 if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
794 dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
798 if (of_property_read_u32(np, "nvidia,reg-addr", ®_addr)) {
799 dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
803 if (of_property_read_u32(np, "nvidia,reg-data", ®_data)) {
804 dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
808 if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
811 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
812 value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
813 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
815 value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
816 (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
817 tegra_pmc_writel(value, PMC_SCRATCH54);
819 value = PMC_SCRATCH55_RESET_TEGRA;
820 value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
821 value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
822 value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
825 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
826 * contain the checksum and are currently zero, so they are not added.
828 checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
829 + ((value >> 24) & 0xff);
831 checksum = 0x100 - checksum;
833 value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
835 tegra_pmc_writel(value, PMC_SCRATCH55);
837 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
838 value |= PMC_SENSOR_CTRL_ENABLE_RST;
839 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
841 dev_info(pmc->dev, "emergency thermal reset enabled\n");
847 static int tegra_pmc_probe(struct platform_device *pdev)
850 struct resource *res;
853 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
857 /* take over the memory region from the early initialization */
858 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
859 base = devm_ioremap_resource(&pdev->dev, res);
861 return PTR_ERR(base);
863 pmc->clk = devm_clk_get(&pdev->dev, "pclk");
864 if (IS_ERR(pmc->clk)) {
865 err = PTR_ERR(pmc->clk);
866 dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
870 pmc->dev = &pdev->dev;
874 tegra_pmc_init_tsense_reset(pmc);
876 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
877 err = tegra_powergate_debugfs_init();
882 err = register_restart_handler(&tegra_pmc_restart_handler);
884 debugfs_remove(pmc->debugfs);
885 dev_err(&pdev->dev, "unable to register restart handler, %d\n",
890 mutex_lock(&pmc->powergates_lock);
893 mutex_unlock(&pmc->powergates_lock);
898 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
899 static int tegra_pmc_suspend(struct device *dev)
901 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
906 static int tegra_pmc_resume(struct device *dev)
908 tegra_pmc_writel(0x0, PMC_SCRATCH41);
913 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
917 static const char * const tegra20_powergates[] = {
918 [TEGRA_POWERGATE_CPU] = "cpu",
919 [TEGRA_POWERGATE_3D] = "3d",
920 [TEGRA_POWERGATE_VENC] = "venc",
921 [TEGRA_POWERGATE_VDEC] = "vdec",
922 [TEGRA_POWERGATE_PCIE] = "pcie",
923 [TEGRA_POWERGATE_L2] = "l2",
924 [TEGRA_POWERGATE_MPE] = "mpe",
927 static const struct tegra_pmc_soc tegra20_pmc_soc = {
928 .num_powergates = ARRAY_SIZE(tegra20_powergates),
929 .powergates = tegra20_powergates,
930 .num_cpu_powergates = 0,
931 .cpu_powergates = NULL,
932 .has_tsense_reset = false,
933 .has_gpu_clamps = false,
936 static const char * const tegra30_powergates[] = {
937 [TEGRA_POWERGATE_CPU] = "cpu0",
938 [TEGRA_POWERGATE_3D] = "3d0",
939 [TEGRA_POWERGATE_VENC] = "venc",
940 [TEGRA_POWERGATE_VDEC] = "vdec",
941 [TEGRA_POWERGATE_PCIE] = "pcie",
942 [TEGRA_POWERGATE_L2] = "l2",
943 [TEGRA_POWERGATE_MPE] = "mpe",
944 [TEGRA_POWERGATE_HEG] = "heg",
945 [TEGRA_POWERGATE_SATA] = "sata",
946 [TEGRA_POWERGATE_CPU1] = "cpu1",
947 [TEGRA_POWERGATE_CPU2] = "cpu2",
948 [TEGRA_POWERGATE_CPU3] = "cpu3",
949 [TEGRA_POWERGATE_CELP] = "celp",
950 [TEGRA_POWERGATE_3D1] = "3d1",
953 static const u8 tegra30_cpu_powergates[] = {
955 TEGRA_POWERGATE_CPU1,
956 TEGRA_POWERGATE_CPU2,
957 TEGRA_POWERGATE_CPU3,
960 static const struct tegra_pmc_soc tegra30_pmc_soc = {
961 .num_powergates = ARRAY_SIZE(tegra30_powergates),
962 .powergates = tegra30_powergates,
963 .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
964 .cpu_powergates = tegra30_cpu_powergates,
965 .has_tsense_reset = true,
966 .has_gpu_clamps = false,
969 static const char * const tegra114_powergates[] = {
970 [TEGRA_POWERGATE_CPU] = "crail",
971 [TEGRA_POWERGATE_3D] = "3d",
972 [TEGRA_POWERGATE_VENC] = "venc",
973 [TEGRA_POWERGATE_VDEC] = "vdec",
974 [TEGRA_POWERGATE_MPE] = "mpe",
975 [TEGRA_POWERGATE_HEG] = "heg",
976 [TEGRA_POWERGATE_CPU1] = "cpu1",
977 [TEGRA_POWERGATE_CPU2] = "cpu2",
978 [TEGRA_POWERGATE_CPU3] = "cpu3",
979 [TEGRA_POWERGATE_CELP] = "celp",
980 [TEGRA_POWERGATE_CPU0] = "cpu0",
981 [TEGRA_POWERGATE_C0NC] = "c0nc",
982 [TEGRA_POWERGATE_C1NC] = "c1nc",
983 [TEGRA_POWERGATE_DIS] = "dis",
984 [TEGRA_POWERGATE_DISB] = "disb",
985 [TEGRA_POWERGATE_XUSBA] = "xusba",
986 [TEGRA_POWERGATE_XUSBB] = "xusbb",
987 [TEGRA_POWERGATE_XUSBC] = "xusbc",
990 static const u8 tegra114_cpu_powergates[] = {
991 TEGRA_POWERGATE_CPU0,
992 TEGRA_POWERGATE_CPU1,
993 TEGRA_POWERGATE_CPU2,
994 TEGRA_POWERGATE_CPU3,
997 static const struct tegra_pmc_soc tegra114_pmc_soc = {
998 .num_powergates = ARRAY_SIZE(tegra114_powergates),
999 .powergates = tegra114_powergates,
1000 .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
1001 .cpu_powergates = tegra114_cpu_powergates,
1002 .has_tsense_reset = true,
1003 .has_gpu_clamps = false,
1006 static const char * const tegra124_powergates[] = {
1007 [TEGRA_POWERGATE_CPU] = "crail",
1008 [TEGRA_POWERGATE_3D] = "3d",
1009 [TEGRA_POWERGATE_VENC] = "venc",
1010 [TEGRA_POWERGATE_PCIE] = "pcie",
1011 [TEGRA_POWERGATE_VDEC] = "vdec",
1012 [TEGRA_POWERGATE_MPE] = "mpe",
1013 [TEGRA_POWERGATE_HEG] = "heg",
1014 [TEGRA_POWERGATE_SATA] = "sata",
1015 [TEGRA_POWERGATE_CPU1] = "cpu1",
1016 [TEGRA_POWERGATE_CPU2] = "cpu2",
1017 [TEGRA_POWERGATE_CPU3] = "cpu3",
1018 [TEGRA_POWERGATE_CELP] = "celp",
1019 [TEGRA_POWERGATE_CPU0] = "cpu0",
1020 [TEGRA_POWERGATE_C0NC] = "c0nc",
1021 [TEGRA_POWERGATE_C1NC] = "c1nc",
1022 [TEGRA_POWERGATE_SOR] = "sor",
1023 [TEGRA_POWERGATE_DIS] = "dis",
1024 [TEGRA_POWERGATE_DISB] = "disb",
1025 [TEGRA_POWERGATE_XUSBA] = "xusba",
1026 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1027 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1028 [TEGRA_POWERGATE_VIC] = "vic",
1029 [TEGRA_POWERGATE_IRAM] = "iram",
1032 static const u8 tegra124_cpu_powergates[] = {
1033 TEGRA_POWERGATE_CPU0,
1034 TEGRA_POWERGATE_CPU1,
1035 TEGRA_POWERGATE_CPU2,
1036 TEGRA_POWERGATE_CPU3,
1039 static const struct tegra_pmc_soc tegra124_pmc_soc = {
1040 .num_powergates = ARRAY_SIZE(tegra124_powergates),
1041 .powergates = tegra124_powergates,
1042 .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
1043 .cpu_powergates = tegra124_cpu_powergates,
1044 .has_tsense_reset = true,
1045 .has_gpu_clamps = true,
1048 static const char * const tegra210_powergates[] = {
1049 [TEGRA_POWERGATE_CPU] = "crail",
1050 [TEGRA_POWERGATE_3D] = "3d",
1051 [TEGRA_POWERGATE_VENC] = "venc",
1052 [TEGRA_POWERGATE_PCIE] = "pcie",
1053 [TEGRA_POWERGATE_MPE] = "mpe",
1054 [TEGRA_POWERGATE_SATA] = "sata",
1055 [TEGRA_POWERGATE_CPU1] = "cpu1",
1056 [TEGRA_POWERGATE_CPU2] = "cpu2",
1057 [TEGRA_POWERGATE_CPU3] = "cpu3",
1058 [TEGRA_POWERGATE_CPU0] = "cpu0",
1059 [TEGRA_POWERGATE_C0NC] = "c0nc",
1060 [TEGRA_POWERGATE_SOR] = "sor",
1061 [TEGRA_POWERGATE_DIS] = "dis",
1062 [TEGRA_POWERGATE_DISB] = "disb",
1063 [TEGRA_POWERGATE_XUSBA] = "xusba",
1064 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1065 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1066 [TEGRA_POWERGATE_VIC] = "vic",
1067 [TEGRA_POWERGATE_IRAM] = "iram",
1068 [TEGRA_POWERGATE_NVDEC] = "nvdec",
1069 [TEGRA_POWERGATE_NVJPG] = "nvjpg",
1070 [TEGRA_POWERGATE_AUD] = "aud",
1071 [TEGRA_POWERGATE_DFD] = "dfd",
1072 [TEGRA_POWERGATE_VE2] = "ve2",
1075 static const u8 tegra210_cpu_powergates[] = {
1076 TEGRA_POWERGATE_CPU0,
1077 TEGRA_POWERGATE_CPU1,
1078 TEGRA_POWERGATE_CPU2,
1079 TEGRA_POWERGATE_CPU3,
1082 static const struct tegra_pmc_soc tegra210_pmc_soc = {
1083 .num_powergates = ARRAY_SIZE(tegra210_powergates),
1084 .powergates = tegra210_powergates,
1085 .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
1086 .cpu_powergates = tegra210_cpu_powergates,
1087 .has_tsense_reset = true,
1088 .has_gpu_clamps = true,
1091 static const struct of_device_id tegra_pmc_match[] = {
1092 { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
1093 { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
1094 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
1095 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
1096 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
1097 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
1101 static struct platform_driver tegra_pmc_driver = {
1103 .name = "tegra-pmc",
1104 .suppress_bind_attrs = true,
1105 .of_match_table = tegra_pmc_match,
1106 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1107 .pm = &tegra_pmc_pm_ops,
1110 .probe = tegra_pmc_probe,
1112 builtin_platform_driver(tegra_pmc_driver);
1115 * Early initialization to allow access to registers in the very early boot
1118 static int __init tegra_pmc_early_init(void)
1120 const struct of_device_id *match;
1121 struct device_node *np;
1122 struct resource regs;
1126 np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
1129 * Fall back to legacy initialization for 32-bit ARM only. All
1130 * 64-bit ARM device tree files for Tegra are required to have
1133 * This is for backwards-compatibility with old device trees
1134 * that didn't contain a PMC node. Note that in this case the
1135 * SoC data can't be matched and therefore powergating is
1138 if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
1139 pr_warn("DT node not found, powergating disabled\n");
1141 regs.start = 0x7000e400;
1142 regs.end = 0x7000e7ff;
1143 regs.flags = IORESOURCE_MEM;
1145 pr_warn("Using memory region %pR\n", ®s);
1148 * At this point we're not running on Tegra, so play
1149 * nice with multi-platform kernels.
1155 * Extract information from the device tree if we've found a
1158 if (of_address_to_resource(np, 0, ®s) < 0) {
1159 pr_err("failed to get PMC registers\n");
1163 pmc->soc = match->data;
1166 pmc->base = ioremap_nocache(regs.start, resource_size(®s));
1168 pr_err("failed to map PMC registers\n");
1172 mutex_init(&pmc->powergates_lock);
1175 * Invert the interrupt polarity if a PMC device tree node exists and
1176 * contains the nvidia,invert-interrupt property.
1178 invert = of_property_read_bool(np, "nvidia,invert-interrupt");
1180 value = tegra_pmc_readl(PMC_CNTRL);
1183 value |= PMC_CNTRL_INTR_POLARITY;
1185 value &= ~PMC_CNTRL_INTR_POLARITY;
1187 tegra_pmc_writel(value, PMC_CNTRL);
1191 early_initcall(tegra_pmc_early_init);