From: Soomin Kim Date: Fri, 6 Jan 2017 07:17:12 +0000 (+0900) Subject: [COMMON] thermal: gpu_cooling: Move and Modify cooling_table_init function X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=136ff9d2ba6ce6217479c052786bac0f08855b2a;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git [COMMON] thermal: gpu_cooling: Move and Modify cooling_table_init function 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 --- diff --git a/drivers/thermal/gpu_cooling.c b/drivers/thermal/gpu_cooling.c index 78458c449b4a..7f049afe68ee 100644 --- a/drivers/thermal/gpu_cooling.c +++ b/drivers/thermal/gpu_cooling.c @@ -32,6 +32,7 @@ #include #include +#include "samsung/exynos_tmu.h" #if defined(CONFIG_SOC_EXYNOS8895) && defined(CONFIG_SOC_EMULATOR8895) #include @@ -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); diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 3cdcf2c616e9..834467ee54b3 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -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) diff --git a/include/linux/gpu_cooling.h b/include/linux/gpu_cooling.h index ff29dde41f7b..a3d6c2f1e289 100755 --- a/include/linux/gpu_cooling.h +++ b/include/linux/gpu_cooling.h @@ -27,6 +27,9 @@ #include #include #include +#include + +#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);