Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, 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> |
| 31 | #include <linux/fb.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/poll.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 34 | #include <sys/resource.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 35 | #include <cutils/properties.h> |
| 36 | #include "hwc_utils.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 37 | #include "external.h" |
| 38 | #include "overlayUtils.h" |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 39 | #include "overlay.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 40 | |
| 41 | using namespace android; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 42 | |
| 43 | namespace qhwc { |
| 44 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 45 | #define MAX_FRAME_BUFFER_NAME_SIZE (80) |
| 46 | #define MAX_DISPLAY_DEVICES (3) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 47 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 48 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 49 | const char* msmFbDevicePath[] = { "/dev/graphics/fb1", |
| 50 | "/dev/graphics/fb2"}; |
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 | /* |
| 53 | * Updates extDeviceFbIndex Array with the correct frame buffer indices |
| 54 | * of avaiable external devices |
| 55 | * |
| 56 | */ |
| 57 | void ExternalDisplay::updateExtDispDevFbIndex() |
| 58 | { |
| 59 | FILE *displayDeviceFP = NULL; |
| 60 | char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 61 | char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 62 | |
| 63 | for(int j = 1; j < MAX_DISPLAY_DEVICES; j++) { |
| 64 | sprintf (msmFbTypePath,"/sys/class/graphics/fb%d/msm_fb_type", j); |
| 65 | displayDeviceFP = fopen(msmFbTypePath, "r"); |
| 66 | if(displayDeviceFP){ |
| 67 | fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, |
| 68 | displayDeviceFP); |
| 69 | if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0){ |
| 70 | ALOGD_IF(DEBUG,"hdmi framebuffer index is %d",j); |
| 71 | mHdmiFbNum = j; |
| 72 | } else if(strncmp(fbType, "writeback panel", |
| 73 | strlen("writeback panel")) == 0){ |
| 74 | ALOGD_IF(DEBUG,"wfd framebuffer index is %d",j); |
| 75 | mWfdFbNum = j; |
| 76 | } |
| 77 | fclose(displayDeviceFP); |
| 78 | } |
| 79 | } |
| 80 | ALOGD_IF(DEBUG,"%s: mHdmiFbNum: %d mWfdFbNum: %d ",__FUNCTION__, |
| 81 | mHdmiFbNum, mWfdFbNum); |
| 82 | } |
| 83 | |
| 84 | int ExternalDisplay::configureHDMIDisplay() { |
| 85 | openFrameBuffer(mHdmiFbNum); |
| 86 | if(mFd == -1) |
| 87 | return -1; |
| 88 | readResolution(); |
| 89 | //Get the best mode and set |
| 90 | // TODO: Move this to activate |
| 91 | setResolution(getBestMode()); |
| 92 | setDpyHdmiAttr(); |
| 93 | setExternalDisplay(true, mHdmiFbNum); |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | int ExternalDisplay::configureWFDDisplay() { |
| 98 | int ret = 0; |
| 99 | if(mConnectedFbNum == mHdmiFbNum) { |
| 100 | ALOGE("%s: Cannot process WFD connection while HDMI is active", |
| 101 | __FUNCTION__); |
| 102 | return -1; |
| 103 | } |
| 104 | openFrameBuffer(mWfdFbNum); |
| 105 | if(mFd == -1) |
| 106 | return -1; |
| 107 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 108 | if(ret < 0) { |
| 109 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 110 | strerror(errno)); |
| 111 | } |
| 112 | setDpyWfdAttr(); |
| 113 | setExternalDisplay(true, mWfdFbNum); |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int ExternalDisplay::teardownHDMIDisplay() { |
| 118 | if(mConnectedFbNum == mHdmiFbNum) { |
| 119 | // hdmi offline event..! |
| 120 | closeFrameBuffer(); |
| 121 | resetInfo(); |
| 122 | setExternalDisplay(false); |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int ExternalDisplay::teardownWFDDisplay() { |
| 128 | if(mConnectedFbNum == mWfdFbNum) { |
| 129 | // wfd offline event..! |
| 130 | closeFrameBuffer(); |
| 131 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 132 | setExternalDisplay(false); |
| 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | void ExternalDisplay::processUEventOnline(const char *str) { |
| 138 | const char *s1 = str + strlen("change@/devices/virtual/switch/"); |
| 139 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 140 | // hdmi online event..! |
| 141 | configureHDMIDisplay(); |
| 142 | }else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 143 | // wfd online event..! |
| 144 | configureWFDDisplay(); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void ExternalDisplay::processUEventOffline(const char *str) { |
| 149 | const char *s1 = str + strlen("change@/devices/virtual/switch/"); |
| 150 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 151 | teardownHDMIDisplay(); |
| 152 | }else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 153 | teardownWFDDisplay(); |
| 154 | } |
| 155 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 156 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 157 | ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1), |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 158 | mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0), |
| 159 | mHwcContext(ctx), mHdmiFbNum(-1), mWfdFbNum(-1) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 160 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 161 | memset(&mVInfo, 0, sizeof(mVInfo)); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 162 | //Determine the fb index for external display devices. |
| 163 | updateExtDispDevFbIndex(); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 166 | void ExternalDisplay::setEDIDMode(int resMode) { |
| 167 | ALOGD_IF(DEBUG,"resMode=%d ", resMode); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 168 | { |
| 169 | Mutex::Autolock lock(mExtDispLock); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 170 | setExternalDisplay(false); |
| 171 | openFrameBuffer(mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 172 | setResolution(resMode); |
| 173 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 174 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void ExternalDisplay::setHPD(uint32_t startEnd) { |
| 178 | ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd); |
| 179 | writeHPDOption(startEnd); |
| 180 | } |
| 181 | |
| 182 | void ExternalDisplay::setActionSafeDimension(int w, int h) { |
| 183 | ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h); |
| 184 | Mutex::Autolock lock(mExtDispLock); |
| 185 | overlay::utils::ActionSafe::getInstance()->setDimension(w, h); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 186 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | int ExternalDisplay::getModeCount() const { |
| 190 | ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount); |
| 191 | Mutex::Autolock lock(mExtDispLock); |
| 192 | return mModeCount; |
| 193 | } |
| 194 | |
| 195 | void ExternalDisplay::getEDIDModes(int *out) const { |
| 196 | Mutex::Autolock lock(mExtDispLock); |
| 197 | for(int i = 0;i < mModeCount;i++) { |
| 198 | out[i] = mEDIDModes[i]; |
| 199 | } |
| 200 | } |
| 201 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 202 | ExternalDisplay::~ExternalDisplay() |
| 203 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 204 | closeFrameBuffer(); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 207 | struct disp_mode_timing_type { |
| 208 | int video_format; |
| 209 | |
| 210 | int active_h; |
| 211 | int active_v; |
| 212 | |
| 213 | int front_porch_h; |
| 214 | int pulse_width_h; |
| 215 | int back_porch_h; |
| 216 | |
| 217 | int front_porch_v; |
| 218 | int pulse_width_v; |
| 219 | int back_porch_v; |
| 220 | |
| 221 | int pixel_freq; |
| 222 | bool interlaced; |
| 223 | |
| 224 | void set_info(struct fb_var_screeninfo &info) const; |
| 225 | }; |
| 226 | |
| 227 | void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const |
| 228 | { |
| 229 | info.reserved[0] = 0; |
| 230 | info.reserved[1] = 0; |
| 231 | info.reserved[2] = 0; |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 232 | info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 233 | |
| 234 | info.xoffset = 0; |
| 235 | info.yoffset = 0; |
| 236 | info.xres = active_h; |
| 237 | info.yres = active_v; |
| 238 | |
| 239 | info.pixclock = pixel_freq*1000; |
| 240 | info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED; |
| 241 | |
| 242 | info.right_margin = front_porch_h; |
| 243 | info.hsync_len = pulse_width_h; |
| 244 | info.left_margin = back_porch_h; |
| 245 | info.lower_margin = front_porch_v; |
| 246 | info.vsync_len = pulse_width_v; |
| 247 | info.upper_margin = back_porch_v; |
| 248 | } |
| 249 | |
| 250 | /* Video formates supported by the HDMI Standard */ |
| 251 | /* Indicates the resolution, pix clock and the aspect ratio */ |
| 252 | #define m640x480p60_4_3 1 |
| 253 | #define m720x480p60_4_3 2 |
| 254 | #define m720x480p60_16_9 3 |
| 255 | #define m1280x720p60_16_9 4 |
| 256 | #define m1920x1080i60_16_9 5 |
| 257 | #define m1440x480i60_4_3 6 |
| 258 | #define m1440x480i60_16_9 7 |
| 259 | #define m1920x1080p60_16_9 16 |
| 260 | #define m720x576p50_4_3 17 |
| 261 | #define m720x576p50_16_9 18 |
| 262 | #define m1280x720p50_16_9 19 |
| 263 | #define m1440x576i50_4_3 21 |
| 264 | #define m1440x576i50_16_9 22 |
| 265 | #define m1920x1080p50_16_9 31 |
| 266 | #define m1920x1080p24_16_9 32 |
| 267 | #define m1920x1080p25_16_9 33 |
| 268 | #define m1920x1080p30_16_9 34 |
| 269 | |
| 270 | static struct disp_mode_timing_type supported_video_mode_lut[] = { |
| 271 | {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false}, |
| 272 | {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false}, |
| 273 | {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false}, |
| 274 | {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false}, |
| 275 | {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false}, |
| 276 | {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true}, |
| 277 | {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true}, |
| 278 | {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false}, |
| 279 | {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false}, |
| 280 | {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false}, |
| 281 | {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false}, |
| 282 | {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true}, |
| 283 | {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true}, |
| 284 | {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false}, |
| 285 | {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false}, |
| 286 | {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false}, |
| 287 | {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false}, |
| 288 | }; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 289 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 290 | int ExternalDisplay::parseResolution(char* edidStr, int* edidModes) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 291 | { |
| 292 | char delim = ','; |
| 293 | int count = 0; |
| 294 | char *start, *end; |
| 295 | // EDIDs are string delimited by ',' |
| 296 | // Ex: 16,4,5,3,32,34,1 |
| 297 | // Parse this string to get mode(int) |
| 298 | start = (char*) edidStr; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 299 | end = &delim; |
| 300 | while(*end == delim) { |
| 301 | edidModes[count] = (int) strtol(start, &end, 10); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 302 | start = end+1; |
| 303 | count++; |
| 304 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 305 | ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count); |
| 306 | for (int i = 0; i < count; i++) |
| 307 | ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 308 | return count; |
| 309 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 310 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 311 | bool ExternalDisplay::readResolution() |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 312 | { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 313 | char sysFsEDIDFilePath[255]; |
| 314 | sprintf(sysFsEDIDFilePath , "/sys/devices/virtual/graphics/fb%d/edid_modes", |
| 315 | mHdmiFbNum); |
| 316 | |
| 317 | int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 318 | int len = -1; |
| 319 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 320 | if (hdmiEDIDFile < 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 321 | ALOGE("%s: edid_modes file '%s' not found", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 322 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 323 | return false; |
| 324 | } else { |
| 325 | len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 326 | ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d", |
| 327 | __FUNCTION__, mEDIDs, len); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 328 | if ( len <= 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 329 | ALOGE("%s: edid_modes file empty '%s'", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 330 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 331 | } |
| 332 | else { |
| 333 | while (len > 1 && isspace(mEDIDs[len-1])) |
| 334 | --len; |
| 335 | mEDIDs[len] = 0; |
| 336 | } |
| 337 | } |
| 338 | close(hdmiEDIDFile); |
| 339 | if(len > 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 340 | // Get EDID modes from the EDID strings |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 341 | mModeCount = parseResolution(mEDIDs, mEDIDModes); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 342 | ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, |
| 343 | mModeCount); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | return (strlen(mEDIDs) > 0); |
| 347 | } |
| 348 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 349 | bool ExternalDisplay::openFrameBuffer(int fbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 350 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 351 | if (mFd == -1) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 352 | mFd = open(msmFbDevicePath[fbNum-1], O_RDWR); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 353 | if (mFd < 0) |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 354 | ALOGE("%s: %s is not available", __FUNCTION__, |
| 355 | msmFbDevicePath[fbNum-1]); |
| 356 | if(mHwcContext) { |
| 357 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd; |
| 358 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 359 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 360 | return (mFd > 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 363 | bool ExternalDisplay::closeFrameBuffer() |
| 364 | { |
| 365 | int ret = 0; |
| 366 | if(mFd > 0) { |
| 367 | ret = close(mFd); |
| 368 | mFd = -1; |
| 369 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 370 | if(mHwcContext) { |
| 371 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd; |
| 372 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 373 | return (ret == 0); |
| 374 | } |
| 375 | |
| 376 | // clears the vinfo, edid, best modes |
| 377 | void ExternalDisplay::resetInfo() |
| 378 | { |
| 379 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 380 | memset(mEDIDs, 0, sizeof(mEDIDs)); |
| 381 | memset(mEDIDModes, 0, sizeof(mEDIDModes)); |
| 382 | mModeCount = 0; |
| 383 | mCurrentMode = -1; |
| 384 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 385 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 386 | int ExternalDisplay::getModeOrder(int mode) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 387 | { |
| 388 | switch (mode) { |
| 389 | default: |
| 390 | case m1440x480i60_4_3: |
| 391 | return 1; // 480i 4:3 |
| 392 | case m1440x480i60_16_9: |
| 393 | return 2; // 480i 16:9 |
| 394 | case m1440x576i50_4_3: |
| 395 | return 3; // i576i 4:3 |
| 396 | case m1440x576i50_16_9: |
| 397 | return 4; // 576i 16:9 |
| 398 | case m640x480p60_4_3: |
| 399 | return 5; // 640x480 4:3 |
| 400 | case m720x480p60_4_3: |
| 401 | return 6; // 480p 4:3 |
| 402 | case m720x480p60_16_9: |
| 403 | return 7; // 480p 16:9 |
| 404 | case m720x576p50_4_3: |
| 405 | return 8; // 576p 4:3 |
| 406 | case m720x576p50_16_9: |
| 407 | return 9; // 576p 16:9 |
| 408 | case m1920x1080i60_16_9: |
| 409 | return 10; // 1080i 16:9 |
| 410 | case m1280x720p50_16_9: |
| 411 | return 11; // 720p@50Hz |
| 412 | case m1280x720p60_16_9: |
| 413 | return 12; // 720p@60Hz |
| 414 | case m1920x1080p24_16_9: |
| 415 | return 13; //1080p@24Hz |
| 416 | case m1920x1080p25_16_9: |
| 417 | return 14; //108-p@25Hz |
| 418 | case m1920x1080p30_16_9: |
| 419 | return 15; //1080p@30Hz |
| 420 | case m1920x1080p50_16_9: |
| 421 | return 16; //1080p@50Hz |
| 422 | case m1920x1080p60_16_9: |
| 423 | return 17; //1080p@60Hz |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 424 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | // Get the best mode for the current HD TV |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 428 | int ExternalDisplay::getBestMode() { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 429 | int bestOrder = 0; |
| 430 | int bestMode = m640x480p60_4_3; |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 431 | Mutex::Autolock lock(mExtDispLock); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 432 | // for all the edid read, get the best mode |
| 433 | for(int i = 0; i < mModeCount; i++) { |
| 434 | int mode = mEDIDModes[i]; |
| 435 | int order = getModeOrder(mode); |
| 436 | if (order > bestOrder) { |
| 437 | bestOrder = order; |
| 438 | bestMode = mode; |
| 439 | } |
| 440 | } |
| 441 | return bestMode; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 442 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 443 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 444 | inline bool ExternalDisplay::isValidMode(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 445 | { |
| 446 | return ((ID >= m640x480p60_4_3) && (ID <= m1920x1080p30_16_9)); |
| 447 | } |
| 448 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 449 | void ExternalDisplay::setResolution(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 450 | { |
| 451 | struct fb_var_screeninfo info; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 452 | int ret = 0; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 453 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 454 | if(ret < 0) { |
| 455 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 456 | strerror(errno)); |
| 457 | } |
| 458 | |
| 459 | ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d)," |
| 460 | "(%d,%d,%d) %dMHz>", __FUNCTION__, |
| 461 | mVInfo.reserved[3], mVInfo.xres, mVInfo.yres, |
| 462 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 463 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 464 | mVInfo.pixclock/1000/1000); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 465 | //If its a valid mode and its a new ID - update var_screeninfo |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 466 | if ((isValidMode(ID)) && mCurrentMode != ID) { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 467 | const struct disp_mode_timing_type *mode = |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 468 | &supported_video_mode_lut[0]; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 469 | unsigned count = sizeof(supported_video_mode_lut)/sizeof |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 470 | (*supported_video_mode_lut); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 471 | for (unsigned int i = 0; i < count; ++i) { |
| 472 | const struct disp_mode_timing_type *cur = |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 473 | &supported_video_mode_lut[i]; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 474 | if (cur->video_format == ID) |
| 475 | mode = cur; |
| 476 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 477 | mode->set_info(mVInfo); |
| 478 | 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] | 479 | "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID, |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 480 | mVInfo.reserved[3], mVInfo.xres, mVInfo.yres, |
| 481 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 482 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 483 | mVInfo.pixclock/1000/1000); |
| 484 | mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE; |
| 485 | ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo); |
| 486 | if(ret < 0) { |
| 487 | ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s", |
| 488 | __FUNCTION__, strerror(errno)); |
| 489 | } |
| 490 | mCurrentMode = ID; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 491 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 494 | void ExternalDisplay::setExternalDisplay(bool connected, int extFbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 495 | { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 496 | hwc_context_t* ctx = mHwcContext; |
| 497 | if(ctx) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 498 | ALOGD_IF(DEBUG, "%s: connected = %d", __FUNCTION__, connected); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 499 | // Store the external display |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 500 | mConnected = connected; |
| 501 | mConnectedFbNum = extFbNum; |
| 502 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = connected; |
| 503 | // Update external fb number in Overlay context |
| 504 | overlay::Overlay::getInstance()->setExtFbNum(extFbNum); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 505 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | int ExternalDisplay::getExtFbNum(int &fbNum) { |
| 509 | int ret = -1; |
| 510 | if(mConnected) { |
| 511 | fbNum = mConnectedFbNum; |
| 512 | ret = 0; |
| 513 | } |
| 514 | return ret; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 517 | bool ExternalDisplay::writeHPDOption(int userOption) const |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 518 | { |
| 519 | bool ret = true; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 520 | char sysFsHPDFilePath[255]; |
| 521 | sprintf(sysFsHPDFilePath ,"/sys/devices/virtual/graphics/fb%d/hpd", |
| 522 | mHdmiFbNum); |
| 523 | int hdmiHPDFile = open(sysFsHPDFilePath,O_RDWR, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 524 | if (hdmiHPDFile < 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 525 | ALOGE("%s: state file '%s' not found : ret%d err str: %s", __FUNCTION__, |
| 526 | sysFsHPDFilePath, hdmiHPDFile, strerror(errno)); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 527 | ret = false; |
| 528 | } else { |
| 529 | int err = -1; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 530 | ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__, userOption); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 531 | if(userOption) |
| 532 | err = write(hdmiHPDFile, "1", 2); |
| 533 | else |
| 534 | err = write(hdmiHPDFile, "0" , 2); |
| 535 | if (err <= 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 536 | ALOGE("%s: file write failed '%s'", __FUNCTION__, sysFsHPDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 537 | ret = false; |
| 538 | } |
| 539 | close(hdmiHPDFile); |
| 540 | } |
| 541 | return ret; |
| 542 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 543 | |
Saurabh Shah | 3825f25 | 2012-09-21 16:32:18 -0700 | [diff] [blame] | 544 | /* |
| 545 | * commits the changes to the external display |
Saurabh Shah | 3825f25 | 2012-09-21 16:32:18 -0700 | [diff] [blame] | 546 | */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 547 | bool ExternalDisplay::post() |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 548 | { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 549 | if(mFd == -1) |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 550 | return false; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 551 | struct mdp_display_commit ext_commit; |
Naseer Ahmed | 9da8466 | 2012-12-06 19:29:29 -0500 | [diff] [blame^] | 552 | memset(&ext_commit, 0, sizeof(struct mdp_display_commit)); |
| 553 | ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 554 | if (ioctl(mFd, MSMFB_DISPLAY_COMMIT, &ext_commit) == -1) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 555 | ALOGE("%s: MSMFB_DISPLAY_COMMIT for external failed, str: %s", |
| 556 | __FUNCTION__, strerror(errno)); |
| 557 | return false; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 558 | } |
| 559 | return true; |
| 560 | } |
| 561 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 562 | void ExternalDisplay::setDpyWfdAttr() { |
| 563 | if(mHwcContext) { |
| 564 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = mVInfo.xres; |
| 565 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = mVInfo.yres; |
| 566 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period = |
| 567 | 1000000000l /60; |
| 568 | ALOGD_IF(DEBUG,"%s: wfd...connected..!",__FUNCTION__); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | void ExternalDisplay::setDpyHdmiAttr() { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 573 | int width = 0, height = 0, fps = 0; |
| 574 | getAttrForMode(width, height, fps); |
| 575 | if(mHwcContext) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 576 | ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 577 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width; |
| 578 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 579 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period = |
| 580 | 1000000000l / fps; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 581 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 584 | void ExternalDisplay::getAttrForMode(int& width, int& height, int& fps) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 585 | switch (mCurrentMode) { |
| 586 | case m640x480p60_4_3: |
| 587 | width = 640; |
| 588 | height = 480; |
| 589 | fps = 60; |
| 590 | break; |
| 591 | case m720x480p60_4_3: |
| 592 | case m720x480p60_16_9: |
| 593 | width = 720; |
| 594 | height = 480; |
| 595 | fps = 60; |
| 596 | break; |
| 597 | case m720x576p50_4_3: |
| 598 | case m720x576p50_16_9: |
| 599 | width = 720; |
| 600 | height = 576; |
| 601 | fps = 50; |
| 602 | break; |
| 603 | case m1280x720p50_16_9: |
| 604 | width = 1280; |
| 605 | height = 720; |
| 606 | fps = 50; |
| 607 | break; |
| 608 | case m1280x720p60_16_9: |
| 609 | width = 1280; |
| 610 | height = 720; |
| 611 | fps = 60; |
| 612 | break; |
| 613 | case m1920x1080p24_16_9: |
| 614 | width = 1920; |
| 615 | height = 1080; |
| 616 | fps = 24; |
| 617 | break; |
| 618 | case m1920x1080p25_16_9: |
| 619 | width = 1920; |
| 620 | height = 1080; |
| 621 | fps = 25; |
| 622 | break; |
| 623 | case m1920x1080p30_16_9: |
| 624 | width = 1920; |
| 625 | height = 1080; |
| 626 | fps = 30; |
| 627 | break; |
| 628 | case m1920x1080p50_16_9: |
| 629 | width = 1920; |
| 630 | height = 1080; |
| 631 | fps = 50; |
| 632 | break; |
| 633 | case m1920x1080p60_16_9: |
| 634 | width = 1920; |
| 635 | height = 1080; |
| 636 | fps = 60; |
| 637 | break; |
| 638 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 641 | }; |