Skip to contentSkip to conversation

thermal: lookup temperature

PATCH In review Eduardo Valentin 3 participants 13 messages Apr 5, 2013 – Apr 17, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover thermal: lookup temperature

Hello Rui,

Here is V3 of temperature lookup helper function. This has been split into two API as suggested on V1 and now the API returns an specific error code for multiple matches, as suggested in V2.

The usage of it is exemplified on patch 03.

Eduardo Valentin (3):
thermal: introduce thermal_zone_get_zone_by_name helper function
thermal: expose thermal_zone_get_temp API
staging: ti-soc-thermal: remove external heat while extrapolating
hotspot

 drivers/staging/ti-soc-thermal/ti-thermal-common.c |   30 +++++++----
 drivers/thermal/thermal_sys.c                      |   58 +++++++++++++++++++-
 include/linux/thermal.h                            |    2 +
 3 files changed, 77 insertions(+), 13 deletions(-)
Signature · 1 line
1.7.7.1.488.ge8e1c
#1 lore raw

PATCH v3 1/3 thermal: introduce thermal_zone_get_zone_by_name helper function

This patch adds a helper function to get a reference of a thermal zone, based on the zone type name.

It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR).

---
 drivers/thermal/thermal_sys.c |   38 ++++++++++++++++++++++++++++++++++++++
 include/linux/thermal.h       |    1 +
 2 files changed, 39 insertions(+), 0 deletions(-)
drivers/thermal/thermal_sys.c +38 -0
index 5bd95d4..e9b636b 100644
@@ -1790,6 +1790,44 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
 
+/**
+ * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
+ * @name: thermal zone name to fetch the temperature
+ *
+ * When only one zone is found with the passed name, returns a reference to it.
+ *
+ * Return: On success returns a reference to an unique thermal zone with
+ * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
+ * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
+{
+	struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
+	unsigned int found = 0;
+
+	if (!name)
+		goto exit;
+
+	mutex_lock(&thermal_list_lock);
+	list_for_each_entry(pos, &thermal_tz_list, node)
+		if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
+			found++;
+			ref = pos;
+		}
+	mutex_unlock(&thermal_list_lock);
+
+	/* nothing has been found, thus an error code for it */
+	if (found == 0)
+		ref = ERR_PTR(-ENODEV);
+	else if (found > 1)
+	/* Success only when an unique zone is found */
+		ref = ERR_PTR(-EEXIST);
+
+exit:
+	return ref;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
+
 #ifdef CONFIG_NET
 static struct genl_family thermal_event_genl_family = {
 	.id = GENL_ID_GENERATE,
include/linux/thermal.h +1 -0
index 542a39c..0cf9eb5 100644
@@ -237,6 +237,7 @@ void thermal_zone_device_update(struct thermal_zone_device *);
 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
 		const struct thermal_cooling_device_ops *);
 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
 
 int thermal_zone_trend_get(struct thermal_zone_device *, int);
 struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
Signature · 1 line
1.7.7.1.488.ge8e1c
Acked-by on v3 1/3
#2 lore raw

RE: [PATCHv3 1/3] thermal: introduce thermal_zone_get_zone_by_name helper function

Quoted 12 lines

-----Original Message-----
From: Eduardo Valentin [mailto:[email protected]]
Sent: Friday, April 05, 2013 6:02 PM
To: Zhang, Rui
Cc: [email protected]; [email protected]; R, Durgadoss; Eduardo Valentin
Subject: [PATCHv3 1/3] thermal: introduce thermal_zone_get_zone_by_name helper function

This patch adds a helper function to get a reference of a thermal zone, based on the zone type name.

Quoted 8 lines

It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR).

Looks okay to me.

Thanks,
Durga

Quoted 78 lines
---
 drivers/thermal/thermal_sys.c |   38
++++++++++++++++++++++++++++++++++++++
 include/linux/thermal.h       |    1 +
 2 files changed, 39 insertions(+), 0 deletions(-)
