linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: "Alvin Šipraga" <alvin@pqrs.dk>
Cc: "Mark Brown" <broonie@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Andi Shyti" <andi.shyti@kernel.org>,
	"Saravana Kannan" <saravanak@google.com>,
	"Emil Svendsen" <emas@bang-olufsen.dk>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-sound@vger.kernel.org,
	linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org,
	"Alvin Šipraga" <alsi@bang-olufsen.dk>
Subject: Re: [PATCH 06/13] gpio: add AD24xx GPIO driver
Date: Tue, 28 May 2024 14:13:02 +0200	[thread overview]
Message-ID: <CACRpkdYKTD=97AfBN69X3BUf+4HjVrFwp-Ht2kf3HA62ud99QA@mail.gmail.com> (raw)
In-Reply-To: <20240517-a2b-v1-6-b8647554c67b@bang-olufsen.dk>

Hi Alvin,

thanks for your patch!

On Fri, May 17, 2024 at 2:58 PM Alvin Šipraga <alvin@pqrs.dk> wrote:

> From: Alvin Šipraga <alsi@bang-olufsen.dk>
>
> This driver adds GPIO function support for AD24xx A2B transceiver chips.
> When a GPIO is requested, the relevant pin is automatically muxed to
> GPIO mode. The device tree property gpio-reserved-ranges can be used to
> protect certain pins which are reserved for other functionality such as
> I2S/TDM data.
>
> Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk>
(...)

>  config A2B_AD24XX_NODE
>         tristate "Analog Devices Inc. AD24xx node support"
>         select REGMAP_A2B
> +       imply GPIO_AD24XX

Maybe it should even be select, if it's hard to think about a case
where this is not desired?

> +config GPIO_AD24XX
> +       tristate "Analog Devies Inc. AD24xx GPIO support"
> +       depends on A2B_AD24XX_NODE
> +       help
> +         Say Y here to enable GPIO support for AD24xx A2B transceivers.
> +
>  config GPIO_ARIZONA
>         tristate "Wolfson Microelectronics Arizona class devices"
>         depends on MFD_ARIZONA

This is grouped with the MFD devices but as I understand it A2B is a
completely new bus type? Is MFD even always selected when A2B is
in use?

To me it's fine to add a new submenu for A2B devices, if there will be
more of them.

