CRAS: alsa_jack - Create gpio jacks on first input/output device

We used to create gpio jacks only on device 0 of a card. This does
not work for Samus since there are two front end DAIs:
device 0: System Playback (CRAS_STREAM_OUTPUT)
device 1: Capture (CRAS_STREAM_INPUT)

With this patch, headphone/HDMI gpio jacks are created and attached
to the first output device of a card. Mic gpio jacks are created and
attached to the first input device of a card.

BUG=chrome-os-partner:29649
TEST=On Samus bdw-rt5677 Mic Jack appears with this patch

Change-Id: I87ad98c7605a7855af86bfaaec8425c02a89427d
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220591
UCM config: Add UCM config for Ryu

This contains basic initialization:
AIF1 Playback -> PDM1 (speakers)
AIF1 Playback -> OUT1/OUT2 (headphones)
DMIC1 -> AIF1 Capture
IN1P/IN1N -> AIF1 Capture

Default config:
playback to speakers
capture from DMICs

Headphone plugged in:
playback to headphone; speaker disabled

Analog mic plugged in:
capture from analog mic; DMICs disabled

BUG=chrome-os-partner:30793
TEST=tested playback to speaker/mic jack, capture from dmic/mic

Change-Id: Ia27790f6c0afea07461e1a85e69a18875c796f18
Signed-off-by: Anatol Pomazau <anatol@google.com>
Reviewed-on: https://chromium-review.googlesource.com/221432
Reviewed-by: Dylan Reid <dgreid@chromium.org>
CRAS: Builds software volume scalers from volume curve.

This change creates software volume scalers according to the volume
curve defined in card config files, and thus produces similar volume
at each level when using software volume for the device.

BUG=chromium:407957
TEST=1. make && make check
     2. Tested on peppy with USB speaker, USB headphone, and HDMI output.

Change-Id: I93ad0c81484305a0db734fefc69c1a41bd6c5550
Reviewed-on: https://chromium-review.googlesource.com/221400
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
CRAS: audio_thread - Handle dev error while appending stream

If there is a device error while appending a stream to the device,
return an error from append_stream_to_dev and handle it in
append_stream.  This will ensure that the stream lands on the fallback
device and that the fallback device is initialized.  Before it could
be dropped and the fallback device could be left uninitialized.

BUG=chromium:425286
TEST=select device, open it with aplay -Dhw to generate an error and
play a new stream.

Change-Id: I51c485973934de9ef7b629ab438af9a73fd53fb8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224476
CRAS: update minimum alsa version.

27 or later is needed for quering chmaps.

BUG=none
TEST=compiles

Change-Id: I679f4ca9f801c1c4b50b75c53fe8b6067a21ddba
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224523
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
UCM config: Samus: rename IF1 Slot01 Swap kcontrol

In rt5677 codec driver, the kcontrol 'IF1 Slot01 Swap' has
been renamed to 'IF1 ADC1 Swap Mux'

BUG=none
TEST=arecord from external mic still has sound in both left and
right channels on Samus
CQ-DEPEND=CL:224801

Change-Id: Idba338b086b234ed8bc244a1471bbdf5f9ffc675
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224784
Reviewed-by: Anatol Pomazau <anatol@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
CRAS: fmt_conv - Fix a bug in sample format conversion

BUG=chromium:425715
TEST=None

Change-Id: Ia2dc2cad0e655d2115a092cd1626afd274ec4748
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224627
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: client - Remove fmt_conv from client

cras_rclient always accepts the format requested by client
and the format conversion has been moved to server side.
Remove all the fmt_conv code from cras_client.

BUG=chromium:420589
TEST=unittest

Change-Id: I018aeff8aa531e4daa6e3812bdaac53a3e28a514
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224625
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: move fmt_conv from common to server

fmt_conv will be integrated with the modules in
server side.

BUG=chromium:420589
TEST=None

Change-Id: I92abdaf3306e1ede4c5449ceed86543075f96cba
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224626
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: iodev - Get estimate rate ratio

Change the getter to return the ratio of estimated rate and
the rate device is claimed to use. In later changes when we
align an active device to the rate of the master active device.
Using this ratio will make the code simpler as opposed to using
the estimate rate value directly.

BUG=chromium:420589
TEST=None

Change-Id: Ib6109ed86c06379dcfb8371d1189b3f28a78315f
Reviewed-on: https://chromium-review.googlesource.com/224624
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
UCM: Ryu: Adopt configuration for recent upstream changes

'ADC1 TDM Channel' switch was renamed to 'IF1 ADC TDM Swap Mux'

BUG=chrome-os-partner:30793
TEST=Speaker playback with aplay

