]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
2 | SMBUS Functions\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
fb3df220 | 13 | **/\r |
14 | \r | |
15 | #ifndef __SMBUS_LIB__\r | |
16 | #define __SMBUS_LIB__\r | |
17 | \r | |
fc30687f | 18 | ///\r |
19 | /// PEC BIT is bit 22 in SMBUS address\r | |
20 | ///\r | |
fb3df220 | 21 | #define SMBUS_LIB_PEC_BIT (1 << 22)\r |
22 | \r | |
23 | /**\r | |
24 | Macro that converts SMBUS slave address, SMBUS command, SMBUS data length,\r | |
25 | and PEC to a value that can be passed to the SMBUS Library functions.\r | |
26 | \r | |
27 | Computes an address that is compatible with the SMBUS Library functions.\r | |
28 | The unused upper bits of SlaveAddress, Command, and Length are stripped\r | |
29 | prior to the generation of the address.\r | |
30 | \r | |
31 | @param SlaveAddress SMBUS Slave Address. Range 0..127.\r | |
32 | @param Command SMBUS Command. Range 0..255.\r | |
33 | @param Length SMBUS Data Length. Range 0..32.\r | |
34 | @param Pec TRUE if Packet Error Checking is enabled. Otherwise FALSE.\r | |
35 | \r | |
36 | **/\r | |
37 | #define SMBUS_LIB_ADDRESS(SlaveAddress,Command,Length,Pec) \\r | |
38 | ( ((Pec) ? SMBUS_LIB_PEC_BIT: 0) | \\r | |
39 | (((SlaveAddress) & 0x7f) << 1) | \\r | |
40 | (((Command) & 0xff) << 8) | \\r | |
41 | (((Length) & 0x3f) << 16) \\r | |
42 | )\r | |
43 | \r | |
44 | /**\r | |
45 | Executes an SMBUS quick read command.\r | |
46 | \r | |
47 | Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.\r | |
48 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
49 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
50 | If PEC is set in SmBusAddress, then ASSERT().\r | |
51 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
52 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
53 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
54 | \r | |
55 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
56 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
57 | @param Status Return status for the executed command.\r | |
58 | This is an optional parameter and may be NULL.\r | |
59 | \r | |
60 | **/\r | |
61 | VOID\r | |
62 | EFIAPI\r | |
63 | SmBusQuickRead (\r | |
64 | IN UINTN SmBusAddress,\r | |
65 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 66 | );\r |
fb3df220 | 67 | \r |
68 | /**\r | |
69 | Executes an SMBUS quick write command.\r | |
70 | \r | |
71 | Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.\r | |
72 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
73 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
74 | If PEC is set in SmBusAddress, then ASSERT().\r | |
75 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
76 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
77 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
78 | \r | |
79 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
80 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
81 | @param Status Return status for the executed command.\r | |
82 | This is an optional parameter and may be NULL.\r | |
83 | \r | |
84 | **/\r | |
85 | VOID\r | |
86 | EFIAPI\r | |
87 | SmBusQuickWrite (\r | |
88 | IN UINTN SmBusAddress,\r | |
89 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 90 | );\r |
fb3df220 | 91 | \r |
92 | /**\r | |
93 | Executes an SMBUS receive byte command.\r | |
94 | \r | |
95 | Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.\r | |
96 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
97 | The byte received from the SMBUS is returned.\r | |
98 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
99 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
100 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
101 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
102 | \r | |
103 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
104 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
105 | @param Status Return status for the executed command.\r | |
106 | This is an optional parameter and may be NULL.\r | |
107 | \r | |
108 | @return The byte received from the SMBUS.\r | |
109 | \r | |
110 | **/\r | |
111 | UINT8\r | |
112 | EFIAPI\r | |
113 | SmBusReceiveByte (\r | |
114 | IN UINTN SmBusAddress,\r | |
115 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 116 | );\r |
fb3df220 | 117 | \r |
118 | /**\r | |
119 | Executes an SMBUS send byte command.\r | |
120 | \r | |
121 | Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.\r | |
122 | The byte specified by Value is sent.\r | |
123 | Only the SMBUS slave address field of SmBusAddress is required. Value is returned.\r | |
124 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
125 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
126 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
127 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
128 | \r | |
129 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
130 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
131 | @param Value The 8-bit value to send.\r | |
132 | @param Status Return status for the executed command.\r | |
133 | This is an optional parameter and may be NULL.\r | |
134 | \r | |
135 | @return The parameter of Value.\r | |
136 | \r | |
137 | **/\r | |
138 | UINT8\r | |
139 | EFIAPI\r | |
140 | SmBusSendByte (\r | |
141 | IN UINTN SmBusAddress,\r | |
142 | IN UINT8 Value,\r | |
143 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 144 | );\r |
fb3df220 | 145 | \r |
146 | /**\r | |
147 | Executes an SMBUS read data byte command.\r | |
148 | \r | |
149 | Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.\r | |
150 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
151 | The 8-bit value read from the SMBUS is returned.\r | |
152 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
153 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
154 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
155 | \r | |
156 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
157 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
158 | @param Status Return status for the executed command.\r | |
159 | This is an optional parameter and may be NULL.\r | |
160 | \r | |
161 | @return The byte read from the SMBUS.\r | |
162 | \r | |
163 | **/\r | |
164 | UINT8\r | |
165 | EFIAPI\r | |
166 | SmBusReadDataByte (\r | |
167 | IN UINTN SmBusAddress,\r | |
168 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 169 | );\r |
fb3df220 | 170 | \r |
171 | /**\r | |
172 | Executes an SMBUS write data byte command.\r | |
173 | \r | |
174 | Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.\r | |
175 | The 8-bit value specified by Value is written.\r | |
176 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
177 | Value is returned.\r | |
178 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
179 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
180 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
181 | \r | |
182 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
183 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
184 | @param Value The 8-bit value to write.\r | |
185 | @param Status Return status for the executed command.\r | |
186 | This is an optional parameter and may be NULL.\r | |
187 | \r | |
188 | @return The parameter of Value.\r | |
189 | \r | |
190 | **/\r | |
191 | UINT8\r | |
192 | EFIAPI\r | |
193 | SmBusWriteDataByte (\r | |
194 | IN UINTN SmBusAddress,\r | |
195 | IN UINT8 Value,\r | |
196 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 197 | );\r |
fb3df220 | 198 | \r |
199 | /**\r | |
200 | Executes an SMBUS read data word command.\r | |
201 | \r | |
202 | Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.\r | |
203 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
204 | The 16-bit value read from the SMBUS is returned.\r | |
205 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
206 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
207 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
208 | \r | |
209 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
210 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
211 | @param Status Return status for the executed command.\r | |
212 | This is an optional parameter and may be NULL.\r | |
213 | \r | |
214 | @return The byte read from the SMBUS.\r | |
215 | \r | |
216 | **/\r | |
217 | UINT16\r | |
218 | EFIAPI\r | |
219 | SmBusReadDataWord (\r | |
220 | IN UINTN SmBusAddress,\r | |
221 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 222 | );\r |
fb3df220 | 223 | \r |
224 | /**\r | |
225 | Executes an SMBUS write data word command.\r | |
226 | \r | |
227 | Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.\r | |
228 | The 16-bit value specified by Value is written.\r | |
229 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
230 | Value is returned.\r | |
231 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
232 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
233 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
234 | \r | |
235 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
236 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
237 | @param Value The 16-bit value to write.\r | |
238 | @param Status Return status for the executed command.\r | |
239 | This is an optional parameter and may be NULL.\r | |
240 | \r | |
241 | @return The parameter of Value.\r | |
242 | \r | |
243 | **/\r | |
244 | UINT16\r | |
245 | EFIAPI\r | |
246 | SmBusWriteDataWord (\r | |
247 | IN UINTN SmBusAddress,\r | |
248 | IN UINT16 Value,\r | |
249 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 250 | );\r |
fb3df220 | 251 | \r |
252 | /**\r | |
253 | Executes an SMBUS process call command.\r | |
254 | \r | |
255 | Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.\r | |
256 | The 16-bit value specified by Value is written.\r | |
257 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
258 | The 16-bit value returned by the process call command is returned.\r | |
259 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
260 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
261 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
262 | \r | |
263 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
264 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
265 | @param Value The 16-bit value to write.\r | |
266 | @param Status Return status for the executed command.\r | |
267 | This is an optional parameter and may be NULL.\r | |
268 | \r | |
269 | @return The 16-bit value returned by the process call command.\r | |
270 | \r | |
271 | **/\r | |
272 | UINT16\r | |
273 | EFIAPI\r | |
274 | SmBusProcessCall (\r | |
275 | IN UINTN SmBusAddress,\r | |
276 | IN UINT16 Value,\r | |
277 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 278 | );\r |
fb3df220 | 279 | \r |
280 | /**\r | |
281 | Executes an SMBUS read block command.\r | |
282 | \r | |
283 | Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.\r | |
284 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
285 | Bytes are read from the SMBUS and stored in Buffer.\r | |
286 | The number of bytes read is returned, and will never return a value larger than 32-bytes.\r | |
287 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
288 | It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r | |
289 | SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r | |
290 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
291 | If Buffer is NULL, then ASSERT().\r | |
292 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
293 | \r | |
294 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
295 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
296 | @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r | |
297 | @param Status Return status for the executed command.\r | |
298 | This is an optional parameter and may be NULL.\r | |
299 | \r | |
300 | @return The number of bytes read.\r | |
301 | \r | |
302 | **/\r | |
303 | UINTN\r | |
304 | EFIAPI\r | |
305 | SmBusReadBlock (\r | |
306 | IN UINTN SmBusAddress,\r | |
307 | OUT VOID *Buffer,\r | |
308 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 309 | );\r |
fb3df220 | 310 | \r |
311 | /**\r | |
312 | Executes an SMBUS write block command.\r | |
313 | \r | |
314 | Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.\r | |
315 | The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r | |
316 | Bytes are written to the SMBUS from Buffer.\r | |
317 | The number of bytes written is returned, and will never return a value larger than 32-bytes.\r | |
318 | If Status is not NULL, then the status of the executed command is returned in Status. \r | |
319 | If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r | |
320 | If Buffer is NULL, then ASSERT().\r | |
321 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
322 | \r | |
323 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
324 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
325 | @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r | |
326 | @param Status Return status for the executed command.\r | |
327 | This is an optional parameter and may be NULL.\r | |
328 | \r | |
329 | @return The number of bytes written.\r | |
330 | \r | |
331 | **/\r | |
332 | UINTN\r | |
333 | EFIAPI\r | |
334 | SmBusWriteBlock (\r | |
335 | IN UINTN SmBusAddress,\r | |
336 | OUT VOID *Buffer,\r | |
337 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 338 | );\r |
fb3df220 | 339 | \r |
340 | /**\r | |
341 | Executes an SMBUS block process call command.\r | |
342 | \r | |
343 | Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r | |
344 | The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r | |
345 | Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.\r | |
346 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
347 | It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r | |
348 | SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r | |
349 | If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r | |
350 | If WriteBuffer is NULL, then ASSERT().\r | |
351 | If ReadBuffer is NULL, then ASSERT().\r | |
352 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
353 | \r | |
354 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
355 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
356 | @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.\r | |
357 | @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.\r | |
358 | @param Status Return status for the executed command.\r | |
359 | This is an optional parameter and may be NULL.\r | |
360 | \r | |
361 | @return The number of bytes written.\r | |
362 | \r | |
363 | **/\r | |
364 | UINTN\r | |
365 | EFIAPI\r | |
366 | SmBusBlockProcessCall (\r | |
367 | IN UINTN SmBusAddress,\r | |
368 | IN VOID *WriteBuffer,\r | |
369 | OUT VOID *ReadBuffer,\r | |
370 | OUT RETURN_STATUS *Status OPTIONAL\r | |
dca1cc59 | 371 | );\r |
fb3df220 | 372 | \r |
373 | \r | |
374 | #endif\r |