Re: [PATCH V2 1/2] thermal: sysfs: Add a new sysfs node emul_temp for thermal emulation

2013-02-03 Thread amit kachhap
On Fri, Feb 1, 2013 at 12:27 AM, Zhang Rui rui.zh...@intel.com wrote:
 On Sun, 2013-01-27 at 19:28 -0800, Amit Daniel Kachhap wrote:
 This patch adds support to set the emulated temperature method in
 thermal zone (sensor). After setting this feature thermal zone may
 report this temperature and not the actual temperature. The emulation
 implementation may be based on sensor capability through platform
 specific handler or pure software emulation if no platform handler defined.

 This is useful in debugging different temperature threshold and its
 associated cooling action. Critical threshold's cannot be emulated.
 Writing 0 on this node should disable emulation.

 Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
 Acked-by: Kukjin Kim kgene@samsung.com
 ---

 Changes in V2:
 * Added config option for enabling emulation support.
 * Added s/w emulation if no platform handler registered.
 * skip the critical trip point emulation

 This patchset is based on thermal maintainer next tree.
 git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git next

  Documentation/thermal/sysfs-api.txt |   13 ++
  drivers/thermal/Kconfig |8 +++
  drivers/thermal/thermal_sys.c   |   82 
 ++-
  include/linux/thermal.h |2 +
  4 files changed, 94 insertions(+), 11 deletions(-)

 diff --git a/Documentation/thermal/sysfs-api.txt 
 b/Documentation/thermal/sysfs-api.txt
 index 526d4b9..6859661 100644
 --- a/Documentation/thermal/sysfs-api.txt
 +++ b/Documentation/thermal/sysfs-api.txt
 @@ -55,6 +55,8 @@ temperature) and throttle appropriate devices.
   .get_trip_type: get the type of certain trip point.
   .get_trip_temp: get the temperature above which the certain trip point
   will be fired.
 + .set_emul_temp: set the emulation temperature which helps in debugging
 + different threshold temperature points.

  1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)

 @@ -153,6 +155,7 @@ Thermal zone device sys I/F, created once it's 
 registered:
  |---trip_point_[0-*]_temp:   Trip point temperature
  |---trip_point_[0-*]_type:   Trip point type
  |---trip_point_[0-*]_hyst:   Hysteresis value for this trip point
 +|---emul_temp:   Emulated temperature set node

  Thermal cooling device sys I/F, created once it's registered:
  /sys/class/thermal/cooling_device[0-*]:
 @@ -252,6 +255,16 @@ passive
   Valid values: 0 (disabled) or greater than 1000
   RW, Optional

 +emul_temp
 + Interface to set the emulated temperature method in thermal zone
 + (sensor). After setting this temperature, the thermal zone may pass
 + this temperature to platform emulation function if registered or
 + cache it locally. This is useful in debugging different temperature
 + threshold and its associated cooling action. This is write only node
 + and writing 0 on this node should disable emulation.
 + Unit: millidegree Celsius
 + WO, Optional
 +
  *
  * Cooling device attributes *
  *
 diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
 index faf38c5..e4cf7fb 100644
 --- a/drivers/thermal/Kconfig
 +++ b/drivers/thermal/Kconfig
 @@ -78,6 +78,14 @@ config CPU_THERMAL
 and not the ACPI interface.
 If you want this support, you should say Y here.

 +config THERMAL_EMULATION
 + bool Thermal emulation mode support
 + help
 +   Enable this option to make a emul_temp sysfs node in thermal zone
 +   directory to support temperature emulation. With emulation sysfs 
 node,
 +   user can manually input temperature and test the different trip
 +   threshold behaviour for simulation purpose.
 +
  config SPEAR_THERMAL
   bool SPEAr thermal sensor driver
   depends on PLAT_SPEAR
 diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
 index 0a1bf6b..59ba709 100644
 --- a/drivers/thermal/thermal_sys.c
 +++ b/drivers/thermal/thermal_sys.c
 @@ -378,24 +378,57 @@ 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)
 +{
 + int ret = 0, count;
 + unsigned long crit_temp = -1UL;
 + enum thermal_trip_type type;
 +
 + mutex_lock(tz-lock);
 +
 + if (tz-ops-get_temp)
 + ret = tz-ops-get_temp(tz, temp);
 we do not need to do this check, .get_temp() should always be available.

 #ifdef CONFIG_THERMAL_EMUL
 + else
 + ret = -EPERM;
 +
 + if (!tz-emul_temperature)
 + goto skip_emul;
 +


 + for (count = 0; count  tz-trips; count++) {
 + ret = tz-ops-get_trip_type(tz, count, type);
 + if (!ret  type == THERMAL_TRIP_CRITICAL) {
 + ret = 

Re: [PATCH V2 1/2] thermal: sysfs: Add a new sysfs node emul_temp for thermal emulation

2013-02-01 Thread Zhang Rui
On Sun, 2013-01-27 at 19:28 -0800, Amit Daniel Kachhap wrote:
 This patch adds support to set the emulated temperature method in
 thermal zone (sensor). After setting this feature thermal zone may
 report this temperature and not the actual temperature. The emulation
 implementation may be based on sensor capability through platform
 specific handler or pure software emulation if no platform handler defined.
 
 This is useful in debugging different temperature threshold and its
 associated cooling action. Critical threshold's cannot be emulated.
 Writing 0 on this node should disable emulation.
 
 Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
 Acked-by: Kukjin Kim kgene@samsung.com
 ---
 
 Changes in V2:
 * Added config option for enabling emulation support.
 * Added s/w emulation if no platform handler registered.
 * skip the critical trip point emulation
 
 This patchset is based on thermal maintainer next tree.
 git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git next 
 
  Documentation/thermal/sysfs-api.txt |   13 ++
  drivers/thermal/Kconfig |8 +++
  drivers/thermal/thermal_sys.c   |   82 
 ++-
  include/linux/thermal.h |2 +
  4 files changed, 94 insertions(+), 11 deletions(-)
 
 diff --git a/Documentation/thermal/sysfs-api.txt 
 b/Documentation/thermal/sysfs-api.txt
 index 526d4b9..6859661 100644
 --- a/Documentation/thermal/sysfs-api.txt
 +++ b/Documentation/thermal/sysfs-api.txt
 @@ -55,6 +55,8 @@ temperature) and throttle appropriate devices.
   .get_trip_type: get the type of certain trip point.
   .get_trip_temp: get the temperature above which the certain trip point
   will be fired.
 + .set_emul_temp: set the emulation temperature which helps in debugging
 + different threshold temperature points.
  
  1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
  
 @@ -153,6 +155,7 @@ Thermal zone device sys I/F, created once it's registered:
  |---trip_point_[0-*]_temp:   Trip point temperature
  |---trip_point_[0-*]_type:   Trip point type
  |---trip_point_[0-*]_hyst:   Hysteresis value for this trip point
 +|---emul_temp:   Emulated temperature set node
  
  Thermal cooling device sys I/F, created once it's registered:
  /sys/class/thermal/cooling_device[0-*]:
 @@ -252,6 +255,16 @@ passive
   Valid values: 0 (disabled) or greater than 1000
   RW, Optional
  
 +emul_temp
 + Interface to set the emulated temperature method in thermal zone
 + (sensor). After setting this temperature, the thermal zone may pass
 + this temperature to platform emulation function if registered or
 + cache it locally. This is useful in debugging different temperature
 + threshold and its associated cooling action. This is write only node
 + and writing 0 on this node should disable emulation.
 + Unit: millidegree Celsius
 + WO, Optional
 +
  *
  * Cooling device attributes *
  *
 diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
 index faf38c5..e4cf7fb 100644
 --- a/drivers/thermal/Kconfig
 +++ b/drivers/thermal/Kconfig
 @@ -78,6 +78,14 @@ config CPU_THERMAL
 and not the ACPI interface.
 If you want this support, you should say Y here.
  
 +config THERMAL_EMULATION
 + bool Thermal emulation mode support
 + help
 +   Enable this option to make a emul_temp sysfs node in thermal zone
 +   directory to support temperature emulation. With emulation sysfs node,
 +   user can manually input temperature and test the different trip
 +   threshold behaviour for simulation purpose.
 +
  config SPEAR_THERMAL
   bool SPEAr thermal sensor driver
   depends on PLAT_SPEAR
 diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
 index 0a1bf6b..59ba709 100644
 --- a/drivers/thermal/thermal_sys.c
 +++ b/drivers/thermal/thermal_sys.c
 @@ -378,24 +378,57 @@ 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)
 +{
 + int ret = 0, count;
 + unsigned long crit_temp = -1UL;
 + enum thermal_trip_type type;
 +
 + mutex_lock(tz-lock);
 +
 + if (tz-ops-get_temp)
 + ret = tz-ops-get_temp(tz, temp);
we do not need to do this check, .get_temp() should always be available.

#ifdef CONFIG_THERMAL_EMUL
 + else
 + ret = -EPERM;
 +
 + if (!tz-emul_temperature)
 + goto skip_emul;
 +


 + for (count = 0; count  tz-trips; count++) {
 + ret = tz-ops-get_trip_type(tz, count, type);
 + if (!ret  type == THERMAL_TRIP_CRITICAL) {
 + ret = tz-ops-get_trip_temp(tz, count, crit_temp);
 +   

[PATCH V2 1/2] thermal: sysfs: Add a new sysfs node emul_temp for thermal emulation

2013-01-27 Thread Amit Daniel Kachhap
This patch adds support to set the emulated temperature method in
thermal zone (sensor). After setting this feature thermal zone may
report this temperature and not the actual temperature. The emulation
implementation may be based on sensor capability through platform
specific handler or pure software emulation if no platform handler defined.

This is useful in debugging different temperature threshold and its
associated cooling action. Critical threshold's cannot be emulated.
Writing 0 on this node should disable emulation.

Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
Acked-by: Kukjin Kim kgene@samsung.com
---

Changes in V2:
* Added config option for enabling emulation support.
* Added s/w emulation if no platform handler registered.
* skip the critical trip point emulation

This patchset is based on thermal maintainer next tree.
git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git next 

 Documentation/thermal/sysfs-api.txt |   13 ++
 drivers/thermal/Kconfig |8 +++
 drivers/thermal/thermal_sys.c   |   82 ++-
 include/linux/thermal.h |2 +
 4 files changed, 94 insertions(+), 11 deletions(-)

diff --git a/Documentation/thermal/sysfs-api.txt 
b/Documentation/thermal/sysfs-api.txt
index 526d4b9..6859661 100644
--- a/Documentation/thermal/sysfs-api.txt
+++ b/Documentation/thermal/sysfs-api.txt
@@ -55,6 +55,8 @@ temperature) and throttle appropriate devices.
.get_trip_type: get the type of certain trip point.
.get_trip_temp: get the temperature above which the certain trip point
will be fired.
+   .set_emul_temp: set the emulation temperature which helps in debugging
+   different threshold temperature points.
 
 1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 
@@ -153,6 +155,7 @@ Thermal zone device sys I/F, created once it's registered:
 |---trip_point_[0-*]_temp: Trip point temperature
 |---trip_point_[0-*]_type: Trip point type
 |---trip_point_[0-*]_hyst: Hysteresis value for this trip point
+|---emul_temp: Emulated temperature set node
 
 Thermal cooling device sys I/F, created once it's registered:
 /sys/class/thermal/cooling_device[0-*]:
@@ -252,6 +255,16 @@ passive
Valid values: 0 (disabled) or greater than 1000
RW, Optional
 
+emul_temp
+   Interface to set the emulated temperature method in thermal zone
+   (sensor). After setting this temperature, the thermal zone may pass
+   this temperature to platform emulation function if registered or
+   cache it locally. This is useful in debugging different temperature
+   threshold and its associated cooling action. This is write only node
+   and writing 0 on this node should disable emulation.
+   Unit: millidegree Celsius
+   WO, Optional
+
 *
 * Cooling device attributes *
 *
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index faf38c5..e4cf7fb 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -78,6 +78,14 @@ config CPU_THERMAL
  and not the ACPI interface.
  If you want this support, you should say Y here.
 
+config THERMAL_EMULATION
+   bool Thermal emulation mode support
+   help
+ Enable this option to make a emul_temp sysfs node in thermal zone
+ directory to support temperature emulation. With emulation sysfs node,
+ user can manually input temperature and test the different trip
+ threshold behaviour for simulation purpose.
+
 config SPEAR_THERMAL
bool SPEAr thermal sensor driver
depends on PLAT_SPEAR
diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 0a1bf6b..59ba709 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -378,24 +378,57 @@ 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)
+{
+   int ret = 0, count;
+   unsigned long crit_temp = -1UL;
+   enum thermal_trip_type type;
+
+   mutex_lock(tz-lock);
+
+   if (tz-ops-get_temp)
+   ret = tz-ops-get_temp(tz, temp);
+   else
+   ret = -EPERM;
+
+   if (!tz-emul_temperature)
+   goto skip_emul;
+
+   for (count = 0; count  tz-trips; count++) {
+   ret = tz-ops-get_trip_type(tz, count, type);
+   if (!ret  type == THERMAL_TRIP_CRITICAL) {
+   ret = tz-ops-get_trip_temp(tz, count, crit_temp);
+   break;
+   }
+   }
+
+   if (ret)
+   goto skip_emul;
+
+   if (*temp  crit_temp)
+   *temp = tz-emul_temperature;
+
+skip_emul:
+   mutex_unlock(tz-lock);
+