From patchwork Tue May 8 17:48:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 10386771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A72BD602C2 for ; Tue, 8 May 2018 17:49:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B2452903D for ; Tue, 8 May 2018 17:49:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F453290B3; Tue, 8 May 2018 17:49:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C7992903D for ; Tue, 8 May 2018 17:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751806AbeEHRtM (ORCPT ); Tue, 8 May 2018 13:49:12 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39008 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755452AbeEHRtJ (ORCPT ); Tue, 8 May 2018 13:49:09 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F1A4260881; Tue, 8 May 2018 17:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525801749; bh=lFNVHoqFKXzSq3bZ2cIrpXKVyTonebYXP1YIaDpkSdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ndiG5HUFqRUx/ITvrhGkLfSkKQCo4+Ukxt6rCap0BxzF7pqNFK26HaEVMU/msZyO5 mBHW0rk3E1B+o2Xa6nrbYtZv8KGxKERCv/s/Ku4b5BIj36szqQiMXRjktyojLKZswJ 2NIKk+k0EKCRCmfyx9Qn5jkvNFU76W5T8b+STJ10= Received: from codeaurora.org (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5354860881; Tue, 8 May 2018 17:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525801748; bh=lFNVHoqFKXzSq3bZ2cIrpXKVyTonebYXP1YIaDpkSdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EGzCdFOUedSTVewHnHysXIMTOvKDjbapP5mdYdDZaNqn+9LP9BVfP4rnT78uTxb/J kG3iCcspV+ujmf0BtXDtcJlY+8/Znrur+pQhvf8EjBxdETXoYqbJbGb+bZUUxdU/Nl eVcOyNfkH4WmgqK3JmgsPNqTvN4ibmLpO5esjrkU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5354860881 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org From: Lina Iyer To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, daniel.lezcano@linaro.org, amit.kucheria@linaro.org, Lina Iyer Subject: [PATCH RFC 3/4] drivers: of-thermal: aggregate sensor trips across thermal zones Date: Tue, 8 May 2018 11:48:58 -0600 Message-Id: <20180508174859.26539-4-ilina@codeaurora.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180508174859.26539-1-ilina@codeaurora.org> References: <20180508174859.26539-1-ilina@codeaurora.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Aggregate thermal trip based on the trip points of the thermal zones that use this sensor as the source. Signed-off-by: Lina Iyer --- drivers/thermal/of-thermal.c | 28 ++++++++++++++++++++++- drivers/thermal/thermal_helpers.c | 37 ++++++++++++++++++------------- include/linux/thermal.h | 4 ++++ 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 06e581a37c67..6fb2eeb5b6cf 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -96,16 +96,42 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz, return sensor->ops->get_temp(sensor->sensor_data, temp); } +static void __of_thermal_agg_trip(struct thermal_sensor *sensor, + int *floor, int *ceil) +{ + int low, high; + int max_lo = INT_MIN; + int min_hi = INT_MAX; + struct thermal_zone_device *tz; + + list_for_each_entry(tz, &sensor->tz_list, sensor_tzd) { + thermal_zone_get_trip(tz, &low, &high); + if (low > max_lo) + max_lo = low; + if (high < min_hi) + min_hi = high; + } + + *floor = max_lo; + *ceil = min_hi; +} + static int of_thermal_set_trips(struct thermal_zone_device *tz, int low, int high) { struct __thermal_zone *data = tz->devdata; struct thermal_sensor *sensor = data->sensor; + int ret; if (!sensor || !sensor->ops->set_trips) return -EINVAL; - return sensor->ops->set_trips(sensor->sensor_data, low, high); + mutex_lock(&sensor->lock); + __of_thermal_agg_trip(sensor, &low, &high); + ret = sensor->ops->set_trips(sensor->sensor_data, low, high); + mutex_unlock(&sensor->lock); + + return ret; } /** diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c index f550fdee0f9b..d4fa125f8799 100644 --- a/drivers/thermal/thermal_helpers.c +++ b/drivers/thermal/thermal_helpers.c @@ -113,32 +113,39 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) } EXPORT_SYMBOL_GPL(thermal_zone_get_temp); -void thermal_zone_set_trips(struct thermal_zone_device *tz) + +void thermal_zone_get_trip(struct thermal_zone_device *tz, int *low, int *high) { - int low = -INT_MAX; - int high = INT_MAX; - int trip_temp, hysteresis; - int i, ret; + int i, trip_low, trip_temp, hysteresis; - mutex_lock(&tz->lock); - - if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) - goto exit; + *low = -INT_MAX; + *high = INT_MAX; for (i = 0; i < tz->trips; i++) { - int trip_low; - tz->ops->get_trip_temp(tz, i, &trip_temp); tz->ops->get_trip_hyst(tz, i, &hysteresis); trip_low = trip_temp - hysteresis; - if (trip_low < tz->temperature && trip_low > low) - low = trip_low; + if (trip_low < tz->temperature && trip_low > *low) + *low = trip_low; - if (trip_temp > tz->temperature && trip_temp < high) - high = trip_temp; + if (trip_temp > tz->temperature && trip_temp < *high) + *high = trip_temp; } +} + +void thermal_zone_set_trips(struct thermal_zone_device *tz) +{ + int low, high; + int ret; + + mutex_lock(&tz->lock); + + if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) + goto exit; + + thermal_zone_get_trip(tz, &low, &high); /* No need to change trip points */ if (tz->prev_low_trip == low && tz->prev_high_trip == high) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 09e1669a4919..000ae6a97678 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -443,6 +443,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); +void thermal_zone_get_trip(struct thermal_zone_device *tz, int *low, int *high); void thermal_zone_set_trips(struct thermal_zone_device *); struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, @@ -496,6 +497,9 @@ static inline int thermal_zone_unbind_cooling_device( static inline void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { } +static inline void thermal_zone_get_trip(struct thermal_zone_device *tz, + int *low, int *high) +{ } static inline void thermal_zone_set_trips(struct thermal_zone_device *tz) { } static inline struct thermal_cooling_device *