aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cdv/drv/psb_intel_hdmi.c
blob: 676fc2a756378033ddb9747d315bfb3be4238639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
/*
 * Copyright © 2011 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *	jim liu <jim.liu@intel.com>
 */

#include <drm/drmP.h>
#include <drm/drm.h>
#include <drm/drm_crtc.h>
#include <drm/drm_edid.h>
#include "psb_intel_drv.h"
#include "psb_drv.h"
#include "psb_intel_reg.h"
#include "psb_intel_hdmi_reg.h"
#include "psb_intel_hdmi_edid.h"
#include "psb_intel_hdmi.h"
#include <linux/pm_runtime.h>

static void mdfld_hdmi_mode_set(struct drm_encoder *encoder,
				struct drm_display_mode *mode,
				struct drm_display_mode *adjusted_mode)
{
	struct drm_device *dev = encoder->dev;
	struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
	struct mid_intel_hdmi_priv *hdmi_priv = output->dev_priv;
	u32 hdmib;
	struct drm_crtc *crtc = encoder->crtc;
	struct psb_intel_crtc *intel_crtc = to_psb_intel_crtc(crtc);
	PSB_DEBUG_ENTRY("\n");

	hdmib = (2 << 10);

	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
		hdmib |= SDVO_VSYNC_ACTIVE_HIGH;
	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
		hdmib |= SDVO_HSYNC_ACTIVE_HIGH;

	if (intel_crtc->pipe == 1)
		hdmib |= HDMIB_PIPE_B_SELECT;

	if (hdmi_priv->has_hdmi_audio) {
		hdmib |= HDMI_AUDIO_ENABLE;
		hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
	}
		
	REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
	REG_READ(hdmi_priv->hdmi_reg);
}

static bool mdfld_hdmi_mode_fixup(struct drm_encoder *encoder,
				  struct drm_display_mode *mode,
				  struct drm_display_mode *adjusted_mode)
{

       return true;
}


static void mdfld_hdmi_dpms(struct drm_encoder *encoder, int mode)
{
	struct drm_device *dev = encoder->dev;
	struct psb_intel_output *output = enc_to_psb_intel_output(encoder);
	struct mid_intel_hdmi_priv *hdmi_priv = output->dev_priv;
	u32 hdmib;

	PSB_DEBUG_ENTRY("%s \n", mode == DRM_MODE_DPMS_ON ? "on" : "off");

	hdmib = REG_READ(hdmi_priv->hdmi_reg);

	if (mode != DRM_MODE_DPMS_ON) {
		REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
	} else {
		REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
	}
	REG_READ(hdmi_priv->hdmi_reg);
}

static void mdfld_hdmi_save(struct drm_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct psb_intel_output *output = to_psb_intel_output(connector);
	struct mid_intel_hdmi_priv *hdmi_priv = output->dev_priv;

	PSB_DEBUG_ENTRY("\n");

	hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
}

static void mdfld_hdmi_restore(struct drm_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct psb_intel_output *output = to_psb_intel_output(connector);
	struct mid_intel_hdmi_priv *hdmi_priv = output->dev_priv;

	PSB_DEBUG_ENTRY("\n");

	REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
	REG_READ(hdmi_priv->hdmi_reg);
}

#if 0

/* HDMI DIP related stuff */
static int mdfld_hdmi_get_cached_edid_block(struct drm_connector *connector, uint32_t num_block, uint8_t *edid_block, uint32_t size)
{
    struct drm_display_info *displayinfo = &(connector->display_info);
    if (num_block >= MAX_EDID_BLOCKS)
    {
	DRM_ERROR("mdfld_hdmi_get_cached_edid_block() - Invalid EDID block\n");
        return 0; 
    }
    edid_block = &displayinfo->raw_edid[EDID_BLOCK_SIZE*num_block];
    return 1;
}

