[COMMON] thermal: gpu_cooling: Move and Modify cooling_table_init function
authorSoomin Kim <sm8326.kim@samsung.com>
Fri, 6 Jan 2017 07:17:12 +0000 (16:17 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:18:30 +0000 (17:18 +0900)
gpu_cooling_table_init() is moved from exynos tmu driver.
And cooling table is made with ECT since GPU throttling
information is defined in it.

Change-Id: I483359872eb1ba21a35f52b3ee6eb05f5914bb24
Signed-off-by: Soomin Kim <sm8326.kim@samsung.com>
drivers/thermal/gpu_cooling.c
drivers/thermal/samsung/exynos_tmu.c
include/linux/gpu_cooling.h

index 78458c449b4a51e28ed77fda1ffdf2e72239c219..7f049afe68ee77804d730fcb406e9ffa5a034deb 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <soc/samsung/cal-if.h>
 #include <soc/samsung/ect_parser.h>
+#include "samsung/exynos_tmu.h"
 
 #if defined(CONFIG_SOC_EXYNOS8895) && defined(CONFIG_SOC_EMULATOR8895)
 #include <dt-bindings/clock/emulator8895.h>
@@ -91,7 +92,7 @@ static BLOCKING_NOTIFIER_HEAD(gpu_notifier);
 
 static unsigned int gpufreq_cdev_count;
 
-extern struct cpufreq_frequency_table gpu_freq_table[];
+struct cpufreq_frequency_table *gpu_freq_table;
 
 /**
  * get_idr - function to get a unique id.
@@ -986,3 +987,86 @@ void gpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
        kfree(gpufreq_cdev);
 }
 EXPORT_SYMBOL_GPL(gpufreq_cooling_unregister);
+
+/**
+ * gpu_cooling_table_init - function to make GPU throttling table.
+ * @pdev : struct platform_device pointer
+ *
+ * Return : a valid struct gpu_freq_table pointer on success,
+ * on failture, it returns a corresponding ERR_PTR().
+ */
+int gpu_cooling_table_init(struct platform_device *pdev)
+{
+       int ret = 0, i = 0;
+#if defined(CONFIG_ECT)
+       struct exynos_tmu_data *exynos_data;
+       void *thermal_block;
+       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
+
+#if defined(CONFIG_ECT)
+       exynos_data = platform_get_drvdata(pdev);
+
+       thermal_block = ect_get_block(BLOCK_AP_THERMAL);
+       if (thermal_block == NULL) {
+               dev_err(&pdev->dev, "Failed to get thermal block");
+               return -ENODEV;
+       }
+
+       function = ect_ap_thermal_get_function(thermal_block, exynos_data->tmu_name);
+       if (function == NULL) {
+               dev_err(&pdev->dev, "Failed to get %s information", exynos_data->tmu_name);
+               return -ENODEV;
+       }
+
+       /* Table size can be num_of_range + 1 since last row has the value of TABLE_END */
+       gpu_freq_table = kzalloc(sizeof(struct cpufreq_frequency_table)
+                                       * (function->num_of_range + 1), GFP_KERNEL);
+
+       for (i = 0; i < function->num_of_range; i++) {
+               if (last_level == function->range_list[i].max_frequency)
+                       continue;
+
+               gpu_freq_table[count].flags = 0;
+               gpu_freq_table[count].driver_data = count;
+               gpu_freq_table[count].frequency = function->range_list[i].max_frequency;
+               last_level = gpu_freq_table[count].frequency;
+
+               dev_info(&pdev->dev, "[GPU TMU] index : %d, frequency : %d \n",
+                       gpu_freq_table[count].driver_data, gpu_freq_table[count].frequency);
+               count++;
+       }
+
+       if (i == function->num_of_range)
+               gpu_freq_table[count].frequency = GPU_TABLE_END;
+#else
+       /* gpu cooling frequency table parse */
+       ret = of_property_read_u32(pdev->dev.of_node, "gpu_idx_num", &gpu_idx_num);
+       if (ret < 0)
+               dev_err(&pdev->dev, "gpu_idx_num happend error value\n");
+
+       if (gpu_idx_num) {
+               gpu_freq_table= kzalloc(sizeof(struct cpufreq_frequency_table)
+                                                       * gpu_idx_num, GFP_KERNEL);
+               if (!gpu_freq_table) {
+                       dev_err(&pdev->dev, "failed to allocate for gpu_table\n");
+                       return -ENODEV;
+               }
+               table_size = sizeof(struct cpufreq_frequency_table) / sizeof(unsigned int);
+
+               ret = of_property_read_u32_array(pdev->dev.of_node, "gpu_cooling_table",
+                       (unsigned int *)gpu_freq_table, table_size * gpu_idx_num);
+
+               for (i = 0; i < gpu_idx_num; i++)
+                       dev_info(&pdev->dev, "[GPU TMU] index : %d, frequency : %d \n",
+                               gpu_freq_table[i].driver_data, gpu_freq_table[i].frequency);
+       }
+#endif
+       return ret;
+}
+EXPORT_SYMBOL_GPL(gpu_cooling_table_init);
index 3cdcf2c616e91e0aa0c394a8d47d1b36ca96c477..834467ee54b3a64f0a0b8c9b352b41b947e37979 100644 (file)
@@ -149,7 +149,6 @@ static DEFINE_MUTEX (thermal_suspend_lock);
 
 /* list of multiple instance for each thermal sensor */
 static LIST_HEAD(dtm_dev_list);
-struct cpufreq_frequency_table gpu_freq_table[10];
 
 static u32 global_avg_con;
 
@@ -1166,46 +1165,6 @@ static int exynos_map_dt_data(struct platform_device *pdev)
 
        return 0;
 }
