[PATCH] commands: pwm: add option to list registered PWMs
Sascha Hauer
sha at pengutronix.de
Wed Sep 6 07:13:11 PDT 2023
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 at 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 |
More information about the barebox
mailing list