diff options
author | Zhang Rui <rui.zhang@intel.com> | 2012-11-22 02:45:02 -0500 |
---|---|---|
committer | Zhang Rui <rui.zhang@intel.com> | 2013-01-04 02:22:37 -0500 |
commit | b8bb6cb999858043489c1ddef08eed2127559169 (patch) | |
tree | c8a40b5a995a63355da9177e87b16ba015eefbab | |
parent | 3dbfff3dfe6714aeefb615c65bec0800dc5a4c51 (diff) |
step_wise: Unify the code for both throttle and dethrottle
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
-rw-r--r-- | drivers/thermal/step_wise.c | 70 |
1 files changed, 25 insertions, 45 deletions
diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index f45dd0f768f0..407cde3211c1 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c | |||
@@ -99,52 +99,14 @@ static void update_passive_instance(struct thermal_zone_device *tz, | |||
99 | tz->passive += value; | 99 | tz->passive += value; |
100 | } | 100 | } |
101 | 101 | ||
102 | static void update_instance_for_throttle(struct thermal_zone_device *tz, | ||
103 | int trip, enum thermal_trip_type trip_type, | ||
104 | enum thermal_trend trend) | ||
105 | { | ||
106 | struct thermal_instance *instance; | ||
107 | |||
108 | list_for_each_entry(instance, &tz->thermal_instances, tz_node) { | ||
109 | if (instance->trip != trip) | ||
110 | continue; | ||
111 | |||
112 | instance->target = get_target_state(instance, trend, true); | ||
113 | |||
114 | /* Activate a passive thermal instance */ | ||
115 | if (instance->target == THERMAL_NO_TARGET) | ||
116 | update_passive_instance(tz, trip_type, 1); | ||
117 | |||
118 | instance->cdev->updated = false; /* cdev needs update */ | ||
119 | } | ||
120 | } | ||
121 | |||
122 | static void update_instance_for_dethrottle(struct thermal_zone_device *tz, | ||
123 | int trip, enum thermal_trip_type trip_type, | ||
124 | enum thermal_trend trend) | ||
125 | { | ||
126 | struct thermal_instance *instance; | ||
127 | |||
128 | list_for_each_entry(instance, &tz->thermal_instances, tz_node) { | ||
129 | if (instance->trip != trip || | ||
130 | instance->target == THERMAL_NO_TARGET) | ||
131 | continue; | ||
132 | |||
133 | instance->target = get_target_state(instance, trend, false); | ||
134 | |||
135 | /* Deactivate a passive thermal instance */ | ||
136 | if (instance->target == THERMAL_NO_TARGET) | ||
137 | update_passive_instance(tz, trip_type, -1); | ||
138 | |||
139 | instance->cdev->updated = false; /* cdev needs update */ | ||
140 | } | ||
141 | } | ||
142 | |||
143 | static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) | 102 | static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) |
144 | { | 103 | { |
145 | long trip_temp; | 104 | long trip_temp; |
146 | enum thermal_trip_type trip_type; | 105 | enum thermal_trip_type trip_type; |
147 | enum thermal_trend trend; | 106 | enum thermal_trend trend; |
107 | struct thermal_instance *instance; | ||
108 | bool throttle = false; | ||
109 | int old_target; | ||
148 | 110 | ||
149 | if (trip == THERMAL_TRIPS_NONE) { | 111 | if (trip == THERMAL_TRIPS_NONE) { |
150 | trip_temp = tz->forced_passive; | 112 | trip_temp = tz->forced_passive; |
@@ -156,12 +118,30 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) | |||
156 | 118 | ||
157 | trend = get_tz_trend(tz, trip); | 119 | trend = get_tz_trend(tz, trip); |
158 | 120 | ||
121 | if (tz->temperature >= trip_temp) | ||
122 | throttle = true; | ||
123 | |||
159 | mutex_lock(&tz->lock); | 124 | mutex_lock(&tz->lock); |
160 | 125 | ||
161 | if (tz->temperature >= trip_temp) | 126 | list_for_each_entry(instance, &tz->thermal_instances, tz_node) { |
162 | update_instance_for_throttle(tz, trip, trip_type, trend); | 127 | if (instance->trip != trip) |
163 | else | 128 | continue; |
164 | update_instance_for_dethrottle(tz, trip, trip_type, trend); | 129 | |
130 | old_target = instance->target; | ||
131 | instance->target = get_target_state(instance, trend, throttle); | ||
132 | |||
133 | /* Activate a passive thermal instance */ | ||
134 | if (old_target == THERMAL_NO_TARGET && | ||
135 | instance->target != THERMAL_NO_TARGET) | ||
136 | update_passive_instance(tz, trip_type, 1); | ||
137 | /* Deactivate a passive thermal instance */ | ||
138 | else if (old_target != THERMAL_NO_TARGET && | ||
139 | instance->target == THERMAL_NO_TARGET) | ||
140 | update_passive_instance(tz, trip_type, -1); | ||
141 | |||
142 | |||
143 | instance->cdev->updated = false; /* cdev needs update */ | ||
144 | } | ||
165 | 145 | ||
166 | mutex_unlock(&tz->lock); | 146 | mutex_unlock(&tz->lock); |
167 | } | 147 | } |