mbox series

[0/2] gpio: modepin: Add driver support for modepin GPIO controller

Message ID 20210615080553.2021061-1-piyush.mehta@xilinx.com
Headers show
Series gpio: modepin: Add driver support for modepin GPIO controller | expand

Message

Piyush Mehta June 15, 2021, 8:05 a.m. UTC
This patch adds support for the mode pin GPIO controller and documented
for the same. GPIO Modepin driver set and get the value and status of
the PS_MODE pin, based on device-tree pin configuration.
These 4-bits boot-mode pins are dedicated configurable as input/output.
After the stabilization of the system,these mode pins are sampled.

Piyush Mehta (2):
  dt-bindings: gpio: Add binding documentation for modepin
  gpio: modepin: Add driver support for modepin GPIO controller

 .../bindings/gpio/xlnx,zynqmp-gpio-modepin.yaml    |  41 ++++++
 drivers/gpio/Kconfig                               |  12 ++
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-zynqmp-modepin.c                 | 154 +++++++++++++++++++++
 4 files changed, 208 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/xlnx,zynqmp-gpio-modepin.yaml
 create mode 100644 drivers/gpio/gpio-zynqmp-modepin.c

Comments

Linus Walleij June 18, 2021, 9:43 a.m. UTC | #1
Hi Piyush!

thanks for your patch!

On Tue, Jun 15, 2021 at 10:06 AM Piyush Mehta <piyush.mehta@xilinx.com> wrote:

> This patch adds support for the mode pin GPIO controller. GPIO Modepin
> driver set and get the value and status of the PS_MODE pin, based on
> device-tree pin configuration. These 4-bits boot-mode pins are dedicated
> configurable as input/output. After the stabilization of the system,
> these mode pins are sampled.
>
> Signed-off-by: Piyush Mehta <piyush.mehta@xilinx.com>

OK, sounds interesting!

> +#include <linux/slab.h>

I think I saw somewhere that this is not needed anymore, check if you need it.

> +#define GET_OUTEN_PIN(pin)             (1U << (pin))

Delete this macro and just use BIT(pin) inline.
#include <linux/bits.h>

