Skip to contentSkip to conversation

kw_spi: fix clock prescaler computation

PATCH New Valentin Longchamp 2 participants 7 messages Jun 29, 2012 – Sep 3, 2012

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

PATCH 1/1 kw_spi: fix clock prescaler computation

The computation was not correct with low clock values: setting a 1MHz clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 629 (Serial Memory Interface Configuration Register).

cc Holger Brunck <[email protected]>
cc Prafulla Wadaskar <[email protected]>
---
 arch/arm/include/asm/arch-kirkwood/spi.h |    1 +
 drivers/spi/kirkwood_spi.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-kirkwood/spi.h +1 -0
index 1d5043f..5a38dc5 100644
@@ -38,6 +38,7 @@ struct kwspi_registers {
 };
 
 #define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
 #define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
drivers/spi/kirkwood_spi.c +3 -2
index ee14669..9b3f6a4 100644
@@ -57,8 +57,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
 
 	/* calculate spi clock prescaller using max_hz */
-	data = ((CONFIG_SYS_TCLK / 2) / max_hz) & KWSPI_CLKPRESCL_MASK;
-	data |= 0x10;
+	data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
+	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
+	data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data;
 
 	/* program spi clock prescaller using max_hz */
 	writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 kw_spi: fix clock prescaler computation

Hi Prafulla,

I haven't received feedback about this patch from you. Can I please kindly remind you about it since I am about to send patches that deal with SPI clk setting.

Thank you.

Quoted 45 lines · Valentin Longchamp

The computation was not correct with low clock values: setting a 1MHz clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 629 (Serial Memory Interface Configuration Register).

cc Holger Brunck <[email protected]>
cc Prafulla Wadaskar <[email protected]>
---
 arch/arm/include/asm/arch-kirkwood/spi.h |    1 +
 drivers/spi/kirkwood_spi.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-kirkwood/spi.h +1 -0
index 1d5043f..5a38dc5 100644
@@ -38,6 +38,7 @@ struct kwspi_registers {
 };
 
 #define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
 #define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
drivers/spi/kirkwood_spi.c +3 -2
index ee14669..9b3f6a4 100644
@@ -57,8 +57,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
 
 	/* calculate spi clock prescaller using max_hz */
-	data = ((CONFIG_SYS_TCLK / 2) / max_hz) & KWSPI_CLKPRESCL_MASK;
-	data |= 0x10;
+	data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
+	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
+	data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data;
 
 	/* program spi clock prescaller using max_hz */
 	writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
#2 lore raw

PATCH 1/1 kw_spi: fix clock prescaler computation

Quoted 9 lines

-----Original Message-----
From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
Sent: 14 August 2012 15:02
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Holger Brunck
Subject: Re: [PATCH] kw_spi: fix clock prescaler computation

Quoted 6 lines

Hi Prafulla,

I haven't received feedback about this patch from you. Can I please kindly
remind you about it since I am about to send patches that deal with SPI clk setting.

