lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1475852194-27690-2-git-send-email-tthayer@opensource.altera.com>
Date:   Fri, 7 Oct 2016 09:56:34 -0500
From:   <tthayer@...nsource.altera.com>
To:     <broonie@...nel.org>
CC:     <andriy.shevchenko@...ux.intel.com>,
        <jarkko.nikula@...ux.intel.com>, <jszhang@...vell.com>,
        <michael@...rt-africa.com>, <kernel@...idel.net>,
        <linux-spi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <tthayer@...nsource.altera.com>
Subject: [PATCHv2 2/2] spi: Add Flag to Enable Slave Select with GPIO Chip Select.

From: Thor Thayer <tthayer@...nsource.altera.com>

Some SPI masters require slave selection before the transfer
can begin [1]. The SPI framework currently selects the chip using
either 1) the internal CS mechanism or 2) the GPIO CS, but not both.

This patch adds a boolean variable to indicate both the GPIO CS and
the internal chip select should be used.

Tested On:
    Altera CycloneV development kit
    Compile tested for build errors on x86_64 (allyesconfigs)

[1] DesignWare dw_apb_ssi Databook, Version 3.20a (page 39)

Signed-off-by: Thor Thayer <tthayer@...nsource.altera.com>
---
v2  Move changes to SPI framework based on maintainer comments
    Add a new SPI master boolean variable.
---
 drivers/spi/spi.c       |   10 ++++++++--
 include/linux/spi/spi.h |    1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5787b72..c042a8c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -697,10 +697,14 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
 	if (spi->mode & SPI_CS_HIGH)
 		enable = !enable;
 
-	if (gpio_is_valid(spi->cs_gpio))
+	if (gpio_is_valid(spi->cs_gpio)) {
 		gpio_set_value(spi->cs_gpio, !enable);
-	else if (spi->master->set_cs)
+		/* Some SPI masters need both GPIO CS & slave_select */
+		if (spi->master->set_cs && spi->master->gpio_ss)
+			spi->master->set_cs(spi, !enable);
+	} else if (spi->master->set_cs) {
 		spi->master->set_cs(spi, !enable);
+	}
 }
 
 #ifdef CONFIG_HAS_DMA
@@ -1845,6 +1849,8 @@ static int of_spi_register_master(struct spi_master *master)
 	for (i = 0; i < nb; i++)
 		cs[i] = of_get_named_gpio(np, "cs-gpios", i);
 
+	master->gpio_ss = of_property_read_bool(np, "gpio-ss");
+
 	return 0;
 }
 #else
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 4b743ac..0437995 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -551,6 +551,7 @@ struct spi_master {
 
 	/* gpio chip select */
 	int			*cs_gpios;
+	bool			gpio_ss;
 
 	/* statistics */
 	struct spi_statistics	statistics;
-- 
1.7.9.5

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