Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754927AbcCPAJj (ORCPT ); Tue, 15 Mar 2016 20:09:39 -0400 Received: from mga09.intel.com ([134.134.136.24]:62018 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbcCPAJi (ORCPT ); Tue, 15 Mar 2016 20:09:38 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,341,1455004800"; d="scan'208";a="911466838" From: "Pandruvada, Srinivas" To: "edubezval@gmail.com" , "Zhang, Rui" CC: "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" Subject: Re: [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Thread-Topic: [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Thread-Index: AQHRfxgf4DdrrZd0YU+DLY5y+b6HJA== Date: Wed, 16 Mar 2016 00:09:36 +0000 Message-ID: <1458083216.4486.42.camel@intel.com> References: <1450379609-7826-1-git-send-email-edubezval@gmail.com> <1450379609-7826-3-git-send-email-edubezval@gmail.com> In-Reply-To: <1450379609-7826-3-git-send-email-edubezval@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.254.53.46] Content-Type: text/plain; charset="utf-8" Content-ID: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u2G09k9f007131 Content-Length: 3363 Lines: 118 On Thu, 2015-12-17 at 11:13 -0800, Eduardo Valentin wrote: > 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 Reviewed-by: Srinivas Pandruvada > --- > V1-> V2: fixed real_temp initial value. > --- >  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..a229c84 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 = INT_MIN; >   > - 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); >