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)  * This file provides the ACPI based P-state support. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * module works with generic cpufreq infrastructure. Most of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * the code is based on i386 version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * (arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2005 Intel Corp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *      Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/pal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <acpi/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_AUTHOR("Venkatesh Pallipadi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_DESCRIPTION("ACPI Processor P-States Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct cpufreq_acpi_io {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct acpi_processor_performance	acpi_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned int				resume;
^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) struct cpufreq_acpi_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned int		cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned int		state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static struct cpufreq_acpi_io	*acpi_io_data[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static struct cpufreq_driver acpi_cpufreq_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) processor_set_pstate (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32	value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	s64 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	pr_debug("processor_set_pstate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	retval = ia64_pal_set_pstate((u64)value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		pr_debug("Failed to set freq to 0x%x, with error 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		        value, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return (int)retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) processor_get_pstate (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32	*value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u64	pstate_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	s64 	retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	pr_debug("processor_get_pstate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	retval = ia64_pal_get_pstate(&pstate_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	                             PAL_GET_PSTATE_TYPE_INSTANT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	*value = (u32) pstate_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		pr_debug("Failed to get current freq with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			"error 0x%lx, idx 0x%x\n", retval, *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return (int)retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /* To be used only after data->acpi_data is initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) extract_clock (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct cpufreq_acpi_io *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	pr_debug("extract_clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	for (i = 0; i < data->acpi_data.state_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (value == data->acpi_data.states[i].status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			return data->acpi_data.states[i].core_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return data->acpi_data.states[i-1].core_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) processor_get_freq (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct cpufreq_acpi_req *req = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned int		cpu = req->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct cpufreq_acpi_io	*data = acpi_io_data[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	u32			value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int			ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pr_debug("processor_get_freq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (smp_processor_id() != cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* processor_get_pstate gets the instantaneous frequency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ret = processor_get_pstate(&value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		pr_warn("get performance failed with error %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 1000 * extract_clock(data, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) processor_set_freq (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct cpufreq_acpi_req *req = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	unsigned int		cpu = req->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct cpufreq_acpi_io	*data = acpi_io_data[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int			ret, state = req->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	u32			value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	pr_debug("processor_set_freq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (smp_processor_id() != cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (state == data->acpi_data.state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (unlikely(data->resume)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			pr_debug("Called after resume, resetting to P%d\n", state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			data->resume = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			pr_debug("Already at target state (P%d)\n", state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	pr_debug("Transitioning from P%d to P%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		data->acpi_data.state, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * First we write the target state's 'control' value to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * control_register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	value = (u32) data->acpi_data.states[state].control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	pr_debug("Transitioning to state: 0x%08x\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = processor_set_pstate(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		pr_warn("Transition failed with error %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	data->acpi_data.state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) acpi_cpufreq_get (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	unsigned int		cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct cpufreq_acpi_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	req.cpu = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ret = work_on_cpu(cpu, processor_get_freq, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return ret > 0 ? (unsigned int) ret : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_cpufreq_target (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct cpufreq_policy   *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct cpufreq_acpi_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	req.cpu = policy->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	req.state = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return work_on_cpu(req.cpu, processor_set_freq, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) acpi_cpufreq_cpu_init (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct cpufreq_policy   *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	unsigned int		i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	unsigned int		cpu = policy->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct cpufreq_acpi_io	*data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	unsigned int		result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct cpufreq_frequency_table *freq_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	pr_debug("acpi_cpufreq_cpu_init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return (-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	acpi_io_data[cpu] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	result = acpi_processor_register_performance(&data->acpi_data, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* capability check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (data->acpi_data.state_count <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		pr_debug("No P-States\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		goto err_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if ((data->acpi_data.control_register.space_id !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					ACPI_ADR_SPACE_FIXED_HARDWARE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	    (data->acpi_data.status_register.space_id !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					ACPI_ADR_SPACE_FIXED_HARDWARE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		pr_debug("Unsupported address space [%d, %d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			(u32) (data->acpi_data.control_register.space_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			(u32) (data->acpi_data.status_register.space_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		goto err_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/* alloc freq_table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	freq_table = kcalloc(data->acpi_data.state_count + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	                           sizeof(*freq_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	                           GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (!freq_table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto err_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* detect transition latency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	policy->cpuinfo.transition_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	for (i=0; i<data->acpi_data.state_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		if ((data->acpi_data.states[i].transition_latency * 1000) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		    policy->cpuinfo.transition_latency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			policy->cpuinfo.transition_latency =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			    data->acpi_data.states[i].transition_latency * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* table init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	for (i = 0; i <= data->acpi_data.state_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (i < data->acpi_data.state_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			freq_table[i].frequency =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			      data->acpi_data.states[i].core_frequency * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			freq_table[i].frequency = CPUFREQ_TABLE_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	policy->freq_table = freq_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	/* notify BIOS that we exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	acpi_processor_notify_smm(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	pr_info("CPU%u - ACPI performance management activated\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	for (i = 0; i < data->acpi_data.state_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		pr_debug("     %cP%d: %d MHz, %d mW, %d uS, %d uS, 0x%x 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			(i == data->acpi_data.state?'*':' '), i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			(u32) data->acpi_data.states[i].core_frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			(u32) data->acpi_data.states[i].power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			(u32) data->acpi_data.states[i].transition_latency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			(u32) data->acpi_data.states[i].bus_master_latency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			(u32) data->acpi_data.states[i].status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			(u32) data->acpi_data.states[i].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/* the first call to ->target() should result in us actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * writing something to the appropriate registers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	data->resume = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return (result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  err_unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	acpi_processor_unregister_performance(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	acpi_io_data[cpu] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return (result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) acpi_cpufreq_cpu_exit (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct cpufreq_policy   *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	pr_debug("acpi_cpufreq_cpu_exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		acpi_io_data[policy->cpu] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		acpi_processor_unregister_performance(policy->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		kfree(policy->freq_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static struct cpufreq_driver acpi_cpufreq_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.verify 	= cpufreq_generic_frequency_table_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.target_index	= acpi_cpufreq_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.get 		= acpi_cpufreq_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.init		= acpi_cpufreq_cpu_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.exit		= acpi_cpufreq_cpu_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.name		= "acpi-cpufreq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.attr		= cpufreq_generic_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) acpi_cpufreq_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	pr_debug("acpi_cpufreq_init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  	return cpufreq_register_driver(&acpi_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) acpi_cpufreq_exit (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	pr_debug("acpi_cpufreq_exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	cpufreq_unregister_driver(&acpi_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) late_initcall(acpi_cpufreq_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) module_exit(acpi_cpufreq_exit);