]>
Commit | Line | Data |
---|---|---|
9b6bbcdb MK |
1 | /** @file\r |
2 | Provides definition of entry point to the common I2C module that produces\r | |
3 | common I2C Controller functions used by I2C library services.\r | |
4 | \r | |
5 | \r | |
6 | Copyright (c) 2013-2015 Intel Corporation.\r | |
7 | \r | |
8 | This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | \r | |
19 | #ifndef _I2CCOMMON_H_\r | |
20 | #define _I2CCOMMON_H_\r | |
21 | \r | |
22 | #include <Uefi.h>\r | |
23 | #include <Base.h>\r | |
24 | \r | |
25 | #include <Library/DebugLib.h>\r | |
26 | #include <Library/TimerLib.h>\r | |
27 | #include <Library/I2cLib.h>\r | |
28 | #include <IohAccess.h>\r | |
29 | #include <IohCommonDefinitions.h>\r | |
30 | #include "I2cRegs.h"\r | |
31 | \r | |
32 | //\r | |
33 | // Constants that define I2C Controller timeout and max. polling time.\r | |
34 | //\r | |
35 | #define MAX_T_POLL_COUNT 100\r | |
36 | #define TI2C_POLL 25 // microseconds\r | |
37 | #define MAX_STOP_DET_POLL_COUNT ((1000 * 1000) / TI2C_POLL) // Extreme for expected Stop detect.\r | |
38 | \r | |
39 | /**\r | |
40 | The GetI2CIoPortBaseAddress() function gets IO port base address of I2C Controller.\r | |
41 | \r | |
42 | Always reads PCI configuration space to get MMIO base address of I2C Controller.\r | |
43 | \r | |
44 | @return The IO port base address of I2C controller.\r | |
45 | \r | |
46 | **/\r | |
47 | UINTN\r | |
48 | GetI2CIoPortBaseAddress (\r | |
49 | VOID\r | |
50 | );\r | |
51 | \r | |
52 | /**\r | |
53 | The EnableI2CMmioSpace() function enables access to I2C MMIO space.\r | |
54 | \r | |
55 | **/\r | |
56 | VOID\r | |
57 | EnableI2CMmioSpace (\r | |
58 | VOID\r | |
59 | );\r | |
60 | \r | |
61 | /**\r | |
62 | The DisableI2CController() functions disables I2C Controller.\r | |
63 | \r | |
64 | **/\r | |
65 | VOID\r | |
66 | DisableI2CController (\r | |
67 | VOID\r | |
68 | );\r | |
69 | \r | |
70 | /**\r | |
71 | The EnableI2CController() function enables the I2C Controller.\r | |
72 | \r | |
73 | **/\r | |
74 | VOID\r | |
75 | EnableI2CController (\r | |
76 | VOID\r | |
77 | );\r | |
78 | \r | |
79 | /**\r | |
80 | The WaitForStopDet() function waits until I2C STOP Condition occurs,\r | |
81 | indicating transfer completion.\r | |
82 | \r | |
83 | @retval EFI_SUCCESS Stop detected.\r | |
84 | @retval EFI_TIMEOUT Timeout while waiting for stop condition.\r | |
85 | @retval EFI_ABORTED Tx abort signaled in HW status register.\r | |
86 | @retval EFI_DEVICE_ERROR Tx or Rx overflow detected.\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | WaitForStopDet (\r | |
91 | VOID\r | |
92 | );\r | |
93 | \r | |
94 | /**\r | |
95 | \r | |
96 | The InitializeInternal() function initialises internal I2C Controller\r | |
97 | register values that are commonly required for I2C Write and Read transfers.\r | |
98 | \r | |
99 | @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.\r | |
100 | \r | |
101 | @retval EFI_SUCCESS I2C Operation completed successfully.\r | |
102 | \r | |
103 | **/\r | |
104 | EFI_STATUS\r | |
105 | InitializeInternal (\r | |
106 | IN EFI_I2C_ADDR_MODE AddrMode\r | |
107 | );\r | |
108 | \r | |
109 | /**\r | |
110 | \r | |
111 | The WriteByte() function provides a standard way to execute a\r | |
112 | standard single byte write to an IC2 device (without accessing\r | |
113 | sub-addresses), as defined in the I2C Specification.\r | |
114 | \r | |
115 | @param I2CAddress I2C Slave device address\r | |
116 | @param Value The 8-bit value to write.\r | |
117 | \r | |
118 | @retval EFI_SUCCESS Transfer success.\r | |
119 | @retval EFI_UNSUPPORTED Unsupported input param.\r | |
120 | @retval EFI_TIMEOUT Timeout while waiting xfer.\r | |
121 | @retval EFI_ABORTED Controller aborted xfer.\r | |
122 | @retval EFI_DEVICE_ERROR Device error detected by controller.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | EFIAPI\r | |
127 | WriteByte (\r | |
128 | IN UINTN I2CAddress,\r | |
129 | IN UINT8 Value\r | |
130 | );\r | |
131 | \r | |
132 | /**\r | |
133 | \r | |
134 | The ReadByte() function provides a standard way to execute a\r | |
135 | standard single byte read to an IC2 device (without accessing\r | |
136 | sub-addresses), as defined in the I2C Specification.\r | |
137 | \r | |
138 | @param I2CAddress I2C Slave device address\r | |
139 | @param ReturnDataPtr Pointer to location to receive read byte.\r | |
140 | \r | |
141 | @retval EFI_SUCCESS Transfer success.\r | |
142 | @retval EFI_UNSUPPORTED Unsupported input param.\r | |
143 | @retval EFI_TIMEOUT Timeout while waiting xfer.\r | |
144 | @retval EFI_ABORTED Controller aborted xfer.\r | |
145 | @retval EFI_DEVICE_ERROR Device error detected by controller.\r | |
146 | \r | |
147 | **/\r | |
148 | EFI_STATUS\r | |
149 | EFIAPI\r | |
150 | ReadByte (\r | |
151 | IN UINTN I2CAddress,\r | |
152 | OUT UINT8 *ReturnDataPtr\r | |
153 | );\r | |
154 | \r | |
155 | /**\r | |
156 | \r | |
157 | The WriteMultipleByte() function provides a standard way to execute\r | |
158 | multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or\r | |
159 | when writing block of data), as defined in the I2C Specification.\r | |
160 | \r | |
161 | @param I2CAddress The I2C slave address of the device\r | |
162 | with which to communicate.\r | |
163 | \r | |
164 | @param WriteBuffer Contains the value of byte to be written to the\r | |
165 | I2C slave device.\r | |
166 | \r | |
167 | @param Length No. of bytes to be written.\r | |
168 | \r | |
169 | @retval EFI_SUCCESS Transfer success.\r | |
170 | @retval EFI_UNSUPPORTED Unsupported input param.\r | |
171 | @retval EFI_TIMEOUT Timeout while waiting xfer.\r | |
172 | @retval EFI_ABORTED Tx abort signaled in HW status register.\r | |
173 | @retval EFI_DEVICE_ERROR Tx overflow detected.\r | |
174 | \r | |
175 | **/\r | |
176 | EFI_STATUS\r | |
177 | EFIAPI\r | |
178 | WriteMultipleByte (\r | |
179 | IN UINTN I2CAddress,\r | |
180 | IN UINT8 *WriteBuffer,\r | |
181 | IN UINTN Length\r | |
182 | );\r | |
183 | \r | |
184 | /**\r | |
185 | \r | |
186 | The ReadMultipleByte() function provides a standard way to execute\r | |
187 | multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or\r | |
188 | when reading block of data), as defined in the I2C Specification (I2C combined\r | |
189 | write/read protocol).\r | |
190 | \r | |
191 | @param I2CAddress The I2C slave address of the device\r | |
192 | with which to communicate.\r | |
193 | \r | |
194 | @param Buffer Contains the value of byte data written or read from the\r | |
195 | I2C slave device.\r | |
196 | \r | |
197 | @param WriteLength No. of bytes to be written. In this case data\r | |
198 | written typically contains sub-address or sub-addresses\r | |
199 | in Hi-Lo format, that need to be read (I2C combined\r | |
200 | write/read protocol).\r | |
201 | \r | |
202 | @param ReadLength No. of bytes to be read from I2C slave device.\r | |
203 | \r | |
204 | @retval EFI_SUCCESS Transfer success.\r | |
205 | @retval EFI_UNSUPPORTED Unsupported input param.\r | |
206 | @retval EFI_TIMEOUT Timeout while waiting xfer.\r | |
207 | @retval EFI_ABORTED Tx abort signaled in HW status register.\r | |
208 | @retval EFI_DEVICE_ERROR Rx underflow or Rx/Tx overflow detected.\r | |
209 | \r | |
210 | **/\r | |
211 | EFI_STATUS\r | |
212 | EFIAPI\r | |
213 | ReadMultipleByte (\r | |
214 | IN UINTN I2CAddress,\r | |
215 | IN OUT UINT8 *Buffer,\r | |
216 | IN UINTN WriteLength,\r | |
217 | IN UINTN ReadLength\r | |
218 | );\r | |
219 | \r | |
220 | #endif\r |