msm: clock: Add a new API to print registers for debugging

clk_debug_print_hw() will format a list of register names and values, and
output the result to either the kernel log or a seq_file.

Change-Id: Ic225eb0261818faaee91b42955f2a517e927a30b
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock-debug: Add support to show all the enabled clocks

Add a new debugfs file <debugfs>/clk/enabled_clocks to show all the
currently enabled clock, their rate and their dependency chain.

Example output:
cat /sys/kernel/debug/clk/enabled_clocks
Enabled clocks:
        gcc_lpass_q6_axi_clk:1:1 [0]
        gcc_mss_q6_bimc_axi_clk:1:1 [0]
        gcc_mss_cfg_ahb_clk:1:1 [0]
        gcc_boot_rom_ahb_clk:1:1 [0]
        xo_a_clk:2:2 [19200000]
        gpll0_ao:2:2 [600000000]
        kpss_ahb_clk_src:1:1 [19200000] ->
xo_a_clk:2:2 [19200000]
        bimc_msmbus_a_clk:1:1 [400000000] ->
bimc_a_clk:1:1 [400000000]
        qdss_clk:4:4 [1]
        qdss_clk:4:4 [1]
        qdss_clk:4:4 [1]
        qdss_clk:4:4 [1]
        qdss_clk:4:4 [1]
           ....
Enabled clock count: 42

Change-Id: I6eda59c7e61b77518676e3aa93895ccb792176ac
Signed-off-by: Xiaogang Cui <xiaogang@codeaurora.org>
msm: clock-8226: Fix compile errors when CONFIG_DEBUG_FS is removed

Declare variables used only if CONFIG_DEBUG_FS is defined within ifdef
statements.

CRs-fixed: 554999
Change-Id: I28d2104ebd7baba8a151fc34946463f2429709b1
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock-pll: Add round_rate for table based plls

The round rate function is used by clocks which attempt to configure
themselves dynamically based on the rate the client requests and
the rates the parent clock supports. The round_rate api is used to
determine the rates supported by the parent clock.

Change-Id: I6214492d68ba738f9ab9d642310a6fe8d3862956
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: rpm_stats: show master votes for xo/cxo sleep mode

RPM sleep stats structure has "client_votes" field. It
provides the information of masters who is preventing
the RPM from entering the associated sleep mode(xo/cxo).
Print client_votes info along with xo & vddmin stats.

CRs-fixed: 576283
Change-Id: Ia656add1b8ade7a92502058b8eb6a22516990b7a
Signed-off-by: Harry Yang <harryy@codeaurora.org>
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
msm: pm: Rearchitect power management code

The existing PM code relies on a levels table to determine the various
sleep modes including the system sleep states. Splitting them into cpu
and system/cluster specific levels is a more appropriate representation
of the existing system. As a part of this rearchitecture, the decision
to enter a low power mode is made within lpm_levels module. Unlike
earlier, the decision was split between pm-8x60 and lpm_levels.

To this effect, the lpm_levels directly registers with the cpuidle
driver instead of relying on a glue msm-cpuidle driver. The
functionality of the cpuidle driver was limited to calling into a PM
driver and without providing any additional functionality.

While at it, also remove any references to unused enums and
functionality.

Change-Id: I474cc85c6220473fdaa87e14e3b0a199e95d7eb7
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: lpm_levels: Support for RPM PC on all cores

When more than one core is online, the current model prevent entering
idle power collapse on all cores and the deepest sleep mode that a
cpu could enter is standalone power collapse. To achieve better power
savings when several cores are online all the time, it is important for
multiple cores to enter a deeper system sleep state by configuring L2
and RPM.

Each core entering the deepest sleep mode increments a counter. The
last core to enter the deepest sleep mode will acquire a lock and will
be responsible for configuring the system low power mode.  cpus. The
last core going down will configure the system wide resources with the
lock held. If a core were to wakeup during this time, it would have to
wait for the lock to be released before it can continue to resume. The
last core releases the lock after configuring the system resources at
which point, the core that resumed from power collapse would reset the
system resources before continuing to run to ensure that the shared
resources are programmed for a safe state.

With this change the idle PC becomes more of a soft state where each
core identifies that its safe to enter a system sleep state. The
decision to enter a system sleep mode is based on the next wakeup event
across all cores. With not all cores encoutering latency associated with
system sleep modes, the residency of idle PC mode will be lower than
what it has been previously acheived. However, the residency of the
system sleep states should be unaffected.

