aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal
diff options
context:
space:
mode:
authorDurgadoss R <durgadoss.r@intel.com>2012-09-18 01:34:57 -0400
committerZhang Rui <rui.zhang@intel.com>2012-11-05 01:00:05 -0500
commita4a15485fbba44d162d626141b9a7404e790f570 (patch)
tree1fdff11c9a771b879238f03eafec080fa193edf7 /drivers/thermal
parent50125a9b27dd09e9afdc1b8712ba0b3859886c68 (diff)
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 <durgadoss.r@intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_sys.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index dca3bfc0e702..0afd84cb127d 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -49,7 +49,86 @@ static DEFINE_MUTEX(thermal_idr_lock);
49 49
50static LIST_HEAD(thermal_tz_list); 50static LIST_HEAD(thermal_tz_list);
51static LIST_HEAD(thermal_cdev_list); 51static LIST_HEAD(thermal_cdev_list);
52static LIST_HEAD(thermal_governor_list);
53
52static DEFINE_MUTEX(thermal_list_lock); 54static DEFINE_MUTEX(thermal_list_lock);
55static DEFINE_MUTEX(thermal_governor_lock);
56
57static struct thermal_governor *__find_governor(const char *name)
58{
59 struct thermal_governor *pos;
60
61 list_for_each_entry(pos, &thermal_governor_list, governor_list)
62 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
63 return pos;
64
65 return NULL;
66}
67
68int thermal_register_governor(struct thermal_governor *governor)
69{
70 int err;
71 const char *name;
72 struct thermal_zone_device *pos;
73
74 if (!governor)
75 return -EINVAL;
76
77 mutex_lock(&thermal_governor_lock);
78
79 err = -EBUSY;
80 if (__find_governor(governor->name) == NULL) {
81 err = 0;
82 list_add(&governor->governor_list, &thermal_governor_list);
83 }
84
85 mutex_lock(&thermal_list_lock);
86
87 list_for_each_entry(pos, &thermal_tz_list, node) {
88 if (pos->governor)
89 continue;
90 if (pos->tzp)
91 name = pos->tzp->governor_name;
92 else
93 name = DEFAULT_THERMAL_GOVERNOR;
94 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
95 pos->governor = governor;
96 }
97
98 mutex_unlock(&thermal_list_lock);
99 mutex_unlock(&thermal_governor_lock);
100
101 return err;
102}
103EXPORT_SYMBOL_GPL(thermal_register_governor);
104
105void thermal_unregister_governor(struct thermal_governor *governor)
106{
107 struct thermal_zone_device *pos;
108
109 if (!governor)
110 return;
111
112 mutex_lock(&thermal_governor_lock);
113
114 if (__find_governor(governor->name) == NULL)
115 goto exit;
116
117 mutex_lock(&thermal_list_lock);
118
119 list_for_each_entry(pos, &thermal_tz_list, node) {
120 if (!strnicmp(pos->governor->name, governor->name,
121 THERMAL_NAME_LENGTH))
122 pos->governor = NULL;
123 }
124
125 mutex_unlock(&thermal_list_lock);
126 list_del(&governor->governor_list);
127exit:
128 mutex_unlock(&thermal_governor_lock);
129 return;
130}
131EXPORT_SYMBOL_GPL(thermal_unregister_governor);
53 132
54static int get_idr(struct idr *idr, struct mutex *lock, int *id) 133static int get_idr(struct idr *idr, struct mutex *lock, int *id)
55{ 134{
@@ -1437,6 +1516,16 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1437 if (result) 1516 if (result)
1438 goto unregister; 1517 goto unregister;
1439 1518
1519 /* Update 'this' zone's governor information */
1520 mutex_lock(&thermal_governor_lock);
1521
1522 if (tz->tzp)
1523 tz->governor = __find_governor(tz->tzp->governor_name);
1524 else
1525 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1526
1527 mutex_unlock(&thermal_governor_lock);
1528
1440 result = thermal_add_hwmon_sysfs(tz); 1529 result = thermal_add_hwmon_sysfs(tz);
1441 if (result) 1530 if (result)
1442 goto unregister; 1531 goto unregister;
@@ -1500,6 +1589,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1500 if (tz->ops->get_mode) 1589 if (tz->ops->get_mode)
1501 device_remove_file(&tz->device, &dev_attr_mode); 1590 device_remove_file(&tz->device, &dev_attr_mode);
1502 remove_trip_attrs(tz); 1591 remove_trip_attrs(tz);
1592 tz->governor = NULL;
1503 1593
1504 thermal_remove_hwmon_sysfs(tz); 1594 thermal_remove_hwmon_sysfs(tz);
1505 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); 1595 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);