/**
* 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);
.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)
{
.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;
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;
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: