Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 3 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <soc/addressmap.h> |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 7 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 8 | #include <soc/flow.h> |
| 9 | #include <soc/pmc.h> |
| 10 | #include <soc/power.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 11 | |
| 12 | static struct tegra_pmc_regs * const pmc = (void *)TEGRA_PMC_BASE; |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 13 | static struct flow_ctlr * const flow = (void *)TEGRA_FLOW_BASE; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 14 | |
| 15 | static int partition_powered(int id) |
| 16 | { |
| 17 | return read32(&pmc->pwrgate_status) & (0x1 << id); |
| 18 | } |
| 19 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 20 | static int partition_clamp_on(int id) |
| 21 | { |
| 22 | return read32(&pmc->clamp_status) & (0x1 << id); |
| 23 | } |
| 24 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 25 | static 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 Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 34 | write32(&pmc->pwrgate_toggle, pwrgate_toggle); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 35 | |
| 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 Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 44 | |
| 45 | // Wait for clamp off. |
| 46 | while (partition_clamp_on(id)) |
| 47 | ; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | printk(BIOS_INFO, "Ungated power partition %d.\n", id); |
| 51 | } |
| 52 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 53 | void power_enable_and_ungate_cpu(void) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 54 | { |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 55 | /* |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 56 | * 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 Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 58 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 59 | write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5)); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 60 | |
| 61 | uint32_t cntrl = read32(&pmc->cntrl); |
| 62 | cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY; |
| 63 | cntrl |= PMC_CNTRL_CPUPWRREQ_OE; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 64 | write32(&pmc->cntrl, cntrl); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 65 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 66 | power_ungate_partition(POWER_PARTID_CRAIL); |
| 67 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 68 | // 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 Black | 4dc3e28 | 2014-05-06 15:33:37 -0700 | [diff] [blame] | 74 | |
| 75 | int power_reset_status(void) |
| 76 | { |
| 77 | return read32(&pmc->rst_status) & 0x7; |
| 78 | } |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 79 | |
| 80 | void ram_repair(void) |
| 81 | { |
| 82 | // Request RAM repair for cluster 0 |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 83 | setbits32(&flow->ram_repair, RAM_REPAIR_REQ); |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 84 | // Poll for completion |
| 85 | while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS)) |
| 86 | ; |
| 87 | // Request RAM repair for cluster 1 |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 88 | setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ); |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 89 | // Poll for completion |
| 90 | while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS)) |
| 91 | ; |
| 92 | } |