blob: f00d551d7510c0520a964885d18e7916e23ea2a0 [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 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700385}
386
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700387void ExternalDisplay::setExternalDisplay(int connected)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700388{
389
390 hwc_context_t* ctx = mHwcContext;
391 if(ctx) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700392 ALOGD_IF(DEBUG, "%s: status = %d", __FUNCTION__,
393 connected);
394 if(connected) {
395 readResolution();
396 //Get the best mode and set
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700397 // TODO: Move this to activate
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700398 setResolution(getBestMode());
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700399 setDpyAttr();
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700400 //enable hdmi vsync
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700401 } else {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700402 // Disable the hdmi vsync
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700403 closeFrameBuffer();
404 resetInfo();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700405 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700406 // Store the external display
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700407 mExternalDisplay = connected;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700408 const char* prop = (connected) ? "1" : "0";
409 // set system property
410 property_set("hw.hdmiON", prop);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700411 }
412 return;
413}
414
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700415bool ExternalDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700416{
417 bool ret = true;
418 int hdmiHPDFile = open(SYSFS_HPD,O_RDWR, 0);
419 if (hdmiHPDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700420 ALOGE("%s: state file '%s' not found : ret%d"
421 "err str: %s", __FUNCTION__, SYSFS_HPD, hdmiHPDFile,
422 strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700423 ret = false;
424 } else {
425 int err = -1;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700426 ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__,
427 userOption);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700428 if(userOption)
429 err = write(hdmiHPDFile, "1", 2);
430 else
431 err = write(hdmiHPDFile, "0" , 2);
432 if (err <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700433 ALOGE("%s: file write failed '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700434 __FUNCTION__, SYSFS_HPD);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700435 ret = false;
436 }
437 close(hdmiHPDFile);
438 }
439 return ret;
440}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700441
Saurabh Shah3825f252012-09-21 16:32:18 -0700442/*
443 * commits the changes to the external display
444 * mExternalDisplay has the mixer number(1-> HDMI 2-> WFD)
445 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700446bool ExternalDisplay::post()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700447{
448 if(mFd == -1) {
449 return false;
Saurabh Shah3825f252012-09-21 16:32:18 -0700450 } else if(ioctl(mFd, MSMFB_OVERLAY_COMMIT, &mExternalDisplay) == -1) {
451 ALOGE("%s: MSMFB_OVERLAY_COMMIT failed, str: %s", __FUNCTION__,
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700452 strerror(errno));
453 return false;
454 }
455 return true;
456}
457
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700458void ExternalDisplay::setDpyAttr() {
459 int width = 0, height = 0, fps = 0;
460 getAttrForMode(width, height, fps);
461 if(mHwcContext) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700462 ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700463 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
464 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700465 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period =
466 1000000000l / fps;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700467 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700468}
469
470void ExternalDisplay::getAttrForMode(int& width, int& height,
471int& fps) {
472 switch (mCurrentMode) {
473 case m640x480p60_4_3:
474 width = 640;
475 height = 480;
476 fps = 60;
477 break;
478 case m720x480p60_4_3:
479 case m720x480p60_16_9:
480 width = 720;
481 height = 480;
482 fps = 60;
483 break;
484 case m720x576p50_4_3:
485 case m720x576p50_16_9:
486 width = 720;
487 height = 576;
488 fps = 50;
489 break;
490 case m1280x720p50_16_9:
491 width = 1280;
492 height = 720;
493 fps = 50;
494 break;
495 case m1280x720p60_16_9:
496 width = 1280;
497 height = 720;
498 fps = 60;
499 break;
500 case m1920x1080p24_16_9:
501 width = 1920;
502 height = 1080;
503 fps = 24;
504 break;
505 case m1920x1080p25_16_9:
506 width = 1920;
507 height = 1080;
508 fps = 25;
509 break;
510 case m1920x1080p30_16_9:
511 width = 1920;
512 height = 1080;
513 fps = 30;
514 break;
515 case m1920x1080p50_16_9:
516 width = 1920;
517 height = 1080;
518 fps = 50;
519 break;
520 case m1920x1080p60_16_9:
521 width = 1920;
522 height = 1080;
523 fps = 60;
524 break;
525 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700526}
527
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700528};
529