From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on LS1043A SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 +++++++++++++++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c + I2c driver APIs for read, write, initialize, set speed and reset + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h> + + +EFI_STATUS +EFIAPI +SetBusFrequency ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This, + IN OUT UINTN *BusClockHertz + ) +{ + + return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz)); +} + +EFI_STATUS +EFIAPI +Reset ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This + ) +{ + I2cReset(PcdGet32(PcdI2cBus)); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI StartRequest ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This, + IN UINTN SlaveAddress, + IN EFI_I2C_REQUEST_PACKET *RequestPacket, + IN EFI_EVENT Event OPTIONAL, + OUT EFI_STATUS *I2cStatus OPTIONAL + ) +{ + UINT32 Count; + INT32 Ret; + UINT32 Length; + UINT8 *Buffer = NULL; + UINT32 Flag; + + if (RequestPacket->OperationCount <= 0) { + DEBUG((EFI_D_ERROR," Operation count is not valid %d\n", + RequestPacket->OperationCount)); + return EFI_INVALID_PARAMETER; + } + + if (RequestPacket->Operation == NULL) { + DEBUG((EFI_D_ERROR," Operation array is NULL\n")); + return EFI_INVALID_PARAMETER; + } + + for (Count = 0; Count < RequestPacket->OperationCount; Count++) { + Flag = RequestPacket->Operation[Count].Flags; + Length = RequestPacket->Operation[Count].LengthInBytes; + Buffer = RequestPacket->Operation[Count].Buffer; + + if (Length <= 0) { + DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length)); + return EFI_INVALID_PARAMETER; + } + + if (Flag == I2C_READ_FLAG) { + Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress, + 0x00, sizeof(SlaveAddress)/8, Buffer, Length); + if (Ret != EFI_SUCCESS) { + DEBUG((EFI_D_ERROR," I2c read operation failed (error %d)\n", Ret)); + return Ret; + } + } else if (Flag == I2C_WRITE_FLAG) { + Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress, + 0x00, sizeof(SlaveAddress)/8, Buffer, Length); + if (Ret != EFI_SUCCESS) { + DEBUG((EFI_D_ERROR," I2c write operation failed (error %d)\n", Ret)); + return Ret; + } + } else { + DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag)); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = { + 0, + 0, + 0, + 0 +}; + +EFI_I2C_MASTER_PROTOCOL I2c = { + /// + /// Set the clock frequency for the I2C bus. + /// + SetBusFrequency, + /// + /// Reset the I2C host controller. + /// + Reset, + /// + /// Start an I2C transaction in master mode on the host controller. + /// + StartRequest, + /// + /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure containing + /// the capabilities of the I2C host controller. + /// + &I2cControllerCapabilities +}; + +/** + The user Entry Point for I2C module. The user code starts with this function. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +InitializeI2c( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status = 0; + + I2cBusInit(); + + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiI2cMasterProtocolGuid, (VOID**)&I2c, + NULL + ); + return Status; +} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +*/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = I2c + FILE_GUID = 4ec8b120-8307-11e0-bd91-0002a5d5c51b + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = InitializeI2c + +[Sources.common] + I2cDxe.c + +[LibraryClasses] + I2cLib + ArmLib + PcdLib + UefiLib + UefiDriverEntryPoint + MemoryAllocationLib + IoLib + PcdLib + +[Packages] + MdePkg/MdePkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[Protocols] + gEfiI2cMasterProtocolGuid + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdI2cBus + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed + +[Depex] + TRUE