1 /** @file
2 Common definitons for SMBus PEIM/DXE driver. Smbus PEI and DXE
3 modules share the same version of this file.
4 
5 Copyright (c) 2013-2015 Intel Corporation.
6 
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 #ifndef _QNC_SMBUS_H_
18 #define _QNC_SMBUS_H_
19 
20 #include "CommonHeader.h"
21 
22 //
23 // Minimum and maximum length for SMBus bus block protocols defined in SMBus spec 2.0.
24 //
25 #define MIN_SMBUS_BLOCK_LEN               1
26 #define MAX_SMBUS_BLOCK_LEN               32
27 #define ADD_LENGTH(SmbusAddress, Length)  ((SmbusAddress) + SMBUS_LIB_ADDRESS (0, 0, (Length), FALSE))
28 
29 /**
30   Executes an SMBus operation to an SMBus controller. Returns when either the command has been
31   executed or an error is encountered in doing the operation.
32 
33   The internal worker function provides a standard way to execute an operation as defined in the
34   System Management Bus (SMBus) Specification. The resulting transaction will be either that the
35   SMBus slave devices accept this transaction or that this function returns with error.
36 
37   @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
38   @param  Command                 This command is transmitted by the SMBus host controller to the
39                                   SMBus slave device and the interpretation is SMBus slave device
40                                   specific. It can mean the offset to a list of functions inside an
41                                   SMBus slave device. Not all operations or slave devices support
42                                   this command's registers.
43   @param  Operation               Signifies which particular SMBus hardware protocol instance that
44                                   it will use to execute the SMBus transactions. This SMBus
45                                   hardware protocol is defined by the SMBus Specification and is
46                                   not related to EFI.
47   @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
48                                   operation.
49   @param  Length                  Signifies the number of bytes that this operation will do. The
50                                   maximum number of bytes can be revision specific and operation
51                                   specific. This field will contain the actual number of bytes that
52                                   are executed for this operation. Not all operations require this
53                                   argument.
54   @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
55                                   Not all operations require this argument. The length of this
56                                   buffer is identified by Length.
57 
58   @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
59                                   exit criteria.
60   @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
61   @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
62                                   determined by the SMBus host controller device.
63   @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
64   @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
65                                   reflected in the Host Status Register bit. Device errors are a
66                                   result of a transaction collision, illegal command field,
67                                   unclaimed cycle (host initiated), or bus errors (collisions).
68   @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
69   @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
70                                   and EfiSmbusQuickWrite. Length is outside the range of valid
71                                   values.
72   @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
73   @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
74 
75 **/
76 EFI_STATUS
77 Execute (
78   IN     EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
79   IN     EFI_SMBUS_DEVICE_COMMAND Command,
80   IN     EFI_SMBUS_OPERATION      Operation,
81   IN     BOOLEAN                  PecCheck,
82   IN OUT UINTN                    *Length,
83   IN OUT VOID                     *Buffer
84   );
85 
86 #endif
87