/////////////////////////////////////////////////////////////////////////
//    INTHDMIENCODER_CreateEELDPacket():
//    This function parses v1.3 base EDID and CEA-861b EDID Timing Extension
//    Version3 and creates EELD (Enhanced EDID Like Data) packet. This EELD data contains
//    audio configuration information and other details read EDID.This can also contain Vendor specific Data
//
/////////////////////////////////////////////////////////////////////////
static int mdfld_hdmi_create_eeld_packet(struct drm_connector *connector)
{
    struct psb_intel_output *output = to_psb_intel_output(connector);
    struct mid_intel_hdmi_priv *hdmi_priv = output->dev_priv;
    uint8_t ucEdidBlock[128];
    hdmi_eeld_t *pEEld                = NULL;
    baseedid_1_x_t *pEdid        = NULL;
    ce_edid_t *pCeEdid        = NULL;
    int dwNumOfBytes        = 0;
    int sizeOfCEADataBlock    = 0;
    uint8_t * pDataBlock        = NULL;
    edid_dtd_timing_t *pDTD    = NULL;
    uint8_t *pData            = NULL;
    uint8_t ucDataBlockTag    = 0;
    cea_861b_adb_t *pADB        = NULL;
    uint8_t i                    = 0;
    uint8_t j                    = 0;
    uint8_t * pSADBlocks = NULL;
    uint8_t * pCurrentSADBlocks = NULL;
    uint32_t ulNumSADBytes = 0;
    //vsdb_byte6_to_byte8_t *pVSDB = NULL;
    uint32_t ulIndex = 0;
    //uint8_t b48kHzCADPresent = false;

    pEEld = (hdmi_eeld_t *) &hdmi_priv->eeld;

    // Fill Version info
    pEEld->cea_edid_rev_id = HDMI_EELD_CEA_EDID_VERSION;
    pEEld->eld_ver = HDMI_EELD_VERSION;

    // Fill BaseLine ELD length
    // This is 80 bytes as per EELD proposal
    pEEld->baseline_eld_length = HDMI_EELD_BASELINE_DATA_LENGTH;

    //Zero out EDID block buffer
    memset(ucEdidBlock, 0, sizeof(ucEdidBlock));

    // Get Extn EDID
    if(!mdfld_hdmi_get_cached_edid_block(connector, 1, ucEdidBlock, EDID_BLOCK_SIZE))
    {
        return 0;
    }    

    pCeEdid = (ce_edid_t *) ucEdidBlock;

    //allocate memory (48 bytes) for SAD Blocks buffer
    pSADBlocks = kcalloc(1, 48, GFP_KERNEL);

    if(pSADBlocks == NULL)
    {
	DRM_ERROR("mdfld_hdmi_create_eld_packaet() - Failed to allocate mem for pSADBlocks\n");
        return 0;
    }

    pCurrentSADBlocks = pSADBlocks;

    // Now pull out data from CEA Extension EDID
    // If Offset <= 4, we will not have CEA DataBlocks
    if(pCeEdid->ucDTDOffset > CEA_EDID_HEADER_SZIE)
    {
        sizeOfCEADataBlock = pCeEdid->ucDTDOffset - CEA_EDID_HEADER_SZIE;

        pDataBlock = (uint8_t *)pCeEdid;

        // skip header (first 4 bytes) in CEA EDID Timing Extension
        // and set pointer to start of DataBlocks collection
        pDataBlock += CEA_EDID_HEADER_SZIE;

        // General Format of CEA Data Block Collection
        // -----------+--------------------+-----------------------------------------+
        //            |Byte#   |bits5-7    |       bits 0-4                          |
        // -----------|--------------------+-----------------------------------------+
        //            |  1     | Video Tag |Length = total #of video bytes following |
        //            |        |    Code   |this byte (L1)                           |
        //            |--------------------+-----------------------------------------+
        //  Video     |  2     | CEA Short Video Descriptor 1                        |
        //  Data      |--------+-----------------------------------------------------|
        //  Block     |  3     | CEA Short Video Descriptor 2                        |
        //            |--------+-----------------------------------------------------|
        //            | ...    | ...                                                 |
        //            |--------------------------------------------------------------+
        //            | 1+L1   | CEA Short Video Descriptor L1                       |
        // -----------+--------------------+-----------------------------------------+
        //            | 2+L1   | Audio Tag |Length = total #of audio bytes following |
        //            |        |    Code   |this byte (L2)                           |
        //            |--------------------+-----------------------------------------+
        //  Audio     | 3+L1   |                                                     |
        //  Data      |--------+                                                     |
        //  Block     | 4+L1   | CEA Short Audio Descriptor 1                        |
        //            |--------+                                                     |
        //            | 5+L1   |                                                     |
        //            |--------------------------------------------------------------+
        //            | ...    |                                                     |
        //            |        |                                                     |
        //            |        |                                                     |
        //            | ...    |                                                     |
        //            |---------------------------------------------------------------
        //            |L1+L2   |                                                     |
        //            |--------|                                                     |
        //            |1+L1+L2 | CEA Short Audio Descriptor L2/3                     |
        //            |--------|                                                     |
        //            |2+L1+L2 |                                                     |
        // -----------+--------------------------------------------------------------+
        //            |3+L1+L2 |  Speaker  |Length = total #of SA bytes following    |
        //            |        | Tag Code  |this byte (L1)                           |
        //  Speaker   |--------------------------------------------------------------+
        //  Allocation|4+L1+L2 |                                                     |
        //  Data      |--------|                                                     |
        //  Block     |5+L1+L2 | Speaker Allocation Data Block Payload(3 bytes)      |
        //            |--------|                                                     |
        //            |6+L1+L2 |                                                     |
        // -----------+--------------------------------------------------------------+
        //            |7+L1+L2 | VSDB  Tag |Length = total #of VSDB bytes following  |
        //            |        |    Code   |this byte (L1)                           |
        //  Vendor    |--------------------------------------------------------------+
        //  Specific  |8+L1+L2 |                                                     |
        //  Data      |--------|                                                     |
        //  Block     |9+L1+L2 | 24-bit IEEE Registration Identifier (LSB first)     |
        //            |--------|                                                     |
        //            |10+L1+L2|                                                     |
        //            |--------------------------------------------------------------+
        //            | ...    | Vendor Specific Data block Payload                  |
        // -----------+--------------------------------------------------------------+

        while(sizeOfCEADataBlock > 0)
        {
            // Get the Size of CEA DataBlock in bytes and TAG
            dwNumOfBytes = *pDataBlock & CEA_DATABLOCK_LENGTH_MASK;
            ucDataBlockTag = (*pDataBlock & CEA_DATABLOCK_TAG_MASK) >> 5;

            switch(ucDataBlockTag)
            {
                case CEA_AUDIO_DATABLOCK:
                    // move beyond tag/length byte
                    ++pDataBlock;
                    for (i = 0; i < (dwNumOfBytes / 3); ++i, pDataBlock += 3)
                    {
                        pADB = (cea_861b_adb_t*)pDataBlock;
                        switch(pADB->audio_format_code)
                        {
                            // uncompressed audio (Linear PCM)
                            case AUDIO_LPCM:
                                memcpy(&(hdmi_priv->lpcm_sad),pDataBlock,3);
                                //save these blocks
                                memcpy(pCurrentSADBlocks, pDataBlock, 3);
                                // move pointer in SAD blocks buffer
                                pCurrentSADBlocks += 3;
                                // update SADC field
                                pEEld->sadc += 1;
                                break;
                            // compressed audio
                            case AUDIO_AC3:
                            case AUDIO_MPEG1:
                            case AUDIO_MP3:
                            case AUDIO_MPEG2:
                            case AUDIO_AAC:
                            case AUDIO_DTS:
                            case AUDIO_ATRAC:
                            case AUDIO_OBA:
                            case AUDIO_DOLBY_DIGITAL:
                            case AUDIO_DTS_HD:
                            case AUDIO_MAT:
                            case AUDIO_DST:
                            case AUDIO_WMA_PRO:
                                //save these blocks
                                memcpy(pCurrentSADBlocks, pDataBlock, 3);
                                // move pointer in SAD blocks buffer
                                pCurrentSADBlocks += 3;
                                // update SADC field
                                pEEld->sadc += 1;
                                break;
                        }
                    }
                    break;

                case CEA_VENDOR_DATABLOCK:
                    // audio wants data from 6th byte of VSDB onwards
                    //Sighting 94842: 

                    // | Byte # |    bits[7-0]                                              |
                    // |--------------------------------------------------------------------|
                    // | 1-3    |24-bit IEEE Registration Identifier (0x000C03)             |
                    // |--------------------------------------------------------------------|
                    // | 4-5    |       Source Physical Address                             |
                    // |--------------------------------------------------------------------|
                    // | 6      |SupportsAI|DC48bit|DC36bit|Dc30bit|DCY444|Rsvd|Rsvd|DVIDual|
                    // |--------------------------------------------------------------------|
                    // | 7      |   Max TMDS clock                                          |
                    // |--------------------------------------------------------------------|
                    // | 8      |Latency_Field |I_Latency_Field| Reserved bits 5-0          |
                    // |        |   _Present   |  _Present     |                            |
                    // |--------------------------------------------------------------------|
                    // | 9      |               Video Latency                               |
                    // |--------------------------------------------------------------------|
                    // | 10     |               Audio Latency                               |
                    // |--------------------------------------------------------------------|
                    // | 11     |            Interlaced Video Latency                       |
                    // |--------------------------------------------------------------------|
                    // | 12     |            Interlaced Audio Latency                       |
                    // |--------------------------------------------------------------------|

                    ++pDataBlock;
                    // move pointer to next CEA Datablock
                    pDataBlock += dwNumOfBytes;
                    break;                 

                case CEA_SPEAKER_DATABLOCK:
                    pEEld->speaker_allocation_block = *(++pDataBlock);
                    // move pointer to next CEA Datablock
                    pDataBlock += dwNumOfBytes;
                    break;                       

                default:
                    // Move pointer to next CEA DataBlock
                    pDataBlock += (dwNumOfBytes + 1);
            }
            // Decrement size of CEA DataBlock
            sizeOfCEADataBlock -= (dwNumOfBytes + 1);
        }    
    }

    //Copy all the saved SAD blocks at the end of ELD
    //SAD blocks should be written after the Monitor name and VSDB.
    //See ELD definition in iHDMI.h
    ulNumSADBytes = (pEEld->sadc) * 3; //Size of each SAD block is 3 bytes

    //DCN 460119: Audio does not play on displays which do not provide SAB in EDID.
    //Solution: Graphics driver should create a default SAB in ELD with front left and front right
    //speakers enabled if the display supports basic audio. 
    pDataBlock = (uint8_t *)pCeEdid;
    if((*(pDataBlock + HDMI_CEA_EXTENSION_BLOCK_BYTE_3) & HDMI_BASIC_AUDIO_SUPPORTED) && (pEEld->speaker_allocation_block == 0)) 
    {
        pEEld->flr = 1;
    }
    //End of DCN 460119

    // zero out local buffers
    memset(ucEdidBlock, 0, sizeof(ucEdidBlock));

    // Get base EDID
    if(!mdfld_hdmi_get_cached_edid_block(connector, 0, ucEdidBlock, EDID_BLOCK_SIZE))
    {
        return 0;
    }

    pEdid = (baseedid_1_x_t*) ucEdidBlock;
    pDTD = &pEdid->DTD[1];

    //Update the Manufacturer ID and Product Code here
    memcpy(pEEld->manufacturer_id,pEdid->ManufacturerID,2);
    memcpy(pEEld->product_id,pEdid->ProductID,2);

    // Now Fill the monitor string name
    // Search through DTD blocks, looking for monitor name
    for (i = 0; i < MAX_BASEEDID_DTD_BLOCKS - 1; ++i, ++pDTD)
    {
        // Set a uint8_t pointer to DTD data
        pData = (uint8_t *)pDTD;

        // Check the Flag (the first two bytes) to determine
        // if this block is used as descriptor
        if (pData[0] == 0x00 && pData[1] == 0x00)
        {
            // And now check Data Type Tag within this descriptor
            // Tag = 0xFC, then monitor name stored as ASCII
            if (pData[3] == 0xFC)
            {
                ulIndex = 0;
                // Copy monitor name
                for (j = 0; (j < 13) && (pData[j+5] != 0x0A); ++j)
                {
                    pEEld->mn_sand_sads[ulIndex] = pData[j+5];
                    ulIndex++;
                }
                pEEld->mnl = j;
                break;
            }
        }
    }

    //Check if number of SAD Bytes > 0 and for size within limits of allowed Base line Data size as per EELD spec
    if((ulNumSADBytes > 0) && (ulNumSADBytes <= 64))
    {
        //Copy the SADs immediately after the Monitor Name String
        memcpy(&pEEld->mn_sand_sads[j], pSADBlocks, ulNumSADBytes);
    }


    // Header = 4, Baseline Data = 60 and Vendor (INTEL) specific = 2
    // 4 + 60 + 2 = 66
    hdmi_priv->hdmi_eeld_size = HDMI_EELD_SIZE;
    
    //free the buffer allocated for SAD blocks
    kfree(pSADBlocks);
    pSADBlocks = NULL;
    pCurrentSADBlocks = NULL;
    return 1;
}

