4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: SmbusLib.h
21 Macro that converts SMBUS slave address, SMBUS command, SMBUS data length,
22 and PEC to a value that can be passed to the SMBUS Library functions.
24 Computes an address that is compatible with the SMBUS Library functions.
25 The unused upper bits of SlaveAddress, Command, and Length are stripped
26 prior to the generation of the address.
28 @param SlaveAddress SMBUS Slave Address. Range 0..127.
29 @param Command SMBUS Command. Range 0..255.
30 @param Length SMBUS Data Length. Range 0..32.
31 @param Pec TRUE if Packet Error Checking is enabled. Otherwise FALSE.
34 #define SMBUS_LIB_ADDRESS(SlaveAddress,Command,Length,Pec) \
35 ( ((Pec) ? MAX_BIT : 0) | \
36 (((SlaveAddress) & 0x7f) << 1) | \
37 (((Command) & 0xff) << 8) | \
38 (((Length) & 0x1f) << 16) \
42 Executes an SMBUS quick read command.
44 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.
45 Only the SMBUS slave address field of SmBusAddress is required.
46 If Status is not NULL, then the status of the executed command is returned in Status.
47 If PEC is set in SmBusAddress, then ASSERT().
48 If Command in SmBusAddress is not zero, then ASSERT().
49 If Length in SmBusAddress is not zero, then ASSERT().
50 If any reserved bits of SmBusAddress are set, then ASSERT().
52 @param SmBusAddress Address that encodes the SMBUS Slave Address,
53 SMBUS Command, SMBUS Data Length, and PEC.
54 @param Status Return status for the executed command.
55 This is an optional parameter and may be NULL.
61 IN UINTN SmBusAddress
,
62 OUT RETURN_STATUS
*Status OPTIONAL
67 Executes an SMBUS quick write command.
69 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.
70 Only the SMBUS slave address field of SmBusAddress is required.
71 If Status is not NULL, then the status of the executed command is returned in Status.
72 If PEC is set in SmBusAddress, then ASSERT().
73 If Command in SmBusAddress is not zero, then ASSERT().
74 If Length in SmBusAddress is not zero, then ASSERT().
75 If any reserved bits of SmBusAddress are set, then ASSERT().
77 @param SmBusAddress Address that encodes the SMBUS Slave Address,
78 SMBUS Command, SMBUS Data Length, and PEC.
79 @param Status Return status for the executed command.
80 This is an optional parameter and may be NULL.
86 IN UINTN SmBusAddress
,
87 OUT RETURN_STATUS
*Status OPTIONAL
92 Executes an SMBUS receive byte command.
94 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.
95 Only the SMBUS slave address field of SmBusAddress is required.
96 The byte received from the SMBUS is returned.
97 If Status is not NULL, then the status of the executed command is returned in Status.
98 If Command in SmBusAddress is not zero, then ASSERT().
99 If Length in SmBusAddress is not zero, then ASSERT().
100 If any reserved bits of SmBusAddress are set, then ASSERT().
102 @param SmBusAddress Address that encodes the SMBUS Slave Address,
103 SMBUS Command, SMBUS Data Length, and PEC.
104 @param Status Return status for the executed command.
105 This is an optional parameter and may be NULL.
107 @return The byte received from the SMBUS.
113 IN UINTN SmBusAddress
,
114 OUT RETURN_STATUS
*Status OPTIONAL
119 Executes an SMBUS send byte command.
121 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.
122 The byte specified by Value is sent.
123 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.
124 If Status is not NULL, then the status of the executed command is returned in Status.
125 If Command in SmBusAddress is not zero, then ASSERT().
126 If Length in SmBusAddress is not zero, then ASSERT().
127 If any reserved bits of SmBusAddress are set, then ASSERT().
129 @param SmBusAddress Address that encodes the SMBUS Slave Address,
130 SMBUS Command, SMBUS Data Length, and PEC.
131 @param Value The 8-bit value to send.
132 @param Status Return status for the executed command.
133 This is an optional parameter and may be NULL.
135 @return The parameter of Value.
141 IN UINTN SmBusAddress
,
143 OUT RETURN_STATUS
*Status OPTIONAL
148 Executes an SMBUS read data byte command.
150 Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.
151 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
152 The 8-bit value read from the SMBUS is returned.
153 If Status is not NULL, then the status of the executed command is returned in Status.
154 If Length in SmBusAddress is not zero, then ASSERT().
155 If any reserved bits of SmBusAddress are set, then ASSERT().
157 @param SmBusAddress Address that encodes the SMBUS Slave Address,
158 SMBUS Command, SMBUS Data Length, and PEC.
159 @param Status Return status for the executed command.
160 This is an optional parameter and may be NULL.
162 @return The byte read from the SMBUS.
168 IN UINTN SmBusAddress
,
169 OUT RETURN_STATUS
*Status OPTIONAL
174 Executes an SMBUS write data byte command.
176 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.
177 The 8-bit value specified by Value is written.
178 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
180 If Status is not NULL, then the status of the executed command is returned in Status.
181 If Length in SmBusAddress is not zero, then ASSERT().
182 If any reserved bits of SmBusAddress are set, then ASSERT().
184 @param SmBusAddress Address that encodes the SMBUS Slave Address,
185 SMBUS Command, SMBUS Data Length, and PEC.
186 @param Value The 8-bit value to write.
187 @param Status Return status for the executed command.
188 This is an optional parameter and may be NULL.
190 @return The parameter of Value.
196 IN UINTN SmBusAddress
,
198 OUT RETURN_STATUS
*Status OPTIONAL
203 Executes an SMBUS read data word command.
205 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.
206 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
207 The 16-bit value read from the SMBUS is returned.
208 If Status is not NULL, then the status of the executed command is returned in Status.
209 If Length in SmBusAddress is not zero, then ASSERT().
210 If any reserved bits of SmBusAddress are set, then ASSERT().
212 @param SmBusAddress Address that encodes the SMBUS Slave Address,
213 SMBUS Command, SMBUS Data Length, and PEC.
214 @param Status Return status for the executed command.
215 This is an optional parameter and may be NULL.
217 @return The byte read from the SMBUS.
223 IN UINTN SmBusAddress
,
224 OUT RETURN_STATUS
*Status OPTIONAL
229 Executes an SMBUS write data word command.
231 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.
232 The 16-bit value specified by Value is written.
233 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
235 If Status is not NULL, then the status of the executed command is returned in Status.
236 If Length in SmBusAddress is not zero, then ASSERT().
237 If any reserved bits of SmBusAddress are set, then ASSERT().
239 @param SmBusAddress Address that encodes the SMBUS Slave Address,
240 SMBUS Command, SMBUS Data Length, and PEC.
241 @param Value The 16-bit value to write.
242 @param Status Return status for the executed command.
243 This is an optional parameter and may be NULL.
245 @return The parameter of Value.
251 IN UINTN SmBusAddress
,
253 OUT RETURN_STATUS
*Status OPTIONAL
258 Executes an SMBUS process call command.
260 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.
261 The 16-bit value specified by Value is written.
262 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
263 The 16-bit value returned by the process call command is returned.
264 If Status is not NULL, then the status of the executed command is returned in Status.
265 If Length in SmBusAddress is not zero, then ASSERT().
266 If any reserved bits of SmBusAddress are set, then ASSERT().
268 @param SmBusAddress Address that encodes the SMBUS Slave Address,
269 SMBUS Command, SMBUS Data Length, and PEC.
270 @param Value The 16-bit value to write.
271 @param Status Return status for the executed command.
272 This is an optional parameter and may be NULL.
274 @return The 16-bit value returned by the process call command.
280 IN UINTN SmBusAddress
,
282 OUT RETURN_STATUS
*Status OPTIONAL
287 Executes an SMBUS read block command.
289 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.
290 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
291 Bytes are read from the SMBUS and stored in Buffer.
292 The number of bytes read is returned, and will never return a value larger than 32-bytes.
293 If Status is not NULL, then the status of the executed command is returned in Status.
294 It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.
295 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
296 If Length in SmBusAddress is not zero, then ASSERT().
297 If Buffer is NULL, then ASSERT().
298 If any reserved bits of SmBusAddress are set, then ASSERT().
300 @param SmBusAddress Address that encodes the SMBUS Slave Address,
301 SMBUS Command, SMBUS Data Length, and PEC.
302 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
303 @param Status Return status for the executed command.
304 This is an optional parameter and may be NULL.
306 @return The number of bytes read.
312 IN UINTN SmBusAddress
,
314 OUT RETURN_STATUS
*Status OPTIONAL
319 Executes an SMBUS write block command.
321 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.
322 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
323 Bytes are written to the SMBUS from Buffer.
324 The number of bytes written is returned, and will never return a value larger than 32-bytes.
325 If Status is not NULL, then the status of the executed command is returned in Status.
326 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
327 If Buffer is NULL, then ASSERT().
328 If any reserved bits of SmBusAddress are set, then ASSERT().
330 @param SmBusAddress Address that encodes the SMBUS Slave Address,
331 SMBUS Command, SMBUS Data Length, and PEC.
332 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
333 @param Status Return status for the executed command.
334 This is an optional parameter and may be NULL.
336 @return The number of bytes written.
342 IN UINTN SmBusAddress
,
344 OUT RETURN_STATUS
*Status OPTIONAL
349 Executes an SMBUS block process call command.
351 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.
352 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
353 Bytes are written to the SMBUS from OutBuffer. Bytes are then read from the SMBUS into InBuffer.
354 If Status is not NULL, then the status of the executed command is returned in Status.
355 It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.
356 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
357 If OutBuffer is NULL, then ASSERT().
358 If InBuffer is NULL, then ASSERT().
359 If any reserved bits of SmBusAddress are set, then ASSERT().
362 @param SmBusAddress Address that encodes the SMBUS Slave Address,
363 SMBUS Command, SMBUS Data Length, and PEC.
364 @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS.
365 @param InBuffer Pointer to the buffer of bytes to read from the SMBUS.
366 @param Status Return status for the executed command.
367 This is an optional parameter and may be NULL.
369 @return The number of bytes written.
374 SmBusBlockProcessCall (
375 IN UINTN SmBusAddress
,
378 OUT RETURN_STATUS
*Status OPTIONAL
383 Enumerates the SMBUS and assigns slave addresses.
385 Executes the SMBUS enumeration algorithm and assigns a valid address to all SMBUS slave devices.
386 The total number of SMBUS slave devices detected is returned.
387 The status of the executed command is returned.
388 If Slave Address in SmBusAddress is not zero, then ASSERT().
389 If Command in SmBusAddress is not zero, then ASSERT().
390 If Length in SmBusAddress is not zero, then ASSERT().
391 If PEC in SmBusAddress is set, then ASSERT().
392 If any reserved bits of SmBusAddress are set, then ASSERT().
394 @param SmBusAddress Address that encodes the SMBUS Slave Address,
395 SMBUS Command, SMBUS Data Length, and PEC.
397 @retval RETURN_SUCCESS The SMBUS command was executed.
398 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
399 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
400 in the Host Status Register bit.
401 Device errors are a result of a transaction collision, illegal command field,
402 unclaimed cycle (host initiated), or bus errors (collisions).
408 IN UINTN SmBusAddress
413 Assigns an SMBUS slave addresses.
415 Assigns the SMBUS device specified by Uuid the slave address specified by SmBusAddress.
416 The status of the executed command is returned.
417 If Command in SmBusAddress is not zero, then ASSERT().
418 If Length in SmBusAddress is not zero, then ASSERT().
419 If PEC in SmBusAddress is set, then ASSERT().
420 If any reserved bits of SmBusAddress are set, then ASSERT().
422 @param SmBusAddress Address that encodes the SMBUS Slave Address,
423 SMBUS Command, SMBUS Data Length, and PEC.
424 @param Uuid Pointer to the UUID of the device to assign a slave address.
426 @retval RETURN_SUCCESS The SMBUS command was executed.
427 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
428 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
429 in the Host Status Register bit.
430 Device errors are a result of a transaction collision, illegal command field,
431 unclaimed cycle (host initiated), or bus errors (collisions).
437 IN UINTN SmBusAddress
,
443 Retrieves the UUID associated with an SMBUS slave device.
445 Retrieves the UUID associated with the slave address specified
446 by SmBusAddress and returns the UUID in Uuid.
447 The status of the executed command is returned.
448 If Command in SmBusAddress is not zero, then ASSERT().
449 If Length in SmBusAddress is not zero, then ASSERT().
450 If PEC in SmBusAddress is set, then ASSERT().
451 If Uuid is NULL, then ASSERT().
452 If any reserved bits of SmBusAddress are set, then ASSERT().
454 @param SmBusAddress Address that encodes the SMBUS Slave Address,
455 SMBUS Command, SMBUS Data Length, and PEC.
456 @param Uuid Pointer to the UUID retrieved from the SMBUS slave device.
458 @retval RETURN_SUCCESS The SMBUS command was executed.
459 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
460 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
461 in the Host Status Register bit.
462 Device errors are a result of a transaction collision, illegal command field,
463 unclaimed cycle (host initiated), or bus errors (collisions).
469 IN UINTN SmBusAddress
,