summaryrefslogtreecommitdiffstats
path: root/main/common/i2c.h
blob: 3be9c4dd3e0d56b6592216ffbd64a8a3a7863e9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**************************************************************************
 *
 * Copyright (c) 2013 Alcatel-Lucent
 *
 * Alcatel Lucent licenses this file to You under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License.  A copy of the License is contained the
 * file LICENSE at the top level of this repository.
 * You may also obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **************************************************************************
 *
 * i2c.h:
 *
 * Header for I-Squared-C code.
 *
 * Original author:     Ed Sutter (ed.sutter@alcatel-lucent.com)
 *
 */
#ifndef _I2C_H_
#define _I2C_H_

extern int i2cVerbose;

/********************************************************************
 *
 * Commands used by i2cCtrl():
 */
#define I2CCTRL_INIT    1
#define I2CCTRL_SHOW    2
#define I2CCTRL_START   3       /* Send START condition */
#define I2CCTRL_STOP    4       /* Send STOP condition */
#define I2CCTRL_WADD    5       /* Send Write address */
#define I2CCTRL_RADD    6       /* Send Read address */
#define I2CCTRL_RDAT    7       /* Read data */
#define I2CCTRL_WDAT    8       /* Write data */
#define I2CCTRL_SACK    9       /* Send ACK */
#define I2CCTRL_WACK    10      /* WaitFor ACK */

/********************************************************************
 *
 * Upper bits of the bigaddr integer used for special case read/write
 */
#define REPEATED_START  0x40000000
#define OMIT_STOP       0x20000000

/********************************************************************
 *
 * Functions that must be provided from some target-specific code.
 */


/* i2cCtrl()
 * Parameters:
 *  int interface-
 *      This parameter supports the case where the target hardware has more
 *      than one i2c controller.  The interface number would correspond to
 *      one of potentially several different controllers.
 *  int cmd-
 *      Command to be carried out by the control function.
 *  ulong arg1-
 *      First command-specific argument.
 *  ulong arg2-
 *      Second command-specific argument.
 */
extern int i2cCtrl(int interface,int cmd,unsigned long arg1,unsigned long arg2);

/* i2cRead()
 * Parameters:
 *  int interface-
 *      See description under i2cCtrl.
 *  int bigaddr-
 *      The device address on the I2C bus.  Referred to here as "big" because
 *      it is an "int" so it supports 10-bit addresses (if needed).
 *  uchar *data-
 *      Pointer to the data buffer into which the data is to be placed.
 *  int len-
 *      Number of bytes to be read from the I2C device.  This must not be
 *      larger than the size of the data buffer.
 * Return:
 *  int
 *      The function should return the number of bytes read.  If everything
 *      went well, then the return value should equal the len parameter.
 *      Negative represents some failure.
 */
extern int i2cRead(int interface,int bigaddr,unsigned char *data,int len);

/* i2cWrite()
 * Parameters:
 *  int interface-
 *      See description under i2cCtrl.
 *  int bigaddr-
 *      See description under i2cRead.
 *  uchar *data-
 *      Buffer from which the data is to be taken and put into the specified
 *      I2C device.
 *  int len-
 *      Number of bytes to be written.
 * Return:
 *  int
 *      The function should return the number of bytes written.  If everything
 *      went well, then the return value should equal the len parameter.
 *      Negative represents some failure.
 */
extern int i2cWrite(int interface,int bigaddr,unsigned char *data,int len);

/* i2cShow()
 * Parameters:
 *  int interface-
 *      See description under i2cCtrl.
 * Return:
 *  void
 *      The function should be part of target-specific code that simply
 *      prints out a list of the device names and their address on the
 *      I-Squared-C bus of the specfied interface.
 */
extern void i2cShow(int interface);

#endif