Lines Matching full:nor

3  * SPI NOR Software Write Protection logic.
9 #include <linux/mtd/spi-nor.h>
13 static u8 spi_nor_get_sr_bp_mask(struct spi_nor *nor) in spi_nor_get_sr_bp_mask() argument
17 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6) in spi_nor_get_sr_bp_mask()
20 if (nor->flags & SNOR_F_HAS_4BIT_BP) in spi_nor_get_sr_bp_mask()
26 static u8 spi_nor_get_sr_tb_mask(struct spi_nor *nor) in spi_nor_get_sr_tb_mask() argument
28 if (nor->flags & SNOR_F_HAS_SR_TB_BIT6) in spi_nor_get_sr_tb_mask()
34 static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor) in spi_nor_get_min_prot_length_sr() argument
41 unsigned int sector_size = nor->info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE; in spi_nor_get_min_prot_length_sr()
42 u64 n_sectors = div_u64(nor->params->size, sector_size); in spi_nor_get_min_prot_length_sr()
43 u8 mask = spi_nor_get_sr_bp_mask(nor); in spi_nor_get_min_prot_length_sr()
55 static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, in spi_nor_get_locked_range_sr() argument
58 struct mtd_info *mtd = &nor->mtd; in spi_nor_get_locked_range_sr()
60 u8 mask = spi_nor_get_sr_bp_mask(nor); in spi_nor_get_locked_range_sr()
61 u8 tb_mask = spi_nor_get_sr_tb_mask(nor); in spi_nor_get_locked_range_sr()
64 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3_BIT6) in spi_nor_get_locked_range_sr()
76 min_prot_len = spi_nor_get_min_prot_length_sr(nor); in spi_nor_get_locked_range_sr()
82 if (nor->flags & SNOR_F_HAS_SR_TB && sr & tb_mask) in spi_nor_get_locked_range_sr()
92 static bool spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs, in spi_nor_check_lock_status_sr() argument
101 spi_nor_get_locked_range_sr(nor, sr, &lock_offs, &lock_len); in spi_nor_check_lock_status_sr()
114 static bool spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, u64 len, u8 sr) in spi_nor_is_locked_sr() argument
116 return spi_nor_check_lock_status_sr(nor, ofs, len, sr, true); in spi_nor_is_locked_sr()
119 static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, u64 len, in spi_nor_is_unlocked_sr() argument
122 return spi_nor_check_lock_status_sr(nor, ofs, len, sr, false); in spi_nor_is_unlocked_sr()
158 static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len) in spi_nor_sr_lock() argument
160 struct mtd_info *mtd = &nor->mtd; in spi_nor_sr_lock()
163 u8 mask = spi_nor_get_sr_bp_mask(nor); in spi_nor_sr_lock()
164 u8 tb_mask = spi_nor_get_sr_tb_mask(nor); in spi_nor_sr_lock()
167 bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB; in spi_nor_sr_lock()
170 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_lock()
174 status_old = nor->bouncebuf[0]; in spi_nor_sr_lock()
177 if (spi_nor_is_locked_sr(nor, ofs, len, status_old)) in spi_nor_sr_lock()
181 if (!spi_nor_is_locked_sr(nor, 0, ofs, status_old)) in spi_nor_sr_lock()
185 if (!spi_nor_is_locked_sr(nor, ofs + len, mtd->size - (ofs + len), in spi_nor_sr_lock()
204 min_prot_len = spi_nor_get_min_prot_length_sr(nor); in spi_nor_sr_lock()
208 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3) in spi_nor_sr_lock()
222 * Disallow further writes if WP# pin is neither left floating nor in spi_nor_sr_lock()
226 if (!(nor->flags & SNOR_F_NO_WP)) in spi_nor_sr_lock()
240 return spi_nor_write_sr_and_check(nor, status_new); in spi_nor_sr_lock()
248 static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len) in spi_nor_sr_unlock() argument
250 struct mtd_info *mtd = &nor->mtd; in spi_nor_sr_unlock()
253 u8 mask = spi_nor_get_sr_bp_mask(nor); in spi_nor_sr_unlock()
254 u8 tb_mask = spi_nor_get_sr_tb_mask(nor); in spi_nor_sr_unlock()
257 bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB; in spi_nor_sr_unlock()
260 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_unlock()
264 status_old = nor->bouncebuf[0]; in spi_nor_sr_unlock()
267 if (spi_nor_is_unlocked_sr(nor, ofs, len, status_old)) in spi_nor_sr_unlock()
271 if (!spi_nor_is_unlocked_sr(nor, 0, ofs, status_old)) in spi_nor_sr_unlock()
275 if (!spi_nor_is_unlocked_sr(nor, ofs + len, mtd->size - (ofs + len), in spi_nor_sr_unlock()
294 min_prot_len = spi_nor_get_min_prot_length_sr(nor); in spi_nor_sr_unlock()
298 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3) in spi_nor_sr_unlock()
323 return spi_nor_write_sr_and_check(nor, status_new); in spi_nor_sr_unlock()
333 static int spi_nor_sr_is_locked(struct spi_nor *nor, loff_t ofs, u64 len) in spi_nor_sr_is_locked() argument
337 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_is_locked()
341 return spi_nor_is_locked_sr(nor, ofs, len, nor->bouncebuf[0]); in spi_nor_sr_is_locked()
350 void spi_nor_init_default_locking_ops(struct spi_nor *nor) in spi_nor_init_default_locking_ops() argument
352 nor->params->locking_ops = &spi_nor_sr_locking_ops; in spi_nor_init_default_locking_ops()
357 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_lock() local
360 ret = spi_nor_prep_and_lock(nor); in spi_nor_lock()
364 ret = nor->params->locking_ops->lock(nor, ofs, len); in spi_nor_lock()
366 spi_nor_unlock_and_unprep(nor); in spi_nor_lock()
372 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_unlock() local
375 ret = spi_nor_prep_and_lock(nor); in spi_nor_unlock()
379 ret = nor->params->locking_ops->unlock(nor, ofs, len); in spi_nor_unlock()
381 spi_nor_unlock_and_unprep(nor); in spi_nor_unlock()
387 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_is_locked() local
390 ret = spi_nor_prep_and_lock(nor); in spi_nor_is_locked()
394 ret = nor->params->locking_ops->is_locked(nor, ofs, len); in spi_nor_is_locked()
396 spi_nor_unlock_and_unprep(nor); in spi_nor_is_locked()
402 * @nor: pointer to a 'struct spi_nor'.
404 * Some SPI NOR flashes are write protected by default after a power-on reset
412 void spi_nor_try_unlock_all(struct spi_nor *nor) in spi_nor_try_unlock_all() argument
416 if (!(nor->flags & SNOR_F_HAS_LOCK)) in spi_nor_try_unlock_all()
419 dev_dbg(nor->dev, "Unprotecting entire flash array\n"); in spi_nor_try_unlock_all()
421 ret = spi_nor_unlock(&nor->mtd, 0, nor->params->size); in spi_nor_try_unlock_all()
423 dev_dbg(nor->dev, "Failed to unlock the entire flash memory array\n"); in spi_nor_try_unlock_all()
426 void spi_nor_set_mtd_locking_ops(struct spi_nor *nor) in spi_nor_set_mtd_locking_ops() argument
428 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_locking_ops()
430 if (!nor->params->locking_ops) in spi_nor_set_mtd_locking_ops()