mtd: spi-nor: add support to SPI 1-2-2 and SPI 1-4-4 protocols
Subsystems (5)
cover mtd: spi-nor: add support to SPI 1-2-2 and SPI 1-4-4 protocols
Hi all,
this series of patches updates the spi-nor framework to add support to more SPI protocols. Also the 3rd argument of spi_nor_scan() is changed so we can now make the difference between read and write operations. Indeed some SPI controllers may support Quad SPI protocols only for read operations but not for write operations.
The new argument is designed so SPI controller drivers can precisely describe their hardware capabilies to the spi-nor framework. In turn, this framework selects the right SPI protocols, op code, number of dummy cycles and so on for (Fast) Read and Page Program commands by computing the best match between the SPI memory and controller hardware capabilities.
Please note that a spi_nor_basic_flash_parameter structure is also introduced by this series. It's used to describe the hardware capabilities and requirements of SPI memories. The structure fields are based on what can be read from the SFDP Basic Flash Parameter table of the JESD216B specification. Indeed this series of patch is also a base for a further series which will add support to the SFDP tables in the spi-nor framework.
This series is based on the next branch of the spi-nor tree.
Best regards,
Cyrille
Cyrille Pitchen (3):
mtd: spi-nor: add support of SPI protocols like SPI 1-2-2 and SPI
1-4-4
mtd: spi-nor: remove unused set_quad_mode() function
mtd: m25p80: add support of SPI 1-2-2 and 1-4-4 protocols
drivers/mtd/devices/m25p80.c | 133 +++++++++++---- drivers/mtd/spi-nor/aspeed-smc.c | 22 +-- drivers/mtd/spi-nor/atmel-quadspi.c | 82 ++++++---- drivers/mtd/spi-nor/cadence-quadspi.c | 18 ++- drivers/mtd/spi-nor/fsl-quadspi.c | 8 +- drivers/mtd/spi-nor/hisi-sfc.c | 31 +++- drivers/mtd/spi-nor/intel-spi.c | 6 +- drivers/mtd/spi-nor/mtk-quadspi.c | 16 +- drivers/mtd/spi-nor/nxp-spifi.c | 21 +-- drivers/mtd/spi-nor/spi-nor.c | 295 +++++++++++++++++++++++++--------- include/linux/mtd/spi-nor.h | 163 +++++++++++++++++-- 11 files changed, 604 insertions(+), 191 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 mtd: spi-nor: add support of SPI protocols like SPI 1-2-2 and SPI 1-4-4
This patch changes the prototype of spi_nor_scan(): its 3rd parameter is replaced by a const struct spi_nor_modes pointer, which tells the spi-nor framework about which SPI protocols are supported by the SPI controller.
Besides, this patch also introduces a new spi_nor_basic_flash_parameter structure telling the spi-nor framework about the SPI protocols supported by the SPI memory and the needed op codes to use these SPI protocols.
Currently the struct spi_nor_basic_flash_parameter is filled with legacy values but a later patch will allow to fill it dynamically by reading the JESD216 Serial Flash Discoverable Parameter (SFDP) tables from the SPI memory.
With both structures, the spi-nor framework can now compute the best match between SPI protocols supported by both the (Q)SPI memory and controller hence selecting the relevant op codes for (Fast) Read, Page Program and Sector Erase operations.
The spi_nor_basic_flash_parameter structure also provides the spi-nor framework with the number of dummy cycles to be used with each Fast Read commands and the erase block size associated to the erase block op codes.
Finally the spi_nor_basic_flash_parameter structure, through the optional .enable_quad_io() hook, tells the spi-nor framework how to set the Quad Enable (QE) bit of the QSPI memory to enable its Quad SPI features.
--- drivers/mtd/devices/m25p80.c | 17 ++- drivers/mtd/spi-nor/aspeed-smc.c | 22 +-- drivers/mtd/spi-nor/atmel-quadspi.c | 82 ++++++---- drivers/mtd/spi-nor/cadence-quadspi.c | 18 ++- drivers/mtd/spi-nor/fsl-quadspi.c | 8 +- drivers/mtd/spi-nor/hisi-sfc.c | 31 +++- drivers/mtd/spi-nor/intel-spi.c | 6 +- drivers/mtd/spi-nor/mtk-quadspi.c | 16 +- drivers/mtd/spi-nor/nxp-spifi.c | 21 +-- drivers/mtd/spi-nor/spi-nor.c | 271 +++++++++++++++++++++++++++------- include/linux/mtd/spi-nor.h | 163 ++++++++++++++++++-- 11 files changed, 515 insertions(+), 140 deletions(-)
drivers/mtd/devices/m25p80.c +10 -7
@@ -111,10 +111,10 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,static inline unsigned int m25p80_rx_nbits (struct spi_nor *nor) { -switch (nor->flash_read) { -case SPI_NOR_DUAL : +switch (nor->read_proto) { +case SNOR_PROTO_1_1_2 :return 2 ; -case SPI_NOR_QUAD : +case SNOR_PROTO_1_1_4 :return 4 ;default :return 0 ;
@@ -196,7 +196,10 @@ static int m25p_probe(struct spi_device *spi)struct flash_platform_data *data;struct m25p *flash;struct spi_nor *nor; -enum read_mode mode =SPI_NOR_NORMAL ; +struct spi_nor_modes modes = { + .rd_modes =SNOR_MODE_SLOW , + .wr_modes =SNOR_MODE_1_1_1 , + };char *flash_name;int ret;
@@ -222,9 +225,9 @@ static int m25p_probe(struct spi_device *spi) flash->spi = spi;if (spi->mode &SPI_RX_QUAD ) - mode =SPI_NOR_QUAD ; + modes.rd_modes |=SNOR_MODE_1_1_4 ;else if (spi->mode &SPI_RX_DUAL ) - mode =SPI_NOR_DUAL ; + modes.rd_modes |=SNOR_MODE_1_1_2 ;if (data && data->name) nor->mtd.name = data->name;
@@ -241,7 +244,7 @@ static int m25p_probe(struct spi_device *spi)else flash_name = spi->modalias; - ret =spi_nor_scan (nor, flash_name, mode); + ret =spi_nor_scan (nor, flash_name, &modes);if (ret)return ret;
drivers/mtd/spi-nor/aspeed-smc.c +12 -10
@@ -585,14 +585,12 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)* TODO: Adjust clocks if fast read is supported and interpret * SPI-NOR flags to adjust controller settings. */ -switch (chip->nor.flash_read) { -case SPI_NOR_NORMAL : - cmd =CONTROL_COMMAND_MODE_NORMAL ; -break ; -case SPI_NOR_FAST : - cmd =CONTROL_COMMAND_MODE_FREAD ; -break ; -default : +if (chip->nor.read_proto ==SNOR_PROTO_1_1_1 ) { +if (chip->nor.read_dummy ==0 ) + cmd =CONTROL_COMMAND_MODE_NORMAL ; +else + cmd =CONTROL_COMMAND_MODE_FREAD ; + }else {dev_err (chip->nor.dev,"unsupported SPI read mode\n" );return -EINVAL ; }
@@ -608,6 +606,10 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)static int aspeed_smc_setup_flash (struct aspeed_smc_controller *controller,struct device_node *np,struct resource *r) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW |SNOR_MODE_1_1_1 ), + .wr_modes =SNOR_MODE_1_1_1 , + };const struct aspeed_smc_info *info = controller->info;struct device *dev = controller->dev;struct device_node *child;
@@ -671,11 +673,11 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller,break ;/* -* TODO: Add support for SPI_NOR_QUAD and SPI_NOR_DUAL +* TODO: Add support for SNOR_MODE_1_*_4 and SNOR_MODE_1_*_2 * attach when board support is present as determined * by of property. */ - ret =spi_nor_scan (nor,NULL ,SPI_NOR_NORMAL ); + ret =spi_nor_scan (nor,NULL , &modes);if (ret)break ;
drivers/mtd/spi-nor/atmel-quadspi.c +55 -27
144 lines not on this page · raw message
drivers/mtd/spi-nor/cadence-quadspi.c +12 -6
@@ -855,15 +855,14 @@ static int cqspi_set_protocol(struct spi_nor *nor, const int read) f_pdata->data_width =CQSPI_INST_TYPE_SINGLE ;if (read) { -switch (nor->flash_read) { -case SPI_NOR_NORMAL : -case SPI_NOR_FAST : +switch (nor->read_proto) { +case SNOR_PROTO_1_1_1 : f_pdata->data_width =CQSPI_INST_TYPE_SINGLE ;break ; -case SPI_NOR_DUAL : +case SNOR_PROTO_1_1_2 : f_pdata->data_width =CQSPI_INST_TYPE_DUAL ;break ; -case SPI_NOR_QUAD : +case SNOR_PROTO_1_1_4 : f_pdata->data_width =CQSPI_INST_TYPE_QUAD ;break ;default :
@@ -1069,6 +1068,13 @@ static void cqspi_controller_init(struct cqspi_st *cqspi)static int cqspi_setup_flash (struct cqspi_st *cqspi,struct device_node *np) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW | +SNOR_MODE_1_1_1 | +SNOR_MODE_1_1_2 | +SNOR_MODE_1_1_4 ), + .wr_modes =SNOR_MODE_1_1_1 , + };struct platform_device *pdev = cqspi->pdev;struct device *dev = &pdev->dev;struct cqspi_flash_pdata *f_pdata;
@@ -1123,7 +1129,7 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi, struct device_node *np) goto err; } - ret =spi_nor_scan (nor,NULL ,SPI_NOR_QUAD ); + ret =spi_nor_scan (nor,NULL , &modes);if (ret) goto err;
drivers/mtd/spi-nor/fsl-quadspi.c +7 -1
@@ -973,6 +973,12 @@ static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)static int fsl_qspi_probe (struct platform_device *pdev) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW | +SNOR_MODE_1_1_1 | +SNOR_MODE_1_1_4 ), + .wr_modes =SNOR_MODE_1_1_1 , + };struct device_node *np = pdev->dev.of_node;struct device *dev = &pdev->dev;struct fsl_qspi *q;
@@ -1081,7 +1087,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)/* set the chip address for READID */ fsl_qspi_set_base_addr (q, nor); - ret =spi_nor_scan (nor,NULL ,SPI_NOR_QUAD ); + ret =spi_nor_scan (nor,NULL , &modes);if (ret) goto mutex_failed;
drivers/mtd/spi-nor/hisi-sfc.c +23 -8
@@ -120,19 +120,24 @@ static inline int wait_op_finish(struct hifmc_host *host) (reg & FMC_INT_OP_DONE), 0, FMC_WAIT_TIMEOUT); } -static int get_if_type (enum read_mode flash_read) +static int get_if_type (enum spi_nor_protocol proto) {enum hifmc_iftype if_type; -switch (flash_read) { -case SPI_NOR_DUAL : +switch (proto) { +case SNOR_PROTO_1_1_2 : if_type =IF_TYPE_DUAL ;break ; -case SPI_NOR_QUAD : +case SNOR_PROTO_1_2_2 : + if_type =IF_TYPE_DIO ; +break ; +case SNOR_PROTO_1_1_4 : if_type =IF_TYPE_QUAD ;break ; -case SPI_NOR_NORMAL : -case SPI_NOR_FAST : +case SNOR_PROTO_1_4_4 : + if_type =IF_TYPE_QIO ; +break ; +case SNOR_PROTO_1_1_1 :default : if_type =IF_TYPE_STD ;break ;
@@ -253,7 +258,10 @@ static int hisi_spi_nor_dma_transfer(struct spi_nor *nor, loff_t start_off,writel (FMC_DMA_LEN_SET (len), host->regbase +FMC_DMA_LEN ); reg =OP_CFG_FM_CS (priv->chipselect); - if_type =get_if_type (nor->flash_read); +if (op_type ==FMC_OP_READ ) + if_type =get_if_type (nor->read_proto); +else + if_type =get_if_type (nor->write_proto); reg |=OP_CFG_MEM_IF_TYPE (if_type);if (op_type ==FMC_OP_READ ) reg |=OP_CFG_DUMMY_NUM (nor->read_dummy >>3 );
@@ -321,6 +329,13 @@ static ssize_t hisi_spi_nor_write(struct spi_nor *nor, loff_t to,static int hisi_spi_nor_register (struct device_node *np,struct hifmc_host *host) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW | +SNOR_MODE_1_1_1 | +SNOR_MODE_1_1_2 | +SNOR_MODE_1_1_4 ), + .wr_modes =SNOR_MODE_1_1_1 , + };struct device *dev = host->dev;struct spi_nor *nor;struct hifmc_priv *priv;
@@ -362,7 +377,7 @@ static int hisi_spi_nor_register(struct device_node *np, nor->read = hisi_spi_nor_read; nor->write = hisi_spi_nor_write; nor->erase =NULL ; - ret =spi_nor_scan (nor,NULL ,SPI_NOR_QUAD ); + ret =spi_nor_scan (nor,NULL , &modes);if (ret)return ret;
drivers/mtd/spi-nor/intel-spi.c +5 -1
@@ -715,6 +715,10 @@ static void intel_spi_fill_partition(struct intel_spi *ispi,struct intel_spi *intel_spi_probe (struct device *dev,struct resource *mem,const struct intel_spi_boardinfo *info) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW |SNOR_MODE_1_1_1 ), + .wr_modes =SNOR_MODE_1_1_1 , + };struct mtd_partition part;struct intel_spi *ispi;int ret;
@@ -746,7 +750,7 @@ struct intel_spi *intel_spi_probe(struct device *dev, ispi->nor.write = intel_spi_write; ispi->nor.erase = intel_spi_erase; - ret =spi_nor_scan (&ispi->nor,NULL ,SPI_NOR_NORMAL ); + ret =spi_nor_scan (&ispi->nor,NULL , &modes);if (ret) {dev_info (dev,"failed to locate the chip\n" );return ERR_PTR (ret);
drivers/mtd/spi-nor/mtk-quadspi.c +11 -5
@@ -121,20 +121,20 @@ static void mt8173_nor_set_read_mode(struct mt8173_nor *mt8173_nor) {struct spi_nor *nor = &mt8173_nor->nor; -switch (nor->flash_read) { -case SPI_NOR_FAST : +switch (nor->read_proto) { +case SNOR_PROTO_1_1_1 :writeb (nor->read_opcode, mt8173_nor->base +MTK_NOR_PRGDATA3_REG );writeb (MTK_NOR_FAST_READ , mt8173_nor->base +MTK_NOR_CFG1_REG );break ; -case SPI_NOR_DUAL : +case SNOR_PROTO_1_1_2 :writeb (nor->read_opcode, mt8173_nor->base +MTK_NOR_PRGDATA3_REG );writeb (MTK_NOR_DUAL_READ_EN , mt8173_nor->base +MTK_NOR_DUAL_REG );break ; -case SPI_NOR_QUAD : +case SNOR_PROTO_1_1_4 :writeb (nor->read_opcode, mt8173_nor->base +MTK_NOR_PRGDATA4_REG ); writeb(MTK_NOR_QUAD_READ_EN, mt8173_nor->base +
@@ -381,6 +381,12 @@ static int mt8173_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf,static int mtk_nor_init (struct mt8173_nor *mt8173_nor,struct device_node *flash_node) { +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW | +SNOR_MODE_1_1_1 | +SNOR_MODE_1_1_2 ), + .wr_modes =SNOR_MODE_1_1_1 , + };int ret;struct spi_nor *nor;
@@ -399,7 +405,7 @@ static int mtk_nor_init(struct mt8173_nor *mt8173_nor, nor->write_reg = mt8173_nor_write_reg; nor->mtd.name ="mtk_nor" ;/* initialized with NULL */ - ret =spi_nor_scan (nor,NULL ,SPI_NOR_DUAL ); + ret =spi_nor_scan (nor,NULL , &modes);if (ret)return ret;
drivers/mtd/spi-nor/nxp-spifi.c +11 -10
@@ -240,13 +240,12 @@ static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs)static int nxp_spifi_setup_memory_cmd (struct nxp_spifi *spifi) { -switch (spifi->nor.flash_read) { -case SPI_NOR_NORMAL : -case SPI_NOR_FAST : +switch (spifi->nor.read_proto) { +case SNOR_PROTO_1_1_1 : spifi->mcmd =SPIFI_CMD_FIELDFORM_ALL_SERIAL ;break ; -case SPI_NOR_DUAL : -case SPI_NOR_QUAD : +case SNOR_PROTO_1_1_2 : +case SNOR_PROTO_1_1_4 : spifi->mcmd =SPIFI_CMD_FIELDFORM_QUAD_DUAL_DATA ;break ;default :
@@ -274,7 +273,10 @@ static void nxp_spifi_dummy_id_read(struct spi_nor *nor)static int nxp_spifi_setup_flash (struct nxp_spifi *spifi,struct device_node *np) { -enum read_mode flash_read; +struct spi_nor_modes modes = { + .rd_modes = (SNOR_MODE_SLOW |SNOR_MODE_1_1_1 ), + .wr_modes =SNOR_MODE_1_1_1 , + };u32 ctrl, property;u16 mode =0 ;int ret;
@@ -308,13 +310,12 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,if (mode &SPI_RX_DUAL ) { ctrl |=SPIFI_CTRL_DUAL ; - flash_read =SPI_NOR_DUAL ; + modes.rd_modes |=SNOR_MODE_1_1_2 ; }else if (mode &SPI_RX_QUAD ) { ctrl &= ~SPIFI_CTRL_DUAL ; - flash_read =SPI_NOR_QUAD ; + modes.rd_modes |=SNOR_MODE_1_1_4 ; }else { ctrl |=SPIFI_CTRL_DUAL ; - flash_read =SPI_NOR_NORMAL ; }switch (mode & (SPI_CPHA |SPI_CPOL )) {
@@ -351,7 +352,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,*/ nxp_spifi_dummy_id_read (&spifi->nor); - ret =spi_nor_scan (&spifi->nor,NULL , flash_read); + ret =spi_nor_scan (&spifi->nor,NULL , &modes);if (ret) {dev_err (spifi->dev,"device scan failed\n" );return ret;
drivers/mtd/spi-nor/spi-nor.c +215 -56
318 lines not on this page · raw message
include/linux/mtd/spi-nor.h +154 -9
194 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/3 mtd: spi-nor: remove unused set_quad_mode() function
In reply to Cyrille PitchenThe set_quad_mode() function is no longer used, so we remove it.
This patch is not squashed into the previous patch on purpose for readiness issue and to ease the review process of the whole series.
--- drivers/mtd/spi-nor/spi-nor.c | 24 ------------------------ 1 file changed, 24 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +0 -24
@@ -1432,30 +1432,6 @@ static int spansion_quad_enable(struct spi_nor *nor)return 0 ; } -static int set_quad_mode (struct spi_nor *nor,const struct flash_info *info) -{ -int status; - -switch (JEDEC_MFR (info)) { -case SNOR_MFR_MACRONIX : - status =macronix_quad_enable (nor); -if (status) { -dev_err (nor->dev,"Macronix quad-read not enabled\n" ); -return -EINVAL ; - } -return status; -case SNOR_MFR_MICRON : -return 0 ; -default : - status =spansion_quad_enable (nor); -if (status) { -dev_err (nor->dev,"Spansion quad-read not enabled\n" ); -return -EINVAL ; - } -return status; - } -} -static int spi_nor_check (struct spi_nor *nor) { if (!nor->dev || !nor->read || !nor->write ||
Signature · 1 line
2.7.4
PATCH 3/3 mtd: m25p80: add support of SPI 1-2-2 and 1-4-4 protocols
In reply to Cyrille PitchenBefore this patch, m25p80_read() supported few SPI protocols:
- regular SPI 1-1-1
- SPI Dual Output 1-1-2
- SPI Quad Output 1-1-4
On the other hand, m25p80_write() only supported SPI 1-1-1.
This patch updates both m25p80_read() and m25p80_write() functions to let them support SPI 1-2-2 and SPI 1-4-4 protocols for Fast Read and Page Program SPI commands.
It adopts a conservative approach to avoid regressions. Hence the new implementations try to be as close as possible to the old implementations, so the main differences are:
- the tx_nbits values now being set properly for the spi_transfer structures carrying the (op code + address/dummy) bytes
- and the spi_transfer structure being split into 2 spi_transfer structures when the numbers of I/O lines are different for op code and for address/dummy byte transfers on the SPI bus.
Besides, the current spi-nor framework supports neither the SPI 2-2-2 nor the SPI 4-4-4 protocols. So, for now, we don't need to update the m25p80_{read|write}_reg() functions as SPI 1-1-1 is the only one possible protocol.
--- drivers/mtd/devices/m25p80.c | 122 ++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 30 deletions(-)
drivers/mtd/devices/m25p80.c +92 -30
@@ -34,6 +34,19 @@ struct m25p {u8 command[MAX_CMD_SIZE ]; }; +static inline void m25p80_proto2nbits (enum spi_nor_protocol proto, +unsigned int *code_nbits, +unsigned int *addr_nbits, +unsigned int *data_nbits) +{ +if (code_nbits) + *code_nbits =SNOR_PROTO_CODE_FROM_PROTO (proto); +if (addr_nbits) + *addr_nbits =SNOR_PROTO_ADDR_FROM_PROTO (proto); +if (data_nbits) + *data_nbits =SNOR_PROTO_DATA_FROM_PROTO (proto); +} +static int m25p80_read_reg (struct spi_nor *nor,u8 code,u8 *val,int len) {struct m25p *flash = nor->priv;
@@ -78,11 +91,16 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len, {struct m25p *flash = nor->priv;struct spi_device *spi = flash->spi; -struct spi_transfer t[2 ] = {}; +unsigned int code_nbits, addr_nbits, data_nbits, data_idx; +struct spi_transfer t[3 ] = {};struct spi_message m;int cmd_sz =m25p_cmdsz (nor);ssize_t ret; +/* get transfer protocols. */ +m25p80_proto2nbits (nor->write_proto, &code_nbits, + &addr_nbits, &data_nbits); +spi_message_init (&m);if (nor->program_opcode ==SPINOR_OP_AAI_WP && nor->sst_write_second)
@@ -92,12 +110,27 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,m25p_addr2cmd (nor, to, flash->command); t[0 ].tx_buf = flash->command; + t[0 ].tx_nbits = code_nbits; t[0 ].len = cmd_sz;spi_message_add_tail (&t[0 ], &m); - t[1 ].tx_buf = buf; - t[1 ].len = len; -spi_message_add_tail (&t[1 ], &m); +/* split the op code and address bytes into two transfers if needed. */ + data_idx =1 ; +if (addr_nbits != code_nbits) { + t[0 ].len =1 ; + + t[1 ].tx_buf = &flash->command[1 ]; + t[1 ].tx_nbits = addr_nbits; + t[1 ].len = cmd_sz -1 ; +spi_message_add_tail (&t[1 ], &m); + + data_idx =2 ; + } + + t[data_idx].tx_buf = buf; + t[data_idx].tx_nbits = data_nbits; + t[data_idx].len = len; +spi_message_add_tail (&t[data_idx], &m); ret =spi_sync (spi, &m);if (ret)
@@ -109,18 +142,6 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,return ret; } -static inline unsigned int m25p80_rx_nbits (struct spi_nor *nor) -{ -switch (nor->read_proto) { -case SNOR_PROTO_1_1_2 : -return 2 ; -case SNOR_PROTO_1_1_4 : -return 4 ; -default : -return 0 ; - } -} -/* * Read an address range from the nor chip. The address range * may be any size provided it is within the physical boundaries.
@@ -130,13 +151,19 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, {struct m25p *flash = nor->priv;struct spi_device *spi = flash->spi; -struct spi_transfer t[2 ]; +unsigned int code_nbits, addr_nbits, data_nbits, data_idx; +struct spi_transfer t[3 ];struct spi_message m;unsigned int dummy = nor->read_dummy;ssize_t ret; +int cmd_sz; + +/* get transfer protocols. */ +m25p80_proto2nbits (nor->read_proto, &code_nbits, + &addr_nbits, &data_nbits);/* convert the dummy cycles to the number of bytes */ - dummy /=8 ; + dummy = (dummy * addr_nbits) /8 ;if (spi_flash_read_supported (spi)) {struct spi_flash_read_message msg;
@@ -149,10 +176,9 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, msg.read_opcode = nor->read_opcode; msg.addr_width = nor->addr_width; msg.dummy_bytes = dummy; -/* TODO: Support other combinations */ - msg.opcode_nbits =SPI_NBITS_SINGLE ; - msg.addr_nbits =SPI_NBITS_SINGLE ; - msg.data_nbits =m25p80_rx_nbits (nor); + msg.opcode_nbits = code_nbits; + msg.addr_nbits = addr_nbits; + msg.data_nbits = data_nbits; ret =spi_flash_read (spi, &msg);if (ret <0 )
@@ -167,20 +193,45 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,m25p_addr2cmd (nor, from, flash->command); t[0 ].tx_buf = flash->command; + t[0 ].tx_nbits = code_nbits; t[0 ].len =m25p_cmdsz (nor) + dummy;spi_message_add_tail (&t[0 ], &m); - t[1 ].rx_buf = buf; - t[1 ].rx_nbits =m25p80_rx_nbits (nor); - t[1 ].len =min3 (len,spi_max_transfer_size (spi), -spi_max_message_size (spi) - t[0 ].len); -spi_message_add_tail (&t[1 ], &m); +/* +* Set all dummy/mode cycle bits to avoid sending some manufacturer +* specific pattern, which might make the memory enter its Continuous +* Read mode by mistake. +* Based on the different mode cycle bit patterns listed and described +* in the JESD216B speficication, the 0xff value works for all memories +* and all manufacturers. +*/ + cmd_sz = t[0 ].len; +memset (flash->command + cmd_sz - dummy,0xff , dummy); + +/* split the op code and address bytes into two transfers if needed. */ + data_idx =1 ; +if (addr_nbits != code_nbits) { + t[0 ].len =1 ; + + t[1 ].tx_buf = &flash->command[1 ]; + t[1 ].tx_nbits = addr_nbits; + t[1 ].len = cmd_sz -1 ; +spi_message_add_tail (&t[1 ], &m); + + data_idx =2 ; + } + + t[data_idx].rx_buf = buf; + t[data_idx].rx_nbits = data_nbits; + t[data_idx].len =min3 (len,spi_max_transfer_size (spi), +spi_max_message_size (spi) - cmd_sz); +spi_message_add_tail (&t[data_idx], &m); ret =spi_sync (spi, &m);if (ret)return ret; - ret = m.actual_length -m25p_cmdsz (nor) - dummy; + ret = m.actual_length - cmd_sz;if (ret <0 )return -EIO ;return ret;
@@ -224,11 +275,22 @@ static int m25p_probe(struct spi_device *spi)spi_set_drvdata (spi, flash); flash->spi = spi; -if (spi->mode &SPI_RX_QUAD ) +if (spi->mode &SPI_RX_QUAD ) { modes.rd_modes |=SNOR_MODE_1_1_4 ; -else if (spi->mode &SPI_RX_DUAL ) + +if (spi->mode &SPI_TX_QUAD ) { + modes.rd_modes |=SNOR_MODE_1_4_4 ; + modes.wr_modes |= (SNOR_MODE_1_1_4 |SNOR_MODE_1_4_4 ); + } + }else if (spi->mode &SPI_RX_DUAL ) { modes.rd_modes |=SNOR_MODE_1_1_2 ; +if (spi->mode &SPI_TX_DUAL ) { + modes.rd_modes |=SNOR_MODE_1_2_2 ; + modes.wr_modes |= (SNOR_MODE_1_1_2 |SNOR_MODE_1_2_2 ); + } + } +if (data && data->name) nor->mtd.name = data->name;
Signature · 1 line
2.7.4