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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (C) 2014 Imagination Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * CPU PM notifiers for saving/restoring general CPU state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/cpu_pm.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/dsp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/fpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/watch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* Used by PM helper macros in asm/pm.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct mips_static_suspend_state mips_static_suspend_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * mips_cpu_save() - Save general CPU state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  * Ensures that general CPU context is saved, notably FPU and DSP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int mips_cpu_save(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	/* Save FPU state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	lose_fpu(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	/* Save DSP state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	save_dsp(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  * mips_cpu_restore() - Restore general CPU state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)  * Restores important CPU context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void mips_cpu_restore(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	/* Restore ASID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	if (current->mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		write_c0_entryhi(cpu_asid(cpu, current->mm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	/* Restore DSP state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	restore_dsp(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	/* Restore UserLocal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	if (cpu_has_userlocal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		write_c0_userlocal(current_thread_info()->tp_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	/* Restore watch registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	__restore_watch(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)  * mips_pm_notifier() - Notifier for preserving general CPU context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)  * @self:	Notifier block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)  * @cmd:	CPU PM event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)  * @v:		Private data (unused).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)  * This is called when a CPU power management event occurs, and is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)  * ensure that important CPU context is preserved across a CPU power down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int mips_pm_notifier(struct notifier_block *self, unsigned long cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 			    void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	case CPU_PM_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 		ret = mips_cpu_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 			return NOTIFY_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	case CPU_PM_ENTER_FAILED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	case CPU_PM_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 		mips_cpu_restore();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static struct notifier_block mips_pm_notifier_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	.notifier_call = mips_pm_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static int __init mips_pm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 	return cpu_pm_register_notifier(&mips_pm_notifier_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) arch_initcall(mips_pm_init);