spi_stmp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Freescale STMP378X SPI master driver
  3. *
  4. * Author: dmitry pervushin <dimka@embeddedalley.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  7. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  8. */
  9. /*
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/err.h>
  23. #include <linux/clk.h>
  24. #include <linux/io.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/delay.h>
  27. #include <mach/platform.h>
  28. #include <mach/stmp3xxx.h>
  29. #include <mach/dma.h>
  30. #include <mach/regs-ssp.h>
  31. #include <mach/regs-apbh.h>
  32. /* 0 means DMA mode(recommended, default), !0 - PIO mode */
  33. static int pio;
  34. static int clock;
  35. /* default timeout for busy waits is 2 seconds */
  36. #define STMP_SPI_TIMEOUT (2 * HZ)
  37. struct stmp_spi {
  38. int id;
  39. void * __iomem regs; /* vaddr of the control registers */
  40. int irq, err_irq;
  41. u32 dma;
  42. struct stmp3xxx_dma_descriptor d;
  43. u32 speed_khz;
  44. u32 saved_timings;
  45. u32 divider;
  46. struct clk *clk;
  47. struct device *master_dev;
  48. struct work_struct work;
  49. struct workqueue_struct *workqueue;
  50. /* lock protects queue access */
  51. spinlock_t lock;
  52. struct list_head queue;
  53. struct completion done;
  54. };
  55. #define busy_wait(cond) \
  56. ({ \
  57. unsigned long end_jiffies = jiffies + STMP_SPI_TIMEOUT; \
  58. bool succeeded = false; \
  59. do { \
  60. if (cond) { \
  61. succeeded = true; \
  62. break; \
  63. } \
  64. cpu_relax(); \
  65. } while (time_before(jiffies, end_jiffies)); \
  66. succeeded; \
  67. })
  68. /**
  69. * stmp_spi_init_hw
  70. * Initialize the SSP port
  71. */
  72. static int stmp_spi_init_hw(struct stmp_spi *ss)
  73. {
  74. int err = 0;
  75. void *pins = ss->master_dev->platform_data;
  76. err = stmp3xxx_request_pin_group(pins, dev_name(ss->master_dev));
  77. if (err)
  78. goto out;
  79. ss->clk = clk_get(NULL, "ssp");
  80. if (IS_ERR(ss->clk)) {
  81. err = PTR_ERR(ss->clk);
  82. goto out_free_pins;
  83. }
  84. clk_enable(ss->clk);
  85. stmp3xxx_reset_block(ss->regs, false);
  86. stmp3xxx_dma_reset_channel(ss->dma);
  87. return 0;
  88. out_free_pins:
  89. stmp3xxx_release_pin_group(pins, dev_name(ss->master_dev));
  90. out:
  91. return err;
  92. }
  93. static void stmp_spi_release_hw(struct stmp_spi *ss)
  94. {
  95. void *pins = ss->master_dev->platform_data;
  96. if (ss->clk && !IS_ERR(ss->clk)) {
  97. clk_disable(ss->clk);
  98. clk_put(ss->clk);
  99. }
  100. stmp3xxx_release_pin_group(pins, dev_name(ss->master_dev));
  101. }
  102. static int stmp_spi_setup_transfer(struct spi_device *spi,
  103. struct spi_transfer *t)
  104. {
  105. u8 bits_per_word;
  106. u32 hz;
  107. struct stmp_spi *ss = spi_master_get_devdata(spi->master);
  108. u16 rate;
  109. bits_per_word = spi->bits_per_word;
  110. if (t && t->bits_per_word)
  111. bits_per_word = t->bits_per_word;
  112. /*
  113. * Calculate speed:
  114. * - by default, use maximum speed from ssp clk
  115. * - if device overrides it, use it
  116. * - if transfer specifies other speed, use transfer's one
  117. */
  118. hz = 1000 * ss->speed_khz / ss->divider;
  119. if (spi->max_speed_hz)
  120. hz = min(hz, spi->max_speed_hz);
  121. if (t && t->speed_hz)
  122. hz = min(hz, t->speed_hz);
  123. if (hz == 0) {
  124. dev_err(&spi->dev, "Cannot continue with zero clock\n");
  125. return -EINVAL;
  126. }
  127. if (bits_per_word != 8) {
  128. dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
  129. __func__, bits_per_word);
  130. return -EINVAL;
  131. }
  132. dev_dbg(&spi->dev, "Requested clk rate = %uHz, max = %uHz/%d = %uHz\n",
  133. hz, ss->speed_khz, ss->divider,
  134. ss->speed_khz * 1000 / ss->divider);
  135. if (ss->speed_khz * 1000 / ss->divider < hz) {
  136. dev_err(&spi->dev, "%s, unsupported clock rate %uHz\n",
  137. __func__, hz);
  138. return -EINVAL;
  139. }
  140. rate = 1000 * ss->speed_khz/ss->divider/hz;
  141. writel(BF(ss->divider, SSP_TIMING_CLOCK_DIVIDE) |
  142. BF(rate - 1, SSP_TIMING_CLOCK_RATE),
  143. HW_SSP_TIMING + ss->regs);
  144. writel(BF(1 /* mode SPI */, SSP_CTRL1_SSP_MODE) |
  145. BF(4 /* 8 bits */, SSP_CTRL1_WORD_LENGTH) |
  146. ((spi->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) |
  147. ((spi->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0) |
  148. (pio ? 0 : BM_SSP_CTRL1_DMA_ENABLE),
  149. ss->regs + HW_SSP_CTRL1);
  150. return 0;
  151. }
  152. static int stmp_spi_setup(struct spi_device *spi)
  153. {
  154. /* spi_setup() does basic checks,
  155. * stmp_spi_setup_transfer() does more later
  156. */
  157. if (spi->bits_per_word != 8) {
  158. dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
  159. __func__, spi->bits_per_word);
  160. return -EINVAL;
  161. }
  162. return 0;
  163. }
  164. static inline u32 stmp_spi_cs(unsigned cs)
  165. {
  166. return ((cs & 1) ? BM_SSP_CTRL0_WAIT_FOR_CMD : 0) |
  167. ((cs & 2) ? BM_SSP_CTRL0_WAIT_FOR_IRQ : 0);
  168. }
  169. static int stmp_spi_txrx_dma(struct stmp_spi *ss, int cs,
  170. unsigned char *buf, dma_addr_t dma_buf, int len,
  171. int first, int last, bool write)
  172. {
  173. u32 c0 = 0;
  174. dma_addr_t spi_buf_dma = dma_buf;
  175. int status = 0;
  176. enum dma_data_direction dir = write ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  177. c0 |= (first ? BM_SSP_CTRL0_LOCK_CS : 0);
  178. c0 |= (last ? BM_SSP_CTRL0_IGNORE_CRC : 0);
  179. c0 |= (write ? 0 : BM_SSP_CTRL0_READ);
  180. c0 |= BM_SSP_CTRL0_DATA_XFER;
  181. c0 |= stmp_spi_cs(cs);
  182. c0 |= BF(len, SSP_CTRL0_XFER_COUNT);
  183. if (!dma_buf)
  184. spi_buf_dma = dma_map_single(ss->master_dev, buf, len, dir);
  185. ss->d.command->cmd =
  186. BF(len, APBH_CHn_CMD_XFER_COUNT) |
  187. BF(1, APBH_CHn_CMD_CMDWORDS) |
  188. BM_APBH_CHn_CMD_WAIT4ENDCMD |
  189. BM_APBH_CHn_CMD_IRQONCMPLT |
  190. BF(write ? BV_APBH_CHn_CMD_COMMAND__DMA_READ :
  191. BV_APBH_CHn_CMD_COMMAND__DMA_WRITE,
  192. APBH_CHn_CMD_COMMAND);
  193. ss->d.command->pio_words[0] = c0;
  194. ss->d.command->buf_ptr = spi_buf_dma;
  195. stmp3xxx_dma_reset_channel(ss->dma);
  196. stmp3xxx_dma_clear_interrupt(ss->dma);
  197. stmp3xxx_dma_enable_interrupt(ss->dma);
  198. init_completion(&ss->done);
  199. stmp3xxx_dma_go(ss->dma, &ss->d, 1);
  200. wait_for_completion(&ss->done);
  201. if (!busy_wait(readl(ss->regs + HW_SSP_CTRL0) & BM_SSP_CTRL0_RUN))
  202. status = -ETIMEDOUT;
  203. if (!dma_buf)
  204. dma_unmap_single(ss->master_dev, spi_buf_dma, len, dir);
  205. return status;
  206. }
  207. static inline void stmp_spi_enable(struct stmp_spi *ss)
  208. {
  209. stmp3xxx_setl(BM_SSP_CTRL0_LOCK_CS, ss->regs + HW_SSP_CTRL0);
  210. stmp3xxx_clearl(BM_SSP_CTRL0_IGNORE_CRC, ss->regs + HW_SSP_CTRL0);
  211. }
  212. static inline void stmp_spi_disable(struct stmp_spi *ss)
  213. {
  214. stmp3xxx_clearl(BM_SSP_CTRL0_LOCK_CS, ss->regs + HW_SSP_CTRL0);
  215. stmp3xxx_setl(BM_SSP_CTRL0_IGNORE_CRC, ss->regs + HW_SSP_CTRL0);
  216. }
  217. static int stmp_spi_txrx_pio(struct stmp_spi *ss, int cs,
  218. unsigned char *buf, int len,
  219. bool first, bool last, bool write)
  220. {
  221. if (first)
  222. stmp_spi_enable(ss);
  223. stmp3xxx_setl(stmp_spi_cs(cs), ss->regs + HW_SSP_CTRL0);
  224. while (len--) {
  225. if (last && len <= 0)
  226. stmp_spi_disable(ss);
  227. stmp3xxx_clearl(BM_SSP_CTRL0_XFER_COUNT,
  228. ss->regs + HW_SSP_CTRL0);
  229. stmp3xxx_setl(1, ss->regs + HW_SSP_CTRL0);
  230. if (write)
  231. stmp3xxx_clearl(BM_SSP_CTRL0_READ,
  232. ss->regs + HW_SSP_CTRL0);
  233. else
  234. stmp3xxx_setl(BM_SSP_CTRL0_READ,
  235. ss->regs + HW_SSP_CTRL0);
  236. /* Run! */
  237. stmp3xxx_setl(BM_SSP_CTRL0_RUN, ss->regs + HW_SSP_CTRL0);
  238. if (!busy_wait(readl(ss->regs + HW_SSP_CTRL0) &
  239. BM_SSP_CTRL0_RUN))
  240. break;
  241. if (write)
  242. writel(*buf, ss->regs + HW_SSP_DATA);
  243. /* Set TRANSFER */
  244. stmp3xxx_setl(BM_SSP_CTRL0_DATA_XFER, ss->regs + HW_SSP_CTRL0);
  245. if (!write) {
  246. if (busy_wait((readl(ss->regs + HW_SSP_STATUS) &
  247. BM_SSP_STATUS_FIFO_EMPTY)))
  248. break;
  249. *buf = readl(ss->regs + HW_SSP_DATA) & 0xFF;
  250. }
  251. if (!busy_wait(readl(ss->regs + HW_SSP_CTRL0) &
  252. BM_SSP_CTRL0_RUN))
  253. break;
  254. /* advance to the next byte */
  255. buf++;
  256. }
  257. return len < 0 ? 0 : -ETIMEDOUT;
  258. }
  259. static int stmp_spi_handle_message(struct stmp_spi *ss, struct spi_message *m)
  260. {
  261. bool first, last;
  262. struct spi_transfer *t, *tmp_t;
  263. int status = 0;
  264. int cs;
  265. cs = m->spi->chip_select;
  266. list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) {
  267. first = (&t->transfer_list == m->transfers.next);
  268. last = (&t->transfer_list == m->transfers.prev);
  269. if (first || t->speed_hz || t->bits_per_word)
  270. stmp_spi_setup_transfer(m->spi, t);
  271. /* reject "not last" transfers which request to change cs */
  272. if (t->cs_change && !last) {
  273. dev_err(&m->spi->dev,
  274. "Message with t->cs_change has been skipped\n");
  275. continue;
  276. }
  277. if (t->tx_buf) {
  278. status = pio ?
  279. stmp_spi_txrx_pio(ss, cs, (void *)t->tx_buf,
  280. t->len, first, last, true) :
  281. stmp_spi_txrx_dma(ss, cs, (void *)t->tx_buf,
  282. t->tx_dma, t->len, first, last, true);
  283. #ifdef DEBUG
  284. if (t->len < 0x10)
  285. print_hex_dump_bytes("Tx ",
  286. DUMP_PREFIX_OFFSET,
  287. t->tx_buf, t->len);
  288. else
  289. pr_debug("Tx: %d bytes\n", t->len);
  290. #endif
  291. }
  292. if (t->rx_buf) {
  293. status = pio ?
  294. stmp_spi_txrx_pio(ss, cs, t->rx_buf,
  295. t->len, first, last, false) :
  296. stmp_spi_txrx_dma(ss, cs, t->rx_buf,
  297. t->rx_dma, t->len, first, last, false);
  298. #ifdef DEBUG
  299. if (t->len < 0x10)
  300. print_hex_dump_bytes("Rx ",
  301. DUMP_PREFIX_OFFSET,
  302. t->rx_buf, t->len);
  303. else
  304. pr_debug("Rx: %d bytes\n", t->len);
  305. #endif
  306. }
  307. if (t->delay_usecs)
  308. udelay(t->delay_usecs);
  309. if (status)
  310. break;
  311. }
  312. return status;
  313. }
  314. /**
  315. * stmp_spi_handle - handle messages from the queue
  316. */
  317. static void stmp_spi_handle(struct work_struct *w)
  318. {
  319. struct stmp_spi *ss = container_of(w, struct stmp_spi, work);
  320. unsigned long flags;
  321. struct spi_message *m;
  322. spin_lock_irqsave(&ss->lock, flags);
  323. while (!list_empty(&ss->queue)) {
  324. m = list_entry(ss->queue.next, struct spi_message, queue);
  325. list_del_init(&m->queue);
  326. spin_unlock_irqrestore(&ss->lock, flags);
  327. m->status = stmp_spi_handle_message(ss, m);
  328. m->complete(m->context);
  329. spin_lock_irqsave(&ss->lock, flags);
  330. }
  331. spin_unlock_irqrestore(&ss->lock, flags);
  332. return;
  333. }
  334. /**
  335. * stmp_spi_transfer - perform message transfer.
  336. * Called indirectly from spi_async, queues all the messages to
  337. * spi_handle_message.
  338. * @spi: spi device
  339. * @m: message to be queued
  340. */
  341. static int stmp_spi_transfer(struct spi_device *spi, struct spi_message *m)
  342. {
  343. struct stmp_spi *ss = spi_master_get_devdata(spi->master);
  344. unsigned long flags;
  345. m->status = -EINPROGRESS;
  346. spin_lock_irqsave(&ss->lock, flags);
  347. list_add_tail(&m->queue, &ss->queue);
  348. queue_work(ss->workqueue, &ss->work);
  349. spin_unlock_irqrestore(&ss->lock, flags);
  350. return 0;
  351. }
  352. static irqreturn_t stmp_spi_irq(int irq, void *dev_id)
  353. {
  354. struct stmp_spi *ss = dev_id;
  355. stmp3xxx_dma_clear_interrupt(ss->dma);
  356. complete(&ss->done);
  357. return IRQ_HANDLED;
  358. }
  359. static irqreturn_t stmp_spi_irq_err(int irq, void *dev_id)
  360. {
  361. struct stmp_spi *ss = dev_id;
  362. u32 c1, st;
  363. c1 = readl(ss->regs + HW_SSP_CTRL1);
  364. st = readl(ss->regs + HW_SSP_STATUS);
  365. dev_err(ss->master_dev, "%s: status = 0x%08X, c1 = 0x%08X\n",
  366. __func__, st, c1);
  367. stmp3xxx_clearl(c1 & 0xCCCC0000, ss->regs + HW_SSP_CTRL1);
  368. return IRQ_HANDLED;
  369. }
  370. static int __devinit stmp_spi_probe(struct platform_device *dev)
  371. {
  372. int err = 0;
  373. struct spi_master *master;
  374. struct stmp_spi *ss;
  375. struct resource *r;
  376. master = spi_alloc_master(&dev->dev, sizeof(struct stmp_spi));
  377. if (master == NULL) {
  378. err = -ENOMEM;
  379. goto out0;
  380. }
  381. master->flags = SPI_MASTER_HALF_DUPLEX;
  382. ss = spi_master_get_devdata(master);
  383. platform_set_drvdata(dev, master);
  384. /* Get resources(memory, IRQ) associated with the device */
  385. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  386. if (r == NULL) {
  387. err = -ENODEV;
  388. goto out_put_master;
  389. }
  390. ss->regs = ioremap(r->start, resource_size(r));
  391. if (!ss->regs) {
  392. err = -EINVAL;
  393. goto out_put_master;
  394. }
  395. ss->master_dev = &dev->dev;
  396. ss->id = dev->id;
  397. INIT_WORK(&ss->work, stmp_spi_handle);
  398. INIT_LIST_HEAD(&ss->queue);
  399. spin_lock_init(&ss->lock);
  400. ss->workqueue = create_singlethread_workqueue(dev_name(&dev->dev));
  401. if (!ss->workqueue) {
  402. err = -ENXIO;
  403. goto out_put_master;
  404. }
  405. master->transfer = stmp_spi_transfer;
  406. master->setup = stmp_spi_setup;
  407. /* the spi->mode bits understood by this driver: */
  408. master->mode_bits = SPI_CPOL | SPI_CPHA;
  409. ss->irq = platform_get_irq(dev, 0);
  410. if (ss->irq < 0) {
  411. err = ss->irq;
  412. goto out_put_master;
  413. }
  414. ss->err_irq = platform_get_irq(dev, 1);
  415. if (ss->err_irq < 0) {
  416. err = ss->err_irq;
  417. goto out_put_master;
  418. }
  419. r = platform_get_resource(dev, IORESOURCE_DMA, 0);
  420. if (r == NULL) {
  421. err = -ENODEV;
  422. goto out_put_master;
  423. }
  424. ss->dma = r->start;
  425. err = stmp3xxx_dma_request(ss->dma, &dev->dev, dev_name(&dev->dev));
  426. if (err)
  427. goto out_put_master;
  428. err = stmp3xxx_dma_allocate_command(ss->dma, &ss->d);
  429. if (err)
  430. goto out_free_dma;
  431. master->bus_num = dev->id;
  432. master->num_chipselect = 1;
  433. /* SPI controller initializations */
  434. err = stmp_spi_init_hw(ss);
  435. if (err) {
  436. dev_dbg(&dev->dev, "cannot initialize hardware\n");
  437. goto out_free_dma_desc;
  438. }
  439. if (clock) {
  440. dev_info(&dev->dev, "clock rate forced to %d\n", clock);
  441. clk_set_rate(ss->clk, clock);
  442. }
  443. ss->speed_khz = clk_get_rate(ss->clk);
  444. ss->divider = 2;
  445. dev_info(&dev->dev, "max possible speed %d = %ld/%d kHz\n",
  446. ss->speed_khz, clk_get_rate(ss->clk), ss->divider);
  447. /* Register for SPI interrupt */
  448. err = request_irq(ss->irq, stmp_spi_irq, 0,
  449. dev_name(&dev->dev), ss);
  450. if (err) {
  451. dev_dbg(&dev->dev, "request_irq failed, %d\n", err);
  452. goto out_release_hw;
  453. }
  454. /* ..and shared interrupt for all SSP controllers */
  455. err = request_irq(ss->err_irq, stmp_spi_irq_err, IRQF_SHARED,
  456. dev_name(&dev->dev), ss);
  457. if (err) {
  458. dev_dbg(&dev->dev, "request_irq(error) failed, %d\n", err);
  459. goto out_free_irq;
  460. }
  461. err = spi_register_master(master);
  462. if (err) {
  463. dev_dbg(&dev->dev, "cannot register spi master, %d\n", err);
  464. goto out_free_irq_2;
  465. }
  466. dev_info(&dev->dev, "at (mapped) 0x%08X, irq=%d, bus %d, %s mode\n",
  467. (u32)ss->regs, ss->irq, master->bus_num,
  468. pio ? "PIO" : "DMA");
  469. return 0;
  470. out_free_irq_2:
  471. free_irq(ss->err_irq, ss);
  472. out_free_irq:
  473. free_irq(ss->irq, ss);
  474. out_free_dma_desc:
  475. stmp3xxx_dma_free_command(ss->dma, &ss->d);
  476. out_free_dma:
  477. stmp3xxx_dma_release(ss->dma);
  478. out_release_hw:
  479. stmp_spi_release_hw(ss);
  480. out_put_master:
  481. if (ss->workqueue)
  482. destroy_workqueue(ss->workqueue);
  483. if (ss->regs)
  484. iounmap(ss->regs);
  485. platform_set_drvdata(dev, NULL);
  486. spi_master_put(master);
  487. out0:
  488. return err;
  489. }
  490. static int __devexit stmp_spi_remove(struct platform_device *dev)
  491. {
  492. struct stmp_spi *ss;
  493. struct spi_master *master;
  494. master = platform_get_drvdata(dev);
  495. if (master == NULL)
  496. goto out0;
  497. ss = spi_master_get_devdata(master);
  498. spi_unregister_master(master);
  499. free_irq(ss->err_irq, ss);
  500. free_irq(ss->irq, ss);
  501. stmp3xxx_dma_free_command(ss->dma, &ss->d);
  502. stmp3xxx_dma_release(ss->dma);
  503. stmp_spi_release_hw(ss);
  504. destroy_workqueue(ss->workqueue);
  505. iounmap(ss->regs);
  506. spi_master_put(master);
  507. platform_set_drvdata(dev, NULL);
  508. out0:
  509. return 0;
  510. }
  511. #ifdef CONFIG_PM
  512. static int stmp_spi_suspend(struct platform_device *pdev, pm_message_t pmsg)
  513. {
  514. struct stmp_spi *ss;
  515. struct spi_master *master;
  516. master = platform_get_drvdata(pdev);
  517. ss = spi_master_get_devdata(master);
  518. ss->saved_timings = readl(HW_SSP_TIMING + ss->regs);
  519. clk_disable(ss->clk);
  520. return 0;
  521. }
  522. static int stmp_spi_resume(struct platform_device *pdev)
  523. {
  524. struct stmp_spi *ss;
  525. struct spi_master *master;
  526. master = platform_get_drvdata(pdev);
  527. ss = spi_master_get_devdata(master);
  528. clk_enable(ss->clk);
  529. stmp3xxx_reset_block(ss->regs, false);
  530. writel(ss->saved_timings, ss->regs + HW_SSP_TIMING);
  531. return 0;
  532. }
  533. #else
  534. #define stmp_spi_suspend NULL
  535. #define stmp_spi_resume NULL
  536. #endif
  537. static struct platform_driver stmp_spi_driver = {
  538. .probe = stmp_spi_probe,
  539. .remove = __devexit_p(stmp_spi_remove),
  540. .driver = {
  541. .name = "stmp3xxx_ssp",
  542. .owner = THIS_MODULE,
  543. },
  544. .suspend = stmp_spi_suspend,
  545. .resume = stmp_spi_resume,
  546. };
  547. static int __init stmp_spi_init(void)
  548. {
  549. return platform_driver_register(&stmp_spi_driver);
  550. }
  551. static void __exit stmp_spi_exit(void)
  552. {
  553. platform_driver_unregister(&stmp_spi_driver);
  554. }
  555. module_init(stmp_spi_init);
  556. module_exit(stmp_spi_exit);
  557. module_param(pio, int, S_IRUGO);
  558. module_param(clock, int, S_IRUGO);
  559. MODULE_AUTHOR("dmitry pervushin <dpervushin@embeddedalley.com>");
  560. MODULE_DESCRIPTION("STMP3xxx SPI/SSP driver");
  561. MODULE_LICENSE("GPL");