[PATCH] commands: pwm: add option to list registered PWMs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's useful to be able to list all registered PWMs, especially
considering these might be aliased. So add such an option to the pwm
command.

Signed-off-by: Bastian Krause <bst@xxxxxxxxxxxxxx>
---
 commands/pwm.c     | 8 ++++++--
 drivers/pwm/core.c | 9 +++++++++
 include/pwm.h      | 2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/commands/pwm.c b/commands/pwm.c
index 68d7988886e..5d41fa8ff42 100644
--- a/commands/pwm.c
+++ b/commands/pwm.c
@@ -34,8 +34,11 @@ static int do_pwm_cmd(int argc, char *argv[])
 	bool verbose = false;
 	int opt;
 
-	while ((opt = getopt(argc, argv, "d:D:P:f:w:F:isv")) > 0) {
+	while ((opt = getopt(argc, argv, "ld:D:P:f:w:F:isv")) > 0) {
 		switch (opt) {
+		case 'l':
+			pwm_print();
+			return 0;
 		case 'd':
 			devname = optarg;
 			break;
@@ -189,6 +192,7 @@ BAREBOX_CMD_HELP_TEXT("  (although note this will not by itself stop the pwm run
 BAREBOX_CMD_HELP_TEXT(" Stopping the pwm device does not necessarily set the output to inactive,")
 BAREBOX_CMD_HELP_TEXT("  but stop is handled last, so can be done in addition to other changes.")
 BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-l\t", "list registered PWMs")
 BAREBOX_CMD_HELP_OPT("-d <name>", "device name (eg 'pwm0')")
 BAREBOX_CMD_HELP_OPT("-D <duty_ns>", "duty cycle (ns)")
 BAREBOX_CMD_HELP_OPT("-P <period_ns>", "period (ns)")
@@ -202,7 +206,7 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(pwm)
 	.cmd		= do_pwm_cmd,
 	BAREBOX_CMD_DESC("pwm")
-	BAREBOX_CMD_OPTS("[-dDPfwisv]")
+	BAREBOX_CMD_OPTS("[-ldDPfwisv]")
 	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
 	BAREBOX_CMD_HELP(cmd_pwm_help)
 BAREBOX_CMD_END
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 2237dad4537..a3f27708e6e 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -44,6 +44,15 @@ struct pwm_device {
 
 static LIST_HEAD(pwm_list);
 
+void pwm_print(void)
+{
+	struct pwm_device *pwm;
+
+	list_for_each_entry(pwm, &pwm_list, node)
+		printf("%s\n", pwm->chip->devname);
+}
+EXPORT_SYMBOL(pwm_print);
+
 static struct pwm_device *_find_pwm(const char *devname)
 {
 	struct pwm_device *pwm;
diff --git a/include/pwm.h b/include/pwm.h
index 02af7d0a5f3..4d403fe1746 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -24,6 +24,8 @@ struct pwm_state {
 	unsigned int p_enable;
 };
 
+void pwm_print(void);
+
 /*
  * pwm_request - request a PWM device
  */
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux