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