UPSTREAM: ASoC: max98090: add digital mic mux to record path

The max98090 driver currently treats the digital mic enable as a supply
on the record path, causing the digital mic enable to always be turned on
when attempting to record.  This is incorrect, however, since the digital
mic enable is also a mux control where 0 selects the ADC output as input
to the record-path DSP and 1 selects the digital mic.  This patch adds
a virtual DMIC mux to the reocrd path so that we can switch between the
ADC and the digital mic for recording.

BUG=chrome-os-partner:18720
TEST=After audio support is added, observe that enabling the record
path does not force the digital mic enable bits on.

Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
(cherry picked from linux-next commit
	fd5f940f82cdc0132438a96559b27dd7fd574875)

Change-Id: I92b7a51747258e69822b81426fb9df9b8e7e48ed
Reviewed-on: https://gerrit.chromium.org/gerrit/57630
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177661
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CHROMIUM: ALSA: ASoC: max98090: Shutdown codec when changing to/from dmic.

The DMIC Mux control can't safely be toggled unless the codec is
shutdown.  Doing so results in an unstable input path and awful
recordings from the mic.  When shutting down the codec, configure the
volume smoothing and disable zero crossing.  This keeps the shutdown
time deterministic (not dependent on the output content) and avoid an
abrupt mute of the output.

BUG=chrome-os-partner:21869
TEST=Toggle DMIC Mux during a hangout, listen to other end.
plug/unplug headsets make sure recording doesn't change to pure noise.
Also listen to youtube while switching between analog and digital mic,
make sure audio dropout isn't too abrupt.

Change-Id: I5d47fef66fc378b9e281c9ee74afe01fa84e0d11
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168620
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177662
CHROMIUM: ALSA: ASoC: max98090: Shudown codec for hw_params.

The REG_INTERFACE and REG_FILTER_CONFIG registers can only be modified when shdn
is set.  Set shutdown in hw_params while configuring these registers. Re-use the
code from dmic mux that had to do the same thing.

BUG=chrome-os-partner:22816
TEST=boot and enter hangout from pit, check that the mic isn't hissing.

Change-Id: Ib382765aac9113061eb351ee8947f8324b9aab18
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170683
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177663
CHROMIUM: BYT_LPE_FEATURE: Ported LPE audio driver codes from kernel 3.8

[dbaseshore : This patch must be reverted and broken up.]

Signed-off-by: Loh, Boon Kiat <boon.kiat.loh@intel.com>
Signed-off-by: Derek Basehore <dbasehore@chromium.org>

Conflicts:
	arch/x86/platform/Makefile

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I1817bc0be4d73cb3fc73b0ba099f29b946744e6c
Reviewed-on: https://chromium-review.googlesource.com/182361
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: BYT_LPE: Added machine driver source file for RT5642 codec as the base

(cherry picked from commit 9988a0265ff0978e9671dc7d5ac2f7feaa126d89)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I6a065e2b075435e9f59e503c1680679ef871a4bb
Reviewed-on: https://chromium-review.googlesource.com/180702
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: dmaengine: mid_dma: Add mid_dma changes from LPE commit

This is separated from isg_atom-linux_kernel commit 66b779b ("BYT_LPE: Added
Realtek(RT5642) support to LPE. Sound card registration successful, but
functionality yet to be tested.").

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit e51bfaf21c87fab21f7140415134f6be2931f7c1)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: Icf1c3f1b24a8d5c39553ff00edf78e45d572840c
Reviewed-on: https://chromium-review.googlesource.com/180704
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: x86: Add BYT RT564x related registrations

This is separated from isg_atom-linux_kernel commit 66b779b ("BYT_LPE: Added
Realtek(RT5642) support to LPE. Sound card registration successful, but
functionality yet to be tested.").

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit 8fecc555782c1051ed6168fa829b8e06a2811336)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I8ac5d416437652966f9f7ce823f9b53c481d2f27
Reviewed-on: https://chromium-review.googlesource.com/180705
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: ASoC: mid-x86: Codec selection and machine driver update for BYT

