blob: 6abc675aa081d4d1ea7a982961464570d5d27936 [file] [log] [blame]
Angel Ponsa2ee7612020-04-04 18:51:15 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Gabe Blackd40be112013-10-09 23:45:07 -07003
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Gabe Blackd40be112013-10-09 23:45:07 -07005#include <console/console.h>
6#include <soc/addressmap.h>
Jimmy Zhangb3655302014-07-02 17:45:18 -07007#include <soc/clock.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -07008#include <soc/flow.h>
9#include <soc/pmc.h>
10#include <soc/power.h>
Gabe Blackd40be112013-10-09 23:45:07 -070011
12static struct tegra_pmc_regs * const pmc = (void *)TEGRA_PMC_BASE;
Yen Lin58406262014-07-10 11:46:10 -070013static struct flow_ctlr * const flow = (void *)TEGRA_FLOW_BASE;
Gabe Blackd40be112013-10-09 23:45:07 -070014
15static int partition_powered(int id)
16{
17 return read32(&pmc->pwrgate_status) & (0x1 << id);
18}
19
Jimmy Zhangb3655302014-07-02 17:45:18 -070020static int partition_clamp_on(int id)
21{
22 return read32(&pmc->clamp_status) & (0x1 << id);
23}
24
Gabe Blackd40be112013-10-09 23:45:07 -070025static void power_ungate_partition(uint32_t id)
26{
27 printk(BIOS_INFO, "Ungating power partition %d.\n", id);
28
29 if (!partition_powered(id)) {
30 uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle);
31 pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK);
32 pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT);
33 pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START;
Julius Werner2f37bd62015-02-19 14:51:15 -080034 write32(&pmc->pwrgate_toggle, pwrgate_toggle);
Gabe Blackd40be112013-10-09 23:45:07 -070035
36 // Wait for the request to be accepted.
37 while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START)
38 ;
39 printk(BIOS_DEBUG, "Power gate toggle request accepted.\n");
40
41 // Wait for the partition to be powered.
42 while (!partition_powered(id))
43 ;
Jimmy Zhangb3655302014-07-02 17:45:18 -070044
45 // Wait for clamp off.
46 while (partition_clamp_on(id))
47 ;
Gabe Blackd40be112013-10-09 23:45:07 -070048 }
49
50 printk(BIOS_INFO, "Ungated power partition %d.\n", id);
51}
52
Jimmy Zhangb3655302014-07-02 17:45:18 -070053void power_enable_and_ungate_cpu(void)
Gabe Blackd40be112013-10-09 23:45:07 -070054{
Gabe Blackd40be112013-10-09 23:45:07 -070055 /*
Jimmy Zhangb3655302014-07-02 17:45:18 -070056 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz),
57 * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s).
Gabe Blackd40be112013-10-09 23:45:07 -070058 */
Julius Werner2f37bd62015-02-19 14:51:15 -080059 write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5));
Gabe Blackd40be112013-10-09 23:45:07 -070060
61 uint32_t cntrl = read32(&pmc->cntrl);
62 cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY;
63 cntrl |= PMC_CNTRL_CPUPWRREQ_OE;
Julius Werner2f37bd62015-02-19 14:51:15 -080064 write32(&pmc->cntrl, cntrl);
Gabe Blackd40be112013-10-09 23:45:07 -070065
Jimmy Zhangb3655302014-07-02 17:45:18 -070066 power_ungate_partition(POWER_PARTID_CRAIL);
67
Gabe Blackd40be112013-10-09 23:45:07 -070068 // Ungate power to the non-core parts of the fast cluster.
69 power_ungate_partition(POWER_PARTID_C0NC);
70
71 // Ungate power to CPU0 in the fast cluster.
72 power_ungate_partition(POWER_PARTID_CE0);
73}
Gabe Black4dc3e282014-05-06 15:33:37 -070074
75int power_reset_status(void)
76{
77 return read32(&pmc->rst_status) & 0x7;
78}
Yen Lin58406262014-07-10 11:46:10 -070079
80void ram_repair(void)
81{
82 // Request RAM repair for cluster 0
Julius Werner55009af2019-12-02 22:03:27 -080083 setbits32(&flow->ram_repair, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -070084 // Poll for completion
85 while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS))
86 ;
87 // Request RAM repair for cluster 1
Julius Werner55009af2019-12-02 22:03:27 -080088 setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -070089 // Poll for completion
90 while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS))
91 ;
92}