summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzung-Bi Shih <tzungbi@chromium.org>2019-06-28 13:41:24 +0800
committerCommit Bot <commit-bot@chromium.org>2019-09-17 14:56:59 +0000
commit6a159855aae92c3d98a4927babb4a8319d644c1e (patch)
tree58ddc25322bdeb245370c0d3fdfc4cef58ee9cf0
parent0ba3ba3049226e92d6cf64ed06031ec9a3bb7949 (diff)
downloadchrome-ec-6a159855aae92c3d98a4927babb4a8319d644c1e.tar.gz
audio_codec: support software gain
Chip or board can define a scaler for software gain for up to 8 channels. BRANCH=none BUG=b:122027734, b:123268236 TEST=1. define CONFIG_AUDIO_CODEC in board.h 2. define CONFIG_AUDIO_CODEC_DMIC in board.h 3. define CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN in board.h 4. define CONFIG_AUDIO_CODEC_DMIC_MAX_SOFTWARE_GAIN in board.h 5. make BOARD=kukui_scp -j Change-Id: I38418ca9bda7973f35d35947a55cad8180eb4df0 Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1683027 Commit-Queue: Sean Abraham <seanabraham@chromium.org> Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r--common/audio_codec_dmic.c30
-rw-r--r--include/config.h3
2 files changed, 33 insertions, 0 deletions
diff --git a/common/audio_codec_dmic.c b/common/audio_codec_dmic.c
index 461b8508e9..986451650e 100644
--- a/common/audio_codec_dmic.c
+++ b/common/audio_codec_dmic.c
@@ -75,3 +75,33 @@ static int dmic_host_command(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
DECLARE_HOST_COMMAND(EC_CMD_EC_CODEC_DMIC, dmic_host_command, EC_VER_MASK(0));
+
+#ifdef CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN
+static uint8_t channel_gains[EC_CODEC_DMIC_CHANNEL_COUNT];
+
+int audio_codec_dmic_get_max_gain(uint8_t *gain)
+{
+ *gain = CONFIG_AUDIO_CODEC_DMIC_MAX_SOFTWARE_GAIN;
+ return EC_SUCCESS;
+}
+
+int audio_codec_dmic_set_gain_idx(uint8_t channel, uint8_t gain)
+{
+ if (channel >= ARRAY_SIZE(channel_gains))
+ return EC_ERROR_INVAL;
+ if (gain > CONFIG_AUDIO_CODEC_DMIC_MAX_SOFTWARE_GAIN)
+ return EC_ERROR_INVAL;
+
+ channel_gains[channel] = gain;
+ return EC_SUCCESS;
+}
+
+int audio_codec_dmic_get_gain_idx(uint8_t channel, uint8_t *gain)
+{
+ if (channel >= ARRAY_SIZE(channel_gains))
+ return EC_ERROR_INVAL;
+
+ *gain = channel_gains[channel];
+ return EC_SUCCESS;
+}
+#endif
diff --git a/include/config.h b/include/config.h
index b39196140a..207410cc92 100644
--- a/include/config.h
+++ b/include/config.h
@@ -354,6 +354,9 @@
#undef CONFIG_AUDIO_CODEC
/* Support audio codec on DMIC. */
#undef CONFIG_AUDIO_CODEC_DMIC
+/* Support audio codec software gain on DMIC. */
+#undef CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN
+#undef CONFIG_AUDIO_CODEC_DMIC_MAX_SOFTWARE_GAIN
/* Allow proprietary communication protocols' extensions. */
#undef CONFIG_EXTENSION_COMMAND