• Home
  • Raw
  • Download

Lines Matching +full:switching +full:- +full:freq

5  *            (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
10 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
11 * Fix handling for CPU hotplug -- affected CPUs
38 return cpumask_empty(policy->cpus); in policy_is_inactive()
60 * The "cpufreq driver" - the arch- or hardware-dependent low
73 return cpufreq_driver->target_index || cpufreq_driver->target; in has_target()
107 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); in have_governor_per_policy()
114 return &policy->kobj; in get_governor_parent_kobj()
135 idle_time = cur_wall_time - busy_time; in get_cpu_idle_time_jiffy()
146 if (idle_time == -1ULL) in get_cpu_idle_time()
164 * - validate & show freq table passed
165 * - set policies transition latency
166 * - policy->cpus with all possible CPUs
172 policy->freq_table = table; in cpufreq_generic_init()
173 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
179 cpumask_setall(policy->cpus); in cpufreq_generic_init()
189 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
197 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
203 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
235 kobject_get(&policy->kobj); in cpufreq_cpu_get()
254 kobject_put(&policy->kobj); in cpufreq_cpu_put()
263 * adjust_jiffies - adjust the system "loops_per_jiffy"
268 * per-CPU loops_per_jiffy value wherever possible.
276 if (ci->flags & CPUFREQ_CONST_LOOPS) in adjust_jiffies()
281 l_p_j_ref_freq = ci->old; in adjust_jiffies()
282 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", in adjust_jiffies()
285 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) { in adjust_jiffies()
287 ci->new); in adjust_jiffies()
289 loops_per_jiffy, ci->new); in adjust_jiffies()
295 * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
296 * @policy: cpufreq policy to enable fast frequency switching for.
313 freqs->flags = cpufreq_driver->flags; in cpufreq_notify_transition()
315 state, freqs->new); in cpufreq_notify_transition()
324 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { in cpufreq_notify_transition()
325 if (policy->cur && (policy->cur != freqs->old)) { in cpufreq_notify_transition()
327 freqs->old, policy->cur); in cpufreq_notify_transition()
328 freqs->old = policy->cur; in cpufreq_notify_transition()
332 for_each_cpu(freqs->cpu, policy->cpus) { in cpufreq_notify_transition()
342 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, in cpufreq_notify_transition()
343 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
345 for_each_cpu(freqs->cpu, policy->cpus) { in cpufreq_notify_transition()
346 trace_cpu_frequency(freqs->new, freqs->cpu); in cpufreq_notify_transition()
351 cpufreq_stats_record_transition(policy, freqs->new); in cpufreq_notify_transition()
352 policy->cur = freqs->new; in cpufreq_notify_transition()
364 swap(freqs->old, freqs->new); in cpufreq_notify_post_transition()
374 * Catch double invocations of _begin() which lead to self-deadlock. in cpufreq_freq_transition_begin()
378 * where these checks can emit false-positive warnings in these in cpufreq_freq_transition_begin()
381 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION) in cpufreq_freq_transition_begin()
382 && current == policy->transition_task); in cpufreq_freq_transition_begin()
385 wait_event(policy->transition_wait, !policy->transition_ongoing); in cpufreq_freq_transition_begin()
387 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_begin()
389 if (unlikely(policy->transition_ongoing)) { in cpufreq_freq_transition_begin()
390 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
394 policy->transition_ongoing = true; in cpufreq_freq_transition_begin()
395 policy->transition_task = current; in cpufreq_freq_transition_begin()
397 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
406 if (unlikely(WARN_ON(!policy->transition_ongoing))) in cpufreq_freq_transition_end()
411 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
412 policy->transition_task = NULL; in cpufreq_freq_transition_end()
414 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
419 * Fast frequency switching status count. Positive means "enabled", negative
433 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) in cpufreq_list_transition_notifiers()
434 pr_info("%pF\n", nb->notifier_call); in cpufreq_list_transition_notifiers()
440 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
441 * @policy: cpufreq policy to enable fast frequency switching for.
443 * Try to enable fast frequency switching for @policy.
446 * at this point, as fast frequency switching is quite fundamentally at odds
452 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
454 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
460 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
462 pr_warn("CPU%u: Fast frequency switching not enabled\n", in cpufreq_enable_fast_switch()
463 policy->cpu); in cpufreq_enable_fast_switch()
471 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
472 * @policy: cpufreq policy to disable fast frequency switching for.
477 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
478 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
480 cpufreq_fast_switch_count--; in cpufreq_disable_fast_switch()
487 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
493 * Return: Lowest driver-supported frequency greater than or equal to the
499 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_resolve_freq()
500 policy->cached_target_freq = target_freq; in cpufreq_driver_resolve_freq()
502 if (cpufreq_driver->target_index) { in cpufreq_driver_resolve_freq()
507 policy->cached_resolved_idx = idx; in cpufreq_driver_resolve_freq()
508 return policy->freq_table[idx].frequency; in cpufreq_driver_resolve_freq()
511 if (cpufreq_driver->resolve_freq) in cpufreq_driver_resolve_freq()
512 return cpufreq_driver->resolve_freq(policy, target_freq); in cpufreq_driver_resolve_freq()
522 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
523 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
525 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
550 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
560 return -EINVAL; in store_boost()
565 return -EINVAL; in store_boost()
580 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
587 * cpufreq_parse_governor - parse a governor string
592 if (cpufreq_driver->setpolicy) { in cpufreq_parse_governor()
594 policy->policy = CPUFREQ_POLICY_PERFORMANCE; in cpufreq_parse_governor()
599 policy->policy = CPUFREQ_POLICY_POWERSAVE; in cpufreq_parse_governor()
615 return -EINVAL; in cpufreq_parse_governor()
621 if (t && !try_module_get(t->owner)) in cpufreq_parse_governor()
627 policy->governor = t; in cpufreq_parse_governor()
632 return -EINVAL; in cpufreq_parse_governor()
636 * cpufreq_per_cpu_attr_read() / show_##file_name() -
639 * Write out information from cpufreq_driver->policy[cpu]; object must be
647 return sprintf(buf, "%u\n", policy->object); \
664 unsigned int freq; in show_scaling_cur_freq() local
666 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
667 if (freq) in show_scaling_cur_freq()
668 ret = sprintf(buf, "%u\n", freq); in show_scaling_cur_freq()
669 else if (cpufreq_driver && cpufreq_driver->setpolicy && in show_scaling_cur_freq()
670 cpufreq_driver->get) in show_scaling_cur_freq()
671 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
673 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
681 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
691 new_policy.min = policy->user_policy.min; \
692 new_policy.max = policy->user_policy.max; \
696 return -EINVAL; \
701 policy->user_policy.object = temp; \
710 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
724 * show_scaling_governor - show the current policy for the specified CPU
728 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
730 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
732 else if (policy->governor) in show_scaling_governor()
734 policy->governor->name); in show_scaling_governor()
735 return -EINVAL; in show_scaling_governor()
739 * store_scaling_governor - store policy for the specified CPU
752 return -EINVAL; in store_scaling_governor()
755 return -EINVAL; in store_scaling_governor()
760 module_put(new_policy.governor->owner); in store_scaling_governor()
766 * show_scaling_driver - show the cpufreq driver currently loaded
770 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
774 * show_scaling_available_governors - show the available CPUfreq governors
789 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
791 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); in show_scaling_available_governors()
805 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); in cpufreq_show_cpus()
806 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); in cpufreq_show_cpus()
807 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
816 * show_related_cpus - show the CPUs affected by each transition even if
821 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
825 * show_affected_cpus - show the CPUs affected by each transition
829 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
835 unsigned int freq = 0; in store_scaling_setspeed() local
838 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
839 return -EINVAL; in store_scaling_setspeed()
841 ret = sscanf(buf, "%u", &freq); in store_scaling_setspeed()
843 return -EINVAL; in store_scaling_setspeed()
845 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
852 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
855 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
859 * show_bios_limit - show the current cpufreq HW/BIOS limitation
865 if (cpufreq_driver->bios_limit) { in show_bios_limit()
866 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
870 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
912 if (!fattr->show) in show()
913 return -EIO; in show()
915 down_read(&policy->rwsem); in show()
916 ret = fattr->show(policy, buf); in show()
917 up_read(&policy->rwsem); in show()
927 ssize_t ret = -EINVAL; in store()
929 if (!fattr->store) in store()
930 return -EIO; in store()
937 return -EBUSY; in store()
939 if (cpu_online(policy->cpu)) { in store()
940 down_write(&policy->rwsem); in store()
941 ret = fattr->store(policy, buf, count); in store()
942 up_write(&policy->rwsem); in store()
954 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
975 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
979 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
987 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
996 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
998 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1003 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1004 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1009 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1013 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1014 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1035 gov = find_governor(policy->last_governor); in cpufreq_init_policy()
1038 policy->governor->name, policy->cpu); in cpufreq_init_policy()
1042 return -ENODATA; in cpufreq_init_policy()
1048 if (cpufreq_driver->setpolicy) { in cpufreq_init_policy()
1049 if (policy->last_policy) in cpufreq_init_policy()
1050 new_policy.policy = policy->last_policy; in cpufreq_init_policy()
1052 cpufreq_parse_governor(gov->name, &new_policy); in cpufreq_init_policy()
1063 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1066 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1070 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1077 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1085 unsigned int cpu = policy->cpu; in handle_update()
1099 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1102 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1105 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1108 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1111 pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1112 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1116 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1117 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1118 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1119 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1120 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1121 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1123 policy->cpu = cpu; in cpufreq_policy_alloc()
1127 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1129 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1131 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1143 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1145 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1146 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1147 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1167 list_del(&policy->policy_list); in cpufreq_policy_free()
1169 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1174 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1175 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1176 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1193 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1199 down_write(&policy->rwsem); in cpufreq_online()
1200 policy->cpu = cpu; in cpufreq_online()
1201 policy->governor = NULL; in cpufreq_online()
1202 up_write(&policy->rwsem); in cpufreq_online()
1207 return -ENOMEM; in cpufreq_online()
1210 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1213 * to accept all calls to ->verify and ->setpolicy for this CPU in cpufreq_online()
1215 ret = cpufreq_driver->init(policy); in cpufreq_online()
1225 down_write(&policy->rwsem); in cpufreq_online()
1228 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1229 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1236 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1239 policy->user_policy.min = policy->min; in cpufreq_online()
1240 policy->user_policy.max = policy->max; in cpufreq_online()
1242 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1247 policy->min = policy->user_policy.min; in cpufreq_online()
1248 policy->max = policy->user_policy.max; in cpufreq_online()
1251 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { in cpufreq_online()
1252 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1253 if (!policy->cur) { in cpufreq_online()
1254 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1264 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1265 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1266 * isn't found in freq-table. in cpufreq_online()
1269 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1270 * otherwise we will end up setting freq to lowest of the table as 'cur' in cpufreq_online()
1273 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1274 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1275 * equal to target-freq. in cpufreq_online()
1277 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1280 ret = cpufreq_frequency_table_get_index(policy, policy->cur); in cpufreq_online()
1281 if (ret == -EINVAL) { in cpufreq_online()
1283 pr_warn("%s: CPU%d: Running at unlisted freq: %u KHz\n", in cpufreq_online()
1284 __func__, policy->cpu, policy->cur); in cpufreq_online()
1285 ret = __cpufreq_driver_target(policy, policy->cur - 1, in cpufreq_online()
1295 __func__, policy->cpu, policy->cur); in cpufreq_online()
1307 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1320 up_write(&policy->rwsem); in cpufreq_online()
1322 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1325 if (cpufreq_driver->ready) in cpufreq_online()
1326 cpufreq_driver->ready(policy); in cpufreq_online()
1333 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1336 up_write(&policy->rwsem); in cpufreq_online()
1339 if (cpufreq_driver->exit) in cpufreq_online()
1340 cpufreq_driver->exit(policy); in cpufreq_online()
1348 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1355 unsigned cpu = dev->id; in cpufreq_add_dev()
1387 down_write(&policy->rwsem); in cpufreq_offline()
1391 cpumask_clear_cpu(cpu, policy->cpus); in cpufreq_offline()
1395 strncpy(policy->last_governor, policy->governor->name, in cpufreq_offline()
1398 policy->last_policy = policy->policy; in cpufreq_offline()
1399 } else if (cpu == policy->cpu) { in cpufreq_offline()
1401 policy->cpu = cpumask_any(policy->cpus); in cpufreq_offline()
1415 if (cpufreq_driver->stop_cpu) in cpufreq_offline()
1416 cpufreq_driver->stop_cpu(policy); in cpufreq_offline()
1422 * Perform the ->exit() even during light-weight tear-down, in cpufreq_offline()
1424 * subsequent light-weight ->init() to succeed. in cpufreq_offline()
1426 if (cpufreq_driver->exit) { in cpufreq_offline()
1427 cpufreq_driver->exit(policy); in cpufreq_offline()
1428 policy->freq_table = NULL; in cpufreq_offline()
1432 up_write(&policy->rwsem); in cpufreq_offline()
1437 * cpufreq_remove_dev - remove a CPU device
1443 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1452 cpumask_clear_cpu(cpu, policy->real_cpus); in cpufreq_remove_dev()
1455 if (cpumask_empty(policy->real_cpus)) in cpufreq_remove_dev()
1460 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1474 policy->cur, new_freq); in cpufreq_out_of_sync()
1476 freqs.old = policy->cur; in cpufreq_out_of_sync()
1484 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1487 * This is the last known freq, without actually getting it from the driver.
1498 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1499 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1508 ret_freq = policy->cur; in cpufreq_quick_get()
1517 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1528 ret_freq = policy->max; in cpufreq_quick_get_max()
1540 if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get) in __cpufreq_get()
1543 ret_freq = cpufreq_driver->get(policy->cpu); in __cpufreq_get()
1546 * If fast frequency switching is used with the given policy, the check in __cpufreq_get()
1547 * against policy->cur is pointless, so skip it in that case too. in __cpufreq_get()
1549 if (policy->fast_switch_enabled) in __cpufreq_get()
1552 if (ret_freq && policy->cur && in __cpufreq_get()
1553 !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { in __cpufreq_get()
1556 if (unlikely(ret_freq != policy->cur)) { in __cpufreq_get()
1558 schedule_work(&policy->update); in __cpufreq_get()
1566 * cpufreq_get - get the current CPU frequency (in kHz)
1577 down_read(&policy->rwsem); in cpufreq_get()
1579 up_read(&policy->rwsem); in cpufreq_get()
1592 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_update_current_freq()
1596 if (!policy->cur) { in cpufreq_update_current_freq()
1597 pr_debug("cpufreq: Driver did not initialize current freq\n"); in cpufreq_update_current_freq()
1598 policy->cur = new_freq; in cpufreq_update_current_freq()
1599 } else if (policy->cur != new_freq && has_target()) { in cpufreq_update_current_freq()
1621 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1626 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1627 policy->suspend_freq); in cpufreq_generic_suspend()
1629 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1632 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1633 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1640 * cpufreq_suspend() - Suspend CPUFreq governors
1654 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1661 down_write(&policy->rwsem); in cpufreq_suspend()
1663 up_write(&policy->rwsem); in cpufreq_suspend()
1666 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1676 * cpufreq_resume() - Resume CPUFreq governors
1694 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
1700 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1704 down_write(&policy->rwsem); in cpufreq_resume()
1706 up_write(&policy->rwsem); in cpufreq_resume()
1716 * cpufreq_get_current_driver - return current driver's name
1724 return cpufreq_driver->name; in cpufreq_get_current_driver()
1731 * cpufreq_get_driver_data - return current driver data
1739 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
1750 * cpufreq_register_notifier - register a driver with cpufreq
1767 return -EINVAL; in cpufreq_register_notifier()
1775 return -EBUSY; in cpufreq_register_notifier()
1780 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
1789 ret = -EINVAL; in cpufreq_register_notifier()
1797 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1811 return -EINVAL; in cpufreq_unregister_notifier()
1829 ret = -EINVAL; in cpufreq_unregister_notifier()
1842 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
1848 * The driver's ->fast_switch() callback invoked by this function must be
1849 * suitable for being called from within RCU-sched read-side critical sections
1853 * This function must not be called if policy->fast_switch_enabled is unset.
1857 * parallel with either ->target() or ->target_index() for the same policy.
1861 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
1867 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
1869 return cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
1873 /* Must set freqs->new to intermediate frequency */
1879 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
1881 /* We don't need to switch to intermediate freq */ in __target_intermediate()
1882 if (!freqs->new) in __target_intermediate()
1885 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n", in __target_intermediate()
1886 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
1889 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
1901 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
1903 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
1904 int retval = -EINVAL; in __target_index()
1907 if (newfreq == policy->cur) in __target_index()
1910 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
1912 /* Handle switching to intermediate frequency */ in __target_index()
1913 if (cpufreq_driver->get_intermediate) { in __target_index()
1919 /* Set old freq to intermediate */ in __target_index()
1925 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", in __target_index()
1926 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
1931 retval = cpufreq_driver->target_index(policy, index); in __target_index()
1940 * Failed after setting to intermediate freq? Driver should have in __target_index()
1943 * case we haven't switched to intermediate freq at all. in __target_index()
1947 freqs.new = policy->restore_freq; in __target_index()
1964 return -ENODEV; in __cpufreq_driver_target()
1967 target_freq = clamp_val(target_freq, policy->min, policy->max); in __cpufreq_driver_target()
1970 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
1975 * exactly same freq is called again and so we can save on few function in __cpufreq_driver_target()
1978 if (target_freq == policy->cur) in __cpufreq_driver_target()
1982 policy->restore_freq = policy->cur; in __cpufreq_driver_target()
1984 if (cpufreq_driver->target) in __cpufreq_driver_target()
1985 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
1987 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
1988 return -EINVAL; in __cpufreq_driver_target()
2000 int ret = -EINVAL; in cpufreq_driver_target()
2002 down_write(&policy->rwsem); in cpufreq_driver_target()
2006 up_write(&policy->rwsem); in cpufreq_driver_target()
2028 if (!policy->governor) in cpufreq_init_governor()
2029 return -EINVAL; in cpufreq_init_governor()
2031 /* Platform doesn't want dynamic frequency switching ? */ in cpufreq_init_governor()
2032 if (policy->governor->dynamic_switching && in cpufreq_init_governor()
2033 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2037 pr_warn("Can't use %s governor as dynamic switching is disallowed. Fallback to %s governor\n", in cpufreq_init_governor()
2038 policy->governor->name, gov->name); in cpufreq_init_governor()
2039 policy->governor = gov; in cpufreq_init_governor()
2041 return -EINVAL; in cpufreq_init_governor()
2045 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2046 return -EINVAL; in cpufreq_init_governor()
2048 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2050 if (policy->governor->init) { in cpufreq_init_governor()
2051 ret = policy->governor->init(policy); in cpufreq_init_governor()
2053 module_put(policy->governor->owner); in cpufreq_init_governor()
2063 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2066 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2068 if (policy->governor->exit) in cpufreq_exit_governor()
2069 policy->governor->exit(policy); in cpufreq_exit_governor()
2071 module_put(policy->governor->owner); in cpufreq_exit_governor()
2081 if (!policy->governor) in cpufreq_start_governor()
2082 return -EINVAL; in cpufreq_start_governor()
2084 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2086 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) in cpufreq_start_governor()
2089 if (policy->governor->start) { in cpufreq_start_governor()
2090 ret = policy->governor->start(policy); in cpufreq_start_governor()
2095 if (policy->governor->limits) in cpufreq_start_governor()
2096 policy->governor->limits(policy); in cpufreq_start_governor()
2103 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2106 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2108 if (policy->governor->stop) in cpufreq_stop_governor()
2109 policy->governor->stop(policy); in cpufreq_stop_governor()
2114 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2117 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2119 if (policy->governor->limits) in cpufreq_governor_limits()
2120 policy->governor->limits(policy); in cpufreq_governor_limits()
2128 return -EINVAL; in cpufreq_register_governor()
2131 return -ENODEV; in cpufreq_register_governor()
2135 err = -EBUSY; in cpufreq_register_governor()
2136 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2138 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2160 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2161 policy->governor = NULL; in cpufreq_unregister_governor()
2162 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2168 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2179 * cpufreq_get_policy - get the current cpufreq_policy
2189 return -EINVAL; in cpufreq_get_policy()
2193 return -EINVAL; in cpufreq_get_policy()
2212 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2213 new_policy->cpu, new_policy->min, new_policy->max); in cpufreq_set_policy()
2215 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2218 * This check works well when we store new min/max freq attributes, in cpufreq_set_policy()
2221 if (new_policy->min > new_policy->max) in cpufreq_set_policy()
2222 return -EINVAL; in cpufreq_set_policy()
2225 ret = cpufreq_driver->verify(new_policy); in cpufreq_set_policy()
2229 /* adjust if necessary - all reasons */ in cpufreq_set_policy()
2237 ret = cpufreq_driver->verify(new_policy); in cpufreq_set_policy()
2245 policy->min = new_policy->min; in cpufreq_set_policy()
2246 policy->max = new_policy->max; in cpufreq_set_policy()
2249 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2251 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2252 policy->min, policy->max); in cpufreq_set_policy()
2254 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2255 policy->policy = new_policy->policy; in cpufreq_set_policy()
2257 return cpufreq_driver->setpolicy(new_policy); in cpufreq_set_policy()
2260 if (new_policy->governor == policy->governor) { in cpufreq_set_policy()
2269 old_gov = policy->governor; in cpufreq_set_policy()
2277 policy->governor = new_policy->governor; in cpufreq_set_policy()
2288 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2289 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2291 policy->governor = old_gov; in cpufreq_set_policy()
2293 policy->governor = NULL; in cpufreq_set_policy()
2302 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
2303 * @cpu: CPU which shall be re-evaluated
2316 down_write(&policy->rwsem); in cpufreq_update_policy()
2323 new_policy.min = policy->user_policy.min; in cpufreq_update_policy()
2324 new_policy.max = policy->user_policy.max; in cpufreq_update_policy()
2327 * BIOS might change freq behind our back in cpufreq_update_policy()
2328 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2330 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { in cpufreq_update_policy()
2342 up_write(&policy->rwsem); in cpufreq_update_policy()
2354 int ret = -EINVAL; in cpufreq_boost_set_sw()
2357 if (!policy->freq_table) in cpufreq_boost_set_sw()
2361 policy->freq_table); in cpufreq_boost_set_sw()
2368 down_write(&policy->rwsem); in cpufreq_boost_set_sw()
2369 policy->user_policy.max = policy->max; in cpufreq_boost_set_sw()
2371 up_write(&policy->rwsem); in cpufreq_boost_set_sw()
2382 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2386 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2389 ret = cpufreq_driver->set_boost(state); in cpufreq_boost_trigger_state()
2392 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2404 return likely(cpufreq_driver) && cpufreq_driver->set_boost; in cpufreq_boost_supported()
2428 return -EINVAL; in cpufreq_enable_boost_support()
2433 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2442 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2466 * cpufreq_register_driver - register a CPU Frequency driver
2471 * returns zero on success, -EEXIST when another driver got here first
2481 return -ENODEV; in cpufreq_register_driver()
2488 return -EPROBE_DEFER; in cpufreq_register_driver()
2490 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2491 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2492 driver_data->target) || in cpufreq_register_driver()
2493 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2494 driver_data->target)) || in cpufreq_register_driver()
2495 (!!driver_data->get_intermediate != !!driver_data->target_intermediate)) in cpufreq_register_driver()
2496 return -EINVAL; in cpufreq_register_driver()
2498 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2506 ret = -EEXIST; in cpufreq_register_driver()
2512 if (driver_data->setpolicy) in cpufreq_register_driver()
2513 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2525 if (!(cpufreq_driver->flags & CPUFREQ_STICKY) && in cpufreq_register_driver()
2527 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2528 ret = -ENODEV; in cpufreq_register_driver()
2530 driver_data->name); in cpufreq_register_driver()
2543 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2561 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2565 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2573 return -EINVAL; in cpufreq_unregister_driver()
2575 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
2600 return -ENODEV; in cpufreq_core_init()
2602 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); in cpufreq_core_init()