mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: pwm: add option to list registered PWMs
@ 2023-09-06 13:26 Bastian Krause
  2023-09-06 14:13 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Bastian Krause @ 2023-09-06 13:26 UTC (permalink / raw)
  To: barebox; +Cc: afa, Bastian Krause

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] commands: pwm: add option to list registered PWMs
  2023-09-06 13:26 [PATCH] commands: pwm: add option to list registered PWMs Bastian Krause
@ 2023-09-06 14:13 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-09-06 14:13 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox, afa

On Wed, Sep 06, 2023 at 03:26:23PM +0200, Bastian Krause wrote:
> 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(-)

Applied, thanks

Sascha

> 
> 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
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-06 14:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 13:26 [PATCH] commands: pwm: add option to list registered PWMs Bastian Krause
2023-09-06 14:13 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox