introduce intel_menlow platform specific driver
Subsystems (2)
PATCH 9/10 introduce intel_menlow platform specific driver
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 538 insertions(+)
drivers/misc/intel_menlow.c new file +527 -0
@@ -0,0 +1,527 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int +memory_get_max_bandwidth (struct thermal_cooling_device *cdev,char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev,&value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} + +static int +memory_get_cur_bandwidth (struct thermal_cooling_device *cdev,char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int +memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev,&max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end; + } + + end: +return result; +} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip +* ----------------- +* get the current auxtrip value from sensor through proprietory ACPI methods +* name: Thermalzone name +* auxtype : AUX0/AUX1 +* buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +/* +* sensor_set_auxtrip +* ----------------- +* set the new auxtrip value to sensor through proprietory ACPI methods +* name: Thermalzone name +* auxtype : AUX0/AUX1 +* buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} + +static acpi_status +intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver); +if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; + +return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);
drivers/misc/Kconfig +10 -0
@@ -232,4 +232,14 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + default n + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If you are not sure, say N here. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
drivers/misc/Kconfig config ATMEL_SSC · line 238
Quoted 5 lines
drivers/misc/Kconfig +4
-0+config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + default n
default n is not needed - it is default.
Sam
drivers/misc/Kconfig config ATMEL_SSC · line 238
Quoted 5 lines
drivers/misc/Kconfig +4
-0+config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + default n
default n is not needed - it is default.
Sam
Quoted 25 lines · On Thu, 17 Jan 2008 15:51:17 +0800 Zhang Rui wrote:
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 538 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +8
-0@@ -0,0 +1,527 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*
drivers/misc/intel_menlow.c line 57
Quoted 10 lines
drivers/misc/intel_menlow.c new file +9
-0+* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)
Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)
Quoted 52 lines
drivers/misc/intel_menlow.c new file +52
-0+{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" );
drivers/misc/intel_menlow.c line 191
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end; + } + + end:
Labels should begin in column 0 or 1. Only.
drivers/misc/intel_menlow.c line 211
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },
or just {} for the terminating entry, right?
drivers/misc/intel_menlow.c line 251
Quoted 10 lines
drivers/misc/intel_menlow.c new file +9
-0+}; +/* +* sensor_get_auxtrip +* ----------------- +* get the current auxtrip value from sensor through proprietory ACPI methods +* name: Thermalzone name +* auxtype : AUX0/AUX1 +* buf: syfs buffer +*/
It would be Good to use kernel-doc format if someone is going to add function documentation at all... (ref. multiple places)
See Documentation/kernel-doc-nano-HOWTO.txt .
Quoted 60 lines
drivers/misc/intel_menlow.c new file +59
-0+static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static acpi_status +intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app
drivers/misc/intel_menlow.c line 469
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found:
Don't indent labels so much. It hides them.
Quoted 11 lines
drivers/misc/intel_menlow.c new file +5
-0+if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +}Index: linux-2.6/drivers/misc/Kconfig
===================================================================
drivers/misc/Kconfig config ATMEL_SSC · line 238
Quoted 7 lines
drivers/misc/Kconfig +4
-0@@ -232,4 +232,14 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + default n
Documentation/CodingStyle has info on Kconfig style. Please read & use it and be more careful.
drivers/misc/Kconfig config ATMEL_SSC · line 245
Quoted 7 lines
drivers/misc/Kconfig +6
-0+ ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If you are not sure, say N here. + endif # MISC_DEVICES
---
~Randy
Quoted 25 lines · On Thu, 17 Jan 2008 15:51:17 +0800 Zhang Rui wrote:
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 538 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +8
-0@@ -0,0 +1,527 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*
drivers/misc/intel_menlow.c line 57
Quoted 10 lines
drivers/misc/intel_menlow.c new file +9
-0+* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)
Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)
Quoted 52 lines
drivers/misc/intel_menlow.c new file +52
-0+{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" );
drivers/misc/intel_menlow.c line 191
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end; + } + + end:
Labels should begin in column 0 or 1. Only.
drivers/misc/intel_menlow.c line 211
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },
or just {} for the terminating entry, right?
drivers/misc/intel_menlow.c line 251
Quoted 10 lines
drivers/misc/intel_menlow.c new file +9
-0+}; +/* +* sensor_get_auxtrip +* ----------------- +* get the current auxtrip value from sensor through proprietory ACPI methods +* name: Thermalzone name +* auxtype : AUX0/AUX1 +* buf: syfs buffer +*/
It would be Good to use kernel-doc format if someone is going to add function documentation at all... (ref. multiple places)
See Documentation/kernel-doc-nano-HOWTO.txt .
Quoted 60 lines
drivers/misc/intel_menlow.c new file +59
-0+static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static acpi_status +intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app
drivers/misc/intel_menlow.c line 469
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found:
Don't indent labels so much. It hides them.
Quoted 11 lines
drivers/misc/intel_menlow.c new file +5
-0+if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +}Index: linux-2.6/drivers/misc/Kconfig
===================================================================
drivers/misc/Kconfig config ATMEL_SSC · line 238
Quoted 7 lines
drivers/misc/Kconfig +4
-0@@ -232,4 +232,14 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + default n
Documentation/CodingStyle has info on Kconfig style. Please read & use it and be more careful.
drivers/misc/Kconfig config ATMEL_SSC · line 245
Quoted 7 lines
drivers/misc/Kconfig +6
-0+ ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If you are not sure, say N here. + endif # MISC_DEVICES
---
~Randy
Len Brown
reviewerQuoted 7 lines
drivers/misc/intel_menlow.c line 57
Quoted 4 lines
drivers/misc/intel_menlow.c new file +3
-0+static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)
if checkpatch.pl and Lindent are happey (which they are not, totally) then I'm satisifed witht he Linux style of the code.
Randy, if you feel strongly about this this style nit, then change Lindent to implement it -- nagging developers about trivia is a waste of everybody's time.
thanks,
-Len
Len Brown
reviewerQuoted 7 lines
drivers/misc/intel_menlow.c line 57
Quoted 4 lines
drivers/misc/intel_menlow.c new file +3
-0+static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)
if checkpatch.pl and Lindent are happey (which they are not, totally) then I'm satisifed witht he Linux style of the code.
Randy, if you feel strongly about this this style nit, then change Lindent to implement it -- nagging developers about trivia is a waste of everybody's time.
thanks,
-Len
Quoted 9 lines · Len Brown
Quoted 5 lines
drivers/misc/intel_menlow.c line 57
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)if checkpatch.pl and Lindent are happey (which they are not, totally) then I'm satisifed witht he Linux style of the code.
Quoted 6 lines
Randy, if you feel strongly about this this style nit, then change Lindent to implement it -- nagging developers about trivia is a waste of everybody's time.
thanks,
-Len
http://marc.info/?l=linux-kernel&m=105451996829576&w=2
Thanks.
Signature · 1 line
~Randy
Quoted 9 lines · Len Brown
Quoted 5 lines
drivers/misc/intel_menlow.c line 57
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+static int +memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state)Don't put 'static int' (return type etc.) on a line by itself.
That format is not wanted in Linux. (many places here)if checkpatch.pl and Lindent are happey (which they are not, totally) then I'm satisifed witht he Linux style of the code.
Quoted 6 lines
Randy, if you feel strongly about this this style nit, then change Lindent to implement it -- nagging developers about trivia is a waste of everybody's time.
thanks,
-Len
http://marc.info/?l=linux-kernel&m=105451996829576&w=2
Thanks.
Signature · 1 line
~Randy
Hi, Randy and Sam,
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (result) + goto end; + } + + end:
Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002", 0}, + {"", 0},or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 530 insertions(+)
drivers/misc/intel_menlow.c new file +520 -0
@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end; + } + + end: +return result; +} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} + +static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver); +if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; + +return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);
drivers/misc/Kconfig +9 -0
@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 129 lines · Zhang Rui
Hi, Randy and Sam,
Quoted 5 lines
drivers/misc/intel_menlow.c line 189
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+if (result) + goto end;acpi_bus_get_private_data + } + + end:Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)Quoted 8 lines
drivers/misc/intel_menlow.c line 209
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 530 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +87
-0@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} +
<...>
Quoted 62 lines
drivers/misc/intel_menlow.c new file +62
-0+static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; +
<...>
Quoted 27 lines
drivers/misc/intel_menlow.c new file +27
-0+/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else {
drivers/misc/intel_menlow.c line 186
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end;
This if condition is needless.
drivers/misc/intel_menlow.c line 190
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+ } + + end: +return result;
No need to call thermal_cooling_device_unregister() and sysfs_remove_link() in some error routines ?
Quoted 72 lines
drivers/misc/intel_menlow.c new file +72
-0+} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +
<...>
Quoted 84 lines
drivers/misc/intel_menlow.c new file +84
-0+/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} +
<...>
Quoted 63 lines
drivers/misc/intel_menlow.c new file +63
-0+static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} +
<...>
Quoted 90 lines
drivers/misc/intel_menlow.c new file +90
-0+static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);
drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +
It seems to me this should be 'return -ENODEV;'
You can just eliminate variable result, because result will be -ENODEV only.
Quoted 40 lines
drivers/misc/intel_menlow.c new file +11
-0+return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);Index: linux-2.6/drivers/misc/Kconfig
===================================================================drivers/misc/Kconfig +9
-0@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICESIndex: linux-2.6/drivers/misc/Makefile
===================================================================drivers/misc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 129 lines · Zhang Rui
Hi, Randy and Sam,
Quoted 5 lines
drivers/misc/intel_menlow.c line 189
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+if (result) + goto end;acpi_bus_get_private_data + } + + end:Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)Quoted 8 lines
drivers/misc/intel_menlow.c line 209
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 530 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +87
-0@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} +
<...>
Quoted 62 lines
drivers/misc/intel_menlow.c new file +62
-0+static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; +
<...>
Quoted 27 lines
drivers/misc/intel_menlow.c new file +27
-0+/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else {
drivers/misc/intel_menlow.c line 186
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end;
This if condition is needless.
drivers/misc/intel_menlow.c line 190
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+ } + + end: +return result;
No need to call thermal_cooling_device_unregister() and sysfs_remove_link() in some error routines ?
Quoted 72 lines
drivers/misc/intel_menlow.c new file +72
-0+} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +
<...>
Quoted 84 lines
drivers/misc/intel_menlow.c new file +84
-0+/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} +
<...>
Quoted 63 lines
drivers/misc/intel_menlow.c new file +63
-0+static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} +
<...>
Quoted 90 lines
drivers/misc/intel_menlow.c new file +90
-0+static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);
drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +
It seems to me this should be 'return -ENODEV;'
You can just eliminate variable result, because result will be -ENODEV only.
Quoted 36 lines
drivers/misc/intel_menlow.c new file +11
-0+return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);Index: linux-2.6/drivers/misc/Kconfig
===================================================================drivers/misc/Kconfig +9
-0@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICESIndex: linux-2.6/drivers/misc/Makefile
===================================================================
drivers/misc/Makefile obj-$(CONFIG_SONY_LAPTOP) += sony-laptop · line 20
Quoted 4 lines
drivers/misc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 253 lines
-----Original Message-----
From: Li Zefan [mailto:[email protected]]
Sent: Friday, January 18, 2008 9:25 AM
To: Zhang, Rui
Cc: Randy Dunlap; [email protected]; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; Thomas, Sujith
Subject: Re: [PATCH 9/10] introduceintel_menlowplatform specific driverQuoted 27 lines · Zhang Rui
Hi, Randy and Sam,
Quoted 5 lines
drivers/misc/intel_menlow.c line 189
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+if (result) + goto end;acpi_bus_get_private_data + } + + end:Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)Quoted 8 lines
drivers/misc/intel_menlow.c line 209
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Quoted 8 lines
Intel menlow platform specific driver for thermal management extension.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520++++++++++++++++++++++++++++++++++++++++++++
drivers/misc/intel_menlow.c line 2
Quoted 9 lines
3 files changed, 530 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +2
-0@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension
drivers/misc/intel_menlow.c line 8
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along
drivers/misc/intel_menlow.c line 19
Quoted 1 line
drivers/misc/intel_menlow.c new file +1
-0+* with this program; if not, write to the Free Software Foundation, Inc.,
drivers/misc/intel_menlow.c line 23
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
drivers/misc/intel_menlow.c
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware
Quoted 20 lines
drivers/misc/intel_menlow.c new file +20
-0+* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth(struct thermal_cooling_device*cdev,
Quoted 13 lines
drivers/misc/intel_menlow.c new file +13
-0+ unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ;drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth(struct thermal_cooling_device*cdev,
Quoted 9 lines
drivers/misc/intel_menlow.c new file +9
-0+ char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld¥n" , value); +} +<...>
Quoted 1 line
+static int memory_get_cur_bandwidth(struct
thermal_cooling_device*cdev,
Quoted 12 lines
drivers/misc/intel_menlow.c new file +12
-0+ char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ;drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld¥n" , value); +} + +static int memory_set_cur_bandwidth(struct thermal_cooling_device*cdev,
Quoted 39 lines
drivers/misc/intel_menlow.c new file +39
-0+ unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d¥n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; +<...>
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device)drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status = acpi_get_handle(device->handle, MEMORY_GET_BANDWIDTH,&dummy);
drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+if (ACPI_FAILURE (status)) + goto end; + + status = acpi_get_handle(device->handle, MEMORY_SET_BANDWIDTH,&dummy);
Quoted 13 lines
drivers/misc/intel_menlow.c new file +13
-0+if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result)
Quoted 8 lines
drivers/misc/intel_menlow.c line 186
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+ goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end;This if condition is needless.
I agree. This will be taken care of.
Quoted 9 lines
drivers/misc/intel_menlow.c line 190
Quoted 5 lines
drivers/misc/intel_menlow.c new file +4
-0+ } + + end: +return result;No need to call
thermal_cooling_device_unregister()andsysfs_remove_link()in
some error routines ?
Yes, I agree. We need to call those on error routines
Quoted 346 lines
drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +3
-0+} + +static int intel_menlow_memory_remove(struct acpi_device *device, inttype)
Quoted 45 lines
drivers/misc/intel_menlow.c new file +45
-0+{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip(acpi_handle handle, int index, int*value)
Quoted 14 lines
drivers/misc/intel_menlow.c new file +14
-0+{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +<...>
Quoted 35 lines
drivers/misc/intel_menlow.c new file +35
-0+/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+return 0 ; +} + +#define to_intel_menlow_attr (_attr) ¥ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + + return result ? result : sprintf(buf, "%lu",
KELVIN_TO_CELSIUS(value));drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + + return result ? result : sprintf(buf, "%lu",
KELVIN_TO_CELSIUS(value));drivers/misc/intel_menlow.c
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result = sensor_set_auxtrip(attr->handle, 0,
CELSIUS_TO_KELVIN(value));Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+return result ? result : count; +} +<...>
drivers/misc/intel_menlow.c
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result = sensor_set_auxtrip(attr->handle, 1,
CELSIUS_TO_KELVIN(value));drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */
drivers/misc/intel_menlow.c
Quoted 8 lines
drivers/misc/intel_menlow.c new file +8
-0+#define BIOS_ENABLED "¥¥_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status = acpi_evaluate_integer(NULL, BIOS_ENABLED, NULL,
&bios_enabled);drivers/misc/intel_menlow.c
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s¥n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute(char *name, int mode, void*show,
Quoted 28 lines
drivers/misc/intel_menlow.c new file +28
-0+ void *store, struct device *dev, + acpi_handle handle) +{ + struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} +<...>
Quoted 1 line
+static
acpi_statusintel_menlow_register_sensor(acpi_handle handle, u32lvl,
Quoted 89 lines
drivers/misc/intel_menlow.c new file +89
-0+ void *context, void **rv) +{ + acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the ¥_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +It seems to me this should be 'return
-ENODEV;'
Quoted 2 lines
You can just eliminate variable result, because result will be
-ENODEVonly.
I disagree. "result" is required to store the return value from acpi_bus_register_driver which may be different from ENODEV. Otherwise it's all -ENODEV.
:-Sujith
Quoted 41 lines
Quoted 41 lines
drivers/misc/intel_menlow.c new file +11
-0+return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);Index: linux-2.6/drivers/misc/Kconfig
===================================================================drivers/misc/Kconfig +9
-0@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICESIndex: linux-2.6/drivers/misc/Makefile
===================================================================drivers/misc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 253 lines
-----Original Message-----
From: Li Zefan [mailto:[email protected]]
Sent: Friday, January 18, 2008 9:25 AM
To: Zhang, Rui
Cc: Randy Dunlap; [email protected]; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; Thomas, Sujith
Subject: Re: [PATCH 9/10] introduceintel_menlowplatform specific driverQuoted 27 lines · Zhang Rui
Hi, Randy and Sam,
Quoted 5 lines
drivers/misc/intel_menlow.c line 189
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+if (result) + goto end;acpi_bus_get_private_data + } + + end:Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)Quoted 8 lines
drivers/misc/intel_menlow.c line 209
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 },or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Quoted 8 lines
Intel menlow platform specific driver for thermal management extension.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520++++++++++++++++++++++++++++++++++++++++++++
drivers/misc/intel_menlow.c line 2
Quoted 9 lines
3 files changed, 530 insertions(+)Index:
linux-2.6/drivers/misc/intel_menlow.c
===================================================================drivers/misc/intel_menlow.c new file +2
-0@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension
drivers/misc/intel_menlow.c line 8
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along
drivers/misc/intel_menlow.c line 19
Quoted 1 line
drivers/misc/intel_menlow.c new file +1
-0+* with this program; if not, write to the Free Software Foundation, Inc.,
drivers/misc/intel_menlow.c line 23
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
drivers/misc/intel_menlow.c
Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware
Quoted 20 lines
drivers/misc/intel_menlow.c new file +20
-0+* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth(struct thermal_cooling_device*cdev,
Quoted 13 lines
drivers/misc/intel_menlow.c new file +13
-0+ unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ;drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth(struct thermal_cooling_device*cdev,
Quoted 9 lines
drivers/misc/intel_menlow.c new file +9
-0+ char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld¥n" , value); +} +<...>
Quoted 1 line
+static int memory_get_cur_bandwidth(struct
thermal_cooling_device*cdev,
Quoted 12 lines
drivers/misc/intel_menlow.c new file +12
-0+ char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ;drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+ arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld¥n" , value); +} + +static int memory_set_cur_bandwidth(struct thermal_cooling_device*cdev,
Quoted 39 lines
drivers/misc/intel_menlow.c new file +39
-0+ unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d¥n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; +<...>
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device)drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status = acpi_get_handle(device->handle, MEMORY_GET_BANDWIDTH,&dummy);
drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+if (ACPI_FAILURE (status)) + goto end; + + status = acpi_get_handle(device->handle, MEMORY_SET_BANDWIDTH,&dummy);
Quoted 13 lines
drivers/misc/intel_menlow.c new file +13
-0+if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result)
Quoted 8 lines
drivers/misc/intel_menlow.c line 186
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+ goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end;This if condition is needless.
I agree. This will be taken care of.
Quoted 9 lines
drivers/misc/intel_menlow.c line 190
Quoted 5 lines
drivers/misc/intel_menlow.c new file +4
-0+ } + + end: +return result;No need to call
thermal_cooling_device_unregister()andsysfs_remove_link()in
some error routines ?
Yes, I agree. We need to call those on error routines
Quoted 346 lines
drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +3
-0+} + +static int intel_menlow_memory_remove(struct acpi_device *device, inttype)
Quoted 45 lines
drivers/misc/intel_menlow.c new file +45
-0+{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip(acpi_handle handle, int index, int*value)
Quoted 14 lines
drivers/misc/intel_menlow.c new file +14
-0+{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +<...>
Quoted 35 lines
drivers/misc/intel_menlow.c new file +35
-0+/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ +drivers/misc/intel_menlow.c
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+return 0 ; +} + +#define to_intel_menlow_attr (_attr) ¥ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + + return result ? result : sprintf(buf, "%lu",
KELVIN_TO_CELSIUS(value));drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + + return result ? result : sprintf(buf, "%lu",
KELVIN_TO_CELSIUS(value));drivers/misc/intel_menlow.c
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result = sensor_set_auxtrip(attr->handle, 0,
CELSIUS_TO_KELVIN(value));Quoted 3 lines
drivers/misc/intel_menlow.c new file +3
-0+return result ? result : count; +} +<...>
drivers/misc/intel_menlow.c
Quoted 5 lines
drivers/misc/intel_menlow.c new file +5
-0+static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ + struct intel_menlow_attribute *attr =
to_intel_menlow_attr(dev_attr);drivers/misc/intel_menlow.c
Quoted 11 lines
drivers/misc/intel_menlow.c new file +11
-0+int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result = sensor_set_auxtrip(attr->handle, 1,
CELSIUS_TO_KELVIN(value));drivers/misc/intel_menlow.c
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */
drivers/misc/intel_menlow.c
Quoted 8 lines
drivers/misc/intel_menlow.c new file +8
-0+#define BIOS_ENABLED "¥¥_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status = acpi_evaluate_integer(NULL, BIOS_ENABLED, NULL,
&bios_enabled);drivers/misc/intel_menlow.c
Quoted 7 lines
drivers/misc/intel_menlow.c new file +7
-0+if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s¥n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute(char *name, int mode, void*show,
Quoted 28 lines
drivers/misc/intel_menlow.c new file +28
-0+ void *store, struct device *dev, + acpi_handle handle) +{ + struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} +<...>
Quoted 1 line
+static
acpi_statusintel_menlow_register_sensor(acpi_handle handle, u32lvl,
Quoted 89 lines
drivers/misc/intel_menlow.c new file +89
-0+ void *context, void **rv) +{ + acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the ¥_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +It seems to me this should be 'return
-ENODEV;'
Quoted 2 lines
You can just eliminate variable result, because result will be
-ENODEVonly.
I disagree. "result" is required to store the return value from acpi_bus_register_driver which may be different from ENODEV. Otherwise it's all -ENODEV.
:-Sujith
Quoted 41 lines
Quoted 41 lines
drivers/misc/intel_menlow.c new file +11
-0+return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);Index: linux-2.6/drivers/misc/Kconfig
===================================================================drivers/misc/Kconfig +9
-0@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICESIndex: linux-2.6/drivers/misc/Makefile
===================================================================drivers/misc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
drivers/misc/intel_menlow.c new file +16
-0+static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +It seems to me this should be 'return
-ENODEV;'
Quoted 5 lines
Quoted 2 lines
You can just eliminate variable result, because result will be
-ENODEVonly.I disagree. "result" is required to store the return value from
acpi_bus_register_driverwhich may be different from ENODEV. Otherwise it's all-ENODEV.:-Sujith
Indead, I overlooked it.
But the above 'result = -ENODEV;' should be 'return -ENODEV;', right?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
drivers/misc/intel_menlow.c new file +16
-0+static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver);drivers/misc/intel_menlow.c line 509
Quoted 10 lines
drivers/misc/intel_menlow.c new file +10
-0+if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; +It seems to me this should be 'return
-ENODEV;'
Quoted 5 lines
Quoted 2 lines
You can just eliminate variable result, because result will be
-ENODEVonly.I disagree. "result" is required to store the return value from
acpi_bus_register_driverwhich may be different from ENODEV. Otherwise it's all-ENODEV.:-Sujith
Indead, I overlooked it.
But the above 'result = -ENODEV;' should be 'return -ENODEV;', right?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
Quoted 35 lines · Li Zefan
Quoted 11 lines
Quoted 11 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+static int __init intel_menlow_module_init(void) +{ + int result = -ENODEV; + acpi_status status; + unsigned long enable; + + if (acpi_disabled) + return result; + + /* Looking for the \_TZ.GSTS method */ + status = acpi_evaluate_integer(NULL, BIOS_ENABLED, NULL,&enable);
Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (ACPI_FAILURE(status) || !enable) + return -ENODEV; + + /* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =
acpi_bus_register_driver(&intel_menlow_memory_driver);Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (result) + return result; + + /* Looking for sensors in each ACPI thermal zone */ + status = acpi_walk_namespace(ACPI_TYPE_THERMAL,
ACPI_ROOT_OBJECT,Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ ACPI_UINT32_MAX, + intel_menlow_register_sensor,NULL, NULL);
Quoted 8 lines
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (ACPI_FAILURE(status)) + result = -ENODEV; +It seems to me this should be 'return
-ENODEV;'You can just eliminate variable result, because result will be
-ENODEVonly.I disagree. "result" is required to store the return value from
Quoted 8 lines
acpi_bus_register_driverwhich may be different from ENODEV. Otherwise it's all-ENODEV.Quoted 2 lines
:-Sujith
Indead, I overlooked it.
But the above 'result =
-ENODEV;' should be 'return-ENODEV;', right?
Yes, please review the refreshed patches.
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 526 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 536 insertions(+)
drivers/misc/intel_menlow.c new file +526 -0
@@ -0,0 +1,526 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result =sysfs_create_link (&device->dev.kobj, + &cdev->device.kobj,"thermal_cooling" ); +if (result) + goto unregister; + + result =sysfs_create_link (&cdev->device.kobj, + &device->dev.kobj,"device" ); +if (result) { +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); + goto unregister; + } + } + + end: +return result; + + unregister: +thermal_cooling_device_unregister (cdev); +return result; + +} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} + +static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver); +if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);
drivers/misc/Kconfig +9 -0
@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 35 lines · Li Zefan
Quoted 11 lines
Quoted 11 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+static int __init intel_menlow_module_init(void) +{ + int result = -ENODEV; + acpi_status status; + unsigned long enable; + + if (acpi_disabled) + return result; + + /* Looking for the \_TZ.GSTS method */ + status = acpi_evaluate_integer(NULL, BIOS_ENABLED, NULL,&enable);
Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (ACPI_FAILURE(status) || !enable) + return -ENODEV; + + /* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =
acpi_bus_register_driver(&intel_menlow_memory_driver);Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (result) + return result; + + /* Looking for sensors in each ACPI thermal zone */ + status = acpi_walk_namespace(ACPI_TYPE_THERMAL,
ACPI_ROOT_OBJECT,Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ ACPI_UINT32_MAX, + intel_menlow_register_sensor,NULL, NULL);
Quoted 8 lines
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (ACPI_FAILURE(status)) + result = -ENODEV; +It seems to me this should be 'return
-ENODEV;'You can just eliminate variable result, because result will be
-ENODEVonly.I disagree. "result" is required to store the return value from
Quoted 8 lines
acpi_bus_register_driverwhich may be different from ENODEV. Otherwise it's all-ENODEV.Quoted 2 lines
:-Sujith
Indead, I overlooked it.
But the above 'result =
-ENODEV;' should be 'return-ENODEV;', right?
Yes, please review the refreshed patches.
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 526 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 536 insertions(+)
drivers/misc/intel_menlow.c new file +526 -0
@@ -0,0 +1,526 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result =sysfs_create_link (&device->dev.kobj, + &cdev->device.kobj,"thermal_cooling" ); +if (result) + goto unregister; + + result =sysfs_create_link (&cdev->device.kobj, + &device->dev.kobj,"device" ); +if (result) { +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); + goto unregister; + } + } + + end: +return result; + + unregister: +thermal_cooling_device_unregister (cdev); +return result; + +} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} + +static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver); +if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);
drivers/misc/Kconfig +9 -0
@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Hi, Randy and Sam,
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (result) + goto end; + } + + end:
Hah, Lindent always does this for me,
Quoted 1 line
Labels should begin in column 0 or 1. Only.
yes, and checkpatch.pl begins to complain about this after using Lindent...
I think we should change one of them, :)
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ return result; +} + + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002", 0}, + {"", 0},or just {} for the terminating entry, right?
Yes, I use this just to be consistent with other ACPI device drivers.
Thanks for your comments, please review the patch below,
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management extension.
--- drivers/misc/Kconfig | 9 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 520 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 530 insertions(+)
drivers/misc/intel_menlow.c new file +520 -0
@@ -0,0 +1,520 @@ +/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This driver creates the sys I/F for programming the sensors. +* It also implements the driver for intel menlow memory controller (hardware +* id is INT0002) which makes use of the platform specific ACPI methods +* to get/set bandwidth. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/pm.h> + +#include <linux/thermal.h> +#include <acpi/acpi_bus.h> +#include <acpi/acpi_drivers.h> + +MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" ); +MODULE_DESCRIPTION ("Intel Menlow platform specific driver" ); +MODULE_LICENSE ("GPL" ); + +/* +* Memory controller device control +*/ + +#define MEMORY_GET_BANDWIDTH "GTHS" +#define MEMORY_SET_BANDWIDTH "STHS" +#define MEMORY_ARG_CUR_BANDWIDTH 1 +#define MEMORY_ARG_MAX_BANDWIDTH 0 + +static int memory_get_int_max_bandwidth (struct thermal_cooling_device *cdev, +unsigned long *max_state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_MAX_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + + *max_state = value -1 ; +return 0 ; +} + +static int memory_get_max_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +unsigned long value; +if (memory_get_int_max_bandwidth (cdev, &value)) +return -EINVAL ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_get_cur_bandwidth (struct thermal_cooling_device *cdev, +char *buf) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +unsigned long value; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status =AE_OK ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =MEMORY_ARG_CUR_BANDWIDTH ; + status =acpi_evaluate_integer (handle,MEMORY_GET_BANDWIDTH , + &arg_list, &value); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return sprintf (buf,"%ld\n" , value); +} + +static int memory_set_cur_bandwidth (struct thermal_cooling_device *cdev, +unsigned int state) +{ +struct acpi_device *device = cdev->devdata; +acpi_handle handle = device->handle; +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; +int temp; +unsigned long max_state; + +if (memory_get_int_max_bandwidth (cdev, &max_state)) +return -EFAULT ; + +if (max_state <0 || state > max_state) +return -EINVAL ; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value = state; + + status = +acpi_evaluate_integer (handle,MEMORY_SET_BANDWIDTH , &arg_list, + (unsigned long *)&temp); + +printk (KERN_INFO +"Bandwidth value was %d: status is %d\n" , state, status); +if (ACPI_FAILURE (status)) +return -EFAULT ; + +return 0 ; +} + +static struct thermal_cooling_device_ops memory_cooling_ops = { + .get_max_state = memory_get_max_bandwidth, + .get_cur_state = memory_get_cur_bandwidth, + .set_cur_state = memory_set_cur_bandwidth, +}; + +/* +* Memory Device Management +*/ +static int intel_menlow_memory_add (struct acpi_device *device) +{ +int result = -ENODEV ; +acpi_status status =AE_OK ; +acpi_handle dummy; +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; + + status =acpi_get_handle (device->handle,MEMORY_GET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + status =acpi_get_handle (device->handle,MEMORY_SET_BANDWIDTH , &dummy); +if (ACPI_FAILURE (status)) + goto end; + + cdev =thermal_cooling_device_register ("Memory controller" , device, + &memory_cooling_ops); +acpi_driver_data (device) = cdev; +if (!cdev) + result = -ENODEV ; +else { + result = +sysfs_create_link (&device->dev.kobj, &cdev->device.kobj, +"thermal_cooling" ); +if (result) + goto end; + result = +sysfs_create_link (&cdev->device.kobj, &device->dev.kobj, +"device" ); +if (result) + goto end; + } + + end: +return result; +} + +static int intel_menlow_memory_remove (struct acpi_device *device,int type) +{ +struct thermal_cooling_device *cdev =acpi_driver_data (device); + +if (!device || !cdev) +return -EINVAL ; + +sysfs_remove_link (&device->dev.kobj,"thermal_cooling" ); +sysfs_remove_link (&cdev->device.kobj,"device" ); +thermal_cooling_device_unregister (cdev); + +return 0 ; +} + +const static struct acpi_device_id intel_menlow_memory_ids[] = { + {"INT0002" ,0 }, + {"" ,0 }, +}; + +static struct acpi_driver intel_menlow_memory_driver = { + .name ="intel_menlow_thermal_control" , + .ids = intel_menlow_memory_ids, + .ops = { + .add = intel_menlow_memory_add, + .remove = intel_menlow_memory_remove, + }, +}; + +/* +* Sensor control on menlow platform +*/ + +#define THERMAL_AUX0 0 +#define THERMAL_AUX1 1 +#define GET_AUX0 "GAX0" +#define GET_AUX1 "GAX1" +#define SET_AUX0 "SAX0" +#define SET_AUX1 "SAX1" + +struct intel_menlow_attribute { +struct device_attribute attr; +struct device *device; +acpi_handle handle; +struct list_head node; +}; + +static LIST_HEAD (intel_menlow_attr_list); +static DEFINE_MUTEX (intel_menlow_attr_lock); + +/* +* sensor_get_auxtrip - get the current auxtrip value from sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_get_auxtrip (acpi_handle handle,int index,int *value) +{ +acpi_status status; + +if ((index !=0 && index !=1 ) || !value) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX1 :GET_AUX0 , +NULL , (unsigned long *)value); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +/* +* sensor_set_auxtrip - set the new auxtrip value to sensor +* @name: Thermalzone name +* @auxtype : AUX0/AUX1 +* @buf: syfs buffer +*/ +static int sensor_set_auxtrip (acpi_handle handle,int index,int value) +{ +acpi_status status; +union acpi_object arg = { +ACPI_TYPE_INTEGER + }; +struct acpi_object_list args = { +1 , &arg + }; +int temp; + +if (index !=0 && index !=1 ) +return -EINVAL ; + + status =acpi_evaluate_integer (handle, index ?GET_AUX0 :GET_AUX1 , +NULL , (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; +if ((index && value < temp) || (!index && value > temp)) +return -EINVAL ; + + arg.integer.value = value; + status =acpi_evaluate_integer (handle, index ?SET_AUX1 :SET_AUX0 , + &args, (unsigned long *)&temp); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* do we need to check the return value of SAX0/SAX1 ? */ + +return 0 ; +} + +#define to_intel_menlow_attr (_attr) \ + container_of(_attr, struct intel_menlow_attribute, attr) + +static ssize_t aux0_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,0 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux1_show (struct device *dev, +struct device_attribute *dev_attr,char *buf) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + + result =sensor_get_auxtrip (attr->handle,1 , &value); + +return result ? result :sprintf (buf,"%lu" ,KELVIN_TO_CELSIUS (value)); +} + +static ssize_t aux0_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,0 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +static ssize_t aux1_store (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct intel_menlow_attribute *attr =to_intel_menlow_attr (dev_attr); +int value; +int result; + +/*Sanity check; should be a positive integer */ +if (!sscanf (buf,"%d" , &value)) +return -EINVAL ; + +if (value <0 ) +return -EINVAL ; + + result =sensor_set_auxtrip (attr->handle,1 ,CELSIUS_TO_KELVIN (value)); +return result ? result : count; +} + +/* BIOS can enable/disable the thermal user application in dabney platform */ +#define BIOS_ENABLED "\\_TZ.GSTS" +static ssize_t bios_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +acpi_status status; +unsigned long bios_enabled; + + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &bios_enabled); +if (ACPI_FAILURE (status)) +return -ENODEV ; + +return sprintf (buf,"%s\n" , bios_enabled ?"enabled" :"disabled" ); +} + +static int intel_menlow_add_one_attribute (char *name,int mode,void *show, +void *store,struct device *dev, +acpi_handle handle) +{ +struct intel_menlow_attribute *attr; +int result; + + attr =kzalloc (sizeof (struct intel_menlow_attribute ),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.attr.name = name; + attr->attr.attr.mode = mode; + attr->attr.show = show; + attr->attr.store = store; + attr->device = dev; + attr->handle = handle; + + result =device_create_file (dev, &attr->attr); +if (result) +return result; + +mutex_lock (&intel_menlow_attr_lock); +list_add_tail (&attr->node, &intel_menlow_attr_list); +mutex_unlock (&intel_menlow_attr_lock); + +return 0 ; +} + +static acpi_status intel_menlow_register_sensor (acpi_handle handle,u32 lvl, +void *context,void **rv) +{ +acpi_status status; +acpi_handle dummy; +struct thermal_zone_device *thermal; +int result; + + result =acpi_bus_get_private_data (handle, (void **)&thermal); +if (result) +return 0 ; + +/* _TZ must have the AUX0/1 methods */ + status =acpi_get_handle (handle,GET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX0 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux0" ,0644 , + aux0_show, aux0_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + + status =acpi_get_handle (handle,GET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + status =acpi_get_handle (handle,SET_AUX1 , &dummy); +if (ACPI_FAILURE (status)) + goto not_found; + + result =intel_menlow_add_one_attribute ("aux1" ,0644 , + aux1_show, aux1_store, + &thermal->device, handle); +if (result) +return AE_ERROR ; + +/* +* create the "dabney_enabled" attribute which means the user app +* should be loaded or not +*/ + + result =intel_menlow_add_one_attribute ("bios_enabled" ,0444 , + bios_enabled_show,NULL , + &thermal->device, handle); +if (result) +return AE_ERROR ; + + not_found: +if (status ==AE_NOT_FOUND ) +return AE_OK ; +else +return status; +} + +static void intel_menlow_unregister_sensor (void ) +{ +struct intel_menlow_attribute *pos, *next; + +mutex_lock (&intel_menlow_attr_lock); +list_for_each_entry_safe (pos, next, &intel_menlow_attr_list, node) { +list_del (&pos->node); +device_remove_file (pos->device, &pos->attr); +kfree (pos); + } +mutex_unlock (&intel_menlow_attr_lock); + +return ; +} + +static int __init intel_menlow_module_init (void ) +{ +int result = -ENODEV ; +acpi_status status; +unsigned long enable; + +if (acpi_disabled) +return result; + +/* Looking for the \_TZ.GSTS method */ + status =acpi_evaluate_integer (NULL ,BIOS_ENABLED ,NULL , &enable); +if (ACPI_FAILURE (status) || !enable) +return -ENODEV ; + +/* Looking for ACPI device MEM0 with hardware id INT0002 */ + result =acpi_bus_register_driver (&intel_menlow_memory_driver); +if (result) +return result; + +/* Looking for sensors in each ACPI thermal zone */ + status =acpi_walk_namespace (ACPI_TYPE_THERMAL ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , + intel_menlow_register_sensor,NULL ,NULL ); +if (ACPI_FAILURE (status)) + result = -ENODEV ; + +return 0 ; +} + +static void __exit intel_menlow_module_exit(void) +{ +acpi_bus_unregister_driver (&intel_menlow_memory_driver); +intel_menlow_unregister_sensor (); +} + +module_init (intel_menlow_module_init); +module_exit (intel_menlow_module_exit);
drivers/misc/Kconfig +9 -0
@@ -232,4 +232,13 @@ config ATMEL_SSC If unsure, say N. +config INTEL_MENLOW + tristate "Thermal Management driver for Intel menlow platform" + depends on ACPI_THERMAL + ---help--- + ACPI thermal management enhancement driver on + Intel Menlow platform. + + If unsure, say N. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
Quoted 10 lines · Zhang Rui
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++
Why is this in drivers/misc? I don't have a thermal.h in mainline, but if this is a new subsystem your adding care to create a directory under drivers/ for it?
drivers/misc/intel_menlow.c line 6
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]>
Please add a whitespace before the * so they line up.
drivers/misc/intel_menlow.c line 42
Quoted 2 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );
I've never seen a driver with two MODULE_AUTHOR statements before. Does this actually work? What does modinfo -F author say for your module?
Quoted 10 lines · Zhang Rui
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++
Why is this in drivers/misc? I don't have a thermal.h in mainline, but if this is a new subsystem your adding care to create a directory under drivers/ for it?
drivers/misc/intel_menlow.c line 6
Quoted 6 lines
drivers/misc/intel_menlow.c new file +6
-0+/* +* intel_menlow.c - Intel menlow Driver for thermal management extension +* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]>
Please add a whitespace before the * so they line up.
drivers/misc/intel_menlow.c line 42
Quoted 2 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );
I've never seen a driver with two MODULE_AUTHOR statements before. Does this actually work? What does modinfo -F author say for your module?
Quoted 9 lines
-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Monday, January 21, 2008 3:24 PM
To: Zhang, Rui
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; Thomas, Sujith
Subject: Re: [PATCH 9/10] introduceintel_menlowplatform specific
driver
Quoted 12 lines · Zhang Rui
Quoted 10 lines
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527
Quoted 3 lines
++++++++++++++++++++++++++++++++++++++++++++
Why is this in
drivers/misc? I don't have athermal.hin mainline,
but
Quoted 1 line
if this is a new subsystem your adding care to create a directory
under
Quoted 1 line
drivers/for it?
This patch series adds a new "thermal" subsystem and is rightly placed under drivers/thermal/ . intel_menlow.c isn't fully a thermal driver. It does all the platform specific stuff (thermal is one of them). It's not fitting under any of the subsystems hence moved to drivers/misc
Quoted 10 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+/* +* intel_menlow.c - Intel menlow Driver for thermal managementextension
drivers/misc/intel_menlow.c line 6
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> Please add a whitespace before the * so they line up.
Will take care of this.
Quoted 5 lines
drivers/misc/intel_menlow.c line 42
Quoted 3 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );I've never seen a driver with two
MODULE_AUTHORstatements before.
Does
Quoted 1 line
this actually work? What does modinfo -F author say for your module?
There is nothing wrong in giving 2 MODULE_AUTHORS. Both will be displayed in the command modinfo -F author.
:-Sujith
Quoted 9 lines
-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Monday, January 21, 2008 3:24 PM
To: Zhang, Rui
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; Thomas, Sujith
Subject: Re: [PATCH 9/10] introduceintel_menlowplatform specific
driver
Quoted 12 lines · Zhang Rui
Quoted 10 lines
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527
Quoted 3 lines
++++++++++++++++++++++++++++++++++++++++++++
Why is this in
drivers/misc? I don't have athermal.hin mainline,
but
Quoted 1 line
if this is a new subsystem your adding care to create a directory
under
Quoted 1 line
drivers/for it?
This patch series adds a new "thermal" subsystem and is rightly placed under drivers/thermal/ . intel_menlow.c isn't fully a thermal driver. It does all the platform specific stuff (thermal is one of them). It's not fitting under any of the subsystems hence moved to drivers/misc
Quoted 10 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+/* +* intel_menlow.c - Intel menlow Driver for thermal managementextension
drivers/misc/intel_menlow.c line 6
Quoted 4 lines
drivers/misc/intel_menlow.c new file +4
-0+* +* Copyright (C) 2008 Intel Corp +* Copyright (C) 2008 Sujith Thomas <[email protected]> +* Copyright (C) 2008 Zhang Rui <[email protected]> Please add a whitespace before the * so they line up.
Will take care of this.
Quoted 5 lines
drivers/misc/intel_menlow.c line 42
Quoted 3 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );I've never seen a driver with two
MODULE_AUTHORstatements before.
Does
Quoted 1 line
this actually work? What does modinfo -F author say for your module?
There is nothing wrong in giving 2 MODULE_AUTHORS. Both will be displayed in the command modinfo -F author.
:-Sujith
Quoted 9 lines · Sujith
Quoted 6 lines
drivers/misc/intel_menlow.c line 42
Quoted 3 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );I've never seen a driver with two
MODULE_AUTHORstatements before. Does this actually work? What does modinfo -F author say for your module?There is nothing wrong in giving 2
MODULE_AUTHORS. Both will be displayed in the command modinfo -F author.
Coding-wise, it is no problem. MODULE_* gets transformed into char __mod_*line, so as long as you have the two MODULE_AUTHOR() macros on different lines, it will work.
It is cool to actually see this working out-of-the-box with modinfo too (even without the -F option). Could decouple a few AUTHOR lines.
Quoted 9 lines · Sujith
Quoted 6 lines
drivers/misc/intel_menlow.c line 42
Quoted 3 lines
drivers/misc/intel_menlow.c new file +2
-0+MODULE_AUTHOR ("Thomas Sujith" ); +MODULE_AUTHOR ("Zhang Rui" );I've never seen a driver with two
MODULE_AUTHORstatements before. Does this actually work? What does modinfo -F author say for your module?There is nothing wrong in giving 2
MODULE_AUTHORS. Both will be displayed in the command modinfo -F author.
Coding-wise, it is no problem. MODULE_* gets transformed into char __mod_*line, so as long as you have the two MODULE_AUTHOR() macros on different lines, it will work.
It is cool to actually see this working out-of-the-box with modinfo too (even without the -F option). Could decouple a few AUTHOR lines.
Len Brown
reviewerQuoted 12 lines · Christoph Hellwig
Quoted 10 lines · Zhang Rui
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines
Why is this in
drivers/misc? I don't have athermal.hin mainline, but if this is a new subsystem your adding care to create a directory underdrivers/for it?
Hi Christoph,
I'm sure it was me who suggested putting intel_menlo.c under drivers/misc.
A while back I refused to let any new platform specific drivers under drivers/acpi, and asked that the ones here already move out.
This is because they happne to use ACPI, but are not actually part of the ACPI sub-system (any more than ATA is).
Also, I wanted the maintainer roles to be clear -- these
drivers have primary maintainers other than me, and those
guys are in the heroic, but tragic, business of writing platform-specific drivers for systems with no documentation or vendor support.
drivers/misc/asus-laptop.cdrivers/misc/fujitsu-laptop.cdrivers/misc/msi-laptop.cdrivers/misc/sony-laptop.cdrivers/misc/thinkpad_acpi.cdrivers/misc/sony-laptop.c
intel_menlo.c fits in with this group, the only difference is that its primary maintainers actually have documentation:-)
is there a better place than drivers/misc for this group?
thanks,
-Len
Len Brown
reviewerQuoted 12 lines · Christoph Hellwig
Quoted 10 lines · Zhang Rui
From: Thomas Sujith <[email protected]>
Intel menlow platform specific driver for thermal management.
Signed-off-by Thomas Sujith <[email protected]>Signed-off-by Zhang Rui <[email protected]>--- drivers/misc/Kconfig | 10 drivers/misc/Makefile | 1 drivers/misc/intel_menlow.c | 527 ++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines
Why is this in
drivers/misc? I don't have athermal.hin mainline, but if this is a new subsystem your adding care to create a directory underdrivers/for it?
Hi Christoph,
I'm sure it was me who suggested putting intel_menlo.c under drivers/misc.
A while back I refused to let any new platform specific drivers under drivers/acpi, and asked that the ones here already move out.
This is because they happne to use ACPI, but are not actually part of the ACPI sub-system (any more than ATA is).
Also, I wanted the maintainer roles to be clear -- these
drivers have primary maintainers other than me, and those
guys are in the heroic, but tragic, business of writing platform-specific drivers for systems with no documentation or vendor support.
drivers/misc/asus-laptop.cdrivers/misc/fujitsu-laptop.cdrivers/misc/msi-laptop.cdrivers/misc/sony-laptop.cdrivers/misc/thinkpad_acpi.cdrivers/misc/sony-laptop.c
intel_menlo.c fits in with this group, the only difference is that its primary maintainers actually have documentation:-)
is there a better place than drivers/misc for this group?
thanks,
-Len