aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/hdmi/Sii8338/sii_hal_linux_i2c.c
blob: 4691b7f8eac632c0453ac0826f0f8a00e1e80eb2 (plain) (blame)
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
#define SII_HAL_LINUX_I2C_C
#include <linux/i2c.h>
#include "sii_hal.h"
#include "hdmi_cust.h"
#include "sii_hal_priv.h"
#include "si_mhl_tx_api.h"

#include <mach/hardware.h>
/* #include <linux/mx51_pins.h> */
#include <mach/mt_gpio.h>
#include <cust_gpio_usage.h>
#include <cust_eint.h>


/******************************software I2C demo code**********************************/
/* ------------------------------------------------------------------------------ */
#if 0
/******************************software I2C demo code**********************************/
/* ------------------------------------------------------------------------------ */
#define I2C_DELAY_VALUE	3
/* ------------------------------------------------------------------------------ */
/* Local macros to simplify bit operations */
/* ------------------------------------------------------------------------------ */

#define GPIO_SDA	GPIO_HDMI_I2C_SDA
#define GPIO_SCL	GPIO_HDMI_I2C_SCL

uint8_t GET_SDA(void)
{
	unsigned int a;
	/* mt_set_gpio_dir(GPIO_SDA, GPIO_DIR_IN); */
	a = mt_get_gpio_in(GPIO_SDA);
	return a;
}

uint8_t GET_SCL(void)
{
	unsigned int a;

	/* mt_set_gpio_dir(GPIO_SCL, GPIO_DIR_IN); */
	a = mt_get_gpio_in(GPIO_SCL);
	return a;
}

void SET_SDA(void)
{
	mt_set_gpio_out(GPIO_SDA, GPIO_OUT_ONE);
	udelay(I2C_DELAY_VALUE);
}

void SET_SCL(void)
{
	mt_set_gpio_out(GPIO_SCL, GPIO_OUT_ONE);
	udelay(I2C_DELAY_VALUE);
}

void CLEAR_SDA(void)
{
	mt_set_gpio_out(GPIO_SDA, GPIO_OUT_ZERO);
	udelay(I2C_DELAY_VALUE);
}

void CLEAR_SCL(void)
{
	mt_set_gpio_out(GPIO_SCL, GPIO_OUT_ZERO);
	udelay(I2C_DELAY_VALUE);
}


/* ------------------------------------------------------------------------------ */
/* Local constants (function parameters) */
/* ------------------------------------------------------------------------------ */
#undef READ
#define READ   1

#undef WRITE
#define WRITE  0

#define LAST_BYTE      1
#define NOT_LAST_BYTE  0

#define IIC_OK			 0
#define IIC_NOACK		 1
#define IIC_SCL_TIMEOUT  2

/* ------------------------------------------------------------------------------ */
/* Function: SetSCLHigh */
/* Description: */
/* ------------------------------------------------------------------------------ */
static uint8_t SetSCLHigh(void)
{
	volatile uint8_t x = 0;	/* delay variable */
	uint32_t timeout = 0;

	/* set SCL high, and wait for it to go high in case slave is clock stretching */
	SET_SCL();
	x++;
	x++;
	x++;
	x++;

	while (!GET_SCL()) {
		/* do nothing - just wait */
		/* udelay(2); */
		timeout++;
		if (timeout > 100000)	/* about 1s is enough */
		{
			printk("\n ************IIC SCL low timeout...\n");
			return IIC_SCL_TIMEOUT;
		}
	}

	return IIC_OK;
}

