Lines Matching refs:tz

77  * @tz: thermal zone we are operating in
86 static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
90 struct power_allocator_params *params = tz->governor_data;
92 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
110 * @tz: thermal zone for which to estimate the constants
127 static void estimate_pid_constants(struct thermal_zone_device *tz,
135 ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp);
151 if (!tz->tzp->k_po || force)
152 tz->tzp->k_po = int_to_frac(sustainable_power) /
155 if (!tz->tzp->k_pu || force)
156 tz->tzp->k_pu = int_to_frac(2 * sustainable_power) /
159 if (!tz->tzp->k_i || force)
160 tz->tzp->k_i = int_to_frac(10) / 1000;
169 * @tz: thermal zone we are operating in
185 static u32 pid_controller(struct thermal_zone_device *tz,
192 struct power_allocator_params *params = tz->governor_data;
196 if (tz->tzp->sustainable_power) {
197 sustainable_power = tz->tzp->sustainable_power;
199 sustainable_power = estimate_sustainable_power(tz);
200 estimate_pid_constants(tz, sustainable_power,
205 err = control_temp - tz->temperature;
209 p = mul_frac(err < 0 ? tz->tzp->k_po : tz->tzp->k_pu, err);
217 i = mul_frac(tz->tzp->k_i, params->err_integral);
219 if (err < int_to_frac(tz->tzp->integral_cutoff)) {
220 s64 i_next = i + mul_frac(tz->tzp->k_i, err);
235 d = mul_frac(tz->tzp->k_d, err - params->prev_err);
236 d = div_frac(d, tz->passive_delay);
246 trace_thermal_power_allocator_pid(tz, frac_to_int(err),
325 static int allocate_power(struct thermal_zone_device *tz,
329 struct power_allocator_params *params = tz->governor_data;
337 mutex_lock(&tz->lock);
341 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
381 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
411 power_range = pid_controller(tz, control_temp, max_allocatable_power);
419 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
433 trace_thermal_power_allocator(tz, req_power, total_req_power,
436 max_allocatable_power, tz->temperature,
437 control_temp - tz->temperature);
441 mutex_unlock(&tz->lock);
448 * @tz: thermal zone to operate on
461 static void get_governor_trips(struct thermal_zone_device *tz,
471 for (i = 0; i < tz->trips; i++) {
475 ret = tz->ops->get_trip_type(tz, i, &type);
477 dev_warn(&tz->device,
514 static void allow_maximum_power(struct thermal_zone_device *tz)
517 struct power_allocator_params *params = tz->governor_data;
519 mutex_lock(&tz->lock);
520 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
531 mutex_unlock(&tz->lock);
536 * @tz: thermal zone to bind it to
543 static int power_allocator_bind(struct thermal_zone_device *tz)
553 if (!tz->tzp) {
554 tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL);
555 if (!tz->tzp) {
563 if (!tz->tzp->sustainable_power)
564 dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n");
566 get_governor_trips(tz, params);
568 if (tz->trips > 0) {
569 ret = tz->ops->get_trip_temp(tz,
573 estimate_pid_constants(tz, tz->tzp->sustainable_power,
580 tz->governor_data = params;
590 static void power_allocator_unbind(struct thermal_zone_device *tz)
592 struct power_allocator_params *params = tz->governor_data;
594 dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id);
597 kfree(tz->tzp);
598 tz->tzp = NULL;
601 kfree(tz->governor_data);
602 tz->governor_data = NULL;
605 static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
609 struct power_allocator_params *params = tz->governor_data;
618 ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
620 if (!ret && (tz->temperature < switch_on_temp)) {
621 tz->passive = 0;
623 allow_maximum_power(tz);
627 tz->passive = 1;
629 ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature,
632 dev_warn(&tz->device,
638 return allocate_power(tz, control_temp);