cadence-qspi: Add DTR support including PHY mode calibration
Subsystems (3)
cover cadence-qspi: Add DTR support including PHY mode calibration
This series introduces support for DTR mode for the Cadence QSPI/OSPI IP. We have been developing it against the SC594/SC598 from ADI, so there are some limitations specific to our hardware's capabilities. Ideally this series could be enhanced with features introduced in a patch series submitted by AMD, but currently no work has been done to reconcile the two. So this is somewhere between an RFC patch and a patch series we wish to submit as-is for inclusion.
Beyond the specific support for the QSPI peripheral, this series also introduces a more general calibration framework as part of the spi system in order to facilitate integration of calibration support for other controllers within a consistent approach.
Ian Roberts (11):
mtd: spi-nor: Add calibration hook for high speed SPI
mtd: spi-nor: Octal DTR support for IS25*x
spi: cadence-quadspi: Enable DDR bit for DTR commands
spi: cadence-quadspi: enable opcode extension based on command length
spi: cadence-quadspi: disable automatic write enable
spi: cadence-quadspi: unconditionally disable auto status register
reads
spi: cadence-quadspi: Remove redundant DTR state
spi: cadence-quadspi: Direct mode does not support zero length
addresses
spi: cadence-quadspi: Add support for memory DMA channel transfers
spi: cadence-quadspi: Add DT control of max Read Delay Capture value
spi: cadence-quadspi: Implement high speed calibration
doc/device-tree-bindings/spi/spi-bus.txt | 4 + doc/device-tree-bindings/spi/spi-cadence.txt | 11 + drivers/mtd/spi/Kconfig | 12 + drivers/mtd/spi/spi-nor-core.c | 246 ++++++++ drivers/mtd/spi/spi-nor-ids.c | 6 +- drivers/spi/cadence_qspi.c | 444 ++++++++++---- drivers/spi/cadence_qspi.h | 105 +++- drivers/spi/cadence_qspi_apb.c | 572 +++++++++++++++---- drivers/spi/spi-mem.c | 24 + include/linux/mtd/spi-nor.h | 13 + include/spi-mem.h | 19 + 11 files changed, 1226 insertions(+), 230 deletions(-)
Signature · 1 line
2.43.2
PATCH 1/11 mtd: spi-nor: Add calibration hook for high speed SPI
From: Ian Roberts <[email protected]>
High speed SPI flash chip operation, such as speeds greater than 50MHz, require a calibration of the data lines to determine the correct signal propagation delay. This calibration delay will vary based on flash chip, operating frequency, board trace length, and board temperature to a smaller extent.
To my knowledge, JEDEC doesn't have a well defined standard for how calibration should be implemented by flash chip manufacturers. The few flash chip datasheets I have viewed from chips that do support such high speed operation implement very different methods for assisting in calibration, such as:
* No provision for calibration.
* Independent "data learning" commands.
* Scratch data registers.
* Predefined bit patterns inserted before read data contents (preamble).
Thus, the simplest and most portable solution to calibrate appears to be to simply read and compare a known data pattern from the flash array.
During SPI flash probe, calibration is initialized after the SFDP read, but before read command selection. At this stage, higher speeds, more advanced read commands, and additional IO lanes, and dual data rate options have not yet been enabled. Communication is most reliable at this stage to read out a pattern to then check against later. The most basic and widely supported read commands are then used to read out the data pattern. The default is to read 2 flash pages worth of data at the first address in flash. Commonly, this is where a bootloader might be located on the chip. While a bootloader is not an ideal pattern, two pages worth of data hopefully contains enough entropy to calibrate successfully. This can be further customized with two new flash chip device tree parameters:
* 'calibration-offset' The flash chip address offset where the pattern data is located.
* 'calibration-length' The length of pattern data.
The calibration step is then called at the end of the chip probe, right after all advanced IO modes have been enabled, such as multiple IO lanes and SDR/DDR modes.
Another solution to the high speed calibration issue is to perform the calibration offline and then to simply apply the calibration at boot. This skips a potentially lengthy calibration process. However, this change set also serves as an ideal hook for controller drivers to also simply apply any pre-calibrated values. Early commands in the probe process, such as RDID, RDSFDP, and RDAY may have slower operating frequencies. As, for example, the JEDEC spec only requires that RDSFDP and RDAY to support at least up to 50MHz frequency. Thus it is ideal to probe the chip at lower frequencies with more reliable IO modes, such as a low frequency with one lane at a single data rate.
This patch implements:
* SPI-mem API function for drivers to implement to perform calibration.
* Read pattern data through reliable methods.
* Call SPI-mem API calibration function with a read check function that uses probed read commands and all enabled fast IO modes.
---
--- doc/device-tree-bindings/spi/spi-bus.txt | 4 + drivers/mtd/spi/Kconfig | 12 ++ drivers/mtd/spi/spi-nor-core.c | 168 +++++++++++++++++++++++ drivers/spi/spi-mem.c | 24 ++++ include/linux/mtd/spi-nor.h | 7 + include/spi-mem.h | 19 +++ 6 files changed, 234 insertions(+)
doc/device-tree-bindings/spi/spi-bus.txt +4 -0
@@ -61,6 +61,10 @@ contain the following properties. used for MISO. Defaults to 1 if not present. - spi-half-duplex - (optional) Indicates that the SPI bus should wait for a header byte before reading data from the slave. +- calibration-offset - (optional) Check pattern offset location for high- + speed calibration. +- calibration-length - (optional) Check pattern length for high-speed + calibration. Some SPI controllers and devices support Dual and Quad SPI transfer mode. It allows data in SPI system transferred in 2 wires(DUAL) or 4 wires(QUAD).
drivers/mtd/spi/Kconfig +12 -0
@@ -127,6 +127,18 @@ config SPI_FLASH_SOFT_RESET_ON_BOOT that are not supposed to be handed to U-Boot in Octal DTR mode, even if they _do_ support the Soft Reset sequence. +config SPI_FLASH_HS_CALIB + bool "Support for high-speed SPI flash calibration" + default n + help + Modern flash chips and controllers that operate at speeds higher than + 50MHz require delays in the signal lines to be calibrated. This + feature adds a spi-mem API hook to allow controller drivers to + perform the calibration during chip probe. + Select N here if SPI flash chips or controllers on your platform + operate roughly around or less than 50MHz, or if the controller driver + doesn't implement the calibration hook. + config SPI_FLASH_BAR bool "SPI flash Bank/Extended address register support" help
drivers/mtd/spi/spi-nor-core.c +168 -0
192 lines not on this page · raw message
drivers/spi/spi-mem.c +24 -0
@@ -763,6 +763,30 @@ ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc, }EXPORT_SYMBOL_GPL (spi_mem_dirmap_write); +#if CONFIG_IS_ENABLED (SPI_FLASH_HS_CALIB ) +int spi_mem_has_calibrate (struct spi_slave *slave) +{ +struct udevice *bus = slave->dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +return (ops->mem_ops && ops->mem_ops->calibrate); +} +EXPORT_SYMBOL_GPL (spi_mem_has_calibrate); + +int spi_mem_calibrate (struct spi_slave *slave, +int (*calib_chk_fn)(struct spi_slave *)) +{ +struct udevice *bus = slave->dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +if (spi_mem_has_calibrate (slave)) +return ops->mem_ops->calibrate (slave, calib_chk_fn); + +return -ENOSYS ; +} +EXPORT_SYMBOL_GPL (spi_mem_calibrate); +#endif +#ifndef __UBOOT__static inline struct spi_mem_driver *to_spi_mem_drv (struct device_driver *drv) {
include/linux/mtd/spi-nor.h +7 -0
@@ -593,6 +593,13 @@ struct spi_nor {u32 size;u32 sector_size;u32 erase_size; + +#if CONFIG_IS_ENABLED (SPI_FLASH_HS_CALIB ) +u8 *calib_ref_buff; +u8 *calib_buff; +u32 calib_size; +u32 calib_off; +#endif };#ifndef __UBOOT__
include/spi-mem.h +19 -0
@@ -243,6 +243,15 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem)* the currently mapped area), and the caller of * spi_mem_dirmap_write() is responsible for calling it again in * this case. +* @calibrate: instruct driver to perform or clear high speed calibration for +* the memory device. The provided function should be used by the +* driver to check if a calibration configuration is valid. May be +* called multiple times as needed. Do note that calling the check +* function may call back into the other ops in this interface. +* A null calib_chk_fn should clear any existing calibration. +* calib_chk_fn is expected to return 0 on success, negative error +* codes, and a positive value on failure. +* The same return value expectation for the calibrate function. * * This interface should be implemented by SPI controllers providing an * high-level interface to execute SPI memory operation, which is usually the
@@ -266,6 +275,10 @@ struct spi_controller_mem_ops { u64 offs, size_t len, void *buf);ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc,u64 offs,size_t len,const void *buf); +#if CONFIG_IS_ENABLED (SPI_FLASH_HS_CALIB ) +int (*calibrate)(struct spi_slave *slave, +int (*calib_chk_fn)(struct spi_slave *)); +#endif };#ifndef __UBOOT__
@@ -341,6 +354,12 @@ ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,ssize_t spi_mem_dirmap_write (struct spi_mem_dirmap_desc *desc,u64 offs,size_t len,const void *buf); +#if CONFIG_IS_ENABLED (SPI_FLASH_HS_CALIB ) +int spi_mem_has_calibrate (struct spi_slave *slave); +int spi_mem_calibrate (struct spi_slave *slave, +int (*calib_chk_fn)(struct spi_slave *)); +#endif +#ifndef __UBOOT__int spi_mem_driver_register_with_owner (struct spi_mem_driver *drv,struct module *owner);
Signature · 1 line
2.43.2
PATCH 2/11 mtd: spi-nor: Octal DTR support for IS25*x
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
ISSI IS25*x series SPIflash chips are capable of Octal IO and DDR. Add spi-nor support to enable and operate in these modes.
---
drivers/mtd/spi/spi-nor-core.c | 78 ++++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi-nor-ids.c | 6 ++- include/linux/mtd/spi-nor.h | 6 +++ 3 files changed, 89 insertions(+), 1 deletion(-)
drivers/mtd/spi/spi-nor-core.c +78 -0
@@ -3968,6 +3968,76 @@ static struct spi_nor_fixups macronix_octal_fixups = { };#endif /* CONFIG_SPI_FLASH_MACRONIX */ +#ifdef CONFIG_SPI_FLASH_ISSI +/** +* spi_nor_issi_octal_dtr_enable() - Enable octal DTR on ISSI flashes. +* @nor: pointer to a 'struct spi_nor' +* +* Return: 0 on success, -errno otherwise. +*/ +static int spi_nor_issi_octal_dtr_enable (struct spi_nor *nor) +{ +struct spi_mem_op op; +int ret; +u8 regval; + + nor->read_dummy =ISSI_MAX_DC ; + + ret =write_enable (nor); +if (ret) +return ret; + + regval =SPINOR_REG_ISSI_VCR_ODDR_EN ; + op = (struct spi_mem_op ) +SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_ISSI_WR_VCR ,1 ), +SPI_MEM_OP_ADDR (3 ,SPINOR_REG_ISSI_VCR_IOMODE ,1 ), +SPI_MEM_OP_NO_DUMMY , +SPI_MEM_OP_DATA_OUT (1 , ®val,1 )); + + ret =spi_mem_exec_op (nor->spi, &op); +if (ret) { +dev_err (nor->dev,"Failed to enable octal DTR mode\n" ); +return ret; + } + + nor->reg_proto =SNOR_PROTO_8_8_8_DTR ; + +return 0 ; +} + +static void issi_octal_default_init (struct spi_nor *nor) +{ + nor->octal_dtr_enable = spi_nor_issi_octal_dtr_enable; +} + +static void issi_octal_post_sfdp_fixup (struct spi_nor *nor, +struct spi_nor_flash_parameter *params) +{ +/* +* Adding SNOR_HWCAPS_PP_8_8_8_DTR in hwcaps.mask when +* SPI_NOR_OCTAL_DTR_READ flag exists. +*/ +if (params->hwcaps.mask &SNOR_HWCAPS_READ_8_8_8_DTR ) + params->hwcaps.mask |=SNOR_HWCAPS_PP_8_8_8_DTR ; + nor->cmd_ext_type =SPI_NOR_EXT_INVERT ; + +spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_8_8_8_DTR ], +0 ,16 ,0x0c ,SNOR_PROTO_8_8_8_DTR ); +spi_nor_set_pp_settings (¶ms->page_programs[SNOR_CMD_PP_8_8_8_DTR ], +0x12 ,SNOR_PROTO_8_8_8_DTR ); + + params->rdsr_dummy =8 ; + + nor->flags |=SNOR_F_IO_MODE_EN_VOLATILE ; + nor->flags |=SNOR_F_SOFT_RESET ; +} + +static struct spi_nor_fixups issi_octal_dtr_fixups = { + .default_init = issi_octal_default_init, + .post_sfdp = issi_octal_post_sfdp_fixup, +}; +#endif /* CONFIG_SPI_FLASH_ISSI */ +/** spi_nor_octal_dtr_enable() - enable Octal DTR I/O if needed * @nor: pointer to a 'struct spi_nor' *
@@ -4161,6 +4231,14 @@ void spi_nor_set_fixups(struct spi_nor *nor) nor->fixups = &mt35xu512aba_fixups;#endif +#if CONFIG_IS_ENABLED (SPI_FLASH_ISSI ) +if (JEDEC_MFR (nor->info) ==SNOR_MFR_ISSI ) { +if ((nor->info->id[1 ] ==0x5a || nor->info->id[1 ] ==0x5b ) && + (nor->info->id[2 ] ==0x19 || nor->info->id[2 ] ==0x18 )) + nor->fixups = &issi_octal_dtr_fixups; + } +#endif +#if CONFIG_IS_ENABLED (SPI_FLASH_MACRONIX ) nor->fixups = ¯onix_octal_fixups;#endif /* SPI_FLASH_MACRONIX */
drivers/mtd/spi/spi-nor-ids.c +5 -1
@@ -238,8 +238,12 @@ const struct flash_info spi_nor_ids[] = { SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { INFO("is25wp01g", 0x9d701b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, + { INFO("is25lx256", 0x9d5a19, 0, 128 * 1024, 256, +SECT_4K |USE_FSR |SPI_NOR_OCTAL_READ + | SPI_NOR_OCTAL_DTR_READ | SPI_NOR_4B_OPCODES) }, { INFO("is25wx256", 0x9d5b19, 0, 128 * 1024, 256, - SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ | SPI_NOR_4B_OPCODES) }, +SECT_4K |USE_FSR |SPI_NOR_OCTAL_READ + | SPI_NOR_OCTAL_DTR_READ | SPI_NOR_4B_OPCODES) }, { INFO("is25lx512", 0x9d5a1a, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_4B_OPCODES | SPI_NOR_HAS_TB) }, #endif
include/linux/mtd/spi-nor.h +6 -0
@@ -131,6 +131,12 @@#define SPINOR_REG_MXIC_DC_20 0x0/* Setting dummy cycles to 20 */ #define MXIC_MAX_DC 20/* Maximum value of dummy cycles */ +/* Used for ISSI flashes. */ +#define SPINOR_OP_ISSI_WR_VCR 0x81 +#define SPINOR_REG_ISSI_VCR_IOMODE 0x0 +#define SPINOR_REG_ISSI_VCR_ODDR_EN 0xe7 +#define ISSI_MAX_DC 16 +/* Used for Spansion flashes only. */ #define SPINOR_OP_BRWR 0x17/* Bank register write */ #define SPINOR_OP_BRRD 0x16/* Bank register read */
Signature · 1 line
2.43.2
PATCH 3/11 spi: cadence-quadspi: Enable DDR bit for DTR commands
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
The Cadence octal SPI IP read instruction register requires a bit to be set to indicate if the read opcode is a compliant DDR read command.
---
drivers/spi/cadence_qspi.h | 1 + drivers/spi/cadence_qspi_apb.c | 4 ++++ 2 files changed, 5 insertions(+)
drivers/spi/cadence_qspi.h +1 -0
@@ -61,6 +61,7 @@#define CQSPI_REG_RD_INSTR 0x04#define CQSPI_REG_RD_INSTR_OPCODE_LSB 0#define CQSPI_REG_RD_INSTR_TYPE_INSTR_LSB 8 +#define CQSPI_REG_RD_INSTR_DDR_EN_MASK BIT(10)#define CQSPI_REG_RD_INSTR_TYPE_ADDR_LSB 12#define CQSPI_REG_RD_INSTR_TYPE_DATA_LSB 16#define CQSPI_REG_RD_INSTR_MODE_EN_LSB 20
drivers/spi/cadence_qspi_apb.c +4 -0
@@ -446,6 +446,7 @@ int cadence_qspi_apb_command_read_setup(struct cadence_spi_priv *priv,return ret; reg =cadence_qspi_calc_rdreg (priv); + reg |= op->cmd.dtr ?CQSPI_REG_RD_INSTR_DDR_EN_MASK :0 ;writel (reg, priv->regbase +CQSPI_REG_RD_INSTR );return 0 ;
@@ -537,6 +538,7 @@ int cadence_qspi_apb_command_write_setup(struct cadence_spi_priv *priv,return ret; reg =cadence_qspi_calc_rdreg (priv); + reg |= op->cmd.dtr ?CQSPI_REG_RD_INSTR_DDR_EN_MASK :0 ;writel (reg, priv->regbase +CQSPI_REG_RD_INSTR );return 0 ;
@@ -638,6 +640,7 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv, opcode = op->cmd.opcode; rd_reg = opcode <<CQSPI_REG_RD_INSTR_OPCODE_LSB ; + rd_reg |= op->cmd.dtr ?CQSPI_REG_RD_INSTR_DDR_EN_MASK :0 ; rd_reg |=cadence_qspi_calc_rdreg (priv);writel (op->addr.val, priv->regbase +CQSPI_REG_INDIRECTRDSTARTADDR );
@@ -812,6 +815,7 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv,writel (reg, priv->regbase +CQSPI_REG_WR_INSTR ); reg =cadence_qspi_calc_rdreg (priv); + reg |= op->cmd.dtr ?CQSPI_REG_RD_INSTR_DDR_EN_MASK :0 ;writel (reg, priv->regbase +CQSPI_REG_RD_INSTR );writel (op->addr.val, priv->regbase +CQSPI_REG_INDIRECTWRSTARTADDR );
Signature · 1 line
2.43.2
PATCH 4/11 spi: cadence-quadspi: enable opcode extension based on command length
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
Some flash chips use dual opcodes in other modes. For example, the Macronix MX66 requires dual opcodes for STR octal operation. Thus, enable opcode extension based on the length of the command instead of the DTR mode of the controller.
---
drivers/spi/cadence_qspi_apb.c | 66 +++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 17 deletions(-)
drivers/spi/cadence_qspi_apb.c +49 -17
@@ -412,19 +412,27 @@ static int cadence_qspi_enable_dtr(struct cadence_spi_priv *priv, reg =readl (priv->regbase +CQSPI_REG_CONFIG ); -if (enable) { - reg |=CQSPI_REG_CONFIG_DTR_PROTO ; +switch (op->cmd.nbytes) { +case 1 : + reg &= ~CQSPI_REG_CONFIG_DUAL_OPCODE ; +break ; +case 2 : reg |=CQSPI_REG_CONFIG_DUAL_OPCODE ;/* Set up command opcode extension. */ ret =cadence_qspi_setup_opcode_ext (priv, op, shift);if (ret)return ret; - }else { - reg &= ~CQSPI_REG_CONFIG_DTR_PROTO ; - reg &= ~CQSPI_REG_CONFIG_DUAL_OPCODE ; +break ; +default : +return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); } +if (enable) + reg |=CQSPI_REG_CONFIG_DTR_PROTO ; +else + reg &= ~CQSPI_REG_CONFIG_DTR_PROTO ; +writel (reg, priv->regbase +CQSPI_REG_CONFIG );return 0 ;
@@ -465,10 +473,16 @@ int cadence_qspi_apb_command_read(struct cadence_spi_priv *priv,unsigned int dummy_clk;u8 opcode; -if (priv->dtr) - opcode = op->cmd.opcode >>8 ; -else +switch (op->cmd.nbytes) { +case 1 : opcode = op->cmd.opcode; +break ; +case 2 : + opcode = op->cmd.opcode >>8 ; +break ; +default : +return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); + }if (opcode ==CMD_4BYTE_OCTAL_READ && !priv->dtr) opcode =CMD_4BYTE_FAST_READ ;
@@ -557,10 +571,16 @@ int cadence_qspi_apb_command_write(struct cadence_spi_priv *priv,void *reg_base = priv->regbase;u8 opcode; -if (priv->dtr) - opcode = op->cmd.opcode >>8 ; -else +switch (op->cmd.nbytes) { +case 1 : opcode = op->cmd.opcode; +break ; +case 2 : + opcode = op->cmd.opcode >>8 ; +break ; +default : +return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); + } reg |= opcode <<CQSPI_REG_CMDCTRL_OPCODE_LSB ;
@@ -634,10 +654,16 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv, priv->regbase + CQSPI_REG_INDIRECTTRIGGER);/* Configure the opcode */ -if (priv->dtr) - opcode = op->cmd.opcode >>8 ; -else +switch (op->cmd.nbytes) { +case 1 : opcode = op->cmd.opcode; +break ; +case 2 : + opcode = op->cmd.opcode >>8 ; +break ; +default : +return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); + } rd_reg = opcode <<CQSPI_REG_RD_INSTR_OPCODE_LSB ; rd_reg |= op->cmd.dtr ?CQSPI_REG_RD_INSTR_DDR_EN_MASK :0 ;
@@ -804,10 +830,16 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv, priv->regbase + CQSPI_REG_INDIRECTTRIGGER);/* Configure the opcode */ -if (priv->dtr) - opcode = op->cmd.opcode >>8 ; -else +switch (op->cmd.nbytes) { +case 1 : opcode = op->cmd.opcode; +break ; +case 2 : + opcode = op->cmd.opcode >>8 ; +break ; +default : +return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); + } reg = opcode <<CQSPI_REG_WR_INSTR_OPCODE_LSB ; reg |= priv->data_width <<CQSPI_REG_WR_INSTR_TYPE_DATA_LSB ;
Signature · 1 line
2.43.2
PATCH 5/11 spi: cadence-quadspi: disable automatic write enable
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
The spi-nor subsystem issues the write enable command manually. So this automatic feature sends duplicate commands and also introduces the possibility of erroneous writes.
Disable the automatic write enable feature by default.
---
drivers/spi/cadence_qspi.h | 1 + drivers/spi/cadence_qspi_apb.c | 1 + 2 files changed, 2 insertions(+)
drivers/spi/cadence_qspi.h +1 -0
@@ -73,6 +73,7 @@#define CQSPI_REG_WR_INSTR 0x08#define CQSPI_REG_WR_INSTR_OPCODE_LSB 0 +#define CQSPI_REG_WR_INSTR_WELDIS_MASK BIT(8)#define CQSPI_REG_WR_INSTR_TYPE_ADDR_LSB 12#define CQSPI_REG_WR_INSTR_TYPE_DATA_LSB 16
drivers/spi/cadence_qspi_apb.c +1 -0
@@ -842,6 +842,7 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv, } reg = opcode <<CQSPI_REG_WR_INSTR_OPCODE_LSB ; + reg |=CQSPI_REG_WR_INSTR_WELDIS_MASK ; reg |= priv->data_width <<CQSPI_REG_WR_INSTR_TYPE_DATA_LSB ; reg |= priv->addr_width <<CQSPI_REG_WR_INSTR_TYPE_ADDR_LSB ;writel (reg, priv->regbase +CQSPI_REG_WR_INSTR );
Signature · 1 line
2.43.2
PATCH 6/11 spi: cadence-quadspi: unconditionally disable auto status register reads
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
In addition to the given reason for the conditional disable of this feature for DTR:
Theoretically, some flashes have their WIP bit in different bit positions or have a different bit polarity. spi-nor currently does not have an interface in place to dictate this information to this driver for proper configuration.
The default of the controller hardware has this status register auto polling without expiration. This means that if there is any controller misconfiguration or communication failure, it will completely lock up the controller.
Thus, unconditionally disable this feature for now.
---
drivers/spi/cadence_qspi_apb.c | 46 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/spi/cadence_qspi_apb.c +24 -22
@@ -853,19 +853,29 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv,writel (op->addr.val, priv->regbase +CQSPI_REG_INDIRECTWRSTARTADDR ); -if (priv->dtr) { -/* -* Some flashes like the cypress Semper flash expect a 4-byte -* dummy address with the Read SR command in DTR mode, but this -* controller does not support sending address with the Read SR -* command. So, disable write completion polling on the -* controller's side. spi-nor will take care of polling the -* status register. -*/ - reg =readl (priv->regbase +CQSPI_REG_WR_COMPLETION_CTRL ); - reg |=CQSPI_REG_WR_DISABLE_AUTO_POLL ; -writel (reg, priv->regbase +CQSPI_REG_WR_COMPLETION_CTRL ); - } +/* +* Some flashes like the cypress Semper flash expect a 4-byte +* dummy address with the Read SR command in DTR mode, but this +* controller does not support sending address with the Read SR +* command. So, disable write completion polling on the +* controller's side. spi-nor will take care of polling the +* status register. +* +* Theoretically, some flashes have their WIP bit in different +* bit positions or have a different bit polarity. spi-nor +* currently does not have an interface in place to dictate +* this information to this driver for proper configuration. +* +* The default of the controller hardware has this status register +* auto polling without expiration. This means that if there is any +* controller misconfiguration or communication failure, it will +* completely lock up the controller. +* +* Thus, unconditionally disable this feature for now. +*/ + reg =readl (priv->regbase +CQSPI_REG_WR_COMPLETION_CTRL ); + reg |=CQSPI_REG_WR_DISABLE_AUTO_POLL ; +writel (reg, priv->regbase +CQSPI_REG_WR_COMPLETION_CTRL ); reg =readl (priv->regbase +CQSPI_REG_SIZE ); reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK ;
@@ -970,16 +980,8 @@ int cadence_qspi_apb_write_execute(struct cadence_spi_priv *priv,const void *buf = op->data.buf.out;size_t len = op->data.nbytes; -/* -* Some flashes like the Cypress Semper flash expect a dummy 4-byte -* address (all 0s) with the read status register command in DTR mode. -* But this controller does not support sending dummy address bytes to -* the flash when it is polling the write completion register in DTR -* mode. So, we can not use direct mode when in DTR mode for writing -* data. -*/ cadence_qspi_apb_enable_linear_mode (true); -if (!priv->dtr && priv->use_dac_mode && (to + len < priv->ahbsize)) { +if (priv->use_dac_mode && (to + len < priv->ahbsize)) {memcpy_toio (priv->ahbbase + to, buf, len);if (!cadence_qspi_wait_idle (priv->regbase))return -EIO ;
Signature · 1 line
2.43.2
PATCH 7/11 spi: cadence-quadspi: Remove redundant DTR state
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
cadence_spi_mem_supports_op() already checks that every memory operation either has all DTR booleans set or cleared. Thus, there is no need to store a cached dtr value. The command DTR state can be used since it is not optional like the other fields.
---
drivers/spi/cadence_qspi.c | 6 ++++++ drivers/spi/cadence_qspi.h | 1 - drivers/spi/cadence_qspi_apb.c | 27 ++++++++------------------- 3 files changed, 14 insertions(+), 20 deletions(-)
drivers/spi/cadence_qspi.c +6 -0
@@ -362,6 +362,12 @@ static bool cadence_spi_mem_supports_op(struct spi_slave *slave,bool all_true, all_false;/* +* For an op to be DTR, cmd phase along with every other non-empty +* phase should have dtr field set to 1. If an op phase has zero +* nbytes, ignore its dtr field; otherwise, check its dtr field. +* Also, dummy checks not performed here Since supports_op() +* already checks that all or none of the fields are DTR. +* * op->dummy.dtr is required for converting nbytes into ncycles. * Also, don't check the dtr field of the op phase having zero nbytes. */
drivers/spi/cadence_qspi.h +0 -1
@@ -265,7 +265,6 @@ struct cadence_spi_priv {u8 inst_width;u8 addr_width;u8 data_width; -bool dtr; };/* Functions call declaration */
drivers/spi/cadence_qspi_apb.c +8 -19
@@ -120,17 +120,6 @@ static int cadence_qspi_set_protocol(struct cadence_spi_priv *priv, {int ret; -/* -* For an op to be DTR, cmd phase along with every other non-empty -* phase should have dtr field set to 1. If an op phase has zero -* nbytes, ignore its dtr field; otherwise, check its dtr field. -* Also, dummy checks not performed here Since supports_op() -* already checks that all or none of the fields are DTR. -*/ - priv->dtr = op->cmd.dtr && - (!op->addr.nbytes || op->addr.dtr) && - (!op->data.nbytes || op->data.dtr); - ret =cadence_qspi_buswidth_to_inst_type (op->cmd.buswidth);if (ret <0 )return ret;
@@ -449,7 +438,7 @@ int cadence_qspi_apb_command_read_setup(struct cadence_spi_priv *priv,return ret; ret =cadence_qspi_enable_dtr (priv, op,CQSPI_REG_OP_EXT_STIG_LSB , - priv->dtr); + op->cmd.dtr);if (ret)return ret;
@@ -484,13 +473,13 @@ int cadence_qspi_apb_command_read(struct cadence_spi_priv *priv,return log_msg_ret ("QSPI: Invalid command length" , -EINVAL ); } -if (opcode ==CMD_4BYTE_OCTAL_READ && !priv->dtr) +if (opcode ==CMD_4BYTE_OCTAL_READ && !op->cmd.dtr) opcode =CMD_4BYTE_FAST_READ ; reg = opcode <<CQSPI_REG_CMDCTRL_OPCODE_LSB ;/* Set up dummy cycles. */ - dummy_clk =cadence_qspi_calc_dummy (op, priv->dtr); + dummy_clk =cadence_qspi_calc_dummy (op, op->cmd.dtr);if (dummy_clk >CQSPI_DUMMY_CLKS_MAX )return -ENOTSUPP ;
@@ -547,7 +536,7 @@ int cadence_qspi_apb_command_write_setup(struct cadence_spi_priv *priv,return ret; ret =cadence_qspi_enable_dtr (priv, op,CQSPI_REG_OP_EXT_STIG_LSB , - priv->dtr); + op->cmd.dtr);if (ret)return ret;
@@ -597,7 +586,7 @@ int cadence_qspi_apb_command_write(struct cadence_spi_priv *priv, }/* Set up dummy cycles. */ - dummy_clk =cadence_qspi_calc_dummy (op, priv->dtr); + dummy_clk =cadence_qspi_calc_dummy (op, op->cmd.dtr);if (dummy_clk >CQSPI_DUMMY_CLKS_MAX )return -EOPNOTSUPP ;
@@ -645,7 +634,7 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv,return ret; ret =cadence_qspi_enable_dtr (priv, op,CQSPI_REG_OP_EXT_READ_LSB , - priv->dtr); + op->cmd.dtr);if (ret)return ret;
@@ -673,7 +662,7 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv,if (dummy_bytes) {/* Convert to clock cycles. */ - dummy_clk =cadence_qspi_calc_dummy (op, priv->dtr); + dummy_clk =cadence_qspi_calc_dummy (op, op->cmd.dtr);if (dummy_clk >CQSPI_DUMMY_CLKS_MAX )return -ENOTSUPP ;
@@ -821,7 +810,7 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv,return ret; ret =cadence_qspi_enable_dtr (priv, op,CQSPI_REG_OP_EXT_WRITE_LSB , - priv->dtr); + op->cmd.dtr);if (ret)return ret;
Signature · 1 line
2.43.2
PATCH 8/11 spi: cadence-quadspi: Direct mode does not support zero length addresses
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
It is not possible to configure the Cadence SPI IP block to use a zero length address in DMA read or write commands.
---
drivers/spi/cadence_qspi_apb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi_apb.c +2 -2
@@ -784,7 +784,7 @@ int cadence_qspi_apb_read_execute(struct cadence_spi_priv *priv,cadence_qspi_apb_enable_linear_mode (true); -if (priv->use_dac_mode && (from + len < priv->ahbsize)) { +if (op->addr.nbytes && priv->use_dac_mode && (from + len < priv->ahbsize)) {if (len <256 ||dma_memcpy (buf, priv->ahbbase + from, len) <0 ) {memcpy_fromio (buf, priv->ahbbase + from, len);
@@ -970,7 +970,7 @@ int cadence_qspi_apb_write_execute(struct cadence_spi_priv *priv,size_t len = op->data.nbytes;cadence_qspi_apb_enable_linear_mode (true); -if (priv->use_dac_mode && (to + len < priv->ahbsize)) { +if (op->addr.nbytes && priv->use_dac_mode && (to + len < priv->ahbsize)) {memcpy_toio (priv->ahbbase + to, buf, len);if (!cadence_qspi_wait_idle (priv->regbase))return -EIO ;
Signature · 1 line
2.43.2
PATCH 9/11 spi: cadence-quadspi: Add support for memory DMA channel transfers
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
On the SC59x platform, the Cadence SPI IP block can use memory DMA channels to execute transactions. Existing Cadence DMA support attempts appears to be SOC specific and not generic. Thus, framework to use the DMA subsystem was added. On the SC59x, DMA to the Cadence SPI block is connected via memory DMA instead of peripheral DMA. In addition, some of the memory DMA channels are recommended over others for better transaction performance. This initial implementation simply uses the recommended memory channel indicated from the device tree. Peripheral DMA support can be added later for platforms that need it.
---
drivers/spi/cadence_qspi.c | 47 ++++++++++++++++ drivers/spi/cadence_qspi.h | 31 +++++++++-- drivers/spi/cadence_qspi_apb.c | 99 ++++++++++++++++++++++++++++++---- 3 files changed, 164 insertions(+), 13 deletions(-)
drivers/spi/cadence_qspi.c +47 -0
@@ -7,6 +7,8 @@#include <common.h> #include <clk.h> #include <log.h> +#include <asm-generic/io.h> +#include <dma.h> #include <dm.h> #include <fdtdec.h> #include <malloc.h>
@@ -194,6 +196,42 @@ static int cadence_spi_set_speed(struct udevice *bus, uint hz)return 0 ; } +#if CONFIG_IS_ENABLED (DMA_CHANNELS ) +static int cadence_spi_probe_dma (struct udevice *bus) +{ +struct cadence_spi_priv *priv =dev_get_priv (bus); +struct dma_dev_priv *dma_uc; +int hasdma; +int ret; + + hasdma = (ofnode_read_u32 (dev_ofnode (bus),"dmas" ,NULL ) ==0 ) && + (ofnode_read_u32 (dev_ofnode (bus),"dma-names" ,NULL ) ==0 ); +if (!hasdma) +return 0 ; + + ret =dma_get_by_name (bus,"dst" , &priv->dstdma); +if (ret !=0 ) +return 0 ; + + dma_uc =dev_get_uclass_priv (priv->dstdma.dev); + +if (dma_uc->supported ==DMA_SUPPORTS_MEM_TO_MEM ) { +/* We were given a specific DMA channel that only +* supports mem-to-mem transactions. +*/ + priv->hasdma = hasdma; + priv->ops.direct_read_copy = cadence_qspi_apb_read_copy_mdma; + priv->ops.direct_write_copy = cadence_qspi_apb_write_copy_mdma; +return 0 ; + } + +/* Todo: Implement device DMA channel modes when needed +* (DMA_SUPPORTS_MEM_TO_DEV, DMA_SUPPORTS_DEV_TO_MEM). +*/ +return -ENOSYS ; +} +#endif +static int cadence_spi_probe (struct udevice *bus) {struct cadence_spi_plat *plat =dev_get_plat (bus);
@@ -219,6 +257,9 @@ static int cadence_spi_probe(struct udevice *bus) priv->tchsh_ns = plat->tchsh_ns; priv->tslch_ns = plat->tslch_ns; + priv->ops.direct_read_copy = cadence_qspi_apb_direct_read_copy; + priv->ops.direct_write_copy = cadence_qspi_apb_direct_write_copy; +if (IS_ENABLED (CONFIG_ZYNQMP_FIRMWARE )) xilinx_pm_request(PM_REQUEST_NODE, PM_DEV_OSPI, ZYNQMP_PM_CAPABILITY_ACCESS, ZYNQMP_PM_MAX_QOS,
@@ -252,6 +293,12 @@ static int cadence_spi_probe(struct udevice *bus) priv->wr_delay =50 *DIV_ROUND_UP (NSEC_PER_SEC , priv->ref_clk_hz); +if (CONFIG_IS_ENABLED (DMA_CHANNELS )) { + ret =cadence_spi_probe_dma (bus); +if (ret) +return ret; + } +/* Versal and Versal-NET use spi calibration to set read delay */ if (CONFIG_IS_ENABLED (ARCH_VERSAL ) ||CONFIG_IS_ENABLED (ARCH_VERSAL_NET ))
drivers/spi/cadence_qspi.h +27 -4
@@ -223,7 +223,16 @@ struct cadence_spi_plat {u32 tchsh_ns;u32 tslch_ns; -bool is_dma; +bool is_dma; +}; + +struct cadence_spi_priv ; + +struct cadence_drv_ops { +int (*direct_read_copy)(struct cadence_spi_priv *priv, +void *dst,u64 src,size_t len); +int (*direct_write_copy)(struct cadence_spi_priv *priv, +const void *src,u64 dst,size_t len); };struct cadence_spi_priv {
@@ -234,11 +243,17 @@ struct cadence_spi_priv {unsigned int fifo_depth;unsigned int fifo_width;unsigned int trigger_address; -fdt_addr_t ahbsize; +fdt_addr_t ahbsize;size_t cmd_len;u8 cmd_buf[32 ];size_t data_len; +bool hasdma; +#if CONFIG_IS_ENABLED (DMA_CHANNELS ) +struct dma dstdma; +#endif +struct cadence_drv_ops ops; +int qspi_is_init;unsigned int qspi_calibrated_hz;unsigned int qspi_calibrated_cs;
@@ -253,8 +268,8 @@ struct cadence_spi_priv {u32 tsd2d_ns;u32 tchsh_ns;u32 tslch_ns; -u8 edge_mode; -u8 dll_mode; +u8 edge_mode; +u8 dll_mode;bool extra_dummy;bool ddr_init;bool is_decoded_cs;
@@ -312,4 +327,12 @@ int cadence_qspi_versal_flash_reset(struct udevice *dev);ofnode cadence_qspi_get_subnode (struct udevice *dev);void cadence_qspi_apb_enable_linear_mode (bool enable); +int cadence_qspi_apb_read_copy_mdma (struct cadence_spi_priv *priv, +void *dst,u64 src,size_t len); +int cadence_qspi_apb_write_copy_mdma (struct cadence_spi_priv *priv, +const void *src,u64 dst,size_t len); +int cadence_qspi_apb_direct_read_copy (struct cadence_spi_priv *priv, +void *dst,u64 src,size_t len); +int cadence_qspi_apb_direct_write_copy (struct cadence_spi_priv *priv, +const void *src,u64 dst,size_t len);#endif /* __CADENCE_QSPI_H__ */
drivers/spi/cadence_qspi_apb.c +90 -9
132 lines not on this page · raw message
Signature · 1 line
2.43.2
PATCH 10/11 spi: cadence-quadspi: Add DT control of max Read Delay Capture value
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
On some SOCs (eg sc59x), attempting to use too high of a Read Delay Capture value can cause the controller DMA to lock up. Thus, add a device tree configuration property to allow controlling the max Read Delay Capture value.
---
doc/device-tree-bindings/spi/spi-cadence.txt | 2 ++ drivers/spi/cadence_qspi.c | 9 ++++++++- drivers/spi/cadence_qspi.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-)
doc/device-tree-bindings/spi/spi-cadence.txt +2 -0
@@ -29,3 +29,5 @@ connected flash properties select (n_ss_out). - cdns,tslch-ns : Delay in master reference clocks between setting n_ss_out low and first bit transfer +- cdns,max-read-delay : Max safe value to use for the read capture delay + during auto calibration.
drivers/spi/cadence_qspi.c +8 -1
@@ -104,7 +104,7 @@ static int spi_calibration(struct udevice *bus, uint hz)/* use back the intended clock and find low range */ cadence_spi_write_speed (bus, hz); -for (i =0 ; i <CQSPI_READ_CAPTURE_MAX_DELAY ; i++) { +for (i =0 ; i < priv->max_read_delay; i++) {/* Disable QSPI */ cadence_qspi_apb_controller_disable (base);
@@ -246,6 +246,7 @@ static int cadence_spi_probe(struct udevice *bus) priv->fifo_depth = plat->fifo_depth; priv->fifo_width = plat->fifo_width; priv->trigger_address = plat->trigger_address; + priv->max_read_delay = plat->max_read_delay; priv->read_delay = plat->read_delay; priv->ahbsize = plat->ahbsize; priv->max_hz = plat->max_hz;
@@ -456,6 +457,10 @@ static int cadence_spi_of_to_plat(struct udevice *bus) plat->is_dma =dev_read_bool (bus,"cdns,is-dma" ); + plat->max_read_delay =dev_read_u32_default (bus, +"cdns,max-read-delay" , +CQSPI_READ_CAPTURE_MAX_DELAY ); +/* All other parameters are embedded in the child node */ subnode =cadence_qspi_get_subnode (bus);if (!ofnode_valid (subnode)) {
@@ -484,6 +489,8 @@ static int cadence_spi_of_to_plat(struct udevice *bus)*/ plat->read_delay =ofnode_read_s32_default (subnode,"cdns,read-delay" ,-1 ); +if (plat->read_delay > plat->max_read_delay) + plat->read_delay = plat->max_read_delay; debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n", __func__, plat->regbase, plat->ahbbase, plat->max_hz,
drivers/spi/cadence_qspi.h +2 -0
@@ -214,6 +214,7 @@ struct cadence_spi_plat {fdt_addr_t ahbsize;bool use_dac_mode;int read_delay; +int max_read_delay;/* Flash parameters */ u32 page_size;
@@ -260,6 +261,7 @@ struct cadence_spi_priv {unsigned int previous_hz;u32 wr_delay;int read_delay; +int max_read_delay;struct reset_ctl_bulk *resets;u32 page_size;
Signature · 1 line
2.43.2
PATCH 11/11 spi: cadence-quadspi: Implement high speed calibration
In reply to Greg MalysaFrom: Ian Roberts <[email protected]>
Implement the spi-mem calibration hook for high speed flash operation for use on the SC59x SOCs. The Cadence controller IP has support for the DQS signal and a PHY mode that facilitates speeds greater than 50MHz.
At high speeds, the IO lines must be calibrated for signal propagation delay. This calibration is intended to be executed in the final IO configuration mode. That is, if 8-lane DDR IO operation is the use case, calibration must occur while that mode is enabled. For example, there might be excess noise on a single IO lane while operating in 8-lane mode that then limits the speed of the entire bus. SPI bus drivers are not involved in the control of the SPI flash chip operating mode, and performing the switch is done by the SPI-nor subsystem. To add to this complexity, different IO modes use different command sets, and different flash chips may also modify this command set further. Thus, we must lean on the spi-nor subsystem through the spi-mem calibration function for the most portable implementation of calibration.
The original calibration code in this driver only calibrates the Read Delay Capture value, over a single lane, over only 3 bytes in the readid command. This produces unreliable calibrations in single IO mode and is unusable in DDR or multi-IO modes.
The prior calibration implementation is replaced in favor of the new approach when CONFIG_SPI_FLASH_HS_CALIB is defined. The old implementation is still available when not defined. However, the previous implementation has been tweaked to take advantage of code reuse and to fix an invalid SPI chip select read from the dm_spi_ops set_speed callback. It would always return the same invalid CS number, never triggering a recalibration if the chip changes. However, this driver was not implemented with support for multiple chips on the bus in mind anyway. For example:
* of_to_plat only scans the first subnode for flash-specific configuration, and thus only a single copy of this info is declared in the plat and priv structs.
* Defining cdns,read-delay overrides any automatic recalibration that would normally occur from a chip select change to this single value.
A few additional comments, checks, and renames have been made to make this more clear. The new calibration implementation explicitly disallows changing the chip after calibration until it is properly implemented in the driver. The legacy implementation will still allow the chip to change but now correctly trigger a recalibration after the chip select changes. The issue with cdns,read-delay and multi-IO modes is only fixed in the new implementation.
---
doc/device-tree-bindings/spi/spi-cadence.txt | 9 + drivers/spi/cadence_qspi.c | 392 +++++++++++++------ drivers/spi/cadence_qspi.h | 77 ++-- drivers/spi/cadence_qspi_apb.c | 327 ++++++++++++++-- 4 files changed, 641 insertions(+), 164 deletions(-)
doc/device-tree-bindings/spi/spi-cadence.txt +9 -0
@@ -31,3 +31,12 @@ connected flash properties n_ss_out low and first bit transfer - cdns,max-read-delay : Max safe value to use for the read capture delay during auto calibration. +- cdns,spi-calib-frequency : Max safe SPI clock frequency to use before bus + calibration is performed. +- cdns,dqs : Enable use of the DQS signal with the flash chip. +- cdns,phy : Enable use of the high-speed PHY feature with the + flash chip. Generally required for speeds higher + than 50MHz. +- cdns,read-delay : Optional pre-calibrated Read Delay Capture value. +- cdns,phyrxdly : Optional pre-calibrated PHY RX Delay value. +- cdns,phytxdly : Optional pre-calibrated PHY TX Delay value.
drivers/spi/cadence_qspi.c +280 -112
527 lines not on this page · raw message
drivers/spi/cadence_qspi.h +54 -23
163 lines not on this page · raw message
drivers/spi/cadence_qspi_apb.c +298 -29
370 lines not on this page · raw message
Signature · 1 line
2.43.2