Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-28 Thread Eduardo Valentin

Durga,


On 05-02-2013 06:46, Durgadoss R wrote:

This patch creates a thermal map sysfs node under
/sys/class/thermal/zoneX/. This contains
entries named mapY_trip_type, mapY_sensor_name,
mapY_cdev_name, mapY_trip_mask, mapY_weights.



Some of the previous comments apply here as well, specially wrt to 
devm_, snprintf and strlcpy. Also the documentation for the exported 
functions are welcome.




Signed-off-by: Durgadoss R 
---
  drivers/thermal/thermal_sys.c |  221 -
  include/linux/thermal.h   |   25 +
  2 files changed, 244 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 69a60a4..e284b67 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone *tz,
tz->cdev_indx--;
  }

+static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
+{
+   int i;
+   struct thermal_map_attr *attr = tz->map_attr[indx];
+
+   for (i = 0; i < NUM_MAP_ATTRS; i++)
+   device_remove_file(>device, >attrs[i].attr);
+
+   kfree(tz->map_attr[indx]);
+   tz->map[indx] = NULL;
+}
+
+static void remove_sensor_map_entry(struct thermal_zone *tz,
+   struct thermal_sensor *ts)
+{
+   int i;
+
+   for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
+   if (tz->map[i] && !strnicmp(ts->name, tz->map[i]->sensor_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
+static void remove_cdev_map_entry(struct thermal_zone *tz,
+   struct thermal_cooling_device *cdev)
+{
+   int i;
+
+   for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
+   if (tz->map[i] && !strnicmp(cdev->type, tz->map[i]->cdev_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
  /* sys I/F for thermal zone */

  #define to_thermal_zone(_dev) \
@@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
*devattr, char *buf)
  }

  static ssize_t
+map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char *trip;
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_trip_type", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");


Is this condition possible? If yes, we probably need to change the code 
so that if the map is not present, the sysfs files are also removed.



+
+   trip = (tz->map[indx]->trip_type == THERMAL_TRIP_ACTIVE) ?
+   "active" : "passive";
+   return sprintf(buf, "%s\n", trip);
+}
+
+static ssize_t map_ts_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_sensor_name", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");


ditto


+
+   return sprintf(buf, "%s\n", tz->map[indx]->sensor_name);
+}
+
+static ssize_t map_cdev_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_cdev_name", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");


ditto


+
+   return sprintf(buf, "%s\n", tz->map[indx]->cdev_name);
+}
+
+static ssize_t map_trip_mask_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_trip_mask", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");


ditto


+
+   return sprintf(buf, "0x%x\n", tz->map[indx]->trip_mask);
+}
+
+static ssize_t map_weights_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int i, indx, ret = 0;
+   struct thermal_map *map;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_weights", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= 

Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-28 Thread Eduardo Valentin

Durga,


On 05-02-2013 06:46, Durgadoss R wrote:

This patch creates a thermal map sysfs node under
/sys/class/thermal/zoneX/. This contains
entries named mapY_trip_type, mapY_sensor_name,
mapY_cdev_name, mapY_trip_mask, mapY_weights.



Some of the previous comments apply here as well, specially wrt to 
devm_, snprintf and strlcpy. Also the documentation for the exported 
functions are welcome.




Signed-off-by: Durgadoss R durgados...@intel.com
---
  drivers/thermal/thermal_sys.c |  221 -
  include/linux/thermal.h   |   25 +
  2 files changed, 244 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 69a60a4..e284b67 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone *tz,
tz-cdev_indx--;
  }

+static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
+{
+   int i;
+   struct thermal_map_attr *attr = tz-map_attr[indx];
+
+   for (i = 0; i  NUM_MAP_ATTRS; i++)
+   device_remove_file(tz-device, attr-attrs[i].attr);
+
+   kfree(tz-map_attr[indx]);
+   tz-map[indx] = NULL;
+}
+
+static void remove_sensor_map_entry(struct thermal_zone *tz,
+   struct thermal_sensor *ts)
+{
+   int i;
+
+   for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
+   if (tz-map[i]  !strnicmp(ts-name, tz-map[i]-sensor_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
+static void remove_cdev_map_entry(struct thermal_zone *tz,
+   struct thermal_cooling_device *cdev)
+{
+   int i;
+
+   for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
+   if (tz-map[i]  !strnicmp(cdev-type, tz-map[i]-cdev_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
  /* sys I/F for thermal zone */

  #define to_thermal_zone(_dev) \
@@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
*devattr, char *buf)
  }

  static ssize_t
+map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char *trip;
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_trip_type, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);


Is this condition possible? If yes, we probably need to change the code 
so that if the map is not present, the sysfs files are also removed.



+
+   trip = (tz-map[indx]-trip_type == THERMAL_TRIP_ACTIVE) ?
+   active : passive;
+   return sprintf(buf, %s\n, trip);
+}
+
+static ssize_t map_ts_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_sensor_name, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);


ditto


+
+   return sprintf(buf, %s\n, tz-map[indx]-sensor_name);
+}
+
+static ssize_t map_cdev_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_cdev_name, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);


