usb: core: Try generic PHY_MODE_USB_HOST if usb_phy_roothub_set_mode fails
[linux-2.6-block.git] / drivers / cpuidle / poll_state.c
CommitLineData
34c2f65b
RW
1/*
2 * poll_state.c - Polling idle state
3 *
4 * This file is released under the GPLv2.
5 */
6
7#include <linux/cpuidle.h>
8#include <linux/sched.h>
a37b969a 9#include <linux/sched/clock.h>
34c2f65b
RW
10#include <linux/sched/idle.h>
11
4dc2375c 12#define POLL_IDLE_RELAX_COUNT 200
a37b969a 13
34c2f65b
RW
14static int __cpuidle poll_idle(struct cpuidle_device *dev,
15 struct cpuidle_driver *drv, int index)
16{
a37b969a
RW
17 u64 time_start = local_clock();
18
5f26bdce
RW
19 dev->poll_time_limit = false;
20
34c2f65b
RW
21 local_irq_enable();
22 if (!current_set_polling_and_test()) {
4dc2375c 23 unsigned int loop_count = 0;
1617971c 24 u64 limit = TICK_NSEC;
800fb34a
RW
25 int i;
26
27 for (i = 1; i < drv->state_count; i++) {
28 if (drv->states[i].disabled || dev->states_usage[i].disable)
29 continue;
30
31 limit = (u64)drv->states[i].target_residency * NSEC_PER_USEC;
32 break;
33 }
4dc2375c 34
a37b969a 35 while (!need_resched()) {
34c2f65b 36 cpu_relax();
4dc2375c
RW
37 if (loop_count++ < POLL_IDLE_RELAX_COUNT)
38 continue;
a37b969a 39
4dc2375c 40 loop_count = 0;
01bad1c6 41 if (local_clock() - time_start > limit) {
5f26bdce 42 dev->poll_time_limit = true;
a37b969a 43 break;
5f26bdce 44 }
a37b969a 45 }
34c2f65b
RW
46 }
47 current_clr_polling();
48
49 return index;
50}
51
1b39e3f8 52void cpuidle_poll_state_init(struct cpuidle_driver *drv)
34c2f65b
RW
53{
54 struct cpuidle_state *state = &drv->states[0];
55
56 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
57 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
58 state->exit_latency = 0;
59 state->target_residency = 0;
60 state->power_usage = -1;
61 state->enter = poll_idle;
62 state->disabled = false;
63 state->flags = CPUIDLE_FLAG_POLLING;
64}
1b39e3f8 65EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);