[PATCH 10/14] misc: Implement nvmem interface
Sean Anderson
sean.anderson at seco.com
Tue Feb 8 00:42:08 CET 2022
This adds nvmem support for misc devices. Short reads/writes are not
allowed, so we need to translate the return code a bit. This breaks the API
slightly, because the original buffer shouldn't be touched if we fail while
writing. If this becomes an issue, we can add a bounce buffer here.
Signed-off-by: Sean Anderson <sean.anderson at seco.com>
---
drivers/misc/misc-uclass.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
index cfe9d562fa..6bbc78c38a 100644
--- a/drivers/misc/misc-uclass.c
+++ b/drivers/misc/misc-uclass.c
@@ -9,6 +9,7 @@
#include <dm.h>
#include <errno.h>
#include <misc.h>
+#include <nvmem.h>
/*
* Implement a miscellaneous uclass for those do not fit other more
@@ -74,3 +75,33 @@ UCLASS_DRIVER(misc) = {
.post_bind = dm_scan_fdt_dev,
#endif
};
+
+static int misc_nvmem_read(struct udevice *dev, unsigned int offset, void *buf,
+ size_t size)
+{
+ int ret = misc_read(dev, offset, buf, size);
+
+ if (ret < 0)
+ return ret;
+ if (ret != size)
+ return -EIO;
+ return 0;
+}
+
+static int misc_nvmem_write(struct udevice *dev, unsigned int offset,
+ const void *buf, size_t size)
+{
+ int ret = misc_write(dev, offset, buf, size);
+
+ if (ret < 0)
+ return ret;
+ if (ret != size)
+ return -EIO;
+ return 0;
+}
+
+NVMEM_INTERFACE(misc) = {
+ .id = UCLASS_MISC,
+ .read = misc_nvmem_read,
+ .write = misc_nvmem_write,
+};
--
2.25.1
More information about the U-Boot
mailing list