Lines Matching refs:tz
93 static u32 estimate_sustainable_power(struct thermal_zone_device *tz) in estimate_sustainable_power() argument
97 struct power_allocator_params *params = tz->governor_data; in estimate_sustainable_power()
99 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in estimate_sustainable_power()
106 if (power_actor_get_min_power(cdev, tz, &min_power)) in estimate_sustainable_power()
134 static void estimate_pid_constants(struct thermal_zone_device *tz, in estimate_pid_constants() argument
142 ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); in estimate_pid_constants()
158 if (!tz->tzp->k_po || force) in estimate_pid_constants()
159 tz->tzp->k_po = int_to_frac(sustainable_power) / in estimate_pid_constants()
162 if (!tz->tzp->k_pu || force) in estimate_pid_constants()
163 tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / in estimate_pid_constants()
166 if (!tz->tzp->k_i || force) in estimate_pid_constants()
167 tz->tzp->k_i = int_to_frac(10) / 1000; in estimate_pid_constants()
192 static u32 pid_controller(struct thermal_zone_device *tz, in pid_controller() argument
199 struct power_allocator_params *params = tz->governor_data; in pid_controller()
203 if (tz->tzp->sustainable_power) { in pid_controller()
204 sustainable_power = tz->tzp->sustainable_power; in pid_controller()
206 sustainable_power = estimate_sustainable_power(tz); in pid_controller()
207 estimate_pid_constants(tz, sustainable_power, in pid_controller()
212 err = control_temp - tz->temperature; in pid_controller()
216 p = mul_frac(err < 0 ? tz->tzp->k_po : tz->tzp->k_pu, err); in pid_controller()
224 i = mul_frac(tz->tzp->k_i, params->err_integral); in pid_controller()
226 if (err < int_to_frac(tz->tzp->integral_cutoff)) { in pid_controller()
227 s64 i_next = i + mul_frac(tz->tzp->k_i, err); in pid_controller()
242 d = mul_frac(tz->tzp->k_d, err - params->prev_err); in pid_controller()
243 d = div_frac(d, tz->passive_delay); in pid_controller()
253 trace_thermal_power_allocator_pid(tz, frac_to_int(err), in pid_controller()
332 static int allocate_power(struct thermal_zone_device *tz, in allocate_power() argument
336 struct power_allocator_params *params = tz->governor_data; in allocate_power()
344 mutex_lock(&tz->lock); in allocate_power()
348 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
388 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
398 if (cdev->ops->get_requested_power(cdev, tz, &req_power[i])) in allocate_power()
408 if (power_actor_get_max_power(cdev, tz, &max_power[i])) in allocate_power()
418 power_range = pid_controller(tz, control_temp, max_allocatable_power); in allocate_power()
426 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
440 trace_thermal_power_allocator(tz, req_power, total_req_power, in allocate_power()
443 max_allocatable_power, tz->temperature, in allocate_power()
444 control_temp - tz->temperature); in allocate_power()
448 mutex_unlock(&tz->lock); in allocate_power()
468 static void get_governor_trips(struct thermal_zone_device *tz, in get_governor_trips() argument
478 for (i = 0; i < tz->trips; i++) { in get_governor_trips()
482 ret = tz->ops->get_trip_type(tz, i, &type); in get_governor_trips()
484 dev_warn(&tz->device, in get_governor_trips()
521 static void allow_maximum_power(struct thermal_zone_device *tz) in allow_maximum_power() argument
524 struct power_allocator_params *params = tz->governor_data; in allow_maximum_power()
526 mutex_lock(&tz->lock); in allow_maximum_power()
527 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allow_maximum_power()
538 mutex_unlock(&tz->lock); in allow_maximum_power()
550 static int power_allocator_bind(struct thermal_zone_device *tz) in power_allocator_bind() argument
560 if (!tz->tzp) { in power_allocator_bind()
561 tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL); in power_allocator_bind()
562 if (!tz->tzp) { in power_allocator_bind()
570 if (!tz->tzp->sustainable_power) in power_allocator_bind()
571 dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); in power_allocator_bind()
573 get_governor_trips(tz, params); in power_allocator_bind()
575 if (tz->trips > 0) { in power_allocator_bind()
576 ret = tz->ops->get_trip_temp(tz, in power_allocator_bind()
580 estimate_pid_constants(tz, tz->tzp->sustainable_power, in power_allocator_bind()
587 tz->governor_data = params; in power_allocator_bind()
597 static void power_allocator_unbind(struct thermal_zone_device *tz) in power_allocator_unbind() argument
599 struct power_allocator_params *params = tz->governor_data; in power_allocator_unbind()
601 dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); in power_allocator_unbind()
604 kfree(tz->tzp); in power_allocator_unbind()
605 tz->tzp = NULL; in power_allocator_unbind()
608 kfree(tz->governor_data); in power_allocator_unbind()
609 tz->governor_data = NULL; in power_allocator_unbind()
612 static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) in power_allocator_throttle() argument
616 struct power_allocator_params *params = tz->governor_data; in power_allocator_throttle()
625 ret = tz->ops->get_trip_temp(tz, params->trip_switch_on, in power_allocator_throttle()
627 if (!ret && (tz->temperature < switch_on_temp)) { in power_allocator_throttle()
628 tz->passive = 0; in power_allocator_throttle()
630 allow_maximum_power(tz); in power_allocator_throttle()
634 tz->passive = 1; in power_allocator_throttle()
636 ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature, in power_allocator_throttle()
639 dev_warn(&tz->device, in power_allocator_throttle()
645 return allocate_power(tz, control_temp); in power_allocator_throttle()