ditto


+
+   return sprintf(buf, %s\n, tz-map[indx]-cdev_name);
+}
+
+static ssize_t map_trip_mask_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_trip_mask, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);


ditto


+
+   return sprintf(buf, 0x%x\n, tz-map[indx]-trip_mask);
+}
+
+static ssize_t map_weights_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int i, indx, ret = 0;
+   struct thermal_map *map;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_weights, indx))
+   return -EINVAL;
+
+   if (indx  0 

RE: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread Zhang Rui
On Fri, 2013-02-08 at 02:08 -0700, R, Durgadoss wrote:
> Hi Rui,
> 
> > -Original Message-
> > From: Zhang, Rui
> > Sent: Friday, February 08, 2013 2:35 PM
> > To: R, Durgadoss
> > Cc: linux...@vger.kernel.org; linux-kernel@vger.kernel.org;
> > eduardo.valen...@ti.com; hongbo.zh...@linaro.org; w...@nvidia.com
> > Subject: Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a
> > zone
> > 
> > On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
> > > This patch creates a thermal map sysfs node under
> > > /sys/class/thermal/zoneX/. This contains
> > > entries named mapY_trip_type, mapY_sensor_name,
> > > mapY_cdev_name, mapY_trip_mask, mapY_weights.
> > sorry I still not quite understand.
> > 
> > does it look like?
> > /sys/class/thermal/zoneX/
> > |
> > map-->|-->map0_trip_type
> >   |...
> >   |-->map0_weight
> >   |-->map1_trip_type
> >   |...
> >   |-->map1_weight
> >   |...
> > 
> 
> There is no separate 'map' directory.
> So, everything is under /sys/class/thermal/zoneX/ directly,
> named as map0_weight etc...
> 
got it.

thanks,
rui

> I think I should make the Doc/ABI patch should clarify this.
> 
> Thanks,
> Durga


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread R, Durgadoss
Hi Rui,

> -Original Message-
> From: Zhang, Rui
> Sent: Friday, February 08, 2013 2:35 PM
> To: R, Durgadoss
> Cc: linux...@vger.kernel.org; linux-kernel@vger.kernel.org;
> eduardo.valen...@ti.com; hongbo.zh...@linaro.org; w...@nvidia.com
> Subject: Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a
> zone
> 
> On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
> > This patch creates a thermal map sysfs node under
> > /sys/class/thermal/zoneX/. This contains
> > entries named mapY_trip_type, mapY_sensor_name,
> > mapY_cdev_name, mapY_trip_mask, mapY_weights.
> sorry I still not quite understand.
> 
> does it look like?
> /sys/class/thermal/zoneX/
> |
> map-->|-->map0_trip_type
>   |...
>   |-->map0_weight
>   |-->map1_trip_type
>   |...
>   |-->map1_weight
>   |...
> 

There is no separate 'map' directory.
So, everything is under /sys/class/thermal/zoneX/ directly,
named as map0_weight etc...

I think I should make the Doc/ABI patch should clarify this.

Thanks,
Durga


Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread Zhang Rui
On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
> This patch creates a thermal map sysfs node under
> /sys/class/thermal/zoneX/. This contains
> entries named mapY_trip_type, mapY_sensor_name,
> mapY_cdev_name, mapY_trip_mask, mapY_weights.
sorry I still not quite understand.

does it look like?
/sys/class/thermal/zoneX/
|
map-->|-->map0_trip_type
  |...
  |-->map0_weight
  |-->map1_trip_type
  |...
  |-->map1_weight
  |...

thanks,
rui
> 
> Signed-off-by: Durgadoss R 
> ---
>  drivers/thermal/thermal_sys.c |  221 
> -
>  include/linux/thermal.h   |   25 +
>  2 files changed, 244 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> index 69a60a4..e284b67 100644
> --- a/drivers/thermal/thermal_sys.c
> +++ b/drivers/thermal/thermal_sys.c
> @@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone 
> *tz,
>   tz->cdev_indx--;
>  }
>  
> +static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
> +{
> + int i;
> + struct thermal_map_attr *attr = tz->map_attr[indx];
> +
> + for (i = 0; i < NUM_MAP_ATTRS; i++)
> + device_remove_file(>device, >attrs[i].attr);
> +
> + kfree(tz->map_attr[indx]);
> + tz->map[indx] = NULL;
> +}
> +
> +static void remove_sensor_map_entry(struct thermal_zone *tz,
> + struct thermal_sensor *ts)
> +{
> + int i;
> +
> + for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
> + if (tz->map[i] && !strnicmp(ts->name, tz->map[i]->sensor_name,
> + THERMAL_NAME_LENGTH)) {
> + __remove_map_entry(tz, i);
> + }
> + }
> +}
> +
> +static void remove_cdev_map_entry(struct thermal_zone *tz,
> + struct thermal_cooling_device *cdev)
> +{
> + int i;
> +
> + for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
> + if (tz->map[i] && !strnicmp(cdev->type, tz->map[i]->cdev_name,
> + THERMAL_NAME_LENGTH)) {
> + __remove_map_entry(tz, i);
> + }
> + }
> +}
> +
>  /* sys I/F for thermal zone */
>  
>  #define to_thermal_zone(_dev) \
> @@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
> *devattr, char *buf)
>  }
>  
>  static ssize_t
> +map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + char *trip;
> + int indx;
> + struct thermal_zone *tz = to_zone(dev);
> +
> + if (!sscanf(attr->attr.name, "map%d_trip_type", ))
> + return -EINVAL;
> +
> + if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
> + return -EINVAL;
> +
> + if (!tz->map[indx])
> + return sprintf(buf, "\n");
> +
> + trip = (tz->map[indx]->trip_type == THERMAL_TRIP_ACTIVE) ?
> + "active" : "passive";
> + return sprintf(buf, "%s\n", trip);
> +}
> +
> +static ssize_t map_ts_name_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + int indx;
> + struct thermal_zone *tz = to_zone(dev);
> +
> + if (!sscanf(attr->attr.name, "map%d_sensor_name", ))
> + return -EINVAL;
> +
> + if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
> + return -EINVAL;
> +
> + if (!tz->map[indx])
> + return sprintf(buf, "\n");
> +
> + return sprintf(buf, "%s\n", tz->map[indx]->sensor_name);
> +}
> +
> +static ssize_t map_cdev_name_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + int indx;
> + struct thermal_zone *tz = to_zone(dev);
> +
> + if (!sscanf(attr->attr.name, "map%d_cdev_name", ))
> + return -EINVAL;
> +
> + if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
> + return -EINVAL;
> +
> + if (!tz->map[indx])
> + return sprintf(buf, "\n");
> +
> + return sprintf(buf, "%s\n", tz->map[indx]->cdev_name);
> +}
> +
> +static ssize_t map_trip_mask_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + int indx;
> + struct thermal_zone *tz = to_zone(dev);
> +
> + if (!sscanf(attr->attr.name, "map%d_trip_mask", ))
> + return -EINVAL;
> +
> + if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
> + return -EINVAL;
> +
> + if (!tz->map[indx])
> + return sprintf(buf, "\n");
> +
> + return sprintf(buf, "0x%x\n", tz->map[indx]->trip_mask);
> +}
> +
> +static ssize_t map_weights_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + int i, indx, ret = 0;
> + struct thermal_map *map;
> + struct thermal_zone *tz = to_zone(dev);
> +
> + if (!sscanf(attr->attr.name, "map%d_weights", ))
> + return -EINVAL;
> 

Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread Zhang Rui
On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
 This patch creates a thermal map sysfs node under
 /sys/class/thermal/zoneX/. This contains
 entries named mapY_trip_type, mapY_sensor_name,
 mapY_cdev_name, mapY_trip_mask, mapY_weights.
