blob: 75f04942b9e81d5cb58ed646fe1c7b024d6f4f11 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <arch/io.h>
22#include <console/console.h>
23#include <soc/addressmap.h>
Jimmy Zhangb3655302014-07-02 17:45:18 -070024#include <soc/clock.h>
Gabe Blackd40be112013-10-09 23:45:07 -070025
26#include "pmc.h"
27#include "power.h"
Yen Lin58406262014-07-10 11:46:10 -070028#include "flow.h"
Gabe Blackd40be112013-10-09 23:45:07 -070029
30static struct tegra_pmc_regs * const pmc = (void *)TEGRA_PMC_BASE;
Yen Lin58406262014-07-10 11:46:10 -070031static struct flow_ctlr * const flow = (void *)TEGRA_FLOW_BASE;
Gabe Blackd40be112013-10-09 23:45:07 -070032
33static int partition_powered(int id)
34{
35 return read32(&pmc->pwrgate_status) & (0x1 << id);
36}
37
Jimmy Zhangb3655302014-07-02 17:45:18 -070038static int partition_clamp_on(int id)
39{
40 return read32(&pmc->clamp_status) & (0x1 << id);
41}
42
Gabe Blackd40be112013-10-09 23:45:07 -070043static void power_ungate_partition(uint32_t id)
44{
45 printk(BIOS_INFO, "Ungating power partition %d.\n", id);
46
47 if (!partition_powered(id)) {
48 uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle);
49 pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK);
50 pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT);
51 pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START;
52 write32(pwrgate_toggle, &pmc->pwrgate_toggle);
53
54 // Wait for the request to be accepted.
55 while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START)
56 ;
57 printk(BIOS_DEBUG, "Power gate toggle request accepted.\n");
58
59 // Wait for the partition to be powered.
60 while (!partition_powered(id))
61 ;
Jimmy Zhangb3655302014-07-02 17:45:18 -070062
63 // Wait for clamp off.
64 while (partition_clamp_on(id))
65 ;
Gabe Blackd40be112013-10-09 23:45:07 -070066 }
67
68 printk(BIOS_INFO, "Ungated power partition %d.\n", id);
69}
70
Jimmy Zhangb3655302014-07-02 17:45:18 -070071void power_enable_and_ungate_cpu(void)
Gabe Blackd40be112013-10-09 23:45:07 -070072{
Gabe Blackd40be112013-10-09 23:45:07 -070073 /*
Jimmy Zhangb3655302014-07-02 17:45:18 -070074 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz),
75 * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s).
Gabe Blackd40be112013-10-09 23:45:07 -070076 */
Jimmy Zhangb3655302014-07-02 17:45:18 -070077 write32((TEGRA_PCLK_KHZ * 5), &pmc->cpupwrgood_timer);
Gabe Blackd40be112013-10-09 23:45:07 -070078
79 uint32_t cntrl = read32(&pmc->cntrl);
80 cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY;
81 cntrl |= PMC_CNTRL_CPUPWRREQ_OE;
82 write32(cntrl, &pmc->cntrl);
Gabe Blackd40be112013-10-09 23:45:07 -070083
Jimmy Zhangb3655302014-07-02 17:45:18 -070084 power_ungate_partition(POWER_PARTID_CRAIL);
85
Gabe Blackd40be112013-10-09 23:45:07 -070086 // Ungate power to the non-core parts of the fast cluster.
87 power_ungate_partition(POWER_PARTID_C0NC);
88
89 // Ungate power to CPU0 in the fast cluster.
90 power_ungate_partition(POWER_PARTID_CE0);
91}
Gabe Black4dc3e282014-05-06 15:33:37 -070092
93int power_reset_status(void)
94{
95 return read32(&pmc->rst_status) & 0x7;
96}
Yen Lin58406262014-07-10 11:46:10 -070097
98void ram_repair(void)
99{
100 // Request RAM repair for cluster 0
101 setbits_le32(&flow->ram_repair, RAM_REPAIR_REQ);
102 // Poll for completion
103 while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS))
104 ;
105 // Request RAM repair for cluster 1
106 setbits_le32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ);
107 // Poll for completion
108 while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS))
109 ;
110}