blob: 5a307b57bb0efd08854b19e945fec565e0a9bf2d [file] [log] [blame]
Aaron Durbin3aca2cd2014-06-30 16:37:13 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050014 */
15
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050016#include <arch/io.h>
17#include <cbfs.h>
Julius Werner96195ee2014-10-20 13:25:21 -070018#include <console/console.h>
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050019#include <soc/addressmap.h>
Furquan Shaikh68a672c2014-09-20 15:07:52 -070020#include <soc/clock.h>
Julius Werner96195ee2014-10-20 13:25:21 -070021#include <soc/clk_rst.h>
22#include <soc/ccplex.h>
Aaron Durbin4058d7b2014-08-22 10:24:27 -050023#include <soc/cpu.h>
Julius Werner96195ee2014-10-20 13:25:21 -070024#include <soc/flow.h>
25#include <soc/mc.h>
26#include <soc/pmc.h>
27#include <soc/power.h>
Aaron Durbin5626d8f2014-07-10 12:50:27 -050028#include <soc/romstage.h>
Julius Werner96195ee2014-10-20 13:25:21 -070029#include <string.h>
30#include <timer.h>
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050031
Aaron Durbind2907c12014-07-01 13:51:21 -050032#define PMC_REGS (void *)(uintptr_t)(TEGRA_PMC_BASE)
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050033#define MTS_FILE_NAME "mts"
34
Aaron Durbind2907c12014-07-01 13:51:21 -050035static int ccplex_start(void)
36{
Aaron Durbinb9894ef2014-09-23 16:33:21 -050037 struct stopwatch sw;
38 const long timeout_ms = 1500;
Aaron Durbind2907c12014-07-01 13:51:21 -050039 const uint32_t handshake_mask = 1;
40 const uint32_t cxreset1_mask = 1 << 21;
41 uint32_t reg;
42 struct tegra_pmc_regs * const pmc = PMC_REGS;
Aaron Durbind2907c12014-07-01 13:51:21 -050043
44 /* Set the handshake bit to be knocked down. */
Julius Werner2f37bd62015-02-19 14:51:15 -080045 write32(&pmc->scratch118, handshake_mask);
Aaron Durbind2907c12014-07-01 13:51:21 -050046
47 /* Assert nCXRSET[1] */
Furquan Shaikhba167252014-09-22 14:58:05 -070048 reg = read32(CLK_RST_REG(rst_cpu_cmplx_set));
Aaron Durbind2907c12014-07-01 13:51:21 -050049 reg |= cxreset1_mask;
Julius Werner2f37bd62015-02-19 14:51:15 -080050 write32(CLK_RST_REG(rst_cpu_cmplx_set), reg);
Aaron Durbind2907c12014-07-01 13:51:21 -050051
Aaron Durbinb9894ef2014-09-23 16:33:21 -050052 stopwatch_init_msecs_expire(&sw, timeout_ms);
Aaron Durbind2907c12014-07-01 13:51:21 -050053 while (1) {
54 reg = read32(&pmc->scratch118);
Aaron Durbind2907c12014-07-01 13:51:21 -050055
56 /* Wait for the bit to be knocked down. */
57 if ((reg & handshake_mask) != handshake_mask)
58 break;
59
Aaron Durbinb9894ef2014-09-23 16:33:21 -050060 if (stopwatch_expired(&sw)) {
Aaron Durbind2907c12014-07-01 13:51:21 -050061 printk(BIOS_DEBUG, "MTS handshake timeout.\n");
62 return -1;
63 }
64 }
65
Aaron Durbin4f9150b2014-09-24 09:13:14 -050066 printk(BIOS_DEBUG, "MTS handshake took %ld usecs.\n",
Aaron Durbinb9894ef2014-09-23 16:33:21 -050067 stopwatch_duration_usecs(&sw));
Aaron Durbind2907c12014-07-01 13:51:21 -050068
69 return 0;
70}
71
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050072int ccplex_load_mts(void)
73{
Aaron Durbin899d13d2015-05-15 23:39:23 -050074 ssize_t nread;
Aaron Durbin4f9150b2014-09-24 09:13:14 -050075 struct stopwatch sw;
Aaron Durbin37a5d152015-09-17 16:09:30 -050076 struct cbfsf mts_file;
Aaron Durbin899d13d2015-05-15 23:39:23 -050077 struct region_device fh;
Aaron Durbin4f9150b2014-09-24 09:13:14 -050078
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050079 /*
80 * MTS location is hard coded to this magic address. The hardware will
81 * take the MTS from this location and place it in the final resting
82 * place in the carveout region.
83 */
84 void * const mts = (void *)(uintptr_t)MTS_LOAD_ADDRESS;
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050085
Aaron Durbin4f9150b2014-09-24 09:13:14 -050086 stopwatch_init(&sw);
Aaron Durbin37a5d152015-09-17 16:09:30 -050087 if (cbfs_boot_locate(&mts_file, MTS_FILE_NAME, NULL)) {
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050088 printk(BIOS_DEBUG, "MTS file not found: %s\n", MTS_FILE_NAME);
89 return -1;
90 }
91
Aaron Durbin37a5d152015-09-17 16:09:30 -050092 cbfs_file_data(&fh, &mts_file);
93
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050094 /* Read MTS file into the carveout region. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050095 nread = rdev_readat(&fh, mts, 0, region_device_sz(&fh));
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050096
Aaron Durbin899d13d2015-05-15 23:39:23 -050097 if (nread != region_device_sz(&fh)) {
Aaron Durbin3aca2cd2014-06-30 16:37:13 -050098 printk(BIOS_DEBUG, "MTS bytes read (%zu) != file length(%u)!\n",
Aaron Durbin899d13d2015-05-15 23:39:23 -050099 nread, region_device_sz(&fh));
Aaron Durbin3aca2cd2014-06-30 16:37:13 -0500100 return -1;
101 }
102
Aaron Durbin4f9150b2014-09-24 09:13:14 -0500103 printk(BIOS_DEBUG, "MTS: %zu bytes loaded @ %p in %ld usecs.\n",
104 nread, mts, stopwatch_duration_usecs(&sw));
Aaron Durbin3aca2cd2014-06-30 16:37:13 -0500105
Aaron Durbind2907c12014-07-01 13:51:21 -0500106 return ccplex_start();
Aaron Durbin3aca2cd2014-06-30 16:37:13 -0500107}
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500108
109static void enable_cpu_clocks(void)
110{
Furquan Shaikh68a672c2014-09-20 15:07:52 -0700111 clock_enable(CLK_ENB_CPU, 0, 0, SET_CLK_ENB_CPUG_ENABLE |
112 SET_CLK_ENB_CPULP_ENABLE, 0, 0);
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500113}
114
115static void enable_cpu_power_partitions(void)
116{
117 /* Bring up fast cluster, non-CPU, CPU0, and CPU1 partitions. */
118 power_ungate_partition(POWER_PARTID_CRAIL);
119 power_ungate_partition(POWER_PARTID_C0NC);
120 power_ungate_partition(POWER_PARTID_CE0);
121 power_ungate_partition(POWER_PARTID_CE1);
122}
123
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500124static void request_ram_repair(void)
125{
126 struct flow_ctlr * const flow = (void *)(uintptr_t)TEGRA_FLOW_BASE;
127 const uint32_t req = 1 << 0;
128 const uint32_t sts = 1 << 1;
129 uint32_t reg;
Aaron Durbinb9894ef2014-09-23 16:33:21 -0500130 struct stopwatch sw;
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500131
132 printk(BIOS_DEBUG, "Requesting RAM repair.\n");
133
Yen Lin9b99d7b2015-01-07 17:04:15 -0800134 stopwatch_init(&sw);
135
136 /* Perform cluster 0 ram repair */
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500137 reg = read32(&flow->ram_repair);
138 reg |= req;
Julius Werner2f37bd62015-02-19 14:51:15 -0800139 write32(&flow->ram_repair, reg);
Aaron Durbinb9894ef2014-09-23 16:33:21 -0500140 while ((read32(&flow->ram_repair) & sts) != sts)
141 ;
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500142
Yen Lin9b99d7b2015-01-07 17:04:15 -0800143 /* Perform cluster 1 ram repair */
144 reg = read32(&flow->ram_repair_cluster1);
145 reg |= req;
Julius Werner2f37bd62015-02-19 14:51:15 -0800146 write32(&flow->ram_repair_cluster1, reg);
Yen Lin9b99d7b2015-01-07 17:04:15 -0800147 while ((read32(&flow->ram_repair_cluster1) & sts) != sts)
148 ;
149
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500150 printk(BIOS_DEBUG, "RAM repair complete in %ld usecs.\n",
Aaron Durbinb9894ef2014-09-23 16:33:21 -0500151 stopwatch_duration_usecs(&sw));
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500152}
153
154void ccplex_cpu_prepare(void)
155{
156 enable_cpu_clocks();
157 enable_cpu_power_partitions();
158
159 mainboard_configure_pmc();
160 mainboard_enable_vdd_cpu();
161
162 request_ram_repair();
163}
164
Aaron Durbin4058d7b2014-08-22 10:24:27 -0500165static void start_common_clocks(void)
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500166{
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500167 /* Clear fast CPU partition reset. */
Julius Werner2f37bd62015-02-19 14:51:15 -0800168 write32(CLK_RST_REG(rst_cpug_cmplx_clr), CRC_RST_CPUG_CLR_NONCPU);
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500169
Aaron Durbin4058d7b2014-08-22 10:24:27 -0500170 /* Clear reset of L2 and CoreSight components. */
Julius Werner2f37bd62015-02-19 14:51:15 -0800171 write32(CLK_RST_REG(rst_cpug_cmplx_clr),
172 CRC_RST_CPUG_CLR_L2 | CRC_RST_CPUG_CLR_PDBG);
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500173}
174
175void ccplex_cpu_start(void *entry_addr)
176{
Aaron Durbin4058d7b2014-08-22 10:24:27 -0500177 /* Enable common clocks for the shared resources between the cores. */
178 start_common_clocks();
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500179
Aaron Durbin4058d7b2014-08-22 10:24:27 -0500180 start_cpu(0, entry_addr);
Aaron Durbin5626d8f2014-07-10 12:50:27 -0500181}