2013-04-05 12:33:00

by Eduardo Valentin

[permalink] [raw]
Subject: [PATCHv3 0/3] 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(-)

--
1.7.7.1.488.ge8e1c


2013-04-05 12:33:43

by Eduardo Valentin

[permalink] [raw]
Subject: [PATCHv3 2/3] thermal: expose thermal_zone_get_temp API

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

Acked-by: Durgadoss R <[email protected]>
Signed-off-by: Eduardo Valentin <[email protected]>
---
drivers/thermal/thermal_sys.c | 20 +++++++++++++++++---
include/linux/thermal.h | 1 +
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index e9b636b..83bfa0d 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -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)
{
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 0cf9eb5..8eea86c 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -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 *,
--
1.7.7.1.488.ge8e1c

2013-04-05 12:34:04

by Eduardo Valentin

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

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.

Signed-off-by: Eduardo Valentin <[email protected]>
---
drivers/staging/ti-soc-thermal/ti-thermal-common.c | 30 +++++++++++++------
1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/ti-soc-thermal/ti-thermal-common.c b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
index 231c549..780368b 100644
--- a/drivers/staging/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
@@ -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;
--
1.7.7.1.488.ge8e1c

2013-04-05 12:38:21

by Eduardo Valentin

[permalink] [raw]
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.

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).

Cc: Durgadoss R <[email protected]>
Signed-off-by: Eduardo Valentin <[email protected]>
---
drivers/thermal/thermal_sys.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/thermal.h | 1 +
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 5bd95d4..e9b636b 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -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,
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 542a39c..0cf9eb5 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -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

2013-04-05 12:47:50

by R, Durgadoss

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

> -----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.
>
> 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).
>
> Cc: Durgadoss R <[email protected]>
> Signed-off-by: Eduardo Valentin <[email protected]>

Looks okay to me.
Acked-by: Durgadoss R <[email protected]>

Thanks,
Durga

> ---
> drivers/thermal/thermal_sys.c | 38
> ++++++++++++++++++++++++++++++++++++++
> include/linux/thermal.h | 1 +
> 2 files changed, 39 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> index 5bd95d4..e9b636b 100644
> --- a/drivers/thermal/thermal_sys.c
> +++ b/drivers/thermal/thermal_sys.c
> @@ -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,
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 542a39c..0cf9eb5 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -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

2013-04-15 01:43:22

by Zhang Rui

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

On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
> 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).
>
> Cc: Durgadoss R <[email protected]>
> Signed-off-by: Eduardo Valentin <[email protected]>

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

thanks,
rui
> ---
> drivers/thermal/thermal_sys.c | 38 ++++++++++++++++++++++++++++++++++++++
> include/linux/thermal.h | 1 +
> 2 files changed, 39 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> index 5bd95d4..e9b636b 100644
> --- a/drivers/thermal/thermal_sys.c
> +++ b/drivers/thermal/thermal_sys.c
> @@ -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,
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 542a39c..0cf9eb5 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -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 *,

2013-04-15 01:43:59

by Zhang Rui

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

On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
> This patch exports the thermal_zone_get_temp API so that driver
> writers can fetch temperature of thermal zones managed by other
> drivers.
>
> Acked-by: Durgadoss R <[email protected]>
> Signed-off-by: Eduardo Valentin <[email protected]>

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

thanks,
rui

> ---
> drivers/thermal/thermal_sys.c | 20 +++++++++++++++++---
> include/linux/thermal.h | 1 +
> 2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> index e9b636b..83bfa0d 100644
> --- a/drivers/thermal/thermal_sys.c
> +++ b/drivers/thermal/thermal_sys.c
> @@ -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)
> {
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 0cf9eb5..8eea86c 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -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 *,

2013-04-15 01:44:23

by Zhang Rui

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

On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
> 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.
>
> Signed-off-by: Eduardo Valentin <[email protected]>

hmm, who should take this patch?

thanks,
rui
> ---
> drivers/staging/ti-soc-thermal/ti-thermal-common.c | 30 +++++++++++++------
> 1 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/ti-soc-thermal/ti-thermal-common.c b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
> index 231c549..780368b 100644
> --- a/drivers/staging/ti-soc-thermal/ti-thermal-common.c
> +++ b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
> @@ -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;

2013-04-15 13:21:16

by Eduardo Valentin

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

On 14-04-2013 21:43, Zhang Rui wrote:
> On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
>> 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).
>>
>> Cc: Durgadoss R <[email protected]>
>> Signed-off-by: Eduardo Valentin <[email protected]>
>
> refreshed the patch to modify drivers/thermal/thermal_core.c instead of
> drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks.

