sdm: update panel info immediately after setting display mode

MDP clocks are different between video mode and command mode,
and MDP clocks are calculated and validated in display prepare
stage.
So the panel info needs to be updated immediately for calculation
MDP clocks correctly.
Add IDLE_NOTIFY event in cmd mode for panel operating mode
switch feature.

Change-Id: If9be98078504d66757c32f6159d82799a2e39565
diff --git a/sdm/libs/core/display_builtin.cpp b/sdm/libs/core/display_builtin.cpp
index 25af21e..26e89a9 100644
--- a/sdm/libs/core/display_builtin.cpp
+++ b/sdm/libs/core/display_builtin.cpp
@@ -90,6 +90,7 @@
   if (hw_panel_info_.mode == kModeCommand) {
     event_list_ = {HWEvent::VSYNC,
                    HWEvent::EXIT,
+                   HWEvent::IDLE_NOTIFY,
                    HWEvent::SHOW_BLANK_EVENT,
                    HWEvent::THERMAL_LEVEL,
                    HWEvent::IDLE_POWER_COLLAPSE,
@@ -330,6 +331,8 @@
       return error;
     }
 
+    DisplayBase::ReconfigureDisplay();
+
     if (mode == kModeVideo) {
       ControlPartialUpdate(false /* enable */, &pending);
     } else if (mode == kModeCommand) {
diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp
index ed8d372..8baf0a4 100644
--- a/sdm/libs/core/drm/hw_device_drm.cpp
+++ b/sdm/libs/core/drm/hw_device_drm.cpp
@@ -1201,21 +1201,11 @@
   }
 
   // Set panel mode
-  if (panel_mode_changed_) {
-    for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) {
-      if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) &&
-         (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) &&
-         (current_mode.vrefresh == connector_info_.modes[mode_index].mode.vrefresh) &&
-         (panel_mode_changed_ & connector_info_.modes[mode_index].mode.flags)) {
-        current_mode = connector_info_.modes[mode_index].mode;
-        if ((current_mode.flags & DRM_MODE_FLAG_VID_MODE_PANEL) && !validate) {
-          // Switch to video mode, corresponding change the fence_offset
-          drm_atomic_intf_->Perform(DRMOps::CRTC_SET_OUTPUT_FENCE_OFFSET, token_.crtc_id, 1);
-        }
-        break;
-      }
-    }
+  if ((panel_mode_changed_ & DRM_MODE_FLAG_VID_MODE_PANEL) && !validate) {
+    // Switch to video mode, corresponding change the fence_offset
+    drm_atomic_intf_->Perform(DRMOps::CRTC_SET_OUTPUT_FENCE_OFFSET, token_.crtc_id, 1);
   }
+
   if (hw_layers->hw_avr_info.update) {
     sde_drm::DRMQsyncMode mode = sde_drm::DRMQsyncMode::NONE;
     if (hw_layers->hw_avr_info.mode == kContinuousMode) {
@@ -1490,29 +1480,13 @@
     bit_clk_rate_ = 0;
   }
 
-  if (panel_mode_changed_) {
-    drmModeModeInfo current_mode = connector_info_.modes[current_mode_index_].mode;
-    for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) {
-      if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) &&
-          (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) &&
-          (current_mode.vrefresh & connector_info_.modes[mode_index].mode.vrefresh) &&
-          (panel_mode_changed_ & connector_info_.modes[mode_index].mode.flags)) {
-        if (connector_info_.modes[mode_index].mode.flags & DRM_MODE_FLAG_CMD_MODE_PANEL) {
-          hw_panel_info_.mode = kModeCommand;
-          DLOGV_IF(kTagDriverConfig, "switch to command mode done, mode_index = %d\n",
-                    mode_index);
-        }
-        if (connector_info_.modes[mode_index].mode.flags & DRM_MODE_FLAG_VID_MODE_PANEL) {
-          hw_panel_info_.mode = kModeVideo;
-          reset_output_fence_offset_ = true;
-          DLOGV_IF(kTagDriverConfig, "switch to video mode done, mode_index = %d\n", mode_index);
-        }
-        current_mode_index_ = mode_index;
-        break;
-      }
-    }
+   if (panel_mode_changed_ & DRM_MODE_FLAG_CMD_MODE_PANEL) {
     panel_mode_changed_ = 0;
     synchronous_commit_ = false;
+  } else if (panel_mode_changed_ & DRM_MODE_FLAG_VID_MODE_PANEL) {
+    panel_mode_changed_ = 0;
+    synchronous_commit_ = false;
+    reset_output_fence_offset_ = true;
   }
 
   first_cycle_ = false;
@@ -1737,6 +1711,8 @@
         (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) &&
         (current_mode.vrefresh == connector_info_.modes[mode_index].mode.vrefresh) &&
         (mode_flag & connector_info_.modes[mode_index].mode.flags)) {
+      current_mode_index_ = mode_index;
+      PopulateHWPanelInfo();
       panel_mode_changed_ = mode_flag;
       synchronous_commit_ = true;
       return kErrorNone;