[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALL1Z1z4450depX-X5VC=r3J7fRkTCkFP5re_ULHiS6O1KQ3rA@mail.gmail.com>
Date: Mon, 17 Feb 2020 14:14:59 +0100
From: Khouloud Touil <ktouil@...libre.com>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Bartosz Golaszewski <bgolaszewski@...libre.com>,
Rob Herring <robh+dt@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
baylibre-upstreaming@...ups.io,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@...r.kernel.org>,
Linux I2C <linux-i2c@...r.kernel.org>,
Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v4 2/5] nvmem: add support for the write-protect pin
Le jeu. 30 janv. 2020 à 09:06, Geert Uytterhoeven
<geert@...ux-m68k.org> a écrit :
>
> Hi Khouloud,
>
> On Tue, Jan 7, 2020 at 10:30 AM Khouloud Touil <ktouil@...libre.com> wrote:
> > The write-protect pin handling looks like a standard property that
> > could benefit other users if available in the core nvmem framework.
> >
> > Instead of modifying all the memory drivers to check this pin, make
> > the NVMEM subsystem check if the write-protect GPIO being passed
> > through the nvmem_config or defined in the device tree and pull it
> > low whenever writing to the memory.
> >
> > There was a suggestion for introducing the gpiodesc from pdata, but
> > as pdata is already removed it could be replaced by adding it to
> > nvmem_config.
> >
> > Reference: https://lists.96boards.org/pipermail/dev/2018-August/001056.html
> >
> > Signed-off-by: Khouloud Touil <ktouil@...libre.com>
> > Reviewed-by: Linus Walleij <linus.walleij@...aro.org>
> > Acked-by: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
>
> Thanks for your patch!
>
> > --- a/drivers/nvmem/core.c
> > +++ b/drivers/nvmem/core.c
> > @@ -15,6 +15,7 @@
> > #include <linux/module.h>
> > #include <linux/nvmem-consumer.h>
> > #include <linux/nvmem-provider.h>
> > +#include <linux/gpio/consumer.h>
> > #include <linux/of.h>
> > #include <linux/slab.h>
> > #include "nvmem.h"
> > @@ -54,8 +55,14 @@ static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
> > static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
> > void *val, size_t bytes)
> > {
> > - if (nvmem->reg_write)
> > - return nvmem->reg_write(nvmem->priv, offset, val, bytes);
> > + int ret;
> > +
> > + if (nvmem->reg_write) {
> > + gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
> > + ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
> > + gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
> > + return ret;
> > + }
> >
> > return -EINVAL;
> > }
> > @@ -338,6 +345,14 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> > kfree(nvmem);
> > return ERR_PTR(rval);
> > }
> > + if (config->wp_gpio)
> > + nvmem->wp_gpio = config->wp_gpio;
> > + else
> > + nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
> > + GPIOD_OUT_HIGH);
>
> Shouldn't this GPIO be released in nvmem_release(), by calling gpiod_put()?
>
> Once that's implemented, I assume it will be auto-released on registration
> failure by the call to put_device()?
Hello Geert,
Thanks for your review.
Yes you are right, I will add that
Khouloud,
>
> > + if (IS_ERR(nvmem->wp_gpio))
> > + return PTR_ERR(nvmem->wp_gpio);
> > +
> >
> > kref_init(&nvmem->refcnt);
> > INIT_LIST_HEAD(&nvmem->cells);
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
Powered by blists - more mailing lists