All the patchset based on Kernel version 3.2-rc6 and uses the cpufreq cooling registration api's implemented in earlier patchset http://www.spinics.net/lists/linux-pm/msg26500.html
The code added in this patchset adds a thermal interface layer for samsung exynos platforms. This layer is registered from the hwmon based temperature sensor and recieves/monitor the temperature from the sensor and informs the generic thermal layer to take the necessary cooling action. Currently this layer can be used to create only one thermal zone and hence only one temperature sensor can register.
Some modifications are done in the temperature sensor driver to export the information needed for the thermal interface to register with the core linux thermal framework and with the cpu frequency based cooling devices.
A simple data/control flow diagrams to illustrate this,
Core Linux thermal <-------> Exynos thermal <-------- Temperature Sensor | | |/ | Cpufreq cooling device <-----
Amit Daniel Kachhap (3): thermal: exynos: Add thermal interface support for linux thermal layer thermal: exynos4: Register the tmu sensor with the thermal interface layer ARM: exynos4: Add thermal sensor driver platform device support
arch/arm/mach-exynos/Kconfig | 12 ++ arch/arm/mach-exynos/Makefile | 1 + arch/arm/mach-exynos/clock.c | 4 + arch/arm/mach-exynos/dev-tmu.c | 64 +++++++ arch/arm/mach-exynos/include/mach/irqs.h | 2 + arch/arm/mach-exynos/include/mach/map.h | 1 + arch/arm/mach-exynos/mach-origen.c | 1 + arch/arm/plat-samsung/include/plat/devs.h | 1 + drivers/hwmon/exynos4_tmu.c | 34 ++++- drivers/thermal/Kconfig | 8 + drivers/thermal/Makefile | 1 + drivers/thermal/exynos_thermal.c | 255 +++++++++++++++++++++++++++++ include/linux/exynos_thermal.h | 59 +++++++ include/linux/platform_data/exynos4_tmu.h | 7 + 14 files changed, 447 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-exynos/dev-tmu.c create mode 100644 drivers/thermal/exynos_thermal.c create mode 100644 include/linux/exynos_thermal.h
This codes uses the generic linux thermal layer and creates a bridge between temperature sensors, linux thermal framework and cooling devices for samsung exynos platform. This layer recieves or monitor the temperature from the sensor and informs the generic thermal layer to take the necessary cooling action.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org --- drivers/thermal/Kconfig | 8 ++ drivers/thermal/Makefile | 1 + drivers/thermal/exynos_thermal.c | 255 ++++++++++++++++++++++++++++++++++++++ include/linux/exynos_thermal.h | 59 +++++++++ 4 files changed, 323 insertions(+), 0 deletions(-) create mode 100644 drivers/thermal/exynos_thermal.c create mode 100644 include/linux/exynos_thermal.h
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 298c1cd..4e8df56 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -29,3 +29,11 @@ config CPU_THERMAL This will be useful for platforms using the generic thermal interface and not the ACPI interface. If you want this support, you should say Y or M here. + +config SAMSUNG_THERMAL_INTERFACE + bool "Samsung Thermal interface support" + depends on THERMAL && CPU_THERMAL + help + This is a samsung thermal interface which will be used as + a link between sensors and cooling devices with linux thermal + framework. diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 655cbc4..c67b6b2 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -4,3 +4,4 @@
obj-$(CONFIG_THERMAL) += thermal_sys.o obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o +obj-$(CONFIG_SAMSUNG_THERMAL_INTERFACE) += exynos_thermal.o diff --git a/drivers/thermal/exynos_thermal.c b/drivers/thermal/exynos_thermal.c new file mode 100644 index 0000000..7c916db --- /dev/null +++ b/drivers/thermal/exynos_thermal.c @@ -0,0 +1,255 @@ +/* linux/drivers/thermal/exynos_thermal.c + * + * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/thermal.h> +#include <linux/platform_device.h> +#include <linux/cpufreq.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/cpu_cooling.h> +#include <linux/platform_data/exynos4_tmu.h> +#include <linux/exynos_thermal.h> + +struct exynos4_thermal_zone { + unsigned int idle_interval; + unsigned int active_interval; + struct thermal_zone_device *therm_dev; + struct thermal_cooling_device *cool_dev; + struct platform_device *exynos4_dev; + struct thermal_sensor_conf *sensor_conf; + struct exynos4_tmu_platform_data *sensor_data; +}; + +static struct exynos4_thermal_zone *th_zone; + +static int exynos4_get_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode *mode) +{ + if (th_zone->sensor_conf) { + pr_info("Temperature sensor not initialised\n"); + *mode = THERMAL_DEVICE_DISABLED; + } else + *mode = THERMAL_DEVICE_ENABLED; + return 0; +} + +static int exynos4_set_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) +{ + if (!th_zone->therm_dev) { + pr_notice("thermal zone not registered\n"); + return 0; + } + if (mode == THERMAL_DEVICE_ENABLED) + th_zone->therm_dev->polling_delay = + th_zone->active_interval*1000; + else + th_zone->therm_dev->polling_delay = + th_zone->idle_interval*1000; + + thermal_zone_device_update(th_zone->therm_dev); + pr_info("thermal polling set for duration=%d sec\n", + th_zone->therm_dev->polling_delay/1000); + return 0; +} + +/*This may be called from interrupt based temperature sensor*/ +void exynos4_report_trigger(void) +{ + unsigned int th_temp = th_zone->sensor_data->threshold; + unsigned int monitor_temp = th_temp + + th_zone->sensor_data->trigger_levels[1]; + + thermal_zone_device_update(th_zone->therm_dev); + + if (th_zone->therm_dev->last_temperature > monitor_temp) + th_zone->therm_dev->polling_delay = + th_zone->active_interval*1000; + else + th_zone->therm_dev->polling_delay = + th_zone->idle_interval*1000; +} + +static int exynos4_get_trip_type(struct thermal_zone_device *thermal, int trip, + enum thermal_trip_type *type) +{ + if (trip == 0 || trip == 1) + *type = THERMAL_TRIP_STATE_ACTIVE; + else if (trip == 2) + *type = THERMAL_TRIP_CRITICAL; + else + return -EINVAL; + + return 0; +} + +static int exynos4_get_trip_temp(struct thermal_zone_device *thermal, int trip, + unsigned long *temp) +{ + unsigned int th_temp = th_zone->sensor_data->threshold; + + /*Monitor zone*/ + if (trip == 0) + *temp = th_temp + th_zone->sensor_data->trigger_levels[1]; + /*Warn zone*/ + else if (trip == 1) + *temp = th_temp + th_zone->sensor_data->trigger_levels[2]; + /*Panic zone*/ + else if (trip == 2) + *temp = th_temp + th_zone->sensor_data->trigger_levels[3]; + else + return -EINVAL; + /*convert the temperature into millicelsius*/ + *temp = *temp * 1000; + return 0; +} + +static int exynos4_get_crit_temp(struct thermal_zone_device *thermal, + unsigned long *temp) +{ + unsigned int th_temp = th_zone->sensor_data->threshold; + /*Panic zone*/ + *temp = th_temp + th_zone->sensor_data->trigger_levels[3]; + /*convert the temperature into millicelsius*/ + *temp = *temp * 1000; + return 0; +} + +static int exynos4_bind(struct thermal_zone_device *thermal, + struct thermal_cooling_device *cdev) +{ + /* if the cooling device is the one from exynos4 bind it */ + if (cdev != th_zone->cool_dev) + return 0; + + if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) { + pr_err("error binding cooling dev\n"); + return -EINVAL; + } + if (thermal_zone_bind_cooling_device(thermal, 1, cdev)) { + pr_err("error binding cooling dev\n"); + return -EINVAL; + } + + return 0; +} + +static int exynos4_unbind(struct thermal_zone_device *thermal, + struct thermal_cooling_device *cdev) +{ + if (cdev != th_zone->cool_dev) + return 0; + if (thermal_zone_unbind_cooling_device(thermal, 0, cdev)) { + pr_err("error unbinding cooling dev\n"); + return -EINVAL; + } + return 0; +} + +static int exynos4_get_temp(struct thermal_zone_device *thermal, + unsigned long *temp) +{ + void *data; + + if (!th_zone->sensor_conf) { + pr_info("Temperature sensor not initialised\n"); + return -EINVAL; + } + data = th_zone->sensor_conf->private_data; + *temp = th_zone->sensor_conf->read_temperature(data); + /*convert the temperature into millicelsius*/ + *temp = *temp * 1000; + return 0; +} + +/* bind callback functions to thermalzone */ +static struct thermal_zone_device_ops exynos4_dev_ops = { + .bind = exynos4_bind, + .unbind = exynos4_unbind, + .get_temp = exynos4_get_temp, + .get_mode = exynos4_get_mode, + .set_mode = exynos4_set_mode, + .get_trip_type = exynos4_get_trip_type, + .get_trip_temp = exynos4_get_trip_temp, + .get_crit_temp = exynos4_get_crit_temp, +}; + +int exynos4_register_thermal(struct thermal_sensor_conf *sensor_conf) +{ + int ret; + + if (!sensor_conf) { + pr_err("Temperature sensor not initialised\n"); + return -EINVAL; + } + + th_zone = kzalloc(sizeof(struct exynos4_thermal_zone), GFP_KERNEL); + if (!th_zone) { + ret = -ENOMEM; + goto err_unregister; + } + + th_zone->sensor_conf = sensor_conf; + + th_zone->sensor_data = sensor_conf->sensor_data; + if (!th_zone->sensor_data) { + pr_err("Temperature sensor data not initialised\n"); + ret = -EINVAL; + goto err_unregister; + } + + th_zone->cool_dev = cpufreq_cooling_register( + (struct freq_pctg_table *)th_zone->sensor_data->freq_tab, + th_zone->sensor_data->freq_tab_count, cpumask_of(0)); + + if (IS_ERR(th_zone->cool_dev)) { + pr_err("Failed to register cpufreq cooling device\n"); + ret = -EINVAL; + goto err_unregister; + } + + th_zone->therm_dev = thermal_zone_device_register(sensor_conf->name, + 3, NULL, &exynos4_dev_ops, 0, 0, 0, 1000); + if (IS_ERR(th_zone->therm_dev)) { + pr_err("Failed to register thermal zone device\n"); + ret = -EINVAL; + goto err_unregister; + } + + th_zone->active_interval = 1; + th_zone->idle_interval = 10; + + exynos4_set_mode(th_zone->therm_dev, THERMAL_DEVICE_DISABLED); + + pr_info("Exynos: Kernel Thermal management registered\n"); + + return 0; + +err_unregister: + exynos4_unregister_thermal(); + return ret; +} +EXPORT_SYMBOL(exynos4_register_thermal); + +void exynos4_unregister_thermal(void) +{ + if (th_zone && th_zone->cool_dev) + cpufreq_cooling_unregister(); + + if (th_zone && th_zone->therm_dev) + thermal_zone_device_unregister(th_zone->therm_dev); + + kfree(th_zone); + + pr_info("Exynos: Kernel Thermal management unregistered\n"); +} +EXPORT_SYMBOL(exynos4_unregister_thermal); diff --git a/include/linux/exynos_thermal.h b/include/linux/exynos_thermal.h new file mode 100644 index 0000000..de7195b --- /dev/null +++ b/include/linux/exynos_thermal.h @@ -0,0 +1,59 @@ +/* linux/include/linux/exynos_thermal.h + * + * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#ifndef THERMAL_INTERFACE_H +#define THERMAL_INTERFACE_H +/* CPU Zone information */ + +#define SENSOR_NAME_LEN 16 + +#define PANIC_ZONE 4 +#define WARN_ZONE 3 +#define MONITOR_ZONE 2 +#define SAFE_ZONE 1 +#define NO_ACTION 0 + +/** + * struct exynos4_tmu_platform_data + * @name: name of the temperature sensor + * @read_temperature: A function pointer to read temperature info + * @private_data: Temperature sensor private data + * @sensor_data: Sensor specific information like trigger temperature, level + */ +struct thermal_sensor_conf { + char name[SENSOR_NAME_LEN]; + int (*read_temperature)(void *data); + void *private_data; + void *sensor_data; +}; + +/** + * exynos4_register_thermal: Register to the exynos thermal interface. + * @sensor_conf: Structure containing temperature sensor information + * + * returns zero on success, else negative errno. + */ +int exynos4_register_thermal(struct thermal_sensor_conf *sensor_conf); + +/** + * exynos4_unregister_thermal: Un-register from the exynos thermal interface. + * + * return not applicable. + */ +void exynos4_unregister_thermal(void); + +/** + * exynos4_report_trigger: Report any trigger level crossed in the + * temperature sensor. This may be useful to take any cooling action. + * + * return not applicable. + */ +extern void exynos4_report_trigger(void); +#endif
Export and register information from the hwmon tmu sensor to the samsung exynos kernel thermal framework where different cooling devices and thermal zone are binded. The exported information is based according to the data structure thermal_sensor_conf present in exynos_thermal.h. HWMON sysfs functions are currently left although all of them are present in generic linux thermal layer. Also the platform data structure is modified to pass frequency cooling in percentages for each thermal level.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org --- drivers/hwmon/exynos4_tmu.c | 34 ++++++++++++++++++++++++++-- include/linux/platform_data/exynos4_tmu.h | 7 ++++++ 2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/exynos4_tmu.c b/drivers/hwmon/exynos4_tmu.c index f2359a0..6912a7f 100644 --- a/drivers/hwmon/exynos4_tmu.c +++ b/drivers/hwmon/exynos4_tmu.c @@ -37,6 +37,9 @@ #include <linux/hwmon-sysfs.h>
#include <linux/platform_data/exynos4_tmu.h> +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +#include <linux/exynos_thermal.h> +#endif
#define EXYNOS4_TMU_REG_TRIMINFO 0x0 #define EXYNOS4_TMU_REG_CONTROL 0x20 @@ -248,10 +251,13 @@ static void exynos4_tmu_work(struct work_struct *work)
kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);
- enable_irq(data->irq);
clk_disable(data->clk); mutex_unlock(&data->lock); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + exynos4_report_trigger(); +#endif + enable_irq(data->irq); }
static irqreturn_t exynos4_tmu_irq(int irq, void *id) @@ -345,6 +351,14 @@ static const struct attribute_group exynos4_tmu_attr_group = { .attrs = exynos4_tmu_attributes, };
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +static struct thermal_sensor_conf exynos4_sensor_conf = { + .name = "exynos4-therm", + .read_temperature = (int (*)(void *))exynos4_tmu_read, +}; +#endif +/*CONFIG_SAMSUNG_THERMAL_INTERFACE*/ + static int __devinit exynos4_tmu_probe(struct platform_device *pdev) { struct exynos4_tmu_data *data; @@ -432,9 +446,20 @@ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) }
exynos4_tmu_control(pdev, true); - +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + (&exynos4_sensor_conf)->private_data = data; + (&exynos4_sensor_conf)->sensor_data = pdata; + ret = exynos4_register_thermal(&exynos4_sensor_conf); + if (ret) { + dev_err(&pdev->dev, "Failed to register thermal interface\n"); + goto err_hwmon_device; + } +#endif return 0; - +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +err_hwmon_device: + hwmon_device_unregister(data->hwmon_dev); +#endif err_create_group: sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); err_clk: @@ -458,6 +483,9 @@ static int __devexit exynos4_tmu_remove(struct platform_device *pdev)
exynos4_tmu_control(pdev, false);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + exynos4_unregister_thermal(); +#endif hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group);
diff --git a/include/linux/platform_data/exynos4_tmu.h b/include/linux/platform_data/exynos4_tmu.h index 39e038c..642c508 100644 --- a/include/linux/platform_data/exynos4_tmu.h +++ b/include/linux/platform_data/exynos4_tmu.h @@ -21,6 +21,7 @@
#ifndef _LINUX_EXYNOS4_TMU_H #define _LINUX_EXYNOS4_TMU_H +#include <linux/cpu_cooling.h>
enum calibration_type { TYPE_ONE_POINT_TRIMMING, @@ -64,6 +65,9 @@ enum calibration_type { * in the positive-TC generator block * 0 <= reference_voltage <= 31 * @cal_type: calibration type for temperature + * @freq_pctg_table: Table representing frequency reduction percentage. + * @freq_tab_count: Count of the above table as frequency reduction may + * applicable to only some of the trigger levels. * * This structure is required for configuration of exynos4_tmu driver. */ @@ -79,5 +83,8 @@ struct exynos4_tmu_platform_data { u8 reference_voltage;
enum calibration_type cal_type; + + struct freq_pctg_table freq_tab[4]; + unsigned int freq_tab_count; }; #endif /* _LINUX_EXYNOS4_TMU_H */
On Wed, 2011-12-21 at 06:59 -0500, Amit Daniel Kachhap wrote:
Export and register information from the hwmon tmu sensor to the samsung exynos kernel thermal framework where different cooling devices and thermal zone are binded. The exported information is based according to the data structure thermal_sensor_conf present in exynos_thermal.h. HWMON sysfs functions are currently left although all of them are present in generic linux thermal layer. Also the platform data structure is modified to pass frequency cooling in percentages for each thermal level.
Hi Amit,
wouldn't it make more sense to merge the code as necessary from hwmon/exynos4_tmu.c into the new thermal/exynos_thermal.c, and drop hwmon/exynos4_tmu.c entirely ?
With that, you should get the hwmon entries for free, and we would not have to maintain two drivers with overlapping functionality.
Thanks, Guenter
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org
drivers/hwmon/exynos4_tmu.c | 34 ++++++++++++++++++++++++++-- include/linux/platform_data/exynos4_tmu.h | 7 ++++++ 2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/exynos4_tmu.c b/drivers/hwmon/exynos4_tmu.c index f2359a0..6912a7f 100644 --- a/drivers/hwmon/exynos4_tmu.c +++ b/drivers/hwmon/exynos4_tmu.c @@ -37,6 +37,9 @@ #include <linux/hwmon-sysfs.h> #include <linux/platform_data/exynos4_tmu.h> +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +#include <linux/exynos_thermal.h> +#endif #define EXYNOS4_TMU_REG_TRIMINFO 0x0 #define EXYNOS4_TMU_REG_CONTROL 0x20 @@ -248,10 +251,13 @@ static void exynos4_tmu_work(struct work_struct *work) kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);
- enable_irq(data->irq);
clk_disable(data->clk); mutex_unlock(&data->lock); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- exynos4_report_trigger();
+#endif
- enable_irq(data->irq);
} static irqreturn_t exynos4_tmu_irq(int irq, void *id) @@ -345,6 +351,14 @@ static const struct attribute_group exynos4_tmu_attr_group = { .attrs = exynos4_tmu_attributes, }; +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +static struct thermal_sensor_conf exynos4_sensor_conf = {
- .name = "exynos4-therm",
- .read_temperature = (int (*)(void *))exynos4_tmu_read,
+}; +#endif +/*CONFIG_SAMSUNG_THERMAL_INTERFACE*/
static int __devinit exynos4_tmu_probe(struct platform_device *pdev) { struct exynos4_tmu_data *data; @@ -432,9 +446,20 @@ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) } exynos4_tmu_control(pdev, true);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- (&exynos4_sensor_conf)->private_data = data;
- (&exynos4_sensor_conf)->sensor_data = pdata;
- ret = exynos4_register_thermal(&exynos4_sensor_conf);
- if (ret) {
dev_err(&pdev->dev, "Failed to register thermal interface\n");
goto err_hwmon_device;
- }
+#endif return 0;
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +err_hwmon_device:
- hwmon_device_unregister(data->hwmon_dev);
+#endif err_create_group: sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); err_clk: @@ -458,6 +483,9 @@ static int __devexit exynos4_tmu_remove(struct platform_device *pdev) exynos4_tmu_control(pdev, false); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- exynos4_unregister_thermal();
+#endif hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); diff --git a/include/linux/platform_data/exynos4_tmu.h b/include/linux/platform_data/exynos4_tmu.h index 39e038c..642c508 100644 --- a/include/linux/platform_data/exynos4_tmu.h +++ b/include/linux/platform_data/exynos4_tmu.h @@ -21,6 +21,7 @@ #ifndef _LINUX_EXYNOS4_TMU_H #define _LINUX_EXYNOS4_TMU_H +#include <linux/cpu_cooling.h> enum calibration_type { TYPE_ONE_POINT_TRIMMING, @@ -64,6 +65,9 @@ enum calibration_type {
- in the positive-TC generator block
- 0 <= reference_voltage <= 31
- @cal_type: calibration type for temperature
- @freq_pctg_table: Table representing frequency reduction percentage.
- @freq_tab_count: Count of the above table as frequency reduction may
*/
- applicable to only some of the trigger levels.
- This structure is required for configuration of exynos4_tmu driver.
@@ -79,5 +83,8 @@ struct exynos4_tmu_platform_data { u8 reference_voltage; enum calibration_type cal_type;
- struct freq_pctg_table freq_tab[4];
- unsigned int freq_tab_count;
}; #endif /* _LINUX_EXYNOS4_TMU_H */
Hi Guenter,
The main idea of this work is to leave the current userspace based notification scheme and add the kernel based cooling scheme on top of it. Anyway, It is a good idea to move the file hwmon/exynos4_tmu.c as this creates 2 hwmon entries. Adding CC: Donggeun Kim to know his opinion.
Thanks, Amit Daniel
On 4 January 2012 03:55, Guenter Roeck guenter.roeck@ericsson.com wrote:
On Wed, 2011-12-21 at 06:59 -0500, Amit Daniel Kachhap wrote:
Export and register information from the hwmon tmu sensor to the samsung exynos kernel thermal framework where different cooling devices and thermal zone are binded. The exported information is based according to the data structure thermal_sensor_conf present in exynos_thermal.h. HWMON sysfs functions are currently left although all of them are present in generic linux thermal layer. Also the platform data structure is modified to pass frequency cooling in percentages for each thermal level.
Hi Amit,
wouldn't it make more sense to merge the code as necessary from hwmon/exynos4_tmu.c into the new thermal/exynos_thermal.c, and drop hwmon/exynos4_tmu.c entirely ?
With that, you should get the hwmon entries for free, and we would not have to maintain two drivers with overlapping functionality.
Thanks, Guenter
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org
drivers/hwmon/exynos4_tmu.c | 34 ++++++++++++++++++++++++++-- include/linux/platform_data/exynos4_tmu.h | 7 ++++++ 2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/exynos4_tmu.c b/drivers/hwmon/exynos4_tmu.c index f2359a0..6912a7f 100644 --- a/drivers/hwmon/exynos4_tmu.c +++ b/drivers/hwmon/exynos4_tmu.c @@ -37,6 +37,9 @@ #include <linux/hwmon-sysfs.h>
#include <linux/platform_data/exynos4_tmu.h> +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +#include <linux/exynos_thermal.h> +#endif
#define EXYNOS4_TMU_REG_TRIMINFO 0x0 #define EXYNOS4_TMU_REG_CONTROL 0x20 @@ -248,10 +251,13 @@ static void exynos4_tmu_work(struct work_struct *work)
kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);
- enable_irq(data->irq);
clk_disable(data->clk); mutex_unlock(&data->lock); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- exynos4_report_trigger();
+#endif
- enable_irq(data->irq);
}
static irqreturn_t exynos4_tmu_irq(int irq, void *id) @@ -345,6 +351,14 @@ static const struct attribute_group exynos4_tmu_attr_group = { .attrs = exynos4_tmu_attributes, };
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +static struct thermal_sensor_conf exynos4_sensor_conf = {
- .name = "exynos4-therm",
- .read_temperature = (int (*)(void *))exynos4_tmu_read,
+}; +#endif +/*CONFIG_SAMSUNG_THERMAL_INTERFACE*/
static int __devinit exynos4_tmu_probe(struct platform_device *pdev) { struct exynos4_tmu_data *data; @@ -432,9 +446,20 @@ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) }
exynos4_tmu_control(pdev, true);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- (&exynos4_sensor_conf)->private_data = data;
- (&exynos4_sensor_conf)->sensor_data = pdata;
- ret = exynos4_register_thermal(&exynos4_sensor_conf);
- if (ret) {
- dev_err(&pdev->dev, "Failed to register thermal interface\n");
- goto err_hwmon_device;
- }
+#endif return 0;
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +err_hwmon_device:
- hwmon_device_unregister(data->hwmon_dev);
+#endif err_create_group: sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); err_clk: @@ -458,6 +483,9 @@ static int __devexit exynos4_tmu_remove(struct platform_device *pdev)
exynos4_tmu_control(pdev, false);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
- exynos4_unregister_thermal();
+#endif hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group);
diff --git a/include/linux/platform_data/exynos4_tmu.h b/include/linux/platform_data/exynos4_tmu.h index 39e038c..642c508 100644 --- a/include/linux/platform_data/exynos4_tmu.h +++ b/include/linux/platform_data/exynos4_tmu.h @@ -21,6 +21,7 @@
#ifndef _LINUX_EXYNOS4_TMU_H #define _LINUX_EXYNOS4_TMU_H +#include <linux/cpu_cooling.h>
enum calibration_type { TYPE_ONE_POINT_TRIMMING, @@ -64,6 +65,9 @@ enum calibration_type { * in the positive-TC generator block * 0 <= reference_voltage <= 31 * @cal_type: calibration type for temperature
- @freq_pctg_table: Table representing frequency reduction percentage.
- @freq_tab_count: Count of the above table as frequency reduction may
- applicable to only some of the trigger levels.
* * This structure is required for configuration of exynos4_tmu driver. */ @@ -79,5 +83,8 @@ struct exynos4_tmu_platform_data { u8 reference_voltage;
enum calibration_type cal_type;
- struct freq_pctg_table freq_tab[4];
- unsigned int freq_tab_count;
}; #endif /* _LINUX_EXYNOS4_TMU_H */
Hi Amit Daniel,
Hi Guenter,
The main idea of this work is to leave the current userspace based notification scheme and add the kernel based cooling scheme on top of it. Anyway, It is a good idea to move the file hwmon/exynos4_tmu.c as
But, What I feel is, kernel based cooling scheme will work only for Controlling 'CPU' frequency. But in SoC's there are other devices that Contribute to Thermal. For example, GPU, Display, Battery (during charging) etc.. In this case, we need a user space to control these devices. So, in a way, the user space notification mechanism is a unified solution for throttling all devices and keeps the kernel code light weight.
I am also curious to know why the existing mechanism did not work for you ?
Thanks, Durga
this creates 2 hwmon entries. Adding CC: Donggeun Kim to know his opinion.
Thanks, Amit Daniel
[snip.]
On Wed, 2012-01-04 at 05:23 -0500, R, Durgadoss wrote:
Hi Amit Daniel,
Hi Guenter,
The main idea of this work is to leave the current userspace based notification scheme and add the kernel based cooling scheme on top of it. Anyway, It is a good idea to move the file hwmon/exynos4_tmu.c as
But, What I feel is, kernel based cooling scheme will work only for Controlling 'CPU' frequency. But in SoC's there are other devices that Contribute to Thermal. For example, GPU, Display, Battery (during charging) etc.. In this case, we need a user space to control these devices. So, in a way, the user space notification mechanism is a unified solution for throttling all devices and keeps the kernel code light weight.
I am also curious to know why the existing mechanism did not work for you ?
That is one question.
For me, the main concern is that the proposed implementation creates duplicate hwmon entries for the same device, which is simply messy. If both the kernel thermal mechanism and the userspace mechanism are needed, I think it would make more sense to use a thermal driver and have that thermal driver generate the necessary userspace events.
Thanks, Guenter
Thanks, Durga
this creates 2 hwmon entries. Adding CC: Donggeun Kim to know his opinion.
Thanks, Amit Daniel
[snip.]
Actually, the TMU driver is closely related to thermal layer. I think it's okay to move it to the thermal.
Thanks. -Donggeun
On 2012년 01월 04일 19:14, Amit Kachhap wrote:
Hi Guenter,
The main idea of this work is to leave the current userspace based notification scheme and add the kernel based cooling scheme on top of it. Anyway, It is a good idea to move the file hwmon/exynos4_tmu.c as this creates 2 hwmon entries. Adding CC: Donggeun Kim to know his opinion.
Thanks, Amit Daniel
On 4 January 2012 03:55, Guenter Roeck guenter.roeck@ericsson.com wrote:
On Wed, 2011-12-21 at 06:59 -0500, Amit Daniel Kachhap wrote:
Export and register information from the hwmon tmu sensor to the samsung exynos kernel thermal framework where different cooling devices and thermal zone are binded. The exported information is based according to the data structure thermal_sensor_conf present in exynos_thermal.h. HWMON sysfs functions are currently left although all of them are present in generic linux thermal layer. Also the platform data structure is modified to pass frequency cooling in percentages for each thermal level.
Hi Amit,
wouldn't it make more sense to merge the code as necessary from hwmon/exynos4_tmu.c into the new thermal/exynos_thermal.c, and drop hwmon/exynos4_tmu.c entirely ?
With that, you should get the hwmon entries for free, and we would not have to maintain two drivers with overlapping functionality.
Thanks, Guenter
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org
drivers/hwmon/exynos4_tmu.c | 34 ++++++++++++++++++++++++++-- include/linux/platform_data/exynos4_tmu.h | 7 ++++++ 2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/exynos4_tmu.c b/drivers/hwmon/exynos4_tmu.c index f2359a0..6912a7f 100644 --- a/drivers/hwmon/exynos4_tmu.c +++ b/drivers/hwmon/exynos4_tmu.c @@ -37,6 +37,9 @@ #include <linux/hwmon-sysfs.h>
#include <linux/platform_data/exynos4_tmu.h> +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +#include <linux/exynos_thermal.h> +#endif
#define EXYNOS4_TMU_REG_TRIMINFO 0x0 #define EXYNOS4_TMU_REG_CONTROL 0x20 @@ -248,10 +251,13 @@ static void exynos4_tmu_work(struct work_struct *work)
kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);
enable_irq(data->irq); clk_disable(data->clk); mutex_unlock(&data->lock);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
exynos4_report_trigger();
+#endif
enable_irq(data->irq);
}
static irqreturn_t exynos4_tmu_irq(int irq, void *id) @@ -345,6 +351,14 @@ static const struct attribute_group exynos4_tmu_attr_group = { .attrs = exynos4_tmu_attributes, };
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +static struct thermal_sensor_conf exynos4_sensor_conf = {
.name = "exynos4-therm",
.read_temperature = (int (*)(void *))exynos4_tmu_read,
+}; +#endif +/*CONFIG_SAMSUNG_THERMAL_INTERFACE*/
static int __devinit exynos4_tmu_probe(struct platform_device *pdev) { struct exynos4_tmu_data *data; @@ -432,9 +446,20 @@ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) }
exynos4_tmu_control(pdev, true);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
(&exynos4_sensor_conf)->private_data = data;
(&exynos4_sensor_conf)->sensor_data = pdata;
ret = exynos4_register_thermal(&exynos4_sensor_conf);
if (ret) {
dev_err(&pdev->dev, "Failed to register thermal interface\n");
goto err_hwmon_device;
}
+#endif return 0;
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +err_hwmon_device:
hwmon_device_unregister(data->hwmon_dev);
+#endif err_create_group: sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); err_clk: @@ -458,6 +483,9 @@ static int __devexit exynos4_tmu_remove(struct platform_device *pdev)
exynos4_tmu_control(pdev, false);
+#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE
exynos4_unregister_thermal();
+#endif hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group);
diff --git a/include/linux/platform_data/exynos4_tmu.h b/include/linux/platform_data/exynos4_tmu.h index 39e038c..642c508 100644 --- a/include/linux/platform_data/exynos4_tmu.h +++ b/include/linux/platform_data/exynos4_tmu.h @@ -21,6 +21,7 @@
#ifndef _LINUX_EXYNOS4_TMU_H #define _LINUX_EXYNOS4_TMU_H +#include <linux/cpu_cooling.h>
enum calibration_type { TYPE_ONE_POINT_TRIMMING, @@ -64,6 +65,9 @@ enum calibration_type {
- in the positive-TC generator block
- 0 <= reference_voltage <= 31
- @cal_type: calibration type for temperature
- @freq_pctg_table: Table representing frequency reduction percentage.
- @freq_tab_count: Count of the above table as frequency reduction may
*/
- applicable to only some of the trigger levels.
- This structure is required for configuration of exynos4_tmu driver.
@@ -79,5 +83,8 @@ struct exynos4_tmu_platform_data { u8 reference_voltage;
enum calibration_type cal_type;
struct freq_pctg_table freq_tab[4];
unsigned int freq_tab_count;
}; #endif /* _LINUX_EXYNOS4_TMU_H */
This patch adds necessary source definations needed for TMU driver and the platform device support.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@linaro.org --- arch/arm/mach-exynos/Kconfig | 12 +++++ arch/arm/mach-exynos/Makefile | 1 + arch/arm/mach-exynos/clock.c | 4 ++ arch/arm/mach-exynos/dev-tmu.c | 64 +++++++++++++++++++++++++++++ arch/arm/mach-exynos/include/mach/irqs.h | 2 + arch/arm/mach-exynos/include/mach/map.h | 1 + arch/arm/mach-exynos/mach-origen.c | 1 + arch/arm/plat-samsung/include/plat/devs.h | 1 + 8 files changed, 86 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-exynos/dev-tmu.c
diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig index 724ec0f..cfc6119 100644 --- a/arch/arm/mach-exynos/Kconfig +++ b/arch/arm/mach-exynos/Kconfig @@ -82,6 +82,17 @@ config EXYNOS4_DEV_DWMCI help Compile in platform device definitions for DWMCI
+config EXYNOS4_DEV_TMU + bool "Exynos4 tmu device support" + default n + depends on ARCH_EXYNOS4 + ---help--- + Compile in platform device definitions for TMU. This macro also + enables compilation hwmon base TMU driver and also allows compilation + of the platform device files. The platform data in this case is trip + temperature and some tmu h/w configurations related parameter. + + config EXYNOS4_SETUP_I2C1 bool help @@ -288,6 +299,7 @@ config MACH_ORIGEN select SAMSUNG_DEV_BACKLIGHT select SAMSUNG_DEV_PWM select EXYNOS4_DEV_PD + select EXYNOS4_DEV_TMU select EXYNOS4_SETUP_FIMD0 select EXYNOS4_SETUP_SDHCI select EXYNOS4_SETUP_USB_PHY diff --git a/arch/arm/mach-exynos/Makefile b/arch/arm/mach-exynos/Makefile index 59069a3..d2493e8 100644 --- a/arch/arm/mach-exynos/Makefile +++ b/arch/arm/mach-exynos/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_EXYNOS4_DEV_AHCI) += dev-ahci.o obj-$(CONFIG_EXYNOS4_DEV_PD) += dev-pd.o obj-$(CONFIG_EXYNOS4_DEV_SYSMMU) += dev-sysmmu.o obj-$(CONFIG_EXYNOS4_DEV_DWMCI) += dev-dwmci.o +obj-$(CONFIG_EXYNOS4_DEV_TMU) += dev-tmu.o
obj-$(CONFIG_EXYNOS4_SETUP_FIMC) += setup-fimc.o obj-$(CONFIG_EXYNOS4_SETUP_FIMD0) += setup-fimd0.o diff --git a/arch/arm/mach-exynos/clock.c b/arch/arm/mach-exynos/clock.c index 2894f0a..edecc5e 100644 --- a/arch/arm/mach-exynos/clock.c +++ b/arch/arm/mach-exynos/clock.c @@ -567,6 +567,10 @@ static struct clk init_clocks_off[] = { .enable = exynos4_clk_ip_peril_ctrl, .ctrlbit = (1 << 15), }, { + .name = "tmu_apbif", + .enable = exynos4_clk_ip_perir_ctrl, + .ctrlbit = (1 << 17), + }, { .name = "keypad", .enable = exynos4_clk_ip_perir_ctrl, .ctrlbit = (1 << 16), diff --git a/arch/arm/mach-exynos/dev-tmu.c b/arch/arm/mach-exynos/dev-tmu.c new file mode 100644 index 0000000..2e98912 --- /dev/null +++ b/arch/arm/mach-exynos/dev-tmu.c @@ -0,0 +1,64 @@ +/* linux/arch/arm/mach-exynos4/dev-tmu.c + * + * Copyright 2011 by SAMSUNG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/platform_data/exynos4_tmu.h> +#include <asm/irq.h> + +#include <mach/irqs.h> +#include <mach/map.h> +#include <plat/devs.h> + +static struct resource exynos4_tmu_resource[] = { + [0] = { + .start = EXYNOS4_PA_TMU, + .end = EXYNOS4_PA_TMU + 0xFFFF - 1, + .flags = IORESOURCE_MEM, + }, + [1] = { + .start = IRQ_TMU_TRIG0, + .end = IRQ_TMU_TRIG0, + .flags = IORESOURCE_IRQ, + }, +}; + +static struct exynos4_tmu_platform_data default_tmu_data = { + .threshold = 80, + .trigger_levels[0] = 2, + .trigger_levels[1] = 5, + .trigger_levels[2] = 20, + .trigger_levels[3] = 30, + .trigger_level0_en = 1, + .trigger_level1_en = 1, + .trigger_level2_en = 1, + .trigger_level3_en = 1, + .gain = 15, + .reference_voltage = 7, + .cal_type = TYPE_ONE_POINT_TRIMMING, + .freq_tab[0] = { + .freq_clip_pctg[0] = 30, + }, + .freq_tab[1] = { + .freq_clip_pctg[0] = 99, + }, + .freq_tab_count = 2, +}; + +struct platform_device exynos4_device_tmu = { + .name = "exynos4-tmu", + .id = -1, + .num_resources = ARRAY_SIZE(exynos4_tmu_resource), + .resource = exynos4_tmu_resource, + .dev = { + .platform_data = &default_tmu_data, + }, +}; diff --git a/arch/arm/mach-exynos/include/mach/irqs.h b/arch/arm/mach-exynos/include/mach/irqs.h index dfd4b7e..d66a24b 100644 --- a/arch/arm/mach-exynos/include/mach/irqs.h +++ b/arch/arm/mach-exynos/include/mach/irqs.h @@ -125,6 +125,8 @@ #define COMBINER_GROUP(x) ((x) * MAX_IRQ_IN_COMBINER + IRQ_SPI(128)) #define COMBINER_IRQ(x, y) (COMBINER_GROUP(x) + y)
+#define IRQ_TMU_TRIG0 COMBINER_IRQ(2, 4) +#define IRQ_TMU_TRIG1 COMBINER_IRQ(3, 4) #define IRQ_SYSMMU_MDMA0_0 COMBINER_IRQ(4, 0) #define IRQ_SYSMMU_SSS_0 COMBINER_IRQ(4, 1) #define IRQ_SYSMMU_FIMC0_0 COMBINER_IRQ(4, 2) diff --git a/arch/arm/mach-exynos/include/mach/map.h b/arch/arm/mach-exynos/include/mach/map.h index 058541d..0d79b88 100644 --- a/arch/arm/mach-exynos/include/mach/map.h +++ b/arch/arm/mach-exynos/include/mach/map.h @@ -66,6 +66,7 @@ #define EXYNOS4_PA_COREPERI 0x10500000 #define EXYNOS4_PA_TWD 0x10500600 #define EXYNOS4_PA_L2CC 0x10502000 +#define EXYNOS4_PA_TMU 0x100C0000
#define EXYNOS4_PA_MDMA 0x10810000 #define EXYNOS4_PA_PDMA0 0x12680000 diff --git a/arch/arm/mach-exynos/mach-origen.c b/arch/arm/mach-exynos/mach-origen.c index f80b563..699140a 100644 --- a/arch/arm/mach-exynos/mach-origen.c +++ b/arch/arm/mach-exynos/mach-origen.c @@ -615,6 +615,7 @@ static struct platform_device *origen_devices[] __initdata = { &exynos4_device_pd[PD_MFC], &origen_device_gpiokeys, &origen_lcd_hv070wsa, + &exynos4_device_tmu, };
/* LCD Backlight data */ diff --git a/arch/arm/plat-samsung/include/plat/devs.h b/arch/arm/plat-samsung/include/plat/devs.h index ab633c9..74cbf0d 100644 --- a/arch/arm/plat-samsung/include/plat/devs.h +++ b/arch/arm/plat-samsung/include/plat/devs.h @@ -135,6 +135,7 @@ extern struct platform_device exynos4_device_pcm2; extern struct platform_device exynos4_device_pd[]; extern struct platform_device exynos4_device_spdif; extern struct platform_device exynos4_device_sysmmu; +extern struct platform_device exynos4_device_tmu;
extern struct platform_device samsung_asoc_dma; extern struct platform_device samsung_asoc_idma;