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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * poll_state.c - Polling idle state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/sched/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/sched/idle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define POLL_IDLE_RELAX_COUNT	200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static int __cpuidle poll_idle(struct cpuidle_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 			       struct cpuidle_driver *drv, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	u64 time_start = local_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	dev->poll_time_limit = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	if (!current_set_polling_and_test()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		unsigned int loop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 		u64 limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		limit = cpuidle_poll_time(drv, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		while (!need_resched()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 			cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 			if (loop_count++ < POLL_IDLE_RELAX_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 			loop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 			if (local_clock() - time_start > limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 				dev->poll_time_limit = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	current_clr_polling();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void cpuidle_poll_state_init(struct cpuidle_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	struct cpuidle_state *state = &drv->states[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	state->exit_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	state->target_residency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	state->exit_latency_ns = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	state->target_residency_ns = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	state->power_usage = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	state->enter = poll_idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	state->flags = CPUIDLE_FLAG_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);