Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1702978 > unrolled thread

[PATCH RFC 0/2] spi: pxa2xx: gpiod cleanups and late CS GPIO allocation

Started byJan Kiszka <jan.kiszka@siemens.com>
First post2017-08-03 13:50 +0200
Last post2017-08-04 13:50 +0200
Articles 10 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH RFC 0/2] spi: pxa2xx: gpiod cleanups and late CS GPIO allocation Jan Kiszka <jan.kiszka@siemens.com> - 2017-08-03 13:50 +0200
    [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible Jan Kiszka <jan.kiszka@siemens.com> - 2017-08-03 13:50 +0200
      Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API  where possible Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-08-04 12:20 +0200
        Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where  possible Jan Kiszka <jan.kiszka@siemens.com> - 2017-08-04 12:20 +0200
          Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API  where possible Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-08-04 12:30 +0200
            Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API  where possible Mark Brown <broonie@kernel.org> - 2017-08-04 13:50 +0200
      Applied "spi: pxa2xx: Convert to GPIO descriptor API where possible" to the spi tree Mark Brown <broonie@kernel.org> - 2017-08-04 13:50 +0200
    [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created Jan Kiszka <jan.kiszka@siemens.com> - 2017-08-03 13:50 +0200
      Re: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave  device is created Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-08-04 12:30 +0200
      Re: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave  device is created Mark Brown <broonie@kernel.org> - 2017-08-04 13:50 +0200

#1702978 — [PATCH RFC 0/2] spi: pxa2xx: gpiod cleanups and late CS GPIO allocation

FromJan Kiszka <jan.kiszka@siemens.com>
Date2017-08-03 13:50 +0200
Subject[PATCH RFC 0/2] spi: pxa2xx: gpiod cleanups and late CS GPIO allocation
Message-ID<uamNA-7Pj-13@gated-at.bofh.it>
This is a follow-up to the discussion on
https://lkml.org/lkml/2017/7/8/42. It tries to convert more of pxa2xx
driver to gpio descriptors, and it does that late CS GPIO binding, but
now hopefully without violating the GPIO API and while taking multiple
calls to setup_cs into account.

Jan

Jan Kiszka (2):
  spi: pxa2xx: Convert to GPIO descriptor API where possible
  spi: pxa2xx: Only claim CS GPIOs when the slave device is created

 drivers/spi/spi-pxa2xx.c | 92 ++++++++++++++++++++++--------------------------
 drivers/spi/spi-pxa2xx.h |  5 ++-
 2 files changed, 44 insertions(+), 53 deletions(-)

-- 
2.12.3

[toc] | [next] | [standalone]


#1702982 — [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible

FromJan Kiszka <jan.kiszka@siemens.com>
Date2017-08-03 13:50 +0200
Subject[PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible
Message-ID<uamNB-7Pj-25@gated-at.bofh.it>
In reply to#1702978
From: Jan Kiszka <jan.kiszka@siemens.com>

We still need to request/free GPIOs passed via the legacy path of
pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise.

Consistently use the descriptor API instead of the legacy one.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 drivers/spi/spi-pxa2xx.c | 32 ++++++++++++++++----------------
 drivers/spi/spi-pxa2xx.h |  2 +-
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 38d053682892..7faba738110c 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -402,8 +402,8 @@ static void cs_assert(struct driver_data *drv_data)
 		return;
 	}
 
-	if (gpio_is_valid(chip->gpio_cs)) {
-		gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
+	if (chip->gpiod_cs) {
+		gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
 		return;
 	}
 
@@ -424,8 +424,8 @@ static void cs_deassert(struct driver_data *drv_data)
 		return;
 	}
 
-	if (gpio_is_valid(chip->gpio_cs)) {
-		gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
+	if (chip->gpiod_cs) {
+		gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
 		return;
 	}
 
@@ -1213,17 +1213,16 @@ 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 gpio_desc *gpiod;
 	int err = 0;
 
 	if (chip == NULL)
 		return 0;
 
 	if (drv_data->cs_gpiods) {
-		struct gpio_desc *gpiod;
-
 		gpiod = drv_data->cs_gpiods[spi->chip_select];
 		if (gpiod) {
-			chip->gpio_cs = desc_to_gpio(gpiod);
+			chip->gpiod_cs = gpiod;
 			chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
 			gpiod_set_value(gpiod, chip->gpio_cs_inverted);
 		}
@@ -1237,8 +1236,10 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
 	/* NOTE: setup() can be called multiple times, possibly with
 	 * different chip_info, release previously requested GPIO
 	 */
-	if (gpio_is_valid(chip->gpio_cs))
-		gpio_free(chip->gpio_cs);
+	if (chip->gpiod_cs) {
+		gpio_free(desc_to_gpio(chip->gpiod_cs));
+		chip->gpiod_cs = NULL;
+	}
 
 	/* If (*cs_control) is provided, ignore GPIO chip select */
 	if (chip_info->cs_control) {
@@ -1254,11 +1255,11 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
 			return err;
 		}
 
-		chip->gpio_cs = chip_info->gpio_cs;
+		gpiod = gpio_to_desc(chip_info->gpio_cs);
+		chip->gpiod_cs = gpiod;
 		chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
 
-		err = gpio_direction_output(chip->gpio_cs,
-					!chip->gpio_cs_inverted);
+		err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
 	}
 
 	return err;
@@ -1317,8 +1318,7 @@ static int setup(struct spi_device *spi)
 			}
 
 			chip->frm = spi->chip_select;
-		} else
-			chip->gpio_cs = -1;
+		}
 		chip->enable_dma = drv_data->master_info->enable_dma;
 		chip->timeout = TIMOUT_DFLT;
 	}
