summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCecilia Hung <ceciliahung@google.com>2023-06-01 05:23:11 +0000
committerCecilia Hung <ceciliahung@google.com>2023-06-01 13:12:53 +0000
commit95e20d524817a4283d24b9ce7271890d18c319f8 (patch)
tree31ce1277d97312fdd5102e2c4f9606c3401362bc
parentbfd0a7afd15981e25bd1ceba3f6f5c36e3fe6012 (diff)
downloadmcu_mic_codec-android-msm-eos-5.15-tm-wear-kr3-dr-eos.tar.gz
mcu_mic_codec: Save intended value for hotword status and activity stopandroid-wear-13.0.0_r0.3android-msm-eos-5.15-tm-wear-kr3-dr-eos
Test: Manual testing that the intended settings are saved even if the send to MCU fails Bug: 271166024 Change-Id: If3d61db2759f4ac83bd6bdb186787efac0a69c16 Signed-off-by: Cecilia Hung <ceciliahung@google.com>
-rw-r--r--mcu_mic_codec.c57
1 files changed, 38 insertions, 19 deletions
diff --git a/mcu_mic_codec.c b/mcu_mic_codec.c
index 747e629..b90a791 100644
--- a/mcu_mic_codec.c
+++ b/mcu_mic_codec.c
@@ -306,17 +306,25 @@ static int dmic_mcu_on_put(struct snd_kcontrol *kcontrol,
codec_data->pending_rec = DMIC_MCU_ON_OFF;
}
+ if (value == DMIC_MCU_ON_ON) {
+ // Clear Activity Stop status since framework has sent DMIC_MCU_ON_ON
+ // regardless if the actual sent succeed or not. Reasoning is this
+ // saved flag is only used to notify MCU if MCU crashes, and we want
+ // to use the framework's intended state in restoring MCU after the
+ // crash.
+ codec_data->activity_stop_sent = false;
+ }
+
ret = dmic_mcu_send_message(component->dev, DMIC_MCU_MESSAGE_MIC_ON, value);
- if (ret != 0)
+ if (ret != 0) {
+ dev_err(component->dev,
+ "Error sending DMIC_MCU_MESSAGE_MIC_ON: %d", ret);
+ ret = -EIO;
goto end;
+ }
codec_data->mic_on = value;
- if (value == DMIC_MCU_ON_ON) {
- // Clear Activity Stop status since DMIC_MCU_ON_ON has been applied
- codec_data->activity_stop_sent = false;
- }
-
dev_info(component->dev, "%s: new mcu_mic_on: %d\n",
__func__, codec_data->mic_on);
@@ -351,21 +359,27 @@ static int dmic_mcu_hw_enabled_put(struct snd_kcontrol *kcontrol,
struct mcu_mic_codec_data *codec_data =
snd_soc_component_get_drvdata(component);
int value = ucontrol->value.integer.value[0];
- int ret;
+ int ret = 0;
dev_dbg(component->dev, "%s\n", __func__);
- ret = dmic_mcu_send_message(component->dev, DMIC_MCU_MESSAGE_HOTWORD_STATUS, value);
- if (ret != 0)
- return ret;
-
+ // Save HW Enable Status regardless if actual send to MCU succeed or
+ // not. Reasoning is this saved flag is only used to notify MCU if MCU
+ // crashes, and we want to use the framework's intended state in restoring
+ // MCU after the crash.
mutex_lock(&codec_data->iolock);
codec_data->hw_enabled = value;
dev_info(component->dev, "%s: mcu_mc_hw_enabled: %d\n",
__func__, codec_data->hw_enabled);
mutex_unlock(&codec_data->iolock);
- return 0;
+ ret = dmic_mcu_send_message(component->dev, DMIC_MCU_MESSAGE_HOTWORD_STATUS, value);
+ if (ret != 0) {
+ dev_err(component->dev,
+ "Error sending DMIC_MCU_MESSAGE_HOTWORD_STATUS: %d", ret);
+ ret = -EIO;
+ }
+ return ret;
}
static int dmic_mcu_activity_stop_get(struct snd_kcontrol *kcontrol,
@@ -392,22 +406,27 @@ static int dmic_mcu_activity_stop_put(struct snd_kcontrol *kcontrol,
snd_soc_kcontrol_component(kcontrol);
struct mcu_mic_codec_data *codec_data =
snd_soc_component_get_drvdata(component);
- int ret;
+ int ret = 0;
dev_dbg(component->dev, "%s\n", __func__);
- ret = dmic_mcu_send_message(component->dev, DMIC_MCU_MESSAGE_ACTIVITY_STOP, 1);
- if (ret != 0)
- return ret;
-
- // Set the flag that ActivityStop has been sent since flag was cleared last time
+ // Save ActivityStop as true regardless if actual send to MCU succeed or
+ // not. Reasoning is this saved flag is only used to notify MCU if MCU
+ // crashes, and we want to use the framework's intended state in restoring
+ // MCU after the crash.
mutex_lock(&codec_data->iolock);
codec_data->activity_stop_sent = true;
dev_info(component->dev, "%s: mcu_mic_activity_stop: %d\n",
__func__, codec_data->activity_stop_sent);
mutex_unlock(&codec_data->iolock);
- return 0;
+ ret = dmic_mcu_send_message(component->dev, DMIC_MCU_MESSAGE_ACTIVITY_STOP, 1);
+ if (ret != 0) {
+ dev_err(component->dev,
+ "Error sending DMIC_MCU_MESSAGE_ACTIVITY_STOP: %d", ret);
+ ret = -EIO;
+ }
+ return ret;
}