hal: update the notification of HDMI/DisplayPort connection

Update the notification mechanism of HDMI/DisplayPort cable
Connection/disconnect between audio and display driver.

Change-Id: I484f52c13ecddec7638261cad11394b362677763
CRs-Fixed: 2003481
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index c9d3cf8..bc722f8 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -180,6 +180,41 @@
     return ret;
 }
 
+static int update_audio_ack_state(const struct audio_device *adev, int node_value)
+{
+    const char *mixer_ctl_name = "External Display Audio Ack";
+    struct mixer_ctl *ctl;
+    int ret = 0;
+
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    /* If no mixer command support, fall back to sysfs node approach */
+    if (!ctl) {
+        ALOGI("%s: could not get ctl for mixer cmd(%s), use sysfs node instead\n",
+              __func__, mixer_ctl_name);
+        ret = update_ext_disp_sysfs_node(adev, node_value);
+    } else {
+        char *ack_str = NULL;
+
+        if (node_value == EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE)
+            ack_str = "Ack_Enable";
+        else if (node_value == 1)
+            ack_str = "Connect";
+        else if (node_value == 0)
+            ack_str = "Disconnect";
+        else {
+            ALOGE("%s: Invalid input parameter - 0x%x\n",
+                  __func__, node_value);
+            return -EINVAL;
+        }
+
+        ret = mixer_ctl_set_enum_by_string(ctl, ack_str);
+        if (ret)
+            ALOGE("%s: Could not set ctl for mixer cmd - %s ret %d\n",
+                  __func__, mixer_ctl_name, ret);
+    }
+    return ret;
+}
+
 static void audio_extn_ext_disp_set_parameters(const struct audio_device *adev,
                                                      struct str_parms *parms)
 {
@@ -192,13 +227,13 @@
         if (is_hdmi_sysfs_node_init == false) {
             //check if this is different for dp and hdmi
             is_hdmi_sysfs_node_init = true;
-            update_ext_disp_sysfs_node(adev, EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE);
+            update_audio_ack_state(adev, EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE);
         }
-        update_ext_disp_sysfs_node(adev, 1);
+        update_audio_ack_state(adev, 1);
     } else if(str_parms_get_str(parms, "disconnect", value, sizeof(value)) >= 0
             && (atoi(value) & AUDIO_DEVICE_OUT_AUX_DIGITAL)){
         //params = "disconnect=1024" for external display disconnection.
-        update_ext_disp_sysfs_node(adev, 0);
+        update_audio_ack_state(adev, 0);
         ALOGV("invalidate cached edid");
         platform_invalidate_hdmi_config(adev->platform);
     } else {