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