blob: dd2fc797a991bf72bce32e19955e24f27c19390e [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
Devin Heitmueller38b2df92012-08-13 21:18:02 -030045#ifndef __BSPI2C_H__
46#define __BSPI2C_H__
Mauro Carvalho Chehab5b223b32012-03-20 00:33:46 -030047
Devin Heitmueller38b2df92012-08-13 21:18:02 -030048#include "bsp_types.h"
49
Mauro Carvalho Chehab5b223b32012-03-20 00:33:46 -030050/*
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030051 * This structure contains the I2C address, the device ID and a user_data pointer.
52 * The user_data pointer can be used for application specific purposes.
Mauro Carvalho Chehab5b223b32012-03-20 00:33:46 -030053 */
54struct i2c_device_addr {
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030055 u16 i2c_addr; /* The I2C address of the device. */
56 u16 i2c_dev_id; /* The device identifier. */
57 void *user_data; /* User data pointer */
Mauro Carvalho Chehab5b223b32012-03-20 00:33:46 -030058};
Devin Heitmueller38b2df92012-08-13 21:18:02 -030059
Devin Heitmueller38b2df92012-08-13 21:18:02 -030060
61/**
62* \def IS_I2C_10BIT( addr )
63* \brief Determine if I2C address 'addr' is a 10 bits address or not.
64* \param addr The I2C address.
65* \return int.
66* \retval 0 if address is not a 10 bits I2C address.
67* \retval 1 if address is a 10 bits I2C address.
68*/
69#define IS_I2C_10BIT(addr) \
70 (((addr) & 0xF8) == 0xF0)
71
72/*------------------------------------------------------------------------------
Devin Heitmueller38b2df92012-08-13 21:18:02 -030073Exported FUNCTIONS
74------------------------------------------------------------------------------*/
75
Devin Heitmueller38b2df92012-08-13 21:18:02 -030076/**
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030077* \fn drxbsp_i2c_init()
Devin Heitmueller38b2df92012-08-13 21:18:02 -030078* \brief Initialize I2C communication module.
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030079* \return drx_status_t Return status.
Devin Heitmueller38b2df92012-08-13 21:18:02 -030080* \retval DRX_STS_OK Initialization successful.
81* \retval DRX_STS_ERROR Initialization failed.
82*/
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030083 drx_status_t drxbsp_i2c_init(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -030084
85/**
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030086* \fn drxbsp_i2c_term()
Devin Heitmueller38b2df92012-08-13 21:18:02 -030087* \brief Terminate I2C communication module.
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030088* \return drx_status_t Return status.
Devin Heitmueller38b2df92012-08-13 21:18:02 -030089* \retval DRX_STS_OK Termination successful.
90* \retval DRX_STS_ERROR Termination failed.
91*/
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030092 drx_status_t drxbsp_i2c_term(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -030093
94/**
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030095* \fn drx_status_t drxbsp_i2c_write_read( struct i2c_device_addr *w_dev_addr,
96* u16 w_count,
Mauro Carvalho Chehab43a431e2012-03-20 00:49:45 -030097* u8 *wData,
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -030098* struct i2c_device_addr *r_dev_addr,
99* u16 r_count,
100* u8 *r_data)
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300101* \brief Read and/or write count bytes from I2C bus, store them in data[].
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300102* \param w_dev_addr The device i2c address and the device ID to write to
103* \param w_count The number of bytes to write
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300104* \param wData The array to write the data to
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300105* \param r_dev_addr The device i2c address and the device ID to read from
106* \param r_count The number of bytes to read
107* \param r_data The array to read the data from
108* \return drx_status_t Return status.
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300109* \retval DRX_STS_OK Succes.
110* \retval DRX_STS_ERROR Failure.
111* \retval DRX_STS_INVALID_ARG Parameter 'wcount' is not zero but parameter
112* 'wdata' contains NULL.
113* Idem for 'rcount' and 'rdata'.
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300114* Both w_dev_addr and r_dev_addr are NULL.
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300115*
116* This function must implement an atomic write and/or read action on the I2C bus
117* No other process may use the I2C bus when this function is executing.
118* The critical section of this function runs from and including the I2C
119* write, up to and including the I2C read action.
120*
121* The device ID can be useful if several devices share an I2C address.
122* It can be used to control a "switch" on the I2C bus to the correct device.
123*/
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300124 drx_status_t drxbsp_i2c_write_read(struct i2c_device_addr *w_dev_addr,
125 u16 w_count,
Mauro Carvalho Chehab43a431e2012-03-20 00:49:45 -0300126 u8 *wData,
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300127 struct i2c_device_addr *r_dev_addr,
128 u16 r_count, u8 *r_data);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300129
130/**
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300131* \fn drxbsp_i2c_error_text()
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300132* \brief Returns a human readable error.
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300133* Counter part of numerical drx_i2c_error_g.
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300134*
135* \return char* Pointer to human readable error text.
136*/
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300137 char *drxbsp_i2c_error_text(void);
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300138
139/**
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300140* \var drx_i2c_error_g;
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300141* \brief I2C specific error codes, platform dependent.
142*/
Mauro Carvalho Chehab57afe2f2014-01-16 11:24:57 -0300143 extern int drx_i2c_error_g;
Devin Heitmueller38b2df92012-08-13 21:18:02 -0300144
Mauro Carvalho Chehab443f18d2012-03-20 00:00:42 -0300145#endif /* __BSPI2C_H__ */