Skip to contentSkip to conversation

Few spi_mpc83xx.c fixes and improvements

PATCH In review Anton Vorontsov 3 participants 9 messages Jul 26, 2007 – Jul 27, 2007 4 messages not in the archive SPI

lore
Share & tools
lore
#0 lore raw

cover Few spi_mpc83xx.c fixes and improvements

Hi all,

These patches based on Linus' tree, as of today.

Signature · 10 lines
Anton Vorontsov
email: cbou-JGs/[email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): 20070726131134.GA3309-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

PATCH 1/4 spi_mpc83xx.c: should turn off SPI unit while switching any mode.

Documentation clearly states, that mode should not be changed till SPMODE_ENABLE bit set. I've seen hangs w/o this patch.

---
 drivers/spi/spi_mpc83xx.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/spi/spi_mpc83xx.c +4 -0
index 3295cfc..0b99fd9 100644
@@ -176,6 +176,8 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
 			regval |= SPMODE_PM(pm);
 		}
 
+		/* Turn off SPI unit prior changing mode */
+		mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0);
 		mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval);
 		if (mpc83xx_spi->activate_cs)
 			mpc83xx_spi->activate_cs(spi->chip_select, pol);
@@ -249,6 +251,8 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 	regval &= 0xff0fffff;
 	regval |= SPMODE_LEN(bits_per_word);
 
+	/* Turn off SPI unit prior changing mode */
+	mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0);
 	mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval);
 
 	return 0;
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): 20070726131346.GA3417-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#4 lore raw

Re: [PATCH 1/4] [POWERPC][SPI] spi_mpc83xx.c: should turn off SPI unit while switching any mode.

Quoted 2 lines · Anton Vorontsov

Documentation clearly states, that mode should not be changed till SPMODE_ENABLE bit set. I've seen hangs w/o this patch.

Out of interest what board/part do you see the hang on?

- k

A message that is not in the archive (sent off-list or not yet received): 250FD11F-9ADC-46CC-B652-1148FC549316-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org

#6 lore raw

Re: [PATCH 1/4] [POWERPC][SPI] spi_mpc83xx.c: should turn off SPI unit while switching any mode.

Quoted 7 lines · Kumar Gala
Quoted 2 lines · Anton Vorontsov

Documentation clearly states, that mode should not be changed till SPMODE_ENABLE bit set. I've seen hangs w/o this patch.

Out of interest what board/part do you see the hang on?

It's MPC8323E-RDB.

Using spidev_test utility:

root-/FxswC0nw/[email protected]:~# ./a.out -D /dev/spidev1.0
spi mode: 0
bits per word: 8
max speed: Hz (kHz): 500000 (500)
...
root-/FxswC0nw/[email protected]:~#

Then trying change bits per word to 32:

root-/FxswC0nw/[email protected]:~# ./a.out -D /dev/spidev1.0 -b 32
spi mode: 0
bits per word: 32
max speed: Hz (kHz): 500000 (500)
<---- hang

Board is still alive, but SPI isn't.

Though, there are various steps to reproduce the same. So SPI unit should be really turned off to change mode.

Thanks,

Signature · 10 lines
Anton Vorontsov
email: cbou-JGs/[email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
#7 lore raw

PATCH 2/4 spi_mpc83xx: get rid of magic numbers

In reply to a message not in the archive
---
 drivers/spi/spi_mpc83xx.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi_mpc83xx.c +3 -2
index 0b99fd9..e2d8dbc 100644
@@ -153,7 +153,8 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
 			len = len - 1;
 
 		/* mask out bits we are going to set */
-		regval &= ~0x38ff0000;
+		regval &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH |
+			    SPMODE_LEN(0xF) | SPMODE_DIV16 | SPMODE_PM(0xF));
 
 		if (spi->mode & SPI_CPHA)
 			regval |= SPMODE_CP_BEGIN_EDGECLK;
