spi_tegra.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * Driver for Nvidia TEGRA spi controller.
  3. *
  4. * Copyright (C) 2010 Google, Inc.
  5. *
  6. * Author:
  7. * Erik Gilling <konkers@android.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/err.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/io.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/dmapool.h>
  26. #include <linux/clk.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/delay.h>
  29. #include <linux/spi/spi.h>
  30. #include <mach/dma.h>
  31. #define SLINK_COMMAND 0x000
  32. #define SLINK_BIT_LENGTH(x) (((x) & 0x1f) << 0)
  33. #define SLINK_WORD_SIZE(x) (((x) & 0x1f) << 5)
  34. #define SLINK_BOTH_EN (1 << 10)
  35. #define SLINK_CS_SW (1 << 11)
  36. #define SLINK_CS_VALUE (1 << 12)
  37. #define SLINK_CS_POLARITY (1 << 13)
  38. #define SLINK_IDLE_SDA_DRIVE_LOW (0 << 16)
  39. #define SLINK_IDLE_SDA_DRIVE_HIGH (1 << 16)
  40. #define SLINK_IDLE_SDA_PULL_LOW (2 << 16)
  41. #define SLINK_IDLE_SDA_PULL_HIGH (3 << 16)
  42. #define SLINK_IDLE_SDA_MASK (3 << 16)
  43. #define SLINK_CS_POLARITY1 (1 << 20)
  44. #define SLINK_CK_SDA (1 << 21)
  45. #define SLINK_CS_POLARITY2 (1 << 22)
  46. #define SLINK_CS_POLARITY3 (1 << 23)
  47. #define SLINK_IDLE_SCLK_DRIVE_LOW (0 << 24)
  48. #define SLINK_IDLE_SCLK_DRIVE_HIGH (1 << 24)
  49. #define SLINK_IDLE_SCLK_PULL_LOW (2 << 24)
  50. #define SLINK_IDLE_SCLK_PULL_HIGH (3 << 24)
  51. #define SLINK_IDLE_SCLK_MASK (3 << 24)
  52. #define SLINK_M_S (1 << 28)
  53. #define SLINK_WAIT (1 << 29)
  54. #define SLINK_GO (1 << 30)
  55. #define SLINK_ENB (1 << 31)
  56. #define SLINK_COMMAND2 0x004
  57. #define SLINK_LSBFE (1 << 0)
  58. #define SLINK_SSOE (1 << 1)
  59. #define SLINK_SPIE (1 << 4)
  60. #define SLINK_BIDIROE (1 << 6)
  61. #define SLINK_MODFEN (1 << 7)
  62. #define SLINK_INT_SIZE(x) (((x) & 0x1f) << 8)
  63. #define SLINK_CS_ACTIVE_BETWEEN (1 << 17)
  64. #define SLINK_SS_EN_CS(x) (((x) & 0x3) << 18)
  65. #define SLINK_SS_SETUP(x) (((x) & 0x3) << 20)
  66. #define SLINK_FIFO_REFILLS_0 (0 << 22)
  67. #define SLINK_FIFO_REFILLS_1 (1 << 22)
  68. #define SLINK_FIFO_REFILLS_2 (2 << 22)
  69. #define SLINK_FIFO_REFILLS_3 (3 << 22)
  70. #define SLINK_FIFO_REFILLS_MASK (3 << 22)
  71. #define SLINK_WAIT_PACK_INT(x) (((x) & 0x7) << 26)
  72. #define SLINK_SPC0 (1 << 29)
  73. #define SLINK_TXEN (1 << 30)
  74. #define SLINK_RXEN (1 << 31)
  75. #define SLINK_STATUS 0x008
  76. #define SLINK_COUNT(val) (((val) >> 0) & 0x1f)
  77. #define SLINK_WORD(val) (((val) >> 5) & 0x1f)
  78. #define SLINK_BLK_CNT(val) (((val) >> 0) & 0xffff)
  79. #define SLINK_MODF (1 << 16)
  80. #define SLINK_RX_UNF (1 << 18)
  81. #define SLINK_TX_OVF (1 << 19)
  82. #define SLINK_TX_FULL (1 << 20)
  83. #define SLINK_TX_EMPTY (1 << 21)
  84. #define SLINK_RX_FULL (1 << 22)
  85. #define SLINK_RX_EMPTY (1 << 23)
  86. #define SLINK_TX_UNF (1 << 24)
  87. #define SLINK_RX_OVF (1 << 25)
  88. #define SLINK_TX_FLUSH (1 << 26)
  89. #define SLINK_RX_FLUSH (1 << 27)
  90. #define SLINK_SCLK (1 << 28)
  91. #define SLINK_ERR (1 << 29)
  92. #define SLINK_RDY (1 << 30)
  93. #define SLINK_BSY (1 << 31)
  94. #define SLINK_MAS_DATA 0x010
  95. #define SLINK_SLAVE_DATA 0x014
  96. #define SLINK_DMA_CTL 0x018
  97. #define SLINK_DMA_BLOCK_SIZE(x) (((x) & 0xffff) << 0)
  98. #define SLINK_TX_TRIG_1 (0 << 16)
  99. #define SLINK_TX_TRIG_4 (1 << 16)
  100. #define SLINK_TX_TRIG_8 (2 << 16)
  101. #define SLINK_TX_TRIG_16 (3 << 16)
  102. #define SLINK_TX_TRIG_MASK (3 << 16)
  103. #define SLINK_RX_TRIG_1 (0 << 18)
  104. #define SLINK_RX_TRIG_4 (1 << 18)
  105. #define SLINK_RX_TRIG_8 (2 << 18)
  106. #define SLINK_RX_TRIG_16 (3 << 18)
  107. #define SLINK_RX_TRIG_MASK (3 << 18)
  108. #define SLINK_PACKED (1 << 20)
  109. #define SLINK_PACK_SIZE_4 (0 << 21)
  110. #define SLINK_PACK_SIZE_8 (1 << 21)
  111. #define SLINK_PACK_SIZE_16 (2 << 21)
  112. #define SLINK_PACK_SIZE_32 (3 << 21)
  113. #define SLINK_PACK_SIZE_MASK (3 << 21)
  114. #define SLINK_IE_TXC (1 << 26)
  115. #define SLINK_IE_RXC (1 << 27)
  116. #define SLINK_DMA_EN (1 << 31)
  117. #define SLINK_STATUS2 0x01c
  118. #define SLINK_TX_FIFO_EMPTY_COUNT(val) (((val) & 0x3f) >> 0)
  119. #define SLINK_RX_FIFO_FULL_COUNT(val) (((val) & 0x3f) >> 16)
  120. #define SLINK_TX_FIFO 0x100
  121. #define SLINK_RX_FIFO 0x180
  122. static const unsigned long spi_tegra_req_sels[] = {
  123. TEGRA_DMA_REQ_SEL_SL2B1,
  124. TEGRA_DMA_REQ_SEL_SL2B2,
  125. TEGRA_DMA_REQ_SEL_SL2B3,
  126. TEGRA_DMA_REQ_SEL_SL2B4,
  127. };
  128. #define BB_LEN 32
  129. struct spi_tegra_data {
  130. struct spi_master *master;
  131. struct platform_device *pdev;
  132. spinlock_t lock;
  133. struct clk *clk;
  134. void __iomem *base;
  135. unsigned long phys;
  136. u32 cur_speed;
  137. struct list_head queue;
  138. struct spi_transfer *cur;
  139. unsigned cur_pos;
  140. unsigned cur_len;
  141. unsigned cur_bytes_per_word;
  142. /* The tegra spi controller has a bug which causes the first word
  143. * in PIO transactions to be garbage. Since packed DMA transactions
  144. * require transfers to be 4 byte aligned we need a bounce buffer
  145. * for the generic case.
  146. */
  147. struct tegra_dma_req rx_dma_req;
  148. struct tegra_dma_channel *rx_dma;
  149. u32 *rx_bb;
  150. dma_addr_t rx_bb_phys;
  151. };
  152. static inline unsigned long spi_tegra_readl(struct spi_tegra_data *tspi,
  153. unsigned long reg)
  154. {
  155. return readl(tspi->base + reg);
  156. }
  157. static inline void spi_tegra_writel(struct spi_tegra_data *tspi,
  158. unsigned long val,
  159. unsigned long reg)
  160. {
  161. writel(val, tspi->base + reg);
  162. }
  163. static void spi_tegra_go(struct spi_tegra_data *tspi)
  164. {
  165. unsigned long val;
  166. wmb();
  167. val = spi_tegra_readl(tspi, SLINK_DMA_CTL);
  168. val &= ~SLINK_DMA_BLOCK_SIZE(~0) & ~SLINK_DMA_EN;
  169. val |= SLINK_DMA_BLOCK_SIZE(tspi->rx_dma_req.size / 4 - 1);
  170. spi_tegra_writel(tspi, val, SLINK_DMA_CTL);
  171. tegra_dma_enqueue_req(tspi->rx_dma, &tspi->rx_dma_req);
  172. val |= SLINK_DMA_EN;
  173. spi_tegra_writel(tspi, val, SLINK_DMA_CTL);
  174. }
  175. static unsigned spi_tegra_fill_tx_fifo(struct spi_tegra_data *tspi,
  176. struct spi_transfer *t)
  177. {
  178. unsigned len = min(t->len - tspi->cur_pos, BB_LEN *
  179. tspi->cur_bytes_per_word);
  180. u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_pos;
  181. int i, j;
  182. unsigned long val;
  183. val = spi_tegra_readl(tspi, SLINK_COMMAND);
  184. val &= ~SLINK_WORD_SIZE(~0);
  185. val |= SLINK_WORD_SIZE(len / tspi->cur_bytes_per_word - 1);
  186. spi_tegra_writel(tspi, val, SLINK_COMMAND);
  187. for (i = 0; i < len; i += tspi->cur_bytes_per_word) {
  188. val = 0;
  189. for (j = 0; j < tspi->cur_bytes_per_word; j++)
  190. val |= tx_buf[i + j] << j * 8;
  191. spi_tegra_writel(tspi, val, SLINK_TX_FIFO);
  192. }
  193. tspi->rx_dma_req.size = len / tspi->cur_bytes_per_word * 4;
  194. return len;
  195. }
  196. static unsigned spi_tegra_drain_rx_fifo(struct spi_tegra_data *tspi,
  197. struct spi_transfer *t)
  198. {
  199. unsigned len = tspi->cur_len;
  200. u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_pos;
  201. int i, j;
  202. unsigned long val;
  203. for (i = 0; i < len; i += tspi->cur_bytes_per_word) {
  204. val = tspi->rx_bb[i / tspi->cur_bytes_per_word];
  205. for (j = 0; j < tspi->cur_bytes_per_word; j++)
  206. rx_buf[i + j] = (val >> (j * 8)) & 0xff;
  207. }
  208. return len;
  209. }
  210. static void spi_tegra_start_transfer(struct spi_device *spi,
  211. struct spi_transfer *t)
  212. {
  213. struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
  214. u32 speed;
  215. u8 bits_per_word;
  216. unsigned long val;
  217. speed = t->speed_hz ? t->speed_hz : spi->max_speed_hz;
  218. bits_per_word = t->bits_per_word ? t->bits_per_word :
  219. spi->bits_per_word;
  220. tspi->cur_bytes_per_word = (bits_per_word - 1) / 8 + 1;
  221. if (speed != tspi->cur_speed)
  222. clk_set_rate(tspi->clk, speed);
  223. if (tspi->cur_speed == 0)
  224. clk_enable(tspi->clk);
  225. tspi->cur_speed = speed;
  226. val = spi_tegra_readl(tspi, SLINK_COMMAND2);
  227. val &= ~SLINK_SS_EN_CS(~0) | SLINK_RXEN | SLINK_TXEN;
  228. if (t->rx_buf)
  229. val |= SLINK_RXEN;
  230. if (t->tx_buf)
  231. val |= SLINK_TXEN;
  232. val |= SLINK_SS_EN_CS(spi->chip_select);
  233. val |= SLINK_SPIE;
  234. spi_tegra_writel(tspi, val, SLINK_COMMAND2);
  235. val = spi_tegra_readl(tspi, SLINK_COMMAND);
  236. val &= ~SLINK_BIT_LENGTH(~0);
  237. val |= SLINK_BIT_LENGTH(bits_per_word - 1);
  238. /* FIXME: should probably control CS manually so that we can be sure
  239. * it does not go low between transfer and to support delay_usecs
  240. * correctly.
  241. */
  242. val &= ~SLINK_IDLE_SCLK_MASK & ~SLINK_CK_SDA & ~SLINK_CS_SW;
  243. if (spi->mode & SPI_CPHA)
  244. val |= SLINK_CK_SDA;
  245. if (spi->mode & SPI_CPOL)
  246. val |= SLINK_IDLE_SCLK_DRIVE_HIGH;
  247. else
  248. val |= SLINK_IDLE_SCLK_DRIVE_LOW;
  249. val |= SLINK_M_S;
  250. spi_tegra_writel(tspi, val, SLINK_COMMAND);
  251. spi_tegra_writel(tspi, SLINK_RX_FLUSH | SLINK_TX_FLUSH, SLINK_STATUS);
  252. tspi->cur = t;
  253. tspi->cur_pos = 0;
  254. tspi->cur_len = spi_tegra_fill_tx_fifo(tspi, t);
  255. spi_tegra_go(tspi);
  256. }
  257. static void spi_tegra_start_message(struct spi_device *spi,
  258. struct spi_message *m)
  259. {
  260. struct spi_transfer *t;
  261. m->actual_length = 0;
  262. m->status = 0;
  263. t = list_first_entry(&m->transfers, struct spi_transfer, transfer_list);
  264. spi_tegra_start_transfer(spi, t);
  265. }
  266. static void tegra_spi_rx_dma_complete(struct tegra_dma_req *req)
  267. {
  268. struct spi_tegra_data *tspi = req->dev;
  269. unsigned long flags;
  270. struct spi_message *m;
  271. struct spi_device *spi;
  272. int timeout = 0;
  273. unsigned long val;
  274. /* the SPI controller may come back with both the BSY and RDY bits
  275. * set. In this case we need to wait for the BSY bit to clear so
  276. * that we are sure the DMA is finished. 1000 reads was empirically
  277. * determined to be long enough.
  278. */
  279. while (timeout++ < 1000) {
  280. if (!(spi_tegra_readl(tspi, SLINK_STATUS) & SLINK_BSY))
  281. break;
  282. }
  283. spin_lock_irqsave(&tspi->lock, flags);
  284. val = spi_tegra_readl(tspi, SLINK_STATUS);
  285. val |= SLINK_RDY;
  286. spi_tegra_writel(tspi, val, SLINK_STATUS);
  287. m = list_first_entry(&tspi->queue, struct spi_message, queue);
  288. if (timeout >= 1000)
  289. m->status = -EIO;
  290. spi = m->state;
  291. tspi->cur_pos += spi_tegra_drain_rx_fifo(tspi, tspi->cur);
  292. m->actual_length += tspi->cur_pos;
  293. if (tspi->cur_pos < tspi->cur->len) {
  294. tspi->cur_len = spi_tegra_fill_tx_fifo(tspi, tspi->cur);
  295. spi_tegra_go(tspi);
  296. } else if (!list_is_last(&tspi->cur->transfer_list,
  297. &m->transfers)) {
  298. tspi->cur = list_first_entry(&tspi->cur->transfer_list,
  299. struct spi_transfer,
  300. transfer_list);
  301. spi_tegra_start_transfer(spi, tspi->cur);
  302. } else {
  303. list_del(&m->queue);
  304. m->complete(m->context);
  305. if (!list_empty(&tspi->queue)) {
  306. m = list_first_entry(&tspi->queue, struct spi_message,
  307. queue);
  308. spi = m->state;
  309. spi_tegra_start_message(spi, m);
  310. } else {
  311. clk_disable(tspi->clk);
  312. tspi->cur_speed = 0;
  313. }
  314. }
  315. spin_unlock_irqrestore(&tspi->lock, flags);
  316. }
  317. static int spi_tegra_setup(struct spi_device *spi)
  318. {
  319. struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
  320. unsigned long cs_bit;
  321. unsigned long val;
  322. unsigned long flags;
  323. dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
  324. spi->bits_per_word,
  325. spi->mode & SPI_CPOL ? "" : "~",
  326. spi->mode & SPI_CPHA ? "" : "~",
  327. spi->max_speed_hz);
  328. switch (spi->chip_select) {
  329. case 0:
  330. cs_bit = SLINK_CS_POLARITY;
  331. break;
  332. case 1:
  333. cs_bit = SLINK_CS_POLARITY1;
  334. break;
  335. case 2:
  336. cs_bit = SLINK_CS_POLARITY2;
  337. break;
  338. case 4:
  339. cs_bit = SLINK_CS_POLARITY3;
  340. break;
  341. default:
  342. return -EINVAL;
  343. }
  344. spin_lock_irqsave(&tspi->lock, flags);
  345. val = spi_tegra_readl(tspi, SLINK_COMMAND);
  346. if (spi->mode & SPI_CS_HIGH)
  347. val |= cs_bit;
  348. else
  349. val &= ~cs_bit;
  350. spi_tegra_writel(tspi, val, SLINK_COMMAND);
  351. spin_unlock_irqrestore(&tspi->lock, flags);
  352. return 0;
  353. }
  354. static int spi_tegra_transfer(struct spi_device *spi, struct spi_message *m)
  355. {
  356. struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
  357. struct spi_transfer *t;
  358. unsigned long flags;
  359. int was_empty;
  360. if (list_empty(&m->transfers) || !m->complete)
  361. return -EINVAL;
  362. list_for_each_entry(t, &m->transfers, transfer_list) {
  363. if (t->bits_per_word < 0 || t->bits_per_word > 32)
  364. return -EINVAL;
  365. if (t->len == 0)
  366. return -EINVAL;
  367. if (!t->rx_buf && !t->tx_buf)
  368. return -EINVAL;
  369. }
  370. m->state = spi;
  371. spin_lock_irqsave(&tspi->lock, flags);
  372. was_empty = list_empty(&tspi->queue);
  373. list_add_tail(&m->queue, &tspi->queue);
  374. if (was_empty)
  375. spi_tegra_start_message(spi, m);
  376. spin_unlock_irqrestore(&tspi->lock, flags);
  377. return 0;
  378. }
  379. static int __init spi_tegra_probe(struct platform_device *pdev)
  380. {
  381. struct spi_master *master;
  382. struct spi_tegra_data *tspi;
  383. struct resource *r;
  384. int ret;
  385. master = spi_alloc_master(&pdev->dev, sizeof *tspi);
  386. if (master == NULL) {
  387. dev_err(&pdev->dev, "master allocation failed\n");
  388. return -ENOMEM;
  389. }
  390. /* the spi->mode bits understood by this driver: */
  391. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
  392. master->bus_num = pdev->id;
  393. master->setup = spi_tegra_setup;
  394. master->transfer = spi_tegra_transfer;
  395. master->num_chipselect = 4;
  396. dev_set_drvdata(&pdev->dev, master);
  397. tspi = spi_master_get_devdata(master);
  398. tspi->master = master;
  399. tspi->pdev = pdev;
  400. spin_lock_init(&tspi->lock);
  401. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  402. if (r == NULL) {
  403. ret = -ENODEV;
  404. goto err0;
  405. }
  406. if (!request_mem_region(r->start, (r->end - r->start) + 1,
  407. dev_name(&pdev->dev))) {
  408. ret = -EBUSY;
  409. goto err0;
  410. }
  411. tspi->phys = r->start;
  412. tspi->base = ioremap(r->start, r->end - r->start + 1);
  413. if (!tspi->base) {
  414. dev_err(&pdev->dev, "can't ioremap iomem\n");
  415. ret = -ENOMEM;
  416. goto err1;
  417. }
  418. tspi->clk = clk_get(&pdev->dev, NULL);
  419. if (IS_ERR(tspi->clk)) {
  420. dev_err(&pdev->dev, "can not get clock\n");
  421. ret = PTR_ERR(tspi->clk);
  422. goto err2;
  423. }
  424. INIT_LIST_HEAD(&tspi->queue);
  425. tspi->rx_dma = tegra_dma_allocate_channel(TEGRA_DMA_MODE_ONESHOT);
  426. if (!tspi->rx_dma) {
  427. dev_err(&pdev->dev, "can not allocate rx dma channel\n");
  428. ret = -ENODEV;
  429. goto err3;
  430. }
  431. tspi->rx_bb = dma_alloc_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
  432. &tspi->rx_bb_phys, GFP_KERNEL);
  433. if (!tspi->rx_bb) {
  434. dev_err(&pdev->dev, "can not allocate rx bounce buffer\n");
  435. ret = -ENOMEM;
  436. goto err4;
  437. }
  438. tspi->rx_dma_req.complete = tegra_spi_rx_dma_complete;
  439. tspi->rx_dma_req.to_memory = 1;
  440. tspi->rx_dma_req.dest_addr = tspi->rx_bb_phys;
  441. tspi->rx_dma_req.dest_bus_width = 32;
  442. tspi->rx_dma_req.source_addr = tspi->phys + SLINK_RX_FIFO;
  443. tspi->rx_dma_req.source_bus_width = 32;
  444. tspi->rx_dma_req.source_wrap = 4;
  445. tspi->rx_dma_req.req_sel = spi_tegra_req_sels[pdev->id];
  446. tspi->rx_dma_req.dev = tspi;
  447. ret = spi_register_master(master);
  448. if (ret < 0)
  449. goto err5;
  450. return ret;
  451. err5:
  452. dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
  453. tspi->rx_bb, tspi->rx_bb_phys);
  454. err4:
  455. tegra_dma_free_channel(tspi->rx_dma);
  456. err3:
  457. clk_put(tspi->clk);
  458. err2:
  459. iounmap(tspi->base);
  460. err1:
  461. release_mem_region(r->start, (r->end - r->start) + 1);
  462. err0:
  463. spi_master_put(master);
  464. return ret;
  465. }
  466. static int __devexit spi_tegra_remove(struct platform_device *pdev)
  467. {
  468. struct spi_master *master;
  469. struct spi_tegra_data *tspi;
  470. struct resource *r;
  471. master = dev_get_drvdata(&pdev->dev);
  472. tspi = spi_master_get_devdata(master);
  473. spi_unregister_master(master);
  474. tegra_dma_free_channel(tspi->rx_dma);
  475. dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
  476. tspi->rx_bb, tspi->rx_bb_phys);
  477. clk_put(tspi->clk);
  478. iounmap(tspi->base);
  479. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  480. release_mem_region(r->start, (r->end - r->start) + 1);
  481. return 0;
  482. }
  483. MODULE_ALIAS("platform:spi_tegra");
  484. static struct platform_driver spi_tegra_driver = {
  485. .driver = {
  486. .name = "spi_tegra",
  487. .owner = THIS_MODULE,
  488. },
  489. .remove = __devexit_p(spi_tegra_remove),
  490. };
  491. static int __init spi_tegra_init(void)
  492. {
  493. return platform_driver_probe(&spi_tegra_driver, spi_tegra_probe);
  494. }
  495. module_init(spi_tegra_init);
  496. static void __exit spi_tegra_exit(void)
  497. {
  498. platform_driver_unregister(&spi_tegra_driver);
  499. }
  500. module_exit(spi_tegra_exit);
  501. MODULE_LICENSE("GPL");