3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 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.
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
24 #include <Protocol/EmbeddedExternalDevice.h>
25 #include <Protocol/SmbusHc.h>
27 EFI_SMBUS_HC_PROTOCOL
*Smbus
;
31 IN EMBEDDED_EXTERNAL_DEVICE
*This
,
38 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress
;
40 UINTN DeviceRegisterLength
= 1;
42 SlaveAddress
.SmbusDeviceAddress
= EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register
);
43 DeviceRegister
= (UINT8
)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register
);
45 //Write DeviceRegister.
46 Status
= Smbus
->Execute(Smbus
, SlaveAddress
, 0, EfiSmbusWriteBlock
, FALSE
, &DeviceRegisterLength
, &DeviceRegister
);
47 if (EFI_ERROR(Status
)) {
52 Status
= Smbus
->Execute(Smbus
, SlaveAddress
, 0, EfiSmbusReadBlock
, FALSE
, &Length
, Buffer
);
58 IN EMBEDDED_EXTERNAL_DEVICE
*This
,
65 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress
;
67 UINTN DeviceBufferLength
= Length
+ 1;
70 SlaveAddress
.SmbusDeviceAddress
= EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register
);
71 DeviceRegister
= (UINT8
)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register
);
73 //Prepare buffer for writing
74 DeviceBuffer
= (UINT8
*)AllocatePool(DeviceBufferLength
);
75 if (DeviceBuffer
== NULL
) {
76 Status
= EFI_OUT_OF_RESOURCES
;
80 //Set Device register followed by data to write.
81 DeviceBuffer
[0] = DeviceRegister
;
82 CopyMem(&DeviceBuffer
[1], Buffer
, Length
);
85 Status
= Smbus
->Execute(Smbus
, SlaveAddress
, 0, EfiSmbusWriteBlock
, FALSE
, &DeviceBufferLength
, DeviceBuffer
);
86 if (EFI_ERROR(Status
)) {
92 FreePool(DeviceBuffer
);
98 EMBEDDED_EXTERNAL_DEVICE ExternalDevice
= {
105 IN EFI_HANDLE ImageHandle
,
106 IN EFI_SYSTEM_TABLE
*SystemTable
111 Status
= gBS
->LocateProtocol(&gEfiSmbusHcProtocolGuid
, NULL
, (VOID
**)&Smbus
);
112 ASSERT_EFI_ERROR(Status
);
114 Status
= gBS
->InstallMultipleProtocolInterfaces(&ImageHandle
, &gEmbeddedExternalDeviceProtocolGuid
, &ExternalDevice
, NULL
);