drivers/nvmem/s32g-ocotp-nvmem.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/s32g-ocotp-nvmem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/s32g-ocotp-nvmem.c- Extension
.c- Size
- 2431 bytes
- Lines
- 101
- Domain
- Driver Families
- Bucket
- drivers/nvmem
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/io.hlinux/module.hlinux/nvmem-provider.hlinux/of.hlinux/of_device.hlinux/platform_device.h
Detected Declarations
struct s32g_ocotp_privfunction s32g_ocotp_readfunction s32g_ocotp_probe
Annotated Snippet
struct s32g_ocotp_priv {
struct device *dev;
void __iomem *base;
};
static int s32g_ocotp_read(void *context, unsigned int offset,
void *val, size_t bytes)
{
struct s32g_ocotp_priv *s32g_data = context;
u32 *dst = val;
while (bytes >= sizeof(u32)) {
*dst++ = ioread32(s32g_data->base + offset);
bytes -= sizeof(u32);
offset += sizeof(u32);
}
return 0;
}
static struct nvmem_keepout s32g_keepouts[] = {
{ .start = 0, .end = 520 },
{ .start = 540, .end = 564 },
{ .start = 596, .end = 664 },
{ .start = 668, .end = 676 },
{ .start = 684, .end = 732 },
{ .start = 744, .end = 864 },
{ .start = 908, .end = 924 },
{ .start = 928, .end = 936 },
{ .start = 948, .end = 964 },
{ .start = 968, .end = 976 },
{ .start = 984, .end = 1012 },
};
static struct nvmem_config s32g_ocotp_nvmem_config = {
.name = "s32g-ocotp",
.add_legacy_fixed_of_cells = true,
.read_only = true,
.word_size = 4,
.reg_read = s32g_ocotp_read,
.keepout = s32g_keepouts,
.nkeepout = ARRAY_SIZE(s32g_keepouts),
};
static const struct of_device_id ocotp_of_match[] = {
{ .compatible = "nxp,s32g2-ocotp" },
{ /* sentinel */ }
};
static int s32g_ocotp_probe(struct platform_device *pdev)
{
struct s32g_ocotp_priv *s32g_data;
struct device *dev = &pdev->dev;
struct nvmem_device *nvmem;
struct resource *res;
s32g_data = devm_kzalloc(dev, sizeof(*s32g_data), GFP_KERNEL);
if (!s32g_data)
return -ENOMEM;
s32g_data->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(s32g_data->base))
return dev_err_probe(dev, PTR_ERR(s32g_data->base),
"Cannot map OCOTP device.\n");
s32g_data->dev = dev;
s32g_ocotp_nvmem_config.dev = dev;
s32g_ocotp_nvmem_config.priv = s32g_data;
s32g_ocotp_nvmem_config.size = resource_size(res);
nvmem = devm_nvmem_register(dev, &s32g_ocotp_nvmem_config);
return PTR_ERR_OR_ZERO(nvmem);
}
static struct platform_driver s32g_ocotp_driver = {
.probe = s32g_ocotp_probe,
.driver = {
.name = "s32g-ocotp",
.of_match_table = ocotp_of_match,
},
};
module_platform_driver(s32g_ocotp_driver);
MODULE_AUTHOR("NXP");
MODULE_DESCRIPTION("S32G OCOTP driver");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/device.h`, `linux/io.h`, `linux/module.h`, `linux/nvmem-provider.h`, `linux/of.h`, `linux/of_device.h`, `linux/platform_device.h`.
- Detected declarations: `struct s32g_ocotp_priv`, `function s32g_ocotp_read`, `function s32g_ocotp_probe`.
- Atlas domain: Driver Families / drivers/nvmem.
- Implementation status: source implementation candidate.
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.