Subject: [PATCH] [acpi thermal] Add sysfs interface - Add these files: [Read Only] critical hot passive active temp [Read / Write] critical_trip hot_trip passive_trip cooling_mode polling_freq [Trip Points, if each trip point is active] 0 - 10 Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/thermal/sysfs.c | 210 ++++++++++++++++++++++++++++++++++ 1 files changed, 209 insertions(+), 1 deletions(-) applies-to: 6cf62c2b0c37113e43845ee3febd39854aae10a2 f0f3181be55088f23ff447f2210ea35077e09a54 diff --git a/drivers/acpi/drivers/thermal/sysfs.c b/drivers/acpi/drivers/thermal/sysfs.c index d36c228..f112335 100644 --- a/drivers/acpi/drivers/thermal/sysfs.c +++ b/drivers/acpi/drivers/thermal/sysfs.c @@ -8,4 +8,212 @@ #include "thermal.h" -acpi_driver_sysfs_none(thermal); + +static ssize_t store_temp(unsigned long * v, const char * buf, size_t count) +{ + unsigned long val; + char * end; + int ret = 0; + + val = simple_strtoul(buf, &end, 0); + if (*end != '\0') + *v = thermal_temp_k(val); + else + ret = -EINVAL; + return ret; +} + + + +static ssize_t critical_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%u\n", !! (at->t_state & THERMAL_STATE_CRIT) ); +} + +static ssize_t hot_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%u\n", !! (at->t_state & THERMAL_STATE_HOT) ); +} + +static ssize_t passive_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%u\n", !! (at->t_state & THERMAL_STATE_PSV) ); +} + +static ssize_t active_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%u\n", at->t_state & THERMAL_STATE_ACT ? + at->t_trips.act_index + 1 : 0); +} + +static ssize_t temp_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%lu\n", thermal_temp_c(at->t_temp)); +} + + +static ssize_t critical_trip_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%lu\n", + at->t_trips.crit_val ? + thermal_temp_c(at->t_trips.crit_temp) : 0); +} + +static ssize_t critical_trip_store(struct acpi_dev * ad, + const char * buf, size_t count) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return store_temp(&at->t_trips.crit_temp, buf, count); +} + + +static ssize_t hot_trip_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%lu\n", + at->t_trips.hot_val ? + thermal_temp_c(at->t_trips.hot_temp) : 0); +} + +static ssize_t hot_trip_store(struct acpi_dev * ad, + const char * buf, size_t count) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return store_temp(&at->t_trips.hot_temp, buf, count); +} + + +static ssize_t passive_trip_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%lu\n", + at->t_trips.psv_val ? + thermal_temp_c(at->t_trips.psv_temp) : 0); +} + +static ssize_t passive_trip_store(struct acpi_dev * ad, + const char * buf, size_t count) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return store_temp(&at->t_trips.psv_temp, buf, count); +} + + +static ssize_t cooling_mode_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%d\n", at->t_cooling_mode); +} + +static ssize_t cooling_mode_store(struct acpi_dev * ad, + const char * buf, size_t count) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + u32 mode; + char * end; + int ret = 0; + + mode = simple_strtoul(buf, &end, 0); + if (*end != '\0') { + if (mode == THERMAL_MODE_CRIT || + mode == THERMAL_MODE_ACT || + mode == THERMAL_MODE_PSV) { + ret = thermal_set_cooling_mode(at, mode); + + if (!ret) + thermal_check(at); + } + } else + ret = -EINVAL; + return ret; +} + +static ssize_t polling_freq_show(struct acpi_dev * ad, char * buf) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + return sprintf(buf, "%lu\n", at->t_poll_freq); +} + +static ssize_t polling_freq_store(struct acpi_dev * ad, + const char * buf, size_t count) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + unsigned long freq; + char * end; + int ret = 0; + + freq = simple_strtoul(buf, &end, 0); + if (*end != '\0') { + ret = thermal_set_poll_freq(at, freq); + if (!ret) + thermal_check(at); + } else + ret = -EINVAL; + return ret; +} + +#define define_active_attr(__num) \ +static ssize_t active_trip_##__num##_test(struct acpi_dev * ad) \ +{ \ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); \ + return at->t_trips.act[__num].val ? 1 : 0; \ +} \ +static ssize_t active_trip_##__num##_show(struct acpi_dev * ad, \ + char * buf) \ +{ \ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); \ + return sprintf(buf, "%lu\n", at->t_trips.act[__num].temp); \ +} \ +static ssize_t active_trip_##__num##_store(struct acpi_dev * ad, \ + const char * buf, \ + size_t count) \ +{ \ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); \ + return store_temp(&at->t_trips.act[__num].temp, buf, count); \ +} + +define_active_attr(0); +define_active_attr(1); +define_active_attr(2); +define_active_attr(3); +define_active_attr(4); +define_active_attr(5); +define_active_attr(6); +define_active_attr(7); +define_active_attr(8); +define_active_attr(9); + + +static struct acpi_dev_attr thermal_attrs[] = { + acpi_dev_attr_ro(critical), + acpi_dev_attr_ro(hot), + acpi_dev_attr_ro(passive), + acpi_dev_attr_ro(active), + acpi_dev_attr_ro(temp), + + acpi_dev_attr_rw(critical_trip), + acpi_dev_attr_rw(hot_trip), + acpi_dev_attr_rw(passive_trip), + + acpi_dev_attr_rw(cooling_mode), + acpi_dev_attr_rw(polling_freq), + + acpi_dev_attr_rw_test(active_trip_0), + acpi_dev_attr_rw_test(active_trip_1), + acpi_dev_attr_rw_test(active_trip_2), + acpi_dev_attr_rw_test(active_trip_3), + acpi_dev_attr_rw_test(active_trip_4), + acpi_dev_attr_rw_test(active_trip_5), + acpi_dev_attr_rw_test(active_trip_6), + acpi_dev_attr_rw_test(active_trip_7), + acpi_dev_attr_rw_test(active_trip_8), + acpi_dev_attr_rw_test(active_trip_9), +}; + +acpi_driver_sysfs(thermal); --- 0.99.9.GIT