public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Leif Lindholm" <leif@nuviainc.com>
To: Pankaj Bansal <pankaj.bansal@nxp.com>
Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Varun Sethi <V.Sethi@nxp.com>,
	devel@edk2.groups.io
Subject: Re: [PATCH 16/19] Silicon/NXP: Add Pl011 Serial port lib
Date: Wed, 12 Feb 2020 20:26:05 +0000	[thread overview]
Message-ID: <20200212202605.GE23627@bivouac.eciton.net> (raw)
In-Reply-To: <20200207124328.8723-17-pankaj.bansal@nxp.com>

On Fri, Feb 07, 2020 at 18:13:25 +0530, Pankaj Bansal wrote:
> Use ArmPlatformPkg/PL011SerialPortLib with some changes:
> 1. add Get clock API to get the UART clock from ArmPlatformLib
> 2. remove SerialPortInitalize functionality
> 
> This is same as being done in Silicon/NXP/Library/BaseSerialPortLib16550.

And just like for that one, any functionality changes need to be
introduced conditionally in the original - if there is no other way to
achieve the same effect.

/
    Leif

> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  .../PL011SerialPortLib/PL011SerialPortLib.c   | 229 ++++++++++++++++++
>  .../PL011SerialPortLib/PL011SerialPortLib.inf |  42 ++++
>  Silicon/NXP/NxpQoriqLs.dsc.inc                |   1 +
>  3 files changed, 272 insertions(+)
>  create mode 100644 Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c
>  create mode 100644 Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf
> 
> diff --git a/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c
> new file mode 100644
> index 0000000000..35cfe8e324
> --- /dev/null
> +++ b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.c
> @@ -0,0 +1,229 @@
> +/** @file
> +  Serial I/O Port library functions with no library constructor/destructor
> +
> +  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
> +  Copyright (c) 2012 - 2016, ARM Ltd. All rights reserved.<BR>
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright 2020 NXP
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Base.h>
> +
> +#include <Library/IoLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PL011UartClockLib.h>
> +#include <Library/PL011UartLib.h>
> +#include <Library/SerialPortLib.h>
> +#include <Ppi/NxpPlatformGetClock.h>
> +
> +extern NXP_PLATFORM_GET_CLOCK_PPI mPlatformGetClockPpi;
> +
> +/** Initialise the serial device hardware with default settings.
> +
> +  @retval RETURN_SUCCESS            The serial device was initialised.
> +  @retval RETURN_INVALID_PARAMETER  One or more of the default settings
> +                                    has an unsupported value.
> + **/
> +RETURN_STATUS
> +EFIAPI
> +SerialPortInitialize (
> +  VOID
> +  )
> +{
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Write data to serial device.
> +
> +  @param  Buffer           Point of data buffer which need to be written.
> +  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
> +
> +  @retval 0                Write data failed.
> +  @retval !0               Actual number of bytes written to serial device.
> +
> +**/
> +UINTN
> +EFIAPI
> +SerialPortWrite (
> +  IN UINT8     *Buffer,
> +  IN UINTN     NumberOfBytes
> +  )
> +{
> +  return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
> +}
> +
> +/**
> +  Read data from serial device and save the data in buffer.
> +
> +  @param  Buffer           Point of data buffer which need to be written.
> +  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
> +
> +  @retval 0                Read data failed.
> +  @retval !0               Actual number of bytes read from serial device.
> +
> +**/
> +UINTN
> +EFIAPI
> +SerialPortRead (
> +  OUT UINT8     *Buffer,
> +  IN  UINTN     NumberOfBytes
> +)
> +{
> +  return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
> +}
> +
> +/**
> +  Check to see if any data is available to be read from the debug device.
> +
> +  @retval TRUE       At least one byte of data is available to be read
> +  @retval FALSE      No data is available to be read
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +SerialPortPoll (
> +  VOID
> +  )
> +{
> +  return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
> +}
> +/**
> +  Set new attributes to PL011.
> +
> +  @param  BaudRate                The baud rate of the serial device. If the
> +                                  baud rate is not supported, the speed will
> +                                  be reduced down to the nearest supported one
> +                                  and the variable's value will be updated
> +                                  accordingly.
> +  @param  ReceiveFifoDepth        The number of characters the device will
> +                                  buffer on input. If the specified value is
> +                                  not supported, the variable's value will
> +                                  be reduced down to the nearest supported one.
> +  @param  Timeout                 If applicable, the number of microseconds the
> +                                  device will wait before timing out a Read or
> +                                  a Write operation.
> +  @param  Parity                  If applicable, this is the EFI_PARITY_TYPE
> +                                  that is computed or checked as each character
> +                                  is transmitted or received. If the device
> +                                  does not support parity, the value is the
> +                                  default parity value.
> +  @param  DataBits                The number of data bits in each character
> +  @param  StopBits                If applicable, the EFI_STOP_BITS_TYPE number
> +                                  of stop bits per character. If the device
> +                                  does not support stop bits, the value is the
> +                                  default stop bit value.
> +
> +  @retval EFI_SUCCESS             All attributes were set correctly.
> +  @retval EFI_INVALID_PARAMETERS  One or more attributes has an unsupported
> +                                  value.
> +  @retval RETURN_DEVICE_ERROR     The serial device is not functioning correctly.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +SerialPortSetAttributes (
> +  IN OUT UINT64              *BaudRate,
> +  IN OUT UINT32              *ReceiveFifoDepth,
> +  IN OUT UINT32              *Timeout,
> +  IN OUT EFI_PARITY_TYPE     *Parity,
> +  IN OUT UINT8               *DataBits,
> +  IN OUT EFI_STOP_BITS_TYPE  *StopBits
> +  )
> +{
> +  UINT64    SerialClock;
> +
> +  SerialClock = mPlatformGetClockPpi.PlatformGetClock (NXP_UART_CLOCK, 0);
> +  if (SerialClock == 0) {
> +    return EFI_DEVICE_ERROR;
> +  }
> +
> +  return PL011UartInitializePort (
> +           (UINTN)PcdGet64 (PcdSerialRegisterBase),
> +           SerialClock,
> +           BaudRate,
> +           ReceiveFifoDepth,
> +           Parity,
> +           DataBits,
> +           StopBits
> +           );
> +}
> +
> +/**
> +
> +  Assert or deassert the control signals on a serial port.
> +  The following control signals are set according their bit settings :
> +  . Request to Send
> +  . Data Terminal Ready
> +
> +  @param[in]  Control  The following bits are taken into account :
> +                       . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the
> +                         "Request To Send" control signal if this bit is
> +                         equal to one/zero.
> +                       . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert
> +                         the "Data Terminal Ready" control signal if this
> +                         bit is equal to one/zero.
> +                       . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable
> +                         the hardware loopback if this bit is equal to
> +                         one/zero.
> +                       . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.
> +                       . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/
> +                         disable the hardware flow control based on CTS (Clear
> +                         To Send) and RTS (Ready To Send) control signals.
> +
> +  @retval  RETURN_SUCCESS      The new control bits were set on the device.
> +  @retval  RETURN_UNSUPPORTED  The device does not support this operation.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +SerialPortSetControl (
> +  IN UINT32  Control
> +  )
> +{
> +  return PL011UartSetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
> +}
> +
> +/**
> +
> +  Retrieve the status of the control bits on a serial device.
> +
> +  @param[out]  Control  Status of the control bits on a serial device :
> +
> +                        . EFI_SERIAL_DATA_CLEAR_TO_SEND,
> +                          EFI_SERIAL_DATA_SET_READY,
> +                          EFI_SERIAL_RING_INDICATE,
> +                          EFI_SERIAL_CARRIER_DETECT,
> +                          EFI_SERIAL_REQUEST_TO_SEND,
> +                          EFI_SERIAL_DATA_TERMINAL_READY
> +                          are all related to the DTE (Data Terminal Equipment)
> +                          and DCE (Data Communication Equipment) modes of
> +                          operation of the serial device.
> +                        . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the
> +                          receive buffer is empty, 0 otherwise.
> +                        . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the
> +                          transmit buffer is empty, 0 otherwise.
> +                        . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if
> +                          the hardware loopback is enabled (the output feeds
> +                          the receive buffer), 0 otherwise.
> +                        . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one
> +                          if a loopback is accomplished by software, else 0.
> +                        . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to
> +                          one if the hardware flow control based on CTS (Clear
> +                          To Send) and RTS (Ready To Send) control signals is
> +                          enabled, 0 otherwise.
> +
> +  @retval RETURN_SUCCESS  The control bits were read from the device.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +SerialPortGetControl (
> +  OUT UINT32  *Control
> +  )
> +{
> +  return PL011UartGetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
> +}
> diff --git a/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf
> new file mode 100644
> index 0000000000..29f234027f
> --- /dev/null
> +++ b/Silicon/NXP/Library/PL011SerialPortLib/PL011SerialPortLib.inf
> @@ -0,0 +1,42 @@
> +#/** @file
> +#
> +#  Component description file for PL011SerialPortLib module
> +#
> +#  Copyright (c) 2011-2016, ARM Ltd. All rights reserved.<BR>
> +#  Copyright 2020 NXP
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +#**/
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = PL011SerialPortLib
> +  FILE_GUID                      = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = SerialPortLib
> +
> +[Sources.common]
> +  PL011SerialPortLib.c
> +
> +[LibraryClasses]
> +  PL011UartLib
> +  PcdLib
> +  ArmPlatformLib
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  ArmPlatformPkg/ArmPlatformPkg.dec
> +  Silicon/NXP/NxpQoriqLs.dec
> +
> +[Pcd]
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
> +
> +[FixedPcd]
> +  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
> +  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
> +  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
> +  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
> diff --git a/Silicon/NXP/NxpQoriqLs.dsc.inc b/Silicon/NXP/NxpQoriqLs.dsc.inc
> index 9922686304..2ab6ee1920 100644
> --- a/Silicon/NXP/NxpQoriqLs.dsc.inc
> +++ b/Silicon/NXP/NxpQoriqLs.dsc.inc
> @@ -100,6 +100,7 @@
>    IoAccessLib|Silicon/NXP/Library/IoAccessLib/IoAccessLib.inf
>    PlatformPeiLib|Silicon/NXP/Library/PlatformPeiLib/PlatformPeiLib.inf
>    MemoryInitPeiLib|Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> +  PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf
>  
>  [LibraryClasses.common.SEC]
>    PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
> -- 
> 2.17.1
> 

  reply	other threads:[~2020-02-12 20:26 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07 12:43 [PATCH 00/19] ADD LX2160ARDB Platform Support Pankaj Bansal
2020-02-07 12:43 ` [PATCH 01/19] Silicon/NXP: Add I2c lib Pankaj Bansal
2020-02-08 17:13   ` Leif Lindholm
2020-02-09 11:49     ` [edk2-devel] " Ard Biesheuvel
2020-02-07 12:43 ` [PATCH 02/19] Silicon/NXP: changes to use I2clib in i2cdxe Pankaj Bansal
2020-02-08 17:23   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 03/19] NXP/LS1043aRdb: Move Soc specific components to soc files Pankaj Bansal
2020-02-08 17:27   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 04/19] Silicon/NXP: Remove DuartLib and use BaseSerialPortLib16550 Pankaj Bansal
2020-02-08 17:46   ` Leif Lindholm
2020-02-10  5:48     ` Pankaj Bansal
2020-02-12 23:27       ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 05/19] NXP/BaseSerialPortLib16550: remove SerialPortInitalize functionality Pankaj Bansal
2020-02-07 12:43 ` [PATCH 06/19] Silicon/NXP: remove print information from Soc lib Pankaj Bansal
2020-02-10 17:09   ` [EXTERNAL] " Leif Lindholm
2020-02-07 12:43 ` [PATCH 07/19] Silicon/NXP: remove not needed components Pankaj Bansal
2020-02-10 17:11   ` Leif Lindholm
2020-02-11  7:24     ` Pankaj Bansal
2020-02-20 19:05       ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 08/19] Silicon/NXP: Remove unnecessary PCDs Pankaj Bansal
2020-02-10 17:32   ` Leif Lindholm
2020-02-11  8:45     ` Pankaj Bansal
2020-02-20 18:56       ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 09/19] Silicon/NXP: Move dsc file Pankaj Bansal
2020-02-11 11:35   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 10/19] Platform/NXP: rename the ArmPlatformLib as per ArmPlatformPkg Pankaj Bansal
2020-02-11 11:40   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 11/19] Silicon/NXP: Add Chassis Lib for Chassis2 Pankaj Bansal
2020-02-11 12:28   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 12/19] Silicon/NXP/LS1043A: Add SocLib Pankaj Bansal
2020-02-11 12:38   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 13/19] Silicon/NXP: Move RAM retrieval from SocLib Pankaj Bansal
2020-02-11 13:28   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 14/19] Silicon/NXP/LS1043A: Replce SocLib Pankaj Bansal
2020-02-11 13:35   ` Leif Lindholm
2020-02-12  9:37     ` Pankaj Bansal
2020-02-12 22:50       ` Leif Lindholm
2020-02-13 11:00         ` Pankaj Bansal
2020-02-20 18:45           ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 15/19] Platform/NXP/LS1043ARDB: introduce PEI Phase Pankaj Bansal
2020-02-12 20:24   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 16/19] Silicon/NXP: Add Pl011 Serial port lib Pankaj Bansal
2020-02-12 20:26   ` Leif Lindholm [this message]
2020-02-07 12:43 ` [PATCH 17/19] Silicon/NXP: Add Chassis3V2 Pankaj Bansal
2020-02-12 20:33   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 18/19] Silicon/NXP: Add LX2160A SocLib Pankaj Bansal
2020-02-12 21:39   ` Leif Lindholm
2020-02-07 12:43 ` [PATCH 19/19] Platform/NXP: Add LX2160ARDBPKG Pankaj Bansal
2020-02-12 21:36   ` Leif Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200212202605.GE23627@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox