atmel_spi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Driver for Atmel AT32 and AT91 SPI Controllers
  3. *
  4. * Copyright (C) 2006 Atmel Corporation
  5. *
  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. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/clk.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/delay.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/err.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/spi/spi.h>
  20. #include <asm/io.h>
  21. #include <asm/arch/board.h>
  22. #include <asm/arch/gpio.h>
  23. #include "atmel_spi.h"
  24. /*
  25. * The core SPI transfer engine just talks to a register bank to set up
  26. * DMA transfers; transfer queue progress is driven by IRQs. The clock
  27. * framework provides the base clock, subdivided for each spi_device.
  28. *
  29. * Newer controllers, marked with "new_1" flag, have:
  30. * - CR.LASTXFER
  31. * - SPI_MR.DIV32 may become FDIV or must-be-zero (here: always zero)
  32. * - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
  33. * - SPI_CSRx.CSAAT
  34. * - SPI_CSRx.SBCR allows faster clocking
  35. */
  36. struct atmel_spi {
  37. spinlock_t lock;
  38. void __iomem *regs;
  39. int irq;
  40. struct clk *clk;
  41. struct platform_device *pdev;
  42. unsigned new_1:1;
  43. u8 stopping;
  44. struct list_head queue;
  45. struct spi_transfer *current_transfer;
  46. unsigned long remaining_bytes;
  47. void *buffer;
  48. dma_addr_t buffer_dma;
  49. };
  50. #define BUFFER_SIZE PAGE_SIZE
  51. #define INVALID_DMA_ADDRESS 0xffffffff
  52. /*
  53. * Earlier SPI controllers (e.g. on at91rm9200) have a design bug whereby
  54. * they assume that spi slave device state will not change on deselect, so
  55. * that automagic deselection is OK. Not so! Workaround uses nCSx pins
  56. * as GPIOs; or newer controllers have CSAAT and friends.
  57. *
  58. * Since the CSAAT functionality is a bit weird on newer controllers
  59. * as well, we use GPIO to control nCSx pins on all controllers.
  60. */
  61. static inline void cs_activate(struct spi_device *spi)
  62. {
  63. unsigned gpio = (unsigned) spi->controller_data;
  64. unsigned active = spi->mode & SPI_CS_HIGH;
  65. dev_dbg(&spi->dev, "activate %u%s\n", gpio, active ? " (high)" : "");
  66. gpio_set_value(gpio, active);
  67. }
  68. static inline void cs_deactivate(struct spi_device *spi)
  69. {
  70. unsigned gpio = (unsigned) spi->controller_data;
  71. unsigned active = spi->mode & SPI_CS_HIGH;
  72. dev_dbg(&spi->dev, "DEactivate %u%s\n", gpio, active ? " (low)" : "");
  73. gpio_set_value(gpio, !active);
  74. }
  75. /*
  76. * Submit next transfer for DMA.
  77. * lock is held, spi irq is blocked
  78. */
  79. static void atmel_spi_next_xfer(struct spi_master *master,
  80. struct spi_message *msg)
  81. {
  82. struct atmel_spi *as = spi_master_get_devdata(master);
  83. struct spi_transfer *xfer;
  84. u32 len;
  85. dma_addr_t tx_dma, rx_dma;
  86. xfer = as->current_transfer;
  87. if (!xfer || as->remaining_bytes == 0) {
  88. if (xfer)
  89. xfer = list_entry(xfer->transfer_list.next,
  90. struct spi_transfer, transfer_list);
  91. else
  92. xfer = list_entry(msg->transfers.next,
  93. struct spi_transfer, transfer_list);
  94. as->remaining_bytes = xfer->len;
  95. as->current_transfer = xfer;
  96. }
  97. len = as->remaining_bytes;
  98. tx_dma = xfer->tx_dma;
  99. rx_dma = xfer->rx_dma;
  100. /* use scratch buffer only when rx or tx data is unspecified */
  101. if (rx_dma == INVALID_DMA_ADDRESS) {
  102. rx_dma = as->buffer_dma;
  103. if (len > BUFFER_SIZE)
  104. len = BUFFER_SIZE;
  105. }
  106. if (tx_dma == INVALID_DMA_ADDRESS) {
  107. tx_dma = as->buffer_dma;
  108. if (len > BUFFER_SIZE)
  109. len = BUFFER_SIZE;
  110. memset(as->buffer, 0, len);
  111. dma_sync_single_for_device(&as->pdev->dev,
  112. as->buffer_dma, len, DMA_TO_DEVICE);
  113. }
  114. spi_writel(as, RPR, rx_dma);
  115. spi_writel(as, TPR, tx_dma);
  116. as->remaining_bytes -= len;
  117. if (msg->spi->bits_per_word > 8)
  118. len >>= 1;
  119. /* REVISIT: when xfer->delay_usecs == 0, the PDC "next transfer"
  120. * mechanism might help avoid the IRQ latency between transfers
  121. *
  122. * We're also waiting for ENDRX before we start the next
  123. * transfer because we need to handle some difficult timing
  124. * issues otherwise. If we wait for ENDTX in one transfer and
  125. * then starts waiting for ENDRX in the next, it's difficult
  126. * to tell the difference between the ENDRX interrupt we're
  127. * actually waiting for and the ENDRX interrupt of the
  128. * previous transfer.
  129. *
  130. * It should be doable, though. Just not now...
  131. */
  132. spi_writel(as, TNCR, 0);
  133. spi_writel(as, RNCR, 0);
  134. spi_writel(as, IER, SPI_BIT(ENDRX) | SPI_BIT(OVRES));
  135. dev_dbg(&msg->spi->dev,
  136. " start xfer %p: len %u tx %p/%08x rx %p/%08x imr %03x\n",
  137. xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
  138. xfer->rx_buf, xfer->rx_dma, spi_readl(as, IMR));
  139. spi_writel(as, TCR, len);
  140. spi_writel(as, RCR, len);
  141. spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
  142. }
  143. static void atmel_spi_next_message(struct spi_master *master)
  144. {
  145. struct atmel_spi *as = spi_master_get_devdata(master);
  146. struct spi_message *msg;
  147. u32 mr;
  148. BUG_ON(as->current_transfer);
  149. msg = list_entry(as->queue.next, struct spi_message, queue);
  150. /* Select the chip */
  151. mr = spi_readl(as, MR);
  152. mr = SPI_BFINS(PCS, ~(1 << msg->spi->chip_select), mr);
  153. spi_writel(as, MR, mr);
  154. cs_activate(msg->spi);
  155. atmel_spi_next_xfer(master, msg);
  156. }
  157. static void
  158. atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
  159. {
  160. xfer->tx_dma = xfer->rx_dma = INVALID_DMA_ADDRESS;
  161. if (xfer->tx_buf)
  162. xfer->tx_dma = dma_map_single(&as->pdev->dev,
  163. (void *) xfer->tx_buf, xfer->len,
  164. DMA_TO_DEVICE);
  165. if (xfer->rx_buf)
  166. xfer->rx_dma = dma_map_single(&as->pdev->dev,
  167. xfer->rx_buf, xfer->len,
  168. DMA_FROM_DEVICE);
  169. }
  170. static void atmel_spi_dma_unmap_xfer(struct spi_master *master,
  171. struct spi_transfer *xfer)
  172. {
  173. if (xfer->tx_dma != INVALID_DMA_ADDRESS)
  174. dma_unmap_single(master->cdev.dev, xfer->tx_dma,
  175. xfer->len, DMA_TO_DEVICE);
  176. if (xfer->rx_dma != INVALID_DMA_ADDRESS)
  177. dma_unmap_single(master->cdev.dev, xfer->rx_dma,
  178. xfer->len, DMA_FROM_DEVICE);
  179. }
  180. static void
  181. atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
  182. struct spi_message *msg, int status)
  183. {
  184. cs_deactivate(msg->spi);
  185. list_del(&msg->queue);
  186. msg->status = status;
  187. dev_dbg(master->cdev.dev,
  188. "xfer complete: %u bytes transferred\n",
  189. msg->actual_length);
  190. spin_unlock(&as->lock);
  191. msg->complete(msg->context);
  192. spin_lock(&as->lock);
  193. as->current_transfer = NULL;
  194. /* continue if needed */
  195. if (list_empty(&as->queue) || as->stopping)
  196. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  197. else
  198. atmel_spi_next_message(master);
  199. }
  200. static irqreturn_t
  201. atmel_spi_interrupt(int irq, void *dev_id)
  202. {
  203. struct spi_master *master = dev_id;
  204. struct atmel_spi *as = spi_master_get_devdata(master);
  205. struct spi_message *msg;
  206. struct spi_transfer *xfer;
  207. u32 status, pending, imr;
  208. int ret = IRQ_NONE;
  209. spin_lock(&as->lock);
  210. xfer = as->current_transfer;
  211. msg = list_entry(as->queue.next, struct spi_message, queue);
  212. imr = spi_readl(as, IMR);
  213. status = spi_readl(as, SR);
  214. pending = status & imr;
  215. if (pending & SPI_BIT(OVRES)) {
  216. int timeout;
  217. ret = IRQ_HANDLED;
  218. spi_writel(as, IDR, (SPI_BIT(ENDTX) | SPI_BIT(ENDRX)
  219. | SPI_BIT(OVRES)));
  220. /*
  221. * When we get an overrun, we disregard the current
  222. * transfer. Data will not be copied back from any
  223. * bounce buffer and msg->actual_len will not be
  224. * updated with the last xfer.
  225. *
  226. * We will also not process any remaning transfers in
  227. * the message.
  228. *
  229. * First, stop the transfer and unmap the DMA buffers.
  230. */
  231. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  232. if (!msg->is_dma_mapped)
  233. atmel_spi_dma_unmap_xfer(master, xfer);
  234. /* REVISIT: udelay in irq is unfriendly */
  235. if (xfer->delay_usecs)
  236. udelay(xfer->delay_usecs);
  237. dev_warn(master->cdev.dev, "fifo overrun (%u/%u remaining)\n",
  238. spi_readl(as, TCR), spi_readl(as, RCR));
  239. /*
  240. * Clean up DMA registers and make sure the data
  241. * registers are empty.
  242. */
  243. spi_writel(as, RNCR, 0);
  244. spi_writel(as, TNCR, 0);
  245. spi_writel(as, RCR, 0);
  246. spi_writel(as, TCR, 0);
  247. for (timeout = 1000; timeout; timeout--)
  248. if (spi_readl(as, SR) & SPI_BIT(TXEMPTY))
  249. break;
  250. if (!timeout)
  251. dev_warn(master->cdev.dev,
  252. "timeout waiting for TXEMPTY");
  253. while (spi_readl(as, SR) & SPI_BIT(RDRF))
  254. spi_readl(as, RDR);
  255. /* Clear any overrun happening while cleaning up */
  256. spi_readl(as, SR);
  257. atmel_spi_msg_done(master, as, msg, -EIO);
  258. } else if (pending & SPI_BIT(ENDRX)) {
  259. ret = IRQ_HANDLED;
  260. spi_writel(as, IDR, pending);
  261. if (as->remaining_bytes == 0) {
  262. msg->actual_length += xfer->len;
  263. if (!msg->is_dma_mapped)
  264. atmel_spi_dma_unmap_xfer(master, xfer);
  265. /* REVISIT: udelay in irq is unfriendly */
  266. if (xfer->delay_usecs)
  267. udelay(xfer->delay_usecs);
  268. if (msg->transfers.prev == &xfer->transfer_list) {
  269. /* report completed message */
  270. atmel_spi_msg_done(master, as, msg, 0);
  271. } else {
  272. if (xfer->cs_change) {
  273. cs_deactivate(msg->spi);
  274. udelay(1);
  275. cs_activate(msg->spi);
  276. }
  277. /*
  278. * Not done yet. Submit the next transfer.
  279. *
  280. * FIXME handle protocol options for xfer
  281. */
  282. atmel_spi_next_xfer(master, msg);
  283. }
  284. } else {
  285. /*
  286. * Keep going, we still have data to send in
  287. * the current transfer.
  288. */
  289. atmel_spi_next_xfer(master, msg);
  290. }
  291. }
  292. spin_unlock(&as->lock);
  293. return ret;
  294. }
  295. #define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
  296. static int atmel_spi_setup(struct spi_device *spi)
  297. {
  298. struct atmel_spi *as;
  299. u32 scbr, csr;
  300. unsigned int bits = spi->bits_per_word;
  301. unsigned long bus_hz, sck_hz;
  302. unsigned int npcs_pin;
  303. int ret;
  304. as = spi_master_get_devdata(spi->master);
  305. if (as->stopping)
  306. return -ESHUTDOWN;
  307. if (spi->chip_select > spi->master->num_chipselect) {
  308. dev_dbg(&spi->dev,
  309. "setup: invalid chipselect %u (%u defined)\n",
  310. spi->chip_select, spi->master->num_chipselect);
  311. return -EINVAL;
  312. }
  313. if (bits == 0)
  314. bits = 8;
  315. if (bits < 8 || bits > 16) {
  316. dev_dbg(&spi->dev,
  317. "setup: invalid bits_per_word %u (8 to 16)\n",
  318. bits);
  319. return -EINVAL;
  320. }
  321. if (spi->mode & ~MODEBITS) {
  322. dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
  323. spi->mode & ~MODEBITS);
  324. return -EINVAL;
  325. }
  326. /* speed zero convention is used by some upper layers */
  327. bus_hz = clk_get_rate(as->clk);
  328. if (spi->max_speed_hz) {
  329. /* assume div32/fdiv/mbz == 0 */
  330. if (!as->new_1)
  331. bus_hz /= 2;
  332. scbr = ((bus_hz + spi->max_speed_hz - 1)
  333. / spi->max_speed_hz);
  334. if (scbr >= (1 << SPI_SCBR_SIZE)) {
  335. dev_dbg(&spi->dev, "setup: %d Hz too slow, scbr %u\n",
  336. spi->max_speed_hz, scbr);
  337. return -EINVAL;
  338. }
  339. } else
  340. scbr = 0xff;
  341. sck_hz = bus_hz / scbr;
  342. csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8);
  343. if (spi->mode & SPI_CPOL)
  344. csr |= SPI_BIT(CPOL);
  345. if (!(spi->mode & SPI_CPHA))
  346. csr |= SPI_BIT(NCPHA);
  347. /* TODO: DLYBS and DLYBCT */
  348. csr |= SPI_BF(DLYBS, 10);
  349. csr |= SPI_BF(DLYBCT, 10);
  350. /* chipselect must have been muxed as GPIO (e.g. in board setup) */
  351. npcs_pin = (unsigned int)spi->controller_data;
  352. if (!spi->controller_state) {
  353. ret = gpio_request(npcs_pin, "spi_npcs");
  354. if (ret)
  355. return ret;
  356. spi->controller_state = (void *)npcs_pin;
  357. gpio_direction_output(npcs_pin);
  358. }
  359. dev_dbg(&spi->dev,
  360. "setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
  361. sck_hz, bits, spi->mode, spi->chip_select, csr);
  362. spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
  363. return 0;
  364. }
  365. static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  366. {
  367. struct atmel_spi *as;
  368. struct spi_transfer *xfer;
  369. unsigned long flags;
  370. struct device *controller = spi->master->cdev.dev;
  371. as = spi_master_get_devdata(spi->master);
  372. dev_dbg(controller, "new message %p submitted for %s\n",
  373. msg, spi->dev.bus_id);
  374. if (unlikely(list_empty(&msg->transfers)
  375. || !spi->max_speed_hz))
  376. return -EINVAL;
  377. if (as->stopping)
  378. return -ESHUTDOWN;
  379. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  380. if (!(xfer->tx_buf || xfer->rx_buf)) {
  381. dev_dbg(&spi->dev, "missing rx or tx buf\n");
  382. return -EINVAL;
  383. }
  384. /* FIXME implement these protocol options!! */
  385. if (xfer->bits_per_word || xfer->speed_hz) {
  386. dev_dbg(&spi->dev, "no protocol options yet\n");
  387. return -ENOPROTOOPT;
  388. }
  389. }
  390. /* scrub dcache "early" */
  391. if (!msg->is_dma_mapped) {
  392. list_for_each_entry(xfer, &msg->transfers, transfer_list)
  393. atmel_spi_dma_map_xfer(as, xfer);
  394. }
  395. list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  396. dev_dbg(controller,
  397. " xfer %p: len %u tx %p/%08x rx %p/%08x\n",
  398. xfer, xfer->len,
  399. xfer->tx_buf, xfer->tx_dma,
  400. xfer->rx_buf, xfer->rx_dma);
  401. }
  402. msg->status = -EINPROGRESS;
  403. msg->actual_length = 0;
  404. spin_lock_irqsave(&as->lock, flags);
  405. list_add_tail(&msg->queue, &as->queue);
  406. if (!as->current_transfer)
  407. atmel_spi_next_message(spi->master);
  408. spin_unlock_irqrestore(&as->lock, flags);
  409. return 0;
  410. }
  411. static void atmel_spi_cleanup(const struct spi_device *spi)
  412. {
  413. if (spi->controller_state)
  414. gpio_free((unsigned int)spi->controller_data);
  415. }
  416. /*-------------------------------------------------------------------------*/
  417. static int __init atmel_spi_probe(struct platform_device *pdev)
  418. {
  419. struct resource *regs;
  420. int irq;
  421. struct clk *clk;
  422. int ret;
  423. struct spi_master *master;
  424. struct atmel_spi *as;
  425. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  426. if (!regs)
  427. return -ENXIO;
  428. irq = platform_get_irq(pdev, 0);
  429. if (irq < 0)
  430. return irq;
  431. clk = clk_get(&pdev->dev, "spi_clk");
  432. if (IS_ERR(clk))
  433. return PTR_ERR(clk);
  434. /* setup spi core then atmel-specific driver state */
  435. ret = -ENOMEM;
  436. master = spi_alloc_master(&pdev->dev, sizeof *as);
  437. if (!master)
  438. goto out_free;
  439. master->bus_num = pdev->id;
  440. master->num_chipselect = 4;
  441. master->setup = atmel_spi_setup;
  442. master->transfer = atmel_spi_transfer;
  443. master->cleanup = atmel_spi_cleanup;
  444. platform_set_drvdata(pdev, master);
  445. as = spi_master_get_devdata(master);
  446. as->buffer = dma_alloc_coherent(&pdev->dev, BUFFER_SIZE,
  447. &as->buffer_dma, GFP_KERNEL);
  448. if (!as->buffer)
  449. goto out_free;
  450. spin_lock_init(&as->lock);
  451. INIT_LIST_HEAD(&as->queue);
  452. as->pdev = pdev;
  453. as->regs = ioremap(regs->start, (regs->end - regs->start) + 1);
  454. if (!as->regs)
  455. goto out_free_buffer;
  456. as->irq = irq;
  457. as->clk = clk;
  458. #ifdef CONFIG_ARCH_AT91
  459. if (!cpu_is_at91rm9200())
  460. as->new_1 = 1;
  461. #endif
  462. ret = request_irq(irq, atmel_spi_interrupt, 0,
  463. pdev->dev.bus_id, master);
  464. if (ret)
  465. goto out_unmap_regs;
  466. /* Initialize the hardware */
  467. clk_enable(clk);
  468. spi_writel(as, CR, SPI_BIT(SWRST));
  469. spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
  470. spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
  471. spi_writel(as, CR, SPI_BIT(SPIEN));
  472. /* go! */
  473. dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
  474. (unsigned long)regs->start, irq);
  475. ret = spi_register_master(master);
  476. if (ret)
  477. goto out_reset_hw;
  478. return 0;
  479. out_reset_hw:
  480. spi_writel(as, CR, SPI_BIT(SWRST));
  481. clk_disable(clk);
  482. free_irq(irq, master);
  483. out_unmap_regs:
  484. iounmap(as->regs);
  485. out_free_buffer:
  486. dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
  487. as->buffer_dma);
  488. out_free:
  489. clk_put(clk);
  490. spi_master_put(master);
  491. return ret;
  492. }
  493. static int __exit atmel_spi_remove(struct platform_device *pdev)
  494. {
  495. struct spi_master *master = platform_get_drvdata(pdev);
  496. struct atmel_spi *as = spi_master_get_devdata(master);
  497. struct spi_message *msg;
  498. /* reset the hardware and block queue progress */
  499. spin_lock_irq(&as->lock);
  500. as->stopping = 1;
  501. spi_writel(as, CR, SPI_BIT(SWRST));
  502. spi_readl(as, SR);
  503. spin_unlock_irq(&as->lock);
  504. /* Terminate remaining queued transfers */
  505. list_for_each_entry(msg, &as->queue, queue) {
  506. /* REVISIT unmapping the dma is a NOP on ARM and AVR32
  507. * but we shouldn't depend on that...
  508. */
  509. msg->status = -ESHUTDOWN;
  510. msg->complete(msg->context);
  511. }
  512. dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
  513. as->buffer_dma);
  514. clk_disable(as->clk);
  515. clk_put(as->clk);
  516. free_irq(as->irq, master);
  517. iounmap(as->regs);
  518. spi_unregister_master(master);
  519. return 0;
  520. }
  521. #ifdef CONFIG_PM
  522. static int atmel_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
  523. {
  524. struct spi_master *master = platform_get_drvdata(pdev);
  525. struct atmel_spi *as = spi_master_get_devdata(master);
  526. clk_disable(as->clk);
  527. return 0;
  528. }
  529. static int atmel_spi_resume(struct platform_device *pdev)
  530. {
  531. struct spi_master *master = platform_get_drvdata(pdev);
  532. struct atmel_spi *as = spi_master_get_devdata(master);
  533. clk_enable(as->clk);
  534. return 0;
  535. }
  536. #else
  537. #define atmel_spi_suspend NULL
  538. #define atmel_spi_resume NULL
  539. #endif
  540. static struct platform_driver atmel_spi_driver = {
  541. .driver = {
  542. .name = "atmel_spi",
  543. .owner = THIS_MODULE,
  544. },
  545. .suspend = atmel_spi_suspend,
  546. .resume = atmel_spi_resume,
  547. .remove = __exit_p(atmel_spi_remove),
  548. };
  549. static int __init atmel_spi_init(void)
  550. {
  551. return platform_driver_probe(&atmel_spi_driver, atmel_spi_probe);
  552. }
  553. module_init(atmel_spi_init);
  554. static void __exit atmel_spi_exit(void)
  555. {
  556. platform_driver_unregister(&atmel_spi_driver);
  557. }
  558. module_exit(atmel_spi_exit);
  559. MODULE_DESCRIPTION("Atmel AT32/AT91 SPI Controller driver");
  560. MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
  561. MODULE_LICENSE("GPL");