Lines Matching +full:factory +full:- +full:otp

1 // SPDX-License-Identifier: GPL-2.0
3 * OTP support for SPI NOR flashes
11 #include <linux/mtd/spi-nor.h>
15 #define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len)
16 #define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions)
19 * spi_nor_otp_read_secr() - read security register
28 * an one-time-programmable memory area, consisting of multiple bytes (usually
29 * 256). Thus one "security register" maps to one OTP region.
35 * Return: number of bytes read successfully, -errno otherwise
44 read_opcode = nor->read_opcode;
45 addr_nbytes = nor->addr_nbytes;
46 read_dummy = nor->read_dummy;
47 read_proto = nor->read_proto;
48 rdesc = nor->dirmap.rdesc;
50 nor->read_opcode = SPINOR_OP_RSECR;
51 nor->read_dummy = 8;
52 nor->read_proto = SNOR_PROTO_1_1_1;
53 nor->dirmap.rdesc = NULL;
57 nor->read_opcode = read_opcode;
58 nor->addr_nbytes = addr_nbytes;
59 nor->read_dummy = read_dummy;
60 nor->read_proto = read_proto;
61 nor->dirmap.rdesc = rdesc;
67 * spi_nor_otp_write_secr() - write security register
82 * Return: number of bytes written successfully, -errno otherwise
92 program_opcode = nor->program_opcode;
93 addr_nbytes = nor->addr_nbytes;
94 write_proto = nor->write_proto;
95 wdesc = nor->dirmap.wdesc;
97 nor->program_opcode = SPINOR_OP_PSECR;
98 nor->write_proto = SNOR_PROTO_1_1_1;
99 nor->dirmap.wdesc = NULL;
116 nor->program_opcode = program_opcode;
117 nor->addr_nbytes = addr_nbytes;
118 nor->write_proto = write_proto;
119 nor->dirmap.wdesc = wdesc;
125 * spi_nor_otp_erase_secr() - erase a security register
136 * Return: 0 on success, -errno otherwise
140 u8 erase_opcode = nor->erase_opcode;
147 nor->erase_opcode = SPINOR_OP_ESECR;
149 nor->erase_opcode = erase_opcode;
161 return -EINVAL;
167 * spi_nor_otp_lock_sr2() - lock the OTP region
169 * @region: OTP region
171 * Lock the OTP region by writing the status register-2. This method is used on
174 * Return: 0 on success, -errno otherwise.
178 u8 *cr = nor->bouncebuf;
199 * spi_nor_otp_is_locked_sr2() - get the OTP region lock status
201 * @region: OTP region
203 * Retrieve the OTP region lock bit by reading the status register-2. This
206 * Return: 0 on success, -errno otherwise.
210 u8 *cr = nor->bouncebuf;
226 const struct spi_nor_otp_organization *org = nor->params->otp.org;
228 return org->base + region * org->offset;
236 /* Translate the file offsets from and to OTP regions. */
251 const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
257 return -ENOSPC;
264 buf->start = spi_nor_otp_region_to_offset(nor, i);
265 buf->length = spi_nor_otp_region_len(nor);
267 locked = ops->is_locked(nor, i);
273 buf->locked = !!locked;
288 const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
293 * If any of the affected OTP regions are locked the entire range is
297 region <= spi_nor_otp_offset_to_region(nor, ofs + len - 1);
299 locked = ops->is_locked(nor, region);
313 const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
324 total_len = min_t(size_t, total_len, spi_nor_otp_size(nor) - ofs);
338 ret = -EROFS;
345 * The OTP regions are mapped into a contiguous area starting
347 * file offsets to the address of an OTP region as used in the
354 * The size of a OTP region is expected to be a power of two,
358 rofs = ofs & (rlen - 1);
360 /* don't access beyond one OTP region */
361 len = min_t(size_t, total_len, rlen - rofs);
364 ret = ops->write(nor, rstart + rofs, len, buf);
366 ret = ops->read(nor, rstart + rofs, len, (u8 *)buf);
368 ret = -EIO;
375 total_len -= ret;
399 const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
405 /* OTP erase is optional */
406 if (!ops->erase)
407 return -EOPNOTSUPP;
413 return -EINVAL;
417 return -EINVAL;
427 ret = -EROFS;
435 ret = ops->erase(nor, rstart);
439 len -= rlen;
452 const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
458 return -EINVAL;
462 return -EINVAL;
470 ret = ops->lock(nor, region);
474 len -= rlen;
486 struct mtd_info *mtd = &nor->mtd;
488 if (!nor->params->otp.ops)
498 * different variants. One with a factory locked OTP area and one where
499 * it is left to the user to write to it. The factory locked OTP is
503 mtd->_get_user_prot_info = spi_nor_mtd_otp_info;
504 mtd->_read_user_prot_reg = spi_nor_mtd_otp_read;
505 mtd->_write_user_prot_reg = spi_nor_mtd_otp_write;
506 mtd->_lock_user_prot_reg = spi_nor_mtd_otp_lock;
507 mtd->_erase_user_prot_reg = spi_nor_mtd_otp_erase;