sdm: Configure DP/DTV port based on the connection status.

1. Parse the connection status of each fb node on HDMI connection and
   configure DP/DTV port.
2. Enable HPD for all the pluggable displays.

Change-Id: I0e410f82660e30174068fd4e397771cea90d34b6
CRs-Fixed: 1055148
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index f75e92a..3d5cb78 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -737,7 +737,7 @@
 }
 
 int HWDevice::GetFBNodeIndex(HWDeviceType device_type) {
-  for (int i = 0; i <= kDeviceVirtual; i++) {
+  for (int i = 0; i < kFBNodeMax; i++) {
     HWPanelInfo panel_info;
     GetHWPanelInfoByNode(i, &panel_info);
     switch (device_type) {
@@ -748,7 +748,9 @@
       break;
     case kDeviceHDMI:
       if (panel_info.is_pluggable == true) {
-        return i;
+        if (IsFBNodeConnected(i)) {
+          return i;
+        }
       }
       break;
     case kDeviceVirtual:
@@ -990,17 +992,20 @@
 
 bool HWDevice::EnableHotPlugDetection(int enable) {
   char hpdpath[kMaxStringLength];
-  int hdmi_node_index = GetFBNodeIndex(kDeviceHDMI);
-  if (hdmi_node_index < 0) {
-    return false;
-  }
-
-  snprintf(hpdpath , sizeof(hpdpath), "%s%d/hpd", fb_path_, hdmi_node_index);
-
   char value = enable ? '1' : '0';
-  ssize_t length = SysFsWrite(hpdpath, &value, sizeof(value));
-  if (length <= 0) {
-    return false;
+
+  // Enable HPD for all pluggable devices.
+  for (int i = 0; i < kFBNodeMax; i++) {
+    HWPanelInfo panel_info;
+    GetHWPanelInfoByNode(i, &panel_info);
+    if (panel_info.is_pluggable == true) {
+      snprintf(hpdpath , sizeof(hpdpath), "%s%d/hpd", fb_path_, i);
+
+      ssize_t length = SysFsWrite(hpdpath, &value, sizeof(value));
+      if (length <= 0) {
+        return false;
+      }
+    }
   }
 
   return true;
@@ -1165,6 +1170,23 @@
   return len;
 }
 
+bool HWDevice::IsFBNodeConnected(int fb_node) {
+  string file_name = fb_path_ + to_string(fb_node) + "/connected";
+
+  Sys::fstream fs(file_name, fstream::in);
+  if (!fs.is_open()) {
+    DLOGW("File not found %s", file_name.c_str());
+    return false;
+  }
+
+  string line;
+  if (!Sys::getline_(fs, line)) {
+    return false;
+  }
+
+  return atoi(line.c_str());
+}
+
 DisplayError HWDevice::SetS3DMode(HWS3DMode s3d_mode) {
   return kErrorNotSupported;
 }
diff --git a/sdm/libs/core/fb/hw_device.h b/sdm/libs/core/fb/hw_device.h
index 8916dc4..5543b48 100644
--- a/sdm/libs/core/fb/hw_device.h
+++ b/sdm/libs/core/fb/hw_device.h
@@ -100,6 +100,9 @@
 
   static const int kMaxStringLength = 1024;
   static const int kNumPhysicalDisplays = 2;
+  // This indicates the number of fb devices created in the driver for all interfaces. Any addition
+  // of new fb devices should be added here.
+  static const int kFBNodeMax = 4;
 
   void DumpLayerCommit(const mdp_layer_commit &layer_commit);
   DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target);
@@ -127,6 +130,7 @@
 
   bool EnableHotPlugDetection(int enable);
   ssize_t SysFsWrite(const char* file_node, const char* value, ssize_t length);
+  bool IsFBNodeConnected(int fb_node);
 
   HWResourceInfo hw_resource_;
   HWPanelInfo hw_panel_info_;
diff --git a/sdm/libs/core/fb/hw_info.cpp b/sdm/libs/core/fb/hw_info.cpp
index 81d81a3..121b7c0 100644
--- a/sdm/libs/core/fb/hw_info.cpp
+++ b/sdm/libs/core/fb/hw_info.cpp
@@ -516,7 +516,8 @@
     return kErrorHardware;
   }
 
-  if (!strncmp(line.c_str(), "dtv panel", strlen("dtv panel"))) {
+  if (!strncmp(line.c_str(), "dtv panel", strlen("dtv panel")) ||
+      !strncmp(line.c_str(), "dp panel", strlen("dp panel"))) {
     hw_disp_info->type = kHDMI;
     DLOGI("First display is HDMI");
   } else {