From: Bastian Krause <bst@pengutronix.de>
To: barebox@lists.infradead.org
Cc: afa@pengutronix.de, Bastian Krause <bst@pengutronix.de>
Subject: [PATCH] commands: pwm: add option to list registered PWMs
Date: Wed, 6 Sep 2023 15:26:23 +0200 [thread overview]
Message-ID: <20230906132623.1608529-1-bst@pengutronix.de> (raw)
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@pengutronix.de>
---
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
next reply other threads:[~2023-09-06 13:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 13:26 Bastian Krause [this message]
2023-09-06 14:13 ` 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=20230906132623.1608529-1-bst@pengutronix.de \
--to=bst@pengutronix.de \
--cc=afa@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