#endif

static enum drm_connector_status mdfld_hdmi_detect(struct drm_connector *connector, bool force)
{
	struct psb_intel_output *psb_intel_output = to_psb_intel_output(connector);
	struct mid_intel_hdmi_priv *hdmi_priv = psb_intel_output->dev_priv;
	struct edid *edid = NULL;
	enum drm_connector_status status = connector_status_disconnected;

	PSB_DEBUG_ENTRY("\n");

	edid = drm_get_edid(&psb_intel_output->base,
			 psb_intel_output->hdmi_i2c_adapter);

	hdmi_priv->has_hdmi_sink = false;
	hdmi_priv->has_hdmi_audio = false;
	if (edid) {
		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
			status = connector_status_connected;
			hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
			hdmi_priv->has_hdmi_audio = drm_detect_monitor_audio(edid);
		}

		psb_intel_output->base.display_info.raw_edid = NULL;
		kfree(edid);
	}

	return status;
}

static int mdfld_hdmi_set_property(struct drm_connector *connector,
				       struct drm_property *property,
				       uint64_t value)
{
	struct drm_encoder *pEncoder = connector->encoder;

	PSB_DEBUG_ENTRY("connector info, type = %d, type_id=%d, base=0x%p, base.id=0x%x. \n", connector->connector_type, connector->connector_type_id, &connector->base, connector->base.id);
	PSB_DEBUG_ENTRY("encoder info, base.id=%d, encoder_type=%d, dev=0x%p, base=0x%p, possible_clones=0x%x. \n", pEncoder->base.id, pEncoder->encoder_type, pEncoder->dev, &pEncoder->base, pEncoder->possible_clones);
	PSB_DEBUG_ENTRY("encoder info, possible_crtcs=0x%x, crtc=0x%p.  \n", pEncoder->possible_crtcs, pEncoder->crtc);

	if (!strcmp(property->name, "scaling mode") && pEncoder) {
		PSB_DEBUG_ENTRY("scaling mode \n");
	} else if (!strcmp(property->name, "backlight") && pEncoder) {
		PSB_DEBUG_ENTRY("backlight \n");
	} else if (!strcmp(property->name, "DPMS") && pEncoder) {
		PSB_DEBUG_ENTRY("DPMS \n");
	}

	if (!strcmp(property->name, "scaling mode") && pEncoder) {
		struct psb_intel_crtc *pPsbCrtc = to_psb_intel_crtc(pEncoder->crtc);
		bool bTransitionFromToCentered;
		uint64_t curValue;

		if (!pPsbCrtc)
			goto set_prop_error;

		switch (value) {
		case DRM_MODE_SCALE_FULLSCREEN:
			break;
		case DRM_MODE_SCALE_NO_SCALE:
			break;
		case DRM_MODE_SCALE_ASPECT:
			break;
		default:
			goto set_prop_error;
		}

		if (drm_connector_property_get_value(connector, property, &curValue))
			goto set_prop_error;

		if (curValue == value)
			goto set_prop_done;

		if (drm_connector_property_set_value(connector, property, value))
			goto set_prop_error;

		bTransitionFromToCentered = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
			(value == DRM_MODE_SCALE_NO_SCALE);

		if (pPsbCrtc->saved_mode.hdisplay != 0 &&
		    pPsbCrtc->saved_mode.vdisplay != 0) {
			if (bTransitionFromToCentered) {
				if (!drm_crtc_helper_set_mode(pEncoder->crtc, &pPsbCrtc->saved_mode,
					    pEncoder->crtc->x, pEncoder->crtc->y, pEncoder->crtc->fb))
					goto set_prop_error;
			} else {
				struct drm_encoder_helper_funcs *pEncHFuncs  = pEncoder->helper_private;
				pEncHFuncs->mode_set(pEncoder, &pPsbCrtc->saved_mode,
						     &pPsbCrtc->saved_adjusted_mode);
			}
		}
	}
set_prop_done:
    return 0;
set_prop_error:
    return -1;
}