drivers/thermal/thermal_sys.c +2 -0
index 5bd95d4..e9b636b 100644
@@ -1790,6 +1790,44 @@ void thermal_zone_device_unregister(struct
 thermal_zone_device *tz)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
 
+/**
+ * thermal_zone_get_zone_by_name() - search for a zone and returns its

ref
+ * @name: thermal zone name to fetch the temperature
+ *
+ * When only one zone is found with the passed name, returns a reference to it.
+ *
+ * Return: On success returns a reference to an unique thermal zone with
+ * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
+ * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)

drivers/thermal/thermal_sys.c +27 -0
+{
+	struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
+	unsigned int found = 0;
+
+	if (!name)
+		goto exit;
+
+	mutex_lock(&thermal_list_lock);
+	list_for_each_entry(pos, &thermal_tz_list, node)
+		if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
+			found++;
+			ref = pos;
+		}
+	mutex_unlock(&thermal_list_lock);
+
+	/* nothing has been found, thus an error code for it */
+	if (found == 0)
+		ref = ERR_PTR(-ENODEV);
+	else if (found > 1)
+	/* Success only when an unique zone is found */
+		ref = ERR_PTR(-EEXIST);
+
+exit:
+	return ref;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
+
 #ifdef CONFIG_NET
 static struct genl_family thermal_event_genl_family = {
 	.id = GENL_ID_GENERATE,
include/linux/thermal.h +1 -0
index 542a39c..0cf9eb5 100644
@@ -237,6 +237,7 @@ void thermal_zone_device_update(struct
 thermal_zone_device *);
 struct thermal_cooling_device *thermal_cooling_device_register(char *,
 void *,
 		const struct thermal_cooling_device_ops *);
 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const
 char *name);

int thermal_zone_trend_get(struct thermal_zone_device *, int); struct thermal_instance *thermal_instance_get(struct
thermal_zone_device *,
--
1.7.7.1.488.ge8e1c

reviewer
#3 lore raw

Re: [PATCHv3 1/3] thermal: introduce thermal_zone_get_zone_by_name helper function

In reply to Eduardo Valentin
Quoted 11 lines · Eduardo Valentin

This patch adds a helper function to get a reference of a thermal zone, based on the zone type name.

It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR).

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

thanks,
rui

Quoted 66 lines
---
 drivers/thermal/thermal_sys.c |   38 ++++++++++++++++++++++++++++++++++++++
 include/linux/thermal.h       |    1 +
 2 files changed, 39 insertions(+), 0 deletions(-)
drivers/thermal/thermal_sys.c +38 -0
index 5bd95d4..e9b636b 100644
@@ -1790,6 +1790,44 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
 
+/**
+ * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
+ * @name: thermal zone name to fetch the temperature
+ *
+ * When only one zone is found with the passed name, returns a reference to it.
+ *
+ * Return: On success returns a reference to an unique thermal zone with
+ * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
+ * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
+{
+	struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
+	unsigned int found = 0;
+
+	if (!name)
+		goto exit;
+
+	mutex_lock(&thermal_list_lock);
+	list_for_each_entry(pos, &thermal_tz_list, node)
+		if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
+			found++;
+			ref = pos;
+		}
+	mutex_unlock(&thermal_list_lock);
+
+	/* nothing has been found, thus an error code for it */
+	if (found == 0)
+		ref = ERR_PTR(-ENODEV);
+	else if (found > 1)
+	/* Success only when an unique zone is found */
+		ref = ERR_PTR(-EEXIST);
+
+exit:
+	return ref;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
+
 #ifdef CONFIG_NET
 static struct genl_family thermal_event_genl_family = {
 	.id = GENL_ID_GENERATE,
include/linux/thermal.h +1 -0
index 542a39c..0cf9eb5 100644
@@ -237,6 +237,7 @@ void thermal_zone_device_update(struct thermal_zone_device *);
 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
 		const struct thermal_cooling_device_ops *);
 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
 
 int thermal_zone_trend_get(struct thermal_zone_device *, int);
 struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
