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/delay.h>
30 #include <linux/clk.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/regs-ssp.h>
41 #include <asm/arch/ssp.h>
42 #include <asm/arch/pxa2xx_spi.h>
44 MODULE_AUTHOR("Stephen Street");
45 MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
46 MODULE_LICENSE("GPL");
47 MODULE_ALIAS("platform:pxa2xx-spi");
51 #define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)
52 #define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)
53 #define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0)
56 * for testing SSCR1 changes that require SSP restart, basically
57 * everything except the service and interrupt enables, the pxa270 developer
58 * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
59 * list, but the PXA255 dev man says all bits without really meaning the
60 * service and interrupt enables
62 #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
63 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
64 | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
65 | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
66 | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
67 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
69 #define DEFINE_SSP_REG(reg, off) \
70 static inline u32 read_##reg(void const __iomem *p) \
71 { return __raw_readl(p + (off)); } \
73 static inline void write_##reg(u32 v, void __iomem *p) \
74 { __raw_writel(v, p + (off)); }
76 DEFINE_SSP_REG(SSCR0, 0x00)
77 DEFINE_SSP_REG(SSCR1, 0x04)
78 DEFINE_SSP_REG(SSSR, 0x08)
79 DEFINE_SSP_REG(SSITR, 0x0c)
80 DEFINE_SSP_REG(SSDR, 0x10)
81 DEFINE_SSP_REG(SSTO, 0x28)
82 DEFINE_SSP_REG(SSPSP, 0x2c)
84 #define START_STATE ((void*)0)
85 #define RUNNING_STATE ((void*)1)
86 #define DONE_STATE ((void*)2)
87 #define ERROR_STATE ((void*)-1)
89 #define QUEUE_RUNNING 0
90 #define QUEUE_STOPPED 1
93 /* Driver model hookup */
94 struct platform_device *pdev;
97 struct ssp_device *ssp;
99 /* SPI framework hookup */
100 enum pxa_ssp_type ssp_type;
101 struct spi_master *master;
104 struct pxa2xx_spi_master *master_info;
106 /* DMA setup stuff */
111 /* SSP register addresses */
112 void __iomem *ioaddr;
121 /* Driver message queue */
122 struct workqueue_struct *workqueue;
123 struct work_struct pump_messages;
125 struct list_head queue;
129 /* Message Transfer pump */
130 struct tasklet_struct pump_transfers;
132 /* Current message transfer state info */
133 struct spi_message* cur_msg;
134 struct spi_transfer* cur_transfer;
135 struct chip_data *cur_chip;
149 int (*write)(struct driver_data *drv_data);
150 int (*read)(struct driver_data *drv_data);
151 irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
152 void (*cs_control)(u32 command);
168 int (*write)(struct driver_data *drv_data);
169 int (*read)(struct driver_data *drv_data);
170 void (*cs_control)(u32 command);
173 static void pump_messages(struct work_struct *work);
175 static int flush(struct driver_data *drv_data)
177 unsigned long limit = loops_per_jiffy << 1;
179 void __iomem *reg = drv_data->ioaddr;
182 while (read_SSSR(reg) & SSSR_RNE) {
185 } while ((read_SSSR(reg) & SSSR_BSY) && limit--);
186 write_SSSR(SSSR_ROR, reg);
191 static void null_cs_control(u32 command)
195 static int null_writer(struct driver_data *drv_data)
197 void __iomem *reg = drv_data->ioaddr;
198 u8 n_bytes = drv_data->n_bytes;
200 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
201 || (drv_data->tx == drv_data->tx_end))
205 drv_data->tx += n_bytes;
210 static int null_reader(struct driver_data *drv_data)
212 void __iomem *reg = drv_data->ioaddr;
213 u8 n_bytes = drv_data->n_bytes;
215 while ((read_SSSR(reg) & SSSR_RNE)
216 && (drv_data->rx < drv_data->rx_end)) {
218 drv_data->rx += n_bytes;
221 return drv_data->rx == drv_data->rx_end;
224 static int u8_writer(struct driver_data *drv_data)
226 void __iomem *reg = drv_data->ioaddr;
228 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
229 || (drv_data->tx == drv_data->tx_end))
232 write_SSDR(*(u8 *)(drv_data->tx), reg);
238 static int u8_reader(struct driver_data *drv_data)
240 void __iomem *reg = drv_data->ioaddr;
242 while ((read_SSSR(reg) & SSSR_RNE)
243 && (drv_data->rx < drv_data->rx_end)) {
244 *(u8 *)(drv_data->rx) = read_SSDR(reg);
248 return drv_data->rx == drv_data->rx_end;
251 static int u16_writer(struct driver_data *drv_data)
253 void __iomem *reg = drv_data->ioaddr;
255 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
256 || (drv_data->tx == drv_data->tx_end))
259 write_SSDR(*(u16 *)(drv_data->tx), reg);
265 static int u16_reader(struct driver_data *drv_data)
267 void __iomem *reg = drv_data->ioaddr;
269 while ((read_SSSR(reg) & SSSR_RNE)
270 && (drv_data->rx < drv_data->rx_end)) {
271 *(u16 *)(drv_data->rx) = read_SSDR(reg);
275 return drv_data->rx == drv_data->rx_end;
278 static int u32_writer(struct driver_data *drv_data)
280 void __iomem *reg = drv_data->ioaddr;
282 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
283 || (drv_data->tx == drv_data->tx_end))
286 write_SSDR(*(u32 *)(drv_data->tx), reg);
292 static int u32_reader(struct driver_data *drv_data)
294 void __iomem *reg = drv_data->ioaddr;
296 while ((read_SSSR(reg) & SSSR_RNE)
297 && (drv_data->rx < drv_data->rx_end)) {
298 *(u32 *)(drv_data->rx) = read_SSDR(reg);
302 return drv_data->rx == drv_data->rx_end;
305 static void *next_transfer(struct driver_data *drv_data)
307 struct spi_message *msg = drv_data->cur_msg;
308 struct spi_transfer *trans = drv_data->cur_transfer;
310 /* Move to next transfer */
311 if (trans->transfer_list.next != &msg->transfers) {
312 drv_data->cur_transfer =
313 list_entry(trans->transfer_list.next,
316 return RUNNING_STATE;
321 static int map_dma_buffers(struct driver_data *drv_data)
323 struct spi_message *msg = drv_data->cur_msg;
324 struct device *dev = &msg->spi->dev;
326 if (!drv_data->cur_chip->enable_dma)
329 if (msg->is_dma_mapped)
330 return drv_data->rx_dma && drv_data->tx_dma;
332 if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
335 /* Modify setup if rx buffer is null */
336 if (drv_data->rx == NULL) {
337 *drv_data->null_dma_buf = 0;
338 drv_data->rx = drv_data->null_dma_buf;
339 drv_data->rx_map_len = 4;
341 drv_data->rx_map_len = drv_data->len;
344 /* Modify setup if tx buffer is null */
345 if (drv_data->tx == NULL) {
346 *drv_data->null_dma_buf = 0;
347 drv_data->tx = drv_data->null_dma_buf;
348 drv_data->tx_map_len = 4;
350 drv_data->tx_map_len = drv_data->len;
352 /* Stream map the rx buffer */
353 drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
354 drv_data->rx_map_len,
356 if (dma_mapping_error(drv_data->rx_dma))
359 /* Stream map the tx buffer */
360 drv_data->tx_dma = dma_map_single(dev, drv_data->tx,
361 drv_data->tx_map_len,
364 if (dma_mapping_error(drv_data->tx_dma)) {
365 dma_unmap_single(dev, drv_data->rx_dma,
366 drv_data->rx_map_len, DMA_FROM_DEVICE);
373 static void unmap_dma_buffers(struct driver_data *drv_data)
377 if (!drv_data->dma_mapped)
380 if (!drv_data->cur_msg->is_dma_mapped) {
381 dev = &drv_data->cur_msg->spi->dev;
382 dma_unmap_single(dev, drv_data->rx_dma,
383 drv_data->rx_map_len, DMA_FROM_DEVICE);
384 dma_unmap_single(dev, drv_data->tx_dma,
385 drv_data->tx_map_len, DMA_TO_DEVICE);
388 drv_data->dma_mapped = 0;
391 /* caller already set message->status; dma and pio irqs are blocked */
392 static void giveback(struct driver_data *drv_data)
394 struct spi_transfer* last_transfer;
396 struct spi_message *msg;
398 spin_lock_irqsave(&drv_data->lock, flags);
399 msg = drv_data->cur_msg;
400 drv_data->cur_msg = NULL;
401 drv_data->cur_transfer = NULL;
402 drv_data->cur_chip = NULL;
403 queue_work(drv_data->workqueue, &drv_data->pump_messages);
404 spin_unlock_irqrestore(&drv_data->lock, flags);
406 last_transfer = list_entry(msg->transfers.prev,
410 if (!last_transfer->cs_change)
411 drv_data->cs_control(PXA2XX_CS_DEASSERT);
415 msg->complete(msg->context);
418 static int wait_ssp_rx_stall(void const __iomem *ioaddr)
420 unsigned long limit = loops_per_jiffy << 1;
422 while ((read_SSSR(ioaddr) & SSSR_BSY) && limit--)
428 static int wait_dma_channel_stop(int channel)
430 unsigned long limit = loops_per_jiffy << 1;
432 while (!(DCSR(channel) & DCSR_STOPSTATE) && limit--)
438 static void dma_error_stop(struct driver_data *drv_data, const char *msg)
440 void __iomem *reg = drv_data->ioaddr;
443 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
444 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
445 write_SSSR(drv_data->clear_sr, reg);
446 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
447 if (drv_data->ssp_type != PXA25x_SSP)
450 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
452 unmap_dma_buffers(drv_data);
454 dev_err(&drv_data->pdev->dev, "%s\n", msg);
456 drv_data->cur_msg->state = ERROR_STATE;
457 tasklet_schedule(&drv_data->pump_transfers);
460 static void dma_transfer_complete(struct driver_data *drv_data)
462 void __iomem *reg = drv_data->ioaddr;
463 struct spi_message *msg = drv_data->cur_msg;
465 /* Clear and disable interrupts on SSP and DMA channels*/
466 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
467 write_SSSR(drv_data->clear_sr, reg);
468 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
469 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
471 if (wait_dma_channel_stop(drv_data->rx_channel) == 0)
472 dev_err(&drv_data->pdev->dev,
473 "dma_handler: dma rx channel stop failed\n");
475 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
476 dev_err(&drv_data->pdev->dev,
477 "dma_transfer: ssp rx stall failed\n");
479 unmap_dma_buffers(drv_data);
481 /* update the buffer pointer for the amount completed in dma */
482 drv_data->rx += drv_data->len -
483 (DCMD(drv_data->rx_channel) & DCMD_LENGTH);
485 /* read trailing data from fifo, it does not matter how many
486 * bytes are in the fifo just read until buffer is full
487 * or fifo is empty, which ever occurs first */
488 drv_data->read(drv_data);
490 /* return count of what was actually read */
491 msg->actual_length += drv_data->len -
492 (drv_data->rx_end - drv_data->rx);
494 /* Release chip select if requested, transfer delays are
495 * handled in pump_transfers */
496 if (drv_data->cs_change)
497 drv_data->cs_control(PXA2XX_CS_DEASSERT);
499 /* Move to next transfer */
500 msg->state = next_transfer(drv_data);
502 /* Schedule transfer tasklet */
503 tasklet_schedule(&drv_data->pump_transfers);
506 static void dma_handler(int channel, void *data)
508 struct driver_data *drv_data = data;
509 u32 irq_status = DCSR(channel) & DMA_INT_MASK;
511 if (irq_status & DCSR_BUSERR) {
513 if (channel == drv_data->tx_channel)
514 dma_error_stop(drv_data,
516 "bad bus address on tx channel");
518 dma_error_stop(drv_data,
520 "bad bus address on rx channel");
524 /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */
525 if ((channel == drv_data->tx_channel)
526 && (irq_status & DCSR_ENDINTR)
527 && (drv_data->ssp_type == PXA25x_SSP)) {
529 /* Wait for rx to stall */
530 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
531 dev_err(&drv_data->pdev->dev,
532 "dma_handler: ssp rx stall failed\n");
534 /* finish this transfer, start the next */
535 dma_transfer_complete(drv_data);
539 static irqreturn_t dma_transfer(struct driver_data *drv_data)
542 void __iomem *reg = drv_data->ioaddr;
544 irq_status = read_SSSR(reg) & drv_data->mask_sr;
545 if (irq_status & SSSR_ROR) {
546 dma_error_stop(drv_data, "dma_transfer: fifo overrun");
550 /* Check for false positive timeout */
551 if ((irq_status & SSSR_TINT)
552 && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {
553 write_SSSR(SSSR_TINT, reg);
557 if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) {
559 /* Clear and disable timeout interrupt, do the rest in
560 * dma_transfer_complete */
561 if (drv_data->ssp_type != PXA25x_SSP)
564 /* finish this transfer, start the next */
565 dma_transfer_complete(drv_data);
570 /* Opps problem detected */
574 static void int_error_stop(struct driver_data *drv_data, const char* msg)
576 void __iomem *reg = drv_data->ioaddr;
578 /* Stop and reset SSP */
579 write_SSSR(drv_data->clear_sr, reg);
580 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
581 if (drv_data->ssp_type != PXA25x_SSP)
584 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
586 dev_err(&drv_data->pdev->dev, "%s\n", msg);
588 drv_data->cur_msg->state = ERROR_STATE;
589 tasklet_schedule(&drv_data->pump_transfers);
592 static void int_transfer_complete(struct driver_data *drv_data)
594 void __iomem *reg = drv_data->ioaddr;
597 write_SSSR(drv_data->clear_sr, reg);
598 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
599 if (drv_data->ssp_type != PXA25x_SSP)
602 /* Update total byte transfered return count actual bytes read */
603 drv_data->cur_msg->actual_length += drv_data->len -
604 (drv_data->rx_end - drv_data->rx);
606 /* Release chip select if requested, transfer delays are
607 * handled in pump_transfers */
608 if (drv_data->cs_change)
609 drv_data->cs_control(PXA2XX_CS_DEASSERT);
611 /* Move to next transfer */
612 drv_data->cur_msg->state = next_transfer(drv_data);
614 /* Schedule transfer tasklet */
615 tasklet_schedule(&drv_data->pump_transfers);
618 static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
620 void __iomem *reg = drv_data->ioaddr;
622 u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
623 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
625 u32 irq_status = read_SSSR(reg) & irq_mask;
627 if (irq_status & SSSR_ROR) {
628 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
632 if (irq_status & SSSR_TINT) {
633 write_SSSR(SSSR_TINT, reg);
634 if (drv_data->read(drv_data)) {
635 int_transfer_complete(drv_data);
640 /* Drain rx fifo, Fill tx fifo and prevent overruns */
642 if (drv_data->read(drv_data)) {
643 int_transfer_complete(drv_data);
646 } while (drv_data->write(drv_data));
648 if (drv_data->read(drv_data)) {
649 int_transfer_complete(drv_data);
653 if (drv_data->tx == drv_data->tx_end) {
654 write_SSCR1(read_SSCR1(reg) & ~SSCR1_TIE, reg);
655 /* PXA25x_SSP has no timeout, read trailing bytes */
656 if (drv_data->ssp_type == PXA25x_SSP) {
657 if (!wait_ssp_rx_stall(reg))
659 int_error_stop(drv_data, "interrupt_transfer: "
663 if (!drv_data->read(drv_data))
665 int_error_stop(drv_data,
666 "interrupt_transfer: "
667 "trailing byte read failed");
670 int_transfer_complete(drv_data);
674 /* We did something */
678 static irqreturn_t ssp_int(int irq, void *dev_id)
680 struct driver_data *drv_data = dev_id;
681 void __iomem *reg = drv_data->ioaddr;
683 if (!drv_data->cur_msg) {
685 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
686 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
687 if (drv_data->ssp_type != PXA25x_SSP)
689 write_SSSR(drv_data->clear_sr, reg);
691 dev_err(&drv_data->pdev->dev, "bad message state "
692 "in interrupt handler\n");
698 return drv_data->transfer_handler(drv_data);
701 static int set_dma_burst_and_threshold(struct chip_data *chip,
702 struct spi_device *spi,
703 u8 bits_per_word, u32 *burst_code,
706 struct pxa2xx_spi_chip *chip_info =
707 (struct pxa2xx_spi_chip *)spi->controller_data;
714 /* Set the threshold (in registers) to equal the same amount of data
715 * as represented by burst size (in bytes). The computation below
716 * is (burst_size rounded up to nearest 8 byte, word or long word)
717 * divided by (bytes/register); the tx threshold is the inverse of
718 * the rx, so that there will always be enough data in the rx fifo
719 * to satisfy a burst, and there will always be enough space in the
720 * tx fifo to accept a burst (a tx burst will overwrite the fifo if
721 * there is not enough space), there must always remain enough empty
722 * space in the rx fifo for any data loaded to the tx fifo.
723 * Whenever burst_size (in bytes) equals bits/word, the fifo threshold
724 * will be 8, or half the fifo;
725 * The threshold can only be set to 2, 4 or 8, but not 16, because
726 * to burst 16 to the tx fifo, the fifo would have to be empty;
727 * however, the minimum fifo trigger level is 1, and the tx will
728 * request service when the fifo is at this level, with only 15 spaces.
731 /* find bytes/word */
732 if (bits_per_word <= 8)
734 else if (bits_per_word <= 16)
739 /* use struct pxa2xx_spi_chip->dma_burst_size if available */
741 req_burst_size = chip_info->dma_burst_size;
743 switch (chip->dma_burst_size) {
745 /* if the default burst size is not set,
747 chip->dma_burst_size = DCMD_BURST8;
759 if (req_burst_size <= 8) {
760 *burst_code = DCMD_BURST8;
762 } else if (req_burst_size <= 16) {
763 if (bytes_per_word == 1) {
764 /* don't burst more than 1/2 the fifo */
765 *burst_code = DCMD_BURST8;
769 *burst_code = DCMD_BURST16;
773 if (bytes_per_word == 1) {
774 /* don't burst more than 1/2 the fifo */
775 *burst_code = DCMD_BURST8;
778 } else if (bytes_per_word == 2) {
779 /* don't burst more than 1/2 the fifo */
780 *burst_code = DCMD_BURST16;
784 *burst_code = DCMD_BURST32;
789 thresh_words = burst_bytes / bytes_per_word;
791 /* thresh_words will be between 2 and 8 */
792 *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)
793 | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);
798 static unsigned int ssp_get_clk_div(struct ssp_device *ssp, int rate)
800 unsigned long ssp_clk = clk_get_rate(ssp->clk);
802 if (ssp->type == PXA25x_SSP)
803 return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8;
805 return ((ssp_clk / rate - 1) & 0xfff) << 8;
808 static void pump_transfers(unsigned long data)
810 struct driver_data *drv_data = (struct driver_data *)data;
811 struct spi_message *message = NULL;
812 struct spi_transfer *transfer = NULL;
813 struct spi_transfer *previous = NULL;
814 struct chip_data *chip = NULL;
815 struct ssp_device *ssp = drv_data->ssp;
816 void __iomem *reg = drv_data->ioaddr;
822 u32 dma_thresh = drv_data->cur_chip->dma_threshold;
823 u32 dma_burst = drv_data->cur_chip->dma_burst_size;
825 /* Get current state information */
826 message = drv_data->cur_msg;
827 transfer = drv_data->cur_transfer;
828 chip = drv_data->cur_chip;
830 /* Handle for abort */
831 if (message->state == ERROR_STATE) {
832 message->status = -EIO;
837 /* Handle end of message */
838 if (message->state == DONE_STATE) {
844 /* Delay if requested at end of transfer*/
845 if (message->state == RUNNING_STATE) {
846 previous = list_entry(transfer->transfer_list.prev,
849 if (previous->delay_usecs)
850 udelay(previous->delay_usecs);
853 /* Check transfer length */
854 if (transfer->len > 8191)
856 dev_warn(&drv_data->pdev->dev, "pump_transfers: transfer "
857 "length greater than 8191\n");
858 message->status = -EINVAL;
863 /* Setup the transfer state based on the type of transfer */
864 if (flush(drv_data) == 0) {
865 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
866 message->status = -EIO;
870 drv_data->n_bytes = chip->n_bytes;
871 drv_data->dma_width = chip->dma_width;
872 drv_data->cs_control = chip->cs_control;
873 drv_data->tx = (void *)transfer->tx_buf;
874 drv_data->tx_end = drv_data->tx + transfer->len;
875 drv_data->rx = transfer->rx_buf;
876 drv_data->rx_end = drv_data->rx + transfer->len;
877 drv_data->rx_dma = transfer->rx_dma;
878 drv_data->tx_dma = transfer->tx_dma;
879 drv_data->len = transfer->len & DCMD_LENGTH;
880 drv_data->write = drv_data->tx ? chip->write : null_writer;
881 drv_data->read = drv_data->rx ? chip->read : null_reader;
882 drv_data->cs_change = transfer->cs_change;
884 /* Change speed and bit per word on a per transfer */
886 if (transfer->speed_hz || transfer->bits_per_word) {
888 bits = chip->bits_per_word;
889 speed = chip->speed_hz;
891 if (transfer->speed_hz)
892 speed = transfer->speed_hz;
894 if (transfer->bits_per_word)
895 bits = transfer->bits_per_word;
897 clk_div = ssp_get_clk_div(ssp, speed);
900 drv_data->n_bytes = 1;
901 drv_data->dma_width = DCMD_WIDTH1;
902 drv_data->read = drv_data->read != null_reader ?
903 u8_reader : null_reader;
904 drv_data->write = drv_data->write != null_writer ?
905 u8_writer : null_writer;
906 } else if (bits <= 16) {
907 drv_data->n_bytes = 2;
908 drv_data->dma_width = DCMD_WIDTH2;
909 drv_data->read = drv_data->read != null_reader ?
910 u16_reader : null_reader;
911 drv_data->write = drv_data->write != null_writer ?
912 u16_writer : null_writer;
913 } else if (bits <= 32) {
914 drv_data->n_bytes = 4;
915 drv_data->dma_width = DCMD_WIDTH4;
916 drv_data->read = drv_data->read != null_reader ?
917 u32_reader : null_reader;
918 drv_data->write = drv_data->write != null_writer ?
919 u32_writer : null_writer;
921 /* if bits/word is changed in dma mode, then must check the
922 * thresholds and burst also */
923 if (chip->enable_dma) {
924 if (set_dma_burst_and_threshold(chip, message->spi,
927 if (printk_ratelimit())
928 dev_warn(&message->spi->dev,
930 "DMA burst size reduced to "
931 "match bits_per_word\n");
936 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
938 | (bits > 16 ? SSCR0_EDSS : 0);
941 message->state = RUNNING_STATE;
943 /* Try to map dma buffer and do a dma transfer if successful */
944 if ((drv_data->dma_mapped = map_dma_buffers(drv_data))) {
946 /* Ensure we have the correct interrupt handler */
947 drv_data->transfer_handler = dma_transfer;
949 /* Setup rx DMA Channel */
950 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
951 DSADR(drv_data->rx_channel) = drv_data->ssdr_physical;
952 DTADR(drv_data->rx_channel) = drv_data->rx_dma;
953 if (drv_data->rx == drv_data->null_dma_buf)
954 /* No target address increment */
955 DCMD(drv_data->rx_channel) = DCMD_FLOWSRC
956 | drv_data->dma_width
960 DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR
962 | drv_data->dma_width
966 /* Setup tx DMA Channel */
967 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
968 DSADR(drv_data->tx_channel) = drv_data->tx_dma;
969 DTADR(drv_data->tx_channel) = drv_data->ssdr_physical;
970 if (drv_data->tx == drv_data->null_dma_buf)
971 /* No source address increment */
972 DCMD(drv_data->tx_channel) = DCMD_FLOWTRG
973 | drv_data->dma_width
977 DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR
979 | drv_data->dma_width
983 /* Enable dma end irqs on SSP to detect end of transfer */
984 if (drv_data->ssp_type == PXA25x_SSP)
985 DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN;
987 /* Clear status and start DMA engine */
988 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
989 write_SSSR(drv_data->clear_sr, reg);
990 DCSR(drv_data->rx_channel) |= DCSR_RUN;
991 DCSR(drv_data->tx_channel) |= DCSR_RUN;
993 /* Ensure we have the correct interrupt handler */
994 drv_data->transfer_handler = interrupt_transfer;
997 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
998 write_SSSR(drv_data->clear_sr, reg);
1001 /* see if we need to reload the config registers */
1002 if ((read_SSCR0(reg) != cr0)
1003 || (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
1004 (cr1 & SSCR1_CHANGE_MASK)) {
1006 /* stop the SSP, and update the other bits */
1007 write_SSCR0(cr0 & ~SSCR0_SSE, reg);
1008 if (drv_data->ssp_type != PXA25x_SSP)
1009 write_SSTO(chip->timeout, reg);
1010 /* first set CR1 without interrupt and service enables */
1011 write_SSCR1(cr1 & SSCR1_CHANGE_MASK, reg);
1012 /* restart the SSP */
1013 write_SSCR0(cr0, reg);
1016 if (drv_data->ssp_type != PXA25x_SSP)
1017 write_SSTO(chip->timeout, reg);
1020 /* FIXME, need to handle cs polarity,
1021 * this driver uses struct pxa2xx_spi_chip.cs_control to
1022 * specify a CS handling function, and it ignores most
1023 * struct spi_device.mode[s], including SPI_CS_HIGH */
1024 drv_data->cs_control(PXA2XX_CS_ASSERT);
1026 /* after chip select, release the data by enabling service
1027 * requests and interrupts, without changing any mode bits */
1028 write_SSCR1(cr1, reg);
1031 static void pump_messages(struct work_struct *work)
1033 struct driver_data *drv_data =
1034 container_of(work, struct driver_data, pump_messages);
1035 unsigned long flags;
1037 /* Lock queue and check for queue work */
1038 spin_lock_irqsave(&drv_data->lock, flags);
1039 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
1041 spin_unlock_irqrestore(&drv_data->lock, flags);
1045 /* Make sure we are not already running a message */
1046 if (drv_data->cur_msg) {
1047 spin_unlock_irqrestore(&drv_data->lock, flags);
1051 /* Extract head of queue */
1052 drv_data->cur_msg = list_entry(drv_data->queue.next,
1053 struct spi_message, queue);
1054 list_del_init(&drv_data->cur_msg->queue);
1056 /* Initial message state*/
1057 drv_data->cur_msg->state = START_STATE;
1058 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
1059 struct spi_transfer,
1062 /* prepare to setup the SSP, in pump_transfers, using the per
1063 * chip configuration */
1064 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
1066 /* Mark as busy and launch transfers */
1067 tasklet_schedule(&drv_data->pump_transfers);
1070 spin_unlock_irqrestore(&drv_data->lock, flags);
1073 static int transfer(struct spi_device *spi, struct spi_message *msg)
1075 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1076 unsigned long flags;
1078 spin_lock_irqsave(&drv_data->lock, flags);
1080 if (drv_data->run == QUEUE_STOPPED) {
1081 spin_unlock_irqrestore(&drv_data->lock, flags);
1085 msg->actual_length = 0;
1086 msg->status = -EINPROGRESS;
1087 msg->state = START_STATE;
1089 list_add_tail(&msg->queue, &drv_data->queue);
1091 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
1092 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1094 spin_unlock_irqrestore(&drv_data->lock, flags);
1099 /* the spi->mode bits understood by this driver: */
1100 #define MODEBITS (SPI_CPOL | SPI_CPHA)
1102 static int setup(struct spi_device *spi)
1104 struct pxa2xx_spi_chip *chip_info = NULL;
1105 struct chip_data *chip;
1106 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1107 struct ssp_device *ssp = drv_data->ssp;
1108 unsigned int clk_div;
1110 if (!spi->bits_per_word)
1111 spi->bits_per_word = 8;
1113 if (drv_data->ssp_type != PXA25x_SSP
1114 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
1115 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1116 "b/w not 4-32 for type non-PXA25x_SSP\n",
1117 drv_data->ssp_type, spi->bits_per_word);
1120 else if (drv_data->ssp_type == PXA25x_SSP
1121 && (spi->bits_per_word < 4
1122 || spi->bits_per_word > 16)) {
1123 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1124 "b/w not 4-16 for type PXA25x_SSP\n",
1125 drv_data->ssp_type, spi->bits_per_word);
1129 if (spi->mode & ~MODEBITS) {
1130 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
1131 spi->mode & ~MODEBITS);
1135 /* Only alloc on first setup */
1136 chip = spi_get_ctldata(spi);
1138 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
1141 "failed setup: can't allocate chip data\n");
1145 chip->cs_control = null_cs_control;
1146 chip->enable_dma = 0;
1147 chip->timeout = 1000;
1148 chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1);
1149 chip->dma_burst_size = drv_data->master_info->enable_dma ?
1153 /* protocol drivers may change the chip settings, so...
1154 * if chip_info exists, use it */
1155 chip_info = spi->controller_data;
1157 /* chip_info isn't always needed */
1160 if (chip_info->cs_control)
1161 chip->cs_control = chip_info->cs_control;
1163 chip->timeout = chip_info->timeout;
1165 chip->threshold = (SSCR1_RxTresh(chip_info->rx_threshold) &
1167 (SSCR1_TxTresh(chip_info->tx_threshold) &
1170 chip->enable_dma = chip_info->dma_burst_size != 0
1171 && drv_data->master_info->enable_dma;
1172 chip->dma_threshold = 0;
1174 if (chip_info->enable_loopback)
1175 chip->cr1 = SSCR1_LBM;
1178 /* set dma burst and threshold outside of chip_info path so that if
1179 * chip_info goes away after setting chip->enable_dma, the
1180 * burst and threshold can still respond to changes in bits_per_word */
1181 if (chip->enable_dma) {
1182 /* set up legal burst and threshold for dma */
1183 if (set_dma_burst_and_threshold(chip, spi, spi->bits_per_word,
1184 &chip->dma_burst_size,
1185 &chip->dma_threshold)) {
1186 dev_warn(&spi->dev, "in setup: DMA burst size reduced "
1187 "to match bits_per_word\n");
1191 clk_div = ssp_get_clk_div(ssp, spi->max_speed_hz);
1192 chip->speed_hz = spi->max_speed_hz;
1196 | SSCR0_DataSize(spi->bits_per_word > 16 ?
1197 spi->bits_per_word - 16 : spi->bits_per_word)
1199 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
1200 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1201 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1202 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
1204 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1205 if (drv_data->ssp_type != PXA25x_SSP)
1206 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d\n",
1208 clk_get_rate(ssp->clk)
1209 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1212 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d\n",
1214 clk_get_rate(ssp->clk)
1215 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1218 if (spi->bits_per_word <= 8) {
1220 chip->dma_width = DCMD_WIDTH1;
1221 chip->read = u8_reader;
1222 chip->write = u8_writer;
1223 } else if (spi->bits_per_word <= 16) {
1225 chip->dma_width = DCMD_WIDTH2;
1226 chip->read = u16_reader;
1227 chip->write = u16_writer;
1228 } else if (spi->bits_per_word <= 32) {
1229 chip->cr0 |= SSCR0_EDSS;
1231 chip->dma_width = DCMD_WIDTH4;
1232 chip->read = u32_reader;
1233 chip->write = u32_writer;
1235 dev_err(&spi->dev, "invalid wordsize\n");
1238 chip->bits_per_word = spi->bits_per_word;
1240 spi_set_ctldata(spi, chip);
1245 static void cleanup(struct spi_device *spi)
1247 struct chip_data *chip = spi_get_ctldata(spi);
1252 static int __init init_queue(struct driver_data *drv_data)
1254 INIT_LIST_HEAD(&drv_data->queue);
1255 spin_lock_init(&drv_data->lock);
1257 drv_data->run = QUEUE_STOPPED;
1260 tasklet_init(&drv_data->pump_transfers,
1261 pump_transfers, (unsigned long)drv_data);
1263 INIT_WORK(&drv_data->pump_messages, pump_messages);
1264 drv_data->workqueue = create_singlethread_workqueue(
1265 drv_data->master->dev.parent->bus_id);
1266 if (drv_data->workqueue == NULL)
1272 static int start_queue(struct driver_data *drv_data)
1274 unsigned long flags;
1276 spin_lock_irqsave(&drv_data->lock, flags);
1278 if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
1279 spin_unlock_irqrestore(&drv_data->lock, flags);
1283 drv_data->run = QUEUE_RUNNING;
1284 drv_data->cur_msg = NULL;
1285 drv_data->cur_transfer = NULL;
1286 drv_data->cur_chip = NULL;
1287 spin_unlock_irqrestore(&drv_data->lock, flags);
1289 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1294 static int stop_queue(struct driver_data *drv_data)
1296 unsigned long flags;
1297 unsigned limit = 500;
1300 spin_lock_irqsave(&drv_data->lock, flags);
1302 /* This is a bit lame, but is optimized for the common execution path.
1303 * A wait_queue on the drv_data->busy could be used, but then the common
1304 * execution path (pump_messages) would be required to call wake_up or
1305 * friends on every SPI message. Do this instead */
1306 drv_data->run = QUEUE_STOPPED;
1307 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1308 spin_unlock_irqrestore(&drv_data->lock, flags);
1310 spin_lock_irqsave(&drv_data->lock, flags);
1313 if (!list_empty(&drv_data->queue) || drv_data->busy)
1316 spin_unlock_irqrestore(&drv_data->lock, flags);
1321 static int destroy_queue(struct driver_data *drv_data)
1325 status = stop_queue(drv_data);
1326 /* we are unloading the module or failing to load (only two calls
1327 * to this routine), and neither call can handle a return value.
1328 * However, destroy_workqueue calls flush_workqueue, and that will
1329 * block until all work is done. If the reason that stop_queue
1330 * timed out is that the work will never finish, then it does no
1331 * good to call destroy_workqueue, so return anyway. */
1335 destroy_workqueue(drv_data->workqueue);
1340 static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1342 struct device *dev = &pdev->dev;
1343 struct pxa2xx_spi_master *platform_info;
1344 struct spi_master *master;
1345 struct driver_data *drv_data = NULL;
1346 struct ssp_device *ssp;
1349 platform_info = dev->platform_data;
1351 ssp = ssp_request(pdev->id, pdev->name);
1353 dev_err(&pdev->dev, "failed to request SSP%d\n", pdev->id);
1357 /* Allocate master with space for drv_data and null dma buffer */
1358 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
1360 dev_err(&pdev->dev, "can not alloc spi_master\n");
1364 drv_data = spi_master_get_devdata(master);
1365 drv_data->master = master;
1366 drv_data->master_info = platform_info;
1367 drv_data->pdev = pdev;
1368 drv_data->ssp = ssp;
1370 master->bus_num = pdev->id;
1371 master->num_chipselect = platform_info->num_chipselect;
1372 master->cleanup = cleanup;
1373 master->setup = setup;
1374 master->transfer = transfer;
1376 drv_data->ssp_type = ssp->type;
1377 drv_data->null_dma_buf = (u32 *)ALIGN((u32)(drv_data +
1378 sizeof(struct driver_data)), 8);
1380 drv_data->ioaddr = ssp->mmio_base;
1381 drv_data->ssdr_physical = ssp->phys_base + SSDR;
1382 if (ssp->type == PXA25x_SSP) {
1383 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
1384 drv_data->dma_cr1 = 0;
1385 drv_data->clear_sr = SSSR_ROR;
1386 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
1388 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
1389 drv_data->dma_cr1 = SSCR1_TSRE | SSCR1_RSRE | SSCR1_TINTE;
1390 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1391 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1394 status = request_irq(ssp->irq, ssp_int, 0, dev->bus_id, drv_data);
1396 dev_err(&pdev->dev, "can not get IRQ\n");
1397 goto out_error_master_alloc;
1400 /* Setup DMA if requested */
1401 drv_data->tx_channel = -1;
1402 drv_data->rx_channel = -1;
1403 if (platform_info->enable_dma) {
1405 /* Get two DMA channels (rx and tx) */
1406 drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx",
1410 if (drv_data->rx_channel < 0) {
1411 dev_err(dev, "problem (%d) requesting rx channel\n",
1412 drv_data->rx_channel);
1414 goto out_error_irq_alloc;
1416 drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx",
1420 if (drv_data->tx_channel < 0) {
1421 dev_err(dev, "problem (%d) requesting tx channel\n",
1422 drv_data->tx_channel);
1424 goto out_error_dma_alloc;
1427 DRCMR(ssp->drcmr_rx) = DRCMR_MAPVLD | drv_data->rx_channel;
1428 DRCMR(ssp->drcmr_tx) = DRCMR_MAPVLD | drv_data->tx_channel;
1431 /* Enable SOC clock */
1432 clk_enable(ssp->clk);
1434 /* Load default SSP configuration */
1435 write_SSCR0(0, drv_data->ioaddr);
1436 write_SSCR1(SSCR1_RxTresh(4) | SSCR1_TxTresh(12), drv_data->ioaddr);
1437 write_SSCR0(SSCR0_SerClkDiv(2)
1439 | SSCR0_DataSize(8),
1441 if (drv_data->ssp_type != PXA25x_SSP)
1442 write_SSTO(0, drv_data->ioaddr);
1443 write_SSPSP(0, drv_data->ioaddr);
1445 /* Initial and start queue */
1446 status = init_queue(drv_data);
1448 dev_err(&pdev->dev, "problem initializing queue\n");
1449 goto out_error_clock_enabled;
1451 status = start_queue(drv_data);
1453 dev_err(&pdev->dev, "problem starting queue\n");
1454 goto out_error_clock_enabled;
1457 /* Register with the SPI framework */
1458 platform_set_drvdata(pdev, drv_data);
1459 status = spi_register_master(master);
1461 dev_err(&pdev->dev, "problem registering spi master\n");
1462 goto out_error_queue_alloc;
1467 out_error_queue_alloc:
1468 destroy_queue(drv_data);
1470 out_error_clock_enabled:
1471 clk_disable(ssp->clk);
1473 out_error_dma_alloc:
1474 if (drv_data->tx_channel != -1)
1475 pxa_free_dma(drv_data->tx_channel);
1476 if (drv_data->rx_channel != -1)
1477 pxa_free_dma(drv_data->rx_channel);
1479 out_error_irq_alloc:
1480 free_irq(ssp->irq, drv_data);
1482 out_error_master_alloc:
1483 spi_master_put(master);
1488 static int pxa2xx_spi_remove(struct platform_device *pdev)
1490 struct driver_data *drv_data = platform_get_drvdata(pdev);
1491 struct ssp_device *ssp = drv_data->ssp;
1497 /* Remove the queue */
1498 status = destroy_queue(drv_data);
1500 /* the kernel does not check the return status of this
1501 * this routine (mod->exit, within the kernel). Therefore
1502 * nothing is gained by returning from here, the module is
1503 * going away regardless, and we should not leave any more
1504 * resources allocated than necessary. We cannot free the
1505 * message memory in drv_data->queue, but we can release the
1506 * resources below. I think the kernel should honor -EBUSY
1508 dev_err(&pdev->dev, "pxa2xx_spi_remove: workqueue will not "
1509 "complete, message memory not freed\n");
1511 /* Disable the SSP at the peripheral and SOC level */
1512 write_SSCR0(0, drv_data->ioaddr);
1513 clk_disable(ssp->clk);
1516 if (drv_data->master_info->enable_dma) {
1517 DRCMR(ssp->drcmr_rx) = 0;
1518 DRCMR(ssp->drcmr_tx) = 0;
1519 pxa_free_dma(drv_data->tx_channel);
1520 pxa_free_dma(drv_data->rx_channel);
1524 free_irq(ssp->irq, drv_data);
1529 /* Disconnect from the SPI framework */
1530 spi_unregister_master(drv_data->master);
1532 /* Prevent double remove */
1533 platform_set_drvdata(pdev, NULL);
1538 static void pxa2xx_spi_shutdown(struct platform_device *pdev)
1542 if ((status = pxa2xx_spi_remove(pdev)) != 0)
1543 dev_err(&pdev->dev, "shutdown failed with %d\n", status);
1548 static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
1550 struct driver_data *drv_data = platform_get_drvdata(pdev);
1551 struct ssp_device *ssp = drv_data->ssp;
1554 status = stop_queue(drv_data);
1557 write_SSCR0(0, drv_data->ioaddr);
1558 clk_disable(ssp->clk);
1563 static int pxa2xx_spi_resume(struct platform_device *pdev)
1565 struct driver_data *drv_data = platform_get_drvdata(pdev);
1566 struct ssp_device *ssp = drv_data->ssp;
1569 /* Enable the SSP clock */
1570 clk_enable(ssp->clk);
1572 /* Start the queue running */
1573 status = start_queue(drv_data);
1575 dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
1582 #define pxa2xx_spi_suspend NULL
1583 #define pxa2xx_spi_resume NULL
1584 #endif /* CONFIG_PM */
1586 static struct platform_driver driver = {
1588 .name = "pxa2xx-spi",
1589 .owner = THIS_MODULE,
1591 .remove = pxa2xx_spi_remove,
1592 .shutdown = pxa2xx_spi_shutdown,
1593 .suspend = pxa2xx_spi_suspend,
1594 .resume = pxa2xx_spi_resume,
1597 static int __init pxa2xx_spi_init(void)
1599 return platform_driver_probe(&driver, pxa2xx_spi_probe);
1601 module_init(pxa2xx_spi_init);
1603 static void __exit pxa2xx_spi_exit(void)
1605 platform_driver_unregister(&driver);
1607 module_exit(pxa2xx_spi_exit);