PM / QoS: correct the valid range of pm_qos_class

The valid start index for pm_qos_array is not 0, but
PM_QOS_CPU_DMA_LATENCY. There is a null_pm_qos at index 0 of
pm_qos_array.  However, null_pm_qos is not created as misc device so
that inclusion of 0 index for checking pm_qos_class especially for
file operations is not proper here.

[rjw: Changelog, a bit]
Signed-off-by: Sahara <keun-o.park@windriver.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM / Sleep: Print last wakeup source on failed wakeup_count write

Commit a938da06 introduced a useful little log message to tell
users/debuggers which wakeup source aborted a suspend.  However,
this message is only printed if the abort happens during the
in-kernel suspend path (after writing /sys/power/state).

The full specification of the /sys/power/wakeup_count facility
allows user-space power managers to double-check if wakeups have
already happened before it actually tries to suspend (e.g. while it
was running user-space pre-suspend hooks), by writing the last known
wakeup_count value to /sys/power/wakeup_count.  This patch changes
the sysfs handler for that node to also print said log message if
that write fails, so that we can figure out the offending wakeup
source for both kinds of suspend aborts.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM / Sleep: Include additional information in pm_print_times()

Change __device_suspend() path to include driver name and the ops
that get run for a device. This additional information helps to
associate the driver and the type of pm_ops the device uses in the
suspend path very quickly, which will aid in debugging problems in
suspend and resume paths.

Changed both start and end debug messages to include pm_ops
information and use dev_info() instead of pr_info(). Changed the end
message to include parent device information and have the same format
as the start message.

dmesg output before the change:

[  164.390032] calling  1-1+ @ 69, parent: usb1
[  164.390035] call 1-1+ returned 0 after 0 usecs

[  164.390352] calling  00:0a+ @ 2457, parent: pnp0
[  164.390357] call 00:0a+ returned 0 after 3 usecs

[  164.390361] calling  00:09+ @ 2457, parent: pnp0
[  164.496458] call 00:09+ returned 0 after 103500 usecs

[  164.496494] calling  00:05+ @ 2457, parent: pnp0
[  164.496511] call 00:05+ returned 0 after 14 usecs

dmesg output after the change:

[  545.985394] usb 1-1: Start: type pm ops @ 68, parent: usb1
[  545.987650] usb 1-1: End  : type pm ops @ 68, parent: usb1 time(2184 usecs) err(0)

[  545.982544] system 00:0a: Start: legacy bus pm ops @ 2391, parent: pnp0
[  545.982554] system 00:0a: End  : legacy bus pm ops @ 2391, parent: pnp0 time(4 usecs) err(0)

[  545.982569] tpm_tis 00:09: Start: legacy bus pm ops @ 2391, parent: pnp0
[  546.087017] tpm_tis 00:09: End  : legacy bus pm ops @ 2391, parent: pnp0 time(101936 usecs) err(0)

[  546.087069] rtc_cmos 00:05: Start: legacy bus pm ops @ 2391, parent: pnp0
[  546.087084] rtc_cmos 00:05: End  : legacy bus pm ops @ 2391, parent: pnp0 time(11 usecs) err(0)

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pm-assorted-next' into bleeding-edge

* pm-assorted-next:
  PM / Sleep: Include additional information in pm_print_times()
  PM / Sleep: Print last wakeup source on failed wakeup_count write
  PM / QoS: correct the valid range of pm_qos_class
cpufreq: Fix governor start/stop race condition

Cpufreq governors' stop and start operations should be carried out
in sequence.  Otherwise, there will be unexpected behavior, like in
the example below.

Suppose there are 4 CPUs and policy->cpu=CPU0, CPU1/2/3 are linked
to CPU0.  The normal sequence is:

 1) Current governor is userspace.  An application tries to set the
    governor to ondemand.  It will call __cpufreq_set_policy() in
    which it will stop the userspace governor and then start the
    ondemand governor.

 2) Current governor is userspace.  The online of CPU3 runs on CPU0.
    It will call cpufreq_add_policy_cpu() in which it will first
    stop the userspace governor, and then start it again.

If the sequence of the above two cases interleaves, it becomes:

 1) Application stops userspace governor
 2)                                  Hotplug stops userspace governor

which is a problem, because the governor shouldn't be stopped twice
in a row.  What happens next is:

 3) Application starts ondemand governor
 4)                                  Hotplug starts a governor

In step 4, the hotplug is supposed to start the userspace governor,
but now the governor has been changed by the application to ondemand,
so the ondemand governor is started once again, which is incorrect.

The solution is to prevent policy governors from being stopped
multiple times in a row.  A governor should only be stopped once for
one policy.  After it has been stopped, no more governor stop
operations should be executed.

Also add a mutex to serialize governor operations.

[rjw: Changelog.  And you owe me a beverage of my choice.]
Signed-off-by: Xiaoguang Chen <chenxg@marvell.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Fix minor formatting issues

There were a few noticeable formatting issues in core cpufreq code.
This cleans them up to make code look better.  The changes include:
 - Whitespace cleanup.
 - Rearrangements of code.
 - Multiline comments fixes.
 - Formatting changes to fit 80 columns.

Copyright information in cpufreq.c is also updated to include my name
for 2013.

[rjw: Changelog]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: make __cpufreq_notify_transition() static

__cpufreq_notify_transition() is used only in cpufreq.c,
make it static.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pm-cpufreq-next' into bleeding-edge

* pm-cpufreq-next:
  cpufreq: make __cpufreq_notify_transition() static
  cpufreq: Fix minor formatting issues
  cpufreq: Fix governor start/stop race condition