1 // SPDX-License-Identifier: GPL-2.0-only
3 * SPI driver for NVIDIA's Tegra114 SPI Controller.
5 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
9 #include <linux/completion.h>
10 #include <linux/delay.h>
11 #include <linux/dmaengine.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/dmapool.h>
14 #include <linux/err.h>
15 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/kthread.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/pm_runtime.h>
23 #include <linux/of_device.h>
24 #include <linux/reset.h>
25 #include <linux/spi/spi.h>
27 #define SPI_COMMAND1 0x000
28 #define SPI_BIT_LENGTH(x) (((x) & 0x1f) << 0)
29 #define SPI_PACKED (1 << 5)
30 #define SPI_TX_EN (1 << 11)
31 #define SPI_RX_EN (1 << 12)
32 #define SPI_BOTH_EN_BYTE (1 << 13)
33 #define SPI_BOTH_EN_BIT (1 << 14)
34 #define SPI_LSBYTE_FE (1 << 15)
35 #define SPI_LSBIT_FE (1 << 16)
36 #define SPI_BIDIROE (1 << 17)
37 #define SPI_IDLE_SDA_DRIVE_LOW (0 << 18)
38 #define SPI_IDLE_SDA_DRIVE_HIGH (1 << 18)
39 #define SPI_IDLE_SDA_PULL_LOW (2 << 18)
40 #define SPI_IDLE_SDA_PULL_HIGH (3 << 18)
41 #define SPI_IDLE_SDA_MASK (3 << 18)
42 #define SPI_CS_SW_VAL (1 << 20)
43 #define SPI_CS_SW_HW (1 << 21)
44 /* SPI_CS_POL_INACTIVE bits are default high */
46 #define SPI_CS_POL_INACTIVE(n) (1 << (22 + (n)))
47 #define SPI_CS_POL_INACTIVE_MASK (0xF << 22)
49 #define SPI_CS_SEL_0 (0 << 26)
50 #define SPI_CS_SEL_1 (1 << 26)
51 #define SPI_CS_SEL_2 (2 << 26)
52 #define SPI_CS_SEL_3 (3 << 26)
53 #define SPI_CS_SEL_MASK (3 << 26)
54 #define SPI_CS_SEL(x) (((x) & 0x3) << 26)
55 #define SPI_CONTROL_MODE_0 (0 << 28)
56 #define SPI_CONTROL_MODE_1 (1 << 28)
57 #define SPI_CONTROL_MODE_2 (2 << 28)
58 #define SPI_CONTROL_MODE_3 (3 << 28)
59 #define SPI_CONTROL_MODE_MASK (3 << 28)
60 #define SPI_MODE_SEL(x) (((x) & 0x3) << 28)
61 #define SPI_M_S (1 << 30)
62 #define SPI_PIO (1 << 31)
64 #define SPI_COMMAND2 0x004
65 #define SPI_TX_TAP_DELAY(x) (((x) & 0x3F) << 6)
66 #define SPI_RX_TAP_DELAY(x) (((x) & 0x3F) << 0)
68 #define SPI_CS_TIMING1 0x008
69 #define SPI_SETUP_HOLD(setup, hold) (((setup) << 4) | (hold))
70 #define SPI_CS_SETUP_HOLD(reg, cs, val) \
71 ((((val) & 0xFFu) << ((cs) * 8)) | \
72 ((reg) & ~(0xFFu << ((cs) * 8))))
74 #define SPI_CS_TIMING2 0x00C
75 #define CYCLES_BETWEEN_PACKETS_0(x) (((x) & 0x1F) << 0)
76 #define CS_ACTIVE_BETWEEN_PACKETS_0 (1 << 5)
77 #define CYCLES_BETWEEN_PACKETS_1(x) (((x) & 0x1F) << 8)
78 #define CS_ACTIVE_BETWEEN_PACKETS_1 (1 << 13)
79 #define CYCLES_BETWEEN_PACKETS_2(x) (((x) & 0x1F) << 16)
80 #define CS_ACTIVE_BETWEEN_PACKETS_2 (1 << 21)
81 #define CYCLES_BETWEEN_PACKETS_3(x) (((x) & 0x1F) << 24)
82 #define CS_ACTIVE_BETWEEN_PACKETS_3 (1 << 29)
83 #define SPI_SET_CS_ACTIVE_BETWEEN_PACKETS(reg, cs, val) \
84 (reg = (((val) & 0x1) << ((cs) * 8 + 5)) | \
85 ((reg) & ~(1 << ((cs) * 8 + 5))))
86 #define SPI_SET_CYCLES_BETWEEN_PACKETS(reg, cs, val) \
87 (reg = (((val) & 0xF) << ((cs) * 8)) | \
88 ((reg) & ~(0xF << ((cs) * 8))))
90 #define SPI_TRANS_STATUS 0x010
91 #define SPI_BLK_CNT(val) (((val) >> 0) & 0xFFFF)
92 #define SPI_SLV_IDLE_COUNT(val) (((val) >> 16) & 0xFF)
93 #define SPI_RDY (1 << 30)
95 #define SPI_FIFO_STATUS 0x014
96 #define SPI_RX_FIFO_EMPTY (1 << 0)
97 #define SPI_RX_FIFO_FULL (1 << 1)
98 #define SPI_TX_FIFO_EMPTY (1 << 2)
99 #define SPI_TX_FIFO_FULL (1 << 3)
100 #define SPI_RX_FIFO_UNF (1 << 4)
101 #define SPI_RX_FIFO_OVF (1 << 5)
102 #define SPI_TX_FIFO_UNF (1 << 6)
103 #define SPI_TX_FIFO_OVF (1 << 7)
104 #define SPI_ERR (1 << 8)
105 #define SPI_TX_FIFO_FLUSH (1 << 14)
106 #define SPI_RX_FIFO_FLUSH (1 << 15)
107 #define SPI_TX_FIFO_EMPTY_COUNT(val) (((val) >> 16) & 0x7F)
108 #define SPI_RX_FIFO_FULL_COUNT(val) (((val) >> 23) & 0x7F)
109 #define SPI_FRAME_END (1 << 30)
110 #define SPI_CS_INACTIVE (1 << 31)
112 #define SPI_FIFO_ERROR (SPI_RX_FIFO_UNF | \
113 SPI_RX_FIFO_OVF | SPI_TX_FIFO_UNF | SPI_TX_FIFO_OVF)
114 #define SPI_FIFO_EMPTY (SPI_RX_FIFO_EMPTY | SPI_TX_FIFO_EMPTY)
116 #define SPI_TX_DATA 0x018
117 #define SPI_RX_DATA 0x01C
119 #define SPI_DMA_CTL 0x020
120 #define SPI_TX_TRIG_1 (0 << 15)
121 #define SPI_TX_TRIG_4 (1 << 15)
122 #define SPI_TX_TRIG_8 (2 << 15)
123 #define SPI_TX_TRIG_16 (3 << 15)
124 #define SPI_TX_TRIG_MASK (3 << 15)
125 #define SPI_RX_TRIG_1 (0 << 19)
126 #define SPI_RX_TRIG_4 (1 << 19)
127 #define SPI_RX_TRIG_8 (2 << 19)
128 #define SPI_RX_TRIG_16 (3 << 19)
129 #define SPI_RX_TRIG_MASK (3 << 19)
130 #define SPI_IE_TX (1 << 28)
131 #define SPI_IE_RX (1 << 29)
132 #define SPI_CONT (1 << 30)
133 #define SPI_DMA (1 << 31)
134 #define SPI_DMA_EN SPI_DMA
136 #define SPI_DMA_BLK 0x024
137 #define SPI_DMA_BLK_SET(x) (((x) & 0xFFFF) << 0)
139 #define SPI_TX_FIFO 0x108
140 #define SPI_RX_FIFO 0x188
141 #define SPI_INTR_MASK 0x18c
142 #define SPI_INTR_ALL_MASK (0x1fUL << 25)
143 #define MAX_CHIP_SELECT 4
144 #define SPI_FIFO_DEPTH 64
145 #define DATA_DIR_TX (1 << 0)
146 #define DATA_DIR_RX (1 << 1)
148 #define SPI_DMA_TIMEOUT (msecs_to_jiffies(1000))
149 #define DEFAULT_SPI_DMA_BUF_LEN (16*1024)
150 #define TX_FIFO_EMPTY_COUNT_MAX SPI_TX_FIFO_EMPTY_COUNT(0x40)
151 #define RX_FIFO_FULL_COUNT_ZERO SPI_RX_FIFO_FULL_COUNT(0)
152 #define MAX_HOLD_CYCLES 16
153 #define SPI_DEFAULT_SPEED 25000000
155 struct tegra_spi_soc_data {
156 bool has_intr_mask_reg;
159 struct tegra_spi_data {
161 struct spi_master *master;
165 struct reset_control *rst;
171 struct spi_device *cur_spi;
172 struct spi_device *cs_control;
174 unsigned words_per_32bit;
175 unsigned bytes_per_word;
176 unsigned curr_dma_words;
177 unsigned cur_direction;
182 unsigned dma_buf_size;
183 unsigned max_buf_size;
184 bool is_curr_dma_xfer;
186 struct completion rx_dma_complete;
187 struct completion tx_dma_complete;
196 u32 def_command1_reg;
198 struct completion xfer_completion;
199 struct spi_transfer *curr_xfer;
200 struct dma_chan *rx_dma_chan;
202 dma_addr_t rx_dma_phys;
203 struct dma_async_tx_descriptor *rx_dma_desc;
205 struct dma_chan *tx_dma_chan;
207 dma_addr_t tx_dma_phys;
208 struct dma_async_tx_descriptor *tx_dma_desc;
209 const struct tegra_spi_soc_data *soc_data;
212 static int tegra_spi_runtime_suspend(struct device *dev);
213 static int tegra_spi_runtime_resume(struct device *dev);
215 static inline u32 tegra_spi_readl(struct tegra_spi_data *tspi,
218 return readl(tspi->base + reg);
221 static inline void tegra_spi_writel(struct tegra_spi_data *tspi,
222 u32 val, unsigned long reg)
224 writel(val, tspi->base + reg);
226 /* Read back register to make sure that register writes completed */
227 if (reg != SPI_TX_FIFO)
228 readl(tspi->base + SPI_COMMAND1);
231 static void tegra_spi_clear_status(struct tegra_spi_data *tspi)
235 /* Write 1 to clear status register */
236 val = tegra_spi_readl(tspi, SPI_TRANS_STATUS);
237 tegra_spi_writel(tspi, val, SPI_TRANS_STATUS);
239 /* Clear fifo status error if any */
240 val = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
242 tegra_spi_writel(tspi, SPI_ERR | SPI_FIFO_ERROR,
246 static unsigned tegra_spi_calculate_curr_xfer_param(
247 struct spi_device *spi, struct tegra_spi_data *tspi,
248 struct spi_transfer *t)
250 unsigned remain_len = t->len - tspi->cur_pos;
252 unsigned bits_per_word = t->bits_per_word;
254 unsigned total_fifo_words;
256 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8);
258 if ((bits_per_word == 8 || bits_per_word == 16 ||
259 bits_per_word == 32) && t->len > 3) {
261 tspi->words_per_32bit = 32/bits_per_word;
264 tspi->words_per_32bit = 1;
267 if (tspi->is_packed) {
268 max_len = min(remain_len, tspi->max_buf_size);
269 tspi->curr_dma_words = max_len/tspi->bytes_per_word;
270 total_fifo_words = (max_len + 3) / 4;
272 max_word = (remain_len - 1) / tspi->bytes_per_word + 1;
273 max_word = min(max_word, tspi->max_buf_size/4);
274 tspi->curr_dma_words = max_word;
275 total_fifo_words = max_word;
277 return total_fifo_words;
280 static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
281 struct tegra_spi_data *tspi, struct spi_transfer *t)
284 unsigned tx_empty_count;
286 unsigned max_n_32bit;
288 unsigned int written_words;
289 unsigned fifo_words_left;
290 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
292 fifo_status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
293 tx_empty_count = SPI_TX_FIFO_EMPTY_COUNT(fifo_status);
295 if (tspi->is_packed) {
296 fifo_words_left = tx_empty_count * tspi->words_per_32bit;
297 written_words = min(fifo_words_left, tspi->curr_dma_words);
298 nbytes = written_words * tspi->bytes_per_word;
299 max_n_32bit = DIV_ROUND_UP(nbytes, 4);
300 for (count = 0; count < max_n_32bit; count++) {
303 for (i = 0; (i < 4) && nbytes; i++, nbytes--)
304 x |= (u32)(*tx_buf++) << (i * 8);
305 tegra_spi_writel(tspi, x, SPI_TX_FIFO);
308 tspi->cur_tx_pos += written_words * tspi->bytes_per_word;
310 unsigned int write_bytes;
311 max_n_32bit = min(tspi->curr_dma_words, tx_empty_count);
312 written_words = max_n_32bit;
313 nbytes = written_words * tspi->bytes_per_word;
314 if (nbytes > t->len - tspi->cur_pos)
315 nbytes = t->len - tspi->cur_pos;
316 write_bytes = nbytes;
317 for (count = 0; count < max_n_32bit; count++) {
320 for (i = 0; nbytes && (i < tspi->bytes_per_word);
322 x |= (u32)(*tx_buf++) << (i * 8);
323 tegra_spi_writel(tspi, x, SPI_TX_FIFO);
326 tspi->cur_tx_pos += write_bytes;
329 return written_words;
332 static unsigned int tegra_spi_read_rx_fifo_to_client_rxbuf(
333 struct tegra_spi_data *tspi, struct spi_transfer *t)
335 unsigned rx_full_count;
338 unsigned int read_words = 0;
340 u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_rx_pos;
342 fifo_status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
343 rx_full_count = SPI_RX_FIFO_FULL_COUNT(fifo_status);
344 if (tspi->is_packed) {
345 len = tspi->curr_dma_words * tspi->bytes_per_word;
346 for (count = 0; count < rx_full_count; count++) {
347 u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO);
349 for (i = 0; len && (i < 4); i++, len--)
350 *rx_buf++ = (x >> i*8) & 0xFF;
352 read_words += tspi->curr_dma_words;
353 tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
355 u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
356 u8 bytes_per_word = tspi->bytes_per_word;
357 unsigned int read_bytes;
359 len = rx_full_count * bytes_per_word;
360 if (len > t->len - tspi->cur_pos)
361 len = t->len - tspi->cur_pos;
363 for (count = 0; count < rx_full_count; count++) {
364 u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO) & rx_mask;
366 for (i = 0; len && (i < bytes_per_word); i++, len--)
367 *rx_buf++ = (x >> (i*8)) & 0xFF;
369 read_words += rx_full_count;
370 tspi->cur_rx_pos += read_bytes;
376 static void tegra_spi_copy_client_txbuf_to_spi_txbuf(
377 struct tegra_spi_data *tspi, struct spi_transfer *t)
379 /* Make the dma buffer to read by cpu */
380 dma_sync_single_for_cpu(tspi->dev, tspi->tx_dma_phys,
381 tspi->dma_buf_size, DMA_TO_DEVICE);
383 if (tspi->is_packed) {
384 unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
386 memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len);
387 tspi->cur_tx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
391 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
392 unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word;
393 unsigned int write_bytes;
395 if (consume > t->len - tspi->cur_pos)
396 consume = t->len - tspi->cur_pos;
397 write_bytes = consume;
398 for (count = 0; count < tspi->curr_dma_words; count++) {
401 for (i = 0; consume && (i < tspi->bytes_per_word);
403 x |= (u32)(*tx_buf++) << (i * 8);
404 tspi->tx_dma_buf[count] = x;
407 tspi->cur_tx_pos += write_bytes;
410 /* Make the dma buffer to read by dma */
411 dma_sync_single_for_device(tspi->dev, tspi->tx_dma_phys,
412 tspi->dma_buf_size, DMA_TO_DEVICE);
415 static void tegra_spi_copy_spi_rxbuf_to_client_rxbuf(
416 struct tegra_spi_data *tspi, struct spi_transfer *t)
418 /* Make the dma buffer to read by cpu */
419 dma_sync_single_for_cpu(tspi->dev, tspi->rx_dma_phys,
420 tspi->dma_buf_size, DMA_FROM_DEVICE);
422 if (tspi->is_packed) {
423 unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
425 memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len);
426 tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
430 unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos;
431 u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
432 unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word;
433 unsigned int read_bytes;
435 if (consume > t->len - tspi->cur_pos)
436 consume = t->len - tspi->cur_pos;
437 read_bytes = consume;
438 for (count = 0; count < tspi->curr_dma_words; count++) {
439 u32 x = tspi->rx_dma_buf[count] & rx_mask;
441 for (i = 0; consume && (i < tspi->bytes_per_word);
443 *rx_buf++ = (x >> (i*8)) & 0xFF;
446 tspi->cur_rx_pos += read_bytes;
449 /* Make the dma buffer to read by dma */
450 dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys,
451 tspi->dma_buf_size, DMA_FROM_DEVICE);
454 static void tegra_spi_dma_complete(void *args)
456 struct completion *dma_complete = args;
458 complete(dma_complete);
461 static int tegra_spi_start_tx_dma(struct tegra_spi_data *tspi, int len)
463 reinit_completion(&tspi->tx_dma_complete);
464 tspi->tx_dma_desc = dmaengine_prep_slave_single(tspi->tx_dma_chan,
465 tspi->tx_dma_phys, len, DMA_MEM_TO_DEV,
466 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
467 if (!tspi->tx_dma_desc) {
468 dev_err(tspi->dev, "Not able to get desc for Tx\n");
472 tspi->tx_dma_desc->callback = tegra_spi_dma_complete;
473 tspi->tx_dma_desc->callback_param = &tspi->tx_dma_complete;
475 dmaengine_submit(tspi->tx_dma_desc);
476 dma_async_issue_pending(tspi->tx_dma_chan);
480 static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len)
482 reinit_completion(&tspi->rx_dma_complete);
483 tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma_chan,
484 tspi->rx_dma_phys, len, DMA_DEV_TO_MEM,
485 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
486 if (!tspi->rx_dma_desc) {
487 dev_err(tspi->dev, "Not able to get desc for Rx\n");
491 tspi->rx_dma_desc->callback = tegra_spi_dma_complete;
492 tspi->rx_dma_desc->callback_param = &tspi->rx_dma_complete;
494 dmaengine_submit(tspi->rx_dma_desc);
495 dma_async_issue_pending(tspi->rx_dma_chan);
499 static int tegra_spi_flush_fifos(struct tegra_spi_data *tspi)
501 unsigned long timeout = jiffies + HZ;
504 status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
505 if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) {
506 status |= SPI_RX_FIFO_FLUSH | SPI_TX_FIFO_FLUSH;
507 tegra_spi_writel(tspi, status, SPI_FIFO_STATUS);
508 while ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) {
509 status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
510 if (time_after(jiffies, timeout)) {
512 "timeout waiting for fifo flush\n");
523 static int tegra_spi_start_dma_based_transfer(
524 struct tegra_spi_data *tspi, struct spi_transfer *t)
530 struct dma_slave_config dma_sconfig = {0};
532 val = SPI_DMA_BLK_SET(tspi->curr_dma_words - 1);
533 tegra_spi_writel(tspi, val, SPI_DMA_BLK);
536 len = DIV_ROUND_UP(tspi->curr_dma_words * tspi->bytes_per_word,
539 len = tspi->curr_dma_words * 4;
541 /* Set attention level based on length of transfer */
543 val |= SPI_TX_TRIG_1 | SPI_RX_TRIG_1;
545 } else if (((len) >> 4) & 0x1) {
546 val |= SPI_TX_TRIG_4 | SPI_RX_TRIG_4;
549 val |= SPI_TX_TRIG_8 | SPI_RX_TRIG_8;
553 if (!tspi->soc_data->has_intr_mask_reg) {
554 if (tspi->cur_direction & DATA_DIR_TX)
557 if (tspi->cur_direction & DATA_DIR_RX)
561 tegra_spi_writel(tspi, val, SPI_DMA_CTL);
562 tspi->dma_control_reg = val;
564 dma_sconfig.device_fc = true;
565 if (tspi->cur_direction & DATA_DIR_TX) {
566 dma_sconfig.dst_addr = tspi->phys + SPI_TX_FIFO;
567 dma_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
568 dma_sconfig.dst_maxburst = dma_burst;
569 ret = dmaengine_slave_config(tspi->tx_dma_chan, &dma_sconfig);
572 "DMA slave config failed: %d\n", ret);
576 tegra_spi_copy_client_txbuf_to_spi_txbuf(tspi, t);
577 ret = tegra_spi_start_tx_dma(tspi, len);
580 "Starting tx dma failed, err %d\n", ret);
585 if (tspi->cur_direction & DATA_DIR_RX) {
586 dma_sconfig.src_addr = tspi->phys + SPI_RX_FIFO;
587 dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
588 dma_sconfig.src_maxburst = dma_burst;
589 ret = dmaengine_slave_config(tspi->rx_dma_chan, &dma_sconfig);
592 "DMA slave config failed: %d\n", ret);
596 /* Make the dma buffer to read by dma */
597 dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys,
598 tspi->dma_buf_size, DMA_FROM_DEVICE);
600 ret = tegra_spi_start_rx_dma(tspi, len);
603 "Starting rx dma failed, err %d\n", ret);
604 if (tspi->cur_direction & DATA_DIR_TX)
605 dmaengine_terminate_all(tspi->tx_dma_chan);
609 tspi->is_curr_dma_xfer = true;
610 tspi->dma_control_reg = val;
613 tegra_spi_writel(tspi, val, SPI_DMA_CTL);
617 static int tegra_spi_start_cpu_based_transfer(
618 struct tegra_spi_data *tspi, struct spi_transfer *t)
623 if (tspi->cur_direction & DATA_DIR_TX)
624 cur_words = tegra_spi_fill_tx_fifo_from_client_txbuf(tspi, t);
626 cur_words = tspi->curr_dma_words;
628 val = SPI_DMA_BLK_SET(cur_words - 1);
629 tegra_spi_writel(tspi, val, SPI_DMA_BLK);
632 if (tspi->cur_direction & DATA_DIR_TX)
635 if (tspi->cur_direction & DATA_DIR_RX)
638 tegra_spi_writel(tspi, val, SPI_DMA_CTL);
639 tspi->dma_control_reg = val;
641 tspi->is_curr_dma_xfer = false;
643 val = tspi->command1_reg;
645 tegra_spi_writel(tspi, val, SPI_COMMAND1);
649 static int tegra_spi_init_dma_param(struct tegra_spi_data *tspi,
652 struct dma_chan *dma_chan;
657 dma_chan = dma_request_slave_channel_reason(tspi->dev,
658 dma_to_memory ? "rx" : "tx");
659 if (IS_ERR(dma_chan)) {
660 ret = PTR_ERR(dma_chan);
661 if (ret != -EPROBE_DEFER)
663 "Dma channel is not available: %d\n", ret);
667 dma_buf = dma_alloc_coherent(tspi->dev, tspi->dma_buf_size,
668 &dma_phys, GFP_KERNEL);
670 dev_err(tspi->dev, " Not able to allocate the dma buffer\n");
671 dma_release_channel(dma_chan);
676 tspi->rx_dma_chan = dma_chan;
677 tspi->rx_dma_buf = dma_buf;
678 tspi->rx_dma_phys = dma_phys;
680 tspi->tx_dma_chan = dma_chan;
681 tspi->tx_dma_buf = dma_buf;
682 tspi->tx_dma_phys = dma_phys;
687 static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi,
692 struct dma_chan *dma_chan;
695 dma_buf = tspi->rx_dma_buf;
696 dma_chan = tspi->rx_dma_chan;
697 dma_phys = tspi->rx_dma_phys;
698 tspi->rx_dma_chan = NULL;
699 tspi->rx_dma_buf = NULL;
701 dma_buf = tspi->tx_dma_buf;
702 dma_chan = tspi->tx_dma_chan;
703 dma_phys = tspi->tx_dma_phys;
704 tspi->tx_dma_buf = NULL;
705 tspi->tx_dma_chan = NULL;
710 dma_free_coherent(tspi->dev, tspi->dma_buf_size, dma_buf, dma_phys);
711 dma_release_channel(dma_chan);
714 static u32 tegra_spi_setup_transfer_one(struct spi_device *spi,
715 struct spi_transfer *t, bool is_first_of_msg)
717 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
718 u32 speed = t->speed_hz;
719 u8 bits_per_word = t->bits_per_word;
723 if (speed != tspi->cur_speed) {
724 clk_set_rate(tspi->clk, speed);
725 tspi->cur_speed = speed;
730 tspi->cur_rx_pos = 0;
731 tspi->cur_tx_pos = 0;
734 if (is_first_of_msg) {
735 tegra_spi_clear_status(tspi);
737 command1 = tspi->def_command1_reg;
738 command1 |= SPI_BIT_LENGTH(bits_per_word - 1);
740 command1 &= ~SPI_CONTROL_MODE_MASK;
741 req_mode = spi->mode & 0x3;
742 if (req_mode == SPI_MODE_0)
743 command1 |= SPI_CONTROL_MODE_0;
744 else if (req_mode == SPI_MODE_1)
745 command1 |= SPI_CONTROL_MODE_1;
746 else if (req_mode == SPI_MODE_2)
747 command1 |= SPI_CONTROL_MODE_2;
748 else if (req_mode == SPI_MODE_3)
749 command1 |= SPI_CONTROL_MODE_3;
751 if (spi->mode & SPI_LSB_FIRST)
752 command1 |= SPI_LSBIT_FE;
754 command1 &= ~SPI_LSBIT_FE;
756 if (spi->mode & SPI_3WIRE)
757 command1 |= SPI_BIDIROE;
759 command1 &= ~SPI_BIDIROE;
761 if (tspi->cs_control) {
762 if (tspi->cs_control != spi)
763 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
764 tspi->cs_control = NULL;
766 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
768 command1 |= SPI_CS_SW_HW;
769 if (spi->mode & SPI_CS_HIGH)
770 command1 |= SPI_CS_SW_VAL;
772 command1 &= ~SPI_CS_SW_VAL;
774 tegra_spi_writel(tspi, 0, SPI_COMMAND2);
776 command1 = tspi->command1_reg;
777 command1 &= ~SPI_BIT_LENGTH(~0);
778 command1 |= SPI_BIT_LENGTH(bits_per_word - 1);
784 static int tegra_spi_start_transfer_one(struct spi_device *spi,
785 struct spi_transfer *t, u32 command1)
787 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
788 unsigned total_fifo_words;
791 total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t);
793 if (t->rx_nbits == SPI_NBITS_DUAL || t->tx_nbits == SPI_NBITS_DUAL)
794 command1 |= SPI_BOTH_EN_BIT;
796 command1 &= ~SPI_BOTH_EN_BIT;
799 command1 |= SPI_PACKED;
801 command1 &= ~SPI_PACKED;
803 command1 &= ~(SPI_CS_SEL_MASK | SPI_TX_EN | SPI_RX_EN);
804 tspi->cur_direction = 0;
806 command1 |= SPI_RX_EN;
807 tspi->cur_direction |= DATA_DIR_RX;
810 command1 |= SPI_TX_EN;
811 tspi->cur_direction |= DATA_DIR_TX;
813 command1 |= SPI_CS_SEL(spi->chip_select);
814 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
815 tspi->command1_reg = command1;
817 dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n",
818 tspi->def_command1_reg, (unsigned)command1);
820 ret = tegra_spi_flush_fifos(tspi);
823 if (total_fifo_words > SPI_FIFO_DEPTH)
824 ret = tegra_spi_start_dma_based_transfer(tspi, t);
826 ret = tegra_spi_start_cpu_based_transfer(tspi, t);
830 static int tegra_spi_setup(struct spi_device *spi)
832 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
837 dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
839 spi->mode & SPI_CPOL ? "" : "~",
840 spi->mode & SPI_CPHA ? "" : "~",
843 ret = pm_runtime_get_sync(tspi->dev);
845 dev_err(tspi->dev, "pm runtime failed, e = %d\n", ret);
849 if (tspi->soc_data->has_intr_mask_reg) {
850 val = tegra_spi_readl(tspi, SPI_INTR_MASK);
851 val &= ~SPI_INTR_ALL_MASK;
852 tegra_spi_writel(tspi, val, SPI_INTR_MASK);
855 spin_lock_irqsave(&tspi->lock, flags);
856 val = tspi->def_command1_reg;
857 if (spi->mode & SPI_CS_HIGH)
858 val &= ~SPI_CS_POL_INACTIVE(spi->chip_select);
860 val |= SPI_CS_POL_INACTIVE(spi->chip_select);
861 tspi->def_command1_reg = val;
862 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
863 spin_unlock_irqrestore(&tspi->lock, flags);
865 pm_runtime_put(tspi->dev);
869 static void tegra_spi_transfer_delay(int delay)
875 mdelay(delay / 1000);
877 udelay(delay % 1000);
880 static void tegra_spi_transfer_end(struct spi_device *spi)
882 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
883 int cs_val = (spi->mode & SPI_CS_HIGH) ? 0 : 1;
886 tspi->command1_reg |= SPI_CS_SW_VAL;
888 tspi->command1_reg &= ~SPI_CS_SW_VAL;
889 tegra_spi_writel(tspi, tspi->command1_reg, SPI_COMMAND1);
890 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
893 static void tegra_spi_dump_regs(struct tegra_spi_data *tspi)
895 dev_dbg(tspi->dev, "============ SPI REGISTER DUMP ============\n");
896 dev_dbg(tspi->dev, "Command1: 0x%08x | Command2: 0x%08x\n",
897 tegra_spi_readl(tspi, SPI_COMMAND1),
898 tegra_spi_readl(tspi, SPI_COMMAND2));
899 dev_dbg(tspi->dev, "DMA_CTL: 0x%08x | DMA_BLK: 0x%08x\n",
900 tegra_spi_readl(tspi, SPI_DMA_CTL),
901 tegra_spi_readl(tspi, SPI_DMA_BLK));
902 dev_dbg(tspi->dev, "TRANS_STAT: 0x%08x | FIFO_STATUS: 0x%08x\n",
903 tegra_spi_readl(tspi, SPI_TRANS_STATUS),
904 tegra_spi_readl(tspi, SPI_FIFO_STATUS));
907 static int tegra_spi_transfer_one_message(struct spi_master *master,
908 struct spi_message *msg)
910 bool is_first_msg = true;
911 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
912 struct spi_transfer *xfer;
913 struct spi_device *spi = msg->spi;
918 msg->actual_length = 0;
920 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
923 reinit_completion(&tspi->xfer_completion);
925 cmd1 = tegra_spi_setup_transfer_one(spi, xfer, is_first_msg);
933 ret = tegra_spi_start_transfer_one(spi, xfer, cmd1);
936 "spi can not start transfer, err %d\n", ret);
940 is_first_msg = false;
941 ret = wait_for_completion_timeout(&tspi->xfer_completion,
943 if (WARN_ON(ret == 0)) {
945 "spi transfer timeout, err %d\n", ret);
946 if (tspi->is_curr_dma_xfer &&
947 (tspi->cur_direction & DATA_DIR_TX))
948 dmaengine_terminate_all(tspi->tx_dma_chan);
949 if (tspi->is_curr_dma_xfer &&
950 (tspi->cur_direction & DATA_DIR_RX))
951 dmaengine_terminate_all(tspi->rx_dma_chan);
953 tegra_spi_dump_regs(tspi);
954 tegra_spi_flush_fifos(tspi);
955 reset_control_assert(tspi->rst);
957 reset_control_deassert(tspi->rst);
961 if (tspi->tx_status || tspi->rx_status) {
962 dev_err(tspi->dev, "Error in Transfer\n");
964 tegra_spi_dump_regs(tspi);
967 msg->actual_length += xfer->len;
970 if (ret < 0 || skip) {
971 tegra_spi_transfer_end(spi);
972 tegra_spi_transfer_delay(xfer->delay_usecs);
974 } else if (list_is_last(&xfer->transfer_list,
977 tspi->cs_control = spi;
979 tegra_spi_transfer_end(spi);
980 tegra_spi_transfer_delay(xfer->delay_usecs);
982 } else if (xfer->cs_change) {
983 tegra_spi_transfer_end(spi);
984 tegra_spi_transfer_delay(xfer->delay_usecs);
991 spi_finalize_current_message(master);
995 static irqreturn_t handle_cpu_based_xfer(struct tegra_spi_data *tspi)
997 struct spi_transfer *t = tspi->curr_xfer;
1000 spin_lock_irqsave(&tspi->lock, flags);
1001 if (tspi->tx_status || tspi->rx_status) {
1002 dev_err(tspi->dev, "CpuXfer ERROR bit set 0x%x\n",
1004 dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n",
1005 tspi->command1_reg, tspi->dma_control_reg);
1006 tegra_spi_dump_regs(tspi);
1007 tegra_spi_flush_fifos(tspi);
1008 complete(&tspi->xfer_completion);
1009 spin_unlock_irqrestore(&tspi->lock, flags);
1010 reset_control_assert(tspi->rst);
1012 reset_control_deassert(tspi->rst);
1016 if (tspi->cur_direction & DATA_DIR_RX)
1017 tegra_spi_read_rx_fifo_to_client_rxbuf(tspi, t);
1019 if (tspi->cur_direction & DATA_DIR_TX)
1020 tspi->cur_pos = tspi->cur_tx_pos;
1022 tspi->cur_pos = tspi->cur_rx_pos;
1024 if (tspi->cur_pos == t->len) {
1025 complete(&tspi->xfer_completion);
1029 tegra_spi_calculate_curr_xfer_param(tspi->cur_spi, tspi, t);
1030 tegra_spi_start_cpu_based_transfer(tspi, t);
1032 spin_unlock_irqrestore(&tspi->lock, flags);
1036 static irqreturn_t handle_dma_based_xfer(struct tegra_spi_data *tspi)
1038 struct spi_transfer *t = tspi->curr_xfer;
1041 unsigned total_fifo_words;
1042 unsigned long flags;
1044 /* Abort dmas if any error */
1045 if (tspi->cur_direction & DATA_DIR_TX) {
1046 if (tspi->tx_status) {
1047 dmaengine_terminate_all(tspi->tx_dma_chan);
1050 wait_status = wait_for_completion_interruptible_timeout(
1051 &tspi->tx_dma_complete, SPI_DMA_TIMEOUT);
1052 if (wait_status <= 0) {
1053 dmaengine_terminate_all(tspi->tx_dma_chan);
1054 dev_err(tspi->dev, "TxDma Xfer failed\n");
1060 if (tspi->cur_direction & DATA_DIR_RX) {
1061 if (tspi->rx_status) {
1062 dmaengine_terminate_all(tspi->rx_dma_chan);
1065 wait_status = wait_for_completion_interruptible_timeout(
1066 &tspi->rx_dma_complete, SPI_DMA_TIMEOUT);
1067 if (wait_status <= 0) {
1068 dmaengine_terminate_all(tspi->rx_dma_chan);
1069 dev_err(tspi->dev, "RxDma Xfer failed\n");
1075 spin_lock_irqsave(&tspi->lock, flags);
1077 dev_err(tspi->dev, "DmaXfer: ERROR bit set 0x%x\n",
1079 dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n",
1080 tspi->command1_reg, tspi->dma_control_reg);
1081 tegra_spi_dump_regs(tspi);
1082 tegra_spi_flush_fifos(tspi);
1083 complete(&tspi->xfer_completion);
1084 spin_unlock_irqrestore(&tspi->lock, flags);
1085 reset_control_assert(tspi->rst);
1087 reset_control_deassert(tspi->rst);
1091 if (tspi->cur_direction & DATA_DIR_RX)
1092 tegra_spi_copy_spi_rxbuf_to_client_rxbuf(tspi, t);
1094 if (tspi->cur_direction & DATA_DIR_TX)
1095 tspi->cur_pos = tspi->cur_tx_pos;
1097 tspi->cur_pos = tspi->cur_rx_pos;
1099 if (tspi->cur_pos == t->len) {
1100 complete(&tspi->xfer_completion);
1104 /* Continue transfer in current message */
1105 total_fifo_words = tegra_spi_calculate_curr_xfer_param(tspi->cur_spi,
1107 if (total_fifo_words > SPI_FIFO_DEPTH)
1108 err = tegra_spi_start_dma_based_transfer(tspi, t);
1110 err = tegra_spi_start_cpu_based_transfer(tspi, t);
1113 spin_unlock_irqrestore(&tspi->lock, flags);
1117 static irqreturn_t tegra_spi_isr_thread(int irq, void *context_data)
1119 struct tegra_spi_data *tspi = context_data;
1121 if (!tspi->is_curr_dma_xfer)
1122 return handle_cpu_based_xfer(tspi);
1123 return handle_dma_based_xfer(tspi);
1126 static irqreturn_t tegra_spi_isr(int irq, void *context_data)
1128 struct tegra_spi_data *tspi = context_data;
1130 tspi->status_reg = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
1131 if (tspi->cur_direction & DATA_DIR_TX)
1132 tspi->tx_status = tspi->status_reg &
1133 (SPI_TX_FIFO_UNF | SPI_TX_FIFO_OVF);
1135 if (tspi->cur_direction & DATA_DIR_RX)
1136 tspi->rx_status = tspi->status_reg &
1137 (SPI_RX_FIFO_OVF | SPI_RX_FIFO_UNF);
1138 tegra_spi_clear_status(tspi);
1140 return IRQ_WAKE_THREAD;
1143 static struct tegra_spi_soc_data tegra114_spi_soc_data = {
1144 .has_intr_mask_reg = false,
1147 static struct tegra_spi_soc_data tegra124_spi_soc_data = {
1148 .has_intr_mask_reg = false,
1151 static struct tegra_spi_soc_data tegra210_spi_soc_data = {
1152 .has_intr_mask_reg = true,
1155 static const struct of_device_id tegra_spi_of_match[] = {
1157 .compatible = "nvidia,tegra114-spi",
1158 .data = &tegra114_spi_soc_data,
1160 .compatible = "nvidia,tegra124-spi",
1161 .data = &tegra124_spi_soc_data,
1163 .compatible = "nvidia,tegra210-spi",
1164 .data = &tegra210_spi_soc_data,
1168 MODULE_DEVICE_TABLE(of, tegra_spi_of_match);
1170 static int tegra_spi_probe(struct platform_device *pdev)
1172 struct spi_master *master;
1173 struct tegra_spi_data *tspi;
1178 master = spi_alloc_master(&pdev->dev, sizeof(*tspi));
1180 dev_err(&pdev->dev, "master allocation failed\n");
1183 platform_set_drvdata(pdev, master);
1184 tspi = spi_master_get_devdata(master);
1186 if (of_property_read_u32(pdev->dev.of_node, "spi-max-frequency",
1187 &master->max_speed_hz))
1188 master->max_speed_hz = 25000000; /* 25MHz */
1190 /* the spi->mode bits understood by this driver: */
1191 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST |
1192 SPI_TX_DUAL | SPI_RX_DUAL | SPI_3WIRE;
1193 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1194 master->setup = tegra_spi_setup;
1195 master->transfer_one_message = tegra_spi_transfer_one_message;
1196 master->num_chipselect = MAX_CHIP_SELECT;
1197 master->auto_runtime_pm = true;
1198 bus_num = of_alias_get_id(pdev->dev.of_node, "spi");
1200 master->bus_num = bus_num;
1202 tspi->master = master;
1203 tspi->dev = &pdev->dev;
1204 spin_lock_init(&tspi->lock);
1206 tspi->soc_data = of_device_get_match_data(&pdev->dev);
1207 if (!tspi->soc_data) {
1208 dev_err(&pdev->dev, "unsupported tegra\n");
1210 goto exit_free_master;
1213 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1214 tspi->base = devm_ioremap_resource(&pdev->dev, r);
1215 if (IS_ERR(tspi->base)) {
1216 ret = PTR_ERR(tspi->base);
1217 goto exit_free_master;
1219 tspi->phys = r->start;
1221 spi_irq = platform_get_irq(pdev, 0);
1222 tspi->irq = spi_irq;
1224 tspi->clk = devm_clk_get(&pdev->dev, "spi");
1225 if (IS_ERR(tspi->clk)) {
1226 dev_err(&pdev->dev, "can not get clock\n");
1227 ret = PTR_ERR(tspi->clk);
1228 goto exit_free_master;
1231 tspi->rst = devm_reset_control_get_exclusive(&pdev->dev, "spi");
1232 if (IS_ERR(tspi->rst)) {
1233 dev_err(&pdev->dev, "can not get reset\n");
1234 ret = PTR_ERR(tspi->rst);
1235 goto exit_free_master;
1238 tspi->max_buf_size = SPI_FIFO_DEPTH << 2;
1239 tspi->dma_buf_size = DEFAULT_SPI_DMA_BUF_LEN;
1241 ret = tegra_spi_init_dma_param(tspi, true);
1243 goto exit_free_master;
1244 ret = tegra_spi_init_dma_param(tspi, false);
1246 goto exit_rx_dma_free;
1247 tspi->max_buf_size = tspi->dma_buf_size;
1248 init_completion(&tspi->tx_dma_complete);
1249 init_completion(&tspi->rx_dma_complete);
1251 init_completion(&tspi->xfer_completion);
1253 pm_runtime_enable(&pdev->dev);
1254 if (!pm_runtime_enabled(&pdev->dev)) {
1255 ret = tegra_spi_runtime_resume(&pdev->dev);
1257 goto exit_pm_disable;
1260 ret = pm_runtime_get_sync(&pdev->dev);
1262 dev_err(&pdev->dev, "pm runtime get failed, e = %d\n", ret);
1263 goto exit_pm_disable;
1266 reset_control_assert(tspi->rst);
1268 reset_control_deassert(tspi->rst);
1269 tspi->def_command1_reg = SPI_M_S;
1270 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
1271 pm_runtime_put(&pdev->dev);
1272 ret = request_threaded_irq(tspi->irq, tegra_spi_isr,
1273 tegra_spi_isr_thread, IRQF_ONESHOT,
1274 dev_name(&pdev->dev), tspi);
1276 dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
1278 goto exit_pm_disable;
1281 master->dev.of_node = pdev->dev.of_node;
1282 ret = devm_spi_register_master(&pdev->dev, master);
1284 dev_err(&pdev->dev, "can not register to master err %d\n", ret);
1290 free_irq(spi_irq, tspi);
1292 pm_runtime_disable(&pdev->dev);
1293 if (!pm_runtime_status_suspended(&pdev->dev))
1294 tegra_spi_runtime_suspend(&pdev->dev);
1295 tegra_spi_deinit_dma_param(tspi, false);
1297 tegra_spi_deinit_dma_param(tspi, true);
1299 spi_master_put(master);
1303 static int tegra_spi_remove(struct platform_device *pdev)
1305 struct spi_master *master = platform_get_drvdata(pdev);
1306 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
1308 free_irq(tspi->irq, tspi);
1310 if (tspi->tx_dma_chan)
1311 tegra_spi_deinit_dma_param(tspi, false);
1313 if (tspi->rx_dma_chan)
1314 tegra_spi_deinit_dma_param(tspi, true);
1316 pm_runtime_disable(&pdev->dev);
1317 if (!pm_runtime_status_suspended(&pdev->dev))
1318 tegra_spi_runtime_suspend(&pdev->dev);
1323 #ifdef CONFIG_PM_SLEEP
1324 static int tegra_spi_suspend(struct device *dev)
1326 struct spi_master *master = dev_get_drvdata(dev);
1328 return spi_master_suspend(master);
1331 static int tegra_spi_resume(struct device *dev)
1333 struct spi_master *master = dev_get_drvdata(dev);
1334 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
1337 ret = pm_runtime_get_sync(dev);
1339 dev_err(dev, "pm runtime failed, e = %d\n", ret);
1342 tegra_spi_writel(tspi, tspi->command1_reg, SPI_COMMAND1);
1343 pm_runtime_put(dev);
1345 return spi_master_resume(master);
1349 static int tegra_spi_runtime_suspend(struct device *dev)
1351 struct spi_master *master = dev_get_drvdata(dev);
1352 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
1354 /* Flush all write which are in PPSB queue by reading back */
1355 tegra_spi_readl(tspi, SPI_COMMAND1);
1357 clk_disable_unprepare(tspi->clk);
1361 static int tegra_spi_runtime_resume(struct device *dev)
1363 struct spi_master *master = dev_get_drvdata(dev);
1364 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
1367 ret = clk_prepare_enable(tspi->clk);
1369 dev_err(tspi->dev, "clk_prepare failed: %d\n", ret);
1375 static const struct dev_pm_ops tegra_spi_pm_ops = {
1376 SET_RUNTIME_PM_OPS(tegra_spi_runtime_suspend,
1377 tegra_spi_runtime_resume, NULL)
1378 SET_SYSTEM_SLEEP_PM_OPS(tegra_spi_suspend, tegra_spi_resume)
1380 static struct platform_driver tegra_spi_driver = {
1382 .name = "spi-tegra114",
1383 .pm = &tegra_spi_pm_ops,
1384 .of_match_table = tegra_spi_of_match,
1386 .probe = tegra_spi_probe,
1387 .remove = tegra_spi_remove,
1389 module_platform_driver(tegra_spi_driver);
1391 MODULE_ALIAS("platform:spi-tegra114");
1392 MODULE_DESCRIPTION("NVIDIA Tegra114 SPI Controller Driver");
1393 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
1394 MODULE_LICENSE("GPL v2");