Skip to contentSkip to conversation

spi: cadence_qspi: support DM_CLK

PATCH New Simon Goldschmidt 3 participants 5 messages Oct 23, 2019 – Oct 24, 2019 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: cadence_qspi: support DM_CLK

Support loading clk speed via DM instead of requiring ad-hoc code.

---

 drivers/spi/cadence_qspi.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +18 -2
index e2e54cd277..0b89115885 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
@@ -22,12 +23,27 @@ static int cadence_spi_write_speed(struct udevice *bus, uint hz)
 {
 	struct cadence_spi_platdata *plat = bus->platdata;
 	struct cadence_spi_priv *priv = dev_get_priv(bus);
+	unsigned int ref_clk_hz;
+	struct clk clk;
+	int ret;
+
+	ret = clk_get_by_index(bus, 0, &clk);
+	if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
+		ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+		return ret;
+#endif
+	} else {
+		ref_clk_hz = clk_get_rate(&clk);
+		clk_free(&clk);
+	}
 
 	cadence_qspi_apb_config_baudrate_div(priv->regbase,
-					     CONFIG_CQSPI_REF_CLK, hz);
+					     ref_clk_hz, hz);
 
 	/* Reconfigure delay timing if speed is changed. */
-	cadence_qspi_apb_delay(priv->regbase, CONFIG_CQSPI_REF_CLK, hz,
+	cadence_qspi_apb_delay(priv->regbase, ref_clk_hz, hz,
 			       plat->tshsl_ns, plat->tsd2d_ns,
 			       plat->tchsh_ns, plat->tslch_ns);
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 spi: cadence_qspi: support DM_CLK

Quoted 28 lines · Simon Goldschmidt

Support loading clk speed via DM instead of requiring ad-hoc code.

---

 drivers/spi/cadence_qspi.c | 20 ++++++++++++++++++--

 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index e2e54cd277..0b89115885 100644
@@ -5,6 +5,7 @@
   */


 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>

drivers/spi/cadence_qspi.c +3 -0
@@ -22,12 +23,27 @@ static int cadence_spi_write_speed(struct udevice
 *bus, uint hz)
  {
  	struct cadence_spi_platdata *plat = bus->platdata;
  	struct cadence_spi_priv *priv = dev_get_priv(bus);
+	unsigned int ref_clk_hz;
+	struct clk clk;
+	int ret;

drivers/spi/cadence_qspi.c static int cadence_spi_write_speed(struct udevice · line 39

Quoted 10 lines
drivers/spi/cadence_qspi.c +10 -0
+
+	ret = clk_get_by_index(bus, 0, &clk);
+	if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
+		ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+		return ret;
+#endif
+	} else {
+		ref_clk_hz = clk_get_rate(&clk);

clk_get_rate() might return negative error code if failed to get clock rate.

Quoted 15 lines
drivers/spi/cadence_qspi.c +2 -0
+		clk_free(&clk);
+	}

cadence_qspi_apb_config_baudrate_div(priv->regbase,

drivers/spi/cadence_qspi.c +0 -1
-					     CONFIG_CQSPI_REF_CLK,

hz);

drivers/spi/cadence_qspi.c +1 -0
+					     ref_clk_hz, hz);


  /* Reconfigure delay timing if speed is changed. */

drivers/spi/cadence_qspi.c +0 -1
-	cadence_qspi_apb_delay(priv->regbase, CONFIG_CQSPI_REF_CLK,

hz,

drivers/spi/cadence_qspi.c +1 -0
+	cadence_qspi_apb_delay(priv->regbase, ref_clk_hz, hz,

         plat->tshsl_ns, plat->tsd2d_ns, plat->tchsh_ns, plat->tslch_ns);

#2 lore raw

PATCH 1/1 spi: cadence_qspi: support DM_CLK

Quoted 34 lines · Ley Foon Tan
Quoted 32 lines · Simon Goldschmidt

Support loading clk speed via DM instead of requiring ad-hoc code.

---

 drivers/spi/cadence_qspi.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +8 -0
index e2e54cd277..0b89115885 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
@@ -22,12 +23,27 @@ static int cadence_spi_write_speed(struct udevice
 *bus, uint hz)
 {
      struct cadence_spi_platdata *plat = bus->platdata;
      struct cadence_spi_priv *priv = dev_get_priv(bus);
+     unsigned int ref_clk_hz;
+     struct clk clk;
+     int ret;
+
+     ret = clk_get_by_index(bus, 0, &clk);
+     if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
Quoted 8 lines

drivers/spi/cadence_qspi.c static int cadence_spi_write_speed(struct udevice *bus, uint hz) · line 38

Quoted 6 lines
drivers/spi/cadence_qspi.c +6 -0
+             ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+             return ret;
+#endif
+     } else {
+             ref_clk_hz = clk_get_rate(&clk);

clk_get_rate() might return negative error code if failed to get clock rate.

Sigh, you're right. Returning negative error values in an ulong seems like a funny way of getting people to ignore error values.

I can understand we might have to do that when returning pointers, but this function should better return long, not ulong...

I'll send a v2.

Regards,
Simon

Quoted 15 lines
Quoted 15 lines
drivers/spi/cadence_qspi.c +4 -2
+             clk_free(&clk);
+     }
 
      cadence_qspi_apb_config_baudrate_div(priv->regbase,
-                                          CONFIG_CQSPI_REF_CLK,
 hz);
+                                          ref_clk_hz, hz);
 
      /* Reconfigure delay timing if speed is changed. */
-     cadence_qspi_apb_delay(priv->regbase, CONFIG_CQSPI_REF_CLK,
 hz,
+     cadence_qspi_apb_delay(priv->regbase, ref_clk_hz, hz,
                             plat->tshsl_ns, plat->tsd2d_ns,
                             plat->tchsh_ns, plat->tslch_ns);
#3 lore raw

PATCH 1/1 spi: cadence_qspi: support DM_CLK

Quoted 45 lines · Simon Goldschmidt
Quoted 34 lines · Ley Foon Tan
Quoted 32 lines · Simon Goldschmidt

Support loading clk speed via DM instead of requiring ad-hoc code.

---

 drivers/spi/cadence_qspi.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +8 -0
index e2e54cd277..0b89115885 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
@@ -22,12 +23,27 @@ static int cadence_spi_write_speed(struct udevice
 *bus, uint hz)
 {
      struct cadence_spi_platdata *plat = bus->platdata;
      struct cadence_spi_priv *priv = dev_get_priv(bus);
+     unsigned int ref_clk_hz;
+     struct clk clk;
+     int ret;
+
+     ret = clk_get_by_index(bus, 0, &clk);
+     if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
Quoted 8 lines

drivers/spi/cadence_qspi.c static int cadence_spi_write_speed(struct udevice *bus, uint hz) · line 38

Quoted 6 lines
drivers/spi/cadence_qspi.c +6 -0
+             ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+             return ret;
+#endif
+     } else {
+             ref_clk_hz = clk_get_rate(&clk);

clk_get_rate() might return negative error code if failed to get clock rate.

Quoted 7 lines

Sigh, you're right. Returning negative error values in an ulong seems like a funny way of getting people to ignore error values.

I can understand we might have to do that when returning pointers, but this function should better return long, not ulong...

I'll send a v2.

Do it on top of u-boot-spi/master, have Ley patch on this tree.

#4 lore raw

PATCH 1/1 spi: cadence_qspi: support DM_CLK

Jagan Teki <[email protected]> schrieb am Do., 24. Okt. 2019, 09:22:

Quoted 52 lines
Quoted 2 lines · Simon Goldschmidt

On Thu, Oct 24, 2019 at 4:54 AM Ley Foon Tan <[email protected]>

Quoted 43 lines · wrote:
Quoted 34 lines · Simon Goldschmidt
Quoted 32 lines

Support loading clk speed via DM instead of requiring ad-hoc code.

---

 drivers/spi/cadence_qspi.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +8 -0
index e2e54cd277..0b89115885 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
@@ -22,12 +23,27 @@ static int cadence_spi_write_speed(struct udevice
 *bus, uint hz)
 {
      struct cadence_spi_platdata *plat = bus->platdata;
      struct cadence_spi_priv *priv = dev_get_priv(bus);
+     unsigned int ref_clk_hz;
+     struct clk clk;
+     int ret;
+
+     ret = clk_get_by_index(bus, 0, &clk);
+     if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
Quoted 8 lines

drivers/spi/cadence_qspi.c static int cadence_spi_write_speed(struct udevice *bus, uint hz) · line 38

Quoted 6 lines
drivers/spi/cadence_qspi.c +6 -0
+             ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+             return ret;
+#endif
+     } else {
+             ref_clk_hz = clk_get_rate(&clk);

clk_get_rate() might return negative error code if failed to get clock rate.

Quoted 1 line

Sigh, you're right. Returning negative error values in an ulong seems

like a

Quoted 2 lines

funny way of getting people to ignore error values.

Quoted 8 lines
Quoted 1 line

I can understand we might have to do that when returning pointers, but

this

Quoted 3 lines

function should better return long, not ulong...

I'll send a v2.

Do it on top of u-boot-spi/master, have Ley patch on this tree.

Will do so.