Received: by 10.192.165.148 with SMTP id m20csp4591489imm; Tue, 8 May 2018 10:50:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqNGBo9jiFHWFFmMEHsxpxi5AwCCbrawccUmamtp57hRqYim9ecErxjRr/eg94zNkTvBjhI X-Received: by 2002:a63:744a:: with SMTP id e10-v6mr29358347pgn.275.1525801857552; Tue, 08 May 2018 10:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525801857; cv=none; d=google.com; s=arc-20160816; b=abCWADzXaWqh8K3tNGGE97F7Cv9At8JDMEBLJbMcSmoOFdNpnKs4loZgwt3Pv7SA4p msracUv74lAaBxS+Vo4aSZS3T8Xq4ZVUg3dBf9arHIY/zWbLTHKP/GSdVd1D+w7noQiF wGJhV3qHkZ/PonhUND7rCYoZO4bLNbzG3LzhusD2LyfLHqynqow3AQ58iioV8dNGTZxW EtJgFtMEqAqYpS1ecMckFfF/zo8pEll5EI/L6EjUO2rXie4bkqQsyPjVkmVQ1X8ORtwJ R9ZYp8vxu4iLqVDAUoHgz8XqJYPpHHRS2gJHR9iDfFB6AjDtILIFz7yszlxZCF2415qR tpXA== 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=96cq8jbPFT1/TuRN1sqJAYkBTNVgwA+hn2LdgSSyJts=; b=rXcu5VP+fkwX2eVAz6ZXyO0+d2LSdUj1QOuAqIM5H49ORbLpwUyXsaavyNQfLjm8Bl NuaLFEicOXiAhOZj8we9GZYSNwwPVZmLXMun/CSY9yTzx0Dct2vVaaaEoJW52VRM0IPI Hst0B42hLa7lz8alUjeKFSt1nS9vE3gqB/TxGzK8r8eI3KupG1Zd+zPPY8C0E7zfC7vB z4n78kKBsNDjdVyVx23ssLoyvlw1CyfR7Scw9WrUtVPTrGyq4ZvCk7nnDF5GBiklDl0S W9a/vAXZ05eyMpuHLQipTgdh8NoEYXZYeBOvai9lgld/lwkUgHPZihALFaii62vYlFJg FcKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=pLvcKFma; dkim=pass header.i=@codeaurora.org header.s=default header.b=cdudUWpR; 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 h8si15433303pfi.115.2018.05.08.10.50.43; Tue, 08 May 2018 10:50:57 -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=pLvcKFma; dkim=pass header.i=@codeaurora.org header.s=default header.b=cdudUWpR; 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 S1755675AbeEHRt4 (ORCPT + 99 others); Tue, 8 May 2018 13:49:56 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39118 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755466AbeEHRtK (ORCPT ); Tue, 8 May 2018 13:49:10 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3155A60B23; Tue, 8 May 2018 17:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525801750; bh=oDd4hLgvRO4DlIbOhRua2DJNe4LyyqjkeYO4R4GGjCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLvcKFmaXHdHTYYudDoOu/gJcAfgsAWu4Sz727pFpfWNZgjCiaX7ay7NToj6kdudS 0DkUPmh1odUWMoeBSszuwCe68S0zTOUbRXL+/Mk40Jcbgy1LOCdD4fYsC++KBRd2cN E9lqA1eNm12OJYpdglK6NIK72Epix9XvIiy0cxGc= 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 4A7E06085F; 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=oDd4hLgvRO4DlIbOhRua2DJNe4LyyqjkeYO4R4GGjCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cdudUWpRGmTA2YEMd39f7Y28o9IkWf5P+RG8TfxfDFt/eBvWmxuTBSWpkcpT3IebJ LAr2V6j5ALYzfWH0WaxT5xXRZASYX7e8dZ+Bm1Oeblq/Xt+kmcvyxOaHcFA3bK1S1E e+S7f0cHqk5cN4M+fI6ljmKkQzFLn0lpdQCsjGWQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4A7E06085F 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 4/4] drivers: of-thermal: notify framework when sensor is tripped Date: Tue, 8 May 2018 11:48:59 -0600 Message-Id: <20180508174859.26539-5-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 Notify all related thermal zones when the sensor reports a thermal trip. Signed-off-by: Lina Iyer --- drivers/thermal/of-thermal.c | 83 ++++++++++++++++++++++++++++++++++-- include/linux/thermal.h | 4 ++ 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 6fb2eeb5b6cf..9b42bfed78bf 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -41,12 +41,18 @@ struct __thermal_bind_params { * @ops: sensor driver ops * @tz_list: list of thermal zones for this sensor * @lock: lock sensor during operations + * @low_trip: sensor's low trip temp + * @high_trip: sensor's high trip temp + * @low_tz: the thermal zone whose low trip is used as @low_trip + * @high_tz: the thermal zone whose high trip is used as @high_trip */ struct thermal_sensor { void *sensor_data; const struct thermal_zone_of_device_ops *ops; struct list_head tz_list; struct mutex lock; + int low_trip, high_trip; + struct thermal_zone_device *low_tz, *high_tz; }; /** @@ -102,18 +108,26 @@ static void __of_thermal_agg_trip(struct thermal_sensor *sensor, int low, high; int max_lo = INT_MIN; int min_hi = INT_MAX; - struct thermal_zone_device *tz; + struct thermal_zone_device *tz, *lo_tz = NULL, *hi_tz = NULL; list_for_each_entry(tz, &sensor->tz_list, sensor_tzd) { thermal_zone_get_trip(tz, &low, &high); - if (low > max_lo) + if (low > max_lo) { max_lo = low; - if (high < min_hi) + lo_tz = tz; + } + if (high < min_hi) { min_hi = high; + hi_tz = tz; + } } *floor = max_lo; *ceil = min_hi; + sensor->low_trip = max_lo; + sensor->high_trip = min_hi; + sensor->low_tz = lo_tz; + sensor->high_tz = hi_tz; } static int of_thermal_set_trips(struct thermal_zone_device *tz, @@ -427,6 +441,69 @@ static struct thermal_zone_device_ops of_thermal_ops = { /*** sensor API ***/ +static void thermal_zone_of_get_trip(struct thermal_zone_device *tz, + int temp, int *low_trip, int *hi_trip) +{ + struct __thermal_zone *data = tz->devdata; + int low = INT_MIN; + int hi = INT_MAX; + int i; + + for (i = 0; i < data->ntrips; i++) { + int trip_temp = data->trips[i].temperature; + + if (trip_temp < temp && trip_temp > low) + *low_trip = i; + if (trip_temp > temp && trip_temp < hi) + *hi_trip = i; + } +} + +/** + * thermal_zone_of_sensor_notify - notify framework of a trip + * @tzd: the thermal zone device + * + * Sensor drivers may use this API to notify the thermal framework that the + * temperature has crossed the trip threshold. This function is akin to + * thermal_notify_framework() call, but is expected to be called by a sensor + * that registered itself with the framework using the + * thermal_zone_of_add_sensor() function. + */ +void thermal_zone_of_sensor_notify(struct thermal_zone_device *tzd) +{ + struct __thermal_zone *tz = tzd->devdata; + struct thermal_sensor *sensor = tz->sensor; + int temp, low_trip, hi_trip, *trip; + struct thermal_zone_device *trip_tz = NULL; + + if (!tz->sensor) + return; + + if (of_thermal_get_temp(tzd, &temp)) + return; + + mutex_lock(&sensor->lock); + if (tzd->temperature < sensor->low_trip && sensor->low_tz) { + trip_tz = sensor->low_tz; + trip = &low_trip; + } + if (tzd->temperature > sensor->high_trip && sensor->high_tz) { + trip_tz = sensor->high_tz; + trip = &hi_trip; + } + + if (trip_tz) + thermal_zone_of_get_trip(trip_tz, temp, &low_trip, &hi_trip); + + mutex_unlock(&sensor->lock); + + if (!trip_tz) + return; + + thermal_notify_framework(trip_tz, *trip); +} +EXPORT_SYMBOL(thermal_zone_of_sensor_notify); + static struct thermal_zone_device * thermal_zone_of_add_sensor(struct device_node *zone, struct device_node *sensor_np, diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 000ae6a97678..603bf8065d7d 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -388,6 +388,7 @@ struct thermal_zone_device *devm_thermal_zone_of_sensor_register( const struct thermal_zone_of_device_ops *ops); void devm_thermal_zone_of_sensor_unregister(struct device *dev, struct thermal_zone_device *tz); +void thermal_zone_of_sensor_notify(struct thermal_zone_device *tzd); #else static inline struct thermal_zone_device * thermal_zone_of_sensor_register(struct device *dev, int id, void *data, @@ -415,6 +416,9 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev, { } +static inline +void thermal_zone_of_sensor_notify(struct thermal_zone_device *tzd) +{ } #endif #if IS_ENABLED(CONFIG_THERMAL) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project