Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-08 Thread Leif Lindholm
On Wed, Nov 08, 2017 at 05:45:11PM +, Ard Biesheuvel wrote:
> On 8 November 2017 at 16:47, Leif Lindholm  wrote:
> > On Fri, Nov 03, 2017 at 10:16:52AM +, Ard Biesheuvel wrote:
> >> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
> >> the Socionext Developer Box board. Note that the standard I2C protocol
> >> stack does not support runtime use, so this driver invokes the I2C master
> >> protocol directly. This requires support from the platform side as well,
> >> and so this driver will only attach to a I2C master that has the
> >> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
> >> handle. It is up to the platform to ensure that the driver producing
> >> the I2C master protocol in question is runtime capable, and is not
> >> shared with the I2C protocol stack (i.e., it should not have the I2C
> >> Bus Configuration Management protocol installed as well).
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.1
> >> Signed-off-by: Ard Biesheuvel 
> >
> > Reviewed-by: Leif Lindholm 
> 
> Ehm, is this in response to the correct patch, given that you already
> asked for some changes?

No, that's me getting confused by the patches appearing out of order
in my inbox... Apologies.

/
Leif
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-08 Thread Ard Biesheuvel
On 8 November 2017 at 16:47, Leif Lindholm  wrote:
> On Fri, Nov 03, 2017 at 10:16:52AM +, Ard Biesheuvel wrote:
>> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
>> the Socionext Developer Box board. Note that the standard I2C protocol
>> stack does not support runtime use, so this driver invokes the I2C master
>> protocol directly. This requires support from the platform side as well,
>> and so this driver will only attach to a I2C master that has the
>> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
>> handle. It is up to the platform to ensure that the driver producing
>> the I2C master protocol in question is runtime capable, and is not
>> shared with the I2C protocol stack (i.e., it should not have the I2C
>> Bus Configuration Management protocol installed as well).
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Ard Biesheuvel 
>
> Reviewed-by: Leif Lindholm 
>

