Skip to content

Commit 510a230

Browse files
committed
Merge series "mtd: spi-nor: add xSPI Octal DTR support" from Pratyush Yadav <[email protected]>:
Hi, This series adds support for octal DTR flashes in the spi-nor framework, and then adds hooks for the Cypress Semper and Mircom Xcella flashes to allow running them in octal DTR mode. This series assumes that the flash is handed to the kernel in Legacy SPI mode. Tested on TI J721e EVM with 1-bit ECC on the Cypress flash. Changes in v10: - Rebase on latest linux-next/master. Drop a couple patches that made it in the previous release. - Move the code that sets 20 dummy cycles for MT35XU512ABA to its octal enable function. This way, if the controller doesn't support 8D mode 20 dummy cycles won't be used. Changes in v9: - Do not use '& 0xff' to get the opcode LSB in spi-mxic and spi-zynq-qspi. The cast to u8 will do that anyway. - Do not use if (opcode) as a check for whether the command phase exists in spi-zynq-qspi because the opcode 0 can be valid. Use the new cmd.nbytes instead. Changes in v8: - Move controller changes in spi-mxic to the commit which introduces 2-byte opcodes to avoid problems when bisecting. - Replace usage of sizeof(op->cmd.opcode) with op->cmd.nbytes. - Extract opcode in spi-zynq-qspi instead of using &op->cmd.opcode. Changes in v7: - Reject ops with more than 1 command byte in spi_mem_default_supports_op(). - Reject ops with more than 1 command byte in atmel and mtk controllers. - Reject ops with 0 command bytes in spi_mem_check_op(). - Set cmd.nbytes to 1 when using SPI_MEM_OP_CMD(). - Avoid endianness problems in spi-mxic. Changes in v6: - Instead of hard-coding 8D-8D-8D Fast Read dummy cycles to 20, find them out from the Profile 1.0 table. Changes in v5: - Do not enable stateful X-X-X modes if the reset line is broken. - Instead of setting SNOR_READ_HWCAPS_8_8_8_DTR from Profile 1.0 table parsing, do it in spi_nor_info_init_params() instead based on the SPI_NOR_OCTAL_DTR_READ flag instead. - Set SNOR_HWCAPS_PP_8_8_8_DTR in s28hs post_sfdp hook since this capability is no longer set in Profile 1.0 parsing. - Instead of just checking for spi_nor_get_protocol_width() in spi_nor_octal_dtr_enable(), make sure the protocol is SNOR_PROTO_8_8_8_DTR since get_protocol_width() only cares about data width. - Drop flag SPI_NOR_SOFT_RESET. Instead, discover soft reset capability via BFPT. - Do not make an invalid Quad Enable BFPT field a fatal error. Silently ignore it by assuming no quad enable bit is present. - Set dummy cycles for Cypress Semper flash to 24 instead of 20. This allows for 200MHz operation in 8D mode compared to the 166MHz with 20. - Rename spi_nor_cypress_octal_enable() to spi_nor_cypress_octal_dtr_enable(). - Update spi-mtk-nor.c to reject DTR ops since it doesn't call spi_mem_default_supports_op(). Changes in v4: - Refactor the series to use the new spi-nor framework with the manufacturer-specific bits separated from the core. - Add support for Micron MT35XU512ABA. - Use cmd.nbytes as the criteria of whether the data phase exists or not instead of cmd.buf.in || cmd.buf.out in spi_nor_spimem_setup_op(). - Update Read FSR to use the same dummy cycles and address width as Read SR. - Fix BFPT parsing stopping too early for JESD216 rev B flashes. - Use 2 byte reads for Read SR and FSR commands in DTR mode. Changes in v3: - Drop the DT properties "spi-rx-dtr" and "spi-tx-dtr". Instead, if later a need is felt to disable DTR in case someone has a board with Octal DTR capable flash but does not support DTR transactions for some reason, a property like "spi-no-dtr" can be added. - Remove mode bits SPI_RX_DTR and SPI_TX_DTR. - Remove the Cadence Quadspi controller patch to un-block this series. I will submit it as a separate patch. - Rebase on latest 'master' and fix merge conflicts. - Update read and write dirmap templates to use DTR. - Rename 'is_dtr' to 'dtr'. - Make 'dtr' a bitfield. - Reject DTR ops in spi_mem_default_supports_op(). - Update atmel-quadspi to reject DTR ops. All other controller drivers call spi_mem_default_supports_op() so they will automatically reject DTR ops. - Add support for both enabling and disabling DTR modes. - Perform a Software Reset on flashes that support it when shutting down. - Disable Octal DTR mode on suspend, and re-enable it on resume. - Drop enum 'spi_mem_cmd_ext' and make command opcode u16 instead. Update spi-nor to use the 2-byte command instead of the command extension. Since we still need a "extension type", mode that enum to spi-nor and name it 'spi_nor_cmd_ext'. - Default variable address width to 3 to fix SMPT parsing. - Drop non-volatile change to uniform sector mode and rely on parsing SMPT. Changes in v2: - Add DT properties "spi-rx-dtr" and "spi-tx-dtr" to allow expressing DTR capabilities. - Set the mode bits SPI_RX_DTR and SPI_TX_DTR when we discover the DT properties "spi-rx-dtr" and spi-tx-dtr". - spi_nor_cypress_octal_enable() was updating nor->params.read[] with the intention of setting the correct number of dummy cycles. But this function is called _after_ selecting the read so setting nor->params.read[] will have no effect. So, update nor->read_dummy directly. - Fix spi_nor_spimem_check_readop() and spi_nor_spimem_check_pp() passing nor->read_proto and nor->write_proto to spi_nor_spimem_setup_op() instead of read->proto and pp->proto respectively. - Move the call to cqspi_setup_opcode_ext() inside cqspi_enable_dtr(). This avoids repeating the 'if (f_pdata->is_dtr) cqspi_setup_opcode_ext()...` snippet multiple times. - Call the default 'supports_op()' from cqspi_supports_mem_op(). This makes sure the buswidth requirements are also enforced along with the DTR requirements. - Drop the 'is_dtr' argument from spi_check_dtr_req(). We only call it when a phase is DTR so it is redundant. Pratyush Yadav (17): spi: spi-mem: allow specifying whether an op is DTR or not spi: spi-mem: allow specifying a command's extension spi: atmel-quadspi: reject DTR ops spi: spi-mtk-nor: reject DTR ops mtd: spi-nor: add support for DTR protocol mtd: spi-nor: sfdp: get command opcode extension type from BFPT mtd: spi-nor: sfdp: parse xSPI Profile 1.0 table mtd: spi-nor: core: use dummy cycle and address width info from SFDP mtd: spi-nor: core: do 2 byte reads for SR and FSR in DTR mode mtd: spi-nor: core: enable octal DTR mode when possible mtd: spi-nor: sfdp: do not make invalid quad enable fatal mtd: spi-nor: sfdp: detect Soft Reset sequence support from BFPT mtd: spi-nor: core: perform a Soft Reset on shutdown mtd: spi-nor: core: disable Octal DTR mode on suspend. mtd: spi-nor: core: expose spi_nor_default_setup() in core.h mtd: spi-nor: spansion: add support for Cypress Semper flash mtd: spi-nor: micron-st: allow using MT35XU512ABA in Octal DTR mode drivers/mtd/spi-nor/core.c | 446 +++++++++++++++++++++++++++----- drivers/mtd/spi-nor/core.h | 22 ++ drivers/mtd/spi-nor/micron-st.c | 103 +++++++- drivers/mtd/spi-nor/sfdp.c | 131 +++++++++- drivers/mtd/spi-nor/sfdp.h | 8 + drivers/mtd/spi-nor/spansion.c | 166 ++++++++++++ drivers/spi/atmel-quadspi.c | 6 + drivers/spi/spi-mem.c | 16 +- drivers/spi/spi-mtk-nor.c | 10 +- drivers/spi/spi-mxic.c | 3 +- drivers/spi/spi-zynq-qspi.c | 11 +- include/linux/mtd/spi-nor.h | 53 +++- include/linux/spi/spi-mem.h | 14 +- 13 files changed, 889 insertions(+), 100 deletions(-) -- 2.27.0 base-commit: b3a9e3b _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
2 parents 8257083 + 4728f07 commit 510a230

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

drivers/spi/atmel-quadspi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
285285
op->dummy.nbytes == 0)
286286
return false;
287287

288+
/* DTR ops not supported. */
289+
if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
290+
return false;
291+
if (op->cmd.nbytes != 1)
292+
return false;
293+
288294
return true;
289295
}
290296

drivers/spi/spi-mem.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
156156
op->data.dir == SPI_MEM_DATA_OUT))
157157
return false;
158158

159+
if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
160+
return false;
161+
162+
if (op->cmd.nbytes != 1)
163+
return false;
164+
159165
return true;
160166
}
161167
EXPORT_SYMBOL_GPL(spi_mem_default_supports_op);
@@ -170,7 +176,7 @@ static bool spi_mem_buswidth_is_valid(u8 buswidth)
170176

171177
static int spi_mem_check_op(const struct spi_mem_op *op)
172178
{
173-
if (!op->cmd.buswidth)
179+
if (!op->cmd.buswidth || !op->cmd.nbytes)
174180
return -EINVAL;
175181

176182
if ((op->addr.nbytes && !op->addr.buswidth) ||
@@ -306,8 +312,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
306312
return ret;
307313
}
308314

309-
tmpbufsize = sizeof(op->cmd.opcode) + op->addr.nbytes +
310-
op->dummy.nbytes;
315+
tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
311316

312317
/*
313318
* Allocate a buffer to transmit the CMD, ADDR cycles with kmalloc() so
@@ -322,7 +327,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
322327

323328
tmpbuf[0] = op->cmd.opcode;
324329
xfers[xferpos].tx_buf = tmpbuf;
325-
xfers[xferpos].len = sizeof(op->cmd.opcode);
330+
xfers[xferpos].len = op->cmd.nbytes;
326331
xfers[xferpos].tx_nbits = op->cmd.buswidth;
327332
spi_message_add_tail(&xfers[xferpos], &msg);
328333
xferpos++;
@@ -424,8 +429,7 @@ int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
424429
return ctlr->mem_ops->adjust_op_size(mem, op);
425430

426431
if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) {
427-
len = sizeof(op->cmd.opcode) + op->addr.nbytes +
428-
op->dummy.nbytes;
432+
len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
429433

430434
if (len > spi_max_transfer_size(mem->spi))
431435
return -EINVAL;

drivers/spi/spi-mtk-nor.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
195195
}
196196
}
197197

198-
len = MTK_NOR_PRG_MAX_SIZE - sizeof(op->cmd.opcode) - op->addr.nbytes -
198+
len = MTK_NOR_PRG_MAX_SIZE - op->cmd.nbytes - op->addr.nbytes -
199199
op->dummy.nbytes;
200200
if (op->data.nbytes > len)
201201
op->data.nbytes = len;
@@ -211,6 +211,12 @@ static bool mtk_nor_supports_op(struct spi_mem *mem,
211211
if (op->cmd.buswidth != 1)
212212
return false;
213213

214+
/* DTR ops not supported. */
215+
if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
216+
return false;
217+
if (op->cmd.nbytes != 1)
218+
return false;
219+
214220
if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
215221
if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op))
216222
return true;
@@ -219,7 +225,7 @@ static bool mtk_nor_supports_op(struct spi_mem *mem,
219225
(op->dummy.buswidth == 0) &&
220226
(op->data.buswidth == 1);
221227
}
222-
len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;
228+
len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
223229
if ((len > MTK_NOR_PRG_MAX_SIZE) ||
224230
((op->data.nbytes) && (len == MTK_NOR_PRG_MAX_SIZE)))
225231
return false;

drivers/spi/spi-mxic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
356356
int nio = 1, i, ret;
357357
u32 ss_ctrl;
358358
u8 addr[8];
359+
u8 opcode = op->cmd.opcode;
359360

360361
ret = mxic_spi_set_freq(mxic, mem->spi->max_speed_hz);
361362
if (ret)
@@ -393,7 +394,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
393394
writel(readl(mxic->regs + HC_CFG) | HC_CFG_MAN_CS_ASSERT,
394395
mxic->regs + HC_CFG);
395396

396-
ret = mxic_spi_data_xfer(mxic, &op->cmd.opcode, NULL, 1);
397+
ret = mxic_spi_data_xfer(mxic, &opcode, NULL, 1);
397398
if (ret)
398399
goto out;
399400

drivers/spi/spi-zynq-qspi.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,20 +527,21 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem,
527527
struct zynq_qspi *xqspi = spi_controller_get_devdata(mem->spi->master);
528528
int err = 0, i;
529529
u8 *tmpbuf;
530+
u8 opcode = op->cmd.opcode;
530531

531532
dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n",
532-
op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,
533+
opcode, op->cmd.buswidth, op->addr.buswidth,
533534
op->dummy.buswidth, op->data.buswidth);
534535

535536
zynq_qspi_chipselect(mem->spi, true);
536537
zynq_qspi_config_op(xqspi, mem->spi);
537538

538-
if (op->cmd.opcode) {
539+
if (op->cmd.nbytes) {
539540
reinit_completion(&xqspi->data_completion);
540-
xqspi->txbuf = (u8 *)&op->cmd.opcode;
541+
xqspi->txbuf = &opcode;
541542
xqspi->rxbuf = NULL;
542-
xqspi->tx_bytes = sizeof(op->cmd.opcode);
543-
xqspi->rx_bytes = sizeof(op->cmd.opcode);
543+
xqspi->tx_bytes = op->cmd.nbytes;
544+
xqspi->rx_bytes = op->cmd.nbytes;
544545
zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true);
545546
zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET,
546547
ZYNQ_QSPI_IXR_RXTX_MASK);

include/linux/spi/spi-mem.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
{ \
1818
.buswidth = __buswidth, \
1919
.opcode = __opcode, \
20+
.nbytes = 1, \
2021
}
2122

2223
#define SPI_MEM_OP_ADDR(__nbytes, __val, __buswidth) \
@@ -69,19 +70,25 @@ enum spi_mem_data_dir {
6970

7071
/**
7172
* struct spi_mem_op - describes a SPI memory operation
73+
* @cmd.nbytes: number of opcode bytes (only 1 or 2 are valid). The opcode is
74+
* sent MSB-first.
7275
* @cmd.buswidth: number of IO lines used to transmit the command
7376
* @cmd.opcode: operation opcode
77+
* @cmd.dtr: whether the command opcode should be sent in DTR mode or not
7478
* @addr.nbytes: number of address bytes to send. Can be zero if the operation
7579
* does not need to send an address
7680
* @addr.buswidth: number of IO lines used to transmit the address cycles
81+
* @addr.dtr: whether the address should be sent in DTR mode or not
7782
* @addr.val: address value. This value is always sent MSB first on the bus.
7883
* Note that only @addr.nbytes are taken into account in this
7984
* address value, so users should make sure the value fits in the
8085
* assigned number of bytes.
8186
* @dummy.nbytes: number of dummy bytes to send after an opcode or address. Can
8287
* be zero if the operation does not require dummy bytes
8388
* @dummy.buswidth: number of IO lanes used to transmit the dummy bytes
89+
* @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not
8490
* @data.buswidth: number of IO lanes used to send/receive the data
91+
* @data.dtr: whether the data should be sent in DTR mode or not
8592
* @data.dir: direction of the transfer
8693
* @data.nbytes: number of data bytes to send/receive. Can be zero if the
8794
* operation does not involve transferring data
@@ -90,23 +97,28 @@ enum spi_mem_data_dir {
9097
*/
9198
struct spi_mem_op {
9299
struct {
100+
u8 nbytes;
93101
u8 buswidth;
94-
u8 opcode;
102+
u8 dtr : 1;
103+
u16 opcode;
95104
} cmd;
96105

97106
struct {
98107
u8 nbytes;
99108
u8 buswidth;
109+
u8 dtr : 1;
100110
u64 val;
101111
} addr;
102112

103113
struct {
104114
u8 nbytes;
105115
u8 buswidth;
116+
u8 dtr : 1;
106117
} dummy;
107118

108119
struct {
109120
u8 buswidth;
121+
u8 dtr : 1;
110122
enum spi_mem_data_dir dir;
111123
unsigned int nbytes;
112124
union {

0 commit comments

Comments
 (0)