Each core as its power collapsed disables the HFPLL and switches to
GFPLL in the event of a power collapse. During this time, each cores
removes its vote to keep L2 enabled. To ensure that there are enough
votes for keep L2 on, set the number of L2 votes to number of online
cpus in cpufreq.c

Change-Id: If6a8e181bdb9c7bae8066fb804de13caa48bad3b
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm: Set affinity of PM irqs to next scheduled CPU

Modify the affinity of the interrupts associated with PM driver to the cpu
that will wakeup for the next expiring timer.

Change-Id: I6a1b25538a6d12bada3345a17b3ed4ff181ac089
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm: Disable cpu clk during retention

The CPU clock source MUXes cannot switch while a CPU is in
retention, but callers of acpuclock APIs may not known that
the CPU is in retention.

Fix issue by disabling the cpu clk before entering retention and
re-enable them on exit. This would temporarily switch the CPU to 300Mhz
and clk api would buffer any clock requests until the clk is enabled
when the core comes out of retention.

CRs-fixed: 535967
Change-Id: I103e41fc8ef78cd412b7860bf525ea9cd99ff283
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
msm: pm-stats: Move to seq_file and friends

In future kernels create_proc_entry() is going to be removed.
Let's modernize this code and use regular file operations and
seq_printf() to avoid experiencing compilation problems in future
kernels.

Change-Id: Ibeca64a8346d33e1b66b089990c17f1b1dbaf5db
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
msm: pm: add new stat variable for reporting suspend stats

Incorrectly reporting suspend stats because of moving timekeeping
logic to prepare/resume callbacks in suspend. Declared a new
global system_suspend stat variable for reporting suspend
stats and removed the suspend stats for each core.

CRs-fixed: 584850
Change-Id: Idead3cdb7b40ccca3fd91371a10378f4b5f72d95
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
msm: rpm-regulator-smd: limit current to RPM defined maximum

Modify the rpm_vreg_get_optimum_mode() function so that it
restricts the maximum current that can be sent for the 'ma' KVP
to the limit defined by the RPM.

Change-Id: I744e656c75a5e78a81df9c283a8f14a977c4c6ee
Signed-off-by: David Collins <collinsd@codeaurora.org>
msm: rpm-regulator-smd: remove incorrect rpm_regulator_get() unlock calls

The rpm_regulator_get() function calls rpm_vreg_unlock() in
failure paths after two kzalloc() calls.  However, there is no
corresponding rpm_vreg_lock() call before these calls.  Also, the
code being executed does not require mutual exclusion.  Thus,
remove the rpm_vreg_unlock() calls in order to avoid possible
locking problems if kzalloc() fails.

Change-Id: I0a0f2ffde5a6c54600a823e3ed12c3c47c3bac6a
Signed-off-by: David Collins <collinsd@codeaurora.org>
lpm_levels: Do not consider latency during suspend

Currently, cpu mode selection does not consider pm_qos latency
values during suspend, allows cores to be power collapsed. But
the system mode selection considers pm_qos latency which causes
to not choose any deep sleep mode.

Change-Id: Ia9db8692e6eb081b29bb4d75a7c0816fec5695bc
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
msm: lpm_levels: remove debug print

remove a pr_info that was added for debug purpose. This is
causing excessive logging issues.

CRs-fixed: 589307
Change-Id: I1f7bcb5282b51734cb7bf30ff933d65714445cba
Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>
msm: msm-pm: Remove timeout waiting for cpu to power collapse

The delays in the CPU_DYING notication path could result in the core
initiating the hotplug to send out CPU_DEAD notifications after
msm_pm_wait_cpu_shutdown() times out. This could result in a unknown
resets when regulator/clocks are disabled in the CPU_DEAD path. To
prevent unknown resets, wait infinitely to enter power collapse but
throw a warning after the 1ms mark.

The platform_cpu_kill() path is also executed in the reboot path when a
core tries to stop secondary cores. In these cases, platform_cpu_kill
shouldn't wait infinitely for the secondary cores to power collapse. To
circumvent this scenario, track dying cpus as a part of the hotplug
notification and skip waiting for the core to power collpase during
reboot path.

Change-Id: I6a7fbeeea0d50b5f1fc76a02a39f161b40a67b6c
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: rpm-smd: use data type correctly for a variable

Change variable data type from signed int to unsigned int.

CRs-fixed: 556055
Change-Id: I6bb363b31d4fab26d84f89e775101c6051fe9e10
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>