Ehm, is this in response to the correct patch, given that you already
asked for some changes?
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-08 Thread Ard Biesheuvel
On 8 November 2017 at 16:43, Leif Lindholm  wrote:
> On Fri, Nov 03, 2017 at 10:16:52AM +, Ard Biesheuvel wrote:
>> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
>> the Socionext Developer Box board. Note that the standard I2C protocol
>> stack does not support runtime use, so this driver invokes the I2C master
>> protocol directly. This requires support from the platform side as well,
>> and so this driver will only attach to a I2C master that has the
>> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
>> handle. It is up to the platform to ensure that the driver producing
>> the I2C master protocol in question is runtime capable, and is not
>> shared with the I2C protocol stack (i.e., it should not have the I2C
>> Bus Configuration Management protocol installed as well).
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   | 
>> 385 
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |  
>> 29 ++
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |  
>> 52 +++
>>  3 files changed, 466 insertions(+)
>>
>> diff --git 
>> a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c 
>> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
>> new file mode 100644
>> index ..fea65a225d7f
>> --- /dev/null
>> +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
>> @@ -0,0 +1,385 @@
>> +/** @file
>> +
>> +  Copyright (c) 2017, Linaro, Ltd. 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 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
>> +#define PCF8563_DATA_REG_OFFSET   0x2
>> +
>> +#define PCF8563_SECONDS_MASK  0x7f
>> +#define PCF8563_MINUTES_MASK  0x7f
>> +#define PCF8563_HOURS_MASK0x3f
>> +#define PCF8563_DAYS_MASK 0x3f
>> +#define PCF8563_WEEKDAYS_MASK 0x07
>> +#define PCF8563_MONTHS_MASK   0x1f
>> +#define PCF8563_CENTURY_MASK  0x80
>> +
>> +#define EPOCH_BASE2000
>> +
>> +STATIC EFI_HANDLE mI2cMasterHandle;
>> +STATIC VOID   *mDriverEventRegistration;
>> +STATIC EFI_I2C_MASTER_PROTOCOL*mI2cMaster;
>> +STATIC EFI_EVENT  mRtcVirtualAddrChangeEvent;
>> +
>> +typedef struct {
>> +  UINTN   OperationCount;
>> +  EFI_I2C_OPERATION   SetAddressOp;
>> +  EFI_I2C_OPERATION   GetSetDateTimeOp;
>> +} RTC_I2C_REQUEST;
>> +
>> +#pragma pack(1)
>> +typedef struct {
>> +  UINT8 VL_seconds;
>> +  UINT8 Minutes;
>> +  UINT8 Hours;
>> +  UINT8 Days;
>> +  UINT8 Weekdays;
>> +  UINT8 Century_months;
>> +  UINT8 Years;
>> +} RTC_DATETIME;
>> +#pragma pack()
>> +
>> +/**
>> +  Returns the current time and date information, and the time-keeping
>> +  capabilities of the hardware platform.
>> +
>> +  @param  Time  A pointer to storage to receive a snapshot 
>> of
>> +the current time.
>> +  @param  Capabilities  An optional pointer to a buffer to receive 
>> the
>> +real time clock device's capabilities.
>> +
>> +  @retval EFI_SUCCESS   The operation completed successfully.
>> +  @retval EFI_INVALID_PARAMETER Time is NULL.
>> +  @retval EFI_DEVICE_ERROR  The time could not be retrieved due to 
>> hardware
>> +error.
>> +
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +LibGetTime (
>> +  OUT EFI_TIME*Time,
>> +  OUT EFI_TIME_CAPABILITIES   *Capabilities
>> +  )
>> +{
>> +  RTC_I2C_REQUEST Op;
>> +  RTC_DATETIMEDateTime;
>> +  EFI_STATUS  Status;
>> +  UINT8   Reg;
>> +
>> +  if (Time == NULL) {
>> +return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  if (mI2cMaster == NULL) {
>> +return EFI_DEVICE_ERROR;
>> +  }
>> +
>> +  Reg = PCF8563_DATA_REG_OFFSET;
>> +
>> +  Op.OperationCount = 2;
>> +
>> +  Op.SetAddressOp.Flags = 0;
>> +  Op.SetAddressOp.LengthInBytes = 1;
>> +  Op.SetAddressOp.Buffer = 
>> +
>> +  Op.GetSetDateTimeOp.Flags = I2C_FLAG_READ;
>> +  Op.GetSetDateTimeOp.LengthInBytes = sizeof 

Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-08 Thread Leif Lindholm
On Fri, Nov 03, 2017 at 10:16:52AM +, Ard Biesheuvel wrote:
> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
> the Socionext Developer Box board. Note that the standard I2C protocol
> stack does not support runtime use, so this driver invokes the I2C master
> protocol directly. This requires support from the platform side as well,
> and so this driver will only attach to a I2C master that has the
> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
> handle. It is up to the platform to ensure that the driver producing
> the I2C master protocol in question is runtime capable, and is not
> shared with the I2C protocol stack (i.e., it should not have the I2C
> Bus Configuration Management protocol installed as well).
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel 

Reviewed-by: Leif Lindholm 

> ---
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   | 
> 385 
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |  
> 29 ++
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |  
> 52 +++
>  3 files changed, 466 insertions(+)
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-08 Thread Leif Lindholm
On Fri, Nov 03, 2017 at 10:16:52AM +, Ard Biesheuvel wrote:
> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
> the Socionext Developer Box board. Note that the standard I2C protocol
> stack does not support runtime use, so this driver invokes the I2C master
> protocol directly. This requires support from the platform side as well,
> and so this driver will only attach to a I2C master that has the
> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
> handle. It is up to the platform to ensure that the driver producing
> the I2C master protocol in question is runtime capable, and is not
> shared with the I2C protocol stack (i.e., it should not have the I2C
> Bus Configuration Management protocol installed as well).
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel 
> ---
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   | 
> 385 
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |  
> 29 ++
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |  
> 52 +++
>  3 files changed, 466 insertions(+)
> 
> diff --git 
> a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c 
> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> new file mode 100644
> index ..fea65a225d7f
> --- /dev/null
> +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> @@ -0,0 +1,385 @@
> +/** @file
> +
> +  Copyright (c) 2017, Linaro, Ltd. 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
> +#define PCF8563_DATA_REG_OFFSET   0x2
> +
> +#define PCF8563_SECONDS_MASK  0x7f
> +#define PCF8563_MINUTES_MASK  0x7f
> +#define PCF8563_HOURS_MASK0x3f
> +#define PCF8563_DAYS_MASK 0x3f
> +#define PCF8563_WEEKDAYS_MASK 0x07
> +#define PCF8563_MONTHS_MASK   0x1f
> +#define PCF8563_CENTURY_MASK  0x80
> +
> +#define EPOCH_BASE2000
> +
> +STATIC EFI_HANDLE mI2cMasterHandle;
> +STATIC VOID   *mDriverEventRegistration;
> +STATIC EFI_I2C_MASTER_PROTOCOL*mI2cMaster;
> +STATIC EFI_EVENT  mRtcVirtualAddrChangeEvent;
> +
> +typedef struct {
> +  UINTN   OperationCount;
> +  EFI_I2C_OPERATION   SetAddressOp;
> +  EFI_I2C_OPERATION   GetSetDateTimeOp;
> +} RTC_I2C_REQUEST;
> +
> +#pragma pack(1)
> +typedef struct {
> +  UINT8 VL_seconds;
> +  UINT8 Minutes;
> +  UINT8 Hours;
> +  UINT8 Days;
> +  UINT8 Weekdays;
> +  UINT8 Century_months;
> +  UINT8 Years;
> +} RTC_DATETIME;
> +#pragma pack()
> +
> +/**
> +  Returns the current time and date information, and the time-keeping
> +  capabilities of the hardware platform.
> +
> +  @param  Time  A pointer to storage to receive a snapshot of
> +the current time.
> +  @param  Capabilities  An optional pointer to a buffer to receive 
> the
> +real time clock device's capabilities.
> +
> +  @retval EFI_SUCCESS   The operation completed successfully.
> +  @retval EFI_INVALID_PARAMETER Time is NULL.
> +  @retval EFI_DEVICE_ERROR  The time could not be retrieved due to 
> hardware
> +error.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +LibGetTime (
> +  OUT EFI_TIME*Time,
> +  OUT EFI_TIME_CAPABILITIES   *Capabilities
> +  )
> +{
> +  RTC_I2C_REQUEST Op;
> +  RTC_DATETIMEDateTime;
> +  EFI_STATUS  Status;
> +  UINT8   Reg;
> +
> +  if (Time == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
> +  if (mI2cMaster == NULL) {
> +return EFI_DEVICE_ERROR;
> +  }
> +
> +  Reg = PCF8563_DATA_REG_OFFSET;
> +
> +  Op.OperationCount = 2;
> +
> +  Op.SetAddressOp.Flags = 0;
> +  Op.SetAddressOp.LengthInBytes = 1;
> +  Op.SetAddressOp.Buffer = 
> +
> +  Op.GetSetDateTimeOp.Flags = I2C_FLAG_READ;
> +  Op.GetSetDateTimeOp.LengthInBytes = sizeof (RTC_DATETIME);
> +  Op.GetSetDateTimeOp.Buffer = (VOID *)
> +
> +  Status = mI2cMaster->StartRequest (mI2cMaster, SLAVE_ADDRESS,
> + (VOID *), NULL, NULL);
> +  if (EFI_ERROR (Status)) {
> +return 

Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-06 Thread Udit Kumar
Thanks Ard, 
Your another patch set is addressing my concern 

Regards
Udit

> -Original Message-
> From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org]
> Sent: Monday, November 06, 2017 4:41 PM
> To: Udit Kumar <udit.ku...@nxp.com>
> Cc: edk2-devel@lists.01.org; leif.lindh...@linaro.org;
> daniel.thomp...@linaro.org
> Subject: Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC
> support library for PCF8563 I2C IP
> 
> On 6 November 2017 at 11:09, Udit Kumar <udit.ku...@nxp.com> wrote:
> > Thanks Ard.
> > This will allow to use PCF8563 on any platform not limiting to targeted
> platform.
> 
> Yes, that was the intention.
> 
> > Few comments are inline.
> >
> 
> Thanks.
> 
> >
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf
> >> Of Ard Biesheuvel
> >> Sent: Friday, November 03, 2017 3:47 PM
> >> To: edk2-devel@lists.01.org; leif.lindh...@linaro.org;
> >> daniel.thomp...@linaro.org
> >> Cc: Ard Biesheuvel <ard.biesheu...@linaro.org>
> >> Subject: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC
> >> support library for PCF8563 I2C IP
> >>
> >> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
> >> the Socionext Developer Box board. Note that the standard I2C
> >> protocol stack does not support runtime use, so this driver invokes
> >> the I2C master protocol directly. This requires support from the
> >> platform side as well, and so this driver will only attach to a I2C
> >> master that has the gPcf8563RealTimeClockLibI2cMasterProtolGuid
> >> protocol installed on its handle. It is up to the platform to ensure
> >> that the driver producing the I2C master protocol in question is
> >> runtime capable, and is not shared with the I2C protocol stack (i.e.,
> >> it should not have the I2C Bus Configuration Management protocol installed
> as well).
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.1
> >> Signed-off-by: Ard Biesheuvel <ard.biesheu...@linaro.org>
> >> ---
> >>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> |
> >> 385 
> >>
> >> Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.d
> >> ec |
> >> 29 ++
> >>
> >> Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.i
> >> nf |
> >> 52 +++
> >>  3 files changed, 466 insertions(+)
> >>
> >> diff --git
> >> a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib
> >> .c
> >> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib
> >> .c
> >> new file mode 100644
> >> index ..fea65a225d7f
> >> --- /dev/null
> >> +++
> >> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib
> >> .c
> >> @@ -0,0 +1,385 @@
> >> +/** @file
> >> +
> >> +  Copyright (c) 2017, Linaro, Ltd. 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
> >> +
> >> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fope
> >> nso
> >> urce.org%2Flicenses%2Fbsd-
> >>
> license.php=02%7C01%7Cudit.kumar%40nxp.com%7C6faa68073eef4ed07
> >>
> 25208d522a40d65%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636
> >>
> 453010374642660=vDhroHNG20VCsMtj7%2FggWcWRG8hwt5fbV1Kv4R
> >> Na98Q%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.
> >> +
> >> +**/
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include  #include
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
> >> +#define PCF8563_DATA_REG_OFFSET   0x2
> >> +
> >> +#define PCF8563_SECONDS_MASK  0x7f
> >> +#define PCF8563_MINUTES_MASK  0x7f
> >> +#define PCF8563_HOURS_MASK0x3f
> >> +#defi

Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-06 Thread Ard Biesheuvel
On 6 November 2017 at 11:09, Udit Kumar <udit.ku...@nxp.com> wrote:
> Thanks Ard.
> This will allow to use PCF8563 on any platform not limiting to targeted 
> platform.