@@ -1416,8 +1416,8 @@ static void cleanup(struct spi_device *spi)
 		return;
 
 	if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
-	    gpio_is_valid(chip->gpio_cs))
-		gpio_free(chip->gpio_cs);
+	    chip->gpiod_cs)
+		gpio_free(desc_to_gpio(chip->gpiod_cs));
 
 	kfree(chip);
 }
diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
index 2823a00a9405..94f7b0713281 100644
--- a/drivers/spi/spi-pxa2xx.h
+++ b/drivers/spi/spi-pxa2xx.h
@@ -83,7 +83,7 @@ struct chip_data {
 	u16 lpss_tx_threshold;
 	u8 enable_dma;
 	union {
-		int gpio_cs;
+		struct gpio_desc *gpiod_cs;
 		unsigned int frm;
 	};
 	int gpio_cs_inverted;
-- 
2.12.3

[toc] | [prev] | [next] | [standalone]


#1703850 — Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-08-04 12:20 +0200
SubjectRe: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible
Message-ID<uaHS1-5H2-5@gated-at.bofh.it>
In reply to#1702982
On Thu, Aug 03, 2017 at 01:40:32PM +0200, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> We still need to request/free GPIOs passed via the legacy path of
> pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise.
> 
> Consistently use the descriptor API instead of the legacy one.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

There are some PXA2xx platforms under arch/arm/* which use this driver
and legacy GPIOs. I wonder if this causes any problems with them?

That was one of the reasons I did not convert the whole driver over GPIO
descriptors.

[toc] | [prev] | [next] | [standalone]


#1703853 — Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible

FromJan Kiszka <jan.kiszka@siemens.com>
Date2017-08-04 12:20 +0200
SubjectRe: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible
Message-ID<uaHS1-5H2-13@gated-at.bofh.it>
In reply to#1703850
On 2017-08-04 12:10, Mika Westerberg wrote:
> On Thu, Aug 03, 2017 at 01:40:32PM +0200, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> We still need to request/free GPIOs passed via the legacy path of
>> pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise.
>>
>> Consistently use the descriptor API instead of the legacy one.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> 
> There are some PXA2xx platforms under arch/arm/* which use this driver
> and legacy GPIOs. I wonder if this causes any problems with them?
> 
> That was one of the reasons I did not convert the whole driver over GPIO
> descriptors.

It shouldn't cause problems (famous last words) because I refrained from
changing the interfaces to them. References that come in as legacy GPIO
are still treated like that.

Jan

-- 
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

[toc] | [prev] | [next] | [standalone]


#1703858 — Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-08-04 12:30 +0200
SubjectRe: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible
Message-ID<uaI1H-5Ka-5@gated-at.bofh.it>
In reply to#1703853
On Fri, Aug 04, 2017 at 12:18:28PM +0200, Jan Kiszka wrote:
> On 2017-08-04 12:10, Mika Westerberg wrote:
> > On Thu, Aug 03, 2017 at 01:40:32PM +0200, Jan Kiszka wrote:
> >> From: Jan Kiszka <jan.kiszka@siemens.com>
> >>
> >> We still need to request/free GPIOs passed via the legacy path of
> >> pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise.
> >>
> >> Consistently use the descriptor API instead of the legacy one.
> >>
> >> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> > 
> > There are some PXA2xx platforms under arch/arm/* which use this driver
> > and legacy GPIOs. I wonder if this causes any problems with them?
> > 
> > That was one of the reasons I did not convert the whole driver over GPIO
> > descriptors.
> 
> It shouldn't cause problems (famous last words) because I refrained from
> changing the interfaces to them. References that come in as legacy GPIO
> are still treated like that.

OK. I hope someone with a PXA2xx machine could still test it.

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

[toc] | [prev] | [next] | [standalone]


#1703890 — Re: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible

FromMark Brown <broonie@kernel.org>
Date2017-08-04 13:50 +0200
SubjectRe: [PATCH RFC 1/2] spi: pxa2xx: Convert to GPIO descriptor API where possible
Message-ID<uaJh8-6qw-9@gated-at.bofh.it>
In reply to#1703858

[Multipart message — attachments visible in raw view] — view raw

On Fri, Aug 04, 2017 at 01:24:08PM +0300, Mika Westerberg wrote:
> On Fri, Aug 04, 2017 at 12:18:28PM +0200, Jan Kiszka wrote:

> > It shouldn't cause problems (famous last words) because I refrained from
> > changing the interfaces to them. References that come in as legacy GPIO
> > are still treated like that.

> OK. I hope someone with a PXA2xx machine could still test it.

> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

This path should be very well covered - there's plenty of things that
convert GPIO numbers into descriptors out there.

[toc] | [prev] | [next] | [standalone]


#1703894 — Applied "spi: pxa2xx: Convert to GPIO descriptor API where possible" to the spi tree

FromMark Brown <broonie@kernel.org>
Date2017-08-04 13:50 +0200
SubjectApplied "spi: pxa2xx: Convert to GPIO descriptor API where possible" to the spi tree
Message-ID<uaJh8-6qw-19@gated-at.bofh.it>
In reply to#1702982
The patch

   spi: pxa2xx: Convert to GPIO descriptor API where possible

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From c18d925fca20d33c3d04e5002a883f62d699543e Mon Sep 17 00:00:00 2001
From: Jan Kiszka <jan.kiszka@siemens.com>
Date: Thu, 3 Aug 2017 13:40:32 +0200
Subject: [PATCH] spi: pxa2xx: Convert to GPIO descriptor API where possible

We still need to request/free GPIOs passed via the legacy path of
pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise.

Consistently use the descriptor API instead of the legacy one.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spi-pxa2xx.c | 32 ++++++++++++++++----------------
 drivers/spi/spi-pxa2xx.h |  2 +-
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 6e5af88b7c6f..4cb515a3104c 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -402,8 +402,8 @@ static void cs_assert(struct driver_data *drv_data)
 		return;
 	}
 
-	if (gpio_is_valid(chip->gpio_cs)) {
-		gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
+	if (chip->gpiod_cs) {
+		gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
 		return;
 	}
 
@@ -424,8 +424,8 @@ static void cs_deassert(struct driver_data *drv_data)
 		return;
 	}
 
-	if (gpio_is_valid(chip->gpio_cs)) {
-		gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
+	if (chip->gpiod_cs) {
+		gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
 		return;
 	}
 
@@ -1213,17 +1213,16 @@ 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 gpio_desc *gpiod;
 	int err = 0;
 
 	if (chip == NULL)
 		return 0;
 
 	if (drv_data->cs_gpiods) {
-		struct gpio_desc *gpiod;
-
 		gpiod = drv_data->cs_gpiods[spi->chip_select];
 		if (gpiod) {
-			chip->gpio_cs = desc_to_gpio(gpiod);
+			chip->gpiod_cs = gpiod;
 			chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
 			gpiod_set_value(gpiod, chip->gpio_cs_inverted);
 		}
@@ -1237,8 +1236,10 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
 	/* NOTE: setup() can be called multiple times, possibly with
 	 * different chip_info, release previously requested GPIO
 	 */
-	if (gpio_is_valid(chip->gpio_cs))
-		gpio_free(chip->gpio_cs);
+	if (chip->gpiod_cs) {
+		gpio_free(desc_to_gpio(chip->gpiod_cs));
+		chip->gpiod_cs = NULL;
+	}
 
 	/* If (*cs_control) is provided, ignore GPIO chip select */
 	if (chip_info->cs_control) {
@@ -1254,11 +1255,11 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
 			return err;
 		}
 
-		chip->gpio_cs = chip_info->gpio_cs;
+		gpiod = gpio_to_desc(chip_info->gpio_cs);
+		chip->gpiod_cs = gpiod;
 		chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
 
-		err = gpio_direction_output(chip->gpio_cs,
-					!chip->gpio_cs_inverted);
+		err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
 	}
 
 	return err;
