[Blaze] ASoC: TWL6040: Add switch based headset detection support

Android relies on a switch class driver to report uEvent
for headset status. This adds support for basic headset status
reporting to the twl6040 codec driver. The switch is registered
only if the codec private data indicates it should be used.
This allows boards that don't use jack detection mechanism to
register the switch for headset detection elsewhere.

Change-Id: Ie7762f9a99246b30fb4f1ee4a9e63e62079d334e
Signed-off-by: Chris Kelly <c-kelly@ti.com>
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: twl6040: Add VDDHF regulator

Use regulator framework to enable/disable VDDHF voltage supply
for handsfree drivers. Not providing a valid regulator for VDDHF
through regulator framework doesn't have any negative impact as
long as VDDHF is actually supplied by some other way (e.g. voltage
supply enabled through bootloader or machine initialization).

Ported from p-android-omap-2.6.35

Change-Id: I9df90a695ed9afcb6da916fb53bb3965c5292226
Signed-off-by: Girish S G <girishsg@ti.com>
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Signed-off-by: Akash Choudhari <akashc@ti.com>
Signed-off-by: Girish S Ghongdemath <girishsg@ti.com>
Signed-off-by: Gabriel M. Beddingfield <gabrbedd@ti.com>

Conflicts:
	sound/soc/codecs/twl6040.c
ASoC: twl6040: SW WA for DC Offset On EAR Differential Output

Correct Sequencing To Ensure No DC offset On EAR Outputs.
Fix the pops on switches between HF to EP

Change-Id: I497f8d6a2c2662406720a28e7906c5e58917fb24
Signed-off-by: Pierre Moos <p-moos@ti.com>
Signed-off-by: Francois Mazard <f-mazard@ti.com>

Conflicts:
	sound/soc/codecs/twl6040.c
ASoC: twl6040: Align widget names with Kernel V3.1

Change-Id: I77acb512c8d8bd703d10cdfab4397d5ffdbb2fb6
Signed-off-by: Pierre Moos <p-moos@ti.com>
Signed-off-by: Francois Mazard <f-mazard@ti.com>

Conflicts:
	sound/soc/codecs/twl6040.c
ASoC: twl6040: Add wakelock for headset detection interrupt

TWL6040 is kept active during a voice call, but CPU can go into
suspend state. If headset is inserted or removed while the CPU
is in suspend, SYS_NIRQ2 IRQ line will wake the CPU up and the
headset state will be acknowledged at kernel level, but the
event propagated to userspace layers to cause audio rerouting
might not be completed on-time before CPU goes back to suspend.
A wakelock is added to prevent CPU to go back to suspend
immediately after the event, instead it'll wait for 2 secs for
the event to be processed in userspace.

Change-Id: I88a71345c7a082801a21335f20c920c68bacb8fc
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: twl6040: Fix HS DACs DC offset errata

Current implementation of HSDACs DC offset errata disables DACR when
headset and earpiece outputs are used simultaneously. A simpler approach
is used:

- Headset DAC Left:
  o HSDACR must be enabled before enabling HSDACL, since HSDACL reset is
    done when HSDACR is enabled
  o No additional handling required for power-down

- Headset DAC Right:
  o No special handling required for power-up
  o HSDACR reset is done when HSDACL is enabled, so in case DACL was
    already disabled, re-enabled it momentarily while HSDACR power-down
    occurs.

Change-Id: I20f29602268d701b64c10dfa86cc43f66b8325b0
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: twl6040: Use HS DC offset errata for TWL6041 ES2.0

Headset DC offset errata also applies for TWL6041 ES2.0.

Change-Id: Ia1c6f837507d146d137fd62e3e500ad427cad233
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: twl6040: Split HF DAC event handler

Use a dedicated event handler for HS DAC widgets whose only task is
wait for the settling time of at least 80us.

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

Conflicts:
	sound/soc/codecs/twl6040.c
ASoC: twl6040: Reorder HSDAC/DRV power mode change

HSDAC and HSDRV power mode change cannot be performed when the
corresponding DAC is enabled, which is now explicitly rejected.
This constraint has an important impact on eapiece path, since
it can work only in high-performance mode.

In such case, we need to force the power mode before enabling
the DACs and restore previous mode after DACs have been disabled.
That sequence cannot be achieved if the event is associated with
a switch widget, so using a supply widget instead.

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

Conflicts:
	sound/soc/codecs/twl6040.c
ASoC: twl6040: Reduce i2c writes during power mode change

Replace direct i2c writes to TWL6040 by calls to snd_soc_update_bits()
which prevents unnecessary i2c writes when reg cache and hardware are
in sync.

Change-Id: I8bb02d83fb419a478707d33498a95efa6e98a45c
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: twl6040: Handle handsfree overcurrent events

TWL6040 has a short circuit detection mechanism that report events
when the current exceeds 2.2A in its handsfree output stage. Upon
detection of handsfree overcurrent, the suggested action is to
disable handsfree drivers to prevent damage. Additionally, when
this event occurs it's reported to Android userspace layers through
an uEvent associated with the TWL6040 MFD.

Change-Id: Iea94c55286a9adb158caac10f7a15fae73827792
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Signed-off-by: Chris Kelly <c-kelly@ti.com>
ASoC: twl6040: VDDHF as SUPPLY widget

VDDHF external boost supply was being enabled after and disabled before
handsfree driver as a strategy for pop noise reduction. This strategy
makes handsfree driver very susceptible to overcurrent events, so the
boost supply is converted to a SUPPLY widget to enable it before and
disable it after handsfree path.

Change-Id: I608b4b0f5cb3301053869ccd2732434efe276b81
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
ASoC: TWL6040: Adding Aux audio output

Adding switch controls to enable/disable audio output
throught Aux pins in codec.

Change-Id: I329c44fe95a9157d56017ac47cb4e091e87d8710
Signed-off-by: Israel Cepeda <icepeda@ti.com>