Yes, that was the intention.

> Few comments are inline.
>

Thanks.

>
>> -Original Message-
>> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ard
>> Biesheuvel
>> Sent: Friday, November 03, 2017 3:47 PM
>> To: edk2-devel@lists.01.org; leif.lindh...@linaro.org;
>> daniel.thomp...@linaro.org
>> Cc: Ard Biesheuvel <ard.biesheu...@linaro.org>
>> Subject: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support
>> library for PCF8563 I2C IP
>>
>> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
>> the Socionext Developer Box board. Note that the standard I2C protocol
>> stack does not support runtime use, so this driver invokes the I2C master
>> protocol directly. This requires support from the platform side as well,
>> and so this driver will only attach to a I2C master that has the
>> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
>> handle. It is up to the platform to ensure that the driver producing
>> the I2C master protocol in question is runtime capable, and is not
>> shared with the I2C protocol stack (i.e., it should not have the I2C
>> Bus Configuration Management protocol installed as well).
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Ard Biesheuvel <ard.biesheu...@linaro.org>
>> ---
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   |
>> 385 
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |
>> 29 ++
>>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |
>> 52 +++
>>  3 files changed, 466 insertions(+)
>>
>> diff --git
>> a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
>> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
>> new file mode 100644
>> index ..fea65a225d7f
>> --- /dev/null
>> +++
>> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
>> @@ -0,0 +1,385 @@
>> +/** @file
>> +
>> +  Copyright (c) 2017, Linaro, Ltd. 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
>> +
>> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fopenso
>> urce.org%2Flicenses%2Fbsd-
>> license.php=02%7C01%7Cudit.kumar%40nxp.com%7C6faa68073eef4ed07
>> 25208d522a40d65%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636
>> 453010374642660=vDhroHNG20VCsMtj7%2FggWcWRG8hwt5fbV1Kv4R
>> Na98Q%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.
>> +
>> +**/
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
>> +#define PCF8563_DATA_REG_OFFSET   0x2
>> +
>> +#define PCF8563_SECONDS_MASK  0x7f
>> +#define PCF8563_MINUTES_MASK  0x7f
>> +#define PCF8563_HOURS_MASK0x3f
>> +#define PCF8563_DAYS_MASK 0x3f
>> +#define PCF8563_WEEKDAYS_MASK 0x07
>> +#define PCF8563_MONTHS_MASK   0x1f
>> +#define PCF8563_CENTURY_MASK  0x80
>> +
>> +#define EPOCH_BASE2000
>> +
>> +STATIC EFI_HANDLE mI2cMasterHandle;
>> +STATIC VOID   *mDriverEventRegistration;
>> +STATIC EFI_I2C_MASTER_PROTOCOL*mI2cMaster;
>> +STATIC EFI_EVENT  mRtcVirtualAddrChangeEvent;
>> +
>> +typedef struct {
>> +  UINTN   OperationCount;
>> +  EFI_I2C_OPERATION   SetAddressOp;
>> +  EFI_I2C_OPERATION   GetSetDateTimeOp;
>> +} RTC_I2C_REQUEST;
>> +
>> +#pragma pack(1)
>> +typedef struct {
>> +  UINT8 VL_seconds;
>> +  UINT8 Minutes;
>> +  UINT8 Hours;
>> +  UINT8 Days;
>> +  UINT8 Weekdays;
>> +  UINT8 Century_months;
>> +  UINT8 Years;
>> +} RTC_DATETIME;
>> +#prag

