Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 24 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 25 | #include <soc/flow.h> |
| 26 | #include <soc/pmc.h> |
| 27 | #include <soc/power.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 28 | |
| 29 | static struct tegra_pmc_regs * const pmc = (void *)TEGRA_PMC_BASE; |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 30 | static struct flow_ctlr * const flow = (void *)TEGRA_FLOW_BASE; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 31 | |
| 32 | static int partition_powered(int id) |
| 33 | { |
| 34 | return read32(&pmc->pwrgate_status) & (0x1 << id); |
| 35 | } |
| 36 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 37 | static int partition_clamp_on(int id) |
| 38 | { |
| 39 | return read32(&pmc->clamp_status) & (0x1 << id); |
| 40 | } |
| 41 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 42 | static void power_ungate_partition(uint32_t id) |
| 43 | { |
| 44 | printk(BIOS_INFO, "Ungating power partition %d.\n", id); |
| 45 | |
| 46 | if (!partition_powered(id)) { |
| 47 | uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle); |
| 48 | pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK); |
| 49 | pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT); |
| 50 | pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 51 | write32(&pmc->pwrgate_toggle, pwrgate_toggle); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 52 | |
| 53 | // Wait for the request to be accepted. |
| 54 | while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START) |
| 55 | ; |
| 56 | printk(BIOS_DEBUG, "Power gate toggle request accepted.\n"); |
| 57 | |
| 58 | // Wait for the partition to be powered. |
| 59 | while (!partition_powered(id)) |
| 60 | ; |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 61 | |
| 62 | // Wait for clamp off. |
| 63 | while (partition_clamp_on(id)) |
| 64 | ; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | printk(BIOS_INFO, "Ungated power partition %d.\n", id); |
| 68 | } |
| 69 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 70 | void power_enable_and_ungate_cpu(void) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 71 | { |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 72 | /* |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 73 | * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz), |
| 74 | * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s). |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 75 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 76 | write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5)); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 77 | |
| 78 | uint32_t cntrl = read32(&pmc->cntrl); |
| 79 | cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY; |
| 80 | cntrl |= PMC_CNTRL_CPUPWRREQ_OE; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 81 | write32(&pmc->cntrl, cntrl); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 82 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 83 | power_ungate_partition(POWER_PARTID_CRAIL); |
| 84 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 85 | // Ungate power to the non-core parts of the fast cluster. |
| 86 | power_ungate_partition(POWER_PARTID_C0NC); |
| 87 | |
| 88 | // Ungate power to CPU0 in the fast cluster. |
| 89 | power_ungate_partition(POWER_PARTID_CE0); |
| 90 | } |
Gabe Black | 4dc3e28 | 2014-05-06 15:33:37 -0700 | [diff] [blame] | 91 | |
| 92 | int power_reset_status(void) |
| 93 | { |
| 94 | return read32(&pmc->rst_status) & 0x7; |
| 95 | } |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 96 | |
| 97 | void ram_repair(void) |
| 98 | { |
| 99 | // Request RAM repair for cluster 0 |
| 100 | setbits_le32(&flow->ram_repair, RAM_REPAIR_REQ); |
| 101 | // Poll for completion |
| 102 | while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS)) |
| 103 | ; |
| 104 | // Request RAM repair for cluster 1 |
| 105 | setbits_le32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ); |
| 106 | // Poll for completion |
| 107 | while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS)) |
| 108 | ; |
| 109 | } |