Lines Matching +full:programmable +full:- +full:security

1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/mtd/spi-nor.h>
14 #define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len)
15 #define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions)
18 * spi_nor_otp_read_secr() - read security register
24 * Read a security register by using the SPINOR_OP_RSECR commands.
26 * In Winbond/GigaDevice datasheets the term "security register" stands for
27 * an one-time-programmable memory area, consisting of multiple bytes (usually
28 * 256). Thus one "security register" maps to one OTP region.
34 * Return: number of bytes read successfully, -errno otherwise
43 read_opcode = nor->read_opcode; in spi_nor_otp_read_secr()
44 addr_nbytes = nor->addr_nbytes; in spi_nor_otp_read_secr()
45 read_dummy = nor->read_dummy; in spi_nor_otp_read_secr()
46 read_proto = nor->read_proto; in spi_nor_otp_read_secr()
47 rdesc = nor->dirmap.rdesc; in spi_nor_otp_read_secr()
49 nor->read_opcode = SPINOR_OP_RSECR; in spi_nor_otp_read_secr()
50 nor->read_dummy = 8; in spi_nor_otp_read_secr()
51 nor->read_proto = SNOR_PROTO_1_1_1; in spi_nor_otp_read_secr()
52 nor->dirmap.rdesc = NULL; in spi_nor_otp_read_secr()
56 nor->read_opcode = read_opcode; in spi_nor_otp_read_secr()
57 nor->addr_nbytes = addr_nbytes; in spi_nor_otp_read_secr()
58 nor->read_dummy = read_dummy; in spi_nor_otp_read_secr()
59 nor->read_proto = read_proto; in spi_nor_otp_read_secr()
60 nor->dirmap.rdesc = rdesc; in spi_nor_otp_read_secr()
66 * spi_nor_otp_write_secr() - write security register
72 * Write a security register by using the SPINOR_OP_PSECR commands.
74 * For more information on the term "security register", see the documentation
81 * Return: number of bytes written successfully, -errno otherwise
91 program_opcode = nor->program_opcode; in spi_nor_otp_write_secr()
92 addr_nbytes = nor->addr_nbytes; in spi_nor_otp_write_secr()
93 write_proto = nor->write_proto; in spi_nor_otp_write_secr()
94 wdesc = nor->dirmap.wdesc; in spi_nor_otp_write_secr()
96 nor->program_opcode = SPINOR_OP_PSECR; in spi_nor_otp_write_secr()
97 nor->write_proto = SNOR_PROTO_1_1_1; in spi_nor_otp_write_secr()
98 nor->dirmap.wdesc = NULL; in spi_nor_otp_write_secr()
102 * flashes only have one page per security register. in spi_nor_otp_write_secr()
115 nor->program_opcode = program_opcode; in spi_nor_otp_write_secr()
116 nor->addr_nbytes = addr_nbytes; in spi_nor_otp_write_secr()
117 nor->write_proto = write_proto; in spi_nor_otp_write_secr()
118 nor->dirmap.wdesc = wdesc; in spi_nor_otp_write_secr()
124 * spi_nor_otp_erase_secr() - erase a security register
126 * @addr: offset of the security register to be erased
128 * Erase a security register by using the SPINOR_OP_ESECR command.
130 * For more information on the term "security register", see the documentation
135 * Return: 0 on success, -errno otherwise
139 u8 erase_opcode = nor->erase_opcode; in spi_nor_otp_erase_secr()
146 nor->erase_opcode = SPINOR_OP_ESECR; in spi_nor_otp_erase_secr()
148 nor->erase_opcode = erase_opcode; in spi_nor_otp_erase_secr()
160 return -EINVAL; in spi_nor_otp_lock_bit_cr()
166 * spi_nor_otp_lock_sr2() - lock the OTP region
170 * Lock the OTP region by writing the status register-2. This method is used on
173 * Return: 0 on success, -errno otherwise.
177 u8 *cr = nor->bouncebuf; in spi_nor_otp_lock_sr2()
198 * spi_nor_otp_is_locked_sr2() - get the OTP region lock status
202 * Retrieve the OTP region lock bit by reading the status register-2. This
205 * Return: 0 on success, -errno otherwise.
209 u8 *cr = nor->bouncebuf; in spi_nor_otp_is_locked_sr2()
225 const struct spi_nor_otp_organization *org = nor->params->otp.org; in spi_nor_otp_region_start()
227 return org->base + region * org->offset; in spi_nor_otp_region_start()
250 const struct spi_nor_otp_ops *ops = nor->params->otp.ops; in spi_nor_mtd_otp_info()
256 return -ENOSPC; in spi_nor_mtd_otp_info()
263 buf->start = spi_nor_otp_region_to_offset(nor, i); in spi_nor_mtd_otp_info()
264 buf->length = spi_nor_otp_region_len(nor); in spi_nor_mtd_otp_info()
266 locked = ops->is_locked(nor, i); in spi_nor_mtd_otp_info()
272 buf->locked = !!locked; in spi_nor_mtd_otp_info()
287 const struct spi_nor_otp_ops *ops = nor->params->otp.ops; in spi_nor_mtd_otp_range_is_locked()
296 region <= spi_nor_otp_offset_to_region(nor, ofs + len - 1); in spi_nor_mtd_otp_range_is_locked()
298 locked = ops->is_locked(nor, region); in spi_nor_mtd_otp_range_is_locked()
312 const struct spi_nor_otp_ops *ops = nor->params->otp.ops; in spi_nor_mtd_otp_read_write()
323 total_len = min_t(size_t, total_len, spi_nor_otp_size(nor) - ofs); in spi_nor_mtd_otp_read_write()
337 ret = -EROFS; in spi_nor_mtd_otp_read_write()
357 rofs = ofs & (rlen - 1); in spi_nor_mtd_otp_read_write()
360 len = min_t(size_t, total_len, rlen - rofs); in spi_nor_mtd_otp_read_write()
363 ret = ops->write(nor, rstart + rofs, len, buf); in spi_nor_mtd_otp_read_write()
365 ret = ops->read(nor, rstart + rofs, len, (u8 *)buf); in spi_nor_mtd_otp_read_write()
367 ret = -EIO; in spi_nor_mtd_otp_read_write()
374 total_len -= ret; in spi_nor_mtd_otp_read_write()
398 const struct spi_nor_otp_ops *ops = nor->params->otp.ops; in spi_nor_mtd_otp_erase()
405 if (!ops->erase) in spi_nor_mtd_otp_erase()
406 return -EOPNOTSUPP; in spi_nor_mtd_otp_erase()
412 return -EINVAL; in spi_nor_mtd_otp_erase()
416 return -EINVAL; in spi_nor_mtd_otp_erase()
426 ret = -EROFS; in spi_nor_mtd_otp_erase()
434 ret = ops->erase(nor, rstart); in spi_nor_mtd_otp_erase()
438 len -= rlen; in spi_nor_mtd_otp_erase()
451 const struct spi_nor_otp_ops *ops = nor->params->otp.ops; in spi_nor_mtd_otp_lock()
457 return -EINVAL; in spi_nor_mtd_otp_lock()
461 return -EINVAL; in spi_nor_mtd_otp_lock()
469 ret = ops->lock(nor, region); in spi_nor_mtd_otp_lock()
473 len -= rlen; in spi_nor_mtd_otp_lock()
485 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_otp_ops()
487 if (!nor->params->otp.ops) in spi_nor_set_mtd_otp_ops()
502 mtd->_get_user_prot_info = spi_nor_mtd_otp_info; in spi_nor_set_mtd_otp_ops()
503 mtd->_read_user_prot_reg = spi_nor_mtd_otp_read; in spi_nor_set_mtd_otp_ops()
504 mtd->_write_user_prot_reg = spi_nor_mtd_otp_write; in spi_nor_set_mtd_otp_ops()
505 mtd->_lock_user_prot_reg = spi_nor_mtd_otp_lock; in spi_nor_set_mtd_otp_ops()
506 mtd->_erase_user_prot_reg = spi_nor_mtd_otp_erase; in spi_nor_set_mtd_otp_ops()