blob: a499a62b7421c41a5a36c0f66f0bdf0a0b656f75 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/types.h>
15#include <linux/bitops.h>
16#include <linux/mutex.h>
17
Manoj Rao668d6d52011-08-16 19:12:31 -070018/* #define DEBUG */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#define DEV_DBG_PREFIX "EXT_COMMON: "
20
21#include "msm_fb.h"
22#include "external_common.h"
23
24struct external_common_state_type *external_common_state;
25EXPORT_SYMBOL(external_common_state);
26DEFINE_MUTEX(external_common_state_hpd_mutex);
27EXPORT_SYMBOL(external_common_state_hpd_mutex);
28
29static int atoi(const char *name)
30{
31 int val = 0;
32
33 for (;; name++) {
34 switch (*name) {
35 case '0' ... '9':
36 val = 10*val+(*name-'0');
37 break;
38 default:
39 return val;
40 }
41 }
42}
43
Manoj Rao668d6d52011-08-16 19:12:31 -070044#ifdef DEBUG_EDID
45/*
46 * Block 0 - 1920x1080p, 1360x768p
47 * Block 1 - 1280x720p, 1920x540i, 720x480p
48 */
49const char edid_blk0[0x100] = {
500x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x4C, 0x2D, 0x03, 0x05, 0x00,
510x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78, 0x0A, 0xEE,
520x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F, 0x50, 0x54, 0xBD, 0xEF, 0x80, 0x71,
530x4F, 0x81, 0x00, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00, 0x95, 0x0F, 0xB3, 0x00,
540xA9, 0x40, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45,
550x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x66, 0x21, 0x50, 0xB0, 0x51, 0x00,
560x1B, 0x30, 0x40, 0x70, 0x36, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x00,
570x00, 0x00, 0xFD, 0x00, 0x18, 0x4B, 0x1A, 0x51, 0x17, 0x00, 0x0A, 0x20, 0x20,
580x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53, 0x41, 0x4D, 0x53,
590x55, 0x4E, 0x47, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8F};
60
61const char edid_blk1[0x100] = {
620x02, 0x03, 0x1E, 0xF1, 0x46, 0x90, 0x04, 0x05, 0x03, 0x20, 0x22, 0x23, 0x09,
630x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0xE2, 0x00, 0x0F, 0x67, 0x03, 0x0C, 0x00,
640x10, 0x00, 0xB8, 0x2D, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20, 0x6E,
650x28, 0x55, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0x18,
660x71, 0x1C, 0x16, 0x20, 0x58, 0x2C, 0x25, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00,
670x9E, 0x8C, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10, 0x10, 0x3E, 0x96, 0x00,
680xA0, 0x5A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
690x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
700x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
710x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF};
72#endif /* DEBUG_EDID */
73
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074const char *video_format_2string(uint32 format)
75{
76 switch (format) {
77 default:
78#ifdef CONFIG_FB_MSM_HDMI_COMMON
79 case HDMI_VFRMT_640x480p60_4_3: return " 640x 480 p60 4/3";
80 case HDMI_VFRMT_720x480p60_4_3: return " 720x 480 p60 4/3";
81 case HDMI_VFRMT_720x480p60_16_9: return " 720x 480 p60 16/9";
82 case HDMI_VFRMT_1280x720p60_16_9: return "1280x 720 p60 16/9";
83 case HDMI_VFRMT_1920x1080i60_16_9: return "1920x1080 i60 16/9";
84 case HDMI_VFRMT_1440x480i60_4_3: return "1440x 480 i60 4/3";
85 case HDMI_VFRMT_1440x480i60_16_9: return "1440x 480 i60 16/9";
86 case HDMI_VFRMT_1440x240p60_4_3: return "1440x 240 p60 4/3";
87 case HDMI_VFRMT_1440x240p60_16_9: return "1440x 240 p60 16/9";
88 case HDMI_VFRMT_2880x480i60_4_3: return "2880x 480 i60 4/3";
89 case HDMI_VFRMT_2880x480i60_16_9: return "2880x 480 i60 16/9";
90 case HDMI_VFRMT_2880x240p60_4_3: return "2880x 240 p60 4/3";
91 case HDMI_VFRMT_2880x240p60_16_9: return "2880x 240 p60 16/9";
92 case HDMI_VFRMT_1440x480p60_4_3: return "1440x 480 p60 4/3";
93 case HDMI_VFRMT_1440x480p60_16_9: return "1440x 480 p60 16/9";
94 case HDMI_VFRMT_1920x1080p60_16_9: return "1920x1080 p60 16/9";
95 case HDMI_VFRMT_720x576p50_4_3: return " 720x 576 p50 4/3";
96 case HDMI_VFRMT_720x576p50_16_9: return " 720x 576 p50 16/9";
97 case HDMI_VFRMT_1280x720p50_16_9: return "1280x 720 p50 16/9";
98 case HDMI_VFRMT_1920x1080i50_16_9: return "1920x1080 i50 16/9";
99 case HDMI_VFRMT_1440x576i50_4_3: return "1440x 576 i50 4/3";
100 case HDMI_VFRMT_1440x576i50_16_9: return "1440x 576 i50 16/9";
101 case HDMI_VFRMT_1440x288p50_4_3: return "1440x 288 p50 4/3";
102 case HDMI_VFRMT_1440x288p50_16_9: return "1440x 288 p50 16/9";
103 case HDMI_VFRMT_2880x576i50_4_3: return "2880x 576 i50 4/3";
104 case HDMI_VFRMT_2880x576i50_16_9: return "2880x 576 i50 16/9";
105 case HDMI_VFRMT_2880x288p50_4_3: return "2880x 288 p50 4/3";
106 case HDMI_VFRMT_2880x288p50_16_9: return "2880x 288 p50 16/9";
107 case HDMI_VFRMT_1440x576p50_4_3: return "1440x 576 p50 4/3";
108 case HDMI_VFRMT_1440x576p50_16_9: return "1440x 576 p50 16/9";
109 case HDMI_VFRMT_1920x1080p50_16_9: return "1920x1080 p50 16/9";
110 case HDMI_VFRMT_1920x1080p24_16_9: return "1920x1080 p24 16/9";
111 case HDMI_VFRMT_1920x1080p25_16_9: return "1920x1080 p25 16/9";
112 case HDMI_VFRMT_1920x1080p30_16_9: return "1920x1080 p30 16/9";
113 case HDMI_VFRMT_2880x480p60_4_3: return "2880x 480 p60 4/3";
114 case HDMI_VFRMT_2880x480p60_16_9: return "2880x 480 p60 16/9";
115 case HDMI_VFRMT_2880x576p50_4_3: return "2880x 576 p50 4/3";
116 case HDMI_VFRMT_2880x576p50_16_9: return "2880x 576 p50 16/9";
117 case HDMI_VFRMT_1920x1250i50_16_9: return "1920x1250 i50 16/9";
118 case HDMI_VFRMT_1920x1080i100_16_9:return "1920x1080 i100 16/9";
119 case HDMI_VFRMT_1280x720p100_16_9: return "1280x 720 p100 16/9";
120 case HDMI_VFRMT_720x576p100_4_3: return " 720x 576 p100 4/3";
121 case HDMI_VFRMT_720x576p100_16_9: return " 720x 576 p100 16/9";
122 case HDMI_VFRMT_1440x576i100_4_3: return "1440x 576 i100 4/3";
123 case HDMI_VFRMT_1440x576i100_16_9: return "1440x 576 i100 16/9";
124 case HDMI_VFRMT_1920x1080i120_16_9:return "1920x1080 i120 16/9";
125 case HDMI_VFRMT_1280x720p120_16_9: return "1280x 720 p120 16/9";
126 case HDMI_VFRMT_720x480p120_4_3: return " 720x 480 p120 4/3";
127 case HDMI_VFRMT_720x480p120_16_9: return " 720x 480 p120 16/9";
128 case HDMI_VFRMT_1440x480i120_4_3: return "1440x 480 i120 4/3";
129 case HDMI_VFRMT_1440x480i120_16_9: return "1440x 480 i120 16/9";
130 case HDMI_VFRMT_720x576p200_4_3: return " 720x 576 p200 4/3";
131 case HDMI_VFRMT_720x576p200_16_9: return " 720x 576 p200 16/9";
132 case HDMI_VFRMT_1440x576i200_4_3: return "1440x 576 i200 4/3";
133 case HDMI_VFRMT_1440x576i200_16_9: return "1440x 576 i200 16/9";
134 case HDMI_VFRMT_720x480p240_4_3: return " 720x 480 p240 4/3";
135 case HDMI_VFRMT_720x480p240_16_9: return " 720x 480 p240 16/9";
136 case HDMI_VFRMT_1440x480i240_4_3: return "1440x 480 i240 4/3";
137 case HDMI_VFRMT_1440x480i240_16_9: return "1440x 480 i240 16/9";
138#elif defined(CONFIG_FB_MSM_TVOUT)
139 case TVOUT_VFRMT_NTSC_M_720x480i: return "NTSC_M_720x480i";
140 case TVOUT_VFRMT_NTSC_J_720x480i: return "NTSC_J_720x480i";
141 case TVOUT_VFRMT_PAL_BDGHIN_720x576i: return "PAL_BDGHIN_720x576i";
142 case TVOUT_VFRMT_PAL_M_720x480i: return "PAL_M_720x480i";
143 case TVOUT_VFRMT_PAL_N_720x480i: return "PAL_N_720x480i";
144#endif
145
146 }
147}
148EXPORT_SYMBOL(video_format_2string);
149
150static ssize_t external_common_rda_video_mode_str(struct device *dev,
151 struct device_attribute *attr, char *buf)
152{
153 ssize_t ret = snprintf(buf, PAGE_SIZE, "%s\n",
154 video_format_2string(external_common_state->video_resolution));
155 DEV_DBG("%s: '%s'\n", __func__,
156 video_format_2string(external_common_state->video_resolution));
157 return ret;
158}
159
160#ifdef CONFIG_FB_MSM_HDMI_COMMON
161struct hdmi_disp_mode_timing_type
162 hdmi_common_supported_video_mode_lut[HDMI_VFRMT_MAX] = {
163 HDMI_SETTINGS_640x480p60_4_3,
164 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_4_3),
165 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_16_9),
166 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p60_16_9),
167 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i60_16_9),
168 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_4_3),
169 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_16_9),
170 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_4_3),
171 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_16_9),
172 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_4_3),
173 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_16_9),
174 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_4_3),
175 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_16_9),
176 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_4_3),
177 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_16_9),
178 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p60_16_9),
179 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_4_3),
180 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_16_9),
181 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p50_16_9),
182 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i50_16_9),
183 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_4_3),
184 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_16_9),
185 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_4_3),
186 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_16_9),
187 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_4_3),
188 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_16_9),
189 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_4_3),
190 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_16_9),
191 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_4_3),
192 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_16_9),
193 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p50_16_9),
194 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p24_16_9),
195 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p25_16_9),
196 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p30_16_9),
197 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_4_3),
198 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_16_9),
199 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_4_3),
200 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_16_9),
201 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1250i50_16_9),
202 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i100_16_9),
203 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p100_16_9),
204 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_4_3),
205 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_16_9),
206 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_4_3),
207 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_16_9),
208 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i120_16_9),
209 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p120_16_9),
210 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_4_3),
211 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_16_9),
212 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_4_3),
213 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_16_9),
214 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_4_3),
215 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_16_9),
216 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_4_3),
217 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_16_9),
218 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_4_3),
219 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_16_9),
220 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_4_3),
221 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_16_9),
222};
223EXPORT_SYMBOL(hdmi_common_supported_video_mode_lut);
224
225static ssize_t hdmi_common_rda_edid_modes(struct device *dev,
226 struct device_attribute *attr, char *buf)
227{
228 ssize_t ret = 0;
229 int i;
230
231 buf[0] = 0;
232 if (external_common_state->disp_mode_list.num_of_elements) {
233 uint32 *video_mode = external_common_state->disp_mode_list
234 .disp_mode_list;
235 for (i = 0; i < external_common_state->disp_mode_list
236 .num_of_elements; ++i) {
237 if (ret > 0)
238 ret += snprintf(buf+ret, PAGE_SIZE-ret, ",%d",
239 *video_mode++ + 1);
240 else
241 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
242 *video_mode++ + 1);
243 }
244 } else
245 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
246 external_common_state->video_resolution+1);
247
248 DEV_DBG("%s: '%s'\n", __func__, buf);
249 ret += snprintf(buf+ret, PAGE_SIZE-ret, "\n");
250 return ret;
251}
252
253static ssize_t hdmi_common_rda_hdcp(struct device *dev,
254 struct device_attribute *attr, char *buf)
255{
256 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
257 external_common_state->hdcp_active);
258 DEV_DBG("%s: '%d'\n", __func__,
259 external_common_state->hdcp_active);
260 return ret;
261}
262
263static ssize_t hdmi_common_rda_hpd(struct device *dev,
264 struct device_attribute *attr, char *buf)
265{
266 ssize_t ret;
267 if (external_common_state->hpd_feature) {
268 ret = snprintf(buf, PAGE_SIZE, "%d\n",
269 external_common_state->hpd_feature_on);
270 DEV_DBG("%s: '%d'\n", __func__,
271 external_common_state->hpd_feature_on);
272 } else {
273 ret = snprintf(buf, PAGE_SIZE, "-1\n");
274 DEV_DBG("%s: 'not supported'\n", __func__);
275 }
276 return ret;
277}
278
279static ssize_t hdmi_common_wta_hpd(struct device *dev,
280 struct device_attribute *attr, const char *buf, size_t count)
281{
282 ssize_t ret = strnlen(buf, PAGE_SIZE);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700283#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
284 int hpd = 1;
285#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286 int hpd = atoi(buf);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700287#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 if (external_common_state->hpd_feature) {
289 if (hpd == 0 && external_common_state->hpd_feature_on) {
290 external_common_state->hpd_feature(0);
291 external_common_state->hpd_feature_on = 0;
292 DEV_DBG("%s: '%d'\n", __func__,
293 external_common_state->hpd_feature_on);
294 } else if (hpd == 1 && !external_common_state->hpd_feature_on) {
295 external_common_state->hpd_feature(1);
296 external_common_state->hpd_feature_on = 1;
297 DEV_DBG("%s: '%d'\n", __func__,
298 external_common_state->hpd_feature_on);
299 } else {
300 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
301 external_common_state->hpd_feature_on);
302 }
303 } else {
304 DEV_DBG("%s: 'not supported'\n", __func__);
305 }
306
307 return ret;
308}
309
310static ssize_t hdmi_common_rda_3d_present(struct device *dev,
311 struct device_attribute *attr, char *buf)
312{
313 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
314 external_common_state->present_3d);
315 DEV_DBG("%s: '%d'\n", __func__,
316 external_common_state->present_3d);
317 return ret;
318}
319
320static ssize_t hdmi_common_rda_hdcp_present(struct device *dev,
321 struct device_attribute *attr, char *buf)
322{
323 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
324 external_common_state->present_hdcp);
325 DEV_DBG("%s: '%d'\n", __func__,
326 external_common_state->present_hdcp);
327 return ret;
328}
329#endif
330
331#ifdef CONFIG_FB_MSM_HDMI_3D
332static ssize_t hdmi_3d_rda_format_3d(struct device *dev,
333 struct device_attribute *attr, char *buf)
334{
335 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
336 external_common_state->format_3d);
337 DEV_DBG("%s: '%d'\n", __func__,
338 external_common_state->format_3d);
339 return ret;
340}
341
342static ssize_t hdmi_3d_wta_format_3d(struct device *dev,
343 struct device_attribute *attr, const char *buf, size_t count)
344{
345 ssize_t ret = strnlen(buf, PAGE_SIZE);
346 int format_3d = atoi(buf);
347
348 if (format_3d >= 0 && format_3d <= 2) {
349 if (format_3d != external_common_state->format_3d) {
350 external_common_state->format_3d = format_3d;
351 if (external_common_state->switch_3d)
352 external_common_state->switch_3d(format_3d);
353 DEV_DBG("%s: '%d'\n", __func__,
354 external_common_state->format_3d);
355 } else {
356 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
357 external_common_state->format_3d);
358 }
359 } else {
360 DEV_DBG("%s: '%d' (unknown)\n", __func__, format_3d);
361 }
362
363 return ret;
364}
365#endif
366
367static ssize_t external_common_rda_video_mode(struct device *dev,
368 struct device_attribute *attr, char *buf)
369{
370 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
371 external_common_state->video_resolution+1);
372 DEV_DBG("%s: '%d'\n", __func__,
373 external_common_state->video_resolution+1);
374 return ret;
375}
376
377static ssize_t external_common_wta_video_mode(struct device *dev,
378 struct device_attribute *attr, const char *buf, size_t count)
379{
380 ssize_t ret = strnlen(buf, PAGE_SIZE);
381 uint32 video_mode;
382#ifdef CONFIG_FB_MSM_HDMI_COMMON
383 const struct hdmi_disp_mode_timing_type *disp_mode;
384#endif
385 mutex_lock(&external_common_state_hpd_mutex);
386 if (!external_common_state->hpd_state) {
387 mutex_unlock(&external_common_state_hpd_mutex);
388 DEV_INFO("%s: FAILED: display off or cable disconnected\n",
389 __func__);
390 return ret;
391 }
392 mutex_unlock(&external_common_state_hpd_mutex);
393
394 video_mode = atoi(buf)-1;
395 kobject_uevent(external_common_state->uevent_kobj, KOBJ_OFFLINE);
396#ifdef CONFIG_FB_MSM_HDMI_COMMON
397 disp_mode = hdmi_common_get_supported_mode(video_mode);
398 if (!disp_mode) {
399 DEV_INFO("%s: FAILED: mode not supported (%d)\n",
400 __func__, video_mode);
401 return ret;
402 }
403 external_common_state->disp_mode_list.num_of_elements = 1;
404 external_common_state->disp_mode_list.disp_mode_list[0] = video_mode;
405#elif defined(CONFIG_FB_MSM_TVOUT)
406 external_common_state->video_resolution = video_mode;
407#endif
408 DEV_DBG("%s: 'mode=%d %s' successful (sending OFF/ONLINE)\n", __func__,
409 video_mode, video_format_2string(video_mode));
410 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ONLINE);
411 return ret;
412}
413
414static ssize_t external_common_rda_connected(struct device *dev,
415 struct device_attribute *attr, char *buf)
416{
417 ssize_t ret;
418 mutex_lock(&external_common_state_hpd_mutex);
419 ret = snprintf(buf, PAGE_SIZE, "%d\n",
420 external_common_state->hpd_state);
421 DEV_DBG("%s: '%d'\n", __func__,
422 external_common_state->hpd_state);
423 mutex_unlock(&external_common_state_hpd_mutex);
424 return ret;
425}
426
427static DEVICE_ATTR(video_mode, S_IRUGO | S_IWUGO,
428 external_common_rda_video_mode, external_common_wta_video_mode);
429static DEVICE_ATTR(video_mode_str, S_IRUGO, external_common_rda_video_mode_str,
430 NULL);
431static DEVICE_ATTR(connected, S_IRUGO, external_common_rda_connected, NULL);
432#ifdef CONFIG_FB_MSM_HDMI_COMMON
433static DEVICE_ATTR(edid_modes, S_IRUGO, hdmi_common_rda_edid_modes, NULL);
434static DEVICE_ATTR(hpd, S_IRUGO | S_IWUGO, hdmi_common_rda_hpd,
435 hdmi_common_wta_hpd);
436static DEVICE_ATTR(hdcp, S_IRUGO, hdmi_common_rda_hdcp, NULL);
437static DEVICE_ATTR(3d_present, S_IRUGO, hdmi_common_rda_3d_present, NULL);
438static DEVICE_ATTR(hdcp_present, S_IRUGO, hdmi_common_rda_hdcp_present, NULL);
439#endif
440#ifdef CONFIG_FB_MSM_HDMI_3D
441static DEVICE_ATTR(format_3d, S_IRUGO | S_IWUGO, hdmi_3d_rda_format_3d,
442 hdmi_3d_wta_format_3d);
443#endif
444
445static struct attribute *external_common_fs_attrs[] = {
446 &dev_attr_video_mode.attr,
447 &dev_attr_video_mode_str.attr,
448 &dev_attr_connected.attr,
449#ifdef CONFIG_FB_MSM_HDMI_COMMON
450 &dev_attr_edid_modes.attr,
451 &dev_attr_hdcp.attr,
452 &dev_attr_hpd.attr,
453 &dev_attr_3d_present.attr,
454 &dev_attr_hdcp_present.attr,
455#endif
456#ifdef CONFIG_FB_MSM_HDMI_3D
457 &dev_attr_format_3d.attr,
458#endif
459 NULL,
460};
461static struct attribute_group external_common_fs_attr_group = {
462 .attrs = external_common_fs_attrs,
463};
464
465/* create external interface kobject and initialize */
466int external_common_state_create(struct platform_device *pdev)
467{
468 int rc;
469 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
470 if (!mfd) {
471 DEV_ERR("%s: mfd not found\n", __func__);
472 return -ENODEV;
473 }
474 if (!mfd->fbi) {
475 DEV_ERR("%s: mfd->fbi not found\n", __func__);
476 return -ENODEV;
477 }
478 if (!mfd->fbi->dev) {
479 DEV_ERR("%s: mfd->fbi->dev not found\n", __func__);
480 return -ENODEV;
481 }
482 rc = sysfs_create_group(&mfd->fbi->dev->kobj,
483 &external_common_fs_attr_group);
484 if (rc) {
485 DEV_ERR("%s: sysfs group creation failed, rc=%d\n", __func__,
486 rc);
487 return rc;
488 }
489 external_common_state->uevent_kobj = &mfd->fbi->dev->kobj;
490 DEV_ERR("%s: sysfs group %p\n", __func__,
491 external_common_state->uevent_kobj);
492
493 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ADD);
494 DEV_DBG("%s: kobject_uevent(KOBJ_ADD)\n", __func__);
495 return 0;
496}
497EXPORT_SYMBOL(external_common_state_create);
498
499void external_common_state_remove(void)
500{
501 if (external_common_state->uevent_kobj)
502 sysfs_remove_group(external_common_state->uevent_kobj,
503 &external_common_fs_attr_group);
504 external_common_state->uevent_kobj = NULL;
505}
506EXPORT_SYMBOL(external_common_state_remove);
507
508#ifdef CONFIG_FB_MSM_HDMI_COMMON
509/* The Logic ID for HDMI TX Core. Currently only support 1 HDMI TX Core. */
510struct hdmi_edid_video_mode_property_type {
511 uint32 video_code;
512 uint32 active_h;
513 uint32 active_v;
514 boolean interlaced;
515 uint32 total_h;
516 uint32 total_blank_h;
517 uint32 total_v;
518 uint32 total_blank_v;
519 /* Must divide by 1000 to get the frequency */
520 uint32 freq_h;
521 /* Must divide by 1000 to get the frequency */
522 uint32 freq_v;
523 /* Must divide by 1000 to get the frequency */
524 uint32 pixel_freq;
525 /* Must divide by 1000 to get the frequency */
526 uint32 refresh_rate;
527 boolean aspect_ratio_4_3;
528};
529
530/* LUT is sorted from lowest Active H to highest Active H - ease searching */
531static struct hdmi_edid_video_mode_property_type
532 hdmi_edid_disp_mode_lut[] = {
533
534 /* All 640 H Active */
535 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
536 31465, 59940, 25175, 59940, TRUE},
537 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
538 31500, 60000, 25200, 60000, TRUE},
539
540 /* All 720 H Active */
541 {HDMI_VFRMT_720x576p50_4_3, 720, 576, FALSE, 864, 144, 625, 49,
542 31250, 50000, 27000, 50000, TRUE},
543 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
544 31465, 59940, 27000, 59940, TRUE},
545 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
546 31500, 60000, 27030, 60000, TRUE},
547 {HDMI_VFRMT_720x576p100_4_3, 720, 576, FALSE, 864, 144, 625, 49,
548 62500, 100000, 54000, 100000, TRUE},
549 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
550 62937, 119880, 54000, 119880, TRUE},
551 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
552 63000, 120000, 54054, 120000, TRUE},
553 {HDMI_VFRMT_720x576p200_4_3, 720, 576, FALSE, 864, 144, 625, 49,
554 125000, 200000, 108000, 200000, TRUE},
555 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
556 125874, 239760, 108000, 239000, TRUE},
557 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
558 126000, 240000, 108108, 240000, TRUE},
559
560 /* All 1280 H Active */
561 {HDMI_VFRMT_1280x720p50_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
562 37500, 50000, 74250, 50000, FALSE},
563 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
564 44955, 59940, 74176, 59940, FALSE},
565 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
566 45000, 60000, 74250, 60000, FALSE},
567 {HDMI_VFRMT_1280x720p100_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
568 75000, 100000, 148500, 100000, FALSE},
569 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
570 89909, 119880, 148352, 119880, FALSE},
571 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
572 90000, 120000, 148500, 120000, FALSE},
573
574 /* All 1440 H Active */
575 {HDMI_VFRMT_1440x576i50_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
576 15625, 50000, 27000, 50000, TRUE},
577 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 312, 24,
578 15625, 50080, 27000, 50000, TRUE},
579 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 313, 25,
580 15625, 49920, 27000, 50000, TRUE},
581 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 314, 26,
582 15625, 49761, 27000, 50000, TRUE},
583 {HDMI_VFRMT_1440x576p50_4_3, 1440, 576, FALSE, 1728, 288, 625, 49,
584 31250, 50000, 54000, 50000, TRUE},
585 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
586 15734, 59940, 27000, 59940, TRUE},
587 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
588 15734, 60054, 27000, 59940, TRUE},
589 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
590 15734, 59826, 27000, 59940, TRUE},
591 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
592 31469, 59940, 54000, 59940, TRUE},
593 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
594 15750, 60000, 27027, 60000, TRUE},
595 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
596 15750, 60115, 27027, 60000, TRUE},
597 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
598 15750, 59886, 27027, 60000, TRUE},
599 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
600 31500, 60000, 54054, 60000, TRUE},
601 {HDMI_VFRMT_1440x576i100_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
602 31250, 100000, 54000, 100000, TRUE},
603 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
604 31469, 119880, 54000, 119880, TRUE},
605 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
606 31500, 120000, 54054, 120000, TRUE},
607 {HDMI_VFRMT_1440x576i200_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
608 62500, 200000, 108000, 200000, TRUE},
609 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
610 62937, 239760, 108000, 239000, TRUE},
611 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
612 63000, 240000, 108108, 240000, TRUE},
613
614 /* All 1920 H Active */
615 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
616 45, 67433, 59940, 148352, 59940, FALSE},
617 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
618 45, 67500, 60000, 148500, 60000, FALSE},
619 {HDMI_VFRMT_1920x1080p50_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
620 45, 56250, 50000, 148500, 50000, FALSE},
621 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
622 45, 26973, 23976, 74176, 24000, FALSE},
623 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
624 45, 27000, 24000, 74250, 24000, FALSE},
625 {HDMI_VFRMT_1920x1080p25_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
626 45, 28125, 25000, 74250, 25000, FALSE},
627 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
628 45, 33716, 29970, 74176, 30000, FALSE},
629 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
630 45, 33750, 30000, 74250, 30000, FALSE},
631 {HDMI_VFRMT_1920x1080i50_16_9, 1920, 1080, TRUE, 2304, 384, 1250,
632 85, 31250, 50000, 72000, 50000, FALSE},
633 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
634 22, 33716, 59940, 74176, 59940, FALSE},
635 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
636 22, 33750, 60000, 74250, 60000, FALSE},
637 {HDMI_VFRMT_1920x1080i100_16_9, 1920, 1080, TRUE, 2640, 720, 1125,
638 22, 56250, 100000, 148500, 100000, FALSE},
639 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
640 22, 67432, 119880, 148352, 119980, FALSE},
641 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
642 22, 67500, 120000, 148500, 120000, FALSE},
643
644 /* All 2880 H Active */
645 {HDMI_VFRMT_2880x576i50_4_3, 2880, 576, TRUE, 3456, 576, 625, 24,
646 15625, 50000, 54000, 50000, TRUE},
647 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 312, 24,
648 15625, 50080, 54000, 50000, TRUE},
649 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 313, 25,
650 15625, 49920, 54000, 50000, TRUE},
651 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 314, 26,
652 15625, 49761, 54000, 50000, TRUE},
653 {HDMI_VFRMT_2880x576p50_4_3, 2880, 576, FALSE, 3456, 576, 625, 49,
654 31250, 50000, 108000, 50000, TRUE},
655 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
656 15734, 59940, 54000, 59940, TRUE},
657 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 262, 22,
658 15734, 60054, 54000, 59940, TRUE},
659 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 263, 23,
660 15734, 59940, 54000, 59940, TRUE},
661 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
662 31469, 59940, 108000, 59940, TRUE},
663 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
664 15750, 60000, 54054, 60000, TRUE},
665 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 22,
666 15750, 60115, 54054, 60000, TRUE},
667 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 23,
668 15750, 59886, 54054, 60000, TRUE},
669 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
670 31500, 60000, 108108, 60000, TRUE},
671};
672
673static const uint8 *hdmi_edid_find_block(const uint8 *in_buf, uint8 type,
674 uint8 *len)
675{
676 /* the start of data block collection, start of Video Data Block */
677 uint32 offset = 4;
678
679 *len = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -0700680 if ((in_buf[2] == 4) && (type != 2)) { /* no non-DTD data present */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700681 DEV_WARN("EDID: no non-DTD data present\n");
682 return NULL;
683 }
684 while (offset < 0x80) {
685 uint8 block_len = in_buf[offset] & 0x1F;
686 if ((in_buf[offset] >> 5) == type) {
687 *len = block_len;
688 DEV_DBG("EDID: block=%d found @ %d with length=%d\n",
689 type, offset, block_len);
690 return in_buf+offset;
691 }
692 offset += 1 + block_len;
693 }
Manoj Rao668d6d52011-08-16 19:12:31 -0700694 DEV_WARN("EDID: type=%d block not found in EDID block\n", type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695 return NULL;
696}
697
698static void hdmi_edid_extract_vendor_id(const uint8 *in_buf,
699 char *vendor_id)
700{
701 uint32 id_codes = ((uint32)in_buf[8] << 8) + in_buf[9];
702
703 vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
704 vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
705 vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
706 vendor_id[3] = 0;
707}
708
709static uint32 hdmi_edid_extract_ieee_reg_id(const uint8 *in_buf)
710{
711 uint8 len;
712 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
713
714 if (vsd == NULL)
715 return 0;
716
717 DEV_DBG("EDID: VSD PhyAddr=%04x, MaxTMDS=%dMHz\n",
718 ((uint32)vsd[6] << 8) + (uint32)vsd[5], (uint32)vsd[7] * 5);
719 return ((uint32)vsd[3] << 16) + ((uint32)vsd[2] << 8) + (uint32)vsd[1];
720}
721
722static void hdmi_edid_extract_3d_present(const uint8 *in_buf)
723{
724 uint8 len, offset;
725 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
726
727 external_common_state->present_3d = 0;
728 if (vsd == NULL || len < 9) {
729 DEV_DBG("EDID[3D]: block-id 3 not found or not long enough\n");
730 return;
731 }
732
733 offset = !(vsd[8] & BIT(7)) ? 9 : 13;
734 DEV_DBG("EDID: 3D present @ %d = %02x\n", offset, vsd[offset]);
735 if (vsd[offset] >> 7) { /* 3D format indication present */
736 DEV_INFO("EDID: 3D present, 3D-len=%d\n", vsd[offset+1] & 0x1F);
737 external_common_state->present_3d = 1;
738 }
739}
740
741
742static void hdmi_edid_extract_latency_fields(const uint8 *in_buf)
743{
744 uint8 len;
745 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
746
747 if (vsd == NULL || len < 12 || !(vsd[8] & BIT(7))) {
748 external_common_state->video_latency = (uint16)-1;
749 external_common_state->audio_latency = (uint16)-1;
750 DEV_DBG("EDID: No audio/video latency present\n");
751 } else {
752 external_common_state->video_latency = vsd[9];
753 external_common_state->audio_latency = vsd[10];
754 DEV_DBG("EDID: video-latency=%04x, audio-latency=%04x\n",
755 external_common_state->video_latency,
756 external_common_state->audio_latency);
757 }
758}
759
760static void hdmi_edid_extract_speaker_allocation_data(const uint8 *in_buf)
761{
762 uint8 len;
763 const uint8 *sad = hdmi_edid_find_block(in_buf, 4, &len);
764
765 if (sad == NULL)
766 return;
767
768 external_common_state->speaker_allocation_block = sad[1];
769 DEV_DBG("EDID: speaker allocation data=%s%s%s%s%s%s%s\n",
770 (sad[1] & BIT(0)) ? "FL/FR," : "",
771 (sad[1] & BIT(1)) ? "LFE," : "",
772 (sad[1] & BIT(2)) ? "FC," : "",
773 (sad[1] & BIT(3)) ? "RL/RR," : "",
774 (sad[1] & BIT(4)) ? "RC," : "",
775 (sad[1] & BIT(5)) ? "FLC/FRC," : "",
776 (sad[1] & BIT(6)) ? "LFE," : "");
777}
778
779static void hdmi_edid_extract_audio_data_blocks(const uint8 *in_buf)
780{
781 uint8 len;
782 const uint8 *sad = hdmi_edid_find_block(in_buf, 1, &len);
783 uint32 *adb = external_common_state->audio_data_blocks;
784
785 if (sad == NULL)
786 return;
787
788 external_common_state->audio_data_block_cnt = 0;
789 while (len >= 3 && external_common_state->audio_data_block_cnt < 16) {
790 DEV_DBG("EDID: Audio Data Block=<ch=%d, format=%d "
791 "sampling=0x%02x bit-depth=0x%02x>\n",
792 (sad[1] & 0x7)+1, sad[1] >> 3, sad[2], sad[3]);
793 *adb++ = (uint32)sad[1] + ((uint32)sad[2] << 8)
794 + ((uint32)sad[2] << 16);
795 ++external_common_state->audio_data_block_cnt;
796 len -= 3;
797 sad += 3;
798 }
799}
800
801
802static void hdmi_edid_detail_desc(const uint8 *data_buf, uint32 *disp_mode)
803{
804 boolean aspect_ratio_4_3 = FALSE;
805 boolean interlaced = FALSE;
806 uint32 active_h = 0;
807 uint32 active_v = 0;
808 uint32 blank_h = 0;
809 uint32 blank_v = 0;
810 uint32 ndx = 0;
811 uint32 max_num_of_elements = 0;
812 uint32 img_size_h = 0;
813 uint32 img_size_v = 0;
814
815 /* See VESA Spec */
816 /* EDID_TIMING_DESC_UPPER_H_NIBBLE[0x4]: Relative Offset to the EDID
817 * detailed timing descriptors - Upper 4 bit for each H active/blank
818 * field */
819 /* EDID_TIMING_DESC_H_ACTIVE[0x2]: Relative Offset to the EDID detailed
820 * timing descriptors - H active */
821 active_h = ((((uint32)data_buf[0x4] >> 0x4) & 0xF) << 8)
822 | data_buf[0x2];
823
824 /* EDID_TIMING_DESC_H_BLANK[0x3]: Relative Offset to the EDID detailed
825 * timing descriptors - H blank */
826 blank_h = (((uint32)data_buf[0x4] & 0xF) << 8)
827 | data_buf[0x3];
828
829 /* EDID_TIMING_DESC_UPPER_V_NIBBLE[0x7]: Relative Offset to the EDID
830 * detailed timing descriptors - Upper 4 bit for each V active/blank
831 * field */
832 /* EDID_TIMING_DESC_V_ACTIVE[0x5]: Relative Offset to the EDID detailed
833 * timing descriptors - V active */
834 active_v = ((((uint32)data_buf[0x7] >> 0x4) & 0xF) << 8)
835 | data_buf[0x5];
836
837 /* EDID_TIMING_DESC_V_BLANK[0x6]: Relative Offset to the EDID detailed
838 * timing descriptors - V blank */
839 blank_v = (((uint32)data_buf[0x7] & 0xF) << 8)
840 | data_buf[0x6];
841
842 /* EDID_TIMING_DESC_IMAGE_SIZE_UPPER_NIBBLE[0xE]: Relative Offset to the
843 * EDID detailed timing descriptors - Image Size upper nibble
844 * V and H */
845 /* EDID_TIMING_DESC_H_IMAGE_SIZE[0xC]: Relative Offset to the EDID
846 * detailed timing descriptors - H image size */
847 /* EDID_TIMING_DESC_V_IMAGE_SIZE[0xD]: Relative Offset to the EDID
848 * detailed timing descriptors - V image size */
849 img_size_h = ((((uint32)data_buf[0xE] >> 0x4) & 0xF) << 8)
850 | data_buf[0xC];
851 img_size_v = (((uint32)data_buf[0xE] & 0xF) << 8)
852 | data_buf[0xD];
853
854 aspect_ratio_4_3 = (img_size_h * 3 == img_size_v * 4);
855
856 max_num_of_elements = sizeof(hdmi_edid_disp_mode_lut)
857 / sizeof(*hdmi_edid_disp_mode_lut);
858
Manoj Rao668d6d52011-08-16 19:12:31 -0700859 /* EDID_TIMING_DESC_INTERLACE[0x11:7]: Relative Offset to the EDID
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860 * detailed timing descriptors - Interlace flag */
Manoj Rao668d6d52011-08-16 19:12:31 -0700861 DEV_DBG("Interlaced mode byte data_buf[0x11]=[%x]\n", data_buf[0x11]);
862 /*
863 * CEA 861-D: interlaced bit is bit[7] of byte[0x11]
864 */
865 interlaced = (data_buf[0x11] & 0x80) >> 7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866
867 DEV_DBG("%s: A[%ux%u] B[%ux%u] V[%ux%u] %s\n", __func__,
868 active_h, active_v, blank_h, blank_v, img_size_h, img_size_v,
869 interlaced ? "i" : "p");
870
871 *disp_mode = HDMI_VFRMT_FORCE_32BIT;
872 while (ndx < max_num_of_elements) {
873 const struct hdmi_edid_video_mode_property_type *edid =
874 hdmi_edid_disp_mode_lut+ndx;
875
876 if ((interlaced == edid->interlaced) &&
877 (active_h == edid->active_h) &&
878 (blank_h == edid->total_blank_h) &&
879 (blank_v == edid->total_blank_v) &&
880 ((active_v == edid->active_v) ||
881 (active_v == (edid->active_v + 1)))
882 ) {
883 if (edid->aspect_ratio_4_3 && !aspect_ratio_4_3)
884 /* Aspect ratio 16:9 */
885 *disp_mode = edid->video_code + 1;
886 else
887 /* Aspect ratio 4:3 */
888 *disp_mode = edid->video_code;
889
890 DEV_DBG("%s: mode found:%d\n", __func__, *disp_mode);
891 break;
892 }
893 ++ndx;
894 }
895 if (ndx == max_num_of_elements)
896 DEV_INFO("%s: *no mode* found\n", __func__);
897}
898
899static void add_supported_video_format(
900 struct hdmi_disp_mode_list_type *disp_mode_list,
901 uint32 video_format)
902{
903 const struct hdmi_disp_mode_timing_type *timing =
904 hdmi_common_get_supported_mode(video_format);
905 boolean supported = timing != NULL;
906
907 if (video_format >= HDMI_VFRMT_MAX)
908 return;
909
910 DEV_DBG("EDID: format: %d [%s], %s\n",
911 video_format, video_format_2string(video_format),
912 supported ? "Supported" : "Not-Supported");
913 if (supported)
914 disp_mode_list->disp_mode_list[
915 disp_mode_list->num_of_elements++] = video_format;
916}
917
918static void hdmi_edid_get_display_mode(const uint8 *data_buf,
919 struct hdmi_disp_mode_list_type *disp_mode_list,
920 uint32 num_og_cea_blocks)
921{
922 uint8 i = 0;
923 uint32 video_format = HDMI_VFRMT_640x480p60_4_3;
924 boolean has480p = FALSE;
925 uint8 len;
Manoj Rao668d6d52011-08-16 19:12:31 -0700926 const uint8 *edid_blk0 = &data_buf[0x0];
927 const uint8 *edid_blk1 = &data_buf[0x80];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928 const uint8 *svd = num_og_cea_blocks ?
929 hdmi_edid_find_block(data_buf+0x80, 2, &len) : NULL;
930
931 disp_mode_list->num_of_elements = 0;
932 if (svd != NULL) {
933 ++svd;
934 for (i = 0; i < len; ++i, ++svd) {
935 /* Subtract 1 because it is zero based in the driver,
936 * while the Video identification code is 1 based in the
937 * CEA_861D spec */
938 video_format = (*svd & 0x7F) - 1;
939 add_supported_video_format(disp_mode_list,
940 video_format);
941 if (video_format == HDMI_VFRMT_640x480p60_4_3)
942 has480p = TRUE;
943 }
944 } else if (!num_og_cea_blocks) {
945 /* Detailed timing descriptors */
946 uint32 desc_offset = 0;
947 /* Maximum 4 timing descriptor in block 0 - No CEA
948 * extension in this case */
949 /* EDID_FIRST_TIMING_DESC[0x36] - 1st detailed timing
950 * descriptor */
951 /* EDID_DETAIL_TIMING_DESC_BLCK_SZ[0x12] - Each detailed timing
952 * descriptor has block size of 18 */
Manoj Rao668d6d52011-08-16 19:12:31 -0700953 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
954 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700955 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -0700956 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
957 __func__, __LINE__,
958 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700959 add_supported_video_format(disp_mode_list,
960 video_format);
961 if (video_format == HDMI_VFRMT_640x480p60_4_3)
962 has480p = TRUE;
963 desc_offset += 0x12;
964 ++i;
965 }
966 } else if (1 == num_og_cea_blocks) {
967 uint32 desc_offset = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -0700968
969 /*
970 * Read from both block 0 and block 1
971 * Read EDID block[0] as above
972 */
973 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
974 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
975 &video_format);
976 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
977 __func__, __LINE__,
978 video_format_2string(video_format));
979 add_supported_video_format(disp_mode_list,
980 video_format);
981 if (video_format == HDMI_VFRMT_640x480p60_4_3)
982 has480p = TRUE;
983 desc_offset += 0x12;
984 ++i;
985 }
986
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 /* Parse block 1 - CEA extension byte offset of first
988 * detailed timing generation - offset is relevant to
989 * the offset of block 1 */
990
991 /* EDID_CEA_EXTENSION_FIRST_DESC[0x82]: Offset to CEA
992 * extension first timing desc - indicate the offset of
993 * the first detailed timing descriptor */
994 /* EDID_BLOCK_SIZE = 0x80 Each page size in the EDID ROM */
Manoj Rao668d6d52011-08-16 19:12:31 -0700995 desc_offset = edid_blk1[0x02];
996 while (0 != edid_blk1[desc_offset]) {
997 hdmi_edid_detail_desc(edid_blk1+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700998 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -0700999 DEV_DBG("[%s:%d] Block-1 Adding vid fmt = [%s]\n",
1000 __func__, __LINE__,
1001 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 add_supported_video_format(disp_mode_list,
1003 video_format);
1004 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1005 has480p = TRUE;
1006 desc_offset += 0x12;
1007 ++i;
1008 }
1009 }
1010
1011 if (!has480p)
1012 /* Need to add default 640 by 480 timings, in case not described
1013 * in the EDID structure.
1014 * All DTV sink devices should support this mode */
1015 add_supported_video_format(disp_mode_list,
1016 HDMI_VFRMT_640x480p60_4_3);
1017}
1018
1019static int hdmi_common_read_edid_block(int block, uint8 *edid_buf)
1020{
Manoj Rao668d6d52011-08-16 19:12:31 -07001021 uint32 ndx, check_sum, print_len;
1022#ifdef DEBUG
1023 const u8 *b = edid_buf;
1024#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025 int status = external_common_state->read_edid_block(block, edid_buf);
Manoj Rao668d6d52011-08-16 19:12:31 -07001026 if (status)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001027 goto error;
1028
1029 /* Calculate checksum */
1030 check_sum = 0;
1031 for (ndx = 0; ndx < 0x80; ++ndx)
1032 check_sum += edid_buf[ndx];
1033
1034 if (check_sum & 0xFF) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001035 DEV_ERR("%s: failed CHECKSUM (read:%x, expected:%x)\n",
1036 __func__, (uint8)edid_buf[0x7F], (uint8)check_sum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001037#ifdef DEBUG
1038 for (ndx = 0; ndx < 0x100; ndx += 16)
1039 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1040 "%02x %02x %02x %02x %02x %02x %02x %02x "
1041 "%02x %02x %02x %02x\n", ndx, ndx+15,
1042 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1043 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1044 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1045 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1046#endif
1047 status = -EPROTO;
1048 goto error;
1049 }
Manoj Rao668d6d52011-08-16 19:12:31 -07001050 print_len = 0x80;
1051 for (ndx = 0; ndx < print_len; ndx += 16)
1052 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1053 "%02x %02x %02x %02x %02x %02x %02x %02x "
1054 "%02x %02x %02x %02x\n", ndx, ndx+15,
1055 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1056 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1057 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1058 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1059
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001060
1061error:
1062 return status;
1063}
1064
1065static boolean check_edid_header(const uint8 *edid_buf)
1066{
1067 return (edid_buf[0] == 0x00) && (edid_buf[1] == 0xff)
1068 && (edid_buf[2] == 0xff) && (edid_buf[3] == 0xff)
1069 && (edid_buf[4] == 0xff) && (edid_buf[5] == 0xff)
1070 && (edid_buf[6] == 0xff) && (edid_buf[7] == 0x00);
1071}
1072
1073int hdmi_common_read_edid(void)
1074{
1075 int status = 0;
1076 uint32 cea_extension_ver = 0;
1077 uint32 num_og_cea_blocks = 0;
1078 uint32 ieee_reg_id = 0;
1079 uint32 i = 1;
1080 char vendor_id[5];
1081 /* EDID_BLOCK_SIZE[0x80] Each page size in the EDID ROM */
1082 uint8 edid_buf[0x80 * 4];
1083
1084 external_common_state->present_3d = 0;
1085 memset(&external_common_state->disp_mode_list, 0,
1086 sizeof(external_common_state->disp_mode_list));
1087 memset(edid_buf, 0, sizeof(edid_buf));
1088
1089 status = hdmi_common_read_edid_block(0, edid_buf);
1090 if (status || !check_edid_header(edid_buf)) {
1091 if (!status)
1092 status = -EPROTO;
1093 DEV_ERR("%s: edid read block(0) failed: %d "
1094 "[%02x%02x%02x%02x%02x%02x%02x%02x]\n", __func__,
1095 status,
1096 edid_buf[0], edid_buf[1], edid_buf[2], edid_buf[3],
1097 edid_buf[4], edid_buf[5], edid_buf[6], edid_buf[7]);
1098 goto error;
1099 }
1100 hdmi_edid_extract_vendor_id(edid_buf, vendor_id);
1101
1102 /* EDID_CEA_EXTENSION_FLAG[0x7E] - CEC extension byte */
1103 num_og_cea_blocks = edid_buf[0x7E];
1104
1105 DEV_DBG("[JSR] (%s): No. of CEA blocks is [%u]\n", __func__,
1106 num_og_cea_blocks);
1107 /* Find out any CEA extension blocks following block 0 */
1108 switch (num_og_cea_blocks) {
1109 case 0: /* No CEA extension */
1110 external_common_state->hdmi_sink = false;
1111 DEV_DBG("HDMI DVI mode: %s\n",
1112 external_common_state->hdmi_sink ? "no" : "yes");
1113 break;
1114 case 1: /* Read block 1 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001115 status = hdmi_common_read_edid_block(1, &edid_buf[0x80]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001116 if (status) {
1117 DEV_ERR("%s: ddc read block(1) failed: %d\n", __func__,
1118 status);
1119 goto error;
1120 }
1121 if (edid_buf[0x80] != 2)
1122 num_og_cea_blocks = 0;
1123 if (num_og_cea_blocks) {
1124 ieee_reg_id =
1125 hdmi_edid_extract_ieee_reg_id(edid_buf+0x80);
1126 if (ieee_reg_id == 0x0c03)
1127 external_common_state->hdmi_sink = TRUE ;
1128 else
1129 external_common_state->hdmi_sink = FALSE ;
1130 hdmi_edid_extract_latency_fields(edid_buf+0x80);
1131 hdmi_edid_extract_speaker_allocation_data(
1132 edid_buf+0x80);
1133 hdmi_edid_extract_audio_data_blocks(edid_buf+0x80);
1134 hdmi_edid_extract_3d_present(edid_buf+0x80);
1135 }
1136 break;
1137 case 2:
1138 case 3:
1139 case 4:
1140 for (i = 1; i <= num_og_cea_blocks; i++) {
1141 if (!(i % 2)) {
1142 status = hdmi_common_read_edid_block(i,
1143 edid_buf+0x00);
1144 if (status) {
1145 DEV_ERR("%s: ddc read block(%d)"
1146 "failed: %d\n", __func__, i,
1147 status);
1148 goto error;
1149 }
1150 } else {
1151 status = hdmi_common_read_edid_block(i,
1152 edid_buf+0x80);
1153 if (status) {
1154 DEV_ERR("%s: ddc read block(%d)"
1155 "failed:%d\n", __func__, i,
1156 status);
1157 goto error;
1158 }
1159 }
1160 }
1161 break;
1162 default:
1163 DEV_ERR("%s: ddc read failed, not supported multi-blocks: %d\n",
1164 __func__, num_og_cea_blocks);
1165 status = -EPROTO;
1166 goto error;
1167 }
1168
1169 if (num_og_cea_blocks) {
1170 /* EDID_CEA_EXTENSION_VERSION[0x81]: Offset to CEA extension
1171 * version number - v1,v2,v3 (v1 is seldom, v2 is obsolete,
1172 * v3 most common) */
1173 cea_extension_ver = edid_buf[0x81];
1174 }
1175
1176 /* EDID_VERSION[0x12] - EDID Version */
1177 /* EDID_REVISION[0x13] - EDID Revision */
1178 DEV_INFO("EDID (V=%d.%d, #CEABlocks=%d[V%d], ID=%s, IEEE=%04x, "
1179 "EDID-Ext=0x%02x)\n", edid_buf[0x12], edid_buf[0x13],
1180 num_og_cea_blocks, cea_extension_ver, vendor_id, ieee_reg_id,
1181 edid_buf[0x80]);
1182
1183 hdmi_edid_get_display_mode(edid_buf,
1184 &external_common_state->disp_mode_list, num_og_cea_blocks);
1185
1186 return 0;
1187
1188error:
1189 external_common_state->disp_mode_list.num_of_elements = 1;
1190 external_common_state->disp_mode_list.disp_mode_list[0] =
1191 external_common_state->video_resolution;
1192 return status;
1193}
1194EXPORT_SYMBOL(hdmi_common_read_edid);
1195
1196bool hdmi_common_get_video_format_from_drv_data(struct msm_fb_data_type *mfd)
1197{
1198 uint32 format;
1199 struct fb_var_screeninfo *var = &mfd->fbi->var;
1200 bool changed = TRUE;
1201
1202 if (var->reserved[3]) {
1203 format = var->reserved[3]-1;
1204 } else {
1205 DEV_DBG("detecting resolution from %dx%d use var->reserved[3]"
1206 " to specify mode", mfd->var_xres, mfd->var_yres);
1207 switch (mfd->var_xres) {
1208 default:
1209 case 640:
1210 format = HDMI_VFRMT_640x480p60_4_3;
1211 break;
1212 case 720:
1213 format = (mfd->var_yres == 480)
1214 ? HDMI_VFRMT_720x480p60_16_9
1215 : HDMI_VFRMT_720x576p50_16_9;
1216 break;
1217 case 1280:
1218 format = HDMI_VFRMT_1280x720p60_16_9;
1219 break;
1220 case 1440:
1221 format = (mfd->var_yres == 480)
1222 ? HDMI_VFRMT_1440x480i60_16_9
1223 : HDMI_VFRMT_1440x576i50_16_9;
1224 break;
1225 case 1920:
1226 format = HDMI_VFRMT_1920x1080p60_16_9;
1227 break;
1228 }
1229 }
1230
1231 changed = external_common_state->video_resolution != format;
1232 if (external_common_state->video_resolution != format)
1233 DEV_DBG("switching %s => %s", video_format_2string(
1234 external_common_state->video_resolution),
1235 video_format_2string(format));
1236 else
1237 DEV_DBG("resolution %s", video_format_2string(
1238 external_common_state->video_resolution));
1239 external_common_state->video_resolution = format;
1240 return changed;
1241}
1242EXPORT_SYMBOL(hdmi_common_get_video_format_from_drv_data);
1243
1244const struct hdmi_disp_mode_timing_type *hdmi_common_get_mode(uint32 mode)
1245{
1246 if (mode >= HDMI_VFRMT_MAX)
1247 return NULL;
1248
1249 return &hdmi_common_supported_video_mode_lut[mode];
1250}
1251EXPORT_SYMBOL(hdmi_common_get_mode);
1252
1253const struct hdmi_disp_mode_timing_type *hdmi_common_get_supported_mode(
1254 uint32 mode)
1255{
1256 const struct hdmi_disp_mode_timing_type *ret
1257 = hdmi_common_get_mode(mode);
1258
1259 if (ret == NULL || !ret->supported)
1260 return NULL;
1261 return ret;
1262}
1263EXPORT_SYMBOL(hdmi_common_get_supported_mode);
1264
1265void hdmi_common_init_panel_info(struct msm_panel_info *pinfo)
1266{
1267 const struct hdmi_disp_mode_timing_type *timing =
1268 hdmi_common_get_supported_mode(
1269 external_common_state->video_resolution);
1270
1271 if (timing == NULL)
1272 return;
1273
1274 pinfo->xres = timing->active_h;
1275 pinfo->yres = timing->active_v;
1276 pinfo->clk_rate = timing->pixel_freq*1000;
1277
1278 pinfo->lcdc.h_back_porch = timing->back_porch_h;
1279 pinfo->lcdc.h_front_porch = timing->front_porch_h;
1280 pinfo->lcdc.h_pulse_width = timing->pulse_width_h;
1281 pinfo->lcdc.v_back_porch = timing->back_porch_v;
1282 pinfo->lcdc.v_front_porch = timing->front_porch_v;
1283 pinfo->lcdc.v_pulse_width = timing->pulse_width_v;
1284
1285 pinfo->type = DTV_PANEL;
1286 pinfo->pdest = DISPLAY_2;
1287 pinfo->wait_cycle = 0;
1288 pinfo->bpp = 24;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001289#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
1290 pinfo->fb_num = 2;
1291#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001292 pinfo->fb_num = 1;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001293#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001294
1295 /* blk */
1296 pinfo->lcdc.border_clr = 0;
1297 /* blue */
1298 pinfo->lcdc.underflow_clr = 0xff;
1299 pinfo->lcdc.hsync_skew = 0;
1300}
1301EXPORT_SYMBOL(hdmi_common_init_panel_info);
1302#endif