All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srikar Srimath Tirumala <srikars@nvidia.com>
To: edubezval@gmail.com, rui.zhang@intel.com,
	srinivas.pandruvada@intel.com, linux-pm@vger.kernel.org,
	linux-tegra@vger.kernel.org
Cc: mlongnecker@nvidia.com, Srikar Srimath Tirumala <srikars@nvidia.com>
Subject: [PATCH v3 2/4] thermal: send notifications for tz temperature
Date: Tue, 29 Mar 2016 17:41:35 -0700	[thread overview]
Message-ID: <1459298497-29481-3-git-send-email-srikars@nvidia.com> (raw)
In-Reply-To: <1459298497-29481-1-git-send-email-srikars@nvidia.com>

* Update the 'temp' attr of a thermal_zone sysfs node, when the
  temperature goes above\below a trip point. Use sysfs_notify to send
  the notifications.

* Send the notification only if the temperature notifications are
  enabled. Use the hysteresis property to avoid sending too many
  notifications when the temperatures are bouncing around.

* Add ops that will allow thermal framework to:
  * find out if a temperature notification can be sent when a given
    trip point has been crossed.
  * get/set the trip state.

* Add a new state type for the trip points. A trip point can either
  be 'TRIPPED' or 'NOT_TRIPPED'.

Change-Id: If5b530b4045cdb2840eef855dc158cbce239ce79
Signed-off-by: Srikar Srimath Tirumala <srikars@nvidia.com>
---
 drivers/thermal/thermal_core.c | 28 ++++++++++++++++++++++++++++
 include/linux/thermal.h        | 12 ++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index b09fff1..37bdc32 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -419,6 +419,32 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
 	mutex_unlock(&tz->lock);
 }
 
+static void handle_temp_notify(struct thermal_zone_device *tz, int trip)
+{
+	int trip_temp, hyst = 0;
+	enum thermal_trip_state s, ns;
+
+	s = ns = THERMAL_TRIP_NOT_TRIPPED;
+	tz->ops->get_trip_temp(tz, trip, &trip_temp);
+	tz->ops->get_trip_hyst(tz, trip, &hyst);
+
+	if (tz->ops->get_trip_state)
+		tz->ops->get_trip_state(tz, trip, &s);
+
+	if (s == THERMAL_TRIP_TRIPPED && tz->temperature < trip_temp - hyst)
+		ns = THERMAL_TRIP_NOT_TRIPPED;
+	else if (s == THERMAL_TRIP_NOT_TRIPPED && tz->temperature >= trip_temp)
+		ns = THERMAL_TRIP_TRIPPED;
+
+	if (tz->ops->set_trip_state)
+		tz->ops->set_trip_state(tz, trip, ns);
+
+	/* send if notifications are enabled and state has changed */
+	if (s != ns && tz->ops->enb_temp_notify &&
+		tz->ops->enb_temp_notify(tz, trip))
+		sysfs_notify(&tz->device.kobj, NULL, "temp");
+}
+
 static void handle_non_critical_trips(struct thermal_zone_device *tz,
 			int trip, enum thermal_trip_type trip_type)
 {
@@ -464,6 +490,8 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
 		handle_critical_trips(tz, trip, type);
 	else
 		handle_non_critical_trips(tz, trip, type);
+
+	handle_temp_notify(tz, trip);
 	/*
 	 * Alright, we handled this trip successfully.
 	 * So, start monitoring again.
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index a55d052..9182e36 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -84,6 +84,11 @@ enum thermal_trip_type {
 	THERMAL_TRIP_CRITICAL,
 };
 
+enum thermal_trip_state {
+	THERMAL_TRIP_NOT_TRIPPED = 0,
+	THERMAL_TRIP_TRIPPED
+};
+
 enum thermal_trend {
 	THERMAL_TREND_STABLE, /* temperature is stable */
 	THERMAL_TREND_RAISING, /* temperature is raising */
@@ -114,6 +119,11 @@ struct thermal_zone_device_ops {
 			  enum thermal_trend *);
 	int (*notify) (struct thermal_zone_device *, int,
 		       enum thermal_trip_type);
+	int (*get_trip_state)(struct thermal_zone_device *, int,
+			enum thermal_trip_state *);
+	int (*set_trip_state)(struct thermal_zone_device *, int,
+			enum thermal_trip_state);
+	bool (*enb_temp_notify)(struct thermal_zone_device *, int);
 };
 
 struct thermal_cooling_device_ops {
@@ -348,6 +358,7 @@ struct thermal_zone_of_device_ops {
  * @temperature: temperature value in miliCelsius
  * @hysteresis: relative hysteresis in miliCelsius
  * @type: trip point type
+ * @state: trip point state
  */
 
 struct thermal_trip {
@@ -355,6 +366,7 @@ struct thermal_trip {
 	unsigned long int temperature;
 	unsigned long int hysteresis;
 	enum thermal_trip_type type;
+	enum thermal_trip_state state;
 };
 
 /* Function declarations */
-- 
2.1.4


  reply	other threads:[~2016-03-30  0:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30  0:41 [PATCH v3 0/4] add sysfs_notify on some attributes Srikar Srimath Tirumala
2016-03-30  0:41 ` Srikar Srimath Tirumala [this message]
     [not found]   ` <1459298497-29481-3-git-send-email-srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-03-30 16:43     ` [PATCH v3 2/4] thermal: send notifications for tz temperature Matt Longnecker
2016-03-30 16:53       ` Matt Longnecker
     [not found] ` <1459298497-29481-1-git-send-email-srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-03-30  0:41   ` [PATCH v3 1/4] thermal: send notifications for cdev state change Srikar Srimath Tirumala
     [not found]     ` <1459298497-29481-2-git-send-email-srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-03-30 16:45       ` Matt Longnecker
2016-03-30  0:41   ` [PATCH v3 3/4] thermal: of: enable temperature notifications Srikar Srimath Tirumala
2016-03-30 16:54     ` Matt Longnecker
     [not found]     ` <1459298497-29481-4-git-send-email-srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-05-03  3:26       ` Eduardo Valentin
2016-03-30  0:41   ` [PATCH v3 4/4] thermal: update documentation for new device ops Srikar Srimath Tirumala
     [not found]     ` <1459298497-29481-5-git-send-email-srikars-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-03-30 16:54       ` Matt Longnecker
2016-05-03  3:27     ` Eduardo Valentin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459298497-29481-3-git-send-email-srikars@nvidia.com \
    --to=srikars@nvidia.com \
    --cc=edubezval@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mlongnecker@nvidia.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.