-#ifdef CONFIG_GPU_THERMAL
-static int gpu_cooling_table_init(struct platform_device *pdev)
-{
-       struct cpufreq_frequency_table *table_ptr;
-       unsigned int table_size;
-       u32 gpu_idx_num = 0;
-       int ret = 0, i = 0;
-
-       /* gpu cooling frequency table parse */
-       ret = of_property_read_u32(pdev->dev.of_node, "gpu_idx_num",
-                                       &gpu_idx_num);
-       if (ret < 0)
-               dev_err(&pdev->dev, "gpu_idx_num happend error value\n");
-
-       if (gpu_idx_num) {
-               table_ptr = kzalloc(sizeof(struct cpufreq_frequency_table)
-                                               * gpu_idx_num, GFP_KERNEL);
-               if (!table_ptr) {
-                       dev_err(&pdev->dev, "failed to allocate for gpu_table\n");
-                       return -ENODEV;
-               }
-               table_size = sizeof(struct cpufreq_frequency_table) /
-                                                       sizeof(unsigned int);
-               ret = of_property_read_u32_array(pdev->dev.of_node, "gpu_cooling_table",
-                       (unsigned int *)table_ptr, table_size * gpu_idx_num);
-
-               for (i = 0; i < gpu_idx_num; i++) {
-                       gpu_freq_table[i].flags = table_ptr[i].flags;
-                       gpu_freq_table[i].driver_data = table_ptr[i].driver_data;
-                       gpu_freq_table[i].frequency = table_ptr[i].frequency;
-                       dev_info(&pdev->dev, "[GPU TMU] index : %d, frequency : %d \n",
-                               gpu_freq_table[i].driver_data, gpu_freq_table[i].frequency);
-               }
-               kfree(table_ptr);
-       }
-       return ret;
-}
-#else
-static int gpu_cooling_table_init(struct platform_device *pdev) {return 0;}
-#endif
 
 struct pm_qos_request thermal_cpu_hotplug_request;
 static int exynos_throttle_cpu_hotplug(void *p, int temp)
index ff29dde41f7b2fbfe27c041e1741eababb071aae..a3d6c2f1e28948576676d5c532e8438b9a9e8f43 100755 (executable)
@@ -27,6 +27,9 @@
 #include <linux/of.h>
 #include <linux/thermal.h>
 #include <linux/cpumask.h>
+#include <linux/platform_device.h>
+
+#define GPU_TABLE_END     ~1
 
 typedef int (*get_static_t)(cpumask_t *cpumask, int interval,
                            unsigned long voltage, u32 *power);
@@ -83,6 +86,7 @@ of_gpufreq_power_cooling_register(struct device_node *np,
 void gpufreq_cooling_unregister(struct thermal_cooling_device *cdev);
 
 unsigned long gpufreq_cooling_get_level(unsigned int gpu, unsigned int freq);
+int gpu_cooling_table_init(struct platform_device *pdev);
 #else /* !CONFIG_GPU_THERMAL */
 static inline struct thermal_cooling_device *
 gpufreq_cooling_register(const struct cpumask *clip_gpus)
@@ -123,6 +127,11 @@ unsigned long gpufreq_cooling_get_level(unsigned int gpu, unsigned int freq)
 {
        return THERMAL_CSTATE_INVALID;
 }
+
+static inline int gpu_cooling_table_init(struct platform_device *dev)
+{
+       return true;
+}
 #endif /* CONFIG_GPU_THERMAL */
 #ifdef CONFIG_MALI_DVFS
 extern int gpu_dvfs_get_clock(int level);