Re: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-06 Thread Udit Kumar
Thanks Ard. 
This will allow to use PCF8563 on any platform not limiting to targeted 
platform. 
Few comments are inline.

Regards
Udit 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ard
> Biesheuvel
> Sent: Friday, November 03, 2017 3:47 PM
> To: edk2-devel@lists.01.org; leif.lindh...@linaro.org;
> daniel.thomp...@linaro.org
> Cc: Ard Biesheuvel <ard.biesheu...@linaro.org>
> Subject: [edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support
> library for PCF8563 I2C IP
> 
> Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
> the Socionext Developer Box board. Note that the standard I2C protocol
> stack does not support runtime use, so this driver invokes the I2C master
> protocol directly. This requires support from the platform side as well,
> and so this driver will only attach to a I2C master that has the
> gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
> handle. It is up to the platform to ensure that the driver producing
> the I2C master protocol in question is runtime capable, and is not
> shared with the I2C protocol stack (i.e., it should not have the I2C
> Bus Configuration Management protocol installed as well).
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheu...@linaro.org>
> ---
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   |
> 385 
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |
> 29 ++
>  Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |
> 52 +++
>  3 files changed, 466 insertions(+)
> 
> diff --git
> a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> new file mode 100644
> index ..fea65a225d7f
> --- /dev/null
> +++
> b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
> @@ -0,0 +1,385 @@
> +/** @file
> +
> +  Copyright (c) 2017, Linaro, Ltd. 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
> +
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fopenso
> urce.org%2Flicenses%2Fbsd-
> license.php=02%7C01%7Cudit.kumar%40nxp.com%7C6faa68073eef4ed07
> 25208d522a40d65%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636
> 453010374642660=vDhroHNG20VCsMtj7%2FggWcWRG8hwt5fbV1Kv4R
> Na98Q%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.
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
> +#define PCF8563_DATA_REG_OFFSET   0x2
> +
> +#define PCF8563_SECONDS_MASK  0x7f
> +#define PCF8563_MINUTES_MASK  0x7f
> +#define PCF8563_HOURS_MASK0x3f
> +#define PCF8563_DAYS_MASK 0x3f
> +#define PCF8563_WEEKDAYS_MASK 0x07
> +#define PCF8563_MONTHS_MASK   0x1f
> +#define PCF8563_CENTURY_MASK  0x80
> +
> +#define EPOCH_BASE2000
> +
> +STATIC EFI_HANDLE mI2cMasterHandle;
> +STATIC VOID   *mDriverEventRegistration;
> +STATIC EFI_I2C_MASTER_PROTOCOL*mI2cMaster;
> +STATIC EFI_EVENT  mRtcVirtualAddrChangeEvent;
> +
> +typedef struct {
> +  UINTN   OperationCount;
> +  EFI_I2C_OPERATION   SetAddressOp;
> +  EFI_I2C_OPERATION   GetSetDateTimeOp;
> +} RTC_I2C_REQUEST;
> +
> +#pragma pack(1)
> +typedef struct {
> +  UINT8 VL_seconds;
> +  UINT8 Minutes;
> +  UINT8 Hours;
> +  UINT8 Days;
> +  UINT8 Weekdays;
> +  UINT8 Century_months;
> +  UINT8 Years;
> +} RTC_DATETIME;
> +#pragma pack()
> +
> +/**
> +  Returns the current time and date information, and the time-keeping
> +  capabilities of the hardware platform.
> +
> +  @param  Time  A pointer to storage to receive a snapshot of
> +the current time.
> +  @param  Capabilities  An optional pointer to a buffer to receive 
> the
> +real time clock device's capabilities.
> +
> +  @retval EFI_SUCCESS   The operation completed successfully.
> +  @retval 

[edk2] [RFC PATCH edk2-platforms 1/3] Silicon/NXP: add RTC support library for PCF8563 I2C IP

2017-11-03 Thread Ard Biesheuvel
Add a RealTimeClockLib implementation for the NXP PCF8563 as used on
the Socionext Developer Box board. Note that the standard I2C protocol
stack does not support runtime use, so this driver invokes the I2C master
protocol directly. This requires support from the platform side as well,
and so this driver will only attach to a I2C master that has the
gPcf8563RealTimeClockLibI2cMasterProtolGuid protocol installed on its
handle. It is up to the platform to ensure that the driver producing
the I2C master protocol in question is runtime capable, and is not
shared with the I2C protocol stack (i.e., it should not have the I2C
Bus Configuration Management protocol installed as well).

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c   | 385 

 Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec |  29 
++
 Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf |  52 
+++
 3 files changed, 466 insertions(+)

diff --git 
a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c 
b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
new file mode 100644
index ..fea65a225d7f
--- /dev/null
+++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c
@@ -0,0 +1,385 @@
+/** @file
+
+  Copyright (c) 2017, Linaro, Ltd. 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress))
+#define PCF8563_DATA_REG_OFFSET   0x2
+
+#define PCF8563_SECONDS_MASK  0x7f
+#define PCF8563_MINUTES_MASK  0x7f
+#define PCF8563_HOURS_MASK0x3f
+#define PCF8563_DAYS_MASK 0x3f
+#define PCF8563_WEEKDAYS_MASK 0x07
+#define PCF8563_MONTHS_MASK   0x1f
+#define PCF8563_CENTURY_MASK  0x80
+
+#define EPOCH_BASE2000
+
+STATIC EFI_HANDLE mI2cMasterHandle;
+STATIC VOID   *mDriverEventRegistration;
+STATIC EFI_I2C_MASTER_PROTOCOL*mI2cMaster;
+STATIC EFI_EVENT  mRtcVirtualAddrChangeEvent;
+
+typedef struct {
+  UINTN   OperationCount;
+  EFI_I2C_OPERATION   SetAddressOp;
+  EFI_I2C_OPERATION   GetSetDateTimeOp;
+} RTC_I2C_REQUEST;
+
+#pragma pack(1)
+typedef struct {
+  UINT8 VL_seconds;
+  UINT8 Minutes;
+  UINT8 Hours;
+  UINT8 Days;
+  UINT8 Weekdays;
+  UINT8 Century_months;
+  UINT8 Years;
+} RTC_DATETIME;
+#pragma pack()
+
+/**
+  Returns the current time and date information, and the time-keeping
+  capabilities of the hardware platform.
+
+  @param  Time  A pointer to storage to receive a snapshot of
+the current time.
+  @param  Capabilities  An optional pointer to a buffer to receive the
+real time clock device's capabilities.
+
+  @retval EFI_SUCCESS   The operation completed successfully.
+  @retval EFI_INVALID_PARAMETER Time is NULL.
+  @retval EFI_DEVICE_ERROR  The time could not be retrieved due to hardware
+error.
+
+**/
+EFI_STATUS
+EFIAPI
+LibGetTime (
+  OUT EFI_TIME*Time,
+  OUT EFI_TIME_CAPABILITIES   *Capabilities
+  )
+{
+  RTC_I2C_REQUEST Op;
+  RTC_DATETIMEDateTime;
+  EFI_STATUS  Status;
+  UINT8   Reg;
+
+  if (Time == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  if (mI2cMaster == NULL) {
+return EFI_DEVICE_ERROR;
+  }
+
+  Reg = PCF8563_DATA_REG_OFFSET;
+
+  Op.OperationCount = 2;
+
+  Op.SetAddressOp.Flags = 0;
+  Op.SetAddressOp.LengthInBytes = 1;
+  Op.SetAddressOp.Buffer = 
+
+  Op.GetSetDateTimeOp.Flags = I2C_FLAG_READ;
+  Op.GetSetDateTimeOp.LengthInBytes = sizeof (RTC_DATETIME);
+  Op.GetSetDateTimeOp.Buffer = (VOID *)
+
+  Status = mI2cMaster->StartRequest (mI2cMaster, SLAVE_ADDRESS,
+ (VOID *), NULL, NULL);
+  if (EFI_ERROR (Status)) {
+return EFI_DEVICE_ERROR;
+  }
+
+  Time->Second  = BcdToDecimal8 (DateTime.VL_seconds & PCF8563_SECONDS_MASK);
+  Time->Minute  = BcdToDecimal8 (DateTime.Minutes & PCF8563_MINUTES_MASK);
+  Time->Hour= BcdToDecimal8 (DateTime.Hours & PCF8563_HOURS_MASK);
+  Time->Day = BcdToDecimal8 (DateTime.Days & PCF8563_DAYS_MASK);
+  Time->Month   = BcdToDecimal8