[COMMON] thermal: gpu: Modify thermal control method.
authorSoomin Kim <sm8326.kim@samsung.com>
Fri, 6 Jan 2017 07:22:05 +0000 (16:22 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:18:31 +0000 (17:18 +0900)
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 <cww.park2@samsung.com>
drivers/thermal/gpu_cooling.c
include/linux/thermal.h

index 7f049afe68ee77804d730fcb406e9ffa5a034deb..73bc94431c27426939ad9962f78bc2191a17bd58 100644 (file)
@@ -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
index d2df798831e8707ab921e2f8b3e1811844707854..8400e0089038c8a93b9cdf03017a6baa98e14bed 100644 (file)
@@ -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)