mfd: Fix for the TWL4030 PM sleep/wakeup sequence

Only configure sleep script when the flag is TWL4030_SLEEP_SCRIPT.

Adding the missing brackets for fixing the issue.

Signed-off-by: Lesly A M <leslyam@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: David Derrick <dderrick@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
mfd: Correct the twl4030-power warning print during script loading

Correcting the if condition check for printing the warning,
if wakeup script is not updated before updating the sleep script.

Since the flag 'order' is set to '1' while updating the wakeup script
for P1P2, the condition checking for printing the warning should be
if(!order) (ie: print the warning if wakeup script is not updated before
updating the sleep script)

Signed-off-by: Lesly A M <leslyam@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: David Derrick <dderrick@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
mfd: Modifying the twl4030-power macro name Main_Ref to all caps

Modifying the macro name Main_Ref to all caps(MAIN_REF).

Suggested by Nishanth Menon <nm@ti.com>

Signed-off-by: Lesly A M <leslyam@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: David Derrick <dderrick@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
mfd: Check twl4030-power remove script error condition after i2cwrite

Fixing the error condition check in twl4030 remove script function.
Due to some typo in commit ID: 11a441ce82d6ffecfd39b324024de0cd630b36c1

Signed-off-by: Lesly A M <leslyam@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
MFD: TWL4030: power scripts for OMAP3 boards

Power bus message sequence for TWL4030 to enter sleep/wakeup/warm_reset.

TWL4030 power scripts which can be used by different OMAP3 boards
with the power companion chip (TWL4030 series).

The twl4030 generic script can be used by any board file to update
the power data in twl4030_platform_data.

Since the TWL4030 power script has dependency with APIs in twl4030-power.c
removing the __init for these APIs.

For more information please see:
	http://omapedia.org/wiki/TWL4030_power_scripts

Signed-off-by: Lesly A M <leslyam@ti.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
MFD: TWL4030: TWL version checking

Added API to get the TWL5030 Si version from the IDCODE register.
It is used for enabling the workaround for TWL erratum 27.

Signed-off-by: Lesly A M <leslyam@ti.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
MFD: TWL4030: workaround changes for Erratum 27

Workaround for TWL5030 Silicon Errata 27 & 28:
	27 - VDD1, VDD2, may have glitches when their output value is updated.
	28 - VDD1 and / or VDD2 DCDC clock may stop working when internal clock
		is switched from internal to external.

Erratum 27:
	If the DCDC regulators is running on their internal oscillator,
	negative glitches may occur on VDD1, VDD2 output when voltage is changed.
	The OMAP device may reboot if the VDD1 or VDD2 go below the
	core minimum operating voltage.

	WORKAROUND
	Set up the TWL5030 DC-DC power supplies to use the HFCLKIN instead of
	the internal oscillator.

Erratum 28:
	VDD1/VDD2 clock system may hang during switching the clock source from
	internal oscillator to external. VDD1/VDD2 output voltages may collapse
	if clock stops.

	WORKAROUND
	If HFCLK is disabled in OFFMODE, modify the sleep/wakeup sequence and
	setuptimes to make sure the switching will happen only when HFCLKIN is stable.
	Also use the TWL5030 watchdog to safeguard the first switching from
	internal oscillator to HFCLKIN during the TWL5030 init.

	IMPACT
	power sequence is changed.
	sleep/wakeup time values will be changed.

The workaround changes are called from twl4030_power_init(), since we have to
make some i2c_read calls to check the TWL4030 version & the i2c will not be
initialized in the early stage.

This workaround is required for TWL5030 Silicon version less than ES1.2
The power script & setup time changes are recommended by TI HW team.

For more information please see:
	http://omapedia.org/wiki/TWL4030_power_scripts

Changes taken from TWL4030 Erratum 27 workaround patch by Nishanth Menon.

Signed-off-by: Lesly A M <leslyam@ti.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
MFD: TWL4030: optimizing resource configuration

Skip the i2c register writes in twl4030_configure_resource() if the new value
is same as the old value, for devgrp/type/remap regs.

Suggested by David Derrick <dderrick@ti.com>

Signed-off-by: Lesly A M <leslyam@ti.com>
Signed-off-by: Sanjeev Premi <premi@ti.com>
mfd: Fix twl_probe section mismatch warning in mfd/twl-core.c

Fix the following section mismatch warning when building
omap2plus_defconfig:

WARNING: vmlinux.o(.data+0x47d7c): Section mismatch in reference
from the variable twl_driver to the function .init.text:twl_probe()

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
Signed-off-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
mfd: twl: Use appropriate config option

