Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <soc/addressmap.h> |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 6 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 7 | #include <soc/flow.h> |
| 8 | #include <soc/pmc.h> |
| 9 | #include <soc/power.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 10 | |
Elyes Haouas | 0657590 | 2024-06-28 10:15:59 +0200 | [diff] [blame^] | 11 | static struct tegra_pmc_regs *const pmc = (void *)TEGRA_PMC_BASE; |
| 12 | static struct flow_ctlr *const flow = (void *)TEGRA_FLOW_BASE; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 13 | |
| 14 | static int partition_powered(int id) |
| 15 | { |
| 16 | return read32(&pmc->pwrgate_status) & (0x1 << id); |
| 17 | } |
| 18 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 19 | static int partition_clamp_on(int id) |
| 20 | { |
| 21 | return read32(&pmc->clamp_status) & (0x1 << id); |
| 22 | } |
| 23 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 24 | static void power_ungate_partition(uint32_t id) |
| 25 | { |
| 26 | printk(BIOS_INFO, "Ungating power partition %d.\n", id); |
| 27 | |
| 28 | if (!partition_powered(id)) { |
| 29 | uint32_t pwrgate_toggle = read32(&pmc->pwrgate_toggle); |
| 30 | pwrgate_toggle &= ~(PMC_PWRGATE_TOGGLE_PARTID_MASK); |
| 31 | pwrgate_toggle |= (id << PMC_PWRGATE_TOGGLE_PARTID_SHIFT); |
| 32 | pwrgate_toggle |= PMC_PWRGATE_TOGGLE_START; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 33 | write32(&pmc->pwrgate_toggle, pwrgate_toggle); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 34 | |
| 35 | // Wait for the request to be accepted. |
| 36 | while (read32(&pmc->pwrgate_toggle) & PMC_PWRGATE_TOGGLE_START) |
| 37 | ; |
| 38 | printk(BIOS_DEBUG, "Power gate toggle request accepted.\n"); |
| 39 | |
| 40 | // Wait for the partition to be powered. |
| 41 | while (!partition_powered(id)) |
| 42 | ; |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 43 | |
| 44 | // Wait for clamp off. |
| 45 | while (partition_clamp_on(id)) |
| 46 | ; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | printk(BIOS_INFO, "Ungated power partition %d.\n", id); |
| 50 | } |
| 51 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 52 | void power_enable_and_ungate_cpu(void) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 53 | { |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 54 | /* |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 55 | * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (150MHz), |
| 56 | * set it for 5ms as per SysEng (5ms * PCLK_KHZ * 1000 / 1s). |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 57 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 58 | write32(&pmc->cpupwrgood_timer, (TEGRA_PCLK_KHZ * 5)); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 59 | |
| 60 | uint32_t cntrl = read32(&pmc->cntrl); |
| 61 | cntrl &= ~PMC_CNTRL_CPUPWRREQ_POLARITY; |
| 62 | cntrl |= PMC_CNTRL_CPUPWRREQ_OE; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 63 | write32(&pmc->cntrl, cntrl); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 64 | |
Jimmy Zhang | b365530 | 2014-07-02 17:45:18 -0700 | [diff] [blame] | 65 | power_ungate_partition(POWER_PARTID_CRAIL); |
| 66 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 67 | // Ungate power to the non-core parts of the fast cluster. |
| 68 | power_ungate_partition(POWER_PARTID_C0NC); |
| 69 | |
| 70 | // Ungate power to CPU0 in the fast cluster. |
| 71 | power_ungate_partition(POWER_PARTID_CE0); |
| 72 | } |
Gabe Black | 4dc3e28 | 2014-05-06 15:33:37 -0700 | [diff] [blame] | 73 | |
| 74 | int power_reset_status(void) |
| 75 | { |
| 76 | return read32(&pmc->rst_status) & 0x7; |
| 77 | } |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 78 | |
| 79 | void ram_repair(void) |
| 80 | { |
| 81 | // Request RAM repair for cluster 0 |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 82 | setbits32(&flow->ram_repair, RAM_REPAIR_REQ); |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 83 | // Poll for completion |
| 84 | while (!(read32(&flow->ram_repair) & RAM_REPAIR_STS)) |
| 85 | ; |
| 86 | // Request RAM repair for cluster 1 |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 87 | setbits32(&flow->ram_repair_cluster1, RAM_REPAIR_REQ); |
Yen Lin | 5840626 | 2014-07-10 11:46:10 -0700 | [diff] [blame] | 88 | // Poll for completion |
| 89 | while (!(read32(&flow->ram_repair_cluster1) & RAM_REPAIR_STS)) |
| 90 | ; |
| 91 | } |