blob: 90702f3b01590bf4f27c9fb491830b07898ed514 [file] [log] [blame]
Kiran Kandi94f25dc2012-01-31 00:18:33 -08001/* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 Kalyanam0bb7fe92011-10-27 16:06:30 -0700350 int hpd;
351 if (hdmi_prim_display)
352 hpd = 1;
353 else
354 hpd = atoi(buf);
355
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700356 if (external_common_state->hpd_feature) {
357 if (hpd == 0 && external_common_state->hpd_feature_on) {
358 external_common_state->hpd_feature(0);
359 external_common_state->hpd_feature_on = 0;
360 DEV_DBG("%s: '%d'\n", __func__,
361 external_common_state->hpd_feature_on);
362 } else if (hpd == 1 && !external_common_state->hpd_feature_on) {
363 external_common_state->hpd_feature(1);
364 external_common_state->hpd_feature_on = 1;
365 DEV_DBG("%s: '%d'\n", __func__,
366 external_common_state->hpd_feature_on);
367 } else {
368 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
369 external_common_state->hpd_feature_on);
370 }
371 } else {
372 DEV_DBG("%s: 'not supported'\n", __func__);
373 }
374
375 return ret;
376}
377
Manoj Raoa2c27672011-08-30 17:19:39 -0700378#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
379/*
380 * This interface for CEC feature is defined to suit
381 * the current requirements. However, the actual functionality is
382 * added to accommodate different interfaces
383 */
384static ssize_t hdmi_msm_rda_cec(struct device *dev,
385 struct device_attribute *attr, char *buf)
386{
387 /* 0x028C CEC_CTRL */
388 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
389 (HDMI_INP(0x028C) & BIT(0)));
390 return ret;
391}
392
393static ssize_t hdmi_msm_wta_cec(struct device *dev,
394 struct device_attribute *attr, const char *buf, size_t count)
395{
396 ssize_t ret = strnlen(buf, PAGE_SIZE);
397 int cec = atoi(buf);
398
399 if (cec != 0) {
400 mutex_lock(&hdmi_msm_state_mutex);
401 hdmi_msm_state->cec_enabled = true;
402 hdmi_msm_state->cec_logical_addr = 4;
Ajay Singh Parmar60b26062012-03-15 14:40:11 +0530403
404 /* flush CEC queue */
405 hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
406 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
407 hdmi_msm_state->cec_queue_full = false;
408 memset(hdmi_msm_state->cec_queue_rd, 0,
409 sizeof(struct hdmi_msm_cec_msg)*CEC_QUEUE_SIZE);
410
Manoj Raoa2c27672011-08-30 17:19:39 -0700411 mutex_unlock(&hdmi_msm_state_mutex);
412 hdmi_msm_cec_init();
413 hdmi_msm_cec_write_logical_addr(
414 hdmi_msm_state->cec_logical_addr);
415 DEV_DBG("CEC enabled\n");
416 } else {
417 mutex_lock(&hdmi_msm_state_mutex);
418 hdmi_msm_state->cec_enabled = false;
419 hdmi_msm_state->cec_logical_addr = 15;
420 mutex_unlock(&hdmi_msm_state_mutex);
421 hdmi_msm_cec_write_logical_addr(
422 hdmi_msm_state->cec_logical_addr);
423 /* 0x028C CEC_CTRL */
424 HDMI_OUTP(0x028C, 0);
425 DEV_DBG("CEC disabled\n");
426 }
427 return ret;
428}
429
430static ssize_t hdmi_msm_rda_cec_logical_addr(struct device *dev,
431 struct device_attribute *attr, char *buf)
432{
433 ssize_t ret;
434
435 mutex_lock(&hdmi_msm_state_mutex);
436 ret = snprintf(buf, PAGE_SIZE, "%d\n",
437 hdmi_msm_state->cec_logical_addr);
438 mutex_unlock(&hdmi_msm_state_mutex);
439 return ret;
440}
441
442static ssize_t hdmi_msm_wta_cec_logical_addr(struct device *dev,
443 struct device_attribute *attr, const char *buf, size_t count)
444{
445
Manoj Rao0f0ab642011-11-01 12:28:24 -0700446#ifdef DRVR_ONLY_CECT_NO_DAEMON
Manoj Raoa2c27672011-08-30 17:19:39 -0700447 /*
448 * Only for testing
449 */
450 hdmi_msm_cec_one_touch_play();
451 return 0;
452#else
453 ssize_t ret = strnlen(buf, PAGE_SIZE);
454 int logical_addr = atoi(buf);
455
456 if (logical_addr < 0 || logical_addr > 15)
457 return -EINVAL;
458
459 mutex_lock(&hdmi_msm_state_mutex);
460 hdmi_msm_state->cec_logical_addr = logical_addr;
461 mutex_unlock(&hdmi_msm_state_mutex);
462
463 hdmi_msm_cec_write_logical_addr(logical_addr);
464
465 return ret;
466#endif
467}
468
469static ssize_t hdmi_msm_rda_cec_frame(struct device *dev,
470 struct device_attribute *attr, char *buf)
471{
472 mutex_lock(&hdmi_msm_state_mutex);
473 if (hdmi_msm_state->cec_queue_rd == hdmi_msm_state->cec_queue_wr
474 && !hdmi_msm_state->cec_queue_full) {
475 mutex_unlock(&hdmi_msm_state_mutex);
476 DEV_ERR("CEC message queue is empty\n");
477 return -EBUSY;
478 }
479 memcpy(buf, hdmi_msm_state->cec_queue_rd++,
480 sizeof(struct hdmi_msm_cec_msg));
481 hdmi_msm_state->cec_queue_full = false;
482 if (hdmi_msm_state->cec_queue_rd == CEC_QUEUE_END)
483 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
484 mutex_unlock(&hdmi_msm_state_mutex);
485
486 return sizeof(struct hdmi_msm_cec_msg);
487}
488
489static ssize_t hdmi_msm_wta_cec_frame(struct device *dev,
490 struct device_attribute *attr, const char *buf, size_t count)
491{
Manoj Rao15735992012-01-26 17:15:09 -0800492 int i;
Manoj Raoa2c27672011-08-30 17:19:39 -0700493 int retry = ((struct hdmi_msm_cec_msg *) buf)->retransmit;
494
Manoj Rao15735992012-01-26 17:15:09 -0800495 for (i = 0; i < RETRANSMIT_MAX_NUM; i++) {
Manoj Raoa2c27672011-08-30 17:19:39 -0700496 hdmi_msm_cec_msg_send((struct hdmi_msm_cec_msg *) buf);
497 if (hdmi_msm_state->cec_frame_wr_status
Manoj Rao15735992012-01-26 17:15:09 -0800498 & CEC_STATUS_WR_ERROR && retry--) {
499 mutex_lock(&hdmi_msm_state_mutex);
500 if (hdmi_msm_state->fsm_reset_done)
501 retry++;
502 mutex_unlock(&hdmi_msm_state_mutex);
Manoj Raoa2c27672011-08-30 17:19:39 -0700503 msleep(360);
Manoj Rao15735992012-01-26 17:15:09 -0800504 } else
Manoj Raoa2c27672011-08-30 17:19:39 -0700505 break;
506 }
507
508 if (hdmi_msm_state->cec_frame_wr_status & CEC_STATUS_WR_DONE)
509 return sizeof(struct hdmi_msm_cec_msg);
510 else
511 return -EINVAL;
512}
513#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
514
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700515static ssize_t hdmi_common_rda_3d_present(struct device *dev,
516 struct device_attribute *attr, char *buf)
517{
518 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
519 external_common_state->present_3d);
520 DEV_DBG("%s: '%d'\n", __func__,
521 external_common_state->present_3d);
522 return ret;
523}
524
525static ssize_t hdmi_common_rda_hdcp_present(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->present_hdcp);
530 DEV_DBG("%s: '%d'\n", __func__,
531 external_common_state->present_hdcp);
532 return ret;
533}
534#endif
535
536#ifdef CONFIG_FB_MSM_HDMI_3D
537static ssize_t hdmi_3d_rda_format_3d(struct device *dev,
538 struct device_attribute *attr, char *buf)
539{
540 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
541 external_common_state->format_3d);
542 DEV_DBG("%s: '%d'\n", __func__,
543 external_common_state->format_3d);
544 return ret;
545}
546
547static ssize_t hdmi_3d_wta_format_3d(struct device *dev,
548 struct device_attribute *attr, const char *buf, size_t count)
549{
550 ssize_t ret = strnlen(buf, PAGE_SIZE);
551 int format_3d = atoi(buf);
552
553 if (format_3d >= 0 && format_3d <= 2) {
554 if (format_3d != external_common_state->format_3d) {
555 external_common_state->format_3d = format_3d;
556 if (external_common_state->switch_3d)
557 external_common_state->switch_3d(format_3d);
558 DEV_DBG("%s: '%d'\n", __func__,
559 external_common_state->format_3d);
560 } else {
561 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
562 external_common_state->format_3d);
563 }
564 } else {
565 DEV_DBG("%s: '%d' (unknown)\n", __func__, format_3d);
566 }
567
568 return ret;
569}
570#endif
571
Manoj Raoa2c27672011-08-30 17:19:39 -0700572#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
573static DEVICE_ATTR(cec, S_IRUGO | S_IWUSR,
574 hdmi_msm_rda_cec,
575 hdmi_msm_wta_cec);
576
577static DEVICE_ATTR(cec_logical_addr, S_IRUGO | S_IWUSR,
578 hdmi_msm_rda_cec_logical_addr,
579 hdmi_msm_wta_cec_logical_addr);
580
581static DEVICE_ATTR(cec_rd_frame, S_IRUGO,
582 hdmi_msm_rda_cec_frame, NULL);
583
584static DEVICE_ATTR(cec_wr_frame, S_IWUSR,
585 NULL, hdmi_msm_wta_cec_frame);
586#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
587
588
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700589static ssize_t external_common_rda_video_mode(struct device *dev,
590 struct device_attribute *attr, char *buf)
591{
592 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
593 external_common_state->video_resolution+1);
594 DEV_DBG("%s: '%d'\n", __func__,
595 external_common_state->video_resolution+1);
596 return ret;
597}
598
599static ssize_t external_common_wta_video_mode(struct device *dev,
600 struct device_attribute *attr, const char *buf, size_t count)
601{
602 ssize_t ret = strnlen(buf, PAGE_SIZE);
603 uint32 video_mode;
604#ifdef CONFIG_FB_MSM_HDMI_COMMON
605 const struct hdmi_disp_mode_timing_type *disp_mode;
606#endif
607 mutex_lock(&external_common_state_hpd_mutex);
608 if (!external_common_state->hpd_state) {
609 mutex_unlock(&external_common_state_hpd_mutex);
610 DEV_INFO("%s: FAILED: display off or cable disconnected\n",
611 __func__);
612 return ret;
613 }
614 mutex_unlock(&external_common_state_hpd_mutex);
615
616 video_mode = atoi(buf)-1;
Eugene Yasmand0de5f92011-12-20 13:57:28 +0200617 DEV_INFO("%s: video_mode is %d\n", __func__, video_mode);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700618 kobject_uevent(external_common_state->uevent_kobj, KOBJ_OFFLINE);
619#ifdef CONFIG_FB_MSM_HDMI_COMMON
620 disp_mode = hdmi_common_get_supported_mode(video_mode);
621 if (!disp_mode) {
622 DEV_INFO("%s: FAILED: mode not supported (%d)\n",
623 __func__, video_mode);
624 return ret;
625 }
626 external_common_state->disp_mode_list.num_of_elements = 1;
627 external_common_state->disp_mode_list.disp_mode_list[0] = video_mode;
628#elif defined(CONFIG_FB_MSM_TVOUT)
629 external_common_state->video_resolution = video_mode;
630#endif
631 DEV_DBG("%s: 'mode=%d %s' successful (sending OFF/ONLINE)\n", __func__,
632 video_mode, video_format_2string(video_mode));
633 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ONLINE);
634 return ret;
635}
636
637static ssize_t external_common_rda_connected(struct device *dev,
638 struct device_attribute *attr, char *buf)
639{
640 ssize_t ret;
641 mutex_lock(&external_common_state_hpd_mutex);
642 ret = snprintf(buf, PAGE_SIZE, "%d\n",
643 external_common_state->hpd_state);
644 DEV_DBG("%s: '%d'\n", __func__,
645 external_common_state->hpd_state);
646 mutex_unlock(&external_common_state_hpd_mutex);
647 return ret;
648}
649
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530650static ssize_t external_common_rda_hdmi_mode(struct device *dev,
651 struct device_attribute *attr, char *buf)
652{
653 ssize_t ret;
654
655 ret = snprintf(buf, PAGE_SIZE, "%d\n",
656 external_common_state->hdmi_sink);
657
658 DEV_DBG("%s: '%d'\n", __func__,
659 external_common_state->hdmi_sink);
660
661 return ret;
662}
663
Ravishangar Kalyanam0bb7fe92011-10-27 16:06:30 -0700664static ssize_t hdmi_common_rda_hdmi_primary(struct device *dev,
665 struct device_attribute *attr, char *buf)
666{
667 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
668 hdmi_prim_display);
669 DEV_DBG("%s: '%d'\n", __func__, hdmi_prim_display);
670 return ret;
671}
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530672
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673static DEVICE_ATTR(video_mode, S_IRUGO | S_IWUGO,
674 external_common_rda_video_mode, external_common_wta_video_mode);
675static DEVICE_ATTR(video_mode_str, S_IRUGO, external_common_rda_video_mode_str,
676 NULL);
677static DEVICE_ATTR(connected, S_IRUGO, external_common_rda_connected, NULL);
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530678static DEVICE_ATTR(hdmi_mode, S_IRUGO, external_common_rda_hdmi_mode, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700679#ifdef CONFIG_FB_MSM_HDMI_COMMON
680static DEVICE_ATTR(edid_modes, S_IRUGO, hdmi_common_rda_edid_modes, NULL);
681static DEVICE_ATTR(hpd, S_IRUGO | S_IWUGO, hdmi_common_rda_hpd,
682 hdmi_common_wta_hpd);
683static DEVICE_ATTR(hdcp, S_IRUGO, hdmi_common_rda_hdcp, NULL);
684static DEVICE_ATTR(3d_present, S_IRUGO, hdmi_common_rda_3d_present, NULL);
685static DEVICE_ATTR(hdcp_present, S_IRUGO, hdmi_common_rda_hdcp_present, NULL);
686#endif
687#ifdef CONFIG_FB_MSM_HDMI_3D
688static DEVICE_ATTR(format_3d, S_IRUGO | S_IWUGO, hdmi_3d_rda_format_3d,
689 hdmi_3d_wta_format_3d);
690#endif
Ravishangar Kalyanam0bb7fe92011-10-27 16:06:30 -0700691static DEVICE_ATTR(hdmi_primary, S_IRUGO, hdmi_common_rda_hdmi_primary, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700692
693static struct attribute *external_common_fs_attrs[] = {
694 &dev_attr_video_mode.attr,
695 &dev_attr_video_mode_str.attr,
696 &dev_attr_connected.attr,
Ajay Singh Parmardb7007f2011-12-14 02:17:58 +0530697 &dev_attr_hdmi_mode.attr,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698#ifdef CONFIG_FB_MSM_HDMI_COMMON
699 &dev_attr_edid_modes.attr,
700 &dev_attr_hdcp.attr,
701 &dev_attr_hpd.attr,
702 &dev_attr_3d_present.attr,
703 &dev_attr_hdcp_present.attr,
704#endif
705#ifdef CONFIG_FB_MSM_HDMI_3D
706 &dev_attr_format_3d.attr,
707#endif
Manoj Raoa2c27672011-08-30 17:19:39 -0700708#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
709 &dev_attr_cec.attr,
710 &dev_attr_cec_logical_addr.attr,
711 &dev_attr_cec_rd_frame.attr,
712 &dev_attr_cec_wr_frame.attr,
713#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Ravishangar Kalyanam0bb7fe92011-10-27 16:06:30 -0700714 &dev_attr_hdmi_primary.attr,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700715 NULL,
716};
717static struct attribute_group external_common_fs_attr_group = {
718 .attrs = external_common_fs_attrs,
719};
720
721/* create external interface kobject and initialize */
722int external_common_state_create(struct platform_device *pdev)
723{
724 int rc;
725 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
726 if (!mfd) {
727 DEV_ERR("%s: mfd not found\n", __func__);
728 return -ENODEV;
729 }
730 if (!mfd->fbi) {
731 DEV_ERR("%s: mfd->fbi not found\n", __func__);
732 return -ENODEV;
733 }
734 if (!mfd->fbi->dev) {
735 DEV_ERR("%s: mfd->fbi->dev not found\n", __func__);
736 return -ENODEV;
737 }
738 rc = sysfs_create_group(&mfd->fbi->dev->kobj,
739 &external_common_fs_attr_group);
740 if (rc) {
741 DEV_ERR("%s: sysfs group creation failed, rc=%d\n", __func__,
742 rc);
743 return rc;
744 }
745 external_common_state->uevent_kobj = &mfd->fbi->dev->kobj;
746 DEV_ERR("%s: sysfs group %p\n", __func__,
747 external_common_state->uevent_kobj);
748
749 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ADD);
750 DEV_DBG("%s: kobject_uevent(KOBJ_ADD)\n", __func__);
751 return 0;
752}
753EXPORT_SYMBOL(external_common_state_create);
754
755void external_common_state_remove(void)
756{
757 if (external_common_state->uevent_kobj)
758 sysfs_remove_group(external_common_state->uevent_kobj,
759 &external_common_fs_attr_group);
760 external_common_state->uevent_kobj = NULL;
761}
762EXPORT_SYMBOL(external_common_state_remove);
763
764#ifdef CONFIG_FB_MSM_HDMI_COMMON
765/* The Logic ID for HDMI TX Core. Currently only support 1 HDMI TX Core. */
766struct hdmi_edid_video_mode_property_type {
767 uint32 video_code;
768 uint32 active_h;
769 uint32 active_v;
770 boolean interlaced;
771 uint32 total_h;
772 uint32 total_blank_h;
773 uint32 total_v;
774 uint32 total_blank_v;
775 /* Must divide by 1000 to get the frequency */
776 uint32 freq_h;
777 /* Must divide by 1000 to get the frequency */
778 uint32 freq_v;
779 /* Must divide by 1000 to get the frequency */
780 uint32 pixel_freq;
781 /* Must divide by 1000 to get the frequency */
782 uint32 refresh_rate;
783 boolean aspect_ratio_4_3;
784};
785
786/* LUT is sorted from lowest Active H to highest Active H - ease searching */
787static struct hdmi_edid_video_mode_property_type
788 hdmi_edid_disp_mode_lut[] = {
789
790 /* All 640 H Active */
791 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
792 31465, 59940, 25175, 59940, TRUE},
793 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
794 31500, 60000, 25200, 60000, TRUE},
795
796 /* All 720 H Active */
797 {HDMI_VFRMT_720x576p50_4_3, 720, 576, FALSE, 864, 144, 625, 49,
798 31250, 50000, 27000, 50000, TRUE},
799 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
800 31465, 59940, 27000, 59940, TRUE},
801 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
802 31500, 60000, 27030, 60000, TRUE},
803 {HDMI_VFRMT_720x576p100_4_3, 720, 576, FALSE, 864, 144, 625, 49,
804 62500, 100000, 54000, 100000, TRUE},
805 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
806 62937, 119880, 54000, 119880, TRUE},
807 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
808 63000, 120000, 54054, 120000, TRUE},
809 {HDMI_VFRMT_720x576p200_4_3, 720, 576, FALSE, 864, 144, 625, 49,
810 125000, 200000, 108000, 200000, TRUE},
811 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
812 125874, 239760, 108000, 239000, TRUE},
813 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
814 126000, 240000, 108108, 240000, TRUE},
815
816 /* All 1280 H Active */
817 {HDMI_VFRMT_1280x720p50_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
818 37500, 50000, 74250, 50000, FALSE},
819 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
820 44955, 59940, 74176, 59940, FALSE},
821 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
822 45000, 60000, 74250, 60000, FALSE},
823 {HDMI_VFRMT_1280x720p100_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
824 75000, 100000, 148500, 100000, FALSE},
825 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
826 89909, 119880, 148352, 119880, FALSE},
827 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
828 90000, 120000, 148500, 120000, FALSE},
829
830 /* All 1440 H Active */
831 {HDMI_VFRMT_1440x576i50_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
832 15625, 50000, 27000, 50000, TRUE},
833 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 312, 24,
834 15625, 50080, 27000, 50000, TRUE},
835 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 313, 25,
836 15625, 49920, 27000, 50000, TRUE},
837 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 314, 26,
838 15625, 49761, 27000, 50000, TRUE},
839 {HDMI_VFRMT_1440x576p50_4_3, 1440, 576, FALSE, 1728, 288, 625, 49,
840 31250, 50000, 54000, 50000, TRUE},
841 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
842 15734, 59940, 27000, 59940, TRUE},
843 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
844 15734, 60054, 27000, 59940, TRUE},
845 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
846 15734, 59826, 27000, 59940, TRUE},
847 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
848 31469, 59940, 54000, 59940, TRUE},
849 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
850 15750, 60000, 27027, 60000, TRUE},
851 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
852 15750, 60115, 27027, 60000, TRUE},
853 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
854 15750, 59886, 27027, 60000, TRUE},
855 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
856 31500, 60000, 54054, 60000, TRUE},
857 {HDMI_VFRMT_1440x576i100_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
858 31250, 100000, 54000, 100000, TRUE},
859 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
860 31469, 119880, 54000, 119880, TRUE},
861 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
862 31500, 120000, 54054, 120000, TRUE},
863 {HDMI_VFRMT_1440x576i200_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
864 62500, 200000, 108000, 200000, TRUE},
865 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
866 62937, 239760, 108000, 239000, TRUE},
867 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
868 63000, 240000, 108108, 240000, TRUE},
869
870 /* All 1920 H Active */
871 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
872 45, 67433, 59940, 148352, 59940, FALSE},
873 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
874 45, 67500, 60000, 148500, 60000, FALSE},
875 {HDMI_VFRMT_1920x1080p50_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
876 45, 56250, 50000, 148500, 50000, FALSE},
877 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
878 45, 26973, 23976, 74176, 24000, FALSE},
879 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
880 45, 27000, 24000, 74250, 24000, FALSE},
881 {HDMI_VFRMT_1920x1080p25_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
882 45, 28125, 25000, 74250, 25000, FALSE},
883 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
884 45, 33716, 29970, 74176, 30000, FALSE},
885 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
886 45, 33750, 30000, 74250, 30000, FALSE},
887 {HDMI_VFRMT_1920x1080i50_16_9, 1920, 1080, TRUE, 2304, 384, 1250,
888 85, 31250, 50000, 72000, 50000, FALSE},
889 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
890 22, 33716, 59940, 74176, 59940, FALSE},
891 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
892 22, 33750, 60000, 74250, 60000, FALSE},
893 {HDMI_VFRMT_1920x1080i100_16_9, 1920, 1080, TRUE, 2640, 720, 1125,
894 22, 56250, 100000, 148500, 100000, FALSE},
895 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
896 22, 67432, 119880, 148352, 119980, FALSE},
897 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
898 22, 67500, 120000, 148500, 120000, FALSE},
899
900 /* All 2880 H Active */
901 {HDMI_VFRMT_2880x576i50_4_3, 2880, 576, TRUE, 3456, 576, 625, 24,
902 15625, 50000, 54000, 50000, TRUE},
903 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 312, 24,
904 15625, 50080, 54000, 50000, TRUE},
905 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 313, 25,
906 15625, 49920, 54000, 50000, TRUE},
907 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 314, 26,
908 15625, 49761, 54000, 50000, TRUE},
909 {HDMI_VFRMT_2880x576p50_4_3, 2880, 576, FALSE, 3456, 576, 625, 49,
910 31250, 50000, 108000, 50000, TRUE},
911 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
912 15734, 59940, 54000, 59940, TRUE},
913 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 262, 22,
914 15734, 60054, 54000, 59940, TRUE},
915 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 263, 23,
916 15734, 59940, 54000, 59940, TRUE},
917 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
918 31469, 59940, 108000, 59940, TRUE},
919 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
920 15750, 60000, 54054, 60000, TRUE},
921 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 22,
922 15750, 60115, 54054, 60000, TRUE},
923 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 23,
924 15750, 59886, 54054, 60000, TRUE},
925 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
926 31500, 60000, 108108, 60000, TRUE},
927};
928
929static const uint8 *hdmi_edid_find_block(const uint8 *in_buf, uint8 type,
930 uint8 *len)
931{
932 /* the start of data block collection, start of Video Data Block */
933 uint32 offset = 4;
934
935 *len = 0;
Ajay Singh Parmar3b9595f2012-02-08 16:36:03 +0530936
937 /*edid buffer 1, byte 2 being 4 means no non-DTD/Data block collection
938 present.
939 edid buffer 1, byte 2 being 0 menas no non-DTD/DATA block collection
940 present and no DTD data present.*/
941 if ((in_buf[2] == 0) || (in_buf[2] == 4)) {
942 DEV_WARN("EDID: no DTD or non-DTD data present\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700943 return NULL;
944 }
945 while (offset < 0x80) {
946 uint8 block_len = in_buf[offset] & 0x1F;
947 if ((in_buf[offset] >> 5) == type) {
948 *len = block_len;
949 DEV_DBG("EDID: block=%d found @ %d with length=%d\n",
950 type, offset, block_len);
951 return in_buf+offset;
952 }
953 offset += 1 + block_len;
954 }
Manoj Rao668d6d52011-08-16 19:12:31 -0700955 DEV_WARN("EDID: type=%d block not found in EDID block\n", type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700956 return NULL;
957}
958
959static void hdmi_edid_extract_vendor_id(const uint8 *in_buf,
960 char *vendor_id)
961{
962 uint32 id_codes = ((uint32)in_buf[8] << 8) + in_buf[9];
963
964 vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
965 vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
966 vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
967 vendor_id[3] = 0;
968}
969
970static uint32 hdmi_edid_extract_ieee_reg_id(const uint8 *in_buf)
971{
972 uint8 len;
973 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
974
975 if (vsd == NULL)
976 return 0;
977
978 DEV_DBG("EDID: VSD PhyAddr=%04x, MaxTMDS=%dMHz\n",
979 ((uint32)vsd[6] << 8) + (uint32)vsd[5], (uint32)vsd[7] * 5);
980 return ((uint32)vsd[3] << 16) + ((uint32)vsd[2] << 8) + (uint32)vsd[1];
981}
982
983static void hdmi_edid_extract_3d_present(const uint8 *in_buf)
984{
985 uint8 len, offset;
986 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
987
988 external_common_state->present_3d = 0;
989 if (vsd == NULL || len < 9) {
990 DEV_DBG("EDID[3D]: block-id 3 not found or not long enough\n");
991 return;
992 }
993
994 offset = !(vsd[8] & BIT(7)) ? 9 : 13;
995 DEV_DBG("EDID: 3D present @ %d = %02x\n", offset, vsd[offset]);
996 if (vsd[offset] >> 7) { /* 3D format indication present */
997 DEV_INFO("EDID: 3D present, 3D-len=%d\n", vsd[offset+1] & 0x1F);
998 external_common_state->present_3d = 1;
999 }
1000}
1001
1002
1003static void hdmi_edid_extract_latency_fields(const uint8 *in_buf)
1004{
1005 uint8 len;
1006 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
1007
1008 if (vsd == NULL || len < 12 || !(vsd[8] & BIT(7))) {
1009 external_common_state->video_latency = (uint16)-1;
1010 external_common_state->audio_latency = (uint16)-1;
1011 DEV_DBG("EDID: No audio/video latency present\n");
1012 } else {
1013 external_common_state->video_latency = vsd[9];
1014 external_common_state->audio_latency = vsd[10];
1015 DEV_DBG("EDID: video-latency=%04x, audio-latency=%04x\n",
1016 external_common_state->video_latency,
1017 external_common_state->audio_latency);
1018 }
1019}
1020
1021static void hdmi_edid_extract_speaker_allocation_data(const uint8 *in_buf)
1022{
1023 uint8 len;
1024 const uint8 *sad = hdmi_edid_find_block(in_buf, 4, &len);
1025
1026 if (sad == NULL)
1027 return;
1028
1029 external_common_state->speaker_allocation_block = sad[1];
Kiran Kandi94f25dc2012-01-31 00:18:33 -08001030 DEV_DBG("EDID: speaker allocation data SP byte = %08x %s%s%s%s%s%s%s\n",
1031 sad[1],
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 (sad[1] & BIT(0)) ? "FL/FR," : "",
1033 (sad[1] & BIT(1)) ? "LFE," : "",
1034 (sad[1] & BIT(2)) ? "FC," : "",
1035 (sad[1] & BIT(3)) ? "RL/RR," : "",
1036 (sad[1] & BIT(4)) ? "RC," : "",
1037 (sad[1] & BIT(5)) ? "FLC/FRC," : "",
Kiran Kandi94f25dc2012-01-31 00:18:33 -08001038 (sad[1] & BIT(6)) ? "RLC/RRC," : "");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039}
1040
1041static void hdmi_edid_extract_audio_data_blocks(const uint8 *in_buf)
1042{
1043 uint8 len;
1044 const uint8 *sad = hdmi_edid_find_block(in_buf, 1, &len);
1045 uint32 *adb = external_common_state->audio_data_blocks;
1046
1047 if (sad == NULL)
1048 return;
1049
1050 external_common_state->audio_data_block_cnt = 0;
1051 while (len >= 3 && external_common_state->audio_data_block_cnt < 16) {
1052 DEV_DBG("EDID: Audio Data Block=<ch=%d, format=%d "
1053 "sampling=0x%02x bit-depth=0x%02x>\n",
1054 (sad[1] & 0x7)+1, sad[1] >> 3, sad[2], sad[3]);
1055 *adb++ = (uint32)sad[1] + ((uint32)sad[2] << 8)
1056 + ((uint32)sad[2] << 16);
1057 ++external_common_state->audio_data_block_cnt;
1058 len -= 3;
1059 sad += 3;
1060 }
1061}
1062
1063
1064static void hdmi_edid_detail_desc(const uint8 *data_buf, uint32 *disp_mode)
1065{
1066 boolean aspect_ratio_4_3 = FALSE;
1067 boolean interlaced = FALSE;
1068 uint32 active_h = 0;
1069 uint32 active_v = 0;
1070 uint32 blank_h = 0;
1071 uint32 blank_v = 0;
1072 uint32 ndx = 0;
1073 uint32 max_num_of_elements = 0;
1074 uint32 img_size_h = 0;
1075 uint32 img_size_v = 0;
1076
1077 /* See VESA Spec */
1078 /* EDID_TIMING_DESC_UPPER_H_NIBBLE[0x4]: Relative Offset to the EDID
1079 * detailed timing descriptors - Upper 4 bit for each H active/blank
1080 * field */
1081 /* EDID_TIMING_DESC_H_ACTIVE[0x2]: Relative Offset to the EDID detailed
1082 * timing descriptors - H active */
1083 active_h = ((((uint32)data_buf[0x4] >> 0x4) & 0xF) << 8)
1084 | data_buf[0x2];
1085
1086 /* EDID_TIMING_DESC_H_BLANK[0x3]: Relative Offset to the EDID detailed
1087 * timing descriptors - H blank */
1088 blank_h = (((uint32)data_buf[0x4] & 0xF) << 8)
1089 | data_buf[0x3];
1090
1091 /* EDID_TIMING_DESC_UPPER_V_NIBBLE[0x7]: Relative Offset to the EDID
1092 * detailed timing descriptors - Upper 4 bit for each V active/blank
1093 * field */
1094 /* EDID_TIMING_DESC_V_ACTIVE[0x5]: Relative Offset to the EDID detailed
1095 * timing descriptors - V active */
1096 active_v = ((((uint32)data_buf[0x7] >> 0x4) & 0xF) << 8)
1097 | data_buf[0x5];
1098
1099 /* EDID_TIMING_DESC_V_BLANK[0x6]: Relative Offset to the EDID detailed
1100 * timing descriptors - V blank */
1101 blank_v = (((uint32)data_buf[0x7] & 0xF) << 8)
1102 | data_buf[0x6];
1103
1104 /* EDID_TIMING_DESC_IMAGE_SIZE_UPPER_NIBBLE[0xE]: Relative Offset to the
1105 * EDID detailed timing descriptors - Image Size upper nibble
1106 * V and H */
1107 /* EDID_TIMING_DESC_H_IMAGE_SIZE[0xC]: Relative Offset to the EDID
1108 * detailed timing descriptors - H image size */
1109 /* EDID_TIMING_DESC_V_IMAGE_SIZE[0xD]: Relative Offset to the EDID
1110 * detailed timing descriptors - V image size */
1111 img_size_h = ((((uint32)data_buf[0xE] >> 0x4) & 0xF) << 8)
1112 | data_buf[0xC];
1113 img_size_v = (((uint32)data_buf[0xE] & 0xF) << 8)
1114 | data_buf[0xD];
1115
Abhishek Kharbanda402adc62011-12-15 12:21:29 -08001116 /*
1117 * aspect ratio as 4:3 if within specificed range , rathaer than being
1118 * absolute value
1119 */
1120 aspect_ratio_4_3 = (abs(img_size_h * 3 - img_size_v * 4) < 5) ? 1 : 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001121
1122 max_num_of_elements = sizeof(hdmi_edid_disp_mode_lut)
1123 / sizeof(*hdmi_edid_disp_mode_lut);
1124
Manoj Rao668d6d52011-08-16 19:12:31 -07001125 /* EDID_TIMING_DESC_INTERLACE[0x11:7]: Relative Offset to the EDID
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001126 * detailed timing descriptors - Interlace flag */
Manoj Rao668d6d52011-08-16 19:12:31 -07001127 DEV_DBG("Interlaced mode byte data_buf[0x11]=[%x]\n", data_buf[0x11]);
1128 /*
1129 * CEA 861-D: interlaced bit is bit[7] of byte[0x11]
1130 */
1131 interlaced = (data_buf[0x11] & 0x80) >> 7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132
1133 DEV_DBG("%s: A[%ux%u] B[%ux%u] V[%ux%u] %s\n", __func__,
1134 active_h, active_v, blank_h, blank_v, img_size_h, img_size_v,
1135 interlaced ? "i" : "p");
1136
1137 *disp_mode = HDMI_VFRMT_FORCE_32BIT;
1138 while (ndx < max_num_of_elements) {
1139 const struct hdmi_edid_video_mode_property_type *edid =
1140 hdmi_edid_disp_mode_lut+ndx;
1141
1142 if ((interlaced == edid->interlaced) &&
1143 (active_h == edid->active_h) &&
1144 (blank_h == edid->total_blank_h) &&
1145 (blank_v == edid->total_blank_v) &&
1146 ((active_v == edid->active_v) ||
1147 (active_v == (edid->active_v + 1)))
1148 ) {
1149 if (edid->aspect_ratio_4_3 && !aspect_ratio_4_3)
1150 /* Aspect ratio 16:9 */
1151 *disp_mode = edid->video_code + 1;
1152 else
1153 /* Aspect ratio 4:3 */
1154 *disp_mode = edid->video_code;
1155
1156 DEV_DBG("%s: mode found:%d\n", __func__, *disp_mode);
1157 break;
1158 }
1159 ++ndx;
1160 }
1161 if (ndx == max_num_of_elements)
1162 DEV_INFO("%s: *no mode* found\n", __func__);
1163}
1164
1165static void add_supported_video_format(
1166 struct hdmi_disp_mode_list_type *disp_mode_list,
1167 uint32 video_format)
1168{
1169 const struct hdmi_disp_mode_timing_type *timing =
1170 hdmi_common_get_supported_mode(video_format);
1171 boolean supported = timing != NULL;
1172
1173 if (video_format >= HDMI_VFRMT_MAX)
1174 return;
1175
1176 DEV_DBG("EDID: format: %d [%s], %s\n",
1177 video_format, video_format_2string(video_format),
1178 supported ? "Supported" : "Not-Supported");
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001179 if (supported) {
1180 if (mhl_is_connected()) {
1181 const struct hdmi_disp_mode_timing_type *mhl_timing =
1182 hdmi_mhl_get_supported_mode(video_format);
1183 boolean mhl_supported = mhl_timing != NULL;
1184 DEV_DBG("EDID: format: %d [%s], %s by MHL\n",
1185 video_format, video_format_2string(video_format),
1186 mhl_supported ? "Supported" : "Not-Supported");
1187 if (mhl_supported)
1188 disp_mode_list->disp_mode_list[
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189 disp_mode_list->num_of_elements++] = video_format;
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001190 } else
1191 disp_mode_list->disp_mode_list[
1192 disp_mode_list->num_of_elements++] = video_format;
1193 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001194}
1195
1196static void hdmi_edid_get_display_mode(const uint8 *data_buf,
1197 struct hdmi_disp_mode_list_type *disp_mode_list,
1198 uint32 num_og_cea_blocks)
1199{
1200 uint8 i = 0;
1201 uint32 video_format = HDMI_VFRMT_640x480p60_4_3;
1202 boolean has480p = FALSE;
1203 uint8 len;
Manoj Rao668d6d52011-08-16 19:12:31 -07001204 const uint8 *edid_blk0 = &data_buf[0x0];
1205 const uint8 *edid_blk1 = &data_buf[0x80];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 const uint8 *svd = num_og_cea_blocks ?
1207 hdmi_edid_find_block(data_buf+0x80, 2, &len) : NULL;
1208
1209 disp_mode_list->num_of_elements = 0;
1210 if (svd != NULL) {
1211 ++svd;
1212 for (i = 0; i < len; ++i, ++svd) {
1213 /* Subtract 1 because it is zero based in the driver,
1214 * while the Video identification code is 1 based in the
1215 * CEA_861D spec */
1216 video_format = (*svd & 0x7F) - 1;
1217 add_supported_video_format(disp_mode_list,
1218 video_format);
1219 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1220 has480p = TRUE;
1221 }
1222 } else if (!num_og_cea_blocks) {
1223 /* Detailed timing descriptors */
1224 uint32 desc_offset = 0;
1225 /* Maximum 4 timing descriptor in block 0 - No CEA
1226 * extension in this case */
1227 /* EDID_FIRST_TIMING_DESC[0x36] - 1st detailed timing
1228 * descriptor */
1229 /* EDID_DETAIL_TIMING_DESC_BLCK_SZ[0x12] - Each detailed timing
1230 * descriptor has block size of 18 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001231 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1232 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001234 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1235 __func__, __LINE__,
1236 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001237 add_supported_video_format(disp_mode_list,
1238 video_format);
1239 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1240 has480p = TRUE;
1241 desc_offset += 0x12;
1242 ++i;
1243 }
1244 } else if (1 == num_og_cea_blocks) {
1245 uint32 desc_offset = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -07001246
1247 /*
1248 * Read from both block 0 and block 1
1249 * Read EDID block[0] as above
1250 */
1251 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1252 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
1253 &video_format);
1254 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1255 __func__, __LINE__,
1256 video_format_2string(video_format));
1257 add_supported_video_format(disp_mode_list,
1258 video_format);
1259 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1260 has480p = TRUE;
1261 desc_offset += 0x12;
1262 ++i;
1263 }
1264
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265 /* Parse block 1 - CEA extension byte offset of first
1266 * detailed timing generation - offset is relevant to
1267 * the offset of block 1 */
1268
1269 /* EDID_CEA_EXTENSION_FIRST_DESC[0x82]: Offset to CEA
1270 * extension first timing desc - indicate the offset of
1271 * the first detailed timing descriptor */
1272 /* EDID_BLOCK_SIZE = 0x80 Each page size in the EDID ROM */
Manoj Rao668d6d52011-08-16 19:12:31 -07001273 desc_offset = edid_blk1[0x02];
1274 while (0 != edid_blk1[desc_offset]) {
1275 hdmi_edid_detail_desc(edid_blk1+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001276 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001277 DEV_DBG("[%s:%d] Block-1 Adding vid fmt = [%s]\n",
1278 __func__, __LINE__,
1279 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001280 add_supported_video_format(disp_mode_list,
1281 video_format);
1282 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1283 has480p = TRUE;
1284 desc_offset += 0x12;
1285 ++i;
1286 }
1287 }
1288
1289 if (!has480p)
1290 /* Need to add default 640 by 480 timings, in case not described
1291 * in the EDID structure.
1292 * All DTV sink devices should support this mode */
1293 add_supported_video_format(disp_mode_list,
1294 HDMI_VFRMT_640x480p60_4_3);
1295}
1296
1297static int hdmi_common_read_edid_block(int block, uint8 *edid_buf)
1298{
Manoj Rao668d6d52011-08-16 19:12:31 -07001299 uint32 ndx, check_sum, print_len;
1300#ifdef DEBUG
1301 const u8 *b = edid_buf;
1302#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001303 int status = external_common_state->read_edid_block(block, edid_buf);
Manoj Rao668d6d52011-08-16 19:12:31 -07001304 if (status)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 goto error;
1306
1307 /* Calculate checksum */
1308 check_sum = 0;
1309 for (ndx = 0; ndx < 0x80; ++ndx)
1310 check_sum += edid_buf[ndx];
1311
1312 if (check_sum & 0xFF) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001313 DEV_ERR("%s: failed CHECKSUM (read:%x, expected:%x)\n",
1314 __func__, (uint8)edid_buf[0x7F], (uint8)check_sum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315#ifdef DEBUG
1316 for (ndx = 0; ndx < 0x100; ndx += 16)
1317 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1318 "%02x %02x %02x %02x %02x %02x %02x %02x "
1319 "%02x %02x %02x %02x\n", ndx, ndx+15,
1320 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1321 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1322 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1323 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1324#endif
1325 status = -EPROTO;
1326 goto error;
1327 }
Manoj Rao668d6d52011-08-16 19:12:31 -07001328 print_len = 0x80;
1329 for (ndx = 0; ndx < print_len; ndx += 16)
1330 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1331 "%02x %02x %02x %02x %02x %02x %02x %02x "
1332 "%02x %02x %02x %02x\n", ndx, ndx+15,
1333 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1334 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1335 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1336 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1337
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001338
1339error:
1340 return status;
1341}
1342
1343static boolean check_edid_header(const uint8 *edid_buf)
1344{
1345 return (edid_buf[0] == 0x00) && (edid_buf[1] == 0xff)
1346 && (edid_buf[2] == 0xff) && (edid_buf[3] == 0xff)
1347 && (edid_buf[4] == 0xff) && (edid_buf[5] == 0xff)
1348 && (edid_buf[6] == 0xff) && (edid_buf[7] == 0x00);
1349}
1350
1351int hdmi_common_read_edid(void)
1352{
1353 int status = 0;
1354 uint32 cea_extension_ver = 0;
1355 uint32 num_og_cea_blocks = 0;
1356 uint32 ieee_reg_id = 0;
1357 uint32 i = 1;
1358 char vendor_id[5];
1359 /* EDID_BLOCK_SIZE[0x80] Each page size in the EDID ROM */
1360 uint8 edid_buf[0x80 * 4];
1361
1362 external_common_state->present_3d = 0;
1363 memset(&external_common_state->disp_mode_list, 0,
1364 sizeof(external_common_state->disp_mode_list));
1365 memset(edid_buf, 0, sizeof(edid_buf));
1366
1367 status = hdmi_common_read_edid_block(0, edid_buf);
1368 if (status || !check_edid_header(edid_buf)) {
1369 if (!status)
1370 status = -EPROTO;
1371 DEV_ERR("%s: edid read block(0) failed: %d "
1372 "[%02x%02x%02x%02x%02x%02x%02x%02x]\n", __func__,
1373 status,
1374 edid_buf[0], edid_buf[1], edid_buf[2], edid_buf[3],
1375 edid_buf[4], edid_buf[5], edid_buf[6], edid_buf[7]);
1376 goto error;
1377 }
1378 hdmi_edid_extract_vendor_id(edid_buf, vendor_id);
1379
1380 /* EDID_CEA_EXTENSION_FLAG[0x7E] - CEC extension byte */
1381 num_og_cea_blocks = edid_buf[0x7E];
1382
1383 DEV_DBG("[JSR] (%s): No. of CEA blocks is [%u]\n", __func__,
1384 num_og_cea_blocks);
1385 /* Find out any CEA extension blocks following block 0 */
1386 switch (num_og_cea_blocks) {
1387 case 0: /* No CEA extension */
1388 external_common_state->hdmi_sink = false;
1389 DEV_DBG("HDMI DVI mode: %s\n",
1390 external_common_state->hdmi_sink ? "no" : "yes");
1391 break;
1392 case 1: /* Read block 1 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001393 status = hdmi_common_read_edid_block(1, &edid_buf[0x80]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001394 if (status) {
1395 DEV_ERR("%s: ddc read block(1) failed: %d\n", __func__,
1396 status);
1397 goto error;
1398 }
1399 if (edid_buf[0x80] != 2)
1400 num_og_cea_blocks = 0;
1401 if (num_og_cea_blocks) {
1402 ieee_reg_id =
1403 hdmi_edid_extract_ieee_reg_id(edid_buf+0x80);
1404 if (ieee_reg_id == 0x0c03)
1405 external_common_state->hdmi_sink = TRUE ;
1406 else
1407 external_common_state->hdmi_sink = FALSE ;
1408 hdmi_edid_extract_latency_fields(edid_buf+0x80);
1409 hdmi_edid_extract_speaker_allocation_data(
1410 edid_buf+0x80);
1411 hdmi_edid_extract_audio_data_blocks(edid_buf+0x80);
1412 hdmi_edid_extract_3d_present(edid_buf+0x80);
1413 }
1414 break;
1415 case 2:
1416 case 3:
1417 case 4:
1418 for (i = 1; i <= num_og_cea_blocks; i++) {
1419 if (!(i % 2)) {
1420 status = hdmi_common_read_edid_block(i,
1421 edid_buf+0x00);
1422 if (status) {
1423 DEV_ERR("%s: ddc read block(%d)"
1424 "failed: %d\n", __func__, i,
1425 status);
1426 goto error;
1427 }
1428 } else {
1429 status = hdmi_common_read_edid_block(i,
1430 edid_buf+0x80);
1431 if (status) {
1432 DEV_ERR("%s: ddc read block(%d)"
1433 "failed:%d\n", __func__, i,
1434 status);
1435 goto error;
1436 }
1437 }
1438 }
1439 break;
1440 default:
1441 DEV_ERR("%s: ddc read failed, not supported multi-blocks: %d\n",
1442 __func__, num_og_cea_blocks);
1443 status = -EPROTO;
1444 goto error;
1445 }
1446
1447 if (num_og_cea_blocks) {
1448 /* EDID_CEA_EXTENSION_VERSION[0x81]: Offset to CEA extension
1449 * version number - v1,v2,v3 (v1 is seldom, v2 is obsolete,
1450 * v3 most common) */
1451 cea_extension_ver = edid_buf[0x81];
1452 }
1453
1454 /* EDID_VERSION[0x12] - EDID Version */
1455 /* EDID_REVISION[0x13] - EDID Revision */
1456 DEV_INFO("EDID (V=%d.%d, #CEABlocks=%d[V%d], ID=%s, IEEE=%04x, "
1457 "EDID-Ext=0x%02x)\n", edid_buf[0x12], edid_buf[0x13],
1458 num_og_cea_blocks, cea_extension_ver, vendor_id, ieee_reg_id,
1459 edid_buf[0x80]);
1460
1461 hdmi_edid_get_display_mode(edid_buf,
1462 &external_common_state->disp_mode_list, num_og_cea_blocks);
1463
1464 return 0;
1465
1466error:
1467 external_common_state->disp_mode_list.num_of_elements = 1;
1468 external_common_state->disp_mode_list.disp_mode_list[0] =
1469 external_common_state->video_resolution;
1470 return status;
1471}
1472EXPORT_SYMBOL(hdmi_common_read_edid);
1473
1474bool hdmi_common_get_video_format_from_drv_data(struct msm_fb_data_type *mfd)
1475{
1476 uint32 format;
1477 struct fb_var_screeninfo *var = &mfd->fbi->var;
1478 bool changed = TRUE;
1479
1480 if (var->reserved[3]) {
1481 format = var->reserved[3]-1;
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001482 DEV_DBG("reserved format is %d\n", format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001483 } else {
1484 DEV_DBG("detecting resolution from %dx%d use var->reserved[3]"
1485 " to specify mode", mfd->var_xres, mfd->var_yres);
1486 switch (mfd->var_xres) {
1487 default:
1488 case 640:
1489 format = HDMI_VFRMT_640x480p60_4_3;
1490 break;
1491 case 720:
1492 format = (mfd->var_yres == 480)
1493 ? HDMI_VFRMT_720x480p60_16_9
1494 : HDMI_VFRMT_720x576p50_16_9;
1495 break;
1496 case 1280:
1497 format = HDMI_VFRMT_1280x720p60_16_9;
1498 break;
1499 case 1440:
1500 format = (mfd->var_yres == 480)
1501 ? HDMI_VFRMT_1440x480i60_16_9
1502 : HDMI_VFRMT_1440x576i50_16_9;
1503 break;
1504 case 1920:
1505 format = HDMI_VFRMT_1920x1080p60_16_9;
1506 break;
1507 }
1508 }
1509
1510 changed = external_common_state->video_resolution != format;
1511 if (external_common_state->video_resolution != format)
1512 DEV_DBG("switching %s => %s", video_format_2string(
1513 external_common_state->video_resolution),
1514 video_format_2string(format));
1515 else
1516 DEV_DBG("resolution %s", video_format_2string(
1517 external_common_state->video_resolution));
1518 external_common_state->video_resolution = format;
1519 return changed;
1520}
1521EXPORT_SYMBOL(hdmi_common_get_video_format_from_drv_data);
1522
1523const struct hdmi_disp_mode_timing_type *hdmi_common_get_mode(uint32 mode)
1524{
1525 if (mode >= HDMI_VFRMT_MAX)
1526 return NULL;
1527
1528 return &hdmi_common_supported_video_mode_lut[mode];
1529}
1530EXPORT_SYMBOL(hdmi_common_get_mode);
1531
1532const struct hdmi_disp_mode_timing_type *hdmi_common_get_supported_mode(
1533 uint32 mode)
1534{
1535 const struct hdmi_disp_mode_timing_type *ret
1536 = hdmi_common_get_mode(mode);
1537
1538 if (ret == NULL || !ret->supported)
1539 return NULL;
1540 return ret;
1541}
1542EXPORT_SYMBOL(hdmi_common_get_supported_mode);
1543
Eugene Yasmand0de5f92011-12-20 13:57:28 +02001544const struct hdmi_disp_mode_timing_type *hdmi_mhl_get_mode(uint32 mode)
1545{
1546 if (mode >= HDMI_VFRMT_MAX)
1547 return NULL;
1548
1549 return &hdmi_mhl_supported_video_mode_lut[mode];
1550}
1551EXPORT_SYMBOL(hdmi_mhl_get_mode);
1552
1553const struct hdmi_disp_mode_timing_type *hdmi_mhl_get_supported_mode(
1554 uint32 mode)
1555{
1556 const struct hdmi_disp_mode_timing_type *ret
1557 = hdmi_mhl_get_mode(mode);
1558
1559 if (ret == NULL || !ret->supported)
1560 return NULL;
1561 return ret;
1562}
1563EXPORT_SYMBOL(hdmi_mhl_get_supported_mode);
1564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001565void hdmi_common_init_panel_info(struct msm_panel_info *pinfo)
1566{
1567 const struct hdmi_disp_mode_timing_type *timing =
1568 hdmi_common_get_supported_mode(
1569 external_common_state->video_resolution);
1570
1571 if (timing == NULL)
1572 return;
1573
1574 pinfo->xres = timing->active_h;
1575 pinfo->yres = timing->active_v;
1576 pinfo->clk_rate = timing->pixel_freq*1000;
1577
1578 pinfo->lcdc.h_back_porch = timing->back_porch_h;
1579 pinfo->lcdc.h_front_porch = timing->front_porch_h;
1580 pinfo->lcdc.h_pulse_width = timing->pulse_width_h;
1581 pinfo->lcdc.v_back_porch = timing->back_porch_v;
1582 pinfo->lcdc.v_front_porch = timing->front_porch_v;
1583 pinfo->lcdc.v_pulse_width = timing->pulse_width_v;
1584
1585 pinfo->type = DTV_PANEL;
1586 pinfo->pdest = DISPLAY_2;
1587 pinfo->wait_cycle = 0;
1588 pinfo->bpp = 24;
Ravishangar Kalyanam0bb7fe92011-10-27 16:06:30 -07001589 if (hdmi_prim_display)
1590 pinfo->fb_num = 2;
1591 else
1592 pinfo->fb_num = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001593
1594 /* blk */
1595 pinfo->lcdc.border_clr = 0;
1596 /* blue */
1597 pinfo->lcdc.underflow_clr = 0xff;
1598 pinfo->lcdc.hsync_skew = 0;
1599}
1600EXPORT_SYMBOL(hdmi_common_init_panel_info);
1601#endif