OMAP4: 4430SDP/Tablet: Mark e.MMC card as built_in

SDIN5Cx-Y e.MMC card that is installed on 44XXr-based SOMs
is following JESD84-A441 standard. This standard is declaring
CMD5 for allow e.MMC enter Sleep-state when VCC suppling can be
disabled. In this case HSMMC controller on resume path should
only restore setting that it had before suspend and doesn't need
to initialize the e.MMC card one more time.

So mark HSMMC controller that serve e.MMC card as built_in,
   this allow us to exclude mmc_power_off()/mmc_power_up()
   routines from suspend/resume path and thereby not drop
   HSMMC host configuration. Host configuration is this case
   saved/restored by PM runtime operations.

Change-Id: I93f2feb8832114278c653ab7158ab5b900da10d7
Signed-off-by: Riazantsev Volodymyr <v.riazantsev@ti.com>
usb: ehci-omap: implement workaround for errata i640

The OMAP4 EHCI controller has the following defect (errata ID i640):

Title:
	USB HOST EHCI In TLL Mode Will See The Port Being Disabled Upon Resume
	Or Remote Wakeup.

Description:
	This bug impacts the TLL module when used in conjunction with the EHCI
	part of the USB host module. Upon resume or remote wakeup from a bus
	suspended state, the device will switch from full speed to high speed
	before the host does.This will incorrectly generate a disconnect IRQ on
	the host side (USBSTS[2]:PCD=1), and the hardware will disable the port
	(PORTSC[2]:PED=0). The peripheral will then go back to suspend because
	there is no more activity on the bus.

	PHY mode (non-TLL) is not impacted. OHCI is not impacted.

WORKAROUND:
	The workaround consists of stalling the device for some time so that
	the host can switch to HS before the device.

	The programming guide to follow at the end of the resume sequence is:
	1. The host ends the resume sequence by clearing PORTSC.FPR bit.
	2. The software waits for the TLL to report the LineState change from
	   K to SE0 on ULPI. PORTSC.LS will switch from 0x1(K) to 0x0(SE0).
	3. Gate the TLL ULPI clock and thereby the device controller by PRCM
	   control: the whole TLL is frozen, including the ULPI clock
		- Clear the appropriate OPTFCLKEN_USB_CHx_CLK bit in the
		  CM_L3INIT_HSUSBTLL_CLKCTRL register
	4. Wait 3 us for the host to go to HS.
	5. Restart the TLL ULPI clock and the device controller by PRCM
	   control, to unfreeze the entire TLL, including the ULPI clock
		- Set back the appropriate OPTFCLKEN_USB_CHx_CLK bit in the
		  CM_L3INIT_HSUSBTLL_CLKCTRL register
	6. The USB device switches to HS.

This workaround is based on next patches from k3.0:
- 4ca67e5 OMAP4: USB Host: Re-implement EHCI Hub Control to workaround errata
	(by Anand Gadiyar <gadiyar@ti.com>)
- 7ce60b1 OMAP4: USB: Update EHCI TLL errata i640
	(by Jon Hunter <jon-hunter@ti.com>)

Change-Id: I7fa89428950f3a5b39db7db76fdbee28f5cfec52
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
OMAP4: USBTLL: Off mode disconnect workaround (Errata i754)

When resuming from OFF mode, the EHCI controller was performing a
reset resume for ports using the TLL interface because the port
status was being cleared. This was caused by the host controller
not restoring the state of the ID pin in the TLL module correctly.
This issue is workarounded by enabling the ID pin pull-up in the TLL
(because the EHCI controller is always the host) and disabling ID
pin events as these are not required for the TLL connection.

[Ruslan]: ported from k3.0 (commit-id fa25183)

Change-Id: Ibc22d77606e05e4dd138819079028ebcf254039e
Signed-off-by: Jon Hunter <jon-hunter@ti.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
Merge branch 'p-linux-omap-3.4' into p-android-omap-3.4

* p-linux-omap-3.4:
  OMAP4: USBTLL: Off mode disconnect workaround (Errata i754)
  usb: ehci-omap: implement workaround for errata i640
  OMAP4: 4430SDP/Tablet: Mark e.MMC card as built_in

Change-Id: I496bd388d066ea290980a145c43c291ef07025c1
Signed-off-by: Praneeth Bajjuri <praneeth@ti.com>
ARM: OMAP4: twl603x: Enable SMPS standard mode with offset by default

