From: Jagan Teki <jagan@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 2/5] spi: sifive: Fix format register proto field
Date: Thu, 23 Apr 2020 22:30:54 +0530 [thread overview]
Message-ID: <20200423170057.1976-3-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20200423170057.1976-1-jagan@amarulasolutions.com>
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 <vigneshr@ti.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
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) {
--
2.17.1
next prev parent reply other threads:[~2020-04-23 17:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 17:00 [PATCH v4 0/5] riscv: sifive/fu540: Enable SPI-NOR support Jagan Teki
2020-04-23 17:00 ` [PATCH v4 1/5] spi: sifive: Add spi-mem exec op Jagan Teki
2020-04-23 17:00 ` Jagan Teki [this message]
2020-04-23 17:00 ` [PATCH v4 3/5] spi: sifive: Fix QPP transfer Jagan Teki
2020-04-23 17:00 ` [PATCH v4 4/5] riscv: dts: hifive-unleashed-a00: Add -u-boot.dtsi Jagan Teki
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA46FCB06@ATCPCS16.andestech.com>
2020-04-27 1:55 ` Rick Chen
2020-04-23 17:00 ` [PATCH v4 5/5] sifive: fu540: Enable spi-nor flash support Jagan Teki
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA46FCB21@ATCPCS16.andestech.com>
2020-04-27 2:00 ` Rick Chen
2020-04-24 18:18 ` [PATCH v4 0/5] riscv: sifive/fu540: Enable SPI-NOR support Sagar Kadam
2020-04-25 11:08 ` Jagan Teki
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA46FC853@ATCPCS16.andestech.com>
2020-04-27 0:16 ` Rick Chen
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-all 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=20200423170057.1976-3-jagan@amarulasolutions.com \
--to=jagan@amarulasolutions.com \
--cc=u-boot@lists.denx.de \
/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