blob: 92a129b8ee55ecb6f1f1075768db597e8152083a [file] [log] [blame]
Saurabh Shah3825f252012-09-21 16:32:18 -07001
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07002/*
3 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07004 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07005 *
6 * Not a Contribution, Apache license notifications and license are
7 * retained for attribution purposes only.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#define DEBUG 0
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070023#include <ctype.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070024#include <fcntl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070025#include <media/IAudioPolicyService.h>
26#include <media/AudioSystem.h>
27#include <utils/threads.h>
28#include <utils/Errors.h>
29#include <utils/Log.h>
30
31#include <linux/msm_mdp.h>
32#include <linux/fb.h>
33#include <sys/ioctl.h>
34#include <sys/poll.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070035#include <sys/resource.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070036#include <cutils/properties.h>
37#include "hwc_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070038#include "external.h"
39#include "overlayUtils.h"
40
41using namespace android;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070042
43namespace qhwc {
44
45
46#define DEVICE_ROOT "/sys/devices/virtual/graphics"
47#define DEVICE_NODE "fb1"
48
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070049#define SYSFS_EDID_MODES DEVICE_ROOT "/" DEVICE_NODE "/edid_modes"
50#define SYSFS_HPD DEVICE_ROOT "/" DEVICE_NODE "/hpd"
51
52
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070053ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1),
Saurabh Shah56f610d2012-08-07 15:27:06 -070054 mCurrentMode(-1), mExternalDisplay(0), mModeCount(0), mHwcContext(ctx)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070055{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070056 memset(&mVInfo, 0, sizeof(mVInfo));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070057 //Enable HPD for HDMI
58 writeHPDOption(1);
59}
60
Saurabh Shah56f610d2012-08-07 15:27:06 -070061void ExternalDisplay::setEDIDMode(int resMode) {
62 ALOGD_IF(DEBUG,"resMode=%d ", resMode);
63 int extDispType;
64 {
65 Mutex::Autolock lock(mExtDispLock);
66 extDispType = mExternalDisplay;
67 setExternalDisplay(0);
68 setResolution(resMode);
69 }
70 setExternalDisplay(extDispType);
71}
72
73void ExternalDisplay::setHPD(uint32_t startEnd) {
74 ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd);
75 writeHPDOption(startEnd);
76}
77
78void ExternalDisplay::setActionSafeDimension(int w, int h) {
79 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
80 Mutex::Autolock lock(mExtDispLock);
81 overlay::utils::ActionSafe::getInstance()->setDimension(w, h);
82 setExternalDisplay(mExternalDisplay);
83}
84
85int ExternalDisplay::getModeCount() const {
86 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
87 Mutex::Autolock lock(mExtDispLock);
88 return mModeCount;
89}
90
91void ExternalDisplay::getEDIDModes(int *out) const {
92 Mutex::Autolock lock(mExtDispLock);
93 for(int i = 0;i < mModeCount;i++) {
94 out[i] = mEDIDModes[i];
95 }
96}
97
Naseer Ahmed72cf9762012-07-21 12:17:13 -070098ExternalDisplay::~ExternalDisplay()
99{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700100 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700101}
102
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700103struct disp_mode_timing_type {
104 int video_format;
105
106 int active_h;
107 int active_v;
108
109 int front_porch_h;
110 int pulse_width_h;
111 int back_porch_h;
112
113 int front_porch_v;
114 int pulse_width_v;
115 int back_porch_v;
116
117 int pixel_freq;
118 bool interlaced;
119
120 void set_info(struct fb_var_screeninfo &info) const;
121};
122
123void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const
124{
125 info.reserved[0] = 0;
126 info.reserved[1] = 0;
127 info.reserved[2] = 0;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700128 info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700129
130 info.xoffset = 0;
131 info.yoffset = 0;
132 info.xres = active_h;
133 info.yres = active_v;
134
135 info.pixclock = pixel_freq*1000;
136 info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
137
138 info.right_margin = front_porch_h;
139 info.hsync_len = pulse_width_h;
140 info.left_margin = back_porch_h;
141 info.lower_margin = front_porch_v;
142 info.vsync_len = pulse_width_v;
143 info.upper_margin = back_porch_v;
144}
145
146/* Video formates supported by the HDMI Standard */
147/* Indicates the resolution, pix clock and the aspect ratio */
148#define m640x480p60_4_3 1
149#define m720x480p60_4_3 2
150#define m720x480p60_16_9 3
151#define m1280x720p60_16_9 4
152#define m1920x1080i60_16_9 5
153#define m1440x480i60_4_3 6
154#define m1440x480i60_16_9 7
155#define m1920x1080p60_16_9 16
156#define m720x576p50_4_3 17
157#define m720x576p50_16_9 18
158#define m1280x720p50_16_9 19
159#define m1440x576i50_4_3 21
160#define m1440x576i50_16_9 22
161#define m1920x1080p50_16_9 31
162#define m1920x1080p24_16_9 32
163#define m1920x1080p25_16_9 33
164#define m1920x1080p30_16_9 34
165
166static struct disp_mode_timing_type supported_video_mode_lut[] = {
167 {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false},
168 {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
169 {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
170 {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false},
171 {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false},
172 {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
173 {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
174 {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false},
175 {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
176 {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
177 {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false},
178 {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
179 {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
180 {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false},
181 {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false},
182 {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false},
183 {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false},
184};
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700185
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700186int ExternalDisplay::parseResolution(char* edidStr, int* edidModes)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700187{
188 char delim = ',';
189 int count = 0;
190 char *start, *end;
191 // EDIDs are string delimited by ','
192 // Ex: 16,4,5,3,32,34,1
193 // Parse this string to get mode(int)
194 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700195 end = &delim;
196 while(*end == delim) {
197 edidModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700198 start = end+1;
199 count++;
200 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700201 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
202 for (int i = 0; i < count; i++)
203 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700204 return count;
205}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700206
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700207bool ExternalDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700208{
209 int hdmiEDIDFile = open(SYSFS_EDID_MODES, O_RDONLY, 0);
210 int len = -1;
211
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700212 if (hdmiEDIDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700213 ALOGE("%s: edid_modes file '%s' not found",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700214 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700215 return false;
216 } else {
217 len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700218 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d",
219 __FUNCTION__, mEDIDs, len);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700220 if ( len <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700221 ALOGE("%s: edid_modes file empty '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700222 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700223 }
224 else {
225 while (len > 1 && isspace(mEDIDs[len-1]))
226 --len;
227 mEDIDs[len] = 0;
228 }
229 }
230 close(hdmiEDIDFile);
231 if(len > 0) {
232 // GEt EDID modes from the EDID strings
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700233 mModeCount = parseResolution(mEDIDs, mEDIDModes);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
235 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700236 }
237
238 return (strlen(mEDIDs) > 0);
239}
240
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700241bool ExternalDisplay::openFramebuffer()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700242{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700243 if (mFd == -1) {
244 mFd = open("/dev/graphics/fb1", O_RDWR);
245 if (mFd < 0)
246 ALOGE("%s: /dev/graphics/fb1 not available", __FUNCTION__);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700247 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700248 if(mHwcContext) {
249 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
250 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700251 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700252}
253
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700254bool ExternalDisplay::closeFrameBuffer()
255{
256 int ret = 0;
257 if(mFd > 0) {
258 ret = close(mFd);
259 mFd = -1;
260 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700261 if(mHwcContext) {
262 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
263 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700264 return (ret == 0);
265}
266
267// clears the vinfo, edid, best modes
268void ExternalDisplay::resetInfo()
269{
270 memset(&mVInfo, 0, sizeof(mVInfo));
271 memset(mEDIDs, 0, sizeof(mEDIDs));
272 memset(mEDIDModes, 0, sizeof(mEDIDModes));
273 mModeCount = 0;
274 mCurrentMode = -1;
275}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700276
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700277int ExternalDisplay::getModeOrder(int mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700278{
279 switch (mode) {
280 default:
281 case m1440x480i60_4_3:
282 return 1; // 480i 4:3
283 case m1440x480i60_16_9:
284 return 2; // 480i 16:9
285 case m1440x576i50_4_3:
286 return 3; // i576i 4:3
287 case m1440x576i50_16_9:
288 return 4; // 576i 16:9
289 case m640x480p60_4_3:
290 return 5; // 640x480 4:3
291 case m720x480p60_4_3:
292 return 6; // 480p 4:3
293 case m720x480p60_16_9:
294 return 7; // 480p 16:9
295 case m720x576p50_4_3:
296 return 8; // 576p 4:3
297 case m720x576p50_16_9:
298 return 9; // 576p 16:9
299 case m1920x1080i60_16_9:
300 return 10; // 1080i 16:9
301 case m1280x720p50_16_9:
302 return 11; // 720p@50Hz
303 case m1280x720p60_16_9:
304 return 12; // 720p@60Hz
305 case m1920x1080p24_16_9:
306 return 13; //1080p@24Hz
307 case m1920x1080p25_16_9:
308 return 14; //108-p@25Hz
309 case m1920x1080p30_16_9:
310 return 15; //1080p@30Hz
311 case m1920x1080p50_16_9:
312 return 16; //1080p@50Hz
313 case m1920x1080p60_16_9:
314 return 17; //1080p@60Hz
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700315 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700316}
317
318// Get the best mode for the current HD TV
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700319int ExternalDisplay::getBestMode() {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700320 int bestOrder = 0;
321 int bestMode = m640x480p60_4_3;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700322 Mutex::Autolock lock(mExtDispLock);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700323 // for all the edid read, get the best mode
324 for(int i = 0; i < mModeCount; i++) {
325 int mode = mEDIDModes[i];
326 int order = getModeOrder(mode);
327 if (order > bestOrder) {
328 bestOrder = order;
329 bestMode = mode;
330 }
331 }
332 return bestMode;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700333}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700334
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700335inline bool ExternalDisplay::isValidMode(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700336{
337 return ((ID >= m640x480p60_4_3) && (ID <= m1920x1080p30_16_9));
338}
339
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700340void ExternalDisplay::setResolution(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700341{
342 struct fb_var_screeninfo info;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700343 int ret = 0;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700344 if (!openFramebuffer())
345 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700346 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
347 if(ret < 0) {
348 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
349 strerror(errno));
350 }
351
352 ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
353 "(%d,%d,%d) %dMHz>", __FUNCTION__,
354 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
355 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
356 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
357 mVInfo.pixclock/1000/1000);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700358 //If its a valid mode and its a new ID - update var_screeninfo
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700359 if ((isValidMode(ID)) && mCurrentMode != ID) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700360 const struct disp_mode_timing_type *mode =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700361 &supported_video_mode_lut[0];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700362 unsigned count = sizeof(supported_video_mode_lut)/sizeof
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700363 (*supported_video_mode_lut);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700364 for (unsigned int i = 0; i < count; ++i) {
365 const struct disp_mode_timing_type *cur =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700366 &supported_video_mode_lut[i];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700367 if (cur->video_format == ID)
368 mode = cur;
369 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700370 mode->set_info(mVInfo);
371 ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700372 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID,
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700373 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
374 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
375 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
376 mVInfo.pixclock/1000/1000);
377 mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
378 ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
379 if(ret < 0) {
380 ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
381 __FUNCTION__, strerror(errno));
382 }
383 mCurrentMode = ID;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700384 }
385 //Powerup
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700386 ret = ioctl(mFd, FBIOBLANK, FB_BLANK_UNBLANK);
387 if(ret < 0) {
388 ALOGD("In %s: FBIOBLANK failed Err Str = %s", __FUNCTION__,
389 strerror(errno));
390 }
391 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
392 if(ret < 0) {
393 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
394 strerror(errno));
395 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700396 //Pan_Display
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700397 ret = ioctl(mFd, FBIOPAN_DISPLAY, &mVInfo);
398 if(ret < 0) {
399 ALOGD("In %s: FBIOPAN_DISPLAY failed Err Str = %s", __FUNCTION__,
400 strerror(errno));
401 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700402}
403
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700404void ExternalDisplay::setExternalDisplay(int connected)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700405{
406
407 hwc_context_t* ctx = mHwcContext;
408 if(ctx) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700409 ALOGD_IF(DEBUG, "%s: status = %d", __FUNCTION__,
410 connected);
411 if(connected) {
412 readResolution();
413 //Get the best mode and set
414 // TODO: DO NOT call this for WFD
415 setResolution(getBestMode());
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700416 setDpyAttr();
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700417 //enable hdmi vsync
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700418 } else {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700419 // Disable the hdmi vsync
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700420 closeFrameBuffer();
421 resetInfo();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700422 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700423 // Store the external display
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700424 mExternalDisplay = connected;
Saurabh Shah3825f252012-09-21 16:32:18 -0700425 ALOGD_IF(DEBUG, "In %s: mExternalDisplay = %d", __FUNCTION__,
426 mExternalDisplay);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700427 const char* prop = (connected) ? "1" : "0";
428 // set system property
429 property_set("hw.hdmiON", prop);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700430 //Inform SF
431 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
Saurabh Shah86623d72012-09-25 19:39:17 -0700432 //TODO remove invalidate send hotplug
433 //ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, connected);
434 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = connected;
435 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700436 }
437 return;
438}
439
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700440bool ExternalDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700441{
442 bool ret = true;
443 int hdmiHPDFile = open(SYSFS_HPD,O_RDWR, 0);
444 if (hdmiHPDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700445 ALOGE("%s: state file '%s' not found : ret%d"
446 "err str: %s", __FUNCTION__, SYSFS_HPD, hdmiHPDFile,
447 strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700448 ret = false;
449 } else {
450 int err = -1;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700451 ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__,
452 userOption);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700453 if(userOption)
454 err = write(hdmiHPDFile, "1", 2);
455 else
456 err = write(hdmiHPDFile, "0" , 2);
457 if (err <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700458 ALOGE("%s: file write failed '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700459 __FUNCTION__, SYSFS_HPD);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700460 ret = false;
461 }
462 close(hdmiHPDFile);
463 }
464 return ret;
465}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700466
Saurabh Shah3825f252012-09-21 16:32:18 -0700467/*
468 * commits the changes to the external display
469 * mExternalDisplay has the mixer number(1-> HDMI 2-> WFD)
470 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700471bool ExternalDisplay::post()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700472{
473 if(mFd == -1) {
474 return false;
Saurabh Shah3825f252012-09-21 16:32:18 -0700475 } else if(ioctl(mFd, MSMFB_OVERLAY_COMMIT, &mExternalDisplay) == -1) {
476 ALOGE("%s: MSMFB_OVERLAY_COMMIT failed, str: %s", __FUNCTION__,
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700477 strerror(errno));
478 return false;
479 }
480 return true;
481}
482
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700483void ExternalDisplay::setDpyAttr() {
484 int width = 0, height = 0, fps = 0;
485 getAttrForMode(width, height, fps);
486 if(mHwcContext) {
487 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
488 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
489 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period = 1000000000l /
490 fps;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700491 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700492}
493
494void ExternalDisplay::getAttrForMode(int& width, int& height,
495int& fps) {
496 switch (mCurrentMode) {
497 case m640x480p60_4_3:
498 width = 640;
499 height = 480;
500 fps = 60;
501 break;
502 case m720x480p60_4_3:
503 case m720x480p60_16_9:
504 width = 720;
505 height = 480;
506 fps = 60;
507 break;
508 case m720x576p50_4_3:
509 case m720x576p50_16_9:
510 width = 720;
511 height = 576;
512 fps = 50;
513 break;
514 case m1280x720p50_16_9:
515 width = 1280;
516 height = 720;
517 fps = 50;
518 break;
519 case m1280x720p60_16_9:
520 width = 1280;
521 height = 720;
522 fps = 60;
523 break;
524 case m1920x1080p24_16_9:
525 width = 1920;
526 height = 1080;
527 fps = 24;
528 break;
529 case m1920x1080p25_16_9:
530 width = 1920;
531 height = 1080;
532 fps = 25;
533 break;
534 case m1920x1080p30_16_9:
535 width = 1920;
536 height = 1080;
537 fps = 30;
538 break;
539 case m1920x1080p50_16_9:
540 width = 1920;
541 height = 1080;
542 fps = 50;
543 break;
544 case m1920x1080p60_16_9:
545 width = 1920;
546 height = 1080;
547 fps = 60;
548 break;
549 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700550}
551
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700552};
553