Re: [PATCH v2 2/2] gpio: fxl6408: add I2C GPIO expander driver

From: Andy Shevchenko
Date: Mon Mar 13 2023 - 08:25:37 EST


On Mon, Mar 13, 2023 at 1:33 PM Francesco Dolcini <francesco@xxxxxxxxxx> wrote:
>
> From: Emanuele Ghidoli <emanuele.ghidoli@xxxxxxxxxxx>
>
> Add minimal driver for Fairchild FXL6408 8-bit I2C-controlled GPIO expander
> using the generic regmap based GPIO driver (GPIO_REGMAP).
>
> The driver implements setting the GPIO direction, reading inputs
> and writing outputs.
>
> In addition to that the FXL6408 has the following functionalities:
> - allows to monitor input ports for data transitions with an interrupt pin
> - all inputs can be configured with pull-up or pull-down resistors

Thank you for the update, my comments below.

...

+ Co-developed-by: your name + email ?

> Signed-off-by: Francesco Dolcini <francesco.dolcini@xxxxxxxxxxx>

...

> +config GPIO_FXL6408
> + tristate "FXL6408 I2C GPIO expander"
> + select GPIO_REGMAP

> + select REGMAP_I2C

Somebody pointed out that this might require

depends on I2C

being added as well.

...

> +#include <linux/gpio/regmap.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>

Missing kernel.h for ARRAY_SIZE(), but I prefer the array_size.h to
appear (nevertheless, the latter is out of scope of this one).
Missing err.h for error handling macros.

...

> +#define FXL6408_MAX_REGISTER 0x13

This is used as a range, but why? If we can have a proper name for
this register, why bother dumping all this or even having access to?

...

> +static int fxl6408_identify(struct device *dev, struct regmap *regmap)
> +{
> + int val, ret;
> +
> + ret = regmap_read(regmap, FXL6408_REG_DEVICE_ID, &val);
> + if (ret) {
> + dev_err(dev, "error %d reading DEVICE_ID\n", ret);
> + } else if (val >> FXL6408_MF_SHIFT != FXL6408_MF_FAIRCHILD) {
> + dev_err(dev, "invalid device id 0x%02x\n", val);
> + ret = -ENODEV;
> + }
> +
> + return ret;

This function is only used at ->probe(), you may refactor it like

ret = regmap_read(regmap, FXL6408_REG_DEVICE_ID, &val);
if (ret)
return dev_err_probe(dev, ret, "error reading DEVICE_ID\n");
if (val >> FXL6408_MF_SHIFT != FXL6408_MF_FAIRCHILD)
return dev_err_probe(dev, -ENODEV, "invalid device id
0x%02x\n", val);

return 0;

> +}

--
With Best Regards,
Andy Shevchenko