aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/Kconfig16
-rw-r--r--drivers/spi/Makefile1
-rw-r--r--drivers/spi/amba-pl022.c2
-rw-r--r--drivers/spi/davinci_spi.c11
-rw-r--r--drivers/spi/omap2_mcspi.c222
-rw-r--r--drivers/spi/ti-ssp-spi.c402
6 files changed, 488 insertions, 166 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index cdeb01f45bc2..fc14b8dea0d7 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -167,13 +167,13 @@ config SPI_IMX_VER_0_0
167 def_bool y if SOC_IMX21 || SOC_IMX27 167 def_bool y if SOC_IMX21 || SOC_IMX27
168 168
169config SPI_IMX_VER_0_4 169config SPI_IMX_VER_0_4
170 def_bool y if ARCH_MX31 170 def_bool y if SOC_IMX31
171 171
172config SPI_IMX_VER_0_7 172config SPI_IMX_VER_0_7
173 def_bool y if ARCH_MX25 || ARCH_MX35 || ARCH_MX51 || ARCH_MX53 173 def_bool y if ARCH_MX25 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
174 174
175config SPI_IMX_VER_2_3 175config SPI_IMX_VER_2_3
176 def_bool y if ARCH_MX51 || ARCH_MX53 176 def_bool y if SOC_IMX51 || SOC_IMX53
177 177
178config SPI_IMX 178config SPI_IMX
179 tristate "Freescale i.MX SPI controllers" 179 tristate "Freescale i.MX SPI controllers"
@@ -369,6 +369,16 @@ config SPI_TEGRA
369 help 369 help
370 SPI driver for NVidia Tegra SoCs 370 SPI driver for NVidia Tegra SoCs
371 371
372config SPI_TI_SSP
373 tristate "TI Sequencer Serial Port - SPI Support"
374 depends on MFD_TI_SSP
375 help
376 This selects an SPI master implementation using a TI sequencer
377 serial port.
378
379 To compile this driver as a module, choose M here: the
380 module will be called ti-ssp-spi.
381
372config SPI_TOPCLIFF_PCH 382config SPI_TOPCLIFF_PCH
373 tristate "Topcliff PCH SPI Controller" 383 tristate "Topcliff PCH SPI Controller"
374 depends on PCI 384 depends on PCI
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 8b5a315045a6..fd2fc5f6505f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
45obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx_hw.o 45obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx_hw.o
46obj-$(CONFIG_SPI_S3C64XX) += spi_s3c64xx.o 46obj-$(CONFIG_SPI_S3C64XX) += spi_s3c64xx.o
47obj-$(CONFIG_SPI_TEGRA) += spi_tegra.o 47obj-$(CONFIG_SPI_TEGRA) += spi_tegra.o
48obj-$(CONFIG_SPI_TI_SSP) += ti-ssp-spi.o
48obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi_topcliff_pch.o 49obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi_topcliff_pch.o
49obj-$(CONFIG_SPI_TXX9) += spi_txx9.o 50obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
50obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o 51obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index 14a451b2ad63..5c2b092a915e 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -2020,7 +2020,7 @@ static void pl022_cleanup(struct spi_device *spi)
2020 2020
2021 2021
2022static int __devinit 2022static int __devinit
2023pl022_probe(struct amba_device *adev, struct amba_id *id) 2023pl022_probe(struct amba_device *adev, const struct amba_id *id)
2024{ 2024{
2025 struct device *dev = &adev->dev; 2025 struct device *dev = &adev->dev;
2026 struct pl022_ssp_controller *platform_info = adev->dev.platform_data; 2026 struct pl022_ssp_controller *platform_info = adev->dev.platform_data;
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
index e90c2d6a84b3..1f0ed8005c91 100644
--- a/drivers/spi/davinci_spi.c
+++ b/drivers/spi/davinci_spi.c
@@ -807,7 +807,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
807 struct resource *r, *mem; 807 struct resource *r, *mem;
808 resource_size_t dma_rx_chan = SPI_NO_RESOURCE; 808 resource_size_t dma_rx_chan = SPI_NO_RESOURCE;
809 resource_size_t dma_tx_chan = SPI_NO_RESOURCE; 809 resource_size_t dma_tx_chan = SPI_NO_RESOURCE;
810 resource_size_t dma_eventq = SPI_NO_RESOURCE;
811 int i = 0, ret = 0; 810 int i = 0, ret = 0;
812 u32 spipc0; 811 u32 spipc0;
813 812
@@ -895,17 +894,13 @@ static int davinci_spi_probe(struct platform_device *pdev)
895 r = platform_get_resource(pdev, IORESOURCE_DMA, 1); 894 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
896 if (r) 895 if (r)
897 dma_tx_chan = r->start; 896 dma_tx_chan = r->start;
898 r = platform_get_resource(pdev, IORESOURCE_DMA, 2);
899 if (r)
900 dma_eventq = r->start;
901 897
902 dspi->bitbang.txrx_bufs = davinci_spi_bufs; 898 dspi->bitbang.txrx_bufs = davinci_spi_bufs;
903 if (dma_rx_chan != SPI_NO_RESOURCE && 899 if (dma_rx_chan != SPI_NO_RESOURCE &&
904 dma_tx_chan != SPI_NO_RESOURCE && 900 dma_tx_chan != SPI_NO_RESOURCE) {
905 dma_eventq != SPI_NO_RESOURCE) {
906 dspi->dma.rx_channel = dma_rx_chan; 901 dspi->dma.rx_channel = dma_rx_chan;
907 dspi->dma.tx_channel = dma_tx_chan; 902 dspi->dma.tx_channel = dma_tx_chan;
908 dspi->dma.eventq = dma_eventq; 903 dspi->dma.eventq = pdata->dma_event_q;
909 904
910 ret = davinci_spi_request_dma(dspi); 905 ret = davinci_spi_request_dma(dspi);
911 if (ret) 906 if (ret)
@@ -914,7 +909,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
914 dev_info(&pdev->dev, "DMA: supported\n"); 909 dev_info(&pdev->dev, "DMA: supported\n");
915 dev_info(&pdev->dev, "DMA: RX channel: %d, TX channel: %d, " 910 dev_info(&pdev->dev, "DMA: RX channel: %d, TX channel: %d, "
916 "event queue: %d\n", dma_rx_chan, dma_tx_chan, 911 "event queue: %d\n", dma_rx_chan, dma_tx_chan,
917 dma_eventq); 912 pdata->dma_event_q);
918 } 913 }
919 914
920 dspi->get_rx = davinci_spi_rx_buf_u8; 915 dspi->get_rx = davinci_spi_rx_buf_u8;
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index 6a982a25b7c3..3a5ed06d3d2f 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2005, 2006 Nokia Corporation 4 * Copyright (C) 2005, 2006 Nokia Corporation
5 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and 5 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
6 * Juha Yrjölä <juha.yrjola@nokia.com> 6 * Juha Yrj�l� <juha.yrjola@nokia.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@
33#include <linux/clk.h> 33#include <linux/clk.h>
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/pm_runtime.h>
36 37
37#include <linux/spi/spi.h> 38#include <linux/spi/spi.h>
38 39
@@ -46,7 +47,6 @@
46#define OMAP2_MCSPI_MAX_CTRL 4 47#define OMAP2_MCSPI_MAX_CTRL 4
47 48
48#define OMAP2_MCSPI_REVISION 0x00 49#define OMAP2_MCSPI_REVISION 0x00
49#define OMAP2_MCSPI_SYSCONFIG 0x10
50#define OMAP2_MCSPI_SYSSTATUS 0x14 50#define OMAP2_MCSPI_SYSSTATUS 0x14
51#define OMAP2_MCSPI_IRQSTATUS 0x18 51#define OMAP2_MCSPI_IRQSTATUS 0x18
52#define OMAP2_MCSPI_IRQENABLE 0x1c 52#define OMAP2_MCSPI_IRQENABLE 0x1c
@@ -63,13 +63,6 @@
63 63
64/* per-register bitmasks: */ 64/* per-register bitmasks: */
65 65
66#define OMAP2_MCSPI_SYSCONFIG_SMARTIDLE BIT(4)
67#define OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP BIT(2)
68#define OMAP2_MCSPI_SYSCONFIG_AUTOIDLE BIT(0)
69#define OMAP2_MCSPI_SYSCONFIG_SOFTRESET BIT(1)
70
71#define OMAP2_MCSPI_SYSSTATUS_RESETDONE BIT(0)
72
73#define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0) 66#define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0)
74#define OMAP2_MCSPI_MODULCTRL_MS BIT(2) 67#define OMAP2_MCSPI_MODULCTRL_MS BIT(2)
75#define OMAP2_MCSPI_MODULCTRL_STEST BIT(3) 68#define OMAP2_MCSPI_MODULCTRL_STEST BIT(3)
@@ -122,13 +115,12 @@ struct omap2_mcspi {
122 spinlock_t lock; 115 spinlock_t lock;
123 struct list_head msg_queue; 116 struct list_head msg_queue;
124 struct spi_master *master; 117 struct spi_master *master;
125 struct clk *ick;
126 struct clk *fck;
127 /* Virtual base address of the controller */ 118 /* Virtual base address of the controller */
128 void __iomem *base; 119 void __iomem *base;
129 unsigned long phys; 120 unsigned long phys;
130 /* SPI1 has 4 channels, while SPI2 has 2 */ 121 /* SPI1 has 4 channels, while SPI2 has 2 */
131 struct omap2_mcspi_dma *dma_channels; 122 struct omap2_mcspi_dma *dma_channels;
123 struct device *dev;
132}; 124};
133 125
134struct omap2_mcspi_cs { 126struct omap2_mcspi_cs {
@@ -144,7 +136,6 @@ struct omap2_mcspi_cs {
144 * corresponding registers are modified. 136 * corresponding registers are modified.
145 */ 137 */
146struct omap2_mcspi_regs { 138struct omap2_mcspi_regs {
147 u32 sysconfig;
148 u32 modulctrl; 139 u32 modulctrl;
149 u32 wakeupenable; 140 u32 wakeupenable;
150 struct list_head cs; 141 struct list_head cs;
@@ -268,9 +259,6 @@ static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
268 mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL, 259 mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL,
269 omap2_mcspi_ctx[spi_cntrl->bus_num - 1].modulctrl); 260 omap2_mcspi_ctx[spi_cntrl->bus_num - 1].modulctrl);
270 261
271 mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_SYSCONFIG,
272 omap2_mcspi_ctx[spi_cntrl->bus_num - 1].sysconfig);
273
274 mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE, 262 mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE,
275 omap2_mcspi_ctx[spi_cntrl->bus_num - 1].wakeupenable); 263 omap2_mcspi_ctx[spi_cntrl->bus_num - 1].wakeupenable);
276 264
@@ -280,20 +268,12 @@ static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
280} 268}
281static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi) 269static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi)
282{ 270{
283 clk_disable(mcspi->ick); 271 pm_runtime_put_sync(mcspi->dev);
284 clk_disable(mcspi->fck);
285} 272}
286 273
287static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi) 274static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi)
288{ 275{
289 if (clk_enable(mcspi->ick)) 276 return pm_runtime_get_sync(mcspi->dev);
290 return -ENODEV;
291 if (clk_enable(mcspi->fck))
292 return -ENODEV;
293
294 omap2_mcspi_restore_ctx(mcspi);
295
296 return 0;
297} 277}
298 278
299static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) 279static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
@@ -829,8 +809,9 @@ static int omap2_mcspi_setup(struct spi_device *spi)
829 return ret; 809 return ret;
830 } 810 }
831 811
832 if (omap2_mcspi_enable_clocks(mcspi)) 812 ret = omap2_mcspi_enable_clocks(mcspi);
833 return -ENODEV; 813 if (ret < 0)
814 return ret;
834 815
835 ret = omap2_mcspi_setup_transfer(spi, NULL); 816 ret = omap2_mcspi_setup_transfer(spi, NULL);
836 omap2_mcspi_disable_clocks(mcspi); 817 omap2_mcspi_disable_clocks(mcspi);
@@ -873,10 +854,11 @@ static void omap2_mcspi_work(struct work_struct *work)
873 struct omap2_mcspi *mcspi; 854 struct omap2_mcspi *mcspi;
874 855
875 mcspi = container_of(work, struct omap2_mcspi, work); 856 mcspi = container_of(work, struct omap2_mcspi, work);
876 spin_lock_irq(&mcspi->lock);
877 857
878 if (omap2_mcspi_enable_clocks(mcspi)) 858 if (omap2_mcspi_enable_clocks(mcspi) < 0)
879 goto out; 859 return;
860
861 spin_lock_irq(&mcspi->lock);
880 862
881 /* We only enable one channel at a time -- the one whose message is 863 /* We only enable one channel at a time -- the one whose message is
882 * at the head of the queue -- although this controller would gladly 864 * at the head of the queue -- although this controller would gladly
@@ -989,10 +971,9 @@ static void omap2_mcspi_work(struct work_struct *work)
989 spin_lock_irq(&mcspi->lock); 971 spin_lock_irq(&mcspi->lock);
990 } 972 }
991 973
992 omap2_mcspi_disable_clocks(mcspi);
993
994out:
995 spin_unlock_irq(&mcspi->lock); 974 spin_unlock_irq(&mcspi->lock);
975
976 omap2_mcspi_disable_clocks(mcspi);
996} 977}
997 978
998static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m) 979static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
@@ -1068,25 +1049,15 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
1068 return 0; 1049 return 0;
1069} 1050}
1070 1051
1071static int __init omap2_mcspi_reset(struct omap2_mcspi *mcspi) 1052static int __init omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
1072{ 1053{
1073 struct spi_master *master = mcspi->master; 1054 struct spi_master *master = mcspi->master;
1074 u32 tmp; 1055 u32 tmp;
1056 int ret = 0;
1075 1057
1076 if (omap2_mcspi_enable_clocks(mcspi)) 1058 ret = omap2_mcspi_enable_clocks(mcspi);
1077 return -1; 1059 if (ret < 0)
1078 1060 return ret;
1079 mcspi_write_reg(master, OMAP2_MCSPI_SYSCONFIG,
1080 OMAP2_MCSPI_SYSCONFIG_SOFTRESET);
1081 do {
1082 tmp = mcspi_read_reg(master, OMAP2_MCSPI_SYSSTATUS);
1083 } while (!(tmp & OMAP2_MCSPI_SYSSTATUS_RESETDONE));
1084
1085 tmp = OMAP2_MCSPI_SYSCONFIG_AUTOIDLE |
1086 OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP |
1087 OMAP2_MCSPI_SYSCONFIG_SMARTIDLE;
1088 mcspi_write_reg(master, OMAP2_MCSPI_SYSCONFIG, tmp);
1089 omap2_mcspi_ctx[master->bus_num - 1].sysconfig = tmp;
1090 1061
1091 tmp = OMAP2_MCSPI_WAKEUPENABLE_WKEN; 1062 tmp = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
1092 mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, tmp); 1063 mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, tmp);
@@ -1097,91 +1068,26 @@ static int __init omap2_mcspi_reset(struct omap2_mcspi *mcspi)
1097 return 0; 1068 return 0;
1098} 1069}
1099 1070
1100static u8 __initdata spi1_rxdma_id [] = { 1071static int omap_mcspi_runtime_resume(struct device *dev)
1101 OMAP24XX_DMA_SPI1_RX0, 1072{
1102 OMAP24XX_DMA_SPI1_RX1, 1073 struct omap2_mcspi *mcspi;
1103 OMAP24XX_DMA_SPI1_RX2, 1074 struct spi_master *master;
1104 OMAP24XX_DMA_SPI1_RX3,
1105};
1106
1107static u8 __initdata spi1_txdma_id [] = {
1108 OMAP24XX_DMA_SPI1_TX0,
1109 OMAP24XX_DMA_SPI1_TX1,
1110 OMAP24XX_DMA_SPI1_TX2,
1111 OMAP24XX_DMA_SPI1_TX3,
1112};
1113
1114static u8 __initdata spi2_rxdma_id[] = {
1115 OMAP24XX_DMA_SPI2_RX0,
1116 OMAP24XX_DMA_SPI2_RX1,
1117};
1118
1119static u8 __initdata spi2_txdma_id[] = {
1120 OMAP24XX_DMA_SPI2_TX0,
1121 OMAP24XX_DMA_SPI2_TX1,
1122};
1123
1124#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
1125 || defined(CONFIG_ARCH_OMAP4)
1126static u8 __initdata spi3_rxdma_id[] = {
1127 OMAP24XX_DMA_SPI3_RX0,
1128 OMAP24XX_DMA_SPI3_RX1,
1129};
1130 1075
1131static u8 __initdata spi3_txdma_id[] = { 1076 master = dev_get_drvdata(dev);
1132 OMAP24XX_DMA_SPI3_TX0, 1077 mcspi = spi_master_get_devdata(master);
1133 OMAP24XX_DMA_SPI3_TX1, 1078 omap2_mcspi_restore_ctx(mcspi);
1134};
1135#endif
1136 1079
1137#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) 1080 return 0;
1138static u8 __initdata spi4_rxdma_id[] = { 1081}
1139 OMAP34XX_DMA_SPI4_RX0,
1140};
1141 1082
1142static u8 __initdata spi4_txdma_id[] = {
1143 OMAP34XX_DMA_SPI4_TX0,
1144};
1145#endif
1146 1083
1147static int __init omap2_mcspi_probe(struct platform_device *pdev) 1084static int __init omap2_mcspi_probe(struct platform_device *pdev)
1148{ 1085{
1149 struct spi_master *master; 1086 struct spi_master *master;
1087 struct omap2_mcspi_platform_config *pdata = pdev->dev.platform_data;
1150 struct omap2_mcspi *mcspi; 1088 struct omap2_mcspi *mcspi;
1151 struct resource *r; 1089 struct resource *r;
1152 int status = 0, i; 1090 int status = 0, i;
1153 const u8 *rxdma_id, *txdma_id;
1154 unsigned num_chipselect;
1155
1156 switch (pdev->id) {
1157 case 1:
1158 rxdma_id = spi1_rxdma_id;
1159 txdma_id = spi1_txdma_id;
1160 num_chipselect = 4;
1161 break;
1162 case 2:
1163 rxdma_id = spi2_rxdma_id;
1164 txdma_id = spi2_txdma_id;
1165 num_chipselect = 2;
1166 break;
1167#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
1168 || defined(CONFIG_ARCH_OMAP4)
1169 case 3:
1170 rxdma_id = spi3_rxdma_id;
1171 txdma_id = spi3_txdma_id;
1172 num_chipselect = 2;
1173 break;
1174#endif
1175#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1176 case 4:
1177 rxdma_id = spi4_rxdma_id;
1178 txdma_id = spi4_txdma_id;
1179 num_chipselect = 1;
1180 break;
1181#endif
1182 default:
1183 return -EINVAL;
1184 }
1185 1091
1186 master = spi_alloc_master(&pdev->dev, sizeof *mcspi); 1092 master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
1187 if (master == NULL) { 1093 if (master == NULL) {
@@ -1198,7 +1104,7 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1198 master->setup = omap2_mcspi_setup; 1104 master->setup = omap2_mcspi_setup;
1199 master->transfer = omap2_mcspi_transfer; 1105 master->transfer = omap2_mcspi_transfer;
1200 master->cleanup = omap2_mcspi_cleanup; 1106 master->cleanup = omap2_mcspi_cleanup;
1201 master->num_chipselect = num_chipselect; 1107 master->num_chipselect = pdata->num_cs;
1202 1108
1203 dev_set_drvdata(&pdev->dev, master); 1109 dev_set_drvdata(&pdev->dev, master);
1204 1110
@@ -1216,49 +1122,62 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1216 goto err1; 1122 goto err1;
1217 } 1123 }
1218 1124
1125 r->start += pdata->regs_offset;
1126 r->end += pdata->regs_offset;
1219 mcspi->phys = r->start; 1127 mcspi->phys = r->start;
1220 mcspi->base = ioremap(r->start, r->end - r->start + 1); 1128 mcspi->base = ioremap(r->start, r->end - r->start + 1);
1221 if (!mcspi->base) { 1129 if (!mcspi->base) {
1222 dev_dbg(&pdev->dev, "can't ioremap MCSPI\n"); 1130 dev_dbg(&pdev->dev, "can't ioremap MCSPI\n");
1223 status = -ENOMEM; 1131 status = -ENOMEM;
1224 goto err1aa; 1132 goto err2;
1225 } 1133 }
1226 1134
1135 mcspi->dev = &pdev->dev;
1227 INIT_WORK(&mcspi->work, omap2_mcspi_work); 1136 INIT_WORK(&mcspi->work, omap2_mcspi_work);
1228 1137
1229 spin_lock_init(&mcspi->lock); 1138 spin_lock_init(&mcspi->lock);
1230 INIT_LIST_HEAD(&mcspi->msg_queue); 1139 INIT_LIST_HEAD(&mcspi->msg_queue);
1231 INIT_LIST_HEAD(&omap2_mcspi_ctx[master->bus_num - 1].cs); 1140 INIT_LIST_HEAD(&omap2_mcspi_ctx[master->bus_num - 1].cs);
1232 1141
1233 mcspi->ick = clk_get(&pdev->dev, "ick");
1234 if (IS_ERR(mcspi->ick)) {
1235 dev_dbg(&pdev->dev, "can't get mcspi_ick\n");
1236 status = PTR_ERR(mcspi->ick);
1237 goto err1a;
1238 }
1239 mcspi->fck = clk_get(&pdev->dev, "fck");
1240 if (IS_ERR(mcspi->fck)) {
1241 dev_dbg(&pdev->dev, "can't get mcspi_fck\n");
1242 status = PTR_ERR(mcspi->fck);
1243 goto err2;
1244 }
1245
1246 mcspi->dma_channels = kcalloc(master->num_chipselect, 1142 mcspi->dma_channels = kcalloc(master->num_chipselect,
1247 sizeof(struct omap2_mcspi_dma), 1143 sizeof(struct omap2_mcspi_dma),
1248 GFP_KERNEL); 1144 GFP_KERNEL);
1249 1145
1250 if (mcspi->dma_channels == NULL) 1146 if (mcspi->dma_channels == NULL)
1251 goto err3; 1147 goto err2;
1148
1149 for (i = 0; i < master->num_chipselect; i++) {
1150 char dma_ch_name[14];
1151 struct resource *dma_res;
1152
1153 sprintf(dma_ch_name, "rx%d", i);
1154 dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA,
1155 dma_ch_name);
1156 if (!dma_res) {
1157 dev_dbg(&pdev->dev, "cannot get DMA RX channel\n");
1158 status = -ENODEV;
1159 break;
1160 }
1252 1161
1253 for (i = 0; i < num_chipselect; i++) {
1254 mcspi->dma_channels[i].dma_rx_channel = -1; 1162 mcspi->dma_channels[i].dma_rx_channel = -1;
1255 mcspi->dma_channels[i].dma_rx_sync_dev = rxdma_id[i]; 1163 mcspi->dma_channels[i].dma_rx_sync_dev = dma_res->start;
1164 sprintf(dma_ch_name, "tx%d", i);
1165 dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA,
1166 dma_ch_name);
1167 if (!dma_res) {
1168 dev_dbg(&pdev->dev, "cannot get DMA TX channel\n");
1169 status = -ENODEV;
1170 break;
1171 }
1172
1256 mcspi->dma_channels[i].dma_tx_channel = -1; 1173 mcspi->dma_channels[i].dma_tx_channel = -1;
1257 mcspi->dma_channels[i].dma_tx_sync_dev = txdma_id[i]; 1174 mcspi->dma_channels[i].dma_tx_sync_dev = dma_res->start;
1258 } 1175 }
1259 1176
1260 if (omap2_mcspi_reset(mcspi) < 0) 1177 pm_runtime_enable(&pdev->dev);
1261 goto err4; 1178
1179 if (status || omap2_mcspi_master_setup(mcspi) < 0)
1180 goto err3;
1262 1181
1263 status = spi_register_master(master); 1182 status = spi_register_master(master);
1264 if (status < 0) 1183 if (status < 0)
@@ -1267,17 +1186,13 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1267 return status; 1186 return status;
1268 1187
1269err4: 1188err4:
1270 kfree(mcspi->dma_channels); 1189 spi_master_put(master);
1271err3: 1190err3:
1272 clk_put(mcspi->fck); 1191 kfree(mcspi->dma_channels);
1273err2: 1192err2:
1274 clk_put(mcspi->ick);
1275err1a:
1276 iounmap(mcspi->base);
1277err1aa:
1278 release_mem_region(r->start, (r->end - r->start) + 1); 1193 release_mem_region(r->start, (r->end - r->start) + 1);
1194 iounmap(mcspi->base);
1279err1: 1195err1:
1280 spi_master_put(master);
1281 return status; 1196 return status;
1282} 1197}
1283 1198
@@ -1293,9 +1208,7 @@ static int __exit omap2_mcspi_remove(struct platform_device *pdev)
1293 mcspi = spi_master_get_devdata(master); 1208 mcspi = spi_master_get_devdata(master);
1294 dma_channels = mcspi->dma_channels; 1209 dma_channels = mcspi->dma_channels;
1295 1210
1296 clk_put(mcspi->fck); 1211 omap2_mcspi_disable_clocks(mcspi);
1297 clk_put(mcspi->ick);
1298
1299 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1212 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1300 release_mem_region(r->start, (r->end - r->start) + 1); 1213 release_mem_region(r->start, (r->end - r->start) + 1);
1301 1214
@@ -1346,6 +1259,7 @@ static int omap2_mcspi_resume(struct device *dev)
1346 1259
1347static const struct dev_pm_ops omap2_mcspi_pm_ops = { 1260static const struct dev_pm_ops omap2_mcspi_pm_ops = {
1348 .resume = omap2_mcspi_resume, 1261 .resume = omap2_mcspi_resume,
1262 .runtime_resume = omap_mcspi_runtime_resume,
1349}; 1263};
1350 1264
1351static struct platform_driver omap2_mcspi_driver = { 1265static struct platform_driver omap2_mcspi_driver = {
diff --git a/drivers/spi/ti-ssp-spi.c b/drivers/spi/ti-ssp-spi.c
new file mode 100644
index 000000000000..ee22795c7973
--- /dev/null
+++ b/drivers/spi/ti-ssp-spi.c
@@ -0,0 +1,402 @@
1/*
2 * Sequencer Serial Port (SSP) based SPI master driver
3 *
4 * Copyright (C) 2010 Texas Instruments Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/err.h>
23#include <linux/completion.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h>
26#include <linux/spi/spi.h>
27#include <linux/mfd/ti_ssp.h>
28
29#define MODE_BITS (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH)
30
31struct ti_ssp_spi {
32 struct spi_master *master;
33 struct device *dev;
34 spinlock_t lock;
35 struct list_head msg_queue;
36 struct completion complete;
37 bool shutdown;
38 struct workqueue_struct *workqueue;
39 struct work_struct work;
40 u8 mode, bpw;
41 int cs_active;
42 u32 pc_en, pc_dis, pc_wr, pc_rd;
43 void (*select)(int cs);
44};
45
46static u32 ti_ssp_spi_rx(struct ti_ssp_spi *hw)
47{
48 u32 ret;
49
50 ti_ssp_run(hw->dev, hw->pc_rd, 0, &ret);
51 return ret;
52}
53
54static void ti_ssp_spi_tx(struct ti_ssp_spi *hw, u32 data)
55{
56 ti_ssp_run(hw->dev, hw->pc_wr, data << (32 - hw->bpw), NULL);
57}
58
59static int ti_ssp_spi_txrx(struct ti_ssp_spi *hw, struct spi_message *msg,
60 struct spi_transfer *t)
61{
62 int count;
63
64 if (hw->bpw <= 8) {
65 u8 *rx = t->rx_buf;
66 const u8 *tx = t->tx_buf;
67
68 for (count = 0; count < t->len; count += 1) {
69 if (t->tx_buf)
70 ti_ssp_spi_tx(hw, *tx++);
71 if (t->rx_buf)
72 *rx++ = ti_ssp_spi_rx(hw);
73 }
74 } else if (hw->bpw <= 16) {
75 u16 *rx = t->rx_buf;
76 const u16 *tx = t->tx_buf;
77
78 for (count = 0; count < t->len; count += 2) {
79 if (t->tx_buf)
80 ti_ssp_spi_tx(hw, *tx++);
81 if (t->rx_buf)
82 *rx++ = ti_ssp_spi_rx(hw);
83 }
84 } else {
85 u32 *rx = t->rx_buf;
86 const u32 *tx = t->tx_buf;
87
88 for (count = 0; count < t->len; count += 4) {
89 if (t->tx_buf)
90 ti_ssp_spi_tx(hw, *tx++);
91 if (t->rx_buf)
92 *rx++ = ti_ssp_spi_rx(hw);
93 }
94 }
95
96 msg->actual_length += count; /* bytes transferred */
97
98 dev_dbg(&msg->spi->dev, "xfer %s%s, %d bytes, %d bpw, count %d%s\n",
99 t->tx_buf ? "tx" : "", t->rx_buf ? "rx" : "", t->len,
100 hw->bpw, count, (count < t->len) ? " (under)" : "");
101
102 return (count < t->len) ? -EIO : 0; /* left over data */
103}
104
105static void ti_ssp_spi_chip_select(struct ti_ssp_spi *hw, int cs_active)
106{
107 cs_active = !!cs_active;
108 if (cs_active == hw->cs_active)
109 return;
110 ti_ssp_run(hw->dev, cs_active ? hw->pc_en : hw->pc_dis, 0, NULL);
111 hw->cs_active = cs_active;
112}
113
114#define __SHIFT_OUT(bits) (SSP_OPCODE_SHIFT | SSP_OUT_MODE | \
115 cs_en | clk | SSP_COUNT((bits) * 2 - 1))
116#define __SHIFT_IN(bits) (SSP_OPCODE_SHIFT | SSP_IN_MODE | \
117 cs_en | clk | SSP_COUNT((bits) * 2 - 1))
118
119static int ti_ssp_spi_setup_transfer(struct ti_ssp_spi *hw, u8 bpw, u8 mode)
120{
121 int error, idx = 0;
122 u32 seqram[16];
123 u32 cs_en, cs_dis, clk;
124 u32 topbits, botbits;
125
126 mode &= MODE_BITS;
127 if (mode == hw->mode && bpw == hw->bpw)
128 return 0;
129
130 cs_en = (mode & SPI_CS_HIGH) ? SSP_CS_HIGH : SSP_CS_LOW;
131 cs_dis = (mode & SPI_CS_HIGH) ? SSP_CS_LOW : SSP_CS_HIGH;
132 clk = (mode & SPI_CPOL) ? SSP_CLK_HIGH : SSP_CLK_LOW;
133
134 /* Construct instructions */
135
136 /* Disable Chip Select */
137 hw->pc_dis = idx;
138 seqram[idx++] = SSP_OPCODE_DIRECT | SSP_OUT_MODE | cs_dis | clk;
139 seqram[idx++] = SSP_OPCODE_STOP | SSP_OUT_MODE | cs_dis | clk;
140
141 /* Enable Chip Select */
142 hw->pc_en = idx;
143 seqram[idx++] = SSP_OPCODE_DIRECT | SSP_OUT_MODE | cs_en | clk;
144 seqram[idx++] = SSP_OPCODE_STOP | SSP_OUT_MODE | cs_en | clk;
145
146 /* Reads and writes need to be split for bpw > 16 */
147 topbits = (bpw > 16) ? 16 : bpw;
148 botbits = bpw - topbits;
149
150 /* Write */
151 hw->pc_wr = idx;
152 seqram[idx++] = __SHIFT_OUT(topbits) | SSP_ADDR_REG;
153 if (botbits)
154 seqram[idx++] = __SHIFT_OUT(botbits) | SSP_DATA_REG;
155 seqram[idx++] = SSP_OPCODE_STOP | SSP_OUT_MODE | cs_en | clk;
156
157 /* Read */
158 hw->pc_rd = idx;
159 if (botbits)
160 seqram[idx++] = __SHIFT_IN(botbits) | SSP_ADDR_REG;
161 seqram[idx++] = __SHIFT_IN(topbits) | SSP_DATA_REG;
162 seqram[idx++] = SSP_OPCODE_STOP | SSP_OUT_MODE | cs_en | clk;
163
164 error = ti_ssp_load(hw->dev, 0, seqram, idx);
165 if (error < 0)
166 return error;
167
168 error = ti_ssp_set_mode(hw->dev, ((mode & SPI_CPHA) ?
169 0 : SSP_EARLY_DIN));
170 if (error < 0)
171 return error;
172
173 hw->bpw = bpw;
174 hw->mode = mode;
175
176 return error;
177}
178
179static void ti_ssp_spi_work(struct work_struct *work)
180{
181 struct ti_ssp_spi *hw = container_of(work, struct ti_ssp_spi, work);
182
183 spin_lock(&hw->lock);
184
185 while (!list_empty(&hw->msg_queue)) {
186 struct spi_message *m;
187 struct spi_device *spi;
188 struct spi_transfer *t = NULL;
189 int status = 0;
190
191 m = container_of(hw->msg_queue.next, struct spi_message,
192 queue);
193
194 list_del_init(&m->queue);
195
196 spin_unlock(&hw->lock);
197
198 spi = m->spi;
199
200 if (hw->select)
201 hw->select(spi->chip_select);
202
203 list_for_each_entry(t, &m->transfers, transfer_list) {
204 int bpw = spi->bits_per_word;
205 int xfer_status;
206
207 if (t->bits_per_word)
208 bpw = t->bits_per_word;
209
210 if (ti_ssp_spi_setup_transfer(hw, bpw, spi->mode) < 0)
211 break;
212
213 ti_ssp_spi_chip_select(hw, 1);
214
215 xfer_status = ti_ssp_spi_txrx(hw, m, t);
216 if (xfer_status < 0)
217 status = xfer_status;
218
219 if (t->delay_usecs)
220 udelay(t->delay_usecs);
221
222 if (t->cs_change)
223 ti_ssp_spi_chip_select(hw, 0);
224 }
225
226 ti_ssp_spi_chip_select(hw, 0);
227 m->status = status;
228 m->complete(m->context);
229
230 spin_lock(&hw->lock);
231 }
232
233 if (hw->shutdown)
234 complete(&hw->complete);
235
236 spin_unlock(&hw->lock);
237}
238
239static int ti_ssp_spi_setup(struct spi_device *spi)
240{
241 if (spi->bits_per_word > 32)
242 return -EINVAL;
243
244 return 0;
245}
246
247static int ti_ssp_spi_transfer(struct spi_device *spi, struct spi_message *m)
248{
249 struct ti_ssp_spi *hw;
250 struct spi_transfer *t;
251 int error = 0;
252
253 m->actual_length = 0;
254 m->status = -EINPROGRESS;
255
256 hw = spi_master_get_devdata(spi->master);
257
258 if (list_empty(&m->transfers) || !m->complete)
259 return -EINVAL;
260
261 list_for_each_entry(t, &m->transfers, transfer_list) {
262 if (t->len && !(t->rx_buf || t->tx_buf)) {
263 dev_err(&spi->dev, "invalid xfer, no buffer\n");
264 return -EINVAL;
265 }
266
267 if (t->len && t->rx_buf && t->tx_buf) {
268 dev_err(&spi->dev, "invalid xfer, full duplex\n");
269 return -EINVAL;
270 }
271
272 if (t->bits_per_word > 32) {
273 dev_err(&spi->dev, "invalid xfer width %d\n",
274 t->bits_per_word);
275 return -EINVAL;
276 }
277 }
278
279 spin_lock(&hw->lock);
280 if (hw->shutdown) {
281 error = -ESHUTDOWN;
282 goto error_unlock;
283 }
284 list_add_tail(&m->queue, &hw->msg_queue);
285 queue_work(hw->workqueue, &hw->work);
286error_unlock:
287 spin_unlock(&hw->lock);
288 return error;
289}
290
291static int __devinit ti_ssp_spi_probe(struct platform_device *pdev)
292{
293 const struct ti_ssp_spi_data *pdata;
294 struct ti_ssp_spi *hw;
295 struct spi_master *master;
296 struct device *dev = &pdev->dev;
297 int error = 0;
298
299 pdata = dev->platform_data;
300 if (!pdata) {
301 dev_err(dev, "platform data not found\n");
302 return -EINVAL;
303 }
304
305 master = spi_alloc_master(dev, sizeof(struct ti_ssp_spi));
306 if (!master) {
307 dev_err(dev, "cannot allocate SPI master\n");
308 return -ENOMEM;
309 }
310
311 hw = spi_master_get_devdata(master);
312 platform_set_drvdata(pdev, hw);
313
314 hw->master = master;
315 hw->dev = dev;
316 hw->select = pdata->select;
317
318 spin_lock_init(&hw->lock);
319 init_completion(&hw->complete);
320 INIT_LIST_HEAD(&hw->msg_queue);
321 INIT_WORK(&hw->work, ti_ssp_spi_work);
322
323 hw->workqueue = create_singlethread_workqueue(dev_name(dev));
324 if (!hw->workqueue) {
325 error = -ENOMEM;
326 dev_err(dev, "work queue creation failed\n");
327 goto error_wq;
328 }
329
330 error = ti_ssp_set_iosel(hw->dev, pdata->iosel);
331 if (error < 0) {
332 dev_err(dev, "io setup failed\n");
333 goto error_iosel;
334 }
335
336 master->bus_num = pdev->id;
337 master->num_chipselect = pdata->num_cs;
338 master->mode_bits = MODE_BITS;
339 master->flags = SPI_MASTER_HALF_DUPLEX;
340 master->setup = ti_ssp_spi_setup;
341 master->transfer = ti_ssp_spi_transfer;
342
343 error = spi_register_master(master);
344 if (error) {
345 dev_err(dev, "master registration failed\n");
346 goto error_reg;
347 }
348
349 return 0;
350
351error_reg:
352error_iosel:
353 destroy_workqueue(hw->workqueue);
354error_wq:
355 spi_master_put(master);
356 return error;
357}
358
359static int __devexit ti_ssp_spi_remove(struct platform_device *pdev)
360{
361 struct ti_ssp_spi *hw = platform_get_drvdata(pdev);
362 int error;
363
364 hw->shutdown = 1;
365 while (!list_empty(&hw->msg_queue)) {
366 error = wait_for_completion_interruptible(&hw->complete);
367 if (error < 0) {
368 hw->shutdown = 0;
369 return error;
370 }
371 }
372 destroy_workqueue(hw->workqueue);
373 spi_unregister_master(hw->master);
374
375 return 0;
376}
377
378static struct platform_driver ti_ssp_spi_driver = {
379 .probe = ti_ssp_spi_probe,
380 .remove = __devexit_p(ti_ssp_spi_remove),
381 .driver = {
382 .name = "ti-ssp-spi",
383 .owner = THIS_MODULE,
384 },
385};
386
387static int __init ti_ssp_spi_init(void)
388{
389 return platform_driver_register(&ti_ssp_spi_driver);
390}
391module_init(ti_ssp_spi_init);
392
393static void __exit ti_ssp_spi_exit(void)
394{
395 platform_driver_unregister(&ti_ssp_spi_driver);
396}
397module_exit(ti_ssp_spi_exit);
398
399MODULE_DESCRIPTION("SSP SPI Master");
400MODULE_AUTHOR("Cyril Chemparathy");
401MODULE_LICENSE("GPL");
402MODULE_ALIAS("platform:ti-ssp-spi");