提交 0afa0724 编写于 作者: M Mark Brown

Merge remote-tracking branches 'spi/topic/armada', 'spi/topic/ath79',...

Merge remote-tracking branches 'spi/topic/armada', 'spi/topic/ath79', 'spi/topic/atmel' and 'spi/topic/axi' into spi-next
* Marvell Armada 3700 SPI Controller
Required Properties:
- compatible: should be "marvell,armada-3700-spi"
- reg: physical base address of the controller and length of memory mapped
region.
- interrupts: The interrupt number. The interrupt specifier format depends on
the interrupt controller and of its driver.
- clocks: Must contain the clock source, usually from the North Bridge clocks.
- num-cs: The number of chip selects that is supported by this SPI Controller
- #address-cells: should be 1.
- #size-cells: should be 0.
Example:
spi0: spi@10600 {
compatible = "marvell,armada-3700-spi";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x10600 0x5d>;
clocks = <&nb_perih_clk 7>;
interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
num-cs = <4>;
};
...@@ -67,6 +67,13 @@ config SPI_ATH79 ...@@ -67,6 +67,13 @@ config SPI_ATH79
This enables support for the SPI controller present on the This enables support for the SPI controller present on the
Atheros AR71XX/AR724X/AR913X SoCs. Atheros AR71XX/AR724X/AR913X SoCs.
config SPI_ARMADA_3700
tristate "Marvell Armada 3700 SPI Controller"
depends on (ARCH_MVEBU && OF) || COMPILE_TEST
help
This enables support for the SPI controller present on the
Marvell Armada 3700 SoCs.
config SPI_ATMEL config SPI_ATMEL
tristate "Atmel SPI Controller" tristate "Atmel SPI Controller"
depends on HAS_DMA depends on HAS_DMA
......
...@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o ...@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o
# SPI master controller drivers (bus) # SPI master controller drivers (bus)
obj-$(CONFIG_SPI_ALTERA) += spi-altera.o obj-$(CONFIG_SPI_ALTERA) += spi-altera.o
obj-$(CONFIG_SPI_ARMADA_3700) += spi-armada-3700.o
obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o
obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_ATH79) += spi-ath79.o
obj-$(CONFIG_SPI_AU1550) += spi-au1550.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o
......
此差异已折叠。
...@@ -304,6 +304,7 @@ static const struct of_device_id ath79_spi_of_match[] = { ...@@ -304,6 +304,7 @@ static const struct of_device_id ath79_spi_of_match[] = {
{ .compatible = "qca,ar7100-spi", }, { .compatible = "qca,ar7100-spi", },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, ath79_spi_of_match);
static struct platform_driver ath79_spi_driver = { static struct platform_driver ath79_spi_driver = {
.probe = ath79_spi_probe, .probe = ath79_spi_probe,
......
...@@ -265,17 +265,6 @@ ...@@ -265,17 +265,6 @@
#define AUTOSUSPEND_TIMEOUT 2000 #define AUTOSUSPEND_TIMEOUT 2000
struct atmel_spi_dma {
struct dma_chan *chan_rx;
struct dma_chan *chan_tx;
struct scatterlist sgrx;
struct scatterlist sgtx;
struct dma_async_tx_descriptor *data_desc_rx;
struct dma_async_tx_descriptor *data_desc_tx;
struct at_dma_slave dma_slave;
};
struct atmel_spi_caps { struct atmel_spi_caps {
bool is_spi2; bool is_spi2;
bool has_wdrbt; bool has_wdrbt;
...@@ -304,17 +293,11 @@ struct atmel_spi { ...@@ -304,17 +293,11 @@ struct atmel_spi {
struct completion xfer_completion; struct completion xfer_completion;
/* scratch buffer */
void *buffer;
dma_addr_t buffer_dma;
struct atmel_spi_caps caps; struct atmel_spi_caps caps;
bool use_dma; bool use_dma;
bool use_pdc; bool use_pdc;
bool use_cs_gpios; bool use_cs_gpios;
/* dmaengine data */
struct atmel_spi_dma dma;
bool keep_cs; bool keep_cs;
bool cs_active; bool cs_active;
...@@ -328,7 +311,7 @@ struct atmel_spi_device { ...@@ -328,7 +311,7 @@ struct atmel_spi_device {
u32 csr; u32 csr;
}; };
#define BUFFER_SIZE PAGE_SIZE #define SPI_MAX_DMA_XFER 65535 /* true for both PDC and DMA */
#define INVALID_DMA_ADDRESS 0xffffffff #define INVALID_DMA_ADDRESS 0xffffffff
/* /*
...@@ -458,10 +441,20 @@ static inline bool atmel_spi_use_dma(struct atmel_spi *as, ...@@ -458,10 +441,20 @@ static inline bool atmel_spi_use_dma(struct atmel_spi *as,
return as->use_dma && xfer->len >= DMA_MIN_BYTES; return as->use_dma && xfer->len >= DMA_MIN_BYTES;
} }
static bool atmel_spi_can_dma(struct spi_master *master,
struct spi_device *spi,
struct spi_transfer *xfer)
{
struct atmel_spi *as = spi_master_get_devdata(master);
return atmel_spi_use_dma(as, xfer);
}
static int atmel_spi_dma_slave_config(struct atmel_spi *as, static int atmel_spi_dma_slave_config(struct atmel_spi *as,
struct dma_slave_config *slave_config, struct dma_slave_config *slave_config,
u8 bits_per_word) u8 bits_per_word)
{ {
struct spi_master *master = platform_get_drvdata(as->pdev);
int err = 0; int err = 0;
if (bits_per_word > 8) { if (bits_per_word > 8) {
...@@ -493,7 +486,7 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as, ...@@ -493,7 +486,7 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as,
* path works the same whether FIFOs are available (and enabled) or not. * path works the same whether FIFOs are available (and enabled) or not.
*/ */
slave_config->direction = DMA_MEM_TO_DEV; slave_config->direction = DMA_MEM_TO_DEV;
if (dmaengine_slave_config(as->dma.chan_tx, slave_config)) { if (dmaengine_slave_config(master->dma_tx, slave_config)) {
dev_err(&as->pdev->dev, dev_err(&as->pdev->dev,
"failed to configure tx dma channel\n"); "failed to configure tx dma channel\n");
err = -EINVAL; err = -EINVAL;
...@@ -508,7 +501,7 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as, ...@@ -508,7 +501,7 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as,
* enabled) or not. * enabled) or not.
*/ */
slave_config->direction = DMA_DEV_TO_MEM; slave_config->direction = DMA_DEV_TO_MEM;
if (dmaengine_slave_config(as->dma.chan_rx, slave_config)) { if (dmaengine_slave_config(master->dma_rx, slave_config)) {
dev_err(&as->pdev->dev, dev_err(&as->pdev->dev,
"failed to configure rx dma channel\n"); "failed to configure rx dma channel\n");
err = -EINVAL; err = -EINVAL;
...@@ -517,7 +510,8 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as, ...@@ -517,7 +510,8 @@ static int atmel_spi_dma_slave_config(struct atmel_spi *as,
return err; return err;
} }
static int atmel_spi_configure_dma(struct atmel_spi *as) static int atmel_spi_configure_dma(struct spi_master *master,
struct atmel_spi *as)
{ {
struct dma_slave_config slave_config; struct dma_slave_config slave_config;
struct device *dev = &as->pdev->dev; struct device *dev = &as->pdev->dev;
...@@ -527,26 +521,26 @@ static int atmel_spi_configure_dma(struct atmel_spi *as) ...@@ -527,26 +521,26 @@ static int atmel_spi_configure_dma(struct atmel_spi *as)
dma_cap_zero(mask); dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask); dma_cap_set(DMA_SLAVE, mask);
as->dma.chan_tx = dma_request_slave_channel_reason(dev, "tx"); master->dma_tx = dma_request_slave_channel_reason(dev, "tx");
if (IS_ERR(as->dma.chan_tx)) { if (IS_ERR(master->dma_tx)) {
err = PTR_ERR(as->dma.chan_tx); err = PTR_ERR(master->dma_tx);
if (err == -EPROBE_DEFER) { if (err == -EPROBE_DEFER) {
dev_warn(dev, "no DMA channel available at the moment\n"); dev_warn(dev, "no DMA channel available at the moment\n");
return err; goto error_clear;
} }
dev_err(dev, dev_err(dev,
"DMA TX channel not available, SPI unable to use DMA\n"); "DMA TX channel not available, SPI unable to use DMA\n");
err = -EBUSY; err = -EBUSY;
goto error; goto error_clear;
} }
/* /*
* No reason to check EPROBE_DEFER here since we have already requested * No reason to check EPROBE_DEFER here since we have already requested
* tx channel. If it fails here, it's for another reason. * tx channel. If it fails here, it's for another reason.
*/ */
as->dma.chan_rx = dma_request_slave_channel(dev, "rx"); master->dma_rx = dma_request_slave_channel(dev, "rx");
if (!as->dma.chan_rx) { if (!master->dma_rx) {
dev_err(dev, dev_err(dev,
"DMA RX channel not available, SPI unable to use DMA\n"); "DMA RX channel not available, SPI unable to use DMA\n");
err = -EBUSY; err = -EBUSY;
...@@ -559,31 +553,38 @@ static int atmel_spi_configure_dma(struct atmel_spi *as) ...@@ -559,31 +553,38 @@ static int atmel_spi_configure_dma(struct atmel_spi *as)
dev_info(&as->pdev->dev, dev_info(&as->pdev->dev,
"Using %s (tx) and %s (rx) for DMA transfers\n", "Using %s (tx) and %s (rx) for DMA transfers\n",
dma_chan_name(as->dma.chan_tx), dma_chan_name(master->dma_tx),
dma_chan_name(as->dma.chan_rx)); dma_chan_name(master->dma_rx));
return 0; return 0;
error: error:
if (as->dma.chan_rx) if (master->dma_rx)
dma_release_channel(as->dma.chan_rx); dma_release_channel(master->dma_rx);
if (!IS_ERR(as->dma.chan_tx)) if (!IS_ERR(master->dma_tx))
dma_release_channel(as->dma.chan_tx); dma_release_channel(master->dma_tx);
error_clear:
master->dma_tx = master->dma_rx = NULL;
return err; return err;
} }
static void atmel_spi_stop_dma(struct atmel_spi *as) static void atmel_spi_stop_dma(struct spi_master *master)
{ {
if (as->dma.chan_rx) if (master->dma_rx)
dmaengine_terminate_all(as->dma.chan_rx); dmaengine_terminate_all(master->dma_rx);
if (as->dma.chan_tx) if (master->dma_tx)
dmaengine_terminate_all(as->dma.chan_tx); dmaengine_terminate_all(master->dma_tx);
} }
static void atmel_spi_release_dma(struct atmel_spi *as) static void atmel_spi_release_dma(struct spi_master *master)
{ {
if (as->dma.chan_rx) if (master->dma_rx) {
dma_release_channel(as->dma.chan_rx); dma_release_channel(master->dma_rx);
if (as->dma.chan_tx) master->dma_rx = NULL;
dma_release_channel(as->dma.chan_tx); }
if (master->dma_tx) {
dma_release_channel(master->dma_tx);
master->dma_tx = NULL;
}
} }
/* This function is called by the DMA driver from tasklet context */ /* This function is called by the DMA driver from tasklet context */
...@@ -613,14 +614,10 @@ static void atmel_spi_next_xfer_single(struct spi_master *master, ...@@ -613,14 +614,10 @@ static void atmel_spi_next_xfer_single(struct spi_master *master,
cpu_relax(); cpu_relax();
} }
if (xfer->tx_buf) { if (xfer->bits_per_word > 8)
if (xfer->bits_per_word > 8) spi_writel(as, TDR, *(u16 *)(xfer->tx_buf + xfer_pos));
spi_writel(as, TDR, *(u16 *)(xfer->tx_buf + xfer_pos)); else
else spi_writel(as, TDR, *(u8 *)(xfer->tx_buf + xfer_pos));
spi_writel(as, TDR, *(u8 *)(xfer->tx_buf + xfer_pos));
} else {
spi_writel(as, TDR, 0);
}
dev_dbg(master->dev.parent, dev_dbg(master->dev.parent,
" start pio xfer %p: len %u tx %p rx %p bitpw %d\n", " start pio xfer %p: len %u tx %p rx %p bitpw %d\n",
...@@ -667,17 +664,12 @@ static void atmel_spi_next_xfer_fifo(struct spi_master *master, ...@@ -667,17 +664,12 @@ static void atmel_spi_next_xfer_fifo(struct spi_master *master,
/* Fill TX FIFO */ /* Fill TX FIFO */
while (num_data >= 2) { while (num_data >= 2) {
if (xfer->tx_buf) { if (xfer->bits_per_word > 8) {
if (xfer->bits_per_word > 8) { td0 = *words++;
td0 = *words++; td1 = *words++;
td1 = *words++;
} else {
td0 = *bytes++;
td1 = *bytes++;
}
} else { } else {
td0 = 0; td0 = *bytes++;
td1 = 0; td1 = *bytes++;
} }
spi_writel(as, TDR, (td1 << 16) | td0); spi_writel(as, TDR, (td1 << 16) | td0);
...@@ -685,14 +677,10 @@ static void atmel_spi_next_xfer_fifo(struct spi_master *master, ...@@ -685,14 +677,10 @@ static void atmel_spi_next_xfer_fifo(struct spi_master *master,
} }
if (num_data) { if (num_data) {
if (xfer->tx_buf) { if (xfer->bits_per_word > 8)
if (xfer->bits_per_word > 8) td0 = *words++;
td0 = *words++; else
else td0 = *bytes++;
td0 = *bytes++;
} else {
td0 = 0;
}
spi_writew(as, TDR, td0); spi_writew(as, TDR, td0);
num_data--; num_data--;
...@@ -732,13 +720,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, ...@@ -732,13 +720,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
u32 *plen) u32 *plen)
{ {
struct atmel_spi *as = spi_master_get_devdata(master); struct atmel_spi *as = spi_master_get_devdata(master);
struct dma_chan *rxchan = as->dma.chan_rx; struct dma_chan *rxchan = master->dma_rx;
struct dma_chan *txchan = as->dma.chan_tx; struct dma_chan *txchan = master->dma_tx;
struct dma_async_tx_descriptor *rxdesc; struct dma_async_tx_descriptor *rxdesc;
struct dma_async_tx_descriptor *txdesc; struct dma_async_tx_descriptor *txdesc;
struct dma_slave_config slave_config; struct dma_slave_config slave_config;
dma_cookie_t cookie; dma_cookie_t cookie;
u32 len = *plen;
dev_vdbg(master->dev.parent, "atmel_spi_next_xfer_dma_submit\n"); dev_vdbg(master->dev.parent, "atmel_spi_next_xfer_dma_submit\n");
...@@ -749,44 +736,22 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, ...@@ -749,44 +736,22 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
/* release lock for DMA operations */ /* release lock for DMA operations */
atmel_spi_unlock(as); atmel_spi_unlock(as);
/* prepare the RX dma transfer */ *plen = xfer->len;
sg_init_table(&as->dma.sgrx, 1);
if (xfer->rx_buf) {
as->dma.sgrx.dma_address = xfer->rx_dma + xfer->len - *plen;
} else {
as->dma.sgrx.dma_address = as->buffer_dma;
if (len > BUFFER_SIZE)
len = BUFFER_SIZE;
}
/* prepare the TX dma transfer */
sg_init_table(&as->dma.sgtx, 1);
if (xfer->tx_buf) {
as->dma.sgtx.dma_address = xfer->tx_dma + xfer->len - *plen;
} else {
as->dma.sgtx.dma_address = as->buffer_dma;
if (len > BUFFER_SIZE)
len = BUFFER_SIZE;
memset(as->buffer, 0, len);
}
sg_dma_len(&as->dma.sgtx) = len;
sg_dma_len(&as->dma.sgrx) = len;
*plen = len;
if (atmel_spi_dma_slave_config(as, &slave_config, if (atmel_spi_dma_slave_config(as, &slave_config,
xfer->bits_per_word)) xfer->bits_per_word))
goto err_exit; goto err_exit;
/* Send both scatterlists */ /* Send both scatterlists */
rxdesc = dmaengine_prep_slave_sg(rxchan, &as->dma.sgrx, 1, rxdesc = dmaengine_prep_slave_sg(rxchan,
xfer->rx_sg.sgl, xfer->rx_sg.nents,
DMA_FROM_DEVICE, DMA_FROM_DEVICE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK); DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!rxdesc) if (!rxdesc)
goto err_dma; goto err_dma;
txdesc = dmaengine_prep_slave_sg(txchan, &as->dma.sgtx, 1, txdesc = dmaengine_prep_slave_sg(txchan,
xfer->tx_sg.sgl, xfer->tx_sg.nents,
DMA_TO_DEVICE, DMA_TO_DEVICE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK); DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!txdesc) if (!txdesc)
...@@ -820,7 +785,7 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, ...@@ -820,7 +785,7 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
err_dma: err_dma:
spi_writel(as, IDR, SPI_BIT(OVRES)); spi_writel(as, IDR, SPI_BIT(OVRES));
atmel_spi_stop_dma(as); atmel_spi_stop_dma(master);
err_exit: err_exit:
atmel_spi_lock(as); atmel_spi_lock(as);
return -ENOMEM; return -ENOMEM;
...@@ -832,30 +797,10 @@ static void atmel_spi_next_xfer_data(struct spi_master *master, ...@@ -832,30 +797,10 @@ static void atmel_spi_next_xfer_data(struct spi_master *master,
dma_addr_t *rx_dma, dma_addr_t *rx_dma,
u32 *plen) u32 *plen)
{ {
struct atmel_spi *as = spi_master_get_devdata(master); *rx_dma = xfer->rx_dma + xfer->len - *plen;
u32 len = *plen; *tx_dma = xfer->tx_dma + xfer->len - *plen;
if (*plen > master->max_dma_len)
/* use scratch buffer only when rx or tx data is unspecified */ *plen = master->max_dma_len;
if (xfer->rx_buf)
*rx_dma = xfer->rx_dma + xfer->len - *plen;
else {
*rx_dma = as->buffer_dma;
if (len > BUFFER_SIZE)
len = BUFFER_SIZE;
}
if (xfer->tx_buf)
*tx_dma = xfer->tx_dma + xfer->len - *plen;
else {
*tx_dma = as->buffer_dma;
if (len > BUFFER_SIZE)
len = BUFFER_SIZE;
memset(as->buffer, 0, len);
dma_sync_single_for_device(&as->pdev->dev,
as->buffer_dma, len, DMA_TO_DEVICE);
}
*plen = len;
} }
static int atmel_spi_set_xfer_speed(struct atmel_spi *as, static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
...@@ -1027,16 +972,12 @@ atmel_spi_pump_single_data(struct atmel_spi *as, struct spi_transfer *xfer) ...@@ -1027,16 +972,12 @@ atmel_spi_pump_single_data(struct atmel_spi *as, struct spi_transfer *xfer)
u16 *rxp16; u16 *rxp16;
unsigned long xfer_pos = xfer->len - as->current_remaining_bytes; unsigned long xfer_pos = xfer->len - as->current_remaining_bytes;
if (xfer->rx_buf) { if (xfer->bits_per_word > 8) {
if (xfer->bits_per_word > 8) { rxp16 = (u16 *)(((u8 *)xfer->rx_buf) + xfer_pos);
rxp16 = (u16 *)(((u8 *)xfer->rx_buf) + xfer_pos); *rxp16 = spi_readl(as, RDR);
*rxp16 = spi_readl(as, RDR);
} else {
rxp = ((u8 *)xfer->rx_buf) + xfer_pos;
*rxp = spi_readl(as, RDR);
}
} else { } else {
spi_readl(as, RDR); rxp = ((u8 *)xfer->rx_buf) + xfer_pos;
*rxp = spi_readl(as, RDR);
} }
if (xfer->bits_per_word > 8) { if (xfer->bits_per_word > 8) {
if (as->current_remaining_bytes > 2) if (as->current_remaining_bytes > 2)
...@@ -1075,12 +1016,10 @@ atmel_spi_pump_fifo_data(struct atmel_spi *as, struct spi_transfer *xfer) ...@@ -1075,12 +1016,10 @@ atmel_spi_pump_fifo_data(struct atmel_spi *as, struct spi_transfer *xfer)
/* Read data */ /* Read data */
while (num_data) { while (num_data) {
rd = spi_readl(as, RDR); rd = spi_readl(as, RDR);
if (xfer->rx_buf) { if (xfer->bits_per_word > 8)
if (xfer->bits_per_word > 8) *words++ = rd;
*words++ = rd; else
else *bytes++ = rd;
*bytes++ = rd;
}
num_data--; num_data--;
} }
} }
...@@ -1301,7 +1240,7 @@ static int atmel_spi_one_transfer(struct spi_master *master, ...@@ -1301,7 +1240,7 @@ static int atmel_spi_one_transfer(struct spi_master *master,
* better fault reporting. * better fault reporting.
*/ */
if ((!msg->is_dma_mapped) if ((!msg->is_dma_mapped)
&& (atmel_spi_use_dma(as, xfer) || as->use_pdc)) { && as->use_pdc) {
if (atmel_spi_dma_map_xfer(as, xfer) < 0) if (atmel_spi_dma_map_xfer(as, xfer) < 0)
return -ENOMEM; return -ENOMEM;
} }
...@@ -1374,11 +1313,11 @@ static int atmel_spi_one_transfer(struct spi_master *master, ...@@ -1374,11 +1313,11 @@ static int atmel_spi_one_transfer(struct spi_master *master,
spi_readl(as, SR); spi_readl(as, SR);
} else if (atmel_spi_use_dma(as, xfer)) { } else if (atmel_spi_use_dma(as, xfer)) {
atmel_spi_stop_dma(as); atmel_spi_stop_dma(master);
} }
if (!msg->is_dma_mapped if (!msg->is_dma_mapped
&& (atmel_spi_use_dma(as, xfer) || as->use_pdc)) && as->use_pdc)
atmel_spi_dma_unmap_xfer(master, xfer); atmel_spi_dma_unmap_xfer(master, xfer);
return 0; return 0;
...@@ -1389,7 +1328,7 @@ static int atmel_spi_one_transfer(struct spi_master *master, ...@@ -1389,7 +1328,7 @@ static int atmel_spi_one_transfer(struct spi_master *master,
} }
if (!msg->is_dma_mapped if (!msg->is_dma_mapped
&& (atmel_spi_use_dma(as, xfer) || as->use_pdc)) && as->use_pdc)
atmel_spi_dma_unmap_xfer(master, xfer); atmel_spi_dma_unmap_xfer(master, xfer);
if (xfer->delay_usecs) if (xfer->delay_usecs)
...@@ -1511,15 +1450,15 @@ static int atmel_spi_gpio_cs(struct platform_device *pdev) ...@@ -1511,15 +1450,15 @@ static int atmel_spi_gpio_cs(struct platform_device *pdev)
int cs_gpio = of_get_named_gpio(pdev->dev.of_node, int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
"cs-gpios", i); "cs-gpios", i);
if (cs_gpio == -EPROBE_DEFER) if (cs_gpio == -EPROBE_DEFER)
return cs_gpio; return cs_gpio;
if (gpio_is_valid(cs_gpio)) { if (gpio_is_valid(cs_gpio)) {
ret = devm_gpio_request(&pdev->dev, cs_gpio, ret = devm_gpio_request(&pdev->dev, cs_gpio,
dev_name(&pdev->dev)); dev_name(&pdev->dev));
if (ret) if (ret)
return ret; return ret;
} }
} }
return 0; return 0;
...@@ -1562,29 +1501,23 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1562,29 +1501,23 @@ static int atmel_spi_probe(struct platform_device *pdev)
master->bus_num = pdev->id; master->bus_num = pdev->id;
master->num_chipselect = master->dev.of_node ? 0 : 4; master->num_chipselect = master->dev.of_node ? 0 : 4;
master->setup = atmel_spi_setup; master->setup = atmel_spi_setup;
master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);
master->transfer_one_message = atmel_spi_transfer_one_message; master->transfer_one_message = atmel_spi_transfer_one_message;
master->cleanup = atmel_spi_cleanup; master->cleanup = atmel_spi_cleanup;
master->auto_runtime_pm = true; master->auto_runtime_pm = true;
master->max_dma_len = SPI_MAX_DMA_XFER;
master->can_dma = atmel_spi_can_dma;
platform_set_drvdata(pdev, master); platform_set_drvdata(pdev, master);
as = spi_master_get_devdata(master); as = spi_master_get_devdata(master);
/*
* Scratch buffer is used for throwaway rx and tx data.
* It's coherent to minimize dcache pollution.
*/
as->buffer = dma_alloc_coherent(&pdev->dev, BUFFER_SIZE,
&as->buffer_dma, GFP_KERNEL);
if (!as->buffer)
goto out_free;
spin_lock_init(&as->lock); spin_lock_init(&as->lock);
as->pdev = pdev; as->pdev = pdev;
as->regs = devm_ioremap_resource(&pdev->dev, regs); as->regs = devm_ioremap_resource(&pdev->dev, regs);
if (IS_ERR(as->regs)) { if (IS_ERR(as->regs)) {
ret = PTR_ERR(as->regs); ret = PTR_ERR(as->regs);
goto out_free_buffer; goto out_unmap_regs;
} }
as->phybase = regs->start; as->phybase = regs->start;
as->irq = irq; as->irq = irq;
...@@ -1609,11 +1542,12 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1609,11 +1542,12 @@ static int atmel_spi_probe(struct platform_device *pdev)
as->use_dma = false; as->use_dma = false;
as->use_pdc = false; as->use_pdc = false;
if (as->caps.has_dma_support) { if (as->caps.has_dma_support) {
ret = atmel_spi_configure_dma(as); ret = atmel_spi_configure_dma(master, as);
if (ret == 0) if (ret == 0) {
as->use_dma = true; as->use_dma = true;
else if (ret == -EPROBE_DEFER) } else if (ret == -EPROBE_DEFER) {
return ret; return ret;
}
} else { } else {
as->use_pdc = true; as->use_pdc = true;
} }
...@@ -1658,10 +1592,6 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1658,10 +1592,6 @@ static int atmel_spi_probe(struct platform_device *pdev)
spi_writel(as, CR, SPI_BIT(FIFOEN)); spi_writel(as, CR, SPI_BIT(FIFOEN));
} }
/* go! */
dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
(unsigned long)regs->start, irq);
pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT); pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_set_active(&pdev->dev); pm_runtime_set_active(&pdev->dev);
...@@ -1671,6 +1601,10 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1671,6 +1601,10 @@ static int atmel_spi_probe(struct platform_device *pdev)
if (ret) if (ret)
goto out_free_dma; goto out_free_dma;
/* go! */
dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
(unsigned long)regs->start, irq);
return 0; return 0;
out_free_dma: out_free_dma:
...@@ -1678,16 +1612,13 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1678,16 +1612,13 @@ static int atmel_spi_probe(struct platform_device *pdev)
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
if (as->use_dma) if (as->use_dma)
atmel_spi_release_dma(as); atmel_spi_release_dma(master);
spi_writel(as, CR, SPI_BIT(SWRST)); spi_writel(as, CR, SPI_BIT(SWRST));
spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
clk_disable_unprepare(clk); clk_disable_unprepare(clk);
out_free_irq: out_free_irq:
out_unmap_regs: out_unmap_regs:
out_free_buffer:
dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
as->buffer_dma);
out_free: out_free:
spi_master_put(master); spi_master_put(master);
return ret; return ret;
...@@ -1703,8 +1634,8 @@ static int atmel_spi_remove(struct platform_device *pdev) ...@@ -1703,8 +1634,8 @@ static int atmel_spi_remove(struct platform_device *pdev)
/* reset the hardware and block queue progress */ /* reset the hardware and block queue progress */
spin_lock_irq(&as->lock); spin_lock_irq(&as->lock);
if (as->use_dma) { if (as->use_dma) {
atmel_spi_stop_dma(as); atmel_spi_stop_dma(master);
atmel_spi_release_dma(as); atmel_spi_release_dma(master);
} }
spi_writel(as, CR, SPI_BIT(SWRST)); spi_writel(as, CR, SPI_BIT(SWRST));
...@@ -1712,9 +1643,6 @@ static int atmel_spi_remove(struct platform_device *pdev) ...@@ -1712,9 +1643,6 @@ static int atmel_spi_remove(struct platform_device *pdev)
spi_readl(as, SR); spi_readl(as, SR);
spin_unlock_irq(&as->lock); spin_unlock_irq(&as->lock);
dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
as->buffer_dma);
clk_disable_unprepare(as->clk); clk_disable_unprepare(as->clk);
pm_runtime_put_noidle(&pdev->dev); pm_runtime_put_noidle(&pdev->dev);
......
...@@ -574,6 +574,7 @@ static const struct of_device_id spi_engine_match_table[] = { ...@@ -574,6 +574,7 @@ static const struct of_device_id spi_engine_match_table[] = {
{ .compatible = "adi,axi-spi-engine-1.00.a" }, { .compatible = "adi,axi-spi-engine-1.00.a" },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, spi_engine_match_table);
static struct platform_driver spi_engine_driver = { static struct platform_driver spi_engine_driver = {
.probe = spi_engine_probe, .probe = spi_engine_probe,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册