@@ -248,7 +249,7 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 	regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
 
 	/* Mask out bits_per_wordgth */
-	regval &= 0xff0fffff;
+	regval &= ~SPMODE_LEN(0xF);
 	regval |= SPMODE_LEN(bits_per_word);
 
 	/* Turn off SPI unit prior changing mode */
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
#8 lore raw

PATCH 3/4 spi_mpc83xx: support for lsb mode switching

In reply to a message not in the archive
---
 drivers/spi/spi_mpc83xx.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
drivers/spi/spi_mpc83xx.c +9 -4
index e2d8dbc..7e17c8b 100644
@@ -154,12 +154,15 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
 
 		/* mask out bits we are going to set */
 		regval &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH |
-			    SPMODE_LEN(0xF) | SPMODE_DIV16 | SPMODE_PM(0xF));
+			    SPMODE_LEN(0xF) | SPMODE_DIV16 | SPMODE_PM(0xF) | \
+			    SPMODE_REV);
 
 		if (spi->mode & SPI_CPHA)
 			regval |= SPMODE_CP_BEGIN_EDGECLK;
 		if (spi->mode & SPI_CPOL)
 			regval |= SPMODE_CI_INACTIVEHIGH;
+		if (!(spi->mode & SPI_LSB_FIRST))
+			regval |= SPMODE_REV;
 
 		regval |= SPMODE_LEN(len);
 
@@ -248,9 +251,11 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 
 	regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
 
-	/* Mask out bits_per_wordgth */
-	regval &= ~SPMODE_LEN(0xF);
+	/* mask out bits we are going to set */
+	regval &= ~(SPMODE_LEN(0xF) | SPMODE_REV);
 	regval |= SPMODE_LEN(bits_per_word);
+	if (!(spi->mode & SPI_LSB_FIRST))
+		regval |= SPMODE_REV;
 
 	/* Turn off SPI unit prior changing mode */
 	mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0);
@@ -260,7 +265,7 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 }
 
 /* the spi->mode bits understood by this driver: */
-#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
+#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST)
 
 static int mpc83xx_spi_setup(struct spi_device *spi)
 {
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
#9 lore raw

PATCH 4/4 spi_mpc83xx: fix LSB mode shifts

In reply to a message not in the archive

spi_mpc83xx should use other shifts when running in QE+LSB mode.

---
 drivers/spi/spi_mpc83xx.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/spi/spi_mpc83xx.c +8 -0
index 7e17c8b..458075a 100644
@@ -237,6 +237,14 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 	} else
 		return -EINVAL;
 
+	if (mpc83xx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) {
+		mpc83xx_spi->tx_shift = 0;
+		if (bits_per_word <= 8)
+			mpc83xx_spi->rx_shift = 8;
+		else
+			mpc83xx_spi->rx_shift = 0;
+	}
+
 	/* nsecs = (clock period)/2 */
 	if (!hz)
 		hz = spi->max_speed_hz;
Signature · 7 lines
1.5.0.6

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
#10 lore raw
In reply to a message not in the archive
Quoted 3 lines · Anton Vorontsov

Hi all,

These patches based on Linus' tree, as of today.

I don't know mpc83xx ... are there any PPC folk who can see any reason not to just merge these patches? They look OK to me, but in this case that doesn't mean much. :)

If I don't hear otherwise, I'll forward all four of these patches upstream on Monday.

(Anton, thanks for these updates!)

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): 200707261958.09127.david-b-yBeKhBN/[email protected]

#12 lore raw
Quoted 5 lines · David Brownell
Quoted 3 lines · Anton Vorontsov

Hi all,

These patches based on Linus' tree, as of today.

Quoted 8 lines

I don't know mpc83xx ... are there any PPC folk who can see any reason not to just merge these patches? They look OK to me, but in this case that doesn't mean much. :)

If I don't hear otherwise, I'll forward all four of these patches upstream on Monday.

(Anton, thanks for these updates!)

These all look good to me for upstream.

- k