From patchwork Wed Dec 16 03:49:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 7859341 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DD7FF9F32E for ; Wed, 16 Dec 2015 03:50:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08C86202BE for ; Wed, 16 Dec 2015 03:50:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24BA52020F for ; Wed, 16 Dec 2015 03:50:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965768AbbLPDtm (ORCPT ); Tue, 15 Dec 2015 22:49:42 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:36861 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965742AbbLPDtl (ORCPT ); Tue, 15 Dec 2015 22:49:41 -0500 Received: by mail-pa0-f52.google.com with SMTP id nt2so6460890pab.3; Tue, 15 Dec 2015 19:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ftlED3JGmsVy93nSLMm43YGPMie9Eh1AX0LHYiwi1Xc=; b=OtOhc4g8EYTiegMKFiHW4oWj7y9jFFb9e6U95Y1kmOmpjo0pvz+/PTojLZUhp5Rpiw nzCd9WO9yfP8C54EtLeapbyQLxc5QBG4au3CiUTDYfNIqDgi6wtGHUGxYmG5yx51tJyB uX8TkM9S7LG2vQyCMha946Lz4LJwG+mTMXF34dU1IahEqdbYZ+nYxZy5VmqVxmDKAzqP MBx/tbrSau+DfeGBm9Vvv5Vd1wFX19oC49iFKnfU0IDmzXYC4fp+ilDwI69OWsoWomH+ oAJ/f7T71lAwrg6VAK6X58Xw63mcp4j/i/jHhrG2PA9RK83ULg9JRAsi7QEyap7L21sR jieA== X-Received: by 10.67.5.98 with SMTP id cl2mr60369238pad.157.1450237780505; Tue, 15 Dec 2015 19:49:40 -0800 (PST) Received: from localhost ([2601:647:4203:c8e0:438:6288:1d0:4ac2]) by smtp.gmail.com with ESMTPSA id r193sm1048857pfr.65.2015.12.15.19.49.38 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 15 Dec 2015 19:49:39 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Date: Tue, 15 Dec 2015 19:49:13 -0800 Message-Id: <1450237754-31906-3-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450237754-31906-1-git-send-email-edubezval@gmail.com> References: <1450237754-31906-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the way we handle emul_temp. This is to allow emul_temp to be used as input to exercise thermal core properly. Now, even if .get_temp is not available, the emul_temp can be used to emulate temperature. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 8fa82c0..f826589 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -472,18 +472,25 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) { int ret = -EINVAL; - int count; - int crit_temp = INT_MAX; - enum thermal_trip_type type; + int crit_temp = INT_MAX, real_temp = crit_temp - 1; - if (!tz || IS_ERR(tz) || !tz->ops->get_temp) - goto exit; + if (!tz || IS_ERR(tz)) + return ret; mutex_lock(&tz->lock); - ret = tz->ops->get_temp(tz, temp); + /* Allow emulation if .get_temp is still not available */ + if (tz->ops->get_temp) { + ret = tz->ops->get_temp(tz, temp); + if (!ret) + real_temp = *temp; + } if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { + enum thermal_trip_type type; + int count; + + ret = 0; for (count = 0; count < tz->trips; count++) { ret = tz->ops->get_trip_type(tz, count, &type); if (!ret && type == THERMAL_TRIP_CRITICAL) { @@ -498,17 +505,17 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) * is below the critical temperature so that the emulation code * cannot hide critical conditions. */ - if (!ret && *temp < crit_temp) + if (!ret && real_temp < crit_temp) *temp = tz->emul_temperature; } mutex_unlock(&tz->lock); -exit: + return ret; } EXPORT_SYMBOL_GPL(thermal_zone_get_temp); -static void update_temperature(struct thermal_zone_device *tz) +static int update_temperature(struct thermal_zone_device *tz) { int temp, ret; @@ -518,7 +525,7 @@ static void update_temperature(struct thermal_zone_device *tz) dev_warn(&tz->device, "failed to read out thermal zone (%d)\n", ret); - return; + return ret; } mutex_lock(&tz->lock); @@ -529,17 +536,17 @@ static void update_temperature(struct thermal_zone_device *tz) trace_thermal_temperature(tz); dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n", tz->last_temperature, tz->temperature); + + return 0; } void thermal_zone_device_update(struct thermal_zone_device *tz) { int count; - if (!tz->ops->get_temp) + if (update_temperature(tz)) return; - update_temperature(tz); - for (count = 0; count < tz->trips; count++) handle_thermal_trip(tz, count);