aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
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 /drivers/spi
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.
Diffstat (limited to 'drivers/spi')
-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
11 files changed, 325 insertions, 99 deletions
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)