1 /*
2  * Copyright (c) 2021, Stephan Gerhold <stephan@gerhold.net>
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch.h>
8 #include <common/debug.h>
9 #include <drivers/arm/gicv2.h>
10 #include <drivers/delay_timer.h>
11 #include <lib/mmio.h>
12 #include <lib/psci/psci.h>
13 #include <plat/common/platform.h>
14 
15 #include <msm8916_mmap.h>
16 #include "msm8916_pm.h"
17 
msm8916_pwr_domain_on(u_register_t mpidr)18 static int msm8916_pwr_domain_on(u_register_t mpidr)
19 {
20 	unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
21 
22 	VERBOSE("PSCI: Booting CPU %d\n", core);
23 	msm8916_cpu_boot(core);
24 
25 	return PSCI_E_SUCCESS;
26 }
27 
msm8916_pwr_domain_on_finish(const psci_power_state_t * target_state)28 static void msm8916_pwr_domain_on_finish(const psci_power_state_t *target_state)
29 {
30 	gicv2_pcpu_distif_init();
31 	gicv2_cpuif_enable();
32 }
33 
msm8916_system_reset(void)34 static void __dead2 msm8916_system_reset(void)
35 {
36 	mmio_write_32(MPM_PS_HOLD, 0);
37 	mdelay(1000);
38 
39 	ERROR("PSCI: System reset failed\n");
40 	panic();
41 }
42 
43 static const plat_psci_ops_t msm8916_psci_ops = {
44 	.pwr_domain_on			= msm8916_pwr_domain_on,
45 	.pwr_domain_on_finish		= msm8916_pwr_domain_on_finish,
46 	.system_off			= msm8916_system_reset,
47 	.system_reset			= msm8916_system_reset,
48 };
49 
50 /* Defined and used in msm8916_helpers.S */
51 extern uintptr_t msm8916_entry_point;
52 
plat_setup_psci_ops(uintptr_t sec_entrypoint,const plat_psci_ops_t ** psci_ops)53 int plat_setup_psci_ops(uintptr_t sec_entrypoint,
54 			const plat_psci_ops_t **psci_ops)
55 {
56 	msm8916_entry_point = sec_entrypoint;
57 	*psci_ops = &msm8916_psci_ops;
58 	return 0;
59 }
60