Skip to content

Commit 054e532

Browse files
KamalDasubroonie
authored andcommitted
spi: bcm-qspi: Remove hardcoded settings and spi-nor.h dependency
The newly added broadcom qspi driver in drivers/spi produces a build warning when CONFIG_MTD is disabled: include/linux/mtd/cfi.h:76:2: #warning No CONFIG_MTD_CFI_Ix selected. No NOR chip support can work. [-Werror=cpp] There has been discussion on this in the link provided below. This fix in SPI controller drivers implementing the ->spi_flash_read handler, now uses the settings provided inside the 'struct spi_flash_read_message' parameter instead of hardcoding them. Made changes to bcm_qspi_bspi_set_flex_mode() to set the BSPI controller using the passed msg structure and remove the need to include <linux/mtd/spi-nor.h> file by removing all use of SPINOR_OP_READ* macros. Fixes: 4e3b2d2 ("spi: bcm-qspi: Add BSPI spi-nor flash controller driver") Link: https://patchwork.kernel.org/patch/9624585/ Signed-off-by: Kamal Dasu <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 5771a8c commit 054e532

File tree

1 file changed

+33
-56
lines changed

1 file changed

+33
-56
lines changed

drivers/spi/spi-bcm-qspi.c

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/ioport.h>
2626
#include <linux/kernel.h>
2727
#include <linux/module.h>
28-
#include <linux/mtd/spi-nor.h>
2928
#include <linux/of.h>
3029
#include <linux/of_irq.h>
3130
#include <linux/platform_device.h>
@@ -349,76 +348,60 @@ static void bcm_qspi_bspi_set_xfer_params(struct bcm_qspi *qspi, u8 cmd_byte,
349348
bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, flex_mode);
350349
}
351350

352-
static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, int width,
353-
int addrlen, int hp)
351+
static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi,
352+
struct spi_flash_read_message *msg,
353+
int hp)
354354
{
355355
int bpc = 0, bpp = 0;
356-
u8 command = SPINOR_OP_READ_FAST;
357-
int flex_mode = 1, rv = 0;
358-
bool spans_4byte = false;
356+
u8 command = msg->read_opcode;
357+
int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE;
358+
int addrlen = msg->addr_width;
359+
int addr_nbits = msg->addr_nbits ? msg->addr_nbits : SPI_NBITS_SINGLE;
360+
int flex_mode = 1;
359361

360362
dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n",
361363
width, addrlen, hp);
362364

363-
if (addrlen == BSPI_ADDRLEN_4BYTES) {
365+
if (addrlen == BSPI_ADDRLEN_4BYTES)
364366
bpp = BSPI_BPP_ADDR_SELECT_MASK;
365-
spans_4byte = true;
366-
}
367367

368-
bpp |= 8;
368+
bpp |= msg->dummy_bytes * (8/addr_nbits);
369369

370370
switch (width) {
371371
case SPI_NBITS_SINGLE:
372372
if (addrlen == BSPI_ADDRLEN_3BYTES)
373373
/* default mode, does not need flex_cmd */
374374
flex_mode = 0;
375-
else
376-
command = SPINOR_OP_READ_FAST_4B;
377375
break;
378376
case SPI_NBITS_DUAL:
379377
bpc = 0x00000001;
380378
if (hp) {
381379
bpc |= 0x00010100; /* address and mode are 2-bit */
382380
bpp = BSPI_BPP_MODE_SELECT_MASK;
383-
command = OPCODE_DIOR;
384-
if (spans_4byte)
385-
command = OPCODE_DIOR_4B;
386-
} else {
387-
command = SPINOR_OP_READ_1_1_2;
388-
if (spans_4byte)
389-
command = SPINOR_OP_READ_1_1_2_4B;
390381
}
391382
break;
392383
case SPI_NBITS_QUAD:
393384
bpc = 0x00000002;
394385
if (hp) {
395386
bpc |= 0x00020200; /* address and mode are 4-bit */
396-
bpp = 4; /* dummy cycles */
397-
bpp |= BSPI_BPP_ADDR_SELECT_MASK;
398-
command = OPCODE_QIOR;
399-
if (spans_4byte)
400-
command = OPCODE_QIOR_4B;
401-
} else {
402-
command = SPINOR_OP_READ_1_1_4;
403-
if (spans_4byte)
404-
command = SPINOR_OP_READ_1_1_4_4B;
387+
bpp |= BSPI_BPP_MODE_SELECT_MASK;
405388
}
406389
break;
407390
default:
408-
rv = -EINVAL;
409-
break;
391+
return -EINVAL;
410392
}
411393