>
> thanks,
> rui
>> ---
>> drivers/thermal/thermal_sys.c | 38 ++++++++++++++++++++++++++++++++++++++
>> include/linux/thermal.h | 1 +
>> 2 files changed, 39 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
>> index 5bd95d4..e9b636b 100644
>> --- a/drivers/thermal/thermal_sys.c
>> +++ b/drivers/thermal/thermal_sys.c
>> @@ -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,
>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>> index 542a39c..0cf9eb5 100644
>> --- a/include/linux/thermal.h
>> +++ b/include/linux/thermal.h
>> @@ -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 *,
>
>
>
>

2013-04-15 13:22:11

by Eduardo Valentin

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

On 14-04-2013 21:43, Zhang Rui wrote:
> On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
>> This patch exports the thermal_zone_get_temp API so that driver
>> writers can fetch temperature of thermal zones managed by other
>> drivers.
>>
>> Acked-by: Durgadoss R <[email protected]>
>> Signed-off-by: Eduardo Valentin <[email protected]>
>
> refreshed the patch to modify drivers/thermal/thermal_core.c instead of
> drivers/thermal/thermal_sys.c and applied to thermal -next.

Thanks!

>
> thanks,
> rui
>
>> ---
>> drivers/thermal/thermal_sys.c | 20 +++++++++++++++++---
>> include/linux/thermal.h | 1 +
>> 2 files changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
>> index e9b636b..83bfa0d 100644
>> --- a/drivers/thermal/thermal_sys.c
>> +++ b/drivers/thermal/thermal_sys.c
>> @@ -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)
>> {
>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>> index 0cf9eb5..8eea86c 100644
>> --- a/include/linux/thermal.h
>> +++ b/include/linux/thermal.h
>> @@ -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 *,
>
>
>
>

2013-04-15 13:24:28

by Eduardo Valentin

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

On 14-04-2013 21:44, Zhang Rui wrote:
> On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
>> 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.
>>
>> Signed-off-by: Eduardo Valentin <[email protected]>
>
> 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.



> thanks,
> rui
>> ---
>> drivers/staging/ti-soc-thermal/ti-thermal-common.c | 30 +++++++++++++------
>> 1 files changed, 20 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/staging/ti-soc-thermal/ti-thermal-common.c b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
>> index 231c549..780368b 100644
>> --- a/drivers/staging/ti-soc-thermal/ti-thermal-common.c
>> +++ b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
>> @@ -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;
>
>
>
>

2013-04-17 19:10:54

by Eduardo Valentin

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

On 15-04-2013 09:22, Eduardo Valentin wrote:
> On 14-04-2013 21:43, Zhang Rui wrote:
>> On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
>>> This patch exports the thermal_zone_get_temp API so that driver
>>> writers can fetch temperature of thermal zones managed by other
>>> drivers.
>>>
>>> Acked-by: Durgadoss R <[email protected]>
>>> Signed-off-by: Eduardo Valentin <[email protected]>
>>
>> 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.
>
>>
>> thanks,
>> rui
>>
>>> ---
>>> drivers/thermal/thermal_sys.c | 20 +++++++++++++++++---
>>> include/linux/thermal.h | 1 +
>>> 2 files changed, 18 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/thermal/thermal_sys.c
>>> b/drivers/thermal/thermal_sys.c
>>> index e9b636b..83bfa0d 100644
>>> --- a/drivers/thermal/thermal_sys.c
>>> +++ b/drivers/thermal/thermal_sys.c
>>> @@ -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)
>>> {
>>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>>> index 0cf9eb5..8eea86c 100644
>>> --- a/include/linux/thermal.h
>>> +++ b/include/linux/thermal.h
>>> @@ -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 *,
>>
>>
>>
>>
>
>
>

2013-04-17 19:12:25

by Eduardo Valentin

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

On 15-04-2013 09:21, Eduardo Valentin wrote:
> On 14-04-2013 21:43, Zhang Rui wrote:
>> On Fri, 2013-04-05 at 08:32 -0400, Eduardo Valentin wrote:
>>> 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).
>>>
>>> Cc: Durgadoss R <[email protected]>
>>> Signed-off-by: Eduardo Valentin <[email protected]>
>>
>> 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.

>
>>
>> thanks,
>> rui
>>> ---
>>> drivers/thermal/thermal_sys.c | 38
>>> ++++++++++++++++++++++++++++++++++++++
>>> include/linux/thermal.h | 1 +
>>> 2 files changed, 39 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/thermal/thermal_sys.c
>>> b/drivers/thermal/thermal_sys.c
>>> index 5bd95d4..e9b636b 100644
>>> --- a/drivers/thermal/thermal_sys.c
>>> +++ b/drivers/thermal/thermal_sys.c
>>> @@ -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,
>>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>>> index 542a39c..0cf9eb5 100644
>>> --- a/include/linux/thermal.h
>>> +++ b/include/linux/thermal.h
>>> @@ -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 *,
>>
>>
>>
>>
>
>
>