]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_1_eng/packages/ti/board/src/flash/platform_flash/evmc66x_i2c.h
PASDK-258:Update PDK eng to 1.0.1.1. Using build number to differentiate PDK eng...
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / src / flash / platform_flash / evmc66x_i2c.h
1 /*
2  * Copyright (c) 2011-2015, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
34 /**
35  *
36  * \file evmc66x_i2c.h
37  *
38  * \brief This contains i2c specific structure, typedefs, function
39  *                prototypes.
40  *
41  *
42  ******************************************************************************/
43 #ifndef _EVM66X_I2C_H_
44 #define _EVM66X_I2C_H_
46 /************************
47  * Include Files
48  ************************/
49 #include "cslr_i2c.h"
50 #include "cslr_device.h"
52 /************************
53  * Defines and Macros
54  ************************/
55 #define I2C_OWN_ADDR                 (0x10)
57 // Interrupt
58 #define I2C_DISABLE_INTR                 (0x00)
60 #ifdef CPU_1000MHZ_CLOCK
62 #ifdef _I2C_400KHZ_
63 // I2C prescalar set to 13 to get module freq (1000MHz/6)/14 = 11.9 MHz
64 #define I2C_PRESCALER                            (13)
65 // Setting the divider to divide module freq 11.9MHz/((9+6)+(9+6)) = 396.67 KHz
66 #define I2C_CLK_LOW                                      (9)
67 #define I2C_CLK_HIGH                             (9)
68 #else
69 // I2C prescalar set to 16 to get module freq (1000MHz/6)/17 = 9.8 MHz
70 #define I2C_PRESCALER                            (16)
71 // Setting the divider to divide module freq 9.8MHz/((36+6)+(36+6)) = 116.67 KHz
72 #define I2C_CLK_LOW                                      (36)
73 #define I2C_CLK_HIGH                             (36)
74 #endif
76 #else
78 #ifdef _I2C_400KHZ_
79 // I2C prescalar set to 9 to get module freq (600MHz/6)/10 = 10 MHz
80 #define I2C_PRESCALER                            (9)
81 // Setting the divider to divide module freq 10MHz/((7+6)+(7+6)) = 384.61 KHz
82 #define I2C_CLK_LOW                                      (7)
83 #define I2C_CLK_HIGH                             (7)
84 #else
85 // I2C prescalar set to 9 to get module freq (600MHz/6)/10 = 10 MHz
86 #define I2C_PRESCALER                            (9)
87 // Setting the divider to divide module freq 10MHz/((44+6)+(44+6)) = 100 KHz
88 #define I2C_CLK_LOW                                      (44)
89 #define I2C_CLK_HIGH                             (44)
90 #endif
92 #endif  /* #ifdef CPU_1000MHZ_CLOCK */
94 // I2C delay value
95 #define DELAY_CONST                          (2)
97 // I2C ports available
98 #define I2C_PORT_0                                       (CSL_I2C_0)
99 #define I2C_PORT_1                                       (CSL_I2C_1)
100 #define I2C_PORT_2                                       (CSL_I2C_2)
102 // Register values for specific purpose
103 #define I2C_VAL_REG_MDR_RESET            (0x4000)
104 #define I2C_VAL_REG_MDR_SLVRCV           (0x40A0)
105 #define I2C_VAL_REG_MDR_MSTRCV           (0x64A0)
106 #define I2C_VAL_REG_MDR_MSTRCVSTOP       (0x4CA0)
107 #define I2C_VAL_REG_MDR_MSTXMT           (0x46A0)
108 #define I2C_VAL_REG_MDR_MSTXMTSTRT       (0x66A0)
109 #define I2C_VAL_REG_MDR_MSTXMTSTOP       (0x4CA0)
111 #define I2C_VAL_REG_STR_RESET            (0x0410)
112 #define I2C_VAL_REG_STR_ON_FAIL          (0x1002)  // Clear bus busy, clear nack
113 #define I2C_VAL_REG_STR_CLR_BUSY         (0x1000)  // Clear busy
115 // Bit field definitions
116 #define BOOTBITMASK(x,y)                         ((( (1 << ((x)-(y)+1) )        - 1 )) << (y))
117 #define BOOT_READ_BITFIELD(z,x,y)        ((z) & BOOTBITMASK(x,y)) >> (y)
118 #define I2C_REG_STR_FIELD_BB(x)          BOOT_READ_BITFIELD((x),        12, 12)
119 #define I2C_REG_STR_FIELD_NACK(x)        BOOT_READ_BITFIELD((x),         1,  1)
120 #define I2C_REG_STR_FIELD_ARDY(x)        BOOT_READ_BITFIELD((x),         2,  2)
121 #define I2C_REG_STR_FIELD_XRDY(x)        BOOT_READ_BITFIELD((x),         4,  4)
122 #define I2C_REG_STR_FIELD_RRDY(x)        BOOT_READ_BITFIELD((x),         3,  3)
124 // Return values
125 #define I2C_RET_OK                                       (0)
126 #define I2C_RET_LOST_ARB                         (1)
127 #define I2C_RET_NO_ACK                           (2)
128 #define I2C_RET_IDLE_TIMEOUT             (3)
129 #define I2C_RET_BAD_REQUEST                      (4)
130 #define I2C_RET_CLOCK_STUCK_LOW          (5)
131 #define I2C_RET_NULL_PTR_ERROR           (6)
132 #define I2C_RET_INVALID_PARAM            (7)
133 #define I2C_RET_NO_ACK_READ                      (8)
134 #define I2C_RET_GEN_ERROR                        (99)
136 // Desired frequency for module operation
137 #define I2C_TARGET_MODULE_FREQ_MHZ           (8)
139 // Timeout limit for master     transmitter/receiver.
140 // The units are in number of bits, so provide some overhead
141 #define I2C_MAX_MASTER_TRANSFER_TIMEOUT  (24)   /* 3    bytes */
143 // Timeout limit for master     receiver. The units are
144 // in number of bits, so provide some overhead
145 #define I2C_MAX_MASTER_RECEIVE_TIMEOUT   (24)   /* 3 bytes */
147 // Timeout limit for the master transmitter     to get access
148 // to the bus. In 10ms units.
149 #define I2C_MAX_MASTER_TRANSMITTER_BUS_ACCESS_TIMEOUT  (5)
150 #define I2C_MASTER_TRANSMITTER_BUS_ACCESS_DELAY_US     (25)
152 /* Timeout limit after a master transmitter     operation is
153  * complete, and waiting for access     to the MMRs. This should be on
154  * the order of two bytes, for the last two that are being sent
155  * (one in the shift register, one in the dxr. The units are in bits. */
156 #define I2C_MAX_MASTER_TRANSMITTER_ARDY_TIMEOUT   (32)  /* 4 bytes */
158 /* Timeout limit in     slave receiver mode. The unit is in
159  * expected     bit periods, but is long since the master
160  * may have     a long delay before beginning transmission. */
161 #define I2C_MAX_SLAVE_RECEIVE_TIMEOUT      (5000000)
163 // I2C slave address offset minimum and maximum length supported
164 #define I2C_MIN_OFFSET_LEN      (1)
165 #define I2C_MAX_OFFSET_LEN      (4)
167 // Flags to indicate I2C data transfer direction
168 #define I2C_TRANSFER_READ       (0)
169 #define I2C_TRANSFER_WRITE      (1)
171 //#define ENABLE_I2C_DEBUG        (1)
173 #if (ENABLE_I2C_DEBUG)
174 #define IFPRINT_I2CDEBUG(x)   (x)
175 #else
176 #define IFPRINT_I2CDEBUG(x)
177 #endif
179 /************************
180  * Structures and Enums
181  ************************/
183 // Bus release
184 enum {
185   I2C_RELEASE_BUS,
186   I2C_DO_NOT_RELEASE_BUS
187 };
189 typedef uint16_t I2C_RET;
191 /************************
192  * Function declarations
193  ************************/
195 CSL_I2cRegs* i2cGetRegBaseAddr(uint8_t i2cPortNumber);
196 void evmI2CInit(uint8_t i2cportnumber );
197 I2C_RET i2cConfig(uint8_t i2cPortNumber);
198 I2C_RET i2cWrite( uint8_t i2cPortNumber, uint8_t slaveAddress, uint8_t *pData,
199                           uint32_t numBytes, uint32_t endBusState);
200 I2C_RET i2cRead ( uint8_t i2cPortNumber, uint8_t slaveAddress, uint8_t *pData,
201                   uint32_t readOffset, uint32_t OffsetLen, uint32_t numBytes);
202 I2C_RET i2cWriteLong( uint8_t i2cPortNumber, uint8_t slaveAddress,
203                               uint32_t *pData, uint32_t writeOffset, uint32_t OffsetLen,
204                               uint32_t numBytes, uint32_t endBusState);
205 void i2cDelay (uint32_t count);
206 I2C_RET i2cProbe (uint8_t i2cPortNumber, uint8_t slaveI2cAddress,
207                                   uint32_t offset, uint8_t *pData, uint32_t numBytes);
209 #endif // _EVM66X_I2C_H_