yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 1 | /** @file
|
lgao4 | 484c778 | 2008-11-13 08:30:16 +0000 | [diff] [blame] | 2 | Implementation of SmBusLib class library for DXE phase.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 3 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 4 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
hhtian | 19388d2 | 2010-04-23 16:37:43 +0000 | [diff] [blame] | 5 | This program and the accompanying materials
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 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
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 8 | http://opensource.org/licenses/bsd-license.php.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 9 |
|
| 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.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 12 |
|
| 13 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 14 | **/
|
| 15 |
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 16 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 17 | #include "InternalSmbusLib.h"
|
| 18 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 19 |
|
| 20 | //
|
| 21 | // Globle varible to cache pointer to Smbus protocol.
|
| 22 | //
|
jji4 | fe46741 | 2008-10-30 05:58:52 +0000 | [diff] [blame] | 23 | EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 24 |
|
| 25 | /**
|
| 26 | The constructor function caches the pointer to Smbus protocol.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 27 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 28 | The constructor function locates Smbus protocol from protocol database.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 29 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 30 |
|
| 31 | @param ImageHandle The firmware allocated handle for the EFI image.
|
| 32 | @param SystemTable A pointer to the EFI System Table.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 33 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 34 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
|
| 35 |
|
| 36 | **/
|
| 37 | EFI_STATUS
|
| 38 | EFIAPI
|
| 39 | SmbusLibConstructor (
|
| 40 | IN EFI_HANDLE ImageHandle,
|
| 41 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 42 | )
|
| 43 | {
|
| 44 | EFI_STATUS Status;
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 45 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 46 | Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);
|
| 47 | ASSERT_EFI_ERROR (Status);
|
| 48 | ASSERT (mSmbus != NULL);
|
| 49 |
|
| 50 | return Status;
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 54 | Executes an SMBus operation to an SMBus controller.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 55 |
|
| 56 | This function provides a standard way to execute Smbus script
|
| 57 | as defined in the SmBus Specification. The data can either be of
|
| 58 | the Length byte, word, or a block of data.
|
| 59 |
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 60 | @param SmbusOperation Signifies which particular SMBus hardware protocol instance
|
| 61 | that it will use to execute the SMBus transactions.
|
myronporter | 2fc59a0 | 2010-06-25 21:56:02 +0000 | [diff] [blame] | 62 | @param SmBusAddress The address that encodes the SMBUS Slave Address,
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 63 | SMBUS Command, SMBUS Data Length, and PEC.
|
myronporter | 58380e9 | 2010-06-30 00:13:25 +0000 | [diff] [blame] | 64 | @param Length Signifies the number of bytes that this operation will do.
|
| 65 | The maximum number of bytes can be revision specific
|
| 66 | and operation specific.
|
| 67 | @param Buffer Contains the value of data to execute to the SMBus slave
|
| 68 | device. Not all operations require this argument. The
|
| 69 | length of this buffer is identified by Length.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 70 | @param Status Return status for the executed command.
|
| 71 | This is an optional parameter and may be NULL.
|
| 72 |
|
klu2 | 070a76b | 2008-12-10 03:28:54 +0000 | [diff] [blame] | 73 | @return The actual number of bytes that are executed for this operation.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 74 |
|
| 75 | **/
|
| 76 | UINTN
|
| 77 | InternalSmBusExec (
|
| 78 | IN EFI_SMBUS_OPERATION SmbusOperation,
|
| 79 | IN UINTN SmBusAddress,
|
| 80 | IN UINTN Length,
|
| 81 | IN OUT VOID *Buffer,
|
| 82 | OUT RETURN_STATUS *Status OPTIONAL
|
| 83 | )
|
| 84 | {
|
| 85 | RETURN_STATUS ReturnStatus;
|
| 86 | EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
|
| 87 |
|
| 88 | SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
|
| 89 |
|
| 90 | ReturnStatus = mSmbus->Execute (
|
| 91 | mSmbus,
|
| 92 | SmbusDeviceAddress,
|
| 93 | SMBUS_LIB_COMMAND (SmBusAddress),
|
| 94 | SmbusOperation,
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 95 | SMBUS_LIB_PEC (SmBusAddress),
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 96 | &Length,
|
| 97 | Buffer
|
| 98 | );
|
| 99 | if (Status != NULL) {
|
| 100 | *Status = ReturnStatus;
|
| 101 | }
|
| 102 |
|
| 103 | return Length;
|
| 104 | }
|