Skip to contentSkip to conversation

spi: cadence_qspi: Ensure spi_calibration is run when sclk change

PATCH New Chin Liang See 2 participants 7 messages Sep 1, 2015 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
---
 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +3 -0
index 34a0f46..512bf2d 100644
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice *bus, uint hz)
 
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+
 	/* Calibration required for different SCLK speed or chip select */
 	if (priv->qspi_calibrated_hz != plat->max_hz ||
 	    priv->qspi_calibrated_cs != spi_chip_select(bus)) {
Signature · 1 line
1.7.7.4
#1 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Quoted 20 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
---
 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index 34a0f46..512bf2d 100644

drivers/spi/cadence_qspi.c static int cadence_spi_set_speed(struct udevice *bus, · line 134

Quoted 7 lines
drivers/spi/cadence_qspi.c +3 -0
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice *bus,
 uint hz)
 
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Quoted 3 lines
drivers/spi/cadence_qspi.c +0 -0
 	/* Calibration required for different SCLK speed or chip select */
 	if (priv->qspi_calibrated_hz != plat->max_hz ||

priv->qspi_calibrated_cs != spi_chip_select(bus)) {

Best regards,
Marek Vasut

#2 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Quoted 23 lines · marex at denx.de
Quoted 22 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
---
 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index 34a0f46..512bf2d 100644
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice *bus,
 uint hz)
 
Quoted 8 lines

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

Quoted 5 lines
drivers/spi/cadence_qspi.c +3 -0
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Nope. I checked through debugger where plat->max_hz is initialized once with the value from device tree. When you use sf probe to change frequency, the value is not reflected to plat->max_hz. Hence the calibration is not run when frequency change. That lead to the sf probe fail when running at 80MHz or higher. Note the priv->qspi_calibrated_hz is updated after calibration succeed.

Thanks
Chin Liang

Quoted 7 lines
Quoted 4 lines
drivers/spi/cadence_qspi.c +0 -0
 	/* Calibration required for different SCLK speed or chip select */
 	if (priv->qspi_calibrated_hz != plat->max_hz ||

priv->qspi_calibrated_cs != spi_chip_select(bus)) {

Best regards,
Marek Vasut

#3 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Quoted 40 lines · Chin Liang See
Quoted 23 lines · marex at denx.de
Quoted 22 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
---
 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index 34a0f46..512bf2d 100644
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice *bus,
 uint hz)
 
Quoted 8 lines

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

Quoted 5 lines
drivers/spi/cadence_qspi.c +3 -0
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Nope. I checked through debugger where plat->max_hz is initialized once with the value from device tree. When you use sf probe to change frequency, the value is not reflected to plat->max_hz. Hence the calibration is not run when frequency change. That lead to the sf probe fail when running at 80MHz or higher. Note the priv->qspi_calibrated_hz is updated after calibration succeed.

Quoted 2 lines

Thanks
Chin Liang

Here are the useful info

U-Boot 2015.10-rc2-06835-gf7d7156-dirty (Sep 01 2015 - 08:29:14 +0000)

CPU:   Altera SoCFPGA Platform
FPGA:  Altera Cyclone V, SE/A6 or SX/C6 or ST/D6, version 0x0
BOOT:  SD/MMC External Transceiver (1.8V)
       Watchdog enabled
I2C:   ready
DRAM:  1 GiB
MMC:   SOCFPGA DWMMC: 0

Using default environment

In:    serial
Out:   serial
Err:   serial
Model: Altera SOCFPGA Cyclone V SoC Development Kit

Net:
Error: ethernet at ff702000 address not set.
No ethernet found.
Hit any key to stop autoboot: 0
=> sf probe 0 1000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 0000000f ....
=> sf probe 0 10000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 0000000f ....
=> sf probe 0 20000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 0000000d ....
=> sf probe 0 50000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 00000007 ....
=> sf probe 0 80000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 00000007 ....
=> sf probe 0 100000000
SF: Detected N25Q512 with page size 256 Bytes, erase size 4 KiB, total 64 MiB
=> md ff705010 1
ff705010: 00000007 ....

Thanks
Chin Liang

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
drivers/spi/cadence_qspi.c +0 -0
 	/* Calibration required for different SCLK speed or chip select */
 	if (priv->qspi_calibrated_hz != plat->max_hz ||

priv->qspi_calibrated_cs != spi_chip_select(bus)) {

Best regards,
Marek Vasut

#4 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

In reply to Chin Liang See
Quoted 34 lines · Chin Liang See
Quoted 24 lines · marex at denx.de
Quoted 23 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>

---

 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index 34a0f46..512bf2d 100644
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice
 *bus, uint hz)
 
Quoted 8 lines

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

Quoted 5 lines
drivers/spi/cadence_qspi.c +3 -0
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Quoted 6 lines

Nope. I checked through debugger where plat->max_hz is initialized once with the value from device tree. When you use sf probe to change frequency, the value is not reflected to plat->max_hz. Hence the calibration is not run when frequency change. That lead to the sf probe fail when running at 80MHz or higher. Note the priv->qspi_calibrated_hz is updated after calibration succeed.

Isn't the purpose of ->max_hz to reflect the maximum frequency of the bus? I don't think this should thus ever be updated, in particular not by the user. I also think that setting ->max_hz once from DT is the correct behavior.

Best regards,
Marek Vasut

#5 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Quoted 42 lines · marex at denx.de
Quoted 34 lines · Chin Liang See
Quoted 24 lines · marex at denx.de
Quoted 23 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>

---

 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/spi/cadence_qspi.c +0 -0
index 34a0f46..512bf2d 100644
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice
 *bus, uint hz)
 
Quoted 8 lines

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

Quoted 5 lines
drivers/spi/cadence_qspi.c +3 -0
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change */
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Quoted 6 lines

Nope. I checked through debugger where plat->max_hz is initialized once with the value from device tree. When you use sf probe to change frequency, the value is not reflected to plat->max_hz. Hence the calibration is not run when frequency change. That lead to the sf probe fail when running at 80MHz or higher. Note the priv->qspi_calibrated_hz is updated after calibration succeed.

Quoted 4 lines

Isn't the purpose of ->max_hz to reflect the maximum frequency of the bus? I don't think this should thus ever be updated, in particular not by the user. I also think that setting ->max_hz once from DT is the correct behavior.

Oh, in this case, there are more bug in the code. I saw there is mismatch of the usage of this variable. As example, the line "priv->qspi_calibrated_hz = plat->max_hz;" is wrong as it would be always static. Besides that, there is no check against the requested speed not to exceed the max_hz. Let me fix this all again.

Thanks
Chin Liang

Quoted 2 lines

Best regards,
Marek Vasut

#6 lore raw

PATCH 1/1 spi: cadence_qspi: Ensure spi_calibration is run when sclk change

Quoted 27 lines · Chin Liang See
Quoted 26 lines · marex at denx.de
Quoted 25 lines · Chin Liang See
Quoted 24 lines · marex at denx.de
Quoted 23 lines · Chin Liang See

Ensuring spi_calibration is run when there is a change of sclk frequency. This will ensure the qspi flash access works for high sclk frequency

Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>

---

 drivers/spi/cadence_qspi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/drivers/spi/cadence_qspi.c index 34a0f46..512bf2d 100644

drivers/spi/cadence_qspi.c +0 -0
@@ -128,6 +128,9 @@ static int cadence_spi_set_speed(struct udevice
 *bus, uint hz)
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/spi/cadence_qspi.c static int cadence_spi_set_speed(struct udevice *bus, uint hz)

Quoted 3 lines
drivers/spi/cadence_qspi.c +1 -0
 	cadence_spi_write_speed(bus, hz);
 
+	/* to ensure spi_calibration is run when SCLK frequency change 

*/

Quoted 18 lines
Quoted 13 lines
Quoted 6 lines
Quoted 5 lines

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

Quoted 2 lines
drivers/spi/cadence_qspi.c +2 -0
+	plat->max_hz = hz;
+

This looks like a hack, doesn't this change just subvert the condition below to enforce the calibration ?

Quoted 6 lines

Nope. I checked through debugger where plat->max_hz is initialized once with the value from device tree. When you use sf probe to change frequency, the value is not reflected to plat->max_hz. Hence the calibration is not run when frequency change. That lead to the sf probe fail when running at 80MHz or higher. Note the priv->qspi_calibrated_hz is updated after calibration succeed.

Quoted 4 lines

Isn't the purpose of ->max_hz to reflect the maximum frequency of the bus? I don't think this should thus ever be updated, in particular not by the user. I also think that setting ->max_hz once from DT is the correct behavior.

Quoted 5 lines

Oh, in this case, there are more bug in the code. I saw there is mismatch of the usage of this variable. As example, the line "priv->qspi_calibrated_hz = plat->max_hz;" is wrong as it would be always static. Besides that, there is no check against the requested speed not to exceed the max_hz. Let me fix this all again.

THanks

Best regards,
Marek Vasut