This patch ensures that definition of platform device
for the PMIC is tied to more appropriate config option.
mfd: twl: Enable execution of power scripts (as default)

This ensures that no changes are required to any of the
existing board configuration to enable this feature.
omap3evm: Board specific initialization (workaround)

Until a better way to identify the board during driver
initialization is found this patch helps isolate the
board specific initialization.

These changes may be required for other boards as well
but it is better to be prudent.
omap3evm: Add support for PMIC scripts

This patch defines the PMIC scripts for the OMAP3EVM.

While creating the patchset, suddenly the warm-reset
isn't working. So this patch nees to be reworked.
I have postponed some formatting changes for next
revision.
mfd: twl: Prevent dual initialization of PMIC scripts

Currently, twl4030_script_init() and is called during probe
and module_init(). The PMIC scripts for specific to the board
are lost (overwritten) when twl4030_script_init() is invoked
via module_init().

This patch ensures that probe isn't called twice.
omap3evm: Configure to use sys_offmode

This patch enables configures the board to use
sys_offmode to take benefit of the PMIC scripts.
fix: Fix warmreset (1)

We shouldn't initialize the P*_SW_EVENTS register to 0x08.
This value was taken from the CCS project for OFF mode testing.

But this masks/undoes the settings for warm reset.
fix: Fix warmreset (2)

Update the warm reset sequence as per the recommendations
for ZOOM platform.

There were minor changes between the resource groups that
were mixed with device groups.
serial: omap-serial: Enable the UART wake-up bits always

OMAP can do also dynamic idling so wake-up enable register should be set
also while system is running. If UART_OMAP_WER is not set, then for instance
the RX activity cannot wake up the UART port that is sleeping.

This RX wake-up feature was working when the 8250 driver was used instead
of omap-serial. Reason for this is that the 8250 doesn't set the
UART_OMAP_WER and then arch/arm/mach-omap2/pm34xx.c ends up saving and
restoring the reset default which is the same than value
OMAP_UART_WER_MOD_WKUP here.

Fix this by moving the conditional UART_OMAP_WER write from serial_omap_pm
into serial_omap_startup where wake-up bits are set unconditionally.

[Sanjeev Premi] Backported to 2.6.37

Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Cc: Govindraj.R <govindraj.raja@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
omap_device: Convert pr_warning to pr_debug

The messages printed during the change of latency
for devices are not really warnings.

Change them to debug messages. Specifically helps
for the UART where the messages interfere with the
idle transitions.
omap2+: serial: Fix random hang when sleep is enabled

With a minimal kernel image, the linux kernel would hang
randomly - usually without any dump.

Only on rare occasions, this dump could be observed:
  Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa3070a0
  Internal error: : 1028 [#1]
  last sysfs file: /sys/power/state
  Modules linked in:
  CPU: 0    Not tainted  (2.6.37-14305-g3767dd6-dirty #155)
  PC is at omap_uart_allow_sleep+0x40/0xe0
  LR is at omap_uart_can_sleep+0x38/0x64
  pc : [<c00483dc>]    lr : [<c00484b8>]    psr: 200000d3
  sp : c0429fa8  ip : c0438880  fp : 00000000
  r10: 0000001f  r9 : 413fc082  r8 : 80028110
  r7 : c042cd0c  r6 : c00299dc  r5 : 00000000  r4 : cf8052c0
  r3 : 00000001  r2 : fa3070a0  r1 : 00040000  r0 : cf8052c0
  Flags: nzCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment kernel

The script to recreate the hang/crash is:
  mount -t debugfs debugfs /mnt
  echo 5 > /sys/devices/platform/omap/omap_uart.0/sleep_timeout
  echo 5 > /sys/devices/platform/omap/omap_uart.1/sleep_timeout
  echo 5 > /sys/devices/platform/omap/omap_uart.2/sleep_timeout
  echo 5 > /sys/devices/platform/omap/omap_uart.3/sleep_timeout

  echo 1 > /mnt/pm_debug/sleep_while_idle
  echo 1 > /mnt/pm_debug/enable_off_mode

The problem occurs when accessing the registers UART registers
are accessed when the clocks are disabled.

This patch moves steps to enable/ disable wakeup into function
omap_uart_prepare_idle() before the clocka are disabled. This
makes the usage similar to omap_uart_resume_idle().

With register access happening only when the clocks are enabled,
there is no possibility of hang/ crash - as originally observed.