Commit b6094ac8 authored by Tudor Ambarus's avatar Tudor Ambarus

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.orgSigned-off-by: default avatarTudor Ambarus <tudor.ambarus@linaro.org>
parent 37513c56
...@@ -3134,9 +3134,35 @@ static int spi_nor_quad_enable(struct spi_nor *nor) ...@@ -3134,9 +3134,35 @@ static int spi_nor_quad_enable(struct spi_nor *nor)
return nor->params->quad_enable(nor); return nor->params->quad_enable(nor);
} }
static int spi_nor_init(struct spi_nor *nor) /**
* spi_nor_set_4byte_addr_mode() - Set address mode.
* @nor: pointer to a 'struct spi_nor'.
* @enable: enable/disable 4 byte address mode.
*
* Return: 0 on success, -errno otherwise.
*/
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
{ {
struct spi_nor_flash_parameter *params = nor->params; struct spi_nor_flash_parameter *params = nor->params;
int ret;
ret = params->set_4byte_addr_mode(nor, enable);
if (ret && ret != -ENOTSUPP)
return ret;
if (enable) {
params->addr_nbytes = 4;
params->addr_mode_nbytes = 4;
} else {
params->addr_nbytes = 3;
params->addr_mode_nbytes = 3;
}
return 0;
}
static int spi_nor_init(struct spi_nor *nor)
{
int err; int err;
err = spi_nor_octal_dtr_enable(nor, true); err = spi_nor_octal_dtr_enable(nor, true);
...@@ -3178,10 +3204,9 @@ static int spi_nor_init(struct spi_nor *nor) ...@@ -3178,10 +3204,9 @@ static int spi_nor_init(struct spi_nor *nor)
*/ */
WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET,
"enabling reset hack; may not recover from unexpected reboots\n"); "enabling reset hack; may not recover from unexpected reboots\n");
err = params->set_4byte_addr_mode(nor, true); err = spi_nor_set_4byte_addr_mode(nor, true);
if (err && err != -ENOTSUPP) if (err)
return err; return err;
params->addr_mode_nbytes = 4;
} }
return 0; return 0;
...@@ -3300,7 +3325,7 @@ static void spi_nor_restore(struct spi_nor *nor) ...@@ -3300,7 +3325,7 @@ static void spi_nor_restore(struct spi_nor *nor)
/* restore the addressing mode */ /* restore the addressing mode */
if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
nor->flags & SNOR_F_BROKEN_RESET) { nor->flags & SNOR_F_BROKEN_RESET) {
ret = nor->params->set_4byte_addr_mode(nor, false); ret = spi_nor_set_4byte_addr_mode(nor, false);
if (ret) if (ret)
/* /*
* Do not stop the execution in the hope that the flash * Do not stop the execution in the hope that the flash
......
...@@ -651,6 +651,7 @@ int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable); ...@@ -651,6 +651,7 @@ int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable);
int spi_nor_set_4byte_addr_mode_wren_en4b_ex4b(struct spi_nor *nor, int spi_nor_set_4byte_addr_mode_wren_en4b_ex4b(struct spi_nor *nor,
bool enable); bool enable);
int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable); int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable);
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable);
int spi_nor_wait_till_ready(struct spi_nor *nor); int spi_nor_wait_till_ready(struct spi_nor *nor);
int spi_nor_global_block_unlock(struct spi_nor *nor); int spi_nor_global_block_unlock(struct spi_nor *nor);
int spi_nor_prep_and_lock(struct spi_nor *nor); int spi_nor_prep_and_lock(struct spi_nor *nor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment