source: svn/trunk/newcon3bcm2_21bu/nexus/modules/i2c/7552/include/nexus_i2c.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 14.3 KB
Line 
1/***************************************************************************
2*     (c)2004-2009 Broadcom Corporation
3*
4*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5*  and may only be used, duplicated, modified or distributed pursuant to the terms and
6*  conditions of a separate, written license agreement executed between you and Broadcom
7*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8*  no license (express or implied), right to use, or waiver of any kind with respect to the
9*  Software, and Broadcom expressly reserves all rights in and to the Software and all
10*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13*
14*  Except as expressly set forth in the Authorized License,
15*
16*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18*  and to use this information only in connection with your use of Broadcom integrated circuit products.
19*
20*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27*  USE OR PERFORMANCE OF THE SOFTWARE.
28*
29*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36*  ANY LIMITED REMEDY.
37*
38* $brcm_Workfile: nexus_i2c.h $
39* $brcm_Revision: 6 $
40* $brcm_Date: 7/20/09 8:46a $
41*
42* API Description:
43*   API name: I2c
44*    Specific APIs related to I2c Control.
45*
46* Revision History:
47*
48* $brcm_Log: /nexus/modules/i2c/7400/include/nexus_i2c.h $
49*
50* 6   7/20/09 8:46a erickson
51* PR56687: Change I2C clock enum from Khz to Hz
52*
53* 5   2/18/09 9:38a erickson
54* PR52223: add NEXUS_I2c_SetSettings
55*
56* 4   4/24/08 9:54a erickson
57* PR41989: added NEXUS_I2c_ReadNoAddrNoAck
58*
59* 3   2/4/08 4:24p vsilyaev
60* PR 38682: Added more tags for the linux kernel/user proxy mode
61*
62* 2   2/4/08 2:41p vsilyaev
63* PR 38682: Added markup for variable size pointers
64*
65* 1   1/18/08 2:15p jgarrett
66* PR 38808: Merging to main branch
67*
68* Nexus_Devel/8   11/30/07 11:12a erickson
69* PR35457: api update
70*
71* Nexus_Devel/7   11/29/07 2:24p erickson
72* PR35457: doc update for 0.5 release
73*
74* Nexus_Devel/6   11/21/07 1:57p erickson
75* PR36725: added #include
76*
77* Nexus_Devel/5   11/5/07 2:12p erickson
78* PR36725: remove NEXUS_I2c_Get
79*
80* Nexus_Devel/4   10/10/07 11:29a jgarrett
81* PR 35551: Revising I2C Handle for synchronization purposes
82*
83* Nexus_Devel/3   10/5/07 1:42p jgarrett
84* PR 35744: Changing comments
85*
86* Nexus_Devel/2   9/12/07 4:35p jgarrett
87* PR 34702: Adding I2C interface
88*
89* Nexus_Devel/1   9/12/07 10:39a jgarrett
90* PR 34702: Adding initial IO headers
91*
92***************************************************************************/
93#ifndef NEXUS_I2C_H__
94#define NEXUS_I2C_H__
95
96#include "nexus_types.h"
97#include "nexus_gpio.h"
98
99#ifdef __cplusplus
100extern "C" {
101#endif
102
103/**
104Summary:
105Handle for the I2c Interface.
106**/
107typedef struct NEXUS_I2c *NEXUS_I2cHandle;
108
109/**
110Summary:
111Enumeration for I2C clock rate
112
113Description:
114This enumeration defines the clock rate for the I2C master
115**/
116typedef enum NEXUS_I2cClockRate
117{
118    NEXUS_I2cClockRate_e47Khz  = 47000,
119    NEXUS_I2cClockRate_e50Khz  = 50000,
120    NEXUS_I2cClockRate_e93Khz  = 93000,
121    NEXUS_I2cClockRate_e100Khz = 100000,
122    NEXUS_I2cClockRate_e187Khz = 187000,
123    NEXUS_I2cClockRate_e200Khz = 200000,
124    NEXUS_I2cClockRate_e375Khz = 375000,
125    NEXUS_I2cClockRate_e400Khz = 400000,
126    NEXUS_I2cClockRate_eMax
127} NEXUS_I2cClockRate;
128
129/**
130Summary:
131I2C Channel Settings.
132
133Description:
134All of these settings are used in NEXUS_I2c_Open.
135Some of these settings may be changed with NEXUS_I2c_SetSettings. See detailed comments for which ones can be changed.
136**/
137typedef struct NEXUS_I2cSettings
138{
139    NEXUS_I2cClockRate clockRate; /* Clock Rate. May be changed with NEXUS_I2c_SetSettings. */
140    bool interruptMode;           /* Will interrupts be used for this channel? [default=true] */
141    bool burstMode;               /* Will burst mode reads be used? [default=false]. May be changed with NEXUS_I2c_SetSettings. */
142    unsigned timeout;             /* If 0, a default will be assumed based on the clock rate */
143   
144    bool softI2c;                 /* If false, HW i2c will be used.  If true, SW bit bang i2c will be used. */
145    NEXUS_GpioHandle clockGpio;   /* Only used if softI2c is true. If not NULL, this will override the BI2C GPIO default. */
146    NEXUS_GpioHandle dataGpio;    /* Only used if softI2c is true. If not NULL, this will override the BI2C GPIO default. */
147} NEXUS_I2cSettings;
148
149/**
150Summary:
151Get default settings for the structure.
152
153Description:
154This is required in order to make application code resilient to the addition of new strucutre members in the future.
155**/
156void NEXUS_I2c_GetDefaultSettings(
157    NEXUS_I2cSettings *pSettings    /* [out] */
158    );
159
160/**
161Summary:
162Open an I2c channel.
163**/
164NEXUS_I2cHandle NEXUS_I2c_Open( /* attr{destructor=NEXUS_I2c_Close} */
165    unsigned channelIndex,
166    const NEXUS_I2cSettings *pSettings
167    );
168
169/**
170Summary:
171Close an I2c channel.
172**/
173void NEXUS_I2c_Close(
174    NEXUS_I2cHandle handle
175    );
176
177/**
178Summary:
179Set new settings. See comments for NEXUS_I2cSettings to see which members can be changed after NEXUS_I2c_Open.
180**/
181NEXUS_Error NEXUS_I2c_SetSettings(
182    NEXUS_I2cHandle i2cHandle,
183    const NEXUS_I2cSettings *pSettings
184    );
185
186/**
187Summary:
188Get current settings.
189**/
190void NEXUS_I2c_GetSettings(
191    NEXUS_I2cHandle i2cHandle,
192    NEXUS_I2cSettings *pSettings /* [out] */
193    );
194
195/**
196Summary:
197Write a programmable number of I2C registers using an 8 bit sub address.
198**/
199NEXUS_Error NEXUS_I2c_Write(
200    NEXUS_I2cHandle handle, /* I2C Handle */
201    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
202    uint8_t subAddr,        /* 8 bit sub address */
203    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
204    size_t length           /* number of bytes to write */
205    );
206
207/*
208Summary:
209This function atomically writes then reads a programmable number of I2C registers using an 8 bit
210sub address.
211*/
212NEXUS_Error NEXUS_I2c_WriteRead(
213    NEXUS_I2cHandle i2cHandle,  /* I2C Handle */
214    uint16_t chipAddr,          /* 7 or 10 bit chip address (_unshifted_) */
215    uint8_t subAddr,            /* 8 bit sub address */
216    const uint8_t *pWriteData,  /* attr{nelem=writeLength;reserved=8} pointer to data to write */
217    size_t writeLength,         /* number of bytes to write */
218    uint8_t *pReadData,         /* [out] attr{nelem=readLength;reserved=8} pointer to memory to store read data */
219    size_t readLength           /* number of bytes to read */
220    );
221
222/**
223Summary:
224Write a programmable number of I2C registers using an 8 bit
225sub address and no ack.
226**/
227NEXUS_Error NEXUS_I2c_WriteNoAck(
228    NEXUS_I2cHandle handle, /* I2C Handle */
229    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
230    uint8_t subAddr,        /* 8 bit sub address */
231    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
232    size_t length           /* number of bytes to write */
233    );
234
235/**
236Summary:
237Write a programmable number of I2C registers using a 16 bit
238sub address.
239**/
240NEXUS_Error NEXUS_I2c_WriteA16(
241    NEXUS_I2cHandle handle, /* I2C Handle */
242    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
243    uint16_t subAddr,       /* 16 bit sub address */
244    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
245    size_t length           /* number of bytes to write */
246    );
247
248/**
249Summary:
250Write a programmable number of I2C registers using a 24 bit
251sub address.
252**/
253NEXUS_Error NEXUS_I2c_WriteA24(
254    NEXUS_I2cHandle handle, /* I2C Handle */
255    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
256    uint32_t subAddr,       /* 24 bit sub address */
257    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
258    size_t length           /* number of bytes to write */
259    );
260
261/**
262Summary:
263Write a programmable number of I2C registers without a sub address
264(raw write).
265**/
266NEXUS_Error NEXUS_I2c_WriteNoAddr(
267    NEXUS_I2cHandle handle, /* I2C Handle */
268    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
269    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
270    size_t length           /* number of bytes to write */
271    );
272
273/**
274Summary:
275Write a programmable number of I2C registers without a sub address
276(raw write), and without waiting for an ack.
277**/
278NEXUS_Error NEXUS_I2c_WriteNoAddrNoAck(
279    NEXUS_I2cHandle handle, /* I2C Handle */
280    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
281    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
282    size_t length           /* number of bytes to write */
283    );
284
285/**
286Summary:
287Write an I2C NVRAM device using an 8 bit sub address.
288**/
289NEXUS_Error NEXUS_I2c_WriteNvram(
290    NEXUS_I2cHandle handle, /* I2C Handle */
291    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
292    uint8_t subAddr,        /* 8 bit sub address */
293    const uint8_t *pData,   /* attr{nelem=length;reserved=8} pointer to data to write */
294    size_t length           /* number of bytes to write */
295    );
296
297/**
298Summary:
299Read a programmable number of I2C registers using an 8 bit
300sub address.
301**/
302NEXUS_Error NEXUS_I2c_Read(
303    NEXUS_I2cHandle handle, /* I2C Handle */
304    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
305    uint8_t subAddr,        /* 8 bit sub address */
306    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
307    size_t length           /* number of bytes to read */
308    );
309
310/**
311Summary:
312Read a programmable number of I2C registers using an 8 bit
313sub address and no ack.
314**/
315NEXUS_Error NEXUS_I2c_ReadNoAck(
316    NEXUS_I2cHandle handle, /* I2C Handle */
317    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
318    uint8_t subAddr,        /* 8 bit sub address */
319    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
320    size_t length           /* number of bytes to read */
321    );
322
323/**
324Summary:
325Read a programmable number of I2C registers using a 16 bit
326sub address.
327**/
328NEXUS_Error NEXUS_I2c_ReadA16(
329    NEXUS_I2cHandle handle, /* I2C Handle */
330    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
331    uint16_t subAddr,       /* 16 bit sub address */
332    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
333    size_t length           /* number of bytes to read */
334    );
335
336/*
337Summary:
338Read a programmable number of I2C registers using a 24 bit
339sub address.
340**/
341NEXUS_Error NEXUS_I2c_ReadA24(
342    NEXUS_I2cHandle handle, /* I2C Handle */
343    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
344    uint32_t subAddr,       /* 32 bit sub address */
345    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
346    size_t length           /* number of bytes to read */
347    );
348
349/**
350Summary:
351Read a programmable number of I2C registers without a sub address
352(raw read).
353**/
354NEXUS_Error NEXUS_I2c_ReadNoAddr(
355    NEXUS_I2cHandle handle, /* I2C Handle */
356    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
357    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
358    size_t length           /* number of bytes to read */
359    );
360
361/**
362Summary:
363Read a programmable number of I2C registers without a sub address
364(raw read) and no ack.
365**/
366NEXUS_Error NEXUS_I2c_ReadNoAddrNoAck(
367    NEXUS_I2cHandle handle, /* I2C Handle */
368    uint16_t chipAddr,      /* 7 or 10 bit chip address (_unshifted_) */
369    uint8_t *pData,         /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data */
370    size_t length           /* number of bytes to read */
371    );
372
373/**
374Summary:
375Read using the Enhanced Display Data Channel protocol.
376**/
377NEXUS_Error NEXUS_I2c_ReadEDDC(
378    NEXUS_I2cHandle handle,     /* I2C Handle */
379    uint8_t chipAddr,           /* chip address */
380    uint8_t segment,            /* EDDC segment pointer */
381    uint8_t subAddr,            /* 8-bit sub address */
382    uint8_t *pData,             /* [out] attr{nelem=length;reserved=8} pointer to memory location to store read data  */
383    size_t length               /* number of bytes to read */
384    );
385
386/**
387Summary:
388Write using the Enhanced Display Data Channel protocol.
389**/
390NEXUS_Error NEXUS_I2c_WriteEDDC(
391    NEXUS_I2cHandle handle,     /* I2C Handle */
392    uint8_t chipAddr,           /* chip address */
393    uint8_t segment,            /* EDDC segment pointer */
394    uint8_t subAddr,            /* 8-bit sub address */
395    const uint8_t *pData,       /* attr{nelem=length;reserved=8} pointer to data to write */
396    size_t length               /* number of bytes to write */
397    );
398
399/**
400Summary:
401Perform a software reset
402
403Description:
404After an interruption in protocol, power loss or system reset, any 2-wire
405part can be protocol reset by following these steps: (a) Create a start bit
406condition, (b) clock 9 cycles, (c) create another start bit followed by stop
407bit condition. The device is ready for next communication after above steps
408have been completed.
409**/
410NEXUS_Error NEXUS_I2c_SwReset(
411    NEXUS_I2cHandle handle
412    );
413
414#ifdef __cplusplus
415}
416#endif
417
418#endif /* #ifndef NEXUS_I2C_H__ */
419
420
Note: See TracBrowser for help on using the repository browser.