--- ../spi_sunxi.c.orig 2014-10-23 10:12:13.007628069 +0100 +++ drivers/spi/spi_sunxi.c 2014-10-23 11:45:38.758239135 +0100 @@ -510,6 +510,13 @@ writel(reg_val, base_addr + SPI_CTL_REG); } +/* keep unused burst */ +void spi_clear_dhb(void *base_addr) +{ + u32 reg_val = readl(base_addr + SPI_CTL_REG); + reg_val &= ~SPI_CTL_DHB; + writel(reg_val, base_addr + SPI_CTL_REG); +} static int spi_sunxi_get_cfg_csbitmap(int bus_num); @@ -582,7 +589,6 @@ else { spi_wrn("unknow dma direction = %d \n",aw_spi->dma_dir); } - aw_spi_sel_dma_type(0, aw_spi->base_addr); spin_unlock_irqrestore(&aw_spi->lock, flags); } #else @@ -608,8 +614,7 @@ //spi_msg("spi dma tx -write data\n"); aw_spi_disable_dma_irq(SPI_DRQEN_THE, aw_spi->base_addr); - aw_spi_sel_dma_type(0, aw_spi->base_addr); - spin_unlock_irqrestore(&aw_spi->lock, flags); + spin_unlock_irqrestore(&aw_spi->lock, flags); } @@ -950,10 +955,9 @@ spi_wrn("Full duplex not supported for normal dma!\n"); return EINVAL; } - aw_spi_sel_dma_type(0, base_addr); - #else - aw_spi_sel_dma_type(1, base_addr); - #endif + #else + aw_spi_sel_dma_type(1, base_addr); + #endif if(tx_len) { /* txFIFO 1/4 empty dma request enable,when 16 or less than 16 bytes. */ @@ -1001,28 +1005,33 @@ aw_spi_start_xfer(base_addr); } else { /* no dma */ - unsigned int poll_time = 0xfffff; + unsigned int poll_time_rx = 0x7ffff; + unsigned int poll_time_tx = 0xfffff; //spi_msg(" tx -> by ahb\n"); spin_lock_irqsave(&aw_spi->lock, flags); for(; tx_len > 0; --tx_len) { writeb(*tx_buf++, base_addr + SPI_TXDATA_REG); } spin_unlock_irqrestore(&aw_spi->lock, flags); - aw_spi_start_xfer(base_addr); + aw_spi_start_xfer(base_addr); + if (tx_len) { + while ( aw_spi_query_txfifo(base_addr) && (--poll_time_tx > 0) ); //txFIFO counter + if ( poll_time_tx <= 0 ) { + spi_wrn("cpu tx data time out!\n"); + } + } if (rx_len) { - while(rx_len && (--poll_time >0)) { + while(rx_len && (--poll_time_rx >0)) { /* rxFIFO counter */ - if(aw_spi_query_rxfifo(base_addr)){ - *rx_buf++ = readb(base_addr + SPI_RXDATA_REG);//fetch data - --rx_len; - poll_time = 0xffff; - } + if (aw_spi_query_rxfifo(base_addr)) { + *rx_buf++ = readb(base_addr + SPI_RXDATA_REG); //fetch data + --rx_len; + } + if ( poll_time_rx <= 0 ) { + spi_wrn("cpu rx data time out!\n"); + } } - } else { - while(aw_spi_query_txfifo(base_addr)&&(--poll_time > 0) );/* txFIFO counter */ - } - if(poll_time <= 0) { - spi_wrn("cpu tx data time out!\n"); + } } @@ -1081,6 +1090,10 @@ } /* update the new cs value */ cs_change = t->cs_change; + /* full duplex mode */ + if (t->rx_buf && t->tx_buf) + spi_clear_dhb(aw_spi->base_addr); + /* * do transfer * > 64 : cpu ; =< 64 : dma