linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-08 21:36 Michael Welling
  2015-04-09 10:52 ` Mark Brown
  2015-04-13 20:45 ` Michael Welling
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Welling @ 2015-04-08 21:36 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel; +Cc: Michael Welling

This patch allows for GPIOs specified in the devicetree to be used as SPI chipselects
on TI OMAP2 SoCs.

Tested on the AM3354.

Signed-off-by: Michael Welling <mwelling@ieee.org>
---
 drivers/spi/spi-omap2-mcspi.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 4df8942..464dec9 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -35,6 +35,7 @@
 #include <linux/gcd.h>
 
 #include <linux/spi/spi.h>
+#include <linux/gpio.h>
 
 #include <linux/platform_data/spi-omap2-mcspi.h>
 
@@ -246,6 +247,9 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
 {
 	u32 l;
 
+	if (gpio_is_valid(spi->cs_gpio))
+		gpio_set_value(spi->cs_gpio, (cs_active) ? 0 : 1);
+
 	l = mcspi_cached_chconf0(spi);
 	if (cs_active)
 		l |= OMAP2_MCSPI_CHCONF_FORCE;
@@ -1015,6 +1019,12 @@ static int omap2_mcspi_setup(struct spi_device *spi)
 	if (ret < 0)
 		return ret;
 
+	if (gpio_is_valid(spi->cs_gpio)) {
+		if (gpio_request(spi->cs_gpio, dev_name(&spi->dev)) == 0)
+			gpio_direction_output(spi->cs_gpio,
+					!(spi->mode & SPI_CS_HIGH));
+	}
+
 	ret = omap2_mcspi_setup_transfer(spi, NULL);
 	pm_runtime_mark_last_busy(mcspi->dev);
 	pm_runtime_put_autosuspend(mcspi->dev);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects
  2015-04-08 21:36 [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects Michael Welling
@ 2015-04-09 10:52 ` Mark Brown
  2015-04-13 20:45 ` Michael Welling
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2015-04-09 10:52 UTC (permalink / raw)
  To: Michael Welling; +Cc: linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On Wed, Apr 08, 2015 at 04:36:01PM -0500, Michael Welling wrote:
> This patch allows for GPIOs specified in the devicetree to be used as SPI chipselects
> on TI OMAP2 SoCs.

Please keep your commit messages under 80 columns.

> +	if (gpio_is_valid(spi->cs_gpio)) {
> +		if (gpio_request(spi->cs_gpio, dev_name(&spi->dev)) == 0)
> +			gpio_direction_output(spi->cs_gpio,
> +					!(spi->mode & SPI_CS_HIGH));
> +	}

For this to work we need to be sure that unspecified GPIOs are invalid
which isn't normally the default - zero tends to be a valid GPIO and
that's also the default for otherwise uninitialized data.  Is there
something that takes care of this?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects
  2015-04-08 21:36 [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects Michael Welling
  2015-04-09 10:52 ` Mark Brown
@ 2015-04-13 20:45 ` Michael Welling
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Welling @ 2015-04-13 20:45 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel

I noticed a response to my message on the mailing lists that did not appear in
my mailbox. Not sure where it went.

Sorry about the over 80 characters in the commit log.

As for the question about the uninitialized GPIOs, it is taken care in the 
core SPI driver.

The cs_gpio struct member is initialized to -ENOENT in spi_alloc_device:
http://lxr.free-electrons.com/source/drivers/spi/spi.c#L353

If there are GPIOs specified in the devicetree the value is updated:
http://lxr.free-electrons.com/source/drivers/spi/spi.c#L440

On Wed, Apr 08, 2015 at 04:36:01PM -0500, Michael Welling wrote:
> This patch allows for GPIOs specified in the devicetree to be used as SPI chipselects
> on TI OMAP2 SoCs.
> 
> Tested on the AM3354.
> 
> Signed-off-by: Michael Welling <mwelling@ieee.org>
> ---
>  drivers/spi/spi-omap2-mcspi.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
> index 4df8942..464dec9 100644
> --- a/drivers/spi/spi-omap2-mcspi.c
> +++ b/drivers/spi/spi-omap2-mcspi.c
> @@ -35,6 +35,7 @@
>  #include <linux/gcd.h>
>  
>  #include <linux/spi/spi.h>
> +#include <linux/gpio.h>
>  
>  #include <linux/platform_data/spi-omap2-mcspi.h>
>  
> @@ -246,6 +247,9 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
>  {
>  	u32 l;
>  
> +	if (gpio_is_valid(spi->cs_gpio))
> +		gpio_set_value(spi->cs_gpio, (cs_active) ? 0 : 1);
> +

This may need to be changed to reflect the value of the spi->mode SPI_CS_HIGH
bit. It seems that I assumed that the chipselects are active low above.

>  	l = mcspi_cached_chconf0(spi);
>  	if (cs_active)
>  		l |= OMAP2_MCSPI_CHCONF_FORCE;
> @@ -1015,6 +1019,12 @@ static int omap2_mcspi_setup(struct spi_device *spi)
>  	if (ret < 0)
>  		return ret;
>  
> +	if (gpio_is_valid(spi->cs_gpio)) {
> +		if (gpio_request(spi->cs_gpio, dev_name(&spi->dev)) == 0)
> +			gpio_direction_output(spi->cs_gpio,
> +					!(spi->mode & SPI_CS_HIGH));
> +	}
> +
>  	ret = omap2_mcspi_setup_transfer(spi, NULL);
>  	pm_runtime_mark_last_busy(mcspi->dev);
>  	pm_runtime_put_autosuspend(mcspi->dev);
> -- 
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-13 20:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-08 21:36 [PATCH] spi: omap2-mcspi: Add support for GPIO chipselects Michael Welling
2015-04-09 10:52 ` Mark Brown
2015-04-13 20:45 ` Michael Welling

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).