Lines Matching refs:tz
88 static u32 estimate_sustainable_power(struct thermal_zone_device *tz) in estimate_sustainable_power() argument
92 struct power_allocator_params *params = tz->governor_data; in estimate_sustainable_power()
94 &tz->trips[params->trip_max_desired_temperature]; in estimate_sustainable_power()
96 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in estimate_sustainable_power()
125 static void estimate_pid_constants(struct thermal_zone_device *tz, in estimate_pid_constants() argument
134 ret = __thermal_zone_get_trip(tz, trip_switch_on, &trip); in estimate_pid_constants()
149 tz->tzp->k_po = int_to_frac(sustainable_power) / in estimate_pid_constants()
152 tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / in estimate_pid_constants()
155 k_i = tz->tzp->k_pu / 10; in estimate_pid_constants()
156 tz->tzp->k_i = k_i > 0 ? k_i : 1; in estimate_pid_constants()
175 static u32 get_sustainable_power(struct thermal_zone_device *tz, in get_sustainable_power() argument
181 if (!tz->tzp->sustainable_power) in get_sustainable_power()
182 sustainable_power = estimate_sustainable_power(tz); in get_sustainable_power()
184 sustainable_power = tz->tzp->sustainable_power; in get_sustainable_power()
188 estimate_pid_constants(tz, sustainable_power, in get_sustainable_power()
192 tz->tzp->sustainable_power = sustainable_power; in get_sustainable_power()
217 static u32 pid_controller(struct thermal_zone_device *tz, in pid_controller() argument
224 struct power_allocator_params *params = tz->governor_data; in pid_controller()
228 sustainable_power = get_sustainable_power(tz, params, control_temp); in pid_controller()
230 err = control_temp - tz->temperature; in pid_controller()
234 p = mul_frac(err < 0 ? tz->tzp->k_po : tz->tzp->k_pu, err); in pid_controller()
242 i = mul_frac(tz->tzp->k_i, params->err_integral); in pid_controller()
244 if (err < int_to_frac(tz->tzp->integral_cutoff)) { in pid_controller()
245 s64 i_next = i + mul_frac(tz->tzp->k_i, err); in pid_controller()
260 d = mul_frac(tz->tzp->k_d, err - params->prev_err); in pid_controller()
261 d = div_frac(d, jiffies_to_msecs(tz->passive_delay_jiffies)); in pid_controller()
271 trace_thermal_power_allocator_pid(tz, frac_to_int(err), in pid_controller()
383 static int allocate_power(struct thermal_zone_device *tz, in allocate_power() argument
387 struct power_allocator_params *params = tz->governor_data; in allocate_power()
389 &tz->trips[params->trip_max_desired_temperature]; in allocate_power()
398 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
434 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
465 power_range = pid_controller(tz, control_temp, max_allocatable_power); in allocate_power()
473 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allocate_power()
487 trace_thermal_power_allocator(tz, req_power, total_req_power, in allocate_power()
490 max_allocatable_power, tz->temperature, in allocate_power()
491 control_temp - tz->temperature); in allocate_power()
513 static void get_governor_trips(struct thermal_zone_device *tz, in get_governor_trips() argument
523 for (i = 0; i < tz->num_trips; i++) { in get_governor_trips()
527 ret = __thermal_zone_get_trip(tz, i, &trip); in get_governor_trips()
529 dev_warn(&tz->device, in get_governor_trips()
566 static void allow_maximum_power(struct thermal_zone_device *tz, bool update) in allow_maximum_power() argument
569 struct power_allocator_params *params = tz->governor_data; in allow_maximum_power()
571 &tz->trips[params->trip_max_desired_temperature]; in allow_maximum_power()
574 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in allow_maximum_power()
609 static int check_power_actors(struct thermal_zone_device *tz) in check_power_actors() argument
614 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { in check_power_actors()
616 dev_warn(&tz->device, "power_allocator: %s is not a power actor\n", in check_power_actors()
635 static int power_allocator_bind(struct thermal_zone_device *tz) in power_allocator_bind() argument
641 ret = check_power_actors(tz); in power_allocator_bind()
649 if (!tz->tzp) { in power_allocator_bind()
650 tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL); in power_allocator_bind()
651 if (!tz->tzp) { in power_allocator_bind()
659 if (!tz->tzp->sustainable_power) in power_allocator_bind()
660 dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); in power_allocator_bind()
662 get_governor_trips(tz, params); in power_allocator_bind()
664 if (tz->num_trips > 0) { in power_allocator_bind()
665 ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, in power_allocator_bind()
668 estimate_pid_constants(tz, tz->tzp->sustainable_power, in power_allocator_bind()
675 tz->governor_data = params; in power_allocator_bind()
685 static void power_allocator_unbind(struct thermal_zone_device *tz) in power_allocator_unbind() argument
687 struct power_allocator_params *params = tz->governor_data; in power_allocator_unbind()
689 dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); in power_allocator_unbind()
692 kfree(tz->tzp); in power_allocator_unbind()
693 tz->tzp = NULL; in power_allocator_unbind()
696 kfree(tz->governor_data); in power_allocator_unbind()
697 tz->governor_data = NULL; in power_allocator_unbind()
700 static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id) in power_allocator_throttle() argument
702 struct power_allocator_params *params = tz->governor_data; in power_allocator_throttle()
707 lockdep_assert_held(&tz->lock); in power_allocator_throttle()
716 ret = __thermal_zone_get_trip(tz, params->trip_switch_on, &trip); in power_allocator_throttle()
717 if (!ret && (tz->temperature < trip.temperature)) { in power_allocator_throttle()
718 update = tz->passive; in power_allocator_throttle()
719 tz->passive = 0; in power_allocator_throttle()
721 allow_maximum_power(tz, update); in power_allocator_throttle()
725 tz->passive = 1; in power_allocator_throttle()
727 ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &trip); in power_allocator_throttle()
729 dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d\n", in power_allocator_throttle()
734 return allocate_power(tz, trip.temperature); in power_allocator_throttle()