power: main: Add conditional compilation for touch nodes

Add conditional compilation for touch event sysfs nodes. Otherwise,
if CONFIG_PM_SLEEP is not defined, there could be compilation errors.

Change-Id: I1ac7f284ec35eae2cfa076ef8e71c29ddc24817c
Signed-off-by: Amar Singhal <asinghal@codeaurora.org>
msm: clock: Remove warned flag

Now that all clock consumers have moved over to using the
clk_prepare/unprepare APIs we can remove the warned flag that
used to indicate that we had already warned about improper usage
of the clock APIs. In particular, we used this flag to avoid
printing warnings for "source" clocks such as PLLs and
crystals that no consumer directly controls but that the clock
driver calls clk_enable() on during clk_set_rate().

Let's use a local variable for clk->dbg_name too because we use
it many times and it makes lines too long.

Change-Id: I3730d55e0ccc97eba60cca3f844602ae995ebda4
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
msm: clock: Expose parts of "clock.h" through <mach/clk-provider.h>

Expose the features of "clock.h" outside of mach-msm so that new clock
drivers leveraging the framework in mach-msm/clock.c can be implemented
outside of the mach-msm sub-architecture directory.

Change-Id: I3d07017388b28d4e5b6e930e7eda4f48e840714b
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
msm: clock: Make lock for vdd_class into mutex

There is no reason to hold a spinlock here anymore when the
vdd_class is only updated in non-atomic context. Move to using a
mutex instead. We couldn't do this before because voltage voting
was done in atomic context.

Change-Id: Ic0a4fa8f4255f8454d0b34d148cc5365eca8f139
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
msm: clock: Convert clock fmax and vdd class levels from arrays to pointers

Not all clocks can capture their fmax data with an array size of 4. So,
change the fmax entry from an array to a pointer and add a num_fmax field.
This allows each clock to specify fmax data of different length. Also, this
makes fixing up of fmax entries based on SoC id and version a lot easier.

Obviously, if a clock can have more than 4 fmax levels, the vdd class would
also need more than 4 levels. So, update the vdd class code in a similar
fashion.

Change-Id: Idf94c2e660269a3d208e87ff1414300469737624
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Move parent field into top level struct clk

Maintaining a parent field inside each clock type leads to pointless
repetition of code. Almost all clocks have parents, so move the parent
field to top level struct clk, have it updated whenever the parent changes
for a clock and remove the get_parent ops implementation.

Change-Id: Id897a55d496446a1047322d40d8df041dfea5840
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Improve clock handoff code.

The current clock handoff code hands off the child clock before handing off
the parent clock. That is technically incorrect since the state and rate of
a clock can't be determined without knowing the state and rate of the
source/parent clock. But this works alright for now since the handoff code
forcefully enables the necessary parent and also assumes that if a clock
has multiple parents, the rates of all those parents are fixed. As we
implement more clocks, this assumption no longer holds true.

The current handoff code also causes the prepare and enable ops to be
called for an already enabled clock. The hardware read/writes caused by
this might not be harmful in the case of most clock hardware designs, but
is not always the case. Eg: PLLs, I2C clocks, etc.

To address these issues, rewrite the clock handoff code so that the parent
clock is identified first, it's handed off and then the child clock is
handed off. Also, when an already enabled clock is handed off, just
directly update the software state of the clock and don't call the ops to
update the hardware. To make sure the parent clock's reference counts are
updated correctly, call clk_prepare_enable() on the parent clock.

This change also has the nice effect of avoiding any "clock stuck off/on"
warnings during boot that are caused by the boot code configuring the
clocks incorrectly (parent off, child on). This is because we don't
actually call the prepare/enable ops and also make sure the parent clocks
is on before calling the handoff code for the child clock.

Change-Id: I385a2afaf62a4138d53048f675822e079be2fcca
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Move regulator API calls into clock framework

All B-family clock drivers can use standard regulator APIs. Move these
calls into the shared clock.c file.

Maintain backwards compatibility with older targets by continuing to
allow usage of target specific non-standard calls.

Change-Id: I538f3118ee135a4266b82977b71c92d3dfa2e8f7
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock: Add helper functions to use when changing clock parent

Any clock op (such as set_rate and set_parent) that changes the parent of a
clock needs to transfer the prepare and enable requirements of the clock
from the old parent to the new parent. Provide a generic pair of APIs,
__clk_pre_reparent() and __clk_post_reparent(), that take care of this.

