From a3f31cd7dab06caf251befda7fdeb2c0c8aabcf4 Mon Sep 17 00:00:00 2001 From: Lei Qian Date: Thu, 17 Oct 2019 13:54:06 +0800 Subject: [PATCH] thermal: merge from mainline PD#SWPL-15312 Change-Id: Icc4841dbb5145c96eca8f54d1358d301b9f6b863 Signed-off-by: Lei Qian --- drivers/amlogic/thermal/aml_thermal_hw.c | 4 +-- drivers/amlogic/thermal/cpucore_cooling.c | 38 ++++++++++++++++++++--- drivers/amlogic/thermal/meson_cooldev.c | 10 +++--- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/drivers/amlogic/thermal/aml_thermal_hw.c b/drivers/amlogic/thermal/aml_thermal_hw.c index 04fdada7eaa7..f9d9b6ba0f04 100644 --- a/drivers/amlogic/thermal/aml_thermal_hw.c +++ b/drivers/amlogic/thermal/aml_thermal_hw.c @@ -162,7 +162,7 @@ int aml_thermal_min_update(struct thermal_cooling_device *cdev) case COOL_DEV_TYPE_CPU_FREQ: for_each_possible_cpu(cpu) { - if (mc_capable()) + if (topology_physical_package_id(0) != -1) c_id = topology_physical_package_id(cpu); else c_id = 0; /* force cluster 0 if no MC */ @@ -332,7 +332,7 @@ static int aml_thermal_probe(struct platform_device *pdev) } for_each_possible_cpu(cpu) { - if (mc_capable()) + if (topology_physical_package_id(0) != -1) c_id = topology_physical_package_id(cpu); else c_id = CLUSTER_BIG; /* Always cluster 0 if no mc */ diff --git a/drivers/amlogic/thermal/cpucore_cooling.c b/drivers/amlogic/thermal/cpucore_cooling.c index 0b0c7fc3c701..99502fda172b 100644 --- a/drivers/amlogic/thermal/cpucore_cooling.c +++ b/drivers/amlogic/thermal/cpucore_cooling.c @@ -140,7 +140,7 @@ static int cpucore_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { struct cpucore_cooling_device *cpucore_device = cdev->devdata; - int set_max_num, id; + int set_max_num, id, i, core_num; mutex_lock(&cooling_cpucore_lock); if (cpucore_device->stop_flag) { @@ -156,8 +156,24 @@ static int cpucore_set_cur_state(struct thermal_cooling_device *cdev, cpucore_device->cpucore_state = state; set_max_num = cpucore_device->max_cpu_core_num - state; id = cpucore_device->cluster_id; - pr_debug("set max cpu num=%d,state=%ld\n", set_max_num, state); - cpufreq_set_max_cpu_num(set_max_num, id); + if (id != CLUSTER_FLAG) { + pr_debug("set max cpu num=%d,state=%ld\n", + set_max_num, state); + cpufreq_set_max_cpu_num(set_max_num, id); + } else { + for (i = 0; i < MAX_CLUSTER; i++) { + pr_debug("%s, set max num: %d, cluster: %d\n", + __func__, set_max_num, i); + core_num = cpucore_device->core_num[i]; + if (set_max_num < core_num) { + cpufreq_set_max_cpu_num(set_max_num, i); + set_max_num = 0; + } else { + set_max_num = set_max_num - core_num; + cpufreq_set_max_cpu_num(core_num, i); + } + } + } } return 0; @@ -256,7 +272,7 @@ cpucore_cooling_register(struct device_node *np, int cluster_id) struct thermal_cooling_device *cool_dev; struct cpucore_cooling_device *cpucore_dev = NULL; char dev_name[THERMAL_NAME_LENGTH]; - int ret = 0, cpu; + int ret = 0, cpu, i; int cores = 0; cpucore_dev = kzalloc(sizeof(struct cpucore_cooling_device), @@ -270,7 +286,8 @@ cpucore_cooling_register(struct device_node *np, int cluster_id) return ERR_PTR(-EINVAL); } - if (mc_capable()) { + if ((topology_physical_package_id(0) != -1) + && (cluster_id != CLUSTER_FLAG)) { for_each_possible_cpu(cpu) { if (topology_physical_package_id(cpu) == cluster_id) cores++; @@ -283,6 +300,17 @@ cpucore_cooling_register(struct device_node *np, int cluster_id) snprintf(dev_name, sizeof(dev_name), "thermal-cpucore-%d", cpucore_dev->id); + if (cluster_id == CLUSTER_FLAG) { + for (i = MAX_CLUSTER - 1; i >= 0; i--) { + cores = 0; + for_each_possible_cpu(cpu) { + if (topology_physical_package_id(cpu) == i) + cores++; + } + cpucore_dev->core_num[i] = cores; + pr_info("%s, clutser[%d] core num:%d\n", __func__, i, cores); + } + } cool_dev = thermal_of_cooling_device_register(np, dev_name, cpucore_dev, &cpucore_cooling_ops); if (!cool_dev) { diff --git a/drivers/amlogic/thermal/meson_cooldev.c b/drivers/amlogic/thermal/meson_cooldev.c index db2c9e474f2d..b12bdd9714d7 100644 --- a/drivers/amlogic/thermal/meson_cooldev.c +++ b/drivers/amlogic/thermal/meson_cooldev.c @@ -232,7 +232,7 @@ int meson_cooldev_min_update(struct platform_device *pdev, int index) case COOL_DEV_TYPE_CPU_FREQ: for_each_possible_cpu(cpu) { - if (mc_capable()) + if (topology_physical_package_id(0) != -1) c_id = topology_physical_package_id(cpu); else c_id = 0; /* force cluster 0 if no MC */ @@ -349,10 +349,12 @@ static int parse_cool_device(struct platform_device *pdev) else cool->gpupp = temp; - if (of_property_read_u32(child, "cluster_id", &temp)) - pr_err("thermal: read cluster_id failed\n"); - else + if (of_property_read_u32(child, "cluster_id", &temp)) { + pr_info("thermal: no cluster id, cpucore as one cooldev\n"); + cool->cluster_id = CLUSTER_FLAG; + } else { cool->cluster_id = temp; + } if (of_property_read_string(child, "device_type", &str)) pr_err("thermal: read device_type failed\n");