From: hhb Date: Tue, 12 Mar 2013 02:37:26 +0000 (+0800) Subject: spi: add slave supprot X-Git-Tag: firefly_0821_release~7431 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4474e2aeaba9289593459571e81b820beab71ed4;p=firefly-linux-kernel-4.4.55.git spi: add slave supprot --- diff --git a/drivers/spi/rk29_spim.c b/drivers/spi/rk29_spim.c index a314787e71cb..e8a02cbe28a7 100755 --- a/drivers/spi/rk29_spim.c +++ b/drivers/spi/rk29_spim.c @@ -73,7 +73,7 @@ struct chip_data { u8 type; /* SPI/SSP/MicroWire */ u8 poll_mode; /* 1 means use poll mode */ - + u8 slave_enable; u32 dma_width; u32 rx_threshold; u32 tx_threshold; @@ -270,7 +270,12 @@ static void transfer_complete(struct rk29xx_spi *dws); static void wait_till_not_busy(struct rk29xx_spi *dws) { unsigned long end = jiffies + 1 + usecs_to_jiffies(1000); - + //if spi was slave, it is SR_BUSY always. + if(dws->cur_chip) { + if(dws->cur_chip->slave_enable == 1) + return; + } + while (time_before(jiffies, end)) { if (!(rk29xx_readw(dws, SPIM_SR) & SR_BUSY)) return; @@ -613,6 +618,7 @@ static void giveback(struct rk29xx_spi *dws) dws->prev_chip = dws->cur_chip; dws->cur_chip = NULL; dws->dma_mapped = 0; + /*it is important to close intterrupt*/ spi_mask_intr(dws, 0xff); @@ -901,9 +907,11 @@ static void pump_transfers(unsigned long data) chip->tmode = SPI_TMOD_TO; cr0 &= ~(0x3 << SPI_MODE_OFFSET); - cr0 &= ~(0x3 << SPI_TMOD_OFFSET); + cr0 &= ~(0x3 << SPI_TMOD_OFFSET); + cr0 &= ~(0x1 << SPI_OPMOD_OFFSET); cr0 |= (spi->mode << SPI_MODE_OFFSET); cr0 |= (chip->tmode << SPI_TMOD_OFFSET); + cr0 |= ((chip->slave_enable & 1) << SPI_OPMOD_OFFSET); } /* @@ -943,10 +951,11 @@ static void pump_transfers(unsigned long data) spi_chip_sel(dws, spi->chip_select); rk29xx_writew(dws, SPIM_CTRLR1, dws->len-1); - spi_enable_chip(dws, 1); - + if (txint_level) rk29xx_writew(dws, SPIM_TXFTLR, txint_level); + spi_enable_chip(dws, 1); + if (rxint_level) rk29xx_writew(dws, SPIM_RXFTLR, rxint_level); /* Set the interrupt mask, for poll mode just diable all int */ @@ -1111,9 +1120,11 @@ static void dma_transfer(struct rk29xx_spi *dws) chip->tmode = SPI_TMOD_TO; cr0 &= ~(0x3 << SPI_MODE_OFFSET); - cr0 &= ~(0x3 << SPI_TMOD_OFFSET); - cr0 |= (chip->mode << SPI_MODE_OFFSET); + cr0 &= ~(0x3 << SPI_TMOD_OFFSET); + cr0 &= ~(0x1 << SPI_OPMOD_OFFSET); + cr0 |= (spi->mode << SPI_MODE_OFFSET); cr0 |= (chip->tmode << SPI_TMOD_OFFSET); + cr0 |= ((chip->slave_enable & 1) << SPI_OPMOD_OFFSET); } /* @@ -1730,7 +1741,7 @@ static int rk29xx_spi_setup(struct spi_device *spi) chip->poll_mode = chip_info->poll_mode; chip->type = chip_info->type; - + chip->slave_enable = chip_info->slave_enable; chip->rx_threshold = 0; chip->tx_threshold = 0; diff --git a/drivers/spi/rk29_spim.h b/drivers/spi/rk29_spim.h index d417bc8ce946..073c434a7929 100755 --- a/drivers/spi/rk29_spim.h +++ b/drivers/spi/rk29_spim.h @@ -64,6 +64,10 @@ #define SPI_SCOL_OFFSET 7 /* Serial Clock Polarity */ +#define SPI_OPMOD_OFFSET 20 +#define SPI_OPMOD_MASTER 0 +#define SPI_OPMOD_SLAVE 1 + #define SPI_TMOD_OFFSET 18 /* Transfer Mode */ #define SPI_TMOD_TR 0x00 /* xmit & recv */ #define SPI_TMOD_TO 0x01 /* xmit only */ @@ -254,6 +258,7 @@ struct rk29xx_spi_chip { u8 poll_mode; /* 0 for contoller polling mode */ u8 type; /* SPI/SSP/Micrwire */ u8 enable_dma; + u8 slave_enable; void (*cs_control)(struct rk29xx_spi *dws, u32 cs, u8 flag); };