Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754558AbbL3Kiv (ORCPT ); Wed, 30 Dec 2015 05:38:51 -0500 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35284 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754375AbbL3Kit (ORCPT ); Wed, 30 Dec 2015 05:38:49 -0500 From: Leo Yan To: Zhang Rui , Eduardo Valentin , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, javi.merino@arm.com Cc: Leo Yan Subject: [PATCH v2] thermal: re-calculate k_po/k_pu when update sustainable power Date: Wed, 30 Dec 2015 18:38:40 +0800 Message-Id: <1451471920-2148-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1642 Lines: 47 k_po/k_pu are in essence ratio values compared with sustainable power. So when update sustainable power, we can recalculate k_po/k_pu simply with below formula: sustainable_power(new) k_p(new) = ---------------------- * k_p(old) sustainable_power(old) Signed-off-by: Leo Yan --- drivers/thermal/thermal_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d9e525c..223f8df 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -908,7 +908,7 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); - u32 sustainable_power; + u32 sustainable_power, old_val; if (!tz->tzp) return -EIO; @@ -916,8 +916,12 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr, if (kstrtou32(buf, 10, &sustainable_power)) return -EINVAL; + old_val = tz->tzp->sustainable_power; + tz->tzp->sustainable_power = sustainable_power; + tz->tzp->k_po = (tz->tzp->k_po * sustainable_power) / old_val; + tz->tzp->k_pu = (tz->tzp->k_pu * sustainable_power) / old_val; return count; } static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO, sustainable_power_show, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/