cmd/sf: probe flash with speed of last known flash or speed from devicetree
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the 'spi_flash_probe_bus_cs' really scanning the bus.
Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero speed.
Result of this is, that the spi-flash runs at very low speed depending on the minimum given by low-level driver/hardware.
Values like 'spi-max-frequency' from devicetree are ignored totally today.
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from the responsible spi node is taken.
---
cmd/sf.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
cmd/sf.c +10 -0
@@ -87,6 +87,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])char *endp;#ifdef CONFIG_DM_SPI_FLASH struct udevice *new, *bus_dev; +struct dm_spi_bus *spi;int ret;/* In DM mode defaults will be taken from DT */ speed =0 , mode =0 ;
@@ -124,6 +125,15 @@ static int do_spi_flash_probe(int argc, char * const argv[])/* Remove the old device, otherwise probe will just be a nop */ ret =spi_find_bus_and_cs (bus, cs, &bus_dev, &new);if (!ret) { +if (new !=NULL ) { + flash =dev_get_uclass_priv (new); +if (flash !=NULL ) { + speed = flash->spi->speed; + }else { + spi =dev_get_uclass_priv (bus_dev); + speed = spi->max_hz; + } + }device_remove (new);device_unbind (new); }
Signature · 1 line
1.9.1
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Hi,
Quoted 13 lines · Hannes Schmelzer
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the '
spi_flash_probe_bus_cs' really scanning the bus.Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero speed.
Result of this is, that the spi-flash runs at very low speed depending on the minimum given by low-level driver/hardware.Values like 'spi-max-frequency' from devicetree are ignored totally today.
Quoted 7 lines
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from the responsible spi node is taken.Signed-off-by Hannes Schmelzer <[email protected]>
With commit 96907c0fe50a8 ("dm: spi: Read default speed and mode values from DT") sf probe picks spi-max-frequency from DT if not specified as argument.
But when sf probe is called second time, the command fails to pick up speed from DT. This is because flash node is unbound from the SPI controller children nodes. Below patch should fix this issue:
https://patchwork.ozlabs.org/patch/659979/
Signature · 2 lines
Regards Vignesh
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 1 line · Vignesh R
Hi,
Hi Vignesh,
Quoted 22 lines · Hannes Schmelzer
Quoted 13 lines
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the '
spi_flash_probe_bus_cs' really scanning the bus.Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero speed.
Result of this is, that the spi-flash runs at very low speed depending on the minimum given by low-level driver/hardware.Values like 'spi-max-frequency' from devicetree are ignored totally today.
Quoted 7 lines
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from the responsible spi node is taken.Signed-off-by Hannes Schmelzer <[email protected]>
Quoted 8 lines
With commit
96907c0fe50a8("dm: spi: Read default speed and mode values from DT") sf probe picks spi-max-frequency from DT if not specified as argument.But when sf probe is called second time, the command fails to pick up speed from DT. This is because flash node is unbound from the SPI controller children nodes. Below patch should fix this issue:
https://patchwork.ozlabs.org/patch/659979/
sry ... i didn't took notice about this patch at the beginning of mine. Just reviewed and tested it.
The named patch makes things a bit better but not good. Speed for flash still has no relationship to 'spi-max-frequency' from the spi-bus nor with a maybe defined flash in dts.
Rather the #define CONFIG_ENV_SPI_MAX_HZ is used.
But for my thinking the way we should walk is having more and more and finally (if possible) all within device-tree and dynamic configuration rather than in #define ...
cheers,
Hannes
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 34 lines · Hannes Schmelzer
Quoted 1 line · Vignesh R
Hi,
Hi Vignesh,
Quoted 22 lines · Hannes Schmelzer
Quoted 13 lines
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the '
spi_flash_probe_bus_cs' really scanning the bus.Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero speed.
Result of this is, that the spi-flash runs at very low speed depending on the minimum given by low-level driver/hardware.Values like 'spi-max-frequency' from devicetree are ignored totally today.
Quoted 7 lines
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from the responsible spi node is taken.Signed-off-by Hannes Schmelzer <[email protected]>Quoted 8 lines
With commit
96907c0fe50a8("dm: spi: Read default speed and mode values from DT") sf probe picks spi-max-frequency from DT if not specified as argument.But when sf probe is called second time, the command fails to pick up speed from DT. This is because flash node is unbound from the SPI controller children nodes. Below patch should fix this issue:
https://patchwork.ozlabs.org/patch/659979/
Quoted 9 lines
sry ... i didn't took notice about this patch at the beginning of mine. Just reviewed and tested it.
The named patch makes things a bit better but not good. Speed for flash still has no relationship to 'spi-max-frequency' from the spi-bus nor with a maybe defined flash in dts.
Rather the #define
CONFIG_ENV_SPI_MAX_HZis used.
sf probe calls do_spi_flash_probe()
-spi_flash_probe_bus_cs() -spi_get_bus_and_cs()
In spi_get_bus_and_cs():
if (!speed) {
speed = plat->max_hz;
mode = plat->mode;
}This should set speed to spi-max-frequency as per flash DT node.
AFAIU, saveenv() uses CONFIG_ENV_SPI_MAX_HZ only when CONFIG_DM_SPI_FLASH is not defined. Could please explain how CONFIG_ENV_SPI_MAX_HZ takes precedence over spi-max-frequency during sf probe?
Signature · 2 lines
Regards Vignesh
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 47 lines · Vignesh R
Quoted 32 lines · Hannes Schmelzer
Quoted 1 line · Vignesh R
Hi,
Hi Vignesh,
Quoted 21 lines · Hannes Schmelzer
Quoted 13 lines
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the '
spi_flash_probe_bus_cs' really scanning the bus.Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero speed.
Result of this is, that the spi-flash runs at very low speed depending on the minimum given by low-level driver/hardware.Values like 'spi-max-frequency' from devicetree are ignored totally today.
Quoted 7 lines
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from the responsible spi node is taken.Signed-off-by Hannes Schmelzer <[email protected]>Quoted 8 lines
With commit
96907c0fe50a8("dm: spi: Read default speed and mode values from DT") sf probe picks spi-max-frequency from DT if not specified as argument.But when sf probe is called second time, the command fails to pick up speed from DT. This is because flash node is unbound from the SPI controller children nodes. Below patch should fix this issue:
https://patchwork.ozlabs.org/patch/659979/Quoted 9 lines
sry ... i didn't took notice about this patch at the beginning of mine. Just reviewed and tested it.
The named patch makes things a bit better but not good. Speed for flash still has no relationship to 'spi-max-frequency' from the spi-bus nor with a maybe defined flash in dts.
Rather the #define
CONFIG_ENV_SPI_MAX_HZis used.sf probe calls
do_spi_flash_probe()-spi_flash_probe_bus_cs() -spi_get_bus_and_cs()
Quoted 6 lines
In
spi_get_bus_and_cs():if (!speed) { speed = plat->max_hz; mode = plat->mode; }This should set speed to spi-max-frequency as per flash DT node.
yes that should do.
But have look a few lines up, around 296, there the newly created flash node has been modified with wrong values before.
No glue why a new flash node is being created.
Quoted 4 lines
AFAIU,
saveenv()usesCONFIG_ENV_SPI_MAX_HZonly whenCONFIG_DM_SPI_FLASHis not defined. Could please explain howCONFIG_ENV_SPI_MAX_HZtakes precedence over spi-max-frequency during sf probe?
Thanks the discussion, I think we coming closer to the problem. Your'e right saveenv() behaves as you described, but not so env_relocate_spec().
There the flash is probed like this:
env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
and thats the point where some existing dt node becomes modified with those values. Thats probably wrong doing so.
I think there should be same logic applied as in saveen().
Just for testing i fixed the probe there.
Now i'm a bit confused about that the function spi_find_chip_select(bus, cs, &dev) in spi-uclass doesn't find child devices on the spi node. Instead there a new flash binding is created.spi_get_bus_and_cs: Binding new device 'spi_flash at 0:0', busnum=0, cs=0, driver=spi_flash_std
my devicetree look like this:
=> fdt print spi0
spi at e000d000 {
clock-names = "ref_clk", "pclk";
clocks = <0x00000001 0x0000000a 0x00000001 0x0000002b>;
compatible = "xlnx,zynq-qspi-1.0";
status = "okay";
interrupt-parent = <0x00000003>;
interrupts = <0x00000000 0x00000013 0x00000004>;
reg = <0xe000d000 0x00001000>;
#address-cells = <0x00000001>;
#size-cells = <0x00000000>;
u-boot,dm-pre-reloc;
spi-max-frequency = <0x05f5e100>;
S25FL256S at 0 {
#address-cells = <0x00000001>;
#size-cells = <0x00000001>;
compatible = "spansion,S25FL256S";
reg = <0x00000000>;
spi-max-frequency = <0x05f5e100>;
};
};=>
cheers,
Hannes
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 70 lines · Hannes Schmelzer
Quoted 51 lines · Vignesh R
Quoted 36 lines · Hannes Schmelzer
Quoted 1 line · Vignesh R
Hi,
Hi Vignesh,
Quoted 29 lines · Hannes Schmelzer
Quoted 15 lines
During probing flashes on the spi bus using the "sf probe" command, a maybe existing flash (from fdt) is unbound and removed to force the '
spi_flash_probe_bus_cs' really scanning the bus.Today the bus is probed with speed 0, this triggers several fall-back mechanism (mostly in the low-level drivers) to catch the impossible zero
speed.
Result of this is, that the spi-flash runs at very low speed depending
on the minimum given by low-level driver/hardware.Values like 'spi-max-frequency' from devicetree are ignored totally today.
Quoted 8 lines
This commit changes as following:
- if there was already some flash binding in devicetree (having some spi-max-frequency within) speed is taken from it
- if no flash binding was present for speed the 'spi-max-frequency' from
the responsible spi node is taken.Signed-off-by Hannes Schmelzer <[email protected]>With commit
96907c0fe50a8("dm: spi: Read default speed and mode values
from DT") sf probe picks spi-max-frequency from DT if not specified as argument.Quoted 4 lines
But when sf probe is called second time, the command fails to pick up speed from DT. This is because flash node is unbound from the SPI controller children nodes. Below patch should fix this issue:
https://patchwork.ozlabs.org/patch/659979/Quoted 9 lines
sry ... i didn't took notice about this patch at the beginning of mine. Just reviewed and tested it.
The named patch makes things a bit better but not good. Speed for flash still has no relationship to 'spi-max-frequency' from the spi-bus nor with a maybe defined flash in dts.
Rather the #define
CONFIG_ENV_SPI_MAX_HZis used.sf probe calls
do_spi_flash_probe()-spi_flash_probe_bus_cs() -spi_get_bus_and_cs()Quoted 6 lines
In
spi_get_bus_and_cs():if (!speed) { speed = plat->max_hz; mode = plat->mode; }This should set speed to spi-max-frequency as per flash DT node.
yes that should do.
But have look a few lines up, around 296, there the newly created flash node has been modified with wrong values before. No glue why a new flash node is being created.Quoted 4 lines
AFAIU,
saveenv()usesCONFIG_ENV_SPI_MAX_HZonly whenCONFIG_DM_SPI_FLASHis not defined. Could please explain howCONFIG_ENV_SPI_MAX_HZtakes precedence over spi-max-frequency during sf probe?Thanks the discussion, I think we coming closer to the problem. Your'e right
saveenv()behaves as you described, but not soenv_relocate_spec().
Quoted 8 lines
There the flash is probed like this:
env_flash= spi_flash_probe(CONFIG_ENV_SPI_BUS,CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ,CONFIG_ENV_SPI_MODE);and thats the point where some existing dt node becomes modified with those values. Thats probably wrong doing so.
I think there should be same logic applied as in
saveen().
Tested again, and confirming this behaviour.
Quoted 8 lines
Just for testing i fixed the probe there.
Now i'm a bit confused about that the functionspi_find_chip_select(bus, cs, &dev)in spi-uclass doesn't find child devices on the spi node.
Instead there a new flash binding is created.spi_get_bus_and_cs: Binding new device 'spi_flashat 0:0', busnum=0, cs=0, driver=spi_flash_std
Debugged into DM and found out that my devicetree didn't represent a valid flash-child.
I've now modified it to:
=> fdt print spi0
spi at e000d000 {
clock-names = "ref_clk", "pclk";
clocks = <0x00000001 0x0000000a 0x00000001 0x0000002b>;
compatible = "xlnx,zynq-qspi-1.0";
status = "okay";
interrupt-parent = <0x00000003>;
interrupts = <0x00000000 0x00000013 0x00000004>;
reg = <0xe000d000 0x00001000>;
#address-cells = <0x00000001>;
#size-cells = <0x00000000>;
u-boot,dm-pre-reloc;
spi-max-frequency = <0x05f5e100>;
spiflash at 0 {
u-boot,dm-pre-reloc;
compatible = "spidev", "spi-flash";
spi-max-frequency = <0x05f5e100>;
reg = <0x00000000>;
};
};=>
So that works and u-boot knows the flash from beginning and uses as correct flash-node from fdt instead creating a new one.
Finally i think, we can drop my patch and somebody (maybe me?) should fix the probing during environment relocation.
cheers,
Hannes
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 5 lines · Hannes Schmelzer
Quoted 4 lines · Hannes Schmelzer
Quoted 3 lines · Vignesh R
Quoted 1 line · Hannes Schmelzer
On 08/24/2016 12:35 PM, Vignesh R wrote:
[...]
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
AFAIU,
saveenv()usesCONFIG_ENV_SPI_MAX_HZonly whenCONFIG_DM_SPI_FLASHis not defined. Could please explain howCONFIG_ENV_SPI_MAX_HZtakes precedence over spi-max-frequency during sf probe?Thanks the discussion, I think we coming closer to the problem. Your'e right
saveenv()behaves as you described, but not soenv_relocate_spec().There the flash is probed like this:
env_flash= spi_flash_probe(CONFIG_ENV_SPI_BUS,CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ,CONFIG_ENV_SPI_MODE);
Quoted 5 lines
Quoted 4 lines
and thats the point where some existing dt node becomes modified with those values. Thats probably wrong doing so.
I think there should be same logic applied as in
saveen().Tested again, and confirming this behaviour.
Yeah, I think relocate_spec() was not updated during dm conversion.
Quoted 13 lines
Quoted 8 lines
Just for testing i fixed the probe there.
Now i'm a bit confused about that the functionspi_find_chip_select(bus, cs, &dev)in spi-uclass doesn't find child devices on the spi node.
Instead there a new flash binding is created.spi_get_bus_and_cs: Binding new device 'spi_flashat 0:0', busnum=0, cs=0, driver=spi_flash_stdDebugged into DM and found out that my devicetree didn't represent a valid flash-child.
I've now modified it to:=> fdt print spi0
Quoted 15 lines
spi at e000d000 {
clock-names = "ref_clk", "pclk";
clocks = <0x00000001 0x0000000a 0x00000001 0x0000002b>;
compatible = "xlnx,zynq-qspi-1.0";
status = "okay";
interrupt-parent = <0x00000003>;
interrupts = <0x00000000 0x00000013 0x00000004>;
reg = <0xe000d000 0x00001000>;
#address-cells = <0x00000001>;
#size-cells = <0x00000000>;
u-boot,dm-pre-reloc;
spi-max-frequency = <0x05f5e100>;
spiflash at 0 {
u-boot,dm-pre-reloc;
compatible = "spidev", "spi-flash";Shouldn't this be: compatible = "spansion,S25FL256S_64K", "spi-flash"; as per doc/device-tree-bindings/mtd/spi/spi-flash.txt
Signature · 2 lines
Regards Vignesh
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 20 lines · Vignesh R
Quoted 4 lines · Hannes Schmelzer
Quoted 3 lines · Hannes Schmelzer
Quoted 2 lines · Vignesh R
Quoted 1 line · Hannes Schmelzer
On 08/24/2016 12:35 PM, Vignesh R wrote:
[...]
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
AFAIU,
saveenv()usesCONFIG_ENV_SPI_MAX_HZonly whenCONFIG_DM_SPI_FLASHis not defined. Could please explain howCONFIG_ENV_SPI_MAX_HZtakes precedence over spi-max-frequency during sf probe?Thanks the discussion, I think we coming closer to the problem. Your'e right
saveenv()behaves as you described, but not soenv_relocate_spec().There the flash is probed like this:
env_flash= spi_flash_probe(CONFIG_ENV_SPI_BUS,CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ,CONFIG_ENV_SPI_MODE);
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
and thats the point where some existing dt node becomes modified with those values. Thats probably wrong doing so.
I think there should be same logic applied as in
saveen().Tested again, and confirming this behaviour.
Yeah, I think
relocate_spec()was not updated during dm conversion.
looks like, should i submit some patch?
Quoted 28 lines
Quoted 13 lines
Quoted 8 lines
Just for testing i fixed the probe there.
Now i'm a bit confused about that the functionspi_find_chip_select(bus, cs, &dev)in spi-uclass doesn't find child devices on the spi node.
Instead there a new flash binding is created.spi_get_bus_and_cs: Binding new device 'spi_flashat 0:0', busnum=0, cs=0, driver=spi_flash_stdDebugged into DM and found out that my devicetree didn't represent a valid flash-child.
I've now modified it to:=> fdt print spi0
Quoted 15 lines
spi at e000d000 { clock-names = "ref_clk", "pclk"; clocks = <0x00000001 0x0000000a 0x00000001 0x0000002b>; compatible = "xlnx,zynq-qspi-1.0"; status = "okay"; interrupt-parent = <0x00000003>; interrupts = <0x00000000 0x00000013 0x00000004>; reg = <0xe000d000 0x00001000>; #address-cells = <0x00000001>; #size-cells = <0x00000000>; u-boot,dm-pre-reloc; spi-max-frequency = <0x05f5e100>; spiflash at 0 { u-boot,dm-pre-reloc; compatible = "spidev", "spi-flash";
Quoted 2 lines
Shouldn't this be: compatible = "spansion,S25FL256S_64K", "spi-flash"; as per
doc/device-tree-bindings/mtd/spi/spi-flash.txt
yes you're right ... i will fix this.
PATCH 1/1 cmd/sf: probe flash with speed of last known flash or speed from devicetree
Quoted 22 lines · Hannes Schmelzer
Quoted 21 lines · Vignesh R
Quoted 4 lines · Hannes Schmelzer
Quoted 3 lines · Hannes Schmelzer
Quoted 2 lines · Vignesh R
Quoted 1 line · Hannes Schmelzer
On 08/24/2016 12:35 PM, Vignesh R wrote:
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
AFAIU,
saveenv()usesCONFIG_ENV_SPI_MAX_HZonly whenCONFIG_DM_SPI_FLASHis not defined. Could please explain howCONFIG_ENV_SPI_MAX_HZtakes precedence over spi-max-frequency during sf
probe?Thanks the discussion, I think we coming closer to the problem. Your'e right
saveenv()behaves as you described, but not soenv_relocate_spec().There the flash is probed like this:
env_flash= spi_flash_probe(CONFIG_ENV_SPI_BUS,CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ,CONFIG_ENV_SPI_MODE);
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
and thats the point where some existing dt node becomes modified with those values. Thats probably wrong doing so.
I think there should be same logic applied as in
saveen().Tested again, and confirming this behaviour.
Yeah, I think
relocate_spec()was not updated during dm conversion.looks like, should i submit some patch?
Patches are welcome. Please Cc U-Boot SPI maintainer Jagan Teki <[email protected]>. Thanks!
Signature · 2 lines
Regards Vignesh