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