In TWL603x depending on the value of SMPS_OFFSET efuse register the SMPS
regulator 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.

The wider voltage range should be enabled on OMAP4 for supporting of
higher OPPs, hence always try to enable standard mode with offset for
SMPS regulators. Because twl603x_set_offset() need to be called only once -
run it for MPU VD on OMAP4430/70 and Core VD on OMAP4460
(where MPU VD controlled by TPS6236X).

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: I710ca4e4b7b83701465c2aab322803a6bd2476e3
[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>
[oleksandr.tyshchenko@ti.com: ported from K3.0]
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
ARM: OMAP3+: fix OFF mode vsel calculation if voltdm->pmic->vddmin is
set

OFF mode vsel will be calculated to value >=1 if voltdm->pmic->vddmin is
set to non zero (0) value for TWL603x and voltdm->vc_param->off == 0. As
result, voltage domains will not be switched off during suspend. It
happens because omap_vc_calc_vsel() function is used for OFF mode vsel
calculation and it does the following:
   if (voltdm->pmic->vddmin > uvolt)
		uvolt = voltdm->pmic->vddmin;

Hence, fix it by using PMIC specific uv_to_vsel() conversation routine
and let PMIC decide how to .

Change-Id: I92b3d911b9fb7e6c9e4742b89ee339e504676546
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
ARM: OMAP4: twl603x: configure vddmin/vddmax

The current working voltages range is from ~0.7V - ~1.4V on OMAP4 with
TWL6030/6032 where SMPS regulators configured to SMPS standard mode with
offset.

Hence, configure vddmin and vddmax fields in omap_voltdm_pmic structures
for all volatge domains to 709000(0x01) and 1418000(0x39) respectively
to protect us from using unsupported voltage values.

Change-Id: Iba7c6ab1b23c47fd44e1ecf7a1713852b454b788
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
twl603x: usb: Fix build if CONFIG_TWL6030_USB is not defined

The patch fixes build error, which could occur
if use twl6030 usb notifiers when CONFIG_TWL6030_USB is
not defined.

Change-Id: If26655ac4d3f204e5757e5f51e3a28680ec79fe6
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
MFD: TWL603x: Introduce errata implementation

This patch adds generic code for errata implementation
supporting for the TWL6030/TWL6032 chips.

Change-Id: Ieb2329ec3cf1e0300decc2908fba28aa471854e5
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
[oleg.kosheliev@ti.com: port from K3.0]
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Regulator: TWL6032: Keep ON some resources during suspend

For TWL6032 revision < ES1.1 with EEPROM revision < rev56.0
LDO6 and LDOLN must be always ON because of the hardware
bug in the TWL6032. If LDO6 or LDOLN is always on then SYSEN
must be always on.
For TWL6032 revision >= ES1.1 with EEPROM revision >= rev56.0
those LDOs can be off in sleep-mode.
This patch performs additional checks.

Change-Id: Ifb7d894e2f6282b04eef8f27e993e8235ad7efc1
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
[oleksandr.tyshchenko@ti.com: ported from K3.0]
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
ARM: OMAP4: twl-common: Gate resources during suspend

During suspend some resources is kept ON, so gate them.
This patch disables following resources during suspend:
vdac, vaux1, vaux2, vaux3, vmmc, vpp, vusim, vana, vcxio,
vusb, v2v1, sysen, regen1.

Change-Id: I84cc0c889e0021fa5b7d216102a0be5bfc635103
Signed-off-by: Ambresh K <ambresh@ti.com>
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
[oleksandr.tyshchenko@ti.com: ported from K3.0]
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
ARM: OMAP4: twl-common: Keep ON regulator v1v8 during suspend

Regulator v1v8 is used as general-purpose supply for
OMAP/PMIC I/Os and external peripheral on the board.
So he must be enabled during suspend.

Change-Id: I69afb4d8ff2f6eb884873f7e7e445fb00d9b2c97
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
ARM: OMAP4: twl-common: Configure some resources as always_on

The regulator framework will shut down any unused regulators
in the system. This was causing the some regulators to be shut
down, but VDAC supplies clock generation chip, VANA supplies
GPADC and GAS-GAUGE, CLK32KG is used for the WILINK, etc.
So configure resources VDAC, VANA, CLK32KG and V2V1 as always_on
by default since it was implemented in K3.0.

Change-Id: Ib3ca353fb91033c6b68e01f137d9ea31b49ff5d1
[balajitk@ti.com: add always_on for VANA]
Signed-off-by: Balaji T K <balajitk@ti.com>
[m-sonasath@ti.com: add always_on for VDAC]
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>
[vishalm@ti.com: add always_on for CLK32KG]
Signed-off-by: Vishal Mahaveer <vishalm@ti.com>
[oleksandr.tyshchenko@ti.com: ported from K3.0]
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
ARM: OMAP4: Tablet/SDP4430: Call regulator_has_full_constraints on init

This allows the regulator core to disable all regulators
which are not in use at the end of the kernel init phase.

Change-Id: Ibfa437a5ad3a339f87ea5acee797e4d595bd489f
Signed-off-by: Dan Murphy <dmurphy@ti.com>
[oleksandr.tyshchenko@ti.com: forward port from K3.0]
Signed-off-by: Oleksandr Tyshchenko <oleksandr.tyshchenko@ti.com>
bq2415x-charger: Add BQ2415x charger driver

Added support for BQ2415x charger.
It enables battery charging via AC.

Change-Id: I3b2cf70328781521c1172722a7ce2e61a5de7378
Signed-off-by: Balaji T K <balajitk@ti.com>
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
[oleg.kosheliev@ti.com: ported from K3.0,
added suspend and resume functions]
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
twl603x_battery: Add twl603x Battery driver

Added support for twl6030/32 battery charger.
It enables battery charging via USB and
interacts with BQ2415x AC charger.

Change-Id: I67d45d4c9d8817a23eebdde866bb246d56930c6a
Signed-off-by: Nishant Kamat <nskamat@ti.com>
Signed-off-by: Balaji T K <balajitk@ti.com>
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
[oleg.kosheliev@ti.com: ported from K3.0
Watchdog reset moved to dedicated non-deferrable
delayed work. Added wakeup from suspend if charging from
USB DCP. Added Errata field in device_info.
Fixed mem leak in probe (caused by kmemdup of
platform_data).
Added unregistration of the USB notifier in suspend.
Removed self-rescheduling of the bci_monitor_work.
Removed interrupts masking at suspend.
Removed BQ2415x suspend/resume actions because they
are implemented in BQ2415x driver now. Removed
disabling of the thermal monitoring in suspend
if the battery is charging. Removed android
wake-locks. Omap_dm_timer replaced with
generic alarmtimer. Alarmtimer is based on RTC timer.
Initialized di->dev in probe (it was not assigned
in k3.0 and NULL was indicated in all info msgs).]
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
ARM: OMAP4: twl603x: Add platform data for twl603x_bci_battery

Add platform data to initialize twl603x battery
charger driver.

Change-Id: Ie8a309f8ee2db1f0fb17d8e22f8d0c65ae23447d
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
ARM: OMAP4: Tablet/SDP: Add twl603x/BQ2415x battery charger support to board file

Enable twl603x charger and BQ2415x AC charger support in
board files for 44xx tablet and 4430sdp.

Change-Id: I09dc3e5cf897074f6845f3beabdc60948bae3f4b
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
ARM: MFD: TWL6032: Implementation of the ProDB00119490 errata

Residual voltage may be present on VBUS when USB cable is unplugged.
Workaround: Increase the VBUS anticollapse loop threshold to 4.44 V.

This errata affects only TWL6032 ES1.1

Change-Id: I7533fa7e3caa98e9e326f0c30cfb31d813303be8
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>
ARM: MFD: TWL6030: Implementation of the ProDB00112620 errata

This errata affects only TWL6030 ES2.1. The usage of the CIN_LIMIT
codes above 600mA (CHARGERUSB_CINLIMIT Register, codes
650mA/700mA/750mA) may lead to an unlimited input current in
case VBUS < 4.1V.

Workaround: The anti-collapse feature needs to be enabled before
usage of the CIN_LIMIT. All CIN_LIMIT codes will be functional at
all anti-collapse levels.

Change-Id: I4fc0eb64cc96b692f4761a27098df307e1f5cd54
Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@ti.com>
Signed-off-by: Oleg_Kosheliev <oleg.kosheliev@ti.com>