* [PATCH 0/4] Zynq qspi updates
@ 2022-01-31 5:22 Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 1/4] spi: zynq_qspi: Typecast rxbuf properly Ashok Reddy Soma
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Ashok Reddy Soma @ 2022-01-31 5:22 UTC (permalink / raw)
To: u-boot; +Cc: jagan, michal.simek, git, somaashokreddy, Ashok Reddy Soma
This patch series does below updates to zynq qspi driver.
1. Fix typecast to rxbuf in zynq_qspi_read_data()
2. Fix data abort issue incase of un-aligned writes
3. Add a check for baudrate and if not in limits set to default
4. Add zynq_qspi_exec_op() to avoid spi_mem_exec_op() from spi-mem
framework.
Siva Durga Prasad Paladugu (3):
spi: zynq_qspi: Typecast rxbuf properly
spi: zynq_qspi: Read only one byte at a time from txbuf
spi: zynq_qspi: Add a check for baudrate and set default if not in
limits
T Karthik Reddy (1):
spi: zynq_qspi: Add SPI memory operations to zynq qspi
drivers/spi/zynq_qspi.c | 91 +++++++++++++++++++++++++++++++++++++----
1 file changed, 83 insertions(+), 8 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] spi: zynq_qspi: Typecast rxbuf properly
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
@ 2022-01-31 5:22 ` Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 2/4] spi: zynq_qspi: Read only one byte at a time from txbuf Ashok Reddy Soma
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ashok Reddy Soma @ 2022-01-31 5:22 UTC (permalink / raw)
To: u-boot
Cc: jagan, michal.simek, git, somaashokreddy,
Siva Durga Prasad Paladugu, Ashok Reddy Soma
From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
This patch typecasts and accesses rx buf properly as
an unaligned rxbuf, typecasting with u16 and accessing
it causes data abort exception and this patch fixes it.
Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
---
drivers/spi/zynq_qspi.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c
index cf6da5340a..34d39d66fb 100644
--- a/drivers/spi/zynq_qspi.c
+++ b/drivers/spi/zynq_qspi.c
@@ -230,12 +230,16 @@ static void zynq_qspi_read_data(struct zynq_qspi_priv *priv, u32 data, u8 size)
priv->rx_buf += 1;
break;
case 2:
- *((u16 *)priv->rx_buf) = data;
- priv->rx_buf += 2;
+ *((u8 *)priv->rx_buf) = data;
+ priv->rx_buf += 1;
+ *((u8 *)priv->rx_buf) = (u8)(data >> 8);
+ priv->rx_buf += 1;
break;
case 3:
- *((u16 *)priv->rx_buf) = data;
- priv->rx_buf += 2;
+ *((u8 *)priv->rx_buf) = data;
+ priv->rx_buf += 1;
+ *((u8 *)priv->rx_buf) = (u8)(data >> 8);
+ priv->rx_buf += 1;
byte3 = (u8)(data >> 16);
*((u8 *)priv->rx_buf) = byte3;
priv->rx_buf += 1;
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] spi: zynq_qspi: Read only one byte at a time from txbuf
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 1/4] spi: zynq_qspi: Typecast rxbuf properly Ashok Reddy Soma
@ 2022-01-31 5:22 ` Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 3/4] spi: zynq_qspi: Add a check for baudrate and set default if not in limits Ashok Reddy Soma
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ashok Reddy Soma @ 2022-01-31 5:22 UTC (permalink / raw)
To: u-boot
Cc: jagan, michal.simek, git, somaashokreddy,
Siva Durga Prasad Paladugu, Ashok Reddy Soma
From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Read only one byte at a time from txbuf as txbuf may not be
aligned and accessing more than a byte at a time may cause
alignment issues. This fixes the issue of data abort exception
while writing to flash device.
Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
---
drivers/spi/zynq_qspi.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c
index 34d39d66fb..aa060d7940 100644
--- a/drivers/spi/zynq_qspi.c
+++ b/drivers/spi/zynq_qspi.c
@@ -276,13 +276,17 @@ static void zynq_qspi_write_data(struct zynq_qspi_priv *priv,
*data |= 0xFFFFFF00;
break;
case 2:
- *data = *((u16 *)priv->tx_buf);
- priv->tx_buf += 2;
+ *data = *((u8 *)priv->tx_buf);
+ priv->tx_buf += 1;
+ *data |= (*((u8 *)priv->tx_buf) << 8);
+ priv->tx_buf += 1;
*data |= 0xFFFF0000;
break;
case 3:
- *data = *((u16 *)priv->tx_buf);
- priv->tx_buf += 2;
+ *data = *((u8 *)priv->tx_buf);
+ priv->tx_buf += 1;
+ *data |= (*((u8 *)priv->tx_buf) << 8);
+ priv->tx_buf += 1;
*data |= (*((u8 *)priv->tx_buf) << 16);
priv->tx_buf += 1;
*data |= 0xFF000000;
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] spi: zynq_qspi: Add a check for baudrate and set default if not in limits
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 1/4] spi: zynq_qspi: Typecast rxbuf properly Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 2/4] spi: zynq_qspi: Read only one byte at a time from txbuf Ashok Reddy Soma
@ 2022-01-31 5:22 ` Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 4/4] spi: zynq_qspi: Add SPI memory operations to zynq qspi Ashok Reddy Soma
2022-02-07 9:22 ` [PATCH 0/4] Zynq qspi updates Michal Simek
4 siblings, 0 replies; 6+ messages in thread
From: Ashok Reddy Soma @ 2022-01-31 5:22 UTC (permalink / raw)
To: u-boot
Cc: jagan, michal.simek, git, somaashokreddy,
Siva Durga Prasad Paladugu, Ashok Reddy Soma
From: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Add a check afer baudrate calculation to see if the resultant value
falls within the range, else set it to default baudrate value.
Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
---
drivers/spi/zynq_qspi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c
index aa060d7940..2963f48bb0 100644
--- a/drivers/spi/zynq_qspi.c
+++ b/drivers/spi/zynq_qspi.c
@@ -49,6 +49,9 @@ DECLARE_GLOBAL_DATA_PTR;
#define ZYNQ_QSPI_CR_BAUD_SHIFT 3 /* Baud rate divisor shift */
#define ZYNQ_QSPI_CR_SS_SHIFT 10 /* Slave select shift */
+#define ZYNQ_QSPI_MAX_BAUD_RATE 0x7
+#define ZYNQ_QSPI_DEFAULT_BAUD_RATE 0x2
+
#define ZYNQ_QSPI_FIFO_DEPTH 63
#define ZYNQ_QSPI_WAIT (CONFIG_SYS_HZ / 100) /* 10 ms */
@@ -621,6 +624,9 @@ static int zynq_qspi_set_speed(struct udevice *bus, uint speed)
(2 << baud_rate_val)) > speed))
baud_rate_val++;
+ if (baud_rate_val > ZYNQ_QSPI_MAX_BAUD_RATE)
+ baud_rate_val = ZYNQ_QSPI_DEFAULT_BAUD_RATE;
+
plat->speed_hz = speed / (2 << baud_rate_val);
}
confr &= ~ZYNQ_QSPI_CR_BAUD_MASK;
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] spi: zynq_qspi: Add SPI memory operations to zynq qspi
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
` (2 preceding siblings ...)
2022-01-31 5:22 ` [PATCH 3/4] spi: zynq_qspi: Add a check for baudrate and set default if not in limits Ashok Reddy Soma
@ 2022-01-31 5:22 ` Ashok Reddy Soma
2022-02-07 9:22 ` [PATCH 0/4] Zynq qspi updates Michal Simek
4 siblings, 0 replies; 6+ messages in thread
From: Ashok Reddy Soma @ 2022-01-31 5:22 UTC (permalink / raw)
To: u-boot
Cc: jagan, michal.simek, git, somaashokreddy, T Karthik Reddy,
Ashok Reddy Soma
From: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Spi memory operation interface is added to zynq qspi
driver to provide an high-level interface to execute
qspi controller specific memory operations by avoiding
spi_mem_exec_op() from spi-mem framework.
Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
---
drivers/spi/zynq_qspi.c | 61 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c
index 2963f48bb0..b69d992b28 100644
--- a/drivers/spi/zynq_qspi.c
+++ b/drivers/spi/zynq_qspi.c
@@ -16,6 +16,7 @@
#include <asm/global_data.h>
#include <asm/io.h>
#include <linux/bitops.h>
+#include <spi-mem.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -663,12 +664,72 @@ static int zynq_qspi_set_mode(struct udevice *bus, uint mode)
return 0;
}
+static int zynq_qspi_exec_op(struct spi_slave *slave,
+ const struct spi_mem_op *op)
+{
+ int op_len, pos = 0, ret, i;
+ unsigned int flag = 0;
+ const u8 *tx_buf = NULL;
+ u8 *rx_buf = NULL;
+
+ if (op->data.nbytes) {
+ if (op->data.dir == SPI_MEM_DATA_IN)
+ rx_buf = op->data.buf.in;
+ else
+ tx_buf = op->data.buf.out;
+ }
+
+ op_len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
+
+ u8 op_buf[op_len];
+
+ op_buf[pos++] = op->cmd.opcode;
+
+ if (op->addr.nbytes) {
+ for (i = 0; i < op->addr.nbytes; i++)
+ op_buf[pos + i] = op->addr.val >>
+ (8 * (op->addr.nbytes - i - 1));
+
+ pos += op->addr.nbytes;
+ }
+
+ if (op->dummy.nbytes)
+ memset(op_buf + pos, 0xff, op->dummy.nbytes);
+
+ /* 1st transfer: opcode + address + dummy cycles */
+ /* Make sure to set END bit if no tx or rx data messages follow */
+ if (!tx_buf && !rx_buf)
+ flag |= SPI_XFER_END;
+
+ ret = zynq_qspi_xfer(slave->dev, op_len * 8, op_buf, NULL,
+ flag | SPI_XFER_BEGIN);
+ if (ret)
+ return ret;
+
+ /* 2nd transfer: rx or tx data path */
+ if (tx_buf || rx_buf) {
+ ret = zynq_qspi_xfer(slave->dev, op->data.nbytes * 8, tx_buf,
+ rx_buf, flag | SPI_XFER_END);
+ if (ret)
+ return ret;
+ }
+
+ spi_release_bus(slave);
+
+ return 0;
+}
+
+static const struct spi_controller_mem_ops zynq_qspi_mem_ops = {
+ .exec_op = zynq_qspi_exec_op,
+};
+
static const struct dm_spi_ops zynq_qspi_ops = {
.claim_bus = zynq_qspi_claim_bus,
.release_bus = zynq_qspi_release_bus,
.xfer = zynq_qspi_xfer,
.set_speed = zynq_qspi_set_speed,
.set_mode = zynq_qspi_set_mode,
+ .mem_ops = &zynq_qspi_mem_ops,
};
static const struct udevice_id zynq_qspi_ids[] = {
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] Zynq qspi updates
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
` (3 preceding siblings ...)
2022-01-31 5:22 ` [PATCH 4/4] spi: zynq_qspi: Add SPI memory operations to zynq qspi Ashok Reddy Soma
@ 2022-02-07 9:22 ` Michal Simek
4 siblings, 0 replies; 6+ messages in thread
From: Michal Simek @ 2022-02-07 9:22 UTC (permalink / raw)
To: Ashok Reddy Soma, u-boot; +Cc: jagan, michal.simek, git, somaashokreddy
On 1/31/22 06:22, Ashok Reddy Soma wrote:
> This patch series does below updates to zynq qspi driver.
> 1. Fix typecast to rxbuf in zynq_qspi_read_data()
> 2. Fix data abort issue incase of un-aligned writes
> 3. Add a check for baudrate and if not in limits set to default
> 4. Add zynq_qspi_exec_op() to avoid spi_mem_exec_op() from spi-mem
> framework.
>
>
> Siva Durga Prasad Paladugu (3):
> spi: zynq_qspi: Typecast rxbuf properly
> spi: zynq_qspi: Read only one byte at a time from txbuf
> spi: zynq_qspi: Add a check for baudrate and set default if not in
> limits
>
> T Karthik Reddy (1):
> spi: zynq_qspi: Add SPI memory operations to zynq qspi
>
> drivers/spi/zynq_qspi.c | 91 +++++++++++++++++++++++++++++++++++++----
> 1 file changed, 83 insertions(+), 8 deletions(-)
>
Applied.
M
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-07 9:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 5:22 [PATCH 0/4] Zynq qspi updates Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 1/4] spi: zynq_qspi: Typecast rxbuf properly Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 2/4] spi: zynq_qspi: Read only one byte at a time from txbuf Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 3/4] spi: zynq_qspi: Add a check for baudrate and set default if not in limits Ashok Reddy Soma
2022-01-31 5:22 ` [PATCH 4/4] spi: zynq_qspi: Add SPI memory operations to zynq qspi Ashok Reddy Soma
2022-02-07 9:22 ` [PATCH 0/4] Zynq qspi updates Michal Simek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).