linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Andy Shevchenko
	<andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Jan Kiszka <jan.kiszka-S0/GAf8tV78@public.gmane.org>,
	Daniel Mack <daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>,
	Haojian Zhuang
	<haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Robert Jarzmik <robert.jarzmik-GANU6spQydw@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	linux-spi <linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Linux Kernel Mailing List
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-arm-kernel
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [PATCH] spi: pxa2xx: Only claim CS GPIOs when the slave device is created
Date: Mon, 24 Jul 2017 16:14:11 +0300	[thread overview]
Message-ID: <20170724131411.GZ629@lahna.fi.intel.com> (raw)
In-Reply-To: <CAHp75VfL8RK57sxKH4UVQ0-u9gGnJ-DaqOKYcq7DrdsFhpecwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Mon, Jul 24, 2017 at 04:03:31PM +0300, Andy Shevchenko wrote:
> +Cc: Mika (for real this time)
> 
> On Sat, Jul 8, 2017 at 11:41 AM, Jan Kiszka <jan.kiszka-S0/GAf8tV78@public.gmane.org> wrote:
> > From: Jan Kiszka <jan.kiszka-kv7WeFo6aLtBDgjK7y7TUQ@public.gmane.org>
> >
> > Avoid hogging chip select GPIOs just because they are listed for the
> > master. They might be mulitplexed and, if no slave device is attached,
> > used for different purposes. Moreover, this strategy avoids having to
> > allocate a cs_gpiods structure.
> >
> > Tested on the IOT2000 where the second SPI bus is connected to an
> > Arduino-compatible connector and multiplexed between SPI, GPIO and PWM
> > usage.
> >
> > Signed-off-by: Jan Kiszka <jan.kiszka-kv7WeFo6aLtBDgjK7y7TUQ@public.gmane.org>
> > ---
> >  drivers/spi/spi-pxa2xx.c | 59 +++++++++++++++++-------------------------------
> >  1 file changed, 21 insertions(+), 38 deletions(-)
> >
> > diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> > index 38d053682892..be991266a6ce 100644
> > --- a/drivers/spi/spi-pxa2xx.c
> > +++ b/drivers/spi/spi-pxa2xx.c
> > @@ -1213,21 +1213,33 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
> >                     struct pxa2xx_spi_chip *chip_info)
> >  {
> >         struct driver_data *drv_data = spi_master_get_devdata(spi->master);
> > +       struct device *pdev = &drv_data->pdev->dev;
> > +       struct gpio_desc *gpiod;
> >         int err = 0;
> > +       int count;
> >
> >         if (chip == NULL)
> >                 return 0;
> >
> > -       if (drv_data->cs_gpiods) {
> > -               struct gpio_desc *gpiod;
> > +       count = gpiod_count(pdev, "cs");
> > +       if (count > 0) {
> > +               if (spi->chip_select >= count)
> > +                       return -EINVAL;
> > +
> > +               gpiod = gpiod_get_index(pdev, "cs", spi->chip_select,
> > +                                       GPIOD_OUT_HIGH);

This will not work if setup() gets called multiple times (and it will in
some cases) because we already have the GPIO descriptor from the
previous call to setup().

At least you should check if we already have the GPIO requested.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-07-24 13:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-08  8:41 [PATCH] spi: pxa2xx: Only claim CS GPIOs when the slave device is created Jan Kiszka
     [not found] ` <90b3e14d-0077-9a25-9d90-ab340577af57-S0/GAf8tV78@public.gmane.org>
2017-07-08 21:48   ` Andy Shevchenko
2017-07-09  9:30     ` Jan Kiszka
     [not found]       ` <1677d448-4cdd-363f-34a6-152c61a06c0e-S0/GAf8tV78@public.gmane.org>
2017-07-09  9:55         ` Andy Shevchenko
     [not found]           ` <CAHp75VeSeHuXGmQeGr2Kq3+TOD8uHoKjd0EYLRkJVogOxcLJ2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-09 10:30             ` Jan Kiszka
     [not found]     ` <CAHp75Vd8GRCwGp8eDFOL=dsgxCR+VqqUy+O50PEW=p99a8xAwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-10 12:09       ` Mark Brown
2017-07-10 17:31         ` Jan Kiszka
2017-07-17 16:07   ` Applied "spi: pxa2xx: Only claim CS GPIOs when the slave device is created" to the spi tree Mark Brown
2017-07-24 10:44   ` [PATCH] spi: pxa2xx: Only claim CS GPIOs when the slave device is created Andy Shevchenko
     [not found]     ` <CAHp75VfpJzOdhMyZoMGnC4CQc5kGxq1k-__dpmVAOaxaD04w6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-24 10:53       ` Jan Kiszka
     [not found]         ` <59066818-a284-4da0-d05f-d2503aeee44b-S0/GAf8tV78@public.gmane.org>
2017-07-24 11:02           ` Andy Shevchenko
     [not found]             ` <CAHp75Vf0NuOAvsJDxeB=5uqhMFpQ54vZzegJe=EYZDd3Bd6erw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-24 11:06               ` Jan Kiszka
     [not found]                 ` <db94e41e-5772-ec74-8587-3192dc866040-S0/GAf8tV78@public.gmane.org>
2017-07-24 11:14                   ` Andy Shevchenko
2017-07-24 13:03   ` Andy Shevchenko
     [not found]     ` <CAHp75VfL8RK57sxKH4UVQ0-u9gGnJ-DaqOKYcq7DrdsFhpecwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-07-24 13:14       ` Mika Westerberg [this message]
2017-07-22 22:07 ` Andy Shevchenko

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=20170724131411.GZ629@lahna.fi.intel.com \
    --to=mika.westerberg-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org \
    --cc=haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jan.kiszka-S0/GAf8tV78@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robert.jarzmik-GANU6spQydw@public.gmane.org \
    /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).