blob: d71260240bda38e8dc008f1a0f5f7ba834066c2c [file] [log] [blame]
Devin Heitmuellerca3355a2010-07-04 18:42:11 -03001/*
2 Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc.
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 are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 * Neither the name of Trident Microsystems nor Hauppauge Computer Works
14 nor the names of its contributors may be used to endorse or promote
15 products derived from this software without specific prior written
16 permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE.
29*/
30
Devin Heitmueller38b2df92012-08-13 21:18:02 -030031/**
32* \file $Id: bsp_i2c.h,v 1.5 2009/07/07 14:20:30 justin Exp $
33*
34* \brief I2C API, implementation depends on board specifics
35*
36* This module encapsulates I2C access.In some applications several devices
37* share one I2C bus. If these devices have the same I2C address some kind
38* off "switch" must be implemented to ensure error free communication with
39* one device. In case such a "switch" is used, the device ID can be used
40* to implement control over this "switch".
41*
42*
43*/
44
Mauro Carvalho Chehabc7db16a2012-03-20 00:16:54 -030045#include <linux/kernel.h>
46
Devin Heitmueller38b2df92012-08-13 21:18:02 -030047#ifndef __BSPI2C_H__
48#define __BSPI2C_H__
49/*------------------------------------------------------------------------------
50INCLUDES
51------------------------------------------------------------------------------*/
52#include "bsp_types.h"
53
Devin Heitmueller38b2df92012-08-13 21:18:02 -030054/*------------------------------------------------------------------------------
55TYPEDEFS
56------------------------------------------------------------------------------*/
Devin Heitmueller38b2df92012-08-13 21:18:02 -030057
58/**
59* \struct _I2CDeviceAddr_t
60* \brief I2C device parameters.
61*
62* This structure contains the I2C address, the device ID and a userData pointer.
63* The userData pointer can be used for application specific purposes.
64*
65*/
Mauro Carvalho Chehabc7db16a2012-03-20 00:16:54 -030066 struct I2CDeviceAddr_t {
67 u16 i2cAddr;
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -030068 /**< The I2C address of the device. */
Mauro Carvalho Chehabc7db16a2012-03-20 00:16:54 -030069 u16 i2cDevId;
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -030070 /**< The device identifier. */
71 void *userData;
72 /**< User data pointer */
73 };
Devin Heitmueller38b2df92012-08-13 21:18:02 -030074
75/**
76* \typedef I2CDeviceAddr_t
77* \brief I2C device parameters.
78*
79* This structure contains the I2C address and the device ID.
80*
81*/
Mauro Carvalho Chehabc7db16a2012-03-20 00:16:54 -030082 typedef struct I2CDeviceAddr_t I2CDeviceAddr_t;
Devin Heitmueller38b2df92012-08-13 21:18:02 -030083
84/**
85* \typedef pI2CDeviceAddr_t
86* \brief Pointer to I2C device parameters.
87*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -030088 typedef I2CDeviceAddr_t *pI2CDeviceAddr_t;
Devin Heitmueller38b2df92012-08-13 21:18:02 -030089
90/*------------------------------------------------------------------------------
91DEFINES
92------------------------------------------------------------------------------*/
93
94/*------------------------------------------------------------------------------
95MACROS
96------------------------------------------------------------------------------*/
97
98/**
99* \def IS_I2C_10BIT( addr )
100* \brief Determine if I2C address 'addr' is a 10 bits address or not.
101* \param addr The I2C address.
102* \return int.
103* \retval 0 if address is not a 10 bits I2C address.
104* \retval 1 if address is a 10 bits I2C address.
105*/
106#define IS_I2C_10BIT(addr) \
107 (((addr) & 0xF8) == 0xF0)
108
109/*------------------------------------------------------------------------------
110ENUM
111------------------------------------------------------------------------------*/
112
113/*------------------------------------------------------------------------------
114STRUCTS
115------------------------------------------------------------------------------*/
116
117/*------------------------------------------------------------------------------
118Exported FUNCTIONS
119------------------------------------------------------------------------------*/
120
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300121/**
122* \fn DRXBSP_I2C_Init()
123* \brief Initialize I2C communication module.
124* \return DRXStatus_t Return status.
125* \retval DRX_STS_OK Initialization successful.
126* \retval DRX_STS_ERROR Initialization failed.
127*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300128 DRXStatus_t DRXBSP_I2C_Init(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300129
130/**
131* \fn DRXBSP_I2C_Term()
132* \brief Terminate I2C communication module.
133* \return DRXStatus_t Return status.
134* \retval DRX_STS_OK Termination successful.
135* \retval DRX_STS_ERROR Termination failed.
136*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300137 DRXStatus_t DRXBSP_I2C_Term(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300138
139/**
140* \fn DRXStatus_t DRXBSP_I2C_WriteRead( pI2CDeviceAddr_t wDevAddr,
141* u16_t wCount,
142* pu8_t wData,
143* pI2CDeviceAddr_t rDevAddr,
144* u16_t rCount,
145* pu8_t rData)
146* \brief Read and/or write count bytes from I2C bus, store them in data[].
147* \param wDevAddr The device i2c address and the device ID to write to
148* \param wCount The number of bytes to write
149* \param wData The array to write the data to
150* \param rDevAddr The device i2c address and the device ID to read from
151* \param rCount The number of bytes to read
152* \param rData The array to read the data from
153* \return DRXStatus_t Return status.
154* \retval DRX_STS_OK Succes.
155* \retval DRX_STS_ERROR Failure.
156* \retval DRX_STS_INVALID_ARG Parameter 'wcount' is not zero but parameter
157* 'wdata' contains NULL.
158* Idem for 'rcount' and 'rdata'.
159* Both wDevAddr and rDevAddr are NULL.
160*
161* This function must implement an atomic write and/or read action on the I2C bus
162* No other process may use the I2C bus when this function is executing.
163* The critical section of this function runs from and including the I2C
164* write, up to and including the I2C read action.
165*
166* The device ID can be useful if several devices share an I2C address.
167* It can be used to control a "switch" on the I2C bus to the correct device.
168*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300169 DRXStatus_t DRXBSP_I2C_WriteRead(pI2CDeviceAddr_t wDevAddr,
170 u16_t wCount,
171 pu8_t wData,
172 pI2CDeviceAddr_t rDevAddr,
173 u16_t rCount, pu8_t rData);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300174
175/**
176* \fn DRXBSP_I2C_ErrorText()
177* \brief Returns a human readable error.
178* Counter part of numerical DRX_I2C_Error_g.
179*
180* \return char* Pointer to human readable error text.
181*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300182 char *DRXBSP_I2C_ErrorText(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300183
184/**
185* \var DRX_I2C_Error_g;
186* \brief I2C specific error codes, platform dependent.
187*/
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300188 extern int DRX_I2C_Error_g;
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300189
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300190#endif /* __BSPI2C_H__ */