summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTzung-Bi Shih <tzungbi@chromium.org>2019-05-17 11:22:53 +0800
committerCommit Bot <commit-bot@chromium.org>2019-09-17 14:56:58 +0000
commit0ba3ba3049226e92d6cf64ed06031ec9a3bb7949 (patch)
treeb4f3aff83258c93042ad2b3a02bda7f2f50e3af3 /common
parentbb5d21d349efbc12fa5596a811a241508621e64d (diff)
downloadchrome-ec-0ba3ba3049226e92d6cf64ed06031ec9a3bb7949.tar.gz
audio_codec: add DMIC abstract layer
Common DMIC host commands: - get_max_gain - get_gain_idx - set_gain_idx 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. make BOARD=kukui_scp -j Change-Id: I7b4cc11645675f9d790947b17c3ea385dae13483 Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1564502 Commit-Queue: Sean Abraham <seanabraham@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/audio_codec_dmic.c77
-rw-r--r--common/build.mk1
2 files changed, 78 insertions, 0 deletions
diff --git a/common/audio_codec_dmic.c b/common/audio_codec_dmic.c
new file mode 100644
index 0000000000..461b8508e9
--- /dev/null
+++ b/common/audio_codec_dmic.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "audio_codec.h"
+#include "console.h"
+#include "host_command.h"
+
+#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ## args)
+
+static int dmic_get_max_gain(struct host_cmd_handler_args *args)
+{
+ struct ec_response_ec_codec_dmic_get_max_gain *r = args->response;
+
+ if (audio_codec_dmic_get_max_gain(&r->max_gain) != EC_SUCCESS)
+ return EC_RES_ERROR;
+
+ args->response_size = sizeof(*r);
+ return EC_RES_SUCCESS;
+}
+
+static int dmic_set_gain_idx(struct host_cmd_handler_args *args)
+{
+ const struct ec_param_ec_codec_dmic *p = args->params;
+
+ if (audio_codec_dmic_set_gain_idx(
+ p->set_gain_idx_param.channel,
+ p->set_gain_idx_param.gain) != EC_SUCCESS)
+ return EC_RES_ERROR;
+
+ return EC_RES_SUCCESS;
+}
+
+static int dmic_get_gain_idx(struct host_cmd_handler_args *args)
+{
+ const struct ec_param_ec_codec_dmic *p = args->params;
+ struct ec_response_ec_codec_dmic_get_gain_idx *r = args->response;
+
+ if (audio_codec_dmic_get_gain_idx(
+ p->get_gain_idx_param.channel, &r->gain) != EC_SUCCESS)
+ return EC_RES_ERROR;
+
+ args->response_size = sizeof(*r);
+ return EC_RES_SUCCESS;
+}
+
+static int (*sub_cmds[])(struct host_cmd_handler_args *) = {
+ [EC_CODEC_DMIC_GET_MAX_GAIN] = dmic_get_max_gain,
+ [EC_CODEC_DMIC_SET_GAIN_IDX] = dmic_set_gain_idx,
+ [EC_CODEC_DMIC_GET_GAIN_IDX] = dmic_get_gain_idx,
+};
+
+#ifdef DEBUG_AUDIO_CODEC
+static char *strcmd[] = {
+ [EC_CODEC_DMIC_GET_MAX_GAIN] = "EC_CODEC_DMIC_GET_MAX_GAIN",
+ [EC_CODEC_DMIC_SET_GAIN_IDX] = "EC_CODEC_DMIC_SET_GAIN_IDX",
+ [EC_CODEC_DMIC_GET_GAIN_IDX] = "EC_CODEC_DMIC_GET_GAIN_IDX",
+};
+BUILD_ASSERT(ARRAY_SIZE(sub_cmds) == ARRAY_SIZE(strcmd));
+#endif
+
+static int dmic_host_command(struct host_cmd_handler_args *args)
+{
+ const struct ec_param_ec_codec_dmic *p = args->params;
+
+#ifdef DEBUG_AUDIO_CODEC
+ CPRINTS("DMIC subcommand: %s", strcmd[p->cmd]);
+#endif
+
+ if (p->cmd < EC_CODEC_DMIC_SUBCMD_COUNT)
+ return sub_cmds[p->cmd](args);
+
+ return EC_RES_INVALID_PARAM;
+}
+DECLARE_HOST_COMMAND(EC_CMD_EC_CODEC_DMIC, dmic_host_command, EC_VER_MASK(0));
diff --git a/common/build.mk b/common/build.mk
index 213db0a0fc..8398434b47 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -30,6 +30,7 @@ common-$(CONFIG_CMD_ADC)+=adc.o
common-$(HAS_TASK_ALS)+=als.o
common-$(CONFIG_AP_HANG_DETECT)+=ap_hang_detect.o
common-$(CONFIG_AUDIO_CODEC)+=audio_codec.o
+common-$(CONFIG_AUDIO_CODEC_DMIC)+=audio_codec_dmic.o
common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
common-$(CONFIG_BASE32)+=base32.o
common-$(CONFIG_DETACHABLE_BASE)+=base_state.o