aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-omap2-mcspi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-omap2-mcspi.c')
-rw-r--r--drivers/spi/spi-omap2-mcspi.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 893c3d78e426..86d2158946bb 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -285,8 +285,12 @@ static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
285 285
286 timeout = jiffies + msecs_to_jiffies(1000); 286 timeout = jiffies + msecs_to_jiffies(1000);
287 while (!(__raw_readl(reg) & bit)) { 287 while (!(__raw_readl(reg) & bit)) {
288 if (time_after(jiffies, timeout)) 288 if (time_after(jiffies, timeout)) {
289 return -1; 289 if (!(__raw_readl(reg) & bit))
290 return -ETIMEDOUT;
291 else
292 return 0;
293 }
290 cpu_relax(); 294 cpu_relax();
291 } 295 }
292 return 0; 296 return 0;
@@ -805,6 +809,10 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi,
805 return 0; 809 return 0;
806} 810}
807 811
812/*
813 * Note that we currently allow DMA only if we get a channel
814 * for both rx and tx. Otherwise we'll do PIO for both rx and tx.
815 */
808static int omap2_mcspi_request_dma(struct spi_device *spi) 816static int omap2_mcspi_request_dma(struct spi_device *spi)
809{ 817{
810 struct spi_master *master = spi->master; 818 struct spi_master *master = spi->master;
@@ -823,21 +831,22 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
823 dma_cap_set(DMA_SLAVE, mask); 831 dma_cap_set(DMA_SLAVE, mask);
824 sig = mcspi_dma->dma_rx_sync_dev; 832 sig = mcspi_dma->dma_rx_sync_dev;
825 mcspi_dma->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 833 mcspi_dma->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
826 if (!mcspi_dma->dma_rx) { 834 if (!mcspi_dma->dma_rx)
827 dev_err(&spi->dev, "no RX DMA engine channel for McSPI\n"); 835 goto no_dma;
828 return -EAGAIN;
829 }
830 836
831 sig = mcspi_dma->dma_tx_sync_dev; 837 sig = mcspi_dma->dma_tx_sync_dev;
832 mcspi_dma->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 838 mcspi_dma->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
833 if (!mcspi_dma->dma_tx) { 839 if (!mcspi_dma->dma_tx) {
834 dev_err(&spi->dev, "no TX DMA engine channel for McSPI\n");
835 dma_release_channel(mcspi_dma->dma_rx); 840 dma_release_channel(mcspi_dma->dma_rx);
836 mcspi_dma->dma_rx = NULL; 841 mcspi_dma->dma_rx = NULL;
837 return -EAGAIN; 842 goto no_dma;
838 } 843 }
839 844
840 return 0; 845 return 0;
846
847no_dma:
848 dev_warn(&spi->dev, "not using DMA for McSPI\n");
849 return -EAGAIN;
841} 850}
842 851
843static int omap2_mcspi_setup(struct spi_device *spi) 852static int omap2_mcspi_setup(struct spi_device *spi)
@@ -870,7 +879,7 @@ static int omap2_mcspi_setup(struct spi_device *spi)
870 879
871 if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) { 880 if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) {
872 ret = omap2_mcspi_request_dma(spi); 881 ret = omap2_mcspi_request_dma(spi);
873 if (ret < 0) 882 if (ret < 0 && ret != -EAGAIN)
874 return ret; 883 return ret;
875 } 884 }
876 885
@@ -928,6 +937,7 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
928 struct spi_device *spi; 937 struct spi_device *spi;
929 struct spi_transfer *t = NULL; 938 struct spi_transfer *t = NULL;
930 struct spi_master *master; 939 struct spi_master *master;
940 struct omap2_mcspi_dma *mcspi_dma;
931 int cs_active = 0; 941 int cs_active = 0;
932 struct omap2_mcspi_cs *cs; 942 struct omap2_mcspi_cs *cs;
933 struct omap2_mcspi_device_config *cd; 943 struct omap2_mcspi_device_config *cd;
@@ -937,6 +947,7 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
937 947
938 spi = m->spi; 948 spi = m->spi;
939 master = spi->master; 949 master = spi->master;
950 mcspi_dma = mcspi->dma_channels + spi->chip_select;
940 cs = spi->controller_state; 951 cs = spi->controller_state;
941 cd = spi->controller_data; 952 cd = spi->controller_data;
942 953
@@ -993,7 +1004,8 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
993 __raw_writel(0, cs->base 1004 __raw_writel(0, cs->base
994 + OMAP2_MCSPI_TX0); 1005 + OMAP2_MCSPI_TX0);
995 1006
996 if (m->is_dma_mapped || t->len >= DMA_MIN_BYTES) 1007 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
1008 (m->is_dma_mapped || t->len >= DMA_MIN_BYTES))
997 count = omap2_mcspi_txrx_dma(spi, t); 1009 count = omap2_mcspi_txrx_dma(spi, t);
998 else 1010 else
999 count = omap2_mcspi_txrx_pio(spi, t); 1011 count = omap2_mcspi_txrx_pio(spi, t);
@@ -1040,10 +1052,14 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
1040static int omap2_mcspi_transfer_one_message(struct spi_master *master, 1052static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1041 struct spi_message *m) 1053 struct spi_message *m)
1042{ 1054{
1055 struct spi_device *spi;
1043 struct omap2_mcspi *mcspi; 1056 struct omap2_mcspi *mcspi;
1057 struct omap2_mcspi_dma *mcspi_dma;
1044 struct spi_transfer *t; 1058 struct spi_transfer *t;
1045 1059
1060 spi = m->spi;
1046 mcspi = spi_master_get_devdata(master); 1061 mcspi = spi_master_get_devdata(master);
1062 mcspi_dma = mcspi->dma_channels + spi->chip_select;
1047 m->actual_length = 0; 1063 m->actual_length = 0;
1048 m->status = 0; 1064 m->status = 0;
1049 1065
@@ -1078,7 +1094,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1078 if (m->is_dma_mapped || len < DMA_MIN_BYTES) 1094 if (m->is_dma_mapped || len < DMA_MIN_BYTES)
1079 continue; 1095 continue;
1080 1096
1081 if (tx_buf != NULL) { 1097 if (mcspi_dma->dma_tx && tx_buf != NULL) {
1082 t->tx_dma = dma_map_single(mcspi->dev, (void *) tx_buf, 1098 t->tx_dma = dma_map_single(mcspi->dev, (void *) tx_buf,
1083 len, DMA_TO_DEVICE); 1099 len, DMA_TO_DEVICE);
1084 if (dma_mapping_error(mcspi->dev, t->tx_dma)) { 1100 if (dma_mapping_error(mcspi->dev, t->tx_dma)) {
@@ -1087,7 +1103,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1087 return -EINVAL; 1103 return -EINVAL;
1088 } 1104 }
1089 } 1105 }
1090 if (rx_buf != NULL) { 1106 if (mcspi_dma->dma_rx && rx_buf != NULL) {
1091 t->rx_dma = dma_map_single(mcspi->dev, rx_buf, t->len, 1107 t->rx_dma = dma_map_single(mcspi->dev, rx_buf, t->len,
1092 DMA_FROM_DEVICE); 1108 DMA_FROM_DEVICE);
1093 if (dma_mapping_error(mcspi->dev, t->rx_dma)) { 1109 if (dma_mapping_error(mcspi->dev, t->rx_dma)) {
@@ -1277,7 +1293,8 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
1277 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); 1293 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
1278 pm_runtime_enable(&pdev->dev); 1294 pm_runtime_enable(&pdev->dev);
1279 1295
1280 if (status || omap2_mcspi_master_setup(mcspi) < 0) 1296 status = omap2_mcspi_master_setup(mcspi);
1297 if (status < 0)
1281 goto disable_pm; 1298 goto disable_pm;
1282 1299
1283 status = spi_register_master(master); 1300 status = spi_register_master(master);