Received: by 10.192.165.148 with SMTP id m20csp4591636imm; Tue, 8 May 2018 10:51:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpCKWbw0taWYQ8nsmAhaB64yxY2vVJII+GtsvUJaOxy9xUoO5UMx2wAopBaobARPBC58V45 X-Received: by 10.98.91.2 with SMTP id p2mr32663484pfb.96.1525801866143; Tue, 08 May 2018 10:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525801866; cv=none; d=google.com; s=arc-20160816; b=rPaXt+mMByzYA3mMIDscq8ae2UQsBS+CkPbhQcnrLF5c2uDH+hHkKv3S1QZ4zSlkby 8zGz0V8Q9rEuh8xDgzwybXyHdpf4+GkMiKCmWmrTUzzElb95wweZfjXU655smnxeqIY2 axcEl65nxE0e8VkHc6eAyvKiFlVjVWneuzX/3dAOu8U05OdZOK6J85vZUrMU0OIKXMB8 MH7MUkw/ETpa3AnbA2ffAJZvkEzona4pyr7hixMzhmryYyNoIVZA6dsHfn5MiJCdIhpb ghkv4j9waK0PMh9W8MILAclen+2gKhXSLtGxFbDUp+8SDTxid4i4Fz/amElh8zKEfB3o 6VrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=dYXHADXx+2HqzCt1K8Nf4klXmgw7dPC0yySzJ4MzIEs=; b=gF5o/acVCJ6IqlbqVODDgwadbX3J6cnPSYL5cChm1PBeBJCMXjdxTFu1UZd+Q5jRHZ K0yfIh47aHTL0q3DMC3IgfLMi7K+uy+KS5CgsHf4eBoP9xK89t5WANMRFg86DokKRnBE SXZNUUB3jhx2pcWxYemnCBNUKDWM8mDnKHjG8e+7g/a4Rm4TaFLROqsPzeEpu84X5T3k FXqOkt3kpV0u8Mbi3lyIAH4YiAUKgh8n+EqoOT9OqtnhMTmtPkO+OOqVO3clN5Yfb1UA uAMPWr3Ah8WqM+tWbZ4vdeNQDUnnxOvvFF06/jWPjRqWqYISpkyYQ0uOclsZCNqGwp0F ZCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ndiG5HUF; dkim=pass header.i=@codeaurora.org header.s=default header.b=EGzCdFOU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s12-v6si19624114pgp.48.2018.05.08.10.50.51; Tue, 08 May 2018 10:51:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ndiG5HUF; dkim=pass header.i=@codeaurora.org header.s=default header.b=EGzCdFOU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755601AbeEHRtO (ORCPT + 99 others); Tue, 8 May 2018 13:49:14 -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= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 * -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project