#4 lore raw

Re: [PATCHv3 1/3] thermal: introduce thermal_zone_get_zone_by_name helper function

Quoted 10 lines · Zhang Rui
Quoted 9 lines · Eduardo Valentin

This patch adds a helper function to get a reference of a thermal zone, based on the zone type name.

It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR).

Quoted 5 lines
Quoted 2 lines

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks.

Quoted 73 lines

thanks,
rui

Quoted 66 lines
---
  drivers/thermal/thermal_sys.c |   38 ++++++++++++++++++++++++++++++++++++++
  include/linux/thermal.h       |    1 +
  2 files changed, 39 insertions(+), 0 deletions(-)
drivers/thermal/thermal_sys.c +38 -0
index 5bd95d4..e9b636b 100644
@@ -1790,6 +1790,44 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
  }
  EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
 
+/**
+ * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
+ * @name: thermal zone name to fetch the temperature
+ *
+ * When only one zone is found with the passed name, returns a reference to it.
+ *
+ * Return: On success returns a reference to an unique thermal zone with
+ * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
+ * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
+{
+	struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
+	unsigned int found = 0;
+
+	if (!name)
+		goto exit;
+
+	mutex_lock(&thermal_list_lock);
+	list_for_each_entry(pos, &thermal_tz_list, node)
+		if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
+			found++;
+			ref = pos;
+		}
+	mutex_unlock(&thermal_list_lock);
+
+	/* nothing has been found, thus an error code for it */
+	if (found == 0)
+		ref = ERR_PTR(-ENODEV);
+	else if (found > 1)
+	/* Success only when an unique zone is found */
+		ref = ERR_PTR(-EEXIST);
+
+exit:
+	return ref;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
+
  #ifdef CONFIG_NET
  static struct genl_family thermal_event_genl_family = {
  	.id = GENL_ID_GENERATE,
include/linux/thermal.h +1 -0
index 542a39c..0cf9eb5 100644
@@ -237,6 +237,7 @@ void thermal_zone_device_update(struct thermal_zone_device *);
  struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
  		const struct thermal_cooling_device_ops *);
  void thermal_cooling_device_unregister(struct thermal_cooling_device *);
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
 
  int thermal_zone_trend_get(struct thermal_zone_device *, int);
  struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
#5 lore raw

Re: [PATCHv3 1/3] thermal: introduce thermal_zone_get_zone_by_name helper function

Quoted 11 lines · Eduardo Valentin
Quoted 10 lines · Zhang Rui
Quoted 9 lines · Eduardo Valentin

This patch adds a helper function to get a reference of a thermal zone, based on the zone type name.

It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR).

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks.

Just a gentle reminder, this one does not seam to be applied to thermal/next.

Quoted 91 lines
Quoted 88 lines

thanks,
rui

Quoted 80 lines
---
  drivers/thermal/thermal_sys.c |   38
++++++++++++++++++++++++++++++++++++++
  include/linux/thermal.h       |    1 +
  2 files changed, 39 insertions(+), 0 deletions(-)
drivers/thermal/thermal_sys.c +2 -0
index 5bd95d4..e9b636b 100644
@@ -1790,6 +1790,44 @@ void thermal_zone_device_unregister(struct
 thermal_zone_device *tz)
  }
  EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
 