The pair of APIs require the prepare lock to be held the entire duration
between and including the calls to the two APIs. Since __clk_pre_reparent
grabs a spin lock and __clk_post_reparent releases the spin lock, only
atomic operations can be performed between calls to the two APIs.

Change-Id: I1dc3905655652b2c58841f0b4e65ea6d2ab5020e
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Refactor clk_set_rate()

The refactor makes the code more readable and maintainable. Also, it avoids
sending out a clk_set_rate() trace point when rate change does not occur
due to an invalid argument.

Change-Id: I848301a2fc5ddc4080e75daaaf53163db2588736
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Move voting for regulators to clock framework

Some clocks, and the regulators they require, may be enabled by the
bootloader. The clock driver detects these clocks, and attempts to
configure its data structures in a consistent manner. This procedure
involves voting for regulators.

Regulators may support different voltage levels. The first vote by the
clock driver will override whatever level was set by the bootloaders to
account for all the clocks that are on. Therefore, temporarily vote for
the highest supported voltage level until all clocks have voted for their
required voltage level. Then remove the temporary high vote.

Change-Id: Ibdb97eba374ec139768ad0b23cb1163dec9aa3aa
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock: Allow dynamic allocation for vdd_class parameters

Once clocks move to device tree, parameters for the vdd class will be
parsed and assigned into the struct. Therefore, elements of the struct
cannot be const.

Change-Id: Ie2f33d64921bca24035ec8f8ea1ab4d1ac241a60
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock: Add support for current to vdd_class

The regulator_set_optimum_mode() API is used by acpuclock-krait. As part
of the effort to rewrite this code using standard clock APIs, broaden
these standard APIs to allow configuring both regulator voltage and
current.

Change-Id: Ic6dfa5c0c18d1c3eb531727ee79e4f5be84e8a97
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock: change vdd_corner to 1D array

Previously a 2D array was used for vdd_corner.  Since the dimensions
are known, 1D array saves one level of pointers and works equally well.
It's also easier to dynamically construct a 1D array.

Change-Id: Ic873ca40b383ff12363becd74537f58fcd2fdbf7
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>
msm: clock: Add a flag to disable rate caching

Certain clocks can have the rate of their parent
changed without clk_set_rate being called on them.
Caching rates for these clocks is incorrect, since
their rates may have changed since the last
clk_set_rate.

Change-Id: I1eb5dded6093f5ccd2b43a4d89eca033db54b73f
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
msm: clock: Allow msm_clock_init to be invoked multiple times

In preparation for a series of changes that move MSM clock
controllers to the Linux device model, allow msm_clock_init
to be invoked multiple times (once for each clock controller).

Change-Id: I0d56612c660f020ea762feb468234813cff0db22
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
msm: clock: Add pre_set_rate and post_set_rate ops

Some clocks might need to perform additional steps before/after a voltage
changes happen during a rate change. To accomodate such clocks and similar
requirements from new clock types in the future, add generic
pre/post_set_rate ops that are called before any HW state change is done
for set rate.

Change-Id: I07e4f79136028aaae5dee6d66d18b45c445f325b
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
msm: clock: Keep proper track of current voltage level

Fix a bug where vdd_class->cur_level is not updated when regulator api
calls are successful. The impact of the bug is unnecessary calls to
regulator APIs but not additional RPM calls since the regulator APIs
will optimize out repeated requests for the same voltage/current.

In case the regulator APIs fail, this bug might also result in
undervolting. But that's an unlikely case in a real product.

Change-Id: Ibe3574b6b72fcf898a5bfe9b5b253a8d0e0125ae
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
msm: clock: Call regulator_enable/disable when updating vdd

When all clocks on a regulator are disabled, regulator_disable should
be called.  Likewise, when first clock is prepared, regulator_enable
should be called.

Add regulator_enable/disable function during voltage voting.

Change-Id: I791e6faffe58870990a7865b7f241ec53f50012b
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>
msm: cpufreq: Initialize cpufreq driver early at boot

MSM cpufreq driver registering with the CPUFreq framework during
late_initcall() may cause the device to be available a few seconds after
the clock driver is ready for changing frequency. This could be bad for
boot and/or thermal performance, since the cpu will continue to boot at
whatever frequency the bootloaders set it to.

Initialize cpufreq driver as part of device_initcalL() but only after
all the clock drivers have had a chance to initialize their devices.

Change-Id: Iaa4867108f59a368ee5b511d35ea2e8e219d39d3
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>