aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-08-14 14:54:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-14 14:54:09 -0400
commitb171aa27700c78511086a759383b033949c9d7f0 (patch)
tree2775b0682ea342dd49c5b997de248da73ec83049
parent11ac552477e32835cb6970bf0a70c210807f5673 (diff)
parentb4225885deb569f7afcf1f3a9f069f74cc9db591 (diff)
Merge branch 'next-spi' of git://git.secretlab.ca/git/linux-2.6
* 'next-spi' of git://git.secretlab.ca/git/linux-2.6: spi/amba_pl022: Fix probe and remove hook section annotations. spi/mpc5121: change annotations for probe and remove functions spi/bitbang: reinitialize transfer parameters for every message spi/spi-gpio: add support for controllers without MISO or MOSI pin spi/bitbang: add support for SPI_MASTER_NO_{TX, RX} modes SPI100k: Fix 8-bit and RX-only transfers spi/mmc_spi: mmc_spi adaptations for SPI bus locking API spi/mmc_spi: SPI bus locking API, using mutex Fix trivial conflict in drivers/spi/mpc512x_psc_spi.c due to 'struct of_device' => 'struct platform_device' rename and __init/__exit to __devinit/__devexit fix.
-rw-r--r--drivers/mmc/host/mmc_spi.c59
-rw-r--r--drivers/spi/amba-pl022.c6
-rw-r--r--drivers/spi/mpc512x_psc_spi.c16
-rw-r--r--drivers/spi/omap_spi_100k.c23
-rw-r--r--drivers/spi/spi.c225
-rw-r--r--drivers/spi/spi_bitbang.c9
-rw-r--r--drivers/spi/spi_bitbang_txrx.h16
-rw-r--r--drivers/spi/spi_butterfly.c2
-rw-r--r--drivers/spi/spi_gpio.c109
-rw-r--r--drivers/spi/spi_lm70llp.c2
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c8
-rw-r--r--drivers/spi/spi_sh_sci.c8
-rw-r--r--include/linux/spi/spi.h12
-rw-r--r--include/linux/spi/spi_gpio.h5
14 files changed, 353 insertions, 147 deletions
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 1145ea0792e6..62a35822003e 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -182,7 +182,7 @@ mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
182 host->data_dma, sizeof(*host->data), 182 host->data_dma, sizeof(*host->data),
183 DMA_FROM_DEVICE); 183 DMA_FROM_DEVICE);
184 184
185 status = spi_sync(host->spi, &host->readback); 185 status = spi_sync_locked(host->spi, &host->readback);
186 186
187 if (host->dma_dev) 187 if (host->dma_dev)
188 dma_sync_single_for_cpu(host->dma_dev, 188 dma_sync_single_for_cpu(host->dma_dev,
@@ -541,7 +541,7 @@ mmc_spi_command_send(struct mmc_spi_host *host,
541 host->data_dma, sizeof(*host->data), 541 host->data_dma, sizeof(*host->data),
542 DMA_BIDIRECTIONAL); 542 DMA_BIDIRECTIONAL);
543 } 543 }
544 status = spi_sync(host->spi, &host->m); 544 status = spi_sync_locked(host->spi, &host->m);
545 545
546 if (host->dma_dev) 546 if (host->dma_dev)
547 dma_sync_single_for_cpu(host->dma_dev, 547 dma_sync_single_for_cpu(host->dma_dev,
@@ -685,7 +685,7 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t,
685 host->data_dma, sizeof(*scratch), 685 host->data_dma, sizeof(*scratch),
686 DMA_BIDIRECTIONAL); 686 DMA_BIDIRECTIONAL);
687 687
688 status = spi_sync(spi, &host->m); 688 status = spi_sync_locked(spi, &host->m);
689 689
690 if (status != 0) { 690 if (status != 0) {
691 dev_dbg(&spi->dev, "write error (%d)\n", status); 691 dev_dbg(&spi->dev, "write error (%d)\n", status);
@@ -822,7 +822,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t,
822 DMA_FROM_DEVICE); 822 DMA_FROM_DEVICE);
823 } 823 }
824 824
825 status = spi_sync(spi, &host->m); 825 status = spi_sync_locked(spi, &host->m);
826 826
827 if (host->dma_dev) { 827 if (host->dma_dev) {
828 dma_sync_single_for_cpu(host->dma_dev, 828 dma_sync_single_for_cpu(host->dma_dev,
@@ -1018,7 +1018,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
1018 host->data_dma, sizeof(*scratch), 1018 host->data_dma, sizeof(*scratch),
1019 DMA_BIDIRECTIONAL); 1019 DMA_BIDIRECTIONAL);
1020 1020
1021 tmp = spi_sync(spi, &host->m); 1021 tmp = spi_sync_locked(spi, &host->m);
1022 1022
1023 if (host->dma_dev) 1023 if (host->dma_dev)
1024 dma_sync_single_for_cpu(host->dma_dev, 1024 dma_sync_single_for_cpu(host->dma_dev,
@@ -1084,6 +1084,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
1084 } 1084 }
1085#endif 1085#endif
1086 1086
1087 /* request exclusive bus access */
1088 spi_bus_lock(host->spi->master);
1089
1087 /* issue command; then optionally data and stop */ 1090 /* issue command; then optionally data and stop */
1088 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL); 1091 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
1089 if (status == 0 && mrq->data) { 1092 if (status == 0 && mrq->data) {
@@ -1094,6 +1097,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
1094 mmc_cs_off(host); 1097 mmc_cs_off(host);
1095 } 1098 }
1096 1099
1100 /* release the bus */
1101 spi_bus_unlock(host->spi->master);
1102
1097 mmc_request_done(host->mmc, mrq); 1103 mmc_request_done(host->mmc, mrq);
1098} 1104}
1099 1105
@@ -1290,23 +1296,6 @@ mmc_spi_detect_irq(int irq, void *mmc)
1290 return IRQ_HANDLED; 1296 return IRQ_HANDLED;
1291} 1297}
1292 1298
1293struct count_children {
1294 unsigned n;
1295 struct bus_type *bus;
1296};
1297
1298static int maybe_count_child(struct device *dev, void *c)
1299{
1300 struct count_children *ccp = c;
1301
1302 if (dev->bus == ccp->bus) {
1303 if (ccp->n)
1304 return -EBUSY;
1305 ccp->n++;
1306 }
1307 return 0;
1308}
1309
1310static int mmc_spi_probe(struct spi_device *spi) 1299static int mmc_spi_probe(struct spi_device *spi)
1311{ 1300{
1312 void *ones; 1301 void *ones;
@@ -1338,32 +1327,6 @@ static int mmc_spi_probe(struct spi_device *spi)
1338 return status; 1327 return status;
1339 } 1328 }
1340 1329
1341 /* We can use the bus safely iff nobody else will interfere with us.
1342 * Most commands consist of one SPI message to issue a command, then
1343 * several more to collect its response, then possibly more for data
1344 * transfer. Clocking access to other devices during that period will
1345 * corrupt the command execution.
1346 *
1347 * Until we have software primitives which guarantee non-interference,
1348 * we'll aim for a hardware-level guarantee.
1349 *
1350 * REVISIT we can't guarantee another device won't be added later...
1351 */
1352 if (spi->master->num_chipselect > 1) {
1353 struct count_children cc;
1354
1355 cc.n = 0;
1356 cc.bus = spi->dev.bus;
1357 status = device_for_each_child(spi->dev.parent, &cc,
1358 maybe_count_child);
1359 if (status < 0) {
1360 dev_err(&spi->dev, "can't share SPI bus\n");
1361 return status;
1362 }
1363
1364 dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
1365 }
1366
1367 /* We need a supply of ones to transmit. This is the only time 1330 /* We need a supply of ones to transmit. This is the only time
1368 * the CPU touches these, so cache coherency isn't a concern. 1331 * the CPU touches these, so cache coherency isn't a concern.
1369 * 1332 *
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index f0a1418ce660..acd35d1ebd12 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -1723,7 +1723,7 @@ static void pl022_cleanup(struct spi_device *spi)
1723} 1723}
1724 1724
1725 1725
1726static int __init 1726static int __devinit
1727pl022_probe(struct amba_device *adev, struct amba_id *id) 1727pl022_probe(struct amba_device *adev, struct amba_id *id)
1728{ 1728{
1729 struct device *dev = &adev->dev; 1729 struct device *dev = &adev->dev;
@@ -1838,7 +1838,7 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1838 return status; 1838 return status;
1839} 1839}
1840 1840
1841static int __exit 1841static int __devexit
1842pl022_remove(struct amba_device *adev) 1842pl022_remove(struct amba_device *adev)
1843{ 1843{
1844 struct pl022 *pl022 = amba_get_drvdata(adev); 1844 struct pl022 *pl022 = amba_get_drvdata(adev);
@@ -1970,7 +1970,7 @@ static struct amba_driver pl022_driver = {
1970 }, 1970 },
1971 .id_table = pl022_ids, 1971 .id_table = pl022_ids,
1972 .probe = pl022_probe, 1972 .probe = pl022_probe,
1973 .remove = __exit_p(pl022_remove), 1973 .remove = __devexit_p(pl022_remove),
1974 .suspend = pl022_suspend, 1974 .suspend = pl022_suspend,
1975 .resume = pl022_resume, 1975 .resume = pl022_resume,
1976}; 1976};
diff --git a/drivers/spi/mpc512x_psc_spi.c b/drivers/spi/mpc512x_psc_spi.c
index cddbfceb324f..77d9e7ee8b27 100644
--- a/drivers/spi/mpc512x_psc_spi.c
+++ b/drivers/spi/mpc512x_psc_spi.c
@@ -406,9 +406,9 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id)
406} 406}
407 407
408/* bus_num is used only for the case dev->platform_data == NULL */ 408/* bus_num is used only for the case dev->platform_data == NULL */
409static int __init mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, 409static int __devinit mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
410 u32 size, unsigned int irq, 410 u32 size, unsigned int irq,
411 s16 bus_num) 411 s16 bus_num)
412{ 412{
413 struct fsl_spi_platform_data *pdata = dev->platform_data; 413 struct fsl_spi_platform_data *pdata = dev->platform_data;
414 struct mpc512x_psc_spi *mps; 414 struct mpc512x_psc_spi *mps;
@@ -492,7 +492,7 @@ free_master:
492 return ret; 492 return ret;
493} 493}
494 494
495static int __exit mpc512x_psc_spi_do_remove(struct device *dev) 495static int __devexit mpc512x_psc_spi_do_remove(struct device *dev)
496{ 496{
497 struct spi_master *master = dev_get_drvdata(dev); 497 struct spi_master *master = dev_get_drvdata(dev);
498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
@@ -507,8 +507,8 @@ static int __exit mpc512x_psc_spi_do_remove(struct device *dev)
507 return 0; 507 return 0;
508} 508}
509 509
510static int __init mpc512x_psc_spi_of_probe(struct platform_device *op, 510static int __devinit mpc512x_psc_spi_of_probe(struct platform_device *op,
511 const struct of_device_id *match) 511 const struct of_device_id *match)
512{ 512{
513 const u32 *regaddr_p; 513 const u32 *regaddr_p;
514 u64 regaddr64, size64; 514 u64 regaddr64, size64;
@@ -539,7 +539,7 @@ static int __init mpc512x_psc_spi_of_probe(struct platform_device *op,
539 irq_of_parse_and_map(op->dev.of_node, 0), id); 539 irq_of_parse_and_map(op->dev.of_node, 0), id);
540} 540}
541 541
542static int __exit mpc512x_psc_spi_of_remove(struct platform_device *op) 542static int __devexit mpc512x_psc_spi_of_remove(struct platform_device *op)
543{ 543{
544 return mpc512x_psc_spi_do_remove(&op->dev); 544 return mpc512x_psc_spi_do_remove(&op->dev);
545} 545}
@@ -553,7 +553,7 @@ MODULE_DEVICE_TABLE(of, mpc512x_psc_spi_of_match);
553 553
554static struct of_platform_driver mpc512x_psc_spi_of_driver = { 554static struct of_platform_driver mpc512x_psc_spi_of_driver = {
555 .probe = mpc512x_psc_spi_of_probe, 555 .probe = mpc512x_psc_spi_of_probe,
556 .remove = __exit_p(mpc512x_psc_spi_of_remove), 556 .remove = __devexit_p(mpc512x_psc_spi_of_remove),
557 .driver = { 557 .driver = {
558 .name = "mpc512x-psc-spi", 558 .name = "mpc512x-psc-spi",
559 .owner = THIS_MODULE, 559 .owner = THIS_MODULE,
diff --git a/drivers/spi/omap_spi_100k.c b/drivers/spi/omap_spi_100k.c
index 24668b30a52d..9bd1c92ad96e 100644
--- a/drivers/spi/omap_spi_100k.c
+++ b/drivers/spi/omap_spi_100k.c
@@ -141,7 +141,12 @@ static void spi100k_write_data(struct spi_master *master, int len, int data)
141{ 141{
142 struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 142 struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
143 143
144 /* write 16-bit word */ 144 /* write 16-bit word, shifting 8-bit data if necessary */
145 if (len <= 8) {
146 data <<= 8;
147 len = 16;
148 }
149
145 spi100k_enable_clock(master); 150 spi100k_enable_clock(master);
146 writew( data , spi100k->base + SPI_TX_MSB); 151 writew( data , spi100k->base + SPI_TX_MSB);
147 152
@@ -162,6 +167,10 @@ static int spi100k_read_data(struct spi_master *master, int len)
162 int dataH,dataL; 167 int dataH,dataL;
163 struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 168 struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
164 169
170 /* Always do at least 16 bits */
171 if (len <= 8)
172 len = 16;
173
165 spi100k_enable_clock(master); 174 spi100k_enable_clock(master);
166 writew(SPI_CTRL_SEN(0) | 175 writew(SPI_CTRL_SEN(0) |
167 SPI_CTRL_WORD_SIZE(len) | 176 SPI_CTRL_WORD_SIZE(len) |
@@ -214,10 +223,6 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
214 c = count; 223 c = count;
215 word_len = cs->word_len; 224 word_len = cs->word_len;
216 225
217 /* RX_ONLY mode needs dummy data in TX reg */
218 if (xfer->tx_buf == NULL)
219 spi100k_write_data(spi->master,word_len, 0);
220
221 if (word_len <= 8) { 226 if (word_len <= 8) {
222 u8 *rx; 227 u8 *rx;
223 const u8 *tx; 228 const u8 *tx;
@@ -227,9 +232,9 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
227 do { 232 do {
228 c-=1; 233 c-=1;
229 if (xfer->tx_buf != NULL) 234 if (xfer->tx_buf != NULL)
230 spi100k_write_data(spi->master,word_len, *tx); 235 spi100k_write_data(spi->master, word_len, *tx++);
231 if (xfer->rx_buf != NULL) 236 if (xfer->rx_buf != NULL)
232 *rx = spi100k_read_data(spi->master,word_len); 237 *rx++ = spi100k_read_data(spi->master, word_len);
233 } while(c); 238 } while(c);
234 } else if (word_len <= 16) { 239 } else if (word_len <= 16) {
235 u16 *rx; 240 u16 *rx;
@@ -380,10 +385,6 @@ static void omap1_spi100k_work(struct work_struct *work)
380 if (t->len) { 385 if (t->len) {
381 unsigned count; 386 unsigned count;
382 387
383 /* RX_ONLY mode needs dummy data in TX reg */
384 if (t->tx_buf == NULL)
385 spi100k_write_data(spi->master, 8, 0);
386
387 count = omap1_spi100k_txrx_pio(spi, t); 388 count = omap1_spi100k_txrx_pio(spi, t);
388 m->actual_length += count; 389 m->actual_length += count;
389 390
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bb1b88780ce..a9e5c79ae52a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -528,6 +528,10 @@ int spi_register_master(struct spi_master *master)
528 dynamic = 1; 528 dynamic = 1;
529 } 529 }
530 530
531 spin_lock_init(&master->bus_lock_spinlock);
532 mutex_init(&master->bus_lock_mutex);
533 master->bus_lock_flag = 0;
534
531 /* register the device, then userspace will see it. 535 /* register the device, then userspace will see it.
532 * registration fails if the bus ID is in use. 536 * registration fails if the bus ID is in use.
533 */ 537 */
@@ -670,6 +674,35 @@ int spi_setup(struct spi_device *spi)
670} 674}
671EXPORT_SYMBOL_GPL(spi_setup); 675EXPORT_SYMBOL_GPL(spi_setup);
672 676
677static int __spi_async(struct spi_device *spi, struct spi_message *message)
678{
679 struct spi_master *master = spi->master;
680
681 /* Half-duplex links include original MicroWire, and ones with
682 * only one data pin like SPI_3WIRE (switches direction) or where
683 * either MOSI or MISO is missing. They can also be caused by
684 * software limitations.
685 */
686 if ((master->flags & SPI_MASTER_HALF_DUPLEX)
687 || (spi->mode & SPI_3WIRE)) {
688 struct spi_transfer *xfer;
689 unsigned flags = master->flags;
690
691 list_for_each_entry(xfer, &message->transfers, transfer_list) {
692 if (xfer->rx_buf && xfer->tx_buf)
693 return -EINVAL;
694 if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf)
695 return -EINVAL;
696 if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf)
697 return -EINVAL;
698 }
699 }
700
701 message->spi = spi;
702 message->status = -EINPROGRESS;
703 return master->transfer(spi, message);
704}
705
673/** 706/**
674 * spi_async - asynchronous SPI transfer 707 * spi_async - asynchronous SPI transfer
675 * @spi: device with which data will be exchanged 708 * @spi: device with which data will be exchanged
@@ -702,33 +735,68 @@ EXPORT_SYMBOL_GPL(spi_setup);
702int spi_async(struct spi_device *spi, struct spi_message *message) 735int spi_async(struct spi_device *spi, struct spi_message *message)
703{ 736{
704 struct spi_master *master = spi->master; 737 struct spi_master *master = spi->master;
738 int ret;
739 unsigned long flags;
705 740
706 /* Half-duplex links include original MicroWire, and ones with 741 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
707 * only one data pin like SPI_3WIRE (switches direction) or where
708 * either MOSI or MISO is missing. They can also be caused by
709 * software limitations.
710 */
711 if ((master->flags & SPI_MASTER_HALF_DUPLEX)
712 || (spi->mode & SPI_3WIRE)) {
713 struct spi_transfer *xfer;
714 unsigned flags = master->flags;
715 742
716 list_for_each_entry(xfer, &message->transfers, transfer_list) { 743 if (master->bus_lock_flag)
717 if (xfer->rx_buf && xfer->tx_buf) 744 ret = -EBUSY;
718 return -EINVAL; 745 else
719 if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf) 746 ret = __spi_async(spi, message);
720 return -EINVAL;
721 if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf)
722 return -EINVAL;
723 }
724 }
725 747
726 message->spi = spi; 748 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
727 message->status = -EINPROGRESS; 749
728 return master->transfer(spi, message); 750 return ret;
729} 751}
730EXPORT_SYMBOL_GPL(spi_async); 752EXPORT_SYMBOL_GPL(spi_async);
731 753
754/**
755 * spi_async_locked - version of spi_async with exclusive bus usage
756 * @spi: device with which data will be exchanged
757 * @message: describes the data transfers, including completion callback
758 * Context: any (irqs may be blocked, etc)
759 *
760 * This call may be used in_irq and other contexts which can't sleep,
761 * as well as from task contexts which can sleep.
762 *
763 * The completion callback is invoked in a context which can't sleep.
764 * Before that invocation, the value of message->status is undefined.
765 * When the callback is issued, message->status holds either zero (to
766 * indicate complete success) or a negative error code. After that
767 * callback returns, the driver which issued the transfer request may
768 * deallocate the associated memory; it's no longer in use by any SPI
769 * core or controller driver code.
770 *
771 * Note that although all messages to a spi_device are handled in
772 * FIFO order, messages may go to different devices in other orders.
773 * Some device might be higher priority, or have various "hard" access
774 * time requirements, for example.
775 *
776 * On detection of any fault during the transfer, processing of
777 * the entire message is aborted, and the device is deselected.
778 * Until returning from the associated message completion callback,
779 * no other spi_message queued to that device will be processed.
780 * (This rule applies equally to all the synchronous transfer calls,
781 * which are wrappers around this core asynchronous primitive.)
782 */
783int spi_async_locked(struct spi_device *spi, struct spi_message *message)
784{
785 struct spi_master *master = spi->master;
786 int ret;
787 unsigned long flags;
788
789 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
790
791 ret = __spi_async(spi, message);
792
793 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
794
795 return ret;
796
797}
798EXPORT_SYMBOL_GPL(spi_async_locked);
799
732 800
733/*-------------------------------------------------------------------------*/ 801/*-------------------------------------------------------------------------*/
734 802
@@ -742,6 +810,32 @@ static void spi_complete(void *arg)
742 complete(arg); 810 complete(arg);
743} 811}
744 812
813static int __spi_sync(struct spi_device *spi, struct spi_message *message,
814 int bus_locked)
815{
816 DECLARE_COMPLETION_ONSTACK(done);
817 int status;
818 struct spi_master *master = spi->master;
819
820 message->complete = spi_complete;
821 message->context = &done;
822
823 if (!bus_locked)
824 mutex_lock(&master->bus_lock_mutex);
825
826 status = spi_async_locked(spi, message);
827
828 if (!bus_locked)
829 mutex_unlock(&master->bus_lock_mutex);
830
831 if (status == 0) {
832 wait_for_completion(&done);
833 status = message->status;
834 }
835 message->context = NULL;
836 return status;
837}
838
745/** 839/**
746 * spi_sync - blocking/synchronous SPI data transfers 840 * spi_sync - blocking/synchronous SPI data transfers
747 * @spi: device with which data will be exchanged 841 * @spi: device with which data will be exchanged
@@ -765,21 +859,86 @@ static void spi_complete(void *arg)
765 */ 859 */
766int spi_sync(struct spi_device *spi, struct spi_message *message) 860int spi_sync(struct spi_device *spi, struct spi_message *message)
767{ 861{
768 DECLARE_COMPLETION_ONSTACK(done); 862 return __spi_sync(spi, message, 0);
769 int status;
770
771 message->complete = spi_complete;
772 message->context = &done;
773 status = spi_async(spi, message);
774 if (status == 0) {
775 wait_for_completion(&done);
776 status = message->status;
777 }
778 message->context = NULL;
779 return status;
780} 863}
781EXPORT_SYMBOL_GPL(spi_sync); 864EXPORT_SYMBOL_GPL(spi_sync);
782 865
866/**
867 * spi_sync_locked - version of spi_sync with exclusive bus usage
868 * @spi: device with which data will be exchanged
869 * @message: describes the data transfers
870 * Context: can sleep
871 *
872 * This call may only be used from a context that may sleep. The sleep
873 * is non-interruptible, and has no timeout. Low-overhead controller
874 * drivers may DMA directly into and out of the message buffers.
875 *
876 * This call should be used by drivers that require exclusive access to the
877 * SPI bus. It has to be preceeded by a spi_bus_lock call. The SPI bus must
878 * be released by a spi_bus_unlock call when the exclusive access is over.
879 *
880 * It returns zero on success, else a negative error code.
881 */
882int spi_sync_locked(struct spi_device *spi, struct spi_message *message)
883{
884 return __spi_sync(spi, message, 1);
885}
886EXPORT_SYMBOL_GPL(spi_sync_locked);
887
888/**
889 * spi_bus_lock - obtain a lock for exclusive SPI bus usage
890 * @master: SPI bus master that should be locked for exclusive bus access
891 * Context: can sleep
892 *
893 * This call may only be used from a context that may sleep. The sleep
894 * is non-interruptible, and has no timeout.
895 *
896 * This call should be used by drivers that require exclusive access to the
897 * SPI bus. The SPI bus must be released by a spi_bus_unlock call when the
898 * exclusive access is over. Data transfer must be done by spi_sync_locked
899 * and spi_async_locked calls when the SPI bus lock is held.
900 *
901 * It returns zero on success, else a negative error code.
902 */
903int spi_bus_lock(struct spi_master *master)
904{
905 unsigned long flags;
906
907 mutex_lock(&master->bus_lock_mutex);
908
909 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
910 master->bus_lock_flag = 1;
911 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
912
913 /* mutex remains locked until spi_bus_unlock is called */
914
915 return 0;
916}
917EXPORT_SYMBOL_GPL(spi_bus_lock);
918
919/**
920 * spi_bus_unlock - release the lock for exclusive SPI bus usage
921 * @master: SPI bus master that was locked for exclusive bus access
922 * Context: can sleep
923 *
924 * This call may only be used from a context that may sleep. The sleep
925 * is non-interruptible, and has no timeout.
926 *
927 * This call releases an SPI bus lock previously obtained by an spi_bus_lock
928 * call.
929 *
930 * It returns zero on success, else a negative error code.
931 */
932int spi_bus_unlock(struct spi_master *master)
933{
934 master->bus_lock_flag = 0;
935
936 mutex_unlock(&master->bus_lock_mutex);
937
938 return 0;
939}
940EXPORT_SYMBOL_GPL(spi_bus_unlock);
941
783/* portable code must never pass more than 32 bytes */ 942/* portable code must never pass more than 32 bytes */
784#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES) 943#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
785 944
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 5265330a528f..8b55724d5f39 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -259,7 +259,6 @@ static void bitbang_work(struct work_struct *work)
259 struct spi_bitbang *bitbang = 259 struct spi_bitbang *bitbang =
260 container_of(work, struct spi_bitbang, work); 260 container_of(work, struct spi_bitbang, work);
261 unsigned long flags; 261 unsigned long flags;
262 int do_setup = -1;
263 int (*setup_transfer)(struct spi_device *, 262 int (*setup_transfer)(struct spi_device *,
264 struct spi_transfer *); 263 struct spi_transfer *);
265 264
@@ -275,6 +274,7 @@ static void bitbang_work(struct work_struct *work)
275 unsigned tmp; 274 unsigned tmp;
276 unsigned cs_change; 275 unsigned cs_change;
277 int status; 276 int status;
277 int do_setup = -1;
278 278
279 m = container_of(bitbang->queue.next, struct spi_message, 279 m = container_of(bitbang->queue.next, struct spi_message,
280 queue); 280 queue);
@@ -307,6 +307,8 @@ static void bitbang_work(struct work_struct *work)
307 status = setup_transfer(spi, t); 307 status = setup_transfer(spi, t);
308 if (status < 0) 308 if (status < 0)
309 break; 309 break;
310 if (do_setup == -1)
311 do_setup = 0;
310 } 312 }
311 313
312 /* set up default clock polarity, and activate chip; 314 /* set up default clock polarity, and activate chip;
@@ -367,11 +369,6 @@ static void bitbang_work(struct work_struct *work)
367 m->status = status; 369 m->status = status;
368 m->complete(m->context); 370 m->complete(m->context);
369 371
370 /* restore speed and wordsize if it was overridden */
371 if (do_setup == 1)
372 setup_transfer(spi, NULL);
373 do_setup = 0;
374
375 /* normally deactivate chipselect ... unless no error and 372 /* normally deactivate chipselect ... unless no error and
376 * cs_change has hinted that the next message will probably 373 * cs_change has hinted that the next message will probably
377 * be for this chip too. 374 * be for this chip too.
diff --git a/drivers/spi/spi_bitbang_txrx.h b/drivers/spi/spi_bitbang_txrx.h
index fc033bbf9180..c16bf853c3eb 100644
--- a/drivers/spi/spi_bitbang_txrx.h
+++ b/drivers/spi/spi_bitbang_txrx.h
@@ -44,7 +44,7 @@
44 44
45static inline u32 45static inline u32
46bitbang_txrx_be_cpha0(struct spi_device *spi, 46bitbang_txrx_be_cpha0(struct spi_device *spi,
47 unsigned nsecs, unsigned cpol, 47 unsigned nsecs, unsigned cpol, unsigned flags,
48 u32 word, u8 bits) 48 u32 word, u8 bits)
49{ 49{
50 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ 50 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
@@ -53,7 +53,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
53 for (word <<= (32 - bits); likely(bits); bits--) { 53 for (word <<= (32 - bits); likely(bits); bits--) {
54 54
55 /* setup MSB (to slave) on trailing edge */ 55 /* setup MSB (to slave) on trailing edge */
56 setmosi(spi, word & (1 << 31)); 56 if ((flags & SPI_MASTER_NO_TX) == 0)
57 setmosi(spi, word & (1 << 31));
57 spidelay(nsecs); /* T(setup) */ 58 spidelay(nsecs); /* T(setup) */
58 59
59 setsck(spi, !cpol); 60 setsck(spi, !cpol);
@@ -61,7 +62,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
61 62
62 /* sample MSB (from slave) on leading edge */ 63 /* sample MSB (from slave) on leading edge */
63 word <<= 1; 64 word <<= 1;
64 word |= getmiso(spi); 65 if ((flags & SPI_MASTER_NO_RX) == 0)
66 word |= getmiso(spi);
65 setsck(spi, cpol); 67 setsck(spi, cpol);
66 } 68 }
67 return word; 69 return word;
@@ -69,7 +71,7 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
69 71
70static inline u32 72static inline u32
71bitbang_txrx_be_cpha1(struct spi_device *spi, 73bitbang_txrx_be_cpha1(struct spi_device *spi,
72 unsigned nsecs, unsigned cpol, 74 unsigned nsecs, unsigned cpol, unsigned flags,
73 u32 word, u8 bits) 75 u32 word, u8 bits)
74{ 76{
75 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ 77 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
@@ -79,7 +81,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,
79 81
80 /* setup MSB (to slave) on leading edge */ 82 /* setup MSB (to slave) on leading edge */
81 setsck(spi, !cpol); 83 setsck(spi, !cpol);
82 setmosi(spi, word & (1 << 31)); 84 if ((flags & SPI_MASTER_NO_TX) == 0)
85 setmosi(spi, word & (1 << 31));
83 spidelay(nsecs); /* T(setup) */ 86 spidelay(nsecs); /* T(setup) */
84 87
85 setsck(spi, cpol); 88 setsck(spi, cpol);
@@ -87,7 +90,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,
87 90
88 /* sample MSB (from slave) on trailing edge */ 91 /* sample MSB (from slave) on trailing edge */
89 word <<= 1; 92 word <<= 1;
90 word |= getmiso(spi); 93 if ((flags & SPI_MASTER_NO_RX) == 0)
94 word |= getmiso(spi);
91 } 95 }
92 return word; 96 return word;
93} 97}
diff --git a/drivers/spi/spi_butterfly.c b/drivers/spi/spi_butterfly.c
index 8b5281281111..0d4ceba3b590 100644
--- a/drivers/spi/spi_butterfly.c
+++ b/drivers/spi/spi_butterfly.c
@@ -156,7 +156,7 @@ butterfly_txrx_word_mode0(struct spi_device *spi,
156 unsigned nsecs, 156 unsigned nsecs,
157 u32 word, u8 bits) 157 u32 word, u8 bits)
158{ 158{
159 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 159 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
160} 160}
161 161
162/*----------------------------------------------------------------------*/ 162/*----------------------------------------------------------------------*/
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index 7edbd5807e0e..e24a63498acb 100644
--- a/drivers/spi/spi_gpio.c
+++ b/drivers/spi/spi_gpio.c
@@ -146,25 +146,63 @@ static inline int getmiso(const struct spi_device *spi)
146static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, 146static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
147 unsigned nsecs, u32 word, u8 bits) 147 unsigned nsecs, u32 word, u8 bits)
148{ 148{
149 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 149 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
150} 150}
151 151
152static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, 152static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
153 unsigned nsecs, u32 word, u8 bits) 153 unsigned nsecs, u32 word, u8 bits)
154{ 154{
155 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 155 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
156} 156}
157 157
158static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, 158static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
159 unsigned nsecs, u32 word, u8 bits) 159 unsigned nsecs, u32 word, u8 bits)
160{ 160{
161 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 161 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
162} 162}
163 163
164static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, 164static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
165 unsigned nsecs, u32 word, u8 bits) 165 unsigned nsecs, u32 word, u8 bits)
166{ 166{
167 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 167 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
168}
169
170/*
171 * These functions do not call setmosi or getmiso if respective flag
172 * (SPI_MASTER_NO_RX or SPI_MASTER_NO_TX) is set, so they are safe to
173 * call when such pin is not present or defined in the controller.
174 * A separate set of callbacks is defined to get highest possible
175 * speed in the generic case (when both MISO and MOSI lines are
176 * available), as optimiser will remove the checks when argument is
177 * constant.
178 */
179
180static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi,
181 unsigned nsecs, u32 word, u8 bits)
182{
183 unsigned flags = spi->master->flags;
184 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
185}
186
187static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi,
188 unsigned nsecs, u32 word, u8 bits)
189{
190 unsigned flags = spi->master->flags;
191 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
192}
193
194static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi,
195 unsigned nsecs, u32 word, u8 bits)
196{
197 unsigned flags = spi->master->flags;
198 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
199}
200
201static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
202 unsigned nsecs, u32 word, u8 bits)
203{
204 unsigned flags = spi->master->flags;
205 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
168} 206}
169 207
170/*----------------------------------------------------------------------*/ 208/*----------------------------------------------------------------------*/
@@ -232,19 +270,30 @@ static int __init spi_gpio_alloc(unsigned pin, const char *label, bool is_in)
232} 270}
233 271
234static int __init 272static int __init
235spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label) 273spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label,
274 u16 *res_flags)
236{ 275{
237 int value; 276 int value;
238 277
239 /* NOTE: SPI_*_GPIO symbols may reference "pdata" */ 278 /* NOTE: SPI_*_GPIO symbols may reference "pdata" */
240 279
241 value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false); 280 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) {
242 if (value) 281 value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false);
243 goto done; 282 if (value)
283 goto done;
284 } else {
285 /* HW configuration without MOSI pin */
286 *res_flags |= SPI_MASTER_NO_TX;
287 }
244 288
245 value = spi_gpio_alloc(SPI_MISO_GPIO, label, true); 289 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) {
246 if (value) 290 value = spi_gpio_alloc(SPI_MISO_GPIO, label, true);
247 goto free_mosi; 291 if (value)
292 goto free_mosi;
293 } else {
294 /* HW configuration without MISO pin */
295 *res_flags |= SPI_MASTER_NO_RX;
296 }
248 297
249 value = spi_gpio_alloc(SPI_SCK_GPIO, label, false); 298 value = spi_gpio_alloc(SPI_SCK_GPIO, label, false);
250 if (value) 299 if (value)
@@ -253,9 +302,11 @@ spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label)
253 goto done; 302 goto done;
254 303
255free_miso: 304free_miso:
256 gpio_free(SPI_MISO_GPIO); 305 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
306 gpio_free(SPI_MISO_GPIO);
257free_mosi: 307free_mosi:
258 gpio_free(SPI_MOSI_GPIO); 308 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
309 gpio_free(SPI_MOSI_GPIO);
259done: 310done:
260 return value; 311 return value;
261} 312}
@@ -266,6 +317,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
266 struct spi_master *master; 317 struct spi_master *master;
267 struct spi_gpio *spi_gpio; 318 struct spi_gpio *spi_gpio;
268 struct spi_gpio_platform_data *pdata; 319 struct spi_gpio_platform_data *pdata;
320 u16 master_flags = 0;
269 321
270 pdata = pdev->dev.platform_data; 322 pdata = pdev->dev.platform_data;
271#ifdef GENERIC_BITBANG 323#ifdef GENERIC_BITBANG
@@ -273,7 +325,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
273 return -ENODEV; 325 return -ENODEV;
274#endif 326#endif
275 327
276 status = spi_gpio_request(pdata, dev_name(&pdev->dev)); 328 status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags);
277 if (status < 0) 329 if (status < 0)
278 return status; 330 return status;
279 331
@@ -289,6 +341,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
289 if (pdata) 341 if (pdata)
290 spi_gpio->pdata = *pdata; 342 spi_gpio->pdata = *pdata;
291 343
344 master->flags = master_flags;
292 master->bus_num = pdev->id; 345 master->bus_num = pdev->id;
293 master->num_chipselect = SPI_N_CHIPSEL; 346 master->num_chipselect = SPI_N_CHIPSEL;
294 master->setup = spi_gpio_setup; 347 master->setup = spi_gpio_setup;
@@ -296,10 +349,18 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
296 349
297 spi_gpio->bitbang.master = spi_master_get(master); 350 spi_gpio->bitbang.master = spi_master_get(master);
298 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 351 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
299 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 352
300 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; 353 if ((master_flags & (SPI_MASTER_NO_RX | SPI_MASTER_NO_RX)) == 0) {
301 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; 354 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0;
302 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; 355 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1;
356 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2;
357 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3;
358 } else {
359 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0;
360 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1;
361 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2;
362 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3;
363 }
303 spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; 364 spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer;
304 spi_gpio->bitbang.flags = SPI_CS_HIGH; 365 spi_gpio->bitbang.flags = SPI_CS_HIGH;
305 366
@@ -307,8 +368,10 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
307 if (status < 0) { 368 if (status < 0) {
308 spi_master_put(spi_gpio->bitbang.master); 369 spi_master_put(spi_gpio->bitbang.master);
309gpio_free: 370gpio_free:
310 gpio_free(SPI_MISO_GPIO); 371 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
311 gpio_free(SPI_MOSI_GPIO); 372 gpio_free(SPI_MISO_GPIO);
373 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
374 gpio_free(SPI_MOSI_GPIO);
312 gpio_free(SPI_SCK_GPIO); 375 gpio_free(SPI_SCK_GPIO);
313 spi_master_put(master); 376 spi_master_put(master);
314 } 377 }
@@ -331,8 +394,10 @@ static int __exit spi_gpio_remove(struct platform_device *pdev)
331 394
332 platform_set_drvdata(pdev, NULL); 395 platform_set_drvdata(pdev, NULL);
333 396
334 gpio_free(SPI_MISO_GPIO); 397 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
335 gpio_free(SPI_MOSI_GPIO); 398 gpio_free(SPI_MISO_GPIO);
399 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
400 gpio_free(SPI_MOSI_GPIO);
336 gpio_free(SPI_SCK_GPIO); 401 gpio_free(SPI_SCK_GPIO);
337 402
338 return status; 403 return status;
diff --git a/drivers/spi/spi_lm70llp.c b/drivers/spi/spi_lm70llp.c
index 86fb7b5993db..7746a41ab6d6 100644
--- a/drivers/spi/spi_lm70llp.c
+++ b/drivers/spi/spi_lm70llp.c
@@ -191,7 +191,7 @@ static void lm70_chipselect(struct spi_device *spi, int value)
191 */ 191 */
192static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) 192static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
193{ 193{
194 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 194 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
195} 195}
196 196
197static void spi_lm70llp_attach(struct parport *p) 197static void spi_lm70llp_attach(struct parport *p)
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index 8979a75dbd7b..be991359bf92 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -64,25 +64,25 @@ static inline u32 getmiso(struct spi_device *dev)
64static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi, 64static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi,
65 unsigned nsecs, u32 word, u8 bits) 65 unsigned nsecs, u32 word, u8 bits)
66{ 66{
67 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 67 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
68} 68}
69 69
70static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi, 70static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
71 unsigned nsecs, u32 word, u8 bits) 71 unsigned nsecs, u32 word, u8 bits)
72{ 72{
73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
74} 74}
75 75
76static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi, 76static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
77 unsigned nsecs, u32 word, u8 bits) 77 unsigned nsecs, u32 word, u8 bits)
78{ 78{
79 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 79 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
80} 80}
81 81
82static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi, 82static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
83 unsigned nsecs, u32 word, u8 bits) 83 unsigned nsecs, u32 word, u8 bits)
84{ 84{
85 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 85 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
86} 86}
87 87
88 88
diff --git a/drivers/spi/spi_sh_sci.c b/drivers/spi/spi_sh_sci.c
index a511be7961a0..5c6439161199 100644
--- a/drivers/spi/spi_sh_sci.c
+++ b/drivers/spi/spi_sh_sci.c
@@ -83,25 +83,25 @@ static inline u32 getmiso(struct spi_device *dev)
83static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, 83static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
84 unsigned nsecs, u32 word, u8 bits) 84 unsigned nsecs, u32 word, u8 bits)
85{ 85{
86 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 86 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
87} 87}
88 88
89static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, 89static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
90 unsigned nsecs, u32 word, u8 bits) 90 unsigned nsecs, u32 word, u8 bits)
91{ 91{
92 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 92 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
93} 93}
94 94
95static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, 95static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
96 unsigned nsecs, u32 word, u8 bits) 96 unsigned nsecs, u32 word, u8 bits)
97{ 97{
98 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 98 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
99} 99}
100 100
101static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, 101static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
102 unsigned nsecs, u32 word, u8 bits) 102 unsigned nsecs, u32 word, u8 bits)
103{ 103{
104 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 104 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
105} 105}
106 106
107static void sh_sci_spi_chipselect(struct spi_device *dev, int value) 107static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index af56071b06f9..ae0a5286f558 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -262,6 +262,13 @@ struct spi_master {
262#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */ 262#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */
263#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */ 263#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */
264 264
265 /* lock and mutex for SPI bus locking */
266 spinlock_t bus_lock_spinlock;
267 struct mutex bus_lock_mutex;
268
269 /* flag indicating that the SPI bus is locked for exclusive use */
270 bool bus_lock_flag;
271
265 /* Setup mode and clock, etc (spi driver may call many times). 272 /* Setup mode and clock, etc (spi driver may call many times).
266 * 273 *
267 * IMPORTANT: this may be called when transfers to another 274 * IMPORTANT: this may be called when transfers to another
@@ -542,6 +549,8 @@ static inline void spi_message_free(struct spi_message *m)
542 549
543extern int spi_setup(struct spi_device *spi); 550extern int spi_setup(struct spi_device *spi);
544extern int spi_async(struct spi_device *spi, struct spi_message *message); 551extern int spi_async(struct spi_device *spi, struct spi_message *message);
552extern int spi_async_locked(struct spi_device *spi,
553 struct spi_message *message);
545 554
546/*---------------------------------------------------------------------------*/ 555/*---------------------------------------------------------------------------*/
547 556
@@ -551,6 +560,9 @@ extern int spi_async(struct spi_device *spi, struct spi_message *message);
551 */ 560 */
552 561
553extern int spi_sync(struct spi_device *spi, struct spi_message *message); 562extern int spi_sync(struct spi_device *spi, struct spi_message *message);
563extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message);
564extern int spi_bus_lock(struct spi_master *master);
565extern int spi_bus_unlock(struct spi_master *master);
554 566
555/** 567/**
556 * spi_write - SPI synchronous write 568 * spi_write - SPI synchronous write
diff --git a/include/linux/spi/spi_gpio.h b/include/linux/spi/spi_gpio.h
index ca6782ee4b9f..369b3d7d5b95 100644
--- a/include/linux/spi/spi_gpio.h
+++ b/include/linux/spi/spi_gpio.h
@@ -29,11 +29,16 @@
29 * SPI_GPIO_NO_CHIPSELECT to the controller_data: 29 * SPI_GPIO_NO_CHIPSELECT to the controller_data:
30 * .controller_data = (void *) SPI_GPIO_NO_CHIPSELECT; 30 * .controller_data = (void *) SPI_GPIO_NO_CHIPSELECT;
31 * 31 *
32 * If the MISO or MOSI pin is not available then it should be set to
33 * SPI_GPIO_NO_MISO or SPI_GPIO_NO_MOSI.
34 *
32 * If the bitbanged bus is later switched to a "native" controller, 35 * If the bitbanged bus is later switched to a "native" controller,
33 * that platform_device and controller_data should be removed. 36 * that platform_device and controller_data should be removed.
34 */ 37 */
35 38
36#define SPI_GPIO_NO_CHIPSELECT ((unsigned long)-1l) 39#define SPI_GPIO_NO_CHIPSELECT ((unsigned long)-1l)
40#define SPI_GPIO_NO_MISO ((unsigned long)-1l)
41#define SPI_GPIO_NO_MOSI ((unsigned long)-1l)
37 42
38/** 43/**
39 * struct spi_gpio_platform_data - parameter for bitbanged SPI master 44 * struct spi_gpio_platform_data - parameter for bitbanged SPI master