blob: bca7a0b2e7fdc129eead15fa3d02c17addedf8f9 [file] [log] [blame]
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Tatenda Chipeperekwacbe1dfe2014-11-25 13:21:15 -08003 * Copyright (C) 2012-2015, The Linux Foundation. All rights reserved.
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07004 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#define DEBUG 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <fcntl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070023#include <linux/msm_mdp.h>
24#include <linux/fb.h>
25#include <sys/ioctl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070026#include <cutils/properties.h>
27#include "hwc_utils.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070028#include "hdmi.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070029#include "overlayUtils.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080030#include "overlay.h"
Tatenda Chipeperekwaf080b792014-03-05 19:32:33 -080031#include "qd_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070032
33using namespace android;
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -070034using namespace qdutils;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070035
36namespace qhwc {
Arun Kumar K.R26808f32013-02-11 19:17:05 -080037#define UNKNOWN_STRING "unknown"
38#define SPD_NAME_LENGTH 16
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070039
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070040int HDMIDisplay::configure() {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070041 if(!openFrameBuffer()) {
42 ALOGE("%s: Failed to open FB: %d", __FUNCTION__, mFbNum);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080043 return -1;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070044 }
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -080045 readCEUnderscanInfo();
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080046 readResolution();
Arun Kumar K.R37552c52012-12-10 12:47:18 -080047 /* Used for changing the resolution
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -070048 * getUserConfig will get the preferred
49 * config index set thru adb shell */
50 mActiveConfig = getUserConfig();
51 if (mActiveConfig == -1) {
Arun Kumar K.R37552c52012-12-10 12:47:18 -080052 //Get the best mode and set
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -070053 mActiveConfig = getBestConfig();
Arun Kumar K.R37552c52012-12-10 12:47:18 -080054 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -070055
56 // Read the system property to determine if downscale feature is enabled.
57 char value[PROPERTY_VALUE_MAX];
58 mMDPDownscaleEnabled = false;
59 if(property_get("sys.hwc.mdp_downscale_enabled", value, "false")
60 && !strcmp(value, "true")) {
61 mMDPDownscaleEnabled = true;
62 }
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -070063
Tatenda Chipeperekwacbe1dfe2014-11-25 13:21:15 -080064 // Set the mode corresponding to the active index
65 mCurrentMode = mEDIDModes[mActiveConfig];
66 setAttributes();
67 // set system property
68 property_set("hw.hdmiON", "1");
69
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -070070 // XXX: A debug property can be used to enable resolution change for
71 // testing purposes: debug.hwc.enable_resolution_change
72 mEnableResolutionChange = false;
73 if(property_get("debug.hwc.enable_resolution_change", value, "false")
74 && !strcmp(value, "true")) {
75 mEnableResolutionChange = true;
76 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080077 return 0;
78}
79
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070080void HDMIDisplay::getAttributes(uint32_t& width, uint32_t& height) {
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -080081 uint32_t refresh = 0, fps = 0;
82 getAttrForConfig(mActiveConfig, width, height, refresh, fps);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -070083}
84
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070085int HDMIDisplay::teardown() {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070086 closeFrameBuffer();
87 resetInfo();
88 // unset system property
89 property_set("hw.hdmiON", "0");
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080090 return 0;
91}
92
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070093HDMIDisplay::HDMIDisplay():mFd(-1),
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -070094 mCurrentMode(-1), mModeCount(0), mPrimaryWidth(0), mPrimaryHeight(0),
Tatenda Chipeperekwacbe1dfe2014-11-25 13:21:15 -080095 mUnderscanSupported(false), mMDPDownscaleEnabled(false)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070096{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070097 memset(&mVInfo, 0, sizeof(mVInfo));
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -070098
99 mDisplayId = HWC_DISPLAY_EXTERNAL;
100 // Update the display if HDMI is connected as primary
101 if (isHDMIPrimaryDisplay()) {
102 mDisplayId = HWC_DISPLAY_PRIMARY;
103 }
104
105 mFbNum = overlay::Overlay::getInstance()->getFbForDpy(mDisplayId);
Tatenda Chipeperekwacbe1dfe2014-11-25 13:21:15 -0800106 // Disable HPD at start if HDMI is external, it will be enabled later
Arun Kumar K.Re746ac52013-03-20 15:56:15 -0700107 // when the display powers on
108 // This helps for framework reboot or adb shell stop/start
Tatenda Chipeperekwacbe1dfe2014-11-25 13:21:15 -0800109 if (mDisplayId) {
110 writeHPDOption(0);
111 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800112
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700113 if(mFbNum != -1) {
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800114 // Update the Source Product Information
115 // Vendor Name
116 setSPDInfo("vendor_name", "ro.product.manufacturer");
117 // Product Description
118 setSPDInfo("product_description", "ro.product.name");
119 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700120
121 ALOGD_IF(DEBUG, "%s mDisplayId(%d) mFbNum(%d)",
122 __FUNCTION__, mDisplayId, mFbNum);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800123}
124/* gets the product manufacturer and product name and writes it
125 * to the sysfs node, so that the driver can get that information
126 * Used to show QCOM 8974 instead of Input 1 for example
127 */
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700128void HDMIDisplay::setSPDInfo(const char* node, const char* property) {
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800129 char info[PROPERTY_VALUE_MAX];
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700130 ssize_t err = -1;
131 int spdFile = openDeviceNode(node, O_RDWR);
132 if (spdFile >= 0) {
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800133 memset(info, 0, sizeof(info));
134 property_get(property, info, UNKNOWN_STRING);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700135 ALOGD_IF(DEBUG, "In %s: %s = %s",
136 __FUNCTION__, property, info);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800137 if (strncmp(info, UNKNOWN_STRING, SPD_NAME_LENGTH)) {
138 err = write(spdFile, info, strlen(info));
139 if (err <= 0) {
140 ALOGE("%s: file write failed for '%s'"
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700141 "err no = %d", __FUNCTION__, node, errno);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800142 }
143 } else {
144 ALOGD_IF(DEBUG, "%s: property_get failed for SPD %s",
145 __FUNCTION__, node);
146 }
147 close(spdFile);
Arun Kumar K.R25187572013-02-28 18:47:36 -0800148 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700149}
150
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700151void HDMIDisplay::setHPD(uint32_t value) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700152 ALOGD_IF(DEBUG,"HPD enabled=%d", value);
153 writeHPDOption(value);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700154}
155
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700156void HDMIDisplay::setActionSafeDimension(int w, int h) {
Saurabh Shah56f610d2012-08-07 15:27:06 -0700157 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800158 char actionsafeWidth[PROPERTY_VALUE_MAX];
159 char actionsafeHeight[PROPERTY_VALUE_MAX];
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800160 snprintf(actionsafeWidth, sizeof(actionsafeWidth), "%d", w);
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700161 property_set("persist.sys.actionsafe.width", actionsafeWidth);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800162 snprintf(actionsafeHeight, sizeof(actionsafeHeight), "%d", h);
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700163 property_set("persist.sys.actionsafe.height", actionsafeHeight);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700164}
165
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700166int HDMIDisplay::getModeCount() const {
Saurabh Shah56f610d2012-08-07 15:27:06 -0700167 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700168 return mModeCount;
169}
170
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700171void HDMIDisplay::readCEUnderscanInfo()
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800172{
173 int hdmiScanInfoFile = -1;
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530174 ssize_t len = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800175 char scanInfo[17];
176 char *ce_info_str = NULL;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800177 char *save_ptr;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800178 const char token[] = ", \n";
179 int ce_info = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800180
181 memset(scanInfo, 0, sizeof(scanInfo));
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700182 hdmiScanInfoFile = openDeviceNode("scan_info", O_RDONLY);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800183 if (hdmiScanInfoFile < 0) {
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800184 return;
185 } else {
186 len = read(hdmiScanInfoFile, scanInfo, sizeof(scanInfo)-1);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700187 ALOGD("%s: Scan Info string: %s length = %zu",
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800188 __FUNCTION__, scanInfo, len);
189 if (len <= 0) {
190 close(hdmiScanInfoFile);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700191 ALOGE("%s: Scan Info file empty", __FUNCTION__);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800192 return;
193 }
194 scanInfo[len] = '\0'; /* null terminate the string */
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530195 close(hdmiScanInfoFile);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800196 }
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800197
198 /*
199 * The scan_info contains the three fields
200 * PT - preferred video format
201 * IT - video format
202 * CE video format - containing the underscan support information
203 */
204
205 /* PT */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800206 ce_info_str = strtok_r(scanInfo, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800207 if (ce_info_str) {
208 /* IT */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800209 ce_info_str = strtok_r(NULL, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800210 if (ce_info_str) {
211 /* CE */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800212 ce_info_str = strtok_r(NULL, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800213 if (ce_info_str)
214 ce_info = atoi(ce_info_str);
215 }
216 }
217
218 if (ce_info_str) {
219 // ce_info contains the underscan information
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700220 if (ce_info == HDMI_SCAN_ALWAYS_UNDERSCANED ||
221 ce_info == HDMI_SCAN_BOTH_SUPPORTED)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800222 // if TV supported underscan, then driver will always underscan
223 // hence no need to apply action safe rectangle
224 mUnderscanSupported = true;
225 } else {
226 ALOGE("%s: scan_info string error", __FUNCTION__);
227 }
228
229 // Store underscan support info in a system property
230 const char* prop = (mUnderscanSupported) ? "1" : "0";
231 property_set("hw.underscan_supported", prop);
232 return;
233}
234
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700235HDMIDisplay::~HDMIDisplay()
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700236{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700237 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700238}
239
Arun Kumar K.R25187572013-02-28 18:47:36 -0800240/*
241 * sets the fb_var_screeninfo from the hdmi_mode_timing_info
242 */
243void setDisplayTiming(struct fb_var_screeninfo &info,
244 const msm_hdmi_mode_timing_info* mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700245{
246 info.reserved[0] = 0;
247 info.reserved[1] = 0;
248 info.reserved[2] = 0;
Ken Zhang7b03a952013-01-16 13:23:48 -0500249#ifndef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
Arun Kumar K.R25187572013-02-28 18:47:36 -0800250 info.reserved[3] = (info.reserved[3] & 0xFFFF) |
251 (mode->video_format << 16);
Ken Zhang7b03a952013-01-16 13:23:48 -0500252#endif
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700253 info.xoffset = 0;
254 info.yoffset = 0;
Arun Kumar K.R25187572013-02-28 18:47:36 -0800255 info.xres = mode->active_h;
256 info.yres = mode->active_v;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700257
Arun Kumar K.R25187572013-02-28 18:47:36 -0800258 info.pixclock = (mode->pixel_freq)*1000;
259 info.vmode = mode->interlaced ?
260 FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700261
Arun Kumar K.R25187572013-02-28 18:47:36 -0800262 info.right_margin = mode->front_porch_h;
263 info.hsync_len = mode->pulse_width_h;
264 info.left_margin = mode->back_porch_h;
265 info.lower_margin = mode->front_porch_v;
266 info.vsync_len = mode->pulse_width_v;
267 info.upper_margin = mode->back_porch_v;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700268}
269
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700270int HDMIDisplay::parseResolution(char* edidStr)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700271{
272 char delim = ',';
273 int count = 0;
274 char *start, *end;
275 // EDIDs are string delimited by ','
276 // Ex: 16,4,5,3,32,34,1
277 // Parse this string to get mode(int)
278 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700279 end = &delim;
280 while(*end == delim) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700281 mEDIDModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700282 start = end+1;
283 count++;
284 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700285 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
286 for (int i = 0; i < count; i++)
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700287 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, mEDIDModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700288 return count;
289}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700290
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700291bool HDMIDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700292{
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530293 ssize_t len = -1;
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800294 char edidStr[PAGE_SIZE] = {'\0'};
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700295
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700296 int hdmiEDIDFile = openDeviceNode("edid_modes", O_RDONLY);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700297 if (hdmiEDIDFile < 0) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700298 return false;
299 } else {
Arun Kumar K.R83812342013-09-24 17:30:36 -0700300 len = read(hdmiEDIDFile, edidStr, sizeof(edidStr)-1);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700301 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %zu",
Arun Kumar K.R83812342013-09-24 17:30:36 -0700302 __FUNCTION__, edidStr, len);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700303 if (len <= 0) {
304 ALOGE("%s: edid_modes file empty", __FUNCTION__);
Arun Kumar K.R83812342013-09-24 17:30:36 -0700305 edidStr[0] = '\0';
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700306 }
307 else {
Arun Kumar K.R83812342013-09-24 17:30:36 -0700308 while (len > 1 && isspace(edidStr[len-1])) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700309 --len;
Arun Kumar K.R83812342013-09-24 17:30:36 -0700310 }
311 edidStr[len] = '\0';
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700312 }
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530313 close(hdmiEDIDFile);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700314 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700315 if(len > 0) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800316 // Get EDID modes from the EDID strings
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700317 mModeCount = parseResolution(edidStr);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700318 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
319 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700320 }
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800321 // Populate the internal data structure with the timing information
322 // for each edid mode read from the driver
323 if (mModeCount > 0) {
324 mDisplayConfigs = new msm_hdmi_mode_timing_info[mModeCount];
325 readConfigs();
326 } else {
327 // If we fail to read from EDID when HDMI is connected, then
328 // mModeCount will be 0 and bestConfigIndex will be invalid.
329 // In this case, we populate the mEDIDModes structure with
330 // a default mode at config index 0.
331 uint32_t defaultConfigIndex = 0;
332 mModeCount = 1;
333 mEDIDModes[defaultConfigIndex] = HDMI_VFRMT_640x480p60_4_3;
334 struct msm_hdmi_mode_timing_info defaultMode =
335 HDMI_VFRMT_640x480p60_4_3_TIMING;
336 mDisplayConfigs = new msm_hdmi_mode_timing_info[mModeCount];
337 mDisplayConfigs[defaultConfigIndex] = defaultMode;
338 ALOGD("%s Defaulting to HDMI_VFRMT_640x480p60_4_3", __FUNCTION__);
339 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700340
Arun Kumar K.R83812342013-09-24 17:30:36 -0700341 return (len > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700342}
343
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700344bool HDMIDisplay::openFrameBuffer()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700345{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700346 if (mFd == -1) {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700347 char strDevPath[MAX_SYSFS_FILE_PATH];
348 snprintf(strDevPath, MAX_SYSFS_FILE_PATH, "/dev/graphics/fb%d", mFbNum);
349 mFd = open(strDevPath, O_RDWR);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700350 if (mFd < 0)
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700351 ALOGE("%s: %s is not available", __FUNCTION__, strDevPath);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700352 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700353 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700354}
355
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700356bool HDMIDisplay::closeFrameBuffer()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700357{
358 int ret = 0;
Naseer Ahmedf53b3772013-02-15 19:13:50 -0500359 if(mFd >= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700360 ret = close(mFd);
361 mFd = -1;
362 }
363 return (ret == 0);
364}
365
366// clears the vinfo, edid, best modes
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700367void HDMIDisplay::resetInfo()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700368{
369 memset(&mVInfo, 0, sizeof(mVInfo));
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700370 memset(mEDIDModes, 0, sizeof(mEDIDModes));
371 mModeCount = 0;
372 mCurrentMode = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800373 mUnderscanSupported = false;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700374 mXres = 0;
375 mYres = 0;
376 mVsyncPeriod = 0;
377 mMDPScalingMode = false;
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800378 if (mDisplayConfigs) {
379 delete [] mDisplayConfigs;
380 mDisplayConfigs = 0;
381 }
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800382 // Reset the underscan supported system property
383 const char* prop = "0";
384 property_set("hw.underscan_supported", prop);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700385}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700386
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700387/// Returns the index of the user mode set(if any) using adb shell
388int HDMIDisplay::getUserConfig() {
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800389 /* Based on the property set the resolution */
390 char property_value[PROPERTY_VALUE_MAX];
Arun Kumar K.Rc31bdcb2013-02-25 17:47:42 -0800391 property_get("hw.hdmi.resolution", property_value, "-1");
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800392 int mode = atoi(property_value);
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800393 if(isValidMode(mode)) {
Naseer Ahmed74214722013-02-09 08:11:36 -0500394 ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode);
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700395 return getModeIndex(mode);
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800396 }
397 return -1;
398}
399
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700400// Get the index of the best mode for the current HD TV
401int HDMIDisplay::getBestConfig() {
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800402 int bestConfigIndex = 0;
403 int edidMode = -1;
404 struct msm_hdmi_mode_timing_info currentModeInfo = {0};
405 struct msm_hdmi_mode_timing_info bestModeInfo = {0};
406 bestModeInfo.video_format = 0;
407 bestModeInfo.active_v = 0;
408 bestModeInfo.active_h = 0;
409 bestModeInfo.refresh_rate = 0;
410 bestModeInfo.ar = HDMI_RES_AR_INVALID;
411
412 // for all the timing info read, get the best config
413 for (int configIndex = 0; configIndex < mModeCount; configIndex++) {
414 currentModeInfo = mDisplayConfigs[configIndex];
415
416 if (!currentModeInfo.supported) {
417 ALOGD("%s EDID Mode %d is not supported", __FUNCTION__, edidMode);
418 continue;
419 }
420
421 ALOGD_IF(DEBUG, "%s Best (%d) : (%dx%d) @ %d;"
422 " Current (%d) (%dx%d) @ %d",
423 __FUNCTION__, bestConfigIndex, bestModeInfo.active_h,
424 bestModeInfo.active_v, bestModeInfo.refresh_rate, configIndex,
425 currentModeInfo.active_h, currentModeInfo.active_v,
426 currentModeInfo.refresh_rate);
427
428 // Compare two HDMI modes in order of height, width, refresh rate and
429 // aspect ratio.
430 if (currentModeInfo.active_v > bestModeInfo.active_v) {
431 bestConfigIndex = configIndex;
432 } else if (currentModeInfo.active_v == bestModeInfo.active_v) {
433 if (currentModeInfo.active_h > bestModeInfo.active_h) {
434 bestConfigIndex = configIndex;
435 } else if (currentModeInfo.active_h == bestModeInfo.active_h) {
436 if (currentModeInfo.refresh_rate > bestModeInfo.refresh_rate) {
437 bestConfigIndex = configIndex;
438 } else if (currentModeInfo.refresh_rate ==
439 bestModeInfo.refresh_rate) {
440 if (currentModeInfo.ar > bestModeInfo.ar) {
441 bestConfigIndex = configIndex;
442 }
443 }
444 }
445 }
446 if (bestConfigIndex == configIndex) {
447 bestModeInfo = mDisplayConfigs[bestConfigIndex];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700448 }
449 }
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800450 return bestConfigIndex;
451}
452
453// Utility function used to request HDMI driver to write a new page of timing
454// info into res_info node
455void HDMIDisplay::requestNewPage(int pageNumber) {
456 char pageString[PAGE_SIZE];
457 int fd = openDeviceNode("res_info", O_WRONLY);
458 if (fd >= 0) {
459 snprintf(pageString, sizeof(pageString), "%d", pageNumber);
460 ALOGD_IF(DEBUG, "%s: page=%s", __FUNCTION__, pageString);
461 ssize_t err = write(fd, pageString, sizeof(pageString));
462 if (err <= 0) {
463 ALOGE("%s: Write to res_info failed (%d)", __FUNCTION__, errno);
464 }
465 close(fd);
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700466 }
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800467}
468
469// Reads the contents of res_info node into a buffer if the file is not empty
470bool HDMIDisplay::readResFile(char * configBuffer) {
471 bool fileRead = false;
472 size_t bytesRead = 0;
473 int fd = openDeviceNode("res_info", O_RDONLY);
474 if (fd >= 0 && (bytesRead = read(fd, configBuffer, PAGE_SIZE)) != 0) {
475 fileRead = true;
476 }
477 close(fd);
478 ALOGD_IF(DEBUG, "%s: bytesRead=%d fileRead=%d",
479 __FUNCTION__, bytesRead, fileRead);
480 return fileRead;
481}
482
483// Populates the internal timing info structure with the timing info obtained
484// from the HDMI driver
485void HDMIDisplay::readConfigs() {
486 int configIndex = 0;
487 int pageNumber = MSM_HDMI_INIT_RES_PAGE;
488 long unsigned int size = sizeof(msm_hdmi_mode_timing_info);
489
490 while (true) {
491 char configBuffer[PAGE_SIZE] = {0};
492 msm_hdmi_mode_timing_info *info =
493 (msm_hdmi_mode_timing_info*) configBuffer;
494
495 if (!readResFile(configBuffer))
496 break;
497
498 while (info->video_format && size < PAGE_SIZE) {
499 mDisplayConfigs[configIndex] = *info;
500 size += sizeof(msm_hdmi_mode_timing_info);
501 info++;
502 ALOGD_IF(DEBUG, "%s: Config=%d Mode %d: (%dx%d) @ %d",
503 __FUNCTION__, configIndex,
504 mDisplayConfigs[configIndex].video_format,
505 mDisplayConfigs[configIndex].active_h,
506 mDisplayConfigs[configIndex].active_v,
507 mDisplayConfigs[configIndex].refresh_rate);
508 configIndex++;
509 }
510 size = sizeof(msm_hdmi_mode_timing_info);
511 // Request HDMI driver to populate res_info with more
512 // timing information
513 pageNumber++;
514 requestNewPage(pageNumber);
515 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700516}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700517
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700518inline bool HDMIDisplay::isValidMode(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700519{
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800520 bool valid = false;
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800521 int modeIndex = getModeIndex(ID);
522 if (ID <= 0 || modeIndex < 0 || modeIndex > mModeCount) {
523 return false;
524 }
525 struct msm_hdmi_mode_timing_info* mode = &mDisplayConfigs[modeIndex];
526 // We dont support interlaced modes
527 if (mode->supported && !mode->interlaced) {
528 valid = true;
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800529 }
530 return valid;
531}
532
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700533// Does a put_vscreen info on the HDMI interface which will update
534// the configuration (resolution, timing info) to match mCurrentMode
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700535void HDMIDisplay::activateDisplay()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700536{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700537 int ret = 0;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700538 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
539 if(ret < 0) {
540 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
541 strerror(errno));
542 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700543 ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
544 "(%d,%d,%d) %dMHz>", __FUNCTION__,
545 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
546 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
547 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
548 mVInfo.pixclock/1000/1000);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700549
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800550 struct msm_hdmi_mode_timing_info *mode = &mDisplayConfigs[mActiveConfig];
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700551 setDisplayTiming(mVInfo, mode);
552 ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
553 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, mCurrentMode,
554 mode->video_format, mVInfo.xres, mVInfo.yres,
555 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
556 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
557 mVInfo.pixclock/1000/1000);
Ken Zhang7b03a952013-01-16 13:23:48 -0500558#ifdef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700559 struct msmfb_metadata metadata;
560 memset(&metadata, 0 , sizeof(metadata));
561 metadata.op = metadata_op_vic;
562 metadata.data.video_info_code = mode->video_format;
563 if (ioctl(mFd, MSMFB_METADATA_SET, &metadata) == -1) {
564 ALOGD("In %s: MSMFB_METADATA_SET failed Err Str = %s",
565 __FUNCTION__, strerror(errno));
566 }
Ken Zhang7b03a952013-01-16 13:23:48 -0500567#endif
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700568 mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
569 ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
570 if(ret < 0) {
571 ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
572 __FUNCTION__, strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700573 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700574}
575
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700576bool HDMIDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700577{
578 bool ret = true;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700579 if(mFbNum != -1) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700580 int hdmiHPDFile = openDeviceNode("hpd", O_RDWR);
581 if (hdmiHPDFile >= 0) {
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530582 ssize_t err = -1;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700583 ALOGD_IF(DEBUG, "%s: option = %d",
584 __FUNCTION__, userOption);
Arun Kumar K.R47d6b642013-06-26 16:20:30 -0700585 if(userOption)
586 err = write(hdmiHPDFile, "1", 2);
587 else
588 err = write(hdmiHPDFile, "0" , 2);
589 if (err <= 0) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700590 ALOGE("%s: file write failed 'hpd'", __FUNCTION__);
Arun Kumar K.R47d6b642013-06-26 16:20:30 -0700591 ret = false;
592 }
593 close(hdmiHPDFile);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700594 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700595 }
596 return ret;
597}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700598
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700599
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700600void HDMIDisplay::setAttributes() {
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800601 uint32_t refresh = 0, fps = 0;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700602 // Always set dpyAttr res to mVInfo res
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800603 getAttrForConfig(mActiveConfig, mXres, mYres, refresh, fps);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700604 mMDPScalingMode = false;
605
606 if(overlay::Overlay::getInstance()->isUIScalingOnExternalSupported()
607 && mMDPDownscaleEnabled) {
608 // if primary resolution is more than the hdmi resolution
609 // configure dpy attr to primary resolution and set MDP
610 // scaling mode
611 // Restrict this upto 1080p resolution max, if target does not
612 // support source split feature.
613 uint32_t primaryArea = mPrimaryWidth * mPrimaryHeight;
614 if(((primaryArea) > (mXres * mYres)) &&
615 (((primaryArea) <= SUPPORTED_DOWNSCALE_AREA) ||
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700616 qdutils::MDPVersion::getInstance().isSrcSplit())) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700617 // tmpW and tmpH will hold the primary dimensions before we
618 // update the aspect ratio if necessary.
619 int tmpW = mPrimaryWidth;
620 int tmpH = mPrimaryHeight;
621 // HDMI is always in landscape, so always assign the higher
622 // dimension to hdmi's xres
623 if(mPrimaryHeight > mPrimaryWidth) {
624 tmpW = mPrimaryHeight;
625 tmpH = mPrimaryWidth;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700626 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700627 // The aspect ratios of the external and primary displays
628 // can be different. As a result, directly assigning primary
629 // resolution could lead to an incorrect final image.
630 // We get around this by calculating a new resolution by
631 // keeping aspect ratio intact.
632 hwc_rect r = {0, 0, 0, 0};
633 qdutils::getAspectRatioPosition(tmpW, tmpH, mXres, mYres, r);
634 uint32_t newExtW = r.right - r.left;
635 uint32_t newExtH = r.bottom - r.top;
636 uint32_t alignedExtW;
637 uint32_t alignedExtH;
638 // On 8994 and below targets MDP supports only 4X downscaling,
639 // Restricting selected external resolution to be exactly 4X
640 // greater resolution than actual external resolution
641 uint32_t maxMDPDownScale =
642 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
643 if((mXres * mYres * maxMDPDownScale) < (newExtW * newExtH)) {
644 float upScaleFactor = (float)maxMDPDownScale / 2.0f;
645 newExtW = (int)((float)mXres * upScaleFactor);
646 newExtH = (int)((float)mYres * upScaleFactor);
647 }
648 // Align it down so that the new aligned resolution does not
649 // exceed the maxMDPDownscale factor
650 alignedExtW = overlay::utils::aligndown(newExtW, 4);
651 alignedExtH = overlay::utils::aligndown(newExtH, 4);
652 mXres = alignedExtW;
653 mYres = alignedExtH;
654 // Set External Display MDP Downscale mode indicator
655 mMDPScalingMode = true;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700656 }
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700657 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700658 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Selected external resolution [%d X %d] "
659 "maxMDPDownScale %d mMDPScalingMode %d srcSplitEnabled %d "
660 "MDPDownscale feature %d",
661 mXres, mYres,
662 qdutils::MDPVersion::getInstance().getMaxMDPDownscale(),
663 mMDPScalingMode, qdutils::MDPVersion::getInstance().isSrcSplit(),
664 mMDPDownscaleEnabled);
665 mVsyncPeriod = (int) 1000000000l / fps;
666 ALOGD_IF(DEBUG, "%s xres=%d, yres=%d", __FUNCTION__, mXres, mYres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700667}
668
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700669/* returns the fd related to the node specified*/
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700670int HDMIDisplay::openDeviceNode(const char* node, int fileMode) const {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700671 char sysFsFilePath[MAX_SYSFS_FILE_PATH];
672 memset(sysFsFilePath, 0, sizeof(sysFsFilePath));
673 snprintf(sysFsFilePath , sizeof(sysFsFilePath),
674 "/sys/devices/virtual/graphics/fb%d/%s",
675 mFbNum, node);
676
677 int fd = open(sysFsFilePath, fileMode, 0);
678
679 if (fd < 0) {
680 ALOGE("%s: file '%s' not found : ret = %d err str: %s",
681 __FUNCTION__, sysFsFilePath, fd, strerror(errno));
682 }
683 return fd;
684}
685
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700686bool HDMIDisplay::isHDMIPrimaryDisplay() {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700687 int hdmiNode = qdutils::getHDMINode();
688 return (hdmiNode == HWC_DISPLAY_PRIMARY);
689}
690
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700691int HDMIDisplay::getConnectedState() {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700692 int ret = -1;
693 int mFbNum = qdutils::getHDMINode();
694 int connectedNode = openDeviceNode("connected", O_RDONLY);
695 if(connectedNode >= 0) {
696 char opStr[4];
697 ssize_t bytesRead = read(connectedNode, opStr, sizeof(opStr) - 1);
698 if(bytesRead > 0) {
699 opStr[bytesRead] = '\0';
700 ret = atoi(opStr);
701 ALOGD_IF(DEBUG, "%s: Read %d from connected", __FUNCTION__, ret);
702 } else if(bytesRead == 0) {
703 ALOGE("%s: HDMI connected node empty", __FUNCTION__);
704 } else {
705 ALOGE("%s: Read from HDMI connected node failed with error %s",
706 __FUNCTION__, strerror(errno));
707 }
708 close(connectedNode);
709 } else {
710 ALOGD("%s: /sys/class/graphics/fb%d/connected could not be opened : %s",
711 __FUNCTION__, mFbNum, strerror(errno));
712 }
713 return ret;
714}
715
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700716void HDMIDisplay::setPrimaryAttributes(uint32_t primaryWidth,
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700717 uint32_t primaryHeight) {
718 mPrimaryHeight = primaryHeight;
719 mPrimaryWidth = primaryWidth;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700720}
721
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700722int HDMIDisplay::setActiveConfig(int newConfig) {
723 if(newConfig < 0 || newConfig > mModeCount) {
724 ALOGE("%s Invalid configuration %d", __FUNCTION__, newConfig);
725 return -EINVAL;
726 }
727
728 // XXX: Currently, we only support a change in frame rate.
729 // We need to validate the new config before proceeding.
730 if (!isValidConfigChange(newConfig)) {
731 ALOGE("%s Invalid configuration %d", __FUNCTION__, newConfig);
732 return -EINVAL;
733 }
734
735 mCurrentMode = mEDIDModes[newConfig];
736 mActiveConfig = newConfig;
737 activateDisplay();
738 ALOGD("%s config(%d) mode(%d)", __FUNCTION__, mActiveConfig, mCurrentMode);
739 return 0;
740}
741
742// returns false if the xres or yres of the new config do
743// not match the current config
744bool HDMIDisplay::isValidConfigChange(int newConfig) {
745 int newMode = mEDIDModes[newConfig];
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800746 uint32_t width = 0, height = 0, refresh = 0, fps = 0;
747 getAttrForConfig(newConfig, width, height, refresh, fps);
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700748 return ((mXres == width) && (mYres == height)) || mEnableResolutionChange;
749}
750
751int HDMIDisplay::getModeIndex(int mode) {
752 int modeIndex = -1;
753 for(int i = 0; i < mModeCount; i++) {
754 if(mode == mEDIDModes[i]) {
755 modeIndex = i;
756 break;
757 }
758 }
759 return modeIndex;
760}
761
762int HDMIDisplay::getAttrForConfig(int config, uint32_t& xres,
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800763 uint32_t& yres, uint32_t& refresh, uint32_t& fps) const {
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700764 if(config < 0 || config > mModeCount) {
765 ALOGE("%s Invalid configuration %d", __FUNCTION__, config);
766 return -EINVAL;
767 }
Tatenda Chipeperekwa16301192014-11-14 17:39:27 -0800768
769 xres = mDisplayConfigs[config].active_h;
770 yres = mDisplayConfigs[config].active_v;
771 fps = (mDisplayConfigs[config].refresh_rate / 1000);
772
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700773 refresh = (uint32_t) 1000000000l / fps;
774 ALOGD_IF(DEBUG, "%s xres(%d) yres(%d) fps(%d) refresh(%d)", __FUNCTION__,
775 xres, yres, fps, refresh);
776 return 0;
777}
778
779int HDMIDisplay::getDisplayConfigs(uint32_t* configs,
780 size_t* numConfigs) const {
781 if (*numConfigs <= 0) {
782 ALOGE("%s Invalid number of configs (%d)", __FUNCTION__, *numConfigs);
783 return -EINVAL;
784 }
785 *numConfigs = mModeCount;
786 for (int configIndex = 0; configIndex < mModeCount; configIndex++) {
787 configs[configIndex] = (uint32_t)configIndex;
788 }
789 return 0;
790}
791
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700792};