sdm: Panel name retrieval support

Change-Id: I4f4d4ace0022dedcc4e8deecbf47b99f1e518e24
diff --git a/sdm/include/private/color_params.h b/sdm/include/private/color_params.h
index a34d84c..2a261ee 100644
--- a/sdm/include/private/color_params.h
+++ b/sdm/include/private/color_params.h
@@ -30,6 +30,7 @@
 #ifndef __COLOR_PARAMS_H__
 #define __COLOR_PARAMS_H__
 
+#include <stdio.h>
 #include <string.h>
 #include <utils/locker.h>
 #include <utils/constants.h>
@@ -105,20 +106,11 @@
 };
 
 struct PPHWAttributes : HWResourceInfo, HWPanelInfo, DisplayConfigVariableInfo {
-  const char *panel_name = "generic_panel";  // TODO(user):  Add into HWPanelInfo
-                                             // to retrieve panel_name from HW.
+  char panel_name[256] = "generic_panel";
   PPFeatureVersion version;
 
-  inline void Set(const HWResourceInfo &hw_res, const HWPanelInfo &panel_info,
-                  const DisplayConfigVariableInfo &attr, const PPFeatureVersion &feature_ver) {
-    HWResourceInfo &res = *this;
-    res = hw_res;
-    HWPanelInfo &panel = *this;
-    panel = panel_info;
-    DisplayConfigVariableInfo &attributes = *this;
-    attributes = attr;
-    version = feature_ver;
-  }
+  void Set(const HWResourceInfo &hw_res, const HWPanelInfo &panel_info,
+           const DisplayConfigVariableInfo &attr, const PPFeatureVersion &feature_ver);
 };
 
 struct PPDisplayAPIPayload {
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 6aa7eab..164d438 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -134,6 +134,7 @@
   uint32_t max_fps = 0;               // Max fps supported by panel
   bool is_primary_panel = false;      // Panel is primary display
   HWSplitInfo split_info;             // Panel split configuration
+  char panel_name[256] = {0};         // Panel name
 
   bool operator !=(const HWPanelInfo &panel_info) {
     return ((port != panel_info.port) || (mode != panel_info.mode) ||
diff --git a/sdm/libs/core/color_manager.cpp b/sdm/libs/core/color_manager.cpp
index aea55b0..1d224ad 100644
--- a/sdm/libs/core/color_manager.cpp
+++ b/sdm/libs/core/color_manager.cpp
@@ -196,4 +196,26 @@
   return ret;
 }
 
+void PPHWAttributes::Set(const HWResourceInfo &hw_res,
+                         const HWPanelInfo &panel_info,
+                         const DisplayConfigVariableInfo &attr,
+                         const PPFeatureVersion &feature_ver) {
+  HWResourceInfo &res = *this;
+  res = hw_res;
+  HWPanelInfo &panel = *this;
+  panel = panel_info;
+  DisplayConfigVariableInfo &attributes = *this;
+  attributes = attr;
+  version = feature_ver;
+
+  if (strlen(panel_info.panel_name)) {
+    snprintf(&panel_name[0], sizeof(panel_name), "%s", &panel_info.panel_name[0]);
+    char *tmp = panel_name;
+    while ((tmp = strstr(tmp, " ")) != NULL)
+      *tmp = '_';
+    if ((tmp = strstr(panel_name, "\n")) != NULL)
+      *tmp = '\0';
+  }
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index 5ac049c..a72fe6c 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -679,6 +679,40 @@
         hw_panel_info_.split_info.right_split);
 }
 
+void HWDevice::GetHWPanelNameByNode(int device_node, HWPanelInfo *panel_info) {
+  if (!panel_info) {
+    DLOGE("PanelInfo pointer in invalid.");
+    return;
+  }
+  char *string_buffer = new char[kMaxStringLength]();
+  if (!string_buffer) {
+    DLOGE("Failed to allocated string_buffer memory");
+    return;
+  }
+  snprintf(string_buffer, kMaxStringLength, "%s%d/msm_fb_panel_info", fb_path_, device_node);
+  FILE *fileptr = Sys::fopen_(string_buffer, "r");
+  if (!fileptr) {
+    DLOGW("Failed to open msm_fb_panel_info node device node %d", device_node);
+  } else {
+    char *line = string_buffer;
+    size_t len = kMaxStringLength;
+
+    while ((Sys::getline_(&line, &len, fileptr)) != -1) {
+      uint32_t token_count = 0;
+      const uint32_t max_count = 10;
+      char *tokens[max_count] = { NULL };
+      if (!ParseLine(line, "=\n", tokens, max_count, &token_count)) {
+        if (!strncmp(tokens[0], "panel_name", strlen("panel_name"))) {
+          snprintf(panel_info->panel_name, sizeof(panel_info->panel_name), "%s", tokens[1]);
+          break;
+        }
+      }
+    }
+    Sys::fclose_(fileptr);
+  }
+  delete[] string_buffer;
+}
+
 void HWDevice::GetHWPanelInfoByNode(int device_node, HWPanelInfo *panel_info) {
   if (!panel_info) {
     DLOGE("PanelInfo pointer in invalid.");
@@ -733,6 +767,7 @@
   panel_info->port = GetHWDisplayPort(device_node);
   panel_info->mode = GetHWDisplayMode(device_node);
   GetSplitInfo(device_node, panel_info);
+  GetHWPanelNameByNode(device_node, panel_info);
 }
 
 HWDisplayPort HWDevice::GetHWDisplayPort(int device_node) {
@@ -855,6 +890,24 @@
   return 0;
 }
 
+int HWDevice::ParseLine(char *input, const char *delim, char *tokens[],
+                        const uint32_t max_token, uint32_t *count) {
+  char *tmp_token = NULL;
+  char *temp_ptr;
+  uint32_t index = 0;
+  if (!input) {
+    return -1;
+  }
+  tmp_token = strtok_r(input, delim, &temp_ptr);
+  while (tmp_token && index < max_token) {
+    tokens[index++] = tmp_token;
+    tmp_token = strtok_r(NULL, delim, &temp_ptr);
+  }
+  *count = index;
+
+  return 0;
+}
+
 bool HWDevice::EnableHotPlugDetection(int enable) {
   char hpdpath[kMaxStringLength];
   int hdmi_node_index = GetFBNodeIndex(kDeviceHDMI);
diff --git a/sdm/libs/core/fb/hw_device.h b/sdm/libs/core/fb/hw_device.h
index b4205e0..a2610d1 100644
--- a/sdm/libs/core/fb/hw_device.h
+++ b/sdm/libs/core/fb/hw_device.h
@@ -101,10 +101,13 @@
   // Populates HWPanelInfo based on node index
   void PopulateHWPanelInfo();
   void GetHWPanelInfoByNode(int device_node, HWPanelInfo *panel_info);
+  void GetHWPanelNameByNode(int device_node, HWPanelInfo *panel_info);
   HWDisplayPort GetHWDisplayPort(int device_node);
   HWDisplayMode GetHWDisplayMode(int device_node);
   void GetSplitInfo(int device_node, HWPanelInfo *panel_info);
   int ParseLine(char *input, char *tokens[], const uint32_t max_token, uint32_t *count);
+  int ParseLine(char *input, const char *delim, char *tokens[],
+                const uint32_t max_token, uint32_t *count);
   mdp_scale_data* GetScaleDataRef(uint32_t index) { return &scale_data_[index]; }
   void SetHWScaleData(const ScaleData &scale, uint32_t index);
   void ResetDisplayParams();