spi-tegra.c 16 KB

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