All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Lars Povlsen <lars.povlsen@microchip.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
	devicetree <devicetree@vger.kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v6 2/3] pinctrl: pinctrl-microchip-sgpio: Add pinctrl driver for Microsemi Serial GPIO
Date: Fri, 16 Oct 2020 17:34:15 +0300	[thread overview]
Message-ID: <CAHp75Vdd6ECJaWytYVz+5GYZrwybzZmviUOt3H=t-4LH=_idKg@mail.gmail.com> (raw)
In-Reply-To: <20201014100707.2728637-3-lars.povlsen@microchip.com>

On Wed, Oct 14, 2020 at 6:25 PM Lars Povlsen <lars.povlsen@microchip.com> wrote:
>
> This adds a pinctrl driver for the Microsemi/Microchip Serial GPIO
> (SGPIO) device used in various SoC's.

...

> +#define PIN_NAM_SZ     (sizeof("SGPIO_D_pXXbY")+1)

+1 for what?

...

> +#define __shf(x)               (__builtin_ffsll(x) - 1)
> +#define __BF_PREP(bf, x)       (bf & ((x) << __shf(bf)))
> +#define __BF_GET(bf, x)                (((x & bf) >> __shf(bf)))

This smells like bitfield.h.

...

> +static int sgpio_input_get(struct sgpio_priv *priv,
> +                          struct sgpio_port_addr *addr)
> +{

> +       int ret;
> +
> +       ret = !!(sgpio_readl(priv, REG_INPUT_DATA, addr->bit) &
> +                BIT(addr->port));
> +
> +       return ret;

Sounds like one line.

> +}

> +static int sgpio_get_functions_count(struct pinctrl_dev *pctldev)
> +{

> +       return 1;

I didn't get why it's not a pure GPIO driver?
It has only one function (no pinmux).
I didn't find any pin control features either.

What did I miss?

...

> +static int microchip_sgpio_get_value(struct gpio_chip *gc, unsigned int gpio)
> +{
> +       struct sgpio_bank *bank = gpiochip_get_data(gc);
> +       struct sgpio_priv *priv = bank->priv;
> +       struct sgpio_port_addr addr;

> +       int ret;

No need.

> +
> +       sgpio_pin_to_addr(priv, gpio, &addr);
> +
> +       if (bank->is_input)
> +               ret = sgpio_input_get(priv, &addr);
> +       else
> +               ret = sgpio_output_get(priv, &addr);
> +
> +       return ret;
> +}


...


> +       ret = devm_gpiochip_add_data(dev, gc, bank);
> +       if (ret == 0)

> +               dev_info(dev, "Registered %d GPIOs\n", ngpios);

No noise.

> +       else
> +               dev_err(dev, "Failed to register: ret %d\n", ret);
> +

...

> +       /* Get register map */
> +       regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +       priv->regs = devm_ioremap_resource(dev, regs);

devm_platform_ioremap_resource();

> +       if (IS_ERR(priv->regs))
> +               return PTR_ERR(priv->regs);

> +       priv->properties = of_device_get_match_data(dev);

It's interesting you have a mix between OF APIs and device property
APIs. Choose one. If you stick with OF, use of_property_ and so,
otherwise replace of_*() by corresponding device_*() or generic calls.

Can you use gpio-regmap APIs?

-- 
With Best Regards,
Andy Shevchenko

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Lars Povlsen <lars.povlsen@microchip.com>
Cc: devicetree <devicetree@vger.kernel.org>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v6 2/3] pinctrl: pinctrl-microchip-sgpio: Add pinctrl driver for Microsemi Serial GPIO
Date: Fri, 16 Oct 2020 17:34:15 +0300	[thread overview]
Message-ID: <CAHp75Vdd6ECJaWytYVz+5GYZrwybzZmviUOt3H=t-4LH=_idKg@mail.gmail.com> (raw)
In-Reply-To: <20201014100707.2728637-3-lars.povlsen@microchip.com>

