blob: 8e9579c0dd623d7a028619a47803bf02b77bc70e [file] [log] [blame]
Angel Ponsa2ee7612020-04-04 18:51:15 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Gabe Blackd40be112013-10-09 23:45:07 -07002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Gabe Blackd40be112013-10-09 23:45:07 -07004#include <console/console.h>
5#include <soc/addressmap.h>
Jimmy Zhangb3655302014-07-02 17:45:18 -07006#include <soc/clock.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -07007#include <soc/flow.h>
8#include <soc/pmc.h>
9#include <soc/power.h>
Gabe Blackd40be112013-10-09 23:45:07 -070010
Elyes Haouas06575902024-06-28 10:15:59 +020011static struct tegra_pmc_regs *const pmc = (void *)TEGRA_PMC_BASE;
12static struct flow_ctlr *const flow = (void *)TEGRA_FLOW_BASE;
Gabe Blackd40be112013-10-09 23:45:07 -070013
14static int partition_powered(int id)
15{
16 return read32(&pmc->pwrgate_status) & (0x1 << id);
17}
18
Jimmy Zhangb3655302014-07-02 17:45:18 -070019static int partition_clamp_on(int id)
20{
21 return read32(&pmc->clamp_status) & (0x1 << id);
22}
23
Gabe Blackd40be112013-10-09 23:45:07 -070024static 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;
Julius Werner2f37bd62015-02-19 14:51:15 -080033 write32(&pmc->pwrgate_toggle, pwrgate_toggle);
Gabe Blackd40be112013-10-09 23:45:07 -070034
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 ;
Jimmy Zhangb3655302014-07-02 17:45:18 -070043
44 // Wait for clamp off.
45 while (partition_clamp_on(id))
46 ;
Gabe Blackd40be112013-10-09 23:45:07 -070047 }
48
49 printk(BIOS_INFO, "Ungated power partition %d.\n", id);
50}
51
Jimmy Zhangb3655302014-07-02 17:45:18 -070052void power_enable_and_ungate_cpu(void)
Gabe Blackd40be112013-10-09 23:45:07 -070053{
Gabe Blackd40be112013-10-09 23:45:07 -070054 /*
Jimmy Zhangb3655302014-07-02 17:45:18 -070055 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz),
56 * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s).
Gabe Blackd40be112013-10-09 23:45:07 -070057 */
Julius Werner2f37bd62015-02-19 14:51:15 -080058 write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5));
Gabe Blackd40be112013-10-09 23:45:07 -070059
60 uint32_t cntrl = read32(&pmc->cntrl);
61 cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY;
62 cntrl |= PMC_CNTRL_CPUPWRREQ_OE;
Julius Werner2f37bd62015-02-19 14:51:15 -080063 write32(&pmc->cntrl, cntrl);
Gabe Blackd40be112013-10-09 23:45:07 -070064
Jimmy Zhangb3655302014-07-02 17:45:18 -070065 power_ungate_partition(POWER_PARTID_CRAIL);
66
Gabe Blackd40be112013-10-09 23:45:07 -070067 // 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}
Gabe Black4dc3e282014-05-06 15:33:37 -070073
74int power_reset_status(void)
75{
76 return read32(&pmc->rst_status) & 0x7;
77}
Yen Lin58406262014-07-10 11:46:10 -070078
79void ram_repair(void)
80{
81 // Request RAM repair for cluster 0
Julius Werner55009af2019-12-02 22:03:27 -080082 setbits32(&flow->ram_repair, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -070083 // Poll for completion
84 while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS))
85 ;
86 // Request RAM repair for cluster 1
Julius Werner55009af2019-12-02 22:03:27 -080087 setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -070088 // Poll for completion
89 while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS))
90 ;
91}