[COMMON] thermal: samsung: Move gpufreq_cooling_register
authorHyeonseong Gil <hs.gil@samsung.com>
Thu, 30 Mar 2017 01:41:07 +0000 (10:41 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:18:34 +0000 (17:18 +0900)
Change-Id: Id3de94b3f240ee786c5f3b2bf1e84d4b3aef2453
Signed-off-by: Hyeonseong Gil <hs.gil@samsung.com>
drivers/thermal/gpu_cooling.c
drivers/thermal/samsung/exynos_tmu.c
include/linux/gpu_cooling.h

index 73bc94431c27426939ad9962f78bc2191a17bd58..d69b494a577ef987211f64dc1cf8f0a324725e6d 100644 (file)
@@ -1022,82 +1022,79 @@ 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)
+static int gpu_cooling_table_init(void)
 {
-       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
-       unsigned int table_size;
-       u32 gpu_idx_num = 0;
-#endif
-
-#if defined(CONFIG_ECT)
-       exynos_data = platform_get_drvdata(pdev);
+       int i = 0;
+       int num_level = 0, count = 0;
+       unsigned long freq;
 
-       thermal_block = ect_get_block(BLOCK_AP_THERMAL);
-       if (thermal_block == NULL) {
-               dev_err(&pdev->dev, "Failed to get thermal block");
-               return -ENODEV;
-       }
+       num_level = gpu_dvfs_get_step();
 
-       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;
+       if (num_level == 0) {
+               pr_err("Faile to get gpu_dvfs_get_step()\n");
+               return -EINVAL;
        }
 
        /* 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);
+                                       * (num_level + 1), GFP_KERNEL);
+
+       if (!gpu_freq_table)
+               return -ENOMEM;
+
+       for (i = 0; i < num_level; i++) {
+               freq = gpu_dvfs_get_clock(i);
 
-       for (i = 0; i < function->num_of_range; i++) {
-               if (last_level == function->range_list[i].max_frequency)
+               if (freq > gpu_dvfs_get_max_freq())
                        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;
+               gpu_freq_table[count].frequency = freq * 1000;
 
-               dev_info(&pdev->dev, "[GPU TMU] index : %d, frequency : %d \n",
+               pr_info("[GPU cooling] index : %d, frequency : %d\n",
                        gpu_freq_table[count].driver_data, gpu_freq_table[count].frequency);
                count++;
        }
 
-       if (i == function->num_of_range)
+       if (i == num_level)
                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);
+       return 0;
+}
+
+static int __init exynos_gpu_cooling_init(void)
+{
+       struct device_node *np;
+       struct thermal_cooling_device *dev;
+       int ret = 0;
+
+       ret = gpu_cooling_table_init();
+
+       if (ret) {
+               pr_err("Fail to initialize gpu_cooling_table\n");
+               return ret;
 
-               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
+
+       np = of_find_node_by_name(NULL, "mali");
+
+       if (!np) {
+               pr_err("Fail to find device node\n");
+               return -EINVAL;
+       }
+
+       dev = __gpufreq_cooling_register(np, NULL, 0, NULL);
+
+       if (IS_ERR(dev)) {
+               pr_err("Fail to register gpufreq cooling\n");
+               return -EINVAL;
+       }
+
        return ret;
 }
-EXPORT_SYMBOL_GPL(gpu_cooling_table_init);
+device_initcall(exynos_gpu_cooling_init);
index 6756ec726ce0c24c99517beac2600aa0166c369a..e81006b067a16d5f1dc9d69682902ba790992955 100644 (file)
@@ -1441,78 +1441,6 @@ static const struct thermal_zone_of_device_ops exynos_sensor_ops = {
        .get_trend = exynos_get_trend,
 };
 
-#ifdef CONFIG_GPU_THERMAL
-
-#ifdef CONFIG_MALI_DEBUG_KERNEL_SYSFS
-struct exynos_tmu_data *gpu_thermal_data = NULL;
-#endif
-
-static int exynos_gpufreq_cooling_register(struct exynos_tmu_data *data)
-{
-       struct device_node *np, *child = NULL, *gchild, *ggchild;
-       struct device_node *cool_np;
-       struct of_phandle_args cooling_spec;
-       int ret;
-       const char *governor_name;
-       u32 power_coefficient = 0;
-       void *gen_block;
-       struct ect_gen_param_table *pwr_coeff;
-
-       np = of_find_node_by_name(NULL, "thermal-zones");
-       if (!np)
-               return -ENODEV;
-
-       /* Regist gpufreq cooling device */
-       for_each_child_of_node(np, child) {
-               struct device_node *zone_np;
-               zone_np = of_parse_phandle(child, "thermal-sensors", 0);
-
-               if (zone_np == data->np) break;
-       }
-
-       gchild = of_get_child_by_name(child, "cooling-maps");
-       ggchild = of_get_next_child(gchild, NULL);
-       ret = of_parse_phandle_with_args(ggchild, "cooling-device", "#cooling-cells",
-                                        0, &cooling_spec);
-       if (ret < 0)
-               pr_err("%s do not get cooling spec(err = %d) \n", data->tmu_name, ret);
-
-       cool_np = cooling_spec.np;
-
-       if (!of_property_read_string(child, "governor", &governor_name)) {
-               if (!strncasecmp(governor_name, "power_allocator", THERMAL_NAME_LENGTH)) {
-                       gen_block = ect_get_block("GEN");
-                       if (gen_block == NULL) {
-                               pr_err("%s: Failed to get gen block from ECT\n", __func__);
-                               return -EINVAL;
-                       }
-                       pwr_coeff = ect_gen_param_get_table(gen_block, "DTM_PWR_Coeff");
-                       if (pwr_coeff == NULL) {
-                               pr_err("%s: Failed to get power coeff from ECT\n", __func__);
-                               return -EINVAL;
-                       }
-                       power_coefficient = pwr_coeff->parameter[data->id];
-               }
-       }
-
-       data->cool_dev = of_gpufreq_power_cooling_register(cool_np, NULL, power_coefficient, NULL);
-
-       if (IS_ERR(data->cool_dev)) {
-               data->cool_dev = NULL;
-               pr_err("gpu cooling device register fail \n");
-               return -ENODEV;
-       }
-
-#ifdef CONFIG_MALI_DEBUG_KERNEL_SYSFS
-       gpu_thermal_data = data;
-#endif
-
-       return ret;
-}
-#else
-static int exynos_gpufreq_cooling_register(struct exynos_tmu_data *data) {return 0;}
-#endif
-
 #ifdef CONFIG_ISP_THERMAL
 static int exynos_isp_cooling_register(struct exynos_tmu_data *data)
 {
@@ -1706,6 +1634,10 @@ static const struct attribute_group exynos_tmu_attr_group = {
        .attrs = exynos_tmu_attrs,
 };
 
+#ifdef CONFIG_MALI_DEBUG_KERNEL_SYSFS
+struct exynos_tmu_data *gpu_thermal_data;
+#endif
+
 static int exynos_tmu_probe(struct platform_device *pdev)
 {
        struct exynos_tmu_data *data;
@@ -1723,17 +1655,7 @@ static int exynos_tmu_probe(struct platform_device *pdev)
        if (ret)
                goto err_sensor;
 
-       if (data->id == 2) {
-               ret = gpu_cooling_table_init(pdev);
-               if (ret)
-                       goto err_sensor;
-
-               ret = exynos_gpufreq_cooling_register(data);
-               if (ret) {
-                       dev_err(&pdev->dev, "Failed cooling register \n");
-                       goto err_sensor;
-               }
-       } else if (data->id == 3) {
+       if (data->id == 3) {
                ret = isp_cooling_table_init(pdev);
                if (ret)
                        goto err_sensor;
@@ -1798,6 +1720,11 @@ static int exynos_tmu_probe(struct platform_device *pdev)
        if (!IS_ERR(data->tzd))
                data->tzd->ops->set_mode(data->tzd, THERMAL_DEVICE_ENABLED);
 
+#ifdef CONFIG_MALI_DEBUG_KERNEL_SYSFS
+       if (data->id == 2)
+               gpu_thermal_data = data;
+#endif
+
        return 0;
 
 err_thermal:
index a3d6c2f1e28948576676d5c532e8438b9a9e8f43..e12db2bc37582778c10069d2863f0a64fad96f9e 100755 (executable)
@@ -86,7 +86,6 @@ 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)
@@ -127,11 +126,6 @@ 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);