1 From f52838cd03de045aa67cc1a0c1614ea5bfb30fcc Mon Sep 17 00:00:00 2001
2 From: Alan Olsen <alan.r.olsen@intel.com>
3 Date: Wed, 11 Nov 2009 13:12:42 -0800
4 Subject: [PATCH 065/104] Moorestown SPI Slave Controller driver v1.1 consolidation patch
6 This patch contains the following patches:
8 Alpha2-1.0-1-1-mrst-SPI-Slave-Core-Driver-K29.patch
10 [PATCH] SPI Slave Support Added to SPI Core Driver
12 Signed-off-by: Pranav K. Sanghadia <pranav.k.sanghadia@intel.com>
14 Alpha2-1.0-1-1-mrst-SPI-Slave-controller-driver.patch
16 [PATCH] SPI slave controller driver for Moorestown platform
18 This driver currently supports only programmed IO mode.
22 CONFIG_SPI_MRST_SLAVE=y
23 CONFIG_SPI_MRST_SLAVE_DMA is not set
25 Signed-off-by: Ken Mills <ken.k.mills@intel.com>
27 Alpha2-1.0-1-1-DMA-Support-added-in-SPI-Slave-Controller-Driver.patch
29 [PATCH] This patch adds DMA support for SPI Slave Controller Driver. DMA provides
30 highspeed data transfer between SPI-SSP and external Master mode device
32 Signed-off-by: Pranav K. Sanghadia <pranav.k.sanghadia@intel.com>
34 Alpha2-1.0-1-1-mrst-SPI-Slave-controller-fix-DMA-Issue.patch
36 [PATCH] Alpha2-1.0-1-1-mrst-SPI-Slave-controller-fix-DMA-Issue.patch
38 [PATCH] Optimized SSP clock bitbang routine
40 Signed-off-by: Ken Mills <ken.k.mills@intel.com>
42 Signed-off-by: Alan Olsen <alan.r.olsen@intel.com>
44 drivers/spi/Kconfig | 11 +
45 drivers/spi/Makefile | 1 +
46 drivers/spi/mrst_spi_slave.c | 1227 ++++++++++++++++++++++++++++++++++++
47 drivers/spi/spi.c | 403 +++++++++++-
48 include/linux/spi/mrst_spi_slave.h | 143 +++++
49 include/linux/spi/spi.h | 98 +++-
50 6 files changed, 1862 insertions(+), 21 deletions(-)
51 create mode 100644 drivers/spi/mrst_spi_slave.c
52 create mode 100644 include/linux/spi/mrst_spi_slave.h
54 diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
55 index 9d4ff53..b94445b 100644
56 --- a/drivers/spi/Kconfig
57 +++ b/drivers/spi/Kconfig
58 @@ -360,5 +360,16 @@ config SPI_TLE62X0
61 # (slave support would go here)
62 +config SPI_MRST_SLAVE
63 + tristate "SPI slave controller driver for Intel Moorestown platform "
64 + depends on SPI_MASTER
66 + This is the SPI slave controller driver for Intel Moorestown platform
68 +config SPI_MRST_SLAVE_DMA
69 + boolean "Enable DMA for MRST SPI Slave Controller"
70 + depends on INTEL_LNW_DMAC1
72 + This has to be enabled after Moorestown DMAC1 driver is enabled
75 diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
76 index c78cb77..8acdd96 100644
77 --- a/drivers/spi/Makefile
78 +++ b/drivers/spi/Makefile
79 @@ -56,6 +56,7 @@ obj-$(CONFIG_SPI_TLE62X0) += tle62x0.o
80 # ... add above this line ...
82 # SPI slave controller drivers (upstream link)
83 +obj-$(CONFIG_SPI_MRST_SLAVE) += mrst_spi_slave.o
84 # ... add above this line ...
86 # SPI slave drivers (protocol for that link)
87 diff --git a/drivers/spi/mrst_spi_slave.c b/drivers/spi/mrst_spi_slave.c
89 index 0000000..82a50b7
91 +++ b/drivers/spi/mrst_spi_slave.c
94 + * mrst_spi_slave.c - Moorestown SPI slave controller driver
95 + * based on pxa2xx_spi.c
97 + * Copyright (C) Intel 2009
98 + * Ken Mills <ken.k.mills@intel.com>
100 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102 + * This program is free software; you can redistribute it and/or modify
103 + * it under the terms of the GNU General Public License as published by
104 + * the Free Software Foundation; either version 2 of the License, or
105 + * (at your option) any later version.
107 + * This program is distributed in the hope that it will be useful,
108 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
109 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110 + * GNU General Public License for more details.
112 + * You should have received a copy of the GNU General Public License
113 + * along with this program; if not, write to the Free Software
114 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
116 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123 + * Supports interrupt programmed I/O, DMA and non-interrupt polled transfers.
127 +#include <linux/delay.h>
128 +#include <linux/highmem.h>
129 +#include <linux/pci.h>
130 +#include <linux/interrupt.h>
132 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
133 +#include <linux/dma-mapping.h>
134 +#include <linux/lnw_dma.h>
137 +#include <linux/spi/spi.h>
138 +#include <linux/spi/mrst_spi_slave.h>
141 +#define DRIVER_NAME "mrst_spi_slave"
143 +#define SSP_NOT_SYNC 0x400000
146 +MODULE_DESCRIPTION("Moorestown SPI Slave Contoller");
147 +MODULE_LICENSE("GPL");
150 + * For testing SSCR1 changes that require SSP restart, basically
151 + * everything except the service and interrupt enables
153 +#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_EBCEI | SSCR1_SCFR \
154 + | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
156 + | SSCR1_RWOT | SSCR1_TRAIL | SSCR1_PINTE \
157 + | SSCR1_STRF | SSCR1_EFWR | SSCR1_RFT \
158 + | SSCR1_TFT | SSCR1_SPH | SSCR1_SPO)
160 +#define DEFINE_SSP_REG(reg, off) \
161 +static inline u32 read_##reg(void *p) { return __raw_readl(p + (off)); } \
162 +static inline void write_##reg(u32 v, void *p) { __raw_writel(v, p + (off)); }
164 +DEFINE_SSP_REG(SSCR0, 0x00)
165 +DEFINE_SSP_REG(SSCR1, 0x04)
166 +DEFINE_SSP_REG(SSSR, 0x08)
167 +DEFINE_SSP_REG(SSITR, 0x0c)
168 +DEFINE_SSP_REG(SSDR, 0x10)
169 +DEFINE_SSP_REG(SSTO, 0x28)
170 +DEFINE_SSP_REG(SSPSP, 0x2c)
172 +DEFINE_SSP_REG(IPCCSR, 0x00);
173 +DEFINE_SSP_REG(IPCPISR, 0x08);
174 +DEFINE_SSP_REG(IPCPIMR, 0x10);
176 +DEFINE_SSP_REG(I2CCTRL, 0x00);
177 +DEFINE_SSP_REG(I2CDATA, 0x04);
179 +DEFINE_SSP_REG(GPLR1, 0x04);
180 +DEFINE_SSP_REG(GPDR1, 0x0c);
181 +DEFINE_SSP_REG(GPSR1, 0x14);
182 +DEFINE_SSP_REG(GPCR1, 0x1C);
183 +DEFINE_SSP_REG(GAFR1_U, 0x44);
185 +#define START_STATE ((void *)0)
186 +#define RUNNING_STATE ((void *)1)
187 +#define DONE_STATE ((void *)2)
188 +#define ERROR_STATE ((void *)-1)
190 +struct driver_data {
191 + /* Driver model hookup */
192 + struct pci_dev *pdev;
194 + /* SPI framework hookup */
195 + struct spi_slave *slave;
197 + /* SSP register addresses */
203 + /* IPC registers */
207 + /* I2C registers */
217 + struct tasklet_struct poll_transfer;
223 + /* Current message transfer state info */
224 + struct spi_message *cur_msg;
236 + int (*write)(struct driver_data *drv_data);
237 + int (*read)(struct driver_data *drv_data);
238 + irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
239 + void (*cs_control)(u32 command);
241 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
242 + struct lnw_dma_slave dmas_tx;
243 + struct lnw_dma_slave dmas_rx;
244 + struct dma_chan *txchan;
245 + struct dma_chan *rxchan;
251 + struct pci_dev *dmac1;
263 + u8 poll_mode; /* 1 means use poll mode */
265 + int (*write)(struct driver_data *drv_data);
266 + int (*read)(struct driver_data *drv_data);
269 +static void flush(struct driver_data *drv_data)
271 + void *reg = drv_data->ioaddr;
274 + /* If the transmit fifo is not empty, reset the interface. */
275 + sssr = read_SSSR(reg);
276 + if ((sssr & 0xf00) || (sssr & SSSR_TNF) == 0) {
277 + write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
281 + while (read_SSSR(reg) & SSSR_RNE)
284 + write_SSSR(SSSR_ROR, reg);
285 + write_SSSR(SSSR_TUR, reg);
290 +static int null_writer(struct driver_data *drv_data)
292 + void *reg = drv_data->ioaddr;
293 + u8 n_bytes = drv_data->n_bytes;
295 + if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
296 + || (drv_data->tx == drv_data->tx_end))
299 + write_SSDR(0, reg);
300 + drv_data->tx += n_bytes;
305 +static int null_reader(struct driver_data *drv_data)
307 + void *reg = drv_data->ioaddr;
308 + u8 n_bytes = drv_data->n_bytes;
310 + while ((read_SSSR(reg) & SSSR_RNE)
311 + && (drv_data->rx < drv_data->rx_end)) {
313 + drv_data->rx += n_bytes;
316 + return drv_data->rx == drv_data->rx_end;
319 +static int u8_writer(struct driver_data *drv_data)
321 + void *reg = drv_data->ioaddr;
322 + if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
323 + || (drv_data->tx == drv_data->tx_end))
326 + write_SSDR(*(u8 *)(drv_data->tx), reg);
332 +static int u8_reader(struct driver_data *drv_data)
334 + void *reg = drv_data->ioaddr;
335 + while ((read_SSSR(reg) & SSSR_RNE)
336 + && (drv_data->rx < drv_data->rx_end)) {
337 + *(u8 *)(drv_data->rx) = read_SSDR(reg);
341 + return drv_data->rx == drv_data->rx_end;
344 +static int u16_writer(struct driver_data *drv_data)
346 + void *reg = drv_data->ioaddr;
347 + if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
348 + || (drv_data->tx == drv_data->tx_end))
351 + write_SSDR(*(u16 *)(drv_data->tx), reg);
357 +static int u16_reader(struct driver_data *drv_data)
359 + void *reg = drv_data->ioaddr;
360 + while ((read_SSSR(reg) & SSSR_RNE)
361 + && (drv_data->rx < drv_data->rx_end)) {
362 + *(u16 *)(drv_data->rx) = read_SSDR(reg);
366 + return drv_data->rx == drv_data->rx_end;
369 +static int u32_writer(struct driver_data *drv_data)
371 + void *reg = drv_data->ioaddr;
372 + if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
373 + || (drv_data->tx == drv_data->tx_end))
376 + write_SSDR(*(u32 *)(drv_data->tx), reg);
382 +static int u32_reader(struct driver_data *drv_data)
384 + void *reg = drv_data->ioaddr;
385 + while ((read_SSSR(reg) & SSSR_RNE)
386 + && (drv_data->rx < drv_data->rx_end)) {
387 + *(u32 *)(drv_data->rx) = read_SSDR(reg);
391 + return drv_data->rx == drv_data->rx_end;
396 +/* caller already set message->status; dma and pio irqs are blocked */
397 +static void giveback(struct driver_data *drv_data)
399 + struct spi_message *msg;
401 + msg = drv_data->cur_msg;
404 + msg->complete(msg->context);
407 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
409 +static bool chan_filter(struct dma_chan *chan, void *param)
411 + struct driver_data *drv_data = (struct driver_data *)param;
414 + if (!drv_data->dmac1)
417 + if (chan->device->dev == &drv_data->dmac1->dev)
423 +static void int_transfer_complete(struct driver_data *drv_data);
425 +static void mrst_spi_dma_done(void *arg)
428 + struct driver_data *drv_data;
431 + drv_data = (struct driver_data *)(u32)(*param >> 32);
432 + done = (int *)(u32)(*param & 0xffffffff);
435 + if (!drv_data->txdma_done || !drv_data->rxdma_done)
437 + int_transfer_complete(drv_data);
440 +static void mrst_spi_dma_init(struct driver_data *drv_data)
442 + struct lnw_dma_slave *rxs, *txs;
443 + dma_cap_mask_t mask;
446 + drv_data->dmac1 = pci_get_device(PCI_VENDOR_ID_INTEL, 0x0814, NULL);
447 + if (!drv_data->dmac1) {
448 + printk(KERN_WARNING "SPI Slave:Can't find DMAC1\n");
452 + /* 1. init rx channel */
453 + rxs = &drv_data->dmas_rx;
455 + rxs->dirn = DMA_FROM_DEVICE;
456 + rxs->hs_mode = LNW_DMA_HW_HS;
457 + rxs->cfg_mode = LNW_DMA_PER_TO_MEM;
458 + rxs->src_width = LNW_DMA_WIDTH_16BIT;
459 + rxs->dst_width = LNW_DMA_WIDTH_32BIT;
460 + rxs->src_msize = LNW_DMA_MSIZE_8;
461 + rxs->dst_msize = LNW_DMA_MSIZE_8;
464 + dma_cap_zero(mask);
465 + dma_cap_set(DMA_MEMCPY, mask);
466 + dma_cap_set(DMA_SLAVE, mask);
468 + drv_data->rxchan = dma_request_channel(mask, chan_filter, drv_data);
469 + if (!drv_data->rxchan)
472 + drv_data->rxchan->private = rxs;
474 + /* 2. init tx channel */
475 + txs = &drv_data->dmas_tx;
477 + txs->dirn = DMA_TO_DEVICE;
478 + txs->hs_mode = LNW_DMA_HW_HS;
479 + txs->cfg_mode = LNW_DMA_MEM_TO_PER;
480 + txs->src_width = LNW_DMA_WIDTH_32BIT;
481 + txs->dst_width = LNW_DMA_WIDTH_16BIT;
482 + txs->src_msize = LNW_DMA_MSIZE_8;
483 + txs->dst_msize = LNW_DMA_MSIZE_8;
486 + dma_cap_set(DMA_SLAVE, mask);
487 + dma_cap_set(DMA_MEMCPY, mask);
489 + drv_data->txchan = dma_request_channel(mask, chan_filter, drv_data);
490 + if (!drv_data->txchan)
494 + drv_data->txchan->private = txs;
496 + /* set the dma done bit to 1 */
497 + drv_data->txdma_done = 1;
498 + drv_data->rxdma_done = 1;
500 + drv_data->tx_param = ((u64)(u32)drv_data << 32)
501 + | (u32)(&drv_data->txdma_done);
502 + drv_data->rx_param = ((u64)(u32)drv_data << 32)
503 + | (u32)(&drv_data->rxdma_done);
507 + printk(KERN_ERR "SPI-Slave Error : DMA Channle Not available\n");
508 + dma_release_channel(drv_data->rxchan);
510 + printk(KERN_ERR "SPI-Slave Error : DMA Channel Not available\n");
511 + pci_dev_put(drv_data->dmac1);
515 +static void mrst_spi_dma_exit(struct driver_data *drv_data)
517 + dma_release_channel(drv_data->txchan);
518 + dma_release_channel(drv_data->rxchan);
519 + pci_dev_put(drv_data->dmac1);
522 +static void dma_transfer(struct driver_data *drv_data)
524 + dma_addr_t ssdr_addr;
525 + struct dma_async_tx_descriptor *txdesc = NULL, *rxdesc = NULL;
526 + struct dma_chan *txchan, *rxchan;
527 + enum dma_ctrl_flags flag;
529 + /* get Data Read/Write address */
530 + ssdr_addr = (dma_addr_t)(u32)(drv_data->paddr + 0x10);
532 + if (drv_data->tx_dma)
533 + drv_data->txdma_done = 0;
535 + if (drv_data->rx_dma)
536 + drv_data->rxdma_done = 0;
538 + /* 2. start the TX dma transfer */
539 + txchan = drv_data->txchan;
540 + rxchan = drv_data->rxchan;
542 + flag = DMA_PREP_INTERRUPT | DMA_CTRL_ACK;
544 + if (drv_data->rx_dma) {
545 + rxdesc = rxchan->device->device_prep_dma_memcpy
546 + (rxchan, /* DMA Channel */
547 + drv_data->rx_dma, /* DAR */
548 + ssdr_addr, /* SAR */
549 + drv_data->len, /* Data Length */
552 + rxdesc->callback = mrst_spi_dma_done;
553 + rxdesc->callback_param = &drv_data->rx_param;
556 + /* 3. start the RX dma transfer */
557 + if (drv_data->tx_dma) {
558 + txdesc = txchan->device->device_prep_dma_memcpy
559 + (txchan, /* DMA Channel */
560 + ssdr_addr, /* DAR */
561 + drv_data->tx_dma, /* SAR */
562 + drv_data->len, /* Data Length */
565 + txdesc->callback = mrst_spi_dma_done;
566 + txdesc->callback_param = &drv_data->tx_param;
570 + rxdesc->tx_submit(rxdesc);
572 + txdesc->tx_submit(txdesc);
576 +static int map_dma_buffers(struct driver_data *drv_data)
578 + drv_data->rx_dma = (dma_addr_t) virt_to_phys(drv_data->rx);
579 + drv_data->tx_dma = (dma_addr_t) virt_to_phys(drv_data->tx);
584 +static void int_error_stop(struct driver_data *drv_data, const char* msg)
586 + void *reg = drv_data->ioaddr;
588 + /* Stop and reset SSP */
589 + write_SSSR(drv_data->clear_sr, reg);
590 + write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
591 + write_SSTO(0, reg);
594 + dev_err(&drv_data->pdev->dev, "%s\n", msg);
596 + drv_data->cur_msg->state = ERROR_STATE;
599 +static void int_transfer_complete(struct driver_data *drv_data)
601 + void *reg = drv_data->ioaddr;
603 + /* Clear Status Register */
604 + write_SSSR(drv_data->clear_sr, reg);
606 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
607 + /* Disable Triggers to DMA */
608 + write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
610 + /* Disable Interrupt */
611 + write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
613 + /* Stop getting Time Outs */
614 + write_SSTO(0, reg);
616 + /* Update total byte transfered return count actual bytes read */
617 + drv_data->cur_msg->actual_length += drv_data->len -
618 + (drv_data->rx_end - drv_data->rx);
620 + drv_data->cur_msg->status = 0;
621 + giveback(drv_data);
624 +static void transfer_complete(struct driver_data *drv_data)
626 + /* Update total byte transfered return count actual bytes read */
627 + drv_data->cur_msg->actual_length +=
628 + drv_data->len - (drv_data->rx_end - drv_data->rx);
630 + drv_data->cur_msg->status = 0;
631 + giveback(drv_data);
634 +static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
636 + void *reg = drv_data->ioaddr;
637 + u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
638 + drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
640 + u32 irq_status = read_SSSR(reg) & irq_mask;
641 + if (irq_status & SSSR_ROR) {
642 + int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
643 + return IRQ_HANDLED;
646 + if (irq_status & SSSR_TINT) {
647 + write_SSSR(SSSR_TINT, reg);
648 + if (drv_data->read(drv_data)) {
649 + int_transfer_complete(drv_data);
650 + return IRQ_HANDLED;
654 + /* Drain rx fifo, Fill tx fifo and prevent overruns */
656 + if (drv_data->read(drv_data)) {
657 + int_transfer_complete(drv_data);
658 + return IRQ_HANDLED;
660 + } while (drv_data->write(drv_data));
662 + if (drv_data->read(drv_data)) {
663 + int_transfer_complete(drv_data);
664 + return IRQ_HANDLED;
667 + if (drv_data->tx == drv_data->tx_end)
668 + write_SSCR1(read_SSCR1(reg) & ~SSCR1_TIE, reg);
670 + return IRQ_HANDLED;
673 +static irqreturn_t ssp_int(int irq, void *dev_id)
675 + struct driver_data *drv_data = dev_id;
676 + void *reg = drv_data->ioaddr;
677 + u32 status = read_SSSR(reg);
679 + #ifdef CONFIG_SPI_MRST_SLAVE_DMA
680 + if (status & SSSR_ROR || status & SSSR_TUR) {
681 + printk(KERN_DEBUG "--- SPI ROR or TUR Occred : SSSR=%x\n", status);
682 + write_SSSR(SSSR_ROR, reg); /* Clear ROR */
683 + write_SSSR(SSSR_TUR, reg); /* Clear TUR */
684 + return IRQ_HANDLED;
688 + /* just return if this is not our interrupt */
689 + if (!(read_SSSR(reg) & drv_data->mask_sr))
692 + if (!drv_data->cur_msg) {
693 + write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
694 + write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
695 + write_SSSR(drv_data->clear_sr, reg);
698 + return IRQ_HANDLED;
700 + return drv_data->transfer_handler(drv_data);
703 +static void poll_transfer(unsigned long data)
705 + struct driver_data *drv_data = (struct driver_data *)data;
708 + while (drv_data->tx != drv_data->tx_end) {
709 + drv_data->write(drv_data);
710 + drv_data->read(drv_data);
713 + while (!drv_data->read(drv_data))
716 + transfer_complete(drv_data);
719 +static int transfer(struct spi_device *spi, struct spi_message *msg)
721 + struct driver_data *drv_data = \
722 + spi_slave_get_devdata(spi->slave);
723 + unsigned long flags;
724 + struct chip_data *chip = NULL;
725 + struct spi_transfer *transfer = NULL;
726 + void *reg = drv_data->ioaddr;
727 + void *i2cReg = drv_data->I2C_ioaddr;
734 + spin_lock_irqsave(&drv_data->lock, flags);
735 + msg->actual_length = 0;
736 + msg->status = -EINPROGRESS;
737 + drv_data->cur_msg = msg;
738 + /* Initial message state*/
739 + msg->state = START_STATE;
741 + /* We handle only one transfer message since the protocol module has to
742 + control the out of band signaling. */
743 + transfer = list_entry(msg->transfers.next,
744 + struct spi_transfer,
747 + chip = spi_get_ctldata(msg->spi);
749 + drv_data->busy = 1;
751 + /* Check transfer length */
752 + if (transfer->len > 8192) {
753 + dev_warn(&drv_data->pdev->dev, "SPI-SLAVE: transfer "
754 + "length greater than 8192\n");
755 + msg->status = -EINVAL;
756 + giveback(drv_data);
757 + spin_unlock_irqrestore(&drv_data->lock, flags);
761 + /* Setup the transfer state based on the type of transfer */
763 + drv_data->n_bytes = chip->n_bytes;
764 + drv_data->tx = (void *)transfer->tx_buf;
765 + drv_data->tx_end = drv_data->tx + transfer->len;
766 + drv_data->rx = transfer->rx_buf;
767 + drv_data->rx_end = drv_data->rx + transfer->len;
768 + drv_data->rx_dma = transfer->rx_dma;
769 + drv_data->tx_dma = transfer->tx_dma;
770 + drv_data->len = transfer->len;
771 + drv_data->write = drv_data->tx ? chip->write : null_writer;
772 + drv_data->read = drv_data->rx ? chip->read : null_reader;
774 + /* Change speed and bit per word on a per transfer */
776 + if (transfer->bits_per_word) {
778 + bits = chip->bits_per_word;
782 + if (transfer->bits_per_word)
783 + bits = transfer->bits_per_word;
787 + drv_data->n_bytes = 1;
788 + drv_data->read = drv_data->read != null_reader ?
789 + u8_reader : null_reader;
790 + drv_data->write = drv_data->write != null_writer ?
791 + u8_writer : null_writer;
792 + } else if (bits <= 16) {
793 + drv_data->n_bytes = 2;
794 + drv_data->read = drv_data->read != null_reader ?
795 + u16_reader : null_reader;
796 + drv_data->write = drv_data->write != null_writer ?
797 + u16_writer : null_writer;
798 + } else if (bits <= 32) {
799 + drv_data->n_bytes = 4;
800 + drv_data->read = drv_data->read != null_reader ?
801 + u32_reader : null_reader;
802 + drv_data->write = drv_data->write != null_writer ?
803 + u32_writer : null_writer;
808 + | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
812 + | (bits > 16 ? SSCR0_EDSS : 0);
816 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
817 + drv_data->dma_mapped = 0;
818 + if (chip->enable_dma)
819 + drv_data->dma_mapped = map_dma_buffers(drv_data);
822 + msg->state = RUNNING_STATE;
823 + /* Ensure we have the correct interrupt handler */
824 + drv_data->transfer_handler = interrupt_transfer;
826 + cr1 = chip->cr1 | chip->threshold;
827 + write_SSSR(drv_data->clear_sr, reg);
829 + /* Reload the config and do bitbanging only if SSP not-enable or not-synchronized */
830 + if( ( read_SSSR(reg) & SSP_NOT_SYNC ) || (!(read_SSCR0(reg) & SSCR0_SSE) ) ) {
832 + write_SSSR(drv_data->clear_sr, reg); /* clear status */
833 + write_SSCR0(cr0 & ~SSCR0_SSE, reg);
834 + write_SSPSP(0x02010007, reg);
835 + write_SSTO(chip->timeout, reg);
836 + write_SSCR1(0x13001DC0, reg); /* TBD remove hardcoded value */
837 + write_SSCR0(cr0, reg);
840 + * This routine uses the DFx block to override the SSP inputs
841 + * and outputs allowing us to bit bang SSPSCLK. On Langwell,
842 + * we have to generate the clock to clear busy.
845 + write_I2CDATA(0x3, i2cReg);
847 + write_I2CCTRL(0x01070034, i2cReg);
849 + write_I2CDATA(0x00000099, i2cReg);
851 + write_I2CCTRL(0x01070038, i2cReg);
853 + sssr = read_SSSR(reg);
855 + /* Bit bang the clock until CSS clears */
856 + while (sssr & 0x400000) {
857 + write_I2CDATA(0x2, i2cReg);
859 + write_I2CCTRL(0x01070034, i2cReg);
861 + write_I2CDATA(0x3, i2cReg);
863 + write_I2CCTRL(0x01070034, i2cReg);
865 + sssr = read_SSSR(reg);
868 + write_I2CDATA(0x0, i2cReg);
870 + write_I2CCTRL(0x01070038, i2cReg);
873 + write_SSTO(chip->timeout, reg);
874 + write_SSCR1(0x13001DC0, reg); /* TBD: remove hardcoded value */
877 + /* transfer using DMA */
878 + if (drv_data->dma_mapped) {
879 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
880 + cr1 = cr1 | drv_data->dma_cr1;
881 + write_SSCR1(0x13701DC0, reg); /* TBD: remove hardcoded value */
882 + dma_transfer(drv_data);
886 + /* transfer using non interrupt polling */
887 + else if (chip->poll_mode)
888 + tasklet_schedule(&drv_data->poll_transfer);
890 + /* transfer using interrupt driven programmed I/O */
892 + cr1 = cr1 | drv_data->int_cr1;
893 + write_SSCR1(cr1, reg);
896 + spin_unlock_irqrestore(&drv_data->lock, flags);
900 +static int setup(struct spi_device *spi)
902 + struct mrst_spi_chip *chip_info = NULL;
903 + struct chip_data *chip;
905 + if (!spi->bits_per_word)
906 + spi->bits_per_word = 8;
908 + if ((spi->bits_per_word < 4 || spi->bits_per_word > 32))
911 + /* Only alloc on first setup */
912 + chip = spi_get_ctldata(spi);
914 + chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
917 + "failed setup: can't allocate chip data\n");
921 + chip->enable_dma = 1;
922 + chip->poll_mode = 1;
923 + chip->timeout = 1000;
924 + chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1);
928 + * protocol drivers may change the chip settings, so...
929 + * if chip_info exists, use it
931 + chip_info = spi->controller_data;
933 + /* chip_info isn't always needed */
937 + chip->timeout = chip_info->timeout;
939 + chip->threshold = (SSCR1_RxTresh(chip_info->rx_threshold) &
941 + (SSCR1_TxTresh(chip_info->tx_threshold) &
945 + if (chip_info->enable_loopback)
946 + chip->cr1 = SSCR1_LBM;
949 + chip->cr0 = SSCR0_Motorola
950 + | SSCR0_DataSize(spi->bits_per_word > 16 ?
951 + spi->bits_per_word - 16 : spi->bits_per_word)
955 + | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
956 + chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
957 + chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
958 + | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
959 + /* set slave mode */
960 + chip->cr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR;
961 + chip->cr1 |= SSCR1_SCFR; /* slave clock is not free running */
962 + dev_dbg(&spi->dev, "%d bits/word, mode %d\n",
963 + spi->bits_per_word,
966 + if (spi->bits_per_word <= 8) {
968 + chip->read = u8_reader;
969 + chip->write = u8_writer;
970 + } else if (spi->bits_per_word <= 16) {
972 + chip->read = u16_reader;
973 + chip->write = u16_writer;
974 + } else if (spi->bits_per_word <= 32) {
975 + chip->cr0 |= SSCR0_EDSS;
977 + chip->read = u32_reader;
978 + chip->write = u32_writer;
980 + dev_err(&spi->dev, "invalid wordsize\n");
983 + chip->bits_per_word = spi->bits_per_word;
984 + spi_set_ctldata(spi, chip);
989 +static void cleanup(struct spi_device *spi)
991 + struct chip_data *chip = spi_get_ctldata(spi);
996 +static struct mrst_spi_chip spidev_chip_info = {
997 + .tx_threshold = 8, /* SSP hardware FIFO threshold */
998 + .rx_threshold = 8, /* SSP hardware FIFO threshold */
999 + .timeout = 235, /* See Intel documentation */
1003 + * mrst_parse_spi_dib - mrst-ssp parse the spi device info block
1005 + * @pdev: spi controller pci device structure
1006 + * @drv_data: spi controller driver data
1007 + * Context: can sleep
1009 + * ssp controller needs to parse the spi device info block table
1010 + * saved in PCI bar 1 and register them with the spi core subsystem.
1012 +static void mrst_parse_spi_dib(struct pci_dev *pdev,
1013 + struct driver_data *drv_data)
1017 + unsigned long dib_paddr;
1018 + struct spi_board_info info[1];
1019 + struct spi_dib_header *header;
1020 + struct spi_dib *dib;
1021 + int info_num, i, j, dib_bar;
1025 + dib_paddr = pci_resource_start(pdev, dib_bar);
1026 + dib_len = pci_resource_len(pdev, dib_bar);
1028 + printk(KERN_INFO "SPI-Slave: %s() - paddr = 0x%08lx, "
1029 + "iolen = 0x%x\n", __func__, dib_paddr, dib_len);
1031 + dib_vaddr = ioremap(dib_paddr, dib_len);
1033 + dev_err(&pdev->dev, "%s(): ioremap failed\n", __func__);
1037 + /* bar1 contains a pointer to the SPI DIB table */
1038 + if (dib_len == 8) {
1039 + u32 *ptemp = (u32 *)dib_vaddr;
1040 + dib_len = *(ptemp + 1);
1041 + dib_vaddr = ioremap(*(unsigned long *)dib_vaddr, dib_len);
1045 + header = (struct spi_dib_header *)dib_vaddr;
1046 + info_num = (header->length - sizeof(*header)) /
1048 + dib = (struct spi_dib *)&header[1];
1050 + /* search for our dib entry. */
1051 + for (i = 0; i < info_num; i++)
1052 + if (dib[i].host_num == 3)
1054 + if (i == info_num)
1057 + strncpy(info[0].modalias, dib[i].name, SPI_DIB_NAME_LEN);
1058 + info[0].irq = dib[i].irq;
1059 + info[0].bus_num = dib[i].host_num;
1060 + info[0].chip_select = dib[i].cs;
1062 + info[0].max_speed_hz = 0;
1064 + printk(KERN_INFO "SPI-Slave: name = %s, irq = 0x%x, "
1065 + "bus = %d, cs = %d\n", info[0].modalias, info[0].irq,
1066 + info[0].bus_num, info[0].chip_select);
1068 + pval = (u16 *)&(dib[i].dev_data[0]);
1070 + info[0].controller_data = &spidev_chip_info; /* Slave chip config */
1072 + for (j = 0; j < 5; j++) {
1073 + spidev_chip_info.extra_data[j] = *pval;
1077 + spi_register_board_info(info, 1);
1080 + pci_release_region(pdev, dib_bar);
1085 +static int mrst_spi_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1087 + struct device *dev = &pdev->dev;
1088 + struct spi_slave *slave;
1089 + struct driver_data *drv_data = 0;
1093 + printk(KERN_INFO "SPI-Slave: found PCI SSP controller(ID: %04x:%04x)\n",
1094 + pdev->vendor, pdev->device);
1096 + status = pci_enable_device(pdev);
1100 + /* Allocate Slave with space for drv_data and null dma buffer */
1101 + slave = spi_alloc_slave(dev, sizeof(struct driver_data));
1104 + dev_err(&pdev->dev, "cannot alloc spi_slave\n");
1106 + goto err_free_slave0;
1109 + drv_data = spi_slave_get_devdata(slave);
1110 + drv_data->slave = slave;
1112 + drv_data->pdev = pdev;
1113 + spin_lock_init(&drv_data->lock);
1115 + slave->bus_num = 3;
1116 + slave->num_chipselect = 1;
1117 + slave->cleanup = cleanup;
1118 + slave->setup = setup;
1119 + slave->transfer = transfer;
1121 + /* get basic io resource and map it */
1122 + drv_data->paddr = (void *)pci_resource_start(pdev, pci_bar);
1123 + drv_data->iolen = pci_resource_len(pdev, pci_bar);
1125 + status = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
1127 + goto err_free_slave1;
1129 + drv_data->ioaddr =
1130 + ioremap_nocache((u32)drv_data->paddr, drv_data->iolen);
1131 + if (!drv_data->ioaddr) {
1133 + goto err_free_slave2;
1135 + printk(KERN_INFO "SPI-Slave: ioaddr = : %08x\n", (int)drv_data->ioaddr);
1136 + printk(KERN_INFO "SPI-Slave: attaching to IRQ: %04x\n", pdev->irq);
1138 + mrst_parse_spi_dib(pdev, drv_data);
1140 + /* get base address of IPC registers */
1141 + drv_data->IPC_paddr = (void *)0xffae8000;
1142 + drv_data->IPC_ioaddr =
1143 + ioremap_nocache((unsigned long)drv_data->IPC_paddr, 0x80);
1144 + if (!drv_data->IPC_ioaddr) {
1146 + goto err_free_slave3;
1148 + /* get base address of I2C_Serbus registers */
1149 + drv_data->I2C_paddr = (void *)0xff12b000;
1150 + drv_data->I2C_ioaddr =
1151 + ioremap_nocache((unsigned long)drv_data->I2C_paddr, 0x10);
1152 + if (!drv_data->I2C_ioaddr) {
1154 + goto err_free_slave4;
1157 + printk(KERN_INFO "SPI-Slave: IPC_ioaddr = : %08x\n",
1158 + (int)drv_data->IPC_ioaddr);
1159 + printk(KERN_INFO "SPI-Slave: IPCCSR = : %08x\n",
1160 + read_IPCCSR(drv_data->IPC_ioaddr));
1161 + write_IPCCSR(0x802, drv_data->IPC_ioaddr);
1162 + printk(KERN_INFO "SPI-Slave: IPCCSR = : %08x\n",
1163 + read_IPCCSR(drv_data->IPC_ioaddr));
1165 + /* Attach to IRQ */
1166 + drv_data->irq = pdev->irq;
1167 + status = request_irq(drv_data->irq, ssp_int, IRQF_SHARED,
1168 + "mrst_spi3", drv_data);
1170 + dev_err(&pdev->dev, "can not get IRQ\n");
1171 + goto err_free_slave5;
1174 + drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
1175 + drv_data->dma_cr1 = SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL;
1176 + drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1177 + drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1179 + tasklet_init(&drv_data->poll_transfer,
1180 + poll_transfer, (unsigned long)drv_data);
1182 + /* Setup DMA if requested */
1184 + /* Load default SSP configuration */
1185 + printk(KERN_INFO "SPI-Slave: setup default SSP configuration\n");
1186 + write_SSCR0(0, drv_data->ioaddr);
1187 + write_SSCR1(SSCR1_RxTresh(4) | SSCR1_TxTresh(12), drv_data->ioaddr);
1188 + write_SSCR0(SSCR0_Motorola
1189 + | SSCR0_DataSize(8),
1190 + drv_data->ioaddr);
1191 + write_SSTO(0, drv_data->ioaddr);
1192 + write_SSPSP(0x02010007, drv_data->ioaddr);
1194 + /* Register with the SPI framework */
1195 + printk(KERN_INFO "SPI-Slave: register with SPI framework\n");
1197 + status = spi_register_slave(slave);
1199 + if (status != 0) {
1200 + dev_err(&pdev->dev, "problem registering spi slave\n");
1201 + goto err_free_slave6;
1204 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
1205 + mrst_spi_dma_init(drv_data);
1208 + pci_set_drvdata(pdev, drv_data);
1213 + free_irq(drv_data->irq, drv_data);
1215 + iounmap(drv_data->I2C_ioaddr);
1217 + iounmap(drv_data->IPC_ioaddr);
1219 + iounmap(drv_data->ioaddr);
1221 + pci_release_region(pdev, pci_bar);
1223 + spi_slave_put(slave);
1225 + pci_disable_device(pdev);
1230 +static void __devexit mrst_spi_remove(struct pci_dev *pdev)
1232 + struct driver_data *drv_data = pci_get_drvdata(pdev);
1237 + pci_set_drvdata(pdev, NULL);
1239 +#ifdef CONFIG_SPI_MRST_SLAVE_DMA
1240 + mrst_spi_dma_exit(drv_data);
1241 + pci_dev_put(drv_data->dmac1);
1245 + free_irq(drv_data->irq, drv_data);
1247 + iounmap(drv_data->ioaddr);
1248 + iounmap(drv_data->I2C_ioaddr);
1249 + iounmap(drv_data->IPC_ioaddr);
1251 + pci_release_region(pdev, 0);
1253 + /* disconnect from the SPI framework */
1254 + spi_unregister_slave(drv_data->slave);
1256 + pci_disable_device(pdev);
1263 +static int mrst_spi_suspend(struct pci_dev *pdev, pm_message_t state)
1265 + struct driver_data *drv_data = pci_get_drvdata(pdev);
1266 + printk(KERN_ERR "spi-slave: suspend\n");
1268 + tasklet_disable(&drv_data->poll_transfer);
1273 +static int mrst_spi_resume(struct pci_dev *pdev)
1275 + struct driver_data *drv_data = pci_get_drvdata(pdev);
1276 + printk(KERN_ERR "spi-slave: resume\n");
1278 + tasklet_enable(&drv_data->poll_transfer);
1283 +#define mrst_spi_suspend NULL
1284 +#define mrst_spi_resume NULL
1285 +#endif /* CONFIG_PM */
1288 +static const struct pci_device_id pci_ids[] __devinitdata = {
1291 + .vendor = PCI_VENDOR_ID_INTEL,
1293 + .subvendor = PCI_ANY_ID,
1294 + .subdevice = PCI_ANY_ID,
1299 +static struct pci_driver mrst_spi_slave_driver = {
1300 + .name = DRIVER_NAME,
1301 + .id_table = pci_ids,
1302 + .probe = mrst_spi_probe,
1303 + .remove = __devexit_p(mrst_spi_remove),
1304 + .suspend = mrst_spi_suspend,
1305 + .resume = mrst_spi_resume,
1308 +static int __init mrst_spi_init(void)
1310 + return pci_register_driver(&mrst_spi_slave_driver);
1313 +late_initcall_sync(mrst_spi_init);
1315 +static void __exit mrst_spi_exit(void)
1317 + pci_unregister_driver(&mrst_spi_slave_driver);
1319 +module_exit(mrst_spi_exit);
1320 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
1321 index b76f246..f58f8c3 100644
1322 --- a/drivers/spi/spi.c
1323 +++ b/drivers/spi/spi.c
1325 #include <linux/spi/spi.h>
1328 -/* SPI bustype and spi_master class are registered after board init code
1329 - * provides the SPI device tables, ensuring that both are present by the
1330 - * time controller driver registration causes spi_devices to "enumerate".
1332 +/* SPI bustype, spi_master and spi_slave class are registered after board
1333 +* init code provides the SPI device tables, ensuring that both are present
1334 +* by the time controller driver registration causes spi_devices
1338 +/* SPI Slave Support is added for new spi slave devices: It uses common APIs,
1339 +* apart from few new APIs and a spi_slave structure.
1342 static void spidev_release(struct device *dev)
1344 struct spi_device *spi = to_spi_device(dev);
1345 @@ -43,11 +49,22 @@ static void spidev_release(struct device *dev)
1349 +static void spidev_slave_release(struct device *dev)
1351 + struct spi_device *spi = to_spi_device(dev);
1353 + /* spi slave may cleanup */
1354 + if (spi->slave->cleanup)
1355 + spi->slave->cleanup(spi);
1357 + spi_slave_put(spi->slave);
1362 modalias_show(struct device *dev, struct device_attribute *a, char *buf)
1364 const struct spi_device *spi = to_spi_device(dev);
1366 return sprintf(buf, "%s\n", spi->modalias);
1369 @@ -177,10 +194,13 @@ int spi_register_driver(struct spi_driver *sdrv)
1370 sdrv->driver.bus = &spi_bus_type;
1372 sdrv->driver.probe = spi_drv_probe;
1375 sdrv->driver.remove = spi_drv_remove;
1378 sdrv->driver.shutdown = spi_drv_shutdown;
1380 return driver_register(&sdrv->driver);
1382 EXPORT_SYMBOL_GPL(spi_register_driver);
1383 @@ -201,6 +221,7 @@ struct boardinfo {
1385 static LIST_HEAD(board_list);
1386 static DEFINE_MUTEX(board_lock);
1387 +static DEFINE_MUTEX(slave_board_lock);
1390 * spi_alloc_device - Allocate a new SPI device
1391 @@ -221,28 +242,70 @@ static DEFINE_MUTEX(board_lock);
1393 struct spi_device *spi_alloc_device(struct spi_master *master)
1395 - struct spi_device *spi;
1396 + struct spi_device *spi_m_dev;
1397 struct device *dev = master->dev.parent;
1399 if (!spi_master_get(master))
1402 - spi = kzalloc(sizeof *spi, GFP_KERNEL);
1404 + spi_m_dev = kzalloc(sizeof *spi_m_dev, GFP_KERNEL);
1406 dev_err(dev, "cannot alloc spi_device\n");
1407 spi_master_put(master);
1411 - spi->master = master;
1412 - spi->dev.parent = dev;
1413 - spi->dev.bus = &spi_bus_type;
1414 - spi->dev.release = spidev_release;
1415 - device_initialize(&spi->dev);
1417 + spi_m_dev->master = master;
1418 + spi_m_dev->using_slave = 0;
1419 + spi_m_dev->dev.parent = dev;
1420 + spi_m_dev->dev.bus = &spi_bus_type;
1421 + spi_m_dev->dev.release = spidev_release;
1422 + device_initialize(&spi_m_dev->dev);
1425 EXPORT_SYMBOL_GPL(spi_alloc_device);
1428 +* spi_alloc_slave_device - Allocate a new SPI device
1429 +* @slave: Controller to which device is connected
1430 +* Context: can sleep
1432 +* Allows a driver to allocate and initialize a spi_device without
1433 +* registering it immediately. This allows a driver to directly
1434 +* fill the spi_device with device parameters before calling
1435 +* spi_add_slave_device() on it.
1437 +* Caller is responsible to call spi_add_slave_device() on the returned
1438 +* spi_device structure to add it to the SPI slave. If the caller
1439 +* needs to discard the spi_device without adding it, then it should
1440 +* call spi_dev_slave_put() on it.
1441 +* Returns a pointer to the new device, or NULL.
1443 +struct spi_device *spi_alloc_slave_device(struct spi_slave *slave)
1445 + struct spi_device *spi_s;
1446 + struct device *dev = slave->dev.parent;
1448 + if (!spi_slave_get(slave))
1451 + spi_s = kzalloc(sizeof *spi_s, GFP_KERNEL);
1453 + dev_err(dev, "cannot alloc spi_slave_device\n");
1454 + spi_slave_put(slave);
1458 + spi_s->slave = slave;
1459 + spi_s->using_slave = 9;
1460 + spi_s->dev.parent = dev;
1461 + spi_s->dev.bus = &spi_bus_type;
1462 + spi_s->dev.release = spidev_slave_release;
1463 + device_initialize(&spi_s->dev);
1466 +EXPORT_SYMBOL_GPL(spi_alloc_slave_device);
1469 * spi_add_device - Add spi_device allocated with spi_alloc_device
1470 * @spi: spi_device to register
1471 @@ -301,6 +364,7 @@ int spi_add_device(struct spi_device *spi)
1473 dev_err(dev, "can't %s %s, status %d\n",
1474 "add", dev_name(&spi->dev), status);
1477 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
1479 @@ -311,6 +375,74 @@ done:
1480 EXPORT_SYMBOL_GPL(spi_add_device);
1483 +* spi_add_slave_device - Add spi_device allocated with spi_alloc_slave_device
1484 +* @spi: spi_device to register
1486 +* Companion function to spi_alloc_slave_device. Devices allocated with
1487 +* spi_alloc_slave_device can be added onto the spi bus with this function.
1489 +* Returns 0 on success; negative errno on failure
1491 +int spi_add_slave_device(struct spi_device *spi)
1493 + static DEFINE_MUTEX(spi_slave_add_lock);
1494 + struct device *dev = spi->slave->dev.parent;
1497 + /* Chipselects are numbered 0..max; validate. */
1498 + if (spi->chip_select >= spi->slave->num_chipselect) {
1499 + dev_err(dev, "cs%d >= max %d\n",
1501 + spi->slave->num_chipselect);
1505 + /* Set the bus ID string */
1506 + dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->slave->dev),
1507 + spi->chip_select);
1510 + /* We need to make sure there's no other device with this
1511 + * chipselect **BEFORE** we call setup(), else we'll trash
1512 + * its configuration. Lock against concurrent add() calls.
1514 + mutex_lock(&spi_slave_add_lock);
1516 + if (bus_find_device_by_name(&spi_bus_type, NULL, dev_name(&spi->dev))
1518 + dev_err(dev, "chipselect %d already in use\n",
1519 + spi->chip_select);
1524 + /* Drivers may modify this initial i/o setup, but will
1525 + * normally rely on the device being setup. Devices
1526 + * using SPI_CS_HIGH can't coexist well otherwise...
1528 + status = spi->slave->setup(spi);
1530 + dev_err(dev, "can't %s %s, status %d\n",
1531 + "setup", dev_name(&spi->dev), status);
1535 + /* Device may be bound to an active driver when this returns */
1536 + status = device_add(&spi->dev);
1538 + dev_err(dev, "can't %s %s, status %d\n",
1539 + "add", dev_name(&spi->dev), status);
1541 + dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
1544 + mutex_unlock(&spi_slave_add_lock);
1547 +EXPORT_SYMBOL_GPL(spi_add_slave_device);
1551 * spi_new_device - instantiate one new SPI device
1552 * @master: Controller to which device is connected
1553 * @chip: Describes the SPI device
1554 @@ -341,6 +473,8 @@ struct spi_device *spi_new_device(struct spi_master *master,
1560 WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
1562 proxy->chip_select = chip->chip_select;
1563 @@ -363,6 +497,54 @@ struct spi_device *spi_new_device(struct spi_master *master,
1564 EXPORT_SYMBOL_GPL(spi_new_device);
1567 +* spi_slave_new_device - instantiate one new SPI device
1568 +* @slave: Controller to which device is connected
1569 +* @chip: Describes the SPI device
1570 +* Context: can sleep
1572 +* On typical mainboards, this is purely internal; and it's not needed
1573 +* after board init creates the hard-wired devices. Some development
1574 +* platforms may not be able to use spi_register_board_info though, and
1575 +* this is exported so that for example a USB or parport based adapter
1576 +* driver could add devices (which it would learn about out-of-band).
1578 +* Returns the new device, or NULL.
1580 +struct spi_device *spi_slave_new_device(struct spi_slave *slave,
1581 + struct spi_board_info *chip)
1583 + struct spi_device *proxy_slave;
1586 + proxy_slave = spi_alloc_slave_device(slave);
1591 + WARN_ON(strlen(chip->modalias) >= sizeof(proxy_slave->modalias));
1593 + proxy_slave->chip_select = chip->chip_select;
1594 + proxy_slave->max_speed_hz = chip->max_speed_hz;
1595 + proxy_slave->mode = chip->mode;
1596 + proxy_slave->irq = chip->irq;
1597 + strlcpy(proxy_slave->modalias, chip->modalias,
1598 + sizeof(proxy_slave->modalias));
1599 + proxy_slave->dev.platform_data = (void *) chip->platform_data;
1600 + proxy_slave->controller_data = chip->controller_data;
1601 + proxy_slave->controller_state = NULL;
1603 + status = spi_add_slave_device(proxy_slave);
1605 + spi_dev_put(proxy_slave);
1609 + return proxy_slave;
1611 +EXPORT_SYMBOL_GPL(spi_slave_new_device);
1615 * spi_register_board_info - register SPI devices for a given board
1616 * @info: array of chip descriptors
1617 * @n: how many descriptors are provided
1618 @@ -389,6 +571,7 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1619 bi = kmalloc(sizeof(*bi) + n * sizeof *info, GFP_KERNEL);
1623 bi->n_board_info = n;
1624 memcpy(bi->board_info, info, n * sizeof *info);
1626 @@ -398,6 +581,7 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1631 /* FIXME someone should add support for a __setup("spi", ...) that
1632 * creates board info from kernel command lines
1634 @@ -423,6 +607,28 @@ static void scan_boardinfo(struct spi_master *master)
1635 mutex_unlock(&board_lock);
1638 +static void spi_slave_scan_boardinfo(struct spi_slave *slave)
1640 + struct boardinfo *bi;
1642 + mutex_lock(&slave_board_lock);
1643 + list_for_each_entry(bi, &board_list, list) {
1644 + struct spi_board_info *chip = bi->board_info;
1647 + for (n = bi->n_board_info; n > 0; n--, chip++) {
1648 + if (chip->bus_num != slave->bus_num)
1650 + /* NOTE: this relies on spi_new_device to
1651 + * issue diagnostics when given bogus inputs
1653 + (void) spi_slave_new_device(slave, chip);
1657 + mutex_unlock(&slave_board_lock);
1660 /*-------------------------------------------------------------------------*/
1662 static void spi_master_release(struct device *dev)
1663 @@ -439,6 +645,19 @@ static struct class spi_master_class = {
1664 .dev_release = spi_master_release,
1667 +static void spi_slave_release(struct device *dev)
1669 + struct spi_slave *slave;
1671 + slave = container_of(dev, struct spi_slave, dev);
1675 +static struct class spi_slave_class = {
1676 + .name = "spi_slave",
1677 + .owner = THIS_MODULE,
1678 + .dev_release = spi_slave_release,
1682 * spi_alloc_master - allocate SPI master controller
1683 @@ -480,6 +699,47 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
1684 EXPORT_SYMBOL_GPL(spi_alloc_master);
1687 +* spi_alloc_slave - allocate SPI slave controller
1688 +* @dev: the controller, possibly using the platform_bus
1689 +* @size: how much zeroed driver-private data to allocate; the pointer to this
1690 +* memory is in the driver_data field of the returned device,
1691 +* accessible with spi_slave_get_devdata().
1692 +* Context: can sleep
1694 +* This call is used only by SPI master controller drivers, which are the
1695 +* only ones directly touching chip registers. It's how they allocate
1696 +* an spi_master structure, prior to calling spi_register_slave().
1698 +* This must be called from context that can sleep. It returns the SPI
1699 +* master structure on success, else NULL.
1701 +* The caller is responsible for assigning the bus number and initializing
1702 +* the master's methods before calling spi_register_slave(); and (after errors
1703 +* adding the device) calling spi_slave_put() to prevent a memory leak.
1705 +struct spi_slave *spi_alloc_slave(struct device *dev, unsigned size)
1707 + struct spi_slave *slave;
1712 + slave = kzalloc(size + sizeof *slave, GFP_KERNEL);
1716 + device_initialize(&slave->dev);
1717 + slave->dev.class = &spi_slave_class;
1718 + slave->dev.parent = get_device(dev);
1719 + spi_slave_set_devdata(slave, &slave[1]);
1723 +EXPORT_SYMBOL_GPL(spi_alloc_slave);
1728 * spi_register_master - register SPI master controller
1729 * @master: initialized master, originally from spi_alloc_master()
1730 * Context: can sleep
1731 @@ -531,7 +791,8 @@ int spi_register_master(struct spi_master *master)
1732 status = device_add(&master->dev);
1735 - dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
1737 + dev_dbg(dev, "spi_register_master() : %s%s\n", dev_name(&master->dev),
1738 dynamic ? " (dynamic)" : "");
1740 /* populate children from any spi device tables */
1741 @@ -542,6 +803,71 @@ done:
1743 EXPORT_SYMBOL_GPL(spi_register_master);
1746 +* spi_register_slave - register SPI slave controller
1747 +* @master: initialized master, originally from spi_alloc_slave()
1748 +* Context: can sleep
1750 +* SPI slave controllers connect to their drivers using some non-SPI bus,
1751 +* such as the platform bus. The final stage of probe() in that code
1752 +* includes calling spi_register_slave() to hook up to this SPI bus glue.
1754 +* SPI controllers use board specific (often SOC specific) bus numbers,
1755 +* and board-specific addressing for SPI devices combines those numbers
1756 +* with chip select numbers. Since SPI does not directly support dynamic
1757 +* device identification, boards need configuration tables telling which
1758 +* chip is at which address.
1760 +* This must be called from context that can sleep. It returns zero on
1761 +* success, else a negative error code (dropping the slave's refcount).
1762 +* After a successful return, the caller is responsible for calling
1763 +* spi_unregister_slave().
1765 +int spi_register_slave(struct spi_slave *slave)
1767 + static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
1768 + struct device *dev = slave->dev.parent;
1769 + int status = -ENODEV;
1775 + /* even if it's just one always-selected device, there must
1776 + * be at least one chipselect
1778 + if (slave->num_chipselect == 0)
1781 + /* convention: dynamically assigned bus IDs count down from the max */
1782 + if (slave->bus_num < 0) {
1783 + /* FIXME switch to an IDR based scheme, something like
1784 + * I2C now uses, so we can't run out of "dynamic" IDs
1786 + slave->bus_num = atomic_dec_return(&dyn_bus_id);
1790 + /* register the device, then userspace will see it.
1791 + * registration fails if the bus ID is in use.
1793 + dev_set_name(&slave->dev, "spi%u", slave->bus_num);
1794 + status = device_add(&slave->dev);
1798 + dev_dbg(dev, "registered slave %s%s\n", dev_name(&slave->dev),
1799 + dynamic ? " (dynamic)" : "");
1801 + /* populate children from any spi device tables */
1802 + spi_slave_scan_boardinfo(slave);
1807 +EXPORT_SYMBOL_GPL(spi_register_slave);
1811 static int __unregister(struct device *dev, void *master_dev)
1813 @@ -571,6 +897,27 @@ void spi_unregister_master(struct spi_master *master)
1815 EXPORT_SYMBOL_GPL(spi_unregister_master);
1818 +* spi_unregister_slave - unregister SPI slave controller
1819 +* @master: the slave being unregistered
1820 +* Context: can sleep
1822 +* This call is used only by SPI slave controller drivers, which are the
1823 +* only ones directly touching chip registers.
1825 +* This must be called from context that can sleep.
1827 +void spi_unregister_slave(struct spi_slave *slave)
1831 + dummy = device_for_each_child(slave->dev.parent, &slave->dev,
1833 + device_unregister(&slave->dev);
1835 +EXPORT_SYMBOL_GPL(spi_unregister_slave);
1838 static int __spi_master_match(struct device *dev, void *data)
1840 struct spi_master *m;
1841 @@ -718,7 +1065,12 @@ int spi_async(struct spi_device *spi, struct spi_message *message)
1844 message->status = -EINPROGRESS;
1845 - return master->transfer(spi, message);
1848 + if (spi->using_slave == 9)
1849 + return spi->slave->transfer(spi, message); /* Slave */
1851 + return spi->master->transfer(spi, message); /* Master */
1853 EXPORT_SYMBOL_GPL(spi_async);
1855 @@ -773,6 +1125,18 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
1857 EXPORT_SYMBOL_GPL(spi_sync);
1859 +/* spi_transfer_async - Wraper function to allow spi_async to expose to
1860 +* user protocol drivers for modem handshaking
1863 +int spi_transfer_async(struct spi_device *spi, struct spi_message *message)
1866 + status = spi_async(spi, message);
1869 +EXPORT_SYMBOL_GPL(spi_transfer_async);
1871 /* portable code must never pass more than 32 bytes */
1872 #define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
1874 @@ -871,6 +1235,12 @@ static int __init spi_init(void)
1875 status = class_register(&spi_master_class);
1879 + status = class_register(&spi_slave_class);
1887 @@ -890,4 +1260,3 @@ err0:
1888 * include needing to have boardinfo data structures be much more public.
1890 postcore_initcall(spi_init);
1892 diff --git a/include/linux/spi/mrst_spi_slave.h b/include/linux/spi/mrst_spi_slave.h
1893 new file mode 100644
1894 index 0000000..4d73f0e
1896 +++ b/include/linux/spi/mrst_spi_slave.h
1899 + * Copyright (C) Intel 2009
1900 + * Ken Mills <ken.k.mills@intel.com>
1902 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1904 + * This program is free software; you can redistribute it and/or modify
1905 + * it under the terms of the GNU General Public License as published by
1906 + * the Free Software Foundation; either version 2 of the License, or
1907 + * (at your option) any later version.
1909 + * This program is distributed in the hope that it will be useful,
1910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1912 + * GNU General Public License for more details.
1914 + * You should have received a copy of the GNU General Public License
1915 + * along with this program; if not, write to the Free Software
1916 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1918 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1921 +#ifndef MRST_SSP_H_
1922 +#define MRST_SSP_H_
1926 + * Langwell SSP serial port register definitions
1929 +#define SSCR0_DSS (0x0000000f) /* Data Size Select (mask) */
1930 +#define SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..16] */
1931 +#define SSCR0_FRF (0x00000030) /* FRame Format (mask) */
1932 +#define SSCR0_Motorola (0x0 << 4) /* Motorola's SPI mode */
1933 +#define SSCR0_ECS (1 << 6) /* External clock select */
1934 +#define SSCR0_SSE (1 << 7) /* Synchronous Serial Port Enable */
1937 +#define SSCR0_SCR (0x000fff00) /* Serial Clock Rate (mask) */
1938 +#define SSCR0_SerClkDiv(x) (((x) - 1) << 8) /* Divisor [1..4096] */
1939 +#define SSCR0_EDSS (1 << 20) /* Extended data size select */
1940 +#define SSCR0_NCS (1 << 21) /* Network clock select */
1941 +#define SSCR0_RIM (1 << 22) /* Receive FIFO overrrun int mask */
1942 +#define SSCR0_TUM (1 << 23) /* Transmit FIFO underrun int mask */
1943 +#define SSCR0_FRDC (0x07000000) /* Frame rate divider control (mask) */
1944 +#define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame */
1945 +#define SSCR0_ADC (1 << 30) /* Audio clock select */
1946 +#define SSCR0_MOD (1 << 31) /* Mode (normal or network) */
1949 +#define SSCR1_RIE (1 << 0) /* Receive FIFO Interrupt Enable */
1950 +#define SSCR1_TIE (1 << 1) /* Transmit FIFO Interrupt Enable */
1951 +#define SSCR1_LBM (1 << 2) /* Loop-Back Mode */
1952 +#define SSCR1_SPO (1 << 3) /* SSPSCLK polarity setting */
1953 +#define SSCR1_SPH (1 << 4) /* Motorola SPI SSPSCLK phase setting */
1954 +#define SSCR1_MWDS (1 << 5) /* Microwire Transmit Data Size */
1955 +#define SSCR1_TFT (0x000003c0) /* Transmit FIFO Threshold (mask) */
1956 +#define SSCR1_TxTresh(x) (((x) - 1) << 6) /* level [1..16] */
1957 +#define SSCR1_RFT (0x00003c00) /* Receive FIFO Threshold (mask) */
1958 +#define SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..16] */
1960 +#define SSSR_TNF (1 << 2) /* Transmit FIFO Not Full */
1961 +#define SSSR_RNE (1 << 3) /* Receive FIFO Not Empty */
1962 +#define SSSR_BSY (1 << 4) /* SSP Busy */
1963 +#define SSSR_TFS (1 << 5) /* Transmit FIFO Service Request */
1964 +#define SSSR_RFS (1 << 6) /* Receive FIFO Service Request */
1965 +#define SSSR_ROR (1 << 7) /* Receive FIFO Overrun */
1967 +#define SSCR0_TIM (1 << 23) /* Transmit FIFO Under Run Int Mask */
1968 +#define SSCR0_RIM (1 << 22) /* Receive FIFO Over Run int Mask */
1969 +#define SSCR0_NCS (1 << 21) /* Network Clock Select */
1970 +#define SSCR0_EDSS (1 << 20) /* Extended Data Size Select */
1972 +#define SSCR0_TISSP (1 << 4) /* TI Sync Serial Protocol */
1973 +#define SSCR0_PSP (3 << 4) /* PSP - Programmable Serial Protocol */
1974 +#define SSCR1_TTELP (1 << 31) /* TXD Tristate Enable Last Phase */
1975 +#define SSCR1_TTE (1 << 30) /* TXD Tristate Enable */
1976 +#define SSCR1_EBCEI (1 << 29) /* Enable Bit Count Error interrupt */
1977 +#define SSCR1_SCFR (1 << 28) /* Slave Clock free Running */
1978 +#define SSCR1_ECRA (1 << 27) /* Enable Clock Request A */
1979 +#define SSCR1_ECRB (1 << 26) /* Enable Clock request B */
1980 +#define SSCR1_SCLKDIR (1 << 25) /* Serial Bit Rate Clock Direction */
1981 +#define SSCR1_SFRMDIR (1 << 24) /* Frame Direction */
1982 +#define SSCR1_RWOT (1 << 23) /* Receive Without Transmit */
1983 +#define SSCR1_TRAIL (1 << 22) /* Trailing Byte */
1984 +#define SSCR1_TSRE (1 << 21) /* Transmit Service Request Enable */
1985 +#define SSCR1_RSRE (1 << 20) /* Receive Service Request Enable */
1986 +#define SSCR1_TINTE (1 << 19) /* Receiver Time-out Interrupt enable */
1987 +#define SSCR1_PINTE (1 << 18) /* Trailing Byte Interupt Enable */
1988 +#define SSCR1_STRF (1 << 15) /* Select FIFO or EFWR */
1989 +#define SSCR1_EFWR (1 << 14) /* Enable FIFO Write/Read */
1991 +#define SSSR_BCE (1 << 23) /* Bit Count Error */
1992 +#define SSSR_CSS (1 << 22) /* Clock Synchronisation Status */
1993 +#define SSSR_TUR (1 << 21) /* Transmit FIFO Under Run */
1994 +#define SSSR_EOC (1 << 20) /* End Of Chain */
1995 +#define SSSR_TINT (1 << 19) /* Receiver Time-out Interrupt */
1996 +#define SSSR_PINT (1 << 18) /* Peripheral Trailing Byte Interrupt */
1998 +#define SSPSP_FSRT (1 << 25) /* Frame Sync Relative Timing */
1999 +#define SSPSP_DMYSTOP(x) ((x) << 23) /* Dummy Stop */
2000 +#define SSPSP_SFRMWDTH(x) ((x) << 16) /* Serial Frame Width */
2001 +#define SSPSP_SFRMDLY(x) ((x) << 9) /* Serial Frame Delay */
2002 +#define SSPSP_DMYSTRT(x) ((x) << 7) /* Dummy Start */
2003 +#define SSPSP_STRTDLY(x) ((x) << 4) /* Start Delay */
2004 +#define SSPSP_ETDS (1 << 3) /* End of Transfer data State */
2005 +#define SSPSP_SFRMP (1 << 2) /* Serial Frame Polarity */
2006 +#define SSPSP_SCMODE(x) ((x) << 0) /* Serial Bit Rate Clock Mode */
2008 +/* spi_board_info.controller_data for SPI slave devices,
2009 + * copied to spi_device.platform_data ... mostly for dma tuning
2011 +struct mrst_spi_chip {
2014 + u8 dma_burst_size;
2016 + u8 enable_loopback;
2017 + u16 extra_data[5];
2021 +#define SPI_DIB_NAME_LEN 16
2022 +#define SPI_DIB_SPEC_INFO_LEN 10
2024 +struct spi_dib_header {
2030 +} __attribute__((packed));
2036 + char name[SPI_DIB_NAME_LEN];
2037 + u8 dev_data[SPI_DIB_SPEC_INFO_LEN];
2038 +} __attribute__((packed));
2040 +#endif /*MRST_SSP_H_*/
2041 diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
2042 index 97b60b3..87b4d12 100644
2043 --- a/include/linux/spi/spi.h
2044 +++ b/include/linux/spi/spi.h
2046 #include <linux/mod_devicetable.h>
2049 - * INTERFACES between SPI master-side drivers and SPI infrastructure.
2050 - * (There's no SPI slave support for Linux yet...)
2051 + * INTERFACES between SPI Master/Slave side drivers and
2052 + * SPI infrastructure.
2053 + * SPI Slave Support added : It uses few new APIs and
2054 + * a new spi_slave struct
2056 extern struct bus_type spi_bus_type;
2059 * struct spi_device - Master side proxy for an SPI slave device
2060 * @dev: Driver model representation of the device.
2061 - * @master: SPI controller used with the device.
2062 + * @master: SPI Master controller used with the device.
2063 + * @slave: SPI Slave Controller used with the device
2064 + * @using_slave: SPI Slave Flag used by spi_async()
2065 * @max_speed_hz: Maximum clock rate to be used with this chip
2066 * (on this board); may be changed by the device's driver.
2067 * The spi_transfer.speed_hz can override this for each transfer.
2068 @@ -68,6 +72,8 @@ extern struct bus_type spi_bus_type;
2071 struct spi_master *master;
2072 + struct spi_slave *slave;
2077 @@ -143,7 +149,6 @@ static inline void *spi_get_drvdata(struct spi_device *spi)
2083 * struct spi_driver - Host side "protocol" driver
2084 * @id_table: List of SPI devices supported by this driver
2085 @@ -295,16 +300,56 @@ struct spi_master {
2086 void (*cleanup)(struct spi_device *spi);
2090 + * struct spi_slave - interface to SPI Slave Controller
2091 + * @dev: device interface to this driver
2092 + * @bus_num: board-specific (and often SOC-specific) identifier for a
2093 + * given SPI controller.
2094 + * @num_chipselect: chipselects are used to distinguish individual
2095 + * SPI slaves, and are numbered from zero to num_chipselects.
2096 + * each slave has a chipselect signal, but it's common that not
2097 + * every chipselect is connected to a slave.
2098 + * @setup: updates the device mode and clocking records used by a
2099 + * device's SPI controller; protocol code may call this. This
2100 + * must fail if an unrecognized or unsupported mode is requested.
2101 + * It's always safe to call this unless transfers are pending on
2102 + * the device whose settings are being modified.
2103 + * @transfer: adds a message to the controller's transfer queue.
2104 + * @cleanup: frees controller-specific state
2107 + struct device dev;
2109 + u16 num_chipselect;
2111 + int (*setup)(struct spi_device *spi);
2113 + int (*transfer)(struct spi_device *spi,
2114 + struct spi_message *mesg);
2116 + void (*cleanup)(struct spi_device *spi);
2119 static inline void *spi_master_get_devdata(struct spi_master *master)
2121 return dev_get_drvdata(&master->dev);
2124 +static inline void *spi_slave_get_devdata(struct spi_slave *slave)
2126 + return dev_get_drvdata(&slave->dev);
2129 static inline void spi_master_set_devdata(struct spi_master *master, void *data)
2131 dev_set_drvdata(&master->dev, data);
2134 +static inline void spi_slave_set_devdata(struct spi_slave *slave, void *data)
2136 + dev_set_drvdata(&slave->dev, data);
2139 static inline struct spi_master *spi_master_get(struct spi_master *master)
2141 if (!master || !get_device(&master->dev))
2142 @@ -312,20 +357,42 @@ static inline struct spi_master *spi_master_get(struct spi_master *master)
2146 +static inline struct spi_slave *spi_slave_get(struct spi_slave *slave)
2148 + if (!slave || !get_device(&slave->dev))
2153 static inline void spi_master_put(struct spi_master *master)
2156 put_device(&master->dev);
2159 +static inline void spi_slave_put(struct spi_slave *slave)
2162 + put_device(&slave->dev);
2166 /* the spi driver core manages memory for the spi_master classdev */
2167 extern struct spi_master *
2168 spi_alloc_master(struct device *host, unsigned size);
2170 +extern struct spi_slave *
2171 +spi_alloc_slave(struct device *host, unsigned size);
2174 extern int spi_register_master(struct spi_master *master);
2176 +extern int spi_register_slave(struct spi_slave *slave);
2178 extern void spi_unregister_master(struct spi_master *master);
2180 +extern void spi_unregister_slave(struct spi_slave *slave);
2182 extern struct spi_master *spi_busnum_to_master(u16 busnum);
2184 /*---------------------------------------------------------------------------*/
2185 @@ -551,6 +618,18 @@ extern int spi_async(struct spi_device *spi, struct spi_message *message);
2187 extern int spi_sync(struct spi_device *spi, struct spi_message *message);
2190 +spi_slave_setup(struct spi_device *spi)
2192 + return spi->slave->setup(spi);
2196 +/* spi_transfer_async() exposes spi_async() functionality */
2197 +extern int spi_transfer_async(struct spi_device *spi,
2198 + struct spi_message *message);
2202 * spi_write - SPI synchronous write
2203 * @spi: device to which data will be written
2204 @@ -759,12 +838,23 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
2205 extern struct spi_device *
2206 spi_alloc_device(struct spi_master *master);
2208 +extern struct spi_device *
2209 +spi_alloc_slave_device(struct spi_slave *slave);
2212 spi_add_device(struct spi_device *spi);
2215 +spi_add_slave_device(struct spi_device *spi);
2218 extern struct spi_device *
2219 spi_new_device(struct spi_master *, struct spi_board_info *);
2221 +extern struct spi_device *
2222 +spi_slave_new_device(struct spi_slave *, struct spi_board_info *);
2226 spi_unregister_device(struct spi_device *spi)