OMAP4: DVFS: Fix scaling dependent frequencies.

When scaling dependent frequencies down it is observed that the order
in which frequencies are changed is incorrect.  For example, when core
domain changes OPP down from OPP119 to OPP50 the order is:
a) scale L3 freq down to OPP50
b) scale SGX freq down to OPP50
which is wrong.

Frequencies are scaled in order devices are registered in omap dvfs
framework in device list. Devices are inserted to the list in order,
such as dependences are satisfied if scaling frequencies up.

When scaling frequencies down traverse list backwards.

Change-Id: I752bcb264cac12514f358986a906f29ee81ba75e
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
MFD: twl6040-codec: cancel synch all active works on suspend

The TWL6040 vib_update work has to be canceled synchronously
before continue suspending, because of:
- it may sleep while accessing to I2C bus and, as result, WFI may be
reached in the middle of its execution and that may prevent system
from entering to OFF state.
- the device suspend handler may switch TWL6040 device to sleep
state while vib_update work is still active.

Change-Id: I77b681188976378eec9242ea64dc5f001960d279
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
MFD: TWL6030: cancel synch all active works on suspend

The TWL6030 battery works have to be canceled synchronously
before continue suspending, because of:
- they may sleep while accessing to I2C bus and, as result, WFI may be
reached in the middle of its execution and that may prevent system
from entering to OFF state.
- the device suspend handler may switch TWL6030 device to sleep
state while their works are still active.

Change-Id: Ie3ef579e05bded049e39f9186acb01b116283c87
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
bma180: cancel synch active accel work on suspend

The bma180_accel_device_worklogic has to be canceled synchronously
before continue suspending, because of:
- it may sleep while accessing to I2C bus and, as result, WFI may be
reached in the middle of its execution and that may prevent system
from entering to OFF state.
- the accel device suspend handler may switch bm180 to sleep state while
bma180_accel_device_worklogic is still active.

Change-Id: I66d56c895a37cc9391cfbb095f6e9ee45be86e49
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
TI TFW: omap die governor: cancel synch panic guard work on suspend

The decrease_mpu_freq_work has to be canceled synchronously before
continue suspending.
The decrease_mpu_freq_work may sleep because of accessing to I2C bus as
result WFI may be reached in the middle of its execution which will
prevent system from entering to OFF state.

Change-Id: Ief29ba634b9d296f8aa82f94bd39687c65b331ec
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
twl6030_bci_battery remove use_eeprom_config

In all sensible use cases use_eeprom_config and use_hw_charger are
actually synonymous so simplify the code and remove the use_eeprom_config.

Change-Id: Ibf473ea8106a72038f646e9163665caa91de9e06
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
twl6030_bci_battery read charger mode from register

For the twl6032 read the charger mode and power path usage from a register
on the chip.

Because of this change these parameters no longer need to be provided by
platform data so move these variable to the private structure.

This change also means that these variables being set also implies
twl6032 is the chip type so simplify the code by removing checks
for this from features at each usage of one of these variables.

Change-Id: If371db6270e40edf2ee315696300cf29bd9e8ea8
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>

Conflicts:
	drivers/power/twl6030_bci_battery.c
twl6030_bci_battery correct the current readings.

Correct the current reading functions for current_now and current_avg.
This was done with advice on the correct algorithm from the design team
and application engineers.

Also by default twl6030 and twl6032 use different sense resistors and
according to design team these resistors may be tuned for certain boards.
So allow the resistor value to be passed as platform data but select
sensible defaults if it is not.

Change-Id: Ib60742ec5779708d7156a4c6b4acd16b84cc8f0c
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
twl6030_bci_battery add seperate irq handlers for hw mode

As HW/Auto mode for the charger just wants to read status and convert
this to power supply class statuses. It is easier and cleaner to seperate
the handling of HW mode into seperate IRQ handlers.

Change-Id: Ic80fa0ff6b77a77e8c10b63027876bb8f613e0f8
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
twl6030_bci_battery remove hw handling from sw irq

Now that hardware charging mode has seperate IRQs remove the hardware
mode handling from the software mode IRQs as it is not required here
anymore.

Change-Id: Ib2cd7ae43157014b9111a5bdd5da36e1caeb6602
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
POWER: twl6030_bci_battery fix start/stop for hw mode

In use_hw_charger mode the charger should not be started or stopped
by disabling/enabled the DCDC/Linear charger. It should rather be
paused by setting HZ_MODE. This prevents the charger switching from
HW to SW mode.

Change-Id: I521b094a0fa4835466142219f1a1eef1ef4578b1
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
POWER: twl6030_bci_battery fix boot charge state in hw mode

Change the method to detect the charging state on boot. The
_STS bits used previously did not contain the complete charging
state so in some situations state was incorrectly indicated.

Change-Id: I6e276765d36f41df263ef5588aef4c792c8cbb7e
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
twl6030_bci_battery alter the hw mode start logic

