1 /******************************************************************************
\r
2 ** File Name: I2C_drv.c *
\r
4 ** DATE: 04/23/2002 *
\r
5 ** Copyright: 2002 Spreatrum, Incoporated. All Rights Reserved. *
\r
6 ** Description: This file define the basic interfaces of I2C device. *
\r
7 ******************************************************************************
\r
9 ******************************************************************************
\r
11 ** ------------------------------------------------------------------------- *
\r
12 ** DATE NAME DESCRIPTION *
\r
13 ** 01/16/2001 Richard.Yang Create. *
\r
14 ** 04/02/2002 Lin.Liu Code *
\r
15 ******************************************************************************/
\r
19 /**---------------------------------------------------------------------------*
\r
21 **---------------------------------------------------------------------------*/
\r
22 #include <asm/arch/sci_types.h>
\r
23 #include <asm/arch/arm_reg.h>
\r
25 /**---------------------------------------------------------------------------*
\r
27 **---------------------------------------------------------------------------*/
\r
29 /**---------------------------------------------------------------------------*
\r
31 **---------------------------------------------------------------------------*/
\r
39 // I2C command define
\r
40 #define I2C_CMD_ICLR BIT_0
\r
41 #define I2C_CMD_TX_ACK BIT_1
\r
42 #define I2C_CMD_WRITE BIT_2
\r
43 #define I2C_CMD_READ BIT_3
\r
44 #define I2C_CMD_STOP BIT_4
\r
45 #define I2C_CMD_START BIT_5
\r
46 #define I2C_CMD_ACK BIT_6
\r
47 #define I2C_CMD_BUSY BIT_7
\r
49 //I2C error code define
\r
52 ERR_I2C_NONE = 0, // Success,no error
\r
53 ERR_I2C_ACK_TIMEOUT, // I2C wait ACK timeout
\r
54 ERR_I2C_INT_TIMEOUT, // I2C wait INT timeout
\r
55 ERR_I2C_BUSY_TIMEOUT, // I2C wait BUSY timeout
\r
56 ERR_I2C_DEVICE_NOT_FOUND // I2C device not found
\r
62 /**---------------------------------------------------------------------------*
\r
63 ** Function Prototype
\r
64 **---------------------------------------------------------------------------*/
\r
65 /*********************************************************************/
\r
66 // Description: i2c interrupt service
\r
73 /*********************************************************************/
\r
74 PUBLIC void I2C_Handler(uint32 param);
\r
76 /*********************************************************************/
\r
77 // Description: Write a command to a slave device
\r
79 // addr the slave device's address
\r
80 // command the command to be set into the slave device's address
\r
81 // ack_en Enable/Disable check the slave device rsp ACK
\r
83 // ERR_I2C_NONE successfully
\r
86 /*********************************************************************/
\r
87 PUBLIC ERR_I2C_E I2C_WriteCmd(uint8 addr,uint8 command, BOOLEAN ack_en);
\r
89 /*********************************************************************/
\r
90 // Description: read a command from the slave device
\r
92 // addr the slave device's address
\r
93 // pCmd the command's pointer
\r
94 // ack_en Enable/Disable check the slave device rsp ACK
\r
96 // ERR_I2C_NONE successfully
\r
99 /*********************************************************************/
\r
100 PUBLIC ERR_I2C_E I2C_ReadCmd(uint8 addr,uint8 *pCmd,BOOLEAN ack_en);
\r
102 /*********************************************************************/
\r
103 // Description: Write the command array into the slave device
\r
105 // addr the slave device's address
\r
106 // pCmd the command array's pointer
\r
107 // len the length of the command array
\r
108 // ack_en Enable/Disable check the slave device rsp ACK
\r
110 // ERR_I2C_NONE successfully
\r
113 /*********************************************************************/
\r
114 PUBLIC ERR_I2C_E I2C_WriteCmdArr(uint8 addr, uint8 *pCmd, uint32 len, BOOLEAN ack_en);
\r
116 /*********************************************************************/
\r
117 // Description: Read a command array from the slave device
\r
119 // addr the slave device's address
\r
120 // pCmd the command array's pointer
\r
121 // len the length of command array
\r
122 // ack_en Enable/Disable check the slave device rsp ACK
\r
124 // ERR_I2C_NONE successfully
\r
127 /*********************************************************************/
\r
128 PUBLIC ERR_I2C_E I2C_ReadCmdArr(uint8 addr, uint8 *pCmd, uint32 len,BOOLEAN ack_en );
\r
130 /*********************************************************************/
\r
131 // Description: i2c set SCL clock
\r
133 // freq I2C SCL's frequency to be set
\r
135 // ERR_I2C_NONE successfully
\r
138 /*********************************************************************/
\r
139 PUBLIC ERR_I2C_E I2C_SetSCLclk(uint32 freq);
\r
141 /*********************************************************************/
\r
142 // Description: get i2c SCL clock
\r
146 // the freq of i2c SCL clock
\r
149 /*********************************************************************/
\r
150 PUBLIC uint32 I2C_GetSCLclk(void);
\r
152 /*********************************************************************/
\r
153 // Description: i2c init fuction
\r
155 // freq I2C SCL's frequency
\r
157 // ERR_I2C_NONE successfully
\r
160 /*********************************************************************/
\r
161 PUBLIC ERR_I2C_E I2C_Init(uint32 freq);
\r
166 /**---------------------------------------------------------------------------*
\r
168 **---------------------------------------------------------------------------*/
\r