Patch adds show functions for irq-mode feature. It allocates new attributes and extends the old list. Cc: Zhang Rui <rui.zhang@xxxxxxxxx> Cc: Eduardo Valentin <edubezval@xxxxxxxxx> Cc: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx> Signed-off-by: Lukasz Luba <l.luba@xxxxxxxxxxxxxxxxxxx> --- drivers/thermal/thermal_sysfs.c | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 2241cea..372b439 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -21,6 +21,8 @@ #include "thermal_core.h" +#define TRIP_ATTR_NUM 4 + /* sys I/F for thermal zone */ static ssize_t @@ -167,6 +169,28 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr, } static ssize_t +trip_point_irq_mode_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + int trip, ret; + bool mode; + + if (!tz->ops->get_trip_irq_mode) + return -EPERM; + + if (sscanf(attr->attr.name, "trip_point_%d_irq", &trip) != 1) + return -EINVAL; + + ret = tz->ops->get_trip_irq_mode(tz, trip, &mode); + + if (ret) + return ret; + + return sprintf(buf, "%d\n", mode); +} + +static ssize_t trip_point_hyst_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -520,10 +544,19 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) if (!tz->trip_type_attrs) return -ENOMEM; + tz->trip_irq_mode_attrs = kcalloc(tz->trips, + sizeof(*tz->trip_irq_mode_attrs), + GFP_KERNEL); + if (!tz->trip_irq_mode_attrs) { + kfree(tz->trip_type_attrs); + return -ENOMEM; + } + tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs), GFP_KERNEL); if (!tz->trip_temp_attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_irq_mode_attrs); return -ENOMEM; } @@ -533,14 +566,17 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) GFP_KERNEL); if (!tz->trip_hyst_attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_irq_mode_attrs); kfree(tz->trip_temp_attrs); return -ENOMEM; } } - attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL); + attrs = kcalloc(tz->trips * TRIP_ATTR_NUM + 1, sizeof(*attrs), + GFP_KERNEL); if (!attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_irq_mode_attrs); kfree(tz->trip_temp_attrs); if (tz->ops->get_trip_hyst) kfree(tz->trip_hyst_attrs); @@ -559,6 +595,19 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) tz->trip_type_attrs[indx].attr.show = trip_point_type_show; attrs[indx] = &tz->trip_type_attrs[indx].attr.attr; + /* create trip irq_mode attribute */ + snprintf(tz->trip_irq_mode_attrs[indx].name, + THERMAL_NAME_LENGTH, "trip_point_%d_irq", indx); + + sysfs_attr_init(&tz->trip_irq_mode_attrs[indx].attr.attr); + tz->trip_irq_mode_attrs[indx].attr.attr.name = + tz->trip_irq_mode_attrs[indx].name; + tz->trip_irq_mode_attrs[indx].attr.attr.mode = S_IRUGO; + tz->trip_irq_mode_attrs[indx].attr.show = + trip_point_irq_mode_show; + attrs[indx + tz->trips * 3] = + &tz->trip_irq_mode_attrs[indx].attr.attr; + /* create trip temp attribute */ snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH, "trip_point_%d_temp", indx); @@ -595,7 +644,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) attrs[indx + tz->trips * 2] = &tz->trip_hyst_attrs[indx].attr.attr; } - attrs[tz->trips * 3] = NULL; + attrs[tz->trips * TRIP_ATTR_NUM] = NULL; tz->trips_attribute_group.attrs = attrs; -- 2.7.4