> +static int ad24xx_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
> +{
> +       struct ad24xx_gpio *adg = gpiochip_get_data(gc);
> +       unsigned int val;
> +       int ret;
> +
> +       ret = regmap_read(adg->regmap, A2B_GPIOOEN, &val);
> +       if (ret)
> +               return ret;
> +
> +       if (val & BIT(offset))
> +               return 0; /* output */
> +
> +       return 1; /* input */

Please use GPIO_LINE_DIRECTION_OUT/GPIO_LINE_DIRECTION_IN
instead of 0/1 here?

Then you don't need the comments because it's evident.

> +static int ad24xx_gpio_get(struct gpio_chip *gc, unsigned int offset)
> +{
> +       struct ad24xx_gpio *adg = gpiochip_get_data(gc);
> +       unsigned int val;
> +       int ret;
> +
> +       ret = regmap_read(adg->regmap, A2B_GPIOIN, &val);
> +       if (ret)
> +               return ret;
> +
> +       if (val & BIT(offset))
> +               return 1; /* high */
> +
> +       return 0; /* low */

Just

return !!(val & BIT(offset));

> +static int ad24xx_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
> +                                            unsigned int child,
> +                                            unsigned int child_type,
> +                                            unsigned int *parent,
> +                                            unsigned int *parent_type)
> +{
> +       *parent = child;
> +       return 0;
> +}

This deserves a comment, is IRQ 0 the singular parent of
everything? Then it doesn't seem very hierarchical but rather
cascaded don't you think?

> +static int ad24xx_gpio_irq_set_type(struct irq_data *d, unsigned int type)
> +{
> +       struct gpio_chip *gpio_chip = irq_data_get_irq_chip_data(d);
> +       struct ad24xx_gpio *adg = gpiochip_get_data(gpio_chip);
> +       irq_hw_number_t hwirq = irqd_to_hwirq(d);
> +
> +       switch (type) {
> +       case IRQ_TYPE_EDGE_RISING:
> +               adg->irq_invert &= ~BIT(hwirq);
> +               break;
> +       case IRQ_TYPE_EDGE_FALLING:
> +               adg->irq_invert |= BIT(hwirq);
> +               break;
> +       default:
> +               return -EINVAL;
> +       }

No need for the "toggling trick" for supporting IRQ on both edges?
Implementing that hack (which is in several drivers) will be nice to
have for e.g. pushbuttons.

> +static void ad24xx_gpio_irq_bus_lock(struct irq_data *d)
> +{
> +       struct gpio_chip *gpio_chip = irq_data_get_irq_chip_data(d);
> +       struct ad24xx_gpio *adg = gpiochip_get_data(gpio_chip);
> +
> +       mutex_lock(&adg->mutex);
> +}

Is this mutex needed since there is already a mutex or spinlock
in the regmap? Isn't this the case for A2B?

Yours,
Linus Walleij

  parent reply	other threads:[~2024-05-28 12:13 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17 12:57 [PATCH 00/13] Analog Devices Inc. Automotive Audio Bus (A2B) support Alvin Šipraga
2024-05-17 12:57 ` [PATCH 01/13] a2b: add A2B driver core Alvin Šipraga
2024-05-18 12:46   ` kernel test robot
2024-05-19  7:15   ` Markus Elfring
2024-05-19  7:33   ` Markus Elfring
2024-05-19  8:38   ` Markus Elfring
2024-05-21  7:11     ` Alvin Šipraga
2024-05-21  7:33       ` Markus Elfring
2024-05-21  7:37         ` Greg Kroah-Hartman
2024-05-19 11:18   ` Markus Elfring
2024-05-17 12:58 ` [PATCH 02/13] regmap: add A2B support Alvin Šipraga
2024-05-17 14:42   ` Mark Brown
2024-05-21  6:27     ` Alvin Šipraga
2024-05-21 10:43       ` Mark Brown
2024-05-17 12:58 ` [PATCH 03/13] dt-bindings: a2b: Analog Devices AD24xx devices Alvin Šipraga
2024-05-19 11:40   ` Krzysztof Kozlowski
2024-05-19 11:44     ` Krzysztof Kozlowski
2024-05-21  7:24     ` Alvin Šipraga
2024-05-21  7:47       ` Krzysztof Kozlowski
2024-05-17 12:58 ` [PATCH 04/13] a2b: add AD24xx I2C interface driver Alvin Šipraga
2024-05-17 14:49   ` Wolfram Sang
2024-05-21  8:31     ` Alvin Šipraga
2024-05-18 12:56   ` kernel test robot
2024-05-18 15:02   ` kernel test robot
2024-05-17 12:58 ` [PATCH 05/13] a2b: add AD24xx node driver Alvin Šipraga
2024-05-17 12:58 ` [PATCH 06/13] gpio: add AD24xx GPIO driver Alvin Šipraga
2024-05-22 15:31   ` Bartosz Golaszewski
2024-05-28 12:13   ` Linus Walleij [this message]
2024-05-28 20:02   ` Andy Shevchenko
2024-05-17 12:58 ` [PATCH 07/13] ASoC: codecs: add AD24xx codec driver Alvin Šipraga
2024-05-17 15:03   ` Mark Brown
2024-05-21  6:46     ` Alvin Šipraga
2024-05-21  7:08       ` Alvin Šipraga
2024-05-21 10:49       ` Mark Brown
2024-05-17 13:02 ` [PATCH 08/13] clk: add AD24xx clock driver Alvin Šipraga
2024-06-04  0:10   ` Stephen Boyd
2024-05-17 13:02 ` [PATCH 09/13] i2c: add AD24xx I2C controller driver Alvin Šipraga
2024-05-17 13:02 ` [PATCH 10/13] dt-bindings: vendor-prefixes: add Bang & Olufsen a/s Alvin Šipraga
2024-05-19 11:40   ` Krzysztof Kozlowski
2024-05-17 13:02 ` [PATCH 11/13] dt-bindings: a2b: add compatible string for Beosound Shape node Alvin Šipraga
2024-05-19 11:41   ` Krzysztof Kozlowski
2024-05-21  7:12     ` Alvin Šipraga
2024-05-21  7:32       ` Krzysztof Kozlowski
2024-05-17 13:02 ` [PATCH 12/13] a2b: add Beosound Shape node driver Alvin Šipraga
2024-05-17 13:02 ` [PATCH 13/13] MAINTAINERS: add maintainership for A2B drivers Alvin Šipraga
2024-05-17 14:57 ` [PATCH 00/13] Analog Devices Inc. Automotive Audio Bus (A2B) support Wolfram Sang
2024-05-21  7:08   ` Alvin Šipraga
2024-05-19  6:44 ` Markus Elfring

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='CACRpkdYKTD=97AfBN69X3BUf+4HjVrFwp-Ht2kf3HA62ud99QA@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=alsi@bang-olufsen.dk \
    --cc=alvin@pqrs.dk \
    --cc=andi.shyti@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=emas@bang-olufsen.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=perex@perex.cz \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=sboyd@kernel.org \
    --cc=tiwai@suse.com \
    /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;
as well as URLs for NNTP newsgroup(s).