diff options
-rw-r--r-- | drivers/spi/Kconfig | 1 | ||||
-rw-r--r-- | drivers/spi/spi-bcm2835.c | 5 | ||||
-rw-r--r-- | drivers/spi/spi-bitbang.c | 17 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-cpm.c | 35 | ||||
-rw-r--r-- | drivers/spi/spi-omap2-mcspi.c | 16 |
5 files changed, 43 insertions, 31 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 198f96b7fb45..a132180a9251 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
@@ -78,6 +78,7 @@ config SPI_ATMEL | |||
78 | config SPI_BCM2835 | 78 | config SPI_BCM2835 |
79 | tristate "BCM2835 SPI controller" | 79 | tristate "BCM2835 SPI controller" |
80 | depends on ARCH_BCM2835 || COMPILE_TEST | 80 | depends on ARCH_BCM2835 || COMPILE_TEST |
81 | depends on GPIOLIB | ||
81 | help | 82 | help |
82 | This selects a driver for the Broadcom BCM2835 SPI master. | 83 | This selects a driver for the Broadcom BCM2835 SPI master. |
83 | 84 | ||
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index f63864a893c5..37875cf942f7 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c | |||
@@ -164,13 +164,12 @@ static int bcm2835_spi_transfer_one_poll(struct spi_master *master, | |||
164 | unsigned long xfer_time_us) | 164 | unsigned long xfer_time_us) |
165 | { | 165 | { |
166 | struct bcm2835_spi *bs = spi_master_get_devdata(master); | 166 | struct bcm2835_spi *bs = spi_master_get_devdata(master); |
167 | unsigned long timeout = jiffies + | 167 | /* set timeout to 1 second of maximum polling */ |
168 | max(4 * xfer_time_us * HZ / 1000000, 2uL); | 168 | unsigned long timeout = jiffies + HZ; |
169 | 169 | ||
170 | /* enable HW block without interrupts */ | 170 | /* enable HW block without interrupts */ |
171 | bcm2835_wr(bs, BCM2835_SPI_CS, cs | BCM2835_SPI_CS_TA); | 171 | bcm2835_wr(bs, BCM2835_SPI_CS, cs | BCM2835_SPI_CS_TA); |
172 | 172 | ||
173 | /* set timeout to 4x the expected time, or 2 jiffies */ | ||
174 | /* loop until finished the transfer */ | 173 | /* loop until finished the transfer */ |
175 | while (bs->rx_len) { | 174 | while (bs->rx_len) { |
176 | /* read from fifo as much as possible */ | 175 | /* read from fifo as much as possible */ |
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index 5ef6638d5e8a..840a4984d365 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c | |||
@@ -180,7 +180,6 @@ int spi_bitbang_setup(struct spi_device *spi) | |||
180 | { | 180 | { |
181 | struct spi_bitbang_cs *cs = spi->controller_state; | 181 | struct spi_bitbang_cs *cs = spi->controller_state; |
182 | struct spi_bitbang *bitbang; | 182 | struct spi_bitbang *bitbang; |
183 | int retval; | ||
184 | unsigned long flags; | 183 | unsigned long flags; |
185 | 184 | ||
186 | bitbang = spi_master_get_devdata(spi->master); | 185 | bitbang = spi_master_get_devdata(spi->master); |
@@ -197,9 +196,11 @@ int spi_bitbang_setup(struct spi_device *spi) | |||
197 | if (!cs->txrx_word) | 196 | if (!cs->txrx_word) |
198 | return -EINVAL; | 197 | return -EINVAL; |
199 | 198 | ||
200 | retval = bitbang->setup_transfer(spi, NULL); | 199 | if (bitbang->setup_transfer) { |
201 | if (retval < 0) | 200 | int retval = bitbang->setup_transfer(spi, NULL); |
202 | return retval; | 201 | if (retval < 0) |
202 | return retval; | ||
203 | } | ||
203 | 204 | ||
204 | dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); | 205 | dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); |
205 | 206 | ||
@@ -295,9 +296,11 @@ static int spi_bitbang_transfer_one(struct spi_master *master, | |||
295 | 296 | ||
296 | /* init (-1) or override (1) transfer params */ | 297 | /* init (-1) or override (1) transfer params */ |
297 | if (do_setup != 0) { | 298 | if (do_setup != 0) { |
298 | status = bitbang->setup_transfer(spi, t); | 299 | if (bitbang->setup_transfer) { |
299 | if (status < 0) | 300 | status = bitbang->setup_transfer(spi, t); |
300 | break; | 301 | if (status < 0) |
302 | break; | ||
303 | } | ||
301 | if (do_setup == -1) | 304 | if (do_setup == -1) |
302 | do_setup = 0; | 305 | do_setup = 0; |
303 | } | 306 | } |
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c index 9c46a3058743..6f466ab1201a 100644 --- a/drivers/spi/spi-fsl-cpm.c +++ b/drivers/spi/spi-fsl-cpm.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/of_address.h> | 24 | #include <linux/of_address.h> |
25 | #include <linux/spi/spi.h> | 25 | #include <linux/spi/spi.h> |
26 | #include <linux/types.h> | 26 | #include <linux/types.h> |
27 | #include <linux/platform_device.h> | ||
27 | 28 | ||
28 | #include "spi-fsl-cpm.h" | 29 | #include "spi-fsl-cpm.h" |
29 | #include "spi-fsl-lib.h" | 30 | #include "spi-fsl-lib.h" |
@@ -269,17 +270,6 @@ static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi) | |||
269 | if (mspi->flags & SPI_CPM2) { | 270 | if (mspi->flags & SPI_CPM2) { |
270 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | 271 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); |
271 | out_be16(spi_base, pram_ofs); | 272 | out_be16(spi_base, pram_ofs); |
272 | } else { | ||
273 | struct spi_pram __iomem *pram = spi_base; | ||
274 | u16 rpbase = in_be16(&pram->rpbase); | ||
275 | |||
276 | /* Microcode relocation patch applied? */ | ||
277 | if (rpbase) { | ||
278 | pram_ofs = rpbase; | ||
279 | } else { | ||
280 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
281 | out_be16(spi_base, pram_ofs); | ||
282 | } | ||
283 | } | 273 | } |
284 | 274 | ||
285 | iounmap(spi_base); | 275 | iounmap(spi_base); |
@@ -292,7 +282,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | |||
292 | struct device_node *np = dev->of_node; | 282 | struct device_node *np = dev->of_node; |
293 | const u32 *iprop; | 283 | const u32 *iprop; |
294 | int size; | 284 | int size; |
295 | unsigned long pram_ofs; | ||
296 | unsigned long bds_ofs; | 285 | unsigned long bds_ofs; |
297 | 286 | ||
298 | if (!(mspi->flags & SPI_CPM_MODE)) | 287 | if (!(mspi->flags & SPI_CPM_MODE)) |
@@ -319,8 +308,21 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | |||
319 | } | 308 | } |
320 | } | 309 | } |
321 | 310 | ||
322 | pram_ofs = fsl_spi_cpm_get_pram(mspi); | 311 | if (mspi->flags & SPI_CPM1) { |
323 | if (IS_ERR_VALUE(pram_ofs)) { | 312 | struct resource *res; |
313 | |||
314 | res = platform_get_resource(to_platform_device(dev), | ||
315 | IORESOURCE_MEM, 1); | ||
316 | mspi->pram = devm_ioremap_resource(dev, res); | ||
317 | } else { | ||
318 | unsigned long pram_ofs = fsl_spi_cpm_get_pram(mspi); | ||
319 | |||
320 | if (IS_ERR_VALUE(pram_ofs)) | ||
321 | mspi->pram = NULL; | ||
322 | else | ||
323 | mspi->pram = cpm_muram_addr(pram_ofs); | ||
324 | } | ||
325 | if (mspi->pram == NULL) { | ||
324 | dev_err(dev, "can't allocate spi parameter ram\n"); | 326 | dev_err(dev, "can't allocate spi parameter ram\n"); |
325 | goto err_pram; | 327 | goto err_pram; |
326 | } | 328 | } |
@@ -346,8 +348,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | |||
346 | goto err_dummy_rx; | 348 | goto err_dummy_rx; |
347 | } | 349 | } |
348 | 350 | ||
349 | mspi->pram = cpm_muram_addr(pram_ofs); | ||
350 | |||
351 | mspi->tx_bd = cpm_muram_addr(bds_ofs); | 351 | mspi->tx_bd = cpm_muram_addr(bds_ofs); |
352 | mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); | 352 | mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); |
353 | 353 | ||
@@ -375,7 +375,8 @@ err_dummy_rx: | |||
375 | err_dummy_tx: | 375 | err_dummy_tx: |
376 | cpm_muram_free(bds_ofs); | 376 | cpm_muram_free(bds_ofs); |
377 | err_bds: | 377 | err_bds: |
378 | cpm_muram_free(pram_ofs); | 378 | if (!(mspi->flags & SPI_CPM1)) |
379 | cpm_muram_free(cpm_muram_offset(mspi->pram)); | ||
379 | err_pram: | 380 | err_pram: |
380 | fsl_spi_free_dummy_rx(); | 381 | fsl_spi_free_dummy_rx(); |
381 | return -ENOMEM; | 382 | return -ENOMEM; |
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 4df8942058de..d1a5b9fc3eba 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c | |||
@@ -1210,6 +1210,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master, | |||
1210 | struct omap2_mcspi *mcspi; | 1210 | struct omap2_mcspi *mcspi; |
1211 | struct omap2_mcspi_dma *mcspi_dma; | 1211 | struct omap2_mcspi_dma *mcspi_dma; |
1212 | struct spi_transfer *t; | 1212 | struct spi_transfer *t; |
1213 | int status; | ||
1213 | 1214 | ||
1214 | spi = m->spi; | 1215 | spi = m->spi; |
1215 | mcspi = spi_master_get_devdata(master); | 1216 | mcspi = spi_master_get_devdata(master); |
@@ -1229,7 +1230,8 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master, | |||
1229 | tx_buf ? "tx" : "", | 1230 | tx_buf ? "tx" : "", |
1230 | rx_buf ? "rx" : "", | 1231 | rx_buf ? "rx" : "", |
1231 | t->bits_per_word); | 1232 | t->bits_per_word); |
1232 | return -EINVAL; | 1233 | status = -EINVAL; |
1234 | goto out; | ||
1233 | } | 1235 | } |
1234 | 1236 | ||
1235 | if (m->is_dma_mapped || len < DMA_MIN_BYTES) | 1237 | if (m->is_dma_mapped || len < DMA_MIN_BYTES) |
@@ -1241,7 +1243,8 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master, | |||
1241 | if (dma_mapping_error(mcspi->dev, t->tx_dma)) { | 1243 | if (dma_mapping_error(mcspi->dev, t->tx_dma)) { |
1242 | dev_dbg(mcspi->dev, "dma %cX %d bytes error\n", | 1244 | dev_dbg(mcspi->dev, "dma %cX %d bytes error\n", |
1243 | 'T', len); | 1245 | 'T', len); |
1244 | return -EINVAL; | 1246 | status = -EINVAL; |
1247 | goto out; | ||
1245 | } | 1248 | } |
1246 | } | 1249 | } |
1247 | if (mcspi_dma->dma_rx && rx_buf != NULL) { | 1250 | if (mcspi_dma->dma_rx && rx_buf != NULL) { |
@@ -1253,14 +1256,19 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master, | |||
1253 | if (tx_buf != NULL) | 1256 | if (tx_buf != NULL) |
1254 | dma_unmap_single(mcspi->dev, t->tx_dma, | 1257 | dma_unmap_single(mcspi->dev, t->tx_dma, |
1255 | len, DMA_TO_DEVICE); | 1258 | len, DMA_TO_DEVICE); |
1256 | return -EINVAL; | 1259 | status = -EINVAL; |
1260 | goto out; | ||
1257 | } | 1261 | } |
1258 | } | 1262 | } |
1259 | } | 1263 | } |
1260 | 1264 | ||
1261 | omap2_mcspi_work(mcspi, m); | 1265 | omap2_mcspi_work(mcspi, m); |
1266 | /* spi_finalize_current_message() changes the status inside the | ||
1267 | * spi_message, save the status here. */ | ||
1268 | status = m->status; | ||
1269 | out: | ||
1262 | spi_finalize_current_message(master); | 1270 | spi_finalize_current_message(master); |
1263 | return 0; | 1271 | return status; |
1264 | } | 1272 | } |
1265 | 1273 | ||
1266 | static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) | 1274 | static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) |