summaryrefslogtreecommitdiff
path: root/drivers/thermal/thermal_sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thermal/thermal_sysfs.c')
-rw-r--r--drivers/thermal/thermal_sysfs.c135
1 files changed, 44 insertions, 91 deletions
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index d97f0bc0a26b..cef860deaf91 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -83,27 +83,25 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct thermal_zone_device *tz = to_thermal_zone(dev);
- enum thermal_trip_type type;
- int trip, result;
+ struct thermal_trip trip;
+ int trip_id, result;
- if (!tz->ops->get_trip_type)
- return -EPERM;
-
- if (sscanf(attr->attr.name, "trip_point_%d_type", &trip) != 1)
+ if (sscanf(attr->attr.name, "trip_point_%d_type", &trip_id) != 1)
return -EINVAL;
mutex_lock(&tz->lock);
if (device_is_registered(dev))
- result = tz->ops->get_trip_type(tz, trip, &type);
+ result = __thermal_zone_get_trip(tz, trip_id, &trip);
else
result = -ENODEV;
mutex_unlock(&tz->lock);
+
if (result)
return result;
- switch (type) {
+ switch (trip.type) {
case THERMAL_TRIP_CRITICAL:
return sprintf(buf, "critical\n");
case THERMAL_TRIP_HOT:
@@ -122,17 +120,10 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct thermal_zone_device *tz = to_thermal_zone(dev);
- int trip, ret;
- int temperature, hyst = 0;
- enum thermal_trip_type type;
-
- if (!tz->ops->set_trip_temp && !tz->trips)
- return -EPERM;
-
- if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
- return -EINVAL;
+ struct thermal_trip trip;
+ int trip_id, ret;
- if (kstrtoint(buf, 10, &temperature))
+ if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
return -EINVAL;
mutex_lock(&tz->lock);
@@ -142,36 +133,19 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
goto unlock;
}
- if (tz->ops->set_trip_temp) {
- ret = tz->ops->set_trip_temp(tz, trip, temperature);
- if (ret)
- goto unlock;
- }
-
- if (tz->trips)
- tz->trips[trip].temperature = temperature;
-
- if (tz->ops->get_trip_hyst) {
- ret = tz->ops->get_trip_hyst(tz, trip, &hyst);
- if (ret)
- goto unlock;
- }
-
- ret = tz->ops->get_trip_type(tz, trip, &type);
+ ret = __thermal_zone_get_trip(tz, trip_id, &trip);
if (ret)
goto unlock;
- thermal_notify_tz_trip_change(tz->id, trip, type, temperature, hyst);
-
- __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
+ ret = kstrtoint(buf, 10, &trip.temperature);
+ if (ret)
+ goto unlock;
+ ret = thermal_zone_set_trip(tz, trip_id, &trip);
unlock:
mutex_unlock(&tz->lock);
-
- if (ret)
- return ret;
-
- return count;
+
+ return ret ? ret : count;
}
static ssize_t
@@ -179,19 +153,16 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct thermal_zone_device *tz = to_thermal_zone(dev);
- int trip, ret;
- int temperature;
-
- if (!tz->ops->get_trip_temp)
- return -EPERM;
+ struct thermal_trip trip;
+ int trip_id, ret;
- if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
+ if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
return -EINVAL;
mutex_lock(&tz->lock);
if (device_is_registered(dev))
- ret = tz->ops->get_trip_temp(tz, trip, &temperature);
+ ret = __thermal_zone_get_trip(tz, trip_id, &trip);
else
ret = -ENODEV;
@@ -200,7 +171,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
if (ret)
return ret;
- return sprintf(buf, "%d\n", temperature);
+ return sprintf(buf, "%d\n", trip.temperature);
}
static ssize_t
@@ -208,16 +179,13 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct thermal_zone_device *tz = to_thermal_zone(dev);
- int trip, ret;
- int temperature;
-
- if (!tz->ops->set_trip_hyst)
- return -EPERM;
+ struct thermal_trip trip;
+ int trip_id, ret;
- if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
+ if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
return -EINVAL;
- if (kstrtoint(buf, 10, &temperature))
+ if (kstrtoint(buf, 10, &trip.hysteresis))
return -EINVAL;
mutex_lock(&tz->lock);
@@ -227,16 +195,11 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
goto unlock;
}
- /*
- * We are not doing any check on the 'temperature' value
- * here. The driver implementing 'set_trip_hyst' has to
- * take care of this.
- */
- ret = tz->ops->set_trip_hyst(tz, trip, temperature);
-
- if (!ret)
- __thermal_zone_set_trips(tz);
-
+ ret = __thermal_zone_get_trip(tz, trip_id, &trip);
+ if (ret)
+ goto unlock;
+
+ ret = thermal_zone_set_trip(tz, trip_id, &trip);
unlock:
mutex_unlock(&tz->lock);
@@ -248,25 +211,22 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct thermal_zone_device *tz = to_thermal_zone(dev);
- int trip, ret;
- int temperature;
-
- if (!tz->ops->get_trip_hyst)
- return -EPERM;
+ struct thermal_trip trip;
+ int trip_id, ret;
- if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
+ if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
return -EINVAL;
mutex_lock(&tz->lock);
if (device_is_registered(dev))
- ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
+ ret = __thermal_zone_get_trip(tz, trip_id, &trip);
else
ret = -ENODEV;
mutex_unlock(&tz->lock);
- return ret ? ret : sprintf(buf, "%d\n", temperature);
+ return ret ? ret : sprintf(buf, "%d\n", trip.hysteresis);
}
static ssize_t
@@ -491,23 +451,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
return -ENOMEM;
}
- if (tz->ops->get_trip_hyst) {
- tz->trip_hyst_attrs = kcalloc(tz->num_trips,
- sizeof(*tz->trip_hyst_attrs),
- GFP_KERNEL);
- if (!tz->trip_hyst_attrs) {
- kfree(tz->trip_type_attrs);
- kfree(tz->trip_temp_attrs);
- return -ENOMEM;
- }
+ tz->trip_hyst_attrs = kcalloc(tz->num_trips,
+ sizeof(*tz->trip_hyst_attrs),
+ GFP_KERNEL);
+ if (!tz->trip_hyst_attrs) {
+ kfree(tz->trip_type_attrs);
+ kfree(tz->trip_temp_attrs);
+ return -ENOMEM;
}
attrs = kcalloc(tz->num_trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
if (!attrs) {
kfree(tz->trip_type_attrs);
kfree(tz->trip_temp_attrs);
- if (tz->ops->get_trip_hyst)
- kfree(tz->trip_hyst_attrs);
+ kfree(tz->trip_hyst_attrs);
return -ENOMEM;
}
@@ -540,9 +497,6 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
}
attrs[indx + tz->num_trips] = &tz->trip_temp_attrs[indx].attr.attr;
- /* create Optional trip hyst attribute */
- if (!tz->ops->get_trip_hyst)
- continue;
snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
"trip_point_%d_hyst", indx);
@@ -579,8 +533,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz)
kfree(tz->trip_type_attrs);
kfree(tz->trip_temp_attrs);
- if (tz->ops->get_trip_hyst)
- kfree(tz->trip_hyst_attrs);
+ kfree(tz->trip_hyst_attrs);
kfree(tz->trips_attribute_group.attrs);
}