diff --git a/doc/services/storage/nvmem/index.rst b/doc/services/storage/nvmem/index.rst index 91aa2e78824..5c4cfeff3a1 100644 --- a/doc/services/storage/nvmem/index.rst +++ b/doc/services/storage/nvmem/index.rst @@ -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 ******************* diff --git a/subsys/nvmem/Kconfig b/subsys/nvmem/Kconfig index d05a869f8c2..62f2ffd6c8b 100644 --- a/subsys/nvmem/Kconfig +++ b/subsys/nvmem/Kconfig @@ -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" diff --git a/subsys/nvmem/nvmem.c b/subsys/nvmem/nvmem.c index 97eb6233e0b..82e09a1802c 100644 --- a/subsys/nvmem/nvmem.c +++ b/subsys/nvmem/nvmem.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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; }