This is separated from isg_atom-linux_kernel commit 66b779b ("BYT_LPE: Added
Realtek(RT5642) support to LPE. Sound card registration successful, but
functionality yet to be tested.").

[Jarkko: couple minor coding style issues corrected. This actually should be
squashed into ("BYT_LPE: Added machine driver source file for RT5642 codec
as the base")]

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit c81aa6d43a682c64195383c039009e14da551c16)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I7d231c62c9e2561ae425b9b0dd01aad79cb66e23
Reviewed-on: https://chromium-review.googlesource.com/180706
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: BYT_LPE : Enabled playback with RT5642

(Stereo; Master; FW-controlled SSP2) but record is not working yet.

(cherry picked from commit e0f895847939a8e3f72e4403d3355bf41f89bde7)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I3e5eeaa031b9ebd5ab54635db0c1d6e862f279f5
Reviewed-on: https://chromium-review.googlesource.com/180707
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: ASoC: mid-x86: Fix select statement for rt5640 driver

For simplicity rt5642 driver from 3.8 branch wasn't applied but idea was to
use upstream rt5640 instead. Fix driver select statement accordingly.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit c2bac8f138fd647b2711a1a888fee4fb356295c3)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: Ief60d341f50a7ff811e57b109c896b6cf971bfd2
Reviewed-on: https://chromium-review.googlesource.com/180708
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
CHROMIUM: ASoC: mid-x86: Use I2S BCLK as a codec master clock on byt_bl_rt5642

Currently MCLK from Baytrail SoC seems to not activate. Use temporary
I2S BCLK as a codec PLL input.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit 089f73b77ca12cd64f365982413366d0d8879773)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I855edab67e160e975ee4ef1909ad302ce17c868c
Reviewed-on: https://chromium-review.googlesource.com/180709
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: ASoC: mid-x86: Use rt5640-aic1 also for capture on byt_bl_rt5642

Second I2S of audio interface card is not routed to LPE on Bayley Bay-I and
therefore capture obviosly don't work. Fix this by using rt5640-aif1 for
capture too.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
(cherry picked from commit 76472f8decbd30a9dfb624841578c688f7c04894)

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: If21f8ec48b9bb4fcd521d632a7c27b50d4d490de
Reviewed-on: https://chromium-review.googlesource.com/180710
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Force firmware-loading to use 4-byte writes

The LPE-audio IRAM and DRAM memory types apparently can only
accept 4-byte writes of firmware.  The "memcpy" variants
cannot be relied upon to do this.  Accordingly, the code
that copies dsp firmware to the LPE-audio memory is
re-written as a loop of 4-byte copies.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: Iba72dbaf392d091742a2cb69ed1226908e8b0421
Reviewed-on: https://chromium-review.googlesource.com/180711
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Add a Maxim 98090-codec choice to the audio driver

This adds a new choice of codec to the LPE audio driver for
the Rambi platform.  This platform has a Maxim 98090 codec,
so that choice is added.  The actual code added is merely
glue-code copied and edited from the RT5640-codec case which
is architecturally similar.

TODO:  The codec shows up on some I2C bus, of which there
are several in the system.  Currently we don't have a good
way to determine which I2C but has the codec, so for now
this defines a CONFIG option SND_BYT_MAX98090_I2C_BUSNUM
(integer) that defines the bus number.  Every reference to
the bus number should be derived from this.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I96f496d35c4ea64ffbaf707fcfd719d9c68ef3f7
Reviewed-on: https://chromium-review.googlesource.com/180712
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Extract standalone platform-data for Baytrail audio codec

This extracts a standalone platform-data initializer for
Baytrail audio codec Maxim 98090 (Found on "rambi" variant),
without pulling all the 32-bit medfield and moorestown
dependencies.

