Re: [PATCH 2/2] gpio: modepin: Add driver support for modepin GPIO controller
From: Linus Walleij
Date: Fri Jun 18 2021 - 05:44:20 EST
Hi Piyush!
thanks for your patch!
On Tue, Jun 15, 2021 at 10:06 AM Piyush Mehta <piyush.mehta@xxxxxxxxxx> 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@xxxxxxxxxx>
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(®val);
> + 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