diff options
author | Brian Niebuhr <bniebuhr@efjohnson.com> | 2010-08-13 00:41:03 -0400 |
---|---|---|
committer | Sekhar Nori <nsekhar@ti.com> | 2010-11-18 08:08:24 -0500 |
commit | 7978b8c385a86f0b5b9304e81a1dfb5dcaf21528 (patch) | |
tree | ff13c4dd8d8cd570d57d50f072e8cdab3c97ea5f /drivers | |
parent | 843a713bc53d04f8fac46ddd8693a2cc0422ca5e (diff) |
spi: davinci: enable both activation and deactivation of chip-selects
Let davinci_spi_chipselect() perform both activation and
deactivation of chip selects. This lets spi_bitbang fully
control chip select activation, as intended by the SPI API.
With this change, the chip select activation code need not
be duplicated in davinci_spi_bufs_{pio|dma}().
Also, keeping chip select active control is removed as a
platform data and simply controlled using information from
spi_bitbang on whether chip slect should be activated or
de-activated.
Signed-off-by: Brian Niebuhr <bniebuhr@efjohnson.com>
Tested-By: Michael Williamson <michael.williamson@criticallink.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/davinci_spi.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index d6b6a4958088..105c686b2cea 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c | |||
@@ -66,7 +66,7 @@ | |||
66 | #define SPI_INTLVL_0 0x00000000u | 66 | #define SPI_INTLVL_0 0x00000000u |
67 | 67 | ||
68 | /* SPIDAT1 */ | 68 | /* SPIDAT1 */ |
69 | #define SPIDAT1_CSHOLD_SHIFT 28 | 69 | #define SPIDAT1_CSHOLD_MASK BIT(28) |
70 | #define SPIDAT1_CSNR_SHIFT 16 | 70 | #define SPIDAT1_CSNR_SHIFT 16 |
71 | #define SPIGCR1_CLKMOD_MASK BIT(1) | 71 | #define SPIGCR1_CLKMOD_MASK BIT(1) |
72 | #define SPIGCR1_MASTER_MASK BIT(0) | 72 | #define SPIGCR1_MASTER_MASK BIT(0) |
@@ -235,7 +235,8 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value) | |||
235 | { | 235 | { |
236 | struct davinci_spi *davinci_spi; | 236 | struct davinci_spi *davinci_spi; |
237 | struct davinci_spi_platform_data *pdata; | 237 | struct davinci_spi_platform_data *pdata; |
238 | u32 data1_reg_val = 0; | 238 | u32 data1_reg_val; |
239 | u8 chip_sel = spi->chip_select; | ||
239 | 240 | ||
240 | davinci_spi = spi_master_get_devdata(spi->master); | 241 | davinci_spi = spi_master_get_devdata(spi->master); |
241 | pdata = davinci_spi->pdata; | 242 | pdata = davinci_spi->pdata; |
@@ -244,14 +245,17 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value) | |||
244 | * Board specific chip select logic decides the polarity and cs | 245 | * Board specific chip select logic decides the polarity and cs |
245 | * line for the controller | 246 | * line for the controller |
246 | */ | 247 | */ |
247 | if (value == BITBANG_CS_INACTIVE) { | 248 | data1_reg_val = CS_DEFAULT << SPIDAT1_CSNR_SHIFT; |
248 | data1_reg_val |= CS_DEFAULT << SPIDAT1_CSNR_SHIFT; | 249 | if (value == BITBANG_CS_ACTIVE) { |
249 | iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1); | 250 | data1_reg_val |= SPIDAT1_CSHOLD_MASK; |
250 | 251 | data1_reg_val &= ~((0x1 << chip_sel) << SPIDAT1_CSNR_SHIFT); | |
251 | while ((ioread32(davinci_spi->base + SPIBUF) | ||
252 | & SPIBUF_RXEMPTY_MASK) == 0) | ||
253 | cpu_relax(); | ||
254 | } | 252 | } |
253 | |||
254 | iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1); | ||
255 | while ((ioread32(davinci_spi->base + SPIBUF) | ||
256 | & SPIBUF_RXEMPTY_MASK) == 0) | ||
257 | cpu_relax(); | ||
258 | |||
255 | } | 259 | } |
256 | 260 | ||
257 | /** | 261 | /** |
@@ -632,7 +636,7 @@ static int davinci_spi_bufs_pio(struct spi_device *spi, struct spi_transfer *t) | |||
632 | { | 636 | { |
633 | struct davinci_spi *davinci_spi; | 637 | struct davinci_spi *davinci_spi; |
634 | int int_status, count, ret; | 638 | int int_status, count, ret; |
635 | u8 conv, tmp; | 639 | u8 conv; |
636 | u32 tx_data, data1_reg_val; | 640 | u32 tx_data, data1_reg_val; |
637 | u32 buf_val, flg_val; | 641 | u32 buf_val, flg_val; |
638 | struct davinci_spi_platform_data *pdata; | 642 | struct davinci_spi_platform_data *pdata; |
@@ -647,6 +651,8 @@ static int davinci_spi_bufs_pio(struct spi_device *spi, struct spi_transfer *t) | |||
647 | conv = davinci_spi->slave[spi->chip_select].bytes_per_word; | 651 | conv = davinci_spi->slave[spi->chip_select].bytes_per_word; |
648 | davinci_spi->count = t->len / conv; | 652 | davinci_spi->count = t->len / conv; |
649 | 653 | ||
654 | data1_reg_val = ioread32(davinci_spi->base + SPIDAT1); | ||
655 | |||
650 | INIT_COMPLETION(davinci_spi->done); | 656 | INIT_COMPLETION(davinci_spi->done); |
651 | 657 | ||
652 | ret = davinci_spi_bufs_prep(spi, davinci_spi); | 658 | ret = davinci_spi_bufs_prep(spi, davinci_spi); |
@@ -661,16 +667,6 @@ static int davinci_spi_bufs_pio(struct spi_device *spi, struct spi_transfer *t) | |||
661 | davinci_spi->base + SPIDELAY); | 667 | davinci_spi->base + SPIDELAY); |
662 | 668 | ||
663 | count = davinci_spi->count; | 669 | count = davinci_spi->count; |
664 | data1_reg_val = pdata->cs_hold << SPIDAT1_CSHOLD_SHIFT; | ||
665 | tmp = ~(0x1 << spi->chip_select); | ||
666 | |||
667 | clear_io_bits(davinci_spi->base + SPIDEF, ~tmp); | ||
668 | |||
669 | data1_reg_val |= tmp << SPIDAT1_CSNR_SHIFT; | ||
670 | |||
671 | while ((ioread32(davinci_spi->base + SPIBUF) | ||
672 | & SPIBUF_RXEMPTY_MASK) == 0) | ||
673 | cpu_relax(); | ||
674 | 670 | ||
675 | /* Determine the command to execute READ or WRITE */ | 671 | /* Determine the command to execute READ or WRITE */ |
676 | if (t->tx_buf) { | 672 | if (t->tx_buf) { |
@@ -770,7 +766,6 @@ static int davinci_spi_bufs_dma(struct spi_device *spi, struct spi_transfer *t) | |||
770 | int int_status = 0; | 766 | int int_status = 0; |
771 | int count, temp_count; | 767 | int count, temp_count; |
772 | u8 conv = 1; | 768 | u8 conv = 1; |
773 | u8 tmp; | ||
774 | u32 data1_reg_val; | 769 | u32 data1_reg_val; |
775 | struct davinci_spi_dma *davinci_spi_dma; | 770 | struct davinci_spi_dma *davinci_spi_dma; |
776 | int word_len, data_type, ret; | 771 | int word_len, data_type, ret; |
@@ -794,6 +789,8 @@ static int davinci_spi_bufs_dma(struct spi_device *spi, struct spi_transfer *t) | |||
794 | conv = davinci_spi->slave[spi->chip_select].bytes_per_word; | 789 | conv = davinci_spi->slave[spi->chip_select].bytes_per_word; |
795 | davinci_spi->count = t->len / conv; | 790 | davinci_spi->count = t->len / conv; |
796 | 791 | ||
792 | data1_reg_val = ioread32(davinci_spi->base + SPIDAT1); | ||
793 | |||
797 | INIT_COMPLETION(davinci_spi->done); | 794 | INIT_COMPLETION(davinci_spi->done); |
798 | 795 | ||
799 | init_completion(&davinci_spi_dma->dma_rx_completion); | 796 | init_completion(&davinci_spi_dma->dma_rx_completion); |
@@ -820,28 +817,14 @@ static int davinci_spi_bufs_dma(struct spi_device *spi, struct spi_transfer *t) | |||
820 | davinci_spi->base + SPIDELAY); | 817 | davinci_spi->base + SPIDELAY); |
821 | 818 | ||
822 | count = davinci_spi->count; /* the number of elements */ | 819 | count = davinci_spi->count; /* the number of elements */ |
823 | data1_reg_val = pdata->cs_hold << SPIDAT1_CSHOLD_SHIFT; | ||
824 | |||
825 | /* CS default = 0xFF */ | ||
826 | tmp = ~(0x1 << spi->chip_select); | ||
827 | |||
828 | clear_io_bits(davinci_spi->base + SPIDEF, ~tmp); | ||
829 | |||
830 | data1_reg_val |= tmp << SPIDAT1_CSNR_SHIFT; | ||
831 | 820 | ||
832 | /* disable all interrupts for dma transfers */ | 821 | /* disable all interrupts for dma transfers */ |
833 | clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL); | 822 | clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL); |
834 | /* Disable SPI to write configuration bits in SPIDAT */ | 823 | /* Disable SPI to write configuration bits in SPIDAT */ |
835 | clear_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); | 824 | clear_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); |
836 | iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1); | ||
837 | /* Enable SPI */ | 825 | /* Enable SPI */ |
838 | set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); | 826 | set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); |
839 | 827 | ||
840 | while ((ioread32(davinci_spi->base + SPIBUF) | ||
841 | & SPIBUF_RXEMPTY_MASK) == 0) | ||
842 | cpu_relax(); | ||
843 | |||
844 | |||
845 | if (t->tx_buf) { | 828 | if (t->tx_buf) { |
846 | t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf, count, | 829 | t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf, count, |
847 | DMA_TO_DEVICE); | 830 | DMA_TO_DEVICE); |