/**
 * Return the list of HDMI DDC modes if available.
 */
static int mdfld_hdmi_get_modes(struct drm_connector *connector)
{
	struct psb_intel_output *psb_intel_output = to_psb_intel_output(connector);
	struct edid *edid = NULL;
	int ret = 0;

	PSB_DEBUG_ENTRY("\n");

	edid = drm_get_edid(&psb_intel_output->base,
			 psb_intel_output->hdmi_i2c_adapter);
	if (edid) {
		drm_mode_connector_update_edid_property(&psb_intel_output->
							base, edid);
		ret = drm_add_edid_modes(&psb_intel_output->base, edid);
		kfree(edid);
	}

	return ret;
}

static int mdfld_hdmi_mode_valid(struct drm_connector *connector,
				 struct drm_display_mode *mode)
{

	PSB_DEBUG_ENTRY("display info. hdisplay = %d, vdisplay = %d. \n", mode->hdisplay, mode->vdisplay);

	if (mode->clock > 165000)
		return MODE_CLOCK_HIGH;
	if (mode->clock < 20000)
		return MODE_CLOCK_HIGH;

	/* just in case */
	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
		return MODE_NO_DBLESCAN;

	/* just in case */
	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
		return MODE_NO_INTERLACE;

	return MODE_OK;
}

