| 1 | /**************************************************************************** |
|---|
| 2 | * |
|---|
| 3 | * Copyright (c) 2001 Trident Microsystems, Inc. |
|---|
| 4 | * All rights reserved |
|---|
| 5 | * |
|---|
| 6 | * The content of this file or document is CONFIDENTIAL and PROPRIETARY |
|---|
| 7 | * to Trident Microsystems, Inc. It is subject to the terms of a License |
|---|
| 8 | * Agreement between Licensee and Trident Microsystems, Inc. |
|---|
| 9 | * restricting among other things, the use, reproduction, distribution |
|---|
| 10 | * and transfer. Each of the embodiments, including this information and |
|---|
| 11 | * any derivative work shall retain this copyright notice |
|---|
| 12 | * |
|---|
| 13 | * FileName: IicComm.c |
|---|
| 14 | * |
|---|
| 15 | * modification history |
|---|
| 16 | * Created by Alex |
|---|
| 17 | * Date: 2006-4-28 |
|---|
| 18 | *******************************************************************************/ |
|---|
| 19 | #include "dsthalcommon.h" |
|---|
| 20 | |
|---|
| 21 | int S5H1409_IicTransmit(unsigned char chipAddr, unsigned char *pBuffer, int len ) |
|---|
| 22 | { |
|---|
| 23 | int n; |
|---|
| 24 | |
|---|
| 25 | n = DHL_SYS_I2cWrite( chipAddr, 0, 0, pBuffer, len ); |
|---|
| 26 | if (n != len) |
|---|
| 27 | return -1; |
|---|
| 28 | |
|---|
| 29 | return 0; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | int S5H1409_IicTransmitEx(unsigned char chipAddr, unsigned char *pBuffer, int len ) |
|---|
| 33 | { |
|---|
| 34 | int n; |
|---|
| 35 | #if 1 |
|---|
| 36 | n = DHL_SYS_I2cWrite( chipAddr, 1, pBuffer[0], &pBuffer[1], len-1 ); |
|---|
| 37 | if (n != len) |
|---|
| 38 | return -1; |
|---|
| 39 | #else |
|---|
| 40 | |
|---|
| 41 | n = DHL_SYS_I2cWrite( chipAddr, 0, 0, pBuffer, len ); |
|---|
| 42 | if (n != len) |
|---|
| 43 | return -1; |
|---|
| 44 | #endif |
|---|
| 45 | return 0; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /************************************************************************** |
|---|
| 49 | * Name: |
|---|
| 50 | * IicWriteOneRegister |
|---|
| 51 | * Description: |
|---|
| 52 | * write data to one register |
|---|
| 53 | * Parameter: |
|---|
| 54 | * chipaddr: I2c address |
|---|
| 55 | * regaddr: subaddress |
|---|
| 56 | * data: 2 bytes |
|---|
| 57 | * return: |
|---|
| 58 | * the value of the regaddr |
|---|
| 59 | * 0 for success, non-zero for failure |
|---|
| 60 | * Author: |
|---|
| 61 | * Alex |
|---|
| 62 | ***************************************************************************/ |
|---|
| 63 | DS_U16 S5H_IicWriteOneRegister(DS_U8 chipaddr, DS_U8 regaddr, DS_U16 data) |
|---|
| 64 | { |
|---|
| 65 | int n; |
|---|
| 66 | DS_U16 result = 0; |
|---|
| 67 | DS_U8 dataBuf[2] = {0x00, 0x00}; |
|---|
| 68 | |
|---|
| 69 | dataBuf[0] = (data>>8)&0xff; |
|---|
| 70 | dataBuf[1] = (data)&0xff; |
|---|
| 71 | |
|---|
| 72 | n = DHL_SYS_I2cWrite( chipaddr, 1, regaddr, dataBuf, 2 ); |
|---|
| 73 | if ( n != 2 && n != 3 ) { |
|---|
| 74 | printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); |
|---|
| 75 | result = 1; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | return result; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /************************************************************************** |
|---|
| 82 | * Name: |
|---|
| 83 | * IicReadOneRegister |
|---|
| 84 | * Description: |
|---|
| 85 | * Read one register with 2 bytes |
|---|
| 86 | * Parameter: |
|---|
| 87 | * chipaddr: I2c address |
|---|
| 88 | * regaddr: subaddress |
|---|
| 89 | * return: |
|---|
| 90 | * the value of the regaddr |
|---|
| 91 | * 0 for success, non-zero for failure |
|---|
| 92 | * Author: |
|---|
| 93 | * Alex |
|---|
| 94 | ***************************************************************************/ |
|---|
| 95 | DS_U16 S5H_IicReadOneRegister(DS_U8 chipaddr, DS_U8 regaddr) |
|---|
| 96 | { |
|---|
| 97 | DS_U8 dataBuf[2] = {0x00, 0x00}; |
|---|
| 98 | DS_U16 ret_val; |
|---|
| 99 | int n; |
|---|
| 100 | |
|---|
| 101 | n = DHL_SYS_I2cRead( chipaddr, 1, regaddr, dataBuf, 2 ); |
|---|
| 102 | if ( n != 2 ) { |
|---|
| 103 | printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | ret_val = ((dataBuf[0]<<8) | dataBuf[1]); |
|---|
| 107 | |
|---|
| 108 | return ret_val; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | DS_U8 S5H_IicReadTunerByte(DS_U8 TunerAddr) |
|---|
| 112 | { |
|---|
| 113 | DS_U8 dataBuf[2] = {0x00, 0x00}; |
|---|
| 114 | DS_U8 ret_val; |
|---|
| 115 | int n; |
|---|
| 116 | |
|---|
| 117 | n = DHL_SYS_I2cRead( TunerAddr, 0, 0, dataBuf, 1 ); |
|---|
| 118 | if ( n != 0 ) { |
|---|
| 119 | printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | ret_val = dataBuf[0]; |
|---|
| 123 | |
|---|
| 124 | return ret_val; |
|---|
| 125 | } |
|---|