From patchwork Thu Apr 23 17:00:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1103 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D692541496 for ; Thu, 23 Apr 2020 19:01:17 +0200 (CEST) Received: by mail-vk1-f198.google.com with SMTP id m76sf3119097vke.4 for ; Thu, 23 Apr 2020 10:01:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1587661276; cv=pass; d=google.com; s=arc-20160816; b=Z9y7mtU001k6RqvqwAF0N5+SB4+wsqT4KG5v0EPlS29FoXqOE3SwP9kuKwHXWWQC3X 76yhPCJ7PoaZfW4nJ1OLcxbRfJLgGEwplQ1BCOrK+n+7eDB1F//hVYRa7FisggMn+4WZ yiACD2BF0RUGhJ+3Ukgqh6J4CJNEq23vlvRPnCXId4rqeew0lJlZ6FEuQKYx1qyOnlQ1 LeJkxBGt29RkE1XDeygH3ZJ3JS4EkGmEqHrTIk8QZfW+mDo6O+v8LibeteAtq+qewN6b g0rM0iF7dUjosmd0WEFECKib9H8IQtKKhCglZgOharmNm47ScdCA6WWYRB2KK/vcUOFf Zn0g== 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=7SlTWew0TF3iag0/N7v+xESCPRbLzQPDVc8yNx5sgTU=; b=BhgpVK95AKlBJxNr+WG/uymaJiYuZzW4EQcSVUP4KhMrbJ/dOBBzspxLn0/btd9JLE IW7yIL2Sj8jEctjEZYjUWYXRPd7CgTf0Z0/+QOMgAsFc4SXM8I9x3syA0BTkhng7WJc4 fKUKTK0jzZt0BMnhw4Fh1dMwaUgjTpZNNoGgwJVSACXFGbuArHrGZsPfHpqvt6zKrJh1 9uF1/nIhgTKAQ3zD0lbDMDMZx8mSzbycgTPq89JklmZAkAwRxVhYSl4H/hTQCZDBJn2S U9Q907ajpVAAgi8oRgswvV/qRp97QdHWQINDuhKVcwlDmzWW2aWJpblVHS9clRyPTIjS eAgQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jVxQJTEw; 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=7SlTWew0TF3iag0/N7v+xESCPRbLzQPDVc8yNx5sgTU=; b=S+p9oubVUdfUllj9W3zapBTESe8wUIK4GfYxd6GwyqLruYNhRpSUlNmxjt6rhkfpf4 to2iWiyrL5pBWDK3h+sjAZk052aWe/PayNKCPaOEMsToMvXXf1IiDlXiBYtfyTJdg21j Vol+wfGaWXGwb8Y/Uz4ce3KQElPBwOWSZV2Ps= 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=7SlTWew0TF3iag0/N7v+xESCPRbLzQPDVc8yNx5sgTU=; b=P7OAg3Tt7ewrwO02S/eh86CdINZGjRwIDUO8MOIza/+Q2cw/TbiGEw9efyOA9XRoHt qvk/aBl1jA2+D2TpAVuKHwWUxIf6xTasgxhGbuPg6tiUvbChQuTkrkCOWdMNUPNld1XX vtjOSFevpGszRwSoylqSG+9EMX0q5KeGl6BP9Szpcfq1wCXFZJB1tl71SrEMnk/hF1iT Ij0FBUYeX5UN2R6NiBiBetw39M7543tw/wE0tTxyinCWZrt1Zt+YanFkTld5qsPP/8G+ IZGhIP/dRiUnR/b08+VGF/c9Mq6TZv9OfiucSWsEDM5smUUycHzvARFFIVJ3SbdefazB qtzA== X-Gm-Message-State: AGi0PuYSIpflO8gr0z8xjDmGQ6WWCrjY+HBvW406QllRzD5voulqgJmy CahksTd+5vPDt2JOXDTfC1386rzt X-Google-Smtp-Source: APiQypIPs2udK4PYO8+P52EvuKiE9oEGp3yoTi9pBg5VgtOfFkKzbhfNo0KcFWInM58TgpbrvEm0Lg== X-Received: by 2002:a1f:9148:: with SMTP id t69mr4137305vkd.83.1587661276434; Thu, 23 Apr 2020 10:01:16 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a67:f605:: with SMTP id k5ls963823vso.2.gmail; Thu, 23 Apr 2020 10:01:16 -0700 (PDT) X-Received: by 2002:a05:6102:409:: with SMTP id d9mr4135136vsq.220.1587661275915; Thu, 23 Apr 2020 10:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587661275; cv=none; d=google.com; s=arc-20160816; b=uiV0NVcCpZ+PUYzU4LriWyDvkcj98/x5HKhzQY3XhXmrSOzQPPfaEXhu2FdHswVKns 3NrZdGjQAGKPZrXw/viffBKbh+21AcFgkgO8e4yT5dahh4QEbtUsVppqLe2sXDpl5XjR MHqxLvLUICyUpM/tLB6voPuoY9RqNtgDF2+F6AaUBxThuwB+5bPuiczSA+VnxiN3RDpC O7HDcjmmDL1W5DBCjTtIwqnFrt+ZBwhP45/VsNM9Coa4pweQ1iuWYhVGw6eYdegwprD3 NEiEJSNM0vxMDHs5DiFSkSiF3dyFmxlQq2W5ImqNkt6WN2kxn24/M1oohjUqr8G4942v 2gCw== 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=qd9a9Bpe2vulcb7CflNsSS2kb1zWBFdJUqbqnTGph44=; b=BVklzKB+M8VjZR/Umkji9tS8c1h6rb+fp6dii9y+FOtsHX3x6Lwsa17P21HzIcMjvM P9zYKeGGJgnDWBDz4KP/oiW5H3Sy3FRXIVo6u0h4ETKlRRyivtT/xdXGGt0n9fMYx85a 7E6fGcjgvhIL6o8CnX5iLhbPtiNRDrnoIq4TsKxbAoJNhtXhVK6JpAJyPdSYYTaYlQPm agyc7EJQwpFfXsuSojjzFvzzRRssAp/6eEe8OPBK1VJ0LeOLJK1eSjVaxp7wioEiePtN jZ9D5+1nZsRs9x4QFQi9kqwgL/OiZsfduhH93lsb6IlebRKoN54HzlMbwsMM2X9sqzc4 cpSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jVxQJTEw; 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 r143sor1840200vke.25.2020.04.23.10.01.15 for (Google Transport Security); Thu, 23 Apr 2020 10:01:15 -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:a17:902:6a82:: with SMTP id n2mr2585644plk.159.1587661274661; Thu, 23 Apr 2020 10:01:14 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 10:01:13 -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 2/5] spi: sifive: Fix format register proto field Date: Thu, 23 Apr 2020 22:30:54 +0530 Message-Id: <20200423170057.1976-3-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=jVxQJTEw; 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: , SiFive SPI controller has a proto bit field in frame format register which would be used to configure the SPI I/O protocol lines used on specific transfer.  Right now the driver is configuring this proto using slave->mode, for all types of transctions. This makes the driver unable to function since the proto needs to configure dynamically for each and every transaction separately at runtime. Now, the controller driver supports per transfer via spi-mem exec_opo, so add the fmt_proto flag and fill the per transfer buswidth so that the controller configures the proto bit at runtime. This patch fixes the SPI controller works with SPI NOR flash on quad read with page program. Cc: Vignesh R Signed-off-by: Jagan Teki --- Changes for v4: - new patch drivers/spi/spi-sifive.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-sifive.c b/drivers/spi/spi-sifive.c index 5e612edcff..0ea4930a0a 100644 --- a/drivers/spi/spi-sifive.c +++ b/drivers/spi/spi-sifive.c @@ -86,6 +86,11 @@ #define SIFIVE_SPI_IP_TXWM BIT(0) #define SIFIVE_SPI_IP_RXWM BIT(1) +/* format protocol */ +#define SIFIVE_SPI_PROTO_QUAD 4 /* 4 lines I/O protocol transfer */ +#define SIFIVE_SPI_PROTO_DUAL 2 /* 2 lines I/O protocol transfer */ +#define SIFIVE_SPI_PROTO_SINGLE 1 /* 1 line I/O protocol transfer */ + struct sifive_spi { void *regs; /* base address of the registers */ u32 fifo_depth; @@ -93,6 +98,7 @@ struct sifive_spi { u32 cs_inactive; /* Level of the CS pins when inactive*/ u32 freq; u32 num_cs; + u8 fmt_proto; }; static void sifive_spi_prep_device(struct sifive_spi *spi, @@ -147,12 +153,17 @@ static void sifive_spi_prep_transfer(struct sifive_spi *spi, /* Number of wires ? */ cr &= ~SIFIVE_SPI_FMT_PROTO_MASK; - if ((slave_plat->mode & SPI_TX_QUAD) || (slave_plat->mode & SPI_RX_QUAD)) + switch (spi->fmt_proto) { + case SIFIVE_SPI_PROTO_QUAD: cr |= SIFIVE_SPI_FMT_PROTO_QUAD; - else if ((slave_plat->mode & SPI_TX_DUAL) || (slave_plat->mode & SPI_RX_DUAL)) + break; + case SIFIVE_SPI_PROTO_DUAL: cr |= SIFIVE_SPI_FMT_PROTO_DUAL; - else + break; + default: cr |= SIFIVE_SPI_FMT_PROTO_SINGLE; + break; + } /* SPI direction in/out ? */ cr &= ~SIFIVE_SPI_FMT_DIR; @@ -246,6 +257,7 @@ static int sifive_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) { struct udevice *dev = slave->dev; + struct sifive_spi *spi = dev_get_priv(dev->parent); unsigned long flags = SPI_XFER_BEGIN; u8 opcode = op->cmd.opcode; unsigned int pos = 0; @@ -257,6 +269,8 @@ static int sifive_spi_exec_op(struct spi_slave *slave, if (!op->addr.nbytes && !op->dummy.nbytes && !op->data.nbytes) flags |= SPI_XFER_END; + spi->fmt_proto = op->cmd.buswidth; + /* send the opcode */ ret = sifive_spi_xfer(dev, 8, (void *)&opcode, NULL, flags); if (ret < 0) { @@ -284,6 +298,8 @@ static int sifive_spi_exec_op(struct spi_slave *slave, if (!op->data.nbytes) flags |= SPI_XFER_END; + spi->fmt_proto = op->addr.buswidth; + ret = sifive_spi_xfer(dev, op_len * 8, op_buf, NULL, flags); if (ret < 0) { dev_err(dev, "failed to xfer addr + dummy\n"); @@ -298,6 +314,8 @@ static int sifive_spi_exec_op(struct spi_slave *slave, else tx_buf = op->data.buf.out; + spi->fmt_proto = op->data.buswidth; + ret = sifive_spi_xfer(dev, op->data.nbytes * 8, tx_buf, rx_buf, SPI_XFER_END); if (ret) {