blob: 2142125fedd45d683f23e0cfac8a34069577b449 [file] [log] [blame]
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07004 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#define DEBUG 0
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070022#include <ctype.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070023#include <fcntl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070024#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 Ahmed72cf9762012-07-21 12:17:13 -070034#include <sys/resource.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070035#include <cutils/properties.h>
36#include "hwc_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070037#include "external.h"
38#include "overlayUtils.h"
39
40using namespace android;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070041
42namespace qhwc {
43
44
45#define DEVICE_ROOT "/sys/devices/virtual/graphics"
46#define DEVICE_NODE "fb1"
47
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070048#define SYSFS_EDID_MODES DEVICE_ROOT "/" DEVICE_NODE "/edid_modes"
49#define SYSFS_HPD DEVICE_ROOT "/" DEVICE_NODE "/hpd"
50
51
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070052ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1),
Saurabh Shah56f610d2012-08-07 15:27:06 -070053 mCurrentMode(-1), mExternalDisplay(0), mModeCount(0), mHwcContext(ctx)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070054{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070055 memset(&mVInfo, 0, sizeof(mVInfo));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070056 //Enable HPD for HDMI
57 writeHPDOption(1);
58}
59
Saurabh Shah56f610d2012-08-07 15:27:06 -070060void ExternalDisplay::setEDIDMode(int resMode) {
61 ALOGD_IF(DEBUG,"resMode=%d ", resMode);
62 int extDispType;
63 {
64 Mutex::Autolock lock(mExtDispLock);
65 extDispType = mExternalDisplay;
66 setExternalDisplay(0);
67 setResolution(resMode);
68 }
69 setExternalDisplay(extDispType);
70}
71
72void ExternalDisplay::setHPD(uint32_t startEnd) {
73 ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd);
74 writeHPDOption(startEnd);
75}
76
77void ExternalDisplay::setActionSafeDimension(int w, int h) {
78 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
79 Mutex::Autolock lock(mExtDispLock);
80 overlay::utils::ActionSafe::getInstance()->setDimension(w, h);
81 setExternalDisplay(mExternalDisplay);
82}
83
84int ExternalDisplay::getModeCount() const {
85 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
86 Mutex::Autolock lock(mExtDispLock);
87 return mModeCount;
88}
89
90void ExternalDisplay::getEDIDModes(int *out) const {
91 Mutex::Autolock lock(mExtDispLock);
92 for(int i = 0;i < mModeCount;i++) {
93 out[i] = mEDIDModes[i];
94 }
95}
96
97int ExternalDisplay::getExternalDisplay() const {
98 Mutex::Autolock lock(mExtDispLock);
99 return mExternalDisplay;
100}
101
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700102ExternalDisplay::~ExternalDisplay()
103{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700104 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700105}
106
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700107struct disp_mode_timing_type {
108 int video_format;
109
110 int active_h;
111 int active_v;
112
113 int front_porch_h;
114 int pulse_width_h;
115 int back_porch_h;
116
117 int front_porch_v;
118 int pulse_width_v;
119 int back_porch_v;
120
121 int pixel_freq;
122 bool interlaced;
123
124 void set_info(struct fb_var_screeninfo &info) const;
125};
126
127void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const
128{
129 info.reserved[0] = 0;
130 info.reserved[1] = 0;
131 info.reserved[2] = 0;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700132 info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700133
134 info.xoffset = 0;
135 info.yoffset = 0;
136 info.xres = active_h;
137 info.yres = active_v;
138
139 info.pixclock = pixel_freq*1000;
140 info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
141
142 info.right_margin = front_porch_h;
143 info.hsync_len = pulse_width_h;
144 info.left_margin = back_porch_h;
145 info.lower_margin = front_porch_v;
146 info.vsync_len = pulse_width_v;
147 info.upper_margin = back_porch_v;
148}
149
150/* Video formates supported by the HDMI Standard */
151/* Indicates the resolution, pix clock and the aspect ratio */
152#define m640x480p60_4_3 1
153#define m720x480p60_4_3 2
154#define m720x480p60_16_9 3
155#define m1280x720p60_16_9 4
156#define m1920x1080i60_16_9 5
157#define m1440x480i60_4_3 6
158#define m1440x480i60_16_9 7
159#define m1920x1080p60_16_9 16
160#define m720x576p50_4_3 17
161#define m720x576p50_16_9 18
162#define m1280x720p50_16_9 19
163#define m1440x576i50_4_3 21
164#define m1440x576i50_16_9 22
165#define m1920x1080p50_16_9 31
166#define m1920x1080p24_16_9 32
167#define m1920x1080p25_16_9 33
168#define m1920x1080p30_16_9 34
169
170static struct disp_mode_timing_type supported_video_mode_lut[] = {
171 {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false},
172 {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
173 {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
174 {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false},
175 {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false},
176 {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
177 {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
178 {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false},
179 {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
180 {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
181 {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false},
182 {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
183 {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
184 {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false},
185 {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false},
186 {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false},
187 {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false},
188};
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700189
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700190int ExternalDisplay::parseResolution(char* edidStr, int* edidModes)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700191{
192 char delim = ',';
193 int count = 0;
194 char *start, *end;
195 // EDIDs are string delimited by ','
196 // Ex: 16,4,5,3,32,34,1
197 // Parse this string to get mode(int)
198 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700199 end = &delim;
200 while(*end == delim) {
201 edidModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700202 start = end+1;
203 count++;
204 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700205 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
206 for (int i = 0; i < count; i++)
207 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700208 return count;
209}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700210
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700211bool ExternalDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700212{
213 int hdmiEDIDFile = open(SYSFS_EDID_MODES, O_RDONLY, 0);
214 int len = -1;
215
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700216 if (hdmiEDIDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700217 ALOGE("%s: edid_modes file '%s' not found",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700218 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700219 return false;
220 } else {
221 len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700222 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d",
223 __FUNCTION__, mEDIDs, len);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700224 if ( len <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700225 ALOGE("%s: edid_modes file empty '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700226 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700227 }
228 else {
229 while (len > 1 && isspace(mEDIDs[len-1]))
230 --len;
231 mEDIDs[len] = 0;
232 }
233 }
234 close(hdmiEDIDFile);
235 if(len > 0) {
236 // GEt EDID modes from the EDID strings
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700237 mModeCount = parseResolution(mEDIDs, mEDIDModes);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700238 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
239 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700240 }
241
242 return (strlen(mEDIDs) > 0);
243}
244
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700245bool ExternalDisplay::openFramebuffer()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700246{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700247 if (mFd == -1) {
248 mFd = open("/dev/graphics/fb1", O_RDWR);
249 if (mFd < 0)
250 ALOGE("%s: /dev/graphics/fb1 not available", __FUNCTION__);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700251 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700252 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700253}
254
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700255bool ExternalDisplay::closeFrameBuffer()
256{
257 int ret = 0;
258 if(mFd > 0) {
259 ret = close(mFd);
260 mFd = -1;
261 }
262 return (ret == 0);
263}
264
265// clears the vinfo, edid, best modes
266void ExternalDisplay::resetInfo()
267{
268 memset(&mVInfo, 0, sizeof(mVInfo));
269 memset(mEDIDs, 0, sizeof(mEDIDs));
270 memset(mEDIDModes, 0, sizeof(mEDIDModes));
271 mModeCount = 0;
272 mCurrentMode = -1;
273}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700274
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700275int ExternalDisplay::getModeOrder(int mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700276{
277 switch (mode) {
278 default:
279 case m1440x480i60_4_3:
280 return 1; // 480i 4:3
281 case m1440x480i60_16_9:
282 return 2; // 480i 16:9
283 case m1440x576i50_4_3:
284 return 3; // i576i 4:3
285 case m1440x576i50_16_9:
286 return 4; // 576i 16:9
287 case m640x480p60_4_3:
288 return 5; // 640x480 4:3
289 case m720x480p60_4_3:
290 return 6; // 480p 4:3
291 case m720x480p60_16_9:
292 return 7; // 480p 16:9
293 case m720x576p50_4_3:
294 return 8; // 576p 4:3
295 case m720x576p50_16_9:
296 return 9; // 576p 16:9
297 case m1920x1080i60_16_9:
298 return 10; // 1080i 16:9
299 case m1280x720p50_16_9:
300 return 11; // 720p@50Hz
301 case m1280x720p60_16_9:
302 return 12; // 720p@60Hz
303 case m1920x1080p24_16_9:
304 return 13; //1080p@24Hz
305 case m1920x1080p25_16_9:
306 return 14; //108-p@25Hz
307 case m1920x1080p30_16_9:
308 return 15; //1080p@30Hz
309 case m1920x1080p50_16_9:
310 return 16; //1080p@50Hz
311 case m1920x1080p60_16_9:
312 return 17; //1080p@60Hz
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700313 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700314}
315
316// Get the best mode for the current HD TV
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700317int ExternalDisplay::getBestMode() {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700318 int bestOrder = 0;
319 int bestMode = m640x480p60_4_3;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700320 Mutex::Autolock lock(mExtDispLock);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700321 // for all the edid read, get the best mode
322 for(int i = 0; i < mModeCount; i++) {
323 int mode = mEDIDModes[i];
324 int order = getModeOrder(mode);
325 if (order > bestOrder) {
326 bestOrder = order;
327 bestMode = mode;
328 }
329 }
330 return bestMode;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700331}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700332
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700333inline bool ExternalDisplay::isValidMode(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700334{
335 return ((ID >= m640x480p60_4_3) && (ID <= m1920x1080p30_16_9));
336}
337
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700338void ExternalDisplay::setResolution(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700339{
340 struct fb_var_screeninfo info;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700341 int ret = 0;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700342 if (!openFramebuffer())
343 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700344 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
345 if(ret < 0) {
346 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
347 strerror(errno));
348 }
349
350 ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
351 "(%d,%d,%d) %dMHz>", __FUNCTION__,
352 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
353 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
354 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
355 mVInfo.pixclock/1000/1000);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700356 //If its a valid mode and its a new ID - update var_screeninfo
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700357 if ((isValidMode(ID)) && mCurrentMode != ID) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700358 const struct disp_mode_timing_type *mode =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700359 &supported_video_mode_lut[0];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700360 unsigned count = sizeof(supported_video_mode_lut)/sizeof
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700361 (*supported_video_mode_lut);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700362 for (unsigned int i = 0; i < count; ++i) {
363 const struct disp_mode_timing_type *cur =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700364 &supported_video_mode_lut[i];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700365 if (cur->video_format == ID)
366 mode = cur;
367 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700368 mode->set_info(mVInfo);
369 ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700370 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID,
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700371 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
372 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
373 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
374 mVInfo.pixclock/1000/1000);
375 mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
376 ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
377 if(ret < 0) {
378 ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
379 __FUNCTION__, strerror(errno));
380 }
381 mCurrentMode = ID;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700382 }
383 //Powerup
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700384 ret = ioctl(mFd, FBIOBLANK, FB_BLANK_UNBLANK);
385 if(ret < 0) {
386 ALOGD("In %s: FBIOBLANK failed Err Str = %s", __FUNCTION__,
387 strerror(errno));
388 }
389 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
390 if(ret < 0) {
391 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
392 strerror(errno));
393 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700394 //Pan_Display
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700395 ret = ioctl(mFd, FBIOPAN_DISPLAY, &mVInfo);
396 if(ret < 0) {
397 ALOGD("In %s: FBIOPAN_DISPLAY failed Err Str = %s", __FUNCTION__,
398 strerror(errno));
399 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700400}
401
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700402void ExternalDisplay::setExternalDisplay(int connected)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700403{
404
405 hwc_context_t* ctx = mHwcContext;
406 if(ctx) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700407 ALOGD_IF(DEBUG, "%s: status = %d", __FUNCTION__,
408 connected);
409 if(connected) {
410 readResolution();
411 //Get the best mode and set
412 // TODO: DO NOT call this for WFD
413 setResolution(getBestMode());
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700414 //enable hdmi vsync
415 enableHDMIVsync(connected);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700416 } else {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700417 // Disable the hdmi vsync
418 enableHDMIVsync(connected);
419 closeFrameBuffer();
420 resetInfo();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700421 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700422 // Store the external display
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700423 mExternalDisplay = connected;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700424 const char* prop = (connected) ? "1" : "0";
425 // set system property
426 property_set("hw.hdmiON", prop);
Jesse Hall3be78d92012-08-21 15:12:23 -0700427 /* Trigger redraw */
428 ALOGD_IF(DEBUG, "%s: Invalidate !!", __FUNCTION__);
429 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700430 }
431 return;
432}
433
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700434bool ExternalDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700435{
436 bool ret = true;
437 int hdmiHPDFile = open(SYSFS_HPD,O_RDWR, 0);
438 if (hdmiHPDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700439 ALOGE("%s: state file '%s' not found : ret%d"
440 "err str: %s", __FUNCTION__, SYSFS_HPD, hdmiHPDFile,
441 strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700442 ret = false;
443 } else {
444 int err = -1;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700445 ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__,
446 userOption);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700447 if(userOption)
448 err = write(hdmiHPDFile, "1", 2);
449 else
450 err = write(hdmiHPDFile, "0" , 2);
451 if (err <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700452 ALOGE("%s: file write failed '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700453 __FUNCTION__, SYSFS_HPD);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700454 ret = false;
455 }
456 close(hdmiHPDFile);
457 }
458 return ret;
459}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700460
461bool ExternalDisplay::commit()
462{
463 if(mFd == -1) {
464 return false;
465 } else if(ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo) == -1) {
466 ALOGE("%s: FBIOPUT_VSCREENINFO failed, str: %s", __FUNCTION__,
467 strerror(errno));
468 return false;
469 }
470 return true;
471}
472
473int ExternalDisplay::enableHDMIVsync(int enable)
474{
475 if(mFd > 0) {
476 int ret = ioctl(mFd, MSMFB_OVERLAY_VSYNC_CTRL, &enable);
477 if (ret<0) {
478 ALOGE("%s: enabling HDMI vsync failed, str: %s", __FUNCTION__,
479 strerror(errno));
480 }
481 }
482 return -errno;
483}
484
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700485};
486