blob: 7fd4c5629db3f58146e75e4520a416bee2794581 [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"
Manoj Raoa2c27672011-08-30 17:19:39 -070022#include "hdmi_msm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include "external_common.h"
Eugene Yasmand0de5f92011-12-20 13:57:28 +020024#include "mhl_api.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025
26struct external_common_state_type *external_common_state;
27EXPORT_SYMBOL(external_common_state);
28DEFINE_MUTEX(external_common_state_hpd_mutex);
29EXPORT_SYMBOL(external_common_state_hpd_mutex);
30
Manoj Raoa2c27672011-08-30 17:19:39 -070031
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032static int atoi(const char *name)
33{
34 int val = 0;
35
36 for (;; name++) {
37 switch (*name) {
38 case '0' ... '9':
39 val = 10*val+(*name-'0');
40 break;
41 default:
42 return val;
43 }
44 }
45}
46
Manoj Rao668d6d52011-08-16 19:12:31 -070047#ifdef DEBUG_EDID
48/*
49 * Block 0 - 1920x1080p, 1360x768p
50 * Block 1 - 1280x720p, 1920x540i, 720x480p
51 */
52const char edid_blk0[0x100] = {
530x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x4C, 0x2D, 0x03, 0x05, 0x00,
540x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78, 0x0A, 0xEE,
550x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F, 0x50, 0x54, 0xBD, 0xEF, 0x80, 0x71,
560x4F, 0x81, 0x00, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00, 0x95, 0x0F, 0xB3, 0x00,
570xA9, 0x40, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45,
580x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x66, 0x21, 0x50, 0xB0, 0x51, 0x00,
590x1B, 0x30, 0x40, 0x70, 0x36, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x00,
600x00, 0x00, 0xFD, 0x00, 0x18, 0x4B, 0x1A, 0x51, 0x17, 0x00, 0x0A, 0x20, 0x20,
610x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53, 0x41, 0x4D, 0x53,
620x55, 0x4E, 0x47, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x8F};
63
64const char edid_blk1[0x100] = {
650x02, 0x03, 0x1E, 0xF1, 0x46, 0x90, 0x04, 0x05, 0x03, 0x20, 0x22, 0x23, 0x09,
660x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0xE2, 0x00, 0x0F, 0x67, 0x03, 0x0C, 0x00,
670x10, 0x00, 0xB8, 0x2D, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20, 0x6E,
680x28, 0x55, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0x18,
690x71, 0x1C, 0x16, 0x20, 0x58, 0x2C, 0x25, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00,
700x9E, 0x8C, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10, 0x10, 0x3E, 0x96, 0x00,
710xA0, 0x5A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
730x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
740x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF};
75#endif /* DEBUG_EDID */
76
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077const char *video_format_2string(uint32 format)
78{
79 switch (format) {
80 default:
81#ifdef CONFIG_FB_MSM_HDMI_COMMON
82 case HDMI_VFRMT_640x480p60_4_3: return " 640x 480 p60 4/3";
83 case HDMI_VFRMT_720x480p60_4_3: return " 720x 480 p60 4/3";
84 case HDMI_VFRMT_720x480p60_16_9: return " 720x 480 p60 16/9";
85 case HDMI_VFRMT_1280x720p60_16_9: return "1280x 720 p60 16/9";
86 case HDMI_VFRMT_1920x1080i60_16_9: return "1920x1080 i60 16/9";
87 case HDMI_VFRMT_1440x480i60_4_3: return "1440x 480 i60 4/3";
88 case HDMI_VFRMT_1440x480i60_16_9: return "1440x 480 i60 16/9";
89 case HDMI_VFRMT_1440x240p60_4_3: return "1440x 240 p60 4/3";
90 case HDMI_VFRMT_1440x240p60_16_9: return "1440x 240 p60 16/9";
91 case HDMI_VFRMT_2880x480i60_4_3: return "2880x 480 i60 4/3";
92 case HDMI_VFRMT_2880x480i60_16_9: return "2880x 480 i60 16/9";
93 case HDMI_VFRMT_2880x240p60_4_3: return "2880x 240 p60 4/3";
94 case HDMI_VFRMT_2880x240p60_16_9: return "2880x 240 p60 16/9";
95 case HDMI_VFRMT_1440x480p60_4_3: return "1440x 480 p60 4/3";
96 case HDMI_VFRMT_1440x480p60_16_9: return "1440x 480 p60 16/9";
97 case HDMI_VFRMT_1920x1080p60_16_9: return "1920x1080 p60 16/9";
98 case HDMI_VFRMT_720x576p50_4_3: return " 720x 576 p50 4/3";
99 case HDMI_VFRMT_720x576p50_16_9: return " 720x 576 p50 16/9";
100 case HDMI_VFRMT_1280x720p50_16_9: return "1280x 720 p50 16/9";
101 case HDMI_VFRMT_1920x1080i50_16_9: return "1920x1080 i50 16/9";
102 case HDMI_VFRMT_1440x576i50_4_3: return "1440x 576 i50 4/3";
103 case HDMI_VFRMT_1440x576i50_16_9: return "1440x 576 i50 16/9";
104 case HDMI_VFRMT_1440x288p50_4_3: return "1440x 288 p50 4/3";
105 case HDMI_VFRMT_1440x288p50_16_9: return "1440x 288 p50 16/9";
106 case HDMI_VFRMT_2880x576i50_4_3: return "2880x 576 i50 4/3";
107 case HDMI_VFRMT_2880x576i50_16_9: return "2880x 576 i50 16/9";
108 case HDMI_VFRMT_2880x288p50_4_3: return "2880x 288 p50 4/3";
109 case HDMI_VFRMT_2880x288p50_16_9: return "2880x 288 p50 16/9";
110 case HDMI_VFRMT_1440x576p50_4_3: return "1440x 576 p50 4/3";
111 case HDMI_VFRMT_1440x576p50_16_9: return "1440x 576 p50 16/9";
112 case HDMI_VFRMT_1920x1080p50_16_9: return "1920x1080 p50 16/9";
113 case HDMI_VFRMT_1920x1080p24_16_9: return "1920x1080 p24 16/9";
114 case HDMI_VFRMT_1920x1080p25_16_9: return "1920x1080 p25 16/9";
115 case HDMI_VFRMT_1920x1080p30_16_9: return "1920x1080 p30 16/9";
116 case HDMI_VFRMT_2880x480p60_4_3: return "2880x 480 p60 4/3";
117 case HDMI_VFRMT_2880x480p60_16_9: return "2880x 480 p60 16/9";
118 case HDMI_VFRMT_2880x576p50_4_3: return "2880x 576 p50 4/3";
119 case HDMI_VFRMT_2880x576p50_16_9: return "2880x 576 p50 16/9";
120 case HDMI_VFRMT_1920x1250i50_16_9: return "1920x1250 i50 16/9";
121 case HDMI_VFRMT_1920x1080i100_16_9:return "1920x1080 i100 16/9";
122 case HDMI_VFRMT_1280x720p100_16_9: return "1280x 720 p100 16/9";
123 case HDMI_VFRMT_720x576p100_4_3: return " 720x 576 p100 4/3";
124 case HDMI_VFRMT_720x576p100_16_9: return " 720x 576 p100 16/9";
125 case HDMI_VFRMT_1440x576i100_4_3: return "1440x 576 i100 4/3";
126 case HDMI_VFRMT_1440x576i100_16_9: return "1440x 576 i100 16/9";
127 case HDMI_VFRMT_1920x1080i120_16_9:return "1920x1080 i120 16/9";
128 case HDMI_VFRMT_1280x720p120_16_9: return "1280x 720 p120 16/9";
129 case HDMI_VFRMT_720x480p120_4_3: return " 720x 480 p120 4/3";
130 case HDMI_VFRMT_720x480p120_16_9: return " 720x 480 p120 16/9";
131 case HDMI_VFRMT_1440x480i120_4_3: return "1440x 480 i120 4/3";
132 case HDMI_VFRMT_1440x480i120_16_9: return "1440x 480 i120 16/9";
133 case HDMI_VFRMT_720x576p200_4_3: return " 720x 576 p200 4/3";
134 case HDMI_VFRMT_720x576p200_16_9: return " 720x 576 p200 16/9";
135 case HDMI_VFRMT_1440x576i200_4_3: return "1440x 576 i200 4/3";
136 case HDMI_VFRMT_1440x576i200_16_9: return "1440x 576 i200 16/9";
137 case HDMI_VFRMT_720x480p240_4_3: return " 720x 480 p240 4/3";
138 case HDMI_VFRMT_720x480p240_16_9: return " 720x 480 p240 16/9";
139 case HDMI_VFRMT_1440x480i240_4_3: return "1440x 480 i240 4/3";
140 case HDMI_VFRMT_1440x480i240_16_9: return "1440x 480 i240 16/9";
141#elif defined(CONFIG_FB_MSM_TVOUT)
142 case TVOUT_VFRMT_NTSC_M_720x480i: return "NTSC_M_720x480i";
143 case TVOUT_VFRMT_NTSC_J_720x480i: return "NTSC_J_720x480i";
144 case TVOUT_VFRMT_PAL_BDGHIN_720x576i: return "PAL_BDGHIN_720x576i";
145 case TVOUT_VFRMT_PAL_M_720x480i: return "PAL_M_720x480i";
146 case TVOUT_VFRMT_PAL_N_720x480i: return "PAL_N_720x480i";
147#endif
148
149 }
150}
151EXPORT_SYMBOL(video_format_2string);
152
153static ssize_t external_common_rda_video_mode_str(struct device *dev,
154 struct device_attribute *attr, char *buf)
155{
156 ssize_t ret = snprintf(buf, PAGE_SIZE, "%s\n",
157 video_format_2string(external_common_state->video_resolution));
158 DEV_DBG("%s: '%s'\n", __func__,
159 video_format_2string(external_common_state->video_resolution));
160 return ret;
161}
162
163#ifdef CONFIG_FB_MSM_HDMI_COMMON
164struct hdmi_disp_mode_timing_type
165 hdmi_common_supported_video_mode_lut[HDMI_VFRMT_MAX] = {
166 HDMI_SETTINGS_640x480p60_4_3,
167 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_4_3),
168 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_16_9),
169 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p60_16_9),
170 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i60_16_9),
171 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_4_3),
172 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_16_9),
173 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_4_3),
174 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_16_9),
175 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_4_3),
176 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_16_9),
177 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_4_3),
178 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_16_9),
179 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_4_3),
180 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_16_9),
181 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p60_16_9),
182 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_4_3),
183 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_16_9),
184 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p50_16_9),
185 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i50_16_9),
186 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_4_3),
187 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_16_9),
188 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_4_3),
189 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_16_9),
190 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_4_3),
191 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_16_9),
192 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_4_3),
193 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_16_9),
194 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_4_3),
195 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_16_9),
196 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p50_16_9),
197 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p24_16_9),
198 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p25_16_9),
199 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p30_16_9),
200 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_4_3),
201 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_16_9),
202 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_4_3),
203 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_16_9),
204 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1250i50_16_9),
205 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i100_16_9),
206 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p100_16_9),
207 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_4_3),
208 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_16_9),
209 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_4_3),
210 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_16_9),
211 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i120_16_9),
212 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p120_16_9),
213 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_4_3),
214 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_16_9),
215 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_4_3),
216 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_16_9),
217 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_4_3),
218 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_16_9),
219 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_4_3),
220 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_16_9),
221 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_4_3),
222 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_16_9),
223 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_4_3),
224 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_16_9),
225};
226EXPORT_SYMBOL(hdmi_common_supported_video_mode_lut);
227
Eugene Yasmand0de5f92011-12-20 13:57:28 +0200228struct hdmi_disp_mode_timing_type
229 hdmi_mhl_supported_video_mode_lut[HDMI_VFRMT_MAX] = {
230 HDMI_SETTINGS_640x480p60_4_3,
231 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_4_3),
232 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p60_16_9),
233 HDMI_SETTINGS_1280x720p60_16_9,
234 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i60_16_9),
235 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_4_3),
236 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i60_16_9),
237 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_4_3),
238 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x240p60_16_9),
239 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_4_3),
240 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480i60_16_9),
241 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_4_3),
242 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x240p60_16_9),
243 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_4_3),
244 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480p60_16_9),
245 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p60_16_9),
246 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_4_3),
247 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p50_16_9),
248 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p50_16_9),
249 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i50_16_9),
250 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_4_3),
251 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i50_16_9),
252 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_4_3),
253 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x288p50_16_9),
254 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_4_3),
255 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576i50_16_9),
256 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_4_3),
257 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x288p50_16_9),
258 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_4_3),
259 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576p50_16_9),
260 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080p50_16_9),
261 HDMI_SETTINGS_1920x1080p24_16_9,
262 HDMI_SETTINGS_1920x1080p25_16_9,
263 HDMI_SETTINGS_1920x1080p30_16_9,
264 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_4_3),
265 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x480p60_16_9),
266 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_4_3),
267 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_2880x576p50_16_9),
268 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1250i50_16_9),
269 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i100_16_9),
270 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p100_16_9),
271 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_4_3),
272 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p100_16_9),
273 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_4_3),
274 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i100_16_9),
275 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1920x1080i120_16_9),
276 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1280x720p120_16_9),
277 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_4_3),
278 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p120_16_9),
279 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_4_3),
280 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i120_16_9),
281 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_4_3),
282 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x576p200_16_9),
283 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_4_3),
284 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x576i200_16_9),
285 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_4_3),
286 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_720x480p240_16_9),
287 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_4_3),
288 VFRMT_NOT_SUPPORTED(HDMI_VFRMT_1440x480i240_16_9),
289};
290EXPORT_SYMBOL(hdmi_mhl_supported_video_mode_lut);
291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292static ssize_t hdmi_common_rda_edid_modes(struct device *dev,
293 struct device_attribute *attr, char *buf)
294{
295 ssize_t ret = 0;
296 int i;
297
298 buf[0] = 0;
299 if (external_common_state->disp_mode_list.num_of_elements) {
300 uint32 *video_mode = external_common_state->disp_mode_list
301 .disp_mode_list;
302 for (i = 0; i < external_common_state->disp_mode_list
303 .num_of_elements; ++i) {
304 if (ret > 0)
305 ret += snprintf(buf+ret, PAGE_SIZE-ret, ",%d",
306 *video_mode++ + 1);
307 else
308 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
309 *video_mode++ + 1);
310 }
311 } else
312 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
313 external_common_state->video_resolution+1);
314
315 DEV_DBG("%s: '%s'\n", __func__, buf);
316 ret += snprintf(buf+ret, PAGE_SIZE-ret, "\n");
317 return ret;
318}
319
320static ssize_t hdmi_common_rda_hdcp(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->hdcp_active);
325 DEV_DBG("%s: '%d'\n", __func__,
326 external_common_state->hdcp_active);
327 return ret;
328}
329
330static ssize_t hdmi_common_rda_hpd(struct device *dev,
331 struct device_attribute *attr, char *buf)
332{
333 ssize_t ret;
334 if (external_common_state->hpd_feature) {
335 ret = snprintf(buf, PAGE_SIZE, "%d\n",
336 external_common_state->hpd_feature_on);
337 DEV_DBG("%s: '%d'\n", __func__,
338 external_common_state->hpd_feature_on);
339 } else {
340 ret = snprintf(buf, PAGE_SIZE, "-1\n");
341 DEV_DBG("%s: 'not supported'\n", __func__);
342 }
343 return ret;
344}
345
346static ssize_t hdmi_common_wta_hpd(struct device *dev,
347 struct device_attribute *attr, const char *buf, size_t count)
348{
349 ssize_t ret = strnlen(buf, PAGE_SIZE);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700350#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
351 int hpd = 1;
352#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700353 int hpd = atoi(buf);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700354#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355 if (external_common_state->hpd_feature) {
356 if (hpd == 0 && external_common_state->hpd_feature_on) {
357 external_common_state->hpd_feature(0);
358 external_common_state->hpd_feature_on = 0;
359 DEV_DBG("%s: '%d'\n", __func__,
360 external_common_state->hpd_feature_on);
361 } else if (hpd == 1 && !external_common_state->hpd_feature_on) {
362 external_common_state->hpd_feature(1);
363 external_common_state->hpd_feature_on = 1;
364 DEV_DBG("%s: '%d'\n", __func__,
365 external_common_state->hpd_feature_on);
366 } else {
367 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
368 external_common_state->hpd_feature_on);
369 }
370 } else {
371 DEV_DBG("%s: 'not supported'\n", __func__);
372 }
373
374 return ret;
375}
376
Manoj Raoa2c27672011-08-30 17:19:39 -0700377#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
378/*
379 * This interface for CEC feature is defined to suit
380 * the current requirements. However, the actual functionality is
381 * added to accommodate different interfaces
382 */
383static ssize_t hdmi_msm_rda_cec(struct device *dev,
384 struct device_attribute *attr, char *buf)
385{
386 /* 0x028C CEC_CTRL */
387 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
388 (HDMI_INP(0x028C) & BIT(0)));
389 return ret;
390}
391
392static ssize_t hdmi_msm_wta_cec(struct device *dev,
393 struct device_attribute *attr, const char *buf, size_t count)
394{
395 ssize_t ret = strnlen(buf, PAGE_SIZE);
396 int cec = atoi(buf);
397
398 if (cec != 0) {
399 mutex_lock(&hdmi_msm_state_mutex);
400 hdmi_msm_state->cec_enabled = true;
401 hdmi_msm_state->cec_logical_addr = 4;
402 mutex_unlock(&hdmi_msm_state_mutex);
403 hdmi_msm_cec_init();
404 hdmi_msm_cec_write_logical_addr(
405 hdmi_msm_state->cec_logical_addr);
406 DEV_DBG("CEC enabled\n");
407 } else {
408 mutex_lock(&hdmi_msm_state_mutex);
409 hdmi_msm_state->cec_enabled = false;
410 hdmi_msm_state->cec_logical_addr = 15;
411 mutex_unlock(&hdmi_msm_state_mutex);
412 hdmi_msm_cec_write_logical_addr(
413 hdmi_msm_state->cec_logical_addr);
414 /* 0x028C CEC_CTRL */
415 HDMI_OUTP(0x028C, 0);
416 DEV_DBG("CEC disabled\n");
417 }
418 return ret;
419}
420
421static ssize_t hdmi_msm_rda_cec_logical_addr(struct device *dev,
422 struct device_attribute *attr, char *buf)
423{
424 ssize_t ret;
425
426 mutex_lock(&hdmi_msm_state_mutex);
427 ret = snprintf(buf, PAGE_SIZE, "%d\n",
428 hdmi_msm_state->cec_logical_addr);
429 mutex_unlock(&hdmi_msm_state_mutex);
430 return ret;
431}
432
433static ssize_t hdmi_msm_wta_cec_logical_addr(struct device *dev,
434 struct device_attribute *attr, const char *buf, size_t count)
435{
436
Manoj Rao0f0ab642011-11-01 12:28:24 -0700437#ifdef DRVR_ONLY_CECT_NO_DAEMON
Manoj Raoa2c27672011-08-30 17:19:39 -0700438 /*
439 * Only for testing
440 */
441 hdmi_msm_cec_one_touch_play();
442 return 0;
443#else
444 ssize_t ret = strnlen(buf, PAGE_SIZE);
445 int logical_addr = atoi(buf);
446
447 if (logical_addr < 0 || logical_addr > 15)
448 return -EINVAL;
449
450 mutex_lock(&hdmi_msm_state_mutex);
451 hdmi_msm_state->cec_logical_addr = logical_addr;
452 mutex_unlock(&hdmi_msm_state_mutex);
453
454 hdmi_msm_cec_write_logical_addr(logical_addr);
455
456 return ret;
457#endif
458}
459
460static ssize_t hdmi_msm_rda_cec_frame(struct device *dev,
461 struct device_attribute *attr, char *buf)
462{
463 mutex_lock(&hdmi_msm_state_mutex);
464 if (hdmi_msm_state->cec_queue_rd == hdmi_msm_state->cec_queue_wr
465 && !hdmi_msm_state->cec_queue_full) {
466 mutex_unlock(&hdmi_msm_state_mutex);
467 DEV_ERR("CEC message queue is empty\n");
468 return -EBUSY;
469 }
470 memcpy(buf, hdmi_msm_state->cec_queue_rd++,
471 sizeof(struct hdmi_msm_cec_msg));
472 hdmi_msm_state->cec_queue_full = false;
473 if (hdmi_msm_state->cec_queue_rd == CEC_QUEUE_END)
474 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
475 mutex_unlock(&hdmi_msm_state_mutex);
476
477 return sizeof(struct hdmi_msm_cec_msg);
478}
479
480static ssize_t hdmi_msm_wta_cec_frame(struct device *dev,
481 struct device_attribute *attr, const char *buf, size_t count)
482{
483 int retry = ((struct hdmi_msm_cec_msg *) buf)->retransmit;
484
485 if (retry > 15)
486 retry = 15;
487 while (1) {
488 hdmi_msm_cec_msg_send((struct hdmi_msm_cec_msg *) buf);
489 if (hdmi_msm_state->cec_frame_wr_status
490 & CEC_STATUS_WR_ERROR && retry--)
491 msleep(360);
492 else
493 break;
494 }
495
496 if (hdmi_msm_state->cec_frame_wr_status & CEC_STATUS_WR_DONE)
497 return sizeof(struct hdmi_msm_cec_msg);
498 else
499 return -EINVAL;
500}
501#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
502
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700503static ssize_t hdmi_common_rda_3d_present(struct device *dev,
504 struct device_attribute *attr, char *buf)
505{
506 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
507 external_common_state->present_3d);
508 DEV_DBG("%s: '%d'\n", __func__,
509 external_common_state->present_3d);
510 return ret;
511}
512
513static ssize_t hdmi_common_rda_hdcp_present(struct device *dev,
514 struct device_attribute *attr, char *buf)
515{
516 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
517 external_common_state->present_hdcp);
518 DEV_DBG("%s: '%d'\n", __func__,
519 external_common_state->present_hdcp);
520 return ret;
521}
522#endif
523
524#ifdef CONFIG_FB_MSM_HDMI_3D
525static ssize_t hdmi_3d_rda_format_3d(struct device *dev,
526 struct device_attribute *attr, char *buf)
527{
528 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
529 external_common_state->format_3d);
530 DEV_DBG("%s: '%d'\n", __func__,
531 external_common_state->format_3d);
532 return ret;
533}
534
535static ssize_t hdmi_3d_wta_format_3d(struct device *dev,
536 struct device_attribute *attr, const char *buf, size_t count)
537{
538 ssize_t ret = strnlen(buf, PAGE_SIZE);
539 int format_3d = atoi(buf);
540
541 if (format_3d >= 0 && format_3d <= 2) {
542 if (format_3d != external_common_state->format_3d) {
543 external_common_state->format_3d = format_3d;
544 if (external_common_state->switch_3d)
545 external_common_state->switch_3d(format_3d);
546 DEV_DBG("%s: '%d'\n", __func__,
547 external_common_state->format_3d);
548 } else {
549 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
550 external_common_state->format_3d);
551 }
552 } else {
553 DEV_DBG("%s: '%d' (unknown)\n", __func__, format_3d);
554 }
555
556 return ret;
557}
558#endif
559
Manoj Raoa2c27672011-08-30 17:19:39 -0700560#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
561static DEVICE_ATTR(cec, S_IRUGO | S_IWUSR,
562 hdmi_msm_rda_cec,
563 hdmi_msm_wta_cec);
564
565static DEVICE_ATTR(cec_logical_addr, S_IRUGO | S_IWUSR,
566 hdmi_msm_rda_cec_logical_addr,
567 hdmi_msm_wta_cec_logical_addr);
568
569static DEVICE_ATTR(cec_rd_frame, S_IRUGO,
570 hdmi_msm_rda_cec_frame, NULL);
571
572static DEVICE_ATTR(cec_wr_frame, S_IWUSR,
573 NULL, hdmi_msm_wta_cec_frame);
574#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
575
576
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577static ssize_t external_common_rda_video_mode(struct device *dev,
578 struct device_attribute *attr, char *buf)
579{
580 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
581 external_common_state->video_resolution+1);
582 DEV_DBG("%s: '%d'\n", __func__,
583 external_common_state->video_resolution+1);
584 return ret;
585}
586
587static ssize_t external_common_wta_video_mode(struct device *dev,
588 struct device_attribute *attr, const char *buf, size_t count)
589{
590 ssize_t ret = strnlen(buf, PAGE_SIZE);
591 uint32 video_mode;
592#ifdef CONFIG_FB_MSM_HDMI_COMMON
593 const struct hdmi_disp_mode_timing_type *disp_mode;
594#endif
595 mutex_lock(&external_common_state_hpd_mutex);
596 if (!external_common_state->hpd_state) {
597 mutex_unlock(&external_common_state_hpd_mutex);
598 DEV_INFO("%s: FAILED: display off or cable disconnected\n",
599 __func__);
600 return ret;
601 }
602 mutex_unlock(&external_common_state_hpd_mutex);
603
604 video_mode = atoi(buf)-1;
Eugene Yasmand0de5f92011-12-20 13:57:28 +0200605 DEV_INFO("%s: video_mode is %d\n", __func__, video_mode);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700606 kobject_uevent(external_common_state->uevent_kobj, KOBJ_OFFLINE);
607#ifdef CONFIG_FB_MSM_HDMI_COMMON
608 disp_mode = hdmi_common_get_supported_mode(video_mode);
609 if (!disp_mode) {
610 DEV_INFO("%s: FAILED: mode not supported (%d)\n",
611 __func__, video_mode);
612 return ret;
613 }
614 external_common_state->disp_mode_list.num_of_elements = 1;
615 external_common_state->disp_mode_list.disp_mode_list[0] = video_mode;
616#elif defined(CONFIG_FB_MSM_TVOUT)
617 external_common_state->video_resolution = video_mode;
618#endif
619 DEV_DBG("%s: 'mode=%d %s' successful (sending OFF/ONLINE)\n", __func__,
620 video_mode, video_format_2string(video_mode));
621 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ONLINE);
622 return ret;
623}
624
625static ssize_t external_common_rda_connected(struct device *dev,
626 struct device_attribute *attr, char *buf)
627{
628 ssize_t ret;
629 mutex_lock(&external_common_state_hpd_mutex);
630 ret = snprintf(buf, PAGE_SIZE, "%d\n",
631 external_common_state->hpd_state);
632 DEV_DBG("%s: '%d'\n", __func__,
633 external_common_state->hpd_state);
634 mutex_unlock(&external_common_state_hpd_mutex);
635 return ret;
636}
637
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530638static ssize_t external_common_rda_hdmi_mode(struct device *dev,
639 struct device_attribute *attr, char *buf)
640{
641 ssize_t ret;
642
643 ret = snprintf(buf, PAGE_SIZE, "%d\n",
644 external_common_state->hdmi_sink);
645
646 DEV_DBG("%s: '%d'\n", __func__,
647 external_common_state->hdmi_sink);
648
649 return ret;
650}
651
652
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700653static DEVICE_ATTR(video_mode, S_IRUGO | S_IWUGO,
654 external_common_rda_video_mode, external_common_wta_video_mode);
655static DEVICE_ATTR(video_mode_str, S_IRUGO, external_common_rda_video_mode_str,
656 NULL);
657static DEVICE_ATTR(connected, S_IRUGO, external_common_rda_connected, NULL);
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530658static DEVICE_ATTR(hdmi_mode, S_IRUGO, external_common_rda_hdmi_mode, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659#ifdef CONFIG_FB_MSM_HDMI_COMMON
660static DEVICE_ATTR(edid_modes, S_IRUGO, hdmi_common_rda_edid_modes, NULL);
661static DEVICE_ATTR(hpd, S_IRUGO | S_IWUGO, hdmi_common_rda_hpd,
662 hdmi_common_wta_hpd);
663static DEVICE_ATTR(hdcp, S_IRUGO, hdmi_common_rda_hdcp, NULL);
664static DEVICE_ATTR(3d_present, S_IRUGO, hdmi_common_rda_3d_present, NULL);
665static DEVICE_ATTR(hdcp_present, S_IRUGO, hdmi_common_rda_hdcp_present, NULL);
666#endif
667#ifdef CONFIG_FB_MSM_HDMI_3D
668static DEVICE_ATTR(format_3d, S_IRUGO | S_IWUGO, hdmi_3d_rda_format_3d,
669 hdmi_3d_wta_format_3d);
670#endif
671
672static struct attribute *external_common_fs_attrs[] = {
673 &dev_attr_video_mode.attr,
674 &dev_attr_video_mode_str.attr,
675 &dev_attr_connected.attr,
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530676 &dev_attr_hdmi_mode.attr,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700677#ifdef CONFIG_FB_MSM_HDMI_COMMON
678 &dev_attr_edid_modes.attr,
679 &dev_attr_hdcp.attr,
680 &dev_attr_hpd.attr,
681 &dev_attr_3d_present.attr,
682 &dev_attr_hdcp_present.attr,
683#endif
684#ifdef CONFIG_FB_MSM_HDMI_3D
685 &dev_attr_format_3d.attr,
686#endif
Manoj Raoa2c27672011-08-30 17:19:39 -0700687#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
688 &dev_attr_cec.attr,
689 &dev_attr_cec_logical_addr.attr,
690 &dev_attr_cec_rd_frame.attr,
691 &dev_attr_cec_wr_frame.attr,
692#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700693 NULL,
694};
695static struct attribute_group external_common_fs_attr_group = {
696 .attrs = external_common_fs_attrs,
697};
698
699/* create external interface kobject and initialize */
700int external_common_state_create(struct platform_device *pdev)
701{
702 int rc;
703 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
704 if (!mfd) {
705 DEV_ERR("%s: mfd not found\n", __func__);
706 return -ENODEV;
707 }
708 if (!mfd->fbi) {
709 DEV_ERR("%s: mfd->fbi not found\n", __func__);
710 return -ENODEV;
711 }
712 if (!mfd->fbi->dev) {
713 DEV_ERR("%s: mfd->fbi->dev not found\n", __func__);
714 return -ENODEV;
715 }
716 rc = sysfs_create_group(&mfd->fbi->dev->kobj,
717 &external_common_fs_attr_group);
718 if (rc) {
719 DEV_ERR("%s: sysfs group creation failed, rc=%d\n", __func__,
720 rc);
721 return rc;
722 }
723 external_common_state->uevent_kobj = &mfd->fbi->dev->kobj;
724 DEV_ERR("%s: sysfs group %p\n", __func__,
725 external_common_state->uevent_kobj);
726
727 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ADD);
728 DEV_DBG("%s: kobject_uevent(KOBJ_ADD)\n", __func__);
729 return 0;
730}
731EXPORT_SYMBOL(external_common_state_create);
732
733void external_common_state_remove(void)
734{
735 if (external_common_state->uevent_kobj)
736 sysfs_remove_group(external_common_state->uevent_kobj,
737 &external_common_fs_attr_group);
738 external_common_state->uevent_kobj = NULL;
739}
740EXPORT_SYMBOL(external_common_state_remove);
741
742#ifdef CONFIG_FB_MSM_HDMI_COMMON
743/* The Logic ID for HDMI TX Core. Currently only support 1 HDMI TX Core. */
744struct hdmi_edid_video_mode_property_type {
745 uint32 video_code;
746 uint32 active_h;
747 uint32 active_v;
748 boolean interlaced;
749 uint32 total_h;
750 uint32 total_blank_h;
751 uint32 total_v;
752 uint32 total_blank_v;
753 /* Must divide by 1000 to get the frequency */
754 uint32 freq_h;
755 /* Must divide by 1000 to get the frequency */
756 uint32 freq_v;
757 /* Must divide by 1000 to get the frequency */
758 uint32 pixel_freq;
759 /* Must divide by 1000 to get the frequency */
760 uint32 refresh_rate;
761 boolean aspect_ratio_4_3;
762};
763
764/* LUT is sorted from lowest Active H to highest Active H - ease searching */
765static struct hdmi_edid_video_mode_property_type
766 hdmi_edid_disp_mode_lut[] = {
767
768 /* All 640 H Active */
769 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
770 31465, 59940, 25175, 59940, TRUE},
771 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
772 31500, 60000, 25200, 60000, TRUE},
773
774 /* All 720 H Active */
775 {HDMI_VFRMT_720x576p50_4_3, 720, 576, FALSE, 864, 144, 625, 49,
776 31250, 50000, 27000, 50000, TRUE},
777 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
778 31465, 59940, 27000, 59940, TRUE},
779 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
780 31500, 60000, 27030, 60000, TRUE},
781 {HDMI_VFRMT_720x576p100_4_3, 720, 576, FALSE, 864, 144, 625, 49,
782 62500, 100000, 54000, 100000, TRUE},
783 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
784 62937, 119880, 54000, 119880, TRUE},
785 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
786 63000, 120000, 54054, 120000, TRUE},
787 {HDMI_VFRMT_720x576p200_4_3, 720, 576, FALSE, 864, 144, 625, 49,
788 125000, 200000, 108000, 200000, TRUE},
789 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
790 125874, 239760, 108000, 239000, TRUE},
791 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
792 126000, 240000, 108108, 240000, TRUE},
793
794 /* All 1280 H Active */
795 {HDMI_VFRMT_1280x720p50_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
796 37500, 50000, 74250, 50000, FALSE},
797 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
798 44955, 59940, 74176, 59940, FALSE},
799 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
800 45000, 60000, 74250, 60000, FALSE},
801 {HDMI_VFRMT_1280x720p100_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
802 75000, 100000, 148500, 100000, FALSE},
803 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
804 89909, 119880, 148352, 119880, FALSE},
805 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
806 90000, 120000, 148500, 120000, FALSE},
807
808 /* All 1440 H Active */
809 {HDMI_VFRMT_1440x576i50_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
810 15625, 50000, 27000, 50000, TRUE},
811 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 312, 24,
812 15625, 50080, 27000, 50000, TRUE},
813 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 313, 25,
814 15625, 49920, 27000, 50000, TRUE},
815 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 314, 26,
816 15625, 49761, 27000, 50000, TRUE},
817 {HDMI_VFRMT_1440x576p50_4_3, 1440, 576, FALSE, 1728, 288, 625, 49,
818 31250, 50000, 54000, 50000, TRUE},
819 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
820 15734, 59940, 27000, 59940, TRUE},
821 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
822 15734, 60054, 27000, 59940, TRUE},
823 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
824 15734, 59826, 27000, 59940, TRUE},
825 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
826 31469, 59940, 54000, 59940, TRUE},
827 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
828 15750, 60000, 27027, 60000, TRUE},
829 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
830 15750, 60115, 27027, 60000, TRUE},
831 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
832 15750, 59886, 27027, 60000, TRUE},
833 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
834 31500, 60000, 54054, 60000, TRUE},
835 {HDMI_VFRMT_1440x576i100_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
836 31250, 100000, 54000, 100000, TRUE},
837 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
838 31469, 119880, 54000, 119880, TRUE},
839 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
840 31500, 120000, 54054, 120000, TRUE},
841 {HDMI_VFRMT_1440x576i200_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
842 62500, 200000, 108000, 200000, TRUE},
843 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
844 62937, 239760, 108000, 239000, TRUE},
845 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
846 63000, 240000, 108108, 240000, TRUE},
847
848 /* All 1920 H Active */
849 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
850 45, 67433, 59940, 148352, 59940, FALSE},
851 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
852 45, 67500, 60000, 148500, 60000, FALSE},
853 {HDMI_VFRMT_1920x1080p50_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
854 45, 56250, 50000, 148500, 50000, FALSE},
855 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
856 45, 26973, 23976, 74176, 24000, FALSE},
857 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
858 45, 27000, 24000, 74250, 24000, FALSE},
859 {HDMI_VFRMT_1920x1080p25_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
860 45, 28125, 25000, 74250, 25000, FALSE},
861 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
862 45, 33716, 29970, 74176, 30000, FALSE},
863 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
864 45, 33750, 30000, 74250, 30000, FALSE},
865 {HDMI_VFRMT_1920x1080i50_16_9, 1920, 1080, TRUE, 2304, 384, 1250,
866 85, 31250, 50000, 72000, 50000, FALSE},
867 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
868 22, 33716, 59940, 74176, 59940, FALSE},
869 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
870 22, 33750, 60000, 74250, 60000, FALSE},
871 {HDMI_VFRMT_1920x1080i100_16_9, 1920, 1080, TRUE, 2640, 720, 1125,
872 22, 56250, 100000, 148500, 100000, FALSE},
873 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
874 22, 67432, 119880, 148352, 119980, FALSE},
875 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
876 22, 67500, 120000, 148500, 120000, FALSE},
877
878 /* All 2880 H Active */
879 {HDMI_VFRMT_2880x576i50_4_3, 2880, 576, TRUE, 3456, 576, 625, 24,
880 15625, 50000, 54000, 50000, TRUE},
881 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 312, 24,
882 15625, 50080, 54000, 50000, TRUE},
883 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 313, 25,
884 15625, 49920, 54000, 50000, TRUE},
885 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 314, 26,
886 15625, 49761, 54000, 50000, TRUE},
887 {HDMI_VFRMT_2880x576p50_4_3, 2880, 576, FALSE, 3456, 576, 625, 49,
888 31250, 50000, 108000, 50000, TRUE},
889 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
890 15734, 59940, 54000, 59940, TRUE},
891 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 262, 22,
892 15734, 60054, 54000, 59940, TRUE},
893 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 263, 23,
894 15734, 59940, 54000, 59940, TRUE},
895 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
896 31469, 59940, 108000, 59940, TRUE},
897 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
898 15750, 60000, 54054, 60000, TRUE},
899 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 22,
900 15750, 60115, 54054, 60000, TRUE},
901 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 23,
902 15750, 59886, 54054, 60000, TRUE},
903 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
904 31500, 60000, 108108, 60000, TRUE},
905};
906
907static const uint8 *hdmi_edid_find_block(const uint8 *in_buf, uint8 type,
908 uint8 *len)
909{
910 /* the start of data block collection, start of Video Data Block */
911 uint32 offset = 4;
912
913 *len = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -0700914 if ((in_buf[2] == 4) && (type != 2)) { /* no non-DTD data present */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915 DEV_WARN("EDID: no non-DTD data present\n");
916 return NULL;
917 }
918 while (offset < 0x80) {
919 uint8 block_len = in_buf[offset] & 0x1F;
920 if ((in_buf[offset] >> 5) == type) {
921 *len = block_len;
922 DEV_DBG("EDID: block=%d found @ %d with length=%d\n",
923 type, offset, block_len);
924 return in_buf+offset;
925 }
926 offset += 1 + block_len;
927 }
Manoj Rao668d6d52011-08-16 19:12:31 -0700928 DEV_WARN("EDID: type=%d block not found in EDID block\n", type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929 return NULL;
930}
931
932static void hdmi_edid_extract_vendor_id(const uint8 *in_buf,
933 char *vendor_id)
934{
935 uint32 id_codes = ((uint32)in_buf[8] << 8) + in_buf[9];
936
937 vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
938 vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
939 vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
940 vendor_id[3] = 0;
941}
942
943static uint32 hdmi_edid_extract_ieee_reg_id(const uint8 *in_buf)
944{
945 uint8 len;
946 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
947
948 if (vsd == NULL)
949 return 0;
950
951 DEV_DBG("EDID: VSD PhyAddr=%04x, MaxTMDS=%dMHz\n",
952 ((uint32)vsd[6] << 8) + (uint32)vsd[5], (uint32)vsd[7] * 5);
953 return ((uint32)vsd[3] << 16) + ((uint32)vsd[2] << 8) + (uint32)vsd[1];
954}
955
956static void hdmi_edid_extract_3d_present(const uint8 *in_buf)
957{
958 uint8 len, offset;
959 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
960
961 external_common_state->present_3d = 0;
962 if (vsd == NULL || len < 9) {
963 DEV_DBG("EDID[3D]: block-id 3 not found or not long enough\n");
964 return;
965 }
966
967 offset = !(vsd[8] & BIT(7)) ? 9 : 13;
968 DEV_DBG("EDID: 3D present @ %d = %02x\n", offset, vsd[offset]);
969 if (vsd[offset] >> 7) { /* 3D format indication present */
970 DEV_INFO("EDID: 3D present, 3D-len=%d\n", vsd[offset+1] & 0x1F);
971 external_common_state->present_3d = 1;
972 }
973}
974
975
976static void hdmi_edid_extract_latency_fields(const uint8 *in_buf)
977{
978 uint8 len;
979 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
980
981 if (vsd == NULL || len < 12 || !(vsd[8] & BIT(7))) {
982 external_common_state->video_latency = (uint16)-1;
983 external_common_state->audio_latency = (uint16)-1;
984 DEV_DBG("EDID: No audio/video latency present\n");
985 } else {
986 external_common_state->video_latency = vsd[9];
987 external_common_state->audio_latency = vsd[10];
988 DEV_DBG("EDID: video-latency=%04x, audio-latency=%04x\n",
989 external_common_state->video_latency,
990 external_common_state->audio_latency);
991 }
992}
993
994static void hdmi_edid_extract_speaker_allocation_data(const uint8 *in_buf)
995{
996 uint8 len;
997 const uint8 *sad = hdmi_edid_find_block(in_buf, 4, &len);
998
999 if (sad == NULL)
1000 return;
1001
1002 external_common_state->speaker_allocation_block = sad[1];
1003 DEV_DBG("EDID: speaker allocation data=%s%s%s%s%s%s%s\n",
1004 (sad[1] & BIT(0)) ? "FL/FR," : "",
1005 (sad[1] & BIT(1)) ? "LFE," : "",
1006 (sad[1] & BIT(2)) ? "FC," : "",
1007 (sad[1] & BIT(3)) ? "RL/RR," : "",
1008 (sad[1] & BIT(4)) ? "RC," : "",
1009 (sad[1] & BIT(5)) ? "FLC/FRC," : "",
1010 (sad[1] & BIT(6)) ? "LFE," : "");
1011}
1012
1013static void hdmi_edid_extract_audio_data_blocks(const uint8 *in_buf)
1014{
1015 uint8 len;
1016 const uint8 *sad = hdmi_edid_find_block(in_buf, 1, &len);
1017 uint32 *adb = external_common_state->audio_data_blocks;
1018
1019 if (sad == NULL)
1020 return;
1021
1022 external_common_state->audio_data_block_cnt = 0;
1023 while (len >= 3 && external_common_state->audio_data_block_cnt < 16) {
1024 DEV_DBG("EDID: Audio Data Block=<ch=%d, format=%d "
1025 "sampling=0x%02x bit-depth=0x%02x>\n",
1026 (sad[1] & 0x7)+1, sad[1] >> 3, sad[2], sad[3]);
1027 *adb++ = (uint32)sad[1] + ((uint32)sad[2] << 8)
1028 + ((uint32)sad[2] << 16);
1029 ++external_common_state->audio_data_block_cnt;
1030 len -= 3;
1031 sad += 3;
1032 }
1033}
1034
1035
1036static void hdmi_edid_detail_desc(const uint8 *data_buf, uint32 *disp_mode)
1037{
1038 boolean aspect_ratio_4_3 = FALSE;
1039 boolean interlaced = FALSE;
1040 uint32 active_h = 0;
1041 uint32 active_v = 0;
1042 uint32 blank_h = 0;
1043 uint32 blank_v = 0;
1044 uint32 ndx = 0;
1045 uint32 max_num_of_elements = 0;
1046 uint32 img_size_h = 0;
1047 uint32 img_size_v = 0;
1048
1049 /* See VESA Spec */
1050 /* EDID_TIMING_DESC_UPPER_H_NIBBLE[0x4]: Relative Offset to the EDID
1051 * detailed timing descriptors - Upper 4 bit for each H active/blank
1052 * field */
1053 /* EDID_TIMING_DESC_H_ACTIVE[0x2]: Relative Offset to the EDID detailed
1054 * timing descriptors - H active */
1055 active_h = ((((uint32)data_buf[0x4] >> 0x4) & 0xF) << 8)
1056 | data_buf[0x2];
1057
1058 /* EDID_TIMING_DESC_H_BLANK[0x3]: Relative Offset to the EDID detailed
1059 * timing descriptors - H blank */
1060 blank_h = (((uint32)data_buf[0x4] & 0xF) << 8)
1061 | data_buf[0x3];
1062
1063 /* EDID_TIMING_DESC_UPPER_V_NIBBLE[0x7]: Relative Offset to the EDID
1064 * detailed timing descriptors - Upper 4 bit for each V active/blank
1065 * field */
1066 /* EDID_TIMING_DESC_V_ACTIVE[0x5]: Relative Offset to the EDID detailed
1067 * timing descriptors - V active */
1068 active_v = ((((uint32)data_buf[0x7] >> 0x4) & 0xF) << 8)
1069 | data_buf[0x5];
1070
1071 /* EDID_TIMING_DESC_V_BLANK[0x6]: Relative Offset to the EDID detailed
1072 * timing descriptors - V blank */
1073 blank_v = (((uint32)data_buf[0x7] & 0xF) << 8)
1074 | data_buf[0x6];
1075
1076 /* EDID_TIMING_DESC_IMAGE_SIZE_UPPER_NIBBLE[0xE]: Relative Offset to the
1077 * EDID detailed timing descriptors - Image Size upper nibble
1078 * V and H */
1079 /* EDID_TIMING_DESC_H_IMAGE_SIZE[0xC]: Relative Offset to the EDID
1080 * detailed timing descriptors - H image size */
1081 /* EDID_TIMING_DESC_V_IMAGE_SIZE[0xD]: Relative Offset to the EDID
1082 * detailed timing descriptors - V image size */
1083 img_size_h = ((((uint32)data_buf[0xE] >> 0x4) & 0xF) << 8)
1084 | data_buf[0xC];
1085 img_size_v = (((uint32)data_buf[0xE] & 0xF) << 8)
1086 | data_buf[0xD];
1087
Abhishek Kharbanda402adc62011-12-15 12:21:29 -08001088 /*
1089 * aspect ratio as 4:3 if within specificed range , rathaer than being
1090 * absolute value
1091 */
1092 aspect_ratio_4_3 = (abs(img_size_h * 3 - img_size_v * 4) < 5) ? 1 : 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093
1094 max_num_of_elements = sizeof(hdmi_edid_disp_mode_lut)
1095 / sizeof(*hdmi_edid_disp_mode_lut);
1096
Manoj Rao668d6d52011-08-16 19:12:31 -07001097 /* EDID_TIMING_DESC_INTERLACE[0x11:7]: Relative Offset to the EDID
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001098 * detailed timing descriptors - Interlace flag */
Manoj Rao668d6d52011-08-16 19:12:31 -07001099 DEV_DBG("Interlaced mode byte data_buf[0x11]=[%x]\n", data_buf[0x11]);
1100 /*
1101 * CEA 861-D: interlaced bit is bit[7] of byte[0x11]
1102 */
1103 interlaced = (data_buf[0x11] & 0x80) >> 7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001104
1105 DEV_DBG("%s: A[%ux%u] B[%ux%u] V[%ux%u] %s\n", __func__,
1106 active_h, active_v, blank_h, blank_v, img_size_h, img_size_v,
1107 interlaced ? "i" : "p");
1108
1109 *disp_mode = HDMI_VFRMT_FORCE_32BIT;
1110 while (ndx < max_num_of_elements) {
1111 const struct hdmi_edid_video_mode_property_type *edid =
1112 hdmi_edid_disp_mode_lut+ndx;
1113
1114 if ((interlaced == edid->interlaced) &&
1115 (active_h == edid->active_h) &&
1116 (blank_h == edid->total_blank_h) &&
1117 (blank_v == edid->total_blank_v) &&
1118 ((active_v == edid->active_v) ||
1119 (active_v == (edid->active_v + 1)))
1120 ) {
1121 if (edid->aspect_ratio_4_3 && !aspect_ratio_4_3)
1122 /* Aspect ratio 16:9 */
1123 *disp_mode = edid->video_code + 1;
1124 else
1125 /* Aspect ratio 4:3 */
1126 *disp_mode = edid->video_code;
1127
1128 DEV_DBG("%s: mode found:%d\n", __func__, *disp_mode);
1129 break;
1130 }
1131 ++ndx;
1132 }
1133 if (ndx == max_num_of_elements)
1134 DEV_INFO("%s: *no mode* found\n", __func__);
1135}
1136
1137static void add_supported_video_format(
1138 struct hdmi_disp_mode_list_type *disp_mode_list,
1139 uint32 video_format)
1140{
1141 const struct hdmi_disp_mode_timing_type *timing =
1142 hdmi_common_get_supported_mode(video_format);
1143 boolean supported = timing != NULL;
1144
1145 if (video_format >= HDMI_VFRMT_MAX)
1146 return;
1147
1148 DEV_DBG("EDID: format: %d [%s], %s\n",
1149 video_format, video_format_2string(video_format),
1150 supported ? "Supported" : "Not-Supported");
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001151 if (supported) {
1152 if (mhl_is_connected()) {
1153 const struct hdmi_disp_mode_timing_type *mhl_timing =
1154 hdmi_mhl_get_supported_mode(video_format);
1155 boolean mhl_supported = mhl_timing != NULL;
1156 DEV_DBG("EDID: format: %d [%s], %s by MHL\n",
1157 video_format, video_format_2string(video_format),
1158 mhl_supported ? "Supported" : "Not-Supported");
1159 if (mhl_supported)
1160 disp_mode_list->disp_mode_list[
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161 disp_mode_list->num_of_elements++] = video_format;
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001162 } else
1163 disp_mode_list->disp_mode_list[
1164 disp_mode_list->num_of_elements++] = video_format;
1165 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166}
1167
1168static void hdmi_edid_get_display_mode(const uint8 *data_buf,
1169 struct hdmi_disp_mode_list_type *disp_mode_list,
1170 uint32 num_og_cea_blocks)
1171{
1172 uint8 i = 0;
1173 uint32 video_format = HDMI_VFRMT_640x480p60_4_3;
1174 boolean has480p = FALSE;
1175 uint8 len;
Manoj Rao668d6d52011-08-16 19:12:31 -07001176 const uint8 *edid_blk0 = &data_buf[0x0];
1177 const uint8 *edid_blk1 = &data_buf[0x80];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001178 const uint8 *svd = num_og_cea_blocks ?
1179 hdmi_edid_find_block(data_buf+0x80, 2, &len) : NULL;
1180
1181 disp_mode_list->num_of_elements = 0;
1182 if (svd != NULL) {
1183 ++svd;
1184 for (i = 0; i < len; ++i, ++svd) {
1185 /* Subtract 1 because it is zero based in the driver,
1186 * while the Video identification code is 1 based in the
1187 * CEA_861D spec */
1188 video_format = (*svd & 0x7F) - 1;
1189 add_supported_video_format(disp_mode_list,
1190 video_format);
1191 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1192 has480p = TRUE;
1193 }
1194 } else if (!num_og_cea_blocks) {
1195 /* Detailed timing descriptors */
1196 uint32 desc_offset = 0;
1197 /* Maximum 4 timing descriptor in block 0 - No CEA
1198 * extension in this case */
1199 /* EDID_FIRST_TIMING_DESC[0x36] - 1st detailed timing
1200 * descriptor */
1201 /* EDID_DETAIL_TIMING_DESC_BLCK_SZ[0x12] - Each detailed timing
1202 * descriptor has block size of 18 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001203 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1204 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001206 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1207 __func__, __LINE__,
1208 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209 add_supported_video_format(disp_mode_list,
1210 video_format);
1211 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1212 has480p = TRUE;
1213 desc_offset += 0x12;
1214 ++i;
1215 }
1216 } else if (1 == num_og_cea_blocks) {
1217 uint32 desc_offset = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -07001218
1219 /*
1220 * Read from both block 0 and block 1
1221 * Read EDID block[0] as above
1222 */
1223 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1224 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
1225 &video_format);
1226 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1227 __func__, __LINE__,
1228 video_format_2string(video_format));
1229 add_supported_video_format(disp_mode_list,
1230 video_format);
1231 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1232 has480p = TRUE;
1233 desc_offset += 0x12;
1234 ++i;
1235 }
1236
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001237 /* Parse block 1 - CEA extension byte offset of first
1238 * detailed timing generation - offset is relevant to
1239 * the offset of block 1 */
1240
1241 /* EDID_CEA_EXTENSION_FIRST_DESC[0x82]: Offset to CEA
1242 * extension first timing desc - indicate the offset of
1243 * the first detailed timing descriptor */
1244 /* EDID_BLOCK_SIZE = 0x80 Each page size in the EDID ROM */
Manoj Rao668d6d52011-08-16 19:12:31 -07001245 desc_offset = edid_blk1[0x02];
1246 while (0 != edid_blk1[desc_offset]) {
1247 hdmi_edid_detail_desc(edid_blk1+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001248 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001249 DEV_DBG("[%s:%d] Block-1 Adding vid fmt = [%s]\n",
1250 __func__, __LINE__,
1251 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001252 add_supported_video_format(disp_mode_list,
1253 video_format);
1254 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1255 has480p = TRUE;
1256 desc_offset += 0x12;
1257 ++i;
1258 }
1259 }
1260
1261 if (!has480p)
1262 /* Need to add default 640 by 480 timings, in case not described
1263 * in the EDID structure.
1264 * All DTV sink devices should support this mode */
1265 add_supported_video_format(disp_mode_list,
1266 HDMI_VFRMT_640x480p60_4_3);
1267}
1268
1269static int hdmi_common_read_edid_block(int block, uint8 *edid_buf)
1270{
Manoj Rao668d6d52011-08-16 19:12:31 -07001271 uint32 ndx, check_sum, print_len;
1272#ifdef DEBUG
1273 const u8 *b = edid_buf;
1274#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001275 int status = external_common_state->read_edid_block(block, edid_buf);
Manoj Rao668d6d52011-08-16 19:12:31 -07001276 if (status)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001277 goto error;
1278
1279 /* Calculate checksum */
1280 check_sum = 0;
1281 for (ndx = 0; ndx < 0x80; ++ndx)
1282 check_sum += edid_buf[ndx];
1283
1284 if (check_sum & 0xFF) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285 DEV_ERR("%s: failed CHECKSUM (read:%x, expected:%x)\n",
1286 __func__, (uint8)edid_buf[0x7F], (uint8)check_sum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001287#ifdef DEBUG
1288 for (ndx = 0; ndx < 0x100; ndx += 16)
1289 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1290 "%02x %02x %02x %02x %02x %02x %02x %02x "
1291 "%02x %02x %02x %02x\n", ndx, ndx+15,
1292 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1293 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1294 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1295 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1296#endif
1297 status = -EPROTO;
1298 goto error;
1299 }
Manoj Rao668d6d52011-08-16 19:12:31 -07001300 print_len = 0x80;
1301 for (ndx = 0; ndx < print_len; ndx += 16)
1302 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1303 "%02x %02x %02x %02x %02x %02x %02x %02x "
1304 "%02x %02x %02x %02x\n", ndx, ndx+15,
1305 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1306 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1307 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1308 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1309
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001310
1311error:
1312 return status;
1313}
1314
1315static boolean check_edid_header(const uint8 *edid_buf)
1316{
1317 return (edid_buf[0] == 0x00) && (edid_buf[1] == 0xff)
1318 && (edid_buf[2] == 0xff) && (edid_buf[3] == 0xff)
1319 && (edid_buf[4] == 0xff) && (edid_buf[5] == 0xff)
1320 && (edid_buf[6] == 0xff) && (edid_buf[7] == 0x00);
1321}
1322
1323int hdmi_common_read_edid(void)
1324{
1325 int status = 0;
1326 uint32 cea_extension_ver = 0;
1327 uint32 num_og_cea_blocks = 0;
1328 uint32 ieee_reg_id = 0;
1329 uint32 i = 1;
1330 char vendor_id[5];
1331 /* EDID_BLOCK_SIZE[0x80] Each page size in the EDID ROM */
1332 uint8 edid_buf[0x80 * 4];
1333
1334 external_common_state->present_3d = 0;
1335 memset(&external_common_state->disp_mode_list, 0,
1336 sizeof(external_common_state->disp_mode_list));
1337 memset(edid_buf, 0, sizeof(edid_buf));
1338
1339 status = hdmi_common_read_edid_block(0, edid_buf);
1340 if (status || !check_edid_header(edid_buf)) {
1341 if (!status)
1342 status = -EPROTO;
1343 DEV_ERR("%s: edid read block(0) failed: %d "
1344 "[%02x%02x%02x%02x%02x%02x%02x%02x]\n", __func__,
1345 status,
1346 edid_buf[0], edid_buf[1], edid_buf[2], edid_buf[3],
1347 edid_buf[4], edid_buf[5], edid_buf[6], edid_buf[7]);
1348 goto error;
1349 }
1350 hdmi_edid_extract_vendor_id(edid_buf, vendor_id);
1351
1352 /* EDID_CEA_EXTENSION_FLAG[0x7E] - CEC extension byte */
1353 num_og_cea_blocks = edid_buf[0x7E];
1354
1355 DEV_DBG("[JSR] (%s): No. of CEA blocks is [%u]\n", __func__,
1356 num_og_cea_blocks);
1357 /* Find out any CEA extension blocks following block 0 */
1358 switch (num_og_cea_blocks) {
1359 case 0: /* No CEA extension */
1360 external_common_state->hdmi_sink = false;
1361 DEV_DBG("HDMI DVI mode: %s\n",
1362 external_common_state->hdmi_sink ? "no" : "yes");
1363 break;
1364 case 1: /* Read block 1 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001365 status = hdmi_common_read_edid_block(1, &edid_buf[0x80]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001366 if (status) {
1367 DEV_ERR("%s: ddc read block(1) failed: %d\n", __func__,
1368 status);
1369 goto error;
1370 }
1371 if (edid_buf[0x80] != 2)
1372 num_og_cea_blocks = 0;
1373 if (num_og_cea_blocks) {
1374 ieee_reg_id =
1375 hdmi_edid_extract_ieee_reg_id(edid_buf+0x80);
1376 if (ieee_reg_id == 0x0c03)
1377 external_common_state->hdmi_sink = TRUE ;
1378 else
1379 external_common_state->hdmi_sink = FALSE ;
1380 hdmi_edid_extract_latency_fields(edid_buf+0x80);
1381 hdmi_edid_extract_speaker_allocation_data(
1382 edid_buf+0x80);
1383 hdmi_edid_extract_audio_data_blocks(edid_buf+0x80);
1384 hdmi_edid_extract_3d_present(edid_buf+0x80);
1385 }
1386 break;
1387 case 2:
1388 case 3:
1389 case 4:
1390 for (i = 1; i <= num_og_cea_blocks; i++) {
1391 if (!(i % 2)) {
1392 status = hdmi_common_read_edid_block(i,
1393 edid_buf+0x00);
1394 if (status) {
1395 DEV_ERR("%s: ddc read block(%d)"
1396 "failed: %d\n", __func__, i,
1397 status);
1398 goto error;
1399 }
1400 } else {
1401 status = hdmi_common_read_edid_block(i,
1402 edid_buf+0x80);
1403 if (status) {
1404 DEV_ERR("%s: ddc read block(%d)"
1405 "failed:%d\n", __func__, i,
1406 status);
1407 goto error;
1408 }
1409 }
1410 }
1411 break;
1412 default:
1413 DEV_ERR("%s: ddc read failed, not supported multi-blocks: %d\n",
1414 __func__, num_og_cea_blocks);
1415 status = -EPROTO;
1416 goto error;
1417 }
1418
1419 if (num_og_cea_blocks) {
1420 /* EDID_CEA_EXTENSION_VERSION[0x81]: Offset to CEA extension
1421 * version number - v1,v2,v3 (v1 is seldom, v2 is obsolete,
1422 * v3 most common) */
1423 cea_extension_ver = edid_buf[0x81];
1424 }
1425
1426 /* EDID_VERSION[0x12] - EDID Version */
1427 /* EDID_REVISION[0x13] - EDID Revision */
1428 DEV_INFO("EDID (V=%d.%d, #CEABlocks=%d[V%d], ID=%s, IEEE=%04x, "
1429 "EDID-Ext=0x%02x)\n", edid_buf[0x12], edid_buf[0x13],
1430 num_og_cea_blocks, cea_extension_ver, vendor_id, ieee_reg_id,
1431 edid_buf[0x80]);
1432
1433 hdmi_edid_get_display_mode(edid_buf,
1434 &external_common_state->disp_mode_list, num_og_cea_blocks);
1435
1436 return 0;
1437
1438error:
1439 external_common_state->disp_mode_list.num_of_elements = 1;
1440 external_common_state->disp_mode_list.disp_mode_list[0] =
1441 external_common_state->video_resolution;
1442 return status;
1443}
1444EXPORT_SYMBOL(hdmi_common_read_edid);
1445
1446bool hdmi_common_get_video_format_from_drv_data(struct msm_fb_data_type *mfd)
1447{
1448 uint32 format;
1449 struct fb_var_screeninfo *var = &mfd->fbi->var;
1450 bool changed = TRUE;
1451
1452 if (var->reserved[3]) {
1453 format = var->reserved[3]-1;
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001454 DEV_DBG("reserved format is %d\n", format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001455 } else {
1456 DEV_DBG("detecting resolution from %dx%d use var->reserved[3]"
1457 " to specify mode", mfd->var_xres, mfd->var_yres);
1458 switch (mfd->var_xres) {
1459 default:
1460 case 640:
1461 format = HDMI_VFRMT_640x480p60_4_3;
1462 break;
1463 case 720:
1464 format = (mfd->var_yres == 480)
1465 ? HDMI_VFRMT_720x480p60_16_9
1466 : HDMI_VFRMT_720x576p50_16_9;
1467 break;
1468 case 1280:
1469 format = HDMI_VFRMT_1280x720p60_16_9;
1470 break;
1471 case 1440:
1472 format = (mfd->var_yres == 480)
1473 ? HDMI_VFRMT_1440x480i60_16_9
1474 : HDMI_VFRMT_1440x576i50_16_9;
1475 break;
1476 case 1920:
1477 format = HDMI_VFRMT_1920x1080p60_16_9;
1478 break;
1479 }
1480 }
1481
1482 changed = external_common_state->video_resolution != format;
1483 if (external_common_state->video_resolution != format)
1484 DEV_DBG("switching %s => %s", video_format_2string(
1485 external_common_state->video_resolution),
1486 video_format_2string(format));
1487 else
1488 DEV_DBG("resolution %s", video_format_2string(
1489 external_common_state->video_resolution));
1490 external_common_state->video_resolution = format;
1491 return changed;
1492}
1493EXPORT_SYMBOL(hdmi_common_get_video_format_from_drv_data);
1494
1495const struct hdmi_disp_mode_timing_type *hdmi_common_get_mode(uint32 mode)
1496{
1497 if (mode >= HDMI_VFRMT_MAX)
1498 return NULL;
1499
1500 return &hdmi_common_supported_video_mode_lut[mode];
1501}
1502EXPORT_SYMBOL(hdmi_common_get_mode);
1503
1504const struct hdmi_disp_mode_timing_type *hdmi_common_get_supported_mode(
1505 uint32 mode)
1506{
1507 const struct hdmi_disp_mode_timing_type *ret
1508 = hdmi_common_get_mode(mode);
1509
1510 if (ret == NULL || !ret->supported)
1511 return NULL;
1512 return ret;
1513}
1514EXPORT_SYMBOL(hdmi_common_get_supported_mode);
1515
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001516const struct hdmi_disp_mode_timing_type *hdmi_mhl_get_mode(uint32 mode)
1517{
1518 if (mode >= HDMI_VFRMT_MAX)
1519 return NULL;
1520
1521 return &hdmi_mhl_supported_video_mode_lut[mode];
1522}
1523EXPORT_SYMBOL(hdmi_mhl_get_mode);
1524
1525const struct hdmi_disp_mode_timing_type *hdmi_mhl_get_supported_mode(
1526 uint32 mode)
1527{
1528 const struct hdmi_disp_mode_timing_type *ret
1529 = hdmi_mhl_get_mode(mode);
1530
1531 if (ret == NULL || !ret->supported)
1532 return NULL;
1533 return ret;
1534}
1535EXPORT_SYMBOL(hdmi_mhl_get_supported_mode);
1536
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001537void hdmi_common_init_panel_info(struct msm_panel_info *pinfo)
1538{
1539 const struct hdmi_disp_mode_timing_type *timing =
1540 hdmi_common_get_supported_mode(
1541 external_common_state->video_resolution);
1542
1543 if (timing == NULL)
1544 return;
1545
1546 pinfo->xres = timing->active_h;
1547 pinfo->yres = timing->active_v;
1548 pinfo->clk_rate = timing->pixel_freq*1000;
1549
1550 pinfo->lcdc.h_back_porch = timing->back_porch_h;
1551 pinfo->lcdc.h_front_porch = timing->front_porch_h;
1552 pinfo->lcdc.h_pulse_width = timing->pulse_width_h;
1553 pinfo->lcdc.v_back_porch = timing->back_porch_v;
1554 pinfo->lcdc.v_front_porch = timing->front_porch_v;
1555 pinfo->lcdc.v_pulse_width = timing->pulse_width_v;
1556
1557 pinfo->type = DTV_PANEL;
1558 pinfo->pdest = DISPLAY_2;
1559 pinfo->wait_cycle = 0;
1560 pinfo->bpp = 24;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001561#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
1562 pinfo->fb_num = 2;
1563#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001564 pinfo->fb_num = 1;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001565#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001566
1567 /* blk */
1568 pinfo->lcdc.border_clr = 0;
1569 /* blue */
1570 pinfo->lcdc.underflow_clr = 0xff;
1571 pinfo->lcdc.hsync_skew = 0;
1572}
1573EXPORT_SYMBOL(hdmi_common_init_panel_info);
1574#endif