drivers/mtd/nand/spi/otp.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/spi/otp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/spi/otp.c- Extension
.c- Size
- 8901 bytes
- Lines
- 363
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mtd/mtd.hlinux/mtd/spinand.h
Detected Declarations
function Copyrightfunction spinand_otp_sizefunction spinand_fact_otp_sizefunction spinand_user_otp_sizefunction spinand_otp_check_boundsfunction spinand_user_otp_check_boundsfunction spinand_otp_rwfunction spinand_fact_otp_readfunction spinand_user_otp_readfunction spinand_user_otp_writefunction spinand_mtd_otp_infofunction spinand_mtd_fact_otp_infofunction spinand_mtd_user_otp_infofunction spinand_mtd_otp_readfunction spinand_mtd_fact_otp_readfunction spinand_mtd_user_otp_readfunction spinand_mtd_user_otp_writefunction spinand_mtd_user_otp_erasefunction spinand_mtd_user_otp_lockfunction spinand_set_mtd_otp_ops
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2025, SaluteDevices. All Rights Reserved.
*
* Author: Martin Kurbanov <mmkurbanov@salutedevices.com>
*/
#include <linux/mtd/mtd.h>
#include <linux/mtd/spinand.h>
/**
* spinand_otp_page_size() - Get SPI-NAND OTP page size
* @spinand: the spinand device
*
* Return: the OTP page size.
*/
size_t spinand_otp_page_size(struct spinand_device *spinand)
{
struct nand_device *nand = spinand_to_nand(spinand);
return nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
}
static size_t spinand_otp_size(struct spinand_device *spinand,
const struct spinand_otp_layout *layout)
{
return layout->npages * spinand_otp_page_size(spinand);
}
/**
* spinand_fact_otp_size() - Get SPI-NAND factory OTP area size
* @spinand: the spinand device
*
* Return: the OTP size.
*/
size_t spinand_fact_otp_size(struct spinand_device *spinand)
{
return spinand_otp_size(spinand, &spinand->fact_otp->layout);
}
/**
* spinand_user_otp_size() - Get SPI-NAND user OTP area size
* @spinand: the spinand device
*
* Return: the OTP size.
*/
size_t spinand_user_otp_size(struct spinand_device *spinand)
{
return spinand_otp_size(spinand, &spinand->user_otp->layout);
}
static int spinand_otp_check_bounds(struct spinand_device *spinand, loff_t ofs,
size_t len,
const struct spinand_otp_layout *layout)
{
if (ofs < 0 || ofs + len > spinand_otp_size(spinand, layout))
return -EINVAL;
return 0;
}
static int spinand_user_otp_check_bounds(struct spinand_device *spinand,
loff_t ofs, size_t len)
{
return spinand_otp_check_bounds(spinand, ofs, len,
&spinand->user_otp->layout);
}
static int spinand_otp_rw(struct spinand_device *spinand, loff_t ofs,
size_t len, size_t *retlen, u8 *buf, bool is_write,
const struct spinand_otp_layout *layout)
{
struct nand_page_io_req req = {};
unsigned long long page;
size_t copied = 0;
size_t otp_pagesize = spinand_otp_page_size(spinand);
int ret;
if (!len)
return 0;
ret = spinand_otp_check_bounds(spinand, ofs, len, layout);
if (ret)
return ret;
ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, CFG_OTP_ENABLE);
if (ret)
return ret;
page = ofs;
Annotation
- Immediate include surface: `linux/mtd/mtd.h`, `linux/mtd/spinand.h`.
- Detected declarations: `function Copyright`, `function spinand_otp_size`, `function spinand_fact_otp_size`, `function spinand_user_otp_size`, `function spinand_otp_check_bounds`, `function spinand_user_otp_check_bounds`, `function spinand_otp_rw`, `function spinand_fact_otp_read`, `function spinand_user_otp_read`, `function spinand_user_otp_write`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.