1 | /************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (c) 2013 Alcatel-Lucent |
---|
4 | * |
---|
5 | * Alcatel Lucent licenses this file to You under the Apache License, |
---|
6 | * Version 2.0 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. A copy of the License is contained the |
---|
8 | * file LICENSE at the top level of this repository. |
---|
9 | * You may also obtain a copy of the License at: |
---|
10 | * |
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | * |
---|
13 | * Unless required by applicable law or agreed to in writing, software |
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | * See the License for the specific language governing permissions and |
---|
17 | * limitations under the License. |
---|
18 | * |
---|
19 | ************************************************************************** |
---|
20 | * |
---|
21 | * i2c.h: |
---|
22 | * |
---|
23 | * Header for I-Squared-C code. |
---|
24 | * |
---|
25 | * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) |
---|
26 | * |
---|
27 | */ |
---|
28 | #ifndef _I2C_H_ |
---|
29 | #define _I2C_H_ |
---|
30 | |
---|
31 | extern int i2cVerbose; |
---|
32 | |
---|
33 | /******************************************************************** |
---|
34 | * |
---|
35 | * Commands used by i2cCtrl(): |
---|
36 | */ |
---|
37 | #define I2CCTRL_INIT 1 |
---|
38 | #define I2CCTRL_SHOW 2 |
---|
39 | #define I2CCTRL_START 3 /* Send START condition */ |
---|
40 | #define I2CCTRL_STOP 4 /* Send STOP condition */ |
---|
41 | #define I2CCTRL_WADD 5 /* Send Write address */ |
---|
42 | #define I2CCTRL_RADD 6 /* Send Read address */ |
---|
43 | #define I2CCTRL_RDAT 7 /* Read data */ |
---|
44 | #define I2CCTRL_WDAT 8 /* Write data */ |
---|
45 | #define I2CCTRL_SACK 9 /* Send ACK */ |
---|
46 | #define I2CCTRL_WACK 10 /* WaitFor ACK */ |
---|
47 | |
---|
48 | /******************************************************************** |
---|
49 | * |
---|
50 | * Upper bits of the bigaddr integer used for special case read/write |
---|
51 | */ |
---|
52 | #define REPEATED_START 0x40000000 |
---|
53 | #define OMIT_STOP 0x20000000 |
---|
54 | |
---|
55 | /******************************************************************** |
---|
56 | * |
---|
57 | * Functions that must be provided from some target-specific code. |
---|
58 | */ |
---|
59 | |
---|
60 | |
---|
61 | /* i2cCtrl() |
---|
62 | * Parameters: |
---|
63 | * int interface- |
---|
64 | * This parameter supports the case where the target hardware has more |
---|
65 | * than one i2c controller. The interface number would correspond to |
---|
66 | * one of potentially several different controllers. |
---|
67 | * int cmd- |
---|
68 | * Command to be carried out by the control function. |
---|
69 | * ulong arg1- |
---|
70 | * First command-specific argument. |
---|
71 | * ulong arg2- |
---|
72 | * Second command-specific argument. |
---|
73 | */ |
---|
74 | extern int i2cCtrl(int interface,int cmd,unsigned long arg1,unsigned long arg2); |
---|
75 | |
---|
76 | /* i2cRead() |
---|
77 | * Parameters: |
---|
78 | * int interface- |
---|
79 | * See description under i2cCtrl. |
---|
80 | * int bigaddr- |
---|
81 | * The device address on the I2C bus. Referred to here as "big" because |
---|
82 | * it is an "int" so it supports 10-bit addresses (if needed). |
---|
83 | * uchar *data- |
---|
84 | * Pointer to the data buffer into which the data is to be placed. |
---|
85 | * int len- |
---|
86 | * Number of bytes to be read from the I2C device. This must not be |
---|
87 | * larger than the size of the data buffer. |
---|
88 | * Return: |
---|
89 | * int |
---|
90 | * The function should return the number of bytes read. If everything |
---|
91 | * went well, then the return value should equal the len parameter. |
---|
92 | * Negative represents some failure. |
---|
93 | */ |
---|
94 | extern int i2cRead(int interface,int bigaddr,unsigned char *data,int len); |
---|
95 | |
---|
96 | /* i2cWrite() |
---|
97 | * Parameters: |
---|
98 | * int interface- |
---|
99 | * See description under i2cCtrl. |
---|
100 | * int bigaddr- |
---|
101 | * See description under i2cRead. |
---|
102 | * uchar *data- |
---|
103 | * Buffer from which the data is to be taken and put into the specified |
---|
104 | * I2C device. |
---|
105 | * int len- |
---|
106 | * Number of bytes to be written. |
---|
107 | * Return: |
---|
108 | * int |
---|
109 | * The function should return the number of bytes written. If everything |
---|
110 | * went well, then the return value should equal the len parameter. |
---|
111 | * Negative represents some failure. |
---|
112 | */ |
---|
113 | extern int i2cWrite(int interface,int bigaddr,unsigned char *data,int len); |
---|
114 | |
---|
115 | /* i2cShow() |
---|
116 | * Parameters: |
---|
117 | * int interface- |
---|
118 | * See description under i2cCtrl. |
---|
119 | * Return: |
---|
120 | * void |
---|
121 | * The function should be part of target-specific code that simply |
---|
122 | * prints out a list of the device names and their address on the |
---|
123 | * I-Squared-C bus of the specfied interface. |
---|
124 | */ |
---|
125 | extern void i2cShow(int interface); |
---|
126 | |
---|
127 | #endif |
---|