+/**
+ * thermal_zone_get_zone_by_name() - search for a zone and returns

its ref
+ * @name: thermal zone name to fetch the temperature
+ *
+ * When only one zone is found with the passed name, returns a reference to it.
+ *
+ * Return: On success returns a reference to an unique thermal zone with
+ * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
+ * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)

drivers/thermal/thermal_sys.c +27 -0
+{
+    struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
+    unsigned int found = 0;
+
+    if (!name)
+        goto exit;
+
+    mutex_lock(&thermal_list_lock);
+    list_for_each_entry(pos, &thermal_tz_list, node)
+        if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
+            found++;
+            ref = pos;
+        }
+    mutex_unlock(&thermal_list_lock);
+
+    /* nothing has been found, thus an error code for it */
+    if (found == 0)
+        ref = ERR_PTR(-ENODEV);
+    else if (found > 1)
+    /* Success only when an unique zone is found */
+        ref = ERR_PTR(-EEXIST);
+
+exit:
+    return ref;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
+
  #ifdef CONFIG_NET
  static struct genl_family thermal_event_genl_family = {
      .id = GENL_ID_GENERATE,
include/linux/thermal.h +1 -0
index 542a39c..0cf9eb5 100644
@@ -237,6 +237,7 @@ void thermal_zone_device_update(struct
 thermal_zone_device *);
  struct thermal_cooling_device *thermal_cooling_device_register(char
 *, void *,
          const struct thermal_cooling_device_ops *);
  void thermal_cooling_device_unregister(struct
 thermal_cooling_device *);
+struct thermal_zone_device *thermal_zone_get_zone_by_name(const char

*name);

int thermal_zone_trend_get(struct thermal_zone_device *, int); struct thermal_instance *thermal_instance_get(struct
thermal_zone_device *,

#6 lore raw

PATCH v3 2/3 thermal: expose thermal_zone_get_temp API

In reply to Eduardo Valentin

This patch exports the thermal_zone_get_temp API so that driver writers can fetch temperature of thermal zones managed by other drivers.

---
 drivers/thermal/thermal_sys.c |   20 +++++++++++++++++---
 include/linux/thermal.h       |    1 +
 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sys.c +17 -3
index e9b636b..83bfa0d 100644
@@ -371,16 +371,28 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
 	monitor_thermal_zone(tz);
 }
 
-static int thermal_zone_get_temp(struct thermal_zone_device *tz,
-				unsigned long *temp)
+/**
+ * thermal_zone_get_temp() - returns its the temperature of thermal zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
 {
-	int ret = 0;
+	int ret = -EINVAL;
 #ifdef CONFIG_THERMAL_EMULATION
 	int count;
 	unsigned long crit_temp = -1UL;
 	enum thermal_trip_type type;
 #endif
 
+	if (IS_ERR_OR_NULL(tz))
+		goto exit;
+
 	mutex_lock(&tz->lock);
 
 	ret = tz->ops->get_temp(tz, temp);
@@ -404,8 +416,10 @@ static int thermal_zone_get_temp(struct thermal_zone_device *tz,
 skip_emul:
 #endif
 	mutex_unlock(&tz->lock);
+exit:
 	return ret;
 }
+EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
 
 static void update_temperature(struct thermal_zone_device *tz)
 {
include/linux/thermal.h +1 -0
index 0cf9eb5..8eea86c 100644
@@ -238,6 +238,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
 		const struct thermal_cooling_device_ops *);
 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);
 
 int thermal_zone_trend_get(struct thermal_zone_device *, int);
 struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
Signature · 1 line
1.7.7.1.488.ge8e1c
reviewer
#7 lore raw

Re: [PATCHv3 2/3] thermal: expose thermal_zone_get_temp API

Quoted 6 lines · Eduardo Valentin

This patch exports the thermal_zone_get_temp API so that driver writers can fetch temperature of thermal zones managed by other drivers.

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

thanks,
rui

Quoted 64 lines
---
 drivers/thermal/thermal_sys.c |   20 +++++++++++++++++---
 include/linux/thermal.h       |    1 +
 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sys.c +17 -3
index e9b636b..83bfa0d 100644
@@ -371,16 +371,28 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
 	monitor_thermal_zone(tz);
 }
 
-static int thermal_zone_get_temp(struct thermal_zone_device *tz,
-				unsigned long *temp)
+/**
+ * thermal_zone_get_temp() - returns its the temperature of thermal zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
 {
-	int ret = 0;
+	int ret = -EINVAL;
 #ifdef CONFIG_THERMAL_EMULATION
 	int count;
 	unsigned long crit_temp = -1UL;
 	enum thermal_trip_type type;
 #endif
 
+	if (IS_ERR_OR_NULL(tz))
+		goto exit;
+
 	mutex_lock(&tz->lock);
 
 	ret = tz->ops->get_temp(tz, temp);
@@ -404,8 +416,10 @@ static int thermal_zone_get_temp(struct thermal_zone_device *tz,
 skip_emul:
 #endif
 	mutex_unlock(&tz->lock);
+exit:
 	return ret;
 }
+EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
 
 static void update_temperature(struct thermal_zone_device *tz)
 {
include/linux/thermal.h +1 -0
index 0cf9eb5..8eea86c 100644
@@ -238,6 +238,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
 		const struct thermal_cooling_device_ops *);
 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);
 
 int thermal_zone_trend_get(struct thermal_zone_device *, int);
 struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
#8 lore raw

Re: [PATCHv3 2/3] thermal: expose thermal_zone_get_temp API

Quoted 10 lines · Zhang Rui
Quoted 6 lines · Eduardo Valentin

This patch exports the thermal_zone_get_temp API so that driver writers can fetch temperature of thermal zones managed by other drivers.

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks!

Quoted 72 lines

thanks,
rui

Quoted 64 lines
---
  drivers/thermal/thermal_sys.c |   20 +++++++++++++++++---
  include/linux/thermal.h       |    1 +
  2 files changed, 18 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sys.c +17 -3
index e9b636b..83bfa0d 100644
@@ -371,16 +371,28 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
  	monitor_thermal_zone(tz);
  }
 
-static int thermal_zone_get_temp(struct thermal_zone_device *tz,
-				unsigned long *temp)
+/**
+ * thermal_zone_get_temp() - returns its the temperature of thermal zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
  {
-	int ret = 0;
+	int ret = -EINVAL;
  #ifdef CONFIG_THERMAL_EMULATION
  	int count;
  	unsigned long crit_temp = -1UL;
  	enum thermal_trip_type type;
  #endif
 
+	if (IS_ERR_OR_NULL(tz))
+		goto exit;
+
  	mutex_lock(&tz->lock);
 
  	ret = tz->ops->get_temp(tz, temp);
@@ -404,8 +416,10 @@ static int thermal_zone_get_temp(struct thermal_zone_device *tz,
  skip_emul:
  #endif
  	mutex_unlock(&tz->lock);
+exit:
  	return ret;
  }
+EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
 
  static void update_temperature(struct thermal_zone_device *tz)
  {
include/linux/thermal.h +1 -0
index 0cf9eb5..8eea86c 100644
@@ -238,6 +238,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
  		const struct thermal_cooling_device_ops *);
  void thermal_cooling_device_unregister(struct thermal_cooling_device *);
  struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);
 
  int thermal_zone_trend_get(struct thermal_zone_device *, int);
  struct thermal_instance *thermal_instance_get(struct thermal_zone_device *,
#9 lore raw

Re: [PATCHv3 2/3] thermal: expose thermal_zone_get_temp API

Quoted 6 lines · Eduardo Valentin
Quoted 5 lines · Zhang Rui
Quoted 4 lines · Eduardo Valentin

This patch exports the thermal_zone_get_temp API so that driver writers can fetch temperature of thermal zones managed by other drivers.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

refreshed the patch to modify drivers/thermal/thermal_core.c instead of drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks!

Just a gentle reminder, this one does not seam to be applied to thermal/next.

Quoted 86 lines
Quoted 83 lines

thanks,
rui

Quoted 74 lines
---
  drivers/thermal/thermal_sys.c |   20 +++++++++++++++++---
  include/linux/thermal.h       |    1 +
  2 files changed, 18 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sys.c +2 -2
index e9b636b..83bfa0d 100644
@@ -371,16 +371,28 @@ static void handle_thermal_trip(struct
 thermal_zone_device *tz, int trip)
      monitor_thermal_zone(tz);
  }
 
-static int thermal_zone_get_temp(struct thermal_zone_device *tz,
-                unsigned long *temp)
+/**
+ * thermal_zone_get_temp() - returns its the temperature of thermal

zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
{

drivers/thermal/thermal_sys.c +6 -1
-    int ret = 0;
+    int ret = -EINVAL;
  #ifdef CONFIG_THERMAL_EMULATION
      int count;
      unsigned long crit_temp = -1UL;
      enum thermal_trip_type type;
  #endif
 
+    if (IS_ERR_OR_NULL(tz))
+        goto exit;
+
      mutex_lock(&tz->lock);
 
      ret = tz->ops->get_temp(tz, temp);
@@ -404,8 +416,10 @@ static int thermal_zone_get_temp(struct
 thermal_zone_device *tz,
  skip_emul:
  #endif
      mutex_unlock(&tz->lock);
+exit:
      return ret;
  }
+EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
 
  static void update_temperature(struct thermal_zone_device *tz)
  {
include/linux/thermal.h +1 -0
index 0cf9eb5..8eea86c 100644
@@ -238,6 +238,7 @@ struct thermal_cooling_device
 *thermal_cooling_device_register(char *, void *,
          const struct thermal_cooling_device_ops *);
  void thermal_cooling_device_unregister(struct
 thermal_cooling_device *);
  struct thermal_zone_device *thermal_zone_get_zone_by_name(const
 char *name);
+int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned

long *temp);

int thermal_zone_trend_get(struct thermal_zone_device *, int); struct thermal_instance *thermal_instance_get(struct
thermal_zone_device *,

#10 lore raw

PATCH v3 3/3 staging: ti-soc-thermal: remove external heat while extrapolating hotspot

In reply to Eduardo Valentin

For boards that provide a PCB sensor close to SoC junction temperature, it is possible to remove the cumulative heat reported by the SoC temperature sensor.

This patch changes the extrapolation computation to consider an external sensor in the extrapolation equations.

---
 drivers/staging/ti-soc-thermal/ti-thermal-common.c |   30 +++++++++++++------
 1 files changed, 20 insertions(+), 10 deletions(-)
drivers/staging/ti-soc-thermal/ti-thermal-common.c +20 -10
index 231c549..780368b 100644
@@ -38,6 +38,7 @@
 /* common data structures */
 struct ti_thermal_data {
 	struct thermal_zone_device *ti_thermal;
+	struct thermal_zone_device *pcb_tz;
 	struct thermal_cooling_device *cool_dev;
 	struct ti_bandgap *bgp;
 	enum thermal_device_mode mode;
@@ -77,10 +78,12 @@ static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
 static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
 				      unsigned long *temp)
 {
+	struct thermal_zone_device *pcb_tz = NULL;
 	struct ti_thermal_data *data = thermal->devdata;
 	struct ti_bandgap *bgp;
 	const struct ti_temp_sensor *s;
-	int ret, tmp, pcb_temp, slope, constant;
+	int ret, tmp, slope, constant;
+	unsigned long pcb_temp;
 
 	if (!data)
 		return 0;
@@ -92,16 +95,22 @@ static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
 	if (ret)
 		return ret;
 
-	pcb_temp = 0;
-	/* TODO: Introduce pcb temperature lookup */
+	/* Default constants */
+	slope = s->slope;
+	constant = s->constant;
+
+	pcb_tz = data->pcb_tz;
 	/* In case pcb zone is available, use the extrapolation rule with it */
-	if (pcb_temp) {
-		tmp -= pcb_temp;
-		slope = s->slope_pcb;
-		constant = s->constant_pcb;
-	} else {
-		slope = s->slope;
-		constant = s->constant;
+	if (!IS_ERR_OR_NULL(pcb_tz)) {
+		ret = thermal_zone_get_temp(pcb_tz, &pcb_temp);
+		if (!ret) {
+			tmp -= pcb_temp; /* got a valid PCB temp */
+			slope = s->slope_pcb;
+			constant = s->constant_pcb;
+		} else {
+			dev_err(bgp->dev,
+				"Failed to read PCB state. Using defaults\n");
+		}
 	}
 	*temp = ti_thermal_hotspot_temperature(tmp, slope, constant);
 
@@ -248,6 +257,7 @@ static struct ti_thermal_data
 	data->sensor_id = id;
 	data->bgp = bgp;
 	data->mode = THERMAL_DEVICE_ENABLED;
+	data->pcb_tz = thermal_zone_get_zone_by_name("pcb");
 	INIT_WORK(&data->thermal_wq, ti_thermal_work);
 
 	return data;
Signature · 1 line
1.7.7.1.488.ge8e1c
reviewer
#11 lore raw

Re: [PATCHv3 3/3] staging: ti-soc-thermal: remove external heat while extrapolating hotspot

Quoted 8 lines · Eduardo Valentin

For boards that provide a PCB sensor close to SoC junction temperature, it is possible to remove the cumulative heat reported by the SoC temperature sensor.

This patch changes the extrapolation computation to consider an external sensor in the extrapolation equations.

hmm, who should take this patch?

thanks,
rui

Quoted 70 lines
---
 drivers/staging/ti-soc-thermal/ti-thermal-common.c |   30 +++++++++++++------
 1 files changed, 20 insertions(+), 10 deletions(-)
drivers/staging/ti-soc-thermal/ti-thermal-common.c +20 -10
index 231c549..780368b 100644
@@ -38,6 +38,7 @@
 /* common data structures */
 struct ti_thermal_data {
 	struct thermal_zone_device *ti_thermal;
+	struct thermal_zone_device *pcb_tz;
 	struct thermal_cooling_device *cool_dev;
 	struct ti_bandgap *bgp;
 	enum thermal_device_mode mode;
@@ -77,10 +78,12 @@ static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
 static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
 				      unsigned long *temp)
 {
+	struct thermal_zone_device *pcb_tz = NULL;
 	struct ti_thermal_data *data = thermal->devdata;
 	struct ti_bandgap *bgp;
 	const struct ti_temp_sensor *s;
-	int ret, tmp, pcb_temp, slope, constant;
+	int ret, tmp, slope, constant;
+	unsigned long pcb_temp;
 
 	if (!data)
 		return 0;
@@ -92,16 +95,22 @@ static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
 	if (ret)
 		return ret;
 
-	pcb_temp = 0;
-	/* TODO: Introduce pcb temperature lookup */
+	/* Default constants */
+	slope = s->slope;
+	constant = s->constant;
+
+	pcb_tz = data->pcb_tz;
 	/* In case pcb zone is available, use the extrapolation rule with it */
-	if (pcb_temp) {
-		tmp -= pcb_temp;
-		slope = s->slope_pcb;
-		constant = s->constant_pcb;
-	} else {
-		slope = s->slope;
-		constant = s->constant;
+	if (!IS_ERR_OR_NULL(pcb_tz)) {
+		ret = thermal_zone_get_temp(pcb_tz, &pcb_temp);
+		if (!ret) {
+			tmp -= pcb_temp; /* got a valid PCB temp */
+			slope = s->slope_pcb;
+			constant = s->constant_pcb;
+		} else {
+			dev_err(bgp->dev,
+				"Failed to read PCB state. Using defaults\n");
+		}
 	}
 	*temp = ti_thermal_hotspot_temperature(tmp, slope, constant);
 
@@ -248,6 +257,7 @@ static struct ti_thermal_data
 	data->sensor_id = id;
 	data->bgp = bgp;
 	data->mode = THERMAL_DEVICE_ENABLED;
+	data->pcb_tz = thermal_zone_get_zone_by_name("pcb");
 	INIT_WORK(&data->thermal_wq, ti_thermal_work);
 
 	return data;
#12 lore raw

Re: [PATCHv3 3/3] staging: ti-soc-thermal: remove external heat while extrapolating hotspot

Quoted 5 lines · Zhang Rui
Quoted 4 lines · Eduardo Valentin

For boards that provide a PCB sensor close to SoC junction temperature, it is possible to remove the cumulative heat reported by the SoC temperature sensor.

Quoted 7 lines
Quoted 4 lines

This patch changes the extrapolation computation to consider an external sensor in the extrapolation equations.

hmm, who should take this patch?

I will send this one to Greg, maintainer of the staging tree.

BTW, Rui, do you think there is still time to send the TI driver out of the drivers/staging/ti-soc-thermal to drivers/thermal/ti-soc-thermal for 3.10? If yes, I can send a series straight away.

Quoted 76 lines

thanks,
rui

Quoted 70 lines
---
  drivers/staging/ti-soc-thermal/ti-thermal-common.c |   30 +++++++++++++------
  1 files changed, 20 insertions(+), 10 deletions(-)
drivers/staging/ti-soc-thermal/ti-thermal-common.c +20 -10
index 231c549..780368b 100644
@@ -38,6 +38,7 @@
  /* common data structures */
  struct ti_thermal_data {
  	struct thermal_zone_device *ti_thermal;
+	struct thermal_zone_device *pcb_tz;
  	struct thermal_cooling_device *cool_dev;
  	struct ti_bandgap *bgp;
  	enum thermal_device_mode mode;
@@ -77,10 +78,12 @@ static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
  static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
  				      unsigned long *temp)
  {
+	struct thermal_zone_device *pcb_tz = NULL;
  	struct ti_thermal_data *data = thermal->devdata;
  	struct ti_bandgap *bgp;
  	const struct ti_temp_sensor *s;
-	int ret, tmp, pcb_temp, slope, constant;
+	int ret, tmp, slope, constant;
+	unsigned long pcb_temp;
 
  	if (!data)
  		return 0;
@@ -92,16 +95,22 @@ static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
  	if (ret)
  		return ret;
 
-	pcb_temp = 0;
-	/* TODO: Introduce pcb temperature lookup */
+	/* Default constants */
+	slope = s->slope;
+	constant = s->constant;
+
+	pcb_tz = data->pcb_tz;
  	/* In case pcb zone is available, use the extrapolation rule with it */
-	if (pcb_temp) {
-		tmp -= pcb_temp;
-		slope = s->slope_pcb;
-		constant = s->constant_pcb;
-	} else {
-		slope = s->slope;
-		constant = s->constant;
+	if (!IS_ERR_OR_NULL(pcb_tz)) {
+		ret = thermal_zone_get_temp(pcb_tz, &pcb_temp);
+		if (!ret) {
+			tmp -= pcb_temp; /* got a valid PCB temp */
+			slope = s->slope_pcb;
+			constant = s->constant_pcb;
+		} else {
+			dev_err(bgp->dev,
+				"Failed to read PCB state. Using defaults\n");
+		}
  	}
  	*temp = ti_thermal_hotspot_temperature(tmp, slope, constant);
 
@@ -248,6 +257,7 @@ static struct ti_thermal_data
  	data->sensor_id = id;
  	data->bgp = bgp;
  	data->mode = THERMAL_DEVICE_ENABLED;
+	data->pcb_tz = thermal_zone_get_zone_by_name("pcb");
  	INIT_WORK(&data->thermal_wq, ti_thermal_work);
 
  	return data;