sdm: Support external display with bootup

- Register for UEvents before core creation to support bootup
with external connected. Drm driver resends hpd on device open.
- Break on first match config for user selected video format.
- In HPD event, explicitly check for DP string for now.

Change-Id: I18917097c3077fbfcb30cec3ce345487eec03318
CRs-fixed: 2017766
diff --git a/sdm/libs/core/drm/hw_tv_drm.cpp b/sdm/libs/core/drm/hw_tv_drm.cpp
index 2659a32..abebb5e 100644
--- a/sdm/libs/core/drm/hw_tv_drm.cpp
+++ b/sdm/libs/core/drm/hw_tv_drm.cpp
@@ -146,10 +146,12 @@
         (fps == connector_info_.modes[idex].vrefresh)) {
       if ((format >> 1) & (connector_info_.modes[idex].flags >> kBitYUV)) {
         *index = UINT32(idex);
+        break;
       }
 
       if (format & (connector_info_.modes[idex].flags >> kBitRGB)) {
         *index = UINT32(idex);
+        break;
       }
     }
   }
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 272b2f6..41a6b36 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -163,6 +163,8 @@
     return -EINVAL;
   }
 
+  g_hwc_uevent_.Register(this);
+
   error = CoreInterface::CreateCore(HWCDebugHandler::Get(), &buffer_allocator_,
                                     &buffer_sync_handler_, &socket_handler_, &core_intf_);
   if (error != kErrorNone) {
@@ -171,7 +173,6 @@
     return -EINVAL;
   }
 
-  g_hwc_uevent_.Register(this);
 
   // If HDMI display is primary display, defer display creation until hotplug event is received.
   HWDisplayInterfaceInfo hw_disp_info = {};
@@ -1347,25 +1348,37 @@
   }
 }
 
-void HWCSession::HandleExtHPD(const char *uevent_data, int length) {
+const char *GetTokenValue(const char *uevent_data, int length, const char *token) {
   const char *iterator_str = uevent_data;
-  const char *event_info = "status=";
   const char *pstr = NULL;
   while (((iterator_str - uevent_data) <= length) && (*iterator_str)) {
-    pstr = strstr(iterator_str, event_info);
-    if (pstr != NULL) {
+    pstr = strstr(iterator_str, token);
+    if (pstr) {
       break;
     }
     iterator_str += strlen(iterator_str) + 1;
   }
 
+  if (pstr)
+    pstr = pstr+strlen(token);
+
+  return pstr;
+}
+
+void HWCSession::HandleExtHPD(const char *uevent_data, int length) {
+  const char *pstr = GetTokenValue(uevent_data, length, "name=");
+  if (!pstr || (strcmp(pstr, "DP-1") != 0)) {
+    return;
+  }
+
+  pstr = GetTokenValue(uevent_data, length, "status=");
   if (pstr) {
     bool connected = false;
-    if (strcmp(pstr+strlen(event_info), "connected") == 0) {
+    if (strcmp(pstr, "connected") == 0) {
       connected = true;
     }
 
-    DLOGI("Recived Ext HPD, connected:%d  status=%s", connected, pstr+strlen(event_info));
+    DLOGI("Recived Ext HPD, connected:%d  status=%s", connected, pstr);
     HotPlugHandler(connected);
   }
 }