From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::244; helo=mail-lf0-x244.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x244.google.com (mail-lf0-x244.google.com [IPv6:2a00:1450:4010:c07::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BDF1F21CEB130 for ; Mon, 30 Oct 2017 20:56:12 -0700 (PDT) Received: by mail-lf0-x244.google.com with SMTP id 75so17406190lfx.1 for ; Mon, 30 Oct 2017 21:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gld9rqO5kswB2d11OcJqiNSai8oGSnKuOiKdMb6pREU=; b=YQWnM7MaSU3dJF7JVEq+6oQ7AttCadcm6qKtfNfnpQcDIy5sfEpUokd3ZtRp0XC1VP vZXTQl1BVKeb6E8wLq01KuqWet+LEipYYPgkRxnZkw2V4hsE1frOyWZgNi+lrgXM4U8R L6gp/NmK2aQ9hLnDjOBKvnQgmWPJxg42kZUcZFuhUMRsZkE21MUso0695c+QdsQX/kjq 22sPAYDX6dr5fcUvyrw4QiASRqFIphrN5WiaUlfwJxmxd5w90CCaNsid94qPb5zH4nsa oO5pGLtJkPRKzDBD5tarf+8sJTN8r/jhmXFGQVLqdw9GeZvP9tqf7P7NlTEfkQWaq1TR Nofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gld9rqO5kswB2d11OcJqiNSai8oGSnKuOiKdMb6pREU=; b=I+U7riccdJQM5jJMzzgRwSfWRpSQ24g2AE63UckPqtNStHd5j4XF6q6QMfWdP+yLrd A8fOHA/ePo5YxETs4FbGXfb+BDEBGj3XSZiV49nXBr80ek+Q/yp1ZSxnSMIc1wfZflSk dYowYjWNZ+enocu3veLeD//wsV+yvYImGXOv0YLtgxs/4CQSHO9xF9Grne+i4rLdaVR4 ppD0AR0WQJR07139f/9Z+QZQPf368tKGtzHW/zg8lltU3bacAhujW7jFykABLMvl7VwY YoRBT/xy5ePJ5jnmlR5TinkcHByQImwtPHJAycWEqek6bS99kN47nYmun0DagKzBYv8d 2QEw== X-Gm-Message-State: AMCzsaUylvAa69nmcD8Vqr9aF4B315/tztioqjm90hWKPASGsVTJy1gS uVkagt2yFqqFlipnOSKKApMfrULPMBQ= X-Google-Smtp-Source: ABhQp+TW9MEqsp2/QPG3GX2r8ENoxPxHiT/OM6dLVBppsKkOazSArImDg5+hJn2qpJtnuPdX5wpiIQ== X-Received: by 10.46.25.87 with SMTP id p84mr262515lje.67.1509422402165; Mon, 30 Oct 2017 21:00:02 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id f21sm107393lja.25.2017.10.30.21.00.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 21:00:01 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com, jinghua@marvell.com, mw@semihalf.com, jsd@semihalf.com Date: Tue, 31 Oct 2017 04:59:35 +0100 Message-Id: <1509422375-20198-7-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509422375-20198-1-git-send-email-mw@semihalf.com> References: <1509422375-20198-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH 6/6] Marvell/Drivers: MvSpiDxe: Keep data in SPI_DEVICE structure X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Oct 2017 03:56:13 -0000 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 --- 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