@@ -1598,6 +1598,12 @@ static int stm_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len)
15981598 return stm_is_locked_sr (nor , ofs , len , status );
15991599}
16001600
1601+ static const struct spi_nor_locking_ops stm_locking_ops = {
1602+ .lock = stm_lock ,
1603+ .unlock = stm_unlock ,
1604+ .is_locked = stm_is_locked ,
1605+ };
1606+
16011607static int spi_nor_lock (struct mtd_info * mtd , loff_t ofs , uint64_t len )
16021608{
16031609 struct spi_nor * nor = mtd_to_spi_nor (mtd );
@@ -1607,7 +1613,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
16071613 if (ret )
16081614 return ret ;
16091615
1610- ret = nor -> flash_lock (nor , ofs , len );
1616+ ret = nor -> params . locking_ops -> lock (nor , ofs , len );
16111617
16121618 spi_nor_unlock_and_unprep (nor , SPI_NOR_OPS_UNLOCK );
16131619 return ret ;
@@ -1622,7 +1628,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
16221628 if (ret )
16231629 return ret ;
16241630
1625- ret = nor -> flash_unlock (nor , ofs , len );
1631+ ret = nor -> params . locking_ops -> unlock (nor , ofs , len );
16261632
16271633 spi_nor_unlock_and_unprep (nor , SPI_NOR_OPS_LOCK );
16281634 return ret ;
@@ -1637,7 +1643,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
16371643 if (ret )
16381644 return ret ;
16391645
1640- ret = nor -> flash_is_locked (nor , ofs , len );
1646+ ret = nor -> params . locking_ops -> is_locked (nor , ofs , len );
16411647
16421648 spi_nor_unlock_and_unprep (nor , SPI_NOR_OPS_LOCK );
16431649 return ret ;
@@ -4148,6 +4154,7 @@ static void macronix_set_default_init(struct spi_nor *nor)
41484154
41494155static void st_micron_set_default_init (struct spi_nor * nor )
41504156{
4157+ nor -> flags |= SNOR_F_HAS_LOCK ;
41514158 nor -> params .quad_enable = NULL ;
41524159 nor -> params .set_4byte = st_micron_set_4byte ;
41534160}
@@ -4291,6 +4298,23 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
42914298 spi_nor_init_uniform_erase_map (map , erase_mask , params -> size );
42924299}
42934300
4301+ /**
4302+ * spi_nor_late_init_params() - Late initialization of default flash parameters.
4303+ * @nor: pointer to a 'struct spi_nor'
4304+ *
4305+ * Used to set default flash parameters and settings when the ->default_init()
4306+ * hook or the SFDP parser let voids.
4307+ */
4308+ static void spi_nor_late_init_params (struct spi_nor * nor )
4309+ {
4310+ /*
4311+ * NOR protection support. When locking_ops are not provided, we pick
4312+ * the default ones.
4313+ */
4314+ if (nor -> flags & SNOR_F_HAS_LOCK && !nor -> params .locking_ops )
4315+ nor -> params .locking_ops = & stm_locking_ops ;
4316+ }
4317+
42944318/**
42954319 * spi_nor_init_params() - Initialize the flash's parameters and settings.
42964320 * @nor: pointer to a 'struct spi-nor'.
@@ -4316,6 +4340,10 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
43164340 * Please note that there is a ->post_bfpt() fixup hook that can overwrite
43174341 * the flash parameters and settings immediately after parsing the Basic
43184342 * Flash Parameter Table.
4343+ *
4344+ * 4/ Late default flash parameters initialization, used when the
4345+ * ->default_init() hook or the SFDP parser do not set specific params.
4346+ * spi_nor_late_init_params()
43194347 */
43204348static void spi_nor_init_params (struct spi_nor * nor )
43214349{
@@ -4326,6 +4354,8 @@ static void spi_nor_init_params(struct spi_nor *nor)
43264354 if ((nor -> info -> flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ )) &&
43274355 !(nor -> info -> flags & SPI_NOR_SKIP_SFDP ))
43284356 spi_nor_sfdp_init_params (nor );
4357+
4358+ spi_nor_late_init_params (nor );
43294359}
43304360
43314361static int spi_nor_select_read (struct spi_nor * nor ,
@@ -4707,6 +4737,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
47074737 if (info -> flags & SPI_S3AN )
47084738 nor -> flags |= SNOR_F_READY_XSR_RDY ;
47094739
4740+ if (info -> flags & SPI_NOR_HAS_LOCK )
4741+ nor -> flags |= SNOR_F_HAS_LOCK ;
4742+
47104743 /*
47114744 * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
47124745 * with the software protection bits set.
@@ -4731,16 +4764,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
47314764 mtd -> _read = spi_nor_read ;
47324765 mtd -> _resume = spi_nor_resume ;
47334766
4734- /* NOR protection support for STmicro/Micron chips and similar */
4735- if (JEDEC_MFR (info ) == SNOR_MFR_ST ||
4736- JEDEC_MFR (info ) == SNOR_MFR_MICRON ||
4737- info -> flags & SPI_NOR_HAS_LOCK ) {
4738- nor -> flash_lock = stm_lock ;
4739- nor -> flash_unlock = stm_unlock ;
4740- nor -> flash_is_locked = stm_is_locked ;
4741- }
4742-
4743- if (nor -> flash_lock && nor -> flash_unlock && nor -> flash_is_locked ) {
4767+ if (nor -> params .locking_ops ) {
47444768 mtd -> _lock = spi_nor_lock ;
47454769 mtd -> _unlock = spi_nor_unlock ;
47464770 mtd -> _is_locked = spi_nor_is_locked ;
0 commit comments