/**************************************************************************** * * Copyright (c) 2001 Trident Microsystems, Inc. * All rights reserved * * The content of this file or document is CONFIDENTIAL and PROPRIETARY * to Trident Microsystems, Inc. It is subject to the terms of a License * Agreement between Licensee and Trident Microsystems, Inc. * restricting among other things, the use, reproduction, distribution * and transfer. Each of the embodiments, including this information and * any derivative work shall retain this copyright notice * * FileName: IicComm.c * * modification history * Created by Alex * Date: 2006-4-28 *******************************************************************************/ #include "dsthalcommon.h" int S5H1409_IicTransmit(unsigned char chipAddr, unsigned char *pBuffer, int len ) { int n; n = DHL_SYS_I2cWrite( chipAddr, 0, 0, pBuffer, len ); if (n != len) return -1; return 0; } int S5H1409_IicTransmitEx(unsigned char chipAddr, unsigned char *pBuffer, int len ) { int n; #if 1 n = DHL_SYS_I2cWrite( chipAddr, 1, pBuffer[0], &pBuffer[1], len-1 ); if (n != len) return -1; #else n = DHL_SYS_I2cWrite( chipAddr, 0, 0, pBuffer, len ); if (n != len) return -1; #endif return 0; } /************************************************************************** * Name: * IicWriteOneRegister * Description: * write data to one register * Parameter: * chipaddr: I2c address * regaddr: subaddress * data: 2 bytes * return: * the value of the regaddr * 0 for success, non-zero for failure * Author: * Alex ***************************************************************************/ DS_U16 S5H_IicWriteOneRegister(DS_U8 chipaddr, DS_U8 regaddr, DS_U16 data) { int n; DS_U16 result = 0; DS_U8 dataBuf[2] = {0x00, 0x00}; dataBuf[0] = (data>>8)&0xff; dataBuf[1] = (data)&0xff; n = DHL_SYS_I2cWrite( chipaddr, 1, regaddr, dataBuf, 2 ); if ( n != 2 && n != 3 ) { printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); result = 1; } return result; } /************************************************************************** * Name: * IicReadOneRegister * Description: * Read one register with 2 bytes * Parameter: * chipaddr: I2c address * regaddr: subaddress * return: * the value of the regaddr * 0 for success, non-zero for failure * Author: * Alex ***************************************************************************/ DS_U16 S5H_IicReadOneRegister(DS_U8 chipaddr, DS_U8 regaddr) { DS_U8 dataBuf[2] = {0x00, 0x00}; DS_U16 ret_val; int n; n = DHL_SYS_I2cRead( chipaddr, 1, regaddr, dataBuf, 2 ); if ( n != 2 ) { printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); } ret_val = ((dataBuf[0]<<8) | dataBuf[1]); return ret_val; } DS_U8 S5H_IicReadTunerByte(DS_U8 TunerAddr) { DS_U8 dataBuf[2] = {0x00, 0x00}; DS_U8 ret_val; int n; n = DHL_SYS_I2cRead( TunerAddr, 0, 0, dataBuf, 1 ); if ( n != 0 ) { printf("|%s| ERROR, Return=%d\n", __FUNCTION__, n); } ret_val = dataBuf[0]; return ret_val; }