static const struct drm_encoder_helper_funcs mdfld_hdmi_helper_funcs = {
	.dpms = mdfld_hdmi_dpms,
	.mode_fixup = mdfld_hdmi_mode_fixup,
	.prepare = psb_intel_encoder_prepare,
	.mode_set = mdfld_hdmi_mode_set,
	.commit = psb_intel_encoder_commit,
};

static const struct drm_connector_helper_funcs mdfld_hdmi_connector_helper_funcs = {
	.get_modes = mdfld_hdmi_get_modes,
	.mode_valid = mdfld_hdmi_mode_valid,
	.best_encoder = psb_intel_best_encoder,
};

static const struct drm_connector_funcs mdfld_hdmi_connector_funcs = {
	.dpms = drm_helper_connector_dpms,
	.save = mdfld_hdmi_save,
	.restore = mdfld_hdmi_restore,
	.detect = mdfld_hdmi_detect,
	.fill_modes = drm_helper_probe_single_connector_modes,
	.set_property = mdfld_hdmi_set_property,
	.destroy = psb_intel_lvds_destroy,
};

void mdfld_hdmi_init(struct drm_device *dev, struct psb_intel_mode_device *mode_dev, int reg)
{
	struct psb_intel_output *psb_intel_output;
	struct drm_connector *connector;
	struct drm_encoder *encoder;
	struct mid_intel_hdmi_priv *hdmi_priv;
	int ddc_bus;

	PSB_DEBUG_ENTRY("\n");

	psb_intel_output = kzalloc(sizeof(struct psb_intel_output) +
			       sizeof(struct mid_intel_hdmi_priv), GFP_KERNEL);
	if (!psb_intel_output)
		return;

	hdmi_priv = (struct mid_intel_hdmi_priv *)(psb_intel_output + 1);
	psb_intel_output->mode_dev = mode_dev;
	connector = &psb_intel_output->base;
	encoder = &psb_intel_output->enc;
	drm_connector_init(dev, &psb_intel_output->base,
			   &mdfld_hdmi_connector_funcs,
			   DRM_MODE_CONNECTOR_DVID);

	drm_encoder_init(dev, &psb_intel_output->enc, &psb_intel_lvds_enc_funcs,
			 DRM_MODE_ENCODER_TMDS);

	drm_mode_connector_attach_encoder(&psb_intel_output->base,
					  &psb_intel_output->enc);
	psb_intel_output->type = INTEL_OUTPUT_HDMI;
	hdmi_priv->hdmi_reg = reg;
	hdmi_priv->has_hdmi_sink = false;
	psb_intel_output->dev_priv = hdmi_priv;

	drm_encoder_helper_add(encoder, &mdfld_hdmi_helper_funcs);
	drm_connector_helper_add(connector,
				 &mdfld_hdmi_connector_helper_funcs);
	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
	connector->interlace_allowed = false;
	connector->doublescan_allowed = false;

	connector->polled = DRM_CONNECTOR_POLL_HPD;

	drm_connector_attach_property(connector, dev->mode_config.scaling_mode_property, DRM_MODE_SCALE_FULLSCREEN);

	switch (reg) {
	case SDVOB:
		ddc_bus = GPIOE;
		break;
	case SDVOC:
		ddc_bus = GPIOD;
		break;
	default:
		DRM_ERROR("unknown reg 0x%x for HDMI\n", reg);
		goto failed_ddc;
		break;
	}

	psb_intel_output->ddc_bus = psb_intel_i2c_create(dev,
						ddc_bus, (reg == SDVOB) ? "HDMIB":"HDMIC");

	if (!psb_intel_output->ddc_bus) {
		DRM_ERROR("No ddc adapter available!\n");
		goto failed_ddc;
	}
	psb_intel_output->hdmi_i2c_adapter = &(psb_intel_output->ddc_bus->adapter);

	hdmi_priv->is_hdcp_supported = true;
	hdmi_priv->dev = dev; 
	drm_sysfs_connector_add(connector);
	return;

failed_ddc:
	drm_encoder_cleanup(&psb_intel_output->enc);
	drm_connector_cleanup(&psb_intel_output->base);
	kfree(psb_intel_output);
}