blob: 1aee664d0f83bbcc6182b1705d6029b9952cec2b [file] [log] [blame]
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -07003 * Copyright (C) 2012-2014, 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>
Arun Kumar K.R25187572013-02-28 18:47:36 -080024#include <video/msm_hdmi_modes.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070025#include <linux/fb.h>
26#include <sys/ioctl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070027#include <cutils/properties.h>
28#include "hwc_utils.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070029#include "hdmi.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070030#include "overlayUtils.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080031#include "overlay.h"
Tatenda Chipeperekwaf080b792014-03-05 19:32:33 -080032#include "qd_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070033
34using namespace android;
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -070035using namespace qdutils;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070036
37namespace qhwc {
Arun Kumar K.R26808f32013-02-11 19:17:05 -080038#define UNKNOWN_STRING "unknown"
39#define SPD_NAME_LENGTH 16
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070040
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -070041/* The array gEDIDData contains a list of modes currently
42 * supported by HDMI and display, and modes that are not
43 * supported i.e. interlaced modes.
44
45 * In order to add support for a new mode, the mode must be
46 * appended to the end of the array.
47 *
48 * Each new entry must contain the following:
49 * -Mode: a video format defined in msm_hdmi_modes.h
50 * -Width: x resolution for the mode
51 * -Height: y resolution for the mode
52 * -FPS: the frame rate for the mode
53 * -Mode Order: the priority for the new mode that is used when determining
54 * the best mode when the HDMI display is connected.
55 */
56EDIDData gEDIDData [] = {
57 EDIDData(HDMI_VFRMT_1440x480i60_4_3, 1440, 480, 60, 1),
58 EDIDData(HDMI_VFRMT_1440x480i60_16_9, 1440, 480, 60, 2),
59 EDIDData(HDMI_VFRMT_1440x576i50_4_3, 1440, 576, 50, 3),
60 EDIDData(HDMI_VFRMT_1440x576i50_16_9, 1440, 576, 50, 4),
61 EDIDData(HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, 60, 5),
62 EDIDData(HDMI_VFRMT_640x480p60_4_3, 640, 480, 60, 6),
63 EDIDData(HDMI_VFRMT_720x480p60_4_3, 720, 480, 60, 7),
64 EDIDData(HDMI_VFRMT_720x480p60_16_9, 720, 480, 60, 8),
65 EDIDData(HDMI_VFRMT_720x576p50_4_3, 720, 576, 50, 9),
66 EDIDData(HDMI_VFRMT_720x576p50_16_9, 720, 576, 50, 10),
Tatenda Chipeperekwa85dcfe52014-09-29 16:34:01 -070067 EDIDData(HDMI_VFRMT_800x600p60_4_3, 800, 600, 60, 11),
68 EDIDData(HDMI_VFRMT_848x480p60_16_9, 848, 480, 60, 12),
69 EDIDData(HDMI_VFRMT_1024x768p60_4_3, 1024, 768, 60, 13),
70 EDIDData(HDMI_VFRMT_1280x1024p60_5_4, 1280, 1024, 60, 14),
71 EDIDData(HDMI_VFRMT_1280x720p50_16_9, 1280, 720, 50, 15),
72 EDIDData(HDMI_VFRMT_1280x720p60_16_9, 1280, 720, 60, 16),
73 EDIDData(HDMI_VFRMT_1280x800p60_16_10, 1280, 800, 60, 17),
74 EDIDData(HDMI_VFRMT_1280x960p60_4_3, 1280, 960, 60, 18),
75 EDIDData(HDMI_VFRMT_1360x768p60_16_9, 1360, 768, 60, 19),
76 EDIDData(HDMI_VFRMT_1366x768p60_16_10, 1366, 768, 60, 20),
77 EDIDData(HDMI_VFRMT_1440x900p60_16_10, 1440, 900, 60, 21),
78 EDIDData(HDMI_VFRMT_1400x1050p60_4_3, 1400, 1050, 60, 22),
79 EDIDData(HDMI_VFRMT_1680x1050p60_16_10, 1680, 1050, 60, 23),
80 EDIDData(HDMI_VFRMT_1600x1200p60_4_3, 1600, 1200, 60, 24),
81 EDIDData(HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, 24, 25),
82 EDIDData(HDMI_VFRMT_1920x1080p25_16_9, 1920, 1080, 25, 26),
83 EDIDData(HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, 30, 27),
84 EDIDData(HDMI_VFRMT_1920x1080p50_16_9, 1920, 1080, 50, 28),
85 EDIDData(HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, 60, 29),
86 EDIDData(HDMI_VFRMT_1920x1200p60_16_10, 1920, 1200, 60, 30),
87 EDIDData(HDMI_VFRMT_2560x1600p60_16_9, 2560, 1600, 60, 31),
88 EDIDData(HDMI_VFRMT_3840x2160p24_16_9, 3840, 2160, 24, 32),
89 EDIDData(HDMI_VFRMT_3840x2160p25_16_9, 3840, 2160, 25, 33),
90 EDIDData(HDMI_VFRMT_3840x2160p30_16_9, 3840, 2160, 30, 34),
91 EDIDData(HDMI_VFRMT_4096x2160p24_16_9, 4096, 2160, 24, 35),
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -070092};
93
94// Number of modes in gEDIDData
95const int gEDIDCount = (sizeof(gEDIDData)/sizeof(gEDIDData)[0]);
96
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070097int HDMIDisplay::configure() {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070098 if(!openFrameBuffer()) {
99 ALOGE("%s: Failed to open FB: %d", __FUNCTION__, mFbNum);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800100 return -1;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700101 }
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800102 readCEUnderscanInfo();
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800103 readResolution();
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800104 /* Used for changing the resolution
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700105 * getUserConfig will get the preferred
106 * config index set thru adb shell */
107 mActiveConfig = getUserConfig();
108 if (mActiveConfig == -1) {
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800109 //Get the best mode and set
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700110 mActiveConfig = getBestConfig();
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800111 }
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700112 // Set the mode corresponding to the active index
113 mCurrentMode = mEDIDModes[mActiveConfig];
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700114 setAttributes();
Amara Venkata Mastan Manoj Kumarb156a2f2013-02-07 16:42:50 -0800115 // set system property
116 property_set("hw.hdmiON", "1");
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700117
118 // Read the system property to determine if downscale feature is enabled.
119 char value[PROPERTY_VALUE_MAX];
120 mMDPDownscaleEnabled = false;
121 if(property_get("sys.hwc.mdp_downscale_enabled", value, "false")
122 && !strcmp(value, "true")) {
123 mMDPDownscaleEnabled = true;
124 }
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700125
126 // XXX: A debug property can be used to enable resolution change for
127 // testing purposes: debug.hwc.enable_resolution_change
128 mEnableResolutionChange = false;
129 if(property_get("debug.hwc.enable_resolution_change", value, "false")
130 && !strcmp(value, "true")) {
131 mEnableResolutionChange = true;
132 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800133 return 0;
134}
135
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700136void HDMIDisplay::getAttributes(uint32_t& width, uint32_t& height) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700137 uint32_t fps = 0;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700138 getAttrForMode(width, height, fps);
139}
140
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700141int HDMIDisplay::teardown() {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700142 closeFrameBuffer();
143 resetInfo();
144 // unset system property
145 property_set("hw.hdmiON", "0");
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800146 return 0;
147}
148
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700149HDMIDisplay::HDMIDisplay():mFd(-1),
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700150 mCurrentMode(-1), mModeCount(0), mPrimaryWidth(0), mPrimaryHeight(0),
151 mUnderscanSupported(false)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700152{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700153 memset(&mVInfo, 0, sizeof(mVInfo));
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700154
155 mDisplayId = HWC_DISPLAY_EXTERNAL;
156 // Update the display if HDMI is connected as primary
157 if (isHDMIPrimaryDisplay()) {
158 mDisplayId = HWC_DISPLAY_PRIMARY;
159 }
160
161 mFbNum = overlay::Overlay::getInstance()->getFbForDpy(mDisplayId);
Arun Kumar K.Re746ac52013-03-20 15:56:15 -0700162 // disable HPD at start, it will be enabled later
163 // when the display powers on
164 // This helps for framework reboot or adb shell stop/start
165 writeHPDOption(0);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800166
Arun Kumar K.R25187572013-02-28 18:47:36 -0800167 // for HDMI - retreive all the modes supported by the driver
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700168 if(mFbNum != -1) {
Arun Kumar K.R25187572013-02-28 18:47:36 -0800169 supported_video_mode_lut =
170 new msm_hdmi_mode_timing_info[HDMI_VFRMT_MAX];
171 // Populate the mode table for supported modes
172 MSM_HDMI_MODES_INIT_TIMINGS(supported_video_mode_lut);
173 MSM_HDMI_MODES_SET_SUPP_TIMINGS(supported_video_mode_lut,
174 MSM_HDMI_MODES_ALL);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800175 // Update the Source Product Information
176 // Vendor Name
177 setSPDInfo("vendor_name", "ro.product.manufacturer");
178 // Product Description
179 setSPDInfo("product_description", "ro.product.name");
180 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700181
182 ALOGD_IF(DEBUG, "%s mDisplayId(%d) mFbNum(%d)",
183 __FUNCTION__, mDisplayId, mFbNum);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800184}
185/* gets the product manufacturer and product name and writes it
186 * to the sysfs node, so that the driver can get that information
187 * Used to show QCOM 8974 instead of Input 1 for example
188 */
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700189void HDMIDisplay::setSPDInfo(const char* node, const char* property) {
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800190 char info[PROPERTY_VALUE_MAX];
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700191 ssize_t err = -1;
192 int spdFile = openDeviceNode(node, O_RDWR);
193 if (spdFile >= 0) {
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800194 memset(info, 0, sizeof(info));
195 property_get(property, info, UNKNOWN_STRING);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700196 ALOGD_IF(DEBUG, "In %s: %s = %s",
197 __FUNCTION__, property, info);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800198 if (strncmp(info, UNKNOWN_STRING, SPD_NAME_LENGTH)) {
199 err = write(spdFile, info, strlen(info));
200 if (err <= 0) {
201 ALOGE("%s: file write failed for '%s'"
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700202 "err no = %d", __FUNCTION__, node, errno);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800203 }
204 } else {
205 ALOGD_IF(DEBUG, "%s: property_get failed for SPD %s",
206 __FUNCTION__, node);
207 }
208 close(spdFile);
Arun Kumar K.R25187572013-02-28 18:47:36 -0800209 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700210}
211
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700212void HDMIDisplay::setHPD(uint32_t value) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700213 ALOGD_IF(DEBUG,"HPD enabled=%d", value);
214 writeHPDOption(value);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700215}
216
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700217void HDMIDisplay::setActionSafeDimension(int w, int h) {
Saurabh Shah56f610d2012-08-07 15:27:06 -0700218 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800219 char actionsafeWidth[PROPERTY_VALUE_MAX];
220 char actionsafeHeight[PROPERTY_VALUE_MAX];
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800221 snprintf(actionsafeWidth, sizeof(actionsafeWidth), "%d", w);
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700222 property_set("persist.sys.actionsafe.width", actionsafeWidth);
Arun Kumar K.R26808f32013-02-11 19:17:05 -0800223 snprintf(actionsafeHeight, sizeof(actionsafeHeight), "%d", h);
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700224 property_set("persist.sys.actionsafe.height", actionsafeHeight);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700225}
226
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700227int HDMIDisplay::getModeCount() const {
Saurabh Shah56f610d2012-08-07 15:27:06 -0700228 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700229 return mModeCount;
230}
231
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700232void HDMIDisplay::readCEUnderscanInfo()
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800233{
234 int hdmiScanInfoFile = -1;
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530235 ssize_t len = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800236 char scanInfo[17];
237 char *ce_info_str = NULL;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800238 char *save_ptr;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800239 const char token[] = ", \n";
240 int ce_info = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800241
242 memset(scanInfo, 0, sizeof(scanInfo));
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700243 hdmiScanInfoFile = openDeviceNode("scan_info", O_RDONLY);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800244 if (hdmiScanInfoFile < 0) {
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800245 return;
246 } else {
247 len = read(hdmiScanInfoFile, scanInfo, sizeof(scanInfo)-1);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700248 ALOGD("%s: Scan Info string: %s length = %zu",
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800249 __FUNCTION__, scanInfo, len);
250 if (len <= 0) {
251 close(hdmiScanInfoFile);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700252 ALOGE("%s: Scan Info file empty", __FUNCTION__);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800253 return;
254 }
255 scanInfo[len] = '\0'; /* null terminate the string */
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530256 close(hdmiScanInfoFile);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800257 }
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800258
259 /*
260 * The scan_info contains the three fields
261 * PT - preferred video format
262 * IT - video format
263 * CE video format - containing the underscan support information
264 */
265
266 /* PT */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800267 ce_info_str = strtok_r(scanInfo, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800268 if (ce_info_str) {
269 /* IT */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800270 ce_info_str = strtok_r(NULL, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800271 if (ce_info_str) {
272 /* CE */
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800273 ce_info_str = strtok_r(NULL, token, &save_ptr);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800274 if (ce_info_str)
275 ce_info = atoi(ce_info_str);
276 }
277 }
278
279 if (ce_info_str) {
280 // ce_info contains the underscan information
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700281 if (ce_info == HDMI_SCAN_ALWAYS_UNDERSCANED ||
282 ce_info == HDMI_SCAN_BOTH_SUPPORTED)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800283 // if TV supported underscan, then driver will always underscan
284 // hence no need to apply action safe rectangle
285 mUnderscanSupported = true;
286 } else {
287 ALOGE("%s: scan_info string error", __FUNCTION__);
288 }
289
290 // Store underscan support info in a system property
291 const char* prop = (mUnderscanSupported) ? "1" : "0";
292 property_set("hw.underscan_supported", prop);
293 return;
294}
295
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700296HDMIDisplay::~HDMIDisplay()
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700297{
Arun Kumar K.R25187572013-02-28 18:47:36 -0800298 delete [] supported_video_mode_lut;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700299 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700300}
301
Arun Kumar K.R25187572013-02-28 18:47:36 -0800302/*
303 * sets the fb_var_screeninfo from the hdmi_mode_timing_info
304 */
305void setDisplayTiming(struct fb_var_screeninfo &info,
306 const msm_hdmi_mode_timing_info* mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700307{
308 info.reserved[0] = 0;
309 info.reserved[1] = 0;
310 info.reserved[2] = 0;
Ken Zhang7b03a952013-01-16 13:23:48 -0500311#ifndef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
Arun Kumar K.R25187572013-02-28 18:47:36 -0800312 info.reserved[3] = (info.reserved[3] & 0xFFFF) |
313 (mode->video_format << 16);
Ken Zhang7b03a952013-01-16 13:23:48 -0500314#endif
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700315 info.xoffset = 0;
316 info.yoffset = 0;
Arun Kumar K.R25187572013-02-28 18:47:36 -0800317 info.xres = mode->active_h;
318 info.yres = mode->active_v;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700319
Arun Kumar K.R25187572013-02-28 18:47:36 -0800320 info.pixclock = (mode->pixel_freq)*1000;
321 info.vmode = mode->interlaced ?
322 FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700323
Arun Kumar K.R25187572013-02-28 18:47:36 -0800324 info.right_margin = mode->front_porch_h;
325 info.hsync_len = mode->pulse_width_h;
326 info.left_margin = mode->back_porch_h;
327 info.lower_margin = mode->front_porch_v;
328 info.vsync_len = mode->pulse_width_v;
329 info.upper_margin = mode->back_porch_v;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700330}
331
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700332int HDMIDisplay::parseResolution(char* edidStr)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700333{
334 char delim = ',';
335 int count = 0;
336 char *start, *end;
337 // EDIDs are string delimited by ','
338 // Ex: 16,4,5,3,32,34,1
339 // Parse this string to get mode(int)
340 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700341 end = &delim;
342 while(*end == delim) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700343 mEDIDModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700344 start = end+1;
345 count++;
346 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700347 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
348 for (int i = 0; i < count; i++)
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700349 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, mEDIDModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700350 return count;
351}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700352
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700353bool HDMIDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700354{
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530355 ssize_t len = -1;
Arun Kumar K.R83812342013-09-24 17:30:36 -0700356 char edidStr[128] = {'\0'};
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700357
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700358 int hdmiEDIDFile = openDeviceNode("edid_modes", O_RDONLY);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700359 if (hdmiEDIDFile < 0) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700360 return false;
361 } else {
Arun Kumar K.R83812342013-09-24 17:30:36 -0700362 len = read(hdmiEDIDFile, edidStr, sizeof(edidStr)-1);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700363 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %zu",
Arun Kumar K.R83812342013-09-24 17:30:36 -0700364 __FUNCTION__, edidStr, len);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700365 if (len <= 0) {
366 ALOGE("%s: edid_modes file empty", __FUNCTION__);
Arun Kumar K.R83812342013-09-24 17:30:36 -0700367 edidStr[0] = '\0';
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700368 }
369 else {
Arun Kumar K.R83812342013-09-24 17:30:36 -0700370 while (len > 1 && isspace(edidStr[len-1])) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700371 --len;
Arun Kumar K.R83812342013-09-24 17:30:36 -0700372 }
373 edidStr[len] = '\0';
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700374 }
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530375 close(hdmiEDIDFile);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700376 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700377 if(len > 0) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800378 // Get EDID modes from the EDID strings
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700379 mModeCount = parseResolution(edidStr);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700380 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
381 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700382 }
383
Arun Kumar K.R83812342013-09-24 17:30:36 -0700384 return (len > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700385}
386
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700387bool HDMIDisplay::openFrameBuffer()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700388{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700389 if (mFd == -1) {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700390 char strDevPath[MAX_SYSFS_FILE_PATH];
391 snprintf(strDevPath, MAX_SYSFS_FILE_PATH, "/dev/graphics/fb%d", mFbNum);
392 mFd = open(strDevPath, O_RDWR);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700393 if (mFd < 0)
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700394 ALOGE("%s: %s is not available", __FUNCTION__, strDevPath);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700395 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700396 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700397}
398
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700399bool HDMIDisplay::closeFrameBuffer()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700400{
401 int ret = 0;
Naseer Ahmedf53b3772013-02-15 19:13:50 -0500402 if(mFd >= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700403 ret = close(mFd);
404 mFd = -1;
405 }
406 return (ret == 0);
407}
408
409// clears the vinfo, edid, best modes
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700410void HDMIDisplay::resetInfo()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700411{
412 memset(&mVInfo, 0, sizeof(mVInfo));
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700413 memset(mEDIDModes, 0, sizeof(mEDIDModes));
414 mModeCount = 0;
415 mCurrentMode = -1;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800416 mUnderscanSupported = false;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700417 mXres = 0;
418 mYres = 0;
419 mVsyncPeriod = 0;
420 mMDPScalingMode = false;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800421 // Reset the underscan supported system property
422 const char* prop = "0";
423 property_set("hw.underscan_supported", prop);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700424}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700425
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700426int HDMIDisplay::getModeOrder(int mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700427{
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700428 for (int dataIndex = 0; dataIndex < gEDIDCount; dataIndex++) {
429 if (gEDIDData[dataIndex].mMode == mode) {
430 return gEDIDData[dataIndex].mModeOrder;
431 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700432 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700433 ALOGE("%s Mode not found: %d", __FUNCTION__, mode);
434 return -1;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700435}
436
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700437/// Returns the index of the user mode set(if any) using adb shell
438int HDMIDisplay::getUserConfig() {
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800439 /* Based on the property set the resolution */
440 char property_value[PROPERTY_VALUE_MAX];
Arun Kumar K.Rc31bdcb2013-02-25 17:47:42 -0800441 property_get("hw.hdmi.resolution", property_value, "-1");
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800442 int mode = atoi(property_value);
443 // We dont support interlaced modes
444 if(isValidMode(mode) && !isInterlacedMode(mode)) {
Naseer Ahmed74214722013-02-09 08:11:36 -0500445 ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode);
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700446 return getModeIndex(mode);
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800447 }
448 return -1;
449}
450
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700451// Get the index of the best mode for the current HD TV
452int HDMIDisplay::getBestConfig() {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700453 int bestOrder = 0;
Arun Kumar K.R25187572013-02-28 18:47:36 -0800454 int bestMode = HDMI_VFRMT_640x480p60_4_3;
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700455 int bestModeIndex = -1;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700456 // for all the edid read, get the best mode
457 for(int i = 0; i < mModeCount; i++) {
458 int mode = mEDIDModes[i];
459 int order = getModeOrder(mode);
460 if (order > bestOrder) {
461 bestOrder = order;
462 bestMode = mode;
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700463 bestModeIndex = i;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700464 }
465 }
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700466 // If we fail to read from EDID when HDMI is connected, then
467 // mModeCount will be 0 and bestModeIndex will be invalid.
468 // In this case, we populate the mEDIDModes structure with
469 // a default mode at index 0.
470 if (bestModeIndex == -1) {
471 bestModeIndex = 0;
472 mModeCount = 1;
473 mEDIDModes[bestModeIndex] = bestMode;
474 }
475 return bestModeIndex;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700476}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700477
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700478inline bool HDMIDisplay::isValidMode(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700479{
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800480 bool valid = false;
481 for (int i = 0; i < mModeCount; i++) {
482 if(ID == mEDIDModes[i]) {
483 valid = true;
484 break;
485 }
486 }
487 return valid;
488}
489
490// returns true if the mode(ID) is interlaced mode format
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700491bool HDMIDisplay::isInterlacedMode(int ID) {
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800492 bool interlaced = false;
493 switch(ID) {
Arun Kumar K.R25187572013-02-28 18:47:36 -0800494 case HDMI_VFRMT_1440x480i60_4_3:
495 case HDMI_VFRMT_1440x480i60_16_9:
496 case HDMI_VFRMT_1440x576i50_4_3:
497 case HDMI_VFRMT_1440x576i50_16_9:
498 case HDMI_VFRMT_1920x1080i60_16_9:
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800499 interlaced = true;
Arun Kumar K.Rae46f3a2013-05-16 16:40:10 -0700500 break;
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800501 default:
502 interlaced = false;
Arun Kumar K.Rae46f3a2013-05-16 16:40:10 -0700503 break;
Arun Kumar K.R37552c52012-12-10 12:47:18 -0800504 }
505 return interlaced;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700506}
507
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700508// Does a put_vscreen info on the HDMI interface which will update
509// the configuration (resolution, timing info) to match mCurrentMode
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700510void HDMIDisplay::activateDisplay()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700511{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700512 int ret = 0;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700513 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
514 if(ret < 0) {
515 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
516 strerror(errno));
517 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700518 ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
519 "(%d,%d,%d) %dMHz>", __FUNCTION__,
520 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
521 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
522 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
523 mVInfo.pixclock/1000/1000);
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700524
525 const struct msm_hdmi_mode_timing_info *mode =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700526 &supported_video_mode_lut[0];
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700527 for (unsigned int i = 0; i < HDMI_VFRMT_MAX; ++i) {
528 const struct msm_hdmi_mode_timing_info *cur =
529 &supported_video_mode_lut[i];
530 if (cur->video_format == (uint32_t)mCurrentMode) {
531 mode = cur;
532 break;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700533 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700534 }
535 setDisplayTiming(mVInfo, mode);
536 ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
537 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, mCurrentMode,
538 mode->video_format, mVInfo.xres, mVInfo.yres,
539 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
540 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
541 mVInfo.pixclock/1000/1000);
Ken Zhang7b03a952013-01-16 13:23:48 -0500542#ifdef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700543 struct msmfb_metadata metadata;
544 memset(&metadata, 0 , sizeof(metadata));
545 metadata.op = metadata_op_vic;
546 metadata.data.video_info_code = mode->video_format;
547 if (ioctl(mFd, MSMFB_METADATA_SET, &metadata) == -1) {
548 ALOGD("In %s: MSMFB_METADATA_SET failed Err Str = %s",
549 __FUNCTION__, strerror(errno));
550 }
Ken Zhang7b03a952013-01-16 13:23:48 -0500551#endif
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700552 mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
553 ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
554 if(ret < 0) {
555 ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
556 __FUNCTION__, strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700557 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700558}
559
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700560bool HDMIDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700561{
562 bool ret = true;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700563 if(mFbNum != -1) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700564 int hdmiHPDFile = openDeviceNode("hpd", O_RDWR);
565 if (hdmiHPDFile >= 0) {
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530566 ssize_t err = -1;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700567 ALOGD_IF(DEBUG, "%s: option = %d",
568 __FUNCTION__, userOption);
Arun Kumar K.R47d6b642013-06-26 16:20:30 -0700569 if(userOption)
570 err = write(hdmiHPDFile, "1", 2);
571 else
572 err = write(hdmiHPDFile, "0" , 2);
573 if (err <= 0) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700574 ALOGE("%s: file write failed 'hpd'", __FUNCTION__);
Arun Kumar K.R47d6b642013-06-26 16:20:30 -0700575 ret = false;
576 }
577 close(hdmiHPDFile);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700578 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700579 }
580 return ret;
581}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700582
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700583
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700584void HDMIDisplay::setAttributes() {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700585 uint32_t fps = 0;
586 // Always set dpyAttr res to mVInfo res
587 getAttrForMode(mXres, mYres, fps);
588 mMDPScalingMode = false;
589
590 if(overlay::Overlay::getInstance()->isUIScalingOnExternalSupported()
591 && mMDPDownscaleEnabled) {
592 // if primary resolution is more than the hdmi resolution
593 // configure dpy attr to primary resolution and set MDP
594 // scaling mode
595 // Restrict this upto 1080p resolution max, if target does not
596 // support source split feature.
597 uint32_t primaryArea = mPrimaryWidth * mPrimaryHeight;
598 if(((primaryArea) > (mXres * mYres)) &&
599 (((primaryArea) <= SUPPORTED_DOWNSCALE_AREA) ||
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700600 qdutils::MDPVersion::getInstance().isSrcSplit())) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700601 // tmpW and tmpH will hold the primary dimensions before we
602 // update the aspect ratio if necessary.
603 int tmpW = mPrimaryWidth;
604 int tmpH = mPrimaryHeight;
605 // HDMI is always in landscape, so always assign the higher
606 // dimension to hdmi's xres
607 if(mPrimaryHeight > mPrimaryWidth) {
608 tmpW = mPrimaryHeight;
609 tmpH = mPrimaryWidth;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700610 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700611 // The aspect ratios of the external and primary displays
612 // can be different. As a result, directly assigning primary
613 // resolution could lead to an incorrect final image.
614 // We get around this by calculating a new resolution by
615 // keeping aspect ratio intact.
616 hwc_rect r = {0, 0, 0, 0};
617 qdutils::getAspectRatioPosition(tmpW, tmpH, mXres, mYres, r);
618 uint32_t newExtW = r.right - r.left;
619 uint32_t newExtH = r.bottom - r.top;
620 uint32_t alignedExtW;
621 uint32_t alignedExtH;
622 // On 8994 and below targets MDP supports only 4X downscaling,
623 // Restricting selected external resolution to be exactly 4X
624 // greater resolution than actual external resolution
625 uint32_t maxMDPDownScale =
626 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
627 if((mXres * mYres * maxMDPDownScale) < (newExtW * newExtH)) {
628 float upScaleFactor = (float)maxMDPDownScale / 2.0f;
629 newExtW = (int)((float)mXres * upScaleFactor);
630 newExtH = (int)((float)mYres * upScaleFactor);
631 }
632 // Align it down so that the new aligned resolution does not
633 // exceed the maxMDPDownscale factor
634 alignedExtW = overlay::utils::aligndown(newExtW, 4);
635 alignedExtH = overlay::utils::aligndown(newExtH, 4);
636 mXres = alignedExtW;
637 mYres = alignedExtH;
638 // Set External Display MDP Downscale mode indicator
639 mMDPScalingMode = true;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700640 }
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700641 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700642 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Selected external resolution [%d X %d] "
643 "maxMDPDownScale %d mMDPScalingMode %d srcSplitEnabled %d "
644 "MDPDownscale feature %d",
645 mXres, mYres,
646 qdutils::MDPVersion::getInstance().getMaxMDPDownscale(),
647 mMDPScalingMode, qdutils::MDPVersion::getInstance().isSrcSplit(),
648 mMDPDownscaleEnabled);
649 mVsyncPeriod = (int) 1000000000l / fps;
650 ALOGD_IF(DEBUG, "%s xres=%d, yres=%d", __FUNCTION__, mXres, mYres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700651}
652
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700653void HDMIDisplay::getAttrForMode(uint32_t& width, uint32_t& height,
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700654 uint32_t& fps) {
655 for (int dataIndex = 0; dataIndex < gEDIDCount; dataIndex++) {
656 if (gEDIDData[dataIndex].mMode == mCurrentMode) {
657 width = gEDIDData[dataIndex].mWidth;
658 height = gEDIDData[dataIndex].mHeight;
659 fps = gEDIDData[dataIndex].mFps;
660 return;
661 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700662 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700663 ALOGE("%s Unable to get attributes for %d", __FUNCTION__, mCurrentMode);
664}
665
666/* returns the fd related to the node specified*/
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700667int HDMIDisplay::openDeviceNode(const char* node, int fileMode) const {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700668 char sysFsFilePath[MAX_SYSFS_FILE_PATH];
669 memset(sysFsFilePath, 0, sizeof(sysFsFilePath));
670 snprintf(sysFsFilePath , sizeof(sysFsFilePath),
671 "/sys/devices/virtual/graphics/fb%d/%s",
672 mFbNum, node);
673
674 int fd = open(sysFsFilePath, fileMode, 0);
675
676 if (fd < 0) {
677 ALOGE("%s: file '%s' not found : ret = %d err str: %s",
678 __FUNCTION__, sysFsFilePath, fd, strerror(errno));
679 }
680 return fd;
681}
682
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700683bool HDMIDisplay::isHDMIPrimaryDisplay() {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700684 int hdmiNode = qdutils::getHDMINode();
685 return (hdmiNode == HWC_DISPLAY_PRIMARY);
686}
687
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700688int HDMIDisplay::getConnectedState() {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700689 int ret = -1;
690 int mFbNum = qdutils::getHDMINode();
691 int connectedNode = openDeviceNode("connected", O_RDONLY);
692 if(connectedNode >= 0) {
693 char opStr[4];
694 ssize_t bytesRead = read(connectedNode, opStr, sizeof(opStr) - 1);
695 if(bytesRead > 0) {
696 opStr[bytesRead] = '\0';
697 ret = atoi(opStr);
698 ALOGD_IF(DEBUG, "%s: Read %d from connected", __FUNCTION__, ret);
699 } else if(bytesRead == 0) {
700 ALOGE("%s: HDMI connected node empty", __FUNCTION__);
701 } else {
702 ALOGE("%s: Read from HDMI connected node failed with error %s",
703 __FUNCTION__, strerror(errno));
704 }
705 close(connectedNode);
706 } else {
707 ALOGD("%s: /sys/class/graphics/fb%d/connected could not be opened : %s",
708 __FUNCTION__, mFbNum, strerror(errno));
709 }
710 return ret;
711}
712
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700713void HDMIDisplay::setPrimaryAttributes(uint32_t primaryWidth,
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700714 uint32_t primaryHeight) {
715 mPrimaryHeight = primaryHeight;
716 mPrimaryWidth = primaryWidth;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700717}
718
Tatenda Chipeperekwa319eec12014-09-18 15:08:09 -0700719int HDMIDisplay::setActiveConfig(int newConfig) {
720 if(newConfig < 0 || newConfig > mModeCount) {
721 ALOGE("%s Invalid configuration %d", __FUNCTION__, newConfig);
722 return -EINVAL;
723 }
724
725 // XXX: Currently, we only support a change in frame rate.
726 // We need to validate the new config before proceeding.
727 if (!isValidConfigChange(newConfig)) {
728 ALOGE("%s Invalid configuration %d", __FUNCTION__, newConfig);
729 return -EINVAL;
730 }
731
732 mCurrentMode = mEDIDModes[newConfig];
733 mActiveConfig = newConfig;
734 activateDisplay();
735 ALOGD("%s config(%d) mode(%d)", __FUNCTION__, mActiveConfig, mCurrentMode);
736 return 0;
737}
738
739// returns false if the xres or yres of the new config do
740// not match the current config
741bool HDMIDisplay::isValidConfigChange(int newConfig) {
742 int newMode = mEDIDModes[newConfig];
743 uint32_t width = 0, height = 0, refresh = 0;
744 getAttrForConfig(newConfig, width, height, refresh);
745 return ((mXres == width) && (mYres == height)) || mEnableResolutionChange;
746}
747
748int HDMIDisplay::getModeIndex(int mode) {
749 int modeIndex = -1;
750 for(int i = 0; i < mModeCount; i++) {
751 if(mode == mEDIDModes[i]) {
752 modeIndex = i;
753 break;
754 }
755 }
756 return modeIndex;
757}
758
759int HDMIDisplay::getAttrForConfig(int config, uint32_t& xres,
760 uint32_t& yres, uint32_t& refresh) const {
761 if(config < 0 || config > mModeCount) {
762 ALOGE("%s Invalid configuration %d", __FUNCTION__, config);
763 return -EINVAL;
764 }
765 int mode = mEDIDModes[config];
766 uint32_t fps = 0;
767 // Retrieve the mode attributes from gEDIDData
768 for (int dataIndex = 0; dataIndex < gEDIDCount; dataIndex++) {
769 if (gEDIDData[dataIndex].mMode == mode) {
770 xres = gEDIDData[dataIndex].mWidth;
771 yres = gEDIDData[dataIndex].mHeight;
772 fps = gEDIDData[dataIndex].mFps;
773 }
774 }
775 refresh = (uint32_t) 1000000000l / fps;
776 ALOGD_IF(DEBUG, "%s xres(%d) yres(%d) fps(%d) refresh(%d)", __FUNCTION__,
777 xres, yres, fps, refresh);
778 return 0;
779}
780
781int HDMIDisplay::getDisplayConfigs(uint32_t* configs,
782 size_t* numConfigs) const {
783 if (*numConfigs <= 0) {
784 ALOGE("%s Invalid number of configs (%d)", __FUNCTION__, *numConfigs);
785 return -EINVAL;
786 }
787 *numConfigs = mModeCount;
788 for (int configIndex = 0; configIndex < mModeCount; configIndex++) {
789 configs[configIndex] = (uint32_t)configIndex;
790 }
791 return 0;
792}
793
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700794};