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>
This commit is contained in:
Baruch Siach
2014-01-31 12:07:47 +02:00
committed by Mark Brown
parent 20e5ea1915
commit d9c73bb8a3
3 changed files with 45 additions and 11 deletions

View File

@@ -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 */