2 * drivers/soc/tegra/pmc.c
4 * Copyright (c) 2010 Google, Inc
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #define pr_fmt(fmt) "tegra-pmc: " fmt
22 #include <linux/kernel.h>
23 #include <linux/clk.h>
24 #include <linux/clk/tegra.h>
25 #include <linux/debugfs.h>
26 #include <linux/delay.h>
27 #include <linux/err.h>
28 #include <linux/export.h>
29 #include <linux/init.h>
31 #include <linux/iopoll.h>
33 #include <linux/of_address.h>
34 #include <linux/of_clk.h>
35 #include <linux/of_platform.h>
36 #include <linux/pinctrl/pinctrl.h>
37 #include <linux/pinctrl/pinconf.h>
38 #include <linux/pinctrl/pinconf-generic.h>
39 #include <linux/platform_device.h>
40 #include <linux/pm_domain.h>
41 #include <linux/reboot.h>
42 #include <linux/reset.h>
43 #include <linux/seq_file.h>
44 #include <linux/slab.h>
45 #include <linux/spinlock.h>
47 #include <soc/tegra/common.h>
48 #include <soc/tegra/fuse.h>
49 #include <soc/tegra/pmc.h>
51 #include <dt-bindings/pinctrl/pinctrl-tegra-io-pad.h>
54 #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
55 #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
56 #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
57 #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
58 #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
59 #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
60 #define PMC_CNTRL_MAIN_RST BIT(4)
62 #define DPD_SAMPLE 0x020
63 #define DPD_SAMPLE_ENABLE BIT(0)
64 #define DPD_SAMPLE_DISABLE (0 << 0)
66 #define PWRGATE_TOGGLE 0x30
67 #define PWRGATE_TOGGLE_START BIT(8)
69 #define REMOVE_CLAMPING 0x34
71 #define PWRGATE_STATUS 0x38
73 #define PMC_IMPL_E_33V_PWR 0x40
75 #define PMC_PWR_DET 0x48
77 #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
78 #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
79 #define PMC_SCRATCH0_MODE_RCM BIT(1)
80 #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
81 PMC_SCRATCH0_MODE_BOOTLOADER | \
82 PMC_SCRATCH0_MODE_RCM)
84 #define PMC_CPUPWRGOOD_TIMER 0xc8
85 #define PMC_CPUPWROFF_TIMER 0xcc
87 #define PMC_PWR_DET_VALUE 0xe4
89 #define PMC_SCRATCH41 0x140
91 #define PMC_SENSOR_CTRL 0x1b0
92 #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
93 #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
95 #define PMC_RST_STATUS 0x1b4
96 #define PMC_RST_STATUS_POR 0
97 #define PMC_RST_STATUS_WATCHDOG 1
98 #define PMC_RST_STATUS_SENSOR 2
99 #define PMC_RST_STATUS_SW_MAIN 3
100 #define PMC_RST_STATUS_LP0 4
101 #define PMC_RST_STATUS_AOTAG 5
103 #define IO_DPD_REQ 0x1b8
104 #define IO_DPD_REQ_CODE_IDLE (0U << 30)
105 #define IO_DPD_REQ_CODE_OFF (1U << 30)
106 #define IO_DPD_REQ_CODE_ON (2U << 30)
107 #define IO_DPD_REQ_CODE_MASK (3U << 30)
109 #define IO_DPD_STATUS 0x1bc
110 #define IO_DPD2_REQ 0x1c0
111 #define IO_DPD2_STATUS 0x1c4
112 #define SEL_DPD_TIM 0x1c8
114 #define PMC_SCRATCH54 0x258
115 #define PMC_SCRATCH54_DATA_SHIFT 8
116 #define PMC_SCRATCH54_ADDR_SHIFT 0
118 #define PMC_SCRATCH55 0x25c
119 #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
120 #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
121 #define PMC_SCRATCH55_PINMUX_SHIFT 24
122 #define PMC_SCRATCH55_16BITOP BIT(15)
123 #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
124 #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
126 #define GPU_RG_CNTRL 0x2d4
128 /* Tegra186 and later */
129 #define WAKE_AOWAKE_CTRL 0x4f4
130 #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0)
132 struct tegra_powergate {
133 struct generic_pm_domain genpd;
134 struct tegra_pmc *pmc;
137 unsigned int num_clks;
138 struct reset_control *reset;
141 struct tegra_io_pad_soc {
142 enum tegra_io_pad id;
144 unsigned int voltage;
148 struct tegra_pmc_regs {
149 unsigned int scratch0;
150 unsigned int dpd_req;
151 unsigned int dpd_status;
152 unsigned int dpd2_req;
153 unsigned int dpd2_status;
156 struct tegra_pmc_soc {
157 unsigned int num_powergates;
158 const char *const *powergates;
159 unsigned int num_cpu_powergates;
160 const u8 *cpu_powergates;
162 bool has_tsense_reset;
164 bool needs_mbist_war;
165 bool has_impl_33v_pwr;
167 const struct tegra_io_pad_soc *io_pads;
168 unsigned int num_io_pads;
170 const struct pinctrl_pin_desc *pin_descs;
171 unsigned int num_pin_descs;
173 const struct tegra_pmc_regs *regs;
174 void (*init)(struct tegra_pmc *pmc);
175 void (*setup_irq_polarity)(struct tegra_pmc *pmc,
176 struct device_node *np,
181 * struct tegra_pmc - NVIDIA Tegra PMC
182 * @dev: pointer to PMC device structure
183 * @base: pointer to I/O remapped register region
184 * @clk: pointer to pclk clock
185 * @soc: pointer to SoC data structure
186 * @debugfs: pointer to debugfs entry
187 * @rate: currently configured rate of pclk
188 * @suspend_mode: lowest suspend mode available
189 * @cpu_good_time: CPU power good time (in microseconds)
190 * @cpu_off_time: CPU power off time (in microsecends)
191 * @core_osc_time: core power good OSC time (in microseconds)
192 * @core_pmu_time: core power good PMU time (in microseconds)
193 * @core_off_time: core power off time (in microseconds)
194 * @corereq_high: core power request is active-high
195 * @sysclkreq_high: system clock request is active-high
196 * @combined_req: combined power request for CPU & core
197 * @cpu_pwr_good_en: CPU power good signal is enabled
198 * @lp0_vec_phys: physical base address of the LP0 warm boot code
199 * @lp0_vec_size: size of the LP0 warm boot code
200 * @powergates_available: Bitmap of available power gates
201 * @powergates_lock: mutex for power gate register access
208 void __iomem *scratch;
210 struct dentry *debugfs;
212 const struct tegra_pmc_soc *soc;
216 enum tegra_suspend_mode suspend_mode;
225 bool cpu_pwr_good_en;
228 DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX);
230 struct mutex powergates_lock;
232 struct pinctrl_dev *pctl_dev;
235 static struct tegra_pmc *pmc = &(struct tegra_pmc) {
237 .suspend_mode = TEGRA_SUSPEND_NONE,
240 static inline struct tegra_powergate *
241 to_powergate(struct generic_pm_domain *domain)
243 return container_of(domain, struct tegra_powergate, genpd);
246 static u32 tegra_pmc_readl(unsigned long offset)
248 return readl(pmc->base + offset);
251 static void tegra_pmc_writel(u32 value, unsigned long offset)
253 writel(value, pmc->base + offset);
256 static inline bool tegra_powergate_state(int id)
258 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
259 return (tegra_pmc_readl(GPU_RG_CNTRL) & 0x1) == 0;
261 return (tegra_pmc_readl(PWRGATE_STATUS) & BIT(id)) != 0;
264 static inline bool tegra_powergate_is_valid(int id)
266 return (pmc->soc && pmc->soc->powergates[id]);
269 static inline bool tegra_powergate_is_available(int id)
271 return test_bit(id, pmc->powergates_available);
274 static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name)
278 if (!pmc || !pmc->soc || !name)
281 for (i = 0; i < pmc->soc->num_powergates; i++) {
282 if (!tegra_powergate_is_valid(i))
285 if (!strcmp(name, pmc->soc->powergates[i]))
293 * tegra_powergate_set() - set the state of a partition
295 * @new_state: new state of the partition
297 static int tegra_powergate_set(unsigned int id, bool new_state)
302 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
305 mutex_lock(&pmc->powergates_lock);
307 if (tegra_powergate_state(id) == new_state) {
308 mutex_unlock(&pmc->powergates_lock);
312 tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
314 err = readx_poll_timeout(tegra_powergate_state, id, status,
315 status == new_state, 10, 100000);
317 mutex_unlock(&pmc->powergates_lock);
322 static int __tegra_powergate_remove_clamping(unsigned int id)
326 mutex_lock(&pmc->powergates_lock);
329 * On Tegra124 and later, the clamps for the GPU are controlled by a
330 * separate register (with different semantics).
332 if (id == TEGRA_POWERGATE_3D) {
333 if (pmc->soc->has_gpu_clamps) {
334 tegra_pmc_writel(0, GPU_RG_CNTRL);
340 * Tegra 2 has a bug where PCIE and VDE clamping masks are
341 * swapped relatively to the partition ids
343 if (id == TEGRA_POWERGATE_VDEC)
344 mask = (1 << TEGRA_POWERGATE_PCIE);
345 else if (id == TEGRA_POWERGATE_PCIE)
346 mask = (1 << TEGRA_POWERGATE_VDEC);
350 tegra_pmc_writel(mask, REMOVE_CLAMPING);
353 mutex_unlock(&pmc->powergates_lock);
358 static void tegra_powergate_disable_clocks(struct tegra_powergate *pg)
362 for (i = 0; i < pg->num_clks; i++)
363 clk_disable_unprepare(pg->clks[i]);
366 static int tegra_powergate_enable_clocks(struct tegra_powergate *pg)
371 for (i = 0; i < pg->num_clks; i++) {
372 err = clk_prepare_enable(pg->clks[i]);
381 clk_disable_unprepare(pg->clks[i]);
386 int __weak tegra210_clk_handle_mbist_war(unsigned int id)
391 static int tegra_powergate_power_up(struct tegra_powergate *pg,
396 err = reset_control_assert(pg->reset);
400 usleep_range(10, 20);
402 err = tegra_powergate_set(pg->id, true);
406 usleep_range(10, 20);
408 err = tegra_powergate_enable_clocks(pg);
412 usleep_range(10, 20);
414 err = __tegra_powergate_remove_clamping(pg->id);
418 usleep_range(10, 20);
420 err = reset_control_deassert(pg->reset);
424 usleep_range(10, 20);
426 if (pg->pmc->soc->needs_mbist_war)
427 err = tegra210_clk_handle_mbist_war(pg->id);
432 tegra_powergate_disable_clocks(pg);
437 tegra_powergate_disable_clocks(pg);
438 usleep_range(10, 20);
441 tegra_powergate_set(pg->id, false);
446 static int tegra_powergate_power_down(struct tegra_powergate *pg)
450 err = tegra_powergate_enable_clocks(pg);
454 usleep_range(10, 20);
456 err = reset_control_assert(pg->reset);
460 usleep_range(10, 20);
462 tegra_powergate_disable_clocks(pg);
464 usleep_range(10, 20);
466 err = tegra_powergate_set(pg->id, false);
473 tegra_powergate_enable_clocks(pg);
474 usleep_range(10, 20);
475 reset_control_deassert(pg->reset);
476 usleep_range(10, 20);
479 tegra_powergate_disable_clocks(pg);
484 static int tegra_genpd_power_on(struct generic_pm_domain *domain)
486 struct tegra_powergate *pg = to_powergate(domain);
489 err = tegra_powergate_power_up(pg, true);
491 pr_err("failed to turn on PM domain %s: %d\n", pg->genpd.name,
497 static int tegra_genpd_power_off(struct generic_pm_domain *domain)
499 struct tegra_powergate *pg = to_powergate(domain);
502 err = tegra_powergate_power_down(pg);
504 pr_err("failed to turn off PM domain %s: %d\n",
505 pg->genpd.name, err);
511 * tegra_powergate_power_on() - power on partition
514 int tegra_powergate_power_on(unsigned int id)
516 if (!tegra_powergate_is_available(id))
519 return tegra_powergate_set(id, true);
523 * tegra_powergate_power_off() - power off partition
526 int tegra_powergate_power_off(unsigned int id)
528 if (!tegra_powergate_is_available(id))
531 return tegra_powergate_set(id, false);
533 EXPORT_SYMBOL(tegra_powergate_power_off);
536 * tegra_powergate_is_powered() - check if partition is powered
539 int tegra_powergate_is_powered(unsigned int id)
543 if (!tegra_powergate_is_valid(id))
546 mutex_lock(&pmc->powergates_lock);
547 status = tegra_powergate_state(id);
548 mutex_unlock(&pmc->powergates_lock);
554 * tegra_powergate_remove_clamping() - remove power clamps for partition
557 int tegra_powergate_remove_clamping(unsigned int id)
559 if (!tegra_powergate_is_available(id))
562 return __tegra_powergate_remove_clamping(id);
564 EXPORT_SYMBOL(tegra_powergate_remove_clamping);
567 * tegra_powergate_sequence_power_up() - power up partition
569 * @clk: clock for partition
570 * @rst: reset for partition
572 * Must be called with clk disabled, and returns with clk enabled.
574 int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
575 struct reset_control *rst)
577 struct tegra_powergate *pg;
580 if (!tegra_powergate_is_available(id))
583 pg = kzalloc(sizeof(*pg), GFP_KERNEL);
593 err = tegra_powergate_power_up(pg, false);
595 pr_err("failed to turn on partition %d: %d\n", id, err);
601 EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
604 * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
605 * @cpuid: CPU partition ID
607 * Returns the partition ID corresponding to the CPU partition ID or a
608 * negative error code on failure.
610 static int tegra_get_cpu_powergate_id(unsigned int cpuid)
612 if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates)
613 return pmc->soc->cpu_powergates[cpuid];
619 * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
620 * @cpuid: CPU partition ID
622 bool tegra_pmc_cpu_is_powered(unsigned int cpuid)
626 id = tegra_get_cpu_powergate_id(cpuid);
630 return tegra_powergate_is_powered(id);
634 * tegra_pmc_cpu_power_on() - power on CPU partition
635 * @cpuid: CPU partition ID
637 int tegra_pmc_cpu_power_on(unsigned int cpuid)
641 id = tegra_get_cpu_powergate_id(cpuid);
645 return tegra_powergate_set(id, true);
649 * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
650 * @cpuid: CPU partition ID
652 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)
656 id = tegra_get_cpu_powergate_id(cpuid);
660 return tegra_powergate_remove_clamping(id);
663 static int tegra_pmc_restart_notify(struct notifier_block *this,
664 unsigned long action, void *data)
666 const char *cmd = data;
669 value = readl(pmc->scratch + pmc->soc->regs->scratch0);
670 value &= ~PMC_SCRATCH0_MODE_MASK;
673 if (strcmp(cmd, "recovery") == 0)
674 value |= PMC_SCRATCH0_MODE_RECOVERY;
676 if (strcmp(cmd, "bootloader") == 0)
677 value |= PMC_SCRATCH0_MODE_BOOTLOADER;
679 if (strcmp(cmd, "forced-recovery") == 0)
680 value |= PMC_SCRATCH0_MODE_RCM;
683 writel(value, pmc->scratch + pmc->soc->regs->scratch0);
685 /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
686 value = tegra_pmc_readl(PMC_CNTRL);
687 value |= PMC_CNTRL_MAIN_RST;
688 tegra_pmc_writel(value, PMC_CNTRL);
693 static struct notifier_block tegra_pmc_restart_handler = {
694 .notifier_call = tegra_pmc_restart_notify,
698 static int powergate_show(struct seq_file *s, void *data)
703 seq_printf(s, " powergate powered\n");
704 seq_printf(s, "------------------\n");
706 for (i = 0; i < pmc->soc->num_powergates; i++) {
707 status = tegra_powergate_is_powered(i);
711 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
712 status ? "yes" : "no");
718 static int powergate_open(struct inode *inode, struct file *file)
720 return single_open(file, powergate_show, inode->i_private);
723 static const struct file_operations powergate_fops = {
724 .open = powergate_open,
727 .release = single_release,
730 static int tegra_powergate_debugfs_init(void)
732 pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
740 static int tegra_powergate_of_get_clks(struct tegra_powergate *pg,
741 struct device_node *np)
744 unsigned int i, count;
747 count = of_clk_get_parent_count(np);
751 pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL);
755 for (i = 0; i < count; i++) {
756 pg->clks[i] = of_clk_get(np, i);
757 if (IS_ERR(pg->clks[i])) {
758 err = PTR_ERR(pg->clks[i]);
763 pg->num_clks = count;
769 clk_put(pg->clks[i]);
776 static int tegra_powergate_of_get_resets(struct tegra_powergate *pg,
777 struct device_node *np, bool off)
781 pg->reset = of_reset_control_array_get_exclusive(np);
782 if (IS_ERR(pg->reset)) {
783 err = PTR_ERR(pg->reset);
784 pr_err("failed to get device resets: %d\n", err);
789 err = reset_control_assert(pg->reset);
791 err = reset_control_deassert(pg->reset);
794 reset_control_put(pg->reset);
799 static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np)
801 struct tegra_powergate *pg;
805 pg = kzalloc(sizeof(*pg), GFP_KERNEL);
809 id = tegra_powergate_lookup(pmc, np->name);
811 pr_err("powergate lookup failed for %pOFn: %d\n", np, id);
816 * Clear the bit for this powergate so it cannot be managed
817 * directly via the legacy APIs for controlling powergates.
819 clear_bit(id, pmc->powergates_available);
822 pg->genpd.name = np->name;
823 pg->genpd.power_off = tegra_genpd_power_off;
824 pg->genpd.power_on = tegra_genpd_power_on;
827 off = !tegra_powergate_is_powered(pg->id);
829 err = tegra_powergate_of_get_clks(pg, np);
831 pr_err("failed to get clocks for %pOFn: %d\n", np, err);
835 err = tegra_powergate_of_get_resets(pg, np, off);
837 pr_err("failed to get resets for %pOFn: %d\n", np, err);
841 if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) {
843 WARN_ON(tegra_powergate_power_up(pg, true));
849 * FIXME: If XHCI is enabled for Tegra, then power-up the XUSB
850 * host and super-speed partitions. Once the XHCI driver
851 * manages the partitions itself this code can be removed. Note
852 * that we don't register these partitions with the genpd core
853 * to avoid it from powering down the partitions as they appear
856 if (IS_ENABLED(CONFIG_USB_XHCI_TEGRA) &&
857 (id == TEGRA_POWERGATE_XUSBA || id == TEGRA_POWERGATE_XUSBC)) {
859 WARN_ON(tegra_powergate_power_up(pg, true));
864 err = pm_genpd_init(&pg->genpd, NULL, off);
866 pr_err("failed to initialise PM domain %pOFn: %d\n", np,
871 err = of_genpd_add_provider_simple(np, &pg->genpd);
873 pr_err("failed to add PM domain provider for %pOFn: %d\n",
878 pr_debug("added PM domain %s\n", pg->genpd.name);
883 pm_genpd_remove(&pg->genpd);
886 reset_control_put(pg->reset);
889 while (pg->num_clks--)
890 clk_put(pg->clks[pg->num_clks]);
895 set_bit(id, pmc->powergates_available);
901 static void tegra_powergate_init(struct tegra_pmc *pmc,
902 struct device_node *parent)
904 struct device_node *np, *child;
907 /* Create a bitmap of the available and valid partitions */
908 for (i = 0; i < pmc->soc->num_powergates; i++)
909 if (pmc->soc->powergates[i])
910 set_bit(i, pmc->powergates_available);
912 np = of_get_child_by_name(parent, "powergates");
916 for_each_child_of_node(np, child)
917 tegra_powergate_add(pmc, child);
922 static const struct tegra_io_pad_soc *
923 tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id)
927 for (i = 0; i < pmc->soc->num_io_pads; i++)
928 if (pmc->soc->io_pads[i].id == id)
929 return &pmc->soc->io_pads[i];
934 static int tegra_io_pad_get_dpd_register_bit(enum tegra_io_pad id,
935 unsigned long *request,
936 unsigned long *status,
939 const struct tegra_io_pad_soc *pad;
941 pad = tegra_io_pad_find(pmc, id);
943 pr_err("invalid I/O pad ID %u\n", id);
947 if (pad->dpd == UINT_MAX)
950 *mask = BIT(pad->dpd % 32);
953 *status = pmc->soc->regs->dpd_status;
954 *request = pmc->soc->regs->dpd_req;
956 *status = pmc->soc->regs->dpd2_status;
957 *request = pmc->soc->regs->dpd2_req;
963 static int tegra_io_pad_prepare(enum tegra_io_pad id, unsigned long *request,
964 unsigned long *status, u32 *mask)
966 unsigned long rate, value;
969 err = tegra_io_pad_get_dpd_register_bit(id, request, status, mask);
974 rate = clk_get_rate(pmc->clk);
976 pr_err("failed to get clock rate\n");
980 tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
982 /* must be at least 200 ns, in APB (PCLK) clock cycles */
983 value = DIV_ROUND_UP(1000000000, rate);
984 value = DIV_ROUND_UP(200, value);
985 tegra_pmc_writel(value, SEL_DPD_TIM);
991 static int tegra_io_pad_poll(unsigned long offset, u32 mask,
992 u32 val, unsigned long timeout)
996 timeout = jiffies + msecs_to_jiffies(timeout);
998 while (time_after(timeout, jiffies)) {
999 value = tegra_pmc_readl(offset);
1000 if ((value & mask) == val)
1003 usleep_range(250, 1000);
1009 static void tegra_io_pad_unprepare(void)
1012 tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
1016 * tegra_io_pad_power_enable() - enable power to I/O pad
1017 * @id: Tegra I/O pad ID for which to enable power
1019 * Returns: 0 on success or a negative error code on failure.
1021 int tegra_io_pad_power_enable(enum tegra_io_pad id)
1023 unsigned long request, status;
1027 mutex_lock(&pmc->powergates_lock);
1029 err = tegra_io_pad_prepare(id, &request, &status, &mask);
1031 pr_err("failed to prepare I/O pad: %d\n", err);
1035 tegra_pmc_writel(IO_DPD_REQ_CODE_OFF | mask, request);
1037 err = tegra_io_pad_poll(status, mask, 0, 250);
1039 pr_err("failed to enable I/O pad: %d\n", err);
1043 tegra_io_pad_unprepare();
1046 mutex_unlock(&pmc->powergates_lock);
1049 EXPORT_SYMBOL(tegra_io_pad_power_enable);
1052 * tegra_io_pad_power_disable() - disable power to I/O pad
1053 * @id: Tegra I/O pad ID for which to disable power
1055 * Returns: 0 on success or a negative error code on failure.
1057 int tegra_io_pad_power_disable(enum tegra_io_pad id)
1059 unsigned long request, status;
1063 mutex_lock(&pmc->powergates_lock);
1065 err = tegra_io_pad_prepare(id, &request, &status, &mask);
1067 pr_err("failed to prepare I/O pad: %d\n", err);
1071 tegra_pmc_writel(IO_DPD_REQ_CODE_ON | mask, request);
1073 err = tegra_io_pad_poll(status, mask, mask, 250);
1075 pr_err("failed to disable I/O pad: %d\n", err);
1079 tegra_io_pad_unprepare();
1082 mutex_unlock(&pmc->powergates_lock);
1085 EXPORT_SYMBOL(tegra_io_pad_power_disable);
1087 static int tegra_io_pad_is_powered(enum tegra_io_pad id)
1089 unsigned long request, status;
1093 err = tegra_io_pad_get_dpd_register_bit(id, &request, &status, &mask);
1097 value = tegra_pmc_readl(status);
1099 return !(value & mask);
1102 static int tegra_io_pad_set_voltage(enum tegra_io_pad id, int voltage)
1104 const struct tegra_io_pad_soc *pad;
1107 pad = tegra_io_pad_find(pmc, id);
1111 if (pad->voltage == UINT_MAX)
1114 mutex_lock(&pmc->powergates_lock);
1116 if (pmc->soc->has_impl_33v_pwr) {
1117 value = tegra_pmc_readl(PMC_IMPL_E_33V_PWR);
1119 if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8)
1120 value &= ~BIT(pad->voltage);
1122 value |= BIT(pad->voltage);
1124 tegra_pmc_writel(value, PMC_IMPL_E_33V_PWR);
1126 /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
1127 value = tegra_pmc_readl(PMC_PWR_DET);
1128 value |= BIT(pad->voltage);
1129 tegra_pmc_writel(value, PMC_PWR_DET);
1131 /* update I/O voltage */
1132 value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
1134 if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8)
1135 value &= ~BIT(pad->voltage);
1137 value |= BIT(pad->voltage);
1139 tegra_pmc_writel(value, PMC_PWR_DET_VALUE);
1142 mutex_unlock(&pmc->powergates_lock);
1144 usleep_range(100, 250);
1149 static int tegra_io_pad_get_voltage(enum tegra_io_pad id)
1151 const struct tegra_io_pad_soc *pad;
1154 pad = tegra_io_pad_find(pmc, id);
1158 if (pad->voltage == UINT_MAX)
1161 if (pmc->soc->has_impl_33v_pwr)
1162 value = tegra_pmc_readl(PMC_IMPL_E_33V_PWR);
1164 value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
1166 if ((value & BIT(pad->voltage)) == 0)
1167 return TEGRA_IO_PAD_VOLTAGE_1V8;
1169 return TEGRA_IO_PAD_VOLTAGE_3V3;
1173 * tegra_io_rail_power_on() - enable power to I/O rail
1174 * @id: Tegra I/O pad ID for which to enable power
1176 * See also: tegra_io_pad_power_enable()
1178 int tegra_io_rail_power_on(unsigned int id)
1180 return tegra_io_pad_power_enable(id);
1182 EXPORT_SYMBOL(tegra_io_rail_power_on);
1185 * tegra_io_rail_power_off() - disable power to I/O rail
1186 * @id: Tegra I/O pad ID for which to disable power
1188 * See also: tegra_io_pad_power_disable()
1190 int tegra_io_rail_power_off(unsigned int id)
1192 return tegra_io_pad_power_disable(id);
1194 EXPORT_SYMBOL(tegra_io_rail_power_off);
1196 #ifdef CONFIG_PM_SLEEP
1197 enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
1199 return pmc->suspend_mode;
1202 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
1204 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
1207 pmc->suspend_mode = mode;
1210 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
1212 unsigned long long rate = 0;
1216 case TEGRA_SUSPEND_LP1:
1220 case TEGRA_SUSPEND_LP2:
1221 rate = clk_get_rate(pmc->clk);
1228 if (WARN_ON_ONCE(rate == 0))
1231 if (rate != pmc->rate) {
1234 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
1235 do_div(ticks, USEC_PER_SEC);
1236 tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
1238 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
1239 do_div(ticks, USEC_PER_SEC);
1240 tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
1247 value = tegra_pmc_readl(PMC_CNTRL);
1248 value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
1249 value |= PMC_CNTRL_CPU_PWRREQ_OE;
1250 tegra_pmc_writel(value, PMC_CNTRL);
1254 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
1256 u32 value, values[2];
1258 if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
1262 pmc->suspend_mode = TEGRA_SUSPEND_LP0;
1266 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
1270 pmc->suspend_mode = TEGRA_SUSPEND_LP2;
1274 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
1279 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
1281 if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
1282 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
1284 pmc->cpu_good_time = value;
1286 if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
1287 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
1289 pmc->cpu_off_time = value;
1291 if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
1292 values, ARRAY_SIZE(values)))
1293 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
1295 pmc->core_osc_time = values[0];
1296 pmc->core_pmu_time = values[1];
1298 if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
1299 pmc->suspend_mode = TEGRA_SUSPEND_NONE;
1301 pmc->core_off_time = value;
1303 pmc->corereq_high = of_property_read_bool(np,
1304 "nvidia,core-power-req-active-high");
1306 pmc->sysclkreq_high = of_property_read_bool(np,
1307 "nvidia,sys-clock-req-active-high");
1309 pmc->combined_req = of_property_read_bool(np,
1310 "nvidia,combined-power-req");
1312 pmc->cpu_pwr_good_en = of_property_read_bool(np,
1313 "nvidia,cpu-pwr-good-en");
1315 if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
1316 ARRAY_SIZE(values)))
1317 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
1318 pmc->suspend_mode = TEGRA_SUSPEND_LP1;
1320 pmc->lp0_vec_phys = values[0];
1321 pmc->lp0_vec_size = values[1];
1326 static void tegra_pmc_init(struct tegra_pmc *pmc)
1329 pmc->soc->init(pmc);
1332 static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
1334 static const char disabled[] = "emergency thermal reset disabled";
1335 u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
1336 struct device *dev = pmc->dev;
1337 struct device_node *np;
1338 u32 value, checksum;
1340 if (!pmc->soc->has_tsense_reset)
1343 np = of_get_child_by_name(pmc->dev->of_node, "i2c-thermtrip");
1345 dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
1349 if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
1350 dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
1354 if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
1355 dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
1359 if (of_property_read_u32(np, "nvidia,reg-addr", ®_addr)) {
1360 dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
1364 if (of_property_read_u32(np, "nvidia,reg-data", ®_data)) {
1365 dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
1369 if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
1372 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
1373 value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
1374 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
1376 value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
1377 (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
1378 tegra_pmc_writel(value, PMC_SCRATCH54);
1380 value = PMC_SCRATCH55_RESET_TEGRA;
1381 value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
1382 value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
1383 value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
1386 * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
1387 * contain the checksum and are currently zero, so they are not added.
1389 checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
1390 + ((value >> 24) & 0xff);
1392 checksum = 0x100 - checksum;
1394 value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
1396 tegra_pmc_writel(value, PMC_SCRATCH55);
1398 value = tegra_pmc_readl(PMC_SENSOR_CTRL);
1399 value |= PMC_SENSOR_CTRL_ENABLE_RST;
1400 tegra_pmc_writel(value, PMC_SENSOR_CTRL);
1402 dev_info(pmc->dev, "emergency thermal reset enabled\n");
1408 static int tegra_io_pad_pinctrl_get_groups_count(struct pinctrl_dev *pctl_dev)
1410 return pmc->soc->num_io_pads;
1413 static const char *tegra_io_pad_pinctrl_get_group_name(
1414 struct pinctrl_dev *pctl, unsigned int group)
1416 return pmc->soc->io_pads[group].name;
1419 static int tegra_io_pad_pinctrl_get_group_pins(struct pinctrl_dev *pctl_dev,
1421 const unsigned int **pins,
1422 unsigned int *num_pins)
1424 *pins = &pmc->soc->io_pads[group].id;
1429 static const struct pinctrl_ops tegra_io_pad_pinctrl_ops = {
1430 .get_groups_count = tegra_io_pad_pinctrl_get_groups_count,
1431 .get_group_name = tegra_io_pad_pinctrl_get_group_name,
1432 .get_group_pins = tegra_io_pad_pinctrl_get_group_pins,
1433 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
1434 .dt_free_map = pinconf_generic_dt_free_map,
1437 static int tegra_io_pad_pinconf_get(struct pinctrl_dev *pctl_dev,
1438 unsigned int pin, unsigned long *config)
1440 const struct tegra_io_pad_soc *pad = tegra_io_pad_find(pmc, pin);
1441 enum pin_config_param param = pinconf_to_config_param(*config);
1449 case PIN_CONFIG_POWER_SOURCE:
1450 ret = tegra_io_pad_get_voltage(pad->id);
1455 case PIN_CONFIG_LOW_POWER_MODE:
1456 ret = tegra_io_pad_is_powered(pad->id);
1465 *config = pinconf_to_config_packed(param, arg);
1470 static int tegra_io_pad_pinconf_set(struct pinctrl_dev *pctl_dev,
1471 unsigned int pin, unsigned long *configs,
1472 unsigned int num_configs)
1474 const struct tegra_io_pad_soc *pad = tegra_io_pad_find(pmc, pin);
1475 enum pin_config_param param;
1483 for (i = 0; i < num_configs; ++i) {
1484 param = pinconf_to_config_param(configs[i]);
1485 arg = pinconf_to_config_argument(configs[i]);
1488 case PIN_CONFIG_LOW_POWER_MODE:
1490 err = tegra_io_pad_power_disable(pad->id);
1492 err = tegra_io_pad_power_enable(pad->id);
1496 case PIN_CONFIG_POWER_SOURCE:
1497 if (arg != TEGRA_IO_PAD_VOLTAGE_1V8 &&
1498 arg != TEGRA_IO_PAD_VOLTAGE_3V3)
1500 err = tegra_io_pad_set_voltage(pad->id, arg);
1512 static const struct pinconf_ops tegra_io_pad_pinconf_ops = {
1513 .pin_config_get = tegra_io_pad_pinconf_get,
1514 .pin_config_set = tegra_io_pad_pinconf_set,
1518 static struct pinctrl_desc tegra_pmc_pctl_desc = {
1519 .pctlops = &tegra_io_pad_pinctrl_ops,
1520 .confops = &tegra_io_pad_pinconf_ops,
1523 static int tegra_pmc_pinctrl_init(struct tegra_pmc *pmc)
1527 if (!pmc->soc->num_pin_descs)
1530 tegra_pmc_pctl_desc.name = dev_name(pmc->dev);
1531 tegra_pmc_pctl_desc.pins = pmc->soc->pin_descs;
1532 tegra_pmc_pctl_desc.npins = pmc->soc->num_pin_descs;
1534 pmc->pctl_dev = devm_pinctrl_register(pmc->dev, &tegra_pmc_pctl_desc,
1536 if (IS_ERR(pmc->pctl_dev)) {
1537 err = PTR_ERR(pmc->pctl_dev);
1538 dev_err(pmc->dev, "unable to register pinctrl, %d\n", err);
1544 static int tegra_pmc_probe(struct platform_device *pdev)
1547 struct resource *res;
1551 * Early initialisation should have configured an initial
1552 * register mapping and setup the soc data pointer. If these
1553 * are not valid then something went badly wrong!
1555 if (WARN_ON(!pmc->base || !pmc->soc))
1558 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
1562 /* take over the memory region from the early initialization */
1563 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1564 base = devm_ioremap_resource(&pdev->dev, res);
1566 return PTR_ERR(base);
1568 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wake");
1570 pmc->wake = devm_ioremap_resource(&pdev->dev, res);
1571 if (IS_ERR(pmc->wake))
1572 return PTR_ERR(pmc->wake);
1577 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aotag");
1579 pmc->aotag = devm_ioremap_resource(&pdev->dev, res);
1580 if (IS_ERR(pmc->aotag))
1581 return PTR_ERR(pmc->aotag);
1586 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "scratch");
1588 pmc->scratch = devm_ioremap_resource(&pdev->dev, res);
1589 if (IS_ERR(pmc->scratch))
1590 return PTR_ERR(pmc->scratch);
1592 pmc->scratch = base;
1595 pmc->clk = devm_clk_get(&pdev->dev, "pclk");
1596 if (IS_ERR(pmc->clk)) {
1597 err = PTR_ERR(pmc->clk);
1599 if (err != -ENOENT) {
1600 dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
1607 pmc->dev = &pdev->dev;
1609 tegra_pmc_init(pmc);
1611 tegra_pmc_init_tsense_reset(pmc);
1613 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1614 err = tegra_powergate_debugfs_init();
1619 err = register_restart_handler(&tegra_pmc_restart_handler);
1621 dev_err(&pdev->dev, "unable to register restart handler, %d\n",
1623 goto cleanup_debugfs;
1626 err = tegra_pmc_pinctrl_init(pmc);
1628 goto cleanup_restart_handler;
1630 mutex_lock(&pmc->powergates_lock);
1633 mutex_unlock(&pmc->powergates_lock);
1637 cleanup_restart_handler:
1638 unregister_restart_handler(&tegra_pmc_restart_handler);
1640 debugfs_remove(pmc->debugfs);
1644 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
1645 static int tegra_pmc_suspend(struct device *dev)
1647 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
1652 static int tegra_pmc_resume(struct device *dev)
1654 tegra_pmc_writel(0x0, PMC_SCRATCH41);
1659 static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
1663 static const char * const tegra20_powergates[] = {
1664 [TEGRA_POWERGATE_CPU] = "cpu",
1665 [TEGRA_POWERGATE_3D] = "3d",
1666 [TEGRA_POWERGATE_VENC] = "venc",
1667 [TEGRA_POWERGATE_VDEC] = "vdec",
1668 [TEGRA_POWERGATE_PCIE] = "pcie",
1669 [TEGRA_POWERGATE_L2] = "l2",
1670 [TEGRA_POWERGATE_MPE] = "mpe",
1673 static const struct tegra_pmc_regs tegra20_pmc_regs = {
1676 .dpd_status = 0x1bc,
1678 .dpd2_status = 0x1c4,
1681 static void tegra20_pmc_init(struct tegra_pmc *pmc)
1685 /* Always enable CPU power request */
1686 value = tegra_pmc_readl(PMC_CNTRL);
1687 value |= PMC_CNTRL_CPU_PWRREQ_OE;
1688 tegra_pmc_writel(value, PMC_CNTRL);
1690 value = tegra_pmc_readl(PMC_CNTRL);
1692 if (pmc->sysclkreq_high)
1693 value &= ~PMC_CNTRL_SYSCLK_POLARITY;
1695 value |= PMC_CNTRL_SYSCLK_POLARITY;
1697 /* configure the output polarity while the request is tristated */
1698 tegra_pmc_writel(value, PMC_CNTRL);
1700 /* now enable the request */
1701 value = tegra_pmc_readl(PMC_CNTRL);
1702 value |= PMC_CNTRL_SYSCLK_OE;
1703 tegra_pmc_writel(value, PMC_CNTRL);
1706 static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
1707 struct device_node *np,
1712 value = tegra_pmc_readl(PMC_CNTRL);
1715 value |= PMC_CNTRL_INTR_POLARITY;
1717 value &= ~PMC_CNTRL_INTR_POLARITY;
1719 tegra_pmc_writel(value, PMC_CNTRL);
1722 static const struct tegra_pmc_soc tegra20_pmc_soc = {
1723 .num_powergates = ARRAY_SIZE(tegra20_powergates),
1724 .powergates = tegra20_powergates,
1725 .num_cpu_powergates = 0,
1726 .cpu_powergates = NULL,
1727 .has_tsense_reset = false,
1728 .has_gpu_clamps = false,
1733 .regs = &tegra20_pmc_regs,
1734 .init = tegra20_pmc_init,
1735 .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
1738 static const char * const tegra30_powergates[] = {
1739 [TEGRA_POWERGATE_CPU] = "cpu0",
1740 [TEGRA_POWERGATE_3D] = "3d0",
1741 [TEGRA_POWERGATE_VENC] = "venc",
1742 [TEGRA_POWERGATE_VDEC] = "vdec",
1743 [TEGRA_POWERGATE_PCIE] = "pcie",
1744 [TEGRA_POWERGATE_L2] = "l2",
1745 [TEGRA_POWERGATE_MPE] = "mpe",
1746 [TEGRA_POWERGATE_HEG] = "heg",
1747 [TEGRA_POWERGATE_SATA] = "sata",
1748 [TEGRA_POWERGATE_CPU1] = "cpu1",
1749 [TEGRA_POWERGATE_CPU2] = "cpu2",
1750 [TEGRA_POWERGATE_CPU3] = "cpu3",
1751 [TEGRA_POWERGATE_CELP] = "celp",
1752 [TEGRA_POWERGATE_3D1] = "3d1",
1755 static const u8 tegra30_cpu_powergates[] = {
1756 TEGRA_POWERGATE_CPU,
1757 TEGRA_POWERGATE_CPU1,
1758 TEGRA_POWERGATE_CPU2,
1759 TEGRA_POWERGATE_CPU3,
1762 static const struct tegra_pmc_soc tegra30_pmc_soc = {
1763 .num_powergates = ARRAY_SIZE(tegra30_powergates),
1764 .powergates = tegra30_powergates,
1765 .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
1766 .cpu_powergates = tegra30_cpu_powergates,
1767 .has_tsense_reset = true,
1768 .has_gpu_clamps = false,
1769 .has_impl_33v_pwr = false,
1774 .regs = &tegra20_pmc_regs,
1775 .init = tegra20_pmc_init,
1776 .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
1779 static const char * const tegra114_powergates[] = {
1780 [TEGRA_POWERGATE_CPU] = "crail",
1781 [TEGRA_POWERGATE_3D] = "3d",
1782 [TEGRA_POWERGATE_VENC] = "venc",
1783 [TEGRA_POWERGATE_VDEC] = "vdec",
1784 [TEGRA_POWERGATE_MPE] = "mpe",
1785 [TEGRA_POWERGATE_HEG] = "heg",
1786 [TEGRA_POWERGATE_CPU1] = "cpu1",
1787 [TEGRA_POWERGATE_CPU2] = "cpu2",
1788 [TEGRA_POWERGATE_CPU3] = "cpu3",
1789 [TEGRA_POWERGATE_CELP] = "celp",
1790 [TEGRA_POWERGATE_CPU0] = "cpu0",
1791 [TEGRA_POWERGATE_C0NC] = "c0nc",
1792 [TEGRA_POWERGATE_C1NC] = "c1nc",
1793 [TEGRA_POWERGATE_DIS] = "dis",
1794 [TEGRA_POWERGATE_DISB] = "disb",
1795 [TEGRA_POWERGATE_XUSBA] = "xusba",
1796 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1797 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1800 static const u8 tegra114_cpu_powergates[] = {
1801 TEGRA_POWERGATE_CPU0,
1802 TEGRA_POWERGATE_CPU1,
1803 TEGRA_POWERGATE_CPU2,
1804 TEGRA_POWERGATE_CPU3,
1807 static const struct tegra_pmc_soc tegra114_pmc_soc = {
1808 .num_powergates = ARRAY_SIZE(tegra114_powergates),
1809 .powergates = tegra114_powergates,
1810 .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
1811 .cpu_powergates = tegra114_cpu_powergates,
1812 .has_tsense_reset = true,
1813 .has_gpu_clamps = false,
1814 .has_impl_33v_pwr = false,
1819 .regs = &tegra20_pmc_regs,
1820 .init = tegra20_pmc_init,
1821 .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
1824 static const char * const tegra124_powergates[] = {
1825 [TEGRA_POWERGATE_CPU] = "crail",
1826 [TEGRA_POWERGATE_3D] = "3d",
1827 [TEGRA_POWERGATE_VENC] = "venc",
1828 [TEGRA_POWERGATE_PCIE] = "pcie",
1829 [TEGRA_POWERGATE_VDEC] = "vdec",
1830 [TEGRA_POWERGATE_MPE] = "mpe",
1831 [TEGRA_POWERGATE_HEG] = "heg",
1832 [TEGRA_POWERGATE_SATA] = "sata",
1833 [TEGRA_POWERGATE_CPU1] = "cpu1",
1834 [TEGRA_POWERGATE_CPU2] = "cpu2",
1835 [TEGRA_POWERGATE_CPU3] = "cpu3",
1836 [TEGRA_POWERGATE_CELP] = "celp",
1837 [TEGRA_POWERGATE_CPU0] = "cpu0",
1838 [TEGRA_POWERGATE_C0NC] = "c0nc",
1839 [TEGRA_POWERGATE_C1NC] = "c1nc",
1840 [TEGRA_POWERGATE_SOR] = "sor",
1841 [TEGRA_POWERGATE_DIS] = "dis",
1842 [TEGRA_POWERGATE_DISB] = "disb",
1843 [TEGRA_POWERGATE_XUSBA] = "xusba",
1844 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1845 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1846 [TEGRA_POWERGATE_VIC] = "vic",
1847 [TEGRA_POWERGATE_IRAM] = "iram",
1850 static const u8 tegra124_cpu_powergates[] = {
1851 TEGRA_POWERGATE_CPU0,
1852 TEGRA_POWERGATE_CPU1,
1853 TEGRA_POWERGATE_CPU2,
1854 TEGRA_POWERGATE_CPU3,
1857 #define TEGRA_IO_PAD(_id, _dpd, _voltage, _name) \
1858 ((struct tegra_io_pad_soc) { \
1861 .voltage = (_voltage), \
1865 #define TEGRA_IO_PIN_DESC(_id, _dpd, _voltage, _name) \
1866 ((struct pinctrl_pin_desc) { \
1871 #define TEGRA124_IO_PAD_TABLE(_pad) \
1872 /* .id .dpd .voltage .name */ \
1873 _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \
1874 _pad(TEGRA_IO_PAD_BB, 15, UINT_MAX, "bb"), \
1875 _pad(TEGRA_IO_PAD_CAM, 36, UINT_MAX, "cam"), \
1876 _pad(TEGRA_IO_PAD_COMP, 22, UINT_MAX, "comp"), \
1877 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
1878 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csb"), \
1879 _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "cse"), \
1880 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
1881 _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \
1882 _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \
1883 _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \
1884 _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \
1885 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
1886 _pad(TEGRA_IO_PAD_HV, 38, UINT_MAX, "hv"), \
1887 _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \
1888 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
1889 _pad(TEGRA_IO_PAD_NAND, 13, UINT_MAX, "nand"), \
1890 _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \
1891 _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \
1892 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
1893 _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \
1894 _pad(TEGRA_IO_PAD_SDMMC1, 33, UINT_MAX, "sdmmc1"), \
1895 _pad(TEGRA_IO_PAD_SDMMC3, 34, UINT_MAX, "sdmmc3"), \
1896 _pad(TEGRA_IO_PAD_SDMMC4, 35, UINT_MAX, "sdmmc4"), \
1897 _pad(TEGRA_IO_PAD_SYS_DDC, 58, UINT_MAX, "sys_ddc"), \
1898 _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \
1899 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
1900 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
1901 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
1902 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb_bias")
1904 static const struct tegra_io_pad_soc tegra124_io_pads[] = {
1905 TEGRA124_IO_PAD_TABLE(TEGRA_IO_PAD)
1908 static const struct pinctrl_pin_desc tegra124_pin_descs[] = {
1909 TEGRA124_IO_PAD_TABLE(TEGRA_IO_PIN_DESC)
1912 static const struct tegra_pmc_soc tegra124_pmc_soc = {
1913 .num_powergates = ARRAY_SIZE(tegra124_powergates),
1914 .powergates = tegra124_powergates,
1915 .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
1916 .cpu_powergates = tegra124_cpu_powergates,
1917 .has_tsense_reset = true,
1918 .has_gpu_clamps = true,
1919 .has_impl_33v_pwr = false,
1920 .num_io_pads = ARRAY_SIZE(tegra124_io_pads),
1921 .io_pads = tegra124_io_pads,
1922 .num_pin_descs = ARRAY_SIZE(tegra124_pin_descs),
1923 .pin_descs = tegra124_pin_descs,
1924 .regs = &tegra20_pmc_regs,
1925 .init = tegra20_pmc_init,
1926 .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
1929 static const char * const tegra210_powergates[] = {
1930 [TEGRA_POWERGATE_CPU] = "crail",
1931 [TEGRA_POWERGATE_3D] = "3d",
1932 [TEGRA_POWERGATE_VENC] = "venc",
1933 [TEGRA_POWERGATE_PCIE] = "pcie",
1934 [TEGRA_POWERGATE_MPE] = "mpe",
1935 [TEGRA_POWERGATE_SATA] = "sata",
1936 [TEGRA_POWERGATE_CPU1] = "cpu1",
1937 [TEGRA_POWERGATE_CPU2] = "cpu2",
1938 [TEGRA_POWERGATE_CPU3] = "cpu3",
1939 [TEGRA_POWERGATE_CPU0] = "cpu0",
1940 [TEGRA_POWERGATE_C0NC] = "c0nc",
1941 [TEGRA_POWERGATE_SOR] = "sor",
1942 [TEGRA_POWERGATE_DIS] = "dis",
1943 [TEGRA_POWERGATE_DISB] = "disb",
1944 [TEGRA_POWERGATE_XUSBA] = "xusba",
1945 [TEGRA_POWERGATE_XUSBB] = "xusbb",
1946 [TEGRA_POWERGATE_XUSBC] = "xusbc",
1947 [TEGRA_POWERGATE_VIC] = "vic",
1948 [TEGRA_POWERGATE_IRAM] = "iram",
1949 [TEGRA_POWERGATE_NVDEC] = "nvdec",
1950 [TEGRA_POWERGATE_NVJPG] = "nvjpg",
1951 [TEGRA_POWERGATE_AUD] = "aud",
1952 [TEGRA_POWERGATE_DFD] = "dfd",
1953 [TEGRA_POWERGATE_VE2] = "ve2",
1956 static const u8 tegra210_cpu_powergates[] = {
1957 TEGRA_POWERGATE_CPU0,
1958 TEGRA_POWERGATE_CPU1,
1959 TEGRA_POWERGATE_CPU2,
1960 TEGRA_POWERGATE_CPU3,
1963 #define TEGRA210_IO_PAD_TABLE(_pad) \
1964 /* .id .dpd .voltage .name */ \
1965 _pad(TEGRA_IO_PAD_AUDIO, 17, 5, "audio"), \
1966 _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 18, "audio-hv"), \
1967 _pad(TEGRA_IO_PAD_CAM, 36, 10, "cam"), \
1968 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
1969 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \
1970 _pad(TEGRA_IO_PAD_CSIC, 42, UINT_MAX, "csic"), \
1971 _pad(TEGRA_IO_PAD_CSID, 43, UINT_MAX, "csid"), \
1972 _pad(TEGRA_IO_PAD_CSIE, 44, UINT_MAX, "csie"), \
1973 _pad(TEGRA_IO_PAD_CSIF, 45, UINT_MAX, "csif"), \
1974 _pad(TEGRA_IO_PAD_DBG, 25, 19, "dbg"), \
1975 _pad(TEGRA_IO_PAD_DEBUG_NONAO, 26, UINT_MAX, "debug-nonao"), \
1976 _pad(TEGRA_IO_PAD_DMIC, 50, 20, "dmic"), \
1977 _pad(TEGRA_IO_PAD_DP, 51, UINT_MAX, "dp"), \
1978 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
1979 _pad(TEGRA_IO_PAD_DSIB, 39, UINT_MAX, "dsib"), \
1980 _pad(TEGRA_IO_PAD_DSIC, 40, UINT_MAX, "dsic"), \
1981 _pad(TEGRA_IO_PAD_DSID, 41, UINT_MAX, "dsid"), \
1982 _pad(TEGRA_IO_PAD_EMMC, 35, UINT_MAX, "emmc"), \
1983 _pad(TEGRA_IO_PAD_EMMC2, 37, UINT_MAX, "emmc2"), \
1984 _pad(TEGRA_IO_PAD_GPIO, 27, 21, "gpio"), \
1985 _pad(TEGRA_IO_PAD_HDMI, 28, UINT_MAX, "hdmi"), \
1986 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
1987 _pad(TEGRA_IO_PAD_LVDS, 57, UINT_MAX, "lvds"), \
1988 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
1989 _pad(TEGRA_IO_PAD_PEX_BIAS, 4, UINT_MAX, "pex-bias"), \
1990 _pad(TEGRA_IO_PAD_PEX_CLK1, 5, UINT_MAX, "pex-clk1"), \
1991 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
1992 _pad(TEGRA_IO_PAD_PEX_CNTRL, UINT_MAX, 11, "pex-cntrl"), \
1993 _pad(TEGRA_IO_PAD_SDMMC1, 33, 12, "sdmmc1"), \
1994 _pad(TEGRA_IO_PAD_SDMMC3, 34, 13, "sdmmc3"), \
1995 _pad(TEGRA_IO_PAD_SPI, 46, 22, "spi"), \
1996 _pad(TEGRA_IO_PAD_SPI_HV, 47, 23, "spi-hv"), \
1997 _pad(TEGRA_IO_PAD_UART, 14, 2, "uart"), \
1998 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
1999 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
2000 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
2001 _pad(TEGRA_IO_PAD_USB3, 18, UINT_MAX, "usb3"), \
2002 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias")
2004 static const struct tegra_io_pad_soc tegra210_io_pads[] = {
2005 TEGRA210_IO_PAD_TABLE(TEGRA_IO_PAD)
2008 static const struct pinctrl_pin_desc tegra210_pin_descs[] = {
2009 TEGRA210_IO_PAD_TABLE(TEGRA_IO_PIN_DESC)
2012 static const struct tegra_pmc_soc tegra210_pmc_soc = {
2013 .num_powergates = ARRAY_SIZE(tegra210_powergates),
2014 .powergates = tegra210_powergates,
2015 .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
2016 .cpu_powergates = tegra210_cpu_powergates,
2017 .has_tsense_reset = true,
2018 .has_gpu_clamps = true,
2019 .has_impl_33v_pwr = false,
2020 .needs_mbist_war = true,
2021 .num_io_pads = ARRAY_SIZE(tegra210_io_pads),
2022 .io_pads = tegra210_io_pads,
2023 .num_pin_descs = ARRAY_SIZE(tegra210_pin_descs),
2024 .pin_descs = tegra210_pin_descs,
2025 .regs = &tegra20_pmc_regs,
2026 .init = tegra20_pmc_init,
2027 .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
2030 #define TEGRA186_IO_PAD_TABLE(_pad) \
2031 /* .id .dpd .voltage .name */ \
2032 _pad(TEGRA_IO_PAD_CSIA, 0, UINT_MAX, "csia"), \
2033 _pad(TEGRA_IO_PAD_CSIB, 1, UINT_MAX, "csib"), \
2034 _pad(TEGRA_IO_PAD_DSI, 2, UINT_MAX, "dsi"), \
2035 _pad(TEGRA_IO_PAD_MIPI_BIAS, 3, UINT_MAX, "mipi-bias"), \
2036 _pad(TEGRA_IO_PAD_PEX_CLK_BIAS, 4, UINT_MAX, "pex-clk-bias"), \
2037 _pad(TEGRA_IO_PAD_PEX_CLK3, 5, UINT_MAX, "pex-clk3"), \
2038 _pad(TEGRA_IO_PAD_PEX_CLK2, 6, UINT_MAX, "pex-clk2"), \
2039 _pad(TEGRA_IO_PAD_PEX_CLK1, 7, UINT_MAX, "pex-clk1"), \
2040 _pad(TEGRA_IO_PAD_USB0, 9, UINT_MAX, "usb0"), \
2041 _pad(TEGRA_IO_PAD_USB1, 10, UINT_MAX, "usb1"), \
2042 _pad(TEGRA_IO_PAD_USB2, 11, UINT_MAX, "usb2"), \
2043 _pad(TEGRA_IO_PAD_USB_BIAS, 12, UINT_MAX, "usb-bias"), \
2044 _pad(TEGRA_IO_PAD_UART, 14, UINT_MAX, "uart"), \
2045 _pad(TEGRA_IO_PAD_AUDIO, 17, UINT_MAX, "audio"), \
2046 _pad(TEGRA_IO_PAD_HSIC, 19, UINT_MAX, "hsic"), \
2047 _pad(TEGRA_IO_PAD_DBG, 25, UINT_MAX, "dbg"), \
2048 _pad(TEGRA_IO_PAD_HDMI_DP0, 28, UINT_MAX, "hdmi-dp0"), \
2049 _pad(TEGRA_IO_PAD_HDMI_DP1, 29, UINT_MAX, "hdmi-dp1"), \
2050 _pad(TEGRA_IO_PAD_PEX_CNTRL, 32, UINT_MAX, "pex-cntrl"), \
2051 _pad(TEGRA_IO_PAD_SDMMC2_HV, 34, 5, "sdmmc2-hv"), \
2052 _pad(TEGRA_IO_PAD_SDMMC4, 36, UINT_MAX, "sdmmc4"), \
2053 _pad(TEGRA_IO_PAD_CAM, 38, UINT_MAX, "cam"), \
2054 _pad(TEGRA_IO_PAD_DSIB, 40, UINT_MAX, "dsib"), \
2055 _pad(TEGRA_IO_PAD_DSIC, 41, UINT_MAX, "dsic"), \
2056 _pad(TEGRA_IO_PAD_DSID, 42, UINT_MAX, "dsid"), \
2057 _pad(TEGRA_IO_PAD_CSIC, 43, UINT_MAX, "csic"), \
2058 _pad(TEGRA_IO_PAD_CSID, 44, UINT_MAX, "csid"), \
2059 _pad(TEGRA_IO_PAD_CSIE, 45, UINT_MAX, "csie"), \
2060 _pad(TEGRA_IO_PAD_CSIF, 46, UINT_MAX, "csif"), \
2061 _pad(TEGRA_IO_PAD_SPI, 47, UINT_MAX, "spi"), \
2062 _pad(TEGRA_IO_PAD_UFS, 49, UINT_MAX, "ufs"), \
2063 _pad(TEGRA_IO_PAD_DMIC_HV, 52, 2, "dmic-hv"), \
2064 _pad(TEGRA_IO_PAD_EDP, 53, UINT_MAX, "edp"), \
2065 _pad(TEGRA_IO_PAD_SDMMC1_HV, 55, 4, "sdmmc1-hv"), \
2066 _pad(TEGRA_IO_PAD_SDMMC3_HV, 56, 6, "sdmmc3-hv"), \
2067 _pad(TEGRA_IO_PAD_CONN, 60, UINT_MAX, "conn"), \
2068 _pad(TEGRA_IO_PAD_AUDIO_HV, 61, 1, "audio-hv"), \
2069 _pad(TEGRA_IO_PAD_AO_HV, UINT_MAX, 0, "ao-hv")
2071 static const struct tegra_io_pad_soc tegra186_io_pads[] = {
2072 TEGRA186_IO_PAD_TABLE(TEGRA_IO_PAD)
2075 static const struct pinctrl_pin_desc tegra186_pin_descs[] = {
2076 TEGRA186_IO_PAD_TABLE(TEGRA_IO_PIN_DESC)
2079 static const struct tegra_pmc_regs tegra186_pmc_regs = {
2084 .dpd2_status = 0x80,
2087 static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
2088 struct device_node *np,
2091 struct resource regs;
2096 index = of_property_match_string(np, "reg-names", "wake");
2098 pr_err("failed to find PMC wake registers\n");
2102 of_address_to_resource(np, index, ®s);
2104 wake = ioremap_nocache(regs.start, resource_size(®s));
2106 pr_err("failed to map PMC wake registers\n");
2110 value = readl(wake + WAKE_AOWAKE_CTRL);
2113 value |= WAKE_AOWAKE_CTRL_INTR_POLARITY;
2115 value &= ~WAKE_AOWAKE_CTRL_INTR_POLARITY;
2117 writel(value, wake + WAKE_AOWAKE_CTRL);
2122 static const struct tegra_pmc_soc tegra186_pmc_soc = {
2123 .num_powergates = 0,
2125 .num_cpu_powergates = 0,
2126 .cpu_powergates = NULL,
2127 .has_tsense_reset = false,
2128 .has_gpu_clamps = false,
2129 .has_impl_33v_pwr = true,
2130 .num_io_pads = ARRAY_SIZE(tegra186_io_pads),
2131 .io_pads = tegra186_io_pads,
2132 .num_pin_descs = ARRAY_SIZE(tegra186_pin_descs),
2133 .pin_descs = tegra186_pin_descs,
2134 .regs = &tegra186_pmc_regs,
2136 .setup_irq_polarity = tegra186_pmc_setup_irq_polarity,
2139 static const struct of_device_id tegra_pmc_match[] = {
2140 { .compatible = "nvidia,tegra194-pmc", .data = &tegra186_pmc_soc },
2141 { .compatible = "nvidia,tegra186-pmc", .data = &tegra186_pmc_soc },
2142 { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
2143 { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
2144 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
2145 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
2146 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
2147 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
2151 static struct platform_driver tegra_pmc_driver = {
2153 .name = "tegra-pmc",
2154 .suppress_bind_attrs = true,
2155 .of_match_table = tegra_pmc_match,
2156 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
2157 .pm = &tegra_pmc_pm_ops,
2160 .probe = tegra_pmc_probe,
2162 builtin_platform_driver(tegra_pmc_driver);
2165 * Early initialization to allow access to registers in the very early boot
2168 static int __init tegra_pmc_early_init(void)
2170 const struct of_device_id *match;
2171 struct device_node *np;
2172 struct resource regs;
2175 mutex_init(&pmc->powergates_lock);
2177 np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
2180 * Fall back to legacy initialization for 32-bit ARM only. All
2181 * 64-bit ARM device tree files for Tegra are required to have
2184 * This is for backwards-compatibility with old device trees
2185 * that didn't contain a PMC node. Note that in this case the
2186 * SoC data can't be matched and therefore powergating is
2189 if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
2190 pr_warn("DT node not found, powergating disabled\n");
2192 regs.start = 0x7000e400;
2193 regs.end = 0x7000e7ff;
2194 regs.flags = IORESOURCE_MEM;
2196 pr_warn("Using memory region %pR\n", ®s);
2199 * At this point we're not running on Tegra, so play
2200 * nice with multi-platform kernels.
2206 * Extract information from the device tree if we've found a
2209 if (of_address_to_resource(np, 0, ®s) < 0) {
2210 pr_err("failed to get PMC registers\n");
2216 pmc->base = ioremap_nocache(regs.start, resource_size(®s));
2218 pr_err("failed to map PMC registers\n");
2224 pmc->soc = match->data;
2226 tegra_powergate_init(pmc, np);
2229 * Invert the interrupt polarity if a PMC device tree node
2230 * exists and contains the nvidia,invert-interrupt property.
2232 invert = of_property_read_bool(np, "nvidia,invert-interrupt");
2234 pmc->soc->setup_irq_polarity(pmc, np, invert);
2241 early_initcall(tegra_pmc_early_init);