sf: improve support of (Q)SPI flash memories
v3 cover sf: improve support of (Q)SPI flash memories
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset 0x10000 (u-boot env): OK
+ Page Program 1-1-4 at offset 0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...
- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset 0x10000 (u-boot env): OK
+ Page Program 1-1-1 at offset 0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.
- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset 0x10000 (u-boot env): OK
+ Page Program 1-1-1 at offset 0x10000: OK
- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset 0x6000 (u-boot env): OK
+ Page Program 1-1-1 at offest 0x6000: OK
- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OK
During my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.
Changes in v3:
- Add the include <spi.h> to fix build error for corvus_defconfig.
Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'struct spi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'struct spi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controller
drivers/mtd/spi/Kconfig | 16 +- drivers/mtd/spi/sf.c | 78 ++++++-- drivers/mtd/spi/sf_dataflash.c | 119 ++++++------ drivers/mtd/spi/sf_internal.h | 48 +++-- drivers/mtd/spi/spi_flash.c | 341 +++++++++++++++++++++++---------- drivers/mtd/spi/spi_flash_ids.c | 5 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 +++++++++++++++++ drivers/spi/spi-uclass.c | 40 ++++ drivers/spi/spi.c | 13 ++ include/spi.h | 168 +++++++++++++++++ include/spi_flash.h | 7 + 14 files changed, 1226 insertions(+), 190 deletions(-) create mode 100644 drivers/spi/atmel_qspi.c create mode 100644 drivers/spi/atmel_qspi.h
Signature · 1 line
2.13.0
PATCH v3 1/8 spi: add support of SPI flash commands
From: Cyrille Pitchen <[email protected]>
This patch introduces 'struct spi_flash_command' and functions spi_is_flash_command_supported() / spi_exec_flash_command().
The 'struct spi_flash_command' describes all the relevant parameters to execute any SPI flash command:
- the instruction op code
- the number of bytes used to send the address: 0, 3 or 4 bytes
- the number of mode and wait-state clock cycles, also called dummy cycles
- the number and values of data bytes to be sent or received
- the SPI x-y-z protocol [1]
- the flash command type [2]
[1] SPI x-y-z protocol:
- x is the number of I/O lines used to send the instruction op code.
- y is the number of I/O lines used during address, mode and wait-state clock cycles.
- z is the number of I/O lines used to send or received data.
[2] Flash command type:
The flash command type is provided to differenciate "memory" read/write/erase operations from "flash internal register" read/write operations. Indeed some SPI controller drivers handle those command type in different ways.
However SPI controller drivers should not check the value of the instruction op code to guess the actual kind of flash command to perform. Many instruction op codes are SPI flash manufacturer specific and only drivers/mtd/spi/spi_flash.c should have the knowledge of all of them.
Besides, more and more QSPI controllers, like those of TI and Candence, have special way to support (Fast) Read operations using some "memory like" area mapped into the system bus. Hence, if those drivers choose to override the default implementation of spi_is_flash_command_supported() so that their own functions return true only for a "memory read" flash command type, then spi_exec_flash_command() might be used to implement the read from the "memory like" area mapped into the system bus.
It means that spi_exec_flash_command() could be used to supersede the actual flash->memory_map mechanism; spi_is_flash_command_supported() / spi_exec_flash_command() being more generic and covering more use cases.
For instance, the Atmel QSPI hardware controller uses its "memory like" area mapped ino the system to perform not only (Fast) Read operations but actually all other types of flash commands. Hence the regular SPI API based on the spi_xfer() function is not suited to support the Atmel QSPI controller.
---
Changes in v3: None
Changes in v2: None
drivers/spi/spi-uclass.c | 40 +++++++++++ drivers/spi/spi.c | 13 ++++ include/spi.h | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+)
drivers/spi/spi-uclass.c +40 -0
@@ -91,6 +91,30 @@ int dm_spi_xfer(struct udevice *dev, unsigned int bitlen,return spi_get_ops (bus)->xfer (dev, bitlen, dout, din, flags); } +bool dm_spi_is_flash_command_supported (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->is_flash_command_supported) +return ops->is_flash_command_supported (dev, cmd); + +return false; +} + +int dm_spi_exec_flash_command (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->exec_flash_command) +return ops->exec_flash_command (dev, cmd); + +return -EINVAL ; +} +int spi_claim_bus (struct spi_slave *slave) {return dm_spi_claim_bus (slave->dev);
@@ -107,6 +131,18 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,return dm_spi_xfer (slave->dev, bitlen, dout, din, flags); } +bool spi_is_flash_command_supported (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return dm_spi_is_flash_command_supported (slave->dev, cmd); +} + +int spi_exec_flash_command (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return dm_spi_exec_flash_command (slave->dev, cmd); +} +#if !CONFIG_IS_ENABLED (OF_PLATDATA )static int spi_child_post_bind (struct udevice *dev) {
@@ -144,6 +180,10 @@ static int spi_post_probe(struct udevice *bus) ops->set_mode += gd->reloc_off;if (ops->cs_info) ops->cs_info += gd->reloc_off; +if (ops->is_flash_command_supported) + ops->is_flash_command_supported += gd->reloc_off; +if (ops->exec_flash_command) + ops->exec_flash_command += gd->reloc_off;#endif return 0 ;
drivers/spi/spi.c +13 -0
@@ -5,6 +5,7 @@*/ #include <common.h> +#include <errno.h> #include <fdtdec.h> #include <malloc.h> #include <spi.h>
@@ -58,3 +59,15 @@ struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum, return spi_setup_slave(busnum, cs, max_hz, mode); }#endif + +__weak bool spi_is_flash_command_supported (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return false; +} + +__weak int spi_exec_flash_command (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return -EINVAL ; +}
include/spi.h +168 -0
198 lines not on this page · raw message
Signature · 1 line
2.13.0
PATCH v3 1/8 spi: add support of SPI flash commands
Quoted 5 lines · Wenyou Yang
From: Cyrille Pitchen <[email protected]>
This patch introduces 'struct
spi_flash_command' and functionsspi_is_flash_command_supported()/spi_exec_flash_command().
Answer for why this shouldn't be part of SPI area.
[snip]
drivers/spi and include/spi.h is Generic SPI area code - this can deal all connected slave devices like EEPROM, SPI-NOR etc drivers/mtd/spi and include/spi_flash.h is SPI-Flash or SPI-NOR code - this can handle only SPI flashes.
Quoted 33 lines
drivers/spi/spi-uclass.c +25
-0+bool dm_spi_is_flash_command_supported (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->is_flash_command_supported) +return ops->is_flash_command_supported (dev, cmd); + +return false; +} + +int dm_spi_exec_flash_command (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->exec_flash_command) +return ops->exec_flash_command (dev, cmd); + +return -EINVAL ; +} +int spi_claim_bus (struct spi_slave *slave) {return dm_spi_claim_bus (slave->dev);@@ -107,6 +131,18 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,return dm_spi_xfer (slave->dev, bitlen, dout, din, flags); } +bool spi_is_flash_command_supported(struct spi_slave *slave,
drivers/spi/spi-uclass.c int spi_xfer(struct spi_slave *slave, unsigned int bitlen, · line 144
Quoted 10 lines
drivers/spi/spi-uclass.c +10
-0+ const struct spi_flash_command *cmd) +{ +return dm_spi_is_flash_command_supported (slave->dev, cmd); +} + +int spi_exec_flash_command (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return dm_spi_exec_flash_command (slave->dev, cmd); +}
Handling spi-flash stuff in spi core is not proper way of dealing, and I saw these functions are not-at-all needed for generic controller drivers in drivers/spi except the Atmel QSPI driver (in v3,8/8).
Quoted 84 lines
drivers/spi/spi-uclass.c +5
-0+#if !CONFIG_IS_ENABLED (OF_PLATDATA )static int spi_child_post_bind (struct udevice *dev) {@@ -144,6 +180,10 @@ static int spi_post_probe(struct udevice *bus) ops->set_mode += gd->reloc_off;if (ops->cs_info) ops->cs_info += gd->reloc_off; +if (ops->is_flash_command_supported) + ops->is_flash_command_supported += gd->reloc_off; +if (ops->exec_flash_command) + ops->exec_flash_command += gd->reloc_off;#endif return 0 ;drivers/spi/spi.c +13
-0@@ -5,6 +5,7 @@*/ #include <common.h> +#include <errno.h> #include <fdtdec.h> #include <malloc.h> #include <spi.h> @@ -58,3 +59,15 @@ struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum, return spi_setup_slave(busnum, cs, max_hz, mode); }#endif + +__weak bool spi_is_flash_command_supported (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return false; +} + +__weak int spi_exec_flash_command (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return -EINVAL ; +}include/spi.h +26
-0@@ -10,6 +10,8 @@#ifndef _SPI_H_#define _SPI_H_ +#include <linux/string.h> /* memset() */ +/* SPI mode flags */ #define SPI_CPHA BIT(0)/* clock phase */ #define SPI_CPOL BIT(1)/* clock polarity */ @@ -64,6 +66,116 @@ struct dm_spi_slave_platdata {#endif /* CONFIG_DM_SPI */ /** +* enum spi_flash_protocol - SPI flash command protocol +*/ +#define SPI_FPROTO_INST_SHIFT 16 +#define SPI_FPROTO_INST_MASK GENMASK(23, 16) +#define SPI_FPROTO_INST (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_INST_SHIFT) & \ + SPI_FPROTO_INST_MASK) + +#define SPI_FPROTO_ADDR_SHIFT 8 +#define SPI_FPROTO_ADDR_MASK GENMASK(15, 8) +#define SPI_FPROTO_ADDR (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_ADDR_SHIFT) & \ + SPI_FPROTO_ADDR_MASK) + +#define SPI_FPROTO_DATA_SHIFT 0 +#define SPI_FPROTO_DATA_MASK GENMASK(7, 0) +#define SPI_FPROTO_DATA (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_DATA_SHIFT) & \ + SPI_FPROTO_DATA_MASK) + +#define SPI_FPROTO (inst_nbits, addr_nbits, data_nbits) \ + (SPI_FPROTO_INST(inst_nbits) | \ + SPI_FPROTO_ADDR(addr_nbits) | \ + SPI_FPROTO_DATA(data_nbits))
include/spi.h struct dm_spi_slave_platdata { · line 102
Quoted 10 lines
include/spi.h +10
-0+ +enum spi_flash_protocol { +SPI_FPROTO_1_1_1 =SPI_FPROTO (1 ,1 ,1 ), +SPI_FPROTO_1_1_2 =SPI_FPROTO (1 ,1 ,2 ), +SPI_FPROTO_1_1_4 =SPI_FPROTO (1 ,1 ,4 ), +SPI_FPROTO_1_2_2 =SPI_FPROTO (1 ,2 ,2 ), +SPI_FPROTO_1_4_4 =SPI_FPROTO (1 ,4 ,4 ), +SPI_FPROTO_2_2_2 =SPI_FPROTO (2 ,2 ,2 ), +SPI_FPROTO_4_4_4 =SPI_FPROTO (4 ,4 ,4 ), +};
these protocol also includes IO's like dual and quad and IO's which are specific for SPI-NOR flash and not Generic SPI protocols.
Quoted 46 lines
include/spi.h +46
-0+ +static inline +u8 spi_flash_protocol_get_inst_nbits (enum spi_flash_protocol proto) +{ +return ((unsigned long )(proto &SPI_FPROTO_INST_MASK )) >> +SPI_FPROTO_INST_SHIFT ; +} + +static inline +u8 spi_flash_protocol_get_addr_nbits (enum spi_flash_protocol proto) +{ +return ((unsigned long )(proto &SPI_FPROTO_ADDR_MASK )) >> +SPI_FPROTO_ADDR_SHIFT ; +} + +static inline +u8 spi_flash_protocol_get_data_nbits (enum spi_flash_protocol proto) +{ +return ((unsigned long )(proto &SPI_FPROTO_DATA_MASK )) >> +SPI_FPROTO_DATA_SHIFT ; +} + +/** +* struct spi_flash_command - SPI flash command structure +* +* @instr: Opcode sent to the SPI slave during instr clock cycles. +* @mode: Value sent to the SPI slave during mode clock cycles. +* @num_mode_cycles: Number of mode clock cycles. +* @num_wait_states: Number of wait-state clock cycles. +* @addr_len: Number of bytes sent during address clock cycles: +* should be 0, 3, or 4. +* @addr: Value sent to the SPI slave during address clock cycles. +* @data_len: Number of bytes to be sent during data clock cycles. +* @tx_data: Data sent to the SPI slave during data clock cycles. +* @rx_data: Data read from the SPI slave during data clock cycles. +*/ +struct spi_flash_command { +enum spi_flash_protocol proto; +u8 flags; +#define SPI_FCMD_TYPE GENMASK(2, 0) +#define SPI_FCMD_READ (0x0U << 0) +#define SPI_FCMD_WRITE (0x1U << 0) +#define SPI_FCMD_ERASE (0x2U << 0) +#define SPI_FCMD_READ_REG (0x3U << 0) +#define SPI_FCMD_WRITE_REG (0x4U << 0) +
include/spi.h struct dm_spi_slave_platdata { · line 158
Quoted 10 lines
include/spi.h +10
-0+u8 inst; +u8 mode; +u8 num_mode_cycles; +u8 num_wait_states; +u8 addr_len; +u32 addr; +size_t data_len; +const void *tx_data; +void *rx_data; +};
I saw from the other patches, this structure is initializing for each I/O interface between SPI to driver/mtd like spi_transfer, if so it shouldn't have flash attributes. Better to move flash contents to spi_flash structure and do the respective operations.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
PATCH v3 1/8 spi: add support of SPI flash commands
Hi Jagan,
Thank you for your comments.
I will rework this patch set according to your advice. Thank you!
Best Regards,
Wenyou Yang
Quoted 222 lines
-----Original Message-----
From: Jagan Teki [mailto:jagannadh.teki at gmail.com]
Sent: 2017年8月30日 21:50
To: Wenyou Yang - A41535 <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Marek Vasut <[email protected]>; Cyrille Pitchen <[email protected]>; Jagan Teki <[email protected]>
Subject: Re: [U-Boot] [PATCH v3 1/8] spi: add support of SPI flash commandsQuoted 5 lines · Wenyou Yang
From: Cyrille Pitchen <[email protected]>
This patch introduces 'struct
spi_flash_command' and functionsspi_is_flash_command_supported()/spi_exec_flash_command().Answer for why this shouldn't be part of SPI area.
[snip]
drivers/spiandinclude/spi.his Generic SPI area code - this can deal all connected slave devices like EEPROM, SPI-NOR etcdrivers/mtd/spiandinclude/spi_flash.his SPI-Flash or SPI-NOR code - this can handle only SPI flashes.Quoted 29 lines
drivers/spi/spi-uclass.c +23
-0+bool dm_spi_is_flash_command_supported (struct udevice *dev, +const struct spi_flash_command +*cmd) { +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->is_flash_command_supported) +return ops->is_flash_command_supported (dev, cmd); + +return false; +} + +int dm_spi_exec_flash_command (struct udevice *dev, +const struct spi_flash_command *cmd) { +struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (ops->exec_flash_command) +return ops->exec_flash_command (dev, cmd); + +return -EINVAL ; +} +int spi_claim_bus (struct spi_slave *slave) { return dm_spi_claim_bus(slave->dev); @@ -107,6 +131,18 @@ intspi_xfer(struct
spi_slave*slave, unsigned int bitlen,return dm_spi_xfer(slave->dev, bitlen, dout, din, flags); }Review
Quoted 8 lines
(quoted diff) +8
-0+bool spi_is_flash_command_supported(struct spi_slave *slave, + const struct spi_flash_command +*cmd) { + return dm_spi_is_flash_command_supported(slave->dev, cmd); } + +int spi_exec_flash_command(struct spi_slave *slave, + const struct spi_flash_command *cmd) { + return dm_spi_exec_flash_command(slave->dev, cmd); }Handling spi-flash stuff in spi core is not proper way of dealing, and I saw these functions are not-at-all needed for generic controller drivers in
drivers/spiexcept the Atmel QSPI driver (in v3,8/8).drivers/spi/spi.c struct spi_slave *spi_base_setup_slave_fdt(const void
Quoted 27 lines
drivers/spi/spi-uclass.c +6
-0+#if !CONFIG_IS_ENABLED (OF_PLATDATA ) static int spi_child_post_bind(struct udevice *dev) { @@ -144,6 +180,10 @@ static int spi_post_probe(struct udevice *bus) ops->set_mode += gd->reloc_off;if (ops->cs_info) ops->cs_info += gd->reloc_off; +if (ops->is_flash_command_supported) + ops->is_flash_command_supported += gd->reloc_off; +if (ops->exec_flash_command) + ops->exec_flash_command += gd->reloc_off;#endif return 0 ;drivers/spi/spi.c index renamed from drivers/spi/spi.c +0
-0
7d81fbd7f8..e47acdc9e4100644drivers/spi/spi.c +1
-0@@ -5,6 +5,7 @@*/ #include <common.h> +#include <errno.h> #include <fdtdec.h> #include <malloc.h> #include <spi.h> @@ -58,3 +59,15 @@ struct spi_slave *spi_base_setup_slave_fdt(const void*blob, int busnum,
Quoted 52 lines
drivers/spi/spi.c +12
-0return spi_setup_slave (busnum, cs, max_hz, mode); }#endif + +__weak bool spi_is_flash_command_supported (struct spi_slave *slave, +const struct +spi_flash_command *cmd) { +return false; +} + +__weak int spi_exec_flash_command (struct spi_slave *slave, +const struct spi_flash_command *cmd) +{ +return -EINVAL ; +}include/spi.h index renamed from include/spi.h +0
-0
8c4b882c54..a090266b52100644include/spi.h +2
-0@@ -10,6 +10,8 @@#ifndef _SPI_H_#define _SPI_H_ +#include <linux/string.h> /* memset() */ +/* SPI mode flags */ #define SPI_CPHA BIT(0)/* clock phase */ #define SPI_CPOL BIT(1)/* clock polarity */ @@ -64,6 +66,116 @@ struct dm_spi_slave_platdata { #endif /*
CONFIG_DM_SPI*//**
+ * enumspi_flash_protocol- SPI flash command protocol */ #defineinclude/spi.h +21
-0+SPI_FPROTO_INST_SHIFT 16 +#define SPI_FPROTO_INST_MASK GENMASK(23, 16) +#define SPI_FPROTO_INST (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_INST_SHIFT) & \ + SPI_FPROTO_INST_MASK) + +#define SPI_FPROTO_ADDR_SHIFT 8 +#define SPI_FPROTO_ADDR_MASK GENMASK(15, 8) +#define SPI_FPROTO_ADDR (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_ADDR_SHIFT) & \ + SPI_FPROTO_ADDR_MASK) + +#define SPI_FPROTO_DATA_SHIFT 0 +#define SPI_FPROTO_DATA_MASK GENMASK(7, 0) +#define SPI_FPROTO_DATA (nbits) \ + ((((unsigned long)(nbits)) << SPI_FPROTO_DATA_SHIFT) & \ + SPI_FPROTO_DATA_MASK) + +#define SPI_FPROTO (inst_nbits, addr_nbits, data_nbits) \ + (SPI_FPROTO_INST(inst_nbits) | \ + SPI_FPROTO_ADDR(addr_nbits) | \include/spi.h struct dm_spi_slave_platdata {
Quoted 10 lines
include/spi.h +10
-0+ SPI_FPROTO_DATA(data_nbits)) + +enum spi_flash_protocol { +SPI_FPROTO_1_1_1 =SPI_FPROTO (1 ,1 ,1 ), +SPI_FPROTO_1_1_2 =SPI_FPROTO (1 ,1 ,2 ), +SPI_FPROTO_1_1_4 =SPI_FPROTO (1 ,1 ,4 ), +SPI_FPROTO_1_2_2 =SPI_FPROTO (1 ,2 ,2 ), +SPI_FPROTO_1_4_4 =SPI_FPROTO (1 ,4 ,4 ), +SPI_FPROTO_2_2_2 =SPI_FPROTO (2 ,2 ,2 ), +SPI_FPROTO_4_4_4 =SPI_FPROTO (4 ,4 ,4 ), };these protocol also includes IO's like dual and quad and IO's which are specific for SPI-NOR flash and not Generic SPI protocols.
Quoted 40 lines
include/spi.h +40
-0+ +static inline +u8 spi_flash_protocol_get_inst_nbits (enum spi_flash_protocol proto) { +return ((unsigned long )(proto &SPI_FPROTO_INST_MASK )) >> +SPI_FPROTO_INST_SHIFT ; } + +static inline +u8 spi_flash_protocol_get_addr_nbits (enum spi_flash_protocol proto) { +return ((unsigned long )(proto &SPI_FPROTO_ADDR_MASK )) >> +SPI_FPROTO_ADDR_SHIFT ; } + +static inline +u8 spi_flash_protocol_get_data_nbits (enum spi_flash_protocol proto) { +return ((unsigned long )(proto &SPI_FPROTO_DATA_MASK )) >> +SPI_FPROTO_DATA_SHIFT ; } + +/** +* struct spi_flash_command - SPI flash command structure +* +* @instr: Opcode sent to the SPI slave during instr clock cycles. +* @mode: Value sent to the SPI slave during mode clock cycles. +* @num_mode_cycles: Number of mode clock cycles. +* @num_wait_states: Number of wait-state clock cycles. +* @addr_len: Number of bytes sent during address clock cycles: +* should be 0, 3, or 4. +* @addr: Value sent to the SPI slave during address clock cycles. +* @data_len: Number of bytes to be sent during data clock cycles. +* @tx_data: Data sent to the SPI slave during data clock cycles. +* @rx_data: Data read from the SPI slave during data clock cycles. +*/ +struct spi_flash_command { +enum spi_flash_protocol proto; +u8 flags; +#define SPI_FCMD_TYPE GENMASK(2, 0) +#define SPI_FCMD_READ (0x0U << 0) +#define SPI_FCMD_WRITE (0x1U << 0) +#define SPI_FCMD_ERASE (0x2U << 0) +#define SPI_FCMD_READ_REG (0x3U << 0) +#define SPI_FCMD_WRITE_REG (0x4U << 0) +include/spi.h struct dm_spi_slave_platdata { · line 158
Quoted 10 lines
include/spi.h +10
-0+u8 inst; +u8 mode; +u8 num_mode_cycles; +u8 num_wait_states; +u8 addr_len; +u32 addr; +size_t data_len; +const void *tx_data; +void *rx_data; +};I saw from the other patches, this structure is initializing for each I/O interface between SPI to driver/mtd like
spi_transfer, if so it shouldn't have flash attributes. Better to move flash contents tospi_flashstructure and do the respective operations.thanks!
--
Jagan Teki
Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
PATCH v3 2/8 sf: describe all SPI flash commands with 'struct spi_flash_command'
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
Now that the SPI sub-system API has been extended with 'struct spi_flash_command' and spi_is_flash_command_supported() / spi_exec_flash_command() functions, we update the SPI FLASH sub-system to use this new API.
---
Changes in v3: None
Changes in v2: None
drivers/mtd/spi/sf.c | 78 +++++++++++++---- drivers/mtd/spi/sf_dataflash.c | 119 +++++++++++++------------- drivers/mtd/spi/sf_internal.h | 24 +++--- drivers/mtd/spi/spi_flash.c | 184 +++++++++++++++++++++++------------------ 4 files changed, 236 insertions(+), 169 deletions(-)
drivers/mtd/spi/sf.c +60 -18
@@ -9,46 +9,88 @@#include <common.h> #include <spi.h> +#include <spi_flash.h> -static int spi_flash_read_write (struct spi_slave *spi, -const u8 *cmd,size_t cmd_len, -const u8 *data_out,u8 *data_in, -size_t data_len) +#include "sf_internal.h" + +static void spi_flash_addr (u32 addr,u8 addr_len,u8 *cmd_buf) { +u8 i; + +for (i =0 ; i < addr_len; i++) + cmd_buf[i] = addr >> ((addr_len -1 - i) *8 ); +} + +static u8 spi_compute_num_dummy_bytes (enum spi_flash_protocol proto, +u8 num_dummy_clock_cycles) +{ +int shift =fls (spi_flash_protocol_get_addr_nbits (proto)) -1 ; + +if (shift <0 ) + shift =0 ; +return (num_dummy_clock_cycles << shift) >>3 ; +} + +static int spi_flash_exec (struct spi_flash *flash, +const struct spi_flash_command *cmd) +{ +struct spi_slave *spi = flash->spi; +u8 cmd_buf[SPI_FLASH_CMD_LEN ]; +size_t cmd_len, num_dummy_bytes;unsigned long flags =SPI_XFER_BEGIN ;int ret; -if (data_len ==0 ) +if (spi_is_flash_command_supported (spi, cmd)) +return spi_exec_flash_command (spi, cmd); + +if (cmd->data_len ==0 ) flags |=SPI_XFER_END ; - ret =spi_xfer (spi, cmd_len *8 , cmd,NULL , flags); + cmd_buf[0 ] = cmd->inst; +spi_flash_addr (cmd->addr, cmd->addr_len, cmd_buf +1 ); + cmd_len =1 + cmd->addr_len; + + num_dummy_bytes =spi_compute_num_dummy_bytes (cmd->proto, + cmd->num_mode_cycles + + cmd->num_wait_states); +memset (cmd_buf + cmd_len,0xff , num_dummy_bytes); + cmd_len += num_dummy_bytes; + + ret =spi_xfer (spi, cmd_len *8 , cmd_buf,NULL , flags);if (ret) {debug ("SF: Failed to send command (%zu bytes): %d\n" , cmd_len, ret); - }else if (data_len !=0 ) { - ret =spi_xfer (spi, data_len *8 , data_out, data_in, -SPI_XFER_END ); + }else if (cmd->data_len !=0 ) { + ret =spi_xfer (spi, cmd->data_len *8 , + cmd->tx_data, cmd->rx_data, +SPI_XFER_END );if (ret)debug ("SF: Failed to transfer %zu bytes of data: %d\n" , - data_len, ret); + cmd->data_len, ret); }return ret; } -int spi_flash_cmd_read (struct spi_slave *spi,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len) +int spi_flash_cmd_read (struct spi_flash *flash, +const struct spi_flash_command *cmd) { -return spi_flash_read_write (spi, cmd, cmd_len,NULL , data, data_len); +return spi_flash_exec (flash, cmd); } -int spi_flash_cmd (struct spi_slave *spi,u8 cmd,void *response,size_t len) +int spi_flash_cmd (struct spi_flash *flash,u8 instr,void *response,size_t len) { -return spi_flash_cmd_read (spi, &cmd,1 , response, len); +struct spi_flash_command cmd; +u8 flags = (response && len) ?SPI_FCMD_READ_REG :SPI_FCMD_WRITE_REG ; + +spi_flash_command_init (&cmd, instr,0 , flags); + cmd.data_len = len; + cmd.rx_data = response; +return spi_flash_exec (flash, &cmd); } -int spi_flash_cmd_write (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, -const void *data,size_t data_len) +int spi_flash_cmd_write (struct spi_flash *flash, +const struct spi_flash_command *cmd) { -return spi_flash_read_write (spi, cmd, cmd_len, data,NULL , data_len); +return spi_flash_exec (flash, cmd); }
drivers/mtd/spi/sf_dataflash.c +61 -58
294 lines not on this page · raw message
drivers/mtd/spi/sf_internal.h +12 -12
@@ -27,7 +27,7 @@ enum spi_nor_option_flags { };#define SPI_FLASH_3B_ADDR_LEN 3 -#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN) +#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN + 16)#define SPI_FLASH_16MB_BOUN 0x1000000/* CFI Manufacture ID's */
@@ -137,21 +137,21 @@ struct spi_flash_info {extern const struct spi_flash_info spi_flash_ids[];/* Send a single-byte command to the device and read the response */ -int spi_flash_cmd (struct spi_slave *spi,u8 cmd,void *response,size_t len); +int spi_flash_cmd (struct spi_flash *flash,u8 instr,void *response,size_t len);/* * Send a multi-byte command to the device and read the response. Used * for flash array reads, etc. */ -int spi_flash_cmd_read (struct spi_slave *spi,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len); +int spi_flash_cmd_read (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* * Send a multi-byte command to the device followed by (optional) * data. Used for programming the flash array, etc. */ -int spi_flash_cmd_write (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, -const void *data,size_t data_len); +int spi_flash_cmd_write (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* Flash erase(sectors) operation, support all possible erase commands */
@@ -169,13 +169,13 @@ int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len);/* Enable writing on the SPI flash */ static inline int spi_flash_cmd_write_enable (struct spi_flash *flash) { -return spi_flash_cmd (flash->spi,CMD_WRITE_ENABLE ,NULL ,0 ); +return spi_flash_cmd (flash,CMD_WRITE_ENABLE ,NULL ,0 ); }/* Disable writing on the SPI flash */ static inline int spi_flash_cmd_write_disable (struct spi_flash *flash) { -return spi_flash_cmd (flash->spi,CMD_WRITE_DISABLE ,NULL ,0 ); +return spi_flash_cmd (flash,CMD_WRITE_DISABLE ,NULL ,0 ); }/*
@@ -186,8 +186,8 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)* - spi_flash_wait_till_ready * - SPI release */ -int spi_flash_write_common (struct spi_flash *flash,const u8 *cmd, -size_t cmd_len,const void *buf,size_t buf_len); +int spi_flash_write_common (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* * Flash write operation, support all possible write commands.
@@ -201,8 +201,8 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,* Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation. */ -int spi_flash_read_common (struct spi_flash *flash,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len); +int spi_flash_read_common (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* Flash read operation, support all possible read commands */ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
drivers/mtd/spi/spi_flash.c +103 -81
397 lines not on this page · raw message
Signature · 1 line
2.13.0
PATCH v3 2/8 sf: describe all SPI flash commands with 'struct spi_flash_command'
Quoted 545 lines · Wenyou Yang
From: Cyrille Pitchen <[email protected]>
Now that the SPI sub-system API has been extended with 'struct
spi_flash_command' andspi_is_flash_command_supported()/spi_exec_flash_command()functions, we update the SPI FLASH sub-system to use this new API.Signed-off-by Cyrille Pitchen <[email protected]>Signed-off-by Wenyou Yang <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/mtd/spi/sf.c | 78 +++++++++++++---- drivers/mtd/spi/sf_dataflash.c | 119 +++++++++++++------------- drivers/mtd/spi/sf_internal.h | 24 +++--- drivers/mtd/spi/spi_flash.c | 184 +++++++++++++++++++++++------------------ 4 files changed, 236 insertions(+), 169 deletions(-)drivers/mtd/spi/sf.c +60
-18@@ -9,46 +9,88 @@#include <common.h> #include <spi.h> +#include <spi_flash.h> -static int spi_flash_read_write (struct spi_slave *spi, -const u8 *cmd,size_t cmd_len, -const u8 *data_out,u8 *data_in, -size_t data_len) +#include "sf_internal.h" + +static void spi_flash_addr (u32 addr,u8 addr_len,u8 *cmd_buf) { +u8 i; + +for (i =0 ; i < addr_len; i++) + cmd_buf[i] = addr >> ((addr_len -1 - i) *8 ); +} + +static u8 spi_compute_num_dummy_bytes (enum spi_flash_protocol proto, +u8 num_dummy_clock_cycles) +{ +int shift =fls (spi_flash_protocol_get_addr_nbits (proto)) -1 ; + +if (shift <0 ) + shift =0 ; +return (num_dummy_clock_cycles << shift) >>3 ; +} + +static int spi_flash_exec (struct spi_flash *flash, +const struct spi_flash_command *cmd) +{ +struct spi_slave *spi = flash->spi; +u8 cmd_buf[SPI_FLASH_CMD_LEN ]; +size_t cmd_len, num_dummy_bytes;unsigned long flags =SPI_XFER_BEGIN ;int ret; -if (data_len ==0 ) +if (spi_is_flash_command_supported (spi, cmd)) +return spi_exec_flash_command (spi, cmd); + +if (cmd->data_len ==0 ) flags |=SPI_XFER_END ; - ret =spi_xfer (spi, cmd_len *8 , cmd,NULL , flags); + cmd_buf[0 ] = cmd->inst; +spi_flash_addr (cmd->addr, cmd->addr_len, cmd_buf +1 ); + cmd_len =1 + cmd->addr_len; + + num_dummy_bytes =spi_compute_num_dummy_bytes (cmd->proto, + cmd->num_mode_cycles + + cmd->num_wait_states); +memset (cmd_buf + cmd_len,0xff , num_dummy_bytes); + cmd_len += num_dummy_bytes; + + ret =spi_xfer (spi, cmd_len *8 , cmd_buf,NULL , flags);if (ret) {debug ("SF: Failed to send command (%zu bytes): %d\n" , cmd_len, ret); - }else if (data_len !=0 ) { - ret =spi_xfer (spi, data_len *8 , data_out, data_in, -SPI_XFER_END ); + }else if (cmd->data_len !=0 ) { + ret =spi_xfer (spi, cmd->data_len *8 , + cmd->tx_data, cmd->rx_data, +SPI_XFER_END );if (ret)debug ("SF: Failed to transfer %zu bytes of data: %d\n" , - data_len, ret); + cmd->data_len, ret); }return ret; } -int spi_flash_cmd_read (struct spi_slave *spi,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len) +int spi_flash_cmd_read (struct spi_flash *flash, +const struct spi_flash_command *cmd) { -return spi_flash_read_write (spi, cmd, cmd_len,NULL , data, data_len); +return spi_flash_exec (flash, cmd); } -int spi_flash_cmd (struct spi_slave *spi,u8 cmd,void *response,size_t len) +int spi_flash_cmd (struct spi_flash *flash,u8 instr,void *response,size_t len) { -return spi_flash_cmd_read (spi, &cmd,1 , response, len); +struct spi_flash_command cmd; +u8 flags = (response && len) ?SPI_FCMD_READ_REG :SPI_FCMD_WRITE_REG ; + +spi_flash_command_init (&cmd, instr,0 , flags); + cmd.data_len = len; + cmd.rx_data = response; +return spi_flash_exec (flash, &cmd); } -int spi_flash_cmd_write (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, -const void *data,size_t data_len) +int spi_flash_cmd_write (struct spi_flash *flash, +const struct spi_flash_command *cmd) { -return spi_flash_read_write (spi, cmd, cmd_len, data,NULL , data_len); +return spi_flash_exec (flash, cmd); }drivers/mtd/spi/sf_dataflash.c +61
-58@@ -73,7 +73,7 @@ struct dataflash { };/* Return the status of the DataFlash device */ -static inline int dataflash_status (struct spi_slave *spi) +static inline int dataflash_status (struct spi_flash *spi_flash) {int ret;u8 status;@@ -81,7 +81,7 @@ static inline int dataflash_status(struct spi_slave *spi)* NOTE: at45db321c over 25 MHz wants to write * a dummy byte after the opcode... */ - ret =spi_flash_cmd (spi,OP_READ_STATUS , &status,1 ); + ret =spi_flash_cmd (spi_flash,OP_READ_STATUS , &status,1 );return ret ? -EIO : status; }@@ -90,7 +90,7 @@ static inline int dataflash_status(struct spi_slave *spi)* This usually takes 5-20 msec or so; more for sector erase. * ready: return > 0 */ -static int dataflash_waitready (struct spi_slave *spi) +static int dataflash_waitready (struct spi_flash *spi_flash) {int status;int timeout =2 *CONFIG_SYS_HZ ;@@ -98,7 +98,7 @@ static int dataflash_waitready(struct spi_slave *spi) timebase =get_timer (0 ); do { - status = dataflash_status(spi); + status = dataflash_status(spi_flash); if (status < 0) status = 0;@@ -114,11 +114,11 @@ static int dataflash_waitready(struct spi_slave *spi)/* Erase pages of flash */ static int spi_dataflash_erase (struct udevice *dev,u32 offset,size_t len) { +struct spi_flash_command cmd;struct dataflash *dataflash;struct spi_flash *spi_flash;struct spi_slave *spi;unsigned blocksize; -uint8_t *command;uint32_t rem;int status;@@ -128,9 +128,6 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) blocksize = spi_flash->page_size <<3 ; -memset (dataflash->command,0 ,sizeof (dataflash->command)); - command = dataflash->command; -debug ("%s: erase addr=0x%x len 0x%x\n" , dev->name, offset, len);div_u64_rem (len, spi_flash->page_size, &rem);@@ -146,6 +143,8 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len)return status; } +spi_flash_command_init (&cmd,OP_ERASE_BLOCK ,SPI_FLASH_3B_ADDR_LEN , +SPI_FCMD_ERASE );while (len >0 ) {unsigned int pageaddr;int do_block;@@ -157,23 +156,24 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) do_block = (pageaddr &0x7 ) ==0 && len >= blocksize; pageaddr = pageaddr << dataflash->page_offset; - command[0 ] = do_block ?OP_ERASE_BLOCK :OP_ERASE_PAGE ; - command[1 ] = (uint8_t )(pageaddr >>16 ); - command[2 ] = (uint8_t )(pageaddr >>8 ); - command[3 ] =0 ; + cmd.inst = do_block ?OP_ERASE_BLOCK :OP_ERASE_PAGE ; + cmd.addr = pageaddr &0x00FFFF00 ;debug ("%s ERASE %s: (%x) %x %x %x [%d]\n" , dev->name, do_block ?"block" :"page" , - command[0 ], command[1 ], command[2 ], command[3 ], + cmd.inst, + (cmd.addr >>16 ) &0xff , + (cmd.addr >>8 ) &0xff , + (cmd.addr >>0 ) &0xff , pageaddr); - status =spi_flash_cmd_write (spi, command,4 ,NULL ,0 ); + status =spi_flash_cmd_write (spi_flash, &cmd);if (status <0 ) {debug ("%s: erase send command error!\n" , dev->name);return -EIO ; } - status =dataflash_waitready (spi); + status =dataflash_waitready (spi_flash);if (status <0 ) {debug ("%s: erase waitready error!\n" , dev->name);return status;@@ -202,23 +202,18 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len)static int spi_dataflash_read (struct udevice *dev,u32 offset,size_t len,void *buf) { +struct spi_flash_command cmd;struct dataflash *dataflash;struct spi_flash *spi_flash;struct spi_slave *spi;unsigned int addr; -uint8_t *command;int status; dataflash =dev_get_priv (dev); spi_flash =dev_get_uclass_priv (dev); spi = spi_flash->spi; -memset (dataflash->command,0 ,sizeof (dataflash->command)); - command = dataflash->command; - -debug ("%s: erase addr=0x%x len 0x%x\n" , dev->name, offset, len); -debug ("READ: (%x) %x %x %x\n" , - command[0 ], command[1 ], command[2 ], command[3 ]); +debug ("%s: read addr=0x%x len 0x%x\n" , dev->name, offset, len);/* Calculate flash page/byte address */ addr = (((unsigned)offset / spi_flash->page_size)@@ -236,13 +231,15 @@ static int spi_dataflash_read(struct udevice *dev, u32 offset, size_t len,* the peak rate available. Some chips support commands with * fewer "don't care" bytes. Both buffers stay unchanged. */ - command[0 ] =OP_READ_CONTINUOUS ; - command[1 ] = (uint8_t )(addr >>16 ); - command[2 ] = (uint8_t )(addr >>8 ); - command[3 ] = (uint8_t )(addr >>0 ); +spi_flash_command_init (&cmd,OP_READ_CONTINUOUS ,SPI_FLASH_3B_ADDR_LEN , +SPI_FCMD_READ ); + cmd.addr = addr; + cmd.num_wait_states =4 *8 ;/* 4 "don't care" bytes */ + cmd.data_len = len; + cmd.rx_data = buf;/* plus 4 "don't care" bytes, command len: 4 + 4 "don't care" bytes */ - status =spi_flash_cmd_read (spi, command,8 , buf, len); + status =spi_flash_cmd_read (spi_flash, &cmd);spi_release_bus (spi);@@ -258,10 +255,10 @@ static int spi_dataflash_read(struct udevice *dev, u32 offset, size_t len,int spi_dataflash_write (struct udevice *dev,u32 offset,size_t len,const void *buf) { +struct spi_flash_command cmd;struct dataflash *dataflash;struct spi_flash *spi_flash;struct spi_slave *spi; -uint8_t *command;unsigned int pageaddr, addr, to, writelen;size_t remaining = len;u_char *writebuf = (u_char *)buf;@@ -271,9 +268,6 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len, spi_flash =dev_get_uclass_priv (dev); spi = spi_flash->spi; -memset (dataflash->command,0 ,sizeof (dataflash->command)); - command = dataflash->command; -debug ("%s: write 0x%x..0x%x\n" , dev->name, offset, (offset + len)); pageaddr = ((unsigned )offset / spi_flash->page_size);@@ -289,6 +283,8 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,return status; } +spi_flash_command_init (&cmd,OP_TRANSFER_BUF1 ,SPI_FLASH_3B_ADDR_LEN , +SPI_FCMD_WRITE );while (remaining >0 ) {debug ("write @ %d:%d len=%d\n" , pageaddr, to, writelen);@@ -313,22 +309,25 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,/* (1) Maybe transfer partial page to Buffer1 */ if (writelen != spi_flash->page_size) { - command[0 ] =OP_TRANSFER_BUF1 ; - command[1 ] = (addr &0x00FF0000 ) >>16 ; - command[2 ] = (addr &0x0000FF00 ) >>8 ; - command[3 ] =0 ; + cmd.inst =OP_TRANSFER_BUF1 ; + cmd.addr = (addr &0x00FFFF00 ); + cmd.data_len =0 ; + cmd.tx_data =NULL ;debug ("TRANSFER: (%x) %x %x %x\n" , - command[0 ], command[1 ], command[2 ], command[3 ]); + cmd.inst, + (cmd.addr >>16 ) &0xff , + (cmd.addr >>8 ) &0xff , + (cmd.addr >>0 ) &0xff ); - status =spi_flash_cmd_write (spi, command,4 ,NULL ,0 ); + status =spi_flash_cmd_write (spi_flash, &cmd);if (status <0 ) {debug ("%s: write(<pagesize) command error!\n" , dev->name);return -EIO ; } - status =dataflash_waitready (spi); + status =dataflash_waitready (spi_flash);if (status <0 ) {debug ("%s: write(<pagesize) waitready error!\n" , dev->name);@@ -338,22 +337,24 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,/* (2) Program full page via Buffer1 */ addr += to; - command[0 ] =OP_PROGRAM_VIA_BUF1 ; - command[1 ] = (addr &0x00FF0000 ) >>16 ; - command[2 ] = (addr &0x0000FF00 ) >>8 ; - command[3 ] = (addr &0x000000FF ); + cmd.inst =OP_PROGRAM_VIA_BUF1 ; + cmd.addr = addr; + cmd.data_len = writelen; + cmd.tx_data = writebuf;debug ("PROGRAM: (%x) %x %x %x\n" , - command[0 ], command[1 ], command[2 ], command[3 ]); + cmd.inst, + (cmd.addr >>16 ) &0xff , + (cmd.addr >>8 ) &0xff , + (cmd.addr >>0 ) &0xff ); - status =spi_flash_cmd_write (spi, command, -4 , writebuf, writelen); + status =spi_flash_cmd_write (spi_flash, &cmd);if (status <0 ) {debug ("%s: write send command error!\n" , dev->name);return -EIO ; } - status =dataflash_waitready (spi); + status =dataflash_waitready (spi_flash);if (status <0 ) {debug ("%s: write waitready error!\n" , dev->name);return status;@@ -362,16 +363,18 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,#ifdef CONFIG_SPI_DATAFLASH_WRITE_VERIFY /* (3) Compare to Buffer1 */ addr = pageaddr << dataflash->page_offset; - command[0 ] =OP_COMPARE_BUF1 ; - command[1 ] = (addr &0x00FF0000 ) >>16 ; - command[2 ] = (addr &0x0000FF00 ) >>8 ; - command[3 ] =0 ; + cmd.inst =OP_COMPARE_BUF1 ; + cmd.addr = addr &0x00FFFF00 ; + cmd.data_len = writelen; + cmd.tx_data = writebuf;debug ("COMPARE: (%x) %x %x %x\n" , - command[0 ], command[1 ], command[2 ], command[3 ]); + cmd.inst, + (cmd.addr >>16 ) &0xff , + (cmd.addr >>8 ) &0xff , + (cmd.addr >>0 ) &0xff ); - status =spi_flash_cmd_write (spi, command, -4 , writebuf, writelen); + status =spi_flash_cmd_write (spi, &cmd);if (status <0 ) {debug ("%s: write(compare) send command error!\n" , dev->name);@@ -496,7 +499,7 @@ static struct flash_info dataflash_data[] = { { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_slave *spi) +static struct flash_info *jedec_probe (struct spi_flash *spi_flash) {int tmp;uint8_t id[5 ];@@ -513,7 +516,7 @@ static struct flash_info *jedec_probe(struct spi_slave *spi)* That's not an error; only rev C and newer chips handle it, and * only Atmel sells these chips. */ - tmp =spi_flash_cmd (spi,CMD_READ_ID , id,sizeof (id)); + tmp =spi_flash_cmd (spi_flash,CMD_READ_ID , id,sizeof (id));if (tmp <0 ) {printf ("dataflash: error %d reading JEDEC ID\n" , tmp);return ERR_PTR (tmp);@@ -532,7 +535,7 @@ static struct flash_info *jedec_probe(struct spi_slave *spi) tmp++, info++) {if (info->jedec_id == jedec) {if (info->flags &SUP_POW2PS ) { - status =dataflash_status (spi); + status =dataflash_status (spi_flash);if (status <0 ) {debug ("dataflash: status error %d\n" , status);@@ -596,7 +599,7 @@ static int spi_dataflash_probe(struct udevice *dev)* Both support the security register, though with different * write procedures. */ - info =jedec_probe (spi); + info =jedec_probe (spi_flash);if (IS_ERR (info)) goto err_jedec_probe;if (info !=NULL ) {@@ -611,7 +614,7 @@ static int spi_dataflash_probe(struct udevice *dev)* Older chips support only legacy commands, identifing * capacity using bits in the status byte. */ - status =dataflash_status (spi); + status =dataflash_status (spi_flash);if (status <=0 || status ==0xff ) {printf ("dataflash: read status error %d\n" , status);if (status ==0 || status ==0xff )drivers/mtd/spi/sf_internal.h +12
-12@@ -27,7 +27,7 @@ enum spi_nor_option_flags { };#define SPI_FLASH_3B_ADDR_LEN 3 -#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN) +#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN + 16)#define SPI_FLASH_16MB_BOUN 0x1000000/* CFI Manufacture ID's */ @@ -137,21 +137,21 @@ struct spi_flash_info {extern const struct spi_flash_info spi_flash_ids[];/* Send a single-byte command to the device and read the response */ -int spi_flash_cmd (struct spi_slave *spi,u8 cmd,void *response,size_t len); +int spi_flash_cmd (struct spi_flash *flash,u8 instr,void *response,size_t len);/* * Send a multi-byte command to the device and read the response. Used * for flash array reads, etc. */ -int spi_flash_cmd_read (struct spi_slave *spi,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len); +int spi_flash_cmd_read (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* * Send a multi-byte command to the device followed by (optional) * data. Used for programming the flash array, etc. */ -int spi_flash_cmd_write (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, -const void *data,size_t data_len); +int spi_flash_cmd_write (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* Flash erase(sectors) operation, support all possible erase commands */ @@ -169,13 +169,13 @@ int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len);/* Enable writing on the SPI flash */ static inline int spi_flash_cmd_write_enable (struct spi_flash *flash) { -return spi_flash_cmd (flash->spi,CMD_WRITE_ENABLE ,NULL ,0 ); +return spi_flash_cmd (flash,CMD_WRITE_ENABLE ,NULL ,0 ); }/* Disable writing on the SPI flash */ static inline int spi_flash_cmd_write_disable (struct spi_flash *flash) { -return spi_flash_cmd (flash->spi,CMD_WRITE_DISABLE ,NULL ,0 ); +return spi_flash_cmd (flash,CMD_WRITE_DISABLE ,NULL ,0 ); }/* @@ -186,8 +186,8 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)* - spi_flash_wait_till_ready * - SPI release */ -int spi_flash_write_common (struct spi_flash *flash,const u8 *cmd, -size_t cmd_len,const void *buf,size_t buf_len); +int spi_flash_write_common (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* * Flash write operation, support all possible write commands. @@ -201,8 +201,8 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,* Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation. */ -int spi_flash_read_common (struct spi_flash *flash,const u8 *cmd, -size_t cmd_len,void *data,size_t data_len); +int spi_flash_read_common (struct spi_flash *flash, +const struct spi_flash_command *cmd);/* Flash read operation, support all possible read commands */ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,drivers/mtd/spi/spi_flash.c +0
-8@@ -22,21 +22,15 @@DECLARE_GLOBAL_DATA_PTR ; -static void spi_flash_addr (u32 addr,u8 *cmd) -{ -/* cmd[0] is actual command */ - cmd[1 ] = addr >>16 ; - cmd[2 ] = addr >>8 ; - cmd[3 ] = addr >>0 ; -} -static int read_sr (struct spi_flash *flash,u8 *rs)
drivers/mtd/spi/spi_flash.c line 32
Quoted 10 lines
drivers/mtd/spi/spi_flash.c +4
-3{ +struct spi_flash_command cmd;int ret; -u8 cmd; - cmd =CMD_READ_STATUS ; - ret =spi_flash_read_common (flash, &cmd,1 , rs,1 ); +spi_flash_command_init (&cmd,CMD_READ_STATUS ,0 ,SPI_FCMD_READ_REG ); + cmd.data_len =1 ; + cmd.rx_data = rs;
Better to do these command initialization in sf.c just before the transfer initiate instead of doing it for each I/O operation.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
PATCH v3 3/8 sf: select the relevant SPI flash protocol for read and write commands
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
SPI controller drivers should not check the instruction op code byte to guess which SPI x-y-z protocol is to be used for Fast Read or Page Program operations.
Indeed, the op code values are not so reliable. For instance, the 32h op code is generally used for Page Program 1-1-4 operations. However Microchip SST26 memories use this 32h op code for their Page Program 1-4-4 operations. There are many other examples of those SPI flash manufacturer quirks.
Instead, the SPI FLASH sub-system now fills the 'proto' member of 'struct spi_flash_command' with flash->read_proto for Fast Read operations and flash->write_proto for Page Program operations.
---
Changes in v3:
- Add the include <spi.h> to fix build error for corvus_defconfig.
Changes in v2: None
drivers/mtd/spi/spi_flash.c | 24 ++++++++++++++++-------- include/spi_flash.h | 5 +++++ 2 files changed, 21 insertions(+), 8 deletions(-)
drivers/mtd/spi/spi_flash.c +16 -8
@@ -379,6 +379,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,spi_flash_command_init (&cmd, flash->write_cmd,SPI_FLASH_3B_ADDR_LEN ,SPI_FCMD_WRITE ); + cmd.proto = flash->write_proto;for (actual =0 ; actual < len; actual += chunk_len) { write_addr = offset;
@@ -482,6 +483,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,spi_flash_command_init (&cmd, flash->read_cmd,SPI_FLASH_3B_ADDR_LEN ,SPI_FCMD_READ ); + cmd.proto = flash->read_proto; cmd.num_wait_states = flash->dummy_byte *8 ;while (len) { read_addr = offset;
@@ -1044,24 +1046,30 @@ int spi_flash_scan(struct spi_flash *flash)/* Look for read commands */ flash->read_cmd =CMD_READ_ARRAY_FAST ; -if (spi->mode &SPI_RX_SLOW ) + flash->read_proto =SPI_FPROTO_1_1_1 ; +if (spi->mode &SPI_RX_SLOW ) { flash->read_cmd =CMD_READ_ARRAY_SLOW ; -else if (spi->mode &SPI_RX_QUAD && info->flags &RD_QUAD ) + }else if (spi->mode &SPI_RX_QUAD && info->flags &RD_QUAD ) { flash->read_cmd =CMD_READ_QUAD_OUTPUT_FAST ; -else if (spi->mode &SPI_RX_DUAL && info->flags &RD_DUAL ) + flash->read_proto =SPI_FPROTO_1_1_4 ; + }else if (spi->mode &SPI_RX_DUAL && info->flags &RD_DUAL ) { flash->read_cmd =CMD_READ_DUAL_OUTPUT_FAST ; + flash->read_proto =SPI_FPROTO_1_1_2 ; + }/* Look for write commands */ -if (info->flags &WR_QPP && spi->mode &SPI_TX_QUAD ) +if (info->flags &WR_QPP && spi->mode &SPI_TX_QUAD ) { flash->write_cmd =CMD_QUAD_PAGE_PROGRAM ; -else + flash->write_proto =SPI_FPROTO_1_1_4 ; + }else {/* Go for default supported write cmd */ flash->write_cmd =CMD_PAGE_PROGRAM ; + flash->write_proto =SPI_FPROTO_1_1_1 ; + }/* Set the quad enable bit - only for quad commands */ -if ((flash->read_cmd ==CMD_READ_QUAD_OUTPUT_FAST ) || - (flash->read_cmd ==CMD_READ_QUAD_IO_FAST ) || - (flash->write_cmd ==CMD_QUAD_PAGE_PROGRAM )) { +if (spi_flash_protocol_get_data_nbits (flash->read_proto) ==4 || +spi_flash_protocol_get_data_nbits (flash->write_proto) ==4 ) { ret =set_quad_mode (flash, info);if (ret) { debug("SF: Fail to set QEB for %02x\n",
include/spi_flash.h +5 -0
@@ -11,6 +11,7 @@#define _SPI_FLASH_H_#include <dm.h> /* Because we dereference struct udevice here */ +#include <spi.h> #include <linux/types.h> #ifndef CONFIG_SF_DEFAULT_SPEED
@@ -48,6 +49,8 @@ struct spi_slave;* @read_cmd: Read cmd - Array Fast, Extn read and quad read. * @write_cmd: Write cmd - page and quad program. * @dummy_byte: Dummy cycles for read operation. +* @read_proto: SPI x-y-z protocol for flash read ops +* @write_proto: SPI x-y-z protocol for flash write ops * @memory_map: Address of read-only SPI flash access * @flash_lock: lock a region of the SPI Flash * @flash_unlock: unlock a region of the SPI Flash
@@ -83,6 +86,8 @@ struct spi_flash {u8 read_cmd;u8 write_cmd;u8 dummy_byte; +enum spi_flash_protocol read_proto; +enum spi_flash_protocol write_proto;void *memory_map;
Signature · 1 line
2.13.0
PATCH v3 4/8 sf: differentiate Page Program 1-1-4 and 1-4-4
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
This patch simply renames the ambiguous CMD_QUAD_PAGE_PROGRAM macro into the more explicit CMD_PAGE_PROGRAM_1_1_4.
Also it defines the CMD_PAGE_PROGRAM_1_4_4 macro to the standard 38h op code.
---
Changes in v3: None
Changes in v2: None
drivers/mtd/spi/sf_internal.h | 3 ++- drivers/mtd/spi/spi_flash.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -1
@@ -48,7 +48,8 @@ enum spi_nor_option_flags {#define CMD_PAGE_PROGRAM 0x02#define CMD_WRITE_DISABLE 0x04#define CMD_WRITE_ENABLE 0x06 -#define CMD_QUAD_PAGE_PROGRAM 0x32 +#define CMD_PAGE_PROGRAM_1_1_4 0x32 +#define CMD_PAGE_PROGRAM_1_4_4 0x38/* Read commands */ #define CMD_READ_ARRAY_SLOW 0x03
drivers/mtd/spi/spi_flash.c +1 -1
@@ -1059,7 +1059,7 @@ int spi_flash_scan(struct spi_flash *flash)/* Look for write commands */ if (info->flags &WR_QPP && spi->mode &SPI_TX_QUAD ) { - flash->write_cmd =CMD_QUAD_PAGE_PROGRAM ; + flash->write_cmd =CMD_PAGE_PROGRAM_1_1_4 ; flash->write_proto =SPI_FPROTO_1_1_4 ; }else {/* Go for default supported write cmd */
Signature · 1 line
2.13.0
PATCH v3 5/8 sf: add 'addr_len' member to 'struct spi_flash'
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
This is a transitional patch to prepare the SPI FLASH sub-system to support the 4-byte address instruction set later.
For now, flash->addr_len is always set to SPI_FLASH_3B_ADDR_LEN.
---
Changes in v3: None
Changes in v2: None
drivers/mtd/spi/spi_flash.c | 13 ++++++++----- include/spi_flash.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/spi/spi_flash.c +8 -5
@@ -322,7 +322,7 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) } } -spi_flash_command_init (&cmd, flash->erase_cmd,SPI_FLASH_3B_ADDR_LEN , +spi_flash_command_init (&cmd, flash->erase_cmd, flash->addr_len,SPI_FCMD_ERASE );while (len) { erase_addr = offset;
@@ -377,7 +377,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, } } -spi_flash_command_init (&cmd, flash->write_cmd,SPI_FLASH_3B_ADDR_LEN , +spi_flash_command_init (&cmd, flash->write_cmd, flash->addr_len,SPI_FCMD_WRITE ); cmd.proto = flash->write_proto;for (actual =0 ; actual < len; actual += chunk_len) {
@@ -481,7 +481,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,return 0 ; } -spi_flash_command_init (&cmd, flash->read_cmd,SPI_FLASH_3B_ADDR_LEN , +spi_flash_command_init (&cmd, flash->read_cmd, flash->addr_len,SPI_FCMD_READ ); cmd.proto = flash->read_proto; cmd.num_wait_states = flash->dummy_byte *8 ;
@@ -529,7 +529,7 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)int ret;u8 sr =0xFFu ; -spi_flash_command_init (&cmd,CMD_SST_BP ,SPI_FLASH_3B_ADDR_LEN , +spi_flash_command_init (&cmd,CMD_SST_BP , flash->addr_len,SPI_FCMD_WRITE ); cmd.addr = offset; cmd.data_len =1 ;
@@ -580,7 +580,7 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,if (ret) goto done; -spi_flash_command_init (&cmd,CMD_SST_AAI_WP ,SPI_FLASH_3B_ADDR_LEN , +spi_flash_command_init (&cmd,CMD_SST_AAI_WP , flash->addr_len,SPI_FCMD_WRITE ); cmd.addr = offset; cmd.data_len =2 ;
@@ -1102,6 +1102,9 @@ int spi_flash_scan(struct spi_flash *flash) flash->flags |=SNOR_F_USE_FSR ;#endif +/* Set the address length */ + flash->addr_len =SPI_FLASH_3B_ADDR_LEN ; +/* Configure the BAR - discover bank cmds and read current bank */ #ifdef CONFIG_SPI_FLASH_BAR ret =read_bar (flash, info);
include/spi_flash.h +2 -0
@@ -45,6 +45,7 @@ struct spi_slave;* @bank_read_cmd: Bank read cmd * @bank_write_cmd: Bank write cmd * @bank_curr: Current flash bank +* @addr_len: Number of bytes for the address * @erase_cmd: Erase cmd 4K, 32K, 64K * @read_cmd: Read cmd - Array Fast, Extn read and quad read. * @write_cmd: Write cmd - page and quad program.
@@ -82,6 +83,7 @@ struct spi_flash {u8 bank_write_cmd;u8 bank_curr;#endif +u8 addr_len;u8 erase_cmd;u8 read_cmd;u8 write_cmd;
Signature · 1 line
2.13.0
PATCH v3 6/8 sf: add new option to support SPI flash above 16MiB
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
The patch provides an alternative method to support SPI flash size greater than 16MiB (128Mib).
Indeed using the Base Address Register (BAR) is stateful. Hence, once the BAR has been modified, if a spurious CPU reset occurs with no reset/power off at the SPI flash side, early boot loarders may try to read from offset 0 but fails because of the new BAR value.
On the other hand, using the 4-byte address instruction set is stateless. When supported by the SPI flash memory, it allows us to access memory data area above 16MiB without changing the internal state of this SPI flash memory. Then if a spirious reboot occurs, early boot loaders can still access data from offset 0.
---
Changes in v3: None
Changes in v2: None
drivers/mtd/spi/Kconfig | 16 +++++++- drivers/mtd/spi/sf_internal.h | 18 +++++++++ drivers/mtd/spi/spi_flash.c | 92 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 119 insertions(+), 7 deletions(-)
drivers/mtd/spi/Kconfig +15 -1
@@ -34,14 +34,28 @@ config SPI_FLASH If unsure, say N +choice + prompt "Support SPI flash above 16MiB" + depends on SPI_FLASH + optional + config SPI_FLASH_BAR bool "SPI flash Bank/Extended address register support" - depends on SPI_FLASH help Enable the SPI flash Bank/Extended address register support. Bank/Extended address registers are used to access the flash which has size > 16MiB in 3-byte addressing. +config SPI_FLASH_4BAIS + bool "SPI flash 4-byte address instruction set support" + help + Convert the selected 3-byte address op codes into their associated + 4-byte address op codes. Using this instruction set does not change + the internal state of the SPI flash device. + +endchoice + + config SF_DUAL_FLASH bool "SPI DUAL flash memory support" depends on SPI_FLASH
drivers/mtd/spi/sf_internal.h +18 -0
@@ -27,6 +27,7 @@ enum spi_nor_option_flags { };#define SPI_FLASH_3B_ADDR_LEN 3 +#define SPI_FLASH_4B_ADDR_LEN 4#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN + 16)#define SPI_FLASH_16MB_BOUN 0x1000000
@@ -64,6 +65,19 @@ enum spi_nor_option_flags {#define CMD_READ_CONFIG 0x35#define CMD_FLAG_STATUS 0x70 +/* 4-byte address instruction set */ +#define CMD_READ_ARRAY_SLOW_4B 0x13 +#define CMD_READ_ARRAY_FAST_4B 0x0c +#define CMD_READ_DUAL_OUTPUT_FAST_4B 0x3c +#define CMD_READ_DUAL_IO_FAST_4B 0xbc +#define CMD_READ_QUAD_OUTPUT_FAST_4B 0x6c +#define CMD_READ_QUAD_IO_FAST_4B 0xec +#define CMD_PAGE_PROGRAM_4B 0x12 +#define CMD_PAGE_PROGRAM_1_1_4_4B 0x34 +#define CMD_PAGE_PROGRAM_1_4_4_4B 0x3e +#define CMD_ERASE_4K_4B 0x21 +#define CMD_ERASE_64K_4B 0xdc +/* Bank addr access commands */ #ifdef CONFIG_SPI_FLASH_BAR # define CMD_BANKADDR_BRWR 0x17
@@ -133,6 +147,10 @@ struct spi_flash_info {#define RD_QUADIO BIT(6)/* use Quad IO Read */ #define RD_DUALIO BIT(7)/* use Dual IO Read */ #define RD_FULL (RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO) +#define NO_4BAIS BIT(8)/* +* 4-byte address instruction set +* NOT supported +*/ };extern const struct spi_flash_info spi_flash_ids[];
drivers/mtd/spi/spi_flash.c +86 -6
117 lines not on this page · raw message
Signature · 1 line
2.13.0
PATCH v3 7/8 sf: add support to Microchip SST26 QSPI memories
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
This patch adds support to Microchip SST26 QSPI memories.
Erase blocks are protected at power up and must be unlocked first before being erased then programmed.
Also, the erase block sizes are not uniform. The memory layout is uniform only for the 4K sector blocks. The 64K Block Erase (D8h) op code cannot be used as currently done by the SPI FLASH sub-system.
The 4K Sector Erase (20h) op code should be chosen instead even if CONFIG_SPI_FLASH_USE_4K_SECTORS is not set.
---
Changes in v3: None
Changes in v2: None
drivers/mtd/spi/sf_internal.h | 3 +++ drivers/mtd/spi/spi_flash.c | 36 ++++++++++++++++++++++++++++++++---- drivers/mtd/spi/spi_flash_ids.c | 5 +++++ 3 files changed, 40 insertions(+), 4 deletions(-)
drivers/mtd/spi/sf_internal.h +3 -0
@@ -104,6 +104,7 @@ enum spi_nor_option_flags {#ifdef CONFIG_SPI_FLASH_SST # define CMD_SST_BP 0x02/* Byte Program */ # define CMD_SST_AAI_WP 0xAD/* Auto Address Incr Word Program */ +# define CMD_SST_ULBPR 0x98/* Global Block Protection Unlock */ int sst_write_wp (struct spi_flash *flash,u32 offset,size_t len,const void *buf);
@@ -151,6 +152,8 @@ struct spi_flash_info {* 4-byte address instruction set * NOT supported */ +#define SECT_4K_ONLY BIT(9)/* use only CMD_ERASE_4K */ +#define SST_ULBPR BIT(10)/* use SST unlock block protection */ };extern const struct spi_flash_info spi_flash_ids[];
drivers/mtd/spi/spi_flash.c +32 -4
@@ -73,7 +73,8 @@ static int write_sr(struct spi_flash *flash, u8 ws)return 0 ; } -#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) +#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) || \ + defined(CONFIG_SPI_FLASH_SST )static int read_cr (struct spi_flash *flash,u8 *rc) {struct spi_flash_command cmd;
@@ -891,6 +892,22 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len) }#endif +#ifdef CONFIG_SPI_FLASH_SST +static int sst26_unlock (struct spi_flash *flash) +{ +struct spi_flash_command cmd; +int ret; + +spi_flash_command_init (&cmd,CMD_SST_ULBPR ,0 ,SPI_FCMD_WRITE_REG ); + ret =spi_flash_write_common (flash, &cmd); +if (ret) { +debug ("SF: SST26 is still locked (read-only)\n" ); +return ret; + } + +return 0 ; +} +#endif #ifdef CONFIG_SPI_FLASH_MACRONIX static int macronix_quad_enable (struct spi_flash *flash)
@@ -920,7 +937,8 @@ static int macronix_quad_enable(struct spi_flash *flash) }#endif -#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) +#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) ||\ + defined(CONFIG_SPI_FLASH_SST )static int spansion_quad_enable (struct spi_flash *flash) {u8 qeb_status;
@@ -981,9 +999,11 @@ static int set_quad_mode(struct spi_flash *flash,case SPI_FLASH_CFI_MFR_MACRONIX :return macronix_quad_enable (flash);#endif -#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) +#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND ) ||\ + defined(CONFIG_SPI_FLASH_SST )case SPI_FLASH_CFI_MFR_SPANSION :case SPI_FLASH_CFI_MFR_WINBOND : +case SPI_FLASH_CFI_MFR_SST :return spansion_quad_enable (flash);#endif #ifdef CONFIG_SPI_FLASH_STMICRO
@@ -1039,6 +1059,11 @@ int spi_flash_scan(struct spi_flash *flash) JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_SST)write_sr (flash,0 ); +#ifdef CONFIG_SPI_FLASH_SST +if (info->flags &SST_ULBPR ) +sst26_unlock (flash); +#endif + flash->name = info->name; flash->memory_map = spi->memory_map;
@@ -1098,7 +1123,10 @@ int spi_flash_scan(struct spi_flash *flash) flash->erase_size =4096 << flash->shift; } else#endif - { +if (info->flags &SECT_4K_ONLY ) { + flash->erase_cmd =CMD_ERASE_4K ; + flash->erase_size =4096 << flash->shift; + }else { flash->erase_cmd =CMD_ERASE_64K ; flash->erase_size = flash->sector_size; }
drivers/mtd/spi/spi_flash_ids.c +5 -0
@@ -146,6 +146,11 @@ const struct spi_flash_info spi_flash_ids[] = { {"sst25wf040", INFO(0xbf2504, 0x0, 64 * 1024, 8, SECT_4K | SST_WR) }, {"sst25wf040b", INFO(0x621613, 0x0, 64 * 1024, 8, SECT_4K) }, {"sst25wf080", INFO(0xbf2505, 0x0, 64 * 1024, 16, SECT_4K | SST_WR) }, + {"sst26vf016b", INFO(0xbf2641, 0x0, 4 * 1024, 512, SECT_4K_ONLY | SST_ULBPR | RD_FULL) }, + {"sst26vf032b", INFO(0xbf2642, 0x0, 4 * 1024, 1024, SECT_4K_ONLY | SST_ULBPR | RD_FULL) }, + {"sst26vf064b", INFO(0xbf2643, 0x0, 4 * 1024, 2048, SECT_4K_ONLY | SST_ULBPR | RD_FULL) }, + {"sst26wf040b", INFO(0xbf2654, 0x0, 4 * 1024, 128, SECT_4K_ONLY | SST_ULBPR | RD_FULL) }, + {"sst26wf080b", INFO(0xbf2658, 0x0, 4 * 1024, 256, SECT_4K_ONLY | SST_ULBPR | RD_FULL) }, #endif #ifdef CONFIG_SPI_FLASH_WINBOND /* WINBOND */ {"w25p80", INFO(0xef2014, 0x0, 64 * 1024, 16, 0) },
Signature · 1 line
2.13.0
PATCH v3 8/8 sf: add driver for Atmel QSPI controller
In reply to Wenyou YangFrom: Cyrille Pitchen <[email protected]>
This patch adds support to the Atmel Quad SPI controller.
---
Changes in v3: None
Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).
drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 ++++++++++++++++++++ 4 files changed, 581 insertions(+) create mode 100644 drivers/spi/atmel_qspi.c create mode 100644 drivers/spi/atmel_qspi.h
drivers/spi/Kconfig +7 -0
@@ -32,6 +32,13 @@ config ATH79_SPI uses driver model and requires a device tree binding to operate. please refer to doc/device-tree-bindings/spi/spi-ath79.txt. +config ATMEL_QSPI + bool "Atmel QSPI driver" + depends on ARCH_AT91 + help + Enable the Ateml Quad-SPI (QSPI) driver. This driver can only be + used to access SPI NOR flashes. + config ATMEL_SPI bool "Atmel SPI driver" depends on ARCH_AT91
drivers/spi/Makefile +1 -0
@@ -18,6 +18,7 @@ endif obj-$(CONFIG_ALTERA_SPI) += altera_spi.o obj-$(CONFIG_ATH79_SPI) += ath79_spi.o obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o +obj-$(CONFIG_ATMEL_QSPI) += atmel_qspi.o obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o obj-$(CONFIG_CADENCE_QSPI) += cadence_qspi.o cadence_qspi_apb.o obj-$(CONFIG_CF_SPI) += cf_spi.o
drivers/spi/atmel_qspi.c new file +404 -0
404 lines not on this page · raw message
drivers/spi/atmel_qspi.h new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.13.0
PATCH v3 8/8 sf: add driver for Atmel QSPI controller
Quoted 3 lines · Wenyou Yang
From: Cyrille Pitchen <[email protected]>
This patch adds support to the Atmel Quad SPI controller.
So, this is SPI flash driver not Generic SPI - the problem with these were resides at drivers/spi is entire SPI layer becomes SPI-flash oriented which is absolutely a wrong indication where SPI layer getting effected more with flash operation.
Quoted 345 lines
Signed-off-by Cyrille Pitchen <[email protected]>Signed-off-by Wenyou Yang <[email protected]>---
Changes in v3: None
Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 ++++++++++++++++++++ 4 files changed, 581 insertions(+) create mode 100644 drivers/spi/atmel_qspi.c create mode 100644 drivers/spi/atmel_qspi.hdrivers/spi/Kconfig +7
-0@@ -32,6 +32,13 @@ config ATH79_SPI uses driver model and requires a device tree binding to operate. please refer to doc/device-tree-bindings/spi/spi-ath79.txt. +config ATMEL_QSPI + bool "Atmel QSPI driver" + depends on ARCH_AT91 + help + Enable the Ateml Quad-SPI (QSPI) driver. This driver can only be + used to access SPI NOR flashes. + config ATMEL_SPI bool "Atmel SPI driver" depends on ARCH_AT91drivers/spi/Makefile +1
-0@@ -18,6 +18,7 @@ endif obj-$(CONFIG_ALTERA_SPI) += altera_spi.o obj-$(CONFIG_ATH79_SPI) += ath79_spi.o obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o +obj-$(CONFIG_ATMEL_QSPI) += atmel_qspi.o obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o obj-$(CONFIG_CADENCE_QSPI) += cadence_qspi.o cadence_qspi_apb.o obj-$(CONFIG_CF_SPI) += cf_spi.odrivers/spi/atmel_qspi.c new file +292
-0@@ -0,0 +1,404 @@ +/* +* Copyright (C) 2017 Atmel Corporation +* +* SPDX-License-Identifier: GPL-2.0+ +*/ +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <fdtdec.h> +#include <errno.h> +#include <spi.h> +#include <asm/io.h> +#include <mach/clk.h> +#include "atmel_qspi.h" + +DECLARE_GLOBAL_DATA_PTR ; + +static void atmel_qspi_memcpy_fromio (void *dst,unsigned long src,size_t len) +{ +u8 *d = (u8 *)dst; + +while (len--) { + *d++ =readb (src); + src++; + } +} + +static void atmel_qspi_memcpy_toio (unsigned long dst,const void *src, +size_t len) +{ +const u8 *s = (const u8 *)src; + +while (len--) { +writeb (*s, dst); + dst++; + s++; + } +} + +static int atmel_qspi_set_ifr_tfrtype (u8 flags,u32 *ifr) +{ +u32 ifr_tfrtype; + +switch (flags &SPI_FCMD_TYPE ) { +case SPI_FCMD_READ : + ifr_tfrtype =QSPI_IFR_TFRTYPE_READ_MEMORY ; +break ; + +case SPI_FCMD_WRITE : + ifr_tfrtype =QSPI_IFR_TFRTYPE_WRITE_MEMORY ; +break ; + +case SPI_FCMD_ERASE : +case SPI_FCMD_WRITE_REG : + ifr_tfrtype =QSPI_IFR_TFRTYPE_WRITE ; +break ; + +case SPI_FCMD_READ_REG : + ifr_tfrtype =QSPI_IFR_TFRTYPE_READ ; +break ; + +default : +return -EINVAL ; + } + + *ifr = (*ifr & ~QSPI_IFR_TFRTYPE ) | ifr_tfrtype; +return 0 ; +} + +static int atmel_qpsi_set_ifr_width (enum spi_flash_protocol proto,u32 *ifr) +{ +u32 ifr_width; + +switch (proto) { +case SPI_FPROTO_1_1_1 : + ifr_width =QSPI_IFR_WIDTH_SINGLE_BIT_SPI ; +break ; + +case SPI_FPROTO_1_1_2 : + ifr_width =QSPI_IFR_WIDTH_DUAL_OUTPUT ; +break ; + +case SPI_FPROTO_1_2_2 : + ifr_width =QSPI_IFR_WIDTH_DUAL_IO ; +break ; + +case SPI_FPROTO_2_2_2 : + ifr_width =QSPI_IFR_WIDTH_DUAL_CMD ; +break ; + +case SPI_FPROTO_1_1_4 : + ifr_width =QSPI_IFR_WIDTH_QUAD_OUTPUT ; +break ; + +case SPI_FPROTO_1_4_4 : + ifr_width =QSPI_IFR_WIDTH_QUAD_IO ; +break ; + +case SPI_FPROTO_4_4_4 : + ifr_width =QSPI_IFR_WIDTH_QUAD_CMD ; +break ; + +default : +return -EINVAL ; + } + + *ifr = (*ifr & ~QSPI_IFR_WIDTH ) | ifr_width; +return 0 ; +} + +static int atmel_qspi_xfer (struct udevice *dev,unsigned int bitlen, +const void *dout,void *din,unsigned long flags) +{ +/* This controller can only be used with SPI NOR flashes. */ +return -EINVAL ; +} + +static int atmel_qspi_set_speed (struct udevice *bus,uint hz) +{ +struct atmel_qspi_priv *aq =dev_get_priv (bus); +u32 scr, scbr, mask, new_value; + +/* Compute the QSPI baudrate */ + scbr =DIV_ROUND_UP (aq->bus_clk_rate, hz); +if (scbr >0 ) + scbr--; + + new_value =QSPI_SCR_SCBR_ (scbr); + mask =QSPI_SCR_SCBR ; + + scr =qspi_readl (aq,QSPI_SCR ); +if ((scr & mask) == new_value) +return 0 ; + + scr = (scr & ~mask) | new_value; +qspi_writel (aq,QSPI_SCR , scr); + +return 0 ; +} + +static int atmel_qspi_set_mode (struct udevice *bus,uint mode) +{ +struct atmel_qspi_priv *aq =dev_get_priv (bus); +u32 scr, mask, new_value; + + new_value = (QSPI_SCR_CPOL_ ((mode &SPI_CPOL ) !=0 ) | +QSPI_SCR_CPHA_ ((mode &SPI_CPHA ) !=0 )); + mask = (QSPI_SCR_CPOL |QSPI_SCR_CPHA ); + + scr =qspi_readl (aq,QSPI_SCR ); +if ((scr & mask) == new_value) +return 0 ; + + scr = (scr & ~mask) | new_value; +qspi_writel (aq,QSPI_SCR , scr); + +return 0 ; +} + +static bool +atmel_qspi_is_flash_command_supported (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +return true; +} + +static int atmel_qspi_exec_flash_command (struct udevice *dev, +const struct spi_flash_command *cmd) +{ +struct udevice *bus =dev_get_parent (dev); +struct atmel_qspi_priv *aq =dev_get_priv (bus); +unsigned int iar, icr, ifr; +unsigned int offset; +unsigned int imr, sr; +unsigned long memaddr; +int err; + + iar =0 ; + icr =0 ; + ifr =0 ; + + err =atmel_qspi_set_ifr_tfrtype (cmd->flags, &ifr); +if (err) +return err; + + err =atmel_qpsi_set_ifr_width (cmd->proto, &ifr); +if (err) +return err; + +/* Compute instruction parameters */ + icr |=QSPI_ICR_INST_ (cmd->inst); + ifr |=QSPI_IFR_INSTEN ; + +/* Compute address parameters. */ +switch (cmd->addr_len) { +case 4 : + ifr |=QSPI_IFR_ADDRL_32_BIT ; +/*break;*/ /* fall through the 24bit (3 byte) address case */ +case 3 : + iar = cmd->data_len ?0 : cmd->addr; + ifr |=QSPI_IFR_ADDREN ; + offset = cmd->addr; +break ; +case 0 : + offset =0 ; +break ; +default : +return -EINVAL ; + } + +/* Compute option parameters. */ +if (cmd->num_mode_cycles) { +unsigned int mode_cycle_bits, mode_bits; + + icr |=QSPI_ICR_OPT_ (cmd->mode); + ifr |=QSPI_IFR_OPTEN ; + +switch (ifr &QSPI_IFR_WIDTH ) { +case QSPI_IFR_WIDTH_SINGLE_BIT_SPI : +case QSPI_IFR_WIDTH_DUAL_OUTPUT : +case QSPI_IFR_WIDTH_QUAD_OUTPUT : + mode_cycle_bits =1 ; +break ; +case QSPI_IFR_WIDTH_DUAL_IO : +case QSPI_IFR_WIDTH_DUAL_CMD : + mode_cycle_bits =2 ; +break ; +case QSPI_IFR_WIDTH_QUAD_IO : +case QSPI_IFR_WIDTH_QUAD_CMD : + mode_cycle_bits =4 ; +break ; +default : +return -EINVAL ; + } + + mode_bits = cmd->num_mode_cycles * mode_cycle_bits; +switch (mode_bits) { +case 1 : + ifr |=QSPI_IFR_OPTL_1BIT ; +break ; + +case 2 : + ifr |=QSPI_IFR_OPTL_2BIT ; +break ; + +case 4 : + ifr |=QSPI_IFR_OPTL_4BIT ; +break ; + +case 8 : + ifr |=QSPI_IFR_OPTL_8BIT ; +break ; + +default : +return -EINVAL ; + } + } + +/* Set the number of dummy cycles. */ +if (cmd->num_wait_states) + ifr |=QSPI_IFR_NBDUM_ (cmd->num_wait_states); + +/* Set data enable. */ +if (cmd->data_len) + ifr |=QSPI_IFR_DATAEN ; + +/* Clear pending interrupts. */ + (void )qspi_readl (aq,QSPI_SR ); + +/* Set QSPI Instruction Frame registers. */ +qspi_writel (aq,QSPI_IAR , iar); +qspi_writel (aq,QSPI_ICR , icr); +qspi_writel (aq,QSPI_IFR , ifr); + +/* Skip to the final steps if there is no data. */ +if (!cmd->data_len) + goto no_data; + +/* Dummy read of QSPI_IFR to synchronize APB and AHB accesses. */ + (void )qspi_readl (aq,QSPI_IFR ); + +/* Stop here for Continuous Read. */ + memaddr = (unsigned long )(aq->membase + offset); +if (cmd->tx_data) +/* Write data. */ +atmel_qspi_memcpy_toio (memaddr, cmd->tx_data, cmd->data_len); +else if (cmd->rx_data) +/* Read data. */ +atmel_qspi_memcpy_fromio (cmd->rx_data, memaddr, cmd->data_len); + +/* Release the chip-select. */ +qspi_writel (aq,QSPI_CR ,QSPI_CR_LASTXFER );
drivers/spi/atmel_qspi.c line 302
Quoted 10 lines
drivers/spi/atmel_qspi.c new file +10
-0+ +no_data: +/* Poll INSTruction End and Chip Select Rise flags. */ + imr =QSPI_SR_INSTRE |QSPI_SR_CSR ; + sr =0 ; +while (sr != (QSPI_SR_INSTRE |QSPI_SR_CSR )) + sr |=qspi_readl (aq,QSPI_SR ) & imr; + +return 0 ; +}
From v3 1/8 comments, this can be local function where we each IO opeartions can initiate this run command.
Quoted 85 lines
drivers/spi/atmel_qspi.c new file +85
-0+ + +static const struct dm_spi_ops atmel_qspi_ops = { + .xfer = atmel_qspi_xfer, + .set_speed = atmel_qspi_set_speed, + .set_mode = atmel_qspi_set_mode, + .is_flash_command_supported = atmel_qspi_is_flash_command_supported, + .exec_flash_command = atmel_qspi_exec_flash_command, +}; + +static int atmel_qspi_enable_clk (struct udevice *bus) +{ +struct atmel_qspi_priv *aq =dev_get_priv (bus); +struct clk clk; +ulong clk_rate; +int ret; + + ret =clk_get_by_index (bus,0 , &clk); +if (ret) +return -EINVAL ; + + ret =clk_enable (&clk); +if (ret) + goto free_clock; + + clk_rate =clk_get_rate (&clk); +if (!clk_rate) { + ret = -EINVAL ; + goto free_clock; + } + + aq->bus_clk_rate = clk_rate; + +free_clock: +clk_free (&clk); + +return ret; +} + +static int atmel_qspi_probe (struct udevice *bus) +{ +const struct atmel_qspi_platdata *plat =dev_get_platdata (bus); +struct atmel_qspi_priv *aq =dev_get_priv (bus); +u32 mr; +int ret; + + ret =atmel_qspi_enable_clk (bus); +if (ret) +return ret; + + aq->regbase = plat->regbase; + aq->membase = plat->membase; + +/* Reset the QSPI controler */ +qspi_writel (aq,QSPI_CR ,QSPI_CR_SWRST ); + +/* Set the QSPI controller in Serial Memory Mode */ + mr = (QSPI_MR_NBBITS_8_BIT | +QSPI_MR_SMM_MEMORY | +QSPI_MR_CSMODE_LASTXFER ); +qspi_writel (aq,QSPI_MR , mr); + +/* Enable the QSPI controller */ +qspi_writel (aq,QSPI_CR ,QSPI_CR_QSPIEN ); + +return 0 ; +} + +static int atmel_qspi_ofdata_to_platdata (struct udevice *bus) +{ +struct atmel_qspi_platdata *plat =dev_get_platdata (bus); +const void *blob = gd->fdt_blob; +int node =dev_of_offset (bus); +u32 data[4 ]; +int ret; + + ret =fdtdec_get_int_array (blob, node,"reg" , data,ARRAY_SIZE (data)); +if (ret) { +printf ("Error: Can't get base addresses (ret=%d)!\n" , ret); +return -ENODEV ; + } + plat->regbase = (void *)data[0 ]; + plat->membase = (void *)data[2 ]; + +return 0 ;
drivers/spi/atmel_qspi.c line 397
Quoted 10 lines
drivers/spi/atmel_qspi.c new file +10
-0+} + +static const struct udevice_id atmel_qspi_ids[] = { + { .compatible ="atmel,sama5d2-qspi" }, + { } +}; + +U_BOOT_DRIVER (atmel_qspi) = { + .name ="atmel_qspi" , + .id =UCLASS_SPI ,
Summary, better to write UCLASS_SPI_FLASH driver.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
Yang
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Wenyou YangHi,
Do you have comments?
Best Regards,
Wenyou Yang
Quoted 77 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerdrivers/mtd/spi/Kconfig | 16 +- drivers/mtd/spi/sf.c | 78 ++++++-- drivers/mtd/spi/sf_dataflash.c | 119 ++++++------ drivers/mtd/spi/sf_internal.h | 48 +++-- drivers/mtd/spi/spi_flash.c | 341 +++++++++++++++++++++++---------- drivers/mtd/spi/spi_flash_ids.c | 5 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 +++++++++++++++++ drivers/spi/spi-uclass.c | 40 ++++ drivers/spi/spi.c | 13 ++ include/spi.h | 168 +++++++++++++++++ include/spi_flash.h | 7 + 14 files changed, 1226 insertions(+), 190 deletions(-)create mode 100644
drivers/spi/atmel_qspi.c
create mode 100644drivers/spi/atmel_qspi.h
Yang
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Wenyou YangHi All,
Do you have some comment on it?
Quoted 74 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerdrivers/mtd/spi/Kconfig | 16 +- drivers/mtd/spi/sf.c | 78 ++++++-- drivers/mtd/spi/sf_dataflash.c | 119 ++++++------ drivers/mtd/spi/sf_internal.h | 48 +++-- drivers/mtd/spi/spi_flash.c | 341 +++++++++++++++++++++++---------- drivers/mtd/spi/spi_flash_ids.c | 5 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 +++++++++++++++++ drivers/spi/spi-uclass.c | 40 ++++ drivers/spi/spi.c | 13 ++ include/spi.h | 168 +++++++++++++++++ include/spi_flash.h | 7 + 14 files changed, 1226 insertions(+), 190 deletions(-)
Quoted 2 lines
create mode 100644
drivers/spi/atmel_qspi.c
create mode 100644drivers/spi/atmel_qspi.h
Best Regards,
Wenyou Yang
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 3 lines · Wenyou
Hi All,
Do you have some comment on it?
Yes, Will come back.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
Yang
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Wenyou YangHi,
This patch set has been here for a long time, could you have a look and take it?
Best Regards,
Wenyou Yang
Quoted 77 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerdrivers/mtd/spi/Kconfig | 16 +- drivers/mtd/spi/sf.c | 78 ++++++-- drivers/mtd/spi/sf_dataflash.c | 119 ++++++------ drivers/mtd/spi/sf_internal.h | 48 +++-- drivers/mtd/spi/spi_flash.c | 341 +++++++++++++++++++++++---------- drivers/mtd/spi/spi_flash_ids.c | 5 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/atmel_qspi.c | 404 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/atmel_qspi.h | 169 +++++++++++++++++ drivers/spi/spi-uclass.c | 40 ++++ drivers/spi/spi.c | 13 ++ include/spi.h | 168 +++++++++++++++++ include/spi_flash.h | 7 + 14 files changed, 1226 insertions(+), 190 deletions(-)create mode 100644
drivers/spi/atmel_qspi.c
create mode 100644drivers/spi/atmel_qspi.h
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 4 lines · Wenyou
Hi,
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 8 lines · Jagan Teki
Quoted 4 lines · Wenyou
Hi,
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
Signature · 2 lines
Best regards, Marek Vasut
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 7 lines · Marek Vasut
Quoted 6 lines · Jagan Teki
Quoted 4 lines · Wenyou
Hi,
This patch set has been here for a long time, could you have a look and take it?
Quoted 8 lines
Quoted 2 lines
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review. There is nothing wrong with maintainer duties here, you must need to understand.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 5 lines · Jagan Teki
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Jagan Teki
Quoted 2 lines · Wenyou
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
You did not answer this question.
Quoted 6 lines
Quoted 3 lines
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review.
I never implied this. Rather the opposite, you claim you do some work on the SPI NOR core, yet you let this patchset rot in the list for over a month now and gave the author zero feedback.
Notifying the author about the core changes early could've prevented a lot of wasted effort on his side. Reviewing early could've prevented a lot of frustration from patches being ignored.
Quoted 2 lines
There is nothing wrong with
maintainer duties here, you must need to understand.
I disagree.
Signature · 2 lines
Best regards, Marek Vasut
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 27 lines · Marek Vasut
Quoted 5 lines · Jagan Teki
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Jagan Teki
Quoted 2 lines · Wenyou
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
You did not answer this question.
Quoted 6 lines
Quoted 3 lines
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review.
I never implied this. Rather the opposite, you claim you do some work on the SPI NOR core, yet you let this patchset rot in the list for over a month now and gave the author zero feedback.
Quoted 9 lines
Notifying the author about the core changes early could've prevented a lot of wasted effort on his side. Reviewing early could've prevented a lot of frustration from patches being ignored.
Quoted 2 lines
There is nothing wrong with
maintainer duties here, you must need to understand.I disagree.
I agree with Marek here. I found it's really hard to get feedback for SF patches in time and what I have to do is to ping again and again.
Regards,
Bin
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 32 lines · Bin Meng
Quoted 31 lines · Marek Vasut
Quoted 5 lines · Jagan Teki
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Jagan Teki
Quoted 2 lines · Wenyou
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
You did not answer this question.
Quoted 6 lines
Quoted 3 lines
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review.
I never implied this. Rather the opposite, you claim you do some work on the SPI NOR core, yet you let this patchset rot in the list for over a month now and gave the author zero feedback.
Notifying the author about the core changes early could've prevented a lot of wasted effort on his side. Reviewing early could've prevented a lot of frustration from patches being ignored.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
There is nothing wrong with
maintainer duties here, you must need to understand.I disagree.
I agree with Marek here. I found it's really hard to get feedback for SF patches in time and what I have to do is to ping again and again.
I agree that the SF side patches have got some delay recently, but ie something not intentional. SF stack is not stable as of now, so I'm working on SPI-NOR (v10)[1] the new patches for SF need to wait - please be patient.
[1] http://git.denx.de/?p=u-boot-spi.git;a=shortlog;h=refs/heads/mtd-spinor
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 39 lines · Jagan Teki
Quoted 38 lines · Bin Meng
Quoted 36 lines · Marek Vasut
Quoted 5 lines · Jagan Teki
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Jagan Teki
Quoted 2 lines · Wenyou
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
You did not answer this question.
Quoted 6 lines
Quoted 3 lines
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review.
I never implied this. Rather the opposite, you claim you do some work on the SPI NOR core, yet you let this patchset rot in the list for over a month now and gave the author zero feedback.
Notifying the author about the core changes early could've prevented a lot of wasted effort on his side. Reviewing early could've prevented a lot of frustration from patches being ignored.
Quoted 2 lines
There is nothing wrong with
maintainer duties here, you must need to understand.I disagree.
Quoted 7 lines
Quoted 2 lines
I agree with Marek here. I found it's really hard to get feedback for SF patches in time and what I have to do is to ping again and again.
I agree that the SF side patches have got some delay recently, but ie something not intentional. SF stack is not stable as of now, so I'm working on SPI-NOR (v10)[1] the new patches for SF need to wait - please be patient.
What are the problems with the stack causing this instability ?
How do you plan to stabilize the stack for the current release ?
Given how complex and incomplete this patch(set) [1] is and that it's already in v10, it seems it will take a while to get it into shape in which it can be included in mainline. Blocking all other contributions because of this patchset seems wrong and hurtful to the contributors to me.
Quoted 4 lines
[1] http://git.denx.de/?p=u-boot-spi.git;a=shortlog;h=refs/heads/mtd-spinor
thanks!
Signature · 2 lines
Best regards, Marek Vasut
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 48 lines · Marek Vasut
Quoted 39 lines · Jagan Teki
Quoted 38 lines · Bin Meng
Quoted 36 lines · Marek Vasut
Quoted 5 lines · Jagan Teki
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Jagan Teki
Quoted 2 lines · Wenyou
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This patch set has been here for a long time, could you have a look and take it?
Yeah, I'm holding this because of my current spi-nor work. But anyway I will try to merge on coming MW If all OK.
Is your work posted somewhere or available in some git repository ?
You did not answer this question.
Quoted 6 lines
Quoted 3 lines
I don't see any reason why you should not perform your maintainer duties by reviewing/replying to an incoming patch, no matter what work you do to the subsystem though ...
I didn't write "this series holding spi-nor work" since it has some new features I'm taking time to review.
I never implied this. Rather the opposite, you claim you do some work on the SPI NOR core, yet you let this patchset rot in the list for over a month now and gave the author zero feedback.
Notifying the author about the core changes early could've prevented a lot of wasted effort on his side. Reviewing early could've prevented a lot of frustration from patches being ignored.
Quoted 2 lines
There is nothing wrong with
maintainer duties here, you must need to understand.I disagree.
Quoted 7 lines
Quoted 2 lines
I agree with Marek here. I found it's really hard to get feedback for SF patches in time and what I have to do is to ping again and again.
I agree that the SF side patches have got some delay recently, but ie something not intentional. SF stack is not stable as of now, so I'm working on SPI-NOR (v10)[1] the new patches for SF need to wait - please be patient.
Quoted 8 lines
What are the problems with the stack causing this instability ?
How do you plan to stabilize the stack for the current release ?
Given how complex and incomplete this patch(set) [1] is and that it's already in v10, it seems it will take a while to get it into shape in which it can be included in mainline. Blocking all other contributions because of this patchset seems wrong and hurtful to the contributors to me.
Yes. We cannot let a new framework block progress enabling things on our current framework. We are not at the point with spi-nor that we can say nothing else is allowed to move forward. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170826/172c6bee/attachment.sig>
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Wenyou YangHi,
Thanks for the changes.
Quoted 49 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).
Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controller
Comments:
How about writing struct spi_flash_command in spi_flash area (include/spi_flash.h)? and then write atmel_qspi with UCLASS_SPI_FLASH?
Testing:
Basic testing works fine.
Issues:
- Build issue: with zynq_microzed_defconfig drivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]
bool above_16MB;
^~~~~~~~~~ CC spl/lib/membuff.o
- issue with spi_flash_cmd_read_ops 4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len as read_len.
Will send separate patch for this.
drivers/mtd/spi/spi_flash.c +0 -0
@@ -558,13 +558,15 @@ int spi_flash_cmd_read_ops(struct spi_flash
*flash, u32 offset,
if (ret < 0)
return ret;
bank_sel = flash->bank_curr;
-#endif
remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) *
(bank_sel + 1)) - offset;
if (len < remain_len)
read_len = len;
else
read_len = remain_len;+#else
+ read_len = len;
+#endif
cmd.addr = read_addr;
cmd.data_len = read_len;thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
Yang
v3 cover sf: improve support of (Q)SPI flash memories
Hi Jagan,
Quoted 63 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 49 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controller
Quoted 4 lines
Comments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?
The spi_flash_command struct describes the relevant features of the spi controller, instead of the spi_flash device.
The purpose of patch set is used to supersede the spi_xfer() function to access the spi_flash device.
So putting it in include/spi.h is suitable, we should not move it in the spi_flash area.
Moreover, why do we write atmel_qspi with UCLASS_SPI_FLASH? It is not easy to understand.
Quoted 10 lines
Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]
boolabove_16MB;
Will send a new version to fix it. Thanks a lot.
Quoted 31 lines
^~~~~~~~~~CC
spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
drivers/mtd/spi/spi_flash.c +3
-1@@ -558,13 +558,15 @@ int spi_flash_cmd_read_ops(struct spi_flashmake *flash, u32 offset, if (ret < 0)return ret; bank_sel = flash->bank_curr; -#endif remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * (bank_sel +1 )) - offset;if (len < remain_len) read_len = len;else read_len = remain_len; +#else + read_len = len; +#endif cmd.addr = read_addr;cmd.data_len = read_len;
Quoted 1 line
thanks!
Best Regards,
Wenyou Yang
v3 cover sf: improve support of (Q)SPI flash memories
Hi Wenyou Yang,
Quoted 83 lines · Wenyou
Hi Jagan,
Quoted 67 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 50 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerQuoted 4 lines
Comments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?The
spi_flash_commandstruct describes the relevant features of the spi controller, instead of thespi_flashdevice.
The purpose of patch set is used to supersede thespi_xfer()function to access thespi_flashdevice.
So putting it ininclude/spi.his suitable, we should not move it in thespi_flasharea.
Quoted 2 lines
Moreover, why do we write
atmel_qspiwithUCLASS_SPI_FLASH? It is not easy to understand.
I will send explanation for these on respective patches, that would rather clean to understand from code point-of-view.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
Yang
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Jagan TekiQuoted 78 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 49 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~
Quoted 7 lines
CC
spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
Quoted 23 lines
drivers/mtd/spi/spi_flash.c +3
-1@@ -558,13 +558,15 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, if (ret < 0)return ret; bank_sel = flash->bank_curr; -#endif remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * (bank_sel +1 )) - offset;if (len < remain_len) read_len = len;else read_len = remain_len; +#else + read_len = len; +#endif cmd.addr = read_addr;cmd.data_len = read_len;
Quoted 1 line
thanks!
Best Regards,
Wenyou Yang
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 87 lines · Wenyou
Quoted 84 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 50 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~CC
spl/lib/membuff.o
Quoted 8 lines
Quoted 5 lines
- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
Quoted 1 line
This should not be a separate patch. Since every patch needs to pass buildman testing.
Quoted 20 lines
Quoted 20 lines
drivers/mtd/spi/spi_flash.c +3
-1@@ -558,13 +558,15 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, if (ret < 0)return ret; bank_sel = flash->bank_curr; -#endif remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * (bank_sel +1 )) - offset;if (len < remain_len) read_len = len;else read_len = remain_len; +#else + read_len = len; +#endif
Quoted 3 lines
Quoted 3 lines
drivers/mtd/spi/spi_flash.c +0
-0cmd.addr = read_addr;cmd.data_len = read_len;
Regards,
Bin
Yang
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 85 lines · Bin Meng
Quoted 83 lines · Wenyou
Quoted 81 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 49 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and QSPI controllers.
The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't know why...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 9 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.o
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
But it is not introduced by this patch set. So should be a separate patch to fix.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/mtd/spi/spi_flash.c +3
-1@@ -558,13 +558,15 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, if (ret < 0)return ret; bank_sel = flash->bank_curr; -#endif remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * (bank_sel +1 )) - offset;if (len < remain_len) read_len = len;else read_len = remain_len; +#else + read_len = len; +#endif
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
drivers/mtd/spi/spi_flash.c +0
-0cmd.addr = read_addr;cmd.data_len = read_len;Regards,
Bin
Best Regards,
Wenyou Yang
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 103 lines · Wenyou
Quoted 100 lines · Bin Meng
Quoted 97 lines · Wenyou
Quoted 93 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 52 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and
QSPI controllers.The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't
knowwhy...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 10 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write
commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
But it is not introduced by this patch set. So should be a separate patch to fix.
Do you mean the build warnings exist in current u-boot/master?
If so, Jagan can you please explain why you mention this? This is nothing related to this patch review.
Regards,
Bin
Yang
v3 cover sf: improve support of (Q)SPI flash memories
Quoted 96 lines · Bin Meng
Quoted 95 lines · Wenyou
Quoted 93 lines · Bin Meng
Quoted 91 lines · Wenyou
Quoted 89 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 51 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and
QSPI controllers.The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't
knowwhy...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 10 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write
commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
But it is not introduced by this patch set. So should be a separate patch to fix.
Do you mean the build warnings exist in current u-boot/master?
Here are two issue, one is the build warning, other is the issue with spi_flash_cmd_read_ops.
The build warning is related with this patch, I will fix it in the next version.
But the issue with spi_flash_cmd_read_ops on bank length is not related with this patch.
Quoted 6 lines
If so, Jagan can you please explain why you mention this? This is nothing related to this patch review.
Regards,
Bin
Best Regards,
Wenyou Yang
v3 cover sf: improve support of (Q)SPI flash memories
In reply to Bin MengHi Bin,
Quoted 109 lines · Bin Meng
Quoted 108 lines · Wenyou
Quoted 104 lines · Bin Meng
Quoted 91 lines · Wenyou
Quoted 88 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 52 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and
QSPI controllers.The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't
knowwhy...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 10 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write
commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.oQuoted 7 lines
Quoted 5 lines
- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
Quoted 7 lines
Quoted 2 lines
But it is not introduced by this patch set. So should be a separate patch to fix.
Do you mean the build warnings exist in current u-boot/master?
If so, Jagan can you please explain why you mention this? This is nothing related to this patch review.
Please read my previous comments, I was clearly explain the issue and diff. Issue came up this series with 4BAIS on spi_flash_cmd_read_ops
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.
v3 cover sf: improve support of (Q)SPI flash memories
Hi Jagan,
Quoted 115 lines · Jagan Teki
Hi Bin,
Quoted 112 lines · Bin Meng
Quoted 110 lines · Wenyou
Quoted 98 lines · Bin Meng
Quoted 95 lines · Wenyou
Quoted 92 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 52 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and
QSPI controllers.The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't
knowwhy...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 10 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write
commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Will send separate patch for this.
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
But it is not introduced by this patch set. So should be a separate patch to fix.
Quoted 8 lines
Quoted 4 lines
Do you mean the build warnings exist in current u-boot/master?
If so, Jagan can you please explain why you mention this? This is nothing related to this patch review.
Please read my previous comments, I was clearly explain the issue and diff. Issue came up this series with 4BAIS on
spi_flash_cmd_read_ops
So your words and Wenyou are contradictory. Wenyou claimed the warnings do not come from his patchset while you said yes. Anyway will leave you guys to resolve.
My point is: if the warnings exist in current mainline, this should be fixed as a unrelated patch. If the warnings come from this series, this should be fixed in the particular patch that introduces the warnings!
Regards,
Bin
v3 cover sf: improve support of (Q)SPI flash memories
Hi Bin,
Quoted 123 lines · Bin Meng
Hi Jagan,
Quoted 120 lines · Jagan Teki
Hi Bin,
Quoted 116 lines · Bin Meng
Quoted 103 lines · Wenyou
Quoted 100 lines · Bin Meng
Quoted 97 lines · Wenyou
Quoted 93 lines · Jagan Teki
Hi,
Thanks for the changes.
Quoted 52 lines · Wenyou Yang
This series of patches are based and have been tested on the 'master' branch of the u-boot.git tree.
Tests were passed with a sama5d2 xplained board which embeds both SPI and
QSPI controllers.The following tests have been passed:
- QSPI0 + Macronix MX25L25673G:
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-4 at offset0x10000: OK
The Macronix datasheet tells that only Page Program 1-4-4 is supported, not Page Program 1-1-4, however it worked, I don't
knowwhy...- QSPI0 + Microchip SST26
+ probe: OK
+ Fast Read 1-1-4 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK
SST26 memories support Page Program 1-4-4 but with the op code of Page Program 1-1-4, which is not standard so I don't use it.- QSPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x10000(u-boot env): OK
+ Page Program 1-1-1 at offset0x10000: OK- SPI0 + Adesto AT25DF321A
+ probe: OK
+ Fast Read 1-1-1 at offset0x6000(u-boot env): OK
+ Page Program 1-1-1 at offest0x6000: OK- SPI1 + Atmel AT45
+ probe: OK
+ Read at offset 0 and other than 0: OK
+ Write at offset 0 and other than 0: OKDuring my tests, I used:
- setenv/saveenv, reboot, printenv
or
- sf probe, sf read, sf write, sf erase and sf update.Changes in v3:
- Add the include <spi.h> to fix build error forcorvus_defconfig.Changes in v2:
- Rebase on the latest u-boot/master(2710d54f5).Quoted 10 lines
Cyrille Pitchen (8):
spi: add support of SPI flash commands
sf: describe all SPI flash commands with 'structspi_flash_command'
sf: select the relevant SPI flash protocol for read and write
commands
sf: differentiate Page Program 1-1-4 and 1-4-4
sf: add 'addr_len' member to 'structspi_flash'
sf: add new option to support SPI flash above 16MiB
sf: add support to Microchip SST26 QSPI memories
sf: add driver for Atmel QSPI controllerComments:
How about writing structspi_flash_commandinspi_flasharea (include/spi_flash.h)? and then writeatmel_qspiwithUCLASS_SPI_FLASH?Testing:
Basic testing works fine.Issues:
- Build issue: withzynq_microzed_defconfigdrivers/mtd/spi/spi_flash.c: In function ‘spi_flash_scan’:drivers/mtd/spi/spi_flash.c:1049:7: warning: variable ‘above_16MB’ set but not used [-Wunused-but-set-variable]bool above_16MB; ^~~~~~~~~~ CC spl/lib/membuff.o- issue with
spi_flash_cmd_read_ops4BAIS
Need to calculate bank length only if BAR is in use. Otherwise, consider the given len asread_len.Will send separate patch for this.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Will You send a separate patch? or I include it in this patch set?
This should not be a separate patch. Since every patch needs to pass buildman testing.
But it is not introduced by this patch set. So should be a separate patch to fix.
Do you mean the build warnings exist in current u-boot/master?
If so, Jagan can you please explain why you mention this? This is nothing related to this patch review.
Quoted 7 lines
Quoted 3 lines
Please read my previous comments, I was clearly explain the issue and diff. Issue came up this series with 4BAIS on
spi_flash_cmd_read_opsSo your words and Wenyou are contradictory. Wenyou claimed the warnings do not come from his patchset while you said yes. Anyway will leave you guys to resolve.
No, I didn't say that I wrote "Will send separate patch for this." for 4BIAS fix not for the warning issue.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.