Skip to contentSkip to conversation

ARM: dts: dra7xx: Update spi-max-frequency for qspi slave node

PATCH Superseded Vignesh R 3 participants 9 messages Oct 12, 2016 – Oct 26, 2016

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vignesh R

author
#0 lore raw

PATCH 1/2 ARM: dts: dra7xx: Update spi-max-frequency for qspi slave node

Update the spi-max-frequency property of m25p80 flash slave to match that of TI QSPI controller node, so that QSPI operations happen at maximum supported frequency of 76.8MHz.

---
 arch/arm/dts/dra7-evm.dts          | 2 +-
 arch/arm/dts/dra72-evm-common.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/dts/dra7-evm.dts +1 -1
index fe755c05841d..be36d456206d 100644
@@ -505,7 +505,7 @@
 	spi-max-frequency = <76800000>;
 	m25p80 at 0 {
 		compatible = "s25fl256s1","spi-flash";
-		spi-max-frequency = <64000000>;
+		spi-max-frequency = <76800000>;
 		reg = <0>;
 		spi-tx-bus-width = <1>;
 		spi-rx-bus-width = <4>;
arch/arm/dts/dra72-evm-common.dtsi +1 -1
index b0993e5bf7e0..1e1ca725577f 100644
@@ -441,7 +441,7 @@
 	spi-max-frequency = <76800000>;
 	m25p80 at 0 {
 		compatible = "s25fl256s1", "spi-flash";
-		spi-max-frequency = <64000000>;
+		spi-max-frequency = <76800000>;
 		reg = <0>;
 		spi-tx-bus-width = <1>;
 		spi-rx-bus-width = <4>;
Signature · 1 line
2.10.1
author
#1 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

Fix the divider calculation logic to choose a value so that the resulting baudrate is either equal to or closest possible baudrate less than the requested value.

---
 drivers/spi/ti_qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/ti_qspi.c +2 -1
index 52520dff6325..d97e2479d1b3 100644
@@ -16,6 +16,7 @@
 #include <asm/omap_gpio.h>
 #include <asm/omap_common.h>
 #include <asm/ti-common/ti-edma3.h>
+#include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
 	if (!hz)
 		clk_div = 0;
 	else
-		clk_div = (priv->fclk / hz) - 1;
+		clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;
 
 	debug("ti_spi_set_speed: hz: %d, clock divider %d\n", hz, clk_div);
 
Signature · 1 line
2.10.1
#2 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

Quoted 22 lines · Vignesh R

Fix the divider calculation logic to choose a value so that the resulting baudrate is either equal to or closest possible baudrate less than the requested value.

---
 drivers/spi/ti_qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/ti_qspi.c +1 -0
index 52520dff6325..d97e2479d1b3 100644
@@ -16,6 +16,7 @@
 #include <asm/omap_gpio.h>
 #include <asm/omap_common.h>
 #include <asm/ti-common/ti-edma3.h>
+#include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 122

Quoted 5 lines
drivers/spi/ti_qspi.c +1 -1
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
        if (!hz)
                clk_div = 0;
        else
-               clk_div = (priv->fclk / hz) - 1;
+               clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;

Better to have a checks for min and max divider values or mask.

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 124

Quoted 2 lines
drivers/spi/ti_qspi.c +0 -0
        debug("ti_spi_set_speed: hz: %d, clock divider %d\n", hz, clk_div);

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#8 lore raw

PATCH 1/2 ARM: dts: dra7xx: Update spi-max-frequency for qspi slave node

In reply to Vignesh R
Quoted 5 lines · Vignesh R

Update the spi-max-frequency property of m25p80 flash slave to match that of TI QSPI controller node, so that QSPI operations happen at maximum supported frequency of 76.8MHz.

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
author
#3 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

In reply to Jagan Teki

Hi,

Quoted 22 lines · Jagan Teki
Quoted 21 lines · Vignesh R

Fix the divider calculation logic to choose a value so that the resulting baudrate is either equal to or closest possible baudrate less than the requested value.

---
 drivers/spi/ti_qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/ti_qspi.c +1 -0
index 52520dff6325..d97e2479d1b3 100644
@@ -16,6 +16,7 @@
 #include <asm/omap_gpio.h>
 #include <asm/omap_common.h>
 #include <asm/ti-common/ti-edma3.h>
+#include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
Quoted 8 lines

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 122

Quoted 6 lines
drivers/spi/ti_qspi.c +1 -1
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
        if (!hz)
                clk_div = 0;
        else
-               clk_div = (priv->fclk / hz) - 1;
+               clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;

Better to have a checks for min and max divider values or mask.

That code already exists in this function.

Signature · 2 lines
Regards
Vignesh
#4 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

Quoted 34 lines · Vignesh R

Hi,

Quoted 22 lines · Jagan Teki
Quoted 21 lines · Vignesh R

Fix the divider calculation logic to choose a value so that the resulting baudrate is either equal to or closest possible baudrate less than the requested value.

---
 drivers/spi/ti_qspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/ti_qspi.c +1 -0
index 52520dff6325..d97e2479d1b3 100644
@@ -16,6 +16,7 @@
 #include <asm/omap_gpio.h>
 #include <asm/omap_common.h>
 #include <asm/ti-common/ti-edma3.h>
+#include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
Quoted 8 lines

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 122

Quoted 6 lines
drivers/spi/ti_qspi.c +1 -1
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
        if (!hz)
                clk_div = 0;
        else
-               clk_div = (priv->fclk / hz) - 1;
+               clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;

Better to have a checks for min and max divider values or mask.

Quoted 1 line

That code already exists in this function.

True but it's unnecessary to print the wrong baud prior to checking. Do the check, then print/debug and finally write reg.

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
author
#7 lore raw

PATCH v2 2/2 spi: ti_qspi: Fix baudrate divider calculation

In reply to Vignesh R

Fix the divider calculation logic to choose a value so that the resulting baudrate is either equal to or closest possible baudrate less than the requested value. While at that, cleanup ti_spi_set_speed().

---

v2: cleanup ti_spi_set_speed() a bit.

 drivers/spi/ti_qspi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/spi/ti_qspi.c +7 -8
index 52520dff6325..b5de70bf40e3 100644
@@ -16,6 +16,7 @@
 #include <asm/omap_gpio.h>
 #include <asm/omap_common.h>
 #include <asm/ti-common/ti-edma3.h>
+#include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -118,21 +119,19 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
 	if (!hz)
 		clk_div = 0;
 	else
-		clk_div = (priv->fclk / hz) - 1;
-
-	debug("ti_spi_set_speed: hz: %d, clock divider %d\n", hz, clk_div);
+		clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;
 
 	/* disable SCLK */
 	writel(readl(&priv->base->clk_ctrl) & ~QSPI_CLK_EN,
 	       &priv->base->clk_ctrl);
 
-	/* assign clk_div values */
-	if (clk_div < 0)
-		clk_div = 0;
-	else if (clk_div > QSPI_CLK_DIV_MAX)
+	/* truncate clk_div value to QSPI_CLK_DIV_MAX */
+	if (clk_div > QSPI_CLK_DIV_MAX)
 		clk_div = QSPI_CLK_DIV_MAX;
 
-	/* enable SCLK */
+	debug("ti_spi_set_speed: hz: %d, clock divider %d\n", hz, clk_div);
+
+	/* enable SCLK and program the clk divider */
 	writel(QSPI_CLK_EN | clk_div, &priv->base->clk_ctrl);
 }
 
Signature · 1 line
2.10.1
#5 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

In reply to Jagan Teki
Quoted 1 line · Jagan Teki

On Fri, Oct 14, 2016 at 10:54 AM, Vignesh R <[email protected]> wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 122

Quoted 8 lines

DECLARE_GLOBAL_DATA_PTR;

drivers/spi/ti_qspi.c +1 -1
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
        if (!hz)
                clk_div = 0;
        else
-               clk_div = (priv->fclk / hz) - 1;
+               clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;

Better to have a checks for min and max divider values or mask.

Quoted 5 lines
Quoted 1 line

That code already exists in this function.

True but it's unnecessary to print the wrong baud prior to checking. Do the check, then print/debug and finally write reg.

Posted a v2 in reply to the patch. Thanks for the review!

Regards
Vignesh

#6 lore raw

PATCH 2/2 spi: ti_qspi: Fix baudrate divider calculation

Quoted 16 lines · Vignesh
Quoted 1 line · Jagan Teki

On Fri, Oct 14, 2016 at 10:54 AM, Vignesh R <[email protected]> wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

drivers/spi/ti_qspi.c static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz) · line 122

Quoted 8 lines

DECLARE_GLOBAL_DATA_PTR;

drivers/spi/ti_qspi.c +1 -1
@@ -118,7 +119,7 @@ static void ti_spi_set_speed(struct ti_qspi_priv *priv, uint hz)
        if (!hz)
                clk_div = 0;
        else
-               clk_div = (priv->fclk / hz) - 1;
+               clk_div = DIV_ROUND_UP(priv->fclk, hz) - 1;

Better to have a checks for min and max divider values or mask.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

That code already exists in this function.

True but it's unnecessary to print the wrong baud prior to checking. Do the check, then print/debug and finally write reg.

Posted a v2 in reply to the patch. Thanks for the review!

Please re-post the two patches again, so how I missed it.

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.