Add the possibility to lock the mute state.

This feature is needed to implement a device policy for muting the sound
input or output on ChromeOS devices.

BUG=chromium-os:11263
TEST=unittest: SystemStateSuite.MuteLocked

Change-Id: Ie9c13d04a9e0a37cfe70aba426064a790f8a0bb7
Reviewed-on: https://gerrit.chromium.org/gerrit/29169
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Ready: Julian Pastarmov <pastarmovj@chromium.org>
Tested-by: Julian Pastarmov <pastarmovj@chromium.org>
HP Max/Min Volume for snow

It makes max volume at 1dB which makes good sound Snow Headphone.
Without this patch, It makes distortion in sign wave

BUG=chrome-os-partner:13604
TEST=check i2c value 0x1b when you go into max volume
     i2cget -y -f 7 0x11 0x65
     check i2c value 0x5 when you go into min volume

Change-Id: I262c564eeaab92d9ab69ace4772f6bbd795039e6
Reviewed-on: https://gerrit.chromium.org/gerrit/32292
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Wonjoon Lee <woojoo.lee@samsung.com>
Commit-Ready: Wonjoon Lee <woojoo.lee@samsung.com>
CRAS: system state UT - fix compile error.

Set but not used error on variable 'rc', fix it by checking the return
value.

BUG=none
TEST=this is a test.

Change-Id: Ibc11870a8a84796129a8129555450b750fdc1eef
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32448
Reviewed-by: Olof Johansson <olofj@chromium.org>
CRAS: Don't print potentially null format.

If there is an error while playing the stream, the alsa device can be
closed and the format can be set to null.  Don't try to dereference and
print it when the stream is removed.

BUG=chromium-os:34236
TEST=Check it isn't printed in syslog.

Change-Id: I2e08d97a59df9ad59f88b67a08707224d06b7457
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32558
Reviewed-by: Olof Johansson <olofj@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: ucm - Fix humpbacked variable.

Why was there one variable humpbacked to begin with??

Change-Id: Ie33d360c04db65207c132fb92c53f9d855fe53ba
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33060
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
CRAS: alsa jack - Attach UCM devices to jacks.

If a ucm device specifies a value of "JackName", then attach the jack
with that name to the device.  This will allow board to configure
arbitrary device enable/disable actions for devices.

BUG=chrome-os-partner:12039
TEST=updated unit tests.

Change-Id: I346cf8797f7c12819ab6deffb34f388465cfb4c6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33061
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
CRAS: alsa jack - Add API to activate ucm device.

If the jack has an associated ucm device, then activate it when the new
cras_alsa_jack_enable_dev api is called.

BUG=chrome-os-partner:12039
TEST=updated unit test

Change-Id: Ic7bd7151d0e16f86e524f48d45620d8206a9167d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33062
CRAS: alsa io - Use new jack/ucm enable function.

When an input or output device is plugged or unplugged, tell the jack to
enable/disable an associated ucm device.  This removes the hardcoded
mapping of input jacks to headset devices, and will allow for EQ
toggling to be done in when Headphones are attached/removed.

BUG=chrome-os-partner:12039
TEST=updated alsa_io_unittest

Change-Id: I321e50b84598dbf9e7c4ca023eb9597ac510c3db
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33063
daisy ucm config - Split mic and headphone, toggle EQ on headphone.

When headphones are plugged in to daisy the EQ must be turned off, and
turned back on when they are unplugged.  Separate this from the mic
device being plugged in.

BUG=chrome-os-partner:12039
TEST=plug/unplug headphones and mic on daisy, make sure alsa controls
toggle.

Change-Id: I013584d9746c059c463215504b822f1af580578a
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33064
Update /etc/asound.state file for butterfly.

The difference is to turn on HDMI output and turn off headphone output.

BUG=chrome-os-partner:12837
TEST=play youtube and plug/unplug HDMI cable

Change-Id: I05315107c85dacbce86fc00738b48d38740e90e1
Reviewed-on: https://gerrit.chromium.org/gerrit/33076
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Ready: Chih-Chung Chang <chihchung@chromium.org>
Update /etc/asound.state file for stout.

Turn on HDMI output: We don't change the setting once initialized
and want to keep it always on.

