cmd64x: don't clear the other channel's interrupt
[linux-2.6/linux-mips/linux-dm7025.git] / drivers / spi / atmel_spi.c
blob0d342dcdd302e176e9178971c0961789fb55b596
1 /*
2 * Driver for Atmel AT32 and AT91 SPI Controllers
4 * Copyright (C) 2006 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/clk.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/err.h>
19 #include <linux/interrupt.h>
20 #include <linux/spi/spi.h>
22 #include <asm/io.h>
23 #include <asm/arch/board.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/arch/cpu.h>
27 #include "atmel_spi.h"
30 * The core SPI transfer engine just talks to a register bank to set up
31 * DMA transfers; transfer queue progress is driven by IRQs. The clock
32 * framework provides the base clock, subdivided for each spi_device.
34 * Newer controllers, marked with "new_1" flag, have:
35 * - CR.LASTXFER
36 * - SPI_MR.DIV32 may become FDIV or must-be-zero (here: always zero)
37 * - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
38 * - SPI_CSRx.CSAAT
39 * - SPI_CSRx.SBCR allows faster clocking
41 struct atmel_spi {
42 spinlock_t lock;
44 void __iomem *regs;
45 int irq;
46 struct clk *clk;
47 struct platform_device *pdev;
48 unsigned new_1:1;
49 struct spi_device *stay;
51 u8 stopping;
52 struct list_head queue;
53 struct spi_transfer *current_transfer;
54 unsigned long remaining_bytes;
56 void *buffer;
57 dma_addr_t buffer_dma;
60 #define BUFFER_SIZE PAGE_SIZE
61 #define INVALID_DMA_ADDRESS 0xffffffff
64 * Earlier SPI controllers (e.g. on at91rm9200) have a design bug whereby
65 * they assume that spi slave device state will not change on deselect, so
66 * that automagic deselection is OK. ("NPCSx rises if no data is to be
67 * transmitted") Not so! Workaround uses nCSx pins as GPIOs; or newer
68 * controllers have CSAAT and friends.
70 * Since the CSAAT functionality is a bit weird on newer controllers as
71 * well, we use GPIO to control nCSx pins on all controllers, updating
72 * MR.PCS to avoid confusing the controller. Using GPIOs also lets us
73 * support active-high chipselects despite the controller's belief that
74 * only active-low devices/systems exists.
76 * However, at91rm9200 has a second erratum whereby nCS0 doesn't work
77 * right when driven with GPIO. ("Mode Fault does not allow more than one
78 * Master on Chip Select 0.") No workaround exists for that ... so for
79 * nCS0 on that chip, we (a) don't use the GPIO, (b) can't support CS_HIGH,
80 * and (c) will trigger that first erratum in some cases.
83 static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
85 unsigned gpio = (unsigned) spi->controller_data;
86 unsigned active = spi->mode & SPI_CS_HIGH;
87 u32 mr;
89 mr = spi_readl(as, MR);
90 mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);
92 dev_dbg(&spi->dev, "activate %u%s, mr %08x\n",
93 gpio, active ? " (high)" : "",
94 mr);
96 if (!(cpu_is_at91rm9200() && spi->chip_select == 0))
97 gpio_set_value(gpio, active);
98 spi_writel(as, MR, mr);
101 static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
103 unsigned gpio = (unsigned) spi->controller_data;
104 unsigned active = spi->mode & SPI_CS_HIGH;
105 u32 mr;
107 /* only deactivate *this* device; sometimes transfers to
108 * another device may be active when this routine is called.
110 mr = spi_readl(as, MR);
111 if (~SPI_BFEXT(PCS, mr) & (1 << spi->chip_select)) {
112 mr = SPI_BFINS(PCS, 0xf, mr);
113 spi_writel(as, MR, mr);
116 dev_dbg(&spi->dev, "DEactivate %u%s, mr %08x\n",
117 gpio, active ? " (low)" : "",
118 mr);
120 if (!(cpu_is_at91rm9200() && spi->chip_select == 0))
121 gpio_set_value(gpio, !active);
125 * Submit next transfer for DMA.
126 * lock is held, spi irq is blocked
128 static void atmel_spi_next_xfer(struct spi_master *master,
129 struct spi_message *msg)
131 struct atmel_spi *as = spi_master_get_devdata(master);
132 struct spi_transfer *xfer;
133 u32 len;
134 dma_addr_t tx_dma, rx_dma;
136 xfer = as->current_transfer;
137 if (!xfer || as->remaining_bytes == 0) {
138 if (xfer)
139 xfer = list_entry(xfer->transfer_list.next,
140 struct spi_transfer, transfer_list);
141 else
142 xfer = list_entry(msg->transfers.next,
143 struct spi_transfer, transfer_list);
144 as->remaining_bytes = xfer->len;
145 as->current_transfer = xfer;
148 len = as->remaining_bytes;
150 tx_dma = xfer->tx_dma + xfer->len - len;
151 rx_dma = xfer->rx_dma + xfer->len - len;
153 /* use scratch buffer only when rx or tx data is unspecified */
154 if (!xfer->rx_buf) {
155 rx_dma = as->buffer_dma;
156 if (len > BUFFER_SIZE)
157 len = BUFFER_SIZE;
159 if (!xfer->tx_buf) {
160 tx_dma = as->buffer_dma;
161 if (len > BUFFER_SIZE)
162 len = BUFFER_SIZE;
163 memset(as->buffer, 0, len);
164 dma_sync_single_for_device(&as->pdev->dev,
165 as->buffer_dma, len, DMA_TO_DEVICE);
168 spi_writel(as, RPR, rx_dma);
169 spi_writel(as, TPR, tx_dma);
171 as->remaining_bytes -= len;
172 if (msg->spi->bits_per_word > 8)
173 len >>= 1;
175 /* REVISIT: when xfer->delay_usecs == 0, the PDC "next transfer"
176 * mechanism might help avoid the IRQ latency between transfers
177 * (and improve the nCS0 errata handling on at91rm9200 chips)
179 * We're also waiting for ENDRX before we start the next
180 * transfer because we need to handle some difficult timing
181 * issues otherwise. If we wait for ENDTX in one transfer and
182 * then starts waiting for ENDRX in the next, it's difficult
183 * to tell the difference between the ENDRX interrupt we're
184 * actually waiting for and the ENDRX interrupt of the
185 * previous transfer.
187 * It should be doable, though. Just not now...
189 spi_writel(as, TNCR, 0);
190 spi_writel(as, RNCR, 0);
191 spi_writel(as, IER, SPI_BIT(ENDRX) | SPI_BIT(OVRES));
193 dev_dbg(&msg->spi->dev,
194 " start xfer %p: len %u tx %p/%08x rx %p/%08x imr %03x\n",
195 xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
196 xfer->rx_buf, xfer->rx_dma, spi_readl(as, IMR));
198 spi_writel(as, TCR, len);
199 spi_writel(as, RCR, len);
200 spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
203 static void atmel_spi_next_message(struct spi_master *master)
205 struct atmel_spi *as = spi_master_get_devdata(master);
206 struct spi_message *msg;
207 struct spi_device *spi;
209 BUG_ON(as->current_transfer);
211 msg = list_entry(as->queue.next, struct spi_message, queue);
212 spi = msg->spi;
214 dev_dbg(master->dev.parent, "start message %p for %s\n",
215 msg, spi->dev.bus_id);
217 /* select chip if it's not still active */
218 if (as->stay) {
219 if (as->stay != spi) {
220 cs_deactivate(as, as->stay);
221 cs_activate(as, spi);
223 as->stay = NULL;
224 } else
225 cs_activate(as, spi);
227 atmel_spi_next_xfer(master, msg);
231 * For DMA, tx_buf/tx_dma have the same relationship as rx_buf/rx_dma:
232 * - The buffer is either valid for CPU access, else NULL
233 * - If the buffer is valid, so is its DMA addresss
235 * This driver manages the dma addresss unless message->is_dma_mapped.
237 static int
238 atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
240 struct device *dev = &as->pdev->dev;
242 xfer->tx_dma = xfer->rx_dma = INVALID_DMA_ADDRESS;
243 if (xfer->tx_buf) {
244 xfer->tx_dma = dma_map_single(dev,
245 (void *) xfer->tx_buf, xfer->len,
246 DMA_TO_DEVICE);
247 if (dma_mapping_error(xfer->tx_dma))
248 return -ENOMEM;
250 if (xfer->rx_buf) {
251 xfer->rx_dma = dma_map_single(dev,
252 xfer->rx_buf, xfer->len,
253 DMA_FROM_DEVICE);
254 if (dma_mapping_error(xfer->rx_dma)) {
255 if (xfer->tx_buf)
256 dma_unmap_single(dev,
257 xfer->tx_dma, xfer->len,
258 DMA_TO_DEVICE);
259 return -ENOMEM;
262 return 0;
265 static void atmel_spi_dma_unmap_xfer(struct spi_master *master,
266 struct spi_transfer *xfer)
268 if (xfer->tx_dma != INVALID_DMA_ADDRESS)
269 dma_unmap_single(master->dev.parent, xfer->tx_dma,
270 xfer->len, DMA_TO_DEVICE);
271 if (xfer->rx_dma != INVALID_DMA_ADDRESS)
272 dma_unmap_single(master->dev.parent, xfer->rx_dma,
273 xfer->len, DMA_FROM_DEVICE);
276 static void
277 atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
278 struct spi_message *msg, int status, int stay)
280 if (!stay || status < 0)
281 cs_deactivate(as, msg->spi);
282 else
283 as->stay = msg->spi;
285 list_del(&msg->queue);
286 msg->status = status;
288 dev_dbg(master->dev.parent,
289 "xfer complete: %u bytes transferred\n",
290 msg->actual_length);
292 spin_unlock(&as->lock);
293 msg->complete(msg->context);
294 spin_lock(&as->lock);
296 as->current_transfer = NULL;
298 /* continue if needed */
299 if (list_empty(&as->queue) || as->stopping)
300 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
301 else
302 atmel_spi_next_message(master);
305 static irqreturn_t
306 atmel_spi_interrupt(int irq, void *dev_id)
308 struct spi_master *master = dev_id;
309 struct atmel_spi *as = spi_master_get_devdata(master);
310 struct spi_message *msg;
311 struct spi_transfer *xfer;
312 u32 status, pending, imr;
313 int ret = IRQ_NONE;
315 spin_lock(&as->lock);
317 xfer = as->current_transfer;
318 msg = list_entry(as->queue.next, struct spi_message, queue);
320 imr = spi_readl(as, IMR);
321 status = spi_readl(as, SR);
322 pending = status & imr;
324 if (pending & SPI_BIT(OVRES)) {
325 int timeout;
327 ret = IRQ_HANDLED;
329 spi_writel(as, IDR, (SPI_BIT(ENDTX) | SPI_BIT(ENDRX)
330 | SPI_BIT(OVRES)));
333 * When we get an overrun, we disregard the current
334 * transfer. Data will not be copied back from any
335 * bounce buffer and msg->actual_len will not be
336 * updated with the last xfer.
338 * We will also not process any remaning transfers in
339 * the message.
341 * First, stop the transfer and unmap the DMA buffers.
343 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
344 if (!msg->is_dma_mapped)
345 atmel_spi_dma_unmap_xfer(master, xfer);
347 /* REVISIT: udelay in irq is unfriendly */
348 if (xfer->delay_usecs)
349 udelay(xfer->delay_usecs);
351 dev_warn(master->dev.parent, "fifo overrun (%u/%u remaining)\n",
352 spi_readl(as, TCR), spi_readl(as, RCR));
355 * Clean up DMA registers and make sure the data
356 * registers are empty.
358 spi_writel(as, RNCR, 0);
359 spi_writel(as, TNCR, 0);
360 spi_writel(as, RCR, 0);
361 spi_writel(as, TCR, 0);
362 for (timeout = 1000; timeout; timeout--)
363 if (spi_readl(as, SR) & SPI_BIT(TXEMPTY))
364 break;
365 if (!timeout)
366 dev_warn(master->dev.parent,
367 "timeout waiting for TXEMPTY");
368 while (spi_readl(as, SR) & SPI_BIT(RDRF))
369 spi_readl(as, RDR);
371 /* Clear any overrun happening while cleaning up */
372 spi_readl(as, SR);
374 atmel_spi_msg_done(master, as, msg, -EIO, 0);
375 } else if (pending & SPI_BIT(ENDRX)) {
376 ret = IRQ_HANDLED;
378 spi_writel(as, IDR, pending);
380 if (as->remaining_bytes == 0) {
381 msg->actual_length += xfer->len;
383 if (!msg->is_dma_mapped)
384 atmel_spi_dma_unmap_xfer(master, xfer);
386 /* REVISIT: udelay in irq is unfriendly */
387 if (xfer->delay_usecs)
388 udelay(xfer->delay_usecs);
390 if (msg->transfers.prev == &xfer->transfer_list) {
391 /* report completed message */
392 atmel_spi_msg_done(master, as, msg, 0,
393 xfer->cs_change);
394 } else {
395 if (xfer->cs_change) {
396 cs_deactivate(as, msg->spi);
397 udelay(1);
398 cs_activate(as, msg->spi);
402 * Not done yet. Submit the next transfer.
404 * FIXME handle protocol options for xfer
406 atmel_spi_next_xfer(master, msg);
408 } else {
410 * Keep going, we still have data to send in
411 * the current transfer.
413 atmel_spi_next_xfer(master, msg);
417 spin_unlock(&as->lock);
419 return ret;
422 /* the spi->mode bits understood by this driver: */
423 #define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
425 static int atmel_spi_setup(struct spi_device *spi)
427 struct atmel_spi *as;
428 u32 scbr, csr;
429 unsigned int bits = spi->bits_per_word;
430 unsigned long bus_hz, sck_hz;
431 unsigned int npcs_pin;
432 int ret;
434 as = spi_master_get_devdata(spi->master);
436 if (as->stopping)
437 return -ESHUTDOWN;
439 if (spi->chip_select > spi->master->num_chipselect) {
440 dev_dbg(&spi->dev,
441 "setup: invalid chipselect %u (%u defined)\n",
442 spi->chip_select, spi->master->num_chipselect);
443 return -EINVAL;
446 if (bits == 0)
447 bits = 8;
448 if (bits < 8 || bits > 16) {
449 dev_dbg(&spi->dev,
450 "setup: invalid bits_per_word %u (8 to 16)\n",
451 bits);
452 return -EINVAL;
455 if (spi->mode & ~MODEBITS) {
456 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
457 spi->mode & ~MODEBITS);
458 return -EINVAL;
461 /* see notes above re chipselect */
462 if (cpu_is_at91rm9200()
463 && spi->chip_select == 0
464 && (spi->mode & SPI_CS_HIGH)) {
465 dev_dbg(&spi->dev, "setup: can't be active-high\n");
466 return -EINVAL;
469 /* speed zero convention is used by some upper layers */
470 bus_hz = clk_get_rate(as->clk);
471 if (spi->max_speed_hz) {
472 /* assume div32/fdiv/mbz == 0 */
473 if (!as->new_1)
474 bus_hz /= 2;
475 scbr = ((bus_hz + spi->max_speed_hz - 1)
476 / spi->max_speed_hz);
477 if (scbr >= (1 << SPI_SCBR_SIZE)) {
478 dev_dbg(&spi->dev,
479 "setup: %d Hz too slow, scbr %u; min %ld Hz\n",
480 spi->max_speed_hz, scbr, bus_hz/255);
481 return -EINVAL;
483 } else
484 scbr = 0xff;
485 sck_hz = bus_hz / scbr;
487 csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8);
488 if (spi->mode & SPI_CPOL)
489 csr |= SPI_BIT(CPOL);
490 if (!(spi->mode & SPI_CPHA))
491 csr |= SPI_BIT(NCPHA);
493 /* TODO: DLYBS and DLYBCT */
494 csr |= SPI_BF(DLYBS, 10);
495 csr |= SPI_BF(DLYBCT, 10);
497 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
498 npcs_pin = (unsigned int)spi->controller_data;
499 if (!spi->controller_state) {
500 ret = gpio_request(npcs_pin, "spi_npcs");
501 if (ret)
502 return ret;
503 spi->controller_state = (void *)npcs_pin;
504 gpio_direction_output(npcs_pin, !(spi->mode & SPI_CS_HIGH));
505 } else {
506 unsigned long flags;
508 spin_lock_irqsave(&as->lock, flags);
509 if (as->stay == spi)
510 as->stay = NULL;
511 cs_deactivate(as, spi);
512 spin_unlock_irqrestore(&as->lock, flags);
515 dev_dbg(&spi->dev,
516 "setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
517 sck_hz, bits, spi->mode, spi->chip_select, csr);
519 spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
521 return 0;
524 static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
526 struct atmel_spi *as;
527 struct spi_transfer *xfer;
528 unsigned long flags;
529 struct device *controller = spi->master->dev.parent;
531 as = spi_master_get_devdata(spi->master);
533 dev_dbg(controller, "new message %p submitted for %s\n",
534 msg, spi->dev.bus_id);
536 if (unlikely(list_empty(&msg->transfers)
537 || !spi->max_speed_hz))
538 return -EINVAL;
540 if (as->stopping)
541 return -ESHUTDOWN;
543 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
544 if (!(xfer->tx_buf || xfer->rx_buf)) {
545 dev_dbg(&spi->dev, "missing rx or tx buf\n");
546 return -EINVAL;
549 /* FIXME implement these protocol options!! */
550 if (xfer->bits_per_word || xfer->speed_hz) {
551 dev_dbg(&spi->dev, "no protocol options yet\n");
552 return -ENOPROTOOPT;
556 * DMA map early, for performance (empties dcache ASAP) and
557 * better fault reporting. This is a DMA-only driver.
559 * NOTE that if dma_unmap_single() ever starts to do work on
560 * platforms supported by this driver, we would need to clean
561 * up mappings for previously-mapped transfers.
563 if (!msg->is_dma_mapped) {
564 if (atmel_spi_dma_map_xfer(as, xfer) < 0)
565 return -ENOMEM;
569 #ifdef VERBOSE
570 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
571 dev_dbg(controller,
572 " xfer %p: len %u tx %p/%08x rx %p/%08x\n",
573 xfer, xfer->len,
574 xfer->tx_buf, xfer->tx_dma,
575 xfer->rx_buf, xfer->rx_dma);
577 #endif
579 msg->status = -EINPROGRESS;
580 msg->actual_length = 0;
582 spin_lock_irqsave(&as->lock, flags);
583 list_add_tail(&msg->queue, &as->queue);
584 if (!as->current_transfer)
585 atmel_spi_next_message(spi->master);
586 spin_unlock_irqrestore(&as->lock, flags);
588 return 0;
591 static void atmel_spi_cleanup(struct spi_device *spi)
593 struct atmel_spi *as = spi_master_get_devdata(spi->master);
594 unsigned gpio = (unsigned) spi->controller_data;
595 unsigned long flags;
597 if (!spi->controller_state)
598 return;
600 spin_lock_irqsave(&as->lock, flags);
601 if (as->stay == spi) {
602 as->stay = NULL;
603 cs_deactivate(as, spi);
605 spin_unlock_irqrestore(&as->lock, flags);
607 gpio_free(gpio);
610 /*-------------------------------------------------------------------------*/
612 static int __init atmel_spi_probe(struct platform_device *pdev)
614 struct resource *regs;
615 int irq;
616 struct clk *clk;
617 int ret;
618 struct spi_master *master;
619 struct atmel_spi *as;
621 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
622 if (!regs)
623 return -ENXIO;
625 irq = platform_get_irq(pdev, 0);
626 if (irq < 0)
627 return irq;
629 clk = clk_get(&pdev->dev, "spi_clk");
630 if (IS_ERR(clk))
631 return PTR_ERR(clk);
633 /* setup spi core then atmel-specific driver state */
634 ret = -ENOMEM;
635 master = spi_alloc_master(&pdev->dev, sizeof *as);
636 if (!master)
637 goto out_free;
639 master->bus_num = pdev->id;
640 master->num_chipselect = 4;
641 master->setup = atmel_spi_setup;
642 master->transfer = atmel_spi_transfer;
643 master->cleanup = atmel_spi_cleanup;
644 platform_set_drvdata(pdev, master);
646 as = spi_master_get_devdata(master);
649 * Scratch buffer is used for throwaway rx and tx data.
650 * It's coherent to minimize dcache pollution.
652 as->buffer = dma_alloc_coherent(&pdev->dev, BUFFER_SIZE,
653 &as->buffer_dma, GFP_KERNEL);
654 if (!as->buffer)
655 goto out_free;
657 spin_lock_init(&as->lock);
658 INIT_LIST_HEAD(&as->queue);
659 as->pdev = pdev;
660 as->regs = ioremap(regs->start, (regs->end - regs->start) + 1);
661 if (!as->regs)
662 goto out_free_buffer;
663 as->irq = irq;
664 as->clk = clk;
665 if (!cpu_is_at91rm9200())
666 as->new_1 = 1;
668 ret = request_irq(irq, atmel_spi_interrupt, 0,
669 pdev->dev.bus_id, master);
670 if (ret)
671 goto out_unmap_regs;
673 /* Initialize the hardware */
674 clk_enable(clk);
675 spi_writel(as, CR, SPI_BIT(SWRST));
676 spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
677 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
678 spi_writel(as, CR, SPI_BIT(SPIEN));
680 /* go! */
681 dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
682 (unsigned long)regs->start, irq);
684 ret = spi_register_master(master);
685 if (ret)
686 goto out_reset_hw;
688 return 0;
690 out_reset_hw:
691 spi_writel(as, CR, SPI_BIT(SWRST));
692 clk_disable(clk);
693 free_irq(irq, master);
694 out_unmap_regs:
695 iounmap(as->regs);
696 out_free_buffer:
697 dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
698 as->buffer_dma);
699 out_free:
700 clk_put(clk);
701 spi_master_put(master);
702 return ret;
705 static int __exit atmel_spi_remove(struct platform_device *pdev)
707 struct spi_master *master = platform_get_drvdata(pdev);
708 struct atmel_spi *as = spi_master_get_devdata(master);
709 struct spi_message *msg;
711 /* reset the hardware and block queue progress */
712 spin_lock_irq(&as->lock);
713 as->stopping = 1;
714 spi_writel(as, CR, SPI_BIT(SWRST));
715 spi_readl(as, SR);
716 spin_unlock_irq(&as->lock);
718 /* Terminate remaining queued transfers */
719 list_for_each_entry(msg, &as->queue, queue) {
720 /* REVISIT unmapping the dma is a NOP on ARM and AVR32
721 * but we shouldn't depend on that...
723 msg->status = -ESHUTDOWN;
724 msg->complete(msg->context);
727 dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
728 as->buffer_dma);
730 clk_disable(as->clk);
731 clk_put(as->clk);
732 free_irq(as->irq, master);
733 iounmap(as->regs);
735 spi_unregister_master(master);
737 return 0;
740 #ifdef CONFIG_PM
742 static int atmel_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
744 struct spi_master *master = platform_get_drvdata(pdev);
745 struct atmel_spi *as = spi_master_get_devdata(master);
747 clk_disable(as->clk);
748 return 0;
751 static int atmel_spi_resume(struct platform_device *pdev)
753 struct spi_master *master = platform_get_drvdata(pdev);
754 struct atmel_spi *as = spi_master_get_devdata(master);
756 clk_enable(as->clk);
757 return 0;
760 #else
761 #define atmel_spi_suspend NULL
762 #define atmel_spi_resume NULL
763 #endif
766 static struct platform_driver atmel_spi_driver = {
767 .driver = {
768 .name = "atmel_spi",
769 .owner = THIS_MODULE,
771 .suspend = atmel_spi_suspend,
772 .resume = atmel_spi_resume,
773 .remove = __exit_p(atmel_spi_remove),
776 static int __init atmel_spi_init(void)
778 return platform_driver_probe(&atmel_spi_driver, atmel_spi_probe);
780 module_init(atmel_spi_init);
782 static void __exit atmel_spi_exit(void)
784 platform_driver_unregister(&atmel_spi_driver);
786 module_exit(atmel_spi_exit);
788 MODULE_DESCRIPTION("Atmel AT32/AT91 SPI Controller driver");
789 MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
790 MODULE_LICENSE("GPL");