Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 4 | * |
| 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #define DEBUG 0 |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 22 | #include <ctype.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 23 | #include <fcntl.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 24 | #include <media/IAudioPolicyService.h> |
| 25 | #include <media/AudioSystem.h> |
| 26 | #include <utils/threads.h> |
| 27 | #include <utils/Errors.h> |
| 28 | #include <utils/Log.h> |
| 29 | |
| 30 | #include <linux/msm_mdp.h> |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 31 | #include <video/msm_hdmi_modes.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 32 | #include <linux/fb.h> |
| 33 | #include <sys/ioctl.h> |
| 34 | #include <sys/poll.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 35 | #include <sys/resource.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 36 | #include <cutils/properties.h> |
| 37 | #include "hwc_utils.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 38 | #include "external.h" |
| 39 | #include "overlayUtils.h" |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 40 | #include "overlay.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 41 | |
| 42 | using namespace android; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 43 | |
| 44 | namespace qhwc { |
| 45 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 46 | #define MAX_FRAME_BUFFER_NAME_SIZE (80) |
| 47 | #define MAX_DISPLAY_DEVICES (3) |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 48 | #define MAX_SYSFS_FILE_PATH 255 |
| 49 | #define UNKNOWN_STRING "unknown" |
| 50 | #define SPD_NAME_LENGTH 16 |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 51 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 52 | const char* msmFbDevicePath[] = { "/dev/graphics/fb1", |
| 53 | "/dev/graphics/fb2"}; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 54 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 55 | /* |
| 56 | * Updates extDeviceFbIndex Array with the correct frame buffer indices |
| 57 | * of avaiable external devices |
| 58 | * |
| 59 | */ |
| 60 | void ExternalDisplay::updateExtDispDevFbIndex() |
| 61 | { |
| 62 | FILE *displayDeviceFP = NULL; |
| 63 | char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 64 | char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 65 | |
| 66 | for(int j = 1; j < MAX_DISPLAY_DEVICES; j++) { |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 67 | snprintf (msmFbTypePath, sizeof(msmFbTypePath), |
| 68 | "/sys/class/graphics/fb%d/msm_fb_type", j); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 69 | displayDeviceFP = fopen(msmFbTypePath, "r"); |
| 70 | if(displayDeviceFP){ |
| 71 | fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, |
| 72 | displayDeviceFP); |
| 73 | if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0){ |
| 74 | ALOGD_IF(DEBUG,"hdmi framebuffer index is %d",j); |
| 75 | mHdmiFbNum = j; |
| 76 | } else if(strncmp(fbType, "writeback panel", |
| 77 | strlen("writeback panel")) == 0){ |
| 78 | ALOGD_IF(DEBUG,"wfd framebuffer index is %d",j); |
| 79 | mWfdFbNum = j; |
| 80 | } |
| 81 | fclose(displayDeviceFP); |
| 82 | } |
| 83 | } |
| 84 | ALOGD_IF(DEBUG,"%s: mHdmiFbNum: %d mWfdFbNum: %d ",__FUNCTION__, |
| 85 | mHdmiFbNum, mWfdFbNum); |
| 86 | } |
| 87 | |
| 88 | int ExternalDisplay::configureHDMIDisplay() { |
| 89 | openFrameBuffer(mHdmiFbNum); |
| 90 | if(mFd == -1) |
| 91 | return -1; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 92 | readCEUnderscanInfo(); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 93 | readResolution(); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 94 | // TODO: Move this to activate |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 95 | /* Used for changing the resolution |
| 96 | * getUserMode will get the preferred |
| 97 | * mode set thru adb shell */ |
| 98 | int mode = getUserMode(); |
| 99 | if (mode == -1) { |
| 100 | //Get the best mode and set |
| 101 | mode = getBestMode(); |
| 102 | } |
| 103 | setResolution(mode); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 104 | setDpyHdmiAttr(); |
| 105 | setExternalDisplay(true, mHdmiFbNum); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 106 | // set system property |
| 107 | property_set("hw.hdmiON", "1"); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | int ExternalDisplay::configureWFDDisplay() { |
| 112 | int ret = 0; |
| 113 | if(mConnectedFbNum == mHdmiFbNum) { |
| 114 | ALOGE("%s: Cannot process WFD connection while HDMI is active", |
| 115 | __FUNCTION__); |
| 116 | return -1; |
| 117 | } |
| 118 | openFrameBuffer(mWfdFbNum); |
| 119 | if(mFd == -1) |
| 120 | return -1; |
| 121 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 122 | if(ret < 0) { |
| 123 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 124 | strerror(errno)); |
| 125 | } |
| 126 | setDpyWfdAttr(); |
| 127 | setExternalDisplay(true, mWfdFbNum); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | int ExternalDisplay::teardownHDMIDisplay() { |
| 132 | if(mConnectedFbNum == mHdmiFbNum) { |
| 133 | // hdmi offline event..! |
| 134 | closeFrameBuffer(); |
| 135 | resetInfo(); |
| 136 | setExternalDisplay(false); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 137 | // unset system property |
| 138 | property_set("hw.hdmiON", "0"); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 139 | } |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int ExternalDisplay::teardownWFDDisplay() { |
| 144 | if(mConnectedFbNum == mWfdFbNum) { |
| 145 | // wfd offline event..! |
| 146 | closeFrameBuffer(); |
| 147 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 148 | setExternalDisplay(false); |
| 149 | } |
| 150 | return 0; |
| 151 | } |
| 152 | |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 153 | int ExternalDisplay::ignoreRequest(const char *str) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 154 | const char *s1 = str + strlen("change@/devices/virtual/switch/"); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 155 | if(!strncmp(s1,"wfd",strlen(s1))) { |
| 156 | if(mConnectedFbNum == mHdmiFbNum) { |
| 157 | ALOGE("Ignore wfd event when HDMI is active"); |
| 158 | return true; |
| 159 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 160 | } |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 161 | return false; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 164 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 165 | ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1), |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 166 | mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0), |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 167 | mUnderscanSupported(false), mHwcContext(ctx), mHdmiFbNum(-1), |
| 168 | mWfdFbNum(-1), mExtDpyNum(HWC_DISPLAY_EXTERNAL) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 169 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 170 | memset(&mVInfo, 0, sizeof(mVInfo)); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 171 | //Determine the fb index for external display devices. |
| 172 | updateExtDispDevFbIndex(); |
Arun Kumar K.R | e746ac5 | 2013-03-20 15:56:15 -0700 | [diff] [blame] | 173 | // disable HPD at start, it will be enabled later |
| 174 | // when the display powers on |
| 175 | // This helps for framework reboot or adb shell stop/start |
| 176 | writeHPDOption(0); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 177 | |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 178 | // for HDMI - retreive all the modes supported by the driver |
| 179 | if(mHdmiFbNum != -1) { |
| 180 | supported_video_mode_lut = |
| 181 | new msm_hdmi_mode_timing_info[HDMI_VFRMT_MAX]; |
| 182 | // Populate the mode table for supported modes |
| 183 | MSM_HDMI_MODES_INIT_TIMINGS(supported_video_mode_lut); |
| 184 | MSM_HDMI_MODES_SET_SUPP_TIMINGS(supported_video_mode_lut, |
| 185 | MSM_HDMI_MODES_ALL); |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 186 | // Update the Source Product Information |
| 187 | // Vendor Name |
| 188 | setSPDInfo("vendor_name", "ro.product.manufacturer"); |
| 189 | // Product Description |
| 190 | setSPDInfo("product_description", "ro.product.name"); |
| 191 | } |
| 192 | } |
| 193 | /* gets the product manufacturer and product name and writes it |
| 194 | * to the sysfs node, so that the driver can get that information |
| 195 | * Used to show QCOM 8974 instead of Input 1 for example |
| 196 | */ |
| 197 | void ExternalDisplay::setSPDInfo(const char* node, const char* property) { |
| 198 | int err = -1; |
| 199 | char info[PROPERTY_VALUE_MAX]; |
| 200 | char sysFsSPDFilePath[MAX_SYSFS_FILE_PATH]; |
| 201 | memset(sysFsSPDFilePath, 0, sizeof(sysFsSPDFilePath)); |
| 202 | snprintf(sysFsSPDFilePath , sizeof(sysFsSPDFilePath), |
| 203 | "/sys/devices/virtual/graphics/fb%d/%s", |
| 204 | mHdmiFbNum, node); |
| 205 | int spdFile = open(sysFsSPDFilePath, O_RDWR, 0); |
| 206 | if (spdFile < 0) { |
| 207 | ALOGE("%s: file '%s' not found : ret = %d" |
| 208 | "err str: %s", __FUNCTION__, sysFsSPDFilePath, |
| 209 | spdFile, strerror(errno)); |
| 210 | } else { |
| 211 | memset(info, 0, sizeof(info)); |
| 212 | property_get(property, info, UNKNOWN_STRING); |
| 213 | ALOGD_IF(DEBUG, "In %s: %s = %s", __FUNCTION__, property, info); |
| 214 | if (strncmp(info, UNKNOWN_STRING, SPD_NAME_LENGTH)) { |
| 215 | err = write(spdFile, info, strlen(info)); |
| 216 | if (err <= 0) { |
| 217 | ALOGE("%s: file write failed for '%s'" |
| 218 | "err no = %d", __FUNCTION__, sysFsSPDFilePath, errno); |
| 219 | } |
| 220 | } else { |
| 221 | ALOGD_IF(DEBUG, "%s: property_get failed for SPD %s", |
| 222 | __FUNCTION__, node); |
| 223 | } |
| 224 | close(spdFile); |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 225 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 228 | void ExternalDisplay::setEDIDMode(int resMode) { |
| 229 | ALOGD_IF(DEBUG,"resMode=%d ", resMode); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 230 | { |
| 231 | Mutex::Autolock lock(mExtDispLock); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 232 | setExternalDisplay(false); |
| 233 | openFrameBuffer(mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 234 | setResolution(resMode); |
| 235 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 236 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void ExternalDisplay::setHPD(uint32_t startEnd) { |
| 240 | ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd); |
| 241 | writeHPDOption(startEnd); |
| 242 | } |
| 243 | |
| 244 | void ExternalDisplay::setActionSafeDimension(int w, int h) { |
| 245 | ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h); |
| 246 | Mutex::Autolock lock(mExtDispLock); |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 247 | char actionsafeWidth[PROPERTY_VALUE_MAX]; |
| 248 | char actionsafeHeight[PROPERTY_VALUE_MAX]; |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 249 | snprintf(actionsafeWidth, sizeof(actionsafeWidth), "%d", w); |
Arun Kumar K.R | 4d73d64 | 2013-04-10 17:06:39 -0700 | [diff] [blame] | 250 | property_set("persist.sys.actionsafe.width", actionsafeWidth); |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 251 | snprintf(actionsafeHeight, sizeof(actionsafeHeight), "%d", h); |
Arun Kumar K.R | 4d73d64 | 2013-04-10 17:06:39 -0700 | [diff] [blame] | 252 | property_set("persist.sys.actionsafe.height", actionsafeHeight); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 253 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | int ExternalDisplay::getModeCount() const { |
| 257 | ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount); |
| 258 | Mutex::Autolock lock(mExtDispLock); |
| 259 | return mModeCount; |
| 260 | } |
| 261 | |
| 262 | void ExternalDisplay::getEDIDModes(int *out) const { |
| 263 | Mutex::Autolock lock(mExtDispLock); |
| 264 | for(int i = 0;i < mModeCount;i++) { |
| 265 | out[i] = mEDIDModes[i]; |
| 266 | } |
| 267 | } |
| 268 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 269 | void ExternalDisplay::readCEUnderscanInfo() |
| 270 | { |
| 271 | int hdmiScanInfoFile = -1; |
| 272 | int len = -1; |
| 273 | char scanInfo[17]; |
| 274 | char *ce_info_str = NULL; |
| 275 | const char token[] = ", \n"; |
| 276 | int ce_info = -1; |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 277 | char sysFsScanInfoFilePath[MAX_SYSFS_FILE_PATH]; |
| 278 | snprintf(sysFsScanInfoFilePath, sizeof(sysFsScanInfoFilePath), |
| 279 | "/sys/devices/virtual/graphics/fb%d/" |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 280 | "scan_info", mHdmiFbNum); |
| 281 | |
| 282 | memset(scanInfo, 0, sizeof(scanInfo)); |
| 283 | hdmiScanInfoFile = open(sysFsScanInfoFilePath, O_RDONLY, 0); |
| 284 | if (hdmiScanInfoFile < 0) { |
| 285 | ALOGD_IF(DEBUG, "%s: scan_info file '%s' not found", |
| 286 | __FUNCTION__, sysFsScanInfoFilePath); |
| 287 | return; |
| 288 | } else { |
| 289 | len = read(hdmiScanInfoFile, scanInfo, sizeof(scanInfo)-1); |
| 290 | ALOGD("%s: Scan Info string: %s length = %d", |
| 291 | __FUNCTION__, scanInfo, len); |
| 292 | if (len <= 0) { |
| 293 | close(hdmiScanInfoFile); |
| 294 | ALOGE("%s: Scan Info file empty '%s'", |
| 295 | __FUNCTION__, sysFsScanInfoFilePath); |
| 296 | return; |
| 297 | } |
| 298 | scanInfo[len] = '\0'; /* null terminate the string */ |
| 299 | } |
| 300 | close(hdmiScanInfoFile); |
| 301 | |
| 302 | /* |
| 303 | * The scan_info contains the three fields |
| 304 | * PT - preferred video format |
| 305 | * IT - video format |
| 306 | * CE video format - containing the underscan support information |
| 307 | */ |
| 308 | |
| 309 | /* PT */ |
| 310 | ce_info_str = strtok(scanInfo, token); |
| 311 | if (ce_info_str) { |
| 312 | /* IT */ |
| 313 | ce_info_str = strtok(NULL, token); |
| 314 | if (ce_info_str) { |
| 315 | /* CE */ |
| 316 | ce_info_str = strtok(NULL, token); |
| 317 | if (ce_info_str) |
| 318 | ce_info = atoi(ce_info_str); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if (ce_info_str) { |
| 323 | // ce_info contains the underscan information |
| 324 | if (ce_info == EXT_SCAN_ALWAYS_UNDERSCANED || |
| 325 | ce_info == EXT_SCAN_BOTH_SUPPORTED) |
| 326 | // if TV supported underscan, then driver will always underscan |
| 327 | // hence no need to apply action safe rectangle |
| 328 | mUnderscanSupported = true; |
| 329 | } else { |
| 330 | ALOGE("%s: scan_info string error", __FUNCTION__); |
| 331 | } |
| 332 | |
| 333 | // Store underscan support info in a system property |
| 334 | const char* prop = (mUnderscanSupported) ? "1" : "0"; |
| 335 | property_set("hw.underscan_supported", prop); |
| 336 | return; |
| 337 | } |
| 338 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 339 | ExternalDisplay::~ExternalDisplay() |
| 340 | { |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 341 | delete [] supported_video_mode_lut; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 342 | closeFrameBuffer(); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 345 | /* |
| 346 | * sets the fb_var_screeninfo from the hdmi_mode_timing_info |
| 347 | */ |
| 348 | void setDisplayTiming(struct fb_var_screeninfo &info, |
| 349 | const msm_hdmi_mode_timing_info* mode) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 350 | { |
| 351 | info.reserved[0] = 0; |
| 352 | info.reserved[1] = 0; |
| 353 | info.reserved[2] = 0; |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 354 | #ifndef FB_METADATA_VIDEO_INFO_CODE_SUPPORT |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 355 | info.reserved[3] = (info.reserved[3] & 0xFFFF) | |
| 356 | (mode->video_format << 16); |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 357 | #endif |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 358 | info.xoffset = 0; |
| 359 | info.yoffset = 0; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 360 | info.xres = mode->active_h; |
| 361 | info.yres = mode->active_v; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 362 | |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 363 | info.pixclock = (mode->pixel_freq)*1000; |
| 364 | info.vmode = mode->interlaced ? |
| 365 | FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 366 | |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 367 | info.right_margin = mode->front_porch_h; |
| 368 | info.hsync_len = mode->pulse_width_h; |
| 369 | info.left_margin = mode->back_porch_h; |
| 370 | info.lower_margin = mode->front_porch_v; |
| 371 | info.vsync_len = mode->pulse_width_v; |
| 372 | info.upper_margin = mode->back_porch_v; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 375 | int ExternalDisplay::parseResolution(char* edidStr, int* edidModes) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 376 | { |
| 377 | char delim = ','; |
| 378 | int count = 0; |
| 379 | char *start, *end; |
| 380 | // EDIDs are string delimited by ',' |
| 381 | // Ex: 16,4,5,3,32,34,1 |
| 382 | // Parse this string to get mode(int) |
| 383 | start = (char*) edidStr; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 384 | end = &delim; |
| 385 | while(*end == delim) { |
| 386 | edidModes[count] = (int) strtol(start, &end, 10); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 387 | start = end+1; |
| 388 | count++; |
| 389 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 390 | ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count); |
| 391 | for (int i = 0; i < count; i++) |
| 392 | ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 393 | return count; |
| 394 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 395 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 396 | bool ExternalDisplay::readResolution() |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 397 | { |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 398 | char sysFsEDIDFilePath[MAX_SYSFS_FILE_PATH]; |
| 399 | snprintf(sysFsEDIDFilePath , sizeof(sysFsEDIDFilePath), |
| 400 | "/sys/devices/virtual/graphics/fb%d/edid_modes", mHdmiFbNum); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 401 | |
| 402 | int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 403 | int len = -1; |
| 404 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 405 | if (hdmiEDIDFile < 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 406 | ALOGE("%s: edid_modes file '%s' not found", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 407 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 408 | return false; |
| 409 | } else { |
| 410 | len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 411 | ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d", |
| 412 | __FUNCTION__, mEDIDs, len); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 413 | if ( len <= 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 414 | ALOGE("%s: edid_modes file empty '%s'", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 415 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 416 | } |
| 417 | else { |
| 418 | while (len > 1 && isspace(mEDIDs[len-1])) |
| 419 | --len; |
| 420 | mEDIDs[len] = 0; |
| 421 | } |
| 422 | } |
| 423 | close(hdmiEDIDFile); |
| 424 | if(len > 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 425 | // Get EDID modes from the EDID strings |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 426 | mModeCount = parseResolution(mEDIDs, mEDIDModes); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 427 | ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, |
| 428 | mModeCount); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | return (strlen(mEDIDs) > 0); |
| 432 | } |
| 433 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 434 | bool ExternalDisplay::openFrameBuffer(int fbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 435 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 436 | if (mFd == -1) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 437 | mFd = open(msmFbDevicePath[fbNum-1], O_RDWR); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 438 | if (mFd < 0) |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 439 | ALOGE("%s: %s is not available", __FUNCTION__, |
| 440 | msmFbDevicePath[fbNum-1]); |
| 441 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 442 | mHwcContext->dpyAttr[mExtDpyNum].fd = mFd; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 443 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 444 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 445 | return (mFd > 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 448 | bool ExternalDisplay::closeFrameBuffer() |
| 449 | { |
| 450 | int ret = 0; |
Naseer Ahmed | f53b377 | 2013-02-15 19:13:50 -0500 | [diff] [blame] | 451 | if(mFd >= 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 452 | ret = close(mFd); |
| 453 | mFd = -1; |
| 454 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 455 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 456 | mHwcContext->dpyAttr[mExtDpyNum].fd = mFd; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 457 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 458 | return (ret == 0); |
| 459 | } |
| 460 | |
| 461 | // clears the vinfo, edid, best modes |
| 462 | void ExternalDisplay::resetInfo() |
| 463 | { |
| 464 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 465 | memset(mEDIDs, 0, sizeof(mEDIDs)); |
| 466 | memset(mEDIDModes, 0, sizeof(mEDIDModes)); |
| 467 | mModeCount = 0; |
| 468 | mCurrentMode = -1; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 469 | mUnderscanSupported = false; |
| 470 | // Reset the underscan supported system property |
| 471 | const char* prop = "0"; |
| 472 | property_set("hw.underscan_supported", prop); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 473 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 474 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 475 | int ExternalDisplay::getModeOrder(int mode) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 476 | { |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 477 | // XXX: We dont support interlaced modes but having |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 478 | // it here for future |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 479 | switch (mode) { |
| 480 | default: |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 481 | case HDMI_VFRMT_1440x480i60_4_3: |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 482 | return 1; // 480i 4:3 |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 483 | case HDMI_VFRMT_1440x480i60_16_9: |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 484 | return 2; // 480i 16:9 |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 485 | case HDMI_VFRMT_1440x576i50_4_3: |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 486 | return 3; // i576i 4:3 |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 487 | case HDMI_VFRMT_1440x576i50_16_9: |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 488 | return 4; // 576i 16:9 |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 489 | case HDMI_VFRMT_1920x1080i60_16_9: |
Arun Kumar K.R | 6ce73ff | 2013-01-24 19:48:24 -0800 | [diff] [blame] | 490 | return 5; // 1080i 16:9 |
| 491 | case HDMI_VFRMT_640x480p60_4_3: |
| 492 | return 6; // 640x480 4:3 |
| 493 | case HDMI_VFRMT_720x480p60_4_3: |
| 494 | return 7; // 480p 4:3 |
| 495 | case HDMI_VFRMT_720x480p60_16_9: |
| 496 | return 8; // 480p 16:9 |
| 497 | case HDMI_VFRMT_720x576p50_4_3: |
| 498 | return 9; // 576p 4:3 |
| 499 | case HDMI_VFRMT_720x576p50_16_9: |
| 500 | return 10; // 576p 16:9 |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 501 | case HDMI_VFRMT_1024x768p60_4_3: |
| 502 | return 11; // 768p 4:3 Vesa format |
Arun Kumar K.R | 6ce73ff | 2013-01-24 19:48:24 -0800 | [diff] [blame] | 503 | case HDMI_VFRMT_1280x1024p60_5_4: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 504 | return 12; // 1024p Vesa format |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 505 | case HDMI_VFRMT_1280x720p50_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 506 | return 13; // 720p@50Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 507 | case HDMI_VFRMT_1280x720p60_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 508 | return 14; // 720p@60Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 509 | case HDMI_VFRMT_1920x1080p24_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 510 | return 15; //1080p@24Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 511 | case HDMI_VFRMT_1920x1080p25_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 512 | return 16; //108-p@25Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 513 | case HDMI_VFRMT_1920x1080p30_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 514 | return 17; //1080p@30Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 515 | case HDMI_VFRMT_1920x1080p50_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 516 | return 18; //1080p@50Hz |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 517 | case HDMI_VFRMT_1920x1080p60_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 518 | return 19; //1080p@60Hz |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 519 | case HDMI_VFRMT_2560x1600p60_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 520 | return 20; //WQXGA@60Hz541 |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 521 | case HDMI_VFRMT_3840x2160p24_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 522 | return 21;//2160@24Hz |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 523 | case HDMI_VFRMT_3840x2160p25_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 524 | return 22;//2160@25Hz |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 525 | case HDMI_VFRMT_3840x2160p30_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 526 | return 23; //2160@30Hz |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 527 | case HDMI_VFRMT_4096x2160p24_16_9: |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 528 | return 24; //4kx2k@24Hz |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 529 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 532 | /// Returns the user mode set(if any) using adb shell |
| 533 | int ExternalDisplay::getUserMode() { |
| 534 | /* Based on the property set the resolution */ |
| 535 | char property_value[PROPERTY_VALUE_MAX]; |
Arun Kumar K.R | c31bdcb | 2013-02-25 17:47:42 -0800 | [diff] [blame] | 536 | property_get("hw.hdmi.resolution", property_value, "-1"); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 537 | int mode = atoi(property_value); |
| 538 | // We dont support interlaced modes |
| 539 | if(isValidMode(mode) && !isInterlacedMode(mode)) { |
Naseer Ahmed | 7421472 | 2013-02-09 08:11:36 -0500 | [diff] [blame] | 540 | ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 541 | return mode; |
| 542 | } |
| 543 | return -1; |
| 544 | } |
| 545 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 546 | // Get the best mode for the current HD TV |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 547 | int ExternalDisplay::getBestMode() { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 548 | int bestOrder = 0; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 549 | int bestMode = HDMI_VFRMT_640x480p60_4_3; |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 550 | Mutex::Autolock lock(mExtDispLock); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 551 | // for all the edid read, get the best mode |
| 552 | for(int i = 0; i < mModeCount; i++) { |
| 553 | int mode = mEDIDModes[i]; |
| 554 | int order = getModeOrder(mode); |
| 555 | if (order > bestOrder) { |
| 556 | bestOrder = order; |
| 557 | bestMode = mode; |
| 558 | } |
| 559 | } |
| 560 | return bestMode; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 561 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 562 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 563 | inline bool ExternalDisplay::isValidMode(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 564 | { |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 565 | bool valid = false; |
| 566 | for (int i = 0; i < mModeCount; i++) { |
| 567 | if(ID == mEDIDModes[i]) { |
| 568 | valid = true; |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | return valid; |
| 573 | } |
| 574 | |
| 575 | // returns true if the mode(ID) is interlaced mode format |
| 576 | bool ExternalDisplay::isInterlacedMode(int ID) { |
| 577 | bool interlaced = false; |
| 578 | switch(ID) { |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 579 | case HDMI_VFRMT_1440x480i60_4_3: |
| 580 | case HDMI_VFRMT_1440x480i60_16_9: |
| 581 | case HDMI_VFRMT_1440x576i50_4_3: |
| 582 | case HDMI_VFRMT_1440x576i50_16_9: |
| 583 | case HDMI_VFRMT_1920x1080i60_16_9: |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 584 | interlaced = true; |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 585 | break; |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 586 | default: |
| 587 | interlaced = false; |
Arun Kumar K.R | ae46f3a | 2013-05-16 16:40:10 -0700 | [diff] [blame] | 588 | break; |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 589 | } |
| 590 | return interlaced; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 593 | void ExternalDisplay::setResolution(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 594 | { |
| 595 | struct fb_var_screeninfo info; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 596 | int ret = 0; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 597 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 598 | if(ret < 0) { |
| 599 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 600 | strerror(errno)); |
| 601 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 602 | ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d)," |
| 603 | "(%d,%d,%d) %dMHz>", __FUNCTION__, |
| 604 | mVInfo.reserved[3], mVInfo.xres, mVInfo.yres, |
| 605 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 606 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 607 | mVInfo.pixclock/1000/1000); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 608 | //If its a new ID - update var_screeninfo |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 609 | if ((isValidMode(ID)) && mCurrentMode != ID) { |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 610 | const struct msm_hdmi_mode_timing_info *mode = |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 611 | &supported_video_mode_lut[0]; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 612 | for (unsigned int i = 0; i < HDMI_VFRMT_MAX; ++i) { |
| 613 | const struct msm_hdmi_mode_timing_info *cur = |
| 614 | &supported_video_mode_lut[i]; |
| 615 | if (cur->video_format == (uint32_t)ID) { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 616 | mode = cur; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 617 | break; |
| 618 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 619 | } |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 620 | setDisplayTiming(mVInfo, mode); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 621 | ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 622 | "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID, |
Arun Kumar K.R | e1cea3e | 2013-02-06 16:57:43 -0800 | [diff] [blame] | 623 | mode->video_format, mVInfo.xres, mVInfo.yres, |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 624 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 625 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 626 | mVInfo.pixclock/1000/1000); |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 627 | #ifdef FB_METADATA_VIDEO_INFO_CODE_SUPPORT |
| 628 | struct msmfb_metadata metadata; |
| 629 | memset(&metadata, 0 , sizeof(metadata)); |
| 630 | metadata.op = metadata_op_vic; |
| 631 | metadata.data.video_info_code = mode->video_format; |
| 632 | if (ioctl(mFd, MSMFB_METADATA_SET, &metadata) == -1) { |
| 633 | ALOGD("In %s: MSMFB_METADATA_SET failed Err Str = %s", |
| 634 | __FUNCTION__, strerror(errno)); |
| 635 | } |
| 636 | #endif |
Arun Kumar K.R | e1cea3e | 2013-02-06 16:57:43 -0800 | [diff] [blame] | 637 | mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE; |
| 638 | ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo); |
| 639 | if(ret < 0) { |
| 640 | ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s", |
| 641 | __FUNCTION__, strerror(errno)); |
| 642 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 643 | mCurrentMode = ID; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 644 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 647 | void ExternalDisplay::setExternalDisplay(bool connected, int extFbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 648 | { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 649 | hwc_context_t* ctx = mHwcContext; |
| 650 | if(ctx) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 651 | ALOGD_IF(DEBUG, "%s: connected = %d", __FUNCTION__, connected); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 652 | // Store the external display |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 653 | mConnected = connected; |
| 654 | mConnectedFbNum = extFbNum; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 655 | mHwcContext->dpyAttr[mExtDpyNum].connected = connected; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 656 | // Update external fb number in Overlay context |
| 657 | overlay::Overlay::getInstance()->setExtFbNum(extFbNum); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 658 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | int ExternalDisplay::getExtFbNum(int &fbNum) { |
| 662 | int ret = -1; |
| 663 | if(mConnected) { |
| 664 | fbNum = mConnectedFbNum; |
| 665 | ret = 0; |
| 666 | } |
| 667 | return ret; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 670 | bool ExternalDisplay::writeHPDOption(int userOption) const |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 671 | { |
| 672 | bool ret = true; |
Arun Kumar K.R | 26808f3 | 2013-02-11 19:17:05 -0800 | [diff] [blame] | 673 | char sysFsHPDFilePath[MAX_SYSFS_FILE_PATH]; |
| 674 | snprintf(sysFsHPDFilePath ,sizeof(sysFsHPDFilePath), |
| 675 | "/sys/devices/virtual/graphics/fb%d/hpd", mHdmiFbNum); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 676 | int hdmiHPDFile = open(sysFsHPDFilePath,O_RDWR, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 677 | if (hdmiHPDFile < 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 678 | ALOGE("%s: state file '%s' not found : ret%d err str: %s", __FUNCTION__, |
| 679 | sysFsHPDFilePath, hdmiHPDFile, strerror(errno)); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 680 | ret = false; |
| 681 | } else { |
| 682 | int err = -1; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 683 | ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__, userOption); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 684 | if(userOption) |
| 685 | err = write(hdmiHPDFile, "1", 2); |
| 686 | else |
| 687 | err = write(hdmiHPDFile, "0" , 2); |
| 688 | if (err <= 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 689 | ALOGE("%s: file write failed '%s'", __FUNCTION__, sysFsHPDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 690 | ret = false; |
| 691 | } |
| 692 | close(hdmiHPDFile); |
| 693 | } |
| 694 | return ret; |
| 695 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 696 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 697 | void ExternalDisplay::setDpyWfdAttr() { |
| 698 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 699 | mHwcContext->dpyAttr[mExtDpyNum].xres = mVInfo.xres; |
| 700 | mHwcContext->dpyAttr[mExtDpyNum].yres = mVInfo.yres; |
| 701 | mHwcContext->dpyAttr[mExtDpyNum].vsync_period = |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 702 | 1000000000l /60; |
| 703 | ALOGD_IF(DEBUG,"%s: wfd...connected..!",__FUNCTION__); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | void ExternalDisplay::setDpyHdmiAttr() { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 708 | int width = 0, height = 0, fps = 0; |
| 709 | getAttrForMode(width, height, fps); |
| 710 | if(mHwcContext) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 711 | ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 712 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width; |
| 713 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 714 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period = |
| 715 | 1000000000l / fps; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 716 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 719 | void ExternalDisplay::getAttrForMode(int& width, int& height, int& fps) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 720 | switch (mCurrentMode) { |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 721 | case HDMI_VFRMT_640x480p60_4_3: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 722 | width = 640; |
| 723 | height = 480; |
| 724 | fps = 60; |
| 725 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 726 | case HDMI_VFRMT_720x480p60_4_3: |
| 727 | case HDMI_VFRMT_720x480p60_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 728 | width = 720; |
| 729 | height = 480; |
| 730 | fps = 60; |
| 731 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 732 | case HDMI_VFRMT_720x576p50_4_3: |
| 733 | case HDMI_VFRMT_720x576p50_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 734 | width = 720; |
| 735 | height = 576; |
| 736 | fps = 50; |
| 737 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 738 | case HDMI_VFRMT_1280x720p50_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 739 | width = 1280; |
| 740 | height = 720; |
| 741 | fps = 50; |
| 742 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 743 | case HDMI_VFRMT_1280x720p60_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 744 | width = 1280; |
| 745 | height = 720; |
| 746 | fps = 60; |
| 747 | break; |
Arun Kumar K.R | 6ce73ff | 2013-01-24 19:48:24 -0800 | [diff] [blame] | 748 | case HDMI_VFRMT_1280x1024p60_5_4: |
| 749 | width = 1280; |
| 750 | height = 1024; |
| 751 | fps = 60; |
| 752 | break; |
Manoj Rao | 564ee92 | 2013-05-07 21:32:57 -0700 | [diff] [blame] | 753 | case HDMI_VFRMT_1024x768p60_4_3: |
| 754 | width = 1024; |
| 755 | height = 768; |
| 756 | fps = 60; |
| 757 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 758 | case HDMI_VFRMT_1920x1080p24_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 759 | width = 1920; |
| 760 | height = 1080; |
| 761 | fps = 24; |
| 762 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 763 | case HDMI_VFRMT_1920x1080p25_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 764 | width = 1920; |
| 765 | height = 1080; |
| 766 | fps = 25; |
| 767 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 768 | case HDMI_VFRMT_1920x1080p30_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 769 | width = 1920; |
| 770 | height = 1080; |
| 771 | fps = 30; |
| 772 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 773 | case HDMI_VFRMT_1920x1080p50_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 774 | width = 1920; |
| 775 | height = 1080; |
| 776 | fps = 50; |
| 777 | break; |
Arun Kumar K.R | 2518757 | 2013-02-28 18:47:36 -0800 | [diff] [blame] | 778 | case HDMI_VFRMT_1920x1080p60_16_9: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 779 | width = 1920; |
| 780 | height = 1080; |
| 781 | fps = 60; |
| 782 | break; |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 783 | case HDMI_VFRMT_2560x1600p60_16_9: |
| 784 | width = 2560; |
| 785 | height = 1600; |
| 786 | fps = 60; |
| 787 | break; |
| 788 | case HDMI_VFRMT_3840x2160p24_16_9: |
| 789 | width = 3840; |
| 790 | height = 2160; |
| 791 | fps = 24; |
| 792 | break; |
Arun Kumar K.R | 92ebf9d | 2013-04-09 19:23:14 -0700 | [diff] [blame] | 793 | case HDMI_VFRMT_3840x2160p25_16_9: |
| 794 | width = 3840; |
| 795 | height = 2160; |
| 796 | fps = 25; |
| 797 | break; |
Ujwal Patel | b9430d2 | 2012-11-15 18:10:19 -0800 | [diff] [blame] | 798 | case HDMI_VFRMT_3840x2160p30_16_9: |
| 799 | width = 3840; |
| 800 | height = 2160; |
| 801 | fps = 30; |
| 802 | break; |
| 803 | case HDMI_VFRMT_4096x2160p24_16_9: |
| 804 | width = 4096; |
| 805 | height = 2160; |
| 806 | fps = 24; |
| 807 | break; |
| 808 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 809 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 812 | }; |