2 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/device.h>
22 #include <linux/ioport.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <linux/platform_device.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/spi/spi.h>
28 #include <linux/workqueue.h>
29 #include <linux/errno.h>
30 #include <linux/delay.h>
34 #include <asm/hardware.h>
35 #include <asm/delay.h>
38 #include <asm/arch/hardware.h>
39 #include <asm/arch/pxa-regs.h>
40 #include <asm/arch/pxa2xx_spi.h>
42 MODULE_AUTHOR("Stephen Street");
43 MODULE_DESCRIPTION("PXA2xx SSP SPI Contoller");
44 MODULE_LICENSE("GPL");
48 #define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)
49 #define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)
50 #define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0)
52 /* for testing SSCR1 changes that require SSP restart, basically
53 * everything except the service and interrupt enables */
54 #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_EBCEI | SSCR1_SCFR \
55 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
56 | SSCR1_RWOT | SSCR1_TRAIL | SSCR1_PINTE \
57 | SSCR1_STRF | SSCR1_EFWR |SSCR1_RFT \
58 | SSCR1_TFT | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
60 #define DEFINE_SSP_REG(reg, off) \
61 static inline u32 read_##reg(void *p) { return __raw_readl(p + (off)); } \
62 static inline void write_##reg(u32 v, void *p) { __raw_writel(v, p + (off)); }
64 DEFINE_SSP_REG(SSCR0, 0x00)
65 DEFINE_SSP_REG(SSCR1, 0x04)
66 DEFINE_SSP_REG(SSSR, 0x08)
67 DEFINE_SSP_REG(SSITR, 0x0c)
68 DEFINE_SSP_REG(SSDR, 0x10)
69 DEFINE_SSP_REG(SSTO, 0x28)
70 DEFINE_SSP_REG(SSPSP, 0x2c)
72 #define START_STATE ((void*)0)
73 #define RUNNING_STATE ((void*)1)
74 #define DONE_STATE ((void*)2)
75 #define ERROR_STATE ((void*)-1)
77 #define QUEUE_RUNNING 0
78 #define QUEUE_STOPPED 1
81 /* Driver model hookup */
82 struct platform_device *pdev;
84 /* SPI framework hookup */
85 enum pxa_ssp_type ssp_type;
86 struct spi_master *master;
89 struct pxa2xx_spi_master *master_info;
96 /* SSP register addresses */
106 /* Driver message queue */
107 struct workqueue_struct *workqueue;
108 struct work_struct pump_messages;
110 struct list_head queue;
114 /* Message Transfer pump */
115 struct tasklet_struct pump_transfers;
117 /* Current message transfer state info */
118 struct spi_message* cur_msg;
119 struct spi_transfer* cur_transfer;
120 struct chip_data *cur_chip;
134 int (*write)(struct driver_data *drv_data);
135 int (*read)(struct driver_data *drv_data);
136 irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
137 void (*cs_control)(u32 command);
153 int (*write)(struct driver_data *drv_data);
154 int (*read)(struct driver_data *drv_data);
155 void (*cs_control)(u32 command);
158 static void pump_messages(struct work_struct *work);
160 static int flush(struct driver_data *drv_data)
162 unsigned long limit = loops_per_jiffy << 1;
164 void *reg = drv_data->ioaddr;
167 while (read_SSSR(reg) & SSSR_RNE) {
170 } while ((read_SSSR(reg) & SSSR_BSY) && limit--);
171 write_SSSR(SSSR_ROR, reg);
176 static void null_cs_control(u32 command)
180 static int null_writer(struct driver_data *drv_data)
182 void *reg = drv_data->ioaddr;
183 u8 n_bytes = drv_data->n_bytes;
185 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
186 || (drv_data->tx == drv_data->tx_end))
190 drv_data->tx += n_bytes;
195 static int null_reader(struct driver_data *drv_data)
197 void *reg = drv_data->ioaddr;
198 u8 n_bytes = drv_data->n_bytes;
200 while ((read_SSSR(reg) & SSSR_RNE)
201 && (drv_data->rx < drv_data->rx_end)) {
203 drv_data->rx += n_bytes;
206 return drv_data->rx == drv_data->rx_end;
209 static int u8_writer(struct driver_data *drv_data)
211 void *reg = drv_data->ioaddr;
213 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
214 || (drv_data->tx == drv_data->tx_end))
217 write_SSDR(*(u8 *)(drv_data->tx), reg);
223 static int u8_reader(struct driver_data *drv_data)
225 void *reg = drv_data->ioaddr;
227 while ((read_SSSR(reg) & SSSR_RNE)
228 && (drv_data->rx < drv_data->rx_end)) {
229 *(u8 *)(drv_data->rx) = read_SSDR(reg);
233 return drv_data->rx == drv_data->rx_end;
236 static int u16_writer(struct driver_data *drv_data)
238 void *reg = drv_data->ioaddr;
240 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
241 || (drv_data->tx == drv_data->tx_end))
244 write_SSDR(*(u16 *)(drv_data->tx), reg);
250 static int u16_reader(struct driver_data *drv_data)
252 void *reg = drv_data->ioaddr;
254 while ((read_SSSR(reg) & SSSR_RNE)
255 && (drv_data->rx < drv_data->rx_end)) {
256 *(u16 *)(drv_data->rx) = read_SSDR(reg);
260 return drv_data->rx == drv_data->rx_end;
263 static int u32_writer(struct driver_data *drv_data)
265 void *reg = drv_data->ioaddr;
267 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
268 || (drv_data->tx == drv_data->tx_end))
271 write_SSDR(*(u32 *)(drv_data->tx), reg);
277 static int u32_reader(struct driver_data *drv_data)
279 void *reg = drv_data->ioaddr;
281 while ((read_SSSR(reg) & SSSR_RNE)
282 && (drv_data->rx < drv_data->rx_end)) {
283 *(u32 *)(drv_data->rx) = read_SSDR(reg);
287 return drv_data->rx == drv_data->rx_end;
290 static void *next_transfer(struct driver_data *drv_data)
292 struct spi_message *msg = drv_data->cur_msg;
293 struct spi_transfer *trans = drv_data->cur_transfer;
295 /* Move to next transfer */
296 if (trans->transfer_list.next != &msg->transfers) {
297 drv_data->cur_transfer =
298 list_entry(trans->transfer_list.next,
301 return RUNNING_STATE;
306 static int map_dma_buffers(struct driver_data *drv_data)
308 struct spi_message *msg = drv_data->cur_msg;
309 struct device *dev = &msg->spi->dev;
311 if (!drv_data->cur_chip->enable_dma)
314 if (msg->is_dma_mapped)
315 return drv_data->rx_dma && drv_data->tx_dma;
317 if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
320 /* Modify setup if rx buffer is null */
321 if (drv_data->rx == NULL) {
322 *drv_data->null_dma_buf = 0;
323 drv_data->rx = drv_data->null_dma_buf;
324 drv_data->rx_map_len = 4;
326 drv_data->rx_map_len = drv_data->len;
329 /* Modify setup if tx buffer is null */
330 if (drv_data->tx == NULL) {
331 *drv_data->null_dma_buf = 0;
332 drv_data->tx = drv_data->null_dma_buf;
333 drv_data->tx_map_len = 4;
335 drv_data->tx_map_len = drv_data->len;
337 /* Stream map the rx buffer */
338 drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
339 drv_data->rx_map_len,
341 if (dma_mapping_error(drv_data->rx_dma))
344 /* Stream map the tx buffer */
345 drv_data->tx_dma = dma_map_single(dev, drv_data->tx,
346 drv_data->tx_map_len,
349 if (dma_mapping_error(drv_data->tx_dma)) {
350 dma_unmap_single(dev, drv_data->rx_dma,
351 drv_data->rx_map_len, DMA_FROM_DEVICE);
358 static void unmap_dma_buffers(struct driver_data *drv_data)
362 if (!drv_data->dma_mapped)
365 if (!drv_data->cur_msg->is_dma_mapped) {
366 dev = &drv_data->cur_msg->spi->dev;
367 dma_unmap_single(dev, drv_data->rx_dma,
368 drv_data->rx_map_len, DMA_FROM_DEVICE);
369 dma_unmap_single(dev, drv_data->tx_dma,
370 drv_data->tx_map_len, DMA_TO_DEVICE);
373 drv_data->dma_mapped = 0;
376 /* caller already set message->status; dma and pio irqs are blocked */
377 static void giveback(struct driver_data *drv_data)
379 struct spi_transfer* last_transfer;
381 struct spi_message *msg;
383 spin_lock_irqsave(&drv_data->lock, flags);
384 msg = drv_data->cur_msg;
385 drv_data->cur_msg = NULL;
386 drv_data->cur_transfer = NULL;
387 drv_data->cur_chip = NULL;
388 queue_work(drv_data->workqueue, &drv_data->pump_messages);
389 spin_unlock_irqrestore(&drv_data->lock, flags);
391 last_transfer = list_entry(msg->transfers.prev,
395 if (!last_transfer->cs_change)
396 drv_data->cs_control(PXA2XX_CS_DEASSERT);
400 msg->complete(msg->context);
403 static int wait_ssp_rx_stall(void *ioaddr)
405 unsigned long limit = loops_per_jiffy << 1;
407 while ((read_SSSR(ioaddr) & SSSR_BSY) && limit--)
413 static int wait_dma_channel_stop(int channel)
415 unsigned long limit = loops_per_jiffy << 1;
417 while (!(DCSR(channel) & DCSR_STOPSTATE) && limit--)
423 void dma_error_stop(struct driver_data *drv_data, const char *msg)
425 void *reg = drv_data->ioaddr;
428 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
429 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
430 write_SSSR(drv_data->clear_sr, reg);
431 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
432 if (drv_data->ssp_type != PXA25x_SSP)
435 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
437 unmap_dma_buffers(drv_data);
439 dev_err(&drv_data->pdev->dev, "%s\n", msg);
441 drv_data->cur_msg->state = ERROR_STATE;
442 tasklet_schedule(&drv_data->pump_transfers);
445 static void dma_transfer_complete(struct driver_data *drv_data)
447 void *reg = drv_data->ioaddr;
448 struct spi_message *msg = drv_data->cur_msg;
450 /* Clear and disable interrupts on SSP and DMA channels*/
451 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
452 write_SSSR(drv_data->clear_sr, reg);
453 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
454 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
456 if (wait_dma_channel_stop(drv_data->rx_channel) == 0)
457 dev_err(&drv_data->pdev->dev,
458 "dma_handler: dma rx channel stop failed\n");
460 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
461 dev_err(&drv_data->pdev->dev,
462 "dma_transfer: ssp rx stall failed\n");
464 unmap_dma_buffers(drv_data);
466 /* update the buffer pointer for the amount completed in dma */
467 drv_data->rx += drv_data->len -
468 (DCMD(drv_data->rx_channel) & DCMD_LENGTH);
470 /* read trailing data from fifo, it does not matter how many
471 * bytes are in the fifo just read until buffer is full
472 * or fifo is empty, which ever occurs first */
473 drv_data->read(drv_data);
475 /* return count of what was actually read */
476 msg->actual_length += drv_data->len -
477 (drv_data->rx_end - drv_data->rx);
479 /* Release chip select if requested, transfer delays are
480 * handled in pump_transfers */
481 if (drv_data->cs_change)
482 drv_data->cs_control(PXA2XX_CS_DEASSERT);
484 /* Move to next transfer */
485 msg->state = next_transfer(drv_data);
487 /* Schedule transfer tasklet */
488 tasklet_schedule(&drv_data->pump_transfers);
491 static void dma_handler(int channel, void *data)
493 struct driver_data *drv_data = data;
494 u32 irq_status = DCSR(channel) & DMA_INT_MASK;
496 if (irq_status & DCSR_BUSERR) {
498 if (channel == drv_data->tx_channel)
499 dma_error_stop(drv_data,
501 "bad bus address on tx channel");
503 dma_error_stop(drv_data,
505 "bad bus address on rx channel");
509 /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */
510 if ((channel == drv_data->tx_channel)
511 && (irq_status & DCSR_ENDINTR)
512 && (drv_data->ssp_type == PXA25x_SSP)) {
514 /* Wait for rx to stall */
515 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
516 dev_err(&drv_data->pdev->dev,
517 "dma_handler: ssp rx stall failed\n");
519 /* finish this transfer, start the next */
520 dma_transfer_complete(drv_data);
524 static irqreturn_t dma_transfer(struct driver_data *drv_data)
527 void *reg = drv_data->ioaddr;
529 irq_status = read_SSSR(reg) & drv_data->mask_sr;
530 if (irq_status & SSSR_ROR) {
531 dma_error_stop(drv_data, "dma_transfer: fifo overrun");
535 /* Check for false positive timeout */
536 if ((irq_status & SSSR_TINT)
537 && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {
538 write_SSSR(SSSR_TINT, reg);
542 if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) {
544 /* Clear and disable timeout interrupt, do the rest in
545 * dma_transfer_complete */
546 if (drv_data->ssp_type != PXA25x_SSP)
549 /* finish this transfer, start the next */
550 dma_transfer_complete(drv_data);
555 /* Opps problem detected */
559 static void int_error_stop(struct driver_data *drv_data, const char* msg)
561 void *reg = drv_data->ioaddr;
563 /* Stop and reset SSP */
564 write_SSSR(drv_data->clear_sr, reg);
565 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
566 if (drv_data->ssp_type != PXA25x_SSP)
569 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
571 dev_err(&drv_data->pdev->dev, "%s\n", msg);
573 drv_data->cur_msg->state = ERROR_STATE;
574 tasklet_schedule(&drv_data->pump_transfers);
577 static void int_transfer_complete(struct driver_data *drv_data)
579 void *reg = drv_data->ioaddr;
582 write_SSSR(drv_data->clear_sr, reg);
583 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
584 if (drv_data->ssp_type != PXA25x_SSP)
587 /* Update total byte transfered return count actual bytes read */
588 drv_data->cur_msg->actual_length += drv_data->len -
589 (drv_data->rx_end - drv_data->rx);
591 /* Release chip select if requested, transfer delays are
592 * handled in pump_transfers */
593 if (drv_data->cs_change)
594 drv_data->cs_control(PXA2XX_CS_DEASSERT);
596 /* Move to next transfer */
597 drv_data->cur_msg->state = next_transfer(drv_data);
599 /* Schedule transfer tasklet */
600 tasklet_schedule(&drv_data->pump_transfers);
603 static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
605 void *reg = drv_data->ioaddr;
607 u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
608 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
610 u32 irq_status = read_SSSR(reg) & irq_mask;
612 if (irq_status & SSSR_ROR) {
613 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
617 if (irq_status & SSSR_TINT) {
618 write_SSSR(SSSR_TINT, reg);
619 if (drv_data->read(drv_data)) {
620 int_transfer_complete(drv_data);
625 /* Drain rx fifo, Fill tx fifo and prevent overruns */
627 if (drv_data->read(drv_data)) {
628 int_transfer_complete(drv_data);
631 } while (drv_data->write(drv_data));
633 if (drv_data->read(drv_data)) {
634 int_transfer_complete(drv_data);
638 if (drv_data->tx == drv_data->tx_end) {
639 write_SSCR1(read_SSCR1(reg) & ~SSCR1_TIE, reg);
640 /* PXA25x_SSP has no timeout, read trailing bytes */
641 if (drv_data->ssp_type == PXA25x_SSP) {
642 if (!wait_ssp_rx_stall(reg))
644 int_error_stop(drv_data, "interrupt_transfer: "
648 if (!drv_data->read(drv_data))
650 int_error_stop(drv_data,
651 "interrupt_transfer: "
652 "trailing byte read failed");
655 int_transfer_complete(drv_data);
659 /* We did something */
663 static irqreturn_t ssp_int(int irq, void *dev_id)
665 struct driver_data *drv_data = dev_id;
666 void *reg = drv_data->ioaddr;
668 if (!drv_data->cur_msg) {
670 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
671 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
672 if (drv_data->ssp_type != PXA25x_SSP)
674 write_SSSR(drv_data->clear_sr, reg);
676 dev_err(&drv_data->pdev->dev, "bad message state "
677 "in interrupt handler\n");
683 return drv_data->transfer_handler(drv_data);
686 int set_dma_burst_and_threshold(struct chip_data *chip, struct spi_device *spi,
687 u8 bits_per_word, u32 *burst_code,
690 struct pxa2xx_spi_chip *chip_info =
691 (struct pxa2xx_spi_chip *)spi->controller_data;
698 /* Set the threshold (in registers) to equal the same amount of data
699 * as represented by burst size (in bytes). The computation below
700 * is (burst_size rounded up to nearest 8 byte, word or long word)
701 * divided by (bytes/register); the tx threshold is the inverse of
702 * the rx, so that there will always be enough data in the rx fifo
703 * to satisfy a burst, and there will always be enough space in the
704 * tx fifo to accept a burst (a tx burst will overwrite the fifo if
705 * there is not enough space), there must always remain enough empty
706 * space in the rx fifo for any data loaded to the tx fifo.
707 * Whenever burst_size (in bytes) equals bits/word, the fifo threshold
708 * will be 8, or half the fifo;
709 * The threshold can only be set to 2, 4 or 8, but not 16, because
710 * to burst 16 to the tx fifo, the fifo would have to be empty;
711 * however, the minimum fifo trigger level is 1, and the tx will
712 * request service when the fifo is at this level, with only 15 spaces.
715 /* find bytes/word */
716 if (bits_per_word <= 8)
718 else if (bits_per_word <= 16)
723 /* use struct pxa2xx_spi_chip->dma_burst_size if available */
725 req_burst_size = chip_info->dma_burst_size;
727 switch (chip->dma_burst_size) {
729 /* if the default burst size is not set,
731 chip->dma_burst_size = DCMD_BURST8;
743 if (req_burst_size <= 8) {
744 *burst_code = DCMD_BURST8;
746 } else if (req_burst_size <= 16) {
747 if (bytes_per_word == 1) {
748 /* don't burst more than 1/2 the fifo */
749 *burst_code = DCMD_BURST8;
753 *burst_code = DCMD_BURST16;
757 if (bytes_per_word == 1) {
758 /* don't burst more than 1/2 the fifo */
759 *burst_code = DCMD_BURST8;
762 } else if (bytes_per_word == 2) {
763 /* don't burst more than 1/2 the fifo */
764 *burst_code = DCMD_BURST16;
768 *burst_code = DCMD_BURST32;
773 thresh_words = burst_bytes / bytes_per_word;
775 /* thresh_words will be between 2 and 8 */
776 *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)
777 | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);
782 static void pump_transfers(unsigned long data)
784 struct driver_data *drv_data = (struct driver_data *)data;
785 struct spi_message *message = NULL;
786 struct spi_transfer *transfer = NULL;
787 struct spi_transfer *previous = NULL;
788 struct chip_data *chip = NULL;
789 void *reg = drv_data->ioaddr;
795 u32 dma_thresh = drv_data->cur_chip->dma_threshold;
796 u32 dma_burst = drv_data->cur_chip->dma_burst_size;
798 /* Get current state information */
799 message = drv_data->cur_msg;
800 transfer = drv_data->cur_transfer;
801 chip = drv_data->cur_chip;
803 /* Handle for abort */
804 if (message->state == ERROR_STATE) {
805 message->status = -EIO;
810 /* Handle end of message */
811 if (message->state == DONE_STATE) {
817 /* Delay if requested at end of transfer*/
818 if (message->state == RUNNING_STATE) {
819 previous = list_entry(transfer->transfer_list.prev,
822 if (previous->delay_usecs)
823 udelay(previous->delay_usecs);
826 /* Check transfer length */
827 if (transfer->len > 8191)
829 dev_warn(&drv_data->pdev->dev, "pump_transfers: transfer "
830 "length greater than 8191\n");
831 message->status = -EINVAL;
836 /* Setup the transfer state based on the type of transfer */
837 if (flush(drv_data) == 0) {
838 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
839 message->status = -EIO;
843 drv_data->n_bytes = chip->n_bytes;
844 drv_data->dma_width = chip->dma_width;
845 drv_data->cs_control = chip->cs_control;
846 drv_data->tx = (void *)transfer->tx_buf;
847 drv_data->tx_end = drv_data->tx + transfer->len;
848 drv_data->rx = transfer->rx_buf;
849 drv_data->rx_end = drv_data->rx + transfer->len;
850 drv_data->rx_dma = transfer->rx_dma;
851 drv_data->tx_dma = transfer->tx_dma;
852 drv_data->len = transfer->len & DCMD_LENGTH;
853 drv_data->write = drv_data->tx ? chip->write : null_writer;
854 drv_data->read = drv_data->rx ? chip->read : null_reader;
855 drv_data->cs_change = transfer->cs_change;
857 /* Change speed and bit per word on a per transfer */
859 if (transfer->speed_hz || transfer->bits_per_word) {
861 bits = chip->bits_per_word;
862 speed = chip->speed_hz;
864 if (transfer->speed_hz)
865 speed = transfer->speed_hz;
867 if (transfer->bits_per_word)
868 bits = transfer->bits_per_word;
870 if (reg == SSP1_VIRT)
871 clk_div = SSP1_SerClkDiv(speed);
872 else if (reg == SSP2_VIRT)
873 clk_div = SSP2_SerClkDiv(speed);
874 else if (reg == SSP3_VIRT)
875 clk_div = SSP3_SerClkDiv(speed);
878 drv_data->n_bytes = 1;
879 drv_data->dma_width = DCMD_WIDTH1;
880 drv_data->read = drv_data->read != null_reader ?
881 u8_reader : null_reader;
882 drv_data->write = drv_data->write != null_writer ?
883 u8_writer : null_writer;
884 } else if (bits <= 16) {
885 drv_data->n_bytes = 2;
886 drv_data->dma_width = DCMD_WIDTH2;
887 drv_data->read = drv_data->read != null_reader ?
888 u16_reader : null_reader;
889 drv_data->write = drv_data->write != null_writer ?
890 u16_writer : null_writer;
891 } else if (bits <= 32) {
892 drv_data->n_bytes = 4;
893 drv_data->dma_width = DCMD_WIDTH4;
894 drv_data->read = drv_data->read != null_reader ?
895 u32_reader : null_reader;
896 drv_data->write = drv_data->write != null_writer ?
897 u32_writer : null_writer;
899 /* if bits/word is changed in dma mode, then must check the
900 * thresholds and burst also */
901 if (chip->enable_dma) {
902 if (set_dma_burst_and_threshold(chip, message->spi,
905 if (printk_ratelimit())
906 dev_warn(&message->spi->dev,
908 "DMA burst size reduced to "
909 "match bits_per_word\n");
914 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
916 | (bits > 16 ? SSCR0_EDSS : 0);
919 message->state = RUNNING_STATE;
921 /* Try to map dma buffer and do a dma transfer if successful */
922 if ((drv_data->dma_mapped = map_dma_buffers(drv_data))) {
924 /* Ensure we have the correct interrupt handler */
925 drv_data->transfer_handler = dma_transfer;
927 /* Setup rx DMA Channel */
928 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
929 DSADR(drv_data->rx_channel) = drv_data->ssdr_physical;
930 DTADR(drv_data->rx_channel) = drv_data->rx_dma;
931 if (drv_data->rx == drv_data->null_dma_buf)
932 /* No target address increment */
933 DCMD(drv_data->rx_channel) = DCMD_FLOWSRC
934 | drv_data->dma_width
938 DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR
940 | drv_data->dma_width
944 /* Setup tx DMA Channel */
945 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
946 DSADR(drv_data->tx_channel) = drv_data->tx_dma;
947 DTADR(drv_data->tx_channel) = drv_data->ssdr_physical;
948 if (drv_data->tx == drv_data->null_dma_buf)
949 /* No source address increment */
950 DCMD(drv_data->tx_channel) = DCMD_FLOWTRG
951 | drv_data->dma_width
955 DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR
957 | drv_data->dma_width
961 /* Enable dma end irqs on SSP to detect end of transfer */
962 if (drv_data->ssp_type == PXA25x_SSP)
963 DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN;
965 /* Fix me, need to handle cs polarity */
966 drv_data->cs_control(PXA2XX_CS_ASSERT);
968 /* Clear status and start DMA engine */
969 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
970 write_SSSR(drv_data->clear_sr, reg);
971 DCSR(drv_data->rx_channel) |= DCSR_RUN;
972 DCSR(drv_data->tx_channel) |= DCSR_RUN;
974 /* Ensure we have the correct interrupt handler */
975 drv_data->transfer_handler = interrupt_transfer;
977 /* Fix me, need to handle cs polarity */
978 drv_data->cs_control(PXA2XX_CS_ASSERT);
981 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
982 write_SSSR(drv_data->clear_sr, reg);
985 /* see if we need to reload the config registers */
986 if ((read_SSCR0(reg) != cr0)
987 || (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
988 (cr1 & SSCR1_CHANGE_MASK)) {
990 write_SSCR0(cr0 & ~SSCR0_SSE, reg);
991 if (drv_data->ssp_type != PXA25x_SSP)
992 write_SSTO(chip->timeout, reg);
993 write_SSCR1(cr1, reg);
994 write_SSCR0(cr0, reg);
996 if (drv_data->ssp_type != PXA25x_SSP)
997 write_SSTO(chip->timeout, reg);
998 write_SSCR1(cr1, reg);
1002 static void pump_messages(struct work_struct *work)
1004 struct driver_data *drv_data =
1005 container_of(work, struct driver_data, pump_messages);
1006 unsigned long flags;
1008 /* Lock queue and check for queue work */
1009 spin_lock_irqsave(&drv_data->lock, flags);
1010 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
1012 spin_unlock_irqrestore(&drv_data->lock, flags);
1016 /* Make sure we are not already running a message */
1017 if (drv_data->cur_msg) {
1018 spin_unlock_irqrestore(&drv_data->lock, flags);
1022 /* Extract head of queue */
1023 drv_data->cur_msg = list_entry(drv_data->queue.next,
1024 struct spi_message, queue);
1025 list_del_init(&drv_data->cur_msg->queue);
1027 /* Initial message state*/
1028 drv_data->cur_msg->state = START_STATE;
1029 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
1030 struct spi_transfer,
1033 /* prepare to setup the SSP, in pump_transfers, using the per
1034 * chip configuration */
1035 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
1037 /* Mark as busy and launch transfers */
1038 tasklet_schedule(&drv_data->pump_transfers);
1041 spin_unlock_irqrestore(&drv_data->lock, flags);
1044 static int transfer(struct spi_device *spi, struct spi_message *msg)
1046 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1047 unsigned long flags;
1049 spin_lock_irqsave(&drv_data->lock, flags);
1051 if (drv_data->run == QUEUE_STOPPED) {
1052 spin_unlock_irqrestore(&drv_data->lock, flags);
1056 msg->actual_length = 0;
1057 msg->status = -EINPROGRESS;
1058 msg->state = START_STATE;
1060 list_add_tail(&msg->queue, &drv_data->queue);
1062 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
1063 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1065 spin_unlock_irqrestore(&drv_data->lock, flags);
1070 /* the spi->mode bits understood by this driver: */
1071 #define MODEBITS (SPI_CPOL | SPI_CPHA)
1073 static int setup(struct spi_device *spi)
1075 struct pxa2xx_spi_chip *chip_info = NULL;
1076 struct chip_data *chip;
1077 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1078 unsigned int clk_div;
1080 if (!spi->bits_per_word)
1081 spi->bits_per_word = 8;
1083 if (drv_data->ssp_type != PXA25x_SSP
1084 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
1085 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1086 "b/w not 4-32 for type non-PXA25x_SSP\n",
1087 drv_data->ssp_type, spi->bits_per_word);
1090 else if (drv_data->ssp_type == PXA25x_SSP
1091 && (spi->bits_per_word < 4
1092 || spi->bits_per_word > 16)) {
1093 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1094 "b/w not 4-16 for type PXA25x_SSP\n",
1095 drv_data->ssp_type, spi->bits_per_word);
1099 if (spi->mode & ~MODEBITS) {
1100 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
1101 spi->mode & ~MODEBITS);
1105 /* Only alloc on first setup */
1106 chip = spi_get_ctldata(spi);
1108 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
1111 "failed setup: can't allocate chip data\n");
1115 chip->cs_control = null_cs_control;
1116 chip->enable_dma = 0;
1117 chip->timeout = 1000;
1118 chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1);
1119 chip->dma_burst_size = drv_data->master_info->enable_dma ?
1123 /* protocol drivers may change the chip settings, so...
1124 * if chip_info exists, use it */
1125 chip_info = spi->controller_data;
1127 /* chip_info isn't always needed */
1130 if (chip_info->cs_control)
1131 chip->cs_control = chip_info->cs_control;
1133 chip->timeout = chip_info->timeout;
1135 chip->threshold = (SSCR1_RxTresh(chip_info->rx_threshold) &
1137 (SSCR1_TxTresh(chip_info->tx_threshold) &
1140 chip->enable_dma = chip_info->dma_burst_size != 0
1141 && drv_data->master_info->enable_dma;
1142 chip->dma_threshold = 0;
1144 if (chip_info->enable_loopback)
1145 chip->cr1 = SSCR1_LBM;
1148 /* set dma burst and threshold outside of chip_info path so that if
1149 * chip_info goes away after setting chip->enable_dma, the
1150 * burst and threshold can still respond to changes in bits_per_word */
1151 if (chip->enable_dma) {
1152 /* set up legal burst and threshold for dma */
1153 if (set_dma_burst_and_threshold(chip, spi, spi->bits_per_word,
1154 &chip->dma_burst_size,
1155 &chip->dma_threshold)) {
1156 dev_warn(&spi->dev, "in setup: DMA burst size reduced "
1157 "to match bits_per_word\n");
1161 if (drv_data->ioaddr == SSP1_VIRT)
1162 clk_div = SSP1_SerClkDiv(spi->max_speed_hz);
1163 else if (drv_data->ioaddr == SSP2_VIRT)
1164 clk_div = SSP2_SerClkDiv(spi->max_speed_hz);
1165 else if (drv_data->ioaddr == SSP3_VIRT)
1166 clk_div = SSP3_SerClkDiv(spi->max_speed_hz);
1169 dev_err(&spi->dev, "failed setup: unknown IO address=0x%p\n",
1173 chip->speed_hz = spi->max_speed_hz;
1177 | SSCR0_DataSize(spi->bits_per_word > 16 ?
1178 spi->bits_per_word - 16 : spi->bits_per_word)
1180 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
1181 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1182 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1183 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
1185 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1186 if (drv_data->ssp_type != PXA25x_SSP)
1187 dev_dbg(&spi->dev, "%d bits/word, %d Hz, mode %d\n",
1190 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1193 dev_dbg(&spi->dev, "%d bits/word, %d Hz, mode %d\n",
1196 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1199 if (spi->bits_per_word <= 8) {
1201 chip->dma_width = DCMD_WIDTH1;
1202 chip->read = u8_reader;
1203 chip->write = u8_writer;
1204 } else if (spi->bits_per_word <= 16) {
1206 chip->dma_width = DCMD_WIDTH2;
1207 chip->read = u16_reader;
1208 chip->write = u16_writer;
1209 } else if (spi->bits_per_word <= 32) {
1210 chip->cr0 |= SSCR0_EDSS;
1212 chip->dma_width = DCMD_WIDTH4;
1213 chip->read = u32_reader;
1214 chip->write = u32_writer;
1216 dev_err(&spi->dev, "invalid wordsize\n");
1219 chip->bits_per_word = spi->bits_per_word;
1221 spi_set_ctldata(spi, chip);
1226 static void cleanup(struct spi_device *spi)
1228 struct chip_data *chip = spi_get_ctldata(spi);
1233 static int init_queue(struct driver_data *drv_data)
1235 INIT_LIST_HEAD(&drv_data->queue);
1236 spin_lock_init(&drv_data->lock);
1238 drv_data->run = QUEUE_STOPPED;
1241 tasklet_init(&drv_data->pump_transfers,
1242 pump_transfers, (unsigned long)drv_data);
1244 INIT_WORK(&drv_data->pump_messages, pump_messages);
1245 drv_data->workqueue = create_singlethread_workqueue(
1246 drv_data->master->cdev.dev->bus_id);
1247 if (drv_data->workqueue == NULL)
1253 static int start_queue(struct driver_data *drv_data)
1255 unsigned long flags;
1257 spin_lock_irqsave(&drv_data->lock, flags);
1259 if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
1260 spin_unlock_irqrestore(&drv_data->lock, flags);
1264 drv_data->run = QUEUE_RUNNING;
1265 drv_data->cur_msg = NULL;
1266 drv_data->cur_transfer = NULL;
1267 drv_data->cur_chip = NULL;
1268 spin_unlock_irqrestore(&drv_data->lock, flags);
1270 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1275 static int stop_queue(struct driver_data *drv_data)
1277 unsigned long flags;
1278 unsigned limit = 500;
1281 spin_lock_irqsave(&drv_data->lock, flags);
1283 /* This is a bit lame, but is optimized for the common execution path.
1284 * A wait_queue on the drv_data->busy could be used, but then the common
1285 * execution path (pump_messages) would be required to call wake_up or
1286 * friends on every SPI message. Do this instead */
1287 drv_data->run = QUEUE_STOPPED;
1288 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1289 spin_unlock_irqrestore(&drv_data->lock, flags);
1291 spin_lock_irqsave(&drv_data->lock, flags);
1294 if (!list_empty(&drv_data->queue) || drv_data->busy)
1297 spin_unlock_irqrestore(&drv_data->lock, flags);
1302 static int destroy_queue(struct driver_data *drv_data)
1306 status = stop_queue(drv_data);
1307 /* we are unloading the module or failing to load (only two calls
1308 * to this routine), and neither call can handle a return value.
1309 * However, destroy_workqueue calls flush_workqueue, and that will
1310 * block until all work is done. If the reason that stop_queue
1311 * timed out is that the work will never finish, then it does no
1312 * good to call destroy_workqueue, so return anyway. */
1316 destroy_workqueue(drv_data->workqueue);
1321 static int pxa2xx_spi_probe(struct platform_device *pdev)
1323 struct device *dev = &pdev->dev;
1324 struct pxa2xx_spi_master *platform_info;
1325 struct spi_master *master;
1326 struct driver_data *drv_data = 0;
1327 struct resource *memory_resource;
1331 platform_info = dev->platform_data;
1333 if (platform_info->ssp_type == SSP_UNDEFINED) {
1334 dev_err(&pdev->dev, "undefined SSP\n");
1338 /* Allocate master with space for drv_data and null dma buffer */
1339 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
1341 dev_err(&pdev->dev, "can not alloc spi_master\n");
1344 drv_data = spi_master_get_devdata(master);
1345 drv_data->master = master;
1346 drv_data->master_info = platform_info;
1347 drv_data->pdev = pdev;
1349 master->bus_num = pdev->id;
1350 master->num_chipselect = platform_info->num_chipselect;
1351 master->cleanup = cleanup;
1352 master->setup = setup;
1353 master->transfer = transfer;
1355 drv_data->ssp_type = platform_info->ssp_type;
1356 drv_data->null_dma_buf = (u32 *)ALIGN((u32)(drv_data +
1357 sizeof(struct driver_data)), 8);
1359 /* Setup register addresses */
1360 memory_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1361 if (!memory_resource) {
1362 dev_err(&pdev->dev, "memory resources not defined\n");
1364 goto out_error_master_alloc;
1367 drv_data->ioaddr = (void *)io_p2v((unsigned long)(memory_resource->start));
1368 drv_data->ssdr_physical = memory_resource->start + 0x00000010;
1369 if (platform_info->ssp_type == PXA25x_SSP) {
1370 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
1371 drv_data->dma_cr1 = 0;
1372 drv_data->clear_sr = SSSR_ROR;
1373 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
1375 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
1376 drv_data->dma_cr1 = SSCR1_TSRE | SSCR1_RSRE | SSCR1_TINTE;
1377 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1378 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1382 irq = platform_get_irq(pdev, 0);
1384 dev_err(&pdev->dev, "irq resource not defined\n");
1386 goto out_error_master_alloc;
1389 status = request_irq(irq, ssp_int, 0, dev->bus_id, drv_data);
1391 dev_err(&pdev->dev, "can not get IRQ\n");
1392 goto out_error_master_alloc;
1395 /* Setup DMA if requested */
1396 drv_data->tx_channel = -1;
1397 drv_data->rx_channel = -1;
1398 if (platform_info->enable_dma) {
1400 /* Get two DMA channels (rx and tx) */
1401 drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx",
1405 if (drv_data->rx_channel < 0) {
1406 dev_err(dev, "problem (%d) requesting rx channel\n",
1407 drv_data->rx_channel);
1409 goto out_error_irq_alloc;
1411 drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx",
1415 if (drv_data->tx_channel < 0) {
1416 dev_err(dev, "problem (%d) requesting tx channel\n",
1417 drv_data->tx_channel);
1419 goto out_error_dma_alloc;
1422 if (drv_data->ioaddr == SSP1_VIRT) {
1423 DRCMRRXSSDR = DRCMR_MAPVLD
1424 | drv_data->rx_channel;
1425 DRCMRTXSSDR = DRCMR_MAPVLD
1426 | drv_data->tx_channel;
1427 } else if (drv_data->ioaddr == SSP2_VIRT) {
1428 DRCMRRXSS2DR = DRCMR_MAPVLD
1429 | drv_data->rx_channel;
1430 DRCMRTXSS2DR = DRCMR_MAPVLD
1431 | drv_data->tx_channel;
1432 } else if (drv_data->ioaddr == SSP3_VIRT) {
1433 DRCMRRXSS3DR = DRCMR_MAPVLD
1434 | drv_data->rx_channel;
1435 DRCMRTXSS3DR = DRCMR_MAPVLD
1436 | drv_data->tx_channel;
1438 dev_err(dev, "bad SSP type\n");
1439 goto out_error_dma_alloc;
1443 /* Enable SOC clock */
1444 pxa_set_cken(platform_info->clock_enable, 1);
1446 /* Load default SSP configuration */
1447 write_SSCR0(0, drv_data->ioaddr);
1448 write_SSCR1(SSCR1_RxTresh(4) | SSCR1_TxTresh(12), drv_data->ioaddr);
1449 write_SSCR0(SSCR0_SerClkDiv(2)
1451 | SSCR0_DataSize(8),
1453 if (drv_data->ssp_type != PXA25x_SSP)
1454 write_SSTO(0, drv_data->ioaddr);
1455 write_SSPSP(0, drv_data->ioaddr);
1457 /* Initial and start queue */
1458 status = init_queue(drv_data);
1460 dev_err(&pdev->dev, "problem initializing queue\n");
1461 goto out_error_clock_enabled;
1463 status = start_queue(drv_data);
1465 dev_err(&pdev->dev, "problem starting queue\n");
1466 goto out_error_clock_enabled;
1469 /* Register with the SPI framework */
1470 platform_set_drvdata(pdev, drv_data);
1471 status = spi_register_master(master);
1473 dev_err(&pdev->dev, "problem registering spi master\n");
1474 goto out_error_queue_alloc;
1479 out_error_queue_alloc:
1480 destroy_queue(drv_data);
1482 out_error_clock_enabled:
1483 pxa_set_cken(platform_info->clock_enable, 0);
1485 out_error_dma_alloc:
1486 if (drv_data->tx_channel != -1)
1487 pxa_free_dma(drv_data->tx_channel);
1488 if (drv_data->rx_channel != -1)
1489 pxa_free_dma(drv_data->rx_channel);
1491 out_error_irq_alloc:
1492 free_irq(irq, drv_data);
1494 out_error_master_alloc:
1495 spi_master_put(master);
1499 static int pxa2xx_spi_remove(struct platform_device *pdev)
1501 struct driver_data *drv_data = platform_get_drvdata(pdev);
1508 /* Remove the queue */
1509 status = destroy_queue(drv_data);
1511 /* the kernel does not check the return status of this
1512 * this routine (mod->exit, within the kernel). Therefore
1513 * nothing is gained by returning from here, the module is
1514 * going away regardless, and we should not leave any more
1515 * resources allocated than necessary. We cannot free the
1516 * message memory in drv_data->queue, but we can release the
1517 * resources below. I think the kernel should honor -EBUSY
1519 dev_err(&pdev->dev, "pxa2xx_spi_remove: workqueue will not "
1520 "complete, message memory not freed\n");
1522 /* Disable the SSP at the peripheral and SOC level */
1523 write_SSCR0(0, drv_data->ioaddr);
1524 pxa_set_cken(drv_data->master_info->clock_enable, 0);
1527 if (drv_data->master_info->enable_dma) {
1528 if (drv_data->ioaddr == SSP1_VIRT) {
1531 } else if (drv_data->ioaddr == SSP2_VIRT) {
1534 } else if (drv_data->ioaddr == SSP3_VIRT) {
1538 pxa_free_dma(drv_data->tx_channel);
1539 pxa_free_dma(drv_data->rx_channel);
1543 irq = platform_get_irq(pdev, 0);
1545 free_irq(irq, drv_data);
1547 /* Disconnect from the SPI framework */
1548 spi_unregister_master(drv_data->master);
1550 /* Prevent double remove */
1551 platform_set_drvdata(pdev, NULL);
1556 static void pxa2xx_spi_shutdown(struct platform_device *pdev)
1560 if ((status = pxa2xx_spi_remove(pdev)) != 0)
1561 dev_err(&pdev->dev, "shutdown failed with %d\n", status);
1565 static int suspend_devices(struct device *dev, void *pm_message)
1567 pm_message_t *state = pm_message;
1569 if (dev->power.power_state.event != state->event) {
1570 dev_warn(dev, "pm state does not match request\n");
1577 static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
1579 struct driver_data *drv_data = platform_get_drvdata(pdev);
1582 /* Check all childern for current power state */
1583 if (device_for_each_child(&pdev->dev, &state, suspend_devices) != 0) {
1584 dev_warn(&pdev->dev, "suspend aborted\n");
1588 status = stop_queue(drv_data);
1591 write_SSCR0(0, drv_data->ioaddr);
1592 pxa_set_cken(drv_data->master_info->clock_enable, 0);
1597 static int pxa2xx_spi_resume(struct platform_device *pdev)
1599 struct driver_data *drv_data = platform_get_drvdata(pdev);
1602 /* Enable the SSP clock */
1603 pxa_set_cken(drv_data->master_info->clock_enable, 1);
1605 /* Start the queue running */
1606 status = start_queue(drv_data);
1608 dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
1615 #define pxa2xx_spi_suspend NULL
1616 #define pxa2xx_spi_resume NULL
1617 #endif /* CONFIG_PM */
1619 static struct platform_driver driver = {
1621 .name = "pxa2xx-spi",
1622 .bus = &platform_bus_type,
1623 .owner = THIS_MODULE,
1625 .probe = pxa2xx_spi_probe,
1626 .remove = __devexit_p(pxa2xx_spi_remove),
1627 .shutdown = pxa2xx_spi_shutdown,
1628 .suspend = pxa2xx_spi_suspend,
1629 .resume = pxa2xx_spi_resume,
1632 static int __init pxa2xx_spi_init(void)
1634 platform_driver_register(&driver);
1638 module_init(pxa2xx_spi_init);
1640 static void __exit pxa2xx_spi_exit(void)
1642 platform_driver_unregister(&driver);
1644 module_exit(pxa2xx_spi_exit);