aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/spi/spi-summary8
-rw-r--r--drivers/spi/spi.c46
-rw-r--r--include/linux/spi/spi.h8
3 files changed, 34 insertions, 28 deletions
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
index f21edb983413..f72e0d1e0da8 100644
--- a/Documentation/spi/spi-summary
+++ b/Documentation/spi/spi-summary
@@ -34,7 +34,7 @@ SPI slave functions are usually not interoperable between vendors
34 - It may also be used to stream data in either direction (half duplex), 34 - It may also be used to stream data in either direction (half duplex),
35 or both of them at the same time (full duplex). 35 or both of them at the same time (full duplex).
36 36
37 - Some devices may use eight bit words. Others may different word 37 - Some devices may use eight bit words. Others may use different word
38 lengths, such as streams of 12-bit or 20-bit digital samples. 38 lengths, such as streams of 12-bit or 20-bit digital samples.
39 39
40 - Words are usually sent with their most significant bit (MSB) first, 40 - Words are usually sent with their most significant bit (MSB) first,
@@ -121,7 +121,7 @@ active. So the master must set the clock to inactive before selecting
121a slave, and the slave can tell the chosen polarity by sampling the 121a slave, and the slave can tell the chosen polarity by sampling the
122clock level when its select line goes active. That's why many devices 122clock level when its select line goes active. That's why many devices
123support for example both modes 0 and 3: they don't care about polarity, 123support for example both modes 0 and 3: they don't care about polarity,
124and alway clock data in/out on rising clock edges. 124and always clock data in/out on rising clock edges.
125 125
126 126
127How do these driver programming interfaces work? 127How do these driver programming interfaces work?
@@ -139,7 +139,7 @@ a command and then reading its response.
139 139
140There are two types of SPI driver, here called: 140There are two types of SPI driver, here called:
141 141
142 Controller drivers ... controllers may be built in to System-On-Chip 142 Controller drivers ... controllers may be built into System-On-Chip
143 processors, and often support both Master and Slave roles. 143 processors, and often support both Master and Slave roles.
144 These drivers touch hardware registers and may use DMA. 144 These drivers touch hardware registers and may use DMA.
145 Or they can be PIO bitbangers, needing just GPIO pins. 145 Or they can be PIO bitbangers, needing just GPIO pins.
@@ -548,7 +548,7 @@ SPI MASTER METHODS
548 DEPRECATED METHODS 548 DEPRECATED METHODS
549 549
550 master->transfer(struct spi_device *spi, struct spi_message *message) 550 master->transfer(struct spi_device *spi, struct spi_message *message)
551 This must not sleep. Its responsibility is arrange that the 551 This must not sleep. Its responsibility is to arrange that the
552 transfer happens and its complete() callback is issued. The two 552 transfer happens and its complete() callback is issued. The two
553 will normally happen later, after other transfers complete, and 553 will normally happen later, after other transfers complete, and
554 if the controller is idle it will need to be kickstarted. This 554 if the controller is idle it will need to be kickstarted. This
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 965dd8ac5939..63613a96233c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -695,7 +695,7 @@ static void spi_pump_messages(struct kthread_work *work)
695 } 695 }
696 /* Extract head of queue */ 696 /* Extract head of queue */
697 master->cur_msg = 697 master->cur_msg =
698 list_entry(master->queue.next, struct spi_message, queue); 698 list_first_entry(&master->queue, struct spi_message, queue);
699 699
700 list_del_init(&master->cur_msg->queue); 700 list_del_init(&master->cur_msg->queue);
701 if (master->busy) 701 if (master->busy)
@@ -803,11 +803,8 @@ struct spi_message *spi_get_next_queued_message(struct spi_master *master)
803 803
804 /* get a pointer to the next message, if any */ 804 /* get a pointer to the next message, if any */
805 spin_lock_irqsave(&master->queue_lock, flags); 805 spin_lock_irqsave(&master->queue_lock, flags);
806 if (list_empty(&master->queue)) 806 next = list_first_entry_or_null(&master->queue, struct spi_message,
807 next = NULL; 807 queue);
808 else
809 next = list_entry(master->queue.next,
810 struct spi_message, queue);
811 spin_unlock_irqrestore(&master->queue_lock, flags); 808 spin_unlock_irqrestore(&master->queue_lock, flags);
812 809
813 return next; 810 return next;
@@ -1608,15 +1605,11 @@ int spi_setup(struct spi_device *spi)
1608} 1605}
1609EXPORT_SYMBOL_GPL(spi_setup); 1606EXPORT_SYMBOL_GPL(spi_setup);
1610 1607
1611static int __spi_async(struct spi_device *spi, struct spi_message *message) 1608static int __spi_validate(struct spi_device *spi, struct spi_message *message)
1612{ 1609{
1613 struct spi_master *master = spi->master; 1610 struct spi_master *master = spi->master;
1614 struct spi_transfer *xfer; 1611 struct spi_transfer *xfer;
1615 1612
1616 message->spi = spi;
1617
1618 trace_spi_message_submit(message);
1619
1620 if (list_empty(&message->transfers)) 1613 if (list_empty(&message->transfers))
1621 return -EINVAL; 1614 return -EINVAL;
1622 if (!message->complete) 1615 if (!message->complete)
@@ -1679,9 +1672,8 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1679 if (xfer->rx_buf && !xfer->rx_nbits) 1672 if (xfer->rx_buf && !xfer->rx_nbits)
1680 xfer->rx_nbits = SPI_NBITS_SINGLE; 1673 xfer->rx_nbits = SPI_NBITS_SINGLE;
1681 /* check transfer tx/rx_nbits: 1674 /* check transfer tx/rx_nbits:
1682 * 1. keep the value is not out of single, dual and quad 1675 * 1. check the value matches one of single, dual and quad
1683 * 2. keep tx/rx_nbits is contained by mode in spi_device 1676 * 2. check tx/rx_nbits match the mode in spi_device
1684 * 3. if SPI_3WIRE, tx/rx_nbits should be in single
1685 */ 1677 */
1686 if (xfer->tx_buf) { 1678 if (xfer->tx_buf) {
1687 if (xfer->tx_nbits != SPI_NBITS_SINGLE && 1679 if (xfer->tx_nbits != SPI_NBITS_SINGLE &&
@@ -1694,9 +1686,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1694 if ((xfer->tx_nbits == SPI_NBITS_QUAD) && 1686 if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
1695 !(spi->mode & SPI_TX_QUAD)) 1687 !(spi->mode & SPI_TX_QUAD))
1696 return -EINVAL; 1688 return -EINVAL;
1697 if ((spi->mode & SPI_3WIRE) &&
1698 (xfer->tx_nbits != SPI_NBITS_SINGLE))
1699 return -EINVAL;
1700 } 1689 }
1701 /* check transfer rx_nbits */ 1690 /* check transfer rx_nbits */
1702 if (xfer->rx_buf) { 1691 if (xfer->rx_buf) {
@@ -1710,13 +1699,22 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1710 if ((xfer->rx_nbits == SPI_NBITS_QUAD) && 1699 if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
1711 !(spi->mode & SPI_RX_QUAD)) 1700 !(spi->mode & SPI_RX_QUAD))
1712 return -EINVAL; 1701 return -EINVAL;
1713 if ((spi->mode & SPI_3WIRE) &&
1714 (xfer->rx_nbits != SPI_NBITS_SINGLE))
1715 return -EINVAL;
1716 } 1702 }
1717 } 1703 }
1718 1704
1719 message->status = -EINPROGRESS; 1705 message->status = -EINPROGRESS;
1706
1707 return 0;
1708}
1709
1710static int __spi_async(struct spi_device *spi, struct spi_message *message)
1711{
1712 struct spi_master *master = spi->master;
1713
1714 message->spi = spi;
1715
1716 trace_spi_message_submit(message);
1717
1720 return master->transfer(spi, message); 1718 return master->transfer(spi, message);
1721} 1719}
1722 1720
@@ -1755,6 +1753,10 @@ int spi_async(struct spi_device *spi, struct spi_message *message)
1755 int ret; 1753 int ret;
1756 unsigned long flags; 1754 unsigned long flags;
1757 1755
1756 ret = __spi_validate(spi, message);
1757 if (ret != 0)
1758 return ret;
1759
1758 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 1760 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
1759 1761
1760 if (master->bus_lock_flag) 1762 if (master->bus_lock_flag)
@@ -1803,6 +1805,10 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)
1803 int ret; 1805 int ret;
1804 unsigned long flags; 1806 unsigned long flags;
1805 1807
1808 ret = __spi_validate(spi, message);
1809 if (ret != 0)
1810 return ret;
1811
1806 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 1812 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
1807 1813
1808 ret = __spi_async(spi, message); 1814 ret = __spi_async(spi, message);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 9f5242df9311..a1d4ca290862 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -75,6 +75,7 @@ struct spi_device {
75 struct spi_master *master; 75 struct spi_master *master;
76 u32 max_speed_hz; 76 u32 max_speed_hz;
77 u8 chip_select; 77 u8 chip_select;
78 u8 bits_per_word;
78 u16 mode; 79 u16 mode;
79#define SPI_CPHA 0x01 /* clock phase */ 80#define SPI_CPHA 0x01 /* clock phase */
80#define SPI_CPOL 0x02 /* clock polarity */ 81#define SPI_CPOL 0x02 /* clock polarity */
@@ -92,7 +93,6 @@ struct spi_device {
92#define SPI_TX_QUAD 0x200 /* transmit with 4 wires */ 93#define SPI_TX_QUAD 0x200 /* transmit with 4 wires */
93#define SPI_RX_DUAL 0x400 /* receive with 2 wires */ 94#define SPI_RX_DUAL 0x400 /* receive with 2 wires */
94#define SPI_RX_QUAD 0x800 /* receive with 4 wires */ 95#define SPI_RX_QUAD 0x800 /* receive with 4 wires */
95 u8 bits_per_word;
96 int irq; 96 int irq;
97 void *controller_state; 97 void *controller_state;
98 void *controller_data; 98 void *controller_data;
@@ -578,8 +578,8 @@ struct spi_transfer {
578 dma_addr_t rx_dma; 578 dma_addr_t rx_dma;
579 579
580 unsigned cs_change:1; 580 unsigned cs_change:1;
581 u8 tx_nbits; 581 unsigned tx_nbits:3;
582 u8 rx_nbits; 582 unsigned rx_nbits:3;
583#define SPI_NBITS_SINGLE 0x01 /* 1bit transfer */ 583#define SPI_NBITS_SINGLE 0x01 /* 1bit transfer */
584#define SPI_NBITS_DUAL 0x02 /* 2bits transfer */ 584#define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
585#define SPI_NBITS_QUAD 0x04 /* 4bits transfer */ 585#define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
@@ -849,7 +849,7 @@ static inline ssize_t spi_w8r16(struct spi_device *spi, u8 cmd)
849 ssize_t status; 849 ssize_t status;
850 u16 result; 850 u16 result;
851 851
852 status = spi_write_then_read(spi, &cmd, 1, (u8 *) &result, 2); 852 status = spi_write_then_read(spi, &cmd, 1, &result, 2);
853 853
854 /* return negative errno or unsigned value */ 854 /* return negative errno or unsigned value */
855 return (status < 0) ? status : result; 855 return (status < 0) ? status : result;