Turn off headphone output: This should have no visible difference.
Just make the default setting consistent with other machines.

BUG=chrome-os-partner:13850
TEST=play youtube when HDMI cable is connected

Change-Id: Ie8bd5ed8a74c5027d1609e954de635c485c2dcfb
Reviewed-on: https://gerrit.chromium.org/gerrit/33194
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
daisy asount.state - configure EQ controls.

Configure the EQ settings for snow.

BUG=chrome-os-partner:12039
TEST=plug/unplug headphone jack while playing youtube.

Change-Id: I3a17738b0dbfbd9636aa1a2d079274a0aa7d5abb
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33377
CRAS: Temproary fix for AEC on existing products.

Partially revert 1fc1754c3d777cbfb59c967402cf4050ccf2111b, this commit
causes the AEC to malfunction on at least lumpy and probably most x86
platforms.  We need the change for Link, but must figure out what was
causing problems on existing platforms first.

BUG=chromium-os:34566
TEST=Gtalk with a lumpy listen for echo.

Change-Id: I43a7efa43ea10d8b0b34ecadf8fa21a7a98372dd
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33701
link asount.state and ucm config - toggle DSP on headphone/mic (un)plug.

Add a UCM config for link. Toggle DSP controls when headphone and mic
are plugged/unplugged.

We don't want to use the DSP effects for headphone output, and the input
blocks we want to run are different when using an external mic.

Change the asound.state to use the configuration we want when
headphone/mic is unplugged.

BUG=chrome-os-partner:14154
TEST=use alsamixer -c 0 to verify the setting are changed when headphone is
plugged/unplugged.

Change-Id: I9ac27208267e2fb0993e2c10780e8cd12508ce10
Reviewed-on: https://gerrit.chromium.org/gerrit/33775
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Ready: Chih-Chung Chang <chihchung@google.com>
Tested-by: Chih-Chung Chang <chihchung@google.com>
CRAS: sys state - Track the number of active streams.

Keep a count of the number of audio streams attached to the server.
This requires adding a lock, as streams can be removed from the audio
threads if they report an error.  Also track the time the last thread is
removed from the system.  This timestamp will be used by the power
manager to measure how long audio has been idle.

BUG=chromium-os:32500
TEST=updated system_state_unittest

Change-Id: Ifa9e1294713eebeac28e6cdffabe9cd770edb5c9
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32449
CRAS: client - export the active stream count to clients.

Add access functions to the count of streams active on the server.  This
API will be used by the power manager to detect if audio is active.

BUG=chromium-os:32500
TEST=cras_test_client --dumpe_server_info

Change-Id: Ie61bfe5da17e34a88973ec513e5490d4f9b2836e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32450
CRAS: rclient - remove dead code.

Nothing checks if any streams have been played anymore, remove the
function that checked, and increment the counter with the active stream
count instead.

BUG=none.
TEST=updated unit-tests

Change-Id: I652a94dfb162448eac50af6a03900efbdd4787a2
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32451
CRAS: alsa card - Check return code of next_device.

snd_pcm_next_device can return an error code.  This happens if you
unplug a device while we are enumerating the devices.

BUG=chrome-os-partner:13371
TEST=updated ut, plug/unplug USB speakers rapidly.

Change-Id: Ie935a23ef9b86b168c5ec77b467a345a150acbc6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33126
CRAS: gpio jack - Check that jacks match the card.

GPIO jacks were being added to all cards in the system.  Luckily the
name of the card is pre-pended to the name of the jack, so it is easy to
check if the card name is passed in to the jack creation routine.

Remember to close the gpio fd when destroying the jack list.

BUG=chromium-os:34375
TEST=update UT, plug headphones while playing to USB, check system
doesn't hang.

Change-Id: Ibca79e382fa78e986a91813ad1c57ad7834a3938
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33141
CRAS: alsa - handle EPIPE from avail_frames.

If the system is suspended, then next time avail_frames is called will
return EPIPE(usb) or ESTRPIPE(non-usb).  Attempt resume in that case.

BUG=chrome-os-partner:12822
TEST=suspend/resume whiel playing audio to USB speakers.

Change-Id: Ic3a09e8ab67cbb2aa271ac0b4f6d2b4e1e4cbbb9
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33562
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>