plat_psci_handlers.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <assert.h>
  8. #include <cortex_a57.h>
  9. #include <arch_helpers.h>
  10. #include <common/debug.h>
  11. #include <drivers/delay_timer.h>
  12. #include <lib/mmio.h>
  13. #include <lib/psci/psci.h>
  14. #include <plat/common/platform.h>
  15. #include <bpmp.h>
  16. #include <flowctrl.h>
  17. #include <lib/utils.h>
  18. #include <memctrl.h>
  19. #include <pmc.h>
  20. #include <platform_def.h>
  21. #include <security_engine.h>
  22. #include <tegra_def.h>
  23. #include <tegra_private.h>
  24. #include <tegra_platform.h>
  25. /*
  26. * Register used to clear CPU reset signals. Each CPU has two reset
  27. * signals: CPU reset (3:0) and Core reset (19:16).
  28. */
  29. #define CPU_CMPLX_RESET_CLR 0x454
  30. #define CPU_CORE_RESET_MASK 0x10001
  31. /* Clock and Reset controller registers for system clock's settings */
  32. #define SCLK_RATE 0x30
  33. #define SCLK_BURST_POLICY 0x28
  34. #define SCLK_BURST_POLICY_DEFAULT 0x10000000
  35. static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER];
  36. static bool tegra_bpmp_available = true;
  37. int32_t tegra_soc_validate_power_state(unsigned int power_state,
  38. psci_power_state_t *req_state)
  39. {
  40. int state_id = psci_get_pstate_id(power_state);
  41. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  42. /* Sanity check the requested state id */
  43. switch (state_id) {
  44. case PSTATE_ID_CORE_POWERDN:
  45. /*
  46. * Core powerdown request only for afflvl 0
  47. */
  48. req_state->pwr_domain_state[MPIDR_AFFLVL0] = state_id & 0xff;
  49. break;
  50. case PSTATE_ID_CLUSTER_IDLE:
  51. /*
  52. * Cluster idle request for afflvl 0
  53. */
  54. req_state->pwr_domain_state[MPIDR_AFFLVL0] = PSTATE_ID_CORE_POWERDN;
  55. req_state->pwr_domain_state[MPIDR_AFFLVL1] = state_id;
  56. break;
  57. case PSTATE_ID_SOC_POWERDN:
  58. /*
  59. * sc7entry-fw must be present in the system when the bpmp
  60. * firmware is not present, for a successful System Suspend
  61. * entry.
  62. */
  63. if (!tegra_bpmp_init() && !plat_params->sc7entry_fw_base)
  64. return PSCI_E_NOT_SUPPORTED;
  65. /*
  66. * System powerdown request only for afflvl 2
  67. */
  68. for (uint32_t i = MPIDR_AFFLVL0; i < PLAT_MAX_PWR_LVL; i++)
  69. req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
  70. req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] =
  71. PLAT_SYS_SUSPEND_STATE_ID;
  72. break;
  73. default:
  74. ERROR("%s: unsupported state id (%d)\n", __func__, state_id);
  75. return PSCI_E_INVALID_PARAMS;
  76. }
  77. return PSCI_E_SUCCESS;
  78. }
  79. /*******************************************************************************
  80. * Platform handler to calculate the proper target power level at the
  81. * specified affinity level.
  82. ******************************************************************************/
  83. plat_local_state_t tegra_soc_get_target_pwr_state(unsigned int lvl,
  84. const plat_local_state_t *states,
  85. unsigned int ncpu)
  86. {
  87. plat_local_state_t target = PSCI_LOCAL_STATE_RUN;
  88. int cpu = plat_my_core_pos();
  89. int core_pos = read_mpidr() & MPIDR_CPU_MASK;
  90. uint32_t bpmp_reply, data[3], val;
  91. int ret;
  92. /* get the power state at this level */
  93. if (lvl == MPIDR_AFFLVL1)
  94. target = *(states + core_pos);
  95. if (lvl == MPIDR_AFFLVL2)
  96. target = *(states + cpu);
  97. if ((lvl == MPIDR_AFFLVL1) && (target == PSTATE_ID_CLUSTER_IDLE)) {
  98. /* initialize the bpmp interface */
  99. ret = tegra_bpmp_init();
  100. if (ret != 0U) {
  101. /*
  102. * flag to indicate that BPMP firmware is not
  103. * available and the CPU has to handle entry/exit
  104. * for all power states
  105. */
  106. tegra_bpmp_available = false;
  107. /* Cluster idle not allowed */
  108. target = PSCI_LOCAL_STATE_RUN;
  109. /*******************************************
  110. * BPMP is not present, so handle CC6 entry
  111. * from the CPU
  112. ******************************************/
  113. /* check if cluster idle state has been enabled */
  114. val = mmio_read_32(TEGRA_CL_DVFS_BASE + DVFS_DFLL_CTRL);
  115. if (val == ENABLE_CLOSED_LOOP) {
  116. /*
  117. * Acquire the cluster idle lock to stop
  118. * other CPUs from powering up.
  119. */
  120. tegra_fc_ccplex_pgexit_lock();
  121. /* Cluster idle only from the last standing CPU */
  122. if (tegra_pmc_is_last_on_cpu() && tegra_fc_is_ccx_allowed()) {
  123. /* Cluster idle allowed */
  124. target = PSTATE_ID_CLUSTER_IDLE;
  125. } else {
  126. /* release cluster idle lock */
  127. tegra_fc_ccplex_pgexit_unlock();
  128. }
  129. }
  130. } else {
  131. /* Cluster power-down */
  132. data[0] = (uint32_t)cpu;
  133. data[1] = TEGRA_PM_CC6;
  134. data[2] = TEGRA_PM_SC1;
  135. ret = tegra_bpmp_send_receive_atomic(MRQ_DO_IDLE,
  136. (void *)&data, (int)sizeof(data),
  137. (void *)&bpmp_reply,
  138. (int)sizeof(bpmp_reply));
  139. /* check if cluster power down is allowed */
  140. if ((ret != 0L) || (bpmp_reply != BPMP_CCx_ALLOWED)) {
  141. /* Cluster power down not allowed */
  142. target = PSCI_LOCAL_STATE_RUN;
  143. }
  144. }
  145. } else if (((lvl == MPIDR_AFFLVL2) || (lvl == MPIDR_AFFLVL1)) &&
  146. (target == PSTATE_ID_SOC_POWERDN)) {
  147. /* System Suspend */
  148. target = PSTATE_ID_SOC_POWERDN;
  149. } else {
  150. ; /* do nothing */
  151. }
  152. return target;
  153. }
  154. int32_t tegra_soc_cpu_standby(plat_local_state_t cpu_state)
  155. {
  156. (void)cpu_state;
  157. return PSCI_E_SUCCESS;
  158. }
  159. int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
  160. {
  161. u_register_t mpidr = read_mpidr();
  162. const plat_local_state_t *pwr_domain_state =
  163. target_state->pwr_domain_state;
  164. unsigned int stateid_afflvl2 = pwr_domain_state[MPIDR_AFFLVL2];
  165. unsigned int stateid_afflvl1 = pwr_domain_state[MPIDR_AFFLVL1];
  166. unsigned int stateid_afflvl0 = pwr_domain_state[MPIDR_AFFLVL0];
  167. uint32_t cfg;
  168. int ret = PSCI_E_SUCCESS;
  169. uint32_t val;
  170. if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
  171. assert((stateid_afflvl0 == PLAT_MAX_OFF_STATE) ||
  172. (stateid_afflvl0 == PSTATE_ID_SOC_POWERDN));
  173. assert((stateid_afflvl1 == PLAT_MAX_OFF_STATE) ||
  174. (stateid_afflvl1 == PSTATE_ID_SOC_POWERDN));
  175. /* Suspend se/se2 and pka1 for T210 B01 and se for T210 */
  176. if (tegra_se_suspend() != 0) {
  177. ret = PSCI_E_INTERN_FAIL;
  178. }
  179. } else if (stateid_afflvl1 == PSTATE_ID_CLUSTER_IDLE) {
  180. assert(stateid_afflvl0 == PSTATE_ID_CORE_POWERDN);
  181. if (!tegra_bpmp_available) {
  182. /*
  183. * When disabled, DFLL loses its state. Enable
  184. * open loop state for the DFLL as we dont want
  185. * garbage values being written to the pmic
  186. * when we enter cluster idle state.
  187. */
  188. mmio_write_32(TEGRA_CL_DVFS_BASE + DVFS_DFLL_CTRL,
  189. ENABLE_OPEN_LOOP);
  190. /* Find if the platform uses OVR2/MAX77621 PMIC */
  191. cfg = mmio_read_32(TEGRA_CL_DVFS_BASE + DVFS_DFLL_OUTPUT_CFG);
  192. if (cfg & DFLL_OUTPUT_CFG_CLK_EN_BIT) {
  193. /* OVR2 */
  194. /* PWM tristate */
  195. val = mmio_read_32(TEGRA_MISC_BASE + PINMUX_AUX_DVFS_PWM);
  196. val |= PINMUX_PWM_TRISTATE;
  197. mmio_write_32(TEGRA_MISC_BASE + PINMUX_AUX_DVFS_PWM, val);
  198. /*
  199. * SCRATCH201[1] is being used to identify CPU
  200. * PMIC in warmboot code.
  201. * 0 : OVR2
  202. * 1 : MAX77621
  203. */
  204. tegra_pmc_write_32(PMC_SCRATCH201, 0x0);
  205. } else {
  206. /* MAX77621 */
  207. tegra_pmc_write_32(PMC_SCRATCH201, 0x2);
  208. }
  209. }
  210. /* Prepare for cluster idle */
  211. tegra_fc_cluster_idle(mpidr);
  212. } else if (stateid_afflvl0 == PSTATE_ID_CORE_POWERDN) {
  213. /* Prepare for cpu powerdn */
  214. tegra_fc_cpu_powerdn(mpidr);
  215. } else {
  216. ERROR("%s: Unknown state id (%d, %d, %d)\n", __func__,
  217. stateid_afflvl2, stateid_afflvl1, stateid_afflvl0);
  218. ret = PSCI_E_NOT_SUPPORTED;
  219. }
  220. return ret;
  221. }
  222. static void tegra_reset_all_dma_masters(void)
  223. {
  224. uint32_t val, mask;
  225. /*
  226. * Reset all possible DMA masters in the system.
  227. */
  228. val = GPU_RESET_BIT;
  229. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_REG_OFFSET, val);
  230. val = NVENC_RESET_BIT | TSECB_RESET_BIT | APE_RESET_BIT |
  231. NVJPG_RESET_BIT | NVDEC_RESET_BIT;
  232. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_Y, val);
  233. val = HOST1X_RESET_BIT | ISP_RESET_BIT | USBD_RESET_BIT |
  234. VI_RESET_BIT | SDMMC4_RESET_BIT | SDMMC1_RESET_BIT |
  235. SDMMC2_RESET_BIT;
  236. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_L, val);
  237. val = USB2_RESET_BIT | APBDMA_RESET_BIT | AHBDMA_RESET_BIT;
  238. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_H, val);
  239. val = XUSB_DEV_RESET_BIT | XUSB_HOST_RESET_BIT | TSEC_RESET_BIT |
  240. PCIE_RESET_BIT | SDMMC3_RESET_BIT;
  241. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_U, val);
  242. val = SE_RESET_BIT | HDA_RESET_BIT | SATA_RESET_BIT;
  243. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_V, val);
  244. /*
  245. * If any of the DMA masters are still alive, assume
  246. * that the system has been compromised and reboot.
  247. */
  248. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_REG_OFFSET);
  249. mask = GPU_RESET_BIT;
  250. if ((val & mask) != mask)
  251. tegra_pmc_system_reset();
  252. mask = NVENC_RESET_BIT | TSECB_RESET_BIT | APE_RESET_BIT |
  253. NVJPG_RESET_BIT | NVDEC_RESET_BIT;
  254. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_Y);
  255. if ((val & mask) != mask)
  256. tegra_pmc_system_reset();
  257. mask = HOST1X_RESET_BIT | ISP_RESET_BIT | USBD_RESET_BIT |
  258. VI_RESET_BIT | SDMMC4_RESET_BIT | SDMMC1_RESET_BIT |
  259. SDMMC2_RESET_BIT;
  260. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_L);
  261. if ((val & mask) != mask)
  262. tegra_pmc_system_reset();
  263. mask = USB2_RESET_BIT | APBDMA_RESET_BIT | AHBDMA_RESET_BIT;
  264. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_H);
  265. if ((val & mask) != mask)
  266. tegra_pmc_system_reset();
  267. mask = XUSB_DEV_RESET_BIT | XUSB_HOST_RESET_BIT | TSEC_RESET_BIT |
  268. PCIE_RESET_BIT | SDMMC3_RESET_BIT;
  269. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_U);
  270. if ((val & mask) != mask)
  271. tegra_pmc_system_reset();
  272. val = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_RST_DEV_SET_V);
  273. mask = SE_RESET_BIT | HDA_RESET_BIT | SATA_RESET_BIT;
  274. if ((val & mask) != mask)
  275. tegra_pmc_system_reset();
  276. }
  277. int tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
  278. {
  279. u_register_t mpidr = read_mpidr();
  280. const plat_local_state_t *pwr_domain_state =
  281. target_state->pwr_domain_state;
  282. unsigned int stateid_afflvl2 = pwr_domain_state[PLAT_MAX_PWR_LVL];
  283. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  284. uint32_t val;
  285. if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
  286. if (tegra_chipid_is_t210_b01()) {
  287. /* Save tzram contents */
  288. tegra_se_save_tzram();
  289. }
  290. /* de-init the interface */
  291. tegra_bpmp_suspend();
  292. /*
  293. * The CPU needs to load the System suspend entry firmware
  294. * if nothing is running on the BPMP.
  295. */
  296. if (!tegra_bpmp_available) {
  297. /*
  298. * BPMP firmware is not running on the co-processor, so
  299. * we need to explicitly load the firmware to enable
  300. * entry/exit to/from System Suspend and set the BPMP
  301. * on its way.
  302. */
  303. /* Power off BPMP before we proceed */
  304. tegra_fc_bpmp_off();
  305. /* bond out IRAM banks B, C and D */
  306. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_BOND_OUT_U,
  307. IRAM_B_LOCK_BIT | IRAM_C_LOCK_BIT |
  308. IRAM_D_LOCK_BIT);
  309. /* bond out APB/AHB DMAs */
  310. mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_BOND_OUT_H,
  311. APB_DMA_LOCK_BIT | AHB_DMA_LOCK_BIT);
  312. /* Power off BPMP before we proceed */
  313. tegra_fc_bpmp_off();
  314. /*
  315. * Reset all the hardware blocks that can act as DMA
  316. * masters on the bus.
  317. */
  318. tegra_reset_all_dma_masters();
  319. /*
  320. * Mark PMC as accessible to the non-secure world
  321. * to allow the COP to execute System Suspend
  322. * sequence
  323. */
  324. val = mmio_read_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE);
  325. val &= ~PMC_SECURITY_EN_BIT;
  326. mmio_write_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE, val);
  327. /* clean up IRAM of any cruft */
  328. zeromem((void *)(uintptr_t)TEGRA_IRAM_BASE,
  329. TEGRA_IRAM_A_SIZE);
  330. /* Copy the firmware to BPMP's internal RAM */
  331. (void)memcpy((void *)(uintptr_t)TEGRA_IRAM_BASE,
  332. (const void *)(plat_params->sc7entry_fw_base + SC7ENTRY_FW_HEADER_SIZE_BYTES),
  333. plat_params->sc7entry_fw_size - SC7ENTRY_FW_HEADER_SIZE_BYTES);
  334. /* Power on the BPMP and execute from IRAM base */
  335. tegra_fc_bpmp_on(TEGRA_IRAM_BASE);
  336. /* Wait until BPMP powers up */
  337. do {
  338. val = mmio_read_32(TEGRA_RES_SEMA_BASE + STA_OFFSET);
  339. } while (val != SIGN_OF_LIFE);
  340. }
  341. /* enter system suspend */
  342. tegra_fc_soc_powerdn(mpidr);
  343. }
  344. return PSCI_E_SUCCESS;
  345. }
  346. int32_t tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
  347. {
  348. return PSCI_E_NOT_SUPPORTED;
  349. }
  350. int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
  351. {
  352. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  353. uint32_t cfg;
  354. uint32_t val, entrypoint = 0;
  355. uint64_t offset;
  356. /* platform parameter passed by the previous bootloader */
  357. if (plat_params->l2_ecc_parity_prot_dis != 1) {
  358. /* Enable ECC Parity Protection for Cortex-A57 CPUs */
  359. val = read_l2ctlr_el1();
  360. val |= (uint64_t)CORTEX_A57_L2_ECC_PARITY_PROTECTION_BIT;
  361. write_l2ctlr_el1(val);
  362. }
  363. /*
  364. * Check if we are exiting from SOC_POWERDN.
  365. */
  366. if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] ==
  367. PLAT_SYS_SUSPEND_STATE_ID) {
  368. /*
  369. * Security engine resume
  370. */
  371. if (tegra_chipid_is_t210_b01()) {
  372. tegra_se_resume();
  373. }
  374. /*
  375. * Lock scratch registers which hold the CPU vectors
  376. */
  377. tegra_pmc_lock_cpu_vectors();
  378. /*
  379. * Enable WRAP to INCR burst type conversions for
  380. * incoming requests on the AXI slave ports.
  381. */
  382. val = mmio_read_32(TEGRA_MSELECT_BASE + MSELECT_CONFIG);
  383. val &= ~ENABLE_UNSUP_TX_ERRORS;
  384. val |= ENABLE_WRAP_TO_INCR_BURSTS;
  385. mmio_write_32(TEGRA_MSELECT_BASE + MSELECT_CONFIG, val);
  386. /*
  387. * Restore Boot and Power Management Processor (BPMP) reset
  388. * address and reset it, if it is supported by the platform.
  389. */
  390. if (!tegra_bpmp_available) {
  391. tegra_fc_bpmp_off();
  392. } else {
  393. entrypoint = tegra_pmc_read_32(PMC_SCRATCH39);
  394. tegra_fc_bpmp_on(entrypoint);
  395. /* initialise the interface */
  396. tegra_bpmp_resume();
  397. }
  398. if (plat_params->sc7entry_fw_base != 0U) {
  399. /* sc7entry-fw is part of TZDRAM area */
  400. offset = plat_params->tzdram_base - plat_params->sc7entry_fw_base;
  401. tegra_memctrl_tzdram_setup(plat_params->sc7entry_fw_base,
  402. plat_params->tzdram_size + offset);
  403. }
  404. if (!tegra_chipid_is_t210_b01()) {
  405. /* restrict PMC access to secure world */
  406. val = mmio_read_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE);
  407. val |= PMC_SECURITY_EN_BIT;
  408. mmio_write_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE, val);
  409. }
  410. }
  411. /*
  412. * Check if we are exiting cluster idle state
  413. */
  414. if (target_state->pwr_domain_state[MPIDR_AFFLVL1] ==
  415. PSTATE_ID_CLUSTER_IDLE) {
  416. if (!tegra_bpmp_available) {
  417. /* PWM un-tristate */
  418. cfg = mmio_read_32(TEGRA_CL_DVFS_BASE + DVFS_DFLL_OUTPUT_CFG);
  419. if (cfg & DFLL_OUTPUT_CFG_CLK_EN_BIT) {
  420. val = mmio_read_32(TEGRA_MISC_BASE + PINMUX_AUX_DVFS_PWM);
  421. val &= ~PINMUX_PWM_TRISTATE;
  422. mmio_write_32(TEGRA_MISC_BASE + PINMUX_AUX_DVFS_PWM, val);
  423. /* make sure the setting took effect */
  424. val = mmio_read_32(TEGRA_MISC_BASE + PINMUX_AUX_DVFS_PWM);
  425. assert((val & PINMUX_PWM_TRISTATE) == 0U);
  426. }
  427. /*
  428. * Restore operation mode for the DFLL ring
  429. * oscillator
  430. */
  431. mmio_write_32(TEGRA_CL_DVFS_BASE + DVFS_DFLL_CTRL,
  432. ENABLE_CLOSED_LOOP);
  433. /* release cluster idle lock */
  434. tegra_fc_ccplex_pgexit_unlock();
  435. }
  436. }
  437. /*
  438. * Mark this CPU as ON in the cpu_powergate_mask[],
  439. * so that we use Flow Controller for all subsequent
  440. * power ups.
  441. */
  442. cpu_powergate_mask[plat_my_core_pos()] = 1;
  443. /*
  444. * T210 has a dedicated ARMv7 boot and power mgmt processor, BPMP. It's
  445. * used for power management and boot purposes. Inform the BPMP that
  446. * we have completed the cluster power up.
  447. */
  448. tegra_fc_lock_active_cluster();
  449. /*
  450. * Resume PMC hardware block for Tegra210 platforms
  451. */
  452. if (!tegra_chipid_is_t210_b01()) {
  453. tegra_pmc_resume();
  454. }
  455. return PSCI_E_SUCCESS;
  456. }
  457. int tegra_soc_pwr_domain_on(u_register_t mpidr)
  458. {
  459. int cpu = mpidr & MPIDR_CPU_MASK;
  460. uint32_t mask = CPU_CORE_RESET_MASK << cpu;
  461. /* Deassert CPU reset signals */
  462. mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask);
  463. /* Turn on CPU using flow controller or PMC */
  464. if (cpu_powergate_mask[cpu] == 0) {
  465. tegra_pmc_cpu_on(cpu);
  466. } else {
  467. tegra_fc_cpu_on(cpu);
  468. }
  469. return PSCI_E_SUCCESS;
  470. }
  471. int32_t tegra_soc_pwr_domain_off_early(const psci_power_state_t *target_state)
  472. {
  473. /* Do not power off the boot CPU */
  474. if (plat_is_my_cpu_primary()) {
  475. return PSCI_E_DENIED;
  476. }
  477. return PSCI_E_SUCCESS;
  478. }
  479. int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
  480. {
  481. tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
  482. return PSCI_E_SUCCESS;
  483. }
  484. int tegra_soc_prepare_system_reset(void)
  485. {
  486. /*
  487. * Set System Clock (SCLK) to POR default so that the clock source
  488. * for the PMC APB clock would not be changed due to system reset.
  489. */
  490. mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
  491. SCLK_BURST_POLICY_DEFAULT);
  492. mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
  493. /* Wait 1 ms to make sure clock source/device logic is stabilized. */
  494. mdelay(1);
  495. /*
  496. * Program the PMC in order to restart the system.
  497. */
  498. tegra_pmc_system_reset();
  499. return PSCI_E_SUCCESS;
  500. }
  501. __dead2 void tegra_soc_prepare_system_off(void)
  502. {
  503. ERROR("Tegra System Off: operation not handled.\n");
  504. panic();
  505. }