Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 4e3b2d236fe0 ("spi: bcm-qspi: Add BSPI spi-nor flash controller driver")
Link: https://patchwork.kernel.org/patch/9624585/
Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kamal Dasu and committed by
Mark Brown
054e532f 5771a8c0

+33 -56
+33 -56
drivers/spi/spi-bcm-qspi.c
··· 25 25 #include <linux/ioport.h> 26 26 #include <linux/kernel.h> 27 27 #include <linux/module.h> 28 - #include <linux/mtd/spi-nor.h> 29 28 #include <linux/of.h> 30 29 #include <linux/of_irq.h> 31 30 #include <linux/platform_device.h> ··· 348 349 bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, flex_mode); 349 350 } 350 351 351 - static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, int width, 352 - int addrlen, int hp) 352 + static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, 353 + struct spi_flash_read_message *msg, 354 + int hp) 353 355 { 354 356 int bpc = 0, bpp = 0; 355 - u8 command = SPINOR_OP_READ_FAST; 356 - int flex_mode = 1, rv = 0; 357 - bool spans_4byte = false; 357 + u8 command = msg->read_opcode; 358 + int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE; 359 + int addrlen = msg->addr_width; 360 + int addr_nbits = msg->addr_nbits ? msg->addr_nbits : SPI_NBITS_SINGLE; 361 + int flex_mode = 1; 358 362 359 363 dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n", 360 364 width, addrlen, hp); 361 365 362 - if (addrlen == BSPI_ADDRLEN_4BYTES) { 366 + if (addrlen == BSPI_ADDRLEN_4BYTES) 363 367 bpp = BSPI_BPP_ADDR_SELECT_MASK; 364 - spans_4byte = true; 365 - } 366 368 367 - bpp |= 8; 369 + bpp |= msg->dummy_bytes * (8/addr_nbits); 368 370 369 371 switch (width) { 370 372 case SPI_NBITS_SINGLE: 371 373 if (addrlen == BSPI_ADDRLEN_3BYTES) 372 374 /* default mode, does not need flex_cmd */ 373 375 flex_mode = 0; 374 - else 375 - command = SPINOR_OP_READ_FAST_4B; 376 376 break; 377 377 case SPI_NBITS_DUAL: 378 378 bpc = 0x00000001; 379 379 if (hp) { 380 380 bpc |= 0x00010100; /* address and mode are 2-bit */ 381 381 bpp = BSPI_BPP_MODE_SELECT_MASK; 382 - command = OPCODE_DIOR; 383 - if (spans_4byte) 384 - command = OPCODE_DIOR_4B; 385 - } else { 386 - command = SPINOR_OP_READ_1_1_2; 387 - if (spans_4byte) 388 - command = SPINOR_OP_READ_1_1_2_4B; 389 382 } 390 383 break; 391 384 case SPI_NBITS_QUAD: 392 385 bpc = 0x00000002; 393 386 if (hp) { 394 387 bpc |= 0x00020200; /* address and mode are 4-bit */ 395 - bpp = 4; /* dummy cycles */ 396 - bpp |= BSPI_BPP_ADDR_SELECT_MASK; 397 - command = OPCODE_QIOR; 398 - if (spans_4byte) 399 - command = OPCODE_QIOR_4B; 400 - } else { 401 - command = SPINOR_OP_READ_1_1_4; 402 - if (spans_4byte) 403 - command = SPINOR_OP_READ_1_1_4_4B; 388 + bpp |= BSPI_BPP_MODE_SELECT_MASK; 404 389 } 405 390 break; 406 391 default: 407 - rv = -EINVAL; 408 - break; 392 + return -EINVAL; 409 393 } 410 394 411 - if (rv == 0) 412 - bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc, 413 - flex_mode); 395 + bcm_qspi_bspi_set_xfer_params(qspi, command, bpp, bpc, flex_mode); 414 396 415 - return rv; 397 + return 0; 416 398 } 417 399 418 - static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, int width, 419 - int addrlen, int hp) 400 + static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi, 401 + struct spi_flash_read_message *msg, 402 + int hp) 420 403 { 404 + int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE; 405 + int addrlen = msg->addr_width; 421 406 u32 data = bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL); 422 407 423 408 dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n", ··· 413 430 data &= ~(BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD | 414 431 BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL); 415 432 break; 416 - 417 433 case SPI_NBITS_QUAD: 418 434 /* clear dual mode and set quad mode */ 419 435 data &= ~BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL; ··· 437 455 /* set the override mode */ 438 456 data |= BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE; 439 457 bcm_qspi_write(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL, data); 440 - bcm_qspi_bspi_set_xfer_params(qspi, SPINOR_OP_READ_FAST, 0, 0, 0); 458 + bcm_qspi_bspi_set_xfer_params(qspi, msg->read_opcode, 0, 0, 0); 441 459 442 460 return 0; 443 461 } 444 462 445 463 static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi, 446 - int width, int addrlen, int hp) 464 + struct spi_flash_read_message *msg, int hp) 447 465 { 448 466 int error = 0; 467 + int width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE; 468 + int addrlen = msg->addr_width; 449 469 450 470 /* default mode */ 451 471 qspi->xfer_mode.flex_mode = true; ··· 459 475 mask = BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE; 460 476 if (val & mask || qspi->s3_strap_override_ctrl & mask) { 461 477 qspi->xfer_mode.flex_mode = false; 462 - bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 463 - 0); 464 - 465 - if ((val | qspi->s3_strap_override_ctrl) & 466 - BSPI_STRAP_OVERRIDE_CTRL_DATA_DUAL) 467 - width = SPI_NBITS_DUAL; 468 - else if ((val | qspi->s3_strap_override_ctrl) & 469 - BSPI_STRAP_OVERRIDE_CTRL_DATA_QUAD) 470 - width = SPI_NBITS_QUAD; 471 - 472 - error = bcm_qspi_bspi_set_override(qspi, width, addrlen, 473 - hp); 478 + bcm_qspi_write(qspi, BSPI, BSPI_FLEX_MODE_ENABLE, 0); 479 + error = bcm_qspi_bspi_set_override(qspi, msg, hp); 474 480 } 475 481 } 476 482 477 483 if (qspi->xfer_mode.flex_mode) 478 - error = bcm_qspi_bspi_set_flex_mode(qspi, width, addrlen, hp); 484 + error = bcm_qspi_bspi_set_flex_mode(qspi, msg, hp); 479 485 480 486 if (error) { 481 487 dev_warn(&qspi->pdev->dev, ··· 955 981 struct bcm_qspi *qspi = spi_master_get_devdata(spi->master); 956 982 int ret = 0; 957 983 bool mspi_read = false; 958 - u32 io_width, addrlen, addr, len; 984 + u32 addr, len; 959 985 u_char *buf; 960 986 961 987 buf = msg->buf; ··· 984 1010 if (mspi_read) 985 1011 return bcm_qspi_mspi_flash_read(spi, msg); 986 1012 987 - io_width = msg->data_nbits ? msg->data_nbits : SPI_NBITS_SINGLE; 988 - addrlen = msg->addr_width; 989 - ret = bcm_qspi_bspi_set_mode(qspi, io_width, addrlen, -1); 1013 + ret = bcm_qspi_bspi_set_mode(qspi, msg, -1); 990 1014 991 1015 if (!ret) 992 1016 ret = bcm_qspi_bspi_flash_read(spi, msg); ··· 1393 1421 static int __maybe_unused bcm_qspi_suspend(struct device *dev) 1394 1422 { 1395 1423 struct bcm_qspi *qspi = dev_get_drvdata(dev); 1424 + 1425 + /* store the override strap value */ 1426 + if (!bcm_qspi_bspi_ver_three(qspi)) 1427 + qspi->s3_strap_override_ctrl = 1428 + bcm_qspi_read(qspi, BSPI, BSPI_STRAP_OVERRIDE_CTRL); 1396 1429 1397 1430 spi_master_suspend(qspi->master); 1398 1431 clk_disable(qspi->clk);