linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] Remove "spi-cs-high" property for GPIO-based chipselects
@ 2013-12-01  7:59 Alexander Shiyan
       [not found] ` <1385884756-31373-1-git-send-email-shc_work-JGs/UdohzUI@public.gmane.org>
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Shiyan @ 2013-12-01  7:59 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Mark Brown, Alexander Shiyan

This patch takes the CS active level from the GPIO bindings,
so we remove the special property "spi-cs-high" for chipselects
that use GPIO.

Signed-off-by: Alexander Shiyan <shc_work-JGs/UdohzUI@public.gmane.org>
---
 drivers/spi/spi.c       | 28 ++++++++++++++++++----------
 include/linux/spi/spi.h |  2 ++
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 98f4b77..d2ba1ec 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -413,8 +413,12 @@ int spi_add_device(struct spi_device *spi)
 		goto done;
 	}
 
-	if (master->cs_gpios)
+	if (master->cs_gpios) {
 		spi->cs_gpio = master->cs_gpios[spi->chip_select];
+		if (!(master->cs_gpios_flags[spi->chip_select] &
+		      OF_GPIO_ACTIVE_LOW))
+			spi->mode |= SPI_CS_HIGH;
+	}
 
 	/* Drivers may modify this initial i/o setup, but will
 	 * normally rely on the device being setup.  Devices
@@ -1027,10 +1031,14 @@ static void of_register_spi_devices(struct spi_master *master)
 			spi->mode |= SPI_CPHA;
 		if (of_find_property(nc, "spi-cpol", NULL))
 			spi->mode |= SPI_CPOL;
-		if (of_find_property(nc, "spi-cs-high", NULL))
-			spi->mode |= SPI_CS_HIGH;
 		if (of_find_property(nc, "spi-3wire", NULL))
 			spi->mode |= SPI_3WIRE;
+		if (of_find_property(nc, "spi-cs-high", NULL)) {
+			if (master->cs_gpios)
+				dev_notice(&master->dev,
+					"\"spi-cs-high\" property is obsolete.\n");
+			spi->mode |= SPI_CS_HIGH;
+		}
 
 		/* Device DUAL/QUAD mode */
 		if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
@@ -1260,7 +1268,7 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
 #ifdef CONFIG_OF
 static int of_spi_register_master(struct spi_master *master)
 {
-	int nb, i, *cs;
+	int nb, i;
 	struct device_node *np = master->dev.of_node;
 
 	if (!np)
@@ -1275,19 +1283,19 @@ static int of_spi_register_master(struct spi_master *master)
 	else if (nb < 0)
 		return nb;
 
-	cs = devm_kzalloc(&master->dev,
-			  sizeof(int) * master->num_chipselect,
-			  GFP_KERNEL);
-	master->cs_gpios = cs;
+	master->cs_gpios = devm_kzalloc(&master->dev, master->num_chipselect *
+		(sizeof(int) + sizeof(enum of_gpio_flags)), GFP_KERNEL);
 
 	if (!master->cs_gpios)
 		return -ENOMEM;
 
 	for (i = 0; i < master->num_chipselect; i++)
-		cs[i] = -ENOENT;
+		master->cs_gpios[i] = -ENOENT;
 
 	for (i = 0; i < nb; i++)
-		cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+		master->cs_gpios[i] =
+			of_get_named_gpio_flags(np, "cs-gpios", i,
+						&master->cs_gpios_flags[i]);
 
 	return 0;
 }
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 8c62ba7..c0cade2 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -423,6 +423,8 @@ struct spi_master {
 
 	/* gpio chip select */
 	int			*cs_gpios;
+	/* GPIO flags */
+	enum of_gpio_flags	*cs_gpios_flags;
 };
 
 static inline void *spi_master_get_devdata(struct spi_master *master)
-- 
1.8.3.2

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

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

end of thread, other threads:[~2013-12-03  4:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-01  7:59 [PATCH RFC] Remove "spi-cs-high" property for GPIO-based chipselects Alexander Shiyan
     [not found] ` <1385884756-31373-1-git-send-email-shc_work-JGs/UdohzUI@public.gmane.org>
2013-12-02 11:43   ` Mark Brown
     [not found]     ` <20131202114310.GP27568-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-12-02 11:58       ` Alexander Shiyan
     [not found]         ` <1385985513.987194654-zxFGIbyeZotsdVUOrk1QfQ@public.gmane.org>
2013-12-02 12:33           ` Mark Brown
     [not found]             ` <20131202123339.GZ27568-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-12-02 12:42               ` Alexander Shiyan
     [not found]                 ` <1385988152.848953040-u8tvknxLvilsdVUOrk1QfQ@public.gmane.org>
2013-12-02 12:46                   ` Mark Brown
2013-12-02 13:49   ` Jonas Gorski
     [not found]     ` <CAOiHx=nAcGdk7QgKPrbmkbQYzWL6qNb2cnJj3c_A+9++RrLoeA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-02 14:54       ` Alexander Shiyan
     [not found]         ` <1385996099.869286515-/wTItXjRvv7WO3iv0lnsqw@public.gmane.org>
2013-12-02 18:03           ` Jonas Gorski
     [not found]             ` <CAOiHx=kLkiWjnuUV_1-rVrO-EDQw=Ut0eZE5egYrmiVK9wmxfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-02 20:17               ` Gerhard Sittig
     [not found]                 ` <20131202201722.GZ2982-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2013-12-02 22:09                   ` Jonas Gorski
     [not found]                     ` <CAOiHx=krrM+NZ7detAv9_UsB+bUXtKL0m4=pDHO30uduJsDdFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-02 22:36                       ` Gerhard Sittig
     [not found]                         ` <20131202223632.GA2982-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2013-12-03  4:23                           ` Alexander Shiyan
2013-12-02 14:59   ` Gerhard Sittig
     [not found]     ` <20131202145911.GT2982-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2013-12-02 15:24       ` Alexander Shiyan
     [not found]         ` <1385997862.727371043-/wTItXjRvv7WO3iv0lnsqw@public.gmane.org>
2013-12-02 16:31           ` Gerhard Sittig
     [not found]             ` <20131202163124.GW2982-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2013-12-02 17:14               ` Alexander Shiyan

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