Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

step_wise: Unify the code for both throttle and dethrottle

Signed-off-by: Zhang Rui <rui.zhang@intel.com>

Zhang Rui b8bb6cb9 3dbfff3d

+25 -45
+25 -45
drivers/thermal/step_wise.c
··· 99 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 102 static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) 144 103 { 145 104 long trip_temp; 146 105 enum thermal_trip_type trip_type; 147 106 enum thermal_trend trend; 107 + struct thermal_instance *instance; 108 + bool throttle = false; 109 + int old_target; 148 110 149 111 if (trip == THERMAL_TRIPS_NONE) { 150 112 trip_temp = tz->forced_passive; ··· 118 156 119 157 trend = get_tz_trend(tz, trip); 120 158 159 + if (tz->temperature >= trip_temp) 160 + throttle = true; 161 + 121 162 mutex_lock(&tz->lock); 122 163 123 - if (tz->temperature >= trip_temp) 124 - update_instance_for_throttle(tz, trip, trip_type, trend); 125 - else 126 - update_instance_for_dethrottle(tz, trip, trip_type, trend); 164 + list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 165 + if (instance->trip != trip) 166 + continue; 167 + 168 + old_target = instance->target; 169 + instance->target = get_target_state(instance, trend, throttle); 170 + 171 + /* Activate a passive thermal instance */ 172 + if (old_target == THERMAL_NO_TARGET && 173 + instance->target != THERMAL_NO_TARGET) 174 + update_passive_instance(tz, trip_type, 1); 175 + /* Deactivate a passive thermal instance */ 176 + else if (old_target != THERMAL_NO_TARGET && 177 + instance->target == THERMAL_NO_TARGET) 178 + update_passive_instance(tz, trip_type, -1); 179 + 180 + 181 + instance->cdev->updated = false; /* cdev needs update */ 182 + } 127 183 128 184 mutex_unlock(&tz->lock); 129 185 }