plat_pm.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. * Copyright (C) 2018-2020 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <common/debug.h>
  8. #ifdef USE_CCI
  9. #include <drivers/arm/cci.h>
  10. #endif
  11. #include <lib/psci/psci.h>
  12. #include <lib/mmio.h>
  13. #include <plat/common/platform.h>
  14. #include <a3700_pm.h>
  15. #include <arch_helpers.h>
  16. #include <armada_common.h>
  17. #include <dram_win.h>
  18. #include <io_addr_dec.h>
  19. #include <mvebu.h>
  20. #include <mvebu_def.h>
  21. #include <marvell_plat_priv.h>
  22. #include <plat_marvell.h>
  23. /* Warm reset register */
  24. #define MVEBU_WARM_RESET_REG (MVEBU_NB_REGS_BASE + 0x840)
  25. #define MVEBU_WARM_RESET_MAGIC 0x1D1E
  26. /* North Bridge GPIO1 SEL register */
  27. #define MVEBU_NB_GPIO1_SEL_REG (MVEBU_NB_REGS_BASE + 0x830)
  28. #define MVEBU_NB_GPIO1_UART1_SEL BIT(19)
  29. #define MVEBU_NB_GPIO1_GPIO_25_26_EN BIT(17)
  30. #define MVEBU_NB_GPIO1_GPIO_19_EN BIT(14)
  31. #define MVEBU_NB_GPIO1_GPIO_18_EN BIT(13)
  32. /* CPU 1 reset register */
  33. #define MVEBU_CPU_1_RESET_VECTOR (MVEBU_REGS_BASE + 0x14044)
  34. #define MVEBU_CPU_1_RESET_REG (MVEBU_REGS_BASE + 0xD00C)
  35. #define MVEBU_CPU_1_RESET_BIT 31
  36. /* IRQ register */
  37. #define MVEBU_NB_IRQ_STATUS_1_REG (MVEBU_NB_SB_IRQ_REG_BASE)
  38. #define MVEBU_NB_IRQ_STATUS_2_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  39. 0x10)
  40. #define MVEBU_NB_IRQ_MASK_2_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  41. 0x18)
  42. #define MVEBU_SB_IRQ_STATUS_1_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  43. 0x40)
  44. #define MVEBU_SB_IRQ_STATUS_2_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  45. 0x50)
  46. #define MVEBU_NB_GPIO_IRQ_MASK_1_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  47. 0xC8)
  48. #define MVEBU_NB_GPIO_IRQ_MASK_2_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  49. 0xD8)
  50. #define MVEBU_SB_GPIO_IRQ_MASK_REG (MVEBU_NB_SB_IRQ_REG_BASE + \
  51. 0xE8)
  52. #define MVEBU_NB_GPIO_IRQ_EN_LOW_REG (MVEBU_NB_GPIO_IRQ_REG_BASE)
  53. #define MVEBU_NB_GPIO_IRQ_EN_HIGH_REG (MVEBU_NB_GPIO_IRQ_REG_BASE + \
  54. 0x04)
  55. #define MVEBU_NB_GPIO_IRQ_STATUS_LOW_REG (MVEBU_NB_GPIO_IRQ_REG_BASE + \
  56. 0x10)
  57. #define MVEBU_NB_GPIO_IRQ_STATUS_HIGH_REG (MVEBU_NB_GPIO_IRQ_REG_BASE + \
  58. 0x14)
  59. #define MVEBU_NB_GPIO_IRQ_WK_LOW_REG (MVEBU_NB_GPIO_IRQ_REG_BASE + \
  60. 0x18)
  61. #define MVEBU_NB_GPIO_IRQ_WK_HIGH_REG (MVEBU_NB_GPIO_IRQ_REG_BASE + \
  62. 0x1C)
  63. #define MVEBU_SB_GPIO_IRQ_EN_REG (MVEBU_SB_GPIO_IRQ_REG_BASE)
  64. #define MVEBU_SB_GPIO_IRQ_STATUS_REG (MVEBU_SB_GPIO_IRQ_REG_BASE + \
  65. 0x10)
  66. #define MVEBU_SB_GPIO_IRQ_WK_REG (MVEBU_SB_GPIO_IRQ_REG_BASE + \
  67. 0x18)
  68. /* PMU registers */
  69. #define MVEBU_PM_NB_PWR_CTRL_REG (MVEBU_PMSU_REG_BASE)
  70. #define MVEBU_PM_PWR_DN_CNT_SEL BIT(28)
  71. #define MVEBU_PM_SB_PWR_DWN BIT(4)
  72. #define MVEBU_PM_INTERFACE_IDLE BIT(0)
  73. #define MVEBU_PM_NB_CPU_PWR_CTRL_REG (MVEBU_PMSU_REG_BASE + 0x4)
  74. #define MVEBU_PM_L2_FLUSH_EN BIT(22)
  75. #define MVEBU_PM_NB_PWR_OPTION_REG (MVEBU_PMSU_REG_BASE + 0x8)
  76. #define MVEBU_PM_DDR_SR_EN BIT(29)
  77. #define MVEBU_PM_DDR_CLK_DIS_EN BIT(28)
  78. #define MVEBU_PM_WARM_RESET_EN BIT(27)
  79. #define MVEBU_PM_DDRPHY_PWRDWN_EN BIT(23)
  80. #define MVEBU_PM_DDRPHY_PAD_PWRDWN_EN BIT(22)
  81. #define MVEBU_PM_OSC_OFF_EN BIT(21)
  82. #define MVEBU_PM_TBG_OFF_EN BIT(20)
  83. #define MVEBU_PM_CPU_VDDV_OFF_EN BIT(19)
  84. #define MVEBU_PM_AVS_DISABLE_MODE BIT(14)
  85. #define MVEBU_PM_AVS_VDD2_MODE BIT(13)
  86. #define MVEBU_PM_AVS_HOLD_MODE BIT(12)
  87. #define MVEBU_PM_L2_SRAM_LKG_PD_EN BIT(8)
  88. #define MVEBU_PM_EIP_SRAM_LKG_PD_EN BIT(7)
  89. #define MVEBU_PM_DDRMC_SRAM_LKG_PD_EN BIT(6)
  90. #define MVEBU_PM_MCI_SRAM_LKG_PD_EN BIT(5)
  91. #define MVEBU_PM_MMC_SRAM_LKG_PD_EN BIT(4)
  92. #define MVEBU_PM_SATA_SRAM_LKG_PD_EN BIT(3)
  93. #define MVEBU_PM_DMA_SRAM_LKG_PD_EN BIT(2)
  94. #define MVEBU_PM_SEC_SRAM_LKG_PD_EN BIT(1)
  95. #define MVEBU_PM_CPU_SRAM_LKG_PD_EN BIT(0)
  96. #define MVEBU_PM_NB_SRAM_LKG_PD_EN (MVEBU_PM_L2_SRAM_LKG_PD_EN |\
  97. MVEBU_PM_EIP_SRAM_LKG_PD_EN | MVEBU_PM_DDRMC_SRAM_LKG_PD_EN |\
  98. MVEBU_PM_MCI_SRAM_LKG_PD_EN | MVEBU_PM_MMC_SRAM_LKG_PD_EN |\
  99. MVEBU_PM_SATA_SRAM_LKG_PD_EN | MVEBU_PM_DMA_SRAM_LKG_PD_EN |\
  100. MVEBU_PM_SEC_SRAM_LKG_PD_EN | MVEBU_PM_CPU_SRAM_LKG_PD_EN)
  101. #define MVEBU_PM_NB_PWR_DEBUG_REG (MVEBU_PMSU_REG_BASE + 0xC)
  102. #define MVEBU_PM_NB_FORCE_CLK_ON BIT(30)
  103. #define MVEBU_PM_IGNORE_CM3_SLEEP BIT(21)
  104. #define MVEBU_PM_IGNORE_CM3_DEEP BIT(20)
  105. #define MVEBU_PM_NB_WAKE_UP_EN_REG (MVEBU_PMSU_REG_BASE + 0x2C)
  106. #define MVEBU_PM_SB_WKP_NB_EN BIT(31)
  107. #define MVEBU_PM_NB_GPIO_WKP_EN BIT(27)
  108. #define MVEBU_PM_SOC_TIMER_WKP_EN BIT(26)
  109. #define MVEBU_PM_UART_WKP_EN BIT(25)
  110. #define MVEBU_PM_UART2_WKP_EN BIT(19)
  111. #define MVEBU_PM_CPU_TIMER_WKP_EN BIT(17)
  112. #define MVEBU_PM_NB_WKP_EN BIT(16)
  113. #define MVEBU_PM_CORE1_FIQ_IRQ_WKP_EN BIT(13)
  114. #define MVEBU_PM_CORE0_FIQ_IRQ_WKP_EN BIT(12)
  115. #define MVEBU_PM_CPU_0_PWR_CTRL_REG (MVEBU_PMSU_REG_BASE + 0x34)
  116. #define MVEBU_PM_CPU_1_PWR_CTRL_REG (MVEBU_PMSU_REG_BASE + 0x38)
  117. #define MVEBU_PM_CORE_SOC_PD BIT(2)
  118. #define MVEBU_PM_CORE_PROC_PD BIT(1)
  119. #define MVEBU_PM_CORE_PD BIT(0)
  120. #define MVEBU_PM_CORE_1_RETURN_ADDR_REG (MVEBU_PMSU_REG_BASE + 0x44)
  121. #define MVEBU_PM_CPU_VDD_OFF_INFO_1_REG (MVEBU_PMSU_REG_BASE + 0x48)
  122. #define MVEBU_PM_CPU_VDD_OFF_INFO_2_REG (MVEBU_PMSU_REG_BASE + 0x4C)
  123. #define MVEBU_PM_LOW_POWER_STATE BIT(0)
  124. #define MVEBU_PM_CPU_WAKE_UP_CONF_REG (MVEBU_PMSU_REG_BASE + 0x54)
  125. #define MVEBU_PM_CORE1_WAKEUP BIT(13)
  126. #define MVEBU_PM_CORE0_WAKEUP BIT(12)
  127. #define MVEBU_PM_WAIT_DDR_RDY_VALUE (0x15)
  128. #define MVEBU_PM_SB_CPU_PWR_CTRL_REG (MVEBU_SB_WAKEUP_REG_BASE)
  129. #define MVEBU_PM_SB_PM_START BIT(0)
  130. #define MVEBU_PM_SB_PWR_OPTION_REG (MVEBU_SB_WAKEUP_REG_BASE + 0x4)
  131. #define MVEBU_PM_SDIO_PHY_PDWN_EN BIT(17)
  132. #define MVEBU_PM_SB_VDDV_OFF_EN BIT(16)
  133. #define MVEBU_PM_EBM_SRAM_LKG_PD_EN BIT(11)
  134. #define MVEBU_PM_PCIE_SRAM_LKG_PD_EN BIT(10)
  135. #define MVEBU_PM_GBE1_TX_SRAM_LKG_PD_EN BIT(9)
  136. #define MVEBU_PM_GBE1_RX_SRAM_LKG_PD_EN BIT(8)
  137. #define MVEBU_PM_GBE1_MIB_SRAM_LKG_PD_EN BIT(7)
  138. #define MVEBU_PM_GBE0_TX_SRAM_LKG_PD_EN BIT(6)
  139. #define MVEBU_PM_GBE0_RX_SRAM_LKG_PD_EN BIT(5)
  140. #define MVEBU_PM_GBE0_MIB_SRAM_LKG_PD_EN BIT(4)
  141. #define MVEBU_PM_SDIO_SRAM_LKG_PD_EN BIT(3)
  142. #define MVEBU_PM_USB2_SRAM_LKG_PD_EN BIT(2)
  143. #define MVEBU_PM_USB3_H_SRAM_LKG_PD_EN BIT(1)
  144. #define MVEBU_PM_SB_SRAM_LKG_PD_EN (MVEBU_PM_EBM_SRAM_LKG_PD_EN |\
  145. MVEBU_PM_PCIE_SRAM_LKG_PD_EN | MVEBU_PM_GBE1_TX_SRAM_LKG_PD_EN |\
  146. MVEBU_PM_GBE1_RX_SRAM_LKG_PD_EN | MVEBU_PM_GBE1_MIB_SRAM_LKG_PD_EN |\
  147. MVEBU_PM_GBE0_TX_SRAM_LKG_PD_EN | MVEBU_PM_GBE0_RX_SRAM_LKG_PD_EN |\
  148. MVEBU_PM_GBE0_MIB_SRAM_LKG_PD_EN | MVEBU_PM_SDIO_SRAM_LKG_PD_EN |\
  149. MVEBU_PM_USB2_SRAM_LKG_PD_EN | MVEBU_PM_USB3_H_SRAM_LKG_PD_EN)
  150. #define MVEBU_PM_SB_WK_EN_REG (MVEBU_SB_WAKEUP_REG_BASE + 0x10)
  151. #define MVEBU_PM_SB_GPIO_WKP_EN BIT(24)
  152. #define MVEBU_PM_SB_WKP_EN BIT(20)
  153. /* DRAM registers */
  154. #define MVEBU_DRAM_STATS_CH0_REG (MVEBU_DRAM_REG_BASE + 0x4)
  155. #define MVEBU_DRAM_WCP_EMPTY BIT(19)
  156. #define MVEBU_DRAM_CMD_0_REG (MVEBU_DRAM_REG_BASE + 0x20)
  157. #define MVEBU_DRAM_CH0_CMD0 BIT(28)
  158. #define MVEBU_DRAM_CS_CMD0 BIT(24)
  159. #define MVEBU_DRAM_WCB_DRAIN_REQ BIT(1)
  160. #define MVEBU_DRAM_PWR_CTRL_REG (MVEBU_DRAM_REG_BASE + 0x54)
  161. #define MVEBU_DRAM_PHY_CLK_GATING_EN BIT(1)
  162. #define MVEBU_DRAM_PHY_AUTO_AC_OFF_EN BIT(0)
  163. /* AVS registers */
  164. #define MVEBU_AVS_CTRL_2_REG (MVEBU_AVS_REG_BASE + 0x8)
  165. #define MVEBU_LOW_VDD_MODE_EN BIT(6)
  166. /* Clock registers */
  167. #define MVEBU_NB_CLOCK_SEL_REG (MVEBU_NB_REGS_BASE + 0x10)
  168. #define MVEBU_A53_CPU_CLK_SEL BIT(15)
  169. /* North Bridge Step-Down Registers */
  170. #define MVEBU_NB_STEP_DOWN_INT_EN_REG MVEBU_NB_STEP_DOWN_REG_BASE
  171. #define MVEBU_NB_GPIO_INT_WAKE_WCPU_CLK BIT(8)
  172. #define MVEBU_NB_GPIO_18 18
  173. #define MVEBU_NB_GPIO_19 19
  174. #define MVEBU_NB_GPIO_25 25
  175. #define MVEBU_NB_GPIO_26 26
  176. typedef int (*wake_up_src_func)(union pm_wake_up_src_data *);
  177. struct wake_up_src_func_map {
  178. enum pm_wake_up_src_type type;
  179. wake_up_src_func func;
  180. };
  181. void marvell_psci_arch_init(int die_index)
  182. {
  183. }
  184. void a3700_pm_ack_irq(void)
  185. {
  186. uint32_t reg;
  187. reg = mmio_read_32(MVEBU_NB_IRQ_STATUS_1_REG);
  188. if (reg)
  189. mmio_write_32(MVEBU_NB_IRQ_STATUS_1_REG, reg);
  190. reg = mmio_read_32(MVEBU_NB_IRQ_STATUS_2_REG);
  191. if (reg)
  192. mmio_write_32(MVEBU_NB_IRQ_STATUS_2_REG, reg);
  193. reg = mmio_read_32(MVEBU_SB_IRQ_STATUS_1_REG);
  194. if (reg)
  195. mmio_write_32(MVEBU_SB_IRQ_STATUS_1_REG, reg);
  196. reg = mmio_read_32(MVEBU_SB_IRQ_STATUS_2_REG);
  197. if (reg)
  198. mmio_write_32(MVEBU_SB_IRQ_STATUS_2_REG, reg);
  199. reg = mmio_read_32(MVEBU_NB_GPIO_IRQ_STATUS_LOW_REG);
  200. if (reg)
  201. mmio_write_32(MVEBU_NB_GPIO_IRQ_STATUS_LOW_REG, reg);
  202. reg = mmio_read_32(MVEBU_NB_GPIO_IRQ_STATUS_HIGH_REG);
  203. if (reg)
  204. mmio_write_32(MVEBU_NB_GPIO_IRQ_STATUS_HIGH_REG, reg);
  205. reg = mmio_read_32(MVEBU_SB_GPIO_IRQ_STATUS_REG);
  206. if (reg)
  207. mmio_write_32(MVEBU_SB_GPIO_IRQ_STATUS_REG, reg);
  208. }
  209. /*****************************************************************************
  210. * A3700 handler called to check the validity of the power state
  211. * parameter.
  212. *****************************************************************************
  213. */
  214. int a3700_validate_power_state(unsigned int power_state,
  215. psci_power_state_t *req_state)
  216. {
  217. ERROR("%s needs to be implemented\n", __func__);
  218. panic();
  219. }
  220. /*****************************************************************************
  221. * A3700 handler called when a CPU is about to enter standby.
  222. *****************************************************************************
  223. */
  224. void a3700_cpu_standby(plat_local_state_t cpu_state)
  225. {
  226. ERROR("%s needs to be implemented\n", __func__);
  227. panic();
  228. }
  229. /*****************************************************************************
  230. * A3700 handler called when a power domain is about to be turned on. The
  231. * mpidr determines the CPU to be turned on.
  232. *****************************************************************************
  233. */
  234. int a3700_pwr_domain_on(u_register_t mpidr)
  235. {
  236. /* Set barrier */
  237. dsbsy();
  238. /* Set the cpu start address to BL1 entry point */
  239. mmio_write_32(MVEBU_CPU_1_RESET_VECTOR,
  240. PLAT_MARVELL_CPU_ENTRY_ADDR >> 2);
  241. /* Get the cpu out of reset */
  242. mmio_clrbits_32(MVEBU_CPU_1_RESET_REG, BIT(MVEBU_CPU_1_RESET_BIT));
  243. mmio_setbits_32(MVEBU_CPU_1_RESET_REG, BIT(MVEBU_CPU_1_RESET_BIT));
  244. return 0;
  245. }
  246. /*****************************************************************************
  247. * A3700 handler called to validate the entry point.
  248. *****************************************************************************
  249. */
  250. int a3700_validate_ns_entrypoint(uintptr_t entrypoint)
  251. {
  252. return PSCI_E_SUCCESS;
  253. }
  254. /*****************************************************************************
  255. * A3700 handler called when a power domain is about to be turned off. The
  256. * target_state encodes the power state that each level should transition to.
  257. *****************************************************************************
  258. */
  259. void a3700_pwr_domain_off(const psci_power_state_t *target_state)
  260. {
  261. /* Prevent interrupts from spuriously waking up this cpu */
  262. plat_marvell_gic_cpuif_disable();
  263. /* Core can not be powered down with pending IRQ,
  264. * acknowledge all the pending IRQ
  265. */
  266. a3700_pm_ack_irq();
  267. }
  268. static void a3700_set_gen_pwr_off_option(void)
  269. {
  270. /* Enable L2 flush -> processor state-machine option */
  271. mmio_setbits_32(MVEBU_PM_NB_CPU_PWR_CTRL_REG, MVEBU_PM_L2_FLUSH_EN);
  272. /*
  273. * North bridge cannot be VDD off (always ON).
  274. * The NB state machine support low power mode by its state machine.
  275. * This bit MUST be set for north bridge power down, e.g.,
  276. * OSC input cutoff(NOT TEST), SRAM power down, PMIC, etc.
  277. * It is not related to CPU VDD OFF!!
  278. */
  279. mmio_clrbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_CPU_VDDV_OFF_EN);
  280. /*
  281. * MUST: Switch CPU/AXI clock to OSC
  282. * NB state machine clock is always connected to OSC (slow clock).
  283. * But Core0/1/processor state machine's clock are connected to AXI
  284. * clock. Now, AXI clock takes the TBG as clock source.
  285. * If using AXI clock, Core0/1/processor state machine may much faster
  286. * than NB state machine. It will cause problem in this case if cores
  287. * are released before north bridge gets ready.
  288. */
  289. mmio_clrbits_32(MVEBU_NB_CLOCK_SEL_REG, MVEBU_A53_CPU_CLK_SEL);
  290. /*
  291. * These register bits will trigger north bridge
  292. * power-down state machine regardless CM3 status.
  293. */
  294. mmio_setbits_32(MVEBU_PM_NB_PWR_DEBUG_REG, MVEBU_PM_IGNORE_CM3_SLEEP);
  295. mmio_setbits_32(MVEBU_PM_NB_PWR_DEBUG_REG, MVEBU_PM_IGNORE_CM3_DEEP);
  296. /*
  297. * SRAM => controlled by north bridge state machine.
  298. * Core VDD OFF is not related to CPU SRAM power down.
  299. */
  300. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_NB_SRAM_LKG_PD_EN);
  301. /*
  302. * Idle AXI interface in order to get L2_WFI
  303. * L2 WFI is only asserted after CORE-0 and CORE-1 WFI asserted.
  304. * (only both core-0/1in WFI, L2 WFI will be issued by CORE.)
  305. * Once L2 WFI asserted, this bit is used for signalling assertion
  306. * to AXI IO masters.
  307. */
  308. mmio_setbits_32(MVEBU_PM_NB_PWR_CTRL_REG, MVEBU_PM_INTERFACE_IDLE);
  309. /* Enable core0 and core1 VDD_OFF */
  310. mmio_setbits_32(MVEBU_PM_CPU_0_PWR_CTRL_REG, MVEBU_PM_CORE_PD);
  311. mmio_setbits_32(MVEBU_PM_CPU_1_PWR_CTRL_REG, MVEBU_PM_CORE_PD);
  312. /* Enable North bridge power down -
  313. * Both Cores MUST enable this bit to power down north bridge!
  314. */
  315. mmio_setbits_32(MVEBU_PM_CPU_0_PWR_CTRL_REG, MVEBU_PM_CORE_SOC_PD);
  316. mmio_setbits_32(MVEBU_PM_CPU_1_PWR_CTRL_REG, MVEBU_PM_CORE_SOC_PD);
  317. /* CA53 (processor domain) power down */
  318. mmio_setbits_32(MVEBU_PM_CPU_0_PWR_CTRL_REG, MVEBU_PM_CORE_PROC_PD);
  319. mmio_setbits_32(MVEBU_PM_CPU_1_PWR_CTRL_REG, MVEBU_PM_CORE_PROC_PD);
  320. }
  321. static void a3700_en_ddr_self_refresh(void)
  322. {
  323. /*
  324. * Both count is 16 bits and configurable. By default, osc stb cnt
  325. * is 0xFFF for lower 12 bits.
  326. * Thus, powerdown count is smaller than osc count.
  327. * This count is used for exiting DDR SR mode on wakeup event.
  328. * The powerdown count also has impact on the following
  329. * state changes: idle -> count-down -> ... (power-down, vdd off, etc)
  330. * Here, make stable counter shorter
  331. * Use power down count value instead of osc_stb_cnt to speed up
  332. * DDR self refresh exit
  333. */
  334. mmio_setbits_32(MVEBU_PM_NB_PWR_CTRL_REG, MVEBU_PM_PWR_DN_CNT_SEL);
  335. /*
  336. * Enable DDR SR mode => controlled by north bridge state machine
  337. * Therefore, we must powerdown north bridge to trigger the DDR SR
  338. * mode switching.
  339. */
  340. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_DDR_SR_EN);
  341. /* Disable DDR clock, otherwise DDR will not enter into SR mode. */
  342. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_DDR_CLK_DIS_EN);
  343. /* Power down DDR PHY (PAD) */
  344. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_DDRPHY_PWRDWN_EN);
  345. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG,
  346. MVEBU_PM_DDRPHY_PAD_PWRDWN_EN);
  347. /* Set wait time for DDR ready in ROM code */
  348. mmio_write_32(MVEBU_PM_CPU_VDD_OFF_INFO_1_REG,
  349. MVEBU_PM_WAIT_DDR_RDY_VALUE);
  350. /* DDR flush write buffer - mandatory */
  351. mmio_write_32(MVEBU_DRAM_CMD_0_REG, MVEBU_DRAM_CH0_CMD0 |
  352. MVEBU_DRAM_CS_CMD0 | MVEBU_DRAM_WCB_DRAIN_REQ);
  353. while ((mmio_read_32(MVEBU_DRAM_STATS_CH0_REG) &
  354. MVEBU_DRAM_WCP_EMPTY) != MVEBU_DRAM_WCP_EMPTY)
  355. ;
  356. /* Trigger PHY reset after ddr out of self refresh =>
  357. * supply reset pulse for DDR phy after wake up
  358. */
  359. mmio_setbits_32(MVEBU_DRAM_PWR_CTRL_REG, MVEBU_DRAM_PHY_CLK_GATING_EN |
  360. MVEBU_DRAM_PHY_AUTO_AC_OFF_EN);
  361. }
  362. static void a3700_pwr_dn_avs(void)
  363. {
  364. /*
  365. * AVS power down - controlled by north bridge statemachine
  366. * Enable AVS power down by clear the AVS disable bit.
  367. */
  368. mmio_clrbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_AVS_DISABLE_MODE);
  369. /*
  370. * Should set BIT[12:13] to powerdown AVS.
  371. * 1. Enable AVS VDD2 mode
  372. * 2. After power down AVS, we must hold AVS output voltage.
  373. * 3. We can choose the lower VDD for AVS power down.
  374. */
  375. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_AVS_VDD2_MODE);
  376. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_AVS_HOLD_MODE);
  377. /* Enable low VDD mode, AVS will set CPU to lowest core VDD 747mV */
  378. mmio_setbits_32(MVEBU_AVS_CTRL_2_REG, MVEBU_LOW_VDD_MODE_EN);
  379. }
  380. static void a3700_pwr_dn_tbg(void)
  381. {
  382. /* Power down TBG */
  383. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_TBG_OFF_EN);
  384. }
  385. static void a3700_pwr_dn_sb(void)
  386. {
  387. /* Enable south bridge power down option */
  388. mmio_setbits_32(MVEBU_PM_NB_PWR_CTRL_REG, MVEBU_PM_SB_PWR_DWN);
  389. /* Enable SDIO_PHY_PWRDWN */
  390. mmio_setbits_32(MVEBU_PM_SB_PWR_OPTION_REG, MVEBU_PM_SDIO_PHY_PDWN_EN);
  391. /* Enable SRAM LRM on SB */
  392. mmio_setbits_32(MVEBU_PM_SB_PWR_OPTION_REG, MVEBU_PM_SB_SRAM_LKG_PD_EN);
  393. /* Enable SB Power Off */
  394. mmio_setbits_32(MVEBU_PM_SB_PWR_OPTION_REG, MVEBU_PM_SB_VDDV_OFF_EN);
  395. /* Kick off South Bridge Power Off */
  396. mmio_setbits_32(MVEBU_PM_SB_CPU_PWR_CTRL_REG, MVEBU_PM_SB_PM_START);
  397. }
  398. static void a3700_set_pwr_off_option(void)
  399. {
  400. /* Set general power off option */
  401. a3700_set_gen_pwr_off_option();
  402. /* Enable DDR self refresh in low power mode */
  403. a3700_en_ddr_self_refresh();
  404. /* Power down AVS */
  405. a3700_pwr_dn_avs();
  406. /* Power down TBG */
  407. a3700_pwr_dn_tbg();
  408. /* Power down south bridge, pay attention south bridge setting
  409. * should be done before
  410. */
  411. a3700_pwr_dn_sb();
  412. }
  413. static void a3700_set_wake_up_option(void)
  414. {
  415. /*
  416. * Enable the wakeup event for NB SOC => north-bridge
  417. * state-machine enablement on wake-up event
  418. */
  419. mmio_setbits_32(MVEBU_PM_NB_WAKE_UP_EN_REG, MVEBU_PM_NB_WKP_EN);
  420. /* Enable both core0 and core1 wakeup on demand */
  421. mmio_setbits_32(MVEBU_PM_CPU_WAKE_UP_CONF_REG,
  422. MVEBU_PM_CORE1_WAKEUP | MVEBU_PM_CORE0_WAKEUP);
  423. /* Enable warm reset in low power mode */
  424. mmio_setbits_32(MVEBU_PM_NB_PWR_OPTION_REG, MVEBU_PM_WARM_RESET_EN);
  425. }
  426. static void a3700_pm_en_nb_gpio(uint32_t gpio)
  427. {
  428. /* For GPIO1 interrupt -- North bridge only */
  429. if (gpio >= 32) {
  430. /* GPIO int mask */
  431. mmio_clrbits_32(MVEBU_NB_GPIO_IRQ_MASK_2_REG, BIT(gpio - 32));
  432. /* NB_CPU_WAKE-up ENABLE GPIO int */
  433. mmio_setbits_32(MVEBU_NB_GPIO_IRQ_EN_HIGH_REG, BIT(gpio - 32));
  434. } else {
  435. /* GPIO int mask */
  436. mmio_clrbits_32(MVEBU_NB_GPIO_IRQ_MASK_1_REG, BIT(gpio));
  437. /* NB_CPU_WAKE-up ENABLE GPIO int */
  438. mmio_setbits_32(MVEBU_NB_GPIO_IRQ_EN_LOW_REG, BIT(gpio));
  439. }
  440. mmio_setbits_32(MVEBU_NB_STEP_DOWN_INT_EN_REG,
  441. MVEBU_NB_GPIO_INT_WAKE_WCPU_CLK);
  442. /* Enable using GPIO as wakeup event
  443. * (actually not only for north bridge)
  444. */
  445. mmio_setbits_32(MVEBU_PM_NB_WAKE_UP_EN_REG, MVEBU_PM_NB_GPIO_WKP_EN |
  446. MVEBU_PM_NB_WKP_EN | MVEBU_PM_CORE1_FIQ_IRQ_WKP_EN |
  447. MVEBU_PM_CORE0_FIQ_IRQ_WKP_EN);
  448. }
  449. static void a3700_pm_en_sb_gpio(uint32_t gpio)
  450. {
  451. /* Enable using GPIO as wakeup event */
  452. mmio_setbits_32(MVEBU_PM_NB_WAKE_UP_EN_REG, MVEBU_PM_SB_WKP_NB_EN |
  453. MVEBU_PM_NB_WKP_EN | MVEBU_PM_CORE1_FIQ_IRQ_WKP_EN |
  454. MVEBU_PM_CORE0_FIQ_IRQ_WKP_EN);
  455. /* SB GPIO Wake UP | South Bridge Wake Up Enable */
  456. mmio_setbits_32(MVEBU_PM_SB_WK_EN_REG, MVEBU_PM_SB_GPIO_WKP_EN |
  457. MVEBU_PM_SB_GPIO_WKP_EN);
  458. /* GPIO int mask */
  459. mmio_clrbits_32(MVEBU_SB_GPIO_IRQ_MASK_REG, BIT(gpio));
  460. /* NB_CPU_WAKE-up ENABLE GPIO int */
  461. mmio_setbits_32(MVEBU_SB_GPIO_IRQ_EN_REG, BIT(gpio));
  462. }
  463. int a3700_pm_src_gpio(union pm_wake_up_src_data *src_data)
  464. {
  465. if (src_data->gpio_data.bank_num == 0)
  466. /* North Bridge GPIO */
  467. a3700_pm_en_nb_gpio(src_data->gpio_data.gpio_num);
  468. else
  469. a3700_pm_en_sb_gpio(src_data->gpio_data.gpio_num);
  470. return 0;
  471. }
  472. int a3700_pm_src_uart1(union pm_wake_up_src_data *src_data)
  473. {
  474. /* Clear Uart1 select */
  475. mmio_clrbits_32(MVEBU_NB_GPIO1_SEL_REG, MVEBU_NB_GPIO1_UART1_SEL);
  476. /* set pin 19 gpio usage*/
  477. mmio_setbits_32(MVEBU_NB_GPIO1_SEL_REG, MVEBU_NB_GPIO1_GPIO_19_EN);
  478. /* Enable gpio wake-up*/
  479. a3700_pm_en_nb_gpio(MVEBU_NB_GPIO_19);
  480. /* set pin 18 gpio usage*/
  481. mmio_setbits_32(MVEBU_NB_GPIO1_SEL_REG, MVEBU_NB_GPIO1_GPIO_18_EN);
  482. /* Enable gpio wake-up*/
  483. a3700_pm_en_nb_gpio(MVEBU_NB_GPIO_18);
  484. return 0;
  485. }
  486. int a3700_pm_src_uart0(union pm_wake_up_src_data *src_data)
  487. {
  488. /* set pin 25/26 gpio usage*/
  489. mmio_setbits_32(MVEBU_NB_GPIO1_SEL_REG, MVEBU_NB_GPIO1_GPIO_25_26_EN);
  490. /* Enable gpio wake-up*/
  491. a3700_pm_en_nb_gpio(MVEBU_NB_GPIO_25);
  492. /* Enable gpio wake-up*/
  493. a3700_pm_en_nb_gpio(MVEBU_NB_GPIO_26);
  494. return 0;
  495. }
  496. struct wake_up_src_func_map src_func_table[WAKE_UP_SRC_MAX] = {
  497. {WAKE_UP_SRC_GPIO, a3700_pm_src_gpio},
  498. {WAKE_UP_SRC_UART1, a3700_pm_src_uart1},
  499. {WAKE_UP_SRC_UART0, a3700_pm_src_uart0},
  500. /* FOLLOWING SRC NOT SUPPORTED YET */
  501. {WAKE_UP_SRC_TIMER, NULL}
  502. };
  503. static wake_up_src_func a3700_get_wake_up_src_func(
  504. enum pm_wake_up_src_type type)
  505. {
  506. uint32_t loop;
  507. for (loop = 0; loop < WAKE_UP_SRC_MAX; loop++) {
  508. if (src_func_table[loop].type == type)
  509. return src_func_table[loop].func;
  510. }
  511. return NULL;
  512. }
  513. #pragma weak mv_wake_up_src_config_get
  514. struct pm_wake_up_src_config *mv_wake_up_src_config_get(void)
  515. {
  516. static struct pm_wake_up_src_config wake_up_src_cfg = {};
  517. return &wake_up_src_cfg;
  518. }
  519. static void a3700_set_wake_up_source(void)
  520. {
  521. struct pm_wake_up_src_config *wake_up_src;
  522. uint32_t loop;
  523. wake_up_src_func src_func = NULL;
  524. wake_up_src = mv_wake_up_src_config_get();
  525. for (loop = 0; loop < wake_up_src->wake_up_src_num; loop++) {
  526. src_func = a3700_get_wake_up_src_func(
  527. wake_up_src->wake_up_src[loop].wake_up_src_type);
  528. if (src_func)
  529. src_func(
  530. &(wake_up_src->wake_up_src[loop].wake_up_data));
  531. }
  532. }
  533. static void a3700_pm_save_lp_flag(void)
  534. {
  535. /* Save the flag for enter the low power mode */
  536. mmio_setbits_32(MVEBU_PM_CPU_VDD_OFF_INFO_2_REG,
  537. MVEBU_PM_LOW_POWER_STATE);
  538. }
  539. static void a3700_pm_clear_lp_flag(void)
  540. {
  541. /* Clear the flag for enter the low power mode */
  542. mmio_clrbits_32(MVEBU_PM_CPU_VDD_OFF_INFO_2_REG,
  543. MVEBU_PM_LOW_POWER_STATE);
  544. }
  545. static uint32_t a3700_pm_get_lp_flag(void)
  546. {
  547. /* Get the flag for enter the low power mode */
  548. return mmio_read_32(MVEBU_PM_CPU_VDD_OFF_INFO_2_REG) &
  549. MVEBU_PM_LOW_POWER_STATE;
  550. }
  551. /*****************************************************************************
  552. * A3700 handler called when a power domain is about to be suspended. The
  553. * target_state encodes the power state that each level should transition to.
  554. *****************************************************************************
  555. */
  556. void a3700_pwr_domain_suspend(const psci_power_state_t *target_state)
  557. {
  558. /* Prevent interrupts from spuriously waking up this cpu */
  559. plat_marvell_gic_cpuif_disable();
  560. /* Save IRQ states */
  561. plat_marvell_gic_irq_save();
  562. /* Set wake up options */
  563. a3700_set_wake_up_option();
  564. /* Set wake up sources */
  565. a3700_set_wake_up_source();
  566. /* SoC can not be powered down with pending IRQ,
  567. * acknowledge all the pending IRQ
  568. */
  569. a3700_pm_ack_irq();
  570. /* Set power off options */
  571. a3700_set_pwr_off_option();
  572. /* Save the flag for enter the low power mode */
  573. a3700_pm_save_lp_flag();
  574. isb();
  575. }
  576. /*****************************************************************************
  577. * A3700 handler called when a power domain has just been powered on after
  578. * being turned off earlier. The target_state encodes the low power state that
  579. * each level has woken up from.
  580. *****************************************************************************
  581. */
  582. void a3700_pwr_domain_on_finish(const psci_power_state_t *target_state)
  583. {
  584. /* arch specific configuration */
  585. marvell_psci_arch_init(0);
  586. /* Per-CPU interrupt initialization */
  587. plat_marvell_gic_pcpu_init();
  588. plat_marvell_gic_cpuif_enable();
  589. /* Restore the per-cpu IRQ state */
  590. if (a3700_pm_get_lp_flag())
  591. plat_marvell_gic_irq_pcpu_restore();
  592. }
  593. /*****************************************************************************
  594. * A3700 handler called when a power domain has just been powered on after
  595. * having been suspended earlier. The target_state encodes the low power state
  596. * that each level has woken up from.
  597. * TODO: At the moment we reuse the on finisher and reinitialize the secure
  598. * context. Need to implement a separate suspend finisher.
  599. *****************************************************************************
  600. */
  601. void a3700_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
  602. {
  603. struct dec_win_config *io_dec_map;
  604. uint32_t dec_win_num;
  605. struct dram_win_map dram_wins_map;
  606. /* arch specific configuration */
  607. marvell_psci_arch_init(0);
  608. /* Interrupt initialization */
  609. plat_marvell_gic_init();
  610. /* Restore IRQ states */
  611. plat_marvell_gic_irq_restore();
  612. /*
  613. * Initialize CCI for this cluster after resume from suspend state.
  614. * No need for locks as no other CPU is active.
  615. */
  616. plat_marvell_interconnect_init();
  617. /*
  618. * Enable CCI coherency for the primary CPU's cluster.
  619. * Platform specific PSCI code will enable coherency for other
  620. * clusters.
  621. */
  622. plat_marvell_interconnect_enter_coherency();
  623. /* CPU address decoder windows initialization. */
  624. cpu_wins_init();
  625. /* fetch CPU-DRAM window mapping information by reading
  626. * CPU-DRAM decode windows (only the enabled ones)
  627. */
  628. dram_win_map_build(&dram_wins_map);
  629. /* Get IO address decoder windows */
  630. if (marvell_get_io_dec_win_conf(&io_dec_map, &dec_win_num)) {
  631. printf("No IO address decoder windows configurations found!\n");
  632. return;
  633. }
  634. /* IO address decoder init */
  635. if (init_io_addr_dec(&dram_wins_map, io_dec_map, dec_win_num)) {
  636. printf("IO address decoder windows initialization failed!\n");
  637. return;
  638. }
  639. /* Clear low power mode flag */
  640. a3700_pm_clear_lp_flag();
  641. }
  642. /*****************************************************************************
  643. * This handler is called by the PSCI implementation during the `SYSTEM_SUSPEND
  644. * call to get the `power_state` parameter. This allows the platform to encode
  645. * the appropriate State-ID field within the `power_state` parameter which can
  646. * be utilized in `pwr_domain_suspend()` to suspend to system affinity level.
  647. *****************************************************************************
  648. */
  649. void a3700_get_sys_suspend_power_state(psci_power_state_t *req_state)
  650. {
  651. /* lower affinities use PLAT_MAX_OFF_STATE */
  652. for (int i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++)
  653. req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
  654. }
  655. /*****************************************************************************
  656. * A3700 handlers to shutdown/reboot the system
  657. *****************************************************************************
  658. */
  659. static void __dead2 a3700_system_off(void)
  660. {
  661. ERROR("%s needs to be implemented\n", __func__);
  662. panic();
  663. }
  664. #pragma weak cm3_system_reset
  665. void cm3_system_reset(void)
  666. {
  667. }
  668. /*****************************************************************************
  669. * A3700 handlers to reset the system
  670. *****************************************************************************
  671. */
  672. static void __dead2 a3700_system_reset(void)
  673. {
  674. /* Clean the mailbox magic number to let it as act like cold boot */
  675. mmio_write_32(PLAT_MARVELL_MAILBOX_BASE, 0x0);
  676. dsbsy();
  677. /* Flush data cache if the mail box shared RAM is cached */
  678. #if PLAT_MARVELL_SHARED_RAM_CACHED
  679. flush_dcache_range((uintptr_t)PLAT_MARVELL_MAILBOX_BASE,
  680. 2 * sizeof(uint64_t));
  681. #endif
  682. /* Use Cortex-M3 secure coprocessor for system reset */
  683. cm3_system_reset();
  684. /* Trigger the warm reset */
  685. mmio_write_32(MVEBU_WARM_RESET_REG, MVEBU_WARM_RESET_MAGIC);
  686. /* Shouldn't get to this point */
  687. panic();
  688. }
  689. /*****************************************************************************
  690. * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard
  691. * platform layer will take care of registering the handlers with PSCI.
  692. *****************************************************************************
  693. */
  694. const plat_psci_ops_t plat_arm_psci_pm_ops = {
  695. .cpu_standby = a3700_cpu_standby,
  696. .pwr_domain_on = a3700_pwr_domain_on,
  697. .pwr_domain_off = a3700_pwr_domain_off,
  698. .pwr_domain_suspend = a3700_pwr_domain_suspend,
  699. .pwr_domain_on_finish = a3700_pwr_domain_on_finish,
  700. .pwr_domain_suspend_finish = a3700_pwr_domain_suspend_finish,
  701. .get_sys_suspend_power_state = a3700_get_sys_suspend_power_state,
  702. .system_off = a3700_system_off,
  703. .system_reset = a3700_system_reset,
  704. .validate_power_state = a3700_validate_power_state,
  705. .validate_ns_entrypoint = a3700_validate_ns_entrypoint
  706. };