Skip to content

Commit b6094ac

Browse files
committed
mtd: spi-nor: core: Introduce spi_nor_set_4byte_addr_mode()
Make the method public, as it will be used as a last resort to enable 4byte address mode when we can't determine the address mode at runtime. Update the addr_nbytes and current address mode while exiting the 4byte address mode too, as it may be used in the future by manufacturer drivers. No functional change. spi_nor_restore didn't update the address mode nbytes, but updating them now doesn't harm as the method is called in the driver's remove and shutdown paths. Link: https://lore.kernel.org/r/20230331074606.3559258-10-tudor.ambarus@linaro.org Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent 37513c5 commit b6094ac

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

drivers/mtd/spi-nor/core.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,9 +3134,35 @@ static int spi_nor_quad_enable(struct spi_nor *nor)
31343134
return nor->params->quad_enable(nor);
31353135
}
31363136

3137-
static int spi_nor_init(struct spi_nor *nor)
3137+
/**
3138+
* spi_nor_set_4byte_addr_mode() - Set address mode.
3139+
* @nor: pointer to a 'struct spi_nor'.
3140+
* @enable: enable/disable 4 byte address mode.
3141+
*
3142+
* Return: 0 on success, -errno otherwise.
3143+
*/
3144+
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
31383145
{
31393146
struct spi_nor_flash_parameter *params = nor->params;
3147+
int ret;
3148+
3149+
ret = params->set_4byte_addr_mode(nor, enable);
3150+
if (ret && ret != -ENOTSUPP)
3151+
return ret;
3152+
3153+
if (enable) {
3154+
params->addr_nbytes = 4;
3155+
params->addr_mode_nbytes = 4;
3156+
} else {
3157+
params->addr_nbytes = 3;
3158+
params->addr_mode_nbytes = 3;
3159+
}
3160+
3161+
return 0;
3162+
}
3163+
3164+
static int spi_nor_init(struct spi_nor *nor)
3165+
{
31403166
int err;
31413167

31423168
err = spi_nor_octal_dtr_enable(nor, true);
@@ -3178,10 +3204,9 @@ static int spi_nor_init(struct spi_nor *nor)
31783204
*/
31793205
WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET,
31803206
"enabling reset hack; may not recover from unexpected reboots\n");
3181-
err = params->set_4byte_addr_mode(nor, true);
3182-
if (err && err != -ENOTSUPP)
3207+
err = spi_nor_set_4byte_addr_mode(nor, true);
3208+
if (err)
31833209
return err;
3184-
params->addr_mode_nbytes = 4;
31853210
}
31863211

31873212
return 0;
@@ -3300,7 +3325,7 @@ static void spi_nor_restore(struct spi_nor *nor)
33003325
/* restore the addressing mode */
33013326
if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
33023327
nor->flags & SNOR_F_BROKEN_RESET) {
3303-
ret = nor->params->set_4byte_addr_mode(nor, false);
3328+
ret = spi_nor_set_4byte_addr_mode(nor, false);
33043329
if (ret)
33053330
/*
33063331
* Do not stop the execution in the hope that the flash

drivers/mtd/spi-nor/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable);
651651
int spi_nor_set_4byte_addr_mode_wren_en4b_ex4b(struct spi_nor *nor,
652652
bool enable);
653653
int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable);
654+
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable);
654655
int spi_nor_wait_till_ready(struct spi_nor *nor);
655656
int spi_nor_global_block_unlock(struct spi_nor *nor);
656657
int spi_nor_prep_and_lock(struct spi_nor *nor);

0 commit comments

Comments
 (0)