From patchwork Mon Apr 20 12:52:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1089 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 4F29E3F1FE for ; Mon, 20 Apr 2020 14:52:52 +0200 (CEST) Received: by mail-pl1-f197.google.com with SMTP id d4sf8477384plr.18 for ; Mon, 20 Apr 2020 05:52:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1587387170; cv=pass; d=google.com; s=arc-20160816; b=aiqBqN7W2Sbh/dU4pXhTfUlaH1yyYxJfkRv57b62okFomBxy/wRyP43VIiyFLnK0TR WlQ9l5ofY/5UXNsPsRqcQdVyTi0xXEd8jCRZLoMSEv5n0a1Rb3wueolEp6PJQAfhknI1 3pReLV6XnkLMmG0/RngtbyBb3XYOWEoI1V3aapA7A+O0DQOktn8HzotMb/KuxKJChh3P I7bFFR9kPYjWmpxLKHpod6WsGsayjgJ22CzTxBxW9OvtBXMgWtkVuLo0lFM5/JuQldDT Qw1Lp8NsAjqIBh5JRM21FV3l1zH2tzXLwXT3AK3eJBRCFupDmbuHaJj3YI9sDiIADN5P 7jKA== 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=G3YogDmmfzG0VTXsvdkKzS5/wvbH4F7YZ+dRiyS3iSg=; b=E3D3a4l7cuny3F5639cNn/sjoin1cSr3VWY5kKHflv9TOxNLXvUEzVianOu8mlWFQS fyHMHs4sVvB3oyOMXDWF+i6ynjdBtoJpSaSh+Y11kdJ+G5h7JHQI+G/1e5B11M748kGI FBnsCpTDh8QGXK94ODFNnT5wsUoMSIxJFDctWK/6eB5BhN+dygUWdBgTGakjEzXSkV2p 6p84+2gHYc60tMH7oNA532p/C9HnVNcJZkXr6vZg+im9dpSL0T+BP3xRDS6aydW3dUju A0OcRqM/iB3pQvhgSF/7zQqHDxR0oVU3Dph0GPu3DEowe4a5RhhQQdqRPCskptCZKHzS 9GSg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BRcHk1W3; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 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=G3YogDmmfzG0VTXsvdkKzS5/wvbH4F7YZ+dRiyS3iSg=; b=APRG2TwldvMvg7+a4ZZVlHEgtW6VERc2c/+/uukuX1qyAN0dzQogDy9FxVmh7I0mjN mkpiYsMWWRhhFGza9uvvU665QF8oVGa1+Tzwqyf1vWiYJvkq+z/mva0B2IGc+TCjAd1T TyLEle/yidZCeWF++5m6040laxbaHtsB6cXkM= 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=G3YogDmmfzG0VTXsvdkKzS5/wvbH4F7YZ+dRiyS3iSg=; b=Y/FWyomtOTnloh90xLFAZAL0ir6eAd5oJhgAeTJpDzG4KeRBYVsib5jMo0Qk2cq3vz N9M+r7fdP2G9a6cnS0riSBxaPr2NtSuELdd0sI0IxulZ6gsVUoSbM6CwcxEuhYTkrB09 8z3Hk2SHJnWwp9FxhsgSKVFcTpPnbiveNm3Y+g1S6AS9Y6qOrKAcIANuRB+eZJA3qgkz WwIYxppuJuyJ+TP63x+CMAd2HcQhzzMKhDEdeLIv6kcCNrZFvHI2E/akx8KjozbjwXjG NdCMQ0iCQeCv0wgftvERc9KNQ5uhhEwHWrJDDFmKG6xjWJi+yzQKJbhEfiSchoOaHPG8 veOw== X-Gm-Message-State: AGi0PuYpKSqn7lM//d2h4SmnTO9QKamwQLPPPgc5LcU5e9hJ7Bfne93n BlRreCirBtzLH4PbFTRZjqHMLAk+ X-Google-Smtp-Source: APiQypL0IxciquZObfc3HL7y10Tjqwp1YuuwQYK7u/ZRCAYTVeNQF3wZdSQsusaIV0oAl1NNW9H9sQ== X-Received: by 2002:a17:90a:fb89:: with SMTP id cp9mr20828354pjb.40.1587387170664; Mon, 20 Apr 2020 05:52:50 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:68c1:: with SMTP id d184ls9452170pgc.9.gmail; Mon, 20 Apr 2020 05:52:50 -0700 (PDT) X-Received: by 2002:aa7:990f:: with SMTP id z15mr17375549pff.132.1587387170110; Mon, 20 Apr 2020 05:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587387170; cv=none; d=google.com; s=arc-20160816; b=Y3RJwHpCwIM53OswAiws4RCwbxKYRgl0YST9wnlOf9r4yK3PkUiRXT9ICN92oPaMW5 FT0ZE6mvDgr0SwATv5QxNoZO2T5WnrzLn5tj86CyxGKlFuErPgRAcLmMMcILsTzqt8+s jUMe1Ol0WoV+JT760X18KEWhU20wPyAP7qT+9dFCeRLPyv+swGBDLu/RUk2CBw5x72Qo 6wBIQ2oCR+DBugV1MAQ9HKKrwbTJpNpdtW4d3ZWkT/fLgYTikeCNoZU9f2ziF3/1NGmR tUgmu/hbkP9Gw0lIb8Pifq3poIlIcG8b3el8PmpptshQlcnRA6IDV6PlA0grK6uSWLRZ TSQg== 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=i23D2qIVooNAK47rSTC2z+zU5i8s7zN5uHrQ/axcnjw=; b=MBGjf8pV7eMXbeLmOAvIx2eZGiJK0hArafLv50N4mwUeEbrf3CzGKuQ80PnZ4AhEuK 0h4hxAuVUTIUhH2dn0jgoXNKCWoO09bNO+WVmNCB9arlSdcged2Tc2DYRS0QGnijwr3A VPK8K7qWYZqLqru7RLYVWZNfQ9vkLoXKAYJmxATeNPjtZTBj1xXF5fArmFsM54I2xX5M vFvIFdppOtsiCMGe1FCNZzCIM/z2oqfLVoGdoP8NAM7RsyjOsCreMm4kAiM2wWEMuG2g mQxhCIWUzhLgj9DWjUQl/ZtYOkBfmqe5q5cpz+SBWk+bIm7gEWvtqESB907t4KUbSMfQ fUnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BRcHk1W3; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p6sor1027229pfq.95.2020.04.20.05.52.50 for (Google Transport Security); Mon, 20 Apr 2020 05:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a62:18c8:: with SMTP id 191mr17013998pfy.255.1587387169773; Mon, 20 Apr 2020 05:52:49 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:7ddc:e17b:a9b3:404]) by smtp.gmail.com with ESMTPSA id i25sm1036932pfd.140.2020.04.20.05.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 05:52:49 -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 Subject: [PATCH v3 1/3] spi: sifive: Fix QPP transfer Date: Mon, 20 Apr 2020 18:22:36 +0530 Message-Id: <20200420125238.9610-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200420125238.9610-1-jagan@amarulasolutions.com> References: <20200420125238.9610-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=BRcHk1W3; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 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: , For historical reasons 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. - TX 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. Signed-off-by: Jagan Teki --- Changes for v3: - new patch 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 336b683476..2a0b28dc08 100644 --- a/drivers/spi/spi-sifive.c +++ b/drivers/spi/spi-sifive.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -127,8 +128,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; @@ -160,7 +161,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); @@ -191,13 +192,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; @@ -210,31 +217,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; @@ -314,6 +327,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);