blob: 28fbd580b06416aaa7f360ad6e2b9a39a660bc52 [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}
58
Saurabh Shah56f610d2012-08-07 15:27:06 -070059void ExternalDisplay::setEDIDMode(int resMode) {
60 ALOGD_IF(DEBUG,"resMode=%d ", resMode);
61 int extDispType;
62 {
63 Mutex::Autolock lock(mExtDispLock);
64 extDispType = mExternalDisplay;
65 setExternalDisplay(0);
66 setResolution(resMode);
67 }
68 setExternalDisplay(extDispType);
69}
70
71void ExternalDisplay::setHPD(uint32_t startEnd) {
72 ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd);
73 writeHPDOption(startEnd);
74}
75
76void ExternalDisplay::setActionSafeDimension(int w, int h) {
77 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
78 Mutex::Autolock lock(mExtDispLock);
79 overlay::utils::ActionSafe::getInstance()->setDimension(w, h);
80 setExternalDisplay(mExternalDisplay);
81}
82
83int ExternalDisplay::getModeCount() const {
84 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
85 Mutex::Autolock lock(mExtDispLock);
86 return mModeCount;
87}
88
89void ExternalDisplay::getEDIDModes(int *out) const {
90 Mutex::Autolock lock(mExtDispLock);
91 for(int i = 0;i < mModeCount;i++) {
92 out[i] = mEDIDModes[i];
93 }
94}
95
Naseer Ahmed72cf9762012-07-21 12:17:13 -070096ExternalDisplay::~ExternalDisplay()
97{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070098 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070099}
100
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700101struct disp_mode_timing_type {
102 int video_format;
103
104 int active_h;
105 int active_v;
106
107 int front_porch_h;
108 int pulse_width_h;
109 int back_porch_h;
110
111 int front_porch_v;
112 int pulse_width_v;
113 int back_porch_v;
114
115 int pixel_freq;
116 bool interlaced;
117
118 void set_info(struct fb_var_screeninfo &info) const;
119};
120
121void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const
122{
123 info.reserved[0] = 0;
124 info.reserved[1] = 0;
125 info.reserved[2] = 0;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700126 info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700127
128 info.xoffset = 0;
129 info.yoffset = 0;
130 info.xres = active_h;
131 info.yres = active_v;
132
133 info.pixclock = pixel_freq*1000;
134 info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
135
136 info.right_margin = front_porch_h;
137 info.hsync_len = pulse_width_h;
138 info.left_margin = back_porch_h;
139 info.lower_margin = front_porch_v;
140 info.vsync_len = pulse_width_v;
141 info.upper_margin = back_porch_v;
142}
143
144/* Video formates supported by the HDMI Standard */
145/* Indicates the resolution, pix clock and the aspect ratio */
146#define m640x480p60_4_3 1
147#define m720x480p60_4_3 2
148#define m720x480p60_16_9 3
149#define m1280x720p60_16_9 4
150#define m1920x1080i60_16_9 5
151#define m1440x480i60_4_3 6
152#define m1440x480i60_16_9 7
153#define m1920x1080p60_16_9 16
154#define m720x576p50_4_3 17
155#define m720x576p50_16_9 18
156#define m1280x720p50_16_9 19
157#define m1440x576i50_4_3 21
158#define m1440x576i50_16_9 22
159#define m1920x1080p50_16_9 31
160#define m1920x1080p24_16_9 32
161#define m1920x1080p25_16_9 33
162#define m1920x1080p30_16_9 34
163
164static struct disp_mode_timing_type supported_video_mode_lut[] = {
165 {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false},
166 {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
167 {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
168 {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false},
169 {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false},
170 {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
171 {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
172 {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false},
173 {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
174 {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
175 {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false},
176 {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
177 {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
178 {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false},
179 {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false},
180 {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false},
181 {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false},
182};
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700183
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700184int ExternalDisplay::parseResolution(char* edidStr, int* edidModes)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700185{
186 char delim = ',';
187 int count = 0;
188 char *start, *end;
189 // EDIDs are string delimited by ','
190 // Ex: 16,4,5,3,32,34,1
191 // Parse this string to get mode(int)
192 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700193 end = &delim;
194 while(*end == delim) {
195 edidModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700196 start = end+1;
197 count++;
198 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700199 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
200 for (int i = 0; i < count; i++)
201 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700202 return count;
203}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700204
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205bool ExternalDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700206{
207 int hdmiEDIDFile = open(SYSFS_EDID_MODES, O_RDONLY, 0);
208 int len = -1;
209
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700210 if (hdmiEDIDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700211 ALOGE("%s: edid_modes file '%s' not found",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700212 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700213 return false;
214 } else {
215 len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700216 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d",
217 __FUNCTION__, mEDIDs, len);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700218 if ( len <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700219 ALOGE("%s: edid_modes file empty '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700220 __FUNCTION__, SYSFS_EDID_MODES);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700221 }
222 else {
223 while (len > 1 && isspace(mEDIDs[len-1]))
224 --len;
225 mEDIDs[len] = 0;
226 }
227 }
228 close(hdmiEDIDFile);
229 if(len > 0) {
230 // GEt EDID modes from the EDID strings
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700231 mModeCount = parseResolution(mEDIDs, mEDIDModes);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700232 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
233 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700234 }
235
236 return (strlen(mEDIDs) > 0);
237}
238
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700239bool ExternalDisplay::openFramebuffer()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700240{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700241 if (mFd == -1) {
242 mFd = open("/dev/graphics/fb1", O_RDWR);
243 if (mFd < 0)
244 ALOGE("%s: /dev/graphics/fb1 not available", __FUNCTION__);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700245 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700246 if(mHwcContext) {
247 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
248 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700249 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700250}
251
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700252bool ExternalDisplay::closeFrameBuffer()
253{
254 int ret = 0;
255 if(mFd > 0) {
256 ret = close(mFd);
257 mFd = -1;
258 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700259 if(mHwcContext) {
260 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
261 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700262 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 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700383}
384
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700385void ExternalDisplay::setExternalDisplay(int connected)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700386{
387
388 hwc_context_t* ctx = mHwcContext;
389 if(ctx) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700390 ALOGD_IF(DEBUG, "%s: status = %d", __FUNCTION__,
391 connected);
392 if(connected) {
393 readResolution();
394 //Get the best mode and set
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700395 // TODO: Move this to activate
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700396 setResolution(getBestMode());
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700397 setDpyAttr();
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700398 //enable hdmi vsync
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700399 } else {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700400 // Disable the hdmi vsync
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700401 closeFrameBuffer();
402 resetInfo();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700403 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700404 // Store the external display
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700405 mExternalDisplay = connected;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700406 const char* prop = (connected) ? "1" : "0";
407 // set system property
408 property_set("hw.hdmiON", prop);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700409 }
410 return;
411}
412
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700413bool ExternalDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700414{
415 bool ret = true;
416 int hdmiHPDFile = open(SYSFS_HPD,O_RDWR, 0);
417 if (hdmiHPDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700418 ALOGE("%s: state file '%s' not found : ret%d"
419 "err str: %s", __FUNCTION__, SYSFS_HPD, hdmiHPDFile,
420 strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700421 ret = false;
422 } else {
423 int err = -1;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700424 ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__,
425 userOption);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700426 if(userOption)
427 err = write(hdmiHPDFile, "1", 2);
428 else
429 err = write(hdmiHPDFile, "0" , 2);
430 if (err <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700431 ALOGE("%s: file write failed '%s'",
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700432 __FUNCTION__, SYSFS_HPD);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700433 ret = false;
434 }
435 close(hdmiHPDFile);
436 }
437 return ret;
438}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700439
Saurabh Shah3825f252012-09-21 16:32:18 -0700440/*
441 * commits the changes to the external display
442 * mExternalDisplay has the mixer number(1-> HDMI 2-> WFD)
443 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700444bool ExternalDisplay::post()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700445{
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500446 if(mFd == -1)
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700447 return false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500448
449 struct mdp_display_commit ext_commit;
450 ext_commit.flags |= MDP_DISPLAY_COMMIT_OVERLAY;
451 if (ioctl(mFd, MSMFB_DISPLAY_COMMIT, &ext_commit) == -1) {
452 ALOGE("%s: MSMFB_DISPLAY_COMMIT for external failed, str: %s",
453 __FUNCTION__, strerror(errno));
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700454 return false;
455 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500456
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700457 return true;
458}
459
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700460void ExternalDisplay::setDpyAttr() {
461 int width = 0, height = 0, fps = 0;
462 getAttrForMode(width, height, fps);
463 if(mHwcContext) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700464 ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700465 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
466 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700467 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period =
468 1000000000l / fps;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700469 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470}
471
472void ExternalDisplay::getAttrForMode(int& width, int& height,
473int& fps) {
474 switch (mCurrentMode) {
475 case m640x480p60_4_3:
476 width = 640;
477 height = 480;
478 fps = 60;
479 break;
480 case m720x480p60_4_3:
481 case m720x480p60_16_9:
482 width = 720;
483 height = 480;
484 fps = 60;
485 break;
486 case m720x576p50_4_3:
487 case m720x576p50_16_9:
488 width = 720;
489 height = 576;
490 fps = 50;
491 break;
492 case m1280x720p50_16_9:
493 width = 1280;
494 height = 720;
495 fps = 50;
496 break;
497 case m1280x720p60_16_9:
498 width = 1280;
499 height = 720;
500 fps = 60;
501 break;
502 case m1920x1080p24_16_9:
503 width = 1920;
504 height = 1080;
505 fps = 24;
506 break;
507 case m1920x1080p25_16_9:
508 width = 1920;
509 height = 1080;
510 fps = 25;
511 break;
512 case m1920x1080p30_16_9:
513 width = 1920;
514 height = 1080;
515 fps = 30;
516 break;
517 case m1920x1080p50_16_9:
518 width = 1920;
519 height = 1080;
520 fps = 50;
521 break;
522 case m1920x1080p60_16_9:
523 width = 1920;
524 height = 1080;
525 fps = 60;
526 break;
527 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700528}
529
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700530};
531