mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 09/13] nvmem: add command to list nvmem devices
Date: Sat, 19 Jun 2021 05:45:12 +0200	[thread overview]
Message-ID: <20210619034516.6737-10-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210619034516.6737-1-a.fatoum@pengutronix.de>

When doing development around nvmem devices, it can be useful to list
which ones exist. Add a command to facilitate this. It can be extended
in future as the need arises (e.g.export cells into the environment?).

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/Kconfig               |  7 +++++++
 commands/Makefile              |  1 +
 commands/nvmem.c               | 24 ++++++++++++++++++++++++
 drivers/nvmem/core.c           |  9 +++++++++
 include/linux/nvmem-consumer.h |  2 ++
 5 files changed, 43 insertions(+)
 create mode 100644 commands/nvmem.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 5ae3cb3dd145..7bb36d6e417e 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -206,6 +206,13 @@ config CMD_REGULATOR
 	  the regulator command lists the currently registered regulators and
 	  their current state.
 
+config CMD_NVMEM
+	bool
+	depends on NVMEM
+	prompt "nvmem command"
+	help
+	  the nvmem command lists the currently registered nvmem devices.
+
 config CMD_LSPCI
 	bool
 	depends on PCI
diff --git a/commands/Makefile b/commands/Makefile
index 4b45d266fd56..ba5ea19eb202 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_CMD_SAVEENV)	+= saveenv.o
 obj-$(CONFIG_CMD_LOADENV)	+= loadenv.o
 obj-$(CONFIG_CMD_NAND)		+= nand.o
 obj-$(CONFIG_CMD_NANDTEST)	+= nandtest.o
+obj-$(CONFIG_CMD_NVMEM)		+= nvmem.o
 obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_MEMTESTER)	+= memtester/
 obj-$(CONFIG_CMD_TRUE)		+= true.o
diff --git a/commands/nvmem.c b/commands/nvmem.c
new file mode 100644
index 000000000000..a0e3d092e3cf
--- /dev/null
+++ b/commands/nvmem.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: © 2021 Ahmad Fatoum, Pengutronix
+
+#include <common.h>
+#include <command.h>
+#include <linux/nvmem-consumer.h>
+
+static int do_nvmem(int argc, char *argv[])
+{
+	nvmem_devices_print();
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(nvmem)
+BAREBOX_CMD_HELP_TEXT("Usage: nvmem")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(nvmem)
+	.cmd		= do_nvmem,
+	BAREBOX_CMD_DESC("list nvmem devices")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+	BAREBOX_CMD_HELP(cmd_nvmem_help)
+BAREBOX_CMD_END
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c060e627db4f..ae9c965c25e2 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -49,6 +49,15 @@ struct nvmem_cell {
 static LIST_HEAD(nvmem_cells);
 static LIST_HEAD(nvmem_devs);
 
+void nvmem_devices_print(void)
+{
+	struct nvmem_device *dev;
+
+	list_for_each_entry(dev, &nvmem_devs, node) {
+		printf("%s\n", dev_name(&dev->dev));
+	}
+}
+
 static ssize_t nvmem_cdev_read(struct cdev *cdev, void *buf, size_t count,
 			       loff_t offset, unsigned long flags)
 {
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 5f44cf00cdff..b979f23372a6 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -49,6 +49,8 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 int nvmem_device_cell_write(struct nvmem_device *nvmem,
 			    struct nvmem_cell_info *info, void *buf);
 
+void nvmem_devices_print(void);
+
 #else
 
 static inline struct nvmem_cell *nvmem_cell_get(struct device_d *dev,
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2021-06-19  3:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19  3:45 [PATCH 00/13] nvmem: misc enhancements Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 01/13] nvmem: bsec: remove unused, left-over, struct member Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 02/13] nvmem: treat devices without nvmem_bus::write as read only Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 03/13] nvmem: add support for new read-only memory (rmem) binding Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 04/13] nvmem: add support for nvmem-cells binding Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 05/13] sandbox: use nvmem on top of stickypage for reset reason Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 06/13] power: reset: port Linux generic NVMEM reboot mode driver Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 07/13] sandbox: use nvmem-reboot-mode instead of syscon-reboot-mode Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 08/13] sandbox: dts: fix unit-address for state partition Ahmad Fatoum
2021-06-19  3:45 ` Ahmad Fatoum [this message]
2021-06-19  3:45 ` [PATCH 10/13] sandbox: hostfile: move initcall to earlier postcore level Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 11/13] of: of_net: sync of_get_mac_address with Linux for NVMEM support Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 12/13] net: consult device tree for ethernet address in NVMEM as fall-back Ahmad Fatoum
2021-06-19  3:45 ` [PATCH 13/13] sandbox: ship sample environment Ahmad Fatoum
2021-06-21  6:05 ` [PATCH 00/13] nvmem: misc enhancements Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210619034516.6737-10-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox