Subject: [PATCH] [acpi thermal] Add basic structure to new thermal driver - Declare and register ACPI driver - No proc, sysfs, or event interfaces - Do simple init (get initial temperature) - Add helpers to get temp and convert to C Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/thermal/device.c | 32 +++++++++++++++++ drivers/acpi/drivers/thermal/driver.c | 59 ++++++++++++++++++++++++++++++++ drivers/acpi/drivers/thermal/event.c | 1 + drivers/acpi/drivers/thermal/proc.c | 1 + drivers/acpi/drivers/thermal/sysfs.c | 1 + drivers/acpi/drivers/thermal/thermal.h | 10 +++++ 6 files changed, 104 insertions(+), 0 deletions(-) applies-to: 5b39529d246e174f0ebc8376d222501cb4ce9dfb 9f1f19477f62851fefc40c68ffd3ecbd62c25cc3 diff --git a/drivers/acpi/drivers/thermal/device.c b/drivers/acpi/drivers/thermal/device.c index 80bbdd7..87db2ba 100644 --- a/drivers/acpi/drivers/thermal/device.c +++ b/drivers/acpi/drivers/thermal/device.c @@ -13,3 +13,35 @@ #include "thermal.h" + +static int get_int(struct acpi_thermal * at, char * obj, unsigned long * val) +{ + acpi_status status; + + status = acpi_evaluate_integer(at->t_ad->acpi_device->handle, + obj, NULL, val); + return ACPI_SUCCESS(status) ? 0 : -ENODEV; +} + + +long thermal_temp_c(long tempk) +{ + if (tempk - 2732 >= 0) + return (tempk - 2732 + 5) / 10; + else + return (tempk - 2732 - 5) / 10; +} + + +int thermal_get_temp(struct acpi_thermal * at) +{ + unsigned long last_temp = at->t_temp; + int ret; + + ret = get_int(at, "_TMP", &at->t_temp); + if (!ret) { + at->t_last_temp = last_temp; + dbg("temperature is %lu dK", at->t_temp); + } + return ret; +} diff --git a/drivers/acpi/drivers/thermal/driver.c b/drivers/acpi/drivers/thermal/driver.c index 8b7faad..d19c8a6 100644 --- a/drivers/acpi/drivers/thermal/driver.c +++ b/drivers/acpi/drivers/thermal/driver.c @@ -13,3 +13,62 @@ #include "thermal.h" + +static int thermal_init(struct acpi_thermal * at) +{ + int ret; + + /* + * Get initial temperature + */ + ret = thermal_get_temp(at); + if (ret) + return ret; + + return 0; +} + +static int thermal_add(struct acpi_dev * ad) +{ + struct acpi_thermal * at; + int ret = 0; + + at = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); + if (!at) + return -ENOMEM; + + at->t_ad = ad; + + ret = thermal_init(at); + if (ret) { + kfree(at); + return ret; + } + + dev_set_drvdata(&ad->dev, at); + + printk(KERN_INFO PREFIX "thermal [%s] (%ld C)\n", + acpi_dev_bid(ad), thermal_temp_c(at->t_temp)); + + return ret; +} + +static int thermal_remove(struct acpi_dev * ad) +{ + struct acpi_thermal * at = dev_get_drvdata(&ad->dev); + dev_set_drvdata(&ad->dev, NULL); + kfree(at); + return 0; +} + +acpi_no_start(thermal); +acpi_no_stop(thermal); +acpi_no_shutdown(thermal); +acpi_no_suspend(thermal); +acpi_no_resume(thermal); + +declare_acpi_driver(thermal); + +MODULE_AUTHOR("Patrick Mochel"); +MODULE_DESCRIPTION("ACPI Thermal Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/acpi/drivers/thermal/event.c b/drivers/acpi/drivers/thermal/event.c index 30c9413..06e2e32 100644 --- a/drivers/acpi/drivers/thermal/event.c +++ b/drivers/acpi/drivers/thermal/event.c @@ -13,3 +13,4 @@ #include "thermal.h" +acpi_device_event_none(thermal); diff --git a/drivers/acpi/drivers/thermal/proc.c b/drivers/acpi/drivers/thermal/proc.c index 7618282..9454df4 100644 --- a/drivers/acpi/drivers/thermal/proc.c +++ b/drivers/acpi/drivers/thermal/proc.c @@ -13,3 +13,4 @@ #include "thermal.h" +acpi_driver_proc_none(thermal); diff --git a/drivers/acpi/drivers/thermal/sysfs.c b/drivers/acpi/drivers/thermal/sysfs.c index 03802fd..d36c228 100644 --- a/drivers/acpi/drivers/thermal/sysfs.c +++ b/drivers/acpi/drivers/thermal/sysfs.c @@ -8,3 +8,4 @@ #include "thermal.h" +acpi_driver_sysfs_none(thermal); diff --git a/drivers/acpi/drivers/thermal/thermal.h b/drivers/acpi/drivers/thermal/thermal.h index 269a8fb..758d7e6 100644 --- a/drivers/acpi/drivers/thermal/thermal.h +++ b/drivers/acpi/drivers/thermal/thermal.h @@ -13,3 +13,13 @@ ACPI_MODULE_NAME("acpi_thermal"); #define ACPI_THERMAL_HID "ACPI_THM" + +struct acpi_thermal { + struct acpi_dev * t_ad; + long t_temp; + long t_last_temp; +}; + +extern int thermal_get_temp(struct acpi_thermal *); + +extern long thermal_temp_c(long tempk); --- 0.99.9.GIT