blob: 1d87de6535886adcb88cf27684ededd0c8833861 [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
Manoj Raoa2c27672011-08-30 17:19:39 -070021/* #define CEC_COMPLIANCE_TESTING */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include "msm_fb.h"
Manoj Raoa2c27672011-08-30 17:19:39 -070023#include "hdmi_msm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include "external_common.h"
25
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
228static ssize_t hdmi_common_rda_edid_modes(struct device *dev,
229 struct device_attribute *attr, char *buf)
230{
231 ssize_t ret = 0;
232 int i;
233
234 buf[0] = 0;
235 if (external_common_state->disp_mode_list.num_of_elements) {
236 uint32 *video_mode = external_common_state->disp_mode_list
237 .disp_mode_list;
238 for (i = 0; i < external_common_state->disp_mode_list
239 .num_of_elements; ++i) {
240 if (ret > 0)
241 ret += snprintf(buf+ret, PAGE_SIZE-ret, ",%d",
242 *video_mode++ + 1);
243 else
244 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
245 *video_mode++ + 1);
246 }
247 } else
248 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%d",
249 external_common_state->video_resolution+1);
250
251 DEV_DBG("%s: '%s'\n", __func__, buf);
252 ret += snprintf(buf+ret, PAGE_SIZE-ret, "\n");
253 return ret;
254}
255
256static ssize_t hdmi_common_rda_hdcp(struct device *dev,
257 struct device_attribute *attr, char *buf)
258{
259 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
260 external_common_state->hdcp_active);
261 DEV_DBG("%s: '%d'\n", __func__,
262 external_common_state->hdcp_active);
263 return ret;
264}
265
266static ssize_t hdmi_common_rda_hpd(struct device *dev,
267 struct device_attribute *attr, char *buf)
268{
269 ssize_t ret;
270 if (external_common_state->hpd_feature) {
271 ret = snprintf(buf, PAGE_SIZE, "%d\n",
272 external_common_state->hpd_feature_on);
273 DEV_DBG("%s: '%d'\n", __func__,
274 external_common_state->hpd_feature_on);
275 } else {
276 ret = snprintf(buf, PAGE_SIZE, "-1\n");
277 DEV_DBG("%s: 'not supported'\n", __func__);
278 }
279 return ret;
280}
281
282static ssize_t hdmi_common_wta_hpd(struct device *dev,
283 struct device_attribute *attr, const char *buf, size_t count)
284{
285 ssize_t ret = strnlen(buf, PAGE_SIZE);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700286#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
287 int hpd = 1;
288#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289 int hpd = atoi(buf);
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -0700290#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 if (external_common_state->hpd_feature) {
292 if (hpd == 0 && external_common_state->hpd_feature_on) {
293 external_common_state->hpd_feature(0);
294 external_common_state->hpd_feature_on = 0;
295 DEV_DBG("%s: '%d'\n", __func__,
296 external_common_state->hpd_feature_on);
297 } else if (hpd == 1 && !external_common_state->hpd_feature_on) {
298 external_common_state->hpd_feature(1);
299 external_common_state->hpd_feature_on = 1;
300 DEV_DBG("%s: '%d'\n", __func__,
301 external_common_state->hpd_feature_on);
302 } else {
303 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
304 external_common_state->hpd_feature_on);
305 }
306 } else {
307 DEV_DBG("%s: 'not supported'\n", __func__);
308 }
309
310 return ret;
311}
312
Manoj Raoa2c27672011-08-30 17:19:39 -0700313#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
314/*
315 * This interface for CEC feature is defined to suit
316 * the current requirements. However, the actual functionality is
317 * added to accommodate different interfaces
318 */
319static ssize_t hdmi_msm_rda_cec(struct device *dev,
320 struct device_attribute *attr, char *buf)
321{
322 /* 0x028C CEC_CTRL */
323 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
324 (HDMI_INP(0x028C) & BIT(0)));
325 return ret;
326}
327
328static ssize_t hdmi_msm_wta_cec(struct device *dev,
329 struct device_attribute *attr, const char *buf, size_t count)
330{
331 ssize_t ret = strnlen(buf, PAGE_SIZE);
332 int cec = atoi(buf);
333
334 if (cec != 0) {
335 mutex_lock(&hdmi_msm_state_mutex);
336 hdmi_msm_state->cec_enabled = true;
337 hdmi_msm_state->cec_logical_addr = 4;
338 mutex_unlock(&hdmi_msm_state_mutex);
339 hdmi_msm_cec_init();
340 hdmi_msm_cec_write_logical_addr(
341 hdmi_msm_state->cec_logical_addr);
342 DEV_DBG("CEC enabled\n");
343 } else {
344 mutex_lock(&hdmi_msm_state_mutex);
345 hdmi_msm_state->cec_enabled = false;
346 hdmi_msm_state->cec_logical_addr = 15;
347 mutex_unlock(&hdmi_msm_state_mutex);
348 hdmi_msm_cec_write_logical_addr(
349 hdmi_msm_state->cec_logical_addr);
350 /* 0x028C CEC_CTRL */
351 HDMI_OUTP(0x028C, 0);
352 DEV_DBG("CEC disabled\n");
353 }
354 return ret;
355}
356
357static ssize_t hdmi_msm_rda_cec_logical_addr(struct device *dev,
358 struct device_attribute *attr, char *buf)
359{
360 ssize_t ret;
361
362 mutex_lock(&hdmi_msm_state_mutex);
363 ret = snprintf(buf, PAGE_SIZE, "%d\n",
364 hdmi_msm_state->cec_logical_addr);
365 mutex_unlock(&hdmi_msm_state_mutex);
366 return ret;
367}
368
369static ssize_t hdmi_msm_wta_cec_logical_addr(struct device *dev,
370 struct device_attribute *attr, const char *buf, size_t count)
371{
372
373#ifdef CEC_COMPLIANCE_TESTING
374 /*
375 * Only for testing
376 */
377 hdmi_msm_cec_one_touch_play();
378 return 0;
379#else
380 ssize_t ret = strnlen(buf, PAGE_SIZE);
381 int logical_addr = atoi(buf);
382
383 if (logical_addr < 0 || logical_addr > 15)
384 return -EINVAL;
385
386 mutex_lock(&hdmi_msm_state_mutex);
387 hdmi_msm_state->cec_logical_addr = logical_addr;
388 mutex_unlock(&hdmi_msm_state_mutex);
389
390 hdmi_msm_cec_write_logical_addr(logical_addr);
391
392 return ret;
393#endif
394}
395
396static ssize_t hdmi_msm_rda_cec_frame(struct device *dev,
397 struct device_attribute *attr, char *buf)
398{
399 mutex_lock(&hdmi_msm_state_mutex);
400 if (hdmi_msm_state->cec_queue_rd == hdmi_msm_state->cec_queue_wr
401 && !hdmi_msm_state->cec_queue_full) {
402 mutex_unlock(&hdmi_msm_state_mutex);
403 DEV_ERR("CEC message queue is empty\n");
404 return -EBUSY;
405 }
406 memcpy(buf, hdmi_msm_state->cec_queue_rd++,
407 sizeof(struct hdmi_msm_cec_msg));
408 hdmi_msm_state->cec_queue_full = false;
409 if (hdmi_msm_state->cec_queue_rd == CEC_QUEUE_END)
410 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
411 mutex_unlock(&hdmi_msm_state_mutex);
412
413 return sizeof(struct hdmi_msm_cec_msg);
414}
415
416static ssize_t hdmi_msm_wta_cec_frame(struct device *dev,
417 struct device_attribute *attr, const char *buf, size_t count)
418{
419 int retry = ((struct hdmi_msm_cec_msg *) buf)->retransmit;
420
421 if (retry > 15)
422 retry = 15;
423 while (1) {
424 hdmi_msm_cec_msg_send((struct hdmi_msm_cec_msg *) buf);
425 if (hdmi_msm_state->cec_frame_wr_status
426 & CEC_STATUS_WR_ERROR && retry--)
427 msleep(360);
428 else
429 break;
430 }
431
432 if (hdmi_msm_state->cec_frame_wr_status & CEC_STATUS_WR_DONE)
433 return sizeof(struct hdmi_msm_cec_msg);
434 else
435 return -EINVAL;
436}
437#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
438
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439static ssize_t hdmi_common_rda_3d_present(struct device *dev,
440 struct device_attribute *attr, char *buf)
441{
442 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
443 external_common_state->present_3d);
444 DEV_DBG("%s: '%d'\n", __func__,
445 external_common_state->present_3d);
446 return ret;
447}
448
449static ssize_t hdmi_common_rda_hdcp_present(struct device *dev,
450 struct device_attribute *attr, char *buf)
451{
452 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
453 external_common_state->present_hdcp);
454 DEV_DBG("%s: '%d'\n", __func__,
455 external_common_state->present_hdcp);
456 return ret;
457}
458#endif
459
460#ifdef CONFIG_FB_MSM_HDMI_3D
461static ssize_t hdmi_3d_rda_format_3d(struct device *dev,
462 struct device_attribute *attr, char *buf)
463{
464 ssize_t ret = snprintf(buf, PAGE_SIZE, "%d\n",
465 external_common_state->format_3d);
466 DEV_DBG("%s: '%d'\n", __func__,
467 external_common_state->format_3d);
468 return ret;
469}
470
471static ssize_t hdmi_3d_wta_format_3d(struct device *dev,
472 struct device_attribute *attr, const char *buf, size_t count)
473{
474 ssize_t ret = strnlen(buf, PAGE_SIZE);
475 int format_3d = atoi(buf);
476
477 if (format_3d >= 0 && format_3d <= 2) {
478 if (format_3d != external_common_state->format_3d) {
479 external_common_state->format_3d = format_3d;
480 if (external_common_state->switch_3d)
481 external_common_state->switch_3d(format_3d);
482 DEV_DBG("%s: '%d'\n", __func__,
483 external_common_state->format_3d);
484 } else {
485 DEV_DBG("%s: '%d' (unchanged)\n", __func__,
486 external_common_state->format_3d);
487 }
488 } else {
489 DEV_DBG("%s: '%d' (unknown)\n", __func__, format_3d);
490 }
491
492 return ret;
493}
494#endif
495
Manoj Raoa2c27672011-08-30 17:19:39 -0700496#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
497static DEVICE_ATTR(cec, S_IRUGO | S_IWUSR,
498 hdmi_msm_rda_cec,
499 hdmi_msm_wta_cec);
500
501static DEVICE_ATTR(cec_logical_addr, S_IRUGO | S_IWUSR,
502 hdmi_msm_rda_cec_logical_addr,
503 hdmi_msm_wta_cec_logical_addr);
504
505static DEVICE_ATTR(cec_rd_frame, S_IRUGO,
506 hdmi_msm_rda_cec_frame, NULL);
507
508static DEVICE_ATTR(cec_wr_frame, S_IWUSR,
509 NULL, hdmi_msm_wta_cec_frame);
510#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
511
512
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513static ssize_t external_common_rda_video_mode(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->video_resolution+1);
518 DEV_DBG("%s: '%d'\n", __func__,
519 external_common_state->video_resolution+1);
520 return ret;
521}
522
523static ssize_t external_common_wta_video_mode(struct device *dev,
524 struct device_attribute *attr, const char *buf, size_t count)
525{
526 ssize_t ret = strnlen(buf, PAGE_SIZE);
527 uint32 video_mode;
528#ifdef CONFIG_FB_MSM_HDMI_COMMON
529 const struct hdmi_disp_mode_timing_type *disp_mode;
530#endif
531 mutex_lock(&external_common_state_hpd_mutex);
532 if (!external_common_state->hpd_state) {
533 mutex_unlock(&external_common_state_hpd_mutex);
534 DEV_INFO("%s: FAILED: display off or cable disconnected\n",
535 __func__);
536 return ret;
537 }
538 mutex_unlock(&external_common_state_hpd_mutex);
539
540 video_mode = atoi(buf)-1;
541 kobject_uevent(external_common_state->uevent_kobj, KOBJ_OFFLINE);
542#ifdef CONFIG_FB_MSM_HDMI_COMMON
543 disp_mode = hdmi_common_get_supported_mode(video_mode);
544 if (!disp_mode) {
545 DEV_INFO("%s: FAILED: mode not supported (%d)\n",
546 __func__, video_mode);
547 return ret;
548 }
549 external_common_state->disp_mode_list.num_of_elements = 1;
550 external_common_state->disp_mode_list.disp_mode_list[0] = video_mode;
551#elif defined(CONFIG_FB_MSM_TVOUT)
552 external_common_state->video_resolution = video_mode;
553#endif
554 DEV_DBG("%s: 'mode=%d %s' successful (sending OFF/ONLINE)\n", __func__,
555 video_mode, video_format_2string(video_mode));
556 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ONLINE);
557 return ret;
558}
559
560static ssize_t external_common_rda_connected(struct device *dev,
561 struct device_attribute *attr, char *buf)
562{
563 ssize_t ret;
564 mutex_lock(&external_common_state_hpd_mutex);
565 ret = snprintf(buf, PAGE_SIZE, "%d\n",
566 external_common_state->hpd_state);
567 DEV_DBG("%s: '%d'\n", __func__,
568 external_common_state->hpd_state);
569 mutex_unlock(&external_common_state_hpd_mutex);
570 return ret;
571}
572
573static DEVICE_ATTR(video_mode, S_IRUGO | S_IWUGO,
574 external_common_rda_video_mode, external_common_wta_video_mode);
575static DEVICE_ATTR(video_mode_str, S_IRUGO, external_common_rda_video_mode_str,
576 NULL);
577static DEVICE_ATTR(connected, S_IRUGO, external_common_rda_connected, NULL);
578#ifdef CONFIG_FB_MSM_HDMI_COMMON
579static DEVICE_ATTR(edid_modes, S_IRUGO, hdmi_common_rda_edid_modes, NULL);
580static DEVICE_ATTR(hpd, S_IRUGO | S_IWUGO, hdmi_common_rda_hpd,
581 hdmi_common_wta_hpd);
582static DEVICE_ATTR(hdcp, S_IRUGO, hdmi_common_rda_hdcp, NULL);
583static DEVICE_ATTR(3d_present, S_IRUGO, hdmi_common_rda_3d_present, NULL);
584static DEVICE_ATTR(hdcp_present, S_IRUGO, hdmi_common_rda_hdcp_present, NULL);
585#endif
586#ifdef CONFIG_FB_MSM_HDMI_3D
587static DEVICE_ATTR(format_3d, S_IRUGO | S_IWUGO, hdmi_3d_rda_format_3d,
588 hdmi_3d_wta_format_3d);
589#endif
590
591static struct attribute *external_common_fs_attrs[] = {
592 &dev_attr_video_mode.attr,
593 &dev_attr_video_mode_str.attr,
594 &dev_attr_connected.attr,
595#ifdef CONFIG_FB_MSM_HDMI_COMMON
596 &dev_attr_edid_modes.attr,
597 &dev_attr_hdcp.attr,
598 &dev_attr_hpd.attr,
599 &dev_attr_3d_present.attr,
600 &dev_attr_hdcp_present.attr,
601#endif
602#ifdef CONFIG_FB_MSM_HDMI_3D
603 &dev_attr_format_3d.attr,
604#endif
Manoj Raoa2c27672011-08-30 17:19:39 -0700605#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
606 &dev_attr_cec.attr,
607 &dev_attr_cec_logical_addr.attr,
608 &dev_attr_cec_rd_frame.attr,
609 &dev_attr_cec_wr_frame.attr,
610#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700611 NULL,
612};
613static struct attribute_group external_common_fs_attr_group = {
614 .attrs = external_common_fs_attrs,
615};
616
617/* create external interface kobject and initialize */
618int external_common_state_create(struct platform_device *pdev)
619{
620 int rc;
621 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
622 if (!mfd) {
623 DEV_ERR("%s: mfd not found\n", __func__);
624 return -ENODEV;
625 }
626 if (!mfd->fbi) {
627 DEV_ERR("%s: mfd->fbi not found\n", __func__);
628 return -ENODEV;
629 }
630 if (!mfd->fbi->dev) {
631 DEV_ERR("%s: mfd->fbi->dev not found\n", __func__);
632 return -ENODEV;
633 }
634 rc = sysfs_create_group(&mfd->fbi->dev->kobj,
635 &external_common_fs_attr_group);
636 if (rc) {
637 DEV_ERR("%s: sysfs group creation failed, rc=%d\n", __func__,
638 rc);
639 return rc;
640 }
641 external_common_state->uevent_kobj = &mfd->fbi->dev->kobj;
642 DEV_ERR("%s: sysfs group %p\n", __func__,
643 external_common_state->uevent_kobj);
644
645 kobject_uevent(external_common_state->uevent_kobj, KOBJ_ADD);
646 DEV_DBG("%s: kobject_uevent(KOBJ_ADD)\n", __func__);
647 return 0;
648}
649EXPORT_SYMBOL(external_common_state_create);
650
651void external_common_state_remove(void)
652{
653 if (external_common_state->uevent_kobj)
654 sysfs_remove_group(external_common_state->uevent_kobj,
655 &external_common_fs_attr_group);
656 external_common_state->uevent_kobj = NULL;
657}
658EXPORT_SYMBOL(external_common_state_remove);
659
660#ifdef CONFIG_FB_MSM_HDMI_COMMON
661/* The Logic ID for HDMI TX Core. Currently only support 1 HDMI TX Core. */
662struct hdmi_edid_video_mode_property_type {
663 uint32 video_code;
664 uint32 active_h;
665 uint32 active_v;
666 boolean interlaced;
667 uint32 total_h;
668 uint32 total_blank_h;
669 uint32 total_v;
670 uint32 total_blank_v;
671 /* Must divide by 1000 to get the frequency */
672 uint32 freq_h;
673 /* Must divide by 1000 to get the frequency */
674 uint32 freq_v;
675 /* Must divide by 1000 to get the frequency */
676 uint32 pixel_freq;
677 /* Must divide by 1000 to get the frequency */
678 uint32 refresh_rate;
679 boolean aspect_ratio_4_3;
680};
681
682/* LUT is sorted from lowest Active H to highest Active H - ease searching */
683static struct hdmi_edid_video_mode_property_type
684 hdmi_edid_disp_mode_lut[] = {
685
686 /* All 640 H Active */
687 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
688 31465, 59940, 25175, 59940, TRUE},
689 {HDMI_VFRMT_640x480p60_4_3, 640, 480, FALSE, 800, 160, 525, 45,
690 31500, 60000, 25200, 60000, TRUE},
691
692 /* All 720 H Active */
693 {HDMI_VFRMT_720x576p50_4_3, 720, 576, FALSE, 864, 144, 625, 49,
694 31250, 50000, 27000, 50000, TRUE},
695 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
696 31465, 59940, 27000, 59940, TRUE},
697 {HDMI_VFRMT_720x480p60_4_3, 720, 480, FALSE, 858, 138, 525, 45,
698 31500, 60000, 27030, 60000, TRUE},
699 {HDMI_VFRMT_720x576p100_4_3, 720, 576, FALSE, 864, 144, 625, 49,
700 62500, 100000, 54000, 100000, TRUE},
701 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
702 62937, 119880, 54000, 119880, TRUE},
703 {HDMI_VFRMT_720x480p120_4_3, 720, 480, FALSE, 858, 138, 525, 45,
704 63000, 120000, 54054, 120000, TRUE},
705 {HDMI_VFRMT_720x576p200_4_3, 720, 576, FALSE, 864, 144, 625, 49,
706 125000, 200000, 108000, 200000, TRUE},
707 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
708 125874, 239760, 108000, 239000, TRUE},
709 {HDMI_VFRMT_720x480p240_4_3, 720, 480, FALSE, 858, 138, 525, 45,
710 126000, 240000, 108108, 240000, TRUE},
711
712 /* All 1280 H Active */
713 {HDMI_VFRMT_1280x720p50_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
714 37500, 50000, 74250, 50000, FALSE},
715 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
716 44955, 59940, 74176, 59940, FALSE},
717 {HDMI_VFRMT_1280x720p60_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
718 45000, 60000, 74250, 60000, FALSE},
719 {HDMI_VFRMT_1280x720p100_16_9, 1280, 720, FALSE, 1980, 700, 750, 30,
720 75000, 100000, 148500, 100000, FALSE},
721 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
722 89909, 119880, 148352, 119880, FALSE},
723 {HDMI_VFRMT_1280x720p120_16_9, 1280, 720, FALSE, 1650, 370, 750, 30,
724 90000, 120000, 148500, 120000, FALSE},
725
726 /* All 1440 H Active */
727 {HDMI_VFRMT_1440x576i50_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
728 15625, 50000, 27000, 50000, TRUE},
729 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 312, 24,
730 15625, 50080, 27000, 50000, TRUE},
731 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 313, 25,
732 15625, 49920, 27000, 50000, TRUE},
733 {HDMI_VFRMT_720x288p50_4_3, 1440, 288, FALSE, 1728, 288, 314, 26,
734 15625, 49761, 27000, 50000, TRUE},
735 {HDMI_VFRMT_1440x576p50_4_3, 1440, 576, FALSE, 1728, 288, 625, 49,
736 31250, 50000, 54000, 50000, TRUE},
737 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
738 15734, 59940, 27000, 59940, TRUE},
739 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
740 15734, 60054, 27000, 59940, TRUE},
741 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
742 15734, 59826, 27000, 59940, TRUE},
743 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
744 31469, 59940, 54000, 59940, TRUE},
745 {HDMI_VFRMT_1440x480i60_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
746 15750, 60000, 27027, 60000, TRUE},
747 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 262, 22,
748 15750, 60115, 27027, 60000, TRUE},
749 {HDMI_VFRMT_1440x240p60_4_3, 1440, 240, FALSE, 1716, 276, 263, 23,
750 15750, 59886, 27027, 60000, TRUE},
751 {HDMI_VFRMT_1440x480p60_4_3, 1440, 480, FALSE, 1716, 276, 525, 45,
752 31500, 60000, 54054, 60000, TRUE},
753 {HDMI_VFRMT_1440x576i100_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
754 31250, 100000, 54000, 100000, TRUE},
755 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
756 31469, 119880, 54000, 119880, TRUE},
757 {HDMI_VFRMT_1440x480i120_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
758 31500, 120000, 54054, 120000, TRUE},
759 {HDMI_VFRMT_1440x576i200_4_3, 1440, 576, TRUE, 1728, 288, 625, 24,
760 62500, 200000, 108000, 200000, TRUE},
761 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
762 62937, 239760, 108000, 239000, TRUE},
763 {HDMI_VFRMT_1440x480i240_4_3, 1440, 480, TRUE, 1716, 276, 525, 22,
764 63000, 240000, 108108, 240000, TRUE},
765
766 /* All 1920 H Active */
767 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
768 45, 67433, 59940, 148352, 59940, FALSE},
769 {HDMI_VFRMT_1920x1080p60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
770 45, 67500, 60000, 148500, 60000, FALSE},
771 {HDMI_VFRMT_1920x1080p50_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
772 45, 56250, 50000, 148500, 50000, FALSE},
773 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
774 45, 26973, 23976, 74176, 24000, FALSE},
775 {HDMI_VFRMT_1920x1080p24_16_9, 1920, 1080, FALSE, 2750, 830, 1125,
776 45, 27000, 24000, 74250, 24000, FALSE},
777 {HDMI_VFRMT_1920x1080p25_16_9, 1920, 1080, FALSE, 2640, 720, 1125,
778 45, 28125, 25000, 74250, 25000, FALSE},
779 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
780 45, 33716, 29970, 74176, 30000, FALSE},
781 {HDMI_VFRMT_1920x1080p30_16_9, 1920, 1080, FALSE, 2200, 280, 1125,
782 45, 33750, 30000, 74250, 30000, FALSE},
783 {HDMI_VFRMT_1920x1080i50_16_9, 1920, 1080, TRUE, 2304, 384, 1250,
784 85, 31250, 50000, 72000, 50000, FALSE},
785 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
786 22, 33716, 59940, 74176, 59940, FALSE},
787 {HDMI_VFRMT_1920x1080i60_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
788 22, 33750, 60000, 74250, 60000, FALSE},
789 {HDMI_VFRMT_1920x1080i100_16_9, 1920, 1080, TRUE, 2640, 720, 1125,
790 22, 56250, 100000, 148500, 100000, FALSE},
791 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
792 22, 67432, 119880, 148352, 119980, FALSE},
793 {HDMI_VFRMT_1920x1080i120_16_9, 1920, 1080, TRUE, 2200, 280, 1125,
794 22, 67500, 120000, 148500, 120000, FALSE},
795
796 /* All 2880 H Active */
797 {HDMI_VFRMT_2880x576i50_4_3, 2880, 576, TRUE, 3456, 576, 625, 24,
798 15625, 50000, 54000, 50000, TRUE},
799 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 312, 24,
800 15625, 50080, 54000, 50000, TRUE},
801 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 313, 25,
802 15625, 49920, 54000, 50000, TRUE},
803 {HDMI_VFRMT_2880x288p50_4_3, 2880, 576, FALSE, 3456, 576, 314, 26,
804 15625, 49761, 54000, 50000, TRUE},
805 {HDMI_VFRMT_2880x576p50_4_3, 2880, 576, FALSE, 3456, 576, 625, 49,
806 31250, 50000, 108000, 50000, TRUE},
807 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
808 15734, 59940, 54000, 59940, TRUE},
809 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 262, 22,
810 15734, 60054, 54000, 59940, TRUE},
811 {HDMI_VFRMT_2880x240p60_4_3, 2880, 480, FALSE, 3432, 552, 263, 23,
812 15734, 59940, 54000, 59940, TRUE},
813 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
814 31469, 59940, 108000, 59940, TRUE},
815 {HDMI_VFRMT_2880x480i60_4_3, 2880, 480, TRUE, 3432, 552, 525, 22,
816 15750, 60000, 54054, 60000, TRUE},
817 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 22,
818 15750, 60115, 54054, 60000, TRUE},
819 {HDMI_VFRMT_2880x240p60_4_3, 2880, 240, FALSE, 3432, 552, 262, 23,
820 15750, 59886, 54054, 60000, TRUE},
821 {HDMI_VFRMT_2880x480p60_4_3, 2880, 480, FALSE, 3432, 552, 525, 45,
822 31500, 60000, 108108, 60000, TRUE},
823};
824
825static const uint8 *hdmi_edid_find_block(const uint8 *in_buf, uint8 type,
826 uint8 *len)
827{
828 /* the start of data block collection, start of Video Data Block */
829 uint32 offset = 4;
830
831 *len = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -0700832 if ((in_buf[2] == 4) && (type != 2)) { /* no non-DTD data present */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 DEV_WARN("EDID: no non-DTD data present\n");
834 return NULL;
835 }
836 while (offset < 0x80) {
837 uint8 block_len = in_buf[offset] & 0x1F;
838 if ((in_buf[offset] >> 5) == type) {
839 *len = block_len;
840 DEV_DBG("EDID: block=%d found @ %d with length=%d\n",
841 type, offset, block_len);
842 return in_buf+offset;
843 }
844 offset += 1 + block_len;
845 }
Manoj Rao668d6d52011-08-16 19:12:31 -0700846 DEV_WARN("EDID: type=%d block not found in EDID block\n", type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847 return NULL;
848}
849
850static void hdmi_edid_extract_vendor_id(const uint8 *in_buf,
851 char *vendor_id)
852{
853 uint32 id_codes = ((uint32)in_buf[8] << 8) + in_buf[9];
854
855 vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
856 vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
857 vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
858 vendor_id[3] = 0;
859}
860
861static uint32 hdmi_edid_extract_ieee_reg_id(const uint8 *in_buf)
862{
863 uint8 len;
864 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
865
866 if (vsd == NULL)
867 return 0;
868
869 DEV_DBG("EDID: VSD PhyAddr=%04x, MaxTMDS=%dMHz\n",
870 ((uint32)vsd[6] << 8) + (uint32)vsd[5], (uint32)vsd[7] * 5);
871 return ((uint32)vsd[3] << 16) + ((uint32)vsd[2] << 8) + (uint32)vsd[1];
872}
873
874static void hdmi_edid_extract_3d_present(const uint8 *in_buf)
875{
876 uint8 len, offset;
877 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
878
879 external_common_state->present_3d = 0;
880 if (vsd == NULL || len < 9) {
881 DEV_DBG("EDID[3D]: block-id 3 not found or not long enough\n");
882 return;
883 }
884
885 offset = !(vsd[8] & BIT(7)) ? 9 : 13;
886 DEV_DBG("EDID: 3D present @ %d = %02x\n", offset, vsd[offset]);
887 if (vsd[offset] >> 7) { /* 3D format indication present */
888 DEV_INFO("EDID: 3D present, 3D-len=%d\n", vsd[offset+1] & 0x1F);
889 external_common_state->present_3d = 1;
890 }
891}
892
893
894static void hdmi_edid_extract_latency_fields(const uint8 *in_buf)
895{
896 uint8 len;
897 const uint8 *vsd = hdmi_edid_find_block(in_buf, 3, &len);
898
899 if (vsd == NULL || len < 12 || !(vsd[8] & BIT(7))) {
900 external_common_state->video_latency = (uint16)-1;
901 external_common_state->audio_latency = (uint16)-1;
902 DEV_DBG("EDID: No audio/video latency present\n");
903 } else {
904 external_common_state->video_latency = vsd[9];
905 external_common_state->audio_latency = vsd[10];
906 DEV_DBG("EDID: video-latency=%04x, audio-latency=%04x\n",
907 external_common_state->video_latency,
908 external_common_state->audio_latency);
909 }
910}
911
912static void hdmi_edid_extract_speaker_allocation_data(const uint8 *in_buf)
913{
914 uint8 len;
915 const uint8 *sad = hdmi_edid_find_block(in_buf, 4, &len);
916
917 if (sad == NULL)
918 return;
919
920 external_common_state->speaker_allocation_block = sad[1];
921 DEV_DBG("EDID: speaker allocation data=%s%s%s%s%s%s%s\n",
922 (sad[1] & BIT(0)) ? "FL/FR," : "",
923 (sad[1] & BIT(1)) ? "LFE," : "",
924 (sad[1] & BIT(2)) ? "FC," : "",
925 (sad[1] & BIT(3)) ? "RL/RR," : "",
926 (sad[1] & BIT(4)) ? "RC," : "",
927 (sad[1] & BIT(5)) ? "FLC/FRC," : "",
928 (sad[1] & BIT(6)) ? "LFE," : "");
929}
930
931static void hdmi_edid_extract_audio_data_blocks(const uint8 *in_buf)
932{
933 uint8 len;
934 const uint8 *sad = hdmi_edid_find_block(in_buf, 1, &len);
935 uint32 *adb = external_common_state->audio_data_blocks;
936
937 if (sad == NULL)
938 return;
939
940 external_common_state->audio_data_block_cnt = 0;
941 while (len >= 3 && external_common_state->audio_data_block_cnt < 16) {
942 DEV_DBG("EDID: Audio Data Block=<ch=%d, format=%d "
943 "sampling=0x%02x bit-depth=0x%02x>\n",
944 (sad[1] & 0x7)+1, sad[1] >> 3, sad[2], sad[3]);
945 *adb++ = (uint32)sad[1] + ((uint32)sad[2] << 8)
946 + ((uint32)sad[2] << 16);
947 ++external_common_state->audio_data_block_cnt;
948 len -= 3;
949 sad += 3;
950 }
951}
952
953
954static void hdmi_edid_detail_desc(const uint8 *data_buf, uint32 *disp_mode)
955{
956 boolean aspect_ratio_4_3 = FALSE;
957 boolean interlaced = FALSE;
958 uint32 active_h = 0;
959 uint32 active_v = 0;
960 uint32 blank_h = 0;
961 uint32 blank_v = 0;
962 uint32 ndx = 0;
963 uint32 max_num_of_elements = 0;
964 uint32 img_size_h = 0;
965 uint32 img_size_v = 0;
966
967 /* See VESA Spec */
968 /* EDID_TIMING_DESC_UPPER_H_NIBBLE[0x4]: Relative Offset to the EDID
969 * detailed timing descriptors - Upper 4 bit for each H active/blank
970 * field */
971 /* EDID_TIMING_DESC_H_ACTIVE[0x2]: Relative Offset to the EDID detailed
972 * timing descriptors - H active */
973 active_h = ((((uint32)data_buf[0x4] >> 0x4) & 0xF) << 8)
974 | data_buf[0x2];
975
976 /* EDID_TIMING_DESC_H_BLANK[0x3]: Relative Offset to the EDID detailed
977 * timing descriptors - H blank */
978 blank_h = (((uint32)data_buf[0x4] & 0xF) << 8)
979 | data_buf[0x3];
980
981 /* EDID_TIMING_DESC_UPPER_V_NIBBLE[0x7]: Relative Offset to the EDID
982 * detailed timing descriptors - Upper 4 bit for each V active/blank
983 * field */
984 /* EDID_TIMING_DESC_V_ACTIVE[0x5]: Relative Offset to the EDID detailed
985 * timing descriptors - V active */
986 active_v = ((((uint32)data_buf[0x7] >> 0x4) & 0xF) << 8)
987 | data_buf[0x5];
988
989 /* EDID_TIMING_DESC_V_BLANK[0x6]: Relative Offset to the EDID detailed
990 * timing descriptors - V blank */
991 blank_v = (((uint32)data_buf[0x7] & 0xF) << 8)
992 | data_buf[0x6];
993
994 /* EDID_TIMING_DESC_IMAGE_SIZE_UPPER_NIBBLE[0xE]: Relative Offset to the
995 * EDID detailed timing descriptors - Image Size upper nibble
996 * V and H */
997 /* EDID_TIMING_DESC_H_IMAGE_SIZE[0xC]: Relative Offset to the EDID
998 * detailed timing descriptors - H image size */
999 /* EDID_TIMING_DESC_V_IMAGE_SIZE[0xD]: Relative Offset to the EDID
1000 * detailed timing descriptors - V image size */
1001 img_size_h = ((((uint32)data_buf[0xE] >> 0x4) & 0xF) << 8)
1002 | data_buf[0xC];
1003 img_size_v = (((uint32)data_buf[0xE] & 0xF) << 8)
1004 | data_buf[0xD];
1005
1006 aspect_ratio_4_3 = (img_size_h * 3 == img_size_v * 4);
1007
1008 max_num_of_elements = sizeof(hdmi_edid_disp_mode_lut)
1009 / sizeof(*hdmi_edid_disp_mode_lut);
1010
Manoj Rao668d6d52011-08-16 19:12:31 -07001011 /* EDID_TIMING_DESC_INTERLACE[0x11:7]: Relative Offset to the EDID
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 * detailed timing descriptors - Interlace flag */
Manoj Rao668d6d52011-08-16 19:12:31 -07001013 DEV_DBG("Interlaced mode byte data_buf[0x11]=[%x]\n", data_buf[0x11]);
1014 /*
1015 * CEA 861-D: interlaced bit is bit[7] of byte[0x11]
1016 */
1017 interlaced = (data_buf[0x11] & 0x80) >> 7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001018
1019 DEV_DBG("%s: A[%ux%u] B[%ux%u] V[%ux%u] %s\n", __func__,
1020 active_h, active_v, blank_h, blank_v, img_size_h, img_size_v,
1021 interlaced ? "i" : "p");
1022
1023 *disp_mode = HDMI_VFRMT_FORCE_32BIT;
1024 while (ndx < max_num_of_elements) {
1025 const struct hdmi_edid_video_mode_property_type *edid =
1026 hdmi_edid_disp_mode_lut+ndx;
1027
1028 if ((interlaced == edid->interlaced) &&
1029 (active_h == edid->active_h) &&
1030 (blank_h == edid->total_blank_h) &&
1031 (blank_v == edid->total_blank_v) &&
1032 ((active_v == edid->active_v) ||
1033 (active_v == (edid->active_v + 1)))
1034 ) {
1035 if (edid->aspect_ratio_4_3 && !aspect_ratio_4_3)
1036 /* Aspect ratio 16:9 */
1037 *disp_mode = edid->video_code + 1;
1038 else
1039 /* Aspect ratio 4:3 */
1040 *disp_mode = edid->video_code;
1041
1042 DEV_DBG("%s: mode found:%d\n", __func__, *disp_mode);
1043 break;
1044 }
1045 ++ndx;
1046 }
1047 if (ndx == max_num_of_elements)
1048 DEV_INFO("%s: *no mode* found\n", __func__);
1049}
1050
1051static void add_supported_video_format(
1052 struct hdmi_disp_mode_list_type *disp_mode_list,
1053 uint32 video_format)
1054{
1055 const struct hdmi_disp_mode_timing_type *timing =
1056 hdmi_common_get_supported_mode(video_format);
1057 boolean supported = timing != NULL;
1058
1059 if (video_format >= HDMI_VFRMT_MAX)
1060 return;
1061
1062 DEV_DBG("EDID: format: %d [%s], %s\n",
1063 video_format, video_format_2string(video_format),
1064 supported ? "Supported" : "Not-Supported");
1065 if (supported)
1066 disp_mode_list->disp_mode_list[
1067 disp_mode_list->num_of_elements++] = video_format;
1068}
1069
1070static void hdmi_edid_get_display_mode(const uint8 *data_buf,
1071 struct hdmi_disp_mode_list_type *disp_mode_list,
1072 uint32 num_og_cea_blocks)
1073{
1074 uint8 i = 0;
1075 uint32 video_format = HDMI_VFRMT_640x480p60_4_3;
1076 boolean has480p = FALSE;
1077 uint8 len;
Manoj Rao668d6d52011-08-16 19:12:31 -07001078 const uint8 *edid_blk0 = &data_buf[0x0];
1079 const uint8 *edid_blk1 = &data_buf[0x80];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001080 const uint8 *svd = num_og_cea_blocks ?
1081 hdmi_edid_find_block(data_buf+0x80, 2, &len) : NULL;
1082
1083 disp_mode_list->num_of_elements = 0;
1084 if (svd != NULL) {
1085 ++svd;
1086 for (i = 0; i < len; ++i, ++svd) {
1087 /* Subtract 1 because it is zero based in the driver,
1088 * while the Video identification code is 1 based in the
1089 * CEA_861D spec */
1090 video_format = (*svd & 0x7F) - 1;
1091 add_supported_video_format(disp_mode_list,
1092 video_format);
1093 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1094 has480p = TRUE;
1095 }
1096 } else if (!num_og_cea_blocks) {
1097 /* Detailed timing descriptors */
1098 uint32 desc_offset = 0;
1099 /* Maximum 4 timing descriptor in block 0 - No CEA
1100 * extension in this case */
1101 /* EDID_FIRST_TIMING_DESC[0x36] - 1st detailed timing
1102 * descriptor */
1103 /* EDID_DETAIL_TIMING_DESC_BLCK_SZ[0x12] - Each detailed timing
1104 * descriptor has block size of 18 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001105 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1106 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001107 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001108 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1109 __func__, __LINE__,
1110 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001111 add_supported_video_format(disp_mode_list,
1112 video_format);
1113 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1114 has480p = TRUE;
1115 desc_offset += 0x12;
1116 ++i;
1117 }
1118 } else if (1 == num_og_cea_blocks) {
1119 uint32 desc_offset = 0;
Manoj Rao668d6d52011-08-16 19:12:31 -07001120
1121 /*
1122 * Read from both block 0 and block 1
1123 * Read EDID block[0] as above
1124 */
1125 while (4 > i && 0 != edid_blk0[0x36+desc_offset]) {
1126 hdmi_edid_detail_desc(edid_blk0+0x36+desc_offset,
1127 &video_format);
1128 DEV_DBG("[%s:%d] Block-0 Adding vid fmt = [%s]\n",
1129 __func__, __LINE__,
1130 video_format_2string(video_format));
1131 add_supported_video_format(disp_mode_list,
1132 video_format);
1133 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1134 has480p = TRUE;
1135 desc_offset += 0x12;
1136 ++i;
1137 }
1138
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001139 /* Parse block 1 - CEA extension byte offset of first
1140 * detailed timing generation - offset is relevant to
1141 * the offset of block 1 */
1142
1143 /* EDID_CEA_EXTENSION_FIRST_DESC[0x82]: Offset to CEA
1144 * extension first timing desc - indicate the offset of
1145 * the first detailed timing descriptor */
1146 /* EDID_BLOCK_SIZE = 0x80 Each page size in the EDID ROM */
Manoj Rao668d6d52011-08-16 19:12:31 -07001147 desc_offset = edid_blk1[0x02];
1148 while (0 != edid_blk1[desc_offset]) {
1149 hdmi_edid_detail_desc(edid_blk1+desc_offset,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001150 &video_format);
Manoj Rao668d6d52011-08-16 19:12:31 -07001151 DEV_DBG("[%s:%d] Block-1 Adding vid fmt = [%s]\n",
1152 __func__, __LINE__,
1153 video_format_2string(video_format));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001154 add_supported_video_format(disp_mode_list,
1155 video_format);
1156 if (video_format == HDMI_VFRMT_640x480p60_4_3)
1157 has480p = TRUE;
1158 desc_offset += 0x12;
1159 ++i;
1160 }
1161 }
1162
1163 if (!has480p)
1164 /* Need to add default 640 by 480 timings, in case not described
1165 * in the EDID structure.
1166 * All DTV sink devices should support this mode */
1167 add_supported_video_format(disp_mode_list,
1168 HDMI_VFRMT_640x480p60_4_3);
1169}
1170
1171static int hdmi_common_read_edid_block(int block, uint8 *edid_buf)
1172{
Manoj Rao668d6d52011-08-16 19:12:31 -07001173 uint32 ndx, check_sum, print_len;
1174#ifdef DEBUG
1175 const u8 *b = edid_buf;
1176#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177 int status = external_common_state->read_edid_block(block, edid_buf);
Manoj Rao668d6d52011-08-16 19:12:31 -07001178 if (status)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001179 goto error;
1180
1181 /* Calculate checksum */
1182 check_sum = 0;
1183 for (ndx = 0; ndx < 0x80; ++ndx)
1184 check_sum += edid_buf[ndx];
1185
1186 if (check_sum & 0xFF) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187 DEV_ERR("%s: failed CHECKSUM (read:%x, expected:%x)\n",
1188 __func__, (uint8)edid_buf[0x7F], (uint8)check_sum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189#ifdef DEBUG
1190 for (ndx = 0; ndx < 0x100; ndx += 16)
1191 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1192 "%02x %02x %02x %02x %02x %02x %02x %02x "
1193 "%02x %02x %02x %02x\n", ndx, ndx+15,
1194 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1195 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1196 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1197 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1198#endif
1199 status = -EPROTO;
1200 goto error;
1201 }
Manoj Rao668d6d52011-08-16 19:12:31 -07001202 print_len = 0x80;
1203 for (ndx = 0; ndx < print_len; ndx += 16)
1204 DEV_DBG("EDID[%02x-%02x] %02x %02x %02x %02x "
1205 "%02x %02x %02x %02x %02x %02x %02x %02x "
1206 "%02x %02x %02x %02x\n", ndx, ndx+15,
1207 b[ndx+0], b[ndx+1], b[ndx+2], b[ndx+3],
1208 b[ndx+4], b[ndx+5], b[ndx+6], b[ndx+7],
1209 b[ndx+8], b[ndx+9], b[ndx+10], b[ndx+11],
1210 b[ndx+12], b[ndx+13], b[ndx+14], b[ndx+15]);
1211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001212
1213error:
1214 return status;
1215}
1216
1217static boolean check_edid_header(const uint8 *edid_buf)
1218{
1219 return (edid_buf[0] == 0x00) && (edid_buf[1] == 0xff)
1220 && (edid_buf[2] == 0xff) && (edid_buf[3] == 0xff)
1221 && (edid_buf[4] == 0xff) && (edid_buf[5] == 0xff)
1222 && (edid_buf[6] == 0xff) && (edid_buf[7] == 0x00);
1223}
1224
1225int hdmi_common_read_edid(void)
1226{
1227 int status = 0;
1228 uint32 cea_extension_ver = 0;
1229 uint32 num_og_cea_blocks = 0;
1230 uint32 ieee_reg_id = 0;
1231 uint32 i = 1;
1232 char vendor_id[5];
1233 /* EDID_BLOCK_SIZE[0x80] Each page size in the EDID ROM */
1234 uint8 edid_buf[0x80 * 4];
1235
1236 external_common_state->present_3d = 0;
1237 memset(&external_common_state->disp_mode_list, 0,
1238 sizeof(external_common_state->disp_mode_list));
1239 memset(edid_buf, 0, sizeof(edid_buf));
1240
1241 status = hdmi_common_read_edid_block(0, edid_buf);
1242 if (status || !check_edid_header(edid_buf)) {
1243 if (!status)
1244 status = -EPROTO;
1245 DEV_ERR("%s: edid read block(0) failed: %d "
1246 "[%02x%02x%02x%02x%02x%02x%02x%02x]\n", __func__,
1247 status,
1248 edid_buf[0], edid_buf[1], edid_buf[2], edid_buf[3],
1249 edid_buf[4], edid_buf[5], edid_buf[6], edid_buf[7]);
1250 goto error;
1251 }
1252 hdmi_edid_extract_vendor_id(edid_buf, vendor_id);
1253
1254 /* EDID_CEA_EXTENSION_FLAG[0x7E] - CEC extension byte */
1255 num_og_cea_blocks = edid_buf[0x7E];
1256
1257 DEV_DBG("[JSR] (%s): No. of CEA blocks is [%u]\n", __func__,
1258 num_og_cea_blocks);
1259 /* Find out any CEA extension blocks following block 0 */
1260 switch (num_og_cea_blocks) {
1261 case 0: /* No CEA extension */
1262 external_common_state->hdmi_sink = false;
1263 DEV_DBG("HDMI DVI mode: %s\n",
1264 external_common_state->hdmi_sink ? "no" : "yes");
1265 break;
1266 case 1: /* Read block 1 */
Manoj Rao668d6d52011-08-16 19:12:31 -07001267 status = hdmi_common_read_edid_block(1, &edid_buf[0x80]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001268 if (status) {
1269 DEV_ERR("%s: ddc read block(1) failed: %d\n", __func__,
1270 status);
1271 goto error;
1272 }
1273 if (edid_buf[0x80] != 2)
1274 num_og_cea_blocks = 0;
1275 if (num_og_cea_blocks) {
1276 ieee_reg_id =
1277 hdmi_edid_extract_ieee_reg_id(edid_buf+0x80);
1278 if (ieee_reg_id == 0x0c03)
1279 external_common_state->hdmi_sink = TRUE ;
1280 else
1281 external_common_state->hdmi_sink = FALSE ;
1282 hdmi_edid_extract_latency_fields(edid_buf+0x80);
1283 hdmi_edid_extract_speaker_allocation_data(
1284 edid_buf+0x80);
1285 hdmi_edid_extract_audio_data_blocks(edid_buf+0x80);
1286 hdmi_edid_extract_3d_present(edid_buf+0x80);
1287 }
1288 break;
1289 case 2:
1290 case 3:
1291 case 4:
1292 for (i = 1; i <= num_og_cea_blocks; i++) {
1293 if (!(i % 2)) {
1294 status = hdmi_common_read_edid_block(i,
1295 edid_buf+0x00);
1296 if (status) {
1297 DEV_ERR("%s: ddc read block(%d)"
1298 "failed: %d\n", __func__, i,
1299 status);
1300 goto error;
1301 }
1302 } else {
1303 status = hdmi_common_read_edid_block(i,
1304 edid_buf+0x80);
1305 if (status) {
1306 DEV_ERR("%s: ddc read block(%d)"
1307 "failed:%d\n", __func__, i,
1308 status);
1309 goto error;
1310 }
1311 }
1312 }
1313 break;
1314 default:
1315 DEV_ERR("%s: ddc read failed, not supported multi-blocks: %d\n",
1316 __func__, num_og_cea_blocks);
1317 status = -EPROTO;
1318 goto error;
1319 }
1320
1321 if (num_og_cea_blocks) {
1322 /* EDID_CEA_EXTENSION_VERSION[0x81]: Offset to CEA extension
1323 * version number - v1,v2,v3 (v1 is seldom, v2 is obsolete,
1324 * v3 most common) */
1325 cea_extension_ver = edid_buf[0x81];
1326 }
1327
1328 /* EDID_VERSION[0x12] - EDID Version */
1329 /* EDID_REVISION[0x13] - EDID Revision */
1330 DEV_INFO("EDID (V=%d.%d, #CEABlocks=%d[V%d], ID=%s, IEEE=%04x, "
1331 "EDID-Ext=0x%02x)\n", edid_buf[0x12], edid_buf[0x13],
1332 num_og_cea_blocks, cea_extension_ver, vendor_id, ieee_reg_id,
1333 edid_buf[0x80]);
1334
1335 hdmi_edid_get_display_mode(edid_buf,
1336 &external_common_state->disp_mode_list, num_og_cea_blocks);
1337
1338 return 0;
1339
1340error:
1341 external_common_state->disp_mode_list.num_of_elements = 1;
1342 external_common_state->disp_mode_list.disp_mode_list[0] =
1343 external_common_state->video_resolution;
1344 return status;
1345}
1346EXPORT_SYMBOL(hdmi_common_read_edid);
1347
1348bool hdmi_common_get_video_format_from_drv_data(struct msm_fb_data_type *mfd)
1349{
1350 uint32 format;
1351 struct fb_var_screeninfo *var = &mfd->fbi->var;
1352 bool changed = TRUE;
1353
1354 if (var->reserved[3]) {
1355 format = var->reserved[3]-1;
1356 } else {
1357 DEV_DBG("detecting resolution from %dx%d use var->reserved[3]"
1358 " to specify mode", mfd->var_xres, mfd->var_yres);
1359 switch (mfd->var_xres) {
1360 default:
1361 case 640:
1362 format = HDMI_VFRMT_640x480p60_4_3;
1363 break;
1364 case 720:
1365 format = (mfd->var_yres == 480)
1366 ? HDMI_VFRMT_720x480p60_16_9
1367 : HDMI_VFRMT_720x576p50_16_9;
1368 break;
1369 case 1280:
1370 format = HDMI_VFRMT_1280x720p60_16_9;
1371 break;
1372 case 1440:
1373 format = (mfd->var_yres == 480)
1374 ? HDMI_VFRMT_1440x480i60_16_9
1375 : HDMI_VFRMT_1440x576i50_16_9;
1376 break;
1377 case 1920:
1378 format = HDMI_VFRMT_1920x1080p60_16_9;
1379 break;
1380 }
1381 }
1382
1383 changed = external_common_state->video_resolution != format;
1384 if (external_common_state->video_resolution != format)
1385 DEV_DBG("switching %s => %s", video_format_2string(
1386 external_common_state->video_resolution),
1387 video_format_2string(format));
1388 else
1389 DEV_DBG("resolution %s", video_format_2string(
1390 external_common_state->video_resolution));
1391 external_common_state->video_resolution = format;
1392 return changed;
1393}
1394EXPORT_SYMBOL(hdmi_common_get_video_format_from_drv_data);
1395
1396const struct hdmi_disp_mode_timing_type *hdmi_common_get_mode(uint32 mode)
1397{
1398 if (mode >= HDMI_VFRMT_MAX)
1399 return NULL;
1400
1401 return &hdmi_common_supported_video_mode_lut[mode];
1402}
1403EXPORT_SYMBOL(hdmi_common_get_mode);
1404
1405const struct hdmi_disp_mode_timing_type *hdmi_common_get_supported_mode(
1406 uint32 mode)
1407{
1408 const struct hdmi_disp_mode_timing_type *ret
1409 = hdmi_common_get_mode(mode);
1410
1411 if (ret == NULL || !ret->supported)
1412 return NULL;
1413 return ret;
1414}
1415EXPORT_SYMBOL(hdmi_common_get_supported_mode);
1416
1417void hdmi_common_init_panel_info(struct msm_panel_info *pinfo)
1418{
1419 const struct hdmi_disp_mode_timing_type *timing =
1420 hdmi_common_get_supported_mode(
1421 external_common_state->video_resolution);
1422
1423 if (timing == NULL)
1424 return;
1425
1426 pinfo->xres = timing->active_h;
1427 pinfo->yres = timing->active_v;
1428 pinfo->clk_rate = timing->pixel_freq*1000;
1429
1430 pinfo->lcdc.h_back_porch = timing->back_porch_h;
1431 pinfo->lcdc.h_front_porch = timing->front_porch_h;
1432 pinfo->lcdc.h_pulse_width = timing->pulse_width_h;
1433 pinfo->lcdc.v_back_porch = timing->back_porch_v;
1434 pinfo->lcdc.v_front_porch = timing->front_porch_v;
1435 pinfo->lcdc.v_pulse_width = timing->pulse_width_v;
1436
1437 pinfo->type = DTV_PANEL;
1438 pinfo->pdest = DISPLAY_2;
1439 pinfo->wait_cycle = 0;
1440 pinfo->bpp = 24;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001441#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
1442 pinfo->fb_num = 2;
1443#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001444 pinfo->fb_num = 1;
Ravishangar Kalyanam898f4bd2011-07-15 18:25:47 -07001445#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001446
1447 /* blk */
1448 pinfo->lcdc.border_clr = 0;
1449 /* blue */
1450 pinfo->lcdc.underflow_clr = 0xff;
1451 pinfo->lcdc.hsync_skew = 0;
1452}
1453EXPORT_SYMBOL(hdmi_common_init_panel_info);
1454#endif