From bd799f7117bc0457dfdb1531792569bb5d86b808 Mon Sep 17 00:00:00 2001 From: Soomin Kim Date: Fri, 6 Jan 2017 16:22:05 +0900 Subject: [PATCH] [COMMON] thermal: gpu: Modify thermal control method. Thermal driver sends frequency instead of cooling state. Resolved migration conflicts from kernel 4.9 to 4.14. - rename gpufreq_device -> gpufreq_cdev Change-Id: I8f32e9a1a37bb095e4c06de41f1969bd75913a20 Signed-off-by: Chungwoo Park --- drivers/thermal/gpu_cooling.c | 37 ++++++++++++++++++++++++++++++++--- include/linux/thermal.h | 3 +++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/gpu_cooling.c b/drivers/thermal/gpu_cooling.c index 7f049afe68ee..73bc94431c27 100644 --- a/drivers/thermal/gpu_cooling.c +++ b/drivers/thermal/gpu_cooling.c @@ -73,7 +73,7 @@ struct power_table { struct gpufreq_cooling_device { int id; struct thermal_cooling_device *cool_dev; - unsigned int gpufreq_state; + unsigned long gpufreq_state; unsigned int gpufreq_val; u32 last_load; struct power_table *dyn_power_table; @@ -247,6 +247,28 @@ unsigned long gpufreq_cooling_get_level(unsigned int gpu, unsigned int freq) } EXPORT_SYMBOL_GPL(gpufreq_cooling_get_level); +/** + * gpufreq_cooling_get_freq - for a give gpu, return the cooling frequency. + * @gpu: gpu for which the level is required + * @level: the level of interest + * + * This function will match the cooling level corresponding to the + * requested @freq and return it. + * + * Return: The matched cooling level on success or THERMAL_CFREQ_INVALID + * otherwise. + */ +static u32 gpufreq_cooling_get_freq(unsigned int gpu, unsigned long level) +{ + unsigned int val = 0; + + if (get_property(gpu, level, &val, GET_FREQ)) + return THERMAL_CFREQ_INVALID; + + return val; +} +EXPORT_SYMBOL_GPL(gpufreq_cooling_get_level); + /** * build_dyn_power_table() - create a dynamic power to frequency table * @gpufreq_cdev: the gpufreq cooling device in which to store the table @@ -528,13 +550,23 @@ static u32 get_dynamic_power(struct gpufreq_cooling_device *gpufreq_cdev, static int gpufreq_apply_cooling(struct gpufreq_cooling_device *gpufreq_cdev, unsigned long cooling_state) { + unsigned int gpu_cooling_freq = 0; + /* Check if the old cooling action is same as new cooling action */ if (gpufreq_cdev->gpufreq_state == cooling_state) return 0; gpufreq_cdev->gpufreq_state = cooling_state; - blocking_notifier_call_chain(&gpu_notifier, GPU_THROTTLING, &cooling_state); + gpu_cooling_freq = gpufreq_cooling_get_freq(0, gpufreq_cdev->gpufreq_state); + if (gpu_cooling_freq == THERMAL_CFREQ_INVALID) { + pr_warn("Failed to convert %lu gpu_level\n", + gpufreq_cdev->gpufreq_state); + return -EINVAL; + } + + gpu_cooling_freq = gpu_cooling_freq / 1000; + blocking_notifier_call_chain(&gpu_notifier, GPU_THROTTLING, &gpu_cooling_freq); return 0; } @@ -1004,7 +1036,6 @@ int gpu_cooling_table_init(struct platform_device *pdev) struct ect_ap_thermal_function *function; int last_level = -1, count = 0; #else - struct cpufreq_frequency_table *table_ptr; unsigned int table_size; u32 gpu_idx_num = 0; #endif diff --git a/include/linux/thermal.h b/include/linux/thermal.h index d2df798831e8..8400e0089038 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -38,6 +38,9 @@ /* invalid cooling state */ #define THERMAL_CSTATE_INVALID -1UL +/* invalid cooling frequency */ +#define THERMAL_CFREQ_INVALID -1 + /* No upper/lower limit requirement */ #define THERMAL_NO_LIMIT ((u32)~0) -- 2.20.1