public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Marcin Wojtas <mw@semihalf.com>
Cc: edk2-devel@lists.01.org, ard.biesheuvel@linaro.org,
	nadavh@marvell.com, neta@marvell.com, kostap@marvell.com,
	jinghua@marvell.com, jsd@semihalf.com
Subject: Re: [platforms: PATCH 6/6] Marvell/Drivers: MvSpiDxe: Keep data in SPI_DEVICE structure
Date: Wed, 1 Nov 2017 03:54:17 +0000	[thread overview]
Message-ID: <20171101035417.tvidg4hioeue4ecu@bivouac.eciton.net> (raw)
In-Reply-To: <1509422375-20198-7-git-send-email-mw@semihalf.com>

On Tue, Oct 31, 2017 at 04:59:35AM +0100, Marcin Wojtas wrote:
> In the MvSpiDxe driver obtaining host register base address,
> controller clock and device maximum frequency directly from PCDs
> was done all over the code. This patch cleans up the parameters'
> handling and enables accessing them from SPI_DEVICE structure fields.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  Platform/Marvell/Drivers/Spi/MvSpiDxe.c | 48 ++++++++++++--------
>  Platform/Marvell/Include/Protocol/Spi.h |  2 +
>  2 files changed, 31 insertions(+), 19 deletions(-)
> 
> diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c b/Platform/Marvell/Drivers/Spi/MvSpiDxe.c
> index a7db5f2..c60a520 100755
> --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c
> +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.c
> @@ -38,12 +38,13 @@ SPI_MASTER *mSpiMasterInstance;
>  STATIC
>  EFI_STATUS
>  SpiSetBaudRate (
> +  IN SPI_DEVICE *Slave,
>    IN UINT32 CpuClock,
>    IN UINT32 MaxFreq
>    )
>  {
>    UINT32 Spr, BestSpr, Sppr, BestSppr, ClockDivider, Match, Reg, MinBaudDiff;
> -  UINTN SpiRegBase = PcdGet32 (PcdSpiRegBase);
> +  UINTN SpiRegBase = Slave->HostRegisterBaseAddress;
>  
>    MinBaudDiff = 0xFFFFFFFF;
>    BestSppr = 0;
> @@ -93,26 +94,28 @@ SpiSetBaudRate (
>  STATIC
>  VOID
>  SpiSetCs (
> -  UINT8 CsId
> +  IN SPI_DEVICE *Slave
>    )
>  {
> -  UINT32 Reg, SpiRegBase = PcdGet32 (PcdSpiRegBase);
> +  UINT32 Reg;
> +  UINTN  SpiRegBase = Slave->HostRegisterBaseAddress;
>  
>    Reg = MmioRead32 (SpiRegBase + SPI_CTRL_REG);
>    Reg &= ~SPI_CS_NUM_MASK;
> -  Reg |= (CsId << SPI_CS_NUM_OFFSET);
> +  Reg |= (Slave->Cs << SPI_CS_NUM_OFFSET);
>    MmioWrite32 (SpiRegBase + SPI_CTRL_REG, Reg);
>  }
>  
>  STATIC
>  VOID
>  SpiActivateCs (
> -  UINT8 IN CsId
> +  IN SPI_DEVICE *Slave
>    )
>  {
> -  UINT32  Reg, SpiRegBase = PcdGet32 (PcdSpiRegBase);
> +  UINT32 Reg;
> +  UINTN  SpiRegBase = Slave->HostRegisterBaseAddress;
>  
> -  SpiSetCs(CsId);
> +  SpiSetCs(Slave);
>    Reg = MmioRead32 (SpiRegBase + SPI_CTRL_REG);
>    Reg |= SPI_CS_EN_MASK;
>    MmioWrite32(SpiRegBase + SPI_CTRL_REG, Reg);
> @@ -121,10 +124,11 @@ SpiActivateCs (
>  STATIC
>  VOID
>  SpiDeactivateCs (
> -  VOID
> +  IN SPI_DEVICE *Slave
>    )
>  {
> -  UINT32  Reg, SpiRegBase = PcdGet32 (PcdSpiRegBase);
> +  UINT32 Reg;
> +  UINTN  SpiRegBase = Slave->HostRegisterBaseAddress;
>  
>    Reg = MmioRead32 (SpiRegBase + SPI_CTRL_REG);
>    Reg &= ~SPI_CS_EN_MASK;
> @@ -139,14 +143,15 @@ SpiSetupTransfer (
>    )
>  {
>    SPI_MASTER *SpiMaster;
> -  UINT32 Reg, SpiRegBase, CoreClock, SpiMaxFreq;
> +  UINT32 Reg, CoreClock, SpiMaxFreq;
> +  UINTN SpiRegBase;
>  
>    SpiMaster = SPI_MASTER_FROM_SPI_MASTER_PROTOCOL (This);
>  
>    // Initialize values from PCDs
> -  SpiRegBase  = PcdGet32 (PcdSpiRegBase);
> -  CoreClock   = PcdGet32 (PcdSpiClockFrequency);
> -  SpiMaxFreq  = PcdGet32 (PcdSpiMaxFrequency);
> +  SpiRegBase  = Slave->HostRegisterBaseAddress;
> +  CoreClock   = Slave->CoreClock;
> +  SpiMaxFreq  = Slave->MaxFreq;
>  
>    EfiAcquireLock (&SpiMaster->Lock);
>  
> @@ -154,9 +159,9 @@ SpiSetupTransfer (
>    Reg |= SPI_BYTE_LENGTH;
>    MmioWrite32 (SpiRegBase + SPI_CONF_REG, Reg);
>  
> -  SpiSetCs(Slave->Cs);
> +  SpiSetCs(Slave);
>  
> -  SpiSetBaudRate (CoreClock, SpiMaxFreq);
> +  SpiSetBaudRate (Slave, CoreClock, SpiMaxFreq);
>  
>    Reg = MmioRead32 (SpiRegBase + SPI_CONF_REG);
>    Reg &= ~(SPI_CPOL_MASK | SPI_CPHA_MASK | SPI_TXLSBF_MASK | SPI_RXLSBF_MASK);
> @@ -194,21 +199,22 @@ MvSpiTransfer (
>  {
>    SPI_MASTER *SpiMaster;
>    UINT64  Length;
> -  UINT32  Iterator, Reg, SpiRegBase;
> +  UINT32  Iterator, Reg;
>    UINT8   *DataOutPtr = (UINT8 *)DataOut;
>    UINT8   *DataInPtr  = (UINT8 *)DataIn;
>    UINT8   DataToSend  = 0;
> +  UINTN   SpiRegBase;
>  
>    SpiMaster = SPI_MASTER_FROM_SPI_MASTER_PROTOCOL (This);
>  
> -  SpiRegBase = PcdGet32 (PcdSpiRegBase);
> +  SpiRegBase = Slave->HostRegisterBaseAddress;
>  
>    Length = 8 * DataByteCount;
>  
>    EfiAcquireLock (&SpiMaster->Lock);
>  
>    if (Flag & SPI_TRANSFER_BEGIN) {
> -    SpiActivateCs (Slave->Cs);
> +    SpiActivateCs (Slave);
>    }
>  
>    // Set 8-bit mode
> @@ -245,7 +251,7 @@ MvSpiTransfer (
>    }
>  
>    if (Flag & SPI_TRANSFER_END) {
> -    SpiDeactivateCs ();
> +    SpiDeactivateCs (Slave);
>    }
>  
>    EfiReleaseLock (&SpiMaster->Lock);
> @@ -312,6 +318,10 @@ MvSpiSetupSlave (
>      Slave->Mode = Mode;
>    }
>  
> +  Slave->HostRegisterBaseAddress = PcdGet32 (PcdSpiRegBase);
> +  Slave->CoreClock = PcdGet32 (PcdSpiClockFrequency);
> +  Slave->MaxFreq = PcdGet32 (PcdSpiMaxFrequency);
> +
>    SpiSetupTransfer (This, Slave);
>  
>    return Slave;
> diff --git a/Platform/Marvell/Include/Protocol/Spi.h b/Platform/Marvell/Include/Protocol/Spi.h
> index 0cf7914..b8981f3 100644
> --- a/Platform/Marvell/Include/Protocol/Spi.h
> +++ b/Platform/Marvell/Include/Protocol/Spi.h
> @@ -52,6 +52,8 @@ typedef struct {
>    INTN MaxFreq;
>    SPI_MODE Mode;
>    NOR_FLASH_INFO *Info;
> +  UINTN HostRegisterBaseAddress;
> +  UINTN CoreClock;
>  } SPI_DEVICE;
>  
>  typedef
> -- 
> 2.7.4
> 


      reply	other threads:[~2017-11-01  3:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  3:59 [platforms: PATCH 0/6] Armada 7k/8k SPI improvements pt 2 Marcin Wojtas
2017-10-31  3:59 ` [platforms: PATCH 1/6] Marvell/Drivers: MvSpiFlash: Improve ReadId Marcin Wojtas
2017-10-31  9:07   ` Leif Lindholm
2017-10-31  9:22     ` Marcin Wojtas
2017-11-01  3:14       ` Leif Lindholm
2017-11-01 16:28         ` Marcin Wojtas
2017-10-31  3:59 ` [platforms: PATCH 2/6] Marvell/Drivers: MvSpiFlash: Enable dynamic SPI Flash detection Marcin Wojtas
2017-11-01  3:25   ` Leif Lindholm
2017-11-01 16:35     ` Marcin Wojtas
2017-10-31  3:59 ` [platforms: PATCH 3/6] Marvell/Drivers: MvSpiFlash: Remove duplicated macros Marcin Wojtas
2017-11-01  3:27   ` Leif Lindholm
2017-11-01 16:36     ` Marcin Wojtas
2017-10-31  3:59 ` [platforms: PATCH 4/6] Marvell/Applications: SpiTool: Do not override existing slave device Marcin Wojtas
2017-11-01  3:45   ` Leif Lindholm
2017-11-01 16:40     ` Marcin Wojtas
2017-11-01 17:15       ` Ard Biesheuvel
2017-10-31  3:59 ` [platforms: PATCH 5/6] Marvell/Drivers: MvSpiFlash: Fix bank selection for Spansion Marcin Wojtas
2017-11-01  3:50   ` Leif Lindholm
2017-11-01 16:41     ` Marcin Wojtas
2017-10-31  3:59 ` [platforms: PATCH 6/6] Marvell/Drivers: MvSpiDxe: Keep data in SPI_DEVICE structure Marcin Wojtas
2017-11-01  3:54   ` Leif Lindholm [this message]

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=20171101035417.tvidg4hioeue4ecu@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