1 #include "rockchip-hdmi.h"
2 #include "../../edid.h"
7 #define EDBG(format, ...)
11 E_HDMI_EDID_SUCCESS = 0,
16 E_HDMI_EDID_UNKOWNDATA,
20 static int hdmi_edid_checksum(unsigned char *buf)
25 for (i = 0; i < HDMI_EDID_BLOCK_SIZE; i++)
31 return E_HDMI_EDID_SUCCESS;
33 return E_HDMI_EDID_CHECKSUM;
37 @Des Parse Detail Timing Descriptor.
38 @Param buf : pointer to DTD data.
39 @Param pvic: VIC of DTD descripted.
41 static int hdmi_edid_parse_dtd(unsigned char *block, struct fb_videomode *mode)
43 mode->xres = H_ACTIVE;
44 mode->yres = V_ACTIVE;
45 mode->pixclock = PIXEL_CLOCK;
46 /* mode->pixclock /= 1000;
47 mode->pixclock = KHZ2PICOS(mode->pixclock);
48 */ mode->right_margin = H_SYNC_OFFSET;
49 mode->left_margin = (H_ACTIVE + H_BLANKING) -
50 (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
51 mode->upper_margin = V_BLANKING - V_SYNC_OFFSET -
53 mode->lower_margin = V_SYNC_OFFSET;
54 mode->hsync_len = H_SYNC_WIDTH;
55 mode->vsync_len = V_SYNC_WIDTH;
57 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
59 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
60 mode->refresh = PIXEL_CLOCK/((H_ACTIVE + H_BLANKING) *
61 (V_ACTIVE + V_BLANKING));
64 mode->upper_margin *= 2;
65 mode->lower_margin *= 2;
67 mode->vmode |= FB_VMODE_INTERLACED;
69 mode->flag = FB_MODE_IS_DETAILED;
71 EDBG("<<<<<<<<Detailed Time>>>>>>>>>\n");
72 EDBG("%d KHz Refresh %d Hz",
73 PIXEL_CLOCK/1000, mode->refresh);
74 EDBG("%d %d %d %d ", H_ACTIVE, H_ACTIVE + H_SYNC_OFFSET,
75 H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH, H_ACTIVE + H_BLANKING);
76 EDBG("%d %d %d %d ", V_ACTIVE, V_ACTIVE + V_SYNC_OFFSET,
77 V_ACTIVE + V_SYNC_OFFSET + V_SYNC_WIDTH, V_ACTIVE + V_BLANKING);
78 EDBG("%sHSync %sVSync\n\n", (HSYNC_POSITIVE) ? "+" : "-",
79 (VSYNC_POSITIVE) ? "+" : "-");
80 return E_HDMI_EDID_SUCCESS;
83 int hdmi_edid_parse_base(unsigned char *buf,
84 int *extend_num, struct hdmi_edid *pedid)
86 int rc = E_HDMI_EDID_SUCCESS;
88 if (buf == NULL || extend_num == NULL)
89 return E_HDMI_EDID_PARAM;
91 *extend_num = buf[0x7e];
93 EDBG("[EDID] extend block num is %d\n", buf[0x7e]);
96 /* Check first 8 byte to ensure it is an edid base block. */
105 pr_err("[EDID] check header error\n");
106 rc = E_HDMI_EDID_HEAD;
111 rc = hdmi_edid_checksum(buf);
112 if (rc != E_HDMI_EDID_SUCCESS) {
113 pr_err("[EDID] base block checksum error\n");
114 rc = E_HDMI_EDID_CHECKSUM;
118 pedid->specs = kzalloc(sizeof(*pedid->specs), GFP_KERNEL);
119 if (pedid->specs == NULL)
120 return E_HDMI_EDID_NOMEMORY;
122 fb_edid_to_monspecs(buf, pedid->specs);
125 if (rc != E_HDMI_EDID_SUCCESS && *extend_num > 4)
128 return E_HDMI_EDID_SUCCESS;
131 /* Parse CEA Short Video Descriptor */
132 static int hdmi_edid_get_cea_svd(unsigned char *buf, struct hdmi_edid *pedid)
136 count = buf[0] & 0x1F;
137 for (i = 0; i < count; i++) {
138 EDBG("[CEA] %02x VID %d native %d\n",
139 buf[1 + i], buf[1 + i] & 0x7f, buf[1 + i] >> 7);
140 vic = buf[1 + i] & 0x7f;
141 hdmi_add_vic(vic, &pedid->modelist);
144 struct list_head *pos;
145 struct display_modelist *modelist;
147 list_for_each(pos, &pedid->modelist) {
148 modelist = list_entry(pos, struct display_modelist, list);
149 pr_info("%s vic %d\n", __FUNCTION__, modelist->vic);
154 /* Parse CEA Short Audio Descriptor */
155 static int hdmi_edid_parse_cea_sad(unsigned char *buf, struct hdmi_edid *pedid)
159 count = buf[0] & 0x1F;
160 pedid->audio = kmalloc((count/3)*sizeof(struct hdmi_audio), GFP_KERNEL);
161 if (pedid->audio == NULL)
162 return E_HDMI_EDID_NOMEMORY;
164 pedid->audio_num = count/3;
165 for (i = 0; i < pedid->audio_num; i++) {
166 pedid->audio[i].type = (buf[1 + i*3] >> 3) & 0x0F;
167 pedid->audio[i].channel = (buf[1 + i*3] & 0x07) + 1;
168 pedid->audio[i].rate = buf[1 + i*3 + 1];
169 if (pedid->audio[i].type == HDMI_AUDIO_LPCM)
170 pedid->audio[i].word_length = buf[1 + i*3 + 2];
172 /* pr_info("type %d channel %d rate %d word length %d\n",
173 pedid->audio[i].type, pedid->audio[i].channel,
174 pedid->audio[i].rate, pedid->audio[i].word_length);
176 return E_HDMI_EDID_SUCCESS;
179 static int hdmi_edid_parse_3dinfo(unsigned char *buf, struct list_head *head)
181 int i, j, len = 0, format_3d, vic_mask;
182 unsigned char offset = 2, vic_2d, structure_3d;
183 struct list_head *pos;
184 struct display_modelist *modelist;
187 len = (buf[1] & 0xe0) >> 5;
188 for (i = 0; i < len; i++) {
190 vic_2d = (buf[offset] == 4) ?
191 98 : (96 - buf[offset]);
192 hdmi_add_vic(vic_2d, head);
200 len += (buf[1] & 0x1F) + 2;
201 if (((buf[0] & 0x60) == 0x40) || ((buf[0] & 0x60) == 0x20)) {
202 format_3d = buf[offset++] << 8;
203 format_3d |= buf[offset++];
204 if ((buf[0] & 0x60) == 0x20) {
207 vic_mask = buf[offset++] << 8;
208 vic_mask |= buf[offset++];
215 for (i = 0; i < 16; i++) {
216 if (vic_mask & (1 << i)) {
218 for (pos = (head)->next; pos != (head);
222 list_entry(pos, struct display_modelist, list);
223 modelist->format_3d = format_3d;
229 while (offset < len) {
230 vic_2d = (buf[offset] & 0xF0) >> 4;
231 structure_3d = (buf[offset++] & 0x0F);
233 for (pos = (head)->next; pos != (head);
238 list_entry(pos, struct display_modelist, list);
239 modelist->format_3d |=
241 if (structure_3d & 0x08)
242 modelist->detail_3d =
243 (buf[offset++] & 0xF0) >> 4;
248 /* mandatory formats */
249 for (pos = (head)->next; pos != (head); pos = pos->next) {
250 modelist = list_entry(pos,
251 struct display_modelist,
253 if (modelist->vic == HDMI_1920X1080P_24HZ ||
254 modelist->vic == HDMI_1280X720P_60HZ ||
255 modelist->vic == HDMI_1280X720P_50HZ) {
256 modelist->format_3d |=
257 (1 << HDMI_3D_FRAME_PACKING) |
258 (1 << HDMI_3D_TOP_BOOTOM);
259 } else if (modelist->vic == HDMI_1920X1080I_60HZ ||
260 modelist->vic == HDMI_1920X1080I_50HZ) {
261 modelist->format_3d |=
262 (1 << HDMI_3D_SIDE_BY_SIDE_HALF);
269 static int hdmi_edmi_parse_vsdb(unsigned char *buf, struct hdmi_edid *pedid,
270 int cur_offset, int IEEEOUI)
272 int count, buf_offset;
274 count = buf[cur_offset] & 0x1F;
277 pedid->sink_hdmi = 1;
278 pedid->cecaddress = buf[cur_offset + 5];
279 pedid->cecaddress |= buf[cur_offset + 4] << 8;
280 EDBG("[CEA] CEC Physical addres is 0x%08x.\n",
283 pedid->deepcolor = (buf[cur_offset + 6] >> 3) & 0x0F;
285 pedid->maxtmdsclock = buf[cur_offset + 7] * 5000000;
286 EDBG("[CEA] maxtmdsclock is %d.\n",
287 pedid->maxtmdsclock);
290 pedid->fields_present = buf[cur_offset + 8];
291 EDBG("[CEA] fields_present is 0x%02x.\n",
292 pedid->fields_present);
294 buf_offset = cur_offset + 9;
295 if (pedid->fields_present & 0x80) {
296 pedid->video_latency = buf[buf_offset++];
297 pedid->audio_latency = buf[buf_offset++];
299 if (pedid->fields_present & 0x40) {
300 pedid->interlaced_video_latency = buf[buf_offset++];
301 pedid->interlaced_audio_latency = buf[buf_offset++];
303 if (pedid->fields_present & 0x20) {
304 hdmi_edid_parse_3dinfo(buf + buf_offset,
309 pedid->sink_hdmi = 1;
310 pedid->hf_vsdb_version = buf[cur_offset + 4];
311 switch (pedid->hf_vsdb_version) {
312 case 1:/*compliant with HDMI Specification 2.0*/
313 pedid->maxtmdsclock =
314 buf[cur_offset + 5] * 5000000;
315 EDBG("[CEA] maxtmdsclock is %d.\n",
316 pedid->maxtmdsclock);
317 pedid->scdc_present = buf[cur_offset+6] >> 7;
319 (buf[cur_offset+6]&0x40) >> 6;
320 pedid->lte_340mcsc_scramble =
321 (buf[cur_offset+6]&0x08) >> 3;
322 pedid->independent_view =
323 (buf[cur_offset+6]&0x04) >> 2;
325 (buf[cur_offset+6]&0x02) >> 1;
326 pedid->osd_disparity_3d =
327 buf[cur_offset+6] & 0x01;
328 pedid->deepcolor_420 =
329 (buf[cur_offset+7] & 0x7) << 1;
332 pr_info("hf_vsdb_version = %d\n",
333 pedid->hf_vsdb_version);
338 pr_info("IEEOUT = 0x%x\n", IEEEOUI);
344 static void hdmi_edid_parse_yuv420cmdb(unsigned char *buf, int count,
345 struct list_head *head)
347 struct list_head *pos;
348 struct display_modelist *modelist;
349 int i, j, yuv420_mask, vic;
351 for (i = 0; i < count - 1; i++) {
352 EDBG("vic which support yuv420 mode is %x\n", buf[i]);
353 yuv420_mask |= buf[i] << (8 * i);
355 for (i = 0; i < 32; i++) {
356 if (yuv420_mask & (1 << i)) {
358 for (pos = head->next; pos != (head); pos = pos->next) {
361 list_entry(pos, struct display_modelist, list);
362 vic = modelist->vic |
364 hdmi_add_vic(vic, head);
372 /* Parse CEA 861 Serial Extension. */
373 static int hdmi_edid_parse_extensions_cea(unsigned char *buf,
374 struct hdmi_edid *pedid)
376 unsigned int ddc_offset, native_dtd_num, cur_offset = 4;
377 unsigned int tag, IEEEOUI = 0, count, i;
378 /* unsigned int underscan_support, baseaudio_support; */
381 return E_HDMI_EDID_PARAM;
383 /* Check ces extension version */
385 pr_err("[CEA] error version.\n");
386 return E_HDMI_EDID_VERSION;
390 /* underscan_support = (buf[3] >> 7) & 0x01;
391 */ pedid->baseaudio_support = (buf[3] >> 6) & 0x01;
392 pedid->ycbcr444 = (buf[3] >> 5) & 0x01;
393 pedid->ycbcr422 = (buf[3] >> 4) & 0x01;
394 native_dtd_num = buf[3] & 0x0F;
395 /* EDBG("[CEA] ddc_offset %d underscan_support %d
396 baseaudio_support %d yuv_support %d
397 native_dtd_num %d\n",
398 ddc_offset, underscan_support, baseaudio_support,
399 yuv_support, native_dtd_num);
400 */ /* Parse data block */
401 while (cur_offset < ddc_offset) {
402 tag = buf[cur_offset] >> 5;
403 count = buf[cur_offset] & 0x1F;
405 case 0x02: /* Video Data Block */
406 EDBG("[CEA] Video Data Block.\n");
407 hdmi_edid_get_cea_svd(buf + cur_offset, pedid);
409 case 0x01: /* Audio Data Block */
410 EDBG("[CEA] Audio Data Block.\n");
411 hdmi_edid_parse_cea_sad(buf + cur_offset, pedid);
413 case 0x04: /* Speaker Allocation Data Block */
414 EDBG("[CEA] Speaker Allocatio Data Block.\n");
416 case 0x03: /* Vendor Specific Data Block */
417 EDBG("[CEA] Vendor Specific Data Block.\n");
419 IEEEOUI = buf[cur_offset + 3];
421 IEEEOUI += buf[cur_offset + 2];
423 IEEEOUI += buf[cur_offset + 1];
424 EDBG("[CEA] IEEEOUI is 0x%08x.\n", IEEEOUI);
426 hdmi_edmi_parse_vsdb(buf, pedid,
427 cur_offset, IEEEOUI);
429 case 0x05: /* VESA DTC Data Block */
430 EDBG("[CEA] VESA DTC Data Block.\n");
432 case 0x07: /* Use Extended Tag */
433 EDBG("[CEA] Use Extended Tag Data Block %02x.\n",
434 buf[cur_offset + 1]);
435 switch (buf[cur_offset + 1]) {
437 EDBG("[CEA] Video Capability Data Block\n");
438 EDBG("value is %02x\n", buf[cur_offset + 2]);
441 EDBG("[CEA] Colorimetry Data Block\n");
442 EDBG("value is %02x\n", buf[cur_offset + 2]);
443 pedid->colorimetry = buf[cur_offset + 2];
446 EDBG("[CEA] YCBCR 4:2:0 Video Data Block\n");
447 for (i = 0; i < count - 1; i++) {
449 buf[cur_offset + 2 + i]);
451 IEEEOUI = buf[cur_offset + 2 + i] |
453 hdmi_add_vic(IEEEOUI,
458 EDBG("[CEA] YCBCR 4:2:0 Capability Map Data\n");
459 hdmi_edid_parse_yuv420cmdb(&buf[cur_offset+2],
467 pr_err("[CEA] unkowned data block tag.\n");
470 cur_offset += (buf[cur_offset] & 0x1F) + 1;
475 struct fb_videomode *vmode =
476 kmalloc(sizeof(struct fb_videomode), GFP_KERNEL);
479 return E_HDMI_EDID_SUCCESS;
480 while (ddc_offset < HDMI_EDID_BLOCK_SIZE - 2) {
481 if (!buf[ddc_offset] && !buf[ddc_offset + 1])
483 memset(vmode, 0, sizeof(struct fb_videomode));
484 hdmi_edid_parse_dtd(buf + ddc_offset, vmode);
485 hdmi_add_vic(hdmi_videomode_to_vic(vmode), &pedid->modelist);
491 return E_HDMI_EDID_SUCCESS;
494 int hdmi_edid_parse_extensions(unsigned char *buf, struct hdmi_edid *pedid)
498 if (buf == NULL || pedid == NULL)
499 return E_HDMI_EDID_PARAM;
502 rc = hdmi_edid_checksum(buf);
503 if (rc != E_HDMI_EDID_SUCCESS) {
504 pr_err("[EDID] extensions block checksum error\n");
505 return E_HDMI_EDID_CHECKSUM;
510 EDBG("[EDID-EXTEND] Iextensions block map.\n");
513 EDBG("[EDID-EXTEND] CEA 861 Series Extension.\n");
514 hdmi_edid_parse_extensions_cea(buf, pedid);
517 EDBG("[EDID-EXTEND] Video Timing Block Extension.\n");
520 EDBG("[EDID-EXTEND] Display Information Extension.\n");
523 EDBG("[EDID-EXTEND] Localized String Extension.\n");
526 EDBG("[EDID-EXTEND] Digital Packet Video Link Extension.\n");
529 pr_err("[EDID-EXTEND] Unkowned Extension.\n");
530 return E_HDMI_EDID_UNKOWNDATA;
533 return E_HDMI_EDID_SUCCESS;