Skip to content

Commit 97e4827

Browse files
tq-schiffernbroonie
authored andcommitted
spi: cadence-quadspi: fix protocol setup for non-1-1-X operations
cqspi_set_protocol() only set the data width, but ignored the command and address width (except for 8-8-8 DTR ops), leading to corruption of all transfers using 1-X-X or X-X-X ops. Fix by setting the other two widths as well. While we're at it, simplify the code a bit by replacing the CQSPI_INST_TYPE_* constants with ilog2(). Tested on a TI AM64x with a Macronix MX25U51245G QSPI flash with 1-4-4 read and write operations. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Link: https://lore.kernel.org/r/20220331110819.133392-1-matthias.schiffer@ew.tq-group.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 409543c commit 97e4827

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

drivers/spi/spi-cadence-quadspi.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/iopoll.h>
2020
#include <linux/jiffies.h>
2121
#include <linux/kernel.h>
22+
#include <linux/log2.h>
2223
#include <linux/module.h>
2324
#include <linux/of_device.h>
2425
#include <linux/of.h>
@@ -102,12 +103,6 @@ struct cqspi_driver_platdata {
102103
#define CQSPI_TIMEOUT_MS 500
103104
#define CQSPI_READ_TIMEOUT_MS 10
104105

105-
/* Instruction type */
106-
#define CQSPI_INST_TYPE_SINGLE 0
107-
#define CQSPI_INST_TYPE_DUAL 1
108-
#define CQSPI_INST_TYPE_QUAD 2
109-
#define CQSPI_INST_TYPE_OCTAL 3
110-
111106
#define CQSPI_DUMMY_CLKS_PER_BYTE 8
112107
#define CQSPI_DUMMY_BYTES_MAX 4
113108
#define CQSPI_DUMMY_CLKS_MAX 31
@@ -376,10 +371,6 @@ static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op, bool dtr)
376371
static int cqspi_set_protocol(struct cqspi_flash_pdata *f_pdata,
377372
const struct spi_mem_op *op)
378373
{
379-
f_pdata->inst_width = CQSPI_INST_TYPE_SINGLE;
380-
f_pdata->addr_width = CQSPI_INST_TYPE_SINGLE;
381-
f_pdata->data_width = CQSPI_INST_TYPE_SINGLE;
382-
383374
/*
384375
* For an op to be DTR, cmd phase along with every other non-empty
385376
* phase should have dtr field set to 1. If an op phase has zero
@@ -389,52 +380,39 @@ static int cqspi_set_protocol(struct cqspi_flash_pdata *f_pdata,
389380
(!op->addr.nbytes || op->addr.dtr) &&
390381
(!op->data.nbytes || op->data.dtr);
391382

392-
switch (op->data.buswidth) {
393-
case 0:
394-
break;
395-
case 1:
396-
f_pdata->data_width = CQSPI_INST_TYPE_SINGLE;
397-
break;
398-
case 2:
399-
f_pdata->data_width = CQSPI_INST_TYPE_DUAL;
400-
break;
401-
case 4:
402-
f_pdata->data_width = CQSPI_INST_TYPE_QUAD;
403-
break;
404-
case 8:
405-
f_pdata->data_width = CQSPI_INST_TYPE_OCTAL;
406-
break;
407-
default:
408-
return -EINVAL;
409-
}
383+
f_pdata->inst_width = 0;
384+
if (op->cmd.buswidth)
385+
f_pdata->inst_width = ilog2(op->cmd.buswidth);
386+
387+
f_pdata->addr_width = 0;
388+
if (op->addr.buswidth)
389+
f_pdata->addr_width = ilog2(op->addr.buswidth);
390+
391+
f_pdata->data_width = 0;
392+
if (op->data.buswidth)
393+
f_pdata->data_width = ilog2(op->data.buswidth);
410394

411395
/* Right now we only support 8-8-8 DTR mode. */
412396
if (f_pdata->dtr) {
413397
switch (op->cmd.buswidth) {
414398
case 0:
415-
break;
416399
case 8:
417-
f_pdata->inst_width = CQSPI_INST_TYPE_OCTAL;
418400
break;
419401
default:
420402
return -EINVAL;
421403
}
422404

423405
switch (op->addr.buswidth) {
424406
case 0:
425-
break;
426407
case 8:
427-
f_pdata->addr_width = CQSPI_INST_TYPE_OCTAL;
428408
break;
429409
default:
430410
return -EINVAL;
431411
}
432412

433413
switch (op->data.buswidth) {
434414
case 0:
435-
break;
436415
case 8:
437-
f_pdata->data_width = CQSPI_INST_TYPE_OCTAL;
438416
break;
439417
default:
440418
return -EINVAL;

0 commit comments

Comments
 (0)