Skip to contentSkip to conversation

spi: s3c64xx: Enable Word transfer

RFC/PATCH Rajeshwari S Shinde 5 participants 6 messages Sep 24, 2013 – Sep 30, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

This patch enables word transfer for s3c64xx spi driver. User can set bits_per_word to 32 before calling spi_setup, which would enable the word transfer mode.

---
 drivers/spi/spi-s3c64xx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/spi/spi-s3c64xx.c +18 -10
index 512b889..893361b 100644
@@ -498,6 +498,17 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 	chcfg = readl(regs + S3C64XX_SPI_CH_CFG);
 	chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
 
+	if(sdd->cur_bpw == 32) {
+		/* For word transfer we need to swap bytes */
+		u32 swapcfg = (S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE |
+				S3C64XX_SPI_SWAP_TX_HALF_WORD |
+				S3C64XX_SPI_SWAP_RX_EN |
+				S3C64XX_SPI_SWAP_RX_BYTE |
+				S3C64XX_SPI_SWAP_RX_HALF_WORD);
+		writel(swapcfg, regs + S3C64XX_SPI_SWAP_CFG);
+	} else
+		writel(0, regs + S3C64XX_SPI_SWAP_CFG);
+
 	if (dma_mode) {
 		chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
 	} else {
@@ -905,19 +916,16 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
 		bpw = xfer->bits_per_word;
 		speed = xfer->speed_hz ? : spi->max_speed_hz;
 
-		if (xfer->len % (bpw / 8)) {
-			dev_err(&spi->dev,
-				"Xfer length(%u) not a multiple of word size(%u)\n",
-				xfer->len, bpw / 8);
-			status = -EIO;
-			goto out;
+		if (speed != sdd->cur_speed) {
+			sdd->cur_speed = speed;
 		}
 
-		if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
+		if (xfer->len % (bpw / 8))
+			sdd->cur_bpw = 8;
+		else
 			sdd->cur_bpw = bpw;
-			sdd->cur_speed = speed;
-			s3c64xx_spi_config(sdd);
-		}
+
+		s3c64xx_spi_config(sdd);
 
 		/* Polling method for xfers not bigger than FIFO capacity */
 		use_dma = 0;
Signature · 1 line
1.7.12.4
#1 lore raw

+cc: Mark

Quoted 5 lines · Rajeshwari S Shinde

This patch enables word transfer for s3c64xx spi driver. User can set bits_per_word to 32 before calling spi_setup, which would enable the word transfer mode.

+ if(sdd->cur_bpw == 32) {

Space needed after if, else checkpatch will complain.

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 510

Quoted 9 lines
drivers/spi/spi-s3c64xx.c +9 -0
+               /* For word transfer we need to swap bytes */
+               u32 swapcfg = (S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE |
+                               S3C64XX_SPI_SWAP_TX_HALF_WORD |
+                               S3C64XX_SPI_SWAP_RX_EN |
+                               S3C64XX_SPI_SWAP_RX_BYTE |
+                               S3C64XX_SPI_SWAP_RX_HALF_WORD);
+               writel(swapcfg, regs + S3C64XX_SPI_SWAP_CFG);
+       } else
+               writel(0, regs + S3C64XX_SPI_SWAP_CFG);

Braces necessary around else as the if block has it.

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 921

Quoted 3 lines
drivers/spi/spi-s3c64xx.c +2 -0
+               if (speed != sdd->cur_speed) {
+                       sdd->cur_speed = speed;
                }

Braces are not necessary here.

Signature · 2 lines
With warm regards,
Sachin
#2 lore raw
In reply to Rajeshwari S Shinde

Hi Rajeshwari,

[Ccing Mark Brown]

Quoted 15 lines · On Tuesday 24 of September 2013 19:30:35 Rajeshwari S Shinde wrote:

This patch enables word transfer for s3c64xx spi driver. User can set bits_per_word to 32 before calling spi_setup, which would enable the word transfer mode.

---
 drivers/spi/spi-s3c64xx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/spi/spi-s3c64xx.c +0 -0
index 512b889..893361b 100644
@@ -498,6 +498,17 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 	chcfg = readl(regs + S3C64XX_SPI_CH_CFG);

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 508

Quoted 10 lines
drivers/spi/spi-s3c64xx.c +8 -0
 	chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
 
+	if(sdd->cur_bpw == 32) {
+		/* For word transfer we need to swap bytes */
+		u32 swapcfg = (S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE |
+				S3C64XX_SPI_SWAP_TX_HALF_WORD |
+				S3C64XX_SPI_SWAP_RX_EN |
+				S3C64XX_SPI_SWAP_RX_BYTE |
+				S3C64XX_SPI_SWAP_RX_HALF_WORD);
+		writel(swapcfg, regs + S3C64XX_SPI_SWAP_CFG);

Wasn't this driver already supposed to support 16 and 32 bits per word transfers? I fail to see any mention in the documentation about the need to enable these swaps in these cases.

In this case, wouldn't 16 bits per word transfers also need swapping?

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 510

Quoted 2 lines
drivers/spi/spi-s3c64xx.c +2 -0
+	} else
+		writel(0, regs + S3C64XX_SPI_SWAP_CFG);

nit: Coding style. If you use braces for one branch, then you should use them for the other one as well.

Quoted 5 lines
drivers/spi/spi-s3c64xx.c +1 -0
+
 	if (dma_mode) {
 		chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
 	} else {

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 913

Quoted 9 lines
drivers/spi/spi-s3c64xx.c +0 -6
@@ -905,19 +916,16 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
 		bpw = xfer->bits_per_word;
 		speed = xfer->speed_hz ? : spi->max_speed_hz;
 
-		if (xfer->len % (bpw / 8)) {
-			dev_err(&spi->dev,
-				"Xfer length(%u) not a multiple of word size(%u)\n",
-				xfer->len, bpw / 8);
-			status = -EIO;
-			goto out;

Why is this check removed in this patch?

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 920

Quoted 2 lines
drivers/spi/spi-s3c64xx.c +2 -0
+		if (speed != sdd->cur_speed) {
+			sdd->cur_speed = speed;

This change does not seem to be related to $subject.

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 928

Quoted 12 lines
drivers/spi/spi-s3c64xx.c +5 -4
 		}
 
-		if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
+		if (xfer->len % (bpw / 8))
+			sdd->cur_bpw = 8;
+		else
 			sdd->cur_bpw = bpw;
-			sdd->cur_speed = speed;
-			s3c64xx_spi_config(sdd);
-		}
+
+		s3c64xx_spi_config(sdd);

Why s3c64xx_spi_config() can't be called only if one of the parameters changed, as it was before this patch?

Best regards,
Tomasz

P.S. Please remember to always add respective maintainers on Cc. You can use scripts/get_maintainer.pl script to quickly get a list of people potentially interested in a patch.

A message that is not in the archive (sent off-list or not yet received): CAPs=JDe6XoyqM=iJWgAZF+tU0p_4K=9K4Kx6ANpCcUV9rBd82Q@mail.gmail.com

#4 lore raw

Hi Tomasz

Sorry for the previous mail with incomplete comments, sent the same by mistake.

Quoted 40 lines · Rajeshwari Birje

Hi Tomasz

Quoted 35 lines · Tomasz Figa

Hi Rajeshwari,

[Ccing Mark Brown]

Quoted 15 lines · On Tuesday 24 of September 2013 19:30:35 Rajeshwari S Shinde wrote:

This patch enables word transfer for s3c64xx spi driver. User can set bits_per_word to 32 before calling spi_setup, which would enable the word transfer mode.

---
 drivers/spi/spi-s3c64xx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/spi/spi-s3c64xx.c +0 -0
index 512b889..893361b 100644
@@ -498,6 +498,17 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
      chcfg = readl(regs + S3C64XX_SPI_CH_CFG);

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 508

Quoted 10 lines
drivers/spi/spi-s3c64xx.c +8 -0
      chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
 
+     if(sdd->cur_bpw == 32) {
+             /* For word transfer we need to swap bytes */
+             u32 swapcfg = (S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE |
+                             S3C64XX_SPI_SWAP_TX_HALF_WORD |
+                             S3C64XX_SPI_SWAP_RX_EN |
+                             S3C64XX_SPI_SWAP_RX_BYTE |
+                             S3C64XX_SPI_SWAP_RX_HALF_WORD);
+             writel(swapcfg, regs + S3C64XX_SPI_SWAP_CFG);

Wasn't this driver already supposed to support 16 and 32 bits per word transfers? I fail to see any mention in the documentation about the need to enable these swaps in these cases.

I get errors when I try 32 bits per word transfers.
There is no clear documentation for this swap config register but without this word transfer is not working fine.

Quoted 4 lines
Quoted 4 lines

In this case, wouldn't 16 bits per word transfers also need swapping?

Yes it would need, have not tested for half word transfer.

Quoted 8 lines
Quoted 7 lines

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 510

Quoted 4 lines
drivers/spi/spi-s3c64xx.c +2 -0
+     } else
+             writel(0, regs + S3C64XX_SPI_SWAP_CFG);

nit: Coding style. If you use braces for one branch, then you should use them for the other one as well.

will correct this.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-s3c64xx.c +1 -0
+
      if (dma_mode) {
              chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
      } else {
@@ -905,19 +916,16 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
              bpw = xfer->bits_per_word;
              speed = xfer->speed_hz ? : spi->max_speed_hz;
 
Quoted 8 lines
Quoted 8 lines

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 913

Quoted 6 lines
drivers/spi/spi-s3c64xx.c +0 -6
-             if (xfer->len % (bpw / 8)) {
-                     dev_err(&spi->dev,
-                             "Xfer length(%u) not a multiple of word size(%u)\n",
-                             xfer->len, bpw / 8);
-                     status = -EIO;
-                     goto out;

Why is this check removed in this patch?

I get "Xfer length(%u) not a multiple of word size(%u)\n" error for word transfer
ex: when if bpw is 32 and len 74 the above condition fails

Quoted 7 lines
Quoted 7 lines

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 920

Quoted 5 lines
drivers/spi/spi-s3c64xx.c +2 -0
+             if (speed != sdd->cur_speed) {
+                     sdd->cur_speed = speed;

This change does not seem to be related to $subject.

have split the if condition to accommodate the above error condition.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/spi/spi-s3c64xx.c +5 -4
              }
 
-             if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
+             if (xfer->len % (bpw / 8))
+                     sdd->cur_bpw = 8;
+             else
                      sdd->cur_bpw = bpw;
-                     sdd->cur_speed = speed;
-                     s3c64xx_spi_config(sdd);
-             }
+
+             s3c64xx_spi_config(sdd);
Quoted 2 lines
Quoted 2 lines

Why s3c64xx_spi_config() can't be called only if one of the parameters changed, as it was before this patch?

Will correct this.

Quoted 13 lines
Quoted 13 lines

Best regards,
Tomasz

P.S. Please remember to always add respective maintainers on Cc. You can use scripts/get_maintainer.pl script to quickly get a list of people potentially interested in a patch.

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Regards,
Rajeshwari Shinde
#5 lore raw

Hi Mark Brown,

Please do let me know if you have any comments on this patch.

Regards,
Rajeshwari Shinde.

Quoted 133 lines · Rajeshwari Birje

Hi Tomasz

Sorry for the previous mail with incomplete comments, sent the same by mistake.

Quoted 40 lines · Rajeshwari Birje

Hi Tomasz

Quoted 35 lines · Tomasz Figa

Hi Rajeshwari,

[Ccing Mark Brown]

Quoted 15 lines · On Tuesday 24 of September 2013 19:30:35 Rajeshwari S Shinde wrote:

This patch enables word transfer for s3c64xx spi driver. User can set bits_per_word to 32 before calling spi_setup, which would enable the word transfer mode.

---
 drivers/spi/spi-s3c64xx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/spi/spi-s3c64xx.c +0 -0
index 512b889..893361b 100644
@@ -498,6 +498,17 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
      chcfg = readl(regs + S3C64XX_SPI_CH_CFG);

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 508

Quoted 10 lines
drivers/spi/spi-s3c64xx.c +8 -0
      chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
 
+     if(sdd->cur_bpw == 32) {
+             /* For word transfer we need to swap bytes */
+             u32 swapcfg = (S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE |
+                             S3C64XX_SPI_SWAP_TX_HALF_WORD |
+                             S3C64XX_SPI_SWAP_RX_EN |
+                             S3C64XX_SPI_SWAP_RX_BYTE |
+                             S3C64XX_SPI_SWAP_RX_HALF_WORD);
+             writel(swapcfg, regs + S3C64XX_SPI_SWAP_CFG);

Wasn't this driver already supposed to support 16 and 32 bits per word transfers? I fail to see any mention in the documentation about the need to enable these swaps in these cases.

I get errors when I try 32 bits per word transfers.
There is no clear documentation for this swap config register but without this word transfer is not working fine.

Quoted 4 lines
Quoted 4 lines

In this case, wouldn't 16 bits per word transfers also need swapping?

Yes it would need, have not tested for half word transfer.

Quoted 8 lines
Quoted 7 lines

drivers/spi/spi-s3c64xx.c static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, · line 510

Quoted 4 lines
drivers/spi/spi-s3c64xx.c +2 -0
+     } else
+             writel(0, regs + S3C64XX_SPI_SWAP_CFG);

nit: Coding style. If you use braces for one branch, then you should use them for the other one as well.

will correct this.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-s3c64xx.c +1 -0
+
      if (dma_mode) {
              chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
      } else {
@@ -905,19 +916,16 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
              bpw = xfer->bits_per_word;
              speed = xfer->speed_hz ? : spi->max_speed_hz;
 
Quoted 8 lines
Quoted 8 lines

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 913

Quoted 6 lines
drivers/spi/spi-s3c64xx.c +0 -6
-             if (xfer->len % (bpw / 8)) {
-                     dev_err(&spi->dev,
-                             "Xfer length(%u) not a multiple of word size(%u)\n",
-                             xfer->len, bpw / 8);
-                     status = -EIO;
-                     goto out;

Why is this check removed in this patch?

I get "Xfer length(%u) not a multiple of word size(%u)\n" error for word transfer
ex: when if bpw is 32 and len 74 the above condition fails

Quoted 7 lines
Quoted 7 lines

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_transfer_one_message(struct spi_master *master, · line 920

Quoted 5 lines
drivers/spi/spi-s3c64xx.c +2 -0
+             if (speed != sdd->cur_speed) {
+                     sdd->cur_speed = speed;

This change does not seem to be related to $subject.

have split the if condition to accommodate the above error condition.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/spi/spi-s3c64xx.c +5 -4
              }
 
-             if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
+             if (xfer->len % (bpw / 8))
+                     sdd->cur_bpw = 8;
+             else
                      sdd->cur_bpw = bpw;
-                     sdd->cur_speed = speed;
-                     s3c64xx_spi_config(sdd);
-             }
+
+             s3c64xx_spi_config(sdd);
Quoted 2 lines
Quoted 2 lines

Why s3c64xx_spi_config() can't be called only if one of the parameters changed, as it was before this patch?

Will correct this.

Quoted 5 lines
Quoted 5 lines

Best regards,
Tomasz

Quoted 8 lines
Quoted 8 lines

P.S. Please remember to always add respective maintainers on Cc. You can use scripts/get_maintainer.pl script to quickly get a list of people potentially interested in a patch.

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Regards,
Rajeshwari Shinde

Signature · 2 lines
Regards,
Rajeshwari Shinde
maintainer
#6 lore raw
Quoted 1 line · Rajeshwari Birje

Please do let me know if you have any comments on this patch.

Don't top post. You need to follow Tomasz's advice and send the patch to me (using the above address from get_maintainer.pl) after addressing the issues he identified. His advice looked good.