EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

Omap35xxPkg/TPS65950Dxe/TPS65950.c

Go to the documentation of this file.
00001 
00015 #include <Uefi.h>
00016 
00017 #include <TPS65950.h>
00018 
00019 #include <Library/BaseMemoryLib.h>
00020 #include <Library/DebugLib.h>
00021 #include <Library/MemoryAllocationLib.h>
00022 #include <Library/UefiBootServicesTableLib.h>
00023 
00024 #include <Protocol/EmbeddedExternalDevice.h>
00025 #include <Protocol/SmbusHc.h>
00026 
00027 EFI_SMBUS_HC_PROTOCOL *Smbus;
00028 
00029 EFI_STATUS
00030 Read (
00031   IN  EMBEDDED_EXTERNAL_DEVICE    *This,
00032   IN  UINTN                       Register,
00033   IN  UINTN                       Length,
00034   OUT VOID                        *Buffer
00035   )
00036 {
00037   EFI_STATUS               Status;
00038   EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; 
00039   UINT8                    DeviceRegister;
00040   UINTN                    DeviceRegisterLength = 1;
00041 
00042   SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);
00043   DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);
00044 
00045   //Write DeviceRegister.
00046   Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceRegisterLength, &DeviceRegister);
00047   if (EFI_ERROR(Status)) {
00048     return Status;
00049   }
00050 
00051   //Read Data
00052   Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusReadBlock, FALSE, &Length, Buffer);
00053   return Status;
00054 }
00055 
00056 EFI_STATUS
00057 Write (
00058   IN EMBEDDED_EXTERNAL_DEVICE   *This,
00059   IN UINTN                      Register,
00060   IN UINTN                      Length,
00061   IN VOID                       *Buffer
00062   )
00063 {
00064   EFI_STATUS               Status;
00065   EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; 
00066   UINT8                    DeviceRegister;
00067   UINTN                    DeviceBufferLength = Length + 1;
00068   UINT8                    *DeviceBuffer;
00069 
00070   SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);
00071   DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);
00072 
00073   //Prepare buffer for writing
00074   DeviceBuffer = (UINT8 *)AllocatePool(DeviceBufferLength);
00075   if (DeviceBuffer == NULL) {
00076     Status = EFI_OUT_OF_RESOURCES;
00077     goto exit;
00078   }
00079 
00080   //Set Device register followed by data to write.
00081   DeviceBuffer[0] = DeviceRegister;
00082   CopyMem(&DeviceBuffer[1], Buffer, Length);
00083 
00084   //Write Data
00085   Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceBufferLength, DeviceBuffer);
00086   if (EFI_ERROR(Status)) {
00087     goto exit;
00088   }
00089 
00090 exit:
00091   if (DeviceBuffer) {
00092     FreePool(DeviceBuffer);
00093   }
00094 
00095   return Status;
00096 }
00097 
00098 EMBEDDED_EXTERNAL_DEVICE ExternalDevice = {
00099   Read,
00100   Write
00101 };
00102 
00103 EFI_STATUS
00104 TPS65950Initialize (
00105   IN EFI_HANDLE         ImageHandle,
00106   IN EFI_SYSTEM_TABLE   *SystemTable
00107   )
00108 {
00109   EFI_STATUS  Status;
00110   
00111   Status = gBS->LocateProtocol(&gEfiSmbusHcProtocolGuid, NULL, (VOID **)&Smbus);
00112   ASSERT_EFI_ERROR(Status);
00113   
00114   Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedExternalDeviceProtocolGuid, &ExternalDevice, NULL);
00115   return Status;
00116 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines