drivers/nvmem/nintendo-otp.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/nintendo-otp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/nintendo-otp.c- Extension
.c- Size
- 3096 bytes
- Lines
- 123
- 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/mod_devicetable.hlinux/nvmem-provider.hlinux/of_device.hlinux/platform_device.h
Detected Declarations
struct nintendo_otp_privstruct nintendo_otp_devtype_datafunction nintendo_otp_reg_readfunction nintendo_otp_probe
Annotated Snippet
struct nintendo_otp_priv {
void __iomem *regs;
};
struct nintendo_otp_devtype_data {
const char *name;
unsigned int num_banks;
};
static const struct nintendo_otp_devtype_data hollywood_otp_data = {
.name = "wii-otp",
.num_banks = 1,
};
static const struct nintendo_otp_devtype_data latte_otp_data = {
.name = "wiiu-otp",
.num_banks = 8,
};
static int nintendo_otp_reg_read(void *context,
unsigned int reg, void *_val, size_t bytes)
{
struct nintendo_otp_priv *priv = context;
u32 *val = _val;
int words = bytes / WORD_SIZE;
u32 bank, addr;
while (words--) {
bank = (reg / BANK_SIZE) << 8;
addr = (reg / WORD_SIZE) % (BANK_SIZE / WORD_SIZE);
iowrite32be(OTP_READ | bank | addr, priv->regs + HW_OTPCMD);
*val++ = ioread32be(priv->regs + HW_OTPDATA);
reg += WORD_SIZE;
}
return 0;
}
static const struct of_device_id nintendo_otp_of_table[] = {
{ .compatible = "nintendo,hollywood-otp", .data = &hollywood_otp_data },
{ .compatible = "nintendo,latte-otp", .data = &latte_otp_data },
{/* sentinel */},
};
MODULE_DEVICE_TABLE(of, nintendo_otp_of_table);
static int nintendo_otp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
const struct of_device_id *of_id =
of_match_device(nintendo_otp_of_table, dev);
struct nvmem_device *nvmem;
struct nintendo_otp_priv *priv;
struct nvmem_config config = {
.stride = WORD_SIZE,
.word_size = WORD_SIZE,
.reg_read = nintendo_otp_reg_read,
.read_only = true,
.root_only = true,
};
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->regs))
return PTR_ERR(priv->regs);
if (of_id->data) {
const struct nintendo_otp_devtype_data *data = of_id->data;
config.name = data->name;
config.size = data->num_banks * BANK_SIZE;
}
config.dev = dev;
config.priv = priv;
nvmem = devm_nvmem_register(dev, &config);
return PTR_ERR_OR_ZERO(nvmem);
}
static struct platform_driver nintendo_otp_driver = {
.probe = nintendo_otp_probe,
.driver = {
.name = "nintendo-otp",
.of_match_table = nintendo_otp_of_table,
},
};
Annotation
- Immediate include surface: `linux/device.h`, `linux/io.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/nvmem-provider.h`, `linux/of_device.h`, `linux/platform_device.h`.
- Detected declarations: `struct nintendo_otp_priv`, `struct nintendo_otp_devtype_data`, `function nintendo_otp_reg_read`, `function nintendo_otp_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.