blob: 3f1ee7ee95a0da1a317ec01fa310a89aa273aaed [file] [log] [blame]
Gabe Blackd40be112013-10-09 23:45:07 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google Inc.
5 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Gabe Blackd40be112013-10-09 23:45:07 -070015 */
16
Kyösti Mälkki13f66502019-03-03 08:01:05 +020017#include <device/mmio.h>
Gabe Blackd40be112013-10-09 23:45:07 -070018#include <console/console.h>
19#include <soc/addressmap.h>
Jimmy Zhangb3655302014-07-02 17:45:18 -070020#include <soc/clock.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070021#include <soc/flow.h>
22#include <soc/pmc.h>
23#include <soc/power.h>
Gabe Blackd40be112013-10-09 23:45:07 -070024
25static struct tegra_pmc_regs * const pmc = (void *)TEGRA_PMC_BASE;
Yen Lin58406262014-07-10 11:46:10 -070026static struct flow_ctlr * const flow = (void *)TEGRA_FLOW_BASE;
Gabe Blackd40be112013-10-09 23:45:07 -070027
28static int partition_powered(int id)
29{
30 return read32(&pmc->pwrgate_status) & (0x1 << id);
31}
32
Jimmy Zhangb3655302014-07-02 17:45:18 -070033static int partition_clamp_on(int id)
34{
35 return read32(&pmc->clamp_status) & (0x1 << id);
36}
37
Gabe Blackd40be112013-10-09 23:45:07 -070038static void power_ungate_partition(uint32_t id)
39{
40 printk(BIOS_INFO, "Ungating power partition %d.\n", id);
41
42 if (!partition_powered(id)) {
43 uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle);
44 pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK);
45 pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT);
46 pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START;
Julius Werner2f37bd62015-02-19 14:51:15 -080047 write32(&pmc->pwrgate_toggle, pwrgate_toggle);
Gabe Blackd40be112013-10-09 23:45:07 -070048
49 // Wait for the request to be accepted.
50 while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START)
51 ;
52 printk(BIOS_DEBUG, "Power gate toggle request accepted.\n");
53
54 // Wait for the partition to be powered.
55 while (!partition_powered(id))
56 ;
Jimmy Zhangb3655302014-07-02 17:45:18 -070057
58 // Wait for clamp off.
59 while (partition_clamp_on(id))
60 ;
Gabe Blackd40be112013-10-09 23:45:07 -070061 }
62
63 printk(BIOS_INFO, "Ungated power partition %d.\n", id);
64}
65
Jimmy Zhangb3655302014-07-02 17:45:18 -070066void power_enable_and_ungate_cpu(void)
Gabe Blackd40be112013-10-09 23:45:07 -070067{
Gabe Blackd40be112013-10-09 23:45:07 -070068 /*
Jimmy Zhangb3655302014-07-02 17:45:18 -070069 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz),
70 * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s).
Gabe Blackd40be112013-10-09 23:45:07 -070071 */
Julius Werner2f37bd62015-02-19 14:51:15 -080072 write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5));
Gabe Blackd40be112013-10-09 23:45:07 -070073
74 uint32_t cntrl = read32(&pmc->cntrl);
75 cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY;
76 cntrl |= PMC_CNTRL_CPUPWRREQ_OE;
Julius Werner2f37bd62015-02-19 14:51:15 -080077 write32(&pmc->cntrl, cntrl);
Gabe Blackd40be112013-10-09 23:45:07 -070078
Jimmy Zhangb3655302014-07-02 17:45:18 -070079 power_ungate_partition(POWER_PARTID_CRAIL);
80
Gabe Blackd40be112013-10-09 23:45:07 -070081 // Ungate power to the non-core parts of the fast cluster.
82 power_ungate_partition(POWER_PARTID_C0NC);
83
84 // Ungate power to CPU0 in the fast cluster.
85 power_ungate_partition(POWER_PARTID_CE0);
86}
Gabe Black4dc3e282014-05-06 15:33:37 -070087
88int power_reset_status(void)
89{
90 return read32(&pmc->rst_status) & 0x7;
91}
Yen Lin58406262014-07-10 11:46:10 -070092
93void ram_repair(void)
94{
95 // Request RAM repair for cluster 0
Julius Werner55009af2019-12-02 22:03:27 -080096 setbits32(&flow->ram_repair, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -070097 // Poll for completion
98 while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS))
99 ;
100 // Request RAM repair for cluster 1
Julius Werner55009af2019-12-02 22:03:27 -0800101 setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
Yen Lin58406262014-07-10 11:46:10 -0700102 // Poll for completion
103 while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS))
104 ;
105}