linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Han, Nandor (GE Healthcare)" <nandor.han@ge.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Malinen, Semi (GE Healthcare)" <semi.malinen@ge.com>
Subject: [PATCH 1/3] gpio - Add EXAR XRA1403 SPI GPIO expander driver
Date: Wed, 5 Apr 2017 13:24:49 +0000	[thread overview]
Message-ID: <HE1P101MB01883B516828F26921267A4FE60A0@HE1P101MB0188.NAMP101.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CACRpkdZB_cxqw0=M4YOhcwdZe7BxJtVKA290yGH-jxPU2MDgBg@mail.gmail.com>



> -----Original Message-----
> From: Linus Walleij [mailto:linus.walleij@linaro.org]
> Sent: 29 March 2017 05:07
> To: Han, Nandor (GE Healthcare) <nandor.han@ge.com>
> Cc: Alexandre Courbot <gnurou@gmail.com>; Rob Herring <robh+dt@kernel.org>; Mark Rutland
> <mark.rutland@arm.com>; linux-gpio@vger.kernel.org; devicetree@vger.kernel.org; linux-kernel@vger.kernel.org;
> Malinen, Semi (GE Healthcare) <semi.malinen@ge.com>
> Subject: EXT: Re: [PATCH 1/3] gpio - Add EXAR XRA1403 SPI GPIO expander driver
> 
> On Mon, Mar 27, 2017 at 8:23 AM, Nandor Han <nandor.han@ge.com> wrote:
> 
> > This is a simple driver that provides a /sys/class/gpio
> > interface for controlling and configuring the GPIO lines.
> 
> Use the gpio tools in tools/gpio, use the characcter device.
> Do not use sysfs. Change this to reference the tools.
> 
> > It does not provide support for chip select or interrupts.
> >
> > Signed-off-by: Nandor Han <nandor.han@ge.com>
> > Signed-off-by: Semi Malinen <semi.malinen@ge.com>
> (...)
> > +exar   Exar Corporation
> 
> Send this as a separate patch to the DT bindings maintainer
> (Rob Herring.)
> 

OK. I will create a separate patch with this one. 
I guess is not an issue to send all the patches to Rob as well.

<snip>

> > +
> > +       ret = xra1403_get_byte(xra, addr + (bit > 7));
> > +       if (ret < 0)
> > +               return ret;
> > +
> > +       return !!(ret & BIT(bit % 8));
> > +}
> 
> This looks like it can use regmap-spi right off, do you agree?
> 

Yes. Using regmap-spi will definitely improve the code readability and reduce boilerplate.
Done.

> git grep devm_regmap_init_spi
> should give you some examples of how to use it.
> 
> If it's not off-the shelf regmap drivers like
> drivers/iio/pressure/mpl115_spi.c
> give examples of how to make more elaborate custom
> SPI transfers with regmap.
> 

Thanks, I did check other drivers as examples. 
Not that I needed for this driver, but ...mpl115_spi.c doesn't seem to
use regmap (checked on next-20170327)

<snip>

> > +
> > +       if (value != ret) {
> > +               tx[0] = addr << 1;
> > +               tx[1] = value;
> > +               ret = spi_write(xra->spi, tx, sizeof(tx));
> > +       } else {
> > +               ret = 0;
> > +       }
> > +
> > +out_unlock:
> > +       mutex_unlock(&xra->lock);
> > +
> > +       return ret;
> > +}
> 
> Classical mask-and-set implementation right?
> With regmap this becomes simply regmap_update_bits(map, addr, mask, set)
> 

True. :)

<snip>

> > +       /* bring the chip out of reset */
> > +       reset_gpio = gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
> > +       if (IS_ERR(reset_gpio))
> > +               dev_warn(&spi->dev, "could not get reset-gpios\n");
> > +       else if (reset_gpio)
> > +               gpiod_put(reset_gpio);
> 
> I don't think you should put it, other than in the remove()
> function and in that case you need to have it in the
> state container.

Can you please be more explicit here.

Currently I'm trying to bring the device out from reset in case reset GPIO is provided.
I don't see how this could be done in remove()  :)

> 
> > +       mutex_init(&xra->lock);
> > +
> > +       xra->chip.direction_input = xra1403_direction_input;
> > +       xra->chip.direction_output = xra1403_direction_output;
> 
> Please implement .get_direction(). This is very nice to have.
> 

Done

> > +static int xra1403_remove(struct spi_device *spi)
> > +{
> > +       struct xra1403 *xra = spi_get_drvdata(spi);
> > +
> > +       gpiochip_remove(&xra->chip);
> 
> Use devm_gpiochip_add_data() and this remove is not
> needed at all.
> 

True. Done

<snip>

> > +subsys_initcall(xra1403_init);
> > +
> > +static void __exit xra1403_exit(void)
> > +{
> > +       spi_unregister_driver(&xra1403_driver);
> > +}
> > +module_exit(xra1403_exit);
> 
> This seems like tricksy. Just module_spi_driver()
> should be fine don't you think?

Yeah. TBH I don't have a strong reason why module_spi_driver init level shouldn't be enough. 
Done.

Regards,
    Nandor

  reply	other threads:[~2017-04-05 13:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27  6:22 [PATCH 0/3] XRA1403,gpio - add XRA1403 gpio expander driver Nandor Han
2017-03-27  6:23 ` [PATCH 1/3] gpio - Add EXAR XRA1403 SPI GPIO " Nandor Han
2017-03-29  2:07   ` Linus Walleij
2017-04-05 13:24     ` Han, Nandor (GE Healthcare) [this message]
2017-04-07 10:07       ` Linus Walleij
2017-04-08  7:38         ` Han, Nandor (GE Healthcare)
2017-03-31 12:38   ` Rob Herring
2017-03-27  6:23 ` [PATCH 2/3] doc,dts - add XRA1403 DTS binding documentation Nandor Han
2017-03-29  2:09   ` Linus Walleij
2017-03-31 18:49   ` Rob Herring
2017-03-27  6:23 ` [PATCH 3/3] Add XRA1403 support to MAINTAINERS file Nandor Han
2017-03-29  1:50 ` [PATCH 0/3] XRA1403,gpio - add XRA1403 gpio expander driver Linus Walleij
2017-04-05 12:46   ` Han, Nandor (GE Healthcare)

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=HE1P101MB01883B516828F26921267A4FE60A0@HE1P101MB0188.NAMP101.PROD.OUTLOOK.COM \
    --to=nandor.han@ge.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=semi.malinen@ge.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).