[PATCH 14/18] spi: qup: allow block mode to generate multiple transactions

2017-06-13 Thread Varadarajan Narayanan
This let's you write more to the SPI bus than 64K-1 which is important
if the block size of a SPI device is >= 64K or some other device wants
to do something larger.

This has the benefit of completely removing spi_message from the spi-qup
transactions

Signed-off-by: Matthew McClintock 
Signed-off-by: Varadarajan Narayanan 
---
 drivers/spi/spi-qup.c | 127 +++---
 1 file changed, 80 insertions(+), 47 deletions(-)

diff --git a/drivers/spi/spi-qup.c b/drivers/spi/spi-qup.c
index f085e36..02d4e10 100644
--- a/drivers/spi/spi-qup.c
+++ b/drivers/spi/spi-qup.c
@@ -120,7 +120,7 @@
 
 #define SPI_NUM_CHIPSELECTS4
 
-#define SPI_MAX_DMA_XFER   (SZ_64K - 64)
+#define SPI_MAX_XFER   (SZ_64K - 64)
 
 /* high speed mode is when bus rate is greater then 26MHz */
 #define SPI_HS_MIN_RATE2600
@@ -151,6 +151,8 @@ struct spi_qup {
int n_words;
int tx_bytes;
int rx_bytes;
+   const u8*tx_buf;
+   u8  *rx_buf;
int qup_v1;
 
int mode;
@@ -175,6 +177,12 @@ static inline bool spi_qup_is_dma_xfer(int mode)
return false;
 }
 
+/* get's the transaction size length */
+static inline unsigned int spi_qup_len(struct spi_qup *controller)
+{
+   return controller->n_words * controller->w_size;
+}
+
 static inline bool spi_qup_is_valid_state(struct spi_qup *controller)
 {
u32 opstate = readl_relaxed(controller->base + QUP_STATE);
@@ -227,10 +235,9 @@ static int spi_qup_set_state(struct spi_qup *controller, 
u32 state)
return 0;
 }
 
-static void spi_qup_read_from_fifo(struct spi_qup *controller,
-   struct spi_transfer *xfer, u32 num_words)
+static void spi_qup_read_from_fifo(struct spi_qup *controller, u32 num_words)
 {
-   u8 *rx_buf = xfer->rx_buf;
+   u8 *rx_buf = controller->rx_buf;
int i, shift, num_bytes;
u32 word;
 
@@ -238,8 +245,9 @@ static void spi_qup_read_from_fifo(struct spi_qup 
*controller,
 
word = readl_relaxed(controller->base + QUP_INPUT_FIFO);
 
-   num_bytes = min_t(int, xfer->len - controller->rx_bytes,
-   controller->w_size);
+   num_bytes = min_t(int, spi_qup_len(controller) -
+  controller->rx_bytes,
+  controller->w_size);
 
if (!rx_buf) {
controller->rx_bytes += num_bytes;
@@ -260,13 +268,12 @@ static void spi_qup_read_from_fifo(struct spi_qup 
*controller,
}
 }
 
-static void spi_qup_read(struct spi_qup *controller,
-   struct spi_transfer *xfer)
+static void spi_qup_read(struct spi_qup *controller)
 {
u32 remainder, words_per_block, num_words;
bool is_block_mode = controller->mode == QUP_IO_M_MODE_BLOCK;
 
-   remainder = DIV_ROUND_UP(xfer->len - controller->rx_bytes,
+   remainder = DIV_ROUND_UP(spi_qup_len(controller) - controller->rx_bytes,
 controller->w_size);
words_per_block = controller->in_blk_sz >> 2;
 
@@ -287,7 +294,7 @@ static void spi_qup_read(struct spi_qup *controller,
}
 
/* read up to the maximum transfer size available */
-   spi_qup_read_from_fifo(controller, xfer, num_words);
+   spi_qup_read_from_fifo(controller, num_words);
 
remainder -= num_words;
 
@@ -309,18 +316,18 @@ static void spi_qup_read(struct spi_qup *controller,
 
 }
 
-static void spi_qup_write_to_fifo(struct spi_qup *controller,
-   struct spi_transfer *xfer, u32 num_words)
+static void spi_qup_write_to_fifo(struct spi_qup *controller, u32 num_words)
 {
-   const u8 *tx_buf = xfer->tx_buf;
+   const u8 *tx_buf = controller->tx_buf;
int i, num_bytes;
u32 word, data;
 
for (; num_words; num_words--) {
word = 0;
 
-   num_bytes = min_t(int, xfer->len - controller->tx_bytes,
-   controller->w_size);
+   num_bytes = min_t(int, spi_qup_len(controller) -
+  controller->tx_bytes,
+  controller->w_size);
if (tx_buf)
for (i = 0; i < num_bytes; i++) {
data = tx_buf[controller->tx_bytes + i];
@@ -338,13 +345,12 @@ static void spi_qup_dma_done(void *data)
complete(data);
 }
 
-static void spi_qup_write(struct spi_qup *controller,
-   struct spi_transfer *xfer)
+static void spi_qup_write(struct spi_qup *controller)
 {
bool is_block_mode = controller->mode == QUP_IO_M_MODE_BLOCK;
u32 remainder, 

[PATCH 14/18] spi: qup: allow block mode to generate multiple transactions

2017-06-13 Thread Varadarajan Narayanan
This let's you write more to the SPI bus than 64K-1 which is important
if the block size of a SPI device is >= 64K or some other device wants
to do something larger.

This has the benefit of completely removing spi_message from the spi-qup
transactions

Signed-off-by: Matthew McClintock 
Signed-off-by: Varadarajan Narayanan 
---
 drivers/spi/spi-qup.c | 127 +++---
 1 file changed, 80 insertions(+), 47 deletions(-)

diff --git a/drivers/spi/spi-qup.c b/drivers/spi/spi-qup.c
index f085e36..02d4e10 100644
--- a/drivers/spi/spi-qup.c
+++ b/drivers/spi/spi-qup.c
@@ -120,7 +120,7 @@
 
 #define SPI_NUM_CHIPSELECTS4
 
-#define SPI_MAX_DMA_XFER   (SZ_64K - 64)
+#define SPI_MAX_XFER   (SZ_64K - 64)
 
 /* high speed mode is when bus rate is greater then 26MHz */
 #define SPI_HS_MIN_RATE2600
@@ -151,6 +151,8 @@ struct spi_qup {
int n_words;
int tx_bytes;
int rx_bytes;
+   const u8*tx_buf;
+   u8  *rx_buf;
int qup_v1;
 
int mode;
@@ -175,6 +177,12 @@ static inline bool spi_qup_is_dma_xfer(int mode)
return false;
 }
 
+/* get's the transaction size length */
+static inline unsigned int spi_qup_len(struct spi_qup *controller)
+{
+   return controller->n_words * controller->w_size;
+}
+
 static inline bool spi_qup_is_valid_state(struct spi_qup *controller)
 {
u32 opstate = readl_relaxed(controller->base + QUP_STATE);
@@ -227,10 +235,9 @@ static int spi_qup_set_state(struct spi_qup *controller, 
u32 state)
return 0;
 }
 
-static void spi_qup_read_from_fifo(struct spi_qup *controller,
-   struct spi_transfer *xfer, u32 num_words)
+static void spi_qup_read_from_fifo(struct spi_qup *controller, u32 num_words)
 {
-   u8 *rx_buf = xfer->rx_buf;
+   u8 *rx_buf = controller->rx_buf;
int i, shift, num_bytes;
u32 word;
 
@@ -238,8 +245,9 @@ static void spi_qup_read_from_fifo(struct spi_qup 
*controller,
 
word = readl_relaxed(controller->base + QUP_INPUT_FIFO);
 
-   num_bytes = min_t(int, xfer->len - controller->rx_bytes,
-   controller->w_size);
+   num_bytes = min_t(int, spi_qup_len(controller) -
+  controller->rx_bytes,
+  controller->w_size);
 
if (!rx_buf) {
controller->rx_bytes += num_bytes;
@@ -260,13 +268,12 @@ static void spi_qup_read_from_fifo(struct spi_qup 
*controller,
}
 }
 
-static void spi_qup_read(struct spi_qup *controller,
-   struct spi_transfer *xfer)
+static void spi_qup_read(struct spi_qup *controller)
 {
u32 remainder, words_per_block, num_words;
bool is_block_mode = controller->mode == QUP_IO_M_MODE_BLOCK;
 
-   remainder = DIV_ROUND_UP(xfer->len - controller->rx_bytes,
+   remainder = DIV_ROUND_UP(spi_qup_len(controller) - controller->rx_bytes,
 controller->w_size);
words_per_block = controller->in_blk_sz >> 2;
 
@@ -287,7 +294,7 @@ static void spi_qup_read(struct spi_qup *controller,
}
 
/* read up to the maximum transfer size available */
-   spi_qup_read_from_fifo(controller, xfer, num_words);
+   spi_qup_read_from_fifo(controller, num_words);
 
remainder -= num_words;
 
@@ -309,18 +316,18 @@ static void spi_qup_read(struct spi_qup *controller,
 
 }
 
-static void spi_qup_write_to_fifo(struct spi_qup *controller,
-   struct spi_transfer *xfer, u32 num_words)
+static void spi_qup_write_to_fifo(struct spi_qup *controller, u32 num_words)
 {
-   const u8 *tx_buf = xfer->tx_buf;
+   const u8 *tx_buf = controller->tx_buf;
int i, num_bytes;
u32 word, data;
 
for (; num_words; num_words--) {
word = 0;
 
-   num_bytes = min_t(int, xfer->len - controller->tx_bytes,
-   controller->w_size);
+   num_bytes = min_t(int, spi_qup_len(controller) -
+  controller->tx_bytes,
+  controller->w_size);
if (tx_buf)
for (i = 0; i < num_bytes; i++) {
data = tx_buf[controller->tx_bytes + i];
@@ -338,13 +345,12 @@ static void spi_qup_dma_done(void *data)
complete(data);
 }
 
-static void spi_qup_write(struct spi_qup *controller,
-   struct spi_transfer *xfer)
+static void spi_qup_write(struct spi_qup *controller)
 {
bool is_block_mode = controller->mode == QUP_IO_M_MODE_BLOCK;
u32 remainder, words_per_block, num_words;
 
-   remainder =