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>
32 #include <linux/of_address.h>
33 #include <linux/platform_device.h>
34 #include <linux/reboot.h>
35 #include <linux/reset.h>
36 #include <linux/seq_file.h>
37 #include <linux/spinlock.h>
39 #include <soc/tegra/common.h>
40 #include <soc/tegra/fuse.h>
41 #include <soc/tegra/pmc.h>
44 #define PMC_CNTRL_SYSCLK_POLARITY (1 << 10) /* sys clk polarity */
45 #define PMC_CNTRL_SYSCLK_OE (1 << 11) /* system clock enable */
46 #define PMC_CNTRL_SIDE_EFFECT_LP0 (1 << 14) /* LP0 when CPU pwr gated */
47 #define PMC_CNTRL_CPU_PWRREQ_POLARITY (1 << 15) /* CPU pwr req polarity */
48 #define PMC_CNTRL_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */
49 #define PMC_CNTRL_INTR_POLARITY (1 << 17) /* inverts INTR polarity */
51 #define DPD_SAMPLE 0x020
52 #define DPD_SAMPLE_ENABLE (1 << 0)
53 #define DPD_SAMPLE_DISABLE (0 << 0)
55 #define PWRGATE_TOGGLE 0x30
56 #define PWRGATE_TOGGLE_START (1 << 8)
58 #define REMOVE_CLAMPING 0x34
60 #define PWRGATE_STATUS 0x38
62 #define PMC_SCRATCH0 0x50
63 #define PMC_SCRATCH0_MODE_RECOVERY (1 << 31)
64 #define PMC_SCRATCH0_MODE_BOOTLOADER (1 << 30)
65 #define PMC_SCRATCH0_MODE_RCM (1 << 1)
66 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
67 PMC_SCRATCH0_MODE_BOOTLOADER | \
68 PMC_SCRATCH0_MODE_RCM)
70 #define PMC_CPUPWRGOOD_TIMER 0xc8
71 #define PMC_CPUPWROFF_TIMER 0xcc
73 #define PMC_SCRATCH41 0x140
75 #define PMC_SENSOR_CTRL 0x1b0
76 #define PMC_SENSOR_CTRL_SCRATCH_WRITE (1 << 2)
77 #define PMC_SENSOR_CTRL_ENABLE_RST (1 << 1)
79 #define IO_DPD_REQ 0x1b8
80 #define IO_DPD_REQ_CODE_IDLE (0 << 30)
81 #define IO_DPD_REQ_CODE_OFF (1 << 30)
82 #define IO_DPD_REQ_CODE_ON (2 << 30)
83 #define IO_DPD_REQ_CODE_MASK (3 << 30)
85 #define IO_DPD_STATUS 0x1bc
86 #define IO_DPD2_REQ 0x1c0
87 #define IO_DPD2_STATUS 0x1c4
88 #define SEL_DPD_TIM 0x1c8
90 #define PMC_SCRATCH54 0x258
91 #define PMC_SCRATCH54_DATA_SHIFT 8
92 #define PMC_SCRATCH54_ADDR_SHIFT 0
94 #define PMC_SCRATCH55 0x25c
95 #define PMC_SCRATCH55_RESET_TEGRA (1 << 31)
96 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
97 #define PMC_SCRATCH55_PINMUX_SHIFT 24
98 #define PMC_SCRATCH55_16BITOP (1 << 15)
99 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
100 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
102 #define GPU_RG_CNTRL 0x2d4
104 struct tegra_pmc_soc
{
105 unsigned int num_powergates
;
106 const char *const *powergates
;
107 unsigned int num_cpu_powergates
;
108 const u8
*cpu_powergates
;
110 bool has_tsense_reset
;
115 * struct tegra_pmc - NVIDIA Tegra PMC
116 * @dev: pointer to PMC device structure
117 * @base: pointer to I/O remapped register region
118 * @clk: pointer to pclk clock
119 * @soc: pointer to SoC data structure
120 * @debugfs: pointer to debugfs entry
121 * @rate: currently configured rate of pclk
122 * @suspend_mode: lowest suspend mode available
123 * @cpu_good_time: CPU power good time (in microseconds)
124 * @cpu_off_time: CPU power off time (in microsecends)
125 * @core_osc_time: core power good OSC time (in microseconds)
126 * @core_pmu_time: core power good PMU time (in microseconds)
127 * @core_off_time: core power off time (in microseconds)
128 * @corereq_high: core power request is active-high
129 * @sysclkreq_high: system clock request is active-high
130 * @combined_req: combined power request for CPU & core
131 * @cpu_pwr_good_en: CPU power good signal is enabled
132 * @lp0_vec_phys: physical base address of the LP0 warm boot code
133 * @lp0_vec_size: size of the LP0 warm boot code
134 * @powergates_lock: mutex for power gate register access
140 struct dentry
*debugfs
;
142 const struct tegra_pmc_soc
*soc
;
146 enum tegra_suspend_mode suspend_mode
;
155 bool cpu_pwr_good_en
;
159 struct mutex powergates_lock
;
162 static struct tegra_pmc
*pmc
= &(struct tegra_pmc
) {
164 .suspend_mode
= TEGRA_SUSPEND_NONE
,
167 static u32
tegra_pmc_readl(unsigned long offset
)
169 return readl(pmc
->base
+ offset
);
172 static void tegra_pmc_writel(u32 value
, unsigned long offset
)
174 writel(value
, pmc
->base
+ offset
);
177 static inline bool tegra_powergate_state(int id
)
179 return (tegra_pmc_readl(PWRGATE_STATUS
) & BIT(id
)) != 0;
182 static inline bool tegra_powergate_is_valid(int id
)
184 return (pmc
->soc
&& pmc
->soc
->powergates
[id
]);
188 * tegra_powergate_set() - set the state of a partition
190 * @new_state: new state of the partition
192 static int tegra_powergate_set(unsigned int id
, bool new_state
)
194 mutex_lock(&pmc
->powergates_lock
);
196 if (tegra_powergate_state(id
) == new_state
) {
197 mutex_unlock(&pmc
->powergates_lock
);
201 tegra_pmc_writel(PWRGATE_TOGGLE_START
| id
, PWRGATE_TOGGLE
);
203 mutex_unlock(&pmc
->powergates_lock
);
209 * tegra_powergate_power_on() - power on partition
212 int tegra_powergate_power_on(unsigned int id
)
214 if (!tegra_powergate_is_valid(id
))
217 return tegra_powergate_set(id
, true);
221 * tegra_powergate_power_off() - power off partition
224 int tegra_powergate_power_off(unsigned int id
)
226 if (!tegra_powergate_is_valid(id
))
229 return tegra_powergate_set(id
, false);
231 EXPORT_SYMBOL(tegra_powergate_power_off
);
234 * tegra_powergate_is_powered() - check if partition is powered
237 int tegra_powergate_is_powered(unsigned int id
)
241 if (!tegra_powergate_is_valid(id
))
244 mutex_lock(&pmc
->powergates_lock
);
245 status
= tegra_powergate_state(id
);
246 mutex_unlock(&pmc
->powergates_lock
);
252 * tegra_powergate_remove_clamping() - remove power clamps for partition
255 int tegra_powergate_remove_clamping(unsigned int id
)
259 if (!tegra_powergate_is_valid(id
))
262 mutex_lock(&pmc
->powergates_lock
);
265 * On Tegra124 and later, the clamps for the GPU are controlled by a
266 * separate register (with different semantics).
268 if (id
== TEGRA_POWERGATE_3D
) {
269 if (pmc
->soc
->has_gpu_clamps
) {
270 tegra_pmc_writel(0, GPU_RG_CNTRL
);
276 * Tegra 2 has a bug where PCIE and VDE clamping masks are
277 * swapped relatively to the partition ids
279 if (id
== TEGRA_POWERGATE_VDEC
)
280 mask
= (1 << TEGRA_POWERGATE_PCIE
);
281 else if (id
== TEGRA_POWERGATE_PCIE
)
282 mask
= (1 << TEGRA_POWERGATE_VDEC
);
286 tegra_pmc_writel(mask
, REMOVE_CLAMPING
);
289 mutex_unlock(&pmc
->powergates_lock
);
293 EXPORT_SYMBOL(tegra_powergate_remove_clamping
);
296 * tegra_powergate_sequence_power_up() - power up partition
298 * @clk: clock for partition
299 * @rst: reset for partition
301 * Must be called with clk disabled, and returns with clk enabled.
303 int tegra_powergate_sequence_power_up(unsigned int id
, struct clk
*clk
,
304 struct reset_control
*rst
)
308 reset_control_assert(rst
);
310 ret
= tegra_powergate_power_on(id
);
314 ret
= clk_prepare_enable(clk
);
318 usleep_range(10, 20);
320 ret
= tegra_powergate_remove_clamping(id
);
324 usleep_range(10, 20);
325 reset_control_deassert(rst
);
330 clk_disable_unprepare(clk
);
332 tegra_powergate_power_off(id
);
336 EXPORT_SYMBOL(tegra_powergate_sequence_power_up
);
340 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
341 * @cpuid: CPU partition ID
343 * Returns the partition ID corresponding to the CPU partition ID or a
344 * negative error code on failure.
346 static int tegra_get_cpu_powergate_id(unsigned int cpuid
)
348 if (pmc
->soc
&& cpuid
< pmc
->soc
->num_cpu_powergates
)
349 return pmc
->soc
->cpu_powergates
[cpuid
];
355 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
356 * @cpuid: CPU partition ID
358 bool tegra_pmc_cpu_is_powered(unsigned int cpuid
)
362 id
= tegra_get_cpu_powergate_id(cpuid
);
366 return tegra_powergate_is_powered(id
);
370 * tegra_pmc_cpu_power_on() - power on CPU partition
371 * @cpuid: CPU partition ID
373 int tegra_pmc_cpu_power_on(unsigned int cpuid
)
377 id
= tegra_get_cpu_powergate_id(cpuid
);
381 return tegra_powergate_set(id
, true);
385 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
386 * @cpuid: CPU partition ID
388 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid
)
392 id
= tegra_get_cpu_powergate_id(cpuid
);
396 return tegra_powergate_remove_clamping(id
);
398 #endif /* CONFIG_SMP */
400 static int tegra_pmc_restart_notify(struct notifier_block
*this,
401 unsigned long action
, void *data
)
403 const char *cmd
= data
;
406 value
= tegra_pmc_readl(PMC_SCRATCH0
);
407 value
&= ~PMC_SCRATCH0_MODE_MASK
;
410 if (strcmp(cmd
, "recovery") == 0)
411 value
|= PMC_SCRATCH0_MODE_RECOVERY
;
413 if (strcmp(cmd
, "bootloader") == 0)
414 value
|= PMC_SCRATCH0_MODE_BOOTLOADER
;
416 if (strcmp(cmd
, "forced-recovery") == 0)
417 value
|= PMC_SCRATCH0_MODE_RCM
;
420 tegra_pmc_writel(value
, PMC_SCRATCH0
);
422 value
= tegra_pmc_readl(0);
424 tegra_pmc_writel(value
, 0);
429 static struct notifier_block tegra_pmc_restart_handler
= {
430 .notifier_call
= tegra_pmc_restart_notify
,
434 static int powergate_show(struct seq_file
*s
, void *data
)
438 seq_printf(s
, " powergate powered\n");
439 seq_printf(s
, "------------------\n");
441 for (i
= 0; i
< pmc
->soc
->num_powergates
; i
++) {
442 if (!pmc
->soc
->powergates
[i
])
445 seq_printf(s
, " %9s %7s\n", pmc
->soc
->powergates
[i
],
446 tegra_powergate_is_powered(i
) ? "yes" : "no");
452 static int powergate_open(struct inode
*inode
, struct file
*file
)
454 return single_open(file
, powergate_show
, inode
->i_private
);
457 static const struct file_operations powergate_fops
= {
458 .open
= powergate_open
,
461 .release
= single_release
,
464 static int tegra_powergate_debugfs_init(void)
466 pmc
->debugfs
= debugfs_create_file("powergate", S_IRUGO
, NULL
, NULL
,
474 static int tegra_io_rail_prepare(unsigned int id
, unsigned long *request
,
475 unsigned long *status
, unsigned int *bit
)
477 unsigned long rate
, value
;
482 * There are two sets of 30 bits to select IO rails, but bits 30 and
483 * 31 are control bits rather than IO rail selection bits.
485 if (id
> 63 || *bit
== 30 || *bit
== 31)
489 *status
= IO_DPD_STATUS
;
490 *request
= IO_DPD_REQ
;
492 *status
= IO_DPD2_STATUS
;
493 *request
= IO_DPD2_REQ
;
496 rate
= clk_get_rate(pmc
->clk
);
498 tegra_pmc_writel(DPD_SAMPLE_ENABLE
, DPD_SAMPLE
);
500 /* must be at least 200 ns, in APB (PCLK) clock cycles */
501 value
= DIV_ROUND_UP(1000000000, rate
);
502 value
= DIV_ROUND_UP(200, value
);
503 tegra_pmc_writel(value
, SEL_DPD_TIM
);
508 static int tegra_io_rail_poll(unsigned long offset
, unsigned long mask
,
509 unsigned long val
, unsigned long timeout
)
513 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
515 while (time_after(timeout
, jiffies
)) {
516 value
= tegra_pmc_readl(offset
);
517 if ((value
& mask
) == val
)
520 usleep_range(250, 1000);
526 static void tegra_io_rail_unprepare(void)
528 tegra_pmc_writel(DPD_SAMPLE_DISABLE
, DPD_SAMPLE
);
531 int tegra_io_rail_power_on(unsigned int id
)
533 unsigned long request
, status
, value
;
534 unsigned int bit
, mask
;
537 mutex_lock(&pmc
->powergates_lock
);
539 err
= tegra_io_rail_prepare(id
, &request
, &status
, &bit
);
545 value
= tegra_pmc_readl(request
);
547 value
&= ~IO_DPD_REQ_CODE_MASK
;
548 value
|= IO_DPD_REQ_CODE_OFF
;
549 tegra_pmc_writel(value
, request
);
551 err
= tegra_io_rail_poll(status
, mask
, 0, 250);
553 pr_info("tegra_io_rail_poll() failed: %d\n", err
);
557 tegra_io_rail_unprepare();
560 mutex_unlock(&pmc
->powergates_lock
);
564 EXPORT_SYMBOL(tegra_io_rail_power_on
);
566 int tegra_io_rail_power_off(unsigned int id
)
568 unsigned long request
, status
, value
;
569 unsigned int bit
, mask
;
572 mutex_lock(&pmc
->powergates_lock
);
574 err
= tegra_io_rail_prepare(id
, &request
, &status
, &bit
);
576 pr_info("tegra_io_rail_prepare() failed: %d\n", err
);
582 value
= tegra_pmc_readl(request
);
584 value
&= ~IO_DPD_REQ_CODE_MASK
;
585 value
|= IO_DPD_REQ_CODE_ON
;
586 tegra_pmc_writel(value
, request
);
588 err
= tegra_io_rail_poll(status
, mask
, mask
, 250);
592 tegra_io_rail_unprepare();
595 mutex_unlock(&pmc
->powergates_lock
);
599 EXPORT_SYMBOL(tegra_io_rail_power_off
);
601 #ifdef CONFIG_PM_SLEEP
602 enum tegra_suspend_mode
tegra_pmc_get_suspend_mode(void)
604 return pmc
->suspend_mode
;
607 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode
)
609 if (mode
< TEGRA_SUSPEND_NONE
|| mode
>= TEGRA_MAX_SUSPEND_MODE
)
612 pmc
->suspend_mode
= mode
;
615 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode
)
617 unsigned long long rate
= 0;
621 case TEGRA_SUSPEND_LP1
:
625 case TEGRA_SUSPEND_LP2
:
626 rate
= clk_get_rate(pmc
->clk
);
633 if (WARN_ON_ONCE(rate
== 0))
636 if (rate
!= pmc
->rate
) {
639 ticks
= pmc
->cpu_good_time
* rate
+ USEC_PER_SEC
- 1;
640 do_div(ticks
, USEC_PER_SEC
);
641 tegra_pmc_writel(ticks
, PMC_CPUPWRGOOD_TIMER
);
643 ticks
= pmc
->cpu_off_time
* rate
+ USEC_PER_SEC
- 1;
644 do_div(ticks
, USEC_PER_SEC
);
645 tegra_pmc_writel(ticks
, PMC_CPUPWROFF_TIMER
);
652 value
= tegra_pmc_readl(PMC_CNTRL
);
653 value
&= ~PMC_CNTRL_SIDE_EFFECT_LP0
;
654 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
655 tegra_pmc_writel(value
, PMC_CNTRL
);
659 static int tegra_pmc_parse_dt(struct tegra_pmc
*pmc
, struct device_node
*np
)
661 u32 value
, values
[2];
663 if (of_property_read_u32(np
, "nvidia,suspend-mode", &value
)) {
667 pmc
->suspend_mode
= TEGRA_SUSPEND_LP0
;
671 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
675 pmc
->suspend_mode
= TEGRA_SUSPEND_LP2
;
679 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
684 pmc
->suspend_mode
= tegra_pm_validate_suspend_mode(pmc
->suspend_mode
);
686 if (of_property_read_u32(np
, "nvidia,cpu-pwr-good-time", &value
))
687 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
689 pmc
->cpu_good_time
= value
;
691 if (of_property_read_u32(np
, "nvidia,cpu-pwr-off-time", &value
))
692 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
694 pmc
->cpu_off_time
= value
;
696 if (of_property_read_u32_array(np
, "nvidia,core-pwr-good-time",
697 values
, ARRAY_SIZE(values
)))
698 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
700 pmc
->core_osc_time
= values
[0];
701 pmc
->core_pmu_time
= values
[1];
703 if (of_property_read_u32(np
, "nvidia,core-pwr-off-time", &value
))
704 pmc
->suspend_mode
= TEGRA_SUSPEND_NONE
;
706 pmc
->core_off_time
= value
;
708 pmc
->corereq_high
= of_property_read_bool(np
,
709 "nvidia,core-power-req-active-high");
711 pmc
->sysclkreq_high
= of_property_read_bool(np
,
712 "nvidia,sys-clock-req-active-high");
714 pmc
->combined_req
= of_property_read_bool(np
,
715 "nvidia,combined-power-req");
717 pmc
->cpu_pwr_good_en
= of_property_read_bool(np
,
718 "nvidia,cpu-pwr-good-en");
720 if (of_property_read_u32_array(np
, "nvidia,lp0-vec", values
,
722 if (pmc
->suspend_mode
== TEGRA_SUSPEND_LP0
)
723 pmc
->suspend_mode
= TEGRA_SUSPEND_LP1
;
725 pmc
->lp0_vec_phys
= values
[0];
726 pmc
->lp0_vec_size
= values
[1];
731 static void tegra_pmc_init(struct tegra_pmc
*pmc
)
735 /* Always enable CPU power request */
736 value
= tegra_pmc_readl(PMC_CNTRL
);
737 value
|= PMC_CNTRL_CPU_PWRREQ_OE
;
738 tegra_pmc_writel(value
, PMC_CNTRL
);
740 value
= tegra_pmc_readl(PMC_CNTRL
);
742 if (pmc
->sysclkreq_high
)
743 value
&= ~PMC_CNTRL_SYSCLK_POLARITY
;
745 value
|= PMC_CNTRL_SYSCLK_POLARITY
;
747 /* configure the output polarity while the request is tristated */
748 tegra_pmc_writel(value
, PMC_CNTRL
);
750 /* now enable the request */
751 value
= tegra_pmc_readl(PMC_CNTRL
);
752 value
|= PMC_CNTRL_SYSCLK_OE
;
753 tegra_pmc_writel(value
, PMC_CNTRL
);
756 static void tegra_pmc_init_tsense_reset(struct tegra_pmc
*pmc
)
758 static const char disabled
[] = "emergency thermal reset disabled";
759 u32 pmu_addr
, ctrl_id
, reg_addr
, reg_data
, pinmux
;
760 struct device
*dev
= pmc
->dev
;
761 struct device_node
*np
;
764 if (!pmc
->soc
->has_tsense_reset
)
767 np
= of_find_node_by_name(pmc
->dev
->of_node
, "i2c-thermtrip");
769 dev_warn(dev
, "i2c-thermtrip node not found, %s.\n", disabled
);
773 if (of_property_read_u32(np
, "nvidia,i2c-controller-id", &ctrl_id
)) {
774 dev_err(dev
, "I2C controller ID missing, %s.\n", disabled
);
778 if (of_property_read_u32(np
, "nvidia,bus-addr", &pmu_addr
)) {
779 dev_err(dev
, "nvidia,bus-addr missing, %s.\n", disabled
);
783 if (of_property_read_u32(np
, "nvidia,reg-addr", ®_addr
)) {
784 dev_err(dev
, "nvidia,reg-addr missing, %s.\n", disabled
);
788 if (of_property_read_u32(np
, "nvidia,reg-data", ®_data
)) {
789 dev_err(dev
, "nvidia,reg-data missing, %s.\n", disabled
);
793 if (of_property_read_u32(np
, "nvidia,pinmux-id", &pinmux
))
796 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
797 value
|= PMC_SENSOR_CTRL_SCRATCH_WRITE
;
798 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
800 value
= (reg_data
<< PMC_SCRATCH54_DATA_SHIFT
) |
801 (reg_addr
<< PMC_SCRATCH54_ADDR_SHIFT
);
802 tegra_pmc_writel(value
, PMC_SCRATCH54
);
804 value
= PMC_SCRATCH55_RESET_TEGRA
;
805 value
|= ctrl_id
<< PMC_SCRATCH55_CNTRL_ID_SHIFT
;
806 value
|= pinmux
<< PMC_SCRATCH55_PINMUX_SHIFT
;
807 value
|= pmu_addr
<< PMC_SCRATCH55_I2CSLV1_SHIFT
;
810 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
811 * contain the checksum and are currently zero, so they are not added.
813 checksum
= reg_addr
+ reg_data
+ (value
& 0xff) + ((value
>> 8) & 0xff)
814 + ((value
>> 24) & 0xff);
816 checksum
= 0x100 - checksum
;
818 value
|= checksum
<< PMC_SCRATCH55_CHECKSUM_SHIFT
;
820 tegra_pmc_writel(value
, PMC_SCRATCH55
);
822 value
= tegra_pmc_readl(PMC_SENSOR_CTRL
);
823 value
|= PMC_SENSOR_CTRL_ENABLE_RST
;
824 tegra_pmc_writel(value
, PMC_SENSOR_CTRL
);
826 dev_info(pmc
->dev
, "emergency thermal reset enabled\n");
832 static int tegra_pmc_probe(struct platform_device
*pdev
)
835 struct resource
*res
;
838 err
= tegra_pmc_parse_dt(pmc
, pdev
->dev
.of_node
);
842 /* take over the memory region from the early initialization */
843 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
844 base
= devm_ioremap_resource(&pdev
->dev
, res
);
846 return PTR_ERR(base
);
848 pmc
->clk
= devm_clk_get(&pdev
->dev
, "pclk");
849 if (IS_ERR(pmc
->clk
)) {
850 err
= PTR_ERR(pmc
->clk
);
851 dev_err(&pdev
->dev
, "failed to get pclk: %d\n", err
);
855 pmc
->dev
= &pdev
->dev
;
859 tegra_pmc_init_tsense_reset(pmc
);
861 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
862 err
= tegra_powergate_debugfs_init();
867 err
= register_restart_handler(&tegra_pmc_restart_handler
);
869 debugfs_remove(pmc
->debugfs
);
870 dev_err(&pdev
->dev
, "unable to register restart handler, %d\n",
875 mutex_lock(&pmc
->powergates_lock
);
878 mutex_unlock(&pmc
->powergates_lock
);
883 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
884 static int tegra_pmc_suspend(struct device
*dev
)
886 tegra_pmc_writel(virt_to_phys(tegra_resume
), PMC_SCRATCH41
);
891 static int tegra_pmc_resume(struct device
*dev
)
893 tegra_pmc_writel(0x0, PMC_SCRATCH41
);
898 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops
, tegra_pmc_suspend
, tegra_pmc_resume
);
902 static const char * const tegra20_powergates
[] = {
903 [TEGRA_POWERGATE_CPU
] = "cpu",
904 [TEGRA_POWERGATE_3D
] = "3d",
905 [TEGRA_POWERGATE_VENC
] = "venc",
906 [TEGRA_POWERGATE_VDEC
] = "vdec",
907 [TEGRA_POWERGATE_PCIE
] = "pcie",
908 [TEGRA_POWERGATE_L2
] = "l2",
909 [TEGRA_POWERGATE_MPE
] = "mpe",
912 static const struct tegra_pmc_soc tegra20_pmc_soc
= {
913 .num_powergates
= ARRAY_SIZE(tegra20_powergates
),
914 .powergates
= tegra20_powergates
,
915 .num_cpu_powergates
= 0,
916 .cpu_powergates
= NULL
,
917 .has_tsense_reset
= false,
918 .has_gpu_clamps
= false,
921 static const char * const tegra30_powergates
[] = {
922 [TEGRA_POWERGATE_CPU
] = "cpu0",
923 [TEGRA_POWERGATE_3D
] = "3d0",
924 [TEGRA_POWERGATE_VENC
] = "venc",
925 [TEGRA_POWERGATE_VDEC
] = "vdec",
926 [TEGRA_POWERGATE_PCIE
] = "pcie",
927 [TEGRA_POWERGATE_L2
] = "l2",
928 [TEGRA_POWERGATE_MPE
] = "mpe",
929 [TEGRA_POWERGATE_HEG
] = "heg",
930 [TEGRA_POWERGATE_SATA
] = "sata",
931 [TEGRA_POWERGATE_CPU1
] = "cpu1",
932 [TEGRA_POWERGATE_CPU2
] = "cpu2",
933 [TEGRA_POWERGATE_CPU3
] = "cpu3",
934 [TEGRA_POWERGATE_CELP
] = "celp",
935 [TEGRA_POWERGATE_3D1
] = "3d1",
938 static const u8 tegra30_cpu_powergates
[] = {
940 TEGRA_POWERGATE_CPU1
,
941 TEGRA_POWERGATE_CPU2
,
942 TEGRA_POWERGATE_CPU3
,
945 static const struct tegra_pmc_soc tegra30_pmc_soc
= {
946 .num_powergates
= ARRAY_SIZE(tegra30_powergates
),
947 .powergates
= tegra30_powergates
,
948 .num_cpu_powergates
= ARRAY_SIZE(tegra30_cpu_powergates
),
949 .cpu_powergates
= tegra30_cpu_powergates
,
950 .has_tsense_reset
= true,
951 .has_gpu_clamps
= false,
954 static const char * const tegra114_powergates
[] = {
955 [TEGRA_POWERGATE_CPU
] = "crail",
956 [TEGRA_POWERGATE_3D
] = "3d",
957 [TEGRA_POWERGATE_VENC
] = "venc",
958 [TEGRA_POWERGATE_VDEC
] = "vdec",
959 [TEGRA_POWERGATE_MPE
] = "mpe",
960 [TEGRA_POWERGATE_HEG
] = "heg",
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_DIS
] = "dis",
969 [TEGRA_POWERGATE_DISB
] = "disb",
970 [TEGRA_POWERGATE_XUSBA
] = "xusba",
971 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
972 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
975 static const u8 tegra114_cpu_powergates
[] = {
976 TEGRA_POWERGATE_CPU0
,
977 TEGRA_POWERGATE_CPU1
,
978 TEGRA_POWERGATE_CPU2
,
979 TEGRA_POWERGATE_CPU3
,
982 static const struct tegra_pmc_soc tegra114_pmc_soc
= {
983 .num_powergates
= ARRAY_SIZE(tegra114_powergates
),
984 .powergates
= tegra114_powergates
,
985 .num_cpu_powergates
= ARRAY_SIZE(tegra114_cpu_powergates
),
986 .cpu_powergates
= tegra114_cpu_powergates
,
987 .has_tsense_reset
= true,
988 .has_gpu_clamps
= false,
991 static const char * const tegra124_powergates
[] = {
992 [TEGRA_POWERGATE_CPU
] = "crail",
993 [TEGRA_POWERGATE_3D
] = "3d",
994 [TEGRA_POWERGATE_VENC
] = "venc",
995 [TEGRA_POWERGATE_PCIE
] = "pcie",
996 [TEGRA_POWERGATE_VDEC
] = "vdec",
997 [TEGRA_POWERGATE_MPE
] = "mpe",
998 [TEGRA_POWERGATE_HEG
] = "heg",
999 [TEGRA_POWERGATE_SATA
] = "sata",
1000 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1001 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1002 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1003 [TEGRA_POWERGATE_CELP
] = "celp",
1004 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1005 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1006 [TEGRA_POWERGATE_C1NC
] = "c1nc",
1007 [TEGRA_POWERGATE_SOR
] = "sor",
1008 [TEGRA_POWERGATE_DIS
] = "dis",
1009 [TEGRA_POWERGATE_DISB
] = "disb",
1010 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1011 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1012 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1013 [TEGRA_POWERGATE_VIC
] = "vic",
1014 [TEGRA_POWERGATE_IRAM
] = "iram",
1017 static const u8 tegra124_cpu_powergates
[] = {
1018 TEGRA_POWERGATE_CPU0
,
1019 TEGRA_POWERGATE_CPU1
,
1020 TEGRA_POWERGATE_CPU2
,
1021 TEGRA_POWERGATE_CPU3
,
1024 static const struct tegra_pmc_soc tegra124_pmc_soc
= {
1025 .num_powergates
= ARRAY_SIZE(tegra124_powergates
),
1026 .powergates
= tegra124_powergates
,
1027 .num_cpu_powergates
= ARRAY_SIZE(tegra124_cpu_powergates
),
1028 .cpu_powergates
= tegra124_cpu_powergates
,
1029 .has_tsense_reset
= true,
1030 .has_gpu_clamps
= true,
1033 static const char * const tegra210_powergates
[] = {
1034 [TEGRA_POWERGATE_CPU
] = "crail",
1035 [TEGRA_POWERGATE_3D
] = "3d",
1036 [TEGRA_POWERGATE_VENC
] = "venc",
1037 [TEGRA_POWERGATE_PCIE
] = "pcie",
1038 [TEGRA_POWERGATE_MPE
] = "mpe",
1039 [TEGRA_POWERGATE_SATA
] = "sata",
1040 [TEGRA_POWERGATE_CPU1
] = "cpu1",
1041 [TEGRA_POWERGATE_CPU2
] = "cpu2",
1042 [TEGRA_POWERGATE_CPU3
] = "cpu3",
1043 [TEGRA_POWERGATE_CPU0
] = "cpu0",
1044 [TEGRA_POWERGATE_C0NC
] = "c0nc",
1045 [TEGRA_POWERGATE_SOR
] = "sor",
1046 [TEGRA_POWERGATE_DIS
] = "dis",
1047 [TEGRA_POWERGATE_DISB
] = "disb",
1048 [TEGRA_POWERGATE_XUSBA
] = "xusba",
1049 [TEGRA_POWERGATE_XUSBB
] = "xusbb",
1050 [TEGRA_POWERGATE_XUSBC
] = "xusbc",
1051 [TEGRA_POWERGATE_VIC
] = "vic",
1052 [TEGRA_POWERGATE_IRAM
] = "iram",
1053 [TEGRA_POWERGATE_NVDEC
] = "nvdec",
1054 [TEGRA_POWERGATE_NVJPG
] = "nvjpg",
1055 [TEGRA_POWERGATE_AUD
] = "aud",
1056 [TEGRA_POWERGATE_DFD
] = "dfd",
1057 [TEGRA_POWERGATE_VE2
] = "ve2",
1060 static const u8 tegra210_cpu_powergates
[] = {
1061 TEGRA_POWERGATE_CPU0
,
1062 TEGRA_POWERGATE_CPU1
,
1063 TEGRA_POWERGATE_CPU2
,
1064 TEGRA_POWERGATE_CPU3
,
1067 static const struct tegra_pmc_soc tegra210_pmc_soc
= {
1068 .num_powergates
= ARRAY_SIZE(tegra210_powergates
),
1069 .powergates
= tegra210_powergates
,
1070 .num_cpu_powergates
= ARRAY_SIZE(tegra210_cpu_powergates
),
1071 .cpu_powergates
= tegra210_cpu_powergates
,
1072 .has_tsense_reset
= true,
1073 .has_gpu_clamps
= true,
1076 static const struct of_device_id tegra_pmc_match
[] = {
1077 { .compatible
= "nvidia,tegra210-pmc", .data
= &tegra210_pmc_soc
},
1078 { .compatible
= "nvidia,tegra132-pmc", .data
= &tegra124_pmc_soc
},
1079 { .compatible
= "nvidia,tegra124-pmc", .data
= &tegra124_pmc_soc
},
1080 { .compatible
= "nvidia,tegra114-pmc", .data
= &tegra114_pmc_soc
},
1081 { .compatible
= "nvidia,tegra30-pmc", .data
= &tegra30_pmc_soc
},
1082 { .compatible
= "nvidia,tegra20-pmc", .data
= &tegra20_pmc_soc
},
1086 static struct platform_driver tegra_pmc_driver
= {
1088 .name
= "tegra-pmc",
1089 .suppress_bind_attrs
= true,
1090 .of_match_table
= tegra_pmc_match
,
1091 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1092 .pm
= &tegra_pmc_pm_ops
,
1095 .probe
= tegra_pmc_probe
,
1097 builtin_platform_driver(tegra_pmc_driver
);
1100 * Early initialization to allow access to registers in the very early boot
1103 static int __init
tegra_pmc_early_init(void)
1105 const struct of_device_id
*match
;
1106 struct device_node
*np
;
1107 struct resource regs
;
1111 np
= of_find_matching_node_and_match(NULL
, tegra_pmc_match
, &match
);
1114 * Fall back to legacy initialization for 32-bit ARM only. All
1115 * 64-bit ARM device tree files for Tegra are required to have
1118 * This is for backwards-compatibility with old device trees
1119 * that didn't contain a PMC node. Note that in this case the
1120 * SoC data can't be matched and therefore powergating is
1123 if (IS_ENABLED(CONFIG_ARM
) && soc_is_tegra()) {
1124 pr_warn("DT node not found, powergating disabled\n");
1126 regs
.start
= 0x7000e400;
1127 regs
.end
= 0x7000e7ff;
1128 regs
.flags
= IORESOURCE_MEM
;
1130 pr_warn("Using memory region %pR\n", ®s
);
1133 * At this point we're not running on Tegra, so play
1134 * nice with multi-platform kernels.
1140 * Extract information from the device tree if we've found a
1143 if (of_address_to_resource(np
, 0, ®s
) < 0) {
1144 pr_err("failed to get PMC registers\n");
1148 pmc
->soc
= match
->data
;
1151 pmc
->base
= ioremap_nocache(regs
.start
, resource_size(®s
));
1153 pr_err("failed to map PMC registers\n");
1157 mutex_init(&pmc
->powergates_lock
);
1160 * Invert the interrupt polarity if a PMC device tree node exists and
1161 * contains the nvidia,invert-interrupt property.
1163 invert
= of_property_read_bool(np
, "nvidia,invert-interrupt");
1165 value
= tegra_pmc_readl(PMC_CNTRL
);
1168 value
|= PMC_CNTRL_INTR_POLARITY
;
1170 value
&= ~PMC_CNTRL_INTR_POLARITY
;
1172 tegra_pmc_writel(value
, PMC_CNTRL
);
1176 early_initcall(tegra_pmc_early_init
);