In Active state the omap does not update the CHRG_DET_N signal so to
change the current limits based on the information of USB stack in
HW mode the CINLIMIT register needs to be written. This does not
take the charger out of HW mode.

Because the new logic started to make start fuction messy I have split
into seperate hw/sw start functions.

Change-Id: I647d2934a9b8e39e0d00049444c79ca196e8820b
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
twl6030_bci_battery fix autogate logic

The logic in the autogate function was causing a storm of events causing
I2C transactions as fast as the bus could run. Add an extra check in
the if statement and correctly set the charger source to stop this
happening. This stops the monitor function being scheduled thousands
of times when USB cable is inserted.

Change-Id: Ib783b684c3b3913e2afb9aa6fd607683c9d555ec
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
OMAP4: PM: TWL603[02]: update min, max voltages

In TWL6030 depending on the value of SMPS_OFFSET efuse register the
voltage range supported in standard mode can be either between
~0.6V - ~1.3V or ~0.7V - ~1.4V. In TWL6030 ES1.0, SMPS_OFFSET efuse
is programmed to all 0's where as starting from TWL6030 ES1.1 the
efuse is programmed to 1.

Since the operational support is from TWL6030 ES1.1, and some of
the TWL6030 firmwares allow us to override the SMPS_OFFSET, we use
the 1.41V as the max voltage and min as 0V as the voltage values
from ~0.7 - ~1.4v are equidistant for each step value or in other
words, 1 step is symmetric 12.66..mV in this range.

In case we are unable to do anything about the offset, then we throw
out a warning and continue as the system should still be able to
function despite the higher value configuration.

Change-Id: I6f93b7ba4694d96f96ce53a1bbe8f058e62c4bc8
[nm@ti.com: rewrite, split up and new controls]
Signed-off-by: Nishanth Menon <nm@ti.com>
[oleksandr.kozaruk@ti.com: original patch]
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>

Conflicts:
	arch/arm/mach-omap2/omap_twl.c
omap-hsmmc: Prevent possible race condition

Making mmc_host_enable() and mmc_host_disable() invocations exclusive to
prevent race condition that occurs on specific board configurations based
on Blaze platform when repeated suspend/resume performed.

Change-Id: Ia709c2e0a4e19a0abb1cfbe7651c838b7c13fc1c
Signed-off-by: Semen Protsenko <semen.protsenko@ti.com>
ASoC: dapm: Use card's power_mutex during codec shutdown

Codec shutdown performs a DAPM power sequence that might cause conflicts
and/or race conditions if another stream power event is running simultaneously.
Use card's power_mutex to protect any potential race condition between them.

Change-Id: Idd3be5967df9a454da8aaefb28ddbe497b651f8f
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>

Conflicts:
	sound/soc/soc-dapm.c
twl6040: errata: PDMUP State In Sleep/Deep Sleep Mode

When AUDPWRON is set to 0 at any time in the IC operation to
put it into sleep or deep sleep mode, there is a finite probability
that the value of PDMUP could be at logic 1 (VDDVIO). In this state,
the resistive pulldown on OMAP on this pin results in a current drain.

Adding new impacted revisions (ES1.3, ES2.0, ES2.2) to errata workaround.

Change-Id: I049fe85eb2e1e9d04c72a9820f3adcc25db35646
Signed-off-by: Vadym Shovkoplias <shovkoplias.vadym@ti.com>
USB: gadget: f_mtp: fix send ZLP packet algorithm.

If size of the data that sent from MTP-device to computer is a multiple of
wMaxPacketSize (usb endpoint) then at the end of transfer device must
send ZLP packet. Previously in f_mtp module a variable 'maxpacket' that
used to send ZLP packet was always equal to 512. For USB2.0 wMaxPacketSize
equals 512 but for USB1.1 wMaxPacketSize can be 64, 32, 16 or 8. Now variable
'maxpacket' contains real value of wMaxPacketSize in all USB modes and ZLP
packet is sent correctly for USB1.1.

Change-Id: I75606c954119dea2a76d955849a47208df0d2db0
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
omap: hwmod: enable clocks before deasserting hardreset

The enable code currently deasserts the hard-reset before
turning on the clocks. These kind of reset lines are limited
only to processor-device like IPs such as DSP or IPU or
IVA, which actually need the clock to be enabled first.

The code that deasserts the hard-reset has therefore been
relocated to execute after the clocks are enabled, to avoid
the hard-deassert traces (failed to hard reset).

Change-Id: Id9c413b315c927295cf4be7f986f6e1a710b9ef8
Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Juan Gutierrez <jgutierrez@ti.com>
Signed-off-by: Oleg Matcovschi <oleg.matcovschi@ti.com>
Signed-off-by: Paul Hunt <hunt@ti.com>

Conflicts:
	arch/arm/mach-omap2/omap_hwmod.c