On Wed, Oct 14, 2020 at 6:25 PM Lars Povlsen <lars.povlsen@microchip.com> wrote:
>
> This adds a pinctrl driver for the Microsemi/Microchip Serial GPIO
> (SGPIO) device used in various SoC's.

...

> +#define PIN_NAM_SZ     (sizeof("SGPIO_D_pXXbY")+1)

+1 for what?

...

> +#define __shf(x)               (__builtin_ffsll(x) - 1)
> +#define __BF_PREP(bf, x)       (bf & ((x) << __shf(bf)))
> +#define __BF_GET(bf, x)                (((x & bf) >> __shf(bf)))

This smells like bitfield.h.

...

> +static int sgpio_input_get(struct sgpio_priv *priv,
> +                          struct sgpio_port_addr *addr)
> +{

> +       int ret;
> +
> +       ret = !!(sgpio_readl(priv, REG_INPUT_DATA, addr->bit) &
> +                BIT(addr->port));
> +
> +       return ret;

Sounds like one line.

> +}

> +static int sgpio_get_functions_count(struct pinctrl_dev *pctldev)
> +{

> +       return 1;

I didn't get why it's not a pure GPIO driver?
It has only one function (no pinmux).
I didn't find any pin control features either.

What did I miss?

...

> +static int microchip_sgpio_get_value(struct gpio_chip *gc, unsigned int gpio)
> +{
> +       struct sgpio_bank *bank = gpiochip_get_data(gc);
> +       struct sgpio_priv *priv = bank->priv;
> +       struct sgpio_port_addr addr;

> +       int ret;

No need.

> +
> +       sgpio_pin_to_addr(priv, gpio, &addr);
> +
> +       if (bank->is_input)
> +               ret = sgpio_input_get(priv, &addr);
> +       else
> +               ret = sgpio_output_get(priv, &addr);
> +
> +       return ret;
> +}


...


> +       ret = devm_gpiochip_add_data(dev, gc, bank);
> +       if (ret == 0)

> +               dev_info(dev, "Registered %d GPIOs\n", ngpios);

No noise.

> +       else
> +               dev_err(dev, "Failed to register: ret %d\n", ret);
> +

...

> +       /* Get register map */
> +       regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +       priv->regs = devm_ioremap_resource(dev, regs);

devm_platform_ioremap_resource();

> +       if (IS_ERR(priv->regs))
> +               return PTR_ERR(priv->regs);

> +       priv->properties = of_device_get_match_data(dev);

It's interesting you have a mix between OF APIs and device property
APIs. Choose one. If you stick with OF, use of_property_ and so,
otherwise replace of_*() by corresponding device_*() or generic calls.

Can you use gpio-regmap APIs?

-- 
With Best Regards,
Andy Shevchenko

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-10-16 14:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 10:07 [PATCH v6 0/3] Adding support for Microchip/Microsemi serial GPIO controller Lars Povlsen
2020-10-14 10:07 ` Lars Povlsen
2020-10-14 10:07 ` [PATCH v6 1/3] dt-bindings: pinctrl: Add bindings for pinctrl-microchip-sgpio driver Lars Povlsen
2020-10-14 10:07   ` Lars Povlsen
2020-10-14 10:07 ` [PATCH v6 2/3] pinctrl: pinctrl-microchip-sgpio: Add pinctrl driver for Microsemi Serial GPIO Lars Povlsen
2020-10-14 10:07   ` Lars Povlsen
2020-10-16 14:34   ` Andy Shevchenko [this message]
2020-10-16 14:34     ` Andy Shevchenko
2020-10-26 14:41     ` Lars Povlsen
2020-10-26 14:41       ` Lars Povlsen
2020-10-14 10:07 ` [PATCH v6 3/3] arm64: dts: sparx5: Add SGPIO devices Lars Povlsen
2020-10-14 10:07   ` Lars Povlsen

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='CAHp75Vdd6ECJaWytYVz+5GYZrwybzZmviUOt3H=t-4LH=_idKg@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=lars.povlsen@microchip.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.