mtd: spi-nor: program quad enable bit for winbond flashes
Subsystems (3)
PATCH 10/30 mtd: spi-nor: program quad enable bit for winbond flashes
From: T Karthik Reddy <[email protected]>
Added support to program quad enable bit for Winbond flash memory. Previously, the quad enable function from Spansion was used for this purpose. However, for Winbond flash memory, the quad enable bit is configured by programming the Write Status Register-2 (SR-2) rather than the Configuration Register (CR).
--- drivers/mtd/spi/spi-nor-core.c | 48 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 50 insertions(+)
drivers/mtd/spi/spi-nor-core.c +48 -0
@@ -2141,6 +2141,49 @@ static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr)return 0 ; } +/** +* winbond_quad_enable() - Set QE bit in status register-2 +* @nor: pointer to a 'struct spi_nor' +* +* Return: 0 on success, -errno otherwise. +*/ +static int winbond_quad_enable (struct spi_nor *nor) +{ +int ret; +u8 cr =0 ; + +/* Check current Quad Enable bit value. */ + cr =read_cr (nor); +if (cr <0 ) { +dev_dbg (nor->dev, +"error while reading configuration register\n" ); +return -EINVAL ; + } + +if (cr &SR2_QUAD_EN_BIT1 ) +return 0 ; + + cr |=SR2_QUAD_EN_BIT1 ; + +write_enable (nor); + + ret = nor->write_reg (nor,SPINOR_OP_WIN_WRSR2 , &cr,1 ); +if (ret <0 ) { +dev_dbg (nor->dev, +"error while writing configuration register\n" ); +return -EINVAL ; + } + + ret =spi_nor_wait_till_ready (nor); +if (ret) { +dev_dbg (nor->dev, +"timeout while writing configuration register\n" ); +return ret; + } + +return write_disable (nor); +} +/** * spansion_read_cr_quad_enable() - set QE bit in Configuration Register. * @nor: pointer to a 'struct spi_nor'
@@ -3052,6 +3095,11 @@ static int spi_nor_init_params(struct spi_nor *nor,case SNOR_MFR_MICRON :break ; +#if defined(CONFIG_SPI_FLASH_WINBOND ) +case SNOR_MFR_WINBOND : + params->quad_enable = winbond_quad_enable; +break ; +#endif default :#if defined(CONFIG_SPI_FLASH_SPANSION ) || defined(CONFIG_SPI_FLASH_WINBOND )/* Kept only for backward compatibility purpose. */
include/linux/mtd/spi-nor.h +2 -0
@@ -48,6 +48,7 @@#define SPINOR_OP_WRSR 0x01/* Write status register 1 byte */ #define SPINOR_OP_RDSR2 0x3f/* Read status register 2 */ #define SPINOR_OP_WRSR2 0x3e/* Write status register 2 */ +#define SPINOR_OP_WIN_WRSR2 0x31/* Winbond Write status register 2 */ #define SPINOR_OP_READ 0x03/* Read data bytes (low frequency) */ #define SPINOR_OP_READ_FAST 0x0b/* Read data bytes (high frequency) */ #define SPINOR_OP_READ_1_1_2 0x3b/* Read data bytes (Dual Output SPI) */
@@ -187,6 +188,7 @@/* Status Register 2 bits. */ #define SR2_QUAD_EN_BIT7 BIT(7) +#define SR2_QUAD_EN_BIT1 BIT(1)/* Winbond Quad I/O */ /* * Maximum number of flashes that can be connected
Signature · 1 line
2.27.0
PATCH 11/30 mtd: spi-nor: Send write disable cmd after every write enable
From: Ashok Reddy Soma <[email protected]>
Write enable(06h) command will be sent to a flash device to set the write enable latch bit before every program, erase, write command. After that write disable command (04h) needs to be sent to clear the write enable latch.
This write_disable() is missing at the majority of the places in the driver, add it to clear write enable latch.
--- drivers/mtd/spi/spi-nor-core.c | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi-nor-core.c +41 -6
@@ -873,6 +873,7 @@ static int spi_nor_wait_till_ready(struct spi_nor *nor)static int clean_bar (struct spi_nor *nor) {u8 cmd, bank_sel =0 ; +int ret;if (nor->bank_curr ==0 )return 0 ;
@@ -880,7 +881,11 @@ static int clean_bar(struct spi_nor *nor) nor->bank_curr =0 ;write_enable (nor); -return nor->write_reg (nor, cmd, &bank_sel,1 ); + ret = nor->write_reg (nor, cmd, &bank_sel,1 ); +if (ret) +return ret; + +return write_disable (nor); }static int write_bar (struct spi_nor *nor,u32 offset)
@@ -1070,11 +1075,15 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) nor->spi->flags &= ~SPI_XFER_U_PAGE ; } } +if (nor->addr_width ==3 ) {#ifdef CONFIG_SPI_FLASH_BAR - ret =write_bar (nor, addr); -if (ret <0 ) - goto erase_err; +/* Update Extended Address Register */ + ret =write_bar (nor, addr); +if (ret <0 ) + goto erase_err;#endif + } + ret =write_enable (nor);if (ret <0 ) goto erase_err;
@@ -1195,6 +1204,10 @@ static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)if (ret)return ret; + ret =write_disable (nor); +if (ret) +return ret; + ret =read_sr (nor);if (ret <0 )return ret;
@@ -1758,13 +1771,18 @@ static int sst26_lock_ctl(struct spi_nor *nor, loff_t ofs, uint64_t len, enum loif (ctl ==SST26_CTL_CHECK )return 0 ; +/* Write latch enable before write operation */ + ret =write_enable (nor); +if (ret) +return ret; + ret = nor->write_reg (nor,SPINOR_OP_WRITE_BPR , bpr_buff, bpr_size);if (ret <0 ) {dev_err (nor->dev,"fail to write block-protection register\n" );return ret; } -return 0 ; +return write_disable (nor); }static int sst26_unlock (struct spi_nor *nor,loff_t ofs,uint64_t len)
@@ -2138,7 +2156,7 @@ static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr)return ret; } -return 0 ; +return write_disable (nor); }/**
@@ -4248,6 +4266,7 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor)static int spi_nor_init (struct spi_nor *nor) { +u8 sr2;int err;if (nor->flags &SNOR_F_HAS_PARALLEL )
@@ -4271,6 +4290,22 @@ static int spi_nor_init(struct spi_nor *nor)write_enable (nor);write_sr (nor,0 );spi_nor_wait_till_ready (nor); + +if (JEDEC_MFR (nor->info) ==SNOR_MFR_WINBOND ) { +write_enable (nor); + sr2 =0 ; + err = nor->write_reg (nor, +SPINOR_OP_WIN_WRSR2 , &sr2,1 ); +if (err <0 ) { +dev_dbg (nor->dev, +"error while writing SR-2 register\n" ); +return -EINVAL ; + } +spi_nor_wait_till_ready (nor); + } + err =write_disable (nor); +if (err) +return err; }if (nor->quad_enable) {
Signature · 1 line
2.27.0
PATCH 12/30 mtd: spi-nor: Update erase operation function
In reply to Tejas BhumkarIf the system is in a dual parallel configuration, it's necessary to halve the erase size since the erase command operates on two flashes simultaneously. When dealing with a dual-stacked configuration, determine whether the erase offset refers to the top or bottom flash, and subsequently, adjust the flag for the relevant flash. Consequently, the argument for the spi_nor_erase_sector function has been modified from addr to offset.
--- drivers/mtd/spi/spi-nor-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/spi/spi-nor-core.c +2 -2
@@ -1078,7 +1078,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)if (nor->addr_width ==3 ) {#ifdef CONFIG_SPI_FLASH_BAR /* Update Extended Address Register */ - ret =write_bar (nor, addr); + ret =write_bar (nor, offset);if (ret <0 ) goto erase_err;#endif
@@ -1092,7 +1092,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) { ret = spi_nor_erase_chip(nor); } else { - ret =spi_nor_erase_sector (nor, addr); + ret =spi_nor_erase_sector (nor, offset); }if (ret <0 ) goto erase_err;
Signature · 1 line
2.27.0
PATCH 13/30 mtd: spi-nor: Check SNOR_F_IO_MODE_EN_VOLATILE only if SFDP is enabled
In reply to Tejas BhumkarFrom: Ashok Reddy Soma <[email protected]>
With 'commit bebdc237507c ("mtd: spi-nor: Parse SFDP SCCR Map")', support for spi_nor_parse_sccr is added under SFDP. But the flag SNOR_F_IO_MODE_EN_VOLATILE in spi_nor_octal_dtr_enable is always checked. Check this flag only if SPI_FLASH_SFDP_SUPPORT enabled.
--- drivers/mtd/spi/spi-nor-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/spi/spi-nor-core.c +3 -2
@@ -4252,8 +4252,9 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor) nor->write_proto == SNOR_PROTO_8_8_8_DTR))return 0 ; -if (!(nor->flags &SNOR_F_IO_MODE_EN_VOLATILE )) -return 0 ; +if (CONFIG_IS_ENABLED (SPI_FLASH_SFDP_SUPPORT )) +if (!(nor->flags &SNOR_F_IO_MODE_EN_VOLATILE )) +return 0 ; ret = nor->octal_dtr_enable (nor);if (ret)
Signature · 1 line
2.27.0
PATCH 14/30 spi: cadence_qspi: Setup ddr mode in cadence qspi driver
In reply to Tejas BhumkarFrom: T Karthik Reddy <[email protected]>
To switch the OSPI controller from SDR to DDR mode, the RX delay should be configured through flash tuning. Begin by establishing a constant value for the TX delay and then increase the RX delay by inspecting the flash IDs. To fine-tune the RX delay, compare the flash IDs with a set of predetermined "golden" flash IDs. This tuning process is borrowed from the Linux Cadence driver. Moreover, make the necessary adjustments in the DDR PHY setup to facilitate the transition from SDR to DDR mode within the OSPI controller.
--- drivers/spi/cadence_ospi_versal.c | 25 +++ drivers/spi/cadence_qspi.c | 321 +++++++++++++++++++++++++++++- drivers/spi/cadence_qspi.h | 52 +++++ drivers/spi/cadence_qspi_apb.c | 33 ++- 4 files changed, 416 insertions(+), 15 deletions(-)
drivers/spi/cadence_ospi_versal.c +25 -0
@@ -15,6 +15,7 @@#include <cpu_func.h> #include <zynqmp_firmware.h> #include <asm/arch/hardware.h> +#include <soc.h> #include "cadence_qspi.h" #include <dt-bindings/power/xlnx-versal-power.h>
@@ -129,6 +130,30 @@ int cadence_qspi_apb_wait_for_dma_cmplt(struct cadence_spi_priv *priv)return 0 ; } +static const struct soc_attr matches[] = { + { .family ="Versal" , .revision ="v2" }, + { } +}; + +/* +* cadence_qspi_versal_set_dll_mode checks for silicon version +* and set the DLL mode. +* Returns 0 in case of success, -ENOTSUPP in case of failure. +*/ +int cadence_qspi_versal_set_dll_mode (struct udevice *dev) +{ +struct cadence_spi_priv *priv =dev_get_priv (dev); +const struct soc_attr *attr; + + attr =soc_device_match (matches); +if (attr) { + priv->dll_mode =CQSPI_DLL_MODE_MASTER ; +return 0 ; + } + +return -ENOTSUPP ; +} +#if defined(CONFIG_DM_GPIO )int cadence_qspi_versal_flash_reset (struct udevice *dev) {
drivers/spi/cadence_qspi.c +315 -6
363 lines not on this page · raw message
drivers/spi/cadence_qspi.h +52 -0
104 lines not on this page · raw message
drivers/spi/cadence_qspi_apb.c +24 -9
@@ -465,6 +465,9 @@ int cadence_qspi_apb_command_read(struct cadence_spi_priv *priv,unsigned int dummy_clk;u8 opcode; +if (priv->dtr) + rxlen = ((rxlen %2 ) !=0 ) ? (rxlen +1 ) : rxlen; +if (priv->dtr) opcode = op->cmd.opcode >>8 ;else
@@ -477,6 +480,9 @@ int cadence_qspi_apb_command_read(struct cadence_spi_priv *priv,if (dummy_clk >CQSPI_DUMMY_CLKS_MAX )return -ENOTSUPP ; +if (priv->extra_dummy) + dummy_clk++; +if (dummy_clk) reg |= (dummy_clk &CQSPI_REG_CMDCTRL_DUMMY_MASK ) <<CQSPI_REG_CMDCTRL_DUMMY_LSB ;
@@ -553,6 +559,9 @@ int cadence_qspi_apb_command_write(struct cadence_spi_priv *priv,void *reg_base = priv->regbase;u8 opcode; + reg =cadence_qspi_calc_rdreg (priv); +writel (reg, reg_base +CQSPI_REG_RD_INSTR ); +if (priv->dtr) opcode = op->cmd.opcode >>8 ;else
@@ -609,7 +618,6 @@ int cadence_qspi_apb_command_write(struct cadence_spi_priv *priv,int cadence_qspi_apb_read_setup (struct cadence_spi_priv *priv,const struct spi_mem_op *op) { -unsigned int reg;unsigned int rd_reg;unsigned int dummy_clk;unsigned int dummy_bytes = op->dummy.nbytes;
@@ -647,6 +655,9 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv,if (dummy_clk >CQSPI_DUMMY_CLKS_MAX )return -ENOTSUPP ; +if (priv->extra_dummy) + dummy_clk++; +if (dummy_clk) rd_reg |= (dummy_clk &CQSPI_REG_RD_INSTR_DUMMY_MASK ) <<CQSPI_REG_RD_INSTR_DUMMY_LSB ;
@@ -655,10 +666,10 @@ int cadence_qspi_apb_read_setup(struct cadence_spi_priv *priv,writel (rd_reg, priv->regbase +CQSPI_REG_RD_INSTR );/* set device size */ - reg =readl (priv->regbase +CQSPI_REG_SIZE ); - reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK ; - reg |= (op->addr.nbytes -1 ); -writel (reg, priv->regbase +CQSPI_REG_SIZE ); +clrsetbits_le32 (priv->regbase +CQSPI_REG_SIZE , +CQSPI_REG_SIZE_ADDRESS_MASK , + op->addr.nbytes -1 ); +return 0 ; }
@@ -828,10 +839,10 @@ int cadence_qspi_apb_write_setup(struct cadence_spi_priv *priv,writel (reg, priv->regbase +CQSPI_REG_WR_COMPLETION_CTRL ); } - reg =readl (priv->regbase +CQSPI_REG_SIZE ); - reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK ; - reg |= (op->addr.nbytes -1 ); -writel (reg, priv->regbase +CQSPI_REG_SIZE ); +clrsetbits_le32 (priv->regbase +CQSPI_REG_SIZE , +CQSPI_REG_SIZE_ADDRESS_MASK , + op->addr.nbytes -1 ); +return 0 ; }
@@ -846,6 +857,10 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv,unsigned int write_bytes;int ret; +if (priv->edge_mode ==CQSPI_EDGE_MODE_DDR && (n_tx %2 ) !=0 ) + n_tx++; + remaining = n_tx; +/* * Use bounce buffer for non 32 bit aligned txbuf to avoid data * aborts
Signature · 1 line
2.27.0
PATCH 15/30 spi: cadence-qspi: Switch SDR/DTR using SPI_FLASH_DTR_ENABLE config
In reply to Tejas BhumkarFrom: T Karthik Reddy <[email protected]>
Cadence driver need to switch from SDR to DTR and vice versa based on the commands from spi-nor framework and based on SPI_FLASH_DTR_ENABLE config. If SPI_FLASH_DTR_ENABLE is not defined, do not switch to DTR mode as it represents that controller does not support DTR. Also do not reinitilize the SDR/DTR tuning if it is already done. Also added the functionality to reset the controller when switching from DTR to STR mode.
Use reset_assert, reset_deassert api's to reset the ospi controller. In mini U-Boot case as ZYNQMP_FIRMWARE config is disabled, reset the controller directly using register writes.
The configuration of the chip select in the Cadence QSPI driver is now determined based on the flags received from SPI-NOR framework.
--- drivers/spi/cadence_ospi_versal.c | 29 +++++++++++++ drivers/spi/cadence_qspi.c | 69 ++++++++++++++++++++++++++++--- drivers/spi/cadence_qspi.h | 7 ++++ 3 files changed, 99 insertions(+), 6 deletions(-)
drivers/spi/cadence_ospi_versal.c +29 -0
@@ -154,6 +154,35 @@ int cadence_qspi_versal_set_dll_mode(struct udevice *dev)return -ENOTSUPP ; } +int cadence_spi_versal_ctrl_reset (struct cadence_spi_priv *priv) +{ +int ret; + +if (CONFIG_IS_ENABLED (ZYNQMP_FIRMWARE )) { +/* Assert ospi controller */ + ret =reset_assert (priv->resets->resets); +if (ret) +return ret; + +udelay (10 ); + +/* Deassert ospi controller */ + ret =reset_deassert (priv->resets->resets); +if (ret) +return ret; + }else { +/* Assert ospi controller */ +setbits_le32 ((u32 *)OSPI_CTRL_RST ,1 ); + +udelay (10 ); + +/* Deassert ospi controller */ +clrbits_le32 ((u32 *)OSPI_CTRL_RST ,1 ); + } + +return 0 ; +} +#if defined(CONFIG_DM_GPIO )int cadence_qspi_versal_flash_reset (struct udevice *dev) {
drivers/spi/cadence_qspi.c +63 -6
106 lines not on this page · raw message
drivers/spi/cadence_qspi.h +7 -0
@@ -18,6 +18,9 @@#define CQSPI_DECODER_MAX_CS 16#define CQSPI_READ_CAPTURE_MAX_DELAY 16 +#define CQSPI_CS0 0 +#define CQSPI_CS1 1 +#define CQSPI_REG_POLL_US 1/* 1us */ #define CQSPI_REG_RETRY 10000#define CQSPI_POLL_IDLE_RETRY 3
@@ -53,6 +56,8 @@#define CQSPI_READID_LOOP_MAX 10#define TERA_MACRO 1000000000000l +#define OSPI_CTRL_RST 0xF1260304 +/**************************************************************************** * Controller's configuration and status register (offset from QSPI_BASE) ****************************************************************************/
@@ -284,6 +289,7 @@ struct cadence_spi_priv {size_t data_len;int qspi_is_init; +unsigned int cs;unsigned int qspi_calibrated_hz;unsigned int qspi_calibrated_cs;unsigned int previous_hz;
@@ -357,5 +363,6 @@ int cadence_qspi_apb_exec_flash_cmd(void *reg_base, unsigned int reg);int cadence_qspi_versal_flash_reset (struct udevice *dev);int cadence_qspi_versal_set_dll_mode (struct udevice *dev);void cadence_qspi_apb_enable_linear_mode (bool enable); +int cadence_spi_versal_ctrl_reset (struct cadence_spi_priv *priv);#endif /* __CADENCE_QSPI_H__ */
Signature · 1 line
2.27.0
PATCH 16/30 spi: cadence_ospi_versal: ospi ddr changes in cadence ospi versal driver
In reply to Tejas BhumkarFrom: T Karthik Reddy <[email protected]>
Set cmd, address & data buswidth to octal. Handle dummy clock cycles incase of reads & writes. Convert odd bytes to even bytes lengths in ddr mode, as we cannot rx/tx odd data in ddr mode.
Disable the DMA once the transfer is done to avoid disabling it at other places.
--- drivers/spi/cadence_ospi_versal.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/spi/cadence_ospi_versal.c +15 -8
@@ -21,12 +21,13 @@#define CMD_4BYTE_READ 0x13#define CMD_4BYTE_FAST_READ 0x0C +#define CMD_4BYTE_OCTAL_READ 0x7cint cadence_qspi_apb_dma_read (struct cadence_spi_priv *priv,const struct spi_mem_op *op) {u32 reg, ret, rx_rem, n_rx, bytes_to_dma, data; -u8 opcode, addr_bytes, *rxbuf, dummy_cycles; +u8 opcode, addr_bytes, *rxbuf, dummy_cycles, unaligned_byte; n_rx = op->data.nbytes; rxbuf = op->data.buf.in;
@@ -70,13 +71,14 @@ int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv,writel (CQSPI_REG_INDIRECTRD_DONE , priv->regbase +CQSPI_REG_INDIRECTRD ); rxbuf += bytes_to_dma; - } -if (rx_rem) { +/* Disable DMA on completion */ reg =readl (priv->regbase +CQSPI_REG_CONFIG ); reg &= ~CQSPI_REG_CONFIG_ENBL_DMA ;writel (reg, priv->regbase +CQSPI_REG_CONFIG ); + } +if (rx_rem) { reg =readl (priv->regbase +CQSPI_REG_INDIRECTRDSTARTADDR ); reg += bytes_to_dma;writel (reg, priv->regbase +CQSPI_REG_CMDADDRESS );
@@ -84,10 +86,10 @@ int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv, addr_bytes =readl (priv->regbase +CQSPI_REG_SIZE ) &CQSPI_REG_SIZE_ADDRESS_MASK ; - opcode =CMD_4BYTE_FAST_READ ; - dummy_cycles =8 ; -writel ((dummy_cycles <<CQSPI_REG_RD_INSTR_DUMMY_LSB ) | opcode, - priv->regbase +CQSPI_REG_RD_INSTR ); + opcode = (u8 )readl (priv->regbase +CQSPI_REG_RD_INSTR ); +if (opcode ==CMD_4BYTE_OCTAL_READ && + priv->edge_mode !=CQSPI_EDGE_MODE_DDR ) + opcode =CMD_4BYTE_FAST_READ ; reg = opcode <<CQSPI_REG_CMDCTRL_OPCODE_LSB ; reg |= (0x1 <<CQSPI_REG_CMDCTRL_RD_EN_LSB );
@@ -99,7 +101,12 @@ int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv,CQSPI_REG_RD_INSTR_DUMMY_MASK ; reg |= (dummy_cycles &CQSPI_REG_CMDCTRL_DUMMY_MASK ) <<CQSPI_REG_CMDCTRL_DUMMY_LSB ; - reg |= (((rx_rem -1 ) &CQSPI_REG_CMDCTRL_RD_BYTES_MASK ) << +if (priv->edge_mode ==CQSPI_EDGE_MODE_DDR && (rx_rem %2 ) !=0 ) + unaligned_byte =1 ; +else + unaligned_byte =0 ; + reg |= (((rx_rem -1 + unaligned_byte) & +CQSPI_REG_CMDCTRL_RD_BYTES_MASK ) <<CQSPI_REG_CMDCTRL_RD_BYTES_LSB ); ret =cadence_qspi_apb_exec_flash_cmd (priv->regbase, reg);if (ret)
Signature · 1 line
2.27.0
PATCH 17/30 spi: cadence_qspi: Fix versal ospi indirect write timed out issue
In reply to Tejas BhumkarTo reduce the CPU load in waiting for the OSPI internal SRAM to clear in indirect mode, it's better to use the CQSPI_REG_IRQSTATUS register to check for indirect operation to complete. Enabled interrupt for Indirect Complete and Transfer Watermark Breach interrupt status register bits and using readl_poll_timeout function to poll for Indirect Operation Complete bit gets set.
Here not enabling IRQ coming to GIC, only IRQ from IP itself is able to poll bits.
It is observed that the Indirect Operation Complete bit is getting set at an average time of 0.172 usec.
--- drivers/spi/cadence_qspi.h | 11 +++++++++++ drivers/spi/cadence_qspi_apb.c | 24 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-)
drivers/spi/cadence_qspi.h +11 -0
@@ -252,6 +252,17 @@ (((readl ((reg_base) +CQSPI_REG_SDRAMLEVEL )) >> \CQSPI_REG_SDRAMLEVEL_WR_LSB ) &CQSPI_REG_SDRAMLEVEL_WR_MASK ) +/* Interrupt status bits */ +#define CQSPI_REG_IRQ_UNDERFLOW BIT(1) +#define CQSPI_REG_IRQ_IND_COMP BIT(2) +#define CQSPI_REG_IRQ_WATERMARK BIT(6) + +#define CQSPI_IRQ_MASK_WR (CQSPI_REG_IRQ_IND_COMP | \ + CQSPI_REG_IRQ_WATERMARK | \ + CQSPI_REG_IRQ_UNDERFLOW) + +#define CQSPI_IRQ_STATUS_MASK GENMASK(16, 0) +struct cadence_spi_plat {unsigned int max_hz;void *regbase;
drivers/spi/cadence_qspi_apb.c +19 -5
@@ -32,6 +32,7 @@#include <linux/bitops.h> #include <linux/delay.h> #include <linux/errno.h> +#include <linux/iopoll.h> #include <wait_bit.h> #include <spi.h> #include <spi-mem.h>
@@ -855,7 +856,7 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv,const u8 *bb_txbuf = txbuf;void *bounce_buf =NULL ;unsigned int write_bytes; -int ret; +int ret, cr;if (priv->edge_mode ==CQSPI_EDGE_MODE_DDR && (n_tx %2 ) !=0 ) n_tx++;
@@ -873,9 +874,15 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv, bb_txbuf = bounce_buf; } -/* Configure the indirect read transfer bytes */ +/* Configure the indirect write transfer bytes */ writel (n_tx, priv->regbase +CQSPI_REG_INDIRECTWRBYTES ); +/* Clear all interrupts */ +writel (CQSPI_IRQ_STATUS_MASK , priv->regbase +CQSPI_REG_IRQSTATUS ); + +/* Enable interrupt for corresponding interrupt status register bit's */ +writel (CQSPI_IRQ_MASK_WR , priv->regbase +CQSPI_REG_IRQMASK ); +/* Start the indirect write transfer */ writel (CQSPI_REG_INDIRECTWR_START , priv->regbase +CQSPI_REG_INDIRECTWR );
@@ -894,9 +901,10 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv, bb_txbuf +rounddown (write_bytes,4 ), write_bytes % 4); - ret =wait_for_bit_le32 (priv->regbase +CQSPI_REG_SDRAMLEVEL , -CQSPI_REG_SDRAMLEVEL_WR_MASK << -CQSPI_REG_SDRAMLEVEL_WR_LSB ,0 ,10 ,0 ); +/* Wait up to Indirect Operation Complete bit to set */ + ret =readl_poll_timeout (priv->regbase +CQSPI_REG_IRQSTATUS , cr, + cr &CQSPI_REG_IRQ_IND_COMP ,10 ); +if (ret) {printf ("Indirect write timed out (%i)\n" , ret); goto failwr;
@@ -914,6 +922,9 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv, goto failwr; } +/* Disable interrupt. */ +writel (0 , priv->regbase +CQSPI_REG_IRQMASK ); +/* Clear indirect completion status */ writel (CQSPI_REG_INDIRECTWR_DONE , priv->regbase +CQSPI_REG_INDIRECTWR );
@@ -931,6 +942,9 @@ cadence_qspi_apb_indirect_write_execute(struct cadence_spi_priv *priv,return 0 ; failwr: +/* Disable interrupt. */ +writel (0 , priv->regbase +CQSPI_REG_IRQMASK ); +/* Cancel the indirect write */ writel (CQSPI_REG_INDIRECTWR_CANCEL , priv->regbase +CQSPI_REG_INDIRECTWR );
Signature · 1 line
2.27.0
PATCH 18/30 spi: cadence_qspi: Set tshsl_ns to at least one sclk_ns
In reply to Tejas BhumkarFrom: Ashok Reddy Soma <[email protected]>
tshsl_ns is the clock delay for chip select deassert. This is the delay in master reference clocks for the length that the master mode chip select outputs are de-asserted between transactions.
The minimum delay is always SCLK period to ensure the chip select is never re-asserted within one SCLK period.
That is why tshsl_ns delay should be at least one sclk_ns value. If it is less than sclk_ns, set it equal to sclk_ns.
--- drivers/spi/cadence_qspi_apb.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/spi/cadence_qspi_apb.c +4 -0
@@ -306,6 +306,10 @@ void cadence_qspi_apb_delay(void *reg_base, tshsl_ns -= sclk_ns + ref_clk_ns;if (tchsh_ns >= sclk_ns +3 * ref_clk_ns) tchsh_ns -= sclk_ns +3 * ref_clk_ns; + +if (tshsl_ns < sclk_ns) + tshsl_ns = sclk_ns; + tshsl =DIV_ROUND_UP (tshsl_ns, ref_clk_ns); tchsh =DIV_ROUND_UP (tchsh_ns, ref_clk_ns); tslch =DIV_ROUND_UP (tslch_ns, ref_clk_ns);
Signature · 1 line
2.27.0
PATCH 19/30 spi: cadence_qspi: Clean up registers in init
In reply to Tejas BhumkarFrom: Ashok Reddy Soma <[email protected]>
This patch cleans up the cadence qspi registers in the init. The register contents may be invalid if this controller is used in previous boot and comes to uboot after a softreset (no power on reset). This may cause issues in uboot.
--- drivers/spi/cadence_qspi_apb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/spi/cadence_qspi_apb.c +22 -0
@@ -346,12 +346,34 @@ void cadence_qspi_apb_controller_init(struct cadence_spi_priv *priv)/* Configure the remap address register, no remap */ writel (0 , priv->regbase +CQSPI_REG_REMAP ); +/* Clear instruction read config register */ +writel (0 , priv->regbase +CQSPI_REG_RD_INSTR ); + +/* Reset the Delay lines */ +writel (CQSPI_REG_PHY_CONFIG_RESET_FLD_MASK , + priv->regbase +CQSPI_REG_PHY_CONFIG ); + + reg =readl (priv->regbase +CQSPI_REG_RD_DATA_CAPTURE ); + reg &= ~CQSPI_REG_READCAPTURE_DQS_ENABLE ; + reg &= ~(CQSPI_REG_RD_DATA_CAPTURE_DELAY_MASK + <<CQSPI_REG_RD_DATA_CAPTURE_DELAY_LSB ); +writel (reg, priv->regbase +CQSPI_REG_RD_DATA_CAPTURE ); +/* Indirect mode configurations */ writel (priv->fifo_depth /2 , priv->regbase +CQSPI_REG_SRAMPARTITION );/* Disable all interrupts */ writel (0 , priv->regbase +CQSPI_REG_IRQMASK ); + reg =readl (priv->regbase +CQSPI_REG_CONFIG ); + reg &= ~CQSPI_REG_CONFIG_DTR_PROT_EN_MASK ; + reg &= ~CQSPI_REG_CONFIG_PHY_ENABLE_MASK ; + reg &= ~CQSPI_REG_CONFIG_DIRECT ; + reg &= ~(CQSPI_REG_CONFIG_CHIPSELECT_MASK + <<CQSPI_REG_CONFIG_CHIPSELECT_LSB ); + +writel (reg, priv->regbase +CQSPI_REG_CONFIG ); +cadence_qspi_apb_controller_enable (priv->regbase); }
Signature · 1 line
2.27.0