sorry I still not quite understand.

does it look like?
/sys/class/thermal/zoneX/
|
map--|--map0_trip_type
  |...
  |--map0_weight
  |--map1_trip_type
  |...
  |--map1_weight
  |...

thanks,
rui
 
 Signed-off-by: Durgadoss R durgados...@intel.com
 ---
  drivers/thermal/thermal_sys.c |  221 
 -
  include/linux/thermal.h   |   25 +
  2 files changed, 244 insertions(+), 2 deletions(-)
 
 diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
 index 69a60a4..e284b67 100644
 --- a/drivers/thermal/thermal_sys.c
 +++ b/drivers/thermal/thermal_sys.c
 @@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone 
 *tz,
   tz-cdev_indx--;
  }
  
 +static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
 +{
 + int i;
 + struct thermal_map_attr *attr = tz-map_attr[indx];
 +
 + for (i = 0; i  NUM_MAP_ATTRS; i++)
 + device_remove_file(tz-device, attr-attrs[i].attr);
 +
 + kfree(tz-map_attr[indx]);
 + tz-map[indx] = NULL;
 +}
 +
 +static void remove_sensor_map_entry(struct thermal_zone *tz,
 + struct thermal_sensor *ts)
 +{
 + int i;
 +
 + for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
 + if (tz-map[i]  !strnicmp(ts-name, tz-map[i]-sensor_name,
 + THERMAL_NAME_LENGTH)) {
 + __remove_map_entry(tz, i);
 + }
 + }
 +}
 +
 +static void remove_cdev_map_entry(struct thermal_zone *tz,
 + struct thermal_cooling_device *cdev)
 +{
 + int i;
 +
 + for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
 + if (tz-map[i]  !strnicmp(cdev-type, tz-map[i]-cdev_name,
 + THERMAL_NAME_LENGTH)) {
 + __remove_map_entry(tz, i);
 + }
 + }
 +}
 +
  /* sys I/F for thermal zone */
  
  #define to_thermal_zone(_dev) \
 @@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
 *devattr, char *buf)
  }
  
  static ssize_t
 +map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
 +{
 + char *trip;
 + int indx;
 + struct thermal_zone *tz = to_zone(dev);
 +
 + if (!sscanf(attr-attr.name, map%d_trip_type, indx))
 + return -EINVAL;
 +
 + if (indx  0 || indx = MAX_MAPS_PER_ZONE)
 + return -EINVAL;
 +
 + if (!tz-map[indx])
 + return sprintf(buf, Unavailable\n);
 +
 + trip = (tz-map[indx]-trip_type == THERMAL_TRIP_ACTIVE) ?
 + active : passive;
 + return sprintf(buf, %s\n, trip);
 +}
 +
 +static ssize_t map_ts_name_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + int indx;
 + struct thermal_zone *tz = to_zone(dev);
 +
 + if (!sscanf(attr-attr.name, map%d_sensor_name, indx))
 + return -EINVAL;
 +
 + if (indx  0 || indx = MAX_MAPS_PER_ZONE)
 + return -EINVAL;
 +
 + if (!tz-map[indx])
 + return sprintf(buf, Unavailable\n);
 +
 + return sprintf(buf, %s\n, tz-map[indx]-sensor_name);
 +}
 +
 +static ssize_t map_cdev_name_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + int indx;
 + struct thermal_zone *tz = to_zone(dev);
 +
 + if (!sscanf(attr-attr.name, map%d_cdev_name, indx))
 + return -EINVAL;
 +
 + if (indx  0 || indx = MAX_MAPS_PER_ZONE)
 + return -EINVAL;
 +
 + if (!tz-map[indx])
 + return sprintf(buf, Unavailable\n);
 +
 + return sprintf(buf, %s\n, tz-map[indx]-cdev_name);
 +}
 +
 +static ssize_t map_trip_mask_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + int indx;
 + struct thermal_zone *tz = to_zone(dev);
 +
 + if (!sscanf(attr-attr.name, map%d_trip_mask, indx))
 + return -EINVAL;
 +
 + if (indx  0 || indx = MAX_MAPS_PER_ZONE)
 + return -EINVAL;
 +
 + if (!tz-map[indx])
 + return sprintf(buf, Unavailable\n);
 +
 + return sprintf(buf, 0x%x\n, tz-map[indx]-trip_mask);
 +}
 +
 +static ssize_t map_weights_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + int i, indx, ret = 0;
 + struct thermal_map *map;
 + struct thermal_zone *tz = to_zone(dev);
 +
 + if (!sscanf(attr-attr.name, map%d_weights, indx))
 + return -EINVAL;
 +
 + if (indx  0 || indx = MAX_MAPS_PER_ZONE)
 + return -EINVAL;
 +
 + if (!tz-map[indx])
 + return 