/* ------------------------------------------------------------------------------ */
/* Function: SendByte */
/* Description: */
/* ------------------------------------------------------------------------------ */
static uint8_t I2CSendByte(uint8_t abyte)
{
	uint8_t error = 0;
	uint8_t i;

	for (i = 0; i < 8; i++) {
		if (abyte & 0x80)
			SET_SDA();	/* send each bit, MSB first */
		else
			CLEAR_SDA();

		if (SetSCLHigh())	/* do clock cycle */
			return IIC_SCL_TIMEOUT;

		CLEAR_SCL();

		abyte <<= 1;	/* shift over to get next bit */
	}

	SET_SDA();		/* listen for ACK */
#if 1
	if (SetSCLHigh())
		return IIC_SCL_TIMEOUT;

	if (GET_SDA())		/* error if no ACK */
	{
		printk("IIC_NOACK\n");
		error = IIC_NOACK;
	}
#endif
	CLEAR_SCL();

	return (error);		/* return 0 for no ACK, 1 for ACK received */
}


/* ------------------------------------------------------------------------------ */
/* Function: SendAddr */
/* Description: */
/* ------------------------------------------------------------------------------ */
static uint8_t I2CSendAddr(uint8_t addr, uint8_t read)
{
	volatile uint8_t x = 0;	/* delay variable */

	/* generate START condition */
	SET_SCL();
#if 0
	if (GET_SCL)
		TX_DEBUG_PRINT(("GET_SCL is high rightly\n"));
	else
		TX_DEBUG_PRINT(("GET_SCL is low wrong\n"));
#endif
	x++;			/* short delay to keep setup times in spec */
	CLEAR_SDA();
#if 0
	if (!GET_SDA)
		TX_DEBUG_PRINT(("GET_SDA is low rightly\n"));
	else
		TX_DEBUG_PRINT(("GET_SDA is high wrong\n"));
#endif
	x++;
	x++;
	x++;
	CLEAR_SCL();
#if 0
	if (!GET_SCL)
		TX_DEBUG_PRINT(("GET_SCL is low rightly\n"));
	else
		TX_DEBUG_PRINT(("GET_SCL is high wrong\n"));
#endif
	x++;

	return (I2CSendByte(addr | read));	/* send address uint8_t with read/write bit */
}

static uint8_t I2CGetByte(uint8_t lastbyte, uint8_t *Data)
{
	uint8_t abyte = 0;
	uint8_t i;

	for (i = 0; i < 8; i++)	/* get each bit, MSB first */
	{
		if (SetSCLHigh())
			return IIC_SCL_TIMEOUT;

		abyte <<= 1;	/* shift result over to make room for next bit */

		if (GET_SDA())
			abyte++;	/* same as 'abyte |= 1', only faster */

		CLEAR_SCL();
	}

	if (lastbyte)
		SET_SDA();	/* do not ACK last uint8_t read */
	else
		CLEAR_SDA();

	if (SetSCLHigh())
		return IIC_SCL_TIMEOUT;

	CLEAR_SCL();
	SET_SDA();

	*Data = abyte;

	return IIC_OK;
}

/* ------------------------------------------------------------------------------ */
/* Function: SendStop */
/* Description: */
/* ------------------------------------------------------------------------------ */
static uint8_t I2CSendStop(void)
{
	CLEAR_SDA();
	if (SetSCLHigh())
		return IIC_SCL_TIMEOUT;

	SET_SDA();
	return IIC_OK;
}

/* ------------------------------------------------------------------- */
uint8_t I2C_ReadByte(uint8_t SlaveAddr, uint8_t RegAddr)
{
#if 0
	return sccb_read(SlaveAddr, RegAddr);
#else
	uint8_t Data = 0;
	I2CSendAddr(SlaveAddr, WRITE);
	I2CSendByte(RegAddr);
	I2CSendAddr(SlaveAddr, READ);
	I2CGetByte(LAST_BYTE, &Data);
	I2CSendStop();

	return Data;
#endif
}

/* ------------------------------------------------------------------- */
void I2C_WriteByte(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t Data)
{
#if 0
	sccb_write(SlaveAddr, RegAddr, Data);

#else

	I2CSendAddr(SlaveAddr, WRITE);
	I2CSendByte(RegAddr);
	I2CSendByte(Data);
	I2CSendStop();
#endif
}

/* ------------------------------------------------------------------------------ */
/* Function Name: I2C_ReadBlock */
/* Function Description: Reads block of data from I2C Device */
/* ------------------------------------------------------------------------------ */
uint8_t I2C_ReadBlock(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t *Data, uint8_t NBytes)
{
	uint8_t i, bState;

	bState = I2CSendAddr(SlaveAddr, WRITE);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendByte(RegAddr);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendAddr(SlaveAddr, READ);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	for (i = 0; i < NBytes - 1; i++) {
		if (I2CGetByte(NOT_LAST_BYTE, &Data[i])) {
			I2CSendStop();
			return IIC_SCL_TIMEOUT;
		}
	}
	if (I2CGetByte(LAST_BYTE, &Data[i])) {
		I2CSendStop();
		return IIC_SCL_TIMEOUT;
	}
	I2CSendStop();

	return IIC_OK;
}

/* ------------------------------------------------------------------------------ */
/* Function Name:  I2C_WriteBlock */
/* Function Description: Writes block of data from I2C Device */
/* ------------------------------------------------------------------------------ */
uint8_t I2C_WriteBlock(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t NBytes, uint8_t *Data)
{
	uint8_t i, bState;

	bState = I2CSendAddr(SlaveAddr, WRITE);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendByte(RegAddr);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	for (i = 0; i < NBytes; i++)
		I2CSendByte(Data[i]);

	I2CSendStop();

	return IIC_OK;

}

/* ------------------------------------------------------------------------------ */
/* Function Name:  I2C_ReadSegmentBlockEDID */
/* Function Description: Reads segment block of EDID from HDMI Downstream Device */
/* ------------------------------------------------------------------------------ */
uint8_t I2C_ReadSegmentBlockEDID(uint8_t SlaveAddr, uint8_t Segment, uint8_t Offset,
				 uint8_t *Buffer, uint8_t Length)
{
	uint8_t i, bState;
	TX_DEBUG_PRINT(("I2C_ReadSegmentBlockEDID%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"));

	bState = I2CSendAddr(0x60, WRITE);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendByte(Segment);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendAddr(SlaveAddr, WRITE);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendByte(Offset);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	bState = I2CSendAddr(SlaveAddr, READ);
	if (bState) {
		I2CSendStop();
		return IIC_NOACK;
	}

	for (i = 0; i < Length - 1; i++)
		if (I2CGetByte(NOT_LAST_BYTE, &Buffer[i]))
			return IIC_SCL_TIMEOUT;

	if (I2CGetByte(LAST_BYTE, &Buffer[i]))
		return IIC_SCL_TIMEOUT;

	I2CSendStop();

	return IIC_OK;
}

/*
void SiiRegEdidReadBlock( SiiReg_t segmentAddr, SiiReg_t virtualAddr, uint8_t *pBuffer, uint16_t count )
{
	uint8_t             Seg_regOffset;
    uint8_t             regOffset = (uint8_t)virtualAddr;

    if ((segmentAddr & 0xFF) != 0)
    {
	Seg_regOffset = (uint8_t)segmentAddr;
    }
    regOffset = (uint8_t)virtualAddr;

	I2C_ReadSegmentBlockEDID (0xA0, Seg_regOffset, regOffset, pBuffer, count);
}
*/
/******************************software I2C demo code**********************************/

#endif

/* void SiiRegEdidReadBlock( SiiReg_t segmentAddr, SiiReg_t virtualAddr, uint8_t *pBuffer, uint16_t count ) */

uint8_t I2C_ReadSegmentBlockEDID(uint8_t SlaveAddr, uint8_t Segment, uint8_t Offset,
				 uint8_t *Buffer, uint8_t Length)
{
	return 0;
}

static int32_t MhlI2cProbe(struct i2c_client *client, const struct i2c_device_id *id);
static int32_t MhlI2cRemove(struct i2c_client *client);


static int32_t MhlI2cProbe(struct i2c_client *client, const struct i2c_device_id *id)
{
	printk("%s, client=0x%08x\n", __func__, (unsigned int)client);
	gMhlDevice.pI2cClient = client;
	return 0;
}

static int32_t MhlI2cRemove(struct i2c_client *client)
{
	gMhlDevice.pI2cClient = NULL;
	return 0;
}

halReturn_t I2cAccessCheck(void)
{
	halReturn_t retStatus;
	retStatus = HalInitCheck();
	if (retStatus != HAL_RET_SUCCESS) {
		return retStatus;
	}
	if (gMhlDevice.pI2cClient == NULL) {
		printk("I2C device not currently open\n");
		/* retStatus = HAL_RET_DEVICE_NOT_OPEN; */
		retStatus = HAL_RET_SUCCESS;
	}
	return retStatus;
}

struct i2c_device_id gMhlI2cIdTable[] = {
	{
	 "Sil_MHL", 0}
};


#if 0 ///SII_I2C_ADDR == (0x76)  default is 0x72
static struct i2c_board_info i2c_mhl __initdata = {
	.type = "Sil_MHL",
	.addr = 0x3B,
	.irq = 8,
};
#else ///default is 0x72
static struct i2c_board_info __initdata i2c_mhl = {
	.type = "Sil_MHL",
	.addr = 0x39,
	.irq = 8,
};
#endif

struct i2c_driver mhl_i2c_driver = {
	.probe = MhlI2cProbe,
	.remove = MhlI2cRemove,
	/* .detect = hdmi_i2c_detect, */
	.driver = {.name = "Sil_MHL",},
	.id_table = gMhlI2cIdTable,
	/* .address_list = (const unsigned short*) forces, */
};

halReturn_t HalOpenI2cDevice(char const *DeviceName, char const *DriverName)
{
	halReturn_t retStatus;
	int32_t retVal;

	retStatus = HalInitCheck();
	if (retStatus != HAL_RET_SUCCESS) {
		return retStatus;
	}
	retVal = strnlen(DeviceName, I2C_NAME_SIZE);
	if (retVal >= I2C_NAME_SIZE) {
		printk("I2c device name too long!\n");
		return HAL_RET_PARAMETER_ERROR;
	}

    if( get_hdmi_i2c_addr()== 0x76)
        i2c_mhl.addr = 0x3B;

	i2c_register_board_info(get_hdmi_i2c_channel(), &i2c_mhl, 1);

	memcpy(gMhlI2cIdTable[0].name, DeviceName, retVal);
	gMhlI2cIdTable[0].name[retVal] = 0;
	gMhlI2cIdTable[0].driver_data = 0;

	gMhlDevice.driver.driver.name = "Sil_MHL";
	gMhlDevice.driver.id_table = gMhlI2cIdTable;
	gMhlDevice.driver.probe = MhlI2cProbe;
	gMhlDevice.driver.remove = MhlI2cRemove;

	/* printk("gMhlDevice.driver.driver.name=%s\n", gMhlDevice.driver.driver.name); */
	/* printk("gMhlI2cIdTable.name=%s\n", gMhlI2cIdTable[0].name); */
	retVal = i2c_add_driver(&mhl_i2c_driver);
	/* printk("gMhlDevice.pI2cClient =%p\n", gMhlDevice.pI2cClient); */
	if (retVal != 0) {
		printk("I2C driver add failed, retVal=%d\n", retVal);
		retStatus = HAL_RET_FAILURE;
	} else {
#if 0
		if (gMhlDevice.pI2cClient == NULL) {
			i2c_del_driver(&gMhlDevice.driver);
			printk("I2C driver add failed, retVal=%d\n", retVal);
			retStatus = HAL_RET_NO_DEVICE;
		} else
#endif
		{
			retStatus = HAL_RET_SUCCESS;
		}
	}

	/* printk("GPIO_SCL=%d, GPIO_SDA=%d\n", GPIO_SCL, GPIO_SDA); */

	return retStatus;
}

halReturn_t HalCloseI2cDevice(void)
{
	halReturn_t retStatus;
	retStatus = HalInitCheck();
	if (retStatus != HAL_RET_SUCCESS) {
		return retStatus;
	}
	if (gMhlDevice.pI2cClient == NULL) {
		printk("I2C device not currently open\n");
		retStatus = HAL_RET_DEVICE_NOT_OPEN;
	} else {
		i2c_del_driver(&gMhlDevice.driver);
		gMhlDevice.pI2cClient = NULL;
		retStatus = HAL_RET_SUCCESS;
	}
	return retStatus;
}

#define USE_DEFAULT_I2C_CODE  0
static int mhl_i2c_status;	/* bit0: read, bit1: write, bit2: block_read, bit3:block_write */

uint8_t I2C_ReadByte(uint8_t deviceID, uint8_t offset)
{
	/* printk("hdmi enter I2C_ReadByte(0x%02x, 0x%02x)\n", */
	/* deviceID, offset); */

	uint8_t accessI2cAddr;
	union i2c_smbus_data data;
	int32_t status;
	u32 client_main_addr;
	char buf = offset;
	if (I2cAccessCheck() != HAL_RET_SUCCESS) {
		return 0xFF;
	}
	mhl_i2c_status |= 1;
	if ((mhl_i2c_status & 0xfe) != 0)
		printk("MHL R mhl_i2c_status(0x%02x)\n", mhl_i2c_status);

	accessI2cAddr = deviceID >> 1;

	/* backup addr */
	client_main_addr = gMhlDevice.pI2cClient->addr;
	gMhlDevice.pI2cClient->addr = (accessI2cAddr & I2C_MASK_FLAG) | I2C_WR_FLAG;

#if 1
#ifdef MHL_SET_EXT_GPIO
	gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
#endif
	status = i2c_master_send(gMhlDevice.pI2cClient, &buf, 0x101);

	/* /gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG; */
	/* /status = i2c_master_recv(gMhlDevice.pI2cClient, (char*)&buf, 1); */
	data.byte = buf;

	if (status < 0) {
		if (deviceID != 0xfc) {
			printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
			       deviceID, offset, status);
		}
		data.byte = 0xFF;
	}
#else
	char buf = offset;
	u32 ext_flag = I2C_DIRECTION_FLAG | I2C_WR_FLAG;
	status = mt_i2c_master_send(gMhlDevice.pI2cClient, &buf, (1 << 8) | 1, ext_flag);

	data.byte = buf;

	if (status < 0) {
		if (deviceID != 0xfc) {
			printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
			       deviceID, offset, status);
		}
		data.byte = 0xFF;
	}
#endif

	mhl_i2c_status &= 0xfe;
	gMhlDevice.pI2cClient->addr = client_main_addr;
	return data.byte;
}

void I2C_WriteByte(uint8_t deviceID, uint8_t offset, uint8_t value)
{
	/* printk("hdmi enter I2C_WriteByte(0x%02x, 0x%02x, 0x%02x)\n", */
	/* deviceID, offset, value); */

	uint8_t accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
	union i2c_smbus_data data;
#endif
	int32_t status;
	u32 client_main_addr;
	u8 buf[2];
	if (I2cAccessCheck() != HAL_RET_SUCCESS) {
		return;
	}
	accessI2cAddr = deviceID >> 1;	/* ? */
	mhl_i2c_status |= 2;
	if ((mhl_i2c_status & 0xfd) != 0)
		printk("MHL W mhl_i2c_status(0x%02x)\n", mhl_i2c_status);

	/* backup addr */
	client_main_addr = gMhlDevice.pI2cClient->addr;
	gMhlDevice.pI2cClient->addr = accessI2cAddr;

#if USE_DEFAULT_I2C_CODE
	data.byte = value;
	status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
				0, I2C_SMBUS_WRITE, offset, I2C_SMBUS_BYTE_DATA, &data);
#else
#ifdef MHL_SET_EXT_GPIO
	gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
#endif
	buf[0] = offset;
	buf[1] = value;
	status = i2c_master_send(gMhlDevice.pI2cClient, (const char *)buf, 2 /*sizeof(buf) */);