@@ -1317,8 +1318,7 @@ static int setup(struct spi_device *spi)
 			}
 
 			chip->frm = spi->chip_select;
-		} else
-			chip->gpio_cs = -1;
+		}
 		chip->enable_dma = drv_data->master_info->enable_dma;
 		chip->timeout = TIMOUT_DFLT;
 	}
@@ -1416,8 +1416,8 @@ static void cleanup(struct spi_device *spi)
 		return;
 
 	if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
-	    gpio_is_valid(chip->gpio_cs))
-		gpio_free(chip->gpio_cs);
+	    chip->gpiod_cs)
+		gpio_free(desc_to_gpio(chip->gpiod_cs));
 
 	kfree(chip);
 }
diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
index 2823a00a9405..94f7b0713281 100644
--- a/drivers/spi/spi-pxa2xx.h
+++ b/drivers/spi/spi-pxa2xx.h
@@ -83,7 +83,7 @@ struct chip_data {
 	u16 lpss_tx_threshold;
 	u8 enable_dma;
 	union {
-		int gpio_cs;
+		struct gpio_desc *gpiod_cs;
 		unsigned int frm;
 	};
 	int gpio_cs_inverted;
-- 
2.13.3

[toc] | [prev] | [next] | [standalone]


#1702983 — [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created

FromJan Kiszka <jan.kiszka@siemens.com>
Date2017-08-03 13:50 +0200
Subject[PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created
Message-ID<uamNB-7Pj-27@gated-at.bofh.it>
In reply to#1702978
From: Jan Kiszka <jan.kiszka@siemens.com>

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@siemens.com>
---
 drivers/spi/spi-pxa2xx.c | 68 +++++++++++++++++++++---------------------------
 drivers/spi/spi-pxa2xx.h |  3 +--
 2 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 7faba738110c..577a2f4ba3bf 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1213,19 +1213,34 @@ 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;
 
 	if (chip == NULL)
 		return 0;
 
-	if (drv_data->cs_gpiods) {
-		gpiod = drv_data->cs_gpiods[spi->chip_select];
-		if (gpiod) {
-			chip->gpiod_cs = gpiod;
-			chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
-			gpiod_set_value(gpiod, chip->gpio_cs_inverted);
+	if (drv_data->cs_count > 0) {
+		/* setup() might be called multiple times. */
+		if (chip->gpiod_cs)
+			return 0;
+
+		if (spi->chip_select >= drv_data->cs_count)
+			return -EINVAL;
+
+		chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
+
+		gpiod = gpiod_get_index(pdev, "cs", spi->chip_select,
+					chip->gpio_cs_inverted ?
+				        GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
+		if (IS_ERR(gpiod)) {
+			/* Means use native chip select */
+			if (PTR_ERR(gpiod) == -ENOENT)
+				return 0;
+
+			return (int)PTR_ERR(gpiod);
 		}
+		chip->gpiod_cs = gpiod;
 
 		return 0;
 	}
@@ -1415,9 +1430,13 @@ static void cleanup(struct spi_device *spi)
 	if (!chip)
 		return;
 
-	if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
-	    chip->gpiod_cs)
-		gpio_free(desc_to_gpio(chip->gpiod_cs));
+	if (drv_data->ssp_type != CE4100_SSP && chip->gpiod_cs) {
+		if (drv_data->cs_count > 0)
+			gpiod_put(chip->gpiod_cs);
+		else
+			gpio_free(desc_to_gpio(chip->gpiod_cs));
+		chip->gpiod_cs = NULL;
+	}
 
 	kfree(chip);
 }
@@ -1752,37 +1771,10 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
 	master->num_chipselect = platform_info->num_chipselect;
 
 	count = gpiod_count(&pdev->dev, "cs");
-	if (count > 0) {
-		int i;
-
+	if (count > 0)
 		master->num_chipselect = max_t(int, count,
 			master->num_chipselect);
-
-		drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
-			master->num_chipselect, sizeof(struct gpio_desc *),
-			GFP_KERNEL);
-		if (!drv_data->cs_gpiods) {
-			status = -ENOMEM;
-			goto out_error_clock_enabled;
-		}
-
-		for (i = 0; i < master->num_chipselect; i++) {
-			struct gpio_desc *gpiod;
-
-			gpiod = devm_gpiod_get_index(dev, "cs", i,
-						     GPIOD_OUT_HIGH);
-			if (IS_ERR(gpiod)) {
-				/* Means use native chip select */
-				if (PTR_ERR(gpiod) == -ENOENT)
-					continue;
-
-				status = (int)PTR_ERR(gpiod);
-				goto out_error_clock_enabled;
-			} else {
-				drv_data->cs_gpiods[i] = gpiod;
-			}
-		}
-	}
+	drv_data->cs_count = count;
 
 	tasklet_init(&drv_data->pump_transfers, pump_transfers,
 		     (unsigned long)drv_data);
diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
index 94f7b0713281..8551c881f636 100644
--- a/drivers/spi/spi-pxa2xx.h
+++ b/drivers/spi/spi-pxa2xx.h
@@ -67,8 +67,7 @@ struct driver_data {
 
 	void __iomem *lpss_base;
 
-	/* GPIOs for chip selects */
-	struct gpio_desc **cs_gpiods;
+	int cs_count;
 };
 
 struct chip_data {
-- 
2.12.3

[toc] | [prev] | [next] | [standalone]


#1703856 — Re: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-08-04 12:30 +0200
SubjectRe: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created
Message-ID<uaI1H-5Ka-1@gated-at.bofh.it>
In reply to#1702983
On Thu, Aug 03, 2017 at 01:40:33PM +0200, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> 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@siemens.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

[toc] | [prev] | [next] | [standalone]


#1703891 — Re: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created

FromMark Brown <broonie@kernel.org>
Date2017-08-04 13:50 +0200
SubjectRe: [PATCH RFC 2/2] spi: pxa2xx: Only claim CS GPIOs when the slave device is created
Message-ID<uaJh8-6qw-15@gated-at.bofh.it>
In reply to#1702983

[Multipart message — attachments visible in raw view] — view raw

On Thu, Aug 03, 2017 at 01:40:33PM +0200, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> 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.

This doesn't apply against current code, please check and resend.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web