Dear Valentin
My bad :-( I am really sorry about this.
I missed this patch.
Please find my comments in lined.

Quoted 12 lines

Thank you.

Quoted 1 line · Valentin Longchamp

The computation was not correct with low clock values: setting a

1MHz

Quoted 6 lines

clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 629 (Serial Memory Interface Configuration Register).

I think this is table 600 (ref: MV-S104860-00 Rev. E specs available on extranet) This is a cosmetic change.

Otherwise I ack for this patch.

Please kindly let me know, should I pull this patch or you will resend it with above change?

Regards...
Prafulla . . .

#3 lore raw

PATCH 1/1 kw_spi: fix clock prescaler computation

Hi Prafulla,

Quoted 34 lines · Prafulla Wadaskar
Quoted 9 lines

-----Original Message-----
From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
Sent: 14 August 2012 15:02
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Holger Brunck
Subject: Re: [PATCH] kw_spi: fix clock prescaler computation

Quoted 6 lines

Hi Prafulla,

I haven't received feedback about this patch from you. Can I please kindly
remind you about it since I am about to send patches that deal with SPI clk setting.

Dear Valentin
My bad :-( I am really sorry about this.
I missed this patch.
Please find my comments in lined.

Quoted 12 lines

Thank you.

Quoted 1 line · Valentin Longchamp

The computation was not correct with low clock values: setting a

1MHz

Quoted 6 lines

clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 629 (Serial Memory Interface Configuration Register).

Quoted 6 lines

I think this is table 600 (ref: MV-S104860-00 Rev. E specs available on extranet) This is a cosmetic change.

Otherwise I ack for this patch.

Please kindly let me know, should I pull this patch or you will resend it with above change?

Ok, I had taken rev. C of the document as a reference, I will resend the patch with the updated commit message.

Valentin

#4 lore raw

PATCH v2 1/1 kw_spi: fix clock prescaler computation

The computation was not correct with low clock values: setting a 1MHz clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 600 (Serial Memory Interface Configuration Register).

cc Holger Brunck <[email protected]>
cc Prafulla Wadaskar <[email protected]>

---
changes for v2:
- table nb in commit message

 arch/arm/include/asm/arch-kirkwood/spi.h |    1 +
 drivers/spi/kirkwood_spi.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-kirkwood/spi.h +1 -0
index 1d5043f..5a38dc5 100644
@@ -38,6 +38,7 @@ struct kwspi_registers {
 };
 
 #define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
 #define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
drivers/spi/kirkwood_spi.c +3 -2
index ee14669..9b3f6a4 100644
@@ -57,8 +57,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
 
 	/* calculate spi clock prescaller using max_hz */
-	data = ((CONFIG_SYS_TCLK / 2) / max_hz) & KWSPI_CLKPRESCL_MASK;
-	data |= 0x10;
+	data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
+	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
+	data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data;
 
 	/* program spi clock prescaller using max_hz */
 	writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
Signature · 1 line
1.7.1
#5 lore raw

PATCH v2 1/1 kw_spi: fix clock prescaler computation

Quoted 59 lines

-----Original Message-----
From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
Sent: 15 August 2012 21:02
To: u-boot at lists.denx.de
Cc: Valentin Longchamp; Holger Brunck; Prafulla Wadaskar
Subject: [PATCH v2] kw_spi: fix clock prescaler computation

The computation was not correct with low clock values: setting a 1MHz clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 600 (Serial Memory Interface Configuration Register).

cc Holger Brunck <[email protected]>
cc Prafulla Wadaskar <[email protected]>

---
changes for v2:
- table nb in commit message

 arch/arm/include/asm/arch-kirkwood/spi.h |    1 +
 drivers/spi/kirkwood_spi.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-kirkwood/spi.h +1 -0
index 1d5043f..5a38dc5 100644
@@ -38,6 +38,7 @@ struct kwspi_registers {
 };
 
 #define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface
 */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */

#define KWSPI_IRQUNMASK 1 /* unmask SPI interrupt */

drivers/spi/kirkwood_spi.c +3 -2
index ee14669..9b3f6a4 100644
@@ -57,8 +57,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
 unsigned int cs,
 	writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
 
 	/* calculate spi clock prescaller using max_hz */
-	data = ((CONFIG_SYS_TCLK / 2) / max_hz) & KWSPI_CLKPRESCL_MASK;
-	data |= 0x10;
+	data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
+	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
+	data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data;
 
 	/* program spi clock prescaller using max_hz */
Quoted 2 lines

writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
--

Will pull this soon.

Regards...
Prafulla . . .

#6 lore raw

PATCH v2 1/1 kw_spi: fix clock prescaler computation

In reply to Valentin Longchamp
Quoted 69 lines

-----Original Message-----
From: Prafulla Wadaskar
Sent: 16 August 2012 09:44
To: 'Valentin Longchamp'; u-boot at lists.denx.de
Cc: Holger Brunck
Subject: RE: [PATCH v2] kw_spi: fix clock prescaler computation

Quoted 8 lines

-----Original Message-----
From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
Sent: 15 August 2012 21:02
To: u-boot at lists.denx.de
Cc: Valentin Longchamp; Holger Brunck; Prafulla Wadaskar
Subject: [PATCH v2] kw_spi: fix clock prescaler computation

The computation was not correct with low clock values: setting a

1MHz

drivers/spi/kirkwood_spi.c struct spi_slave *spi_setup_slave(unsigned int

Quoted 38 lines

clock would result in an overlap that would then configure a 25Mhz clock.

This patch implements a correct computation method according to the kirkwood functionnal spec. table 600 (Serial Memory Interface Configuration Register).

cc Holger Brunck <[email protected]>
cc Prafulla Wadaskar <[email protected]>

---
changes for v2:
- table nb in commit message

 arch/arm/include/asm/arch-kirkwood/spi.h |    1 +
 drivers/spi/kirkwood_spi.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-kirkwood/spi.h +1 -0
index 1d5043f..5a38dc5 100644
@@ -38,6 +38,7 @@ struct kwspi_registers {
 };
 
 #define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface
 */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */

#define KWSPI_IRQUNMASK 1 /* unmask SPI interrupt */

drivers/spi/kirkwood_spi.c +0 -0
index ee14669..9b3f6a4 100644
@@ -57,8 +57,9 @@ struct spi_slave *spi_setup_slave(unsigned int

bus,

Quoted 10 lines
drivers/spi/kirkwood_spi.c +3 -2
 unsigned int cs,
 	writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
 
 	/* calculate spi clock prescaller using max_hz */
-	data = ((CONFIG_SYS_TCLK / 2) / max_hz) & KWSPI_CLKPRESCL_MASK;
-	data |= 0x10;
+	data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
+	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
+	data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data;
 
Quoted 6 lines
Quoted 3 lines
drivers/spi/kirkwood_spi.c +0 -0
 	/* program spi clock prescaller using max_hz */

writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
--

Will pull this soon.

Applied to u-boot-marvell.git to master branch by resolving merge conflict

Regards...
Prafulla . . .