Lines Matching refs:tz

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