From 23064088d6aea049746755e9851760620921a80b Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:04:52 +0530 Subject: Thermal: Refactor thermal.h file This patch rearranges the code in thermal.h file, in the following order, so that it is easy to read/maintain. 1. All #defines 2. All enums 3. All fops structures 4. All device structures 5. All function declarations Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 78 +++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 91b34812cd8..8611e3eba60 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -29,6 +29,23 @@ #include #include +#define THERMAL_TRIPS_NONE -1 +#define THERMAL_MAX_TRIPS 12 +#define THERMAL_NAME_LENGTH 20 + +/* No upper/lower limit requirement */ +#define THERMAL_NO_LIMIT -1UL + +/* Unit conversion macros */ +#define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \ + ((long)t-2732+5)/10 : ((long)t-2732-5)/10) +#define CELSIUS_TO_KELVIN(t) ((t)*10+2732) + +/* Adding event notification support elements */ +#define THERMAL_GENL_FAMILY_NAME "thermal_event" +#define THERMAL_GENL_VERSION 0x01 +#define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group" + struct thermal_zone_device; struct thermal_cooling_device; @@ -50,6 +67,30 @@ enum thermal_trend { THERMAL_TREND_DROPPING, /* temperature is dropping */ }; +/* Events supported by Thermal Netlink */ +enum events { + THERMAL_AUX0, + THERMAL_AUX1, + THERMAL_CRITICAL, + THERMAL_DEV_FAULT, +}; + +/* attributes of thermal_genl_family */ +enum { + THERMAL_GENL_ATTR_UNSPEC, + THERMAL_GENL_ATTR_EVENT, + __THERMAL_GENL_ATTR_MAX, +}; +#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1) + +/* commands supported by the thermal_genl_family */ +enum { + THERMAL_GENL_CMD_UNSPEC, + THERMAL_GENL_CMD_EVENT, + __THERMAL_GENL_CMD_MAX, +}; +#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1) + struct thermal_zone_device_ops { int (*bind) (struct thermal_zone_device *, struct thermal_cooling_device *); @@ -83,11 +124,6 @@ struct thermal_cooling_device_ops { int (*set_cur_state) (struct thermal_cooling_device *, unsigned long); }; -#define THERMAL_NO_LIMIT -1UL /* no upper/lower limit requirement */ - -#define THERMAL_TRIPS_NONE -1 -#define THERMAL_MAX_TRIPS 12 -#define THERMAL_NAME_LENGTH 20 struct thermal_cooling_device { int id; char type[THERMAL_NAME_LENGTH]; @@ -100,10 +136,6 @@ struct thermal_cooling_device { struct list_head node; }; -#define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \ - ((long)t-2732+5)/10 : ((long)t-2732-5)/10) -#define CELSIUS_TO_KELVIN(t) ((t)*10+2732) - struct thermal_attr { struct device_attribute attr; char name[THERMAL_NAME_LENGTH]; @@ -131,38 +163,13 @@ struct thermal_zone_device { struct list_head node; struct delayed_work poll_queue; }; -/* Adding event notification support elements */ -#define THERMAL_GENL_FAMILY_NAME "thermal_event" -#define THERMAL_GENL_VERSION 0x01 -#define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group" - -enum events { - THERMAL_AUX0, - THERMAL_AUX1, - THERMAL_CRITICAL, - THERMAL_DEV_FAULT, -}; struct thermal_genl_event { u32 orig; enum events event; }; -/* attributes of thermal_genl_family */ -enum { - THERMAL_GENL_ATTR_UNSPEC, - THERMAL_GENL_ATTR_EVENT, - __THERMAL_GENL_ATTR_MAX, -}; -#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1) - -/* commands supported by the thermal_genl_family */ -enum { - THERMAL_GENL_CMD_UNSPEC, - THERMAL_GENL_CMD_EVENT, - __THERMAL_GENL_CMD_MAX, -}; -#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1) +/* Function declarations */ struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, void *, const struct thermal_zone_device_ops *, int, int); void thermal_zone_device_unregister(struct thermal_zone_device *); @@ -173,6 +180,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); void thermal_zone_device_update(struct thermal_zone_device *); + struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, const struct thermal_cooling_device_ops *); void thermal_cooling_device_unregister(struct thermal_cooling_device *); -- cgit v1.2.3 From 9b4298a088907811a4fe5a5d7cd2454da60708c5 Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:04:54 +0530 Subject: Thermal: Add get trend, get instance API's to thermal_sys This patch adds the following API's to thermal_sys.c, that can be used by other Thermal drivers. * get_tz_trend: obtain the trend of the given thermal zone * get_thermal_instance: obtain the instance corresponding to the given tz, cdev and the trip point. Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 8611e3eba60..32af124d23c 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -185,6 +185,10 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, const struct thermal_cooling_device_ops *); void thermal_cooling_device_unregister(struct thermal_cooling_device *); +int get_tz_trend(struct thermal_zone_device *, int); +struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, + struct thermal_cooling_device *, int); + #ifdef CONFIG_NET extern int thermal_generate_netlink_event(u32 orig, enum events event); #else -- cgit v1.2.3 From ef87394791206019e4e4e04cb746865f2dc115ed Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:04:55 +0530 Subject: Thermal: Add platform level information to thermal.h This patch adds platform level information to thermal.h by introducing two structures to hold: * bind parameters for a thermal zone, * zone level platform parameters Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 32af124d23c..4caa32e400b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -157,6 +157,7 @@ struct thermal_zone_device { int passive; unsigned int forced_passive; const struct thermal_zone_device_ops *ops; + const struct thermal_zone_params *tzp; struct list_head thermal_instances; struct idr idr; struct mutex lock; /* protect thermal_instances list */ @@ -164,6 +165,34 @@ struct thermal_zone_device { struct delayed_work poll_queue; }; +/* Structure that holds binding parameters for a zone */ +struct thermal_bind_params { + struct thermal_cooling_device *cdev; + + /* + * This is a measure of 'how effectively these devices can + * cool 'this' thermal zone. The shall be determined by platform + * characterization. This is on a 'percentage' scale. + * See Documentation/thermal/sysfs-api.txt for more information. + */ + int weight; + + /* + * This is a bit mask that gives the binding relation between this + * thermal zone and cdev, for a particular trip point. + * See Documentation/thermal/sysfs-api.txt for more information. + */ + int trip_mask; + int (*match) (struct thermal_zone_device *tz, + struct thermal_cooling_device *cdev); +}; + +/* Structure to define Thermal Zone parameters */ +struct thermal_zone_params { + int num_tbps; /* Number of tbp entries */ + struct thermal_bind_params *tbp; +}; + struct thermal_genl_event { u32 orig; enum events event; -- cgit v1.2.3 From 50125a9b27dd09e9afdc1b8712ba0b3859886c68 Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:04:56 +0530 Subject: Thermal: Pass zone parameters as argument to tzd_register This patch adds the thermal zone parameter as an argument to the tzd_register() function call; and updates other drivers using this function. Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 4caa32e400b..58cb1c036a0 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -200,7 +200,8 @@ struct thermal_genl_event { /* Function declarations */ struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, - void *, const struct thermal_zone_device_ops *, int, int); + void *, const struct thermal_zone_device_ops *, + const struct thermal_zone_params *, int, int); void thermal_zone_device_unregister(struct thermal_zone_device *); int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, -- cgit v1.2.3 From a4a15485fbba44d162d626141b9a7404e790f570 Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:04:57 +0530 Subject: Thermal: Add thermal governor registration APIs This patch creates a structure to hold platform thermal governor information, and provides APIs for individual thermal governors to register/unregister with the Thermal framework. Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 58cb1c036a0..6182bd5f750 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -46,6 +46,9 @@ #define THERMAL_GENL_VERSION 0x01 #define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group" +/* Default Thermal Governor: Does Linear Throttling */ +#define DEFAULT_THERMAL_GOVERNOR "step_wise" + struct thermal_zone_device; struct thermal_cooling_device; @@ -158,6 +161,7 @@ struct thermal_zone_device { unsigned int forced_passive; const struct thermal_zone_device_ops *ops; const struct thermal_zone_params *tzp; + struct thermal_governor *governor; struct list_head thermal_instances; struct idr idr; struct mutex lock; /* protect thermal_instances list */ @@ -165,6 +169,14 @@ struct thermal_zone_device { struct delayed_work poll_queue; }; +/* Structure that holds thermal governor information */ +struct thermal_governor { + char name[THERMAL_NAME_LENGTH]; + int (*throttle)(struct thermal_zone_device *tz, int trip); + struct list_head governor_list; + struct module *owner; +}; + /* Structure that holds binding parameters for a zone */ struct thermal_bind_params { struct thermal_cooling_device *cdev; @@ -189,6 +201,7 @@ struct thermal_bind_params { /* Structure to define Thermal Zone parameters */ struct thermal_zone_params { + char governor_name[THERMAL_NAME_LENGTH]; int num_tbps; /* Number of tbp entries */ struct thermal_bind_params *tbp; }; @@ -219,6 +232,9 @@ int get_tz_trend(struct thermal_zone_device *, int); struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, struct thermal_cooling_device *, int); +int thermal_register_governor(struct thermal_governor *); +void thermal_unregister_governor(struct thermal_governor *); + #ifdef CONFIG_NET extern int thermal_generate_netlink_event(u32 orig, enum events event); #else -- cgit v1.2.3 From dc76548269ca2c44e5ddc29db5c36188bc4f2234 Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:05:00 +0530 Subject: Thermal: Make thermal_cdev_update as a global function This patch makes the thermal_cdev_update function as a global one, so that other files can use it. This function serves as a single arbitrator to set the state of a cooling device. Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 6182bd5f750..2bd91584181 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -231,6 +231,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *); int get_tz_trend(struct thermal_zone_device *, int); struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, struct thermal_cooling_device *, int); +void thermal_cdev_update(struct thermal_cooling_device *); int thermal_register_governor(struct thermal_governor *); void thermal_unregister_governor(struct thermal_governor *); -- cgit v1.2.3 From f2b4caafd4aa64c9438b0a94af78b127228e6905 Mon Sep 17 00:00:00 2001 From: Durgadoss R Date: Tue, 18 Sep 2012 11:05:05 +0530 Subject: Thermal: Add a notification API This patch adds a notification API which the sensor drivers' can use to notify the framework. The framework then takes care of the throttling according to the configured policy. Signed-off-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/thermal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 2bd91584181..807f2146fe3 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -232,6 +232,7 @@ int get_tz_trend(struct thermal_zone_device *, int); struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, struct thermal_cooling_device *, int); void thermal_cdev_update(struct thermal_cooling_device *); +void notify_thermal_framework(struct thermal_zone_device *, int); int thermal_register_governor(struct thermal_governor *); void thermal_unregister_governor(struct thermal_governor *); -- cgit v1.2.3 From aa1acb0451bb27add173d9641d0b74c58889e693 Mon Sep 17 00:00:00 2001 From: "hongbo.zhang" Date: Thu, 15 Nov 2012 18:56:42 +0800 Subject: Thermal: Add ST-Ericsson DB8500 thermal driver. This driver is based on the thermal management framework in thermal_sys.c. A thermal zone device is created with the trip points to which cooling devices can be bound, the current cooling device is cpufreq, e.g. CPU frequency is clipped down to cool the CPU, and other cooling devices can be added and bound to the trip points dynamically. The platform specific PRCMU interrupts are used to active thermal update when trip points are reached. Signed-off-by: hongbo.zhang Reviewed-by: Viresh Kumar Reviewed-by: Francesco Lavra Signed-off-by: Zhang Rui --- include/linux/platform_data/db8500_thermal.h | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 include/linux/platform_data/db8500_thermal.h (limited to 'include') diff --git a/include/linux/platform_data/db8500_thermal.h b/include/linux/platform_data/db8500_thermal.h new file mode 100644 index 00000000000..3bf60902e90 --- /dev/null +++ b/include/linux/platform_data/db8500_thermal.h @@ -0,0 +1,38 @@ +/* + * db8500_thermal.h - DB8500 Thermal Management Implementation + * + * Copyright (C) 2012 ST-Ericsson + * Copyright (C) 2012 Linaro Ltd. + * + * Author: Hongbo Zhang + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ + +#ifndef _DB8500_THERMAL_H_ +#define _DB8500_THERMAL_H_ + +#include + +#define COOLING_DEV_MAX 8 + +struct db8500_trip_point { + unsigned long temp; + enum thermal_trip_type type; + char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; +}; + +struct db8500_thsens_platform_data { + struct db8500_trip_point trip_points[THERMAL_MAX_TRIPS]; + int num_trips; +}; + +#endif /* _DB8500_THERMAL_H_ */ -- cgit v1.2.3 From 3778ff5c709899a29cefe4b3077a926d0e1e9785 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Mon, 12 Nov 2012 15:58:50 +0000 Subject: thermal: cpu cooling: use const parameter while registering There are predefined cpu_masks that are const data structures. This patch changes the cpu cooling register function so that those const cpu_masks can be used, without compilation warnings. include/linux/cpumask.h * The following particular system cpumasks and operations manage * possible, present, active and online cpus. * * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable * cpu_present_mask - has bit 'cpu' set iff cpu is populated * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler * cpu_active_mask - has bit 'cpu' set iff cpu available to migration * Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- include/linux/cpu_cooling.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index 851530128e6..b30cc79c7a8 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -35,7 +35,7 @@ * @clip_cpus: cpumask of cpus where the frequency constraints will happen */ struct thermal_cooling_device *cpufreq_cooling_register( - struct cpumask *clip_cpus); + const struct cpumask *clip_cpus); /** * cpufreq_cooling_unregister - function to remove cpufreq cooling device. @@ -44,7 +44,7 @@ struct thermal_cooling_device *cpufreq_cooling_register( void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); #else /* !CONFIG_CPU_THERMAL */ static inline struct thermal_cooling_device *cpufreq_cooling_register( - struct cpumask *clip_cpus) + const struct cpumask *clip_cpus) { return NULL; } -- cgit v1.2.3 From 4ba115b1e1ab6b717e08e0f4e766a1d16853d217 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Wed, 14 Nov 2012 15:23:30 +0000 Subject: thermal: cpu cooling: allow module builds As thermal drivers can be built as modules and also the thermal framework itself, building cpu cooling only as built-in can cause linking errors. For instance: * Generic Thermal sysfs driver * Generic Thermal sysfs driver (THERMAL) [M/n/y/?] m generic cpu cooling support (CPU_THERMAL) [N/y/?] (NEW) y with the following drive: CONFIG_OMAP_BANDGAP=m generates: ERROR: "cpufreq_cooling_unregister" [drivers/staging/omap-thermal/omap-thermal.ko] undefined! ERROR: "cpufreq_cooling_register" [drivers/staging/omap-thermal/omap-thermal.ko] undefined! This patch changes cpu cooling driver to allow it to be built as module. Reported-by: Enric Balletbo i Serra Signed-off-by: Eduardo Valentin Reviewed-by: Durgadoss R Signed-off-by: Zhang Rui --- include/linux/cpu_cooling.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index b30cc79c7a8..40b4ef54cc7 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -29,7 +29,7 @@ #define CPUFREQ_COOLING_START 0 #define CPUFREQ_COOLING_STOP 1 -#ifdef CONFIG_CPU_THERMAL +#if defined(CONFIG_CPU_THERMAL) || defined(CONFIG_CPU_THERMAL_MODULE) /** * cpufreq_cooling_register - function to create cpufreq cooling device. * @clip_cpus: cpumask of cpus where the frequency constraints will happen -- cgit v1.2.3 From 1f53ef17d3ed6c34868cc8e7aa7c1d351c2fdc95 Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Wed, 12 Dec 2012 15:31:37 +0800 Subject: Thermal: Fix DEFAULT_THERMAL_GOVERNOR Fix DEFAULT_THERMAL_GOVERNOR to be consistant with the default governor selected in kernel config file. Signed-off-by: Zhang Rui --- include/linux/thermal.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 807f2146fe3..fe82022478e 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -46,8 +46,14 @@ #define THERMAL_GENL_VERSION 0x01 #define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group" -/* Default Thermal Governor: Does Linear Throttling */ -#define DEFAULT_THERMAL_GOVERNOR "step_wise" +/* Default Thermal Governor */ +#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE) +#define DEFAULT_THERMAL_GOVERNOR "step_wise" +#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE) +#define DEFAULT_THERMAL_GOVERNOR "fair_share" +#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE) +#define DEFAULT_THERMAL_GOVERNOR "user_space" +#endif struct thermal_zone_device; struct thermal_cooling_device; -- cgit v1.2.3