> +static int modepin_gpio_get_value(struct gpio_chip *chip, unsigned int pin)
> +{
> +       u32 out_en;
> +       u32 regval = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Drop this and out_en

> +       ret = zynqmp_pm_bootmode_read(&regval);
> +       if (ret) {
> +               pr_err("modepin: get value err %d\n", ret);
> +               return ret;
> +       }
> +
> +       return (out_en & (regval >> 8U)) ? 1 : 0;

return !!(regval & BIT(pin + 8));

should work and is easier to read IMO. We just check the right
bit immediately.

> +static void modepin_gpio_set_value(struct gpio_chip *chip, unsigned int pin,
> +                                  int state)
> +{
> +       u32 out_en;
> +       u32 bootpin_val = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Skip this helper variable.

> +       state = state != 0 ? out_en : 0;

Uh that is really hard to read and modified a parameter. Skip that too.

> +       bootpin_val = (state << (8U)) | out_en;

What you want is mask and set.

bootpin_val = BIT(pin + 8);

> +       /* Configure bootpin value */
> +       ret = zynqmp_pm_bootmode_write(bootpin_val);

This just looks weird.

Why are you not reading the value first since you are using
read/modify/write?

I *think* you want to do this:

ret = zynqmp_pm_bootmode_read(&val);
if (ret)
   /* error handling */
if (state)
    val |= BIT(pin + 8);
else
    val &= ~BIT(pin + 8);
ret = zynqmp_pm_bootmode_write(val);
if (ret)
   /* error handling */

> +/*
> + * modepin_gpio_dir_in - Set the direction of the specified GPIO pin as input
> + * @chip:      gpio_chip instance to be worked on
> + * @pin:       gpio pin number within the device
> + *
> + * Return: 0 always
> + */
> +static int modepin_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
> +{
> +       return 0;
> +}

I think you said this was configurable in the commit message.

Use the define GPIO_LINE_DIRECTION_OUT rather than 0.

> +static int modepin_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
> +                               int state)
> +{
> +       return 0;
> +}

Configurable?

> +       status = devm_gpiochip_add_data(&pdev->dev, chip, chip);
> +       if (status)
> +               dev_err_probe(&pdev->dev, status,
> +                             "Failed to add GPIO chip\n");

just return dev_err_probe(...)

Yours,
Linus Walleij
Piyush Mehta June 21, 2021, 5:09 p.m. UTC | #2
Hello Linus,

Thanks for the review comments.
We will address all the reviews in the next version.

Regards,
Piyush Mehta

-----Original Message-----
From: Linus Walleij <linus.walleij@linaro.org> 
Sent: Friday, June 18, 2021 3:14 PM
To: Piyush Mehta <piyushm@xilinx.com>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>; Rob Herring <robh+dt@kernel.org>; open list:GPIO SUBSYSTEM <linux-gpio@vger.kernel.org>; open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS <devicetree@vger.kernel.org>; linux-kernel <linux-kernel@vger.kernel.org>; Linux ARM <linux-arm-kernel@lists.infradead.org>; git <git@xilinx.com>; Srinivas Goud <sgoud@xilinx.com>; Michal Simek <michals@xilinx.com>
Subject: Re: [PATCH 2/2] gpio: modepin: Add driver support for modepin GPIO controller

Hi Piyush!

thanks for your patch!

On Tue, Jun 15, 2021 at 10:06 AM Piyush Mehta <piyush.mehta@xilinx.com> wrote:

> This patch adds support for the mode pin GPIO controller. GPIO Modepin 
> driver set and get the value and status of the PS_MODE pin, based on 
> device-tree pin configuration. These 4-bits boot-mode pins are 
> dedicated configurable as input/output. After the stabilization of the 
> system, these mode pins are sampled.
>
> Signed-off-by: Piyush Mehta <piyush.mehta@xilinx.com>

OK, sounds interesting!

> +#include <linux/slab.h>

I think I saw somewhere that this is not needed anymore, check if you need it.

> +#define GET_OUTEN_PIN(pin)             (1U << (pin))

Delete this macro and just use BIT(pin) inline.
#include <linux/bits.h>

> +static int modepin_gpio_get_value(struct gpio_chip *chip, unsigned 
> +int pin) {
> +       u32 out_en;
> +       u32 regval = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Drop this and out_en

> +       ret = zynqmp_pm_bootmode_read(&regval);
> +       if (ret) {
> +               pr_err("modepin: get value err %d\n", ret);
> +               return ret;
> +       }
> +
> +       return (out_en & (regval >> 8U)) ? 1 : 0;

return !!(regval & BIT(pin + 8));

should work and is easier to read IMO. We just check the right bit immediately.

> +static void modepin_gpio_set_value(struct gpio_chip *chip, unsigned int pin,
> +                                  int state) {
> +       u32 out_en;
> +       u32 bootpin_val = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Skip this helper variable.

> +       state = state != 0 ? out_en : 0;

Uh that is really hard to read and modified a parameter. Skip that too.

> +       bootpin_val = (state << (8U)) | out_en;

What you want is mask and set.

bootpin_val = BIT(pin + 8);

> +       /* Configure bootpin value */
> +       ret = zynqmp_pm_bootmode_write(bootpin_val);

This just looks weird.

Why are you not reading the value first since you are using read/modify/write?

I *think* you want to do this:

ret = zynqmp_pm_bootmode_read(&val);
if (ret)
   /* error handling */
if (state)
    val |= BIT(pin + 8);
else
    val &= ~BIT(pin + 8);
ret = zynqmp_pm_bootmode_write(val);
if (ret)
   /* error handling */

> +/*
> + * modepin_gpio_dir_in - Set the direction of the specified GPIO pin as input
> + * @chip:      gpio_chip instance to be worked on
> + * @pin:       gpio pin number within the device
> + *
> + * Return: 0 always
> + */
> +static int modepin_gpio_dir_in(struct gpio_chip *chip, unsigned int 
> +pin) {
> +       return 0;
> +}

I think you said this was configurable in the commit message.

Use the define GPIO_LINE_DIRECTION_OUT rather than 0.

> +static int modepin_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
> +                               int state) {
> +       return 0;
> +}

Configurable?

> +       status = devm_gpiochip_add_data(&pdev->dev, chip, chip);
> +       if (status)
> +               dev_err_probe(&pdev->dev, status,
> +                             "Failed to add GPIO chip\n");

just return dev_err_probe(...)

Yours,
Linus Walleij