#endif

	if (status < 0) {
		printk("I2C_WriteByte(0x%02x, 0x%02x, 0x%02x), i2c_transfer error: %d\n",
		       deviceID, offset, value, status);
	}
	mhl_i2c_status &= 0xfd;
	/* restore default client address */
	gMhlDevice.pI2cClient->addr = client_main_addr;
}

uint8_t I2C_ReadBlock(uint8_t deviceID, uint8_t offset, uint8_t *buf, uint8_t len)
{
	/* printk("hdmi enter %s (0x%02x, 0x%02x, 0x%02x)\n", __func__, deviceID, offset, len); */
	int i;
	uint8_t accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
	union i2c_smbus_data data;
#endif
	int32_t status;
	u32 client_main_addr;
	if (I2cAccessCheck() != HAL_RET_SUCCESS) {
		return 0x00;
	}
	accessI2cAddr = deviceID >> 1;

	/* backup addr */
	client_main_addr = gMhlDevice.pI2cClient->addr;
	gMhlDevice.pI2cClient->addr = accessI2cAddr;
	mhl_i2c_status |= 4;
	if ((mhl_i2c_status & 0xfb) != 0)
		printk("MHL BR mhl_i2c_status(0x%02x)\n", mhl_i2c_status);


	memset(buf, 0xff, len);
	for (i = 0; i < len; i++) {
#if USE_DEFAULT_I2C_CODE
		status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
					0, I2C_SMBUS_READ, offset + i, I2C_SMBUS_BYTE_DATA, &data);
		if (status < 0) {
			return 0;
		}
		*buf = data.byte;
#else
		u8 tmp;
		tmp = offset + i;
#ifdef MHL_SET_EXT_GPIO
		gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
#endif
		status = i2c_master_send(gMhlDevice.pI2cClient, (const char *)&tmp, 1);
		if (status < 0) {
			printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
			       deviceID, offset, status);
		}

		status = i2c_master_recv(gMhlDevice.pI2cClient, (char *)&tmp, 1);
		*buf = tmp;
#endif

		buf++;
	}
	mhl_i2c_status &= 0xfb;
	/* restore default client address */
	gMhlDevice.pI2cClient->addr = client_main_addr;
	return len;
}

void I2C_WriteBlock(uint8_t deviceID, uint8_t offset, uint8_t *buf, uint8_t len)
{
	/* printk("hdmi enter %s (0x%02x, 0x%02x, 0x%02x)\n",__func__, deviceID, offset, len); */
	int i;
	uint8_t accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
	union i2c_smbus_data data;
#endif
	int32_t status;
	u8 tmp[2] = { 0 };
	u32 client_main_addr;

	if (I2cAccessCheck() != HAL_RET_SUCCESS) {
		return;
	}
	accessI2cAddr = deviceID >> 1;
	mhl_i2c_status |= 8;
	if ((mhl_i2c_status & 0xf7) != 0)
		printk("MHL BW mhl_i2c_status(0x%02x)\n", mhl_i2c_status);

	/* backup addr */
	client_main_addr = gMhlDevice.pI2cClient->addr;
	gMhlDevice.pI2cClient->addr = accessI2cAddr;


	for (i = 0; i < len; i++) {
#if USE_DEFAULT_I2C_CODE
		data.byte = *buf;
		status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
					0, I2C_SMBUS_WRITE, offset + i, I2C_SMBUS_BYTE_DATA, &data);
#else
		tmp[0] = offset + i;
		tmp[1] = *buf;
#ifdef MHL_SET_EXT_GPIO
		gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
#endif
		status = i2c_master_send(gMhlDevice.pI2cClient, (const char *)tmp, 2);

#endif
		if (status < 0) {
			/* restore default client address */
			gMhlDevice.pI2cClient->addr = client_main_addr;
			return;
		}
		buf++;
	}
	mhl_i2c_status &= 0xf7;
	/* restore default client address */
	gMhlDevice.pI2cClient->addr = client_main_addr;
	return;
}