Lines Matching refs:nor

9 #include <linux/mtd/spi-nor.h>
13 static u8 spi_nor_get_sr_bp_mask(struct spi_nor *nor)
17 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6)
20 if (nor->flags & SNOR_F_HAS_4BIT_BP)
26 static u8 spi_nor_get_sr_tb_mask(struct spi_nor *nor)
28 if (nor->flags & SNOR_F_HAS_SR_TB_BIT6)
34 static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
37 u8 mask = spi_nor_get_sr_bp_mask(nor);
41 bp_slots_needed = ilog2(nor->info->n_sectors);
44 return nor->info->sector_size <<
47 return nor->info->sector_size;
50 static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
53 struct mtd_info *mtd = &nor->mtd;
55 u8 mask = spi_nor_get_sr_bp_mask(nor);
56 u8 tb_mask = spi_nor_get_sr_tb_mask(nor);
59 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3_BIT6)
71 min_prot_len = spi_nor_get_min_prot_length_sr(nor);
77 if (nor->flags & SNOR_F_HAS_SR_TB && sr & tb_mask)
87 static bool spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
96 spi_nor_get_locked_range_sr(nor, sr, &lock_offs, &lock_len);
109 static bool spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
112 return spi_nor_check_lock_status_sr(nor, ofs, len, sr, true);
115 static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs,
118 return spi_nor_check_lock_status_sr(nor, ofs, len, sr, false);
154 static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
156 struct mtd_info *mtd = &nor->mtd;
159 u8 mask = spi_nor_get_sr_bp_mask(nor);
160 u8 tb_mask = spi_nor_get_sr_tb_mask(nor);
163 bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB;
166 ret = spi_nor_read_sr(nor, nor->bouncebuf);
170 status_old = nor->bouncebuf[0];
173 if (spi_nor_is_locked_sr(nor, ofs, len, status_old))
177 if (!spi_nor_is_locked_sr(nor, 0, ofs, status_old))
181 if (!spi_nor_is_locked_sr(nor, ofs + len, mtd->size - (ofs + len),
200 min_prot_len = spi_nor_get_min_prot_length_sr(nor);
204 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3)
218 * Disallow further writes if WP# pin is neither left floating nor
222 if (!(nor->flags & SNOR_F_NO_WP))
236 return spi_nor_write_sr_and_check(nor, status_new);
244 static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
246 struct mtd_info *mtd = &nor->mtd;
249 u8 mask = spi_nor_get_sr_bp_mask(nor);
250 u8 tb_mask = spi_nor_get_sr_tb_mask(nor);
253 bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB;
256 ret = spi_nor_read_sr(nor, nor->bouncebuf);
260 status_old = nor->bouncebuf[0];
263 if (spi_nor_is_unlocked_sr(nor, ofs, len, status_old))
267 if (!spi_nor_is_unlocked_sr(nor, 0, ofs, status_old))
271 if (!spi_nor_is_unlocked_sr(nor, ofs + len, mtd->size - (ofs + len),
290 min_prot_len = spi_nor_get_min_prot_length_sr(nor);
294 if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3)
319 return spi_nor_write_sr_and_check(nor, status_new);
329 static int spi_nor_sr_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len)
333 ret = spi_nor_read_sr(nor, nor->bouncebuf);
337 return spi_nor_is_locked_sr(nor, ofs, len, nor->bouncebuf[0]);
346 void spi_nor_init_default_locking_ops(struct spi_nor *nor)
348 nor->params->locking_ops = &spi_nor_sr_locking_ops;
353 struct spi_nor *nor = mtd_to_spi_nor(mtd);
356 ret = spi_nor_prep_and_lock(nor);
360 ret = nor->params->locking_ops->lock(nor, ofs, len);
362 spi_nor_unlock_and_unprep(nor);
368 struct spi_nor *nor = mtd_to_spi_nor(mtd);
371 ret = spi_nor_prep_and_lock(nor);
375 ret = nor->params->locking_ops->unlock(nor, ofs, len);
377 spi_nor_unlock_and_unprep(nor);
383 struct spi_nor *nor = mtd_to_spi_nor(mtd);
386 ret = spi_nor_prep_and_lock(nor);
390 ret = nor->params->locking_ops->is_locked(nor, ofs, len);
392 spi_nor_unlock_and_unprep(nor);
398 * @nor: pointer to a 'struct spi_nor'.
408 void spi_nor_try_unlock_all(struct spi_nor *nor)
412 if (!(nor->flags & SNOR_F_HAS_LOCK))
415 dev_dbg(nor->dev, "Unprotecting entire flash array\n");
417 ret = spi_nor_unlock(&nor->mtd, 0, nor->params->size);
419 dev_dbg(nor->dev, "Failed to unlock the entire flash memory array\n");
422 void spi_nor_set_mtd_locking_ops(struct spi_nor *nor)
424 struct mtd_info *mtd = &nor->mtd;
426 if (!nor->params->locking_ops)