Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * SMP support for SoCs with SCU covered by mach-shmobile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2013  Magnus Damm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/smp_plat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/smp_scu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static phys_addr_t shmobile_scu_base_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static void __iomem *shmobile_scu_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int shmobile_scu_cpu_prepare(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	/* For this particular CPU register SCU SMP boot vector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	shmobile_smp_hook(cpu, __pa_symbol(shmobile_boot_scu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 			  shmobile_scu_base_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 					  unsigned int max_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	/* install boot code shared by all CPUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	shmobile_boot_fn = __pa_symbol(shmobile_smp_boot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	/* enable SCU and cache coherency on booting CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	shmobile_scu_base_phys = scu_base_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	shmobile_scu_base = ioremap(scu_base_phys, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	scu_enable(shmobile_scu_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	/* Use CPU notifier for reset vector control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	cpuhp_setup_state_nocalls(CPUHP_ARM_SHMOBILE_SCU_PREPARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 				  "arm/shmobile-scu:prepare",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 				  shmobile_scu_cpu_prepare, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void shmobile_smp_scu_cpu_die(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	/* For this particular CPU deregister boot vector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	shmobile_smp_hook(cpu, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	dsb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	/* disable cache coherency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	/* jump to shared mach-shmobile sleep / reset code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	shmobile_smp_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int shmobile_smp_scu_psr_core_disabled(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int shmobile_smp_scu_cpu_kill(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	/* this function is running on another CPU than the offline target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	 * here we need wait for shutdown code in platform_cpu_die() to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	 * finish before asking SoC-specific code to power off the CPU core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	for (k = 0; k < 1000; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		if (shmobile_smp_scu_psr_core_disabled(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #endif