Debian Codegraph @

src/soc/nvidia/tegra124/power.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <soc/addressmap.h>
6 #include <soc/clock.h>
7 #include <soc/flow.h>
8 #include <soc/pmc.h>
9 #include <soc/power.h>
10
11 static struct tegra_pmc_regs *const pmc = (void *)TEGRA_PMC_BASE;
12 static struct flow_ctlr *const flow = (void *)TEGRA_FLOW_BASE;
13
14 static int partition_powered(int id)
15 {
16 return read32(&pmc->pwrgate_status) & (0x1 << id);
17 }
18
19 static int partition_clamp_on(int id)
20 {
21 return read32(&pmc->clamp_status) & (0x1 << id);
22 }
23
24 static void power_ungate_partition(uint32_t id)
25 {
26 printk(BIOS_INFO, "Ungating power partition %d.\n", id);
27
28 if (!partition_powered(id)) {
29 uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle);
30 pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK);
31 pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT);
32 pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START;
33 write32(&pmc->pwrgate_toggle, pwrgate_toggle);
34
35 // Wait for the request to be accepted.
36 while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START)
37 ;
38 printk(BIOS_DEBUG, "Power gate toggle request accepted.\n");
39
40 // Wait for the partition to be powered.
41 while (!partition_powered(id))
42 ;
43
44 // Wait for clamp off.
45 while (partition_clamp_on(id))
46 ;
47 }
48
49 printk(BIOS_INFO, "Ungated power partition %d.\n", id);
50 }
51
52 void power_enable_and_ungate_cpu(void)
53 {
54 /*
55 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz),
56 * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s).
57 */
58 write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5));
59
60 uint32_t cntrl = read32(&pmc->cntrl);
61 cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY;
62 cntrl |= PMC_CNTRL_CPUPWRREQ_OE;
63 write32(&pmc->cntrl, cntrl);
64
65 power_ungate_partition(POWER_PARTID_CRAIL);
66
67 // Ungate power to the non-core parts of the fast cluster.
68 power_ungate_partition(POWER_PARTID_C0NC);
69
70 // Ungate power to CPU0 in the fast cluster.
71 power_ungate_partition(POWER_PARTID_CE0);
72 }
73
74 int power_reset_status(void)
75 {
76 return read32(&pmc->rst_status) & 0x7;
77 }
78
79 void ram_repair(void)
80 {
81 // Request RAM repair for cluster 0
82 setbits32(&flow->ram_repair, RAM_REPAIR_REQ);
83 // Poll for completion
84 while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS))
85 ;
86 // Request RAM repair for cluster 1
87 setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
88 // Poll for completion
89 while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS))
90 ;
91 }