The initializer is declared to be a "device_initcall" so
that it will get invoked during init, but after the i2c bus
setup which happens during the subsys_initcall phase.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I23292b224a08b4d0ca55e39076a41a8ea5a96f82
Reviewed-on: https://chromium-review.googlesource.com/180713
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Make all sst firmware ipc structures packed

The structures that are used to assemble the ipc messages
that go back and forth with the SST firmware all need to be
"__packed" so that they will have the same layout between
32-bit and 64-bit compilations.  This patch makes that
change for the ones that were missed.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'a 237-hz wav file

Change-Id: I4dc5a883deabf8a3e66f88537fa20bcd80f6e685
Reviewed-on: https://chromium-review.googlesource.com/180714
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Make audio driver fw ipc address-passing 64-bit safe

The LPE audio driver was using kzalloc() to allocate a
memory block to pass to the 32-bit firmware for saving and
restoring firmware context on device-suspend and
device-resume.  It was also using virt_to_phys() to convert
the CPU-type pointer to a 32-bit address to be used by the
firmware.  This approach is not safe in a system where
memory could be dynamically page-mapped, or reside beyond
the 4G (32-bit) boundary.

Accordingly, this patch re-writes the allocation for this
memory block using dma_zalloc_coherent() with suitable flags
to restrict the allocation to 32-bit accessible physical
memory address range.  The 32-bit address is retrieved as
part of the allocation.

This also fixes a memory leak in the allocation failure
handling logic in the probe procedure.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'
insert WARN(), play sound, suspend/resume, play sound

Change-Id: I593737a3a29c000235ab56e21312f70ca868f21a
Reviewed-on: https://chromium-review.googlesource.com/180715
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: Fix warnings in intel_sst_ and intel_mid_dma

Signed-off-by: Benson Leung <bleung@chromium.org>

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'
Make sure that a 64-bit build on kernel-3_10 for rambi builds without
warnings.

Change-Id: I0988cbcfed9c1f3d92f38447271f5c1eef0f555f
Reviewed-on: https://chromium-review.googlesource.com/180716
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: LPE: Eliminate non-portable virt_to_phys in sst_pcm_new

The standard model for a <xxx>_pcm_new procedure is to use
dma-coherent allocation, and then use the resulting virtual
address for CPU access to the memory and the (suitable cast)
resulting dma addr for the physical address.  This patch
changes the sst_pcm_new procedure and subsequent use of
allocated memory to use that standard model instead of using
non-portable virt_to_phys to translate CPU-access pointer to
physical-address reference for the DSP.

This change leaves two remaining virt_to_phys() references
in sound/soc/mid-x86/ directory structure.  These are used
in referencing a ring-buffer used to push data to a
compression module.  The object in question is a (struct
snd_compr_stream *)->runtime->buffer, which is allocated by
sound/soc core procedure using kmalloc() with no option to
use dma-coherent allocation.

It would take an extensive implementation around the
snd_compr_ops.copy() operation to fix this.  The impetus to
fix this would be the debate whether the kmalloc() followed
by virt_to_phys() usage is portable for all future time
across all platforms.  It doesn't look like this will be a
problem for the forseeable future on x86 platforms, and the
code in question has other x86-specific characteristics, so
it did not seem worthwhile to tackle these remaining
virt_to_phys() in this patch.

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: Id9b343b6ce7aee7386be9bf00a1813c7f8bc153c
Reviewed-on: https://chromium-review.googlesource.com/180717
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
CHROMIUM: [MUST_REVERT] LPE: Remove request_irq call from max98090 codec

Why is this attempt to request an IRQ failing?  Don't know.
Just remove it for now.

[bleung : comment out the interrupt function entirely to build without
 warnings]

BUG=chrome-os-partner:24118
TEST=aplay -l
     # lists 'baytrailaudio'

Change-Id: I971ce404fe42b7ea594c115bd5ea798439487e19
Reviewed-on: https://chromium-review.googlesource.com/180718
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>