Change-Id: Ifed4b14e53c03e2ae3290864b9e010fd39f9f375
Reviewed-on: https://chromium-review.googlesource.com/224995
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Anatol Pomazau <anatol@google.com>
Commit-Queue: Anatol Pomazau <anatol@google.com>
Tested-by: Anatol Pomazau <anatol@google.com>
CRAS: iodev_list - Don't just drop system mute/volume events.

This code got dropped when multiple active inputs and outputs were
added.  Put it back in and apply system level changes to all active
devices of the appropriate direction.

BUG=chromium:425591
TEST=suspend falco, plug headset, resume.

Change-Id: I343bc8d98ce6851414dbcaba8bc28f2345f02f10
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/224585
UCM: Ryu: Mix L+R and output to L channel

Ryu P1 has mono speaker, ssm4567 output Left channel of stereo.
To play both channels we need to mix both stereo channel and output
to the left one.

Unfortunately LR mixer is available on Stereo2 path that is currently used by DMIC.
used Stereo1 for DMIC path, and Stereo2 for AIF1->AIF2 (speaker).

BUG=chrome-os-partner:30793
TEST=stereo clip and make sure both channels are audible

Change-Id: Ie7b7e66ee86d62d1212151d5f9ada356b3f1e498
Reviewed-on: https://chromium-review.googlesource.com/225249
Reviewed-by: Anatol Pomazau <anatol@google.com>
Commit-Queue: Anatol Pomazau <anatol@google.com>
Tested-by: Anatol Pomazau <anatol@google.com>
cras-config: Paine: add paine cras configuration files

This is a clone of the Auron configuration.

BUG=none
TEST=check if audio works

Change-Id: I9a2245a0564cd63bdf26afb90607724c6843eedb
Reviewed-on: https://chromium-review.googlesource.com/225335
Reviewed-by: Kevin Cheng <kevin.cheng@intel.com>
Reviewed-by: Yung Leem <yungleem@chromium.org>
Commit-Queue: Grace Kao <grace.kao@intel.com>
Tested-by: Grace Kao <grace.kao@intel.com>
ucm-config: Paine: add paine ucm config files

This is a clone of the auron configuration.

BUG=none
TEST=listen for audio

Change-Id: Ic4ef28404b5c5d172ab0e38153d37335e6cedcc3
Reviewed-on: https://chromium-review.googlesource.com/225336
Reviewed-by: Kevin Cheng <kevin.cheng@intel.com>
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Grace Kao <grace.kao@intel.com>
Tested-by: Grace Kao <grace.kao@intel.com>
CRAS: audio_thread - Log # fds after wake

There are some reports of wakeups happening way too often.  Log the
number of file descriptors that are ready when waking to aid in
debugging this.

BUG=chromium:424271
TEST=cras_test_client --dump_a | grep '^WAKE:'

Change-Id: I234f5efe4d83627c2400c292a07a4325bb6a5267
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225316
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
CRAS: audio_thread - Log iodev callback.

Add an entry in the audio thread log when an iodev callback is made.
This will aid in determining if an iodev callback is responsible for
waking up the thread too often.

BUG=chromium:424271
TEST=cras_test_client --dump_a | grep '^IODEV_CB:'

Change-Id: Icb54537d6f6a93f59fe8b45ff20772621f973a5f
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225317
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
CRAS: audio_thread - Log playback thread messages.

This will aid in determining why the thread is woken up from the logs.

BUG=chromium:424271
TEST=cras_test_client --dump_a | grep '^PB_MSG:'

Change-Id: I4b561f5c853f4d5f7daccab4439ff9d3a830e324
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225318
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
CRAS: Don't limit frames by offset in capture.

The write point returned from cras_shm_get_writeable_frames needs to
have enough space for the offset and the number of remaining frames.
This many frames will be written starting at offset. For example: an
offset of 60 in to a 100 deep buffer, the pointer will be returned to
the first frame (frame zero), Then 50 frames could be written
beginning at the offset of 60, because the shm only limited based on
its write point which is still at the beginning, so there is room for
50 frames.

cras_audio_area_dopy already handles limiting the total number based
on the offset.

BUG=chromium:427675
TEST=record from two devices at once on Blaze.  Jabra and built-in.

Change-Id: I416fc83d460fe1941c5ae08793fa59611d6e72a9
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225703
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: veyron - add audio configure for rk3288 with max98090

Match to the card device name, create the configure files of "ROCKCHIP-I2S"
for board with rockchip-max98090.

BUG=chrome-os-partner:30167
TEST="boot pinky, start cras
  cras_test_client --add_active_output 3:1
  aplay <file>"

Change-Id: I989a3ec1b58c6df63b26a3c1db6df785df80fcd0
Signed-off-by: xujianqun <xjq@rock-chips.com>
Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217361
Reviewed-by: Dylan Reid <dgreid@chromium.org>