Re: [edk2] [PATCH 06/10] Platform/NXP: Add support for I2c operations library
> -Original Message- > From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] > Sent: Monday, November 13, 2017 6:06 PM > To: Meenakshi Aggarwal> Cc: Leif Lindholm ; Kinney, Michael D > ; edk2-devel@lists.01.org; Udit Kumar > ; Varun Sethi > Subject: Re: [PATCH 06/10] Platform/NXP: Add support for I2c operations > library > > On 7 November 2017 at 14:42, Meenakshi Aggarwal > wrote: > > I2C bus initialization and I2c read/write APIs added. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Meenakshi Aggarwal > > --- > > Platform/NXP/Include/Library/I2c.h | 125 > > Platform/NXP/Library/I2cLib/I2cLib.c | 549 > + > > Platform/NXP/Library/I2cLib/I2cLib.h | 109 +++ > > Platform/NXP/Library/I2cLib/I2cLib.inf | 43 +++ > > 4 files changed, 826 insertions(+) > > create mode 100644 Platform/NXP/Include/Library/I2c.h > > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.c > > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.h > > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.inf > > > > Please try to use the PI protocols for I2C rather than inventing your own. > Will rework our patch > > diff --git a/Platform/NXP/Include/Library/I2c.h > > b/Platform/NXP/Include/Library/I2c.h > > new file mode 100644 > > index 000..c7195ab > > --- /dev/null > > +++ b/Platform/NXP/Include/Library/I2c.h > > @@ -0,0 +1,125 @@ > > +/** I2c.h > > + Header defining the constant, base address amd function for I2C > > +controller > > + > > + Copyright 2017 NXP > > + > > + 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 > > + > > + > https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fop > > + ensource.org%2Flicenses%2Fbsd- > license.php=02%7C01%7Cmeenakshi.a > > + > ggarwal%40nxp.com%7C14609f2d45104cbffa4d08d52a9322ed%7C686ea1d3b > c2b4 > > + > c6fa92cd99c5c301635%7C0%7C0%7C636461733822406010=v6XNbA4uv > FFb2 > > + Fp5daZGXSedLOy1cJW%2F5Uo94vcdpbU%3D=0 > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > + BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > + > > +**/ > > + > > +#ifndef __I2C_H___ > > +#define __I2C_H__ > > + > > +#include > > + > > +#define I2C1 0 > > +#define I2C2 1 > > +#define I2C3 2 > > +#define I2C4 3 > > + > > +/// > > +/// Define the I2C flags > > +/// > > +#define I2C_READ_FLAG 0x1 > > +#define I2C_WRITE_FLAG0x2 > > + > > +/** > > + Function to initialize i2c bus > > + > > + @param I2cBus I2c Controller number > > + @param Speed Value to be set > > + > > + @retval EFI_SUCCESS > > +**/ > > +EFI_STATUS > > +EFIAPI > > +I2cBusInit ( > > + IN UINT32 I2cBus, > > + IN UINT32Speed > > Please fix alignment > > > + ); > > + > > +/** > > + Function to read data usin i2c > > + > > + @param I2cBus I2c Controller number > > + @param Chip Address of slave device from where data to be read > > + @param Offset Offset of slave memory > > + @param Alen Address length of slave > > + @param Buffer A pointer to the destination buffer for the data > > + @param LenLength of data to be read > > + > > + @retval EFI_NOT_READYArbitration lost > > + @retval EFI_TIMEOUT Failed to initialize data transfer in > > predefined > time > > + @retval EFI_NOT_FOUNDACK was not recieved > > + @retval EFI_SUCCESS Read was successful > > + > > +**/ > > +EFI_STATUS > > +I2cDataRead ( > > + IN UINT32 I2cBus, > > + IN UINT8Chip, > > + IN UINT32 Offset, > > + IN UINT32 Alen, > > + OUT UINT8 *Buffer, > > + IN UINT32 Len > > + ); > > and here > > > + > > +/** > > + Function to write data using i2c bus > > + > > + @param I2cBus I2c Controller number > > + @param ChipAddress of slave device where data to be > written > > + @param Offset Offset of slave memory > > + @param AlenAddress length of slave > > + @param Buffer A pointer to the source buffer for the > > data > > + @param Len Length of data to be write > > + > > + @retval EFI_NOT_READY Arbitration lost > > + @retval EFI_TIMEOUT Failed to initialize data transfer in > predefined time > > + @retval EFI_NOT_FOUND ACK was not recieved > > + @retval EFI_SUCCESS Read was successful > > + > > +**/ > > +EFI_STATUS > > +I2cDataWrite ( > > + IN UINT32I2cBus, > > + IN UINT8 Chip, > > + IN
Re: [edk2] [PATCH 06/10] Platform/NXP: Add support for I2c operations library
On 7 November 2017 at 14:42, Meenakshi Aggarwalwrote: > I2C bus initialization and I2c read/write APIs added. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Meenakshi Aggarwal > --- > Platform/NXP/Include/Library/I2c.h | 125 > Platform/NXP/Library/I2cLib/I2cLib.c | 549 > + > Platform/NXP/Library/I2cLib/I2cLib.h | 109 +++ > Platform/NXP/Library/I2cLib/I2cLib.inf | 43 +++ > 4 files changed, 826 insertions(+) > create mode 100644 Platform/NXP/Include/Library/I2c.h > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.c > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.h > create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.inf > Please try to use the PI protocols for I2C rather than inventing your own. > diff --git a/Platform/NXP/Include/Library/I2c.h > b/Platform/NXP/Include/Library/I2c.h > new file mode 100644 > index 000..c7195ab > --- /dev/null > +++ b/Platform/NXP/Include/Library/I2c.h > @@ -0,0 +1,125 @@ > +/** I2c.h > + Header defining the constant, base address amd function for I2C controller > + > + Copyright 2017 NXP > + > + 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. > + > +**/ > + > +#ifndef __I2C_H___ > +#define __I2C_H__ > + > +#include > + > +#define I2C1 0 > +#define I2C2 1 > +#define I2C3 2 > +#define I2C4 3 > + > +/// > +/// Define the I2C flags > +/// > +#define I2C_READ_FLAG 0x1 > +#define I2C_WRITE_FLAG0x2 > + > +/** > + Function to initialize i2c bus > + > + @param I2cBus I2c Controller number > + @param Speed Value to be set > + > + @retval EFI_SUCCESS > +**/ > +EFI_STATUS > +EFIAPI > +I2cBusInit ( > + IN UINT32 I2cBus, > + IN UINT32Speed Please fix alignment > + ); > + > +/** > + Function to read data usin i2c > + > + @param I2cBus I2c Controller number > + @param Chip Address of slave device from where data to be read > + @param Offset Offset of slave memory > + @param Alen Address length of slave > + @param Buffer A pointer to the destination buffer for the data > + @param LenLength of data to be read > + > + @retval EFI_NOT_READYArbitration lost > + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined > time > + @retval EFI_NOT_FOUNDACK was not recieved > + @retval EFI_SUCCESS Read was successful > + > +**/ > +EFI_STATUS > +I2cDataRead ( > + IN UINT32 I2cBus, > + IN UINT8Chip, > + IN UINT32 Offset, > + IN UINT32 Alen, > + OUT UINT8 *Buffer, > + IN UINT32 Len > + ); and here > + > +/** > + Function to write data using i2c bus > + > + @param I2cBus I2c Controller number > + @param ChipAddress of slave device where data to be > written > + @param Offset Offset of slave memory > + @param AlenAddress length of slave > + @param Buffer A pointer to the source buffer for the > data > + @param Len Length of data to be write > + > + @retval EFI_NOT_READY Arbitration lost > + @retval EFI_TIMEOUT Failed to initialize data transfer in > predefined time > + @retval EFI_NOT_FOUND ACK was not recieved > + @retval EFI_SUCCESS Read was successful > + > +**/ > +EFI_STATUS > +I2cDataWrite ( > + IN UINT32I2cBus, > + IN UINT8 Chip, > + IN UINT32Offset, > + IN INT32 Alen, > + OUT UINT8 *Buffer, > + IN INT32 Len > + ); > + > +/** > + Function to reset I2c > + @param I2cBusI2c Controller number > + > + @return VOID > +**/ > +VOID > +I2cReset ( > + UINT32 I2cBus > + ); > + > +/** > + Function to Probe I2c slave device > + @paramI2cBusI2c Controller number > + > + @retval EFI_INVALID_PARAMETER Invalid I2c Controller number > + @retval EFI_SUCCESS I2c device probed successfully > + > +**/ > +EFI_STATUS > +EFIAPI > +I2cProbeDevices ( > + IN INT16I2cBus, > + IN UINT8Chip > + ); > + > +#endif > diff --git a/Platform/NXP/Library/I2cLib/I2cLib.c > b/Platform/NXP/Library/I2cLib/I2cLib.c > new file mode 100644 > index 000..574b899 > --- /dev/null > +++ b/Platform/NXP/Library/I2cLib/I2cLib.c > @@ -0,0 +1,549 @@ > +/** I2cLib.c > + I2c Library containing functions for read, write, initialize, set speed etc > + > + Copyright 2017 NXP > + > +
[edk2] [PATCH 06/10] Platform/NXP: Add support for I2c operations library
I2C bus initialization and I2c read/write APIs added. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal--- Platform/NXP/Include/Library/I2c.h | 125 Platform/NXP/Library/I2cLib/I2cLib.c | 549 + Platform/NXP/Library/I2cLib/I2cLib.h | 109 +++ Platform/NXP/Library/I2cLib/I2cLib.inf | 43 +++ 4 files changed, 826 insertions(+) create mode 100644 Platform/NXP/Include/Library/I2c.h create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.c create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.h create mode 100644 Platform/NXP/Library/I2cLib/I2cLib.inf diff --git a/Platform/NXP/Include/Library/I2c.h b/Platform/NXP/Include/Library/I2c.h new file mode 100644 index 000..c7195ab --- /dev/null +++ b/Platform/NXP/Include/Library/I2c.h @@ -0,0 +1,125 @@ +/** I2c.h + Header defining the constant, base address amd function for I2C controller + + Copyright 2017 NXP + + 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. + +**/ + +#ifndef __I2C_H___ +#define __I2C_H__ + +#include + +#define I2C1 0 +#define I2C2 1 +#define I2C3 2 +#define I2C4 3 + +/// +/// Define the I2C flags +/// +#define I2C_READ_FLAG 0x1 +#define I2C_WRITE_FLAG0x2 + +/** + Function to initialize i2c bus + + @param I2cBus I2c Controller number + @param Speed Value to be set + + @retval EFI_SUCCESS +**/ +EFI_STATUS +EFIAPI +I2cBusInit ( + IN UINT32 I2cBus, + IN UINT32Speed + ); + +/** + Function to read data usin i2c + + @param I2cBus I2c Controller number + @param Chip Address of slave device from where data to be read + @param Offset Offset of slave memory + @param Alen Address length of slave + @param Buffer A pointer to the destination buffer for the data + @param LenLength of data to be read + + @retval EFI_NOT_READYArbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUNDACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataRead ( + IN UINT32 I2cBus, + IN UINT8Chip, + IN UINT32 Offset, + IN UINT32 Alen, + OUT UINT8 *Buffer, + IN UINT32 Len + ); + +/** + Function to write data using i2c bus + + @param I2cBus I2c Controller number + @param ChipAddress of slave device where data to be written + @param Offset Offset of slave memory + @param AlenAddress length of slave + @param Buffer A pointer to the source buffer for the data + @param Len Length of data to be write + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataWrite ( + IN UINT32I2cBus, + IN UINT8 Chip, + IN UINT32Offset, + IN INT32 Alen, + OUT UINT8 *Buffer, + IN INT32 Len + ); + +/** + Function to reset I2c + @param I2cBusI2c Controller number + + @return VOID +**/ +VOID +I2cReset ( + UINT32 I2cBus + ); + +/** + Function to Probe I2c slave device + @paramI2cBusI2c Controller number + + @retval EFI_INVALID_PARAMETER Invalid I2c Controller number + @retval EFI_SUCCESS I2c device probed successfully + +**/ +EFI_STATUS +EFIAPI +I2cProbeDevices ( + IN INT16I2cBus, + IN UINT8Chip + ); + +#endif diff --git a/Platform/NXP/Library/I2cLib/I2cLib.c b/Platform/NXP/Library/I2cLib/I2cLib.c new file mode 100644 index 000..574b899 --- /dev/null +++ b/Platform/NXP/Library/I2cLib/I2cLib.c @@ -0,0 +1,549 @@ +/** I2cLib.c + I2c Library containing functions for read, write, initialize, set speed etc + + Copyright 2017 NXP + + 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 +#include +#include +#include +#include + +#include "I2cLib.h" +