RE: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread R, Durgadoss
Hi Rui,

 -Original Message-
 From: Zhang, Rui
 Sent: Friday, February 08, 2013 2:35 PM
 To: R, Durgadoss
 Cc: linux...@vger.kernel.org; linux-kernel@vger.kernel.org;
 eduardo.valen...@ti.com; hongbo.zh...@linaro.org; w...@nvidia.com
 Subject: Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a
 zone
 
 On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
  This patch creates a thermal map sysfs node under
  /sys/class/thermal/zoneX/. This contains
  entries named mapY_trip_type, mapY_sensor_name,
  mapY_cdev_name, mapY_trip_mask, mapY_weights.
 sorry I still not quite understand.
 
 does it look like?
 /sys/class/thermal/zoneX/
 |
 map--|--map0_trip_type
   |...
   |--map0_weight
   |--map1_trip_type
   |...
   |--map1_weight
   |...
 

There is no separate 'map' directory.
So, everything is under /sys/class/thermal/zoneX/ directly,
named as map0_weight etc...

I think I should make the Doc/ABI patch should clarify this.

Thanks,
Durga


RE: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-08 Thread Zhang Rui
On Fri, 2013-02-08 at 02:08 -0700, R, Durgadoss wrote:
 Hi Rui,
 
  -Original Message-
  From: Zhang, Rui
  Sent: Friday, February 08, 2013 2:35 PM
  To: R, Durgadoss
  Cc: linux...@vger.kernel.org; linux-kernel@vger.kernel.org;
  eduardo.valen...@ti.com; hongbo.zh...@linaro.org; w...@nvidia.com
  Subject: Re: [PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a
  zone
  
  On Tue, 2013-02-05 at 16:16 +0530, Durgadoss R wrote:
   This patch creates a thermal map sysfs node under
   /sys/class/thermal/zoneX/. This contains
   entries named mapY_trip_type, mapY_sensor_name,
   mapY_cdev_name, mapY_trip_mask, mapY_weights.
  sorry I still not quite understand.
  
  does it look like?
  /sys/class/thermal/zoneX/
  |
  map--|--map0_trip_type
|...
|--map0_weight
|--map1_trip_type
|...
|--map1_weight
|...
  
 
 There is no separate 'map' directory.
 So, everything is under /sys/class/thermal/zoneX/ directly,
 named as map0_weight etc...
 
got it.

thanks,
rui

 I think I should make the Doc/ABI patch should clarify this.
 
 Thanks,
 Durga


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-05 Thread Durgadoss R
This patch creates a thermal map sysfs node under
/sys/class/thermal/zoneX/. This contains
entries named mapY_trip_type, mapY_sensor_name,
mapY_cdev_name, mapY_trip_mask, mapY_weights.

Signed-off-by: Durgadoss R 
---
 drivers/thermal/thermal_sys.c |  221 -
 include/linux/thermal.h   |   25 +
 2 files changed, 244 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 69a60a4..e284b67 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone *tz,
tz->cdev_indx--;
 }
 
+static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
+{
+   int i;
+   struct thermal_map_attr *attr = tz->map_attr[indx];
+
+   for (i = 0; i < NUM_MAP_ATTRS; i++)
+   device_remove_file(>device, >attrs[i].attr);
+
+   kfree(tz->map_attr[indx]);
+   tz->map[indx] = NULL;
+}
+
+static void remove_sensor_map_entry(struct thermal_zone *tz,
+   struct thermal_sensor *ts)
+{
+   int i;
+
+   for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
+   if (tz->map[i] && !strnicmp(ts->name, tz->map[i]->sensor_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
+static void remove_cdev_map_entry(struct thermal_zone *tz,
+   struct thermal_cooling_device *cdev)
+{
+   int i;
+
+   for (i = 0; i < MAX_MAPS_PER_ZONE; i++) {
+   if (tz->map[i] && !strnicmp(cdev->type, tz->map[i]->cdev_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
 /* sys I/F for thermal zone */
 
 #define to_thermal_zone(_dev) \
@@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
*devattr, char *buf)
 }
 
 static ssize_t
+map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char *trip;
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_trip_type", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");
+
+   trip = (tz->map[indx]->trip_type == THERMAL_TRIP_ACTIVE) ?
+   "active" : "passive";
+   return sprintf(buf, "%s\n", trip);
+}
+
+static ssize_t map_ts_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_sensor_name", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");
+
+   return sprintf(buf, "%s\n", tz->map[indx]->sensor_name);
+}
+
+static ssize_t map_cdev_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_cdev_name", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");
+
+   return sprintf(buf, "%s\n", tz->map[indx]->cdev_name);
+}
+
+static ssize_t map_trip_mask_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_trip_mask", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");
+
+   return sprintf(buf, "0x%x\n", tz->map[indx]->trip_mask);
+}
+
+static ssize_t map_weights_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int i, indx, ret = 0;
+   struct thermal_map *map;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr->attr.name, "map%d_weights", ))
+   return -EINVAL;
+
+   if (indx < 0 || indx >= MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz->map[indx])
+   return sprintf(buf, "\n");
+
+   map = tz->map[indx];
+
+   ret += sprintf(buf, "%d", map->weights[0]);
+   for (i = 1; i < map->num_weights; i++)
+   ret += sprintf(buf + ret, " %d", map->weights[i]);
+
+   ret += sprintf(buf + ret, "\n");
+   return ret;
+}
+
+static 

