1 /* 2 * Copyright (c) 2013, The Linux Foundation. All rights reserved. 3 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "qd_utils.h" 31 32 namespace qdutils { 33 34 int parseLine(char *input, char *tokens[], const uint32_t maxToken, uint32_t *count) { 35 char *tmpToken = NULL; 36 char *tmpPtr; 37 uint32_t index = 0; 38 const char *delim = ", =\n"; 39 if (!input) { 40 return -1; 41 } 42 tmpToken = strtok_r(input, delim, &tmpPtr); 43 while (tmpToken && index < maxToken) { 44 tokens[index++] = tmpToken; 45 tmpToken = strtok_r(NULL, delim, &tmpPtr); 46 } 47 *count = index; 48 49 return 0; 50 } 51 52 int querySDEInfo(HWQueryType type, int *value) { 53 FILE *fileptr = NULL; 54 const char *featureName; 55 char stringBuffer[MAX_STRING_LENGTH]; 56 uint32_t tokenCount = 0; 57 const uint32_t maxCount = 10; 58 char *tokens[maxCount] = { NULL }; 59 60 switch(type) { 61 case HAS_MACRO_TILE: 62 featureName = "tile_format"; 63 break; 64 case HAS_UBWC: 65 featureName = "ubwc"; 66 break; 67 case HAS_WB_UBWC: 68 featureName = "wb_ubwc"; 69 break; 70 default: 71 ALOGE("Invalid query type %d", type); 72 return -EINVAL; 73 } 74 75 fileptr = fopen("/sys/devices/virtual/graphics/fb0/mdp/caps", "rb"); 76 if (!fileptr) { 77 ALOGE("File '%s' not found", stringBuffer); 78 return -EINVAL; 79 } 80 81 size_t len = MAX_STRING_LENGTH; 82 ssize_t read; 83 char *line = stringBuffer; 84 while ((read = getline(&line, &len, fileptr)) != -1) { 85 // parse the line and update information accordingly 86 if (parseLine(line, tokens, maxCount, &tokenCount)) { 87 continue; 88 } 89 90 if (strncmp(tokens[0], "features", strlen("features"))) { 91 continue; 92 } 93 94 for (uint32_t i = 0; i < tokenCount; i++) { 95 if (!strncmp(tokens[i], featureName, strlen(featureName))) { 96 *value = 1; 97 } 98 } 99 } 100 fclose(fileptr); 101 102 return 0; 103 } 104 105 int getHDMINode(void) 106 { 107 FILE *displayDeviceFP = NULL; 108 char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; 109 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; 110 int j = 0; 111 112 for(j = 0; j < HWC_NUM_DISPLAY_TYPES; j++) { 113 snprintf (msmFbTypePath, sizeof(msmFbTypePath), 114 "/sys/class/graphics/fb%d/msm_fb_type", j); 115 displayDeviceFP = fopen(msmFbTypePath, "r"); 116 if(displayDeviceFP) { 117 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, 118 displayDeviceFP); 119 if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0) { 120 ALOGD("%s: HDMI is at fb%d", __func__, j); 121 fclose(displayDeviceFP); 122 break; 123 } 124 fclose(displayDeviceFP); 125 } else { 126 ALOGE("%s: Failed to open fb node %d", __func__, j); 127 } 128 } 129 130 if (j < HWC_NUM_DISPLAY_TYPES) 131 return j; 132 else 133 ALOGE("%s: Failed to find HDMI node", __func__); 134 135 return -1; 136 } 137 138 int getEdidRawData(char *buffer) 139 { 140 int size; 141 int edidFile; 142 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; 143 int node_id = getHDMINode(); 144 145 if (node_id < 0) { 146 ALOGE("%s no HDMI node found", __func__); 147 return 0; 148 } 149 150 snprintf(msmFbTypePath, sizeof(msmFbTypePath), 151 "/sys/class/graphics/fb%d/edid_raw_data", node_id); 152 153 edidFile = open(msmFbTypePath, O_RDONLY, 0); 154 155 if (edidFile < 0) { 156 ALOGE("%s no edid raw data found", __func__); 157 return 0; 158 } 159 160 size = (int)read(edidFile, (char*)buffer, EDID_RAW_DATA_SIZE); 161 close(edidFile); 162 return size; 163 } 164 165 }; //namespace qdutils 166