nvmem: Add OTP API support

OTP drivers are the interface to One Time Programmable memory, which
is NVMEM. Add the interface with the OTP API to the NVMEM one.

Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
This commit is contained in:
Gatien Chevallier
2025-10-22 10:37:11 +02:00
committed by Fabio Baltieri
parent 7db8328b08
commit 624e018a5f
3 changed files with 19 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ Configuration
* :kconfig:option:`CONFIG_NVMEM`: Enables the NVMEM subsystem.
* :kconfig:option:`CONFIG_NVMEM_EEPROM`: Enables NVMEM support for EEPROM devices.
* :kconfig:option-regex:`CONFIG_NVMEM_FLASH.*`: Configure NVMEM support for flash devices.
* :kconfig:option-regex:`CONFIG_NVMEM_OTP.*`: Configure NVMEM support for OTP devices.
Devicetree Bindings
*******************

View File

@@ -26,6 +26,15 @@ config NVMEM_FLASH_WRITE
to write to flash devices requiring out-of-bands erase or
taking write-block sizes into account.
config NVMEM_OTP
bool "NVMEM (read) support for OTP memory handling devices"
default y
depends on OTP
config NVMEM_OTP_WRITE
bool "NVMEM (write) support for OTP memory handling devices"
depends on NVMEM_OTP && OTP_PROGRAM
module = NVMEM
module-str = nvmem
source "subsys/logging/Kconfig.template.log_config"

View File

@@ -7,6 +7,7 @@
#include <errno.h>
#include <zephyr/drivers/eeprom.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/drivers/otp.h>
#include <zephyr/nvmem.h>
#include <zephyr/sys/__assert.h>
@@ -30,6 +31,10 @@ int nvmem_cell_read(const struct nvmem_cell *cell, void *buf, off_t off, size_t
return flash_read(cell->dev, cell->offset + off, buf, len);
}
if (IS_ENABLED(CONFIG_NVMEM_OTP) && DEVICE_API_IS(otp, cell->dev)) {
return otp_read(cell->dev, cell->offset + off, buf, len);
}
return -ENXIO;
}
@@ -57,5 +62,9 @@ int nvmem_cell_write(const struct nvmem_cell *cell, const void *buf, off_t off,
return flash_write(cell->dev, cell->offset + off, buf, len);
}
if (IS_ENABLED(CONFIG_NVMEM_OTP_WRITE) && DEVICE_API_IS(otp, cell->dev)) {
return otp_program(cell->dev, cell->offset + off, buf, len);
}
return -ENXIO;
}