summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-dw.h
diff options
context:
space:
mode:
authorBaruch Siach <baruch@tkos.co.il>2014-01-31 12:07:47 +0200
committerMark Brown <broonie@linaro.org>2014-04-24 18:09:05 +0100
commitd9c73bb8a3a5e4b76d2ad55da00d9ea776475c81 (patch)
treef711caf00b7025672dc919e5896a597535588111 /drivers/spi/spi-dw.h
parent20e5ea191524b482e1b4aa12b5ff4684717f44b8 (diff)
downloadlinux-d9c73bb8a3a5e4b76d2ad55da00d9ea776475c81.tar.gz
linux-d9c73bb8a3a5e4b76d2ad55da00d9ea776475c81.tar.bz2
linux-d9c73bb8a3a5e4b76d2ad55da00d9ea776475c81.zip
spi: dw: add support for gpio controlled chip select
Also, use this opportunity to let spi_chip_sel() handle chip-select deactivation as well. Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi/spi-dw.h')
-rw-r--r--drivers/spi/spi-dw.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 3fd7ab599ab4..6d2acad34f64 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -3,6 +3,7 @@
#include <linux/io.h>
#include <linux/scatterlist.h>
+#include <linux/gpio.h>
/* Register offsets */
#define DW_SPI_CTRL0 0x00
@@ -178,15 +179,20 @@ static inline void spi_set_clk(struct dw_spi *dws, u16 div)
dw_writel(dws, DW_SPI_BAUDR, div);
}
-static inline void spi_chip_sel(struct dw_spi *dws, u16 cs)
+static inline void spi_chip_sel(struct dw_spi *dws, struct spi_device *spi,
+ int active)
{
- if (cs > dws->num_cs)
- return;
+ u16 cs = spi->chip_select;
+ int gpio_val = active ? (spi->mode & SPI_CS_HIGH) :
+ !(spi->mode & SPI_CS_HIGH);
if (dws->cs_control)
- dws->cs_control(1);
+ dws->cs_control(active);
+ if (gpio_is_valid(spi->cs_gpio))
+ gpio_set_value(spi->cs_gpio, gpio_val);
- dw_writel(dws, DW_SPI_SER, 1 << cs);
+ if (active)
+ dw_writel(dws, DW_SPI_SER, 1 << cs);
}
/* Disable IRQ bits */