mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Mary Strodl <mstrodl@csh.rit.edu>
Cc: linux-kernel@vger.kernel.org, tzungbi@kernel.org,
	linus.walleij@linaro.org, brgl@bgdev.pl,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH v3 3/4] gpio: mpsse: add quirk support
Date: Thu, 2 Oct 2025 23:34:13 +0300	[thread overview]
Message-ID: <aN7hxUz7TGG38Hv_@stanley.mountain> (raw)
In-Reply-To: <20251002181136.3546798-4-mstrodl@csh.rit.edu>

On Thu, Oct 02, 2025 at 02:11:35PM -0400, Mary Strodl wrote:
> Builds out a facility for specifying compatible lines directions and
> labels for MPSSE-based devices.
> 
> * dir_in/out are bitmask of lines that can go in/out. 0 means
>   compatible, 1 means incompatible. This is convenient, because it means
>   if the struct is zeroed out, it supports all pins.

What?  No, please make 1 be supported and 0 be not supported.  This
really weirded me out when I read the code.  If it were just 1 for
true and 0 for false a lot of comments regarding dir_in/out could be
removed because the code would be straight forward.

You can easily set everything to 1 by assigning -1 or using memset().

> * names is an array of line names which will be exposed to userspace.
> 
> Also changes the chip label format to include some more useful
> information about the device to help identify it from userspace.
> 
> Signed-off-by: Mary Strodl <mstrodl@csh.rit.edu>
> ---
>  drivers/gpio/gpio-mpsse.c | 109 ++++++++++++++++++++++++++++++++++++--
>  1 file changed, 106 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c
> index 6ec940f6b371..c2a344488a23 100644
> --- a/drivers/gpio/gpio-mpsse.c
> +++ b/drivers/gpio/gpio-mpsse.c
> @@ -29,6 +29,9 @@ struct mpsse_priv {
>  	u8 gpio_outputs[2];	     /* Output states for GPIOs [L, H] */
>  	u8 gpio_dir[2];		     /* Directions for GPIOs [L, H] */
>  
> +	unsigned long dir_in;        /* Bitmask of valid input pins  */
> +	unsigned long dir_out;       /* Bitmask of valid output pins */
> +
>  	u8 *bulk_in_buf;	     /* Extra recv buffer to grab status bytes */
>  
>  	struct usb_endpoint_descriptor *bulk_in;
> @@ -54,6 +57,14 @@ struct bulk_desc {
>  	int timeout;
>  };
>  
> +#define MPSSE_NGPIO 16
> +
> +struct mpsse_quirk {
> +	const char   *names[MPSSE_NGPIO]; /* Pin names, if applicable     */
> +	unsigned long dir_in;             /* Bitmask of valid input pins  */
> +	unsigned long dir_out;            /* Bitmask of valid output pins */
> +};
> +
>  static const struct usb_device_id gpio_mpsse_table[] = {
>  	{ USB_DEVICE(0x0c52, 0xa064) },   /* SeaLevel Systems, Inc. */
>  	{ }                               /* Terminating entry */
> @@ -171,6 +182,32 @@ static int gpio_mpsse_get_bank(struct mpsse_priv *priv, u8 bank)
>  	return buf;
>  }
>  
> +static int mpsse_ensure_supported(struct gpio_chip *chip,
> +				  unsigned long *mask, int direction)

Just pass mask not a pointer to mask.  It would be different if
you were going to allow more than 32 bits to be set, then we would
need to pass a pointer and use set_bit() etc...

> +{
> +	unsigned long supported, unsupported;
> +	char *type = "input";
> +	struct mpsse_priv *priv = gpiochip_get_data(chip);
> +
> +	supported = priv->dir_in;
> +	if (direction == GPIO_LINE_DIRECTION_OUT) {
> +		supported = priv->dir_out;
> +		type = "output";
> +	}
> +
> +	/* An invalid bit was in the provided mask */
> +	unsupported = *mask & supported;
> +	if (unsupported) {
> +		dev_err(&priv->udev->dev,
> +			"mpsse: GPIO %d doesn't support %s\n",
> +			(int)find_first_bit(&unsupported, sizeof(unsupported) * 8),

Use %lu instead of %d and get rid of the unnecessary cast.

> +			type);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	return 0;
> +}

regards,
dan carpenter


  reply	other threads:[~2025-10-02 20:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02 18:11 [PATCH v3 0/4] gpio: mpsse: add support for bryx brik Mary Strodl
2025-10-02 18:11 ` [PATCH v3 1/4] gpio: mpsse: propagate error from direction_input Mary Strodl
2025-10-02 18:11 ` [PATCH v3 2/4] gpio: mpsse: ensure worker is torn down Mary Strodl
2025-10-02 18:11 ` [PATCH v3 3/4] gpio: mpsse: add quirk support Mary Strodl
2025-10-02 20:34   ` Dan Carpenter [this message]
2025-10-03 14:52     ` Mary Strodl
2025-10-02 18:11 ` [PATCH v3 4/4] gpio: mpsse: support bryx radio interface kit Mary Strodl

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=aN7hxUz7TGG38Hv_@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mstrodl@csh.rit.edu \
    --cc=tzungbi@kernel.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

all inboxes | Powered by JetHome®