linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sifan Naeem <sifan.naeem@imgtec.com>
To: Mark Brown <broonie@kernel.org>
Cc: <linux-spi@vger.kernel.org>, <abrestic@chromium.org>,
	Sifan Naeem <sifan.naeem@imgtec.com>,
	"Stable kernel (v4.1)" <stable@vger.kernel.org>
Subject: [PATCH 2/2] spi: img-spfi: fix spfi_setup by removing gpio_request_one
Date: Mon, 27 Jul 2015 13:11:16 +0100	[thread overview]
Message-ID: <1437999076-693-2-git-send-email-sifan.naeem@imgtec.com> (raw)
In-Reply-To: <1437999076-693-1-git-send-email-sifan.naeem@imgtec.com>

spfi_setup may be called many times bye the spi framework, but
gpio_request_one can only be called once without freeing, repeatedly
calling gpio_request_one will cause an error to be thrown, which causes
the request to spi_setup to be marked as failed.

We can simply use gpio_direction_output to set the direction of the
gpio instead of gpio_request_one to put the gpio in to initial state,
after which the spi framework can control the chipselect line via gpio
using gpio_set_value.

Fixes: 8c2c8c0 ("spi: img-spfi: Control CS lines with GPIO")
Signed-off-by: Sifan Naeem <sifan.naeem@imgtec.com>
Cc: Stable kernel (v4.1) <stable@vger.kernel.org>
---
 drivers/spi/spi-img-spfi.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c
index f27d9d5..a7f3d6a 100644
--- a/drivers/spi/spi-img-spfi.c
+++ b/drivers/spi/spi-img-spfi.c
@@ -442,13 +442,15 @@ static int img_spfi_setup(struct spi_device *spi)
 {
 	int ret;
 
-	ret = gpio_request_one(spi->cs_gpio, (spi->mode & SPI_CS_HIGH) ?
-			       GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
-			       dev_name(&spi->dev));
-	if (ret)
-		dev_err(&spi->dev, "can't request chipselect gpio %d\n",
-				spi->cs_gpio);
-
+	if (gpio_is_valid(spi->cs_gpio)) {
+		int mode = ((spi->mode & SPI_CS_HIGH) ?
+			     GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
+
+		ret = gpio_direction_output(spi->cs_gpio, mode);
+		if (ret)
+			dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
+				spi->cs_gpio, ret);
+	}
 	return ret;
 }
 
-- 
1.7.9.5

  reply	other threads:[~2015-07-27 12:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 12:11 [PATCH 1/2] spi: img-spfi: check for timeout error before proceeding Sifan Naeem
2015-07-27 12:11 ` Sifan Naeem [this message]
2015-07-27 16:34   ` [PATCH 2/2] spi: img-spfi: fix spfi_setup by removing gpio_request_one Andrew Bresticker
     [not found]     ` <CAL1qeaHLn6-2QJkPjNCm3V-pVqBk09P2BP-Sp+gn1G4ZWpvkEw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-27 16:40       ` Mark Brown
2015-07-27 16:53         ` Sifan Naeem
2015-07-29 11:05         ` Sifan Naeem
     [not found]           ` <A0E307549471DA4DBAF2DE2DE6CBFB7E4966D9FF-brIQrgj5TFtJFJhlrACyRFBRoQTxkR7k@public.gmane.org>
2015-07-29 12:26             ` Mark Brown
     [not found]               ` <20150729122600.GB20130-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-07-29 12:43                 ` Sifan Naeem
     [not found] ` <1437999076-693-1-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-27 16:30   ` [PATCH 1/2] spi: img-spfi: check for timeout error before proceeding Andrew Bresticker
2015-07-29 13:53 ` Mark Brown
2015-07-29 14:07   ` Sifan Naeem
2015-07-29 14:14 ` Applied "spi: img-spfi: check for timeout error before proceeding" to the spi tree Mark Brown

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=1437999076-693-2-git-send-email-sifan.naeem@imgtec.com \
    --to=sifan.naeem@imgtec.com \
    --cc=abrestic@chromium.org \
    --cc=broonie@kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@vger.kernel.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).