• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023, Intel Corporation. All rights reserved.
3  * Copyright (c) 2024, Altera Corporation. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <assert.h>
9 #include <errno.h>
10 #include <common/debug.h>
11 #include <drivers/delay_timer.h>
12 #include <lib/mmio.h>
13 
14 #include "agilex5_power_manager.h"
15 #include "socfpga_reset_manager.h"
16 
wait_verify_fsm(uint16_t timeout,uint32_t peripheral_handoff)17 static int wait_verify_fsm(uint16_t timeout, uint32_t peripheral_handoff)
18 {
19 	uint32_t data = 0;
20 	uint32_t count = 0;
21 	uint32_t pgstat = 0;
22 
23 	/* Wait FSM ready */
24 	do {
25 		data = mmio_read_32(AGX5_PWRMGR(PSS_PGSTAT));
26 		count++;
27 		if (count >= 1000) {
28 			return -ETIMEDOUT;
29 		}
30 
31 	} while (AGX5_PWRMGR_PSS_STAT_BUSY(data) == AGX5_PWRMGR_PSS_STAT_BUSY_E_BUSY);
32 
33 	/* Verify PSS SRAM power gated */
34 	pgstat = mmio_read_32(AGX5_PWRMGR(PSS_PGSTAT));
35 	if (pgstat != (AGX5_PWRMGR_PSS_PGEN_OUT(peripheral_handoff))) {
36 		return AGX5_PWRMGR_HANDOFF_PERIPHERAL;
37 	}
38 
39 	return 0;
40 }
41 
pss_sram_power_off(handoff * hoff_ptr)42 static int pss_sram_power_off(handoff *hoff_ptr)
43 {
44 	int ret = 0;
45 	uint32_t peripheral_handoff = 0;
46 
47 	/* Get PSS SRAM handoff data */
48 	peripheral_handoff = hoff_ptr->peripheral_pwr_gate_array;
49 
50 	/* Enable firewall for PSS SRAM */
51 	mmio_write_32(AGX5_PWRMGR(PSS_FWENCTL),
52 			AGX5_PWRMGR_PSS_FWEN(peripheral_handoff));
53 
54 	/* Wait */
55 	udelay(1);
56 
57 	/* Power gating PSS SRAM */
58 	mmio_write_32(AGX5_PWRMGR(PSS_PGENCTL),
59 			AGX5_PWRMGR_PSS_PGEN(peripheral_handoff));
60 
61 	ret = wait_verify_fsm(1000, peripheral_handoff);
62 
63 	return ret;
64 }
65 
config_pwrmgr_handoff(handoff * hoff_ptr)66 void config_pwrmgr_handoff(handoff *hoff_ptr)
67 {
68 	int ret = 0;
69 
70 	switch (hoff_ptr->peripheral_pwr_gate_magic) {
71 	case HANDOFF_MAGIC_PERIPHERAL:
72 		ret = pss_sram_power_off(hoff_ptr);
73 		break;
74 	default:
75 		break;
76 	}
77 
78 	if (ret != 0) {
79 		ERROR("Config PwrMgr handoff failed. error %d\n", ret);
80 		assert(false);
81 	}
82 }
83