diff options
author | Baruch Siach <baruch@tkos.co.il> | 2014-01-31 12:07:47 +0200 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-04-24 18:09:05 +0100 |
commit | d9c73bb8a3a5e4b76d2ad55da00d9ea776475c81 (patch) | |
tree | f711caf00b7025672dc919e5896a597535588111 /drivers/spi/spi-dw.c | |
parent | 20e5ea191524b482e1b4aa12b5ff4684717f44b8 (diff) | |
download | linux-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.c')
-rw-r--r-- | drivers/spi/spi-dw.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 357869a704d6..9965e1b84832 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -24,6 +24,7 @@ #include <linux/delay.h> #include <linux/slab.h> #include <linux/spi/spi.h> +#include <linux/gpio.h> #include "spi-dw.h" @@ -36,9 +37,6 @@ #define DONE_STATE ((void *)2) #define ERROR_STATE ((void *)-1) -#define MRST_SPI_DEASSERT 0 -#define MRST_SPI_ASSERT 1 - /* Slave spi_dev related */ struct chip_data { u16 cr0; @@ -272,8 +270,8 @@ static void giveback(struct dw_spi *dws) last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, transfer_list); - if (!last_transfer->cs_change && dws->cs_control) - dws->cs_control(MRST_SPI_DEASSERT); + if (!last_transfer->cs_change) + spi_chip_sel(dws, dws->cur_msg->spi, 0); spi_finalize_current_message(dws->master); } @@ -493,7 +491,7 @@ static void pump_transfers(unsigned long data) dw_writew(dws, DW_SPI_CTRL0, cr0); spi_set_clk(dws, clk_div ? clk_div : chip->clk_div); - spi_chip_sel(dws, spi->chip_select); + spi_chip_sel(dws, spi, 1); /* Set the interrupt mask, for poll mode just disable all int */ spi_mask_intr(dws, 0xff); @@ -544,6 +542,7 @@ static int dw_spi_setup(struct spi_device *spi) { struct dw_spi_chip *chip_info = NULL; struct chip_data *chip; + int ret; /* Only alloc on first setup */ chip = spi_get_ctldata(spi); @@ -597,6 +596,13 @@ static int dw_spi_setup(struct spi_device *spi) | (spi->mode << SPI_MODE_OFFSET) | (chip->tmode << SPI_TMOD_OFFSET); + if (gpio_is_valid(spi->cs_gpio)) { + ret = gpio_direction_output(spi->cs_gpio, + !(spi->mode & SPI_CS_HIGH)); + if (ret) + return ret; + } + return 0; } |