412-
if (rv == 0)
413-
bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc,
414-
flex_mode);
394+
bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc, flex_mode);
415395

416-
return rv;
396+
return 0;
417397
}
418398

419-
static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, int width,
420-
int addrlen, int hp)
399+
static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi,
400+
struct spi_flash_read_message *msg,
401+
int hp)
421402
{
403+
int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE;
404+
int addrlen = msg->addr_width;
422405
u32 data = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL);
423406

424407
dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n",
@@ -430,7 +413,6 @@ static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, int width,
430413
data &= ~(BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD |
431414
BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL);
432415
break;
433-
434416
case SPI_NBITS_QUAD:
435417
/* clear dual mode and set quad mode */
436418
data &= ~BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL;
@@ -455,15 +437,17 @@ static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, int width,
455437
/* set the override mode */
456438
data |= BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE;
457439
bcm_qspi_write(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL, data);
458-
bcm_qspi_bspi_set_xfer_params(qspi, SPINOR_OP_READ_FAST, 0, 0, 0);
440+
bcm_qspi_bspi_set_xfer_params(qspi, msg->read_opcode, 0, 0, 0);
459441

460442
return 0;
461443
}
462444

463445
static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi,
464-
int width, int addrlen, int hp)
446+
struct spi_flash_read_message *msg, int hp)
465447
{
466448
int error = 0;
449+
int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE;
450+
int addrlen = msg->addr_width;
467451

468452
/* default mode */
469453
qspi->xfer_mode.flex_mode = true;
@@ -475,23 +459,13 @@ static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi,
475459
mask = BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE;
476460
if (val & mask || qspi->s3_strap_override_ctrl & mask) {
477461
qspi->xfer_mode.flex_mode = false;
478-
bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE,
479-
0);
480-
481-
if ((val | qspi->s3_strap_override_ctrl) &
482-
BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL)
483-
width = SPI_NBITS_DUAL;
484-
else if ((val | qspi->s3_strap_override_ctrl) &
485-
BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD)
486-
width = SPI_NBITS_QUAD;
487-
488-
error = bcm_qspi_bspi_set_override(qspi, width, addrlen,
489-
hp);
462+
bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 0);
463+
error = bcm_qspi_bspi_set_override(qspi, msg, hp);
490464
}
491465
}
492466

493467
if (qspi->xfer_mode.flex_mode)
494-
error = bcm_qspi_bspi_set_flex_mode(qspi, width, addrlen, hp);
468+
error = bcm_qspi_bspi_set_flex_mode(qspi, msg, hp);
495469

496470
if (error) {
497471
dev_warn(&qspi->pdev->dev,
@@ -981,7 +955,7 @@ static int bcm_qspi_flash_read(struct spi_device *spi,
981955
struct bcm_qspi *qspi = spi_master_get_devdata(spi->master);
982956
int ret = 0;
983957
bool mspi_read = false;
984-
u32 io_width, addrlen, addr, len;
958+
u32 addr, len;
985959
u_char *buf;
986960

987961
buf = msg->buf;
@@ -1010,9 +984,7 @@ static int bcm_qspi_flash_read(struct spi_device *spi,
1010984
if (mspi_read)
1011985
return bcm_qspi_mspi_flash_read(spi, msg);
1012986

1013-
io_width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE;
1014-
addrlen = msg->addr_width;
1015-
ret = bcm_qspi_bspi_set_mode(qspi, io_width, addrlen, -1);
987+
ret = bcm_qspi_bspi_set_mode(qspi, msg, -1);
1016988

1017989
if (!ret)
1018990
ret = bcm_qspi_bspi_flash_read(spi, msg);
@@ -1422,6 +1394,11 @@ static int __maybe_unused bcm_qspi_suspend(struct device *dev)
14221394
{
14231395
struct bcm_qspi *qspi = dev_get_drvdata(dev);
14241396

1397+
/* store the override strap value */
1398+
if (!bcm_qspi_bspi_ver_three(qspi))
1399+
qspi->s3_strap_override_ctrl =
1400+
bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL);
1401+
14251402
spi_master_suspend(qspi->master);
14261403
clk_disable(qspi->clk);
14271404
bcm_qspi_hw_uninit(qspi);

0 commit comments

Comments
 (0)