[PATCH 5/8] Thermal: Create Thermal map sysfs attributes for a zone

2013-02-05 Thread Durgadoss R
This patch creates a thermal map sysfs node under
/sys/class/thermal/zoneX/. This contains
entries named mapY_trip_type, mapY_sensor_name,
mapY_cdev_name, mapY_trip_mask, mapY_weights.

Signed-off-by: Durgadoss R durgados...@intel.com
---
 drivers/thermal/thermal_sys.c |  221 -
 include/linux/thermal.h   |   25 +
 2 files changed, 244 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 69a60a4..e284b67 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -525,6 +525,44 @@ static void remove_cdev_from_zone(struct thermal_zone *tz,
tz-cdev_indx--;
 }
 
+static inline void __remove_map_entry(struct thermal_zone *tz, int indx)
+{
+   int i;
+   struct thermal_map_attr *attr = tz-map_attr[indx];
+
+   for (i = 0; i  NUM_MAP_ATTRS; i++)
+   device_remove_file(tz-device, attr-attrs[i].attr);
+
+   kfree(tz-map_attr[indx]);
+   tz-map[indx] = NULL;
+}
+
+static void remove_sensor_map_entry(struct thermal_zone *tz,
+   struct thermal_sensor *ts)
+{
+   int i;
+
+   for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
+   if (tz-map[i]  !strnicmp(ts-name, tz-map[i]-sensor_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
+static void remove_cdev_map_entry(struct thermal_zone *tz,
+   struct thermal_cooling_device *cdev)
+{
+   int i;
+
+   for (i = 0; i  MAX_MAPS_PER_ZONE; i++) {
+   if (tz-map[i]  !strnicmp(cdev-type, tz-map[i]-cdev_name,
+   THERMAL_NAME_LENGTH)) {
+   __remove_map_entry(tz, i);
+   }
+   }
+}
+
 /* sys I/F for thermal zone */
 
 #define to_thermal_zone(_dev) \
@@ -917,6 +955,107 @@ policy_show(struct device *dev, struct device_attribute 
*devattr, char *buf)
 }
 
 static ssize_t
+map_ttype_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char *trip;
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_trip_type, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);
+
+   trip = (tz-map[indx]-trip_type == THERMAL_TRIP_ACTIVE) ?
+   active : passive;
+   return sprintf(buf, %s\n, trip);
+}
+
+static ssize_t map_ts_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_sensor_name, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);
+
+   return sprintf(buf, %s\n, tz-map[indx]-sensor_name);
+}
+
+static ssize_t map_cdev_name_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_cdev_name, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);
+
+   return sprintf(buf, %s\n, tz-map[indx]-cdev_name);
+}
+
+static ssize_t map_trip_mask_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int indx;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_trip_mask, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);
+
+   return sprintf(buf, 0x%x\n, tz-map[indx]-trip_mask);
+}
+
+static ssize_t map_weights_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   int i, indx, ret = 0;
+   struct thermal_map *map;
+   struct thermal_zone *tz = to_zone(dev);
+
+   if (!sscanf(attr-attr.name, map%d_weights, indx))
+   return -EINVAL;
+
+   if (indx  0 || indx = MAX_MAPS_PER_ZONE)
+   return -EINVAL;
+
+   if (!tz-map[indx])
+   return sprintf(buf, Unavailable\n);
+
+   map = tz-map[indx];
+
+   ret += sprintf(buf, %d, map-weights[0]);
+   for (i = 1; i  map-num_weights; i++)
+   ret += sprintf(buf + ret,  %d, map-weights[i]);
+
+   ret += sprintf(buf + ret, \n);
+   return ret;
+}
+