From 7ca996234fae1c7a0a2bbbb40f4d65a845d499bd Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Thu, 17 Oct 2024 15:23:52 +0000 Subject: [PATCH] drivers: flash: flash_mcux_flexspi_nor: fix IS25WP flash support Some NXP boards program the read parameters bits (P[6:3]) within the IS25WP flash device during init, which will result in JESD216 probe commands failing (as the number of dummy cycles will be incorrect). Add handling to force these volatile bits to their default value to the flexspi flash driver. Signed-off-by: Daniel DeGrasse --- drivers/flash/flash_mcux_flexspi_nor.c | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/flash/flash_mcux_flexspi_nor.c b/drivers/flash/flash_mcux_flexspi_nor.c index 7e08e30bb2a..c92761d4bc5 100644 --- a/drivers/flash/flash_mcux_flexspi_nor.c +++ b/drivers/flash/flash_mcux_flexspi_nor.c @@ -893,6 +893,43 @@ static int flash_flexspi_nor_sfdp_read(const struct device *dev, #endif +/* Helper to configure IS25 flash, by clearing read param bits */ +static int flash_flexspi_nor_is25_clear_read_param(struct flash_flexspi_nor_data *data, + uint32_t (*flexspi_lut)[MEMC_FLEXSPI_CMD_PER_SEQ], + uint32_t *read_params) +{ + int ret; + /* Install Set Read Parameters (Volatile) command */ + flexspi_transfer_t transfer = { + .deviceAddress = 0, + .port = data->port, + .seqIndex = SCRATCH_CMD, + .SeqNumber = 1, + .data = read_params, + .dataSize = 1, + .cmdType = kFLEXSPI_Write, + }; + flexspi_device_config_t config = { + .flexspiRootClk = MHZ(50), + .flashSize = FLEXSPI_FLSHCR0_FLSHSZ_MASK, /* Max flash size */ + .ARDSeqNumber = 1, + .ARDSeqIndex = READ, + }; + + flexspi_lut[SCRATCH_CMD][0] = FLEXSPI_LUT_SEQ( + kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xC0, + kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_1PAD, 0x1); + ret = memc_flexspi_set_device_config(&data->controller, + &config, + (uint32_t *)flexspi_lut, + FLEXSPI_INSTR_END * MEMC_FLEXSPI_CMD_PER_SEQ, + data->port); + if (ret < 0) { + return ret; + } + return memc_flexspi_transfer(&data->controller, &transfer); +} + /* Checks JEDEC ID of flash. If supported, installs custom LUT table */ static int flash_flexspi_nor_check_jedec(struct flash_flexspi_nor_data *data, uint32_t (*flexspi_lut)[MEMC_FLEXSPI_CMD_PER_SEQ]) @@ -907,6 +944,25 @@ static int flash_flexspi_nor_check_jedec(struct flash_flexspi_nor_data *data, /* Switch on manufacturer and vendor ID */ switch (vendor_id & 0xFFFF) { + case 0x709d: + /* + * IS25WP flash. We can support this flash with the JEDEC probe, + * but we need to insure P[6:3] are at the default value + */ + /* Install Set Read Parameters (Volatile) command */ + uint32_t read_params = 0; + ret = flash_flexspi_nor_is25_clear_read_param(data, flexspi_lut, &read_params); + if (ret < 0) { + while (1) { + /* + * Spin here, this flash won't configure correctly. + * We can't print a warning, as we are unlikely to + * be able to XIP at this point. + */ + } + } + /* Still return an error- we want the JEDEC configuration to run */ + return -ENOTSUP; case 0x25C2: /* MX25 flash, use 4 byte read/write */ flexspi_lut[READ][0] = FLEXSPI_LUT_SEQ(