From patchwork Thu Apr 23 17:00:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1104 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7204841496 for ; Thu, 23 Apr 2020 19:01:22 +0200 (CEST) Received: by mail-pg1-f198.google.com with SMTP id 189sf5133243pgb.10 for ; Thu, 23 Apr 2020 10:01:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1587661280; cv=pass; d=google.com; s=arc-20160816; b=OjNgkA4nA3ChvaZrnUtsIhR2NH578FikH+GtvsYUMSVPaq39sXZXfRBJ2O/Pb4LVa4 1/H0/uFppk/SGBXodyleYBQgVbECeTKIG2JmOVmM9K172Yhv+XRa8XgF5vAW7eTrwEco uI30YMVGJJPJCn96l2Dr4WUL2VUFmF72fY2VV6vKUKWkNYymIpSMfbDCTvoHEnyUGas1 1zYkajUVSQYZzTXq6Iggjr45ywdlXlTopxP/4xorjIW5TWKa3EMZqsk0Csmz/EUg36Lc gOLmGjn9Gn2hZRP0LSnXAnl8ngm15LWe6/nrxjyDPORoL+sDcitYR0unpvsgRTKRwIa2 Pr7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t6LAJVkpAaL0ZXpeRN3ytdpQJwB4DCSgldy+Oaubg2A=; b=b24CnlYEuxifPnwNQGms6JQKyI3GUhpdGrHYjwYCZ/CmTQSiemvCVwHyS/laVBtXN3 lwJNvGEazI9yIDa/Bey2BhvYEdM0BwSbYc5cGIx5uuYVFe8soFf1LdT3Ef0b+0qYW7RH xNuqazNjzQqqHqHENhFn+JQkNnEJQ3EogqU+y0ewqjRW256Ojz57eo06bOVlNUDypQ+g gnsJRarNaWe02PEyhK9gw939E5VqdVcuicPYVDqFuCJCoUe9Qw6KyRheljm6v/oaTXbm yW4Md4E4VZu+no1E48JAQYOmzIFQNvuiVxKoHexJdcT8hn84BPgtQ6upsrLSe496ZixN aYnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RGyc7OiE; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=t6LAJVkpAaL0ZXpeRN3ytdpQJwB4DCSgldy+Oaubg2A=; b=Gl5l9j9uH9JJtiN4CB29d3d3MWRF7GFRyxFcwMfHBByAl+42916mER1SVq10qcPx88 qd3qbX8n/TlDz4dFUi0NI9hlJ6guITFglbrkdLTmUpCJG26VCVEiLoAlfZ9xOwXg3tNn f9VJsOFOyE94kEvnVB7+7vh395XDZpg3+aIzc= 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:mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=t6LAJVkpAaL0ZXpeRN3ytdpQJwB4DCSgldy+Oaubg2A=; b=p3/xwtjyIaEbsNoWsu9X60u9PLAQOwoZzSkJCgssJAEuYlXzSTXWUtYEYeqIPykrmR Grj8n/JIRcCTRbb1PG2VkoU0THncj001gehPkoCrKD24qsoFPdGYJAQIt4+G2ks6DJlM EO4jpt0IGmxSBirIiRyTwF2D4J7CKwzvzKDCSjZrsIG2tjx41TSYMo6UQzHjoJrBjc9o VdC5EE1P189W9LGTO1GxqBRg9+pbQIOeFARfeHfYxddjpH29I37SPJaxBUevJmjHbL3T XxjyIIQGaOlY87EZ0CEbEA3gCb7gt35pc7bcOqqKno1nlHWVlpXHpVm5SVzJJA2YnuOl IBdw== X-Gm-Message-State: AGi0PuYBXET7NMuZX0zk4qKFhqjohnWIHuCRG0nj/6vqVC9wNy9Uz4fc d6v9iduTIObO3rEyXvoM+oapbOiM X-Google-Smtp-Source: APiQypIaAImu0z69qbQJwRclIqWwUFav/xbNAMjJFvqQdmpW6OtUg8524AbIlm4+VF562OsPnUiMaw== X-Received: by 2002:aa7:8bc8:: with SMTP id s8mr4765257pfd.252.1587661279461; Thu, 23 Apr 2020 10:01:19 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:7203:: with SMTP id ba3ls692831plb.4.gmail; Thu, 23 Apr 2020 10:01:19 -0700 (PDT) X-Received: by 2002:a17:90a:dd45:: with SMTP id u5mr1615008pjv.19.1587661278900; Thu, 23 Apr 2020 10:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587661278; cv=none; d=google.com; s=arc-20160816; b=wfvPaI7G9L3pMo/O678cMi4y2C4v7BDKavTAsgFUMqcCEOHPU/8RYETBLE7/vIffnT A4Nu1a5oQHpqH+ih0kwtF5mDixvxTSP9i4UQs9TpL6XxUzPO4Biy90GfExaCDVYp4mzo bnLeXCtRDewMsA6mSXQjwaDaSSEq9sk9qjb4POs6XD+wATsPjQq2pnifw4fOKZhZlKq3 7thq4NYNL5pAqTkUC/gwGRMcTgeRNWOVSzs8FnlHwp86g/pWM2BEt5teUXOl5yOTp+hk pGw4uX3OtOvZFvbeyZe3dwn060gEg3mzrafrhv7tTG6xkuY+4njgELhzRJ3oQzCopEh6 lLOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=TaI2O8vgjlonnoHlMX0+YV2RvJ2UJQpboIKrb8XT2P4=; b=pktWVaWKLzjJfri/5NKnBCQOgpd4tYwmWNwDvK3SFiOiQPSgmm+zoGwxbyAqNnFkYZ EKk8YdqcIgaI0eIMOTEVpLrbcJ5gGEjXWWcykBT8wMW50z91voUk8KHKImEJiDEmDJyz uoW0ANcwVcpS2dph3RuyKNgB+Dnswnc/9C9c0TujPF9dp/HPTcplyu5fwtEwIAuRsNWT uCGnvSOcW6JogvfmGicE1dLjmGc69MQ+TJl/qIoYWKdus5nNYzTdc3h7S9XVSq6pSZAB FOHVH1OBr2Z+efk3SYsIimCuOUTP7oYbAsn6CufksxkxFD4aWc3p1YebpXKGyR13imUc AeUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RGyc7OiE; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id fz9sor4192611pjb.22.2020.04.23.10.01.18 for (Google Transport Security); Thu, 23 Apr 2020 10:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:90a:2526:: with SMTP id j35mr1626704pje.98.1587661278463; Thu, 23 Apr 2020 10:01:18 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:587e:69d7:8a4e:a122]) by smtp.gmail.com with ESMTPSA id w2sm3084146pfc.194.2020.04.23.10.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 10:01:17 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Cc: Rick Chen , Bin Meng , Bhargav Shah , Sagar Shrikant Kadam , linux-amarula@amarulasolutions.com, Jagan Teki , Vignesh R Subject: [PATCH v4 3/5] spi: sifive: Fix QPP transfer Date: Thu, 23 Apr 2020 22:30:55 +0530 Message-Id: <20200423170057.1976-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423170057.1976-1-jagan@amarulasolutions.com> References: <20200423170057.1976-1-jagan@amarulasolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RGyc7OiE; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The guessed reason is that the existing logic of filling tx fifo with data, rx fifo with NULL for tx transfer and filling rx fifo with data, tx fifo with NULL for rx transfer is not clear enough to support the Quad Page Program.     SiFive SPI controllers have specific sets of watermark registers and SPI I/O directions bits in order to program SPI controllers clear enough to support all sets of operating modes.     Here is the exact programing sequence that would follow on this patch and tested via SPI-NOR and MMC_SPI.     - set the frame format proto, endian - set the frame format dir, set it for tx and clear it for rx - TX transfer:   fill tx fifo with data.   wait for TX watermark bit to clear. - RX transfer:   fill tx fifo with 0xff.   write nbytes to rx watermark register   wait for rx watermark bit to clear.   read the rx fifo data. So, this patch adopts this program sequence and fixes the existing I/O direction bit. Cc: Vignesh R Signed-off-by: Jagan Teki --- Changes for v4: - update commit message drivers/spi/spi-sifive.c | 57 ++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-sifive.c b/drivers/spi/spi-sifive.c index 0ea4930a0a..4cab0391f7 100644 --- a/drivers/spi/spi-sifive.c +++ b/drivers/spi/spi-sifive.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -134,8 +135,8 @@ static void sifive_spi_clear_cs(struct sifive_spi *spi) } static void sifive_spi_prep_transfer(struct sifive_spi *spi, - bool is_rx_xfer, - struct dm_spi_slave_platdata *slave_plat) + struct dm_spi_slave_platdata *slave_plat, + u8 *rx_ptr) { u32 cr; @@ -167,7 +168,7 @@ static void sifive_spi_prep_transfer(struct sifive_spi *spi, /* SPI direction in/out ? */ cr &= ~SIFIVE_SPI_FMT_DIR; - if (!is_rx_xfer) + if (!rx_ptr) cr |= SIFIVE_SPI_FMT_DIR; writel(cr, spi->regs + SIFIVE_SPI_REG_FMT); @@ -198,13 +199,19 @@ static void sifive_spi_tx(struct sifive_spi *spi, const u8 *tx_ptr) writel(tx_data, spi->regs + SIFIVE_SPI_REG_TXDATA); } +static int sifive_spi_wait(struct sifive_spi *spi, u32 bit) +{ + return wait_for_bit_le32(spi->regs + SIFIVE_SPI_REG_IP, + bit, true, 100, false); +} + static int sifive_spi_xfer(struct udevice *dev, unsigned int bitlen, const void *dout, void *din, unsigned long flags) { struct udevice *bus = dev->parent; struct sifive_spi *spi = dev_get_priv(bus); struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev); - const unsigned char *tx_ptr = dout; + const u8 *tx_ptr = dout; u8 *rx_ptr = din; u32 remaining_len; int ret; @@ -217,31 +224,37 @@ static int sifive_spi_xfer(struct udevice *dev, unsigned int bitlen, return ret; } - sifive_spi_prep_transfer(spi, true, slave_plat); + sifive_spi_prep_transfer(spi, slave_plat, rx_ptr); remaining_len = bitlen / 8; while (remaining_len) { - int n_words, tx_words, rx_words; - - n_words = min(remaining_len, spi->fifo_depth); + unsigned int n_words = min(remaining_len, spi->fifo_depth); + unsigned int tx_words, rx_words; /* Enqueue n_words for transmission */ - if (tx_ptr) { - for (tx_words = 0; tx_words < n_words; ++tx_words) { - sifive_spi_tx(spi, tx_ptr); - sifive_spi_rx(spi, NULL); - tx_ptr++; - } + for (tx_words = 0; tx_words < n_words; tx_words++) { + if (!tx_ptr) + sifive_spi_tx(spi, NULL); + else + sifive_spi_tx(spi, tx_ptr++); } - /* Read out all the data from the RX FIFO */ if (rx_ptr) { - for (rx_words = 0; rx_words < n_words; ++rx_words) { - sifive_spi_tx(spi, NULL); - sifive_spi_rx(spi, rx_ptr); - rx_ptr++; - } + /* Wait for transmission + reception to complete */ + writel(n_words - 1, spi->regs + SIFIVE_SPI_REG_RXMARK); + ret = sifive_spi_wait(spi, SIFIVE_SPI_IP_RXWM); + if (ret) + return ret; + + /* Read out all the data from the RX FIFO */ + for (rx_words = 0; rx_words < n_words; rx_words++) + sifive_spi_rx(spi, rx_ptr++); + } else { + /* Wait for transmission to complete */ + ret = sifive_spi_wait(spi, SIFIVE_SPI_IP_TXWM); + if (ret) + return ret; } remaining_len -= n_words; @@ -395,6 +408,10 @@ static void sifive_spi_init_hw(struct sifive_spi *spi) /* Watermark interrupts are disabled by default */ writel(0, spi->regs + SIFIVE_SPI_REG_IE); + /* Default watermark FIFO threshold values */ + writel(1, spi->regs + SIFIVE_SPI_REG_TXMARK); + writel(0, spi->regs + SIFIVE_SPI_REG_RXMARK); + /* Set CS/SCK Delays and Inactive Time to defaults */ writel(SIFIVE_SPI_DELAY0_CSSCK(1) | SIFIVE_SPI_DELAY0_SCKCS(1), spi->regs + SIFIVE_SPI_REG_DELAY0);